New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 10345 – NEMO

Changeset 10345


Ignore:
Timestamp:
2018-11-21T11:25:53+01:00 (5 years ago)
Author:
smasson
Message:

dev_r10164_HPC09_ESIWACE_PREP_MERGE: merge with trunk@10344, see #2133

Location:
NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE
Files:
8 deleted
66 edited
54 copied

Legend:

Unmodified
Added
Removed
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/INSTALL.rst

    r9596 r10345  
    1 Install the modelling framework (NEMO and XIOS) 
     1********************* 
     2Install the framework 
     3********************* 
    24 
    3 Last edition: 2018-02-14 21:32 CET by nicolasmartin 
     5.. contents:: 
     6   :local: 
     7       
     8Dependencies 
     9============ 
    410 
    5     Extract the NEMO code 
    6         Description of NEMOGCM directory tree 
    7     Extract and install XIOS 
    8     Setup your architecture configuration file 
    9     Compile and create NEMO executable 
    10         More options 
    11         Default behaviour 
    12         Tools used during the process 
    13         Examples 
    14     Running the model 
    15     Viewing and changing list of active CPP keys 
     11| The NEMO source code is written in Fortran 95 and part of its dependencies are already included (``./ext``): 
     12  AGRIF preprocessing program "conv", FCM build system and IOIPSL library for outputs. 
     13| And some Perl 5, Fortran compiler (ifort, gfortran, pgfortran, ...), MPI library (Open MPI or MPICH) 
    1614 
    17 Extract the NEMO code 
     15But The following dependencies should be from the official repositories of your Linux distribution but 
     16you will probably have to compile them from source for enabling parallel I/O support. 
    1817 
    19 Using your account registered here ('my_login' with password) 
     18- `HDF5`_   (C library) 
     19- `NetCDF`_ (C and Fortran libraries) 
     20 
     21Extract the source code 
     22======================= 
     23 
     24Download the source code 
     25------------------------ 
    2026 
    2127.. code:: console 
    22 svn --username 'mylogin' co http://forge.ipsl.jussieu.fr/nemo/svn/branches/2015/nemo_v3_6_STABLE/NEMOGCM 
    2328 
    24 Description of NEMOGCM directory tree 
     29   $ svn co http://forge.ipsl.jussieu.fr/nemo/svn/NEMO/releases/release-4.0 
    2530 
    26 The image below shows the directory tree: 
     31Description of directory tree 
     32----------------------------- 
    2733 
    28 simple table: 
    29     ARCH    Compilation option files, with format arch_compiler.fcm, the compiler name has to be provided with –m option 
    30     CONFIG  All configurations and a cpp.fcm file containing the list of CPP keys to each configuration 
    31     EXTERNAL    Package to implement an embedded model (AGRIF) 
    32     NEMO    FORTRAN source codes in several sub-directories 
    33     SETTE    Package to make tests to ensure the reproducibility and restartability of the code after changes 
    34     TOOLS    Useful softwares to different utilities 
     34+-----------+------------------------------------------------------------+ 
     35| Folder    | Purpose                                                    | 
     36+===========+============================================================+ 
     37| ``arch``  | Settings (per architecture-compiler pair)                  | 
     38+-----------+------------------------------------------------------------+ 
     39| ``cfgs``  | :doc:`Reference configurations <configurations>`           | 
     40+-----------+------------------------------------------------------------+ 
     41| ``doc``   | - ``latex``: reference manuals for |OPA|, |SI3| & |TOP|    | 
     42|           | - ``namelists``: k start guide                             | 
     43|           | - ``rst``:   quick start guide                             | 
     44+-----------+------------------------------------------------------------+ 
     45| ``ext``   | Dependencies included (AGRIF, FCM & IOIPSL)                | 
     46+-----------+------------------------------------------------------------+ 
     47| ``mk``    | Building  routines                                         | 
     48+-----------+------------------------------------------------------------+ 
     49| ``src``   | Modelling routines                                         | 
     50|           |                                                            | 
     51|           | - ``ICE``: |SI3| for sea ice                               | 
     52|           | - ``NST``: AGRIF for embedded zooms                        | 
     53|           | - ``OCE``: |OPA| for ocean dynamics                        | 
     54|           | - ``MBG``: |TOP| for tracers                               | 
     55+-----------+------------------------------------------------------------+ 
     56| ``tests`` | :doc:`Test cases <test_cases>` (unsupported)               | 
     57+-----------+------------------------------------------------------------+ 
     58| ``tools`` | :doc:`Utilities <tools>` to [pre|post]process data         | 
     59+-----------+------------------------------------------------------------+ 
    3560 
    3661Extract and install XIOS 
     62======================== 
    3763 
    3864Diagnostic outputs from NEMO are handled by the third party XIOS library. 
     
    4268 
    4369When you compile NEMO you will need to specify the following CPP keys: 
    44  
     70   
    4571    key_iomput 
    4672    key_mpp_mpi (if you want to run with multiple processes and/or use "detached mode" for the IOs system XIOS) 
     
    4874 
    4975Setup your architecture configuration file 
     76========================================== 
    5077 
    5178All 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. 
     
    5885 
    5986Compile and create NEMO executable 
     87================================== 
    6088 
    6189The 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. 
    6290As an example, compile GYRE with 'my_arch' to create a 'MY_GYRE' configuration: 
    6391 
    64    cd NEMOGCM/CONFIG; ./makenemo –m 'my_arch' –r GYRE -n 'MY_GYRE' 
     92.. code-block:: sh 
     93 
     94   ./makenemo –m 'my_arch' –r GYRE -n 'MY_GYRE' 
    6595 
    6696The 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). 
    6797 
    68     
     98+------------+----------------------------------------------------+ 
     99| Folder     | Purpose                                            | 
     100+============+====================================================+ 
     101| ``BLD``    |                                                    | 
     102+------------+----------------------------------------------------+ 
     103| ``EXP00``  |                                                    | 
     104+------------+----------------------------------------------------+ 
     105| ``EXPREF`` |                                                    | 
     106+------------+----------------------------------------------------+ 
     107| ``MY_SRC`` |                                                    | 
     108+------------+----------------------------------------------------+ 
     109| ``WORK``   |                                                    | 
     110+------------+----------------------------------------------------+ 
    69111 
    70     WORK 
    71  
    72     
    73  
    74     Folder with the symbolic links to all unpreprocessed routines considered in the configuration 
    75  
    76     BLD 
    77  
    78     
    79  
    80     Compilation folder (executables, headers files, libraries, preprocessed routines, flags, …) 
    81  
    82     EXP00 
    83  
    84     
    85  
    86     Computation folder for running the model (namelists, xml, executables and inputs-outputs) 
    87  
    88     MY_SRC 
    89  
    90     
    91  
    92     Folder intended to contain your customized routines (modified from initial ones or new entire routines) 
     112Folder with the symbolic links to all unpreprocessed routines considered in the configuration 
     113Compilation folder (executables, headers files, libraries, preprocessed routines, flags, …) 
     114Computation folder for running the model (namelists, xml, executables and inputs-outputs) 
     115Folder intended to contain your customised routines (modified from initial ones or new entire routines) 
    93116 
    94117After 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). 
    95118More options 
    96119 
    97         echo "Usage      : "${b_n} \ 
    98             " [-h] [-n name] [-m arch] [-d "dir1 dir2"] [-r conf] [-u conf] [-s Path] [-e Path] [-j No] [-v No] [-k 0/1]"; 
    99         echo " -h               : help"; 
    100         echo " -h institute : specific help for consortium members"; 
    101         echo " -n name      : config name, [-n help] to list existing configurations"; 
    102         echo " -m arch      : choose compiler, [-m help] to list existing compilers"; 
    103         echo " -d dir       : choose NEMO sub-directories"; 
    104         echo " -r conf      : choose reference configuration"; 
    105         echo " -u conf      : choose an unsupported (external) configuration"; 
    106         echo " -s Path      : choose alternative location for NEMO main directory"; 
    107         echo " -e Path      : choose alternative location for MY_SRC directory"; 
    108         echo " -j No        : number of processes used to compile (0=nocompilation)"; 
    109         echo " -v No        : set verbosity level for compilation [0-3]"; 
    110         echo " -k 0/1       : used cpp keys check (default = 1 -> check activated)"; 
    111         echo " -t dir       : temporary directory for compilation" 
    112         echo ""; 
     120.. 
     121   .. literalinclude:: 
    113122 
    114123Default behaviour 
     124----------------- 
    115125 
    116126    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. 
     
    118128 
    119129Tools used during the process 
     130----------------------------- 
    120131 
    121132    functions.sh : bash functions used by makenemo, for instance to create the WORK directory 
     
    124135 
    125136Examples 
     137-------- 
    126138 
    127139        echo "Example to install a new configuration MY_CONFIG"; 
     
    149161 
    150162Running the model 
     163================= 
    151164 
    152 Once makenemo has run successfully, the opa executable is available in CONFIG/"MY_CONFIG"/EXP00 
    153 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 
     165Once makenemo has run successfully, the opa executable is available in ``CONFIG/MY_CONFIG/EXP00`` 
     166For 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 
    154167 
    155168   cd 'MY_CONFIG'/EXP00 
     
    157170 
    158171Viewing and changing list of active CPP keys 
     172============================================ 
    159173 
    160 For a given configuration (here called MY_CONFIG), the list of active CPP keys can be found in 
     174For a given configuration (here called MY_CONFIG), the list of active CPP keys can be found in:: 
    161175 
    162    NEMOGCM/CONFIG/'MYCONFIG'/cpp_'MY_CONFIG'.fcm 
     176   NEMOGCM/CONFIG/'MYCONFIG'/cpp_'MY_CONFIG'.fcm 
    163177 
    164178This 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. 
     179 
     180.. _HDF5:   http://www.hdfgroup.org/downloads/hdf5 
     181.. _NetCDF: http://www.unidata.ucar.edu/downloads/netcdf 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/README.rst

    r9650 r10345  
    1 .. role:: rstblue 
    2 .. role:: rstgrey 
    3 .. role:: rstgreen 
     1:Authors: NEMO System Team 
     2:Release: |release| 
     3:Date:    |today| 
    44 
    5 ================ 
    6 NEMO Ocean Model 
    7 ================ 
     5`NEMO`_ for *Nucleus for European Modelling of the Ocean* is a state-of-the-art modelling framework for 
     6research activities and forecasting services in ocean and climate sciences. 
    87 
    9 NEMO_ (Nucleus for European Modelling of the Ocean) is a state-of-the-art modelling framework of  
    10 ocean related engines for oceanographic research, operational oceanography, seasonal forecast and  
    11 [paleo]climate studies. 
     8.. contents:: 
     9   :local: 
     10 
     11Overview 
     12======== 
    1213 
    1314The NEMO ocean model has 3 major components: 
    1415 
    15 - :rstblue:`OPA` is fundamental to all users by modelling the ocean [thermo]dynamics and  
    16   solving the primitive equations; 
    17 - :rstgrey:`LIM` for sea-ice simulates ice [thermo]dynamics, brine inclusions and  
    18   subgrid-scale thickness variations; 
    19 - :rstgreen:`TOP-PISCES` models biogeochemistry with TOP for  
    20   the on/offline oceanic tracers transport and PISCES for the biogeochemical processes. 
     16- |OPA| models the ocean [thermo]dynamics and solves the primitive equations 
     17  (``./src/OCE``) :cite:`NEMO_manual`; 
     18- |SI3| simulates ice [thermo]dynamics, brine inclusions and subgrid-scale thickness variations 
     19  (``./src/ICE``) :cite:`SI3_manual`; 
     20- |TOP| models the [on|off]line oceanic tracers transport and the biogeochemical processes 
     21  (``./src/MBG``) :cite:`TOP_manual`. 
    2122 
    22 These physical engines are described in their respective `reference publications`_. 
     23These physical core engines are described in their respective <reference publications> that must be cited for 
     24any work related to their use. 
    2325 
    24 They are complemented by a 2-way nesting software (AGRIF_) and  
    25 a versatile data assimilation interface with 3 different modules 
    26 (linear-tangent TAM, observational operators OBS, and increment ASM). 
     26Applications and capabilities 
     27============================= 
    2728 
    28 ------------ 
    29 Applications 
    30 ------------ 
     29Not only does the NEMO framework model the ocean circulation, 
     30it offers various features to enable 
    3131 
    32 | Distributed under CeCILL license (GNU GPL compatible - see ``LICENSE``),  
    33   the framework offers several builtins reference configurations to  
    34   check your computing architecture and evaluate the model skills and performances (``./cfgs``). 
    35 | The end user could also find some idealized test cases on the web to serve as examples and  
    36   to study particular processes. 
     32- Create :doc:`embedded zooms <zooms>` seamlessly with 2-way nesting package `AGRIF`_. 
     33- :doc:`Low cost biogeochemistry <coarsening>` and :doc:`alternative model opportunity <tracers>`. 
     34- Versatile :doc:`assimilation <assimilation>`. 
     35- :doc:`Output diagnostics <diagnostics>` with `XIOS`_ server. 
     36- :doc:`Coupling <coupling>` via `OASIS`_ for Earth system modelling. 
    3737 
    38 A set of tools is also provided to setup your own configuration and  
    39 [pre|post]process your data (``./tools``). 
     38| Several :doc:`builtins configurations <configurations>` are provided to assess the skills and performances of 
     39   the model which can be used as templates for :doc:`setting up a new configuration <setup>` (``./cfgs``). 
     40| The end user could also find some :doc:`idealised test cases <test_cases>` online to serve as templates and 
     41   to study particular processes (``./tests``). 
    4042 
    41 ------- 
    42 Options 
    43 ------- 
     43A set of :doc:`utilities <tools>` is also provided to [pre|post]process your data (``./tools``). 
    4444 
    45 For writing diagnostics in a efficient way, NEMO make use of XIOS_ server which  
    46 controlled the outputs using XML input file. 
     45Literature 
     46========== 
    4747 
    48 To enable Earth system modelling, NEMO can be interfaced via  
    49 OASIS_ coupleur to external components such as atmospheric models or  
    50 alternative models of sea-ice or biogeochemistry. 
     48:doc:`install` 
    5149 
    52 ------------- 
    53 Documentation 
    54 ------------- 
     50The reference documentation is archived online 
    5551 
    56 The NEMO reference manual can be generated from the LaTeX source code (``./doc``),  
    57 either in PDF or in HTML format, but it mights require some additionnal installations. 
     52+-------+-------------------+----------------+ 
     53|       | Reference manual  | |NEMO manual|_ | 
     54| |OPA| +-------------------+----------------+ 
     55|       | Quick start guide | |NEMO guide|_  | 
     56+-------+-------------------+----------------+ 
     57| |SI3|                     | |SI3 manual|_  | 
     58+---------------------------+----------------+ 
     59| |TOP|                     | |TOP manual|_  | 
     60+---------------------------+----------------+ 
    5861 
    59 In any case, both formats are available online on the `NEMO website`__. 
     62.. |NEMO manual| image:: http://zenodo.org/badge/DOI/10.5281/zenodo.1464816.svg 
     63.. |NEMO guide|  image:: http://zenodo.org/badge/DOI/10.5281/zenodo.1475325.svg 
     64.. |SI3 manual|  image:: http://zenodo.org/badge/DOI/10.5281/zenodo.1471689.svg 
     65.. |TOP manual|  image:: http://zenodo.org/badge/DOI/10.5281/zenodo.1471700.svg 
    6066 
    61 --------------------- 
     67| Reference manuals and quick start guide can be build from source and exported to HTML or PDF (``./doc``). 
     68| In any case, one can find them online: 
     69 
     70Since 2014 the project has a `Special Issue <http://www.geosci-model-dev.net/special_issue40.html>`_ in 
     71the open-access journal Geoscientific Model Development (GMD) from the European Geosciences Union (EGU). 
     72The main scope is to collect relevant manuscripts covering various topics and to provide a single portal to 
     73assess the model potential and evolution. 
     74 
     75Used by a wide audience, numerous :website:`associated projects <projects>` have been carried out and 
     76extensive :website:`bibliography <bibliography/publications>` published. 
     77 
    6278Community development 
    63 --------------------- 
     79===================== 
    6480 
    65 | The NEMO Consortium gathering 6 European institutes organises the sustainable development in order to  
    66   keep a reliable evolving system since 2008. 
    67 | It defined the multiyear development strategy which is implemented by the NEMO System Team. 
     81| The NEMO Consortium pulling together 5 European institutes (`CMCC`_, `CNRS`_, `MOI`_, `Met Office`_ and `NERC`_) 
     82   plans the sustainable development in order to keep a reliable evolving framework since 2008. 
     83| It defines the |NEMO strategy|_ which is implemented by the System Team on 
     84   a yearly basis in order to release a new version almost every four years. 
    6885 
    69 -------- 
    70 Acronyms 
    71 -------- 
     86.. |NEMO strategy| replace:: multi-year development strategy 
    7287 
    73 AGRIF 
    74  Adaptive Grid Refinement In Fortran 
    75  
    76 LIM 
    77  Louvain-la-Neuve Ice Model 
    78  
    79 OPA 
    80  "Océan PArallélisé" (french) 
    81  
    82 PISCES 
    83  Pelagic Interactions Scheme for Carbon and Ecosystem Studies 
    84  
    85 TAM 
    86  Tangent Adjoint Model 
    87  
    88 TOP 
    89  Tracers in Ocean Paradigm 
    90  
    91 XIOS 
    92  XML Input Output Server 
    93  
    94 ---- 
    95  
    96 .. _AGRIF:                  http://agrif.imag.fr 
    97 .. _Forge:                  http://forge.ipsl.jussieu.fr/nemo 
    98 .. _NEMO:                   http://www.nemo-ocean.eu 
    99 .. _OASIS:                  http://verc.enes.org/oasis 
    100 .. _reference publications: http://www.nemo-ocean.eu/bibliography/documentation 
    101 .. _XIOS:                   http://forge.ipsl.jussieu.fr/ioserver 
    102  
    103 .. __:  NEMO_ 
     88When the need arises, :forge:`working groups <wiki/WorkingGroups>` are created or resumed to 
     89gather the community expertise for advising on the development activities. 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/RELEASE_NOTES.rst

    r10150 r10345  
    1 ================ 
    2 NEMO 4.0 Release 
    3 ================ 
     1********************** 
     2What's new in NEMO 4.0 
     3********************** 
    44 
    55.. contents:: 
    6  
    7 ---------- 
    8 What's new 
    9 ---------- 
    10  
     6   :local: 
     7       
    118Original sea-ice component SI\ :sup:`3`\ 
    129======================================== 
     
    5047Define and install a separate repository for test cases to all easy contributions from the NEMO Users Community 
    5148 
    52 +-------------------+--------------------------------------------------------+------------------------------------+ 
    53 | Name              | Purpose                                                | References                         | 
    54 +===================+=================+======================================+====================================+ 
    55 | ``CANAL``         | East-west periodic canal of variable size with several |                                    | 
    56 |                   | initial states and associated geostrophic currents     |                                    | 
    57 |                   | (zonal jets or vortex).                                |                                    | 
    58 +-------------------+--------------------------------------------------------+------------------------------------+ 
    59 | ``ICEDYN``        | East-west + north-south periodic channel.              |                                    | 
    60 |                   | The common configuration includes an AGRIF zoom (1:3)  |                                    | 
    61 |                   | in the middle of the basin to test how an ice patch is |                                    | 
    62 |                   | advected through it but one can also test the          |                                    | 
    63 |                   | advection schemes (Prather and Ultimate-Macho) by      |                                    | 
    64 |                   | removing the ``key_agrif`` in the CPP keys.            |                                    | 
    65 +-------------------+--------------------------------------------------------+------------------------------------+ 
    66 | ``ISOMIP``        | Simple box configuration with an iceshelf with simple  | `Hunter 2006`_                     | 
    67 |                   | geometry on top.                                       |                                    | 
    68 |                   | The purpose of this test case is to evaluate the       |                                    | 
    69 |                   | impact of various schemes and new development with     |                                    | 
    70 |                   | iceshelf cavities.                                     |                                    | 
    71 +-------------------+--------------------------------------------------------+------------------------------------+ 
    72 | ``LOCK_EXCHANGE`` | Classical fluid dynamics experiment that has been      | - `Haidvogel and Beckmann 1999`_   | 
    73 |                   | adapted for testing advection schemes in ocean         | - `Burchard and Bolding 2002`_     | 
    74 |                   | circulation models.                                    | - `Ilıcak 2012`_                   | 
    75 |                   | This experiment can in particular illustrate the       |                                    | 
    76 |                   | impact of different choices of numerical schemes       |                                    | 
    77 |                   | and/or subgrid closures on spurious interior mixing.   |                                    | 
    78 +-------------------+--------------------------------------------------------+------------------------------------+ 
    79 | ``OVERFLOW``      | Adapted from the non-rotating overflow configuration   | - `Haidvogel and Beckmann 1999`_   | 
    80 |                   | Illustrates the impact of different choices of         | - `Ilıcak 2012`_                   | 
    81 |                   | numerical schemes and/or subgrid closures on spurious  |                                    | 
    82 |                   | interior mixing close to bottom topography.            |                                    | 
    83 +-------------------+--------------------------------------------------------+------------------------------------+ 
    84 | ``VORTEX``        | Illustrates the propagation of an anticyclonic eddy    | - `Debreu 2012`_                   | 
    85 |                   | over a Beta plan and flat bottom.                      | - `Penven 2006`_                   | 
    86 |                   | It is implemented here with an online refined          | - `Spall and Holland 1991`_        | 
    87 |                   | subdomain (thanks to AGRIF library) out of which the   |                                    | 
    88 |                   | vortex propagates and serves as a benchmark to         |                                    | 
    89 |                   | diagnose nesting errors.                               |                                    | 
    90 +-------------------+--------------------------------------------------------+------------------------------------+ 
    91 | ``WAD``           | Set of simple closed basin geometries for testing the  |                                    | 
    92 |                   | wetting and drying capabilities.                       |                                    | 
    93 |                   | Examples range from a closed channel with EW linear    |                                    | 
    94 |                   | bottom slope to a parabolic EW channel with a Gaussian |                                    | 
    95 |                   | ridge.                                                 |                                    | 
    96 +-------------------+--------------------------------------------------------+------------------------------------+ 
    97  
    98 ----------- 
    99 Improvments 
    100 ----------- 
    101  
    10249Core components 
    10350=============== 
     
    10855- The passive tracers transport component was redesigned toward a modular structure and 
    10956  users can enable each module directly through logical flags in namelist_top (no more Fortran macros!). 
    110 - TOP on-line user documentation is available on NEMO Trac platform (TOP-UserQuickGuide_) 
     57- TOP on-line user documentation is available on NEMO Trac platform (`TOP User Quick Guide`_) 
    11158- TOP currently accounts for the following 5 modules: 
    11259 
     
    13077AGRIF (embedded zooms) 
    13178---------------------- 
     79 
     80The NEMO 4.0 includes new capabilities, configurations and test cases with AGRIF: 
     81 
     82.. role:: underline 
     83   :class: underline 
     84 
     85:underline:`New capabilities from NEMO 3.6 to NEMO 4.0` 
     86 
     87AGRIF is continuously maintained so that it could be activated with all NEMO components (OPA, sea-ice, TOP). 
     88Depending on NEMO version, it is nevertheless not the case so that some options may not be compatible with 
     89the use of online grid refinement. 
     90Check out the table below to know the status according to the NEMO release you may use. 
     91 
     92:underline:`Status of available options with AGRIF (if not listed, option is compatible with AGRIF)`: 
     93 
     94+--------------------------------------------------------+----------------+---------------------+ 
     95|                                                        | NEMO 3.6       | NEMO 4.0            | 
     96+========================================================+================+=====================+ 
     97| LIM2                                                   | yes            | ``-``               | 
     98+--------------------------------------------------------+----------------+---------------------+ 
     99| LIM3/SI3                                               | no             | yes                 | 
     100+--------------------------------------------------------+----------------+---------------------+ 
     101| TOP                                                    | yes            | yes                 | 
     102+--------------------------------------------------------+----------------+---------------------+ 
     103| GLS vertical mixing                                    | no             | yes                 | 
     104+--------------------------------------------------------+----------------+---------------------+ 
     105| z*                                                     | no             | yes                 | 
     106+--------------------------------------------------------+----------------+---------------------+ 
     107| z~                                                     | no             | no                  | 
     108+--------------------------------------------------------+----------------+---------------------+ 
     109| Lagrangian icebergs                                    | no             | no                  | 
     110+--------------------------------------------------------+----------------+---------------------+ 
     111| East-west periodic and/or north fold bcs in zooms      | no             | no                  | 
     112+--------------------------------------------------------+----------------+---------------------+ 
     113| Online timing                                          | no             | no                  | 
     114+--------------------------------------------------------+----------------+---------------------+ 
     115| Stochastic parameterization                            | no             | no                  | 
     116+--------------------------------------------------------+----------------+---------------------+ 
     117| Vertical coordinate change in zooms (``key_vertical``) | no             | yes, but not tested | 
     118+--------------------------------------------------------+----------------+---------------------+ 
     119| Number of ghost cells                                  | 1 (hard coded) | 3 (parameter)       | 
     120+--------------------------------------------------------+----------------+---------------------+ 
     121 
     122[Important notice concerning the change of ghost cells number] 
     123 
     124The default number of ghost cells (i.e. the number of cells that serve as open boundary data provision) has been 
     125increased from 1 to 3 in NEMO 4.0. 
     126This allows to properly handle boundary conditions for numerical schemes that 
     127have a discretization order greater than 2. 
     128On the user point of view this does not change anything++ except in the definition of level 1 grids in 
     129the ``AGRIF_FixedGrids.in`` file. 
     130In order to retrieve exactly the position of a nested grid in NEMO 4.0 one has to shift indices by 
     1312 points to the south-west. 
     132Taking the ``ICEDYN`` example above for NEMO 4.0, the "old" NEMO 3.6 corresponding file would contain:: 
     133 
     134   1 
     135   36 65 36 65 3 3 3 
     136   0 
     137 
     138++ Child grid output files are now greater by 4 points in each direction. 
    132139 
    133140- Now compatible with new sea ice component and z* coordinate 
     
    159166- Wave coupling: large scale wave interaction process added in momentum and tracer equations 
    160167- Remove the acceleration of convergence 
    161    
     168 
    162169Numerics 
    163170-------- 
     
    197204 
    198205.. _sea ice working group:       http://forge.ipsl.jussieu.fr/nemo/wiki/WorkingGroups/SI3 
    199 .. _TOP-UserQuickGuide:          http://forge.ipsl.jussieu.fr/nemo/wiki/WorkingGroups/top-dg/TOP-UserQuickGuide 
    200  
    201 .. _Hunter 2006:                 http://staff.acecrc.org.au/~bkgalton/ISOMIP/test_cavities.pdf 
     206.. _TOP User Quick Guide:        http://forge.ipsl.jussieu.fr/nemo/wiki/WorkingGroups/top-dg/TOP-UserQuickGuide 
     207 
     208.. The following references should be in the manual bibliographies and referenced via 'bibliography' directive 
    202209.. _Brodeau 2017:                http://doi.org/10.1175/JPO-D-16-0169.1 
    203 .. _Haidvogel and Beckmann 1999: http://hdl.handle.net/10013/epic.11761 
    204 .. _Burchard and Bolding 2002:   http://www.researchgate.net/publication/258128069_GETM_A_General_Estuarine_Transport_Model_Scientific_Documentation 
    205 .. _Ilıcak 2012:                 http://doi.org/10.1016/j.ocemod.2011.10.003 
    206 .. _Debreu 2012:                 http://doi.org/10.1016/j.ocemod.2012.03.003 
    207 .. _Penven 2006:                 http://doi.org/10.1016/j.ocemod.2005.05.002 
    208 .. _Spall and Holland 1991:      http://www.researchgate.net/publication/232101325_A_Nested_Primitive_Equation_Model_for_Oceanic_Applications 
    209210.. _Holland 2012:                http://doi.org/10.1175/JCLI-D-11-00078.1 
    210211.. _Lupkes 2012:                 http://doi.org/10.1029/2012JD017630 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_ICE_PISCES/EXPREF/context_nemo.xml

    r9930 r10345  
    66<context id="nemo"> 
    77<!-- $id$ --> 
    8     <variable_definition> 
    9     <!-- Year of time origin for NetCDF files; defaults to 1800 --> 
    10        <variable id="ref_year" type="int"   > 1800 </variable> 
    11        <variable id="rau0"     type="float" > 1026.0 </variable> 
    12        <variable id="cpocean"  type="float" > 3991.86795711963 </variable> 
    13        <variable id="convSpsu" type="float" > 0.99530670233846  </variable> 
    14        <variable id="rhoic"    type="float" > 917.0 </variable> 
    15        <variable id="rhosn"    type="float" > 330.0 </variable> 
    16        <variable id="missval"  type="float" > 1.e20 </variable> 
    17     </variable_definition> 
    188<!-- Fields definition --> 
    19     <field_definition src="./field_def_nemo-oce.xml"/>    <!--  NEMO ocean dynamics     --> 
    20     <field_definition src="./field_def_nemo-ice.xml"/>    <!--  NEMO sea-ice model      --> 
    21     <field_definition src="./field_def_nemo-pisces.xml"/> <!--  NEMO ocean biology      --> 
     9    <field_definition src="./field_def_nemo-oce.xml"/>    <!--  NEMO ocean dynamics     -->  
     10    <field_definition src="./field_def_nemo-ice.xml"/>    <!--  NEMO sea-ice model      -->  
     11    <field_definition src="./field_def_nemo-pisces.xml"/> <!--  NEMO ocean biology      -->  
    2212 
    2313<!-- Files definition --> 
    24     <file_definition src="./file_def_nemo-oce.xml"/>     <!--  NEMO ocean dynamics      --> 
    25     <file_definition src="./file_def_nemo-ice.xml"/>     <!--  NEMO sea-ice model       --> 
    26     <file_definition src="./file_def_nemo-pisces.xml"/>  <!--  NEMO ocean biology       --> 
     14    <file_definition src="./file_def_nemo-oce.xml"/>     <!--  NEMO ocean dynamics      -->  
     15    <file_definition src="./file_def_nemo-ice.xml"/>     <!--  NEMO sea-ice model       -->  
     16    <file_definition src="./file_def_nemo-pisces.xml"/>  <!--  NEMO ocean biology       -->  
    2717    <!--  
    2818============================================================================================================ 
     
    3222     
    3323    <axis_definition> 
    34       <axis id="deptht"  long_name="Vertical T levels"  unit="m" positive="down" /> 
    35       <axis id="depthu"  long_name="Vertical U levels"  unit="m" positive="down" /> 
    36       <axis id="depthv"  long_name="Vertical V levels"  unit="m" positive="down" /> 
    37       <axis id="depthw"  long_name="Vertical W levels"  unit="m" positive="down" /> 
    38       <axis id="nfloat"  long_name="Float number"       unit="-"                 /> 
    39       <axis id="icbcla"  long_name="Iceberg class"      unit="1"                 /> 
    40       <axis id="ncatice" long_name="Ice category"       unit="1"                 /> 
    41       <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"              /> 
    42       <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"              /> 
     24      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" /> 
     25      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" /> 
     26      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" /> 
     27      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" /> 
     28      <axis id="profsed" long_name="Vertical S levels" unit="cm" positive="down" /> 
     29      <axis id="nfloat" long_name="Float number"      unit="-"                 /> 
     30      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               /> 
     31      <axis id="ncatice" long_name="Ice category"       unit="1"               /> 
     32      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            /> 
     33      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            /> 
    4334    </axis_definition> 
    4435  
     
    4637   
    4738    <grid_definition src="./grid_def_nemo.xml"/> 
    48  
     39     
    4940</context> 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg

    r10075 r10345  
    8888   nn_fwb      = 2         !  FreshWater Budget:  
    8989   !                       !    =2 annual global mean of e-p-r set to zero 
     90   ln_wave     = .false.   !  Activate coupling with wave  (T => fill namsbc_wave) 
     91   ln_cdgw     = .false.   !  Neutral drag coefficient read from wave model (T => ln_wave=.true. & fill namsbc_wave) 
     92   ln_sdw      = .false.   !  Read 2D Surf Stokes Drift & Computation of 3D stokes drift (T => ln_wave=.true. & fill namsbc_wave)  
     93   nn_sdrift   =  0        !  Parameterization for the calculation of 3D-Stokes drift from the surface Stokes drift 
     94      !                    !   = 0 Breivik 2015 parameterization: v_z=v_0*[exp(2*k*z)/(1-8*k*z)] 
     95      !                    !   = 1 Phillips:                      v_z=v_o*[exp(2*k*z)-beta*sqrt(-2*k*pi*z)*erfc(sqrt(-2*k*z))] 
     96      !                    !   = 2 Phillips as (1) but using the wave frequency from a wave model 
     97   ln_tauwoc   = .false.   !  Activate ocean stress modified by external wave induced stress (T => ln_wave=.true. & fill namsbc_wave) 
     98   ln_tauw     = .false.   !  Activate ocean stress components from wave model 
     99   ln_stcor    = .false.   !  Activate Stokes Coriolis term (T => ln_wave=.true. & ln_sdw=.true. & fill namsbc_wave) 
    90100/ 
    91101!----------------------------------------------------------------------- 
     
    151161/ 
    152162!----------------------------------------------------------------------- 
     163&namsbc_wave   ! External fields from wave model                        (ln_wave=T) 
     164!----------------------------------------------------------------------- 
     165/ 
     166!----------------------------------------------------------------------- 
    153167&namberg       !   iceberg parameters                                   (default: OFF) 
    154168!----------------------------------------------------------------------- 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_pisces_cfg

    r9572 r10345  
    1616/ 
    1717!----------------------------------------------------------------------- 
    18 &namp4zice     !   parameters for nutrient limitations for PISCES std  - ln_p4z 
     18&namp4zlim     !   parameters for nutrient limitations for PISCES std  - ln_p4z 
    1919!----------------------------------------------------------------------- 
    2020/ 
    2121!----------------------------------------------------------------------- 
    22 &namp5zice     !   parameters for nutrient limitations PISCES QUOTA    - ln_p5z 
     22&namp5zlim     !   parameters for nutrient limitations PISCES QUOTA    - ln_p5z 
    2323!----------------------------------------------------------------------- 
    2424/ 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_OFF_PISCES/EXPREF/context_nemo.xml

    r9930 r10345  
    2323      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" /> 
    2424      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" /> 
     25      <axis id="profsed" long_name="Vertical S levels" unit="cm" positive="down" /> 
    2526      <axis id="nfloat" long_name="Float number"      unit="-"                 /> 
    2627      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               /> 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/ORCA2_OFF_PISCES/EXPREF/namelist_pisces_cfg

    r9572 r10345  
    1717/ 
    1818!----------------------------------------------------------------------- 
    19 &namp4zice     !   parameters for nutrient limitations for PISCES std  - ln_p4z 
     19&namp4zlim     !   parameters for nutrient limitations for PISCES std  - ln_p4z 
    2020!----------------------------------------------------------------------- 
    2121/ 
    2222!----------------------------------------------------------------------- 
    23 &namp5zice     !   parameters for nutrient limitations PISCES QUOTA    - ln_p5z 
     23&namp5zlim     !   parameters for nutrient limitations PISCES QUOTA    - ln_p5z 
    2424!----------------------------------------------------------------------- 
    2525/ 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/field_def_nemo-pisces.xml

    r9539 r10345  
    115115 
    116116     </field_group> 
     117 
     118     <!-- SEDIMENT variables on T sediment grid  --> 
     119     <field_group id="sed_T" grid_ref="grid_T_3DS"> 
     120       <field id="SedDIC"          long_name="Dissolved inorganic Concentration"        unit="mmol/m3" /> 
     121       <field id="SedAlkalini"     long_name="Total Alkalinity Concentration"           unit="mmol/m3" /> 
     122       <field id="SedO2"           long_name="Oxygen Concentration"                     unit="mmol/m3" /> 
     123       <field id="SedCaCO3"        long_name="Calcite Concentration"                    unit="%" /> 
     124       <field id="SedPOS"          long_name="Semi-ref POC Concentration"               unit="%" /> 
     125       <field id="SedPOR"          long_name="Refractory POC Concentration"             unit="%" /> 
     126       <field id="SedPO4"          long_name="Phosphate Concentration"                  unit="mmol/m3" /> 
     127       <field id="SedPOC"          long_name="Labile POC Concentration"                 unit="%" /> 
     128       <field id="SedSil"          long_name="Silicate Concentration"                   unit="mmol/m3" /> 
     129       <field id="SedFe2"          long_name="Fe2+ Concentration"                       unit="mmol/m3" /> 
     130       <field id="SedBSi"          long_name="Biogenic Silicate Concentration"          unit="%" /> 
     131       <field id="SedNO3"          long_name="Nitrate Concentration"                    unit="mmol/m3" /> 
     132       <field id="SedNH4"          long_name="Ammonium Concentration"                   unit="mmol/m3" /> 
     133       <field id="SedH2S"          long_name="H2S Concentration"                        unit="mmol/m3" /> 
     134       <field id="SedSO4"          long_name="SO4 Concentration"                        unit="mmol/m3" /> 
     135       <field id="SedClay"         long_name="Clay Concentration"                       unit="%" /> 
     136       <field id="SedFeO"          long_name="Fe(OH)3 Concentration"                    unit="%" /> 
     137       <field id="SedFeS"          long_name="FeS Concentration"                        unit="%" /> 
     138       <field id="SedpH"           long_name="PH"                                       unit="1"          /> 
     139       <field id="SedCO3por"       long_name="Bicarbonates"                             unit="mol/m3" /> 
     140     </field_group> 
     141 
     142     <!-- SEDIMENT additional variables on T sediment grid  --> 
     143     <field_group id="Diag_S" grid_ref="grid_T_2D"> 
     144       <field id="FlxSi"       long_name="Si sediment flux"                        unit="mol/cm2/s"     /> 
     145       <field id="FlxO2"       long_name="O2 sediment flux"                        unit="mol/cm2/s"     /> 
     146       <field id="FlxDIC"      long_name="DIC sediment flux"                       unit="mol/cm2/s"     /> 
     147       <field id="FlxNO3"      long_name="NO3 sediment flux"                       unit="mol/cm2/s"     /> 
     148       <field id="FlxPO4"      long_name="PO4 sediment flux"                       unit="mol/cm2/s"     /> 
     149       <field id="FlxAlkalini" long_name="Alkalinity sediment flux"                unit="mol/cm2/s"     /> 
     150       <field id="FlxNH4"      long_name="Ammonium sediment flux"                  unit="mol/cm2/s"     /> 
     151       <field id="FlxH2S"      long_name="H2S sediment flux"                       unit="mol/cm2/s"     /> 
     152       <field id="FlxSO4"      long_name="SO4 sediment flux"                       unit="mol/cm2/s"     /> 
     153       <field id="FlxFe2"      long_name="Fe2+ sediment flux"                      unit="mol/cm2/s"     /> 
     154       <field id="Flxtot"      long_name="Sediment net burial rate"                unit="cm/s"     /> 
     155       <field id="dzdep"       long_name="Sedimentation rate"                      unit="cm/s"     /> 
     156       <field id="sflxclay"    long_name="Clay sedimentation rate"                 unit="g/m2/s"     /> 
     157       <field id="sflxcal"     long_name="Calcite sedimentation rate"              unit="mol/m2/s"     /> 
     158       <field id="sflxbsi"     long_name="BSi Sedimentation rate"                  unit="mol/m2/s"     /> 
     159       <field id="sflxpoc"     long_name="POC Sedimentation rate"                  unit="mol/m2/s"     /> 
     160       <field id="sflxfeo"     long_name="Fe(OH)3 Sedimentation rate"              unit="mol/m2/s"     /> 
     161</field_group> 
    117162 
    118163     <!-- PISCES additional diagnostics on T grid  --> 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/grid_def_nemo.xml

    r9930 r10345  
    1515         <domain id="grid_T" /> 
    1616         <axis id="deptht" /> 
     17       </grid> 
     18        <!--  --> 
     19       <grid id="grid_T_3DS" > 
     20         <domain id="grid_T" /> 
     21         <axis id="profsed" /> 
    1722       </grid> 
    1823        <!--  --> 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/namelist_pisces_ref

    r10111 r10345  
    1717  ln_p5z    = .false.        !  PISCES QUOTA model used 
    1818  ln_ligand = .false.        !  Enable  organic ligands 
     19  ln_sediment = .false.      !  Enable sediment module 
    1920/ 
    2021!----------------------------------------------------------------------- 
     
    6263/ 
    6364!----------------------------------------------------------------------- 
    64 &namp4zice     !   parameters for nutrient limitations for PISCES std  - ln_p4z 
     65&namp4zlim     !   parameters for nutrient limitations for PISCES std  - ln_p4z 
    6566!----------------------------------------------------------------------- 
    6667   concnno3   =  1.e-6    ! Nitrate half saturation of nanophytoplankton 
     
    8687/ 
    8788!----------------------------------------------------------------------- 
    88 &namp5zice     !   parameters for nutrient limitations PISCES QUOTA    - ln_p5z 
     89&namp5zlim     !   parameters for nutrient limitations PISCES QUOTA    - ln_p5z 
    8990!----------------------------------------------------------------------- 
    9091   concnno3   =  3e-6     ! Nitrate half saturation of nanophytoplankton 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/cfgs/SHARED/namelist_ref

    r10075 r10345  
    481481   !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask ! 
    482482   !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   ! 
    483    sn_cdg      =  'sdw_wave'             ,        1          , 'drag_coeff' ,  .true.  , .false., 'daily'   ,  ''             , ''       , '' 
    484    sn_usd      =  'sdw_wave'             ,        1          , 'u_sd2d'     ,  .true.  , .false., 'daily'   ,  ''             , ''       , '' 
    485    sn_vsd      =  'sdw_wave'             ,        1          , 'v_sd2d'     ,  .true.  , .false., 'daily'   ,  ''             , ''       , '' 
    486    sn_hsw      =  'sdw_wave'             ,        1          , 'hs'         ,  .true.  , .false., 'daily'   ,  ''             , ''       , '' 
    487    sn_wmp      =  'sdw_wave'             ,        1          , 'wmp'        ,  .true.  , .false., 'daily'   ,  ''             , ''       , '' 
    488    sn_wfr      =  'sdw_wave'             ,        1          , 'wfr'        ,  .true.  , .false., 'daily'   ,  ''             , ''       , '' 
    489    sn_wnum     =  'sdw_wave'             ,        1          , 'wave_num'   ,  .true.  , .false., 'daily'   ,  ''             , ''       , '' 
    490    sn_tauwoc   =  'sdw_wave'             ,        1          , 'wave_stress',  .true.  , .false., 'daily'   ,  ''             , ''       , '' 
    491    sn_tauwx    =  'sdw_wave'             ,        1          , 'wave_stress',  .true.  , .false., 'daily'   ,  ''             , ''       , '' 
    492    sn_tauwy    =  'sdw_wave'             ,        1          , 'wave_stress',  .true.  , .false., 'daily'   ,  ''             , ''       , '' 
     483   sn_cdg      =  'sdw_ecwaves_orca2'    ,        6          , 'drag_coeff' ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , '' 
     484   sn_usd      =  'sdw_ecwaves_orca2'    ,        6          , 'u_sd2d'     ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , '' 
     485   sn_vsd      =  'sdw_ecwaves_orca2'    ,        6          , 'v_sd2d'     ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , '' 
     486   sn_hsw      =  'sdw_ecwaves_orca2'    ,        6          , 'hs'         ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , '' 
     487   sn_wmp      =  'sdw_ecwaves_orca2'    ,        6          , 'wmp'        ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , '' 
     488   sn_wfr      =  'sdw_ecwaves_orca2'    ,        6          , 'wfr'        ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , '' 
     489   sn_wnum     =  'sdw_ecwaves_orca2'    ,        6          , 'wave_num'   ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , '' 
     490   sn_tauwoc   =  'sdw_ecwaves_orca2'    ,        6          , 'wave_stress',  .true.  , .true. , 'yearly'  ,  ''              , ''       , '' 
     491   sn_tauwx    =  'sdw_ecwaves_orca2'    ,        6          , 'wave_stress',  .true.  , .true. , 'yearly'  ,  ''              , ''       , '' 
     492   sn_tauwy    =  'sdw_ecwaves_orca2'    ,        6          , 'wave_stress',  .true.  , .true. , 'yearly'  ,  ''              , ''       , '' 
    493493/ 
    494494!----------------------------------------------------------------------- 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE/icedyn_adv_umx.F90

    r10292 r10345  
    229229         ! 
    230230         DO jl = 1, ipl 
    231             DO jj = 1, jpjm1 
     231            DO jj = 2, jpjm1 
    232232               DO ji = 1, fs_jpim1   ! vector opt. 
    233233                  zfu_ho(ji,jj,jl) = puc(ji,jj) * zt_u(ji,jj,jl) 
     234               END DO 
     235            END DO 
     236         END DO 
     237         DO jl = 1, ipl 
     238            DO jj = 1, jpjm1 
     239               DO ji = fs_2, fs_jpim1   ! vector opt. 
    234240                  zfv_ho(ji,jj,jl) = pvc(ji,jj) * zt_v(ji,jj,jl) 
    235241               END DO 
     
    242248      ! -------------------------------------------------- 
    243249      DO jl = 1, ipl 
    244          DO jj = 1, jpjm1 
     250         DO jj = 2, jpjm1 
    245251            DO ji = 1, fs_jpim1   ! vector opt. 
    246252               zfu_ho(ji,jj,jl) = zfu_ho(ji,jj,jl) - zfu_ups(ji,jj,jl) 
     253            END DO 
     254         END DO 
     255      END DO 
     256      DO jl = 1, ipl 
     257         DO jj = 1, jpjm1 
     258            DO ji = fs_2, fs_jpim1   ! vector opt. 
    247259               zfv_ho(ji,jj,jl) = zfv_ho(ji,jj,jl) - zfv_ups(ji,jj,jl) 
    248260            END DO 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE/icedyn_rhg_evp.F90

    r10297 r10345  
    2626   USE sbc_ice , ONLY : utau_ice, vtau_ice, snwice_mass, snwice_mass_b 
    2727   USE ice            ! sea-ice: ice variables 
     28   USE icevar         ! ice_var_sshdyn 
    2829   USE icedyn_rdgrft  ! sea-ice: ice strength 
    2930   USE bdy_oce , ONLY : ln_bdy  
     
    143144      REAL(wp), DIMENSION(jpi,jpj) ::   zs1, zs2, zs12                  ! stress tensor components 
    144145      REAL(wp), DIMENSION(jpi,jpj) ::   zu_ice, zv_ice, zresr           ! check convergence 
    145       REAL(wp), DIMENSION(jpi,jpj) ::   zpice                           ! array used for the calculation of ice surface slope: 
     146      REAL(wp), DIMENSION(jpi,jpj) ::   zssh_lead_m                     ! array used for the calculation of ice surface slope: 
    146147      !                                                                 !    ocean surface (ssh_m) if ice is not embedded 
    147148      !                                                                 !    ice top surface if ice is embedded    
     
    261262      !------------------------------------------------------------------------------! 
    262263 
    263       IF( ln_ice_embd ) THEN             !== embedded sea ice: compute representative ice top surface ==! 
    264          !                                             
    265          ! average interpolation coeff as used in dynspg = (1/nn_fsbc)   * {SUM[n/nn_fsbc], n=0,nn_fsbc-1} 
    266          !                                               = (1/nn_fsbc)^2 * {SUM[n]        , n=0,nn_fsbc-1} 
    267          zintn = REAL( nn_fsbc - 1 ) / REAL( nn_fsbc ) * 0.5_wp      
    268          ! 
    269          ! average interpolation coeff as used in dynspg = (1/nn_fsbc)   *    {SUM[1-n/nn_fsbc], n=0,nn_fsbc-1} 
    270          !                                               = (1/nn_fsbc)^2 * (nn_fsbc^2 - {SUM[n], n=0,nn_fsbc-1}) 
    271          zintb = REAL( nn_fsbc + 1 ) / REAL( nn_fsbc ) * 0.5_wp 
    272          ! 
    273          zpice(:,:) = ssh_m(:,:) + ( zintn * snwice_mass(:,:) + zintb * snwice_mass_b(:,:) ) * r1_rau0 
    274          ! 
    275       ELSE                                    !== non-embedded sea ice: use ocean surface for slope calculation ==! 
    276          zpice(:,:) = ssh_m(:,:) 
    277       ENDIF 
     264      !== embedded sea ice: compute representative ice top surface      ==! 
     265      !== non-embedded sea ice: use ocean surface for slope calculation ==! 
     266      zssh_lead_m(:,:) = ice_var_sshdyn( ssh_m, snwice_mass, snwice_mass_b) 
    278267 
    279268      DO jj = 2, jpjm1 
     
    313302 
    314303            ! Surface pressure gradient (- m*g*GRAD(ssh)) at U-V points 
    315             zspgU(ji,jj)    = - zmassU * grav * ( zpice(ji+1,jj) - zpice(ji,jj) ) * r1_e1u(ji,jj) 
    316             zspgV(ji,jj)    = - zmassV * grav * ( zpice(ji,jj+1) - zpice(ji,jj) ) * r1_e2v(ji,jj) 
     304            zspgU(ji,jj)    = - zmassU * grav * ( zssh_lead_m(ji+1,jj) - zssh_lead_m(ji,jj) ) * r1_e1u(ji,jj) 
     305            zspgV(ji,jj)    = - zmassV * grav * ( zssh_lead_m(ji,jj+1) - zssh_lead_m(ji,jj) ) * r1_e2v(ji,jj) 
    317306 
    318307            ! masks 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE/icevar.F90

    r10069 r10345  
    4949   !!   ice_var_bv        : brine volume 
    5050   !!   ice_var_enthalpy  : compute ice and snow enthalpies from temperature 
     51   !!   ice_var_sshdyn    : compute equivalent ssh in lead 
    5152   !!---------------------------------------------------------------------- 
    5253   USE dom_oce        ! ocean space and time domain 
    5354   USE phycst         ! physical constants (ocean directory)  
    54    USE sbc_oce , ONLY : sss_m 
     55   USE sbc_oce , ONLY : sss_m, ln_ice_embd, nn_fsbc 
    5556   USE ice            ! sea-ice: variables 
    5657   USE ice1D          ! sea-ice: thermodynamics variables 
     
    7475   PUBLIC   ice_var_bv            
    7576   PUBLIC   ice_var_enthalpy            
     77   PUBLIC   ice_var_sshdyn 
    7678 
    7779   !!---------------------------------------------------------------------- 
     
    949951   END SUBROUTINE ice_var_enthalpy 
    950952 
     953   FUNCTION ice_var_sshdyn(pssh, psnwice_mass, psnwice_mass_b) 
     954      !!--------------------------------------------------------------------- 
     955      !!                   ***  ROUTINE rhg_evp_rst  *** 
     956      !!                      
     957      !! ** Purpose :  compute the equivalent ssh in lead when sea ice is embedded 
     958      !! 
     959      !! ** Method  :  ssh_lead = ssh + (Mice + Msnow) / rau0 
     960      !! 
     961      !! ** Reference : Jean-Michel Campin, John Marshall, David Ferreira, 
     962      !!                Sea ice-ocean coupling using a rescaled vertical coordinate z*,  
     963      !!                Ocean Modelling, Volume 24, Issues 1-2, 2008 
     964      !! 
     965      !!---------------------------------------------------------------------- 
     966      ! 
     967      ! input 
     968      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: pssh            !: ssh [m] 
     969      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: psnwice_mass    !: mass of snow and ice at current  ice time step [Kg/m2] 
     970      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: psnwice_mass_b  !: mass of snow and ice at previous ice time step [Kg/m2] 
     971      ! 
     972      ! output 
     973      REAL(wp), DIMENSION(jpi,jpj) :: ice_var_sshdyn  ! equivalent ssh in lead [m] 
     974      ! 
     975      ! temporary 
     976      REAL(wp) :: zintn, zintb                     ! time interpolation weights [] 
     977      REAL(wp), DIMENSION(jpi,jpj) :: zsnwiceload  ! snow and ice load [m] 
     978      ! 
     979      ! compute ice load used to define the equivalent ssh in lead 
     980      IF( ln_ice_embd ) THEN 
     981         !                                             
     982         ! average interpolation coeff as used in dynspg = (1/nn_fsbc)   * {SUM[n/nn_fsbc], n=0,nn_fsbc-1} 
     983         !                                               = (1/nn_fsbc)^2 * {SUM[n]        , n=0,nn_fsbc-1} 
     984         zintn = REAL( nn_fsbc - 1 ) / REAL( nn_fsbc ) * 0.5_wp 
     985         ! 
     986         ! average interpolation coeff as used in dynspg = (1/nn_fsbc)   *    {SUM[1-n/nn_fsbc], n=0,nn_fsbc-1} 
     987         !                                               = (1/nn_fsbc)^2 * (nn_fsbc^2 - {SUM[n], n=0,nn_fsbc-1}) 
     988         zintb = REAL( nn_fsbc + 1 ) / REAL( nn_fsbc ) * 0.5_wp 
     989         ! 
     990         zsnwiceload(:,:) = ( zintn * psnwice_mass(:,:) + zintb * psnwice_mass_b(:,:) ) * r1_rau0 
     991         ! 
     992      ELSE 
     993         zsnwiceload(:,:) = 0.0_wp 
     994      ENDIF 
     995      ! compute equivalent ssh in lead 
     996      ice_var_sshdyn(:,:) = pssh(:,:) + zsnwiceload(:,:) 
     997      ! 
     998   END FUNCTION ice_var_sshdyn 
     999 
     1000 
    9511001#else 
    9521002   !!---------------------------------------------------------------------- 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/DOM/domvvl.F90

    r10314 r10345  
    234234               END DO 
    235235            END DO 
    236             IF( cn_cfg == "orca" .AND. nn_cfg == 3 ) THEN   ! ORCA2: Suppress ztilde in the Foxe Basin for ORCA2 
    237                ii0 = 103   ;   ii1 = 111        
    238                ij0 = 128   ;   ij1 = 135   ;    
    239                frq_rst_e3t( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  0.0_wp 
    240                frq_rst_hdv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  1.e0_wp / rdt 
     236            IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN 
     237               IF( nn_cfg == 3 ) THEN   ! ORCA2: Suppress ztilde in the Foxe Basin for ORCA2 
     238                  ii0 = 103   ;   ii1 = 111        
     239                  ij0 = 128   ;   ij1 = 135   ;    
     240                  frq_rst_e3t( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  0.0_wp 
     241                  frq_rst_hdv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  1.e0_wp / rdt 
     242               ENDIF 
    241243            ENDIF 
    242244         ENDIF 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/DOM/dtatsd.F90

    r10068 r10345  
    150150      ! 
    151151      !                                   !==   ORCA_R2 configuration and T & S damping   ==!  
    152       IF( cn_cfg == "orca" .AND. nn_cfg == 2 .AND. ln_tsd_dmp ) THEN    ! some hand made alterations 
    153          ! 
    154          ij0 = 101   ;   ij1 = 109                       ! Reduced T & S in the Alboran Sea 
    155          ii0 = 141   ;   ii1 = 155 
    156          DO jj = mj0(ij0), mj1(ij1) 
    157             DO ji = mi0(ii0), mi1(ii1) 
    158                sf_tsd(jp_tem)%fnow(ji,jj,13:13) = sf_tsd(jp_tem)%fnow(ji,jj,13:13) - 0.20_wp 
    159                sf_tsd(jp_tem)%fnow(ji,jj,14:15) = sf_tsd(jp_tem)%fnow(ji,jj,14:15) - 0.35_wp 
    160                sf_tsd(jp_tem)%fnow(ji,jj,16:25) = sf_tsd(jp_tem)%fnow(ji,jj,16:25) - 0.40_wp 
    161                ! 
    162                sf_tsd(jp_sal)%fnow(ji,jj,13:13) = sf_tsd(jp_sal)%fnow(ji,jj,13:13) - 0.15_wp 
    163                sf_tsd(jp_sal)%fnow(ji,jj,14:15) = sf_tsd(jp_sal)%fnow(ji,jj,14:15) - 0.25_wp 
    164                sf_tsd(jp_sal)%fnow(ji,jj,16:17) = sf_tsd(jp_sal)%fnow(ji,jj,16:17) - 0.30_wp 
    165                sf_tsd(jp_sal)%fnow(ji,jj,18:25) = sf_tsd(jp_sal)%fnow(ji,jj,18:25) - 0.35_wp 
     152      IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN 
     153         IF( nn_cfg == 2 .AND. ln_tsd_dmp ) THEN    ! some hand made alterations 
     154            ! 
     155            ij0 = 101   ;   ij1 = 109                       ! Reduced T & S in the Alboran Sea 
     156            ii0 = 141   ;   ii1 = 155 
     157            DO jj = mj0(ij0), mj1(ij1) 
     158               DO ji = mi0(ii0), mi1(ii1) 
     159                  sf_tsd(jp_tem)%fnow(ji,jj,13:13) = sf_tsd(jp_tem)%fnow(ji,jj,13:13) - 0.20_wp 
     160                  sf_tsd(jp_tem)%fnow(ji,jj,14:15) = sf_tsd(jp_tem)%fnow(ji,jj,14:15) - 0.35_wp 
     161                  sf_tsd(jp_tem)%fnow(ji,jj,16:25) = sf_tsd(jp_tem)%fnow(ji,jj,16:25) - 0.40_wp 
     162                  ! 
     163                  sf_tsd(jp_sal)%fnow(ji,jj,13:13) = sf_tsd(jp_sal)%fnow(ji,jj,13:13) - 0.15_wp 
     164                  sf_tsd(jp_sal)%fnow(ji,jj,14:15) = sf_tsd(jp_sal)%fnow(ji,jj,14:15) - 0.25_wp 
     165                  sf_tsd(jp_sal)%fnow(ji,jj,16:17) = sf_tsd(jp_sal)%fnow(ji,jj,16:17) - 0.30_wp 
     166                  sf_tsd(jp_sal)%fnow(ji,jj,18:25) = sf_tsd(jp_sal)%fnow(ji,jj,18:25) - 0.35_wp 
     167               END DO 
    166168            END DO 
    167          END DO 
    168          ij0 =  87   ;   ij1 =  96                          ! Reduced temperature in Red Sea 
    169          ii0 = 148   ;   ii1 = 160 
    170          sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ,  4:10 ) = 7.0_wp 
    171          sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 11:13 ) = 6.5_wp 
    172          sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 14:20 ) = 6.0_wp 
     169            ij0 =  87   ;   ij1 =  96                          ! Reduced temperature in Red Sea 
     170            ii0 = 148   ;   ii1 = 160 
     171            sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ,  4:10 ) = 7.0_wp 
     172            sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 11:13 ) = 6.5_wp 
     173            sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 14:20 ) = 6.0_wp 
     174         ENDIF 
    173175      ENDIF 
    174176!!gm end 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/DYN/dynspg_ts.F90

    r10297 r10345  
    11141114                            &   ) * ssvmask(ji,jj) 
    11151115  
    1116 !jth implicit bottom friction: 
    1117                   IF ( ll_wd ) THEN ! revert to explicit for bit comparison tests in non wad runs 
    1118                      ua_e(ji,jj) =  ua_e(ji,jj) /(1.0 -   rdtbt * zCdU_u(ji,jj) * hur_e(ji,jj)) 
    1119                      va_e(ji,jj) =  va_e(ji,jj) /(1.0 -   rdtbt * zCdU_v(ji,jj) * hvr_e(ji,jj)) 
    1120                   ENDIF 
    1121  
    11221116               END DO 
    11231117            END DO 
     
    11441138                            &               +    hv_n(ji,jj)  * zv_frc(ji,jj) ) & 
    11451139                            &   ) * zhvra 
     1140               END DO 
     1141            END DO 
     1142         ENDIF 
     1143!jth implicit bottom friction: 
     1144         IF ( ll_wd ) THEN ! revert to explicit for bit comparison tests in non wad runs 
     1145            DO jj = 2, jpjm1 
     1146               DO ji = fs_2, fs_jpim1   ! vector opt. 
     1147                     ua_e(ji,jj) =  ua_e(ji,jj) /(1.0 -   rdtbt * zCdU_u(ji,jj) * hur_e(ji,jj)) 
     1148                     va_e(ji,jj) =  va_e(ji,jj) /(1.0 -   rdtbt * zCdU_v(ji,jj) * hvr_e(ji,jj)) 
    11461149               END DO 
    11471150            END DO 
     
    13931396      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise  
    13941397         !                                   ! --------------- 
    1395          IF( ln_rstart .AND. ln_bt_fw ) THEN    !* Read the restart file 
     1398         IF( ln_rstart .AND. ln_bt_fw .AND. (neuler/=0) ) THEN    !* Read the restart file 
    13961399            CALL iom_get( numror, jpdom_autoglo, 'ub2_b'  , ub2_b  (:,:), ldxios = lrxios )    
    13971400            CALL iom_get( numror, jpdom_autoglo, 'vb2_b'  , vb2_b  (:,:), ldxios = lrxios )  
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/ICB/icbutl.F90

    r10314 r10345  
    2424#if defined key_si3 
    2525   USE ice,    ONLY: u_ice, v_ice, hm_i    ! SI3 variables 
     26   USE icevar                              ! ice_var_sshdyn 
     27   USE sbc_ice, ONLY: snwice_mass, snwice_mass_b 
    2628#endif 
    2729 
     
    6062      !! ** Method  : - blah blah 
    6163      !!---------------------------------------------------------------------- 
    62  
     64#if defined key_si3 
     65      REAL(wp), DIMENSION(jpi,jpj) :: zssh_lead_m    !    ocean surface (ssh_m) if ice is not embedded 
     66      !                                              !    ocean surface in leads if ice is embedded    
     67#endif 
    6368      ! copy nemo forcing arrays into iceberg versions with extra halo 
    6469      ! only necessary for variables not on T points 
     
    8489      ui_e(:,:) = 0._wp ;   ui_e(1:jpi, 1:jpj) = u_ice(:,:) 
    8590      vi_e(:,:) = 0._wp ;   vi_e(1:jpi, 1:jpj) = v_ice(:,:) 
     91      !       
     92      ! compute ssh slope using ssh_lead if embedded 
     93      zssh_lead_m(:,:) = ice_var_sshdyn(ssh_m, snwice_mass, snwice_mass_b) 
     94      ssh_e(:,:) = 0._wp ;  ssh_e(1:jpi, 1:jpj) = zssh_lead_m(:,:) * tmask(:,:,1) 
    8695      ! 
    8796      CALL lbc_lnk_icb( 'icbutl', hicth, 'T', +1._wp, 1, 1 ) 
    8897      CALL lbc_lnk_icb( 'icbutl', ui_e , 'U', -1._wp, 1, 1 ) 
    8998      CALL lbc_lnk_icb( 'icbutl', vi_e , 'V', -1._wp, 1, 1 ) 
     99#else 
     100      ssh_e(:,:) = 0._wp ;  ssh_e(1:jpi, 1:jpj) = ssh_m(:,:) * tmask(:,:,1) 
    90101#endif 
    91102 
    92103      !! special for ssh which is used to calculate slope 
    93104      !! so fudge some numbers all the way around the boundary 
    94  
    95       ssh_e(:,:) = 0._wp ;   ssh_e(1:jpi, 1:jpj) = ssh_m(:,:) * tmask(:,:,1) 
    96105      ssh_e(0    ,    :) = ssh_e(1  ,  :) 
    97106      ssh_e(jpi+1,    :) = ssh_e(jpi,  :) 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/IOM/iom.F90

    r10170 r10345  
    4343   USE ioipsl, ONLY :  ju2ymds    ! for calendar 
    4444   USE crs             ! Grid coarsening 
     45#if defined key_top 
     46   USE trc, ONLY    :  profsed 
     47#endif 
    4548   USE lib_fortran  
    4649   USE diurnal_bulk, ONLY : ln_diurnal_only, ln_diurnal 
     
    193196      ! vertical grid definition 
    194197      IF(.NOT.llrst_context) THEN 
    195           CALL iom_set_axis_attr( "deptht", paxis = gdept_1d ) 
    196           CALL iom_set_axis_attr( "depthu", paxis = gdept_1d ) 
    197           CALL iom_set_axis_attr( "depthv", paxis = gdept_1d ) 
    198           CALL iom_set_axis_attr( "depthw", paxis = gdepw_1d ) 
     198          CALL iom_set_axis_attr( "deptht",  paxis = gdept_1d ) 
     199          CALL iom_set_axis_attr( "depthu",  paxis = gdept_1d ) 
     200          CALL iom_set_axis_attr( "depthv",  paxis = gdept_1d ) 
     201          CALL iom_set_axis_attr( "depthw",  paxis = gdepw_1d ) 
    199202 
    200203          ! Add vertical grid bounds 
     
    219222          CALL iom_set_axis_attr( "nstrait", (/ (REAL(ji,wp), ji=1,4) /) ) 
    220223# endif 
     224#if defined key_top 
     225          CALL iom_set_axis_attr( "profsed", paxis = profsed ) 
     226#endif 
    221227          CALL iom_set_axis_attr( "icbcla", class_num ) 
    222228          CALL iom_set_axis_attr( "iax_20C", (/ REAL(20,wp) /) ) 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/LBC/lbclnk.F90

    r10314 r10345  
    173173 
    174174   !!---------------------------------------------------------------------- 
    175    !!                   ***  routine lbc_bdy_lnk_(2,3)d  *** 
     175   !!                   ***  routine lbc_bdy_lnk_(2,3,4)d  *** 
    176176   !! 
    177177   !!   wrapper rountine to 'lbc_lnk_3d'. This wrapper is used 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/LBC/mppini.F90

    r10330 r10345  
    139139      !!---------------------------------------------------------------------- 
    140140      INTEGER ::   ji, jj, jn, jproc, jarea   ! dummy loop indices 
    141       INTEGER ::   inij, inijmin 
     141      INTEGER ::   inijmin 
    142142      INTEGER ::   i2add 
    143143      INTEGER ::   inum                       ! local logical unit 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/sbcblk.F90

    r10297 r10345  
    239239      !drag coefficient read from wave model definable only with mfs bulk formulae and core  
    240240         ELSEIF (ln_cdgw .AND. .NOT. ln_NCAR )       THEN        
    241              CALL ctl_stop( 'drag coefficient read from wave model definable only with mfs bulk formulae and core') 
     241             CALL ctl_stop( 'drag coefficient read from wave model definable only with NCAR and CORE bulk formulae') 
    242242         ELSEIF (ln_stcor .AND. .NOT. ln_sdw)                             THEN 
    243243             CALL ctl_stop( 'Stokes-Coriolis term calculated only if activated Stokes Drift ln_sdw=T') 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/sbcblk_algo_ncar.F90

    r10069 r10345  
    149149      Ch = 1.e-3*sqrt_Cd_n10*(18.*stab + 32.7*(1. - stab)) 
    150150      stab = sqrt_Cd_n10   ! Temporaty array !!! stab == SQRT(Cd) 
     151  
     152      IF( ln_cdgw )   Cen = Ce  ; Chn = Ch 
    151153 
    152154      !! Initializing values at z_u with z_t values: 
     
    186188         IF( ln_cdgw ) THEN      ! surface wave case 
    187189            stab = vkarmn / ( vkarmn / sqrt_Cd_n10 - ztmp2 )  ! (stab == SQRT(Cd)) 
    188             Cd      = stab * stab 
     190            Cd   = stab * stab 
     191            ztmp0 = (LOG(zu/10.) - zpsi_h_u) / vkarmn / sqrt_Cd_n10 
     192            ztmp2 = stab / sqrt_Cd_n10   ! (stab == SQRT(Cd)) 
     193            ztmp1 = 1. + Chn * ztmp0      
     194            Ch    = Chn * ztmp2 / ztmp1  ! L&Y 2004 eq. (10b) 
     195            ztmp1 = 1. + Cen * ztmp0 
     196            Ce    = Cen * ztmp2 / ztmp1  ! L&Y 2004 eq. (10c) 
     197 
    189198         ELSE 
    190199            ! Update neutral wind speed at 10m and neutral Cd at 10m (L&Y 2004 eq. 9a)... 
     
    205214            Cd      = ztmp0 / ( ztmp1*ztmp1 ) 
    206215            stab = SQRT( Cd ) ! Temporary array !!! (stab == SQRT(Cd)) 
    207          ENDIF 
    208  
    209          ztmp0 = (LOG(zu/10.) - zpsi_h_u) / vkarmn / sqrt_Cd_n10 
    210          ztmp2 = stab / sqrt_Cd_n10   ! (stab == SQRT(Cd)) 
    211          ztmp1 = 1. + Cx_n10*ztmp0    ! (Cx_n10 == Ch_n10) 
    212          Ch  = Cx_n10*ztmp2 / ztmp1   ! L&Y 2004 eq. (10b) 
    213  
    214          Cx_n10  = 1.e-3 * (34.6 * sqrt_Cd_n10)  ! L&Y 2004 eq. (6b)    ! Cx_n10 == Ce_n10 
    215          Cen(:,:) = Cx_n10 
    216          ztmp1 = 1. + Cx_n10*ztmp0 
    217          Ce  = Cx_n10*ztmp2 / ztmp1  ! L&Y 2004 eq. (10c) 
     216 
     217            ztmp0 = (LOG(zu/10.) - zpsi_h_u) / vkarmn / sqrt_Cd_n10 
     218            ztmp2 = stab / sqrt_Cd_n10   ! (stab == SQRT(Cd)) 
     219            ztmp1 = 1. + Cx_n10*ztmp0    ! (Cx_n10 == Ch_n10) 
     220            Ch  = Cx_n10*ztmp2 / ztmp1   ! L&Y 2004 eq. (10b) 
     221 
     222            Cx_n10  = 1.e-3 * (34.6 * sqrt_Cd_n10)  ! L&Y 2004 eq. (6b)    ! Cx_n10 == Ce_n10 
     223            Cen(:,:) = Cx_n10 
     224            ztmp1 = 1. + Cx_n10*ztmp0 
     225            Ce  = Cx_n10*ztmp2 / ztmp1  ! L&Y 2004 eq. (10c) 
     226            ENDIF 
    218227         ! 
    219228      END DO 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/SBC/sbcmod.F90

    r10297 r10345  
    160160         WRITE(numout,*) '               wave modified ocean stress component ln_tauw       = ', ln_tauw 
    161161         WRITE(numout,*) '               Stokes coriolis term                 ln_stcor      = ', ln_stcor 
    162          WRITE(numout,*) '               neutral drag coefficient (CORE, MFS) ln_cdgw       = ', ln_cdgw 
    163       ENDIF 
    164       ! 
     162         WRITE(numout,*) '               neutral drag coefficient (CORE,NCAR) ln_cdgw       = ', ln_cdgw 
     163      ENDIF 
     164      ! 
     165      IF( .NOT.ln_wave ) THEN 
     166         ln_sdw = .false. ; ln_cdgw = .false. ; ln_tauwoc = .false. ; ln_tauw = .false. ; ln_stcor = .false. 
     167      ENDIF  
    165168      IF( ln_sdw ) THEN 
    166169         IF( .NOT.(nn_sdrift==jp_breivik_2014 .OR. nn_sdrift==jp_li_2017 .OR. nn_sdrift==jp_peakfr) ) & 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/ZDF/zdfgls.F90

    r10297 r10345  
    275275               ! building the matrix 
    276276               zcof = rfact_tke * tmask(ji,jj,jk) 
    277                !                                               ! lower diagonal 
     277               !                                        ! lower diagonal, in fact not used for jk = 2 (see surface conditions) 
    278278               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) ) 
    279                !                                               ! upper diagonal 
     279               !                                        ! upper diagonal, in fact not used for jk = ibotm1 (see bottom conditions) 
    280280               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) ) 
    281                !                                               ! diagonal 
     281               !                                        ! diagonal 
    282282               zdiag(ji,jj,jk) = 1._wp - zd_lw(ji,jj,jk) - zd_up(ji,jj,jk)  + rdt * zdiss * wmask(ji,jj,jk)  
    283                !                                               ! right hand side in en 
     283               !                                        ! right hand side in en 
    284284               en(ji,jj,jk) = en(ji,jj,jk) + rdt * zesh2 * wmask(ji,jj,jk) 
    285285            END DO 
     
    792792      zstm(:,:,1) = zstm(:,:,2) 
    793793 
    794       DO jj = 2, jpjm1 
     794      ! default value, in case jpk > mbkt(ji,jj)+1. Not needed but avoid a bug when looking for undefined values (-fpe0) 
     795      zstm(:,:,jpk) = 0.   
     796      DO jj = 2, jpjm1                ! update bottom with good values 
    795797         DO ji = fs_2, fs_jpim1   ! vector opt. 
    796798            zstm(ji,jj,mbkt(ji,jj)+1) = zstm(ji,jj,mbkt(ji,jj)) 
    797799         END DO 
    798800      END DO 
     801 
     802      zstt(:,:,  1) = wmask(:,:,  1)  ! default value not needed but avoid a bug when looking for undefined values (-fpe0) 
     803      zstt(:,:,jpk) = wmask(:,:,jpk)  ! default value not needed but avoid a bug when looking for undefined values (-fpe0) 
     804 
    799805!!gm should be done for ISF (top boundary cond.) 
    800806!!gm so, totally new staff needed!!gm 
     
    802808      ! Compute diffusivities/viscosities 
    803809      ! The computation below could be restrained to jk=2 to jpkm1 if GOTM style Dirichlet conditions are used 
     810      !  -> yes BUT p_avm(:,:1) and p_avm(:,:jpk) are used when we compute zd_lw(:,:2) and zd_up(:,:jpkm1). These values are 
     811      !     later overwritten by surface/bottom boundaries conditions, so we don't really care of p_avm(:,:1) and p_avm(:,:jpk) 
     812      !     for zd_lw and zd_up but they have to be defined to avoid a bug when looking for undefined values (-fpe0) 
    804813      DO jk = 1, jpk 
    805814         DO jj = 2, jpjm1 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OFF/dtadyn.F90

    r10297 r10345  
    4646   PRIVATE 
    4747 
    48    PUBLIC   dta_dyn_init   ! called by opa.F90 
    49    PUBLIC   dta_dyn        ! called by step.F90 
    50    PUBLIC   dta_dyn_swp   ! called by step.F90 
     48   PUBLIC   dta_dyn_init       ! called by opa.F90 
     49   PUBLIC   dta_dyn            ! called by step.F90 
     50   PUBLIC   dta_dyn_sed_init   ! called by opa.F90 
     51   PUBLIC   dta_dyn_sed        ! called by step.F90 
     52   PUBLIC   dta_dyn_swp        ! called by step.F90 
    5153 
    5254   CHARACTER(len=100) ::   cn_dir          !: Root directory for location of ssr files 
     
    164166      hmld(:,:)       = sf_dyn(jf_mld)%fnow(:,:,1) * tmask(:,:,1)    ! mixed layer depht 
    165167      avt(:,:,:)      = sf_dyn(jf_avt)%fnow(:,:,:) * tmask(:,:,:)    ! vertical diffusive coefficient  
     168      avs(:,:,:)      = avt(:,:,:) 
    166169      ! 
    167170      IF( ln_trabbl .AND. .NOT.lk_c1d ) THEN       ! diffusive Bottom boundary layer param  
     
    182185         CALL prt_ctl(tab3d_1=uslp             , clinfo1=' slp  - u : ', tab3d_2=vslp, clinfo2=' v : ', kdim=jpk) 
    183186         CALL prt_ctl(tab3d_1=wslpi            , clinfo1=' slp  - wi: ', tab3d_2=wslpj, clinfo2=' wj: ', kdim=jpk) 
    184 !         CALL prt_ctl(tab2d_1=fr_i             , clinfo1=' fr_i    - : ', mask1=tmask ) 
    185 !         CALL prt_ctl(tab2d_1=hmld             , clinfo1=' hmld    - : ', mask1=tmask ) 
    186 !         CALL prt_ctl(tab2d_1=fmmflx           , clinfo1=' fmmflx  - : ', mask1=tmask ) 
    187 !         CALL prt_ctl(tab2d_1=emp              , clinfo1=' emp     - : ', mask1=tmask ) 
    188 !         CALL prt_ctl(tab2d_1=wndm             , clinfo1=' wspd    - : ', mask1=tmask ) 
    189 !         CALL prt_ctl(tab2d_1=qsr              , clinfo1=' qsr     - : ', mask1=tmask ) 
    190187      ENDIF 
    191188      ! 
     
    418415   END SUBROUTINE dta_dyn_init 
    419416 
     417   SUBROUTINE dta_dyn_sed( kt ) 
     418      !!---------------------------------------------------------------------- 
     419      !!                  ***  ROUTINE dta_dyn  *** 
     420      !! 
     421      !! ** Purpose :  Prepares dynamics and physics fields from a NEMO run 
     422      !!               for an off-line simulation of passive tracers 
     423      !! 
     424      !! ** Method : calculates the position of data 
     425      !!             - computes slopes if needed 
     426      !!             - interpolates data if needed 
     427      !!---------------------------------------------------------------------- 
     428      INTEGER, INTENT(in) ::   kt   ! ocean time-step index 
     429      ! 
     430      !!---------------------------------------------------------------------- 
     431      ! 
     432      IF( ln_timing )   CALL timing_start( 'dta_dyn_sed') 
     433      ! 
     434      nsecdyn = nsec_year + nsec1jan000   ! number of seconds between Jan. 1st 00h of nit000 year and the middle of time step 
     435      ! 
     436      IF( kt == nit000 ) THEN    ;    nprevrec = 0 
     437      ELSE                       ;    nprevrec = sf_dyn(jf_tem)%nrec_a(2) 
     438      ENDIF 
     439      CALL fld_read( kt, 1, sf_dyn )      !=  read data at kt time step   ==! 
     440      ! 
     441      tsn(:,:,:,jp_tem) = sf_dyn(jf_tem)%fnow(:,:,:)  * tmask(:,:,:)    ! temperature 
     442      tsn(:,:,:,jp_sal) = sf_dyn(jf_sal)%fnow(:,:,:)  * tmask(:,:,:)    ! salinity 
     443      ! 
     444      CALL eos    ( tsn, rhd, rhop, gdept_0(:,:,:) ) ! In any case, we need rhop 
     445 
     446      IF(ln_ctl) THEN                  ! print control 
     447         CALL prt_ctl(tab3d_1=tsn(:,:,:,jp_tem), clinfo1=' tn      - : ', mask1=tmask,  kdim=jpk   ) 
     448         CALL prt_ctl(tab3d_1=tsn(:,:,:,jp_sal), clinfo1=' sn      - : ', mask1=tmask,  kdim=jpk   ) 
     449      ENDIF 
     450      ! 
     451      IF( ln_timing )   CALL timing_stop( 'dta_dyn_sed') 
     452      ! 
     453   END SUBROUTINE dta_dyn_sed 
     454 
     455 
     456   SUBROUTINE dta_dyn_sed_init 
     457      !!---------------------------------------------------------------------- 
     458      !!                  ***  ROUTINE dta_dyn_init  *** 
     459      !! 
     460      !! ** Purpose :   Initialisation of the dynamical data 
     461      !! ** Method  : - read the data namdta_dyn namelist 
     462      !!---------------------------------------------------------------------- 
     463      INTEGER  :: ierr, ierr0, ierr1, ierr2, ierr3   ! return error code 
     464      INTEGER  :: ifpr                               ! dummy loop indice 
     465      INTEGER  :: jfld                               ! dummy loop arguments 
     466      INTEGER  :: inum, idv, idimv                   ! local integer 
     467      INTEGER  :: ios                                ! Local integer output status for namelist read 
     468      !! 
     469      CHARACTER(len=100)            ::  cn_dir        !   Root directory for location of core files 
     470      TYPE(FLD_N), DIMENSION(2) ::  slf_d         ! array of namelist informations on the fields to read 
     471      TYPE(FLD_N) :: sn_tem , sn_sal   !   "                 " 
     472      !! 
     473      NAMELIST/namdta_dyn/cn_dir, ln_dynrnf, ln_dynrnf_depth,  fwbcorr, & 
     474         &                sn_tem, sn_sal 
     475      !!---------------------------------------------------------------------- 
     476      ! 
     477      REWIND( numnam_ref )              ! Namelist namdta_dyn in reference namelist : Offline: init. of dynamical data 
     478      READ  ( numnam_ref, namdta_dyn, IOSTAT = ios, ERR = 901) 
     479901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdta_dyn in reference namelist', lwp ) 
     480      REWIND( numnam_cfg )              ! Namelist namdta_dyn in configuration namelist : Offline: init. of dynamical data 
     481      READ  ( numnam_cfg, namdta_dyn, IOSTAT = ios, ERR = 902 ) 
     482902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdta_dyn in configuration namelist', lwp ) 
     483      IF(lwm) WRITE ( numond, namdta_dyn ) 
     484      !                                         ! store namelist information in an array 
     485      !                                         ! Control print 
     486      IF(lwp) THEN 
     487         WRITE(numout,*) 
     488         WRITE(numout,*) 'dta_dyn : offline dynamics ' 
     489         WRITE(numout,*) '~~~~~~~ ' 
     490         WRITE(numout,*) '   Namelist namdta_dyn' 
     491         WRITE(numout,*) '      runoffs option enabled (T) or not (F)            ln_dynrnf        = ', ln_dynrnf 
     492         WRITE(numout,*) '      runoffs is spread in vertical                    ln_dynrnf_depth  = ', ln_dynrnf_depth 
     493         WRITE(numout,*) '      annual global mean of empmr for ssh correction   fwbcorr          = ', fwbcorr 
     494         WRITE(numout,*) 
     495      ENDIF 
     496      ! 
     497      jf_tem  = 1     ;   jf_sal  = 2    ;   jfld   = jf_sal 
     498      ! 
     499      slf_d(jf_tem)  = sn_tem    ;   slf_d(jf_sal)  = sn_sal 
     500      ! 
     501      ALLOCATE( sf_dyn(jfld), STAT=ierr )         ! set sf structure 
     502      IF( ierr > 0 )  THEN 
     503         CALL ctl_stop( 'dta_dyn: unable to allocate sf structure' )   ;   RETURN 
     504      ENDIF 
     505      !                                         ! fill sf with slf_i and control print 
     506      CALL fld_fill( sf_dyn, slf_d, cn_dir, 'dta_dyn_init', 'Data in file', 'namdta_dyn' ) 
     507      ! 
     508      ! Open file for each variable to get his number of dimension 
     509      DO ifpr = 1, jfld 
     510         CALL fld_clopn( sf_dyn(ifpr), nyear, nmonth, nday ) 
     511         idv   = iom_varid( sf_dyn(ifpr)%num , slf_d(ifpr)%clvar )        ! id of the variable sdjf%clvar 
     512         idimv = iom_file ( sf_dyn(ifpr)%num )%ndims(idv)                 ! number of dimension for variable sdjf%clvar 
     513         IF( sf_dyn(ifpr)%num /= 0 )   CALL iom_close( sf_dyn(ifpr)%num ) ! close file if already open 
     514         ierr1=0 
     515         IF( idimv == 3 ) THEN    ! 2D variable 
     516                                      ALLOCATE( sf_dyn(ifpr)%fnow(jpi,jpj,1)    , STAT=ierr0 ) 
     517            IF( slf_d(ifpr)%ln_tint ) ALLOCATE( sf_dyn(ifpr)%fdta(jpi,jpj,1,2)  , STAT=ierr1 ) 
     518         ELSE                     ! 3D variable 
     519                                      ALLOCATE( sf_dyn(ifpr)%fnow(jpi,jpj,jpk)  , STAT=ierr0 ) 
     520            IF( slf_d(ifpr)%ln_tint ) ALLOCATE( sf_dyn(ifpr)%fdta(jpi,jpj,jpk,2), STAT=ierr1 ) 
     521         ENDIF 
     522         IF( ierr0 + ierr1 > 0 ) THEN 
     523            CALL ctl_stop( 'dta_dyn_init : unable to allocate sf_dyn array structure' )   ;   RETURN 
     524         ENDIF 
     525      END DO 
     526      ! 
     527      CALL dta_dyn_sed( nit000 ) 
     528      ! 
     529   END SUBROUTINE dta_dyn_sed_init 
    420530 
    421531   SUBROUTINE dta_dyn_swp( kt ) 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OFF/nemogcm.F90

    r10297 r10345  
    110110         IF( istp /= nit000 )   CALL day        ( istp )         ! Calendar (day was already called at nit000 in day_init) 
    111111                                CALL iom_setkt  ( istp - nit000 + 1, cxios_context )   ! say to iom that we are at time step kstp 
     112#if defined key_sed_off 
     113                                CALL dta_dyn_sed( istp )         ! Interpolation of the dynamical fields 
     114#else 
    112115                                CALL dta_dyn    ( istp )         ! Interpolation of the dynamical fields 
    113116         IF( .NOT.ln_linssh )   CALL dta_dyn_swp( istp )         ! swap of sea  surface height and vertical scale factors 
    114  
     117#endif 
    115118                                CALL trc_stp    ( istp )         ! time-stepping 
    116119                                CALL stp_ctl    ( istp, indic )  ! Time loop: control and print 
     
    287290                           CALL trc_nam_run    ! Needed to get restart parameters for passive tracers 
    288291                           CALL trc_rst_cal( nit000, 'READ' )   ! calendar 
     292#if defined key_sed_off 
     293                           CALL dta_dyn_sed_init ! Initialization for the dynamics 
     294#else 
    289295                           CALL dta_dyn_init   ! Initialization for the dynamics 
     296#endif 
    290297 
    291298                           CALL     trc_init   ! Passive tracers initialization 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zbio.F90

    r10069 r10345  
    1515   USE p4zsink         !  vertical flux of particulate matter due to sinking 
    1616   USE p4zopt          !  optical model 
    17    USE p4zice          !  Co-limitations of differents nutrients 
     17   USE p4zlim          !  Co-limitations of differents nutrients 
    1818   USE p4zprod         !  Growth rate of the 2 phyto groups 
    1919   USE p4zmort         !  Mortality terms for phytoplankton 
    2020   USE p4zmicro        !  Sources and sinks of microzooplankton 
    2121   USE p4zmeso         !  Sources and sinks of mesozooplankton 
    22    USE p5zice          !  Co-limitations of differents nutrients 
     22   USE p5zlim          !  Co-limitations of differents nutrients 
    2323   USE p5zprod         !  Growth rate of the 2 phyto groups 
    2424   USE p5zmort         !  Mortality terms for phytoplankton 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zche.F90

    r10068 r10345  
    3737   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tempis   ! In situ temperature 
    3838 
    39    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   akb3       !: ??? 
    40    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   akw3       !: ??? 
    41    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   akf3       !: ??? 
    42    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   aks3       !: ??? 
    43    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ak1p3      !: ??? 
    44    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ak2p3      !: ??? 
    45    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ak3p3      !: ??? 
    46    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   aksi3      !: ??? 
    47    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   borat      !: ??? 
    48    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   fluorid    !: ??? 
    49    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   sulfat     !: ??? 
     39   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   akb3       !: ??? 
     40   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   akw3       !: ??? 
     41   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   akf3       !: ??? 
     42   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   aks3       !: ??? 
     43   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ak1p3      !: ??? 
     44   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ak2p3      !: ??? 
     45   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ak3p3      !: ??? 
     46   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   aksi3      !: ??? 
     47   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   borat      !: ??? 
     48   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   fluorid    !: ??? 
     49   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   sulfat     !: ??? 
    5050 
    5151   !!* Variable for chemistry of the CO2 cycle 
     
    233233        END DO 
    234234 
    235  
    236  
    237235      ! CHEMICAL CONSTANTS - DEEP OCEAN 
    238236      ! ------------------------------- 
     
    449447      ! 
    450448   END SUBROUTINE p4z_che 
    451  
    452449 
    453450   SUBROUTINE ahini_for_at(p_hini) 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zmeso.F90

    r10069 r10345  
    108108               zdenom    = zfoodlim / ( xkgraz2 + zfoodlim ) 
    109109               zdenom2   = zdenom / ( zfood + rtrn ) 
    110                zgraze2   = grazrat2 * xstep * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpmes)  
     110               zgraze2   = grazrat2 * xstep * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpmes) * (1. - nitrfac(ji,jj,jk))  
    111111 
    112112               zgrazd    = zgraze2  * xprefc   * zcompadi  * zdenom2  
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zmicro.F90

    r10069 r10345  
    1414   USE trc             ! passive tracers common variables  
    1515   USE sms_pisces      ! PISCES Source Minus Sink variables 
    16    USE p4zice          ! Co-limitations 
     16   USE p4zlim          ! Co-limitations 
    1717   USE p4zprod         ! production 
    1818   USE iom             ! I/O manager 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zmort.F90

    r10068 r10345  
    1414   USE sms_pisces      ! PISCES Source Minus Sink variables 
    1515   USE p4zprod         ! Primary productivity  
    16    USE p4zice          ! Phytoplankton limitation terms 
     16   USE p4zlim          ! Phytoplankton limitation terms 
    1717   USE prtctl_trc      ! print control for debugging 
    1818 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zprod.F90

    r10314 r10345  
    1515   USE trc             ! passive tracers common variables  
    1616   USE sms_pisces      ! PISCES Source Minus Sink variables 
    17    USE p4zice          ! Co-limitations of differents nutrients 
     17   USE p4zlim          ! Co-limitations of differents nutrients 
    1818   USE prtctl_trc      ! print control for debugging 
    1919   USE iom             ! I/O manager 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zrem.F90

    r10069 r10345  
    1717   USE p4zche          !  chemical model 
    1818   USE p4zprod         !  Growth rate of the 2 phyto groups 
    19    USE p4zice 
     19   USE p4zlim 
    2020   USE prtctl_trc      !  print control for debugging 
    2121   USE iom             !  I/O manager 
     
    116116                  zammonic = zremik * nitrfac(ji,jj,jk) * trb(ji,jj,jk,jpdoc) 
    117117                  denitr(ji,jj,jk)  = zammonic * ( 1. - nitrfac2(ji,jj,jk) ) 
    118                   zoxyrem           = zammonic *        nitrfac2(ji,jj,jk) 
     118                  denitr(ji,jj,jk)  = MIN( ( trb(ji,jj,jk,jpno3) - rtrn ) / rdenit, denitr(ji,jj,jk) ) 
     119                  zoxyrem           = zammonic - denitr(ji,jj,jk) 
    119120                  ! 
    120121                  zolimi (ji,jj,jk) = MAX( 0.e0, zolimi (ji,jj,jk) ) 
     
    189190               &         / ( 1.+ emoy(ji,jj,jk) ) * ( 1. + fr_i(ji,jj) * emoy(ji,jj,jk) )  
    190191               zdenitnh4 = nitrif * xstep * trb(ji,jj,jk,jpnh4) * nitrfac(ji,jj,jk) 
     192               zdenitnh4 = MIN(  ( trb(ji,jj,jk,jpno3) - rtrn ) / rdenita, zdenitnh4 )  
    191193               ! Update of the tracers trends 
    192194               ! ---------------------------- 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zsed.F90

    r10127 r10345  
    1414   USE trc             !  passive tracers common variables  
    1515   USE sms_pisces      !  PISCES Source Minus Sink variables 
    16    USE p4zice          !  Co-limitations of differents nutrients 
     16   USE p4zlim          !  Co-limitations of differents nutrients 
    1717   USE p4zsbc          !  External source of nutrients  
    1818   USE p4zint          !  interpolation and computation of various fields 
     19   USE sed             !  Sediment module 
    1920   USE iom             !  I/O manager 
    2021   USE prtctl_trc      !  print control for debugging 
     
    2930   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:  ) :: sdenit     !: Nitrate reduction in the sediments 
    3031   REAL(wp) :: r1_rday                  !: inverse of rday 
     32   LOGICAL, SAVE :: lk_sed 
    3133 
    3234   !!---------------------------------------------------------------------- 
     
    7072      ! 
    7173      IF( ln_timing )  CALL timing_start('p4z_sed') 
     74      ! 
     75      IF( kt == nittrc000 .AND. knt == 1 )   THEN 
     76          r1_rday  = 1. / rday 
     77          IF (ln_sediment .AND. ln_sed_2way) THEN 
     78             lk_sed = .TRUE. 
     79          ELSE 
     80             lk_sed = .FALSE. 
     81          ENDIF 
     82      ENDIF 
    7283      ! 
    7384      IF( kt == nittrc000 .AND. knt == 1 )   r1_rday  = 1. / rday 
     
    185196      ENDIF 
    186197 
    187       ! Add the external input of iron from sediment mobilization 
    188       ! ------------------------------------------------------ 
    189       IF( ln_ironsed ) THEN 
    190                          tra(:,:,:,jpfer) = tra(:,:,:,jpfer) + ironsed(:,:,:) * rfact2 
    191          IF( ln_ligand ) tra(:,:,:,jpfep) = tra(:,:,:,jpfep) + ( ironsed(:,:,:) * fep_rats ) * rfact2 
    192          ! 
    193          IF( lk_iomput .AND. knt == nrdttrc .AND. iom_use( "Ironsed" ) )   & 
    194             &   CALL iom_put( "Ironsed", ironsed(:,:,:) * 1.e+3 * tmask(:,:,:) ) ! iron inputs from sediments 
    195       ENDIF 
    196  
    197198      ! Add the external input of iron from hydrothermal vents 
    198199      ! ------------------------------------------------------ 
     
    231232 
    232233      IF( .NOT.lk_sed ) THEN 
     234! 
     235         ! Add the external input of iron from sediment mobilization 
     236         ! ------------------------------------------------------ 
     237         IF( ln_ironsed ) THEN 
     238                            tra(:,:,:,jpfer) = tra(:,:,:,jpfer) + ironsed(:,:,:) * rfact2 
     239            IF( ln_ligand ) tra(:,:,:,jpfep) = tra(:,:,:,jpfep) + ( ironsed(:,:,:) * fep_rats ) * rfact2 
     240            ! 
     241            IF( lk_iomput .AND. knt == nrdttrc .AND. iom_use( "Ironsed" ) )   & 
     242               &   CALL iom_put( "Ironsed", ironsed(:,:,:) * 1.e+3 * tmask(:,:,:) ) ! iron inputs from sediments 
     243         ENDIF 
     244 
    233245         ! Computation of the sediment denitrification proportion: The metamodel from midlleburg (2006) is being used 
    234246         ! Computation of the fraction of organic matter that is permanently buried from Dunne's model 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p4zsms.F90

    r10314 r10345  
    7474            CALL p4z_che                              ! initialize the chemical constants 
    7575            CALL ahini_for_at(hi)   !  set PH at kt=nit000 
     76            t_oce_co2_flx_cum = 0._wp 
    7677        ELSE 
    7778            CALL p4z_rst( nittrc000, 'READ' )  !* read or initialize all required fields 
     
    101102      ENDIF 
    102103      ! 
     104      IF( ll_sbc ) CALL p4z_sbc( kt )   ! external sources of nutrients  
     105      ! 
     106#if ! defined key_sed_off 
    103107      CALL p4z_che              ! computation of chemical constants 
    104108      CALL p4z_int( kt )        ! computation of various rates for biogeochemistry 
    105109      ! 
    106       IF( ll_sbc ) CALL p4z_sbc( kt )   ! external sources of nutrients  
    107  
    108110      DO jnt = 1, nrdttrc          ! Potential time splitting if requested 
    109111         ! 
     
    149151         END DO 
    150152      END IF 
    151       ! 
    152       IF( lk_sed ) THEN  
     153#endif 
     154      ! 
     155      IF( ln_sediment ) THEN  
    153156         ! 
    154157         CALL sed_model( kt )     !  Main program of Sediment model 
     158         ! 
     159         IF( ln_top_euler ) THEN 
     160            DO jn = jp_pcs0, jp_pcs1 
     161               trn(:,:,:,jn) = trb(:,:,:,jn) 
     162            END DO 
     163         ENDIF 
    155164         ! 
    156165      ENDIF 
     
    352361      IF(lwp)  WRITE(numout,*) 
    353362 
    354       IF( cn_cfg == "orca" .AND. .NOT. lk_c1d ) THEN      ! ORCA configuration (not 1D) ! 
    355          !                                                ! --------------------------- ! 
    356          ! set total alkalinity, phosphate, nitrate & silicate 
    357          zarea          = 1._wp / glob_sum( 'p4zsms', cvol(:,:,:) ) * 1e6               
    358  
    359          zalksumn = glob_sum( 'p4zsms', trn(:,:,:,jptal) * cvol(:,:,:)  ) * zarea 
    360          zpo4sumn = glob_sum( 'p4zsms', trn(:,:,:,jppo4) * cvol(:,:,:)  ) * zarea * po4r 
    361          zno3sumn = glob_sum( 'p4zsms', trn(:,:,:,jpno3) * cvol(:,:,:)  ) * zarea * rno3 
    362          zsilsumn = glob_sum( 'p4zsms', trn(:,:,:,jpsil) * cvol(:,:,:)  ) * zarea 
     363      IF( cn_cfg == "ORCA" .OR. cn_cfg == "orca") THEN 
     364         IF( .NOT. lk_c1d ) THEN      ! ORCA configuration (not 1D) ! 
     365            !                                                ! --------------------------- ! 
     366            ! set total alkalinity, phosphate, nitrate & silicate 
     367            zarea          = 1._wp / glob_sum( 'p4zsms', cvol(:,:,:) ) * 1e6               
     368 
     369            zalksumn = glob_sum( 'p4zsms', trn(:,:,:,jptal) * cvol(:,:,:)  ) * zarea 
     370            zpo4sumn = glob_sum( 'p4zsms', trn(:,:,:,jppo4) * cvol(:,:,:)  ) * zarea * po4r 
     371            zno3sumn = glob_sum( 'p4zsms', trn(:,:,:,jpno3) * cvol(:,:,:)  ) * zarea * rno3 
     372            zsilsumn = glob_sum( 'p4zsms', trn(:,:,:,jpsil) * cvol(:,:,:)  ) * zarea 
    363373  
    364          IF(lwp) WRITE(numout,*) '       TALKN mean : ', zalksumn 
    365          trn(:,:,:,jptal) = trn(:,:,:,jptal) * alkmean / zalksumn 
    366  
    367          IF(lwp) WRITE(numout,*) '       PO4N  mean : ', zpo4sumn 
    368          trn(:,:,:,jppo4) = trn(:,:,:,jppo4) * po4mean / zpo4sumn 
    369  
    370          IF(lwp) WRITE(numout,*) '       NO3N  mean : ', zno3sumn 
    371          trn(:,:,:,jpno3) = trn(:,:,:,jpno3) * no3mean / zno3sumn 
    372  
    373          IF(lwp) WRITE(numout,*) '       SiO3N mean : ', zsilsumn 
    374          trn(:,:,:,jpsil) = MIN( 400.e-6,trn(:,:,:,jpsil) * silmean / zsilsumn ) 
    375          ! 
    376          ! 
    377          IF( .NOT. ln_top_euler ) THEN 
    378             zalksumb = glob_sum( 'p4zsms', trb(:,:,:,jptal) * cvol(:,:,:)  ) * zarea 
    379             zpo4sumb = glob_sum( 'p4zsms', trb(:,:,:,jppo4) * cvol(:,:,:)  ) * zarea * po4r 
    380             zno3sumb = glob_sum( 'p4zsms', trb(:,:,:,jpno3) * cvol(:,:,:)  ) * zarea * rno3 
    381             zsilsumb = glob_sum( 'p4zsms', trb(:,:,:,jpsil) * cvol(:,:,:)  ) * zarea 
     374            IF(lwp) WRITE(numout,*) '       TALKN mean : ', zalksumn 
     375            trn(:,:,:,jptal) = trn(:,:,:,jptal) * alkmean / zalksumn 
     376 
     377            IF(lwp) WRITE(numout,*) '       PO4N  mean : ', zpo4sumn 
     378            trn(:,:,:,jppo4) = trn(:,:,:,jppo4) * po4mean / zpo4sumn 
     379 
     380            IF(lwp) WRITE(numout,*) '       NO3N  mean : ', zno3sumn 
     381            trn(:,:,:,jpno3) = trn(:,:,:,jpno3) * no3mean / zno3sumn 
     382 
     383            IF(lwp) WRITE(numout,*) '       SiO3N mean : ', zsilsumn 
     384            trn(:,:,:,jpsil) = MIN( 400.e-6,trn(:,:,:,jpsil) * silmean / zsilsumn ) 
     385            ! 
     386            ! 
     387            IF( .NOT. ln_top_euler ) THEN 
     388               zalksumb = glob_sum( 'p4zsms', trb(:,:,:,jptal) * cvol(:,:,:)  ) * zarea 
     389               zpo4sumb = glob_sum( 'p4zsms', trb(:,:,:,jppo4) * cvol(:,:,:)  ) * zarea * po4r 
     390               zno3sumb = glob_sum( 'p4zsms', trb(:,:,:,jpno3) * cvol(:,:,:)  ) * zarea * rno3 
     391               zsilsumb = glob_sum( 'p4zsms', trb(:,:,:,jpsil) * cvol(:,:,:)  ) * zarea 
    382392  
    383             IF(lwp) WRITE(numout,*) ' ' 
    384             IF(lwp) WRITE(numout,*) '       TALKB mean : ', zalksumb 
    385             trb(:,:,:,jptal) = trb(:,:,:,jptal) * alkmean / zalksumb 
    386  
    387             IF(lwp) WRITE(numout,*) '       PO4B  mean : ', zpo4sumb 
    388             trb(:,:,:,jppo4) = trb(:,:,:,jppo4) * po4mean / zpo4sumb 
    389  
    390             IF(lwp) WRITE(numout,*) '       NO3B  mean : ', zno3sumb 
    391             trb(:,:,:,jpno3) = trb(:,:,:,jpno3) * no3mean / zno3sumb 
    392  
    393             IF(lwp) WRITE(numout,*) '       SiO3B mean : ', zsilsumb 
    394             trb(:,:,:,jpsil) = MIN( 400.e-6,trb(:,:,:,jpsil) * silmean / zsilsumb ) 
     393               IF(lwp) WRITE(numout,*) ' ' 
     394               IF(lwp) WRITE(numout,*) '       TALKB mean : ', zalksumb 
     395               trb(:,:,:,jptal) = trb(:,:,:,jptal) * alkmean / zalksumb 
     396 
     397               IF(lwp) WRITE(numout,*) '       PO4B  mean : ', zpo4sumb 
     398               trb(:,:,:,jppo4) = trb(:,:,:,jppo4) * po4mean / zpo4sumb 
     399 
     400               IF(lwp) WRITE(numout,*) '       NO3B  mean : ', zno3sumb 
     401               trb(:,:,:,jpno3) = trb(:,:,:,jpno3) * no3mean / zno3sumb 
     402 
     403               IF(lwp) WRITE(numout,*) '       SiO3B mean : ', zsilsumb 
     404               trb(:,:,:,jpsil) = MIN( 400.e-6,trb(:,:,:,jpsil) * silmean / zsilsumb ) 
     405           ENDIF 
    395406        ENDIF 
    396407        ! 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zmicro.F90

    r10070 r10345  
    1515   USE trc             !  passive tracers common variables  
    1616   USE sms_pisces      !  PISCES Source Minus Sink variables 
    17    USE p5zice          !  Phytoplankton limitation terms 
     17   USE p5zlim          !  Phytoplankton limitation terms 
    1818   USE iom             !  I/O manager 
    1919   USE prtctl_trc      !  print control for debugging 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zmort.F90

    r10070 r10345  
    1414   USE trc             !  passive tracers common variables  
    1515   USE sms_pisces      !  PISCES Source Minus Sink variables 
    16    USE p5zice          !  Phytoplankton limitation terms 
     16   USE p5zlim          !  Phytoplankton limitation terms 
    1717   USE prtctl_trc      !  print control for debugging 
    1818 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/P4Z/p5zprod.F90

    r10314 r10345  
    1616   USE trc             !  passive tracers common variables  
    1717   USE sms_pisces      !  PISCES Source Minus Sink variables 
    18    USE p5zice          !  Co-limitations of differents nutrients 
     18   USE p5zlim          !  Co-limitations of differents nutrients 
    1919   USE prtctl_trc      !  print control for debugging 
    2020   USE iom             !  I/O manager 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/par_sed.F90

    r10068 r10345  
    77   !!        !  06-12  (C. Ethe)  Orignal 
    88   !!---------------------------------------------------------------------- 
    9 #if defined key_sed 
    10    !!---------------------------------------------------------------------- 
    11    !!   'key_sed'                                                  Sediment  
    12    !!---------------------------------------------------------------------- 
     9   !! $Id$ 
    1310 
    1411   !! Domain characteristics 
     
    1916      jpim1    =>   jpim1 ,  & !: jpi - 1 
    2017      jpjm1    =>   jpjm1 ,  & !: jpj - 1 
    21       jpij     =>   jpij      !: jpi x jpj 
    22       jp_tem   =>   jp_tem    !: indice of temperature 
     18      jpij     =>   jpij  ,  & !: jpi x jpj 
     19      jp_tem   =>   jp_tem,  & !: indice of temperature 
    2320      jp_sal   =>   jp_sal     !: indice of salintity 
    2421 
    25 #if ! defined key_sed_off 
    26    USE par_pisces 
    27 #endif 
    28  
    29    INTEGER, PARAMETER :: jpdta = 12 
    30  
     22   INTEGER, PARAMETER :: jpdta = 17 
    3123 
    3224   ! Vertical sediment geometry 
    33    INTEGER, PARAMETER :: & 
    34       jpksed   = 11         ,   & !: number of sediment layers 
    35       jpksedm1 = jpksed - 1  
    36        
     25   INTEGER, PUBLIC   ::      & 
     26      jpksed   = 11 ,        & 
     27      jpksedm1 = 10 
     28 
    3729   ! sediment tracer species 
    38    INTEGER, PARAMETER :: & 
    39       jpsol = 4,         &  !: number of solid component 
    40       jpwat = 7,         &   !: number of pore water component 
    41       jpwatp1 = jpwat + 1 
     30   INTEGER, PARAMETER ::    & 
     31      jpsol =  8,           &  !: number of solid component 
     32      jpwat = 10,           &   !: number of pore water component 
     33      jpwatp1 = jpwat +1,   & 
     34      jpsol1 = jpsol - 1 
     35 
    4236    
    4337   ! pore water components        
     
    4943      jwpo4  = 5,        & !: phosphate 
    5044      jwalk  = 6,        & !: alkalinity 
    51       jwc13  = 7           !: dissolved inorganic carbon 13 
     45      jwnh4  = 7,        & !: Ammonium 
     46      jwh2s  = 8,        & !: Sulfate 
     47      jwso4  = 9,        & !: H2S 
     48      jwfe2  = 10          !: Fe2+ 
    5249 
    5350   ! solid components        
     
    5653      jsclay  = 2,        & !: clay 
    5754      jspoc   = 3,        & !: organic carbon 
    58       jscal   = 4           !: calcite 
     55      jscal   = 4,        & !: calcite 
     56      jspos   = 5,        & !: semi-ref POC 
     57      jspor   = 6,        & !: refractory POC 
     58      jsfeo   = 7,        & !: iron hydroxides 
     59      jsfes   = 8           !: FeS 
    5960 
    6061   INTEGER, PARAMETER ::  & 
    6162      jptrased   = jpsol + jpwat , & 
    62       jpdia3dsed = 3          , & 
    63       jpdia2dsed = 7 
    64 #endif 
     63      jpdia3dsed = 2             , & 
     64      jpdia2dsed = 12 
    6565 
    66    !!---------------------------------------------------------------------- 
    67    !! NEMO/TOP 4.0 , NEMO Consortium (2018) 
    68    !! $Id$  
    69    !! Software governed by the CeCILL license (see ./LICENSE) 
    70    !!====================================================================== 
    7166END MODULE par_sed 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sed.F90

    r9124 r10345  
    77   !!        !  06-12  (C. Ethe)  Orignal 
    88   !!---------------------------------------------------------------------- 
    9 #if defined key_sed 
    10    !!---------------------------------------------------------------------- 
    11    !!   'key_sed'                                                  Sediment  
    12    !!---------------------------------------------------------------------- 
    139   USE par_sed 
     10   USE oce_sed 
    1411   USE in_out_manager 
     12 
    1513 
    1614   IMPLICIT NONE 
    1715   PUBLIC 
    1816 
    19    PUBLIC sed_alloc    
    20  
    21    USE dom_oce , ONLY :   nidom     =>   nidom          !: 
    22    USE dom_oce , ONLY :   glamt     =>   glamt          !: longitude of t-point (degre) 
    23    USE dom_oce , ONLY :   gphit     =>   gphit          !: latitude  of t-point (degre) 
    24    USE dom_oce , ONLY :   e3t_1d    =>   e3t_1d         !: reference depth of t-points (m) 
    25    USE dom_oce , ONLY :   mbkt      =>   mbkt           !: vertical index of the bottom last T- ocean level 
    26    USE dom_oce , ONLY :   tmask     =>   tmask          !: land/ocean mask at t-points 
    27    USE dom_oce , ONLY :   rdt       =>   rdt            !: time step for the dynamics 
    28    USE dom_oce , ONLY :   nyear     =>   nyear          !: Current year 
    29    USE dom_oce , ONLY :   nmonth    =>   nmonth         !: Current month 
    30    USE dom_oce , ONLY :   nday      =>   nday           !: Current day 
    31    USE dom_oce , ONLY :   ndastp    =>   ndastp         !: time step date in year/month/day aammjj 
    32    USE dom_oce , ONLY :   nday_year =>   nday_year      !: curent day counted from jan 1st of the current year 
    33    USE dom_oce , ONLY :   adatrj    =>   adatrj         !: number of elapsed days since the begining of the run 
    34    !                                !: it is the accumulated duration of previous runs 
    35    !                                !: that may have been run with different time steps. 
    36  
    37 #if ! defined key_sed_off 
    38  
    39    USE oce     , ONLY :  tsn        =>   tsn             !: pot. temperature (celsius) and salinity (psu) 
    40  
    41    USE trc     , ONLY :  trn        =>   trc             !: tracer  
    42    USE trc     , ONLY :  nwritetrc  =>   nwritetrc       !: outputs frequency of tracer model 
    43  
    44    USE p4zsink , ONLY :  sinking    =>   sinking         !: sinking flux for POC 
    45    USE p4zsink , ONLY :  sinking2   =>   sinking2        !: sinking flux for GOC 
    46    USE p4zsink , ONLY :  sinkcal    =>   sinkcal         !: sinking flux for calcite 
    47    USE p4zsink , ONLY :  sinksil    =>   sinksil         !: sinking flux for opal ( dsi ) 
    48  
    49    USE sms_pisces, ONLY : akb3      =>   akb3            !: Chemical constants   
    50    USE sms_pisces, ONLY : ak13      =>   ak13            !: Chemical constants   
    51    USE sms_pisces, ONLY : ak23      =>   ak23            !: Chemical constants   
    52    USE sms_pisces, ONLY : akw3      =>   akw3            !: Chemical constants   
    53    USE sms_pisces, ONLY : aksp      =>   aksp            !: Chemical constants   
    54    USE sms_pisces, ONLY : borat     =>   borat           !: Chemical constants ( borat )  
    55  
    56 #endif    
    57  
     17   PUBLIC sed_alloc 
    5818 
    5919   !! Namelist 
    60    REAL(wp), PUBLIC, DIMENSION(5) ::  reac                !: reactivity rc in  [l.mol-1.s-1] 
    6120   REAL(wp), PUBLIC               ::  reac_sil            !: reactivity of silicate in  [l.mol-1.s-1] 
    6221   REAL(wp), PUBLIC               ::  reac_clay           !: reactivity of clay in  [l.mol-1.s-1] 
    63    REAL(wp), PUBLIC               ::  reac_poc            !: reactivity of poc in  [l.mol-1.s-1] 
    64    REAL(wp), PUBLIC               ::  reac_no3            !: reactivity of no3 in  [l.mol-1.s-1] 
     22   REAL(wp), PUBLIC               ::  reac_ligc           !: reactivity of Ligands [l.mol-1.s-1] 
     23   REAL(wp), PUBLIC               ::  reac_pocl           !: reactivity of pocl in  [s-1] 
     24   REAL(wp), PUBLIC               ::  reac_pocs           !: reactivity of pocs in  [s-1] 
     25   REAL(wp), PUBLIC               ::  reac_pocr           !: reactivity of pocr in  [s-1] 
     26   REAL(wp), PUBLIC               ::  reac_nh4            !: reactivity of NH4 in  [l.mol-1.s-1] 
     27   REAL(wp), PUBLIC               ::  reac_h2s            !: reactivity of ODU in  [l.mol-1.s-1] 
     28   REAL(wp), PUBLIC               ::  reac_fe2            !: reactivity of Fe2+ in  [l.mol-1.s-1] 
     29   REAL(wp), PUBLIC               ::  reac_feh2s          !: reactivity of Fe2+ in  [l.mol-1.s-1] 
     30   REAL(wp), PUBLIC               ::  reac_fes            !: reactivity of Fe with H2S in  [l.mol-1.s-1] 
     31   REAL(wp), PUBLIC               ::  reac_feso           !: reactivity of FeS with O2 in  [l.mol-1.s-1] 
    6532   REAL(wp), PUBLIC               ::  reac_cal            !: reactivity of cal in  [l.mol-1.s-1] 
    66    REAL(wp), PUBLIC               ::  sat_sil             !: saturation concentration for silicate in [mol.l-1] 
    67    REAL(wp), PUBLIC               ::  sat_clay            !: saturation concentration for clay in [mol.l-1] 
     33   REAL(wp), PUBLIC               ::  adsnh4              !: adsorption coefficient of NH4 
     34   REAL(wp), PUBLIC               ::  ratligc             !: C/L ratio in POC 
    6835   REAL(wp), PUBLIC               ::  so2ut  
    6936   REAL(wp), PUBLIC               ::  srno3  
    7037   REAL(wp), PUBLIC               ::  spo4r  
    7138   REAL(wp), PUBLIC               ::  srDnit  
    72    REAL(wp), PUBLIC               ::  sthro2              !: threshold O2 concen. in [mol.l-1] 
    73    REAL(wp), PUBLIC               ::  pdb = 0.0112372     !: 13C/12C in PD Belemnite 
    74    REAL(wp), PUBLIC               ::  rc13P  = 0.980      !: 13C/12C in POC = rc13P*PDB 
    75    REAL(wp), PUBLIC               ::  rc13Ca = 1.001      !: 13C/12C in CaCO3 = rc13Ca*PDB 
    7639   REAL(wp), PUBLIC               ::  dtsed               !: sedimentation time step 
    77    REAL(wp), PUBLIC               ::  db                  !: bioturb coefficient in [cm2.s-1] 
    78  
     40   REAL(wp), PUBLIC               ::  dtsed2              !: sedimentation time step 
    7941   INTEGER , PUBLIC               ::  nitsed000 
    8042   INTEGER , PUBLIC               ::  nitsedend 
    81    INTEGER , PUBLIC               ::  nwrised 
    82    INTEGER , PUBLIC               ::  nfreq 
    83    REAL(wp), PUBLIC               ::  dens                !: density of solid material 
     43   INTEGER, PUBLIC                ::  nrseddt 
     44   REAL    , PUBLIC               ::  sedmask 
     45   REAL(wp), PUBLIC               ::  denssol                !: density of solid material 
     46   INTEGER , PUBLIC               ::  numrsr, numrsw   !: logical unit for sed restart (read and write) 
     47   LOGICAL , PUBLIC               ::  lrst_sed       !: logical to control the trc restart write 
     48   LOGICAL , PUBLIC               ::  ln_rst_sed  = .TRUE.     !: initialisation from a restart file or not 
     49   LOGICAL , PUBLIC               ::  ln_btbz     = .FALSE.    !: Depth variation of the bioturbation coefficient 
     50   LOGICAL , PUBLIC               ::  ln_irrig    = .FALSE.    !: iActivation of the bioirrigation 
     51   LOGICAL , PUBLIC               ::  ln_sed_2way = .FALSE.    !: 2 way coupling with PISCES 
     52   LOGICAL , PUBLIC               ::  ln_sediment_offline = .FALSE. !: Offline mode for sediment module 
     53   INTEGER             , PUBLIC   ::  nn_rstsed      !: control of the time step ( 0 or 1 ) for pass. tr. 
     54   INTEGER , PUBLIC               ::  nn_dtsed = 1   !: frequency of step on passive tracers 
     55   CHARACTER(len = 80) , PUBLIC   ::  cn_sedrst_in   !: suffix of pass. tracer restart name (input) 
     56   CHARACTER(len = 256), PUBLIC   ::  cn_sedrst_indir  !: restart input directory 
     57   CHARACTER(len = 80) , PUBLIC   ::  cn_sedrst_out  !: suffix of pass. tracer restart name (output) 
     58   CHARACTER(len = 256), PUBLIC   ::  cn_sedrst_outdir  !: restart output directory 
     59 
    8460   ! 
    8561   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::  pwcp       !: pore water sediment data at given time-step 
     
    8763   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::  solcp      !: solid sediment data at given time-step 
    8864   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::  solcp0     !: solid sediment data at initial time 
     65   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::  trc_dta 
     66   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::  diff 
    8967 
    9068   !! * Shared module variables 
     
    10280   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  press      !: pressure 
    10381   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  raintg     !: total massic flux rained in each cell (sum of sol. comp.) 
     82   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  fecratio   !: Fe/C ratio in falling particles to the sediments 
    10483   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  dzdep      !: total thickness of solid material rained [cm] in each cell 
     84   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  zkbot      !: total thickness of solid material rained [cm] in each cell 
     85   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  wacc       !: total thickness of solid material rained [cm] in each cell 
    10586   ! 
    10687   REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE ::  hipor      !: [h+] in mol/kg*densSW  
     
    127108   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  aksis  
    128109   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  aksps  
     110   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  sieqs 
     111   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  aks3s 
     112   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  akf3s 
     113   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  sulfats 
     114   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  fluorids 
    129115 
    130116   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  mol_wgt    !: molecular weight of solid sediment data 
     
    133119   !! Geometry 
    134120   INTEGER , PUBLIC, SAVE                          ::  jpoce, indoce !: Ocean points ( number/indices ) 
    135    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  iarroce       !: Computation of 1D array of sediments points 
     121   INTEGER , PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  iarroce       !: Computation of 1D array of sediments points 
    136122   REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE ::  epkbot        !: ocean bottom layer thickness 
     123   REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE ::  gdepbot       !: Depth of the sediment 
    137124   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  dzkbot        !: ocean bottom layer thickness in meters 
    138    REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::  tmasksed      !: sediment mask 
    139    REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE ::  sbathy        !: bathymetry 
    140125   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  dz            !: sediment layers thickness 
    141126   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  por           !: porosity profile      
    142127   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  por1          !: 1-por  
    143    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  profsed       !: depth of middle of each layer 
    144128   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  volw          !: volume of pore water cell fraction 
    145129   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  vols          !: volume of solid cell fraction 
    146    REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  diff          !: diffusion ceofficient 
     130   REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE ::  db            !: bioturbation ceofficient 
     131   REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE ::  irrig        !: bioturbation ceofficient 
    147132   REAL(wp), PUBLIC, DIMENSION(:    ), ALLOCATABLE ::  rdtsed        !:  sediment model time-step 
     133   REAL(wp), PUBLIC, DIMENSION(:,:  ), ALLOCATABLE :: sedligand 
    148134   REAL(wp)  ::   dens               !: density of solid material 
    149135   !! Inputs / Outputs 
     
    171157      !!------------------------------------------------------------------- 
    172158      ! 
    173       ALLOCATE( trc_dta(jpi,jpj,jdta)                                     ,   & 
    174          &      epkbot(jpi,jpj), sbathy(jpi,jpj)                          ,   & 
    175          &      tmasksed(jpi,jpj,jpksed)                                  ,   & 
    176          &      dz(jpksed)  , por(jpksed) , por1(jpksed), profsed(jpksed) ,   & 
    177          &      volw(jpksed), vols(jpksed), diff(jpksed), rdtsed(jpksed)  ,   & 
     159      ALLOCATE( trc_data(jpi,jpj,jpdta)                                   ,   & 
     160         &      epkbot(jpi,jpj), gdepbot(jpi,jpj)        ,   & 
     161         &      dz(jpksed)  , por(jpksed) , por1(jpksed)                  ,   & 
     162         &      volw(jpksed), vols(jpksed), rdtsed(jpksed)  ,   & 
    178163         &      trcsedi  (jpi,jpj,jpksed,jptrased)                        ,   & 
    179164         &      flxsedi3d(jpi,jpj,jpksed,jpdia3dsed)                      ,   & 
    180          &      flxsedi2d(jpi,jpj,jpksed,jpdia2dsed)                      ,   & 
     165         &      flxsedi2d(jpi,jpj,jpdia2dsed)                             ,   & 
    181166         &      mol_wgt(jpsol),                                           STAT=sed_alloc ) 
    182167 
     
    185170   END FUNCTION sed_alloc 
    186171 
    187 #else 
    188    !!====================================================================== 
    189    !! No Sediment model 
    190    !!====================================================================== 
    191 #endif 
    192  
    193172END MODULE sed 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedadv.F90

    r9124 r10345  
    44   !!    Sediment : vertical advection and burial 
    55   !!===================================================================== 
    6 #if defined key_sed 
    7    !!---------------------------------------------------------------------- 
    8    !!   'key_sed'                                                  Sediment  
     6   !! * Modules used 
    97   !!---------------------------------------------------------------------- 
    108   !!   sed_adv : 
    119   !!---------------------------------------------------------------------- 
    1210   USE sed     ! sediment global variable 
     11   USE lib_mpp         ! distribued memory computing library 
     12 
     13   IMPLICIT NONE 
     14   PRIVATE 
    1315 
    1416   PUBLIC sed_adv 
    15  
    16    !! * Module variable 
    17    INTEGER, PARAMETER  ::  nztime = jpksed         ! number of time step between sunrise and sunset 
    18  
    19    REAL(wp), DIMENSION(jpksed), SAVE :: dvolsp, dvolsm 
    20    REAL(wp), DIMENSION(jpksed), SAVE :: c2por, ckpor 
     17   PUBLIC sed_adv_alloc 
     18 
     19   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) :: dvolsp, dvolsm 
     20   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) :: c2por, ckpor 
    2121 
    2222   REAL(wp) :: cpor 
     
    4949      ! * local variables 
    5050      INTEGER :: ji, jk, js  
    51       INTEGER :: jn, ntimes, ikwneg 
     51      INTEGER :: jn, ntimes, nztime, ikwneg 
    5252       
    53       REAL(wp), DIMENSION(:,:), ALLOCATABLE :: zsolcpno 
    54       REAL(wp), DIMENSION(:  ), ALLOCATABLE :: zfilled, zfull, zfromup, zempty 
    55       REAL(wp), DIMENSION(:,:), ALLOCATABLE :: zgap, zwb 
    56       REAL(wp), DIMENSION(:,:), ALLOCATABLE :: zrainrf 
    57       REAL(wp), DIMENSION(nztime) :: zraipush 
    58  
    59       REAL(wp) :: zkwnup, zkwnlo, zfrac,  zfromce, zrest 
     53      REAL(wp), DIMENSION(jpksed,jpsol) :: zsolcpno 
     54      REAL(wp), DIMENSION(jpksed)      :: zfilled, zfull, zfromup, zempty 
     55      REAL(wp), DIMENSION(jpoce,jpksed) :: zgap, zwb 
     56      REAL(wp), DIMENSION(jpoce,jpsol) :: zrainrf 
     57      REAL(wp), DIMENSION(:  ), ALLOCATABLE :: zraipush 
     58 
     59      REAL(wp) :: zkwnup, zkwnlo, zfrac,  zfromce, zrest, sumtot, zsumtot1 
    6060 
    6161      !------------------------------------------------------------------------ 
    6262 
    6363 
     64      IF( ln_timing )  CALL timing_start('sed_adv') 
     65! 
    6466      IF( kt == nitsed000 ) THEN 
    65          WRITE(numsed,*) ' ' 
    66          WRITE(numsed,*) ' sed_adv : vertical sediment advection  ' 
    67          WRITE(numsed,*) ' ' 
    68          por1clay = dens * por1(jpksed) * dz(jpksed) / mol_wgt(jsclay) 
     67         IF (lwp) THEN 
     68            WRITE(numsed,*) ' ' 
     69            WRITE(numsed,*) ' sed_adv : vertical sediment advection  ' 
     70            WRITE(numsed,*) ' ' 
     71         ENDIF 
     72         por1clay = denssol * por1(jpksed) * dz(jpksed) 
    6973         cpor     = por1(jpksed) / por1(2) 
    7074         DO jk = 2, jpksed 
     
    8084      ENDIF 
    8185 
    82       ALLOCATE( zsolcpno(jpksed,jpsol), zrainrf(jpoce,jpsol) ) 
    83       ALLOCATE( zfilled(jpksed), zfull(jpksed), zfromup(jpksed), zempty(jpksed) ) 
    84       ALLOCATE( zgap (jpoce,jpksed)   , zwb(jpoce,jpksed)  )   
    85  
    8686      ! Initialization of data for mass balance calculation 
    8787      !--------------------------------------------------- 
     
    8989      tosed  (:,:) = 0.  
    9090      rloss  (:,:) = 0. 
    91  
     91      ikwneg = 1 
     92      nztime = jpksed 
     93 
     94      ALLOCATE( zraipush(nztime) ) 
    9295 
    9396      ! Initiate gap  
     
    104107      zgap(1:jpoce,1:jpksed) = 1. - zgap(1:jpoce,1:jpksed)    
    105108 
    106  
    107109      ! Initiate burial rates 
    108110      !----------------------- 
    109111      zwb(:,:) = 0. 
    110112      DO jk = 2, jpksed 
    111          zfrac =  dtsed / ( dens * por1(jk) )      
     113         zfrac =  dtsed / ( denssol * por1(jk) )      
    112114         DO ji = 1, jpoce 
    113115            zwb(ji,jk) = zfrac * raintg(ji) 
     
    127129      ENDDO 
    128130 
    129  
    130131      zrainrf(:,:) = 0. 
    131132      DO ji = 1, jpoce 
     
    206207                  ! quantities to push in deeper sediment 
    207208                  tosed  (ji,js) = zsolcpno(jpksed,js) & 
    208                      &           * zwb(ji,jpksed) * dens * por1(jpksed) / mol_wgt(js) 
    209                ENDDO 
    210                 
     209                     &           * zwb(ji,jpksed) * denssol * por1(jpksed) 
     210               ENDDO 
     211 
    211212            ELSE ! what is remaining is great than dz(2) 
    212213 
    213214               ntimes = INT( zrest / dz(2) ) + 1 
    214                IF( ntimes > nztime ) THEN 
    215                   WRITE( numsed,* ) ' sedadv : rest too large at sediment point ji = ', ji 
    216                   STOP 
    217                ENDIF 
     215               IF( ntimes > nztime ) CALL ctl_stop( 'STOP', 'sed_adv : rest too large ' ) 
    218216               zraipush(1) = dz(2) 
    219217               zrest = zrest - zraipush(1) 
     
    249247                     fromsed(ji,js) = 0. 
    250248                     tosed  (ji,js) = tosed(ji,js) + zsolcpno(jpksed,js) * zraipush(jn) & 
    251                         &             * dens * por1(2) / mol_wgt(js) 
     249                        &             * denssol * por1(2)  
    252250                  ENDDO 
    253251               ENDDO 
     
    279277            ! for the last layer, one make go up clay  
    280278            solcp(ji,jpksed,jsclay) = solcp(ji,jpksed,jsclay) + zempty(jpksed) * 1. 
    281             !! C. Heinze      fromsed(ji,jsclay) = zempty(jpksed) * 1. * dens * por1(jpksed) / mol_wgt(jsclay) 
    282279            fromsed(ji,jsclay) = zempty(jpksed) * 1. * por1clay 
    283  
    284280         ELSE  ! rain > 0 and rain < total reaction loss 
    285281 
     
    323319               ENDDO 
    324320               solcp(ji,jpksed,jsclay) =  solcp(ji,jpksed,jsclay) + zempty(jpksed) * 1. 
    325                !! C. Heinze  fromsed(ji,jsclay) = zempty(jpksed) * 1. * dens * por1(jpksed) / mol_wgt(jsclay) 
     321               !! C. Heinze  fromsed(ji,jsclay) = zempty(jpksed) * 1. * denssol * por1(jpksed) / mol_wgt(jsclay) 
    326322               fromsed(ji,jsclay) = zempty(jpksed) * 1. * por1clay 
    327323                
     
    339335                  solcp(ji,2,js) = zfull(2) * zsolcpno(2,js) + zempty(2) * zrainrf(ji,js) 
    340336               ENDDO 
    341                DO  js = 1, jpsol               
     337               DO  js = 1, jpsol 
    342338                  DO jk = jpksedm1, 3, -1 
    343339                     solcp(ji,jk,js) = zfull(jk) * zsolcpno(jk,js) + zempty(jk) * zsolcpno(jk-1,js) 
     
    349345               ENDDO 
    350346               solcp(ji,jpksed,jsclay) = solcp(ji,jpksed,jsclay) + zkwnlo * 1. 
    351                ! Heinze  fromsed(ji,jsclay) = zkwnlo * 1. * dens * por1(jpksed) / mol_wgt(jsclay) 
     347               ! Heinze  fromsed(ji,jsclay) = zkwnlo * 1. * denssol * por1(jpksed) / mol_wgt(jsclay) 
    352348               fromsed(ji,jsclay) = zkwnlo * 1.* por1clay 
    353349            ELSE   ! 2 < ikwneg(ji) <= jpksedm1 
     
    415411                  fromsed(ji,js)   = 0. 
    416412               ENDDO 
    417                ! Heinze  fromsed(ji,jsclay) = zempty * 1. * dens * por1(jpksed) / mol_wgt(jsclay) 
     413               ! Heinze  fromsed(ji,jsclay) = zempty * 1. * denssol * por1(jpksed) / mol_wgt(jsclay) 
    418414               fromsed(ji,jsclay) = zempty(jpksed) * 1. * por1clay 
     415 
    419416            ENDIF ! ikwneg(ji) = 2 
    420417         ENDIF  ! zwb > 0 
     
    425422      raintg(:)   = 0. 
    426423 
    427       DEALLOCATE( zsolcpno )    
    428       DEALLOCATE( zrainrf  ) 
    429       DEALLOCATE( zfilled  ) 
    430       DEALLOCATE( zfull    ) 
    431       DEALLOCATE( zfromup  ) 
    432       DEALLOCATE( zempty   ) 
    433       DEALLOCATE( zgap     )   
    434       DEALLOCATE( zwb      ) 
    435  
     424      DEALLOCATE( zraipush ) 
     425 
     426      IF( ln_timing )  CALL timing_stop('sed_adv') 
    436427 
    437428   END SUBROUTINE sed_adv 
    438 #else 
    439    !!====================================================================== 
    440    !! MODULE sedbtb  :   Dummy module  
    441    !!====================================================================== 
    442    !! $Id$ 
    443 CONTAINS 
    444    SUBROUTINE sed_adv( kt )         ! Empty routine 
    445       INTEGER, INTENT(in) :: kt 
    446       WRITE(*,*) 'sed_adv: You should not have seen this print! error?', kt 
    447    END SUBROUTINE sed_adv 
    448  
    449    !!====================================================================== 
    450  
    451 #endif 
     429 
     430 
     431   INTEGER FUNCTION sed_adv_alloc() 
     432      !!---------------------------------------------------------------------- 
     433      !!                     ***  ROUTINE p4z_prod_alloc  *** 
     434      !!---------------------------------------------------------------------- 
     435      ALLOCATE( dvolsp(jpksed), dvolsm(jpksed), c2por(jpksed),         & 
     436      &         ckpor(jpksed) ,           STAT = sed_adv_alloc ) 
     437      ! 
     438      IF( sed_adv_alloc /= 0 ) CALL ctl_warn('sed_adv_alloc : failed to allocate arrays.') 
     439      ! 
     440   END FUNCTION sed_adv_alloc 
     441 
    452442END MODULE sedadv 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedarr.F90

    r10068 r10345  
    44   !!              transform 1D (2D) array to a 2D (1D) table 
    55   !!====================================================================== 
    6 #if defined key_sed 
     6 
    77   !!---------------------------------------------------------------------- 
    88   !!   arr_2d_1d  : 2-D to 1-D 
     
    1111   !! * Modules used 
    1212   USE par_sed 
     13   USE dom_oce 
     14   USE sed 
    1315 
    1416   IMPLICIT NONE 
     
    2830 
    2931   !!---------------------------------------------------------------------- 
    30    !! NEMO/TOP 4.0 , NEMO Consortium (2018) 
     32   !! NEMO/TOP 3.3 , NEMO Consortium (2010) 
    3133   !! $Id$  
    32    !! Software governed by the CeCILL license (see ./LICENSE) 
     34   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) 
    3335   !!---------------------------------------------------------------------- 
    3436CONTAINS 
     
    4244 
    4345      INTEGER ::  jn, jid, jjd 
     46 
     47      IF( ln_timing )   CALL timing_start('pack_arr_2d_1d') 
    4448         
    4549      DO jn = 1, ndim1d 
     
    4852         tab1d(jn)  = tab2d(jid, jjd) 
    4953      END DO  
     54 
     55      IF( ln_timing )   CALL timing_stop('pack_arr_2d_1d') 
    5056 
    5157   END SUBROUTINE pack_arr_2d_1d 
     
    5965      INTEGER ::  jn, jid, jjd 
    6066 
     67      IF( ln_timing )   CALL timing_start('unpack_arr_1d_2d') 
     68 
    6169      DO jn = 1, ndim1d 
    6270         jid             = MOD( tab_ind(jn) - 1, jpi) + 1 
     
    6472         tab2d(jid, jjd) = tab1d(jn) 
    6573      END DO 
     74 
     75      IF( ln_timing )   CALL timing_stop('unpack_arr_1d_2d') 
    6676 
    6777   END SUBROUTINE unpack_arr_1d_2d 
     
    7585      INTEGER, DIMENSION(ndim1d) ::  jid, jjd         
    7686      INTEGER ::    jk, jn , ji, jj 
     87 
     88      IF( ln_timing )   CALL timing_start('pack_arr_2d_3d') 
    7789       
    7890      DO jn = 1, ndim1d 
     
    88100         ENDDO 
    89101      ENDDO 
     102 
     103      IF( ln_timing )   CALL timing_stop('pack_arr_2d_3d') 
    90104       
    91105   END SUBROUTINE pack_arr_3d_2d 
     
    100114      INTEGER, DIMENSION(ndim1d) ::  jid, jjd         
    101115      INTEGER ::   jk, jn , ji, jj 
    102  
    103      DO jn = 1, ndim1d 
     116      ! 
     117      IF( ln_timing )   CALL timing_start('unpack_arr_2d_3d') 
     118      ! 
     119      DO jn = 1, ndim1d 
    104120         jid(jn) = MOD( tab_ind(jn) - 1, jpi ) + 1 
    105121         jjd(jn) = ( tab_ind(jn) - 1 ) / jpi + 1 
     
    114130      ENDDO 
    115131 
     132      IF( ln_timing )   CALL timing_stop('unpack_arr_2d_3d') 
     133 
    116134   END SUBROUTINE unpack_arr_2d_3d 
    117135 
    118 #else 
    119    !!====================================================================== 
    120    !! MODULE sedarr  :   Dummy module 
    121    !!====================================================================== 
    122 CONTAINS 
    123    SUBROUTINE pack_arr         ! Empty routine 
    124    END SUBROUTINE  pack_arr 
    125    SUBROUTINE unpack_arr         ! Empty routine 
    126    END SUBROUTINE  unpack_arr 
    127    !!====================================================================== 
    128 #endif 
    129136END MODULE sedarr 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedbtb.F90

    r5215 r10345  
    11MODULE sedbtb 
    2 #if defined key_sed 
    32   !!====================================================================== 
    43   !!              ***  MODULE  sedbtb  *** 
     
    87   USE sed     ! sediment global variable 
    98   USE sedmat  ! linear system of equations 
     9   USE lib_mpp         ! distribued memory computing library 
     10 
     11   IMPLICIT NONE 
     12   PRIVATE 
    1013 
    1114   PUBLIC sed_btb 
     
    3336      ! * local variables 
    3437      INTEGER :: ji, jk, js 
    35       REAL(wp), DIMENSION(:,:,:) , ALLOCATABLE ::  zsol  !   solution 
     38      REAL(wp), DIMENSION(jpoce,jpksedm1,jpsol) ::  zsol  !   solution 
    3639      !------------------------------------------------------------------------ 
    3740 
     41      IF( ln_timing )  CALL timing_start('sed_btb') 
     42 
    3843      IF( kt == nitsed000 ) THEN 
    39          WRITE(numsed,*) ' sed_btb : Bioturbation  ' 
    40          WRITE(numsed,*) ' ' 
     44         IF (lwp) WRITE(numsed,*) ' sed_btb : Bioturbation  ' 
     45         IF (lwp) WRITE(numsed,*) ' ' 
    4146      ENDIF 
    4247 
    4348      ! Initializations 
    4449      !---------------- 
    45       ALLOCATE( zsol(jpoce,jpksedm1,jpsol) ) 
    46  
    4750      zsol(:,:,:) = 0. 
    48  
    4951 
    5052      ! right hand side of coefficient matrix 
     
    5860      ENDDO 
    5961 
    60       CALL sed_mat( jpsol, jpoce, jpksedm1, zsol ) 
     62      CALL sed_mat( jpsol, jpoce, jpksedm1, zsol, dtsed / 2.0 ) 
    6163 
    6264 
     
    7072         ENDDO 
    7173      ENDDO 
    72       
    73       DEALLOCATE( zsol ) 
     74 
     75      IF( ln_timing )  CALL timing_stop('sed_btb') 
    7476 
    7577   END SUBROUTINE sed_btb 
    76 #else 
    77    !!====================================================================== 
    78    !! MODULE sedbtb  :   Dummy module  
    79    !!====================================================================== 
    80    !! $Id$ 
    81 CONTAINS 
    82    SUBROUTINE sed_btb( kt )         ! Empty routine 
    83       INTEGER, INTENT(in) :: kt 
    84       WRITE(*,*) 'sed_btb: You should not have seen this print! error?', kt 
    85    END SUBROUTINE sed_btb 
    8678 
    87    !!====================================================================== 
    88  
    89 #endif 
    9079END MODULE sedbtb 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedchem.F90

    r5215 r10345  
    11MODULE sedchem 
    22 
    3 #if defined key_sed  
    43   !!====================================================================== 
    54   !!                        ***  Module sedchem  *** 
     
    98   USE sed     ! sediment global variable 
    109   USE sedarr 
     10   USE eosbn2, ONLY : neos 
     11   USE lib_mpp         ! distribued memory computing library 
     12 
     13   IMPLICIT NONE 
     14   PRIVATE 
    1115 
    1216   !! * Accessibility 
    13    PUBLIC sed_chem    
     17   PUBLIC sed_chem 
     18   PUBLIC ahini_for_at_sed     ! 
     19   PUBLIC solve_at_general_sed ! 
     20 
     21   ! Maximum number of iterations for each method 
     22   INTEGER, PARAMETER :: jp_maxniter_atgen    = 20 
     23   REAL(wp), PARAMETER :: pp_rdel_ah_target = 1.E-4_wp 
    1424 
    1525   !! * Module variables 
    1626   REAL(wp) :: & 
    17       salchl = 1./1.80655 , & ! conversion factor for salinity --> chlorinity (Wooster et al. 1969) 
    1827      calcon = 1.03E-2        ! mean calcite concentration [Ca2+] in sea water [mole/kg solution]  
    1928 
    20    REAL(wp) :: &              ! coeff. for 1. dissoc. of carbonic acid (Millero, 1995)    
    21       c10 = 3670.7   , & 
    22       c11 = 62.008   , & 
    23       c12 = 9.7944   , & 
    24       c13 = 0.0118   , & 
    25       c14 = 0.000116 
    26  
    27    REAL(wp) :: &              ! coeff. for 2. dissoc. of carbonic acid (Millero, 1995)    
    28       c20 = 1394.7   , & 
    29       c21 = 4.777    , & 
    30       c22 = 0.       , & 
    31       c23 = 0.0184   , & 
    32       c24 = 0.000118 
    33  
    34    REAL(wp) :: &              ! coeff. for 1. dissoc. of boric acid (Dickson and Goyet, 1994) 
    35       cb0  = -8966.90, & 
    36       cb1  = -2890.53, & 
    37       cb2  = -77.942 , & 
    38       cb3  = 1.728   , & 
    39       cb4  = -0.0996 , & 
    40       cb5  = 148.0248, & 
    41       cb6  = 137.1942, & 
    42       cb7  = 1.62142 , & 
    43       cb8  = -24.4344, & 
    44       cb9  = -25.085 , & 
    45       cb10 = -0.2474 , & 
    46       cb11 = 0.053105 
    47  
    48    REAL(wp) :: &             ! borat constants 
    49       bor1 = 0.000232, & 
    50       bor2 = 1./10.811 
    51  
    52    REAL(wp) :: &             ! constants for calculate concentrations  
    53       st1  = 0.14     , &    ! for sulfate (Morris & Riley 1966) 
    54       st2  = 1./96.062, & 
    55       ks0  = 141.328  , & 
    56       ks1  = -4276.1  , & 
    57       ks2  = -23.093  , & 
    58       ks3  = -13856.  , & 
    59       ks4  = 324.57   , & 
    60       ks5  = -47.986  , & 
    61       ks6  = 35474.   , & 
    62       ks7  = -771.54  , & 
    63       ks8  = 114.723  , & 
    64       ks9  = -2698.   , & 
    65       ks10 = 1776.    , & 
    66       ks11 = 1.       , & 
    67       ks12 = -0.001005  
    68  
    69    REAL(wp) :: &             ! constants for calculate concentrations  
    70       ft1  = 0.000067   , &  ! fluorides (Dickson & Riley 1979 ) 
    71       ft2  = 1./18.9984 , & 
    72       kf0  = -12.641    , & 
    73       kf1  = 1590.2     , & 
    74       kf2  = 1.525      , & 
    75       kf3  = 1.0        , & 
    76       kf4  =-0.001005 
    77  
    78    REAL(wp) :: &             ! coeff. for dissoc. of water (Dickson and Riley, 1979 ) 
    79       cw0 = -13847.26  , & 
    80       cw1 = 148.9802   , & 
    81       cw2 = -23.6521   , & 
    82       cw3 = 118.67     , & 
    83       cw4 = -5.977     , & 
    84       cw5 = 1.0495     , & 
    85       cw6 = -0.01615 
    86   
    87    REAL(wp) :: &             ! coeff. for dissoc. of phosphate (Millero (1974) 
    88       cp10 = 115.54    , & 
    89       cp11 = -4576.752 , & 
    90       cp12 = -18.453   , & 
    91       cp13 = -106.736  , & 
    92       cp14 = 0.69171   , & 
    93       cp15 = -0.65643  , & 
    94       cp16 = -0.01844  , & 
    95       cp20 = 172.1033  , & 
    96       cp21 = -8814.715 , & 
    97       cp22 = -27.927   , & 
    98       cp23 = -160.340  , & 
    99       cp24 = 1.3566    , & 
    100       cp25 = 0.37335   , & 
    101       cp26 = -0.05778  , & 
    102       cp30 = -18.126   , & 
    103       cp31 = -3070.75  , & 
    104       cp32 = 17.27039  , & 
    105       cp33 = 2.81197   , & 
    106       cp34 = -44.99486 , & 
    107       cp35 = -0.09984 
    108  
    109    REAL(wp) :: &             ! coeff. for dissoc. of silicates (Millero (1974)   
    110       cs10 = 117.40    , &   
    111       cs11 = -8904.2   , &  
    112       cs12 = -19.334   , &  
    113       cs13 = -458.79   , &  
    114       cs14 = 3.5913    , &  
    115       cs15 = 188.74    , &  
    116       cs16 = -1.5998   , &  
    117       cs17 = -12.1652  , &  
    118       cs18 = 0.07871   , &  
    119       cs19 = 0.        , &  
    120       cs20 = 1.        , &  
    121       cs21 = -0.001005 
    122  
    123    REAL(wp) :: &            ! coeff. for apparent solubility equilibrium  
    124       ! akcc1 = -34.452 , & ! of calcite (Ingle,1975,  1800, eq. 6) 
    125       ! akcc2 = -39.866 , &   
    126       ! akcc3 = 110.21  , &   
    127       ! akcc4 = -7.5752E-6   
    128       akcc1 = -171.9065 , &    ! Millero et al. 1995 from Mucci 1983 
    129       akcc2 = -0.077993 , &   
    130       akcc3 = 2839.319  , &   
    131       akcc4 = 71.595    , &   
    132       akcc5 = -0.77712  , &   
    133       akcc6 = 0.0028426 , &   
    134       akcc7 = 178.34    , &   
    135       akcc8 = -0.07711  , &   
    136       akcc9 = 0.0041249 
    137  
    138    REAL(wp) :: &                 ! universal gas constant 
    139       rgas = 83.145              ! bar.cm3/(mol.K) or R=8.31451 J/(g.mol.K) 
    140  
    141  
    142    ! coeff. for seawater pressure correction (millero 95)       
    143    REAL(wp), DIMENSION(8)  :: &  
    144       devk1, devk2, devk3, devk4, devk5 
    145  
    146    DATA devk1/ -25.5   , -15.82    , -29.48  , -25.60    , -48.76    , -14.51   , -23.12   , -26.57   /    
    147    DATA devk2/ 0.1271  , -0.0219   , 0.1622  , 0.2324    , -0.5304   , 0.1211   ,  0.1758  , 0.2020   /    
    148    DATA devk3/ 0.      , 0.        , 2.608E-3, -3.6246E-3, 0.        , -0.321E-3, -2.647E-3, -3.042E-3/    
    149    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 /    
    150    DATA devk5/0.0877E-3, -0.1475E-3, 0.      , 0.0794E-3 , -0.3692E-3, 0.0427E-3,  0.09E-3 , 0.0714E-3/ 
    151  
     29   REAL(wp) ::   rgas   = 83.14472      ! universal gas constants 
    15230 
    15331   ! coeff. for density of sea water (Millero & Poisson 1981)  
     
    16240   REAL(wp), DIMENSION(6)  :: Ddsw                     
    16341   DATA Ddsw / 999.842594 , 6.793952E-2 , -9.095290E-3, 1.001685E-4, -1.120083E-6, 6.536332E-9/ 
     42 
     43  REAL(wp) :: devk10  = -25.5 
     44   REAL(wp) :: devk11  = -15.82 
     45   REAL(wp) :: devk12  = -29.48 
     46   REAL(wp) :: devk13  = -20.02 
     47   REAL(wp) :: devk14  = -18.03 
     48   REAL(wp) :: devk15  = -9.78 
     49   REAL(wp) :: devk16  = -48.76 
     50   REAL(wp) :: devk17  = -14.51 
     51   REAL(wp) :: devk18  = -23.12 
     52   REAL(wp) :: devk19  = -26.57 
     53   REAL(wp) :: devk110  = -29.48 
     54   ! 
     55   REAL(wp) :: devk20  = 0.1271 
     56   REAL(wp) :: devk21  = -0.0219 
     57   REAL(wp) :: devk22  = 0.1622 
     58   REAL(wp) :: devk23  = 0.1119 
     59   REAL(wp) :: devk24  = 0.0466 
     60   REAL(wp) :: devk25  = -0.0090 
     61   REAL(wp) :: devk26  = 0.5304 
     62   REAL(wp) :: devk27  = 0.1211 
     63   REAL(wp) :: devk28  = 0.1758 
     64   REAL(wp) :: devk29  = 0.2020 
     65   REAL(wp) :: devk210  = 0.1622 
     66   ! 
     67   REAL(wp) :: devk30  = 0. 
     68   REAL(wp) :: devk31  = 0. 
     69   REAL(wp) :: devk32  = 2.608E-3 
     70   REAL(wp) :: devk33  = -1.409e-3 
     71   REAL(wp) :: devk34  = 0.316e-3 
     72   REAL(wp) :: devk35  = -0.942e-3 
     73   REAL(wp) :: devk36  = 0. 
     74   REAL(wp) :: devk37  = -0.321e-3 
     75   REAL(wp) :: devk38  = -2.647e-3 
     76   REAL(wp) :: devk39  = -3.042e-3 
     77   REAL(wp) :: devk310  = -2.6080e-3 
     78   ! 
     79   REAL(wp) :: devk40  = -3.08E-3 
     80   REAL(wp) :: devk41  = 1.13E-3 
     81   REAL(wp) :: devk42  = -2.84E-3 
     82   REAL(wp) :: devk43  = -5.13E-3 
     83   REAL(wp) :: devk44  = -4.53e-3 
     84   REAL(wp) :: devk45  = -3.91e-3 
     85   REAL(wp) :: devk46  = -11.76e-3 
     86   REAL(wp) :: devk47  = -2.67e-3 
     87   REAL(wp) :: devk48  = -5.15e-3 
     88   REAL(wp) :: devk49  = -4.08e-3 
     89   REAL(wp) :: devk410  = -2.84e-3 
     90   ! 
     91   REAL(wp) :: devk50  = 0.0877E-3 
     92   REAL(wp) :: devk51  = -0.1475E-3 
     93   REAL(wp) :: devk52  = 0. 
     94   REAL(wp) :: devk53  = 0.0794E-3 
     95   REAL(wp) :: devk54  = 0.09e-3 
     96   REAL(wp) :: devk55  = 0.054e-3 
     97   REAL(wp) :: devk56  = 0.3692E-3 
     98   REAL(wp) :: devk57  = 0.0427e-3 
     99   REAL(wp) :: devk58  = 0.09e-3 
     100   REAL(wp) :: devk59  = 0.0714e-3 
     101   REAL(wp) :: devk510  = 0.0 
    164102 
    165103   !! $Id$ 
     
    179117      INTEGER, INTENT(in) :: kt                     ! time step 
    180118 
    181 #if ! defined key_sed_off 
    182119      INTEGER  :: ji, jj, ikt 
    183       REAL(wp) :: ztkel, ztc, ztc2, zpres, ztr  
    184       REAL(wp) :: zsal, zsal2, zsqrt, zsal15   
    185       REAL(wp) :: zis, zis2, zisqrt           
     120      REAL(wp) :: ztc, ztc2 
     121      REAL(wp) :: zsal, zsal15   
    186122      REAL(wp) :: zdens0, zaw, zbw, zcw     
    187       REAL(wp) :: zbuf1, zbuf2  
    188       REAL(wp) :: zcpexp, zcpexp2 
    189       REAL(wp) :: zck1p, zck2p, zck3p, zcksi    
    190       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   zchem_data 
    191  
    192 #endif 
     123      REAL(wp), DIMENSION(jpi,jpj,15) ::   zchem_data 
    193124      !!---------------------------------------------------------------------- 
    194125 
    195       IF( MOD( kt - 1, nfreq ) /= 0 ) RETURN 
    196  
    197       WRITE(numsed,*) ' Getting Chemical constants from tracer model at time kt = ', kt 
    198       WRITE(numsed,*) ' ' 
    199  
    200  
    201 #if defined key_sed_off 
    202       CALL sed_chem_off 
    203 #else 
     126 
     127      IF( ln_timing )  CALL timing_start('sed_chem') 
     128 
     129      IF (lwp) WRITE(numsed,*) ' Getting Chemical constants from tracer model at time kt = ', kt 
     130      IF (lwp) WRITE(numsed,*) ' ' 
     131 
    204132      ! reading variables 
    205       ALLOCATE( zchem_data(jpi,jpj,6) )   ;   zchem_data(:,:,:) = 0. 
    206  
    207       DO jj = 1,jpj 
    208          DO ji = 1, jpi 
    209             ikt = mbkt(ji,jj)  
    210             IF ( tmask(ji,jj,ikt) == 1 ) THEN 
    211                zchem_data(ji,jj,1) = ak13 (ji,jj,ikt) 
    212                zchem_data(ji,jj,2) = ak23 (ji,jj,ikt) 
    213                zchem_data(ji,jj,3) = akb3 (ji,jj,ikt) 
    214                zchem_data(ji,jj,4) = akw3 (ji,jj,ikt) 
    215                zchem_data(ji,jj,5) = aksp (ji,jj,ikt) 
    216                zchem_data(ji,jj,6) = borat(ji,jj,ikt) 
    217             ENDIF 
     133      zchem_data(:,:,:) = rtrn 
     134 
     135      IF (ln_sediment_offline) THEN 
     136         CALL sed_chem_cst 
     137      ELSE 
     138         DO jj = 1,jpj 
     139            DO ji = 1, jpi 
     140               ikt = mbkt(ji,jj)  
     141               IF ( tmask(ji,jj,ikt) == 1 ) THEN 
     142                  zchem_data(ji,jj,1) = ak13  (ji,jj,ikt) 
     143                  zchem_data(ji,jj,2) = ak23  (ji,jj,ikt) 
     144                  zchem_data(ji,jj,3) = akb3  (ji,jj,ikt) 
     145                  zchem_data(ji,jj,4) = akw3  (ji,jj,ikt) 
     146                  zchem_data(ji,jj,5) = aksp  (ji,jj,ikt) 
     147                  zchem_data(ji,jj,6) = borat (ji,jj,ikt) 
     148                  zchem_data(ji,jj,7) = ak1p3 (ji,jj,ikt) 
     149                  zchem_data(ji,jj,8) = ak2p3 (ji,jj,ikt) 
     150                  zchem_data(ji,jj,9) = ak3p3 (ji,jj,ikt) 
     151                  zchem_data(ji,jj,10)= aksi3 (ji,jj,ikt) 
     152                  zchem_data(ji,jj,11)= sio3eq(ji,jj,ikt) 
     153                  zchem_data(ji,jj,12)= aks3  (ji,jj,ikt) 
     154                  zchem_data(ji,jj,13)= akf3  (ji,jj,ikt) 
     155                  zchem_data(ji,jj,14)= sulfat(ji,jj,ikt) 
     156                  zchem_data(ji,jj,15)= fluorid(ji,jj,ikt) 
     157               ENDIF 
     158            ENDDO 
    218159         ENDDO 
    219       ENDDO 
    220  
    221       CALL pack_arr ( jpoce, ak1s  (1:jpoce), zchem_data(1:jpi,1:jpj,1), iarroce(1:jpoce) ) 
    222       CALL pack_arr ( jpoce, ak2s  (1:jpoce), zchem_data(1:jpi,1:jpj,2), iarroce(1:jpoce) ) 
    223       CALL pack_arr ( jpoce, akbs  (1:jpoce), zchem_data(1:jpi,1:jpj,3), iarroce(1:jpoce) ) 
    224       CALL pack_arr ( jpoce, akws  (1:jpoce), zchem_data(1:jpi,1:jpj,4), iarroce(1:jpoce) ) 
    225       CALL pack_arr ( jpoce, aksps (1:jpoce), zchem_data(1:jpi,1:jpj,5), iarroce(1:jpoce) ) 
    226       CALL pack_arr ( jpoce, borats(1:jpoce), zchem_data(1:jpi,1:jpj,6), iarroce(1:jpoce) ) 
    227  
    228       DEALLOCATE( zchem_data ) 
     160 
     161         CALL pack_arr ( jpoce, ak1s  (1:jpoce), zchem_data(1:jpi,1:jpj,1) , iarroce(1:jpoce) ) 
     162         CALL pack_arr ( jpoce, ak2s  (1:jpoce), zchem_data(1:jpi,1:jpj,2) , iarroce(1:jpoce) ) 
     163         CALL pack_arr ( jpoce, akbs  (1:jpoce), zchem_data(1:jpi,1:jpj,3) , iarroce(1:jpoce) ) 
     164         CALL pack_arr ( jpoce, akws  (1:jpoce), zchem_data(1:jpi,1:jpj,4) , iarroce(1:jpoce) ) 
     165         CALL pack_arr ( jpoce, aksps (1:jpoce), zchem_data(1:jpi,1:jpj,5) , iarroce(1:jpoce) ) 
     166         CALL pack_arr ( jpoce, borats(1:jpoce), zchem_data(1:jpi,1:jpj,6) , iarroce(1:jpoce) ) 
     167         CALL pack_arr ( jpoce, ak1ps (1:jpoce), zchem_data(1:jpi,1:jpj,7) , iarroce(1:jpoce) ) 
     168         CALL pack_arr ( jpoce, ak2ps (1:jpoce), zchem_data(1:jpi,1:jpj,8) , iarroce(1:jpoce) ) 
     169         CALL pack_arr ( jpoce, ak3ps (1:jpoce), zchem_data(1:jpi,1:jpj,9) , iarroce(1:jpoce) ) 
     170         CALL pack_arr ( jpoce, aksis (1:jpoce), zchem_data(1:jpi,1:jpj,10), iarroce(1:jpoce) ) 
     171         CALL pack_arr ( jpoce, sieqs (1:jpoce), zchem_data(1:jpi,1:jpj,11), iarroce(1:jpoce) ) 
     172         CALL pack_arr ( jpoce, aks3s (1:jpoce), zchem_data(1:jpi,1:jpj,12), iarroce(1:jpoce) ) 
     173         CALL pack_arr ( jpoce, akf3s (1:jpoce), zchem_data(1:jpi,1:jpj,13), iarroce(1:jpoce) ) 
     174         CALL pack_arr ( jpoce, sulfats(1:jpoce), zchem_data(1:jpi,1:jpj,14), iarroce(1:jpoce) ) 
     175         CALL pack_arr ( jpoce, fluorids(1:jpoce), zchem_data(1:jpi,1:jpj,15), iarroce(1:jpoce) ) 
     176      ENDIF 
    229177 
    230178      DO ji = 1, jpoce 
    231          ztkel   = temp(ji) + 273.16 
    232179         ztc     = temp(ji) 
    233180         ztc2    = ztc * ztc 
    234          zpres   = press(ji) 
    235181         ! zqtt    = ztkel * 0.01 
    236182         zsal    = salt(ji) 
    237          zsal2   = zsal * zsal  
    238          zsqrt   = SQRT( zsal ) 
    239          zsal15  = zsqrt * zsal 
    240          zlogt   = LOG( ztkel ) 
    241          ztr     = 1./ ztkel 
    242          ! zis=ionic strength (ORNL/CDIAC-74, DOE 94,Dickson and Goyet) 
    243          zis     = 19.924 * zsal / ( 1000. - 1.005 * zsal ) 
    244          zis2    = zis * zis 
    245          zisqrt  = SQRT( zis ) 
     183         zsal15  = SQRT( zsal ) * zsal 
    246184 
    247185         ! Density of Sea Water - F(temp,sal) [kg/m3] 
     
    256194         densSW(ji) = densSW(ji) * 1E-3   ! to get dens in [kg/l] 
    257195 
    258          ! FORMULA FOR CPEXP AFTER EDMOND AND GIESKES (1970)  
    259          ! (REFERENCE TO CULBERSON AND PYTKOQICZ (1968) AS MADE IN BROECKER ET AL. (1982)  
    260          ! IS INCORRECT; HERE RGAS IS TAKEN TENFOLD TO CORRECT FOR THE NOTATION OF pres  IN 
    261          ! DBAR INSTEAD OF BAR AND THE EXPRESSION FOR CPEXP IS MULTIPLIED BY LN(10.)  
    262          ! TO ALLOW USE OF EXP-FUNCTION WITH BASIS E IN THE FORMULA FOR AKSPP  
    263          ! (CF. EDMOND AND GIESKES (1970), P. 1285 AND P. 1286 (THE SMALL FORMULA ON P. 1286  
    264          ! IS RIGHT AND CONSISTENT WITH THE SIGN IN PARTIAL MOLAR VOLUME CHANGE AS SHOWN ON P. 1285) 
    265          !----------------------------------------------------------------------------------------- 
    266          zcpexp  = zpres / ( rgas*ztkel ) 
    267          zcpexp2 = zpres * zcpexp 
    268  
    269          ! For Phodphates (phosphoric acid) (DOE 1994) 
    270          !---------------------------------------------- 
    271          zck1p = cp10 + cp11*ztr + cp12*zlogt + ( cp13*ztr + cp14 ) * zsqrt & 
    272             &      + ( cp15*ztr + cp16 ) * zsal 
    273          zck2p = cp20 + cp21*ztr + cp22*zlogt + ( cp23*ztr + cp24 ) * zsqrt & 
    274             &      + ( cp25*ztr + cp26 ) * zsal 
    275          zck3p = cp30 + cp31*ztr + ( cp32*ztr + cp33 ) *  zsqrt & 
    276             &      + ( cp34*ztr + cp35 ) * zsal 
    277  
    278          ! For silicates (DOE 1994) change to mol/kg soln) (OCMIP) 
    279          !-------------------------------------------------------- 
    280          zcksi = cs10 + cs11*ztr + cs12*zlogt + ( cs13*ztr + cs14) * zisqrt & 
    281             &      + ( cs15*ztr + cs16 ) * zis & 
    282             &      + ( cs17*ztr + cs18 ) * zis2 & 
    283             &      + LOG( 1. + cs19*zsal ) + LOG( cs20 + cs21*zsal ) 
    284  
    285  
    286          !K1, K2 of carbonic acid, KB of boric acid, KW (H2O) 
    287          !--------------------------------------------------- 
    288          zak1p  = EXP ( zck1p  ) 
    289          zak2p  = EXP ( zck2p  ) 
    290          zak3p  = EXP ( zck3p  ) 
    291          zaksil = EXP ( zcksi  ) 
    292  
    293          zbuf1       = - ( devk1(3) + devk2(3)*ztc + devk3(3)*ztc2 ) 
    294          zbuf2       = 0.5 * ( devk4(3) + devk5(3)*ztc ) 
    295          aksis(ji)     = zaksil * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 ) 
    296  
    297          zbuf1       = - ( devk1(6) + devk2(6)*ztc + devk3(6)*ztc2 ) 
    298          zbuf2       = 0.5 * ( devk4(6) + devk5(6)*ztc ) 
    299          ak1ps(ji)   = zak1p * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 ) 
    300   
    301          zbuf1       = - ( devk1(7) + devk2(7)*ztc + devk3(7)*ztc2 ) 
    302          zbuf2       = 0.5 * ( devk4(7) + devk5(7)*ztc ) 
    303          ak2ps(ji)   = zak2p * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 ) 
    304  
    305          zbuf1       = - ( devk1(8) + devk2(8)*ztc + devk3(8)*ztc2 ) 
    306          zbuf2       = 0.5 * ( devk4(8) + devk5(8)*ztc ) 
    307          ak3ps(ji)   = zak3p * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 ) 
    308  
    309196         ak12s  (ji) = ak1s (ji) * ak2s (ji) 
    310197         ak12ps (ji) = ak1ps(ji) * ak2ps(ji) 
     
    313200         calcon2(ji) = 0.01028 * ( salt(ji) / 35. ) * densSW(ji) 
    314201      ENDDO 
    315  
    316202        
    317 #endif 
     203      IF( ln_timing )  CALL timing_stop('sed_chem') 
    318204 
    319205   END SUBROUTINE sed_chem 
    320206 
    321 #if defined key_sed_off 
    322  
    323    SUBROUTINE sed_chem_off 
    324       !!---------------------------------------------------------------------- 
    325       !!                   ***  ROUTINE sed_chem_off  *** 
    326       !!                     
    327       !! ** Purpose :   compute chemical constants 
     207   SUBROUTINE ahini_for_at_sed(p_hini) 
     208      !!--------------------------------------------------------------------- 
     209      !!                     ***  ROUTINE ahini_for_at  *** 
    328210      !! 
    329       !!   History : 
    330       !!        !  04-10  (N. Emprin, M. Gehlen )  Original code 
    331       !!        !  06-04  (C. Ethe)  Re-organization  
    332       !!----------------------------------------------------------------------   
    333       !! * Local declarations 
    334       INTEGER :: ji 
    335  
    336       REAL(wp) ::  ztkel, ztc, ztc2, zpres, ztr  
    337       REAL(wp) ::  zsal, zsal2, zsqrt, zsal15    
    338       REAL(wp) ::  zis, zis2, zisqrt             
    339       REAL(wp) ::  zdens0, zaw, zbw, zcw         
    340       REAL(wp) ::  zchl, zst, zft, zbuf1, zbuf2  
    341       REAL(wp) ::  zcpexp, zcpexp2               
    342       REAL(wp) ::  zckb, zck1, zck2, zckw        
    343       REAL(wp) ::  zck1p, zck2p, zck3p, zcksi    
    344       REAL(wp) ::  zak1, zak2, zakb, zakw               
    345       REAL(wp) ::  zaksp0, zksp, zks, zkf  
    346  
     211      !! Subroutine returns the root for the 2nd order approximation of the 
     212      !! DIC -- B_T -- A_CB equation for [H+] (reformulated as a cubic  
     213      !! polynomial) around the local minimum, if it exists. 
     214      !! Returns * 1E-03_wp if p_alkcb <= 0 
     215      !!         * 1E-10_wp if p_alkcb >= 2*p_dictot + p_bortot 
     216      !!         * 1E-07_wp if 0 < p_alkcb < 2*p_dictot + p_bortot 
     217      !!                    and the 2nd order approximation does not have  
     218      !!                    a solution 
     219      !!--------------------------------------------------------------------- 
     220      REAL(wp), DIMENSION(jpoce,jpksed), INTENT(OUT)  ::  p_hini 
     221      INTEGER  ::   ji, jk 
     222      REAL(wp)  ::  zca1, zba1 
     223      REAL(wp)  ::  zd, zsqrtd, zhmin 
     224      REAL(wp)  ::  za2, za1, za0 
     225      REAL(wp)  ::  p_dictot, p_bortot, p_alkcb 
     226 
     227      IF( ln_timing )  CALL timing_start('ahini_for_at_sed') 
     228      ! 
     229      DO jk = 1, jpksed 
     230         DO ji = 1, jpoce 
     231            p_alkcb  = pwcp(ji,jk,jwalk) / densSW(ji) 
     232            p_dictot = pwcp(ji,jk,jwdic) / densSW(ji)  
     233            p_bortot = borats(ji) / densSW(ji) 
     234            IF (p_alkcb <= 0.) THEN 
     235                p_hini(ji,jk) = 1.e-3 
     236            ELSEIF (p_alkcb >= (2.*p_dictot + p_bortot)) THEN 
     237                p_hini(ji,jk) = 1.e-10_wp 
     238            ELSE 
     239                zca1 = p_dictot/( p_alkcb + rtrn ) 
     240                zba1 = p_bortot/ (p_alkcb + rtrn ) 
     241           ! Coefficients of the cubic polynomial 
     242                za2 = aKbs(ji)*(1. - zba1) + ak1s(ji)*(1.-zca1) 
     243                za1 = ak1s(ji)*akbs(ji)*(1. - zba1 - zca1)    & 
     244                &     + ak1s(ji)*ak2s(ji)*(1. - (zca1+zca1)) 
     245                za0 = ak1s(ji)*ak2s(ji)*akbs(ji)*(1. - zba1 - (zca1+zca1)) 
     246                                        ! Taylor expansion around the minimum 
     247                zd = za2*za2 - 3.*za1   ! Discriminant of the quadratic equation 
     248                                        ! for the minimum close to the root 
     249 
     250                IF(zd > 0.) THEN        ! If the discriminant is positive 
     251                  zsqrtd = SQRT(zd) 
     252                  IF(za2 < 0) THEN 
     253                    zhmin = (-za2 + zsqrtd)/3. 
     254                  ELSE 
     255                    zhmin = -za1/(za2 + zsqrtd) 
     256                  ENDIF 
     257                  p_hini(ji,jk) = zhmin + SQRT(-(za0 + zhmin*(za1 + zhmin*(za2 + zhmin)))/zsqrtd) 
     258                ELSE 
     259                  p_hini(ji,jk) = 1.e-7 
     260                ENDIF 
     261             ! 
     262            ENDIF 
     263         END DO 
     264      END DO 
     265      ! 
     266      IF( ln_timing )  CALL timing_stop('ahini_for_at_sed') 
     267      ! 
     268   END SUBROUTINE ahini_for_at_sed 
     269 
     270   !=============================================================================== 
     271   SUBROUTINE anw_infsup_sed( p_alknw_inf, p_alknw_sup ) 
     272 
     273   ! Subroutine returns the lower and upper bounds of "non-water-selfionization" 
     274   ! contributions to total alkalinity (the infimum and the supremum), i.e 
     275   ! inf(TA - [OH-] + [H+]) and sup(TA - [OH-] + [H+]) 
     276 
     277   ! Argument variables 
     278   INTEGER :: jk 
     279   REAL(wp), DIMENSION(jpoce,jpksed), INTENT(OUT) :: p_alknw_inf 
     280   REAL(wp), DIMENSION(jpoce,jpksed), INTENT(OUT) :: p_alknw_sup 
     281 
     282   DO jk = 1, jpksed 
     283      p_alknw_inf(:,jk) =  -pwcp(:,jk,jwpo4) / densSW(:) 
     284      p_alknw_sup(:,jk) =   (2. * pwcp(:,jk,jwdic) + 2. * pwcp(:,jk,jwpo4) + pwcp(:,jk,jwsil)     & 
     285   &                        + borats(:) ) / densSW(:) 
     286   END DO 
     287 
     288   END SUBROUTINE anw_infsup_sed 
     289 
     290 
     291   SUBROUTINE solve_at_general_sed( p_hini, zhi ) 
     292 
     293   ! Universal pH solver that converges from any given initial value, 
     294   ! determines upper an lower bounds for the solution if required 
     295 
     296   ! Argument variables 
     297   !-------------------- 
     298   REAL(wp), DIMENSION(jpoce,jpksed), INTENT(IN)   :: p_hini 
     299   REAL(wp), DIMENSION(jpoce,jpksed), INTENT(OUT)  :: zhi 
     300 
     301   ! Local variables 
     302   !----------------- 
     303   INTEGER   ::  ji, jk, jn 
     304   REAL(wp)  ::  zh_ini, zh, zh_prev, zh_lnfactor 
     305   REAL(wp)  ::  zdelta, zh_delta 
     306   REAL(wp)  ::  zeqn, zdeqndh, zalka 
     307   REAL(wp)  ::  aphscale 
     308   REAL(wp)  ::  znumer_dic, zdnumer_dic, zdenom_dic, zalk_dic, zdalk_dic 
     309   REAL(wp)  ::  znumer_bor, zdnumer_bor, zdenom_bor, zalk_bor, zdalk_bor 
     310   REAL(wp)  ::  znumer_po4, zdnumer_po4, zdenom_po4, zalk_po4, zdalk_po4 
     311   REAL(wp)  ::  znumer_sil, zdnumer_sil, zdenom_sil, zalk_sil, zdalk_sil 
     312   REAL(wp)  ::  znumer_so4, zdnumer_so4, zdenom_so4, zalk_so4, zdalk_so4 
     313   REAL(wp)  ::  znumer_flu, zdnumer_flu, zdenom_flu, zalk_flu, zdalk_flu 
     314   REAL(wp)  ::  zalk_wat, zdalk_wat 
     315   REAL(wp)  ::  zfact, p_alktot, zdic, zbot, zpt, zst, zft, zsit 
     316   LOGICAL   ::  l_exitnow 
     317   REAL(wp), PARAMETER :: pz_exp_threshold = 1.0 
     318   REAL(wp), DIMENSION(jpoce,jpksed) :: zalknw_inf, zalknw_sup, rmask, zh_min, zh_max, zeqn_absmin 
     319 
     320   IF( ln_timing )  CALL timing_start('solve_at_general_sed') 
     321      !  Allocate temporary workspace 
     322   CALL anw_infsup_sed( zalknw_inf, zalknw_sup ) 
     323 
     324   rmask(:,:) = 1.0 
     325   zhi(:,:)   = 0. 
     326 
     327   ! TOTAL H+ scale: conversion factor for Htot = aphscale * Hfree 
     328   DO jk = 1, jpksed 
     329      DO ji = 1, jpoce 
     330         IF (rmask(ji,jk) == 1.) THEN 
     331            p_alktot = pwcp(ji,jk,jwalk) / densSW(ji) 
     332            aphscale = 1. + sulfats(ji)/aks3s(ji) 
     333            zh_ini = p_hini(ji,jk) 
     334 
     335            zdelta = (p_alktot-zalknw_inf(ji,jk))**2 + 4.*akws(ji) / aphscale 
     336 
     337            IF(p_alktot >= zalknw_inf(ji,jk)) THEN 
     338               zh_min(ji,jk) = 2.*akws(ji) /( p_alktot-zalknw_inf(ji,jk) + SQRT(zdelta) ) 
     339            ELSE 
     340               zh_min(ji,jk) = aphscale * (-(p_alktot-zalknw_inf(ji,jk)) + SQRT(zdelta) ) / 2. 
     341            ENDIF 
     342 
     343            zdelta = (p_alktot-zalknw_sup(ji,jk))**2 + 4.*akws(ji) / aphscale 
     344 
     345            IF(p_alktot <= zalknw_sup(ji,jk)) THEN 
     346               zh_max(ji,jk) = aphscale * (-(p_alktot-zalknw_sup(ji,jk)) + SQRT(zdelta) ) / 2. 
     347            ELSE 
     348               zh_max(ji,jk) = 2.*akws(ji) /( p_alktot-zalknw_sup(ji,jk) + SQRT(zdelta) ) 
     349            ENDIF 
     350 
     351            zhi(ji,jk) = MAX(MIN(zh_max(ji,jk), zh_ini), zh_min(ji,jk)) 
     352         ENDIF 
     353      END DO 
     354   END DO 
     355 
     356   zeqn_absmin(:,:) = HUGE(1._wp) 
     357 
     358   DO jn = 1, jp_maxniter_atgen 
     359   DO jk = 1, jpksed 
     360      DO ji = 1, jpoce 
     361         IF (rmask(ji,jk) == 1.) THEN 
     362 
     363            p_alktot = pwcp(ji,jk,jwalk) / densSW(ji) 
     364            zdic  = pwcp(ji,jk,jwdic) / densSW(ji) 
     365            zbot  = borats(ji) / densSW(ji) 
     366            zpt =  pwcp(ji,jk,jwpo4) / densSW(ji) 
     367            zsit = pwcp(ji,jk,jwsil) / densSW(ji) 
     368            zst = sulfats(ji) 
     369            zft = fluorids(ji) 
     370            aphscale = 1. + sulfats(ji)/aks3s(ji) 
     371            zh = zhi(ji,jk) 
     372            zh_prev = zh 
     373 
     374            ! H2CO3 - HCO3 - CO3 : n=2, m=0 
     375            znumer_dic = 2.*ak1s(ji)*ak2s(ji) + zh*ak1s(ji) 
     376            zdenom_dic = ak1s(ji)*ak2s(ji) + zh*(ak1s(ji) + zh) 
     377            zalk_dic   = zdic * (znumer_dic/zdenom_dic) 
     378            zdnumer_dic = ak1s(ji)*ak1s(ji)*ak2s(ji) + zh     & 
     379                          *(4.*ak1s(ji)*ak2s(ji) + zh*ak1s(ji)) 
     380            zdalk_dic   = -zdic*(zdnumer_dic/zdenom_dic**2) 
     381 
     382 
     383            ! B(OH)3 - B(OH)4 : n=1, m=0 
     384            znumer_bor = akbs(ji) 
     385            zdenom_bor = akbs(ji) + zh 
     386            zalk_bor   = zbot * (znumer_bor/zdenom_bor) 
     387            zdnumer_bor = akbs(ji) 
     388            zdalk_bor   = -zbot*(zdnumer_bor/zdenom_bor**2) 
     389 
     390 
     391            ! H3PO4 - H2PO4 - HPO4 - PO4 : n=3, m=1 
     392            znumer_po4 = 3.*ak1ps(ji)*ak2ps(ji)*ak3ps(ji)  & 
     393            &            + zh*(2.*ak1ps(ji)*ak2ps(ji) + zh* ak1ps(ji)) 
     394            zdenom_po4 = ak1ps(ji)*ak2ps(ji)*ak3ps(ji)     & 
     395            &            + zh*( ak1ps(ji)*ak2ps(ji) + zh*(ak1ps(ji) + zh)) 
     396            zalk_po4   = zpt * (znumer_po4/zdenom_po4 - 1.) ! Zero level of H3PO4 = 1 
     397            zdnumer_po4 = ak1ps(ji)*ak2ps(ji)*ak1ps(ji)*ak2ps(ji)*ak3ps(ji)  & 
     398            &             + zh*(4.*ak1ps(ji)*ak1ps(ji)*ak2ps(ji)*ak3ps(ji)         & 
     399            &             + zh*(9.*ak1ps(ji)*ak2ps(ji)*ak3ps(ji)                         & 
     400            &             + ak1ps(ji)*ak1ps(ji)*ak2ps(ji)                                & 
     401            &             + zh*(4.*ak1ps(ji)*ak2ps(ji) + zh * ak1ps(ji) ) ) ) 
     402            zdalk_po4   = -zpt * (zdnumer_po4/zdenom_po4**2) 
     403 
     404            ! H4SiO4 - H3SiO4 : n=1, m=0 
     405            znumer_sil = aksis(ji) 
     406            zdenom_sil = aksis(ji) + zh 
     407            zalk_sil   = zsit * (znumer_sil/zdenom_sil) 
     408            zdnumer_sil = aksis(ji) 
     409            zdalk_sil   = -zsit * (zdnumer_sil/zdenom_sil**2) 
     410 
     411            ! HSO4 - SO4 : n=1, m=1 
     412            aphscale = 1.0 + zst/aks3s(ji) 
     413            znumer_so4 = aks3s(ji) * aphscale 
     414            zdenom_so4 = aks3s(ji) * aphscale + zh 
     415            zalk_so4   = zst * (znumer_so4/zdenom_so4 - 1.) 
     416            zdnumer_so4 = aks3s(ji) * aphscale 
     417            zdalk_so4   = -zst * (zdnumer_so4/zdenom_so4**2) 
     418 
     419            ! HF - F : n=1, m=1 
     420            znumer_flu =  akf3s(ji) 
     421            zdenom_flu =  akf3s(ji) + zh 
     422            zalk_flu   =  zft * (znumer_flu/zdenom_flu - 1.) 
     423            zdnumer_flu = akf3s(ji) 
     424            zdalk_flu   = -zft * (zdnumer_flu/zdenom_flu**2) 
     425 
     426            ! H2O - OH 
     427            zalk_wat   = akws(ji)/zh - zh/aphscale 
     428            zdalk_wat  = -akws(ji)/zh**2 - 1./aphscale 
     429 
     430            ! CALCULATE [ALK]([CO3--], [HCO3-]) 
     431            zeqn = zalk_dic + zalk_bor + zalk_po4 + zalk_sil   & 
     432            &      + zalk_so4 + zalk_flu                       & 
     433            &      + zalk_wat - p_alktot 
     434 
     435            zalka = p_alktot - (zalk_bor + zalk_po4 + zalk_sil   & 
     436            &       + zalk_so4 + zalk_flu + zalk_wat) 
     437 
     438            zdeqndh = zdalk_dic + zdalk_bor + zdalk_po4 + zdalk_sil & 
     439            &         + zdalk_so4 + zdalk_flu + zdalk_wat 
     440 
     441            ! Adapt bracketing interval 
     442            IF(zeqn > 0._wp) THEN 
     443               zh_min(ji,jk) = zh_prev 
     444            ELSEIF(zeqn < 0._wp) THEN 
     445               zh_max(ji,jk) = zh_prev 
     446            ENDIF 
     447 
     448            IF(ABS(zeqn) >= 0.5_wp*zeqn_absmin(ji,jk)) THEN 
     449            ! if the function evaluation at the current point is 
     450            ! not decreasing faster than with a bisection step (at least linearly) 
     451            ! in absolute value take one bisection step on [ph_min, ph_max] 
     452            ! ph_new = (ph_min + ph_max)/2d0 
     453            ! 
     454            ! In terms of [H]_new: 
     455            ! [H]_new = 10**(-ph_new) 
     456            !         = 10**(-(ph_min + ph_max)/2d0) 
     457            !         = SQRT(10**(-(ph_min + phmax))) 
     458            !         = SQRT(zh_max * zh_min) 
     459               zh = SQRT(zh_max(ji,jk) * zh_min(ji,jk)) 
     460               zh_lnfactor = (zh - zh_prev)/zh_prev ! Required to test convergence below 
     461            ELSE 
     462            ! dzeqn/dpH = dzeqn/d[H] * d[H]/dpH 
     463            !           = -zdeqndh * LOG(10) * [H] 
     464            ! \Delta pH = -zeqn/(zdeqndh*d[H]/dpH) = zeqn/(zdeqndh*[H]*LOG(10)) 
     465            ! 
     466            ! pH_new = pH_old + \deltapH 
     467            ! 
     468            ! [H]_new = 10**(-pH_new) 
     469            !         = 10**(-pH_old - \Delta pH) 
     470            !         = [H]_old * 10**(-zeqn/(zdeqndh*[H]_old*LOG(10))) 
     471            !         = [H]_old * EXP(-LOG(10)*zeqn/(zdeqndh*[H]_old*LOG(10))) 
     472            !         = [H]_old * EXP(-zeqn/(zdeqndh*[H]_old)) 
     473 
     474               zh_lnfactor = -zeqn/(zdeqndh*zh_prev) 
     475 
     476               IF(ABS(zh_lnfactor) > pz_exp_threshold) THEN 
     477                  zh          = zh_prev*EXP(zh_lnfactor) 
     478               ELSE 
     479                  zh_delta    = zh_lnfactor*zh_prev 
     480                  zh          = zh_prev + zh_delta 
     481               ENDIF 
     482 
     483               IF( zh < zh_min(ji,jk) ) THEN 
     484               ! if [H]_new < [H]_min 
     485               ! i.e., if ph_new > ph_max then 
     486               ! take one bisection step on [ph_prev, ph_max] 
     487               ! ph_new = (ph_prev + ph_max)/2d0 
     488               ! In terms of [H]_new: 
     489               ! [H]_new = 10**(-ph_new) 
     490               !         = 10**(-(ph_prev + ph_max)/2d0) 
     491               !         = SQRT(10**(-(ph_prev + phmax))) 
     492               !         = SQRT([H]_old*10**(-ph_max)) 
     493               !         = SQRT([H]_old * zh_min) 
     494                  zh                = SQRT(zh_prev * zh_min(ji,jk)) 
     495                  zh_lnfactor       = (zh - zh_prev)/zh_prev ! Required to test convergence below 
     496               ENDIF 
     497 
     498               IF( zh > zh_max(ji,jk) ) THEN 
     499               ! if [H]_new > [H]_max 
     500               ! i.e., if ph_new < ph_min, then 
     501               ! take one bisection step on [ph_min, ph_prev] 
     502               ! ph_new = (ph_prev + ph_min)/2d0 
     503               ! In terms of [H]_new: 
     504               ! [H]_new = 10**(-ph_new) 
     505               !         = 10**(-(ph_prev + ph_min)/2d0) 
     506               !         = SQRT(10**(-(ph_prev + ph_min))) 
     507               !         = SQRT([H]_old*10**(-ph_min)) 
     508               !         = SQRT([H]_old * zhmax) 
     509                  zh                = SQRT(zh_prev * zh_max(ji,jk)) 
     510                  zh_lnfactor       = (zh - zh_prev)/zh_prev ! Required to test convergence below 
     511               ENDIF 
     512            ENDIF 
     513 
     514            zeqn_absmin(ji,jk) = MIN( ABS(zeqn), zeqn_absmin(ji,jk)) 
     515 
     516            ! Stop iterations once |\delta{[H]}/[H]| < rdel 
     517            ! <=> |(zh - zh_prev)/zh_prev| = |EXP(-zeqn/(zdeqndh*zh_prev)) -1| < rdel 
     518            ! |EXP(-zeqn/(zdeqndh*zh_prev)) -1| ~ |zeqn/(zdeqndh*zh_prev)| 
     519            ! Alternatively: 
     520            ! |\Delta pH| = |zeqn/(zdeqndh*zh_prev*LOG(10))| 
     521            !             ~ 1/LOG(10) * |\Delta [H]|/[H] 
     522            !             < 1/LOG(10) * rdel 
     523 
     524            ! Hence |zeqn/(zdeqndh*zh)| < rdel 
     525 
     526            ! rdel <-- pp_rdel_ah_target 
     527            l_exitnow = (ABS(zh_lnfactor) < pp_rdel_ah_target) 
     528 
     529            IF(l_exitnow) THEN 
     530               rmask(ji,jk) = 0. 
     531            ENDIF 
     532 
     533            zhi(ji,jk) =  zh 
     534 
     535            IF(jn >= jp_maxniter_atgen) THEN 
     536               zhi(ji,jk) = -1._wp 
     537            ENDIF 
     538 
     539         ENDIF 
     540      END DO 
     541   END DO 
     542   END DO 
     543   ! 
     544   IF( ln_timing )  CALL timing_stop('solve_at_general_sed') 
     545 
     546   END SUBROUTINE solve_at_general_sed 
     547 
     548   SUBROUTINE sed_chem_cst 
     549      !!--------------------------------------------------------------------- 
     550      !!                     ***  ROUTINE sed_chem_cst  *** 
     551      !! 
     552      !! ** Purpose :   Sea water chemistry computed following MOCSY protocol 
     553      !!                Computation is done at the bottom of the ocean only 
     554      !! 
     555      !! ** Method  : - ... 
     556      !!--------------------------------------------------------------------- 
     557      INTEGER  ::   ji 
     558      REAL(wp), DIMENSION(jpoce) :: saltprac, temps 
     559      REAL(wp) ::   ztkel, ztkel1, zt , zsal  , zsal2 , zbuf1 , zbuf2 
     560      REAL(wp) ::   ztgg , ztgg2, ztgg3 , ztgg4 , ztgg5 
     561      REAL(wp) ::   zpres, ztc  , zcl   , zcpexp, zoxy  , zcpexp2 
     562      REAL(wp) ::   zsqrt, ztr  , zlogt , zcek1, zc1, zplat 
     563      REAL(wp) ::   zis  , zis2 , zsal15, zisqrt, za1, za2 
     564      REAL(wp) ::   zckb , zck1 , zck2  , zckw  , zak1 , zak2  , zakb , zaksp0, zakw 
     565      REAL(wp) ::   zck1p, zck2p, zck3p, zcksi, zak1p, zak2p, zak3p, zaksi 
     566      REAL(wp) ::   zst  , zft  , zcks  , zckf  , zaksp1 
     567      REAL(wp) ::   total2free, free2SWS, total2SWS, SWS2total 
     568      !!--------------------------------------------------------------------- 
     569      ! 
     570      IF( ln_timing )   CALL timing_start('sed_chem_cst') 
     571      ! 
     572      ! Computation of chemical constants require practical salinity 
     573      ! Thus, when TEOS08 is used, absolute salinity is converted to 
     574      ! practical salinity 
     575      ! ------------------------------------------------------------- 
     576      IF (neos == -1) THEN 
     577         saltprac(:) = salt(:) * 35.0 / 35.16504 
     578      ELSE 
     579         saltprac(:) = temp(:) 
     580      ENDIF 
     581 
     582      ! 
     583      ! Computations of chemical constants require in situ temperature 
     584      ! Here a quite simple formulation is used to convert 
     585      ! potential temperature to in situ temperature. The errors is less than 
     586      ! 0.04°C relative to an exact computation 
     587      ! --------------------------------------------------------------------- 
     588         DO ji = 1, jpoce 
     589            zpres = zkbot(ji) / 1000. 
     590            za1 = 0.04 * ( 1.0 + 0.185 * temp(ji) + 0.035 * (saltprac(ji) - 35.0) ) 
     591            za2 = 0.0075 * ( 1.0 - temp(ji) / 30.0 ) 
     592            temps(ji) = temp(ji) - za1 * zpres + za2 * zpres**2 
     593         END DO 
    347594 
    348595      ! CHEMICAL CONSTANTS - DEEP OCEAN 
    349       !------------------------------------- 
    350       ! [chem constants]=mol/kg solution (or (mol/kg sol)2 for akws and aksp) 
    351  
     596      ! ------------------------------- 
    352597      DO ji = 1, jpoce 
    353          ztkel   = temp(ji) + 273.16 
    354          ztc     = temp(ji) 
    355          ztc2    = ztc * ztc 
    356          zpres   = press(ji) 
    357          ! zqtt    = ztkel * 0.01 
    358          zsal    = salt(ji) 
    359          zsal2   = zsal * zsal  
    360          zsqrt   = SQRT( zsal ) 
     598         ! SET PRESSION ACCORDING TO SAUNDER (1980) 
     599         zc1 = 5.92E-3  
     600         zpres = ((1-zc1)-SQRT(((1-zc1)**2)-(8.84E-6*zkbot(ji)))) / 4.42E-6 
     601         zpres = zpres / 10.0 
     602 
     603         ! SET ABSOLUTE TEMPERATURE 
     604         ztkel   = temps(ji) + 273.15 
     605         zsal    = saltprac(ji) 
     606         zsqrt  = SQRT( zsal ) 
    361607         zsal15  = zsqrt * zsal 
    362          zlogt   = LOG( ztkel ) 
    363          ztr     = 1./ ztkel 
    364          ! zis=ionic strength (ORNL/CDIAC-74, DOE 94,Dickson and Goyet) 
    365          zis     = 19.924 * zsal / ( 1000. - 1.005 * zsal ) 
    366          zis2    = zis * zis 
    367          zisqrt  = SQRT( zis ) 
    368  
    369  
    370          ! Density of Sea Water - F(temp,sal) [kg/m3] 
    371          zdens0 =  Ddsw(1) + Ddsw(2) * ztc + Ddsw(3) * ztc2 & 
    372                   + Ddsw(4) * ztc * ztc2 + Ddsw(5) * ztc2 * ztc2 & 
    373                   + Ddsw(6) * ztc * ztc2 * ztc2 
    374          zaw =  Adsw(1) + Adsw(2) * ztc + Adsw(3)* ztc2 + Adsw(4) * ztc * ztc2 & 
    375               + Adsw(5) * ztc2 * ztc2 
    376          zbw =  Bdsw(1) + Bdsw(2) * ztc + Bdsw(3) * ztc2 
    377          zcw =  Cdsw 
    378          densSW(ji) = zdens0 + zaw * zsal + zbw * zsal15 + zcw * zsal * zsal 
    379          densSW(ji) = densSW(ji) * 1E-3   ! to get dens in [kg/l] 
    380  
    381  
    382          ! FORMULA FOR CPEXP AFTER EDMOND AND GIESKES (1970)  
    383          ! (REFERENCE TO CULBERSON AND PYTKOQICZ (1968) AS MADE IN BROECKER ET AL. (1982)  
    384          ! IS INCORRECT; HERE RGAS IS TAKEN TENFOLD TO CORRECT FOR THE NOTATION OF pres  IN 
    385          ! DBAR INSTEAD OF BAR AND THE EXPRESSION FOR CPEXP IS MULTIPLIED BY LN(10.)  
    386          ! TO ALLOW USE OF EXP-FUNCTION WITH BASIS E IN THE FORMULA FOR AKSPP  
    387          ! (CF. EDMOND AND GIESKES (1970), P. 1285 AND P. 1286 (THE SMALL FORMULA ON P. 1286  
    388          ! IS RIGHT AND CONSISTENT WITH THE SIGN IN PARTIAL MOLAR VOLUME CHANGE AS SHOWN ON P. 1285) 
    389          !----------------------------------------------------------------------------------------- 
    390          zcpexp  = zpres / ( rgas*ztkel ) 
     608         zlogt  = LOG( ztkel ) 
     609         ztr    = 1. / ztkel 
     610         zis    = 19.924 * zsal / ( 1000.- 1.005 * zsal ) 
     611         zis2   = zis * zis 
     612         zisqrt = SQRT( zis ) 
     613         ztc    = temps(ji) 
     614 
     615         ! CHLORINITY (WOOSTER ET AL., 1969) 
     616         zcl     = zsal / 1.80655 
     617 
     618         ! TOTAL SULFATE CONCENTR. [MOLES/kg soln] 
     619         zst     = 0.14 * zcl /96.062 
     620 
     621         ! TOTAL FLUORIDE CONCENTR. [MOLES/kg soln] 
     622         zft     = 0.000067 * zcl /18.9984 
     623 
     624         ! DISSOCIATION CONSTANT FOR SULFATES on free H scale (Dickson 1990) 
     625         zcks    = EXP(-4276.1 * ztr + 141.328 - 23.093 * zlogt         & 
     626         &         + (-13856. * ztr + 324.57 - 47.986 * zlogt) * zisqrt & 
     627         &         + (35474. * ztr - 771.54 + 114.723 * zlogt) * zis    & 
     628         &         - 2698. * ztr * zis**1.5 + 1776.* ztr * zis2         & 
     629         &         + LOG(1.0 - 0.001005 * zsal)) 
     630 
     631         ! DISSOCIATION CONSTANT FOR FLUORIDES on free H scale (Dickson and Riley 79) 
     632         zckf    = EXP( 1590.2*ztr - 12.641 + 1.525*zisqrt   & 
     633         &         + LOG(1.0d0 - 0.001005d0*zsal)            & 
     634         &         + LOG(1.0d0 + zst/zcks)) 
     635 
     636         ! DISSOCIATION CONSTANT FOR CARBONATE AND BORATE 
     637         zckb=  (-8966.90 - 2890.53*zsqrt - 77.942*zsal        & 
     638         &      + 1.728*zsal15 - 0.0996*zsal*zsal)*ztr         & 
     639         &      + (148.0248 + 137.1942*zsqrt + 1.62142*zsal)   & 
     640         &      + (-24.4344 - 25.085*zsqrt - 0.2474*zsal)      & 
     641         &      * zlogt + 0.053105*zsqrt*ztkel 
     642 
     643         ! DISSOCIATION COEFFICIENT FOR CARBONATE ACCORDING TO 
     644         ! MEHRBACH (1973) REFIT BY MILLERO (1995), seawater scale 
     645         zck1    = -1.0*(3633.86*ztr - 61.2172 + 9.6777*zlogt  & 
     646                   - 0.011555*zsal + 0.0001152*zsal*zsal) 
     647         zck2    = -1.0*(471.78*ztr + 25.9290 - 3.16967*zlogt      & 
     648                   - 0.01781*zsal + 0.0001122*zsal*zsal) 
     649 
     650         ! PKW (H2O) (MILLERO, 1995) from composite data 
     651         zckw    = -13847.26 * ztr + 148.9652 - 23.6521 * zlogt + ( 118.67 * ztr    & 
     652                   - 5.977 + 1.0495 * zlogt ) * zsqrt - 0.01615 * zsal 
     653 
     654         ! CONSTANTS FOR PHOSPHATE (MILLERO, 1995) 
     655         zck1p    = -4576.752*ztr + 115.540 - 18.453*zlogt   & 
     656         &          + (-106.736*ztr + 0.69171) * zsqrt       & 
     657         &          + (-0.65643*ztr - 0.01844) * zsal 
     658 
     659         zck2p    = -8814.715*ztr + 172.1033 - 27.927*zlogt  & 
     660         &          + (-160.340*ztr + 1.3566)*zsqrt          & 
     661         &          + (0.37335*ztr - 0.05778)*zsal 
     662 
     663         zck3p    = -3070.75*ztr - 18.126                    & 
     664         &          + (17.27039*ztr + 2.81197) * zsqrt       & 
     665         &          + (-44.99486*ztr - 0.09984) * zsal 
     666 
     667         ! CONSTANT FOR SILICATE, MILLERO (1995) 
     668         zcksi    = -8904.2*ztr  + 117.400 - 19.334*zlogt   & 
     669         &          + (-458.79*ztr + 3.5913) * zisqrt       & 
     670         &          + (188.74*ztr - 1.5998) * zis           & 
     671         &          + (-12.1652*ztr + 0.07871) * zis2       & 
     672         &          + LOG(1.0 - 0.001005*zsal) 
     673 
     674         ! APPARENT SOLUBILITY PRODUCT K'SP OF CALCITE IN SEAWATER 
     675         !       (S=27-43, T=2-25 DEG C) at pres =0 (atmos. pressure) (MUCCI 1983) 
     676         zaksp0  = -171.9065 -0.077993*ztkel + 2839.319*ztr + 71.595*LOG10( ztkel )   & 
     677         &         + (-0.77712 + 0.00284263*ztkel + 178.34*ztr) * zsqrt  & 
     678         &         - 0.07711*zsal + 0.0041249*zsal15 
     679 
     680         ! K1, K2 OF CARBONIC ACID, KB OF BORIC ACID, KW (H2O) (LIT.?) 
     681         zak1    = 10**(zck1) * total2SWS 
     682         zak2    = 10**(zck2) * total2SWS 
     683         zakb    = EXP( zckb ) * total2SWS 
     684         zakw    = EXP( zckw ) 
     685         zaksp1  = 10**(zaksp0) 
     686         zak1p   = exp( zck1p ) 
     687         zak2p   = exp( zck2p ) 
     688         zak3p   = exp( zck3p ) 
     689         zaksi   = exp( zcksi ) 
     690         zckf    = zckf * total2SWS 
     691 
     692         ! FORMULA FOR CPEXP AFTER EDMOND & GIESKES (1970) 
     693         !        (REFERENCE TO CULBERSON & PYTKOQICZ (1968) AS MADE 
     694         !        IN BROECKER ET AL. (1982) IS INCORRECT; HERE RGAS IS 
     695         !        TAKEN TENFOLD TO CORRECT FOR THE NOTATION OF pres  IN 
     696         !        DBAR INSTEAD OF BAR AND THE EXPRESSION FOR CPEXP IS 
     697         !        MULTIPLIED BY LN(10.) TO ALLOW USE OF EXP-FUNCTION 
     698         !        WITH BASIS E IN THE FORMULA FOR AKSPP (CF. EDMOND 
     699         !        & GIESKES (1970), P. 1285-1286 (THE SMALL 
     700         !        FORMULA ON P. 1286 IS RIGHT AND CONSISTENT WITH THE 
     701         !        SIGN IN PARTIAL MOLAR VOLUME CHANGE AS SHOWN ON P. 1285)) 
     702         zcpexp  = zpres / (rgas*ztkel) 
    391703         zcpexp2 = zpres * zcpexp 
    392704 
    393  
    394          ! chlorinity (WOOSTER ET AL., 1969) 
    395          !--------------------------------------- 
    396          zchl = zsal * salchl 
    397  
    398          ! total sulfate concentration [mol/kg soln] 
    399          ! -------------------------------------- 
    400          zst = st1 * zchl * st2 
    401  
    402          ! total fluoride concentration [mol/kg soln] 
    403          ! -------------------------------------- 
    404          zft = ft1 * zchl * ft2 
    405  
    406          ! dissociation constant for carbonate (Mehrback 74 - Dickson & Millero 87) 
    407          !--------------------------------------------------------------------------- 
    408          zck1 = c10*ztr - c11 + c12*zlogt - c13*zsal + c14*zsal2 
    409          zck2 = c20*ztr + c21 - c22*zlogt - c23*zsal + c24*zsal2 
    410  
    411          ! dissociation constant for sulfates (Dickson 1990) 
    412          !-------------------------------------------------- 
    413          zks = EXP(  ks0 + ks1*ztr + ks2*zlogt & 
    414             &    + ( ks3*ztr + ks4 + ks5*zlogt ) * zisqrt & 
    415             &    + ( ks6*ztr + ks7 + ks8*zlogt ) * zis    & 
    416             &    +   ks9*ztr*zis*zisqrt + ks10*ztr*zis2   & 
    417             &    +   LOG( ks11 + ks12*zsal ) ) 
    418  
    419          ! dissociation constant for fluorides (Dickson and Riley 79) 
    420          !-------------------------------------------------- 
    421          zkf = EXP( kf0 + kf1*ztr + kf2*zisqrt + LOG( kf3 + kf4*zsal ) ) 
    422  
    423          ! dissociation constant for borates (Doe 94) 
    424          !-------------------------------------------------- 
    425          zckb = (  cb0 + cb1*zsqrt + cb2*zsal + cb3*zsal15 + cb4*zsal2) * ztr & 
    426             &  + ( cb5 + cb6*zsqrt + cb7*zsal) & 
    427             &  + ( cb8 + cb9*zsqrt + cb10*zsal) * zlogt & 
    428             &  +   cb11*zsqrt*ztkel + LOG( ( 1. + zst/zks + zft/zkf ) / ( 1. + zst/zks ) )  
    429  
    430          ! PKW (H2O) (DICKSON AND RILEY, 1979) 
    431          !-------------------------------------- 
    432          zckw =   cw0*ztr + cw1 + cw2*zlogt & 
    433             & +( cw3*ztr + cw4 + cw5*zlogt )* zsqrt + cw6*zsal 
    434           
    435          ! For Phodphates (phosphoric acid) (DOE 1994) 
    436          !---------------------------------------------- 
    437          zck1p = cp10 + cp11*ztr + cp12*zlogt + ( cp13*ztr + cp14 ) * zsqrt & 
    438             &      + ( cp15*ztr + cp16 ) * zsal 
    439          zck2p = cp20 + cp21*ztr + cp22*zlogt + ( cp23*ztr + cp24 ) * zsqrt & 
    440             &      + ( cp25*ztr + cp26 ) * zsal 
    441          zck3p = cp30 + cp31*ztr + ( cp32*ztr + cp33 ) *  zsqrt & 
    442             &      + ( cp34*ztr + cp35 ) * zsal 
    443  
    444          ! For silicates (DOE 1994) change to mol/kg soln) (OCMIP) 
    445          !-------------------------------------------------------- 
    446          zcksi = cs10 + cs11*ztr + cs12*zlogt + ( cs13*ztr + cs14) * zisqrt & 
    447             &      + ( cs15*ztr + cs16 ) * zis & 
    448             &      + ( cs17*ztr + cs18 ) * zis2 & 
    449             &      + LOG( 1. + cs19*zsal ) + LOG( cs20 + cs21*zsal ) 
    450  
    451          ! apparent solublity product K'SP of calcite in seawater 
    452          ! (S=27-43, T=2-25 DEG C) AT pres =0 (INGLE, 1975, EQ. 6) 
    453          ! prob: olivier a log = ln et C. Heize a LOG10(sal) 
    454          ! aksp0 = 1.E-7*(akcc1+akcc2*sal**(1./3.)+akcc3*log(sal)+akcc4*tkel*tkel) 
    455          ! aksp0 = 1.E-7*(akcc1+akcc2*sal**(1./3.)+akcc3*log10(sal)+akcc4*tkel*tkel) 
    456          !-------------------------------------------------------------------- 
    457          zaksp0 = akcc1 + akcc2*ztkel + akcc3*ztr + akcc4 * LOG10(ztkel) & 
    458             &  + ( akcc5 + akcc6*ztkel+ akcc7*ztr ) * zsqrt & 
    459             &  +  akcc8*zsal + akcc9*zsal15 
    460  
    461          !K1, K2 of carbonic acid, KB of boric acid, KW (H2O) 
    462          !--------------------------------------------------- 
    463          zak1   = 10**( -zck1  ) 
    464          zak2   = 10**( -zck2  ) 
    465          zakb   = EXP ( zckb   )  
    466          zakw   = EXP ( zckw   ) 
    467          zksp   = 10**( zaksp0 ) 
    468  
    469  
    470  
    471          ! KB of boric acid, K1,K2 of carbonic acid pressure correction  
    472          ! after Culberson and  AND Pytkowicz (1968) (CF. BROECKER ET AL., 1982) Millero 95 
    473          !-------------------------------------------------------------------------------- 
    474          zbuf1       = - ( devk1(1) + devk2(1)*ztc + devk3(1)*ztc2 ) 
    475          zbuf2       = 0.5 * ( devk4(1) + devk5(1)*ztc ) 
    476          ak1s(ji)    = zak1 * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 ) 
    477  
    478          zbuf1       = -( devk1(2) + devk2(2)*ztc + devk3(2)*ztc2 ) 
    479          zbuf2       = 0.5 * ( devk4(2) + devk5(2)*ztc ) 
    480          ak2s(ji)    = zak2 * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 ) 
    481  
    482          zbuf1       = - ( devk1(3) + devk2(3)*ztc + devk3(3)*ztc2 ) 
    483          zbuf2       = 0.5 * ( devk4(3) + devk5(3) * ztc ) 
    484          akbs(ji)    = zakb * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 ) 
    485  
    486          zbuf1       = - ( devk1(4) + devk2(4)*ztc + devk3(4)*ztc2 ) 
    487          zbuf2       = 0.5 * ( devk4(4) + devk5(4)*ztc ) 
    488          akws(ji)    = zakw * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 ) 
    489  
    490  
    491          ! APPARENT SOLUBILITY PRODUCT K''SP OF CALCITE (OR ARAGONITE) 
    492          ! AS FUNCTION OF PRESSURE FOLLWING EDMOND AND GIESKES (1970) 
    493          ! (P. 1285) AND BERNER (1976) 
    494          !----------------------------------------------------------------- 
    495          ! aksp(ji) = aksp0*exp(zcpexp*(devks-devkst*tc)) 
    496          ! or following Mucci 
    497          zbuf1      = - ( devk1(5) + devk2(5)*ztc + devk3(5)*ztc2 ) 
    498          zbuf2      = 0.5 *( devk4(5) + devk5(5)*ztc ) 
    499          aksps(ji)   = zksp * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 ) 
    500  
    501          ! For Phodphates (phosphoric acid) (DOE 1994) 
    502          !---------------------------------------------- 
    503          zck1p = cp10 + cp11*ztr + cp12*zlogt + ( cp13*ztr + cp14 ) * zsqrt & 
    504             &      + ( cp15*ztr + cp16 ) * zsal 
    505          zck2p = cp20 + cp21*ztr + cp22*zlogt + ( cp23*ztr + cp24 ) * zsqrt & 
    506             &      + ( cp25*ztr + cp26 ) * zsal 
    507          zck3p = cp30 + cp31*ztr + ( cp32*ztr + cp33 ) *  zsqrt & 
    508             &      + ( cp34*ztr + cp35 ) * zsal 
    509  
    510          ! For silicates (DOE 1994) change to mol/kg soln) (OCMIP) 
    511          !-------------------------------------------------------- 
    512          zcksi = cs10 + cs11*ztr + cs12*zlogt + ( cs13*ztr + cs14) * zisqrt & 
    513             &      + ( cs15*ztr + cs16 ) * zis & 
    514             &      + ( cs17*ztr + cs18 ) * zis2 & 
    515             &      + LOG( 1. + cs19*zsal ) + LOG( cs20 + cs21*zsal ) 
    516  
    517  
    518          !K1, K2 of carbonic acid, KB of boric acid, KW (H2O) 
    519          !--------------------------------------------------- 
    520          zak1p  = EXP ( zck1p  ) 
    521          zak2p  = EXP ( zck2p  ) 
    522          zak3p  = EXP ( zck3p  ) 
    523          zaksil = EXP ( zcksi  ) 
    524  
    525          zbuf1       = - ( devk1(3) + devk2(3)*ztc + devk3(3)*ztc2 ) 
    526          zbuf2       = 0.5 * ( devk4(3) + devk5(3)*ztc ) 
    527          aksis(ji)     = zaksil * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 ) 
    528  
    529          zbuf1       = - ( devk1(6) + devk2(6)*ztc + devk3(6)*ztc2 ) 
    530          zbuf2       = 0.5 * ( devk4(6) + devk5(6)*ztc ) 
    531          ak1ps(ji)   = zak1p * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 ) 
    532   
    533          zbuf1       = - ( devk1(7) + devk2(7)*ztc + devk3(7)*ztc2 ) 
    534          zbuf2       = 0.5 * ( devk4(7) + devk5(7)*ztc ) 
    535          ak2ps(ji)   = zak2p * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 ) 
    536  
    537          zbuf1       = - ( devk1(8) + devk2(8)*ztc + devk3(8)*ztc2 ) 
    538          zbuf2       = 0.5 * ( devk4(8) + devk5(8)*ztc ) 
    539          ak3ps(ji)   = zak3p * EXP( zbuf1*zcpexp + zbuf2*zcpexp2 ) 
    540  
    541          ! total borat concentration. [mol/l] 
    542          ! or from Millero 1995 [mol/l] : borat(l) = 0.000416_8*(sal/35._8)*densSW(l) 
    543          ! -------------------------------------------------------------------------- 
    544          borats(ji) = bor1 * zchl * bor2 * densSW(ji) 
    545  
    546          ak12s  (ji) = ak1s (ji) * ak2s (ji) 
    547          ak12ps (ji) = ak1ps(ji) * ak2ps(ji) 
    548          ak123ps(ji) = ak1ps(ji) * ak2ps(ji) * ak3ps(ji) 
    549  
    550          calcon2(ji) = 0.01028 * ( zsal / 35. ) * densSW(ji) 
    551  
    552       ENDDO 
    553  
    554    END SUBROUTINE sed_chem_off 
    555  
    556 #endif 
    557  
    558 #else 
    559    !!====================================================================== 
    560    !! MODULE sedchem  :   Dummy module  
    561    !!====================================================================== 
    562    !! $Id$ 
    563 CONTAINS 
    564    SUBROUTINE sed_chem( kt )         ! Empty routine 
    565       INTEGER, INTENT(in) :: kt 
    566       WRITE(*,*) 'trc_stp: You should not have seen this print! error?', kt 
    567    END SUBROUTINE sed_chem 
    568  
    569    !!====================================================================== 
    570  
    571 #endif 
     705         ! KB OF BORIC ACID, K1,K2 OF CARBONIC ACID PRESSURE 
     706         !        CORRECTION AFTER CULBERSON AND PYTKOWICZ (1968) 
     707         !        (CF. BROECKER ET AL., 1982) 
     708 
     709         zbuf1  = -     ( devk10 + devk20 * ztc + devk30 * ztc * ztc ) 
     710         zbuf2  = 0.5 * ( devk40 + devk50 * ztc ) 
     711         ak1s(ji) = zak1 * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 ) 
     712 
     713         zbuf1  =     - ( devk11 + devk21 * ztc + devk31 * ztc * ztc ) 
     714         zbuf2  = 0.5 * ( devk41 + devk51 * ztc ) 
     715         ak2s(ji) = zak2 * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 ) 
     716 
     717         zbuf1  =     - ( devk12 + devk22 * ztc + devk32 * ztc * ztc ) 
     718         zbuf2  = 0.5 * ( devk42 + devk52 * ztc ) 
     719         akbs(ji) = zakb * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 ) 
     720 
     721         zbuf1  =     - ( devk13 + devk23 * ztc + devk33 * ztc * ztc ) 
     722         zbuf2  = 0.5 * ( devk43 + devk53 * ztc ) 
     723         akws(ji) = zakw * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 ) 
     724 
     725         zbuf1  =     - ( devk14 + devk24 * ztc + devk34 * ztc * ztc ) 
     726         zbuf2  = 0.5 * ( devk44 + devk54 * ztc ) 
     727         aks3s(ji) = zcks * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 ) 
     728 
     729         zbuf1  =     - ( devk15 + devk25 * ztc + devk35 * ztc * ztc ) 
     730         zbuf2  = 0.5 * ( devk45 + devk55 * ztc ) 
     731         akf3s(ji) = zckf * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 ) 
     732 
     733         zbuf1  =     - ( devk17 + devk27 * ztc + devk37 * ztc * ztc ) 
     734         zbuf2  = 0.5 * ( devk47 + devk57 * ztc ) 
     735         ak1ps(ji) = zak1p * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 ) 
     736 
     737         zbuf1  =     - ( devk18 + devk28 * ztc + devk38 * ztc * ztc ) 
     738         zbuf2  = 0.5 * ( devk48 + devk58 * ztc ) 
     739         ak2ps(ji) = zak2p * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 ) 
     740 
     741         zbuf1  =     - ( devk110 + devk210 * ztc + devk310 * ztc * ztc ) 
     742         zbuf2  = 0.5 * ( devk410 + devk510 * ztc ) 
     743         aksis(ji) = zaksi * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 ) 
     744 
     745         ! CONVERT FROM DIFFERENT PH SCALES 
     746         total2free  = 1.0/(1.0 + zst/aks3s(ji)) 
     747         free2SWS    = 1. + zst/aks3s(ji) + zft/akf3s(ji) 
     748         total2SWS   = total2free * free2SWS 
     749         SWS2total   = 1.0 / total2SWS 
     750 
     751         ! Convert to total scale 
     752         ak1s(ji)  = ak1s(ji)  * SWS2total 
     753         ak2s(ji)  = ak2s(ji)  * SWS2total 
     754         akbs(ji)  = akbs(ji)  * SWS2total 
     755         akws(ji)  = akws(ji)  * SWS2total 
     756         ak1ps(ji) = ak1ps(ji) * SWS2total 
     757         ak2ps(ji) = ak2ps(ji) * SWS2total 
     758         ak3ps(ji) = ak3ps(ji) * SWS2total 
     759         aksis(ji) = aksis(ji) * SWS2total 
     760         akf3s(ji) = akf3s(ji) / total2free 
     761 
     762         ! APPARENT SOLUBILITY PRODUCT K'SP OF CALCITE 
     763         !        AS FUNCTION OF PRESSURE FOLLOWING MILLERO 
     764         !        (P. 1285) AND BERNER (1976) 
     765         zbuf1  =     - ( devk16 + devk26 * ztc + devk36 * ztc * ztc ) 
     766         zbuf2  = 0.5 * ( devk46 + devk56 * ztc ) 
     767         aksps(ji) = zaksp1 * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 ) 
     768 
     769         ! TOTAL F, S, and BORATE CONCENTR. [MOLES/L] 
     770         borats(ji)   = 0.0002414 * zcl / 10.811 
     771         sulfats(ji)  = zst 
     772         fluorids(ji) = zft 
     773 
     774         ! Iron and SIO3 saturation concentration from ... 
     775         sieqs(ji) = EXP(  LOG( 10.) * ( 6.44 - 968. / ztkel )  ) * 1.e-6 
     776      END DO 
     777      ! 
     778      IF( ln_timing )  CALL timing_stop('sed_chem_cst') 
     779      ! 
     780   END SUBROUTINE sed_chem_cst 
     781 
    572782 
    573783END MODULE sedchem 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/sedco3.F90

    r9598 r10345  
    11MODULE sedco3 
    2 #if defined key_sed 
    32   !!====================================================================== 
    43   !!              ***  MODULE  sedco3  *** 
     
    76   !! * Modules used 
    87   USE sed     ! sediment global variable 
     8   USE sedchem 
     9   USE lib_mpp         ! distribued memory computing library 
    910 
    1011 
     
    1516   PUBLIC sed_co3      
    1617 
    17  
    18    !! * Module variables 
    19    REAL(wp) :: epsmax   =  1.e-12      ! convergence limite value 
    20  
    2118   !!---------------------------------------------------------------------- 
    22    !!   OPA 9.0   !   NEMO Consortium   (2003) 
     19   !!   OPA 9.0   !   LODYC-IPSL   (2003) 
    2320   !!---------------------------------------------------------------------- 
    2421 
     
    4542      !! * Arguments 
    4643      INTEGER, INTENT(in)  :: kt   ! time step 
    47  
    4844      ! 
    4945      !---Local variables 
    50       INTEGER  :: jiter, ji, jk, ipt  ! dummy loop indices 
     46      INTEGER  :: ji, jk           ! dummy loop indices 
    5147 
    52       INTEGER  :: itermax             ! maximum number of Newton-Raphson iterations 
    53       INTEGER  :: itime               ! number of time to perform Newton-Raphson algorithm 
    54       LOGICAL  :: lconv = .FALSE.     ! flag for convergence 
    55       REAL(wp) :: brems               !  relaxation. parameter 
    56       REAL(wp) :: zresm, zresm1, zhipor_min  
    57       REAL(wp) :: zalk, zbor, zsil, zpo4, zdic 
    58       REAL(wp) :: zh_old, zh_old2, zh_old3, zh_old4 
    59       REAL(wp) :: zuu, zvv, zduu, zdvv  
    60       REAL(wp) :: zup, zvp, zdup, zdvp 
    61       REAL(wp) :: zah_old, zah_olds 
    62       REAL(wp) :: zh_new, zh_new2, zco3 
    63  
     48      REAL(wp), DIMENSION(jpoce,jpksed) :: zhinit, zhi 
    6449     !!---------------------------------------------------------------------- 
    6550 
     51      IF( ln_timing )  CALL timing_start('sed_co3') 
     52 
    6653      IF( kt == nitsed000 ) THEN 
    67          WRITE(numsed,*) ' sed_co3 : carbonate ion and proton concentration calculation  ' 
    68          WRITE(numsed,*) ' ' 
     54         IF (lwp) WRITE(numsed,*) ' sed_co3 : carbonate ion and proton concentration calculation  ' 
     55         IF (lwp) WRITE(numsed,*) ' ' 
    6956      ENDIF 
    7057 
    71       itermax     = 30 
    72       brems       = 1. 
    73       itime       = 0 
     58      DO jk = 1, jpksed 
     59         zhinit(:,jk)   = hipor(:,jk) / densSW(:) 
     60      END DO 
    7461 
     62      !     ------------------------------------------- 
     63      !     COMPUTE [CO3--] and [H+] CONCENTRATIONS 
     64      !     ------------------------------------------- 
     65 
     66      CALL solve_at_general_sed(zhinit, zhi) 
    7567 
    7668      DO jk = 1, jpksed 
    77          DO WHILE( itime <= 2 ) 
    78             lconv  = .FALSE. 
    79             IF( itime > 0 ) THEN   
    80                ! increase max number of iterations and relaxation parameter 
    81                itermax = 200 
    82 !!               brems   = 0.3 
    83                IF( itime == 2 ) hipor(1:jpoce,jk) = 3.e-9 ! re-initilazation of [H] values 
    84             ENDIF 
     69         DO ji = 1, jpoce 
     70            co3por(ji,jk) = pwcp(ji,jk,jwdic) * ak1s(ji) * ak2s(ji) / (zhi(ji,jk)**2   & 
     71            &               + ak1s(ji) * zhi(ji,jk) + ak1s(ji) * ak2s(ji) + rtrn ) 
     72            hipor(ji,jk)  = zhi(ji,jk) * densSW(ji) 
     73         END DO 
     74      END DO 
    8575 
    86 iflag:      DO jiter = 1, itermax 
    87  
    88                 ! Store previous hi field.    
    89                zresm = -1.e10 
    90                ipt = 1 
    91                DO ji = 1, jpoce 
    92                   ! dissociation constant are in mol/kg of solution 
    93                   ! convert pwcp concentration [mol/l] in mol/kg for solution 
    94                   zalk    = pwcp(ji,jk,jwalk) / densSW(ji) 
    95                   zh_old  = hipor(ji,jk) / densSW(ji) 
    96                   zh_old2 = zh_old  * zh_old 
    97                   zh_old3 = zh_old2 * zh_old 
    98                   zh_old4 = zh_old3 * zh_old 
    99                   zbor    = borats(ji) / densSW(ji) 
    100                   zsil    = pwcp(ji,jk,jwsil) / densSW(ji) 
    101                   zpo4    = pwcp(ji,jk,jwpo4) / densSW(ji) 
    102                   zdic    = pwcp(ji,jk,jwdic) / densSW(ji)                
    103                   ! intermediate calculation  
    104                   zuu     = zdic * ( ak1s(ji) / zh_old + 2.* ak12s(ji) / zh_old2 ) 
    105                   zvv     = 1. + ak1s(ji) / zh_old + ak12s(ji) / zh_old2 
    106                   zduu    = zdic * ( -ak1s(ji) / zh_old2 - 4. * ak12s(ji) / zh_old3 ) 
    107                   zdvv    = -ak1s(ji) / zh_old2 - 2. * ak12s(ji) / zh_old3 
    108                   zup     = zpo4 * ( ak12ps(ji) / zh_old2 + 2. * ak123ps(ji) / zh_old3 - 1.) 
    109                   zvp     = 1. + ak1ps(ji) / zh_old + ak12ps(ji) / zh_old2 + ak123ps(ji) / zh_old3 
    110                   zdup    = zpo4 * ( -2. * ak12ps(ji) / zh_old3 - 6. * ak123ps(ji) / zh_old4 ) 
    111                   zdvp    = -ak1ps(ji) / zh_old2 - 2.* ak12ps(ji) / zh_old3 - 3. * ak123ps(ji) / zh_old4 
    112                    
    113                   zah_old  = zuu / zvv + zbor / ( 1. + zh_old / akbs(ji) ) + & 
    114                      &      akws(ji) / zh_old - zh_old + zsil / ( 1. + zh_old / aksis(ji) ) + & 
    115                      &      zup / zvp 
    116                    
    117                   zah_olds = ( ( zduu * zvv - zdvv * zuu ) / ( zvv * zvv ) )      - & 
    118                      &        zbor / akbs(ji) * ( 1. + zh_old / akbs(ji) )**(-2) - & 
    119                      &        akws(ji) / zh_old2 - 1. -                            & 
    120                      &        zsil / aksis(ji) * ( 1. + zh_old / aksis(ji) )**(-2) + & 
    121                      &       ( ( zdup * zvp - zdvp * zup ) / ( zvp * zvp ) ) 
    122                   ! 
    123                   zh_new = zh_old - brems * ( zah_old - zalk ) / zah_olds 
    124                   !  
    125                   zresm1 = ABS( zh_new - zh_old ) 
    126                   IF( zresm1 > zresm ) THEN  
    127                      zresm = zresm1   
    128                   ENDIF 
    129                   ! 
    130                   zh_new2  = zh_new * zh_new 
    131                   zco3   = ( ak12s(ji) * zdic ) / ( ak12s(ji) + ak1s(ji) * zh_new + zh_new2) 
    132                   ! again in mol/l 
    133                   hipor (ji,jk) = zh_new * densSW(ji) 
    134                   co3por(ji,jk) = zco3   * densSW(ji) 
    135                    
    136                ENDDO  ! end loop ji 
    137                 
    138                ! convergence test 
    139                IF( zresm <= epsmax ) THEN 
    140                   lconv = .TRUE. 
    141                   !minimum value of hipor 
    142                   zhipor_min = MINVAL( hipor(1:jpoce,jk ) ) 
    143                   EXIT iflag 
    144                ENDIF 
    145  
    146             ENDDO iflag 
    147  
    148             IF( lconv ) THEN 
    149 !               WRITE(numsed,*) ' convergence after iter =', jiter, ' iterations ;  res =',zresm   
    150                IF( zhipor_min < 0. ) THEN  
    151                   IF ( itime == 0 ) THEN 
    152 !                     WRITE(numsed,*) '    but hipor < 0 ; try one more time for jk = ', jk  
    153 !                     WRITE(numsed,*) '    with re-initialization of initial PH field '        
    154                      itime = 2 
    155                   ELSE 
    156 !                     WRITE(numsed,*) ' convergence after iter =', jiter, ' iterations ;  res =',zresm  
    157 !                     WRITE(numsed,*) '    but hipor < 0, again for second time for jk = ', jk  
    158 !                     WRITE(numsed,*) ' We stop : STOP ' 
    159                      STOP 
    160                   ENDIF 
    161                ELSE 
    162 !                  WRITE(numsed,*) ' successfull convergence for level jk = ',jk,& 
    163 !                     &               '  after iter =', jiter, ' iterations ;  res =',zresm   
    164 !                  WRITE(numsed,*) ' ' 
    165                   itime = 3 
    166                ENDIF 
    167             ELSE 
    168                itime = itime + 1 
    169                WRITE(numsed,*) ' No convergence for jk = ', jk, ' after ', itime, '  try'             
    170                IF ( itime == 1 ) THEN 
    171                   WRITE(numsed,*) ' try one more time with more iterations and higher relax. value' 
    172                ELSE IF ( itime == 2 ) THEN 
    173                   WRITE(numsed,*) ' try one more time for with more iterations, higher relax. value'                
    174                   WRITE(numsed,*) ' and with re-initialization of initial PH field '  
    175                ELSE        
    176                   WRITE(numsed,*) ' No more... we stop ' 
    177                   STOP 
    178                ENDIF 
    179             ENDIF 
    180          ENDDO ! End of WHILE LOOP 
    181      ENDDO 
     76     IF( ln_timing )  CALL timing_stop('sed_co3') 
    18277 
    18378   END SUBROUTINE sed_co3 
    184 #else 
    185    !!====================================================================== 
    186    !! MODULE sedco3  :   Dummy module  
    187    !!====================================================================== 
    188    !! $Id$ 
    189 CONTAINS 
    190    SUBROUTINE sed_co3( kt )         ! Empty routine 
    191       INTEGER, INTENT(in) :: kt 
    192       WRITE(*,*) 'sed_co3: You should not have seen this print! error?', kt 
    193    END SUBROUTINE sed_co3 
    194  
    195    !!====================================================================== 
    196  
    197 #endif 
    19879 
    19980END MODULE sedco3 
  • NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/TOP/PISCES/SED/seddsr.F90

    r5215 r10345  
    11MODULE seddsr 
    2 #if defined key_sed 
    32   !!====================================================================== 
    43   !!              ***  MODULE  seddsr  *** 
    5    !!    Sediment : dissolution and reaction in pore water 
     4   !!    Sediment : dissolution and reaction in pore water related  
     5   !!    related to organic matter 
    66   !!===================================================================== 
    77   !! * Modules used 
    88   USE sed     ! sediment global variable 
    9    USE sedmat  ! linear system of equations 
    10    USE sedco3  ! carbonate ion and proton concentration  
     9   USE sed_oce 
     10   USE sedini 
     11   USE lib_mpp         ! distribued memory computing library 
     12   USE lib_fortran 
     13 
     14   IMPLICIT NONE 
     15   PRIVATE 
    1116 
    1217   PUBLIC sed_dsr 
     
    1419   !! * Module variables 
    1520 
    16    REAL(wp), DIMENSION(:), ALLOCATABLE, PUBLIC :: cons_o2 
    17    REAL(wp), DIMENSION(:), ALLOCATABLE, PUBLIC :: cons_no3 
    18    REAL(wp), DIMENSION(:), ALLOCATABLE, PUBLIC :: sour_no3 
    19    REAL(wp), DIMENSION(:), ALLOCATABLE, PUBLIC :: sour_c13 
    20    REAL(wp), DIMENSION(:), ALLOCATABLE, PUBLIC ::  dens_mol_wgt  ! molecular density  
     21   REAL(wp) :: zadsnh4 
     22   REAL(wp), DIMENSION(jpsol), PUBLIC      :: dens_mol_wgt  ! molecular density  
     23   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zvolc    ! temp. variables 
     24 
    2125 
    2226   !! $Id$ 
    2327CONTAINS 
    2428    
    25    SUBROUTINE sed_dsr( kt )  
     29   SUBROUTINE sed_dsr( kt, knt )  
    2630      !!---------------------------------------------------------------------- 
    2731      !!                   ***  ROUTINE sed_dsr  *** 
     
    2933      !!  ** Purpose :  computes pore water dissolution and reaction 
    3034      !! 
    31       !!  ** Methode :  implicit simultaneous computation of undersaturation 
    32       !!               resulting from diffusive pore water transport and chemical 
    33       !!               pore water reactions. Solid material is consumed according 
    34       !!               to redissolution and remineralisation 
    35       !! 
    36       !!  ** Remarks : 
    37       !!              - undersaturation : deviation from saturation concentration 
    38       !!              - reaction rate   : sink of undersaturation from dissolution 
    39       !!                                 of solid material  
     35      !!  ** Methode :  Computation of the redox reactions in sediment. 
     36      !!                The main redox reactions are solved in sed_dsr whereas 
     37      !!                the secondary reactions are solved in sed_dsr_redoxb. 
     38      !!                A strand spliting approach is being used here (see  
     39      !!                sed_dsr_redoxb for more information).  
    4040      !! 
    4141      !!   History : 
     
    4343      !!        !  04-10 (N. Emprin, M. Gehlen ) f90 
    4444      !!        !  06-04 (C. Ethe)  Re-organization 
     45      !!        !  19-08 (O. Aumont) Debugging and improvement of the model. 
     46      !!                             The original method is replaced by a  
     47      !!                              Strand splitting method which deals  
     48      !!                              well with stiff reactions. 
    4549      !!---------------------------------------------------------------------- 
    4650      !! Arguments 
    47       INTEGER, INTENT(in) ::   kt       ! number of iteration 
     51      INTEGER, INTENT(in) ::   kt, knt       ! number of iteration 
    4852      ! --- local variables 
    49       INTEGER :: ji, jk, js, jw   ! dummy looop indices 
    50       INTEGER :: nv               ! number of variables in linear tridiagonal eq 
    51  
    52       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zrearat    ! reaction rate in pore water 
    53       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zundsat    ! undersaturation ; indice jpwatp1 is for calcite    
    54       REAL(wp), DIMENSION(:    ), ALLOCATABLE :: zmo2_0, zmo2_1  ! temp. array for mass balance calculation 
    55       REAL(wp), DIMENSION(:    ), ALLOCATABLE :: zmno3_0, zmno3_1, zmno3_2 
    56       REAL(wp), DIMENSION(:    ), ALLOCATABLE :: zmc13_0, zmc13_1, zmc13_2, zmc13_3 
    57       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zvolc    ! temp. variables 
     53      INTEGER :: ji, jk, js, jw, jn   ! dummy looop indices 
     54 
     55      REAL(wp), DIMENSION(jpoce,jpksed) :: zrearat1, zrearat2, zrearat3    ! reaction rate in pore water 
     56      REAL(wp), DIMENSION(jpoce,jpksed) :: zundsat    ! undersaturation ; indice jpwatp1 is for calcite    
     57      REAL(wp), DIMENSION(jpoce,jpksed) :: zkpoc, zkpos, zkpor, zlimo2, zlimno3, zlimso4, zlimfeo    ! undersaturation ; indice jpwatp1 is for calcite    
     58      REAL(wp), DIMENSION(jpoce)        :: zsumtot 
    5859      REAL(wp)  ::  zsolid1, zsolid2, zsolid3, zvolw, zreasat 
    59  
     60      REAL(wp)  ::  zsatur, zsatur2, znusil, zkpoca, zkpocb, zkpocc 
     61      REAL(wp)  ::  zratio, zgamma, zbeta, zlimtmp, zundsat2 
    6062      !! 
    6163      !!---------------------------------------------------------------------- 
    6264 
    63       IF( kt == nitsed000 ) THEN 
    64          WRITE(numsed,*) ' sed_dsr : Dissolution reaction ' 
    65          WRITE(numsed,*) ' ' 
    66          !  
    67          ALLOCATE( dens_mol_wgt((jpoce) )  
    68          dens_mol_wgt(1:jpsol) = dens / mol_wgt(1:jpsol) 
    69          !  
    70          ALLOCATE( cons_o2 (jpoce) ) ;   ALLOCATE( cons_no3(jpoce) )  
    71          ALLOCATE( sour_no3(jpoce) ) ;   ALLOCATE( sour_c13(jpoce) )   
     65      IF( ln_timing )  CALL timing_start('sed_dsr') 
     66! 
     67      IF( kt == nitsed000 .AND. knt == 1 ) THEN 
     68         IF (lwp) THEN 
     69            WRITE(numsed,*) ' sed_dsr : Dissolution reaction ' 
     70            WRITE(numsed,*) ' ' 
     71         ENDIF 
    7272      ENDIF 
    7373 
    74       ! Initialization of data for mass balance calculation 
    75       !--------------------------------------------------- 
    76  
    77       tokbot(:,:)  = 0. 
    78       cons_o2 (:)  = 0.  
    79       cons_no3(:)  = 0.   
    80       sour_no3(:)  = 0.   
    81       sour_c13(:)  = 0.        
    82     
    83       ! Initializations 
    84       !---------------------- 
    85       ALLOCATE( zmo2_0 (jpoce) ) ;  ALLOCATE( zmo2_1 (jpoce) )  
    86       ALLOCATE( zmno3_0(jpoce) ) ;  ALLOCATE( zmno3_1(jpoce) )  ;  ALLOCATE( zmno3_2(jpoce) )  
    87       ALLOCATE( zmc13_0(jpoce) ) ;  ALLOCATE( zmc13_1(jpoce) )  ;  ALLOCATE( zmc13_2(jpoce) ) ;  ALLOCATE( zmc13_3(jpoce) )  
    88  
    89       zmo2_0 (:) = 0.  ; zmo2_1 (:) = 0. 
    90       zmno3_0(:) = 0.  ; zmno3_1(:) = 0.  ;  zmno3_2(:) = 0. 
    91       zmc13_0(:) = 0.  ; zmc13_1(:) = 0.  ;  zmc13_2(:) = 0.  ; zmc13_3(:) = 0. 
     74     ! Initializations 
     75     !---------------------- 
    9276       
    93       ALLOCATE( zrearat(jpoce,jpksed,3) ) ;  ALLOCATE( zundsat(jpoce,jpksed,3) )       
    94       zrearat(:,:,:)   = 0.    ;   zundsat(:,:,:) = 0.  
    95  
    96  
    97       ALLOCATE( zvolc(jpoce,jpksed,jpsol) )  
    98       zvolc(:,:,:)   = 0. 
    99  
    100       !-------------------------------------------------------------------- 
    101       ! Temporary accomodation to take account of  particule rain deposition 
    102       !--------------------------------------------------------------------- 
    103        
    104        
    105       ! 1. Change of geometry 
    106       !    Increase of dz3d(2) thickness : dz3d(2) = dz3d(2)+dzdep 
    107       !    Warning : no change for dz(2) 
    108       !--------------------------------------------------------- 
    109       dz3d(1:jpoce,2) = dz3d(1:jpoce,2) + dzdep(1:jpoce) 
    110  
    111        
    112       ! New values for volw3d(:,2) and vols3d(:,2) 
    113       ! Warning : no change neither for volw(2) nor  vols(2) 
    114       !------------------------------------------------------ 
    115       volw3d(1:jpoce,2) = dz3d(1:jpoce,2) * por(2) 
    116       vols3d(1:jpoce,2) = dz3d(1:jpoce,2) * por1(2) 
     77      zrearat1(:,:)   = 0.    ;   zundsat(:,:) = 0. ; zkpoc(:,:) = 0. 
     78      zlimo2 (:,:)    = 0.    ;   zlimno3(:,:) = 0. ; zrearat2(:,:) = 0. 
     79      zlimso4(:,:)    = 0.    ;   zkpor(:,:)   = 0. ; zrearat3(:,:) = 0. 
     80      zkpos  (:,:)    = 0. 
     81      zsumtot(:)      = rtrn 
     82   
     83      ALLOCATE( zvolc(jpoce, jpksed, jpsol) ) 
     84      zvolc(:,:,:)    = 0. 
     85      zadsnh4 = 1.0 / ( 1.0 + adsnh4 ) 
     86 
     87      ! Inhibition terms for the different redox equations 
     88      ! -------------------------------------------------- 
     89      DO jk = 1, jpksed 
     90         DO ji = 1, jpoce 
     91            zkpoc(ji,jk) = reac_pocl  
     92            zkpos(ji,jk) = reac_pocs 
     93            zkpor(ji,jk) = reac_pocr 
     94         END DO 
     95      END DO 
    11796 
    11897      ! Conversion of volume units 
     
    12099      DO js = 1, jpsol 
    121100         DO jk = 1, jpksed 
    122             DO ji = 1, jpoce     
     101            DO ji = 1, jpoce 
    123102               zvolc(ji,jk,js) = ( vols3d(ji,jk) * dens_mol_wgt(js) ) /  & 
    124                   &              ( volw3d(ji,jk) * 1.e-3 )      
     103                  &              ( volw3d(ji,jk) * 1.e-3 ) 
    125104            ENDDO 
    126105         ENDDO 
    127106      ENDDO 
    128107 
    129       ! 2. Change of previous solid fractions (due to volum changes) for k=2 
    130       !--------------------------------------------------------------------- 
    131  
    132       DO js = 1, jpsol 
    133          DO ji = 1, jpoce 
    134             solcp(ji,2,js) = solcp(ji,2,js) * dz(2) / dz3d(ji,2) 
    135          ENDDO 
    136       END DO 
    137  
    138       ! 3. New solid fractions (including solid rain fractions) for k=2   
    139       !------------------------------------------------------------------    
    140       DO js = 1, jpsol 
    141          DO ji = 1, jpoce 
    142             solcp(ji,2,js) = solcp(ji,2,js) + & 
    143             &           ( rainrg(ji,js) / raintg(ji) ) * ( dzdep(ji) / dz3d(ji,2) ) 
    144             ! rainrm are temporary cancel 
    145             rainrm(ji,js) = 0. 
    146          END DO 
    147       ENDDO 
    148  
    149       ! 4.  Adjustment of bottom water concen.(pwcp(1)):  
    150       !     We impose that pwcp(2) is constant. Including dzdep in dz3d(:,2) we assume  
    151       !     that dzdep has got a porosity of por(2). So pore water volum of jk=2 increase. 
    152       !     To keep pwcp(2) cste we must compensate this "increase" by a slight adjusment 
    153       !     of bottom water concentration. 
    154       !     This adjustment is compensate at the end of routine 
    155       !------------------------------------------------------------- 
    156       DO jw = 1, jpwat 
    157          DO ji = 1, jpoce 
    158             pwcp(ji,1,jw) = pwcp(ji,1,jw) - & 
    159                &            pwcp(ji,2,jw) * dzdep(ji) * por(2) / dzkbot(ji) 
    160          END DO 
    161       ENDDO 
    162  
    163   
    164108      !---------------------------------------------------------- 
    165       ! 5.  Beginning of  Pore Water diffusion and solid reaction 
     109      ! 5.  Beginning of solid reaction 
    166110      !--------------------------------------------------------- 
    167        
    168       !----------------------------------------------------------------------------- 
    169       ! For jk=2,jpksed, and for couple  
    170       !  1 : jwsil/jsopal  ( SI/Opal ) 
    171       !  2 : jsclay/jsclay ( clay/clay )  
    172       !  3 : jwoxy/jspoc   ( O2/POC ) 
    173       !  reaction rate is a function of solid=concentration in solid reactif in [mol/l]  
    174       !  and undersaturation in [mol/l]. 
    175       !  Solid weight fractions should be in ie [mol/l]) 
    176       !  second member and solution are in zundsat variable 
    177       !------------------------------------------------------------------------- 
    178  
    179       !number of variables 
    180       nv  = 3 
    181       
    182       DO jk = 1, jpksed 
    183          DO ji = 1, jpoce 
    184             ! For Silicic Acid and clay 
    185             zundsat(ji,jk,1) = sat_sil   - pwcp(ji,jk,jwsil) 
    186             zundsat(ji,jk,2) = sat_clay 
    187             ! For O2 
    188             zundsat(ji,jk,3) = pwcp(ji,jk,jwoxy) / so2ut  
    189          ENDDO 
    190       ENDDO 
    191        
    192111       
    193112      ! Definition of reaction rates [rearat]=sans dim  
    194113      ! For jk=1 no reaction (pure water without solid) for each solid compo 
    195       DO ji = 1, jpoce 
    196          zrearat(ji,1,:) = 0. 
    197       ENDDO 
    198  
     114      zrearat1(:,:) = 0. 
     115      zrearat2(:,:) = 0. 
     116      zrearat3(:,:) = 0. 
     117 
     118      zundsat(:,:) = pwcp(:,:,jwoxy) 
     119 
     120      DO jk = 2, jpksed 
     121         DO ji = 1, jpoce 
     122            zlimo2(ji,jk) = 1.0 / ( zundsat(ji,jk) + xksedo2 ) 
     123            zsolid1 = zvolc(ji,jk,jspoc)  * solcp(ji,jk,jspoc) 
     124            zsolid2 = zvolc(ji,jk,jspos)  * solcp(ji,jk,jspos) 
     125            zsolid3 = zvolc(ji,jk,jspor)  * solcp(ji,jk,jspor) 
     126            zkpoca  = zkpoc(ji,jk) * zlimo2(ji,jk) 
     127            zkpocb  = zkpos(ji,jk) * zlimo2(ji,jk) 
     128            zkpocc  = zkpor(ji,jk) * zlimo2(ji,jk) 
     129            zrearat1(ji,jk)  = ( zkpoc(ji,jk) * dtsed2 * zsolid1 ) / & 
     130            &                 ( 1. + zkpoca * zundsat(ji,jk ) * dtsed2 ) 
     131            zrearat2(ji,jk)  = ( zkpos(ji,jk) * dtsed2 * zsolid2 ) / & 
     132            &                 ( 1. + zkpocb * zundsat(ji,jk ) * dtsed2 ) 
     133            zrearat3(ji,jk)  = ( zkpor(ji,jk) * dtsed2 * zsolid3 ) / & 
     134            &                 ( 1. + zkpocc * zundsat(ji,jk ) * dtsed2 ) 
     135         ENDDO 
     136      ENDDO 
    199137 
    200138      ! left hand side of coefficient matrix 
    201       DO jk = 2, jpksed 
    202          DO ji = 1, jpoce 
    203             zsolid1 = zvolc(ji,jk,jsopal) * solcp(ji,jk,jsopal) 
    204             zsolid2 = zvolc(ji,jk,jsclay) * solcp(ji,jk,jsclay) 
    205             zsolid3 = zvolc(ji,jk,jspoc)  * solcp(ji,jk,jspoc) 
    206  
    207             zrearat(ji,jk,1)  = ( reac_sil * dtsed * zsolid1 ) / & 
    208                &                ( 1. + reac_sil * dtsed * zundsat(ji,jk,1 ) ) 
    209             zrearat(ji,jk,2)  = ( reac_clay * dtsed * zsolid2 ) / & 
    210                &                ( 1. + reac_clay * dtsed * zundsat(ji,jk,2 ) ) 
    211             zrearat(ji,jk,3)  = ( reac_poc  * dtsed * zsolid3 ) / & 
    212                &                ( 1. + reac_poc  * dtsed * zundsat(ji,jk,3 ) ) 
    213          ENDDO 
    214       ENDDO 
    215  
    216  
    217       CALL sed_mat( nv, jpoce, jpksed, zrearat, zundsat ) 
    218  
     139!      DO jn = 1, 5 
     140      DO jk = 2, jpksed 
     141         DO ji = 1, jpoce 
     142jflag1:     DO jn = 1, 10 
     143               zsolid1 = zvolc(ji,jk,jspoc)  * solcp(ji,jk,jspoc) 
     144               zsolid2 = zvolc(ji,jk,jspos)  * solcp(ji,jk,jspos) 
     145               zsolid3 = zvolc(ji,jk,jspor)  * solcp(ji,jk,jspor) 
     146               zbeta   = xksedo2 - pwcp(ji,jk,jwoxy) + so2ut * ( zrearat1(ji,jk)    & 
     147               &         + zrearat2(ji,jk) + zrearat3(ji,jk) ) 
     148               zgamma = - xksedo2 * pwcp(ji,jk,jwoxy) 
     149               zundsat2 = zundsat(ji,jk) 
     150               zundsat(ji,jk) = ( - zbeta + SQRT( zbeta**2 - 4.0 * zgamma ) ) / 2.0 
     151               zlimo2(ji,jk) = 1.0 / ( zundsat(ji,jk) + xksedo2 ) 
     152               zkpoca  = zkpoc(ji,jk) * zlimo2(ji,jk) 
     153               zkpocb  = zkpos(ji,jk) * zlimo2(ji,jk) 
     154               zkpocc  = zkpor(ji,jk) * zlimo2(ji,jk) 
     155               zrearat1(ji,jk)  = ( zkpoc(ji,jk) * dtsed2 * zsolid1 ) / & 
     156               &                 ( 1. + zkpoca * zundsat(ji,jk ) * dtsed2 ) 
     157               zrearat2(ji,jk)  = ( zkpos(ji,jk) * dtsed2 * zsolid2 ) / & 
     158               &                 ( 1. + zkpocb * zundsat(ji,jk ) * dtsed2 ) 
     159               zrearat3(ji,jk)  = ( zkpor(ji,jk) * dtsed2 * zsolid3 ) / & 
     160               &                 ( 1. + zkpocc * zundsat(ji,jk ) * dtsed2 ) 
     161               IF ( ABS( (zundsat(ji,jk)-zundsat2)/(zundsat2+rtrn)) < 1E-8 ) THEN 
     162                  EXIT jflag1 
     163               ENDIF 
     164            END DO jflag1 
     165         END DO 
     166      END DO 
    219167 
    220168      ! New solid concentration values (jk=2 to jksed) for each couple  
    221       DO js = 1, nv 
    222          DO jk = 2, jpksed 
    223             DO ji = 1, jpoce 
    224                zreasat = zrearat(ji,jk,js) * zundsat(ji,jk,js) / zvolc(ji,jk,js) 
    225                solcp(ji,jk,js) = solcp(ji,jk,js) - zreasat 
    226             ENDDO 
    227          ENDDO 
    228       ENDDO 
    229       ! mass of O2/NO3 before POC remin. for mass balance check  
    230       ! det. of o2 consomation/NO3 production Mc13 
    231       DO jk = 1, jpksed 
    232          DO ji = 1, jpoce 
    233             zvolw = volw3d(ji,jk) * 1.e-3 
    234             zmo2_0 (ji)  = zmo2_0 (ji) + pwcp(ji,jk,jwoxy) * zvolw 
    235             zmno3_0(ji)  = zmno3_0(ji) + pwcp(ji,jk,jwno3) * zvolw 
    236             zmc13_0(ji)  = zmc13_0(ji) + pwcp(ji,jk,jwc13) * zvolw 
     169      DO jk = 2, jpksed 
     170         DO ji = 1, jpoce 
     171            zreasat = zrearat1(ji,jk) * zlimo2(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspoc) 
     172            solcp(ji,jk,jspoc) = solcp(ji,jk,jspoc) - zreasat 
     173            zreasat = zrearat2(ji,jk) * zlimo2(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspos) 
     174            solcp(ji,jk,jspos) = solcp(ji,jk,jspos) - zreasat 
     175            zreasat = zrearat3(ji,jk) * zlimo2(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspor) 
     176            solcp(ji,jk,jspor) = solcp(ji,jk,jspor) - zreasat 
    237177         ENDDO 
    238178      ENDDO 
    239179 
    240180      ! New pore water concentrations     
    241       DO jk = 1, jpksed 
     181      DO jk = 2, jpksed 
    242182         DO ji = 1, jpoce 
    243183            ! Acid Silicic  
    244             pwcp(ji,jk,jwsil)  = sat_sil - zundsat(ji,jk,1)             
    245             ! For O2 (in mol/l) 
    246             pwcp(ji,jk,jwoxy)  = zundsat(ji,jk,3) * so2ut  
    247             zreasat = zrearat(ji,jk,3) * zundsat(ji,jk,3)    ! oxygen          
     184            pwcp(ji,jk,jwoxy)  = zundsat(ji,jk) 
     185            zreasat = ( zrearat1(ji,jk) + zrearat2(ji,jk) + zrearat3(ji,jk) ) * zlimo2(ji,jk) * zundsat(ji,jk)    ! oxygen          
    248186            ! For DIC 
    249187            pwcp(ji,jk,jwdic)  = pwcp(ji,jk,jwdic) + zreasat 
    250             ! For nitrates 
    251             pwcp(ji,jk,jwno3)  = pwcp(ji,jk,jwno3) + zreasat * srno3             
     188            zsumtot(ji) = zsumtot(ji) + zreasat / dtsed2 * volw3d(ji,jk) * 1.e-3 * 86400. * 365. * 1E3 
    252189            ! For Phosphate (in mol/l) 
    253             pwcp(ji,jk,jwpo4)  = pwcp(ji,jk,jwpo4) + zreasat * spo4r             
     190            pwcp(ji,jk,jwpo4)  = pwcp(ji,jk,jwpo4) + zreasat * spo4r 
     191            ! For iron (in mol/l) 
     192            pwcp(ji,jk,jwfe2)  = pwcp(ji,jk,jwfe2) + fecratio(ji) * zreasat 
    254193            ! For alkalinity 
    255             pwcp(ji,jk,jwalk)  = pwcp(ji,jk,jwalk) - zreasat * ( srno3 + 2.* spo4r )            
    256             ! For DIC13 
    257             pwcp(ji,jk,jwc13)  = pwcp(ji,jk,jwc13) + zreasat * rc13P * pdb 
    258          ENDDO 
    259       ENDDO 
    260  
    261  
    262       ! Mass of O2 for mass balance check and det. of o2 consomation 
    263       DO jk = 1, jpksed 
    264          DO ji = 1, jpoce 
    265             zvolw = volw3d(ji,jk) * 1.e-3 
    266             zmo2_1 (ji) = zmo2_1 (ji) + pwcp(ji,jk,jwoxy) * zvolw 
    267             zmno3_1(ji) = zmno3_1(ji) + pwcp(ji,jk,jwno3) * zvolw 
    268             zmc13_1(ji) = zmc13_1(ji) + pwcp(ji,jk,jwc13) * zvolw 
    269          ENDDO 
    270       ENDDO 
    271  
    272       DO ji = 1, jpoce 
    273          cons_o2 (ji) = zmo2_0 (ji) - zmo2_1 (ji) 
    274          sour_no3(ji) = zmno3_1(ji) - zmno3_0(ji)      
    275          sour_c13(ji) = zmc13_1(ji) - zmc13_0(ji)  
    276       ENDDO 
    277   
     194            pwcp(ji,jk,jwalk)  = pwcp(ji,jk,jwalk) + zreasat * ( srno3 * zadsnh4 - 2.* spo4r ) 
     195            ! Ammonium 
     196            pwcp(ji,jk,jwnh4)  = pwcp(ji,jk,jwnh4) + zreasat * srno3 * zadsnh4 
     197            ! Ligands 
     198            sedligand(ji,jk)   = sedligand(ji,jk) + ratligc * zreasat - reac_ligc * sedligand(ji,jk) 
     199         ENDDO 
     200      ENDDO 
    278201 
    279202      !-------------------------------------------------------------------- 
     
    282205      !-------------------------------------------------------------------- 
    283206 
    284       nv = 1 
    285       DO jk = 1, jpksed 
    286          DO ji = 1, jpoce 
    287             zundsat(ji,jk,1) = pwcp(ji,jk,jwno3) / srDnit 
    288          ENDDO 
    289       ENDDO 
    290       DO jk = 2, jpksed 
    291          DO ji = 1, jpoce 
    292             IF( pwcp(ji,jk,jwoxy) < sthrO2 ) THEN 
     207      zrearat1(:,:) = 0. 
     208      zrearat2(:,:) = 0. 
     209      zrearat3(:,:) = 0. 
     210 
     211      zundsat(:,:) = pwcp(:,:,jwno3) 
     212 
     213      DO jk = 2, jpksed 
     214         DO ji = 1, jpoce 
     215            zlimno3(ji,jk) = ( 1.0 - pwcp(ji,jk,jwoxy) * zlimo2(ji,jk) ) / ( zundsat(ji,jk) + xksedno3 ) 
     216            zsolid1 = zvolc(ji,jk,jspoc) * solcp(ji,jk,jspoc) 
     217            zsolid2 = zvolc(ji,jk,jspos) * solcp(ji,jk,jspos) 
     218            zsolid3 = zvolc(ji,jk,jspor) * solcp(ji,jk,jspor) 
     219            zkpoca = zkpoc(ji,jk) * zlimno3(ji,jk) 
     220            zkpocb = zkpos(ji,jk) * zlimno3(ji,jk) 
     221            zkpocc = zkpor(ji,jk) * zlimno3(ji,jk) 
     222            zrearat1(ji,jk)  = ( zkpoc(ji,jk) * dtsed2 * zsolid1 ) / & 
     223            &                 ( 1. + zkpoca * zundsat(ji,jk ) * dtsed2 ) 
     224            zrearat2(ji,jk)  = ( zkpos(ji,jk) * dtsed2 * zsolid2 ) / & 
     225            &                 ( 1. + zkpocb * zundsat(ji,jk ) * dtsed2 ) 
     226            zrearat3(ji,jk)  = ( zkpor(ji,jk) * dtsed2 * zsolid3 ) / & 
     227            &                 ( 1. + zkpocc * zundsat(ji,jk ) * dtsed2 ) 
     228        END DO 
     229      END DO 
     230 
     231!      DO jn = 1, 5 
     232      DO jk = 2, jpksed 
     233         DO ji = 1, jpoce 
     234jflag2:    DO jn = 1, 10 
     235               zlimtmp = ( 1.0 - pwcp(ji,jk,jwoxy) * zlimo2(ji,jk) ) 
    293236               zsolid1 = zvolc(ji,jk,jspoc) * solcp(ji,jk,jspoc) 
    294                zrearat(ji,jk,1) = ( reac_no3 * dtsed * zsolid1 ) / & 
    295                   &                    ( 1. + reac_no3 * dtsed * zundsat(ji,jk,1 ) ) 
    296             ELSE 
    297                zrearat(ji,jk,1) = 0. 
    298             ENDIF 
    299          END DO 
    300       END DO 
    301  
    302  
    303       ! solves tridiagonal system 
    304       CALL sed_mat( nv, jpoce, jpksed, zrearat, zundsat ) 
     237               zsolid2 = zvolc(ji,jk,jspos) * solcp(ji,jk,jspos) 
     238               zsolid3 = zvolc(ji,jk,jspor) * solcp(ji,jk,jspor) 
     239               zbeta   = xksedno3 - pwcp(ji,jk,jwno3) + srDnit * ( zrearat1(ji,jk)    & 
     240               &         + zrearat2(ji,jk) + zrearat3(ji,jk) ) * zlimtmp 
     241               zgamma = - xksedno3 * pwcp(ji,jk,jwno3) 
     242               zundsat2 = zundsat(ji,jk) 
     243               zundsat(ji,jk) = ( - zbeta + SQRT( zbeta**2 - 4.0 * zgamma ) ) / 2.0 
     244               zlimno3(ji,jk) = ( 1.0 - pwcp(ji,jk,jwoxy) * zlimo2(ji,jk) ) / ( zundsat(ji,jk) + xksedno3 ) 
     245               zkpoca  = zkpoc(ji,jk) * zlimno3(ji,jk) 
     246               zkpocb  = zkpos(ji,jk) * zlimno3(ji,jk) 
     247               zkpocc  = zkpor(ji,jk) * zlimno3(ji,jk) 
     248               zrearat1(ji,jk)  = ( zkpoc(ji,jk) * dtsed2 * zsolid1 ) / & 
     249               &                 ( 1. + zkpoca * zundsat(ji,jk ) * dtsed2 ) 
     250               zrearat2(ji,jk)  = ( zkpos(ji,jk) * dtsed2 * zsolid2 ) / & 
     251               &                 ( 1. + zkpocb * zundsat(ji,jk ) * dtsed2 ) 
     252               zrearat3(ji,jk)  = ( zkpor(ji,jk) * dtsed2 * zsolid3 ) / & 
     253               &                 ( 1. + zkpocc * zundsat(ji,jk ) * dtsed2 ) 
     254               IF ( ABS( (zundsat(ji,jk)-zundsat2)/(zundsat2+rtrn)) < 1E-8 ) THEN 
     255                  EXIT jflag2 
     256               ENDIF 
     257            END DO jflag2 
     258         END DO 
     259      END DO 
    305260 
    306261 
     
    308263      DO jk = 2, jpksed 
    309264         DO ji = 1, jpoce 
    310             zreasat = zrearat(ji,jk,1) * zundsat(ji,jk,1) / zvolc(ji,jk,jspoc) 
     265            zreasat = zrearat1(ji,jk) * zlimno3(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspoc) 
    311266            solcp(ji,jk,jspoc) = solcp(ji,jk,jspoc) - zreasat 
     267            zreasat = zrearat2(ji,jk) * zlimno3(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspos) 
     268            solcp(ji,jk,jspos) = solcp(ji,jk,jspos) - zreasat 
     269            zreasat = zrearat3(ji,jk) * zlimno3(ji,jk) * zundsat(ji,jk) / zvolc(ji,jk,jspor) 
     270            solcp(ji,jk,jspor) = solcp(ji,jk,jspor) - zreasat 
    312271         ENDDO 
    313272      ENDDO 
    314273 
    315274      ! New dissolved concentrations 
    316       DO jk = 1, jpksed 
    317          DO ji = 1, jpoce 
    318             zreasat = zrearat(ji,jk,1) * zundsat(ji,jk,1)     
     275      DO jk = 2, jpksed 
     276         DO ji = 1, jpoce 
    319277            ! For nitrates 
    320             pwcp(ji,jk,jwno3)  =  zundsat(ji,jk,1) * srDnit 
     278            pwcp(ji,jk,jwno3)  =  zundsat(ji,jk) 
     279            zreasat = ( zrearat1(ji,jk) + zrearat2(ji,jk) + zrearat3(ji,jk) ) * zlimno3(ji,jk) * zundsat(ji,jk) 
    321280            ! For DIC 
    322281            pwcp(ji,jk,jwdic)  = pwcp(ji,jk,jwdic) + zreasat 
     282            zsumtot(ji) = zsumtot(ji) + zreasat / dtsed2 * volw3d(ji,jk) * 1.e-3 * 86400. * 365. * 1E3 
    323283            ! For Phosphate (in mol/l) 
    324284            pwcp(ji,jk,jwpo4)  = pwcp(ji,jk,jwpo4) + zreasat * spo4r             
     285            ! Ligands 
     286            sedligand(ji,jk)   = sedligand(ji,jk) + ratligc * zreasat 
     287            ! For iron (in mol/l) 
     288            pwcp(ji,jk,jwfe2)  = pwcp(ji,jk,jwfe2) + fecratio(ji) * zreasat 
    325289            ! For alkalinity 
    326             pwcp(ji,jk,jwalk)  = pwcp(ji,jk,jwalk) + zreasat * ( srDnit - 2.* spo4r )            
    327             ! For DIC13 
    328             pwcp(ji,jk,jwc13)  = pwcp(ji,jk,jwc13) + zreasat * rc13P * pdb 
    329          ENDDO 
    330       ENDDO 
    331  
    332  
    333       ! Mass of O2 for mass balance check and det. of o2 consomation 
    334       DO jk = 1, jpksed 
    335          DO ji = 1, jpoce 
    336             zvolw = volw3d(ji,jk) * 1.e-3 
    337             zmno3_2(ji) = zmno3_2(ji) + pwcp(ji,jk ,jwno3) * zvolw 
    338             zmc13_2(ji) = zmc13_2(ji) + pwcp(ji,jk ,jwc13) * zvolw    
    339          ENDDO 
    340       ENDDO 
    341  
    342       DO ji = 1, jpoce 
    343          cons_no3(ji) = zmno3_1(ji) - zmno3_2(ji)   
    344          sour_c13(ji) = sour_c13(ji) + zmc13_2(ji) - zmc13_1(ji)      
    345       ENDDO 
    346  
    347  
    348       !--------------------------- 
    349       ! Solves PO4 diffusion  
    350       !---------------------------- 
    351  
    352       nv = 1 
    353       DO jk = 1, jpksed 
    354          DO ji = 1, jpoce 
    355             zundsat(ji,jk,1) = pwcp(ji,jk,jwpo4) 
    356             zrearat(ji,jk,1) = 0. 
    357          ENDDO 
    358       ENDDO 
    359  
    360  
    361       ! solves tridiagonal system 
    362       CALL sed_mat( nv, jpoce, jpksed, zrearat, zundsat ) 
    363  
    364  
    365       ! New undsaturation values and dissolved concentrations 
    366       DO jk = 1, jpksed 
    367          DO ji = 1, jpoce 
    368             pwcp(ji,jk,jwpo4) = zundsat(ji,jk,1) 
    369          ENDDO 
    370       ENDDO 
    371  
    372  
    373       !--------------------------------------------------------------- 
    374       ! Performs CaCO3 particle deposition and redissolution (indice 9) 
    375       !-------------------------------------------------------------- 
    376  
    377       ! computes co3por from the updated pwcp concentrations (note [co3por] = mol/l) 
    378  
    379       CALL sed_co3( kt ) 
    380  
    381  
    382       nv = 1 
    383       ! *densSW(l)**2 converts aksps [mol2/kg sol2] into [mol2/l2] to get [undsat] in [mol/l] 
    384       DO jk = 1, jpksed 
    385          DO ji = 1, jpoce 
    386             zundsat(ji,jk,1) = aksps(ji) * densSW(ji) * densSW(ji) / calcon2(ji) & 
    387                &                     - co3por(ji,jk) 
    388             ! positive values of undersaturation 
    389             zundsat(ji,jk,1) = MAX( 0., zundsat(ji,jk,1) )             
    390          ENDDO 
    391       ENDDO 
    392  
    393       DO jk = 2, jpksed 
    394          DO ji = 1, jpoce 
    395             zsolid1 = zvolc(ji,jk,jscal) * solcp(ji,jk,jscal) 
    396             zrearat(ji,jk,1) = ( reac_cal * dtsed * zsolid1 ) / & 
    397                   &               ( 1. + reac_cal * dtsed * zundsat(ji,jk,1) ) 
    398          END DO 
    399       END DO 
    400  
    401  
    402       ! solves tridiagonal system 
    403       CALL sed_mat( nv, jpoce, jpksed, zrearat, zundsat ) 
    404  
    405  
    406       ! New solid concentration values (jk=2 to jksed) for cacO3 
    407       DO jk = 2, jpksed 
    408          DO ji = 1, jpoce 
    409             zreasat = zrearat(ji,jk,1) * zundsat(ji,jk,1) / zvolc(ji,jk,jscal) 
    410             solcp(ji,jk,jscal) = solcp(ji,jk,jscal) - zreasat 
    411          ENDDO 
    412       ENDDO 
     290            pwcp(ji,jk,jwalk)  = pwcp(ji,jk,jwalk) + zreasat * ( srDnit + srno3 * zadsnh4 - 2.* spo4r )            
     291            ! Ammonium 
     292            pwcp(ji,jk,jwnh4)  = pwcp(ji,jk,jwnh4) + zreasat * srno3 * zadsnh4 
     293         ENDDO 
     294      ENDDO 
     295 
     296      !-------------------------------------------------------------------- 
     297      ! Begining POC iron reduction 
     298      ! (indice n�5 for couple POFe(OH)3 ie solcp(:,:,jspoc)/pwcp(:,:,jsfeo)) 
     299      !-------------------------------------------------------------------- 
     300 
     301      zrearat1(:,:) = 0. 
     302      zrearat2(:,:) = 0. 
     303      zrearat3(:,:) = 0. 
     304 
     305      zundsat(:,:) = solcp(:,:,jsfeo) 
     306 
     307      DO jk = 2, jpksed 
     308         DO ji = 1, jpoce 
     309            zlimfeo(ji,jk) = ( 1.0 - pwcp(ji,jk,jwoxy) * zlimo2(ji,jk) ) * ( 1.0 - pwcp(ji,jk,jwno3)    & 
     310            &                / ( pwcp(ji,jk,jwno3) + xksedno3 ) ) / ( zundsat(ji,jk) + xksedfeo ) 
     311            zsolid1 = zvolc(ji,jk,jspoc) * solcp(ji,jk,jspoc) 
     312            zsolid2 = zvolc(ji,jk,jspos) * solcp(ji,jk,jspos) 
     313            zsolid3 = zvolc(ji,jk,jspor) * solcp(ji,jk,jspor) 
     314            zkpoca = zkpoc(ji,jk) * zlimfeo(ji,jk) 
     315            zkpocb = zkpos(ji,jk) * zlimfeo(ji,jk) 
     316            zkpocc = zkpor(ji,jk) * zlimfeo(ji,jk) 
     317            zrearat1(ji,jk) = ( zkpoc(ji,jk) * dtsed2 * zsolid1 ) / & 
     318            &                    ( 1. + zkpoca * zundsat(ji,jk) * dtsed2 ) 
     319            zrearat2(ji,jk) = ( zkpos(ji,jk) * dtsed2 * zsolid2 ) / & 
     320            &                    ( 1. + zkpocb * zundsat(ji,jk) * dtsed2 ) 
     321            zrearat3(ji,jk) = ( zkpor(ji,jk) * dtsed2 * zsolid3 ) / & 
     322            &