Index: /trunk/NEMO/TOP_SRC/SED/par_sed.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/par_sed.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/par_sed.F90	(revision 1179)
@@ -0,0 +1,61 @@
+MODULE par_sed
+   !!======================================================================
+   !!                        ***  par_sed  ***
+   !! Sediment :   set sediment parameter
+   !!======================================================================
+   !! History :
+   !!        !  06-12  (C. Ethe)  Orignal
+   !!----------------------------------------------------------------------
+#if defined key_sed
+   !! Domain characteristics
+   USE par_kind
+   USE par_oce , ONLY :       &
+      jpi      =>   jpi   ,  & !: first  dimension of grid --> i
+      jpj      =>   jpj   ,  & !: second dimension of grid --> j
+      jpim1    =>   jpim1 ,  & !: jpi - 1
+      jpjm1    =>   jpjm1 ,  & !: jpj - 1
+      jpij     =>   jpij       !: jpi x jpj
+
+#if ! defined key_sed_off
+   USE par_pisces
+#if defined key_kriest
+   INTEGER, PARAMETER :: jpdta = 11
+#else
+   INTEGER, PARAMETER :: jpdta = 12
+#endif
+#endif
+
+   ! Vertical sediment geometry
+   INTEGER, PARAMETER :: &
+      jpksed   = 11         ,   & !: number of sediment layers
+      jpksedm1 = jpksed - 1 
+      
+   ! sediment tracer species
+   INTEGER, PARAMETER :: &
+      jpsol = 4,         &  !: number of solid component
+      jpwat = 7,         &   !: number of pore water component
+      jpwatp1 = jpwat + 1
+
+   
+   ! pore water components       
+   INTEGER, PARAMETER :: &
+      jwsil  = 1,        & !: silic acid
+      jwoxy  = 2,        & !: oxygen
+      jwdic  = 3,        & !: dissolved inorganic carbon
+      jwno3  = 4,        & !: nitrate
+      jwpo4  = 5,        & !: phosphate
+      jwalk  = 6,        & !: alkalinity
+      jwc13  = 7           !: dissolved inorganic carbon 13
+
+   ! solid components       
+   INTEGER, PARAMETER ::  &
+      jsopal  = 1,        & !: opal sediment
+      jsclay  = 2,        & !: clay
+      jspoc   = 3,        & !: organic carbon
+      jscal   = 4           !: calcite
+
+   INTEGER, PARAMETER ::  &
+      jptrased = 14 , &
+      jpflxsed = 7
+#endif
+END MODULE par_sed
Index: /trunk/NEMO/TOP_SRC/SED/sed.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sed.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sed.F90	(revision 1179)
@@ -0,0 +1,216 @@
+MODULE sed
+   !!======================================================================
+   !!                        ***  sed  ***
+   !! Sediment :   set sediment global variables
+   !!======================================================================
+#if defined key_sed
+   !! History :
+   !!        !  06-12  (C. Ethe)  Orignal
+   !!----------------------------------------------------------------------
+   USE par_sed
+
+   USE in_out_manager
+
+   USE dom_oce , ONLY :       &
+      nidom    =>   nidom  ,  & !:
+      glamt    =>   glamt  ,  & !: longitude of t-point (degre)
+      gphit    =>   gphit  ,  & !: latitude  of t-point (degre)
+      e3t_0    =>   e3t_0  ,  & !: reference depth of t-points (m)
+      mbathy   =>   mbathy ,  & !: bathymetry
+      tmask    =>   tmask  ,  & !: land/ocean mask at t-points
+      rdt      =>   rdt         !: time step for the dynamics
+
+   USE daymod , ONLY :                 &
+      nyear     =>   nyear,   &  !: Current year
+      nmonth    =>   nmonth,  &  !: Current month
+      nday      =>   nday        !: Current day
+
+
+#if ! defined key_sed_off
+
+   USE oce , ONLY :            &
+      tn      =>    tn    ,  & !: pot. temperature (celsius)
+      sn      =>    sn         !: salinity (psu)
+
+   USE trc, ONLY :  &
+      trn        , & !: tracer 
+      nittrc000  , & !: 1st time step of tracer model
+      nwritetrc      !: outputs frequency of tracer model
+
+   USE p4zsink, ONLY :  &
+      sinking  ,     & !: sinking flux for POC
+#if ! defined key_kriest
+      sinking2 ,     & !: sinking flux for GOC
+#endif
+      sinkcal ,      & !: sinking flux for calcite 
+      sinksil          !: sinking flux for opal ( dsi )
+
+   USE sms_pisces, ONLY :  &
+      akb3  ,     & 
+      ak13  ,     & 
+      ak23  ,     & 
+      akw3  ,     & 
+      aksp  ,     & 
+      borat 
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpdta) :: &
+      trc_data           !: tracer data to share with sediment model
+#endif   
+
+   INTEGER, PUBLIC :: &
+      nitsed000, nitsedend, nwrised, nfreq
+
+   REAL(wp), PUBLIC, DIMENSION(:,:,:) , ALLOCATABLE ::   &
+      pwcp  ,      &     !: pore water sediment data at given time-step
+      pwcp0              !: pore water sediment data at initial time
+
+   REAL(wp), PUBLIC, DIMENSION(:,:,:) , ALLOCATABLE ::   &
+      solcp ,      &     !: solid sediment data at given time-step
+      solcp0             !: solid sediment at initial time
+
+   !! * Shared module variables
+   REAL(wp), PUBLIC, DIMENSION(:,:) , ALLOCATABLE ::   &
+      pwcp_dta           !: pore water data at given time-step
+
+   REAL(wp), PUBLIC, DIMENSION(:,:) , ALLOCATABLE ::   &
+      rainrm_dta,  &     !: rain data at at initial time
+      rainrm    ,  &     !: rain data at given time-step
+      rainrg    ,  &     !: rain of each solid component in [g/(cm**2.s)]
+      fromsed   ,  &     !:
+      tosed     ,  &     !:
+      rloss              !: 
+
+   REAL(wp), PUBLIC, DIMENSION(:,:) , ALLOCATABLE  ::   &
+      tokbot             !: 
+
+   REAL(wp), PUBLIC, DIMENSION(:) , ALLOCATABLE  ::   & 
+      temp  ,      &     !: temperature
+      salt  ,      &     !: salinity
+      press ,      &     !: pressure
+      raintg,      &     !: total massic flux rained in each cell (sum of sol. comp.)
+      dzdep              !: total thickness of solid material rained [cm] in each cell
+
+   REAL(wp), PUBLIC, DIMENSION(:,:) , ALLOCATABLE  ::   &
+      hipor  ,     &     !: [h+] in mol/kg*densSW 
+      co3por             !: [co3--]solid sediment at initial time
+
+   REAL(wp), PUBLIC, DIMENSION(jpsol) ::   &
+      mol_wgt            !: molecular weight of solid sediment data
+
+   
+   !! Geometry
+   INTEGER, PUBLIC, SAVE :: &
+      jpoce ,  &             !: sediment points
+      indoce
+
+   INTEGER , PUBLIC, DIMENSION(:) , ALLOCATABLE  ::   &  !:
+      iarroce      !: ! Computation of 1D array of sediments points
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) :: &
+      epkbot             !: ocean bottom layer thickness
+
+   REAL(wp), PUBLIC, DIMENSION(:) , ALLOCATABLE  :: &
+      dzkbot             !: ocean bottom layer thickness in meters
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpksed) :: &
+      tmasksed           !: sediment mask
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) :: &
+      sbathy
+ 
+   REAL(wp), PUBLIC, DIMENSION(jpksed) :: &
+      dz      ,    &     !: sediment layers thickness
+      por     ,    &     !: porosity profile     
+      por1    ,    &     !: 1 - por 
+      profsed ,    &     !: depth of middle of each layer
+      volw    ,    &     !: volume of pore water cell fraction
+      vols    ,    &     !: volume of solid cell fraction
+      diff    ,    &     !: diffusion ceofficient
+      rdtsed             !: 
+
+   REAL(wp), PUBLIC, DIMENSION(:,:) , ALLOCATABLE :: &
+      dz3d   ,     &     !: 
+      volw3d ,     &     !: 
+      vols3d             !: 
+
+   REAL(wp)  ::    &
+      dens               !: density of solid material
+
+   !! Namelist
+   REAL(wp), PUBLIC, DIMENSION(5) :: &   
+      reac               !: reactivity rc in  [l.mol-1.s-1]
+
+   REAL(wp), PUBLIC       :: &   
+      sat_sil,      &     !: saturation concentration for silicate in [mol.l-1]
+      sat_clay,     &     !:                              clay    
+      reac_sil,     &     !: reactivity rc in  [l.mol-1.s-1]
+      reac_clay,    &     
+      reac_poc,     &     
+      reac_no3,     &     
+      reac_cal         
+
+   REAL(wp), PUBLIC    :: &   
+      so2ut   ,     &     !:
+      srno3   ,     &     !: 
+      spo4r   ,     &     !:
+      srDnit  ,     &     !: 
+      sthro2              !: threshold O2 concen. in [mol.l-1]
+
+   REAL(wp), PUBLIC    :: &   
+      pdb    = 0.0112372, & !: 13C/12C in PD Belemnite
+      rc13P  = 0.980    , & !: 13C/12C in POC = rc13P*PDB
+      rc13Ca = 1.001        !: 13C/12C in CaCO3 = rc13Ca*PDB
+
+   REAL(wp) , PUBLIC ::   &
+      dtsed  ,     &     !: sedimentation time step
+      db                 !: bioturb coefficient in [cm2.s-1]
+
+   !! Chemistry
+   REAL(wp), PUBLIC, DIMENSION(:) , ALLOCATABLE  :: &
+      densSW ,     &
+      borats ,     &
+      calcon2,     &
+      akbs   ,     &
+      ak1s   ,     &
+      ak2s   ,     &
+      akws   ,     &
+      ak12s  ,     &
+      ak1ps  ,     &
+      ak2ps  ,     &
+      ak3ps  ,     &
+      ak12ps ,     &
+      ak123ps,     &
+      aksis  ,     & 
+      aksps 
+
+   !! Inputs / Outputs
+   CHARACTER( len = 80 ), DIMENSION(jptrased) :: &
+      sedtrc3l 
+
+   CHARACTER( len = 20 ), DIMENSION(jptrased) :: &
+      sedtrc3d , sedtrc3u
+
+   CHARACTER( len = 80 ), DIMENSION(jpflxsed) :: &
+      sedtrc2l 
+
+   CHARACTER( len = 20 ), DIMENSION(jpflxsed) :: &
+      sedtrc2d , sedtrc2u
+
+
+   REAL(wp), DIMENSION(jpi,jpj,jpksed,jptrased) :: &
+      trcsedi
+
+   REAL(wp), DIMENSION(jpi,jpj,jpflxsed) :: &
+      flxsedi
+
+   !! Units
+   INTEGER, PUBLIC :: &
+     numsed = 27
+	
+#else
+   !!======================================================================
+   !! No Sediment model
+   !!======================================================================
+#endif
+
+END MODULE sed
Index: /trunk/NEMO/TOP_SRC/SED/sedadv.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sedadv.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sedadv.F90	(revision 1179)
@@ -0,0 +1,459 @@
+MODULE sedadv
+#if defined key_sed
+   !!======================================================================
+   !!              ***  MODULE  sedadv  ***
+   !!    Sediment : vertical advection and burial
+   !!=====================================================================
+   !! * Modules used
+   !!----------------------------------------------------------------------
+   !!   sed_adv :
+   !!----------------------------------------------------------------------
+   USE sed     ! sediment global variable
+
+   PUBLIC sed_adv
+
+   !! * Module variable
+   INTEGER, PARAMETER  ::   &
+      nztime = jpksed         ! number of time step between sunrise and sunset
+   !      
+   
+   REAL(wp), DIMENSION(jpksed), SAVE :: &
+      dvolsp, dvolsm, &
+      c2por, ckpor
+
+   REAL(wp), SAVE :: &
+      por1clay , &
+      cpor   
+
+   REAL(wp) :: &
+      eps = 1.e-13
+
+CONTAINS
+
+   SUBROUTINE sed_adv( kt )
+      !!-------------------------------------------------------------------------
+      !!                  ***  ROUTINE sed_adv  ***
+      !!
+      !! ** Purpose : vertical solid sediment advection and burial 
+      !!
+      !! ** Method  : At each grid point the 1-dimensional solid sediment column
+      !!              is shifted according the rain added to the top layer and
+      !!              the gaps produced through redissolution so that in the end
+      !!              the original sediment mixed layer geometry is reestablished.
+      !!
+      !!
+      !!   History :
+      !!        !  98-08 (E. Maier-Reimer, Christoph Heinze )  Original code
+      !!        !  04-10 (N. Emprin, M. Gehlen ) F90
+      !!        !  06-04 (C. Ethe)  Re-organization
+      !!-------------------------------------------------------------------------
+      !!* Arguments
+      INTEGER, INTENT(in) ::  &
+         kt                     ! time step
+      ! * local variables
+
+      INTEGER ::  &
+         ji, jk, js
+
+      INTEGER ::  &
+         jn, ntimes, ikwneg
+      
+      REAL(wp), DIMENSION(jpksed,jpsol) :: zsolcpno
+      REAL(wp), DIMENSION(jpksed)       :: zfilled, zfull, zfromup, zempty
+     
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: zgap, zwb
+      REAL(wp), DIMENSION(jpoce,jpsol)      :: zrainrf
+
+      REAL(wp), DIMENSION(nztime) ::  zraipush
+
+      REAL(wp) :: &
+         zkwnup, zkwnlo, zfrac, &
+         zfromce, zrest
+
+
+      !------------------------------------------------------------------------
+
+
+      IF( kt == nitsed000 ) THEN
+         WRITE(numsed,*) ' '
+         WRITE(numsed,*) ' sed_adv : vertical sediment advection  '
+         WRITE(numsed,*) ' '
+         por1clay = dens * por1(jpksed) * dz(jpksed) / mol_wgt(jsclay)
+         cpor     = por1(jpksed) / por1(2)
+         DO jk = 2, jpksed
+            c2por(jk) = por1(2)      / por1(jk)
+            ckpor(jk) = por1(jpksed) / por1(jk)
+         ENDDO
+         DO jk = jpksedm1, 2, -1
+            dvolsp(jk) = vols(jk+1) / vols(jk)
+         ENDDO
+         DO jk = 3, jpksed
+           dvolsm(jk) = vols(jk-1) / vols(jk)
+        ENDDO
+      ENDIF
+
+
+      ALLOCATE( zgap (jpoce,jpksed) )    ;   ALLOCATE( zwb(jpoce,jpksed) )
+
+
+      ! Initialization of data for mass balance calculation
+      !---------------------------------------------------
+      fromsed(:,:) = 0.
+      tosed  (:,:) = 0. 
+      rloss  (:,:) = 0.
+
+
+      ! Initiate gap 
+      !--------------
+      zgap(:,:) = 0.
+      DO js = 1, jpsol
+         DO jk = 1, jpksed
+            DO ji = 1, jpoce
+               zgap(ji,jk) = zgap(ji,jk) + solcp(ji,jk,js)
+            END DO
+         ENDDO
+      ENDDO
+
+      zgap(1:jpoce,1:jpksed) = 1. - zgap(1:jpoce,1:jpksed)   
+
+
+      ! Initiate burial rates
+      !-----------------------
+      zwb(:,:) = 0.
+      DO jk = 2, jpksed
+         zfrac =  dtsed / ( dens * por1(jk) )     
+         DO ji = 1, jpoce
+            zwb(ji,jk) = zfrac * raintg(ji)
+         END DO
+      ENDDO
+
+
+      DO ji = 1, jpoce
+         zwb(ji,2) = zwb(ji,2) - zgap(ji,2) * dz(2)
+      ENDDO
+
+      DO jk = 3, jpksed
+         zfrac = por1(jk-1) / por1(jk)
+         DO ji = 1, jpoce
+            zwb(ji,jk) = zwb(ji,jk-1) * zfrac - zgap(ji,jk) * dz(jk)
+         END DO
+      ENDDO
+
+
+      zrainrf(:,:) = 0.
+      DO ji = 1, jpoce
+         IF( raintg(ji) /= 0. )  &
+            &   zrainrf(ji,:) = rainrg(ji,:) / raintg(ji)
+      ENDDO
+
+
+      ! Computation of full and empty solid fraction in each layer
+      ! for all 'burial' case
+      !----------------------------------------------------------
+
+
+      DO ji = 1, jpoce
+
+         ! computation of total weight fraction in sediment
+         !-------------------------------------------------
+         zfilled(:) = 0.
+         DO js = 1, jpsol
+            DO jk = 2, jpksed
+               zfilled(jk) = zfilled(jk) + solcp(ji,jk,js)
+            ENDDO
+         ENDDO
+         
+         DO js = 1, jpsol
+            DO jk = 2, jpksed
+               zsolcpno(jk,js) = solcp(ji,jk,js) / zfilled(jk)
+            ENDDO
+         ENDDO
+
+         ! burial  3 cases: 
+         ! zwb > 0 ==> rain > total rection loss 
+         ! zwb = 0 ==> rain = 0
+         ! zwb < 0 ==> rain > 0 and rain < total reaction loss
+         !----------------------------------------------------------------
+
+         IF( zwb(ji,jpksed) > 0. ) THEN
+
+            zfull (jpksed) = zfilled(jpksed)
+            zempty(jpksed) = 1. - zfull(jpksed)
+            DO jk = jpksedm1, 2, -1
+               zfull (jk) = zfilled(jk)
+               zfull (jk) = zfull(jk) - zempty(jk+1) * dvolsp(jk)
+               zempty(jk) = 1. - zfull(jk)
+            ENDDO
+
+            ! Computation of solid sediment species
+            !--------------------------------------
+            ! push entire sediment column downward to account rest of rain
+            DO js = 1, jpsol
+               DO jk = jpksed, 3, -1
+                  solcp(ji,jk,js) = zfull(jk) * zsolcpno(jk,js) + zempty(jk) * zsolcpno(jk-1,js)
+               ENDDO
+
+               solcp(ji,2,js) = zfull(2) * zsolcpno(2,js) + zempty(2) * zrainrf(ji,js)
+
+               DO jk = 2, jpksed
+                  zsolcpno(jk,js) = solcp(ji,jk,js)
+               END DO
+            ENDDO
+
+            zrest = zwb(ji,jpksed) * cpor
+            ! what is remaining is less than dz(2)
+            IF( zrest <= dz(2) ) THEN           
+
+               zfromup(2) = zrest / dz(2)
+               DO jk = 3, jpksed
+                  zfromup(jk) = zwb(ji,jpksed) * ckpor(jk) / dz(jk)
+               ENDDO
+               DO js = 1, jpsol
+                  zfromce = 1. - zfromup(2)
+                  solcp(ji,2,js) = zfromce * zsolcpno(2,js) + zfromup(2) * zrainrf(ji,js)
+                  DO jk = 3, jpksed
+                     zfromce = 1. - zfromup(jk)
+                     solcp(ji,jk,js) = zfromce * zsolcpno(jk,js) + zfromup(jk) * zsolcpno(jk-1,js)
+                  ENDDO
+                  fromsed(ji,js) = 0.
+                  ! quantities to push in deeper sediment
+                  tosed  (ji,js) = zsolcpno(jpksed,js) &
+                     &           * zwb(ji,jpksed) * dens * por1(jpksed) / mol_wgt(js)
+               ENDDO
+               
+            ELSE ! what is remaining is great than dz(2)
+
+               ntimes = INT( zrest / dz(2) ) + 1
+               IF( ntimes > nztime ) THEN
+                  WRITE( numsed,* ) ' sedadv : rest too large at sediment point ji = ', ji
+                  STOP
+               ENDIF
+               zraipush(1) = dz(2)
+               zrest = zrest - zraipush(1)
+               DO jn = 2, ntimes
+                  IF( zrest >= dz(2) ) THEN
+                     zraipush(jn) = dz(2)
+                     zrest = zrest - zraipush(jn)
+                  ELSE
+                     zraipush(jn) = zrest
+                     zrest = 0.
+                  ENDIF
+               ENDDO
+
+               DO jn = 1, ntimes
+                  DO js = 1, jpsol
+                     DO jk = 2, jpksed
+                        zsolcpno(jk,js) = solcp(ji,jk,js)
+                     END DO
+                  ENDDO
+                  
+                  zfromup(2) = zraipush(jn) / dz(2)
+                  DO jk = 3, jpksed
+                     zfromup(jk) = ( zraipush(jn) / dz(jk) ) * c2por(jk)
+                  ENDDO
+
+                  DO js = 1, jpsol
+                     zfromce = 1. - zfromup(2)
+                     solcp(ji,2,js) = zfromce * zsolcpno(2,js) + zfromup(2) * zrainrf(ji,js)
+                     DO jk = 3, jpksed
+                        zfromce = 1. - zfromup(jk)
+                        solcp(ji,jk,js) = zfromce * zsolcpno(jk,js) + zfromup(jk) * zsolcpno(jk-1,js)
+                     ENDDO
+                     fromsed(ji,js) = 0.
+                     tosed  (ji,js) = tosed(ji,js) + zsolcpno(jpksed,js) * zraipush(jn) &
+                        &             * dens * por1(2) / mol_wgt(js)
+                  ENDDO
+               ENDDO
+ 
+            ENDIF
+
+         ELSE IF( raintg(ji) < eps ) THEN ! rain  = 0
+!! Nadia    rloss(:,:) = rainrm(:,:)   bug ??????           
+
+            rloss(ji,1:jpsol) = rainrm(ji,1:jpsol)
+
+            zfull (2) = zfilled(2)
+            zempty(2) = 1. - zfull(2)
+            DO jk = 3, jpksed
+               zfull (jk) = zfilled(jk)
+               zfull (jk) = zfull (jk) - zempty(jk-1) * dvolsm(jk)
+               zempty(jk) = 1. - zfull(jk)
+            ENDDO
+
+            ! fill boxes with weight fraction from underlying box
+            DO js = 1, jpsol
+               DO jk = 2, jpksedm1
+                  solcp(ji,jk,js) = zfull(jk) * zsolcpno(jk,js) + zempty(jk) * zsolcpno(jk+1,js)
+               END DO
+               solcp(ji,jpksed,js) = zsolcpno(jpksed,js) * zfull(jpksed)
+               tosed  (ji,js) = 0.
+               fromsed(ji,js) = 0.
+            ENDDO
+            ! for the last layer, one make go up clay 
+            solcp(ji,jpksed,jsclay) = solcp(ji,jpksed,jsclay) + zempty(jpksed) * 1.
+            !! C. Heinze      fromsed(ji,jsclay) = zempty(jpksed) * 1. * dens * por1(jpksed) / mol_wgt(jsclay)
+            fromsed(ji,jsclay) = zempty(jpksed) * 1. * por1clay
+
+         ELSE  ! rain > 0 and rain < total reaction loss
+
+
+            DO jk = 2, jpksed
+               zfull (jk) = zfilled(jk)
+               zempty(jk) = 1. - zfull(jk)
+            ENDDO
+
+            ! Determination of indice of layer - ikwneg - where advection is reversed
+            !------------------------------------------------------------------------
+ iflag:     DO jk = 2, jpksed
+               IF( zwb(ji,jk) < 0.  ) THEN
+                  ikwneg = jk
+                  EXIT iflag
+               ENDIF
+            ENDDO iflag
+
+            ! computation of zfull and zempty 
+            ! 3 cases : a/ ikwneg=2, b/ikwneg=3...jpksedm1, c/ikwneg=jpksed    
+            !-------------------------------------------------------------      
+            IF( ikwneg == 2 ) THEN ! advection is reversed in the first sediment layer
+
+               zkwnup = rdtsed(ikwneg) * raintg(ji) / dz(ikwneg)
+               zkwnlo = ABS( zwb(ji,ikwneg) ) / dz(ikwneg)
+               zfull (ikwneg+1) = zfilled(ikwneg+1) - zkwnlo * dvolsm(ikwneg+1)
+               zempty(ikwneg+1) = 1. - zfull(ikwneg+1)
+               DO jk = ikwneg+2, jpksed
+                  zfull (jk) = zfilled(jk) - zempty(jk-1) * dvolsm(jk)
+                  zempty(jk) = 1. - zfull(jk)
+               ENDDO
+               DO js = 1, jpsol
+                  solcp(ji,2,js) = zfull(2) * zsolcpno(2,js)+ zkwnlo * zsolcpno(3,js) &
+                     &                                      + zkwnup * zrainrf(ji,js)
+                  DO jk = 3, jpksedm1
+                     solcp(ji,jk,js) = zfull(jk) * zsolcpno(jk,js) + zempty(jk) * zsolcpno(jk+1,js)
+                  ENDDO
+                  solcp(ji,jpksed,js) = zfull(jpksed) * zsolcpno(jpksed,js)
+                  tosed(ji,js)   = 0.
+                  fromsed(ji,js) = 0.
+               ENDDO
+               solcp(ji,jpksed,jsclay) =  solcp(ji,jpksed,jsclay) + zempty(jpksed) * 1.
+               !! C. Heinze  fromsed(ji,jsclay) = zempty(jpksed) * 1. * dens * por1(jpksed) / mol_wgt(jsclay)
+               fromsed(ji,jsclay) = zempty(jpksed) * 1. * por1clay
+               
+            ELSE IF( ikwneg == jpksed ) THEN
+
+               zkwnup = ABS( zwb(ji,ikwneg-1) ) * dvolsm(ikwneg) / dz(ikwneg)
+               zkwnlo = ABS( zwb(ji,ikwneg) ) / dz(ikwneg)
+               zfull (ikwneg-1) = zfilled(ikwneg-1) - zkwnup * dvolsp(ikwneg-1)
+               zempty(ikwneg-1) = 1. - zfull(ikwneg-1)
+               DO jk = ikwneg-2, 2, -1
+                  zfull (jk) = zfilled(jk) - zempty(jk+1) * dvolsp(jk)
+                  zempty(jk) = 1. - zfull(jk) 
+               ENDDO
+               DO  js = 1, jpsol
+                  solcp(ji,2,js) = zfull(2) * zsolcpno(2,js) + zempty(2) * zrainrf(ji,js)
+               ENDDO
+               DO  js = 1, jpsol              
+                  DO jk = jpksedm1, 3, -1
+                     solcp(ji,jk,js) = zfull(jk) * zsolcpno(jk,js) + zempty(jk) * zsolcpno(jk-1,js)
+                  ENDDO
+                  solcp(ji,jpksed,js) = zfull(jpksed) * zsolcpno(jpksed,js) &
+                     &                       + zkwnup * zsolcpno(jpksedm1,js)
+                  tosed(ji,js)   = 0.
+                  fromsed(ji,js) = 0.
+               ENDDO
+               solcp(ji,jpksed,jsclay) = solcp(ji,jpksed,jsclay) + zkwnlo * 1.
+               ! Heinze  fromsed(ji,jsclay) = zkwnlo * 1. * dens * por1(jpksed) / mol_wgt(jsclay)
+               fromsed(ji,jsclay) = zkwnlo * 1.* por1clay
+            ELSE   ! 2 < ikwneg(ji) <= jpksedm1
+
+               zkwnup = ABS( zwb(ji,ikwneg-1) ) * por1(ikwneg-1) / ( dz(ikwneg) * por1(ikwneg) )
+               zkwnlo = ABS( zwb(ji,ikwneg) ) / dz(ikwneg)
+
+               IF( ikwneg > 3 ) THEN
+
+                  zfull (ikwneg-1) = zfilled(ikwneg-1) - zkwnup * dvolsp(ikwneg-1)
+                  zempty(ikwneg-1) = 1. - zfull(ikwneg-1) 
+                  DO jk = ikwneg-2, 2, -1
+                     zfull (jk) = zfilled(jk) - zempty(jk+1) * dvolsp(jk)
+                     zempty(jk)    = 1. - zfull(jk) 
+                  ENDDO
+                  DO js = 1, jpsol
+                     solcp(ji,2,js) = zfull(2) * zsolcpno(2,js) + zempty(2) * zrainrf(ji,js)
+                  ENDDO
+                  DO js = 1, jpsol
+                     DO jk = ikwneg-1, 3, -1
+                        solcp(ji,jk,js) = zfull(jk) * zsolcpno(jk,js) + zempty(jk) * zsolcpno(jk-1,js)
+                     ENDDO
+                  ENDDO
+               ELSE ! ikw = 3
+
+
+                  zfull (2) = zfilled(2) - zkwnup * dvolsm(3)
+                  zempty(2) = 1. - zfull(2)
+                  DO js = 1, jpsol
+                     solcp(ji,2,js) = zfull(2) * zsolcpno(2,js) + zempty(2) * zrainrf(ji,js)
+                  ENDDO
+               ENDIF
+
+               IF( ikwneg < jpksedm1) THEN
+
+                  zfull (ikwneg+1) = zfilled(ikwneg+1) - zkwnlo * dvolsm(ikwneg+1)
+                  zempty(ikwneg+1) = 1. - zfull(ikwneg+1) 
+                  DO jk = ikwneg+2, jpksed
+                     zfull (jk) = zfilled(jk) - zempty(jk-1) * dvolsm(jk)
+                     zempty(jk) = 1. - zfull(jk)
+                  ENDDO
+                  DO js = 1, jpsol
+                     DO jk = ikwneg+1, jpksedm1
+                        solcp(ji,jk,js) = zfull(jk) * zsolcpno(jk,js) + zempty(jk) * zsolcpno(jk+1,js) 
+                     ENDDO
+                     solcp(ji,jpksed,js) = zfull(jpksed) * zsolcpno(jpksed,js)
+                  ENDDO
+                  solcp(ji,jpksed,jsclay) = solcp(ji,jpksed,jsclay) + zempty(jpksed) * 1.
+               ELSE
+
+                  zfull (jpksed) = zfilled(jpksed) - zkwnlo * dvolsm(jpksed)
+                  zempty(jpksed) = 1. - zfull(jpksed)                
+                  DO js = 1, jpsol
+                     solcp(ji,jpksed,js) = zfull(jpksed) * zsolcpno(jpksed,js)
+                  ENDDO
+                  solcp(ji,jpksed,jsclay) = solcp(ji,jpksed,jsclay) + zempty(jpksed) * 1.
+               ENDIF ! jpksedm1
+               
+               ! ikwneg = jpksedm1  ; ikwneg+1 = jpksed ; ikwneg-1 = jpksed - 2
+               DO js = 1, jpsol
+                  solcp(ji,ikwneg,js) =  zfull(ikwneg) * zsolcpno(ikwneg  ,js) &
+                     &                +  zkwnup        * zsolcpno(ikwneg-1,js) &
+                     &                +  zkwnlo        * zsolcpno(ikwneg+1,js)   
+                  tosed  (ji,js)   = 0.
+                  fromsed(ji,js)   = 0.
+               ENDDO
+               ! Heinze  fromsed(ji,jsclay) = zempty * 1. * dens * por1(jpksed) / mol_wgt(jsclay)
+               fromsed(ji,jsclay) = zempty(jpksed) * 1. * por1clay
+            ENDIF ! ikwneg(ji) = 2
+         ENDIF  ! zwb > 0
+      ENDDO  ! ji = 1, jpoce
+
+      rainrm(:,:) = 0.
+      rainrg(:,:) = 0.
+      raintg(:)   = 0.
+
+
+      DEALLOCATE( zgap  ) ;  DEALLOCATE( zwb )
+
+
+   END SUBROUTINE sed_adv
+#else
+   !!======================================================================
+   !! MODULE sedbtb  :   Dummy module 
+   !!======================================================================
+CONTAINS
+   SUBROUTINE sed_adv( kt )         ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'sed_adv: You should not have seen this print! error?', kt
+   END SUBROUTINE sed_adv
+
+   !!======================================================================
+
+#endif
+END MODULE sedadv
+                  
Index: /trunk/NEMO/TOP_SRC/SED/sedarr.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sedarr.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sedarr.F90	(revision 1179)
@@ -0,0 +1,119 @@
+MODULE sedarr
+   !!======================================================================
+   !!                       ***  MODULE sedarr   ***
+   !!              transform 1D (2D) array to a 2D (1D) table
+   !!======================================================================
+#if defined key_sed
+   !!----------------------------------------------------------------------
+   !!   arr_2d_1d  : 2-D to 1-D
+   !!   arr_1d_2d  : 1-D to 2-D
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_sed
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTERFACE pack_arr
+      MODULE PROCEDURE pack_arr_2d_1d , pack_arr_3d_2d 
+   END INTERFACE
+
+   INTERFACE unpack_arr
+      MODULE PROCEDURE unpack_arr_1d_2d , unpack_arr_2d_3d 
+   END INTERFACE
+
+   !! * Routine accessibility
+   PUBLIC pack_arr
+   PUBLIC unpack_arr
+
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limtab.F90,v 1.2 2005/03/27 18:34:42 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE pack_arr_2d_1d ( ndim1d, tab1d, tab2d, tab_ind )
+
+      INTEGER, INTENT(in) ::  ndim1d
+      REAL(wp), DIMENSION (jpi, jpj), INTENT(in) :: tab2d
+      INTEGER, DIMENSION (ndim1d), INTENT (in) :: tab_ind
+      REAL(wp), DIMENSION(ndim1d), INTENT (out) ::  tab1d
+
+      INTEGER ::  jn, jid, jjd
+        
+      DO jn = 1, ndim1d
+         jid        = MOD( tab_ind(jn) - 1, jpi ) + 1
+         jjd        = ( tab_ind(jn) - 1 ) / jpi + 1
+         tab1d(jn)  = tab2d(jid, jjd)
+      END DO 
+
+   END SUBROUTINE pack_arr_2d_1d
+
+   SUBROUTINE unpack_arr_1d_2d ( ndim1d, tab2d, tab_ind, tab1d )
+
+      INTEGER, INTENT ( in) ::  ndim1d
+      INTEGER, DIMENSION (ndim1d) , INTENT (in) ::   tab_ind
+      REAL(wp), DIMENSION(ndim1d), INTENT (in) ::   tab1d  
+      REAL(wp), DIMENSION (jpi, jpj), INTENT ( out) ::  tab2d
+      INTEGER ::  jn, jid, jjd
+
+      DO jn = 1, ndim1d
+         jid             = MOD( tab_ind(jn) - 1, jpi) + 1
+         jjd             =    ( tab_ind(jn) - 1 ) / jpi  + 1
+         tab2d(jid, jjd) = tab1d(jn)
+      END DO
+
+   END SUBROUTINE unpack_arr_1d_2d
+
+   SUBROUTINE pack_arr_3d_2d ( ndim1d, tab2d, tab3d, tab_ind )
+
+      INTEGER, INTENT(in) :: ndim1d      
+      REAL(wp), DIMENSION(jpi,jpj,jpksed), INTENT(in) ::   tab3d      
+      INTEGER, DIMENSION(ndim1d), INTENT (in) ::   tab_ind      
+      REAL(wp), DIMENSION(ndim1d,jpksed), INTENT (out) ::    tab2d 
+      INTEGER, DIMENSION(ndim1d) ::  jid, jjd        
+      INTEGER ::    jk, jn , ji, jj
+      
+      DO jn = 1, ndim1d
+         jid(jn) = MOD( tab_ind(jn) - 1, jpi ) + 1
+         jjd(jn) = ( tab_ind(jn) - 1 ) / jpi + 1
+      END DO
+ 
+      DO jk = 1, jpksed
+         DO jn = 1, ndim1d
+            ji = jid(jn)
+            jj = jjd(jn)
+            tab2d(jn,jk)  = tab3d(ji,jj,jk) 
+         ENDDO
+      ENDDO
+      
+   END SUBROUTINE pack_arr_3d_2d
+
+
+   SUBROUTINE unpack_arr_2d_3d ( ndim1d, tab3d, tab_ind, tab2d )
+
+      INTEGER, INTENT(in) :: ndim1d      
+      REAL(wp), DIMENSION(ndim1d,jpksed), INTENT(in) ::   tab2d      
+      INTEGER, DIMENSION(ndim1d), INTENT (in) ::   tab_ind      
+      REAL(wp), DIMENSION(jpi,jpj,jpksed), INTENT (out) ::    tab3d 
+      INTEGER, DIMENSION(ndim1d) ::  jid, jjd        
+      INTEGER ::   jk, jn , ji, jj
+
+     DO jn = 1, ndim1d
+         jid(jn) = MOD( tab_ind(jn) - 1, jpi ) + 1
+         jjd(jn) = ( tab_ind(jn) - 1 ) / jpi + 1
+      END DO
+ 
+      DO jk = 1, jpksed
+         DO jn = 1, ndim1d
+            ji = jid(jn)
+            jj = jjd(jn)
+            tab3d(ji, jj, jk) = tab2d(jn,jk)
+         ENDDO
+      ENDDO
+
+   END SUBROUTINE unpack_arr_2d_3d
+
+#endif
+END MODULE sedarr
Index: /trunk/NEMO/TOP_SRC/SED/sedbtb.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sedbtb.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sedbtb.F90	(revision 1179)
@@ -0,0 +1,93 @@
+MODULE sedbtb
+#if defined key_sed
+   !!======================================================================
+   !!              ***  MODULE  sedbtb  ***
+   !!    Sediment : bioturbation of the solid components
+   !!=====================================================================
+   !! * Modules used
+   USE sed     ! sediment global variable
+   USE sedmat  ! linear system of equations
+
+   PUBLIC sed_btb
+
+
+CONTAINS
+   
+   SUBROUTINE sed_btb( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sed_btb  ***
+      !!
+      !! ** Purpose :  performs bioturbation of the solid sediment components
+      !!
+      !! ** Method  :  ``diffusion'' of solid sediment components. 
+      !!
+      !!   History :
+      !!        !  98-08 (E. Maier-Reimer, Christoph Heinze )  Original code
+      !!        !  04-10 (N. Emprin, M. Gehlen ) F90
+      !!        !  06-04 (C. Ethe)  Re-organization
+      !!----------------------------------------------------------------------
+      !!* Arguments
+      INTEGER, INTENT(in) ::  &
+         kt              ! time step
+
+      ! * local variables
+
+      INTEGER :: &
+         ji, jk, js
+
+      REAL(wp), DIMENSION(:,:,:) , ALLOCATABLE ::  &
+         zsol                      ! solution
+      !------------------------------------------------------------------------
+
+      IF( kt == nitsed000 ) THEN
+         WRITE(numsed,*) ' sed_btb : Bioturbation  '
+         WRITE(numsed,*) ' '
+      ENDIF
+
+      ! Initializations
+      !----------------
+      ALLOCATE( zsol(jpoce,jpksedm1,jpsol) )
+
+      zsol(:,:,:) = 0.
+
+
+      ! right hand side of coefficient matrix
+      !--------------------------------------
+      DO js = 1, jpsol
+         DO jk = 1, jpksedm1
+            DO ji = 1, jpoce
+               zsol(ji,jk,js) = solcp(ji,jk+1,js)
+            ENDDO
+         ENDDO
+      ENDDO
+
+      CALL sed_mat( jpsol, jpoce, jpksedm1, zsol )
+
+
+      ! store solution of the tridiagonal system
+      !------------------------
+      DO js = 1, jpsol
+         DO jk = 1, jpksedm1
+            DO ji = 1, jpoce
+               solcp(ji,jk+1,js) = zsol(ji,jk,js)
+            ENDDO
+         ENDDO
+      ENDDO
+     
+      DEALLOCATE( zsol )
+
+   END SUBROUTINE sed_btb
+#else
+   !!======================================================================
+   !! MODULE sedbtb  :   Dummy module 
+   !!======================================================================
+CONTAINS
+   SUBROUTINE sed_btb( kt )         ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'sed_btb: You should not have seen this print! error?', kt
+   END SUBROUTINE sed_btb
+
+   !!======================================================================
+
+#endif
+END MODULE sedbtb
Index: /trunk/NEMO/TOP_SRC/SED/sedchem.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sedchem.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sedchem.F90	(revision 1179)
@@ -0,0 +1,583 @@
+MODULE sedchem
+
+#if defined key_sed 
+   !!======================================================================
+   !!                        ***  Module sedchem  ***
+   !! sediment :   Variable for chemistry of the CO2 cycle
+   !!======================================================================
+   !!   modules used
+   USE sed     ! sediment global variable
+   USE sedarr
+
+   !! * Accessibility
+   PUBLIC sed_chem   
+
+   !! * Module variables
+   REAL(wp) :: &
+      salchl = 1./1.80655 , & ! conversion factor for salinity --> chlorinity (Wooster et al. 1969)
+      calcon = 1.03E-2        ! mean calcite concentration [Ca2+] in sea water [mole/kg solution] 
+
+   REAL(wp) :: &              ! coeff. for 1. dissoc. of carbonic acid (Millero, 1995)   
+      c10 = 3670.7   , &
+      c11 = 62.008   , &
+      c12 = 9.7944   , &
+      c13 = 0.0118   , &
+      c14 = 0.000116
+
+   REAL(wp) :: &              ! coeff. for 2. dissoc. of carbonic acid (Millero, 1995)   
+      c20 = 1394.7   , &
+      c21 = 4.777    , &
+      c22 = 0.       , &
+      c23 = 0.0184   , &
+      c24 = 0.000118
+
+   REAL(wp) :: &              ! coeff. for 1. dissoc. of boric acid (Dickson and Goyet, 1994)
+      cb0  = -8966.90, &
+      cb1  = -2890.53, &
+      cb2  = -77.942 , &
+      cb3  = 1.728   , &
+      cb4  = -0.0996 , &
+      cb5  = 148.0248, &
+      cb6  = 137.1942, &
+      cb7  = 1.62142 , &
+      cb8  = -24.4344, &
+      cb9  = -25.085 , &
+      cb10 = -0.2474 , &
+      cb11 = 0.053105
+
+   REAL(wp) :: &             ! borat constants
+      bor1 = 0.000232, &
+      bor2 = 1./10.811
+
+   REAL(wp) :: &             ! constants for calculate concentrations 
+      st1  = 0.14     , &    ! for sulfate (Morris & Riley 1966)
+      st2  = 1./96.062, &
+      ks0  = 141.328  , &
+      ks1  = -4276.1  , &
+      ks2  = -23.093  , &
+      ks3  = -13856.  , &
+      ks4  = 324.57   , &
+      ks5  = -47.986  , &
+      ks6  = 35474.   , &
+      ks7  = -771.54  , &
+      ks8  = 114.723  , &
+      ks9  = -2698.   , &
+      ks10 = 1776.    , &
+      ks11 = 1.       , &
+      ks12 = -0.001005 
+
+   REAL(wp) :: &             ! constants for calculate concentrations 
+      ft1  = 0.000067   , &  ! fluorides (Dickson & Riley 1979 )
+      ft2  = 1./18.9984 , &
+      kf0  = -12.641    , &
+      kf1  = 1590.2     , &
+      kf2  = 1.525      , &
+      kf3  = 1.0        , &
+      kf4  =-0.001005
+
+   REAL(wp) :: &             ! coeff. for dissoc. of water (Dickson and Riley, 1979 )
+      cw0 = -13847.26  , &
+      cw1 = 148.9802   , &
+      cw2 = -23.6521   , &
+      cw3 = 118.67     , &
+      cw4 = -5.977     , &
+      cw5 = 1.0495     , &
+      cw6 = -0.01615
+ 
+   REAL(wp) :: &             ! coeff. for dissoc. of phosphate (Millero (1974)
+      cp10 = 115.54    , &
+      cp11 = -4576.752 , &
+      cp12 = -18.453   , &
+      cp13 = -106.736  , &
+      cp14 = 0.69171   , &
+      cp15 = -0.65643  , &
+      cp16 = -0.01844  , &
+      cp20 = 172.1033  , &
+      cp21 = -8814.715 , &
+      cp22 = -27.927   , &
+      cp23 = -160.340  , &
+      cp24 = 1.3566    , &
+      cp25 = 0.37335   , &
+      cp26 = -0.05778  , &
+      cp30 = -18.126   , &
+      cp31 = -3070.75  , &
+      cp32 = 17.27039  , &
+      cp33 = 2.81197   , &
+      cp34 = -44.99486 , &
+      cp35 = -0.09984
+
+   REAL(wp) :: &             ! coeff. for dissoc. of silicates (Millero (1974)  
+      cs10 = 117.40    , &  
+      cs11 = -8904.2   , & 
+      cs12 = -19.334   , & 
+      cs13 = -458.79   , & 
+      cs14 = 3.5913    , & 
+      cs15 = 188.74    , & 
+      cs16 = -1.5998   , & 
+      cs17 = -12.1652  , & 
+      cs18 = 0.07871   , & 
+      cs19 = 0.        , & 
+      cs20 = 1.        , & 
+      cs21 = -0.001005
+
+   REAL(wp) :: &            ! coeff. for apparent solubility equilibrium 
+      ! akcc1 = -34.452 , & ! of calcite (Ingle,1975,  1800, eq. 6)
+      ! akcc2 = -39.866 , &  
+      ! akcc3 = 110.21  , &  
+      ! akcc4 = -7.5752E-6  
+      akcc1 = -171.9065 , &    ! Millero et al. 1995 from Mucci 1983
+      akcc2 = -0.077993 , &  
+      akcc3 = 2839.319  , &  
+      akcc4 = 71.595    , &  
+      akcc5 = -0.77712  , &  
+      akcc6 = 0.0028426 , &  
+      akcc7 = 178.34    , &  
+      akcc8 = -0.07711  , &  
+      akcc9 = 0.0041249
+
+   REAL(wp) :: &                 ! universal gas constant
+      rgas = 83.145              ! bar.cm3/(mol.K) or R=8.31451 J/(g.mol.K)
+
+
+   ! coeff. for seawater pressure correction (millero 95)		
+   REAL(wp), DIMENSION(8)  :: & 
+      devk1, devk2, devk3, devk4, devk5
+
+   DATA devk1/ -25.5   , -15.82    , -29.48  , -25.60    , -48.76    , -14.51   , -23.12   , -26.57   /   
+   DATA devk2/ 0.1271  , -0.0219   , 0.1622  , 0.2324    , -0.5304   , 0.1211   ,  0.1758  , 0.2020   /   
+   DATA devk3/ 0.      , 0.        , 2.608E-3, -3.6246E-3, 0.        , -0.321E-3, -2.647E-3, -3.042E-3/   
+   DATA devk4/-3.08E-3 , 1.13E-3   , -2.84E-3, -5.13E-3  , -11.76E-3 , -2.67E-3 , -5.15E-3 , -4.08E-3 /   
+   DATA devk5/0.0877E-3, -0.1475E-3, 0.      , 0.0794E-3 , -0.3692E-3, 0.0427E-3,  0.09E-3 , 0.0714E-3/
+
+
+   ! coeff. for density of sea water (Millero & Poisson 1981) 
+   REAL(wp), DIMENSION(5)  :: Adsw                       
+   DATA Adsw/8.24493E-1, -4.0899E-3, 7.6438E-5 , -8.246E-7, 5.3875E-9 /
+
+   REAL(wp), DIMENSION(3)  :: Bdsw 
+   DATA Bdsw / -5.72466E-3, 1.0227E-4, -1.6546E-6 /
+
+   REAL(wp)  :: Cdsw = 4.8314E-4
+
+   REAL(wp), DIMENSION(6)  :: Ddsw                    
+   DATA Ddsw / 999.842594 , 6.793952E-2 , -9.095290E-3, 1.001685E-4, -1.120083E-6, 6.536332E-9/
+
+
+   !! * Module variables
+   REAL(wp), DIMENSION(jpi,jpj,10) :: &
+      chem_data
+
+CONTAINS
+
+   SUBROUTINE sed_chem( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_chem  ***
+      !!
+      !! ** Purpose :   set chemical constants
+      !!
+      !!   History :
+      !!        !  04-10  (N. Emprin, M. Gehlen )  Original code
+      !!        !  06-04  (C. Ethe)  Re-organization
+      !!----------------------------------------------------------------------
+      !!* Arguments
+      INTEGER, INTENT(in) ::  &
+         kt                     ! time step
+
+#if ! defined key_sed_off
+      INTEGER :: &
+         ji, jj, ikt
+
+      REAL(wp) :: &
+         ztkel, ztc, ztc2, zpres, ztr ,   &
+         zsal, zsal2, zsqrt, zsal15   ,   &
+         zis, zis2, zisqrt            ,   &
+         zdens0, zaw, zbw, zcw        ,   &
+         zbuf1, zbuf2 ,   & 
+         zcpexp, zcpexp2              ,   &
+         zck1p, zck2p, zck3p, zcksi   
+
+     REAL(wp), DIMENSION(jpi,jpj,6) :: &
+        zchem_data
+
+#endif
+      !!----------------------------------------------------------------------
+
+      IF( MOD( kt - 1, nfreq ) /= 0 ) RETURN
+
+      WRITE(numsed,*) ' Getting Chemical constants from tracer model at time kt = ', kt
+      WRITE(numsed,*) ' '
+
+
+#if defined key_sed_off
+      CALL sed_chem_off
+#else
+      ! reading variables
+      zchem_data(:,:,:) = 0.
+      DO jj = 1,jpj
+         DO ji = 1, jpi
+            ikt = MAX( mbathy(ji,jj)-1, 1 )
+            IF ( tmask(ji,jj,ikt) == 1 ) THEN
+               zchem_data(ji,jj,1) = ak13 (ji,jj,ikt)
+               zchem_data(ji,jj,2) = ak23 (ji,jj,ikt)
+               zchem_data(ji,jj,3) = akb3 (ji,jj,ikt)
+               zchem_data(ji,jj,4) = akw3 (ji,jj,ikt)
+               zchem_data(ji,jj,5) = aksp (ji,jj,ikt)
+               zchem_data(ji,jj,6) = borat(ji,jj,ikt)
+            ENDIF
+         ENDDO
+      ENDDO
+
+      CALL pack_arr ( jpoce, ak1s  (1:jpoce), zchem_data(1:jpi,1:jpj,1), iarroce(1:jpoce) )
+      CALL pack_arr ( jpoce, ak2s  (1:jpoce), zchem_data(1:jpi,1:jpj,2), iarroce(1:jpoce) )
+      CALL pack_arr ( jpoce, akbs  (1:jpoce), zchem_data(1:jpi,1:jpj,3), iarroce(1:jpoce) )
+      CALL pack_arr ( jpoce, akws  (1:jpoce), zchem_data(1:jpi,1:jpj,4), iarroce(1:jpoce) )
+      CALL pack_arr ( jpoce, aksps (1:jpoce), zchem_data(1:jpi,1:jpj,5), iarroce(1:jpoce) )
+      CALL pack_arr ( jpoce, borats(1:jpoce), zchem_data(1:jpi,1:jpj,6), iarroce(1:jpoce) )
+
+      DO ji = 1, jpoce
+         ztkel   = temp(ji) + 273.16
+         ztc     = temp(ji)
+         ztc2    = ztc * ztc
+         zpres   = press(ji)
+         ! zqtt    = ztkel * 0.01
+         zsal    = salt(ji)
+         zsal2   = zsal * zsal 
+         zsqrt   = SQRT( zsal )
+         zsal15  = zsqrt * zsal
+         zlogt   = LOG( ztkel )
+         ztr     = 1./ ztkel
+         ! zis=ionic strength (ORNL/CDIAC-74, DOE 94,Dickson and Goyet)
+         zis     = 19.924 * zsal / ( 1000. - 1.005 * zsal )
+         zis2    = zis * zis
+         zisqrt  = SQRT( zis )
+
+         ! Density of Sea Water - F(temp,sal) [kg/m3]
+         zdens0 =  Ddsw(1) + Ddsw(2) * ztc + Ddsw(3) * ztc2 &
+                  + Ddsw(4) * ztc * ztc2 + Ddsw(5) * ztc2 * ztc2 &
+                  + Ddsw(6) * ztc * ztc2 * ztc2
+         zaw =  Adsw(1) + Adsw(2) * ztc + Adsw(3)* ztc2 + Adsw(4) * ztc * ztc2 &
+              + Adsw(5) * ztc2 * ztc2
+         zbw =  Bdsw(1) + Bdsw(2) * ztc + Bdsw(3) * ztc2
+         zcw =  Cdsw
+         densSW(ji) = zdens0 + zaw * zsal + zbw * zsal15 + zcw * zsal * zsal
+         densSW(ji) = densSW(ji) * 1E-3   ! to get dens in [kg/l]
+
+         ! FORMULA FOR CPEXP AFTER EDMOND AND GIESKES (1970) 
+         ! (REFERENCE TO CULBERSON AND PYTKOQICZ (1968) AS MADE IN BROECKER ET AL. (1982) 
+         ! IS INCORRECT; HERE RGAS IS TAKEN TENFOLD TO CORRECT FOR THE NOTATION OF pres  IN
+         ! DBAR INSTEAD OF BAR AND THE EXPRESSION FOR CPEXP IS MULTIPLIED BY LN(10.) 
+         ! TO ALLOW USE OF EXP-FUNCTION WITH BASIS E IN THE FORMULA FOR AKSPP 
+         ! (CF. EDMOND AND GIESKES (1970), P. 1285 AND P. 1286 (THE SMALL FORMULA ON P. 1286 
+         ! IS RIGHT AND CONSISTENT WITH THE SIGN IN PARTIAL MOLAR VOLUME CHANGE AS SHOWN ON P. 1285)
+         !-----------------------------------------------------------------------------------------
+         zcpexp  = zpres / ( rgas*ztkel )
+         zcpexp2 = zpres * zcpexp
+
+         ! For Phodphates (phosphoric acid) (DOE 1994)
+         !----------------------------------------------
+         zck1p = cp10 + cp11*ztr + cp12*zlogt + ( cp13*ztr + cp14 ) * zsqrt &
+            &      + ( cp15*ztr + cp16 ) * zsal
+         zck2p = cp20 + cp21*ztr + cp22*zlogt + ( cp23*ztr + cp24 ) * zsqrt &
+            &      + ( cp25*ztr + cp26 ) * zsal
+         zck3p = cp30 + cp31*ztr + ( cp32*ztr + cp33 ) *  zsqrt &
+            &      + ( cp34*ztr + cp35 ) * zsal
+
+         ! For silicates (DOE 1994) change to mol/kg soln) (OCMIP)
+         !--------------------------------------------------------
+         zcksi = cs10 + cs11*ztr + cs12*zlogt + ( cs13*ztr + cs14) * zisqrt &
+            &      + ( cs15*ztr + cs16 ) * zis &
+            &      + ( cs17*ztr + cs18 ) * zis2 &
+            &      + LOG( 1. + cs19*zsal ) + LOG( cs20 + cs21*zsal )
+
+
+         !K1, K2 of carbonic acid, KB of boric acid, KW (H2O)
+         !---------------------------------------------------
+         zak1p  = EXP ( zck1p  )
+         zak2p  = EXP ( zck2p  )
+         zak3p  = EXP ( zck3p  )
+         zaksil = EXP ( zcksi  )
+
+         zbuf1       = - ( devk1(3) + devk2(3)*ztc + devk3(3)*ztc2 )
+         zbuf2       = 0.5 * ( devk4(3) + devk5(3)*ztc )
+         aksis(ji)     = zaksil * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 )
+
+         zbuf1       = - ( devk1(6) + devk2(6)*ztc + devk3(6)*ztc2 )
+         zbuf2       = 0.5 * ( devk4(6) + devk5(6)*ztc )
+         ak1ps(ji)   = zak1p * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 )
+ 
+         zbuf1       = - ( devk1(7) + devk2(7)*ztc + devk3(7)*ztc2 )
+         zbuf2       = 0.5 * ( devk4(7) + devk5(7)*ztc )
+         ak2ps(ji)   = zak2p * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 )
+
+         zbuf1       = - ( devk1(8) + devk2(8)*ztc + devk3(8)*ztc2 )
+         zbuf2       = 0.5 * ( devk4(8) + devk5(8)*ztc )
+         ak3ps(ji)   = zak3p * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 )
+
+         ak12s  (ji) = ak1s (ji) * ak2s (ji)
+         ak12ps (ji) = ak1ps(ji) * ak2ps(ji)
+         ak123ps(ji) = ak1ps(ji) * ak2ps(ji) * ak3ps(ji)
+
+         calcon2(ji) = 0.01028 * ( salt(ji) / 35. ) * densSW(ji)
+#endif
+      ENDDO
+
+   END SUBROUTINE sed_chem
+
+#if defined key_sed_off
+
+   SUBROUTINE sed_chem_off
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_chem_off  ***
+      !!                    
+      !! ** Purpose :   compute chemical constants
+      !!
+      !!   History :
+      !!        !  04-10  (N. Emprin, M. Gehlen )  Original code
+      !!        !  06-04  (C. Ethe)  Re-organization 
+      !!----------------------------------------------------------------------  
+      !!* Arguments
+      INTEGER, INTENT(in) ::  &
+         kt                     ! time step
+
+      !! * Local declarations
+      INTEGER :: &
+         ji
+
+      REAL(wp) :: &
+         ztkel, ztc, ztc2, zpres, ztr ,   &
+         zsal, zsal2, zsqrt, zsal15   ,   &
+         zis, zis2, zisqrt            ,   &
+         zdens0, zaw, zbw, zcw        ,   &
+         zchl, zst, zft, zbuf1, zbuf2 ,   & 
+         zcpexp, zcpexp2              ,   &
+         zckb, zck1, zck2, zckw       ,   &
+         zck1p, zck2p, zck3p, zcksi   ,   &
+         zak1, zak2, zakb, zakw       ,   &        
+         zaksp0, zksp, zks, zkf 
+
+
+      ! CHEMICAL CONSTANTS - DEEP OCEAN
+      !-------------------------------------
+      ! [chem constants]=mol/kg solution (or (mol/kg sol)2 for akws and aksp)
+
+      DO ji = 1, jpoce
+         ztkel   = temp(ji) + 273.16
+         ztc     = temp(ji)
+         ztc2    = ztc * ztc
+         zpres   = press(ji)
+         ! zqtt    = ztkel * 0.01
+         zsal    = salt(ji)
+         zsal2   = zsal * zsal 
+         zsqrt   = SQRT( zsal )
+         zsal15  = zsqrt * zsal
+         zlogt   = LOG( ztkel )
+         ztr     = 1./ ztkel
+         ! zis=ionic strength (ORNL/CDIAC-74, DOE 94,Dickson and Goyet)
+         zis     = 19.924 * zsal / ( 1000. - 1.005 * zsal )
+         zis2    = zis * zis
+         zisqrt  = SQRT( zis )
+
+
+         ! Density of Sea Water - F(temp,sal) [kg/m3]
+         zdens0 =  Ddsw(1) + Ddsw(2) * ztc + Ddsw(3) * ztc2 &
+                  + Ddsw(4) * ztc * ztc2 + Ddsw(5) * ztc2 * ztc2 &
+                  + Ddsw(6) * ztc * ztc2 * ztc2
+         zaw =  Adsw(1) + Adsw(2) * ztc + Adsw(3)* ztc2 + Adsw(4) * ztc * ztc2 &
+              + Adsw(5) * ztc2 * ztc2
+         zbw =  Bdsw(1) + Bdsw(2) * ztc + Bdsw(3) * ztc2
+         zcw =  Cdsw
+         densSW(ji) = zdens0 + zaw * zsal + zbw * zsal15 + zcw * zsal * zsal
+         densSW(ji) = densSW(ji) * 1E-3   ! to get dens in [kg/l]
+
+
+         ! FORMULA FOR CPEXP AFTER EDMOND AND GIESKES (1970) 
+         ! (REFERENCE TO CULBERSON AND PYTKOQICZ (1968) AS MADE IN BROECKER ET AL. (1982) 
+         ! IS INCORRECT; HERE RGAS IS TAKEN TENFOLD TO CORRECT FOR THE NOTATION OF pres  IN
+         ! DBAR INSTEAD OF BAR AND THE EXPRESSION FOR CPEXP IS MULTIPLIED BY LN(10.) 
+         ! TO ALLOW USE OF EXP-FUNCTION WITH BASIS E IN THE FORMULA FOR AKSPP 
+         ! (CF. EDMOND AND GIESKES (1970), P. 1285 AND P. 1286 (THE SMALL FORMULA ON P. 1286 
+         ! IS RIGHT AND CONSISTENT WITH THE SIGN IN PARTIAL MOLAR VOLUME CHANGE AS SHOWN ON P. 1285)
+         !-----------------------------------------------------------------------------------------
+         zcpexp  = zpres / ( rgas*ztkel )
+         zcpexp2 = zpres * zcpexp
+
+
+         ! chlorinity (WOOSTER ET AL., 1969)
+         !---------------------------------------
+         zchl = zsal * salchl
+
+         ! total sulfate concentration [mol/kg soln]
+         ! --------------------------------------
+         zst = st1 * zchl * st2
+
+         ! total fluoride concentration [mol/kg soln]
+         ! --------------------------------------
+         zft = ft1 * zchl * ft2
+
+         ! dissociation constant for carbonate (Mehrback 74 - Dickson & Millero 87)
+         !---------------------------------------------------------------------------
+         zck1 = c10*ztr - c11 + c12*zlogt - c13*zsal + c14*zsal2
+         zck2 = c20*ztr + c21 - c22*zlogt - c23*zsal + c24*zsal2
+
+         ! dissociation constant for sulfates (Dickson 1990)
+         !--------------------------------------------------
+         zks = EXP(  ks0 + ks1*ztr + ks2*zlogt &
+            &    + ( ks3*ztr + ks4 + ks5*zlogt ) * zisqrt &
+            &    + ( ks6*ztr + ks7 + ks8*zlogt ) * zis    &
+            &    +   ks9*ztr*zis*zisqrt + ks10*ztr*zis2   &
+            &    +   LOG( ks11 + ks12*zsal ) )
+
+         ! dissociation constant for fluorides (Dickson and Riley 79)
+         !--------------------------------------------------
+         zkf = EXP( kf0 + kf1*ztr + kf2*zisqrt + LOG( kf3 + kf4*zsal ) )
+
+         ! dissociation constant for borates (Doe 94)
+         !--------------------------------------------------
+         zckb = (  cb0 + cb1*zsqrt + cb2*zsal + cb3*zsal15 + cb4*zsal2) * ztr &
+            &  + ( cb5 + cb6*zsqrt + cb7*zsal) &
+            &  + ( cb8 + cb9*zsqrt + cb10*zsal) * zlogt &
+            &  +   cb11*zsqrt*ztkel + LOG( ( 1. + zst/zks + zft/zkf ) / ( 1. + zst/zks ) ) 
+
+         ! PKW (H2O) (DICKSON AND RILEY, 1979)
+         !--------------------------------------
+         zckw =   cw0*ztr + cw1 + cw2*zlogt &
+            & +( cw3*ztr + cw4 + cw5*zlogt )* zsqrt + cw6*zsal
+         
+         ! For Phodphates (phosphoric acid) (DOE 1994)
+         !----------------------------------------------
+         zck1p = cp10 + cp11*ztr + cp12*zlogt + ( cp13*ztr + cp14 ) * zsqrt &
+            &      + ( cp15*ztr + cp16 ) * zsal
+         zck2p = cp20 + cp21*ztr + cp22*zlogt + ( cp23*ztr + cp24 ) * zsqrt &
+            &      + ( cp25*ztr + cp26 ) * zsal
+         zck3p = cp30 + cp31*ztr + ( cp32*ztr + cp33 ) *  zsqrt &
+            &      + ( cp34*ztr + cp35 ) * zsal
+
+         ! For silicates (DOE 1994) change to mol/kg soln) (OCMIP)
+         !--------------------------------------------------------
+         zcksi = cs10 + cs11*ztr + cs12*zlogt + ( cs13*ztr + cs14) * zisqrt &
+            &      + ( cs15*ztr + cs16 ) * zis &
+            &      + ( cs17*ztr + cs18 ) * zis2 &
+            &      + LOG( 1. + cs19*zsal ) + LOG( cs20 + cs21*zsal )
+
+         ! apparent solublity product K'SP of calcite in seawater
+         ! (S=27-43, T=2-25 DEG C) AT pres =0 (INGLE, 1975, EQ. 6)
+         ! prob: olivier a log = ln et C. Heize a LOG10(sal)
+         ! aksp0 = 1.E-7*(akcc1+akcc2*sal**(1./3.)+akcc3*log(sal)+akcc4*tkel*tkel)
+         ! aksp0 = 1.E-7*(akcc1+akcc2*sal**(1./3.)+akcc3*log10(sal)+akcc4*tkel*tkel)
+         !--------------------------------------------------------------------
+         zaksp0 = akcc1 + akcc2*ztkel + akcc3*ztr + akcc4 * LOG10(ztkel) &
+            &  + ( akcc5 + akcc6*ztkel+ akcc7*ztr ) * zsqrt &
+            &  +  akcc8*zsal + akcc9*zsal15
+
+         !K1, K2 of carbonic acid, KB of boric acid, KW (H2O)
+         !---------------------------------------------------
+         zak1   = 10**( -zck1  )
+         zak2   = 10**( -zck2  )
+         zakb   = EXP ( zckb   ) 
+         zakw   = EXP ( zckw   )
+         zksp   = 10**( zaksp0 )
+
+
+
+         ! KB of boric acid, K1,K2 of carbonic acid pressure correction 
+         ! after Culberson and  AND Pytkowicz (1968) (CF. BROECKER ET AL., 1982) Millero 95
+         !--------------------------------------------------------------------------------
+         zbuf1       = - ( devk1(1) + devk2(1)*ztc + devk3(1)*ztc2 )
+         zbuf2       = 0.5 * ( devk4(1) + devk5(1)*ztc )
+         ak1s(ji)    = zak1 * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 )
+
+         zbuf1       = -( devk1(2) + devk2(2)*ztc + devk3(2)*ztc2 )
+         zbuf2       = 0.5 * ( devk4(2) + devk5(2)*ztc )
+         ak2s(ji)    = zak2 * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 )
+
+         zbuf1       = - ( devk1(3) + devk2(3)*ztc + devk3(3)*ztc2 )
+         zbuf2       = 0.5 * ( devk4(3) + devk5(3) * ztc )
+         akbs(ji)    = zakb * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 )
+
+         zbuf1       = - ( devk1(4) + devk2(4)*ztc + devk3(4)*ztc2 )
+         zbuf2       = 0.5 * ( devk4(4) + devk5(4)*ztc )
+         akws(ji)    = zakw * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 )
+
+
+         ! APPARENT SOLUBILITY PRODUCT K''SP OF CALCITE (OR ARAGONITE)
+         ! AS FUNCTION OF PRESSURE FOLLWING EDMOND AND GIESKES (1970)
+         ! (P. 1285) AND BERNER (1976)
+         !-----------------------------------------------------------------
+         ! aksp(ji) = aksp0*exp(zcpexp*(devks-devkst*tc))
+         ! or following Mucci
+         zbuf1      = - ( devk1(5) + devk2(5)*ztc + devk3(5)*ztc2 )
+         zbuf2      = 0.5 *( devk4(5) + devk5(5)*ztc )
+         aksps(ji)   = zksp * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 )
+
+         ! For Phodphates (phosphoric acid) (DOE 1994)
+         !----------------------------------------------
+         zck1p = cp10 + cp11*ztr + cp12*zlogt + ( cp13*ztr + cp14 ) * zsqrt &
+            &      + ( cp15*ztr + cp16 ) * zsal
+         zck2p = cp20 + cp21*ztr + cp22*zlogt + ( cp23*ztr + cp24 ) * zsqrt &
+            &      + ( cp25*ztr + cp26 ) * zsal
+         zck3p = cp30 + cp31*ztr + ( cp32*ztr + cp33 ) *  zsqrt &
+            &      + ( cp34*ztr + cp35 ) * zsal
+
+         ! For silicates (DOE 1994) change to mol/kg soln) (OCMIP)
+         !--------------------------------------------------------
+         zcksi = cs10 + cs11*ztr + cs12*zlogt + ( cs13*ztr + cs14) * zisqrt &
+            &      + ( cs15*ztr + cs16 ) * zis &
+            &      + ( cs17*ztr + cs18 ) * zis2 &
+            &      + LOG( 1. + cs19*zsal ) + LOG( cs20 + cs21*zsal )
+
+
+         !K1, K2 of carbonic acid, KB of boric acid, KW (H2O)
+         !---------------------------------------------------
+         zak1p  = EXP ( zck1p  )
+         zak2p  = EXP ( zck2p  )
+         zak3p  = EXP ( zck3p  )
+         zaksil = EXP ( zcksi  )
+
+         zbuf1       = - ( devk1(3) + devk2(3)*ztc + devk3(3)*ztc2 )
+         zbuf2       = 0.5 * ( devk4(3) + devk5(3)*ztc )
+         aksis(ji)     = zaksil * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 )
+
+         zbuf1       = - ( devk1(6) + devk2(6)*ztc + devk3(6)*ztc2 )
+         zbuf2       = 0.5 * ( devk4(6) + devk5(6)*ztc )
+         ak1ps(ji)   = zak1p * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 )
+ 
+         zbuf1       = - ( devk1(7) + devk2(7)*ztc + devk3(7)*ztc2 )
+         zbuf2       = 0.5 * ( devk4(7) + devk5(7)*ztc )
+         ak2ps(ji)   = zak2p * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 )
+
+         zbuf1       = - ( devk1(8) + devk2(8)*ztc + devk3(8)*ztc2 )
+         zbuf2       = 0.5 * ( devk4(8) + devk5(8)*ztc )
+         ak3ps(ji)   = zak3p * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 )
+
+         ! total borat concentration. [mol/l]
+         ! or from Millero 1995 [mol/l] : borat(l) = 0.000416_8*(sal/35._8)*densSW(l)
+         ! --------------------------------------------------------------------------
+         borats(ji) = bor1 * zchl * bor2 * densSW(ji)
+
+         ak12s  (ji) = ak1s (ji) * ak2s (ji)
+         ak12ps (ji) = ak1ps(ji) * ak2ps(ji)
+         ak123ps(ji) = ak1ps(ji) * ak2ps(ji) * ak3ps(ji)
+
+         calcon2(ji) = 0.01028 * ( zsal / 35. ) * densSW(ji)
+
+      ENDDO
+
+   END SUBROUTINE sed_chem_off
+
+#endif
+
+#else
+   !!======================================================================
+   !! MODULE sedchem  :   Dummy module 
+   !!======================================================================
+CONTAINS
+   SUBROUTINE sed_chem( kt )         ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_stp: You should not have seen this print! error?', kt
+   END SUBROUTINE sed_chem
+
+   !!======================================================================
+
+#endif
+
+END MODULE sedchem
Index: /trunk/NEMO/TOP_SRC/SED/sedco3.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sedco3.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sedco3.F90	(revision 1179)
@@ -0,0 +1,213 @@
+MODULE sedco3
+#if defined key_sed
+   !!======================================================================
+   !!              ***  MODULE  sedco3  ***
+   !!    Sediment : carbonate in sediment pore water
+   !!=====================================================================
+   !! * Modules used
+   USE sed     ! sediment global variable
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! *  Routine accessibility
+   PUBLIC sed_co3     
+
+
+   !! * Module variables
+   REAL(wp) ::           & !! 
+      epsmax   =  1.e-12      ! convergence limite value
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0   !   LODYC-IPSL   (2003)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+
+   SUBROUTINE sed_co3( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_co3  ***
+      !!
+      !! ** Purpose :  carbonate ion and proton concentration 
+      !!               in sediment pore water
+      !!
+      !! ** Methode :  - solving nonlinear equation for [H+] with given alkalinity
+      !!               and total co2 
+      !!               - one dimensional newton-raphson algorithm for [H+])
+      !!
+      !!   History :
+      !!        !  98-08 (E. Maier-Reimer, Christoph Heinze )  Original code
+      !!        !  04-10 (N. Emprin, M. Gehlen ) coupled with PISCES
+      !!        !  06-04 (C. Ethe)  Re-organization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(in)  :: &
+         kt   ! time step
+
+      !
+      !---Local variables
+      INTEGER :: &
+         jiter, ji, jk, ipt    ! dummy loop indices
+
+      INTEGER :: &
+         itermax    ,  &  ! maximum number of Newton-Raphson iterations
+         itime            ! number of time to perform Newton-Raphson algorithm
+
+      LOGICAL :: &
+         lconv = .FALSE.           ! flag for convergence
+
+      REAL(wp) ::      & 
+         brems            ! relaxation. parameter
+
+      REAL(wp) ::      &  ! temporay variables
+         zresm, zresm1, zhipor_min , &
+         zalk, zbor, zsil, zpo4, zdic, &
+         zh_old, zh_old2, zh_old3, zh_old4, &
+         zuu, zvv, zduu, zdvv , &
+         zup, zvp, zdup, zdvp , &
+         zah_old, zah_olds,     &
+         zh_new, zh_new2,       &
+         zco3
+
+
+     !!----------------------------------------------------------------------
+
+      IF( kt == nitsed000 ) THEN
+         WRITE(numsed,*) ' sed_co3 : carbonate ion and proton concentration calculation  '
+         WRITE(numsed,*) ' '
+      ENDIF
+
+      itermax     = 30
+      brems       = 1.
+      itime       = 0
+
+
+      DO jk = 1, jpksed
+10001    CONTINUE
+         IF( itime <= 2 ) THEN
+            lconv  = .FALSE.
+            IF( itime > 0 ) THEN  
+               ! increase max number of iterations and relaxation parameter
+               itermax = 200
+!!               brems   = 0.3
+               IF( itime == 2 ) hipor(1:jpoce,jk) = 3.e-9 ! re-initilazation of [H] values
+            ENDIF
+
+iflag:      DO jiter = 1, itermax
+
+                ! Store previous hi field.   
+               zresm = -1.e10
+               ipt = 1
+               DO ji = 1, jpoce
+                  ! dissociation constant are in mol/kg of solution
+                  ! convert pwcp concentration [mol/l] in mol/kg for solution
+                  zalk    = pwcp(ji,jk,jwalk) / densSW(ji)
+                  zh_old  = hipor(ji,jk) / densSW(ji)
+                  zh_old2 = zh_old  * zh_old
+                  zh_old3 = zh_old2 * zh_old
+                  zh_old4 = zh_old3 * zh_old
+                  zbor    = borats(ji) / densSW(ji)
+                  zsil    = pwcp(ji,jk,jwsil) / densSW(ji)
+                  zpo4    = pwcp(ji,jk,jwpo4) / densSW(ji)
+                  zdic    = pwcp(ji,jk,jwdic) / densSW(ji)               
+                  ! intermediate calculation 
+                  zuu     = zdic * ( ak1s(ji) / zh_old + 2.* ak12s(ji) / zh_old2 )
+                  zvv     = 1. + ak1s(ji) / zh_old + ak12s(ji) / zh_old2
+                  zduu    = zdic * ( -ak1s(ji) / zh_old2 - 4. * ak12s(ji) / zh_old3 )
+                  zdvv    = -ak1s(ji) / zh_old2 - 2. * ak12s(ji) / zh_old3
+                  zup     = zpo4 * ( ak12ps(ji) / zh_old2 + 2. * ak123ps(ji) / zh_old3 - 1.)
+                  zvp     = 1. + ak1ps(ji) / zh_old + ak12ps(ji) / zh_old2 + ak123ps(ji) / zh_old3
+                  zdup    = zpo4 * ( -2. * ak12ps(ji) / zh_old3 - 6. * ak123ps(ji) / zh_old4 )
+                  zdvp    = -ak1ps(ji) / zh_old2 - 2.* ak12ps(ji) / zh_old3 - 3. * ak123ps(ji) / zh_old4
+                  
+                  zah_old  = zuu / zvv + zbor / ( 1. + zh_old / akbs(ji) ) + &
+                     &      akws(ji) / zh_old - zh_old + zsil / ( 1. + zh_old / aksis(ji) ) + &
+                     &      zup / zvp
+                  
+                  zah_olds = ( ( zduu * zvv - zdvv * zuu ) / ( zvv * zvv ) )      - &
+                     &        zbor / akbs(ji) * ( 1. + zh_old / akbs(ji) )**(-2) - &
+                     &        akws(ji) / zh_old2 - 1. -                            &
+                     &        zsil / aksis(ji) * ( 1. + zh_old / aksis(ji) )**(-2) + &
+                     &       ( ( zdup * zvp - zdvp * zup ) / ( zvp * zvp ) )
+                  !
+                  zh_new = zh_old - brems * ( zah_old - zalk ) / zah_olds
+                  ! 
+                  zresm1 = ABS( zh_new - zh_old )
+                  IF( zresm1 > zresm ) THEN 
+                     zresm = zresm1  
+                  ENDIF
+                  !
+                  zh_new2  = zh_new * zh_new
+                  zco3   = ( ak12s(ji) * zdic ) / ( ak12s(ji) + ak1s(ji) * zh_new + zh_new2)
+                  ! again in mol/l
+                  hipor (ji,jk) = zh_new * densSW(ji)
+                  co3por(ji,jk) = zco3   * densSW(ji)
+                  
+               ENDDO  ! end loop ji
+               
+               ! convergence test
+               IF( zresm <= epsmax ) THEN
+                  lconv = .TRUE.
+                  !minimum value of hipor
+                  zhipor_min = MINVAL( hipor(1:jpoce,jk ) )
+                  EXIT iflag
+               ENDIF
+
+            ENDDO iflag
+
+            IF( lconv ) THEN
+!               WRITE(numsed,*) ' convergence after iter =', jiter, ' iterations ;  res =',zresm  
+               IF( zhipor_min < 0. ) THEN 
+                  IF ( itime == 0 ) THEN
+!                     WRITE(numsed,*) '    but hipor < 0 ; try one more time for jk = ', jk 
+!                     WRITE(numsed,*) '    with re-initialization of initial PH field '       
+                     itime = 2
+                     GOTO 10001
+                  ELSE
+!                     WRITE(numsed,*) ' convergence after iter =', jiter, ' iterations ;  res =',zresm 
+!                     WRITE(numsed,*) '    but hipor < 0, again for second time for jk = ', jk 
+!                     WRITE(numsed,*) ' We stop : STOP '
+                     STOP
+                  ENDIF
+               ELSE
+!                  WRITE(numsed,*) ' successfull convergence for level jk = ',jk,&
+!                     &               '  after iter =', jiter, ' iterations ;  res =',zresm  
+!                  WRITE(numsed,*) ' '
+                  itime = 0
+               ENDIF
+            ELSE
+               itime = itime + 1
+               WRITE(numsed,*) ' No convergence for jk = ', jk, ' after ', itime, '  try'            
+               IF ( itime == 1 ) THEN
+                  WRITE(numsed,*) ' try one more time with more iterations and higher relax. value'
+                  GOTO 10001
+               ELSE IF ( itime == 2 ) THEN
+                  WRITE(numsed,*) ' try one more time for with more iterations, higher relax. value'               
+                  WRITE(numsed,*) ' and with re-initialization of initial PH field ' 
+               ELSE       
+                  WRITE(numsed,*) ' No more... we stop '
+                  STOP
+               ENDIF
+            ENDIF
+         ENDIF
+     ENDDO
+
+   END SUBROUTINE sed_co3
+#else
+   !!======================================================================
+   !! MODULE sedco3  :   Dummy module 
+   !!======================================================================
+CONTAINS
+   SUBROUTINE sed_co3( kt )         ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'sed_co3: You should not have seen this print! error?', kt
+   END SUBROUTINE sed_co3
+
+   !!======================================================================
+
+#endif
+
+END MODULE sedco3
+
Index: /trunk/NEMO/TOP_SRC/SED/seddsr.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/seddsr.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/seddsr.F90	(revision 1179)
@@ -0,0 +1,551 @@
+MODULE seddsr
+#if defined key_sed
+   !!======================================================================
+   !!              ***  MODULE  seddsr  ***
+   !!    Sediment : dissolution and reaction in pore water
+   !!=====================================================================
+   !! * Modules used
+   USE sed     ! sediment global variable
+   USE sedmat  ! linear system of equations
+   USE sedco3  ! carbonate ion and proton concentration 
+
+   PUBLIC sed_dsr
+
+   !! * Module variables
+
+   REAL(wp), DIMENSION(:), PUBLIC, ALLOCATABLE :: &
+      cons_o2   , &
+      cons_no3  , &
+      sour_no3  , &
+      sour_c13
+
+    REAL(wp), DIMENSION(jpsol), PUBLIC :: &
+       dens_mol_wgt
+  
+CONTAINS
+   
+   SUBROUTINE sed_dsr( kt ) 
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_dsr  ***
+      !! 
+      !!  ** Purpose :  computes pore water dissolution and reaction
+      !!
+      !!  ** Methode :  implicit simultaneous computation of undersaturation
+      !!               resulting from diffusive pore water transport and chemical
+      !!               pore water reactions. Solid material is consumed according
+      !!               to redissolution and remineralisation
+      !!
+      !!  ** Remarks :
+      !!              - undersaturation : deviation from saturation concentration
+      !!              - reaction rate   : sink of undersaturation from dissolution
+      !!                                 of solid material 
+      !!
+      !!   History :
+      !!        !  98-08 (E. Maier-Reimer, Christoph Heinze )  Original code
+      !!        !  04-10 (N. Emprin, M. Gehlen ) f90
+      !!        !  06-04 (C. Ethe)  Re-organization
+      !!----------------------------------------------------------------------
+      !! Arguments
+      INTEGER, INTENT(in) ::   kt       ! number of iteration
+      ! --- local variables
+      INTEGER :: &
+         ji, jk, js, jw
+      
+      INTEGER  ::    &
+         nv                        ! number of variables in linear tridiagonal eq
+   
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         zrearat,  &            ! reaction rate in pore water
+         zundsat                ! undersaturation ; indice jpwatp1 is for calcite   
+     
+      REAL(wp), DIMENSION(:) , ALLOCATABLE :: &    ! temp. variables
+         zmo2_0 , zmo2_1 ,    &          ! mass balance calculation
+         zmno3_0, zmno3_1, zmno3_2,    &
+         zmc13_0, zmc13_1, zmc13_2, zmc13_3
+ 
+      REAL(wp), DIMENSION(:,:,:) , ALLOCATABLE :: &    ! temp. variables
+         zvolc
+
+      REAL(wp)  ::  &
+         zsolid1, zsolid2, zsolid3, &
+         zvolw, zreasat
+      
+      !!
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitsed000 ) THEN
+         WRITE(numsed,*) ' sed_dsr : Dissolution reaction '
+         WRITE(numsed,*) ' '
+         dens_mol_wgt(1:jpsol) = dens / mol_wgt(1:jpsol)
+
+         ALLOCATE( cons_o2 (jpoce) ) ;   ALLOCATE( cons_no3(jpoce) ) 
+         ALLOCATE( sour_no3(jpoce) ) ;   ALLOCATE( sour_c13(jpoce) )  
+    
+      ENDIF
+
+      ! Initialization of data for mass balance calculation
+      !---------------------------------------------------
+
+      tokbot(:,:)  = 0.
+      cons_o2 (:)  = 0. 
+      cons_no3(:)  = 0.  
+      sour_no3(:)  = 0.  
+      sour_c13(:)  = 0.       
+   
+      ! Initializations
+      !----------------------
+      ALLOCATE( zmo2_0 (jpoce) ) ;  ALLOCATE( zmo2_1 (jpoce) ) 
+      ALLOCATE( zmno3_0(jpoce) ) ;  ALLOCATE( zmno3_1(jpoce) )  ;  ALLOCATE( zmno3_2(jpoce) ) 
+      ALLOCATE( zmc13_0(jpoce) ) ;  ALLOCATE( zmc13_1(jpoce) )  ;  ALLOCATE( zmc13_2(jpoce) ) ;  ALLOCATE( zmc13_3(jpoce) ) 
+
+      zmo2_0 (:) = 0.  ; zmo2_1 (:) = 0.
+      zmno3_0(:) = 0.  ; zmno3_1(:) = 0.  ;  zmno3_2(:) = 0.
+      zmc13_0(:) = 0.  ; zmc13_1(:) = 0.  ;  zmc13_2(:) = 0.  ; zmc13_3(:) = 0.
+      
+      ALLOCATE( zrearat(jpoce,jpksed,3) ) ;  ALLOCATE( zundsat(jpoce,jpksed,3) )      
+      zrearat(:,:,:)   = 0.    ;   zundsat(:,:,:) = 0. 
+
+
+      ALLOCATE( zvolc(jpoce,jpksed,jpsol) ) 
+      zvolc(:,:,:)   = 0.
+
+      !--------------------------------------------------------------------
+      ! Temporary accomodation to take account of  particule rain deposition
+      !---------------------------------------------------------------------
+      
+      
+      ! 1. Change of geometry
+      !    Increase of dz3d(2) thickness : dz3d(2) = dz3d(2)+dzdep
+      !    Warning : no change for dz(2)
+      !---------------------------------------------------------
+      dz3d(1:jpoce,2) = dz3d(1:jpoce,2) + dzdep(1:jpoce)
+
+      
+      ! New values for volw3d(:,2) and vols3d(:,2)
+      ! Warning : no change neither for volw(2) nor  vols(2)
+      !------------------------------------------------------
+      volw3d(1:jpoce,2) = dz3d(1:jpoce,2) * por(2)
+      vols3d(1:jpoce,2) = dz3d(1:jpoce,2) * por1(2)
+
+      ! Conversion of volume units
+      !----------------------------
+      DO js = 1, jpsol
+         DO jk = 1, jpksed
+            DO ji = 1, jpoce    
+               zvolc(ji,jk,js) = ( vols3d(ji,jk) * dens_mol_wgt(js) ) /  &
+                  &              ( volw3d(ji,jk) * 1.e-3 )     
+            ENDDO
+         ENDDO
+      ENDDO
+
+      ! 2. Change of previous solid fractions (due to volum changes) for k=2
+      !---------------------------------------------------------------------
+
+      DO js = 1, jpsol
+         DO ji = 1, jpoce
+            solcp(ji,2,js) = solcp(ji,2,js) * dz(2) / dz3d(ji,2)
+         ENDDO
+      END DO
+
+      ! 3. New solid fractions (including solid rain fractions) for k=2  
+      !------------------------------------------------------------------   
+      DO js = 1, jpsol
+         DO ji = 1, jpoce
+            solcp(ji,2,js) = solcp(ji,2,js) + &
+            &           ( rainrg(ji,js) / raintg(ji) ) * ( dzdep(ji) / dz3d(ji,2) )
+            ! rainrm are temporary cancel
+            rainrm(ji,js) = 0.
+         END DO
+      ENDDO
+
+      ! 4.  Adjustment of bottom water concen.(pwcp(1)): 
+      !     We impose that pwcp(2) is constant. Including dzdep in dz3d(:,2) we assume 
+      !     that dzdep has got a porosity of por(2). So pore water volum of jk=2 increase.
+      !     To keep pwcp(2) cste we must compensate this "increase" by a slight adjusment
+      !     of bottom water concentration.
+      !     This adjustment is compensate at the end of routine
+      !-------------------------------------------------------------
+      DO jw = 1, jpwat
+         DO ji = 1, jpoce
+            pwcp(ji,1,jw) = pwcp(ji,1,jw) - &
+               &            pwcp(ji,2,jw) * dzdep(ji) * por(2) / dzkbot(ji)
+         END DO
+      ENDDO
+
+ 
+      !----------------------------------------------------------
+      ! 5.  Beginning of  Pore Water diffusion and solid reaction
+      !---------------------------------------------------------
+      
+      !-----------------------------------------------------------------------------
+      ! For jk=2,jpksed, and for couple 
+      !  1 : jwsil/jsopal  ( SI/Opal )
+      !  2 : jsclay/jsclay ( clay/clay ) 
+      !  3 : jwoxy/jspoc   ( O2/POC )
+      !  reaction rate is a function of solid=concentration in solid reactif in [mol/l] 
+      !  and undersaturation in [mol/l].
+      !  Solid weight fractions should be in ie [mol/l])
+      !  second member and solution are in zundsat variable
+      !-------------------------------------------------------------------------
+
+      !number of variables
+      nv  = 3
+     
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            ! For Silicic Acid and clay
+            zundsat(ji,jk,1) = sat_sil   - pwcp(ji,jk,jwsil)
+            zundsat(ji,jk,2) = sat_clay
+            ! For O2
+            zundsat(ji,jk,3) = pwcp(ji,jk,jwoxy) / so2ut 
+         ENDDO
+      ENDDO
+      
+      
+      ! Definition of reaction rates [rearat]=sans dim 
+      ! For jk=1 no reaction (pure water without solid) for each solid compo
+      DO ji = 1, jpoce
+         zrearat(ji,1,:) = 0.
+      ENDDO
+
+
+      ! left hand side of coefficient matrix
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zsolid1 = zvolc(ji,jk,jsopal) * solcp(ji,jk,jsopal)
+            zsolid2 = zvolc(ji,jk,jsclay) * solcp(ji,jk,jsclay)
+            zsolid3 = zvolc(ji,jk,jspoc)  * solcp(ji,jk,jspoc)
+
+            zrearat(ji,jk,1)  = ( reac_sil * dtsed * zsolid1 ) / &
+               &                ( 1. + reac_sil * dtsed * zundsat(ji,jk,1 ) )
+            zrearat(ji,jk,2)  = ( reac_clay * dtsed * zsolid2 ) / &
+               &                ( 1. + reac_clay * dtsed * zundsat(ji,jk,2 ) )
+            zrearat(ji,jk,3)  = ( reac_poc  * dtsed * zsolid3 ) / &
+               &                ( 1. + reac_poc  * dtsed * zundsat(ji,jk,3 ) )
+         ENDDO
+      ENDDO
+
+
+      CALL sed_mat( nv, jpoce, jpksed, zrearat, zundsat )
+
+
+      ! New solid concentration values (jk=2 to jksed) for each couple 
+      DO js = 1, nv
+         DO jk = 2, jpksed
+            DO ji = 1, jpoce
+               zreasat = zrearat(ji,jk,js) * zundsat(ji,jk,js) / zvolc(ji,jk,js)
+               solcp(ji,jk,js) = solcp(ji,jk,js) - zreasat
+            ENDDO
+         ENDDO
+      ENDDO
+      ! mass of O2/NO3 before POC remin. for mass balance check 
+      ! det. of o2 consomation/NO3 production Mc13
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zvolw = volw3d(ji,jk) * 1.e-3
+            zmo2_0 (ji)  = zmo2_0 (ji) + pwcp(ji,jk,jwoxy) * zvolw
+            zmno3_0(ji)  = zmno3_0(ji) + pwcp(ji,jk,jwno3) * zvolw
+            zmc13_0(ji)  = zmc13_0(ji) + pwcp(ji,jk,jwc13) * zvolw
+         ENDDO
+      ENDDO
+
+      ! New pore water concentrations    
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            ! Acid Silicic 
+            pwcp(ji,jk,jwsil)  = sat_sil - zundsat(ji,jk,1)            
+            ! For O2 (in mol/l)
+            pwcp(ji,jk,jwoxy)  = zundsat(ji,jk,3) * so2ut 
+            zreasat = zrearat(ji,jk,3) * zundsat(ji,jk,3)    ! oxygen         
+            ! For DIC
+            pwcp(ji,jk,jwdic)  = pwcp(ji,jk,jwdic) + zreasat
+            ! For nitrates
+            pwcp(ji,jk,jwno3)  = pwcp(ji,jk,jwno3) + zreasat * srno3            
+            ! For Phosphate (in mol/l)
+            pwcp(ji,jk,jwpo4)  = pwcp(ji,jk,jwpo4) + zreasat * spo4r            
+            ! For alkalinity
+            pwcp(ji,jk,jwalk)  = pwcp(ji,jk,jwalk) - zreasat * ( srno3 + 2.* spo4r )           
+            ! For DIC13
+            pwcp(ji,jk,jwc13)  = pwcp(ji,jk,jwc13) + zreasat * rc13P * pdb
+         ENDDO
+      ENDDO
+
+
+      ! Mass of O2 for mass balance check and det. of o2 consomation
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zvolw = volw3d(ji,jk) * 1.e-3
+            zmo2_1 (ji) = zmo2_1 (ji) + pwcp(ji,jk,jwoxy) * zvolw
+            zmno3_1(ji) = zmno3_1(ji) + pwcp(ji,jk,jwno3) * zvolw
+            zmc13_1(ji) = zmc13_1(ji) + pwcp(ji,jk,jwc13) * zvolw
+         ENDDO
+      ENDDO
+
+      DO ji = 1, jpoce
+         cons_o2 (ji) = zmo2_0 (ji) - zmo2_1 (ji)
+         sour_no3(ji) = zmno3_1(ji) - zmno3_0(ji)     
+         sour_c13(ji) = zmc13_1(ji) - zmc13_0(ji) 
+      ENDDO
+ 
+
+      !--------------------------------------------------------------------
+      ! Begining POC denitrification and NO3- diffusion
+      ! (indice n°5 for couple POC/NO3- ie solcp(:,:,jspoc)/pwcp(:,:,jwno3))
+      !--------------------------------------------------------------------
+
+      nv = 1
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zundsat(ji,jk,1) = pwcp(ji,jk,jwno3) / srDnit
+         ENDDO
+      ENDDO
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            IF( pwcp(ji,jk,jwoxy) < sthrO2 ) THEN
+               zsolid1 = zvolc(ji,jk,jspoc) * solcp(ji,jk,jspoc)
+               zrearat(ji,jk,1) = ( reac_no3 * dtsed * zsolid1 ) / &
+                  &                    ( 1. + reac_no3 * dtsed * zundsat(ji,jk,1 ) )
+            ELSE
+               zrearat(ji,jk,1) = 0.
+            ENDIF
+         END DO
+      END DO
+
+
+      ! solves tridiagonal system
+      CALL sed_mat( nv, jpoce, jpksed, zrearat, zundsat )
+
+
+      ! New solid concentration values (jk=2 to jksed) for each couple 
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zreasat = zrearat(ji,jk,1) * zundsat(ji,jk,1) / zvolc(ji,jk,jspoc)
+            solcp(ji,jk,jspoc) = solcp(ji,jk,jspoc) - zreasat
+         ENDDO
+      ENDDO
+
+      ! New dissolved concentrations
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zreasat = zrearat(ji,jk,1) * zundsat(ji,jk,1)    
+            ! For nitrates
+            pwcp(ji,jk,jwno3)  =  zundsat(ji,jk,1) * srDnit
+            ! For DIC
+            pwcp(ji,jk,jwdic)  = pwcp(ji,jk,jwdic) + zreasat
+            ! For Phosphate (in mol/l)
+            pwcp(ji,jk,jwpo4)  = pwcp(ji,jk,jwpo4) + zreasat * spo4r            
+            ! For alkalinity
+            pwcp(ji,jk,jwalk)  = pwcp(ji,jk,jwalk) + zreasat * ( srDnit - 2.* spo4r )           
+            ! For DIC13
+            pwcp(ji,jk,jwc13)  = pwcp(ji,jk,jwc13) + zreasat * rc13P * pdb
+         ENDDO
+      ENDDO
+
+
+      ! Mass of O2 for mass balance check and det. of o2 consomation
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zvolw = volw3d(ji,jk) * 1.e-3
+            zmno3_2(ji) = zmno3_2(ji) + pwcp(ji,jk ,jwno3) * zvolw
+            zmc13_2(ji) = zmc13_2(ji) + pwcp(ji,jk ,jwc13) * zvolw   
+         ENDDO
+      ENDDO
+
+      DO ji = 1, jpoce
+         cons_no3(ji) = zmno3_1(ji) - zmno3_2(ji)  
+         sour_c13(ji) = sour_c13(ji) + zmc13_2(ji) - zmc13_1(ji)     
+      ENDDO
+
+
+      !---------------------------
+      ! Solves PO4 diffusion 
+      !----------------------------
+
+      nv = 1
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zundsat(ji,jk,1) = pwcp(ji,jk,jwpo4)
+            zrearat(ji,jk,1) = 0.
+         ENDDO
+      ENDDO
+
+
+      ! solves tridiagonal system
+      CALL sed_mat( nv, jpoce, jpksed, zrearat, zundsat )
+
+
+      ! New undsaturation values and dissolved concentrations
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            pwcp(ji,jk,jwpo4) = zundsat(ji,jk,1)
+         ENDDO
+      ENDDO
+
+
+      !---------------------------------------------------------------
+      ! Performs CaCO3 particle deposition and redissolution (indice 9)
+      !--------------------------------------------------------------
+
+      ! computes co3por from the updated pwcp concentrations (note [co3por] = mol/l)
+
+      CALL sed_co3( kt )
+
+
+      nv = 1
+      ! *densSW(l)**2 converts aksps [mol2/kg sol2] into [mol2/l2] to get [undsat] in [mol/l]
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zundsat(ji,jk,1) = aksps(ji) * densSW(ji) * densSW(ji) / calcon2(ji) &
+               &                     - co3por(ji,jk)
+            ! positive values of undersaturation
+            zundsat(ji,jk,1) = MAX( 0., zundsat(ji,jk,1) )            
+         ENDDO
+      ENDDO
+
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zsolid1 = zvolc(ji,jk,jscal) * solcp(ji,jk,jscal)
+            zrearat(ji,jk,1) = ( reac_cal * dtsed * zsolid1 ) / &
+                  &               ( 1. + reac_cal * dtsed * zundsat(ji,jk,1) )
+         END DO
+      END DO
+
+
+      ! solves tridiagonal system
+      CALL sed_mat( nv, jpoce, jpksed, zrearat, zundsat )
+
+
+      ! New solid concentration values (jk=2 to jksed) for cacO3
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zreasat = zrearat(ji,jk,1) * zundsat(ji,jk,1) / zvolc(ji,jk,jscal)
+            solcp(ji,jk,jscal) = solcp(ji,jk,jscal) - zreasat
+         ENDDO
+      ENDDO
+
+      ! New dissolved concentrations
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zreasat = zrearat(ji,jk,1) * zundsat(ji,jk,1)    
+            ! For DIC
+            pwcp(ji,jk,jwdic)  = pwcp(ji,jk,jwdic) + zreasat
+            ! For alkalinity
+            pwcp(ji,jk,jwalk)  = pwcp(ji,jk,jwalk) + 2.* zreasat 
+            ! For DIC13
+            pwcp(ji,jk,jwc13)  = pwcp(ji,jk,jwc13) + zreasat * rc13Ca * pdb
+         ENDDO
+      ENDDO
+
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zmc13_3(ji) = zmc13_3(ji) + pwcp(ji,jk,jwc13) * volw3d(ji,jk) * 1.e-3                  
+         ENDDO
+      ENDDO
+
+      DO ji = 1, jpoce     
+         sour_c13(ji) = sour_c13(ji) + zmc13_3(ji) - zmc13_2(ji)   
+      ENDDO
+      
+      !-------------------------------------------------
+      ! Beginning DIC, Alkalinity and DIC13 diffusion
+      !-------------------------------------------------
+      
+      nv = 3
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce      
+            zundsat(ji,jk,1) = pwcp(ji,jk,jwdic)
+            zundsat(ji,jk,2) = pwcp(ji,jk,jwalk)
+            zundsat(ji,jk,3) = pwcp(ji,jk,jwc13)
+      
+            zrearat(ji,jk,1) = 0.
+            zrearat(ji,jk,2) = 0.
+            zrearat(ji,jk,3) = 0.
+      
+         ENDDO
+      ENDDO
+
+
+      ! solves tridiagonal system
+      CALL sed_mat( nv, jpoce, jpksed, zrearat, zundsat )
+
+
+      ! New dissolved concentrations      
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce                      
+            pwcp(ji,jk,jwdic) = zundsat(ji,jk,1)
+            pwcp(ji,jk,jwalk) = zundsat(ji,jk,2)
+            pwcp(ji,jk,jwc13) = zundsat(ji,jk,3)
+         ENDDO
+      ENDDO            
+      
+      !----------------------------------
+      !   Back to initial geometry
+      !-----------------------------
+      
+      !---------------------------------------------------------------------
+      !   1/ Compensation for ajustement of the bottom water concentrations
+      !      (see note n° 1 about *por(2))
+      !--------------------------------------------------------------------
+      DO jw = 1, jpwat
+         DO ji = 1, jpoce
+            pwcp(ji,1,jw) = pwcp(ji,1,jw) + &
+               &            pwcp(ji,2,jw) * dzdep(ji) * por(2) / dzkbot(ji)
+         END DO
+      ENDDO
+      
+      !-----------------------------------------------------------------------
+      !    2/ Det of new rainrg taking account of the new weight fraction obtained 
+      !      in dz3d(2) after diffusion/reaction (react/diffu are also in dzdep!)
+      !      This new rain (rgntg rm) will be used in advection/burial routine
+      !------------------------------------------------------------------------
+      DO js = 1, jpsol
+         DO ji = 1, jpoce
+            rainrg(ji,js) = raintg(ji) * solcp(ji,2,js)
+            rainrm(ji,js) = rainrg(ji,js) / mol_wgt(js)
+         END DO
+      ENDDO
+      
+      !  New raintg
+      raintg(:) = 0.
+      DO js = 1, jpsol
+         DO ji = 1, jpoce
+            raintg(ji) = raintg(ji) + rainrg(ji,js)
+         END DO
+      ENDDO
+      
+      !--------------------------------
+      !    3/ back to initial geometry
+      !--------------------------------
+      DO ji = 1, jpoce
+         dz3d  (ji,2) = dz(2)
+         volw3d(ji,2) = dz3d(ji,2) * por(2)
+         vols3d(ji,2) = dz3d(ji,2) * por1(2)
+      ENDDO
+      
+      !----------------------------------------------------------------------
+      !    4/ Saving new amount of material in dzkbot for mass balance check
+      !       tokbot in [mol] (implicit *1cm*1cm for spacial dim)
+      !----------------------------------------------------------------------
+      DO jw = 1, jpwat 
+         DO ji = 1, jpoce
+            tokbot(ji,jw) = pwcp(ji,1,jw) * 1.e-3 * dzkbot(ji)
+         END DO
+      ENDDO
+
+      DEALLOCATE( zmo2_0  ) ;  DEALLOCATE( zmno3_1 )  ;  DEALLOCATE( zmno3_2 ) 
+      DEALLOCATE( zmc13_0 ) ;  DEALLOCATE( zmc13_1 )  ;  DEALLOCATE( zmc13_2 ) ;  DEALLOCATE( zmc13_3 ) 
+      
+      DEALLOCATE( zrearat ) ;  DEALLOCATE( zundsat )  ;  DEALLOCATE( zvolc )   
+      
+   END SUBROUTINE sed_dsr
+#else
+   !!======================================================================
+   !! MODULE seddsr  :   Dummy module 
+   !!======================================================================
+CONTAINS
+   SUBROUTINE sed_dsr ( kt )
+     INTEGER, INTENT(in) :: kt
+  END SUBROUTINE sed_dsr
+#endif
+   
+END MODULE seddsr
Index: /trunk/NEMO/TOP_SRC/SED/seddta.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/seddta.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/seddta.F90	(revision 1179)
@@ -0,0 +1,273 @@
+MODULE seddta
+   !!======================================================================
+   !!                     ***  MODULE  seddta  ***
+   !! Sediment data  :  read sediment input data from a file
+   !!=====================================================================
+#if defined key_sed
+   !! * Modules used
+   USE sed
+   USE sedarr
+   USE iom
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC sed_dta   ! 
+
+   !! *  Module variables
+   REAL(wp), DIMENSION(:), ALLOCATABLE :: &
+      smask       ! mask for sediments points
+
+   REAL(wp) ::  &
+      rsecday  , &  ! number of second per a day
+      conv1    , &  ! [m/day]--->[cm/s]  
+      conv2         ! [kg/m2/month]-->[g/cm2/s] ( 1 month has 30 days )
+
+   INTEGER ::     &
+     numbio = 37, &
+     numoce = 47
+
+CONTAINS
+
+   !!---------------------------------------------------------------------------
+   !!   sed_dta  : read the NetCDF data file in online version using module iom
+   !!---------------------------------------------------------------------------
+
+   SUBROUTINE sed_dta( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_dta  ***
+      !!                    
+      !! ** Purpose :   Reads data from a netcdf file and 
+      !!                initialization of rain and pore water (k=1) components
+      !! 
+      !!
+      !!   History :
+      !!        !  04-10  (N. Emprin, M. Gehlen )  Original code
+      !!        !  06-04  (C. Ethe)  Re-organization ; Use of iom
+      !!----------------------------------------------------------------------
+
+      !! Arguments
+      INTEGER, INTENT(in) :: &
+         kt
+
+      !! * Local declarations
+      INTEGER  ::  ji, jj, js, jw, ikt
+
+      REAL(wp) , DIMENSION (jpi,jpj) :: zdta
+#if ! defined key_kriest
+      REAL(wp) , DIMENSION (:), ALLOCATABLE  :: zdtap , zdtag
+#endif 
+
+
+      !----------------------------------------------------------------------
+
+      ! Initialization of sediment variable 
+      ! Spatial dimension is merged, and unity converted if needed
+      !-------------------------------------------------------------
+
+      WRITE(numsed,*)
+      WRITE(numsed,*) ' sed_dta : Bottom layer fields'
+      WRITE(numsed,*) ' ~~~~~~'
+      WRITE(numsed,*) ' Data from SMS model'
+      WRITE(numsed,*)
+
+
+      ! open file
+      IF( kt == nitsed000 ) THEN
+         WRITE(numsed,*) ' sed_dta : Sediment fields'
+         CALL iom_open ( 'data_bio_bot'     , numbio )
+         rsecday = 60.* 60. * 24.
+         conv1   = 1.0e+2 / rsecday 
+         conv2   = 1.0e+3 / ( 1.0e+4 * rsecday * 30. ) 
+
+         ! Compute sediment mask
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ikt = MAX( INT( sbathy(ji,jj) ) - 1, 1 )
+               zdta(ji,jj) = tmask(ji,jj,ikt) 
+            ENDDO
+         ENDDO
+         ALLOCATE( smask(jpoce) )
+         smask(:) = 0.
+         CALL pack_arr( jpoce, smask(1:jpoce), zdta(1:jpi,1:jpj), iarroce(1:jpoce) )
+      ENDIF
+
+
+#if ! defined key_kriest   
+      ! Initialization of temporaries arrays  
+      ALLOCATE( zdtap   (jpoce) )    ;   zdtap(:)    = 0. 
+      ALLOCATE( zdtag   (jpoce) )    ;   zdtag(:)    = 0.  
+#endif
+
+
+      IF( MOD( kt - 1, nfreq ) == 0 ) THEN
+         ! reading variables
+         WRITE(numsed,*)
+         WRITE(numsed,*) ' sed_dta : Bottom layer fields at time  kt = ', kt
+         ! reading variables
+         trc_data(:,:,:) = 0.
+#if ! defined key_sed_off
+         DO jj = 1,jpj
+            DO ji = 1, jpi
+               ikt = MAX( mbathy(ji,jj)-1, 1 )
+               IF ( tmask(ji,jj,ikt) == 1 ) THEN
+                  trc_data(ji,jj,1)  = trn  (ji,jj,ikt,jptal)
+                  trc_data(ji,jj,2)  = trn  (ji,jj,ikt,jpdic)
+                  trc_data(ji,jj,3)  = trn  (ji,jj,ikt,jpno3) / 7.6
+                  trc_data(ji,jj,4)  = trn  (ji,jj,ikt,jppo4) / 122.
+                  trc_data(ji,jj,5)  = trn  (ji,jj,ikt,jpoxy)
+                  trc_data(ji,jj,6)  = trn  (ji,jj,ikt,jpsil)
+#   if ! defined key_kriest
+                  trc_data(ji,jj,7 ) = sinksil (ji,jj,ikt)
+                  trc_data(ji,jj,8 ) = sinking (ji,jj,ikt)
+                  trc_data(ji,jj,9 ) = sinking2(ji,jj,ikt)
+                  trc_data(ji,jj,10) = sinkcal (ji,jj,ikt)
+                  trc_data(ji,jj,11) = tn      (ji,jj,ikt)
+                  trc_data(ji,jj,12) = sn      (ji,jj,ikt)
+#   else
+                  trc_data(ji,jj,7 ) = sinksil (ji,jj,ikt)
+                  trc_data(ji,jj,8 ) = sinking (ji,jj,ikt)
+                  trc_data(ji,jj,9 ) = sinkcal (ji,jj,ikt)
+                  trc_data(ji,jj,10) = tn      (ji,jj,ikt)
+                  trc_data(ji,jj,11) = sn      (ji,jj,ikt)       
+#   endif
+
+#else
+                  CALL iom_get( numbio, jpdom_data, 'ALKBOT'     , trc_data(:,:,1 ) )
+                  CALL iom_get( numbio, jpdom_data, 'DICBOT'     , trc_data(:,:,2 ) )
+                  CALL iom_get( numbio, jpdom_data, 'NO3BOT'     , trc_data(:,:,3 ) )
+                  CALL iom_get( numbio, jpdom_data, 'PO4BOT'     , trc_data(:,:,4 ) )
+                  CALL iom_get( numbio, jpdom_data, 'O2BOT'      , trc_data(:,:,5 ) )
+                  CALL iom_get( numbio, jpdom_data, 'SIBOT'      , trc_data(:,:,6 ) )
+#   if ! defined key_kriest
+                  CALL iom_get( numbio, jpdom_data, 'OPALFLXBOT' , trc_data(:,:,7 ) ) 
+                  CALL iom_get( numbio, jpdom_data, 'POCFLXBOT'  , trc_data(:,:,8 ) ) 
+                  CALL iom_get( numbio, jpdom_data, 'GOCFLXBOT'  , trc_data(:,:,9 ) ) 
+                  CALL iom_get( numbio, jpdom_data, 'CACO3FLXBOT', trc_data(:,:,10) ) 
+                  CALL iom_get( numoce, jpdom_data, 'TBOT'       , trc_data(:,:,11) ) 
+                  CALL iom_get( numoce, jpdom_data, 'SBOT'       , trc_data(:,:,12) ) 
+#   else
+                  CALL iom_get( numbio, jpdom_data, 'OPALFLXBOT' , trc_data(:,:,7 ) ) 
+                  CALL iom_get( numbio, jpdom_data, 'POCFLXBOT'  , trc_data(:,:,8 ) ) 
+                  CALL iom_get( numbio, jpdom_data, 'CACO3FLXBOT', trc_data(:,:,9 ) ) 
+                  CALL iom_get( numoce, jpdom_data, 'TBOT'       , trc_data(:,:,10) ) 
+                  CALL iom_get( numoce, jpdom_data, 'SBOT'       , trc_data(:,:,11) ) 
+#   endif
+#endif
+
+               ENDIF
+            ENDDO
+         ENDDO
+         
+ 
+         ! Pore water initial concentration [mol/l] in  k=1
+         !-------------------------------------------------
+
+          ! Alkalinity ( 1 umol = 10-6equivalent )
+         CALL pack_arr ( jpoce,  pwcp_dta(1:jpoce,jwalk), trc_data(1:jpi,1:jpj,1), iarroce(1:jpoce) )
+         ! DIC 
+         CALL pack_arr ( jpoce,  pwcp_dta(1:jpoce,jwdic), trc_data(1:jpi,1:jpj,2), iarroce(1:jpoce) )
+         ! Nitrates (1 umol/l = 10-6 mol/l)
+         CALL pack_arr ( jpoce,  pwcp_dta(1:jpoce,jwno3), trc_data(1:jpi,1:jpj,3), iarroce(1:jpoce) )
+         ! Phosphates (1 umol/l = 10-6 mol/l)
+         CALL pack_arr ( jpoce,  pwcp_dta(1:jpoce,jwpo4), trc_data(1:jpi,1:jpj,4), iarroce(1:jpoce) )
+         ! Oxygen (1 umol/l = 10-6 mol/l)
+         CALL pack_arr ( jpoce,  pwcp_dta(1:jpoce,jwoxy), trc_data(1:jpi,1:jpj,5), iarroce(1:jpoce) )        
+         ! Silicic Acid [mol.l-1]
+         CALL pack_arr ( jpoce,  pwcp_dta(1:jpoce,jwsil), trc_data(1:jpi,1:jpj,6), iarroce(1:jpoce) )                  
+         ! DIC13 (mol/l)obtained from dc13 and DIC (12) and PDB 
+         CALL iom_get ( numbio,jpdom_data,'DC13',zdta(:,:) )
+         CALL pack_arr ( jpoce,  pwcp_dta(1:jpoce,jwc13), zdta(1:jpi,1:jpj), iarroce(1:jpoce) )
+         pwcp_dta(1:jpoce,jwc13) = pdb * ( pwcp_dta(1:jpoce,jwc13) * 1.0e-3 + 1.0 )  &
+            &                          *   pwcp_dta(1:jpoce,jwdic)         
+         
+         !  Solid components : 
+         !-----------------------
+#if ! defined key_kriest
+         !  Sinking fluxes for OPAL in mol.m-2.s-1 ; conversion in mol.cm-2.s-1
+         CALL pack_arr ( jpoce, rainrm_dta(1:jpoce,jsopal), trc_data(1:jpi,1:jpj,7), iarroce(1:jpoce) ) 
+         rainrm_dta(1:jpoce,jsopal) = rainrm_dta(1:jpoce,jsopal) * 1e-4
+         !  Sinking fluxes for POC in mol.m-2.s-1 ; conversion in mol.cm-2.s-1
+         CALL pack_arr ( jpoce, zdtap(1:jpoce), trc_data(1:jpi,1:jpj,8) , iarroce(1:jpoce) )      
+         CALL pack_arr ( jpoce, zdtag(1:jpoce), trc_data(1:jpi,1:jpj,9) , iarroce(1:jpoce) )
+         rainrm_dta(1:jpoce,jspoc) =   ( zdtap(1:jpoce) +  zdtag(1:jpoce) ) * 1e-4
+         !  Sinking fluxes for Calcite in mol.m-2.s-1 ; conversion in mol.cm-2.s-1
+         CALL pack_arr ( jpoce,  rainrm_dta(1:jpoce,jscal), trc_data(1:jpi,1:jpj,10), iarroce(1:jpoce) )
+         rainrm_dta(1:jpoce,jscal) = rainrm_dta(1:jpoce,jscal) * 1e-4
+         ! vector temperature [°C] and salinity 
+         CALL pack_arr ( jpoce,  temp(1:jpoce), trc_data(1:jpi,1:jpj,11), iarroce(1:jpoce) )
+         CALL pack_arr ( jpoce,  salt(1:jpoce), trc_data(1:jpi,1:jpj,12), iarroce(1:jpoce) )
+#else
+         !  Sinking fluxes for OPAL in mol.m-2.s-1 ; conversion in mol.cm-2.s-1
+         CALL pack_arr ( jpoce, rainrm_dta(1:jpoce,jsopal), trc_data(1:jpi,1:jpj,7), iarroce(1:jpoce) ) 
+         rainrm_dta(1:jpoce,jsopal) = rainrm_dta(1:jpoce,jsopal) * 1e-4
+         !  Sinking fluxes for POC in mol.m-2.s-1 ; conversion in mol.cm-2.s-1
+         CALL pack_arr ( jpoce, rainrm_dta(1:jpoce,jspoc), trc_data(1:jpi,1:jpj,8) , iarroce(1:jpoce) )      
+         rainrm_dta(1:jpoce,jspoc) = rainrm_dta(1:jpoce,jspoc) * 1e-4
+         !  Sinking fluxes for Calcite in mol.m-2.s-1 ; conversion in mol.cm-2.s-1
+         CALL pack_arr ( jpoce,  rainrm_dta(1:jpoce,jscal), trc_data(1:jpi,1:jpj,9), iarroce(1:jpoce) )
+         rainrm_dta(1:jpoce,jscal) = rainrm_dta(1:jpoce,jscal) * 1e-4
+         ! vector temperature [°C] and salinity 
+         CALL pack_arr ( jpoce,  temp(1:jpoce), trc_data(1:jpi,1:jpj,10), iarroce(1:jpoce) )
+         CALL pack_arr ( jpoce,  salt(1:jpoce), trc_data(1:jpi,1:jpj,11), iarroce(1:jpoce) )
+
+#endif
+        
+         ! Clay rain rate in [mol/(cm**2.s)] 
+         ! inputs data in [kg.m-2.mois-1] ---> 1e+3/(1e+4*60*24*60*60) [g.cm-2.s-1]   
+         ! divided after by molecular weight g.mol-1      
+         zdta(:,:)   = 0.
+         CALL iom_get( numbio, jpdom_data, 'CLAY', zdta(:,:) ) 
+         CALL pack_arr ( jpoce, rainrm_dta(1:jpoce,jsclay) , zdta(1:jpi,1:jpj), iarroce(1:jpoce) )      
+         rainrm_dta(1:jpoce,jsclay) = rainrm_dta(1:jpoce,jsclay) * conv2 / mol_wgt(jsclay)
+
+      ENDIF
+
+      ! sediment pore water at 1st layer (k=1)
+      DO jw = 1, jpwat
+         pwcp(1:jpoce,1,jw) = pwcp_dta(1:jpoce,jw) * smask(1:jpoce)
+      ENDDO
+
+      !  rain
+      DO js = 1, jpsol
+         rainrm(1:jpoce,js) = rainrm_dta(1:jpoce,js) * smask(1:jpoce)
+      ENDDO
+
+      ! Calculation of raintg of each sol. comp.: rainrm in [g/(cm**2.s)]
+      DO js = 1, jpsol
+         rainrg(1:jpoce,js) = rainrm(1:jpoce,js) *  mol_wgt(js)
+      ENDDO
+
+      ! Calculation of raintg = total massic flux rained in each cell (sum of sol. comp.)
+      raintg(:) = 0.
+      DO js = 1, jpsol
+         raintg(1:jpoce) = raintg(1:jpoce) + rainrg(1:jpoce,js)
+      ENDDO
+
+      ! computation of dzdep = total thickness of solid material rained [cm] in each cell
+      dzdep(1:jpoce) = raintg(1:jpoce) * rdtsed(2) 
+
+
+#if ! defined key_kriest
+      DEALLOCATE( zdtap    ) ;  DEALLOCATE( zdtag    ) 
+#endif      
+
+      IF( kt == nitsedend )   THEN
+         CALL iom_close ( numbio )
+         CALL iom_close ( numoce )
+      ENDIF
+      
+   END SUBROUTINE sed_dta
+
+#else
+   !!======================================================================
+   !! MODULE seddta  :   Dummy module 
+   !!======================================================================
+CONTAINS
+   SUBROUTINE sed_dta ( kt )
+     INTEGER, INTENT(in) :: kt
+  END SUBROUTINE sed_dta
+#endif
+
+END MODULE seddta
Index: /trunk/NEMO/TOP_SRC/SED/sedini.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sedini.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sedini.F90	(revision 1179)
@@ -0,0 +1,807 @@
+MODULE sedini
+   !!======================================================================
+   !!              ***  MODULE  sedini  ***
+   !! Sediment : define sediment variables
+   !!=====================================================================
+#if defined key_sed
+
+   !!----------------------------------------------------------------------
+   !!   sed_init    : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE sed     ! sediment global variable
+   USE seddta
+   USE sedrst
+   USE sedco3
+   USE sedchem
+   USE sedarr
+   USE iom
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! Module variables
+   REAL(wp)    ::  &
+      sisat   =  800.  ,  &  !: saturation for si    [ mol.l-1]
+      claysat =    0.  ,  &  !: saturation for clay  [ mol.l-1]
+      rcopal  =   40.  ,  &  !: reactivity for si    [l.mol-1.an-1]
+      rcclay  =    0.  ,  &  !: reactivity for clay  [l.mol-1.an-1]
+      dcoef   =  8.e-6       !: diffusion coefficient (*por)   [cm**2/s]
+
+   REAL(wp)    ::  &
+      redO2   =  172.  ,  &  !: Redfield coef for Oxygene
+      redNo3  =   16.  ,  &  !: Redfield coef for Nitrates
+      redPo4  =    1.  ,  &  !: Redfield coef for Phosphates
+      redC    =  122.  ,  &  !: Redfield coef for Carbone
+      redDnit =  97.6  ,  &  !: Redfield coef for denitrification    
+      rcorg   =   50.  ,  &  !: reactivity for POC/O2 [l.mol-1.an-1]    
+      o2seuil =    1.  ,  &  !: threshold O2 concentration for [mol.l-1]     
+      rcorgN  =   50.       !: reactivity for POC/No3 [l.mol-1.an-1]
+
+   REAL(wp)    ::  &
+      rccal   = 1000.        !: reactivity for calcite         [l.mol-1.an-1]
+
+   REAL(wp)    ::  &
+      dbiot   = 15.          !: coefficient for bioturbation    [cm**2.(1000an-1)]
+
+   LOGICAL     :: &
+      ln_rst_sed = .TRUE.    !: initialisation from a restart file or not
+
+   REAL(wp)    ::  &
+      ryear = 365. * 24. * 3600. !:  1 year converted in second
+
+   !! *  Routine accessibility
+   PUBLIC sed_init          ! routine called by opa.F90
+
+CONTAINS
+
+
+   SUBROUTINE sed_init
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_init  ***
+      !!
+      !! ** Purpose :  Initialization of sediment module
+      !!               - Reading namelist
+      !!               - Read the deepest water layer thickness
+      !!                 ( using as mask ) in Netcdf file
+      !!               - Convert unity if necessary
+      !!               - sets initial sediment composition
+      !!                 ( only clay or reading restart file )
+      !!               - sets sediment grid, porosity and others constants
+      !!
+      !!   History :
+      !!        !  04-10  (N. Emprin, M. Gehlen )  Original code
+      !!        !  06-07  (C. Ethe)  Re-organization
+      !!----------------------------------------------------------------------
+      INTEGER :: ji, jj, ikt
+#if defined key_sed_off
+      INTEGER  :: numblt  = 32        
+      INTEGER  :: nummsh  = 42  
+      REAL(wp) , DIMENSION(jpi,jpj) :: zdta
+#endif
+      !!----------------------------------------------------------------------
+
+
+      ! Reading namelist.sed variables
+      !---------------------------------------
+
+      OPEN( UNIT = numsed, FILE = 'sediment.output', FORM = 'FORMATTED' ) 
+
+      WRITE(numsed,*)
+      WRITE(numsed,*) '                 L S C E - C E A'
+      WRITE(numsed,*) '                 SEDIMENT model'
+      WRITE(numsed,*) '                version 2.0  (2007) '
+      WRITE(numsed,*)
+      WRITE(numsed,*)
+
+    
+      WRITE(numsed,*) ' sed_init : Initialization of sediment module  '
+      WRITE(numsed,*) ' '
+
+      ! Determination of sediments number of points and allocate global variables
+#if defined key_sed_off
+      ! Reading Netcdf Pisces file for deepest water layer thickness [m]
+      ! This data will be used as mask to merdge space in 1D vector
+      !----------------------------------------------------------------
+
+      CALL iom_open ( 'mesh_mask'  , nummsh )   
+      CALL iom_open ( 'e3tbot'     , numblt )
+
+      ! mask sediment points for outputs
+      CALL iom_get( nummsh, jpdom_data, 'tmask' , tmask )
+      CALL iom_get( nummsh, jpdom_data, 'mbathy', sbathy )
+      
+      ! longitude/latitude values
+      CALL iom_get ( nummsh, jpdom_data,'nav_lon', glamt(:,:) )
+      CALL iom_get ( nummsh, jpdom_data,'nav_lat', gphit(:,:) )
+    
+      ! bottom layer thickness
+      CALL iom_get  ( numblt, jpdom_data, 'E3TBOT', zdta(:,:) )
+      epkbot(:,:) = 0.
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ikt = MAX( INT( sbathy(ji,jj) )  - 1, 1 )
+            IF( tmask(ji,jj,ikt) == 1 ) epkbot(ji,jj) = zdta(ji,jj)
+         ENDDO
+      ENDDO
+
+      CALL iom_close( nummsh )  
+      CALL iom_close( numblt ) 
+#else
+
+      epkbot(:,:) = 0.
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ikt = MAX( mbathy(ji,jj) - 1, 1 )
+            IF( tmask(ji,jj,ikt) == 1 ) epkbot(ji,jj) = e3t_0(ikt)
+         ENDDO
+      ENDDO
+#endif     
+
+
+      ! computation of total number of ocean points
+      !--------------------------------------------
+      jpoce  = COUNT( epkbot(:,:) > 0. )
+
+
+      ! Allocate memory size of global variables
+      ALLOCATE( pwcp (jpoce,jpksed,jpwat) )  ;  ALLOCATE( pwcp0 (jpoce,jpksed,jpwat) ) ;  ALLOCATE( pwcp_dta  (jpoce,jpwat) )
+      ALLOCATE( solcp(jpoce,jpksed,jpsol) )  ;  ALLOCATE( solcp0(jpoce,jpksed,jpsol) ) ;  ALLOCATE( rainrm_dta(jpoce,jpsol) )
+      ALLOCATE( rainrm(jpoce,jpsol) )        ;  ALLOCATE( rainrg(jpoce,jpsol) )        ;  ALLOCATE( raintg(jpoce) ) 
+      ALLOCATE( dzdep(jpoce) )               ;  ALLOCATE( iarroce(jpoce) )             ;  ALLOCATE( dzkbot(jpoce) )
+      ALLOCATE( temp(jpoce) )                ;  ALLOCATE( salt(jpoce) )                
+      ALLOCATE( press(jpoce) )               ;  ALLOCATE( densSW(jpoce) ) 
+      ALLOCATE( hipor(jpoce,jpksed) )        ;  ALLOCATE( co3por(jpoce,jpksed) ) 
+      ALLOCATE( dz3d(jpoce,jpksed) )         ;  ALLOCATE( volw3d(jpoce,jpksed) )       ;  ALLOCATE( vols3d(jpoce,jpksed) )
+
+      ! Initialization of global variables
+      pwcp  (:,:,:) = 0.  ;  pwcp0 (:,:,:) = 0.  ; pwcp_dta  (:,:) = 0.  
+      solcp (:,:,:) = 0.  ;  solcp0(:,:,:) = 0.  ; rainrm_dta(:,:) = 0.
+      rainrm(:,:  ) = 0.  ;  rainrg(:,:  ) = 0.  ; raintg    (:  ) = 0. 
+      dzdep (:    ) = 0.  ;  iarroce(:   ) = 0   ; dzkbot    (:  ) = 0.
+      temp  (:    ) = 0.  ;  salt   (:   ) = 0.  
+      press (:    ) = 0.  ;  densSW (:   ) = 0. 
+      hipor (:,:  ) = 0.  ;  co3por (:,: ) = 0.  
+      dz3d  (:,:  ) = 0.  ;  volw3d (:,: ) = 0.  ;  vols3d   (:,:) = 0. 
+
+      ! Chemical variables      
+      ALLOCATE( akbs  (jpoce) )  ;  ALLOCATE( ak1s   (jpoce) )  ;  ALLOCATE( ak2s  (jpoce) ) ;  ALLOCATE( akws  (jpoce) )     
+      ALLOCATE( ak1ps (jpoce) )  ;  ALLOCATE( ak2ps  (jpoce) )  ;  ALLOCATE( ak3ps (jpoce) ) ;  ALLOCATE( aksis (jpoce) )    
+      ALLOCATE( aksps (jpoce) )  ;  ALLOCATE( ak12s  (jpoce) )  ;  ALLOCATE( ak12ps(jpoce) ) ;  ALLOCATE( ak123ps(jpoce) )    
+      ALLOCATE( borats(jpoce) )  ;  ALLOCATE( calcon2(jpoce) )    
+
+      akbs  (:) = 0. ;   ak1s   (:) = 0. ;  ak2s  (:) = 0. ;   akws   (:) = 0.
+      ak1ps (:) = 0. ;   ak2ps  (:) = 0. ;  ak3ps (:) = 0. ;   aksis  (:) = 0.
+      aksps (:) = 0. ;   ak12s  (:) = 0. ;  ak12ps(:) = 0. ;   ak123ps(:) = 0.
+      borats(:) = 0. ;   calcon2(:) = 0.
+
+      ! Mass balance calculation  
+      ALLOCATE( fromsed(jpoce, jpsol) ) ; ALLOCATE( tosed(jpoce, jpsol) ) ;  ALLOCATE( rloss(jpoce, jpsol) )
+      ALLOCATE( tokbot (jpoce, jpwat) ) 
+
+      fromsed(:,:) = 0.    ;   tosed(:,:) = 0. ;  rloss(:,:) = 0.  ;   tokbot(:,:) = 0. 
+
+      ! Read sediment Namelist
+      !-------------------------
+      CALL sed_init_nam
+    
+      ! Initialization of sediment geometry
+      !------------------------------------
+      CALL sed_init_geom
+
+
+      ! sets initial sediment composition
+      ! ( only clay or reading restart file )
+      !---------------------------------------
+      CALL sed_init_data
+
+
+      CALL sed_init_wri
+
+
+   END SUBROUTINE sed_init
+
+
+   SUBROUTINE sed_init_geom
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_init_geom  ***
+      !!
+      !! ** Purpose :  Initialization of sediment geometry
+      !!               - Read the deepest water layer thickness
+      !!                 ( using as mask ) in Netcdf file
+      !!               - sets sediment grid, porosity and molecular weight
+      !!                 and others constants
+      !!
+      !!   History :
+      !!        !  06-07  (C. Ethe)  Original
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      !! * local declarations
+      INTEGER ::  &
+        ji, jj, jk
+ 
+#if defined key_sed_off
+      REAL(wp) , DIMENSION (jpi,jpj) :: zdta
+      INTEGER  ::  numpres = 52
+#endif
+      !---------------------------------------------------------- 
+
+      WRITE(numsed,*) ' sed_init_geom : Initialization of sediment geometry '
+      WRITE(numsed,*) ' '
+
+      ! Computation of 1D array of sediments points
+      indoce = 0
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF (  epkbot(ji,jj) > 0. ) THEN
+               indoce          = indoce + 1
+               iarroce(indoce) = (jj - 1) * jpi + ji
+            ENDIF
+         END DO
+      END DO
+
+      IF( indoce .NE. jpoce ) THEN
+         WRITE(numsed,*) ' '
+         WRITE(numsed,*) 'Warning : number of ocean points indoce = ', indoce, &
+            &     ' doesn''t match  number of point where epkbot>0  jpoce = ', jpoce
+         WRITE(numsed,*) ' '
+         WRITE(numsed,*) ' '
+         STOP
+      ELSE
+         WRITE(numsed,*) ' '
+         WRITE(numsed,*) ' total number of ocean points jpoce =  ',jpoce
+         WRITE(numsed,*) ' '
+      ENDIF
+
+#if defined key_sed_off
+
+      ! Reading Netcdf Pisces file for deepest water layer thickness [m]
+      ! This data will be used as mask to merdge space in 1D vector
+      !----------------------------------------------------------------
+      CALL iom_open ( 'pressbot'   , numpres )
+      
+      ! pressure  in  bars      
+      CALL iom_get ( numpres, jpdom_data,'BATH', zdta(:,:) )
+      CALL pack_arr ( jpoce, press(1:jpoce), zdta(1:jpi,1:jpj), iarroce(1:jpoce) )
+      press(1:jpoce) = press(1:jpoce) * 1.025e-1 
+
+      CALL iom_close ( numpres )
+#endif
+
+
+      ! mask sediment points for outputs
+      DO jk = 1, jpksed
+         tmasksed(:,:,jk) = tmask(:,:,1)
+      ENDDO
+
+      ! initialization of dzkbot in [cm]
+      !------------------------------------------------    
+      CALL pack_arr ( jpoce, dzkbot(1:jpoce), epkbot(1:jpi,1:jpj), iarroce(1:jpoce) )
+      dzkbot(1:jpoce) = dzkbot(1:jpoce) * 1.e+2 
+
+      ! Geometry and  constants 
+      ! sediment layer thickness [cm]
+      ! (1st layer= diffusive layer = pur water) 
+      !------------------------------------------
+      dz(1)  = 0.1
+      dz(2)  = 0.3
+      dz(3)  = 0.3
+      dz(4)  = 0.5
+      dz(5)  = 0.5
+      dz(6)  = 0.5
+      dz(7)  = 1.
+      dz(8)  = 1.
+      dz(9)  = 1.
+      dz(10) = 2.45
+      dz(11) = 2.45
+
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            dz3d(ji,jk) = dz(jk)
+         END DO
+      ENDDO
+
+      ! Depth(jk)= depth of middle of each layer
+      !----------------------------------------
+      profsed(1) = -dz(1)/ 2.
+      DO jk = 2, jpksed
+         profsed(jk) = profsed(jk-1) + dz(jk-1) / 2. + dz(jk) / 2.
+      ENDDO
+
+      !  Porosity profile [0]
+      !---------------------
+      por(1)  = 1.
+      por(2)  = 0.95
+      por(3)  = 0.9
+      por(4)  = 0.85
+      por(5)  = 0.81
+      por(6)  = 0.75
+      por(7)  = 0.75      
+      por(8)  = 0.75      
+      por(9)  = 0.75      
+      por(10) = 0.75
+      por(11) = 0.75
+ 
+      ! inverse of  Porosity profile
+      !-----------------------------
+      por1(:) = 1. - por(:)
+
+      ! Volumes of pore water and solid fractions (vector and array)
+      !     WARNING : volw(1) and vols(1) are sublayer volums
+      volw(:) = dz(:) * por(:)
+      vols(:) = dz(:) * por1(:)
+
+      ! temporary new value for dz3d(:,1) 
+      dz3d(1:jpoce,1) = dzkbot(1:jpoce)
+
+      ! WARNING : volw3d(:,1) and vols3d(:,1) are deepest water column volums
+      DO jk = 1, jpksed
+         volw3d(1:jpoce,jk) = dz3d(1:jpoce,jk) * por (jk)
+         vols3d(1:jpoce,jk) = dz3d(1:jpoce,jk) * por1(jk)
+      ENDDO
+
+      ! Back to the old sublayer vlaue for dz3d(:,1)
+      dz3d(1:jpoce,1) = dz(1)
+
+
+      !---------------------------------------------
+      ! Molecular weight [g/mol] for solid species
+      !---------------------------------------------
+
+
+      ! opal=sio2*0.4(h20)=28+2*16+0.4*(2+16)
+      !---------------------------------------
+      mol_wgt(jsopal) = 28. + 2. * 16. + 0.4 * ( 2. + 16. )  
+
+      !  clay
+      !  some kind of Illit (according to Pape)
+      !  K0.58(Al 1.38 Fe(III)0.37Fe(II)0.04Mg0.34)[(OH)2|(Si3.41Al0.59)O10]
+      !--------------------------------------------------------------------
+      mol_wgt(jsclay) = 0.58 * 39. + 1.38 * 27. + ( 0.37 + 0.04 ) * 56.+ &
+         &              0.34 * 24. + 2. * ( 16. + 1. ) + 3.41 * 38. +    &
+         &              0.59 * 27. + 10. * 16.
+
+      ! for chemistry Poc : C(122)H(244)O(86)N(16)P(1)
+      ! But den sity of Poc is an Hydrated material (= POC + 30H2O)
+      ! So C(122)H(355)O(120)N(16)P(1)
+      !------------------------------------------------------------
+      mol_wgt(jspoc) = ( 122. * 12. + 355. + 120. * 16.+ &
+         &                16. * 14. + 31. ) / 122.
+
+      ! CaCO3
+      !---------
+      mol_wgt(jscal) = 40. + 12. + 3. * 16.
+
+      ! Density of solid material in sediment [g/cm**3]
+      !------------------------------------------------
+      dens = 2.6
+
+      ! Initialization of diffusion coefficient as function of porosity [cm**2/s]
+      !--------------------------------------------------------------------
+      diff(:) = dcoef * por(:)
+
+
+      ! Initialization of time step as function of porosity [cm**2/s]
+      !------------------------------------------------------------------
+      rdtsed(2:jpksed) = dtsed / ( dens * por1(2:jpksed) )
+     
+   END SUBROUTINE sed_init_geom
+
+   SUBROUTINE sed_init_nam
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_init_nam  ***
+      !!
+      !! ** Purpose :  Initialization of sediment geometry
+      !!               - Reading namelist and defines constants variables
+      !!
+      !!   History :
+      !!        !  06-07  (C. Ethe)  Original
+      !!----------------------------------------------------------------------
+
+      INTEGER :: &
+         numnamsed = 28
+
+
+      NAMELIST/nam_time/nfreq
+      NAMELIST/nam_dia3d/sedtrc3d,sedtrc3l,sedtrc3u
+      NAMELIST/nam_dia2d/sedtrc2d,sedtrc2l,sedtrc2u
+      NAMELIST/nam_reac/sisat, claysat, rcopal, rcclay, dcoef 
+      NAMELIST/nam_poc/redO2, redNo3, redPo4, redC, redDnit, &
+         &           rcorg, o2seuil, rcorgN
+      NAMELIST/nam_cal/rccal
+      NAMELIST/nam_dc13/pdb, rc13P, rc13Ca
+      NAMELIST/nam_btb/dbiot
+      NAMELIST/nam_rst/ln_rst_sed
+
+      INTEGER :: jn
+
+      !-------------------------------------------------------
+
+      WRITE(numsed,*) ' sed_init_nam : Read namelists '
+      WRITE(numsed,*) ' '
+
+      ! ryear = 1 year converted in second
+      !------------------------------------
+      WRITE(numsed,*) ' '
+      WRITE(numsed,*) 'number of seconds in one year : ryear = ', ryear
+      WRITE(numsed,*) ' '     
+
+      ! Reading namelist.sed variables
+      !---------------------------------------
+      OPEN( UNIT = numnamsed, FILE = 'namelist.sediment', FORM = 'FORMATTED', STATUS = 'OLD' )
+
+      dtsed = rdt
+#if ! defined key_sed_off
+      nitsed000 = nittrc000
+      nitsedend = nitend
+      nwrised   = nwritetrc
+      nfreq     = 1
+#else
+      nitsed000 = nit000
+      nitsedend = nitend
+      nwrised   = nwrite
+#endif
+     ! Diffraction/reaction parameters
+      !----------------------------------
+      READ( numnamsed, nam_time )
+      WRITE(numsed,*) ' namelist nam_time'
+
+      WRITE(numsed,*) ' sedimentation time step              dtsed      = ', dtsed
+      WRITE(numsed,*) ' 1st time step for sediment.          nitsed000  = ', nitsed000
+      WRITE(numsed,*) ' last time step for sediment.         nitsedend  = ', nitsedend
+      WRITE(numsed,*) ' frequency of sediment outputs        nwrised    = ', nwrised
+      WRITE(numsed,*) ' frequency of restoring inputs data   nfreq      = ', nfreq
+      WRITE(numsed,*) ' '
+
+      READ( numnamsed, nam_dia3d )
+      WRITE(numsed,*) ' namelist nam_dia3d'
+      DO jn = 1, jptrased
+         WRITE(numsed,*) 'name of 3d output sediment field number :',jn,' : ',sedtrc3d(jn)
+         WRITE(numsed,*)  sedtrc3l(jn)
+         WRITE(numsed,*) ' in unit = ', sedtrc3u(jn)
+      END DO
+      WRITE(numsed,*) ' '
+
+      
+      READ( numnamsed, nam_dia2d )
+      WRITE(numsed,*) ' namelist nam_dia2d'
+      DO jn = 1, jpflxsed
+         WRITE(numsed,*) 'name of 2d output sediment field number :',jn,' : ',sedtrc2d(jn)
+         WRITE(numsed,*) sedtrc2l(jn)
+         WRITE(numsed,*) ' in unit = ',sedtrc2u(jn)
+      END DO
+      WRITE(numsed,*) ' '
+
+
+      ! Diffraction/reaction parameters
+      !----------------------------------
+      READ( numnamsed, nam_reac )
+      WRITE(numsed,*) ' namelist nam_reac'
+      WRITE(numsed,*) ' saturation for si    sisat   = ', sisat
+      WRITE(numsed,*) ' saturation for clay  claysat = ', claysat
+      WRITE(numsed,*) ' reactivity for Si    rcopal  = ', rcopal
+      WRITE(numsed,*) ' reactivity for clay  rcclay  = ', rcclay
+      WRITE(numsed,*) ' diff. coef for por.  dcoef   = ', dcoef
+      WRITE(numsed,*) ' '
+
+
+      ! Unity conversion to get saturation conc. psat in [mol.l-1]
+      ! and reactivity rc in  [l.mol-1.s-1]
+      !----------------------------------------------------------
+      sat_sil   = sisat   * 1.e-6   
+      sat_clay  = claysat * 1.e-6
+
+      reac_sil  = rcopal / ryear     
+      reac_clay  = rcclay / ryear
+
+
+      ! Additional parameter linked to POC/O2/No3/Po4
+      !----------------------------------------------
+      READ( numnamsed, nam_poc )
+      WRITE(numsed,*) ' namelist nam_poc'
+      WRITE(numsed,*) ' Redfield coef for oxy     redO2   = ', redO2
+      WRITE(numsed,*) ' Redfield coef for no3     redNo3  = ', redNo3
+      WRITE(numsed,*) ' Redfield coef for po4     redPo4  = ', redPo4
+      WRITE(numsed,*) ' Redfield coef for carbone redC    = ', redC
+      WRITE(numsed,*) ' Redfield coef for denitri redDnit = ', redDnit
+      WRITE(numsed,*) ' reactivity for POC/O2     rcorg   = ', rcorg
+      WRITE(numsed,*) ' threshold O2 concen.      o2seuil = ', o2seuil
+      WRITE(numsed,*) ' reactivity for POC/NO3    rcorgN  = ', rcorgN
+      WRITE(numsed,*) ' '
+
+
+      so2ut  = redO2   / redC
+      srno3  = redNo3  / redC
+      spo4r  = redPo4  / redC
+      srDnit = redDnit / redC
+      sthro2 = o2seuil * 1.e-6 ! threshold O2 concen. in [mol.l-1]
+      ! reactivity rc in  [l.mol-1.s-1]
+      reac_poc  = rcorg / ryear
+      reac_no3 = rcorgN  / ryear
+
+
+      ! Carbonate parameters
+      !---------------------
+      READ( numnamsed, nam_cal )
+      WRITE(numsed,*) ' namelist  nam_cal'
+      WRITE(numsed,*) ' reactivity for calcite rccal = ', rccal
+      WRITE(numsed,*) ' '
+
+      ! reactivity rc in  [l.mol-1.s-1]      
+      reac_cal = rccal / ryear
+
+
+      ! C13  parameters
+      !----------------
+      READ( numnamsed, nam_dc13 )
+      WRITE(numsed,*) ' namelist nam_dc13 ' 
+      WRITE(numsed,*) ' 13C/12C in PD Belemnite        PDB    = ', pdb
+      WRITE(numsed,*) ' 13C/12C in POC = rc13P*PDB     rc13P  = ', rc13P
+      WRITE(numsed,*) ' 13C/12C in CaCO3 = rc13Ca*PDB  rc13Ca = ', rc13Ca
+      WRITE(numsed,*) ' '
+
+      
+      ! Bioturbation parameter
+      !------------------------
+      READ( numnamsed, nam_btb )
+      WRITE(numsed,*) ' namelist nam_btb ' 
+      WRITE(numsed,*) ' coefficient for bioturbation   dbiot    = ', dbiot
+      WRITE(numsed,*) ' '
+
+      ! Unity convertion to get bioturb coefficient in [cm2.s-1]
+      db = dbiot / ( ryear * 1000. )
+
+      ! Initial value (t=0) for sediment pore water and solid components
+      !----------------------------------------------------------------
+      READ( numnamsed, nam_rst )
+      WRITE(numsed,*) ' namelist  nam_rst ' 
+      WRITE(numsed,*) '  boolean term for restart (T or F) ln_rst_sed = ', ln_rst_sed 
+      WRITE(numsed,*) ' '
+
+      CLOSE( numnamsed )
+
+   END SUBROUTINE sed_init_nam
+
+   SUBROUTINE sed_init_data
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_init_data  ***
+      !!
+      !! ** Purpose :  Initialization of sediment module
+      !!               - sets initial sediment composition
+      !!                 ( only clay or reading restart file )
+      !!
+      !!   History :
+      !!        !  06-07  (C. Ethe)  original
+      !!----------------------------------------------------------------------
+ 
+      ! local variables
+      INTEGER :: &
+         ji, jk, zhipor
+
+      !--------------------------------------------------------------------
+ 
+
+      IF( .NOT. ln_rst_sed ) THEN
+
+          WRITE(numsed,*) ' Initilization of default values of sediment components'
+
+         ! default values for initial pore water concentrations [mol/l]
+         pwcp(:,:,:) = 0.
+         ! default value for initial solid component (fraction of dry weight dim=[0])
+         ! clay
+         solcp(:,:,:) = 0.
+         solcp(:,2:jpksed,jsclay) = 1.
+
+         ! Initialization of [h+] and [co3--]
+
+         zhipor = 8.
+         ! Initialization of [h+] in mol/kg
+         DO jk = 1, jpksed
+            DO ji = 1, jpoce
+               hipor (ji,jk) = 10.**( -1. * zhipor )
+            ENDDO
+         ENDDO
+
+         co3por(:,:) = 0.
+
+      ELSE   
+  
+         WRITE(numsed,*) ' Initilization of Sediment components from restart'
+
+         CALL sed_rst_read
+
+      ENDIF
+
+
+      ! Load initial Pisces Data for bot. wat. Chem and fluxes
+      CALL sed_dta ( nitsed000 ) 
+
+      ! Initialization of chemical constants
+      CALL sed_chem ( nitsed000 )
+
+      ! Stores initial sediment data for mass balance calculation
+      pwcp0 (1:jpoce,1:jpksed,1:jpwat ) = pwcp (1:jpoce,1:jpksed,1:jpwat ) 
+      solcp0(1:jpoce,1:jpksed,1:jpsol ) = solcp(1:jpoce,1:jpksed,1:jpsol) 
+
+      ! Conversion of [h+] in mol/Kg to get it in mol/l ( multiplication by density)
+      DO jk = 1, jpksed
+         hipor(1:jpoce,jk) = hipor(1:jpoce,jk) * densSW(1:jpoce)
+      ENDDO
+
+
+      ! In default case - no restart - sedco3 is run to initiate [h+] and [co32-]
+      ! Otherwise initiate values of pH and co3 read in restart
+      IF( .NOT. ln_rst_sed ) THEN
+         ! sedco3 is run to initiate[h+] [co32-] in mol/l of solution
+         CALL sed_co3 ( nitsed000 )
+
+      ENDIF
+            
+   END SUBROUTINE sed_init_data
+
+   SUBROUTINE sed_init_wri
+
+      INTEGER :: jk
+
+      WRITE(numsed,*)' '
+      WRITE(numsed,*)'======== Write summary of initial state   ============'
+      WRITE(numsed,*)' '
+      WRITE(numsed,*)' '
+      WRITE(numsed,*)'-------------------------------------------------------------------'
+      WRITE(numsed,*)' Initial Conditions '
+      WRITE(numsed,*)'-------------------------------------------------------------------'
+      WRITE(numsed,*)'dzm = dzkbot minimum to calculate ', 0.
+      WRITE(numsed,*)'Local zone : jpi, jpj : ',jpi, jpj
+      WRITE(numsed,*)'jpoce = ',jpoce,' nbtot pts = ',jpij,' nb earth pts = ',jpij - jpoce
+      WRITE(numsed,*)'sublayer thickness dz(1) [cm] : ', dz(1)
+      WRITE(numsed,*)'Coeff diff for k=1 (cm2/s) : ',diff(1)
+      WRITE(numsed,*)' nb solid comp : ',jpsol
+      WRITE(numsed,*)'(1=opal,2=clay,3=POC,4=CaCO3)'
+      WRITE(numsed,*)'weight mol 1,2,3,4'
+      WRITE(numsed,'(4(F0.2,3X))')mol_wgt(jsopal),mol_wgt(jsclay),mol_wgt(jspoc),mol_wgt(jscal)
+      WRITE(numsed,*)'nb dissolved comp',jpwat
+      WRITE(numsed,*)'(1=silicic acid,2="dissolved" clay,3=O2,4=DIC,5=Nitrate,&
+         &6=Phosphates,7=Alk))'
+      WRITE(numsed,*)'Psat (µmol/l) for silicic Acid and "dissolved" clay'
+      WRITE(numsed,'(2(F0.2,3X))') sat_sil, sat_clay
+      WRITE(numsed,*)'reaction rate rc for Op/si,Clay,POC/O2,caco3, POC/No3 (an-1)'
+      WRITE(numsed,'(5(F0.2,3X))') reac_sil, reac_clay, reac_poc, reac_cal, reac_no3 
+      WRITE(numsed,*)'redfield coef C,O,N P Dit '
+      WRITE(numsed,'(5(F0.2,3X))')1./spo4r,so2ut/spo4r,srno3/spo4r,spo4r/spo4r,srDnit/spo4r
+      WRITE(numsed,*)'threshold for stating denitrification [mol/l]'
+      WRITE(numsed,'(1PE8.2)') sthrO2
+      WRITE(numsed,*)'-------------------------------------------------------------------'
+      WRITE(numsed,*)'Min-Max-Mean'
+      WRITE(numsed,*)'For each variable : min, max, moy value observed on selected local zone'
+      WRITE(numsed,*)'-------------------------------------------------------------------'
+      WRITE(numsed,*)'thickness of the last wet layer dzkbot [m]'
+      WRITE(numsed,'(3(F0.2,3X))') MINVAL(dzkbot(1:jpoce))/100.,MAXVAL(dzkbot(1:jpoce))/100.,&
+         &SUM(dzkbot(1:jpoce))/jpoce/100.
+      WRITE(numsed,*)'temp [°C]'
+      WRITE(numsed,'(3(F0.2,3X))') MINVAL(temp(1:jpoce)),MAXVAL(temp(1:jpoce)),&
+         &                         SUM(temp(1:jpoce))/jpoce
+      WRITE(numsed,*)'salt o/oo'
+      WRITE(numsed,'(3(F0.2,3X))')MINVAL(salt(1:jpoce)),MAXVAL(salt(1:jpoce)),&
+         &                        SUM(salt(1:jpoce))/jpoce
+#if defined key_sed_off
+      WRITE(numsed,*)'pressure [bar] (depth in m is about 10*pressure)'
+      WRITE(numsed,'(3(F0.2,3X))') MINVAL(press(1:jpoce)),MAXVAL(press(1:jpoce)),&
+         &                         SUM(press(1:jpoce))/jpoce
+#endif
+      WRITE(numsed,*)'density of Sea Water'
+      WRITE(numsed,'(3(F0.2,3X))') MINVAL(densSW(1:jpoce)), MAXVAL(densSW(1:jpoce)),&
+         &                         SUM(densSW(1:jpoce))/jpoce
+      WRITE(numsed,*)''
+      WRITE(numsed,*)'     Dissolved Components '
+      WRITE(numsed,*)'     ====================='
+      WRITE(numsed,*)'[Si(OH)4] dissolved (1)(k=1)(µmol/l)(and min value in mol/kg  of solution)'
+      WRITE(numsed,'(4(F0.3,2X))') MINVAL(pwcp(1:jpoce,1,jwsil))*1.e+6,MAXVAL(pwcp(1:jpoce,1,jwsil))*1.e+6,&
+         &                         SUM(pwcp(1:jpoce,1,jwsil))*1.e+6/jpoce,&
+         &                         MINVAL(pwcp(1:jpoce,1,jwsil)*1.e+6/densSW(1:jpoce))
+      WRITE(numsed,*)'[O2]    dissolved (3) (k=1)(µmol/l)(and min value in mol/kg  of solution)'
+      WRITE(numsed,'(4(F0.3,2X))') MINVAL(pwcp(1:jpoce,1,jwoxy))*1.e+6,MAXVAL(pwcp(1:jpoce,1,jwoxy))*1.e+6,&
+         &SUM(pwcp(1:jpoce,1,jwoxy))*1.e+6/jpoce,&
+         &MINVAL(pwcp(1:jpoce,1,jwoxy)*1.e+6/densSW(1:jpoce))
+      WRITE(numsed,*)'[DIC]    dissolved (4) (k=1)(µmol/l)(and min value in mol/kg  of solution)'
+      WRITE(numsed,'(4(F0.3,2X))') MINVAL(pwcp(1:jpoce,1,jwdic))*1.e+6,MAXVAL(pwcp(1:jpoce,1,jwdic))*1.e+6,&
+         &SUM(pwcp(1:jpoce,1,jwdic))*1.e+6/jpoce,&
+         &MINVAL(pwcp(1:jpoce,1,jwdic)*1.e+6/densSW(1:jpoce))
+      WRITE(numsed,*)'[NO3]    dissolved (5) (k=1)(µmol/l)(and min value in mol/kg  of solution)'
+      WRITE(numsed,'(4(F0.3,2X))') MINVAL(pwcp(1:jpoce,1,jwno3))*1.e+6,MAXVAL(pwcp(1:jpoce,1,jwno3))*1.e+6,&
+         &SUM(pwcp(1:jpoce,1,jwno3))*1.e+6/jpoce,&
+         &MINVAL(pwcp(1:jpoce,1,jwno3)*1.e+6/densSW(1:jpoce))
+      WRITE(numsed,*)'[PO4]    dissolved (6) (k=1)(µmol/l)(and min value in mol/kg  of solution)'
+      WRITE(numsed,'(4(F0.3,2X))') MINVAL(pwcp(1:jpoce,1,jwpo4))*1.e+6,MAXVAL(pwcp(1:jpoce,1,jwpo4))*1.e+6,&
+         &SUM(pwcp(1:jpoce,1,jwpo4))*1.e+6/jpoce,&
+         &MINVAL(pwcp(1:jpoce,1,jwpo4)*1.e+6/densSW(1:jpoce))
+      WRITE(numsed,*)'[Alk]    dissolved (7) (k=1)(µequi)(and min value in mol/kg  of solution)'
+      WRITE(numsed,'(4(F0.3,2X))') MINVAL(pwcp(1:jpoce,1,jwalk))*1.e+6,MAXVAL(pwcp(1:jpoce,1,jwalk))*1.e+6,&
+         &SUM(pwcp(1:jpoce,1,jwalk))*1.e+6/jpoce,&
+         &MINVAL(pwcp(1:jpoce,1,jwalk)*1.e+6/densSW(1:jpoce))
+      WRITE(numsed,*)'[DIC13]  dissolved (8) (k=1)(µmol/l)(and min value in mol/kg  of solution)'
+      WRITE(numsed,'(4(F0.3,2X))') MINVAL(pwcp(1:jpoce,1,jwc13))*1.e+6,MAXVAL(pwcp(1:jpoce,1,jwc13))*1.e+6,&
+         &SUM(pwcp(1:jpoce,1,jwc13))*1.e+6/jpoce,&
+         &MINVAL(pwcp(1:jpoce,1,jwc13)*1.e+6/densSW(1:jpoce))
+      WRITE(numsed,*)''
+      WRITE(numsed,*)'     Solid Components '
+      WRITE(numsed,*)'     ====================='
+      WRITE(numsed,*)'nmole of Opale rained per dt'
+      WRITE(numsed,'(3(1PE9.3,2X))') MINVAL(rainrm(1:jpoce,jsopal))*dtsed,MAXVAL(rainrm(1:jpoce,jsopal))*dtsed,&
+         &SUM(rainrm(1:jpoce,1))*dtsed/jpoce
+      WRITE(numsed,*)'nmole of Clay rained per dt'
+      WRITE(numsed,'(3(1PE9.3,2X))') MINVAL(rainrm(1:jpoce,jsclay))*dtsed,MAXVAL(rainrm(1:jpoce,jsclay))*dtsed,&
+         &SUM(rainrm(1:jpoce,jsclay))*dtsed/jpoce
+      WRITE(numsed,*)'nmole of POC rained per dt'
+      WRITE(numsed,'(3(1PE9.3,2X))') MINVAL(rainrm(1:jpoce,jspoc))*dtsed,MAXVAL(rainrm(1:jpoce,jspoc))*dtsed,&
+         &SUM(rainrm(1:jpoce,jspoc))*dtsed/jpoce
+      WRITE(numsed,*)'nmole of CaCO3 rained per dt'
+      WRITE(numsed,'(3(1PE9.3,2X))') MINVAL(rainrm(1:jpoce,jscal))*dtsed,MAXVAL(rainrm(1:jpoce,jscal))*dtsed,&
+         &SUM(rainrm(1:jpoce,jscal))*dtsed/jpoce
+      WRITE(numsed,*)' '
+      WRITE(numsed,*)'Weight frac of opal rained (%) '
+      WRITE(numsed,'(3(F0.3,7X))') MINVAL(rainrg(1:jpoce,jsopal)/raintg(1:jpoce))*100.,&
+         &MAXVAL(rainrg(1:jpoce,jsopal)/raintg(1:jpoce))*100.,&
+         & SUM(rainrg(1:jpoce,jsopal)/raintg(1:jpoce))*100./jpoce
+      WRITE(numsed,*)'Weight frac of clay  rained (%) '
+      WRITE(numsed,'(3(F0.3,7X))') MINVAL(rainrg(1:jpoce,jsclay)/raintg(1:jpoce))*100.,&
+         &MAXVAL(rainrg(1:jpoce,jsclay)/raintg(1:jpoce))*100.,&
+         &SUM(rainrg(1:jpoce,jsclay)/raintg(1:jpoce))*100./jpoce
+      WRITE(numsed,*)'Weight frac of POC rained (%)'
+      WRITE(numsed,'(3(F0.3,7X))') MINVAL(rainrg(1:jpoce,jspoc)/raintg(1:jpoce))*100.,&
+         &MAXVAL(rainrg(1:jpoce,jspoc)/raintg(1:jpoce))*100.,&
+         &SUM(rainrg(1:jpoce,jspoc)/raintg(1:jpoce))*100./jpoce
+      WRITE(numsed,*)'Weight frac of CaCO3  rained (%)'
+      WRITE(numsed,'(3(F0.3,7X))') MINVAL(rainrg(1:jpoce,jscal)/raintg(1:jpoce))*100.,&
+         &MAXVAL(rainrg(1:jpoce,jscal)/raintg(1:jpoce))*100.,&
+         &SUM(rainrg(1:jpoce,jscal)/raintg(1:jpoce))*100./jpoce
+      WRITE(numsed,*)''
+      WRITE(numsed,*)' Thickness of sediment layer added by particule rain, dzdep cm '
+      WRITE(numsed,*)' =============================================================='
+      WRITE(numsed,'(3(F0.5,2X))') MINVAL(dzdep(1:jpoce)),MAXVAL(dzdep(1:jpoce)),SUM(dzdep(1:jpoce))/jpoce
+      WRITE(numsed,*)''
+      WRITE(numsed,*)' chemical constants K1,pK1,K2,pK2,Kw,pKw and Kb pKb (min max) [mol/kgsol] or [mol/kgsol]2 '
+      WRITE(numsed,*)' ========================================================================================='
+      WRITE(numsed,'(4(1PE10.3,2X))')MINVAL(ak1s(1:jpoce)),MAXVAL(ak1s(1:jpoce)),-LOG10(MINVAL(ak1s(1:jpoce))),&
+         &-LOG10(MAXVAL(ak1s(1:jpoce)))
+      WRITE(numsed,'(4(1PE10.3,2X))')MINVAL(ak2s(1:jpoce)),MAXVAL(ak2s(1:jpoce)),-LOG10(MINVAL(ak2s(1:jpoce))),&
+         &-LOG10(MAXVAL(ak2s(1:jpoce)))
+      WRITE(numsed,'(4(1PE10.3,2X))')MINVAL(akws(1:jpoce)),MAXVAL(akws(1:jpoce)),-LOG10(MINVAL(akws(1:jpoce))),&
+         &-LOG10(MAXVAL(akws(1:jpoce)))
+      WRITE(numsed,'(4(1PE10.3,2X))')MINVAL(akbs(1:jpoce)),MAXVAL(akbs(1:jpoce)),-LOG10(MINVAL(akbs(1:jpoce))),&
+         &-LOG10(MAXVAL(akbs(1:jpoce)))
+      WRITE(numsed,*)'and boron'
+      WRITE(numsed,'(2(1PE10.3,2X))')MINVAL(borats(1:jpoce)),MAXVAL(borats(1:jpoce))
+      WRITE(numsed,*)''
+      WRITE(numsed,*)' Compo of initial sediment for point jpoce'
+      WRITE(numsed,*)' ========================================='
+      WRITE(numsed,*)'solcp(1),   solcp(2),   solcp(3),   solcp(4),   hipor,      pH,         co3por'
+      DO jk = 1,jpksed
+         WRITE(numsed,'(7(1PE10.3,2X))')solcp(jpoce,jk,jsopal),solcp(jpoce,jk,jsclay),solcp(jpoce,jk,jspoc),solcp(jpoce,jk,jscal),&
+            &       hipor(jpoce,jk),-LOG10(hipor(jpoce,jk)/densSW(jpoce)),co3por(jpoce,jk)
+      ENDDO
+      WRITE(numsed,'(A82)')'pwcp(1),    pwcp(2),    pwcp(3),    pwcp(4),    pwcp(5),    pwcp(6),    pwcp(7)'
+      DO jk = 1, jpksed
+         WRITE(numsed,'(7(1PE10.3,2X))')pwcp(jpoce,jk,jwsil),pwcp(jpoce,jk,jwoxy),pwcp(jpoce,jk,jwdic),&
+            & pwcp(jpoce,jk,jwno3),pwcp(jpoce,jk,jwpo4),pwcp(jpoce,jk,jwalk),pwcp(jpoce,jk,jwc13)
+      ENDDO
+      WRITE(numsed,*) ' '
+      WRITE(numsed,*) ' End Of Initialization '
+      WRITE(numsed,*) ' '
+!
+   END SUBROUTINE sed_init_wri
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                      NO Sediment model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE sed_ini              ! Empty routine
+
+   END SUBROUTINE sed_ini
+#endif
+
+
+END MODULE sedini
+
+
+
Index: /trunk/NEMO/TOP_SRC/SED/sedmat.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sedmat.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sedmat.F90	(revision 1179)
@@ -0,0 +1,269 @@
+MODULE sedmat
+#if defined key_sed
+   !!======================================================================
+   !!              ***  MODULE  sedmat  ***
+   !!    Sediment : linear system of equations
+   !!=====================================================================
+   !! * Modules used
+   !!----------------------------------------------------------------------
+
+   USE sed     ! sediment global variable
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC sed_mat 
+
+   INTERFACE sed_mat
+      MODULE PROCEDURE sed_mat_dsr, sed_mat_btb
+   END INTERFACE
+
+   INTEGER, PARAMETER :: nmax = 30 
+
+
+ CONTAINS
+
+    SUBROUTINE sed_mat_dsr( nvar, ndim, nlev, preac, psol )
+       !!---------------------------------------------------------------------
+       !!                  ***  ROUTINE sed_mat_dsr  ***
+       !!
+       !! ** Purpose :  solves tridiagonal system of linear equations 
+       !!
+       !! ** Method  : 
+       !!        1 - computes left hand side of linear system of equations
+       !!            for dissolution reaction
+       !!         For mass balance in kbot+sediment :
+       !!              dz3d  (:,1) = dz(1) = 0.5 cm
+       !!              volw3d(:,1) = dzkbot ( see sedini.F90 ) 
+       !!              dz(2)       = 0.3 cm 
+       !!              dz3d(:,2)   = 0.3 + dzdep   ( see seddsr.F90 )     
+       !!              volw3d(:,2) and vols3d(l,2) are thickened ( see seddsr.F90 ) 
+       !!
+       !!         2 - forward/backward substitution. 
+       !!
+       !!   History :
+       !!        !  04-10 (N. Emprin, M. Gehlen ) original
+       !!        !  06-04 (C. Ethe)  Module Re-organization
+       !!----------------------------------------------------------------------
+       !! * Arguments
+       INTEGER , INTENT(in) :: &
+          nvar , &  ! number of variables
+          ndim , &  ! number of points
+          nlev      ! number of sediment levels
+
+       REAL(wp), DIMENSION(ndim,nlev,nvar), INTENT(in) :: &
+          preac     ! reaction rates
+
+       REAL(wp), DIMENSION(ndim,nlev,nvar), INTENT(inout) :: &
+          psol         ! solution ( undersaturation values )
+
+
+       !---Local declarations
+       INTEGER  ::  &
+          ji, jk, jn
+
+       REAL(wp), DIMENSION(ndim,nlev) :: za, zb, zc, zr
+       REAL(wp), DIMENSION(ndim)      :: zbet
+       REAL(wp), DIMENSION(ndim,nmax) :: zgamm
+
+       REAL(wp) ::  &
+          aplus,aminus   ,  & 
+          rplus,rminus   ,  &
+          dxplus,dxminus
+
+       !----------------------------------------------------------------------
+
+
+       ! Computation left hand side of linear system of 
+       ! equations for dissolution reaction
+       !---------------------------------------------
+
+
+       ! first sediment level          
+       DO ji = 1, ndim
+          aplus  = ( ( volw3d(ji,1) / dz3d(ji,1) ) + &
+                     ( volw3d(ji,2) / dz3d(ji,2) ) ) / 2.
+          dxplus = ( dz3d(ji,1) + dz3d(ji,2) ) / 2.
+          rplus  = ( dtsed / volw3d(ji,1) ) * diff(1) * aplus / dxplus 
+
+          za(ji,1) = 0.
+          zb(ji,1) = 1. + rplus
+          zc(ji,1) = -rplus
+       ENDDO
+ 
+       DO jk = 2, nlev - 1
+          DO ji = 1, ndim
+             aminus  = ( ( volw3d(ji,jk-1) / dz3d(ji,jk-1) ) + &
+                &        ( volw3d(ji,jk  ) / dz3d(ji,jk  ) ) ) / 2.
+             dxminus = ( dz3d(ji,jk-1) + dz3d(ji,jk) ) / 2.
+
+             aplus   = ( ( volw3d(ji,jk  ) / dz3d(ji,jk  ) ) + &
+                &        ( volw3d(ji,jk+1) / dz3d(ji,jk+1) ) ) / 2.
+             dxplus  = ( dz3d(ji,jk) + dz3d(ji,jk+1) ) / 2
+             !
+             rminus  = ( dtsed / volw3d(ji,jk) ) * diff(jk-1) * aminus / dxminus
+             rplus   = ( dtsed / volw3d(ji,jk) ) * diff(jk)   * aplus / dxplus
+             !     
+             za(ji,jk) = -rminus
+             zb(ji,jk) = 1. + rminus + rplus 
+             zc(ji,jk) = -rplus
+          END DO
+       END DO
+
+       DO ji = 1, ndim
+          aminus  = ( ( volw3d(ji,nlev-1) / dz3d(ji,nlev-1) ) + &
+             &        ( volw3d(ji,nlev)  / dz3d(ji,nlev) ) ) / 2.
+          dxminus = ( dz3d(ji,nlev-1) + dz3d(ji,nlev) ) / 2.
+          rminus  = ( dtsed / volw3d(ji,nlev) ) * diff(nlev-1) * aminus / dxminus
+          !
+          za(ji,nlev) = -rminus
+          zb(ji,nlev) = 1. + rminus
+          zc(ji,nlev) = 0.
+       END DO
+
+
+       ! solves tridiagonal system of linear equations 
+       ! -----------------------------------------------
+
+       DO jn = 1, nvar
+
+          zr  (:,:)    = psol(:,:,jn)
+          zbet(:  )    = zb(:,1) + preac(:,1,jn)
+          psol(:,1,jn) = zr(:,1) / zbet(:)
+          ! 
+          DO jk = 2, nlev
+             DO ji = 1, ndim
+                zgamm(ji,jk)   =  zc(ji,jk-1) / zbet(ji)
+                zbet(ji)       = ( zb(ji,jk) + preac(ji,jk,jn) ) - za(ji,jk) * zgamm(ji,jk)
+                psol(ji,jk,jn) = ( zr(ji,jk) - za(ji,jk) * psol(ji,jk-1,jn) ) / zbet(ji)
+             END DO
+          ENDDO
+          ! 
+          DO jk = nlev - 1, 1, -1
+             DO ji = 1,ndim
+                psol(ji,jk,jn) = psol(ji,jk,jn) - zgamm(ji,jk+1) * psol(ji,jk+1,jn)
+             END DO
+          ENDDO
+
+       ENDDO
+
+
+    END SUBROUTINE sed_mat_dsr
+
+    
+    SUBROUTINE sed_mat_btb( nvar, ndim, nlev, psol )
+       !!---------------------------------------------------------------------
+       !!                  ***  ROUTINE sed_mat_btb  ***
+       !!
+       !! ** Purpose :  solves tridiagonal system of linear equations 
+       !!
+       !! ** Method  : 
+       !!        1 - computes left hand side of linear system of equations
+       !!            for dissolution reaction
+       !!
+       !!         2 - forward/backward substitution. 
+       !!
+       !!   History :
+       !!        !  04-10 (N. Emprin, M. Gehlen ) original
+       !!        !  06-04 (C. Ethe)  Module Re-organization
+       !!----------------------------------------------------------------------
+       !! * Arguments
+       INTEGER , INTENT(in) :: &
+          nvar , &  ! number of variables
+          ndim , &  ! number of points
+          nlev      ! number of sediment levels
+
+      REAL(wp), DIMENSION(ndim,nlev,nvar), INTENT(inout) :: &
+          psol      ! solution
+
+       !---Local declarations
+       INTEGER  ::  &
+          ji, jk, jn
+
+       REAL(wp) ::  &
+          aplus,aminus   ,  & 
+          rplus,rminus   ,  &
+          dxplus,dxminus 
+
+       REAL(wp), DIMENSION(nlev)      :: za, zb, zc
+       REAL(wp), DIMENSION(ndim,nlev) :: zr
+       REAL(wp), DIMENSION(nmax)      :: zgamm 
+       REAL(wp) ::  zbet
+
+ 
+       !----------------------------------------------------------------------
+
+       ! Computation left hand side of linear system of 
+       ! equations for dissolution reaction
+       !---------------------------------------------
+
+
+       ! first sediment level          
+       aplus  = ( ( vols(2) / dz(2) ) + ( vols(3) / dz(3) ) ) / 2.
+       dxplus = ( dz(2) + dz(3) ) / 2.
+       rplus  = ( dtsed / vols(2) ) * db * aplus / dxplus 
+
+       za(1) = 0.
+       zb(1) = 1. + rplus
+       zc(1) = -rplus
+
+             
+       DO jk = 2, nlev - 1
+          aminus  = ( ( vols(jk) / dz(jk) ) + ( vols(jk+1) / dz(jk+1) ) ) / 2.
+          dxminus = ( dz(jk) + dz(jk+1) ) / 2.
+          rminus  = ( dtsed / vols(jk+1) ) * db * aminus / dxminus
+          !
+          aplus   = ( ( vols(jk+1) / dz(jk+1  ) ) + ( vols(jk+2) / dz(jk+2) ) ) / 2.
+          dxplus  = ( dz(jk+1) + dz(jk+2) ) / 2.
+          rplus   = ( dtsed / vols(jk+1) ) * db * aplus / dxplus
+          !     
+          za(jk) = -rminus
+          zb(jk) = 1. + rminus + rplus 
+          zc(jk) = -rplus
+       ENDDO
+ 
+       aminus  = ( ( vols(nlev) / dz(nlev) ) + ( vols(nlev+1) / dz(nlev+1) ) ) / 2.
+       dxminus = ( dz(nlev) + dz(nlev+1) ) / 2.
+       rminus  = ( dtsed / vols(nlev+1) ) * db * aminus / dxminus
+       !
+ 
+       za(nlev) = -rminus
+       zb(nlev) = 1. + rminus
+       zc(nlev) = 0.
+
+
+       ! solves tridiagonal system of linear equations 
+       ! -----------------------------------------------    
+       DO jn = 1, nvar
+          
+          zr  (:,:)    = psol(:,:,jn)
+          zbet         = zb(1)
+          psol(:,1,jn) = zr(:,1) / zbet
+          ! 
+          DO jk = 2, nlev
+             zgamm(jk) =  zc(jk-1) / zbet
+             zbet      =  zb(jk) - za(jk) * zgamm(jk)
+             DO ji = 1, ndim
+                psol(ji,jk,jn) = ( zr(ji,jk) - za(jk) * psol(ji,jk-1,jn) ) / zbet
+             END DO
+          ENDDO
+          ! 
+          DO jk = nlev - 1, 1, -1
+             DO ji = 1,ndim
+                psol(ji,jk,jn) = psol(ji,jk,jn) - zgamm(jk+1) * psol(ji,jk+1,jn)
+             END DO
+          ENDDO
+
+       ENDDO
+
+       
+    END SUBROUTINE sed_mat_btb
+
+
+#else
+   !!======================================================================
+   !! MODULE sedmat  :   Dummy module 
+   !!======================================================================
+#endif
+
+ END MODULE sedmat
Index: /trunk/NEMO/TOP_SRC/SED/sedmbc.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sedmbc.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sedmbc.F90	(revision 1179)
@@ -0,0 +1,342 @@
+MODULE sedmbc
+#if defined key_sed
+   !!======================================================================
+   !!              ***  MODULE  sedmbc  ***
+   !! Sediment : mass balance calculation
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   sed_mbc    : 
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE sed     ! sediment global variable
+   USE seddsr
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! *  Routine accessibility
+   PUBLIC sed_mbc
+
+   !! * Module variables
+   REAL(wp), DIMENSION(jpsol) :: &
+      rain_tot     ,  &      !
+      fromsed_tot  ,  &      ! 
+      tosed_tot    ,  &      !
+      rloss_tot              !
+
+   REAL(wp), DIMENSION(jpwat) :: &
+      diss_in_tot  ,  &      !
+      diss_out_tot           !
+
+   REAL(wp)  :: &
+      cons_tot_o2  ,  &      !
+      sour_tot_no3 ,  &      !
+      cons_tot_no3 ,  &      !
+      sour_tot_c13           !
+
+   REAL(wp) ::  &
+      src13p  , &
+      src13ca
+
+CONTAINS
+
+
+   SUBROUTINE sed_mbc( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_mbc  ***
+      !!
+      !! ** Purpose :  computation of total tracer inventories for checking
+      !!               mass conservation.
+      !!
+      !!
+      !! ** Method   : tracer inventories of each reservoir are computed and added
+      !!               subsequently.
+      !!
+      !!   History :
+      !!        !  04-10  (N. Emprin, M. Gehlen )  Original code
+      !!        !  06-07  (C. Ethe)  Re-organization
+      !!----------------------------------------------------------------------
+
+      !! Arguments
+      INTEGER, INTENT(in) :: &
+         kt
+
+      !! local declarations
+      INTEGER  :: &
+         ji, js, jw, jk
+
+      REAL(wp) ::  &
+         zinit, zfinal, &
+         zinput, zoutput
+
+      REAL(wp) ::  &
+         zdsw
+
+      REAL, DIMENSION(jpsol) ::  &
+         zsolcp_inv_i, zsolcp_inv_f
+
+      REAL, DIMENSION(jpwat) ::  &
+         zpwcp_inv_i, zpwcp_inv_f
+       
+      REAL(wp) :: &
+         zdelta_sil, zdelta_clay, &
+         zdelta_co2, zdelta_oxy,  &
+         zdelta_po4, zdelta_no3,  &
+         zdelta_c13, zdelta_c13b
+
+      !!----------------------------------------------------------------------
+      ! Initilization
+      !---------------
+      IF( kt == nitsed000 ) THEN
+         cons_tot_o2  = 0.
+         sour_tot_no3 = 0.
+         cons_tot_no3 = 0.
+         sour_tot_c13 = 0.
+
+         DO js = 1, jpsol
+            rain_tot   (js) = 0.
+            fromsed_tot(js) = 0.
+            tosed_tot  (js) = 0.
+            rloss_tot  (js) = 0.
+         ENDDO
+
+         DO jw = 1, jpwat
+            diss_in_tot (jw) = 0.
+            diss_out_tot(jw) = 0.
+         ENDDO
+
+         src13p  = rc13P  * pdb
+         src13ca = rc13Ca * pdb
+      ENDIF
+
+
+      ! Calculation of the cumulativ input and output
+      ! for mass balance check
+      !----------------------------------------------
+
+      ! cumulativ solid
+      DO js = 1, jpsol
+         DO ji = 1, jpoce
+            ! input [mol]
+            rain_tot   (js) = rain_tot   (js) + dtsed * rainrm_dta(ji,js)
+            fromsed_tot(js) = fromsed_tot(js) + fromsed(ji,js)
+            ! output [mol]
+            tosed_tot  (js) = tosed_tot (js) + tosed(ji,js)
+            rloss_tot  (js) = rloss_tot (js) + rloss(ji,js)
+         ENDDO
+      ENDDO
+
+      ! cumulativ dissolved
+      DO jw = 1, jpwat
+         DO ji = 1, jpoce
+            ! input [mol]
+            diss_in_tot (jw) = diss_in_tot (jw) + pwcp_dta(ji,jw) &
+               &                                * 1.e-3 * dzkbot(ji)
+            ! output [mol]
+            diss_out_tot(jw) = diss_out_tot(jw) + tokbot(ji,jw)
+         ENDDO
+      ENDDO
+
+      ! cumulativ o2 and no3 consomation
+      DO ji = 1, jpoce
+         cons_tot_o2  = cons_tot_o2  + cons_o2 (ji)
+         sour_tot_no3 = sour_tot_no3 + sour_no3(ji)
+         cons_tot_no3 = cons_tot_no3 + cons_no3(ji)
+         sour_tot_c13 = sour_tot_c13 + sour_c13(ji)
+      ENDDO
+     
+
+      ! Mass balance check
+      !---------------------
+      IF( kt == nitsedend ) THEN
+         ! initial and final inventories for solid component (mole/dx.dy) in sediment
+         zsolcp_inv_i(:) = 0.
+         zsolcp_inv_f(:) = 0.
+         zpwcp_inv_i (:) = 0.       
+         zpwcp_inv_f (:) = 0.        
+         DO js = 1, jpsol
+            zdsw = dens / mol_wgt(js)
+            DO jk = 2, jpksed
+               DO ji = 1, jpoce
+                  zsolcp_inv_i(js) = zsolcp_inv_i(js) + solcp0(ji,jk,js) * vols3d(ji,jk) * zdsw 
+                  zsolcp_inv_f(js) = zsolcp_inv_f(js) + solcp (ji,jk,js) * vols3d(ji,jk) * zdsw
+               ENDDO
+            END DO
+         ENDDO
+
+         ! initial and final inventories for dissolved component (mole/dx.dy) in sediment
+         DO jw = 1, jpwat
+            DO jk = 2, jpksed
+               DO ji = 1, jpoce 
+                  zpwcp_inv_i(jw) = zpwcp_inv_i(jw) + pwcp0(ji,jk,jw) *  volw3d(ji,jk) * 1.e-3
+                  zpwcp_inv_f(jw) = zpwcp_inv_f(jw) + pwcp (ji,jk,jw) *  volw3d(ji,jk) * 1.e-3
+               ENDDO
+            END DO
+         ENDDO
+
+         ! mass balance for Silica/opal
+         zinit      = zsolcp_inv_i(jsopal) + zpwcp_inv_i(jwsil)
+         zfinal     = zsolcp_inv_f(jsopal) + zpwcp_inv_f(jwsil)
+         zinput     = rain_tot    (jsopal) + diss_in_tot (jwsil)
+         zoutput    = tosed_tot   (jsopal) + rloss_tot  (jsopal) + diss_out_tot(jwsil)
+         zdelta_sil = ( zfinal + zoutput ) - ( zinit + zinput )
+
+
+         ! mass balance for Clay
+         zinit      = zsolcp_inv_i(jsclay) 
+         zfinal     = zsolcp_inv_f(jsclay) 
+         zinput     = rain_tot   (jsclay) + fromsed_tot(jsclay) 
+         zoutput    = tosed_tot  (jsclay) + rloss_tot  (jsclay) 
+         zdelta_clay= ( zfinal + zoutput ) - ( zinit + zinput )
+
+         ! mass balance for carbon ( carbon in POC, CaCo3, DIC )
+         zinit      = zsolcp_inv_i(jspoc) + zsolcp_inv_i(jscal) + zpwcp_inv_i(jwdic)
+         zfinal     = zsolcp_inv_f(jspoc) + zsolcp_inv_f(jscal) + zpwcp_inv_f(jwdic)
+         zinput     = rain_tot   (jspoc) + rain_tot   (jscal) + diss_in_tot(jwdic)
+         zoutput    = tosed_tot  (jspoc) + tosed_tot  (jscal) + diss_out_tot(jwdic) &
+            &       + rloss_tot  (jspoc) + rloss_tot  (jscal) 
+         zdelta_co2 = ( zfinal + zoutput ) - ( zinit + zinput )
+
+         ! mass balance for oxygen : O2 is in POC remineralization
+         zinit      = zpwcp_inv_i(jwoxy)
+         zfinal     = zpwcp_inv_f(jwoxy)
+         zinput     = diss_in_tot(jwoxy)
+         zoutput    = diss_out_tot(jwoxy) + cons_tot_o2
+         zdelta_oxy = ( zfinal + zoutput ) - ( zinit + zinput )
+
+         ! mass balance for phosphate ( PO4 in POC and dissolved phosphates )
+         zinit      = zsolcp_inv_i(jspoc) * spo4r + zpwcp_inv_i(jwpo4)
+         zfinal     = zsolcp_inv_f(jspoc) * spo4r + zpwcp_inv_f(jwpo4)
+         zinput     = rain_tot   (jspoc) * spo4r + diss_in_tot(jwpo4)
+         zoutput    = tosed_tot  (jspoc) * spo4r + diss_out_tot(jwpo4) &
+            &       + rloss_tot  (jspoc) * spo4r
+         zdelta_po4 = ( zfinal + zoutput ) - ( zinit + zinput )
+
+
+         ! mass balance for Nitrate
+         zinit      = zpwcp_inv_i  (jwno3)
+         zfinal     = zpwcp_inv_f  (jwno3)
+         zinput     = diss_in_tot (jwno3) + sour_tot_no3
+         zoutput    = diss_out_tot(jwno3) + cons_tot_no3
+         zdelta_no3 = ( zfinal + zoutput ) - ( zinit + zinput )
+
+         ! mass balance for DIC13
+         zinit      = src13p * zsolcp_inv_i(jspoc) + src13Ca * zsolcp_inv_i(jscal) &
+            &       + zpwcp_inv_i  (jwc13)
+         zfinal     = src13p * zsolcp_inv_f(jspoc) + src13Ca * zsolcp_inv_f(jscal) &
+            &       + zpwcp_inv_f  (jwc13)
+         zinput     = src13p * rain_tot   (jspoc) + src13Ca * rain_tot   (jscal) &
+            &       + diss_in_tot (jwc13) 
+         zoutput    = src13p * tosed_tot  (jspoc) + src13Ca * tosed_tot  (jscal) &
+            &       + diss_out_tot(jwc13) &
+            &       + src13p * rloss_tot  (jspoc) + src13Ca * rloss_tot  (jscal)
+         zdelta_c13 = ( zfinal + zoutput ) - ( zinit + zinput )
+
+         ! other mass balance for DIC13
+         zinit      = zpwcp_inv_i  (jwc13)
+         zfinal     = zpwcp_inv_f  (jwc13)
+         zinput     = diss_in_tot (jwc13) + sour_tot_c13
+         zoutput    = diss_out_tot(jwc13)
+         zdelta_c13b= ( zfinal + zoutput ) - ( zinit + zinput )    
+
+      END IF
+
+      IF( kt == nitsedend) THEN 
+
+         WRITE(numsed,*)
+         WRITE(numsed,*)'==================    General mass balance   ==================  '
+         WRITE(numsed,*)' '
+         WRITE(numsed,*)' '
+         WRITE(numsed,*)' Initial total solid Masses (mole/dx.dy) (k=2-11) '
+         WRITE(numsed,*)' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+         WRITE(numsed,*)'    Opale,      Clay,       POC,        CaCO3,         C13'
+         WRITE(numsed,'(4x,5(1PE10.3,2X))')zsolcp_inv_i(jsopal),zsolcp_inv_i(jsclay),zsolcp_inv_i(jspoc), &
+            & zsolcp_inv_i(jscal),( src13P * zsolcp_inv_i(jspoc) + src13Ca * zsolcp_inv_i(jscal) )
+         WRITE(numsed,*)' '
+         WRITE(numsed,*)' Initial total dissolved Masses (mole/dx.dy) (k=2-11) '
+         WRITE(numsed,*)' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+         WRITE(numsed,*)'    Si,         O2,         DIC,        Nit         Phos,       DIC13'
+         WRITE(numsed,'(4x,6(1PE10.3,2X))') zpwcp_inv_i(jwsil), zpwcp_inv_i(jwoxy), &
+            & zpwcp_inv_i(jwdic), zpwcp_inv_i(jwno3), zpwcp_inv_i(jwpo4), zpwcp_inv_i(jwc13)
+         WRITE(numsed,*)' '
+         WRITE(numsed,*)'  Solid inputs :  Opale,      Clay,       POC,        CaCO3,         C13'
+         WRITE(numsed,'(A4,10X,5(1PE10.3,2X))')'Rain : ',rain_tot(jsopal),rain_tot(jsclay),rain_tot(jspoc),&
+            & rain_tot(jscal),( src13P * rain_tot(jspoc) + src13Ca * rain_tot(jscal) )
+         WRITE(numsed,'(A12,6x,4(1PE10.3,2X))')' From Sed : ',fromsed_tot(jsopal), fromsed_tot(jsclay), &
+            & fromsed_tot(jspoc), fromsed_tot(jscal)
+         WRITE(numsed,*)'Diss. inputs : Si,    O2,         DIC,         Nit,       Phos,       DIC13'
+         WRITE(numsed,'(A9,1x,6(1PE10.3,2X))')' From Pisc : ', diss_in_tot(jwsil), &
+            & diss_in_tot(jwoxy), diss_in_tot(jwdic), diss_in_tot(jwno3), diss_in_tot(jwpo4), &
+            & diss_in_tot(jwc13)
+         WRITE(numsed,*)' '
+         WRITE(numsed,*)'Solid output : Opale,      Clay,       POC,        CaCO3,          C13'
+         WRITE(numsed,'(A6,8x,5(1PE10.3,2X))')'To sed', tosed_tot(jsopal),tosed_tot(jsclay),tosed_tot(jspoc),&
+            & tosed_tot(jscal),( src13P * tosed_tot(jspoc) + src13Ca * tosed_tot(jscal) )
+         WRITE(numsed,'(A5,9x,5(1PE10.3,2X))')'Perdu', rloss_tot(jsopal),rloss_tot(jsclay),rloss_tot(jspoc),&
+            & rloss_tot(jscal),( src13P * rloss_tot(jspoc) + src13Ca * rloss_tot(jscal) )
+         WRITE(numsed,*)'Diss. output : Si,     O2,        DIC,          Nit,       Phos,       DIC13 '  
+         WRITE(numsed,'(A7,2x,6(1PE10.3,2X))')'To kbot', diss_out_tot(jwsil), &
+            & diss_out_tot(jwoxy), diss_out_tot(jwdic), diss_out_tot(jwno3), diss_out_tot(jwpo4), &
+            & diss_out_tot(jwc13)
+         WRITE(numsed,*)' '
+         WRITE(numsed,*)' Total consomation in POC remineralization [mol]:  O2,         NO3'
+         WRITE(numsed,'(51x,2(1PE10.3,2X))') cons_tot_o2,cons_tot_no3
+         WRITE(numsed,*)' '
+         WRITE(numsed,*)'Final solid  Masses (mole/dx.dy) (k=2-11)'
+         WRITE(numsed,*)'    Opale,      Clay,       POC,        CaCO3,          C13'
+         WRITE(numsed,'(4x,5(1PE10.3,2X))')zsolcp_inv_f(jsopal),zsolcp_inv_f(jsclay),zsolcp_inv_f(jspoc), &
+            & zsolcp_inv_f(jscal),( src13P * zsolcp_inv_f(jspoc) + src13Ca * zsolcp_inv_f(jscal) )
+         WRITE(numsed,*)' '
+         WRITE(numsed,*)'Final dissolved  Masses (mole/dx.dy) (k=2-11)'
+         WRITE(numsed,*)'    Si,        O2,         DIC,        Nit,        Phos,    DIC13'
+         WRITE(numsed,'(4x,6(1PE10.3,2X))') zpwcp_inv_f(jwsil), zpwcp_inv_f(jwoxy), &
+            & zpwcp_inv_f(jwdic), zpwcp_inv_f(jwno3), zpwcp_inv_f(jwpo4), zpwcp_inv_f(jwc13)
+         WRITE(numsed,*)' '     
+         WRITE(numsed,*)'Delta : Opale,      Clay,       C,          O,          N,          P,        C13'
+         WRITE(numsed,'(7x,7(1PE11.3,1X))') zdelta_sil, zdelta_clay, zdelta_co2, zdelta_oxy, zdelta_no3,&
+            &                          zdelta_po4, zdelta_c13
+         WRITE(numsed,*)' ' 
+         WRITE(numsed,*)'deltaC13bis : ',zdelta_c13b     
+
+         WRITE(numsed,*)'=========================================================================='
+         WRITE(numsed,*)' Composition of final sediment for point jpoce'
+         WRITE(numsed,*)' ========================================='
+         WRITE(numsed,*)'Opale,      Clay,       POC,        CaCo3,      hipor,      pH,         co3por'
+         DO jk = 1,jpksed
+            WRITE(numsed,'(4(F8.4,4X),3(1PE10.3,2X))') solcp(jpoce,jk,jsopal)*100.,solcp(jpoce,jk,jsclay)*100.,&
+               &       solcp(jpoce,jk,jspoc)*100.,solcp(jpoce,jk,jscal)*100.,&
+               &       hipor(jpoce,jk),-LOG10(hipor(jpoce,jk)/densSW(jpoce)),co3por(jpoce,jk)
+         ENDDO
+         WRITE(numsed,*)'Silicic A.,  Oxygen,     DIC,        Nitrats,    Phosphats,  Alkal.,     DIC13'
+         DO jk = 1, jpksed
+            WRITE(numsed,'(8(1PE10.3,2X))')pwcp(jpoce,jk,jwsil),pwcp(jpoce,jk,jwoxy),&
+               & pwcp(jpoce,jk,jwdic),pwcp(jpoce,jk,jwno3),pwcp(jpoce,jk,jwpo4),pwcp(jpoce,jk,jwalk),pwcp(jpoce,jk,jwc13)
+         ENDDO
+         WRITE(numsed,*)'densSW at the end : ',densSW(jpoce)
+         WRITE(numsed,*)'=========================================================================='
+
+      ENDIF
+  
+   END SUBROUTINE sed_mbc
+
+
+#else
+   !!======================================================================
+   !! MODULE sedmbc :   Dummy module 
+   !!======================================================================
+CONTAINS
+   SUBROUTINE sed_mbc( kt )         ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'sed_mbc: You should not have seen this print! error?', kt
+   END SUBROUTINE sed_mbc
+
+   !!======================================================================
+
+#endif
+END MODULE sedmbc
+
+
+
+
+
Index: /trunk/NEMO/TOP_SRC/SED/sedmodel.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sedmodel.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sedmodel.F90	(revision 1179)
@@ -0,0 +1,70 @@
+MODULE sedmodel
+#if defined key_sed
+   !!======================================================================
+   !!                       ***  MODULE sedmodel   ***
+   !!   Sediment model : Main routine of sediment model 
+   !!======================================================================
+   USE sed
+   USE sedini   ! sediment variables initialization
+   USE sedstp   ! time stepping
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC sed_model  ! called by step.F90
+
+CONTAINS
+
+   SUBROUTINE sed_model ( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sed_model  ***
+      !!
+      !! ** Purpose :   main routine of sediment model
+      !!
+      !!
+      !! ** Method  : - model general initialization
+      !!              - launch the time-stepping (stp routine)
+      !!
+      !!   History :
+      !!        !  07-02 (C. Ethe)  Original
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt       ! number of iteration
+
+
+      !
+      !  Initialization of sediment model
+      ! -----------------------------------
+
+      IF( kt == nit000 ) CALL sed_init
+
+
+      !! Time stepping of Sediment model
+      !!-----------------------------------
+
+      CALL sed_stp( kt )
+
+
+   END SUBROUTINE sed_model
+
+#else
+   !!======================================================================
+   !! MODULE sedbtb  :   Dummy module 
+   !!======================================================================
+CONTAINS
+   SUBROUTINE sed_model( kt )         ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'sed_stp: You should not have seen this print! error?', kt
+   END SUBROUTINE sed_model
+
+   !!======================================================================
+#endif
+
+END MODULE sedmodel
+
+
+
+
+
+
+
Index: /trunk/NEMO/TOP_SRC/SED/sedrst.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sedrst.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sedrst.F90	(revision 1179)
@@ -0,0 +1,266 @@
+MODULE sedrst
+#if defined key_sed
+   !!======================================================================
+   !!                       *** MODULE sedrst ***
+   !!   Read and write the restart files for sediment
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   !! ==============
+   USE sed
+   USE sedarr
+
+
+   !! * Accessibility
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC sed_rst_read
+   PUBLIC sed_rst_write
+
+   !! * Module variables
+   INTEGER, PUBLIC ::   numrsr, numrsw   !: logical unit for sed restart (read and write)
+   
+   
+CONTAINS
+
+
+   SUBROUTINE sed_rst_read 
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_rst_read  ***
+      !!
+      !! ** Purpose :  Initialization of sediment module
+      !!               - sets initial sediment composition
+      !!                 ( only clay or reading restart file )
+      !!
+      !!   History :
+      !!        !  06-07  (C. Ethe)  original
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE iom
+
+      !! * local declarations
+      INTEGER :: &
+         ji, jk, jn
+      REAL(wp), DIMENSION(jpi,jpj,jpksed,jptrased) :: &
+         zdta
+
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: &
+         zhipor
+
+      REAL(wp) :: zkt
+      CHARACTER(len = 20)  ::  cltra
+      !--------------------------------------------------------------------
+ 
+
+      WRITE(numsed,*) ' '      
+      WRITE(numsed,*) ' Initilization of Sediment components from restart'
+      WRITE(numsed,*) ' '
+
+      ALLOCATE( zhipor(jpoce,jpksed) ) 
+
+      CALL iom_open( 'restart_sed', numrsr, kiolib = jprstlib )     
+      CALL iom_get( numrsr, 'kt'     , zkt      )   ! time-step
+ 
+      DO jn = 1, jptrased - 1
+         cltra = sedtrc3d(jn)
+         CALL iom_get( numrsr, jpdom_unknown, cltra, zdta(:,:,:,jn), &
+            &          kstart=(/1,1,1/), kcount=(/jpi,jpj,jpksed/) )
+      ENDDO
+        
+
+      CALL pack_arr( jpoce, solcp(1:jpoce,1:jpksed,jsopal), &
+         &            zdta(1:jpi,1:jpj,1:jpksed,1), iarroce(1:jpoce) )
+
+      CALL pack_arr( jpoce, solcp(1:jpoce,1:jpksed,jsclay), &
+         &             zdta(1:jpi,1:jpj,1:jpksed,2), iarroce(1:jpoce) )
+
+      CALL pack_arr( jpoce, solcp(1:jpoce,1:jpksed,jspoc), &
+         &             zdta(1:jpi,1:jpj,1:jpksed,3), iarroce(1:jpoce) )
+
+      CALL pack_arr( jpoce, solcp(1:jpoce,1:jpksed,jscal), &
+         &             zdta(1:jpi,1:jpj,1:jpksed,4), iarroce(1:jpoce) )
+
+      CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwsil), &
+         &             zdta(1:jpi,1:jpj,1:jpksed,5), iarroce(1:jpoce) )
+
+
+      CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwoxy), &
+         &             zdta(1:jpi,1:jpj,1:jpksed,6), iarroce(1:jpoce) )
+
+
+      CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwdic), &
+         &             zdta(1:jpi,1:jpj,1:jpksed,7), iarroce(1:jpoce) )
+
+      CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwno3), &
+         &             zdta(1:jpi,1:jpj,1:jpksed,8), iarroce(1:jpoce) )
+
+      CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwpo4), &
+         &             zdta(1:jpi,1:jpj,1:jpksed,9), iarroce(1:jpoce) )
+
+      CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwalk), &
+         &             zdta(1:jpi,1:jpj,1:jpksed,10), iarroce(1:jpoce) )
+
+      CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwc13), &
+         &             zdta(1:jpi,1:jpj,1:jpksed,11), iarroce(1:jpoce) )
+
+      zhipor(:,:) = 0.
+      CALL pack_arr( jpoce, zhipor(1:jpoce,1:jpksed), &
+         &             zdta(1:jpi,1:jpj,1:jpksed,12), iarroce(1:jpoce) )
+
+      ! Initialization of [h+] in mol/kg
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            hipor (ji,jk) = 10.**( -1. * zhipor(ji,jk) )
+         ENDDO
+      ENDDO
+      
+      CALL pack_arr( jpoce, co3por(1:jpoce,1:jpksed), &
+         &             zdta(1:jpi,1:jpj,1:jpksed,13), iarroce(1:jpoce) )
+
+      ! Initialization of sediment composant only ie jk=2 to jk=jpksed 
+      ! ( nothing in jk=1)
+      solcp(1:jpoce,1,:) = 0.
+      pwcp (1:jpoce,1,:) = 0.
+
+      DEALLOCATE( zhipor )
+     
+   END SUBROUTINE sed_rst_read
+
+
+   SUBROUTINE sed_rst_write( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_rst_write  ***
+      !!
+      !! ** Purpose :  save field which are necessary for sediment restart
+      !!
+      !!   History :
+      !!        !  06-07  (C. Ethe)  original
+      !!----------------------------------------------------------------------
+      !!* Modules used
+      USE ioipsl
+      !! *Arguments
+      INTEGER, INTENT(in) ::   kt       ! number of iteration
+      !! * local declarations
+
+      CHARACTER (len=50) :: clname,cln
+
+      INTEGER ::  &
+         ic,jc,jn,      &
+         itime
+
+     REAL(wp) ::  &
+         zdate0
+
+     REAL(wp), DIMENSION(1) :: &
+        zinfo
+
+      CHARACTER(len = 20)  ::  cltra 
+
+      INTEGER   :: ji, jk
+      REAL(wp), DIMENSION(:,:) , ALLOCATABLE  :: zdta   
+      !! -----------------------------------------------------------------------
+
+      ALLOCATE( zdta(jpoce,jpksed) )
+
+      IF( MOD(kt,nstock) == 0 .OR. kt == nitsedend ) THEN
+         
+         !! 0. initialisations
+         !! ------------------
+         
+         IF(lwp) WRITE(numsed,*) ' '
+         IF(lwp) WRITE(numsed,*) 'sed_rst_write : write the sediment restart file in NetCDF format ',   &
+            'at it= ',kt
+         IF(lwp) WRITE(numsed,*) '~~~~~~~~~'
+         
+         !! 1. WRITE in nutwrs
+         !! ------------------
+
+         ic = 1
+         DO jc = 1,16
+            IF( cexper(jc:jc) /= ' ') ic = jc
+         END DO
+         WRITE( cln,'("_",i4.4,i2.2,i2.2,"_restart.sed")') nyear, nmonth, nday
+         clname = cexper(1:ic)//cln
+         itime = 0
+         CALL ymds2ju( nyear, nmonth, nday, 0.0, zdate0 )
+         CALL restini( 'NONE', jpi, jpj, glamt, gphit, jpksed, dz, &
+            &         clname, itime, zdate0, dtsed*nstock, numrsw, domain_id=nidom )
+         zinfo(1) = REAL( kt)
+         CALL restput( numrsw, 'kt', 1,1, 1,0, zinfo  )
+
+
+
+         ! Back to 2D geometry
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,1) , iarroce(1:jpoce), &
+            &                    solcp(1:jpoce,1:jpksed,jsopal ) )
+         
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,2) , iarroce(1:jpoce), &
+            &                    solcp(1:jpoce,1:jpksed,jsclay ) )
+         
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,3) , iarroce(1:jpoce), &
+            &                    solcp(1:jpoce,1:jpksed,jspoc  ) )
+         
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,4) , iarroce(1:jpoce), &
+            &                    solcp(1:jpoce,1:jpksed,jscal  ) )   
+         
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,5) , iarroce(1:jpoce), &
+            &                    pwcp(1:jpoce,1:jpksed,jwsil  )  )
+         
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,6)  , iarroce(1:jpoce), &
+            &                    pwcp(1:jpoce,1:jpksed,jwoxy  ) )
+         
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,7)  , iarroce(1:jpoce), &
+            &                    pwcp(1:jpoce,1:jpksed,jwdic  ) )
+         
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,8)  , iarroce(1:jpoce), &
+            &                    pwcp(1:jpoce,1:jpksed,jwno3  ) )
+         
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,9)  , iarroce(1:jpoce), &
+            &                    pwcp(1:jpoce,1:jpksed,jwpo4  ) )
+         
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,10)  , iarroce(1:jpoce), &
+            &                    pwcp(1:jpoce,1:jpksed,jwalk  ) )
+         
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,11)  , iarroce(1:jpoce), &
+         &                    pwcp(1:jpoce,1:jpksed,jwc13  ) )
+         
+         ! porosity
+         zdta(:,:) = 0.
+         DO jk = 1, jpksed
+            DO ji = 1, jpoce
+               zdta(ji,jk) = -LOG10( hipor(ji,jk) / densSW(ji) )
+            ENDDO
+         ENDDO
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,12)  , iarroce(1:jpoce), &
+            &                   zdta(1:jpoce,1:jpksed)  )
+         
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,13)  , iarroce(1:jpoce), &
+            &                   co3por(1:jpoce,1:jpksed)  )
+      
+         ! prognostic variables
+         ! --------------------
+
+
+         DO jn = 1, jptrased - 1
+            cltra = sedtrc3d(jn)
+            CALL restput( numrsw, cltra, jpi, jpj, jpksed, 0, trcsedi(:,:,:,jn) )
+         ENDDO
+
+         CALL restclo( numrsw )
+
+      ENDIF
+
+      DEALLOCATE( zdta )  
+         
+   END SUBROUTINE sed_rst_write
+#else
+   !!======================================================================
+   !! MODULE sedrst :   Dummy module 
+   !!======================================================================
+
+#endif
+
+END MODULE sedrst
Index: /trunk/NEMO/TOP_SRC/SED/sedsfc.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sedsfc.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sedsfc.F90	(revision 1179)
@@ -0,0 +1,78 @@
+MODULE sedsfc
+   !!======================================================================
+   !!              ***  MODULE  sedsfc  ***
+   !!    Sediment : Data at sediment surface
+   !!=====================================================================
+#if defined key_sed && ! defined key_sed_off
+   !! * Modules used
+   USE sed     ! sediment global variable
+   USE sedarr
+   USE seddta
+
+   PUBLIC sed_sfc
+
+CONTAINS
+
+   SUBROUTINE sed_sfc( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sed_sfc ***
+      !!
+      !! ** Purpose :  Give data from sediment model to tracer model
+      !!
+      !!
+      !!   History :
+      !!        !  06-04 (C. Ethe)  Orginal code
+      !!----------------------------------------------------------------------
+      !!* Arguments
+      INTEGER, INTENT(in) ::  &
+         kt              ! time step
+
+      ! * local variables
+      INTEGER :: &
+         ji, jj, ikt     ! dummy loop indices
+
+
+      !------------------------------------------------------------------------
+
+      IF( kt == nitsed000 ) THEN
+         WRITE(numsed,*) ' sed_sfc : Give data from sediment model to tracer model  '
+         WRITE(numsed,*) ' '
+      ENDIF
+
+      ! reading variables
+
+      CALL unpack_arr ( jpoce, trc_data(1:jpi,1:jpj,1), iarroce(1:jpoce), pwcp(1:jpoce,1,jwalk) )
+      CALL unpack_arr ( jpoce, trc_data(1:jpi,1:jpj,2), iarroce(1:jpoce), pwcp(1:jpoce,1,jwdic) )
+      CALL unpack_arr ( jpoce, trc_data(1:jpi,1:jpj,3), iarroce(1:jpoce), pwcp(1:jpoce,1,jwno3) )
+      CALL unpack_arr ( jpoce, trc_data(1:jpi,1:jpj,4), iarroce(1:jpoce), pwcp(1:jpoce,1,jwpo4) )
+      CALL unpack_arr ( jpoce, trc_data(1:jpi,1:jpj,5), iarroce(1:jpoce), pwcp(1:jpoce,1,jwoxy) )
+      CALL unpack_arr ( jpoce, trc_data(1:jpi,1:jpj,6), iarroce(1:jpoce), pwcp(1:jpoce,1,jwsil) )
+
+
+      DO jj = 1,jpj
+         DO ji = 1, jpi
+            ikt = MAX( mbathy(ji,jj)-1, 1 )
+            IF ( tmask(ji,jj,ikt) == 1 ) THEN
+               trn(ji,jj,ikt,jptal) = trc_data(ji,jj,1)
+               trn(ji,jj,ikt,jpdic) = trc_data(ji,jj,2)
+               trn(ji,jj,ikt,jpno3) = trc_data(ji,jj,3) * 7.6
+               trn(ji,jj,ikt,jppo4) = trc_data(ji,jj,4) * 122.
+               trn(ji,jj,ikt,jpoxy) = trc_data(ji,jj,5)
+               trn(ji,jj,ikt,jpsil) = trc_data(ji,jj,6)
+            ENDIF
+         ENDDO
+      ENDDO
+
+   END SUBROUTINE sed_sfc
+
+#else
+   !!======================================================================
+   !! MODULE sedsfc  :   Dummy module 
+   !!======================================================================
+CONTAINS
+   SUBROUTINE sed_sfc ( kt )
+      INTEGER, INTENT(in) :: kt
+   END SUBROUTINE sed_sfc
+#endif
+
+END MODULE sedsfc
Index: /trunk/NEMO/TOP_SRC/SED/sedstp.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sedstp.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sedstp.F90	(revision 1179)
@@ -0,0 +1,87 @@
+MODULE sedstp
+#if defined key_sed
+   !!======================================================================
+   !!                       ***  MODULE sedstp   ***
+   !!   Sediment model : Sediment model time-stepping
+   !!======================================================================
+   USE sed      ! sediment global variables
+   USE seddta   ! data read
+   USE sedchem  ! chemical constant
+   USE sedco3   ! carbonate in sediment pore water
+   USE seddsr   ! dissolution reaction
+   USE sedbtb   ! bioturbation
+   USE sedadv   ! vertical advection
+   USE sedmbc   ! mass balance calculation
+   USE sedsfc   ! sediment surface data
+   USE sedrst   ! restart
+   USE sedwri   ! outputs
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC sed_stp  ! called by step.F90
+
+CONTAINS
+
+   SUBROUTINE sed_stp ( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sed_stp  ***
+      !!
+      !! ** Purpose :   Sediment time stepping
+      !!                Simulation of pore water chemistry
+      !!
+      !! ** Action  :
+      !!
+      !!
+      !!   History :
+      !!        !  98-08 (E. Maier-Reimer, Christoph Heinze )  Original code
+      !!        !  04-10 (N. Emprin, M. Gehlen ) coupled with PISCES
+      !!        !  06-04 (C. Ethe)  Re-organization
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt       ! number of iteration
+
+      !!----------------------------------------------------------------------
+
+      IF( kt /= nitsed000 )  THEN
+        CALL sed_dta( kt )       ! Load  Data for bot. wat. Chem and fluxes
+        CALL sed_chem( kt )      ! update of chemical constant to account for salinity, temperature changes
+      ENDIF
+      CALL sed_dsr( kt )         ! Dissolution reaction
+      CALL sed_adv( kt )         ! advection
+      CALL sed_btb( kt )         ! Bioturbation
+
+      IF ( ( MOD( kt, nwrised ) == 0 ) .OR. ( MOD( kt, nstock ) == 0 ) .OR. ( kt == nitsedend )  )   &
+      CALL sed_co3( kt )      ! pH actualization for saving
+      CALL sed_mbc( kt )         ! cumulation for mass balance calculation
+#if ! defined key_sed_off
+      CALL sed_sfc( kt )         ! Give back new bottom wat chem to tracer model
+#endif
+      CALL sed_rst_write( kt )   ! restart file output
+      CALL sed_wri( kt )         ! outputs
+
+      IF( kt == nitsedend )  CLOSE( numsed )
+
+   END SUBROUTINE sed_stp
+
+#else
+   !!======================================================================
+   !! MODULE sedstp  :   Dummy module 
+   !!======================================================================
+CONTAINS
+   SUBROUTINE sed_stp( kt )         ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'sed_stp: You should not have seen this print! error?', kt
+   END SUBROUTINE sed_stp
+
+   !!======================================================================
+#endif
+
+END MODULE sedstp
+
+
+
+
+
+
+
Index: /trunk/NEMO/TOP_SRC/SED/sedwri.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/SED/sedwri.F90	(revision 1179)
+++ /trunk/NEMO/TOP_SRC/SED/sedwri.F90	(revision 1179)
@@ -0,0 +1,260 @@
+MODULE sedwri
+#if defined key_sed
+   !!======================================================================
+   !!                     ***  MODULE  sedwri  ***
+   !!         Sediment diagnostics :  write sediment output files
+   !!======================================================================
+   USE sed
+   USE sedarr
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC sed_wri 
+
+CONTAINS
+
+   !!----------------------------------------------------------------------
+   !!                                                   NetCDF output file
+   !!----------------------------------------------------------------------
+   SUBROUTINE sed_wri( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_wri  ***
+      !!
+      !! ** Purpose :  output of sediment passive tracer
+      !!
+      !!   History :
+      !!        !  06-07  (C. Ethe)  original
+      !!----------------------------------------------------------------------
+      !! * Local variables
+      USE ioipsl
+      USE dianam    ! build name of file (routine)
+
+      INTEGER, INTENT(in) :: kt
+
+      CHARACTER(len = 60)  ::  clhstnam, clop
+      INTEGER , SAVE :: nised, nhorised, ndimt52, ndimt51, ndepsed
+      REAL(wp), SAVE :: zjulian
+      INTEGER , DIMENSION(jpij*jpksed) , SAVE :: ndext52  
+      INTEGER , DIMENSION(jpij) , SAVE :: ndext51
+      REAL(wp) :: zsto,zout, zdt
+      INTEGER :: iimi, iima, ijmi, ijma,ipk, it
+      INTEGER :: jn
+      CHARACTER(len = 20)  ::  cltra , cltrau
+      CHARACTER(len = 80)  ::  cltral
+
+      INTEGER   :: ji, jk, js, jw
+      REAL(wp)  :: zrate
+      REAL(wp), DIMENSION(:,:) , ALLOCATABLE  :: zdta, zflx
+
+      !!-------------------------------------------------------------------
+
+
+      ! Initialisation
+      ! ----------------- 
+
+
+      ! Define frequency of output and means
+      zdt = dtsed
+#if defined key_diainstant
+      zsto = nwrised * zdt
+!!      clop = "inst(x)"           ! no use of the mask value (require less cpu time)
+      clop="inst(only(x))"   ! put 1.e+20 on land (very expensive!!)
+#else
+      zsto = zdt
+!!      clop = "ave(x)"              ! no use of the mask value (require less cpu time)
+      clop="ave(only(x))"    ! put 1.e+20 on land (very expensive!!)
+#endif
+      zout = nwrised * zdt
+
+      ! Define indices of the horizontal output zoom and vertical limit storage
+      iimi = 1      ;      iima = jpi
+      ijmi = 1      ;      ijma = jpj
+      ipk = jpksed
+
+      ! define time axis
+      it = kt - nitsed000 + 1
+
+
+      ! 1.  Initilisations
+      ! -----------------------------------------------------------------
+      WRITE(numsed,*) ' '
+      WRITE(numsed,*) 'sed_wri kt = ', kt
+      WRITE(numsed,*) ' '
+      
+      ALLOCATE( zdta(jpoce,jpksed) )    ;   ALLOCATE( zflx(jpoce,jpwatp1) )
+
+
+      ! 2.  Back to 2D geometry
+      ! -----------------------------------------------------------------
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,1) , iarroce(1:jpoce), &
+         &                    solcp(1:jpoce,1:jpksed,jsopal ) )
+      
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,2) , iarroce(1:jpoce), &
+         &                    solcp(1:jpoce,1:jpksed,jsclay ) )
+      
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,3) , iarroce(1:jpoce), &
+         &                    solcp(1:jpoce,1:jpksed,jspoc  ) )
+      
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,4) , iarroce(1:jpoce), &
+         &                    solcp(1:jpoce,1:jpksed,jscal  ) )   
+            
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,5) , iarroce(1:jpoce), &
+         &                    pwcp(1:jpoce,1:jpksed,jwsil  )  )
+      
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,6)  , iarroce(1:jpoce), &
+         &                    pwcp(1:jpoce,1:jpksed,jwoxy  ) )
+      
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,7)  , iarroce(1:jpoce), &
+         &                    pwcp(1:jpoce,1:jpksed,jwdic  ) )
+      
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,8)  , iarroce(1:jpoce), &
+         &                    pwcp(1:jpoce,1:jpksed,jwno3  ) )
+      
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,9)  , iarroce(1:jpoce), &
+         &                    pwcp(1:jpoce,1:jpksed,jwpo4  ) )
+      
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,10)  , iarroce(1:jpoce), &
+         &                    pwcp(1:jpoce,1:jpksed,jwalk  ) )
+      
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,11)  , iarroce(1:jpoce), &
+         &                    pwcp(1:jpoce,1:jpksed,jwc13  ) )
+      
+      ! porosity
+      zdta(:,:) = 0.
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zdta(ji,jk) = -LOG10( hipor(ji,jk) / densSW(ji) )
+         ENDDO
+      ENDDO
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,12)  , iarroce(1:jpoce), &
+         &                   zdta(1:jpoce,1:jpksed)  )
+      
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,13)  , iarroce(1:jpoce), &
+         &                   co3por(1:jpoce,1:jpksed)  )
+      
+      
+      ! computation of delta 13C
+      zdta(:,:) = 0.
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zdta(ji,jk) = ( ( pwcp(ji,jk,jwc13) / pwcp(ji,jk,jwdic) / pdb ) - 1. ) &
+               &              * 1000.
+         ENDDO
+      ENDDO
+      CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,14)  , iarroce(1:jpoce), &
+         &                   zdta(1:jpoce,1:jpksed)  )
+      
+ 
+      zflx(:,:) = 0.    
+      ! Calculation of fluxes mol/cm2/s
+      DO jw = 1, jpwat
+         DO ji = 1, jpoce
+            zflx(ji,jw) = ( pwcp(ji,1,jw) - pwcp_dta(ji,jw) ) &
+               &         * 1.e-3 * dzkbot(ji) / dtsed
+         ENDDO
+      ENDDO
+      ! Calculation of accumulation rate per dt
+      DO js = 1, jpsol
+         zrate =  mol_wgt(js) / ( dens * por1(jpksed) ) / dtsed
+         DO ji = 1, jpoce
+            zflx(ji,jpwatp1) = zflx(ji,jpwatp1) + ( tosed(ji,js) - fromsed(ji,js) ) * zrate
+         ENDDO
+      ENDDO
+
+      CALL unpack_arr( jpoce, flxsedi(1:jpi,1:jpj,1), iarroce(1:jpoce), zflx(1:jpoce,1)  )
+      CALL unpack_arr( jpoce, flxsedi(1:jpi,1:jpj,2), iarroce(1:jpoce), zflx(1:jpoce,2)  )
+      CALL unpack_arr( jpoce, flxsedi(1:jpi,1:jpj,3), iarroce(1:jpoce), zflx(1:jpoce,3)  )
+      CALL unpack_arr( jpoce, flxsedi(1:jpi,1:jpj,4), iarroce(1:jpoce), zflx(1:jpoce,4)  )
+      CALL unpack_arr( jpoce, flxsedi(1:jpi,1:jpj,5), iarroce(1:jpoce), zflx(1:jpoce,5)  )
+      CALL unpack_arr( jpoce, flxsedi(1:jpi,1:jpj,6), iarroce(1:jpoce), zflx(1:jpoce,6)  )
+      CALL unpack_arr( jpoce, flxsedi(1:jpi,1:jpj,7), iarroce(1:jpoce), zflx(1:jpoce,8)  )
+
+
+      ! 3. Define NETCDF files and fields at beginning of first time step
+      ! -----------------------------------------------------------------
+
+      IF( kt == nitsed000 ) THEN
+
+         ! Define the NETCDF files        
+         CALL ymds2ju ( nyear, nmonth, nday, 0.0, zjulian )
+         CALL dia_nam ( clhstnam, nwrised, 'sed_T' )
+         CALL histbeg ( clhstnam, jpi, glamt, jpj, gphit,     &
+            &             iimi, iima-iimi+1, ijmi, ijma-ijmi+1,         &
+            &             0, zjulian, zdt,  nhorised, nised , domain_id=nidom )
+         CALL histvert( nised,'deptht','Vertic.sed.T levels','m',ipk, profsed, ndepsed )
+         CALL wheneq  ( jpi*jpj*ipk, tmasksed, 1, 1., ndext52, ndimt52 )
+         CALL wheneq  ( jpi*jpj, tmasksed(:,:,1), 1, 1., ndext51, ndimt51 )
+
+         ! Declare all the output fields as NETCDF variables
+
+         DO jn = 1, jptrased
+            cltra  = sedtrc3d(jn)   ! short title for 3D diagnostic
+            cltral = sedtrc3l(jn)   ! long title for 3D diagnostic
+            cltrau = sedtrc3u(jn)   ! UNIT for 3D diagnostic
+
+            CALL histdef( nised, cltra,cltral,cltrau, jpi, jpj, nhorised, &
+               &          ipk, 1, ipk, ndepsed, 32, clop, zsto, zout )
+         ENDDO
+
+         !Fluxes
+         DO jn = 1, jpflxsed
+            cltra  = sedtrc2d(jn)   ! short title for 3D diagnostic
+            cltral = sedtrc2l(jn)   ! long title for 3D diagnostic
+            cltrau = sedtrc2u(jn)   ! UNIT for 3D diagnostic
+            
+            CALL histdef( nised, cltra,cltral,cltrau, jpi, jpj, nhorised, &
+               &          1, 1, 1, -99, 32, clop, zsto, zout )
+         ENDDO
+
+
+         CALL histend( nised )
+
+         WRITE(numsed,*)
+         WRITE(numsed,*) 'End of NetCDF sediment output file Initialization'
+
+      ELSE
+
+
+         ! Start writing data
+         ! ---------------------
+          DO jn = 1, jptrased
+             cltra = sedtrc3d(jn) ! short title for 3D diagnostic
+             CALL histwrite( nised, cltra, it, trcsedi(:,:,:,jn), ndimt52, ndext52 )
+          END DO
+
+          DO jn = 1, jpflxsed
+             cltra = sedtrc2d(jn) ! short title for 2D diagnostic
+             CALL histwrite( nised, cltra, it, flxsedi(:,:,jn  ), ndimt51, ndext51 )
+          END DO
+
+
+         !!
+         !! synchronise FILE
+         !
+         IF( MOD( kt, nwrised ) == 0 ) THEN
+              WRITE(numsed,*)  '**** sedwri : write NetCDF aditional arrays'
+              CALL histsync( nised )
+          ENDIF
+
+      ENDIF
+
+! 3. Closing all files
+! --------------------
+      IF( kt == nitsedend  ) THEN
+          CALL histclo( nised )
+      ENDIF
+
+      DEALLOCATE( zdta )    ;   DEALLOCATE( zflx )
+
+   END SUBROUTINE sed_wri
+
+#else
+   !!======================================================================
+   !! MODULE sedwri :   Dummy module 
+   !!======================================================================
+
+#endif
+
+END MODULE sedwri
