Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/INSTALL.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/INSTALL.rst	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/INSTALL.rst	(revision 10345)
@@ -1,38 +1,64 @@
-Install the modelling framework (NEMO and XIOS)
+*********************
+Install the framework
+*********************
 
-Last edition: 2018-02-14 21:32 CET by nicolasmartin
+.. contents::
+	:local:
+      
+Dependencies
+============
 
-    Extract the NEMO code
-        Description of NEMOGCM directory tree
-    Extract and install XIOS
-    Setup your architecture configuration file
-    Compile and create NEMO executable
-        More options
-        Default behaviour
-        Tools used during the process
-        Examples
-    Running the model
-    Viewing and changing list of active CPP keys
+| The NEMO source code is written in Fortran 95 and part of its dependencies are already included (``./ext``):
+  AGRIF preprocessing program "conv", FCM build system and IOIPSL library for outputs.
+| And some Perl 5, Fortran compiler (ifort, gfortran, pgfortran, ...), MPI library (Open MPI or MPICH)
 
-Extract the NEMO code
+But The following dependencies should be from the official repositories of your Linux distribution but
+you will probably have to compile them from source for enabling parallel I/O support.
 
-Using your account registered here ('my_login' with password)
+- `HDF5`_   (C library)
+- `NetCDF`_ (C and Fortran libraries)
+
+Extract the source code
+=======================
+
+Download the source code
+------------------------
 
 .. code:: console
-svn --username 'mylogin' co http://forge.ipsl.jussieu.fr/nemo/svn/branches/2015/nemo_v3_6_STABLE/NEMOGCM
 
-Description of NEMOGCM directory tree
+	$ svn co http://forge.ipsl.jussieu.fr/nemo/svn/NEMO/releases/release-4.0
 
-The image below shows the directory tree:
+Description of directory tree
+-----------------------------
 
-simple table:
-    ARCH    Compilation option files, with format arch_compiler.fcm, the compiler name has to be provided with –m option
-    CONFIG	All configurations and a cpp.fcm file containing the list of CPP keys to each configuration
-    EXTERNAL    Package to implement an embedded model (AGRIF)
-    NEMO    FORTRAN source codes in several sub-directories
-    SETTE    Package to make tests to ensure the reproducibility and restartability of the code after changes
-    TOOLS    Useful softwares to different utilities
++-----------+------------------------------------------------------------+
+| Folder    | Purpose                                                    |
++===========+============================================================+
+| ``arch``  | Settings (per architecture-compiler pair)                  |
++-----------+------------------------------------------------------------+
+| ``cfgs``  | :doc:`Reference configurations <configurations>`           |
++-----------+------------------------------------------------------------+
+| ``doc``   | - ``latex``: reference manuals for |OPA|, |SI3| & |TOP|    |
+|           | - ``namelists``: k start guide                             |
+|           | - ``rst``:   quick start guide                             |
++-----------+------------------------------------------------------------+
+| ``ext``   | Dependencies included (AGRIF, FCM & IOIPSL)                |
++-----------+------------------------------------------------------------+
+| ``mk``    | Building  routines                                         |
++-----------+------------------------------------------------------------+
+| ``src``   | Modelling routines                                         |
+|           |                                                            |
+|           | - ``ICE``: |SI3| for sea ice                               |
+|           | - ``NST``: AGRIF for embedded zooms                        |
+|           | - ``OCE``: |OPA| for ocean dynamics                        |
+|           | - ``MBG``: |TOP| for tracers                               |
++-----------+------------------------------------------------------------+
+| ``tests`` | :doc:`Test cases <test_cases>` (unsupported)               |
++-----------+------------------------------------------------------------+
+| ``tools`` | :doc:`Utilities <tools>` to [pre|post]process data         |
++-----------+------------------------------------------------------------+
 
 Extract and install XIOS
+========================
 
 Diagnostic outputs from NEMO are handled by the third party XIOS library.
@@ -42,5 +68,5 @@
 
 When you compile NEMO you will need to specify the following CPP keys:
-
+  
     key_iomput
     key_mpp_mpi (if you want to run with multiple processes and/or use "detached mode" for the IOs system XIOS)
@@ -48,4 +74,5 @@
 
 Setup your architecture configuration file
+==========================================
 
 All compiler options in NEMO are controlled using files in NEMOGCM/ARCH/arch-'my_arch'.fcm where 'my_arch' is the name of the computing architecture.
@@ -58,59 +85,42 @@
 
 Compile and create NEMO executable
+==================================
 
 The main script to compile and create executable is called makenemo and located in the CONFIG directory, it is used to identify the routines you need from the source code, to build the makefile and run it.
 As an example, compile GYRE with 'my_arch' to create a 'MY_GYRE' configuration:
 
-   cd NEMOGCM/CONFIG; ./makenemo –m 'my_arch' –r GYRE -n 'MY_GYRE'
+.. code-block:: sh
+
+	./makenemo –m 'my_arch' –r GYRE -n 'MY_GYRE'
 
 The image below shows the structure and some content of "MY_CONFIG" directory from the launching of the configuration creation (directories and fundamental files created by makenemo).
 
-	
++------------+----------------------------------------------------+
+| Folder     | Purpose                                            |
++============+====================================================+
+| ``BLD``    |                                                    |
++------------+----------------------------------------------------+
+| ``EXP00``  |                                                    |
++------------+----------------------------------------------------+
+| ``EXPREF`` |                                                    |
++------------+----------------------------------------------------+
+| ``MY_SRC`` |                                                    |
++------------+----------------------------------------------------+
+| ``WORK``   |                                                    |
++------------+----------------------------------------------------+
 
-    WORK
-
-	
-
-    Folder with the symbolic links to all unpreprocessed routines considered in the configuration
-
-    BLD
-
-	
-
-    Compilation folder (executables, headers files, libraries, preprocessed routines, flags, …)
-
-    EXP00
-
-	
-
-    Computation folder for running the model (namelists, xml, executables and inputs-outputs)
-
-    MY_SRC
-
-	
-
-    Folder intended to contain your customized routines (modified from initial ones or new entire routines)
+Folder with the symbolic links to all unpreprocessed routines considered in the configuration
+Compilation folder (executables, headers files, libraries, preprocessed routines, flags, …)
+Computation folder for running the model (namelists, xml, executables and inputs-outputs)
+Folder intended to contain your customised routines (modified from initial ones or new entire routines)
 
 After successful execution of makenemo command, the executable called opa is created in the EXP00 directory (in the example above, the executable is created in CONFIG/MY_GYRE/EXP00).
 More options
 
-        echo "Usage      : "${b_n} \
-            " [-h] [-n name] [-m arch] [-d "dir1 dir2"] [-r conf] [-u conf] [-s Path] [-e Path] [-j No] [-v No] [-k 0/1]";
-        echo " -h               : help";
-        echo " -h institute : specific help for consortium members";
-        echo " -n name      : config name, [-n help] to list existing configurations";
-        echo " -m arch      : choose compiler, [-m help] to list existing compilers";
-        echo " -d dir       : choose NEMO sub-directories";
-        echo " -r conf      : choose reference configuration";
-        echo " -u conf      : choose an unsupported (external) configuration";
-        echo " -s Path      : choose alternative location for NEMO main directory";
-        echo " -e Path      : choose alternative location for MY_SRC directory";
-        echo " -j No        : number of processes used to compile (0=nocompilation)";
-        echo " -v No        : set verbosity level for compilation [0-3]";
-        echo " -k 0/1       : used cpp keys check (default = 1 -> check activated)";
-        echo " -t dir       : temporary directory for compilation"
-        echo "";
+..
+	.. literalinclude::
 
 Default behaviour
+-----------------
 
     At the first use, you need the -m option to specify the architecture configuration file (compiler and its options, routines and libraries to include), then for next compilation, it is assumed you will be using the same compiler.
@@ -118,4 +128,5 @@
 
 Tools used during the process
+-----------------------------
 
     functions.sh : bash functions used by makenemo, for instance to create the WORK directory
@@ -124,4 +135,5 @@
 
 Examples
+--------
 
         echo "Example to install a new configuration MY_CONFIG";
@@ -149,7 +161,8 @@
 
 Running the model
+=================
 
-Once makenemo has run successfully, the opa executable is available in CONFIG/"MY_CONFIG"/EXP00
-For the reference configurations, the EXP00 folder also contains the initial input files (namelists, *xml files for the IOs…). If the configuration also needs NetCDF input files, this should be downloaded here from the corresponding tar file, see Users/Reference Configurations
+Once makenemo has run successfully, the opa executable is available in ``CONFIG/MY_CONFIG/EXP00``
+For the reference configurations, the EXP00 folder also contains the initial input files (namelists, \*xml files for the IOs…). If the configuration also needs NetCDF input files, this should be downloaded here from the corresponding tar file, see Users/Reference Configurations
 
    cd 'MY_CONFIG'/EXP00
@@ -157,8 +170,12 @@
 
 Viewing and changing list of active CPP keys
+============================================
 
-For a given configuration (here called MY_CONFIG), the list of active CPP keys can be found in
+For a given configuration (here called MY_CONFIG), the list of active CPP keys can be found in::
 
-   NEMOGCM/CONFIG/'MYCONFIG'/cpp_'MY_CONFIG'.fcm
+	NEMOGCM/CONFIG/'MYCONFIG'/cpp_'MY_CONFIG'.fcm
 
 This text file can be edited to change the list of active CPP keys. Once changed, one needs to recompile opa executable using makenemo command in order for this change to be taken in account.
+
+.. _HDF5:   http://www.hdfgroup.org/downloads/hdf5
+.. _NetCDF: http://www.unidata.ucar.edu/downloads/netcdf
Index: MO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/README-setup-configs
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/README-setup-configs	(revision 10344)
+++ 	(revision )
@@ -1,53 +1,0 @@
-==============================================================
-== HOW TO set up user’s configuration in NEMO version 4.0 : ==
-==============================================================
-This document describes how a configuration is set up in NEMO.
-
-In NEMO 4.0 two types of configurations can be build: global/regional and idealized.
-
-- create ./cfgs/your_config
-- case 1: regional or global 
-    => ln_read_cfg = .true. in ./cfgs/your_config/EXP00/namelist_cfg (i.e. read domain_cfg.nc)
-- case 2: idealized 
-    =>in ./cfgs/your_config/EXP00/namelist_cfg :
-      ln_read_cfg = .false. (need to define usrdef_hgr.F90 and usrdef_zgr.F90) 
-      ln_usr = .true.       (need to define usrdef_sbc.F90)    
-    => copy ./src/OCE/USR in ./cfgs/your_config/MY_SRC routines nedeed to set up domain, forcing fields and initial state
-    
-  Routines in NEMOGCM/NEMO/OCE/USR define analytically the domain, the initial state and the surface boundary conditions for the reference configuration GYRE.
-	  •	usrdef_hgr.F90 and usrdef_zgr.F90 : define horizontal and vertical grid
-	  •	usrdef_sbc.F90    : provides at each time-step the surface boundary condition, i.e. the momentum, heat and freshwater fluxes
-	  •	usrdef_istate.F90 : defines initialization of the dynamics and tracers
-	  •	usrdef_fmask.F90  : used just in ORCA CONFIGURATIONS for alteration of f-point land/ocean mask in some straits 
-	  •	usrdef_closea.F90 : used just in ORCA CONFIGURATIONS for specific treatments associated with closed seas
-	  •	usrdef_nam.F90    : set the domain characteristics of a user configuration
-
-  Other analytical examples are given in ./tests.
-
-===========================================
-== The domain_cfg.nc file must contain : ==
-===========================================
-   int ORCA  , ORCA_index            : configuration name, configuration resolution
-   int jpiglo, jpjglo , jpkglo       : global domain sizes 
-   int jperio                        : lateral global domain b.c. 
-   int ln_zco, ln_zps, ln_sco        : flags for z-coordinate, z-coordinate with partial steps and s-coordinate 
-   int ln_isfcav                     : flag  for ice shelf cavities 
-   double glamt, glamu, glamv, glamf : geographic position 
-   double gphit, gphiu, gphiv, gphif : geographic position
-   double iff, ff_f, ff_t            : Coriolis parameter (if not on the sphere)
-   double e1t, e1u, e1v, e1f         : horizontal scale factors
-   double e2t, e2u, e2v, e2f         : horizontal scale factors
-   double ie1e2u_v, e1e2u, e1e2v     : U and V surfaces (if grid size reduction in some straits)
-   double e3t_1d, e3w_1d             : reference vertical scale factors at T and W points
-   double e3t_0, e3u_0, e3v_0, e3f_0, e3w_0 : vertical scale factors 3D coordinate at T,U,V,F and W points
-   double e3uw_0,e3vw_0              : vertical scale factors 3D coordinate at UW and VW points
-   int bottom_level, top_level       : last wet T-points, 1st wet T-points (for ice shelf cavities)
-
-=======================================
-= HOW TO CREATE domain_cfg.nc file : ==
-=======================================
-Two options are possible :
-
- - users can create with his own tool the domain_cfg.nc with all mandatory fields.  
-
- - tool is available in ./tools/DOMAINcfg based on NEMO 3.6 version. See ./tools/DOMAINcfg/README.
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/README.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/README.rst	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/README.rst	(revision 10345)
@@ -1,103 +1,89 @@
-.. role:: rstblue
-.. role:: rstgrey
-.. role:: rstgreen
+:Authors: NEMO System Team
+:Release: |release|
+:Date:    |today|
 
-================
-NEMO Ocean Model
-================
+`NEMO`_ for *Nucleus for European Modelling of the Ocean* is a state-of-the-art modelling framework for
+research activities and forecasting services in ocean and climate sciences.
 
-NEMO_ (Nucleus for European Modelling of the Ocean) is a state-of-the-art modelling framework of 
-ocean related engines for oceanographic research, operational oceanography, seasonal forecast and 
-[paleo]climate studies.
+.. contents::
+	:local:
+
+Overview
+========
 
 The NEMO ocean model has 3 major components:
 
-- :rstblue:`OPA` is fundamental to all users by modelling the ocean [thermo]dynamics and 
-  solving the primitive equations;
-- :rstgrey:`LIM` for sea-ice simulates ice [thermo]dynamics, brine inclusions and 
-  subgrid-scale thickness variations;
-- :rstgreen:`TOP-PISCES` models biogeochemistry with TOP for 
-  the on/offline oceanic tracers transport and PISCES for the biogeochemical processes.
+- |OPA| models the ocean [thermo]dynamics and solves the primitive equations
+  (``./src/OCE``) :cite:`NEMO_manual`;
+- |SI3| simulates ice [thermo]dynamics, brine inclusions and subgrid-scale thickness variations
+  (``./src/ICE``) :cite:`SI3_manual`;
+- |TOP| models the [on|off]line oceanic tracers transport and the biogeochemical processes
+  (``./src/MBG``) :cite:`TOP_manual`.
 
-These physical engines are described in their respective `reference publications`_.
+These physical core engines are described in their respective <reference publications> that must be cited for
+any work related to their use.
 
-They are complemented by a 2-way nesting software (AGRIF_) and 
-a versatile data assimilation interface with 3 different modules
-(linear-tangent TAM, observational operators OBS, and increment ASM).
+Applications and capabilities
+=============================
 
-------------
-Applications
-------------
+Not only does the NEMO framework model the ocean circulation,
+it offers various features to enable
 
-| Distributed under CeCILL license (GNU GPL compatible - see ``LICENSE``), 
-  the framework offers several builtins reference configurations to 
-  check your computing architecture and evaluate the model skills and performances (``./cfgs``).
-| The end user could also find some idealized test cases on the web to serve as examples and 
-  to study particular processes.
+- Create :doc:`embedded zooms <zooms>` seamlessly with 2-way nesting package `AGRIF`_.
+- :doc:`Low cost biogeochemistry <coarsening>` and :doc:`alternative model opportunity <tracers>`.
+- Versatile :doc:`assimilation <assimilation>`.
+- :doc:`Output diagnostics <diagnostics>` with `XIOS`_ server.
+- :doc:`Coupling <coupling>` via `OASIS`_ for Earth system modelling.
 
-A set of tools is also provided to setup your own configuration and 
-[pre|post]process your data (``./tools``).
+| Several :doc:`builtins configurations <configurations>` are provided to assess the skills and performances of
+	the model which can be used as templates for :doc:`setting up a new configuration <setup>` (``./cfgs``).
+| The end user could also find some :doc:`idealised test cases <test_cases>` online to serve as templates and
+	to study particular processes (``./tests``).
 
--------
-Options
--------
+A set of :doc:`utilities <tools>` is also provided to [pre|post]process your data (``./tools``).
 
-For writing diagnostics in a efficient way, NEMO make use of XIOS_ server which 
-controlled the outputs using XML input file.
+Literature
+==========
 
-To enable Earth system modelling, NEMO can be interfaced via 
-OASIS_ coupleur to external components such as atmospheric models or 
-alternative models of sea-ice or biogeochemistry.
+:doc:`install`
 
--------------
-Documentation
--------------
+The reference documentation is archived online
 
-The NEMO reference manual can be generated from the LaTeX source code (``./doc``), 
-either in PDF or in HTML format, but it mights require some additionnal installations.
++-------+-------------------+----------------+
+|       | Reference manual  | |NEMO manual|_ |
+| |OPA| +-------------------+----------------+
+|       | Quick start guide | |NEMO guide|_  |
++-------+-------------------+----------------+
+| |SI3|                     | |SI3 manual|_  |
++---------------------------+----------------+
+| |TOP|                     | |TOP manual|_  |
++---------------------------+----------------+
 
-In any case, both formats are available online on the `NEMO website`__.
+.. |NEMO manual| image:: http://zenodo.org/badge/DOI/10.5281/zenodo.1464816.svg
+.. |NEMO guide|  image:: http://zenodo.org/badge/DOI/10.5281/zenodo.1475325.svg
+.. |SI3 manual|  image:: http://zenodo.org/badge/DOI/10.5281/zenodo.1471689.svg
+.. |TOP manual|  image:: http://zenodo.org/badge/DOI/10.5281/zenodo.1471700.svg
 
----------------------
+| Reference manuals and quick start guide can be build from source and exported to HTML or PDF (``./doc``).
+| In any case, one can find them online:
+
+Since 2014 the project has a `Special Issue <http://www.geosci-model-dev.net/special_issue40.html>`_ in
+the open-access journal Geoscientific Model Development (GMD) from the European Geosciences Union (EGU).
+The main scope is to collect relevant manuscripts covering various topics and to provide a single portal to
+assess the model potential and evolution.
+
+Used by a wide audience, numerous :website:`associated projects <projects>` have been carried out and
+extensive :website:`bibliography <bibliography/publications>` published.
+
 Community development
----------------------
+=====================
 
-| The NEMO Consortium gathering 6 European institutes organises the sustainable development in order to 
-  keep a reliable evolving system since 2008.
-| It defined the multiyear development strategy which is implemented by the NEMO System Team.
+| The NEMO Consortium pulling together 5 European institutes (`CMCC`_, `CNRS`_, `MOI`_, `Met Office`_ and `NERC`_)
+	plans the sustainable development in order to keep a reliable evolving framework since 2008.
+| It defines the |NEMO strategy|_ which is implemented by the System Team on
+	a yearly basis in	order to release a new version almost every four years.
 
---------
-Acronyms
---------
+.. |NEMO strategy| replace:: multi-year development strategy
 
-AGRIF
- Adaptive Grid Refinement In Fortran
-
-LIM
- Louvain-la-Neuve Ice Model
-
-OPA
- "Océan PArallélisé" (french)
-
-PISCES
- Pelagic Interactions Scheme for Carbon and Ecosystem Studies
-
-TAM
- Tangent Adjoint Model
-
-TOP
- Tracers in Ocean Paradigm
-
-XIOS
- XML Input Output Server
-
-----
-
-.. _AGRIF:                  http://agrif.imag.fr
-.. _Forge:                  http://forge.ipsl.jussieu.fr/nemo
-.. _NEMO:                   http://www.nemo-ocean.eu
-.. _OASIS:                  http://verc.enes.org/oasis
-.. _reference publications: http://www.nemo-ocean.eu/bibliography/documentation
-.. _XIOS:                   http://forge.ipsl.jussieu.fr/ioserver
-
-.. __:  NEMO_
+When the need arises, :forge:`working groups <wiki/WorkingGroups>` are created or resumed to
+gather the community expertise for advising on the development activities.
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/REFERENCES.bib
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/REFERENCES.bib	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/REFERENCES.bib	(revision 10345)
@@ -0,0 +1,68 @@
+@manual{NEMO_manual,
+   title={NEMO ocean engine},
+   author={Madec Gurvan and NEMO System Team},
+   organization={NEMO Consortium},
+   journal={Notes du Pôle de modélisation de l\'Institut Pierre-Simon Laplace (IPSL)},
+   number={27},
+   publisher={Zenodo},
+   abstract={The ocean engine of NEMO is a primitive equation model adapted to regional and
+   global ocean circulation problems.
+   It is intended to be a flexible tool for studying the ocean and its interactions with
+   the others components of the earth climate system over a wide range of space and time scales.},
+   doi={10.5281/zenodo.1464816},
+   edition={},
+   year={}
+}
+
+@manual{SI3_manual,
+   title={SI³ – Sea Ice modelling Integrated Initiative – The NEMO Sea Ice engine},
+   author={NEMO Sea Ice Working Group},
+   organization={NEMO Consortium},
+   journal={Notes du Pôle de modélisation de l\'Institut Pierre-Simon Laplace (IPSL)},
+   number={31},
+   publisher={Zenodo},
+   abstract={SI³ (Sea Ice modelling Integrated Initiative) is the sea ice engine of NEMO
+   (Nucleus for European Modelling of the Ocean).
+   It is adapted to regional and global sea ice and climate problems.
+   It is intended to be a flexible tool for studying sea ice and its interactions with
+   the other components of the Earth System over a wide range of space and time scales.
+   SI3 is based on the Arctic Ice Dynamics Joint EXperiment (AIDJEX) framework,
+   combining the ice thickness distribution framework, the conservation of horizontal momentum,
+   an elastic-viscous plastic rheology, and energy-conserving halo-thermodynamics.
+   Prognostic variables are the two-dimensional horizontal velocity field, ice volume, area, enthalpy,
+   salt content, snow volume and enthalpy.
+   In the horizontal direction, the model uses a curvilinear orthogonal grid.
+   In the vertical direction, the model uses equally-spaced layers.
+   In thickness space, the model uses thickness categories with prescribed boundaries.
+   Various physical and numerical choices are available to describe sea ice physics.
+   SI3 is interfaced with the NEMO ocean engine, and, via the OASIS coupler, with
+   several atmospheric general circulation models.
+   It also supports two-way grid embedding via the AGRIF software.},
+   doi={10.5281/zenodo.1471689},
+   edition={},
+   year={}
+}
+
+@manual{TOP_manual,
+   title={TOP – Tracers in Ocean Paradigm – The NEMO Tracers engine},
+   author={NEMO TOP Working Group},
+   organization={NEMO Consortium},
+   journal={Notes du Pôle de modélisation de l\'Institut Pierre-Simon Laplace (IPSL)},
+   number={28},
+   publisher={Zenodo},
+   abstract={},
+   doi={10.5281/zenodo.1471700},
+   edition={},
+   year={}
+}
+
+@Article{gmd-8-1245-2015,
+   author = {Vidard, A. and Bouttier, P.-A. and Vigilant, F.},
+   title = {{NEMOTAM}: {T}angent and {A}djoint {M}odels for the ocean modelling platform {NEMO}},
+   journal = {Geoscientific Model Development},
+   volume = {8},
+   year = {2015},
+   number = {4},
+   pages = {1245--1257},
+   doi = {10.5194/gmd-8-1245-2015}
+}
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/RELEASE_NOTES.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/RELEASE_NOTES.rst	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/RELEASE_NOTES.rst	(revision 10345)
@@ -1,12 +1,9 @@
-================
-NEMO 4.0 Release
-================
+**********************
+What's new in NEMO 4.0
+**********************
 
 .. contents::
-
-----------
-What's new
-----------
-
+	:local:
+      
 Original sea-ice component SI\ :sup:`3`\
 ========================================
@@ -50,54 +47,4 @@
 Define and install a separate repository for test cases to all easy contributions from the NEMO Users Community
 
-+-------------------+--------------------------------------------------------+------------------------------------+
-| Name              | Purpose                                                | References                         |
-+===================+=================+======================================+====================================+
-| ``CANAL``         | East-west periodic canal of variable size with several |                                    |
-|                   | initial states and associated geostrophic currents     |                                    |
-|                   | (zonal jets or vortex).                                |                                    |
-+-------------------+--------------------------------------------------------+------------------------------------+
-| ``ICEDYN``        | East-west + north-south periodic channel.              |                                    |
-|                   | The common configuration includes an AGRIF zoom (1:3)  |                                    |
-|                   | in the middle of the basin to test how an ice patch is |                                    |
-|                   | advected through it but one can also test the          |                                    |
-|                   | advection schemes (Prather and Ultimate-Macho) by      |                                    |
-|                   | removing the ``key_agrif`` in the CPP keys.            |                                    |
-+-------------------+--------------------------------------------------------+------------------------------------+
-| ``ISOMIP``        | Simple box configuration with an iceshelf with simple  | `Hunter 2006`_                     |
-|                   | geometry on top.                                       |                                    |
-|                   | The purpose of this test case is to evaluate the       |                                    |
-|                   | impact of various schemes and new development with     |                                    |
-|                   | iceshelf cavities.                                     |                                    |
-+-------------------+--------------------------------------------------------+------------------------------------+
-| ``LOCK_EXCHANGE`` | Classical fluid dynamics experiment that has been      | - `Haidvogel and Beckmann 1999`_   |
-|                   | adapted for testing advection schemes in ocean         | - `Burchard and Bolding 2002`_     |
-|                   | circulation models.                                    | - `Ilıcak 2012`_                   |
-|                   | This experiment can in particular illustrate the       |                                    |
-|                   | impact of different choices of numerical schemes       |                                    |
-|                   | and/or subgrid closures on spurious interior mixing.   |                                    |
-+-------------------+--------------------------------------------------------+------------------------------------+
-| ``OVERFLOW``      | Adapted from the non-rotating overflow configuration   | - `Haidvogel and Beckmann 1999`_   |
-|                   | Illustrates the impact of different choices of         | - `Ilıcak 2012`_                   |
-|                   | numerical schemes and/or subgrid closures on spurious  |                                    |
-|                   | interior mixing close to bottom topography.            |                                    |
-+-------------------+--------------------------------------------------------+------------------------------------+
-| ``VORTEX``        | Illustrates the propagation of an anticyclonic eddy    | - `Debreu 2012`_                   |
-|                   | over a Beta plan and flat bottom.                      | - `Penven 2006`_                   |
-|                   | It is implemented here with an online refined          | - `Spall and Holland 1991`_        |
-|                   | subdomain (thanks to AGRIF library) out of which the   |                                    |
-|                   | vortex propagates and serves as a benchmark to         |                                    |
-|                   | diagnose nesting errors.                               |                                    |
-+-------------------+--------------------------------------------------------+------------------------------------+
-| ``WAD``           | Set of simple closed basin geometries for testing the  |                                    |
-|                   | wetting and drying capabilities.                       |                                    |
-|                   | Examples range from a closed channel with EW linear    |                                    |
-|                   | bottom slope to a parabolic EW channel with a Gaussian |                                    |
-|                   | ridge.                                                 |                                    |
-+-------------------+--------------------------------------------------------+------------------------------------+
-
------------
-Improvments
------------
-
 Core components
 ===============
@@ -108,5 +55,5 @@
 - The passive tracers transport component was redesigned toward a modular structure and
   users can enable each module directly through logical flags in namelist_top (no more Fortran macros!).
-- TOP on-line user documentation is available on NEMO Trac platform (TOP-UserQuickGuide_)
+- TOP on-line user documentation is available on NEMO Trac platform (`TOP User Quick Guide`_)
 - TOP currently accounts for the following 5 modules:
 
@@ -130,4 +77,64 @@
 AGRIF (embedded zooms)
 ----------------------
+
+The NEMO 4.0 includes new capabilities, configurations and test cases with AGRIF:
+
+.. role:: underline
+	:class: underline
+
+:underline:`New capabilities from NEMO 3.6 to NEMO 4.0`
+
+AGRIF is continuously maintained so that it could be activated with all NEMO components (OPA, sea-ice, TOP).
+Depending on NEMO version, it is nevertheless not the case so that some options may not be compatible with
+the use of online grid refinement.
+Check out the table below to know the status according to the NEMO release you may use.
+
+:underline:`Status of available options with AGRIF (if not listed, option is compatible with AGRIF)`:
+
++--------------------------------------------------------+----------------+---------------------+
+|                                                        | NEMO 3.6       | NEMO 4.0            |
++========================================================+================+=====================+
+| LIM2                                                   | yes            | ``-``               |
++--------------------------------------------------------+----------------+---------------------+
+| LIM3/SI3                                               | no             | yes                 |
++--------------------------------------------------------+----------------+---------------------+
+| TOP                                                    | yes            | yes                 |
++--------------------------------------------------------+----------------+---------------------+
+| GLS vertical mixing                                    | no             | yes                 |
++--------------------------------------------------------+----------------+---------------------+
+| z*                                                     | no             | yes                 |
++--------------------------------------------------------+----------------+---------------------+
+| z~                                                     | no             | no                  |
++--------------------------------------------------------+----------------+---------------------+
+| Lagrangian icebergs                                    | no             | no                  |
++--------------------------------------------------------+----------------+---------------------+
+| East-west periodic and/or north fold bcs in zooms      | no             | no                  |
++--------------------------------------------------------+----------------+---------------------+
+| Online timing                                          | no             | no                  |
++--------------------------------------------------------+----------------+---------------------+
+| Stochastic parameterization                            | no             | no                  |
++--------------------------------------------------------+----------------+---------------------+
+| Vertical coordinate change in zooms (``key_vertical``) | no             | yes, but not tested |
++--------------------------------------------------------+----------------+---------------------+
+| Number of ghost cells                                  | 1 (hard coded) | 3 (parameter)       |
++--------------------------------------------------------+----------------+---------------------+
+
+[Important notice concerning the change of ghost cells number]
+
+The default number of ghost cells (i.e. the number of cells that serve as open boundary data provision) has been
+increased from 1 to 3 in NEMO 4.0.
+This allows to properly handle boundary conditions for numerical schemes that
+have a discretization order greater than 2.
+On the user point of view this does not change anything++ except in the definition of level 1 grids in
+the ``AGRIF_FixedGrids.in`` file.
+In order to retrieve exactly the position of a nested grid in NEMO 4.0 one has to shift indices by
+2 points to the south-west.
+Taking the ``ICEDYN`` example above for NEMO 4.0, the "old" NEMO 3.6 corresponding file would contain::
+
+	1
+	36 65 36 65 3 3 3
+	0
+
+++ Child grid output files are now greater by 4 points in each direction.
 
 - Now compatible with new sea ice component and z* coordinate
@@ -159,5 +166,5 @@
 - Wave coupling: large scale wave interaction process added in momentum and tracer equations
 - Remove the acceleration of convergence
-  
+
 Numerics
 --------
@@ -197,14 +204,8 @@
 
 .. _sea ice working group:       http://forge.ipsl.jussieu.fr/nemo/wiki/WorkingGroups/SI3
-.. _TOP-UserQuickGuide:          http://forge.ipsl.jussieu.fr/nemo/wiki/WorkingGroups/top-dg/TOP-UserQuickGuide
-
-.. _Hunter 2006:                 http://staff.acecrc.org.au/~bkgalton/ISOMIP/test_cavities.pdf
+.. _TOP User Quick Guide:        http://forge.ipsl.jussieu.fr/nemo/wiki/WorkingGroups/top-dg/TOP-UserQuickGuide
+
+.. The following references should be in the manual bibliographies and referenced via 'bibliography' directive
 .. _Brodeau 2017:                http://doi.org/10.1175/JPO-D-16-0169.1
-.. _Haidvogel and Beckmann 1999: http://hdl.handle.net/10013/epic.11761
-.. _Burchard and Bolding 2002:   http://www.researchgate.net/publication/258128069_GETM_A_General_Estuarine_Transport_Model_Scientific_Documentation
-.. _Ilıcak 2012:                 http://doi.org/10.1016/j.ocemod.2011.10.003
-.. _Debreu 2012:                 http://doi.org/10.1016/j.ocemod.2012.03.003
-.. _Penven 2006:                 http://doi.org/10.1016/j.ocemod.2005.05.002
-.. _Spall and Holland 1991:      http://www.researchgate.net/publication/232101325_A_Nested_Primitive_Equation_Model_for_Oceanic_Applications
 .. _Holland 2012:                http://doi.org/10.1175/JCLI-D-11-00078.1
 .. _Lupkes 2012:                 http://doi.org/10.1029/2012JD017630
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/AGRIF_DEMO/README.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/AGRIF_DEMO/README.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/AGRIF_DEMO/README.rst	(revision 10345)
@@ -0,0 +1,107 @@
+**********************
+Embedded zooms (AGRIF)
+**********************
+
+.. contents::
+   :local:
+
+Overview
+========
+
+AGRIF (Adaptive Grid Refinement In Fortran) is a library that allows the seamless space and time refinement over
+rectangular regions in NEMO.
+Refinement factors can be odd or even (usually lower than 5 to maintain stability).
+Interaction between grid is "two-ways" in the sense that the parent grid feeds the child grid open boundaries and
+the child grid provides volume averages of prognostic variables once a given number of time step is completed.
+These pages provide guidelines how to use AGRIF in NEMO.
+For a more technical description of the library itself, please refer to http://agrif.imag.fr.
+
+Compilation
+===========
+
+Activating AGRIF requires to append the cpp key ``key_agrif`` at compilation time: 
+
+.. code-block:: sh
+
+	./makenemo add_key 'key_agrif'
+
+Although this is transparent to users, the way the code is processed during compilation is different from
+the standard case:
+a preprocessing stage (the so called "conv" program) translates the actual code so that
+saved arrays may be switched in memory space from one domain to an other.
+
+Definition of the grid hierarchy
+================================
+
+An additional text file ``AGRIF_FixedGrids.in`` is required at run time.
+This is where the grid hierarchy is defined.
+An example of such a file, here taken from the ``ICEDYN`` test case, is given below::
+
+	1
+	34 63 34 63 3 3 3
+	0
+
+The first line indicates the number of zooms (1).
+The second line contains the starting and ending indices in both directions on the root grid
+(imin=34 imax=63 jmin=34 jmax=63) followed by the space and time refinement factors (3 3 3).
+The last line is the number of child grid nested in the refined region (0).
+A more complex example with telescoping grids can be found below and
+in the ``AGRIF_DEMO`` reference configuration directory.
+
+[Add some plots here with grid staggering and positioning ?]
+
+When creating the nested domain, one must keep in mind that the child domain is shifted toward north-east and
+depends on the number of ghost cells as illustrated by the (attempted) drawing below for nbghostcells=1 and
+nbghostcells=3.
+The grid refinement is 3 and nxfin is the number of child grid points in i-direction.  
+
+.. image:: _static/agrif_grid_position.jpg
+
+Note that rectangular regions must be defined so that they are connected to a single parent grid.
+Hence, defining overlapping grids with the same refinement ratio will not work properly,
+boundary data exchange and update being only performed between root and child grids.
+Use of east-west periodic or north-fold boundary conditions is not allowed in child grids either.
+Defining for instance a circumpolar zoom in a global model is therefore not possible. 
+
+Preprocessing
+=============
+
+Knowing the refinement factors and area, a ``NESTING`` pre-processing tool may help to create needed input files
+(mesh file, restart, climatological and forcing files).
+The key is to ensure volume matching near the child grid interface,
+a step done by invoking the ``Agrif_create_bathy.exe`` program.
+You may use the namelists provided in the ``NESTING`` directory as a guide.
+These correspond to the namelists used to create ``AGRIF_DEMO`` inputs.
+
+Namelist options
+================
+
+Each child grid expects to read its own namelist so that different numerical choices can be made
+(these should be stored in the form ``1_namelist_cfg``, ``2_namelist_cfg``, etc... according to their rank in
+the grid hierarchy).
+Consistent time steps and number of steps with the chosen time refinement have to be provided.
+Specific to AGRIF is the following block:
+
+.. code-block:: fortran
+
+	!-----------------------------------------------------------------------
+	&namagrif      !  AGRIF zoom                                            ("key_agrif")
+	!-----------------------------------------------------------------------
+	   ln_spc_dyn    = .true.  !  use 0 as special value for dynamics
+	   rn_sponge_tra = 2880.   !  coefficient for tracer   sponge layer [m2/s]
+	   rn_sponge_dyn = 2880.   !  coefficient for dynamics sponge layer [m2/s]
+	   ln_chk_bathy  = .false. !  =T  check the parent bathymetry
+	/             
+
+where sponge layer coefficients have to be chosen according to the child grid mesh size.
+The sponge area is hard coded in NEMO and applies on the following grid points:
+2 x refinement factor (from i=1+nbghostcells+1 to i=1+nbghostcells+sponge_area) 
+
+References
+==========
+
+.. bibliography:: zooms.bib
+	:all:
+	:style: unsrt
+	:labelprefix: A
+	:keyprefix: a-
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/AGRIF_DEMO/zooms.bib
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/AGRIF_DEMO/zooms.bib	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/AGRIF_DEMO/zooms.bib	(revision 10345)
@@ -0,0 +1,35 @@
+@article{DEBREU2012,
+   title = "Two-way nesting in split-explicit ocean models: Algorithms, implementation and validation",
+   journal = "Ocean Modelling",
+   volume = "49-50",
+   pages = "1 - 21",
+   year = "2012",
+   issn = "1463-5003",
+   doi = "10.1016/j.ocemod.2012.03.003",
+   author = "Laurent Debreu and Patrick Marchesiello and Pierrick Penven and Gildas Cambon",
+   keywords = "Two-way nesting, Finite difference method, Modeling, Boundary conditions, Coastal upwelling"
+}
+
+@article{PENVEN2006,
+   title = "Evaluation and application of the {ROMS} 1-way embedding procedure to the central california upwelling system",
+   journal = "Ocean Modelling",
+   volume = "12",
+   number = "1",
+   pages = "157 - 187",
+   year = "2006",
+   issn = "1463-5003",
+   doi = "10.1016/j.ocemod.2005.05.002",
+   author = "Pierrick Penven and Laurent Debreu and Patrick Marchesiello and James C. McWilliams",
+   keywords = "Ocean models, Boundary conditions, Embedding, Coastal upwelling, Mesoscale eddies, Eddy kinetic energy, North America, West Coast, Central upwelling system, Monterey Bay, 35–41°N, 128–121°W"
+}
+
+@article{SPALL1991,
+   author = {Spall, Michael A. and Holland, William R.},
+   title = {A Nested Primitive Equation Model for Oceanic Applications},
+   journal = {Journal of Physical Oceanography},
+   volume = {21},
+   number = {2},
+   pages = {205-220},
+   year = {1991},
+   doi = {10.1175/1520-0485(1991)021<0205:ANPEMF>2.0.CO;2},
+}
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_ICE_PISCES/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_ICE_PISCES/EXPREF/context_nemo.xml	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_ICE_PISCES/EXPREF/context_nemo.xml	(revision 10345)
@@ -6,23 +6,13 @@
 <context id="nemo">
 <!-- $id$ -->
-    <variable_definition>
-    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
-       <variable id="ref_year" type="int"   > 1800 </variable>
-       <variable id="rau0"     type="float" > 1026.0 </variable>
-       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
-       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
-       <variable id="rhoic"    type="float" > 917.0 </variable>
-       <variable id="rhosn"    type="float" > 330.0 </variable>
-       <variable id="missval"  type="float" > 1.e20 </variable>
-    </variable_definition>
 <!-- Fields definition -->
-    <field_definition src="./field_def_nemo-oce.xml"/>    <!--  NEMO ocean dynamics     -->
-    <field_definition src="./field_def_nemo-ice.xml"/>    <!--  NEMO sea-ice model      -->
-    <field_definition src="./field_def_nemo-pisces.xml"/> <!--  NEMO ocean biology      -->
+    <field_definition src="./field_def_nemo-oce.xml"/>    <!--  NEMO ocean dynamics     --> 
+    <field_definition src="./field_def_nemo-ice.xml"/>    <!--  NEMO sea-ice model      --> 
+    <field_definition src="./field_def_nemo-pisces.xml"/> <!--  NEMO ocean biology      --> 
 
 <!-- Files definition -->
-    <file_definition src="./file_def_nemo-oce.xml"/>     <!--  NEMO ocean dynamics      -->
-    <file_definition src="./file_def_nemo-ice.xml"/>     <!--  NEMO sea-ice model       -->
-    <file_definition src="./file_def_nemo-pisces.xml"/>  <!--  NEMO ocean biology       -->
+    <file_definition src="./file_def_nemo-oce.xml"/>     <!--  NEMO ocean dynamics      --> 
+    <file_definition src="./file_def_nemo-ice.xml"/>     <!--  NEMO sea-ice model       --> 
+    <file_definition src="./file_def_nemo-pisces.xml"/>  <!--  NEMO ocean biology       --> 
     <!-- 
 ============================================================================================================
@@ -32,13 +22,14 @@
     
     <axis_definition>
-      <axis id="deptht"  long_name="Vertical T levels"  unit="m" positive="down" />
-      <axis id="depthu"  long_name="Vertical U levels"  unit="m" positive="down" />
-      <axis id="depthv"  long_name="Vertical V levels"  unit="m" positive="down" />
-      <axis id="depthw"  long_name="Vertical W levels"  unit="m" positive="down" />
-      <axis id="nfloat"  long_name="Float number"       unit="-"                 />
-      <axis id="icbcla"  long_name="Iceberg class"      unit="1"                 />
-      <axis id="ncatice" long_name="Ice category"       unit="1"                 />
-      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"              />
-      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"              />
+      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="profsed" long_name="Vertical S levels" unit="cm" positive="down" />
+      <axis id="nfloat" long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
+      <axis id="ncatice" long_name="Ice category"       unit="1"               />
+      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
+      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
     </axis_definition>
  
@@ -46,4 +37,4 @@
   
     <grid_definition src="./grid_def_nemo.xml"/>
-
+    
 </context>
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg	(revision 10345)
@@ -88,4 +88,14 @@
    nn_fwb      = 2         !  FreshWater Budget: 
    !                       !    =2 annual global mean of e-p-r set to zero
+   ln_wave     = .false.   !  Activate coupling with wave  (T => fill namsbc_wave)
+   ln_cdgw     = .false.   !  Neutral drag coefficient read from wave model (T => ln_wave=.true. & fill namsbc_wave)
+   ln_sdw      = .false.   !  Read 2D Surf Stokes Drift & Computation of 3D stokes drift (T => ln_wave=.true. & fill namsbc_wave) 
+   nn_sdrift   =  0        !  Parameterization for the calculation of 3D-Stokes drift from the surface Stokes drift
+      !                    !   = 0 Breivik 2015 parameterization: v_z=v_0*[exp(2*k*z)/(1-8*k*z)]
+      !                    !   = 1 Phillips:                      v_z=v_o*[exp(2*k*z)-beta*sqrt(-2*k*pi*z)*erfc(sqrt(-2*k*z))]
+      !                    !   = 2 Phillips as (1) but using the wave frequency from a wave model
+   ln_tauwoc   = .false.   !  Activate ocean stress modified by external wave induced stress (T => ln_wave=.true. & fill namsbc_wave)
+   ln_tauw     = .false.   !  Activate ocean stress components from wave model
+   ln_stcor    = .false.   !  Activate Stokes Coriolis term (T => ln_wave=.true. & ln_sdw=.true. & fill namsbc_wave)
 /
 !-----------------------------------------------------------------------
@@ -151,4 +161,8 @@
 /
 !-----------------------------------------------------------------------
+&namsbc_wave   ! External fields from wave model                        (ln_wave=T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
 &namberg       !   iceberg parameters                                   (default: OFF)
 !-----------------------------------------------------------------------
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_pisces_cfg
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_pisces_cfg	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_pisces_cfg	(revision 10345)
@@ -16,9 +16,9 @@
 /
 !-----------------------------------------------------------------------
-&namp4zice     !   parameters for nutrient limitations for PISCES std  - ln_p4z
+&namp4zlim     !   parameters for nutrient limitations for PISCES std  - ln_p4z
 !-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
-&namp5zice     !   parameters for nutrient limitations PISCES QUOTA    - ln_p5z
+&namp5zlim     !   parameters for nutrient limitations PISCES QUOTA    - ln_p5z
 !-----------------------------------------------------------------------
 /
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_OFF_PISCES/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_OFF_PISCES/EXPREF/context_nemo.xml	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_OFF_PISCES/EXPREF/context_nemo.xml	(revision 10345)
@@ -23,4 +23,5 @@
       <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
       <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="profsed" long_name="Vertical S levels" unit="cm" positive="down" />
       <axis id="nfloat" long_name="Float number"      unit="-"                 />
       <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_OFF_PISCES/EXPREF/namelist_pisces_cfg
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_OFF_PISCES/EXPREF/namelist_pisces_cfg	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_OFF_PISCES/EXPREF/namelist_pisces_cfg	(revision 10345)
@@ -17,9 +17,9 @@
 /
 !-----------------------------------------------------------------------
-&namp4zice     !   parameters for nutrient limitations for PISCES std  - ln_p4z
+&namp4zlim     !   parameters for nutrient limitations for PISCES std  - ln_p4z
 !-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
-&namp5zice     !   parameters for nutrient limitations PISCES QUOTA    - ln_p5z
+&namp5zlim     !   parameters for nutrient limitations PISCES QUOTA    - ln_p5z
 !-----------------------------------------------------------------------
 /
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/README.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/README.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/README.rst	(revision 10345)
@@ -0,0 +1,349 @@
+*****************************
+Run a reference configuration
+*****************************
+
+.. contents::
+	:local:
+	:depth: 1
+      
+Official configurations
+=======================
+
+| NEMO is distributed with some reference configurations allowing both the user to set up a first application and
+  the developer to validate their developments.
+| :underline:`The NEMO System Team is in charge of these configurations`.
+
++----------------------+-----+-----+-----+--------+-------+-------------------------------+
+|                      | OPA | SI3 | TOP | PISCES | AGRIF | Inputs                        |
++======================+=====+=====+=====+========+=======+===============================+
+| `AGRIF_DEMO`_        |  X  |  X  |     |        |   X   | - `AGRIF_DEMO_v4.0.tar`_      |
+|                      |     |     |     |        |       | - `ORCA2_ICE_v4.0.tar`_       |
++----------------------+-----+-----+-----+--------+-------+-------------------------------+
+| `AMM12`_             |  X  |     |     |        |       | `AMM12_v4.0.tar`_             |
++----------------------+-----+-----+-----+--------+-------+-------------------------------+
+| `C1D_PAPA`_          |  X  |     |     |        |       | `INPUTS_C1D_PAPA_v4.0.tar`_   |
++----------------------+-----+-----+-----+--------+-------+-------------------------------+
+| `GYRE_BFM`_          |  X  |     |  X  |        |       | ``-``                         |
++----------------------+-----+-----+-----+--------+-------+-------------------------------+
+| `GYRE_PISCES`_       |  X  |     |  X  |   X    |       | ``-``                         |
++----------------------+-----+-----+-----+--------+-------+-------------------------------+
+| `ORCA2_ICE_PISCES`_  |  X  |  X  |  X  |   X    |       | - `ORCA2_ICE_v4.0.tar`_       |
+|                      |     |     |     |        |       | - `INPUTS_PISCES_v4.0.tar`_   |
++----------------------+-----+-----+-----+--------+-------+-------------------------------+
+| `ORCA2_OFF_PISCES`_  |     |     |  X  |   X    |       | - `INPUTS_PISCES_v4.0.tar`_   |
+|                      |     |     |     |        |       | - `ORCA2_OFF_v4.0.tar`_       |
++----------------------+-----+-----+-----+--------+-------+-------------------------------+
+| `ORCA2_OFF_TRC`_     |     |     |  X  |        |       | `ORCA2_OFF_v4.0.tar`_         |
++----------------------+-----+-----+-----+--------+-------+-------------------------------+
+| `ORCA2_SAS_ICE`_     |     |  X  |     |        |       | - `ORCA2_ICE_v4.0.tar`_       |
+|                      |     |     |     |        |       | - `INPUTS_SAS_v4.0.tar`_      |
++----------------------+-----+-----+-----+--------+-------+-------------------------------+
+| `SPITZ12`_           |  X  |  X  |     |        |       | `SPITZ12_v4.0.tar`_           |
++----------------------+-----+-----+-----+--------+-------+-------------------------------+
+
+AGRIF_DEMO
+----------
+
+.. image:: _static/AGRIF_DEMO.jpg
+
+``AGRIF_DEMO`` is based on the ``ORCA2_LIM3_PISCES`` global 2° configuration but
+it includes 3 online nested grids that demonstrate the overall capabilities of AGRIF in a realistic context,
+including nesting sea ice models.
+
+The configuration includes a 1:1 grid in the Pacific and two successively nested grids with odd and
+even refinement ratios over the Arctic ocean.
+The finest grid spanning the whole Svalbard archipelago is of particular interest to check that
+sea ice coupling is done properly.
+The 1:1 grid, used alone, is used as a benchmark to check that the solution is not corrupted by grid exchanges.
+
+Note that since grids interact only at the baroclinic time level,
+numerically exact results can not be achieved in the 1:1 case.
+One has to switch to a fully explicit in place of a split explicit free surface scheme in order to
+retrieve perfect reproducibility.
+
+Corresponding ``AGRIF_FixedGrids.in`` file is given by::
+
+	2
+	42 82 49 91 1 1 1
+	122 153 110 143 4 4 4
+	0
+	1
+	38 80 71 111 3 3 3
+	0
+
+AMM12
+-----
+
+``AMM12`` for *Atlantic Margin Model 12kms* is a `regional model`_ covering the Northwest European Shelf domain on
+a regular lat-lon grid at approximately 12km horizontal resolution.
+The key ``key_amm_12km`` is used to create the correct dimensions of the AMM domain.
+
+| This configuration tests several features of NEMO functionality specific to the shelf seas.
+| In particular, the AMM uses s-coordinates in the vertical rather than z-coordinates and is forced with
+  tidal lateral boundary conditions using a flather boundary condition from the BDY module (``key_bdy``).
+
+The AMM configuration uses the GLS (``key_zdfgls``) turbulence scheme,
+the VVL non-linear free surface (``key_vvl``) and time-splitting (``key_dynspg_ts``).
+
+In addition to the tidal boundary condition, the model may also take open boundary conditions from
+a North Atlantic model.
+Boundaries may be completely ommited by removing the BDY key (key_bdy) in ``./cfgs/AMM12/cpp_AMM12_fcm``.
+
+Sample surface fluxes, river forcing and a sample initial restart file are included to test a realistic model run.
+The Baltic boundary is included within the river input file and is specified as a river source.
+Unlike ordinary river points the Baltic inputs also include salinity and temperature data.
+
+C1D_PAPA
+--------
+
+``C1D_PAPA`` is a 1D configuration (one water column called NEMO1D, activated with CPP key ``key_c1d``),
+located at the `PAPA station 145W-50N <http://www.pmel.noaa.gov/OCS/Papa/index-Papa.shtml>`_.
+
+| NEMO1D is useful to test vertical physics in NEMO
+  (turbulent closure scheme, solar penetration, interaction ocean/atmosphere.,...)
+| Size of the horizontal domain is 3x3 grid points.
+
+This reference configuration uses a 75 vertical levels grid (1m at the surface),
+the GLS (key_zdfgls) turbulence scheme with K-epsilon closure and the CORE BULK formulae.
+The atmospheric forcing comes from ECMWF operational analysis with a modification of the long and short waves flux.
+This set has been rescaled at a frequency of 1h. 1 year is simulated in outputs,
+see below (June,15 2010 to June,14 2011)
+
+`Reffray 2015`_ describes some tests on vertical physic using this configuration.
+
+The inputs tar file includes:
+
+- forcing files covering the years 2010 and 2011 (``forcing_PAPASTATION_1h_y201*.nc``)
+- initialization file for June,15 2010 deduced from observed data and Levitus 2009 climatology
+  (``init_PAPASTATION_m06d15.nc``)
+- surface chlorophyll file (``chlorophyll_PAPASTATION.nc``) deduced from Seawifs data.
+
+GYRE_BFM
+--------
+
+``GYRE_BFM`` is the same configuration as `GYRE_PISCES`_, except that PISCES is replaced by
+BFM biogeochemichal model in coupled mode.
+
+GYRE_PISCES
+-----------
+
+| Idealized configuration representing double gyres in the North hemisphere, Beta-plane with
+  a regular grid spacing at 1° horizontal resolution (and possible use as a benchmark by
+  easily inscreasing grid size), 101 vertical levels, forced with analytical heat, freshwater and
+  wind-stress fields.
+| This configuration is coupled to `PISCES biogeochemical model`_.
+
+Running GYRE as a benchmark
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+This simple configuration can be used as a benchmark since it is easy to increase resolution
+(and in this case no physical meaning of outputs):
+
+1. Choose the grid size
+
+   In ``./cfgs/GYRE/EXP00``, edit your ``namelist_cfg`` file to change the ``jp_cfg``, ``jpi``, ``jpj``,
+   ``jpk`` variables in &namcfg:
+
+	+------------+---------+---------+---------+------------------+---------------+
+	| ``jp_cfg`` | ``jpi`` | ``jpj`` | ``jpk`` | Number of points | Equivalent to |
+	+============+=========+=========+=========+==================+===============+
+	| 1          | 30      | 20      | 101     | 60600            | GYRE 1°       |
+	+------------+---------+---------+---------+------------------+---------------+
+	| 25         | 750     | 500     | 101     | 37875000         | ORCA 1/2°     |
+	+------------+---------+---------+---------+------------------+---------------+
+	| 50         | 1500    | 1000    | 101     | 151500000        | ORCA 1/4°     |
+	+------------+---------+---------+---------+------------------+---------------+
+	| 150        | 4500    | 3000    | 101     | 1363500000       | ORCA 1/12°    |
+	+------------+---------+---------+---------+------------------+---------------+
+	| 200        | 6000    | 4000    | 101     | 2424000000       | ORCA 1/16°    |
+	+------------+---------+---------+---------+------------------+---------------+
+
+2. In `namelist_cfg` again, avoid problems in the physics (and results will not be meaningful in terms of physics) by setting `nn_bench = 1` in &namctl
+
+.. code-block:: fortran
+   
+   nn_bench    =    1     !  Bench mode (1/0): CAUTION use zero except for bench
+
+3. If you increase domain size, you may need to decrease time-step (for stability) by changing `rn_rdt` value in &namdom (i.e. for `jp_cfg = 150`, ORCA12 equivalent, use `rn_rdt = 1200`)
+
+.. code-block:: fortran
+   
+   rn_rdt      = 1200.     !  time step for the dynamics
+
+4. Optional, in order to increase the number of MPI communication for benchmark purposes:
+   you can change the number of sub-timesteps computed in the time-splitting scheme each iteration.
+   First change the list of active CPP keys for your experiment,
+   in `cfgs/"your configuration name"/cpp_"your configuration name".fcm`:
+   replace ``key_dynspg_flt by key_dynspg_ts`` and recompile/create your executable again
+   
+   .. code-block:: fortran
+   
+   makenemo [...] add_key 'key_dynspg_ts' del_key 'key_dynspg_flt'
+
+In your ``namelist_cfg`` file, edit the &namsplit namelist by adding the following line: 
+
+.. code-block:: fortran
+   
+   nn_baro       =    30               !  Number of iterations of barotropic mode/
+
+``nn_baro = 30`` is a kind of minimum (we usually use 30 to 60).
+So than increasing the ``nn_baro`` value will increase the number of MPI communications.
+
+The GYRE CPP keys, namelists and scripts can be explored in the ``GYRE`` configuration directory
+(``./cfgs/GYRE`` and ``./cfgs/GYRE/EXP00``).
+
+Find monthly mean outputs of 1 year run here:
+http://prodn.idris.fr/thredds/catalog/ipsl_public/reee451/NEMO_OUT/GYRE/catalog.html
+
+ORCA2_ICE_PISCES
+----------------
+
+ORCA is the generic name given to global ocean configurations.
+Its specificity lies on the horizontal curvilinear mesh used to overcome the North Pole singularity found for
+geographical meshes.
+SI3 (Sea Ice Integrated Initiative) is a thermodynamic-dynamic sea ice model specifically designed for
+climate studies.
+A brief description of the model is given here.
+
+:underline:`Space-time domain`
+
+The horizontal resolution available through the standard configuration is ORCA2.
+It is based on a 2 degrees Mercator mesh, (i.e. variation of meridian scale factor as cosinus of the latitude).
+In the northern hemisphere the mesh has two poles so that the ratio of anisotropy is nearly one everywhere.
+The mean grid spacing is about 2/3 of the nominal value: for example it is 1.3 degrees for ORCA2.
+Other resolutions (ORCA4, ORCA05 and ORCA025) are running or under development within specific projects.
+In the coarse resolution version (i.e. ORCA2 and ORCA4) the meridional grid spacing is increased near
+the equator to improve the equatorial dynamics.
+Figures in pdf format of mesh and bathymetry can be found and downloaded here.
+The sea-ice model runs on the same grid.
+
+The vertical domain spreads from the surface to a depth of 5000m.
+There are 31 levels, with 10 levels in the top 100m.
+The vertical mesh is deduced from a mathematical function of z ([[AttachmentNum(1)]]).
+The ocean surface corresponds to the w-level k=1, and the ocean bottom to the w-level k=31.
+The last T-level (k=31) is thus always in the ground.The depths of the vertical levels and
+the associated scale factors can be viewed.
+Higher vertical resolution is used in ORCA025 and ORCA12 (see `DRAKKAR project <http://www.drakkar-ocean.eu>`_).
+
+The time step depends on the resolution. It is 1h36' for ORCA2 so that there is 15 time steps in one day.
+
+:underline:`Ocean Physics (for ORCA2)`
+
+- horizontal diffusion on momentum: the eddy viscosity coefficient depends on the geographical position.
+  It is taken as 40000 $m^2/s$, reduced in the equator regions (2000 $m^2/s$) excepted near the western boundaries.
+- isopycnal diffusion on tracers: the diffusion acts along the isopycnal surfaces (neutral surface) with
+  a eddy diffusivity coefficient of 2000 $m^2/s$.
+- Eddy induced velocity parametrization with a coefficient that depends on the growth rate of
+  baroclinic instabilities (it usually varies from 15 $m^2/s$ to 3000 $m^2/s$).
+- lateral boundary conditions : zero fluxes of heat and salt and no-slip conditions are applied through
+  lateral solid boundaries.
+- bottom boundary condition : zero fluxes of heat and salt are applied through the ocean bottom.
+  The Beckmann [19XX] simple bottom boundary layer parameterization is applied along continental slopes.
+  A linear friction is applied on momentum.
+- convection: the vertical eddy viscosity and diffusivity coefficients are increased to 1 $m^2/s$ in case of
+  static instability.
+- forcings: the ocean receives heat, freshwater, and momentum fluxes from the atmosphere and/or the sea-ice.
+  The solar radiation penetrates the top meters of the ocean.
+  The downward irradiance I(z) is formulated with two extinction coefficients [Paulson and Simpson, 1977],
+  whose values correspond to a Type I water in Jerlov's classification (i.e the most transparent water)
+
+ORCA2_ICE_PISCES is a reference configuration with the following characteristics:
+
+- global ocean configuration
+- based on a tri-polar ORCA grid, with a 2° horizontal resolution
+- 31 vertical levels
+- forced with climatological surface fields
+- coupled to the sea-ice model SI3.
+- coupled to TOP passive tracer transport module and `PISCES biogeochemical model`_.
+
+:underline:`AGRIF demonstrator`
+
+| From the ``ORCA2_ICE_PISCES`` configuration, a demonstrator using AGRIF nesting can be activated.
+  It includes the global ``ORCA2_ICE_PISCES`` configuration and a nested grid in the Agulhas region.
+| To set up this configuration, after extracting NEMO:
+
+- Build your AGRIF configuration directory from ORCA2_ICE_PISCES, with the key_agrif CPP key activated:
+
+.. code-block:: console
+                
+	$ ./makenemo -r 'ORCA2_ICE_PISCES' -n 'AGRIF' add_key 'key_agrif'
+
+- Using the ``ORCA2_ICE_PISCES`` input files and namelist, AGRIF test configuration is ready to run
+
+:underline:`On-The-Fly Interpolation`
+
+| NEMO allows to use the interpolation on the fly option allowing to interpolate input data during the run.
+  If you want to use this option you need files giving informations on weights, which have been created.
+| You can find at http://prodn.idris.fr/thredds/catalog/ipsl_public/reee512/ORCA2_ONTHEFLY/WEIGHTS/catalog.html
+  2 weights files `bil_weights` for scalar field (bilinear interpolation) and `bic_weights` for
+  vector field (bicubic interpolation).
+| The data files used are `COREII forcing <http://data1.gdfl.noaa.gov/nomads/forms/mom4/COREv2>`_ extrapolated on
+  continents, ready to be used for on the fly option:
+  `COREII`_ forcing files extrapolated on continents
+
+ORCA2_OFF_PISCES
+----------------
+
+``ORCA2_OFF_PISCES`` uses the ORCA2 configuration in which the `PISCES biogeochemical model`_ has been activated in
+standalone using the dynamical fields that are pre calculated.
+
+See `ORCA2_ICE_PISCES`_ for general description of ORCA2.
+
+The input files for PISCES are needed, in addition the dynamical fields are used as input.
+They are coming from a 2000 years of an ORCA2_LIM climatological run using ERA40 atmospheric forcing.
+
+ORCA2_OFF_TRC
+-------------
+
+``ORCA2_OFF_TRC`` uses the ORCA2_LIM configuration in which the tracer passive transport module TOP has been
+activated in standalone using the dynamical fields that are pre calculated.
+
+See `ORCA2_ICE_PISCES`_ for general description of ORCA2.
+
+In ``namelist_top_cfg``, different passive tracers can be activated ( cfc11, cfc12, sf6, c14, age ) or my-trc,
+a user-defined tracer.
+
+The dynamical fields are used as input, they are coming from a 2000 years of an ORCA2_LIM climatological run using
+ERA40 atmospheric forcing.
+
+ORCA2_SAS_ICE
+-------------
+
+``ORCA2_SAS_ICE`` is a demonstrator of the SAS ( Stand-alone Surface module ) based on ORCA2_LIM configuration.
+
+The standalone surface module allows surface elements such as sea-ice, iceberg drift and surface fluxes to
+be run using prescribed model state fields.
+For example, it can be used to inter-compare different bulk formulae or adjust the parameters of
+a given bulk formula
+
+See `ORCA2_ICE_PISCES`_ for general description of ORCA2.
+
+Same input files as `ORCA2_ICE_PISCES`_ are needed plus fields from a previous ORCA2_LIM run.
+
+More informations on input and configuration files in `NEMO manual`_.
+
+SPITZ12
+-------
+
+``SPITZ12``
+
+Unsupported configurations
+==========================
+
+Other configurations are developed and used by some projects with "NEMO inside",
+these projects are welcome to publicize it here: http://www.nemo-ocean.eu/projects/add-project
+
+:underline:`Obviously these "projects configurations" are not under the NEMO System Team's responsibility`.
+
+.. _regional model:               http://www.tandfonline.com/doi/pdf/10.1080/1755876X.2012.11020128
+.. _AMM12_v4.0.tar:               http://prodn.idris.fr/thredds/fileServer/ipsl_public/romr005/Online_forcing_archives/AMM12_v4.0.tar
+.. _PISCES biogeochemical model:  http://www.geosci-model-dev.net/8/2465/2015
+.. _INPUTS_PISCES_v4.0.tar:       http://prodn.idris.fr/thredds/fileServer/ipsl_public/romr005/Online_forcing_archives/INPUTS_PISCES_v4.0.tar
+.. _ORCA2_OFF_v4.0.tar:           http://prodn.idris.fr/thredds/fileServer/ipsl_public/romr005/Online_forcing_archives/ORCA2_OFF_v4.0.tar
+.. _ORCA2_ICE_v4.0.tar:           http://prodn.idris.fr/thredds/fileServer/ipsl_public/romr005/Online_forcing_archives/ORCA2_ICE_v4.0.tar
+.. _INPUTS_SAS_v4.0.tar:          http://prodn.idris.fr/thredds/fileServer/ipsl_public/romr005/Online_forcing_archives/INPUTS_SAS_v4.0.tar
+.. _INPUTS_C1D_PAPA_v4.0.tar:     http://prodn.idris.fr/thredds/fileServer/ipsl_public/romr005/Online_forcing_archives/INPUTS_C1D_PAPA_v4.0.tar
+.. _Reffray 2015:                 http://www.geosci-model-dev.net/8/69/2015
+.. _COREII:                       http://prodn.idris.fr/thredds/catalog/ipsl_public/reee512/ORCA2_ONTHEFLY/FILLED_FILES/catalog.html
+.. _SPITZ12_v4.0.tar:             http://prodn.idris.fr/thredds/fileServer/ipsl_public/romr005/Online_forcing_archives/SPITZ12_v4.0.tar
+.. _AGRIF_DEMO_v4.0.tar:          http://prodn.idris.fr/thredds/fileServer/ipsl_public/romr005/Online_forcing_archives/AGRIF_DEMO_v4.0.tar
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/README.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/README.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/README.rst	(revision 10345)
@@ -0,0 +1,104 @@
+******************
+Diagnostics (XIOS)
+******************
+
+.. contents::
+	:local:
+
+| Output of diagnostics in NEMO is usually done using XIOS.
+  This is an efficient way of writing diagnostics because the time averaging, file writing and even
+  some simple arithmetic or regridding is carried out in parallel to the NEMO model run.
+| This page gives a basic introduction to using XIOS with NEMO.
+  Much more information is available from the XIOS homepage above and from the `NEMO manual`_.
+
+Use of XIOS for diagnostics is activated using the pre-compiler key ``key_iomput``.
+The default version of XIOS is the 2.0 release. 
+
+Extracting and installing XIOS
+==============================
+
+1. Install the NetCDF4 library.
+   If you want to use single file output you will need to compile the HDF & NetCDF libraries to allow parallel IO.
+2. Download the version of XIOS that you wish to use.
+   The recommended version is now XIOS 2.0:
+   
+	.. code-block:: console
+
+		$ svn co ​http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/branchs/xios-2.0 xios-2.0
+
+	and follow the instructions in :xios:`XIOS documentation <wiki/documentation>` to compile it.
+	If you find problems at this stage, support can be found by subscribing to the `XIOS mailing list
+	<http://forge.ipsl.jussieu.fr/mailman/listinfo.cgi/xios-users>`_
+	and sending a mail message to it. 
+
+Namelists
+=========
+
+XIOS is controlled using xml input files that should be copied to your model run directory before
+running the model.
+The exact setup differs slightly between 1.0 and 2.0 releases.
+
+An ``iodef.xml`` file is still required in the run directory.
+For XIOS 2.0 the ``field_def.xml`` file has been further split into ``field_def-oce.xml`` (for physics),
+``field_def-ice.xml`` (for ice) and ``field_def-bgc.xml`` (for biogeochemistry).
+Also the definition of the output files has been moved from the ``iodef.xml`` file into
+separate ``file_definition.xml`` files which are included in the ``iodef.xml`` file.
+Note that the ``domain_def.xml`` file is also different for XIOS 2.0.
+
+Modes
+=====
+
+Detached Mode
+-------------
+
+In detached mode the XIOS executable is executed on separate cores from the NEMO model.
+This is the recommended method for using XIOS for realistic model runs.
+To use this mode set ``using_server`` to ``true`` at the bottom of the ``iodef.xml`` file:
+
+.. code-block:: xml
+
+	<variable id="using_server" type="boolean">true</variable>
+
+Make sure there is a copy (or link to) your XIOS executable in the working directory and
+in your job submission script allocate processors to XIOS.
+
+Attached Mode
+-------------
+
+In attached mode XIOS runs on each of the cores used by NEMO.
+This method is less efficient than the detached mode but can be more convenient for testing or
+with small configurations.
+To activate this mode simply set ``using_server`` to false in the ``iodef.xml`` file
+
+.. code-block:: xml
+
+	<variable id="using_server" type="boolean">false</variable>
+
+and don't allocate any cores to XIOS.
+Note that due to the different domain decompositions between XIOS and NEMO if
+the total number of cores is larger than the number of grid points in the j direction then the model run will fail.
+
+Adding new diagnostics
+======================
+
+If you want to add a NEMO diagnostic to the NEMO code you will need to do the following:
+
+1. Add any necessary code to calculate you new diagnostic in NEMO
+2. Send the field to XIOS using ``CALL iom_put( 'field_id', variable )`` where ``field_id`` is a unique id for
+   your new diagnostics and variable is the fortran variable containing the data.
+   This should be called at every model timestep regardless of how often you want to output the field.
+   No time averaging should be done in the model code. 
+3. If it is computationally expensive to calculate your new diagnostic you should also use "iom_use" to
+   determine if it is requested in the current model run. For example,
+   
+	.. code-block:: fortran
+
+		IF iom_use('field_id') THEN
+		   !Some expensive computation
+	   	!...
+		   !...
+	   	iom_put('field_id', variable)
+		ENDIF
+
+4. Add a variable definition to the ``field_def.xml`` (or ``field_def-???.xml``) file
+5. Add the variable to the ``iodef.xml`` or ``file_definition.xml`` file.
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/field_def_nemo-pisces.xml
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/field_def_nemo-pisces.xml	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/field_def_nemo-pisces.xml	(revision 10345)
@@ -115,4 +115,49 @@
 
      </field_group>
+
+     <!-- SEDIMENT variables on T sediment grid  -->
+     <field_group id="sed_T" grid_ref="grid_T_3DS">
+       <field id="SedDIC"          long_name="Dissolved inorganic Concentration"        unit="mmol/m3" />
+       <field id="SedAlkalini"     long_name="Total Alkalinity Concentration"           unit="mmol/m3" />
+       <field id="SedO2"           long_name="Oxygen Concentration"                     unit="mmol/m3" />
+       <field id="SedCaCO3"        long_name="Calcite Concentration"                    unit="%" />
+       <field id="SedPOS"          long_name="Semi-ref POC Concentration"               unit="%" />
+       <field id="SedPOR"          long_name="Refractory POC Concentration"             unit="%" />
+       <field id="SedPO4"          long_name="Phosphate Concentration"                  unit="mmol/m3" />
+       <field id="SedPOC"          long_name="Labile POC Concentration"                 unit="%" />
+       <field id="SedSil"          long_name="Silicate Concentration"                   unit="mmol/m3" />
+       <field id="SedFe2"          long_name="Fe2+ Concentration"                       unit="mmol/m3" />
+       <field id="SedBSi"          long_name="Biogenic Silicate Concentration"          unit="%" />
+       <field id="SedNO3"          long_name="Nitrate Concentration"                    unit="mmol/m3" />
+       <field id="SedNH4"          long_name="Ammonium Concentration"                   unit="mmol/m3" />
+       <field id="SedH2S"          long_name="H2S Concentration"                        unit="mmol/m3" />
+       <field id="SedSO4"          long_name="SO4 Concentration"                        unit="mmol/m3" />
+       <field id="SedClay"         long_name="Clay Concentration"                       unit="%" />
+       <field id="SedFeO"          long_name="Fe(OH)3 Concentration"                    unit="%" />
+       <field id="SedFeS"          long_name="FeS Concentration"                        unit="%" />
+       <field id="SedpH"           long_name="PH"                                       unit="1"          />
+       <field id="SedCO3por"       long_name="Bicarbonates"                             unit="mol/m3" />
+     </field_group>
+
+     <!-- SEDIMENT additional variables on T sediment grid  -->
+     <field_group id="Diag_S" grid_ref="grid_T_2D">
+       <field id="FlxSi"       long_name="Si sediment flux"                        unit="mol/cm2/s"     />
+       <field id="FlxO2"       long_name="O2 sediment flux"                        unit="mol/cm2/s"     />
+       <field id="FlxDIC"      long_name="DIC sediment flux"                       unit="mol/cm2/s"     />
+       <field id="FlxNO3"      long_name="NO3 sediment flux"                       unit="mol/cm2/s"     />
+       <field id="FlxPO4"      long_name="PO4 sediment flux"                       unit="mol/cm2/s"     />
+       <field id="FlxAlkalini" long_name="Alkalinity sediment flux"                unit="mol/cm2/s"     />
+       <field id="FlxNH4"      long_name="Ammonium sediment flux"                  unit="mol/cm2/s"     />
+       <field id="FlxH2S"      long_name="H2S sediment flux"                       unit="mol/cm2/s"     />
+       <field id="FlxSO4"      long_name="SO4 sediment flux"                       unit="mol/cm2/s"     />
+       <field id="FlxFe2"      long_name="Fe2+ sediment flux"                      unit="mol/cm2/s"     />
+       <field id="Flxtot"      long_name="Sediment net burial rate"                unit="cm/s"     />
+       <field id="dzdep"       long_name="Sedimentation rate"                      unit="cm/s"     />
+       <field id="sflxclay"    long_name="Clay sedimentation rate"                 unit="g/m2/s"     />
+       <field id="sflxcal"     long_name="Calcite sedimentation rate"              unit="mol/m2/s"     />
+       <field id="sflxbsi"     long_name="BSi Sedimentation rate"                  unit="mol/m2/s"     />
+       <field id="sflxpoc"     long_name="POC Sedimentation rate"                  unit="mol/m2/s"     />
+       <field id="sflxfeo"     long_name="Fe(OH)3 Sedimentation rate"              unit="mol/m2/s"     />
+</field_group>
 
      <!-- PISCES additional diagnostics on T grid  -->
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/grid_def_nemo.xml
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/grid_def_nemo.xml	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/grid_def_nemo.xml	(revision 10345)
@@ -15,4 +15,9 @@
          <domain id="grid_T" />
          <axis id="deptht" />
+       </grid>
+        <!--  -->
+       <grid id="grid_T_3DS" >
+         <domain id="grid_T" />
+         <axis id="profsed" />
        </grid>
         <!--  -->
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/namelist_pisces_ref
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/namelist_pisces_ref	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/namelist_pisces_ref	(revision 10345)
@@ -17,4 +17,5 @@
   ln_p5z    = .false.        !  PISCES QUOTA model used
   ln_ligand = .false.        !  Enable  organic ligands
+  ln_sediment = .false.      !  Enable sediment module
 /
 !-----------------------------------------------------------------------
@@ -62,5 +63,5 @@
 /
 !-----------------------------------------------------------------------
-&namp4zice     !   parameters for nutrient limitations for PISCES std  - ln_p4z
+&namp4zlim     !   parameters for nutrient limitations for PISCES std  - ln_p4z
 !-----------------------------------------------------------------------
    concnno3   =  1.e-6    ! Nitrate half saturation of nanophytoplankton
@@ -86,5 +87,5 @@
 /
 !-----------------------------------------------------------------------
-&namp5zice     !   parameters for nutrient limitations PISCES QUOTA    - ln_p5z
+&namp5zlim     !   parameters for nutrient limitations PISCES QUOTA    - ln_p5z
 !-----------------------------------------------------------------------
    concnno3   =  3e-6     ! Nitrate half saturation of nanophytoplankton
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/namelist_ref
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/namelist_ref	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/namelist_ref	(revision 10345)
@@ -481,14 +481,14 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_cdg      =  'sdw_wave'             ,        1          , 'drag_coeff' ,  .true.  , .false., 'daily'   ,  ''             , ''       , ''
-   sn_usd      =  'sdw_wave'             ,        1          , 'u_sd2d'     ,  .true.  , .false., 'daily'   ,  ''             , ''       , ''
-   sn_vsd      =  'sdw_wave'             ,        1          , 'v_sd2d'     ,  .true.  , .false., 'daily'   ,  ''             , ''       , ''
-   sn_hsw      =  'sdw_wave'             ,        1          , 'hs'         ,  .true.  , .false., 'daily'   ,  ''             , ''       , ''
-   sn_wmp      =  'sdw_wave'             ,        1          , 'wmp'        ,  .true.  , .false., 'daily'   ,  ''             , ''       , ''
-   sn_wfr      =  'sdw_wave'             ,        1          , 'wfr'        ,  .true.  , .false., 'daily'   ,  ''             , ''       , ''
-   sn_wnum     =  'sdw_wave'             ,        1          , 'wave_num'   ,  .true.  , .false., 'daily'   ,  ''             , ''       , ''
-   sn_tauwoc   =  'sdw_wave'             ,        1          , 'wave_stress',  .true.  , .false., 'daily'   ,  ''             , ''       , ''
-   sn_tauwx    =  'sdw_wave'             ,        1          , 'wave_stress',  .true.  , .false., 'daily'   ,  ''             , ''       , ''
-   sn_tauwy    =  'sdw_wave'             ,        1          , 'wave_stress',  .true.  , .false., 'daily'   ,  ''             , ''       , ''
+   sn_cdg      =  'sdw_ecwaves_orca2'    ,        6          , 'drag_coeff' ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_usd      =  'sdw_ecwaves_orca2'    ,        6          , 'u_sd2d'     ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_vsd      =  'sdw_ecwaves_orca2'    ,        6          , 'v_sd2d'     ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_hsw      =  'sdw_ecwaves_orca2'    ,        6          , 'hs'         ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_wmp      =  'sdw_ecwaves_orca2'    ,        6          , 'wmp'        ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_wfr      =  'sdw_ecwaves_orca2'    ,        6          , 'wfr'        ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_wnum     =  'sdw_ecwaves_orca2'    ,        6          , 'wave_num'   ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_tauwoc   =  'sdw_ecwaves_orca2'    ,        6          , 'wave_stress',  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_tauwx    =  'sdw_ecwaves_orca2'    ,        6          , 'wave_stress',  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_tauwy    =  'sdw_ecwaves_orca2'    ,        6          , 'wave_stress',  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
 /
 !-----------------------------------------------------------------------
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namage
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namage	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namage	(revision 10345)
@@ -0,0 +1,6 @@
+!-----------------------------------------------------------------------
+&namage          !   AGE 
+!-----------------------------------------------------------------------
+   rn_age_depth      = 10            ! depth over which age tracer reset to zero
+   rn_age_kill_rate  = -0.000138888  !  = -1/7200 recip of relaxation timescale (s) for  age tracer shallower than age_depth
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namalb
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namalb	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namalb	(revision 10345)
@@ -0,0 +1,10 @@
+!------------------------------------------------------------------------------
+&namalb         !   albedo parameters
+!------------------------------------------------------------------------------
+   !                                  !                          !  obs range (cloud-sky)
+   rn_alb_sdry      =   0.85          !  dry snow albedo         :  0.85 -- 0.87
+   rn_alb_smlt      =   0.75          !  melting snow albedo     :  0.72 -- 0.82
+   rn_alb_idry      =   0.60          !  dry ice albedo          :  0.54 -- 0.65
+   rn_alb_imlt      =   0.50          !  bare puddled ice albedo :  0.49 -- 0.58
+   rn_alb_dpnd      =   0.27          !  ponded ice albedo       :  0.10 -- 0.30 
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namdia
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namdia	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namdia	(revision 10345)
@@ -0,0 +1,9 @@
+!------------------------------------------------------------------------------
+&namdia         !   Diagnostics
+!------------------------------------------------------------------------------
+   ln_icediachk     = .false.         !  check online the heat, mass & salt budgets (T) or not (F)
+   ln_icediahsb     = .false.         !  output the heat, mass & salt budgets (T) or not (F)
+   ln_icectl        = .false.         !  ice points output for debug (T or F)
+   iiceprt          =  10             !  i-index for debug
+   jiceprt          =  10             !  j-index for debug
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namdyn
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namdyn	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namdyn	(revision 10345)
@@ -0,0 +1,17 @@
+!------------------------------------------------------------------------------
+&namdyn         !   Ice dynamics
+!------------------------------------------------------------------------------
+   ln_dynFULL       = .true.          !  dyn.: full ice dynamics               (rheology + advection + ridging/rafting + correction)
+   ln_dynRHGADV     = .false.         !  dyn.: no ridge/raft & no corrections  (rheology + advection)
+   ln_dynADV        = .false.         !  dyn.: only advection w prescribed vel.(rn_uvice + advection)
+      rn_uice       =   0.00001       !        prescribed ice u-velocity
+      rn_vice       =   0.            !        prescribed ice v-velocity
+   rn_ishlat        =   2.            !  free slip (0) ; partial slip (0-2) ; no slip (2) ; strong slip (>2)
+   ln_landfast      = .false.         !  landfast ice parameterization (T or F)                           
+      rn_gamma      =   0.15          !     fraction of ocean depth that ice must reach to initiate landfast
+                                      !        recommended range: [0.1 ; 0.25]
+      rn_icebfr     =  10.            !     maximum bottom stress per unit area of contact [N/m2]                 
+                                      !        a very large value ensures ice velocity=0 even with a small contact area
+                                      !        recommended range: ?? (should be greater than atm-ice stress => >0.1 N/m2)
+      rn_lfrelax    =   1.e-5         !     relaxation time scale to reach static friction [s-1]
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namdyn_rdgrft
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namdyn_rdgrft	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namdyn_rdgrft	(revision 10345)
@@ -0,0 +1,25 @@
+!------------------------------------------------------------------------------
+&namdyn_rdgrft  !   Ice ridging/rafting
+!------------------------------------------------------------------------------
+          ! -- ice_rdgrft_strength -- !
+   ln_str_H79       = .true.          !  ice strength param.: Hibler_79   => P = pstar*<h>*exp(-c_rhg*A)                      
+      rn_pstar      =   2.0e+04       !     ice strength thickness parameter [N/m2]
+      rn_crhg       =   20.0          !     ice strength conc. parameter (-)
+                   ! -- ice_rdgrft -- !
+   rn_csrdg         =   0.5           !  fraction of shearing energy contributing to ridging
+              ! -- ice_rdgrft_prep -- !
+   ln_partf_lin     = .false.         !  Linear ridging participation function (Thorndike et al, 1975)
+      rn_gstar      =   0.15          !     fractional area of thin ice being ridged 
+   ln_partf_exp     = .true.          !  Exponential ridging participation function (Lipscomb, 2007)
+      rn_astar      =   0.03          !     exponential measure of ridging ice fraction [set to 0.05 if hstar=100]
+   ln_ridging       = .true.          !  ridging activated (T) or not (F)
+      rn_hstar      =  25.0           !     determines the maximum thickness of ridged ice [m] (Hibler, 1980)
+      rn_porordg    =   0.3           !     porosity of newly ridged ice (Lepparanta et al., 1995)
+      rn_fsnwrdg    =   0.5           !     snow volume fraction that survives in ridging
+      rn_fpndrdg    =   1.0           !     pond fraction that survives in ridging (small a priori)
+   ln_rafting       = .true.          !  rafting activated (T) or not (F)
+      rn_hraft      =   0.75          !     threshold thickness for rafting [m]
+      rn_craft      =   5.0           !     squeezing coefficient used in the rafting function
+      rn_fsnwrft    =   0.5           !     snow volume fraction that survives in rafting
+      rn_fpndrft    =   1.0           !     pond fraction that survives in rafting (0.5 a priori)
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namdyn_rhg
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namdyn_rhg	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namdyn_rhg	(revision 10345)
@@ -0,0 +1,11 @@
+!------------------------------------------------------------------------------
+&namdyn_rhg     !   Ice rheology
+!------------------------------------------------------------------------------
+   ln_rhg_EVP       = .true.          !  EVP rheology
+      ln_aEVP       = .true.          !     adaptive rheology (Kimmritz et al. 2016 & 2017)
+      rn_creepl     =   2.0e-9        !     creep limit [1/s]
+      rn_ecc        =   2.0           !     eccentricity of the elliptical yield curve          
+      nn_nevp       = 120             !     number of EVP subcycles                             
+      rn_relast     =   0.333         !     ratio of elastic timescale to ice time step: Telast = dt_ice * rn_relast 
+                                      !        advised value: 1/3 (rn_nevp=120) or 1/9 (rn_nevp=300)
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namforcing
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namforcing	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namforcing	(revision 10345)
@@ -0,0 +1,13 @@
+!------------------------------------------------------------------------------
+&namforcing     !   Ice surface forcing
+!------------------------------------------------------------------------------
+   rn_cio           =   5.0e-03       !  ice-ocean drag coefficient (-)
+   rn_blow_s        =   0.66          !  mesure of snow blowing into the leads
+                                      !     = 1 => no snow blowing, < 1 => some snow blowing
+   nn_flxdist       =  -1             !  Redistribute heat flux over ice categories
+                                      !     =-1  Do nothing (needs N(cat) fluxes)
+                                      !     = 0  Average N(cat) fluxes then apply the average over the N(cat) ice
+                                      !     = 1  Average N(cat) fluxes then redistribute over the N(cat) ice using T-ice and albedo sensitivity
+                                      !     = 2  Redistribute a single flux over categories
+   nice_jules       = 0               !  Jules coupling (0=OFF, 1=EMULATED, 2=ACTIVE)
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namini
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namini	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namini	(revision 10345)
@@ -0,0 +1,25 @@
+!------------------------------------------------------------------------------
+&namini         !   Ice initialization
+!------------------------------------------------------------------------------
+   ln_iceini        = .true.          !  activate ice initialization (T) or not (F)
+   ln_iceini_file   = .false.         !  netcdf file provided for initialization (T) or not (F)
+   rn_thres_sst     =   2.0           !  max delta temp. above Tfreeze with initial ice = (sst - tfreeze)
+   rn_hts_ini_n     =   0.3           !  initial real snow thickness (m), North
+   rn_hts_ini_s     =   0.3           !        "            "             South
+   rn_hti_ini_n     =   3.0           !  initial real ice thickness  (m), North
+   rn_hti_ini_s     =   1.0           !        "            "             South
+   rn_ati_ini_n     =   0.9           !  initial ice concentration   (-), North
+   rn_ati_ini_s     =   0.9           !        "            "             South
+   rn_smi_ini_n     =   6.3           !  initial ice salinity     (g/kg), North
+   rn_smi_ini_s     =   6.3           !        "            "             South
+   rn_tmi_ini_n     = 270.            !  initial ice/snw temperature (K), North
+   rn_tmi_ini_s     = 270.            !        "            "             South
+
+   sn_hti = 'Ice_initialization'    , -12 ,'hti'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_hts = 'Ice_initialization'    , -12 ,'hts'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_ati = 'Ice_initialization'    , -12 ,'ati'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_tsu = 'Ice_initialization'    , -12 ,'tsu'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_tmi = 'Ice_initialization'    , -12 ,'tmi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_smi = 'Ice_initialization'    , -12 ,'smi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   cn_dir ='./'
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namitd
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namitd	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namitd	(revision 10345)
@@ -0,0 +1,9 @@
+!------------------------------------------------------------------------------
+&namitd         !   Ice discretization
+!------------------------------------------------------------------------------
+   ln_cat_hfn       = .true.          !  ice categories are defined by a function following rn_himean**(-0.05)
+      rn_himean     =   2.0           !  expected domain-average ice thickness (m)
+   ln_cat_usr       = .false.         !  ice categories are defined by rn_catbnd below (m)
+      rn_catbnd     =   0.,0.45,1.1,2.1,3.7,6.0  
+   rn_himin         =   0.1           !  minimum ice thickness (m) used in remapping
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/nampar
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/nampar	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/nampar	(revision 10345)
@@ -0,0 +1,18 @@
+!------------------------------------------------------------------------------
+&nampar         !   Generic parameters
+!------------------------------------------------------------------------------
+   jpl              =   5             !  number of ice  categories
+   nlay_i           =   2             !  number of ice  layers
+   nlay_s           =   1             !  number of snow layers (only 1 is working)
+   nn_virtual_itd   =   0             !  virtual ITD mono-category parameterizations (1-3 => jpl = 1 only) or not (0)
+                                      !     2: activate enhanced thermal conductivity only --- temporary option
+                                      !     3: activate virtual thin ice melting only      ---  temporary option
+   ln_icedyn        = .true.          !  ice dynamics (T) or not (F)
+   ln_icethd        = .true.          !  ice thermo   (T) or not (F)
+   rn_amax_n        =   0.997         !  maximum tolerated ice concentration NH
+   rn_amax_s        =   0.997         !  maximum tolerated ice concentration SH
+   cn_icerst_in     = "restart_ice"   !  suffix of ice restart name (input)
+   cn_icerst_out    = "restart_ice"   !  suffix of ice restart name (output)
+   cn_icerst_indir  = "."             !  directory to read   input ice restarts
+   cn_icerst_outdir = "."             !  directory to write output ice restarts
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd	(revision 10345)
@@ -0,0 +1,8 @@
+!------------------------------------------------------------------------------
+&namthd         !   Ice thermodynamics
+!------------------------------------------------------------------------------
+   ln_icedH         = .true.          !  activate ice thickness change from growing/melting (T) or not (F)
+   ln_icedA         = .true.          !  activate lateral melting param. (T) or not (F)
+   ln_icedO         = .true.          !  activate ice growth in open-water (T) or not (F)
+   ln_icedS         = .true.          !  activate brine drainage (T) or not (F)
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_da
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_da	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_da	(revision 10345)
@@ -0,0 +1,11 @@
+!------------------------------------------------------------------------------
+&namthd_da      !   Ice lateral melting
+!------------------------------------------------------------------------------
+   rn_beta          =   1.0           !  coef. beta for lateral melting param. Recommended range=[0.8-1.2]
+                                      !   => decrease = more melt and melt peaks toward higher concentration (A~0.5 for beta=1 ; A~0.8 for beta=0.2)
+                                      !      0.3 = best fit for western Fram Strait and Antarctica
+                                      !      1.4 = best fit for eastern Fram Strait      
+   rn_dmin          =   8.            !  minimum floe diameter for lateral melting param. Recommended range=[6-10]
+                                      !   => 6  vs 8m = +40% melting at the peak (A~0.5)
+                                      !      10 vs 8m = -20% melting
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_do
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_do	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_do	(revision 10345)
@@ -0,0 +1,9 @@
+!------------------------------------------------------------------------------
+&namthd_do      !   Ice growth in open water
+!------------------------------------------------------------------------------
+   rn_hinew         =   0.1           !  thickness for new ice formation in open water (m), must be larger than rn_hnewice
+   ln_frazil        = .false.         !  Frazil ice parameterization (ice collection as a function of wind)
+      rn_maxfraz    =   1.0           !     maximum fraction of frazil ice collecting at the ice base
+      rn_vfraz      =   0.417         !     thresold drift speed for frazil ice collecting at the ice bottom (m/s)
+      rn_Cfraz      =   5.0           !     squeezing coefficient for frazil ice collecting at the ice bottom
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_pnd
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_pnd	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_pnd	(revision 10345)
@@ -0,0 +1,10 @@
+!------------------------------------------------------------------------------
+&namthd_pnd     !   Melt ponds
+!------------------------------------------------------------------------------
+   ln_pnd_H12       = .false.         !  activate evolutive melt ponds (from Holland et al 2012)
+      ln_pnd_fwb    = .false.         !     melt ponds store freshwater or not
+   ln_pnd_CST       = .false.         !  activate constant melt ponds
+      rn_apnd       =   0.2           !     prescribed pond fraction, at Tsu=0
+      rn_hpnd       =   0.05          !     prescribed pond depth, at Tsu=0
+   ln_pnd_alb       = .false.         !  melt ponds affect albedo or not
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_sal
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_sal	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_sal	(revision 10345)
@@ -0,0 +1,15 @@
+!------------------------------------------------------------------------------
+&namthd_sal     !   Ice salinity
+!------------------------------------------------------------------------------
+   nn_icesal        =   2             !  ice salinity option
+                                      !     1: constant ice salinity (S=rn_icesal)
+                                      !     2: varying salinity parameterization S(z,t)
+                                      !     3: prescribed salinity profile S(z), Schwarzacher, 1959
+   rn_icesal        =   4.            !    (nn_icesal=1) ice salinity (g/kg)
+   rn_sal_gd        =   5.            !  restoring ice salinity, gravity drainage (g/kg)
+   rn_time_gd       =   1.73e+6       !  restoring time scale, gravity drainage  (s)
+   rn_sal_fl        =   2.            !  restoring ice salinity, flushing (g/kg)
+   rn_time_fl       =   8.64e+5       !  restoring time scale, flushing (s)
+   rn_simax         =  20.            !  maximum tolerated ice salinity (g/kg)
+   rn_simin         =   0.1           !  minimum tolerated ice salinity (g/kg)
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_zdf
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_zdf	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namthd_zdf	(revision 10345)
@@ -0,0 +1,10 @@
+!------------------------------------------------------------------------------
+&namthd_zdf     !   Ice heat diffusion
+!------------------------------------------------------------------------------
+   ln_zdf_BL99      = .true.          !  Heat diffusion follows Bitz and Lipscomb 1999
+   ln_cndi_U64      = .false.         !  sea ice thermal conductivity: k = k0 + beta.S/T            (Untersteiner, 1964)
+   ln_cndi_P07      = .true.          !  sea ice thermal conductivity: k = k0 + beta1.S/T - beta2.T (Pringle et al., 2007)
+   rn_cnd_s         =   0.31          !  thermal conductivity of the snow (0.31 W/m/K, Maykut and Untersteiner, 1971)
+                                      !     Obs: 0.1-0.5 (Lecomte et al, JAMES 2013)
+   rn_kappa_i       =   1.0           !  radiation attenuation coefficient in sea ice [1/m]
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc	(revision 10345)
@@ -0,0 +1,23 @@
+!-----------------------------------------------------------------------
+&namtrc          !   tracers definition
+!-----------------------------------------------------------------------
+   jp_bgc        =  0           !  Number of passive tracers of the BGC model
+   !
+   ln_pisces     =  .false.     !  Run PISCES BGC model 
+   ln_my_trc     =  .false.     !  Run MY_TRC BGC model
+   ln_age        =  .false.     !  Run the sea water age tracer
+   ln_cfc11      =  .false.     !  Run the CFC11 passive tracer
+   ln_cfc12      =  .false.     !  Run the CFC12 passive tracer
+   ln_sf6        =  .false.     !  Run the SF6 passive tracer
+   ln_c14        =  .false.     !  Run the Radiocarbon passive tracer
+   !
+   ln_trcdta     =  .false.  !  Initialisation from data input file (T) or not (F)
+   ln_trcdmp     =  .false.  !  add a damping termn (T) or not (F)
+   ln_trcdmp_clo =  .false.  !  damping term (T) or not (F) on closed seas
+   !
+   jp_dia3d      = 0         ! Number of 3D diagnostic variables
+   jp_dia2d      = 0         ! Number of 2D diagnostic variables
+   !_____________!___________!_________________________________________!____________!________________!
+   !             !    name   !           title of the field            !   units    ! init from file ! 
+!  sn_tracer(1)  = 'tracer  ', 'Tracer  Concentration                 ',   ' - '    ,   .false.
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_adv
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_adv	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_adv	(revision 10345)
@@ -0,0 +1,16 @@
+!-----------------------------------------------------------------------
+&namtrc_adv      !   advection scheme for passive tracer                (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_trcadv_OFF =  .false.  !  No passive tracer advection
+   ln_trcadv_cen =  .false.  !  2nd order centered scheme
+      nn_cen_h   =  4               !  =2/4, horizontal 2nd order CEN / 4th order CEN
+      nn_cen_v   =  4               !  =2/4, vertical   2nd order CEN / 4th order COMPACT
+   ln_trcadv_fct =  .false.  !  FCT scheme
+      nn_fct_h   =  2               !  =2/4, horizontal 2nd / 4th order 
+      nn_fct_v   =  2               !  =2/4, vertical   2nd / COMPACT 4th order 
+   ln_trcadv_mus =  .false.  !  MUSCL scheme
+      ln_mus_ups =  .false.         !  use upstream scheme near river mouths
+   ln_trcadv_ubs =  .false.  !  UBS scheme
+      nn_ubs_v   =  2               !  =2  , vertical 2nd order FCT
+   ln_trcadv_qck =  .false.  !  QUICKEST scheme
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_bc
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_bc	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_bc	(revision 10345)
@@ -0,0 +1,9 @@
+!----------------------------------------------------------------------
+&namtrc_bc       !   data for boundary conditions
+!-----------------------------------------------------------------------
+   cn_dir_sbc    =  './'     !  root directory for the location of SURFACE data files
+   cn_dir_cbc    =  './'     !  root directory for the location of COASTAL data files
+   cn_dir_obc    =  './'     !  root directory for the location of OPEN data files
+   ln_rnf_ctl    = .false.   !  Remove runoff dilution on tracers with absent river load
+   rn_bc_time    =  86400.   !  Time scaling factor for SBC and CBC data (seconds in a day)
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_bdy
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_bdy	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_bdy	(revision 10345)
@@ -0,0 +1,11 @@
+!----------------------------------------------------------------------
+&namtrc_bdy      !   Setup of tracer boundary conditions
+!-----------------------------------------------------------------------
+   cn_trc_dflt   = 'neumann' !  OBC applied by default to all tracers
+   cn_trc        = 'none'    !  Boundary conditions used for tracers with data files (selected in namtrc)
+
+   nn_trcdmp_bdy = 0         !  Use damping timescales defined in nambdy of namelist
+                             !  = 0 NO damping of tracers at open boudaries
+                             !  = 1 Only for tracers forced with external data
+                             !  = 2 Damping applied to all tracers
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_dmp
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_dmp	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_dmp	(revision 10345)
@@ -0,0 +1,8 @@
+!-----------------------------------------------------------------------
+&namtrc_dmp      !   passive tracer newtonian damping                   (ln_trcdmp=T)
+!-----------------------------------------------------------------------
+   nn_zdmp_tr    =    1      !  vertical   shape =0    damping throughout the water column
+                             !                   =1 no damping in the mixing layer (kz  criteria)
+                             !                   =2 no damping in the mixed  layer (rho crieria)
+   cn_resto_tr   = 'resto_tr.nc'    !  create a damping.coeff NetCDF file (=1) or not (=0)
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_dta
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_dta	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_dta	(revision 10345)
@@ -0,0 +1,9 @@
+!-----------------------------------------------------------------------
+&namtrc_dta      !    Initialisation from data input file
+!-----------------------------------------------------------------------
+!                !  file name        ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!                !                   !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_trcdta(1)  = 'data_TRC_nomask' ,        -12        ,  'TRC'    ,    .false.   , .true. , 'yearly'  , ''       , ''       , ''
+   !
+   cn_dir        =  './'     !  root directory for the location of the data files
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_ice
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_ice	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_ice	(revision 10345)
@@ -0,0 +1,8 @@
+!-----------------------------------------------------------------------
+&namtrc_ice      !    Representation of sea ice growth & melt effects
+!-----------------------------------------------------------------------
+   nn_ice_tr     =  -1       !  tracer concentration in sea ice 
+                             !    =-1 (no vvl: identical cc in ice and ocean / vvl: cc_ice = 0)
+                             !    = 0 (no vvl: cc_ice = zero / vvl: cc_ice = )
+                             !    = 1 prescribed to a namelist value (implemented in pisces only)
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_ldf
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_ldf	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_ldf	(revision 10345)
@@ -0,0 +1,10 @@
+!-----------------------------------------------------------------------
+&namtrc_ldf      !   lateral diffusion scheme for passive tracer        (default: NO selection)
+!-----------------------------------------------------------------------
+!                            !  Type of the operator:
+   ln_trcldf_OFF   =  .false.    !  No explicit diffusion
+   ln_trcldf_tra   =  .false.    !  use active tracer setting
+   !                         !  Coefficient (defined with namtra_ldf coefficient)
+   rn_ldf_multi    = 1.          !  multiplier of aht for TRC mixing coefficient
+   rn_fact_lap     = 1.          !  Equatorial enhanced zonal eddy diffusivity (lap only)
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_rad
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_rad	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_rad	(revision 10345)
@@ -0,0 +1,5 @@
+!-----------------------------------------------------------------------
+&namtrc_rad      !  treatment of negative concentrations 
+!-----------------------------------------------------------------------
+   ln_trcrad     =  .true.   !  artificially correct negative concentrations (T) or not (F)
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_run
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_run	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_run	(revision 10345)
@@ -0,0 +1,14 @@
+!-----------------------------------------------------------------------
+&namtrc_run      !   run information
+!-----------------------------------------------------------------------
+   nn_dttrc      =  1        !  time step frequency for passive sn_tracers
+   ln_top_euler  = .false.   !  use Euler time-stepping for TOP
+   ln_rsttr      = .false.   !  start from a restart file (T) or not (F)
+   nn_rsttr      =   0       !  restart control = 0 initial time step is not compared to the restart file value
+                             !                  = 1 do not use the value in the restart file
+                             !                  = 2 calendar parameters read in the restart file
+   cn_trcrst_in  = "restart_trc"   !  suffix of pass. sn_tracer restart name (input)
+   cn_trcrst_indir = "."           !  directory from which to read input passive tracer restarts
+   cn_trcrst_out = "restart_trc"   !  suffix of pass. sn_tracer restart name (output)
+   cn_trcrst_outdir = "."          !  directory to which to write output passive tracer restarts
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_trd
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_trd	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/namelists/namtrc_trd	(revision 10345)
@@ -0,0 +1,13 @@
+!-----------------------------------------------------------------------
+&namtrc_trd      !   diagnostics on tracer trends                       ('key_trdtrc')
+!                          or mixed-layer trends                        ('key_trdmld_trc')
+!----------------------------------------------------------------------
+   nn_trd_trc    =  5475     !  time step frequency and tracers trends
+   nn_ctls_trc   =   0       !  control surface type in mixed-layer trends (0,1 or n<jpk)
+   rn_ucf_trc    =   1       !  unit conversion factor (=1 -> /seconds ; =86400. -> /day)
+   ln_trdmld_trc_restart = .false. !  restart for ML diagnostics
+   ln_trdmld_trc_instant = .true.  !  flag to diagnose trends of instantantaneous or mean ML T/S
+   ln_trdtrc( 1) = .true.
+   ln_trdtrc( 2) = .true.
+   ln_trdtrc(23) = .true.
+/
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/Makefile
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/Makefile	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/Makefile	(revision 10345)
@@ -0,0 +1,20 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS    =
+SPHINXBUILD   = sphinx-build
+SPHINXPROJ    = NEMO
+SOURCEDIR     = source
+BUILDDIR      = build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/NEMO_guide.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/NEMO_guide.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/NEMO_guide.rst	(revision 10345)
@@ -0,0 +1,74 @@
+#################
+Quick Start Guide
+#################
+
+..
+	For headings markup, this convention is recommended from Python’s Style Guide
+	# with overline, for parts
+	* with overline, for chapters
+	=, for sections
+	-, for subsections
+	^, for subsubsections
+	", for paragraphs
+
+	'global.rst' contains a list of common directives (roles, substitutions and URL links)
+	It is loaded for each file thanks to 'rst_epilog' setting in 'conf.py'
+
+.. toctree::
+	:hidden:
+
+	release_notes.rst
+
+.. toctree::
+	:hidden:
+	:caption: Getting started
+
+	install
+	configurations
+	test_cases
+
+.. toctree::
+	:hidden:
+	:caption: Setup your configuration
+
+	setup
+	diagnostics
+	tools
+
+.. toctree::
+	:hidden:
+	:caption: Advanced use
+
+	zooms
+	coarsening
+	coupling
+	assimilation
+	tracers
+
+.. toctree::
+	:hidden:
+	:caption: Glossary
+
+	definitions
+
+.. include:: readme.rst
+
+.. Next headings markup acording to readme.rst
+
+How to cite NEMO
+================
+
+..	bibliography:: references.bib
+	:all:
+	:style: unsrt
+	:labelprefix: R
+
+Disclaimer
+==========
+
+The NEMO source code is freely available and distributed under CeCILL license
+(GNU GPL compatible - see ``./LICENSE``).
+
+You can use, modify and/or redistribute the software under its terms,
+but users are provided only with a limited warranty and the software's authors and
+the successive licensor's have only limited liability.
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_static/file_crs_def.xml
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_static/file_crs_def.xml	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_static/file_crs_def.xml	(revision 10345)
@@ -0,0 +1,80 @@
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+ <file_definition type="multiple_file" name="PATH_OUT/@expname@_@freq@" sync_freq="1d" min_digits="4">
+
+    <file_group id="1d" output_freq="1d"  split_freq="1d" output_level="10" enabled=".TRUE."> <!-- 1d files -->
+
+       <file id="file1" name_suffix="_gcrsT" description="ocean T grid variables" >
+          <field field_ref="e3t"          name="e3t"       />
+          <field field_ref="toce"         name="votemper"  operation="instant" freq_op="1d" > @toce_e3t / @e3t </field>
+          <field field_ref="soce"         name="vosaline"  operation="instant" freq_op="1d" > @soce_e3t / @e3t </field>
+          <field field_ref="mldkz5"       name="somixhgt"  />
+       </file>
+
+       <file id="file2" name_suffix="_gcrsU" description="ocean T grid variables" >
+          <field field_ref="e3u"       name="e3u"           />
+          <field field_ref="uoce"      name="uo"       operation="instant" freq_op="1d" > @uoce_e3u / @e3u </field>
+       </file>
+
+       <file id="file3" name_suffix="_gcrsV" description="ocean T grid variables" >
+          <field field_ref="e3v"       name="e3v"           />
+          <field field_ref="voce"      name="vo"       operation="instant" freq_op="1d" > @voce_e3v / @e3v </field>
+       </file>
+
+       <file id="file4" name_suffix="_gcrsW" description="ocean T grid variables" >
+          <field field_ref="woce"        name="woce"        />
+          <field field_ref="avt"         name="difvho"   />
+       </file>
+
+       <file id="file5" name_suffix="_gcrsC" description="ocean T grid variables" >
+          <field field_ref="Alkalini" operation="instant" freq_op="1d" > @Alkalini_E3T / @e3t </field>
+          <field field_ref="O2"       operation="instant" freq_op="1d" > @O2_E3T / @e3t </field>
+          <field field_ref="Si"       operation="instant" freq_op="1d" > @Si_E3T / @e3t </field>
+          <field field_ref="PHY"      operation="instant" freq_op="1d" > @PHY_E3T / @e3t </field>
+          <field field_ref="ZOO"      operation="instant" freq_op="1d" > @ZOO_E3T / @e3t </field>
+          <field field_ref="DOC"      operation="instant" freq_op="1d" > @DOC_E3T / @e3t </field>
+          <field field_ref="NCHL"     operation="instant" freq_op="1d" > @NCHL_E3T / @e3t </field>
+          <field field_ref="DCHL"     operation="instant" freq_op="1d" > @DCHL_E3T / @e3t </field>
+          <field field_ref="NO3"      operation="instant" freq_op="1d" > @NO3_E3T / @e3t </field>
+       </file>
+
+    </file_group>
+
+    <file_group id="1mo" output_freq="1mo"  split_freq="1mo" output_level="10" enabled=".TRUE."> <!-- 1d files -->
+
+       <file id="file6" name_suffix="_gcrsC" description="ocean T grid variables" >
+          <field field_ref="DIC"      operation="instant" freq_op="1mo" > @DIC_E3T / @e3t </field>
+          <field field_ref="Alkalini" operation="instant" freq_op="1mo" > @Alkalini_E3T / @e3t </field>
+          <field field_ref="O2"       operation="instant" freq_op="1mo" > @O2_E3T / @e3t </field>
+          <field field_ref="CaCO3"    operation="instant" freq_op="1mo" > @CaCO3_E3T / @e3t </field>
+          <field field_ref="PO4"      operation="instant" freq_op="1mo" > @PO4_E3T / @e3t </field>
+          <field field_ref="POC"      operation="instant" freq_op="1mo" > @POC_E3T / @e3t </field>
+          <field field_ref="Si"       operation="instant" freq_op="1mo" > @Si_E3T / @e3t </field>
+          <field field_ref="PHY"      operation="instant" freq_op="1mo" > @PHY_E3T / @e3t </field>
+          <field field_ref="ZOO"      operation="instant" freq_op="1mo" > @ZOO_E3T / @e3t </field>
+          <field field_ref="DOC"      operation="instant" freq_op="1mo" > @DOC_E3T / @e3t </field>
+          <field field_ref="PHY2"     operation="instant" freq_op="1mo" > @PHY2_E3T / @e3t </field>
+          <field field_ref="ZOO2"     operation="instant" freq_op="1mo" > @ZOO2_E3T / @e3t </field>
+          <field field_ref="DSi"      operation="instant" freq_op="1mo" > @DSi_E3T / @e3t </field>
+          <field field_ref="Fer"      operation="instant" freq_op="1mo" > @Fer_E3T / @e3t </field>
+          <field field_ref="BFe"      operation="instant" freq_op="1mo" > @BFe_E3T / @e3t </field>
+          <field field_ref="GOC"      operation="instant" freq_op="1mo" > @GOC_E3T / @e3t </field>
+          <field field_ref="SFe"      operation="instant" freq_op="1mo" > @SFe_E3T / @e3t </field>
+          <field field_ref="DFe"      operation="instant" freq_op="1mo" > @DFe_E3T / @e3t </field>
+          <field field_ref="GSi"      operation="instant" freq_op="1mo" > @GSi_E3T / @e3t </field>
+          <field field_ref="NFe"      operation="instant" freq_op="1mo" > @NFe_E3T / @e3t </field>
+          <field field_ref="NCHL"     operation="instant" freq_op="1mo" > @NCHL_E3T / @e3t </field>
+          <field field_ref="DCHL"     operation="instant" freq_op="1mo" > @DCHL_E3T / @e3t </field>
+          <field field_ref="NO3"      operation="instant" freq_op="1mo" > @NO3_E3T / @e3t </field>
+          <field field_ref="NH4"      operation="instant" freq_op="1mo" > @NH4_E3T / @e3t </field>
+       </file>
+
+    </file_group>
+
+
+ </file_definition>
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_static/file_def.xml
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_static/file_def.xml	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_static/file_def.xml	(revision 10345)
@@ -0,0 +1,111 @@
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files        default value="9.96921e+36"                                  =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="multiple_file" name="PATH_OUT/@expname@_@freq@" sync_freq="1d" min_digits="4" >
+    
+     
+      <file_group id="1d" output_freq="1d" split_freq="1d" output_level="10" enabled=".TRUE." >  <!-- 5d files -->  
+ 
+	<file id="file1" name_suffix="_gridT" description="ocean T grid variables" >
+          <field field_ref="e3t"          name="e3t"        />
+          <field field_ref="toce"         name="votemper"   operation="instant" freq_op="1d" > @toce_e3t / @e3t </field>
+        </file>
+
+	<file id="file2" name_suffix="_gridS" description="ocean T grid variables" >
+          <field field_ref="soce"         name="vosaline"   operation="instant" freq_op="1d" > @soce_e3t / @e3t </field>
+        </file>
+
+	<file id="file3" name_suffix="_grid2D" description="ocean T grid variables" >
+	  <field field_ref="mldkz5"       name="somixhgt"   /> 
+	  <field field_ref="empmr"        name="sowaflup"   />
+          <field field_ref="empbmr"       name="sowaflupb"  />
+	  <field field_ref="fmmflx"       name="iowaflup"   />
+	  <field field_ref="ice_cover"    name="soicecov"   />
+	  <field field_ref="qsr"          name="soceshwf"   />
+	  <field field_ref="taum"         name="sowindsp"   />
+          <field field_ref="runoffs"      name="runoffs"   />
+        </file>
+	
+	<file id="file4" name_suffix="_gridU" description="ocean U grid variables" >
+          <field field_ref="e3u"          name="e3u"        />
+          <field field_ref="uocetr_eff"   name="uocetr_eff" /> 
+          <field field_ref="utau"         name="tauuo"      />
+        </file>
+	
+	<file id="file5" name_suffix="_gridV" description="ocean V grid variables" >
+          <field field_ref="e3v"          name="e3v"        />
+          <field field_ref="vocetr_eff"   name="vocetr_eff" /> 
+          <field field_ref="vtau"         name="tauvo"      />
+        </file>
+
+        <file id="file6" name_suffix="_gridW" description="ocean W grid variables" >
+          <field field_ref="e3w"          name="e3w"        />
+          <field field_ref="wocetr_eff"   name="wocetr_eff" /> 
+        </file>
+
+        <file id="file7" name_suffix="_gridKZ" description="ocean W grid variables" >
+          <field field_ref="avt"          name="voddmavs"   />
+        </file>
+
+        <file id="file8" name_suffix="_gridH" description="ocean W grid variables" >
+          <field field_ref="hdiv"      name="hdivtr"  long_name="horizontal divergence transport"   operation="average"  freq_op="1d" > @hdiv * @e3t </field> 
+        </file>
+
+      </file_group>
+
+      <file_group id="1mo" output_freq="1mo" split_freq="1mo" output_level="10" enabled=".TRUE." >  <!-- 5d files -->
+
+        <file id="file10" name_suffix="_gridT" description="ocean T grid variables" >
+          <field field_ref="e3t"          name="e3t"        />
+          <field field_ref="toce"         name="votemper"   operation="instant" freq_op="1d" > @toce_e3t / @e3t </field>
+        </file>
+
+        <file id="file11" name_suffix="_gridS" description="ocean T grid variables" >
+          <field field_ref="soce"         name="vosaline"   operation="instant" freq_op="1d" > @soce_e3t / @e3t </field>
+        </file>
+
+        <file id="file12" name_suffix="_grid2D" description="ocean T grid variables" >
+          <field field_ref="mldkz5"       name="somixhgt"   />
+          <field field_ref="empmr"        name="sowaflup"   />
+          <field field_ref="empbmr"       name="sowaflupb"  />
+          <field field_ref="fmmflx"       name="iowaflup"   />
+          <field field_ref="ice_cover"    name="soicecov"   />
+          <field field_ref="qsr"          name="soceshwf"   />
+          <field field_ref="taum"         name="sowindsp"   />
+          <field field_ref="runoffs"      name="runoffs"   />
+        </file>
+
+        <file id="file13" name_suffix="_gridU" description="ocean U grid variables" >
+          <field field_ref="e3u"          name="e3u"        />
+          <field field_ref="uocetr_eff"   name="uocetr_eff" /> 
+          <field field_ref="utau"         name="tauuo"      />
+        </file>
+
+        <file id="file14" name_suffix="_gridV" description="ocean V grid variables" >
+          <field field_ref="e3v"          name="e3v"        />
+          <field field_ref="vocetr_eff"   name="vocetr_eff" /> 
+          <field field_ref="vtau"         name="tauvo"      />
+        </file>
+
+        <file id="file15" name_suffix="_gridW" description="ocean W grid variables" >
+          <field field_ref="e3w"          name="e3w"        />
+          <field field_ref="wocetr_eff"   name="wocetr_eff" /> 
+        </file>
+
+        <file id="file16" name_suffix="_gridKZ" description="ocean W grid variables" >
+          <field field_ref="avt"          name="voddmavs"   />
+        </file>
+
+        <file id="file17" name_suffix="_gridH" description="ocean W grid variables" >
+          <field field_ref="hdiv"      name="hdivtr"  long_name="horizontal divergence transport"   operation="average"  freq_op="1d" > @hdiv * @e3t </field> 
+        </file>
+
+
+      </file_group>
+      
+   </file_definition>
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_static/iodef.xml
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_static/iodef.xml	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_static/iodef.xml	(revision 10345)
@@ -0,0 +1,194 @@
+<?xml version="1.0"?>
+<simulation> 
+
+ <context id="nemo" >
+    
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                  definition of all existing variables                                    =
+=                                            DO NOT CHANGE                                                 =
+============================================================================================================
+    -->
+    <field_definition src="./field_def.xml"/>
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+       -->
+
+    <file_definition src="./file_def.xml"/>
+
+    <!--
+ 
+============================================================================================================
+= grid definition = = DO NOT CHANGE =
+============================================================================================================
+    -->
+    
+   <axis_definition>  
+      <axis id="deptht"  long_name="Vertical T levels"  unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels"  unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels"  unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels"  unit="m" positive="down" />
+      <axis id="nfloat"  long_name="Float number"       unit="1"                 />
+      <axis id="icbcla"  long_name="Iceberg class"      unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"       unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"              />
+   </axis_definition> 
+    
+   <domain_definition src="./domain_def.xml"/>
+   
+   <grid_definition>    
+     <grid id="grid_T_2D" >
+       <domain id="grid_T" />
+     </grid>
+     <grid id="grid_T_3D" >
+       <domain id="grid_T" />
+       <axis id="deptht" />
+     </grid>
+     <grid id="grid_U_2D" >
+       <domain id="grid_U" />
+     </grid>
+     <grid id="grid_U_3D" >
+       <domain id="grid_U" />
+       <axis id="depthu" />
+     </grid>
+     <grid id="grid_V_2D" >
+       <domain id="grid_V" />
+     </grid>
+     <grid id="grid_V_3D" >
+       <domain id="grid_V" />
+       <axis id="depthv" />
+     </grid>
+     <grid id="grid_W_2D" >
+       <domain id="grid_W" />
+     </grid>
+     <grid id="grid_W_3D" >
+       <domain id="grid_W" />
+       <axis id="depthw" />
+     </grid>
+     <grid id="scalarpoint" />
+
+    </grid_definition> 
+
+  </context>
+  
+    <!-- 
+============================================================================================================
+============================================================================================================
+============================================================================================================
+=                                                    CRS context
+============================================================================================================
+============================================================================================================
+============================================================================================================
+    -->
+
+ <context id="nemo_crs" >
+
+    <!-- $id$ -->
+
+    <!-- 
+============================================================================================================
+=                                  definition of all existing variables                                    =
+=                                            DO NOT CHANGE                                                 =
+============================================================================================================
+    -->
+    <field_definition src="./field_def.xml"/>
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+       -->
+
+    <file_definition src="./file_crs_def.xml"/>
+
+    <!--
+ 
+============================================================================================================
+= grid definition = = DO NOT CHANGE =
+============================================================================================================
+    -->
+
+   <axis_definition>
+      <axis id="deptht"  long_name="Vertical T levels"  unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels"  unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels"  unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels"  unit="m" positive="down" />
+      <axis id="nfloat"  long_name="Float number"       unit="1"                 />
+      <axis id="icbcla"  long_name="Iceberg class"      unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"       unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"              />
+   </axis_definition>
+
+   <domain_definition src="./domain_def.xml"/>
+
+   <grid_definition>
+     <grid id="grid_T_2D" >
+       <domain id="grid_T" />
+     </grid>
+     <grid id="grid_T_3D" >
+       <domain id="grid_T" />
+       <axis id="deptht" />
+     </grid>
+     <grid id="grid_U_2D" >
+       <domain id="grid_U" />
+     </grid>
+     <grid id="grid_U_3D" >
+       <domain id="grid_U" />
+       <axis id="depthu" />
+     </grid>
+     <grid id="grid_V_2D" >
+       <domain id="grid_V" />
+     </grid>
+     <grid id="grid_V_3D" >
+       <domain id="grid_V" />
+       <axis id="depthv" />
+     </grid>
+     <grid id="grid_W_2D" >
+       <domain id="grid_W" />
+     </grid>
+     <grid id="grid_W_3D" >
+       <domain id="grid_W" />
+       <axis id="depthw" />
+     </grid>
+     <grid id="scalarpoint" />
+
+    </grid_definition>
+
+  </context>
+
+    <!-- 
+============================================================================================================
+============================================================================================================
+============================================================================================================
+=                                                    XIOS context
+============================================================================================================
+============================================================================================================
+============================================================================================================
+    -->
+
+  <context id="xios">
+
+      <variable_definition>
+	
+     <!-- 
+        We must have buffer_size > jpi*jpj*jpk*8 (with jpi and jpj the subdomain size)
+-->
+	  <variable id="info_level"                type="int">0</variable>
+	  <variable id="using_server"              type="bool">true</variable>
+	  <variable id="using_oasis"               type="bool">false</variable>
+	  <variable id="oasis_codes_id"            type="string" >oceanx</variable>
+	
+      </variable_definition>
+               
+  </context>
+  
+</simulation>
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_static/style.css
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_static/style.css	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_static/style.css	(revision 10345)
@@ -0,0 +1,5 @@
+.rstblue               { color: blue    ; }
+.rstgrey , .rstgreysup { color: grey    ; }
+.rstgreen              { color: seagreen; }
+
+.logo { filter: invert(1) !important; }
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_templates/layout.html
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_templates/layout.html	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/_templates/layout.html	(revision 10345)
@@ -0,0 +1,18 @@
+{% extends "!layout.html" %}
+{% block extrahead %}
+	<link href="{{ pathto("_static/style.css", True) }}" rel="stylesheet" type="text/css">
+{% endblock %}
+
+{% block sidebartitle %}
+
+	<a href="{{ pathto(master_doc) }}">
+		<img src="{{ pathto('_static/NEMO_grey.png', 1) }}" class="logo" alt="Logo"/>
+	</a>
+
+	<p>Community ocean model for multifarious space and time scales</p>
+
+	<div class="version">{{ release }}</div>
+
+	{% include "searchbox.html" %}
+
+{% endblock %}
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/assimilation.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/assimilation.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/assimilation.rst	(revision 10345)
@@ -0,0 +1,60 @@
+**************************************
+Data assimilation (OBS/SAO, ASM & TAM)
+**************************************
+
+.. contents::
+   :local:
+
+The assimilation interface to NEMO is split into three modules.
+- OBS for the observation operator
+- ASM for the application of increments and model bias correction (based on the assimilation increments).
+- TAM the tangent linear and adjoint model.
+
+Please see the `NEMO manual`_ for more details including information about the input file formats and
+the namelist settings.
+
+Observation and model comparison (OBS)
+======================================
+
+The observation and model comparison code (OBS) reads in observation files (profile temperature and salinity,
+sea surface temperature, sea level anomaly, sea ice concentration, and velocity) and
+calculates an interpolated model equivalent value at the observation location and nearest model timestep.
+The resulting data are saved in a feedback file (or files).
+The code was originally developed for use with the NEMOVAR data assimilation code, but
+can be used for validation or verification of model or any other data assimilation system.
+This is all controlled by the namelist.
+To build with the OBS code active ``key_diaobs`` must be set. 
+
+More details in the `NEMO manual`_ chapter 12.
+
+Standalone observation operator (SAO)
+-------------------------------------
+
+The OBS code can also be run after a model run using saved NEMO model data.
+This is accomplished using the standalone observation operator (SAO)
+(previously known the offline observation operator).
+
+To build the SAO use makenemo.
+This means compiling NEMO once (in the normal way) for the chosen configuration.
+Then include ``SAO`` at the end of the relevant line in ``cfg.txt`` file.
+Then recompile with the replacement main program in ``./src/SAO``.
+This is a special version of ``nemogcm.F90`` (which doesn't run the model, but reads in the model fields, and
+observations and runs the OBS code.
+See section 12.4 of the `NEMO manual`_.
+
+Apply assimilation increments (ASM)
+===================================
+
+The ASM code adds the functionality to apply increments to the model variables:
+temperature, salinity, sea surface height, velocity and sea ice concentration.
+These are read into the model from a NetCDF file which may be produced by separate data assimilation code.
+The code can also output model background fields which are used as an input to data assimilation code.
+This is all controlled by the namelist nam_asminc.
+To build the ASM code ``key asminc`` must be set.
+
+More details in the `NEMO manual`_ chapter 13.
+
+Tangent linear and adjoint (TAM)
+================================
+
+This is the tangent linear and adjoint code of NEMO which is useful to 4D VAR assimilation.
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/coarsening.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/coarsening.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/coarsening.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../src/OCE/CRS/README.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/conf.py
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/conf.py	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/conf.py	(revision 10345)
@@ -0,0 +1,181 @@
+# -*- coding: utf-8 -*-
+#
+# Configuration file for the Sphinx documentation builder.
+#
+# This file does only contain a selection of the most common options. For a
+# full list see the documentation:
+# http://www.sphinx-doc.org/en/master/config
+
+# -- Path setup --------------------------------------------------------------
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#
+# import os
+# import sys
+# sys.path.insert(0, os.path.abspath('.'))
+
+
+# -- Project information -----------------------------------------------------
+
+project = 'NEMO'
+copyright = ''
+author = 'NEMO System Team'
+
+# The short X.Y version
+version = '4.0'
+# The full version, including alpha/beta/rc tags
+release = '4.0rc'
+
+
+# -- General configuration ---------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#
+# needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = ['sphinx.ext.extlinks', 'sphinxcontrib.bibtex']
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix(es) of source filenames.
+# You can specify multiple suffix as a list of string:
+#
+# source_suffix = ['.rst', '.md']
+source_suffix = '.rst'
+
+# The master toctree document.
+master_doc = 'NEMO_guide'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#
+# This is also used if you do content translation via gettext catalogs.
+# Usually you set "language" from the command line for these cases.
+language = None
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This pattern also affects html_static_path and html_extra_path .
+exclude_patterns = ['global.rst']
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+
+# -- Options for HTML output -------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  See the documentation for
+# a list of builtin themes.
+#
+#html_theme = 'alabaster'
+html_theme = 'sphinx_rtd_theme'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further.  For a list of options available for each theme, see the
+# documentation.
+#
+html_theme_options = {
+#	Alabaster theme options
+#	'logo': 'NEMO_grey.png',
+#	'description': 'Community ocean model for multifarious space and time scales',
+#	'fixed_sidebar': True,
+}
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# Custom sidebar templates, must be a dictionary that maps document names
+# to template names.
+#
+# The default sidebars (for documents that don't match any pattern) are
+# defined by theme itself.  Builtin themes are using these templates by
+# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
+# 'searchbox.html']``.
+#
+# html_sidebars = {}
+
+html_favicon = '_static/ORCA.ico'
+
+# -- Options for HTMLHelp output ---------------------------------------------
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'NEMOdoc'
+
+
+# -- Options for LaTeX output ------------------------------------------------
+
+latex_elements = {
+    # The paper size ('letterpaper' or 'a4paper').
+    #
+    # 'papersize': 'letterpaper',
+
+    # The font size ('10pt', '11pt' or '12pt').
+    #
+    # 'pointsize': '10pt',
+
+    # Additional stuff for the LaTeX preamble.
+    #
+    # 'preamble': '',
+
+    # Latex figure (float) alignment
+    #
+    # 'figure_align': 'htbp',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title,
+#  author, documentclass [howto, manual, or own class]).
+latex_documents = [
+    (master_doc, 'NEMO_guide.tex', 'NEMO Quick Start Guide',
+     'NEMO System Team', 'howto'),
+]
+
+
+# -- Options for manual page output ------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+    (master_doc, 'nemo', 'NEMO Documentation',
+     [author], 1)
+]
+
+
+# -- Options for Texinfo output ----------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+#  dir menu entry, description, category)
+texinfo_documents = [
+    (master_doc, 'NEMO', 'NEMO Documentation',
+     author, 'NEMO', 'One line description of project.',
+     'Miscellaneous'),
+]
+
+
+# -- Customisation -----------------------------------------------------------
+
+import datetime
+year = datetime.date.today().year
+copyright = '2008-' + str( year ) + ', NEMO Consortium'
+
+# Link aliases
+extlinks = {
+	'doi'    : ('http://doi.org/%s'                       , None),
+	'forge'  : ('http://forge.ipsl.jussieu.fr/nemo/%s'    , None),
+	'github' : ('http://github.com/%s'                    , None),
+	'xios'   : ('http://forge.ipsl.jussieu.fr/ioserver/%s', None),
+	'website': ('http://www.nemo-ocean.eu/%s'             , None),
+	'zenodo' : ('http://zenodo.org/publication/%s'        , None)
+}
+
+# Include common directives for every rst file
+rst_epilog = open('global.rst', 'r').read()
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/configurations.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/configurations.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/configurations.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../cfgs/README.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/coupling.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/coupling.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/coupling.rst	(revision 10345)
@@ -0,0 +1,13 @@
+**********************
+Coupling (OASIS & SAS)
+**********************
+
+NEMO currently exploits OASIS-3-MCT to implement a generalised coupled interface
+(`Coupled Formulation <http://forge.ipsl.jussieu.fr/nemo/doxygen/node50.html?doc=NEMO>`_).
+It can be used to interface with most of the European atmospheric GCM (ARPEGE, ECHAM, ECMWF, Ha- dAM, HadGAM, LMDz),
+as well as to WRF (Weather Research and Forecasting Model), and to implement the coupling of
+two independent NEMO components, ocean on one hand and sea-ice plus other surface processes on the other hand
+(`Standalone Surface Module - SAS <http://forge.ipsl.jussieu.fr/nemo/doxygen/node46.html?doc=NEMO>`_).
+
+To enable the OASIS interface the required compilation key is ``key_oasis3``.
+The parameters to set are in sections ``namsbc_cpl`` and in case of using of SAS also in section ``namsbc_sas``.
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/definitions.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/definitions.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/definitions.rst	(revision 10345)
@@ -0,0 +1,33 @@
+***********
+Definitions
+***********
+
+`AGRIF`_
+	*Adaptive Grid Refinement In Fortran*, 
+	package for the integration of full adaptive mesh refinement features within 
+	an existing multidimensional finite difference model
+
+SI\ :sup:`3`\ 
+	*Sea Ice Integrated Initiative*, 
+	unified sea ice model merging functionalities from CICE, GELATO and LIM into the NEMO framework
+
+`OASIS`_
+	*Ocean Atmosphere Sea Ice Soil*, 
+	coupling software to synchronise numerical codes representing different components of the climate system
+
+PISCES
+	*Pelagic Interactions Scheme for Carbon and Ecosystem Studies*, 
+	biogeochemical model simulating marine ecosystems, cycles of carbon and the main nutrients
+
+TAM
+	*Tangent linear and Adjoint Model*, 
+	tools to analyse and control the NEMO dynamical core for a wide range of applications such as
+	sensitivity analysis, parameter estimation, vectors computation or data assimilation.
+
+TOP
+	*Tracers in Ocean Paradigm*, 
+	on/off-line oceanic tracers transport and biogeochemistry models
+
+`XIOS`_
+	*XML Input Output Server*, 
+	library dedicated to input/output management of climate code
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/diagnostics.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/diagnostics.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/diagnostics.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../cfgs/SHARED/README.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/global.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/global.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/global.rst	(revision 10345)
@@ -0,0 +1,38 @@
+.. Roles (custom styles related to CSS classes in 'source/_static/style.css')
+
+.. role:: rstblue
+.. role:: rstgreen
+.. role:: rstgrey
+.. role:: rstgreysup(sup)
+.. role:: underline 
+   :class: underline
+
+.. Substitutions
+
+.. |OPA| replace:: :rstblue:`NEMO-OPA`
+.. |SI3| replace:: :rstgrey:`NEMO-SI`\ :rstgreysup:`3`
+.. |TOP| replace:: :rstgreen:`NEMO-TOP/PISCES`
+
+.. Institutes
+
+.. _CMCC:           http://www.cmcc.it 
+.. _CNRS:           http://www.cnrs.fr
+.. _Mercator Océan: http://www.mercator-ocean.fr
+.. _Met Office:     http://www.metoffice.gov.uk
+.. _MOI:            http://www.mercator-ocean.fr
+.. _NERC:           http://nerc.ukri.org
+
+.. Models / Softwares
+
+.. _AGRIF: http://agrif.imag.fr
+.. _OASIS: http://verc.enes.org/oasis
+.. _XIOS:  http://forge.ipsl.jussieu.fr/ioserver
+
+.. NEMO
+
+.. _NEMO:          http://www.nemo-ocean.eu
+.. _NEMO strategy: http://doi.org/10.5281/zenodo.1471663
+.. _NEMO guide:    http://doi.org/10.5281/zenodo.1475325
+.. _NEMO manual:   http://doi.org/10.5281/zenodo.1464816
+.. _SI3 manual:    http://doi.org/10.5281/zenodo.1471689
+.. _TOP manual:    http://doi.org/10.5281/zenodo.1471700
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/install.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/install.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/install.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../INSTALL.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/interfacing_options.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/interfacing_options.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/interfacing_options.rst	(revision 10345)
@@ -0,0 +1,36 @@
+===================
+Interfacing options
+===================
+
+..
+	contents::
+	:local:
+	:depth: 1
+
+.. include:: zooms.rst
+
+.. bibliography:: zooms.bib
+	:all:
+	:style: unsrt
+	:labelprefix: A
+	:keyprefix: a-
+
+----
+
+.. include:: coarsening.rst
+
+----
+
+.. include:: coupling.rst
+
+----
+
+.. include:: assimilation.rst
+
+----
+
+.. include:: input-output.rst
+
+----
+
+.. include:: tracers.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/readme.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/readme.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/readme.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../README.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/references.bib
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/references.bib	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/references.bib	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../REFERENCES.bib
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/release_notes.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/release_notes.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/release_notes.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../RELEASE_NOTES.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/setup.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/setup.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/setup.rst	(revision 10345)
@@ -0,0 +1,249 @@
+******************************
+Setting up a new configuration
+******************************
+
+.. contents::
+
+Starting from an existing configuration
+=======================================
+
+There are three options to build a new configuration from an existing one:
+
+Option 1: Duplicate an existing configuration
+---------------------------------------------
+
+The NEMO so-called Reference Configurations cover a number of major features for NEMO setup
+(global, regional, 1D, using embeded zoom with AGRIF...)
+
+One can create a new configuration by duplicating one of the reference configurations
+(``ORCA2_LIM3_PISCES`` in the following example)
+
+.. code-block:: sh
+
+	makenemo –n 'ORCA2_LIM3_PISCES_MINE' -r 'ORCA2_LIM3_PISCES'
+
+Option 2: Duplicate with differences
+------------------------------------
+
+Create and compile a new configuration based on a reference configuration
+(``ORCA2_LIM3_PISCES`` in the following example) but with different pre-processor options.
+For this either add ``add_key`` or ``del_key`` keys as required; e.g.
+
+.. code-block:: sh
+
+	makenemo –n 'ORCA2_LIM3_PISCES_MINE' -r 'ORCA2_LIM3_PISCES' del_key 'key_iomput' add_key 'key_xios'
+
+Option 3: Use the SIREN tools to subset an existing model
+---------------------------------------------------------
+
+Define a regional configuration which is a sub- or super-set of an existing configuration.
+
+This last option employs the SIREN software tools that are included in the standard distribution.
+The software is written in Fortran 95 and available in the ``./tools/SIREN`` directory.
+SIREN allows you to create your own regional configuration embedded in a wider one.
+
+SIREN is a set of programs to create all the input files you need to run a NEMO regional configuration.
+As a basic demonstrator, a set of GLORYS files (GLObal ReanalYSis on the ORCA025 grid),
+as well as examples of namelists are available `here`_.
+
+`SIREN documentation`_
+
+Any questions or comments regarding the use of SIREN should be posted in `the corresponding forum`_.
+
+Creating a completely new configuration
+=======================================
+
+From NEMO version 4.0 there are two ways to build configurations from scratch.
+The appropriate method to use depends largely on the target configuration.
+Method 1 is for more complex/realistic global or regional configurations and
+method 2 is intended for simpler, idealised configurations whose
+domains and characteristics can be described in simple geometries and formulae.
+
+Option 1: Create and use a domain configuration file
+----------------------------------------------------
+
+This method is used by each of the reference configurations,
+so that downloading their input files linked to their description can help.
+Although starting from scratch it is advisable to create the directory structure to house your new configuration by
+duplicating the closest reference configuration to your target application.
+For example, if your application requires both ocean ice and passive tracers,
+then use the ``ORCA2_LIM3_PISCES`` as template,
+and execute following command to build your ``MY_NEW_CONFIG`` configuration:
+
+.. code-block:: sh
+
+	makenemo –n 'MY_NEW_CONFIG' -r 'ORCA2_LIM3_PISCES'
+
+where ``MY_NEW_CONFIG`` can be substituted with a suitably descriptive name for your new configuration.  
+
+The purpose of this step is simply to create and populate the appropriate ``WORK``, ``MY_SRC`` and
+``EXP00`` subdirectories for your new configuration.
+Other choices for the base reference configuration might be
+
+- ``GYRE``  - If your target application is ocean-only
+- ``AMM12`` - If your target application is regional with open boundaries
+
+All the domain information for your new configuration will be contained within
+a netcdf file called ``domain_cfg.nc`` which you will need to create and
+place in the ``./cfgs/MY_NEW_CONFIG/EXP00`` sub-directory.
+Firstly though, ensure that your configuration is set to use such a file by checking that
+
+.. code-block:: fortran
+
+	ln_read_cfg = .true.
+
+in	``./cfgs/MY_NEW_CONFIG/EXP00/namelist_cfg``
+
+Create the domain_cfg.nc file which must contain the following fields
+
+.. code-block:: c++
+
+	int    ORCA, ORCA_index                  /* configuration name, configuration resolution                 */
+	int    jpiglo, jpjglo, jpkglo            /* global domain sizes                                          */
+	int    jperio                            /* lateral global domain b.c.                                   */
+	int    ln_zco, ln_zps, ln_sco            /* flags for z-coord, z-coord with partial steps and s-coord    */
+	int    ln_isfcav                         /* flag  for ice shelf cavities                                 */
+	double glamt, glamu, glamv, glamf        /* geographic position                                          */
+	double gphit, gphiu, gphiv, gphif        /* geographic position                                          */
+	double iff, ff_f, ff_t                   /* Coriolis parameter (if not on the sphere)                    */
+	double e1t, e1u, e1v, e1f                /* horizontal scale factors                                     */
+	double e2t, e2u, e2v, e2f                /* horizontal scale factors                                     */
+	double ie1e2u_v, e1e2u, e1e2v            /* U and V surfaces (if grid size reduction in some straits)    */
+	double e3t_1d, e3w_1d                    /* reference vertical scale factors at T and W points           */
+	double e3t_0, e3u_0, e3v_0, e3f_0, e3w_0 /* vertical scale factors 3D coordinate at T,U,V,F and W points */
+	double e3uw_0, e3vw_0                    /* vertical scale factors 3D coordinate at UW and VW points     */
+	int    bottom_level, top_level           /* last wet T-points, 1st wet T-points (for ice shelf cavities) */
+
+There are two options for creating a domain_cfg.nc file:
+
+- Users can use tools of their own choice to build a ``domain_cfg.nc`` with all mandatory fields.
+- Users can adapt and apply the supplied tool available in ``./tools/DOMAINcfg``.
+  This tool is based on code extracted from NEMO version 3.6 and will allow similar choices for
+  the horizontal and vertical grids that were available internally to that version.
+  See ``./tools/DOMAINcfg/README`` for details.
+
+Option 2: Adapt the usr_def configuration module of NEMO for you own purposes
+-----------------------------------------------------------------------------
+
+This method is intended for configuring easily simple/idealised configurations which
+are often used as demonstrators or for process evaluation and comparison.
+This method can be used whenever the domain geometry has a simple mathematical description and
+the ocean initial state and boundary forcing is described analytically. 
+As a start, consider the case of starting a completely new ocean-only test case based on
+the ``LOCK_EXCHANGE`` example.
+[Note: we probably need an even more basic example than this with only one namelist and
+minimal changes to the usrdef modules]
+
+Firstly, construct the directory structure, starting in the ``cfgs`` directory:
+
+.. code-block:: sh
+
+	./makenemo -n 'MY_NEW_TEST' -t 'LOCK_EXCHANGE'
+
+where the ``-t`` option has been used to locate the new configuration in the ``tests`` subdirectory
+(it is recommended practice to keep full configurations and idealised cases clearly distinguishable).
+This command will have created (amongst others) the following files and directories::
+
+	./tests/MY_NEW_TEST:
+	BLD	  MY_SRC cpp_MY_NEW_TEST.fcm
+	EXP00   WORK
+	#
+	./tests/MY_NEW_TEST/EXP00:
+	context_nemo.xml       domain_def_nemo.xml
+	field_def_nemo-opa.xml file_def_nemo-opa.xml
+	iodef.xml
+	namelist_cfg
+	namelist_ref
+	#
+	./tests/MY_NEW_TEST/MY_SRC:
+	usrdef_hgr.F90    usrdef_nam.F90 usrdef_zgr.F90
+	usrdef_istate.F90 usrdef_sbc.F90 zdfini.F90
+
+The key to setting up an idealised configuration lies in adapting a small set of short Fortran 90 modules which
+should be dropped into the ``MY_SRC`` directory.
+Here the ``LOCK_EXCHANGE`` example is using 5 such routines but the full set that is available in
+the ``src/OCE/USR`` directory is::
+
+	./src/OCE/USR:
+	usrdef_closea.F90 usrdef_istate.F90 usrdef_zgr.F90
+	usrdef_fmask.F90  usrdef_nam.F90
+	usrdef_hgr.F90    usrdef_sbc.F90
+
+Before discussing these in more detail it is worth noting the various namelist controls that
+engage the different user-defined aspects.
+These controls are set using two new logical switches or are implied by the settings of existing ones.
+For example, the mandatory requirement for an idealised configuration is to provide routines which
+define the horizontal and vertical domains.
+Templates for these are provided in the ``usrdef_hgr.F90`` and ``usrdef_zgr.F90`` modules.
+The application of these modules is activated whenever:
+
+.. code-block:: fortran
+
+	ln_read_cfg = .false.
+
+in any configuration's ``namelist_cfg`` file.
+This setting also activates the reading of an optional ``nam_usrdef`` namelist which can be used to
+supply configuration specific settings.
+These need to be declared and read in the ``usrdef_nam.F90`` module.
+
+Another explicit control is available in the ``namsbc`` namelist which activates the use of analytical forcing.
+With
+
+.. code-block:: fortran
+
+	ln_usr = .true.
+
+Other usrdef modules are activated by less explicit means.
+For example, code in ``usrdef_istate.F90`` is used to define initial temperature and salinity fields if
+
+.. code-block:: fortran
+
+	ln_tsd_init   = .false.
+
+in the ``namtsd`` namelist.
+The remaining modules, namely::
+
+	usrdef_closea.F90 usrdef_fmask.F90
+
+are specific to ORCA configurations and set local variations of some specific fields for
+the various resolutions of the global models.
+They do not need to be considered here in the context of idealised cases but it is worth noting that all
+configuration specific code has now been isolated in the usrdef modules.
+In the case of these last two modules, they are activated only if an ORCA configuration is detected.
+Currently this requires a specific integer variable named ``ORCA`` to be set in a ``domain_cfg.nc`` file.
+[Note: this would be less confusing if the cn_cfg string is read directly as a character attribue from
+the ``domain_cfg.nc`` ]
+
+So, in most cases, the set up of idealised model configurations can be completed by
+copying the template routines from ``./src/OCE/USR`` into
+your new ``./cfgs/MY_NEW_TEST/MY_SRC`` directory and editing the appropriate modules as needed.
+The default set are those used for the GYRE reference configuration.
+The contents of ``MY_SRC`` directories from other idealised configurations may provide more convenient templates if
+they share common characteristics with your target application.
+
+Whatever the starting point it should not require too many changes or additional lines of code to
+produce routines in ``./src/OCE/USR`` that define analytically the domain,
+the initial state and the surface boundary conditions for your new configuration.
+
+To summarize, the base set of modules is:
+
+- ``usrdef_hgr.F90``   : define horizontal grid
+- ``usrdef_zgr.F90``   : define vertical grid
+- ``usrdef_sbc.F90``   : provides at each time-step the surface boundary condition, i.e. the momentum, heat and freshwater fluxes
+- ``usrdef_istate.F90``: defines initialization of the dynamics and tracers
+- ``usrdef_nam.F90``   : configuration-specific namelist processing to set any associated run-time parameters
+
+with two specialised ORCA modules
+(not related to idealised configurations but used to isolate configuration specific code that is used in
+ORCA2 reference configurations and established global configurations using the ORCA tripolar grid):
+
+- ``usrdef_fmask.F90`` : only used in ORCA CONFIGURATIONS for alteration of f-point land/ocean mask in some straits
+- ``usrdef_closea.F90``: only used in ORCA CONFIGURATIONS for specific treatments associated with closed seas
+
+From version 4.0, the NEMO release includes a ``tests`` subdirectory containing available and
+up to date test cases build by the community.
+These will not be fully supported as is NEMO reference but should provide a source of raw material.
+
+.. _here:                     http://prodn.idris.fr/thredds/catalog/ipsl_public/rron463/catalog.html?dataset=DatasetScanipsl_public/rron463/INPUT_SIREN.tar
+.. _the corresponding forum:  http://forge.ipsl.jussieu.fr/nemo/discussion/forum/2
+.. _SIREN documentation:      http://forge.ipsl.jussieu.fr/nemo/doxygen/index.html
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/test_cases.bib
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/test_cases.bib	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/test_cases.bib	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../tests/test_cases.bib
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/test_cases.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/test_cases.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/test_cases.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../tests/README.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/tools.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/tools.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/tools.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../tools/README.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/tracers.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/tracers.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/tracers.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../src/TOP/README.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/zooms.bib
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/zooms.bib	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/zooms.bib	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../cfgs/AGRIF_DEMO/zooms.bib
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/zooms.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/zooms.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/doc/rst/source/zooms.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../cfgs/AGRIF_DEMO/README.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE/icedyn_adv_umx.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE/icedyn_adv_umx.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE/icedyn_adv_umx.F90	(revision 10345)
@@ -229,7 +229,13 @@
          !
          DO jl = 1, ipl
-            DO jj = 1, jpjm1
+            DO jj = 2, jpjm1
                DO ji = 1, fs_jpim1   ! vector opt.
                   zfu_ho(ji,jj,jl) = puc(ji,jj) * zt_u(ji,jj,jl)
+               END DO
+            END DO
+         END DO
+         DO jl = 1, ipl
+            DO jj = 1, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
                   zfv_ho(ji,jj,jl) = pvc(ji,jj) * zt_v(ji,jj,jl)
                END DO
@@ -242,7 +248,13 @@
       ! --------------------------------------------------
       DO jl = 1, ipl
-         DO jj = 1, jpjm1
+         DO jj = 2, jpjm1
             DO ji = 1, fs_jpim1   ! vector opt.
                zfu_ho(ji,jj,jl) = zfu_ho(ji,jj,jl) - zfu_ups(ji,jj,jl)
+            END DO
+         END DO
+      END DO
+      DO jl = 1, ipl
+         DO jj = 1, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
                zfv_ho(ji,jj,jl) = zfv_ho(ji,jj,jl) - zfv_ups(ji,jj,jl)
             END DO
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE/icedyn_rhg_evp.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE/icedyn_rhg_evp.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE/icedyn_rhg_evp.F90	(revision 10345)
@@ -26,4 +26,5 @@
    USE sbc_ice , ONLY : utau_ice, vtau_ice, snwice_mass, snwice_mass_b
    USE ice            ! sea-ice: ice variables
+   USE icevar         ! ice_var_sshdyn
    USE icedyn_rdgrft  ! sea-ice: ice strength
    USE bdy_oce , ONLY : ln_bdy 
@@ -143,5 +144,5 @@
       REAL(wp), DIMENSION(jpi,jpj) ::   zs1, zs2, zs12                  ! stress tensor components
       REAL(wp), DIMENSION(jpi,jpj) ::   zu_ice, zv_ice, zresr           ! check convergence
-      REAL(wp), DIMENSION(jpi,jpj) ::   zpice                           ! array used for the calculation of ice surface slope:
+      REAL(wp), DIMENSION(jpi,jpj) ::   zssh_lead_m                     ! array used for the calculation of ice surface slope:
       !                                                                 !    ocean surface (ssh_m) if ice is not embedded
       !                                                                 !    ice top surface if ice is embedded   
@@ -261,19 +262,7 @@
       !------------------------------------------------------------------------------!
 
-      IF( ln_ice_embd ) THEN             !== embedded sea ice: compute representative ice top surface ==!
-         !                                            
-         ! average interpolation coeff as used in dynspg = (1/nn_fsbc)   * {SUM[n/nn_fsbc], n=0,nn_fsbc-1}
-         !                                               = (1/nn_fsbc)^2 * {SUM[n]        , n=0,nn_fsbc-1}
-         zintn = REAL( nn_fsbc - 1 ) / REAL( nn_fsbc ) * 0.5_wp     
-         !
-         ! average interpolation coeff as used in dynspg = (1/nn_fsbc)   *    {SUM[1-n/nn_fsbc], n=0,nn_fsbc-1}
-         !                                               = (1/nn_fsbc)^2 * (nn_fsbc^2 - {SUM[n], n=0,nn_fsbc-1})
-         zintb = REAL( nn_fsbc + 1 ) / REAL( nn_fsbc ) * 0.5_wp
-         !
-         zpice(:,:) = ssh_m(:,:) + ( zintn * snwice_mass(:,:) + zintb * snwice_mass_b(:,:) ) * r1_rau0
-         !
-      ELSE                                    !== non-embedded sea ice: use ocean surface for slope calculation ==!
-         zpice(:,:) = ssh_m(:,:)
-      ENDIF
+      !== embedded sea ice: compute representative ice top surface      ==!
+      !== non-embedded sea ice: use ocean surface for slope calculation ==!
+      zssh_lead_m(:,:) = ice_var_sshdyn( ssh_m, snwice_mass, snwice_mass_b)
 
       DO jj = 2, jpjm1
@@ -313,6 +302,6 @@
 
             ! Surface pressure gradient (- m*g*GRAD(ssh)) at U-V points
-            zspgU(ji,jj)    = - zmassU * grav * ( zpice(ji+1,jj) - zpice(ji,jj) ) * r1_e1u(ji,jj)
-            zspgV(ji,jj)    = - zmassV * grav * ( zpice(ji,jj+1) - zpice(ji,jj) ) * r1_e2v(ji,jj)
+            zspgU(ji,jj)    = - zmassU * grav * ( zssh_lead_m(ji+1,jj) - zssh_lead_m(ji,jj) ) * r1_e1u(ji,jj)
+            zspgV(ji,jj)    = - zmassV * grav * ( zssh_lead_m(ji,jj+1) - zssh_lead_m(ji,jj) ) * r1_e2v(ji,jj)
 
             ! masks
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE/icevar.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE/icevar.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE/icevar.F90	(revision 10345)
@@ -49,8 +49,9 @@
    !!   ice_var_bv        : brine volume
    !!   ice_var_enthalpy  : compute ice and snow enthalpies from temperature
+   !!   ice_var_sshdyn    : compute equivalent ssh in lead
    !!----------------------------------------------------------------------
    USE dom_oce        ! ocean space and time domain
    USE phycst         ! physical constants (ocean directory) 
-   USE sbc_oce , ONLY : sss_m
+   USE sbc_oce , ONLY : sss_m, ln_ice_embd, nn_fsbc
    USE ice            ! sea-ice: variables
    USE ice1D          ! sea-ice: thermodynamics variables
@@ -74,4 +75,5 @@
    PUBLIC   ice_var_bv           
    PUBLIC   ice_var_enthalpy           
+   PUBLIC   ice_var_sshdyn
 
    !!----------------------------------------------------------------------
@@ -949,4 +951,52 @@
    END SUBROUTINE ice_var_enthalpy
 
+   FUNCTION ice_var_sshdyn(pssh, psnwice_mass, psnwice_mass_b)
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE rhg_evp_rst  ***
+      !!                     
+      !! ** Purpose :  compute the equivalent ssh in lead when sea ice is embedded
+      !!
+      !! ** Method  :  ssh_lead = ssh + (Mice + Msnow) / rau0
+      !!
+      !! ** Reference : Jean-Michel Campin, John Marshall, David Ferreira,
+      !!                Sea ice-ocean coupling using a rescaled vertical coordinate z*, 
+      !!                Ocean Modelling, Volume 24, Issues 1-2, 2008
+      !!
+      !!----------------------------------------------------------------------
+      !
+      ! input
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: pssh            !: ssh [m]
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: psnwice_mass    !: mass of snow and ice at current  ice time step [Kg/m2]
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: psnwice_mass_b  !: mass of snow and ice at previous ice time step [Kg/m2]
+      !
+      ! output
+      REAL(wp), DIMENSION(jpi,jpj) :: ice_var_sshdyn  ! equivalent ssh in lead [m]
+      !
+      ! temporary
+      REAL(wp) :: zintn, zintb                     ! time interpolation weights []
+      REAL(wp), DIMENSION(jpi,jpj) :: zsnwiceload  ! snow and ice load [m]
+      !
+      ! compute ice load used to define the equivalent ssh in lead
+      IF( ln_ice_embd ) THEN
+         !                                            
+         ! average interpolation coeff as used in dynspg = (1/nn_fsbc)   * {SUM[n/nn_fsbc], n=0,nn_fsbc-1}
+         !                                               = (1/nn_fsbc)^2 * {SUM[n]        , n=0,nn_fsbc-1}
+         zintn = REAL( nn_fsbc - 1 ) / REAL( nn_fsbc ) * 0.5_wp
+         !
+         ! average interpolation coeff as used in dynspg = (1/nn_fsbc)   *    {SUM[1-n/nn_fsbc], n=0,nn_fsbc-1}
+         !                                               = (1/nn_fsbc)^2 * (nn_fsbc^2 - {SUM[n], n=0,nn_fsbc-1})
+         zintb = REAL( nn_fsbc + 1 ) / REAL( nn_fsbc ) * 0.5_wp
+         !
+         zsnwiceload(:,:) = ( zintn * psnwice_mass(:,:) + zintb * psnwice_mass_b(:,:) ) * r1_rau0
+         !
+      ELSE
+         zsnwiceload(:,:) = 0.0_wp
+      ENDIF
+      ! compute equivalent ssh in lead
+      ice_var_sshdyn(:,:) = pssh(:,:) + zsnwiceload(:,:)
+      !
+   END FUNCTION ice_var_sshdyn
+
+
 #else
    !!----------------------------------------------------------------------
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/ASM/README.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/ASM/README.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/ASM/README.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../doc/rst/source/data_assimilation.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/CRS/README.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/CRS/README.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/CRS/README.rst	(revision 10345)
@@ -0,0 +1,149 @@
+**********************************
+On line biogeochemistry coarsening
+**********************************
+
+.. contents::
+   :local:
+
+Presentation
+============
+
+A capacity of coarsening physics to force a BGC model coupled to NEMO has been developed.
+This capacity allow to run 'online' a BGC model coupled to OCE-SI3 with a lower resolution,
+to reduce the CPU cost of the BGC model, while preserving the effective resolution of the dynamics.
+
+A presentation is available [attachment:crs_wiki_1.1.pdf​ here], where the methodology is presented.
+
+What is available and working for now in this version
+=====================================================
+
+[To be completed]
+
+Description of the successful validation tests
+==============================================
+
+[To be completed]
+
+What is not working yet with on line coarsening of biogeochemistry
+==================================================================
+
+[To be completed]
+
+''should include precise explanation on MPI decomposition problems too''
+
+How to set up and use on line biogeochemistry
+=============================================
+
+Extract the on line biogeochemistry branch
+------------------------------------------
+
+To get the appropriate source code with the on line coarsening of biogeochemistry feature:
+
+.. code-block:: console
+
+	$ svn co https://forge.ipsl.jussieu.fr/nemo/browser/NEMO/branches/2018/dev_r5003_MERCATOR6_CRS
+
+
+How to activate coarsening?
+---------------------------
+
+To activate the coarsening, ``key_crs`` should be added to list of CPP keys.
+This key will only activate the coarsening of dynamics.
+
+Some parameters are available in the namelist_cfg:
+
+.. code-block:: fortran
+
+	               !   passive tracer coarsened online simulations
+	!-----------------------------------------------------------------------
+	   nn_factx    = 3         !  Reduction factor of x-direction
+	   nn_facty    = 3         !  Reduction factor of y-direction
+	   nn_msh_crs  = 0         !  create (=1) a mesh file or not (=0)
+	   nn_crs_kz   = 3         ! 0, volume-weighted MEAN of KZ
+	                           ! 1, MAX of KZ
+	                           ! 2, MIN of KZ
+	                           ! 3, 10^(MEAN(LOG(KZ)) 
+	                           ! 4, MEDIANE of KZ 
+	   ln_crs_wn   = .false.   ! wn coarsened (T) or computed using horizontal divergence ( F )
+	                           !                           !
+	   ln_crs_top = .true.     !coarsening online for the bio
+	/
+
+- Only ``nn_factx = 3`` is available and the coarsening only works for grids with a T-pivot point for
+  the north-fold lateral boundary condition (ORCA025, ORCA12, ORCA36, ...).
+- ``nn_msh_crs = 1`` will activate the generation of the coarsened grid meshmask.
+- ``nn_crs_kz`` is the operator to coarsen the vertical mixing coefficient. 
+- ``ln_crs_wn``
+
+  - when ``key_vvl`` is activated, this logical has no effect;
+    the coarsened vertical velocities are computed using horizontal divergence.
+  - when ``key_vvl`` is not activated,
+
+    - coarsened vertical velocities are computed using horizontal divergence (``ln_crs_wn = .false.``) 
+    - or coarsened vertical velocities are computed with an average operator (``ln_crs_wn = .true.``)
+- ``ln_crs_top = .true.``: should be activated to run BCG model in coarsened space;
+  so only works when ``key_top`` is in the cpp list and eventually ``key_pisces`` or ``key_my_trc``.
+
+Choice of operator to coarsene KZ
+---------------------------------
+
+A sensiblity test has been done with an Age tracer to compare the different operators.
+The 3 and 4 options seems to provide the best results.
+
+Some results can be found [xxx here]
+
+Example of xml files to output coarsened variables with XIOS
+------------------------------------------------------------
+
+In the [attachment:iodef.xml iodef.xml]  file, a "nemo" context is defined and
+some variable defined in [attachment:file_def.xml file_def.xml] are writted on the ocean-dynamic grid.  
+To write variables on the coarsened grid, and in particular the passive tracers,
+a "nemo_crs" context should be defined in [attachment:iodef.xml iodef.xml] and
+the associated variable are listed in [attachment:file_crs_def.xml file_crs_def.xml ].
+
+Passive tracers tracers initial conditions
+------------------------------------------
+
+When initial conditions are provided in NetCDF files, the field might be:
+
+- on the coarsened grid
+- or they can be on another grid and
+  interpolated `on-the-fly <http://forge.ipsl.jussieu.fr/nemo/wiki/Users/SetupNewConfiguration/Weight-creator>`_.
+  Example of namelist for PISCES :
+  
+	.. code-block:: fortran
+
+		!-----------------------------------------------------------------------
+		&namtrc_dta      !    Initialisation from data input file
+		!-----------------------------------------------------------------------
+		!
+		   sn_trcdta(1)  = 'DIC_REG1'        ,        -12        ,  'DIC'     ,    .false.   , .true. , 'yearly'  , 'reshape_REG1toeORCA075_bilin.nc'       , ''   , ''
+		   sn_trcdta(2)  = 'ALK_REG1'        ,        -12        ,  'ALK'     ,    .false.   , .true. , 'yearly'  , 'reshape_REG1toeORCA075_bilin.nc'       , ''   , ''
+		   sn_trcdta(3)  = 'O2_REG1'         ,        -1         ,  'O2'      ,    .true.    , .true. , 'yearly'  , 'reshape_REG1toeORCA075_bilin.nc'       , ''   , ''
+		   sn_trcdta(5)  = 'PO4_REG1'        ,        -1         ,  'PO4'     ,    .true.    , .true. , 'yearly'  , 'reshape_REG1toeORCA075_bilin.nc'       , ''   , ''
+		   sn_trcdta(7)  = 'Si_REG1'         ,        -1         ,  'Si'      ,    .true.    , .true. , 'yearly'  , 'reshape_REG1toeORCA075_bilin.nc'       , ''   , ''
+	   	sn_trcdta(10) = 'DOC_REG1'        ,        -12        ,  'DOC'     ,    .false.   , .true. , 'yearly'  , 'reshape_REG1toeORCA075_bilin.nc'       , ''   , ''
+		   sn_trcdta(14) = 'Fe_REG1'         ,        -12        ,  'Fe'      ,    .false.   , .true. , 'yearly'  , 'reshape_REG1toeORCA075_bilin.nc'       , ''   , ''
+		   sn_trcdta(23) = 'NO3_REG1'        ,        -1         ,  'NO3'     ,    .true.    , .true. , 'yearly'  , 'reshape_REG1toeORCA075_bilin.nc'       , ''   , ''
+	   	rn_trfac(1)   =   1.0e-06  !  multiplicative factor
+		   rn_trfac(2)   =   1.0e-06  !  -      -      -     -
+		   rn_trfac(3)   =  44.6e-06  !  -      -      -     -
+	   	rn_trfac(5)   = 122.0e-06  !  -      -      -     -
+		   rn_trfac(7)   =   1.0e-06  !  -      -      -     -
+		   rn_trfac(10)  =   1.0e-06  !  -      -      -     -
+	   	rn_trfac(14)  =   1.0e-06  !  -      -      -     -
+		   rn_trfac(23)  =   7.6e-06  !  -      -      -     -
+		
+	   	cn_dir        =  './'      !  root directory for the location of the data files
+
+PISCES forcing files
+--------------------
+
+They might be on the coarsened grid.
+
+Perspectives
+============
+
+For the future, a few options are on the table to implement coarsening for biogeochemistry in 4.0 and
+future releases.
+Those will be discussed in Autumn 2018
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/DOM/domvvl.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/DOM/domvvl.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/DOM/domvvl.F90	(revision 10345)
@@ -234,9 +234,11 @@
                END DO
             END DO
-            IF( cn_cfg == "orca" .AND. nn_cfg == 3 ) THEN   ! ORCA2: Suppress ztilde in the Foxe Basin for ORCA2
-               ii0 = 103   ;   ii1 = 111       
-               ij0 = 128   ;   ij1 = 135   ;   
-               frq_rst_e3t( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  0.0_wp
-               frq_rst_hdv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  1.e0_wp / rdt
+            IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN
+               IF( nn_cfg == 3 ) THEN   ! ORCA2: Suppress ztilde in the Foxe Basin for ORCA2
+                  ii0 = 103   ;   ii1 = 111       
+                  ij0 = 128   ;   ij1 = 135   ;   
+                  frq_rst_e3t( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  0.0_wp
+                  frq_rst_hdv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  1.e0_wp / rdt
+               ENDIF
             ENDIF
          ENDIF
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/DOM/dtatsd.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/DOM/dtatsd.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/DOM/dtatsd.F90	(revision 10345)
@@ -150,25 +150,27 @@
       !
       !                                   !==   ORCA_R2 configuration and T & S damping   ==! 
-      IF( cn_cfg == "orca" .AND. nn_cfg == 2 .AND. ln_tsd_dmp ) THEN    ! some hand made alterations
-         !
-         ij0 = 101   ;   ij1 = 109                       ! Reduced T & S in the Alboran Sea
-         ii0 = 141   ;   ii1 = 155
-         DO jj = mj0(ij0), mj1(ij1)
-            DO ji = mi0(ii0), mi1(ii1)
-               sf_tsd(jp_tem)%fnow(ji,jj,13:13) = sf_tsd(jp_tem)%fnow(ji,jj,13:13) - 0.20_wp
-               sf_tsd(jp_tem)%fnow(ji,jj,14:15) = sf_tsd(jp_tem)%fnow(ji,jj,14:15) - 0.35_wp
-               sf_tsd(jp_tem)%fnow(ji,jj,16:25) = sf_tsd(jp_tem)%fnow(ji,jj,16:25) - 0.40_wp
-               !
-               sf_tsd(jp_sal)%fnow(ji,jj,13:13) = sf_tsd(jp_sal)%fnow(ji,jj,13:13) - 0.15_wp
-               sf_tsd(jp_sal)%fnow(ji,jj,14:15) = sf_tsd(jp_sal)%fnow(ji,jj,14:15) - 0.25_wp
-               sf_tsd(jp_sal)%fnow(ji,jj,16:17) = sf_tsd(jp_sal)%fnow(ji,jj,16:17) - 0.30_wp
-               sf_tsd(jp_sal)%fnow(ji,jj,18:25) = sf_tsd(jp_sal)%fnow(ji,jj,18:25) - 0.35_wp
+      IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN
+         IF( nn_cfg == 2 .AND. ln_tsd_dmp ) THEN    ! some hand made alterations
+            !
+            ij0 = 101   ;   ij1 = 109                       ! Reduced T & S in the Alboran Sea
+            ii0 = 141   ;   ii1 = 155
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  sf_tsd(jp_tem)%fnow(ji,jj,13:13) = sf_tsd(jp_tem)%fnow(ji,jj,13:13) - 0.20_wp
+                  sf_tsd(jp_tem)%fnow(ji,jj,14:15) = sf_tsd(jp_tem)%fnow(ji,jj,14:15) - 0.35_wp
+                  sf_tsd(jp_tem)%fnow(ji,jj,16:25) = sf_tsd(jp_tem)%fnow(ji,jj,16:25) - 0.40_wp
+                  !
+                  sf_tsd(jp_sal)%fnow(ji,jj,13:13) = sf_tsd(jp_sal)%fnow(ji,jj,13:13) - 0.15_wp
+                  sf_tsd(jp_sal)%fnow(ji,jj,14:15) = sf_tsd(jp_sal)%fnow(ji,jj,14:15) - 0.25_wp
+                  sf_tsd(jp_sal)%fnow(ji,jj,16:17) = sf_tsd(jp_sal)%fnow(ji,jj,16:17) - 0.30_wp
+                  sf_tsd(jp_sal)%fnow(ji,jj,18:25) = sf_tsd(jp_sal)%fnow(ji,jj,18:25) - 0.35_wp
+               END DO
             END DO
-         END DO
-         ij0 =  87   ;   ij1 =  96                          ! Reduced temperature in Red Sea
-         ii0 = 148   ;   ii1 = 160
-         sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ,  4:10 ) = 7.0_wp
-         sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 11:13 ) = 6.5_wp
-         sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 14:20 ) = 6.0_wp
+            ij0 =  87   ;   ij1 =  96                          ! Reduced temperature in Red Sea
+            ii0 = 148   ;   ii1 = 160
+            sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ,  4:10 ) = 7.0_wp
+            sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 11:13 ) = 6.5_wp
+            sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 14:20 ) = 6.0_wp
+         ENDIF
       ENDIF
 !!gm end
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/DYN/dynspg_ts.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/DYN/dynspg_ts.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/DYN/dynspg_ts.F90	(revision 10345)
@@ -1114,10 +1114,4 @@
                             &   ) * ssvmask(ji,jj)
  
-!jth implicit bottom friction:
-                  IF ( ll_wd ) THEN ! revert to explicit for bit comparison tests in non wad runs
-                     ua_e(ji,jj) =  ua_e(ji,jj) /(1.0 -   rdtbt * zCdU_u(ji,jj) * hur_e(ji,jj))
-                     va_e(ji,jj) =  va_e(ji,jj) /(1.0 -   rdtbt * zCdU_v(ji,jj) * hvr_e(ji,jj))
-                  ENDIF
-
                END DO
             END DO
@@ -1144,4 +1138,13 @@
                             &               +    hv_n(ji,jj)  * zv_frc(ji,jj) ) &
                             &   ) * zhvra
+               END DO
+            END DO
+         ENDIF
+!jth implicit bottom friction:
+         IF ( ll_wd ) THEN ! revert to explicit for bit comparison tests in non wad runs
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                     ua_e(ji,jj) =  ua_e(ji,jj) /(1.0 -   rdtbt * zCdU_u(ji,jj) * hur_e(ji,jj))
+                     va_e(ji,jj) =  va_e(ji,jj) /(1.0 -   rdtbt * zCdU_v(ji,jj) * hvr_e(ji,jj))
                END DO
             END DO
@@ -1393,5 +1396,5 @@
       IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
          !                                   ! ---------------
-         IF( ln_rstart .AND. ln_bt_fw ) THEN    !* Read the restart file
+         IF( ln_rstart .AND. ln_bt_fw .AND. (neuler/=0) ) THEN    !* Read the restart file
             CALL iom_get( numror, jpdom_autoglo, 'ub2_b'  , ub2_b  (:,:), ldxios = lrxios )   
             CALL iom_get( numror, jpdom_autoglo, 'vb2_b'  , vb2_b  (:,:), ldxios = lrxios ) 
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/ICB/icbutl.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/ICB/icbutl.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/ICB/icbutl.F90	(revision 10345)
@@ -24,4 +24,6 @@
 #if defined key_si3
    USE ice,    ONLY: u_ice, v_ice, hm_i    ! SI3 variables
+   USE icevar                              ! ice_var_sshdyn
+   USE sbc_ice, ONLY: snwice_mass, snwice_mass_b
 #endif
 
@@ -60,5 +62,8 @@
       !! ** Method  : - blah blah
       !!----------------------------------------------------------------------
-
+#if defined key_si3
+      REAL(wp), DIMENSION(jpi,jpj) :: zssh_lead_m    !    ocean surface (ssh_m) if ice is not embedded
+      !                                              !    ocean surface in leads if ice is embedded   
+#endif
       ! copy nemo forcing arrays into iceberg versions with extra halo
       ! only necessary for variables not on T points
@@ -84,14 +89,18 @@
       ui_e(:,:) = 0._wp ;   ui_e(1:jpi, 1:jpj) = u_ice(:,:)
       vi_e(:,:) = 0._wp ;   vi_e(1:jpi, 1:jpj) = v_ice(:,:)
+      !      
+      ! compute ssh slope using ssh_lead if embedded
+      zssh_lead_m(:,:) = ice_var_sshdyn(ssh_m, snwice_mass, snwice_mass_b)
+      ssh_e(:,:) = 0._wp ;  ssh_e(1:jpi, 1:jpj) = zssh_lead_m(:,:) * tmask(:,:,1)
       !
       CALL lbc_lnk_icb( 'icbutl', hicth, 'T', +1._wp, 1, 1 )
       CALL lbc_lnk_icb( 'icbutl', ui_e , 'U', -1._wp, 1, 1 )
       CALL lbc_lnk_icb( 'icbutl', vi_e , 'V', -1._wp, 1, 1 )
+#else
+      ssh_e(:,:) = 0._wp ;  ssh_e(1:jpi, 1:jpj) = ssh_m(:,:) * tmask(:,:,1)
 #endif
 
       !! special for ssh which is used to calculate slope
       !! so fudge some numbers all the way around the boundary
-
-      ssh_e(:,:) = 0._wp ;   ssh_e(1:jpi, 1:jpj) = ssh_m(:,:) * tmask(:,:,1)
       ssh_e(0    ,    :) = ssh_e(1  ,  :)
       ssh_e(jpi+1,    :) = ssh_e(jpi,  :)
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/IOM/iom.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/IOM/iom.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/IOM/iom.F90	(revision 10345)
@@ -43,4 +43,7 @@
    USE ioipsl, ONLY :  ju2ymds    ! for calendar
    USE crs             ! Grid coarsening
+#if defined key_top
+   USE trc, ONLY    :  profsed
+#endif
    USE lib_fortran 
    USE diurnal_bulk, ONLY : ln_diurnal_only, ln_diurnal
@@ -193,8 +196,8 @@
       ! vertical grid definition
       IF(.NOT.llrst_context) THEN
-          CALL iom_set_axis_attr( "deptht", paxis = gdept_1d )
-          CALL iom_set_axis_attr( "depthu", paxis = gdept_1d )
-          CALL iom_set_axis_attr( "depthv", paxis = gdept_1d )
-          CALL iom_set_axis_attr( "depthw", paxis = gdepw_1d )
+          CALL iom_set_axis_attr( "deptht",  paxis = gdept_1d )
+          CALL iom_set_axis_attr( "depthu",  paxis = gdept_1d )
+          CALL iom_set_axis_attr( "depthv",  paxis = gdept_1d )
+          CALL iom_set_axis_attr( "depthw",  paxis = gdepw_1d )
 
           ! Add vertical grid bounds
@@ -219,4 +222,7 @@
           CALL iom_set_axis_attr( "nstrait", (/ (REAL(ji,wp), ji=1,4) /) )
 # endif
+#if defined key_top
+          CALL iom_set_axis_attr( "profsed", paxis = profsed )
+#endif
           CALL iom_set_axis_attr( "icbcla", class_num )
           CALL iom_set_axis_attr( "iax_20C", (/ REAL(20,wp) /) )
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/LBC/lbclnk.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/LBC/lbclnk.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/LBC/lbclnk.F90	(revision 10345)
@@ -173,5 +173,5 @@
 
    !!----------------------------------------------------------------------
-   !!                   ***  routine lbc_bdy_lnk_(2,3)d  ***
+   !!                   ***  routine lbc_bdy_lnk_(2,3,4)d  ***
    !!
    !!   wrapper rountine to 'lbc_lnk_3d'. This wrapper is used
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/LBC/mppini.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/LBC/mppini.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/LBC/mppini.F90	(revision 10345)
@@ -139,5 +139,5 @@
       !!----------------------------------------------------------------------
       INTEGER ::   ji, jj, jn, jproc, jarea   ! dummy loop indices
-      INTEGER ::   inij, inijmin
+      INTEGER ::   inijmin
       INTEGER ::   i2add
       INTEGER ::   inum                       ! local logical unit
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/OBS/README.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/OBS/README.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/OBS/README.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../doc/rst/source/data_assimilation.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/README.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/README.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/README.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../../doc/rst/source/coupling.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/sbcblk.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/sbcblk.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/sbcblk.F90	(revision 10345)
@@ -239,5 +239,5 @@
       !drag coefficient read from wave model definable only with mfs bulk formulae and core 
          ELSEIF (ln_cdgw .AND. .NOT. ln_NCAR )       THEN       
-             CALL ctl_stop( 'drag coefficient read from wave model definable only with mfs bulk formulae and core')
+             CALL ctl_stop( 'drag coefficient read from wave model definable only with NCAR and CORE bulk formulae')
          ELSEIF (ln_stcor .AND. .NOT. ln_sdw)                             THEN
              CALL ctl_stop( 'Stokes-Coriolis term calculated only if activated Stokes Drift ln_sdw=T')
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/sbcblk_algo_ncar.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/sbcblk_algo_ncar.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/sbcblk_algo_ncar.F90	(revision 10345)
@@ -149,4 +149,6 @@
       Ch = 1.e-3*sqrt_Cd_n10*(18.*stab + 32.7*(1. - stab))
       stab = sqrt_Cd_n10   ! Temporaty array !!! stab == SQRT(Cd)
+ 
+      IF( ln_cdgw )   Cen = Ce  ; Chn = Ch
 
       !! Initializing values at z_u with z_t values:
@@ -186,5 +188,12 @@
          IF( ln_cdgw ) THEN      ! surface wave case
             stab = vkarmn / ( vkarmn / sqrt_Cd_n10 - ztmp2 )  ! (stab == SQRT(Cd))
-            Cd      = stab * stab
+            Cd   = stab * stab
+            ztmp0 = (LOG(zu/10.) - zpsi_h_u) / vkarmn / sqrt_Cd_n10
+            ztmp2 = stab / sqrt_Cd_n10   ! (stab == SQRT(Cd))
+            ztmp1 = 1. + Chn * ztmp0     
+            Ch    = Chn * ztmp2 / ztmp1  ! L&Y 2004 eq. (10b)
+            ztmp1 = 1. + Cen * ztmp0
+            Ce    = Cen * ztmp2 / ztmp1  ! L&Y 2004 eq. (10c)
+
          ELSE
             ! Update neutral wind speed at 10m and neutral Cd at 10m (L&Y 2004 eq. 9a)...
@@ -205,15 +214,15 @@
             Cd      = ztmp0 / ( ztmp1*ztmp1 )
             stab = SQRT( Cd ) ! Temporary array !!! (stab == SQRT(Cd))
-         ENDIF
-
-         ztmp0 = (LOG(zu/10.) - zpsi_h_u) / vkarmn / sqrt_Cd_n10
-         ztmp2 = stab / sqrt_Cd_n10   ! (stab == SQRT(Cd))
-         ztmp1 = 1. + Cx_n10*ztmp0    ! (Cx_n10 == Ch_n10)
-         Ch  = Cx_n10*ztmp2 / ztmp1   ! L&Y 2004 eq. (10b)
-
-         Cx_n10  = 1.e-3 * (34.6 * sqrt_Cd_n10)  ! L&Y 2004 eq. (6b)    ! Cx_n10 == Ce_n10
-         Cen(:,:) = Cx_n10
-         ztmp1 = 1. + Cx_n10*ztmp0
-         Ce  = Cx_n10*ztmp2 / ztmp1  ! L&Y 2004 eq. (10c)
+
+            ztmp0 = (LOG(zu/10.) - zpsi_h_u) / vkarmn / sqrt_Cd_n10
+            ztmp2 = stab / sqrt_Cd_n10   ! (stab == SQRT(Cd))
+            ztmp1 = 1. + Cx_n10*ztmp0    ! (Cx_n10 == Ch_n10)
+            Ch  = Cx_n10*ztmp2 / ztmp1   ! L&Y 2004 eq. (10b)
+
+            Cx_n10  = 1.e-3 * (34.6 * sqrt_Cd_n10)  ! L&Y 2004 eq. (6b)    ! Cx_n10 == Ce_n10
+            Cen(:,:) = Cx_n10
+            ztmp1 = 1. + Cx_n10*ztmp0
+            Ce  = Cx_n10*ztmp2 / ztmp1  ! L&Y 2004 eq. (10c)
+            ENDIF
          !
       END DO
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/sbcmod.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/sbcmod.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/sbcmod.F90	(revision 10345)
@@ -160,7 +160,10 @@
          WRITE(numout,*) '               wave modified ocean stress component ln_tauw       = ', ln_tauw
          WRITE(numout,*) '               Stokes coriolis term                 ln_stcor      = ', ln_stcor
-         WRITE(numout,*) '               neutral drag coefficient (CORE, MFS) ln_cdgw       = ', ln_cdgw
-      ENDIF
-      !
+         WRITE(numout,*) '               neutral drag coefficient (CORE,NCAR) ln_cdgw       = ', ln_cdgw
+      ENDIF
+      !
+      IF( .NOT.ln_wave ) THEN
+         ln_sdw = .false. ; ln_cdgw = .false. ; ln_tauwoc = .false. ; ln_tauw = .false. ; ln_stcor = .false.
+      ENDIF 
       IF( ln_sdw ) THEN
          IF( .NOT.(nn_sdrift==jp_breivik_2014 .OR. nn_sdrift==jp_li_2017 .OR. nn_sdrift==jp_peakfr) ) &
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/USR/README-setup-configs
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/USR/README-setup-configs	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/USR/README-setup-configs	(revision 10345)
@@ -0,0 +1,53 @@
+==============================================================
+== HOW TO set up user’s configuration in NEMO version 4.0 : ==
+==============================================================
+This document describes how a configuration is set up in NEMO.
+
+In NEMO 4.0 two types of configurations can be build: global/regional and idealized.
+
+- create ./cfgs/your_config
+- case 1: regional or global 
+    => ln_read_cfg = .true. in ./cfgs/your_config/EXP00/namelist_cfg (i.e. read domain_cfg.nc)
+- case 2: idealized 
+    =>in ./cfgs/your_config/EXP00/namelist_cfg :
+      ln_read_cfg = .false. (need to define usrdef_hgr.F90 and usrdef_zgr.F90) 
+      ln_usr = .true.       (need to define usrdef_sbc.F90)    
+    => copy ./src/OCE/USR in ./cfgs/your_config/MY_SRC routines nedeed to set up domain, forcing fields and initial state
+    
+  Routines in NEMOGCM/NEMO/OCE/USR define analytically the domain, the initial state and the surface boundary conditions for the reference configuration GYRE.
+	  •	usrdef_hgr.F90 and usrdef_zgr.F90 : define horizontal and vertical grid
+	  •	usrdef_sbc.F90    : provides at each time-step the surface boundary condition, i.e. the momentum, heat and freshwater fluxes
+	  •	usrdef_istate.F90 : defines initialization of the dynamics and tracers
+	  •	usrdef_fmask.F90  : used just in ORCA CONFIGURATIONS for alteration of f-point land/ocean mask in some straits 
+	  •	usrdef_closea.F90 : used just in ORCA CONFIGURATIONS for specific treatments associated with closed seas
+	  •	usrdef_nam.F90    : set the domain characteristics of a user configuration
+
+  Other analytical examples are given in ./tests.
+
+===========================================
+== The domain_cfg.nc file must contain : ==
+===========================================
+   int ORCA  , ORCA_index            : configuration name, configuration resolution
+   int jpiglo, jpjglo , jpkglo       : global domain sizes 
+   int jperio                        : lateral global domain b.c. 
+   int ln_zco, ln_zps, ln_sco        : flags for z-coordinate, z-coordinate with partial steps and s-coordinate 
+   int ln_isfcav                     : flag  for ice shelf cavities 
+   double glamt, glamu, glamv, glamf : geographic position 
+   double gphit, gphiu, gphiv, gphif : geographic position
+   double iff, ff_f, ff_t            : Coriolis parameter (if not on the sphere)
+   double e1t, e1u, e1v, e1f         : horizontal scale factors
+   double e2t, e2u, e2v, e2f         : horizontal scale factors
+   double ie1e2u_v, e1e2u, e1e2v     : U and V surfaces (if grid size reduction in some straits)
+   double e3t_1d, e3w_1d             : reference vertical scale factors at T and W points
+   double e3t_0, e3u_0, e3v_0, e3f_0, e3w_0 : vertical scale factors 3D coordinate at T,U,V,F and W points
+   double e3uw_0,e3vw_0              : vertical scale factors 3D coordinate at UW and VW points
+   int bottom_level, top_level       : last wet T-points, 1st wet T-points (for ice shelf cavities)
+
+=======================================
+= HOW TO CREATE domain_cfg.nc file : ==
+=======================================
+Two options are possible :
+
+ - users can create with his own tool the domain_cfg.nc with all mandatory fields.  
+
+ - tool is available in ./tools/DOMAINcfg based on NEMO 3.6 version. See ./tools/DOMAINcfg/README.
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/USR/README.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/USR/README.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/USR/README.rst	(revision 10345)
@@ -0,0 +1,256 @@
+==============================
+Setting up a new configuration
+==============================
+
+.. include:: .global.rst
+
+.. contents::
+
+Starting from an existing configuration
+=======================================
+
+There are three options to build a new configuration from an existing one:
+
+---------------------------------------------
+Option 1: Duplicate an existing configuration
+---------------------------------------------
+
+The NEMO so-called Reference Configurations cover a number of major features for NEMO setup
+(global, regional, 1D, using embeded zoom with AGRIF...)
+
+One can create a new configuration by duplicating one of the reference configurations
+(``ORCA2_LIM3_PISCES`` in the following example)
+
+.. code-block:: sh
+
+	makenemo –n 'ORCA2_LIM3_PISCES_MINE' -r 'ORCA2_LIM3_PISCES'
+
+------------------------------------
+Option 2: Duplicate with differences
+------------------------------------
+
+Create and compile a new configuration based on a reference configuration
+(``ORCA2_LIM3_PISCES`` in the following example) but with different pre-processor options.
+For this either add ``add_key`` or ``del_key`` keys as required; e.g.
+
+.. code-block:: sh
+
+	makenemo –n 'ORCA2_LIM3_PISCES_MINE' -r 'ORCA2_LIM3_PISCES' del_key 'key_iomput' add_key 'key_xios'
+
+---------------------------------------------------------
+Option 3: Use the SIREN tools to subset an existing model
+---------------------------------------------------------
+
+Define a regional configuration which is a sub- or super-set of an existing configuration.
+
+This last option employs the SIREN software tools that are included in the standard distribution.
+The software is written in Fortran 95 and available in the ``./tools/SIREN`` directory.
+SIREN allows you to create your own regional configuration embedded in a wider one.
+
+SIREN is a set of programs to create all the input files you need to run a NEMO regional configuration.
+As a basic demonstrator, a set of GLORYS files (GLObal ReanalYSis on the ORCA025 grid),
+as well as examples of namelists are available `here`_.
+
+`SIREN documentation`_
+
+Any questions or comments regarding the use of SIREN should be posted in `the corresponding forum`_.
+
+Creating a completely new configuration
+=======================================
+
+From NEMO version 4.0 there are two ways to build configurations from scratch.
+The appropriate method to use depends largely on the target configuration.
+Method 1 is for more complex/realistic global or regional configurations and
+method 2 is intended for simpler, idealised configurations whose
+domains and characteristics can be described in simple geometries and formulae.
+
+----------------------------------------------------
+Option 1: Create and use a domain configuration file
+----------------------------------------------------
+
+This method is used by each of the reference configurations,
+so that downloading their input files linked to their description can help.
+Although starting from scratch it is advisable to create the directory structure to house your new configuration by
+duplicating the closest reference configuration to your target application.
+For example, if your application requires both ocean ice and passive tracers,
+then use the ``ORCA2_LIM3_PISCES`` as template,
+and execute following command to build your ``MY_NEW_CONFIG`` configuration:
+
+.. code-block:: sh
+
+	makenemo –n 'MY_NEW_CONFIG' -r 'ORCA2_LIM3_PISCES'
+
+where ``MY_NEW_CONFIG`` can be substituted with a suitably descriptive name for your new configuration.  
+
+The purpose of this step is simply to create and populate the appropriate ``WORK``, ``MY_SRC`` and
+``EXP00`` subdirectories for your new configuration.
+Other choices for the base reference configuration might be
+
+- ``GYRE``  - If your target application is ocean-only
+- ``AMM12`` - If your target application is regional with open boundaries
+
+All the domain information for your new configuration will be contained within
+a netcdf file called ``domain_cfg.nc`` which you will need to create and
+place in the ``./cfgs/MY_NEW_CONFIG/EXP00`` sub-directory.
+Firstly though, ensure that your configuration is set to use such a file by checking that
+
+.. code-block:: fortran
+
+	ln_read_cfg = .true.
+
+in	``./cfgs/MY_NEW_CONFIG/EXP00/namelist_cfg``
+
+Create the domain_cfg.nc file which must contain the following fields
+
+.. code-block:: c++
+
+	int    ORCA, ORCA_index                  /* configuration name, configuration resolution                 */
+	int    jpiglo, jpjglo, jpkglo            /* global domain sizes                                          */
+	int    jperio                            /* lateral global domain b.c.                                   */
+	int    ln_zco, ln_zps, ln_sco            /* flags for z-coord, z-coord with partial steps and s-coord    */
+	int    ln_isfcav                         /* flag  for ice shelf cavities                                 */
+	double glamt, glamu, glamv, glamf        /* geographic position                                          */
+	double gphit, gphiu, gphiv, gphif        /* geographic position                                          */
+	double iff, ff_f, ff_t                   /* Coriolis parameter (if not on the sphere)                    */
+	double e1t, e1u, e1v, e1f                /* horizontal scale factors                                     */
+	double e2t, e2u, e2v, e2f                /* horizontal scale factors                                     */
+	double ie1e2u_v, e1e2u, e1e2v            /* U and V surfaces (if grid size reduction in some straits)    */
+	double e3t_1d, e3w_1d                    /* reference vertical scale factors at T and W points           */
+	double e3t_0, e3u_0, e3v_0, e3f_0, e3w_0 /* vertical scale factors 3D coordinate at T,U,V,F and W points */
+	double e3uw_0, e3vw_0                    /* vertical scale factors 3D coordinate at UW and VW points     */
+	int    bottom_level, top_level           /* last wet T-points, 1st wet T-points (for ice shelf cavities) */
+
+There are two options for creating a domain_cfg.nc file:
+
+- Users can use tools of their own choice to build a ``domain_cfg.nc`` with all mandatory fields.
+- Users can adapt and apply the supplied tool available in ``./tools/DOMAINcfg``.
+  This tool is based on code extracted from NEMO version 3.6 and will allow similar choices for
+  the horizontal and vertical grids that were available internally to that version.
+  See ``./tools/DOMAINcfg/README`` for details.
+
+-----------------------------------------------------------------------------
+Option 2: Adapt the usr_def configuration module of NEMO for you own purposes
+-----------------------------------------------------------------------------
+
+This method is intended for configuring easily simple/idealised configurations which
+are often used as demonstrators or for process evaluation and comparison.
+This method can be used whenever the domain geometry has a simple mathematical description and
+the ocean initial state and boundary forcing is described analytically. 
+As a start, consider the case of starting a completely new ocean-only test case based on
+the ``LOCK_EXCHANGE`` example.
+[Note: we probably need an even more basic example than this with only one namelist and
+minimal changes to the usrdef modules]
+
+Firstly, construct the directory structure, starting in the ``cfgs`` directory:
+
+.. code-block:: sh
+
+	./makenemo -n 'MY_NEW_TEST' -t 'LOCK_EXCHANGE'
+
+where the ``-t`` option has been used to locate the new configuration in the ``tests`` subdirectory
+(it is recommended practice to keep full configurations and idealised cases clearly distinguishable).
+This command will have created (amongst others) the following files and directories::
+
+	./tests/MY_NEW_TEST:
+	BLD	  MY_SRC cpp_MY_NEW_TEST.fcm
+	EXP00   WORK
+	#
+	./tests/MY_NEW_TEST/EXP00:
+	context_nemo.xml       domain_def_nemo.xml
+	field_def_nemo-opa.xml file_def_nemo-opa.xml
+	iodef.xml
+	namelist_cfg
+	namelist_ref
+	#
+	./tests/MY_NEW_TEST/MY_SRC:
+	usrdef_hgr.F90    usrdef_nam.F90 usrdef_zgr.F90
+	usrdef_istate.F90 usrdef_sbc.F90 zdfini.F90
+
+The key to setting up an idealised configuration lies in adapting a small set of short Fortran 90 modules which
+should be dropped into the ``MY_SRC`` directory.
+Here the ``LOCK_EXCHANGE`` example is using 5 such routines but the full set that is available in
+the ``src/OCE/USR`` directory is::
+
+	./src/OCE/USR:
+	usrdef_closea.F90 usrdef_istate.F90 usrdef_zgr.F90
+	usrdef_fmask.F90  usrdef_nam.F90
+	usrdef_hgr.F90    usrdef_sbc.F90
+
+Before discussing these in more detail it is worth noting the various namelist controls that
+engage the different user-defined aspects.
+These controls are set using two new logical switches or are implied by the settings of existing ones.
+For example, the mandatory requirement for an idealised configuration is to provide routines which
+define the horizontal and vertical domains.
+Templates for these are provided in the ``usrdef_hgr.F90`` and ``usrdef_zgr.F90`` modules.
+The application of these modules is activated whenever:
+
+.. code-block:: fortran
+
+	ln_read_cfg = .false.
+
+in any configuration's ``namelist_cfg`` file.
+This setting also activates the reading of an optional ``nam_usrdef`` namelist which can be used to
+supply configuration specific settings.
+These need to be declared and read in the ``usrdef_nam.F90`` module.
+
+Another explicit control is available in the ``namsbc`` namelist which activates the use of analytical forcing.
+With
+
+.. code-block:: fortran
+
+	ln_usr = .true.
+
+Other usrdef modules are activated by less explicit means.
+For example, code in ``usrdef_istate.F90`` is used to define initial temperature and salinity fields if
+
+.. code-block:: fortran
+
+	ln_tsd_init   = .false.
+
+in the ``namtsd`` namelist.
+The remaining modules, namely::
+
+	usrdef_closea.F90 usrdef_fmask.F90
+
+are specific to ORCA configurations and set local variations of some specific fields for
+the various resolutions of the global models.
+They do not need to be considered here in the context of idealised cases but it is worth noting that all
+configuration specific code has now been isolated in the usrdef modules.
+In the case of these last two modules, they are activated only if an ORCA configuration is detected.
+Currently this requires a specific integer variable named ``ORCA`` to be set in a ``domain_cfg.nc`` file.
+[Note: this would be less confusing if the cn_cfg string is read directly as a character attribue from
+the ``domain_cfg.nc`` ]
+
+So, in most cases, the set up of idealised model configurations can be completed by
+copying the template routines from ``./src/OCE/USR`` into
+your new ``./cfgs/MY_NEW_TEST/MY_SRC`` directory and editing the appropriate modules as needed.
+The default set are those used for the GYRE reference configuration.
+The contents of ``MY_SRC`` directories from other idealised configurations may provide more convenient templates if
+they share common characteristics with your target application.
+
+Whatever the starting point it should not require too many changes or additional lines of code to
+produce routines in ``./src/OCE/USR`` that define analytically the domain,
+the initial state and the surface boundary conditions for your new configuration.
+
+To summarize, the base set of modules is:
+
+- ``usrdef_hgr.F90``   : define horizontal grid
+- ``usrdef_zgr.F90``   : define vertical grid
+- ``usrdef_sbc.F90``   : provides at each time-step the surface boundary condition, i.e. the momentum, heat and freshwater fluxes
+- ``usrdef_istate.F90``: defines initialization of the dynamics and tracers
+- ``usrdef_nam.F90``   : configuration-specific namelist processing to set any associated run-time parameters
+
+with two specialised ORCA modules
+(not related to idealised configurations but used to isolate configuration specific code that is used in
+ORCA2 reference configurations and established global configurations using the ORCA tripolar grid):
+
+- ``usrdef_fmask.F90`` : only used in ORCA CONFIGURATIONS for alteration of f-point land/ocean mask in some straits
+- ``usrdef_closea.F90``: only used in ORCA CONFIGURATIONS for specific treatments associated with closed seas
+
+From version 4.0, the NEMO release includes a ``tests`` subdirectory containing available and
+up to date test cases build by the community.
+These will not be fully supported as is NEMO reference but should provide a source of raw material.
+
+.. _here:                     http://prodn.idris.fr/thredds/catalog/ipsl_public/rron463/catalog.html?dataset=DatasetScanipsl_public/rron463/INPUT_SIREN.tar
+.. _the corresponding forum:  http://forge.ipsl.jussieu.fr/nemo/discussion/forum/2
+.. _SIREN documentation:      http://forge.ipsl.jussieu.fr/nemo/doxygen/index.html
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/ZDF/zdfgls.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/ZDF/zdfgls.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/ZDF/zdfgls.F90	(revision 10345)
@@ -275,11 +275,11 @@
                ! building the matrix
                zcof = rfact_tke * tmask(ji,jj,jk)
-               !                                               ! lower diagonal
+               !                                        ! lower diagonal, in fact not used for jk = 2 (see surface conditions)
                zd_lw(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk  ) + p_avm(ji,jj,jk-1) ) / ( e3t_n(ji,jj,jk-1) * e3w_n(ji,jj,jk) )
-               !                                               ! upper diagonal
+               !                                        ! upper diagonal, in fact not used for jk = ibotm1 (see bottom conditions)
                zd_up(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk+1) + p_avm(ji,jj,jk  ) ) / ( e3t_n(ji,jj,jk  ) * e3w_n(ji,jj,jk) )
-               !                                               ! diagonal
+               !                                        ! diagonal
                zdiag(ji,jj,jk) = 1._wp - zd_lw(ji,jj,jk) - zd_up(ji,jj,jk)  + rdt * zdiss * wmask(ji,jj,jk) 
-               !                                               ! right hand side in en
+               !                                        ! right hand side in en
                en(ji,jj,jk) = en(ji,jj,jk) + rdt * zesh2 * wmask(ji,jj,jk)
             END DO
@@ -792,9 +792,15 @@
       zstm(:,:,1) = zstm(:,:,2)
 
-      DO jj = 2, jpjm1
+      ! default value, in case jpk > mbkt(ji,jj)+1. Not needed but avoid a bug when looking for undefined values (-fpe0)
+      zstm(:,:,jpk) = 0.  
+      DO jj = 2, jpjm1                ! update bottom with good values
          DO ji = fs_2, fs_jpim1   ! vector opt.
             zstm(ji,jj,mbkt(ji,jj)+1) = zstm(ji,jj,mbkt(ji,jj))
          END DO
       END DO
+
+      zstt(:,:,  1) = wmask(:,:,  1)  ! default value not needed but avoid a bug when looking for undefined values (-fpe0)
+      zstt(:,:,jpk) = wmask(:,:,jpk)  ! default value not needed but avoid a bug when looking for undefined values (-fpe0)
+
 !!gm should be done for ISF (top boundary cond.)
 !!gm so, totally new staff needed!!gm
@@ -802,4 +808,7 @@
       ! Compute diffusivities/viscosities
       ! The computation below could be restrained to jk=2 to jpkm1 if GOTM style Dirichlet conditions are used
+      !  -> yes BUT p_avm(:,:1) and p_avm(:,:jpk) are used when we compute zd_lw(:,:2) and zd_up(:,:jpkm1). These values are
+      !     later overwritten by surface/bottom boundaries conditions, so we don't really care of p_avm(:,:1) and p_avm(:,:jpk)
+      !     for zd_lw and zd_up but they have to be defined to avoid a bug when looking for undefined values (-fpe0)
       DO jk = 1, jpk
          DO jj = 2, jpjm1
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OFF/dtadyn.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OFF/dtadyn.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OFF/dtadyn.F90	(revision 10345)
@@ -46,7 +46,9 @@
    PRIVATE
 
-   PUBLIC   dta_dyn_init   ! called by opa.F90
-   PUBLIC   dta_dyn        ! called by step.F90
-   PUBLIC   dta_dyn_swp   ! called by step.F90
+   PUBLIC   dta_dyn_init       ! called by opa.F90
+   PUBLIC   dta_dyn            ! called by step.F90
+   PUBLIC   dta_dyn_sed_init   ! called by opa.F90
+   PUBLIC   dta_dyn_sed        ! called by step.F90
+   PUBLIC   dta_dyn_swp        ! called by step.F90
 
    CHARACTER(len=100) ::   cn_dir          !: Root directory for location of ssr files
@@ -164,4 +166,5 @@
       hmld(:,:)       = sf_dyn(jf_mld)%fnow(:,:,1) * tmask(:,:,1)    ! mixed layer depht
       avt(:,:,:)      = sf_dyn(jf_avt)%fnow(:,:,:) * tmask(:,:,:)    ! vertical diffusive coefficient 
+      avs(:,:,:)      = avt(:,:,:)
       !
       IF( ln_trabbl .AND. .NOT.lk_c1d ) THEN       ! diffusive Bottom boundary layer param 
@@ -182,10 +185,4 @@
          CALL prt_ctl(tab3d_1=uslp             , clinfo1=' slp  - u : ', tab3d_2=vslp, clinfo2=' v : ', kdim=jpk)
          CALL prt_ctl(tab3d_1=wslpi            , clinfo1=' slp  - wi: ', tab3d_2=wslpj, clinfo2=' wj: ', kdim=jpk)
-!         CALL prt_ctl(tab2d_1=fr_i             , clinfo1=' fr_i    - : ', mask1=tmask )
-!         CALL prt_ctl(tab2d_1=hmld             , clinfo1=' hmld    - : ', mask1=tmask )
-!         CALL prt_ctl(tab2d_1=fmmflx           , clinfo1=' fmmflx  - : ', mask1=tmask )
-!         CALL prt_ctl(tab2d_1=emp              , clinfo1=' emp     - : ', mask1=tmask )
-!         CALL prt_ctl(tab2d_1=wndm             , clinfo1=' wspd    - : ', mask1=tmask )
-!         CALL prt_ctl(tab2d_1=qsr              , clinfo1=' qsr     - : ', mask1=tmask )
       ENDIF
       !
@@ -418,4 +415,117 @@
    END SUBROUTINE dta_dyn_init
 
+   SUBROUTINE dta_dyn_sed( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dta_dyn  ***
+      !!
+      !! ** Purpose :  Prepares dynamics and physics fields from a NEMO run
+      !!               for an off-line simulation of passive tracers
+      !!
+      !! ** Method : calculates the position of data
+      !!             - computes slopes if needed
+      !!             - interpolates data if needed
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start( 'dta_dyn_sed')
+      !
+      nsecdyn = nsec_year + nsec1jan000   ! number of seconds between Jan. 1st 00h of nit000 year and the middle of time step
+      !
+      IF( kt == nit000 ) THEN    ;    nprevrec = 0
+      ELSE                       ;    nprevrec = sf_dyn(jf_tem)%nrec_a(2)
+      ENDIF
+      CALL fld_read( kt, 1, sf_dyn )      !=  read data at kt time step   ==!
+      !
+      tsn(:,:,:,jp_tem) = sf_dyn(jf_tem)%fnow(:,:,:)  * tmask(:,:,:)    ! temperature
+      tsn(:,:,:,jp_sal) = sf_dyn(jf_sal)%fnow(:,:,:)  * tmask(:,:,:)    ! salinity
+      !
+      CALL eos    ( tsn, rhd, rhop, gdept_0(:,:,:) ) ! In any case, we need rhop
+
+      IF(ln_ctl) THEN                  ! print control
+         CALL prt_ctl(tab3d_1=tsn(:,:,:,jp_tem), clinfo1=' tn      - : ', mask1=tmask,  kdim=jpk   )
+         CALL prt_ctl(tab3d_1=tsn(:,:,:,jp_sal), clinfo1=' sn      - : ', mask1=tmask,  kdim=jpk   )
+      ENDIF
+      !
+      IF( ln_timing )   CALL timing_stop( 'dta_dyn_sed')
+      !
+   END SUBROUTINE dta_dyn_sed
+
+
+   SUBROUTINE dta_dyn_sed_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dta_dyn_init  ***
+      !!
+      !! ** Purpose :   Initialisation of the dynamical data
+      !! ** Method  : - read the data namdta_dyn namelist
+      !!----------------------------------------------------------------------
+      INTEGER  :: ierr, ierr0, ierr1, ierr2, ierr3   ! return error code
+      INTEGER  :: ifpr                               ! dummy loop indice
+      INTEGER  :: jfld                               ! dummy loop arguments
+      INTEGER  :: inum, idv, idimv                   ! local integer
+      INTEGER  :: ios                                ! Local integer output status for namelist read
+      !!
+      CHARACTER(len=100)            ::  cn_dir        !   Root directory for location of core files
+      TYPE(FLD_N), DIMENSION(2) ::  slf_d         ! array of namelist informations on the fields to read
+      TYPE(FLD_N) :: sn_tem , sn_sal   !   "                 "
+      !!
+      NAMELIST/namdta_dyn/cn_dir, ln_dynrnf, ln_dynrnf_depth,  fwbcorr, &
+         &                sn_tem, sn_sal
+      !!----------------------------------------------------------------------
+      !
+      REWIND( numnam_ref )              ! Namelist namdta_dyn in reference namelist : Offline: init. of dynamical data
+      READ  ( numnam_ref, namdta_dyn, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdta_dyn in reference namelist', lwp )
+      REWIND( numnam_cfg )              ! Namelist namdta_dyn in configuration namelist : Offline: init. of dynamical data
+      READ  ( numnam_cfg, namdta_dyn, IOSTAT = ios, ERR = 902 )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdta_dyn in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namdta_dyn )
+      !                                         ! store namelist information in an array
+      !                                         ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dta_dyn : offline dynamics '
+         WRITE(numout,*) '~~~~~~~ '
+         WRITE(numout,*) '   Namelist namdta_dyn'
+         WRITE(numout,*) '      runoffs option enabled (T) or not (F)            ln_dynrnf        = ', ln_dynrnf
+         WRITE(numout,*) '      runoffs is spread in vertical                    ln_dynrnf_depth  = ', ln_dynrnf_depth
+         WRITE(numout,*) '      annual global mean of empmr for ssh correction   fwbcorr          = ', fwbcorr
+         WRITE(numout,*)
+      ENDIF
+      !
+      jf_tem  = 1     ;   jf_sal  = 2    ;   jfld   = jf_sal
+      !
+      slf_d(jf_tem)  = sn_tem    ;   slf_d(jf_sal)  = sn_sal
+      !
+      ALLOCATE( sf_dyn(jfld), STAT=ierr )         ! set sf structure
+      IF( ierr > 0 )  THEN
+         CALL ctl_stop( 'dta_dyn: unable to allocate sf structure' )   ;   RETURN
+      ENDIF
+      !                                         ! fill sf with slf_i and control print
+      CALL fld_fill( sf_dyn, slf_d, cn_dir, 'dta_dyn_init', 'Data in file', 'namdta_dyn' )
+      !
+      ! Open file for each variable to get his number of dimension
+      DO ifpr = 1, jfld
+         CALL fld_clopn( sf_dyn(ifpr), nyear, nmonth, nday )
+         idv   = iom_varid( sf_dyn(ifpr)%num , slf_d(ifpr)%clvar )        ! id of the variable sdjf%clvar
+         idimv = iom_file ( sf_dyn(ifpr)%num )%ndims(idv)                 ! number of dimension for variable sdjf%clvar
+         IF( sf_dyn(ifpr)%num /= 0 )   CALL iom_close( sf_dyn(ifpr)%num ) ! close file if already open
+         ierr1=0
+         IF( idimv == 3 ) THEN    ! 2D variable
+                                      ALLOCATE( sf_dyn(ifpr)%fnow(jpi,jpj,1)    , STAT=ierr0 )
+            IF( slf_d(ifpr)%ln_tint ) ALLOCATE( sf_dyn(ifpr)%fdta(jpi,jpj,1,2)  , STAT=ierr1 )
+         ELSE                     ! 3D variable
+                                      ALLOCATE( sf_dyn(ifpr)%fnow(jpi,jpj,jpk)  , STAT=ierr0 )
+            IF( slf_d(ifpr)%ln_tint ) ALLOCATE( sf_dyn(ifpr)%fdta(jpi,jpj,jpk,2), STAT=ierr1 )
+         ENDIF
+         IF( ierr0 + ierr1 > 0 ) THEN
+            CALL ctl_stop( 'dta_dyn_init : unable to allocate sf_dyn array structure' )   ;   RETURN
+         ENDIF
+      END DO
+      !
+      CALL dta_dyn_sed( nit000 )
+      !
+   END SUBROUTINE dta_dyn_sed_init
 
    SUBROUTINE dta_dyn_swp( kt )
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OFF/nemogcm.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OFF/nemogcm.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OFF/nemogcm.F90	(revision 10345)
@@ -110,7 +110,10 @@
          IF( istp /= nit000 )   CALL day        ( istp )         ! Calendar (day was already called at nit000 in day_init)
                                 CALL iom_setkt  ( istp - nit000 + 1, cxios_context )   ! say to iom that we are at time step kstp
+#if defined key_sed_off
+                                CALL dta_dyn_sed( istp )         ! Interpolation of the dynamical fields
+#else
                                 CALL dta_dyn    ( istp )         ! Interpolation of the dynamical fields
          IF( .NOT.ln_linssh )   CALL dta_dyn_swp( istp )         ! swap of sea  surface height and vertical scale factors
-
+#endif
                                 CALL trc_stp    ( istp )         ! time-stepping
                                 CALL stp_ctl    ( istp, indic )  ! Time loop: control and print
@@ -287,5 +290,9 @@
                            CALL trc_nam_run    ! Needed to get restart parameters for passive tracers
                            CALL trc_rst_cal( nit000, 'READ' )   ! calendar
+#if defined key_sed_off
+                           CALL dta_dyn_sed_init ! Initialization for the dynamics
+#else
                            CALL dta_dyn_init   ! Initialization for the dynamics
+#endif
 
                            CALL     trc_init   ! Passive tracers initialization
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/SAS/README.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/SAS/README.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/SAS/README.rst	(revision 10345)
@@ -0,0 +1,1 @@
+link ../../doc/rst/source/coupling.rst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zbio.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zbio.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zbio.F90	(revision 10345)
@@ -15,10 +15,10 @@
    USE p4zsink         !  vertical flux of particulate matter due to sinking
    USE p4zopt          !  optical model
-   USE p4zice          !  Co-limitations of differents nutrients
+   USE p4zlim          !  Co-limitations of differents nutrients
    USE p4zprod         !  Growth rate of the 2 phyto groups
    USE p4zmort         !  Mortality terms for phytoplankton
    USE p4zmicro        !  Sources and sinks of microzooplankton
    USE p4zmeso         !  Sources and sinks of mesozooplankton
-   USE p5zice          !  Co-limitations of differents nutrients
+   USE p5zlim          !  Co-limitations of differents nutrients
    USE p5zprod         !  Growth rate of the 2 phyto groups
    USE p5zmort         !  Mortality terms for phytoplankton
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zche.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zche.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zche.F90	(revision 10345)
@@ -37,15 +37,15 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tempis   ! In situ temperature
 
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   akb3       !: ???
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   akw3       !: ???
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   akf3       !: ???
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   aks3       !: ???
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ak1p3      !: ???
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ak2p3      !: ???
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ak3p3      !: ???
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   aksi3      !: ???
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   borat      !: ???
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   fluorid    !: ???
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   sulfat     !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   akb3       !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   akw3       !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   akf3       !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   aks3       !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ak1p3      !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ak2p3      !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ak3p3      !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   aksi3      !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   borat      !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   fluorid    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   sulfat     !: ???
 
    !!* Variable for chemistry of the CO2 cycle
@@ -233,6 +233,4 @@
         END DO
 
-
-
       ! CHEMICAL CONSTANTS - DEEP OCEAN
       ! -------------------------------
@@ -449,5 +447,4 @@
       !
    END SUBROUTINE p4z_che
-
 
    SUBROUTINE ahini_for_at(p_hini)
Index: MO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zice.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zice.F90	(revision 10344)
+++ 	(revision )
@@ -1,313 +1,0 @@
-MODULE p4zice
-   !!======================================================================
-   !!                         ***  MODULE p4zice  ***
-   !! TOP :   PISCES 
-   !!======================================================================
-   !! History :   1.0  !  2004     (O. Aumont) Original code
-   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
-   !!             3.4  !  2011-04  (O. Aumont, C. Ethe) Limitation for iron modelled in quota 
-   !!----------------------------------------------------------------------
-   !!   p4z_lim        :   Compute the nutrients limitation terms 
-   !!   p4z_lim_init   :   Read the namelist 
-   !!----------------------------------------------------------------------
-   USE oce_trc         ! Shared ocean-passive tracers variables
-   USE trc             ! Tracers defined
-   USE sms_pisces      ! PISCES variables
-   USE iom             !  I/O manager
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC p4z_lim    
-   PUBLIC p4z_lim_init    
-   PUBLIC p4z_lim_alloc
-
-   !! * Shared module variables
-   REAL(wp), PUBLIC ::  concnno3    !:  NO3, PO4 half saturation   
-   REAL(wp), PUBLIC ::  concdno3    !:  Phosphate half saturation for diatoms  
-   REAL(wp), PUBLIC ::  concnnh4    !:  NH4 half saturation for phyto  
-   REAL(wp), PUBLIC ::  concdnh4    !:  NH4 half saturation for diatoms
-   REAL(wp), PUBLIC ::  concnfer    !:  Iron half saturation for nanophyto 
-   REAL(wp), PUBLIC ::  concdfer    !:  Iron half saturation for diatoms  
-   REAL(wp), PUBLIC ::  concbno3    !:  NO3 half saturation  for bacteria 
-   REAL(wp), PUBLIC ::  concbnh4    !:  NH4 half saturation for bacteria
-   REAL(wp), PUBLIC ::  xsizedia    !:  Minimum size criteria for diatoms
-   REAL(wp), PUBLIC ::  xsizephy    !:  Minimum size criteria for nanophyto
-   REAL(wp), PUBLIC ::  xsizern     !:  Size ratio for nanophytoplankton
-   REAL(wp), PUBLIC ::  xsizerd     !:  Size ratio for diatoms
-   REAL(wp), PUBLIC ::  xksi1       !:  half saturation constant for Si uptake 
-   REAL(wp), PUBLIC ::  xksi2       !:  half saturation constant for Si/C 
-   REAL(wp), PUBLIC ::  xkdoc       !:  2nd half-sat. of DOC remineralization  
-   REAL(wp), PUBLIC ::  concbfe     !:  Fe half saturation for bacteria 
-   REAL(wp), PUBLIC ::  oxymin      !:  half saturation constant for anoxia
-   REAL(wp), PUBLIC ::  qnfelim     !:  optimal Fe quota for nanophyto
-   REAL(wp), PUBLIC ::  qdfelim     !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  caco3r      !:  mean rainratio 
-
-   !!* Phytoplankton limitation terms
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanono3   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatno3   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanonh4   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatnh4   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanopo4   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatpo4   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimphy    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimdia    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimnfe    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimdfe    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimsi     !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimbac    !: ??
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimbacl   !: ??
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   concdfe    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   concnfe    !: ???
-
-   ! Coefficient for iron limitation
-   REAL(wp) ::  xcoef1   = 0.0016  / 55.85  
-   REAL(wp) ::  xcoef2   = 1.21E-5 * 14. / 55.85 / 7.625 * 0.5 * 1.5
-   REAL(wp) ::  xcoef3   = 1.15E-4 * 14. / 55.85 / 7.625 * 0.5 
-
-   !!----------------------------------------------------------------------
-   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
-   !! $Id$ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE p4z_lim( kt, knt )
-      !!---------------------------------------------------------------------
-      !!                     ***  ROUTINE p4z_lim  ***
-      !!
-      !! ** Purpose :   Compute the co-limitations by the various nutrients
-      !!              for the various phytoplankton species
-      !!
-      !! ** Method  : - ???
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in)  :: kt, knt
-      !
-      INTEGER  ::   ji, jj, jk
-      REAL(wp) ::   zlim1, zlim2, zlim3, zlim4, zno3, zferlim
-      REAL(wp) ::   zconcd, zconcd2, zconcn, zconcn2
-      REAL(wp) ::   z1_trbdia, z1_trbphy, ztem1, ztem2, zetot1, zetot2
-      REAL(wp) ::   zdenom, zratio, zironmin
-      REAL(wp) ::   zconc1d, zconc1dnh4, zconc0n, zconc0nnh4   
-      !!---------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start('p4z_lim')
-      !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               
-               ! Tuning of the iron concentration to a minimum level that is set to the detection limit
-               !-------------------------------------
-               zno3    = trb(ji,jj,jk,jpno3) / 40.e-6
-               zferlim = MAX( 3e-11 * zno3 * zno3, 5e-12 )
-               zferlim = MIN( zferlim, 7e-11 )
-               trb(ji,jj,jk,jpfer) = MAX( trb(ji,jj,jk,jpfer), zferlim )
-
-               ! Computation of a variable Ks for iron on diatoms taking into account
-               ! that increasing biomass is made of generally bigger cells
-               !------------------------------------------------
-               zconcd   = MAX( 0.e0 , trb(ji,jj,jk,jpdia) - xsizedia )
-               zconcd2  = trb(ji,jj,jk,jpdia) - zconcd
-               zconcn   = MAX( 0.e0 , trb(ji,jj,jk,jpphy) - xsizephy )
-               zconcn2  = trb(ji,jj,jk,jpphy) - zconcn
-               z1_trbphy   = 1. / ( trb(ji,jj,jk,jpphy) + rtrn )
-               z1_trbdia   = 1. / ( trb(ji,jj,jk,jpdia) + rtrn )
-
-               concdfe(ji,jj,jk) = MAX( concdfer, ( zconcd2 * concdfer + concdfer * xsizerd * zconcd ) * z1_trbdia )
-               zconc1d           = MAX( concdno3, ( zconcd2 * concdno3 + concdno3 * xsizerd * zconcd ) * z1_trbdia )
-               zconc1dnh4        = MAX( concdnh4, ( zconcd2 * concdnh4 + concdnh4 * xsizerd * zconcd ) * z1_trbdia )
-
-               concnfe(ji,jj,jk) = MAX( concnfer, ( zconcn2 * concnfer + concnfer * xsizern * zconcn ) * z1_trbphy )
-               zconc0n           = MAX( concnno3, ( zconcn2 * concnno3 + concnno3 * xsizern * zconcn ) * z1_trbphy )
-               zconc0nnh4        = MAX( concnnh4, ( zconcn2 * concnnh4 + concnnh4 * xsizern * zconcn ) * z1_trbphy )
-
-               ! Michaelis-Menten Limitation term for nutrients Small bacteria
-               ! -------------------------------------------------------------
-               zdenom = 1. /  ( concbno3 * concbnh4 + concbnh4 * trb(ji,jj,jk,jpno3) + concbno3 * trb(ji,jj,jk,jpnh4) )
-               xnanono3(ji,jj,jk) = trb(ji,jj,jk,jpno3) * concbnh4 * zdenom
-               xnanonh4(ji,jj,jk) = trb(ji,jj,jk,jpnh4) * concbno3 * zdenom
-               !
-               zlim1    = xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk)
-               zlim2    = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + concbnh4 )
-               zlim3    = trb(ji,jj,jk,jpfer) / ( concbfe + trb(ji,jj,jk,jpfer) )
-               zlim4    = trb(ji,jj,jk,jpdoc) / ( xkdoc   + trb(ji,jj,jk,jpdoc) )
-               xlimbacl(ji,jj,jk) = MIN( zlim1, zlim2, zlim3 )
-               xlimbac (ji,jj,jk) = MIN( zlim1, zlim2, zlim3 ) * zlim4
-
-               ! Michaelis-Menten Limitation term for nutrients Small flagellates
-               ! -----------------------------------------------
-               zdenom = 1. /  ( zconc0n * zconc0nnh4 + zconc0nnh4 * trb(ji,jj,jk,jpno3) + zconc0n * trb(ji,jj,jk,jpnh4) )
-               xnanono3(ji,jj,jk) = trb(ji,jj,jk,jpno3) * zconc0nnh4 * zdenom
-               xnanonh4(ji,jj,jk) = trb(ji,jj,jk,jpnh4) * zconc0n    * zdenom
-               !
-               zlim1    = xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk)
-               zlim2    = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zconc0nnh4 )
-               zratio   = trb(ji,jj,jk,jpnfe) * z1_trbphy 
-               zironmin = xcoef1 * trb(ji,jj,jk,jpnch) * z1_trbphy + xcoef2 * zlim1 + xcoef3 * xnanono3(ji,jj,jk)
-               zlim3    = MAX( 0.,( zratio - zironmin ) / qnfelim )
-               xnanopo4(ji,jj,jk) = zlim2
-               xlimnfe (ji,jj,jk) = MIN( 1., zlim3 )
-               xlimphy (ji,jj,jk) = MIN( zlim1, zlim2, zlim3 )
-               !
-               !   Michaelis-Menten Limitation term for nutrients Diatoms
-               !   ----------------------------------------------
-               zdenom   = 1. / ( zconc1d * zconc1dnh4 + zconc1dnh4 * trb(ji,jj,jk,jpno3) + zconc1d * trb(ji,jj,jk,jpnh4) )
-               xdiatno3(ji,jj,jk) = trb(ji,jj,jk,jpno3) * zconc1dnh4 * zdenom
-               xdiatnh4(ji,jj,jk) = trb(ji,jj,jk,jpnh4) * zconc1d    * zdenom
-               !
-               zlim1    = xdiatno3(ji,jj,jk) + xdiatnh4(ji,jj,jk)
-               zlim2    = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zconc1dnh4  )
-               zlim3    = trb(ji,jj,jk,jpsil) / ( trb(ji,jj,jk,jpsil) + xksi(ji,jj) )
-               zratio   = trb(ji,jj,jk,jpdfe) * z1_trbdia
-               zironmin = xcoef1 * trb(ji,jj,jk,jpdch) * z1_trbdia + xcoef2 * zlim1 + xcoef3 * xdiatno3(ji,jj,jk)
-               zlim4    = MAX( 0., ( zratio - zironmin ) / qdfelim )
-               xdiatpo4(ji,jj,jk) = zlim2
-               xlimdfe (ji,jj,jk) = MIN( 1., zlim4 )
-               xlimdia (ji,jj,jk) = MIN( zlim1, zlim2, zlim3, zlim4 )
-               xlimsi  (ji,jj,jk) = MIN( zlim1, zlim2, zlim4 )
-           END DO
-         END DO
-      END DO
-
-      ! Compute the fraction of nanophytoplankton that is made of calcifiers
-      ! --------------------------------------------------------------------
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zlim1 =  ( trb(ji,jj,jk,jpno3) * concnnh4 + trb(ji,jj,jk,jpnh4) * concnno3 )    &
-                  &   / ( concnno3 * concnnh4 + concnnh4 * trb(ji,jj,jk,jpno3) + concnno3 * trb(ji,jj,jk,jpnh4) ) 
-               zlim2  = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + concnnh4 )
-               zlim3  = trb(ji,jj,jk,jpfer) / ( trb(ji,jj,jk,jpfer) +  5.E-11   )
-               ztem1  = MAX( 0., tsn(ji,jj,jk,jp_tem) )
-               ztem2  = tsn(ji,jj,jk,jp_tem) - 10.
-               zetot1 = MAX( 0., etot_ndcy(ji,jj,jk) - 1.) / ( 4. + etot_ndcy(ji,jj,jk) ) 
-               zetot2 = 30. / ( 30. + etot_ndcy(ji,jj,jk) ) 
-
-               xfracal(ji,jj,jk) = caco3r * MIN( zlim1, zlim2, zlim3 )                  &
-                  &                       * ztem1 / ( 0.1 + ztem1 )                     &
-                  &                       * MAX( 1., trb(ji,jj,jk,jpphy) * 1.e6 / 2. )  &
-                  &                       * zetot1 * zetot2               &
-                  &                       * ( 1. + EXP(-ztem2 * ztem2 / 25. ) )         &
-                  &                       * MIN( 1., 50. / ( hmld(ji,jj) + rtrn ) )
-               xfracal(ji,jj,jk) = MIN( 0.8 , xfracal(ji,jj,jk) )
-               xfracal(ji,jj,jk) = MAX( 0.02, xfracal(ji,jj,jk) )
-            END DO
-         END DO
-      END DO
-      !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! denitrification factor computed from O2 levels
-               nitrfac(ji,jj,jk) = MAX(  0.e0, 0.4 * ( 6.e-6  - trb(ji,jj,jk,jpoxy) )    &
-                  &                                / ( oxymin + trb(ji,jj,jk,jpoxy) )  )
-               nitrfac(ji,jj,jk) = MIN( 1., nitrfac(ji,jj,jk) )
-               !
-               ! denitrification factor computed from NO3 levels
-               nitrfac2(ji,jj,jk) = MAX( 0.e0,       ( 1.E-6 - trb(ji,jj,jk,jpno3) )  &
-                  &                                / ( 1.E-6 + trb(ji,jj,jk,jpno3) ) )
-               nitrfac2(ji,jj,jk) = MIN( 1., nitrfac2(ji,jj,jk) )
-            END DO
-         END DO
-      END DO
-      !
-      IF( lk_iomput .AND. knt == nrdttrc ) THEN        ! save output diagnostics
-        IF( iom_use( "xfracal" ) )   CALL iom_put( "xfracal", xfracal(:,:,:) * tmask(:,:,:) )  ! euphotic layer deptht
-        IF( iom_use( "LNnut"   ) )   CALL iom_put( "LNnut"  , xlimphy(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
-        IF( iom_use( "LDnut"   ) )   CALL iom_put( "LDnut"  , xlimdia(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
-        IF( iom_use( "LNFe"    ) )   CALL iom_put( "LNFe"   , xlimnfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-        IF( iom_use( "LDFe"    ) )   CALL iom_put( "LDFe"   , xlimdfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-      ENDIF
-      !
-      IF( ln_timing )   CALL timing_stop('p4z_lim')
-      !
-   END SUBROUTINE p4z_lim
-
-
-   SUBROUTINE p4z_lim_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE p4z_lim_init  ***
-      !!
-      !! ** Purpose :   Initialization of nutrient limitation parameters
-      !!
-      !! ** Method  :   Read the nampislim namelist and check the parameters
-      !!      called at the first timestep (nittrc000)
-      !!
-      !! ** input   :   Namelist nampislim
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER ::   ios   ! Local integer
-      !
-      NAMELIST/namp4zice/ concnno3, concdno3, concnnh4, concdnh4, concnfer, concdfer, concbfe,   &
-         &                concbno3, concbnh4, xsizedia, xsizephy, xsizern, xsizerd,          & 
-         &                xksi1, xksi2, xkdoc, qnfelim, qdfelim, caco3r, oxymin
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'p4z_lim_init : initialization of nutrient limitations'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-      ENDIF
-      !
-      REWIND( numnatp_ref )              ! Namelist nampislim in reference namelist : Pisces nutrient limitation parameters
-      READ  ( numnatp_ref, namp4zice, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zice in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampislim in configuration namelist : Pisces nutrient limitation parameters 
-      READ  ( numnatp_cfg, namp4zice, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zice in configuration namelist', lwp )
-      IF(lwm) WRITE( numonp, namp4zice )
-      !
-      IF(lwp) THEN                         ! control print
-         WRITE(numout,*) '   Namelist : namp4zice'
-         WRITE(numout,*) '      mean rainratio                           caco3r    = ', caco3r
-         WRITE(numout,*) '      NO3 half saturation of nanophyto         concnno3  = ', concnno3
-         WRITE(numout,*) '      NO3 half saturation of diatoms           concdno3  = ', concdno3
-         WRITE(numout,*) '      NH4 half saturation for phyto            concnnh4  = ', concnnh4
-         WRITE(numout,*) '      NH4 half saturation for diatoms          concdnh4  = ', concdnh4
-         WRITE(numout,*) '      half saturation constant for Si uptake   xksi1     = ', xksi1
-         WRITE(numout,*) '      half saturation constant for Si/C        xksi2     = ', xksi2
-         WRITE(numout,*) '      half-sat. of DOC remineralization        xkdoc     = ', xkdoc
-         WRITE(numout,*) '      Iron half saturation for nanophyto       concnfer  = ', concnfer
-         WRITE(numout,*) '      Iron half saturation for diatoms         concdfer  = ', concdfer
-         WRITE(numout,*) '      size ratio for nanophytoplankton         xsizern   = ', xsizern
-         WRITE(numout,*) '      size ratio for diatoms                   xsizerd   = ', xsizerd
-         WRITE(numout,*) '      NO3 half saturation of bacteria          concbno3  = ', concbno3
-         WRITE(numout,*) '      NH4 half saturation for bacteria         concbnh4  = ', concbnh4
-         WRITE(numout,*) '      Minimum size criteria for diatoms        xsizedia  = ', xsizedia
-         WRITE(numout,*) '      Minimum size criteria for nanophyto      xsizephy  = ', xsizephy
-         WRITE(numout,*) '      Fe half saturation for bacteria          concbfe   = ', concbfe
-         WRITE(numout,*) '      halk saturation constant for anoxia       oxymin   =' , oxymin
-         WRITE(numout,*) '      optimal Fe quota for nano.               qnfelim   = ', qnfelim
-         WRITE(numout,*) '      Optimal Fe quota for diatoms             qdfelim   = ', qdfelim
-      ENDIF
-      !
-      nitrfac (:,:,:) = 0._wp
-      !
-   END SUBROUTINE p4z_lim_init
-
-
-   INTEGER FUNCTION p4z_lim_alloc()
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE p5z_lim_alloc  ***
-      !!----------------------------------------------------------------------
-      USE lib_mpp , ONLY: ctl_warn
-      !!----------------------------------------------------------------------
-
-      !*  Biological arrays for phytoplankton growth
-      ALLOCATE( xnanono3(jpi,jpj,jpk), xdiatno3(jpi,jpj,jpk),       &
-         &      xnanonh4(jpi,jpj,jpk), xdiatnh4(jpi,jpj,jpk),       &
-         &      xnanopo4(jpi,jpj,jpk), xdiatpo4(jpi,jpj,jpk),       &
-         &      xlimphy (jpi,jpj,jpk), xlimdia (jpi,jpj,jpk),       &
-         &      xlimnfe (jpi,jpj,jpk), xlimdfe (jpi,jpj,jpk),       &
-         &      xlimbac (jpi,jpj,jpk), xlimbacl(jpi,jpj,jpk),       &
-         &      concnfe (jpi,jpj,jpk), concdfe (jpi,jpj,jpk),       &
-         &      xlimsi  (jpi,jpj,jpk), STAT=p4z_lim_alloc )
-      !
-      IF( p4z_lim_alloc /= 0 ) CALL ctl_warn('p4z_lim_alloc : failed to allocate arrays.')
-      !
-   END FUNCTION p4z_lim_alloc
-
-   !!======================================================================
-END MODULE p4zice
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zlim.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zlim.F90	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zlim.F90	(revision 10345)
@@ -0,0 +1,313 @@
+MODULE p4zlim
+   !!======================================================================
+   !!                         ***  MODULE p4zlim  ***
+   !! TOP :   PISCES 
+   !!======================================================================
+   !! History :   1.0  !  2004     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!             3.4  !  2011-04  (O. Aumont, C. Ethe) Limitation for iron modelled in quota 
+   !!----------------------------------------------------------------------
+   !!   p4z_lim        :   Compute the nutrients limitation terms 
+   !!   p4z_lim_init   :   Read the namelist 
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Shared ocean-passive tracers variables
+   USE trc             ! Tracers defined
+   USE sms_pisces      ! PISCES variables
+   USE iom             !  I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC p4z_lim    
+   PUBLIC p4z_lim_init    
+   PUBLIC p4z_lim_alloc
+
+   !! * Shared module variables
+   REAL(wp), PUBLIC ::  concnno3    !:  NO3, PO4 half saturation   
+   REAL(wp), PUBLIC ::  concdno3    !:  Phosphate half saturation for diatoms  
+   REAL(wp), PUBLIC ::  concnnh4    !:  NH4 half saturation for phyto  
+   REAL(wp), PUBLIC ::  concdnh4    !:  NH4 half saturation for diatoms
+   REAL(wp), PUBLIC ::  concnfer    !:  Iron half saturation for nanophyto 
+   REAL(wp), PUBLIC ::  concdfer    !:  Iron half saturation for diatoms  
+   REAL(wp), PUBLIC ::  concbno3    !:  NO3 half saturation  for bacteria 
+   REAL(wp), PUBLIC ::  concbnh4    !:  NH4 half saturation for bacteria
+   REAL(wp), PUBLIC ::  xsizedia    !:  Minimum size criteria for diatoms
+   REAL(wp), PUBLIC ::  xsizephy    !:  Minimum size criteria for nanophyto
+   REAL(wp), PUBLIC ::  xsizern     !:  Size ratio for nanophytoplankton
+   REAL(wp), PUBLIC ::  xsizerd     !:  Size ratio for diatoms
+   REAL(wp), PUBLIC ::  xksi1       !:  half saturation constant for Si uptake 
+   REAL(wp), PUBLIC ::  xksi2       !:  half saturation constant for Si/C 
+   REAL(wp), PUBLIC ::  xkdoc       !:  2nd half-sat. of DOC remineralization  
+   REAL(wp), PUBLIC ::  concbfe     !:  Fe half saturation for bacteria 
+   REAL(wp), PUBLIC ::  oxymin      !:  half saturation constant for anoxia
+   REAL(wp), PUBLIC ::  qnfelim     !:  optimal Fe quota for nanophyto
+   REAL(wp), PUBLIC ::  qdfelim     !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  caco3r      !:  mean rainratio 
+
+   !!* Phytoplankton limitation terms
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanono3   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatno3   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanonh4   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatnh4   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanopo4   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatpo4   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimphy    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimdia    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimnfe    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimdfe    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimsi     !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimbac    !: ??
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimbacl   !: ??
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   concdfe    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   concnfe    !: ???
+
+   ! Coefficient for iron limitation
+   REAL(wp) ::  xcoef1   = 0.0016  / 55.85  
+   REAL(wp) ::  xcoef2   = 1.21E-5 * 14. / 55.85 / 7.625 * 0.5 * 1.5
+   REAL(wp) ::  xcoef3   = 1.15E-4 * 14. / 55.85 / 7.625 * 0.5 
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
+   !! $Id: p4zlim.F90 10069 2018-08-28 14:12:24Z nicolasmartin $ 
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE p4z_lim( kt, knt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_lim  ***
+      !!
+      !! ** Purpose :   Compute the co-limitations by the various nutrients
+      !!              for the various phytoplankton species
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in)  :: kt, knt
+      !
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zlim1, zlim2, zlim3, zlim4, zno3, zferlim
+      REAL(wp) ::   zconcd, zconcd2, zconcn, zconcn2
+      REAL(wp) ::   z1_trbdia, z1_trbphy, ztem1, ztem2, zetot1, zetot2
+      REAL(wp) ::   zdenom, zratio, zironmin
+      REAL(wp) ::   zconc1d, zconc1dnh4, zconc0n, zconc0nnh4   
+      !!---------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('p4z_lim')
+      !
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               
+               ! Tuning of the iron concentration to a minimum level that is set to the detection limit
+               !-------------------------------------
+               zno3    = trb(ji,jj,jk,jpno3) / 40.e-6
+               zferlim = MAX( 3e-11 * zno3 * zno3, 5e-12 )
+               zferlim = MIN( zferlim, 7e-11 )
+               trb(ji,jj,jk,jpfer) = MAX( trb(ji,jj,jk,jpfer), zferlim )
+
+               ! Computation of a variable Ks for iron on diatoms taking into account
+               ! that increasing biomass is made of generally bigger cells
+               !------------------------------------------------
+               zconcd   = MAX( 0.e0 , trb(ji,jj,jk,jpdia) - xsizedia )
+               zconcd2  = trb(ji,jj,jk,jpdia) - zconcd
+               zconcn   = MAX( 0.e0 , trb(ji,jj,jk,jpphy) - xsizephy )
+               zconcn2  = trb(ji,jj,jk,jpphy) - zconcn
+               z1_trbphy   = 1. / ( trb(ji,jj,jk,jpphy) + rtrn )
+               z1_trbdia   = 1. / ( trb(ji,jj,jk,jpdia) + rtrn )
+
+               concdfe(ji,jj,jk) = MAX( concdfer, ( zconcd2 * concdfer + concdfer * xsizerd * zconcd ) * z1_trbdia )
+               zconc1d           = MAX( concdno3, ( zconcd2 * concdno3 + concdno3 * xsizerd * zconcd ) * z1_trbdia )
+               zconc1dnh4        = MAX( concdnh4, ( zconcd2 * concdnh4 + concdnh4 * xsizerd * zconcd ) * z1_trbdia )
+
+               concnfe(ji,jj,jk) = MAX( concnfer, ( zconcn2 * concnfer + concnfer * xsizern * zconcn ) * z1_trbphy )
+               zconc0n           = MAX( concnno3, ( zconcn2 * concnno3 + concnno3 * xsizern * zconcn ) * z1_trbphy )
+               zconc0nnh4        = MAX( concnnh4, ( zconcn2 * concnnh4 + concnnh4 * xsizern * zconcn ) * z1_trbphy )
+
+               ! Michaelis-Menten Limitation term for nutrients Small bacteria
+               ! -------------------------------------------------------------
+               zdenom = 1. /  ( concbno3 * concbnh4 + concbnh4 * trb(ji,jj,jk,jpno3) + concbno3 * trb(ji,jj,jk,jpnh4) )
+               xnanono3(ji,jj,jk) = trb(ji,jj,jk,jpno3) * concbnh4 * zdenom
+               xnanonh4(ji,jj,jk) = trb(ji,jj,jk,jpnh4) * concbno3 * zdenom
+               !
+               zlim1    = xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk)
+               zlim2    = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + concbnh4 )
+               zlim3    = trb(ji,jj,jk,jpfer) / ( concbfe + trb(ji,jj,jk,jpfer) )
+               zlim4    = trb(ji,jj,jk,jpdoc) / ( xkdoc   + trb(ji,jj,jk,jpdoc) )
+               xlimbacl(ji,jj,jk) = MIN( zlim1, zlim2, zlim3 )
+               xlimbac (ji,jj,jk) = MIN( zlim1, zlim2, zlim3 ) * zlim4
+
+               ! Michaelis-Menten Limitation term for nutrients Small flagellates
+               ! -----------------------------------------------
+               zdenom = 1. /  ( zconc0n * zconc0nnh4 + zconc0nnh4 * trb(ji,jj,jk,jpno3) + zconc0n * trb(ji,jj,jk,jpnh4) )
+               xnanono3(ji,jj,jk) = trb(ji,jj,jk,jpno3) * zconc0nnh4 * zdenom
+               xnanonh4(ji,jj,jk) = trb(ji,jj,jk,jpnh4) * zconc0n    * zdenom
+               !
+               zlim1    = xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk)
+               zlim2    = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zconc0nnh4 )
+               zratio   = trb(ji,jj,jk,jpnfe) * z1_trbphy 
+               zironmin = xcoef1 * trb(ji,jj,jk,jpnch) * z1_trbphy + xcoef2 * zlim1 + xcoef3 * xnanono3(ji,jj,jk)
+               zlim3    = MAX( 0.,( zratio - zironmin ) / qnfelim )
+               xnanopo4(ji,jj,jk) = zlim2
+               xlimnfe (ji,jj,jk) = MIN( 1., zlim3 )
+               xlimphy (ji,jj,jk) = MIN( zlim1, zlim2, zlim3 )
+               !
+               !   Michaelis-Menten Limitation term for nutrients Diatoms
+               !   ----------------------------------------------
+               zdenom   = 1. / ( zconc1d * zconc1dnh4 + zconc1dnh4 * trb(ji,jj,jk,jpno3) + zconc1d * trb(ji,jj,jk,jpnh4) )
+               xdiatno3(ji,jj,jk) = trb(ji,jj,jk,jpno3) * zconc1dnh4 * zdenom
+               xdiatnh4(ji,jj,jk) = trb(ji,jj,jk,jpnh4) * zconc1d    * zdenom
+               !
+               zlim1    = xdiatno3(ji,jj,jk) + xdiatnh4(ji,jj,jk)
+               zlim2    = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zconc1dnh4  )
+               zlim3    = trb(ji,jj,jk,jpsil) / ( trb(ji,jj,jk,jpsil) + xksi(ji,jj) )
+               zratio   = trb(ji,jj,jk,jpdfe) * z1_trbdia
+               zironmin = xcoef1 * trb(ji,jj,jk,jpdch) * z1_trbdia + xcoef2 * zlim1 + xcoef3 * xdiatno3(ji,jj,jk)
+               zlim4    = MAX( 0., ( zratio - zironmin ) / qdfelim )
+               xdiatpo4(ji,jj,jk) = zlim2
+               xlimdfe (ji,jj,jk) = MIN( 1., zlim4 )
+               xlimdia (ji,jj,jk) = MIN( zlim1, zlim2, zlim3, zlim4 )
+               xlimsi  (ji,jj,jk) = MIN( zlim1, zlim2, zlim4 )
+           END DO
+         END DO
+      END DO
+
+      ! Compute the fraction of nanophytoplankton that is made of calcifiers
+      ! --------------------------------------------------------------------
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zlim1 =  ( trb(ji,jj,jk,jpno3) * concnnh4 + trb(ji,jj,jk,jpnh4) * concnno3 )    &
+                  &   / ( concnno3 * concnnh4 + concnnh4 * trb(ji,jj,jk,jpno3) + concnno3 * trb(ji,jj,jk,jpnh4) ) 
+               zlim2  = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + concnnh4 )
+               zlim3  = trb(ji,jj,jk,jpfer) / ( trb(ji,jj,jk,jpfer) +  5.E-11   )
+               ztem1  = MAX( 0., tsn(ji,jj,jk,jp_tem) )
+               ztem2  = tsn(ji,jj,jk,jp_tem) - 10.
+               zetot1 = MAX( 0., etot_ndcy(ji,jj,jk) - 1.) / ( 4. + etot_ndcy(ji,jj,jk) ) 
+               zetot2 = 30. / ( 30. + etot_ndcy(ji,jj,jk) ) 
+
+               xfracal(ji,jj,jk) = caco3r * MIN( zlim1, zlim2, zlim3 )                  &
+                  &                       * ztem1 / ( 0.1 + ztem1 )                     &
+                  &                       * MAX( 1., trb(ji,jj,jk,jpphy) * 1.e6 / 2. )  &
+                  &                       * zetot1 * zetot2               &
+                  &                       * ( 1. + EXP(-ztem2 * ztem2 / 25. ) )         &
+                  &                       * MIN( 1., 50. / ( hmld(ji,jj) + rtrn ) )
+               xfracal(ji,jj,jk) = MIN( 0.8 , xfracal(ji,jj,jk) )
+               xfracal(ji,jj,jk) = MAX( 0.02, xfracal(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+      !
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ! denitrification factor computed from O2 levels
+               nitrfac(ji,jj,jk) = MAX(  0.e0, 0.4 * ( 6.e-6  - trb(ji,jj,jk,jpoxy) )    &
+                  &                                / ( oxymin + trb(ji,jj,jk,jpoxy) )  )
+               nitrfac(ji,jj,jk) = MIN( 1., nitrfac(ji,jj,jk) )
+               !
+               ! denitrification factor computed from NO3 levels
+               nitrfac2(ji,jj,jk) = MAX( 0.e0,       ( 1.E-6 - trb(ji,jj,jk,jpno3) )  &
+                  &                                / ( 1.E-6 + trb(ji,jj,jk,jpno3) ) )
+               nitrfac2(ji,jj,jk) = MIN( 1., nitrfac2(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+      !
+      IF( lk_iomput .AND. knt == nrdttrc ) THEN        ! save output diagnostics
+        IF( iom_use( "xfracal" ) )   CALL iom_put( "xfracal", xfracal(:,:,:) * tmask(:,:,:) )  ! euphotic layer deptht
+        IF( iom_use( "LNnut"   ) )   CALL iom_put( "LNnut"  , xlimphy(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
+        IF( iom_use( "LDnut"   ) )   CALL iom_put( "LDnut"  , xlimdia(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
+        IF( iom_use( "LNFe"    ) )   CALL iom_put( "LNFe"   , xlimnfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        IF( iom_use( "LDFe"    ) )   CALL iom_put( "LDFe"   , xlimdfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+      ENDIF
+      !
+      IF( ln_timing )   CALL timing_stop('p4z_lim')
+      !
+   END SUBROUTINE p4z_lim
+
+
+   SUBROUTINE p4z_lim_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE p4z_lim_init  ***
+      !!
+      !! ** Purpose :   Initialization of nutrient limitation parameters
+      !!
+      !! ** Method  :   Read the nampislim namelist and check the parameters
+      !!      called at the first timestep (nittrc000)
+      !!
+      !! ** input   :   Namelist nampislim
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER ::   ios   ! Local integer
+      !
+      NAMELIST/namp4zlim/ concnno3, concdno3, concnnh4, concdnh4, concnfer, concdfer, concbfe,   &
+         &                concbno3, concbnh4, xsizedia, xsizephy, xsizern, xsizerd,          & 
+         &                xksi1, xksi2, xkdoc, qnfelim, qdfelim, caco3r, oxymin
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'p4z_lim_init : initialization of nutrient limitations'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+      ENDIF
+      !
+      REWIND( numnatp_ref )              ! Namelist nampislim in reference namelist : Pisces nutrient limitation parameters
+      READ  ( numnatp_ref, namp4zlim, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zlim in reference namelist', lwp )
+      REWIND( numnatp_cfg )              ! Namelist nampislim in configuration namelist : Pisces nutrient limitation parameters 
+      READ  ( numnatp_cfg, namp4zlim, IOSTAT = ios, ERR = 902 )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zlim in configuration namelist', lwp )
+      IF(lwm) WRITE( numonp, namp4zlim )
+      !
+      IF(lwp) THEN                         ! control print
+         WRITE(numout,*) '   Namelist : namp4zlim'
+         WRITE(numout,*) '      mean rainratio                           caco3r    = ', caco3r
+         WRITE(numout,*) '      NO3 half saturation of nanophyto         concnno3  = ', concnno3
+         WRITE(numout,*) '      NO3 half saturation of diatoms           concdno3  = ', concdno3
+         WRITE(numout,*) '      NH4 half saturation for phyto            concnnh4  = ', concnnh4
+         WRITE(numout,*) '      NH4 half saturation for diatoms          concdnh4  = ', concdnh4
+         WRITE(numout,*) '      half saturation constant for Si uptake   xksi1     = ', xksi1
+         WRITE(numout,*) '      half saturation constant for Si/C        xksi2     = ', xksi2
+         WRITE(numout,*) '      half-sat. of DOC remineralization        xkdoc     = ', xkdoc
+         WRITE(numout,*) '      Iron half saturation for nanophyto       concnfer  = ', concnfer
+         WRITE(numout,*) '      Iron half saturation for diatoms         concdfer  = ', concdfer
+         WRITE(numout,*) '      size ratio for nanophytoplankton         xsizern   = ', xsizern
+         WRITE(numout,*) '      size ratio for diatoms                   xsizerd   = ', xsizerd
+         WRITE(numout,*) '      NO3 half saturation of bacteria          concbno3  = ', concbno3
+         WRITE(numout,*) '      NH4 half saturation for bacteria         concbnh4  = ', concbnh4
+         WRITE(numout,*) '      Minimum size criteria for diatoms        xsizedia  = ', xsizedia
+         WRITE(numout,*) '      Minimum size criteria for nanophyto      xsizephy  = ', xsizephy
+         WRITE(numout,*) '      Fe half saturation for bacteria          concbfe   = ', concbfe
+         WRITE(numout,*) '      halk saturation constant for anoxia       oxymin   =' , oxymin
+         WRITE(numout,*) '      optimal Fe quota for nano.               qnfelim   = ', qnfelim
+         WRITE(numout,*) '      Optimal Fe quota for diatoms             qdfelim   = ', qdfelim
+      ENDIF
+      !
+      nitrfac (:,:,:) = 0._wp
+      !
+   END SUBROUTINE p4z_lim_init
+
+
+   INTEGER FUNCTION p4z_lim_alloc()
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE p5z_lim_alloc  ***
+      !!----------------------------------------------------------------------
+      USE lib_mpp , ONLY: ctl_warn
+      !!----------------------------------------------------------------------
+
+      !*  Biological arrays for phytoplankton growth
+      ALLOCATE( xnanono3(jpi,jpj,jpk), xdiatno3(jpi,jpj,jpk),       &
+         &      xnanonh4(jpi,jpj,jpk), xdiatnh4(jpi,jpj,jpk),       &
+         &      xnanopo4(jpi,jpj,jpk), xdiatpo4(jpi,jpj,jpk),       &
+         &      xlimphy (jpi,jpj,jpk), xlimdia (jpi,jpj,jpk),       &
+         &      xlimnfe (jpi,jpj,jpk), xlimdfe (jpi,jpj,jpk),       &
+         &      xlimbac (jpi,jpj,jpk), xlimbacl(jpi,jpj,jpk),       &
+         &      concnfe (jpi,jpj,jpk), concdfe (jpi,jpj,jpk),       &
+         &      xlimsi  (jpi,jpj,jpk), STAT=p4z_lim_alloc )
+      !
+      IF( p4z_lim_alloc /= 0 ) CALL ctl_warn('p4z_lim_alloc : failed to allocate arrays.')
+      !
+   END FUNCTION p4z_lim_alloc
+
+   !!======================================================================
+END MODULE p4zlim
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zmeso.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zmeso.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zmeso.F90	(revision 10345)
@@ -108,5 +108,5 @@
                zdenom    = zfoodlim / ( xkgraz2 + zfoodlim )
                zdenom2   = zdenom / ( zfood + rtrn )
-               zgraze2   = grazrat2 * xstep * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpmes) 
+               zgraze2   = grazrat2 * xstep * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpmes) * (1. - nitrfac(ji,jj,jk)) 
 
                zgrazd    = zgraze2  * xprefc   * zcompadi  * zdenom2 
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zmicro.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zmicro.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zmicro.F90	(revision 10345)
@@ -14,5 +14,5 @@
    USE trc             ! passive tracers common variables 
    USE sms_pisces      ! PISCES Source Minus Sink variables
-   USE p4zice          ! Co-limitations
+   USE p4zlim          ! Co-limitations
    USE p4zprod         ! production
    USE iom             ! I/O manager
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zmort.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zmort.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zmort.F90	(revision 10345)
@@ -14,5 +14,5 @@
    USE sms_pisces      ! PISCES Source Minus Sink variables
    USE p4zprod         ! Primary productivity 
-   USE p4zice          ! Phytoplankton limitation terms
+   USE p4zlim          ! Phytoplankton limitation terms
    USE prtctl_trc      ! print control for debugging
 
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zprod.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zprod.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zprod.F90	(revision 10345)
@@ -15,5 +15,5 @@
    USE trc             ! passive tracers common variables 
    USE sms_pisces      ! PISCES Source Minus Sink variables
-   USE p4zice          ! Co-limitations of differents nutrients
+   USE p4zlim          ! Co-limitations of differents nutrients
    USE prtctl_trc      ! print control for debugging
    USE iom             ! I/O manager
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zrem.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zrem.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zrem.F90	(revision 10345)
@@ -17,5 +17,5 @@
    USE p4zche          !  chemical model
    USE p4zprod         !  Growth rate of the 2 phyto groups
-   USE p4zice
+   USE p4zlim
    USE prtctl_trc      !  print control for debugging
    USE iom             !  I/O manager
@@ -116,5 +116,6 @@
                   zammonic = zremik * nitrfac(ji,jj,jk) * trb(ji,jj,jk,jpdoc)
                   denitr(ji,jj,jk)  = zammonic * ( 1. - nitrfac2(ji,jj,jk) )
-                  zoxyrem           = zammonic *        nitrfac2(ji,jj,jk)
+                  denitr(ji,jj,jk)  = MIN( ( trb(ji,jj,jk,jpno3) - rtrn ) / rdenit, denitr(ji,jj,jk) )
+                  zoxyrem           = zammonic - denitr(ji,jj,jk)
                   !
                   zolimi (ji,jj,jk) = MAX( 0.e0, zolimi (ji,jj,jk) )
@@ -189,4 +190,5 @@
                &         / ( 1.+ emoy(ji,jj,jk) ) * ( 1. + fr_i(ji,jj) * emoy(ji,jj,jk) ) 
                zdenitnh4 = nitrif * xstep * trb(ji,jj,jk,jpnh4) * nitrfac(ji,jj,jk)
+               zdenitnh4 = MIN(  ( trb(ji,jj,jk,jpno3) - rtrn ) / rdenita, zdenitnh4 ) 
                ! Update of the tracers trends
                ! ----------------------------
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zsed.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zsed.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zsed.F90	(revision 10345)
@@ -14,7 +14,8 @@
    USE trc             !  passive tracers common variables 
    USE sms_pisces      !  PISCES Source Minus Sink variables
-   USE p4zice          !  Co-limitations of differents nutrients
+   USE p4zlim          !  Co-limitations of differents nutrients
    USE p4zsbc          !  External source of nutrients 
    USE p4zint          !  interpolation and computation of various fields
+   USE sed             !  Sediment module
    USE iom             !  I/O manager
    USE prtctl_trc      !  print control for debugging
@@ -29,4 +30,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:  ) :: sdenit     !: Nitrate reduction in the sediments
    REAL(wp) :: r1_rday                  !: inverse of rday
+   LOGICAL, SAVE :: lk_sed
 
    !!----------------------------------------------------------------------
@@ -70,4 +72,13 @@
       !
       IF( ln_timing )  CALL timing_start('p4z_sed')
+      !
+      IF( kt == nittrc000 .AND. knt == 1 )   THEN
+          r1_rday  = 1. / rday
+          IF (ln_sediment .AND. ln_sed_2way) THEN
+             lk_sed = .TRUE.
+          ELSE
+             lk_sed = .FALSE.
+          ENDIF
+      ENDIF
       !
       IF( kt == nittrc000 .AND. knt == 1 )   r1_rday  = 1. / rday
@@ -185,14 +196,4 @@
       ENDIF
 
-      ! Add the external input of iron from sediment mobilization
-      ! ------------------------------------------------------
-      IF( ln_ironsed ) THEN
-                         tra(:,:,:,jpfer) = tra(:,:,:,jpfer) + ironsed(:,:,:) * rfact2
-         IF( ln_ligand ) tra(:,:,:,jpfep) = tra(:,:,:,jpfep) + ( ironsed(:,:,:) * fep_rats ) * rfact2
-         !
-         IF( lk_iomput .AND. knt == nrdttrc .AND. iom_use( "Ironsed" ) )   &
-            &   CALL iom_put( "Ironsed", ironsed(:,:,:) * 1.e+3 * tmask(:,:,:) ) ! iron inputs from sediments
-      ENDIF
-
       ! Add the external input of iron from hydrothermal vents
       ! ------------------------------------------------------
@@ -231,4 +232,15 @@
 
       IF( .NOT.lk_sed ) THEN
+!
+         ! Add the external input of iron from sediment mobilization
+         ! ------------------------------------------------------
+         IF( ln_ironsed ) THEN
+                            tra(:,:,:,jpfer) = tra(:,:,:,jpfer) + ironsed(:,:,:) * rfact2
+            IF( ln_ligand ) tra(:,:,:,jpfep) = tra(:,:,:,jpfep) + ( ironsed(:,:,:) * fep_rats ) * rfact2
+            !
+            IF( lk_iomput .AND. knt == nrdttrc .AND. iom_use( "Ironsed" ) )   &
+               &   CALL iom_put( "Ironsed", ironsed(:,:,:) * 1.e+3 * tmask(:,:,:) ) ! iron inputs from sediments
+         ENDIF
+
          ! Computation of the sediment denitrification proportion: The metamodel from midlleburg (2006) is being used
          ! Computation of the fraction of organic matter that is permanently buried from Dunne's model
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zsms.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zsms.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zsms.F90	(revision 10345)
@@ -74,4 +74,5 @@
             CALL p4z_che                              ! initialize the chemical constants
             CALL ahini_for_at(hi)   !  set PH at kt=nit000
+            t_oce_co2_flx_cum = 0._wp
         ELSE
             CALL p4z_rst( nittrc000, 'READ' )  !* read or initialize all required fields
@@ -101,9 +102,10 @@
       ENDIF
       !
+      IF( ll_sbc ) CALL p4z_sbc( kt )   ! external sources of nutrients 
+      !
+#if ! defined key_sed_off
       CALL p4z_che              ! computation of chemical constants
       CALL p4z_int( kt )        ! computation of various rates for biogeochemistry
       !
-      IF( ll_sbc ) CALL p4z_sbc( kt )   ! external sources of nutrients 
-
       DO jnt = 1, nrdttrc          ! Potential time splitting if requested
          !
@@ -149,8 +151,15 @@
          END DO
       END IF
-      !
-      IF( lk_sed ) THEN 
+#endif
+      !
+      IF( ln_sediment ) THEN 
          !
          CALL sed_model( kt )     !  Main program of Sediment model
+         !
+         IF( ln_top_euler ) THEN
+            DO jn = jp_pcs0, jp_pcs1
+               trn(:,:,:,jn) = trb(:,:,:,jn)
+            END DO
+         ENDIF
          !
       ENDIF
@@ -352,45 +361,47 @@
       IF(lwp)  WRITE(numout,*)
 
-      IF( cn_cfg == "orca" .AND. .NOT. lk_c1d ) THEN      ! ORCA configuration (not 1D) !
-         !                                                ! --------------------------- !
-         ! set total alkalinity, phosphate, nitrate & silicate
-         zarea          = 1._wp / glob_sum( 'p4zsms', cvol(:,:,:) ) * 1e6              
-
-         zalksumn = glob_sum( 'p4zsms', trn(:,:,:,jptal) * cvol(:,:,:)  ) * zarea
-         zpo4sumn = glob_sum( 'p4zsms', trn(:,:,:,jppo4) * cvol(:,:,:)  ) * zarea * po4r
-         zno3sumn = glob_sum( 'p4zsms', trn(:,:,:,jpno3) * cvol(:,:,:)  ) * zarea * rno3
-         zsilsumn = glob_sum( 'p4zsms', trn(:,:,:,jpsil) * cvol(:,:,:)  ) * zarea
+      IF( cn_cfg == "ORCA" .OR. cn_cfg == "orca") THEN
+         IF( .NOT. lk_c1d ) THEN      ! ORCA configuration (not 1D) !
+            !                                                ! --------------------------- !
+            ! set total alkalinity, phosphate, nitrate & silicate
+            zarea          = 1._wp / glob_sum( 'p4zsms', cvol(:,:,:) ) * 1e6              
+
+            zalksumn = glob_sum( 'p4zsms', trn(:,:,:,jptal) * cvol(:,:,:)  ) * zarea
+            zpo4sumn = glob_sum( 'p4zsms', trn(:,:,:,jppo4) * cvol(:,:,:)  ) * zarea * po4r
+            zno3sumn = glob_sum( 'p4zsms', trn(:,:,:,jpno3) * cvol(:,:,:)  ) * zarea * rno3
+            zsilsumn = glob_sum( 'p4zsms', trn(:,:,:,jpsil) * cvol(:,:,:)  ) * zarea
  
-         IF(lwp) WRITE(numout,*) '       TALKN mean : ', zalksumn
-         trn(:,:,:,jptal) = trn(:,:,:,jptal) * alkmean / zalksumn
-
-         IF(lwp) WRITE(numout,*) '       PO4N  mean : ', zpo4sumn
-         trn(:,:,:,jppo4) = trn(:,:,:,jppo4) * po4mean / zpo4sumn
-
-         IF(lwp) WRITE(numout,*) '       NO3N  mean : ', zno3sumn
-         trn(:,:,:,jpno3) = trn(:,:,:,jpno3) * no3mean / zno3sumn
-
-         IF(lwp) WRITE(numout,*) '       SiO3N mean : ', zsilsumn
-         trn(:,:,:,jpsil) = MIN( 400.e-6,trn(:,:,:,jpsil) * silmean / zsilsumn )
-         !
-         !
-         IF( .NOT. ln_top_euler ) THEN
-            zalksumb = glob_sum( 'p4zsms', trb(:,:,:,jptal) * cvol(:,:,:)  ) * zarea
-            zpo4sumb = glob_sum( 'p4zsms', trb(:,:,:,jppo4) * cvol(:,:,:)  ) * zarea * po4r
-            zno3sumb = glob_sum( 'p4zsms', trb(:,:,:,jpno3) * cvol(:,:,:)  ) * zarea * rno3
-            zsilsumb = glob_sum( 'p4zsms', trb(:,:,:,jpsil) * cvol(:,:,:)  ) * zarea
+            IF(lwp) WRITE(numout,*) '       TALKN mean : ', zalksumn
+            trn(:,:,:,jptal) = trn(:,:,:,jptal) * alkmean / zalksumn
+
+            IF(lwp) WRITE(numout,*) '       PO4N  mean : ', zpo4sumn
+            trn(:,:,:,jppo4) = trn(:,:,:,jppo4) * po4mean / zpo4sumn
+
+            IF(lwp) WRITE(numout,*) '       NO3N  mean : ', zno3sumn
+            trn(:,:,:,jpno3) = trn(:,:,:,jpno3) * no3mean / zno3sumn
+
+            IF(lwp) WRITE(numout,*) '       SiO3N mean : ', zsilsumn
+            trn(:,:,:,jpsil) = MIN( 400.e-6,trn(:,:,:,jpsil) * silmean / zsilsumn )
+            !
+            !
+            IF( .NOT. ln_top_euler ) THEN
+               zalksumb = glob_sum( 'p4zsms', trb(:,:,:,jptal) * cvol(:,:,:)  ) * zarea
+               zpo4sumb = glob_sum( 'p4zsms', trb(:,:,:,jppo4) * cvol(:,:,:)  ) * zarea * po4r
+               zno3sumb = glob_sum( 'p4zsms', trb(:,:,:,jpno3) * cvol(:,:,:)  ) * zarea * rno3
+               zsilsumb = glob_sum( 'p4zsms', trb(:,:,:,jpsil) * cvol(:,:,:)  ) * zarea
  
-            IF(lwp) WRITE(numout,*) ' '
-            IF(lwp) WRITE(numout,*) '       TALKB mean : ', zalksumb
-            trb(:,:,:,jptal) = trb(:,:,:,jptal) * alkmean / zalksumb
-
-            IF(lwp) WRITE(numout,*) '       PO4B  mean : ', zpo4sumb
-            trb(:,:,:,jppo4) = trb(:,:,:,jppo4) * po4mean / zpo4sumb
-
-            IF(lwp) WRITE(numout,*) '       NO3B  mean : ', zno3sumb
-            trb(:,:,:,jpno3) = trb(:,:,:,jpno3) * no3mean / zno3sumb
-
-            IF(lwp) WRITE(numout,*) '       SiO3B mean : ', zsilsumb
-            trb(:,:,:,jpsil) = MIN( 400.e-6,trb(:,:,:,jpsil) * silmean / zsilsumb )
+               IF(lwp) WRITE(numout,*) ' '
+               IF(lwp) WRITE(numout,*) '       TALKB mean : ', zalksumb
+               trb(:,:,:,jptal) = trb(:,:,:,jptal) * alkmean / zalksumb
+
+               IF(lwp) WRITE(numout,*) '       PO4B  mean : ', zpo4sumb
+               trb(:,:,:,jppo4) = trb(:,:,:,jppo4) * po4mean / zpo4sumb
+
+               IF(lwp) WRITE(numout,*) '       NO3B  mean : ', zno3sumb
+               trb(:,:,:,jpno3) = trb(:,:,:,jpno3) * no3mean / zno3sumb
+
+               IF(lwp) WRITE(numout,*) '       SiO3B mean : ', zsilsumb
+               trb(:,:,:,jpsil) = MIN( 400.e-6,trb(:,:,:,jpsil) * silmean / zsilsumb )
+           ENDIF
         ENDIF
         !
Index: MO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zice.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zice.F90	(revision 10344)
+++ 	(revision )
@@ -1,602 +1,0 @@
-MODULE p5zice
-   !!======================================================================
-   !!                         ***  MODULE p5zice  ***
-   !! TOP :   PISCES with variable stoichiometry 
-   !!======================================================================
-   !! History :   1.0  !  2004     (O. Aumont) Original code
-   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
-   !!             3.4  !  2011-04  (O. Aumont, C. Ethe) Limitation for iron modelled in quota 
-   !!             3.6  !  2015-05  (O. Aumont) PISCES quota
-   !!----------------------------------------------------------------------
-   !!   p5z_lim        :   Compute the nutrients limitation terms 
-   !!   p5z_lim_init   :   Read the namelist 
-   !!----------------------------------------------------------------------
-   USE oce_trc         ! Shared ocean-passive tracers variables
-   USE trc             ! Tracers defined
-   USE sms_pisces      ! PISCES variables
-   USE iom             !  I/O manager
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC p5z_lim    
-   PUBLIC p5z_lim_init    
-   PUBLIC p5z_lim_alloc
-
-   !! * Shared module variables
-   REAL(wp), PUBLIC ::  concnno3    !:  NO3, PO4 half saturation   
-   REAL(wp), PUBLIC ::  concpno3    !:  NO3, PO4 half saturation   
-   REAL(wp), PUBLIC ::  concdno3    !:  Phosphate half saturation for diatoms  
-   REAL(wp), PUBLIC ::  concnnh4    !:  NH4 half saturation for phyto  
-   REAL(wp), PUBLIC ::  concpnh4    !:  NH4 half saturation for phyto  
-   REAL(wp), PUBLIC ::  concdnh4    !:  NH4 half saturation for diatoms
-   REAL(wp), PUBLIC ::  concnpo4    !:  NH4 half saturation for diatoms
-   REAL(wp), PUBLIC ::  concppo4    !:  NH4 half saturation for diatoms
-   REAL(wp), PUBLIC ::  concdpo4    !:  NH4 half saturation for diatoms
-   REAL(wp), PUBLIC ::  concnfer    !:  Iron half saturation for nanophyto 
-   REAL(wp), PUBLIC ::  concpfer    !:  Iron half saturation for nanophyto 
-   REAL(wp), PUBLIC ::  concdfer    !:  Iron half saturation for diatoms  
-   REAL(wp), PUBLIC ::  concbno3    !:  NO3 half saturation  for bacteria 
-   REAL(wp), PUBLIC ::  concbnh4    !:  NH4 half saturation for bacteria
-   REAL(wp), PUBLIC ::  concbpo4    !:  PO4 half saturation for bacteria
-   REAL(wp), PUBLIC ::  xsizedia    !:  Minimum size criteria for diatoms
-   REAL(wp), PUBLIC ::  xsizepic    !:  Minimum size criteria for diatoms
-   REAL(wp), PUBLIC ::  xsizephy    !:  Minimum size criteria for nanophyto
-   REAL(wp), PUBLIC ::  xsizern     !:  Size ratio for nanophytoplankton
-   REAL(wp), PUBLIC ::  xsizerp     !:  Size ratio for nanophytoplankton
-   REAL(wp), PUBLIC ::  xsizerd     !:  Size ratio for diatoms
-   REAL(wp), PUBLIC ::  xksi1       !:  half saturation constant for Si uptake 
-   REAL(wp), PUBLIC ::  xksi2       !:  half saturation constant for Si/C 
-   REAL(wp), PUBLIC ::  xkdoc       !:  2nd half-sat. of DOC remineralization  
-   REAL(wp), PUBLIC ::  concbfe     !:  Fe half saturation for bacteria 
-   REAL(wp), PUBLIC ::  oxymin      !:  half saturation constant for anoxia
-   REAL(wp), PUBLIC ::  qfnopt      !:  optimal Fe quota for nanophyto
-   REAL(wp), PUBLIC ::  qfpopt      !:  optimal Fe quota for nanophyto
-   REAL(wp), PUBLIC ::  qfdopt      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  caco3r      !:  mean rainratio 
-   REAL(wp), PUBLIC ::  qnnmin      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qnnmax      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qpnmin      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qpnmax      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qnpmin      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qnpmax      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qppmin      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qppmax      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qndmin      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qndmax      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qpdmin      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qpdmax      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qfnmax      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qfpmax      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  qfdmax      !:  optimal Fe quota for diatoms
-   REAL(wp), PUBLIC ::  zpsinh4
-   REAL(wp), PUBLIC ::  zpsino3
-   REAL(wp), PUBLIC ::  zpsiuptk
-
-   !!*  Allometric variations of the quotas
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqnnmin    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqnnmax    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqpnmin    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqpnmax    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqnpmin    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqnpmax    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqppmin    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqppmax    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqndmin    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqndmax    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqpdmin    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqpdmax    !: ???
-
-   !!* Phytoplankton limitation terms
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanono3   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatno3   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanonh4   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatnh4   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanopo4   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatpo4   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimphy    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimdia    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimnfe    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimdfe    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimsi     !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimbac    !: ??
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimbacl   !: ??
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xpicono3   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xpiconh4   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xpicopo4   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanodop   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xpicodop   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatdop   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanofer   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xpicofer   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatfer   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimpic    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimpfe    !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   fvnuptk
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   fvpuptk
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   fvduptk
-
-   ! Coefficient for iron limitation
-   REAL(wp) ::  xcoef1   = 0.00167  / 55.85
-   REAL(wp) ::  xcoef2   = 1.21E-5 * 14. / 55.85 / 7.625 * 0.5 * 1.5
-   REAL(wp) ::  xcoef3   = 1.15E-4 * 14. / 55.85 / 7.625 * 0.5 
-   !!----------------------------------------------------------------------
-   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
-   !! $Id$ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE p5z_lim( kt, knt )
-      !!---------------------------------------------------------------------
-      !!                     ***  ROUTINE p5z_lim  ***
-      !!
-      !! ** Purpose :   Compute the co-limitations by the various nutrients
-      !!              for the various phytoplankton species
-      !!
-      !! ** Method  : - ???
-      !!---------------------------------------------------------------------
-      !
-      INTEGER, INTENT(in)  :: kt, knt
-      !
-      INTEGER  ::   ji, jj, jk
-      REAL(wp) ::   zlim1, zlim2, zlim3, zlim4, zno3, zferlim
-      REAL(wp) ::   z1_trndia, z1_trnpic, z1_trnphy, ztem1, ztem2, zetot1
-      REAL(wp) ::   zratio, zration, zratiof, znutlim, zfalim
-      REAL(wp) ::   zconc1d, zconc1dnh4, zconc0n, zconc0nnh4, zconc0npo4, zconc0dpo4
-      REAL(wp) ::   zconc0p, zconc0pnh4, zconc0ppo4, zconcpfe, zconcnfe, zconcdfe
-      REAL(wp) ::   fanano, fananop, fananof, fadiat, fadiatp, fadiatf
-      REAL(wp) ::   fapico, fapicop, fapicof
-      REAL(wp) ::   zrpho, zrass, zcoef, zfuptk, zratchl
-      REAL(wp) ::   zfvn, zfvp, zfvf, zsizen, zsizep, zsized, znanochl, zpicochl, zdiatchl
-      REAL(wp) ::   zqfemn, zqfemp, zqfemd, zbactno3, zbactnh4
-      !!---------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start('p5z_lim')
-      !
-      zratchl = 6.0
-      !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! 
-               ! Tuning of the iron concentration to a minimum level that is set to the detection limit
-               !-------------------------------------
-               zno3    = trb(ji,jj,jk,jpno3) / 40.e-6
-               zferlim = MAX( 3e-11 * zno3 * zno3, 5e-12 )
-               zferlim = MIN( zferlim, 7e-11 )
-               trb(ji,jj,jk,jpfer) = MAX( trb(ji,jj,jk,jpfer), zferlim )
-
-               ! Computation of the mean relative size of each community
-               ! -------------------------------------------------------
-               z1_trnphy   = 1. / ( trb(ji,jj,jk,jpphy) + rtrn )
-               z1_trnpic   = 1. / ( trb(ji,jj,jk,jppic) + rtrn )
-               z1_trndia   = 1. / ( trb(ji,jj,jk,jpdia) + rtrn )
-               znanochl = trb(ji,jj,jk,jpnch) * z1_trnphy
-               zpicochl = trb(ji,jj,jk,jppch) * z1_trnpic
-               zdiatchl = trb(ji,jj,jk,jpdch) * z1_trndia
-
-               ! Computation of a variable Ks for iron on diatoms taking into account
-               ! that increasing biomass is made of generally bigger cells
-               !------------------------------------------------
-               zsized            = sized(ji,jj,jk)**0.81
-               zconcdfe          = concdfer * zsized
-               zconc1d           = concdno3 * zsized
-               zconc1dnh4        = concdnh4 * zsized
-               zconc0dpo4        = concdpo4 * zsized
-
-               zsizep            = 1.
-               zconcpfe          = concpfer * zsizep
-               zconc0p           = concpno3 * zsizep
-               zconc0pnh4        = concpnh4 * zsizep
-               zconc0ppo4        = concppo4 * zsizep
-
-               zsizen            = 1.
-               zconcnfe          = concnfer * zsizen
-               zconc0n           = concnno3 * zsizen
-               zconc0nnh4        = concnnh4 * zsizen
-               zconc0npo4        = concnpo4 * zsizen
-
-               ! Allometric variations of the minimum and maximum quotas
-               ! From Talmy et al. (2014) and Maranon et al. (2013)
-               ! -------------------------------------------------------
-               xqnnmin(ji,jj,jk) = qnnmin
-               xqnnmax(ji,jj,jk) = qnnmax
-               xqndmin(ji,jj,jk) = qndmin * sized(ji,jj,jk)**(-0.27) 
-               xqndmax(ji,jj,jk) = qndmax
-               xqnpmin(ji,jj,jk) = qnpmin
-               xqnpmax(ji,jj,jk) = qnpmax
-
-               ! Computation of the optimal allocation parameters
-               ! Based on the different papers by Pahlow et al., and Smith et al.
-               ! -----------------------------------------------------------------
-               znutlim = MAX( trb(ji,jj,jk,jpnh4) / zconc0nnh4,    &
-                 &         trb(ji,jj,jk,jpno3) / zconc0n)
-               fanano = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = trb(ji,jj,jk,jppo4) / zconc0npo4
-               fananop = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = biron(ji,jj,jk) / zconcnfe
-               fananof = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = MAX( trb(ji,jj,jk,jpnh4) / zconc0pnh4,    &
-                 &         trb(ji,jj,jk,jpno3) / zconc0p)
-               fapico = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = trb(ji,jj,jk,jppo4) / zconc0ppo4
-               fapicop = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = biron(ji,jj,jk) / zconcpfe
-               fapicof = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = MAX( trb(ji,jj,jk,jpnh4) / zconc1dnh4,    &
-                 &         trb(ji,jj,jk,jpno3) / zconc1d )
-               fadiat = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = trb(ji,jj,jk,jppo4) / zconc0dpo4
-               fadiatp = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = biron(ji,jj,jk) / zconcdfe
-               fadiatf = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               !
-               ! Michaelis-Menten Limitation term for nutrients Small bacteria
-               ! -------------------------------------------------------------
-               zbactnh4 = trb(ji,jj,jk,jpnh4) / ( concbnh4 + trb(ji,jj,jk,jpnh4) )
-               zbactno3 = trb(ji,jj,jk,jpno3) / ( concbno3 + trb(ji,jj,jk,jpno3) ) * (1. - zbactnh4)
-               !
-               zlim1    = zbactno3 + zbactnh4
-               zlim2    = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + concbpo4)
-               zlim3    = biron(ji,jj,jk) / ( concbfe + biron(ji,jj,jk) )
-               zlim4    = trb(ji,jj,jk,jpdoc) / ( xkdoc   + trb(ji,jj,jk,jpdoc) )
-               xlimbacl(ji,jj,jk) = MIN( zlim1, zlim2, zlim3 )
-               xlimbac (ji,jj,jk) = xlimbacl(ji,jj,jk) * zlim4
-               !
-               ! Michaelis-Menten Limitation term for nutrients Small flagellates
-               ! -----------------------------------------------
-               zfalim = (1.-fanano) / fanano
-               xnanonh4(ji,jj,jk) = (1. - fanano) * trb(ji,jj,jk,jpnh4) / ( zfalim * zconc0nnh4 + trb(ji,jj,jk,jpnh4) )
-               xnanono3(ji,jj,jk) = (1. - fanano) * trb(ji,jj,jk,jpno3) / ( zfalim * zconc0n + trb(ji,jj,jk,jpno3) )  &
-               &                    * (1. - xnanonh4(ji,jj,jk))
-               !
-               zfalim = (1.-fananop) / fananop
-               xnanopo4(ji,jj,jk) = (1. - fananop) * trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zfalim * zconc0npo4 )
-               xnanodop(ji,jj,jk) = trb(ji,jj,jk,jpdop) / ( trb(ji,jj,jk,jpdop) + xkdoc )   &
-               &                    * ( 1.0 - xnanopo4(ji,jj,jk) )
-               xnanodop(ji,jj,jk) = 0.
-               !
-               zfalim = (1.-fananof) / fananof
-               xnanofer(ji,jj,jk) = (1. - fananof) * biron(ji,jj,jk) / ( biron(ji,jj,jk) + zfalim * zconcnfe )
-               !
-               zratiof   = trb(ji,jj,jk,jpnfe) * z1_trnphy
-               zqfemn = xcoef1 * znanochl + xcoef2 + xcoef3 * xnanono3(ji,jj,jk)
-               !
-               zration = trb(ji,jj,jk,jpnph) * z1_trnphy
-               zration = MIN(xqnnmax(ji,jj,jk), MAX( 2. * xqnnmin(ji,jj,jk), zration ))
-               fvnuptk(ji,jj,jk) = 1. / zpsiuptk * rno3 * 2. * xqnnmin(ji,jj,jk) / (zration + rtrn)  &
-               &                   * MAX(0., (1. - zratchl * znanochl / 12. ) )
-               !
-               zlim1    = max(0., (zration - 2. * xqnnmin(ji,jj,jk) )  &
-               &          / (xqnnmax(ji,jj,jk) - 2. * xqnnmin(ji,jj,jk) ) ) * xqnnmax(ji,jj,jk)  &
-               &          / (zration + rtrn)
-               zlim3    = MAX( 0.,( zratiof - zqfemn ) / qfnopt ) 
-               xlimnfe(ji,jj,jk) = MIN( 1., zlim3 )
-               xlimphy(ji,jj,jk) = MIN( 1., zlim1, zlim3 )
-               !
-               ! Michaelis-Menten Limitation term for nutrients picophytoplankton
-               ! ----------------------------------------------------------------
-               zfalim = (1.-fapico) / fapico 
-               xpiconh4(ji,jj,jk) = (1. - fapico) * trb(ji,jj,jk,jpnh4) / ( zfalim * zconc0pnh4 + trb(ji,jj,jk,jpnh4) )
-               xpicono3(ji,jj,jk) = (1. - fapico) * trb(ji,jj,jk,jpno3) / ( zfalim * zconc0p + trb(ji,jj,jk,jpno3) )  &
-               &                    * (1. - xpiconh4(ji,jj,jk))
-               !
-               zfalim = (1.-fapicop) / fapicop 
-               xpicopo4(ji,jj,jk) = (1. - fapicop) * trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zfalim * zconc0ppo4 )
-               xpicodop(ji,jj,jk) = trb(ji,jj,jk,jpdop) / ( trb(ji,jj,jk,jpdop) + xkdoc )   &
-               &                    * ( 1.0 - xpicopo4(ji,jj,jk) )
-               xpicodop(ji,jj,jk) = 0.
-               !
-               zfalim = (1.-fapicof) / fapicof
-               xpicofer(ji,jj,jk) = (1. - fapicof) * biron(ji,jj,jk) / ( biron(ji,jj,jk) + zfalim * zconcpfe )
-               !
-               zratiof   = trb(ji,jj,jk,jppfe) * z1_trnpic
-               zqfemp = xcoef1 * zpicochl + xcoef2 + xcoef3 * xpicono3(ji,jj,jk)
-               !
-               zration   = trb(ji,jj,jk,jpnpi) * z1_trnpic
-               zration = MIN(xqnpmax(ji,jj,jk), MAX( 2. * xqnpmin(ji,jj,jk), zration ))
-               fvpuptk(ji,jj,jk) = 1. / zpsiuptk * rno3 * 2. * xqnpmin(ji,jj,jk) / (zration + rtrn)  &
-               &                   * MAX(0., (1. - zratchl * zpicochl / 12. ) ) 
-               !
-               zlim1    = max(0., (zration - 2. * xqnpmin(ji,jj,jk) )  &
-               &          / (xqnpmax(ji,jj,jk) - 2. * xqnpmin(ji,jj,jk) ) ) * xqnpmax(ji,jj,jk)  &
-               &          / (zration + rtrn)
-               zlim3    = MAX( 0.,( zratiof - zqfemp ) / qfpopt )
-               xlimpfe(ji,jj,jk) = MIN( 1., zlim3 )
-               xlimpic(ji,jj,jk) = MIN( 1., zlim1, zlim3 )
-               !
-               !   Michaelis-Menten Limitation term for nutrients Diatoms
-               !   ------------------------------------------------------
-               zfalim = (1.-fadiat) / fadiat 
-               xdiatnh4(ji,jj,jk) = (1. - fadiat) * trb(ji,jj,jk,jpnh4) / ( zfalim * zconc1dnh4 + trb(ji,jj,jk,jpnh4) )
-               xdiatno3(ji,jj,jk) = (1. - fadiat) * trb(ji,jj,jk,jpno3) / ( zfalim * zconc1d + trb(ji,jj,jk,jpno3) )  &
-               &                    * (1. - xdiatnh4(ji,jj,jk))
-               !
-               zfalim = (1.-fadiatp) / fadiatp
-               xdiatpo4(ji,jj,jk) = (1. - fadiatp) * trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zfalim * zconc0dpo4 )
-               xdiatdop(ji,jj,jk) = trb(ji,jj,jk,jpdop) / ( trb(ji,jj,jk,jpdop) + xkdoc )  &
-               &                    * ( 1.0 - xdiatpo4(ji,jj,jk) )
-               xdiatdop(ji,jj,jk) = 0.
-               !
-               zfalim = (1.-fadiatf) / fadiatf
-               xdiatfer(ji,jj,jk) = (1. - fadiatf) * biron(ji,jj,jk) / ( biron(ji,jj,jk) + zfalim * zconcdfe )
-               !
-               zratiof   = trb(ji,jj,jk,jpdfe) * z1_trndia
-               zqfemd = xcoef1 * zdiatchl + xcoef2 + xcoef3 * xdiatno3(ji,jj,jk)
-               !
-               zration   = trb(ji,jj,jk,jpndi) * z1_trndia
-               zration = MIN(xqndmax(ji,jj,jk), MAX( 2. * xqndmin(ji,jj,jk), zration ))
-               fvduptk(ji,jj,jk) = 1. / zpsiuptk * rno3 * 2. * xqndmin(ji,jj,jk) / (zration + rtrn)   &
-               &                   * MAX(0., (1. - zratchl * zdiatchl / 12. ) ) 
-               !
-               zlim1    = max(0., (zration - 2. * xqndmin(ji,jj,jk) )    &
-               &          / (xqndmax(ji,jj,jk) - 2. * xqndmin(ji,jj,jk) ) )   &
-               &          * xqndmax(ji,jj,jk) / (zration + rtrn)
-               zlim3    = trb(ji,jj,jk,jpsil) / ( trb(ji,jj,jk,jpsil) + xksi(ji,jj) )
-               zlim4    = MAX( 0., ( zratiof - zqfemd ) / qfdopt )
-               xlimdfe(ji,jj,jk) = MIN( 1., zlim4 )
-               xlimdia(ji,jj,jk) = MIN( 1., zlim1, zlim3, zlim4 )
-               xlimsi(ji,jj,jk)  = MIN( zlim1, zlim4 )
-            END DO
-         END DO
-      END DO
-      !
-      ! Compute the phosphorus quota values. It is based on Litchmann et al., 2004 and Daines et al, 2013.
-      ! The relative contribution of three fonctional pools are computed: light harvesting apparatus, 
-      ! nutrient uptake pool and assembly machinery. DNA is assumed to represent 1% of the dry mass of 
-      ! phytoplankton (see Daines et al., 2013). 
-      ! --------------------------------------------------------------------------------------------------
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! Size estimation of nanophytoplankton
-               ! ------------------------------------
-               zfvn = 2. * fvnuptk(ji,jj,jk)
-               sizen(ji,jj,jk) = MAX(1., MIN(xsizern, 1.0 / ( MAX(rtrn, zfvn) ) ) )
-
-               ! N/P ratio of nanophytoplankton
-               ! ------------------------------
-               zfuptk = 0.23 * zfvn
-               zrpho = 2.24 * trb(ji,jj,jk,jpnch) / ( trb(ji,jj,jk,jpnph) * rno3 * 15. + rtrn )
-               zrass = 1. - 0.2 - zrpho - zfuptk
-               xqpnmax(ji,jj,jk) = ( zfuptk + zrpho ) * 0.0128 * 16. + zrass * 1./ 7.2 * 16.
-               xqpnmax(ji,jj,jk) = xqpnmax(ji,jj,jk) * trb(ji,jj,jk,jpnph) / ( trb(ji,jj,jk,jpphy) + rtrn ) + 0.13
-               xqpnmin(ji,jj,jk) = 0.13 + 0.23 * 0.0128 * 16.
-
-               ! Size estimation of picophytoplankton
-               ! ------------------------------------
-               zfvn = 2. * fvpuptk(ji,jj,jk)
-               sizep(ji,jj,jk) = MAX(1., MIN(xsizerp, 1.0 / ( MAX(rtrn, zfvn) ) ) )
-
-               ! N/P ratio of picophytoplankton
-               ! ------------------------------
-               zfuptk = 0.35 * zfvn
-               zrpho = 2.24 * trb(ji,jj,jk,jppch) / ( trb(ji,jj,jk,jpnpi) * rno3 * 15. + rtrn )
-               zrass = 1. - 0.4 - zrpho - zfuptk
-               xqppmax(ji,jj,jk) =  (zrpho + zfuptk) * 0.0128 * 16. + zrass * 1./ 9. * 16.
-               xqppmax(ji,jj,jk) = xqppmax(ji,jj,jk) * trb(ji,jj,jk,jpnpi) / ( trb(ji,jj,jk,jppic) + rtrn ) + 0.13
-               xqppmin(ji,jj,jk) = 0.13
-
-               ! Size estimation of diatoms
-               ! --------------------------
-               zfvn = 2. * fvduptk(ji,jj,jk)
-               sized(ji,jj,jk) = MAX(1., MIN(xsizerd, 1.0 / ( MAX(rtrn, zfvn) ) ) )
-               zcoef = trb(ji,jj,jk,jpdia) - MIN(xsizedia, trb(ji,jj,jk,jpdia) )
-               sized(ji,jj,jk) = 1. + xsizerd * zcoef *1E6 / ( 1. + zcoef * 1E6 )
-
-               ! N/P ratio of diatoms
-               ! --------------------
-               zfuptk = 0.2 * zfvn
-               zrpho = 2.24 * trb(ji,jj,jk,jpdch) / ( trb(ji,jj,jk,jpndi) * rno3 * 15. + rtrn )
-               zrass = 1. - 0.2 - zrpho - zfuptk
-               xqpdmax(ji,jj,jk) = ( zfuptk + zrpho ) * 0.0128 * 16. + zrass * 1./ 7.2 * 16.
-               xqpdmax(ji,jj,jk) = xqpdmax(ji,jj,jk) * trb(ji,jj,jk,jpndi) / ( trb(ji,jj,jk,jpdia) + rtrn ) + 0.13
-               xqpdmin(ji,jj,jk) = 0.13 + 0.2 * 0.0128 * 16.
-
-            END DO
-         END DO
-      END DO
-
-      ! Compute the fraction of nanophytoplankton that is made of calcifiers
-      ! --------------------------------------------------------------------
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zlim1 =  trb(ji,jj,jk,jpnh4) / ( trb(ji,jj,jk,jpnh4) + concnnh4 ) + trb(ji,jj,jk,jpno3)    &
-               &        / ( trb(ji,jj,jk,jpno3) + concnno3 ) * ( 1.0 - trb(ji,jj,jk,jpnh4)   &
-               &        / ( trb(ji,jj,jk,jpnh4) + concnnh4 ) )
-               zlim2  = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + concnpo4 )
-               zlim3  = trb(ji,jj,jk,jpfer) / ( trb(ji,jj,jk,jpfer) +  5.E-11 ) 
-               ztem1  = MAX( 0., tsn(ji,jj,jk,jp_tem) )
-               ztem2  = tsn(ji,jj,jk,jp_tem) - 10.
-               zetot1 = MAX( 0., etot(ji,jj,jk) - 1.) / ( 4. + etot(ji,jj,jk) ) * 20. / ( 20. + etot(ji,jj,jk) ) 
-
-!               xfracal(ji,jj,jk) = caco3r * MIN( zlim1, zlim2, zlim3 )                  &
-               xfracal(ji,jj,jk) = caco3r                 &
-               &                   * ztem1 / ( 1. + ztem1 ) * MAX( 1., trb(ji,jj,jk,jpphy)*1E6 )   &
-                  &                * ( 1. + EXP(-ztem2 * ztem2 / 25. ) )         &
-                  &                * zetot1 * MIN( 1., 50. / ( hmld(ji,jj) + rtrn ) )
-               xfracal(ji,jj,jk) = MAX( 0.02, MIN( 0.8 , xfracal(ji,jj,jk) ) )
-            END DO
-         END DO
-      END DO
-      !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! denitrification factor computed from O2 levels
-               nitrfac(ji,jj,jk) = MAX(  0.e0, 0.4 * ( 6.e-6  - trb(ji,jj,jk,jpoxy) )    &
-                  &                                / ( oxymin + trb(ji,jj,jk,jpoxy) )  )
-               nitrfac(ji,jj,jk) = MIN( 1., nitrfac(ji,jj,jk) )
-            END DO
-         END DO
-      END DO
-      !
-      IF( lk_iomput .AND. knt == nrdttrc ) THEN        ! save output diagnostics
-        IF( iom_use( "xfracal" ) ) CALL iom_put( "xfracal", xfracal(:,:,:) * tmask(:,:,:) )  ! euphotic layer deptht
-        IF( iom_use( "LNnut"   ) ) CALL iom_put( "LNnut"  , xlimphy(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
-        IF( iom_use( "LPnut"   ) ) CALL iom_put( "LPnut"  , xlimpic(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
-        IF( iom_use( "LDnut"   ) ) CALL iom_put( "LDnut"  , xlimdia(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
-        IF( iom_use( "LNFe"    ) ) CALL iom_put( "LNFe"   , xlimnfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-        IF( iom_use( "LPFe"    ) ) CALL iom_put( "LPFe"   , xlimpfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-        IF( iom_use( "LDFe"    ) ) CALL iom_put( "LDFe"   , xlimdfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-        IF( iom_use( "SIZEN"   ) ) CALL iom_put( "SIZEN"  , sizen(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-        IF( iom_use( "SIZEP"   ) ) CALL iom_put( "SIZEP"  , sizep(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-        IF( iom_use( "SIZED"   ) ) CALL iom_put( "SIZED"  , sized(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-      ENDIF
-      !
-      IF( ln_timing )  CALL timing_stop('p5z_lim')
-      !
-   END SUBROUTINE p5z_lim
-
-
-   SUBROUTINE p5z_lim_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE p5z_lim_init  ***
-      !!
-      !! ** Purpose :   Initialization of nutrient limitation parameters
-      !!
-      !! ** Method  :   Read the nampislim and nampisquota namelists and check
-      !!      the parameters called at the first timestep (nittrc000)
-      !!
-      !! ** input   :   Namelist nampislim
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER :: ios                 ! Local integer output status for namelist read
-      !!
-      NAMELIST/namp5zice/ concnno3, concpno3, concdno3, concnnh4, concpnh4, concdnh4,  &
-         &                concnfer, concpfer, concdfer, concbfe, concnpo4, concppo4,   &
-         &                concdpo4, concbno3, concbnh4, concbpo4, xsizedia, xsizepic,  &
-         &                xsizephy, xsizern, xsizerp, xsizerd, xksi1, xksi2, xkdoc,    &
-         &                caco3r, oxymin
-         !
-      NAMELIST/namp5zquota/ qnnmin, qnnmax, qpnmin, qpnmax, qnpmin, qnpmax, qppmin,      &
-         &                  qppmax, qndmin, qndmax, qpdmin, qpdmax, qfnmax, qfpmax, qfdmax,  &
-         &                  qfnopt, qfpopt, qfdopt
-      !!----------------------------------------------------------------------
-      !
-      REWIND( numnatp_ref )              ! Namelist nampislim in reference namelist : Pisces nutrient limitation parameters
-      READ  ( numnatp_ref, namp5zice, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampislim in reference namelist', lwp )
-      !
-      REWIND( numnatp_cfg )              ! Namelist nampislim in configuration namelist : Pisces nutrient limitation parameters 
-      READ  ( numnatp_cfg, namp5zice, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampislim in configuration namelist', lwp )
-      IF(lwm) WRITE ( numonp, namp5zice )
-      !
-      IF(lwp) THEN                         ! control print
-         WRITE(numout,*) ' '
-         WRITE(numout,*) ' Namelist parameters for nutrient limitations, namp5zice'
-         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
-         WRITE(numout,*) '    mean rainratio                           caco3r    = ', caco3r
-         WRITE(numout,*) '    NO3 half saturation of nanophyto         concnno3  = ', concnno3
-         WRITE(numout,*) '    NO3 half saturation of picophyto         concpno3  = ', concpno3
-         WRITE(numout,*) '    NO3 half saturation of diatoms           concdno3  = ', concdno3
-         WRITE(numout,*) '    NH4 half saturation for phyto            concnnh4  = ', concnnh4
-         WRITE(numout,*) '    NH4 half saturation for pico             concpnh4  = ', concpnh4
-         WRITE(numout,*) '    NH4 half saturation for diatoms          concdnh4  = ', concdnh4
-         WRITE(numout,*) '    PO4 half saturation for phyto            concnpo4  = ', concnpo4
-         WRITE(numout,*) '    PO4 half saturation for pico             concppo4  = ', concppo4
-         WRITE(numout,*) '    PO4 half saturation for diatoms          concdpo4  = ', concdpo4
-         WRITE(numout,*) '    half saturation constant for Si uptake   xksi1     = ', xksi1
-         WRITE(numout,*) '    half saturation constant for Si/C        xksi2     = ', xksi2
-         WRITE(numout,*) '    half-sat. of DOC remineralization        xkdoc     = ', xkdoc
-         WRITE(numout,*) '    Iron half saturation for nanophyto       concnfer  = ', concnfer
-         WRITE(numout,*) '    Iron half saturation for picophyto       concpfer  = ', concpfer
-         WRITE(numout,*) '    Iron half saturation for diatoms         concdfer  = ', concdfer
-         WRITE(numout,*) '    size ratio for nanophytoplankton         xsizern   = ', xsizern
-         WRITE(numout,*) '    size ratio for picophytoplankton         xsizerp   = ', xsizerp
-         WRITE(numout,*) '    size ratio for diatoms                   xsizerd   = ', xsizerd
-         WRITE(numout,*) '    NO3 half saturation of bacteria          concbno3  = ', concbno3
-         WRITE(numout,*) '    NH4 half saturation for bacteria         concbnh4  = ', concbnh4
-         WRITE(numout,*) '    Minimum size criteria for diatoms        xsizedia  = ', xsizedia
-         WRITE(numout,*) '    Minimum size criteria for picophyto      xsizepic  = ', xsizepic
-         WRITE(numout,*) '    Minimum size criteria for nanophyto      xsizephy  = ', xsizephy
-         WRITE(numout,*) '    Fe half saturation for bacteria          concbfe   = ', concbfe
-         WRITE(numout,*) '    halk saturation constant for anoxia       oxymin   =' , oxymin
-      ENDIF
-
-      REWIND( numnatp_ref )              ! Namelist nampislim in reference namelist : Pisces nutrient limitation parameters
-      READ  ( numnatp_ref, namp5zquota, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisquota in reference namelist', lwp )
-      !
-      REWIND( numnatp_cfg )              ! Namelist nampislim in configuration namelist : Pisces nutrient limitation parameters 
-      READ  ( numnatp_cfg, namp5zquota, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampisquota in configuration namelist', lwp )
-      IF(lwm) WRITE ( numonp, namp5zquota )
-      !
-      IF(lwp) THEN                         ! control print
-         WRITE(numout,*) ' '
-         WRITE(numout,*) ' Namelist parameters for nutrient limitations, namp5zquota'
-         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
-         WRITE(numout,*) '    optimal Fe quota for nano.               qfnopt    = ', qfnopt
-         WRITE(numout,*) '    optimal Fe quota for pico.               qfpopt    = ', qfpopt
-         WRITE(numout,*) '    Optimal Fe quota for diatoms             qfdopt    = ', qfdopt
-         WRITE(numout,*) '    Minimal N quota for nano                 qnnmin    = ', qnnmin
-         WRITE(numout,*) '    Maximal N quota for nano                 qnnmax    = ', qnnmax
-         WRITE(numout,*) '    Minimal P quota for nano                 qpnmin    = ', qpnmin
-         WRITE(numout,*) '    Maximal P quota for nano                 qpnmax    = ', qpnmax
-         WRITE(numout,*) '    Minimal N quota for pico                 qnpmin    = ', qnpmin
-         WRITE(numout,*) '    Maximal N quota for pico                 qnpmax    = ', qnpmax
-         WRITE(numout,*) '    Minimal P quota for pico                 qppmin    = ', qppmin
-         WRITE(numout,*) '    Maximal P quota for pico                 qppmax    = ', qppmax
-         WRITE(numout,*) '    Minimal N quota for diatoms              qndmin    = ', qndmin
-         WRITE(numout,*) '    Maximal N quota for diatoms              qndmax    = ', qndmax
-         WRITE(numout,*) '    Minimal P quota for diatoms              qpdmin    = ', qpdmin
-         WRITE(numout,*) '    Maximal P quota for diatoms              qpdmax    = ', qpdmax
-         WRITE(numout,*) '    Maximal Fe quota for nanophyto.          qfnmax    = ', qfnmax
-         WRITE(numout,*) '    Maximal Fe quota for picophyto.          qfpmax    = ', qfpmax
-         WRITE(numout,*) '    Maximal Fe quota for diatoms             qfdmax    = ', qfdmax
-      ENDIF
-      !
-      zpsino3 = 2.3 * rno3
-      zpsinh4 = 1.8 * rno3
-      zpsiuptk = 2.3 * rno3
-      !
-      nitrfac (:,:,:) = 0._wp
-      !
-   END SUBROUTINE p5z_lim_init
-
-
-   INTEGER FUNCTION p5z_lim_alloc()
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE p5z_lim_alloc  ***
-      !!----------------------------------------------------------------------
-      USE lib_mpp , ONLY: ctl_warn
-      INTEGER ::   ierr(2)        ! Local variables
-      !!----------------------------------------------------------------------
-      ierr(:) = 0
-      !
-      !*  Biological arrays for phytoplankton growth
-      ALLOCATE( xpicono3(jpi,jpj,jpk), xpiconh4(jpi,jpj,jpk),       &
-         &      xpicopo4(jpi,jpj,jpk), xpicodop(jpi,jpj,jpk),       &
-         &      xnanodop(jpi,jpj,jpk), xdiatdop(jpi,jpj,jpk),       &
-         &      xnanono3(jpi,jpj,jpk), xdiatno3(jpi,jpj,jpk),       &
-         &      xnanonh4(jpi,jpj,jpk), xdiatnh4(jpi,jpj,jpk),       &
-         &      xnanopo4(jpi,jpj,jpk), xdiatpo4(jpi,jpj,jpk),       &
-         &      xlimphy (jpi,jpj,jpk), xlimdia (jpi,jpj,jpk),       &
-         &      xlimnfe (jpi,jpj,jpk), xlimdfe (jpi,jpj,jpk),       &
-         &      xlimbac (jpi,jpj,jpk), xlimbacl(jpi,jpj,jpk),       &
-         &      xnanofer(jpi,jpj,jpk), xdiatfer(jpi,jpj,jpk),       &
-         &      xpicofer(jpi,jpj,jpk), xlimpfe (jpi,jpj,jpk),       &
-         &      fvnuptk (jpi,jpj,jpk), fvduptk (jpi,jpj,jpk),       &
-         &      fvpuptk (jpi,jpj,jpk), xlimpic (jpi,jpj,jpk),       &
-         &      xlimsi  (jpi,jpj,jpk), STAT=ierr(1) )
-         !
-      !*  Minimum/maximum quotas of phytoplankton
-      ALLOCATE( xqnnmin (jpi,jpj,jpk), xqnnmax(jpi,jpj,jpk),       &
-         &      xqpnmin (jpi,jpj,jpk), xqpnmax(jpi,jpj,jpk),       &
-         &      xqnpmin (jpi,jpj,jpk), xqnpmax(jpi,jpj,jpk),       &
-         &      xqppmin (jpi,jpj,jpk), xqppmax(jpi,jpj,jpk),       &
-         &      xqndmin (jpi,jpj,jpk), xqndmax(jpi,jpj,jpk),       &
-         &      xqpdmin (jpi,jpj,jpk), xqpdmax(jpi,jpj,jpk),     STAT=ierr(2) )
-         !
-      p5z_lim_alloc = MAXVAL( ierr )
-      !
-      IF( p5z_lim_alloc /= 0 ) CALL ctl_warn('p5z_lim_alloc : failed to allocate arrays.')
-      !
-   END FUNCTION p5z_lim_alloc
-   !!======================================================================
-END MODULE p5zice
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zlim.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zlim.F90	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zlim.F90	(revision 10345)
@@ -0,0 +1,602 @@
+MODULE p5zlim
+   !!======================================================================
+   !!                         ***  MODULE p5zlim  ***
+   !! TOP :   PISCES with variable stoichiometry 
+   !!======================================================================
+   !! History :   1.0  !  2004     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!             3.4  !  2011-04  (O. Aumont, C. Ethe) Limitation for iron modelled in quota 
+   !!             3.6  !  2015-05  (O. Aumont) PISCES quota
+   !!----------------------------------------------------------------------
+   !!   p5z_lim        :   Compute the nutrients limitation terms 
+   !!   p5z_lim_init   :   Read the namelist 
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Shared ocean-passive tracers variables
+   USE trc             ! Tracers defined
+   USE sms_pisces      ! PISCES variables
+   USE iom             !  I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC p5z_lim    
+   PUBLIC p5z_lim_init    
+   PUBLIC p5z_lim_alloc
+
+   !! * Shared module variables
+   REAL(wp), PUBLIC ::  concnno3    !:  NO3, PO4 half saturation   
+   REAL(wp), PUBLIC ::  concpno3    !:  NO3, PO4 half saturation   
+   REAL(wp), PUBLIC ::  concdno3    !:  Phosphate half saturation for diatoms  
+   REAL(wp), PUBLIC ::  concnnh4    !:  NH4 half saturation for phyto  
+   REAL(wp), PUBLIC ::  concpnh4    !:  NH4 half saturation for phyto  
+   REAL(wp), PUBLIC ::  concdnh4    !:  NH4 half saturation for diatoms
+   REAL(wp), PUBLIC ::  concnpo4    !:  NH4 half saturation for diatoms
+   REAL(wp), PUBLIC ::  concppo4    !:  NH4 half saturation for diatoms
+   REAL(wp), PUBLIC ::  concdpo4    !:  NH4 half saturation for diatoms
+   REAL(wp), PUBLIC ::  concnfer    !:  Iron half saturation for nanophyto 
+   REAL(wp), PUBLIC ::  concpfer    !:  Iron half saturation for nanophyto 
+   REAL(wp), PUBLIC ::  concdfer    !:  Iron half saturation for diatoms  
+   REAL(wp), PUBLIC ::  concbno3    !:  NO3 half saturation  for bacteria 
+   REAL(wp), PUBLIC ::  concbnh4    !:  NH4 half saturation for bacteria
+   REAL(wp), PUBLIC ::  concbpo4    !:  PO4 half saturation for bacteria
+   REAL(wp), PUBLIC ::  xsizedia    !:  Minimum size criteria for diatoms
+   REAL(wp), PUBLIC ::  xsizepic    !:  Minimum size criteria for diatoms
+   REAL(wp), PUBLIC ::  xsizephy    !:  Minimum size criteria for nanophyto
+   REAL(wp), PUBLIC ::  xsizern     !:  Size ratio for nanophytoplankton
+   REAL(wp), PUBLIC ::  xsizerp     !:  Size ratio for nanophytoplankton
+   REAL(wp), PUBLIC ::  xsizerd     !:  Size ratio for diatoms
+   REAL(wp), PUBLIC ::  xksi1       !:  half saturation constant for Si uptake 
+   REAL(wp), PUBLIC ::  xksi2       !:  half saturation constant for Si/C 
+   REAL(wp), PUBLIC ::  xkdoc       !:  2nd half-sat. of DOC remineralization  
+   REAL(wp), PUBLIC ::  concbfe     !:  Fe half saturation for bacteria 
+   REAL(wp), PUBLIC ::  oxymin      !:  half saturation constant for anoxia
+   REAL(wp), PUBLIC ::  qfnopt      !:  optimal Fe quota for nanophyto
+   REAL(wp), PUBLIC ::  qfpopt      !:  optimal Fe quota for nanophyto
+   REAL(wp), PUBLIC ::  qfdopt      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  caco3r      !:  mean rainratio 
+   REAL(wp), PUBLIC ::  qnnmin      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qnnmax      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qpnmin      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qpnmax      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qnpmin      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qnpmax      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qppmin      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qppmax      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qndmin      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qndmax      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qpdmin      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qpdmax      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qfnmax      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qfpmax      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  qfdmax      !:  optimal Fe quota for diatoms
+   REAL(wp), PUBLIC ::  zpsinh4
+   REAL(wp), PUBLIC ::  zpsino3
+   REAL(wp), PUBLIC ::  zpsiuptk
+
+   !!*  Allometric variations of the quotas
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqnnmin    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqnnmax    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqpnmin    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqpnmax    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqnpmin    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqnpmax    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqppmin    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqppmax    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqndmin    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqndmax    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqpdmin    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,   DIMENSION(:,:,:)  ::   xqpdmax    !: ???
+
+   !!* Phytoplankton limitation terms
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanono3   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatno3   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanonh4   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatnh4   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanopo4   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatpo4   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimphy    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimdia    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimnfe    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimdfe    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimsi     !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimbac    !: ??
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimbacl   !: ??
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xpicono3   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xpiconh4   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xpicopo4   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanodop   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xpicodop   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatdop   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xnanofer   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xpicofer   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xdiatfer   !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimpic    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   xlimpfe    !: ???
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   fvnuptk
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   fvpuptk
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  ::   fvduptk
+
+   ! Coefficient for iron limitation
+   REAL(wp) ::  xcoef1   = 0.00167  / 55.85
+   REAL(wp) ::  xcoef2   = 1.21E-5 * 14. / 55.85 / 7.625 * 0.5 * 1.5
+   REAL(wp) ::  xcoef3   = 1.15E-4 * 14. / 55.85 / 7.625 * 0.5 
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
+   !! $Id: p5zlim.F90 10070 2018-08-28 14:30:54Z nicolasmartin $ 
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p5z_lim( kt, knt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p5z_lim  ***
+      !!
+      !! ** Purpose :   Compute the co-limitations by the various nutrients
+      !!              for the various phytoplankton species
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      !
+      INTEGER, INTENT(in)  :: kt, knt
+      !
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zlim1, zlim2, zlim3, zlim4, zno3, zferlim
+      REAL(wp) ::   z1_trndia, z1_trnpic, z1_trnphy, ztem1, ztem2, zetot1
+      REAL(wp) ::   zratio, zration, zratiof, znutlim, zfalim
+      REAL(wp) ::   zconc1d, zconc1dnh4, zconc0n, zconc0nnh4, zconc0npo4, zconc0dpo4
+      REAL(wp) ::   zconc0p, zconc0pnh4, zconc0ppo4, zconcpfe, zconcnfe, zconcdfe
+      REAL(wp) ::   fanano, fananop, fananof, fadiat, fadiatp, fadiatf
+      REAL(wp) ::   fapico, fapicop, fapicof
+      REAL(wp) ::   zrpho, zrass, zcoef, zfuptk, zratchl
+      REAL(wp) ::   zfvn, zfvp, zfvf, zsizen, zsizep, zsized, znanochl, zpicochl, zdiatchl
+      REAL(wp) ::   zqfemn, zqfemp, zqfemd, zbactno3, zbactnh4
+      !!---------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('p5z_lim')
+      !
+      zratchl = 6.0
+      !
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ! 
+               ! Tuning of the iron concentration to a minimum level that is set to the detection limit
+               !-------------------------------------
+               zno3    = trb(ji,jj,jk,jpno3) / 40.e-6
+               zferlim = MAX( 3e-11 * zno3 * zno3, 5e-12 )
+               zferlim = MIN( zferlim, 7e-11 )
+               trb(ji,jj,jk,jpfer) = MAX( trb(ji,jj,jk,jpfer), zferlim )
+
+               ! Computation of the mean relative size of each community
+               ! -------------------------------------------------------
+               z1_trnphy   = 1. / ( trb(ji,jj,jk,jpphy) + rtrn )
+               z1_trnpic   = 1. / ( trb(ji,jj,jk,jppic) + rtrn )
+               z1_trndia   = 1. / ( trb(ji,jj,jk,jpdia) + rtrn )
+               znanochl = trb(ji,jj,jk,jpnch) * z1_trnphy
+               zpicochl = trb(ji,jj,jk,jppch) * z1_trnpic
+               zdiatchl = trb(ji,jj,jk,jpdch) * z1_trndia
+
+               ! Computation of a variable Ks for iron on diatoms taking into account
+               ! that increasing biomass is made of generally bigger cells
+               !------------------------------------------------
+               zsized            = sized(ji,jj,jk)**0.81
+               zconcdfe          = concdfer * zsized
+               zconc1d           = concdno3 * zsized
+               zconc1dnh4        = concdnh4 * zsized
+               zconc0dpo4        = concdpo4 * zsized
+
+               zsizep            = 1.
+               zconcpfe          = concpfer * zsizep
+               zconc0p           = concpno3 * zsizep
+               zconc0pnh4        = concpnh4 * zsizep
+               zconc0ppo4        = concppo4 * zsizep
+
+               zsizen            = 1.
+               zconcnfe          = concnfer * zsizen
+               zconc0n           = concnno3 * zsizen
+               zconc0nnh4        = concnnh4 * zsizen
+               zconc0npo4        = concnpo4 * zsizen
+
+               ! Allometric variations of the minimum and maximum quotas
+               ! From Talmy et al. (2014) and Maranon et al. (2013)
+               ! -------------------------------------------------------
+               xqnnmin(ji,jj,jk) = qnnmin
+               xqnnmax(ji,jj,jk) = qnnmax
+               xqndmin(ji,jj,jk) = qndmin * sized(ji,jj,jk)**(-0.27) 
+               xqndmax(ji,jj,jk) = qndmax
+               xqnpmin(ji,jj,jk) = qnpmin
+               xqnpmax(ji,jj,jk) = qnpmax
+
+               ! Computation of the optimal allocation parameters
+               ! Based on the different papers by Pahlow et al., and Smith et al.
+               ! -----------------------------------------------------------------
+               znutlim = MAX( trb(ji,jj,jk,jpnh4) / zconc0nnh4,    &
+                 &         trb(ji,jj,jk,jpno3) / zconc0n)
+               fanano = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+               znutlim = trb(ji,jj,jk,jppo4) / zconc0npo4
+               fananop = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+               znutlim = biron(ji,jj,jk) / zconcnfe
+               fananof = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+               znutlim = MAX( trb(ji,jj,jk,jpnh4) / zconc0pnh4,    &
+                 &         trb(ji,jj,jk,jpno3) / zconc0p)
+               fapico = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+               znutlim = trb(ji,jj,jk,jppo4) / zconc0ppo4
+               fapicop = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+               znutlim = biron(ji,jj,jk) / zconcpfe
+               fapicof = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+               znutlim = MAX( trb(ji,jj,jk,jpnh4) / zconc1dnh4,    &
+                 &         trb(ji,jj,jk,jpno3) / zconc1d )
+               fadiat = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+               znutlim = trb(ji,jj,jk,jppo4) / zconc0dpo4
+               fadiatp = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+               znutlim = biron(ji,jj,jk) / zconcdfe
+               fadiatf = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+               !
+               ! Michaelis-Menten Limitation term for nutrients Small bacteria
+               ! -------------------------------------------------------------
+               zbactnh4 = trb(ji,jj,jk,jpnh4) / ( concbnh4 + trb(ji,jj,jk,jpnh4) )
+               zbactno3 = trb(ji,jj,jk,jpno3) / ( concbno3 + trb(ji,jj,jk,jpno3) ) * (1. - zbactnh4)
+               !
+               zlim1    = zbactno3 + zbactnh4
+               zlim2    = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + concbpo4)
+               zlim3    = biron(ji,jj,jk) / ( concbfe + biron(ji,jj,jk) )
+               zlim4    = trb(ji,jj,jk,jpdoc) / ( xkdoc   + trb(ji,jj,jk,jpdoc) )
+               xlimbacl(ji,jj,jk) = MIN( zlim1, zlim2, zlim3 )
+               xlimbac (ji,jj,jk) = xlimbacl(ji,jj,jk) * zlim4
+               !
+               ! Michaelis-Menten Limitation term for nutrients Small flagellates
+               ! -----------------------------------------------
+               zfalim = (1.-fanano) / fanano
+               xnanonh4(ji,jj,jk) = (1. - fanano) * trb(ji,jj,jk,jpnh4) / ( zfalim * zconc0nnh4 + trb(ji,jj,jk,jpnh4) )
+               xnanono3(ji,jj,jk) = (1. - fanano) * trb(ji,jj,jk,jpno3) / ( zfalim * zconc0n + trb(ji,jj,jk,jpno3) )  &
+               &                    * (1. - xnanonh4(ji,jj,jk))
+               !
+               zfalim = (1.-fananop) / fananop
+               xnanopo4(ji,jj,jk) = (1. - fananop) * trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zfalim * zconc0npo4 )
+               xnanodop(ji,jj,jk) = trb(ji,jj,jk,jpdop) / ( trb(ji,jj,jk,jpdop) + xkdoc )   &
+               &                    * ( 1.0 - xnanopo4(ji,jj,jk) )
+               xnanodop(ji,jj,jk) = 0.
+               !
+               zfalim = (1.-fananof) / fananof
+               xnanofer(ji,jj,jk) = (1. - fananof) * biron(ji,jj,jk) / ( biron(ji,jj,jk) + zfalim * zconcnfe )
+               !
+               zratiof   = trb(ji,jj,jk,jpnfe) * z1_trnphy
+               zqfemn = xcoef1 * znanochl + xcoef2 + xcoef3 * xnanono3(ji,jj,jk)
+               !
+               zration = trb(ji,jj,jk,jpnph) * z1_trnphy
+               zration = MIN(xqnnmax(ji,jj,jk), MAX( 2. * xqnnmin(ji,jj,jk), zration ))
+               fvnuptk(ji,jj,jk) = 1. / zpsiuptk * rno3 * 2. * xqnnmin(ji,jj,jk) / (zration + rtrn)  &
+               &                   * MAX(0., (1. - zratchl * znanochl / 12. ) )
+               !
+               zlim1    = max(0., (zration - 2. * xqnnmin(ji,jj,jk) )  &
+               &          / (xqnnmax(ji,jj,jk) - 2. * xqnnmin(ji,jj,jk) ) ) * xqnnmax(ji,jj,jk)  &
+               &          / (zration + rtrn)
+               zlim3    = MAX( 0.,( zratiof - zqfemn ) / qfnopt ) 
+               xlimnfe(ji,jj,jk) = MIN( 1., zlim3 )
+               xlimphy(ji,jj,jk) = MIN( 1., zlim1, zlim3 )
+               !
+               ! Michaelis-Menten Limitation term for nutrients picophytoplankton
+               ! ----------------------------------------------------------------
+               zfalim = (1.-fapico) / fapico 
+               xpiconh4(ji,jj,jk) = (1. - fapico) * trb(ji,jj,jk,jpnh4) / ( zfalim * zconc0pnh4 + trb(ji,jj,jk,jpnh4) )
+               xpicono3(ji,jj,jk) = (1. - fapico) * trb(ji,jj,jk,jpno3) / ( zfalim * zconc0p + trb(ji,jj,jk,jpno3) )  &
+               &                    * (1. - xpiconh4(ji,jj,jk))
+               !
+               zfalim = (1.-fapicop) / fapicop 
+               xpicopo4(ji,jj,jk) = (1. - fapicop) * trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zfalim * zconc0ppo4 )
+               xpicodop(ji,jj,jk) = trb(ji,jj,jk,jpdop) / ( trb(ji,jj,jk,jpdop) + xkdoc )   &
+               &                    * ( 1.0 - xpicopo4(ji,jj,jk) )
+               xpicodop(ji,jj,jk) = 0.
+               !
+               zfalim = (1.-fapicof) / fapicof
+               xpicofer(ji,jj,jk) = (1. - fapicof) * biron(ji,jj,jk) / ( biron(ji,jj,jk) + zfalim * zconcpfe )
+               !
+               zratiof   = trb(ji,jj,jk,jppfe) * z1_trnpic
+               zqfemp = xcoef1 * zpicochl + xcoef2 + xcoef3 * xpicono3(ji,jj,jk)
+               !
+               zration   = trb(ji,jj,jk,jpnpi) * z1_trnpic
+               zration = MIN(xqnpmax(ji,jj,jk), MAX( 2. * xqnpmin(ji,jj,jk), zration ))
+               fvpuptk(ji,jj,jk) = 1. / zpsiuptk * rno3 * 2. * xqnpmin(ji,jj,jk) / (zration + rtrn)  &
+               &                   * MAX(0., (1. - zratchl * zpicochl / 12. ) ) 
+               !
+               zlim1    = max(0., (zration - 2. * xqnpmin(ji,jj,jk) )  &
+               &          / (xqnpmax(ji,jj,jk) - 2. * xqnpmin(ji,jj,jk) ) ) * xqnpmax(ji,jj,jk)  &
+               &          / (zration + rtrn)
+               zlim3    = MAX( 0.,( zratiof - zqfemp ) / qfpopt )
+               xlimpfe(ji,jj,jk) = MIN( 1., zlim3 )
+               xlimpic(ji,jj,jk) = MIN( 1., zlim1, zlim3 )
+               !
+               !   Michaelis-Menten Limitation term for nutrients Diatoms
+               !   ------------------------------------------------------
+               zfalim = (1.-fadiat) / fadiat 
+               xdiatnh4(ji,jj,jk) = (1. - fadiat) * trb(ji,jj,jk,jpnh4) / ( zfalim * zconc1dnh4 + trb(ji,jj,jk,jpnh4) )
+               xdiatno3(ji,jj,jk) = (1. - fadiat) * trb(ji,jj,jk,jpno3) / ( zfalim * zconc1d + trb(ji,jj,jk,jpno3) )  &
+               &                    * (1. - xdiatnh4(ji,jj,jk))
+               !
+               zfalim = (1.-fadiatp) / fadiatp
+               xdiatpo4(ji,jj,jk) = (1. - fadiatp) * trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zfalim * zconc0dpo4 )
+               xdiatdop(ji,jj,jk) = trb(ji,jj,jk,jpdop) / ( trb(ji,jj,jk,jpdop) + xkdoc )  &
+               &                    * ( 1.0 - xdiatpo4(ji,jj,jk) )
+               xdiatdop(ji,jj,jk) = 0.
+               !
+               zfalim = (1.-fadiatf) / fadiatf
+               xdiatfer(ji,jj,jk) = (1. - fadiatf) * biron(ji,jj,jk) / ( biron(ji,jj,jk) + zfalim * zconcdfe )
+               !
+               zratiof   = trb(ji,jj,jk,jpdfe) * z1_trndia
+               zqfemd = xcoef1 * zdiatchl + xcoef2 + xcoef3 * xdiatno3(ji,jj,jk)
+               !
+               zration   = trb(ji,jj,jk,jpndi) * z1_trndia
+               zration = MIN(xqndmax(ji,jj,jk), MAX( 2. * xqndmin(ji,jj,jk), zration ))
+               fvduptk(ji,jj,jk) = 1. / zpsiuptk * rno3 * 2. * xqndmin(ji,jj,jk) / (zration + rtrn)   &
+               &                   * MAX(0., (1. - zratchl * zdiatchl / 12. ) ) 
+               !
+               zlim1    = max(0., (zration - 2. * xqndmin(ji,jj,jk) )    &
+               &          / (xqndmax(ji,jj,jk) - 2. * xqndmin(ji,jj,jk) ) )   &
+               &          * xqndmax(ji,jj,jk) / (zration + rtrn)
+               zlim3    = trb(ji,jj,jk,jpsil) / ( trb(ji,jj,jk,jpsil) + xksi(ji,jj) )
+               zlim4    = MAX( 0., ( zratiof - zqfemd ) / qfdopt )
+               xlimdfe(ji,jj,jk) = MIN( 1., zlim4 )
+               xlimdia(ji,jj,jk) = MIN( 1., zlim1, zlim3, zlim4 )
+               xlimsi(ji,jj,jk)  = MIN( zlim1, zlim4 )
+            END DO
+         END DO
+      END DO
+      !
+      ! Compute the phosphorus quota values. It is based on Litchmann et al., 2004 and Daines et al, 2013.
+      ! The relative contribution of three fonctional pools are computed: light harvesting apparatus, 
+      ! nutrient uptake pool and assembly machinery. DNA is assumed to represent 1% of the dry mass of 
+      ! phytoplankton (see Daines et al., 2013). 
+      ! --------------------------------------------------------------------------------------------------
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ! Size estimation of nanophytoplankton
+               ! ------------------------------------
+               zfvn = 2. * fvnuptk(ji,jj,jk)
+               sizen(ji,jj,jk) = MAX(1., MIN(xsizern, 1.0 / ( MAX(rtrn, zfvn) ) ) )
+
+               ! N/P ratio of nanophytoplankton
+               ! ------------------------------
+               zfuptk = 0.23 * zfvn
+               zrpho = 2.24 * trb(ji,jj,jk,jpnch) / ( trb(ji,jj,jk,jpnph) * rno3 * 15. + rtrn )
+               zrass = 1. - 0.2 - zrpho - zfuptk
+               xqpnmax(ji,jj,jk) = ( zfuptk + zrpho ) * 0.0128 * 16. + zrass * 1./ 7.2 * 16.
+               xqpnmax(ji,jj,jk) = xqpnmax(ji,jj,jk) * trb(ji,jj,jk,jpnph) / ( trb(ji,jj,jk,jpphy) + rtrn ) + 0.13
+               xqpnmin(ji,jj,jk) = 0.13 + 0.23 * 0.0128 * 16.
+
+               ! Size estimation of picophytoplankton
+               ! ------------------------------------
+               zfvn = 2. * fvpuptk(ji,jj,jk)
+               sizep(ji,jj,jk) = MAX(1., MIN(xsizerp, 1.0 / ( MAX(rtrn, zfvn) ) ) )
+
+               ! N/P ratio of picophytoplankton
+               ! ------------------------------
+               zfuptk = 0.35 * zfvn
+               zrpho = 2.24 * trb(ji,jj,jk,jppch) / ( trb(ji,jj,jk,jpnpi) * rno3 * 15. + rtrn )
+               zrass = 1. - 0.4 - zrpho - zfuptk
+               xqppmax(ji,jj,jk) =  (zrpho + zfuptk) * 0.0128 * 16. + zrass * 1./ 9. * 16.
+               xqppmax(ji,jj,jk) = xqppmax(ji,jj,jk) * trb(ji,jj,jk,jpnpi) / ( trb(ji,jj,jk,jppic) + rtrn ) + 0.13
+               xqppmin(ji,jj,jk) = 0.13
+
+               ! Size estimation of diatoms
+               ! --------------------------
+               zfvn = 2. * fvduptk(ji,jj,jk)
+               sized(ji,jj,jk) = MAX(1., MIN(xsizerd, 1.0 / ( MAX(rtrn, zfvn) ) ) )
+               zcoef = trb(ji,jj,jk,jpdia) - MIN(xsizedia, trb(ji,jj,jk,jpdia) )
+               sized(ji,jj,jk) = 1. + xsizerd * zcoef *1E6 / ( 1. + zcoef * 1E6 )
+
+               ! N/P ratio of diatoms
+               ! --------------------
+               zfuptk = 0.2 * zfvn
+               zrpho = 2.24 * trb(ji,jj,jk,jpdch) / ( trb(ji,jj,jk,jpndi) * rno3 * 15. + rtrn )
+               zrass = 1. - 0.2 - zrpho - zfuptk
+               xqpdmax(ji,jj,jk) = ( zfuptk + zrpho ) * 0.0128 * 16. + zrass * 1./ 7.2 * 16.
+               xqpdmax(ji,jj,jk) = xqpdmax(ji,jj,jk) * trb(ji,jj,jk,jpndi) / ( trb(ji,jj,jk,jpdia) + rtrn ) + 0.13
+               xqpdmin(ji,jj,jk) = 0.13 + 0.2 * 0.0128 * 16.
+
+            END DO
+         END DO
+      END DO
+
+      ! Compute the fraction of nanophytoplankton that is made of calcifiers
+      ! --------------------------------------------------------------------
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zlim1 =  trb(ji,jj,jk,jpnh4) / ( trb(ji,jj,jk,jpnh4) + concnnh4 ) + trb(ji,jj,jk,jpno3)    &
+               &        / ( trb(ji,jj,jk,jpno3) + concnno3 ) * ( 1.0 - trb(ji,jj,jk,jpnh4)   &
+               &        / ( trb(ji,jj,jk,jpnh4) + concnnh4 ) )
+               zlim2  = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + concnpo4 )
+               zlim3  = trb(ji,jj,jk,jpfer) / ( trb(ji,jj,jk,jpfer) +  5.E-11 ) 
+               ztem1  = MAX( 0., tsn(ji,jj,jk,jp_tem) )
+               ztem2  = tsn(ji,jj,jk,jp_tem) - 10.
+               zetot1 = MAX( 0., etot(ji,jj,jk) - 1.) / ( 4. + etot(ji,jj,jk) ) * 20. / ( 20. + etot(ji,jj,jk) ) 
+
+!               xfracal(ji,jj,jk) = caco3r * MIN( zlim1, zlim2, zlim3 )                  &
+               xfracal(ji,jj,jk) = caco3r                 &
+               &                   * ztem1 / ( 1. + ztem1 ) * MAX( 1., trb(ji,jj,jk,jpphy)*1E6 )   &
+                  &                * ( 1. + EXP(-ztem2 * ztem2 / 25. ) )         &
+                  &                * zetot1 * MIN( 1., 50. / ( hmld(ji,jj) + rtrn ) )
+               xfracal(ji,jj,jk) = MAX( 0.02, MIN( 0.8 , xfracal(ji,jj,jk) ) )
+            END DO
+         END DO
+      END DO
+      !
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ! denitrification factor computed from O2 levels
+               nitrfac(ji,jj,jk) = MAX(  0.e0, 0.4 * ( 6.e-6  - trb(ji,jj,jk,jpoxy) )    &
+                  &                                / ( oxymin + trb(ji,jj,jk,jpoxy) )  )
+               nitrfac(ji,jj,jk) = MIN( 1., nitrfac(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+      !
+      IF( lk_iomput .AND. knt == nrdttrc ) THEN        ! save output diagnostics
+        IF( iom_use( "xfracal" ) ) CALL iom_put( "xfracal", xfracal(:,:,:) * tmask(:,:,:) )  ! euphotic layer deptht
+        IF( iom_use( "LNnut"   ) ) CALL iom_put( "LNnut"  , xlimphy(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
+        IF( iom_use( "LPnut"   ) ) CALL iom_put( "LPnut"  , xlimpic(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
+        IF( iom_use( "LDnut"   ) ) CALL iom_put( "LDnut"  , xlimdia(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
+        IF( iom_use( "LNFe"    ) ) CALL iom_put( "LNFe"   , xlimnfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        IF( iom_use( "LPFe"    ) ) CALL iom_put( "LPFe"   , xlimpfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        IF( iom_use( "LDFe"    ) ) CALL iom_put( "LDFe"   , xlimdfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        IF( iom_use( "SIZEN"   ) ) CALL iom_put( "SIZEN"  , sizen(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        IF( iom_use( "SIZEP"   ) ) CALL iom_put( "SIZEP"  , sizep(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        IF( iom_use( "SIZED"   ) ) CALL iom_put( "SIZED"  , sized(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+      ENDIF
+      !
+      IF( ln_timing )  CALL timing_stop('p5z_lim')
+      !
+   END SUBROUTINE p5z_lim
+
+
+   SUBROUTINE p5z_lim_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE p5z_lim_init  ***
+      !!
+      !! ** Purpose :   Initialization of nutrient limitation parameters
+      !!
+      !! ** Method  :   Read the nampislim and nampisquota namelists and check
+      !!      the parameters called at the first timestep (nittrc000)
+      !!
+      !! ** input   :   Namelist nampislim
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER :: ios                 ! Local integer output status for namelist read
+      !!
+      NAMELIST/namp5zlim/ concnno3, concpno3, concdno3, concnnh4, concpnh4, concdnh4,  &
+         &                concnfer, concpfer, concdfer, concbfe, concnpo4, concppo4,   &
+         &                concdpo4, concbno3, concbnh4, concbpo4, xsizedia, xsizepic,  &
+         &                xsizephy, xsizern, xsizerp, xsizerd, xksi1, xksi2, xkdoc,    &
+         &                caco3r, oxymin
+         !
+      NAMELIST/namp5zquota/ qnnmin, qnnmax, qpnmin, qpnmax, qnpmin, qnpmax, qppmin,      &
+         &                  qppmax, qndmin, qndmax, qpdmin, qpdmax, qfnmax, qfpmax, qfdmax,  &
+         &                  qfnopt, qfpopt, qfdopt
+      !!----------------------------------------------------------------------
+      !
+      REWIND( numnatp_ref )              ! Namelist nampislim in reference namelist : Pisces nutrient limitation parameters
+      READ  ( numnatp_ref, namp5zlim, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampislim in reference namelist', lwp )
+      !
+      REWIND( numnatp_cfg )              ! Namelist nampislim in configuration namelist : Pisces nutrient limitation parameters 
+      READ  ( numnatp_cfg, namp5zlim, IOSTAT = ios, ERR = 902 )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampislim in configuration namelist', lwp )
+      IF(lwm) WRITE ( numonp, namp5zlim )
+      !
+      IF(lwp) THEN                         ! control print
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' Namelist parameters for nutrient limitations, namp5zlim'
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '    mean rainratio                           caco3r    = ', caco3r
+         WRITE(numout,*) '    NO3 half saturation of nanophyto         concnno3  = ', concnno3
+         WRITE(numout,*) '    NO3 half saturation of picophyto         concpno3  = ', concpno3
+         WRITE(numout,*) '    NO3 half saturation of diatoms           concdno3  = ', concdno3
+         WRITE(numout,*) '    NH4 half saturation for phyto            concnnh4  = ', concnnh4
+         WRITE(numout,*) '    NH4 half saturation for pico             concpnh4  = ', concpnh4
+         WRITE(numout,*) '    NH4 half saturation for diatoms          concdnh4  = ', concdnh4
+         WRITE(numout,*) '    PO4 half saturation for phyto            concnpo4  = ', concnpo4
+         WRITE(numout,*) '    PO4 half saturation for pico             concppo4  = ', concppo4
+         WRITE(numout,*) '    PO4 half saturation for diatoms          concdpo4  = ', concdpo4
+         WRITE(numout,*) '    half saturation constant for Si uptake   xksi1     = ', xksi1
+         WRITE(numout,*) '    half saturation constant for Si/C        xksi2     = ', xksi2
+         WRITE(numout,*) '    half-sat. of DOC remineralization        xkdoc     = ', xkdoc
+         WRITE(numout,*) '    Iron half saturation for nanophyto       concnfer  = ', concnfer
+         WRITE(numout,*) '    Iron half saturation for picophyto       concpfer  = ', concpfer
+         WRITE(numout,*) '    Iron half saturation for diatoms         concdfer  = ', concdfer
+         WRITE(numout,*) '    size ratio for nanophytoplankton         xsizern   = ', xsizern
+         WRITE(numout,*) '    size ratio for picophytoplankton         xsizerp   = ', xsizerp
+         WRITE(numout,*) '    size ratio for diatoms                   xsizerd   = ', xsizerd
+         WRITE(numout,*) '    NO3 half saturation of bacteria          concbno3  = ', concbno3
+         WRITE(numout,*) '    NH4 half saturation for bacteria         concbnh4  = ', concbnh4
+         WRITE(numout,*) '    Minimum size criteria for diatoms        xsizedia  = ', xsizedia
+         WRITE(numout,*) '    Minimum size criteria for picophyto      xsizepic  = ', xsizepic
+         WRITE(numout,*) '    Minimum size criteria for nanophyto      xsizephy  = ', xsizephy
+         WRITE(numout,*) '    Fe half saturation for bacteria          concbfe   = ', concbfe
+         WRITE(numout,*) '    halk saturation constant for anoxia       oxymin   =' , oxymin
+      ENDIF
+
+      REWIND( numnatp_ref )              ! Namelist nampislim in reference namelist : Pisces nutrient limitation parameters
+      READ  ( numnatp_ref, namp5zquota, IOSTAT = ios, ERR = 903)
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisquota in reference namelist', lwp )
+      !
+      REWIND( numnatp_cfg )              ! Namelist nampislim in configuration namelist : Pisces nutrient limitation parameters 
+      READ  ( numnatp_cfg, namp5zquota, IOSTAT = ios, ERR = 904 )
+904   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampisquota in configuration namelist', lwp )
+      IF(lwm) WRITE ( numonp, namp5zquota )
+      !
+      IF(lwp) THEN                         ! control print
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' Namelist parameters for nutrient limitations, namp5zquota'
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '    optimal Fe quota for nano.               qfnopt    = ', qfnopt
+         WRITE(numout,*) '    optimal Fe quota for pico.               qfpopt    = ', qfpopt
+         WRITE(numout,*) '    Optimal Fe quota for diatoms             qfdopt    = ', qfdopt
+         WRITE(numout,*) '    Minimal N quota for nano                 qnnmin    = ', qnnmin
+         WRITE(numout,*) '    Maximal N quota for nano                 qnnmax    = ', qnnmax
+         WRITE(numout,*) '    Minimal P quota for nano                 qpnmin    = ', qpnmin
+         WRITE(numout,*) '    Maximal P quota for nano                 qpnmax    = ', qpnmax
+         WRITE(numout,*) '    Minimal N quota for pico                 qnpmin    = ', qnpmin
+         WRITE(numout,*) '    Maximal N quota for pico                 qnpmax    = ', qnpmax
+         WRITE(numout,*) '    Minimal P quota for pico                 qppmin    = ', qppmin
+         WRITE(numout,*) '    Maximal P quota for pico                 qppmax    = ', qppmax
+         WRITE(numout,*) '    Minimal N quota for diatoms              qndmin    = ', qndmin
+         WRITE(numout,*) '    Maximal N quota for diatoms              qndmax    = ', qndmax
+         WRITE(numout,*) '    Minimal P quota for diatoms              qpdmin    = ', qpdmin
+         WRITE(numout,*) '    Maximal P quota for diatoms              qpdmax    = ', qpdmax
+         WRITE(numout,*) '    Maximal Fe quota for nanophyto.          qfnmax    = ', qfnmax
+         WRITE(numout,*) '    Maximal Fe quota for picophyto.          qfpmax    = ', qfpmax
+         WRITE(numout,*) '    Maximal Fe quota for diatoms             qfdmax    = ', qfdmax
+      ENDIF
+      !
+      zpsino3 = 2.3 * rno3
+      zpsinh4 = 1.8 * rno3
+      zpsiuptk = 2.3 * rno3
+      !
+      nitrfac (:,:,:) = 0._wp
+      !
+   END SUBROUTINE p5z_lim_init
+
+
+   INTEGER FUNCTION p5z_lim_alloc()
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE p5z_lim_alloc  ***
+      !!----------------------------------------------------------------------
+      USE lib_mpp , ONLY: ctl_warn
+      INTEGER ::   ierr(2)        ! Local variables
+      !!----------------------------------------------------------------------
+      ierr(:) = 0
+      !
+      !*  Biological arrays for phytoplankton growth
+      ALLOCATE( xpicono3(jpi,jpj,jpk), xpiconh4(jpi,jpj,jpk),       &
+         &      xpicopo4(jpi,jpj,jpk), xpicodop(jpi,jpj,jpk),       &
+         &      xnanodop(jpi,jpj,jpk), xdiatdop(jpi,jpj,jpk),       &
+         &      xnanono3(jpi,jpj,jpk), xdiatno3(jpi,jpj,jpk),       &
+         &      xnanonh4(jpi,jpj,jpk), xdiatnh4(jpi,jpj,jpk),       &
+         &      xnanopo4(jpi,jpj,jpk), xdiatpo4(jpi,jpj,jpk),       &
+         &      xlimphy (jpi,jpj,jpk), xlimdia (jpi,jpj,jpk),       &
+         &      xlimnfe (jpi,jpj,jpk), xlimdfe (jpi,jpj,jpk),       &
+         &      xlimbac (jpi,jpj,jpk), xlimbacl(jpi,jpj,jpk),       &
+         &      xnanofer(jpi,jpj,jpk), xdiatfer(jpi,jpj,jpk),       &
+         &      xpicofer(jpi,jpj,jpk), xlimpfe (jpi,jpj,jpk),       &
+         &      fvnuptk (jpi,jpj,jpk), fvduptk (jpi,jpj,jpk),       &
+         &      fvpuptk (jpi,jpj,jpk), xlimpic (jpi,jpj,jpk),       &
+         &      xlimsi  (jpi,jpj,jpk), STAT=ierr(1) )
+         !
+      !*  Minimum/maximum quotas of phytoplankton
+      ALLOCATE( xqnnmin (jpi,jpj,jpk), xqnnmax(jpi,jpj,jpk),       &
+         &      xqpnmin (jpi,jpj,jpk), xqpnmax(jpi,jpj,jpk),       &
+         &      xqnpmin (jpi,jpj,jpk), xqnpmax(jpi,jpj,jpk),       &
+         &      xqppmin (jpi,jpj,jpk), xqppmax(jpi,jpj,jpk),       &
+         &      xqndmin (jpi,jpj,jpk), xqndmax(jpi,jpj,jpk),       &
+         &      xqpdmin (jpi,jpj,jpk), xqpdmax(jpi,jpj,jpk),     STAT=ierr(2) )
+         !
+      p5z_lim_alloc = MAXVAL( ierr )
+      !
+      IF( p5z_lim_alloc /= 0 ) CALL ctl_warn('p5z_lim_alloc : failed to allocate arrays.')
+      !
+   END FUNCTION p5z_lim_alloc
+   !!======================================================================
+END MODULE p5zlim
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zmicro.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zmicro.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zmicro.F90	(revision 10345)
@@ -15,5 +15,5 @@
    USE trc             !  passive tracers common variables 
    USE sms_pisces      !  PISCES Source Minus Sink variables
-   USE p5zice          !  Phytoplankton limitation terms
+   USE p5zlim          !  Phytoplankton limitation terms
    USE iom             !  I/O manager
    USE prtctl_trc      !  print control for debugging
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zmort.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zmort.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zmort.F90	(revision 10345)
@@ -14,5 +14,5 @@
    USE trc             !  passive tracers common variables 
    USE sms_pisces      !  PISCES Source Minus Sink variables
-   USE p5zice          !  Phytoplankton limitation terms
+   USE p5zlim          !  Phytoplankton limitation terms
    USE prtctl_trc      !  print control for debugging
 
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zprod.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zprod.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zprod.F90	(revision 10345)
@@ -16,5 +16,5 @@
    USE trc             !  passive tracers common variables 
    USE sms_pisces      !  PISCES Source Minus Sink variables
-   USE p5zice          !  Co-limitations of differents nutrients
+   USE p5zlim          !  Co-limitations of differents nutrients
    USE prtctl_trc      !  print control for debugging
    USE iom             !  I/O manager
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/oce_sed.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/oce_sed.F90	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/oce_sed.F90	(revision 10345)
@@ -0,0 +1,60 @@
+MODULE oce_sed
+   !!======================================================================
+   !!                        ***  sed  ***
+   !! Sediment :   set sediment global variables
+   !!======================================================================
+   !! History :
+   !!        !  06-12  (C. Ethe)  Orignal
+   !!----------------------------------------------------------------------
+   USE par_sed
+   USE timing
+   USE par_trc
+
+   USE dom_oce , ONLY :   nidom     =>   nidom          !:
+   USE dom_oce , ONLY :   glamt     =>   glamt          !: longitude of t-point (degre)
+   USE dom_oce , ONLY :   gphit     =>   gphit          !: latitude  of t-point (degre)
+   USE dom_oce , ONLY :   e3t_n     =>   e3t_n          !: latitude  of t-point (degre)
+   USE dom_oce , ONLY :   e3t_1d    =>   e3t_1d         !: reference depth of t-points (m)
+   USE dom_oce , ONLY :   gdepw_0   =>   gdepw_0        !: reference depth of t-points (m)
+   USE dom_oce , ONLY :   mbkt      =>   mbkt           !: vertical index of the bottom last T- ocean level
+   USE dom_oce , ONLY :   tmask     =>   tmask          !: land/ocean mask at t-points
+   USE dom_oce , ONLY :   rdt       =>   rdt            !: time step for the dynamics
+   USE dom_oce , ONLY :   nyear     =>   nyear          !: Current year
+   USE dom_oce , ONLY :   nmonth    =>   nmonth         !: Current month
+   USE dom_oce , ONLY :   nday      =>   nday           !: Current day
+   USE dom_oce , ONLY :   ndastp    =>   ndastp         !: time step date in year/month/day aammjj
+   USE dom_oce , ONLY :   nday_year =>   nday_year      !: curent day counted from jan 1st of the current year
+   USE dom_oce , ONLY :   adatrj    =>   adatrj         !: number of elapsed days since the begining of the run
+   USE trc     , ONLY :  nittrc000  =>   nittrc000
+   !                                !: it is the accumulated duration of previous runs
+   !                                !: that may have been run with different time steps.
+
+   USE oce     , ONLY :  tsn        =>   tsn             !: pot. temperature (celsius) and salinity (psu)
+   USE trc     , ONLY :  trb        =>   trb             !: pot. temperature (celsius) and salinity (psu)
+
+   USE sms_pisces, ONLY : wsbio4    =>   wsbio4          !: sinking flux for POC
+   USE sms_pisces, ONLY : wsbio3    =>   wsbio3          !: sinking flux for GOC
+   USE sms_pisces, ONLY : wscal     =>   wscal           !: sinking flux for calcite
+   USE sms_pisces, ONLY : wsbio2    =>   wsbio2           !: sinking flux for calcite
+   USE sms_pisces, ONLY : wsbio     =>   wsbio           !: sinking flux for calcite
+   USE p4zche, ONLY     : akb3      =>   akb3            !: Chemical constants  
+   USE sms_pisces, ONLY : ak13      =>   ak13            !: Chemical constants  
+   USE sms_pisces, ONLY : ak23      =>   ak23            !: Chemical constants  
+   USE p4zche, ONLY     : akw3      =>   akw3            !: Chemical constants  
+   USE sms_pisces, ONLY : aksp      =>   aksp            !: Chemical constants  
+   USE p4zche, ONLY     : borat     =>   borat           !: Chemical constants ( borat ) 
+   USE p4zche, ONLY     : ak1p3     =>   ak1p3           !: Chemical constants  
+   USE p4zche, ONLY     : ak2p3     =>   ak2p3           !: Chemical constants  
+   USE p4zche, ONLY     : ak3p3     =>   ak3p3           !: Chemical constants  
+   USE p4zche, ONLY     : aksi3     =>   aksi3           !: Chemical constants  
+   USE p4zche, ONLY     : aks3      =>   aks3            !: Chemical constants  
+   USE p4zche, ONLY     : akf3      =>   akf3            !: Chemical constants  
+   USE p4zche, ONLY     : fluorid   =>   fluorid         !: Chemical constants  
+   USE p4zche, ONLY     : sulfat    =>   sulfat          !: Chemical constants  
+   USE p4zche, ONLY     : sio3eq    =>   sio3eq          !: Chemical constants  
+   USE p4zsbc, ONLY     : dust      =>   dust
+   USE trc       , ONLY : r2dttrc   =>   r2dttrc
+
+END MODULE oce_sed
+
+
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/par_sed.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/par_sed.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/par_sed.F90	(revision 10345)
@@ -7,8 +7,5 @@
    !!        !  06-12  (C. Ethe)  Orignal
    !!----------------------------------------------------------------------
-#if defined key_sed
-   !!----------------------------------------------------------------------
-   !!   'key_sed'                                                  Sediment 
-   !!----------------------------------------------------------------------
+   !! $Id$
 
    !! Domain characteristics
@@ -19,25 +16,22 @@
       jpim1    =>   jpim1 ,  & !: jpi - 1
       jpjm1    =>   jpjm1 ,  & !: jpj - 1
-      jpij     =>   jpij       !: jpi x jpj
-      jp_tem   =>   jp_tem     !: indice of temperature
+      jpij     =>   jpij  ,  & !: jpi x jpj
+      jp_tem   =>   jp_tem,  & !: indice of temperature
       jp_sal   =>   jp_sal     !: indice of salintity
 
-#if ! defined key_sed_off
-   USE par_pisces
-#endif
-
-   INTEGER, PARAMETER :: jpdta = 12
-
+   INTEGER, PARAMETER :: jpdta = 17
 
    ! Vertical sediment geometry
-   INTEGER, PARAMETER :: &
-      jpksed   = 11         ,   & !: number of sediment layers
-      jpksedm1 = jpksed - 1 
-      
+   INTEGER, PUBLIC   ::      &
+      jpksed   = 11 ,        &
+      jpksedm1 = 10
+
    ! sediment tracer species
-   INTEGER, PARAMETER :: &
-      jpsol = 4,         &  !: number of solid component
-      jpwat = 7,         &   !: number of pore water component
-      jpwatp1 = jpwat + 1
+   INTEGER, PARAMETER ::    &
+      jpsol =  8,           &  !: number of solid component
+      jpwat = 10,           &   !: number of pore water component
+      jpwatp1 = jpwat +1,   &
+      jpsol1 = jpsol - 1
+
    
    ! pore water components       
@@ -49,5 +43,8 @@
       jwpo4  = 5,        & !: phosphate
       jwalk  = 6,        & !: alkalinity
-      jwc13  = 7           !: dissolved inorganic carbon 13
+      jwnh4  = 7,        & !: Ammonium
+      jwh2s  = 8,        & !: Sulfate
+      jwso4  = 9,        & !: H2S
+      jwfe2  = 10          !: Fe2+
 
    ! solid components       
@@ -56,16 +53,14 @@
       jsclay  = 2,        & !: clay
       jspoc   = 3,        & !: organic carbon
-      jscal   = 4           !: calcite
+      jscal   = 4,        & !: calcite
+      jspos   = 5,        & !: semi-ref POC
+      jspor   = 6,        & !: refractory POC
+      jsfeo   = 7,        & !: iron hydroxides
+      jsfes   = 8           !: FeS
 
    INTEGER, PARAMETER ::  &
       jptrased   = jpsol + jpwat , &
-      jpdia3dsed = 3          , &
-      jpdia2dsed = 7
-#endif
+      jpdia3dsed = 2             , &
+      jpdia2dsed = 12
 
-   !!----------------------------------------------------------------------
-   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
-   !! $Id$ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!======================================================================
 END MODULE par_sed
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sed.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sed.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sed.F90	(revision 10345)
@@ -7,79 +7,55 @@
    !!        !  06-12  (C. Ethe)  Orignal
    !!----------------------------------------------------------------------
-#if defined key_sed
-   !!----------------------------------------------------------------------
-   !!   'key_sed'                                                  Sediment 
-   !!----------------------------------------------------------------------
    USE par_sed
+   USE oce_sed
    USE in_out_manager
+
 
    IMPLICIT NONE
    PUBLIC
 
-   PUBLIC sed_alloc   
-
-   USE dom_oce , ONLY :   nidom     =>   nidom          !:
-   USE dom_oce , ONLY :   glamt     =>   glamt          !: longitude of t-point (degre)
-   USE dom_oce , ONLY :   gphit     =>   gphit          !: latitude  of t-point (degre)
-   USE dom_oce , ONLY :   e3t_1d    =>   e3t_1d         !: reference depth of t-points (m)
-   USE dom_oce , ONLY :   mbkt      =>   mbkt           !: vertical index of the bottom last T- ocean level
-   USE dom_oce , ONLY :   tmask     =>   tmask          !: land/ocean mask at t-points
-   USE dom_oce , ONLY :   rdt       =>   rdt            !: time step for the dynamics
-   USE dom_oce , ONLY :   nyear     =>   nyear          !: Current year
-   USE dom_oce , ONLY :   nmonth    =>   nmonth         !: Current month
-   USE dom_oce , ONLY :   nday      =>   nday           !: Current day
-   USE dom_oce , ONLY :   ndastp    =>   ndastp         !: time step date in year/month/day aammjj
-   USE dom_oce , ONLY :   nday_year =>   nday_year      !: curent day counted from jan 1st of the current year
-   USE dom_oce , ONLY :   adatrj    =>   adatrj         !: number of elapsed days since the begining of the run
-   !                                !: it is the accumulated duration of previous runs
-   !                                !: that may have been run with different time steps.
-
-#if ! defined key_sed_off
-
-   USE oce     , ONLY :  tsn        =>   tsn             !: pot. temperature (celsius) and salinity (psu)
-
-   USE trc     , ONLY :  trn        =>   trc             !: tracer 
-   USE trc     , ONLY :  nwritetrc  =>   nwritetrc       !: outputs frequency of tracer model
-
-   USE p4zsink , ONLY :  sinking    =>   sinking         !: sinking flux for POC
-   USE p4zsink , ONLY :  sinking2   =>   sinking2        !: sinking flux for GOC
-   USE p4zsink , ONLY :  sinkcal    =>   sinkcal         !: sinking flux for calcite
-   USE p4zsink , ONLY :  sinksil    =>   sinksil         !: sinking flux for opal ( dsi )
-
-   USE sms_pisces, ONLY : akb3      =>   akb3            !: Chemical constants  
-   USE sms_pisces, ONLY : ak13      =>   ak13            !: Chemical constants  
-   USE sms_pisces, ONLY : ak23      =>   ak23            !: Chemical constants  
-   USE sms_pisces, ONLY : akw3      =>   akw3            !: Chemical constants  
-   USE sms_pisces, ONLY : aksp      =>   aksp            !: Chemical constants  
-   USE sms_pisces, ONLY : borat     =>   borat           !: Chemical constants ( borat ) 
-
-#endif   
-
+   PUBLIC sed_alloc
 
    !! Namelist
-   REAL(wp), PUBLIC, DIMENSION(5) ::  reac                !: reactivity rc in  [l.mol-1.s-1]
    REAL(wp), PUBLIC               ::  reac_sil            !: reactivity of silicate in  [l.mol-1.s-1]
    REAL(wp), PUBLIC               ::  reac_clay           !: reactivity of clay in  [l.mol-1.s-1]
-   REAL(wp), PUBLIC               ::  reac_poc            !: reactivity of poc in  [l.mol-1.s-1]
-   REAL(wp), PUBLIC               ::  reac_no3            !: reactivity of no3 in  [l.mol-1.s-1]
+   REAL(wp), PUBLIC               ::  reac_ligc           !: reactivity of Ligands [l.mol-1.s-1]
+   REAL(wp), PUBLIC               ::  reac_pocl           !: reactivity of pocl in  [s-1]
+   REAL(wp), PUBLIC               ::  reac_pocs           !: reactivity of pocs in  [s-1]
+   REAL(wp), PUBLIC               ::  reac_pocr           !: reactivity of pocr in  [s-1]
+   REAL(wp), PUBLIC               ::  reac_nh4            !: reactivity of NH4 in  [l.mol-1.s-1]
+   REAL(wp), PUBLIC               ::  reac_h2s            !: reactivity of ODU in  [l.mol-1.s-1]
+   REAL(wp), PUBLIC               ::  reac_fe2            !: reactivity of Fe2+ in  [l.mol-1.s-1]
+   REAL(wp), PUBLIC               ::  reac_feh2s          !: reactivity of Fe2+ in  [l.mol-1.s-1]
+   REAL(wp), PUBLIC               ::  reac_fes            !: reactivity of Fe with H2S in  [l.mol-1.s-1]
+   REAL(wp), PUBLIC               ::  reac_feso           !: reactivity of FeS with O2 in  [l.mol-1.s-1]
    REAL(wp), PUBLIC               ::  reac_cal            !: reactivity of cal in  [l.mol-1.s-1]
-   REAL(wp), PUBLIC               ::  sat_sil             !: saturation concentration for silicate in [mol.l-1]
-   REAL(wp), PUBLIC               ::  sat_clay            !: saturation concentration for clay in [mol.l-1]
+   REAL(wp), PUBLIC               ::  adsnh4              !: adsorption coefficient of NH4
+   REAL(wp), PUBLIC               ::  ratligc             !: C/L ratio in POC
    REAL(wp), PUBLIC               ::  so2ut 
    REAL(wp), PUBLIC               ::  srno3 
    REAL(wp), PUBLIC               ::  spo4r 
    REAL(wp), PUBLIC               ::  srDnit 
-   REAL(wp), PUBLIC               ::  sthro2              !: threshold O2 concen. in [mol.l-1]
-   REAL(wp), PUBLIC               ::  pdb = 0.0112372     !: 13C/12C in PD Belemnite
-   REAL(wp), PUBLIC               ::  rc13P  = 0.980      !: 13C/12C in POC = rc13P*PDB
-   REAL(wp), PUBLIC               ::  rc13Ca = 1.001      !: 13C/12C in CaCO3 = rc13Ca*PDB
    REAL(wp), PUBLIC               ::  dtsed               !: sedimentation time step
-   REAL(wp), PUBLIC               ::  db                  !: bioturb coefficient in [cm2.s-1]
-
+   REAL(wp), PUBLIC               ::  dtsed2              !: sedimentation time step
    INTEGER , PUBLIC               ::  nitsed000
    INTEGER , PUBLIC               ::  nitsedend
-   INTEGER , PUBLIC               ::  nwrised
-   INTEGER , PUBLIC               ::  nfreq
-   REAL(wp), PUBLIC               ::  dens                !: density of solid material
+   INTEGER, PUBLIC                ::  nrseddt
+   REAL    , PUBLIC               ::  sedmask
+   REAL(wp), PUBLIC               ::  denssol                !: density of solid material
+   INTEGER , PUBLIC               ::  numrsr, numrsw   !: logical unit for sed restart (read and write)
+   LOGICAL , PUBLIC               ::  lrst_sed       !: logical to control the trc restart write
+   LOGICAL , PUBLIC               ::  ln_rst_sed  = .TRUE.     !: initialisation from a restart file or not
+   LOGICAL , PUBLIC               ::  ln_btbz     = .FALSE.    !: Depth variation of the bioturbation coefficient
+   LOGICAL , PUBLIC               ::  ln_irrig    = .FALSE.    !: iActivation of the bioirrigation
+   LOGICAL , PUBLIC               ::  ln_sed_2way = .FALSE.    !: 2 way coupling with PISCES
+   LOGICAL , PUBLIC               ::  ln_sediment_offline = .FALSE. !: Offline mode for sediment module
+   INTEGER             , PUBLIC   ::  nn_rstsed      !: control of the time step ( 0 or 1 ) for pass. tr.
+   INTEGER , PUBLIC               ::  nn_dtsed = 1   !: frequency of step on passive tracers
+   CHARACTER(len = 80) , PUBLIC   ::  cn_sedrst_in   !: suffix of pass. tracer restart name (input)
+   CHARACTER(len = 256), PUBLIC   ::  cn_sedrst_indir  !: restart input directory
+   CHARACTER(len = 80) , PUBLIC   ::  cn_sedrst_out  !: suffix of pass. tracer restart name (output)
+   CHARACTER(len = 256), PUBLIC   ::  cn_sedrst_outdir  !: restart output directory
+
    !
    REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::  pwcp       !: pore water sediment data at given time-step
@@ -87,4 +63,6 @@
    REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::  solcp      !: solid sediment data at given time-step
    REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::  solcp0     !: solid sediment data at initial time
+   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::  trc_dta
+   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::  diff
 
    !! * Shared module variables
@@ -102,5 +80,8 @@
    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  press      !: pressure
    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  raintg     !: total massic flux rained in each cell (sum of sol. comp.)
+   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  fecratio   !: Fe/C ratio in falling particles to the sediments
    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  dzdep      !: total thickness of solid material rained [cm] in each cell
+   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  zkbot      !: total thickness of solid material rained [cm] in each cell
+   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  wacc       !: total thickness of solid material rained [cm] in each cell
    !
    REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE ::  hipor      !: [h+] in mol/kg*densSW 
@@ -127,4 +108,9 @@
    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  aksis 
    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  aksps 
+   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  sieqs
+   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  aks3s
+   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  akf3s
+   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  sulfats
+   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  fluorids
 
    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  mol_wgt    !: molecular weight of solid sediment data
@@ -133,17 +119,17 @@
    !! Geometry
    INTEGER , PUBLIC, SAVE                          ::  jpoce, indoce !: Ocean points ( number/indices )
-   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  iarroce       !: Computation of 1D array of sediments points
+   INTEGER , PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  iarroce       !: Computation of 1D array of sediments points
    REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE ::  epkbot        !: ocean bottom layer thickness
+   REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE ::  gdepbot       !: Depth of the sediment
    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  dzkbot        !: ocean bottom layer thickness in meters
-   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::  tmasksed      !: sediment mask
-   REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE ::  sbathy        !: bathymetry
    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  dz            !: sediment layers thickness
    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  por           !: porosity profile     
    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  por1          !: 1-por 
-   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  profsed       !: depth of middle of each layer
    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  volw          !: volume of pore water cell fraction
    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  vols          !: volume of solid cell fraction
-   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  diff          !: diffusion ceofficient
+   REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE ::  db            !: bioturbation ceofficient
+   REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE ::  irrig        !: bioturbation ceofficient
    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  rdtsed        !:  sediment model time-step
+   REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE :: sedligand
    REAL(wp)  ::   dens               !: density of solid material
    !! Inputs / Outputs
@@ -171,12 +157,11 @@
       !!-------------------------------------------------------------------
       !
-      ALLOCATE( trc_dta(jpi,jpj,jdta)                                     ,   &
-         &      epkbot(jpi,jpj), sbathy(jpi,jpj)                          ,   &
-         &      tmasksed(jpi,jpj,jpksed)                                  ,   &
-         &      dz(jpksed)  , por(jpksed) , por1(jpksed), profsed(jpksed) ,   &
-         &      volw(jpksed), vols(jpksed), diff(jpksed), rdtsed(jpksed)  ,   &
+      ALLOCATE( trc_data(jpi,jpj,jpdta)                                   ,   &
+         &      epkbot(jpi,jpj), gdepbot(jpi,jpj)        ,   &
+         &      dz(jpksed)  , por(jpksed) , por1(jpksed)                  ,   &
+         &      volw(jpksed), vols(jpksed), rdtsed(jpksed)  ,   &
          &      trcsedi  (jpi,jpj,jpksed,jptrased)                        ,   &
          &      flxsedi3d(jpi,jpj,jpksed,jpdia3dsed)                      ,   &
-         &      flxsedi2d(jpi,jpj,jpksed,jpdia2dsed)                      ,   &
+         &      flxsedi2d(jpi,jpj,jpdia2dsed)                             ,   &
          &      mol_wgt(jpsol),                                           STAT=sed_alloc )
 
@@ -185,9 +170,3 @@
    END FUNCTION sed_alloc
 
-#else
-   !!======================================================================
-   !! No Sediment model
-   !!======================================================================
-#endif
-
 END MODULE sed
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sed_oce.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sed_oce.F90	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sed_oce.F90	(revision 10345)
@@ -0,0 +1,36 @@
+MODULE sed_oce
+   !!======================================================================
+   !!                        ***  sed  ***
+   !! Sediment :   set sediment global variables
+   !!======================================================================
+
+   !! History :
+   !!        !  06-12  (C. Ethe)  Orignal
+   !!----------------------------------------------------------------------
+   USE par_sed
+   USE trc, ONLY : profsed
+
+   IMPLICIT NONE
+   PUBLIC
+
+   PUBLIC sed_oce_alloc
+
+   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  profsedw       !: depth of middle of each layer
+
+   !! $Id: sed.F90 7646 2017-02-06 09:25:03Z timgraham $
+CONTAINS
+
+   INTEGER FUNCTION sed_oce_alloc()
+      !!-------------------------------------------------------------------
+      !!                    *** ROUTINE sed_alloc ***
+      !!-------------------------------------------------------------------
+      USE lib_mpp, ONLY: ctl_warn
+      !!-------------------------------------------------------------------
+      !
+      ALLOCATE( profsed(jpksed) , profsedw(jpksed) , STAT=sed_oce_alloc )
+
+      IF( sed_oce_alloc /= 0 )   CALL ctl_warn('sed_oce_alloc: failed to allocate arrays')
+      !
+   END FUNCTION sed_oce_alloc
+
+END MODULE sed_oce
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedadv.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedadv.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedadv.F90	(revision 10345)
@@ -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
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedarr.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedarr.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedarr.F90	(revision 10345)
@@ -4,5 +4,5 @@
    !!              transform 1D (2D) array to a 2D (1D) table
    !!======================================================================
-#if defined key_sed
+
    !!----------------------------------------------------------------------
    !!   arr_2d_1d  : 2-D to 1-D
@@ -11,4 +11,6 @@
    !! * Modules used
    USE par_sed
+   USE dom_oce
+   USE sed
 
    IMPLICIT NONE
@@ -28,7 +30,7 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
    !! $Id$ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 CONTAINS
@@ -42,4 +44,6 @@
 
       INTEGER ::  jn, jid, jjd
+
+      IF( ln_timing )   CALL timing_start('pack_arr_2d_1d')
         
       DO jn = 1, ndim1d
@@ -48,4 +52,6 @@
          tab1d(jn)  = tab2d(jid, jjd)
       END DO 
+
+      IF( ln_timing )   CALL timing_stop('pack_arr_2d_1d')
 
    END SUBROUTINE pack_arr_2d_1d
@@ -59,4 +65,6 @@
       INTEGER ::  jn, jid, jjd
 
+      IF( ln_timing )   CALL timing_start('unpack_arr_1d_2d')
+
       DO jn = 1, ndim1d
          jid             = MOD( tab_ind(jn) - 1, jpi) + 1
@@ -64,4 +72,6 @@
          tab2d(jid, jjd) = tab1d(jn)
       END DO
+
+      IF( ln_timing )   CALL timing_stop('unpack_arr_1d_2d')
 
    END SUBROUTINE unpack_arr_1d_2d
@@ -75,4 +85,6 @@
       INTEGER, DIMENSION(ndim1d) ::  jid, jjd        
       INTEGER ::    jk, jn , ji, jj
+
+      IF( ln_timing )   CALL timing_start('pack_arr_2d_3d')
       
       DO jn = 1, ndim1d
@@ -88,4 +100,6 @@
          ENDDO
       ENDDO
+
+      IF( ln_timing )   CALL timing_stop('pack_arr_2d_3d')
       
    END SUBROUTINE pack_arr_3d_2d
@@ -100,6 +114,8 @@
       INTEGER, DIMENSION(ndim1d) ::  jid, jjd        
       INTEGER ::   jk, jn , ji, jj
-
-     DO jn = 1, ndim1d
+      !
+      IF( ln_timing )   CALL timing_start('unpack_arr_2d_3d')
+      !
+      DO jn = 1, ndim1d
          jid(jn) = MOD( tab_ind(jn) - 1, jpi ) + 1
          jjd(jn) = ( tab_ind(jn) - 1 ) / jpi + 1
@@ -114,16 +130,7 @@
       ENDDO
 
+      IF( ln_timing )   CALL timing_stop('unpack_arr_2d_3d')
+
    END SUBROUTINE unpack_arr_2d_3d
 
-#else
-   !!======================================================================
-   !! MODULE sedarr  :   Dummy module
-   !!======================================================================
-CONTAINS
-   SUBROUTINE pack_arr         ! Empty routine
-   END SUBROUTINE  pack_arr
-   SUBROUTINE unpack_arr         ! Empty routine
-   END SUBROUTINE  unpack_arr
-   !!======================================================================
-#endif
 END MODULE sedarr
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedbtb.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedbtb.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedbtb.F90	(revision 10345)
@@ -1,4 +1,3 @@
 MODULE sedbtb
-#if defined key_sed
    !!======================================================================
    !!              ***  MODULE  sedbtb  ***
@@ -8,4 +7,8 @@
    USE sed     ! sediment global variable
    USE sedmat  ! linear system of equations
+   USE lib_mpp         ! distribued memory computing library
+
+   IMPLICIT NONE
+   PRIVATE
 
    PUBLIC sed_btb
@@ -33,18 +36,17 @@
       ! * local variables
       INTEGER :: ji, jk, js
-      REAL(wp), DIMENSION(:,:,:) , ALLOCATABLE ::  zsol  !   solution
+      REAL(wp), DIMENSION(jpoce,jpksedm1,jpsol) ::  zsol  !   solution
       !------------------------------------------------------------------------
 
+      IF( ln_timing )  CALL timing_start('sed_btb')
+
       IF( kt == nitsed000 ) THEN
-         WRITE(numsed,*) ' sed_btb : Bioturbation  '
-         WRITE(numsed,*) ' '
+         IF (lwp) WRITE(numsed,*) ' sed_btb : Bioturbation  '
+         IF (lwp) WRITE(numsed,*) ' '
       ENDIF
 
       ! Initializations
       !----------------
-      ALLOCATE( zsol(jpoce,jpksedm1,jpsol) )
-
       zsol(:,:,:) = 0.
-
 
       ! right hand side of coefficient matrix
@@ -58,5 +60,5 @@
       ENDDO
 
-      CALL sed_mat( jpsol, jpoce, jpksedm1, zsol )
+      CALL sed_mat( jpsol, jpoce, jpksedm1, zsol, dtsed / 2.0 )
 
 
@@ -70,21 +72,8 @@
          ENDDO
       ENDDO
-     
-      DEALLOCATE( zsol )
+
+      IF( ln_timing )  CALL timing_stop('sed_btb')
 
    END SUBROUTINE sed_btb
-#else
-   !!======================================================================
-   !! MODULE sedbtb  :   Dummy module 
-   !!======================================================================
-   !! $Id$
-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: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedchem.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedchem.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedchem.F90	(revision 10345)
@@ -1,5 +1,4 @@
 MODULE sedchem
 
-#if defined key_sed 
    !!======================================================================
    !!                        ***  Module sedchem  ***
@@ -9,145 +8,24 @@
    USE sed     ! sediment global variable
    USE sedarr
+   USE eosbn2, ONLY : neos
+   USE lib_mpp         ! distribued memory computing library
+
+   IMPLICIT NONE
+   PRIVATE
 
    !! * Accessibility
-   PUBLIC sed_chem   
+   PUBLIC sed_chem
+   PUBLIC ahini_for_at_sed     !
+   PUBLIC solve_at_general_sed !
+
+   ! Maximum number of iterations for each method
+   INTEGER, PARAMETER :: jp_maxniter_atgen    = 20
+   REAL(wp), PARAMETER :: pp_rdel_ah_target = 1.E-4_wp
 
    !! * 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/
-
+   REAL(wp) ::   rgas   = 83.14472      ! universal gas constants
 
    ! coeff. for density of sea water (Millero & Poisson 1981) 
@@ -162,4 +40,64 @@
    REAL(wp), DIMENSION(6)  :: Ddsw                    
    DATA Ddsw / 999.842594 , 6.793952E-2 , -9.095290E-3, 1.001685E-4, -1.120083E-6, 6.536332E-9/
+
+  REAL(wp) :: devk10  = -25.5
+   REAL(wp) :: devk11  = -15.82
+   REAL(wp) :: devk12  = -29.48
+   REAL(wp) :: devk13  = -20.02
+   REAL(wp) :: devk14  = -18.03
+   REAL(wp) :: devk15  = -9.78
+   REAL(wp) :: devk16  = -48.76
+   REAL(wp) :: devk17  = -14.51
+   REAL(wp) :: devk18  = -23.12
+   REAL(wp) :: devk19  = -26.57
+   REAL(wp) :: devk110  = -29.48
+   !
+   REAL(wp) :: devk20  = 0.1271
+   REAL(wp) :: devk21  = -0.0219
+   REAL(wp) :: devk22  = 0.1622
+   REAL(wp) :: devk23  = 0.1119
+   REAL(wp) :: devk24  = 0.0466
+   REAL(wp) :: devk25  = -0.0090
+   REAL(wp) :: devk26  = 0.5304
+   REAL(wp) :: devk27  = 0.1211
+   REAL(wp) :: devk28  = 0.1758
+   REAL(wp) :: devk29  = 0.2020
+   REAL(wp) :: devk210  = 0.1622
+   !
+   REAL(wp) :: devk30  = 0.
+   REAL(wp) :: devk31  = 0.
+   REAL(wp) :: devk32  = 2.608E-3
+   REAL(wp) :: devk33  = -1.409e-3
+   REAL(wp) :: devk34  = 0.316e-3
+   REAL(wp) :: devk35  = -0.942e-3
+   REAL(wp) :: devk36  = 0.
+   REAL(wp) :: devk37  = -0.321e-3
+   REAL(wp) :: devk38  = -2.647e-3
+   REAL(wp) :: devk39  = -3.042e-3
+   REAL(wp) :: devk310  = -2.6080e-3
+   !
+   REAL(wp) :: devk40  = -3.08E-3
+   REAL(wp) :: devk41  = 1.13E-3
+   REAL(wp) :: devk42  = -2.84E-3
+   REAL(wp) :: devk43  = -5.13E-3
+   REAL(wp) :: devk44  = -4.53e-3
+   REAL(wp) :: devk45  = -3.91e-3
+   REAL(wp) :: devk46  = -11.76e-3
+   REAL(wp) :: devk47  = -2.67e-3
+   REAL(wp) :: devk48  = -5.15e-3
+   REAL(wp) :: devk49  = -4.08e-3
+   REAL(wp) :: devk410  = -2.84e-3
+   !
+   REAL(wp) :: devk50  = 0.0877E-3
+   REAL(wp) :: devk51  = -0.1475E-3
+   REAL(wp) :: devk52  = 0.
+   REAL(wp) :: devk53  = 0.0794E-3
+   REAL(wp) :: devk54  = 0.09e-3
+   REAL(wp) :: devk55  = 0.054e-3
+   REAL(wp) :: devk56  = 0.3692E-3
+   REAL(wp) :: devk57  = 0.0427e-3
+   REAL(wp) :: devk58  = 0.09e-3
+   REAL(wp) :: devk59  = 0.0714e-3
+   REAL(wp) :: devk510  = 0.0
 
    !! $Id$
@@ -179,69 +117,69 @@
       INTEGER, INTENT(in) :: kt                     ! time step
 
-#if ! defined key_sed_off
       INTEGER  :: ji, jj, ikt
-      REAL(wp) :: ztkel, ztc, ztc2, zpres, ztr 
-      REAL(wp) :: zsal, zsal2, zsqrt, zsal15  
-      REAL(wp) :: zis, zis2, zisqrt          
+      REAL(wp) :: ztc, ztc2
+      REAL(wp) :: zsal, zsal15  
       REAL(wp) :: zdens0, zaw, zbw, zcw    
-      REAL(wp) :: zbuf1, zbuf2 
-      REAL(wp) :: zcpexp, zcpexp2
-      REAL(wp) :: zck1p, zck2p, zck3p, zcksi   
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   zchem_data
-
-#endif
+      REAL(wp), DIMENSION(jpi,jpj,15) ::   zchem_data
       !!----------------------------------------------------------------------
 
-      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
+
+      IF( ln_timing )  CALL timing_start('sed_chem')
+
+      IF (lwp) WRITE(numsed,*) ' Getting Chemical constants from tracer model at time kt = ', kt
+      IF (lwp) WRITE(numsed,*) ' '
+
       ! reading variables
-      ALLOCATE( zchem_data(jpi,jpj,6) )   ;   zchem_data(:,:,:) = 0.
-
-      DO jj = 1,jpj
-         DO ji = 1, jpi
-            ikt = mbkt(ji,jj) 
-            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
+      zchem_data(:,:,:) = rtrn
+
+      IF (ln_sediment_offline) THEN
+         CALL sed_chem_cst
+      ELSE
+         DO jj = 1,jpj
+            DO ji = 1, jpi
+               ikt = mbkt(ji,jj) 
+               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)
+                  zchem_data(ji,jj,7) = ak1p3 (ji,jj,ikt)
+                  zchem_data(ji,jj,8) = ak2p3 (ji,jj,ikt)
+                  zchem_data(ji,jj,9) = ak3p3 (ji,jj,ikt)
+                  zchem_data(ji,jj,10)= aksi3 (ji,jj,ikt)
+                  zchem_data(ji,jj,11)= sio3eq(ji,jj,ikt)
+                  zchem_data(ji,jj,12)= aks3  (ji,jj,ikt)
+                  zchem_data(ji,jj,13)= akf3  (ji,jj,ikt)
+                  zchem_data(ji,jj,14)= sulfat(ji,jj,ikt)
+                  zchem_data(ji,jj,15)= fluorid(ji,jj,ikt)
+               ENDIF
+            ENDDO
          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) )
-
-      DEALLOCATE( zchem_data )
+
+         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) )
+         CALL pack_arr ( jpoce, ak1ps (1:jpoce), zchem_data(1:jpi,1:jpj,7) , iarroce(1:jpoce) )
+         CALL pack_arr ( jpoce, ak2ps (1:jpoce), zchem_data(1:jpi,1:jpj,8) , iarroce(1:jpoce) )
+         CALL pack_arr ( jpoce, ak3ps (1:jpoce), zchem_data(1:jpi,1:jpj,9) , iarroce(1:jpoce) )
+         CALL pack_arr ( jpoce, aksis (1:jpoce), zchem_data(1:jpi,1:jpj,10), iarroce(1:jpoce) )
+         CALL pack_arr ( jpoce, sieqs (1:jpoce), zchem_data(1:jpi,1:jpj,11), iarroce(1:jpoce) )
+         CALL pack_arr ( jpoce, aks3s (1:jpoce), zchem_data(1:jpi,1:jpj,12), iarroce(1:jpoce) )
+         CALL pack_arr ( jpoce, akf3s (1:jpoce), zchem_data(1:jpi,1:jpj,13), iarroce(1:jpoce) )
+         CALL pack_arr ( jpoce, sulfats(1:jpoce), zchem_data(1:jpi,1:jpj,14), iarroce(1:jpoce) )
+         CALL pack_arr ( jpoce, fluorids(1:jpoce), zchem_data(1:jpi,1:jpj,15), iarroce(1:jpoce) )
+      ENDIF
 
       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 )
+         zsal15  = SQRT( zsal ) * zsal
 
          ! Density of Sea Water - F(temp,sal) [kg/m3]
@@ -256,55 +194,4 @@
          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)
@@ -313,261 +200,584 @@
          calcon2(ji) = 0.01028 * ( salt(ji) / 35. ) * densSW(ji)
       ENDDO
-
        
-#endif
+      IF( ln_timing )  CALL timing_stop('sed_chem')
 
    END SUBROUTINE sed_chem
 
-#if defined key_sed_off
-
-   SUBROUTINE sed_chem_off
-      !!----------------------------------------------------------------------
-      !!                   ***  ROUTINE sed_chem_off  ***
-      !!                    
-      !! ** Purpose :   compute chemical constants
+   SUBROUTINE ahini_for_at_sed(p_hini)
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE ahini_for_at  ***
       !!
-      !!   History :
-      !!        !  04-10  (N. Emprin, M. Gehlen )  Original code
-      !!        !  06-04  (C. Ethe)  Re-organization 
-      !!----------------------------------------------------------------------  
-      !! * Local declarations
-      INTEGER :: ji
-
-      REAL(wp) ::  ztkel, ztc, ztc2, zpres, ztr 
-      REAL(wp) ::  zsal, zsal2, zsqrt, zsal15   
-      REAL(wp) ::  zis, zis2, zisqrt            
-      REAL(wp) ::  zdens0, zaw, zbw, zcw        
-      REAL(wp) ::  zchl, zst, zft, zbuf1, zbuf2 
-      REAL(wp) ::  zcpexp, zcpexp2              
-      REAL(wp) ::  zckb, zck1, zck2, zckw       
-      REAL(wp) ::  zck1p, zck2p, zck3p, zcksi   
-      REAL(wp) ::  zak1, zak2, zakb, zakw              
-      REAL(wp) ::  zaksp0, zksp, zks, zkf 
-
+      !! Subroutine returns the root for the 2nd order approximation of the
+      !! DIC -- B_T -- A_CB equation for [H+] (reformulated as a cubic 
+      !! polynomial) around the local minimum, if it exists.
+      !! Returns * 1E-03_wp if p_alkcb <= 0
+      !!         * 1E-10_wp if p_alkcb >= 2*p_dictot + p_bortot
+      !!         * 1E-07_wp if 0 < p_alkcb < 2*p_dictot + p_bortot
+      !!                    and the 2nd order approximation does not have 
+      !!                    a solution
+      !!---------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpoce,jpksed), INTENT(OUT)  ::  p_hini
+      INTEGER  ::   ji, jk
+      REAL(wp)  ::  zca1, zba1
+      REAL(wp)  ::  zd, zsqrtd, zhmin
+      REAL(wp)  ::  za2, za1, za0
+      REAL(wp)  ::  p_dictot, p_bortot, p_alkcb
+
+      IF( ln_timing )  CALL timing_start('ahini_for_at_sed')
+      !
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            p_alkcb  = pwcp(ji,jk,jwalk) / densSW(ji)
+            p_dictot = pwcp(ji,jk,jwdic) / densSW(ji) 
+            p_bortot = borats(ji) / densSW(ji)
+            IF (p_alkcb <= 0.) THEN
+                p_hini(ji,jk) = 1.e-3
+            ELSEIF (p_alkcb >= (2.*p_dictot + p_bortot)) THEN
+                p_hini(ji,jk) = 1.e-10_wp
+            ELSE
+                zca1 = p_dictot/( p_alkcb + rtrn )
+                zba1 = p_bortot/ (p_alkcb + rtrn )
+           ! Coefficients of the cubic polynomial
+                za2 = aKbs(ji)*(1. - zba1) + ak1s(ji)*(1.-zca1)
+                za1 = ak1s(ji)*akbs(ji)*(1. - zba1 - zca1)    &
+                &     + ak1s(ji)*ak2s(ji)*(1. - (zca1+zca1))
+                za0 = ak1s(ji)*ak2s(ji)*akbs(ji)*(1. - zba1 - (zca1+zca1))
+                                        ! Taylor expansion around the minimum
+                zd = za2*za2 - 3.*za1   ! Discriminant of the quadratic equation
+                                        ! for the minimum close to the root
+
+                IF(zd > 0.) THEN        ! If the discriminant is positive
+                  zsqrtd = SQRT(zd)
+                  IF(za2 < 0) THEN
+                    zhmin = (-za2 + zsqrtd)/3.
+                  ELSE
+                    zhmin = -za1/(za2 + zsqrtd)
+                  ENDIF
+                  p_hini(ji,jk) = zhmin + SQRT(-(za0 + zhmin*(za1 + zhmin*(za2 + zhmin)))/zsqrtd)
+                ELSE
+                  p_hini(ji,jk) = 1.e-7
+                ENDIF
+             !
+            ENDIF
+         END DO
+      END DO
+      !
+      IF( ln_timing )  CALL timing_stop('ahini_for_at_sed')
+      !
+   END SUBROUTINE ahini_for_at_sed
+
+   !===============================================================================
+   SUBROUTINE anw_infsup_sed( p_alknw_inf, p_alknw_sup )
+
+   ! Subroutine returns the lower and upper bounds of "non-water-selfionization"
+   ! contributions to total alkalinity (the infimum and the supremum), i.e
+   ! inf(TA - [OH-] + [H+]) and sup(TA - [OH-] + [H+])
+
+   ! Argument variables
+   INTEGER :: jk
+   REAL(wp), DIMENSION(jpoce,jpksed), INTENT(OUT) :: p_alknw_inf
+   REAL(wp), DIMENSION(jpoce,jpksed), INTENT(OUT) :: p_alknw_sup
+
+   DO jk = 1, jpksed
+      p_alknw_inf(:,jk) =  -pwcp(:,jk,jwpo4) / densSW(:)
+      p_alknw_sup(:,jk) =   (2. * pwcp(:,jk,jwdic) + 2. * pwcp(:,jk,jwpo4) + pwcp(:,jk,jwsil)     &
+   &                        + borats(:) ) / densSW(:)
+   END DO
+
+   END SUBROUTINE anw_infsup_sed
+
+
+   SUBROUTINE solve_at_general_sed( p_hini, zhi )
+
+   ! Universal pH solver that converges from any given initial value,
+   ! determines upper an lower bounds for the solution if required
+
+   ! Argument variables
+   !--------------------
+   REAL(wp), DIMENSION(jpoce,jpksed), INTENT(IN)   :: p_hini
+   REAL(wp), DIMENSION(jpoce,jpksed), INTENT(OUT)  :: zhi
+
+   ! Local variables
+   !-----------------
+   INTEGER   ::  ji, jk, jn
+   REAL(wp)  ::  zh_ini, zh, zh_prev, zh_lnfactor
+   REAL(wp)  ::  zdelta, zh_delta
+   REAL(wp)  ::  zeqn, zdeqndh, zalka
+   REAL(wp)  ::  aphscale
+   REAL(wp)  ::  znumer_dic, zdnumer_dic, zdenom_dic, zalk_dic, zdalk_dic
+   REAL(wp)  ::  znumer_bor, zdnumer_bor, zdenom_bor, zalk_bor, zdalk_bor
+   REAL(wp)  ::  znumer_po4, zdnumer_po4, zdenom_po4, zalk_po4, zdalk_po4
+   REAL(wp)  ::  znumer_sil, zdnumer_sil, zdenom_sil, zalk_sil, zdalk_sil
+   REAL(wp)  ::  znumer_so4, zdnumer_so4, zdenom_so4, zalk_so4, zdalk_so4
+   REAL(wp)  ::  znumer_flu, zdnumer_flu, zdenom_flu, zalk_flu, zdalk_flu
+   REAL(wp)  ::  zalk_wat, zdalk_wat
+   REAL(wp)  ::  zfact, p_alktot, zdic, zbot, zpt, zst, zft, zsit
+   LOGICAL   ::  l_exitnow
+   REAL(wp), PARAMETER :: pz_exp_threshold = 1.0
+   REAL(wp), DIMENSION(jpoce,jpksed) :: zalknw_inf, zalknw_sup, rmask, zh_min, zh_max, zeqn_absmin
+
+   IF( ln_timing )  CALL timing_start('solve_at_general_sed')
+      !  Allocate temporary workspace
+   CALL anw_infsup_sed( zalknw_inf, zalknw_sup )
+
+   rmask(:,:) = 1.0
+   zhi(:,:)   = 0.
+
+   ! TOTAL H+ scale: conversion factor for Htot = aphscale * Hfree
+   DO jk = 1, jpksed
+      DO ji = 1, jpoce
+         IF (rmask(ji,jk) == 1.) THEN
+            p_alktot = pwcp(ji,jk,jwalk) / densSW(ji)
+            aphscale = 1. + sulfats(ji)/aks3s(ji)
+            zh_ini = p_hini(ji,jk)
+
+            zdelta = (p_alktot-zalknw_inf(ji,jk))**2 + 4.*akws(ji) / aphscale
+
+            IF(p_alktot >= zalknw_inf(ji,jk)) THEN
+               zh_min(ji,jk) = 2.*akws(ji) /( p_alktot-zalknw_inf(ji,jk) + SQRT(zdelta) )
+            ELSE
+               zh_min(ji,jk) = aphscale * (-(p_alktot-zalknw_inf(ji,jk)) + SQRT(zdelta) ) / 2.
+            ENDIF
+
+            zdelta = (p_alktot-zalknw_sup(ji,jk))**2 + 4.*akws(ji) / aphscale
+
+            IF(p_alktot <= zalknw_sup(ji,jk)) THEN
+               zh_max(ji,jk) = aphscale * (-(p_alktot-zalknw_sup(ji,jk)) + SQRT(zdelta) ) / 2.
+            ELSE
+               zh_max(ji,jk) = 2.*akws(ji) /( p_alktot-zalknw_sup(ji,jk) + SQRT(zdelta) )
+            ENDIF
+
+            zhi(ji,jk) = MAX(MIN(zh_max(ji,jk), zh_ini), zh_min(ji,jk))
+         ENDIF
+      END DO
+   END DO
+
+   zeqn_absmin(:,:) = HUGE(1._wp)
+
+   DO jn = 1, jp_maxniter_atgen
+   DO jk = 1, jpksed
+      DO ji = 1, jpoce
+         IF (rmask(ji,jk) == 1.) THEN
+
+            p_alktot = pwcp(ji,jk,jwalk) / densSW(ji)
+            zdic  = pwcp(ji,jk,jwdic) / densSW(ji)
+            zbot  = borats(ji) / densSW(ji)
+            zpt =  pwcp(ji,jk,jwpo4) / densSW(ji)
+            zsit = pwcp(ji,jk,jwsil) / densSW(ji)
+            zst = sulfats(ji)
+            zft = fluorids(ji)
+            aphscale = 1. + sulfats(ji)/aks3s(ji)
+            zh = zhi(ji,jk)
+            zh_prev = zh
+
+            ! H2CO3 - HCO3 - CO3 : n=2, m=0
+            znumer_dic = 2.*ak1s(ji)*ak2s(ji) + zh*ak1s(ji)
+            zdenom_dic = ak1s(ji)*ak2s(ji) + zh*(ak1s(ji) + zh)
+            zalk_dic   = zdic * (znumer_dic/zdenom_dic)
+            zdnumer_dic = ak1s(ji)*ak1s(ji)*ak2s(ji) + zh     &
+                          *(4.*ak1s(ji)*ak2s(ji) + zh*ak1s(ji))
+            zdalk_dic   = -zdic*(zdnumer_dic/zdenom_dic**2)
+
+
+            ! B(OH)3 - B(OH)4 : n=1, m=0
+            znumer_bor = akbs(ji)
+            zdenom_bor = akbs(ji) + zh
+            zalk_bor   = zbot * (znumer_bor/zdenom_bor)
+            zdnumer_bor = akbs(ji)
+            zdalk_bor   = -zbot*(zdnumer_bor/zdenom_bor**2)
+
+
+            ! H3PO4 - H2PO4 - HPO4 - PO4 : n=3, m=1
+            znumer_po4 = 3.*ak1ps(ji)*ak2ps(ji)*ak3ps(ji)  &
+            &            + zh*(2.*ak1ps(ji)*ak2ps(ji) + zh* ak1ps(ji))
+            zdenom_po4 = ak1ps(ji)*ak2ps(ji)*ak3ps(ji)     &
+            &            + zh*( ak1ps(ji)*ak2ps(ji) + zh*(ak1ps(ji) + zh))
+            zalk_po4   = zpt * (znumer_po4/zdenom_po4 - 1.) ! Zero level of H3PO4 = 1
+            zdnumer_po4 = ak1ps(ji)*ak2ps(ji)*ak1ps(ji)*ak2ps(ji)*ak3ps(ji)  &
+            &             + zh*(4.*ak1ps(ji)*ak1ps(ji)*ak2ps(ji)*ak3ps(ji)         &
+            &             + zh*(9.*ak1ps(ji)*ak2ps(ji)*ak3ps(ji)                         &
+            &             + ak1ps(ji)*ak1ps(ji)*ak2ps(ji)                                &
+            &             + zh*(4.*ak1ps(ji)*ak2ps(ji) + zh * ak1ps(ji) ) ) )
+            zdalk_po4   = -zpt * (zdnumer_po4/zdenom_po4**2)
+
+            ! H4SiO4 - H3SiO4 : n=1, m=0
+            znumer_sil = aksis(ji)
+            zdenom_sil = aksis(ji) + zh
+            zalk_sil   = zsit * (znumer_sil/zdenom_sil)
+            zdnumer_sil = aksis(ji)
+            zdalk_sil   = -zsit * (zdnumer_sil/zdenom_sil**2)
+
+            ! HSO4 - SO4 : n=1, m=1
+            aphscale = 1.0 + zst/aks3s(ji)
+            znumer_so4 = aks3s(ji) * aphscale
+            zdenom_so4 = aks3s(ji) * aphscale + zh
+            zalk_so4   = zst * (znumer_so4/zdenom_so4 - 1.)
+            zdnumer_so4 = aks3s(ji) * aphscale
+            zdalk_so4   = -zst * (zdnumer_so4/zdenom_so4**2)
+
+            ! HF - F : n=1, m=1
+            znumer_flu =  akf3s(ji)
+            zdenom_flu =  akf3s(ji) + zh
+            zalk_flu   =  zft * (znumer_flu/zdenom_flu - 1.)
+            zdnumer_flu = akf3s(ji)
+            zdalk_flu   = -zft * (zdnumer_flu/zdenom_flu**2)
+
+            ! H2O - OH
+            zalk_wat   = akws(ji)/zh - zh/aphscale
+            zdalk_wat  = -akws(ji)/zh**2 - 1./aphscale
+
+            ! CALCULATE [ALK]([CO3--], [HCO3-])
+            zeqn = zalk_dic + zalk_bor + zalk_po4 + zalk_sil   &
+            &      + zalk_so4 + zalk_flu                       &
+            &      + zalk_wat - p_alktot
+
+            zalka = p_alktot - (zalk_bor + zalk_po4 + zalk_sil   &
+            &       + zalk_so4 + zalk_flu + zalk_wat)
+
+            zdeqndh = zdalk_dic + zdalk_bor + zdalk_po4 + zdalk_sil &
+            &         + zdalk_so4 + zdalk_flu + zdalk_wat
+
+            ! Adapt bracketing interval
+            IF(zeqn > 0._wp) THEN
+               zh_min(ji,jk) = zh_prev
+            ELSEIF(zeqn < 0._wp) THEN
+               zh_max(ji,jk) = zh_prev
+            ENDIF
+
+            IF(ABS(zeqn) >= 0.5_wp*zeqn_absmin(ji,jk)) THEN
+            ! if the function evaluation at the current point is
+            ! not decreasing faster than with a bisection step (at least linearly)
+            ! in absolute value take one bisection step on [ph_min, ph_max]
+            ! ph_new = (ph_min + ph_max)/2d0
+            !
+            ! In terms of [H]_new:
+            ! [H]_new = 10**(-ph_new)
+            !         = 10**(-(ph_min + ph_max)/2d0)
+            !         = SQRT(10**(-(ph_min + phmax)))
+            !         = SQRT(zh_max * zh_min)
+               zh = SQRT(zh_max(ji,jk) * zh_min(ji,jk))
+               zh_lnfactor = (zh - zh_prev)/zh_prev ! Required to test convergence below
+            ELSE
+            ! dzeqn/dpH = dzeqn/d[H] * d[H]/dpH
+            !           = -zdeqndh * LOG(10) * [H]
+            ! \Delta pH = -zeqn/(zdeqndh*d[H]/dpH) = zeqn/(zdeqndh*[H]*LOG(10))
+            !
+            ! pH_new = pH_old + \deltapH
+            !
+            ! [H]_new = 10**(-pH_new)
+            !         = 10**(-pH_old - \Delta pH)
+            !         = [H]_old * 10**(-zeqn/(zdeqndh*[H]_old*LOG(10)))
+            !         = [H]_old * EXP(-LOG(10)*zeqn/(zdeqndh*[H]_old*LOG(10)))
+            !         = [H]_old * EXP(-zeqn/(zdeqndh*[H]_old))
+
+               zh_lnfactor = -zeqn/(zdeqndh*zh_prev)
+
+               IF(ABS(zh_lnfactor) > pz_exp_threshold) THEN
+                  zh          = zh_prev*EXP(zh_lnfactor)
+               ELSE
+                  zh_delta    = zh_lnfactor*zh_prev
+                  zh          = zh_prev + zh_delta
+               ENDIF
+
+               IF( zh < zh_min(ji,jk) ) THEN
+               ! if [H]_new < [H]_min
+               ! i.e., if ph_new > ph_max then
+               ! take one bisection step on [ph_prev, ph_max]
+               ! ph_new = (ph_prev + ph_max)/2d0
+               ! In terms of [H]_new:
+               ! [H]_new = 10**(-ph_new)
+               !         = 10**(-(ph_prev + ph_max)/2d0)
+               !         = SQRT(10**(-(ph_prev + phmax)))
+               !         = SQRT([H]_old*10**(-ph_max))
+               !         = SQRT([H]_old * zh_min)
+                  zh                = SQRT(zh_prev * zh_min(ji,jk))
+                  zh_lnfactor       = (zh - zh_prev)/zh_prev ! Required to test convergence below
+               ENDIF
+
+               IF( zh > zh_max(ji,jk) ) THEN
+               ! if [H]_new > [H]_max
+               ! i.e., if ph_new < ph_min, then
+               ! take one bisection step on [ph_min, ph_prev]
+               ! ph_new = (ph_prev + ph_min)/2d0
+               ! In terms of [H]_new:
+               ! [H]_new = 10**(-ph_new)
+               !         = 10**(-(ph_prev + ph_min)/2d0)
+               !         = SQRT(10**(-(ph_prev + ph_min)))
+               !         = SQRT([H]_old*10**(-ph_min))
+               !         = SQRT([H]_old * zhmax)
+                  zh                = SQRT(zh_prev * zh_max(ji,jk))
+                  zh_lnfactor       = (zh - zh_prev)/zh_prev ! Required to test convergence below
+               ENDIF
+            ENDIF
+
+            zeqn_absmin(ji,jk) = MIN( ABS(zeqn), zeqn_absmin(ji,jk))
+
+            ! Stop iterations once |\delta{[H]}/[H]| < rdel
+            ! <=> |(zh - zh_prev)/zh_prev| = |EXP(-zeqn/(zdeqndh*zh_prev)) -1| < rdel
+            ! |EXP(-zeqn/(zdeqndh*zh_prev)) -1| ~ |zeqn/(zdeqndh*zh_prev)|
+            ! Alternatively:
+            ! |\Delta pH| = |zeqn/(zdeqndh*zh_prev*LOG(10))|
+            !             ~ 1/LOG(10) * |\Delta [H]|/[H]
+            !             < 1/LOG(10) * rdel
+
+            ! Hence |zeqn/(zdeqndh*zh)| < rdel
+
+            ! rdel <-- pp_rdel_ah_target
+            l_exitnow = (ABS(zh_lnfactor) < pp_rdel_ah_target)
+
+            IF(l_exitnow) THEN
+               rmask(ji,jk) = 0.
+            ENDIF
+
+            zhi(ji,jk) =  zh
+
+            IF(jn >= jp_maxniter_atgen) THEN
+               zhi(ji,jk) = -1._wp
+            ENDIF
+
+         ENDIF
+      END DO
+   END DO
+   END DO
+   !
+   IF( ln_timing )  CALL timing_stop('solve_at_general_sed')
+
+   END SUBROUTINE solve_at_general_sed
+
+   SUBROUTINE sed_chem_cst
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE sed_chem_cst  ***
+      !!
+      !! ** Purpose :   Sea water chemistry computed following MOCSY protocol
+      !!                Computation is done at the bottom of the ocean only
+      !!
+      !! ** Method  : - ...
+      !!---------------------------------------------------------------------
+      INTEGER  ::   ji
+      REAL(wp), DIMENSION(jpoce) :: saltprac, temps
+      REAL(wp) ::   ztkel, ztkel1, zt , zsal  , zsal2 , zbuf1 , zbuf2
+      REAL(wp) ::   ztgg , ztgg2, ztgg3 , ztgg4 , ztgg5
+      REAL(wp) ::   zpres, ztc  , zcl   , zcpexp, zoxy  , zcpexp2
+      REAL(wp) ::   zsqrt, ztr  , zlogt , zcek1, zc1, zplat
+      REAL(wp) ::   zis  , zis2 , zsal15, zisqrt, za1, za2
+      REAL(wp) ::   zckb , zck1 , zck2  , zckw  , zak1 , zak2  , zakb , zaksp0, zakw
+      REAL(wp) ::   zck1p, zck2p, zck3p, zcksi, zak1p, zak2p, zak3p, zaksi
+      REAL(wp) ::   zst  , zft  , zcks  , zckf  , zaksp1
+      REAL(wp) ::   total2free, free2SWS, total2SWS, SWS2total
+      !!---------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('sed_chem_cst')
+      !
+      ! Computation of chemical constants require practical salinity
+      ! Thus, when TEOS08 is used, absolute salinity is converted to
+      ! practical salinity
+      ! -------------------------------------------------------------
+      IF (neos == -1) THEN
+         saltprac(:) = salt(:) * 35.0 / 35.16504
+      ELSE
+         saltprac(:) = temp(:)
+      ENDIF
+
+      !
+      ! Computations of chemical constants require in situ temperature
+      ! Here a quite simple formulation is used to convert
+      ! potential temperature to in situ temperature. The errors is less than
+      ! 0.04°C relative to an exact computation
+      ! ---------------------------------------------------------------------
+         DO ji = 1, jpoce
+            zpres = zkbot(ji) / 1000.
+            za1 = 0.04 * ( 1.0 + 0.185 * temp(ji) + 0.035 * (saltprac(ji) - 35.0) )
+            za2 = 0.0075 * ( 1.0 - temp(ji) / 30.0 )
+            temps(ji) = temp(ji) - za1 * zpres + za2 * zpres**2
+         END DO
 
       ! 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 )
+         ! SET PRESSION ACCORDING TO SAUNDER (1980)
+         zc1 = 5.92E-3 
+         zpres = ((1-zc1)-SQRT(((1-zc1)**2)-(8.84E-6*zkbot(ji)))) / 4.42E-6
+         zpres = zpres / 10.0
+
+         ! SET ABSOLUTE TEMPERATURE
+         ztkel   = temps(ji) + 273.15
+         zsal    = saltprac(ji)
+         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 )
+         zlogt  = LOG( ztkel )
+         ztr    = 1. / ztkel
+         zis    = 19.924 * zsal / ( 1000.- 1.005 * zsal )
+         zis2   = zis * zis
+         zisqrt = SQRT( zis )
+         ztc    = temps(ji)
+
+         ! CHLORINITY (WOOSTER ET AL., 1969)
+         zcl     = zsal / 1.80655
+
+         ! TOTAL SULFATE CONCENTR. [MOLES/kg soln]
+         zst     = 0.14 * zcl /96.062
+
+         ! TOTAL FLUORIDE CONCENTR. [MOLES/kg soln]
+         zft     = 0.000067 * zcl /18.9984
+
+         ! DISSOCIATION CONSTANT FOR SULFATES on free H scale (Dickson 1990)
+         zcks    = EXP(-4276.1 * ztr + 141.328 - 23.093 * zlogt         &
+         &         + (-13856. * ztr + 324.57 - 47.986 * zlogt) * zisqrt &
+         &         + (35474. * ztr - 771.54 + 114.723 * zlogt) * zis    &
+         &         - 2698. * ztr * zis**1.5 + 1776.* ztr * zis2         &
+         &         + LOG(1.0 - 0.001005 * zsal))
+
+         ! DISSOCIATION CONSTANT FOR FLUORIDES on free H scale (Dickson and Riley 79)
+         zckf    = EXP( 1590.2*ztr - 12.641 + 1.525*zisqrt   &
+         &         + LOG(1.0d0 - 0.001005d0*zsal)            &
+         &         + LOG(1.0d0 + zst/zcks))
+
+         ! DISSOCIATION CONSTANT FOR CARBONATE AND BORATE
+         zckb=  (-8966.90 - 2890.53*zsqrt - 77.942*zsal        &
+         &      + 1.728*zsal15 - 0.0996*zsal*zsal)*ztr         &
+         &      + (148.0248 + 137.1942*zsqrt + 1.62142*zsal)   &
+         &      + (-24.4344 - 25.085*zsqrt - 0.2474*zsal)      &
+         &      * zlogt + 0.053105*zsqrt*ztkel
+
+         ! DISSOCIATION COEFFICIENT FOR CARBONATE ACCORDING TO
+         ! MEHRBACH (1973) REFIT BY MILLERO (1995), seawater scale
+         zck1    = -1.0*(3633.86*ztr - 61.2172 + 9.6777*zlogt  &
+                   - 0.011555*zsal + 0.0001152*zsal*zsal)
+         zck2    = -1.0*(471.78*ztr + 25.9290 - 3.16967*zlogt      &
+                   - 0.01781*zsal + 0.0001122*zsal*zsal)
+
+         ! PKW (H2O) (MILLERO, 1995) from composite data
+         zckw    = -13847.26 * ztr + 148.9652 - 23.6521 * zlogt + ( 118.67 * ztr    &
+                   - 5.977 + 1.0495 * zlogt ) * zsqrt - 0.01615 * zsal
+
+         ! CONSTANTS FOR PHOSPHATE (MILLERO, 1995)
+         zck1p    = -4576.752*ztr + 115.540 - 18.453*zlogt   &
+         &          + (-106.736*ztr + 0.69171) * zsqrt       &
+         &          + (-0.65643*ztr - 0.01844) * zsal
+
+         zck2p    = -8814.715*ztr + 172.1033 - 27.927*zlogt  &
+         &          + (-160.340*ztr + 1.3566)*zsqrt          &
+         &          + (0.37335*ztr - 0.05778)*zsal
+
+         zck3p    = -3070.75*ztr - 18.126                    &
+         &          + (17.27039*ztr + 2.81197) * zsqrt       &
+         &          + (-44.99486*ztr - 0.09984) * zsal
+
+         ! CONSTANT FOR SILICATE, MILLERO (1995)
+         zcksi    = -8904.2*ztr  + 117.400 - 19.334*zlogt   &
+         &          + (-458.79*ztr + 3.5913) * zisqrt       &
+         &          + (188.74*ztr - 1.5998) * zis           &
+         &          + (-12.1652*ztr + 0.07871) * zis2       &
+         &          + LOG(1.0 - 0.001005*zsal)
+
+         ! APPARENT SOLUBILITY PRODUCT K'SP OF CALCITE IN SEAWATER
+         !       (S=27-43, T=2-25 DEG C) at pres =0 (atmos. pressure) (MUCCI 1983)
+         zaksp0  = -171.9065 -0.077993*ztkel + 2839.319*ztr + 71.595*LOG10( ztkel )   &
+         &         + (-0.77712 + 0.00284263*ztkel + 178.34*ztr) * zsqrt  &
+         &         - 0.07711*zsal + 0.0041249*zsal15
+
+         ! K1, K2 OF CARBONIC ACID, KB OF BORIC ACID, KW (H2O) (LIT.?)
+         zak1    = 10**(zck1) * total2SWS
+         zak2    = 10**(zck2) * total2SWS
+         zakb    = EXP( zckb ) * total2SWS
+         zakw    = EXP( zckw )
+         zaksp1  = 10**(zaksp0)
+         zak1p   = exp( zck1p )
+         zak2p   = exp( zck2p )
+         zak3p   = exp( zck3p )
+         zaksi   = exp( zcksi )
+         zckf    = zckf * total2SWS
+
+         ! FORMULA FOR CPEXP AFTER EDMOND & GIESKES (1970)
+         !        (REFERENCE TO CULBERSON & 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
+         !        & GIESKES (1970), P. 1285-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 
-   !!======================================================================
-   !! $Id$
-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
+         ! KB OF BORIC ACID, K1,K2 OF CARBONIC ACID PRESSURE
+         !        CORRECTION AFTER CULBERSON AND PYTKOWICZ (1968)
+         !        (CF. BROECKER ET AL., 1982)
+
+         zbuf1  = -     ( devk10 + devk20 * ztc + devk30 * ztc * ztc )
+         zbuf2  = 0.5 * ( devk40 + devk50 * ztc )
+         ak1s(ji) = zak1 * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+         zbuf1  =     - ( devk11 + devk21 * ztc + devk31 * ztc * ztc )
+         zbuf2  = 0.5 * ( devk41 + devk51 * ztc )
+         ak2s(ji) = zak2 * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+         zbuf1  =     - ( devk12 + devk22 * ztc + devk32 * ztc * ztc )
+         zbuf2  = 0.5 * ( devk42 + devk52 * ztc )
+         akbs(ji) = zakb * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+         zbuf1  =     - ( devk13 + devk23 * ztc + devk33 * ztc * ztc )
+         zbuf2  = 0.5 * ( devk43 + devk53 * ztc )
+         akws(ji) = zakw * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+         zbuf1  =     - ( devk14 + devk24 * ztc + devk34 * ztc * ztc )
+         zbuf2  = 0.5 * ( devk44 + devk54 * ztc )
+         aks3s(ji) = zcks * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+         zbuf1  =     - ( devk15 + devk25 * ztc + devk35 * ztc * ztc )
+         zbuf2  = 0.5 * ( devk45 + devk55 * ztc )
+         akf3s(ji) = zckf * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+         zbuf1  =     - ( devk17 + devk27 * ztc + devk37 * ztc * ztc )
+         zbuf2  = 0.5 * ( devk47 + devk57 * ztc )
+         ak1ps(ji) = zak1p * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+         zbuf1  =     - ( devk18 + devk28 * ztc + devk38 * ztc * ztc )
+         zbuf2  = 0.5 * ( devk48 + devk58 * ztc )
+         ak2ps(ji) = zak2p * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+         zbuf1  =     - ( devk110 + devk210 * ztc + devk310 * ztc * ztc )
+         zbuf2  = 0.5 * ( devk410 + devk510 * ztc )
+         aksis(ji) = zaksi * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+         ! CONVERT FROM DIFFERENT PH SCALES
+         total2free  = 1.0/(1.0 + zst/aks3s(ji))
+         free2SWS    = 1. + zst/aks3s(ji) + zft/akf3s(ji)
+         total2SWS   = total2free * free2SWS
+         SWS2total   = 1.0 / total2SWS
+
+         ! Convert to total scale
+         ak1s(ji)  = ak1s(ji)  * SWS2total
+         ak2s(ji)  = ak2s(ji)  * SWS2total
+         akbs(ji)  = akbs(ji)  * SWS2total
+         akws(ji)  = akws(ji)  * SWS2total
+         ak1ps(ji) = ak1ps(ji) * SWS2total
+         ak2ps(ji) = ak2ps(ji) * SWS2total
+         ak3ps(ji) = ak3ps(ji) * SWS2total
+         aksis(ji) = aksis(ji) * SWS2total
+         akf3s(ji) = akf3s(ji) / total2free
+
+         ! APPARENT SOLUBILITY PRODUCT K'SP OF CALCITE
+         !        AS FUNCTION OF PRESSURE FOLLOWING MILLERO
+         !        (P. 1285) AND BERNER (1976)
+         zbuf1  =     - ( devk16 + devk26 * ztc + devk36 * ztc * ztc )
+         zbuf2  = 0.5 * ( devk46 + devk56 * ztc )
+         aksps(ji) = zaksp1 * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+         ! TOTAL F, S, and BORATE CONCENTR. [MOLES/L]
+         borats(ji)   = 0.0002414 * zcl / 10.811
+         sulfats(ji)  = zst
+         fluorids(ji) = zft
+
+         ! Iron and SIO3 saturation concentration from ...
+         sieqs(ji) = EXP(  LOG( 10.) * ( 6.44 - 968. / ztkel )  ) * 1.e-6
+      END DO
+      !
+      IF( ln_timing )  CALL timing_stop('sed_chem_cst')
+      !
+   END SUBROUTINE sed_chem_cst
+
 
 END MODULE sedchem
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedco3.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedco3.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedco3.F90	(revision 10345)
@@ -1,4 +1,3 @@
 MODULE sedco3
-#if defined key_sed
    !!======================================================================
    !!              ***  MODULE  sedco3  ***
@@ -7,4 +6,6 @@
    !! * Modules used
    USE sed     ! sediment global variable
+   USE sedchem
+   USE lib_mpp         ! distribued memory computing library
 
 
@@ -15,10 +16,6 @@
    PUBLIC sed_co3     
 
-
-   !! * Module variables
-   REAL(wp) :: epsmax   =  1.e-12      ! convergence limite value
-
    !!----------------------------------------------------------------------
-   !!   OPA 9.0   !   NEMO Consortium   (2003)
+   !!   OPA 9.0   !   LODYC-IPSL   (2003)
    !!----------------------------------------------------------------------
 
@@ -45,155 +42,39 @@
       !! * Arguments
       INTEGER, INTENT(in)  :: kt   ! time step
-
       !
       !---Local variables
-      INTEGER  :: jiter, ji, jk, ipt  ! dummy loop indices
+      INTEGER  :: ji, jk           ! dummy loop indices
 
-      INTEGER  :: itermax             ! maximum number of Newton-Raphson iterations
-      INTEGER  :: itime               ! number of time to perform Newton-Raphson algorithm
-      LOGICAL  :: lconv = .FALSE.     ! flag for convergence
-      REAL(wp) :: brems               !  relaxation. parameter
-      REAL(wp) :: zresm, zresm1, zhipor_min 
-      REAL(wp) :: zalk, zbor, zsil, zpo4, zdic
-      REAL(wp) :: zh_old, zh_old2, zh_old3, zh_old4
-      REAL(wp) :: zuu, zvv, zduu, zdvv 
-      REAL(wp) :: zup, zvp, zdup, zdvp
-      REAL(wp) :: zah_old, zah_olds
-      REAL(wp) :: zh_new, zh_new2, zco3
-
+      REAL(wp), DIMENSION(jpoce,jpksed) :: zhinit, zhi
      !!----------------------------------------------------------------------
 
+      IF( ln_timing )  CALL timing_start('sed_co3')
+
       IF( kt == nitsed000 ) THEN
-         WRITE(numsed,*) ' sed_co3 : carbonate ion and proton concentration calculation  '
-         WRITE(numsed,*) ' '
+         IF (lwp) WRITE(numsed,*) ' sed_co3 : carbonate ion and proton concentration calculation  '
+         IF (lwp) WRITE(numsed,*) ' '
       ENDIF
 
-      itermax     = 30
-      brems       = 1.
-      itime       = 0
+      DO jk = 1, jpksed
+         zhinit(:,jk)   = hipor(:,jk) / densSW(:)
+      END DO
 
+      !     -------------------------------------------
+      !     COMPUTE [CO3--] and [H+] CONCENTRATIONS
+      !     -------------------------------------------
+
+      CALL solve_at_general_sed(zhinit, zhi)
 
       DO jk = 1, jpksed
-         DO WHILE( itime <= 2 )
-            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
+         DO ji = 1, jpoce
+            co3por(ji,jk) = pwcp(ji,jk,jwdic) * ak1s(ji) * ak2s(ji) / (zhi(ji,jk)**2   &
+            &               + ak1s(ji) * zhi(ji,jk) + ak1s(ji) * ak2s(ji) + rtrn )
+            hipor(ji,jk)  = zhi(ji,jk) * densSW(ji)
+         END DO
+      END DO
 
-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
-                  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 = 3
-               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'
-               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
-         ENDDO ! End of WHILE LOOP
-     ENDDO
+     IF( ln_timing )  CALL timing_stop('sed_co3')
 
    END SUBROUTINE sed_co3
-#else
-   !!======================================================================
-   !! MODULE sedco3  :   Dummy module 
-   !!======================================================================
-   !! $Id$
-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: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/seddiff.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/seddiff.F90	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/seddiff.F90	(revision 10345)
@@ -0,0 +1,120 @@
+MODULE seddiff
+   !!======================================================================
+   !!              ***  MODULE  seddsr  ***
+   !!    Sediment : dissolution and reaction in pore water related 
+   !!    related to organic matter
+   !!=====================================================================
+   !! * Modules used
+   USE sed     ! sediment global variable
+   USE sed_oce
+   USE sedmat  ! linear system of equations
+   USE sedini
+   USE lib_mpp         ! distribued memory computing library
+   USE lib_fortran
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC sed_diff
+
+   !! * Module variables
+
+   !! $Id: seddsr.F90 5215 2015-04-15 16:11:56Z nicolasmartin $
+CONTAINS
+   
+   SUBROUTINE sed_diff( kt, knt ) 
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_diff  ***
+      !! 
+      !!  ** Purpose :  computes pore water diffusion
+      !!
+      !!  ** Methode :  implicit computation of undersaturation
+      !!               resulting from diffusive pore water transport.
+      !!
+      !!  ** Remarks :
+      !!              - undersaturation : deviation from saturation concentration
+      !!   History :
+      !!        !  98-08 (E. Maier-Reimer, Christoph Heinze )  Original code
+      !!        !  04-10 (N. Emprin, M. Gehlen ) f90
+      !!        !  06-04 (C. Ethe)  Re-organization
+      !!        !  19-08 (O. Aumont) Debugging and improvement of the model
+      !!----------------------------------------------------------------------
+      !! Arguments
+      INTEGER, INTENT(in) ::   kt, knt       ! number of iteration
+      ! --- local variables
+      INTEGER :: ji, jk, js   ! dummy looop indices
+
+      REAL(wp), DIMENSION(jpoce,jpksed) :: zrearat1, zrearat2   ! reaction rate in pore water
+      !!
+      !!----------------------------------------------------------------------
+
+      IF( ln_timing )  CALL timing_start('sed_diff')
+!
+      IF( kt == nitsed000 .AND. knt == 1 ) THEN
+         IF (lwp) THEN
+            WRITE(numsed,*) ' sed_diff : pore-water diffusion '
+            WRITE(numsed,*) ' '
+         ENDIF
+      ENDIF
+
+     ! Initializations
+     !----------------------
+      zrearat1(:,:)   = 0.
+      zrearat2(:,:) = 0.
+
+      !---------------------------
+      ! Solves PO4 diffusion 
+      !----------------------------
+
+      ! solves tridiagonal system
+      CALL sed_mat( jwpo4, jpoce, jpksed, zrearat1, zrearat2, pwcp(:,:,jwpo4), dtsed2 / 2.0 )
+
+      !---------------------------
+      ! Solves NH4 diffusion 
+      !----------------------------
+
+      ! solves tridiagonal system
+      CALL sed_mat( jwnh4, jpoce, jpksed, zrearat1, zrearat2, pwcp(:,:,jwnh4), dtsed2 / 2.0 )
+
+      !---------------------------
+      ! Solves Fe2+ diffusion 
+      !----------------------------
+
+      ! solves tridiagonal system
+      CALL sed_mat( jwfe2, jpoce, jpksed, zrearat1, zrearat2, pwcp(:,:,jwfe2), dtsed2 / 2.0 )
+
+      !---------------------------
+      ! Solves H2S diffusion 
+      !----------------------------
+
+      ! solves tridiagonal system
+      CALL sed_mat( jwh2s, jpoce, jpksed, zrearat1, zrearat2, pwcp(:,:,jwh2s), dtsed2 / 2.0  )
+
+      !---------------------------
+      ! Solves SO4 diffusion 
+      !----------------------------
+
+      ! solves tridiagonal system
+      CALL sed_mat( jwso4, jpoce, jpksed, zrearat1, zrearat2, pwcp(:,:,jwso4), dtsed2 / 2.0 )
+
+      !---------------------------
+      ! Solves O2 diffusion
+      !----------------------------
+
+      ! solves tridiagonal system
+      CALL sed_mat( jwoxy, jpoce, jpksed, zrearat1, zrearat2, pwcp(:,:,jwoxy), dtsed2 / 2.0 )
+
+      !---------------------------
+      ! Solves NO3 diffusion
+      !----------------------------
+
+      ! solves tridiagonal system
+      CALL sed_mat( jwno3, jpoce, jpksed, zrearat1, zrearat2, pwcp(:,:,jwno3), dtsed2 / 2.0 )
+
+      CALL sed_mat( jwdic, jpoce, jpksed, zrearat1, zrearat2, sedligand(:,:), dtsed2 / 2.0 )
+
+      IF( ln_timing )  CALL timing_stop('sed_diff')
+!      
+   END SUBROUTINE sed_diff
+
+END MODULE seddiff
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/seddsr.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/seddsr.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/seddsr.F90	(revision 10345)
@@ -1,12 +1,17 @@
 MODULE seddsr
-#if defined key_sed
    !!======================================================================
    !!              ***  MODULE  seddsr  ***
-   !!    Sediment : dissolution and reaction in pore water
+   !!    Sediment : dissolution and reaction in pore water related 
+   !!    related to organic matter
    !!=====================================================================
    !! * Modules used
    USE sed     ! sediment global variable
-   USE sedmat  ! linear system of equations
-   USE sedco3  ! carbonate ion and proton concentration 
+   USE sed_oce
+   USE sedini
+   USE lib_mpp         ! distribued memory computing library
+   USE lib_fortran
+
+   IMPLICIT NONE
+   PRIVATE
 
    PUBLIC sed_dsr
@@ -14,14 +19,13 @@
    !! * Module variables
 
-   REAL(wp), DIMENSION(:), ALLOCATABLE, PUBLIC :: cons_o2
-   REAL(wp), DIMENSION(:), ALLOCATABLE, PUBLIC :: cons_no3
-   REAL(wp), DIMENSION(:), ALLOCATABLE, PUBLIC :: sour_no3
-   REAL(wp), DIMENSION(:), ALLOCATABLE, PUBLIC :: sour_c13
-   REAL(wp), DIMENSION(:), ALLOCATABLE, PUBLIC ::  dens_mol_wgt  ! molecular density 
+   REAL(wp) :: zadsnh4
+   REAL(wp), DIMENSION(jpsol), PUBLIC      :: dens_mol_wgt  ! molecular density 
+   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zvolc    ! temp. variables
+
 
    !! $Id$
 CONTAINS
    
-   SUBROUTINE sed_dsr( kt ) 
+   SUBROUTINE sed_dsr( kt, knt ) 
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE sed_dsr  ***
@@ -29,13 +33,9 @@
       !!  ** 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 
+      !!  ** Methode :  Computation of the redox reactions in sediment.
+      !!                The main redox reactions are solved in sed_dsr whereas
+      !!                the secondary reactions are solved in sed_dsr_redoxb.
+      !!                A strand spliting approach is being used here (see 
+      !!                sed_dsr_redoxb for more information). 
       !!
       !!   History :
@@ -43,76 +43,55 @@
       !!        !  04-10 (N. Emprin, M. Gehlen ) f90
       !!        !  06-04 (C. Ethe)  Re-organization
+      !!        !  19-08 (O. Aumont) Debugging and improvement of the model.
+      !!                             The original method is replaced by a 
+      !!                              Strand splitting method which deals 
+      !!                              well with stiff reactions.
       !!----------------------------------------------------------------------
       !! Arguments
-      INTEGER, INTENT(in) ::   kt       ! number of iteration
+      INTEGER, INTENT(in) ::   kt, knt       ! number of iteration
       ! --- local variables
-      INTEGER :: ji, jk, js, jw   ! dummy looop indices
-      INTEGER :: nv               ! number of variables in linear tridiagonal eq
-
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zrearat    ! reaction rate in pore water
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zundsat    ! undersaturation ; indice jpwatp1 is for calcite   
-      REAL(wp), DIMENSION(:    ), ALLOCATABLE :: zmo2_0, zmo2_1  ! temp. array for mass balance calculation
-      REAL(wp), DIMENSION(:    ), ALLOCATABLE :: zmno3_0, zmno3_1, zmno3_2
-      REAL(wp), DIMENSION(:    ), ALLOCATABLE :: zmc13_0, zmc13_1, zmc13_2, zmc13_3
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zvolc    ! temp. variables
+      INTEGER :: ji, jk, js, jw, jn   ! dummy looop indices
+
+      REAL(wp), DIMENSION(jpoce,jpksed) :: zrearat1, zrearat2, zrearat3    ! reaction rate in pore water
+      REAL(wp), DIMENSION(jpoce,jpksed) :: zundsat    ! undersaturation ; indice jpwatp1 is for calcite   
+      REAL(wp), DIMENSION(jpoce,jpksed) :: zkpoc, zkpos, zkpor, zlimo2, zlimno3, zlimso4, zlimfeo    ! undersaturation ; indice jpwatp1 is for calcite   
+      REAL(wp), DIMENSION(jpoce)        :: zsumtot
       REAL(wp)  ::  zsolid1, zsolid2, zsolid3, zvolw, zreasat
-
+      REAL(wp)  ::  zsatur, zsatur2, znusil, zkpoca, zkpocb, zkpocc
+      REAL(wp)  ::  zratio, zgamma, zbeta, zlimtmp, zundsat2
       !!
       !!----------------------------------------------------------------------
 
-      IF( kt == nitsed000 ) THEN
-         WRITE(numsed,*) ' sed_dsr : Dissolution reaction '
-         WRITE(numsed,*) ' '
-         ! 
-         ALLOCATE( dens_mol_wgt((jpoce) ) 
-         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) )  
+      IF( ln_timing )  CALL timing_start('sed_dsr')
+!
+      IF( kt == nitsed000 .AND. knt == 1 ) THEN
+         IF (lwp) THEN
+            WRITE(numsed,*) ' sed_dsr : Dissolution reaction '
+            WRITE(numsed,*) ' '
+         ENDIF
       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.
+     ! Initializations
+     !----------------------
       
-      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)
+      zrearat1(:,:)   = 0.    ;   zundsat(:,:) = 0. ; zkpoc(:,:) = 0.
+      zlimo2 (:,:)    = 0.    ;   zlimno3(:,:) = 0. ; zrearat2(:,:) = 0.
+      zlimso4(:,:)    = 0.    ;   zkpor(:,:)   = 0. ; zrearat3(:,:) = 0.
+      zkpos  (:,:)    = 0.
+      zsumtot(:)      = rtrn
+  
+      ALLOCATE( zvolc(jpoce, jpksed, jpsol) )
+      zvolc(:,:,:)    = 0.
+      zadsnh4 = 1.0 / ( 1.0 + adsnh4 )
+
+      ! Inhibition terms for the different redox equations
+      ! --------------------------------------------------
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zkpoc(ji,jk) = reac_pocl 
+            zkpos(ji,jk) = reac_pocs
+            zkpor(ji,jk) = reac_pocr
+         END DO
+      END DO
 
       ! Conversion of volume units
@@ -120,160 +99,104 @@
       DO js = 1, jpsol
          DO jk = 1, jpksed
-            DO ji = 1, jpoce    
+            DO ji = 1, jpoce
                zvolc(ji,jk,js) = ( vols3d(ji,jk) * dens_mol_wgt(js) ) /  &
-                  &              ( volw3d(ji,jk) * 1.e-3 )     
+                  &              ( 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
+      ! 5.  Beginning of 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
-
+      zrearat1(:,:) = 0.
+      zrearat2(:,:) = 0.
+      zrearat3(:,:) = 0.
+
+      zundsat(:,:) = pwcp(:,:,jwoxy)
+
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zlimo2(ji,jk) = 1.0 / ( zundsat(ji,jk) + xksedo2 )
+            zsolid1 = zvolc(ji,jk,jspoc)  * solcp(ji,jk,jspoc)
+            zsolid2 = zvolc(ji,jk,jspos)  * solcp(ji,jk,jspos)
+            zsolid3 = zvolc(ji,jk,jspor)  * solcp(ji,jk,jspor)
+            zkpoca  = zkpoc(ji,jk) * zlimo2(ji,jk)
+            zkpocb  = zkpos(ji,jk) * zlimo2(ji,jk)
+            zkpocc  = zkpor(ji,jk) * zlimo2(ji,jk)
+            zrearat1(ji,jk)  = ( zkpoc(ji,jk) * dtsed2 * zsolid1 ) / &
+            &                 ( 1. + zkpoca * zundsat(ji,jk ) * dtsed2 )
+            zrearat2(ji,jk)  = ( zkpos(ji,jk) * dtsed2 * zsolid2 ) / &
+            &                 ( 1. + zkpocb * zundsat(ji,jk ) * dtsed2 )
+            zrearat3(ji,jk)  = ( zkpor(ji,jk) * dtsed2 * zsolid3 ) / &
+            &                 ( 1. + zkpocc * zundsat(ji,jk ) * dtsed2 )
+         ENDDO
+      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 )
-
+!      DO jn = 1, 5
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+jflag1:     DO jn = 1, 10
+               zsolid1 = zvolc(ji,jk,jspoc)  * solcp(ji,jk,jspoc)
+               zsolid2 = zvolc(ji,jk,jspos)  * solcp(ji,jk,jspos)
+               zsolid3 = zvolc(ji,jk,jspor)  * solcp(ji,jk,jspor)
+               zbeta   = xksedo2 - pwcp(ji,jk,jwoxy) + so2ut * ( zrearat1(ji,jk)    &
+               &         + zrearat2(ji,jk) + zrearat3(ji,jk) )
+               zgamma = - xksedo2 * pwcp(ji,jk,jwoxy)
+               zundsat2 = zundsat(ji,jk)
+               zundsat(ji,jk) = ( - zbeta + SQRT( zbeta**2 - 4.0 * zgamma ) ) / 2.0
+               zlimo2(ji,jk) = 1.0 / ( zundsat(ji,jk) + xksedo2 )
+               zkpoca  = zkpoc(ji,jk) * zlimo2(ji,jk)
+               zkpocb  = zkpos(ji,jk) * zlimo2(ji,jk)
+               zkpocc  = zkpor(ji,jk) * zlimo2(ji,jk)
+               zrearat1(ji,jk)  = ( zkpoc(ji,jk) * dtsed2 * zsolid1 ) / &
+               &                 ( 1. + zkpoca * zundsat(ji,jk ) * dtsed2 )
+               zrearat2(ji,jk)  = ( zkpos(ji,jk) * dtsed2 * zsolid2 ) / &
+               &                 ( 1. + zkpocb * zundsat(ji,jk ) * dtsed2 )
+               zrearat3(ji,jk)  = ( zkpor(ji,jk) * dtsed2 * zsolid3 ) / &
+               &                 ( 1. + zkpocc * zundsat(ji,jk ) * dtsed2 )
+               IF ( ABS( (zundsat(ji,jk)-zundsat2)/(zundsat2+rtrn)) < 1E-8 ) THEN
+                  EXIT jflag1
+               ENDIF
+            END DO jflag1
+         END DO
+      END DO
 
       ! 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
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zreasat = zrearat1(ji,jk) * zlimo2(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspoc)
+            solcp(ji,jk,jspoc) = solcp(ji,jk,jspoc) - zreasat
+            zreasat = zrearat2(ji,jk) * zlimo2(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspos)
+            solcp(ji,jk,jspos) = solcp(ji,jk,jspos) - zreasat
+            zreasat = zrearat3(ji,jk) * zlimo2(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspor)
+            solcp(ji,jk,jspor) = solcp(ji,jk,jspor) - zreasat
          ENDDO
       ENDDO
 
       ! New pore water concentrations    
-      DO jk = 1, jpksed
+      DO jk = 2, 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         
+            pwcp(ji,jk,jwoxy)  = zundsat(ji,jk)
+            zreasat = ( zrearat1(ji,jk) + zrearat2(ji,jk) + zrearat3(ji,jk) ) * zlimo2(ji,jk) * zundsat(ji,jk)    ! oxygen         
             ! For DIC
             pwcp(ji,jk,jwdic)  = pwcp(ji,jk,jwdic) + zreasat
-            ! For nitrates
-            pwcp(ji,jk,jwno3)  = pwcp(ji,jk,jwno3) + zreasat * srno3            
+            zsumtot(ji) = zsumtot(ji) + zreasat / dtsed2 * volw3d(ji,jk) * 1.e-3 * 86400. * 365. * 1E3
             ! For Phosphate (in mol/l)
-            pwcp(ji,jk,jwpo4)  = pwcp(ji,jk,jwpo4) + zreasat * spo4r            
+            pwcp(ji,jk,jwpo4)  = pwcp(ji,jk,jwpo4) + zreasat * spo4r
+            ! For iron (in mol/l)
+            pwcp(ji,jk,jwfe2)  = pwcp(ji,jk,jwfe2) + fecratio(ji) * zreasat
             ! 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
- 
+            pwcp(ji,jk,jwalk)  = pwcp(ji,jk,jwalk) + zreasat * ( srno3 * zadsnh4 - 2.* spo4r )
+            ! Ammonium
+            pwcp(ji,jk,jwnh4)  = pwcp(ji,jk,jwnh4) + zreasat * srno3 * zadsnh4
+            ! Ligands
+            sedligand(ji,jk)   = sedligand(ji,jk) + ratligc * zreasat - reac_ligc * sedligand(ji,jk)
+         ENDDO
+      ENDDO
 
       !--------------------------------------------------------------------
@@ -282,25 +205,57 @@
       !--------------------------------------------------------------------
 
-      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
+      zrearat1(:,:) = 0.
+      zrearat2(:,:) = 0.
+      zrearat3(:,:) = 0.
+
+      zundsat(:,:) = pwcp(:,:,jwno3)
+
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zlimno3(ji,jk) = ( 1.0 - pwcp(ji,jk,jwoxy) * zlimo2(ji,jk) ) / ( zundsat(ji,jk) + xksedno3 )
+            zsolid1 = zvolc(ji,jk,jspoc) * solcp(ji,jk,jspoc)
+            zsolid2 = zvolc(ji,jk,jspos) * solcp(ji,jk,jspos)
+            zsolid3 = zvolc(ji,jk,jspor) * solcp(ji,jk,jspor)
+            zkpoca = zkpoc(ji,jk) * zlimno3(ji,jk)
+            zkpocb = zkpos(ji,jk) * zlimno3(ji,jk)
+            zkpocc = zkpor(ji,jk) * zlimno3(ji,jk)
+            zrearat1(ji,jk)  = ( zkpoc(ji,jk) * dtsed2 * zsolid1 ) / &
+            &                 ( 1. + zkpoca * zundsat(ji,jk ) * dtsed2 )
+            zrearat2(ji,jk)  = ( zkpos(ji,jk) * dtsed2 * zsolid2 ) / &
+            &                 ( 1. + zkpocb * zundsat(ji,jk ) * dtsed2 )
+            zrearat3(ji,jk)  = ( zkpor(ji,jk) * dtsed2 * zsolid3 ) / &
+            &                 ( 1. + zkpocc * zundsat(ji,jk ) * dtsed2 )
+        END DO
+      END DO
+
+!      DO jn = 1, 5
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+jflag2:    DO jn = 1, 10
+               zlimtmp = ( 1.0 - pwcp(ji,jk,jwoxy) * zlimo2(ji,jk) )
                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 )
+               zsolid2 = zvolc(ji,jk,jspos) * solcp(ji,jk,jspos)
+               zsolid3 = zvolc(ji,jk,jspor) * solcp(ji,jk,jspor)
+               zbeta   = xksedno3 - pwcp(ji,jk,jwno3) + srDnit * ( zrearat1(ji,jk)    &
+               &         + zrearat2(ji,jk) + zrearat3(ji,jk) ) * zlimtmp
+               zgamma = - xksedno3 * pwcp(ji,jk,jwno3)
+               zundsat2 = zundsat(ji,jk)
+               zundsat(ji,jk) = ( - zbeta + SQRT( zbeta**2 - 4.0 * zgamma ) ) / 2.0
+               zlimno3(ji,jk) = ( 1.0 - pwcp(ji,jk,jwoxy) * zlimo2(ji,jk) ) / ( zundsat(ji,jk) + xksedno3 )
+               zkpoca  = zkpoc(ji,jk) * zlimno3(ji,jk)
+               zkpocb  = zkpos(ji,jk) * zlimno3(ji,jk)
+               zkpocc  = zkpor(ji,jk) * zlimno3(ji,jk)
+               zrearat1(ji,jk)  = ( zkpoc(ji,jk) * dtsed2 * zsolid1 ) / &
+               &                 ( 1. + zkpoca * zundsat(ji,jk ) * dtsed2 )
+               zrearat2(ji,jk)  = ( zkpos(ji,jk) * dtsed2 * zsolid2 ) / &
+               &                 ( 1. + zkpocb * zundsat(ji,jk ) * dtsed2 )
+               zrearat3(ji,jk)  = ( zkpor(ji,jk) * dtsed2 * zsolid3 ) / &
+               &                 ( 1. + zkpocc * zundsat(ji,jk ) * dtsed2 )
+               IF ( ABS( (zundsat(ji,jk)-zundsat2)/(zundsat2+rtrn)) < 1E-8 ) THEN
+                  EXIT jflag2
+               ENDIF
+            END DO jflag2
+         END DO
+      END DO
 
 
@@ -308,234 +263,443 @@
       DO jk = 2, jpksed
          DO ji = 1, jpoce
-            zreasat = zrearat(ji,jk,1) * zundsat(ji,jk,1) / zvolc(ji,jk,jspoc)
+            zreasat = zrearat1(ji,jk) * zlimno3(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspoc)
             solcp(ji,jk,jspoc) = solcp(ji,jk,jspoc) - zreasat
+            zreasat = zrearat2(ji,jk) * zlimno3(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspos)
+            solcp(ji,jk,jspos) = solcp(ji,jk,jspos) - zreasat
+            zreasat = zrearat3(ji,jk) * zlimno3(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspor)
+            solcp(ji,jk,jspor) = solcp(ji,jk,jspor) - zreasat
          ENDDO
       ENDDO
 
       ! New dissolved concentrations
-      DO jk = 1, jpksed
-         DO ji = 1, jpoce
-            zreasat = zrearat(ji,jk,1) * zundsat(ji,jk,1)    
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
             ! For nitrates
-            pwcp(ji,jk,jwno3)  =  zundsat(ji,jk,1) * srDnit
+            pwcp(ji,jk,jwno3)  =  zundsat(ji,jk)
+            zreasat = ( zrearat1(ji,jk) + zrearat2(ji,jk) + zrearat3(ji,jk) ) * zlimno3(ji,jk) * zundsat(ji,jk)
             ! For DIC
             pwcp(ji,jk,jwdic)  = pwcp(ji,jk,jwdic) + zreasat
+            zsumtot(ji) = zsumtot(ji) + zreasat / dtsed2 * volw3d(ji,jk) * 1.e-3 * 86400. * 365. * 1E3
             ! For Phosphate (in mol/l)
             pwcp(ji,jk,jwpo4)  = pwcp(ji,jk,jwpo4) + zreasat * spo4r            
+            ! Ligands
+            sedligand(ji,jk)   = sedligand(ji,jk) + ratligc * zreasat
+            ! For iron (in mol/l)
+            pwcp(ji,jk,jwfe2)  = pwcp(ji,jk,jwfe2) + fecratio(ji) * zreasat
             ! 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
+            pwcp(ji,jk,jwalk)  = pwcp(ji,jk,jwalk) + zreasat * ( srDnit + srno3 * zadsnh4 - 2.* spo4r )           
+            ! Ammonium
+            pwcp(ji,jk,jwnh4)  = pwcp(ji,jk,jwnh4) + zreasat * srno3 * zadsnh4
+         ENDDO
+      ENDDO
+
+      !--------------------------------------------------------------------
+      ! Begining POC iron reduction
+      ! (indice nï¿½5 for couple POFe(OH)3 ie solcp(:,:,jspoc)/pwcp(:,:,jsfeo))
+      !--------------------------------------------------------------------
+
+      zrearat1(:,:) = 0.
+      zrearat2(:,:) = 0.
+      zrearat3(:,:) = 0.
+
+      zundsat(:,:) = solcp(:,:,jsfeo)
+
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zlimfeo(ji,jk) = ( 1.0 - pwcp(ji,jk,jwoxy) * zlimo2(ji,jk) ) * ( 1.0 - pwcp(ji,jk,jwno3)    &
+            &                / ( pwcp(ji,jk,jwno3) + xksedno3 ) ) / ( zundsat(ji,jk) + xksedfeo )
+            zsolid1 = zvolc(ji,jk,jspoc) * solcp(ji,jk,jspoc)
+            zsolid2 = zvolc(ji,jk,jspos) * solcp(ji,jk,jspos)
+            zsolid3 = zvolc(ji,jk,jspor) * solcp(ji,jk,jspor)
+            zkpoca = zkpoc(ji,jk) * zlimfeo(ji,jk)
+            zkpocb = zkpos(ji,jk) * zlimfeo(ji,jk)
+            zkpocc = zkpor(ji,jk) * zlimfeo(ji,jk)
+            zrearat1(ji,jk) = ( zkpoc(ji,jk) * dtsed2 * zsolid1 ) / &
+            &                    ( 1. + zkpoca * zundsat(ji,jk) * dtsed2 )
+            zrearat2(ji,jk) = ( zkpos(ji,jk) * dtsed2 * zsolid2 ) / &
+            &                    ( 1. + zkpocb * zundsat(ji,jk) * dtsed2 )
+            zrearat3(ji,jk) = ( zkpor(ji,jk) * dtsed2 * zsolid3 ) / &
+            &                    ( 1. + zkpocc * zundsat(ji,jk) * dtsed2 )
+         END DO
+      END DO
+
+!      DO jn = 1, 5
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+jflag3:     DO jn = 1, 10
+               zlimtmp = ( 1.0 - pwcp(ji,jk,jwoxy) * zlimo2(ji,jk) ) * ( 1.0 - pwcp(ji,jk,jwno3)    &
+               &                / ( pwcp(ji,jk,jwno3) + xksedno3 ) )
+               zsolid1 = zvolc(ji,jk,jspoc) * solcp(ji,jk,jspoc)
+               zsolid2 = zvolc(ji,jk,jspos) * solcp(ji,jk,jspos)
+               zsolid3 = zvolc(ji,jk,jspor) * solcp(ji,jk,jspor)
+               zreasat = ( zrearat1(ji,jk) + zrearat2(ji,jk) + zrearat3(ji,jk) ) / zvolc(ji,jk,jsfeo)
+               zbeta   = xksedfeo - solcp(ji,jk,jsfeo) + 4.0 * zreasat * zlimtmp
+               zgamma  = -xksedfeo * solcp(ji,jk,jsfeo)
+               zundsat2 = zundsat(ji,jk)
+               zundsat(ji,jk) = ( - zbeta + SQRT( zbeta**2 - 4.0 * zgamma ) ) / 2.0
+               zlimfeo(ji,jk) = ( 1.0 - pwcp(ji,jk,jwoxy) * zlimo2(ji,jk) ) * ( 1.0 - pwcp(ji,jk,jwno3)    &
+               &                / ( pwcp(ji,jk,jwno3) + xksedno3 ) ) / ( zundsat(ji,jk) + xksedfeo )
+               zkpoca  = zkpoc(ji,jk) * zlimfeo(ji,jk)
+               zkpocb  = zkpos(ji,jk) * zlimfeo(ji,jk)
+               zkpocc  = zkpor(ji,jk) * zlimfeo(ji,jk)
+               zrearat1(ji,jk) = ( zkpoc(ji,jk) * dtsed2 * zsolid1 ) / &
+               &                    ( 1. + zkpoca * zundsat(ji,jk) * dtsed2 )
+               zrearat2(ji,jk) = ( zkpos(ji,jk) * dtsed2 * zsolid2 ) / &
+               &                    ( 1. + zkpocb * zundsat(ji,jk) * dtsed2 )
+               zrearat3(ji,jk) = ( zkpor(ji,jk) * dtsed2 * zsolid3 ) / &
+               &                    ( 1. + zkpocc * zundsat(ji,jk) * dtsed2 )
+               IF ( ABS( (zundsat(ji,jk)-zundsat2)/( MAX(0.,zundsat2)+rtrn)) < 1E-8 ) THEN
+                  EXIT jflag3
+               ENDIF
+            END DO jflag3
+         END DO
+      END DO
+
+
+         ! New solid concentration values (jk=2 to jksed) for each couple 
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zreasat = zrearat1(ji,jk) * zlimfeo(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspoc)
+            solcp(ji,jk,jspoc) = solcp(ji,jk,jspoc) - zreasat
+            zreasat = zrearat2(ji,jk) * zlimfeo(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspos)
+            solcp(ji,jk,jspos) = solcp(ji,jk,jspos) - zreasat
+            zreasat = zrearat3(ji,jk) * zlimfeo(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspor)
+            solcp(ji,jk,jspor) = solcp(ji,jk,jspor) - zreasat
+         END DO
+      END DO
 
       ! New dissolved concentrations
-      DO jk = 1, jpksed
-         DO ji = 1, jpoce
-            zreasat = zrearat(ji,jk,1) * zundsat(ji,jk,1)    
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zreasat = ( zrearat1(ji,jk) + zrearat2(ji,jk) + zrearat3(ji,jk) ) * zlimfeo(ji,jk) * zundsat(ji,jk)
+            ! For FEOH
+            solcp(ji,jk,jsfeo) = zundsat(ji,jk)
             ! For DIC
             pwcp(ji,jk,jwdic)  = pwcp(ji,jk,jwdic) + zreasat
+            zsumtot(ji) = zsumtot(ji) + zreasat / dtsed2 * volw3d(ji,jk) * 1.e-3 * 86400. * 365. * 1E3
+            ! For Phosphate (in mol/l)
+            pwcp(ji,jk,jwpo4)  = pwcp(ji,jk,jwpo4) + zreasat * ( spo4r + 4.0 * redfep )
+            ! Ligands
+            sedligand(ji,jk)   = sedligand(ji,jk) + ratligc * zreasat
+            ! For iron (in mol/l)
+            pwcp(ji,jk,jwfe2)  = pwcp(ji,jk,jwfe2) + fecratio(ji) * 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))
+            pwcp(ji,jk,jwalk)  = pwcp(ji,jk,jwalk) + zreasat * ( srno3 * zadsnh4 - 2.* spo4r ) + 8.0 * zreasat
+            ! Ammonium
+            pwcp(ji,jk,jwnh4)  = pwcp(ji,jk,jwnh4) + zreasat * srno3 * zadsnh4
+            pwcp(ji,jk,jwfe2)  = pwcp(ji,jk,jwfe2) + zreasat * 4.0
+         ENDDO
+      ENDDO
+
       !--------------------------------------------------------------------
-      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
-      !--------------------------------
+      ! Begining POC denitrification and NO3- diffusion
+      ! (indice nï¿½5 for couple POC/NO3- ie solcp(:,:,jspoc)/pwcp(:,:,jwno3))
+      !--------------------------------------------------------------------
+
+      zrearat1(:,:) = 0.
+      zrearat2(:,:) = 0.
+      zrearat3(:,:) = 0.
+
+      zundsat(:,:) = pwcp(:,:,jwso4)
+
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zlimso4(ji,jk) = ( 1.0 - pwcp(ji,jk,jwoxy) * zlimo2(ji,jk) ) * ( 1.0 - pwcp(ji,jk,jwno3)    &
+            &                / ( pwcp(ji,jk,jwno3) + xksedno3 ) ) * ( 1. - solcp(ji,jk,jsfeo)  &
+            &                / ( solcp(ji,jk,jsfeo) + xksedfeo ) ) / ( zundsat(ji,jk) + xksedso4 )
+            zsolid1 = zvolc(ji,jk,jspoc) * solcp(ji,jk,jspoc)
+            zsolid2 = zvolc(ji,jk,jspos) * solcp(ji,jk,jspos)
+            zsolid3 = zvolc(ji,jk,jspor) * solcp(ji,jk,jspor)
+            zkpoca = zkpoc(ji,jk) * zlimso4(ji,jk)
+            zkpocb = zkpos(ji,jk) * zlimso4(ji,jk)
+            zkpocc = zkpor(ji,jk) * zlimso4(ji,jk)
+            zrearat1(ji,jk)  = ( zkpoc(ji,jk) * dtsed2 * zsolid1 ) / &
+            &                 ( 1. + zkpoca * zundsat(ji,jk ) * dtsed2 )
+            zrearat2(ji,jk)  = ( zkpos(ji,jk) * dtsed2 * zsolid2 ) / &
+            &                 ( 1. + zkpocb * zundsat(ji,jk ) * dtsed2 )
+            zrearat3(ji,jk)  = ( zkpor(ji,jk) * dtsed2 * zsolid3 ) / &
+            &                 ( 1. + zkpocc * zundsat(ji,jk ) * dtsed2 )
+        END DO
+      END DO
+!
+!      DO jn = 1, 5 
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+jflag4:     DO jn = 1, 10
+               zlimtmp = ( 1.0 - pwcp(ji,jk,jwoxy) * zlimo2(ji,jk) ) * ( 1.0 - pwcp(ji,jk,jwno3)    &
+               &         / ( pwcp(ji,jk,jwno3) + xksedno3 ) ) * ( 1. - solcp(ji,jk,jsfeo)  &
+               &         / ( solcp(ji,jk,jsfeo) + xksedfeo ) ) 
+               zsolid1 = zvolc(ji,jk,jspoc) * solcp(ji,jk,jspoc)
+               zsolid2 = zvolc(ji,jk,jspos) * solcp(ji,jk,jspos)
+               zsolid3 = zvolc(ji,jk,jspor) * solcp(ji,jk,jspor)
+               zreasat = ( zrearat1(ji,jk) + zrearat2(ji,jk) + zrearat3(ji,jk) ) 
+               zbeta   = xksedso4 - pwcp(ji,jk,jwso4) + 0.5 * zreasat * zlimtmp
+               zgamma = - xksedso4 * pwcp(ji,jk,jwso4)
+               zundsat2 = zundsat(ji,jk)
+               zundsat(ji,jk) = ( - zbeta + SQRT( zbeta**2 - 4.0 * zgamma ) ) / 2.0
+               zlimso4(ji,jk) = ( 1.0 - pwcp(ji,jk,jwoxy) * zlimo2(ji,jk) ) * ( 1.0 - pwcp(ji,jk,jwno3)    &
+               &                / ( pwcp(ji,jk,jwno3) + xksedno3 ) ) * ( 1. - solcp(ji,jk,jsfeo)  &
+               &                / ( solcp(ji,jk,jsfeo) + xksedfeo ) ) / ( zundsat(ji,jk) + xksedso4 )
+               zkpoca  = zkpoc(ji,jk) * zlimso4(ji,jk)
+               zkpocb  = zkpos(ji,jk) * zlimso4(ji,jk)
+               zkpocc  = zkpor(ji,jk) * zlimso4(ji,jk)
+               zrearat1(ji,jk)  = ( zkpoc(ji,jk) * dtsed2 * zsolid1 ) / &
+               &                 ( 1. + zkpoca * zundsat(ji,jk ) * dtsed2 )
+               zrearat2(ji,jk)  = ( zkpos(ji,jk) * dtsed2 * zsolid2 ) / &
+               &                 ( 1. + zkpocb * zundsat(ji,jk ) * dtsed2 )
+               zrearat3(ji,jk)  = ( zkpor(ji,jk) * dtsed2 * zsolid3 ) / &
+               &                 ( 1. + zkpocc * zundsat(ji,jk ) * dtsed2 )
+               IF ( ABS( (zundsat(ji,jk)-zundsat2)/(zundsat2+rtrn)) < 1E-8 ) THEN
+                  EXIT jflag4
+               ENDIF
+            END DO jflag4
+         END DO
+      END DO
+
+     ! New solid concentration values (jk=2 to jksed) for each couple 
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zreasat = zrearat1(ji,jk) * zlimso4(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspoc)
+            solcp(ji,jk,jspoc) = solcp(ji,jk,jspoc) - zreasat
+            zreasat = zrearat2(ji,jk) * zlimso4(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspos)
+            solcp(ji,jk,jspos) = solcp(ji,jk,jspos) - zreasat
+            zreasat = zrearat3(ji,jk) * zlimso4(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspor)
+            solcp(ji,jk,jspor) = solcp(ji,jk,jspor) - zreasat
+         ENDDO
+      ENDDO
+!
+      ! New dissolved concentrations
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            ! For sulfur
+            pwcp(ji,jk,jwh2s)  = pwcp(ji,jk,jwh2s) - ( zundsat(ji,jk) - pwcp(ji,jk,jwso4) ) 
+            pwcp(ji,jk,jwso4)  =  zundsat(ji,jk)
+            zreasat = ( zrearat1(ji,jk) + zrearat2(ji,jk) + zrearat3(ji,jk) ) * zlimso4(ji,jk) * zundsat(ji,jk)
+            ! For DIC
+            pwcp(ji,jk,jwdic)  = pwcp(ji,jk,jwdic) + zreasat
+            zsumtot(ji) = zsumtot(ji) + zreasat / dtsed2 * volw3d(ji,jk) * 1.e-3 * 86400. * 365. * 1E3
+            ! For Phosphate (in mol/l)
+            pwcp(ji,jk,jwpo4)  = pwcp(ji,jk,jwpo4) + zreasat * spo4r
+            ! Ligands
+            sedligand(ji,jk)   = sedligand(ji,jk) + ratligc * zreasat
+            ! For iron (in mol/l)
+            pwcp(ji,jk,jwfe2)  = pwcp(ji,jk,jwfe2) + fecratio(ji) * zreasat
+            ! For alkalinity
+            pwcp(ji,jk,jwalk)  = pwcp(ji,jk,jwalk) + zreasat * ( srno3 * zadsnh4 - 2.* spo4r ) + zreasat
+            ! Ammonium
+            pwcp(ji,jk,jwnh4)  = pwcp(ji,jk,jwnh4) + zreasat * srno3 * zadsnh4
+         ENDDO
+      ENDDO
+
+      ! Oxydation of the reduced products. Here only ammonium and ODU is accounted for
+      ! There are two options here: A simple time splitting scheme and a modified 
+     ! Patankar scheme
+      ! ------------------------------------------------------------------------------
+
+      call sed_dsr_redoxb
+
+      ! -------------------------------------------------------------- 
+      !    4/ Computation of the bioturbation coefficient
+      !       This parameterization is taken from Archer et al. (2002)
+      ! --------------------------------------------------------------
+
       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 )   
-      
+         db(ji,:) = dbiot * zsumtot(ji) * pwcp(ji,1,jwoxy) / (pwcp(ji,1,jwoxy) + 20.E-6)
+      END DO
+
+      ! ------------------------------------------------------
+      !    Vertical variations of the bioturbation coefficient
+      ! ------------------------------------------------------
+      IF (ln_btbz) THEN
+         DO ji = 1, jpoce
+            db(ji,:) = db(ji,:) * exp( -(profsedw(:) / dbtbzsc)**2 ) / (365.0 * 86400.0)
+         END DO
+      ELSE
+         DO jk = 1, jpksed
+            IF (profsedw(jk) > dbtbzsc) THEN
+                db(:,jk) = 0.0
+            ENDIF
+         END DO
+      ENDIF
+
+      IF (ln_irrig) THEN
+         DO jk = 1, jpksed
+            DO ji = 1, jpoce
+               irrig(ji,jk) = ( 7.63752 - 7.4465 * exp( -0.89603 * zsumtot(ji) ) ) * pwcp(ji,1,jwoxy)  &
+               &             / (pwcp(ji,1,jwoxy) + 20.E-6) 
+               irrig(ji,jk) = irrig(ji,jk) * exp( -(profsedw(jk) / xirrzsc) )
+            END DO
+         END DO
+      ELSE
+         irrig(:,:) = 0.0
+      ENDIF
+
+      DEALLOCATE( zvolc )
+
+      IF( ln_timing )  CALL timing_stop('sed_dsr')
+!      
    END SUBROUTINE sed_dsr
-#else
-   !!======================================================================
-   !! MODULE seddsr  :   Dummy module 
-   !!======================================================================
-   !! $Id$
-CONTAINS
-   SUBROUTINE sed_dsr ( kt )
-     INTEGER, INTENT(in) :: kt
-     WRITE(*,*) 'sed_dsr: You should not have seen this print! error?', kt
-  END SUBROUTINE sed_dsr
-#endif
-   
+
+   SUBROUTINE sed_dsr_redoxb
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_dsr_redox  ***
+      !! 
+      !!  ** Purpose :  computes secondary redox reactions
+      !!
+      !!  ** Methode :  It uses Strand splitter algorithm proposed by 
+      !!                Nguyen et al. (2009) and modified by Wang et al. (2018)
+      !!                Basically, each equation is solved analytically when 
+      !!                feasible, otherwise numerically at t+1/2. Then 
+      !!                the last equation is solved at t+1. The other equations
+      !!                are then solved at t+1 starting in the reverse order.
+      !!                Ideally, it's better to start from the fastest reaction
+      !!                to the slowest and then reverse the order to finish up
+      !!                with the fastest one. But random order works well also.
+      !!                The scheme is second order, positive and mass 
+      !!                conserving. It works well for stiff systems.
+      !! 
+      !!   History :
+      !!        !  18-08 (O. Aumont)  Original code
+      !!----------------------------------------------------------------------
+      !! Arguments
+      ! --- local variables
+      INTEGER   ::  ji, jk, jn   ! dummy looop indices
+
+      REAL, DIMENSION(6)  :: zsedtrn, zsedtra
+      REAL(wp)  ::  zalpha, zbeta, zgamma, zdelta, zepsi, zsedfer
+      !!
+      !!----------------------------------------------------------------------
+
+      IF( ln_timing )  CALL timing_start('sed_dsr_redoxb')
+
+      DO ji = 1, jpoce
+         DO jk = 2, jpksed
+            zsedtrn(1)  = pwcp(ji,jk,jwoxy)
+            zsedtrn(2)  = MAX(0., pwcp(ji,jk,jwh2s) )
+            zsedtrn(3)  = pwcp(ji,jk,jwnh4)
+            zsedtrn(4)  = MAX(0., pwcp(ji,jk,jwfe2) - sedligand(ji,jk) )
+            zsedfer     = MIN(0., pwcp(ji,jk,jwfe2) - sedligand(ji,jk) )
+            zsedtrn(5)  = solcp(ji,jk,jsfeo) * zvolc(ji,jk,jsfeo)
+            zsedtrn(6)  = solcp(ji,jk,jsfes) * zvolc(ji,jk,jsfes)
+            zsedtra(:)  = zsedtrn(:) 
+
+            ! First pass of the scheme. At the end, it is 1st order 
+            ! -----------------------------------------------------
+            ! Fe + O2
+            zalpha = zsedtra(1) - 0.25 * zsedtra(4)
+            zbeta  = zsedtra(4) + zsedtra(5) 
+            zgamma = pwcp(ji,jk,jwalk) - 2.0 * zsedtra(4)
+            zdelta = pwcp(ji,jk,jwpo4) - redfep * zsedtra(4)
+            zsedtra(4) = ( zsedtra(4) * zalpha ) / ( 0.25 * zsedtra(4) * ( exp( reac_fe2 * zalpha * dtsed2 / 2. ) - 1.0 )  &
+            &            + zalpha * exp( reac_fe2 * zalpha * dtsed2 / 2. ) + rtrn )
+            zsedtra(1) = zalpha + 0.25 * zsedtra(4) 
+            zsedtra(5) = zbeta  - zsedtra(4)
+            pwcp(ji,jk,jwalk) = zgamma + 2.0 * zsedtra(4)
+            pwcp(ji,jk,jwpo4) = zdelta + redfep * zsedtra(4)
+            ! H2S + O2
+            zalpha = zsedtra(1) - 2.0 * zsedtra(2)
+            zbeta  = pwcp(ji,jk,jwso4) + zsedtra(2)
+            zgamma = pwcp(ji,jk,jwalk) - 2.0 * zsedtra(2)
+            zsedtra(2) = ( zsedtra(2) * zalpha ) / ( 2.0 * zsedtra(2) * ( exp( reac_h2s * zalpha * dtsed2 / 2. ) - 1.0 )  &
+            &            + zalpha * exp( reac_h2s * zalpha * dtsed2 / 2. ) + rtrn )
+            zsedtra(1) = zalpha + 2.0 * zsedtra(2)
+            pwcp(ji,jk,jwalk) = zgamma + 2.0 * zsedtra(2)
+            pwcp(ji,jk,jwso4) = zbeta - zsedtra(2)
+            ! NH4 + O2
+            zalpha = zsedtra(1) - 2.0 * zsedtra(3)
+            zgamma = pwcp(ji,jk,jwalk) - 2.0 * zsedtra(3)
+            zsedtra(3) = ( zsedtra(3) * zalpha ) / ( 2.0 * zsedtra(3) * ( exp( reac_nh4 * zadsnh4 * zalpha * dtsed2 / 2. ) - 1.0 )  &
+            &            + zalpha * exp( reac_nh4 * zadsnh4 * zalpha * dtsed2 /2. ) + rtrn )
+            zsedtra(1) = zalpha + 2.0 * zsedtra(3)
+            pwcp(ji,jk,jwalk) = zgamma + 2.0 * zsedtra(3)
+            ! FeS - O2
+            zalpha = zsedtra(1) - 2.0 * zsedtra(6)
+            zbeta  = zsedtra(4) + zsedtra(6)
+            zgamma = pwcp(ji,jk,jwso4) + zsedtra(6)
+            zsedtra(6) = ( zsedtra(6) * zalpha ) / ( 2.0 * zsedtra(6) * ( exp( reac_feso * zalpha * dtsed2 / 2. ) - 1.0 )  &
+            &            + zalpha * exp( reac_feso * zalpha * dtsed2 /2. ) + rtrn )
+            zsedtra(1) = zalpha + 2.0 * zsedtra(6)
+            zsedtra(4) = zbeta  - zsedtra(6)
+            pwcp(ji,jk,jwso4) = zgamma - zsedtra(6)
+!            ! Fe - H2S
+            zalpha = zsedtra(2) - zsedtra(4)
+            zbeta  = zsedtra(4) + zsedtra(6)
+            zgamma = pwcp(ji,jk,jwalk) - 2.0 * zsedtra(4)
+            zsedtra(4) = ( zsedtra(4) * zalpha ) / ( zsedtra(4) * ( exp( reac_fes * zalpha * dtsed2 / 2. ) - 1.0 )  &
+            &            + zalpha * exp( reac_fes * zalpha * dtsed2 /2. ) + rtrn )
+            zsedtra(2) = zalpha + zsedtra(4)
+            zsedtra(6) = zbeta  - zsedtra(4)
+            pwcp(ji,jk,jwalk) = zgamma + 2.0 * zsedtra(4)
+            ! FEOH + H2S
+            zalpha = zsedtra(5) - 2.0 * zsedtra(2)
+            zbeta  = zsedtra(5) + zsedtra(4)
+            zgamma = pwcp(ji,jk,jwalk) - 2.0 * zsedtra(4)
+            zdelta = pwcp(ji,jk,jwso4) + zsedtra(2)
+            zepsi  = pwcp(ji,jk,jwpo4) + redfep * zsedtra(5)
+            zsedtra(2) = ( zsedtra(2) * zalpha ) / ( 2.0 * zsedtra(2) * ( exp( reac_feh2s * zalpha * dtsed2 ) - 1.0 )  &
+            &            + zalpha * exp( reac_feh2s * zalpha * dtsed2 ) + rtrn )
+            zsedtra(5) = zalpha + 2.0 * zsedtra(2)
+            zsedtra(4) = zbeta  - zsedtra(5)
+            pwcp(ji,jk,jwso4) = zdelta - zsedtra(2)
+            pwcp(ji,jk,jwalk) = zgamma + 2.0 * zsedtra(4)
+            pwcp(ji,jk,jwpo4) = zepsi - redfep * zsedtra(5)
+            ! Fe - H2S
+            zalpha = zsedtra(2) - zsedtra(4)
+            zbeta  = zsedtra(4) + zsedtra(6)
+            zgamma = pwcp(ji,jk,jwalk) - 2.0 * zsedtra(4)
+            zsedtra(4) = ( zsedtra(4) * zalpha ) / ( zsedtra(4) * ( exp( reac_fes * zalpha * dtsed2 / 2. ) - 1.0 )  &
+            &            + zalpha * exp( reac_fes * zalpha * dtsed2 /2. ) + rtrn )
+            zsedtra(2) = zalpha + zsedtra(4)
+            zsedtra(6) = zbeta  - zsedtra(4)
+            pwcp(ji,jk,jwalk) = zgamma + 2.0 * zsedtra(4)
+            ! FeS - O2
+            zalpha = zsedtra(1) - 2.0 * zsedtra(6)
+            zbeta  = zsedtra(4) + zsedtra(6)
+            zgamma = pwcp(ji,jk,jwso4) + zsedtra(6)
+            zsedtra(6) = ( zsedtra(6) * zalpha ) / ( 2.0 * zsedtra(6) * ( exp( reac_feso * zalpha * dtsed2 / 2. ) - 1.0 )  &
+            &            + zalpha * exp( reac_feso * zalpha * dtsed2 /2. ) + rtrn )
+            zsedtra(1) = zalpha + 2.0 * zsedtra(6)
+            zsedtra(4) = zbeta  - zsedtra(6)
+            pwcp(ji,jk,jwso4) = zgamma - zsedtra(6)
+            ! NH4 + O2
+            zalpha = zsedtra(1) - 2.0 * zsedtra(3)
+            zgamma = pwcp(ji,jk,jwalk) - 2.0 * zsedtra(3)
+            zsedtra(3) = ( zsedtra(3) * zalpha ) / ( 2.0 * zsedtra(3) * ( exp( reac_nh4 * zadsnh4 * zalpha * dtsed2 / 2. ) - 1.0 )  &
+            &            + zalpha * exp( reac_nh4 * zadsnh4 * zalpha * dtsed2 /2. ) + rtrn )
+            zsedtra(1) = zalpha + 2.0 * zsedtra(3)
+            pwcp(ji,jk,jwalk) = zgamma + 2.0 * zsedtra(3)
+            ! H2S + O2
+            zalpha = zsedtra(1) - 2.0 * zsedtra(2)
+            zbeta  = pwcp(ji,jk,jwso4) + zsedtra(2)
+            zgamma = pwcp(ji,jk,jwalk) - 2.0 * zsedtra(2)
+            zsedtra(2) = ( zsedtra(2) * zalpha ) / ( 2.0 * zsedtra(2) * ( exp( reac_h2s * zalpha * dtsed2 / 2. ) - 1.0 )  &
+            &            + zalpha * exp( reac_h2s * zalpha * dtsed2 / 2. ) + rtrn )
+            zsedtra(1) = zalpha + 2.0 * zsedtra(2)
+            pwcp(ji,jk,jwso4) = zbeta - zsedtra(2)
+            pwcp(ji,jk,jwalk) = zgamma + 2.0 * zsedtra(2)
+            ! Fe + O2
+            zalpha = zsedtra(1) - 0.25 * zsedtra(4)
+            zbeta  = zsedtra(4) + zsedtra(5)
+            zgamma = pwcp(ji,jk,jwalk) - 2.0 * zsedtra(4)
+            zdelta = pwcp(ji,jk,jwpo4) - redfep * zsedtra(4)
+            zsedtra(4) = ( zsedtra(4) * zalpha ) / ( 0.25 * zsedtra(4) * ( exp( reac_fe2 * zalpha * dtsed2 / 2. ) - 1.0 )  &
+            &            + zalpha * exp( reac_fe2 * zalpha * dtsed2 / 2. ) + rtrn )
+            zsedtra(1) = zalpha + 0.25 * zsedtra(4)
+            zsedtra(5) = zbeta  - zsedtra(4)
+            pwcp(ji,jk,jwpo4) = zdelta + redfep * zsedtra(4)
+            pwcp(ji,jk,jwalk) = zgamma + 2.0 * zsedtra(4)
+            pwcp(ji,jk,jwoxy)  = zsedtra(1)
+            pwcp(ji,jk,jwh2s)  = zsedtra(2)
+            pwcp(ji,jk,jwnh4)  = zsedtra(3)
+            pwcp(ji,jk,jwfe2)  = zsedtra(4) + sedligand(ji,jk) + zsedfer
+            pwcp(ji,jk,jwno3)  = pwcp(ji,jk,jwno3)  + ( zsedtrn(3) - pwcp(ji,jk,jwnh4) )
+            solcp(ji,jk,jsfeo) = zsedtra(5) / zvolc(ji,jk,jsfeo)
+            solcp(ji,jk,jsfes) = zsedtra(6) / zvolc(ji,jk,jsfes)
+         END DO
+      END DO
+
+      IF( ln_timing )  CALL timing_stop('sed_dsr_redoxb')
+
+  END SUBROUTINE sed_dsr_redoxb
+
 END MODULE seddsr
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/seddta.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/seddta.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/seddta.F90	(revision 10345)
@@ -4,9 +4,11 @@
    !! Sediment data  :  read sediment input data from a file
    !!=====================================================================
-#if defined key_sed
+
    !! * Modules used
    USE sed
    USE sedarr
+   USE phycst, ONLY : rday
    USE iom
+   USE lib_mpp         ! distribued memory computing library
 
    IMPLICIT NONE
@@ -17,14 +19,6 @@
 
    !! *  Module variables
-   REAL(wp), DIMENSION(:), ALLOCATABLE ::  smask       ! mask for sediments points
    REAL(wp) ::  rsecday  ! number of second per a day
-   REAL(wp) ::  conv1    ! [m/day]--->[cm/s]  
    REAL(wp) ::  conv2    ! [kg/m2/month]-->[g/cm2/s] ( 1 month has 30 days )
-
-   INTEGER ::  numbio
-
-#if defined key_sed_off
-   INTEGER ::  numoce
-#endif
 
    !! $Id$
@@ -54,7 +48,7 @@
       INTEGER  ::  ji, jj, js, jw, ikt
 
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: zdta
-      REAL(wp), DIMENSION(:)  , ALLOCATABLE :: zdtap, zdtag
-
+      REAL(wp), DIMENSION(jpoce) :: zdtap, zdtag
+      REAL(wp), DIMENSION(jpi,jpj) :: zwsbio4, zwsbio3, zwscal
+      REAL(wp) :: zf0, zf1, zf2, zkapp, zratio, zdep
 
       !----------------------------------------------------------------------
@@ -64,136 +58,145 @@
       !-------------------------------------------------------------
 
-      WRITE(numsed,*)
-      WRITE(numsed,*) ' sed_dta : Bottom layer fields'
-      WRITE(numsed,*) ' ~~~~~~'
-      WRITE(numsed,*) ' Data from SMS model'
-      WRITE(numsed,*)
+      IF( ln_timing )  CALL timing_start('sed_dta')
+
+      IF (lwp) THEN
+         WRITE(numsed,*)
+         WRITE(numsed,*) ' sed_dta : Bottom layer fields'
+         WRITE(numsed,*) ' ~~~~~~'
+         WRITE(numsed,*) ' Data from SMS model'
+         WRITE(numsed,*)
+      ENDIF
 
 
       ! open file
       IF( kt == nitsed000 ) THEN
-         WRITE(numsed,*) ' sed_dta : Sediment fields'
-         CALL iom_open ( 'data_bio_bot'     , numbio )
-#if defined key_sed_off
-         CALL iom_open( 'data_oce_bot', numoce)
-#endif
+         IF (lwp) WRITE(numsed,*) ' sed_dta : Sediment fields'
+         dtsed = r2dttrc
          rsecday = 60.* 60. * 24.
-         conv1   = 1.0e+2 / rsecday 
-         conv2   = 1.0e+3 / ( 1.0e+4 * rsecday * 30. ) 
-
-         ! Compute sediment mask
-         ALLOCATE( zdta(jpi,jpj) ) 
+!         conv2   = 1.0e+3 / ( 1.0e+4 * rsecday * 30. )
+         conv2 = 1.0e+3 /  1.0e+4 
+         rdtsed(2:jpksed) = dtsed / ( denssol * por1(2:jpksed) )
+      ENDIF
+
+      ! Initialization of temporaries arrays  
+      zdtap(:)    = 0. 
+      zdtag(:)    = 0.  
+
+      ! reading variables
+      IF (lwp) WRITE(numsed,*)
+      IF (lwp) WRITE(numsed,*) ' sed_dta : Bottom layer fields at time  kt = ', kt
+      ! reading variables
+      !
+      !    Sinking speeds of detritus is increased with depth as shown
+      !    by data and from the coagulation theory
+      !    -----------------------------------------------------------
+      IF (ln_sediment_offline) THEN
          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
-
-      ! Initialization of temporaries arrays  
-      ALLOCATE( zdtap(jpoce) )    ;   zdtap(:)    = 0. 
-      ALLOCATE( zdtag(jpoce) )    ;   zdtag(:)    = 0.  
-
-      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
+               ikt = mbkt(ji,jj)
+               zwsbio4(ji,jj) = wsbio2 / rday
+               zwsbio3(ji,jj) = wsbio  / rday
+               zwscal (ji,jj) = wsbio2 / rday
+            END DO
+         END DO
+      ELSE
+         DO jj = 1, jpj
             DO ji = 1, jpi
                ikt = mbkt(ji,jj)
-               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)
-                  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) = tsn     (ji,jj,ikt,jp_tem)
-                  trc_data(ji,jj,12) = tsn     (ji,jj,ikt,jp_sal)
-               ENDIF
-            ENDDO
+               zdep = e3t_n(ji,jj,ikt) / r2dttrc
+               zwsbio4(ji,jj) = MIN( 0.99 * zdep, wsbio4(ji,jj,ikt) / rday )
+               zwscal (ji,jj) = MIN( 0.99 * zdep, wscal (ji,jj,ikt) / rday )
+               zwsbio3(ji,jj) = MIN( 0.99 * zdep, wsbio3(ji,jj,ikt) / rday )
+            END DO
+         END DO
+      ENDIF
+
+      trc_data(:,:,:) = 0.
+      DO jj = 1,jpj
+         DO ji = 1, jpi
+            ikt = mbkt(ji,jj)
+            IF ( tmask(ji,jj,ikt) == 1 ) THEN
+               trc_data(ji,jj,1)   = trb(ji,jj,ikt,jpsil)
+               trc_data(ji,jj,2)   = trb(ji,jj,ikt,jpoxy)
+               trc_data(ji,jj,3)   = trb(ji,jj,ikt,jpdic)
+               trc_data(ji,jj,4)   = trb(ji,jj,ikt,jpno3) / 7.625
+               trc_data(ji,jj,5)   = trb(ji,jj,ikt,jppo4) / 122.
+               trc_data(ji,jj,6)   = trb(ji,jj,ikt,jptal)
+               trc_data(ji,jj,7)   = trb(ji,jj,ikt,jpnh4) / 7.625
+               trc_data(ji,jj,8)   = 0.0
+               trc_data(ji,jj,9)   = 28.0E-3
+               trc_data(ji,jj,10)  = trb(ji,jj,ikt,jpfer)
+               trc_data(ji,jj,11 ) = MIN(trb(ji,jj,ikt,jpgsi), 1E-4) * zwsbio4(ji,jj) * 1E3
+               trc_data(ji,jj,12 ) = MIN(trb(ji,jj,ikt,jppoc), 1E-4) * zwsbio3(ji,jj) * 1E3
+               trc_data(ji,jj,13 ) = MIN(trb(ji,jj,ikt,jpgoc), 1E-4) * zwsbio4(ji,jj) * 1E3
+               trc_data(ji,jj,14)  = MIN(trb(ji,jj,ikt,jpcal), 1E-4) * zwscal (ji,jj) * 1E3
+               trc_data(ji,jj,15)  = tsn(ji,jj,ikt,jp_tem)
+               trc_data(ji,jj,16)  = tsn(ji,jj,ikt,jp_sal)
+               trc_data(ji,jj,17 ) = ( trb(ji,jj,ikt,jpsfe) * zwsbio3(ji,jj) + trb(ji,jj,ikt,jpbfe)  &
+               &                     * zwsbio4(ji,jj)  ) * 1E3 / ( trc_data(ji,jj,12 ) + trc_data(ji,jj,13 ) + rtrn )
+               trc_data(ji,jj,17 ) = MIN(1E-3, trc_data(ji,jj,17 ) )
+            ENDIF
          ENDDO
-
-#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 ) )
-         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) ) 
-#endif
-
-         ! 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 : 
-         !-----------------------
-         !  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) )
-        
-         ! 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
+      ENDDO
+
+      ! Pore water initial concentration [mol/l] in  k=1
+      !-------------------------------------------------
+      DO jw = 1, jpwat
+         CALL pack_arr ( jpoce,  pwcp_dta(1:jpoce,jw), trc_data(1:jpi,1:jpj,jw), iarroce(1:jpoce) )
+      END DO
+      !  Solid components : 
+      !-----------------------
+      !  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,11), 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,12) , iarroce(1:jpoce) )      
+      CALL pack_arr ( jpoce, zdtag(1:jpoce), trc_data(1:jpi,1:jpj,13) , iarroce(1:jpoce) )
+      DO ji = 1, jpoce
+!        zkapp  = MIN( (1.0 - 0.02 ) * reac_poc, 3731.0 * max(100.0, zkbot(ji) )**(-1.011) / ( 365.0 * 24.0 * 3600.0 ) )
+!        zkapp   = MIN( 0.98 * reac_poc, 100.0 * max(100.0, zkbot(ji) )**(-0.6) / ( 365.0 * 24.0 * 3600.0 ) )
+!        zratio = ( ( 1.0 - 0.02 ) * reac_poc + 0.02 * reac_poc * 0. - zkapp) / ( ( 0.02 - 1.0 ) * reac_poc / 100. - 0.02 * reac_poc * 0. + zkapp )
+!        zf1    = ( 0.02 * (reac_poc - reac_poc * 0.) + zkapp - reac_poc ) / ( reac_poc / 100. - reac_poc )
+!        zf1    = MIN(0.98, MAX(0., zf1 ) )
+         zf1    = 0.48
+         zf0    = 1.0 - 0.02 - zf1
+         zf2    = 0.02
+         rainrm_dta(ji,jspoc) =   ( zdtap(ji) +  zdtag(ji) ) * 1e-4 * zf0
+         rainrm_dta(ji,jspos) =   ( zdtap(ji) +  zdtag(ji) ) * 1e-4 * zf1
+         rainrm_dta(ji,jspor) =   ( zdtap(ji) +  zdtag(ji) ) * 1e-4 * zf2
+      END DO
+      !  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,14), 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,15), iarroce(1:jpoce) )
+      CALL pack_arr ( jpoce,  salt(1:jpoce), trc_data(1:jpi,1:jpj,16), iarroce(1:jpoce) )
+      
+      ! Clay rain rate in [mol/(cm**2.s)] 
+      ! inputs data in [kg.m-2.sec-1] ---> 1e+3/(1e+4) [g.cm-2.s-1]   
+      ! divided after by molecular weight g.mol-1      
+      CALL pack_arr ( jpoce,  rainrm_dta(1:jpoce,jsclay), dust(1:jpi,1:jpj), iarroce(1:jpoce) )
+      rainrm_dta(1:jpoce,jsclay) = rainrm_dta(1:jpoce,jsclay) * conv2 / mol_wgt(jsclay)   &
+      &                            + wacc(1:jpoce) * por1(2) * denssol / mol_wgt(jsclay) / ( rsecday * 365.0 )
+      rainrm_dta(1:jpoce,jsclay) = rainrm_dta(1:jpoce,jsclay) * 0.965
+      rainrm_dta(1:jpoce,jsfeo)  = rainrm_dta(1:jpoce,jsclay) * mol_wgt(jsclay) / mol_wgt(jsfeo) * 0.035 / 0.965
+!    rainrm_dta(1:jpoce,jsclay) = 1.0E-4 * conv2 / mol_wgt(jsclay)
+
+      ! Iron monosulphide rain rates. Set to 0
+      rainrm_dta(1:jpoce,jsfes)  = 0. 
+
+      ! Fe/C ratio in sinking particles that fall to the sediments
+      CALL pack_arr ( jpoce,  fecratio(1:jpoce), trc_data(1:jpi,1:jpj,17), iarroce(1:jpoce) )
+
+      sedligand(:,1) = 1.E-9
 
       ! 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)
+         pwcp(1:jpoce,1,jw) = pwcp_dta(1:jpoce,jw)
       ENDDO
 
       !  rain
       DO js = 1, jpsol
-         rainrm(1:jpoce,js) = rainrm_dta(1:jpoce,js) * smask(1:jpoce)
+         rainrm(1:jpoce,js) = rainrm_dta(1:jpoce,js)
       ENDDO
 
@@ -212,28 +215,14 @@
       dzdep(1:jpoce) = raintg(1:jpoce) * rdtsed(2) 
 
-
-      DEALLOCATE( zdta ) 
-      DEALLOCATE( zdtap    ) ;  DEALLOCATE( zdtag    ) 
-
-      IF( kt == nitsedend )   THEN
-         CALL iom_close ( numbio )
-#if defined key_sed_off
-         CALL iom_close ( numoce )
-#endif
-      ENDIF
+      IF( lk_iomput ) THEN
+          IF( iom_use("sflxclay" ) ) CALL iom_put( "sflxclay", dust(:,:) * conv2 * 1E4 )
+          IF( iom_use("sflxcal" ) )  CALL iom_put( "sflxcal", trc_data(:,:,13) )
+          IF( iom_use("sflxbsi" ) )  CALL iom_put( "sflxbsi", trc_data(:,:,10) )
+          IF( iom_use("sflxpoc" ) )  CALL iom_put( "sflxpoc", trc_data(:,:,11) + trc_data(:,:,12) )
+      ENDIF
+
+      IF( ln_timing )  CALL timing_stop('sed_dta')
       
    END SUBROUTINE sed_dta
 
-#else
-   !!======================================================================
-   !! MODULE seddta  :   Dummy module 
-   !!======================================================================
-   !! $Id$
-CONTAINS
-   SUBROUTINE sed_dta ( kt )
-     INTEGER, INTENT(in) :: kt
-     WRITE(*,*) 'sed_stp: You should not have seen this print! error?', kt 
-  END SUBROUTINE sed_dta
-#endif
-
 END MODULE seddta
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedini.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedini.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedini.F90	(revision 10345)
@@ -4,5 +4,4 @@
    !! Sediment : define sediment variables
    !!=====================================================================
-#if defined key_sed
 
    !!----------------------------------------------------------------------
@@ -11,10 +10,12 @@
    !! * Modules used
    USE sed     ! sediment global variable
-   USE seddta
-   USE sedrst
-   USE sedco3
-   USE sedchem
+   USE sed_oce
    USE sedarr
+   USE sedadv
+   USE trc_oce, ONLY : nn_dttrc
+   USE trcdmp_sed
+   USE trcdta
    USE iom
+   USE lib_mpp         ! distribued memory computing library
 
 
@@ -24,31 +25,55 @@
    !! Module variables
    REAL(wp)    ::  &
-      sisat   =  800.  ,  &  !: saturation for si    [ mol.l-1]
-      claysat =    0.  ,  &  !: saturation for clay  [ mol.l-1]
+      sedzmin = 0.3    ,  &  !: Minimum vertical spacing
+      sedhmax = 10.0   ,  &  !: Maximum depth of the sediment
+      sedkth  = 5.0    ,  &  !: Default parameters
+      sedacr  = 3.0          !: Default parameters
+      
+   REAL(wp)    ::  &
+      porsurf =  0.95  ,  &  !: Porosity at the surface
+      porinf  =  0.75  ,  &  !: Porosity at infinite depth
+      rhox    =  2.0         !: Vertical length scale of porosity variation 
+
+   REAL(wp)    ::  &
       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), PUBLIC    ::  &
+      redO2    =  172.  ,  &  !: Redfield coef for Oxygen
+      redNo3   =   16.  ,  &  !: Redfield coef for Nitrate
+      redPo4   =    1.  ,  &  !: Redfield coef for Phosphate
+      redC     =  122.  ,  &  !: Redfield coef for Carbon
+      redfep   =  0.175 ,  &  !: Ratio for iron bound phosphorus
+      rcorgl   =   50.  ,  &  !: reactivity for POC/O2 [l.mol-1.an-1]    
+      rcorgs   =   0.5  ,  &  !: reactivity of the semi-labile component
+      rcorgr   =   1E-4 ,  &  !: reactivity of the refractory component
+      rcnh4    =   10E6 ,  &  !: reactivity for O2/NH4 [l.mol-1.an-1]  
+      rch2s    =   1.E5 ,  &  !: reactivity for O2/ODU [l.mol-1.an-1] 
+      rcfe2    =   5.E8 ,  &  !: reactivity for O2/Fe2+ [l.mol-1.an-1]
+      rcfeh2s  =   1.E4 ,  &  !: Reactivity for FEOH/H2S [l.mol-1.an-1]
+      rcfes    =   1.E5 ,  &  !: Reactivity for FE2+/H2S [l.mol-1.an-1]
+      rcfeso   =   3.E5 ,  &  !: Reactivity for FES/O2 [l.mol-1.an-1]
+      xksedo2  =   5E-6 ,  &  !: half-sturation constant for oxic remin.
+      xksedno3 =   5E-6 ,  &  !: half-saturation constant for denitrification
+      xksedfeo =   0.6  ,  & !: half-saturation constant for iron remin
+      xksedso4 =   2E-3       !: half-saturation constant for SO4 remin
+
    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
-
+      rccal   = 1000.,      & !: reactivity for calcite         [l.mol-1.an-1]
+      rcligc  = 1.E-4         !: L/C ratio in POC
+
+   REAL(wp), PUBLIC    ::  dbiot   = 15. , &  !: coefficient for bioturbation    [cm**2.(n-1)]
+      dbtbzsc =  10.0  ,    &  !: Vertical scale of variation. If no variation, mixed layer in the sed [cm]
+      xirrzsc = 2.0            !: Vertical scale of irrigation variation.
    REAL(wp)    ::  &
       ryear = 365. * 24. * 3600. !:  1 year converted in second
+
+   REAL(wp), DIMENSION(jpwat), PUBLIC  :: diff1
+   DATA diff1/4.59E-6, 1.104E-5, 4.81E-6 , 9.78E-6, 3.58E-6, 4.01E-6, 9.8E-6, 9.73E-6, 5.0E-6, 3.31E-6 /
+
+   REAL(wp), DIMENSION(jpwat), PUBLIC  :: diff2
+   DATA diff2/1.74E-7, 4.47E-7, 2.51E-7, 3.89E-7, 1.77E-7, 2.5E-7, 3.89E-7, 3.06E-7, 2.5E-7, 1.5E-7 /
+
+
 
    !! *  Routine accessibility
@@ -76,10 +101,5 @@
       !!        !  06-07  (C. Ethe)  Re-organization
       !!----------------------------------------------------------------------
-      INTEGER :: ji, jj, ikt
-#if defined key_sed_off
-      INTEGER  :: numblt         
-      INTEGER  :: nummsh   
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zdta
-#endif
+      INTEGER :: ji, jj, ikt, ierr
       !!----------------------------------------------------------------------
 
@@ -90,53 +110,27 @@
       CALL ctl_opn( numsed, 'sediment.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
 
-      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,*) ' '
-
-      !                                ! Allocate LOBSTER arrays
-      IF( sed_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sed_ini: unable to allocate sediment model arrays' )
-
+      IF (lwp) THEN
+         WRITE(numsed,*)
+         WRITE(numsed,*) '                 PISCES framework'
+         WRITE(numsed,*) '                 SEDIMENT model'
+         WRITE(numsed,*) '                version 3.0  (2018) '
+         WRITE(numsed,*)
+         WRITE(numsed,*)
+      ENDIF
+
+      IF(lwp) WRITE(numsed,*) ' sed_init : Initialization of sediment module  '
+      IF(lwp) WRITE(numsed,*) ' '
+
+      ! Read sediment Namelist
+      !-------------------------
+      CALL sed_init_nam
+
+      ! Allocate SEDIMENT arrays
+      ierr =        sed_alloc()
+      ierr = ierr + sed_oce_alloc()
+      ierr = ierr + sed_adv_alloc() 
+      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'sed_ini: unable to allocate sediment model arrays' )
 
       ! 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
-      ALLOCATE( zdta(jpi,jpj) )
-      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 )
-            IF( tmask(ji,jj,ikt) == 1 ) epkbot(ji,jj) = zdta(ji,jj)
-         ENDDO
-      ENDDO
-
-      CALL iom_close( nummsh )  
-      CALL iom_close( numblt ) 
-
-      DEALLOCATE( zdta )
-#else
-
       epkbot(:,:) = 0.
       DO jj = 1, jpj
@@ -144,13 +138,17 @@
             ikt = mbkt(ji,jj) 
             IF( tmask(ji,jj,ikt) == 1 ) epkbot(ji,jj) = e3t_1d(ikt)
+            gdepbot(ji,jj) = gdepw_0(ji,jj,ikt)
          ENDDO
       ENDDO
-#endif     
-
 
       ! computation of total number of ocean points
       !--------------------------------------------
-      jpoce  = COUNT( epkbot(:,:) > 0. )
-
+      sedmask = 0.
+      IF ( COUNT( epkbot(:,:) > 0. ) == 0 ) THEN 
+          sedmask = 0.
+      ELSE
+          sedmask = 1.
+      ENDIF 
+      jpoce  = MAX( COUNT( epkbot(:,:) > 0. ) , 1 )
 
       ! Allocate memory size of global variables
@@ -159,18 +157,24 @@
       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( zkbot(jpoce) )               ;  ALLOCATE( db(jpoce,jpksed) )
+      ALLOCATE( temp(jpoce) )                ;  ALLOCATE( salt(jpoce) )  
+      ALLOCATE( diff(jpoce,jpksed,jpwat ) )  ;  ALLOCATE( irrig(jpoce, jpksed) )
+      ALLOCATE( wacc(jpoce) )                ;  ALLOCATE( fecratio(jpoce) )
       ALLOCATE( press(jpoce) )               ;  ALLOCATE( densSW(jpoce) ) 
-      ALLOCATE( hipor(jpoce,jpksed) )        ;  ALLOCATE( co3por(jpoce,jpksed) ) 
+      ALLOCATE( hipor(jpoce,jpksed) )        ;  ALLOCATE( co3por(jpoce,jpksed) )
       ALLOCATE( dz3d(jpoce,jpksed) )         ;  ALLOCATE( volw3d(jpoce,jpksed) )       ;  ALLOCATE( vols3d(jpoce,jpksed) )
+      ALLOCATE( sedligand(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. 
+      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.  ; zkbot     (:  ) = 0.
+      press (:    ) = 0.   ;  densSW (:   ) = 0.  ; db        (:,:) = 0. 
+      hipor (:,:  ) = 0.   ;  co3por (:,: ) = 0.  ; irrig     (:,:) = 0. 
+      dz3d  (:,:  ) = 0.   ;  volw3d (:,: ) = 0.  ; vols3d    (:,:) = 0. 
+      fecratio(:)   = 1E-5 
+      sedligand(:,:) = 0.6E-9
 
       ! Chemical variables      
@@ -178,10 +182,13 @@
       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) )    
+      ALLOCATE( borats(jpoce) )  ;  ALLOCATE( calcon2(jpoce) )  ;  ALLOCATE( sieqs (jpoce) ) 
+      ALLOCATE( aks3s(jpoce) )   ;  ALLOCATE( akf3s(jpoce) )    ;  ALLOCATE( sulfats(jpoce) )
+      ALLOCATE( fluorids(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.
+      borats(:) = 0. ;   calcon2(:) = 0. ;  sieqs (:) = 0.
+      aks3s(:)  = 0. ;   akf3s(:)   = 0. ;  sulfats(:) = 0. ;  fluorids(:) = 0.
 
       ! Mass balance calculation  
@@ -191,24 +198,28 @@
       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
-
+      ! Offline specific mode
+      ! ---------------------
+      ln_sediment_offline = .FALSE.
+
+#if defined key_sed_off
+      ln_sediment_offline = .TRUE.
+      IF (lwp) write(numsed,*) 'Sediment module is run in offline mode'
+      IF (lwp) write(numsed,*) 'key_sed_off is activated at compilation time'
+      IF (lwp) write(numsed,*) 'ln_sed_2way is forced to false'
+      IF (lwp) write(numsed,*) '--------------------------------------------'
+      ln_sed_2way = .FALSE.
+#endif
+      ! Initialisation of tracer damping
+      ! --------------------------------
+      IF (ln_sediment_offline) THEN
+         CALL trc_dta_ini(jptra)
+         CALL trc_dmp_sed_ini
+      ENDIF
 
    END SUBROUTINE sed_init
-
 
    SUBROUTINE sed_init_geom
@@ -227,15 +238,11 @@
       !! * Modules used
       !! * local declarations
-      INTEGER ::  &
-        ji, jj, jk
- 
-#if defined key_sed_off
-      REAL(wp) , DIMENSION (jpi,jpj) :: zdta
-      INTEGER  ::  numpres
-#endif
+      INTEGER  :: ji, jj, jk, jn
+      REAL(wp) :: za0, za1, zt, zw, zsum, zsur, zprof, zprofw
+      REAL(wp) :: ztmp1, ztmp2
       !---------------------------------------------------------- 
 
-      WRITE(numsed,*) ' sed_init_geom : Initialization of sediment geometry '
-      WRITE(numsed,*) ' '
+      IF(lwp) WRITE(numsed,*) ' sed_init_geom : Initialization of sediment geometry '
+      IF(lwp) WRITE(numsed,*) ' '
 
       ! Computation of 1D array of sediments points
@@ -250,37 +257,16 @@
       END DO
 
+      IF ( indoce .EQ. 0 ) THEN
+         indoce = 1
+         iarroce(indoce) = 1
+      ENDIF
+
       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
+         CALL ctl_stop( 'STOP', 'sed_ini: number of ocean points indoce doesn''t match  number of point' )
       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
+         IF (lwp) WRITE(numsed,*) ' '
+         IF (lwp) WRITE(numsed,*) ' total number of ocean points jpoce =  ',jpoce
+         IF (lwp) WRITE(numsed,*) ' '
+      ENDIF
 
       ! initialization of dzkbot in [cm]
@@ -288,4 +274,5 @@
       CALL pack_arr ( jpoce, dzkbot(1:jpoce), epkbot(1:jpi,1:jpj), iarroce(1:jpoce) )
       dzkbot(1:jpoce) = dzkbot(1:jpoce) * 1.e+2 
+      CALL pack_arr ( jpoce, zkbot(1:jpoce), gdepbot(1:jpi,1:jpj), iarroce(1:jpoce) )
 
       ! Geometry and  constants 
@@ -293,15 +280,23 @@
       ! (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
+      za1  = (  sedzmin - sedhmax / FLOAT(jpksed-1)  )                                                      &
+         & / ( TANH((1-sedkth)/sedacr) - sedacr/FLOAT(jpksed-1) * (  LOG( COSH( (jpksed - sedkth) / sedacr) )      &
+         &                                                   - LOG( COSH( ( 1  - sedkth) / sedacr) )  )  )
+      za0  = sedzmin - za1 * TANH( (1-sedkth) / sedacr )
+      zsur = - za0 - za1 * sedacr * LOG( COSH( (1-sedkth) / sedacr )  )
+
+      profsedw(1) = 0.0
+      profsed(1) = -dz(1) / 2.
+      DO jk = 2, jpksed
+         zw = REAL( jk , wp )
+         zt = REAL( jk , wp ) - 0.5_wp
+         profsed(jk)  = ( zsur + za0 * zt + za1 * sedacr * LOG ( COSH( (zt-sedkth) / sedacr ) )  ) 
+         profsedw(jk) = ( zsur + za0 * zw + za1 * sedacr * LOG ( COSH( (zw-sedkth) / sedacr ) )  )
+      END DO
+
+      dz(1) = 0.1
+      DO jk = 2, jpksed
+         dz(jk) = profsedw(jk) - profsedw(jk-1)
+      END DO
 
       DO jk = 1, jpksed
@@ -311,24 +306,10 @@
       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
+      por(1) = 1.0
+      DO jk = 2, jpksed
+         por(jk) = porinf + ( porsurf-porinf) * exp(-rhox * (profsed(jk) ) )
+      END DO
  
       ! inverse of  Porosity profile
@@ -353,9 +334,7 @@
       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)
@@ -371,4 +350,8 @@
          &              0.59 * 27. + 10. * 16.
 
+      mol_wgt(jsfeo)  = 55.0 + 3.0 * ( 16.0 + 1.0)
+
+      mol_wgt(jsfes)  = 55.0 + 32.0
+
       ! for chemistry Poc : C(122)H(244)O(86)N(16)P(1)
       ! But den sity of Poc is an Hydrated material (= POC + 30H2O)
@@ -377,4 +360,6 @@
       mol_wgt(jspoc) = ( 122. * 12. + 355. + 120. * 16.+ &
          &                16. * 14. + 31. ) / 122.
+      mol_wgt(jspos) = mol_wgt(jspoc)
+      mol_wgt(jspor) = mol_wgt(jspoc)
 
       ! CaCO3
@@ -384,15 +369,28 @@
       ! Density of solid material in sediment [g/cm**3]
       !------------------------------------------------
-      dens = 2.6
+      denssol = 2.6
 
       ! Initialization of diffusion coefficient as function of porosity [cm**2/s]
       !--------------------------------------------------------------------
-      diff(:) = dcoef * por(:)
+!      DO jn = 1, jpsol
+!         DO jk = 1, jpksed
+!            DO ji = 1, jpoce
+!               diff(ji,jk,jn) = dcoef / ( 1.0 - 2.0 * log(por(jk)) )
+!            END DO
+!         END DO
+!      END DO
+
+      ! Accumulation rate from Burwicz et al. (2011). This is used to
+      ! compute the flux of clays and minerals
+      ! --------------------------------------------------------------
+      DO ji = 1, jpoce
+          ztmp1 = 0.117 / ( 1.0 + ( zkbot(ji) / 200.)**3 )
+          ztmp2 = 0.006 / ( 1.0 + ( zkbot(ji) / 4000.)**10 )
+          wacc(ji) = ztmp1 + ztmp2
+      END DO
 
 
       ! Initialization of time step as function of porosity [cm**2/s]
       !------------------------------------------------------------------
-      rdtsed(2:jpksed) = dtsed / ( dens * por1(2:jpksed) )
-     
    END SUBROUTINE sed_init_geom
 
@@ -408,6 +406,8 @@
       !!----------------------------------------------------------------------
 
-      INTEGER :: &
-         numnamsed = 28
+      INTEGER ::   numnamsed_ref = -1           !! Logical units for namelist sediment
+      INTEGER ::   numnamsed_cfg = -1           !! Logical units for namelist sediment
+      INTEGER :: ios                 ! Local integer output status for namelist read
+      CHARACTER(LEN=20)   ::   clname
 
       TYPE PSED
@@ -422,57 +422,84 @@
       TYPE(PSED) , DIMENSION(jpdia2dsed) :: seddiag2d
 
-      NAMELIST/nam_time/nfreq
+      NAMELIST/nam_run/nrseddt,ln_sed_2way
+      NAMELIST/nam_geom/jpksed, sedzmin, sedhmax, sedkth, sedacr, porsurf, porinf, rhox
       NAMELIST/nam_trased/sedsol, sedwat
       NAMELIST/nam_diased/seddiag3d, seddiag2d
-      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, jn1
+      NAMELIST/nam_inorg/rcopal, dcoef, rccal, ratligc, rcligc
+      NAMELIST/nam_poc/redO2, redNo3, redPo4, redC, redfep, rcorgl, rcorgs,  &
+         &             rcorgr, rcnh4, rch2s, rcfe2, rcfeh2s, rcfes, rcfeso,  &
+         &             xksedo2, xksedno3, xksedfeo, xksedso4
+      NAMELIST/nam_btb/dbiot, ln_btbz, dbtbzsc, adsnh4, ln_irrig, xirrzsc
+      NAMELIST/nam_rst/ln_rst_sed, cn_sedrst_indir, cn_sedrst_outdir, cn_sedrst_in, cn_sedrst_out
+
+      INTEGER :: ji, jn, jn1
       !-------------------------------------------------------
 
-      WRITE(numsed,*) ' sed_init_nam : Read namelists '
-      WRITE(numsed,*) ' '
+      IF(lwp) WRITE(numsed,*) ' sed_init_nam : Read namelists '
+      IF(lwp) WRITE(numsed,*) ' '
 
       ! ryear = 1 year converted in second
       !------------------------------------
-      WRITE(numsed,*) ' '
-      WRITE(numsed,*) 'number of seconds in one year : ryear = ', ryear
-      WRITE(numsed,*) ' '     
+      IF (lwp) THEN
+         WRITE(numsed,*) ' '
+         WRITE(numsed,*) 'number of seconds in one year : ryear = ', ryear
+         WRITE(numsed,*) ' '     
+      ENDIF
 
       ! Reading namelist.sed variables
       !---------------------------------
-      CALL ctl_opn( numnamsed, 'namelist.sediment', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
-
-      dtsed = rdt
+      clname = 'namelist_sediment'
+      IF(lwp) WRITE(numsed,*) ' sed_init_nam : read SEDIMENT namelist'
+      IF(lwp) WRITE(numsed,*) ' ~~~~~~~~~~~~~~'
+      CALL ctl_opn( numnamsed_ref, TRIM( clname )//'_ref', 'OLD'    , 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+      CALL ctl_opn( numnamsed_cfg, TRIM( clname )//'_cfg', 'OLD'    , 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+
       nitsed000 = nittrc000
       nitsedend = nitend
-#if ! defined key_sed_off
-      nwrised   = nwritetrc
-#else
-      nwrised   = nwrite
-#endif
-     ! Diffraction/reaction parameters
-      !----------------------------------
-      READ( numnamsed, nam_time )
-      WRITE(numsed,*) ' namelist nam_time'
-
-#if ! defined key_sed_off
-      nfreq     = 1
-#endif
-
-      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,*) ' '
-
-      REWIND( numnamsed )               ! read nattrc
-      READ  ( numnamsed, nam_trased )
+      ! Namelist nam_run
+      REWIND( numnamsed_ref )              ! Namelist nam_run in reference namelist : Pisces variables
+      READ  ( numnamsed_ref, nam_run, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_run in reference namelist', lwp )
+
+      REWIND( numnamsed_cfg )              ! Namelist nam_run in reference namelist : Pisces variables
+      READ  ( numnamsed_cfg, nam_run, IOSTAT = ios, ERR = 902)
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_run in configuration namelist', lwp )
+
+      IF (lwp) THEN
+         WRITE(numsed,*) ' namelist nam_run'
+         WRITE(numsed,*) ' Nb of iterations for fast species    nrseddt = ', nrseddt
+         WRITE(numsed,*) ' 2-way coupling between PISCES and Sed ln_sed_2way = ', ln_sed_2way
+      ENDIF
+
+      REWIND( numnamsed_ref )              ! Namelist nam_geom in reference namelist : Pisces variables
+      READ  ( numnamsed_ref, nam_geom, IOSTAT = ios, ERR = 903)
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_geom in reference namelist', lwp )
+
+      REWIND( numnamsed_cfg )              ! Namelist nam_geom in reference namelist : Pisces variables
+      READ  ( numnamsed_cfg, nam_geom, IOSTAT = ios, ERR = 904)
+904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_geom in configuration namelist', lwp )
+
+      IF (lwp) THEN 
+         WRITE(numsed,*) ' namelist nam_geom'
+         WRITE(numsed,*) ' Number of vertical layers            jpksed  = ', jpksed
+         WRITE(numsed,*) ' Minimum vertical spacing             sedzmin = ', sedzmin
+         WRITE(numsed,*) ' Maximum depth of the sediment        sedhmax = ', sedhmax
+         WRITE(numsed,*) ' Default parameter                    sedkth  = ', sedkth
+         WRITE(numsed,*) ' Default parameter                    sedacr  = ', sedacr
+         WRITE(numsed,*) ' Sediment porosity at the surface     porsurf = ', porsurf
+         WRITE(numsed,*) ' Sediment porosity at infinite depth  porinf  = ', porinf
+         WRITE(numsed,*) ' Length scale of porosity variation   rhox    = ', rhox
+      ENDIF
+
+      jpksedm1  = jpksed - 1
+      dtsed = r2dttrc
+
+      REWIND( numnamsed_ref )              ! Namelist nam_trased in reference namelist : Pisces variables
+      READ  ( numnamsed_ref, nam_trased, IOSTAT = ios, ERR = 905)
+905   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_trased in reference namelist', lwp )
+
+      REWIND( numnamsed_cfg )              ! Namelist nam_trased in reference namelist : Pisces variables
+      READ  ( numnamsed_cfg, nam_trased, IOSTAT = ios, ERR = 906)
+906   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_trased in configuration namelist', lwp )
 
       DO jn = 1, jpsol
@@ -489,18 +516,24 @@
       END DO
 
-      WRITE(numsed,*) ' namelist nam_trased'
-      WRITE(numsed,*) ' '
-      DO jn = 1, jptrased
-         WRITE(numsed,*) 'name of 3d output sediment field number :',jn,' : ',TRIM(sedtrcd(jn))
-         WRITE(numsed,*) 'long name ', TRIM(sedtrcl(jn))
-         WRITE(numsed,*) ' in unit = ', TRIM(sedtrcu(jn))
-         WRITE(numsed,*) ' '
-      END DO
-      WRITE(numsed,*) ' '
-
+      IF (lwp) THEN
+         WRITE(numsed,*) ' namelist nam_trased'
+         WRITE(numsed,*) ' '
+         DO jn = 1, jptrased
+            WRITE(numsed,*) 'name of 3d output sediment field number :',jn,' : ',TRIM(sedtrcd(jn))
+            WRITE(numsed,*) 'long name ', TRIM(sedtrcl(jn))
+            WRITE(numsed,*) ' in unit = ', TRIM(sedtrcu(jn))
+            WRITE(numsed,*) ' '
+         END DO
+         WRITE(numsed,*) ' '
+      ENDIF
+
+      REWIND( numnamsed_ref )              ! Namelist nam_diased in reference namelist : Pisces variables
+      READ  ( numnamsed_ref, nam_diased, IOSTAT = ios, ERR = 907)
+907   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diased in reference namelist', lwp )
+
+      REWIND( numnamsed_cfg )              ! Namelist nam_diased in reference namelist : Pisces variables
+      READ  ( numnamsed_cfg, nam_diased, IOSTAT = ios, ERR = 908)
+908   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diased in configuration namelist', lwp )
       
-      REWIND( numnamsed )
-      READ( numnamsed, nam_diased )
-
       DO jn = 1, jpdia3dsed
          seddia3d(jn) = seddiag3d(jn)%snamesed
@@ -515,352 +548,144 @@
       END DO
 
-      WRITE(numsed,*) ' namelist nam_diased'
-      WRITE(numsed,*) ' '
-      DO jn = 1, jpdia3dsed
-         WRITE(numsed,*) 'name of 3D output diag number :',jn, ' : ', TRIM(seddia3d(jn))
-         WRITE(numsed,*) 'long name ', TRIM(seddia3l(jn))
-         WRITE(numsed,*) ' in unit = ',TRIM(seddia3u(jn))
-         WRITE(numsed,*) ' '
-      END DO
-
-      DO jn = 1, jpdia2dsed
-         WRITE(numsed,*) 'name of 2D output diag number :',jn, ' : ', TRIM(seddia2d(jn))
-         WRITE(numsed,*) 'long name ', TRIM(seddia2l(jn))
-         WRITE(numsed,*) ' in unit = ',TRIM(seddia2u(jn))
-         WRITE(numsed,*) ' '
-      END DO
-
-      WRITE(numsed,*) ' '
-
-
-      ! Diffraction/reaction parameters
+      IF (lwp) THEN
+         WRITE(numsed,*) ' namelist nam_diased'
+         WRITE(numsed,*) ' '
+         DO jn = 1, jpdia3dsed
+            WRITE(numsed,*) 'name of 3D output diag number :',jn, ' : ', TRIM(seddia3d(jn))
+            WRITE(numsed,*) 'long name ', TRIM(seddia3l(jn))
+            WRITE(numsed,*) ' in unit = ',TRIM(seddia3u(jn))
+            WRITE(numsed,*) ' '
+         END DO
+
+         DO jn = 1, jpdia2dsed
+            WRITE(numsed,*) 'name of 2D output diag number :',jn, ' : ', TRIM(seddia2d(jn))
+            WRITE(numsed,*) 'long name ', TRIM(seddia2l(jn))
+            WRITE(numsed,*) ' in unit = ',TRIM(seddia2u(jn))
+            WRITE(numsed,*) ' '
+         END DO
+
+         WRITE(numsed,*) ' '
+      ENDIF
+
+      ! Inorganic chemistry parameters
       !----------------------------------
-      REWIND( numnamsed )
-      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,*) ' '
-
+      REWIND( numnamsed_ref )              ! Namelist nam_inorg in reference namelist : Pisces variables
+      READ  ( numnamsed_ref, nam_inorg, IOSTAT = ios, ERR = 909)
+909   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_inorg in reference namelist', lwp )
+
+      REWIND( numnamsed_cfg )              ! Namelist nam_inorg in reference namelist : Pisces variables
+      READ  ( numnamsed_cfg, nam_inorg, IOSTAT = ios, ERR = 910)
+910   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_inorg in configuration namelist', lwp )
+
+      IF (lwp) THEN
+         WRITE(numsed,*) ' namelist nam_inorg'
+         WRITE(numsed,*) ' reactivity for Si      rcopal  = ', rcopal
+         WRITE(numsed,*) ' diff. coef for por.    dcoef   = ', dcoef
+         WRITE(numsed,*) ' reactivity for calcite rccal   = ', rccal
+         WRITE(numsed,*) ' L/C ratio in POC       ratligc = ', ratligc
+         WRITE(numsed,*) ' reactivity for ligands rcligc  = ', rcligc
+         WRITE(numsed,*) ' '
+      ENDIF
 
       ! 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
-
+      reac_sil   = rcopal / ryear     
+      reac_ligc  = rcligc / ryear
 
       ! Additional parameter linked to POC/O2/No3/Po4
       !----------------------------------------------
-      REWIND( numnamsed )
-      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]
+      REWIND( numnamsed_ref )              ! Namelist nam_poc in reference namelist : Pisces variables
+      READ  ( numnamsed_ref, nam_poc, IOSTAT = ios, ERR = 911)
+911   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_poc in reference namelist', lwp )
+
+      REWIND( numnamsed_cfg )              ! Namelist nam_poc in reference namelist : Pisces variables
+      READ  ( numnamsed_cfg, nam_poc, IOSTAT = ios, ERR = 912)
+912   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_poc in configuration namelist', lwp )
+
+      IF (lwp) THEN
+         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 carbon         redC     = ', redC
+         WRITE(numsed,*) ' Ration for iron bound P          redfep   = ', redfep
+         WRITE(numsed,*) ' reactivity for labile POC        rcorgl   = ', rcorgl
+         WRITE(numsed,*) ' reactivity for semi-refract. POC rcorgs   = ', rcorgs
+         WRITE(numsed,*) ' reactivity for refractory POC    rcorgr   = ', rcorgr
+         WRITE(numsed,*) ' reactivity for NH4               rcnh4    = ', rcnh4
+         WRITE(numsed,*) ' reactivity for H2S               rch2s    = ', rch2s
+         WRITE(numsed,*) ' reactivity for Fe2+              rcfe2    = ', rcfe2
+         WRITE(numsed,*) ' reactivity for FeOH/H2S          rcfeh2s  = ', rcfeh2s
+         WRITE(numsed,*) ' reactivity for Fe2+/H2S          rcfes    = ', rcfes
+         WRITE(numsed,*) ' reactivity for FeS/O2            rcfeso   = ', rcfeso
+         WRITE(numsed,*) ' Half-sat. cste for oxic remin    xksedo2  = ', xksedo2
+         WRITE(numsed,*) ' Half-sat. cste for denit.        xksedno3 = ', xksedno3
+         WRITE(numsed,*) ' Half-sat. cste for iron remin    xksedfeo = ', xksedfeo
+         WRITE(numsed,*) ' Half-sat. cste for SO4 remin     xksedso4 = ', xksedso4
+         WRITE(numsed,*) ' '
+      ENDIF
+
+
+      so2ut  = redO2    / redC
+      srno3  = redNo3   / redC
+      spo4r  = redPo4   / redC
+      srDnit = ( (redO2 + 32. ) * 0.8 - redNo3 - redNo3 * 0.6 ) / redC
       ! 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,*) ' '
+      reac_pocl  = rcorgl / ryear
+      reac_pocs  = rcorgs / ryear
+      reac_pocr  = rcorgr / ryear
+      reac_nh4   = rcnh4  / ryear
+      reac_h2s   = rch2s  / ryear
+      reac_fe2   = rcfe2  / ryear
+      reac_feh2s = rcfeh2s/ ryear
+      reac_fes   = rcfes  / ryear
+      reac_feso  = rcfeso / ryear
 
       ! 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. )
+      REWIND( numnamsed_ref )              ! Namelist nam_btb in reference namelist : Pisces variables
+      READ  ( numnamsed_ref, nam_btb, IOSTAT = ios, ERR = 913)
+913   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_btb in reference namelist', lwp )
+
+      REWIND( numnamsed_cfg )              ! Namelist nam_btb in reference namelist : Pisces variables
+      READ  ( numnamsed_cfg, nam_btb, IOSTAT = ios, ERR = 914)
+914   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_btb in configuration namelist', lwp )
+
+      IF (lwp) THEN
+         WRITE(numsed,*) ' namelist nam_btb ' 
+         WRITE(numsed,*) ' coefficient for bioturbation      dbiot    = ', dbiot
+         WRITE(numsed,*) ' Depth varying bioturbation        ln_btbz  = ', ln_btbz
+         WRITE(numsed,*) ' coefficient for btb attenuation   dbtbzsc  = ', dbtbzsc
+         WRITE(numsed,*) ' Adsorption coefficient of NH4     adsnh4   = ', adsnh4
+         WRITE(numsed,*) ' Bioirrigation in sediment         ln_irrig = ', ln_irrig
+         WRITE(numsed,*) ' coefficient for irrig attenuation xirrzsc  = ', xirrzsc
+         WRITE(numsed,*) ' '
+      ENDIF
 
       ! 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 )
+      REWIND( numnamsed_ref )              ! Namelist nam_rst in reference namelist : Pisces variables
+      READ  ( numnamsed_ref, nam_rst, IOSTAT = ios, ERR = 915)
+915   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_rst in reference namelist', lwp )
+
+      REWIND( numnamsed_cfg )              ! Namelist nam_rst in reference namelist : Pisces variables
+      READ  ( numnamsed_cfg, nam_rst, IOSTAT = ios, ERR = 916)
+916   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_rst in configuration namelist', lwp )
+
+      IF (lwp) THEN
+         WRITE(numsed,*) ' namelist  nam_rst ' 
+         WRITE(numsed,*) '  boolean term for restart (T or F) ln_rst_sed = ', ln_rst_sed 
+         WRITE(numsed,*) ' '
+      ENDIF
+      nn_dtsed = nn_dttrc
+
+      CLOSE( numnamsed_cfg )
+      CLOSE( numnamsed_ref )
 
    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 (umol/l) for silicic Acid and "dissolved" clay'
-      WRITE(numsed,'(2(F0.2,3X))') sat_sil * 1e+6,  sat_clay * 1e+6
-      WRITE(numsed,*)'reaction rate rc for Op/si,Clay,POC/O2,caco3, POC/No3 (an-1)'
-      WRITE(numsed,'(5(F0.2,3X))') reac_sil * ryear, reac_clay * ryear, reac_poc * ryear, &
-                                   reac_cal * ryear, reac_no3 * ryear
-      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
-   !!----------------------------------------------------------------------
-   !! $Id$
-CONTAINS
-   SUBROUTINE sed_ini              ! Empty routine
-   END SUBROUTINE sed_ini
-#endif
-
-
 END MODULE sedini
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedinitrc.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedinitrc.F90	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedinitrc.F90	(revision 10345)
@@ -0,0 +1,192 @@
+MODULE sedinitrc
+   !!======================================================================
+   !!              ***  MODULE  sedinitrc  ***
+   !! Sediment : define sediment variables
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   sed_init    : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE sed     ! sediment global variable
+   USE sed_oce
+   USE sedini
+   USE seddta
+   USE sedrst
+   USE sedco3
+   USE sedchem
+   USE sedarr
+   USE lib_mpp         ! distribued memory computing library
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   REAL(wp)    ::  &
+      ryear = 365. * 24. * 3600. !:  1 year converted in second
+
+   !! *  Routine accessibility
+   PUBLIC sed_initrc          ! routine called by opa.F90
+
+   !! $Id: sedini.F90 5215 2015-04-15 16:11:56Z nicolasmartin $
+CONTAINS
+
+
+   SUBROUTINE sed_initrc
+      !!----------------------------------------------------------------------
+      !!                   ***  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
+      !!----------------------------------------------------------------------
+
+
+      ! Initialize the sediment tracers concentrations
+      !------------------------------------------------
+
+      IF(lwp) WRITE(numsed,*) ' sed_initrc : Initialization of sediment concentration '
+      IF(lwp) WRITE(numsed,*) ' '
+
+      ! Determination of sediments number of points and allocate global variables
+
+      ! sets initial sediment composition
+      ! ( only clay or reading restart file )
+      !---------------------------------------
+      CALL sed_init_data
+
+
+      CALL sed_init_wri
+
+
+   END SUBROUTINE sed_initrc
+
+
+   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
+
+         IF (lwp) 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.0 * 0.965
+         solcp(:,2:jpksed,jsfeo)  = 1.0 * 0.035
+
+         ! Initialization of [h+] and [co3--]
+
+         zhipor = 8.0
+         ! Initialization of [h+] in mol/kg
+         DO jk = 1, jpksed
+            DO ji = 1, jpoce
+               hipor (ji,jk) = 10.**( -1. * zhipor )
+            ENDDO
+         ENDDO
+
+         co3por(:,:) = 1E-6
+
+      ELSE   
+  
+         IF (lwp) WRITE(numsed,*) ' Initilization of Sediment components from restart'
+
+         CALL sed_rst_cal( nitsed000, 'READ' )
+         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
+
+      IF (lwp) THEN
+         WRITE(numsed,*)' '
+         WRITE(numsed,*)'======== Write summary of sediment char.  ============'
+         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, jpksed : ',jpi, jpj, jpksed
+         WRITE(numsed,*)'jpoce = ',jpoce,' nbtot pts = ',jpij,' nb earth pts = ',jpij - jpoce
+         WRITE(numsed,*)'sublayer thickness dz(1) [cm] : ', dz(1)
+         WRITE(numsed,*)'Vertical domain of the sediment'
+         WRITE(numsed,*)'-------------------------------'
+         WRITE(numsed,*)' Indice, profsed, dz'
+         DO jk = 2, jpksed
+            WRITE(numsed,*) jk,profsed(jk),dz(jk) 
+         END DO
+         WRITE(numsed,*)' nb solid comp : ',jpsol
+         WRITE(numsed,*)'(1=opal,2=clay,3=POC,4=CaCO3), 5=POS, 6=POR, 7=FEO, 8=FeS'
+         WRITE(numsed,*)'weight mol 1,2,3,4,5,6,7'
+         WRITE(numsed,'(8(F0.2,3X))')mol_wgt(jsopal),mol_wgt(jsclay),mol_wgt(jspoc),mol_wgt(jscal),mol_wgt(jspos),mol_wgt(jspor),mol_wgt(jsfeo),mol_wgt(jsfes)
+         WRITE(numsed,*)'nb dissolved comp',jpwat
+         WRITE(numsed,*)'1=silicic acid,,2=O2,3=DIC,4=NO3,5=PO4,6=Alk,7=NH4,8=ODU'
+         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,*) ' '
+         WRITE(numsed,*) ' End Of Initialization '
+         WRITE(numsed,*) ' '
+      ENDIF
+!
+   END SUBROUTINE sed_init_wri
+
+END MODULE sedinitrc
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedinorg.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedinorg.F90	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedinorg.F90	(revision 10345)
@@ -0,0 +1,300 @@
+MODULE sedinorg
+   !!======================================================================
+   !!              ***  MODULE  sedinorg  ***
+   !!    Sediment : dissolution and reaction in pore water of 
+   !!               inorganic species
+   !!=====================================================================
+   !! * Modules used
+   USE sed     ! sediment global variable
+   USE sed_oce
+   USE sedmat  ! linear system of equations
+   USE sedco3  ! carbonate ion and proton concentration 
+   USE sedini
+   USE seddsr
+   USE lib_mpp         ! distribued memory computing library
+   USE lib_fortran
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC sed_inorg
+
+   !! $Id: seddsr.F90 5215 2015-04-15 16:11:56Z nicolasmartin $
+CONTAINS
+   
+   SUBROUTINE sed_inorg( kt ) 
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_inorg  ***
+      !! 
+      !!  ** 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
+      !!        !  19-08 (O. Aumont) Debugging and improvement of the model
+      !!----------------------------------------------------------------------
+      !! Arguments
+      INTEGER, INTENT(in) ::   kt       ! number of iteration
+      ! --- local variables
+      INTEGER :: ji, jk, js, jw         ! dummy looop indices
+      REAL(wp), DIMENSION(jpoce,jpksed) :: zrearat1, zrearat2    ! reaction rate in pore water
+      REAL(wp), DIMENSION(jpoce,jpksed) :: zundsat    ! undersaturation ; indice jpwatp1 is for calcite   
+      REAL(wp), DIMENSION(jpoce) :: zco3eq
+      REAL(wp), DIMENSION(jpoce,jpksed,jpsol) :: zvolc    ! temp. variables
+      REAL(wp), DIMENSION(jpoce) :: zsieq
+      REAL(wp)  ::  zsolid1, zvolw, zreasat
+      REAL(wp)  ::  zsatur, zsatur2, znusil, zsolcpcl, zsolcpsi
+      !!
+      !!----------------------------------------------------------------------
+
+      IF( ln_timing )  CALL timing_start('sed_inorg')
+!
+      IF( kt == nitsed000 ) THEN
+         IF (lwp) THEN
+            WRITE(numsed,*) ' sed_inorg : Dissolution reaction '
+            WRITE(numsed,*) ' '
+         ENDIF
+!         ! 
+      ENDIF
+
+     ! Initializations
+     !----------------------
+      
+      zrearat1(:,:) = 0.    ;   zundsat(:,:)  = 0. 
+      zrearat2(:,:) = 0.    ;   zrearat2(:,:) = 0.
+      zco3eq(:)     = rtrn
+      zvolc(:,:,:)  = 0.
+
+      ! -----------------------------------------------
+      ! Computation of Si solubility
+      ! Param of Ridgwell et al. 2002
+      ! -----------------------------------------------
+
+      DO ji = 1, jpoce
+         zsolcpcl = 0.0
+         zsolcpsi = 0.0
+         DO jk = 1, jpksed
+            zsolcpsi = zsolcpsi + solcp(ji,jk,jsopal) * dz(jk)
+            zsolcpcl = zsolcpcl + solcp(ji,jk,jsclay) * dz(jk)
+         END DO
+         zsieq(ji) = sieqs(ji) * MAX(0.25, 1.0 - (0.045 * zsolcpcl / zsolcpsi )**0.58 )
+         zsieq(ji) = MAX( rtrn, sieqs(ji) )
+      END DO
+
+      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
+
+      !----------------------------------------------------------
+      ! 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
+      !-------------------------------------------------------------------------
+
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            ! For Silicic Acid and clay
+            zundsat(ji,jk) = zsieq(ji) - pwcp(ji,jk,jwsil)
+         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
+         zrearat1(ji,:) = 0.
+         zrearat2(ji,:) = 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)
+            zsatur = MAX(0., zundsat(ji,jk) / zsieq(ji) )
+            zsatur2 = (1.0 + temp(ji) / 400.0 )**37
+            znusil = ( 0.225 * ( 1.0 + temp(ji) / 15.) + 0.775 * zsatur2 * zsatur**2.25 ) / zsieq(ji)
+            zrearat1(ji,jk)  = ( reac_sil * znusil * dtsed * zsolid1 ) / &
+               &                ( 1. + reac_sil * znusil * dtsed * zundsat(ji,jk) )
+         ENDDO
+      ENDDO
+
+      CALL sed_mat( jwsil, jpoce, jpksed, zrearat1, zrearat2, zundsat, dtsed )
+
+      ! New solid concentration values (jk=2 to jksed) for each couple 
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zreasat = zrearat1(ji,jk) * zundsat(ji,jk) / ( zvolc(ji,jk,jsopal) )
+            solcp(ji,jk,jsopal) = solcp(ji,jk,jsopal) - zreasat
+         ENDDO
+      ENDDO
+
+      ! New pore water concentrations    
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            ! Acid Silicic 
+            pwcp(ji,jk,jwsil)  = zsieq(ji) - zundsat(ji,jk)
+         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 )
+
+      ! *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
+            zco3eq(ji)     = aksps(ji) * densSW(ji) * densSW(ji) / ( calcon2(ji) + rtrn )
+            zco3eq(ji)     = MAX( rtrn, zco3eq(ji) ) 
+            zundsat(ji,jk) = MAX(0., zco3eq(ji) - co3por(ji,jk) )
+         ENDDO
+      ENDDO
+
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zsolid1 = zvolc(ji,jk,jscal) * solcp(ji,jk,jscal)
+            zrearat1(ji,jk) = ( reac_cal * dtsed * zsolid1 / zco3eq(ji) ) / &
+                  &               ( 1. + reac_cal * dtsed * zundsat(ji,jk) / zco3eq(ji) )
+         END DO
+      END DO
+
+      ! solves tridiagonal system
+      CALL sed_mat( jwdic, jpoce, jpksed, zrearat1, zrearat2, zundsat, dtsed )
+
+      ! New solid concentration values (jk=2 to jksed) for cacO3
+      DO jk = 2, jpksed
+         DO ji = 1, jpoce
+            zreasat = zrearat1(ji,jk) * zundsat(ji,jk) / 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 = zrearat1(ji,jk) * zundsat(ji,jk)    
+            ! For DIC
+            pwcp(ji,jk,jwdic)  = pwcp(ji,jk,jwdic) + zreasat
+            ! For alkalinity
+            pwcp(ji,jk,jwalk)  = pwcp(ji,jk,jwalk) + 2.0 * zreasat 
+         ENDDO
+      ENDDO
+
+      !-------------------------------------------------
+      ! Beginning DIC, Alkalinity 
+      !-------------------------------------------------
+      
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce      
+            zundsat(ji,jk)   = pwcp(ji,jk,jwdic)
+            zrearat1(ji,jk)  = 0.
+         ENDDO
+      ENDDO
+
+      ! solves tridiagonal system
+      CALL sed_mat( jwdic, jpoce, jpksed, zrearat1, zrearat2, zundsat, dtsed )
+
+     ! New dissolved concentrations      
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce                      
+            pwcp(ji,jk,jwdic) = zundsat(ji,jk)
+         ENDDO
+      ENDDO            
+
+      !-------------------------------------------------
+      ! Beginning DIC, Alkalinity 
+      !-------------------------------------------------
+
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zundsat(ji,jk) = pwcp(ji,jk,jwalk)
+            zrearat1(ji,jk) = 0.
+         ENDDO
+      ENDDO
+!
+!      ! solves tridiagonal system
+      CALL sed_mat( jwalk, jpoce, jpksed, zrearat1, zrearat2, zundsat, dtsed )
+!
+!      ! New dissolved concentrations      
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            pwcp(ji,jk,jwalk) = zundsat(ji,jk)
+         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
+
+      IF( ln_timing )  CALL timing_stop('sed_inorg')
+!      
+   END SUBROUTINE sed_inorg
+
+END MODULE sedinorg
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedmat.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedmat.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedmat.F90	(revision 10345)
@@ -1,4 +1,3 @@
 MODULE sedmat
-#if defined key_sed
    !!======================================================================
    !!              ***  MODULE  sedmat  ***
@@ -9,4 +8,6 @@
 
    USE sed     ! sediment global variable
+   USE lib_mpp         ! distribued memory computing library
+
 
    IMPLICIT NONE
@@ -25,5 +26,5 @@
  CONTAINS
 
-    SUBROUTINE sed_mat_dsr( nvar, ndim, nlev, preac, psol )
+    SUBROUTINE sed_mat_dsr( nvar, ndim, nlev, preac, psms, psol, dtsed_in )
        !!---------------------------------------------------------------------
        !!                  ***  ROUTINE sed_mat_dsr  ***
@@ -48,10 +49,12 @@
        !!----------------------------------------------------------------------
        !! * Arguments
-       INTEGER , INTENT(in) ::  nvar  ! number of variables
+       INTEGER , INTENT(in) ::  nvar  ! number of variable
        INTEGER , INTENT(in) ::  ndim  ! number of points
        INTEGER , INTENT(in) ::  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 )
+       REAL(wp), DIMENSION(ndim,nlev), INTENT(in   ) :: preac  ! reaction rates
+       REAL(wp), DIMENSION(ndim,nlev), INTENT(in   ) :: psms  ! reaction rates
+       REAL(wp), DIMENSION(ndim,nlev), INTENT(inout) :: psol   ! solution ( undersaturation values )
+       REAL(wp), INTENT(in) ::  dtsed_in
  
        !---Local declarations
@@ -67,4 +70,5 @@
        !----------------------------------------------------------------------
 
+       IF( ln_timing )  CALL timing_start('sed_mat_dsr')
 
        ! Computation left hand side of linear system of 
@@ -73,10 +77,11 @@
 
 
+       jn = nvar
        ! first sediment level          
        DO ji = 1, ndim
-          aplus  = ( ( volw3d(ji,1) / dz3d(ji,1) ) + &
-                     ( volw3d(ji,2) / dz3d(ji,2) ) ) / 2.
+          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 
+          rplus  = ( dtsed_in / ( volw3d(ji,1) ) ) * diff(ji,1,jn) * aplus / dxplus 
 
           za(ji,1) = 0.
@@ -87,15 +92,15 @@
        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.
+             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.
+             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
-             !     
+                !
+             rminus  = ( dtsed_in / volw3d(ji,jk) ) * diff(ji,jk-1,jn) * aminus / dxminus
+             rplus   = ( dtsed_in / volw3d(ji,jk) ) * diff(ji,jk,jn)   * aplus / dxplus
+                !     
              za(ji,jk) = -rminus
              zb(ji,jk) = 1. + rminus + rplus 
@@ -105,8 +110,8 @@
 
        DO ji = 1, ndim
-          aminus  = ( ( volw3d(ji,nlev-1) / dz3d(ji,nlev-1) ) + &
-             &        ( volw3d(ji,nlev)  / dz3d(ji,nlev) ) ) / 2.
+          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
+          rminus  = ( dtsed_in / volw3d(ji,nlev) ) * diff(ji,nlev-1,jn) * aminus / dxminus
           !
           za(ji,nlev) = -rminus
@@ -119,31 +124,30 @@
        ! -----------------------------------------------
 
-       DO jn = 1, nvar
-
-          zr  (:,:)    = psol(:,:,jn)
-          zbet(:  )    = zb(:,1) + preac(:,1,jn)
-          psol(:,1,jn) = zr(:,1) / zbet(:)
+       zr  (:,:) = psol(:,:) + psms(:,:)
+       zb  (:,:) = zb(:,:) + preac(:,:)
+       zbet(:  ) = zb(:,1)
+       psol(:,1) = 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 = 2, nlev
+          DO ji = 1, ndim
+             zgamm(ji,jk) =  zc(ji,jk-1) / zbet(ji)
+             zbet(ji)     =  zb(ji,jk) - za(ji,jk) * zgamm(ji,jk)
+             psol(ji,jk)  = ( zr(ji,jk) - za(ji,jk) * psol(ji,jk-1) ) / 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
-
+       DO jk = nlev - 1, 1, -1
+          DO ji = 1,ndim
+             psol(ji,jk) = psol(ji,jk) - zgamm(ji,jk+1) * psol(ji,jk+1)
+          END DO
        ENDDO
 
+       IF( ln_timing )  CALL timing_stop('sed_mat_dsr')
+
 
     END SUBROUTINE sed_mat_dsr
 
-    
-    SUBROUTINE sed_mat_btb( nvar, ndim, nlev, psol )
+    SUBROUTINE sed_mat_btb( nvar, ndim, nlev, psol, dtsed_in )
        !!---------------------------------------------------------------------
        !!                  ***  ROUTINE sed_mat_btb  ***
@@ -170,4 +174,6 @@
           psol      ! solution
 
+      REAL(wp), INTENT(in) :: dtsed_in
+
        !---Local declarations
        INTEGER  ::  &
@@ -192,76 +198,68 @@
 
 
+      IF( ln_timing )  CALL timing_start('sed_mat_btb')
+
        ! 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 ji = 1, ndim
+         aplus  = ( ( vols(2) / dz(2) ) + ( vols(3) / dz(3) ) ) / 2.
+         dxplus = ( dz(2) + dz(3) ) / 2.
+         rplus  = ( dtsed_in / vols(2) ) * db(ji,2) * 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
+         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_in / vols(jk+1) ) * db(ji,jk) * 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_in / vols(jk+1) ) * db(ji,jk+1) * 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_in / vols(nlev+1) ) * db(ji,nlev) * aminus / dxminus
+         !
+         za(nlev) = -rminus
+         zb(nlev) = 1. + rminus
+         zc(nlev) = 0.
+
+
+         ! solves tridiagonal system of linear equations 
+         ! -----------------------------------------------    
+         DO jn = 1, nvar
+          
+            DO jk = 1, nlev
+               zr  (ji,jk)    = psol(ji,jk,jn)
+            END DO
+            zbet          = zb(1)
+            psol(ji,1,jn) = zr(ji,1) / zbet
+            ! 
+            DO jk = 2, nlev
+               zgamm(jk) =  zc(jk-1) / zbet
+               zbet      =  zb(jk) - za(jk) * zgamm(jk)
+               psol(ji,jk,jn) = ( zr(ji,jk) - za(jk) * psol(ji,jk-1,jn) ) / zbet
+            ENDDO
+            ! 
+            DO jk = nlev - 1, 1, -1
+                psol(ji,jk,jn) = psol(ji,jk,jn) - zgamm(jk+1) * psol(ji,jk+1,jn)
+            ENDDO
+
+         ENDDO
+
+       END DO
        !
- 
-       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
+       IF( ln_timing )  CALL timing_stop('sed_mat_btb')
 
        
     END SUBROUTINE sed_mat_btb
 
-
-#else
-   !!======================================================================
-   !! MODULE sedmat  :   Dummy module 
-   !!======================================================================
-   !! $Id$
-CONTAINS
-   SUBROUTINE sed_mat         ! Empty routine
-   END SUBROUTINE sed_mat
-   !!======================================================================
-#endif
-
  END MODULE sedmat
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedmbc.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedmbc.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedmbc.F90	(revision 10345)
@@ -1,4 +1,3 @@
 MODULE sedmbc
-#if defined key_sed
    !!======================================================================
    !!              ***  MODULE  sedmbc  ***
@@ -12,4 +11,5 @@
    USE sed     ! sediment global variable
    USE seddsr
+   USE lib_mpp         ! distribued memory computing library
 
    IMPLICIT NONE
@@ -27,12 +27,4 @@
    REAL(wp), DIMENSION(jpwat) :: diss_in_tot   ! total input in pore water
    REAL(wp), DIMENSION(jpwat) :: diss_out_tot  ! total output from pore water
-
-   REAL(wp)  :: cons_tot_o2                   ! cumulative o2 consomation
-   REAL(wp)  :: sour_tot_no3                  ! cumulative no3 source
-   REAL(wp)  :: cons_tot_no3                  ! cumulative no3 consomation
-   REAL(wp)  :: sour_tot_c13                  ! cumulative o2 source
-
-   REAL(wp)  :: src13p  
-   REAL(wp)  :: src13ca  
 
    !! $Id$
@@ -67,16 +59,13 @@
       REAL, DIMENSION(jpwat) :: zpwcp_inv_i, zpwcp_inv_f
       REAL(wp) ::  zdelta_sil, zdelta_clay
-      REAL(wp) ::  zdelta_co2, zdelta_oxy
+      REAL(wp) ::  zdelta_co2, zdelta_fe
       REAL(wp) ::  zdelta_po4, zdelta_no3
-      REAL(wp) ::  zdelta_c13, zdelta_c13b
 
       !!----------------------------------------------------------------------
       ! Initilization
       !---------------
+      IF( ln_timing )  CALL timing_start('sed_mbc')
+!
       IF( kt == nitsed000 ) THEN
-         cons_tot_o2  = 0.
-         sour_tot_no3 = 0.
-         cons_tot_no3 = 0.
-         sour_tot_c13 = 0.
 
          DO js = 1, jpsol
@@ -92,6 +81,4 @@
          ENDDO
 
-         src13p  = rc13P  * pdb
-         src13ca = rc13Ca * pdb
       ENDIF
 
@@ -106,8 +93,8 @@
             ! input [mol]
             rain_tot   (js) = rain_tot   (js) + dtsed * rainrm_dta(ji,js)
-            fromsed_tot(js) = fromsed_tot(js) + fromsed(ji,js)
+            fromsed_tot(js) = fromsed_tot(js) + fromsed(ji,js) / mol_wgt(js)
             ! output [mol]
-            tosed_tot  (js) = tosed_tot (js) + tosed(ji,js)
-            rloss_tot  (js) = rloss_tot (js) + rloss(ji,js)
+            tosed_tot  (js) = tosed_tot (js) + tosed(ji,js) / mol_wgt(js)
+            rloss_tot  (js) = rloss_tot (js) + rloss(ji,js) / mol_wgt(js)
          ENDDO
       ENDDO
@@ -122,13 +109,4 @@
          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
@@ -141,5 +119,5 @@
          zpwcp_inv_f (:) = 0.        
          DO js = 1, jpsol
-            zdsw = dens / mol_wgt(js)
+            zdsw = denssol / mol_wgt(js)
             DO jk = 2, jpksed
                DO ji = 1, jpoce
@@ -178,52 +156,36 @@
 
          ! 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) 
+         zinit      = zsolcp_inv_i(jspoc) + zsolcp_inv_i(jspos) + zsolcp_inv_i(jspor) &
+         &          + zsolcp_inv_i(jscal) + zpwcp_inv_i(jwdic)
+         zfinal     = zsolcp_inv_f(jspoc) + zsolcp_inv_f(jspos) + zsolcp_inv_f(jspor) &
+         &          + zsolcp_inv_f(jscal) + zpwcp_inv_f(jwdic)
+         zinput     = rain_tot (jspoc) + rain_tot   (jspos)  +  rain_tot   (jspor) &
+         &          + rain_tot (jscal) + diss_in_tot(jwdic)
+         zoutput    = tosed_tot(jspoc) + tosed_tot(jspos) + tosed_tot(jspor) + tosed_tot(jscal) + diss_out_tot(jwdic) &
+            &       + rloss_tot(jspoc) + rloss_tot(jspos) + rloss_tot(jspor) + 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
+         ! mass balance for Sulfur
+         zinit      = zpwcp_inv_i(jwso4) + zpwcp_inv_i(jwh2s)   &
+         &          + zsolcp_inv_i(jsfes) 
+         zfinal     = zpwcp_inv_f(jwso4) + zpwcp_inv_f(jwh2s)   &
+         &          + zsolcp_inv_f(jsfes)
+         zinput     = diss_in_tot (jwso4) + diss_in_tot (jwh2s) &
+         &          + rain_tot (jsfes)
+         zoutput    = diss_out_tot(jwso4) + diss_out_tot(jwh2s) &
+         &          + tosed_tot(jsfes)    + rloss_tot(jsfes)
          zdelta_no3 = ( zfinal + zoutput ) - ( zinit + zinput )
 
-         ! mass balance for DIC13
-         zinit      =  zpwcp_inv_i(jwc13)   &
-            &        + src13p * zsolcp_inv_i(jspoc) + src13Ca * zsolcp_inv_i(jscal) 
-         zfinal     =  zpwcp_inv_f(jwc13)   &
-            &        + src13p * zsolcp_inv_f(jspoc) + src13Ca * zsolcp_inv_f(jscal)
-         zinput     =  diss_in_tot (jwc13)  &
-            &        + src13p * rain_tot(jspoc) + src13Ca * rain_tot(jscal)
-         zoutput    =  diss_out_tot(jwc13)  &
-            &        + src13p * tosed_tot(jspoc) + src13Ca * tosed_tot(jscal) &   
-            &        + 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 )    
+         ! mass balance for iron
+         zinit      = zpwcp_inv_i(jwfe2)  + zsolcp_inv_i(jsfeo)   &
+         &          + zsolcp_inv_i(jsfes)
+         zfinal     = zpwcp_inv_f(jwfe2)  + zsolcp_inv_f(jsfeo)   &
+         &          + zsolcp_inv_f(jsfes)
+         zinput     = diss_in_tot (jwfe2) + rain_tot (jsfeo) &
+         &          + rain_tot (jsfes)
+         zoutput    = diss_out_tot(jwfe2) + tosed_tot(jsfeo) &
+         &          + tosed_tot(jsfes)    + rloss_tot(jsfes) + rloss_tot(jsfeo)
+         zdelta_fe  = ( zfinal + zoutput ) - ( zinit + zinput )
+
 
       END IF
@@ -231,91 +193,65 @@
       IF( kt == nitsedend) THEN 
 
+         IF (lwp) 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,*)' Initial total solid Masses (mole/dx.dy)        '
          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,*)'    Opal,      Clay,       POC,       POS,      POR,        CaCO3,     FeOH,     FeS'
+         WRITE(numsed,'(8x,4(1PE10.3,2X))')zsolcp_inv_i(jsopal),zsolcp_inv_i(jsclay),zsolcp_inv_i(jspoc), &
+            & zsolcp_inv_i(jspos),zsolcp_inv_i(jspor),zsolcp_inv_i(jscal),zsolcp_inv_i(jsfeo),zsolcp_inv_i(jsfes)
+         WRITE(numsed,*)' '
+         WRITE(numsed,*)' Initial total dissolved Masses (mole/dx.dy)    '
          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,*)'    Si,         O2,         DIC,        Nit,         Phos,         Fe2+'
+         WRITE(numsed,'(5x,5(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(jwfe2)
+         WRITE(numsed,*)' '
+         WRITE(numsed,*)'  Solid inputs :  Opale,      Clay,       POC,        CaCO3,        Fe'
+         WRITE(numsed,'(A4,10X,5(1PE10.3,2X))')'Rain : ',rain_tot(jsopal),rain_tot(jsclay),rain_tot(jspoc) + rain_tot(jspos) + rain_tot(jspor),&
+            & rain_tot(jscal), rain_tot(jsfeo)
+         WRITE(numsed,'(A12,6x,5(1PE10.3,2X))')' From Sed : ',fromsed_tot(jsopal), fromsed_tot(jsclay), &
+            & fromsed_tot(jspoc)+fromsed_tot(jspos)+fromsed_tot(jspor), fromsed_tot(jscal),    &
+            & fromsed_tot(jsfeo) + fromsed_tot(jsfes)
+         WRITE(numsed,*)'Diss. inputs : Si,    O2,         DIC,         Nit,       Phos,      Fe'
          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 '  
+            & diss_in_tot(jwoxy), diss_in_tot(jwdic), diss_in_tot(jwno3), diss_in_tot(jwpo4), diss_in_tot(jwfe2)
+         WRITE(numsed,*)' '
+         WRITE(numsed,*)'Solid output : Opale,      Clay,       POC,        CaCO3,        Fe'
+         WRITE(numsed,'(A6,8x,5(1PE10.3,2X))')'To sed', tosed_tot(jsopal),tosed_tot(jsclay),tosed_tot(jspoc) &
+            & +tosed_tot(jspos)+tosed_tot(jspor),tosed_tot(jscal), tosed_tot(jsfeo)+tosed_tot(jsfes)
+         WRITE(numsed,'(A5,9x,5(1PE10.3,2X))')'Perdu', rloss_tot(jsopal),rloss_tot(jsclay),rloss_tot(jspoc) &
+            & +rloss_tot(jspos)+rloss_tot(jspor),rloss_tot(jscal),rloss_tot(jsfeo)+rloss_tot(jsfes)
+         WRITE(numsed,*)'Diss. output : Si,     O2,        DIC,          Nit,       Phos,        Fe '  
          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) )
+            & diss_out_tot(jwoxy), diss_out_tot(jwdic), diss_out_tot(jwno3), diss_out_tot(jwpo4), diss_out_tot(jwfe2)
+         WRITE(numsed,*)' '
+         WRITE(numsed,*)'Final solid  Masses (mole/dx.dy) '
+         WRITE(numsed,*)'    Opale,      Clay,       POC,        CaCO3,      Fe'
+         WRITE(numsed,'(4x,5(1PE10.3,2X))')zsolcp_inv_f(jsopal),zsolcp_inv_f(jsclay),zsolcp_inv_f(jspoc)  &
+            & +zsolcp_inv_f(jspos)+zsolcp_inv_f(jspor),zsolcp_inv_f(jscal),zsolcp_inv_f(jsfeo)+zsolcp_inv_f(jsfes)
          WRITE(numsed,*)' '
          WRITE(numsed,*)'Final dissolved  Masses (mole/dx.dy) (k=2-11)'
-         WRITE(numsed,*)'    Si,        O2,         DIC,        Nit,        Phos,    DIC13'
+         WRITE(numsed,*)'    Si,        O2,         DIC,        Nit,        Phos,        Fe'
          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)
+            & zpwcp_inv_f(jwdic), zpwcp_inv_f(jwno3), zpwcp_inv_f(jwpo4), zpwcp_inv_f(jwfe2)
          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,*)'Delta : Opale,      Clay,       C,         Fe,          S,'
+         WRITE(numsed,'(7x,6(1PE11.3,1X))') zdelta_sil / ( zsolcp_inv_i(jsopal) + zpwcp_inv_i(jwsil) ) , &
+         &            zdelta_clay / ( zsolcp_inv_i(jsclay) ) ,      & 
+         &            zdelta_co2 / ( zsolcp_inv_i(jspoc) + zsolcp_inv_i(jspos) + zsolcp_inv_i(jspor) &
+         &          + zsolcp_inv_i(jscal) + zpwcp_inv_i(jwdic) ),     &
+         &            zdelta_fe / ( zpwcp_inv_i(jwfe2) + zsolcp_inv_i(jsfeo) + zsolcp_inv_i(jsfes) ) ,  &
+         &            zdelta_no3 / ( zpwcp_inv_i(jwso4) + zpwcp_inv_i(jwh2s) + zsolcp_inv_i(jsfes) )
          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
+      ENDIF
+
+      IF( ln_timing )  CALL timing_stop('sed_mbc')
   
    END SUBROUTINE sed_mbc
 
-
-#else
-   !!======================================================================
-   !! MODULE sedmbc :   Dummy module 
-   !!======================================================================
-   !! $Id$
-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: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedmodel.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedmodel.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedmodel.F90	(revision 10345)
@@ -1,4 +1,3 @@
 MODULE sedmodel
-#if defined key_sed
    !!======================================================================
    !!                       ***  MODULE sedmodel   ***
@@ -6,6 +5,6 @@
    !!======================================================================
    USE sed
-   USE sedini   ! sediment variables initialization
    USE sedstp   ! time stepping
+   USE sedinitrc
 
    IMPLICIT NONE
@@ -33,21 +32,12 @@
 
 
-      IF( kt == nittrc000 ) CALL sed_init       ! Initialization of sediment model
+      IF( ln_timing )  CALL timing_start('sed_model')
 
-                         CALL sed_stp( kt )  ! Time stepping of Sediment model
+      IF( kt == nittrc000 ) CALL sed_initrc       ! Initialization of sediment model
+                            CALL sed_stp( kt )  ! Time stepping of Sediment model
 
+      IF( ln_timing )  CALL timing_stop('sed_model')
 
    END SUBROUTINE sed_model
 
-#else
-   !!======================================================================
-   !! MODULE sedmodel  :   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: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedorg.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedorg.F90	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedorg.F90	(revision 10345)
@@ -0,0 +1,159 @@
+MODULE sedorg
+   !!======================================================================
+   !!              ***  MODULE  seddsr  ***
+   !!    Sediment : dissolution and reaction in pore water related 
+   !!    related to organic matter
+   !!=====================================================================
+   !! * Modules used
+   USE sed     ! sediment global variable
+   USE sed_oce
+   USE sedini
+   USE seddiff
+   USE seddsr
+   USE lib_mpp         ! distribued memory computing library
+   USE lib_fortran
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC sed_org
+
+   !! * Module variables
+
+   REAL(wp) :: zadsnh4
+
+   !! $Id: seddsr.F90 5215 2015-04-15 16:11:56Z nicolasmartin $
+CONTAINS
+   
+   SUBROUTINE sed_org( kt ) 
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_org  ***
+      !! 
+      !!  ** Purpose :  computes pore water diffusion and reaction
+      !!
+      !!  ** Methode :  Computation of the redox reactions in sediment.
+      !!                The main redox reactions are solved in sed_dsr whereas
+      !!                the secondary reactions are solved in sed_dsr_redoxb.
+      !!                A strand spliting approach is being used here (see 
+      !!                sed_dsr_redoxb for more information). 
+      !!                Diffusive fluxes are computed in sed_diff
+      !!
+      !!   History :
+      !!        !  98-08 (E. Maier-Reimer, Christoph Heinze )  Original code
+      !!        !  04-10 (N. Emprin, M. Gehlen ) f90
+      !!        !  06-04 (C. Ethe)  Re-organization
+      !!        !  19-08 (O. Aumont) Debugging and improvement of the model.
+      !!                             The original method is replaced by a 
+      !!                             Strand splitting method which deals 
+      !!                             well with stiff reactions.
+      !!----------------------------------------------------------------------
+      !! Arguments
+      INTEGER, INTENT(in) ::   kt
+      ! --- local variables
+      INTEGER  :: ji, jk, js, jw, jnt   ! dummy looop indices
+      REAL(wp) :: zadsnh4
+      !!
+      !!----------------------------------------------------------------------
+
+      IF( ln_timing )  CALL timing_start('sed_org')
+!
+      IF( kt == nitsed000 ) THEN
+         IF (lwp) THEN
+            WRITE(numsed,*) ' sed_org : Organic degradation related reactions and diffusion'
+            WRITE(numsed,*) ' '
+         ENDIF
+!         ! 
+         dens_mol_wgt(1:jpsol) = denssol / mol_wgt(1:jpsol)
+         ! 
+      ENDIF
+
+      dtsed2 = dtsed / REAL( nrseddt, wp )
+
+      ! 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)
+
+      ! 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
+            IF (raintg(ji) .ne. 0) THEN
+               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.
+            ENDIF
+         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) + rtrn )
+         END DO
+      ENDDO
+
+      zadsnh4 = 1.0 / ( 1.0 + adsnh4 )
+
+      ! --------------------------------------------------
+      ! Computation of the diffusivities
+      ! --------------------------------------------------
+
+      DO js = 1, jpwat
+         DO jk = 1, jpksed
+            DO ji = 1, jpoce
+               diff(ji,jk,js) = ( diff1(js) + diff2(js) * temp(ji) ) / ( 1.0 - 2.0 * log( por(jk) ) )
+            END DO
+         END DO
+      END DO
+
+      ! Impact of bioirrigation and adsorption on diffusion
+      ! ---------------------------------------------------
+
+      diff(:,:,jwnh4) = diff(:,:,jwnh4) * ( 1.0 + irrig(:,:) ) * zadsnh4
+      diff(:,:,jwsil) = diff(:,:,jwsil) * ( 1.0 + irrig(:,:) )
+      diff(:,:,jwoxy) = diff(:,:,jwoxy) * ( 1.0 + irrig(:,:) )
+      diff(:,:,jwdic) = diff(:,:,jwdic) * ( 1.0 + irrig(:,:) )
+      diff(:,:,jwno3) = diff(:,:,jwno3) * ( 1.0 + irrig(:,:) )
+      diff(:,:,jwpo4) = diff(:,:,jwpo4) * ( 1.0 + irrig(:,:) )
+      diff(:,:,jwalk) = diff(:,:,jwalk) * ( 1.0 + irrig(:,:) )
+      diff(:,:,jwh2s) = diff(:,:,jwh2s) * ( 1.0 + irrig(:,:) )
+      diff(:,:,jwso4) = diff(:,:,jwso4) * ( 1.0 + irrig(:,:) )
+      diff(:,:,jwfe2) = diff(:,:,jwfe2) * ( 1.0 + 0.2 * irrig(:,:) )
+
+      DO jnt = 1, nrseddt
+         CALL sed_diff( kt, jnt )        ! 1st pass in diffusion to get values at t+1/2
+         CALL sed_dsr ( kt, jnt )        ! Dissolution reaction
+         CALL sed_diff( kt, jnt )        ! 2nd pass in diffusion to get values at t+1
+      END DO
+
+
+      IF( ln_timing )  CALL timing_stop('sed_org')
+!      
+   END SUBROUTINE sed_org
+
+END MODULE sedorg
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedrst.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedrst.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedrst.F90	(revision 10345)
@@ -1,4 +1,3 @@
 MODULE sedrst
-#if defined key_sed
    !!======================================================================
    !!                       *** MODULE sedrst ***
@@ -11,4 +10,9 @@
    USE sed
    USE sedarr
+   USE trc_oce, ONLY : l_offline, nn_dttrc
+   USE phycst , ONLY : rday
+   USE iom
+   USE daymod
+   USE lib_mpp         ! distribued memory computing library
 
 
@@ -18,14 +22,65 @@
 
    !! * Accessibility
+   PUBLIC sed_rst_opn       ! called by ???
    PUBLIC sed_rst_read
    PUBLIC sed_rst_wri
-
-   !! * Module variables
-   INTEGER, PUBLIC ::   numrsr, numrsw   !: logical unit for sed restart (read and write)
-   
-   
+   PUBLIC sed_rst_cal
+
    !! $Id$
 CONTAINS
 
+
+   SUBROUTINE sed_rst_opn( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  sed_rst_opn  ***
+      !!
+      !! ** purpose  :   output of sed-trc variable in a netcdf file
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt       ! number of iteration
+      !
+      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step define as a character
+      CHARACTER(LEN=50)   ::   clname   ! trc output restart file name
+      CHARACTER(LEN=256)  ::   clpath   ! full path to ocean output restart file
+      !!----------------------------------------------------------------------
+      !
+      IF( l_offline ) THEN
+         IF( kt == nittrc000 ) THEN
+            lrst_sed = .FALSE.
+            IF( ln_rst_list ) THEN
+               nrst_lst = 1
+               nitrst = nstocklist( nrst_lst )
+            ELSE
+               nitrst = nitend
+            ENDIF
+         ENDIF
+         IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nstock ) == 0 ) THEN
+            ! we use kt - 1 and not kt - nittrc000 to keep the same periodicity from the beginning of the experiment
+            nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
+            IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
+         ENDIF
+      ELSE
+         IF( kt == nittrc000 ) lrst_sed = .FALSE.
+      ENDIF
+
+      ! to get better performances with NetCDF format:
+      ! we open and define the tracer restart file one tracer time step before writing the data (-> at nitrst - 2*nn_dttrc + 1)
+      ! except if we write tracer restart files every tracer time step or if a tracer restart file was writen at nitend - 2*nn_dttrc + 1
+      IF( kt == nitrst - 2*nn_dtsed .OR. nstock == nn_dtsed .OR. ( kt == nitend - nn_dtsed .AND. .NOT. lrst_sed ) ) THEN
+         ! beware of the format used to write kt (default is i8.8, that should be large enough)
+         IF( nitrst > 1.0e9 ) THEN   ;   WRITE(clkt,*       ) nitrst
+         ELSE                        ;   WRITE(clkt,'(i8.8)') nitrst
+         ENDIF
+         ! create the file
+         IF(lwp) WRITE(numsed,*)
+         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_sedrst_out)
+         clpath = TRIM(cn_sedrst_outdir)
+         IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
+         IF(lwp) WRITE(numsed,*) &
+             '             open sed restart.output NetCDF file: ',TRIM(clpath)//clname
+         CALL iom_open( TRIM(clpath)//TRIM(clname), numrsw, ldwrt = .TRUE., kiolib = jprstlib, kdlev = jpksed )
+         lrst_sed = .TRUE.
+      ENDIF
+      !
+   END SUBROUTINE sed_rst_opn
 
    SUBROUTINE sed_rst_read 
@@ -40,74 +95,54 @@
       !!        !  06-07  (C. Ethe)  original
       !!----------------------------------------------------------------------
-      !! * Modules used
-      USE iom
 
       !! * local declarations
-      INTEGER :: ji, jk, jn 
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) :: zdta
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:  ) :: zdta1 
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:    ) :: zhipor
+      INTEGER :: ji, jj, jk, jn 
+      REAL(wp), DIMENSION(jpi,jpj,jpksed,jptrased) :: zdta
+      REAL(wp), DIMENSION(jpi,jpj,jpksed,2)        :: zdta1 
+      REAL(wp), DIMENSION(jpi,jpj,jpksed)          :: zdta2
+      REAL(wp), DIMENSION(jpoce,jpksed)            :: zhipor
       REAL(wp) :: zkt
       CHARACTER(len = 20) ::   cltra
+      CHARACTER(LEN=20)   ::   name1
       INTEGER             ::   jlibalt = jprstlib
       LOGICAL             ::   llok
       !--------------------------------------------------------------------
- 
-
-      WRITE(numsed,*) ' '      
-      WRITE(numsed,*) ' Initilization of Sediment components from restart'
-      WRITE(numsed,*) ' '
-
-      ALLOCATE( zdta(jpi,jpj,jpksed,jptrased), zdta1(jpi,jpj,jpksed,2), zhipor(jpoce,jpksed) ) 
-
-      CALL iom_open( 'restart_sed', numrsr, kiolib = jlibalt )     
-      CALL iom_get( numrsr, 'kt'     , zkt      )   ! time-step
- 
+
+      IF( ln_timing )  CALL timing_start('sed_rst_read')
+
+      IF (lwp) WRITE(numsed,*) ' '      
+      IF (lwp) WRITE(numsed,*) ' Initilization of Sediment components from restart'
+      IF (lwp) WRITE(numsed,*) ' '
+
+      zdta  = 1.
+      zdta1 = 1.
+      zdta2 = 0.
+
       DO jn = 1, jptrased
-         cltra = sedtrcd(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) )
+         cltra = TRIM(sedtrcd(jn))
+         IF( iom_varid( numrsr, TRIM(cltra) , ldstop = .FALSE. ) > 0 ) THEN
+            CALL iom_get( numrsr, jpdom_autoglo, TRIM(cltra), zdta(:,:,:,jn) )
+         ELSE
+            zdta(:,:,:,jn) = 0.0
+         ENDIF
+      ENDDO
+
+      DO jn = 1, jpsol
+         CALL pack_arr( jpoce, solcp(1:jpoce,1:jpksed,jn), &
+         &              zdta(1:jpi,1:jpj,1:jpksed,jn), iarroce(1:jpoce) )
+      END DO
+
+      DO jn = 1, jpwat
+         CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jn), &
+         &              zdta(1:jpi,1:jpj,1:jpksed,jpsol+jn), iarroce(1:jpoce) )
+      END DO
 
       DO jn = 1, 2
-         cltra = seddia3d(jn)
-         CALL iom_get( numrsr, jpdom_unknown, cltra, zdta1(:,:,:,jn), &
-            &          kstart=(/1,1,1/), kcount=(/jpi,jpj,jpksed/) )
+         cltra = TRIM(seddia3d(jn))
+         IF( iom_varid( numrsr, TRIM(cltra) , ldstop = .FALSE. ) > 0 ) THEN
+            CALL iom_get( numrsr, jpdom_autoglo, TRIM(cltra), zdta1(:,:,:,jn) )
+         ELSE
+            zdta1(:,:,:,jn) = 0.0
+         ENDIF
       ENDDO
 
@@ -122,5 +157,5 @@
          ENDDO
       ENDDO
-      
+
       CALL pack_arr( jpoce, co3por(1:jpoce,1:jpksed), &
          &             zdta1(1:jpi,1:jpj,1:jpksed,2), iarroce(1:jpoce) )
@@ -131,7 +166,35 @@
       pwcp (1:jpoce,1,:) = 0.
 
-      DEALLOCATE( zdta   )
-      DEALLOCATE( zdta1  )
-      DEALLOCATE( zhipor )
+      cltra = "dbioturb"
+      IF( iom_varid( numrsr, TRIM(cltra) , ldstop = .FALSE. ) > 0 ) THEN
+         CALL iom_get( numrsr, jpdom_autoglo, TRIM(cltra), zdta2(:,:,:) )
+      ELSE
+         zdta2(:,:,:) = 0.0
+      ENDIF
+
+      CALL pack_arr( jpoce, db(1:jpoce,1:jpksed), &
+         &             zdta2(1:jpi,1:jpj,1:jpksed), iarroce(1:jpoce) )
+
+      cltra = "irrig"
+      IF( iom_varid( numrsr, TRIM(cltra) , ldstop = .FALSE. ) > 0 ) THEN
+         CALL iom_get( numrsr, jpdom_autoglo, TRIM(cltra), zdta2(:,:,:) )
+      ELSE
+         zdta2(:,:,:) = 0.0
+      ENDIF
+
+      CALL pack_arr( jpoce, irrig(1:jpoce,1:jpksed), &
+         &             zdta2(1:jpi,1:jpj,1:jpksed), iarroce(1:jpoce) )
+
+      cltra = "sedligand"
+      IF( iom_varid( numrsr, TRIM(cltra) , ldstop = .FALSE. ) > 0 ) THEN
+         CALL iom_get( numrsr, jpdom_autoglo, TRIM(cltra), zdta2(:,:,:) )
+      ELSE
+         zdta2(:,:,:) = 0.0
+      ENDIF
+
+      CALL pack_arr( jpoce, sedligand(1:jpoce,1:jpksed), &
+         &             zdta2(1:jpi,1:jpj,1:jpksed), iarroce(1:jpoce) )
+
+      IF( ln_timing )  CALL timing_stop('sed_rst_read')
      
    END SUBROUTINE sed_rst_read
@@ -147,130 +210,204 @@
       !!----------------------------------------------------------------------
       !!* Modules used
-      USE ioipsl
-      !! *Arguments
       INTEGER, INTENT(in) ::   kt       ! number of iteration
       !! * local declarations
-      INTEGER  :: ji, jk
-      INTEGER  :: ic, jc, jn, itime 
-      REAL(wp) :: zdate0
+      INTEGER  :: ji, jj, jk, jn
       REAL(wp), DIMENSION(1) ::  zinfo
-      CHARACTER(len=50) :: clname,cln
-      CHARACTER(len=20) :: cltra 
-      REAL(wp), DIMENSION(:,:) , ALLOCATABLE  :: zdta   
+      CHARACTER(len=50) :: clname
+      CHARACTER(len=20) :: cltra, name1 
+      REAL(wp), DIMENSION(jpoce,jpksed)   :: zdta   
+      REAL(wp), DIMENSION(jpi,jpj,jpksed) :: zdta2
       !! -----------------------------------------------------------------------
 
-      ALLOCATE( zdta(jpoce,jpksed) )
-
-      IF( MOD(kt,nstock) == 0 .OR. kt == nitsedend ) THEN
-         
+      IF( ln_timing )  CALL timing_start('sed_rst_wri')
+
          !! 0. initialisations
          !! ------------------
          
-         IF(lwp) WRITE(numsed,*) ' '
-         IF(lwp) WRITE(numsed,*) 'sed_rst_write : write the sediment restart file in NetCDF format ',   &
+      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,*) '~~~~~~~~~'
+      IF(lwp) WRITE(numsed,*) '~~~~~~~~~'
+
+
+      trcsedi(:,:,:,:)   = 0.0
+      flxsedi3d(:,:,:,:) = 0.0
+      zdta(:,:)          = 1.0
+      zdta2(:,:,:)       = 0.0
+
          
-         !! 1. WRITE in nutwrs
-         !! ------------------
-
-         ic = 1
-         DO jc = 1,16
-            IF( cexper(jc:jc) /= ' ') ic = jc
-         END DO
-         WRITE( cln,'("_",i5.5,i2.2,i2.2,"_restart.sed")') nyear, nmonth, nday
-         clname = cexper(1:ic)//cln
-         itime = 0
-         CALL ymds2ju( nyear, nmonth, nday, rdt, zdate0 )
-         zdate0 = zdate0 - adatrj   !   set calendar origin to the beginning of the experiment
-         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 ) )
+      !! 1. WRITE in nutwrs
+      !! ------------------
+
+      zinfo(1) = REAL( kt)
+      CALL iom_rstput( kt, nitrst, numrsw, 'kt', zinfo  )
+
+      ! Back to 2D geometry
+      DO jn = 1, jpsol
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,jn) , iarroce(1:jpoce), &
+         &                       solcp(1:jpoce,1:jpksed,jn ) )
+      END DO
+
+      DO jn = 1, jpwat
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,jpsol+jn) , iarroce(1:jpoce), &
+         &                       pwcp(1:jpoce,1:jpksed,jn  )  )
+      END DO
+      ! pH
+      DO jk = 1, jpksed
+         DO ji = 1, jpoce
+            zdta(ji,jk) = -LOG10( hipor(ji,jk) / ( densSW(ji) + rtrn ) + rtrn )
+         ENDDO
+      ENDDO
+
+      CALL unpack_arr( jpoce, flxsedi3d(1:jpi,1:jpj,1:jpksed,1)  , iarroce(1:jpoce), &
+      &                   zdta(1:jpoce,1:jpksed)  )
          
-         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, flxsedi3d(1:jpi,1:jpj,1:jpksed,1)  , iarroce(1:jpoce), &
-            &                   zdta(1:jpoce,1:jpksed)  )
-         
-         CALL unpack_arr( jpoce, flxsedi3d(1:jpi,1:jpj,1:jpksed,2)  , iarroce(1:jpoce), &
-            &                   co3por(1:jpoce,1:jpksed)  )
-      
-         ! prognostic variables
-         ! --------------------
-
-
-         DO jn = 1, jptrased
-            cltra = sedtrcd(jn)
-            CALL restput( numrsw, cltra, jpi, jpj, jpksed, 0, trcsedi(:,:,:,jn) )
-         ENDDO
-
-         DO jn = 1, 2
-            cltra = seddia3d(jn)
-            CALL restput( numrsw, cltra, jpi, jpj, jpksed, 0, flxsedi3d(:,:,:,jn) )
-         ENDDO
-
-
-         CALL restclo( numrsw )
-
-      ENDIF
-
-      DEALLOCATE( zdta )  
+      CALL unpack_arr( jpoce, flxsedi3d(1:jpi,1:jpj,1:jpksed,2)  , iarroce(1:jpoce), &
+      &                   co3por(1:jpoce,1:jpksed)  )
+
+      ! prognostic variables
+      ! --------------------
+
+      DO jn = 1, jptrased
+         cltra = TRIM(sedtrcd(jn))
+         CALL iom_rstput( kt, nitrst, numrsw, TRIM(cltra), trcsedi(:,:,:,jn) )
+      ENDDO
+
+      DO jn = 1, 2
+         cltra = TRIM(seddia3d(jn))
+         CALL iom_rstput( kt, nitrst, numrsw, TRIM(cltra), flxsedi3d(:,:,:,jn) )
+      ENDDO
+
+      CALL unpack_arr( jpoce, zdta2(1:jpi,1:jpj,1:jpksed)  , iarroce(1:jpoce), &
+      &                   db(1:jpoce,1:jpksed)  )
+
+      cltra = "dbioturb"
+      CALL iom_rstput( kt, nitrst, numrsw, TRIM(cltra), zdta2(:,:,:) )
+
+      CALL unpack_arr( jpoce, zdta2(1:jpi,1:jpj,1:jpksed)  , iarroce(1:jpoce), &
+      &                   irrig(1:jpoce,1:jpksed)  )
+
+      cltra = "irrig"
+      CALL iom_rstput( kt, nitrst, numrsw, TRIM(cltra), zdta2(:,:,:) )
+
+      CALL unpack_arr( jpoce, zdta2(1:jpi,1:jpj,1:jpksed)  , iarroce(1:jpoce), &
+      &                   sedligand(1:jpoce,1:jpksed)  )
+
+      cltra = "sedligand"
+      CALL iom_rstput( kt, nitrst, numrsw, TRIM(cltra), zdta2(:,:,:) )
+
+      IF( kt == nitrst ) THEN
+          CALL iom_close( numrsw )     ! close the restart file (only at last time step)
+          IF( l_offline .AND. ln_rst_list ) THEN
+             nrst_lst = nrst_lst + 1
+             nitrst = nstocklist( nrst_lst )
+          ENDIF
+      ENDIF
+
+      IF( ln_timing )  CALL timing_stop('sed_rst_wri')
          
    END SUBROUTINE sed_rst_wri
-#else
-   !!======================================================================
-   !! MODULE sedrst :   Dummy module 
-   !!======================================================================
-   !! $Id$
-CONTAINS
-   SUBROUTINE sed_rst_read                      ! Empty routines
-   END SUBROUTINE sed_rst_read
-   SUBROUTINE sed_rst_wri( kt )
-      INTEGER, INTENT ( in ) :: kt
-      WRITE(*,*) 'sed_rst_wri: You should not have seen this print! error?', kt
-   END SUBROUTINE sed_rst_wri   
-#endif
+
+
+   SUBROUTINE sed_rst_cal( kt, cdrw )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE sed_rst_cal  ***
+      !!
+      !!  ** Purpose : Read or write calendar in restart file:
+      !!
+      !!  WRITE(READ) mode:
+      !!       kt        : number of time step since the begining of the experiment at the
+      !!                   end of the current(previous) run
+      !!       adatrj(0) : number of elapsed days since the begining of the experiment at the
+      !!                   end of the current(previous) run (REAL -> keep fractions of day)
+      !!       ndastp    : date at the end of the current(previous) run (coded as yyyymmdd integer)
+      !!
+      !!   According to namelist parameter nrstdt,
+      !!       nn_rsttr = 0  no control on the date (nittrc000 is  arbitrary).
+      !!       nn_rsttr = 1  we verify that nittrc000 is equal to the last
+      !!                   time step of previous run + 1.
+      !!       In both those options, the  exact duration of the experiment
+      !!       since the beginning (cumulated duration of all previous restart runs)
+      !!       is not stored in the restart and is assumed to be (nittrc000-1)*rdt.
+      !!       This is valid is the time step has remained constant.
+      !!
+      !!       nn_rsttr = 2  the duration of the experiment in days (adatrj)
+      !!                    has been stored in the restart file.
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
+      !
+      INTEGER  ::  jlibalt = jprstlib
+      LOGICAL  ::  llok
+      REAL(wp) ::  zkt, zrdttrc1
+      REAL(wp) ::  zndastp
+
+      ! Time domain : restart
+      ! ---------------------
+
+      IF( TRIM(cdrw) == 'READ' ) THEN
+
+         IF(lwp) WRITE(numsed,*)
+         IF(lwp) WRITE(numsed,*) 'sed_rst_cal : read the SED restart file for calendar'
+         IF(lwp) WRITE(numsed,*) '~~~~~~~~~~~~'
+
+         IF( ln_rst_sed ) THEN
+            CALL iom_open( TRIM(cn_sedrst_indir)//'/'//cn_sedrst_in, numrsr, kiolib = jlibalt )
+            CALL iom_get ( numrsr, 'kt', zkt )   ! last time-step of previous run
+
+            IF(lwp) THEN
+               WRITE(numsed,*) ' *** Info read in restart : '
+               WRITE(numsed,*) '   previous time-step                               : ', NINT( zkt )
+               WRITE(numsed,*) ' *** restart option'
+               SELECT CASE ( nn_rstsed )
+               CASE ( 0 )   ;   WRITE(numsed,*) ' nn_rstsed = 0 : no control of nittrc000'
+               CASE ( 1 )   ;   WRITE(numsed,*) ' nn_rstsed = 1 : no control the date at nittrc000 (use ndate0 read in the namelist)'
+               CASE ( 2 )   ;   WRITE(numsed,*) ' nn_rstsed = 2 : calendar parameters read in restart'
+               END SELECT
+               WRITE(numsed,*)
+            ENDIF
+            ! Control of date 
+            IF( nittrc000  - NINT( zkt ) /= nn_dtsed .AND.  nn_rstsed /= 0 )                                  &
+               &   CALL ctl_stop( ' ===>>>> : problem with nittrc000 for the restart',                 &
+               &                  ' verify the restart file or rerun with nn_rsttr = 0 (namelist)' )
+         ENDIF
+         !
+         IF( l_offline ) THEN
+            !                                          ! set the date in offline mode
+            IF( ln_rst_sed .AND. nn_rstsed == 2 ) THEN
+               CALL iom_get( numrsr, 'ndastp', zndastp )
+               ndastp = NINT( zndastp )
+               CALL iom_get( numrsr, 'adatrj', adatrj  )
+             ELSE
+               ndastp = ndate0 - 1     ! ndate0 read in the namelist in dom_nam
+               adatrj = ( REAL( nittrc000-1, wp ) * rdt ) / rday
+               ! note this is wrong if time step has changed during run
+            ENDIF
+            !
+            IF(lwp) THEN
+              WRITE(numsed,*) ' *** Info used values : '
+              WRITE(numsed,*) '   date ndastp                                      : ', ndastp
+              WRITE(numsed,*) '   number of elapsed days since the begining of run : ', adatrj
+              WRITE(numsed,*)
+            ENDIF
+            !
+            CALL day_init          ! compute calendar
+            !
+         ENDIF
+         !
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN
+         !
+         IF(  kt == nitrst ) THEN
+            IF(lwp) WRITE(numsed,*)
+            IF(lwp) WRITE(numsed,*) 'trc_wri : write the TOP restart file (NetCDF) at it= ', kt, ' date= ', ndastp
+            IF(lwp) WRITE(numsed,*) '~~~~~~~'
+         ENDIF
+         CALL iom_rstput( kt, nitrst, numrsw, 'kt'     , REAL( kt    , wp) )   ! time-step
+         CALL iom_rstput( kt, nitrst, numrsw, 'ndastp' , REAL( ndastp, wp) )   ! date
+         CALL iom_rstput( kt, nitrst, numrsw, 'adatrj' , adatrj            )   ! number of elapsed days since
+         !                                                                     ! the begining of the run [s]
+      ENDIF
+
+   END SUBROUTINE sed_rst_cal
 
 END MODULE sedrst
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedsfc.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedsfc.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedsfc.F90	(revision 10345)
@@ -4,5 +4,4 @@
    !!    Sediment : Data at sediment surface
    !!=====================================================================
-#if defined key_sed && ! defined key_sed_off
    !! * Modules used
    USE sed     ! sediment global variable
@@ -32,11 +31,7 @@
 
       !------------------------------------------------------------------------
+      ! reading variables
 
-      IF( kt == nitsed000 ) THEN
-         WRITE(numsed,*) ' sed_sfc : Give data from sediment model to tracer model  '
-         WRITE(numsed,*) ' '
-      ENDIF
-
-      ! reading variables
+      IF( ln_timing )  CALL timing_start('sed_sfc')
 
       CALL unpack_arr ( jpoce, trc_data(1:jpi,1:jpj,1), iarroce(1:jpoce), pwcp(1:jpoce,1,jwalk) )
@@ -46,4 +41,6 @@
       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) )
+      CALL unpack_arr ( jpoce, trc_data(1:jpi,1:jpj,7), iarroce(1:jpoce), pwcp(1:jpoce,1,jwnh4) )
+      CALL unpack_arr ( jpoce, trc_data(1:jpi,1:jpj,8), iarroce(1:jpoce), pwcp(1:jpoce,1,jwfe2) )
 
 
@@ -52,27 +49,19 @@
             ikt = mbkt(ji,jj)
             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)
+               trb(ji,jj,ikt,jptal) = trc_data(ji,jj,1)
+               trb(ji,jj,ikt,jpdic) = trc_data(ji,jj,2)
+               trb(ji,jj,ikt,jpno3) = trc_data(ji,jj,3) * 7.625
+               trb(ji,jj,ikt,jppo4) = trc_data(ji,jj,4) * 122.
+               trb(ji,jj,ikt,jpoxy) = trc_data(ji,jj,5)
+               trb(ji,jj,ikt,jpsil) = trc_data(ji,jj,6)
+               trb(ji,jj,ikt,jpnh4) = trc_data(ji,jj,7) * 7.625
+               trb(ji,jj,ikt,jpfer) = trc_data(ji,jj,8)
             ENDIF
          ENDDO
       ENDDO
 
+      IF( ln_timing )  CALL timing_stop('sed_sfc')
+
    END SUBROUTINE sed_sfc
 
-#else
-   !!======================================================================
-   !! MODULE sedsfc  :   Dummy module 
-   !!======================================================================
-   !! $Id$
-CONTAINS
-   SUBROUTINE sed_sfc ( kt )
-      INTEGER, INTENT(in) :: kt
-      WRITE(*,*) 'sed_sfc: You should not have seen this print! error?', kt
-   END SUBROUTINE sed_sfc
-#endif
-
 END MODULE sedsfc
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedstp.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedstp.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedstp.F90	(revision 10345)
@@ -1,4 +1,3 @@
 MODULE sedstp
-#if defined key_sed
    !!======================================================================
    !!                       ***  MODULE sedstp   ***
@@ -9,5 +8,6 @@
    USE sedchem  ! chemical constant
    USE sedco3   ! carbonate in sediment pore water
-   USE seddsr   ! dissolution reaction
+   USE sedorg   ! Organic reactions and diffusion
+   USE sedinorg ! Inorganic dissolution
    USE sedbtb   ! bioturbation
    USE sedadv   ! vertical advection
@@ -16,4 +16,7 @@
    USE sedrst   ! restart
    USE sedwri   ! outputs
+   USE trcdmp_sed
+   USE lib_mpp         ! distribued memory computing library
+   USE iom
 
    IMPLICIT NONE
@@ -42,38 +45,53 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt       ! number of iteration
+      INTEGER :: ji,jk,js,jn,jw
+      !!----------------------------------------------------------------------
+      IF( ln_timing )      CALL timing_start('sed_stp')
+        !
+                                CALL sed_rst_opn  ( kt )       ! Open tracer restart file 
+      IF( lrst_sed )            CALL sed_rst_cal  ( kt, 'WRITE' )   ! calenda
 
-      !!----------------------------------------------------------------------
+      IF(ln_sediment_offline)   CALL trc_dmp_sed  ( kt )
 
-      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
+      dtsed  = r2dttrc
+!      dtsed2 = dtsed
+      IF (kt /= nitsed000) THEN
+         CALL sed_dta( kt )       ! Load  Data for bot. wat. Chem and fluxes
       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_wri( kt )   ! restart file output
+      IF (sedmask == 1. ) THEN
+         IF( kt /= nitsed000 )  THEN
+           CALL sed_chem( kt )      ! update of chemical constant to account for salinity, temperature changes
+         ENDIF
+
+         CALL sed_btb( kt )         ! 1st pass of bioturbation at t+1/2
+         CALL sed_org( kt )         ! Organic related reactions and diffusion
+         CALL sed_inorg( kt )       ! Dissolution reaction
+         CALL sed_btb( kt )         ! 2nd pass of bioturbation at t+1
+         tokbot(:,:) = 0.0
+         DO jw = 1, jpwat
+            DO ji = 1, jpoce
+               tokbot(ji,jw) = pwcp(ji,1,jw) * 1.e-3 * dzkbot(ji)
+            END DO
+         ENDDO
+         CALL sed_adv( kt )         ! advection
+         CALL sed_co3( kt )         ! pH actualization for saving
+         ! This routine is commented out since it does not work at all
+         CALL sed_mbc( kt )         ! cumulation for mass balance calculation
+
+         IF (ln_sed_2way) CALL sed_sfc( kt )         ! Give back new bottom wat chem to tracer model
+      ENDIF
       CALL sed_wri( kt )         ! outputs
+      IF( kt == nitsed000 ) THEN
+          CALL iom_close( numrsr )       ! close input tracer restart file
+!          IF(lwm) CALL FLUSH( numont )   ! flush namelist output
+      ENDIF
+      IF( lrst_sed )            CALL sed_rst_wri( kt )   ! restart file output
 
       IF( kt == nitsedend )  CLOSE( numsed )
 
+      IF( ln_timing )   CALL timing_stop('sed_stp')
+
    END SUBROUTINE sed_stp
 
-#else
-   !!======================================================================
-   !! MODULE sedstp  :   Dummy module 
-   !!======================================================================
-   !! $Id$
-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: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedwri.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedwri.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedwri.F90	(revision 10345)
@@ -1,4 +1,3 @@
 MODULE sedwri
-#if defined key_sed
    !!======================================================================
    !!                     ***  MODULE  sedwri  ***
@@ -7,6 +6,6 @@
    USE sed
    USE sedarr
-   USE ioipsl
-   USE dianam    ! build name of file (routine)
+   USE lib_mpp         ! distribued memory computing library
+   USE iom
 
    IMPLICIT NONE
@@ -15,13 +14,4 @@
    !! * Accessibility
    PUBLIC sed_wri 
-
-   INTEGER  :: nised
-   INTEGER  :: nhorised
-   INTEGER  :: ndimt52
-   INTEGER  :: ndimt51
-   INTEGER  :: ndepsed
-   REAL(wp) :: zjulian
-   INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) :: ndext52  
-   INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) :: ndext51
 
    !! $Id$
@@ -43,10 +33,7 @@
       INTEGER, INTENT(in) :: kt
 
-      CHARACTER(len = 60)  ::  clhstnam, clop
-      INTEGER  :: ji, jk, js, jw, jn
-      REAL(wp) :: zsto,zout, zdt
-      INTEGER  :: iimi, iima, ijmi, ijma,ipk, it, itmod
-      CHARACTER(len = 20)  ::  cltra , cltrau
-      CHARACTER(len = 80)  ::  cltral
+      INTEGER  :: ji, jj, jk, js, jw, jn
+      INTEGER  :: it
+      CHARACTER(len = 20)  ::  cltra 
       REAL(wp)  :: zrate
       REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zdta, zflx
@@ -57,81 +44,42 @@
       ! Initialisation
       ! ----------------- 
-      IF( kt == nittrc000 )   ALLOCATE( ndext52(jpij*jpksed), ndext51(jpij) )
-
-      ! Define frequency of output and means
-      zdt = dtsed
-      IF( ln_mskland )   THEN   ;   clop = "only(x)"   ! put 1.e+20 on land (very expensive!!)
-      ELSE                      ;   clop = "x"         ! no use of the mask value (require less cpu time)
-      ENDIF
-#if defined key_diainstant
-      zsto = nwrised * zdt
-      clop = "inst("//TRIM(clop)//")"
-#else
-      zsto = zdt
-      clop = "ave("//TRIM(clop)//")"
-#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
-      itmod = kt - nitsed000 + 1
-
 
       ! 1.  Initilisations
       ! -----------------------------------------------------------------
-      WRITE(numsed,*) ' '
-      WRITE(numsed,*) 'sed_wri kt = ', kt
-      WRITE(numsed,*) ' '
+      IF( ln_timing )  CALL timing_start('sed_wri')
+!
+      IF (lwp) WRITE(numsed,*) ' '
+      IF (lwp) WRITE(numsed,*) 'sed_wri kt = ', kt
+      IF (lwp) WRITE(numsed,*) ' '
       
       ALLOCATE( zdta(jpoce,jpksed) )    ;   ALLOCATE( zflx(jpoce,jpwatp1) )
 
+      ! Initialize variables
+      ! --------------------
+
+      trcsedi(:,:,:,:)   = 0.0
+      flxsedi3d(:,:,:,:) = 0.0
+      flxsedi2d(:,:,:)   = 0.0
 
       ! 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 ) )
+      DO jn = 1, jpsol
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,jn) , iarroce(1:jpoce), &
+         &                       solcp(1:jpoce,1:jpksed,jn ) )
+      END DO
       
-      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  ) )
-      
+      DO jn = 1, jpwat
+         CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,jpsol + jn) , iarroce(1:jpoce), &
+         &                       pwcp(1:jpoce,1:jpksed,jn  )  )
+      END DO      
+
       ! porosity
       zdta(:,:) = 0.
       DO jk = 1, jpksed
          DO ji = 1, jpoce
-            zdta(ji,jk) = -LOG10( hipor(ji,jk) / densSW(ji) )
+            zdta(ji,jk) = -LOG10( hipor(ji,jk) / ( densSW(ji) + rtrn ) + rtrn )
          ENDDO
       ENDDO
+
       CALL unpack_arr( jpoce, flxsedi3d(1:jpi,1:jpj,1:jpksed,1)  , iarroce(1:jpoce), &
          &                   zdta(1:jpoce,1:jpksed)  )
@@ -140,17 +88,5 @@
          &                   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, flxsedi3d(1:jpi,1:jpj,1:jpksed,3)  , iarroce(1:jpoce), &
-         &                   zdta(1:jpoce,1:jpksed)  )
-      
- 
+!      flxsedi3d = 0.
       zflx(:,:) = 0.    
       ! Calculation of fluxes mol/cm2/s
@@ -158,10 +94,11 @@
          DO ji = 1, jpoce
             zflx(ji,jw) = ( pwcp(ji,1,jw) - pwcp_dta(ji,jw) ) &
-               &         * 1.e-3 * dzkbot(ji) / dtsed
+               &         * 1.e3 / 1.e2 * dzkbot(ji) / r2dttrc
          ENDDO
       ENDDO
+
       ! Calculation of accumulation rate per dt
       DO js = 1, jpsol
-         zrate =  mol_wgt(js) / ( dens * por1(jpksed) ) / dtsed
+         zrate =  1.0 / ( denssol * por1(jpksed) ) / r2dttrc
          DO ji = 1, jpoce
             zflx(ji,jpwatp1) = zflx(ji,jpwatp1) + ( tosed(ji,js) - fromsed(ji,js) ) * zrate
@@ -169,67 +106,9 @@
       ENDDO
 
-      CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,1), iarroce(1:jpoce), zflx(1:jpoce,1)  )
-      CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,2), iarroce(1:jpoce), zflx(1:jpoce,2)  )
-      CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,3), iarroce(1:jpoce), zflx(1:jpoce,3)  )
-      CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,4), iarroce(1:jpoce), zflx(1:jpoce,4)  )
-      CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,5), iarroce(1:jpoce), zflx(1:jpoce,5)  )
-      CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,6), iarroce(1:jpoce), zflx(1:jpoce,6)  )
-      CALL unpack_arr( jpoce, flxsedi2d(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, rdt, zjulian )
-         zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
-         CALL dia_nam ( clhstnam, nwrised, 'sed_T' )
-         CALL histbeg ( clhstnam, jpi, glamt, jpj, gphit,     &
-            &             iimi, iima-iimi+1, ijmi, ijma-ijmi+1,         &
-            &             nitsed000-1, zjulian, zdt,  nhorised, nised , domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nised,'deptht','Vertic.sed.T levels','m',ipk, profsed, ndepsed, 'down' )
-         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  = sedtrcd(jn)   ! short title for sediment variable
-            cltral = sedtrcl(jn)   ! long title for  sediment variable
-            cltrau = sedtrcu(jn)   ! unit for  sediment variable
-
-            CALL histdef( nised, cltra,cltral,cltrau, jpi, jpj, nhorised, &
-               &          ipk, 1, ipk, ndepsed, 32, clop, zsto, zout )
-         ENDDO
-
-         ! 3D diagnostic
-         DO jn = 1, jpdia3dsed
-            cltra  = seddia3d(jn)   ! short title for 3D diagnostic
-            cltral = seddia3l(jn)   ! long title for 3D diagnostic
-            cltrau = seddia3u(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, jpdia2dsed
-            cltra  = seddia2d(jn)   ! short title for 2D diagnostic
-            cltral = seddia2l(jn)   ! long title for 2D diagnostic
-            cltrau = seddia2u(jn)   ! UNIT for 2D diagnostic
-            
-            CALL histdef( nised, cltra,cltral,cltrau, jpi, jpj, nhorised, &
-               &          1, 1, 1, -99, 32, clop, zsto, zout )
-         ENDDO
-
-
-         CALL histend( nised, snc4set )
-
-         WRITE(numsed,*)
-         WRITE(numsed,*) 'End of NetCDF sediment output file Initialization'
-
-       ENDIF
+      DO jn = 1, jpdia2dsed - 1 
+         CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,jn), iarroce(1:jpoce), zflx(1:jpoce,jn)  )
+      END DO
+      zflx(:,1) = dzdep(:) / dtsed
+      CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,jpdia2dsed), iarroce(1:jpoce), zflx(1:jpoce,1) )
 
        ! Start writing data
@@ -237,41 +116,23 @@
        DO jn = 1, jptrased
           cltra = sedtrcd(jn) ! short title for 3D diagnostic
-          CALL histwrite( nised, cltra, it, trcsedi(:,:,:,jn), ndimt52, ndext52 )
+          CALL iom_put( cltra, trcsedi(:,:,:,jn) )
        END DO
 
        DO jn = 1, jpdia3dsed
           cltra = seddia3d(jn) ! short title for 3D diagnostic
-          CALL histwrite( nised, cltra, it, flxsedi3d(:,:,:,jn), ndimt52, ndext52 )
+          CALL iom_put( cltra, flxsedi3d(:,:,:,jn) )
        END DO
 
        DO jn = 1, jpdia2dsed
-             cltra = seddia2d(jn) ! short title for 2D diagnostic
-             CALL histwrite( nised, cltra, it, flxsedi2d(:,:,jn  ), ndimt51, ndext51 )
+          cltra = seddia2d(jn) ! short title for 2D diagnostic
+          CALL iom_put( cltra, flxsedi2d(:,:,jn) )
        END DO
 
 
-      ! 3. Closing all files
-      ! --------------------
-      IF( kt == nitsedend  ) THEN
-          CALL histclo( nised )
-      ENDIF
+      DEALLOCATE( zdta )    ;   DEALLOCATE( zflx )
 
-      DEALLOCATE( zdta )    ;   DEALLOCATE( zflx )
+      IF( ln_timing )  CALL timing_stop('sed_wri')
 
    END SUBROUTINE sed_wri
 
-#else
-   !!======================================================================
-   !! MODULE sedwri  :   Dummy module
-   !!======================================================================
-   !! $Id$
-CONTAINS
-   SUBROUTINE sed_wri( kt )         ! Empty routine
-      INTEGER, INTENT(in) :: kt
-      WRITE(*,*) 'sed_adv: You should not have seen this print! error?', kt
-   END SUBROUTINE sed_wri
-
-   !!======================================================================
-#endif
-
 END MODULE sedwri
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/trcdmp_sed.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/trcdmp_sed.F90	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/trcdmp_sed.F90	(revision 10345)
@@ -0,0 +1,157 @@
+MODULE trcdmp_sed
+   !!======================================================================
+   !!                       ***  MODULE  trcdmp  ***
+   !! Ocean physics: internal restoring trend on passive tracers
+   !!======================================================================
+   !! History :  OPA  !  1991-03  (O. Marti, G. Madec)  Original code
+   !!                 !  1996-01  (G. Madec) statement function for e3
+   !!                 !  1997-05  (H. Loukos)  adapted for passive tracers
+   !!    NEMO    9.0  !  2004-03  (C. Ethe)    free form + modules
+   !!            3.2  !  2007-02  (C. Deltel)  Diagnose ML trends for passive tracers
+   !!            3.3  !  2010-06  (C. Ethe, G. Madec) merge TRA-TRC 
+   !!----------------------------------------------------------------------
+#if  defined key_top
+   !!----------------------------------------------------------------------
+   !!   trc_dmp      : update the tracer trend with the internal damping
+   !!   trc_dmp_init : initialization, namlist read, parameters control
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! ocean dynamics and tracers variables
+   USE trc             ! ocean passive tracers variables
+   USE sed , ONLY : dtsed => dtsed      ! ocean dynamics and tracers variables
+   USE trc             ! ocean passive tracers variables
+   USE trcdta
+   USE prtctl_trc      ! Print control for debbuging
+   USE iom
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_dmp_sed      
+   PUBLIC trc_dmp_sed_alloc  
+   PUBLIC trc_dmp_sed_ini    
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   restosed   ! restoring coeff. on tracers (s-1)
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id: trcdmp.F90 7646 2017-02-06 09:25:03Z timgraham $ 
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION trc_dmp_sed_alloc()
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE trc_dmp_alloc  ***
+      !!----------------------------------------------------------------------
+      ALLOCATE( restosed(jpi,jpj,jpk) , STAT=trc_dmp_sed_alloc )
+      !
+      IF( trc_dmp_sed_alloc /= 0 )   CALL ctl_warn('trc_dmp_sed_alloc: failed to allocate array')
+      !
+   END FUNCTION trc_dmp_sed_alloc
+
+
+   SUBROUTINE trc_dmp_sed( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE trc_dmp_sed  ***
+      !!                  
+      !! ** Purpose :   Compute the passive tracer trend due to a newtonian damping
+      !!      of the tracer field towards given data field and add it to the
+      !!      general tracer trends.
+      !!
+      !! ** Method  :   Newtonian damping towards trdta computed 
+      !!      and add to the general tracer trends:
+      !!                     trn = tra + restotr * (trdta - trb)
+      !!         The trend is computed either throughout the water column
+      !!      (nlmdmptr=0) or in area of weak vertical mixing (nlmdmptr=1) or
+      !!      below the well mixed layer (nlmdmptr=2)
+      !!
+      !! ** Action  : - update the tracer trends tra with the newtonian 
+      !!                damping trends.
+      !!              - save the trends ('key_trdmxl_trc')
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER ::   ji, jj, jk, jn, jl, ikt   ! dummy loop indices
+      CHARACTER (len=22) ::   charout
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrcdta   ! 3D  workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )  CALL timing_start('trc_dmp_sed')
+      !
+      !
+      IF( nb_trcdta > 0 ) THEN  ! Initialisation of tracer from a file that may also be used for damping
+         !
+         DO jn = 1, jptra                                           ! tracer loop
+            !                                                       ! ===========
+            IF( ln_trc_ini(jn) ) THEN      ! update passive tracers arrays with input data read from file
+               !
+               jl = n_trc_index(jn) 
+               CALL trc_dta( kt, sf_trcdta(jl), rf_trfac(jl), ztrcdta )   ! read tracer data at nit000
+               !
+               DO jj = 1, jpj
+                  DO ji = 1, jpi   ! vector opt.
+                     ikt = mbkt(ji,jj)
+                     trb(ji,jj,ikt,jn) = ztrcdta(ji,jj,ikt) + ( trb(ji,jj,ikt,jn) -  ztrcdta(ji,jj,ikt) )     &
+                     &                  * exp( -restosed(ji,jj,ikt) * dtsed )
+                  END DO
+               END DO
+               ! 
+            ENDIF
+         END DO                                                     ! tracer loop
+         !                                                          ! ===========
+      ENDIF
+      !
+      !                                          ! print mean trends (used for debugging)
+      IF( ln_ctl ) THEN
+         WRITE(charout, FMT="('dmp ')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
+      ENDIF
+      !
+      IF( ln_timing )  CALL timing_stop('trc_dmp_sed')
+      !
+   END SUBROUTINE trc_dmp_sed
+
+
+   SUBROUTINE trc_dmp_sed_ini
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_dmp_ini  ***
+      !! 
+      !! ** Purpose :   Initialization for the newtonian damping 
+      !!
+      !! ** Method  :   read the nammbf namelist and check the parameters
+      !!              called by trc_dmp at the first timestep (nittrc000)
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )  CALL timing_start('trc_dmp_sed_ini')
+
+      IF (lwp) WRITE(numout,*) '   tracer damping throughout the water column'
+      !
+      IF( trc_dmp_sed_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'trc_dmp_sed_ini: unable to allocate arrays' )
+      !
+      IF( .NOT.lk_c1d ) THEN
+         !Read in mask from file
+          restosed(:,:,:) = 0.5 / rday
+         !
+      ENDIF
+      IF( ln_timing )  CALL timing_stop('trc_dmp_sed_ini')
+     !
+   END SUBROUTINE trc_dmp_sed_ini
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_dmp_sed( kt )        ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_dmp_sed: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_dmp_sed
+#endif
+
+   !!======================================================================
+END MODULE trcdmp_sed
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/sms_pisces.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/sms_pisces.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/sms_pisces.F90	(revision 10345)
@@ -24,4 +24,5 @@
    LOGICAL  ::  ln_p5z            !: Flag to use PISCES  quota model
    LOGICAL  ::  ln_ligand         !: Flag to enable organic ligands
+   LOGICAL  ::  ln_sediment       !: Flag to enable sediment module
 
    !!*  Time variables
@@ -123,10 +124,4 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tgfunc2   !: Temp. dependancy of mesozooplankton rates
 
-#if defined key_sed
-   LOGICAL, PUBLIC, PARAMETER ::   lk_sed = .TRUE.     !: sediment flag
-#else
-   LOGICAL, PUBLIC, PARAMETER ::   lk_sed = .FALSE.     !: sediment flag
-#endif
-
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/trcice_pisces.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/trcice_pisces.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/trcice_pisces.F90	(revision 10345)
@@ -273,5 +273,5 @@
             WHERE( gphit(:,:) <  0._wp ) ; trc_o(:,:,jn) = zpisc(jn,3) ; END WHERE ! Antarctic 
          ENDIF
-         IF( cn_cfg == "orca" ) THEN     !  Baltic Sea particular case for ORCA configurations
+         IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN     !  Baltic Sea particular case for ORCA configurations
              WHERE( 14._wp <= glamt(:,:) .AND. glamt(:,:) <= 32._wp .AND.    &
                     54._wp <= gphit(:,:) .AND. gphit(:,:) <= 66._wp )
@@ -312,5 +312,5 @@
        
          !-- Baltic
-         IF( cn_cfg == "orca" ) THEN  ! Baltic treated seperately for ORCA configs
+         IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN     
             IF ( trc_ice_ratio(jn) >= - 1._wp ) THEN ! no prescribed conc. ; typically everything but iron) 
                WHERE( 14._wp <= glamt(:,:) .AND. glamt(:,:) <= 32._wp .AND.    &
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/trcini_pisces.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/trcini_pisces.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/trcini_pisces.F90	(revision 10345)
@@ -18,4 +18,5 @@
    USE trcnam_pisces   !  PISCES namelist
    USE sms_pisces      !  PISCES Source Minus Sink variables
+   USE sedini          !  SEDIMENTS initialization routine
 
    IMPLICIT NONE
@@ -61,5 +62,5 @@
       USE p4zrem          !  Remineralisation of organic matter
       USE p4zflx          !  Gas exchange
-      USE p4zice          !  Co-limitations of differents nutrients
+      USE p4zlim          !  Co-limitations of differents nutrients
       USE p4zprod         !  Growth rate of the 2 phyto groups
       USE p4zmicro        !  Sources and sinks of microzooplankton
@@ -70,5 +71,5 @@
       USE p4zpoc          !  Remineralization of organic particles
       USE p4zligand       !  Remineralization of organic ligands
-      USE p5zice          !  Co-limitations of differents nutrients
+      USE p5zlim          !  Co-limitations of differents nutrients
       USE p5zprod         !  Growth rate of the 2 phyto groups
       USE p5zmicro        !  Sources and sinks of microzooplankton
@@ -269,4 +270,11 @@
         & CALL p4z_flx_init      !  gas exchange 
 
+      ! Initialization of the sediment model
+      IF( ln_sediment) THEN
+         CALL sed_init
+      ELSE
+         ALLOCATE( profsed(2) )
+      ENDIF
+
       IF(lwp) WRITE(numout,*) 
       IF(lwp) WRITE(numout,*) '   ==>>>   Initialization of PISCES tracers done'
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/trcnam_pisces.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/trcnam_pisces.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/trcnam_pisces.F90	(revision 10345)
@@ -43,5 +43,5 @@
       CHARACTER(LEN=20)::   clname
       !!
-      NAMELIST/nampismod/ln_p2z, ln_p4z, ln_p5z, ln_ligand
+      NAMELIST/nampismod/ln_p2z, ln_p4z, ln_p5z, ln_ligand, ln_sediment
       !!----------------------------------------------------------------------
 
@@ -65,16 +65,18 @@
       IF(lwp) THEN                  ! control print
          WRITE(numout,*) '   Namelist : nampismod '
-         WRITE(numout,*) '      Flag to use LOBSTER model            ln_p2z    = ', ln_p2z
-         WRITE(numout,*) '      Flag to use PISCES standard model    ln_p4z    = ', ln_p4z
-         WRITE(numout,*) '      Flag to use PISCES quota    model    ln_p5z    = ', ln_p5z
-         WRITE(numout,*) '      Flag to ligand                       ln_ligand = ', ln_ligand
+         WRITE(numout,*) '      Flag to use LOBSTER model            ln_p2z      = ', ln_p2z
+         WRITE(numout,*) '      Flag to use PISCES standard model    ln_p4z      = ', ln_p4z
+         WRITE(numout,*) '      Flag to use PISCES quota    model    ln_p5z      = ', ln_p5z
+         WRITE(numout,*) '      Flag to ligand                       ln_ligand   = ', ln_ligand
+         WRITE(numout,*) '      Flag to use sediment                 ln_sediment = ', ln_sediment
       ENDIF
       !
       IF(lwp) THEN                         ! control print
          WRITE(numout,*)
-         IF( ln_p5z    )  WRITE(numout,*) '   ==>>>   PISCES QUOTA model is used'
-         IF( ln_p4z    )  WRITE(numout,*) '   ==>>>   PISCES STANDARD model is used'
-         IF( ln_p2z    )  WRITE(numout,*) '   ==>>>   LOBSTER model is used'
+         IF( ln_p5z      )  WRITE(numout,*) '   ==>>>   PISCES QUOTA model is used'
+         IF( ln_p4z      )  WRITE(numout,*) '   ==>>>   PISCES STANDARD model is used'
+         IF( ln_p2z      )  WRITE(numout,*) '   ==>>>   LOBSTER model is used'
          IF( ln_ligand )  WRITE(numout,*) '   ==>>>   Compute remineralization/dissolution of organic ligands'
+         IF( ln_sediment )  WRITE(numout,*) '   ==>>>   Sediment module is used'
       ENDIF
     
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/README.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/README.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/README.rst	(revision 10345)
@@ -0,0 +1,362 @@
+*********************
+Oceanic tracers (TOP)
+*********************
+
+.. contents::
+	:local:
+
+TOP (Tracers in the Ocean Paradigm) is the NEMO hardwired interface toward biogeochemical models and
+provide the physical constraints/boundaries for oceanic tracers.
+It consists of a modular framework to handle multiple ocean tracers, including also a variety of built-in modules.
+
+This component of the NEMO framework allows one to exploit available modules (see below) and
+further develop a range of applications, spanning from the implementation of a dye passive tracer to
+evaluate dispersion processes (by means of MY_TRC), track water masses age (AGE module),
+assess the ocean interior penetration of persistent chemical compounds (e.g., gases like CFC or even PCBs),
+up to the full set of equations involving marine biogeochemical cycles.
+
+Structure
+=========
+
+TOP interface has the following location in the source code ``./src/MBG/`` and
+the following modules are available:
+
+``TRP``
+	Interface to NEMO physical core for computing tracers transport
+
+``CFC``
+	Inert carbon tracers (CFC11,CFC12, SF6)
+
+``C14``
+	Radiocarbon passive tracer
+
+``AGE``
+	Water age tracking
+
+``MY_TRC``
+	Template for creation of new modules and external BGC models coupling
+
+``PISCES``
+	Built in BGC model.
+	See [https://www.geosci-model-dev.net/8/2465/2015/gmd-8-2465-2015-discussion.html Aumont et al. (2015)] for
+	a throughout description. |
+
+The usage of TOP is activated i) by including in the configuration definition  the component ``MBG`` and
+ii) by adding the macro ``key_top`` in the configuration CPP file
+(see for more details [http://forge.ipsl.jussieu.fr/nemo/wiki/Users "Learn more about the model"]).
+
+As an example, the user can refer to already available configurations in the code,
+``GYRE_PISCES`` being the NEMO biogeochemical demonstrator and
+``GYRE_BFM`` to see the required configuration elements to couple with an external biogeochemical model
+(see also Section 4) .
+
+Note that, since version 4.0, TOP interface core functionalities are activated by means of logical keys and
+all submodules preprocessing macros from previous versions were removed.
+
+Here below the list of preprocessing keys that applies to the TOP interface (beside ``key_top``):
+
+``key_iomput``
+	use XIOS I/O
+
+``key_zdfddm`` & ``key_zdftke`` & ``key_zdfgls``
+	vertical schemes (need to be updated after Merge2017 finalization)
+
+``key_trabbl``
+	bottom boundary layer parameterization
+
+``key_agrif``
+	enable AGRIF coupling
+
+``key_trdtrc`` & ``key_trdmxl_trc``
+	trend computation for tracers
+
+Synthetic Workflow
+==================
+
+A synthetic description of the TOP interface workflow is given below to summarize the steps involved in
+the computation of biogeochemical and physical trends and their time integration and outputs,
+by reporting also the principal Fortran subroutine herein involved.
+
+**Model initialization (OPA_SRC/nemogcm.F90)**
+
+call to trc_init (trcini.F90)
+
+  ↳ call trc_nam (trcnam.F90) to initialize TOP tracers and run setting
+
+  ↳ call trc_ini_sms, to initialize each submodule
+
+  ↳ call trc_ini_trp, to initialize transport for tracers
+
+  ↳ call trc_ice_ini, to initialize tracers in seaice
+
+  ↳ call trc_ini_state, read passive tracers from a restart or input data
+
+  ↳ call trc_sub_ini, setup substepping if {{{nn_dttrc /= 1}}}
+
+**Time marching procedure (OPA_SRC/stp.F90)**
+
+call to trc_stp.F90 (trcstp.F90)
+
+  ↳ call trc_sub_stp, averaging physical variables for sub-stepping
+
+  ↳ call trc_wri, call XIOS for output of data
+
+  ↳ call trc_sms, compute BGC trends for each submodule
+
+    ↳ call trc_sms_my_trc, includes also surface and coastal BCs trends
+
+  ↳ call trc_trp (TRP/trctrp.F90), compute physical trends
+
+    ↳ call trc_sbc, get trend due to surface concentration/dilution
+
+    ↳ call trc_adv, compute tracers advection
+
+    ↳ call to trc_ldf, compute tracers lateral diffusion
+
+    ↳ call to trc_zdf, vertical mixing and after tracer fields
+
+    ↳ call to trc_nxt, tracer fields at next time step. Lateral Boundary Conditions are solved in here.
+
+    ↳ call to trc_rad, Correct artificial negative concentrations
+
+  ↳ call trc_rst_wri, output tracers restart files
+
+Namelists walkthrough
+=====================
+
+namelist_top
+------------
+
+Here below are listed the features/options of the TOP interface accessible through the namelist_top_ref and
+modifiable by means of namelist_top_cfg (as for NEMO physical ones).
+
+Note that ## is used to refer to a number in an array field.
+
+.. literalinclude:: ../../namelists/namtrc_run
+
+.. literalinclude:: ../../namelists/namtrc
+
+.. literalinclude:: ../../namelists/namtrc_dta
+
+.. literalinclude:: ../../namelists/namtrc_adv
+
+.. literalinclude:: ../../namelists/namtrc_ldf
+
+.. literalinclude:: ../../namelists/namtrc_rad
+
+.. literalinclude:: ../../namelists/namtrc_dmp
+
+.. literalinclude:: ../../namelists/namtrc_ice
+
+.. literalinclude:: ../../namelists/namtrc_trd
+
+.. literalinclude:: ../../namelists/namtrc_bc
+
+.. literalinclude:: ../../namelists/namtrc_bdy
+
+.. literalinclude:: ../../namelists/namage
+
+Two main types of data structure are used within TOP interface to initialize tracer properties (1) and
+to provide related initial and boundary conditions (2).
+
+**1. TOP tracers initialization**: sn_tracer (namtrc)
+
+Beside providing name and metadata for tracers,
+here are also defined the use of initial ({{{sn_tracer%llinit}}}) and
+boundary ({{{sn_tracer%llsbc, sn_tracer%llcbc, sn_tracer%llobc}}}) conditions.
+
+In the following, an example of the full structure definition is given for two idealized tracers both with
+initial conditions given, while the first has only surface boundary forcing and
+the second both surface and coastal forcings:
+
+.. code-block:: fortran
+
+	!             !    name   !           title of the field            !   units    ! initial data ! sbc   !   cbc  !   obc  !
+	sn_tracer(1)  = 'TRC1'    , 'Tracer 1 Concentration                ',   ' - '    ,  .true.      , .true., .false., .true.
+	sn_tracer(2)  = 'TRC2 '   , 'Tracer 2 Concentration                ',   ' - '    ,  .true.      , .true., .true. , .false.
+
+As tracers in BGC models are increasingly growing,
+the same structure can be written also in a more compact and readable way:
+
+.. code-block:: fortran
+
+	!             !    name   !           title of the field            !   units    ! initial data !
+	sn_tracer(1)  = 'TRC1'    , 'Tracer 1 Concentration                ',   ' - '    ,   .true.
+	sn_tracer(2)  = 'TRC2 '   , 'Tracer 2 Concentration                ',   ' - '    ,   .true.
+	! sbc
+	sn_tracer(1)%llsbc = .true.
+	sn_tracer(2)%llsbc = .true.
+	! cbc
+	sn_tracer(2)%llcbc = .true.
+
+The data structure is internally initialized by code with dummy names and
+all initialization/forcing logical fields set to .false. .
+
+**2. Structures to read input initial and boundary conditions**: namtrc_dta (sn_trcdta), namtrc_bc (sn_trcsbc/sn_trccbc/sn_trcobc)
+
+The overall data structure (Fortran type) is based on the general one defined for NEMO core in the SBC component
+(see details in User Manual SBC Chapter on Input Data specification).
+
+Input fields are prescribed within namtrc_dta (with sn_trcdta structure),
+while Boundary Conditions are applied to the model by means of namtrc_bc,
+with dedicated structure fields for surface (sn_trcsbc), riverine (sn_trccbc), and
+lateral open (sn_trcobc) boundaries.
+
+The following example illustrates the data structure in the case of initial condition for
+a single tracer contained in the file named tracer_1_data.nc (.nc is implicitly assumed in namelist filename),
+with a doubled initial value, and located in the usr/work/model/inputdata/ folder:
+
+.. code-block:: fortran
+
+	!               !  file name             ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+	!               !                        !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+	  sn_trcdta(1)  = 'tracer_1_data'        ,        -12        ,  'TRC1'   ,    .false.   , .true. , 'yearly'  , ''       , ''       , ''
+	  rf_trfac(1) = 2.0
+	  cn_dir = “usr/work/model/inputdata/”
+
+Note that, the Lateral Open Boundaries conditions are applied on the segments defined for the physical core of NEMO
+(see BDY description in the User Manual).
+
+namelist_trc
+------------
+
+Here below the description of namelist_trc_ref used to handle Carbon tracers modules, namely CFC and C14.
+
+|||| &'''namcfc'''     !   CFC ||
+
+|||| &'''namc14_typ'''     !  C14 - type of C14 tracer, default values of C14/C and pco2 ||
+
+|||| &'''namc14_sbc'''     !  C14 - surface BC ||
+
+|||| &'''namc14_fcg'''     !  files & dates ||
+
+``MY_TRC`` interface for coupling external BGC models
+=====================================================
+
+The generalized interface is pivoted on MY_TRC module that contains template files to build the coupling between
+NEMO and any external BGC model.
+
+The call to MY_TRC is activated by setting ``ln_my_trc = .true.`` (in namtrc)
+
+The following 6 fortran files are available in MY_TRC with the specific purposes here described.
+
+``par_my_trc.F90``
+	This module allows to define additional arrays and public variables to be used within the MY_TRC interface
+
+``trcini_my_trc.F90``
+	Here are initialized user defined namelists and the call to the external BGC model initialization procedures to
+	populate general tracer array (trn and trb). Here are also likely to be defined suport arrays related to
+	system metrics that could be needed by the BGC model.
+
+``trcnam_my_trc.F90``
+	This routine is called at the beginning of trcini_my_trc and should contain the initialization of
+	additional namelists for the BGC model or user-defined code.
+
+``trcsms_my_trc.F90``
+	The routine performs the call to Boundary Conditions and its main purpose is to
+	contain the Source-Minus-Sinks terms due to the biogeochemical processes of the external model.
+	Be aware that lateral boundary conditions are applied in trcnxt routine.
+	IMPORTANT: the routines to compute the light penetration along the water column and
+	the tracer vertical sinking should be defined/called in here, as generalized modules are still missing in
+	the code.
+
+``trcice_my_trc.F90``
+	Here it is possible to prescribe the tracers concentrations in the seaice that will be used as
+	boundary conditions when ice melting occurs (nn_ice_tr =1 in namtrc_ice).
+	See e.g. the correspondent PISCES subroutine.
+
+``trcwri_my_trc.F90``
+	This routine performs the output of the model tracers (only those defined in namtrc) using IOM module
+	(see Manual Chapter “Output and Diagnostics”).
+	It is possible to place here the output of additional variables produced by the model,
+	if not done elsewhere in the code, using the call to iom_put.
+
+Coupling an external BGC model using NEMO framework
+===================================================
+
+The coupling with an external BGC model through the NEMO compilation framework can be achieved in
+different ways according to the degree of coding complexity of the Biogeochemical model, like e.g.,
+the whole code is made only by one file or it has multiple modules and interfaces spread across several subfolders.
+
+Beside the 6 core files of MY_TRC module, let’s assume an external BGC model named *MYBGC* and constituted by
+a rather essential coding structure, likely few Fortran files.
+The new coupled configuration name is *NEMO_MYBGC*.
+
+The best solution is to have all files (the modified ``MY_TRC`` routines and the BGC model ones) placed in
+a unique folder with root ``MYBGCPATH`` and to use the makenemo external readdressing of ``MY_SRC`` folder.
+
+The coupled configuration listed in ``work_cfgs.txt`` will look like
+
+::
+
+	NEMO_MYBGC OPA_SRC TOP_SRC
+
+and the related ``cpp_MYBGC.fcm`` content will be
+
+.. code-block:: perl
+
+	bld::tool::fppkeys  key_zdftke key_dynspg_ts key_iomput key_mpp_mpi key_top
+
+the compilation with ``makenemo`` will be executed through the following syntax
+
+.. code-block:: console
+
+	$ makenemo -n 'NEMO_MYBGC' -m '<arch_my_machine>' -j 8 -e '<MYBGCPATH>'
+
+The makenemo feature “-e” was introduced to readdress at compilation time the standard MY_SRC folder
+(usually found in NEMO configurations) with a user defined external one.
+
+The compilation of more articulated BGC model code & infrastructure, like in the case of BFM
+([http://www.bfm-community.eu/publications/bfmnemomanual_r1.0_201508.pdf BFM-NEMO coupling manual]),
+requires some additional features.
+
+As before, let’s assume a coupled configuration name *NEMO_MYBGC*,
+but in this case MYBGC model root becomes ``<MYBGCPATH>`` that contains 4 different subfolders for
+biogeochemistry, named ``initialization``, ``pelagic``, and ``benthic``, and
+a separate one named ``nemo_coupling`` including the modified ``MY_SRC`` routines.
+The latter folder containing the modified NEMO coupling interface will be still linked using
+the makenemo “-e” option.
+
+In order to include the BGC model subfolders in the compilation of NEMO code,
+it will be necessary to extend the configuration ``cpp_NEMO_MYBGC.fcm`` file to include the specific paths of
+``MYBGC`` folders, as in the following example
+
+.. code-block:: perl
+
+	bld::tool::fppkeys  key_zdftke key_dynspg_ts key_iomput key_mpp_mpi key_top
+	
+	src::MYBGC::initialization         <MYBGCPATH>/initialization
+	src::MYBGC::pelagic                <MYBGCPATH>/pelagic
+	src::MYBGC::benthic                <MYBGCPATH>/benthic
+	
+	bld::pp::MYBGC      1
+	bld::tool::fppflags::MYBGC   %FPPFLAGS
+	bld::tool::fppkeys           %bld::tool::fppkeys MYBGC_MACROS
+
+where *MYBGC_MACROS* is the space delimited list of macros used in *MYBGC* model for
+selecting/excluding specific parts of the code.
+The BGC model code will be preprocessed in the configuration ``BLD`` folder as for NEMO,
+but with an independent path, like ``NEMO_MYBGC/BLD/MYBGC/<subforlders>``.
+
+The compilation will be performed similarly to in the previous case with the following
+
+.. code-block:: console
+
+	$ makenemo -n 'NEMO_MYBGC' -m '<arch_my_machine>' -j 8 -e '<MYBGCPATH>/nemo_coupling'
+
+Note that, the additional lines specific for the BGC model source and build paths can be written into
+a separate file, e.g. named ``MYBGC.fcm``, and then simply included in the ``cpp_NEMO_MYBGC.fcm`` as follow
+
+.. code-block:: perl
+
+	bld::tool::fppkeys  key_zdftke key_dynspg_ts key_iomput key_mpp_mpi key_top
+	inc <MYBGCPATH>/MYBGC.fcm
+
+This will enable a more portable compilation structure for all MYBGC related configurations.
+
+**Important**: the coupling interface contained in nemo_coupling cannot be added using the FCM syntax,
+as the same files already exists in NEMO and they are overridden only with the readdressing of MY_SRC contents to
+avoid compilation conflicts due to duplicate routines.
+
+All modifications illustrated above, can be easily implemented using shell or python scripting to
+edit the NEMO configuration CPP.fcm file and to create the BGC model specific FCM compilation file with code paths.
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/TRP/trcdmp.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/TRP/trcdmp.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/TRP/trcdmp.F90	(revision 10345)
@@ -251,5 +251,5 @@
          ! -------------------
 
-         IF( cn_cfg == "orca" ) THEN
+         IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA") THEN
             !
             SELECT CASE ( nn_cfg )
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/trc.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/trc.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/trc.F90	(revision 10345)
@@ -122,4 +122,7 @@
    CHARACTER(len=20), PUBLIC, DIMENSION(jp_bdy) :: cn_trc        ! Choice of boundary condition for tracers
    INTEGER,           PUBLIC, DIMENSION(jp_bdy) :: nn_trcdmp_bdy !: =T Tracer damping
+   !
+   ! Vertical axis used in the sediment module
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   profsed
 !$AGRIF_DO_NOT_TREAT
    ! External data structure of BDY for TOP. Available elements: cn_obc, ll_trc, trcnow, dmp
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/trcdta.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/trcdta.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/trcdta.F90	(revision 10345)
@@ -217,20 +217,20 @@
          ELSE                                !==   z- or zps- coordinate   ==!
             ! zps-coordinate (partial steps) interpolation at the last ocean level
-            IF( ln_zps ) THEN
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     ik = mbkt(ji,jj) 
-                     IF( ik > 1 ) THEN
-                        zl = ( gdept_1d(ik) - gdept_0(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
-                        ptrcdta(ji,jj,ik) = (1.-zl) * ptrcdta(ji,jj,ik) + zl * ptrcdta(ji,jj,ik-1)
-                     ENDIF
-                     ik = mikt(ji,jj)
-                     IF( ik > 1 ) THEN
-                        zl = ( gdept_0(ji,jj,ik) - gdept_1d(ik) ) / ( gdept_1d(ik+1) - gdept_1d(ik) )
-                        ptrcdta(ji,jj,ik) = (1.-zl) * ptrcdta(ji,jj,ik) + zl * ptrcdta(ji,jj,ik+1)
-                     ENDIF
-                  END DO
-              END DO
-            ENDIF
+!            IF( ln_zps ) THEN
+!               DO jj = 1, jpj
+!                  DO ji = 1, jpi
+!                     ik = mbkt(ji,jj) 
+!                     IF( ik > 1 ) THEN
+!                        zl = ( gdept_1d(ik) - gdept_0(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
+!                        ptrcdta(ji,jj,ik) = (1.-zl) * ptrcdta(ji,jj,ik) + zl * ptrcdta(ji,jj,ik-1)
+!                     ENDIF
+!                     ik = mikt(ji,jj)
+!                     IF( ik > 1 ) THEN
+!                        zl = ( gdept_0(ji,jj,ik) - gdept_1d(ik) ) / ( gdept_1d(ik+1) - gdept_1d(ik) )
+!                        ptrcdta(ji,jj,ik) = (1.-zl) * ptrcdta(ji,jj,ik) + zl * ptrcdta(ji,jj,ik+1)
+!                     ENDIF
+!                  END DO
+!              END DO
+!            ENDIF
             !
          ENDIF
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/trcini.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/trcini.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/trcini.F90	(revision 10345)
@@ -174,9 +174,10 @@
       END DO
       !    
-      IF( ln_pisces  )   CALL trc_ini_pisces     !  PISCES model
-      IF( ln_my_trc  )   CALL trc_ini_my_trc     !  MY_TRC model
-      IF( ll_cfc     )   CALL trc_ini_cfc        !  CFC's
-      IF( ln_c14     )   CALL trc_ini_c14        !  C14 model
-      IF( ln_age     )   CALL trc_ini_age        !  AGE
+      IF( ln_pisces      )   CALL trc_ini_pisces     !  PISCES model
+      IF( ln_my_trc      )   CALL trc_ini_my_trc     !  MY_TRC model
+      IF( ll_cfc         )   CALL trc_ini_cfc        !  CFC's
+      IF( ln_c14         )   CALL trc_ini_c14        !  C14 model
+      IF( ln_age         )   CALL trc_ini_age        !  AGE
+      IF( .NOT.ln_pisces ) ALLOCATE( profsed(2) )
       !
       IF(lwp) THEN                   ! control print
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/trcrst.F90
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/trcrst.F90	(revision 10344)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/trcrst.F90	(revision 10345)
@@ -252,5 +252,5 @@
                ! parameters corresponding to nit000 - 1 (as we start the step
                ! loop with a call to day)
-               ndastp = ndate0        ! ndate0 read in the namelist in dom_nam
+               ndastp = ndate0 - 1       ! ndate0 read in the namelist in dom_nam
                nhour   =   nn_time0 / 100
                nminute = ( nn_time0 - nhour * 100 )
Index: MO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/tests/README
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/tests/README	(revision 10344)
+++ 	(revision )
@@ -1,7 +1,0 @@
-## List of available test cases is in demo_cfgs.txt
-
-## HOW TO COMPILE TEST CASES :
-
-In the same manner as ref. cfg with '-r' option, use makenemo with '-a' option
-
-./makenemo -n WAD2 -a WAD -m macport_osx -j 4
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/tests/README.rst
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/tests/README.rst	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/tests/README.rst	(revision 10345)
@@ -0,0 +1,119 @@
+**********************
+Explore the test cases
+**********************
+
+.. contents::
+	:local:
+
+List
+====
+
+  The description below is a brief description of the test cases available in NEMO. 
+
+ICEDYN
+------
+  
+  This test case illustrates the advection of an ice patch across a East/West and North/South periodic channel. 
+  This configuration can be used to test the advection of the ice patch in an AGRIF zoom (1:3) 
+  and across the AGRIF boundary or to test the ice advection schemes (Prather and Ultimate-Macho). 
+  In the latest case user need to remove ``key_agrif`` out of the CPP keys list. 
+
+  .. image:: _static/ICEDYN_UDIAG_43days_UM5.gif
+
+VORTEX
+------
+  
+  This test case illustrates the propagation of an anticyclonic eddy over a Beta plan and a flat bottom.
+  It is implemented here with an online refined subdomain (1:3) out of which the vortex propagates.
+  It serves as a benchmark for quantitative estimates of nesting errors as in Debreu et al. (2012) :cite:`DEBREU2012`,
+  Penven et al. (2006) :cite:`PENVEN2006` or Spall and Holland (1991) :cite:`SPALL1991`.
+  
+  The animation below (sea level anomaly in meters) illustrates with two 1:2 successively nested grids how
+  the vortex smoothly propagates out of the refined grids.
+  
+  .. image:: _static/VORTEX_anim.gif
+
+ISOMIP
+------
+
+  The purpose of this test case is to evaluate the impact of various schemes and new development with the iceshelf cavities circulation and melt.
+  This configuration served as initial assesment of the ice shelf module in Losh et al. (2008) :cite:`LOSCH2008` and Mathiot et al. (2017) :cite:`MATHIOT2017`. 
+  The default setup is the one described `here <http://staff.acecrc.org.au/~bkgalton/ISOMIP/test_cavities.pdf>`_.
+  
+  The figure below (meridional overturning circulation) illustrates the circulation generated after 10000 days by the ice shelf melting (ice pump).
+
+  .. image:: _static/ISOMIP_moc.png
+
+LOCK_EXCHANGE
+-------------
+
+  The LOCK EXCHANGE experiment is a classical fluid dynamics experiment that has been adapted
+  by Haidvogel and Beckmann (1999) :cite:`HAIDVOGEL1999` for testing advection schemes in ocean circulation models.
+  It has been used by several authors including Burchard and Bolding (2002) :cite:`BURCHARD2002` and Ilicak et al. (2012) :cite:`ILICAK2012`.
+  The LOCK EXCHANGE experiment can in particular illustrate the impact of different choices of numerical schemes 
+  and/or subgrid closures on spurious interior mixing.
+
+  Below the animation of the LOCK_EXCHANGE test case using the advection scheme FCT4 (forth order) for tracer and ubs for dynamics.
+
+  .. image:: _static/LOCK-FCT4_flux_ubs.gif
+
+OVERFLOW
+--------
+
+  The OVERFLOW experiment illustrates the impact of different choices of numerical schemes 
+  and/or subgrid closures on spurious interior mixing close to bottom topography. 
+  The OVERFLOW experiment is adapted from the non-rotating overflow configuration described 
+  in Haidvogel and Beckmann (1999) :cite:`HAIDVOGEL1999` and further used by Ilicak et al. (2012) :cite:`ILICAK2012`.
+  Here we can assess the behaviour of the second-order tracer advection scheme FCT2 and fortht-order FCT4, z-coordinate and sigma coordinate (...).
+
+  Below the animation of the OVERFLOW test case in sigma coordinate with the forth-order advection scheme FCT4.
+
+  .. image:: _static/OVF-sco_FCT4_flux_cen-ahm1000.gif
+
+WAD
+---
+
+  A set of simple closed basin geometries for testing the Wetting and drying capabilities. 
+  Examples range from a closed channel with EW linear bottom slope to a parabolic EW channel with a Gaussian ridge.
+  
+  Below the animation of the test case 7. This test case is a simple linear slope with a mid-depth shelf with an open boundary forced with a sinusoidally varying ssh.
+  This test case has been introduced to emulate a typical coastal application with a tidally forced open boundary with an adverse SSH gradient that, when released, creates a surge up the slope.
+  The parameters are chosen such that the surge rises above sea-level before falling back and oscillating towards an equilibrium position
+
+  .. image:: _static/wad_testcase_7.gif
+
+CANAL
+-----
+
+  East-west periodic canal of variable size with several initial states and associated geostrophic currents (zonal jets or vortex).
+
+  .. image::_static/CANAL_image.gif
+
+Compile test cases
+==================
+
+The compilation of the test cases is very similar to the manner the reference configurations are compiled.
+If you are not familiar on how to compile NEMO, it is first recomended to read :doc:`the instructions <install>`
+
+| In the same manner as the ref. cfg are compiled with '-r' option, test cases can be compile by the use of makenemo with '-a' option.
+
+| Here an example to compile a copy named WAD2 of the wetting and drying test case (WAD) on the macport_osx architecture on 4 cores:
+
+.. code-block:: console
+ 
+	$ ./makenemo -n WAD2 -a WAD -m macport_osx -j 4
+
+Run and analyse the test cases
+==============================
+
+There no requirement of specific input file for the test_cases presented here. The XIOS xml input files and namelist are already setup correctly. 
+For detailed description and Jupyter notebook, the reader is directed on
+the `NEMO test cases repository <http://github.com/NEMO-ocean/NEMO-examples>`_
+
+References
+==========
+
+.. bibliography:: test_cases.bib
+	:all:
+	:style: unsrt
+	:labelprefix: T
Index: /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/tests/test_cases.bib
===================================================================
--- /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/tests/test_cases.bib	(revision 10345)
+++ /NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/tests/test_cases.bib	(revision 10345)
@@ -0,0 +1,88 @@
+@book{HAIDVOGEL1999,
+   author = {D. B. Haidvogel and A. Beckmann},
+   publisher = {Imperial College Press, London},
+   year = {1999},
+   title = {Numerical ocean circulation modeling}
+}
+
+@book{BURCHARD2002,
+   title={GETM: A General Estuarine Transport Model; Scientific Documentation},
+   author={Burchard, Hans and Bolding, Karsten},
+   year={2002},
+   publisher={European Commission, Joint Research Centre, Institute for Environment and Sustainability}
+}
+
+@article{ILICAK2012,
+   title = "Spurious dianeutral mixing and the role of momentum closure",
+   journal = "Ocean Modelling",
+   volume = "45-46",
+   pages = "37 - 58",
+   year = "2012",
+   issn = "1463-5003",
+   doi = "10.1016/j.ocemod.2011.10.003",
+   author = "Mehmet Ilicak and Alistair J. Adcroft and Stephen M. Griffies and Robert W. Hallberg",
+   keywords = "Spurious dianeutral transport, Cabbeling, Overflows, Exchange-flow, Ocean models, Momentum transport, Tracer advection, Reference potential energy"
+}
+
+@article{DEBREU2012,
+   title = "Two-way nesting in split-explicit ocean models: Algorithms, implementation and validation",
+   journal = "Ocean Modelling",
+   volume = "49-50",
+   pages = "1 - 21",
+   year = "2012",
+   issn = "1463-5003",
+   doi = "10.1016/j.ocemod.2012.03.003",
+   author = "Laurent Debreu and Patrick Marchesiello and Pierrick Penven and Gildas Cambon",
+   keywords = "Two-way nesting, Finite difference method, Modeling, Boundary conditions, Coastal upwelling"
+}
+
+@article{PENVEN2006,
+   title = "Evaluation and application of the ROMS 1-way embedding procedure to the central california upwelling system",
+   journal = "Ocean Modelling",
+   volume = "12",
+   number = "1",
+   pages = "157 - 187",
+   year = "2006",
+   issn = "1463-5003",
+   doi = "10.1016/j.ocemod.2005.05.002",
+   author = "Pierrick Penven and Laurent Debreu and Patrick Marchesiello and James C. McWilliams",
+   keywords = "Ocean models, Boundary conditions, Embedding, Coastal upwelling, Mesoscale eddies, Eddy kinetic energy, North America, West Coast, Central upwelling system, Monterey Bay, 35–41°N, 128–121°W"
+}
+
+@article{SPALL1991,
+   author = {Spall, M. A. and Holland, W. R.},
+   title = {A Nested Primitive Equation Model for Oceanic Applications},
+   journal = {Journal of Physical Oceanography},
+   volume = {21},
+   number = {2},
+   pages = {205-220},
+   year = {1991},
+   doi = {10.1175/1520-0485(1991)021<0205:ANPEMF>2.0.CO;2},
+}
+
+@article{MATHIOT2017,
+   author = {Mathiot, P. and Jenkins, A. and Harris, C. and Madec, G.},
+   title = {Explicit representation and parametrised impacts of under ice shelf seas in the ${z}^{\ast}$ coordinate ocean model NEMO 3.6},
+   journal = {Geoscientific Model Development},
+   volume = {10},
+   year = {2017},
+   number = {7},
+   pages = {2849--2874},
+   url = {https://www.geosci-model-dev.net/10/2849/2017/},
+   doi = {10.5194/gmd-10-2849-2017}
+}
+
+@article{LOSCH2008,
+   author = {Losch, M.},
+   title = {Modeling ice shelf cavities in a z coordinate ocean general circulation model},
+   journal = {Journal of Geophysical Research: Oceans},
+   volume = {113},
+   year = {2008},
+   number = {C8},
+   pages = {},
+   keywords = {Ice shelf cavities, numerical ocean modeling, z coordinates},
+   doi = {10.1029/2007JC004368},
+   url = {https://agupubs.onlinelibrary.wiley.com/doi/abs/10.1029/2007JC004368},
+   eprint = {https://agupubs.onlinelibrary.wiley.com/doi/pdf/10.1029/2007JC004368},
+   abstract = {Processes at the ice shelf-ocean interface and in particular in ice shelf cavities around Antarctica have an observable effect on the solutions of basin scale to global coupled ice-ocean models. Despite this, these processes are not routinely represented in global ocean and climate models. It is shown that a new ice shelf cavity model for z coordinate models can reproduce results from an intercomparison project of earlier approaches with vertical ?~C or isopycnic coordinates. As a proof of concept, ice shelves are incorporated in a 100-year global integration of a z coordinate model. In this simulation, glacial meltwater can be traced as far as north as 15??S. The observed effects of processes in the ice shelf cavities agree with previous results from a ?~C coordinate model, notably the increase in sea ice thickness. However, melt rates are overestimated probably because the parameterization of basal melting does not suit the low resolution of this configuration.}
+}
