Index: NEMO/branches/UKMO/dev_r9950_GO8_package/src/TOP/PISCES/SED/sedadv.F90
===================================================================
--- NEMO/branches/UKMO/dev_r9950_GO8_package/src/TOP/PISCES/SED/sedadv.F90	(revision 9952)
+++ NEMO/branches/UKMO/dev_r9950_GO8_package/src/TOP/PISCES/SED/sedadv.F90	(revision 10322)
@@ -4,19 +4,19 @@
    !!    Sediment : vertical advection and burial
    !!=====================================================================
-#if defined key_sed
-   !!----------------------------------------------------------------------
-   !!   'key_sed'                                                  Sediment 
+   !! * Modules used
    !!----------------------------------------------------------------------
    !!   sed_adv :
    !!----------------------------------------------------------------------
    USE sed     ! sediment global variable
+   USE lib_mpp         ! distribued memory computing library
+
+   IMPLICIT NONE
+   PRIVATE
 
    PUBLIC sed_adv
-
-   !! * Module variable
-   INTEGER, PARAMETER  ::  nztime = jpksed         ! number of time step between sunrise and sunset
-
-   REAL(wp), DIMENSION(jpksed), SAVE :: dvolsp, dvolsm
-   REAL(wp), DIMENSION(jpksed), SAVE :: c2por, ckpor
+   PUBLIC sed_adv_alloc
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) :: dvolsp, dvolsm
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) :: c2por, ckpor
 
    REAL(wp) :: cpor
@@ -49,22 +49,26 @@
       ! * local variables
       INTEGER :: ji, jk, js 
-      INTEGER :: jn, ntimes, ikwneg
+      INTEGER :: jn, ntimes, nztime, ikwneg
       
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: zsolcpno
-      REAL(wp), DIMENSION(:  ), ALLOCATABLE :: zfilled, zfull, zfromup, zempty
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: zgap, zwb
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: zrainrf
-      REAL(wp), DIMENSION(nztime) ::  zraipush
-
-      REAL(wp) :: zkwnup, zkwnlo, zfrac,  zfromce, zrest
+      REAL(wp), DIMENSION(jpksed,jpsol) :: zsolcpno
+      REAL(wp), DIMENSION(jpksed)       :: zfilled, zfull, zfromup, zempty
+      REAL(wp), DIMENSION(jpoce,jpksed) :: zgap, zwb
+      REAL(wp), DIMENSION(jpoce,jpsol) :: zrainrf
+      REAL(wp), DIMENSION(:  ), ALLOCATABLE :: zraipush
+
+      REAL(wp) :: zkwnup, zkwnlo, zfrac,  zfromce, zrest, sumtot, zsumtot1
 
       !------------------------------------------------------------------------
 
 
+      IF( ln_timing )  CALL timing_start('sed_adv')
+!
       IF( kt == nitsed000 ) THEN
-         WRITE(numsed,*) ' '
-         WRITE(numsed,*) ' sed_adv : vertical sediment advection  '
-         WRITE(numsed,*) ' '
-         por1clay = dens * por1(jpksed) * dz(jpksed) / mol_wgt(jsclay)
+         IF (lwp) THEN
+            WRITE(numsed,*) ' '
+            WRITE(numsed,*) ' sed_adv : vertical sediment advection  '
+            WRITE(numsed,*) ' '
+         ENDIF
+         por1clay = denssol * por1(jpksed) * dz(jpksed)
          cpor     = por1(jpksed) / por1(2)
          DO jk = 2, jpksed
@@ -80,8 +84,4 @@
       ENDIF
 
-      ALLOCATE( zsolcpno(jpksed,jpsol), zrainrf(jpoce,jpsol) )
-      ALLOCATE( zfilled(jpksed), zfull(jpksed), zfromup(jpksed), zempty(jpksed) )
-      ALLOCATE( zgap (jpoce,jpksed)   , zwb(jpoce,jpksed)  )  
-
       ! Initialization of data for mass balance calculation
       !---------------------------------------------------
@@ -89,5 +89,8 @@
       tosed  (:,:) = 0. 
       rloss  (:,:) = 0.
-
+      ikwneg = 1
+      nztime = jpksed
+
+      ALLOCATE( zraipush(nztime) )
 
       ! Initiate gap 
@@ -104,10 +107,9 @@
       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) )     
+         zfrac =  dtsed / ( denssol * por1(jk) )     
          DO ji = 1, jpoce
             zwb(ji,jk) = zfrac * raintg(ji)
@@ -127,5 +129,4 @@
       ENDDO
 
-
       zrainrf(:,:) = 0.
       DO ji = 1, jpoce
@@ -206,14 +207,11 @@
                   ! quantities to push in deeper sediment
                   tosed  (ji,js) = zsolcpno(jpksed,js) &
-                     &           * zwb(ji,jpksed) * dens * por1(jpksed) / mol_wgt(js)
-               ENDDO
-               
+                     &           * zwb(ji,jpksed) * denssol * por1(jpksed)
+               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
+               IF( ntimes > nztime ) CALL ctl_stop( 'STOP', 'sed_adv : rest too large ' )
                zraipush(1) = dz(2)
                zrest = zrest - zraipush(1)
@@ -249,5 +247,5 @@
                      fromsed(ji,js) = 0.
                      tosed  (ji,js) = tosed(ji,js) + zsolcpno(jpksed,js) * zraipush(jn) &
-                        &             * dens * por1(2) / mol_wgt(js)
+                        &             * denssol * por1(2) 
                   ENDDO
                ENDDO
@@ -279,7 +277,5 @@
             ! 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
 
@@ -323,5 +319,5 @@
                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)
+               !! C. Heinze  fromsed(ji,jsclay) = zempty(jpksed) * 1. * denssol * por1(jpksed) / mol_wgt(jsclay)
                fromsed(ji,jsclay) = zempty(jpksed) * 1. * por1clay
                
@@ -339,5 +335,5 @@
                   solcp(ji,2,js) = zfull(2) * zsolcpno(2,js) + zempty(2) * zrainrf(ji,js)
                ENDDO
-               DO  js = 1, jpsol              
+               DO  js = 1, jpsol
                   DO jk = jpksedm1, 3, -1
                      solcp(ji,jk,js) = zfull(jk) * zsolcpno(jk,js) + zempty(jk) * zsolcpno(jk-1,js)
@@ -349,5 +345,5 @@
                ENDDO
                solcp(ji,jpksed,jsclay) = solcp(ji,jpksed,jsclay) + zkwnlo * 1.
-               ! Heinze  fromsed(ji,jsclay) = zkwnlo * 1. * dens * por1(jpksed) / mol_wgt(jsclay)
+               ! Heinze  fromsed(ji,jsclay) = zkwnlo * 1. * denssol * por1(jpksed) / mol_wgt(jsclay)
                fromsed(ji,jsclay) = zkwnlo * 1.* por1clay
             ELSE   ! 2 < ikwneg(ji) <= jpksedm1
@@ -415,6 +411,7 @@
                   fromsed(ji,js)   = 0.
                ENDDO
-               ! Heinze  fromsed(ji,jsclay) = zempty * 1. * dens * por1(jpksed) / mol_wgt(jsclay)
+               ! Heinze  fromsed(ji,jsclay) = zempty * 1. * denssol * por1(jpksed) / mol_wgt(jsclay)
                fromsed(ji,jsclay) = zempty(jpksed) * 1. * por1clay
+
             ENDIF ! ikwneg(ji) = 2
          ENDIF  ! zwb > 0
@@ -425,28 +422,21 @@
       raintg(:)   = 0.
 
-      DEALLOCATE( zsolcpno )   
-      DEALLOCATE( zrainrf  )
-      DEALLOCATE( zfilled  )
-      DEALLOCATE( zfull    )
-      DEALLOCATE( zfromup  )
-      DEALLOCATE( zempty   )
-      DEALLOCATE( zgap     )  
-      DEALLOCATE( zwb      )
-
+      DEALLOCATE( zraipush )
+
+      IF( ln_timing )  CALL timing_stop('sed_adv')
 
    END SUBROUTINE sed_adv
-#else
-   !!======================================================================
-   !! MODULE sedbtb  :   Dummy module 
-   !!======================================================================
-   !! $Id$
-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
+
+
+   INTEGER FUNCTION sed_adv_alloc()
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_prod_alloc  ***
+      !!----------------------------------------------------------------------
+      ALLOCATE( dvolsp(jpksed), dvolsm(jpksed), c2por(jpksed),         &
+      &         ckpor(jpksed) ,           STAT = sed_adv_alloc )
+      !
+      IF( sed_adv_alloc /= 0 ) CALL ctl_warn('sed_adv_alloc : failed to allocate arrays.')
+      !
+   END FUNCTION sed_adv_alloc
+
 END MODULE sedadv
