Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/bin/ooo
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/bin/ooo	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/bin/ooo	(revision 4245)
@@ -0,0 +1,4 @@
+#!/usr/bin/env python2.7
+import ooo
+if __name__ == '__main__':
+    ooo.main()
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/Makefile
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/Makefile	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/Makefile	(revision 4245)
@@ -0,0 +1,153 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS    =
+SPHINXBUILD   = sphinx-build
+PAPER         =
+BUILDDIR      = build
+
+# Internal variables.
+PAPEROPT_a4     = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
+
+help:
+	@echo "Please use \`make <target>' where <target> is one of"
+	@echo "  html       to make standalone HTML files"
+	@echo "  dirhtml    to make HTML files named index.html in directories"
+	@echo "  singlehtml to make a single large HTML file"
+	@echo "  pickle     to make pickle files"
+	@echo "  json       to make JSON files"
+	@echo "  htmlhelp   to make HTML files and a HTML help project"
+	@echo "  qthelp     to make HTML files and a qthelp project"
+	@echo "  devhelp    to make HTML files and a Devhelp project"
+	@echo "  epub       to make an epub"
+	@echo "  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+	@echo "  latexpdf   to make LaTeX files and run them through pdflatex"
+	@echo "  text       to make text files"
+	@echo "  man        to make manual pages"
+	@echo "  texinfo    to make Texinfo files"
+	@echo "  info       to make Texinfo files and run them through makeinfo"
+	@echo "  gettext    to make PO message catalogs"
+	@echo "  changes    to make an overview of all changed/added/deprecated items"
+	@echo "  linkcheck  to check all external links for integrity"
+	@echo "  doctest    to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+	-rm -rf $(BUILDDIR)/*
+
+html:
+	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+	$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+	$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+	@echo
+	@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+	$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+	@echo
+	@echo "Build finished; now you can process the pickle files."
+
+json:
+	$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+	@echo
+	@echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+	$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+	@echo
+	@echo "Build finished; now you can run HTML Help Workshop with the" \
+	      ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+	$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+	@echo
+	@echo "Build finished; now you can run "qcollectiongenerator" with the" \
+	      ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+	@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Offlineobservationoperator.qhcp"
+	@echo "To view the help file:"
+	@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Offlineobservationoperator.qhc"
+
+devhelp:
+	$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+	@echo
+	@echo "Build finished."
+	@echo "To view the help file:"
+	@echo "# mkdir -p $$HOME/.local/share/devhelp/Offlineobservationoperator"
+	@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Offlineobservationoperator"
+	@echo "# devhelp"
+
+epub:
+	$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+	@echo
+	@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo
+	@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+	@echo "Run \`make' in that directory to run these through (pdf)latex" \
+	      "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo "Running LaTeX files through pdflatex..."
+	$(MAKE) -C $(BUILDDIR)/latex all-pdf
+	@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+	$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+	@echo
+	@echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+	$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+	@echo
+	@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+texinfo:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo
+	@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+	@echo "Run \`make' in that directory to run these through makeinfo" \
+	      "(use \`make info' here to do that automatically)."
+
+info:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo "Running Texinfo files through makeinfo..."
+	make -C $(BUILDDIR)/texinfo info
+	@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+gettext:
+	$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+	@echo
+	@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+changes:
+	$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+	@echo
+	@echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+	$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+	@echo
+	@echo "Link check complete; look for any errors in the above output " \
+	      "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+	$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+	@echo "Testing of doctests in the sources finished, look at the " \
+	      "results in $(BUILDDIR)/doctest/output.txt."
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/make.bat
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/make.bat	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/make.bat	(revision 4245)
@@ -0,0 +1,190 @@
+@ECHO OFF
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+	set SPHINXBUILD=sphinx-build
+)
+set BUILDDIR=build
+set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source
+set I18NSPHINXOPTS=%SPHINXOPTS% source
+if NOT "%PAPER%" == "" (
+	set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
+	set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
+)
+
+if "%1" == "" goto help
+
+if "%1" == "help" (
+	:help
+	echo.Please use `make ^<target^>` where ^<target^> is one of
+	echo.  html       to make standalone HTML files
+	echo.  dirhtml    to make HTML files named index.html in directories
+	echo.  singlehtml to make a single large HTML file
+	echo.  pickle     to make pickle files
+	echo.  json       to make JSON files
+	echo.  htmlhelp   to make HTML files and a HTML help project
+	echo.  qthelp     to make HTML files and a qthelp project
+	echo.  devhelp    to make HTML files and a Devhelp project
+	echo.  epub       to make an epub
+	echo.  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter
+	echo.  text       to make text files
+	echo.  man        to make manual pages
+	echo.  texinfo    to make Texinfo files
+	echo.  gettext    to make PO message catalogs
+	echo.  changes    to make an overview over all changed/added/deprecated items
+	echo.  linkcheck  to check all external links for integrity
+	echo.  doctest    to run all doctests embedded in the documentation if enabled
+	goto end
+)
+
+if "%1" == "clean" (
+	for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
+	del /q /s %BUILDDIR%\*
+	goto end
+)
+
+if "%1" == "html" (
+	%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/html.
+	goto end
+)
+
+if "%1" == "dirhtml" (
+	%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
+	goto end
+)
+
+if "%1" == "singlehtml" (
+	%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
+	goto end
+)
+
+if "%1" == "pickle" (
+	%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can process the pickle files.
+	goto end
+)
+
+if "%1" == "json" (
+	%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can process the JSON files.
+	goto end
+)
+
+if "%1" == "htmlhelp" (
+	%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can run HTML Help Workshop with the ^
+.hhp project file in %BUILDDIR%/htmlhelp.
+	goto end
+)
+
+if "%1" == "qthelp" (
+	%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can run "qcollectiongenerator" with the ^
+.qhcp project file in %BUILDDIR%/qthelp, like this:
+	echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Offlineobservationoperator.qhcp
+	echo.To view the help file:
+	echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Offlineobservationoperator.ghc
+	goto end
+)
+
+if "%1" == "devhelp" (
+	%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished.
+	goto end
+)
+
+if "%1" == "epub" (
+	%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The epub file is in %BUILDDIR%/epub.
+	goto end
+)
+
+if "%1" == "latex" (
+	%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
+	goto end
+)
+
+if "%1" == "text" (
+	%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The text files are in %BUILDDIR%/text.
+	goto end
+)
+
+if "%1" == "man" (
+	%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The manual pages are in %BUILDDIR%/man.
+	goto end
+)
+
+if "%1" == "texinfo" (
+	%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
+	goto end
+)
+
+if "%1" == "gettext" (
+	%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
+	goto end
+)
+
+if "%1" == "changes" (
+	%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.The overview file is in %BUILDDIR%/changes.
+	goto end
+)
+
+if "%1" == "linkcheck" (
+	%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Link check complete; look for any errors in the above output ^
+or in %BUILDDIR%/linkcheck/output.txt.
+	goto end
+)
+
+if "%1" == "doctest" (
+	%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Testing of doctests in the sources finished, look at the ^
+results in %BUILDDIR%/doctest/output.txt.
+	goto end
+)
+
+:end
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/conf.py
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/conf.py	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/conf.py	(revision 4245)
@@ -0,0 +1,246 @@
+# -*- coding: utf-8 -*-
+#
+# Offline observation operator documentation build configuration file, created by
+# sphinx-quickstart on Mon Oct  7 17:21:35 2013.
+#
+# This file is execfile()d with the current directory set to its containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys, os
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+sys.path.insert(0, os.path.abspath('../..'))
+
+# -- General configuration -----------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be extensions
+# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx']
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'Offline observation operator'
+copyright = u'2013, Andrew Ryan'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '0.1'
+# The full version, including alpha/beta/rc tags.
+release = '0.1.0'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = []
+
+# The reST default role (used for this markup: `text`) to use for all documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+
+# -- Options for HTML output ---------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  See the documentation for
+# a list of builtin themes.
+html_theme = 'default'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further.  For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+#html_theme_path = []
+
+# The name for this set of Sphinx documents.  If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# A shorter title for the navigation bar.  Default is the same as html_title.
+#html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_domain_indices = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it.  The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'Offlineobservationoperatordoc'
+
+
+# -- Options for LaTeX output --------------------------------------------------
+
+latex_elements = {
+# The paper size ('letterpaper' or 'a4paper').
+#'papersize': 'letterpaper',
+
+# The font size ('10pt', '11pt' or '12pt').
+#'pointsize': '10pt',
+
+# Additional stuff for the LaTeX preamble.
+#'preamble': '',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass [howto/manual]).
+latex_documents = [
+  ('index', 'Offlineobservationoperator.tex', u'Offline observation operator Documentation',
+   u'Andrew Ryan', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_domain_indices = True
+
+
+# -- Options for manual page output --------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+    ('index', 'offlineobservationoperator', u'Offline observation operator Documentation',
+     [u'Andrew Ryan'], 1)
+]
+
+# If true, show URL addresses after external links.
+#man_show_urls = False
+
+
+# -- Options for Texinfo output ------------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+#  dir menu entry, description, category)
+texinfo_documents = [
+  ('index', 'Offlineobservationoperator', u'Offline observation operator Documentation',
+   u'Andrew Ryan', 'Offlineobservationoperator', 'One line description of project.',
+   'Miscellaneous'),
+]
+
+# Documents to append as an appendix to all manuals.
+#texinfo_appendices = []
+
+# If false, no module index is generated.
+#texinfo_domain_indices = True
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#texinfo_show_urls = 'footnote'
+
+
+# Example configuration for intersphinx: refer to the Python standard library.
+intersphinx_mapping = {'http://docs.python.org/': None}
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/index.rst
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/index.rst	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/index.rst	(revision 4245)
@@ -0,0 +1,23 @@
+.. Offline observation operator documentation master file, created by
+   sphinx-quickstart on Mon Oct  7 17:21:35 2013.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
+Welcome to Offline observation operator's documentation!
+========================================================
+
+Contents:
+
+.. toctree::
+   :maxdepth: 2
+
+   intro
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/intro.rst
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/intro.rst	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/intro.rst	(revision 4245)
@@ -0,0 +1,57 @@
+
+Introduction
+------------
+
+The offline observation operator quick start script involves simple
+computation and manipulation of NEMO namelists.
+
+Quick start script
+------------------
+
+.. code-block:: none
+
+   ooo -h
+   usage: ooo [-h] [-w WORK_DIR] [-f FORECAST_TYPES] [-l LEAD_TIMES]
+              [-o OBS_TYPES] [--class4]
+              DATE NAMELIST
+   
+   positional arguments:
+     DATE                  Run date.
+     NAMELIST              NEMO namelist to edit.
+   
+   optional arguments:
+     -h, --help            show this help message and exit
+     -w WORK_DIR, --work-dir WORK_DIR
+     -f FORECAST_TYPES, --forecast-types FORECAST_TYPES
+                           Choice of forecast,persistence,climatology
+     -l LEAD_TIMES, --lead-times LEAD_TIMES
+                           Forecast lead times
+     -o OBS_TYPES, --obs-types OBS_TYPES
+                           Choice of namobs types.
+     --class4              Flag to choose class 4 file outputs
+     --dry-run             Flag to test namelist building without submitting.
+     --cmd COMMAND         Submit task to run.
+     -v, --verbose         Prints difference between before and after namelists.
+
+
+The above command line utility ``ooo`` can be used to edit **NEMO** namelists. 
+
+Run
+---
+
+.. automodule:: ooo.run
+   :members:
+
+
+Locators
+--------
+
+.. automodule:: ooo.locator
+   :members:
+
+Fortran
+-------
+
+.. automodule:: ooo.nml
+   :members:
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/__init__.py
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/__init__.py	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/__init__.py	(revision 4245)
@@ -0,0 +1,3 @@
+import nml
+import locator
+from ooo import main
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/locator.py
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/locator.py	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/locator.py	(revision 4245)
@@ -0,0 +1,151 @@
+"""Locates input files and calculates namelist attributes
+
+    Typically a user will have files distributed throughout the hard drive
+    and it makes little or no sense to try to capture all use cases.
+
+    >>> date = "20130101"
+    >>> namobs = observations(date, types=["profbfiles"])
+
+    >>> namooo, namcl4 = forecasts(date, types=["forecast", "persistence"], lead_times=[12, 36, 60])
+"""
+
+def observations(date, types=None):
+    """Responsible for locating observation files
+
+    Valid **namobs** observation types.
+
+    * profbfiles
+    * sstfbfiles
+    * slafbfiles
+
+    :param date: The verification date in string format ``'%Y%m%d'``
+    :param types: A list of namobs observation types
+
+    :returns: namobs namelist dictionary
+    """
+    namobs = {"ln_t3d": False,
+              "ln_s3d": False,
+              "ln_ena": False,
+              "ln_profb": False,
+              "ln_sst": False,
+              "ln_sstfb": False,
+              "ln_reysst": False,
+              "ln_ghrsst": False,
+              "ln_sla": False,
+              "ln_slafb": False,
+              "ln_sladt": False}
+    if types is None: types = []
+    for obtype in types: 
+        if obtype == "profbfiles":
+            namobs[obtype] = profbfiles(date)
+            namobs["ln_t3d"] = True
+            namobs["ln_s3d"] = True
+            namobs["ln_profb"] = True
+        elif obtype == "sstfbfiles":
+            namobs[obtype] = sstfbfiles(date)
+            namobs["ln_sst"] = True
+            namobs["ln_sstfb"] = True
+        elif obtype == "slafbfiles":
+            namobs[obtype] = slafbfiles(date)
+            namobs["ln_sla"] = True
+            namobs["ln_slafb"] = True
+    return namobs
+
+def profbfiles(date):
+    """Observation file locator stub
+
+    .. note:: User-specified stub
+
+    :param date: The verification date in string format ``'%Y%m%d'``
+    :returns: List of files
+    """
+    files = ['profb.nc']
+    return files
+
+def sstfbfiles(date):
+    """Observation file locator stub
+
+    .. note:: User-specified stub
+
+    :param date: The verification date in string format ``'%Y%m%d'``
+    :returns: List of files
+    """
+    files = ['sstfb.nc']
+    return files
+
+def slafbfiles(date):
+    """Observation file locator stub
+
+    .. note:: User-specified stub
+
+    :param date: The verification date in string format ``'%Y%m%d'``
+    :returns: List of files
+    """
+    files = ['slafb.nc']
+    return files
+
+def forecasts(date, types=None, lead_times=None):
+    """Responsible for locating forecast fields
+
+    :param date: The verification date in string format ``'%Y%m%d'``
+    :param types: A list of forecast system types
+    :param lead_times: A list of lead_times to search for
+
+    :returns: tuple of namelist data, (namooo, namcl4)
+    """
+    namooo = {}
+    namcl4 = {}
+    if types is None: types = []
+    if lead_times is None: lead_times = []
+
+    # Initialise data
+    ooo_files = []
+    nn_ooo_idx = []
+    cl4_vars = []
+    cl4_fcst_idx = []
+
+    # Search for files
+    for type in types:
+        files = []
+        in_indices = []
+        out_indices = []
+        for ilt, lead_time in enumerate(lead_times):
+            file, index = field(date, type=type, lead_time=lead_time)
+            files.append(file)
+            in_indices.append(index)
+            out_indices.append(ilt + 1)
+        # Expand return lists
+        ooo_files += files
+        nn_ooo_idx += in_indices
+        cl4_fcst_idx += out_indices
+        cl4_vars += len(files) * [type]
+
+    # Namoo
+    namooo["ooo_files"] = ooo_files
+    namooo["nn_ooo_idx"] = nn_ooo_idx
+
+    # Namcl4
+    namcl4["cl4_vars"] = cl4_vars
+    namcl4["cl4_fcst_idx"] = cl4_fcst_idx
+
+    return namooo, namcl4
+
+def field(date, type=None, lead_time=None):
+    """Forecast field locator
+
+    Maps verification date and lead time off set to file name and
+    index along file *time_counter*
+
+    .. note:: User-specified stub
+
+    :param date: The verification date in string format ``'%Y%m%d'``
+    :param type: Forecast type
+    :param lead_time: Forecast off set
+
+    :returns: (**path**, **index**)
+    """
+    # Worker function
+    file = 'nofile'
+    index = -1
+    return file, index
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/nml.py
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/nml.py	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/nml.py	(revision 4245)
@@ -0,0 +1,479 @@
+"""Collection of Fortran 90 namelist helper functions.
+
+    A common way to interface with a Fortran executable is via
+    an input file called a namelist. This module defines
+    functions which simplify the process of updating and
+    extending namelist data.
+
+    .. note:: This module is especially lightweight and follows the
+              batteries included philosophy. As such, only standard
+              library modules are required to use this code.
+
+    Walkthrough
+    ===========
+
+    New namelist
+    ------------
+
+    A typical usage is to create and update a Fortran namelist on the fly.
+
+    >>> import nml
+    >>> namid = "namfoo"
+    >>> text = nml.new(namid)
+    >>> data = {"x": nml.tostring([1, 2, 3])}
+    >>> text = nml.update(namid, text, data)
+    >>> print text
+    &namfoo
+       x = 1 2 3
+    /
+    <BLANKLINE>
+
+    In the above snippet :func:`tostring` has been used to sanitize the input
+    Python list. This function cleverly maps string data and numeric data to
+    the correct Fortran syntax.
+
+    However, the :func:`new` function takes care of many of the above steps automatically.
+    Where appropriate :func:`sanitize` has been embedded to reduce the need
+    to worry about data format problems. Take for example,
+
+    >>> print nml.new("namfoo", data={"x": range(3)})
+    &namfoo
+       x = 0 1 2
+    /
+    <BLANKLINE>
+
+    Parse existing namelist
+    -----------------------
+
+    In order to update a namelist it is necessary to convert the namelist text into
+    a dictionary of *key, value* pairs which can be manipulated in the usual Pythonic
+    fashion before being piped back out to disk.
+
+    In everyday usage text will be read from files, here however for illustration
+    purposes I have hand written a namelist.
+
+    >>> text = '''
+    ... &namfoo
+    ...     x = y  ! A description of the variables
+    ... /
+    ... &nambar
+    ...     ln_on = .TRUE. ! A description of the variables
+    ... /
+    ... '''
+
+    This can be parsed by invoking the :func:`variables` command.
+
+    >>> nml.variables(text)
+    {'x': 'y', 'ln_on': '.TRUE.'}
+
+    Or by using the :func:`namelists` function to split the file into sub-lists.
+
+    >>> nml.namelists(text)
+    {'namfoo': '&namfoo\\n    x = y  ! A description of the variables\\n/', 'nambar': '&nambar\\n    ln_on = .TRUE. ! A description of the variables\\n/'}
+    >>> sublists = nml.namelists(text)
+    >>> print sublists["nambar"]
+    &nambar
+        ln_on = .TRUE. ! A description of the variables
+    /
+
+    Which can be parsed into a dictionary as before.
+
+    >>> print nml.variables(sublists["nambar"])
+    {'ln_on': '.TRUE.'}
+
+
+    Update/replace data
+    -------------------
+
+    There are two ways of modifying values inside a Fortran namelist. 
+
+    Replace
+        The first is to simply replace a set of variables with new values. This behaviour is accomplished
+        via the :func:`replace` function. This approach simply overwrites existing variables. No knowledge
+        of sub-namelist structure is required to modify a string of text. 
+
+    .. note:: Additional variables will not be added to a namelist via this approach
+
+    Update
+        The second is to extend the set of variables contained within a namelist. This functionality is
+        controlled by the :func:`update` function. Here, variables which are not already specified are
+        added using a templated namelist line.
+
+    .. note:: It is essential to specify which sub-namelist is to be updated before modification takes place
+
+    Pipe to/from file
+    -----------------
+
+    As typical NEMO namelists are no larger than a few tens of kilobytes
+    it makes sense to process namelists as single strings instead of
+    line by line.
+
+    >>> path = "foo.nml"
+    >>> text = nml.new("namfoo")
+
+    To write to a file simply invoke the writer.
+
+    >>> # Write to file
+    >>> nml.writer(path, text)
+
+    To read from a file specify the path to be read.
+
+    >>> # Read from file
+    >>> text = nml.reader(path)
+
+    Join multiple namelists
+    -----------------------
+
+    Since the namelists are regular Python strings there is no need for a 
+    specific *join* function. Namelists can be combined in whatever manner
+    is most pleasing to the eye.
+
+    >>> namoff = nml.new("namoff")
+    >>> namcl4 = nml.new("namcl4")
+    >>> # new line join
+    >>> print "\\n".join([namoff, namcl4])
+    &namoff
+    /
+    <BLANKLINE>
+    &namcl4
+    /
+    <BLANKLINE>
+
+    >>> # Or addition
+    >>> print namoff + namcl4
+    &namoff
+    /
+    &namcl4
+    /
+    <BLANKLINE>
+
+    Module functions
+    ================
+
+"""
+__version__ = "0.1.0"
+import re
+from numbers import Number
+
+def reader(path):
+    """Reads a file into a string
+
+    Reads whole file into single string. Typically, 
+    namelists are small enough to be stored in memory
+    while updates and edits are being performed.
+
+    :param path: Path to input file
+    :returns: entire file as a single string
+
+    """
+    with open(path, "r") as handle:
+        text = handle.read()
+    return text
+
+def writer(path, text):
+    """Writes to a file from a string
+
+    Handy way of piping a processed namelist into
+    a file.
+
+    :param path: Path to output file
+    :param text: Input text to process
+
+    """
+    with open(path, "w") as handle:
+        handle.write(text)
+
+def update(namid, text, data, convert=True):
+    """Extends namelist definition.
+
+    Similar to replace this function alters the values
+    of variables defined within a namelist. In addition to
+    replacing values it also creates definitions if the
+    variable is not found in the namelist. As such, the
+    namelist id must be specified.
+
+    :param namid: Namelist id
+    :param text: Input text to process
+    :param data: Dictionary of variables
+    :keyword convert: Sanitizes input data before replacement takes place
+
+    :returns: Text
+
+    .. seealso:: :func:`replace` :func:`sanitize`
+    """
+    sublists = namelists(text)
+    assert namid in sublists, "Warning: invalid namid specified!"
+
+    # Sanitize inputs
+    if convert:
+        data = sanitize(data)
+
+    # Parse subsection
+    namtext = sublists[namid]
+    subdata = variables(namtext)
+    subvars = subdata.keys()
+
+    # Replace existing variables in namtext
+    tmptext = replace(namtext, data)
+    text = text.replace(namtext, tmptext)
+    namtext = tmptext
+
+    # Identify new variables
+    vars = data.keys()
+    newvars = list(set(vars) - set(subvars))
+    newvars.sort()
+
+    # Append new vars to namid
+    lines = namtext.split("\n")
+    for v in newvars:
+        newline = "   %s = %s" % (v, data[v])
+        lines.insert(-1, newline)
+    newtext = "\n".join(lines)
+
+    # Replace old namtext with new namtext
+    text = text.replace(namtext, newtext)
+    return text
+
+def replace(text, data, convert=True):
+    """Edits existing variables.
+
+    Pattern matches and substitutes variables inside
+    a string of text. This is independent of namid and
+    as such is useful for modifying existing variables.
+    To append new variables the :func:`update` function 
+    is required.
+
+    >>> text = '''
+    ... &namobs
+    ...    ln_sst = .TRUE. ! Logical switch for SST observations
+    ... /
+    ... '''
+    >>> data = {"ln_sst": ".FALSE."}
+    >>> print replace(text, data)
+    <BLANKLINE>
+    &namobs
+       ln_sst = .FALSE. ! Logical switch for SST observations
+    /
+    <BLANKLINE>
+
+    .. note :: This does not append new variables to a namelist
+
+    :param text: string to process
+    :param data: dictionary with which to modify **text**
+    :keyword convert: Sanitizes input data before replacement takes place
+
+    :returns: string with new data values
+
+    .. seealso:: :func:`update`, :func:`sanitize`
+    """
+    if convert:
+        data = sanitize(data)
+    for k, v in data.iteritems():
+        pat = r"(%s\s*=\s*).+?(\s*[!\n])" % (k,)
+        repl = r"\g<1>%s\g<2>" % (v,)
+        text = re.sub(pat, repl, text)
+    return text
+
+def variables(text):
+    """Retrieves dictionary of variables in text.
+
+    >>> text = '''
+    ... &namobs
+    ...    ln_sst = .TRUE. ! Logical switch for SST observations
+    ... /
+    ... '''
+    >>> variables(text)
+    {'ln_sst': '.TRUE.'}
+
+    :param text: Input text to process
+
+    :returns: A dictionary of variable, value pairs.
+
+    """
+    data = {}
+    pairs = re.findall(r"\n\s*(\w+)\s*=\s*(.+?)\s*(?=[!\n])", text)
+    for key, value in pairs:
+        data[key] = value
+    return data
+
+def namelists(text):
+    """Retrieves dictionary of namelists in text.
+
+    Useful for isolating sub-namelists.
+
+    >>> text = '''
+    ... &namobs
+    ...    ln_sst = .TRUE. ! Logical switch for SST observations
+    ... /
+    ... '''
+    >>> namelists(text)
+    {'namobs': '&namobs\\n   ln_sst = .TRUE. ! Logical switch for SST observations\\n/'}
+
+    :param text: Input text to process
+
+    :returns: A dictionary of id, text block key, value pairs
+
+    """
+    # Boundary case
+    if text.startswith("&"):
+        text = "\n" + text
+    # Regular expression
+    results = re.findall(r"\n(&(\w+).*?\n/)", text, re.DOTALL)
+    data = {}
+    for content, namid in results:
+        data[namid] = content
+    return data
+
+def tostring(data):
+    """Maps standard Python data to Fortran namelist format.
+
+    >>> tostring([1, 2, 3])
+    '1 2 3'
+    >>> tostring(["foo.nc", "bar.nc"])
+    "'foo.nc', 'bar.nc'"
+    >>> tostring(True)
+    '.TRUE.'
+
+    :param data: Input Python data
+
+    :returns: Namelist formatted string
+
+    .. seealso:: :func:`sanitize`
+    """
+    if isinstance(data, list):
+        if all_numeric(data):
+            delim = " "
+        else:
+            delim = ", "
+        text = delim.join([convert(item) for item in data])
+    else:
+        text = convert(data)
+    return text
+
+def all_numeric(inputs):
+    # Checks all list entries are numbers
+    flag = True
+    for input in inputs:
+        if not isinstance(input, Number):
+            flag = False
+            break
+    return flag
+
+def numeric(word):
+    # Tests input string is numeric data
+    parts = word.split(" ")
+    try:
+        map(float, parts)
+        flag = True
+    except ValueError:
+        flag = False
+    return flag
+
+def logical(word):
+    # Tests input string is numeric data
+    if word.upper() in [".FALSE.", ".TRUE."]:
+        flag = True
+    else:
+        flag = False
+    return flag
+
+def listed(word):
+    # Tests input string is not a list
+    if ("," in word) or (" " in word):
+        flag = True
+    else:
+        flag = False
+    return flag
+
+def quote(word):
+    word = str(word)
+    if not quoted(word):
+        word = "'%s'" % (word,)
+    return word
+
+def convert(word):
+    # Conversion function
+    if isinstance(word, str):
+        if (quoted(word) or numeric(word) 
+            or logical(word) or listed(word)):
+            result = "%s" % (word,)
+        else:
+            result = quote(word)
+    elif isinstance(word, bool):
+        if word:
+            result = ".TRUE."
+        else:
+            result = ".FALSE."
+    else:
+        result = str(word)
+    return result
+
+def quoted(word):
+    # Checks if string begins/ends with quotation marks
+    if (word.startswith("'") and word.endswith("'")):
+        flag = True
+    elif (word.startswith('"') and word.endswith('"')):
+        flag = True
+    else: 
+        flag = False
+    return flag
+
+def same_type(data):
+    # True if all entries are the same type
+    types = map(type, data)
+    if len(set(types)) == 1:
+        flag = True
+    else:
+        flag = False
+    return flag
+
+def sanitize(data):
+    """Converts dictionary values into Fortran namelist format.
+
+    This is a more typical way to prepare data for inclusion in
+    a Fortran namelist. Instead of manually applying :func:`tostring`
+    to every element of the input data, **sanitize** fixes the entire
+    data set.
+
+    >>> sanitize({"x": True})
+    {'x': '.TRUE.'}
+    >>> 
+
+    :param data: Dictionary to convert
+
+    :returns: Dictionary whose values are in Fortran namelist format
+
+    .. seealso:: :func:`tostring`
+    """
+    replacements = [(k, tostring(v)) for k, v in data.items()]
+    data.update(replacements)
+    return data
+
+def new(namid, data=None, convert=True):
+    """Creates a new Fortran namelist
+
+    >>> new("namobs")
+    '&namobs\\n/\\n'
+    >>> print new("namobs")
+    &namobs
+    /
+    <BLANKLINE>
+
+    :param namid: Name for the new namelist
+
+    :keyword data: Specifies an initial dictionary with which to
+                   populate the namelist
+    :type data: dict
+    :keyword convert: Sanitizes input data before replacement takes place
+
+    :returns: string representation of a Fortran namelist
+    """
+    text = "&{namid}\n/\n".format(namid=namid)
+    if data is not None:
+        text = update(namid, text, data, convert=convert)
+    return text
+
+if __name__ == '__main__':
+    import doctest
+    doctest.testmod()
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/ooo.py
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/ooo.py	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/ooo.py	(revision 4245)
@@ -0,0 +1,124 @@
+#!/usr/bin/env python2.7
+
+import os
+import shutil
+
+# Local imports
+import locator
+import nml
+import run
+
+def parse_args():
+    import argparse
+    parser = argparse.ArgumentParser()
+    parser.add_argument("date", metavar="DATE", 
+                        help="Run date.")
+    parser.add_argument("-w", "--work-dir", default=os.getcwd())
+    parser.add_argument("-f", "--forecast-types", default="forecast",
+                        help="Choice of forecast,persistence,climatology")
+    parser.add_argument("-l", "--lead-times", default="12",
+                        help="Forecast lead times")
+    parser.add_argument("-o", "--obs-types", default="profbfiles",
+                        help="Choice of namobs types.")
+    parser.add_argument("--class4", dest="ln_cl4", action="store_true",
+                        help="Flag to choose class 4 file outputs")
+    parser.add_argument("--dry-run", action="store_true",
+                        help="Flag to test namelist building without submitting.")
+    parser.add_argument("--cmd", dest="command", default="./opa",
+                        help="Submit task to run.")
+    parser.add_argument("-v", "--verbose", action="store_true",
+                        help="Prints difference between before and after namelists.")
+    parser.add_argument("namelist", metavar="NAMELIST", 
+                        help="NEMO namelist to edit.")
+    args = parser.parse_args()
+    args.forecast_types = args.forecast_types.split(',')
+    args.obs_types = args.obs_types.split(',')
+    args.lead_times = map(int, args.lead_times.split(','))
+    return args
+
+def printdiff(text1, text2):
+    # Provides nice text difference summary of namelists
+    import difflib
+    lines1 = text1.splitlines()
+    lines2 = text2.splitlines()
+    d = difflib.Differ()
+    result = list(d.compare(lines1, lines2))
+    text = '\n'.join(result)
+    print text
+
+def main():
+    args = parse_args()
+    date = args.date
+    print "Processing", args.namelist, " for", args.date
+    
+    # Move to working directory
+    if not os.path.exists(args.work_dir):
+        os.makedirs(args.work_dir)
+    os.chdir(args.work_dir)
+
+    # Collect forecast files
+    types = args.forecast_types
+    lead_times = args.lead_times
+    namooo, namcl4 = locator.forecasts(date=date,
+                                       types=types,
+                                       lead_times=lead_times)
+
+    # Process NEMO namelist
+    text = nml.reader(args.namelist)
+    sublists = nml.namelists(text)
+
+    # Verbose save original text
+    if args.verbose:
+        original_text = text
+
+    # namooo
+    if "namooo" not in sublists:
+        # Attach boilerplate
+        text += nml.new("namooo")
+    text = nml.update("namooo", text, data=namooo)
+
+    # namcl4
+    if "namcl4" not in sublists:
+        # Attach boilerplate
+        text += nml.new("namcl4")
+    namcl4["cl4_leadtime"] = lead_times
+    namcl4["cl4_date"] = nml.quote(date)
+    namcl4["cl4_match_len"] = len(namcl4["cl4_vars"])
+    namcl4["cl4_fcst_len"] = len(namcl4["cl4_leadtime"])
+    # Add naming convention
+    namcl4["cl4_sys"] = "FOAM"
+    namcl4["cl4_cfg"] = "orca025"
+    namcl4["cl4_vn"] = "'1.0'"
+    namcl4["cl4_prefix"] = "class4"
+    namcl4["cl4_contact"] = "example@example.com"
+    namcl4["cl4_inst"] = "institute"
+    text = nml.update("namcl4", text, data=namcl4)
+
+    # namrun
+    namrun = {"nn_date0": nml.quote(date)}
+    text = nml.update("namrun", text, data=namrun)
+
+    # namobs
+    namobs = locator.observations(date=date,
+                                  types=args.obs_types)
+    namobs["ln_cl4"] = args.ln_cl4
+    text = nml.update("namobs", text, data=namobs)
+
+    # Verbose print namelist differences
+    if args.verbose:
+        printdiff(original_text, text)
+
+    # pipe text to file
+    tmp = args.namelist+".tmp"
+    nml.writer(tmp, text)
+    shutil.move(tmp, args.namelist)
+
+    # Run job
+    if not args.dry_run:
+        run.submit(command=args.command)
+    
+
+
+if __name__ == '__main__':
+    main()
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/run.py
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/run.py	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/run.py	(revision 4245)
@@ -0,0 +1,27 @@
+"""
+
+The NEMO offline observation operator is built and runs similarly to the
+online NEMO model.
+ 
+"""
+import subprocess
+import shlex
+import os
+
+class SubmitError(Exception):
+    pass
+
+def submit(command="./opa"):
+    """Simple function that runs the code.
+
+    This can be customised based on the particular environment
+    used to submit MPI or serial tasks. For simplicity, this
+    function calls opa.
+
+    By default, this program runs ``./opa``.
+
+    :returns: retcode
+    """
+    retcode = subprocess.call(shlex.split(command))
+    return retcode
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/test_nml.py
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/test_nml.py	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/test_nml.py	(revision 4245)
@@ -0,0 +1,248 @@
+#!/usr/bin/env python2.7
+import unittest
+import nml
+
+def version(vn):
+    # Converts module version string to int tuple as PEP-440
+    return tuple(map(int, vn.split(".")))
+
+HEADER = """
+!! =====================================
+!! An example FORTRAN 90 namelist
+!! =====================================
+&namex
+"""
+NOHEADER = "&namex\n"
+LOGIC = " ln_test = .TRUE. ! Comment\n"
+NUMERIC = " nn_off_idx = 1 2 3\n"
+NOSPACE = " nn_off_idx=1 2 3\n"
+NEGATIVE = " nn_off_idx = -1 -2 -3\n"
+LIST = " off_files = 'a.nc' 'b.nc' 'c.nc' ! Comment\n"
+STRING = ' contact = "example@nowhere.com" ! Comment\n'
+COMMENT = ' ! x = y '
+FOOTER = "/\n"
+NOFOOTER = "/"
+
+class TestNamelist(unittest.TestCase):
+    def setUp(self):
+        self.logic_text = "\n".join([HEADER, LOGIC, FOOTER])
+        self.numeric_text = "\n".join([HEADER, NUMERIC, FOOTER])
+        self.nospace_text = "\n".join([HEADER, NOSPACE, FOOTER])
+        self.neg_numeric_text = "\n".join([HEADER, NEGATIVE, FOOTER])
+        self.list_text = "\n".join([HEADER, LIST, FOOTER])
+        self.mix_text = "\n".join([HEADER, LIST, NUMERIC, FOOTER])
+        self.string_text = "\n".join([HEADER, STRING, FOOTER])
+        self.comment_text = "\n".join([HEADER, COMMENT, FOOTER])
+        self.no_trail_text = "\n".join([HEADER, NUMERIC, LIST, NOFOOTER])
+
+    def test_should_handle_footer(self):
+        data = nml.variables(self.no_trail_text)
+        truth = {"nn_off_idx": "1 2 3",
+                 "off_files": "'a.nc' 'b.nc' 'c.nc'"}
+        self.assertDictEqual(data, truth)
+
+    def test_mix_data(self):
+        data = nml.variables(self.mix_text)
+        truth = {"nn_off_idx": "1 2 3",
+                 "off_files": "'a.nc' 'b.nc' 'c.nc'"}
+        self.assertDictEqual(data, truth)
+
+    def test_comment_data(self):
+        data = nml.variables(self.comment_text)
+        truth = {}
+        self.assertDictEqual(data, truth)
+
+    def test_logical_data(self):
+        data = nml.variables(self.logic_text)
+        truth = {"ln_test": ".TRUE."}
+        self.assertDictEqual(data, truth)
+
+    def test_numeric_data(self):
+        data = nml.variables(self.numeric_text)
+        truth = {"nn_off_idx": "1 2 3"}
+        self.assertDictEqual(data, truth)
+
+    def test_nospace_data(self):
+        data = nml.variables(self.nospace_text)
+        truth = {"nn_off_idx": "1 2 3"}
+        self.assertDictEqual(data, truth)
+
+    def test_negative_numeric_data(self):
+        data = nml.variables(self.neg_numeric_text)
+        truth = {"nn_off_idx": "-1 -2 -3"}
+        self.assertDictEqual(data, truth)
+
+    def test_string_data(self):
+        data = nml.variables(self.string_text)
+        truth = {"contact": '"example@nowhere.com"'}
+        self.assertDictEqual(data, truth)
+
+    def test_list_data(self):
+        data = nml.variables(self.list_text)
+        truth = {"off_files": "'a.nc' 'b.nc' 'c.nc'"}
+        self.assertDictEqual(data, truth)
+
+    def test_replace_variable_comment(self):
+        FIXTURE = " x = 'y' ! comment \n"
+        RESULT = " x = 'z' ! comment \n"
+        text = nml.replace(FIXTURE, {"x": "z"})
+        self.assertEqual(text, RESULT)
+
+    def test_replace_variable_no_comment(self):
+        FIXTURE = " x = 'y' \n"
+        RESULT = " x = 'z' \n"
+        text = nml.replace(FIXTURE, {"x": "z"})
+        self.assertEqual(text, RESULT)
+
+    def test_replace_variable_no_space(self):
+        FIXTURE = " x='y' \n"
+        RESULT = " x='z' \n"
+        text = nml.replace(FIXTURE, {"x": "z"})
+        self.assertEqual(text, RESULT)
+
+    def test_replace_variable_no_space_comment(self):
+        FIXTURE = " x='y' ! comment \n"
+        RESULT = " x='z' ! comment \n"
+        text = nml.replace(FIXTURE, {"x": "z"})
+        self.assertEqual(text, RESULT)
+
+    @unittest.skipIf(version(nml.__version__) < (1, 0),
+                     "Not implemented in this version")
+    def test_multiline_variable_replace(self):
+        # As a result of a code review
+        FIXTURE = " x = 1, \n     2"
+        RESULT =  " x = 3, \n     4"
+        text = nml.replace(FIXTURE, {"x": [3,4]})
+        self.assertEqual(text, RESULT)
+
+class TestCombinedNamelists(unittest.TestCase):
+    def setUp(self):
+        self.minimal = """&namone
+/"""
+        self.blanks = """
+&namone
+/
+&namtwo
+/
+"""
+        self.contents = """
+&namone
+Content 1
+/
+&namtwo
+Content 2
+/
+"""
+        self.contents_slash = """
+&namone
+Content 1 ! Y/N
+/
+&namtwo
+Content 2
+/
+"""
+    def test_should_select_name_from_minimal_namelist(self):
+        data = nml.namelists(self.minimal)
+        result = {"namone": "&namone\n/"}
+        self.assertDictEqual(data, result)
+
+    def test_should_select_names(self):
+        data = nml.namelists(self.blanks)
+        result = {"namone": "&namone\n/",
+                  "namtwo": "&namtwo\n/"}
+        self.assertDictEqual(data, result)
+
+    def test_should_select_contents(self):
+        data = nml.namelists(self.contents)
+        result = {"namone": "&namone\nContent 1\n/",
+                  "namtwo": "&namtwo\nContent 2\n/"}
+        self.assertDictEqual(data, result)
+
+    def test_should_select_contents_with_forward_slash(self):
+        data = nml.namelists(self.contents_slash)
+        result = {"namone": "&namone\nContent 1 ! Y/N\n/",
+                  "namtwo": "&namtwo\nContent 2\n/"}
+        self.assertDictEqual(data, result)
+
+
+class TestToString(unittest.TestCase):
+    def setUp(self):
+        self.char_list = ["a.nc", "b.nc", "c.nc"]
+        self.num_list = [1, 3, 7]
+        self.char = "foo@bar.com"
+        self.num = 10
+        self.mixed_list = ["foo.nc", -1, True]
+        self.mixed_str_list = map(nml.quote, ["foo.nc", "-1", ".TRUE."])
+
+    def test_should_format_mixed_list(self):
+        data = nml.tostring(self.mixed_list)
+        result = "'foo.nc', -1, .TRUE."
+        self.assertEqual(data, result)
+
+    def test_should_format_numeric_list(self):
+        data = nml.tostring(self.num_list)
+        result = "1 3 7"
+        self.assertEqual(data, result)
+
+    def test_should_format_character_list(self):
+        data = nml.tostring(self.char_list)
+        result = "'a.nc', 'b.nc', 'c.nc'"
+        self.assertEqual(data, result)
+
+    def test_should_format_strings(self):
+        data = nml.tostring(self.char)
+        result = "'%s'" % (self.char,)
+        self.assertEqual(data, result)
+
+    def test_should_format_numbers(self):
+        data = nml.tostring(self.num)
+        result = str(self.num)
+        self.assertEqual(data, result)
+
+    def test_should_not_format_numeric_string(self):
+        input = "3.14159"
+        self.assertEqual(nml.tostring(input), input)
+
+    def test_should_format_logicals(self):
+        data = nml.tostring(True)
+        result = ".TRUE."
+        self.assertEqual(data.upper(), result)
+
+    def test_should_not_format_string_of_list_data(self):
+        for input in ["1 2 3", "1, 2, 3", ".TRUE. .FALSE."]:
+            case = nml.tostring(input)
+            self.assertEqual(case, input)
+
+    def test_should_treat_mixed_numeric_character_data_as_character(self):
+        case = nml.tostring(self.mixed_str_list)
+        result = "'foo.nc', '-1', '.TRUE.'"
+        self.assertEqual(case, result)
+
+class TestUpdateNamelist(unittest.TestCase):
+    def setUp(self):
+        self.empty = """
+&namone
+/
+"""
+        self.single = """
+&namone
+   x = 'y'
+/
+"""
+        self.single_update = """
+&namone
+   x = 'z'
+/
+"""
+
+    def test_should_append_new_variable_to_namelist(self):
+        trial = nml.update("namone", self.empty, {"x": "'y'"})
+        self.assertEqual(trial, self.single)
+
+    def test_should_update_existing_variables(self):
+        trial = nml.update("namone", self.single, {"x": "'z'"})
+        self.assertEqual(trial, self.single_update)
+
+if __name__ == '__main__':
+    unittest.main()
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/setup.py
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/setup.py	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/setup.py	(revision 4245)
@@ -0,0 +1,9 @@
+from distutils.core import setup
+setup(name='Offline observation operator',
+      version='0.1',
+      description='NEMO Offline observation operator',
+      author='Andrew Ryan',
+      author_email='andrew.ryan@metoffice.gov.uk',
+      packages=['ooo',],
+      scripts=['bin/ooo'],
+      )
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/c4comb.F90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/c4comb.F90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/c4comb.F90	(revision 4245)
@@ -0,0 +1,702 @@
+PROGRAM c4comb
+   !!---------------------------------------------------------------------
+   !!
+   !!                     ** PROGRAM c4comb **
+   !!
+   !!  ** Purpose : Combine MPI decomposed class4 files into one file
+   !!
+   !!  ** Method  : Use of utilities from obs_utils, ooo_utils.
+   !!
+   !!  ** Action  : 
+   !!
+   !!   Usage:
+   !!     c4comb.exe outputfile inputfile1 inputfile2 ...
+   !!
+   !!   History :
+   !!----------------------------------------------------------------------
+   USE netcdf
+   USE obs_const
+   USE obs_utils
+   USE ooo_utils, ONLY: date_format, obfilldbl
+   USE toolspar_kind
+   IMPLICIT NONE
+   !! Command line setup
+#ifndef NOIARGCPROTO
+   INTEGER,EXTERNAL :: iargc
+#endif
+   INTEGER :: nargs,    & !: number of command line arguments
+            & ia,       & !: argument loop index
+            & ninfiles    !: number of input files
+   !! Routine arguments
+   CHARACTER(len=256) :: cdoutfile
+   CHARACTER(len=256),ALLOCATABLE :: cdinfile(:)
+   !! Routine variables
+   CHARACTER(len=80) :: cpname
+   INTEGER,PARAMETER :: nstr=8, n128=128
+   INTEGER           ::    ncid,   & !: netcdf file id
+                        &  dimid,  & !: netcdf dimension id
+                        &  dpdim,  & !: netcdf dimension ids
+                        &  fcdim,  &
+                        &  vrdim,  &
+                        &  obdim,  &
+                        &  stdim,  &
+                        &  sxdim,  &
+                        &  fdvid,  & !: netcdf variable ids
+                        &  lonid,  &
+                        &  latid,  &
+                        &  depid,  &
+                        &  varid,  &
+                        &  unitid, &
+                        &  obvid,  &
+                        &  fcvid,  &
+                        &  prvid,  &
+                        &  clvid,  &
+                        &  dm2id,  &
+                        &  dm1id,  &
+                        &  mdtid,  &
+                        &  altid,  &
+                        &  qcvid,  &
+                        &  jdvid,  &
+                        &  mjdid,  &
+                        &  typid,  &
+                        &  idvid,  &
+                        &  ndeps,  & !: number depths
+                        &  nfcst,  & !: number forecast
+                        &  nvars,  & !: number variables
+                        &  nobs,   & !: number obs
+                        &  sdeps,  &
+                        &  sobs,   &
+                        &  l_dex,  &
+                        &  u_dex
+
+   INTEGER                   :: iob, idep, istat
+   INTEGER, DIMENSION(2)     :: dim2a, dim2b, dim2c, dim2d
+   INTEGER, DIMENSION(3)     :: dim3a
+   INTEGER, DIMENSION(4)     :: dim4a
+   INTEGER,  ALLOCATABLE, DIMENSION(:)           :: fcday
+   REAL(wp), ALLOCATABLE, DIMENSION(:)           :: modjd
+   !: Global Attributes
+   CHARACTER(len=40)                             :: nam_str, &
+                                                 & version,  &
+                                                 & contact,  &
+                                                 & sys_str,  &
+                                                 & cfg_str,  &
+                                                 & ins_str,  &
+                                                 & val_str,  &
+                                                 & dat_str,  &
+                                                 & obs_str
+   !: Variable Attributes
+   CHARACTER(len=100)                            :: lon_units, &
+                                                 &  lat_units, &
+                                                 &  dep_units, &
+                                                 &  jul_units, &
+                                                 &  mjd_units, &
+                                                 &  fcd_units, &
+                                                 &  lead_comment, &
+                                                 &  fcst_comment, &
+                                                 &  per_comment,  &
+                                                 &  cli_comment,  &
+                                                 &  dm2_comment,  &
+                                                 &  dm1_comment
+   CHARACTER(len=128)                            :: qc_comment,   &
+                                                 &  qc_flag_meaning
+   INTEGER, DIMENSION(2)                         :: qc_flag_value
+
+   !: Global Arrays
+   REAL(wp), ALLOCATABLE, DIMENSION(:)           :: g_lam, &
+                                                 &  g_phi, & 
+                                                 &  gjuld 
+   CHARACTER(len=n128),ALLOCATABLE,DIMENSION(:)  :: gtype
+   CHARACTER(len=nstr),ALLOCATABLE,DIMENSION(:)  ::        &
+                                                 &  g_id,  & 
+                                                 &  gvnam, & 
+                                                 &  gunit
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:)         :: g_dep
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)       :: g3dob, &
+                                                 &  g3dcl, &
+                                                 &  g3mdt, &
+                                                 &  g3alt, &
+                                                 &  g3dm2, &
+                                                 &  g3dm1
+   INTEGER(ik),  ALLOCATABLE, DIMENSION(:,:,:)   :: g3dqc
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:)     :: g3dmc, &
+                                                 &  g3dpr
+   !: Small Arrays  
+   REAL(wp), ALLOCATABLE, DIMENSION(:)       ::     s_lam, &
+                                                 &  s_phi, & 
+                                                 &  sjuld
+
+   CHARACTER(len=n128),ALLOCATABLE,DIMENSION(:) ::  stype
+   CHARACTER(len=nstr),ALLOCATABLE,DIMENSION(:) ::        &
+                                                 &  s_id 
+
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:)        :: s_dep
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)      :: s3dob, &
+                                                &  s3dcl, &
+                                                &  s3mdt, &
+                                                &  s3alt, &
+                                                &  s3dm2, &
+                                                &  s3dm1
+   INTEGER(ik),  ALLOCATABLE, DIMENSION(:,:,:)  :: s3dqc
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:)    :: s3dmc, &
+                                                &  s3dpr
+
+   !: File creation logical
+   LOGICAL                                     :: ln_cre
+
+   !: Optional variable logicals
+   LOGICAL                                     :: ln_init, &
+                                                & ln_mdt,  &
+                                                & ln_altbias, &
+                                                & ln_best
+   !! Command name
+   cpname='c4comb.exe'
+
+   !! Process command line
+   nargs = IARGC()
+   IF (nargs /= 2) THEN
+      WRITE(*, *) "Usage: c4comb.exe outputfile inputfile1 inputfile2 ..."
+      CALL abort()
+   END IF
+   CALL GETARG(1, cdoutfile)
+
+   !! Process input files
+   !! Set output file creation to off
+   ln_cre = .false.
+
+   !! Turn optional variables off
+   ln_init = .false.
+   ln_best = .false.
+   ln_altbias = .false.
+   ln_mdt = .false.
+
+   !! Compute size of output file
+   nobs = 0
+   ndeps= 0
+   ALLOCATE( cdinfile( nargs - 1 ) )
+   ninfiles = nargs - 1
+   DO ia = 1, ninfiles
+      CALL GETARG(ia+1, cdinfile(ia))
+      WRITE(*,*) "Opening : ", TRIM(cdinfile(ia))
+      !! Open Netcdf file
+      istat = nf90_open(TRIM(cdinfile(ia)),nf90_nowrite,ncid)
+      IF (istat == nf90_noerr) THEN
+         !! Turn output file creation on
+         ln_cre = .true.
+         !! Get Dimensions
+         CALL chkerr( nf90_inq_dimid(ncid, 'numobs',  dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=sobs  ),  cpname, __LINE__ )
+         CALL chkerr( nf90_inq_dimid(ncid, 'numdeps', dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=sdeps ),  cpname, __LINE__ )
+         CALL chkerr( nf90_inq_dimid(ncid, 'numfcsts',dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=nfcst ),  cpname, __LINE__ )
+         CALL chkerr( nf90_inq_dimid(ncid, 'numvars', dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=nvars ),  cpname, __LINE__ )
+         !! Close Netcdf file
+         CALL chkerr( nf90_close(ncid), cpname, __LINE__ )
+         !! Report on file contents
+         WRITE(*,'(2A)')'File = ', TRIM(cdinfile(ia))
+         WRITE(*,'(A,I9,A)')'has', sobs, ' observations'
+         !! Increment size
+         nobs  = nobs + sobs       !: Accumulate number of profiles
+         ndeps = MAX(ndeps, sdeps) !: Define maximum number of levels needed
+      END IF ! istat
+   END DO
+
+   !! Allocate global arrays
+   ALLOCATE( g_phi(nobs),                      &
+          &  g_lam(nobs),                      &
+          &  g_dep(ndeps, nobs),               &
+          &  g3dob(ndeps,        nvars, nobs), &
+          &  g3dmc(ndeps, nfcst, nvars, nobs), &
+          &  g3dpr(ndeps, nfcst, nvars, nobs), &
+          &  g3dcl(ndeps,        nvars, nobs), &
+          &  g3dm2(ndeps,        nvars, nobs), &
+          &  g3dm1(ndeps,        nvars, nobs), &
+          &  g3mdt(ndeps,        nvars, nobs), &
+          &  g3alt(ndeps,        nvars, nobs), &
+          &  g3dqc(ndeps,        nvars, nobs), &
+          &  gjuld(nobs),                      &
+          &  gtype(nobs),                      &
+          &  g_id(nobs),                       &
+          &  gvnam(nvars),                     &
+          &  gunit(nvars) )
+   ALLOCATE(fcday(nfcst), modjd(nfcst))
+
+   !! Fill with missing data value
+   g_dep(:,:)     = 99999.
+   g3dmc(:,:,:,:) = 99999.
+   g3dpr(:,:,:,:) = 99999.
+   g3dob(:,:,:)   = 99999.
+   g3dcl(:,:,:)   = 99999.
+   g3dm2(:,:,:)   = 99999.
+   g3dm1(:,:,:)   = 99999.
+   g3mdt(:,:,:)   = 99999.
+   g3alt(:,:,:)   = 99999.
+   g3dqc(:,:,:)   = NF90_FILL_SHORT
+
+   !! Read in each file
+   !  initialise global matrix indices
+   l_dex = 0
+   u_dex = 0
+
+   !! initialise Global attribute strings
+   nam_str = ''
+   version = ''
+   contact = ''
+   sys_str = ''
+   cfg_str = ''
+   ins_str = ''
+   val_str = ''
+   dat_str = ''
+   obs_str = ''
+
+   !! initialise Variable attribute strings
+   fcd_units = ''
+   lon_units = ''
+   lat_units = ''
+   dep_units = ''
+   jul_units = ''
+   mjd_units = ''
+   lead_comment = ''
+   fcst_comment = ''
+   per_comment  = ''
+   cli_comment  = ''
+   dm2_comment  = ''
+   dm1_comment  = ''
+   qc_comment  = ''
+   qc_flag_meaning  = ''
+
+   DO ia = 1, ninfiles
+      WRITE(*,*) "Opening : ", TRIM(cdinfile(ia))
+      !! Open Netcdf file
+      istat = nf90_open(TRIM(cdinfile(ia)),nf90_nowrite,ncid)
+      IF (istat == nf90_noerr) THEN
+         !! Get Global Attributes
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'title',         nam_str),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'version',       version),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'contact',       contact),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'obs_type',      obs_str),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'system',        sys_str),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'configuration', cfg_str),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'institution',   ins_str),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'validity_time', val_str),cpname, __LINE__)
+         !! Get Dimensions of single file
+         CALL chkerr( nf90_inq_dimid(ncid, 'numdeps', dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=sdeps ),  cpname, __LINE__ )
+         CALL chkerr( nf90_inq_dimid(ncid, 'numfcsts',dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=nfcst ),  cpname, __LINE__ )
+         CALL chkerr( nf90_inq_dimid(ncid, 'numvars', dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=nvars ),  cpname, __LINE__ )
+         CALL chkerr( nf90_inq_dimid(ncid, 'numobs',  dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=sobs  ),  cpname, __LINE__ )
+         !! Check for Optional variables in first file
+         IF (ia == 1) THEN
+            !! Best estimate
+            istat = nf90_inq_varid(ncid,'best_estimate',dm2id)
+            IF (istat == nf90_noerr) THEN
+               ln_best = .TRUE.
+            ENDIF 
+            !! nrt_analysis
+            istat = nf90_inq_varid(ncid,'nrt_analysis',dm1id)
+            IF (istat == nf90_noerr) THEN
+               ln_init = .TRUE.
+            ENDIF 
+            !! Mean Dynamic Topography
+            istat = nf90_inq_varid(ncid,'mdt_reference',mdtid)
+            IF (istat == nf90_noerr) THEN
+               ln_mdt = .TRUE.
+            ENDIF 
+            !! Altimeter bias
+            istat = nf90_inq_varid(ncid,'altimeter_bias',altid)
+            IF (istat == nf90_noerr) THEN
+               ln_altbias = .TRUE.
+            ENDIF 
+         END IF
+         WRITE(*,*) TRIM(cdinfile(ia)), " contains ", sobs, " observations"
+         WRITE(*,*) TRIM(cdinfile(ia)), " contains ", sdeps, " depths"
+         WRITE(*,*) TRIM(cdinfile(ia)), " contains ", nfcst, " forecasts"
+         WRITE(*,*) TRIM(cdinfile(ia)), " contains ", nvars, " vars"
+         !! Read Variables
+         IF (sobs /= 0) THEN
+            !! Get Variable ids
+            CALL chkerr(nf90_inq_varid(ncid,'leadtime', fdvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'longitude',   lonid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'latitude',    latid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'depth',       depid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'varname',     varid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'unitname',   unitid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'observation', obvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'forecast',    fcvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'persistence', prvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'climatology', clvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'qc',          qcvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'juld',        jdvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'modeljuld',   mjdid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'type',        typid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'id',          idvid) ,cpname, __LINE__ )
+            !! Get variable attributes
+            CALL chkerr(nf90_get_att(ncid, fdvid, 'units', fcd_units) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, lonid, 'units', lon_units) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, latid, 'units', lat_units) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, depid, 'units', dep_units) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, jdvid, 'units', jul_units) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, mjdid, 'units', mjd_units) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, fcvid, 'comment', fcst_comment) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, prvid, 'comment', per_comment)  ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, clvid, 'comment', cli_comment)  ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, fdvid, 'comment', lead_comment) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, qcvid, 'comment', qc_comment) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, qcvid, 'flag_value', qc_flag_value) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, qcvid, 'flag_meaning', qc_flag_meaning) ,cpname, __LINE__ )
+            !! Optional variables
+            IF (ln_best) THEN
+               CALL chkerr(nf90_inq_varid(ncid,'best_estimate',dm2id) ,cpname, __LINE__ )
+               CALL chkerr(nf90_get_att(ncid, dm2id, 'comment', dm2_comment)  ,cpname, __LINE__ )
+            ENDIF
+            IF (ln_init) THEN
+               CALL chkerr(nf90_inq_varid(ncid,'nrt_analysis', dm1id) ,cpname, __LINE__ )
+               CALL chkerr(nf90_get_att(ncid, dm1id, 'comment', dm1_comment)  ,cpname, __LINE__ )
+            ENDIF
+            IF (ln_mdt) THEN
+               CALL chkerr(nf90_inq_varid(ncid,'mdt_reference', mdtid) ,cpname, __LINE__ )
+            ENDIF
+            IF (ln_altbias) THEN
+               CALL chkerr(nf90_inq_varid(ncid,'altimeter_bias', altid) ,cpname, __LINE__ )
+            ENDIF
+
+            !! Allocate small arrays
+            ALLOCATE( s_lam(sobs), s_phi(sobs),  s_dep(sdeps, sobs),               &
+                   &  s3dob(sdeps,        nvars, sobs), & !: observations 
+                   &  s3dmc(sdeps, nfcst, nvars, sobs), & !: model data
+                   &  s3dpr(sdeps, nfcst, nvars, sobs), & !: persistence
+                   &  s3dcl(sdeps,        nvars, sobs), & !: climatology
+                   &  s3dm2(sdeps,        nvars, sobs), & !: best estimate
+                   &  s3dm1(sdeps,        nvars, sobs), & !: nrt_analysis
+                   &  s3mdt(sdeps,        nvars, sobs), & !: mdt
+                   &  s3alt(sdeps,        nvars, sobs), & !: altbias
+                   &  s3dqc(sdeps,        nvars, sobs), & !: QC
+                   &  sjuld(sobs), stype( sobs),  &
+                   &  s_id(sobs) )
+            !! Fill with missing data value
+            s3dmc(:,:,:,:) = 99999.
+            s3dpr(:,:,:,:) = 99999.
+            s3dob(:,:,:)   = 99999.
+            s3dcl(:,:,:)   = 99999.
+            s3dm2(:,:,:)   = 99999.
+            s3dm1(:,:,:)   = 99999.
+            s3mdt(:,:,:)   = 99999.
+            s3alt(:,:,:)   = 99999.
+            s3dqc(:,:,:)   = NF90_FILL_SHORT
+
+            !! Read variables into small arrays
+            CALL chkerr( nf90_get_var(ncid, fdvid, fcday), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, lonid, s_lam), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, latid, s_phi), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, depid, s_dep), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, obvid, s3dob), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, fcvid, s3dmc), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, prvid, s3dpr), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, clvid, s3dcl), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, qcvid, s3dqc), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, jdvid, sjuld), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, mjdid, modjd), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, typid, stype), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, idvid, s_id),  cpname, __LINE__ )       
+            !! Read unitname and varname into global arrays
+            CALL chkerr( nf90_get_var(ncid, varid, gvnam), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, unitid,gunit), cpname, __LINE__ )       
+            !! Optional variables read
+            IF (ln_best) THEN
+               CALL chkerr( nf90_get_var(ncid, dm2id, s3dm2), cpname, __LINE__ )       
+            ENDIF
+            IF (ln_init) THEN
+               CALL chkerr( nf90_get_var(ncid, dm1id, s3dm1), cpname, __LINE__ )       
+            ENDIF
+            IF (ln_mdt) THEN
+               CALL chkerr( nf90_get_var(ncid, mdtid, s3mdt), cpname, __LINE__ )       
+            ENDIF
+            IF (ln_altbias) THEN
+               CALL chkerr( nf90_get_var(ncid, altid, s3alt), cpname, __LINE__ )       
+            ENDIF
+
+            !! Fill Global arrays
+            !  increment numobs indices
+            l_dex = u_dex + 1
+            u_dex = l_dex + sobs -1
+
+            g_lam(l_dex:u_dex)                          = s_lam(:)
+            g_phi(l_dex:u_dex)                          = s_phi(:)
+            g_dep(1:sdeps,  l_dex:u_dex)                = s_dep(1:sdeps,:)
+            g3dob(1:sdeps,1:nvars,l_dex:u_dex)          = s3dob(1:sdeps,1:nvars,:)
+            g3dmc(1:sdeps,1:nfcst,1:nvars,l_dex:u_dex)  = s3dmc(1:sdeps,1:nfcst,1:nvars,:)
+            g3dpr(1:sdeps,1:nfcst,1:nvars,l_dex:u_dex)  = s3dpr(1:sdeps,1:nfcst,1:nvars,:)
+            g3dcl(1:sdeps,1:nvars,l_dex:u_dex)          = s3dcl(1:sdeps,1:nvars,:)
+            g3dm2(1:sdeps,1:nvars,l_dex:u_dex)          = s3dm2(1:sdeps,1:nvars,:)
+            g3dm1(1:sdeps,1:nvars,l_dex:u_dex)          = s3dm1(1:sdeps,1:nvars,:)
+            g3mdt(1:sdeps,1:nvars,l_dex:u_dex)          = s3mdt(1:sdeps,1:nvars,:)
+            g3alt(1:sdeps,1:nvars,l_dex:u_dex)          = s3alt(1:sdeps,1:nvars,:)
+            g3dqc(1:sdeps,1:nvars,l_dex:u_dex)          = s3dqc(1:sdeps,1:nvars,:)
+            gjuld(l_dex:u_dex)                          = sjuld(:)
+            gtype(l_dex:u_dex)                          = stype(:)
+            g_id(l_dex:u_dex)                           = s_id(:)
+
+            !! Deallocate small array
+            DEALLOCATE( s_lam, s_phi, s_dep, s3dob, s3dmc, s3dpr, s3dcl, s3dqc, s3dm2, s3dm1, s3mdt, s3alt, sjuld, stype, s_id)
+         ENDIF ! sobs    
+         !! Close Netcdf file
+         CALL chkerr( nf90_close(ncid), cpname, __LINE__ )
+      END IF ! istat
+   END DO
+
+   !! Create Output file
+   IF (ln_cre) THEN
+      WRITE(*,*) 'Create the output file, ',trim(cdoutfile)
+      CALL chkerr( nf90_create(trim(cdoutfile),nf90_clobber,ncid),      cpname, __LINE__ )
+      !! Put Global Attributes
+      CALL date_format(dat_str) 
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'title',          trim(nam_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'version',        trim(version)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'creation_date',  trim(dat_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'contact',        trim(contact)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'obs_type',       trim(obs_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'system',         trim(sys_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'configuration',  trim(cfg_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'institution',    trim(ins_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'validity_time',  trim(val_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'best_estimate_description', &
+                              &       'analysis produced 2 days behind real time'),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'time_interp', 'daily average fields'),cpname, __LINE__)
+      WRITE(*,*) 'Succesfully put global attributes '
+
+      !! Define Dimensions
+      CALL chkerr( nf90_def_dim(ncid, 'numdeps',          ndeps, dpdim) ,cpname, __LINE__ )
+      CALL chkerr( nf90_def_dim(ncid, 'numfcsts',         nfcst, fcdim) ,cpname, __LINE__ )
+      CALL chkerr( nf90_def_dim(ncid, 'numvars',          nvars, vrdim) ,cpname, __LINE__ )
+      CALL chkerr( nf90_def_dim(ncid, 'numobs',           nobs,  obdim) ,cpname, __LINE__ )
+      CALL chkerr( nf90_def_dim(ncid, 'string_length8',   nstr,  stdim) ,cpname, __LINE__ )
+      CALL chkerr( nf90_def_dim(ncid, 'string_length128', n128,  sxdim) ,cpname, __LINE__ )
+      WRITE(*,*) 'Succesfully defined dimensions'
+
+      !! Define possible dimension permutations
+      ! 2d
+      dim2a(:) = (/ dpdim, obdim /) !: (/ ndeps, nobs  /) 
+      dim2b(:) = (/ stdim, obdim /) !: (/ nstr,  nobs  /)
+      dim2c(:) = (/ stdim, vrdim /) !: (/ nstr,  nvars /)
+      dim2d(:) = (/ sxdim, obdim /) !: (/ nstr,  nobs  /)
+      ! 3d
+      dim3a(:) = (/ dpdim, vrdim, obdim/) !: (/ ndeps, nvars, nobs /)
+      ! 4d
+      dim4a(:) = (/ dpdim, fcdim, vrdim, obdim /) !: (/ ndeps, nfcst, nvars, nobs /)
+
+
+      !! Create the variables
+      !  Forecast day
+      CALL chkerr( nf90_def_var(ncid, 'leadtime',  nf90_double, fcdim, fdvid)          ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, fdvid, 'long_name', 'Model forecast day offset') ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, fdvid, 'units',     trim(fcd_units))             ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, fdvid, 'comment',   trim(lead_comment))          ,cpname, __LINE__ )
+      WRITE(*,*) 'leadtime created'
+      !  longitude
+      CALL chkerr( nf90_def_var(ncid, 'longitude',    nf90_float, obdim, lonid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, lonid, 'long_name', 'Longitudes')                ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, lonid, 'units',     trim(lon_units))             ,cpname, __LINE__ )
+      WRITE(*,*) 'lon created'
+      !  latitude
+      CALL chkerr( nf90_def_var(ncid, 'latitude',     nf90_float, obdim, latid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, latid, 'long_name', 'Latitudes')                 ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, latid, 'units',     trim(lat_units))             ,cpname, __LINE__ )
+      WRITE(*,*) 'lat created'
+      !  depth
+      CALL chkerr( nf90_def_var(ncid, 'depth',        nf90_float, dim2a, depid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, depid, 'long_name', 'Depths')                    ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, depid, 'units',     trim(dep_units))             ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, depid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+      WRITE(*,*) 'dep created'
+      !  varname
+      CALL chkerr( nf90_def_var(ncid, 'varname',      nf90_char,  dim2c, varid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, varid, 'long_name', 'Variable name')             ,cpname, __LINE__ )
+      WRITE(*,*) 'varname created'
+      !  unitname
+      CALL chkerr( nf90_def_var(ncid, 'unitname',     nf90_char,  dim2c, unitid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid,  unitid, 'long_name', 'Unit name')              ,cpname, __LINE__ )
+      WRITE(*,*) 'unitname created'
+      !  obs
+      CALL chkerr( nf90_def_var(ncid, 'observation', nf90_float,  dim3a,  obvid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, obvid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid,  obvid, 'long_name', 'Observation value')         ,cpname, __LINE__ )
+      WRITE(*,*) 'obs created'
+      !  forecast
+      CALL chkerr( nf90_def_var(ncid, 'forecast',    nf90_float,  dim4a,  fcvid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, fcvid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, fcvid, 'long_name', 'Model forecast counterpart of obs. value')   ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, fcvid, 'comment',   trim(fcst_comment))           ,cpname, __LINE__ )
+      WRITE(*,*) 'forecast created'
+      !  persistence
+      CALL chkerr( nf90_def_var(ncid, 'persistence', nf90_float,  dim4a,  prvid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, prvid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, prvid, 'long_name', 'Model persistence counterpart of obs. value'),cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, prvid, 'comment',   trim(per_comment))            ,cpname, __LINE__ )
+      WRITE(*,*) 'persistence created'
+      !  clim
+      CALL chkerr( nf90_def_var(ncid, 'climatology', nf90_float,  dim3a, clvid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, clvid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, clvid, 'long_name', 'Climatological value')       ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, clvid, 'comment',   trim(cli_comment))            ,cpname, __LINE__ )
+      WRITE(*,*) 'clim created'
+      IF (ln_best) THEN
+         !  daym2
+         CALL chkerr( nf90_def_var(ncid, 'best_estimate', nf90_float,  dim3a, dm2id)    ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, dm2id, '_FillValue',obfillflt)                 ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, dm2id, 'long_name', 'Best estimate')           ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, dm2id, 'comment',   trim(dm2_comment))         ,cpname, __LINE__ )
+         WRITE(*,*) 'daym2 created'
+      ENDIF
+      IF (ln_init) THEN
+         !  daym1
+         CALL chkerr( nf90_def_var(ncid, 'nrt_analysis', nf90_float,  dim3a, dm1id)        ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, dm1id, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, dm1id, 'long_name', 'Near real time analysis')    ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, dm1id, 'comment',   trim(dm1_comment))            ,cpname, __LINE__ )
+         WRITE(*,*) 'daym1 created'
+      ENDIF
+      IF (ln_mdt) THEN
+         !  mdt
+         CALL chkerr( nf90_def_var(ncid, 'mdt_reference', nf90_float,  dim3a, mdtid)      ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, mdtid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, mdtid, 'long_name', 'Mean dynamic topography')    ,cpname, __LINE__ )
+         WRITE(*,*) 'mdt created'
+      ENDIF
+      IF (ln_altbias) THEN
+         !  altbias
+         CALL chkerr( nf90_def_var(ncid, 'altimeter_bias', nf90_float,  dim3a, altid)     ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, altid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, altid, 'long_name', 'Altimeter bias')             ,cpname, __LINE__ )
+         WRITE(*,*) 'altbias created'
+      ENDIF
+      !  qc
+      CALL chkerr( nf90_def_var(ncid, 'qc',          nf90_short,  dim3a, qcvid)         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, qcvid, '_FillValue', NF90_FILL_SHORT)             ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, qcvid, 'long_name', 'Quality flags')              ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, qcvid, 'flag_value', qc_flag_value)               ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, qcvid, 'flag_meaning', qc_flag_meaning)           ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, qcvid, 'comment', qc_comment)                     ,cpname, __LINE__ )
+      WRITE(*,*) 'qc created'
+      !  juld
+      CALL chkerr( nf90_def_var(ncid, 'juld',       nf90_double,  obdim, jdvid)         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, jdvid, '_FillValue',99999.)                       ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, jdvid, 'long_name', 'Observation time in Julian days'),cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, jdvid, 'units',     trim(jul_units))              ,cpname, __LINE__ )
+      WRITE(*,*) 'juld created'
+      !  modeljuld 
+      CALL chkerr( nf90_def_var(ncid, 'modeljuld',  nf90_double,  fcdim, mjdid)         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, mjdid, 'long_name', 'Model field date in Julian days'),cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, mjdid, 'units',     trim(mjd_units))              ,cpname, __LINE__ )
+      WRITE(*,*) 'modeljuld created'
+      !  type
+      CALL chkerr( nf90_def_var(ncid, 'type',     nf90_char,      dim2d, typid)         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, typid, 'long_name', 'Observation type')           ,cpname, __LINE__ )
+      WRITE(*,*) 'type created'
+      !  id
+      CALL chkerr( nf90_def_var(ncid, 'id',       nf90_char,      dim2b, idvid)         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, idvid, 'long_name', 'Observation id')             ,cpname, __LINE__ )
+      WRITE(*,*) 'id created'
+      ! Close Netcdf file 
+      CALL chkerr( nf90_close(ncid) ,cpname, __LINE__ )  
+      !! Fill in the variables
+      CALL chkerr( nf90_open(trim(cdoutfile),nf90_write,ncid),                   cpname, __LINE__ )
+      WRITE(*,*) 'Create the variables ',trim(cdoutfile)
+      !  Forecast day
+      CALL chkerr( nf90_inq_varid(ncid, 'leadtime', fdvid)                ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, fdvid, fcday) ,cpname, __LINE__ )
+      WRITE(*,*) 'forecast day put'
+      !  longitude
+      CALL chkerr( nf90_inq_varid(ncid, 'longitude', lonid)                  ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, lonid, g_lam) ,cpname, __LINE__ )
+      WRITE(*,*) 'lon put'
+      !  latitude
+      CALL chkerr( nf90_inq_varid(ncid, 'latitude', latid)                   ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, latid, g_phi) ,cpname, __LINE__ )
+      WRITE(*,*) 'lat put'
+      !  depth
+      CALL chkerr( nf90_inq_varid(ncid, 'depth',depid)                       ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, depid, g_dep) ,cpname, __LINE__ )
+      WRITE(*,*) 'dep put'
+      ! varname
+      CALL chkerr( nf90_inq_varid(ncid, 'varname', varid)                    ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, varid, gvnam,(/1,1/), (/nstr,nvars/) ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'var put'
+      ! unitname
+      CALL chkerr( nf90_inq_varid(ncid, 'unitname',unitid)                   ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, unitid, gunit,(/1,1/),(/nstr,nvars/) ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'unitnam put'
+      ! obs
+      CALL chkerr( nf90_inq_varid(ncid, 'observation', obvid)                ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, obvid,g3dob ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'obs put'
+      ! clim
+      CALL chkerr( nf90_inq_varid(ncid, 'climatology', clvid)                ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, clvid,g3dcl ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'cli put'
+      IF (ln_best) THEN
+         ! daym2
+         CALL chkerr( nf90_inq_varid(ncid, 'best_estimate',dm2id)            ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_var(ncid, dm2id,g3dm2 ) ,cpname, __LINE__ )   
+         WRITE(*,*) 'daym2 put'
+      ENDIF
+      IF (ln_init) THEN 
+         ! daym1
+         CALL chkerr( nf90_inq_varid(ncid, 'nrt_analysis',dm1id)              ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_var(ncid, dm1id,g3dm1 ) ,cpname, __LINE__ )   
+         WRITE(*,*) 'daym1 put'
+      ENDIF
+      IF (ln_mdt) THEN 
+         ! mdt
+         CALL chkerr( nf90_inq_varid(ncid, 'mdt_reference', mdtid)              ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_var(ncid, mdtid, g3mdt ) ,cpname, __LINE__ )   
+         WRITE(*,*) 'mdt put'
+      ENDIF
+      IF (ln_altbias) THEN 
+         ! altbias
+         CALL chkerr( nf90_inq_varid(ncid, 'altimeter_bias', altid)             ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_var(ncid, altid, g3alt ) ,cpname, __LINE__ )   
+         WRITE(*,*) 'altbias put'
+      ENDIF
+      ! persistence
+      CALL chkerr( nf90_inq_varid(ncid, 'persistence',prvid)                                 ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, prvid, g3dpr, (/1,1,1,1/) ,(/ ndeps,nfcst,nvars,nobs/) ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'per put'
+      ! forecast
+      CALL chkerr( nf90_inq_varid(ncid, 'forecast',fcvid)                                      ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, fcvid, g3dmc, (/1,1,1,1/), (/ ndeps,nfcst,nvars,nobs/) ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'fcst put'
+      ! qc
+      CALL chkerr( nf90_inq_varid(ncid, 'qc', qcvid)                         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, qcvid,g3dqc ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'qc put'
+      ! juld
+      CALL chkerr( nf90_inq_varid(ncid, 'juld',jdvid)                        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, jdvid, gjuld) ,cpname, __LINE__ )   
+      WRITE(*,*) 'juld put'
+      ! modeljuld
+      CALL chkerr( nf90_inq_varid(ncid, 'modeljuld', mjdid)                  ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, mjdid, modjd,(/1/),(/nfcst/))          ,cpname, __LINE__ )   
+      WRITE(*,*) 'modjuld put'
+      ! type
+      CALL chkerr( nf90_inq_varid(ncid, 'type', typid)                       ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, typid, gtype,(/1,1/) , (/n128,nobs/) ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'type put'
+      ! id
+      CALL chkerr( nf90_inq_varid(ncid, 'id', idvid)                         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, idvid, g_id,(/1,1/)  , (/nstr,nobs/) ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'id put'
+      ! Close netcdf file
+      CALL chkerr( nf90_close(ncid),                                          cpname, __LINE__ )
+   END IF ! ln_cre
+   !! Deallocate Global arrays
+   DEALLOCATE( g_lam, g_phi, g_dep, g3dob, g3dmc, g3dpr, g3dcl, g3dm2, g3dm1, g3mdt, g3alt, g3dqc, gjuld, gtype, g_id, gvnam, gunit)
+   DEALLOCATE( fcday, modjd )
+
+   !! Deallocate input argument list
+   DEALLOCATE(cdinfile)
+END PROGRAM c4comb
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/obs_const.F90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/obs_const.F90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/obs_const.F90	(revision 4245)
@@ -0,0 +1,1 @@
+link ../../../NEMO/OPA_SRC/OBS/obs_const.F90
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/ooo_utils.F90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/ooo_utils.F90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/ooo_utils.F90	(revision 4245)
@@ -0,0 +1,1 @@
+link ../../../NEMO/OOO_SRC/ooo_utils.F90
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/README
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/README	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/README	(revision 4245)
@@ -0,0 +1,46 @@
+ This is a first draft of the CONFIGURATION MANAGER demonstrator.
+ Unfortunately, there are still bugs in those tools.
+ I will continue to work on it next year, to fix those bugs and add some
+ improvement as handle north fold...
+
+ '''WARNING : there are still bugs to fix in those tools!! '''
+
+   ''''''
+
+ 1- program to create coordinate file :
+
+   ./create_coord create_coord.nam
+
+
+ Variables are extracted from the input coordinates coarse grid and
+ interpolated to create fine coordinates files.
+
+ 2- program to create bathymetry file:
+
+ ./create_bathy create_bathy.nam
+
+ Bathymetry could be extracted from fine grid Bathymetry file, or
+ interpolated from coarse grid Bathymetry file.
+
+ 3- program to merge bathymetry file at boundaries :
+
+ ./merge_bathy merge_bathy.nam
+
+ Coarse grid Bathymetry is interpolated on fine grid.
+ Then fine Bathymetry and refined coarse bathymetry are merged at
+ boundaries.
+
+ 4- program to create restart file :
+
+ ./create_restart create_restart.nam
+
+ Variables are read from restart file, or standard output.
+ Then theses variables are interpolated on fine grid.
+ Finally table are split over new decomposition.
+
+ 5- program to create boundary files (OBC) :
+
+ ./create_boundary create_boundary.nam
+
+ Variables are read from standard output.
+ Then theses variables are interpolated on fine grid boundaries.
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/cfg/variable.cfg
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/cfg/variable.cfg	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/cfg/variable.cfg	(revision 4245)
@@ -0,0 +1,37 @@
+# name       | units          | axis | point | standard name               | long name          | interpolation
+X            | 1              | X    |   | projection_x_coordinate         |                    |                      
+Y            | 1              | Y    |   | projection_y_coordinate         |                    |                      
+Z            | 1              | Z    |   | projection_z_coordinate         |                    |                      
+T            | 1              | T    |   | projection_t_coordinate         |                    |                      
+nav_lon      | degrees_east   | XY   | T | longitude                       | Longitude          | cubic                      
+nav_lat      | degrees_north  | XY   | T | latitude                        | Latitude           | cubic         
+nav_lev      | model_levels   | Z    | T |                                 | Model levels       | cubic        
+deptht       | m              | Z    | T | depth                           | Vertical T levels  |
+time_counter |                | T    |   | time                            | Time axis          | 
+Bathymetry   | m              | XY   | T | bathymetry                      | Bathymetry         | cubic         
+votemper     | degree_Celsius | XYZT | T | sea_water_potential_temperature | Temperature        | cubic         
+vozocrtx     | m s-1          | XYZT | U |                                 | Zonal velocity     | cubic         
+vomecrty     | m s-1          | XYZT | V |                                 | Meridional velocity| cubic         
+vosaline     | PSU            | XYZT | T | sea_water_salinity              | Salinity           | cubic         
+sossheig     | m              | XYT  | T | sea_surface_height              | Sea Surface Height | cubic         
+glamt        | degrees_east   | XY   | T |                                 | Longitude_T        | cubic
+glamu        | degrees_east   | XY   | U |                                 | Longitude_U        | cubic            
+glamv        | degrees_east   | XY   | V |                                 | Longitude_V        | cubic          
+glamf        | degrees_east   | XY   | F |                                 | Longitude_F        | cubic         
+gphit        | degrees_north  | XY   | T |                                 | Latitude_T         | cubic         
+gphiu        | degrees_north  | XY   | U |                                 | Latitude_U         | cubic        
+gphiv        | degrees_north  | XY   | V |                                 | Latitude_V         | cubic        
+gphif        | degrees_north  | XY   | F |                                 | Latitude_F         | cubic        
+e1t          | m              | XY   | T |                                 |                    | cubic/rhoi    
+e1u          | m              | XY   | U |                                 |                    | cubic/rhoi     
+e1v          | m              | XY   | V |                                 |                    | cubic/rhoi      
+e1f          | m              | XY   | F |                                 |                    | cubic/rhoi    
+e2t          | m              | XY   | T |                                 |                    | cubic/rhoj      
+e2u          | m              | XY   | U |                                 |                    | cubic/rhoj      
+e2v          | m              | XY   | V |                                 |                    | cubic/rhoj     
+e2f          | m              | XY   | F |                                 |                    | cubic/rhoj      
+tmask        |                | XYZ  | T |                                 |                    | nearest       
+umask        |                | XYZ  | U |                                 |                    | nearest       
+vmask        |                | XYZ  | V |                                 |                    | nearest       
+fmask        |                | XYZ  | F |                                 |                    | nearest       
+weight       |                | XY   | T |                                 |                    |               
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/Doxyfile
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/Doxyfile	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/Doxyfile	(revision 4245)
@@ -0,0 +1,1519 @@
+# Doxyfile 1.6.1
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project
+#
+# All text after a hash (#) is considered a comment and will be ignored
+# The format is:
+#       TAG = value [value, ...]
+# For lists items can also be appended using:
+#       TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (" ")
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# This tag specifies the encoding used for all characters in the config file
+# that follow. The default is UTF-8 which is also the encoding used for all
+# text before the first occurrence of this tag. Doxygen uses libiconv (or the
+# iconv built into libc) for the transcoding. See
+# http://www.gnu.org/software/libiconv for the list of possible encodings.
+
+DOXYFILE_ENCODING      = UTF-8
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
+# by quotes) that should identify the project.
+
+PROJECT_NAME           = Doxygen Fortran Example
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number.
+# This could be handy for archiving the generated documentation or
+# if some version control system is used.
+
+PROJECT_NUMBER         =
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
+# base path where the generated documentation will be put.
+# If a relative path is entered, it will be relative to the location
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY       = 
+
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
+# 4096 sub-directories (in 2 levels) under the output directory of each output
+# format and will distribute the generated files over these directories.
+# Enabling this option can be useful when feeding doxygen a huge amount of
+# source files, where putting all generated files in the same directory would
+# otherwise cause performance problems for the file system.
+
+CREATE_SUBDIRS         = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# The default language is English, other supported languages are:
+# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
+# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German,
+# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English
+# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian,
+# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak,
+# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese.
+
+OUTPUT_LANGUAGE        = English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
+# include brief member descriptions after the members that are listed in
+# the file and class documentation (similar to JavaDoc).
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC      = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
+# the brief description of a member or function before the detailed description.
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF           = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator
+# that is used to form the text in various listings. Each string
+# in this list, if found as the leading text of the brief description, will be
+# stripped from the text and the result after processing the whole list, is
+# used as the annotated text. Otherwise, the brief description is used as-is.
+# If left blank, the following values are used ("$name" is automatically
+# replaced with the name of the entity): "The $name class" "The $name widget"
+# "The $name file" "is" "provides" "specifies" "contains"
+# "represents" "a" "an" "the"
+
+ABBREVIATE_BRIEF       =
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# Doxygen will generate a detailed section even if there is only a brief
+# description.
+
+ALWAYS_DETAILED_SEC    = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+
+INLINE_INHERITED_MEMB  = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
+# path before files name in the file list and in the header files. If set
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES        = YES
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
+# can be used to strip a user-defined part of the path. Stripping is
+# only done if one of the specified strings matches the left-hand part of
+# the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the
+# path to strip.
+
+STRIP_FROM_PATH        =
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
+# the path mentioned in the documentation of a class, which tells
+# the reader which header file to include in order to use a class.
+# If left blank only the name of the header file containing the class
+# definition is used. Otherwise one should specify the include paths that
+# are normally passed to the compiler using the -I flag.
+
+STRIP_FROM_INC_PATH    =
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
+# (but less readable) file names. This can be useful is your file systems
+# doesn't support long names like on DOS, Mac, or CD-ROM.
+
+SHORT_NAMES            = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
+# will interpret the first line (until the first dot) of a JavaDoc-style
+# comment as the brief description. If set to NO, the JavaDoc
+# comments will behave just like regular Qt-style comments
+# (thus requiring an explicit @brief command for a brief description.)
+
+JAVADOC_AUTOBRIEF      = NO
+
+# If the QT_AUTOBRIEF tag is set to YES then Doxygen will
+# interpret the first line (until the first dot) of a Qt-style
+# comment as the brief description. If set to NO, the comments
+# will behave just like regular Qt-style comments (thus requiring
+# an explicit \brief command for a brief description.)
+
+QT_AUTOBRIEF           = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
+# treat a multi-line C++ special comment block (i.e. a block of //! or ///
+# comments) as a brief description. This used to be the default behaviour.
+# The new default is to treat a multi-line C++ comment block as a detailed
+# description. Set this tag to YES if you prefer the old behaviour instead.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
+# member inherits the documentation from any documented member that it
+# re-implements.
+
+INHERIT_DOCS           = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce
+# a new page for each member. If set to NO, the documentation of a member will
+# be part of the file/class/namespace that contains it.
+
+SEPARATE_MEMBER_PAGES  = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab.
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE               = 8
+
+# This tag can be used to specify a number of aliases that acts
+# as commands in the documentation. An alias has the form "name=value".
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to
+# put the command \sideeffect (or @sideeffect) in the documentation, which
+# will result in a user-defined paragraph with heading "Side Effects:".
+# You can put \n's in the value part of an alias to insert newlines.
+
+ALIASES                =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C
+# sources only. Doxygen will then generate output that is more tailored for C.
+# For instance, some of the names that are used will be different. The list
+# of all members will be omitted, etc.
+
+OPTIMIZE_OUTPUT_FOR_C  = NO
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java
+# sources only. Doxygen will then generate output that is more tailored for
+# Java. For instance, namespaces will be presented as packages, qualified
+# scopes will look different, etc.
+
+OPTIMIZE_OUTPUT_JAVA   = NO
+
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources only. Doxygen will then generate output that is more tailored for
+# Fortran.
+
+OPTIMIZE_FOR_FORTRAN   = YES 
+
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for
+# VHDL.
+
+OPTIMIZE_OUTPUT_VHDL   = NO
+
+# Doxygen selects the parser to use depending on the extension of the files it parses.
+# With this tag you can assign which parser to use for a given extension.
+# Doxygen has a built-in mapping, but you can override or extend it using this tag.
+# The format is ext=language, where ext is a file extension, and language is one of
+# the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP,
+# Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat
+# .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran),
+# use: inc=Fortran f=C. Note that for custom extensions you also need to set FILE_PATTERNS otherwise the files are not read by doxygen.
+
+EXTENSION_MAPPING      =
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should
+# set this tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string); v.s.
+# func(std::string) {}). This also make the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+
+BUILTIN_STL_SUPPORT    = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+
+CPP_CLI_SUPPORT        = NO
+
+# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only.
+# Doxygen will parse them like normal C++ but will assume all classes use public
+# instead of private inheritance when no explicit protection keyword is present.
+
+SIP_SUPPORT            = NO
+
+# For Microsoft's IDL there are propget and propput attributes to indicate getter
+# and setter methods for a property. Setting this option to YES (the default)
+# will make doxygen to replace the get and set methods by a property in the
+# documentation. This will only work if the methods are indeed getting or
+# setting a simple type. If this is not the case, or you want to show the
+# methods anyway, you should set this option to NO.
+
+IDL_PROPERTY_SUPPORT   = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES, then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC   = NO
+
+# Set the SUBGROUPING tag to YES (the default) to allow class member groups of
+# the same type (for instance a group of public functions) to be put as a
+# subgroup of that type (e.g. under the Public Functions section). Set it to
+# NO to prevent subgrouping. Alternatively, this can be done per class using
+# the \nosubgrouping command.
+
+SUBGROUPING            = YES
+
+# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum
+# is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically
+# be useful for C code in case the coding convention dictates that all compound
+# types are typedef'ed and only the typedef is referenced, never the tag name.
+
+TYPEDEF_HIDES_STRUCT   = NO
+
+# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to
+# determine which symbols to keep in memory and which to flush to disk.
+# When the cache is full, less often used symbols will be written to disk.
+# For small to medium size projects (<1000 input files) the default value is
+# probably good enough. For larger projects a too small cache size can cause
+# doxygen to be busy swapping symbols to and from disk most of the time
+# causing a significant performance penality.
+# If the system has enough physical memory increasing the cache will improve the
+# performance by keeping more symbols in memory. Note that the value works on
+# a logarithmic scale so increasing the size by one will rougly double the
+# memory usage. The cache size is given by this formula:
+# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0,
+# corresponding to a cache size of 2^16 = 65536 symbols
+
+SYMBOL_CACHE_SIZE      = 0
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
+# documentation are documented, even if no documentation was available.
+# Private class members and static file members will be hidden unless
+# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL            = YES 
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
+# will be included in the documentation.
+
+EXTRACT_PRIVATE        = NO
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file
+# will be included in the documentation.
+
+EXTRACT_STATIC         = NO
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
+# defined locally in source files will be included in the documentation.
+# If set to NO only classes defined in header files are included.
+
+EXTRACT_LOCAL_CLASSES  = YES
+
+# This flag is only useful for Objective-C code. When set to YES local
+# methods, which are defined in the implementation section but not in
+# the interface are included in the documentation.
+# If set to NO (the default) only methods in the interface are included.
+
+EXTRACT_LOCAL_METHODS  = NO
+
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base
+# name of the file that contains the anonymous namespace. By default
+# anonymous namespace are hidden.
+
+EXTRACT_ANON_NSPACES   = NO
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
+# undocumented members of documented classes, files or namespaces.
+# If set to NO (the default) these members will be included in the
+# various overviews, but no documentation section is generated.
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS     = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy.
+# If set to NO (the default) these classes will be included in the various
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES     = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
+# friend (class|struct|union) declarations.
+# If set to NO (the default) these declarations will be included in the
+# documentation.
+
+HIDE_FRIEND_COMPOUNDS  = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
+# documentation blocks found inside the body of a function.
+# If set to NO (the default) these blocks will be appended to the
+# function's detailed documentation block.
+
+HIDE_IN_BODY_DOCS      = NO
+
+# The INTERNAL_DOCS tag determines if documentation
+# that is typed after a \internal command is included. If the tag is set
+# to NO (the default) then the documentation will be excluded.
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS          = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
+# file names in lower-case letters. If set to YES upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# and Mac users are advised to set this option to NO.
+
+CASE_SENSE_NAMES       = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
+# will show members with their full class and namespace scopes in the
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES       = NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
+# will put a list of the files that are included by a file in the documentation
+# of that file.
+
+SHOW_INCLUDE_FILES     = YES
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
+# is inserted in the documentation for inline members.
+
+INLINE_INFO            = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
+# will sort the (detailed) documentation of file and class members
+# alphabetically by member name. If set to NO the members will appear in
+# declaration order.
+
+SORT_MEMBER_DOCS       = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the
+# brief documentation of file, namespace and class members alphabetically
+# by member name. If set to NO (the default) the members will appear in
+# declaration order.
+
+SORT_BRIEF_DOCS        = NO
+
+# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the (brief and detailed) documentation of class members so that constructors and destructors are listed first. If set to NO (the default) the constructors will appear in the respective orders defined by SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO.
+
+SORT_MEMBERS_CTORS_1ST = NO
+
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the
+# hierarchy of group names into alphabetical order. If set to NO (the default)
+# the group names will appear in their defined order.
+
+SORT_GROUP_NAMES       = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be
+# sorted by fully-qualified names, including namespaces. If set to
+# NO (the default), the class list will be sorted only by class name,
+# not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the
+# alphabetical list.
+
+SORT_BY_SCOPE_NAME     = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or
+# disable (NO) the todo list. This list is created by putting \todo
+# commands in the documentation.
+
+GENERATE_TODOLIST      = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or
+# disable (NO) the test list. This list is created by putting \test
+# commands in the documentation.
+
+GENERATE_TESTLIST      = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or
+# disable (NO) the bug list. This list is created by putting \bug
+# commands in the documentation.
+
+GENERATE_BUGLIST       = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
+# disable (NO) the deprecated list. This list is created by putting
+# \deprecated commands in the documentation.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional
+# documentation sections, marked by \if sectionname ... \endif.
+
+ENABLED_SECTIONS       =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
+# the initial value of a variable or define consists of for it to appear in
+# the documentation. If the initializer consists of more lines than specified
+# here it will be hidden. Use a value of 0 to hide initializers completely.
+# The appearance of the initializer of individual variables and defines in the
+# documentation can be controlled using \showinitializer or \hideinitializer
+# command in the documentation regardless of this setting.
+
+MAX_INITIALIZER_LINES  = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
+# at the bottom of the documentation of classes and structs. If set to YES the
+# list will mention the files that were used to generate the documentation.
+
+SHOW_USED_FILES        = YES
+
+# If the sources in your project are distributed over multiple directories
+# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
+# in the documentation. The default is NO.
+
+SHOW_DIRECTORIES       = NO
+
+# Set the SHOW_FILES tag to NO to disable the generation of the Files page.
+# This will remove the Files entry from the Quick Index and from the
+# Folder Tree View (if specified). The default is YES.
+
+SHOW_FILES             = YES
+
+# Set the SHOW_NAMESPACES tag to NO to disable the generation of the
+# Namespaces page.
+# This will remove the Namespaces entry from the Quick Index
+# and from the Folder Tree View (if specified). The default is YES.
+
+SHOW_NAMESPACES        = YES
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
+# popen()) the command <command> <input-file>, where <command> is the value of
+# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file
+# provided by doxygen. Whatever the program writes to standard output
+# is used as the file version. See the manual for examples.
+
+FILE_VERSION_FILTER    =
+
+# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by
+# doxygen. The layout file controls the global structure of the generated output files
+# in an output format independent way. The create the layout file that represents
+# doxygen's defaults, run doxygen with the -l option. You can optionally specify a
+# file name after the option, if omitted DoxygenLayout.xml will be used as the name
+# of the layout file.
+
+LAYOUT_FILE            =
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+
+QUIET                  = NO
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated by doxygen. Possible values are YES and NO. If left blank
+# NO is used.
+
+WARNINGS               = YES
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
+# automatically be disabled.
+
+WARN_IF_UNDOCUMENTED   = YES
+
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some
+# parameters in a documented function, or documenting parameters that
+# don't exist or using markup commands wrongly.
+
+WARN_IF_DOC_ERROR      = YES
+
+# This WARN_NO_PARAMDOC option can be abled to get warnings for
+# functions that are documented, but have no documentation for their parameters
+# or return value. If set to NO (the default) doxygen will only warn about
+# wrong or incomplete parameter documentation, but not about the absence of
+# documentation.
+
+WARN_NO_PARAMDOC       = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that
+# doxygen can produce. The string should contain the $file, $line, and $text
+# tags, which will be replaced by the file and line number from which the
+# warning originated and the warning text. Optionally the format may contain
+# $version, which will be replaced by the version of the file (if it could
+# be obtained via FILE_VERSION_FILTER)
+
+WARN_FORMAT            = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning
+# and error messages should be written. If left blank the output is written
+# to stderr.
+
+WARN_LOGFILE           =
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
+# with spaces.
+
+INPUT                  =
+
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
+# also the default input encoding. Doxygen uses libiconv (or the iconv built
+# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for
+# the list of possible encodings.
+
+INPUT_ENCODING         = UTF-8
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank the following patterns are tested:
+# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx
+# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90
+
+FILE_PATTERNS          = *.f90 
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories
+# should be searched for input files as well. Possible values are YES and NO.
+# If left blank NO is used.
+
+RECURSIVE              = NO
+
+# The EXCLUDE tag can be used to specify files and/or directories that should
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+
+EXCLUDE                =
+
+# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
+# directories that are symbolic links (a Unix filesystem feature) are excluded
+# from the input.
+
+EXCLUDE_SYMLINKS       = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories. Note that the wildcards are matched
+# against the file with absolute path, so to exclude all test directories
+# for example use the pattern */test/*
+
+EXCLUDE_PATTERNS       =
+
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
+# AClass::ANamespace, ANamespace::*Test
+
+EXCLUDE_SYMBOLS        =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or
+# directories that contain example code fragments that are included (see
+# the \include command).
+
+EXAMPLE_PATH           =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank all files are included.
+
+EXAMPLE_PATTERNS       =
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude
+# commands irrespective of the value of the RECURSIVE tag.
+# Possible values are YES and NO. If left blank NO is used.
+
+EXAMPLE_RECURSIVE      = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or
+# directories that contain image that are included in the documentation (see
+# the \image command).
+
+IMAGE_PATH             = 
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command <filter> <input-file>, where <filter>
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
+# input file. Doxygen will then use the output that the filter program writes
+# to standard output.
+# If FILTER_PATTERNS is specified, this tag will be
+# ignored.
+
+INPUT_FILTER           =
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis.
+# Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match.
+# The filters are a list of the form:
+# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further
+# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER
+# is applied to all files.
+
+FILTER_PATTERNS        =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will be used to filter the input files when producing source
+# files to browse (i.e. when SOURCE_BROWSER is set to YES).
+
+FILTER_SOURCE_FILES    = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will
+# be generated. Documented entities will be cross-referenced with these sources.
+# Note: To get rid of all source code in the generated output, make sure also
+# VERBATIM_HEADERS is set to NO.
+
+SOURCE_BROWSER         = NO
+
+# Setting the INLINE_SOURCES tag to YES will include the body
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES         = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
+# doxygen to hide any special comment blocks from generated source code
+# fragments. Normal C and C++ comments will always remain visible.
+
+STRIP_CODE_COMMENTS    = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES
+# then for each documented function all documented
+# functions referencing it will be listed.
+
+REFERENCED_BY_RELATION = NO
+
+# If the REFERENCES_RELATION tag is set to YES
+# then for each documented function all documented entities
+# called/used by that function will be listed.
+
+REFERENCES_RELATION    = NO
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES (the default)
+# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from
+# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will
+# link to the source code.
+# Otherwise they will link to the documentation.
+
+REFERENCES_LINK_SOURCE = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code
+# will point to the HTML generated by the htags(1) tool instead of doxygen
+# built-in source browser. The htags tool is part of GNU's global source
+# tagging system (see http://www.gnu.org/software/global/global.html). You
+# will need version 4.8.6 or higher.
+
+USE_HTAGS              = NO
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
+# will generate a verbatim copy of the header file for each class for
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS       = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
+# of all compounds will be generated. Enable this if the project
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX     = NO
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX    = 5
+
+# In case all classes in a project start with a common prefix, all
+# classes will be put under the same header in the alphabetical index.
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX          =
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
+# generate HTML output.
+
+GENERATE_HTML          = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT            = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
+# doxygen will generate files with .html extension.
+
+HTML_FILE_EXTENSION    = .html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard header.
+
+HTML_HEADER            =
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard footer.
+
+HTML_FOOTER            =
+
+# If the HTML_TIMESTAMP tag is set to YES then the generated HTML
+# documentation will contain the timesstamp.
+
+HTML_TIMESTAMP         = NO
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
+# style sheet that is used by each HTML page. It can be used to
+# fine-tune the look of the HTML output. If the tag is left blank doxygen
+# will generate a default style sheet. Note that doxygen will try to copy
+# the style sheet file to the HTML output directory, so don't put your own
+# stylesheet in the HTML output directory as well, or it will be erased!
+
+HTML_STYLESHEET        =
+
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
+# files or namespaces will be aligned in HTML using tables. If set to
+# NO a bullet list will be used.
+
+HTML_ALIGN_MEMBERS     = YES
+
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded. For this to work a browser that supports
+# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox
+# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari).
+
+HTML_DYNAMIC_SECTIONS  = NO
+
+# If the GENERATE_DOCSET tag is set to YES, additional index files
+# will be generated that can be used as input for Apple's Xcode 3
+# integrated development environment, introduced with OSX 10.5 (Leopard).
+# To create a documentation set, doxygen will generate a Makefile in the
+# HTML output directory. Running make will produce the docset in that
+# directory and running "make install" will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find
+# it at startup.
+# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html for more information.
+
+GENERATE_DOCSET        = NO
+
+# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the
+# feed. A documentation feed provides an umbrella under which multiple
+# documentation sets from a single provider (such as a company or product suite)
+# can be grouped.
+
+DOCSET_FEEDNAME        = "Doxygen generated docs"
+
+# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that
+# should uniquely identify the documentation set bundle. This should be a
+# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen
+# will append .docset to the name.
+
+DOCSET_BUNDLE_ID       = org.doxygen.Project
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files
+# will be generated that can be used as input for tools like the
+# Microsoft HTML help workshop to generate a compiled HTML help file (.chm)
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP      = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
+# be used to specify the file name of the resulting .chm file. You
+# can add a path in front of the file if the result should not be
+# written to the html output directory.
+
+CHM_FILE               =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
+# be used to specify the location (absolute path including file name) of
+# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run
+# the HTML help compiler on the generated index.hhp.
+
+HHC_LOCATION           =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
+# controls if a separate .chi index file is generated (YES) or that
+# it should be included in the master .chm file (NO).
+
+GENERATE_CHI           = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING
+# is used to encode HtmlHelp index (hhk), content (hhc) and project file
+# content.
+
+CHM_INDEX_ENCODING     =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
+# controls whether a binary table of contents is generated (YES) or a
+# normal table of contents (NO) in the .chm file.
+
+BINARY_TOC             = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members
+# to the contents of the HTML help documentation and to the tree view.
+
+TOC_EXPAND             = NO
+
+# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER
+# are set, an additional index file will be generated that can be used as input for
+# Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated
+# HTML documentation.
+
+GENERATE_QHP           = NO
+
+# If the QHG_LOCATION tag is specified, the QCH_FILE tag can
+# be used to specify the file name of the resulting .qch file.
+# The path specified is relative to the HTML output folder.
+
+QCH_FILE               =
+
+# The QHP_NAMESPACE tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#namespace
+
+QHP_NAMESPACE          =
+
+# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#virtual-folders
+
+QHP_VIRTUAL_FOLDER     = doc
+
+# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to add.
+# For more information please see
+# http://doc.trolltech.com/qthelpproject.html#custom-filters
+
+QHP_CUST_FILTER_NAME   =
+
+# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the custom filter to add.For more information please see
+# <a href="http://doc.trolltech.com/qthelpproject.html#custom-filters">Qt Help Project / Custom Filters</a>.
+
+QHP_CUST_FILTER_ATTRS  =
+
+# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this project's
+# filter section matches.
+# <a href="http://doc.trolltech.com/qthelpproject.html#filter-attributes">Qt Help Project / Filter Attributes</a>.
+
+QHP_SECT_FILTER_ATTRS  =
+
+# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can
+# be used to specify the location of Qt's qhelpgenerator.
+# If non-empty doxygen will try to run qhelpgenerator on the generated
+# .qhp file.
+
+QHG_LOCATION           =
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
+# top of each HTML page. The value NO (the default) enables the index and
+# the value YES disables it.
+
+DISABLE_INDEX          = NO
+
+# This tag can be used to set the number of enum values (range [1..20])
+# that doxygen will group on one line in the generated HTML documentation.
+
+ENUM_VALUES_PER_LINE   = 4
+
+# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
+# structure should be generated to display hierarchical information.
+# If the tag value is set to YES, a side panel will be generated
+# containing a tree-like index structure (just like the one that
+# is generated for HTML Help). For this to work a browser that supports
+# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser).
+# Windows users are probably better off using the HTML help feature.
+
+GENERATE_TREEVIEW      = NO
+
+# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories,
+# and Class Hierarchy pages using a tree view instead of an ordered list.
+
+USE_INLINE_TREES       = NO
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
+# used to set the initial width (in pixels) of the frame in which the tree
+# is shown.
+
+TREEVIEW_WIDTH         = 250
+
+# Use this tag to change the font size of Latex formulas included
+# as images in the HTML documentation. The default is 10. Note that
+# when you change the font size after a successful doxygen run you need
+# to manually remove any form_*.png images from the HTML output directory
+# to force them to be regenerated.
+
+FORMULA_FONTSIZE       = 10
+
+# When the SEARCHENGINE tag is enable doxygen will generate a search box for the HTML output. The underlying search engine uses javascript
+# and DHTML and should work on any modern browser. Note that when using HTML help (GENERATE_HTMLHELP) or Qt help (GENERATE_QHP)
+# there is already a search function so this one should typically
+# be disabled.
+
+SEARCHENGINE           = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
+# generate Latex output.
+
+GENERATE_LATEX         = YES
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `latex' will be used as the default path.
+
+LATEX_OUTPUT           = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked. If left blank `latex' will be used as the default command name.
+
+LATEX_CMD_NAME         = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
+# generate index for LaTeX. If left blank `makeindex' will be used as the
+# default command name.
+
+MAKEINDEX_CMD_NAME     = makeindex
+
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
+# LaTeX documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_LATEX          = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used
+# by the printer. Possible values are: a4, a4wide, letter, legal and
+# executive. If left blank a4wide will be used.
+
+PAPER_TYPE             = a4wide
+
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
+# packages that should be included in the LaTeX output.
+
+EXTRA_PACKAGES         =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
+# the generated latex document. The header should contain everything until
+# the first chapter. If it is left blank doxygen will generate a
+# standard header. Notice: only use this tag if you know what you are doing!
+
+LATEX_HEADER           =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will
+# contain links (just like the HTML output) instead of page references
+# This makes the output suitable for online browsing using a pdf viewer.
+
+PDF_HYPERLINKS         = YES
+
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
+# plain latex in the generated Makefile. Set this option to YES to get a
+# higher quality PDF documentation.
+
+USE_PDFLATEX           = YES
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
+# command to the generated LaTeX files. This will instruct LaTeX to keep
+# running if errors occur, instead of asking the user for help.
+# This option is also used when generating formulas in HTML.
+
+LATEX_BATCHMODE        = NO
+
+# If LATEX_HIDE_INDICES is set to YES then doxygen will not
+# include the index chapters (such as File Index, Compound Index, etc.)
+# in the output.
+
+LATEX_HIDE_INDICES     = NO
+
+# If LATEX_SOURCE_CODE is set to YES then doxygen will include source code with syntax highlighting in the LaTeX output. Note that which sources are shown also depends on other settings such as SOURCE_BROWSER.
+
+LATEX_SOURCE_CODE      = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
+# The RTF output is optimized for Word 97 and may not look very pretty with
+# other RTF readers or editors.
+
+GENERATE_RTF           = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `rtf' will be used as the default path.
+
+RTF_OUTPUT             = rtf
+
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
+# RTF documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_RTF            = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
+# will contain hyperlink fields. The RTF file will
+# contain links (just like the HTML output) instead of page references.
+# This makes the output suitable for online browsing using WORD or other
+# programs which support those fields.
+# Note: wordpad (write) and others do not support links.
+
+RTF_HYPERLINKS         = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's
+# config file, i.e. a series of assignments. You only have to provide
+# replacements, missing definitions are set to their default value.
+
+RTF_STYLESHEET_FILE    =
+
+# Set optional variables used in the generation of an rtf document.
+# Syntax is similar to doxygen's config file.
+
+RTF_EXTENSIONS_FILE    =
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
+# generate man pages
+
+GENERATE_MAN           = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT             = man
+
+# The MAN_EXTENSION tag determines the extension that is added to
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION          = .3
+
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
+# then it will generate one additional man file for each entity
+# documented in the real man page(s). These additional files
+# only source the real man page, but without them the man command
+# would be unable to find the correct page. The default is NO.
+
+MAN_LINKS              = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES Doxygen will
+# generate an XML file that captures the structure of
+# the code including all documentation.
+
+GENERATE_XML           = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `xml' will be used as the default path.
+
+XML_OUTPUT             = xml
+
+# The XML_SCHEMA tag can be used to specify an XML schema,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_SCHEMA             =
+
+# The XML_DTD tag can be used to specify an XML DTD,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_DTD                =
+
+# If the XML_PROGRAMLISTING tag is set to YES Doxygen will
+# dump the program listings (including syntax highlighting
+# and cross-referencing information) to the XML output. Note that
+# enabling this will significantly increase the size of the XML output.
+
+XML_PROGRAMLISTING     = YES
+
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
+# generate an AutoGen Definitions (see autogen.sf.net) file
+# that captures the structure of the code including all
+# documentation. Note that this feature is still experimental
+# and incomplete at the moment.
+
+GENERATE_AUTOGEN_DEF   = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will
+# generate a Perl module file that captures the structure of
+# the code including all documentation. Note that this
+# feature is still experimental and incomplete at the
+# moment.
+
+GENERATE_PERLMOD       = NO
+
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able
+# to generate PDF and DVI output from the Perl module output.
+
+PERLMOD_LATEX          = NO
+
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
+# nicely formatted so it can be parsed by a human reader.
+# This is useful
+# if you want to understand what is going on.
+# On the other hand, if this
+# tag is set to NO the size of the Perl module output will be much smaller
+# and Perl will parse it just the same.
+
+PERLMOD_PRETTY         = YES
+
+# The names of the make variables in the generated doxyrules.make file
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
+# This is useful so different doxyrules.make files included by the same
+# Makefile don't overwrite each other's variables.
+
+PERLMOD_MAKEVAR_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
+# evaluate all C-preprocessor directives found in the sources and include
+# files.
+
+ENABLE_PREPROCESSING   = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
+# names in the source code. If set to NO (the default) only conditional
+# compilation will be performed. Macro expansion can be done in a controlled
+# way by setting EXPAND_ONLY_PREDEF to YES.
+
+MACRO_EXPANSION        = NO
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
+# then the macro expansion is limited to the macros specified with the
+# PREDEFINED and EXPAND_AS_DEFINED tags.
+
+EXPAND_ONLY_PREDEF     = NO
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
+# in the INCLUDE_PATH (see below) will be search if a #include is found.
+
+SEARCH_INCLUDES        = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by
+# the preprocessor.
+
+INCLUDE_PATH           =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will
+# be used.
+
+INCLUDE_FILE_PATTERNS  =
+
+# The PREDEFINED tag can be used to specify one or more macro names that
+# are defined before the preprocessor is started (similar to the -D option of
+# gcc). The argument of the tag is a list of macros of the form: name
+# or name=definition (no spaces). If the definition and the = are
+# omitted =1 is assumed. To prevent a macro definition from being
+# undefined via #undef or recursively expanded use the := operator
+# instead of the = operator.
+
+PREDEFINED             =
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
+# this tag can be used to specify a list of macro names that should be expanded.
+# The macro definition that is found in the sources will be used.
+# Use the PREDEFINED tag if you want to use a different macro definition.
+
+EXPAND_AS_DEFINED      =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
+# doxygen's preprocessor will remove all function-like macros that are alone
+# on a line, have an all uppercase name, and do not end with a semicolon. Such
+# function macros are typically used for boiler-plate code, and will confuse
+# the parser if not removed.
+
+SKIP_FUNCTION_MACROS   = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES option can be used to specify one or more tagfiles.
+# Optionally an initial location of the external documentation
+# can be added for each tagfile. The format of a tag file without
+# this location is as follows:
+#
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+#
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where "loc1" and "loc2" can be relative or absolute paths or
+# URLs. If a location is present for each tag, the installdox tool
+# does not have to be run to correct the links.
+# Note that each tag file must have a unique name
+# (where the name does NOT include the path)
+# If a tag file is not located in the directory in which doxygen
+# is run, you must also specify the path to the tagfile here.
+
+TAGFILES               =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE       =
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed
+# in the class index. If set to NO only the inherited external classes
+# will be listed.
+
+ALLEXTERNALS           = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will
+# be listed.
+
+EXTERNAL_GROUPS        = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH              = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
+# or super classes. Setting the tag to NO turns the diagrams off. Note that
+# this option is superseded by the HAVE_DOT option below. This is only a
+# fallback. It is recommended to install and use dot, since it yields more
+# powerful graphs.
+
+CLASS_DIAGRAMS         = YES
+
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see
+# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the
+# documentation. The MSCGEN_PATH tag allows you to specify the directory where
+# the mscgen tool resides. If left empty the tool is assumed to be found in the
+# default search path.
+
+MSCGEN_PATH            =
+
+# If set to YES, the inheritance and collaboration graphs will hide
+# inheritance and usage relations if the target is undocumented
+# or is not a class.
+
+HIDE_UNDOC_RELATIONS   = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz, a graph visualization
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT               = YES 
+
+# By default doxygen will write a font called FreeSans.ttf to the output
+# directory and reference it in all dot files that doxygen generates. This
+# font does not include all possible unicode characters however, so when you need
+# these (or just want a differently looking font) you can specify the font name
+# using DOT_FONTNAME. You need need to make sure dot is able to find the font,
+# which can be done by putting it in a standard location or by setting the
+# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory
+# containing the font.
+
+DOT_FONTNAME           = FreeSans
+
+# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs.
+# The default size is 10pt.
+
+DOT_FONTSIZE           = 10
+
+# By default doxygen will tell dot to use the output directory to look for the
+# FreeSans.ttf font (which doxygen will put there itself). If you specify a
+# different font using DOT_FONTNAME you can set the path where dot
+# can find it using this tag.
+
+DOT_FONTPATH           =
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect inheritance relations. Setting this tag to YES will force the
+# the CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH            = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect implementation dependencies (inheritance, containment, and
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH    = YES
+
+# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for groups, showing the direct groups dependencies
+
+GROUP_GRAPHS           = YES
+
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+
+UML_LOOK               = NO
+
+# If set to YES, the inheritance and collaboration graphs will show the
+# relations between templates and their instances.
+
+TEMPLATE_RELATIONS     = NO
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
+# tags are set to YES then doxygen will generate a graph for each documented
+# file showing the direct and indirect include dependencies of the file with
+# other documented files.
+
+INCLUDE_GRAPH          = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
+# documented header file showing the documented files that directly or
+# indirectly include this file.
+
+INCLUDED_BY_GRAPH      = YES
+
+# If the CALL_GRAPH and HAVE_DOT options are set to YES then
+# doxygen will generate a call dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable call graphs
+# for selected functions only using the \callgraph command.
+
+CALL_GRAPH             = YES
+
+# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then
+# doxygen will generate a caller dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable caller
+# graphs for selected functions only using the \callergraph command.
+
+CALLER_GRAPH           = YES 
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
+# will graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY    = YES
+
+# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES
+# then doxygen will show the dependencies a directory has on other directories
+# in a graphical way. The dependency relations are determined by the #include
+# relations between the files in the directories.
+
+DIRECTORY_GRAPH        = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. Possible values are png, jpg, or gif
+# If left blank png will be used.
+
+DOT_IMAGE_FORMAT       = png
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+
+DOT_PATH               =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the
+# \dotfile command).
+
+DOTFILE_DIRS           =
+
+# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of
+# nodes that will be shown in the graph. If the number of nodes in a graph
+# becomes larger than this value, doxygen will truncate the graph, which is
+# visualized by representing a node as a red box. Note that doxygen if the
+# number of direct children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note
+# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
+
+DOT_GRAPH_MAX_NODES    = 50
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the
+# graphs generated by dot. A depth value of 3 means that only nodes reachable
+# from the root by following a path via at most 3 edges will be shown. Nodes
+# that lay further from the root node will be omitted. Note that setting this
+# option to 1 or 2 may greatly reduce the computation time needed for large
+# code bases. Also note that the size of a graph can be further restricted by
+# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
+
+MAX_DOT_GRAPH_DEPTH    = 0
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, because dot on Windows does not
+# seem to support this out of the box. Warning: Depending on the platform used,
+# enabling this option may lead to badly anti-aliased labels on the edges of
+# a graph (i.e. they become hard to read).
+
+DOT_TRANSPARENT        = NO
+
+# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10)
+# support this, this feature is disabled by default.
+
+DOT_MULTI_TARGETS      = NO
+
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
+# generate a legend page explaining the meaning of the various boxes and
+# arrows in the dot generated graphs.
+
+GENERATE_LEGEND        = YES
+
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
+# remove the intermediate dot files that are used to generate
+# the various graphs.
+
+DOT_CLEANUP            = YES
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/attribute.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/attribute.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/attribute.f90	(revision 4245)
@@ -0,0 +1,997 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: att
+!
+! DESCRIPTION:
+!> @brief 
+!> This module manage attribute of variable or file.
+!
+!> @details
+!>    define type TATT:<br/>
+!>    TYPE(TATT) :: tl_att<br/>
+!>
+!>    the attribute value inside attribute structure will be
+!>    character or real(8) 1D table.<br/>
+!>    However the attribute value could be initialised with:<br/>
+!>    - character
+!>    - scalar (real(4), real(8), integer(4) or integer(8))
+!>    - table 1D (real(4), real(8), integer(4) or integer(8))
+!>
+!>    to initialise an attribute structure :<br/>
+!>    tl_att=att_init('attname',value)<br/>
+!>    tl_att=att_init('attname',tab_value)<br/>
+!>
+!>    to print attribute information of one attribute structure:<br/>
+!>    CALL att_print(td_att) 
+!>
+!>    to get character length or the number of value store in attribute
+!>    - tl_att\%i_len
+!>
+!>    to get attribute value:<br/>
+!>    - tl_att\%c_value    (for character attribute)
+!>    - tl_att\%d_value(i) (otherwise)
+!>    
+!>    to get the type number (based on NETCDF type constants) of the 
+!>    attribute:<br/>
+!>    - tl_att\%i_type
+!>
+!>    to get attribute id (affected when attributes will be added to 
+!>    variable or file):<br/>
+!>    - tl_att\%i_id
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!> @todo
+!----------------------------------------------------------------------
+MODULE att
+   USE netcdf                          ! nf90 library
+   USE global                          ! global variable
+   USE kind                            ! F90 kind parameter
+   USE logger                             ! log file manager
+   USE fct                             ! basic useful function
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+   PUBLIC :: TATT       ! attribute structure
+
+   ! function and subroutine
+   PUBLIC :: ASSIGNMENT(=)  ! copy attribute structure
+   PUBLIC :: att_init     ! initialize attribute structure
+   PUBLIC :: att_print    ! print attribute structure
+   PUBLIC :: att_get_id   ! get attribute id in table of attribute structure
+   PUBLIC :: att_clean    ! clean attribute strcuture
+
+   PRIVATE :: att__init_c     ! initialise an attribute structure with character value
+   PRIVATE :: att__init_dp    ! initialise an attribute structure with table of real(8) value
+   PRIVATE :: att__init_dp_0d ! initialise an attribute structure with real(8) value
+   PRIVATE :: att__init_sp    ! initialise an attribute structure with table of real(4) value
+   PRIVATE :: att__init_sp_0d ! initialise an attribute structure with real(4) value
+   PRIVATE :: att__init_i1    ! initialise an attribute structure with table of integer(1) value
+   PRIVATE :: att__init_i1_0d ! initialise an attribute structure with integer(1) value
+   PRIVATE :: att__init_i2    ! initialise an attribute structure with table of integer(2) value
+   PRIVATE :: att__init_i2_0d ! initialise an attribute structure with integer(2) value
+   PRIVATE :: att__init_i4    ! initialise an attribute structure with table of integer(4) value
+   PRIVATE :: att__init_i4_0d ! initialise an attribute structure with integer(4) value
+   PRIVATE :: att__init_i8    ! initialise an attribute structure with table of integer(8) value
+   PRIVATE :: att__init_i8_0d ! initialise an attribute structure with integer(8) value
+   PRIVATE :: att__copy_unit   ! copy attribute structure
+   PRIVATE :: att__copy_tab    ! copy attribute structure
+
+   !> @struct TATT
+   TYPE TATT
+      !CHARACTER(LEN=lc) :: c_name = 'unknown'  !< attribute name
+      CHARACTER(LEN=lc) :: c_name = ''  !< attribute name
+      INTEGER(i4)       :: i_id = 0          !< attribute id
+      INTEGER(i4)       :: i_type  = 0       !< attribute type
+      INTEGER(i4)       :: i_len  = 0        !< number of value store in attribute
+      CHARACTER(LEN=lc) :: c_value = "none"  !< attribute value if type CHAR
+      REAL(dp), DIMENSION(:), POINTER :: d_value => NULL() !< attribute value if type SHORT,INT,FLOAT or DOUBLE
+   END TYPE TATT
+
+   INTERFACE att_init
+      MODULE PROCEDURE att__init_c
+      MODULE PROCEDURE att__init_dp
+      MODULE PROCEDURE att__init_dp_0d
+      MODULE PROCEDURE att__init_sp
+      MODULE PROCEDURE att__init_sp_0d
+      MODULE PROCEDURE att__init_i1
+      MODULE PROCEDURE att__init_i1_0d
+      MODULE PROCEDURE att__init_i2
+      MODULE PROCEDURE att__init_i2_0d
+      MODULE PROCEDURE att__init_i4
+      MODULE PROCEDURE att__init_i4_0d
+      MODULE PROCEDURE att__init_i8
+      MODULE PROCEDURE att__init_i8_0d
+   END INTERFACE att_init
+
+   INTERFACE ASSIGNMENT(=)
+      MODULE PROCEDURE att__copy_unit   ! copy attribute structure
+      MODULE PROCEDURE att__copy_tab   ! copy attribute structure
+   END INTERFACE
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function copy attribute structure in another attribute
+   !> structure
+   !> @details 
+   !> attribute value are copied in a temporary table, so input and output
+   !> attribute structure value do not point on the same "memory cell", and so
+   !> on are independant. 
+   !>
+   !> @warning to avoid infinite loop, do not use any function inside 
+   !> this subroutine
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[out] td_att1  : attribute structure
+   !> @param[in] td_att2  : attribute structure
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE att__copy_tab( td_att1, td_att2 )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TATT), DIMENSION(:)               , INTENT(IN) :: td_att2
+      TYPE(TATT), DIMENSION(SIZE(td_att2(:))),INTENT(OUT) :: td_att1
+
+      ! local variable
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      DO ji=1,SIZE(td_att2(:))
+         td_att1(ji)=td_att2(ji)
+      ENDDO
+
+   END SUBROUTINE att__copy_tab
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function copy attribute structure in another attribute
+   !> structure
+   !> @details 
+   !> attribute value are copied in a temporary table, so input and output
+   !> attribute structure value do not point on the same "memory cell", and so
+   !> on are independant. 
+   !>
+   !> @warning to avoid infinite loop, do not use any function inside 
+   !> this subroutine
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[out] td_att1  : attribute structure
+   !> @param[in] td_att2  : attribute structure
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE att__copy_unit( td_att1, td_att2 )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TATT), INTENT(OUT) :: td_att1
+      TYPE(TATT), INTENT(IN)  :: td_att2
+
+      ! local variable
+      REAL(dp), DIMENSION(:), ALLOCATABLE :: dl_value
+      !----------------------------------------------------------------
+
+      CALL logger_trace("COPY: attribute "//TRIM(td_att2%c_name) )
+
+      ! copy attribute variable
+      td_att1%c_name  = TRIM(td_att2%c_name)
+      td_att1%i_id    = td_att2%i_id
+      td_att1%i_type  = td_att2%i_type
+      td_att1%i_len   = td_att2%i_len
+      td_att1%c_value = TRIM(td_att2%c_value)
+
+      ! copy attribute pointer in an independant variable
+      IF( ASSOCIATED(td_att1%d_value) ) DEALLOCATE(td_att1%d_value)
+      IF( ASSOCIATED(td_att2%d_value) )THEN
+         ALLOCATE( dl_value(td_att2%i_len) )
+         dl_value(:) = td_att2%d_value(:)
+
+         ALLOCATE( td_att1%d_value(td_att1%i_len) )
+         td_att1%d_value(:) = dl_value(:)
+
+         DEALLOCATE( dl_value )
+      ENDIF
+
+   END SUBROUTINE att__copy_unit
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function get attribute id, in a table of attribute structure,
+   !> given attribute name
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_att  : attribute structure
+   !> @param[in] cd_name : attribute name
+   !> @return attribute id
+   !-------------------------------------------------------------------
+   ! @code
+   INTEGER(i4) FUNCTION att_get_id( td_att, cd_name )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TATT),       DIMENSION(:), INTENT(IN) :: td_att
+      CHARACTER(LEN=*),               INTENT(IN) :: cd_name
+
+      ! local variable
+      INTEGER(i4) :: il_size
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      att_get_id=0
+
+      il_size=SIZE(td_att(:))
+      DO ji=1,il_size
+         IF( TRIM(td_att(ji)%c_name) == TRIM(cd_name) )THEN
+            att_get_id=ji
+            EXIT
+         ENDIF
+      ENDDO
+
+   END FUNCTION att_get_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise an attribute structure with character
+   !> value 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : attribute name
+   !> @param[in] cd_value: attribute value
+   !> @return attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION att__init_c( cd_name, cd_value )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+      CHARACTER(LEN=*), INTENT(IN) :: cd_value
+      !----------------------------------------------------------------
+ 
+      ! clean attribute
+      CALL att_clean(att__init_c)
+
+      CALL logger_info( &
+      &  " ATT INIT: attribute name: "//TRIM(ADJUSTL(cd_name))//&
+      &  " attribute value "//TRIM(ADJUSTL(cd_value)) )
+
+      att__init_c%c_name=TRIM(ADJUSTL(cd_name))
+
+      att__init_c%i_type=NF90_CHAR
+      att__init_c%c_value=TRIM(ADJUSTL(cd_value))
+      att__init_c%i_len=LEN( TRIM(ADJUSTL(cd_value)) )
+
+   END FUNCTION att__init_c
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise an attribute structure with table 
+   !> of real(8) value
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : attribute name
+   !> @param[in] dd_value: attribute value
+   !> @return attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION att__init_dp( cd_name, dd_value )
+      IMPLICIT NONE
+
+      ! Argument
+      CHARACTER(LEN=*),               INTENT(IN) :: cd_name
+      REAL(dp),         DIMENSION(:), INTENT(IN) :: dd_value
+
+      ! local value
+      INTEGER(i4)       :: il_len
+      CHARACTER(LEN=lc) :: cl_value
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! clean attribute
+      CALL att_clean(att__init_dp)
+
+      ! table size
+      il_len=size(dd_value(:))
+
+      cl_value="(/"
+      DO ji=1,il_len-1
+         cl_value=TRIM(cl_value)//TRIM(fct_str(dd_value(ji)))//","
+      ENDDO
+      cl_value=TRIM(cl_value)//TRIM(fct_str(dd_value(il_len)))//"/)"
+
+      CALL logger_info( &
+      &  " ATT INIT: attribute name: "//TRIM(ADJUSTL(cd_name))//&
+      &  " attribute value "//TRIM(ADJUSTL(cl_value)) )
+
+      att__init_dp%c_name=TRIM(ADJUSTL(cd_name))
+
+      att__init_dp%i_type=NF90_DOUBLE
+
+      IF( ASSOCIATED(att__init_dp%d_value) )THEN
+         DEALLOCATE(att__init_dp%d_value)
+      ENDIF
+      ALLOCATE(att__init_dp%d_value(il_len))
+
+      att__init_dp%d_value(:)=dd_value(:)
+      att__init_dp%i_len=il_len
+
+   END FUNCTION att__init_dp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise an attribute structure with 
+   !> real(8) value 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : attribute name
+   !> @param[in] dd_value: attribute value
+   !> @return attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION att__init_dp_0d( cd_name, dd_value )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+      REAL(dp),         INTENT(IN) :: dd_value
+
+      ! local value
+      CHARACTER(LEN=lc) :: cl_value
+      !----------------------------------------------------------------
+
+      ! clean attribute
+      CALL att_clean(att__init_dp_0d)
+      
+      cl_value="(/"//TRIM(fct_str(dd_value))//"/)"
+
+      CALL logger_info( &
+      &  " ATT INIT: attribute name: "//TRIM(ADJUSTL(cd_name))//&
+      &  " attribute value "//TRIM(ADJUSTL(cl_value)) )
+
+      att__init_dp_0d%c_name=TRIM(ADJUSTL(cd_name))
+
+      att__init_dp_0d%i_type=NF90_DOUBLE
+
+      IF( ASSOCIATED(att__init_dp_0d%d_value) )THEN
+         DEALLOCATE(att__init_dp_0d%d_value)
+      ENDIF
+      ALLOCATE(att__init_dp_0d%d_value(1))
+
+      att__init_dp_0d%d_value(1)=dd_value
+      att__init_dp_0d%i_len=1
+
+   END FUNCTION att__init_dp_0d
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise an attribute structure with table 
+   !> of real(4) value
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : attribute name
+   !> @param[in] rd_value: attribute value
+   !> @return attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION att__init_sp( cd_name, rd_value )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),               INTENT(IN) :: cd_name
+      REAL(sp),         DIMENSION(:), INTENT(IN) :: rd_value
+
+      ! local value
+      INTEGER(i4)       :: il_len
+      CHARACTER(LEN=lc) :: cl_value
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! clean attribute
+      CALL att_clean(att__init_sp)
+      
+      ! table size
+      il_len=size(rd_value(:))
+
+      cl_value="(/"
+      DO ji=1,il_len-1
+         cl_value=TRIM(cl_value)//TRIM(fct_str(rd_value(ji)))//","
+      ENDDO
+      cl_value=TRIM(cl_value)//TRIM(fct_str(rd_value(il_len)))//"/)"
+
+      CALL logger_info( &
+      &  " ATT INIT: attribute name: "//TRIM(ADJUSTL(cd_name))//&
+      &  " attribute value "//TRIM(ADJUSTL(cl_value)) )      
+
+      att__init_sp%c_name=TRIM(ADJUSTL(cd_name))
+
+      att__init_sp%i_type=NF90_FLOAT
+
+      IF( ASSOCIATED(att__init_sp%d_value) )THEN
+         DEALLOCATE(att__init_sp%d_value)
+      ENDIF
+      ALLOCATE(att__init_sp%d_value(il_len))
+
+      att__init_sp%d_value(:)=REAL(rd_value(:),dp)
+      att__init_sp%i_len=il_len
+
+   END FUNCTION att__init_sp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise an attribute structure with 
+   !> real(4) value 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : attribute name
+   !> @param[in] rd_value: attribute value
+   !> @return attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION att__init_sp_0d( cd_name, rd_value )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+      REAL(sp),         INTENT(IN) :: rd_value
+
+      ! local value
+      CHARACTER(LEN=lc) :: cl_value
+      !----------------------------------------------------------------
+
+      ! clean attribute
+      CALL att_clean(att__init_sp_0d)
+      
+      cl_value="(/"//TRIM(fct_str(rd_value))//"/)"
+
+      CALL logger_info( &
+      &  " ATT INIT: attribute name: "//TRIM(ADJUSTL(cd_name))//&
+      &  " attribute value "//TRIM(ADJUSTL(cl_value)) )      
+
+      att__init_sp_0d%c_name=TRIM(ADJUSTL(cd_name))
+
+      att__init_sp_0d%i_type=NF90_FLOAT
+
+      IF( ASSOCIATED(att__init_sp_0d%d_value) )THEN
+         DEALLOCATE(att__init_sp_0d%d_value)
+      ENDIF
+      ALLOCATE(att__init_sp_0d%d_value(1))
+
+      att__init_sp_0d%d_value(1)=REAL(rd_value,dp)
+      att__init_sp_0d%i_len=1
+
+   END FUNCTION att__init_sp_0d
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise an attribute structure with table 
+   !> of integer(1) value
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : attribute name
+   !> @param[in] bd_value: attribute value
+   !> @return attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION att__init_i1( cd_name, bd_value )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),               INTENT(IN) :: cd_name
+      INTEGER(i1),      DIMENSION(:), INTENT(IN) :: bd_value
+
+      ! local value
+      INTEGER(i4)       :: il_len
+      CHARACTER(LEN=lc) :: cl_value
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! clean attribute
+      CALL att_clean(att__init_i1)
+      
+      ! table size
+      il_len=size(bd_value(:))
+
+      cl_value="(/"
+      DO ji=1,il_len-1
+         cl_value=TRIM(cl_value)//TRIM(fct_str(bd_value(ji)))//","
+      ENDDO
+      cl_value=TRIM(cl_value)//TRIM(fct_str(bd_value(il_len)))//"/)"
+
+      CALL logger_info( &
+      &  " ATT INIT: attribute name: "//TRIM(ADJUSTL(cd_name))//&
+      &  " attribute value "//TRIM(ADJUSTL(cl_value)) )      
+
+      att__init_i1%c_name=TRIM(ADJUSTL(cd_name))
+
+      att__init_i1%i_type=NF90_BYTE
+
+      IF( ASSOCIATED(att__init_i1%d_value) )THEN
+         DEALLOCATE(att__init_i1%d_value)
+      ENDIF
+      ALLOCATE(att__init_i1%d_value(il_len))
+
+      att__init_i1%d_value(:)=REAL(bd_value(:),dp)
+      att__init_i1%i_len=il_len
+
+   END FUNCTION att__init_i1
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise an attribute structure with 
+   !> integer(1) value 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : attribute name
+   !> @param[in] bd_value: attribute value
+   !> @return attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION att__init_i1_0d( cd_name, bd_value )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+      INTEGER(i1),      INTENT(IN) :: bd_value
+
+      !local value
+      CHARACTER(LEN=lc) :: cl_value
+      !----------------------------------------------------------------
+
+      ! clean attribute
+      CALL att_clean(att__init_i1_0d)
+      
+      cl_value="(/"//TRIM(fct_str(bd_value))//"/)"
+
+      CALL logger_info( &
+      &  " ATT INIT: attribute name: "//TRIM(ADJUSTL(cd_name))//&
+      &  " attibute value "//TRIM(ADJUSTL(cl_value)) )      
+
+      att__init_i1_0d%c_name=TRIM(ADJUSTL(cd_name))
+
+      att__init_i1_0d%i_type=NF90_BYTE
+
+      IF( ASSOCIATED(att__init_i1_0d%d_value) )THEN
+         DEALLOCATE(att__init_i1_0d%d_value)
+      ENDIF
+      ALLOCATE(att__init_i1_0d%d_value(1))
+
+      att__init_i1_0d%d_value(1)=REAL(bd_value,dp)
+      att__init_i1_0d%i_len=1
+
+   END FUNCTION att__init_i1_0d
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise an attribute structure with table 
+   !> of integer(2) value
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : attribute name
+   !> @param[in] sd_value: attribute value
+   !> @return attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION att__init_i2( cd_name, sd_value )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),               INTENT(IN) :: cd_name
+      INTEGER(i2),      DIMENSION(:), INTENT(IN) :: sd_value
+
+      ! local value
+      INTEGER(i4)       :: il_len
+      CHARACTER(LEN=lc) :: cl_value
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! clean attribute
+      CALL att_clean(att__init_i2)
+      
+      ! table size
+      il_len=size(sd_value(:))
+
+      cl_value="(/"
+      DO ji=1,il_len-1
+         cl_value=TRIM(cl_value)//TRIM(fct_str(sd_value(ji)))//","
+      ENDDO
+      cl_value=TRIM(cl_value)//TRIM(fct_str(sd_value(il_len)))//"/)"
+
+      CALL logger_info( &
+      &  " ATT INIT: attribute name: "//TRIM(ADJUSTL(cd_name))//&
+      &  " attribute value "//TRIM(ADJUSTL(cl_value)) )      
+
+      att__init_i2%c_name=TRIM(ADJUSTL(cd_name))
+
+      att__init_i2%i_type=NF90_SHORT
+
+      IF( ASSOCIATED(att__init_i2%d_value) )THEN
+         DEALLOCATE(att__init_i2%d_value)
+      ENDIF
+      ALLOCATE(att__init_i2%d_value(il_len))
+
+      att__init_i2%d_value(:)=REAL(sd_value(:),dp)
+      att__init_i2%i_len=il_len
+
+   END FUNCTION att__init_i2
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise an attribute structure with 
+   !> integer(2) value 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : attribute name
+   !> @param[in] sd_value: attribute value
+   !> @return attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION att__init_i2_0d( cd_name, sd_value )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+      INTEGER(i2),      INTENT(IN) :: sd_value
+
+      !local value
+      CHARACTER(LEN=lc) :: cl_value
+      !----------------------------------------------------------------
+
+      ! clean attribute
+      CALL att_clean(att__init_i2_0d)
+      
+      cl_value="(/"//TRIM(fct_str(sd_value))//"/)"
+
+      CALL logger_info( &
+      &  " ATT INIT: attribute name: "//TRIM(ADJUSTL(cd_name))//&
+      &  " attibute value "//TRIM(ADJUSTL(cl_value)) )      
+
+      att__init_i2_0d%c_name=TRIM(ADJUSTL(cd_name))
+
+      att__init_i2_0d%i_type=NF90_SHORT
+
+      IF( ASSOCIATED(att__init_i2_0d%d_value) )THEN
+         DEALLOCATE(att__init_i2_0d%d_value)
+      ENDIF
+      ALLOCATE(att__init_i2_0d%d_value(1))
+
+      att__init_i2_0d%d_value(1)=REAL(sd_value,dp)
+      att__init_i2_0d%i_len=1
+
+   END FUNCTION att__init_i2_0d
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise an attribute structure with table 
+   !> of integer(4) value
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : attribute name
+   !> @param[in] id_value: attribute value
+   !> @return attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION att__init_i4( cd_name, id_value )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),               INTENT(IN) :: cd_name
+      INTEGER(i4),      DIMENSION(:), INTENT(IN) :: id_value
+
+      ! local value
+      INTEGER(i4)       :: il_len
+      CHARACTER(LEN=lc) :: cl_value
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! clean attribute
+      CALL att_clean(att__init_i4)
+      
+      ! table size
+      il_len=size(id_value(:))
+
+      cl_value="(/"
+      DO ji=1,il_len-1
+         cl_value=TRIM(cl_value)//TRIM(fct_str(id_value(ji)))//","
+      ENDDO
+      cl_value=TRIM(cl_value)//TRIM(fct_str(id_value(il_len)))//"/)"
+
+      CALL logger_info( &
+      &  " ATT INIT: attribute name: "//TRIM(ADJUSTL(cd_name))//&
+      &  " attribute value "//TRIM(ADJUSTL(cl_value)) )      
+
+      att__init_i4%c_name=TRIM(ADJUSTL(cd_name))
+
+      att__init_i4%i_type=NF90_INT
+
+      IF( ASSOCIATED(att__init_i4%d_value) )THEN
+         DEALLOCATE(att__init_i4%d_value)
+      ENDIF
+      ALLOCATE(att__init_i4%d_value(il_len))
+
+      att__init_i4%d_value(:)=REAL(id_value(:),dp)
+      att__init_i4%i_len=il_len
+
+   END FUNCTION att__init_i4
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise an attribute structure with 
+   !> integer(4) value 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : attribute name
+   !> @param[in] id_value: attribute value
+   !> @return attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION att__init_i4_0d( cd_name, id_value )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+      INTEGER(i4),      INTENT(IN) :: id_value
+
+      !local value
+      CHARACTER(LEN=lc) :: cl_value
+      !----------------------------------------------------------------
+
+      ! clean attribute
+      CALL att_clean(att__init_i4_0d)
+      
+      cl_value="(/"//TRIM(fct_str(id_value))//"/)"
+
+      CALL logger_info( &
+      &  " ATT INIT: attribute name: "//TRIM(ADJUSTL(cd_name))//&
+      &  " attibute value "//TRIM(ADJUSTL(cl_value)) )      
+
+      att__init_i4_0d%c_name=TRIM(ADJUSTL(cd_name))
+
+      att__init_i4_0d%i_type=NF90_INT
+
+      IF( ASSOCIATED(att__init_i4_0d%d_value) )THEN
+         DEALLOCATE(att__init_i4_0d%d_value)
+      ENDIF
+      ALLOCATE(att__init_i4_0d%d_value(1))
+
+      att__init_i4_0d%d_value(1)=REAL(id_value,dp)
+      att__init_i4_0d%i_len=1
+
+   END FUNCTION att__init_i4_0d
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise an attribute structure with table 
+   !> of integer(8) value
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : attribute name
+   !> @param[in] kd_value: attribute value
+   !> @return attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION att__init_i8( cd_name, kd_value )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),               INTENT(IN) :: cd_name
+      INTEGER(i8),      DIMENSION(:), INTENT(IN) :: kd_value
+
+      ! local value
+      INTEGER(i4)       :: il_len
+      CHARACTER(LEN=lc) :: cl_value
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! clean attribute
+      CALL att_clean(att__init_i8)
+      
+      ! table size
+      il_len=size(kd_value(:))
+
+      cl_value="(/"
+      DO ji=1,il_len
+         cl_value=TRIM(cl_value)//TRIM(fct_str(kd_value(ji)))//","
+      ENDDO
+      cl_value=TRIM(cl_value)//TRIM(fct_str(kd_value(il_len)))//"/)"
+
+      CALL logger_info( &
+      &  " ATT INIT: attribute name: "//TRIM(ADJUSTL(cd_name))//&
+      &  " attibute value "//TRIM(ADJUSTL(cl_value)) )      
+
+      att__init_i8%c_name=TRIM(ADJUSTL(cd_name))
+
+      att__init_i8%i_type=NF90_INT
+
+      IF( ASSOCIATED(att__init_i8%d_value) )THEN
+         DEALLOCATE(att__init_i8%d_value)
+      ENDIF
+      ALLOCATE(att__init_i8%d_value(il_len))
+
+      att__init_i8%d_value(:)=REAL(kd_value(:),dp)
+      att__init_i8%i_len=il_len
+
+   END FUNCTION att__init_i8
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise an attribute structure with 
+   !> integer(8) value 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : attribute name
+   !> @param[in] kd_value: attribute value
+   !> @return attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION att__init_i8_0d( cd_name, kd_value )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+      INTEGER(i8),      INTENT(IN) :: kd_value
+
+      ! local value
+      CHARACTER(LEN=lc) :: cl_value
+      !----------------------------------------------------------------
+
+      ! clean attribute
+      CALL att_clean(att__init_i8_0d)
+      
+      cl_value="(/"//TRIM(fct_str(kd_value))//"/)"
+
+      CALL logger_info( &
+      &  " ATT INIT: attribute name: "//TRIM(ADJUSTL(cd_name))//&
+      &  " attibute value "//TRIM(ADJUSTL(cl_value)) )      
+
+      att__init_i8_0d%c_name=TRIM(ADJUSTL(cd_name))
+
+      att__init_i8_0d%i_type=NF90_INT
+
+      IF( ASSOCIATED(att__init_i8_0d%d_value) )THEN
+         DEALLOCATE(att__init_i8_0d%d_value)
+      ENDIF
+      ALLOCATE(att__init_i8_0d%d_value(1))
+
+      att__init_i8_0d%d_value(1)=REAL(kd_value,dp)
+      att__init_i8_0d%i_len=1
+
+   END FUNCTION att__init_i8_0d
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine print attribute information
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_att : attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE att_print(td_att)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TATT), INTENT(IN) :: td_att
+
+      ! local vairbale
+      CHARACTER(LEN=lc) :: cl_type
+      CHARACTER(LEN=lc) :: cl_value
+      CHARACTER(LEN=lc) :: cl_tmp
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+         SELECT CASE( td_att%i_type )
+
+            CASE(NF90_CHAR)
+               cl_type='CHAR'
+            CASE(NF90_BYTE)
+               cl_type='BYTE'
+            CASE(NF90_SHORT)
+               cl_type='SHORT'
+            CASE(NF90_INT)
+               cl_type='INT'
+            CASE(NF90_FLOAT)
+               cl_type='FLOAT'
+            CASE(NF90_DOUBLE)
+               cl_type='DOUBLE'
+            CASE DEFAULT
+               cl_type=''
+               !cl_type='unknown'
+         END SELECT
+
+         SELECT CASE( td_att%i_type )
+
+            CASE(NF90_CHAR)
+               cl_value=td_att%c_value
+
+            CASE(NF90_BYTE, NF90_SHORT, NF90_INT, NF90_FLOAT, NF90_DOUBLE)   
+               IF( td_att%i_len > 1 )THEN
+
+                  cl_tmp=','
+                  cl_value='(/'
+                  DO ji=1,td_att%i_len-1
+                     cl_value=TRIM(cl_value)//&
+                     &        TRIM(fct_str(td_att%d_value(ji)))//TRIM(cl_tmp)
+                  ENDDO
+                  cl_value=TRIM(cl_value)//&
+                  &        TRIM(fct_str(td_att%d_value(td_att%i_len)))//'/)'
+
+               ELSE
+
+                  cl_value='(/'//TRIM(fct_str(td_att%d_value(1)))//'/)'
+
+               ENDIF
+            CASE DEFAULT
+               cl_value="none"
+
+         END SELECT
+
+         WRITE(*,'((3x,a,a),(/6x,a,i2.2),(a,a),(a,a))')&
+         &        " attribute : ",TRIM(ADJUSTL(td_att%c_name)),      &
+         &        " id : ",td_att%i_id,                         &
+         &        " type : ",TRIM(ADJUSTL(cl_type)),            &
+         &        " value : ",TRIM(ADJUSTL(cl_value))
+
+   END SUBROUTINE att_print
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !>  This subroutine clean attribute strcuture.
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_att : attribute strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE att_clean( td_att )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TATT),  INTENT(INOUT) :: td_att
+
+      ! local variable
+      TYPE(TATT) :: tl_att ! empty attribute structure
+      !----------------------------------------------------------------
+
+      CALL logger_info( &
+      &  " CLEAN: reset attribute "//TRIM(td_att%c_name) )
+
+      IF( ASSOCIATED(td_att%d_value) )THEN
+         ! clean value
+         DEALLOCATE(td_att%d_value)
+      ENDIF
+
+      ! replace by empty structure
+      td_att=tl_att
+
+   END SUBROUTINE att_clean
+   !> @endcode
+END MODULE att
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/boundary.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/boundary.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/boundary.f90	(revision 4245)
@@ -0,0 +1,1757 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: boundary
+!
+! DESCRIPTION:
+!> @brief
+!> This module manage boundary.
+!
+!> @details
+!>
+!>
+!>
+!>
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!> @todo
+!> - add description generique de l'objet boundary
+!> 
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!----------------------------------------------------------------------
+MODULE boundary
+   USE netcdf                          ! nf90 library                           
+   USE global                          ! global parameter
+   USE phycst                          ! physical constant
+   USE kind                            ! F90 kind parameter
+   USE logger                             ! log file manager
+   USE fct                             ! basic useful function
+!   USE date                            ! date manager
+!   USE att                             ! attribute manager
+!   USE dim                             ! dimension manager
+   USE var                             ! variable manager
+!   USE file                            ! file manager
+!   USE iom                             ! I/O manager
+!   USE dom                             ! domain  manager
+!   USE grid                            ! grid manager
+!   USE extrap                          ! extrapolation manager
+!   USE interp                          ! interpolation manager
+!   USE filter                          ! filter manager
+!   USE mpp                             ! MPP manager
+!   USE iom_mpp                         ! MPP I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+   PUBLIC :: ip_ncard !< number of cardinal point
+   PUBLIC :: ip_card  !< table of cardinal point
+   PUBLIC :: TBDY     !< boundary structure
+   PUBLIC :: TSEG     !< segment structure
+
+   ! function and subroutine
+   PUBLIC :: boundary_init         !< initialise boundary structure
+   PUBLIC :: boundary_print        !< print information about boundary
+   PUBLIC :: boundary_clean        !< clean boundary structure 
+   PUBLIC :: boundary_get_indices  !< get indices of each semgent for each boundary.
+   PUBLIC :: boundary_check        !< check boundary indices and corner.
+   PUBLIC :: boundary_check_corner !< check boundary corner
+   PUBLIC :: boundary_set_filename !< set boundary filename
+   PUBLIC :: boundary_clean_interp !< clean interpolated boundary
+   PUBLIC :: boundary_swap         !< swap array for north and east boundary
+
+   PRIVATE :: boundary__init_wrapper    !< initialise a boundary structure
+   PRIVATE :: boundary__init            !< initialise basically a boundary structure
+!   PRIVATE :: boundary__copy            !< copy boundary structure in another
+   PRIVATE :: boundary__copy_unit       !< copy boundary structure in another
+   PRIVATE :: boundary__copy_tab        !< copy boundary structure in another
+   PRIVATE :: boundary__add_seg         !< add one segment structure to a boundary 
+   PRIVATE :: boundary__del_seg         !< remove all segments of a boundary
+   PRIVATE :: boundary__get_info        !< get boundary information from boundary description string character.
+   PRIVATE :: boundary__get_seg_number  !< compute the number of sea segment for one boundary
+   PRIVATE :: boundary__get_seg_indices !< get segment indices for one boundary 
+   PRIVATE :: boundary__print_unit      !< print information about one boundary
+   PRIVATE :: boundary__print_tab       !< print information about a table of boundary
+   
+   PRIVATE :: seg__init    !< initialise segment structure
+   PRIVATE :: seg__clean   !< clean segment structure
+   PRIVATE :: seg__copy    !< copy segment structure in another
+
+   !> @struct
+   TYPE TSEG   
+      INTEGER(i4) :: i_index = 0 !< segment index
+      INTEGER(i4) :: i_width = 0 !< segment width
+      INTEGER(i4) :: i_first = 0 !< segment first indice 
+      INTEGER(i4) :: i_last  = 0 !< segment last indices
+   END TYPE TSEG
+
+   !> @struct
+   TYPE TBDY
+      CHARACTER(LEN=lc) :: c_card = ''
+      LOGICAL           :: l_use  = .FALSE.
+      INTEGER(i4)       :: i_nseg = 0
+      TYPE(TSEG), DIMENSION(:), POINTER :: t_seg => NULL()
+   END TYPE TBDY
+
+   INTEGER(i4), PARAMETER :: ip_ncard=4
+   CHARACTER(LEN=lc), DIMENSION(ip_ncard), PARAMETER :: ip_card = &
+   &  (/ 'north', &
+   &     'south', &
+   &     'east ', &
+   &     'west ' /)
+
+   INTEGER(i4), PARAMETER :: jp_north=1
+   INTEGER(i4), PARAMETER :: jp_south=2
+   INTEGER(i4), PARAMETER :: jp_east =3
+   INTEGER(i4), PARAMETER :: jp_west =4
+
+   INTEGER(i4), PARAMETER :: im_width=10
+
+   INTERFACE boundary_init
+      MODULE PROCEDURE boundary__init_wrapper 
+   END INTERFACE boundary_init
+
+   INTERFACE boundary_print
+      MODULE PROCEDURE boundary__print_unit 
+      MODULE PROCEDURE boundary__print_tab 
+   END INTERFACE boundary_print
+
+   INTERFACE ASSIGNMENT(=)
+      MODULE PROCEDURE boundary__copy_unit 
+      MODULE PROCEDURE boundary__copy_tab 
+      MODULE PROCEDURE seg__copy   ! copy segment structure
+   END INTERFACE   
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine copy boundary structure in another boundary
+   !> structure
+   !> @details 
+   !>
+   !> @warning to avoid infinite loop, do not use any function inside 
+   !> this subroutine
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[out] td_bdy1  : boundary structure
+   !> @param[in] td_bdy2  : boundary structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE boundary__copy_tab( td_bdy1, td_bdy2 )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TBDY), DIMENSION(:), INTENT(OUT) :: td_bdy1
+      TYPE(TBDY), DIMENSION(:), INTENT(IN)  :: td_bdy2
+
+      ! local variable
+      ! loop indices
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_bdy1(:)) /= SIZE(td_bdy2(:)) )THEN
+         CALL logger_error("BOUNDARY COPY: dimension of table of boundary differ")
+      ELSE
+         DO jk=1,SIZE(td_bdy1(:))
+            td_bdy1(jk)=td_bdy2(jk)
+         ENDDO
+      ENDIF
+   END SUBROUTINE boundary__copy_tab
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine copy boundary structure in another boundary
+   !> structure
+   !> @details 
+   !>
+   !> @warning to avoid infinite loop, do not use any function inside 
+   !> this subroutine
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[out] td_bdy1  : boundary structure
+   !> @param[in] td_bdy2  : boundary structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE boundary__copy_unit( td_bdy1, td_bdy2 )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TBDY), INTENT(OUT) :: td_bdy1
+      TYPE(TBDY), INTENT(IN)  :: td_bdy2
+
+      ! local variable
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! copy variable name, id, ..
+      td_bdy1%c_card     = TRIM(td_bdy2%c_card)
+      td_bdy1%i_nseg     = td_bdy2%i_nseg
+      td_bdy1%l_use      = td_bdy2%l_use
+
+      ! copy segment
+      IF( ASSOCIATED(td_bdy1%t_seg) ) DEALLOCATE(td_bdy1%t_seg)
+      IF( ASSOCIATED(td_bdy2%t_seg) .AND. td_bdy1%i_nseg > 0 )THEN
+         ALLOCATE( td_bdy1%t_seg(td_bdy1%i_nseg) )
+         DO ji=1,td_bdy1%i_nseg
+            td_bdy1%t_seg(ji)=td_bdy2%t_seg(ji)
+         ENDDO
+      ENDIF
+
+   END SUBROUTINE boundary__copy_unit
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine clean boundary structure
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_bdy : boundary strucutre
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE boundary_clean( td_bdy )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TBDY), INTENT(INOUT) :: td_bdy
+
+      ! local variable
+      TYPE(TBDY) :: tl_bdy ! empty boundary strucutre
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      CALL logger_info( &
+      &  " CLEAN: reset boundary "//TRIM(td_bdy%c_card) )
+
+      ! del segment
+      IF( ASSOCIATED(td_bdy%t_seg) )THEN
+         ! clean each attribute
+         DO ji=td_bdy%i_nseg,1,-1
+            CALL seg__clean(td_bdy%t_seg(ji) )
+         ENDDO
+         DEALLOCATE( td_bdy%t_seg )
+      ENDIF
+
+      ! replace by empty structure
+      td_bdy=tl_bdy
+
+   END SUBROUTINE boundary_clean
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This function put cardinal name inside file name  
+   ! 
+   !> @details 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[in] cd_file : file name 
+   !> @param[in] cd_card : cardinal name 
+   !> @return file name with cardinal name inside
+   !------------------------------------------------------------------- 
+   !> @code 
+   FUNCTION boundary_set_filename(cd_file, cd_card) 
+      IMPLICIT NONE 
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN) :: cd_file
+      CHARACTER(LEN=*), INTENT(IN) :: cd_card
+
+      ! function 
+      CHARACTER(LEN=lc) :: boundary_set_filename
+
+      ! local variable 
+      CHARACTER(LEN=lc) :: cl_dirname
+      CHARACTER(LEN=lc) :: cl_basename
+      CHARACTER(LEN=lc) :: cl_base
+      CHARACTER(LEN=lc) :: cl_suffix
+      CHARACTER(LEN=lc) :: cl_name
+      ! loop indices 
+      !---------------------------------------------------------------- 
+      ! init
+      boundary_set_filename=''
+
+      IF( TRIM(cd_file) /= '' .AND. TRIM(cd_card) /= '' )THEN
+
+         cl_dirname = fct_dirname( TRIM(cd_file))
+         IF( TRIM(cl_dirname) == '' ) cl_dirname='.'
+
+         cl_basename= fct_basename(TRIM(cd_file))
+
+         cl_base  =fct_split(TRIM(cl_basename),1,'.')
+         cl_suffix=fct_split(TRIM(cl_basename),2,'.')
+
+         cl_name=TRIM(cl_base)//"_"//TRIM(cd_card)//"."//TRIM(cl_suffix)
+
+         boundary_set_filename=TRIM(cl_dirname)//"/"//TRIM(cl_name)
+      ELSE
+         CALL logger_error("BOUNDARY SET FILENAME: file or cardinal name "//&
+         &  " are empty")
+      ENDIF
+ 
+   END FUNCTION boundary_set_filename 
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This function initialise a boundary structure 
+   ! 
+   !> @details 
+   !>  Boundaries for each cardinal will be compute with variable structure.
+   !>  It means that orthogonal index, first and last indices of each 
+   !>  sea segment will be compute automatically.
+   !>  However you could specify which boundary to use or not with
+   !>  arguments ln_north, ln_south, ln_east, ln_west.
+   !>  And boundary description could be specify with argument
+   !>  cn_north, cn_south, cn_east, cn_west.
+   !>  For each cardinal you could specify orthogonal index, 
+   !>  first and last indices (in this order) and boundary width (between
+   !>  parentheses).
+   !> ex : cn_north='index,first,last(width)'
+   !> You could specify more than one segment for each boundary. 
+   !> However each segment will have the same width. So you do not need to
+   !> specify it for each segment.
+   !> ex : cn_north='index1,first1,last1(width)|index2,first2,last2'
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[in] td_var : variable structure 
+   !> @param[in] ld_north : use north boundary or not 
+   !> @param[in] ld_south : use south boundary or not 
+   !> @param[in] ld_east  : use east  boundary or not 
+   !> @param[in] ld_west  : use west  boundary or not 
+   !> @param[in] cd_north : north boundary description 
+   !> @param[in] cd_south : south boundary description 
+   !> @param[in] cd_east  : east  boundary description 
+   !> @param[in] cd_west  : west  boundary description 
+   !> @return boundary structure
+   !> @todo use bondary_get_indices !!!!
+   !------------------------------------------------------------------- 
+   !> @code 
+   FUNCTION boundary__init_wrapper(td_var, &
+   &                               ld_north, ld_south, ld_east, ld_west, &
+   &                               cd_north, cd_south, cd_east, cd_west, &
+   &                               ld_oneseg ) 
+      IMPLICIT NONE 
+      ! Argument
+      TYPE(TVAR)       , INTENT(IN) :: td_var
+      LOGICAL          , INTENT(IN), OPTIONAL :: ld_north
+      LOGICAL          , INTENT(IN), OPTIONAL :: ld_south
+      LOGICAL          , INTENT(IN), OPTIONAL :: ld_east 
+      LOGICAL          , INTENT(IN), OPTIONAL :: ld_west 
+      CHARACTER(LEN=lc), INTENT(IN), OPTIONAL :: cd_north
+      CHARACTER(LEN=lc), INTENT(IN), OPTIONAL :: cd_south
+      CHARACTER(LEN=lc), INTENT(IN), OPTIONAL :: cd_east 
+      CHARACTER(LEN=lc), INTENT(IN), OPTIONAL :: cd_west
+      LOGICAL          , INTENT(IN), OPTIONAL :: ld_oneseg 
+
+      ! function 
+      TYPE(TBDY), DIMENSION(ip_ncard) :: boundary__init_wrapper
+
+      ! local variable 
+      INTEGER(i4)      , DIMENSION(ip_ncard) :: il_index
+      INTEGER(i4)      , DIMENSION(ip_ncard) :: il_min
+      INTEGER(i4)      , DIMENSION(ip_ncard) :: il_max
+
+      CHARACTER(LEN=lc), DIMENSION(ip_ncard) :: cl_card
+
+      TYPE(TBDY)       , DIMENSION(ip_ncard) :: tl_bdy
+      TYPE(TBDY)                             :: tl_tmp
+
+      TYPE(TSEG)                             :: tl_seg
+
+      LOGICAL                                :: ll_oneseg
+
+      ! loop indices 
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jk
+      !---------------------------------------------------------------- 
+      IF( .NOT. ASSOCIATED(td_var%d_value) )THEN
+         CALL logger_error("BOUNDARY INIT: no value associated to variable "//&
+         &              TRIM(td_var%c_name) )
+      ELSEIF( TRIM(td_var%c_point) /= 'T' )THEN
+         CALL logger_error("BOUNDARY INIT: can not compute boundary with "//&
+         &                 "variable "//TRIM(td_var%c_name)//&
+         &                 ". need a variable on T point." )
+      ELSE
+         ll_oneseg=.TRUE.
+         IF( PRESENT(ld_oneseg) ) ll_oneseg=ld_oneseg
+
+         ! init
+         tl_bdy(jp_north)=boundary__init('north',ld_north)
+         tl_bdy(jp_south)=boundary__init('south',ld_south)
+         tl_bdy(jp_east )=boundary__init('east ',ld_east )
+         tl_bdy(jp_west )=boundary__init('west ',ld_west )
+
+         ! if EW cyclic no east west boundary
+         IF( td_var%i_ew >= 0 )THEN
+            CALL logger_debug("BOUNDARY INIT: cyclic no East West boundary")
+            tl_bdy(jp_east )%l_use=.FALSE.
+            tl_bdy(jp_west )%l_use=.FALSE.
+         ENDIF
+
+         ! attention cas U /= T ???
+         il_index(jp_north)=td_var%t_dim(2)%i_len-ig_ghost
+         il_index(jp_south)=1+ig_ghost
+         il_index(jp_east )=td_var%t_dim(1)%i_len-ig_ghost
+         il_index(jp_west )=1+ig_ghost
+
+         il_min(jp_north)=1
+         il_min(jp_south)=1
+         il_min(jp_east )=1
+         il_min(jp_west )=1
+
+         il_max(jp_north)=td_var%t_dim(1)%i_len
+         il_max(jp_south)=td_var%t_dim(1)%i_len
+         il_max(jp_east )=td_var%t_dim(2)%i_len
+         il_max(jp_west )=td_var%t_dim(2)%i_len
+ 
+         cl_card=(/'','','',''/)
+         IF( PRESENT(cd_north) ) cl_card(jp_north)=TRIM(cd_north)
+         IF( PRESENT(cd_south) ) cl_card(jp_south)=TRIM(cd_south)
+         IF( PRESENT(cd_east ) ) cl_card(jp_east )=TRIM(cd_east )
+         IF( PRESENT(cd_west ) ) cl_card(jp_west )=TRIM(cd_west )
+
+         DO jk=1,ip_ncard
+
+            ! define default segment
+            tl_seg=seg__init(il_index(jk),im_width,il_min(jk),il_max(jk))
+
+            IF( tl_bdy(jk)%l_use )THEN
+
+               ! get namelist information
+               tl_tmp=boundary__get_info(cl_card(jk))
+               DO ji=1,tl_tmp%i_nseg
+                  CALL boundary__add_seg(tl_bdy(jk),tl_tmp%t_seg(ji))
+               ENDDO
+               CALL boundary_clean(tl_tmp)
+
+               IF( tl_bdy(jk)%i_nseg == 0 )THEN
+                  ! add default segment
+                  CALL boundary__add_seg(tl_bdy(jk),tl_seg)
+               ELSE
+                  ! fill undefined value
+                  WHERE( tl_bdy(jk)%t_seg(:)%i_index == 0 ) 
+                     tl_bdy(jk)%t_seg(:)%i_index = tl_seg%i_index
+                  END WHERE               
+                  WHERE( tl_bdy(jk)%t_seg(:)%i_width == 0 ) 
+                     tl_bdy(jk)%t_seg(:)%i_width = tl_seg%i_width
+                  END WHERE
+                  WHERE( tl_bdy(jk)%t_seg(:)%i_first == 0 ) 
+                     tl_bdy(jk)%t_seg(:)%i_first = tl_seg%i_first
+                  END WHERE
+                  WHERE( tl_bdy(jk)%t_seg(:)%i_last == 0 ) 
+                     tl_bdy(jk)%t_seg(:)%i_last = tl_seg%i_last
+                  END WHERE
+               ENDIF
+
+            ENDIF
+
+         ENDDO
+
+         CALL boundary_get_indices(tl_bdy(:), td_var, ll_oneseg)
+
+         CALL boundary_check(tl_bdy, td_var)
+
+         boundary__init_wrapper(:)=tl_bdy(:)
+
+         ! clean
+         DO jk=1,ip_ncard
+            CALL boundary_clean(tl_bdy(jk))
+         ENDDO
+
+      ENDIF
+ 
+   END FUNCTION boundary__init_wrapper 
+   !> @endcode 
+   !------------------------------------------------------------------- 
+   !> @brief This function initialise basically a boundary structure with
+   !> cardinal name.
+   ! 
+   !> @details 
+   !> optionnaly you could specify if this boundary is used or not, 
+   !> and add one segment structure.
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[in]  cd_card : cardinal name
+   !> @param[in]  ld_use  : boundary use or not
+   !> @param[in]  td_seg  : segment structure
+   !> @return boundary structure
+   !------------------------------------------------------------------- 
+   !> @code 
+   FUNCTION boundary__init( cd_card, ld_use, td_seg ) 
+      IMPLICIT NONE 
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN) :: cd_card
+      LOGICAL         , INTENT(IN), OPTIONAL :: ld_use 
+      TYPE(TSEG)      , INTENT(IN), OPTIONAL :: td_seg
+
+      ! function 
+      TYPE(TBDY) :: boundary__init
+
+      ! local variable 
+      
+      ! loop indices 
+      !---------------------------------------------------------------- 
+
+      SELECT CASE(TRIM(cd_card))
+         CASE ('north','south','east','west')
+         
+            boundary__init%c_card=TRIM(cd_card)
+
+            boundary__init%l_use=.TRUE.
+            IF( PRESENT(ld_use) ) boundary__init%l_use=ld_use
+
+            IF( PRESENT(td_seg) )THEN
+               CALL boundary__add_seg(boundary__init, td_seg)
+            ENDIF
+
+         CASE DEFAULT
+            CALL logger_error("BOUNDARY INIT: invalid cardinal name")
+      END SELECT
+
+   END FUNCTION boundary__init
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This subroutine add one segment structure to a boundary structure 
+   ! 
+   !> @details 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[inout] td_bdy : boundary structure  
+   !> @param[in] td_seg : segment structure  
+   !------------------------------------------------------------------- 
+   !> @code 
+   SUBROUTINE boundary__add_seg(td_bdy, td_seg) 
+      IMPLICIT NONE 
+      ! Argument 
+      TYPE(TBDY), INTENT(INOUT) :: td_bdy
+      TYPE(TSEG), INTENT(IN   ) :: td_seg
+
+      ! local variable 
+      INTEGER(i4)                            :: il_status
+      TYPE(TSEG) , DIMENSION(:), ALLOCATABLE :: tl_seg
+
+      ! loop indices 
+      !---------------------------------------------------------------- 
+
+      IF( td_bdy%i_nseg > 0 )THEN
+         ! already other segment in boundary structure
+         ALLOCATE( tl_seg(td_bdy%i_nseg), stat=il_status )
+         IF(il_status /= 0 )THEN
+            CALL logger_error( &
+            &  " BOUNDARY ADD SEG: not enough space to put segments ")
+         ELSE
+            ! save temporary segment
+            tl_seg(:)=td_bdy%t_seg(:)
+
+            DEALLOCATE( td_bdy%t_seg )
+            ALLOCATE( td_bdy%t_seg(td_bdy%i_nseg+1), stat=il_status )
+            IF(il_status /= 0 )THEN
+               CALL logger_error( &
+               &  " BOUNDARY ADD SEG: not enough space to put segments ")
+            ENDIF
+
+            ! copy segment in boundary before
+            td_bdy%t_seg(1:td_bdy%i_nseg)=tl_seg(:)
+
+            DEALLOCATE(tl_seg)            
+            
+         ENDIF
+      ELSE
+         ! no segment in boundary structure
+         IF( ASSOCIATED(td_bdy%t_seg) )THEN
+            DEALLOCATE(td_bdy%t_seg)
+         ENDIF
+         ALLOCATE( td_bdy%t_seg(td_bdy%i_nseg+1), stat=il_status )
+         IF(il_status /= 0 )THEN
+            CALL logger_error( &
+            &  " BOUNDARY ADD SEG: not enough space to put segments ")
+         ENDIF         
+      ENDIF
+ 
+      ! update number of segment
+      td_bdy%i_nseg=td_bdy%i_nseg+1
+
+      ! add new segment
+      td_bdy%t_seg(td_bdy%i_nseg)=td_seg
+
+   END SUBROUTINE boundary__add_seg 
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This subroutine remove all segments of a boundary structure 
+   ! 
+   !> @details 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[inout]  td_bdy : boundary structure
+   !------------------------------------------------------------------- 
+   !> @code 
+   SUBROUTINE boundary__del_seg(td_bdy) 
+      IMPLICIT NONE 
+      ! Argument 
+      TYPE(TBDY), INTENT(INOUT) :: td_bdy
+
+      ! local variable 
+      ! loop indices 
+      !---------------------------------------------------------------- 
+
+      IF( ASSOCIATED(td_bdy%t_seg) )THEN
+         DEALLOCATE(td_bdy%t_seg)
+      ENDIF
+      !update number of segment
+      td_bdy%i_nseg=0
+
+   END SUBROUTINE boundary__del_seg 
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This function get information about boundary from string character. 
+   ! 
+   !> @details
+   !> This string character that will be passed through namelist could contains
+   !> orthogonal index, first and last indices, of each segment. 
+   !> And also the width of all segments of this boundary.
+   !>   cn_north='index1,first1,last1(width)|index2,first2,last2'
+   !> 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[in] cd_card : boundary description
+   !> @return boundary structure
+   !------------------------------------------------------------------- 
+   !> @code 
+   FUNCTION boundary__get_info(cd_card) 
+      IMPLICIT NONE 
+      ! Argument 
+      CHARACTER(LEN=lc), INTENT(IN) :: cd_card
+
+      ! function 
+      TYPE(TBDY) :: boundary__get_info
+
+      ! local variable 
+      INTEGER(i4)       :: il_width
+      INTEGER(i4)       :: il_ind1
+      INTEGER(i4)       :: il_ind2
+
+      CHARACTER(LEN=lc) :: cl_seg
+      CHARACTER(LEN=lc) :: cl_index
+      CHARACTER(LEN=lc) :: cl_width
+      CHARACTER(LEN=lc) :: cl_first
+      CHARACTER(LEN=lc) :: cl_last 
+
+      TYPE(TSEG)        :: tl_seg
+
+      ! loop indices 
+      INTEGER(i4) :: ji
+      !---------------------------------------------------------------- 
+ 
+      ji=1
+      cl_seg=fct_split(cd_card,ji)
+
+      il_width=0
+      ! look for segment width 
+      ! width should be the same for all segment of one boundary
+      IF( TRIM(cl_seg)   /= '' )THEN
+         il_ind1=SCAN(fct_lower(cl_seg),'(')
+         IF( il_ind1 /=0 )THEN
+            cl_width=TRIM(cl_seg(il_ind1+1:))
+
+            il_ind2=SCAN(fct_lower(cl_width),')')
+            IF( il_ind2 /=0 )THEN
+               cl_width=TRIM(cl_width(1:il_ind2-1))
+               READ(cl_width,*) il_width
+            ELSE
+               CALL logger_error("BOUNDARY INIT: unclosed parentheses."//&
+               &  " check namelist. ")
+            ENDIF
+         ENDIF
+      ENDIF 
+
+      DO WHILE( TRIM(cl_seg) /= '' )
+
+         cl_index=fct_split(cl_seg,1,',')
+         ! remove potential width information
+         il_ind1=SCAN(fct_lower(cl_index),'(')
+         IF( il_ind1 /=0 )THEN
+            il_ind2=SCAN(fct_lower(cl_index),'(')
+            IF( il_ind2 /=0 )THEN
+               cl_index=TRIM(cl_index(:il_ind1-1))//TRIM(cl_index(il_ind2+1:))
+            ELSE
+               CALL logger_error("BOUNDARY INIT: unclosed parentheses."//&
+               &  " check namelist. ")
+            ENDIF
+         ENDIF
+      
+         cl_first=fct_split(cl_seg,2,',')
+         ! remove potential width information
+         il_ind1=SCAN(fct_lower(cl_first),'(')
+         IF( il_ind1 /=0 )THEN
+            il_ind2=SCAN(fct_lower(cl_first),'(')
+            IF( il_ind2 /=0 )THEN
+               cl_first=TRIM(cl_first(:il_ind1-1))//TRIM(cl_first(il_ind2+1:))
+            ELSE
+               CALL logger_error("BOUNDARY INIT: unclosed parentheses."//&
+               &  " check namelist. ")
+            ENDIF
+         ENDIF         
+         
+         cl_last =fct_split(cl_seg,3,',')
+         ! remove potential width information
+         il_ind1=SCAN(fct_lower(cl_last),'(')
+         IF( il_ind1 /=0 )THEN
+            il_ind2=SCAN(fct_lower(cl_last),'(')
+            IF( il_ind2 /=0 )THEN
+               cl_last=TRIM(cl_last(:il_ind1-1))//TRIM(cl_last(il_ind2+1:))
+            ELSE
+               CALL logger_error("BOUNDARY INIT: unclosed parentheses."//&
+               &  " check namelist. ")
+            ENDIF
+         ENDIF
+
+         IF( il_width /= 0 ) tl_seg%i_width=il_width
+
+         IF( TRIM(cl_index) /= '' ) READ(cl_index,*) tl_seg%i_index
+         IF( TRIM(cl_first) /= '' ) READ(cl_first,*) tl_seg%i_first
+         IF( TRIM(cl_last)  /= '' ) READ(cl_last ,*) tl_seg%i_last
+
+         IF( (tl_seg%i_first == 0 .AND.  tl_seg%i_last == 0) .OR. &
+         &   (tl_seg%i_first /= 0 .AND.  tl_seg%i_last /= 0) )THEN
+            CALL boundary__add_seg(boundary__get_info, tl_seg)
+         ELSE
+            CALL logger_error("BOUNDARY INIT: first or last segment indices "//&
+            &              "are missing . check namelist.")
+         ENDIF
+
+         ji=ji+1
+         cl_seg=fct_split(cd_card,ji)
+      ENDDO 
+
+   END FUNCTION boundary__get_info 
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This subroutine get indices of each semgent for each boundary.
+   ! 
+   !> @details 
+   !> indices are compute from variable value, actually variable fill value,
+   !> which is assume to be land mask. 
+   !> Boundary structure should have been initialized before running 
+   !> this subroutine. Segment indices will be search between first and last
+   !> indies, at this orthogonal index.
+   !> 
+   !> Optionnally you could forced to use only one segment for each boundary.
+   !> 
+   !> @warning number of segment (i_nseg) will be change, before the number 
+   !> of segment structure
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[inout] td_bdy : boundary structure  
+   !> @param[in] td_var : variable structure 
+   !> @param[in] ld_onseg : use only one sgment for each boundary 
+   !------------------------------------------------------------------- 
+   !> @code 
+   SUBROUTINE boundary_get_indices( td_bdy, td_var, ld_oneseg) 
+      IMPLICIT NONE 
+      ! Argument
+      TYPE(TBDY) , DIMENSION(ip_ncard), INTENT(INOUT) :: td_bdy
+      TYPE(TVAR)                      , INTENT(IN   ) :: td_var
+      LOGICAL                         , INTENT(IN   ), OPTIONAL :: ld_oneseg
+
+      ! local variable 
+      INTEGER(i4) :: il_index
+      INTEGER(i4) :: il_width
+      INTEGER(i4) :: il_first
+      INTEGER(i4) :: il_last 
+
+      LOGICAL     :: ll_oneseg
+
+      TYPE(TSEG)  :: tl_seg
+
+      ! loop indices
+      INTEGER(i4) :: jk
+      !---------------------------------------------------------------- 
+ 
+      ll_oneseg=.TRUE.
+      IF( PRESENT(ld_oneseg) ) ll_oneseg=ld_oneseg
+
+      DO jk=1,ip_ncard
+         IF( .NOT. td_bdy(jk)%l_use .OR. td_bdy(jk)%i_nseg > 1 )THEN
+            ! nothing to be done
+         ELSE
+
+            IF( .NOT. ASSOCIATED(td_bdy(jk)%t_seg) )THEN
+               CALL logger_error("BOUNDARY GET INDICES: no segment "//&
+               &  " associated to "//TRIM(td_bdy(jk)%c_card)//&
+               &  " boundary. you should have run boundary_init before"//&
+               &  " running boundary_get_indices" )
+            ELSE
+               il_index=td_bdy(jk)%t_seg(1)%i_index
+               il_width=td_bdy(jk)%t_seg(1)%i_width
+               il_first=td_bdy(jk)%t_seg(1)%i_first
+               il_last =td_bdy(jk)%t_seg(1)%i_last
+ 
+               CALL boundary__get_seg_number( td_bdy(jk), td_var)
+
+               CALL boundary__get_seg_indices( td_bdy(jk), td_var, &
+               &                               il_index, il_width, &
+               &                               il_first, il_last )
+
+               IF( ll_oneseg .AND. td_bdy(jk)%l_use )THEN
+                  tl_seg=td_bdy(jk)%t_seg(1)
+                  ! use last indice of last segment
+                  tl_seg%i_last=td_bdy(jk)%t_seg(td_bdy(jk)%i_nseg)%i_last
+
+                  ! remove all segment from boundary
+                  CALL boundary__del_seg(td_bdy(jk))
+
+                  ! add one segment
+                  CALL boundary__add_seg(td_bdy(jk),tl_seg)
+               ENDIF
+
+            ENDIF
+
+         ENDIF
+
+      ENDDO
+
+   END SUBROUTINE boundary_get_indices 
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This subroutine compute the number of sea segment. 
+   ! 
+   !> @details 
+   !> It use variable value, actually variable fill value
+   !> (which is assume to be land mask), to compute the number of segment between
+   !> first and last indices at boundary orthogonal index.
+   !> @warning number of segment (i_nseg) will be change, before the number 
+   !> of segment structure
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[inout] td_bdy : boundary structure 
+   !> @param[in] td_var : variable structure 
+   !------------------------------------------------------------------- 
+   !> @code 
+   SUBROUTINE boundary__get_seg_number( td_bdy, td_var) 
+      IMPLICIT NONE 
+      ! Argument
+      TYPE(TBDY) , INTENT(INOUT) :: td_bdy
+      TYPE(TVAR) , INTENT(IN   ) :: td_var
+
+      ! local variable 
+      REAL(dp)   , DIMENSION(:)        , ALLOCATABLE :: dl_value
+      LOGICAL                                        :: ll_sea
+      INTEGER(i4)                                    :: il_index
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !---------------------------------------------------------------- 
+ 
+      IF( td_bdy%l_use .AND. td_bdy%i_nseg == 1 )THEN
+
+         il_index=td_bdy%t_seg(1)%i_index
+
+         SELECT CASE(TRIM(td_bdy%c_card))
+            CASE('north','south')
+
+               ALLOCATE( dl_value(td_var%t_dim(1)%i_len) )
+               dl_value(:)=td_var%d_value(:,il_index,1,1)
+
+               IF( ANY(dl_value(:) /= td_var%d_fill) )THEN
+                  
+                  td_bdy%l_use=.TRUE.
+                  td_bdy%i_nseg=0
+
+                  ll_sea=.FALSE.
+                  DO ji=1,td_var%t_dim(1)%i_len
+                     IF( dl_value(ji)/= td_var%d_fill )THEN
+                        IF( .NOT. ll_sea )THEN
+                           td_bdy%i_nseg=td_bdy%i_nseg+1
+                        ENDIF
+                        ll_sea=.TRUE.
+                     ELSE
+                        ll_sea=.FALSE.
+                     ENDIF
+                  ENDDO
+
+               ELSE
+                  td_bdy%l_use=.FALSE.
+                  td_bdy%i_nseg=0
+               ENDIF
+
+               DEALLOCATE( dl_value )
+
+            CASE('east','west')
+
+               ALLOCATE( dl_value(td_var%t_dim(2)%i_len) )
+               dl_value(:)=td_var%d_value(il_index,:,1,1)
+
+               IF( ANY(dl_value(:) /= td_var%d_fill) )THEN
+                  
+                  td_bdy%l_use=.TRUE.
+                  td_bdy%i_nseg=0
+
+                  ll_sea=.FALSE.
+                  DO ji=1,td_var%t_dim(2)%i_len
+                     IF( dl_value(ji)/= td_var%d_fill )THEN
+                        IF( .NOT. ll_sea )THEN
+                           td_bdy%i_nseg=td_bdy%i_nseg+1
+                        ENDIF
+                        ll_sea=.TRUE.
+                     ELSE
+                        ll_sea=.FALSE.
+                     ENDIF
+                  ENDDO
+
+               ELSE
+                  td_bdy%l_use=.FALSE.
+                  td_bdy%i_nseg=0
+               ENDIF
+
+               DEALLOCATE( dl_value )
+
+         END SELECT
+      ENDIF
+
+      
+   END SUBROUTINE boundary__get_seg_number 
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This subroutine get segment indices for one boundary.
+   ! 
+   !> @details 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[inout] td_bdy : boundary structure  
+   !> @param[in] td_var : variable structure  
+   !> @param[in] id_index : boundary orthogonal index  
+   !> @param[in] id_width : bounary width 
+   !> @param[in] id_first : boundary first indice
+   !> @param[in] id_last  : boundary last  indice
+   !------------------------------------------------------------------- 
+   !> @code 
+   SUBROUTINE boundary__get_seg_indices( td_bdy, td_var, &
+   &                                     id_index, id_width, id_first, id_last) 
+      IMPLICIT NONE 
+      ! Argument
+      TYPE(TBDY) , INTENT(INOUT) :: td_bdy
+      TYPE(TVAR) , INTENT(IN   ) :: td_var
+      INTEGER(i4), INTENT(IN   ) :: id_index
+      INTEGER(i4), INTENT(IN   ) :: id_width
+      INTEGER(i4), INTENT(IN   ) :: id_first
+      INTEGER(i4), INTENT(IN   ) :: id_last
+
+      ! local variable 
+      INTEGER(i4)                                    :: il_nseg
+      INTEGER(i4), DIMENSION(ip_ncard)               :: il_max
+      INTEGER(i4), DIMENSION(ip_ncard)               :: il_min
+
+      REAL(dp)   , DIMENSION(:)        , ALLOCATABLE :: dl_value
+
+      LOGICAL                                        :: ll_sea
+      LOGICAL                                        :: ll_first
+      LOGICAL                                        :: ll_last
+
+      TYPE(TSEG)                                     :: tl_seg
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jk
+      INTEGER(i4) :: jl
+      !---------------------------------------------------------------- 
+ 
+      SELECT CASE(TRIM(td_bdy%c_card))
+         CASE('north')
+            jk=jp_north
+            
+            ALLOCATE( dl_value(td_var%t_dim(1)%i_len) )
+            dl_value(:)=td_var%d_value(:,id_index,1,1)
+
+         CASE('south')
+            jk=jp_south
+
+            ALLOCATE( dl_value(td_var%t_dim(1)%i_len) )
+            dl_value(:)=td_var%d_value(:,id_index,1,1)
+
+         CASE('east ')
+            jk=jp_east 
+
+            ALLOCATE( dl_value(td_var%t_dim(2)%i_len) )
+            dl_value(:)=td_var%d_value(id_index,:,1,1)
+
+         CASE('west ')
+            jk=jp_west 
+
+            ALLOCATE( dl_value(td_var%t_dim(2)%i_len) )
+            dl_value(:)=td_var%d_value(id_index,:,1,1)
+
+      END SELECT
+
+      il_max(jp_north)=td_var%t_dim(1)%i_len-ig_ghost
+      il_max(jp_south)=td_var%t_dim(1)%i_len-ig_ghost
+      il_max(jp_east )=td_var%t_dim(2)%i_len-ig_ghost
+      il_max(jp_west )=td_var%t_dim(2)%i_len-ig_ghost
+
+      il_min(jp_north)=1+ig_ghost
+      il_min(jp_south)=1+ig_ghost
+      il_min(jp_east )=1+ig_ghost
+      il_min(jp_west )=1+ig_ghost
+         
+      ! special case for EW cyclic 
+      IF( td_var%i_ew >= 0 )THEN
+         il_min(jp_north)=1
+         il_min(jp_south)=1
+
+         il_max(jp_north)=td_var%t_dim(1)%i_len
+         il_max(jp_south)=td_var%t_dim(1)%i_len
+      ENDIF
+      
+      il_nseg=td_bdy%i_nseg
+      ! remove all segment from boundary
+      CALL boundary__del_seg(td_bdy)
+
+      ll_first=.FALSE.
+      ll_last =.FALSE.
+      DO jl=1,il_nseg
+
+         ! init
+         tl_seg=seg__init(id_index,id_width,id_first,id_last)
+
+         IF( .NOT. (ll_first .AND. ll_last) )THEN
+            ! first loop
+            tl_seg%i_first=MAX(id_first,il_min(jk))
+            tl_seg%i_last =MIN(id_last ,il_max(jk))
+         ELSE
+            ! load new min and max
+            tl_seg%i_first=MAX(td_bdy%t_seg(jl-1)%i_last,il_min(jk))
+            tl_seg%i_last =MIN(id_last                  ,il_max(jk))
+         ENDIF
+
+         ll_first=.FALSE.
+         ll_last =.FALSE.
+         ll_sea  =.FALSE.
+
+         DO ji=tl_seg%i_first,tl_seg%i_last
+
+            IF( ll_first .AND. ll_last )THEN
+               ! first and last point already loaded
+               ! look for next segment
+               EXIT
+            ENDIF
+
+            IF( dl_value(ji)/= td_var%d_fill )THEN
+               IF( .NOT. ll_sea )THEN
+                  tl_seg%i_first=MAX(tl_seg%i_first,ji-1)
+                  ll_first=.true.
+               ENDIF
+               ll_sea=.TRUE.
+            ELSE
+               IF( ll_sea )THEN
+                  tl_seg%i_last=ji
+                  ll_last=.TRUE.
+               ENDIF
+               ll_sea=.FALSE.
+            ENDIF
+            
+         ENDDO
+
+         CALL boundary__add_seg(td_bdy,tl_seg)
+
+         CALL seg__clean(tl_seg)
+         
+      ENDDO
+
+      DEALLOCATE(dl_value)
+      
+   END SUBROUTINE boundary__get_seg_indices 
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This subroutine check if there is boundary at corner, and 
+   !> adjust boundary indices if necessary. 
+   ! 
+   !> @details 
+   !> If there is a north west corner, first indices of north boundary
+   !> should be the same as the west boundary indices. 
+   !> And the last indices of the west boundary should be the same as
+   !> the north indices.
+   !> More over the width of west and north boundary should be the same.
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[inout] td_bdy : boundary structure
+   !> @param[in] td_var : variable structure
+   !> 
+   !> @todo add schematic to description
+   !------------------------------------------------------------------- 
+   !> @code 
+   SUBROUTINE boundary_check_corner( td_bdy, td_var )
+      IMPLICIT NONE 
+      ! Argument
+      TYPE(TBDY) , DIMENSION(ip_ncard), INTENT(INOUT) :: td_bdy
+      TYPE(TVAR)                      , INTENT(IN   ) :: td_var
+
+      ! local variable 
+      TYPE(TSEG)  :: tl_north
+      TYPE(TSEG)  :: tl_south
+      TYPE(TSEG)  :: tl_east 
+      TYPE(TSEG)  :: tl_west
+
+      INTEGER(i4) :: il_width
+
+      ! loop indices
+      !---------------------------------------------------------------- 
+ 
+      IF( .NOT. ASSOCIATED(td_var%d_value) )THEN
+         CALL logger_error("BOUNDARY CHEKC CORNER: no value associated "//&
+         &              "to variable "//TRIM(td_var%c_name))
+      ENDIF
+
+      ! check north west corner
+      IF( td_bdy(jp_north)%l_use .AND. td_bdy(jp_west)%l_use )THEN
+         tl_west =td_bdy(jp_west )%t_seg(td_bdy(jp_west)%i_nseg)
+         tl_north=td_bdy(jp_north)%t_seg(1)
+
+         IF( tl_west%i_last  >= tl_north%i_index .AND. &
+         &   tl_west%i_index >= tl_north%i_first ) THEN
+            CALL logger_debug("BOUNDARY CHEKC CORNER: there is "//&
+            &                 "a north west corner")
+
+            tl_west%i_last   = tl_north%i_index
+            tl_north%i_first = tl_west%i_index
+
+            IF( tl_west%i_width /= tl_north%i_width )THEN
+               CALL logger_error("BOUNDARY CHEKC CORNER: discordant "//&
+               &  " width between north and west boundary ")
+
+               il_width=MIN(tl_west%i_width,tl_north%i_width)
+               
+               tl_west%i_width =il_width
+               tl_north%i_width=il_width
+
+            ENDIF
+
+            td_bdy(jp_west )%t_seg(td_bdy(jp_west)%i_nseg)=tl_west
+            td_bdy(jp_north)%t_seg(1)                     =tl_north
+
+         ELSE
+
+            IF( td_var%d_value(tl_north%i_first,tl_north%i_index,1,1) /= &
+            &   td_var%d_fill )THEN
+               CALL logger_error("BOUNDARY CHEKC CORNER: wrong "//&
+               &              "north boundary first indice ")
+            ENDIF
+
+            IF( td_var%d_value(tl_west%i_index,tl_west%i_last,1,1) /= &
+            &   td_var%d_fill )THEN
+               CALL logger_error("BOUNDARY CHEKC CORNER: wrong "//&
+               &              "west boundary last indice")
+            ENDIF
+         ENDIF
+      ENDIF
+
+      ! check north east corner
+      IF( td_bdy(jp_north)%l_use .AND. td_bdy(jp_east)%l_use )THEN
+         tl_east =td_bdy(jp_east )%t_seg(td_bdy(jp_east )%i_nseg)
+         tl_north=td_bdy(jp_north)%t_seg(td_bdy(jp_north)%i_nseg)
+
+         IF( tl_east%i_last  >= tl_north%i_index .AND. &
+         &   tl_east%i_index <= tl_north%i_last ) THEN
+            CALL logger_debug("BOUNDARY CHEKC CORNER: there is "//&
+            &              "a north east corner")
+
+            tl_east%i_last  = tl_north%i_index
+            tl_north%i_last = tl_east%i_index
+
+            IF( tl_east%i_width /= tl_north%i_width )THEN
+               CALL logger_error("BOUNDARY CHEKC CORNER: discordant "//&
+               &  " width between north and east boundary ")
+
+               il_width=MIN(tl_east%i_width,tl_north%i_width)
+               
+               tl_east%i_width =il_width
+               tl_north%i_width=il_width
+
+            ENDIF
+
+            td_bdy(jp_east )%t_seg(td_bdy(jp_east )%i_nseg)=tl_east
+            td_bdy(jp_north)%t_seg(td_bdy(jp_north)%i_nseg)=tl_north
+         ELSE
+
+            IF( td_var%d_value(tl_north%i_last,tl_north%i_index,1,1) /= &
+            &   td_var%d_fill )THEN
+               CALL logger_error("BOUNDARY CHEKC CORNER: wrong "//&
+               &              "north boundary last indice ")
+            ENDIF
+
+            IF( td_var%d_value(tl_east%i_index,tl_east%i_last,1,1) /= &
+            &   td_var%d_fill )THEN
+               CALL logger_error("BOUNDARY CHEKC CORNER: wrong "//&
+               &              "east boundary last indice")
+            ENDIF
+         ENDIF
+      ENDIF
+
+      ! check south east corner
+      IF( td_bdy(jp_south)%l_use .AND. td_bdy(jp_east)%l_use )THEN
+         tl_east =td_bdy(jp_east )%t_seg(1)
+         tl_south=td_bdy(jp_south)%t_seg(td_bdy(jp_south)%i_nseg)
+
+         IF( tl_east%i_first <= tl_south%i_index .AND. &
+         &   tl_east%i_index <= tl_south%i_last ) THEN
+            CALL logger_debug("BOUNDARY CHEKC CORNER: there is "//&
+            &              "a south east corner")
+
+            tl_east%i_first = tl_south%i_index
+            tl_south%i_last = tl_east%i_index
+
+            IF( tl_east%i_width /= tl_south%i_width )THEN
+               CALL logger_error("BOUNDARY CHEKC CORNER: discordant "//&
+               &  " width between south and east boundary ")
+
+               il_width=MIN(tl_east%i_width,tl_south%i_width)
+               
+               tl_east%i_width =il_width
+               tl_south%i_width=il_width
+
+            ENDIF
+
+            td_bdy(jp_east )%t_seg(1)                      =tl_east
+            td_bdy(jp_south)%t_seg(td_bdy(jp_south)%i_nseg)=tl_south
+         ELSE
+
+            IF( td_var%d_value(tl_south%i_last,tl_south%i_index,1,1) /= &
+            &   td_var%d_fill )THEN
+               CALL logger_error("BOUNDARY CHEKC CORNER: wrong "//&
+               &              "south boundary last indice ")
+            ENDIF
+
+            IF( td_var%d_value(tl_east%i_index,tl_east%i_first,1,1) /= &
+            &   td_var%d_fill )THEN
+               CALL logger_error("BOUNDARY CHEKC CORNER: wrong "//&
+               &              "east boundary first indice")
+            ENDIF
+         ENDIF
+      ENDIF
+
+      ! check south west corner
+      IF( td_bdy(jp_south)%l_use .AND. td_bdy(jp_west)%l_use )THEN
+         tl_west =td_bdy(jp_west )%t_seg(1)
+         tl_south=td_bdy(jp_south)%t_seg(1)
+
+         IF( tl_west%i_first <= tl_south%i_index .AND. &
+         &   tl_west%i_index >= tl_south%i_first ) THEN
+            CALL logger_debug("BOUNDARY CHEKC CORNER: there is "//&
+            &              "a south west corner")
+
+            tl_west%i_first = tl_south%i_index
+            tl_south%i_first= tl_west%i_index
+
+            IF( tl_west%i_width /= tl_south%i_width )THEN
+               CALL logger_error("BOUNDARY CHEKC CORNER: discordant "//&
+               &  " width between south and west boundary ")
+
+               il_width=MIN(tl_west%i_width,tl_south%i_width)
+               
+               tl_west%i_width =il_width
+               tl_south%i_width=il_width
+
+            ENDIF
+
+            td_bdy(jp_west )%t_seg(1) = tl_west
+            td_bdy(jp_south)%t_seg(1) = tl_south
+         ELSE
+
+            IF( td_var%d_value(tl_south%i_first,tl_south%i_index,1,1) /= &
+            &   td_var%d_fill )THEN
+               CALL logger_error("BOUNDARY CHEKC CORNER: wrong "//&
+               &              "south boundary first indice ")
+            ENDIF
+
+            IF( td_var%d_value(tl_west%i_index,tl_west%i_first,1,1) /= &
+            &   td_var%d_fill )THEN
+               CALL logger_error("BOUNDARY CHEKC CORNER: wrong "//&
+               &              "west boundary first indice")
+            ENDIF
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE boundary_check_corner 
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This subroutine check boundary.
+   ! 
+   !> @details 
+   !> It checks that first and last indices as well as orthogonal index are
+   !> inside domain, and check corner (see boundary_check_corner).
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[inout] td_bdy : boundary structure 
+   !> @param[in] td_var : variable structure 
+   !------------------------------------------------------------------- 
+   !> @code 
+   SUBROUTINE boundary_check(td_bdy, td_var) 
+      IMPLICIT NONE 
+      ! Argument
+      TYPE(TBDY) , DIMENSION(ip_ncard), INTENT(INOUT) :: td_bdy
+      TYPE(TVAR)                      , INTENT(IN   ) :: td_var
+
+      ! local variable 
+      INTEGER(i4)      , DIMENSION(ip_ncard) :: il_max
+      INTEGER(i4)      , DIMENSION(ip_ncard) :: il_maxindex
+
+      ! loop indices 
+      INTEGER(i4) :: jk
+      !---------------------------------------------------------------- 
+ 
+      il_max(jp_north)=td_var%t_dim(1)%i_len
+      il_max(jp_south)=td_var%t_dim(1)%i_len
+      il_max(jp_east )=td_var%t_dim(2)%i_len
+      il_max(jp_west )=td_var%t_dim(2)%i_len
+      
+      il_maxindex(jp_north)=td_var%t_dim(2)%i_len-ig_ghost
+      il_maxindex(jp_south)=td_var%t_dim(2)%i_len-ig_ghost
+      il_maxindex(jp_east )=td_var%t_dim(1)%i_len-ig_ghost
+      il_maxindex(jp_west )=td_var%t_dim(1)%i_len-ig_ghost
+
+      DO jk=1,ip_ncard
+         IF( td_bdy(jk)%l_use )THEN
+            IF( .NOT. ASSOCIATED(td_bdy(jk)%t_seg) )THEN
+               CALL logger_error("BOUNDARY CHECK: no segment associted "//&
+               &                 "to "//TRIM(td_bdy(jk)%c_card)//" boundary")
+            ELSE
+               ! check indices
+               IF( ANY(td_bdy(jk)%t_seg(:)%i_first < 1         ) .OR. &
+               &   ANY(td_bdy(jk)%t_seg(:)%i_first > il_max(jk)) .OR. &
+               &   ANY(td_bdy(jk)%t_seg(:)%i_last  < 1         ) .OR. &
+               &   ANY(td_bdy(jk)%t_seg(:)%i_last  > il_max(jk)) .OR. &
+               &   ANY(td_bdy(jk)%t_seg(:)%i_first > td_bdy(jk)%t_seg(:)%i_last)&
+               & )THEN
+                  CALL logger_error("BOUNDARY CHECK: invalid segment "//&
+                  &              "first and/or last indice for "//&
+                  &              TRIM(td_bdy(jk)%c_card)//&
+                  &              " boundary. check namelist")
+               ENDIF
+
+               IF( ANY(td_bdy(jk)%t_seg(:)%i_index < 1         ) .OR. &
+               &   ANY(td_bdy(jk)%t_seg(:)%i_index > il_maxindex(jk)) &
+               & )THEN
+                  CALL logger_error("BOUNDARY CHECK: invalid index "//&
+                  &              "for "//TRIM(td_bdy(jk)%c_card)//&
+                  &              " boundary. check namelist")
+               ENDIF
+            ENDIF
+         ENDIF
+      ENDDO
+      
+      CALL boundary_check_corner(td_bdy, td_var)
+
+   END SUBROUTINE boundary_check
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine clean interpolated boundary in variable structure.
+   !
+   !> @detail
+   !> interpolation could create more point than needed for boundary (depending
+   !> on refinement factor). This subroutine keep only useful point on variable
+   !> 
+   !> @note we use width define in first segment, cause every segment of a
+   !> boundary should have the same width 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable strucutre
+   !> @param[in   ] td_bdy : boundary strucutre
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE boundary_clean_interp( td_var, td_bdy )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+      TYPE(TBDY), INTENT(IN   ) :: td_bdy
+
+      ! local variable
+      TYPE(TVAR)  :: tl_var
+
+      INTEGER(i4) :: il_imin
+      INTEGER(i4) :: il_imax
+      INTEGER(i4) :: il_jmin
+      INTEGER(i4) :: il_jmax
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! copy input variable
+      tl_var=td_var
+
+      DEALLOCATE(td_var%d_value)
+
+      SELECT CASE(TRIM(td_bdy%c_card))
+      CASE('north')
+
+         il_imin=1
+         il_imax=tl_var%t_dim(1)%i_len
+         SELECT CASE(td_var%c_point)
+         CASE('V','F')
+            il_jmin=td_bdy%t_seg(1)%i_width+1
+            il_jmax=2
+         CASE DEFAULT ! 'T','U'
+            il_jmin=td_bdy%t_seg(1)%i_width
+            il_jmax=1
+         END SELECT
+
+         ! use width as dimension length
+         td_var%t_dim(2)%i_len=td_bdy%t_seg(1)%i_width
+
+      CASE('south')
+
+         il_imin=1
+         il_imax=tl_var%t_dim(1)%i_len
+
+         il_jmin=1
+         il_jmax=td_bdy%t_seg(1)%i_width
+         
+         ! use width as dimension length
+         td_var%t_dim(2)%i_len=td_bdy%t_seg(1)%i_width
+
+      CASE('east')
+
+         SELECT CASE(td_var%c_point)
+         CASE('U','F')
+            il_imin=td_bdy%t_seg(1)%i_width+1
+            il_imax=2
+         CASE DEFAULT ! 'T','V'
+            il_imin=td_bdy%t_seg(1)%i_width
+            il_imax=1
+         END SELECT
+
+         il_jmin=1
+         il_jmax=tl_var%t_dim(2)%i_len
+
+         ! use width as dimension length
+         td_var%t_dim(1)%i_len=td_bdy%t_seg(1)%i_width
+
+      CASE('west')
+
+         il_imin=1
+         il_imax=td_bdy%t_seg(1)%i_width
+
+         il_jmin=1
+         il_jmax=tl_var%t_dim(2)%i_len
+
+         ! use width as dimension length
+         td_var%t_dim(1)%i_len=td_bdy%t_seg(1)%i_width
+
+      END SELECT
+
+
+      ALLOCATE( td_var%d_value(td_var%t_dim(1)%i_len, &
+      &                        td_var%t_dim(2)%i_len, &
+      &                        td_var%t_dim(3)%i_len, &
+      &                        td_var%t_dim(4)%i_len) )
+
+      IF( il_imin > il_imax )THEN
+         il_imin=tl_var%t_dim(1)%i_len-il_imin+1
+         il_imax=tl_var%t_dim(1)%i_len-il_imax+1
+      ENDIF
+
+      IF( il_jmin > il_jmax )THEN
+         il_jmin=tl_var%t_dim(2)%i_len-il_jmin+1
+         il_jmax=tl_var%t_dim(2)%i_len-il_jmax+1
+      ENDIF      
+
+      td_var%d_value(:,:,:,:)=tl_var%d_value( il_imin:il_imax, &
+      &                                       il_jmin:il_jmax, &
+      &                                       :,: )
+
+      CALL var_clean(tl_var)
+
+
+   END SUBROUTINE boundary_clean_interp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine swap array for east and north boundary.
+   !
+   !> @detail
+   !> 
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable strucutre
+   !> @param[in   ] td_bdy : boundary strucutre
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE boundary_swap( td_var, td_bdy )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+      TYPE(TBDY), INTENT(IN   ) :: td_bdy
+
+      ! local variable
+      REAL(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      IF( .NOT. ASSOCIATED(td_var%d_value) )THEN
+         CALL logger_error("BOUNDARY SWAP: no table of value "//&
+         &  "associted to variable "//TRIM(td_var%c_name) )
+      ELSE      
+
+         SELECT CASE(TRIM(td_bdy%c_card))
+         CASE('north')
+            ALLOCATE( dl_value(td_var%t_dim(1)%i_len, &
+            &                  td_var%t_dim(2)%i_len, &
+            &                  td_var%t_dim(3)%i_len, &
+            &                  td_var%t_dim(4)%i_len) )
+
+            dl_value(:,:,:,:)=td_var%d_value(:,:,:,:)
+
+            DO jj=1, td_var%t_dim(2)%i_len
+               td_var%d_value(:,jj,:,:) = &
+               &  dl_value(:,td_var%t_dim(2)%i_len-jj+1,:,:)
+            ENDDO
+
+            DEALLOCATE( dl_value )         
+         CASE('east')
+            ALLOCATE( dl_value(td_var%t_dim(1)%i_len, &
+            &                  td_var%t_dim(2)%i_len, &
+            &                  td_var%t_dim(3)%i_len, &
+            &                  td_var%t_dim(4)%i_len) )
+
+            dl_value(:,:,:,:)=td_var%d_value(:,:,:,:)
+
+            DO ji=1, td_var%t_dim(1)%i_len
+               td_var%d_value(ji,:,:,:) = &
+               &  dl_value(td_var%t_dim(1)%i_len-ji+1,:,:,:)
+            ENDDO
+
+            DEALLOCATE( dl_value )
+         CASE DEFAULT
+         ! nothing to be done
+         END SELECT
+
+      ENDIF
+   END SUBROUTINE boundary_swap
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This subroutine print information about one boundary 
+   ! 
+   !> @details 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[in] td_bdy : boundary structure 
+   !------------------------------------------------------------------- 
+   !> @code 
+   SUBROUTINE boundary__print_unit( td_bdy ) 
+      IMPLICIT NONE 
+      ! Argument
+      TYPE(TBDY), INTENT(IN) :: td_bdy
+      ! local variable 
+      ! loop indices 
+      INTEGER(i4) :: ji
+      !---------------------------------------------------------------- 
+
+      WRITE(*,'(a,/1x,a,/1x,a)') "Boundary "//TRIM(td_bdy%c_card), &
+      &  " use  "//TRIM(fct_str(td_bdy%l_use)), &
+      &  " nseg "//TRIM(fct_str(td_bdy%i_nseg))
+      DO ji=1,td_bdy%i_nseg
+         WRITE(*,'(4(/1x,a))') &
+         &  " index "//TRIM(fct_str(td_bdy%t_seg(ji)%i_index)), &
+         &  " width "//TRIM(fct_str(td_bdy%t_seg(ji)%i_width)), &
+         &  " first "//TRIM(fct_str(td_bdy%t_seg(ji)%i_first)), &
+         &  " last  "//TRIM(fct_str(td_bdy%t_seg(ji)%i_last))
+      ENDDO
+ 
+   END SUBROUTINE boundary__print_unit
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This subroutine print information about a table of boundary 
+   ! 
+   !> @details 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[in] td_bdy : boundary structure 
+   !------------------------------------------------------------------- 
+   !> @code 
+   SUBROUTINE boundary__print_tab( td_bdy ) 
+      IMPLICIT NONE 
+      ! Argument
+      TYPE(TBDY), DIMENSION(:), INTENT(IN) :: td_bdy
+      ! local variable 
+      ! loop indices 
+      INTEGER(i4) :: ji
+      !---------------------------------------------------------------- 
+
+      DO ji=1,SIZE(td_bdy(:))
+         CALL boundary_print(td_bdy(ji))
+      ENDDO
+ 
+   END SUBROUTINE boundary__print_tab
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine copy segment structure in another segment
+   !> structure
+   !> @details 
+   !>
+   !> @warning to avoid infinite loop, do not use any function inside 
+   !> this subroutine
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[out] td_seg1  : segment structure
+   !> @param[in] td_seg2  : segment structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE seg__copy( td_seg1, td_seg2 )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TSEG), INTENT(OUT) :: td_seg1
+      TYPE(TSEG), INTENT(IN)  :: td_seg2
+
+      ! local variable
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! copy segment index, width, ..
+      td_seg1%i_index    = td_seg2%i_index
+      td_seg1%i_width    = td_seg2%i_width
+      td_seg1%i_first    = td_seg2%i_first
+      td_seg1%i_last     = td_seg2%i_last 
+
+   END SUBROUTINE seg__copy
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This function  initialise segment structure.
+   ! 
+   !> @details 
+   !> It simply add orthogonal index, and optionnaly width, first
+   !> and last indices of the segment. 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[in] id_index : orthogonal index
+   !> @param[in] id_width : width of the segment 
+   !> @param[in] id_first : first indices 
+   !> @param[in] id_last  : last  indices
+   !> @return segment structure
+   !------------------------------------------------------------------- 
+   !> @code 
+   FUNCTION seg__init( id_index, id_width, id_first, id_last ) 
+      IMPLICIT NONE 
+      ! Argument
+      INTEGER(i4), INTENT(IN) :: id_index
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_width
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_first
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_last 
+
+      ! function 
+      TYPE(TSEG) :: seg__init
+
+      ! local variable 
+      
+      ! loop indices 
+      !---------------------------------------------------------------- 
+
+      seg__init%i_index=id_index
+
+      IF( PRESENT(id_width) ) seg__init%i_width=id_width
+      IF( PRESENT(id_first) ) seg__init%i_first=id_first
+      IF( PRESENT(id_last ) ) seg__init%i_last =id_last
+
+   END FUNCTION seg__init 
+   !> @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This subroutine clean segment structure. 
+   ! 
+   !> @details 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @param[inout] td_seg : segment structure
+   !------------------------------------------------------------------- 
+   !> @code 
+   SUBROUTINE seg__clean(td_seg) 
+      IMPLICIT NONE 
+      ! Argument       
+      TYPE(TSEG), INTENT(INOUT) :: td_seg
+      ! local variable 
+      TYPE(TSEG) :: tl_seg
+      ! loop indices 
+      !---------------------------------------------------------------- 
+
+      td_seg=tl_seg
+ 
+   END SUBROUTINE seg__clean 
+   !> @endcode
+!   !------------------------------------------------------------------- 
+!   !> @brief This function  
+!   ! 
+!   !> @details 
+!   ! 
+!   !> @author J.Paul 
+!   !> - Nov, 2013- Initial Version 
+!   ! 
+!   !> @param[in]  
+!   !------------------------------------------------------------------- 
+!   !> @code 
+!   FUNCTION boundary_() 
+!      IMPLICIT NONE 
+!      ! Argument       
+!      ! function 
+!      ! local variable 
+!      ! loop indices 
+!      !---------------------------------------------------------------- 
+! 
+!   END FUNCTION boundary_ 
+!   !> @endcode 
+!   !------------------------------------------------------------------- 
+!   !> @brief This subroutine  
+!   ! 
+!   !> @details 
+!   ! 
+!   !> @author J.Paul 
+!   !> - Nov, 2013- Initial Version 
+!   ! 
+!   !> @param[in]  
+!   !------------------------------------------------------------------- 
+!   !> @code 
+!   SUBROUTINE boundary_() 
+!      IMPLICIT NONE 
+!      ! Argument       
+!      ! local variable 
+!      ! loop indices 
+!      !---------------------------------------------------------------- 
+! 
+!   END SUBROUTINE boundary_ 
+!   !> @endcode
+END MODULE boundary
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/create_bathy.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/create_bathy.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/create_bathy.f90	(revision 4245)
@@ -0,0 +1,1011 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+!
+! PROGRAM: create_bathy
+!
+! DESCRIPTION:
+!> @brief 
+!> This program create bathymetry file.
+!>
+!> @details
+!> Bathymetry could be extracted from fine grid Bathymetry file, or interpolated
+!> from coarse grid Bathymetry file.
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!>
+!> @todo
+!> - add attributes indices and refinement in output file
+!----------------------------------------------------------------------
+!> @code
+PROGRAM create_bathy
+
+!   USE netcdf                          ! nf90 library
+   USE global                          ! global variable
+   USE kind                            ! F90 kind parameter
+   USE logger                          ! log file manager
+   USE fct                             ! basic useful function
+   USE date                            ! date manager
+   USE att                             ! attribute manager
+   USE dim                             ! dimension manager
+   USE var                             ! variable manager
+   USE file                            ! file manager
+   USE multi                           ! multi file manager
+   USE iom                             ! I/O manager
+   USE dom                             ! domain manager
+   USE grid                            ! grid manager
+   USE extrap                          ! extrapolation manager
+   USE interp                          ! interpolation manager
+   USE filter                          ! filter manager
+   USE mpp                             ! MPP manager
+   USE iom_mpp                         ! MPP I/O manager
+
+   IMPLICIT NONE
+
+   ! local variable
+   CHARACTER(LEN=lc)                                  :: cl_namelist
+   CHARACTER(LEN=lc)                                  :: cl_date
+   CHARACTER(LEN=lc)                                  :: cl_data
+
+   INTEGER(i4)                                        :: il_narg
+   INTEGER(i4)                                        :: il_status
+   INTEGER(i4)                                        :: il_fileid
+   INTEGER(i4)                                        :: il_attid
+   INTEGER(i4)                                        :: il_imin
+   INTEGER(i4)                                        :: il_imax
+   INTEGER(i4)                                        :: il_jmin
+   INTEGER(i4)                                        :: il_jmax
+   INTEGER(i4)      , DIMENSION(ip_maxdim)            :: il_rho
+   INTEGER(i4)      , DIMENSION(2,2)                  :: il_offset
+   INTEGER(i4)      , DIMENSION(2,2,2)                :: il_ind
+   INTEGER(i4)      , DIMENSION(:,:)    , ALLOCATABLE :: il_mask
+
+   LOGICAL                                            :: ll_exist
+
+   TYPE(TFILE)                                        :: tl_coord0
+   TYPE(TFILE)                                        :: tl_coord1
+   TYPE(TFILE)                                        :: tl_file
+   TYPE(TFILE)                                        :: tl_fileout
+
+   TYPE(TATT)                                         :: tl_att
+   
+   TYPE(TVAR)                                         :: tl_lon
+   TYPE(TVAR)                                         :: tl_lat
+   TYPE(TVAR)                                         :: tl_depth
+   TYPE(TVAR)                                         :: tl_time
+
+   TYPE(TVAR)                                         :: tl_tmp
+   TYPE(TVAR)       , DIMENSION(:), ALLOCATABLE       :: tl_var
+   
+   TYPE(TDIM)       , DIMENSION(ip_maxdim)            :: tl_dim
+
+   TYPE(TMULTI)                                       :: tl_multi
+
+   ! loop indices
+   INTEGER(i4) :: ji
+   INTEGER(i4) :: jj
+   INTEGER(i4) :: jk
+
+   ! namelist variable
+   CHARACTER(LEN=lc) :: cn_logfile = 'create_bathy.log' 
+   CHARACTER(LEN=lc) :: cn_verbosity = 'warning' 
+
+   CHARACTER(LEN=lc) :: cn_varcfg = 'variable.cfg' 
+
+   CHARACTER(LEN=lc) :: cn_coord0 = '' 
+   INTEGER(i4)       :: in_perio0 = -1
+
+   CHARACTER(LEN=lc) :: cn_coord1 = ''
+   INTEGER(i4)       :: in_perio1 = -1
+   LOGICAL           :: ln_fillclosed = .TRUE.
+
+   CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varinfo = ''
+   CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varfile = ''
+
+   INTEGER(i4)       :: in_imin0 = 0
+   INTEGER(i4)       :: in_imax0 = 0
+   INTEGER(i4)       :: in_jmin0 = 0
+   INTEGER(i4)       :: in_jmax0 = 0
+   INTEGER(i4)       :: in_rhoi  = 1
+   INTEGER(i4)       :: in_rhoj  = 1
+
+   CHARACTER(LEN=lc) :: cn_fileout = 'bathy_fine.nc' 
+   !-------------------------------------------------------------------
+
+   NAMELIST /namlog/ &  !< logger namelist
+   &  cn_logfile,    &  !< log file
+   &  cn_verbosity      !< log verbosity
+
+   NAMELIST /namcfg/ &  !< configuration namelist
+   &  cn_varcfg         !< variable configuration file
+
+   NAMELIST /namcrs/ &   !< coarse grid namelist
+   &  cn_coord0,  &      !< coordinate file
+   &  in_perio0          !< periodicity index
+   
+   NAMELIST /namfin/ &   !< fine grid namelist
+   &  cn_coord1,   &     !< coordinate file
+   &  in_perio1,   &     !< periodicity index
+   &  ln_fillclosed      !< fill closed sea
+ 
+   NAMELIST /namvar/ &  !< variable namelist
+   &  cn_varinfo, &     !< list of variable and interpolation method to be used. (ex: 'votemper:linear','vosaline:cubic' )
+   &  cn_varfile        !< list of variable file
+   
+   NAMELIST /namnst/ &  !< nesting namelist
+   &  in_imin0,   &     !< i-direction lower left  point indice 
+   &  in_imax0,   &     !< i-direction upper right point indice
+   &  in_jmin0,   &     !< j-direction lower left  point indice
+   &  in_jmax0,   &     !< j-direction upper right point indice
+   &  in_rhoi,    &     !< refinement factor in i-direction
+   &  in_rhoj           !< refinement factor in j-direction
+
+   NAMELIST /namout/ &  !< output namlist
+   &  cn_fileout       !< fine grid bathymetry file
+   !-------------------------------------------------------------------
+
+   !1- namelist
+   !1-1 get namelist
+   il_narg=COMMAND_ARGUMENT_COUNT() !f03 intrinsec
+   IF( il_narg/=1 )THEN
+      PRINT *,"ERROR in create_bathy: need a namelist"
+      STOP
+   ELSE
+      CALL GET_COMMAND_ARGUMENT(1,cl_namelist) !f03 intrinsec
+   ENDIF
+   
+   !1-2 read namelist
+   INQUIRE(FILE=TRIM(cl_namelist), EXIST=ll_exist)
+   IF( ll_exist )THEN
+      
+      il_fileid=fct_getunit()
+
+      OPEN( il_fileid, FILE=TRIM(cl_namelist), &
+      &                FORM='FORMATTED',       &
+      &                ACCESS='SEQUENTIAL',    &
+      &                STATUS='OLD',           &
+      &                ACTION='READ',          &
+      &                IOSTAT=il_status)
+      CALL fct_err(il_status)
+      IF( il_status /= 0 )THEN
+         PRINT *,"ERROR in create_bathy: error opening "//TRIM(cl_namelist)
+         STOP
+      ENDIF
+
+      READ( il_fileid, NML = namlog )
+      !1-2-1 define log file
+      CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity))
+      CALL logger_header()
+
+      READ( il_fileid, NML = namcfg )
+      !1-2-2 get variable extra information
+      CALL var_def_extra(TRIM(cn_varcfg))
+
+      READ( il_fileid, NML = namcrs )
+      READ( il_fileid, NML = namfin )
+      READ( il_fileid, NML = namvar )
+      !1-2-3 add user change in extra information
+      CALL var_chg_extra(cn_varinfo)
+      !1-2-4 match variable with file
+      tl_multi=multi_init(cn_varfile)
+      
+      READ( il_fileid, NML = namnst )
+      READ( il_fileid, NML = namout )
+
+      CLOSE( il_fileid, IOSTAT=il_status )
+      CALL fct_err(il_status)
+      IF( il_status /= 0 )THEN
+         CALL logger_error("CREATE BATHY: closing "//TRIM(cl_namelist))
+      ENDIF
+
+   ELSE
+
+      PRINT *,"ERROR in create_bathy: can't find "//TRIM(cl_namelist)
+
+   ENDIF
+
+   !2- open files
+   IF( cn_coord0 /= '' )THEN
+      tl_coord0=file_init(TRIM(cn_coord0),id_perio=in_perio0)
+      CALL iom_open(tl_coord0)
+   ELSE
+      CALL logger_fatal("CREATE BATHY: no coarse grid coordinate found. "//&
+      &     "check namelist")      
+   ENDIF
+
+   IF( TRIM(cn_coord1) /= '' )THEN
+      tl_coord1=file_init(TRIM(cn_coord1),id_perio=in_perio1)
+      CALL iom_open(tl_coord1)
+   ELSE
+      CALL logger_fatal("CREATE BATHY: no fine grid coordinate found. "//&
+      &     "check namelist")
+   ENDIF
+
+   !3- check
+   !3-1 check output file do not already exist
+   INQUIRE(FILE=TRIM(cn_fileout), EXIST=ll_exist)
+   IF( ll_exist )THEN
+      CALL logger_fatal("CREATE BATHY: output file "//TRIM(cn_fileout)//&
+      &  " already exist.")
+   ENDIF
+
+   !3-2 check namelist
+   !3-2-1 check refinement factor
+   il_rho(:)=1
+   IF( in_rhoi < 1 .OR. in_rhoj < 1 )THEN
+      CALL logger_error("CREATE BATHY: invalid refinement factor."//&
+      &  " check namelist "//TRIM(cl_namelist))
+   ELSE
+      il_rho(jp_I)=in_rhoi
+      il_rho(jp_J)=in_rhoj
+   ENDIF
+
+   !3-2-2 check domain indices
+   IF( in_imin0 < 1 .OR. in_imax0 < 1 .OR. &
+   &   in_jmin0 < 1 .OR. in_jmax0 < 1)THEN
+      ! compute coarse grid indices around fine grid
+      IF( cn_coord0 /= '' )THEN
+         il_ind(:,:,:)=grid_get_coarse_index( tl_coord0, tl_coord1, &
+         &                                    id_rho=il_rho(:) )
+      ENDIF
+
+      il_imin=il_ind(1,1,1) ; il_imax=il_ind(1,2,1)
+      il_jmin=il_ind(2,1,1) ; il_jmax=il_ind(2,2,1)
+
+      il_offset(:,:)=il_ind(:,:,2)
+   ELSE
+      il_imin=in_imin0 ; il_imax=in_imax0
+      il_jmin=in_jmin0 ; il_jmax=in_jmax0
+
+      il_offset(jp_I,:)=FLOOR(REAL(il_rho(jp_I)-1,dp)*0.5)
+      il_offset(jp_J,:)=FLOOR(REAL(il_rho(jp_J)-1,dp)*0.5)
+   ENDIF
+
+   !3-2-3 check domain validity
+   IF( cn_coord0 /= '' )THEN
+      CALL grid_check_dom(tl_coord0, il_imin, il_imax, il_jmin, il_jmax)
+   ENDIF
+
+   !3-2-4 check coincidence between coarse and fine grid
+   IF( cn_coord0 /= '' )THEN
+      CALL grid_check_coincidence( tl_coord0, tl_coord1, &
+      &                            il_imin, il_imax, &
+      &                            il_jmin, il_jmax, &
+      &                            il_rho(:) )
+   ENDIF
+
+   IF( .NOT. ASSOCIATED(tl_multi%t_file) )THEN
+      CALL logger_error("CREATE BATHY: no file to work on. "//&
+      &                 "check cn_varfile in namelist.")
+   ELSE
+      ALLOCATE( tl_var( tl_multi%i_nvar ) )
+      jk=0
+      DO ji=1,tl_multi%i_nfile
+         WRITE(cl_data,'(a,i2.2)') 'data_',jk+1
+         IF( .NOT. ASSOCIATED(tl_multi%t_file(ji)%t_var) )THEN
+            CALL logger_error("CREATE BATHY: no variable to work on for "//&
+            &                 "file"//TRIM(tl_multi%t_file(ji)%c_name)//&
+            &                 ". check cn_varfile in namelist.")
+         ELSEIF( TRIM(tl_multi%t_file(ji)%c_name) == TRIM(cl_data) )THEN
+            DO jj=1,tl_multi%t_file(ji)%i_nvar
+               jk=jk+1
+               tl_tmp=tl_multi%t_file(ji)%t_var(jj)
+               !- use input matrix to initialise variable
+               tl_var(jk)=create_bathy_matrix(tl_tmp, tl_coord1)
+            ENDDO
+         ELSE
+            ! open file
+            tl_file=file_init(TRIM(tl_multi%t_file(ji)%c_name))
+            CALL iom_open(tl_file)
+
+            ! get or check depth value
+            IF( tl_file%i_depthid /= 0 )THEN
+               IF( ASSOCIATED(tl_depth%d_value) )THEN
+                  IF( ANY( tl_depth%d_value(:,:,:,:) /= &
+                  &        tl_tmp%d_value(:,:,:,:) ) )THEN
+                     CALL logger_fatal("CREATE BATHY: depth value from "//&
+                     &  TRIM(tl_multi%t_file(ji)%c_name)//" not conform "//&
+                     &  " to those from former file(s).")
+                  ENDIF
+               ELSE
+                  tl_depth=iom_read_var(tl_file,tl_file%i_depthid)
+               ENDIF
+            ENDIF
+
+            ! get or check time value
+            IF( tl_file%i_timeid /= 0 )THEN
+               IF( ASSOCIATED(tl_time%d_value) )THEN
+                  IF( ANY( tl_time%d_value(:,:,:,:) /= &
+                  &        tl_tmp%d_value(:,:,:,:) ) )THEN
+                     CALL logger_fatal("CREATE BATHY: time value from "//&
+                     &  TRIM(tl_multi%t_file(ji)%c_name)//" not conform "//&
+                     &  " to those from former file(s).")
+                  ENDIF
+               ELSE
+                  tl_time=iom_read_var(tl_file,tl_file%i_timeid)
+               ENDIF
+            ENDIF
+
+            IF( ANY( tl_file%t_dim(1:2)%i_len /= &
+            &      tl_coord0%t_dim(1:2)%i_len) )THEN
+               DO jj=1,tl_multi%t_file(ji)%i_nvar
+                  jk=jk+1
+                  tl_tmp=tl_multi%t_file(ji)%t_var(jj)
+                  !- extract bathymetry from fine grid bathymetry 
+                  tl_var(jk)=create_bathy_extract( tl_tmp, tl_file, &
+                  &                                tl_coord1 )
+               ENDDO
+            ELSE
+               DO jj=1,tl_multi%t_file(ji)%i_nvar
+                  jk=jk+1
+                  tl_tmp=tl_multi%t_file(ji)%t_var(jj)
+                  !- get bathymetry from coarse grid bathymetry 
+                  tl_var(jk)=create_bathy_get_var( tl_tmp, tl_file,  &
+                  &                                il_imin, il_jmin, &
+                  &                                il_imax, il_jmax, &
+                  &                                il_offset(:,:),   &
+                  &                                il_rho(:) )
+               ENDDO
+            ENDIF
+
+            ! close file
+            CALL iom_close(tl_file)
+            ! clean structure
+            CALL file_clean(tl_file)
+         ENDIF
+      ENDDO
+   ENDIF
+
+   DO jk=1,tl_multi%i_nvar
+         !6- forced min and max value
+         CALL var_limit_value(tl_var(jk))
+
+         !7- fill closed sea
+         IF( TRIM(tl_var(jk)%c_stdname) == 'bathymetry' .AND. &
+             ln_fillclosed )THEN
+            ALLOCATE( il_mask(tl_var(jk)%t_dim(1)%i_len, &
+            &                 tl_var(jk)%t_dim(2)%i_len) )
+
+            !7-1 split domain in N sea subdomain
+            il_mask(:,:)=grid_split_domain(tl_var(jk))
+
+            !7-2  fill smallest domain
+            CALL grid_fill_small_dom( tl_var(jk), il_mask(:,:) )
+
+            DEALLOCATE( il_mask )
+         ENDIF
+
+         !8- filter
+         CALL filter_fill_value(tl_var(jk))
+
+         !9- check bathymetry
+         IF( TRIM(tl_var(jk)%c_stdname) == 'bathymetry' .AND. &
+         &   MINVAL(tl_var(jk)%d_value(:,:,:,:)) <= 0._dp  )THEN
+            CALL logger_error("CREATE BATHY: Bathymetry has value <= 0")
+         ENDIF
+   ENDDO
+
+
+   !10- create file
+   tl_fileout=file_init(TRIM(cn_fileout),id_perio=in_perio1)
+
+   !10-1 add dimension
+   tl_dim(:)=var_max_dim(tl_var(:))
+
+   DO ji=1,ip_maxdim
+      IF( tl_dim(ji)%l_use ) CALL file_add_dim(tl_fileout, tl_dim(ji))
+   ENDDO
+
+   !10-2 add variables
+   IF( ALL( tl_dim(1:2)%l_use ) )THEN
+
+      ! add longitude
+      tl_lon=iom_read_var(tl_coord1,'longitude')
+      CALL file_add_var(tl_fileout, tl_lon)
+      CALL var_clean(tl_lon)
+
+      ! add latitude
+      tl_lat=iom_read_var(tl_coord1,'latitude')
+      CALL file_add_var(tl_fileout, tl_lat)
+      CALL var_clean(tl_lat)
+
+   ENDIF
+
+   IF( tl_dim(3)%l_use )THEN
+      ! add depth
+      CALL file_add_var(tl_fileout, tl_depth)
+      CALL var_clean(tl_depth)
+   ENDIF
+
+   IF( tl_dim(4)%l_use )THEN
+      ! add time
+      CALL file_add_var(tl_fileout, tl_time)
+      CALL var_clean(tl_time)
+   ENDIF
+
+   ! add other variables
+   DO jk=1,tl_multi%i_nvar
+      CALL file_add_var(tl_fileout, tl_var(jk))
+      CALL var_clean(tl_var(jk))
+   ENDDO
+
+   !10-3 add some attribute
+   tl_att=att_init("Created_by","SIREN create_bathy")
+   CALL file_add_att(tl_fileout, tl_att)
+
+   cl_date=date_print(date_now())
+   tl_att=att_init("Creation_date",cl_date)
+   CALL file_add_att(tl_fileout, tl_att)
+
+   ! add attribute periodicity
+   il_attid=0
+   IF( ASSOCIATED(tl_fileout%t_att) )THEN
+      il_attid=att_get_id(tl_fileout%t_att(:),'periodicity')
+   ENDIF
+   IF( tl_coord1%i_perio >= 0 .AND. il_attid == 0 )THEN
+      tl_att=att_init('periodicity',tl_coord1%i_perio)
+      CALL file_add_att(tl_fileout,tl_att)
+   ENDIF
+
+   il_attid=0
+   IF( ASSOCIATED(tl_fileout%t_att) )THEN
+      il_attid=att_get_id(tl_fileout%t_att(:),'ew_overlap')
+   ENDIF
+   IF( tl_coord1%i_ew >= 0 .AND. il_attid == 0 )THEN
+      tl_att=att_init('ew_overlap',tl_coord1%i_ew)
+      CALL file_add_att(tl_fileout,tl_att)
+   ENDIF
+
+   !10-4 create file
+   CALL iom_create(tl_fileout)
+
+   !10-5 write file
+   CALL iom_write_file(tl_fileout)
+
+   !10-6 close file
+   CALL iom_close(tl_fileout)
+   IF( cn_coord0 /= '' ) CALL iom_close(tl_coord0)
+
+   !11- clean
+   DEALLOCATE(tl_var)
+
+   CALL file_clean(tl_fileout)
+   CALL file_clean(tl_coord1)
+   CALL file_clean(tl_coord0)
+
+   ! close log file
+   CALL logger_footer()
+   CALL logger_close()
+
+!> @endcode
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION create_bathy_matrix(td_var, td_coord)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_var
+      TYPE(TFILE), INTENT(IN) :: td_coord
+
+      ! function
+      TYPE(TVAR) :: create_bathy_matrix
+
+      ! local variable
+      INTEGER(i4)                                        :: il_ighost
+      INTEGER(i4)                                        :: il_jghost
+      INTEGER(i4)      , DIMENSION(2)                    :: il_xghost
+      INTEGER(i4)      , DIMENSION(3)                    :: il_dim
+      INTEGER(i4)      , DIMENSION(3)                    :: il_size
+      INTEGER(i4)      , DIMENSION(3)                    :: il_rest
+
+      INTEGER(i4)      , DIMENSION(:)      , ALLOCATABLE :: il_ishape
+      INTEGER(i4)      , DIMENSION(:)      , ALLOCATABLE :: il_jshape
+      INTEGER(i4)      , DIMENSION(:)      , ALLOCATABLE :: il_kshape
+
+      REAL(dp)         , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      TYPE(TVAR)                                         :: tl_lon
+      TYPE(TVAR)                                         :: tl_lat
+      TYPE(TVAR)                                         :: tl_var
+      TYPE(TDIM)       , DIMENSION(ip_maxdim)            :: tl_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      !1- read output grid
+      tl_lon=iom_read_var(td_coord,'longitude')
+      tl_lat=iom_read_var(td_coord,'latitude')
+
+      !2- look for ghost cell
+      il_xghost(:)=grid_get_ghost( tl_lon, tl_lat )
+
+      il_ighost=il_xghost(1)*ig_ghost
+      il_jghost=il_xghost(2)*ig_ghost
+      
+      !3- write value on grid
+      !3-1 get matrix dimension
+      il_dim(:)=td_var%t_dim(1:3)%i_len
+      !3-2 output dimension
+      tl_dim(:)=tl_lon%t_dim(:)
+
+      ! remove ghost cell
+      tl_dim(1)%i_len=tl_dim(1)%i_len - 2*il_xghost(1)*ig_ghost
+      tl_dim(2)%i_len=tl_dim(2)%i_len - 2*il_xghost(2)*ig_ghost
+
+      !3-3 split output domain in N subdomain depending of matrix dimension 
+      il_size(:) = tl_dim(1:3)%i_len / il_dim(:)
+      il_rest(:) = MOD(tl_dim(1:3)%i_len, il_dim(:))
+
+      ALLOCATE( il_ishape(il_dim(1)+1) )
+      il_ishape(:)=0
+      DO ji=2,il_dim(1)+1
+         il_ishape(ji)=il_ishape(ji-1)+il_size(1)
+      ENDDO
+      ! add rest to last cell
+      il_ishape(il_dim(1)+1)=il_ishape(il_dim(1)+1)+il_rest(1)
+      
+
+      ALLOCATE( il_jshape(il_dim(2)+1) )
+      il_jshape(:)=0
+      DO jj=2,il_dim(2)+1
+         il_jshape(jj)=il_jshape(jj-1)+il_size(2)
+      ENDDO
+      ! add rest to last cell
+      il_jshape(il_dim(2)+1)=il_jshape(il_dim(2)+1)+il_rest(2)
+
+      ALLOCATE( il_kshape(il_dim(3)+1) )
+      il_kshape(:)=0
+      DO jk=2,il_dim(3)+1
+         il_kshape(jk)=il_kshape(jk-1)+il_size(3)
+      ENDDO
+      ! add rest to last cell
+      il_kshape(il_dim(3)+1)=il_kshape(il_dim(3)+1)+il_rest(3)
+
+      !3-3 write ouput table of value 
+      ALLOCATE(dl_value( tl_dim(1)%i_len, &
+      &                  tl_dim(2)%i_len, &
+      &                  tl_dim(3)%i_len, &
+      &                  tl_dim(4)%i_len) )
+
+      dl_value(:,:,:,:)=0
+
+      DO jk=2,il_dim(3)+1
+         DO jj=2,il_dim(2)+1
+            DO ji=2,il_dim(1)+1
+               
+               dl_value( 1+il_ishape(ji-1):il_ishape(ji), &
+               &         1+il_jshape(jj-1):il_jshape(jj), &
+               &         1+il_kshape(jk-1):il_kshape(jk), &
+               &         1 ) = td_var%d_value(ji-1,jj-1,jk-1,1)
+
+            ENDDO
+         ENDDO
+      ENDDO
+
+      !3-4 initialise variable with value
+      tl_var=var_init(TRIM(td_var%c_name),dl_value(:,:,:,:))
+
+      DEALLOCATE(dl_value)
+
+      !4- add ghost cell
+      CALL grid_add_ghost(tl_var,il_ighost,il_jghost)
+
+      !5- save result
+      create_bathy_matrix=tl_var
+
+   END FUNCTION create_bathy_matrix
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION create_bathy_extract(td_var, td_file, &
+   &                             td_coord)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_var  
+      TYPE(TFILE), INTENT(IN) :: td_file
+      TYPE(TFILE), INTENT(IN) :: td_coord
+
+      ! function
+      TYPE(TVAR) :: create_bathy_extract
+
+      ! local variable
+      INTEGER(i4), DIMENSION(2,2,2) :: il_ind
+
+      INTEGER(i4) :: il_pivot
+      INTEGER(i4) :: il_perio
+
+      INTEGER(i4) :: il_imin
+      INTEGER(i4) :: il_jmin
+      INTEGER(i4) :: il_imax
+      INTEGER(i4) :: il_jmax
+
+      TYPE(TFILE) :: tl_file
+
+      TYPE(TMPP)  :: tl_mpp
+
+      TYPE(TATT)  :: tl_att
+
+      TYPE(TVAR)  :: tl_var
+      
+      TYPE(TDOM)  :: tl_dom
+      ! loop indices
+      !----------------------------------------------------------------
+
+      IF( td_file%i_id == 0 )THEN
+         CALL logger_error("CREATE BATHY EXTRACT: file "//&
+         &  TRIM(td_file%c_name)//" not opened ")
+      ELSE
+
+         !init
+         tl_file=td_file
+
+         !1- open file
+         CALL iom_open(tl_file)
+
+         ! get periodicity
+         il_pivot=grid_get_pivot(tl_file)
+         il_perio=grid_get_perio(tl_file,il_pivot)
+
+         tl_file%i_perio=il_perio
+
+         !2- compute file grid indices around coord grid
+         il_ind(:,:,:)=grid_get_coarse_index(tl_file, td_coord )
+
+         il_imin=il_ind(1,1,1) ; il_imax=il_ind(1,2,1)
+         il_jmin=il_ind(2,1,1) ; il_jmax=il_ind(2,2,1)
+
+         IF( ANY( il_ind(:,:,2) /= 0 ) )THEN
+            CALL logger_error("CREATE BATHY EXTRACT: something wrong "//&
+            &  " find offset when extracting data")
+         ENDIF
+         !3- check grid coincidence
+         CALL grid_check_coincidence( tl_file, td_coord, &
+         &                            il_imin, il_imax, &
+         &                            il_jmin, il_jmax, &
+         &                            (/1, 1, 1/) )
+
+         !4- compute domain
+         tl_dom=dom_init(tl_file,         &
+         &               il_imin, il_imax, &
+         &               il_jmin, il_jmax)
+
+         ! close file
+         CALL iom_close(tl_file)
+
+         !5- read bathymetry on domain (ugly way to do it, have to work on it)
+         !5-1 init mpp structure
+         tl_mpp=mpp_init(tl_file)
+
+         CALL file_clean(tl_file)
+
+         !5-2 get processor to be used
+         CALL mpp_get_use( tl_mpp, tl_dom )
+
+         !5-3 open mpp files
+         CALL iom_mpp_open(tl_mpp)
+
+         !5-4 read variable on domain
+         tl_var=iom_mpp_read_var(tl_mpp,TRIM(td_var%c_name),td_dom=tl_dom)
+
+         !5-5 close mpp file
+         CALL iom_mpp_close(tl_mpp)
+
+         !6- add ghost cell
+         CALL grid_add_ghost(tl_var,tl_dom%i_ighost,tl_dom%i_jghost)
+
+         !7- check result
+         IF( ANY( tl_var%t_dim(:)%l_use .AND. &
+         &        tl_var%t_dim(:)%i_len /= td_coord%t_dim(:)%i_len) )THEN
+            CALL logger_debug("CREATE BATHY EXTRACT: "//&
+            &        "dimensoin of variable "//TRIM(td_var%c_name)//" "//&
+            &        TRIM(fct_str(tl_var%t_dim(1)%i_len))//","//&
+            &        TRIM(fct_str(tl_var%t_dim(2)%i_len))//","//&
+            &        TRIM(fct_str(tl_var%t_dim(3)%i_len))//","//&
+            &        TRIM(fct_str(tl_var%t_dim(4)%i_len)) )
+            CALL logger_debug("CREATE BATHY EXTRACT: "//&
+            &        "dimensoin of coordinate file "//&
+            &        TRIM(fct_str(td_coord%t_dim(1)%i_len))//","//&
+            &        TRIM(fct_str(td_coord%t_dim(2)%i_len))//","//&
+            &        TRIM(fct_str(td_coord%t_dim(3)%i_len))//","//&
+            &        TRIM(fct_str(td_coord%t_dim(4)%i_len)) )
+            CALL logger_fatal("CREATE BATHY EXTRACT: "//&
+            &  "dimensoin of extracted "//&
+            &  "variable and coordinate file dimension differ")
+         ENDIF
+
+         !8- add attribute to variable
+         tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name)))
+         CALL var_move_att(tl_var, tl_att)         
+
+         tl_att=att_init('src_i-indices',(/tl_dom%i_imin, tl_dom%i_imax/))
+         CALL var_move_att(tl_var, tl_att)
+
+         tl_att=att_init('src_j-indices',(/tl_dom%i_jmin, tl_dom%i_jmax/))
+         CALL var_move_att(tl_var, tl_att)
+
+         !9- save result
+         create_bathy_extract=tl_var
+
+         ! clean structure
+         CALL var_clean(tl_var)
+         CALL mpp_clean(tl_mpp)
+      ENDIF
+
+   END FUNCTION create_bathy_extract
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] td_var : variable structure
+   !> @param[in] td_file : file structure
+   !> @param[in] id_imin : i-direction lower left  corner indice 
+   !> @param[in] id_imax : i-direction upper right corner indice 
+   !> @param[in] id_jmin : j-direction lower left  corner indice
+   !> @param[in] id_jmax : j-direction upper right corner indice 
+   !> @param[in] id_rho  : table of refinement factor
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION create_bathy_get_var(td_var, td_file,  &
+            &                    id_imin, id_jmin, &
+            &                    id_imax, id_jmax, &
+            &                    id_offset,        &
+            &                    id_rho )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_var  
+      TYPE(TFILE), INTENT(IN) :: td_file  
+      INTEGER(i4), INTENT(IN) :: id_imin
+      INTEGER(i4), INTENT(IN) :: id_imax
+      INTEGER(i4), INTENT(IN) :: id_jmin
+      INTEGER(i4), INTENT(IN) :: id_jmax
+      INTEGER(i4), DIMENSION(:,:), INTENT(IN) :: id_offset
+      INTEGER(i4), DIMENSION(:)  , INTENT(IN) :: id_rho
+
+      ! function
+      TYPE(TVAR) :: create_bathy_get_var
+
+      ! local variable
+      INTEGER(i4) :: il_pivot
+      INTEGER(i4) :: il_perio
+
+      TYPE(TFILE) :: tl_file
+
+      TYPE(TMPP)  :: tl_mpp
+
+      TYPE(TATT)  :: tl_att
+
+      TYPE(TVAR)  :: tl_var
+      
+      TYPE(TDOM)  :: tl_dom
+
+      ! loop indices
+      !----------------------------------------------------------------
+      IF( ANY(SHAPE(id_offset(:,:)) /= 2) )THEN
+         CALL logger_error("CREATE BATHY GET VAR: invalid dimensio of "//&
+         &                 "offset table")
+      ENDIF
+
+      !init
+      tl_file=td_file
+
+      !1- open file
+      CALL iom_open(tl_file)
+
+      ! get periodicity
+      il_pivot=grid_get_pivot(tl_file)
+      il_perio=grid_get_perio(tl_file,il_pivot)
+
+      tl_file%i_perio=il_perio
+
+      !2- compute domain
+      tl_dom=dom_init(tl_file,          &
+      &               id_imin, id_imax, &
+      &               id_jmin, id_jmax)
+
+      CALL dom_print(tl_dom)
+      print *,'id_offset ',id_offset(:,:)
+      !3- close file
+      CALL iom_close(tl_file)      
+
+      !4- add extra band (if possible) to compute interpolation
+      CALL dom_add_extra(tl_dom)
+
+      !5- read bathymetry on domain (ugly way to do it, have to work on it)
+      !5-1 init mpp sturcutre
+      tl_mpp=mpp_init(tl_file)
+
+      CALL file_clean(tl_file)
+
+      !5-2 get processor to be used
+      CALL mpp_get_use( tl_mpp, tl_dom )
+
+      !5-3 open mpp files
+      CALL iom_mpp_open(tl_mpp)
+
+      !5-4 read variable value on domain
+      tl_var=iom_mpp_read_var(tl_mpp,TRIM(td_var%c_name),td_dom=tl_dom)
+
+      !5-5 close mpp files
+      CALL iom_mpp_close(tl_mpp)      
+
+      !6- interpolate variable
+      CALL create_bathy_interp(tl_var, id_rho(:), id_offset(:,:))
+
+      !7- remove extraband added to domain
+      CALL dom_del_extra( tl_var, tl_dom, id_rho(:) )
+
+      !8- add ghost cell
+      CALL grid_add_ghost(tl_var,tl_dom%i_ighost,tl_dom%i_jghost)
+ 
+      !9- add attribute to variable
+      tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name)))
+      CALL var_move_att(tl_var, tl_att)
+
+      tl_att=att_init('src_i-indices',(/tl_dom%i_imin, tl_dom%i_imax/))
+      CALL var_move_att(tl_var, tl_att)
+
+      tl_att=att_init('src_j-indices',(/tl_dom%i_jmin, tl_dom%i_jmax/))
+      CALL var_move_att(tl_var, tl_att)
+
+      !10- save result
+      create_bathy_get_var=tl_var
+
+      !11- clean structure
+      CALL mpp_clean(tl_mpp)
+ 
+   END FUNCTION create_bathy_get_var
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] 
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE create_bathy_interp( td_var,         &
+   &                               id_rho,          &
+   &                               id_offset,       &
+   &                               id_iext, id_jext)
+
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TVAR) ,                 INTENT(INOUT) :: td_var
+      INTEGER(i4), DIMENSION(:)  , INTENT(IN   ) :: id_rho
+      INTEGER(i4), DIMENSION(:,:), INTENT(IN   ) :: id_offset
+      INTEGER(i4),                 INTENT(IN   ), OPTIONAL :: id_iext
+      INTEGER(i4),                 INTENT(IN   ), OPTIONAL :: id_jext
+
+      ! local variable
+      TYPE(TVAR)  :: tl_var
+      TYPE(TVAR)  :: tl_mask
+
+      INTEGER(i1), DIMENSION(:,:,:,:), ALLOCATABLE :: bl_mask
+
+      INTEGER(i4) :: il_iext
+      INTEGER(i4) :: il_jext
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! copy variable
+      tl_var=td_var
+
+      !WARNING: two extrabands are required for cubic interpolation
+      il_iext=3
+      IF( PRESENT(id_iext) ) il_iext=id_iext
+
+      il_jext=3
+      IF( PRESENT(id_jext) ) il_jext=id_jext
+
+      IF( il_iext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN
+         CALL logger_warn("CREATE BATHY INTERP: at least extrapolation "//&
+         &  "on two points are required with cubic interpolation ")
+         il_iext=2
+      ENDIF
+
+      IF( il_jext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN
+         CALL logger_warn("CREATE BATHY INTERP: at least extrapolation "//&
+         &  "on two points are required with cubic interpolation ")
+         il_jext=2
+      ENDIF
+
+      !1- work on mask
+      !1-1 create mask
+      ALLOCATE(bl_mask(tl_var%t_dim(1)%i_len, &
+      &                tl_var%t_dim(2)%i_len, &
+      &                tl_var%t_dim(3)%i_len, &
+      &                tl_var%t_dim(4)%i_len) )
+
+      bl_mask(:,:,:,:)=1
+      WHERE(tl_var%d_value(:,:,:,:)==tl_var%d_fill) bl_mask(:,:,:,:)=0      
+
+      SELECT CASE(TRIM(tl_var%c_point))
+      CASE DEFAULT ! 'T'
+         tl_mask=var_init('tmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
+      CASE('U')
+         tl_mask=var_init('umask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
+      CASE('V')
+         tl_mask=var_init('vmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
+      CASE('F')
+         tl_mask=var_init('fmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
+      END SELECT
+
+      DEALLOCATE(bl_mask)
+
+      !1-2 interpolate mask
+      CALL interp_fill_value( tl_mask, id_rho(:), &
+      &                       id_offset=id_offset(:,:) )
+
+      !2- work on variable
+      !2-0 add extraband
+      CALL extrap_add_extrabands(tl_var, il_iext, il_jext)
+
+      !2-1 extrapolate variable
+      CALL extrap_fill_value( tl_var, id_offset=id_offset(:,:), &
+      &                               id_rho=id_rho(:),         &
+      &                               id_iext=il_iext, id_jext=il_jext )
+
+      !2-2 interpolate Bathymetry
+      CALL interp_fill_value( tl_var, id_rho(:), &
+      &                       id_offset=id_offset(:,:) )
+
+      !2-3 remove extraband
+      CALL extrap_del_extrabands(tl_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J))
+
+      !2-2-5 keep original mask 
+      WHERE( tl_mask%d_value(:,:,:,:) == 0 )
+         tl_var%d_value(:,:,:,:)=tl_var%d_fill
+      END WHERE
+
+      !3- save result
+      td_var=tl_var
+
+      ! clean variable structure
+      CALL var_clean(tl_mask)
+      CALL var_clean(tl_var)
+
+   END SUBROUTINE create_bathy_interp
+   !> @endcode
+END PROGRAM create_bathy
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/create_boundary.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/create_boundary.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/create_boundary.f90	(revision 4245)
@@ -0,0 +1,1433 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+!
+! PROGRAM: create_boundary
+!
+! DESCRIPTION:
+!> @brief 
+!> This program create boundary files.
+!>
+!> @details
+!> Variables are read from standard output.
+!> Then theses variables are interpolated on fine grid boundaries.
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!>
+!> @todo
+!----------------------------------------------------------------------
+!> @code
+PROGRAM create_boundary
+
+   USE netcdf                          ! nf90 library
+   USE global                          ! global variable
+   USE phycst                          ! physical constant
+   USE kind                            ! F90 kind parameter
+   USE logger                          ! log file manager
+   USE fct                             ! basic useful function
+   USE date                            ! date manager
+   USE att                             ! attribute manager
+   USE dim                             ! dimension manager
+   USE var                             ! variable manager
+   USE file                            ! file manager
+   USE multi                           ! multi file manager
+   USE boundary                        ! boundary manager
+   USE iom                             ! I/O manager
+   USE dom                             ! domain manager
+   USE grid                            ! grid manager
+   USE vgrid                           ! vartical grid manager
+   USE extrap                          ! extrapolation manager
+   USE interp                          ! interpolation manager
+   USE filter                          ! filter manager
+   USE mpp                             ! MPP manager
+   USE iom_mpp                         ! MPP I/O manager
+
+   IMPLICIT NONE
+
+   ! local variable
+   CHARACTER(LEN=lc)                                  :: cl_namelist
+   CHARACTER(LEN=lc)                                  :: cl_date
+   CHARACTER(LEN=lc)                                  :: cl_name
+   CHARACTER(LEN=lc)                                  :: cl_bdyout
+   CHARACTER(LEN=lc)                                  :: cl_data
+
+   INTEGER(i4)                                        :: il_narg
+   INTEGER(i4)                                        :: il_status
+   INTEGER(i4)                                        :: il_fileid
+   INTEGER(i4)                                        :: il_attid
+   INTEGER(i4)                                        :: il_dim
+   INTEGER(i4)                                        :: il_imin0
+   INTEGER(i4)                                        :: il_imax0
+   INTEGER(i4)                                        :: il_jmin0
+   INTEGER(i4)                                        :: il_jmax0
+   INTEGER(i4)      , DIMENSION(ip_maxdim)            :: il_rho
+   INTEGER(i4)      , DIMENSION(2,2)                  :: il_offset
+   INTEGER(i4)      , DIMENSION(2,2,2)                :: il_ind
+
+   LOGICAL                                            :: ll_exist
+
+   TYPE(TFILE)                                        :: tl_coord0
+   TYPE(TFILE)                                        :: tl_bathy0
+   TYPE(TFILE)                                        :: tl_coord1
+   TYPE(TFILE)                                        :: tl_bathy1
+   TYPE(TFILE)                                        :: tl_file
+   TYPE(TFILE)                                        :: tl_fileout
+   
+   TYPE(TMPP)                                         :: tl_mpp
+
+   TYPE(TMULTI)                                       :: tl_multi
+
+   TYPE(TATT)                                         :: tl_att
+   
+   TYPE(TVAR)       , DIMENSION(:)      , ALLOCATABLE :: tl_level
+   TYPE(TVAR)       , DIMENSION(:,:,:)  , ALLOCATABLE :: tl_seglvl1
+   TYPE(TVAR)                                         :: tl_var1
+   TYPE(TVAR)       , DIMENSION(:,:,:)  , ALLOCATABLE :: tl_segvar1
+   TYPE(TVAR)       , DIMENSION(:,:)    , ALLOCATABLE :: tl_seglon1
+   TYPE(TVAR)       , DIMENSION(:,:)    , ALLOCATABLE :: tl_seglat1
+   TYPE(TVAR)       , DIMENSION(:,:)    , ALLOCATABLE :: tl_var
+   TYPE(TVAR)       , DIMENSION(:)      , ALLOCATABLE :: tl_lon1
+   TYPE(TVAR)       , DIMENSION(:)      , ALLOCATABLE :: tl_lat1
+   TYPE(TVAR)                                         :: tl_depth   
+   TYPE(TVAR)                                         :: tl_time
+   TYPE(TVAR)                                         :: tl_tmp   
+
+   TYPE(TDIM)       , DIMENSION(ip_maxdim)            :: tl_dim
+   
+   TYPE(TBDY)       , DIMENSION(ip_ncard)             :: tl_bdy
+   
+   TYPE(TDOM)                                         :: tl_dom0
+   TYPE(TDOM)       , DIMENSION(:,:)    , ALLOCATABLE :: tl_segdom1
+
+   ! loop indices
+   INTEGER(i4) :: jvar
+   INTEGER(i4) :: ji
+   INTEGER(i4) :: jj
+   INTEGER(i4) :: jk
+   INTEGER(i4) :: jl
+
+   ! namelist variable
+   ! namlog
+   CHARACTER(LEN=lc)                       :: cn_logfile = 'create_boundary.log' 
+   CHARACTER(LEN=lc)                       :: cn_verbosity = 'warning' 
+
+   ! namcrs
+   CHARACTER(LEN=lc)                       :: cn_coord0 = '' 
+   INTEGER(i4)                             :: in_perio0 = -1
+
+   ! namfin
+   CHARACTER(LEN=lc)                       :: cn_coord1 = '' 
+   CHARACTER(LEN=lc)                       :: cn_bathy1 = '' 
+   INTEGER(i4)                             :: in_perio1 = -1
+
+   ! namcfg
+   CHARACTER(LEN=lc)                       :: cn_varcfg = 'variable.cfg' 
+
+   ! namvar
+   CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varinfo = ''
+   CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varfile = ''
+
+   ! namnst
+   INTEGER(i4)                             :: in_imin0 = 0
+   INTEGER(i4)                             :: in_imax0 = 0
+   INTEGER(i4)                             :: in_jmin0 = 0
+   INTEGER(i4)                             :: in_jmax0 = 0
+   INTEGER(i4)                             :: in_rhoi  = 1
+   INTEGER(i4)                             :: in_rhoj  = 1
+
+   ! nambdy
+   LOGICAL                                 :: ln_north   = .TRUE.
+   LOGICAL                                 :: ln_south   = .TRUE.
+   LOGICAL                                 :: ln_east    = .TRUE.
+   LOGICAL                                 :: ln_west    = .TRUE.
+   CHARACTER(LEN=lc)                       :: cn_north   = ''
+   CHARACTER(LEN=lc)                       :: cn_south   = ''
+   CHARACTER(LEN=lc)                       :: cn_east    = ''
+   CHARACTER(LEN=lc)                       :: cn_west    = ''
+   LOGICAL                                 :: ln_oneseg  = .TRUE.
+   INTEGER(i4)                             :: in_extrap  = 0
+
+   ! namout
+   CHARACTER(LEN=lc)                       :: cn_fileout = 'boundary.nc' 
+   !-------------------------------------------------------------------
+
+   NAMELIST /namlog/ &  !< logger namelist
+   &  cn_logfile,    &  !< log file
+   &  cn_verbosity      !< log verbosity
+
+   NAMELIST /namcfg/ &  !< config namelist
+   &  cn_varcfg         !< variable configuration file
+
+   NAMELIST /namcrs/ &  !< coarse grid namelist
+   &  cn_coord0,     &  !< coordinate file
+   &  in_perio0         !< periodicity index
+   
+   NAMELIST /namfin/ &  !< fine grid namelist
+   &  cn_coord1,     &  !< coordinate file
+   &  cn_bathy1,     &  !< bathymetry file
+   &  in_perio1         !< periodicity index
+ 
+   NAMELIST /namvar/ &  !< variable namelist
+   &  cn_varinfo,    &  !< list of variable and method to apply on. (ex: 'votemper:linear','vosaline:cubic' )
+   &  cn_varfile        !< list of variable and file where find it. (ex: 'votemper:GLORYS_gridT.nc' ) 
+   
+   NAMELIST /namnst/ &  !< nesting namelist
+   &  in_imin0,      &  !< i-direction lower left  point indice on coarse grid 
+   &  in_imax0,      &  !< i-direction upper right point indice on coarse grid
+   &  in_jmin0,      &  !< j-direction lower left  point indice on coarse grid
+   &  in_jmax0,      &  !< j-direction upper right point indice on coarse grid
+   &  in_rhoi,       &  !< refinement factor in i-direction
+   &  in_rhoj           !< refinement factor in j-direction
+
+   NAMELIST /nambdy/ &  !< boundary namelist
+   &  ln_north,      &  !< use north boundary
+   &  ln_south,      &  !< use south boundary
+   &  ln_east ,      &  !< use east  boundary
+   &  ln_west ,      &  !< use west  boundary
+   &  cn_north,      &  !< north boundary indices on fine grid
+   &  cn_south,      &  !< south boundary indices on fine grid
+   &  cn_east ,      &  !< east  boundary indices on fine grid
+   &  cn_west ,      &  !< west  boundary indices on fine grid
+   &  ln_oneseg,     &  !< use only one segment for each boundary or not
+   &  in_extrap         !< number of mask point to extrapolate
+
+   NAMELIST /namout/ &  !< output namelist
+   &  cn_fileout    !< fine grid boundary file basename   
+   !-------------------------------------------------------------------
+
+   !1- namelist
+   !1-1 get namelist
+   il_narg=COMMAND_ARGUMENT_COUNT() !f03 intrinsec
+   IF( il_narg/=1 )THEN
+      PRINT *,"CREATE BOUNDARY: ERROR. need a namelist"
+      STOP
+   ELSE
+      CALL GET_COMMAND_ARGUMENT(1,cl_namelist) !f03 intrinsec
+   ENDIF
+   
+   !1-2 read namelist
+   INQUIRE(FILE=TRIM(cl_namelist), EXIST=ll_exist)
+   IF( ll_exist )THEN
+      
+      il_fileid=fct_getunit()
+
+      OPEN( il_fileid, FILE=TRIM(cl_namelist), &
+      &                FORM='FORMATTED',       &
+      &                ACCESS='SEQUENTIAL',    &
+      &                STATUS='OLD',           &
+      &                ACTION='READ',          &
+      &                IOSTAT=il_status)
+      CALL fct_err(il_status)
+      IF( il_status /= 0 )THEN
+         PRINT *,"CREATE BOUNDARY: ERROR opening "//TRIM(cl_namelist)
+         STOP
+      ENDIF
+
+      READ( il_fileid, NML = namlog )
+      !1-2-1 define log file
+      CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity))
+      CALL logger_header()
+
+      READ( il_fileid, NML = namcfg )
+      !1-2-2 get variable extra information
+      CALL var_def_extra(TRIM(cn_varcfg))
+
+      READ( il_fileid, NML = namcrs )
+      READ( il_fileid, NML = namfin )
+      READ( il_fileid, NML = namvar )
+      !1-2-3 add user change in extra information
+      CALL var_chg_extra(cn_varinfo)
+      !1-2-4 match variable with file
+      tl_multi=multi_init(cn_varfile)
+
+      READ( il_fileid, NML = namnst )
+      READ( il_fileid, NML = nambdy )
+
+      READ( il_fileid, NML = namout )
+
+      CLOSE( il_fileid, IOSTAT=il_status )
+      CALL fct_err(il_status)
+      IF( il_status /= 0 )THEN
+         CALL logger_error("CREATE BOUNDARY: ERROR closing "//TRIM(cl_namelist))
+      ENDIF
+
+   ELSE
+
+      PRINT *,"CREATE BOUNDARY: ERROR. can not find "//TRIM(cl_namelist)
+
+   ENDIF
+
+   !2- open files
+   IF( TRIM(cn_coord0) /= '' )THEN
+      tl_coord0=file_init(TRIM(cn_coord0),id_perio=in_perio0)
+      CALL iom_open(tl_coord0)
+   ELSE
+      CALL logger_fatal("CREATE BOUNDARY: can not find coarse grid "//&
+      &  "coordinate file. check namelist")
+   ENDIF
+
+   IF( TRIM(cn_coord1) /= '' )THEN
+      tl_coord1=file_init(TRIM(cn_coord1),id_perio=in_perio1)
+      CALL iom_open(tl_coord1)
+   ELSE
+      CALL logger_fatal("CREATE BOUNDARY: can not find fine grid coordinate "//&
+      &  "file. check namelist")
+   ENDIF
+
+   IF( TRIM(cn_bathy1) /= '' )THEN
+      tl_bathy1=file_init(TRIM(cn_bathy1),id_perio=in_perio1)
+      CALL iom_open(tl_bathy1)
+   ELSE
+      CALL logger_fatal("CREATE BOUNDARY: can not find fine grid bathymetry "//&
+      &  "file. check namelist")
+   ENDIF
+
+   !3- check
+   !3-1 check output file do not already exist
+   DO jk=1,ip_ncard
+      cl_bdyout=boundary_set_filename( TRIM(cn_fileout), &
+      &                                TRIM(ip_card(jk)) )
+      INQUIRE(FILE=TRIM(cl_bdyout), EXIST=ll_exist)
+      IF( ll_exist )THEN
+         CALL logger_fatal("CREATE BOUNDARY: output file "//TRIM(cl_bdyout)//&
+         &  " already exist.")
+      ENDIF
+   ENDDO
+
+   !3-1 check namelist
+   !3-1-1 check refinement factor
+   il_rho(:)=1
+   IF( in_rhoi < 1 .OR. in_rhoj < 1 )THEN
+      CALL logger_error("CREATE BOUNDARY: invalid refinement factor."//&
+      &  " check namelist "//TRIM(cl_namelist))
+   ELSE
+      il_rho(jp_I)=in_rhoi
+      il_rho(jp_J)=in_rhoj
+   ENDIF
+
+   !3-1-2
+   IF( in_imin0 < 1 .OR. in_imax0 < 1 .OR. in_jmin0 < 1 .OR. in_jmax0 < 1)THEN
+      ! compute coarse grid indices around fine grid
+      il_ind(:,:,:)=grid_get_coarse_index(tl_bathy0, tl_bathy1 )
+
+      il_imin0=il_ind(1,1,1) ; il_imax0=il_ind(1,2,1)
+      il_jmin0=il_ind(2,1,1) ; il_jmax0=il_ind(2,2,1)
+   ELSE
+      il_imin0=in_imin0 ; il_imax0=in_imax0
+      il_jmin0=in_jmin0 ; il_jmax0=in_jmax0
+   ENDIF
+
+   !3-2 check domain validity
+   CALL grid_check_dom(tl_coord0, il_imin0, il_imax0, il_jmin0, il_jmax0)
+
+   !3-3 check coordinate file
+   CALL grid_check_coincidence( tl_coord0, tl_coord1, &
+   &                            il_imin0, il_imax0, &
+   &                            il_jmin0, il_jmax0, &
+   &                            il_rho(:) )      
+
+   !4- read or compute boundary
+   tl_var1=iom_read_var(tl_bathy1,'Bathymetry')
+
+   tl_bdy(:)=boundary_init(tl_var1, ln_north, ln_south, ln_east, ln_west, &
+   &                                cn_north, cn_south, cn_east, cn_west, &
+   &                                ln_oneseg ) 
+
+   CALL var_clean(tl_var1)
+
+   !5- compute level
+   ALLOCATE(tl_level(ig_npoint))
+   tl_level(:)=vgrid_get_level(tl_bathy1, cl_namelist )
+
+   !6- get coordinate on each segment of each boundary
+   ALLOCATE( tl_seglon1(ip_ncard,ig_maxseg) )
+   ALLOCATE( tl_seglat1(ip_ncard,ig_maxseg) )
+   ALLOCATE( tl_segdom1(ip_ncard,ig_maxseg) )
+   ALLOCATE( tl_segvar1(tl_multi%i_nvar,ip_ncard,ig_maxseg) )
+   ALLOCATE( tl_seglvl1(ip_ncard,ig_maxseg,ig_npoint) )
+   DO jk=1,ip_ncard
+      IF( tl_bdy(jk)%l_use )THEN
+         DO jl=1,tl_bdy(jk)%i_nseg
+            !6-1 get fine grid segment domain
+            tl_segdom1(jk,jl)=create_boundary_get_dom( tl_bathy1, tl_bdy(jk), jl )
+
+            !6-2 get fine grid segment coordinate
+            CALL create_boundary_get_coord( tl_bathy1, tl_segdom1(jk,jl), &
+            &                               tl_seglon1(jk,jl), tl_seglat1(jk,jl) )
+            !6-2 get fine grid segment coordinate
+            tl_seglvl1(jk,jl,:)=create_bdy_get_level(tl_level(:), tl_segdom1(jk,jl))
+
+         ENDDO
+      ENDIF
+   ENDDO
+
+   DEALLOCATE(tl_level)
+
+   !7- compute boundary for variable to be used (see namelist)
+   IF( .NOT. ASSOCIATED(tl_multi%t_file) )THEN
+      CALL logger_error("CREATE BOUNDARY: no file to work on. "//&
+      &                 "check cn_varfile in namelist.")
+   ELSE
+      jvar=0
+      ! for each file
+      DO ji=1,tl_multi%i_nfile
+         WRITE(cl_data,'(a,i2.2)') 'data_',jvar+1
+
+         IF( .NOT. ASSOCIATED(tl_multi%t_file(ji)%t_var) )THEN
+            CALL logger_error("CREATE BOUNDARY: no variable to work on for "//&
+            &                 "file "//TRIM(tl_multi%t_file(ji)%c_name)//&
+            &                 ". check cn_varfile in namelist.")
+         ELSE
+            IF( .NOT. ASSOCIATED(tl_multi%t_file(ji)%t_var) )THEN
+
+               CALL logger_error("CREATE BOUNDARY: no variable to work on for "//&
+               &                 "file "//TRIM(tl_multi%t_file(ji)%c_name)//&
+               &                 ". check cn_varfile in namelist.")
+
+            ELSEIF( TRIM(tl_multi%t_file(ji)%c_name) == TRIM(cl_data) )THEN
+            !- use input matrix to fill variable
+
+               ! for each variable initialise from matrix
+               DO jj=1,tl_multi%t_file(ji)%i_nvar
+                  jvar=jvar+1
+                  tl_tmp=tl_multi%t_file(ji)%t_var(jj)
+                  DO jk=1,ip_ncard
+                     IF( tl_bdy(jk)%l_use )THEN
+                        DO jl=1,tl_bdy(jk)%i_nseg
+                           !7-1 fill value with matrix data
+                           ! pb voir comment gerer nb de dimension
+                           tl_segvar1(jvar,jk,jl)=create_bdy_matrix(tl_tmp, tl_segdom1(jk,jl), tl_coord1)
+
+                           !7-2 use mask
+                           CALL create_bdy_use_mask(tl_segvar1(jvar,jk,jl), tl_seglvl1(jk,jl,:))
+                        ENDDO
+                     ENDIF
+                  ENDDO
+               ENDDO
+
+            ELSE
+            !- use file to fill variable
+
+               ! open file
+               tl_file=file_init(TRIM(tl_multi%t_file(ji)%c_name))
+               CALL iom_open(tl_file)
+
+               ! get or check depth value
+               IF( tl_file%i_depthid /= 0 )THEN
+                  IF( ASSOCIATED(tl_depth%d_value) )THEN
+                     IF( ANY( tl_depth%d_value(:,:,:,:) /= &
+                     &        tl_tmp%d_value(:,:,:,:) ) )THEN
+                        CALL logger_fatal("CREATE BOUNDARY: depth value from "//&
+                        &  TRIM(tl_multi%t_file(ji)%c_name)//" not conform "//&
+                        &  " to those from former file(s).")
+                     ENDIF
+                  ELSE
+                     tl_depth=iom_read_var(tl_file,tl_file%i_depthid)
+                  ENDIF
+               ENDIF
+
+               ! get or check time value
+               IF( tl_file%i_timeid /= 0 )THEN
+                  IF( ASSOCIATED(tl_time%d_value) )THEN
+                     IF( ANY( tl_time%d_value(:,:,:,:) /= &
+                     &        tl_tmp%d_value(:,:,:,:) ) )THEN
+                        CALL logger_fatal("CREATE BOUNDARY: time value from "//&
+                        &  TRIM(tl_multi%t_file(ji)%c_name)//" not conform "//&
+                        &  " to those from former file(s).")
+                     ENDIF
+                  ELSE
+                     tl_time=iom_read_var(tl_file,tl_file%i_timeid)
+                  ENDIF
+               ENDIF
+
+               IF( ANY( tl_file%t_dim(1:2)%i_len /= &
+               &      tl_coord0%t_dim(1:2)%i_len) )THEN
+               !- extract value from fine grid
+                  DO jk=1,ip_ncard
+                     IF( tl_bdy(jk)%l_use )THEN
+
+                        DO jl=1,tl_bdy(jk)%i_nseg
+                           !7-1 compute domain on fine grid
+                           
+                           ! open mpp file on domain
+                           !7-2 init mpp structure
+                           tl_mpp=mpp_init(tl_file)
+
+                           !7-3 get processor to be used
+                           CALL mpp_get_use( tl_mpp, tl_segdom1(jk,jl) )
+                           !7-4 open mpp files
+                           CALL iom_mpp_open(tl_mpp)
+
+                           ! for each variable of this file
+                           DO jj=1,tl_multi%t_file(ji)%i_nvar
+                              
+                              cl_name=tl_multi%t_file(ji)%t_var(jj)%c_name
+                              !7-5 read variable over domain
+                              tl_segvar1(jvar+jj,jk,jl)=iom_mpp_read_var( tl_mpp, TRIM(cl_name), &
+                              &                                           td_dom=tl_segdom1(jk,jl) )
+
+                              !7-6 add attribute to variable
+                              tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name)))
+                              CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
+
+                              tl_att=att_init('src_i-indices',(/tl_segdom1(jk,jl)%i_imin, tl_segdom1(jk,jl)%i_imax/))
+                              CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
+
+                              tl_att=att_init('src_j-indices',(/tl_segdom1(jk,jl)%i_jmin, tl_segdom1(jk,jl)%i_jmax/))
+                              CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
+                              
+                              ! clean structure
+                              CALL att_clean(tl_att)
+
+                              !7-7 use mask
+                              CALL create_bdy_use_mask(tl_segvar1(jvar+jj,jk,jl), tl_seglvl1(jk,jl,:))
+                           ENDDO
+                           
+                           !7-8 close mpp files
+                           CALL iom_mpp_close(tl_mpp)
+
+                           CALL mpp_clean(tl_mpp)
+
+                        ENDDO
+                     ENDIF
+                  ENDDO
+                  jvar=jvar+tl_multi%t_file(ji)%i_nvar
+               ELSE
+               !- interpolate value from coarse grid
+
+                  DO jk=1,ip_ncard
+                     IF( tl_bdy(jk)%l_use )THEN
+
+                        DO jl=1,tl_bdy(jk)%i_nseg
+                           !7-1 get coarse grid indices of this segment
+                           il_ind(:,:,:)=grid_get_coarse_index(tl_coord0, &
+                           &                                   tl_seglon1(jk,jl), tl_seglat1(jk,jl), &
+                           &                                   id_rho=il_rho(:) )
+
+                           IF( ANY(il_ind(:,:,:)==0) )THEN
+                              CALL logger_error("CREATE BOUNDARY: error computing "//&
+                              &                 " coarse grid indices")
+                           ELSE
+                              il_imin0=il_ind(1,1,1)
+                              il_imax0=il_ind(1,2,1)
+
+                              il_jmin0=il_ind(2,1,1)
+                              il_jmax0=il_ind(2,2,1)
+
+                              il_offset(:,:)=il_ind(:,:,2)
+                           ENDIF
+
+                           !7-2 compute coarse grid segment domain
+                           tl_dom0=dom_init( tl_coord0,         &
+                           &                 il_imin0, il_imax0,&
+                           &                 il_jmin0, il_jmax0 )
+
+                           !7-3 add extra band (if possible) to compute interpolation
+                           CALL dom_add_extra(tl_dom0)
+
+                           !7-4 read variables on domain (ugly way to do it, have to work on it)
+                           !7-4-1 init mpp structure
+                           tl_mpp=mpp_init(tl_file)
+ 
+                           !7-4-2 get processor to be used
+                           CALL mpp_get_use( tl_mpp, tl_dom0 )
+
+                           !7-4-3 open mpp files
+                           CALL iom_mpp_open(tl_mpp)
+
+                           ! check file dimension
+                           IF( ANY(tl_mpp%t_dim(1:2)%i_len /= tl_coord0%t_dim(1:2)%i_len) )THEN
+                              CALL logger_error("CREATE BOUNDARY INTERP: dimension of file "//&
+                              &  TRIM(tl_mpp%c_name)//" not conform to those of "//&
+                              &  TRIM(tl_coord0%c_name))
+                           ELSE
+
+                              ! for each variable of this file
+                              DO jj=1,tl_multi%t_file(ji)%i_nvar
+
+                                 cl_name=tl_multi%t_file(ji)%t_var(jj)%c_name
+                                 !7-4-4 read variable value on domain
+                                 tl_segvar1(jvar+jj,jk,jl)=iom_mpp_read_var( tl_mpp, TRIM(cl_name), &
+                                 &                                           td_dom=tl_dom0 )
+
+                                 !7-4-5 work on variable
+                                 CALL create_boundary_interp(tl_segvar1(jvar+jj,jk,jl), &
+                                 &                           il_rho(:), &
+                                 &                           il_offset(:,:) )
+
+                                 !7-4-6 remove extraband added to domain
+                                 CALL dom_del_extra( tl_segvar1(jvar+jj,jk,jl), tl_dom0, il_rho(:) )
+
+                                 !7-4-7 keep only useful point (width) 
+                                 ! interpolation could create more point than necessary
+                                 CALL boundary_clean_interp(tl_segvar1(jvar+jj,jk,jl), tl_bdy(jk) )
+
+                                 !7-4-8 add attribute to variable
+                                 tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name)))
+                                 CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
+
+                                 tl_att=att_init('src_i-indices',(/tl_dom0%i_imin, tl_dom0%i_imax/))
+                                 CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
+
+                                 tl_att=att_init('src_j-indices',(/tl_dom0%i_jmin, tl_dom0%i_jmax/))
+                                 CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
+
+                                 ! clean structure
+                                 CALL att_clean(tl_att)
+
+                                 !7-4-9 use mask
+                                 CALL create_bdy_use_mask(tl_segvar1(jvar+jj,jk,jl), tl_seglvl1(jk,jl,:))
+                              ENDDO
+                           ENDIF
+
+                           CALL dom_clean(tl_dom0)
+
+                           !7-5 close mpp files
+                           CALL iom_mpp_close(tl_mpp)
+
+                           !7-6 clean structure
+                           CALL mpp_clean(tl_mpp)
+                        ENDDO
+                     ENDIF
+                  ENDDO
+                  jvar=jvar+tl_multi%t_file(ji)%i_nvar
+
+               ENDIF
+               CALL file_clean(tl_file)
+
+            ENDIF
+         ENDIF
+      ENDDO
+   ENDIF
+   IF( jvar /= tl_multi%i_nvar )THEN
+      CALL logger_error("CREATE BOUNDARY: it seems some variable can not be read")
+   ENDIF
+
+   !8- concatenate file
+   ALLOCATE( tl_lon1(ip_ncard) )
+   ALLOCATE( tl_lat1(ip_ncard) )
+   ALLOCATE( tl_var(tl_multi%i_nvar,ip_ncard) )
+
+   DO jk=1,ip_ncard
+      IF( tl_bdy(jk)%l_use )THEN
+
+         SELECT CASE(TRIM(tl_bdy(jk)%c_card))
+         CASE('north','south')
+            il_dim=1
+         CASE('east','west')
+            il_dim=2
+         END SELECT   
+
+         DO jl=1,tl_bdy(jk)%i_nseg
+            !- concatenate variable
+            IF( jl == 1 )THEN
+               tl_lon1(jk)=tl_seglon1(jk,jl)
+               tl_lat1(jk)=tl_seglat1(jk,jl)
+               DO jvar=1,tl_multi%i_nvar
+                  tl_var(jvar,jk)=tl_segvar1(jvar,jk,jl)
+               ENDDO
+            ELSE
+               tl_lon1(jk)=var_concat(tl_lon1(jk),tl_seglon1(jk,jl),DIM=il_dim)
+               tl_lat1(jk)=var_concat(tl_lat1(jk),tl_seglat1(jk,jl),DIM=il_dim)
+               DO jvar=1,tl_multi%i_nvar
+                  tl_var(jvar,jk)=var_concat(tl_var(jvar,jk),tl_segvar1(jvar,jk,jl),DIM=il_dim)
+               ENDDO
+            ENDIF   
+         ENDDO
+
+         ! swap array
+         CALL boundary_swap(tl_lon1(jk), tl_bdy(jk))
+         CALL boundary_swap(tl_lat1(jk), tl_bdy(jk))
+         DO jvar=1,tl_multi%i_nvar
+            CALL boundary_swap(tl_var(jvar,jk), tl_bdy(jk))
+
+            !9- use additional request
+
+            !9-1 forced min and max value
+            CALL var_limit_value(tl_var(jvar,jk))
+
+            !9-2 filter
+            CALL filter_fill_value(tl_var(jvar,jk))
+
+            !9-3 extrapolate
+            CALL extrap_fill_value(tl_var(jvar,jk), id_iext=in_extrap, &
+            &                                       id_jext=in_extrap, &
+            &                                       id_kext=in_extrap)
+
+         ENDDO
+      ENDIF
+   ENDDO
+
+   DEALLOCATE( tl_seglon1 )
+   DEALLOCATE( tl_seglat1 )
+   DEALLOCATE( tl_segdom1 )
+   DEALLOCATE( tl_segvar1 )
+   DEALLOCATE( tl_seglvl1 )
+   
+   DO jk=1,ip_ncard
+      IF( tl_bdy(jk)%l_use )THEN
+
+         !10   create file
+         !10-1 create file structure
+         !10-1-1 set file name
+         cl_bdyout=boundary_set_filename( TRIM(cn_fileout), &
+         &                                TRIM(tl_bdy(jk)%c_card) )
+         !10-1-2 
+         tl_fileout=file_init(TRIM(cl_bdyout),id_perio=in_perio1)
+
+         !10-2 add dimension
+         tl_dim(:)=var_max_dim(tl_var(:,jk))
+
+         DO ji=1,ip_maxdim
+            IF( tl_dim(ji)%l_use ) CALL file_add_dim(tl_fileout, tl_dim(ji))
+         ENDDO
+
+         !10-3 add variables
+         IF( ALL( tl_dim(1:2)%l_use ) )THEN
+            ! add longitude
+            CALL file_add_var(tl_fileout, tl_lon1(jk))
+            CALL var_clean(tl_lon1(jk))
+
+            ! add latitude
+            CALL file_add_var(tl_fileout, tl_lat1(jk))
+            CALL var_clean(tl_lat1(jk))
+         ENDIF
+         
+         IF( tl_dim(3)%l_use )THEN
+            ! add depth
+            CALL file_add_var(tl_fileout, tl_depth)
+         ENDIF
+
+         IF( tl_dim(4)%l_use )THEN
+            ! add time
+            CALL file_add_var(tl_fileout, tl_time)
+         ENDIF
+
+         ! add other variable
+         DO jvar=1,tl_multi%i_nvar
+            !IF( TRIM(tl_var(jvar,jk)%c_name) /= 'X' .AND. &
+            !&   TRIM(tl_var(jvar,jk)%c_name) /= 'Y' )THEN
+               CALL file_add_var(tl_fileout, tl_var(jvar,jk))
+            !ENDIF
+            CALL var_clean(tl_var(jvar,jk))
+         ENDDO
+
+         !10-4 add some attribute
+         tl_att=att_init("Created_by","SIREN create_boundary")
+         CALL file_add_att(tl_fileout, tl_att)
+
+         cl_date=date_print(date_now())
+         tl_att=att_init("Creation_date",cl_date)
+         CALL file_add_att(tl_fileout, tl_att)
+
+         ! add attribute periodicity
+         il_attid=0
+         IF( ASSOCIATED(tl_fileout%t_att) )THEN
+            il_attid=att_get_id(tl_fileout%t_att(:),'periodicity')
+         ENDIF
+         IF( tl_coord1%i_perio >= 0 .AND. il_attid == 0 )THEN
+            tl_att=att_init('periodicity',tl_coord1%i_perio)
+            CALL file_add_att(tl_fileout,tl_att)
+         ENDIF
+      
+         il_attid=0
+         IF( ASSOCIATED(tl_fileout%t_att) )THEN
+            il_attid=att_get_id(tl_fileout%t_att(:),'ew_overlap')
+         ENDIF
+         IF( tl_coord1%i_ew >= 0 .AND. il_attid == 0 )THEN
+            tl_att=att_init('ew_overlap',tl_coord1%i_ew)
+            CALL file_add_att(tl_fileout,tl_att)
+         ENDIF
+
+         !10-5 create file
+         CALL iom_create(tl_fileout)
+
+         !10-6 write file
+         CALL iom_write_file(tl_fileout)
+
+         !10-7 close file
+         CALL iom_close(tl_fileout)
+         CALL file_clean(tl_fileout)
+
+      ENDIF
+   ENDDO
+   DEALLOCATE( tl_lon1 ) 
+   DEALLOCATE( tl_lat1 ) 
+   DEALLOCATE( tl_var ) 
+
+   !11- close file
+   CALL iom_close(tl_bathy1)
+   CALL iom_close(tl_coord1)
+   CALL iom_close(tl_coord0)
+
+   !12- clean
+   CALL var_clean(tl_depth)
+   CALL var_clean(tl_time)
+   CALL file_clean(tl_fileout)
+   CALL file_clean(tl_bathy1)
+   CALL file_clean(tl_coord1)
+   CALL file_clean(tl_coord0)
+
+   ! close log file
+   CALL logger_footer()
+   CALL logger_close()
+
+!> @endcode
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - 2013- Initial Version
+   !>
+   !> @param[in] 
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION create_boundary_get_dom( td_bathy1, td_bdy, id_seg )
+
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TFILE), INTENT(IN   ) :: td_bathy1
+      TYPE(TBDY) , INTENT(IN   ) :: td_bdy
+      INTEGER(i4), INTENT(IN   ) :: id_seg
+
+      ! function
+      TYPE(TDOM) :: create_boundary_get_dom
+
+      ! local variable
+      INTEGER(i4) :: il_imin1
+      INTEGER(i4) :: il_imax1
+      INTEGER(i4) :: il_jmin1
+      INTEGER(i4) :: il_jmax1
+
+      TYPE(TFILE) :: tl_bathy1
+      
+      ! loop indices
+      INTEGER(i4) :: jl
+      !----------------------------------------------------------------
+      jl=id_seg
+
+      !1- get boundary definition
+      SELECT CASE(TRIM(td_bdy%c_card))
+         CASE('north')
+
+            il_imin1=td_bdy%t_seg(jl)%i_first
+            il_imax1=td_bdy%t_seg(jl)%i_last 
+            il_jmin1=td_bdy%t_seg(jl)%i_index-(td_bdy%t_seg(jl)%i_width-1)
+            il_jmax1=td_bdy%t_seg(jl)%i_index
+
+         CASE('south')
+
+            il_imin1=td_bdy%t_seg(jl)%i_first
+            il_imax1=td_bdy%t_seg(jl)%i_last 
+            il_jmin1=td_bdy%t_seg(jl)%i_index
+            il_jmax1=td_bdy%t_seg(jl)%i_index+(td_bdy%t_seg(jl)%i_width-1)
+
+         CASE('east')
+
+            il_imin1=td_bdy%t_seg(jl)%i_index-(td_bdy%t_seg(jl)%i_width-1)
+            il_imax1=td_bdy%t_seg(jl)%i_index
+            il_jmin1=td_bdy%t_seg(jl)%i_first
+            il_jmax1=td_bdy%t_seg(jl)%i_last 
+
+         CASE('west')
+
+            il_imin1=td_bdy%t_seg(jl)%i_index
+            il_imax1=td_bdy%t_seg(jl)%i_index+(td_bdy%t_seg(jl)%i_width-1)
+            il_jmin1=td_bdy%t_seg(jl)%i_first
+            il_jmax1=td_bdy%t_seg(jl)%i_last 
+
+      END SELECT         
+
+      !2 -read fine grid domain
+      tl_bathy1=td_bathy1
+      CALL iom_open(tl_bathy1)
+
+      !2-1 compute domain
+      create_boundary_get_dom=dom_init( tl_bathy1,         &
+      &                                 il_imin1, il_imax1,&
+      &                                 il_jmin1, il_jmax1 )
+
+      !2-2 close file
+      CALL iom_close(tl_bathy1)
+
+   END FUNCTION create_boundary_get_dom
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] 
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE create_boundary_get_coord( td_bathy1, td_dom1, &
+   &                                     td_lon1, td_lat1 )
+
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TFILE), INTENT(IN   ) :: td_bathy1
+      TYPE(TDOM) , INTENT(IN   ) :: td_dom1
+      TYPE(TVAR) , INTENT(  OUT) :: td_lon1
+      TYPE(TVAR) , INTENT(  OUT) :: td_lat1 
+
+      ! local variable
+      TYPE(TFILE) :: tl_bathy1
+      
+      TYPE(TMPP)  :: tl_mppbathy1
+
+      ! loop indices
+      !----------------------------------------------------------------
+      !read variables on domain (ugly way to do it, have to work on it)
+
+      !1 init mpp structure
+      tl_bathy1=td_bathy1
+      tl_mppbathy1=mpp_init(tl_bathy1)
+      
+      CALL file_clean(tl_bathy1)
+
+      !2 get processor to be used
+      CALL mpp_get_use( tl_mppbathy1, td_dom1 )
+
+      !3 open mpp files
+      CALL iom_mpp_open(tl_mppbathy1)
+
+      !4 read variable value on domain
+      td_lon1=iom_mpp_read_var(tl_mppbathy1,'longitude',td_dom=td_dom1)
+      td_lat1=iom_mpp_read_var(tl_mppbathy1,'latitude' ,td_dom=td_dom1)
+
+      !5 close mpp files
+      CALL iom_mpp_close(tl_mppbathy1)
+
+      !6 clean structure
+      CALL mpp_clean(tl_mppbathy1)
+
+   END SUBROUTINE create_boundary_get_coord
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] 
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE create_boundary_get_mask( td_level1, td_dom1, &
+   &                                    td_var, td_mask )
+
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TFILE), INTENT(IN   ) :: td_level1
+      TYPE(TDOM) , INTENT(IN   ) :: td_dom1
+      TYPE(TVAR) , INTENT(IN   ) :: td_var
+      TYPE(TVAR) , INTENT(  OUT) :: td_mask 
+
+      ! local variable
+      TYPE(TFILE) :: tl_level1
+      
+      TYPE(TMPP)  :: tl_mpplevel1
+
+      ! loop indices
+      !----------------------------------------------------------------
+      !read variables on domain (ugly way to do it, have to work on it)
+
+      !1 init mpp structure
+      tl_level1=td_level1
+      tl_mpplevel1=mpp_init(tl_level1)
+      
+      CALL file_clean(tl_level1)
+
+      !2 get processor to be used
+      CALL mpp_get_use( tl_mpplevel1, td_dom1 )
+
+      !3 open mpp files
+      CALL iom_mpp_open(tl_mpplevel1)
+
+      !4 read variable value on domain
+      SELECT CASE(TRIM(td_var%c_point))
+      CASE('T')
+         td_mask=iom_mpp_read_var(tl_mpplevel1,'tlevel',td_dom=td_dom1)
+      CASE('U')
+         td_mask=iom_mpp_read_var(tl_mpplevel1,'ulevel',td_dom=td_dom1)
+      CASE('V')
+         td_mask=iom_mpp_read_var(tl_mpplevel1,'vlevel',td_dom=td_dom1)
+      CASE('F')
+         td_mask=iom_mpp_read_var(tl_mpplevel1,'flevel',td_dom=td_dom1)
+      END SELECT
+
+      !5 close mpp files
+      CALL iom_mpp_close(tl_mpplevel1)
+
+      !6 clean structure
+      CALL mpp_clean(tl_mpplevel1)
+
+   END SUBROUTINE create_boundary_get_mask
+   !> @endcode
+!   !-------------------------------------------------------------------
+!   !> @brief
+!   !> This subroutine
+!   !> 
+!   !> @details 
+!   !>
+!   !> @author J.Paul
+!   !> - Nov, 2013- Initial Version
+!   !>
+!   !> @param[in] 
+!   !> @todo 
+!   !-------------------------------------------------------------------
+!   !> @code
+!   SUBROUTINE create_boundary_get_var( td_var, td_bdy,      &
+!   &                                   td_coord0, td_dom0,  &
+!   &                                   td_mask,             &
+!   &                                   id_rhoi, id_rhoj )
+!
+!      IMPLICIT NONE
+!
+!      ! Argument
+!      TYPE(TVAR) , INTENT(INOUT) :: td_var
+!      TYPE(TBDY) , INTENT(IN   ) :: td_bdy
+!      TYPE(TFILE), INTENT(IN   ) :: td_coord0
+!      TYPE(TDOM) , INTENT(IN   ) :: td_dom0
+!      TYPE(TVAR) , INTENT(IN   ) :: td_mask
+!      INTEGER(I4), INTENT(IN   ) :: id_rhoi
+!      INTEGER(I4), INTENT(IN   ) :: id_rhoj
+!
+!      ! local variable
+!      TYPE(TVAR)  :: tl_var0
+!
+!      TYPE(TDOM)  :: tl_dom0
+!
+!      TYPE(TFILE) :: tl_file0
+!
+!      TYPE(TMPP)  :: tl_mppfile0
+!
+!      ! loop indices
+!      INTEGER(i4) :: jk
+!      INTEGER(i4) :: jl
+!      !----------------------------------------------------------------
+!
+!      CALL logger_debug("CREATE BOUNDARY INTERP: read coarse grid"// TRIM(td_var%c_file) )
+!      !1- read coarse grid variable on domain
+!      tl_file0=file_init( TRIM(td_var%c_file) )
+!
+!      !2- init
+!      tl_dom0=td_dom0
+!
+!      !3- add extra band (if possible) to compute interpolation
+!      CALL dom_add_extra(tl_dom0)
+!
+!      !4- read variables on domain (ugly way to do it, have to work on it)
+!      !4-1 init mpp structure
+!      tl_mppfile0=mpp_init(tl_file0)
+! 
+!      CALL file_clean(tl_file0)
+!
+!      !4-2 get processor to be used
+!      CALL mpp_get_use( tl_mppfile0, tl_dom0 )
+!
+!      !4-3 open mpp files
+!      CALL iom_mpp_open(tl_mppfile0)
+!
+!      ! check file dimension
+!      IF( ANY(tl_mppfile0%t_dim(1:2)%i_len /= td_coord0%t_dim(1:2)%i_len) )THEN
+!         CALL logger_error("CREATE BOUNDARY INTERP: dimension of file "//&
+!         &  TRIM(tl_mppfile0%c_name)//" not conform to those of "//&
+!         &  TRIM(td_coord0%c_name))
+!      ELSE
+!
+!         !4-4 read variable value on domain
+!         tl_var0=iom_mpp_read_var( tl_mppfile0, TRIM(td_var%c_name), &
+!         &                         td_dom=tl_dom0 )
+!
+!         !5- work on variable
+!         CALL create_boundary_interp(tl_var0, id_rhoi, id_rhoj )
+!         
+!         !6- remove extraband added to domain
+!         CALL dom_del_extra( tl_var0, tl_dom0, id_rhoi, id_rhoj )
+!
+!         !6-1 remove extraband added to domain
+!         CALL dom_clean_extra( tl_dom0 )         
+!
+!         !7- keep only useful point (width) 
+!         ! interpolation could create more point than necessary
+!         CALL boundary_clean_interp(tl_var0, td_bdy )
+!
+!         !8- forced min and max value
+!         CALL var_limit_value(tl_var0)
+!
+!         !9- filter
+!         CALL filter_fill_value(tl_var0)
+!
+!         td_var=tl_var0
+!
+!         CALL var_clean(tl_var0)
+!      ENDIF
+!
+!      !4-5 close mpp files
+!      CALL iom_mpp_close(tl_mppfile0)
+!
+!      !4-6 clean structure
+!      CALL mpp_clean(tl_mppfile0)
+!      
+!      !5- apply mask
+!      DO jl=1,td_var%t_dim(4)%i_len
+!         DO jk=1,td_var%t_dim(3)%i_len
+!            WHERE( td_mask%d_value(:,:,1,1) < jk )
+!               td_var%d_value(:,:,jk,jl)=td_var%d_fill
+!            END WHERE
+!         ENDDO
+!      ENDDO
+!
+!   END SUBROUTINE create_boundary_get_var
+!   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] 
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE create_boundary_interp( td_var,           &
+   &                                  id_rho,           &
+   &                                  id_offset,        &
+   &                                  id_iext, id_jext )
+
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TVAR) ,                 INTENT(INOUT) :: td_var
+      INTEGER(I4), DIMENSION(:)  , INTENT(IN   ) :: id_rho
+      INTEGER(i4), DIMENSION(:,:), INTENT(IN   ) :: id_offset
+
+      INTEGER(i4), INTENT(IN   ), OPTIONAL :: id_iext
+      INTEGER(i4), INTENT(IN   ), OPTIONAL :: id_jext
+
+
+      ! local variable
+      TYPE(TVAR)  :: tl_var
+
+      INTEGER(i4) :: il_iext
+      INTEGER(i4) :: il_jext
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! copy variable
+      tl_var=td_var
+
+      !WARNING: at least two extrabands are required for cubic interpolation
+      il_iext=2
+      IF( PRESENT(id_iext) ) il_iext=id_iext
+
+      il_jext=2
+      IF( PRESENT(id_jext) ) il_jext=id_jext
+
+      IF( il_iext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN
+         CALL logger_warn("CREATE BOUNDARY INTERP: at least extrapolation "//&
+         &  "on two points are required with cubic interpolation ")
+         il_iext=2
+      ENDIF
+
+      IF( il_jext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN
+         CALL logger_warn("CREATE BOUNDARY INTERP: at least extrapolation "//&
+         &  "on two points are required with cubic interpolation ")
+         il_jext=2
+      ENDIF
+
+      !2- work on variable
+      !2-0 add extraband
+      CALL extrap_add_extrabands(tl_var, il_iext, il_jext)
+
+      !2-1 extrapolate variable
+      CALL extrap_fill_value( tl_var, id_iext=il_iext, id_jext=il_jext )
+
+      !2-2 interpolate Bathymetry
+      CALL interp_fill_value( tl_var, id_rho(:), &
+      &                       id_offset=id_offset(:,:) )
+
+      !2-3 remove extraband
+      CALL extrap_del_extrabands(tl_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J))
+
+      !3- save result
+      td_var=tl_var
+
+      ! clean variable structure
+      CALL var_clean(tl_var)
+
+   END SUBROUTINE create_boundary_interp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function create variable, filled with matrix value
+   !> 
+   !> @details 
+   !> A variable is create with the same name that the input variable, 
+   !> and with dimension of the coordinate file. 
+   !> Then the variable table of value is split into equal subdomain.
+   !> Each subdomain is fill with the linked value of the matrix.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] td_var : variable structure 
+   !> @param[in] td_dom : domain structure 
+   !> @param[in] td_coord : coordinate 
+   !> @return variable structure 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION create_bdy_matrix(td_var, td_dom, td_coord)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_var
+      TYPE(TDOM) , INTENT(IN) :: td_dom
+      TYPE(TFILE), INTENT(IN) :: td_coord
+
+      ! function
+      TYPE(TVAR) :: create_bdy_matrix
+
+      ! local variable
+      INTEGER(i4)                                        :: il_ighost
+      INTEGER(i4)                                        :: il_jghost
+      INTEGER(i4)      , DIMENSION(2)                    :: il_xghost
+      INTEGER(i4)      , DIMENSION(3)                    :: il_dim
+      INTEGER(i4)      , DIMENSION(3)                    :: il_size
+      INTEGER(i4)      , DIMENSION(3)                    :: il_rest
+
+      INTEGER(i4)      , DIMENSION(:)      , ALLOCATABLE :: il_ishape
+      INTEGER(i4)      , DIMENSION(:)      , ALLOCATABLE :: il_jshape
+      INTEGER(i4)      , DIMENSION(:)      , ALLOCATABLE :: il_kshape
+
+      REAL(dp)         , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      TYPE(TVAR)                                         :: tl_lon
+      TYPE(TVAR)                                         :: tl_lat
+      TYPE(TVAR)                                         :: tl_var
+      TYPE(TDIM)       , DIMENSION(ip_maxdim)            :: tl_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      !1- read output grid
+      tl_lon=iom_read_var(td_coord,'longitude')
+      tl_lat=iom_read_var(td_coord,'latitude')
+
+      !2- look for ghost cell
+      il_xghost(:)=grid_get_ghost( tl_lon, tl_lat )
+
+      il_ighost=il_xghost(1)*ig_ghost
+      il_jghost=il_xghost(2)*ig_ghost
+      
+      !3- write value on grid
+      !3-1 get matrix dimension
+      il_dim(:)=td_var%t_dim(1:3)%i_len
+      !3-2 output dimension
+      tl_dim(:)=tl_lon%t_dim(:)
+
+      ! remove ghost cell
+      tl_dim(1)%i_len=tl_dim(1)%i_len - 2*il_xghost(1)*ig_ghost
+      tl_dim(2)%i_len=tl_dim(2)%i_len - 2*il_xghost(2)*ig_ghost
+
+      !3-3 split output domain in N subdomain depending of matrix dimension 
+      il_size(:) = tl_dim(1:3)%i_len / il_dim(:)
+      il_rest(:) = MOD(tl_dim(1:3)%i_len, il_dim(:))
+
+      ALLOCATE( il_ishape(il_dim(1)+1) )
+      il_ishape(:)=0
+      DO ji=2,il_dim(1)+1
+         il_ishape(ji)=il_ishape(ji-1)+il_size(1)
+      ENDDO
+      ! add rest to last cell
+      il_ishape(il_dim(1)+1)=il_ishape(il_dim(1)+1)+il_rest(1)
+      
+
+      ALLOCATE( il_jshape(il_dim(2)+1) )
+      il_jshape(:)=0
+      DO jj=2,il_dim(2)+1
+         il_jshape(jj)=il_jshape(jj-1)+il_size(2)
+      ENDDO
+      ! add rest to last cell
+      il_jshape(il_dim(2)+1)=il_jshape(il_dim(2)+1)+il_rest(2)
+
+      ALLOCATE( il_kshape(il_dim(3)+1) )
+      il_kshape(:)=0
+      DO jk=2,il_dim(3)+1
+         il_kshape(jk)=il_kshape(jk-1)+il_size(3)
+      ENDDO
+      ! add rest to last cell
+      il_kshape(il_dim(3)+1)=il_kshape(il_dim(3)+1)+il_rest(3)
+
+      !3-3 write ouput table of value 
+      ALLOCATE(dl_value( tl_dim(1)%i_len, &
+      &                  tl_dim(2)%i_len, &
+      &                  tl_dim(3)%i_len, &
+      &                  tl_dim(4)%i_len) )
+
+      dl_value(:,:,:,:)=0
+
+      DO jk=2,il_dim(3)+1
+         DO jj=2,il_dim(2)+1
+            DO ji=2,il_dim(1)+1
+               
+               dl_value( 1+il_ishape(ji-1):il_ishape(ji), &
+               &         1+il_jshape(jj-1):il_jshape(jj), &
+               &         1+il_kshape(jk-1):il_kshape(jk), &
+               &         1 ) = td_var%d_value(ji-1,jj-1,jk-1,1)
+
+            ENDDO
+         ENDDO
+      ENDDO
+
+      !3-4 initialise variable with value
+      tl_var=var_init(TRIM(td_var%c_name),dl_value(:,:,:,:))
+
+      DEALLOCATE(dl_value)
+
+      !4- add ghost cell
+      CALL grid_add_ghost(tl_var,il_ighost,il_jghost)
+
+      !5- save result
+      create_bdy_matrix=tl_var
+
+   END FUNCTION create_bdy_matrix
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] 
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE create_bdy_use_mask( td_var, td_mask )
+
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TVAR)              , INTENT(INOUT) :: td_var
+      TYPE(TVAR), DIMENSION(:), INTENT(IN   ) :: td_mask
+
+      ! local variable
+      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_mask
+
+      ! loop indices
+      INTEGER(i4) :: jk
+      INTEGER(i4) :: jl
+      !----------------------------------------------------------------
+
+      ALLOCATE( il_mask(td_var%t_dim(1)%i_len, &
+      &                 td_var%t_dim(2)%i_len) )
+
+      SELECT CASE(TRIM(td_var%c_point))
+      CASE('T')
+         il_mask(:,:)=INT(td_mask(jp_T)%d_value(:,:,1,1))
+      CASE('U')
+         il_mask(:,:)=INT(td_mask(jp_U)%d_value(:,:,1,1))
+      CASE('V')
+         il_mask(:,:)=INT(td_mask(jp_V)%d_value(:,:,1,1))
+      CASE('F')
+         il_mask(:,:)=INT(td_mask(jp_F)%d_value(:,:,1,1))
+      END SELECT
+
+      DO jl=1,td_var%t_dim(4)%i_len
+         DO jk=1,td_var%t_dim(3)%i_len
+            WHERE( il_mask(:,:) < jk ) td_var%d_value(:,:,jk,jl)=td_var%d_fill
+         ENDDO
+      ENDDO
+
+      DEALLOCATE( il_mask )
+   END SUBROUTINE create_bdy_use_mask
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - 2013- Initial Version
+   !>
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION create_bdy_get_level(td_level, td_dom)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR), DIMENSION(:), INTENT(IN) :: td_level
+      TYPE(TDOM)              , INTENT(IN) :: td_dom
+
+      ! function
+      TYPE(TVAR), DIMENSION(ig_npoint) :: create_bdy_get_level
+
+      ! local variable
+      TYPE(TVAR), DIMENSION(ig_npoint) :: tl_var
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_level(:)) /= ig_npoint )THEN
+         CALL logger_error("CREATE BDY GET LEVEL: invalid dimension. "//&
+         &  "check input table of level.")
+      ELSE
+
+         !tl_var(1:ig_npoint)=td_level(1:ig_npoint)
+         create_bdy_get_level(:)=tl_var(:)
+         DO ji=1,ig_npoint
+
+         tl_var(ji)=td_level(ji)
+
+            IF( ASSOCIATED(tl_var(ji)%d_value) ) DEALLOCATE( tl_var(ji)%d_value )
+
+            tl_var(ji)%t_dim(1)%i_len=td_dom%t_dim(1)%i_len
+            tl_var(ji)%t_dim(2)%i_len=td_dom%t_dim(2)%i_len
+            ALLOCATE(tl_var(ji)%d_value(tl_var(ji)%t_dim(1)%i_len, &
+            &                           tl_var(ji)%t_dim(2)%i_len, &
+            &                           tl_var(ji)%t_dim(3)%i_len, &
+            &                           tl_var(ji)%t_dim(4)%i_len) )
+
+            tl_var(ji)%d_value(:,:,:,:) = &
+            &  td_level(ji)%d_value( td_dom%i_imin:td_dom%i_imax, &
+            &                        td_dom%i_jmin:td_dom%i_jmax, :, : )
+
+         ENDDO
+         !4 save result
+         create_bdy_get_level(:)=tl_var(:)
+
+      ENDIF
+   END FUNCTION create_bdy_get_level
+   !> @endcode
+END PROGRAM create_boundary
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/create_coord.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/create_coord.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/create_coord.f90	(revision 4245)
@@ -0,0 +1,450 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+!
+! PROGRAM: create_coord
+!
+! DESCRIPTION:
+!> @brief 
+!> This program create coordinate file.
+!>
+!> @details
+!> Variables are extracted from the input coordinates coarse grid, 
+!> and interpolated to create fine coordinates files.
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!>
+!> @todo
+!> - add extrapolation (case coordin with mask)
+!> - add extraction from a grid at fine resolution
+!----------------------------------------------------------------------
+!> @code
+PROGRAM create_coord
+
+!   USE netcdf                          ! nf90 library
+   USE global                          ! global variable
+   USE kind                            ! F90 kind parameter
+   USE logger                          ! log file manager
+   USE fct                             ! basic useful function
+   USE date                            ! date manager
+   USE att                             ! attribute manager
+   USE dim                             ! dimension manager
+   USE var                             ! variable manager
+   USE file                            ! file manager
+   USE iom                             ! I/O manager
+   USE dom                             ! domain manager
+   USE grid                            ! grid manager
+   USE extrap                          ! extrapolation manager
+   USE interp                          ! interpolation manager
+   USE filter                          ! filter manager
+   USE mpp                             ! MPP manager
+   USE iom_mpp                         ! MPP I/O manager
+
+   IMPLICIT NONE
+
+   ! local variable
+   CHARACTER(LEN=lc)                                    :: cl_namelist
+   CHARACTER(LEN=lc)                                    :: cl_date
+
+   INTEGER(i4)                                          :: il_narg
+   INTEGER(i4)                                          :: il_status
+   INTEGER(i4)                                          :: il_fileid
+   INTEGER(i4)                                          :: il_nvar
+!   INTEGER(i4)      , DIMENSION(:,:,:,:)  , ALLOCATABLE :: il_value
+   INTEGER(i4)      , DIMENSION(ip_maxdim)              :: il_rho
+
+
+   LOGICAL                                              :: ll_exist
+
+   TYPE(TATT)                                           :: tl_att
+
+   TYPE(TDOM)                                           :: tl_dom
+
+   TYPE(TVAR)       , DIMENSION(:)        , ALLOCATABLE :: tl_var
+
+   TYPE(TDIM)       , DIMENSION(ip_maxdim)              :: tl_dim
+
+   TYPE(TFILE)                                          :: tl_coord0
+   TYPE(TFILE)                                          :: tl_fileout
+
+   TYPE(TMPP)                                           :: tl_mppcoordin
+
+   ! loop indices
+   INTEGER(i4) :: ji
+
+   ! namelist variable
+   CHARACTER(LEN=lc) :: cn_logfile = 'create_coord.log' 
+   CHARACTER(LEN=lc) :: cn_verbosity = 'warning' 
+
+   CHARACTER(LEN=lc) :: cn_coord0 = '' 
+   INTEGER(i4)       :: in_perio0 = -1
+
+   CHARACTER(LEN=lc) :: cn_varcfg = 'variable.cfg' 
+
+   CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varinfo = ''
+
+   INTEGER(i4)       :: in_imin0 = 0
+   INTEGER(i4)       :: in_imax0 = 0
+   INTEGER(i4)       :: in_jmin0 = 0
+   INTEGER(i4)       :: in_jmax0 = 0
+   INTEGER(i4)       :: in_rhoi  = 1
+   INTEGER(i4)       :: in_rhoj  = 1
+
+   CHARACTER(LEN=lc) :: cn_fileout= 'coord_fine.nc'
+   !-------------------------------------------------------------------
+
+   NAMELIST /namlog/ & !< logger namelist
+   &  cn_logfile,    & !< log file
+   &  cn_verbosity     !< logger verbosity
+
+   NAMELIST /namcfg/ &  !< config namelist
+   &  cn_varcfg         !< variable configuration file
+
+   NAMELIST /namcrs/ &  ! coarse grid namelist
+   &  cn_coord0 , &     !< coordinate file
+   &  in_perio0         !< periodicity index
+
+   NAMELIST /namvar/ &  ! namvar
+   &  cn_varinfo        !< list of variable and extra information about 
+                        !< interpolation, extrapolation or filter method to be used. 
+                        !< (ex: 'votemper/linear/hann/dist_weight','vosaline/cubic' ) 
+   
+   NAMELIST /namnst/ &  !< nesting namelist
+   &  in_imin0,   &     !< i-direction lower left  point indice 
+   &  in_imax0,   &     !< i-direction upper right point indice
+   &  in_jmin0,   &     !< j-direction lower left  point indice
+   &  in_jmax0,   &     !< j-direction upper right point indice
+   &  in_rhoi,    &     !< refinement factor in i-direction
+   &  in_rhoj           !< refinement factor in j-direction
+
+   NAMELIST /namout/ &  !< output namelist
+   &  cn_fileout       !< fine grid coordinate file   
+   !-------------------------------------------------------------------
+
+   !1- namelist
+   !1-1 get namelist
+   il_narg=COMMAND_ARGUMENT_COUNT() !f03 intrinsec
+   IF( il_narg/=1 )THEN
+      PRINT *,"ERROR in create_coord: need a namelist"
+      STOP
+   ELSE
+      CALL GET_COMMAND_ARGUMENT(1,cl_namelist) !f03 intrinsec
+   ENDIF
+   
+   !1-2 read namelist
+   INQUIRE(FILE=TRIM(cl_namelist), EXIST=ll_exist)
+   IF( ll_exist )THEN
+      
+      il_fileid=fct_getunit()
+
+      OPEN( il_fileid, FILE=TRIM(cl_namelist),   &
+      &                FORM='FORMATTED',         &
+      &                ACCESS='SEQUENTIAL',      &
+      &                STATUS='OLD',             &
+      &                ACTION='READ',            &
+      &                IOSTAT=il_status)
+      CALL fct_err(il_status)
+      IF( il_status /= 0 )THEN
+         PRINT *,"ERROR in create_coord: error opening "//TRIM(cl_namelist)
+         STOP
+      ENDIF
+
+      READ( il_fileid, NML = namlog )
+      !1-2-1 define log file
+      CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity))
+      CALL logger_header()
+
+      READ( il_fileid, NML = namcfg )
+      !1-2-2 get variable extra information on configuration file
+      CALL var_def_extra(TRIM(cn_varcfg))
+
+      READ( il_fileid, NML = namcrs )
+      READ( il_fileid, NML = namvar )
+      !1-2-3 add user change in extra information
+      CALL var_chg_extra( cn_varinfo )
+
+      READ( il_fileid, NML = namnst )
+      READ( il_fileid, NML = namout )
+
+      CLOSE( il_fileid, IOSTAT=il_status )
+      CALL fct_err(il_status)
+      IF( il_status /= 0 )THEN
+         CALL logger_error("CREATE COORD: closing "//TRIM(cl_namelist))
+      ENDIF
+
+   ELSE
+
+      PRINT *,"ERROR in create_coord: can't find "//TRIM(cl_namelist)
+
+   ENDIF
+
+   !2- open files
+   IF( cn_coord0 /= '' )THEN
+      tl_coord0=file_init(TRIM(cn_coord0),id_perio=in_perio0)
+      CALL iom_open(tl_coord0)
+   ELSE
+       CALL logger_fatal("CREATE COORD: no coarse grid coordinate found. "//&
+      &     "check namelist")      
+   ENDIF
+
+   !3- check
+   !3-1 check output file do not already exist
+   INQUIRE(FILE=TRIM(cn_fileout), EXIST=ll_exist)
+   IF( ll_exist )THEN
+      CALL logger_fatal("CREATE COORD: output file "//TRIM(cn_fileout)//&
+      &  " already exist.")
+   ENDIF
+
+   !3-2 check namelist
+   IF( in_imin0 < 1 .OR. in_imax0 < 1 .OR. in_jmin0 < 1 .OR. in_jmax0 < 1)THEN
+      CALL logger_error("CREATE COORD: invalid point indice."//&
+      &  " check namelist "//TRIM(cl_namelist))
+   ENDIF
+
+   il_rho(:)=1
+   IF( in_rhoi < 1 .OR. in_rhoj < 1 )THEN
+      CALL logger_error("CREATE COORD: invalid refinement factor."//&
+      &  " check namelist "//TRIM(cl_namelist))
+   ELSE
+      il_rho(jp_I)=in_rhoi
+      il_rho(jp_J)=in_rhoj      
+   ENDIF
+
+   !3-3 check domain validity
+   CALL grid_check_dom(tl_coord0, in_imin0, in_imax0, in_jmin0, in_jmax0 )
+
+   !4- compute domain
+   tl_dom=dom_init( tl_coord0,         &
+   &                in_imin0, in_imax0,&
+   &                in_jmin0, in_jmax0 )
+
+   ! close file
+   CALL iom_close(tl_coord0)
+
+   !4-1 add extra band (if possible) to compute interpolation
+   CALL dom_add_extra(tl_dom)
+
+   !5- read variables on domain (ugly way to do it, have to work on it)
+   !5-1 init mpp structure
+   tl_mppcoordin=mpp_init(tl_coord0)
+
+   CALL file_clean(tl_coord0)
+
+   !5-2 get processor to be used
+   CALL mpp_get_use( tl_mppcoordin, tl_dom )
+
+   !5-3 open mpp files
+   CALL iom_mpp_open(tl_mppcoordin)
+
+   !5-4 fill variable value on domain
+   CALL iom_mpp_fill_var(tl_mppcoordin, tl_dom)
+
+   !5-5 close mpp files
+   CALL iom_mpp_close(tl_mppcoordin)
+
+   il_nvar=tl_mppcoordin%t_proc(1)%i_nvar
+   ALLOCATE( tl_var(il_nvar) )
+   DO ji=1,il_nvar
+
+      tl_var(ji)=tl_mppcoordin%t_proc(1)%t_var(ji)
+      !7- interpolate variables
+      CALL create_coord_interp( tl_var(ji), il_rho(:) )
+
+      !6- remove extraband added to domain
+      CALL dom_del_extra( tl_var(ji), tl_dom, il_rho(:) )
+
+      !7- add ghost cell
+      CALL grid_add_ghost(tl_var(ji),tl_dom%i_ighost,tl_dom%i_jghost)      
+
+      !8- filter
+      CALL filter_fill_value(tl_var(ji))      
+
+   ENDDO
+
+   !9- clean
+   DO ji=1,il_nvar
+      CALL var_clean(tl_mppcoordin%t_proc(1)%t_var(ji))
+   ENDDO
+   CALL mpp_clean(tl_mppcoordin)
+
+   !10- create file
+   tl_fileout=file_init(TRIM(cn_fileout))
+
+   !10-1 add dimension
+   ! save biggest dimension
+   tl_dim(:)=var_max_dim(tl_var(:))
+
+   DO ji=1,ip_maxdim
+      IF( tl_dim(ji)%l_use ) CALL file_add_dim(tl_fileout, tl_dim(ji))
+   ENDDO
+
+   !10-2 add variables
+
+   DO ji=1,il_nvar
+      CALL file_add_var(tl_fileout, tl_var(ji))
+   ENDDO
+
+   !10-3 add some attribute
+   tl_att=att_init("Created_by","SIREN create_coord")
+   CALL file_add_att(tl_fileout, tl_att)
+
+   cl_date=date_print(date_now())
+   tl_att=att_init("Creation_date",cl_date)
+   CALL file_add_att(tl_fileout, tl_att)
+
+   tl_att=att_init("source_file",TRIM(fct_basename(cn_coord0)))
+   CALL file_add_att(tl_fileout, tl_att)   
+
+   tl_att=att_init("source_i-indices",(/in_imin0,in_imax0/))
+   CALL file_add_att(tl_fileout, tl_att)   
+   tl_att=att_init("source_j-indices",(/in_jmin0,in_jmax0/))
+   CALL file_add_att(tl_fileout, tl_att)   
+
+   !10-4 create file
+   CALL iom_create(tl_fileout)
+
+   !10-5 write file
+   CALL iom_write_file(tl_fileout)
+
+   !10-6 close file
+   CALL iom_close(tl_fileout)
+
+   !11- clean
+   DO ji=1,il_nvar
+      CALL var_clean(tl_var(ji))
+   ENDDO
+   CALL file_clean(tl_fileout)
+
+   DEALLOCATE( tl_var) 
+
+   ! close log file
+   CALL logger_footer()
+   CALL logger_close()   
+
+!> @endcode
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] 
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE create_coord_interp( td_var,          &
+   &                               id_rho,          &
+   &                               id_iext, id_jext)
+
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TVAR) ,               INTENT(INOUT) :: td_var
+      INTEGER(i4), DIMENSION(:), INTENT(IN   ) :: id_rho
+      INTEGER(i4),               INTENT(IN   ), OPTIONAL :: id_iext
+      INTEGER(i4),               INTENT(IN   ), OPTIONAL :: id_jext
+
+      ! local variable
+      TYPE(TVAR)  :: tl_mask
+      TYPE(TVAR)  :: tl_var
+
+      INTEGER(i1), DIMENSION(:,:,:,:), ALLOCATABLE :: bl_mask
+
+      INTEGER(i4), DIMENSION(2,2) :: il_offset
+
+      INTEGER(i4) :: il_iext
+      INTEGER(i4) :: il_jext
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! copy variable
+      tl_var=td_var
+
+      !WARNING: two extrabands are required for cubic interpolation
+      il_iext=2
+      IF( PRESENT(id_iext) ) il_iext=id_iext
+
+      il_jext=2
+      IF( PRESENT(id_jext) ) il_jext=id_jext
+      
+      IF( il_iext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN
+         CALL logger_warn("CREATE COORD INTERP: at least extrapolation "//&
+         &  "on two points are required with cubic interpolation ")
+         il_iext=2
+      ENDIF
+
+      IF( il_jext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN
+         CALL logger_warn("CREATE COORD INTERP: at least extrapolation "//&
+         &  "on two points are required with cubic interpolation ")
+         il_jext=2
+      ENDIF
+
+      !1- work on mask
+      !1-1 create mask
+      ALLOCATE(bl_mask(tl_var%t_dim(1)%i_len, &
+      &                tl_var%t_dim(2)%i_len, &
+      &                tl_var%t_dim(3)%i_len, &
+      &                tl_var%t_dim(4)%i_len) )
+
+      bl_mask(:,:,:,:)=1
+      WHERE(tl_var%d_value(:,:,:,:)==tl_var%d_fill) bl_mask(:,:,:,:)=0      
+
+      SELECT CASE(TRIM(tl_var%c_point))
+      CASE DEFAULT ! 'T'
+         tl_mask=var_init('tmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
+      CASE('U')
+         tl_mask=var_init('umask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
+      CASE('V')
+         tl_mask=var_init('vmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
+      CASE('F')
+         tl_mask=var_init('fmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
+      END SELECT         
+
+      DEALLOCATE(bl_mask)
+
+      !1-2 interpolate mask
+      il_offset(:,:)=1
+      CALL interp_fill_value( tl_mask, id_rho(:), &
+      &                       id_offset=il_offset(:,:) )
+
+      !2- work on variable
+      !2-0 add extraband
+      CALL extrap_add_extrabands(tl_var, il_iext, il_jext)
+
+      !2-1 extrapolate variable
+      CALL extrap_fill_value( tl_var, id_iext=il_iext, id_jext=il_jext )
+
+      !2-2 interpolate variable
+      il_offset(:,:)=1
+      CALL interp_fill_value( tl_var, id_rho(:), &
+      &                       id_offset=il_offset(:,:))
+
+      !2-3 remove extraband
+      CALL extrap_del_extrabands(tl_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J))
+
+      !3- keep original mask 
+      WHERE( tl_mask%d_value(:,:,:,:) == 0 )
+         tl_var%d_value(:,:,:,:)=tl_var%d_fill
+      END WHERE
+
+      !4- save result
+      td_var=tl_var
+
+      ! clean variable structure
+      CALL var_clean(tl_mask)
+      CALL var_clean(tl_var)
+
+   END SUBROUTINE create_coord_interp
+   !> @endcode
+END PROGRAM create_coord
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/create_restart.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/create_restart.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/create_restart.f90	(revision 4245)
@@ -0,0 +1,1250 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+!
+! PROGRAM: create_restart
+!
+! DESCRIPTION:
+!> @brief 
+!> This program create restart file.
+!>
+!> @details
+!> Variables are read from restart file, or standard output.
+!> Then theses variables are interpolated on fine grid. 
+!> Finally table are split over new decomposition. 
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!>
+!> @todo
+!> - add attributes indices and refinement in output file
+!> - check fileout exist at the beginning
+!----------------------------------------------------------------------
+!> @code
+PROGRAM create_restart
+
+!   USE netcdf                         ! nf90 library
+   USE global                          ! global variable
+   USE kind                            ! F90 kind parameter
+   USE logger                          ! log file manager
+   USE fct                             ! basic useful function
+   USE date                            ! date manager
+   USE att                             ! attribute manager
+   USE dim                             ! dimension manager
+   USE var                             ! variable manager
+   USE file                            ! file manager
+   USE multi                           ! multi file manager
+   USE iom                             ! I/O manager
+   USE dom                             ! domain manager
+   USE grid                            ! grid manager
+   USE vgrid                           ! vertical grid manager
+   USE extrap                          ! extrapolation manager
+   USE interp                          ! interpolation manager
+   USE filter                          ! filter manager
+   USE mpp                             ! MPP manager
+   USE iom_mpp                         ! MPP I/O manager
+
+   IMPLICIT NONE
+
+
+   ! local variable
+   CHARACTER(LEN=lc)                                  :: cl_namelist
+   CHARACTER(LEN=lc)                                  :: cl_date
+   CHARACTER(LEN=lc)                                  :: cl_name
+   CHARACTER(LEN=lc)                                  :: cl_data
+
+   INTEGER(i4)                                        :: il_narg
+   INTEGER(i4)                                        :: il_status
+   INTEGER(i4)                                        :: il_fileid
+   INTEGER(i4)                                        :: il_attid
+   INTEGER(i4)                                        :: il_imin0
+   INTEGER(i4)                                        :: il_imax0
+   INTEGER(i4)                                        :: il_jmin0
+   INTEGER(i4)                                        :: il_jmax0
+   INTEGER(i4)      , DIMENSION(ip_maxdim)            :: il_rho
+   INTEGER(i4)      , DIMENSION(2)                    :: il_xghost
+   INTEGER(i4)      , DIMENSION(2,2)                  :: il_offset
+   INTEGER(i4)      , DIMENSION(2,2,2)                :: il_ind
+
+   LOGICAL                                            :: ll_exist
+
+   TYPE(TFILE)                                        :: tl_coord0
+   TYPE(TFILE)                                        :: tl_coord1
+   TYPE(TFILE)                                        :: tl_bathy1
+   TYPE(TFILE)                                        :: tl_file
+
+   TYPE(TDOM)                                         :: tl_dom1
+   TYPE(TDOM)                                         :: tl_dom0
+
+   TYPE(TATT)                                         :: tl_att
+   
+   TYPE(TVAR)                                         :: tl_depth
+   TYPE(TVAR)                                         :: tl_time
+   TYPE(TVAR)                                         :: tl_lon
+   TYPE(TVAR)                                         :: tl_lat
+   TYPE(TVAR)                                         :: tl_tmp
+   TYPE(TVAR)       , DIMENSION(:)      , ALLOCATABLE :: tl_var
+   TYPE(TVAR)       , DIMENSION(:)      , ALLOCATABLE :: tl_level
+   
+   TYPE(TDIM)       , DIMENSION(ip_maxdim)            :: tl_dim
+
+   TYPE(TMPP)                                         :: tl_mpp
+   TYPE(TMPP)                                         :: tl_mppout
+   TYPE(TMULTI)                                       :: tl_multi
+
+   ! loop indices
+   INTEGER(i4) :: ji
+   INTEGER(i4) :: jj
+   INTEGER(i4) :: jvar
+
+   ! namelist variable
+   CHARACTER(LEN=lc) :: cn_logfile = 'create_restart.log' 
+   CHARACTER(LEN=lc) :: cn_verbosity = 'warning' 
+
+   CHARACTER(LEN=lc) :: cn_varcfg = 'variable.cfg' 
+
+   CHARACTER(LEN=lc) :: cn_coord0 = '' 
+   INTEGER(i4)       :: in_perio0 = -1
+
+   CHARACTER(LEN=lc) :: cn_coord1 = ''
+   CHARACTER(LEN=lc) :: cn_bathy1 = ''
+   INTEGER(i4)       :: in_perio1 = -1
+   INTEGER(i4)       :: in_extrap = 0
+   LOGICAL           :: ln_fillclosed = .TRUE.
+
+   CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varinfo = ''
+   CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varfile = ''
+
+   INTEGER(i4)       :: in_imin0 = 0
+   INTEGER(i4)       :: in_imax0 = 0
+   INTEGER(i4)       :: in_jmin0 = 0
+   INTEGER(i4)       :: in_jmax0 = 0
+   INTEGER(i4)       :: in_rhoi = 0
+   INTEGER(i4)       :: in_rhoj = 0
+
+   CHARACTER(LEN=lc) :: cn_fileout = 'restart' 
+   INTEGER(i4)       :: in_nproc   = 0
+   INTEGER(i4)       :: in_niproc  = 0
+   INTEGER(i4)       :: in_njproc  = 0
+   CHARACTER(LEN=lc) :: cn_type    = ''
+
+   !-------------------------------------------------------------------
+
+   NAMELIST /namlog/ &  !< logger namelist
+   &  cn_logfile,    &  !< log file
+   &  cn_verbosity      !< log verbosity
+
+   NAMELIST /namcfg/ &  !< configuration namelist
+   &  cn_varcfg         !< variable configuration file
+
+   NAMELIST /namcrs/ &   !< coarse grid namelist
+   &  cn_coord0,  &      !< coordinate file
+   &  in_perio0          !< periodicity index
+   
+   NAMELIST /namfin/ &   !< fine grid namelist
+   &  cn_coord1,   &     !< coordinate file
+   &  cn_bathy1,   &     !< bathymetry file
+   &  in_perio1,   &     !< periodicity index
+   &  in_extrap,   &     !<
+   &  ln_fillclosed      !< fill closed sea
+ 
+   NAMELIST /namvar/ &  !< variable namelist
+   &  cn_varinfo, &     !< list of variable and interpolation method to be used. (ex: 'votemper:linear','vosaline:cubic' )
+   &  cn_varfile        !< list of variable file
+   
+   NAMELIST /namnst/ &  !< nesting namelist
+   &  in_imin0,    &     !< i-direction lower left  point indice 
+   &  in_imax0,    &     !< i-direction upper right point indice
+   &  in_jmin0,    &     !< j-direction lower left  point indice
+   &  in_jmax0,    &     !< j-direction upper right point indice
+   &  in_rhoi,    &     !< refinement factor in i-direction
+   &  in_rhoj           !< refinement factor in j-direction
+
+   NAMELIST /namout/ &  !< output namlist
+   &  cn_fileout, &     !< fine grid bathymetry file
+   &  in_nproc,   &     !< number of processor to be used
+   &  in_niproc,  &     !< i-direction number of processor
+   &  in_njproc,  &     !< j-direction numebr of processor
+   &  cn_type           !< output type format (dimg, cdf)
+   !-------------------------------------------------------------------
+
+   !1- namelist
+   !1-1 get namelist
+   il_narg=COMMAND_ARGUMENT_COUNT() !f03 intrinsec
+   IF( il_narg/=1 )THEN
+      PRINT *,"ERROR in create_restart: need a namelist"
+      STOP
+   ELSE
+      CALL GET_COMMAND_ARGUMENT(1,cl_namelist) !f03 intrinsec
+   ENDIF
+   
+   !1-2 read namelist
+   INQUIRE(FILE=TRIM(cl_namelist), EXIST=ll_exist)
+   IF( ll_exist )THEN
+      
+      il_fileid=fct_getunit()
+
+      OPEN( il_fileid, FILE=TRIM(cl_namelist), &
+      &                FORM='FORMATTED',       &
+      &                ACCESS='SEQUENTIAL',    &
+      &                STATUS='OLD',           &
+      &                ACTION='READ',          &
+      &                IOSTAT=il_status)
+      CALL fct_err(il_status)
+      IF( il_status /= 0 )THEN
+         PRINT *,"ERROR in create_restart: error opening "//TRIM(cl_namelist)
+         STOP
+      ENDIF
+
+      READ( il_fileid, NML = namlog )
+      !1-2-1 define log file
+      CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity))
+      CALL logger_header()
+
+      READ( il_fileid, NML = namcfg )
+      !1-2-2 get variable extra information
+      CALL var_def_extra(TRIM(cn_varcfg))
+
+      READ( il_fileid, NML = namcrs )
+      READ( il_fileid, NML = namfin )
+      READ( il_fileid, NML = namvar )
+      !1-2-3 add user change in extra information
+      CALL var_chg_extra(cn_varinfo)
+      !1-2-4 match variable with file
+      tl_multi=multi_init(cn_varfile)
+      
+      READ( il_fileid, NML = namnst )
+      READ( il_fileid, NML = namout )
+
+      CLOSE( il_fileid, IOSTAT=il_status )
+      CALL fct_err(il_status)
+      IF( il_status /= 0 )THEN
+         CALL logger_error("CREATE RESTART: closing "//TRIM(cl_namelist))
+      ENDIF
+
+   ELSE
+
+      PRINT *,"ERROR in create_restart: can't find "//TRIM(cl_namelist)
+
+   ENDIF
+
+   !2- open files
+   IF( cn_coord0 /= '' )THEN
+      tl_coord0=file_init(TRIM(cn_coord0),id_perio=in_perio0)
+      CALL iom_open(tl_coord0)
+   ELSE
+      CALL logger_fatal("CREATE RESTART: no coarse grid coordinate found. "//&
+      &     "check namelist")      
+   ENDIF
+
+   IF( TRIM(cn_coord1) /= '' )THEN
+      tl_coord1=file_init(TRIM(cn_coord1),id_perio=in_perio1)
+      CALL iom_open(tl_coord1)
+   ELSE
+      CALL logger_fatal("CREATE RESTART: no fine grid coordinate found. "//&
+      &     "check namelist")
+   ENDIF
+
+   IF( TRIM(cn_bathy1) /= '' )THEN
+      tl_bathy1=file_init(TRIM(cn_bathy1),id_perio=in_perio1)
+      CALL iom_open(tl_bathy1)
+   ELSE
+      CALL logger_fatal("CREATE RESTART: no fine grid bathymetry found. "//&
+      &     "check namelist")
+   ENDIF
+
+   !3- check
+   !3-2-1 check refinement factor
+   il_rho(:)=1
+   IF( in_rhoi < 1 .OR. in_rhoj < 1 )THEN
+      CALL logger_error("CREATE RESTART: invalid refinement factor."//&
+      &  " check namelist "//TRIM(cl_namelist))
+   ELSE
+      il_rho(jp_I)=in_rhoi
+      il_rho(jp_J)=in_rhoj
+   ENDIF
+
+   IF( cn_coord0 /= '' )THEN !.OR. cn_bathy0 /= '' )THEN
+
+      !3-1 check namelist
+      IF( in_imin0 < 1 .OR. in_imax0 < 1 .OR. in_jmin0 < 1 .OR. in_jmax0 < 1)THEN
+         ! compute coarse grid indices around fine grid
+         IF( cn_coord0 /= '' )THEN
+            il_ind(:,:,:)=grid_get_coarse_index(tl_coord0, tl_coord1 )
+         ENDIF
+
+         il_imin0=il_ind(1,1,1) ; il_imax0=il_ind(1,2,1)
+         il_jmin0=il_ind(2,1,1) ; il_jmax0=il_ind(2,2,1)
+
+         il_offset(:,:)=il_ind(:,:,2)
+      ELSE
+         il_imin0=in_imin0 ; il_imax0=in_imax0
+         il_jmin0=in_jmin0 ; il_jmax0=in_jmax0
+
+         il_offset(1,:)=FLOOR(REAL(il_rho(jp_I)-1,dp)*0.5)
+         il_offset(2,:)=FLOOR(REAL(il_rho(jp_J)-1,dp)*0.5)         
+      ENDIF
+
+      !3-2 check domain validity
+      IF( cn_coord0 /= '' )THEN
+         CALL grid_check_dom(tl_coord0, il_imin0, il_imax0, il_jmin0, il_jmax0)
+      ENDIF
+
+      !3-3 check coordinate file
+      IF( cn_coord0 /= '' )THEN
+         CALL grid_check_coincidence( tl_coord0, tl_coord1, &
+         &                            il_imin0, il_imax0, &
+         &                            il_jmin0, il_jmax0, &
+         &                            il_rho(:) )
+      ENDIF
+
+   ENDIF
+
+   ! compute level
+   ALLOCATE(tl_level(ig_npoint))
+   tl_level(:)=vgrid_get_level(tl_bathy1, cl_namelist )
+
+   ! remove ghost cell
+   il_xghost(:)=grid_get_ghost(tl_bathy1)
+
+   DO ji=1,ig_npoint
+      CALL grid_del_ghost(tl_level(ji), il_xghost(1), il_xghost(2))
+   ENDDO
+
+   ! close
+   CALL iom_close(tl_bathy1)
+
+   !4- work on variables
+   IF( .NOT. ASSOCIATED(tl_multi%t_file) )THEN
+      CALL logger_error("CREATE RESTART: no file to work on. "//&
+      &                 "check cn_varfile in namelist.")
+   ELSE
+      ALLOCATE( tl_var( tl_multi%i_nvar ) )
+      jvar=0
+      ! for each file
+      DO ji=1,tl_multi%i_nfile
+         WRITE(cl_data,'(a,i2.2)') 'data_',jvar+1
+
+         IF( .NOT. ASSOCIATED(tl_multi%t_file(ji)%t_var) )THEN
+
+            CALL logger_error("CREATE RESTART: no variable to work on for "//&
+            &                 "file "//TRIM(tl_multi%t_file(ji)%c_name)//&
+            &                 ". check cn_varfile in namelist.")
+
+         ELSEIF( TRIM(tl_multi%t_file(ji)%c_name) == TRIM(cl_data) )THEN
+         !4-1 use input matrix to fill variable
+
+            ! for each variable initialise from matrix
+            DO jj=1,tl_multi%t_file(ji)%i_nvar
+               jvar=jvar+1
+               tl_tmp=tl_multi%t_file(ji)%t_var(jj)
+               !4-1-1 fill value with matrix data
+               ! pb voir comment gerer nb de dimension
+               tl_var(jvar)=create_restart_matrix(tl_tmp, tl_coord1)
+
+               !4-1-2 use mask
+               CALL create_restart_mask(tl_var(jvar), tl_level(:))
+            ENDDO
+
+         ELSE
+         !4-2 use file to fill variable
+
+            ! open file
+            tl_file=file_init(TRIM(tl_multi%t_file(ji)%c_name))
+            CALL iom_open(tl_file)
+
+            ! get or check depth value
+            IF( tl_file%i_depthid /= 0 )THEN
+               IF( ASSOCIATED(tl_depth%d_value) )THEN
+                  IF( ANY( tl_depth%d_value(:,:,:,:) /= &
+                  &        tl_tmp%d_value(:,:,:,:) ) )THEN
+                     CALL logger_fatal("CREATE RESTART: depth value from "//&
+                     &  TRIM(tl_multi%t_file(ji)%c_name)//" not conform "//&
+                     &  " to those from former file(s).")
+                  ENDIF
+               ELSE
+                  tl_depth=iom_read_var(tl_file,tl_file%i_depthid)
+               ENDIF
+            ENDIF
+
+            ! get or check time value
+            IF( tl_file%i_timeid /= 0 )THEN
+               IF( ASSOCIATED(tl_time%d_value) )THEN
+                  IF( ANY( tl_time%d_value(:,:,:,:) /= &
+                  &        tl_tmp%d_value(:,:,:,:) ) )THEN
+                     CALL logger_fatal("CREATE RESTART: time value from "//&
+                     &  TRIM(tl_multi%t_file(ji)%c_name)//" not conform "//&
+                     &  " to those from former file(s).")
+                  ENDIF
+               ELSE
+                  tl_time=iom_read_var(tl_file,tl_file%i_timeid)
+               ENDIF
+            ENDIF
+
+            IF( ANY( tl_file%t_dim(1:2)%i_len /= &
+            &      tl_coord0%t_dim(1:2)%i_len) )THEN
+            !4-2-1 extract value from fine grid 
+
+               !4-2-1-1 compute domain on fine grid
+               tl_dom1=create__restart_get_dom_coord(tl_file, tl_coord1)
+               
+               ! open mpp file on domain
+               !4-2-1-2 init mpp structure
+               tl_mpp=mpp_init(tl_file)
+
+               !4-2-1-3 get processor to be used
+               CALL mpp_get_use( tl_mpp, tl_dom1 )
+               !4-2-1-4 open mpp files
+               CALL iom_mpp_open(tl_mpp)
+
+               ! for each variable of this file
+               DO jj=1,tl_multi%t_file(ji)%i_nvar
+                  jvar=jvar+1
+                  cl_name=tl_multi%t_file(ji)%t_var(jj)%c_name
+                  !4-2-1-5 read variable over domain
+                  tl_var(jvar)=iom_mpp_read_var( tl_mpp, TRIM(cl_name), &
+                  &                              td_dom=tl_dom1 )
+
+                  !4-2-1-7 add attribute to variable
+                  tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name)))
+                  CALL var_move_att(tl_var(jvar), tl_att)
+
+                  ! clean structure
+                  CALL att_clean(tl_att)
+
+                  !4-2-1-8 use mask
+                  CALL create_restart_mask(tl_var(jvar), tl_level(:))
+
+                  !4-2-1-9 add ghost cell
+                  CALL grid_add_ghost( tl_var(jvar), &
+                  &                    tl_dom1%i_ighost,tl_dom1%i_jghost )
+
+               ENDDO
+
+               !4-2-1-2 close mpp file
+               CALL iom_mpp_close(tl_mpp)
+               ! clean structure
+               CALL mpp_clean(tl_mpp)
+               CALL dom_clean(tl_dom1)
+
+            ELSE
+            !4-2-2 get value from coarse grid 
+
+               !4-2-2-1 compute domain on coarse grid
+               tl_dom0=create__restart_get_dom_index(tl_file, il_imin0, il_jmin0, &
+               &                                              il_imax0, il_jmax0)
+
+               !4-2-2-2 add extra band (if possible) to compute interpolation
+               CALL dom_add_extra(tl_dom0)
+
+               ! open mpp file on domain
+               !4-2-2-3 init mpp structure
+               tl_mpp=mpp_init(tl_file)
+
+               !4-2-2-4 get processor to be used
+               CALL mpp_get_use( tl_mpp, tl_dom0 )
+
+               !4-2-2-5 open mpp files
+               CALL iom_mpp_open(tl_mpp)
+
+               ! for each variable of this file
+               DO jj=1,tl_multi%t_file(ji)%i_nvar
+
+                  jvar=jvar+1
+                  cl_name=tl_multi%t_file(ji)%t_var(jj)%c_name
+                  print *,'work on ',trim(cl_name)
+                  !4-2-2-6 read variable over domain
+                  tl_var(jvar)=iom_mpp_read_var( tl_mpp, TRIM(cl_name), &
+                  &                              td_dom=tl_dom0 )
+
+                  !4-2-2-7 interpolate variable
+                  CALL create_restart_interp(tl_var(jvar), tl_level(:), &
+                  &                          il_rho(:), &
+                  &                          id_offset=il_offset(:,:))
+
+                  !tl_att=att_init('add_offset',0.)
+                  !CALL var_move_att(tl_var(jvar), tl_att)
+                  !tl_att=att_init('scale_factor',1.)
+                  !CALL var_move_att(tl_var(jvar), tl_att)
+
+                  !4-2-2-8 remove extraband added to domain
+                  CALL dom_del_extra( tl_var(jvar), tl_dom0, il_rho(:) )
+
+                  !4-2-2-10 add attribute to variable
+                  tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name)))
+                  CALL var_move_att(tl_var(jvar), tl_att)
+
+                  ! clean structure
+                  CALL att_clean(tl_att)
+
+                  !4-2-2-11 use mask
+                  CALL create_restart_mask(tl_var(jvar), tl_level(:))
+
+                  !4-2-2-12 add ghost cell
+                  CALL grid_add_ghost( tl_var(jvar), &
+                  &                    tl_dom0%i_ighost,tl_dom0%i_jghost )
+
+               ENDDO
+
+               !4-2-2-2 close mpp file
+               CALL iom_mpp_close(tl_mpp)
+               ! clean structure
+               CALL mpp_clean(tl_mpp)
+               CALL dom_clean(tl_dom0)
+
+            ENDIF
+
+            ! close file
+            CALL iom_close(tl_file)
+            ! clean structure
+            CALL file_clean(tl_file)
+         ENDIF
+      ENDDO
+   ENDIF
+
+   !5- use additional request
+   DO jvar=1,tl_multi%i_nvar
+
+         !5-1 forced min and max value
+         CALL var_limit_value(tl_var(jvar))
+
+         !5-2 filter
+         CALL filter_fill_value(tl_var(jvar))
+
+         !5-3 extrapolate
+         CALL extrap_fill_value(tl_var(jvar), id_iext=in_extrap, &
+         &                                    id_jext=in_extrap, &
+         &                                    id_kext=in_extrap)
+
+   ENDDO
+
+   !6- create file
+   IF( in_niproc == 0 .AND. &
+   &   in_njproc == 0 .AND. &
+   &   in_nproc  == 0 )THEN
+      in_niproc = 1
+      in_njproc = 1
+      in_nproc = 1
+   ENDIF
+   tl_mppout=mpp_init( TRIM(cn_fileout), tl_var(1), &
+   &                   in_niproc, in_njproc, in_nproc, &
+   &                   cd_type=cn_type)
+
+   !6-1 add dimension
+   tl_dim(:)=var_max_dim(tl_var(:))
+
+   DO ji=1,ip_maxdim
+      IF( tl_dim(ji)%l_use )THEN
+         CALL mpp_move_dim(tl_mppout, tl_dim(ji))
+         SELECT CASE(TRIM(tl_dim(ji)%c_sname))
+         CASE('z','t')
+            DO jj=1,tl_mppout%i_nproc
+               CALL file_add_dim(tl_mppout%t_proc(jj), tl_dim(ji))
+            ENDDO
+         END SELECT 
+      ENDIF
+   ENDDO
+
+   !6-2 add variables
+
+   !IF( ALL( tl_dim(1:2)%l_use ) )THEN
+   !   ! add longitude
+   !   tl_lon=iom_read_var(tl_coord1,'longitude')
+
+   !   CALL mpp_add_var(tl_mppout, tl_lon)
+   !   CALL var_clean(tl_lon)
+
+   !   ! add latitude
+   !   tl_lat=iom_read_var(tl_coord1,'latitude')
+
+   !   CALL mpp_add_var(tl_mppout, tl_lat)
+   !   CALL var_clean(tl_lat)
+   !ENDIF
+
+   !IF( tl_dim(3)%l_use )THEN
+   !   ! add depth
+   !   CALL mpp_add_var(tl_mppout, tl_depth)
+   !   CALL var_clean(tl_depth)
+   !ENDIF
+
+   !IF( tl_dim(4)%l_use )THEN
+   !   ! add time
+   !   CALL mpp_add_var(tl_mppout, tl_time)
+   !   CALL var_clean(tl_time)
+   !ENDIF
+
+   ! add other variable
+   DO jvar=1,tl_multi%i_nvar
+      CALL mpp_add_var(tl_mppout, tl_var(jvar))
+      CALL var_clean(tl_var(jvar))
+   ENDDO
+
+   DO ji=1,4
+      CALL mpp_add_var(tl_mppout,tl_level(ji))
+   ENDDO
+
+   !6-3 add some attribute
+   tl_att=att_init("Created_by","SIREN create_restart")
+   CALL mpp_add_att(tl_mppout, tl_att)
+
+   cl_date=date_print(date_now())
+   tl_att=att_init("Creation_date",TRIM(cl_date))
+   CALL mpp_add_att(tl_mppout, tl_att)
+
+   ! add attribute periodicity
+   il_attid=0
+   IF( ASSOCIATED(tl_mppout%t_proc(1)%t_att) )THEN
+      il_attid=att_get_id(tl_mppout%t_proc(1)%t_att(:),'periodicity')
+   ENDIF
+   IF( tl_coord1%i_perio >= 0 .AND. il_attid == 0 )THEN
+      tl_att=att_init('periodicity',tl_coord1%i_perio)
+      CALL mpp_add_att(tl_mppout,tl_att)
+   ENDIF
+
+   il_attid=0
+   IF( ASSOCIATED(tl_mppout%t_proc(1)%t_att) )THEN
+      il_attid=att_get_id(tl_mppout%t_proc(1)%t_att(:),'ew_overlap')
+   ENDIF
+   IF( tl_coord1%i_ew >= 0 .AND. il_attid == 0 )THEN
+      tl_att=att_init('ew_overlap',tl_coord1%i_ew)
+      CALL mpp_add_att(tl_mppout,tl_att)
+   ENDIF
+
+   !6-4 create file
+   CALL iom_mpp_create(tl_mppout)
+
+   !6-5 write file
+   CALL iom_mpp_write_file(tl_mppout)
+
+   !6-6 close file
+   CALL iom_mpp_close(tl_mppout)
+   IF( cn_coord0 /= '' ) CALL iom_close(tl_coord0)
+
+   !7- clean
+   DEALLOCATE(tl_var)
+
+   CALL mpp_clean(tl_mppout)
+   CALL file_clean(tl_coord1)
+   CALL file_clean(tl_coord0)
+
+   ! close log file
+   CALL logger_footer()
+   CALL logger_close()
+
+!> @endcode
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION create_restart_level(td_level1)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE), INTENT(IN) :: td_level1
+
+      ! function
+      TYPE(TVAR), DIMENSION(4) :: create_restart_level
+
+      ! local variable
+      TYPE(TFILE)              :: tl_level1
+      TYPE(TVAR), DIMENSION(4) :: tl_var
+      TYPE(TMPP)               :: tl_mpplevel1
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      !0- compute domain
+      tl_dom1=dom_init(td_level1)
+
+      !1 init mpp structure
+      tl_level1=td_level1
+      tl_mpplevel1=mpp_init(tl_level1)
+      
+      CALL file_clean(tl_level1)
+
+      !2 get processor to be used
+      CALL mpp_get_use( tl_mpplevel1, tl_dom1 )
+
+      !3 open mpp files
+      CALL iom_mpp_open(tl_mpplevel1)
+      tl_var(jp_T)=iom_mpp_read_var(tl_mpplevel1,'tlevel',td_dom=tl_dom1)
+      tl_var(jp_U)=iom_mpp_read_var(tl_mpplevel1,'ulevel',td_dom=tl_dom1)
+      tl_var(jp_V)=iom_mpp_read_var(tl_mpplevel1,'vlevel',td_dom=tl_dom1)
+      tl_var(jp_F)=iom_mpp_read_var(tl_mpplevel1,'flevel',td_dom=tl_dom1)
+
+      !4 save result
+      create_restart_level(:)=tl_var(:)
+
+      !5 clean
+      CALL iom_mpp_close(tl_mpplevel1)
+      CALL mpp_clean(tl_mpplevel1)
+
+   END FUNCTION create_restart_level
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function create variable, filled with matrix value
+   !> 
+   !> @details 
+   !> A variable is create with the same name that the input variable, 
+   !> and with dimension of the coordinate file. 
+   !> Then the variable table of value is split into equal subdomain.
+   !> Each subdomain is fill with the linked value of the matrix.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] td_var : variable structure 
+   !> @param[in] td_coord : coordinate 
+   !> @return variable structure 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION create_restart_matrix(td_var, td_coord)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_var
+      TYPE(TFILE), INTENT(IN) :: td_coord
+
+      ! function
+      TYPE(TVAR) :: create_restart_matrix
+
+      ! local variable
+      INTEGER(i4)                                        :: il_ighost
+      INTEGER(i4)                                        :: il_jghost
+      INTEGER(i4)      , DIMENSION(2)                    :: il_xghost
+      INTEGER(i4)      , DIMENSION(3)                    :: il_dim
+      INTEGER(i4)      , DIMENSION(3)                    :: il_size
+      INTEGER(i4)      , DIMENSION(3)                    :: il_rest
+
+      INTEGER(i4)      , DIMENSION(:)      , ALLOCATABLE :: il_ishape
+      INTEGER(i4)      , DIMENSION(:)      , ALLOCATABLE :: il_jshape
+      INTEGER(i4)      , DIMENSION(:)      , ALLOCATABLE :: il_kshape
+
+      REAL(dp)         , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      TYPE(TVAR)                                         :: tl_lon
+      TYPE(TVAR)                                         :: tl_lat
+      TYPE(TVAR)                                         :: tl_var
+      TYPE(TDIM)       , DIMENSION(ip_maxdim)            :: tl_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      !1- read output grid
+      tl_lon=iom_read_var(td_coord,'longitude')
+      tl_lat=iom_read_var(td_coord,'latitude')
+
+      !2- look for ghost cell
+      il_xghost(:)=grid_get_ghost( tl_lon, tl_lat )
+
+      il_ighost=il_xghost(1)*ig_ghost
+      il_jghost=il_xghost(2)*ig_ghost
+      
+      !3- write value on grid
+      !3-1 get matrix dimension
+      il_dim(:)=td_var%t_dim(1:3)%i_len
+      !3-2 output dimension
+      tl_dim(:)=tl_lon%t_dim(:)
+
+      ! remove ghost cell
+      tl_dim(1)%i_len=tl_dim(1)%i_len - 2*il_xghost(1)*ig_ghost
+      tl_dim(2)%i_len=tl_dim(2)%i_len - 2*il_xghost(2)*ig_ghost
+
+      !3-3 split output domain in N subdomain depending of matrix dimension 
+      il_size(:) = tl_dim(1:3)%i_len / il_dim(:)
+      il_rest(:) = MOD(tl_dim(1:3)%i_len, il_dim(:))
+
+      ALLOCATE( il_ishape(il_dim(1)+1) )
+      il_ishape(:)=0
+      DO ji=2,il_dim(1)+1
+         il_ishape(ji)=il_ishape(ji-1)+il_size(1)
+      ENDDO
+      ! add rest to last cell
+      il_ishape(il_dim(1)+1)=il_ishape(il_dim(1)+1)+il_rest(1)
+      
+
+      ALLOCATE( il_jshape(il_dim(2)+1) )
+      il_jshape(:)=0
+      DO jj=2,il_dim(2)+1
+         il_jshape(jj)=il_jshape(jj-1)+il_size(2)
+      ENDDO
+      ! add rest to last cell
+      il_jshape(il_dim(2)+1)=il_jshape(il_dim(2)+1)+il_rest(2)
+
+      ALLOCATE( il_kshape(il_dim(3)+1) )
+      il_kshape(:)=0
+      DO jk=2,il_dim(3)+1
+         il_kshape(jk)=il_kshape(jk-1)+il_size(3)
+      ENDDO
+      ! add rest to last cell
+      il_kshape(il_dim(3)+1)=il_kshape(il_dim(3)+1)+il_rest(3)
+
+      !3-3 write ouput table of value 
+      ALLOCATE(dl_value( tl_dim(1)%i_len, &
+      &                  tl_dim(2)%i_len, &
+      &                  tl_dim(3)%i_len, &
+      &                  tl_dim(4)%i_len) )
+
+      dl_value(:,:,:,:)=0
+
+      DO jk=2,il_dim(3)+1
+         DO jj=2,il_dim(2)+1
+            DO ji=2,il_dim(1)+1
+               
+               dl_value( 1+il_ishape(ji-1):il_ishape(ji), &
+               &         1+il_jshape(jj-1):il_jshape(jj), &
+               &         1+il_kshape(jk-1):il_kshape(jk), &
+               &         1 ) = td_var%d_value(ji-1,jj-1,jk-1,1)
+
+            ENDDO
+         ENDDO
+      ENDDO
+
+      !3-4 initialise variable with value
+      tl_var=var_init(TRIM(td_var%c_name),dl_value(:,:,:,:))
+
+      DEALLOCATE(dl_value)
+
+      !4- add ghost cell
+      CALL grid_add_ghost(tl_var,il_ighost,il_jghost)
+
+      !5- save result
+      create_restart_matrix=tl_var
+
+   END FUNCTION create_restart_matrix
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION create__restart_get_dom_coord( td_file, td_coord, &
+   &                                       id_rho )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE),               INTENT(IN) :: td_file
+      TYPE(TFILE),               INTENT(IN) :: td_coord
+      INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_rho
+
+      ! function
+      TYPE(TDOM) :: create__restart_get_dom_coord
+
+      ! local variable
+      INTEGER(i4)                 :: il_pivot
+      INTEGER(i4)                 :: il_perio
+
+      INTEGER(i4)                 :: il_imin
+      INTEGER(i4)                 :: il_imax
+      INTEGER(i4)                 :: il_jmin
+      INTEGER(i4)                 :: il_jmax
+
+      INTEGER(i4), DIMENSION(2,2,2) :: il_ind
+
+      TYPE(TFILE)                 :: tl_file
+
+      TYPE(TDOM)                  :: tl_dom
+      ! loop indices
+      !----------------------------------------------------------------
+
+      tl_file=td_file
+      !1- open file
+      CALL iom_open(tl_file)
+
+      ! get periodicity
+      il_pivot=grid_get_pivot(tl_file)
+      il_perio=grid_get_perio(tl_file,il_pivot)
+
+      tl_file%i_perio=il_perio
+
+      !2- compute file grid indices around coord grid
+      il_ind(:,:,:)=grid_get_coarse_index(tl_file, td_coord )
+
+      il_imin=il_ind(1,1,1) ; il_imax=il_ind(1,2,1)
+      il_jmin=il_ind(2,1,1) ; il_jmax=il_ind(2,2,1)
+
+      !3- check grid coincidence
+      CALL grid_check_coincidence( tl_file, td_coord, &
+      &                            il_imin, il_imax, &
+      &                            il_jmin, il_jmax, &
+      &                            id_rho(:) )
+
+      !4- compute domain
+      tl_dom=dom_init(tl_file,         &
+      &               il_imin, il_imax, &
+      &               il_jmin, il_jmax)
+
+      ! close file
+      CALL iom_close(tl_file)
+
+      ! save result
+      create__restart_get_dom_coord=tl_dom
+
+   END FUNCTION create__restart_get_dom_coord
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION create__restart_get_dom_index( td_file, id_imin, id_jmin, &
+   &                                                id_imax, id_jmax )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE), INTENT(IN) :: td_file
+      INTEGER(i4), INTENT(IN) :: id_imin
+      INTEGER(i4), INTENT(IN) :: id_imax
+      INTEGER(i4), INTENT(IN) :: id_jmin
+      INTEGER(i4), INTENT(IN) :: id_jmax
+
+      ! function
+      TYPE(TDOM) :: create__restart_get_dom_index
+
+      ! local variable
+      INTEGER(i4)                 :: il_pivot
+      INTEGER(i4)                 :: il_perio
+
+      TYPE(TFILE)                 :: tl_file
+
+      TYPE(TDOM)                  :: tl_dom
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! init
+      tl_file=td_file
+      !1- open file
+      CALL iom_open(tl_file)
+
+      ! get periodicity
+      il_pivot=grid_get_pivot(tl_file)
+      il_perio=grid_get_perio(tl_file,il_pivot)
+
+      tl_file%i_perio=il_perio
+
+      !2- compute domain
+      tl_dom=dom_init(tl_file,         &
+      &               id_imin, id_imax, &
+      &               id_jmin, id_jmax)
+
+      ! close file
+      CALL iom_close(tl_file)
+
+      ! save result
+      create__restart_get_dom_index=tl_dom
+
+   END FUNCTION create__restart_get_dom_index
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] 
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE create_restart_mask( td_var, td_mask )
+
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TVAR)              , INTENT(INOUT) :: td_var
+      TYPE(TVAR), DIMENSION(:), INTENT(IN   ) :: td_mask
+
+      ! local variable
+      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_mask
+
+      ! loop indices
+      INTEGER(i4) :: jl
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      IF( ANY(td_var%t_dim(1:2)%i_len /= td_mask(1)%t_dim(1:2)%i_len) )THEN
+         CALL logger_error("CREATE RESTART MASK: dimension differ between "//&
+         &                 "variable ("//&
+         &                 TRIM(fct_str(td_var%t_dim(1)%i_len))//","//&
+         &                 TRIM(fct_str(td_var%t_dim(2)%i_len))//&
+         &                 ") and level ("//&
+         &                 TRIM(fct_str(td_mask(1)%t_dim(1)%i_len))//","//&
+         &                 TRIM(fct_str(td_mask(1)%t_dim(2)%i_len))//")")
+      ELSE
+         ALLOCATE( il_mask(td_var%t_dim(1)%i_len, &
+         &                 td_var%t_dim(2)%i_len) )
+
+         SELECT CASE(TRIM(td_var%c_point))
+         CASE('T')
+            il_mask(:,:)=INT(td_mask(jp_T)%d_value(:,:,1,1))
+         CASE('U')
+            il_mask(:,:)=INT(td_mask(jp_U)%d_value(:,:,1,1))
+         CASE('V')
+            il_mask(:,:)=INT(td_mask(jp_V)%d_value(:,:,1,1))
+         CASE('F')
+            il_mask(:,:)=INT(td_mask(jp_F)%d_value(:,:,1,1))
+         END SELECT
+
+         DO jl=1,td_var%t_dim(4)%i_len
+            DO jk=1,td_var%t_dim(3)%i_len
+               WHERE( il_mask(:,:) < jk ) td_var%d_value(:,:,jk,jl)=99 !td_var%d_fill
+                  !.AND. &
+                  !&   td_var%d_value(:,:,jk,jl) == td_var%d_fill .OR. &
+                  !&   il_mask(:,:) < jk .AND. &
+                  !&   td_var%d_value(:,:,jk,jl) == 1 ) td_var%d_value(:,:,jk,jl)=99 !td_var%d_fill
+            ENDDO
+         ENDDO
+
+         DEALLOCATE( il_mask )
+      ENDIF
+   END SUBROUTINE create_restart_mask
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION create_restart_extract(td_var, td_file, &
+   &                             td_coord)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_var  
+      TYPE(TFILE), INTENT(IN) :: td_file
+      TYPE(TFILE), INTENT(IN) :: td_coord
+
+      ! function
+      TYPE(TVAR) :: create_restart_extract
+
+      ! local variable
+      INTEGER(i4), DIMENSION(2,2,2) :: il_ind
+
+      INTEGER(i4) :: il_pivot
+      INTEGER(i4) :: il_perio
+
+      INTEGER(i4) :: il_imin
+      INTEGER(i4) :: il_jmin
+      INTEGER(i4) :: il_imax
+      INTEGER(i4) :: il_jmax
+
+      TYPE(TFILE) :: tl_file
+
+      TYPE(TMPP)  :: tl_mpp
+
+      TYPE(TATT)  :: tl_att
+
+      TYPE(TVAR)  :: tl_var
+      
+      TYPE(TDOM)  :: tl_dom
+      ! loop indices
+      !----------------------------------------------------------------
+
+      IF( td_file%i_id == 0 )THEN
+         CALL logger_error("CREATE RESTART EXTRACT: file "//&
+         &  TRIM(td_file%c_name)//" not opened ")
+      ELSE
+
+         !init
+         tl_file=td_file
+
+         !1- open file
+         CALL iom_open(tl_file)
+
+         ! get periodicity
+         il_pivot=grid_get_pivot(tl_file)
+         il_perio=grid_get_perio(tl_file,il_pivot)
+
+         tl_file%i_perio=il_perio
+
+         !2- compute file grid indices around coord grid
+         il_ind(:,:,:)=grid_get_coarse_index(tl_file, td_coord )
+
+         il_imin=il_ind(1,1,1) ; il_imax=il_ind(1,2,1)
+         il_jmin=il_ind(2,1,1) ; il_jmax=il_ind(2,2,1)
+   
+         !3- check grid coincidence
+         CALL grid_check_coincidence( tl_file, td_coord, &
+         &                            il_imin, il_imax, &
+         &                            il_jmin, il_jmax, &
+         &                            (/1, 1, 1/) )
+
+         !4- compute domain
+         tl_dom=dom_init(tl_file,         &
+         &               il_imin, il_imax, &
+         &               il_jmin, il_jmax)
+
+         ! close file
+         CALL iom_close(tl_file)
+
+         !5- read bathymetry on domain (ugly way to do it, have to work on it)
+         !5-1 init mpp structure
+         tl_mpp=mpp_init(tl_file)
+
+         CALL file_clean(tl_file)
+
+         !5-2 get processor to be used
+         CALL mpp_get_use( tl_mpp, tl_dom )
+
+         !5-3 open mpp files
+         CALL iom_mpp_open(tl_mpp)
+
+         !5-4 read variable on domain
+         tl_var=iom_mpp_read_var(tl_mpp,TRIM(td_var%c_name),td_dom=tl_dom)
+
+         !5-5 close mpp file
+         CALL iom_mpp_close(tl_mpp)
+
+         !6- add ghost cell
+         CALL grid_add_ghost(tl_var,tl_dom%i_ighost,tl_dom%i_jghost)
+
+         !7- check result
+         IF( ANY( tl_var%t_dim(:)%l_use .AND. &
+         &        tl_var%t_dim(:)%i_len /= td_coord%t_dim(:)%i_len) )THEN
+            CALL logger_debug("CREATE BATHY EXTRACT: "//&
+            &        "dimensoin of variable "//TRIM(td_var%c_name)//" "//&
+            &        TRIM(fct_str(tl_var%t_dim(1)%i_len))//","//&
+            &        TRIM(fct_str(tl_var%t_dim(2)%i_len))//","//&
+            &        TRIM(fct_str(tl_var%t_dim(3)%i_len))//","//&
+            &        TRIM(fct_str(tl_var%t_dim(4)%i_len)) )
+            CALL logger_debug("CREATE BATHY EXTRACT: "//&
+            &        "dimensoin of coordinate file "//&
+            &        TRIM(fct_str(td_coord%t_dim(1)%i_len))//","//&
+            &        TRIM(fct_str(td_coord%t_dim(2)%i_len))//","//&
+            &        TRIM(fct_str(td_coord%t_dim(3)%i_len))//","//&
+            &        TRIM(fct_str(td_coord%t_dim(4)%i_len)) )
+            CALL logger_fatal("CREATE BATHY EXTRACT: "//&
+            &  "dimensoin of extracted "//&
+            &  "variable and coordinate file dimension differ")
+         ENDIF
+
+         !8- add attribute to variable
+         tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name)))
+         CALL var_move_att(tl_var, tl_att)         
+
+         !9- save result
+         create_restart_extract=tl_var
+
+         ! clean structure
+         CALL var_clean(tl_var)
+         CALL mpp_clean(tl_mpp)
+      ENDIF
+
+   END FUNCTION create_restart_extract
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] 
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE create_restart_interp( td_var, td_level,&
+   &                                 id_rho,          &
+   &                                 id_offset,       &
+   &                                 id_iext, id_jext)
+
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TVAR) ,                 INTENT(INOUT) :: td_var
+      TYPE(TVAR) , DIMENSION(:)  , INTENT(INOUT) :: td_level
+      INTEGER(i4), DIMENSION(:)  , INTENT(IN   ) :: id_rho
+      INTEGER(i4), DIMENSION(:,:), INTENT(IN   ) :: id_offset
+      INTEGER(i4),                 INTENT(IN   ), OPTIONAL :: id_iext
+      INTEGER(i4),                 INTENT(IN   ), OPTIONAL :: id_jext
+
+      ! local variable
+      TYPE(TVAR)  :: tl_var
+
+      INTEGER(i4) :: il_iext
+      INTEGER(i4) :: il_jext
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! copy variable
+      tl_var=td_var
+
+      il_iext=3
+      IF( PRESENT(id_iext) ) il_iext=id_iext
+
+      il_jext=3
+      IF( PRESENT(id_jext) ) il_jext=id_jext
+
+      IF( il_iext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN
+         CALL logger_warn("CREATE RESTART INTERP: at least extrapolation "//&
+         &  "on two points are required with cubic interpolation ")
+         il_iext=2
+      ENDIF
+
+      IF( il_jext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN
+         CALL logger_warn("CREATE RESTART INTERP: at least extrapolation "//&
+         &  "on two points are required with cubic interpolation ")
+         il_jext=2
+      ENDIF
+
+      il_iext=0
+      il_jext=0
+
+      ! work on variable
+      !1 add extraband
+      CALL extrap_add_extrabands(tl_var, il_iext, il_jext)
+
+      !2 extrapolate variable
+      CALL extrap_fill_value( tl_var, td_level(:),    &
+      &                               id_offset(:,:), &
+      &                               id_rho(:),      &
+      &                               id_iext=il_iext, id_jext=il_jext )
+
+      !3 interpolate variable
+      CALL interp_fill_value( tl_var, id_rho(:), &
+      &                       id_offset=id_offset(:,:) )
+
+      !4 remove extraband
+      CALL extrap_del_extrabands(tl_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J))
+
+      !5- save result
+      td_var=tl_var
+
+      ! clean variable structure
+      CALL var_clean(tl_var)
+
+   END SUBROUTINE create_restart_interp
+   !> @endcode
+END PROGRAM create_restart
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/date.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/date.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/date.f90	(revision 4245)
@@ -0,0 +1,941 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: date
+!
+! DESCRIPTION:
+!> @brief This module provide the calculation of Julian dates, and
+!> do many manipulations with dates.<br/>
+!> Actually we use Modified Julian Dates, with origin the 
+!> 17 Nov 1858 at 00:00:00
+!
+!> @details
+!>   define type TDATE:<br/>
+!>   TYPE(TDATE) :: tl_date1<br/>
+!>   default date is 17 Nov 1858 at 00:00:00<br/>
+!>
+!>   to intialise date : <br/>
+!>   - from date of the day at 12:00:00 : tl_date1=date_today()<br/>
+!>   - from date and time of the day    : tl_date1=date_now()<br/>
+!>   - from julian day                  : tl_date1=date_init(1.)<br/>  
+!>   - from year month day              : tl_date1=date_init(2012,12,10)<br/>
+!>
+!>   to print date in format YYYY-MM-DD hh:mm:ss<br/>
+!>   CHARACTER(LEN=lc) :: cl_date<br/>
+!>   cl_date=date_print(tl_date1)<br/>
+!>   PRINT *, TRIM(cl_date)<br/>
+!>
+!>   to print day if the week:<br/>
+!>   PRINT *,"dow ", tl_date1\%i_dow<br/>
+!>   to print last day of the month:<br/>
+!>   PRINT *,"last day ", tl_date1\%i_lday<br/>
+!>   to know if year is a leap year:<br/>
+!>   LOGICAL :: ll_isleap<br/>
+!>   ll_isleap=date_leapyear(tl_date1)<br/>
+!>
+!>   to compute difference between to dates:<br/>
+!>   tl_date2=date_init(2010,12,10)<br/>
+!>   print *,"diff ",tl_date1-tl_date2<br/>
+!>
+!>   to add or substract nday to a date:<br/>
+!>   tl_date2=tl_date1+2.<br/>
+!>   print *,"add ",trim(date_print(tl_date2))<br/>
+!>   tl_date2=tl_date1-2.6<br/>
+!>   print *,"sub ",trim(date_print(tl_date2))<br/>
+!>
+!>   to print julian day:<br/>
+!>   print *," julian day",tl_date1\%r_jd<br/>
+!>
+!>   to print CNES julian day (origin 1950-01-01 00:00:00)<br/>
+!>   print *," CNES julian day",tl_date1\%r_jc<br/>
+!>
+!>   to create pseudo julian day with origin date_now:<br/>
+!>   tl_date1=date_init(2012,12,10,td_dateo=date_now())<br/>
+!>   print *," new julian day",tl_date1\%r_jc<br/>
+!>   Note that you erase CNES julian day when doing so<br/> 
+!>
+!>   to print julian day in seconds:<br/>
+!>   print *, tl_date1\%k_jdsec<br/>
+!>   to print CNES or new julian day in seconds:<br/>
+!>   print *, tl_date1\%k_jcsec<br/>
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note This module is based on Perderabo's date calculator (ksh)
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!> @todo
+!> - check if real(sp), integer(i8) is enough
+!> - see calendar.f90 and select Gregorian, NoLeap, or D360 calendar
+!> - add suffix to number
+!> - add log message
+!----------------------------------------------------------------------
+MODULE date
+   USE global                          ! global variable
+   USE kind                            ! F90 kind parameter
+   USE fct                             ! basic useful function
+   USE logger                             ! log file manager
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+   PUBLIC :: TDATE              ! date structure
+
+   ! function and subroutine
+   PUBLIC :: OPERATOR(-)        ! substract two dates or n days to a date
+   PUBLIC :: OPERATOR(+)        ! add n days to a date
+   PUBLIC :: date_init          ! initiazed date structure form julian day or year month day
+   PUBLIC :: date_now           ! return the date and time
+   PUBLIC :: date_today         ! return the date of the day at 12:00:00
+   PUBLIC :: date_print         ! print the date with format YYYY-MM-DD hh:mm:ss
+   PUBLIC :: date_leapyear      ! check if year is a leap year
+
+   PRIVATE :: date__init_fmtdate ! initiazed date structure from character YYYY-MM-DD hh:mm:ss
+   PRIVATE :: date__init_jd      ! initiazed date structure from julian day
+   PRIVATE :: date__init_nsec    ! initiazed date structure from number of second since origin of julian day
+   PRIVATE :: date__init_ymd     ! initiazed date structure from year month day
+   PRIVATE :: date__addnday      ! add nday to a date
+   PRIVATE :: date__subnday      ! substract nday to a date
+   PRIVATE :: date__diffdate     ! compute number of day between two dates 
+   PRIVATE :: date__lastday      ! compute last day of the month
+   PRIVATE :: date__ymd2jd       ! compute julian day from year month day
+   PRIVATE :: date__jd2ymd       ! compute year month day from julian day 
+   PRIVATE :: date__jc2jd        ! compute julian day from pseudo julian day
+   PRIVATE :: date__jd2jc        ! compute pseudo julian day with new date origin
+   PRIVATE :: date__jd2dow       ! compute the day of week from julian day
+   PRIVATE :: date__hms2jd       ! compute fraction of a day from hour, minute, second
+   PRIVATE :: date__jd2hms       ! compute hour, minute, second from julian fraction
+   PRIVATE :: date__check        ! check date in date structure
+   PRIVATE :: date__adjust       ! adjust date
+   PRIVATE :: date__jd2sec       ! convert julian day in seconds since julian day origin 
+   PRIVATE :: date__sec2jd       ! convert seconds since julian day origin in julian day
+
+   !> @struct TDATE
+   TYPE TDATE
+      INTEGER(i4) :: i_year  = 1858   !< year
+      INTEGER(i4) :: i_month = 11     !< month
+      INTEGER(i4) :: i_day   = 17     !< day
+      INTEGER(i4) :: i_hms   = 0      !< fraction of the day
+      INTEGER(i4) :: i_hour  = 0      !< hour
+      INTEGER(i4) :: i_min   = 0      !< min
+      INTEGER(i4) :: i_sec   = 0      !< sec
+      INTEGER(i4) :: i_dow   = 0      !< day of week
+      INTEGER(i4) :: i_lday  = 0      !< last day of the month
+      REAL(sp)    :: r_jd = 0         !< julian day (origin : 1858/11/17 00:00:00)
+      REAL(sp)    :: r_jc = 0         !< CNES julian day or pseudo julian day with new date origin    
+      INTEGER(i8) :: k_jdsec  = 0     !< number of seconds since julian day origin
+      INTEGER(i8) :: k_jcsec  = 0     !< number of seconds since CNES or pseudo julian day origin
+   END TYPE TDATE   
+
+   !  module variable   
+   CHARACTER(LEN=lc), PARAMETER :: cm_fmtdate = &  !< date format
+   &  "(i0.4,'-',i0.2,'-',i0.2,1x,i0.2,':',i0.2,':',i0.2)"
+
+   INTEGER(i4), PARAMETER :: im_secbyday = 86400    !< number of second by day   
+
+   INTERFACE date_init
+      MODULE PROCEDURE date__init_jd    ! initiazed date structure from julian day
+      MODULE PROCEDURE date__init_nsec  ! initiazed date structure from number of second since origin of julian day
+      MODULE PROCEDURE date__init_ymd   ! initiazed date structure from year month day
+      MODULE PROCEDURE date__init_fmtdate   ! initiazed date structure from character YYYY-MM-DD hh:mm:ss
+   END INTERFACE date_init
+
+   INTERFACE OPERATOR(+)
+      MODULE PROCEDURE date__addnday   ! add nday to a date
+   END INTERFACE
+
+   INTERFACE OPERATOR(-)
+      MODULE PROCEDURE date__subnday   ! substract nday to a date
+      MODULE PROCEDURE date__diffdate  ! compute number of day between two dates
+   END INTERFACE
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief This function print the date with 
+   !> format YYYY/MM/DD hh:mm:ss
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_date : date strutcutre
+   !> @return date in format YYYY-MM-DD hh:mm:ss
+   !-------------------------------------------------------------------
+   ! @code
+   CHARACTER(LEN=lc) FUNCTION date_print(td_date)
+      IMPLICIT NONE
+      ! Argument   
+      TYPE(TDATE), INTENT(IN) :: td_date
+      !----------------------------------------------------------------
+
+      WRITE(date_print,cm_fmtdate) &
+      &    td_date%i_year,td_date%i_month,td_date%i_day, &
+      &    td_date%i_hour,td_date%i_min,td_date%i_sec
+
+   END FUNCTION date_print
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function check if year is a leap year.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_date : date strutcutre
+   !> @return true if year is leap year
+   !-------------------------------------------------------------------
+   ! @code
+   LOGICAL FUNCTION date_leapyear(td_date)
+      IMPLICIT NONE
+      ! Argument   
+      TYPE(TDATE), INTENT(IN) :: td_date
+      !----------------------------------------------------------------
+
+      date_leapyear=.false.
+      IF( (MOD(td_date%i_year,100_i4)==0) )THEN
+         IF( (MOD(td_date%i_year,400_i4)==0) )THEN
+            date_leapyear=.true.
+         ENDIF
+      ELSE
+         IF( (MOD(td_date%i_year,4_i4)==0) )THEN
+            date_leapyear=.true.
+         ENDIF
+      ENDIF      
+
+   END FUNCTION date_leapyear
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function return the date and time 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @return date and time of the day in a date structure
+   !-------------------------------------------------------------------
+   ! @code
+   TYPE(TDATE) FUNCTION date_now()
+      IMPLICIT NONE
+      ! local variable
+      INTEGER(sp), DIMENSION(8) :: il_values
+      !----------------------------------------------------------------
+
+      CALL DATE_AND_TIME( values= il_values)
+
+      date_now=date_init( il_values(1), il_values(2), il_values(3), &
+      &                   il_values(5), il_values(6), il_values(7) )
+
+   END FUNCTION date_now
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function return the date of the day at 12:00:00 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @return date of the day at 12:00:00 in a date structure
+   !-------------------------------------------------------------------
+   ! @code
+   TYPE(TDATE) FUNCTION date_today()
+      IMPLICIT NONE
+      ! local variable
+      INTEGER(sp), DIMENSION(8) :: il_values
+      !----------------------------------------------------------------
+
+      CALL DATE_AND_TIME( values= il_values)
+
+      date_today=date_init( il_values(1), il_values(2), il_values(3), 12_i4 )
+
+   END FUNCTION date_today
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initiazed date structure from a character 
+   !> date with format YYYY-MM-DD hh:mm:ss
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_date : date in format YYYY-MM-DD hh:mm:ss
+   !> @param[in] td_dateo : new date origin for pseudo julian day
+   !> @return date structure
+   !-------------------------------------------------------------------
+   ! @code
+   TYPE(TDATE) FUNCTION date__init_fmtdate(cd_date, td_dateo)
+      IMPLICIT NONE
+      ! Argument   
+      CHARACTER(LEN=*), INTENT(IN)  :: cd_date
+      TYPE(TDATE),      INTENT(IN), OPTIONAL :: td_dateo
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_date
+      CHARACTER(LEN=lc) :: cl_year
+      CHARACTER(LEN=lc) :: cl_month
+      CHARACTER(LEN=lc) :: cl_day
+      CHARACTER(LEN=lc) :: cl_hour
+      CHARACTER(LEN=lc) :: cl_min
+      CHARACTER(LEN=lc) :: cl_sec
+
+      INTEGER(i4) :: il_year
+      INTEGER(i4) :: il_month
+      INTEGER(i4) :: il_day
+      INTEGER(i4) :: il_hour
+      INTEGER(i4) :: il_min
+      INTEGER(i4) :: il_sec
+      !----------------------------------------------------------------
+
+      cl_date=TRIM(ADJUSTL(cd_date))
+
+      cl_year=cl_date(1:4)
+      READ(cl_year,*) il_year
+      cl_month=cl_date(6:7)
+      READ(cl_month, *) il_month
+      cl_day=cl_date(9:10)
+      READ(cl_day, *) il_day
+      cl_hour=cl_date(12:13)
+      READ(cl_hour, *) il_hour
+      cl_min=cl_date(15:16)
+      READ(cl_min, *) il_min
+      cl_sec=cl_date(18:19)
+      READ(cl_sec, *) il_sec
+
+      date__init_fmtdate = date_init( il_year, il_month, il_day, il_hour, &
+      &                               il_min, il_sec, td_dateo=td_dateo )
+
+   END FUNCTION date__init_fmtdate
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function initiazed date structure from julian day<br/>
+   !> optionaly create pseudo julian day with new origin<br/>
+   !> julian day origin is 17 Nov 1858 at 00:00:00
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] rd_jd : julian day
+   !> @param[in] td_dateo : new date origin for pseudo julian day
+   !
+   !> @return date structure of julian day
+   !-------------------------------------------------------------------
+   ! @code
+   TYPE(TDATE) FUNCTION date__init_jd(rd_jd, td_dateo)
+      IMPLICIT NONE
+      !Argument
+      REAL(sp),    INTENT(IN)  :: rd_jd
+      TYPE(TDATE), INTENT(IN), OPTIONAL :: td_dateo
+      !----------------------------------------------------------------
+      IF( PRESENT(td_dateo) )THEN
+         CALL date__check(td_dateo)
+
+         ! pseudo julian day with origin dateo
+         date__init_jd%r_jc=rd_jd
+         date__init_jd%k_jcsec=date__jd2sec(rd_jd)
+
+         ! convert to truly julian day
+         CALL date__jc2jd(date__init_jd, td_dateo)
+      ELSE
+         date__init_jd%r_jd=rd_jd
+         date__init_jd%k_jdsec=date__jd2sec(rd_jd)
+
+         ! compute CNES julian day
+         CALL date__jd2jc(date__init_jd)
+      ENDIF
+
+      ! check input data
+      CALL date__check(date__init_jd)
+
+      ! compute year month day hour min sec 
+      CALL date__jd2ymd(date__init_jd)
+
+      ! compute day of the wekk
+      CALL date__jd2dow(date__init_jd)
+
+      !compute last day of the month
+      date__init_jd%i_lday=date__lastday(date__init_jd)
+
+   END FUNCTION date__init_jd
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initiazed date structure from number of 
+   !> second since julian day origin<br/>
+   !> optionaly create pseudo julian day with new origin
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] rd_jd : julian day
+   !> @param[in] td_dateo : new date origin for pseudo julian day
+   !
+   !> @return date structure of julian day
+   !-------------------------------------------------------------------
+   ! @code
+   TYPE(TDATE) FUNCTION date__init_nsec(kd_nsec, td_dateo)
+      IMPLICIT NONE
+      !Argument
+      INTEGER(i8), INTENT(IN)  :: kd_nsec
+      TYPE(TDATE), INTENT(IN), OPTIONAL :: td_dateo
+      !----------------------------------------------------------------
+      IF( PRESENT(td_dateo) )THEN
+         date__init_nsec=date_init( date__sec2jd(kd_nsec), td_dateo )
+      ELSE
+         date__init_nsec=date_init( date__sec2jd(kd_nsec) )
+      ENDIF
+
+   END FUNCTION date__init_nsec
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function initiazed date structure form year month day
+   !> and optionnaly hour min sec<br/>
+   !> optionaly create pseudo julian day with new origin
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] id_year
+   !> @param[in] id_month
+   !> @param[in] id_day
+   !> @param[in] id_hour
+   !> @param[in] id_min
+   !> @param[in] id_sec
+   !> @param[in] td_dateo : new date origin for pseudo julian day
+   !
+   !> @return date structure of year month day
+   !-------------------------------------------------------------------
+   ! @code
+   TYPE(TDATE) FUNCTION date__init_ymd(id_year, id_month, id_day,  &
+   &                                   id_hour, id_min, id_sec, &
+   &                                   td_dateo)
+      IMPLICIT NONE
+      !Argument
+      INTEGER(i4), INTENT(IN) :: id_year
+      INTEGER(i4), INTENT(IN) :: id_month
+      INTEGER(i4), INTENT(IN) :: id_day
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_hour
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_min
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_sec
+      TYPE(TDATE), INTENT(IN), OPTIONAL :: td_dateo
+      !----------------------------------------------------------------
+      date__init_ymd%i_year=id_year
+      date__init_ymd%i_month=id_month
+      date__init_ymd%i_day=id_day
+      IF( PRESENT(id_hour) )THEN
+         date__init_ymd%i_hour=id_hour
+      ENDIF
+      IF( PRESENT(id_min) )THEN
+         date__init_ymd%i_min=id_min
+      ENDIF   
+      IF( PRESENT(id_sec) )THEN   
+         date__init_ymd%i_sec=id_sec
+      ENDIF   
+      ! check input data
+      CALL date__check(date__init_ymd)
+
+      ! compute julian day
+      CALL date__ymd2jd(date__init_ymd)
+
+      IF( PRESENT(td_dateo) )THEN
+         CALL date__check(td_dateo)
+         ! compute julian day with origin dateo
+         CALL date__jd2jc(date__init_ymd, td_dateo)         
+      ELSE
+         ! compute CNES julian day
+         CALL date__jd2jc(date__init_ymd)
+      ENDIF      
+
+      ! compute day of the week
+      CALL date__jd2dow(date__init_ymd)
+
+      !compute last day of the month
+      date__init_ymd%i_lday=date__lastday(date__init_ymd)
+
+   END FUNCTION date__init_ymd
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute number of day between two dates<br/> 
+   !> nday= date1 - date2
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_date1 : first date strutcutre
+   !> @param[in] td_date2 : second date strutcutre
+   !> @return nday
+   !-------------------------------------------------------------------
+   ! @code
+   REAL(sp) FUNCTION date__diffdate(td_date1, td_date2)
+      IMPLICIT NONE
+       
+      !Argument
+      TYPE(TDATE), INTENT(IN) :: td_date1
+      TYPE(TDATE), INTENT(IN) :: td_date2
+      !----------------------------------------------------------------
+
+      ! check year month day hour min sec
+      CALL date__check(td_date1)   
+      CALL date__check(td_date2)   
+
+      date__diffdate = td_date1%r_jd - td_date2%r_jd
+
+   END FUNCTION date__diffdate
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function substract nday to a date 
+   !> date2 = date1 - nday
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_date : date strutcutre
+   !> @param[in] rd_nday : number of day
+   !> @return date strutcutre of date - nday
+   !-------------------------------------------------------------------
+   ! @code
+   TYPE(TDATE) FUNCTION date__subnday(td_date, rd_nday)
+      IMPLICIT NONE
+      !Argument
+      TYPE(TDATE), INTENT(IN) :: td_date
+      REAL(sp),    INTENT(IN) :: rd_nday
+      !----------------------------------------------------------------
+
+      ! check year month day hour min sec
+      CALL date__check(td_date)   
+
+      date__subnday=date__init_jd(td_date%r_jd-rd_nday)
+
+   END FUNCTION date__subnday
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function add nday to a date  
+   !> date2 = date1 + nday
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_date : date strutcutre
+   !> @param[in] rd_nday : number of day
+   !> @return date strutcutre of date + nday
+   !-------------------------------------------------------------------
+   ! @code
+   TYPE(TDATE) FUNCTION date__addnday(td_date, rd_nday)
+      IMPLICIT NONE
+      !Argument
+      TYPE(TDATE), INTENT(IN) :: td_date
+      REAL(sp),    INTENT(IN) :: rd_nday
+      !----------------------------------------------------------------
+
+      ! check year month day hour min sec
+      CALL date__check(td_date)   
+
+      date__addnday=date__init_jd(td_date%r_jd+rd_nday)
+
+   END FUNCTION date__addnday
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine compute last day of the month
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_date : date strutcutre
+   !-------------------------------------------------------------------
+   ! @code
+   INTEGER(i4) FUNCTION date__lastday(td_date)
+      IMPLICIT NONE
+      ! Argument   
+      TYPE(TDATE), INTENT(IN) :: td_date
+
+      ! local variable
+      INTEGER, DIMENSION(12), PARAMETER :: il_lastdaytab = &
+      &        (/31,28,31,30,31,30,31,31,30,31,30,31/)
+      !----------------------------------------------------------------
+
+      ! general case
+      IF( td_date%i_month /= 2 )THEN
+         date__lastday=il_lastdaytab(td_date%i_month)
+      ELSE
+         IF( date_leapyear(td_date) )THEN
+            date__lastday=29
+         ELSE
+            date__lastday=il_lastdaytab(td_date%i_month)
+         ENDIF
+      ENDIF
+
+   END FUNCTION date__lastday
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine compute julian day from year month day
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_date : date strutcutre
+   !> @return julian day in the date strutcutre
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE date__ymd2jd(td_date)
+      IMPLICIT NONE
+      ! Argument   
+      TYPE(TDATE), INTENT(INOUT) :: td_date
+
+      ! local variable
+      REAL(sp) :: rl_standard_jd
+      REAL(sp) :: rl_frac
+      !----------------------------------------------------------------
+
+      rl_standard_jd= td_date%i_day - 32075                               & 
+          & + 1461 * (td_date%i_year + 4800 - (14 - td_date%i_month)/12)/4  &
+          & + 367 * (td_date%i_month - 2 + (14 - td_date%i_month)/12*12)/12 &
+          & - 3 * ((td_date%i_year + 4900 - (14 - td_date%i_month)/12)/100)/4
+      
+      td_date%r_jd = rl_standard_jd-2400001 ! origin : 17 nov 1858 h00m00s00
+
+      ! compute fraction of day
+      rl_frac=date__hms2jd(td_date)
+
+      td_date%r_jd = td_date%r_jd + rl_frac
+
+      td_date%k_jdsec = date__jd2sec( td_date%r_jd ) 
+
+   END SUBROUTINE date__ymd2jd
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine compute year month day from julian day
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_date : date strutcutre
+   !> @return year month day in the date strutcutre
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE date__jd2ymd(td_date)
+      IMPLICIT NONE
+      ! Argument   
+      TYPE(TDATE), INTENT(INOUT) :: td_date
+
+      ! local variable
+      REAL(sp) :: rl_frac
+      INTEGER(i4) :: il_standard_jd
+      INTEGER(i4) :: il_temp1
+      INTEGER(i4) :: il_temp2
+      !----------------------------------------------------------------
+
+      ! check year month day hour min sec
+      CALL date__check(td_date)   
+
+      il_standard_jd=INT( td_date%r_jd+2400001, i4 )
+      rl_frac=(td_date%r_jd+2400001)-il_standard_jd
+
+      il_temp1=il_standard_jd + 68569
+      il_temp2=4*il_temp1/146097
+      il_temp1=il_temp1 - (146097 * il_temp2 + 3) / 4
+      td_date%i_year  = 4000 * (il_temp1 + 1) / 1461001
+      il_temp1 = il_temp1 - 1461 * td_date%i_year/4 + 31
+      td_date%i_month = 80 * il_temp1 / 2447
+      td_date%i_day   = il_temp1 - 2447 * td_date%i_month / 80
+      il_temp1 = td_date%i_month / 11
+      td_date%i_month = td_date%i_month + 2 - 12 * il_temp1
+      td_date%i_year  = 100 * (il_temp2 - 49) + td_date%i_year + il_temp1
+
+      ! compute hour, minute, second from julian fraction
+      CALL date__jd2hms(td_date)
+
+      ! adjust date
+      CALL date__adjust(td_date)
+
+   END SUBROUTINE date__jd2ymd
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine compute julian day from pseudo julian day 
+   !> with new date origin<br/>
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_date : date
+   !> @return julian day inside input date structure
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE date__jc2jd(td_date, td_dateo)
+      IMPLICIT NONE
+      ! Argument   
+      TYPE(TDATE), INTENT(INOUT) :: td_date
+      TYPE(TDATE), INTENT(IN) :: td_dateo
+
+      ! local variable
+      TYPE(TDATE) :: tl_date
+      REAL(sp)    :: rl_nday
+      !----------------------------------------------------------------
+      ! origin julian day
+      tl_date=date_init(1858,11,17)
+
+      rl_nday=td_dateo-tl_date
+
+      ! compute julian day
+      td_date%r_jd = td_date%r_jc + rl_nday
+      ! compute number of second since julian day origin
+      td_date%k_jdsec = date__jd2sec(td_date%r_jd)
+
+   END SUBROUTINE date__jc2jd
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine compute pseudo julian day with new date origin<br/>
+   !>  default new origin is CNES julian day origin: 1950/01/01
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_date : date
+   !> @param[in] td_dateo : new origin date
+   !> @return pseudo julian day inside input date structure
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE date__jd2jc(td_date, td_dateo)
+      IMPLICIT NONE
+      ! Argument   
+      TYPE(TDATE), INTENT(INOUT) :: td_date
+      TYPE(TDATE), INTENT(IN),   OPTIONAL :: td_dateo
+
+      ! local variable
+      TYPE(TDATE) :: tl_dateo
+      !----------------------------------------------------------------
+      IF( PRESENT(td_dateo) )THEN
+         td_date%r_jc=td_date%r_jd-td_dateo%r_jd
+      ELSE
+         ! CNES julian day origin
+         tl_dateo%i_year = 1950
+         tl_dateo%i_month = 1
+         tl_dateo%i_day = 1
+
+         CALL date__ymd2jd(tl_dateo)
+
+         td_date%r_jc = td_date%r_jd-tl_dateo%r_jd
+      ENDIF
+
+      td_date%k_jcsec = date__jd2sec(td_date%r_jc)
+
+   END SUBROUTINE date__jd2jc
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine compute the day of week from julian day<br/>
+   !>  days   : Sunday Monday Tuesday Wednesday Thursday Friday Saturday<br/>
+   !>  numday : 0      1      2       3         4        5      6<br/>
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_date : date strutcutre
+   !> @return day of week inside input date structure 
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE date__jd2dow(td_date)
+      IMPLICIT NONE
+      ! Argument   
+      TYPE(TDATE), INTENT(INOUT) :: td_date
+      !----------------------------------------------------------------
+
+      td_date%i_dow=MOD((INT(AINT(td_date%r_jd))+3),7)
+
+   END SUBROUTINE date__jd2dow
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function compute fraction of a day from 
+   !> hour, minute, second 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_date : date strutcutre
+   !> @return fraction of the day
+   !-------------------------------------------------------------------
+   ! @code
+   REAL(sp) FUNCTION date__hms2jd(td_date)
+      IMPLICIT NONE
+      ! Argument   
+      TYPE(TDATE), INTENT(IN) :: td_date
+      !----------------------------------------------------------------
+
+      !  compute real seconds
+      date__hms2jd = REAL( td_date%i_sec, sp )   
+      !  compute real minutes
+      date__hms2jd = REAL( td_date%i_min, sp ) + date__hms2jd/60.0
+      !  compute real hours
+      date__hms2jd = REAL( td_date%i_hour, sp ) + date__hms2jd/60.0
+      !  julian fraction of a day
+      date__hms2jd = date__hms2jd/24.0
+
+   END FUNCTION date__hms2jd
+   ! @endcode 
+   !-------------------------------------------------------------------
+   !> @brief This function compute hour, minute, second from julian 
+   !> fraction
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_date : date strutcutre
+   !> @return date strutcutre
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE date__jd2hms(td_date)
+      IMPLICIT NONE
+      ! Argument   
+      TYPE(TDATE), INTENT(INOUT) :: td_date
+
+      !local variable
+      REAL(sp) :: rl_fract
+      !----------------------------------------------------------------
+
+      rl_fract=(td_date%r_jd)-AINT(td_date%r_jd)
+      !  compute hour
+      td_date%i_hour = INT( rl_fract * 24.0, i4 )
+      rl_fract = ( rl_fract - REAL( td_date%i_hour, sp ) / 24.0) * 24.0
+      !  compute minute
+      td_date%i_min = INT( rl_fract * 60.0, i4 )
+      rl_fract = ( rl_fract - REAL( td_date%i_min, sp ) / 60.0) * 60.0
+      !  compute second
+      td_date%i_sec = NINT( rl_fract * 60.0, i4 )
+
+   END SUBROUTINE date__jd2hms
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine check date express in date structure
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_date : date strutcutre
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE date__check(td_date)
+      IMPLICIT NONE
+      ! Argument   
+      TYPE(TDATE), INTENT(IN) :: td_date
+
+      ! local variable
+      INTEGER(i4)       :: il_lastday
+      INTEGER(i4)       :: il_status
+      CHARACTER(LEN=lc) :: cl_msg
+      !----------------------------------------------------------------
+
+      ! check year
+      IF( td_date%i_year < 1858_i4 .OR. td_date%i_year > 39999_i4 )THEN
+         WRITE(cl_msg,*) "year ",td_date%i_year," out of range"
+         CALL logger_error(cl_msg)
+         CALL fct_err(il_status)
+      ENDIF
+      ! check month
+      IF( td_date%i_month < 1_i4 .OR. td_date%i_month > 12_i4 )THEN
+         WRITE(cl_msg,*) "month ",td_date%i_month," out of range"
+         CALL logger_error(cl_msg)
+         CALL fct_err(il_status)
+      ENDIF
+      ! check day
+      il_lastday=date__lastday(td_date)
+      IF( td_date%i_day < 1_i4 .OR. td_date%i_day > il_lastday )THEN
+         WRITE(cl_msg,*) "day ",td_date%i_day," out of range"
+         CALL logger_error(cl_msg)
+         CALL fct_err(il_status)
+      ENDIF
+      ! check hour
+      IF( td_date%i_hour < 0_i4 .OR. td_date%i_hour > 23_i4 )THEN
+         WRITE(cl_msg,*) "hour ",td_date%i_hour," out of range"
+         CALL logger_error(cl_msg)
+         CALL fct_err(il_status)
+      ENDIF
+      ! check minutes
+      IF( td_date%i_min < 0_i4 .OR. td_date%i_min > 59_i4 )THEN
+         WRITE(cl_msg,*) "minutes ",td_date%i_min," out of range"
+         CALL logger_error(cl_msg)
+         CALL fct_err(il_status)
+      ENDIF   
+      ! check seconds
+      IF( td_date%i_sec < 0_i4 .OR. td_date%i_sec > 59_i4 )THEN
+         WRITE(cl_msg,*) "seconds ",td_date%i_sec," out of range"
+         CALL logger_error(cl_msg)
+         CALL fct_err(il_status)
+      ENDIF
+
+      ! check julian day
+      IF( td_date%r_jd < 0_sp .OR. td_date%r_jd > 782028_sp )THEN
+         WRITE(cl_msg,*) "julian day ",td_date%r_jd," out of range"
+         CALL logger_error(cl_msg)
+         CALL fct_err(il_status)
+      ENDIF
+
+   END SUBROUTINE date__check
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine adjust date
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_date : date strutcutre
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE date__adjust(td_date)
+      IMPLICIT NONE
+      ! Argument   
+      TYPE(TDATE), INTENT(INOUT) :: td_date
+      !----------------------------------------------------------------
+
+      IF( td_date%i_sec == 60 )THEN
+         td_date%i_sec=0
+         td_date%i_min=td_date%i_min+1
+      ENDIF
+      
+      IF( td_date%i_min == 60 )THEN
+         td_date%i_min=0
+         td_date%i_hour=td_date%i_hour+1
+      ENDIF
+
+      IF( td_date%i_hour == 24 )THEN
+         td_date%i_hour=0
+         td_date=date__addnday(td_date,1._sp)
+      ENDIF
+
+   END SUBROUTINE date__adjust
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function convert julian day in seconds
+   !> since julian day origin
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_date : date strutcutre
+   !> @return number of seconds since julian day origin
+   !-------------------------------------------------------------------
+   ! @code
+   INTEGER(i8) FUNCTION date__jd2sec(rd_jul)
+      IMPLICIT NONE
+      ! Argument   
+      REAL(sp), INTENT(IN) :: rd_jul
+      !----------------------------------------------------------------
+
+      date__jd2sec = NINT( rd_jul * im_secbyday, i8 )
+
+   END FUNCTION date__jd2sec
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function convert seconds since julian day origin in 
+   !> julian day
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_date : date strutcutre
+   !> @return number of seconds since julian day origin
+   !-------------------------------------------------------------------
+   ! @code
+   REAL(sp) FUNCTION date__sec2jd(kd_nsec)
+      IMPLICIT NONE
+      ! Argument   
+      INTEGER(i8), INTENT(IN) :: kd_nsec
+      !----------------------------------------------------------------
+
+      date__sec2jd = REAL( REAL( kd_nsec , sp ) / im_secbyday, sp )
+
+   END FUNCTION date__sec2jd
+   ! @endcode   
+END MODULE date
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/dimension.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/dimension.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/dimension.f90	(revision 4245)
@@ -0,0 +1,1332 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: dim
+!
+! DESCRIPTION:
+!> @brief 
+!> This module manage dimension and how to change order of those dimension.
+!
+!> @details
+!>    define type TDIM:<br/>
+!>    TYPE(TDIM) :: tl_dim<br/>
+!>
+!>    to initialise a dimension structure:<br/>
+!>    - tl_dim=dim_init( cd_name, [id_len,] [ld_uld,] [cd_sname])
+!>       - cd_name is the dimension name
+!>       - id_len is the dimension size (optional)
+!>       - ld_uld is true if this dimension is the unlimited one (optional)
+!>       - cd_sname is the dimension short name (optional)
+!>
+!>    to print information about dimension structure:<br/>
+!>    CALL dim_print(tl_dim)
+!>
+!>    to get dimension name:<br/>
+!>    - tl_dim\%c_name
+!>
+!>    to get dimension short name:<br/>
+!>    - tl_dim\%c_sname
+!>
+!>    to get dimension length:<br/>
+!>    - tl_dim\%i_len
+!>
+!>    to know if dimension is the unlimited one:<br/>
+!>    - tl_dim\%l_uld
+!>
+!>    to get dimension id (use for variable or file dimension):<br/>
+!>    - tl_dim\%i_id 
+!>
+!>    to know if dimension is used (use for variable or file dimension):<br/>
+!>    - tl_dim\%l_use
+!>
+!>    Former function or information concern only one dimension. However
+!>    variables as well as files use usually 4 dimensions.<br/>
+!>    To easily work with variable we want they will be all 4D and ordered as
+!>    follow: ('x','y','z','t').<br/>
+!>    Functions and subroutines below, allow to reorder dimension of 
+!>    variable.<br/>
+!>    
+!>    Suppose we defined the table of dimension structure below:<br/>
+!>    TYPE(TDIM), DIMENSION(4) :: tl_dim
+!>    tl_dim(1)=dim_init( 'X', id_len=10)
+!>    tl_dim(2)=dim_init( 'T', id_len=3, ld_uld=.TRUE.)
+!>
+!>    to reorder dimension as we assume variable are defined
+!>    ('x','y','z','t'):<br/>
+!>    CALL dim_reorder(tl(dim(:))
+!>
+!>    This subroutine filled dimension structure with unused dimension, 
+!>    then switch from "unordered" dimension to "ordered" dimension
+!>    The dimension structure return will be:
+!>    tl_dim(1) => 'X', i_len=10, l_use=T, l_uld=F
+!>    tl_dim(2) => 'Y', i_len=0,  l_use=F, l_uld=F 
+!>    tl_dim(3) => 'Z', i_len=0,  l_use=F, l_uld=F
+!>    tl_dim(4) => 'T', i_len=3,  l_use=T, l_uld=T
+!>
+!>    After using dim_reorder subroutine you could use functions and subroutine
+!>    below.<br/>
+!>
+!>    to reshape table of value in "ordered" dimension:<br/>
+!>    CALL dim_reshape_2xyzt(tl_dim(:), value(:,:,:,:))
+!>       - value must be a 4D table of real(8) value "unordered"
+!>
+!>    to reshape table of value in "unordered" dimension:<br/>
+!>    CALL dim_reshape_xyzt2(tl_dim(:), value(:,:,:,:))
+!>       - value must be a 4D table of real(8) value "ordered"
+!>
+!>    to reorder a 1D table of 4 elements in "ordered" dimension:<br/>
+!>    CALL dim_reorder_2xyzt(tl_dim(:), tab(:))
+!>
+!>       - tab must be a 1D table with 4 elements "unordered".
+!>       It could be composed of character, integer(4), or logical
+!> 
+!>    to reorder a 1D table of 4 elements in "unordered" dimension:<br/>
+!>    CALL dim_reorder_2xyzt(tl_dim(:), tab(:))
+!>
+!>       - tab must be a 1D table with 4 elements "ordered".
+!>       It could be composed of character, integer(4), or logical
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @todo
+!> - add description generique de l'objet dim
+!>
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!----------------------------------------------------------------------
+MODULE dim
+   USE global                          ! global variable
+   USE kind                            ! F90 kind parameter
+   USE logger                          ! log file manager
+   USE fct                             ! basic useful function
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+   PUBLIC :: TDIM              !< dimension structure
+   PUBLIC :: ip_maxdim         !< number of dimension to be used
+   PUBLIC :: cp_dimorder       !< dimension order
+
+   ! function and subroutine
+   PUBLIC :: dim_init          !< initialize dimension structure
+   PUBLIC :: dim_clean         !< clean dimension structuree
+   PUBLIC :: dim_print         !< print dimension information
+   PUBLIC :: dim_get_id        !< get dimension id in table of dimension structure
+   PUBLIC :: dim_get_void_id   !< get unused dimension id in table of dimension structure
+   PUBLIC :: dim_order         !< check if dimension are ordered or not
+   PUBLIC :: dim_reorder       !< filled dimension structure to switch from unordered to ordered dimension
+   PUBLIC :: dim_unorder       !< switch dimension table from ordered to unordered dimension
+   PUBLIC :: dim_reshape_2xyzt !< reshape table dimension to ('x','y','z','t')
+   PUBLIC :: dim_reshape_xyzt2 !< reshape table dimension from ('x','y','z','t')
+   PUBLIC :: dim_reorder_2xyzt !< reorder 1D table to ('x','y','z','t')
+   PUBLIC :: dim_reorder_xyzt2 !< reorder 1D table from ('x','y','z','t')
+
+   PRIVATE :: dim__fill_unused      !< filled dimension structure with unused dimension 
+   PRIVATE :: dim__reshape_2xyzt_dp !< reshape real(8) 4D table to ('x','y','z','t')
+   PRIVATE :: dim__reshape_xyzt2_dp !< reshape real(8) 4D table from ('x','y','z','t')
+   PRIVATE :: dim__reorder_2xyzt_i4 !< reorder integer(4) 1D table to ('x','y','z','t')
+   PRIVATE :: dim__reorder_xyzt2_i4 !< reorder integer(4) 1D table from ('x','y','z','t')
+   PRIVATE :: dim__reorder_2xyzt_l  !< reorder logical 1D table to ('x','y','z','t')
+   PRIVATE :: dim__reorder_xyzt2_l  !< reorder logical 1D table from ('x','y','z','t')
+   PRIVATE :: dim__reorder_2xyzt_c  !< reorder string 1D table to ('x','y','z','t')
+   PRIVATE :: dim__reorder_xyzt2_c  !< reorder string 1D table from ('x','y','z','t')
+   PRIVATE :: dim__clean_unit       !< clean one dimension structure
+   PRIVATE :: dim__clean_tab        !< clean a table of dimension structure
+   PRIVATE :: dim__print_unit       !< print information on one dimension structure
+   PRIVATE :: dim__print_tab        !< print information on a table of dimension structure
+
+   !> @struct TDIM
+   TYPE TDIM
+      CHARACTER(LEN=lc) :: c_name = ''!< dimension name
+      CHARACTER(LEN=lc) :: c_sname = 'u'     !< dimension short name
+      INTEGER(i4)       :: i_id = 0          !< dimension id
+      INTEGER(i4)       :: i_len = 1         !< dimension length
+      LOGICAL           :: l_uld = .FALSE.   !< dimension unlimited or not
+      LOGICAL           :: l_use = .FALSE.   !< dimension used or not
+      INTEGER(i4)       :: i_2xyzt = 0       !< indices to reshape table to ('x','y','z','t')
+      INTEGER(i4)       :: i_xyzt2 = 0       !< indices to reshape table from ('x','y','z','t')
+   END TYPE
+
+   INTEGER(i4), PARAMETER :: ip_maxdim = 4  !< number of dimension to be used
+
+   !  module variable
+   CHARACTER(LEN=lc), PARAMETER :: cp_dimorder = 'xyzt' !< dimension order to output
+
+   INTERFACE dim_print
+      MODULE PROCEDURE dim__print_unit ! print information on one dimension
+      MODULE PROCEDURE dim__print_tab  ! print information on a table of dimension
+   END INTERFACE dim_print
+
+   INTERFACE dim_clean
+      MODULE PROCEDURE dim__clean_unit ! clean one dimension
+      MODULE PROCEDURE dim__clean_tab  ! clean a table of dimension
+   END INTERFACE dim_clean
+
+   INTERFACE dim_reshape_2xyzt
+      MODULE PROCEDURE dim__reshape_2xyzt_dp   ! reshape real(8) 4D table to ('x','y','z','t')
+   END INTERFACE dim_reshape_2xyzt
+
+   INTERFACE dim_reshape_xyzt2
+      MODULE PROCEDURE dim__reshape_xyzt2_dp   ! reshape real(8) 4D table from ('x','y','z','t')
+   END INTERFACE dim_reshape_xyzt2
+
+   INTERFACE dim_reorder_2xyzt
+      MODULE PROCEDURE dim__reorder_2xyzt_i4   ! reorder integer(4) 1D table to ('x','y','z','t')
+      MODULE PROCEDURE dim__reorder_2xyzt_c    ! reorder string 1D table to ('x','y','z','t')
+      MODULE PROCEDURE dim__reorder_2xyzt_l    ! reorder logical 1D table to ('x','y','z','t')
+   END INTERFACE dim_reorder_2xyzt
+
+   INTERFACE dim_reorder_xyzt2
+      MODULE PROCEDURE dim__reorder_xyzt2_i4   ! reorder integer(4) 1D table from ('x','y','z','t')
+      MODULE PROCEDURE dim__reorder_xyzt2_c    ! reorder string 1D table from ('x','y','z','t')
+      MODULE PROCEDURE dim__reorder_xyzt2_l    ! reorder logical 1D table from ('x','y','z','t')  
+   END INTERFACE dim_reorder_xyzt2
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief This function returns dimension id, in a table of dimension structure,
+   !> given dimension name, or short name.
+   !> only dimension used are checked.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim   : dimension structure
+   !> @param[in] cd_name  : dimension name or short name
+   !> @param[in] cd_sname : dimension short name
+   !> @return dimension id
+   !-------------------------------------------------------------------
+   !> @code
+   INTEGER(i4) FUNCTION dim_get_id( td_dim, cd_name, cd_sname )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDIM),       DIMENSION(:), INTENT(IN) :: td_dim
+      CHARACTER(LEN=*),               INTENT(IN) :: cd_name
+      CHARACTER(LEN=*),               INTENT(IN), OPTIONAL :: cd_sname
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_name
+      CHARACTER(LEN=lc) :: cl_dim_name
+      CHARACTER(LEN=lc) :: cl_sname
+      CHARACTER(LEN=lc) :: cl_dim_sname
+
+      INTEGER(i4) :: il_ndim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+      ! init
+      dim_get_id=0
+
+      il_ndim=SIZE(td_dim(:))
+
+      ! look for dimension name
+      cl_name=fct_lower(cd_name)
+      ! check if dimension is in table of dimension structure and used
+      jj=0
+      DO ji=1,il_ndim
+         !IF( td_dim(ji)%l_use ) jj=jj+1
+
+         cl_dim_name=fct_lower(td_dim(ji)%c_name)
+         IF( TRIM(cl_dim_name) == TRIM(cl_name) .AND. &
+         &   td_dim(ji)%l_use )THEN
+            dim_get_id=ji !jj
+            CALL logger_debug("GET ID: variable name "//&
+            &  TRIM(ADJUSTL(cd_name))//" already in file " )
+            EXIT
+         ENDIF
+      ENDDO
+
+      ! look for dimension short name
+      IF(  dim_get_id == 0 )THEN
+
+         cl_sname=fct_lower(cd_name)
+         ! check if dimension is in table of dimension structure and used
+         jj=0
+         DO ji=1,il_ndim
+            IF( td_dim(ji)%l_use ) jj=jj+1
+            
+            cl_dim_sname=fct_lower(td_dim(ji)%c_sname)
+            IF( (TRIM(cl_dim_sname) == TRIM(cl_sname) ).AND.&
+            &   td_dim(ji)%l_use )THEN
+               CALL logger_debug("GET ID: variable short name "//&
+               &  TRIM(ADJUSTL(cd_name))//" already in file")
+               dim_get_id=jj
+               EXIT
+            ENDIF
+         ENDDO
+      ENDIF
+
+      ! look for dimension short name
+      IF( PRESENT(cd_sname) )THEN
+         IF(  dim_get_id == 0 )THEN
+
+            cl_sname=fct_lower(cd_sname)
+            ! check if dimension is in table of dimension structure and used
+            jj=0
+            DO ji=1,il_ndim
+               IF( td_dim(ji)%l_use ) jj=jj+1
+               
+               cl_dim_sname=fct_lower(td_dim(ji)%c_sname)
+               IF( (TRIM(cl_dim_sname) == TRIM(cl_sname) ).AND.&
+               &   td_dim(ji)%l_use )THEN
+                  CALL logger_debug("GET ID: variable short name "//&
+                  &  TRIM(ADJUSTL(cd_sname))//" already in file")
+                  dim_get_id=jj
+                  EXIT
+               ENDIF
+            ENDDO
+         ENDIF
+      ENDIF
+
+   END FUNCTION dim_get_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function returns dimension id, in a table of dimension structure,
+   !> given dimension name, or short name.
+   !> only dimension used are checked.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim   : dimension structure
+   !> @param[in] cd_name  : dimension name or short name
+   !> @param[in] cd_sname : dimension short name
+   !> @return dimension id
+   !-------------------------------------------------------------------
+   !> @code
+   INTEGER(i4) FUNCTION dim_get_void_id( td_dim, cd_name, cd_sname )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDIM),       DIMENSION(:), INTENT(IN) :: td_dim
+      CHARACTER(LEN=*),               INTENT(IN), OPTIONAL :: cd_name
+      CHARACTER(LEN=*),               INTENT(IN), OPTIONAL :: cd_sname
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_name
+      CHARACTER(LEN=lc) :: cl_dim_name
+      CHARACTER(LEN=lc) :: cl_sname
+      CHARACTER(LEN=lc) :: cl_dim_sname
+
+      INTEGER(i4) :: il_ndim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! init
+      dim_get_void_id=0
+
+      il_ndim=SIZE(td_dim(:))
+
+      ! look for dimension name
+      cl_name=fct_lower(cd_name)
+      ! check if dimension is in table of dimension structure and used
+      DO ji=1,il_ndim
+
+         cl_dim_name=fct_lower(td_dim(ji)%c_name)
+         IF( TRIM(cl_dim_name) == TRIM(cl_name) .AND. &
+         &   .NOT. td_dim(ji)%l_use )THEN
+            dim_get_void_id=ji
+            EXIT
+         ENDIF
+      ENDDO
+
+      ! look for dimension short name
+      IF(  dim_get_void_id == 0 )THEN
+
+         cl_sname=fct_lower(cd_name)
+         ! check if dimension is in table of dimension structure and used
+         DO ji=1,il_ndim
+            
+            cl_dim_sname=fct_lower(td_dim(ji)%c_sname)
+            IF( (TRIM(cl_dim_sname) == TRIM(cl_sname) ).AND.&
+            &   .NOT. td_dim(ji)%l_use )THEN
+               dim_get_void_id=ji
+               EXIT
+            ENDIF
+         ENDDO
+      ENDIF
+
+      ! look for dimension short name
+      IF( PRESENT(cd_sname) )THEN
+         IF(  dim_get_void_id == 0 )THEN
+
+            cl_sname=fct_lower(cd_sname)
+            ! check if dimension is in table of dimension structure and used
+            DO ji=1,il_ndim
+               
+               cl_dim_sname=fct_lower(td_dim(ji)%c_sname)
+               IF( (TRIM(cl_dim_sname) == TRIM(cl_sname) ).AND.&
+               &   .NOT. td_dim(ji)%l_use )THEN
+                  dim_get_void_id=ji
+                  EXIT
+               ENDIF
+            ENDDO
+         ENDIF
+      ENDIF
+
+      IF( dim_get_void_id == 0 )THEN
+         DO ji=1,il_ndim
+            IF( .NOT. td_dim(ji)%l_use ) dim_get_void_id=ji
+         ENDDO
+      ENDIF
+
+   END FUNCTION dim_get_void_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This routine initialise a dimension structure with given 
+   !> arguments (name, length, etc).<br/> 
+   !> define dimension is supposed to be used.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : dimension name
+   !> @param[in] id_len : dimension length
+   !> @param[in] ld_uld : dimension unlimited
+   !> @param[in] cd_sname : dimension short name
+   !> @return dimension structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TDIM) FUNCTION dim_init( cd_name, id_len, ld_uld, cd_sname)
+      IMPLICIT NONE
+
+      ! Argument 
+      CHARACTER(LEN=*), INTENT(IN)  :: cd_name
+      INTEGER(i4),      INTENT(IN), OPTIONAL :: id_len
+      LOGICAL,          INTENT(IN), OPTIONAL :: ld_uld
+      CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: cd_sname
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_name
+      CHARACTER(LEN=lc) :: cl_sname
+      !----------------------------------------------------------------
+
+      ! clean dimension
+      CALL dim_clean(dim_init)
+
+      cl_name=fct_upper(cd_name)
+
+      CALL logger_info( &
+      &  " DIM INIT: dimension name: "//TRIM(cl_name) )
+      dim_init%c_name=TRIM(ADJUSTL(cd_name))
+
+      IF( PRESENT(id_len) )THEN
+         CALL logger_info( &
+         &  " DIM INIT: dimension length: "//fct_str(id_len) )
+         dim_init%i_len=id_len
+      ENDIF
+
+      ! define dimension is supposed to be used
+      dim_init%l_use=.TRUE.
+
+      IF( PRESENT(cd_sname) )THEN
+
+         cl_sname=fct_lower(cd_sname)
+
+         IF( TRIM(cl_sname) == 'x' .OR. &
+         &   TRIM(cl_sname) == 'y' .OR. & 
+         &   TRIM(cl_sname) == 'z' .OR. & 
+         &   TRIM(cl_sname) == 't' )THEN
+            CALL logger_info( &
+            &  " DIM INIT: dimension short name: "//TRIM(cd_sname) )
+            dim_init%c_sname=TRIM(cd_sname)
+         ELSE
+            CALL logger_warn("DIM INIT: invalid short name."//&
+            " choose between ('x','y','z','t')")
+         ENDIF
+      ENDIF
+
+      IF( TRIM(fct_lower(dim_init%c_sname)) == 'u' )THEN
+
+         cl_name=fct_lower(cd_name)
+
+         IF( TRIM(cl_name) == 'x' )THEN
+            dim_init%c_sname='x'
+         ELSEIF( TRIM(cl_name) == 'y' )THEN
+            dim_init%c_sname='y'
+         ELSEIF( TRIM(cl_name)== 'z' .OR. &
+         &   INDEX(cl_name,'depth')/=0 )THEN
+            dim_init%c_sname='z'
+         ELSEIF( TRIM(cl_name)== 't' .OR. &
+         &   INDEX(cl_name,'time')/=0 )THEN
+            dim_init%c_sname='t'
+         ENDIF      
+
+      ENDIF
+
+      IF( PRESENT(ld_uld) )THEN
+         CALL logger_info( &
+         &  " DIM INIT: unlimited dimension: "//fct_str(ld_uld) )
+         dim_init%l_uld=ld_uld
+      ELSE
+         IF( TRIM(fct_lower(dim_init%c_sname)) =='t'  )THEN
+            dim_init%l_uld=.TRUE.
+         ENDIF
+      ENDIF
+      
+   END FUNCTION dim_init
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subrtoutine print dimension information 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim : table of dimension structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dim__print_tab(td_dim)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TDIM), DIMENSION(:), INTENT(IN) :: td_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      DO ji=1,SIZE(td_dim(:))
+         CALL dim_print(td_dim(ji))
+      ENDDO
+
+   END SUBROUTINE dim__print_tab
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subrtoutine print dimension information 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim : dimension structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dim__print_unit(td_dim)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TDIM), INTENT(IN) :: td_dim
+
+      !----------------------------------------------------------------
+
+      WRITE(*,'((3x,a,a),(/6x,a,a),(a,i1),(a,i4),2(a,a),2(a,i1))')   &
+      &        " dimension : ",TRIM(td_dim%c_name),               &
+      &        " short name : ",TRIM(td_dim%c_sname),        &
+      &        " id : ",td_dim%i_id,                         &
+      &        " len : ",td_dim%i_len,                       &
+      &        " use : ",TRIM(fct_str(td_dim%l_use)),        &
+      &        " uld : ",TRIM(fct_str(td_dim%l_uld)),        &
+      &        " xyzt2 : ",td_dim%i_xyzt2,                   &
+      &        " 2xyzt : ",td_dim%i_2xyzt
+
+   END SUBROUTINE dim__print_unit
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This subroutine check if dimension are ordered or not 
+   !
+   !> @author J.Paul
+   !> - 2013- Initial Version
+   !
+   !> @param[in] td_dim : table of dimension structure
+   !> @return dimension are ordered or not 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION dim_order(td_dim)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TDIM), DIMENSION(:), INTENT(IN) :: td_dim
+
+      ! function
+      LOGICAL :: dim_order
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_dimin
+
+      ! loop indices
+      !----------------------------------------------------------------
+      ! init
+      dim_order=.FALSE.
+
+      IF( SIZE(td_dim(:)) /= ip_maxdim )THEN
+         CALL logger_error("DIM ORDER: invalid dimension of table dimension.")
+      ELSE
+
+         cl_dimin=fct_concat(td_dim(:)%c_sname)
+
+         IF( TRIM(cp_dimorder) == TRIM(cl_dimin) )THEN
+            dim_order=.TRUE.
+         ENDIF
+
+      ENDIF
+   END FUNCTION dim_order
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This subroutine switch element of a table (4 elts) of dimension 
+   !> structure 
+   !> from unordered dimension to ordered dimension ('x','y','z','t')
+   !> Example: (/'z','x','t','y'/) => (/'x','y','z','t'/)
+   !> @warning this subroutine change dimension order 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_dim : table of dimension structure
+   !> @return dimension structure completed and reordered 
+   !>
+   !> @todo
+   !> -check input dimension order and stop if already ordered
+   !> - 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dim_reorder(td_dim)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TDIM), DIMENSION(:), INTENT(INOUT) :: td_dim
+
+      ! local variable
+      INTEGER(i4)                             :: il_id
+      CHARACTER(LEN=lc)                       :: cl_dimin
+      TYPE(TDIM)       , DIMENSION(ip_maxdim) :: tl_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_dim(:)) /= ip_maxdim )THEN
+         CALL logger_error("DIM ORDER: invalid dimension of table dimension.")
+      ELSE
+
+         ! copy and rename dimension in local variable
+         tl_dim(:)=td_dim(:)
+         jj=0
+         DO ji=1, ip_maxdim
+
+         CALL logger_debug( "DIM REORDER : jj "//TRIM(fct_str(jj))//&
+         &  " "//TRIM(fct_str(td_dim(ji)%l_use)))
+            IF( td_dim(ji)%l_use )THEN
+               jj=jj+1
+            !IF( td_dim(ji)%l_use .AND. td_dim(ji)%i_id == 0 )THEN
+               ! add id if dimension used and no id
+               CALL logger_debug( "DIM REORDER : add id "//TRIM(fct_str(jj))//&
+               &  " to dimension "//TRIM(td_dim(ji)%c_name) )
+               tl_dim(ji)%i_id=jj
+            ELSE
+               td_dim(ji)%i_id=0
+               td_dim(ji)%i_xyzt2=0
+               td_dim(ji)%c_sname='u'
+               td_dim(ji)%c_name=''
+               td_dim(ji)%l_uld=.FALSE.
+            ENDIF
+
+         ENDDO
+
+         print *,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
+         CALL dim_print(tl_dim(:))
+
+
+         ! fill unused dimension
+         CALL dim__fill_unused(tl_dim(:))
+         cl_dimin=fct_lower(fct_concat(tl_dim(:)%c_sname))
+
+         print *,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
+         CALL dim_print(tl_dim(:))
+         ! compute input id from output id (xyzt) 
+         DO ji = 1, ip_maxdim
+             
+            il_id=SCAN(TRIM(cp_dimorder),TRIM(cl_dimin(ji:ji)))
+            IF( il_id /= 0 )THEN
+               tl_dim(ji)%i_xyzt2=il_id
+            ENDIF
+            
+         ENDDO
+
+         ! compute output id (xyzt) from input id 
+         DO ji = 1, ip_maxdim
+             
+            il_id=SCAN(TRIM(cl_dimin),TRIM(cp_dimorder(ji:ji)))
+            IF( il_id /= 0 )THEN
+               tl_dim(ji)%i_2xyzt=il_id
+            ENDIF
+            
+         ENDDO
+
+         ! change dimension order to ('x','y','z','t')
+         td_dim(:)%c_name  = dim_reorder_2xyzt(tl_dim(:),tl_dim(:)%c_name)
+         td_dim(:)%c_sname = dim_reorder_2xyzt(tl_dim(:),tl_dim(:)%c_sname)
+         td_dim(:)%i_id    = dim_reorder_2xyzt(tl_dim(:),tl_dim(:)%i_id  )
+         td_dim(:)%i_len   = dim_reorder_2xyzt(tl_dim(:),tl_dim(:)%i_len )
+         td_dim(:)%l_uld   = dim_reorder_2xyzt(tl_dim(:),tl_dim(:)%l_uld )
+         td_dim(:)%l_use   = dim_reorder_2xyzt(tl_dim(:),tl_dim(:)%l_use )
+         td_dim(:)%i_2xyzt = tl_dim(:)%i_2xyzt
+         td_dim(:)%i_xyzt2 = tl_dim(:)%i_xyzt2
+
+      ENDIF
+
+   END SUBROUTINE dim_reorder
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This subroutine switch dimension table from ordered dimension ('x','y','z','t')
+   !> to unordered dimension.<br/>
+   !> Example: (/'x','y','z','t'/) => (/'z','x','t','y'/)<br/>
+   !> This is useful to add dimension in a variable or file
+   !
+   !> @warning this subroutine change dimension order 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_dim : table of dimension structure
+   !> @return dimension structure unordered 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dim_unorder(td_dim)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TDIM), DIMENSION(:), INTENT(INOUT) :: td_dim
+
+      ! local variable
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_dim(:)) /= ip_maxdim )THEN
+         CALL logger_error("DIM ORDER: invalid dimension of table dimension.")
+      ELSE      
+         ! add dummy xyzt2 id to removed dimension
+         jj=1
+         DO ji = 1, ip_maxdim
+            IF( .NOT. td_dim(ji)%l_use .AND. td_dim(ji)%i_xyzt2 == 0 )THEN
+               DO WHILE( ANY( td_dim(:)%i_xyzt2 == jj ))
+                  jj=jj+1
+               ENDDO
+               td_dim(ji)%i_xyzt2=jj
+            ENDIF
+         ENDDO
+
+         ! change dimension order from ('x','y','z','t')
+         td_dim(:)%c_name  = dim_reorder_xyzt2(td_dim,td_dim(:)%c_name)
+         td_dim(:)%c_sname = dim_reorder_xyzt2(td_dim,td_dim(:)%c_sname)
+         td_dim(:)%i_id    = dim_reorder_xyzt2(td_dim,td_dim(:)%i_id  )
+         td_dim(:)%i_len   = dim_reorder_xyzt2(td_dim,td_dim(:)%i_len )
+         td_dim(:)%l_uld   = dim_reorder_xyzt2(td_dim,td_dim(:)%l_uld )
+         td_dim(:)%l_use   = dim_reorder_xyzt2(td_dim,td_dim(:)%l_use )
+
+         ! remove dummy xyzt2 id from unused dimension
+         DO ji = 1, ip_maxdim
+            IF( .NOT. td_dim(ji)%l_use )THEN
+               td_dim(ji)%i_id=0
+               td_dim(ji)%i_xyzt2=0
+               td_dim(ji)%c_sname='u'
+               !td_dim(ji)%c_name='unknown'
+               !td_dim(ji)%c_sname=''
+               td_dim(ji)%c_name=''
+               td_dim(ji)%l_uld=.FALSE.
+            ENDIF
+         ENDDO
+      ENDIF
+
+   END SUBROUTINE dim_unorder
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine filled dimension structure with unused 
+   !> dimension in order that all dimensions 'x','y','z' and 't' be
+   !> informed, even if void 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_dim : table of dimension structure
+   !> @return td_dim with unused dimension
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dim__fill_unused(td_dim)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TDIM), DIMENSION(:), INTENT(INOUT) :: td_dim
+
+      ! local variable
+      CHARACTER(LEN=lc)               :: cl_dimin
+      INTEGER(i4)      , DIMENSION(1) :: il_ind  ! index
+      
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_dim(:)) /= ip_maxdim )THEN
+         CALL logger_error("DIM ORDER: invalid dimension of table dimension.")
+      ELSE      
+         ! concatenate dimension used in a character string
+         cl_dimin=fct_lower(fct_concat(td_dim(:)%c_sname))
+         DO ji = 1, ip_maxdim
+
+            ! search missing dimension
+            IF( INDEX(cl_dimin,TRIM(fct_lower(cp_dimorder(ji:ji)))) == 0 )THEN
+               ! search first empty dimension
+               il_ind(:)=MINLOC( td_dim(:)%i_id, td_dim(:)%i_id == 0 )
+
+               ! put missing dimension instead of empty one
+               td_dim(il_ind(1))%c_sname=fct_lower(cp_dimorder(ji:ji))
+               ! update output structure
+               td_dim(il_ind(1))%c_name=fct_lower(cp_dimorder(ji:ji))
+               td_dim(il_ind(1))%i_id=il_ind(1)
+               td_dim(il_ind(1))%i_len=1
+               td_dim(il_ind(1))%l_use=.FALSE.
+
+            ENDIF
+
+         ENDDO
+
+         ! remove id of unused dimension
+         DO ji = 1, ip_maxdim
+            IF( .NOT. td_dim(ji)%l_use ) td_dim(ji)%i_id=0
+         ENDDO
+      ENDIF
+
+   END SUBROUTINE dim__fill_unused
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine reshape real(8) 4D table   
+   !> to an ordered table with dimension (/'x','y','z','t'/).<br/>
+   !> Example: (/'z','x','t','y'/) => (/'x','y','z','t'/)
+   !
+   !> @note you must have run dim_reorder before use this subroutine
+   !
+   !> @warning output table dimension differ from input table dimension
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim : table of dimension structure
+   !> @param[in] dd_value : table of value to reshape
+   !> @return table of value reshaped 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION dim__reshape_2xyzt_dp(td_dim, dd_value)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TDIM), DIMENSION(:)      , INTENT(IN) :: td_dim
+      REAL(dp)  , DIMENSION(:,:,:,:), INTENT(IN) :: dd_value
+      
+      ! function
+      REAL(dp), DIMENSION(td_dim(1)%i_len, &
+      &                   td_dim(2)%i_len, &
+      &                   td_dim(3)%i_len, &
+      &                   td_dim(4)%i_len) :: dim__reshape_2xyzt_dp
+
+      ! local variable
+      INTEGER(i4)      , DIMENSION(ip_maxdim) :: il_shape
+      CHARACTER(LEN=lc)                       :: cl_dim
+      
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_dim(:)) /= ip_maxdim )THEN
+         CALL logger_error("DIM ORDER: invalid dimension of table dimension.")
+      ELSE      
+
+         IF( ANY(td_dim(:)%i_2xyzt==0) .OR. ANY(td_dim(:)%i_xyzt2==0) )THEN
+
+            CALL logger_fatal( &
+            &  "  RESHAPE to XYZT: you should have run dim_reorder &
+            &     before running RESHAPE" )
+
+         ENDIF
+
+         il_shape=SHAPE(dd_value)
+         ! check input dimension
+         IF( ANY(il_shape(:) /= (/ td_dim(td_dim(1)%i_xyzt2)%i_len, &
+                               &   td_dim(td_dim(2)%i_xyzt2)%i_len, &
+                               &   td_dim(td_dim(3)%i_xyzt2)%i_len, &
+                               &   td_dim(td_dim(4)%i_xyzt2)%i_len /)) )THEN
+
+            DO ji=1,ip_maxdim
+               CALL logger_debug(" RESHAPE to XYZT: dim "//&
+               &     TRIM(td_dim(td_dim(ji)%i_xyzt2)%c_name)//" "//&
+               &     TRIM(fct_str(td_dim(td_dim(ji)%i_xyzt2)%i_len))//" vs "//&
+               &     TRIM(fct_str(il_shape(ji))) )
+            ENDDO
+            CALL logger_fatal(" RESHAPE to XYZT: wrong input dimensions " )
+
+         ELSE
+
+            ! write some informations
+            cl_dim="(/"
+            DO ji=1,ip_maxdim-1
+               cl_dim=TRIM(cl_dim)//TRIM(fct_str(il_shape(ji)))//','
+            ENDDO
+            cl_dim=TRIM(cl_dim)//TRIM(fct_str(il_shape(ip_maxdim)))//"/)"
+
+            CALL logger_info(" RESHAPE to XYZT: input dimensions are "//&
+            &  TRIM(cl_dim) )
+
+            cl_dim="(/"
+            DO ji=1,ip_maxdim-1
+               cl_dim=TRIM(cl_dim)//TRIM(fct_str(td_dim(ji)%i_len))//','
+            ENDDO
+            cl_dim=TRIM(cl_dim)//TRIM(fct_str(td_dim(ip_maxdim)%i_len))//"/)"
+
+            CALL logger_info(" RESHAPE to XYZT: ouput dimensions should be "//&
+            &  TRIM(cl_dim) )
+
+               ! reorder dimension to x,y,z,t
+               dim__reshape_2xyzt_dp(:,:,:,:)=RESHAPE(SOURCE=dd_value(:,:,:,:),&
+               &                 SHAPE = (/ td_dim(1)%i_len,   &
+               &                            td_dim(2)%i_len,   &
+               &                            td_dim(3)%i_len,   &
+               &                            td_dim(4)%i_len /),&
+               &                 ORDER = (/ td_dim(1)%i_2xyzt,          &
+               &                            td_dim(2)%i_2xyzt,          &
+               &                            td_dim(3)%i_2xyzt,          &
+               &                            td_dim(4)%i_2xyzt        /))      
+
+         ENDIF
+      ENDIF
+
+   END FUNCTION dim__reshape_2xyzt_dp
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine reshape ordered real(8) 4D table with dimension 
+   !> (/'x','y','z','t'/) to a table ordered as file variable.<br/>
+   !> Example: (/'x','y','z','t'/) => (/'z','x','t','y'/)
+   !
+   !> @note you must have run dim_reorder before use this subroutine
+   !
+   !> @warning output table dimension differ from input table dimension
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim : table of dimension structure
+   !> @param[in] dd_value : table of value to reshape
+   !> @return table of value reshaped 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION dim__reshape_xyzt2_dp(td_dim, dd_value)
+      IMPLICIT NONE
+      
+      ! Argument      
+      TYPE(TDIM), DIMENSION(:)      , INTENT(IN) :: td_dim
+      REAL(dp),   DIMENSION(:,:,:,:), INTENT(IN) :: dd_value
+      
+      ! function
+      REAL(dp), DIMENSION(td_dim(td_dim(1)%i_xyzt2)%i_len, &
+      &                   td_dim(td_dim(2)%i_xyzt2)%i_len, &
+      &                   td_dim(td_dim(3)%i_xyzt2)%i_len, &
+      &                   td_dim(td_dim(4)%i_xyzt2)%i_len) :: dim__reshape_xyzt2_dp
+
+      ! local variable
+      INTEGER(i4),      DIMENSION(ip_maxdim) :: il_shape
+      CHARACTER(LEN=lc)                      :: cl_dim
+      
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_dim(:)) /= ip_maxdim )THEN
+         CALL logger_error("DIM ORDER: invalid dimension of table dimension.")
+      ELSE
+
+         IF( ANY(td_dim(:)%i_xyzt2==0) .OR. ANY(td_dim(:)%i_2xyzt==0) )THEN
+
+            CALL logger_fatal( &
+            &  "  RESHAPE from XYZT: you should have run dim_reorder &
+            &     before running RESHAPE" )
+
+         ENDIF        
+
+         ! check input dimension
+         il_shape=SHAPE(dd_value)
+         IF( ANY(il_shape(:)/=td_dim(:)%i_len))THEN
+
+            DO ji=1,ip_maxdim
+               CALL logger_debug(" RESHAPE from XYZT: dim "//&
+               &              TRIM(td_dim(ji)%c_name)//" "//&
+               &              TRIM(fct_str(td_dim(ji)%i_len))//" vs "//&
+               &              TRIM(fct_str(il_shape(ji))) )
+            ENDDO
+            CALL logger_fatal( "RESHAPE from XYZT: wrong input dimensions ")
+
+         ELSE      
+
+            ! write some informations
+            cl_dim="(/"
+            DO ji=1,ip_maxdim-1
+               cl_dim=TRIM(cl_dim)//TRIM(fct_str(il_shape(ji)))//','
+            ENDDO
+            cl_dim=TRIM(cl_dim)//TRIM(fct_str(il_shape(ip_maxdim)))//"/)"
+
+            CALL logger_info(" RESHAPE from XYZT: input dimensions are "//&
+            &  TRIM(cl_dim) )
+
+            cl_dim="(/"
+            DO ji=1,ip_maxdim-1
+               cl_dim=TRIM(cl_dim)//&
+               &      TRIM(fct_str(td_dim(td_dim(ji)%i_xyzt2)%i_len))//','
+            ENDDO
+            cl_dim=TRIM(cl_dim)//&
+            &      TRIM(fct_str(td_dim(td_dim(ip_maxdim)%i_xyzt2)%i_len))//"/)"
+
+            CALL logger_info(" RESHAPE from XYZT: ouput dimensions should be "//&
+            &  TRIM(cl_dim) )
+
+            ! reshape table
+            dim__reshape_xyzt2_dp(:,:,:,:)=RESHAPE(SOURCE=dd_value,  &
+            &           SHAPE = (/ td_dim(td_dim(1)%i_xyzt2)%i_len,   &
+            &                      td_dim(td_dim(2)%i_xyzt2)%i_len,   &
+            &                      td_dim(td_dim(3)%i_xyzt2)%i_len,   &
+            &                      td_dim(td_dim(4)%i_xyzt2)%i_len /),&
+            &           ORDER = (/        td_dim(1)%i_xyzt2,          &
+            &                             td_dim(2)%i_xyzt2,          &
+            &                             td_dim(3)%i_xyzt2,          &
+            &                             td_dim(4)%i_xyzt2        /))
+
+
+         ENDIF      
+      ENDIF      
+
+   END FUNCTION dim__reshape_xyzt2_dp
+   !> @endcode    
+   !-------------------------------------------------------------------
+   !> @brief  This subroutine reordered integer(4) 1D table to be suitable 
+   !> with dimension ordered as (/'x','y','z','t'/)
+   !> @note you must have run dim_reorder before use this subroutine
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim : table of dimension structure
+   !> @param[in] id_tab : table of value to reshape
+   !> @return table of value reshaped 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION dim__reorder_2xyzt_i4(td_dim, id_tab)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TDIM) , DIMENSION(:), INTENT(IN) :: td_dim
+      INTEGER(i4), DIMENSION(:), INTENT(IN) :: id_tab
+      
+      ! function
+      INTEGER(i4), DIMENSION(ip_maxdim) :: dim__reorder_2xyzt_i4
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_dim(:)) /= ip_maxdim .OR. &
+      &   SIZE(id_tab(:)) /= ip_maxdim )THEN
+         CALL logger_error("DIM ORDER: invalid dimension of table dimension"//&
+         &              " or of table of value.")
+      ELSE      
+         IF( ANY(td_dim(:)%i_2xyzt==0) )THEN
+
+            CALL logger_error( &
+            &  "  REORDER to XYZT: you should have run dim_reorder &
+            &     before running REORDER" )
+
+         ENDIF        
+
+         DO ji=1,ip_maxdim
+            dim__reorder_2xyzt_i4(ji)=id_tab(td_dim(ji)%i_2xyzt)
+         ENDDO
+      ENDIF
+
+   END FUNCTION dim__reorder_2xyzt_i4
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine reordered integer(4) 1D table to be suitable with
+   !> dimension read in the file.
+   !> @note you must have run dim_reorder before use this subroutine
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim : table of dimension structure
+   !> @param[in] id_tab : table of value to reshape
+   !> @return table of value reshaped 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION dim__reorder_xyzt2_i4(td_dim, id_tab)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TDIM) , DIMENSION(:), INTENT(IN) :: td_dim
+      INTEGER(i4), DIMENSION(:), INTENT(IN) :: id_tab
+      
+      ! function
+      INTEGER(i4), DIMENSION(ip_maxdim) :: dim__reorder_xyzt2_i4
+      
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_dim(:)) /= ip_maxdim .OR. &
+      &   SIZE(id_tab(:)) /= ip_maxdim )THEN
+         CALL logger_error("DIM ORDER: invalid dimension of table dimension"//&
+         &              " or of table of value.")
+      ELSE      
+         IF( ANY(td_dim(:)%i_xyzt2==0) )THEN
+
+            CALL logger_error( &
+            &  "  REORDER from XYZT: you should have run dim_reorder &
+            &     before running REORDER" )
+
+         ENDIF        
+
+         DO ji=1,ip_maxdim
+            dim__reorder_xyzt2_i4(ji)=id_tab(td_dim(ji)%i_xyzt2)
+         ENDDO
+      ENDIF
+
+   END FUNCTION dim__reorder_xyzt2_i4
+   !> @endcode    
+   !-------------------------------------------------------------------
+   !> @brief  This subroutine reordered logical 1D table to be suitable 
+   !> with dimension ordered as (/'x','y','z','t'/)
+   !> @note you must have run dim_reorder before use this subroutine
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim : table of dimension structure
+   !> @param[in] ld_tab : table of value to reordered
+   !> @return table of value reordered 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION dim__reorder_2xyzt_l(td_dim, ld_tab)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TDIM) , DIMENSION(:), INTENT(IN) :: td_dim
+      LOGICAL    , DIMENSION(:), INTENT(IN) :: ld_tab
+      
+      ! function
+      LOGICAL, DIMENSION(ip_maxdim) :: dim__reorder_2xyzt_l
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_dim(:)) /= ip_maxdim .OR. &
+      &   SIZE(ld_tab(:)) /= ip_maxdim )THEN
+         CALL logger_error("DIM ORDER: invalid dimension of table dimension"//&
+         &              " or of table of value.")
+      ELSE      
+         IF( ANY(td_dim(:)%i_2xyzt==0) )THEN
+
+            CALL logger_error( &
+            &  "  REORDER to XYZT: you should have run dim_reorder &
+            &     before running REORDER" )
+
+         ENDIF        
+
+         DO ji=1,ip_maxdim
+            dim__reorder_2xyzt_l(ji)=ld_tab(td_dim(ji)%i_2xyzt)
+         ENDDO
+      ENDIF
+
+   END FUNCTION dim__reorder_2xyzt_l
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine reordered logical 1D table to be suitable with
+   !> dimension read in the file.
+   !> @note you must have run dim_reorder before use this subroutine
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim : table of dimension structure
+   !> @param[in] ld_tab : table of value to reordered
+   !> @return table of value reordered 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION dim__reorder_xyzt2_l(td_dim, ld_tab)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TDIM) , DIMENSION(:), INTENT(IN) :: td_dim
+      LOGICAL    , DIMENSION(:), INTENT(IN) :: ld_tab
+      
+      ! function
+      LOGICAL, DIMENSION(ip_maxdim) :: dim__reorder_xyzt2_l
+      
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_dim(:)) /= ip_maxdim .OR. &
+      &   SIZE(ld_tab(:)) /= ip_maxdim )THEN
+         CALL logger_error("DIM ORDER: invalid dimension of table dimension"//&
+         &              " or of table of value.")
+      ELSE
+         IF( ANY(td_dim(:)%i_xyzt2==0) )THEN
+
+            CALL logger_error( &
+            &  "  REORDER from XYZT: you should have run dim_reorder &
+            &     before running REORDER" )
+
+         ENDIF        
+
+         DO ji=1,ip_maxdim
+            dim__reorder_xyzt2_l(ji)=ld_tab(td_dim(ji)%i_xyzt2)
+         ENDDO
+      ENDIF
+
+   END FUNCTION dim__reorder_xyzt2_l
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief  This subroutine reordered string 1D table to be suitable 
+   !> with dimension ordered as (/'x','y','z','t'/)
+   !> @note you must have run dim_reorder before use this subroutine
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim : table of dimension structure
+   !> @param[in] cd_tab : table of value to reordered
+   !> @return table of value reordered 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION dim__reorder_2xyzt_c(td_dim, cd_tab)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TDIM),       DIMENSION(:), INTENT(IN) :: td_dim
+      CHARACTER(LEN=*), DIMENSION(:), INTENT(IN) :: cd_tab
+      
+      ! function
+      CHARACTER(LEN=lc), DIMENSION(ip_maxdim) :: dim__reorder_2xyzt_c
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_dim(:)) /= ip_maxdim .OR. &
+      &   SIZE(cd_tab(:)) /= ip_maxdim )THEN
+         CALL logger_error("DIM ORDER: invalid dimension of table dimension"//&
+         &              " or of table of value.")
+      ELSE      
+         IF( ANY(td_dim(:)%i_2xyzt==0) )THEN
+
+            CALL logger_error( &
+            &  "  REORDER to XYZT: you should have run dim_reorder"//&
+            &  " before running REORDER" )
+
+         ENDIF        
+
+         DO ji=1,ip_maxdim
+            dim__reorder_2xyzt_c(ji)=TRIM(cd_tab(td_dim(ji)%i_2xyzt))
+         ENDDO
+      ENDIF
+
+   END FUNCTION dim__reorder_2xyzt_c
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine reordered string 1D table to be suitable with
+   !> dimension read in the file.
+   !> @note you must have run dim_reorder before use this subroutine
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim : table of dimension structure
+   !> @param[in] cd_tab : table of value to reordered
+   !> @return table of value reordered 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION dim__reorder_xyzt2_c(td_dim, cd_tab)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TDIM),       DIMENSION(:), INTENT(IN) :: td_dim
+      CHARACTER(LEN=*), DIMENSION(:), INTENT(IN) :: cd_tab
+      
+      ! function
+      CHARACTER(LEN=lc), DIMENSION(ip_maxdim) :: dim__reorder_xyzt2_c
+      
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_dim(:)) /= ip_maxdim .OR. &
+      &   SIZE(cd_tab(:)) /= ip_maxdim )THEN
+         CALL logger_error("DIM ORDER: invalid dimension of table dimension"//&
+         &              " or of table of value.")
+      ELSE
+         IF( ANY(td_dim(:)%i_xyzt2==0) )THEN
+            CALL logger_error( &
+            &  "  REORDER from XYZT: you should have run dim_reorder &
+            &     before running REORDER" )
+
+         ENDIF        
+
+         DO ji=1,ip_maxdim
+            dim__reorder_xyzt2_c(ji)=TRIM(cd_tab(td_dim(ji)%i_xyzt2))
+         ENDDO
+      ENDIF
+
+   END FUNCTION dim__reorder_xyzt2_c
+   !> @endcode    
+   !-------------------------------------------------------------------
+   !> @brief This subroutine clean dimension structure
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim : dimension strucutre
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dim__clean_unit( td_dim )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDIM), INTENT(INOUT) :: td_dim
+
+      ! local variable
+      TYPE(TDIM) :: tl_dim ! empty dimension strucutre
+      !----------------------------------------------------------------
+
+      CALL logger_info( &
+      &  " CLEAN: reset dimension "//TRIM(td_dim%c_name) )
+
+      ! replace by empty structure
+      td_dim=tl_dim
+
+   END SUBROUTINE dim__clean_unit
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine clean table of dimension structure
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_dim : table of dimension strucutre
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dim__clean_tab( td_dim )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDIM), DIMENSION(:), INTENT(INOUT) :: td_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      DO ji=1,SIZE(td_dim(:))
+         CALL dim_clean(td_dim(ji))
+      ENDDO
+
+   END SUBROUTINE dim__clean_tab
+   !> @endcode
+END MODULE dim
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/domain.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/domain.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/domain.f90	(revision 4245)
@@ -0,0 +1,1514 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: dom
+!
+! DESCRIPTION:
+!> @brief
+!> This module manage domain computation.
+!
+!> @details
+!>
+!>
+!>
+!>
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!> @todo
+!> - check use of id_pivot
+!> 
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!----------------------------------------------------------------------
+MODULE dom
+   USE kind                            ! F90 kind parameter
+   USE global                          ! global parameter
+   USE fct                             ! basic useful function
+   USE logger                             ! log file manager
+   USE dim                             ! dimension manager
+   USE var                             ! variable manager
+   USE file                            ! file manager
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+   PUBLIC :: TDOM     !< domain structure
+
+   ! function and subroutine
+   PUBLIc :: dom_clean     !< clean domain structure
+   PUBLIC :: dom_init      !< initialise domain structure
+   PUBLIC :: dom_print     !< print information about domain
+   PUBLIC :: dom_get_ew_overlap !< get east west overlap
+   PUBLIC :: dom_add_extra   !< add useful extra point to coarse grid for interpolation
+   PUBLIC :: dom_clean_extra  !< reset domain without extra point
+   PUBLIC :: dom_del_extra   !< remove extra point from fine grid after interpolation
+    
+   PRIVATE :: dom__define    !< define extract domain indices
+                                            !< define extract domain indices for input domain with
+   PRIVATE :: dom__define_cyclic_north_fold !< - cyclic east-west boundary and north fold boundary condition.
+   PRIVATE :: dom__define_north_fold        !< - north fold boundary condition.
+   PRIVATE :: dom__define_symmetric         !< - symmetric boundary condition across the equator.
+   PRIVATE :: dom__define_cyclic            !< - cyclic east-west boundary.
+   PRIVATE :: dom__define_closed            !< - cyclic east-west boundary.
+   PRIVATE :: dom__check_EW_index           !< check East-West indices
+                                            !< compute size of an extract domain
+   PRIVATE :: dom__size_no_pole             !< - without north fold condition
+   PRIVATE :: dom__size_no_pole_overlap     !< - without north fold condition, and which overlap east-west boundary
+   PRIVATE :: dom__size_no_pole_no_overlap  !< - without north fold condition, and which do not overlap east-west boundary
+   PRIVATE :: dom__size_pole                !< - with north fold condition
+   PRIVATE :: dom__size_pole_overlap        !< - with north fold condition, and which overlap east-west boundary
+   PRIVATE :: dom__size_pole_no_overlap     !< - with north fold condition, and which do not overlap east-west boundary
+
+   !> @struct
+   TYPE TDOM
+      TYPE(TDIM), DIMENSION(ip_maxdim)  :: t_dim0           !< global domain dimension
+      TYPE(TDIM), DIMENSION(ip_maxdim)  :: t_dim              !< sub domain dimension
+      INTEGER(i4) :: i_perio0   !< NEMO periodicity index
+      INTEGER(i4) :: i_ew0      !< East-West overlap
+      INTEGER(i4) :: i_perio    !< NEMO periodicity index
+      INTEGER(i4) :: i_pivot    !< NEMO pivot point index F(0),T(1)
+      INTEGER(i4) :: i_imin = 1 !< i-direction sub-domain lower left  point indice
+      INTEGER(i4) :: i_imax = 1 !< i-direction sub-domain upper right point indice
+      INTEGER(i4) :: i_jmin = 1 !< j-direction sub-domain lower left  point indice
+      INTEGER(i4) :: i_jmax = 1 !< j-direction sub-domain upper right point indice
+      INTEGER(i4) :: i_kmin = 1 !< k-direction sub-domain lower level indice
+      INTEGER(i4) :: i_kmax = 1 !< k-direction sub-domain upper level indice
+      INTEGER(i4) :: i_lmin = 1 !< l-direction sub-domain lower time indice
+      INTEGER(i4) :: i_lmax = 1 !< l-direction sub-domain upper time indice
+
+      INTEGER(i4) :: i_ighost = 0 !< i-direction ghost cell factor
+      INTEGER(i4) :: i_jghost = 0 !< j-direction ghost cell factor
+
+      INTEGER(i4), DIMENSION(2) :: i_iextra = 0 !< i-direction extra point
+      INTEGER(i4), DIMENSION(2) :: i_jextra = 0 !< j-direction extra point
+
+   END TYPE TDOM
+
+   INTEGER(i4), PARAMETER :: im_minext  = 2  !< default minumum number of extraband
+
+   INTERFACE dom_init
+      MODULE PROCEDURE dom_init_file
+!      MODULE PROCEDURE dom_init_mpp
+   END INTERFACE dom_init
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief This subroutine print some information about domain strucutre.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_dom : dom structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom_print(td_dom)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TDOM), INTENT(IN) :: td_dom
+
+      ! local argument
+      CHARACTER(LEN=lc) :: cl_pivot
+      !----------------------------------------------------------------
+      SELECT CASE(td_dom%i_pivot)
+         CASE(0)
+            cl_pivot='F-point'
+         CASE(1)
+            cl_pivot='T-point'
+         CASE DEFAULT
+            cl_pivot='unknown'
+      END SELECT
+
+      WRITE(*,'((a,4(i0,1x)),(/a,i2,a,a),(/a,4(i0,1x)),(/a,i2/),10(/a,i0))') &
+      &  " global domain size ",td_dom%t_dim0(:)%i_len, &
+      &  " domain periodicity ",td_dom%i_perio0,", pivot: ",TRIM(cl_pivot),   &
+      &  " sub-domain size : ",td_dom%t_dim(:)%i_len,                         &
+      &  " sub domain periodicity ",td_dom%i_perio,                           &
+      &  " i-direction sub-domain lower left  point indice ",td_dom%i_imin,   &
+      &  " i-direction sub-domain upper right point indice ",td_dom%i_imax,   &
+      &  " j-direction sub-domain lower left  point indice ",td_dom%i_jmin,   &
+      &  " j-direction sub-domain upper right point indice ",td_dom%i_jmax,   &
+!      &  " k-direction sub-domain lower level indice       ",td_dom%i_kmin,   &
+!      &  " k-direction sub-domain upper level indice       ",td_dom%i_kmax,   &
+!      &  " l-direction sub-domain lower time indice        ",td_dom%i_lmin,   &
+!      &  " l-direction sub-domain upper time indice        ",td_dom%i_lmax,   &
+      &  " i-direction ghost cell factor                   ",td_dom%i_ighost, &
+      &  " j-direction ghost cell factor                   ",td_dom%i_jghost
+
+      END SUBROUTINE dom_print
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This function intialise domain structure, given open file structure,
+   !> and grid periodicity. 
+   !
+   !> @author J.Paul
+   !> - June, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_perio : grid periodicity
+   !> @param[in] id_imin : i-direction sub-domain lower left  point indice
+   !> @param[in] id_imax : i-direction sub-domain upper right point indice
+   !> @param[in] id_jmin : j-direction sub-domain lower left  point indice
+   !> @param[in] id_jmax : j-direction sub-domain upper right point indice
+   !> @param[in] id_kmin : k-direction sub-domain lower level indice
+   !> @param[in] id_kmax : k-direction sub-domain upper level indice
+   !> @param[in] id_lmin : l-direction sub-domain lower time indice
+   !> @param[in] id_lmax : l-direction sub-domain upper time indice
+   !> @return domain structure
+   !>
+   !> @todo
+   !> - initialiser domain
+   !> - add info new perio.. dans sortie
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TDOM) FUNCTION dom_init_file( td_file, &
+   &                                  id_imin, id_imax, id_jmin, id_jmax )
+!   &                                  id_kmin, id_kmax, id_lmin, id_lmax )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE), INTENT(IN) :: td_file 
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_imin
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_imax
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_jmin
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_jmax
+!      INTEGER(i4), INTENT(IN), OPTIONAL :: id_kmin
+!      INTEGER(i4), INTENT(IN), OPTIONAL :: id_kmax
+!      INTEGER(i4), INTENT(IN), OPTIONAL :: id_lmin
+!      INTEGER(i4), INTENT(IN), OPTIONAL :: id_lmax
+
+      !local variable
+      !----------------------------------------------------------------
+
+      ! clean domain structure
+      CALL dom_clean(dom_init_file)
+
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " DOM INIT: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+         ! global domain define by file
+
+         ! use global dimension define by file
+         dom_init_file%t_dim0(:) = td_file%t_dim(:)
+
+         IF( td_file%i_perio < 0 .OR. td_file%i_perio > 6 )THEN
+            CALL logger_error("DOM INIT: invalid grid periodicity. "//&
+            &  "you should use dom_get_perio to compute it")
+         ELSE
+            dom_init_file%i_perio0=td_file%i_perio
+         ENDIF
+
+         ! global domain pivot point
+         SELECT CASE(dom_init_file%i_perio0)
+            CASE(3,4)
+               dom_init_file%i_pivot = 0
+            CASE(5,6)
+               dom_init_file%i_pivot = 1
+            CASE DEFAULT
+               dom_init_file%i_pivot = 0
+         END SELECT
+
+         ! look for EW overlap
+         dom_init_file%i_ew0=td_file%i_ew
+
+         ! initialise domain as global
+         dom_init_file%i_imin = 1 
+         dom_init_file%i_imax = dom_init_file%t_dim0(1)%i_len
+
+         dom_init_file%i_jmin = 1 
+         dom_init_file%i_jmax = dom_init_file%t_dim0(2)%i_len
+
+!         dom_init_file%i_kmin = 1 
+!         dom_init_file%i_kmax = dom_init_file%t_dim(3)%i_len
+!
+!         dom_init_file%i_lmin = 1 
+!         dom_init_file%i_lmax = dom_init_file%t_dim(4)%i_len
+
+         ! extract domain dimension
+         dom_init_file%t_dim(:) = td_file%t_dim(:)
+
+         ! define extract domain indices 
+         CALL dom__define( dom_init_file, &
+   &                       id_imin, id_imax, id_jmin, id_jmax )
+!   &                       id_kmin, id_kmax, id_lmin, id_lmax )
+
+      ENDIF
+
+   END FUNCTION dom_init_file
+   !> @endcode
+ !  !-------------------------------------------------------------------
+ !  !> @brief 
+ !  !> This function intialise domain structure, given mpp structure,
+ !  !> and variable name. domain indices could be specify.
+ !  !
+ !  !> @details
+ !  !> 
+ !  !
+ !  !> @author J.Paul
+ !  !> - Nov, 2013- Initial Version
+ !  !
+ !  !> @param[in] td_mpp : mpp structure
+ !  !> @param[in] cd_varname : variable name
+ !  !> @return domain structure
+ !  !>
+ !  !> @todo
+ !  !> - initialiser domain
+ !  !-------------------------------------------------------------------
+ !  !> @code
+ !  TYPE(TDOM) FUNCTION dom_init_mpp( td_mpp, cd_varname )
+ !     IMPLICIT NONE
+ !     ! Argument      
+ !     TYPE(TMPP),       INTENT(IN) :: td_mpp 
+ !     CHARACTER(LEN=*), INTENT(IN) :: cd_varname
+ !     !----------------------------------------------------------------
+
+ !     ! clean domain structure
+ !     CALL dom_clean(dom_init_mpp)
+
+ !     IF( ASSOCIATED(td_mpp%t_proc) )THEN
+
+ !        CALL logger_error( " INIT: mpp strcuture "//TRIM(td_mpp%c_name)//&
+ !        &               " not define" )
+
+ !     ELSE
+ !        ! global domain define by mpp
+
+ !        ! use global dimension define by mpp
+ !        dom_init_mpp%t_dim(:) = td_mpp%t_dim(:)
+
+ !        ! get global domain periodicity ??
+ !        dom_init_mpp%i_perio =  dom_get_perio(td_mpp, cd_varname)
+
+ !        ! global domain pivot point
+ !        SELECT CASE(dom_init%i_perio)
+ !           CASE(3,4)
+ !              dom_init%i_pivot = 0
+ !           CASE(5,6)
+ !              dom_init%i_pivot = 1
+ !           CASE DEFAULT
+ !              dom_init%i_pivot = 0
+ !        END SELECT
+
+ !        ! initialise domain as global
+ !        dom_init_mpp%i_imin = 1 
+ !        dom_init_mpp%i_imax = dom_init_mpp%t_dim(1)%i_len
+
+ !        dom_init_mpp%i_jmin = 1 
+ !        dom_init_mpp%i_jmax = dom_init_mpp%t_dim(2)%i_len
+
+ !        dom_init_mpp%i_kmin = 1 
+ !        dom_init_mpp%i_kmax = dom_init_mpp%t_dim(3)%i_len
+
+ !        dom_init_mpp%i_lmin = 1 
+ !        dom_init_mpp%i_lmax = dom_init_mpp%t_dim(4)%i_len
+
+ !     ENDIF
+
+ !  END FUNCTION dom_init_mpp
+ !  !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This subroutine define extract domain indices, and compute the size 
+   !> of the domain.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain structure
+   !> @param[in] id_imin : i-direction sub-domain lower left  point indice
+   !> @param[in] id_imax : i-direction sub-domain upper right point indice
+   !> @param[in] id_jmin : j-direction sub-domain lower left  point indice
+   !> @param[in] id_jmax : j-direction sub-domain upper right point indice
+   !> @param[in] id_kmin : k-direction sub-domain lower level indice
+   !> @param[in] id_kmax : k-direction sub-domain upper level indice
+   !> @param[in] id_lmin : l-direction sub-domain lower time indice
+   !> @param[in] id_lmax : l-direction sub-domain upper time indice
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__define(td_dom, &
+   &                      id_imin, id_imax, id_jmin, id_jmax )
+!   &                      id_kmin, id_kmax, id_lmin, id_lmax )
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TDOM),  INTENT(INOUT) :: td_dom
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_imin
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_imax
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_jmin
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_jmax
+!      INTEGER(i4), INTENT(IN), OPTIONAL :: id_kmin
+!      INTEGER(i4), INTENT(IN), OPTIONAL :: id_kmax
+!      INTEGER(i4), INTENT(IN), OPTIONAL :: id_lmin
+!      INTEGER(i4), INTENT(IN), OPTIONAL :: id_lmax
+      !----------------------------------------------------------------
+
+      IF( PRESENT(id_imin) ) td_dom%i_imin = id_imin
+      IF( PRESENT(id_imax) ) td_dom%i_imax = id_imax
+
+      IF( PRESENT(id_jmin) ) td_dom%i_jmin = id_jmin
+      IF( PRESENT(id_jmax) ) td_dom%i_jmax = id_jmax
+
+!      IF( PRESENT(id_kmin) ) td_dom%i_kmin = id_kmin
+!      IF( PRESENT(id_kmax) ) td_dom%i_kmax = id_kmax
+!
+!      IF( PRESENT(id_lmin) ) td_dom%i_lmin = id_lmin
+!      IF( PRESENT(id_lmax) ) td_dom%i_lmax = id_lmax
+
+      ! check indices
+      IF(( td_dom%i_imin < 0 .OR. td_dom%i_imin > td_dom%t_dim0(1)%i_len ).OR. &
+      &  ( td_dom%i_imax < 0 .OR. td_dom%i_imax > td_dom%t_dim0(1)%i_len ).OR. &
+      &  ( td_dom%i_jmin < 0 .OR. td_dom%i_jmin > td_dom%t_dim0(2)%i_len ).OR. &
+      &  ( td_dom%i_jmax < 0 .OR. td_dom%i_jmax > td_dom%t_dim0(2)%i_len ))THEN
+!      &  ( td_dom%i_kmin < 0 .OR. td_dom%i_kmin > td_dom%t_dim0(3)%i_len ).OR. &
+!      &  ( td_dom%i_kmax < 0 .OR. td_dom%i_kmax > td_dom%t_dim0(3)%i_len ).OR. &
+!      &  ( td_dom%i_lmin < 0 .OR. td_dom%i_lmin > td_dom%t_dim0(4)%i_len ).OR. &
+!      &  ( td_dom%i_lmax < 0 .OR. td_dom%i_lmax > td_dom%t_dim0(4)%i_len ))THEN
+         CALL logger_error( "DOM INIT DEFINE: invalid grid definition."// &
+         &               " check min and max indices")
+         CALL logger_debug("0 < imin ("//TRIM(fct_str(id_imin))//") < "//&
+         &              TRIM(fct_str(td_dom%t_dim0(1)%i_len)))
+         CALL logger_debug("0 < imax ("//TRIM(fct_str(id_imax))//") < "//&
+         &              TRIM(fct_str(td_dom%t_dim0(1)%i_len)))
+         CALL logger_debug("0 < jmin ("//TRIM(fct_str(id_jmin))//") < "//&
+         &              TRIM(fct_str(td_dom%t_dim0(2)%i_len)))
+         CALL logger_debug("0 < jmax ("//TRIM(fct_str(id_jmax))//") < "//&
+         &              TRIM(fct_str(td_dom%t_dim0(2)%i_len)))
+!         CALL logger_debug("0 < kmin ("//TRIM(fct_str(id_kmin))//") < "//&
+!         &              TRIM(fct_str(td_dom%t_dim0(3)%i_len)))
+!         CALL logger_debug("0 < kmax ("//TRIM(fct_str(id_kmax))//") < "//&
+!         &              TRIM(fct_str(td_dom%t_dim0(3)%i_len)))
+!         CALL logger_debug("0 < lmin ("//TRIM(fct_str(id_lmin))//") < "//&
+!         &              TRIM(fct_str(td_dom%t_dim0(4)%i_len)))
+!         CALL logger_debug("0 < lmax ("//TRIM(fct_str(id_lmax))//") < "//&
+!         &              TRIM(fct_str(td_dom%t_dim0(4)%i_len)))
+      ELSE
+
+!         td_dom%t_dim(3)%i_len=td_dom%i_kmax-td_dom%i_kmin+1
+!         td_dom%t_dim(4)%i_len=td_dom%i_lmax-td_dom%i_lmin+1
+
+         SELECT CASE(td_dom%i_perio0)
+            CASE(0) ! closed boundary
+               CALL logger_trace("DEFINE: closed boundary")
+               CALL dom__define_closed( td_dom )
+            CASE(1) ! cyclic east-west boundary
+               CALL logger_trace("DEFINE: cyclic east-west boundary")
+               CALL dom__define_cyclic( td_dom )
+            CASE(2) ! symmetric boundary condition across the equator
+               CALL logger_trace("DEFINE: symmetric boundary condition "//&
+               &                 " across the equator")
+               CALL dom__define_symmetric( td_dom )
+            CASE(3) ! North fold boundary (with a F-point pivot)  
+               CALL logger_trace("DEFINE: North fold boundary "//&
+               &                 "(with a F-point pivot)")
+               CALL dom__define_north_fold( td_dom )
+            CASE(5) ! North fold boundary (with a T-point pivot)
+               CALL logger_trace("DEFINE: North fold boundary "//&
+               &                 "(with a T-point pivot)")
+               CALL dom__define_north_fold( td_dom )
+            CASE(4) ! North fold boundary (with a F-point pivot) 
+                    ! and cyclic east-west boundary
+               CALL logger_trace("DEFINE:  North fold boundary "//&
+               &                 "(with a F-point pivot) and cyclic "//&
+               &                 "east-west boundary")
+               CALL dom__define_cyclic_north_fold( td_dom )
+            CASE(6) ! North fold boundary (with a T-point pivot) 
+                    ! and cyclic east-west boundary
+               CALL logger_trace("DEFINE: North fold boundary "//&
+               &                 "(with a T-point pivot) and cyclic "//&
+               &                 "east-west boundary")
+               CALL dom__define_cyclic_north_fold( td_dom )
+            CASE DEFAULT
+               CALL logger_error("DEFINE: invalid grid periodicity index")
+         END SELECT
+
+      ENDIF
+
+   END SUBROUTINE dom__define
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This subroutine define domain indices from global domain with
+   !> cyclic east-west boundary and north fold boundary condition.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__define_cyclic_north_fold( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+      !----------------------------------------------------------------
+
+      CALL dom__check_EW_index( td_dom )
+
+      IF( td_dom%i_imin == td_dom%i_imax .AND. &
+      &   td_dom%i_jmin == td_dom%i_jmax )THEN
+
+         CALL logger_trace("DEFINE CYCLIC NORTH FOLD: "//&
+         &  "domain to extract is global" )
+         ! coarse domain is global domain
+
+         CALL dom__size_global( td_dom )
+
+      ELSEIF( td_dom%i_imin == td_dom%i_imax .AND. &
+      &       td_dom%i_jmin >= td_dom%i_jmax )THEN
+
+         CALL logger_trace("DEFINE CYCLIC NORTH FOLD: "//&
+         &  "domain to extract is semi-global" )
+
+         CALL dom__size_semi_global( td_dom )
+
+      ELSEIF( td_dom%i_imin == td_dom%i_imax .AND. &
+      &       td_dom%i_jmin < td_dom%i_jmax )THEN
+
+         CALL logger_trace("DEFINE CYCLIC NORTH FOLD: "//&
+         &  "domain to extract is band of latidue" )
+
+         CALL dom__size_no_pole( td_dom )
+
+      ELSEIF( td_dom%i_imin /= td_dom%i_imax .AND. &
+      &       td_dom%i_jmin == td_dom%i_jmax )THEN
+
+         CALL logger_trace("DEFINE CYCLIC NORTH FOLD: "//&
+         &  "domain to extract has north boundary" )
+
+         CALL dom__size_pole( td_dom )
+
+      ELSEIF( td_dom%i_imin /= td_dom%i_imax .AND. &
+      &       td_dom%i_jmin /= td_dom%i_jmax )THEN
+
+         IF( td_dom%i_jmax < td_dom%t_dim0(2)%i_len-1 .AND. &
+         &   td_dom%i_jmax > td_dom%i_jmin )THEN
+
+            CALL logger_trace("DEFINE CYCLIC NORTH FOLD: "//&
+            &  "domain to extract has no north boundary" )
+            ! no North Pole
+            
+            CALL dom__size_no_pole( td_dom )
+
+         ELSE
+
+            CALL logger_trace("DEFINE CYCLIC NORTH FOLD: "//&
+            &  "domain to extract has north boundary" )
+
+            CALL dom__size_pole( td_dom )
+
+         ENDIF
+
+      ELSE
+
+         CALL logger_error("DEFINE CYCLIC NORTH FOLD: "//&
+         &  "should have been an impossible case" )
+
+      ENDIF
+      
+   END SUBROUTINE dom__define_cyclic_north_fold
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This subroutine define extract domain indices from global domain 
+   !> with north fold boundary condition.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__define_north_fold( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+      !----------------------------------------------------------------
+
+      IF( td_dom%i_jmax < td_dom%t_dim0(2)%i_len-1 .AND. &
+      &   td_dom%i_jmax > td_dom%i_jmin )THEN
+
+         CALL logger_trace("DEFINE NORTH FOLD: "//&
+         &  "domain to extract has no north boundary" )
+         ! no North Pole
+         
+         CALL dom__size_no_pole_no_overlap( td_dom )
+
+      ELSE
+
+         CALL logger_trace("DEFINE NORTH FOLD: "//&
+         &  "domain to extract has north boundary" )
+
+         CALL dom__size_pole_no_overlap( td_dom )
+
+      ENDIF      
+
+   END SUBROUTINE dom__define_north_fold
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This subroutine define extract domain indices from global domain 
+   !> with symmetric boundary condition across the equator.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__define_symmetric( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+      !----------------------------------------------------------------
+
+      CALL dom__size_no_pole_no_overlap( td_dom )
+
+   END SUBROUTINE dom__define_symmetric
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This subroutine define extract domain indices from global domain
+   !> with cyclic east-west boundary.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__define_cyclic( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+      !----------------------------------------------------------------
+      CALL dom__check_EW_index( td_dom )
+      
+      IF( td_dom%i_imin >= td_dom%i_imax )THEN
+         CALL logger_trace("DEFINE CYCLIC: "//&
+         &  "domain to extract overlap east-west boundary")
+
+         CALL dom__size_no_pole_overlap( td_dom )
+
+      ELSE
+         ! id_imin < id_imax
+         CALL logger_trace("DEFINE CYCLIC: "//&
+         &  "domain to extract do not overlap east-west boundary")
+
+         CALL dom__size_no_pole_no_overlap( td_dom )
+
+      ENDIF
+
+   END SUBROUTINE dom__define_cyclic
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This subroutine define extract domain indices from global domain
+   !> with closed boundaries.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__define_closed( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+      !----------------------------------------------------------------
+
+      CALL dom__size_no_pole_no_overlap( td_dom )
+
+   END SUBROUTINE dom__define_closed
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This subroutine check East-West indices, use inside a cyclic domain,
+   !> and redefine it in some particular cases.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__check_EW_index( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+      !----------------------------------------------------------------
+
+      IF( td_dom%i_imin /= td_dom%i_imax )THEN
+
+         IF((ABS(td_dom%i_imax-td_dom%i_imin) >= td_dom%t_dim0(1)%i_len-1).OR.&
+            (ABS(td_dom%i_imax-td_dom%i_imin) <= td_dom%i_ew0 ) )THEN
+
+            td_dom%i_imin = td_dom%i_imax
+
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE dom__check_EW_index
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine compute size of global domain 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__size_global( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+      !----------------------------------------------------------------
+
+      td_dom%i_imin = 1                     
+      td_dom%i_imax = td_dom%t_dim0(1)%i_len
+
+      td_dom%i_jmin = 1 
+      td_dom%i_jmax = td_dom%t_dim0(2)%i_len
+
+      ! domain size
+      td_dom%t_dim(1)%i_len = td_dom%t_dim0(1)%i_len
+      td_dom%t_dim(2)%i_len = td_dom%t_dim0(2)%i_len
+
+      ! no ghost cell to add
+      td_dom%i_ighost=0
+      td_dom%i_jghost=0
+
+      ! peiordicity
+      IF( td_dom%i_pivot == 0 )THEN ! 0-F
+         td_dom%i_perio=4
+         td_dom%i_pivot=0
+      ELSE ! 1-T
+         td_dom%i_perio=6
+         td_dom%i_pivot=1
+      ENDIF
+
+   END SUBROUTINE dom__size_global
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine compute size of a semi global domain 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !> @note never tested
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__size_semi_global( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+
+      ! local variable
+      INTEGER(i4) :: il_imid   ! cananadian bipole index (middle of global domain) 
+      !----------------------------------------------------------------
+
+      il_imid = td_dom%t_dim0(1)%i_len/2 + td_dom%i_pivot
+
+      td_dom%i_imin = 2
+      td_dom%i_imax = il_imid !td_dom%t_dim0(1)%i_len
+
+      IF( td_dom%i_jmax >= td_dom%t_dim0(2)%i_len-1 )THEN
+         td_dom%i_jmax=MIN( td_dom%i_jmin, & 
+         &                  td_dom%t_dim0(2)%i_len-td_dom%i_jmax )
+      ELSE
+         td_dom%i_jmin=td_dom%i_jmax
+      ENDIF
+
+      ! domain size
+      td_dom%t_dim(1)%i_len = (td_dom%i_imax ) - &
+      &                         (td_dom%i_imin ) + 1
+
+      td_dom%t_dim(2)%i_len = ( td_dom%t_dim0(2)%i_len - &
+      &                         ( td_dom%i_jmin ) + 1 ) +      &
+      &                         ( td_dom%t_dim0(2)%i_len - &
+      &                         ( td_dom%i_jmax ) + 1 ) - 2    ! remove north fold condition ?
+
+      ! ghost cell to add
+      td_dom%i_ighost=1
+      td_dom%i_jghost=1
+
+      ! periodicity
+      IF( td_dom%i_pivot == 0 )THEN !0-F
+         td_dom%i_perio=3
+         td_dom%i_pivot=0
+      ELSE !1-T
+         td_dom%i_perio=5
+         td_dom%i_pivot=1
+      ENDIF
+
+   END SUBROUTINE dom__size_semi_global
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine compute size of an extract domain without north fold
+   !> condition
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__size_no_pole( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+      !----------------------------------------------------------------
+
+      IF( td_dom%i_jmin >= td_dom%i_jmax )THEN
+         CALL logger_fatal("DOM INIT: invalid domain. "//&
+         &  "can not get north pole from this coarse grid. "//&
+         &  "check namelist and coarse grid periodicity." )
+      ENDIF
+
+      IF( td_dom%i_imin >= td_dom%i_imax )THEN
+         CALL logger_trace("DEFINE NO POLE: "// &
+         &  "domain to extract overlap east-west boundary")
+
+         CALL dom__size_no_pole_overlap( td_dom )
+
+      ELSE
+         ! id_imin < id_imax
+         CALL logger_trace("DEFINE NO POLE: "// &
+         &  "domain to extract do not overlap east-west boundary")
+
+         CALL dom__size_no_pole_no_overlap( td_dom )
+
+      ENDIF
+
+   END SUBROUTINE dom__size_no_pole
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine compute size of an extract domain with north fold
+   !> condition
+   !>
+   !> @author J.Paul
+   !> - April, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__size_pole( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+      !----------------------------------------------------------------
+
+      IF( td_dom%i_imin > td_dom%i_imax )THEN
+         CALL logger_trace("DEFINE POLE: "//&
+         &  "domain to extract overlap east-west boundary")
+         CALL dom__size_pole_overlap( td_dom )
+      ELSEIF( td_dom%i_imin < td_dom%i_imax )THEN
+         CALL logger_trace("DEFINE POLE: "//&
+         &  "domain to extract do not overlap east-west boundary")
+         CALL dom__size_pole_no_overlap( td_dom )
+      ENDIF
+
+   END SUBROUTINE dom__size_pole
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine compute size of an extract domain without north fold
+   !> condition, and which overlap east-west boundary
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__size_no_pole_overlap( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+      !----------------------------------------------------------------
+
+      IF( td_dom%i_jmin >= td_dom%i_jmax )THEN
+         CALL logger_fatal("DOM INIT: invalid domain. "//&
+         &  "can not get north pole from this coarse grid. "//&
+         &  "check namelist and coarse grid periodicity." )
+      ENDIF
+
+      IF( td_dom%i_imin == td_dom%i_imax )THEN
+         ! domain to extract with east west cyclic boundary
+         CALL logger_trace("DEFINE NO POLE OVERLAP: "//&
+         &  "domain to extract has cyclic east-west boundary")
+
+         td_dom%i_imin = 1
+         td_dom%i_imax = td_dom%t_dim0(1)%i_len
+
+         td_dom%t_dim(1)%i_len = td_dom%t_dim0(1)%i_len
+
+         ! no ghost cell
+         td_dom%i_ighost=0
+
+         ! periodicity
+         td_dom%i_perio=1
+
+      ELSE
+
+         ! id_imin > id_imax
+         ! extract domain overlap east-west boundary
+
+         td_dom%t_dim(1)%i_len = td_dom%t_dim0(1)%i_len -             &
+         &                       (td_dom%i_imin ) + 1 + & 
+         &                       (td_dom%i_imax ) - 2     ! remove cyclic boundary
+
+         ! add ghost cell
+         td_dom%i_ighost=1
+
+         ! periodicity
+         td_dom%i_perio=0
+
+      ENDIF
+
+      td_dom%t_dim(2)%i_len = (td_dom%i_jmax ) - &
+      &                       (td_dom%i_jmin ) + 1
+
+      ! add ghost cell
+      td_dom%i_jghost=1
+
+   END SUBROUTINE dom__size_no_pole_overlap
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine compute size of an extract domain without north fold
+   !> condition, and which do not overlap east-west boundary
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__size_no_pole_no_overlap( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+      !----------------------------------------------------------------
+
+      IF( td_dom%i_jmin >= td_dom%i_jmax )THEN
+         CALL logger_fatal("DOM INIT: invalid domain. "//&
+         &  "can not get north pole from this coarse grid. "//&
+         &  "check namelist and coarse grid periodicity." )
+      ENDIF
+
+      IF( td_dom%i_imin >= td_dom%i_imax )THEN
+         CALL logger_fatal("DOM INIT: invalid domain. "//&
+         &  "can not overlap East-West boundary with this coarse grid. "//&
+         &  "check namelist and coarse grid periodicity." )
+      ENDIF
+
+      td_dom%t_dim(1)%i_len = ( td_dom%i_imax ) - & 
+      &                       ( td_dom%i_imin ) + 1 
+
+      td_dom%t_dim(2)%i_len = ( td_dom%i_jmax ) - &
+      &                       ( td_dom%i_jmin ) + 1
+      
+      ! add ghost cell
+      td_dom%i_ighost=1
+      td_dom%i_jghost=1
+
+      ! periodicity
+      td_dom%i_perio=0
+
+   END SUBROUTINE dom__size_no_pole_no_overlap
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine compute size of an extract domain with north fold
+   !> condition, and which overlap east-west boundary
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !> @note never tested
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__size_pole_overlap( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+
+      ! local variable
+      INTEGER(i4) :: il_idom1  ! extract domain size, east part
+      INTEGER(i4) :: il_idom2  ! extract domain size, west part
+      INTEGER(i4) :: il_imid   ! cananadian bipole index (middle of global domain) 
+      !----------------------------------------------------------------
+
+      CALL logger_trace("DEFINE POLE OVERLAP: "//&
+      &  "asian bipole inside domain to extract")
+
+      il_imid = td_dom%t_dim0(1)%i_len/2 + td_dom%i_pivot
+
+      il_idom1 = td_dom%t_dim0(1)%i_len - td_dom%i_imin + 1
+      il_idom2 = td_dom%i_imax
+      
+      IF( il_idom1 > il_imid .OR. il_idom2 > il_imid )THEN
+
+         CALL logger_trace("DEFINE POLE OVERLAP: "//&
+         &  "canadian bipole inside domain to extract")
+         td_dom%i_imin = td_dom%i_imax
+
+         IF( td_dom%i_jmin == td_dom%i_jmax )THEN
+            CALL dom__size_global( td_dom )
+         ELSE
+            CALL dom__size_semi_global( td_dom )
+         ENDIF
+
+         ! periodicity
+         td_dom%i_perio=0
+
+      ELSEIF( il_idom1 > il_idom2 )THEN
+
+         ! east part bigger than west part
+         CALL logger_trace("DEFINE POLE OVERLAP: east part bigger than west part ")
+         ! to respect symmetry around asian bipole
+         td_dom%i_imax = il_idom1
+
+         ! north pole
+         IF( td_dom%i_jmax >= td_dom%t_dim0(2)%i_len-1 )THEN
+            td_dom%i_jmax=MIN( td_dom%i_jmin, & 
+            &                  td_dom%t_dim0(2)%i_len-td_dom%i_jmax )
+         ELSE
+            td_dom%i_jmax=MIN( td_dom%i_jmin, td_dom%i_jmax )
+         ENDIF
+         td_dom%i_jmin=td_dom%i_jmax
+
+         ! compute size
+         td_dom%t_dim(1)%i_len = il_idom1  !! no ghost cell ??
+         td_dom%t_dim(2)%i_len = ( td_dom%t_dim0(2)%i_len - &
+         &                         ( td_dom%i_jmin ) + 1 ) + &   
+         &                         ( td_dom%t_dim0(2)%i_len - &
+         &                         ( td_dom%i_jmax ) + 1 ) - 2   ! remove north fold condition ?
+
+         ! add ghost cell
+         td_dom%i_ighost=1
+         td_dom%i_jghost=1
+
+         ! periodicity
+         td_dom%i_perio=0
+
+      ELSE ! il_idom2 >= il_idom1
+
+         ! west part bigger than east part
+         CALL logger_trace("DEFINE POLE OVERLAP: west part bigger than east part ")
+
+         ! to respect symmetry around asian bipole
+         td_dom%i_imin = td_dom%t_dim0(1)%i_len - il_idom2 + 1
+
+         ! north pole
+         IF( td_dom%i_jmax >= td_dom%t_dim0(2)%i_len-1 )THEN
+            td_dom%i_jmax=MIN( td_dom%i_jmin, & 
+            &                  td_dom%t_dim0(2)%i_len-td_dom%i_jmax )
+         ELSE
+            td_dom%i_jmax=MIN( td_dom%i_jmin, td_dom%i_jmax )
+         ENDIF
+         td_dom%i_jmin=td_dom%i_jmax
+
+         ! compute size
+         td_dom%t_dim(1)%i_len = il_idom2
+         td_dom%t_dim(2)%i_len = ( td_dom%t_dim0(2)%i_len - &
+         &                         ( td_dom%i_jmin ) + 1 ) + &
+         &                         ( td_dom%t_dim0(2)%i_len - &
+         &                         ( td_dom%i_jmax ) + 1 ) - 2
+
+         ! add ghost cell
+         td_dom%i_ighost=1
+         td_dom%i_jghost=1
+         
+         ! periodicity
+         td_dom%i_perio=0
+
+      ENDIF
+
+   END SUBROUTINE dom__size_pole_overlap
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine compute size of an extract domain with north fold
+   !> condition, and which do not overlap east-west boundary
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !> @note never tested
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom__size_pole_no_overlap( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM), INTENT(INOUT) :: td_dom
+
+      ! local variable
+      INTEGER(i4) :: il_idom1  ! extract domain size, east part
+      INTEGER(i4) :: il_idom2  ! extract domain size, west part
+      INTEGER(i4) :: il_mid    ! canadian biple index ?
+      !----------------------------------------------------------------
+
+      IF( td_dom%i_imin >= td_dom%i_imax )THEN
+         CALL logger_fatal("DOM INIT: invalid domain. "//&
+         &  "can not overlap East-West boundary with this coarse grid. "//&
+         &  "check namelist and coarse grid periodicity." )
+      ENDIF
+
+      CALL logger_trace("DEFINE POLE NO OVERLAP: "//&
+      &  "no asian bipole inside domain to extract")
+
+      ! north pole
+      IF( td_dom%i_jmax >= td_dom%t_dim0(2)%i_len-1 )THEN
+         td_dom%i_jmax=MIN( td_dom%i_jmin, & 
+         &                  td_dom%t_dim0(2)%i_len-td_dom%i_jmax )
+      ELSE
+         td_dom%i_jmax=MIN( td_dom%i_jmin, td_dom%i_jmax )
+      ENDIF
+      td_dom%i_jmin=td_dom%i_jmax
+
+      ! 
+      il_mid = td_dom%t_dim0(1)%i_len/2 + td_dom%i_pivot
+
+      IF( (td_dom%i_imin < il_mid .AND. td_dom%i_imax < il_mid) .OR. &
+      &   (td_dom%i_imin > il_mid .AND. td_dom%i_imax > il_mid) )THEN
+         CALL logger_trace("DEFINE POLE NO OVERLAP: "//&
+         &  "no canadian bipole inside domain to extract")
+
+         td_dom%t_dim(1)%i_len = ( td_dom%i_imax ) - &
+         &                       ( td_dom%i_imin ) + 1
+
+         td_dom%t_dim(2)%i_len = ( td_dom%t_dim0(2)%i_len - &
+         &                       ( td_dom%i_jmin ) + 1 ) + &
+         &                       ( td_dom%t_dim0(2)%i_len - &
+         &                       ( td_dom%i_jmax ) + 1 ) - 2 ! remove north fold condition ?
+
+         ! add ghost cell
+         td_dom%i_ighost=1
+         td_dom%i_jghost=1
+
+         ! periodicity
+         td_dom%i_perio=0
+
+      ELSE ! id_imin < il_mid .AND. id_imax > il_mid
+         CALL logger_trace("DEFINE POLE NO OVERLAP: "//&
+         &  "canadian bipole inside domain to extract")
+
+         il_idom1 = td_dom%i_imax - (il_mid - 1)
+         il_idom2 = il_mid  - td_dom%i_imin
+         IF( il_idom1 > il_idom2 )THEN
+            ! east part bigger than west part
+            CALL logger_trace("DEFINE POLE NO OVERLAP: east part bigger than west part ")
+            ! to respect symmetry around canadian bipole
+            td_dom%i_imin = il_mid - il_idom1
+
+            td_dom%t_dim(1)%i_len = il_idom1 + 1
+            td_dom%t_dim(2)%i_len = ( td_dom%t_dim0(2)%i_len - &
+            &                         ( td_dom%i_jmin ) + 1 ) + & 
+            &                         ( td_dom%t_dim0(2)%i_len - &
+            &                         ( td_dom%i_jmax ) + 1 ) &   
+            &                         - 2 - 2 * td_dom%i_pivot    ! remove north fold condition ?
+
+            ! add ghost cell
+            td_dom%i_ighost=1
+            td_dom%i_jghost=1
+
+            ! periodicity
+            td_dom%i_perio=0
+
+         ELSE ! il_idom2 >= il_idom1
+            ! west part bigger than east part
+            CALL logger_trace("DEFINE POLE NO OVERLAP: west part bigger than east part ")
+            ! to respect symmetry around canadian bipole
+
+            td_dom%i_imax = il_mid + il_idom2
+
+            td_dom%t_dim(1)%i_len = il_idom2 + 1
+            td_dom%t_dim(2)%i_len = ( td_dom%t_dim0(2)%i_len -  &
+            &                         ( td_dom%i_jmin ) + 1 ) +     & 
+            &                         ( td_dom%t_dim0(2)%i_len -  &
+            &                         ( td_dom%i_jmax ) + 1 )       & 
+            &                         - 2 - 2 * td_dom%i_pivot  !  remove north fold condition ?
+
+            ! add ghost cell
+            td_dom%i_ighost=1
+            td_dom%i_jghost=1
+
+            ! periodicity
+            td_dom%i_perio=0            
+
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE dom__size_pole_no_overlap
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function get east west overlap.
+   !
+   !> @details
+   !> If no east -west wrap return -1, 
+   !> else return the size of the ovarlap band 
+   !
+   !> @author J.Paul
+   !> - 2013- Initial Version
+   !
+   !> @param[in] 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION dom_get_ew_overlap(td_lon)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR), INTENT(IN) :: td_lon
+
+      ! function
+      INTEGER(i4) :: dom_get_ew_overlap
+
+      ! local variable
+      REAL(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+      REAL(dp), DIMENSION(:)      , ALLOCATABLE :: dl_lone
+      REAL(dp), DIMENSION(:)      , ALLOCATABLE :: dl_lonw
+
+      REAL(dp)    :: dl_delta
+      REAL(dp)    :: dl_lonmax
+      REAL(dp)    :: dl_lonmin
+
+      INTEGER(i4) :: il_east
+      INTEGER(i4) :: il_west
+      INTEGER(i4) :: il_jmin
+      INTEGER(i4) :: il_jmax
+
+      INTEGER(i4), PARAMETER :: ip_max_overlap = 5
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! init 
+      dom_get_ew_overlap=-1
+
+      il_west=1
+      il_east=td_lon%t_dim(1)%i_len
+
+      ALLOCATE( dl_value(td_lon%t_dim(1)%i_len, &
+      &                  td_lon%t_dim(2)%i_len, &
+      &                  td_lon%t_dim(3)%i_len, &
+      &                  td_lon%t_dim(4)%i_len) )
+
+      dl_value(:,:,:,:)=td_lon%d_value(:,:,:,:)
+      WHERE( dl_value(:,:,:,:) > 180._dp .AND. &
+      &      dl_value(:,:,:,:) /= td_lon%d_fill ) 
+         dl_value(:,:,:,:)=360.-dl_value(:,:,:,:)
+      END WHERE
+
+      ! we do not use jmax as dimension length due to north fold boundary
+      il_jmin=1+ig_ghost
+      il_jmax=(td_lon%t_dim(2)%i_len-ig_ghost)/2
+
+      ALLOCATE( dl_lone(il_jmax-il_jmin+1) )
+      ALLOCATE( dl_lonw(il_jmax-il_jmin+1) )
+
+      dl_lone(:)=dl_value(il_east,il_jmin:il_jmax,1,1)
+      dl_lonw(:)=dl_value(il_west,il_jmin:il_jmax,1,1)
+
+      IF( .NOT.(  ALL(dl_lone(:)==td_lon%d_fill) .AND. &
+      &           ALL(dl_lonw(:)==td_lon%d_fill) ) )THEN
+
+         dl_lonmax=MAXVAL(dl_value(:,il_jmin:il_jmax,:,:))
+         dl_lonmin=MINVAL(dl_value(:,il_jmin:il_jmax,:,:))
+
+         dl_delta=(dl_lonmax-dl_lonmin)/td_lon%t_dim(1)%i_len
+
+         IF( ALL(ABS(dl_lone(:)) - ABS(dl_lonw(:)) == dl_delta) )THEN
+
+            dom_get_ew_overlap=0
+
+         ELSE IF( ALL( ABS(dl_lone(:)) - ABS(dl_lonw(:)) < &
+         &             ip_max_overlap*dl_delta             ) )THEN
+            DO ji=0,ip_max_overlap
+
+               IF( il_east-ji == il_west )THEN
+                  ! case of small domain
+                  EXIT
+               ELSE
+                  dl_lone(:)=dl_value(il_east-ji,il_jmin:il_jmax,1,1)
+                  
+                  IF( ALL( dl_lonw(:) == dl_lone(:) ) )THEN
+                     dom_get_ew_overlap=ji+1
+                     EXIT
+                  ENDIF
+               ENDIF
+
+            ENDDO
+         ENDIF
+
+      ENDIF
+
+      DEALLOCATE( dl_value )
+
+   END FUNCTION dom_get_ew_overlap
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !>  This subroutine add extra point to domain
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !> @param [in] id_iext : i-direction size of extra bands (default=im_minext)
+   !> @param [in] id_jext : j-direction size of extra bands (default=im_minext)
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom_add_extra( td_dom, id_iext, id_jext )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM) ,  INTENT(INOUT) :: td_dom
+      INTEGER(i4),  INTENT(IN   ), OPTIONAL :: id_iext
+      INTEGER(i4),  INTENT(IN   ), OPTIONAL :: id_jext
+
+      ! local variable
+      INTEGER(i4) :: il_iext
+      INTEGER(i4) :: il_jext
+
+      ! loop indices
+      !----------------------------------------------------------------
+      ! init
+      !WARNING: two extrabands are required for cubic interpolation
+      il_iext=im_minext
+      IF( PRESENT(id_iext) ) il_iext=id_iext
+
+      il_jext=im_minext
+      IF( PRESENT(id_jext) ) il_jext=id_jext
+
+      td_dom%i_iextra(:)=0
+      td_dom%i_jextra(:)=0
+
+      IF( td_dom%i_imin == 1                       .AND. &
+      &   td_dom%i_imax == td_dom%t_dim0(1)%i_len  .AND. &
+      &   td_dom%i_jmin == 1                       .AND. &
+      &   td_dom%i_jmax == td_dom%t_dim0(2)%i_len )THEN
+         ! global
+         ! nothing to be done
+      ELSE
+         IF( td_dom%i_imin == 1                       .AND. &
+         &   td_dom%i_imax == td_dom%t_dim0(1)%i_len )THEN
+            ! EW cyclic
+            ! nothing to be done
+         ELSE
+            IF( td_dom%i_imin /= 1 )THEN
+               td_dom%i_iextra(1)=il_iext
+
+            ELSE
+               IF( td_dom%i_ew0 > 0 )THEN
+                  td_dom%i_iextra(1)=il_iext
+
+               ENDIF
+            ENDIF
+
+            IF( td_dom%i_imax /= td_dom%t_dim(1)%i_len )THEN
+               td_dom%i_iextra(2)=1
+
+            ELSE
+               IF( td_dom%i_ew0 > 0 )THEN
+                  td_dom%i_iextra(2)=il_jext
+
+               ENDIF
+            ENDIF
+
+         ENDIF
+
+         IF( td_dom%i_jmin == td_dom%i_jmax )THEN
+            td_dom%i_jextra(1)=il_iext
+            td_dom%i_jextra(2)=il_jext
+
+         ELSE
+            IF( td_dom%i_jmin /= 1)THEN
+               td_dom%i_jextra(1)=il_iext
+
+            ENDIF
+            IF( td_dom%i_jmax /= td_dom%t_dim(2)%i_len )THEN
+               td_dom%i_jextra(2)=il_jext
+
+            ENDIF
+
+         ENDIF
+
+      ENDIF
+
+      ! change domain
+      td_dom%i_imin         = td_dom%i_imin - td_dom%i_iextra(1)
+      td_dom%i_jmin         = td_dom%i_jmin - td_dom%i_jextra(1)
+
+      td_dom%i_imax         = td_dom%i_imax + td_dom%i_iextra(2)
+      td_dom%i_jmax         = td_dom%i_jmax + td_dom%i_jextra(2)
+
+      td_dom%t_dim(1)%i_len = td_dom%t_dim(1)%i_len + &
+      &                          td_dom%i_iextra(1) + &
+      &                          td_dom%i_iextra(2)
+      td_dom%t_dim(2)%i_len = td_dom%t_dim(2)%i_len + &
+      &                          td_dom%i_jextra(1) + &
+      &                          td_dom%i_jextra(2)
+
+
+   END SUBROUTINE dom_add_extra
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !>  This subroutine clean domain structure. it remove extra point added. 
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom_clean_extra( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM) , INTENT(INOUT) :: td_dom
+
+      ! local variable
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! change domain
+      td_dom%i_imin         = td_dom%i_imin + td_dom%i_iextra(1)
+      td_dom%i_jmin         = td_dom%i_jmin + td_dom%i_jextra(1)
+
+      td_dom%i_imax         = td_dom%i_imax - td_dom%i_iextra(2)
+      td_dom%i_jmax         = td_dom%i_jmax - td_dom%i_jextra(2)
+
+      td_dom%t_dim(1)%i_len = td_dom%t_dim(1)%i_len - &
+      &                          td_dom%i_iextra(1) - &
+      &                          td_dom%i_iextra(2)
+      td_dom%t_dim(2)%i_len = td_dom%t_dim(2)%i_len - &
+      &                          td_dom%i_jextra(1) - &
+      &                          td_dom%i_jextra(2)
+
+      td_dom%i_iextra(:)=0
+      td_dom%i_jextra(:)=0
+
+   END SUBROUTINE dom_clean_extra
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !>  This subroutine 
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_var : variable strcuture
+   !> @param[inout] td_dom : domain strcuture
+   !> @param[inout] id_rhoi : i-direction refinement factor
+   !> @param[inout] id_rhoj : j-direction refinement factor
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom_del_extra( td_var, td_dom, id_rho )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(INOUT) :: td_var
+      TYPE(TDOM) , INTENT(IN   ) :: td_dom
+      INTEGER(i4), DIMENSION(:), INTENT(IN   ) :: id_rho
+
+      ! local variable
+      INTEGER(i4) :: il_iextra
+      INTEGER(i4) :: il_jextra
+
+      INTEGER(i4) :: il_imin
+      INTEGER(i4) :: il_imax
+      INTEGER(i4) :: il_jmin
+      INTEGER(i4) :: il_jmax
+      
+      REAL(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      IF( .NOT. ASSOCIATED(td_var%d_value) )THEN
+         CALL logger_error("DOM DEL EXTRA: no value associated to "//&
+         &     "variable "//TRIM(td_var%c_name) )
+      ELSE
+         ! get vairbale right domain
+         IF( ALL(td_var%t_dim(1:2)%l_use) )THEN
+            il_iextra=SUM(td_dom%i_iextra(:))*id_rho(jp_I)
+            il_jextra=SUM(td_dom%i_jextra(:))*id_rho(jp_J)
+
+            ALLOCATE(dl_value(td_var%t_dim(1)%i_len, &
+            &                 td_var%t_dim(2)%i_len, &
+            &                 td_var%t_dim(3)%i_len, &
+            &                 td_var%t_dim(4)%i_len) )
+            dl_value(:,:,:,:)=td_var%d_value(:,:,:,:)
+
+            il_imin=1                     + td_dom%i_iextra(1)*id_rho(jp_I)
+            il_imax=td_var%t_dim(1)%i_len - td_dom%i_iextra(2)*id_rho(jp_I)
+
+            il_jmin=1                     + td_dom%i_jextra(1)*id_rho(jp_J)
+            il_jmax=td_var%t_dim(2)%i_len - td_dom%i_jextra(2)*id_rho(jp_J)
+
+            td_var%t_dim(1)%i_len=td_var%t_dim(1)%i_len-il_iextra
+            td_var%t_dim(2)%i_len=td_var%t_dim(2)%i_len-il_jextra
+
+            DEALLOCATE(td_var%d_value)
+            ALLOCATE(td_var%d_value(td_var%t_dim(1)%i_len, &
+            &                       td_var%t_dim(2)%i_len, &
+            &                       td_var%t_dim(3)%i_len, &
+            &                       td_var%t_dim(4)%i_len) )
+
+            td_var%d_value(:,:,:,:)=dl_value(il_imin:il_imax, &
+            &                                il_jmin:il_jmax, &
+            &                                :, :)
+            DEALLOCATE(dl_value)
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE dom_del_extra
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !>  This subroutine clean mpp strcuture.
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE dom_clean( td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TDOM),  INTENT(INOUT) :: td_dom
+
+      ! local variable
+      TYPE(TDOM) :: tl_dom ! empty file structure
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      CALL logger_info( " CLEAN: reset domain " )
+
+      ! del dimension
+      DO ji=ip_maxdim,1,-1
+         CALL dim_clean( td_dom%t_dim0(ji) )
+      ENDDO
+
+      ! replace by empty structure
+      td_dom=tl_dom
+
+      END SUBROUTINE dom_clean
+END MODULE dom
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/extrap.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/extrap.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/extrap.f90	(revision 4245)
@@ -0,0 +1,1984 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: extrap
+!
+! DESCRIPTION:
+!> @brief 
+!> This module 
+!>
+!> @details
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!>
+!> @note WARNING: FillValue must not be zero (use var_chg_FillValue)
+!>
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!> @todo
+!> - something wrong when computing point to be extralopated
+!> - take care of ew value in variable structure
+!----------------------------------------------------------------------
+MODULE extrap
+   USE netcdf                          ! nf90 library
+   USE kind
+   USE phycst
+   USE global
+   USE fct
+   USE logger
+   USE dim
+   USE att
+   USE var
+
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+
+   ! function and subroutine
+   PUBLIC :: extrap_detect         !< detected point to be extrapolated
+   PUBLIC :: extrap_fill_value     !< extrapolate value over detected point 
+   PUBLIC :: extrap_add_extrabands !< 
+   PUBLIC :: extrap_del_extrabands !< 
+   PUBLIC :: extrap_deriv_1D !< 
+   PUBLIC :: extrap_deriv_2D !< 
+
+   PRIVATE :: extrap__detect_wrapper !< detected point to be extrapolated
+   PRIVATE :: extrap__detect         !< detected point to be extrapolated
+   PRIVATE :: extrap__fill_value_wrapper     !< extrapolate value over detected point 
+   PRIVATE :: extrap__fill_value     !< extrapolate value over detected point 
+   PRIVATE :: extrap__3D
+   PRIVATE :: extrap_deriv_3D
+   PRIVATE :: extrap__3D_min_error_coef
+   PRIVATE :: extrap__3D_min_error_fill
+   PRIVATE :: extrap__3D_dist_weight_coef
+   PRIVATE :: extrap__3D_dist_weight_fill
+
+   INTEGER(i4), PARAMETER :: im_maxiter = 10 !< default maximum number of iteration
+   INTEGER(i4), PARAMETER :: im_minext  = 2  !< default minumum number of point to extrapolate
+   INTEGER(i4), PARAMETER :: im_mincubic= 4  !< default minumum number of point to extrapolate for cubic interpolation
+
+   INTERFACE extrap_detect
+      MODULE PROCEDURE extrap__detect_wrapper !< detected point to be extrapolated
+   END INTERFACE extrap_detect
+
+   INTERFACE extrap_fill_value
+      MODULE PROCEDURE extrap__fill_value_wrapper !< detected point to be interpolated
+   END INTERFACE extrap_fill_value
+   
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function detected point to be extrapolated.
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var : variable to extrapolate
+   !> @param[in] id_iext : number of points to be extrapolated in i-direction
+   !> @param[in] id_jext : number of points to be extrapolated in j-direction
+   !> @param[in] id_kext : number of points to be extrapolated in k-direction
+   !> @return
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION extrap__detect( td_var0, td_level1, &
+   &                        id_offset, id_rho, id_ext )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) ,                 INTENT(INOUT) :: td_var0
+      TYPE(TVAR) , DIMENSION(:)  , INTENT(IN   ), OPTIONAL :: td_level1
+      INTEGER(i4), DIMENSION(:,:), INTENT(IN   ), OPTIONAL :: id_offset
+      INTEGER(i4), DIMENSION(:)  , INTENT(IN   ), OPTIONAL :: id_rho
+      INTEGER(i4), DIMENSION(:)  , INTENT(IN   ), OPTIONAL :: id_ext
+
+      ! function
+      INTEGER(i4), DIMENSION(td_var0%t_dim(1)%i_len,&
+      &                      td_var0%t_dim(2)%i_len,&
+      &                      td_var0%t_dim(3)%i_len ) :: extrap__detect
+
+      ! local variable
+      CHARACTER(LEN=lc)                                :: cl_level
+
+      INTEGER(i4)                                      :: il_varid
+      INTEGER(i4)      , DIMENSION(:,:,:), ALLOCATABLE :: il_detect
+      INTEGER(i4)      , DIMENSION(:,:)  , ALLOCATABLE :: il_offset
+      INTEGER(i4)      , DIMENSION(:,:)  , ALLOCATABLE :: il_level1
+      INTEGER(i4)      , DIMENSION(:,:)  , ALLOCATABLE :: il_level1_G0
+      INTEGER(i4)      , DIMENSION(:,:)  , ALLOCATABLE :: il_extra
+      INTEGER(i4)      , DIMENSION(:)    , ALLOCATABLE :: il_ext
+      INTEGER(i4)      , DIMENSION(:)    , ALLOCATABLE :: il_rho
+      INTEGER(i4)      , DIMENSION(:)    , ALLOCATABLE :: il_dim0
+
+      TYPE(TVAR)                                       :: tl_var1
+
+      ! loop indices
+      INTEGER(i4) :: ji0
+      INTEGER(i4) :: jj0
+      INTEGER(i4) :: jk0
+      INTEGER(i4) :: ji1
+      INTEGER(i4) :: jj1
+      INTEGER(i4) :: ji1m
+      INTEGER(i4) :: jj1m
+      INTEGER(i4) :: ji1p
+      INTEGER(i4) :: jj1p
+      !----------------------------------------------------------------
+
+      ! init
+      extrap__detect(:,:,:)=0
+
+      ALLOCATE( il_dim0(3) )
+      il_dim0(:)=td_var0%t_dim(1:3)%i_len
+
+      ! optional argument
+      ALLOCATE( il_rho(ip_maxdim) )
+      il_rho(:)=1
+      IF( PRESENT(id_rho) ) il_rho(1:SIZE(id_rho(:)))=id_rho(:)
+
+      ALLOCATE( il_offset(ip_maxdim,2) )
+      il_offset(:,:)=0
+      il_offset(jp_I,:)=FLOOR(REAL(il_rho(jp_I)-1,dp)*0.5)
+      il_offset(jp_J,:)=FLOOR(REAL(il_rho(jp_J)-1,dp)*0.5)
+      IF( PRESENT(id_offset) )THEN
+         il_offset(1:SIZE(id_offset(:,:),DIM=1),&
+         &         1:SIZE(id_offset(:,:),DIM=2) )= id_offset(:,:)
+      ENDIF
+
+      ALLOCATE( il_ext(ip_maxdim) )
+      il_ext(:)=im_minext
+      IF( PRESENT(id_ext) ) il_ext(1:SIZE(id_ext(:)))=id_ext(:)
+
+      ALLOCATE( il_detect(il_dim0(1),&
+      &                   il_dim0(2),&
+      &                   il_dim0(3)) )
+      il_detect(:,:,:)=0
+
+      ! select point already inform
+      WHERE( td_var0%d_value(:,:,:,1) /= td_var0%d_fill ) il_detect(:,:,:)=1
+ 
+      IF( PRESENT(td_level1) )THEN
+         SELECT CASE(TRIM(td_var0%c_point))
+         CASE DEFAULT !'T'
+            cl_level='tlevel'
+         CASE('U')
+            cl_level='ulevel'
+         CASE('V')
+            cl_level='vlevel'
+         CASE('F')
+            cl_level='flevel'
+         END SELECT
+         il_varid=var_get_id(td_level1(:),TRIM(cl_level))
+         IF( il_varid == 0 )THEN
+            CALL logger_error("EXTRAP DETECT: can not compute point to be "//&
+            &     "extrapolated for variable "//TRIM(td_var0%c_name)//&
+            &      ". can not find "//&
+            &     "level for variable point "//TRIM(TRIM(td_var0%c_point)))
+         ELSE
+            print *,'read ',trim(cl_level)
+            tl_var1=td_level1(il_varid)
+         ENDIF
+
+         ALLOCATE( il_level1_G0( il_dim0(1), il_dim0(2)) )
+         IF( ALL(tl_var1%t_dim(1:2)%i_len == il_dim0(1:2)) )THEN
+
+            ! variable to be extrapolated use same resolution than level
+            il_level1_G0(:,:)=INT(tl_var1%d_value(:,:,1,1),i4)
+            
+         ELSE
+            ! variable to be extrapolated do not use same resolution than level
+            ALLOCATE( il_level1(tl_var1%t_dim(1)%i_len, &
+            &                   tl_var1%t_dim(2)%i_len) )
+            ! match fine grid vertical level with coarse grid
+            il_level1(:,:)=INT(tl_var1%d_value(:,:,1,1),i4)/il_rho(jp_K)
+
+            ALLOCATE( il_extra(ig_ndim,2) )
+            ! coarsening fine grid level
+            il_extra(jp_I,1)=CEILING(REAL(il_rho(jp_I)-1,dp)/2._dp)
+            il_extra(jp_I,2)=FLOOR(REAL(il_rho(jp_I)-1,dp)/2._dp)
+
+            il_extra(jp_J,1)=CEILING(REAL(il_rho(jp_J)-1,dp)/2._dp)
+            il_extra(jp_J,2)=FLOOR(REAL(il_rho(jp_J)-1,dp)/2._dp)
+
+            DO jj0=1,td_var0%t_dim(2)%i_len
+               
+               jj1=(jj0-1)*il_rho(jp_J)+1-il_offset(jp_J,1)
+
+               jj1m=MAX( jj1-il_extra(jp_J,1), 1 )
+               jj1p=MIN( jj1+il_extra(jp_J,2), &
+               &         tl_var1%t_dim(2)%i_len-il_offset(jp_J,2) )
+               
+               DO ji0=1,td_var0%t_dim(1)%i_len
+
+                  ji1=(ji0-1)*il_rho(jp_I)+1-id_offset(jp_I,1)
+
+                  ji1m=MAX( ji1-il_extra(jp_I,1), 1 )
+                  ji1p=MIN( ji1+il_extra(jp_I,2), &
+                  &         tl_var1%t_dim(1)%i_len-id_offset(jp_I,2) )
+            
+                  il_level1_G0(ji0,jj0)=MAXVAL(il_level1(ji1m:ji1p,jj1m:jj1p))
+               ENDDO
+            ENDDO
+
+            !il_level1_G0(:,:)=0
+            !DO jj1=1,tl_var1%t_dim(2)%i_len
+      
+            !   jj0=INT(REAL((jj1+il_offset(jp_J,1)-1)-1,dp)/REAL(il_rho(jp_J),dp)) +1
+
+            !   DO ji1=1,tl_var1%t_dim(1)%i_len
+
+            !      ji0=INT(REAL((ji1+il_offset(jp_I,1)-1)-1,dp)/REAL(il_rho(jp_I),dp)) +1
+
+            !      il_level1_G0(ji0,jj0)=MAX(il_level1_G0(ji0,jj0),il_level1(ji1,jj1))
+            !      
+            !   ENDDO
+            !ENDDO
+
+            ! clean
+            DEALLOCATE( il_extra )
+            DEALLOCATE( il_level1 )
+
+         ENDIF
+
+         ! look for sea point
+         !il_detect(:,:,1)=0
+         DO jk0=1,td_var0%t_dim(3)%i_len
+            WHERE( il_level1_G0(:,:) >= jk0)
+               il_detect(:,:,jk0)=1
+            END WHERE
+            !il_detect(:,:,jk0)=il_level1_G0(:,:)
+            !WHERE( td_var0%d_value(:,:,jk0,1) /= td_var0%d_fill )
+            !   il_detect(:,:,1)=jk0-1
+            !END WHERE
+         ENDDO
+
+         ! clean
+         DEALLOCATE( il_level1_G0 )
+
+      ENDIF
+
+      ! clean
+      DEALLOCATE( il_offset )
+ 
+      !! select extra point depending on interpolation method
+      !! compute point near grid point already inform
+      !FORALL( ji0=1:il_dim0(1), &
+      !&       jj0=1:il_dim0(2), &
+      !&       jk0=1:il_dim0(3), &
+      !&       il_detect(ji0,jj0,jk0) == 1 )
+
+      !   il_detect(MAX(1,ji0-il_ext(jp_I)):MIN(ji0+il_ext(jp_I),il_dim0(1)),&
+      !   &         MAX(1,jj0-il_ext(jp_J)):MIN(jj0+il_ext(jp_J),il_dim0(2)),&
+      !   &         MAX(1,jk0-il_ext(jp_K)):MIN(jk0+il_ext(jp_K),il_dim0(3)) )=1 
+
+      !END FORALL
+      
+      ! do not compute grid point already inform
+      WHERE( td_var0%d_value(:,:,:,1) /= td_var0%d_fill ) il_detect(:,:,:)=0
+
+      ! save result
+      extrap__detect(:,:,:)=il_detect(:,:,:)
+
+      ! clean
+      DEALLOCATE( il_dim0 )
+      DEALLOCATE( il_ext )
+      DEALLOCATE( il_detect )
+
+   END FUNCTION extrap__detect
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function detected point to be extrapolated.
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var : variable to extrapolate
+   !> @param[in] id_iext : number of points to be extrapolated in i-direction
+   !> @param[in] id_jext : number of points to be extrapolated in j-direction
+   !> @param[in] id_kext : number of points to be extrapolated in k-direction
+   !> @return
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION extrap__detect_wrapper( td_var, td_level, &
+   &                                id_offset, id_rho, id_ext )
+
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) ,                         INTENT(INOUT) :: td_var
+      TYPE(TVAR) , DIMENSION(:)          , INTENT(IN   ), OPTIONAL :: td_level
+      INTEGER(i4), DIMENSION(:,:), INTENT(IN   ), OPTIONAL :: id_offset
+      INTEGER(i4), DIMENSION(:)  , INTENT(IN   ), OPTIONAL :: id_rho
+      INTEGER(i4), DIMENSION(:)  , INTENT(IN   ), OPTIONAL :: id_ext
+
+      ! function
+      INTEGER(i4), DIMENSION(td_var%t_dim(1)%i_len,&
+      &                      td_var%t_dim(2)%i_len,&
+      &                      td_var%t_dim(3)%i_len ) :: extrap__detect_wrapper
+
+      ! local variable
+      ! loop indices
+      !----------------------------------------------------------------
+      ! init
+      extrap__detect_wrapper(:,:,:)=0
+
+      IF( .NOT. ANY(td_var%t_dim(1:3)%l_use) )THEN
+         ! no dimension I-J-K used
+         CALL logger_debug(" EXTRAP DETECT: nothing done for variable"//&
+         &              TRIM(td_var%c_name) )
+      ELSE IF( ALL(td_var%t_dim(1:3)%l_use) )THEN
+         
+         ! detect point to be interpolated on I-J-K
+         CALL logger_debug(" EXTRAP DETECT: detect point "//&
+         &              " for variable "//TRIM(td_var%c_name) )
+         
+         extrap__detect_wrapper(:,:,:)=extrap__detect( td_var, td_level, &
+         &                                             id_offset, &
+         &                                             id_rho,    &
+         &                                             id_ext     )
+
+      ELSE IF( ALL(td_var%t_dim(1:2)%l_use) )THEN
+
+         ! detect point to be interpolated on I-J
+         CALL logger_debug(" EXTRAP DETECT: detect horizontal point "//&
+         &              " for variable "//TRIM(td_var%c_name) )
+         
+         extrap__detect_wrapper(:,:,1:1)=extrap__detect( td_var , td_level,&
+         &                                               id_offset, &
+         &                                               id_rho,    &
+         &                                               id_ext     )
+
+      ELSE IF( td_var%t_dim(3)%l_use )THEN
+         
+         ! detect point to be interpolated on K
+         CALL logger_debug(" EXTRAP DETECT: detect vertical point "//&
+         &              " for variable "//TRIM(td_var%c_name) )
+         
+         extrap__detect_wrapper(1:1,1:1,:)=extrap__detect( td_var , td_level, &
+         &                                                 id_offset, &
+         &                                                 id_rho,    &
+         &                                                 id_ext     )
+
+      ENDIF              
+
+      CALL logger_debug(" EXTRAP DETECT: "//&
+      &  TRIM(fct_str(SUM(extrap__detect_wrapper(:,:,:))))//&
+      &  " points to be extrapolated" )
+      
+   END FUNCTION extrap__detect_wrapper
+   !> @endcode
+!   !-------------------------------------------------------------------
+!   !> @brief
+!   !> This function detected point to be extrapolated.
+!   !> 
+!   !> @details 
+!   !>
+!   !> @author J.Paul
+!   !> - Nov, 2013- Initial Version
+!   !
+!   !> @param[in] td_var : variable to extrapolate
+!   !> @param[in] id_iext : number of points to be extrapolated in i-direction
+!   !> @param[in] id_jext : number of points to be extrapolated in j-direction
+!   !> @param[in] id_kext : number of points to be extrapolated in k-direction
+!   !> @return 
+!   !
+!   !> @todo
+!   !-------------------------------------------------------------------
+!   !> @code
+!   FUNCTION extrap__detect(td_var, id_iext, id_jext, id_kext)
+!      IMPLICIT NONE
+!      ! Argument
+!      TYPE(TVAR) ,                   INTENT(INOUT) :: td_var
+!      !INTEGER(i4), DIMENSION(:,:,:), INTENT(OUT  ) :: id_detect
+!      INTEGER(i4),                   INTENT(IN   ), OPTIONAL :: id_iext
+!      INTEGER(i4),                   INTENT(IN   ), OPTIONAL :: id_jext
+!      INTEGER(i4),                   INTENT(IN   ), OPTIONAL :: id_kext
+!
+!      ! function
+!      INTEGER(i4), DIMENSION(td_var%t_dim(1)%i_len, &
+!      &                      td_var%t_dim(2)%i_len, &
+!      &                      td_var%t_dim(3)%i_len) :: extrap__detect
+!
+!      ! local variable
+!      INTEGER(i4) :: il_iext
+!      INTEGER(i4) :: il_jext
+!      INTEGER(i4) :: il_kext
+!
+!      INTEGER(i4), DIMENSION(3) :: il_dim
+!
+!      ! loop indices
+!      INTEGER(i4) :: ji
+!      INTEGER(i4) :: jj
+!      INTEGER(i4) :: jk
+!      !----------------------------------------------------------------
+!
+!      ! optional argument
+!      il_iext=im_minext
+!      IF( PRESENT(id_iext) ) il_iext=id_iext
+!      il_jext=im_minext
+!      IF( PRESENT(id_jext) ) il_jext=id_jext
+!      il_kext=im_minext
+!      IF( PRESENT(id_kext) ) il_kext=id_kext
+!
+!      ! init
+!      extrap__detect(:,:,:)=0
+!
+!      il_dim(:)=td_var%t_dim(1:3)%i_len
+!
+!      ! compute point near grid point already inform
+!      FORALL( ji=1:il_dim(1), &
+!      &       jj=1:il_dim(2), &
+!      &       jk=1:il_dim(3), &
+!      &       td_var%d_value(ji,jj,jk,1) /= td_var%d_fill )
+!
+!         extrap__detect(MAX(1,ji-il_iext):MIN(ji+il_iext,il_dim(1)),&
+!         &              MAX(1,jj-il_jext):MIN(jj+il_jext,il_dim(2)),&
+!         &              MAX(1,jk-il_kext):MIN(jk+il_kext,il_dim(3)) )=1 
+!
+!
+!      END FORALL
+!      
+!      ! do not compute grid point already inform
+!      WHERE( td_var%d_value(:,:,:,1) /= td_var%d_fill ) extrap__detect(:,:,:)=0
+!
+!   END FUNCTION extrap__detect
+!   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] id_iext : number of points to be extrapolated in i-direction
+   !> @param[in] id_jext : number of points to be extrapolated in j-direction
+   !> @param[in] id_kext : number of points to be extrapolated in k-direction
+   !> @param[in] id_extend :  radius of the box used to compute extrapolation 
+   !> @param[in] id_maxiter : maximum nuber of iteration
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE extrap__fill_value_wrapper( td_var, td_level, &
+   &                                      id_offset,        &
+   &                                      id_rho,           &
+   &                                      id_iext, id_jext, id_kext, &
+   &                                      id_radius, id_maxiter )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) ,                  INTENT(INOUT) :: td_var
+      TYPE(TVAR) ,  DIMENSION(:)  , INTENT(IN   ), OPTIONAL :: td_level
+      INTEGER(i4),  DIMENSION(:,:), INTENT(IN   ), OPTIONAL :: id_offset
+      INTEGER(i4),  DIMENSION(:)  , INTENT(IN   ), OPTIONAL :: id_rho
+      INTEGER(i4),                  INTENT(IN   ), OPTIONAL :: id_iext
+      INTEGER(i4),                  INTENT(IN   ), OPTIONAL :: id_jext
+      INTEGER(i4),                  INTENT(IN   ), OPTIONAL :: id_kext
+      INTEGER(i4),                  INTENT(IN   ), OPTIONAL :: id_radius
+      INTEGER(i4),                  INTENT(IN   ), OPTIONAL :: id_maxiter
+
+      ! local variable
+      INTEGER(i4) :: il_iext
+      INTEGER(i4) :: il_jext
+      INTEGER(i4) :: il_kext
+      INTEGER(i4) :: il_radius
+      INTEGER(i4) :: il_maxiter
+
+      CHARACTER(LEN=lc) :: cl_method
+
+      ! loop indices
+      !----------------------------------------------------------------
+      IF( .NOT. ASSOCIATED(td_var%d_value) )THEN
+         CALL logger_error("EXTRAP FILL VALUE: no table of value "//&
+         &  "associted to variable "//TRIM(td_var%c_name) )
+      ELSE
+
+         SELECT CASE(TRIM(td_var%c_extrap(1)))
+            CASE('min_error')
+               cl_method='min_error'
+            CASE DEFAULT
+               cl_method='dist_weight'
+
+               !update variable structure
+               td_var%c_extrap(1)='dist_weight'
+         END SELECT
+
+         il_iext=im_minext
+         IF( PRESENT(id_iext) ) il_iext=id_iext
+         il_jext=im_minext
+         IF( PRESENT(id_jext) ) il_jext=id_jext
+         il_kext=0
+         IF( PRESENT(id_kext) ) il_kext=id_kext
+
+         IF( TRIM(td_var%c_interp(1)) == 'cubic')THEN
+            IF( il_iext > 0 .AND. il_iext < im_mincubic ) il_iext=im_mincubic
+            IF( il_jext > 0 .AND. il_jext < im_mincubic ) il_jext=im_mincubic
+         ENDIF
+
+         IF( il_iext < 0 )THEN
+            CALL logger_error("EXTRAP FILL VALUE: invalid "//&
+            &  " number of points to be extrapolated in i-direction "//&
+            &  "("//TRIM(fct_str(il_iext))//")")
+         ENDIF
+
+         IF( il_jext < 0 )THEN
+            CALL logger_error("EXTRAP FILL VALUE: invalid "//&
+            &  " number of points to be extrapolated in j-direction "//&
+            &  "("//TRIM(fct_str(il_jext))//")")
+         ENDIF
+
+         IF( il_kext < 0 )THEN
+            CALL logger_error("EXTRAP FILL VALUE: invalid "//&
+            &  " number of points to be extrapolated in k-direction "//&
+            &  "("//TRIM(fct_str(il_kext))//")")
+         ENDIF
+
+         IF( (il_iext /= 0 .AND. td_var%t_dim(1)%l_use) .OR. &
+         &   (il_jext /= 0 .AND. td_var%t_dim(2)%l_use) .OR. &
+         &   (il_kext /= 0 .AND. td_var%t_dim(3)%l_use) .OR. &
+         &   PRESENT(td_level) )THEN
+
+            ! number of point use to compute box
+            il_radius=1
+            IF( PRESENT(id_radius) ) il_radius=id_radius
+            IF( il_radius < 0 )THEN
+               CALL logger_error("EXTRAP FILL VALUE: invalid "//&
+               &  " radius of the box used to compute extrapolation "//&
+               &  "("//TRIM(fct_str(il_radius))//")")
+            ENDIF
+
+            ! maximum number of iteration
+            il_maxiter=im_maxiter
+            IF( PRESENT(id_maxiter) ) il_maxiter=id_maxiter
+            IF( il_maxiter < 0 )THEN
+               CALL logger_error("EXTRAP FILL VALUE: invalid "//&
+               &  " maximum nuber of iteration "//&
+               &  "("//TRIM(fct_str(il_maxiter))//")")
+            ENDIF
+
+            CALL logger_info("EXTRAP FILL: extrapolate "//TRIM(td_var%c_name)//&
+            &  " using "//TRIM(cl_method)//" method." )
+
+            CALL extrap__fill_value( td_var, cl_method, &
+            &                        il_iext, il_jext, il_kext,   &
+            &                        il_radius, il_maxiter,       &
+            &                        td_level,                    &
+            &                        id_offset, id_rho )
+ 
+         ENDIF
+ 
+      ENDIF
+
+   END SUBROUTINE extrap__fill_value_wrapper
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] cd_method : extrapolation method
+   !> @param[in] id_iext : number of points to be extrapolated in i-direction
+   !> @param[in] id_jext : number of points to be extrapolated in j-direction
+   !> @param[in] id_kext : number of points to be extrapolated in k-direction
+   !> @param[in] id_radius : radius of the halo used to compute extrapolation
+   !> @param[in] id_maxiter : maximum nuber of iteration
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE extrap__fill_value( td_var, cd_method, &
+   &                              id_iext, id_jext, id_kext, &
+   &                              id_radius, id_maxiter, &
+   &                              td_level,          &
+   &                              id_offset,         &
+   &                              id_rho )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR)      ,                 INTENT(INOUT) :: td_var
+      CHARACTER(LEN=*),                 INTENT(IN   ) :: cd_method
+      INTEGER(i4)     ,                 INTENT(IN   ) :: id_iext
+      INTEGER(i4)     ,                 INTENT(IN   ) :: id_jext
+      INTEGER(i4)     ,                 INTENT(IN   ) :: id_kext
+      INTEGER(i4)     ,                 INTENT(IN   ) :: id_radius
+      INTEGER(i4)     ,                 INTENT(IN   ) :: id_maxiter
+      TYPE(TVAR)      , DIMENSION(:)  , INTENT(IN   ), OPTIONAL :: td_level
+      INTEGER(i4)     , DIMENSION(:,:), INTENT(IN   ), OPTIONAL :: id_offset
+      INTEGER(i4)     , DIMENSION(:)  , INTENT(IN   ), OPTIONAL :: id_rho
+
+      ! local variable
+      CHARACTER(LEN=lc)                            :: cl_extrap
+
+      INTEGER(i4), DIMENSION(:,:,:)  , ALLOCATABLE :: il_detect
+      INTEGER(i4)                                  :: il_radius
+      INTEGER(i4)                                  :: il_iter
+
+      TYPE(TATT)                                   :: tl_att
+
+      ! loop indices
+      INTEGER(i4) :: jl
+      !----------------------------------------------------------------
+
+      !1- detect point to be extrapolated
+      ALLOCATE( il_detect( td_var%t_dim(1)%i_len, &
+      &                    td_var%t_dim(2)%i_len, &
+      &                    td_var%t_dim(3)%i_len) )
+
+      il_detect(:,:,:) = extrap_detect( td_var, td_level, &
+      &                                 id_offset,        &
+      &                                 id_rho,           &
+      &                                 id_ext=(/id_iext, id_jext, id_kext/) )
+
+      !2- add attribute to variable
+      cl_extrap=fct_concat(td_var%c_extrap(:))
+      tl_att=att_init('extrapolation',cl_extrap)
+      CALL var_move_att(td_var, tl_att)
+
+      CALL logger_warn(" EXTRAP FILL: "//&
+         &              TRIM(fct_str(SUM(il_detect(:,:,:))))//&
+         &              " point(s) to extrapolate " )
+
+      !3- extrapolate
+      DO jl=1,td_var%t_dim(4)%i_len
+        
+!            td_var%d_value(:,:,:,jl)=il_detect(:,:,:)
+         il_iter=1
+         DO WHILE( ANY(il_detect(:,:,:)==1) )
+            ! change extend value to minimize number of iteration
+            il_radius=id_radius+(il_iter/id_maxiter)
+            
+            CALL logger_debug(" EXTRAP FILL VALUE: "//&
+            &              TRIM(fct_str(SUM(il_detect(:,:,:))))//&
+            &              " points to extrapolate " )
+            
+            CALL extrap__3D(td_var%d_value(:,:,:,jl), td_var%d_fill,    &
+            &               il_detect(:,:,:),                           &
+            &               cd_method, il_radius )
+               
+            il_iter=il_iter+1
+         ENDDO
+
+      ENDDO
+ 
+      IF( SUM(il_detect(:,:,:)) /= 0 )THEN
+         CALL logger_warn(" EXTRAP FILL: still "//&
+         &              TRIM(fct_str(SUM(il_detect(:,:,:))))//&
+         &              " point(s) to extrapolate " )
+      ENDIF
+
+      DEALLOCATE(il_detect)
+
+   END SUBROUTINE extrap__fill_value
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] dd_value : 3D table of variable to be extrapolated
+   !> @param[in] dd_fill : FillValue of variable
+   !> @param[inout] id_detect : table of point to extrapolate
+   !> @param[in] id_ext : number of point use to compute box 
+   !> @param[in] cd_method : extrapolation method
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE extrap__3D( dd_value, dd_fill, id_detect,&
+   &                      cd_method, id_ext )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)   , DIMENSION(:,:,:), INTENT(INOUT) :: dd_value
+      REAL(dp)   ,                   INTENT(IN   ) :: dd_fill
+      INTEGER(i4), DIMENSION(:,:,:), INTENT(INOUT) :: id_detect
+      CHARACTER(LEN=*),              INTENT(IN   ) :: cd_method
+      INTEGER(i4),                   INTENT(IN   ) :: id_ext
+
+      ! local variable
+      INTEGER(i4) :: il_imin
+      INTEGER(i4) :: il_imax
+      INTEGER(i4) :: il_jmin
+      INTEGER(i4) :: il_jmax
+      INTEGER(i4) :: il_kmin
+      INTEGER(i4) :: il_kmax
+
+      INTEGER(i4), DIMENSION(3) :: il_shape
+      INTEGER(i4), DIMENSION(3) :: il_dim
+
+      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_dfdx
+      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_dfdy
+      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_dfdz
+      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_coef
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      il_shape(:)=SHAPE(dd_value)
+
+      SELECT CASE(TRIM(cd_method))
+         CASE('min_error')
+
+            ALLOCATE( dl_dfdx(il_shape(1), il_shape(2), il_shape(3)) ) 
+            ALLOCATE( dl_dfdy(il_shape(1), il_shape(2), il_shape(3)) ) 
+            ALLOCATE( dl_dfdz(il_shape(1), il_shape(2), il_shape(3)) ) 
+
+
+            ! compute derivative in i-direction
+            dl_dfdx(:,:,:)=dd_fill
+            IF( il_shape(1) > 1 )THEN
+               dl_dfdx(:,:,:)=extrap_deriv_3D( dd_value(:,:,:), dd_fill, 'I' )
+            ENDIF
+
+            ! compute derivative in i-direction
+            dl_dfdy(:,:,:)=dd_fill
+            IF( il_shape(2) > 1 )THEN
+               dl_dfdy(:,:,:)=extrap_deriv_3D( dd_value(:,:,:), dd_fill, 'J' )
+            ENDIF
+               
+            ! compute derivative in i-direction
+            dl_dfdz(:,:,:)=dd_fill
+            IF( il_shape(3) > 1 )THEN
+               dl_dfdz(:,:,:)=extrap_deriv_3D( dd_value(:,:,:), dd_fill, 'K' )
+            ENDIF
+      
+            il_dim(1)=2*id_ext+1
+            IF( il_shape(1) < 2*id_ext+1 ) il_dim(1)=1
+            il_dim(2)=2*id_ext+1
+            IF( il_shape(2) < 2*id_ext+1 ) il_dim(2)=1
+            il_dim(3)=2*id_ext+1
+            IF( il_shape(3) < 2*id_ext+1 ) il_dim(3)=1
+
+            ALLOCATE( dl_coef(il_dim(1), il_dim(2), il_dim(3)) ) 
+
+            dl_coef(:,:,:)=extrap__3D_min_error_coef(dd_value( 1:il_dim(1), &
+            &                                                  1:il_dim(2), &
+            &                                                  1:il_dim(3)))
+
+            DO jk=1,il_shape(3)
+               IF( ALL(id_detect(:,:,jk) == 0) ) CYCLE
+               DO jj=1,il_shape(2)
+                  IF( ALL(id_detect(:,jj,jk) == 0) ) CYCLE
+                  DO ji=1,il_shape(1)
+
+                     IF( id_detect(ji,jj,jk) == 1 )THEN
+                       
+                        il_imin=MAX(ji-id_ext,1)
+                        il_imax=MIN(ji+id_ext,il_shape(1))
+                        IF( il_dim(1) == 1 )THEN
+                           il_imin=ji
+                           il_imax=ji
+                        ENDIF
+
+                        il_jmin=MAX(jj-id_ext,1)
+                        il_jmax=MIN(jj+id_ext,il_shape(2))
+                        IF( il_dim(2) == 1 )THEN
+                           il_jmin=jj
+                           il_jmax=jj
+                        ENDIF
+
+                        il_kmin=MAX(jk-id_ext,1)
+                        il_kmax=MIN(jk+id_ext,il_shape(3))
+                        IF( il_dim(3) == 1 )THEN
+                           il_kmin=jk
+                           il_kmax=jk
+                        ENDIF
+
+                        dd_value(ji,jj,jk)=extrap__3D_min_error_fill( &
+                        &  dd_value( il_imin:il_imax, &
+                        &            il_jmin:il_jmax, &
+                        &            il_kmin:il_kmax ), dd_fill, id_ext, &
+                        &  dl_dfdx(  il_imin:il_imax, &
+                        &            il_jmin:il_jmax, &
+                        &            il_kmin:il_kmax ), &
+                        &  dl_dfdy(  il_imin:il_imax, &
+                        &            il_jmin:il_jmax, &
+                        &            il_kmin:il_kmax ), &
+                        &  dl_dfdz(  il_imin:il_imax, &
+                        &            il_jmin:il_jmax, &
+                        &            il_kmin:il_kmax ), &
+                        &  dl_coef(:,:,:) )
+
+                        IF( dd_value(ji,jj,jk) /= dd_fill )THEN
+                           id_detect(ji,jj,jk)= 0
+                        ENDIF
+
+                     ENDIF
+
+                  ENDDO
+               ENDDO
+            ENDDO
+
+            IF( ALLOCATED(dl_dfdx) ) DEALLOCATE( dl_dfdx )
+            IF( ALLOCATED(dl_dfdy) ) DEALLOCATE( dl_dfdy )
+            IF( ALLOCATED(dl_dfdz) ) DEALLOCATE( dl_dfdz )
+            IF( ALLOCATED(dl_coef) ) DEALLOCATE( dl_coef )
+
+         CASE DEFAULT ! 'dist_weight'
+
+            il_dim(1)=2*id_ext+1
+            IF( il_shape(1) < 2*id_ext+1 ) il_dim(1)=1
+            il_dim(2)=2*id_ext+1
+            IF( il_shape(2) < 2*id_ext+1 ) il_dim(2)=1
+            il_dim(3)=2*id_ext+1
+            IF( il_shape(3) < 2*id_ext+1 ) il_dim(3)=1
+            
+            ALLOCATE( dl_coef(il_dim(1), il_dim(2), il_dim(3)) )
+
+            dl_coef(:,:,:)=extrap__3D_dist_weight_coef(dd_value(1:il_dim(1), &
+            &                                                   1:il_dim(2), &
+            &                                                   1:il_dim(3)) )
+
+            DO jk=1,il_shape(3)
+               IF( ALL(id_detect(:,:,jk) == 0) ) CYCLE
+               DO jj=1,il_shape(2)
+                  IF( ALL(id_detect(:,jj,jk) == 0) ) CYCLE
+                  DO ji=1,il_shape(1)
+
+                     IF( id_detect(ji,jj,jk) == 1 )THEN
+                        
+                        il_imin=MAX(ji-id_ext,1)
+                        il_imax=MIN(ji+id_ext,il_shape(1))
+                        IF( il_dim(1) == 1 )THEN
+                           il_imin=ji
+                           il_imax=ji
+                        ENDIF
+
+                        il_jmin=MAX(jj-id_ext,1)
+                        il_jmax=MIN(jj+id_ext,il_shape(2))
+                        IF( il_dim(2) == 1 )THEN
+                           il_jmin=jj
+                           il_jmax=jj
+                        ENDIF
+
+                        il_kmin=MAX(jk-id_ext,1)
+                        il_kmax=MIN(jk+id_ext,il_shape(3))
+                        IF( il_dim(3) == 1 )THEN
+                           il_kmin=jk
+                           il_kmax=jk
+                        ENDIF
+
+                        dd_value(ji,jj,jk)=extrap__3D_dist_weight_fill( &
+                        &  dd_value( il_imin:il_imax, &
+                        &            il_jmin:il_jmax, &
+                        &            il_kmin:il_kmax ), dd_fill, id_ext, &
+                        &  dl_coef(:,:,:) )
+
+                        IF( dd_value(ji,jj,jk) /= dd_fill )THEN
+                           id_detect(ji,jj,jk)= 0
+                        ENDIF
+
+                     ENDIF
+
+                  ENDDO
+               ENDDO
+            ENDDO
+
+            IF( ALLOCATED(dl_coef) ) DEALLOCATE( dl_coef )
+            
+      END SELECT
+
+   END SUBROUTINE extrap__3D
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function compute derivative of a function in i- and
+   !> j-direction
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_value : 1D table of variable to be extrapolated
+   !> @param[in] dd_fill : FillValue of variable
+   !> @param[in] cd_dim : compute derivative on first (I) or second (J) dimension 
+   !-------------------------------------------------------------------
+   !> @code
+   PURE FUNCTION extrap_deriv_1D( dd_value, dd_fill, ld_discont )
+
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)   , DIMENSION(:), INTENT(IN) :: dd_value
+      REAL(dp)                 , INTENT(IN) :: dd_fill
+      LOGICAL                  , INTENT(IN), OPTIONAL :: ld_discont
+
+      ! function
+      REAL(dp), DIMENSION(SIZE(dd_value,DIM=1) ) :: extrap_deriv_1D
+
+      ! local variable
+      INTEGER(i4)                            :: il_imin
+      INTEGER(i4)                            :: il_imax
+      INTEGER(i4), DIMENSION(1)              :: il_shape
+
+      REAL(dp)                               :: dl_min
+      REAL(dp)                               :: dl_max
+      REAL(dp)   , DIMENSION(:), ALLOCATABLE :: dl_value
+
+      LOGICAL                                :: ll_discont
+
+      ! loop indices
+      INTEGER(i4) :: ji
+
+      INTEGER(i4) :: i1
+      INTEGER(i4) :: i2
+      !----------------------------------------------------------------
+      ! init
+      extrap_deriv_1D(:)=dd_fill
+
+      ll_discont=.FALSE.
+      IF( PRESENT(ld_discont) ) ll_discont=ld_discont
+
+      il_shape(:)=SHAPE(dd_value(:))
+
+      ALLOCATE( dl_value(3))
+
+      ! compute derivative in i-direction
+      DO ji=1,il_shape(1)
+         
+            il_imin=MAX(ji-1,1)
+            il_imax=MIN(ji+1,il_shape(1))
+
+            IF( il_imin==ji-1 .AND. il_imax==ji+1 )THEN
+               i1=1  ; i2=3
+            ELSEIF( il_imin==ji .AND. il_imax==ji+1 )THEN
+               i1=1  ; i2=2
+            ELSEIF( il_imin==ji-1 .AND. il_imax==ji )THEN
+               i1=2  ; i2=3
+            ENDIF
+
+            dl_value(i1:i2)=dd_value(il_imin:il_imax)
+            IF( il_imin == 1 )THEN
+               dl_value(:)=EOSHIFT( dl_value(:), &
+               &                    DIM=1,         &
+               &                    SHIFT=-1,      &
+               &                    BOUNDARY=dl_value(1) )
+            ENDIF
+            IF( il_imax == il_shape(1) )THEN
+               dl_value(:)=EOSHIFT( dl_value(:), &
+               &                    DIM=1,         &
+               &                    SHIFT=1,       &
+               &                    BOUNDARY=dl_value(3))
+            ENDIF
+
+            IF( ll_discont )THEN
+               dl_min=MINVAL( dl_value(:), dl_value(:)/=dd_fill )
+               dl_max=MAXVAL( dl_value(:), dl_value(:)/=dd_fill )
+               IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN
+                  WHERE( dl_value(:) < 0._dp ) 
+                     dl_value(:) = dl_value(:)+360._dp
+                  END WHERE
+               ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN
+                  WHERE( dl_value(:) > 180._dp ) 
+                     dl_value(:) = dl_value(:)-180._dp
+                  END WHERE
+               ENDIF
+            ENDIF
+
+         IF( dl_value( 2) /= dd_fill .AND. & ! ji
+         &   dl_value( 3) /= dd_fill .AND. & ! ji+1
+         &   dl_value( 1) /= dd_fill )THEN   ! ji-1
+
+            extrap_deriv_1D(ji)=&
+            &  ( dl_value(3) - dl_value(1) ) / &
+            &  REAL( il_imax-il_imin ,dp)
+
+         ENDIF
+
+      ENDDO
+
+      DEALLOCATE( dl_value )
+
+   END FUNCTION extrap_deriv_1D
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function compute derivative of a function in i- and
+   !> j-direction
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_value : 2D table of variable to be extrapolated
+   !> @param[in] dd_fill : FillValue of variable
+   !> @param[in] cd_dim : compute derivative on first (I) or second (J) dimension 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION extrap_deriv_2D( dd_value, dd_fill, cd_dim, ld_discont )
+
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)   , DIMENSION(:,:), INTENT(IN) :: dd_value
+      REAL(dp)                   , INTENT(IN) :: dd_fill
+      CHARACTER(LEN=*)           , INTENT(IN) :: cd_dim
+      LOGICAL                    , INTENT(IN), OPTIONAL :: ld_discont
+
+      ! function
+      REAL(dp), DIMENSION(SIZE(dd_value,DIM=1), &
+      &                   SIZE(dd_value,DIM=2) ) :: extrap_deriv_2D
+
+      ! local variable
+      INTEGER(i4)                              :: il_imin
+      INTEGER(i4)                              :: il_imax
+      INTEGER(i4)                              :: il_jmin
+      INTEGER(i4)                              :: il_jmax
+      INTEGER(i4), DIMENSION(2)                :: il_shape
+
+      REAL(dp)                                 :: dl_min
+      REAL(dp)                                 :: dl_max
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_value
+
+      LOGICAL                                  :: ll_discont
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+
+      INTEGER(i4) :: i1
+      INTEGER(i4) :: i2
+
+      INTEGER(i4) :: j1
+      INTEGER(i4) :: j2
+      !----------------------------------------------------------------
+      ! init
+      extrap_deriv_2D(:,:)=dd_fill
+
+      ll_discont=.FALSE.
+      IF( PRESENT(ld_discont) ) ll_discont=ld_discont
+
+      il_shape(:)=SHAPE(dd_value(:,:))
+
+      SELECT CASE(TRIM(fct_upper(cd_dim)))
+
+      CASE('I')
+
+         ALLOCATE( dl_value(3,il_shape(2)) )
+         ! compute derivative in i-direction
+         DO ji=1,il_shape(1)
+
+            ! init
+            dl_value(:,:)=dd_fill
+            
+            il_imin=MAX(ji-1,1)
+            il_imax=MIN(ji+1,il_shape(1))
+
+            IF( il_imin==ji-1 .AND. il_imax==ji+1 )THEN
+               i1=1  ; i2=3
+            ELSEIF( il_imin==ji .AND. il_imax==ji+1 )THEN
+               i1=1  ; i2=2
+            ELSEIF( il_imin==ji-1 .AND. il_imax==ji )THEN
+               i1=2  ; i2=3
+            ENDIF
+
+            dl_value(i1:i2,:)=dd_value(il_imin:il_imax,:)
+            IF( il_imin == 1 )THEN
+               dl_value(:,:)=EOSHIFT( dl_value(:,:), &
+               &                      DIM=1,         &
+               &                      SHIFT=-1,      &
+               &                      BOUNDARY=dl_value(1,:) )
+            ENDIF
+            IF( il_imax == il_shape(1) )THEN
+               dl_value(:,:)=EOSHIFT( dl_value(:,:), &
+               &                      DIM=1,         &
+               &                      SHIFT=1,       &
+               &                      BOUNDARY=dl_value(3,:))
+            ENDIF
+
+            IF( ll_discont )THEN
+               dl_min=MINVAL( dl_value(:,:), dl_value(:,:)/=dd_fill )
+               dl_max=MAXVAL( dl_value(:,:), dl_value(:,:)/=dd_fill )
+               IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN
+                  WHERE( dl_value(:,:) < 0_dp ) 
+                     dl_value(:,:) = dl_value(:,:)+360._dp
+                  END WHERE
+               ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN
+                  WHERE( dl_value(:,:) > 180 ) 
+                     dl_value(:,:) = dl_value(:,:)-180._dp
+                  END WHERE
+               ENDIF
+            ENDIF
+            
+            WHERE( dl_value(2,:) /= dd_fill .AND. &  ! ji
+            &      dl_value(3,:) /= dd_fill .AND. &  ! ji+1
+            &      dl_value(1,:) /= dd_fill )        ! ji-1
+
+               extrap_deriv_2D(ji,:)=&
+               &  ( dl_value(3,:) - dl_value(1,:) ) / &
+               &    REAL( il_imax-il_imin,dp)
+
+            END WHERE
+
+      ENDDO
+
+      CASE('J')
+
+         ALLOCATE( dl_value(il_shape(1),3) )
+         ! compute derivative in j-direction
+         DO jj=1,il_shape(2)
+         
+            il_jmin=MAX(jj-1,1)
+            il_jmax=MIN(jj+1,il_shape(2))
+
+            IF( il_jmin==jj-1 .AND. il_jmax==jj+1 )THEN
+               j1=1  ; j2=3
+            ELSEIF( il_jmin==jj .AND. il_jmax==jj+1 )THEN
+               j1=1  ; j2=2
+            ELSEIF( il_jmin==jj-1 .AND. il_jmax==jj )THEN
+               j1=2  ; j2=3
+            ENDIF
+
+            dl_value(:,j1:j2)=dd_value(:,il_jmin:il_jmax)
+            IF( il_jmin == 1 )THEN
+               dl_value(:,:)=EOSHIFT( dl_value(:,:), &
+               &                      DIM=2,         &
+               &                      SHIFT=-1,      &
+               &                      BOUNDARY=dl_value(:,1))
+            ENDIF
+            IF( il_jmax == il_shape(2) )THEN
+               dl_value(:,:)=EOSHIFT( dl_value(:,:), &
+               &                      DIM=2,         &
+               &                      SHIFT=1,       &
+               &                      BOUNDARY=dl_value(:,3))
+            ENDIF
+
+            IF( ll_discont )THEN
+               dl_min=MINVAL( dl_value(:,:), dl_value(:,:)/=dd_fill )
+               dl_max=MAXVAL( dl_value(:,:), dl_value(:,:)/=dd_fill )
+               IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN
+                  WHERE( dl_value(:,:) < 0_dp ) 
+                     dl_value(:,:) = dl_value(:,:)+360._dp
+                  END WHERE
+               ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN
+                  WHERE( dl_value(:,:) > 180 ) 
+                     dl_value(:,:) = dl_value(:,:)-180._dp
+                  END WHERE
+               ENDIF
+            ENDIF
+
+            WHERE( dl_value(:, 2) /= dd_fill .AND. & ! jj
+            &      dl_value(:, 3) /= dd_fill .AND. & ! jj+1
+            &      dl_value(:, 1) /= dd_fill )       ! jj-1
+
+               extrap_deriv_2D(:,jj)=&
+               &  ( dl_value(:,3) - dl_value(:,1) ) / &
+               &   REAL(il_jmax-il_jmin,dp)         
+
+            END WHERE
+
+         ENDDO
+         
+      END SELECT
+
+      DEALLOCATE( dl_value )
+
+   END FUNCTION extrap_deriv_2D
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function compute derivative of a function in i- and
+   !> j-direction
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] dd_value : 3D table of variable to be extrapolated
+   !> @param[in] dd_fill : FillValue of variable
+   !> @param[in] cd_dim : compute derivative on first (I) second (J) or third (K) dimension   
+   !-------------------------------------------------------------------
+   !> @code
+   PURE FUNCTION extrap_deriv_3D( dd_value, dd_fill, cd_dim, ld_discont )
+
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)        , DIMENSION(:,:,:), INTENT(IN) :: dd_value
+      REAL(dp)                          , INTENT(IN) :: dd_fill
+      CHARACTER(LEN=*)                  , INTENT(IN) :: cd_dim
+      LOGICAL                           , INTENT(IN), OPTIONAL :: ld_discont
+
+      ! function
+      REAL(dp), DIMENSION(SIZE(dd_value,DIM=1), &
+      &                   SIZE(dd_value,DIM=2), &
+      &                   SIZE(dd_value,DIM=3)) :: extrap_deriv_3D
+
+      ! local variable
+      INTEGER(i4)                                :: il_imin
+      INTEGER(i4)                                :: il_imax
+      INTEGER(i4)                                :: il_jmin
+      INTEGER(i4)                                :: il_jmax
+      INTEGER(i4)                                :: il_kmin
+      INTEGER(i4)                                :: il_kmax
+      INTEGER(i4), DIMENSION(3)                  :: il_shape
+
+      REAL(dp)                                   :: dl_min
+      REAL(dp)                                   :: dl_max
+      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_value
+
+      LOGICAL                                    :: ll_discont
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jk
+
+      INTEGER(i4) :: i1
+      INTEGER(i4) :: i2
+
+      INTEGER(i4) :: j1
+      INTEGER(i4) :: j2
+      
+      INTEGER(i4) :: k1
+      INTEGER(i4) :: k2      
+      !----------------------------------------------------------------
+      ! init
+      extrap_deriv_3D(:,:,:)=dd_fill
+
+      ll_discont=.FALSE.
+      IF( PRESENT(ld_discont) ) ll_discont=ld_discont
+
+      il_shape(:)=SHAPE(dd_value(:,:,:))
+
+
+      SELECT CASE(TRIM(fct_upper(cd_dim)))
+
+      CASE('I')
+
+         ALLOCATE( dl_value(3,il_shape(2),il_shape(3)) )
+         ! compute derivative in i-direction
+         DO ji=1,il_shape(1)
+            
+            il_imin=MAX(ji-1,1)
+            il_imax=MIN(ji+1,il_shape(1))
+
+            IF( il_imin==ji-1 .AND. il_imax==ji+1 )THEN
+               i1=1  ; i2=3
+            ELSEIF( il_imin==ji .AND. il_imax==ji+1 )THEN
+               i1=1  ; i2=2
+            ELSEIF( il_imin==ji-1 .AND. il_imax==ji )THEN
+               i1=2  ; i2=3
+            ENDIF
+
+            dl_value(i1:i2,:,:)=dd_value(il_imin:il_imax,:,:)
+            IF( il_imin == 1 )THEN
+               dl_value(:,:,:)=EOSHIFT( dl_value(:,:,:), &
+               &                      DIM=1,         &
+               &                      SHIFT=-1,      &
+               &                      BOUNDARY=dl_value(1,:,:) )
+            ENDIF
+            IF( il_imax == il_shape(1) )THEN
+               dl_value(:,:,:)=EOSHIFT( dl_value(:,:,:), &
+               &                      DIM=1,         &
+               &                      SHIFT=1,       &
+               &                      BOUNDARY=dl_value(3,:,:))
+            ENDIF
+
+            IF( ll_discont )THEN
+               dl_min=MINVAL( dl_value(:,:,:), dl_value(:,:,:)/=dd_fill )
+               dl_max=MAXVAL( dl_value(:,:,:), dl_value(:,:,:)/=dd_fill )
+               IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN
+                  WHERE( dl_value(:,:,:) < 0_dp ) 
+                     dl_value(:,:,:) = dl_value(:,:,:)+360._dp
+                  END WHERE
+               ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN
+                  WHERE( dl_value(:,:,:) > 180 ) 
+                     dl_value(:,:,:) = dl_value(:,:,:)-180._dp
+                  END WHERE
+               ENDIF
+            ENDIF
+
+            WHERE( dl_value(2,:,:) /= dd_fill .AND. & ! ji
+            &      dl_value(3,:,:) /= dd_fill .AND. & !ji+1 
+            &      dl_value(1,:,:) /= dd_fill )       !ji-1
+
+               extrap_deriv_3D(ji,:,:)= &
+               &  ( dl_value(3,:,:) - dl_value(1,:,:) ) / &
+               &  REAL( il_imax-il_imin ,dp)
+
+            END WHERE
+
+         ENDDO
+
+      CASE('J')
+
+         ALLOCATE( dl_value(il_shape(1),3,il_shape(3)) )
+         ! compute derivative in j-direction
+         DO jj=1,il_shape(2)
+         
+            il_jmin=MAX(jj-1,1)
+            il_jmax=MIN(jj+1,il_shape(2))
+
+            IF( il_jmin==jj-1 .AND. il_jmax==jj+1 )THEN
+               j1=1  ; j2=3
+            ELSEIF( il_jmin==jj .AND. il_jmax==jj+1 )THEN
+               j1=1  ; j2=2
+            ELSEIF( il_jmin==jj-1 .AND. il_jmax==jj )THEN
+               j1=2  ; j2=3
+            ENDIF
+
+            dl_value(:,j1:j2,:)=dd_value(:,il_jmin:il_jmax,:)
+            IF( il_jmin == 1 )THEN
+               dl_value(:,:,:)=EOSHIFT( dl_value(:,:,:), &
+               &                      DIM=2,         &
+               &                      SHIFT=-1,      &
+               &                      BOUNDARY=dl_value(:,1,:) )
+            ENDIF
+            IF( il_jmax == il_shape(2) )THEN
+               dl_value(:,:,:)=EOSHIFT( dl_value(:,:,:), &
+               &                      DIM=2,         &
+               &                      SHIFT=1,       &
+               &                      BOUNDARY=dl_value(:,3,:))
+            ENDIF
+
+            IF( ll_discont )THEN
+               dl_min=MINVAL( dl_value(:,:,:), dl_value(:,:,:)/=dd_fill )
+               dl_max=MAXVAL( dl_value(:,:,:), dl_value(:,:,:)/=dd_fill )
+               IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN
+                  WHERE( dl_value(:,:,:) < 0_dp ) 
+                     dl_value(:,:,:) = dl_value(:,:,:)+360._dp
+                  END WHERE
+               ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN
+                  WHERE( dl_value(:,:,:) > 180 ) 
+                     dl_value(:,:,:) = dl_value(:,:,:)-180._dp
+                  END WHERE
+               ENDIF
+            ENDIF
+
+            WHERE( dl_value(:, 2,:) /= dd_fill .AND. & ! jj
+               &   dl_value(:, 3,:) /= dd_fill .AND. & ! jj+1
+            &      dl_value(:, 1,:) /= dd_fill )       ! jj-1
+
+               extrap_deriv_3D(:,jj,:)=&
+               &  ( dl_value(:,3,:) - dl_value(:,1,:) ) / &
+               &  REAL( il_jmax - il_jmin ,dp)         
+
+            END WHERE
+
+         ENDDO
+         
+      CASE('K')
+         ! compute derivative in k-direction
+         DO jk=1,il_shape(3)
+
+            il_kmin=MAX(jk-1,1)
+            il_kmax=MIN(jk+1,il_shape(3))
+
+            IF( il_kmin==jk-1 .AND. il_kmax==jk+1 )THEN
+               k1=1  ; k2=3
+            ELSEIF( il_kmin==jk .AND. il_kmax==jk+1 )THEN
+               k1=1  ; k2=2
+            ELSEIF( il_kmin==jk-1 .AND. il_kmax==jk )THEN
+               k1=2  ; k2=3
+            ENDIF
+
+            dl_value(:,:,k1:k2)=dd_value(:,:,il_kmin:il_kmax)
+            IF( il_kmin == 1 )THEN
+               dl_value(:,:,:)=EOSHIFT( dl_value(:,:,:), &
+               &                      DIM=3,         &
+               &                      SHIFT=-1,      &
+               &                      BOUNDARY=dl_value(:,:,1) )
+            ENDIF
+            IF( il_kmax == il_shape(3) )THEN
+               dl_value(:,:,:)=EOSHIFT( dl_value(:,:,:), &
+               &                        DIM=3,         &
+               &                        SHIFT=1,       &
+               &                        BOUNDARY=dl_value(:,:,3))
+            ENDIF
+
+            IF( ll_discont )THEN
+               dl_min=MINVAL( dl_value(:,:,:), dl_value(:,:,:)/=dd_fill )
+               dl_max=MAXVAL( dl_value(:,:,:), dl_value(:,:,:)/=dd_fill )
+               IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN
+                  WHERE( dl_value(:,:,:) < 0_dp ) 
+                     dl_value(:,:,:) = dl_value(:,:,:)+360._dp
+                  END WHERE
+               ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN
+                  WHERE( dl_value(:,:,:) > 180 ) 
+                     dl_value(:,:,:) = dl_value(:,:,:)-180._dp
+                  END WHERE
+               ENDIF
+            ENDIF         
+
+            WHERE( dl_value(:,:, 2) /= dd_fill .AND. & ! jk
+               &   dl_value(:,:, 3) /= dd_fill .AND. & ! jk+1
+               &   dl_value(:,:, 1) /= dd_fill )       ! jk-1
+
+               extrap_deriv_3D(:,:,jk)=&
+               &  ( dl_value(:,:,3) - dl_value(:,:,1) ) / &
+               &  REAL( il_kmax-il_kmin,dp)         
+
+            END WHERE
+
+         ENDDO
+
+      END SELECT
+
+      DEALLOCATE( dl_value )
+
+   END FUNCTION extrap_deriv_3D
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function compute extrapolatd values by calculated minimum error using
+   !> taylor expansion
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_value : 3D table of variable to be extrapolated
+   !> @param[in] dd_fill : FillValue of variable
+   !> @param[in] dd_ideriv : derivative of function in i-direction
+   !> @param[in] dd_jderiv : derivative of function in j-direction
+   !> @param[in] dd_kderiv : derivative of function in k-direction
+   !> @param[in] id_ji  : i-direction indices table
+   !> @param[in] id_jj  : j-direction indices table 
+   !> @param[in] id_ii  : i-direction indices of the point to extrapolate 
+   !> @param[in] id_ij  : j-direction indices of the point to extrapolate
+   !-------------------------------------------------------------------
+   !> @code
+   PURE FUNCTION extrap__3D_min_error_coef( dd_value )
+
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)   , DIMENSION(:,:,:), INTENT(IN) :: dd_value
+
+      ! function
+      REAL(dp), DIMENSION(SIZE(dd_value(:,:,:),DIM=1), &
+      &                   SIZE(dd_value(:,:,:),DIM=2), &
+      &                   SIZE(dd_value(:,:,:),DIM=3) ) :: extrap__3D_min_error_coef
+
+      ! local variable
+      INTEGER(i4), DIMENSION(3) :: il_shape
+
+      INTEGER(i4) :: il_imid
+      INTEGER(i4) :: il_jmid
+      INTEGER(i4) :: il_kmid
+
+      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_dist
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      ! init
+      extrap__3D_min_error_coef(:,:,:)=0
+
+      il_shape(:)=SHAPE(dd_value(:,:,:))
+
+      il_imid=INT(REAL(il_shape(1),sp)*0.5+1)
+      il_jmid=INT(REAL(il_shape(2),sp)*0.5+1)
+      il_kmid=INT(REAL(il_shape(3),sp)*0.5+1)
+
+      ALLOCATE( dl_dist(il_shape(1),il_shape(2),il_shape(3)) )
+
+      DO jk=1,il_shape(3)
+         DO jj=1,il_shape(2)
+            DO ji=1,il_shape(1)
+
+               ! compute distance
+               dl_dist(ji,jj,jk) = (ji-il_imid)**2 + &
+               &                   (jj-il_jmid)**2 + &
+               &                   (jk-il_kmid)**2
+
+               IF( dl_dist(ji,jj,jk) /= 0 )THEN
+                  dl_dist(ji,jj,jk)=SQRT( dl_dist(ji,jj,jk) )
+               ENDIF
+
+            ENDDO
+         ENDDO
+      ENDDO
+
+      WHERE( dl_dist(:,:,:) /= 0 )
+         extrap__3D_min_error_coef(:,:,:)=dl_dist(:,:,:)
+      END WHERE
+
+      DEALLOCATE( dl_dist )
+
+   END FUNCTION extrap__3D_min_error_coef
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function compute extrapolatd values by calculated minimum error using
+   !> taylor expansion
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_value : 3D table of variable to be extrapolated
+   !> @param[in] dd_fill : FillValue of variable
+   !> @param[in] dd_dfdx : derivative of function in i-direction
+   !> @param[in] dd_dfdy : derivative of function in j-direction
+   !> @param[in] dd_dfdz : derivative of function in k-direction
+   !> @param[in] dd_coef : 
+   !-------------------------------------------------------------------
+   !> @code
+   PURE FUNCTION extrap__3D_min_error_fill( dd_value, dd_fill, id_ext, &
+   &                                        dd_dfdx, dd_dfdy, dd_dfdz, &
+   &                                        dd_coef )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)   , DIMENSION(:,:,:), INTENT(IN) :: dd_value
+      REAL(dp)   ,                   INTENT(IN) :: dd_fill
+      INTEGER(i4),                   INTENT(IN) :: id_ext
+      REAL(dp)   , DIMENSION(:,:,:), INTENT(IN) :: dd_dfdx
+      REAL(dp)   , DIMENSION(:,:,:), INTENT(IN) :: dd_dfdy
+      REAL(dp)   , DIMENSION(:,:,:), INTENT(IN) :: dd_dfdz
+      REAL(dp)   , DIMENSION(:,:,:), INTENT(IN) :: dd_coef
+
+      ! function
+      REAL(dp) :: extrap__3d_min_error_fill
+
+      ! local variable
+      INTEGER(i4), DIMENSION(3) :: il_shape
+      INTEGER(i4), DIMENSION(3) :: il_ind
+
+      INTEGER(i4), DIMENSION(:,:,:), ALLOCATABLE :: il_mask
+      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_error
+
+      INTEGER(i4) :: il_min
+      ! loop indices
+
+      !----------------------------------------------------------------
+
+      ! init
+      extrap__3D_min_error_fill=dd_fill
+
+      il_min=MAX(1,(SIZE(dd_value(:,:,:)))/(1+id_ext*2))
+
+      IF( COUNT(dd_value(:,:,:) /= dd_fill) >= il_min )THEN
+
+         il_shape(:)=SHAPE(dd_value(:,:,:))
+         ALLOCATE( il_mask( il_shape(1),il_shape(2),il_shape(3)) )
+         ALLOCATE( dl_error(il_shape(1),il_shape(2),il_shape(3)) )
+
+         ! compute error
+         dl_error(:,:,:)=0.
+         il_mask(:,:,:)=0
+         WHERE( dd_dfdx(:,:,:) /= dd_fill )
+            dl_error(:,:,:)=dd_coef(:,:,:)*dd_dfdx(:,:,:)
+            il_mask(:,:,:)=1
+         END WHERE
+         WHERE( dd_dfdy(:,:,:) /= dd_fill  )
+            dl_error(:,:,:)=(dl_error(:,:,:)+dd_coef(:,:,:)*dd_dfdy(:,:,:))
+            il_mask(:,:,:)=1
+         END WHERE
+         WHERE( dd_dfdz(:,:,:) /= dd_fill  )
+            dl_error(:,:,:)=(dl_error(:,:,:)+dd_coef(:,:,:)*dd_dfdz(:,:,:))
+            il_mask(:,:,:)=1
+         END WHERE
+
+         ! get minimum error indices
+         il_ind(:)=MINLOC(dl_error(:,:,:),il_mask(:,:,:)==1)
+
+         ! return value
+         IF( ALL(il_ind(:)/=0) )THEN
+            extrap__3D_min_error_fill=dd_value(il_ind(1),il_ind(2),il_ind(3))
+         ENDIF
+
+         DEALLOCATE( il_mask )
+         DEALLOCATE( dl_error )
+
+      ENDIF
+
+   END FUNCTION extrap__3D_min_error_fill
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function compute extrapolatd values by calculated minimum error using
+   !> taylor expansion
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_value : 3D table of variable to be extrapolated
+   !-------------------------------------------------------------------
+   !> @code
+   PURE FUNCTION extrap__3D_dist_weight_coef( dd_value )
+
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)   , DIMENSION(:,:,:), INTENT(IN) :: dd_value
+
+      ! function
+      REAL(dp), DIMENSION(SIZE(dd_value(:,:,:),DIM=1), &
+      &                   SIZE(dd_value(:,:,:),DIM=2), &
+      &                   SIZE(dd_value(:,:,:),DIM=3) ) :: extrap__3D_dist_weight_coef
+
+      ! local variable
+      INTEGER(i4), DIMENSION(3) :: il_shape
+
+      INTEGER(i4) :: il_imid
+      INTEGER(i4) :: il_jmid
+      INTEGER(i4) :: il_kmid
+
+      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_dist
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      ! init
+      extrap__3D_dist_weight_coef(:,:,:)=0
+
+      il_shape(:)=SHAPE(dd_value(:,:,:))
+
+      il_imid=INT(REAL(il_shape(1),sp)*0.5+1,i4)
+      il_jmid=INT(REAL(il_shape(2),sp)*0.5+1,i4)
+      il_kmid=INT(REAL(il_shape(3),sp)*0.5+1,i4)
+
+      ALLOCATE( dl_dist(il_shape(1),il_shape(2),il_shape(3)) )
+
+      DO jk=1,il_shape(3)
+         DO jj=1,il_shape(2)
+            DO ji=1,il_shape(1)
+
+               ! compute distance
+               dl_dist(ji,jj,jk) = (ji-il_imid)**2 + &
+               &                   (jj-il_jmid)**2 + &
+               &                   (jk-il_kmid)**2
+
+               IF( dl_dist(ji,jj,jk) /= 0 )THEN
+                  dl_dist(ji,jj,jk)=SQRT( dl_dist(ji,jj,jk) )
+               ENDIF
+
+            ENDDO
+         ENDDO
+      ENDDO
+
+      WHERE( dl_dist(:,:,:) /= 0 ) 
+         extrap__3D_dist_weight_coef(:,:,:)=1./dl_dist(:,:,:)
+      END WHERE
+
+      DEALLOCATE( dl_dist )
+
+   END FUNCTION extrap__3D_dist_weight_coef
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function compute extrapolatd values by calculated minimum error using
+   !> taylor expansion
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_value : 3D table of variable to be extrapolated
+   !> @param[in] dd_fill : FillValue of variable
+   !> @param[in] dd_coef :  
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION extrap__3D_dist_weight_fill( dd_value, dd_fill, id_ext, &
+   &                                          dd_coef )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)   , DIMENSION(:,:,:), INTENT(IN) :: dd_value
+      REAL(dp)   ,                   INTENT(IN) :: dd_fill
+      INTEGER(i4),                   INTENT(IN) :: id_ext
+      REAL(dp)   , DIMENSION(:,:,:), INTENT(IN) :: dd_coef
+
+      ! function
+      REAL(dp) :: extrap__3D_dist_weight_fill
+
+      ! local variable
+      INTEGER(i4), DIMENSION(3) :: il_shape
+
+      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_value
+      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_coef
+
+      INTEGER(i4) :: il_min
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jk
+
+      !----------------------------------------------------------------
+
+      ! init
+      extrap__3D_dist_weight_fill=dd_fill
+
+      il_min=MAX(1,(SIZE(dd_value(:,:,:)))/(1+id_ext*2))
+
+      IF( COUNT(dd_value(:,:,:)/= dd_fill) >= il_min )THEN
+
+         il_shape(:)=SHAPE(dd_value(:,:,:))
+         ALLOCATE( dl_value( il_shape(1),il_shape(2),il_shape(3)) )
+         ALLOCATE( dl_coef( il_shape(1),il_shape(2),il_shape(3)) )
+
+         dl_value(:,:,:)=0
+         dl_coef(:,:,:)=0
+
+         FORALL( ji=1:il_shape(1), &
+         &       jj=1:il_shape(2), &
+         &       jk=1:il_shape(3), &
+         &       dd_value(ji,jj,jk) /= dd_fill )
+
+            ! compute factor
+            dl_value(ji,jj,jk)=dd_coef(ji,jj,jk)*dd_value(ji,jj,jk)
+            dl_coef(ji,jj,jk)=dd_coef(ji,jj,jk)
+
+         END FORALL
+
+         ! return value
+         IF( SUM( dl_coef(:,:,:) ) /= 0 )THEN
+            extrap__3D_dist_weight_fill=SUM( dl_value(:,:,:) )/SUM( dl_coef(:,:,:) )
+         ENDIF
+
+         DEALLOCATE( dl_value )
+         DEALLOCATE( dl_coef )
+
+      ENDIF
+
+   END FUNCTION extrap__3D_dist_weight_fill
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine add to the variable (to be extrapolated) an 
+   !> extraband of N points at north,south,east and west boundaries.
+   !> 
+   !> @author J.Paul
+   !> - 2013-Initial version
+   !
+   !> @param[inout] td_var : variable 
+   !> @param[in] id_isize : i-direction size of extra bands (default=im_minext)
+   !> @param[in] id_jsize : j-direction size of extra bands (default=im_minext)
+   !> @todo
+   !> - invalid special case for grid with north fold
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE extrap_add_extrabands(td_var, id_isize, id_jsize )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(INOUT)  :: td_var
+      INTEGER(i4), INTENT(IN   ), OPTIONAL :: id_isize
+      INTEGER(i4), INTENT(IN   ), OPTIONAL :: id_jsize
+
+      ! local variable
+      REAL(dp), DIMENSION(:,:,:,:) , ALLOCATABLE :: dl_value
+
+      INTEGER(i4) :: il_isize
+      INTEGER(i4) :: il_jsize
+      INTEGER(i4) :: il_tmp
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: ij
+      !----------------------------------------------------------------
+      il_isize=im_minext
+      IF(PRESENT(id_isize)) il_isize=id_isize
+      IF( il_isize < im_minext .AND. &
+      &   TRIM(td_var%c_interp(1)) == 'cubic' )THEN
+         CALL logger_warn("EXTRAP ADD EXTRABANDS: size of extrabands "//&
+         &  "should be at least "//TRIM(fct_str(im_minext))//" for "//&
+         &  " cubic interpolation ")
+      ENDIF
+
+      il_jsize=im_minext
+      IF(PRESENT(id_jsize)) il_jsize=id_jsize
+      IF( il_jsize < im_minext .AND. &
+      &   TRIM(td_var%c_interp(1)) == 'cubic' )THEN
+         CALL logger_warn("EXTRAP ADD EXTRABANDS: size of extrabands "//&
+         &  "should be at least "//TRIM(fct_str(im_minext))//" for "//&
+         &  " cubic interpolation ")
+      ENDIF
+
+      IF( .NOT. td_var%t_dim(1)%l_use ) il_isize=0
+      IF( .NOT. td_var%t_dim(2)%l_use ) il_jsize=0
+
+      CALL logger_trace( "EXTRAP ADD EXTRABANDS: dimension change "//&
+      &              "in variable "//TRIM(td_var%c_name) )
+
+      ! add extrabands in variable
+      ALLOCATE(dl_value( td_var%t_dim(1)%i_len, &
+      &                  td_var%t_dim(2)%i_len, &
+      &                  td_var%t_dim(3)%i_len, &
+      &                  td_var%t_dim(4)%i_len ))
+
+      dl_value(:,:,:,:)=td_var%d_value(:,:,:,:)
+
+      td_var%t_dim(1)%i_len = td_var%t_dim(1)%i_len + 2*il_isize
+      td_var%t_dim(2)%i_len = td_var%t_dim(2)%i_len + 2*il_jsize
+
+      DEALLOCATE(td_var%d_value)
+      ALLOCATE( td_var%d_value(td_var%t_dim(1)%i_len, &
+      &                        td_var%t_dim(2)%i_len, &
+      &                        td_var%t_dim(3)%i_len, &
+      &                        td_var%t_dim(4)%i_len ) )
+
+      ! intialise
+      td_var%d_value(:,:,:,:)=td_var%d_fill
+
+      ! fill center
+      td_var%d_value( 1+il_isize:td_var%t_dim(1)%i_len-il_isize, &
+      &               1+il_jsize:td_var%t_dim(2)%i_len-il_jsize, &
+      &                :,:) = dl_value(:,:,:,:)
+
+      ! special case for overlap
+      IF( td_var%i_ew >= 0 .AND. il_isize /= 0 )THEN
+         DO ji=1,il_isize
+            ! from east to west
+            il_tmp=td_var%t_dim(1)%i_len-td_var%i_ew+ji-2*il_isize
+            td_var%d_value(ji,:,:,:) = td_var%d_value(il_tmp,:,:,:)
+
+            ! from west to east
+            ij=td_var%t_dim(1)%i_len-ji+1
+            il_tmp=td_var%i_ew-ji+2*il_isize+1
+            td_var%d_value(ij,:,:,:) = td_var%d_value(il_tmp,:,:,:)
+         ENDDO
+      ENDIF
+
+      DEALLOCATE( dl_value )
+
+   END SUBROUTINE extrap_add_extrabands
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine remove of the variable an extraband 
+   !> of N points at north,south,east and west boundaries.
+   !> 
+   !> @author J.Paul
+   !> - 2013-Initial version
+   !
+   !> @param[inout] td_var : variable 
+   !> @param[in] id_isize : i-direction size of extra bands (default=im_minext)
+   !> @param[in] id_jsize : j-direction size of extra bands (default=im_minext)
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE extrap_del_extrabands(td_var, id_isize, id_jsize )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(INOUT)  :: td_var
+      INTEGER(i4), INTENT(IN   ), OPTIONAL :: id_isize
+      INTEGER(i4), INTENT(IN   ), OPTIONAL :: id_jsize
+
+      ! local variable
+      REAL(dp), DIMENSION(:,:,:,:) , ALLOCATABLE :: dl_value
+
+      INTEGER(i4) :: il_isize
+      INTEGER(i4) :: il_jsize
+      
+      INTEGER(i4) :: il_imin
+      INTEGER(i4) :: il_imax
+      INTEGER(i4) :: il_jmin
+      INTEGER(i4) :: il_jmax
+
+      ! loop indices
+      !----------------------------------------------------------------
+      il_isize=im_minext
+      IF(PRESENT(id_isize)) il_isize=id_isize
+
+      il_jsize=im_minext
+      IF(PRESENT(id_jsize)) il_jsize=id_jsize
+
+      IF( .NOT. td_var%t_dim(1)%l_use ) il_isize=0
+      IF( .NOT. td_var%t_dim(2)%l_use ) il_jsize=0
+
+      CALL logger_trace( "EXTRAP DEL EXTRABANDS: dimension change "//&
+      &              "in variable "//TRIM(td_var%c_name) )
+
+      ! add extrabands in variable
+      ALLOCATE(dl_value( td_var%t_dim(1)%i_len, &
+      &                  td_var%t_dim(2)%i_len, &
+      &                  td_var%t_dim(3)%i_len, &
+      &                  td_var%t_dim(4)%i_len ))
+
+      dl_value(:,:,:,:)=td_var%d_value(:,:,:,:)
+
+      ! fill center
+      il_imin=1+il_isize
+      il_imax=td_var%t_dim(1)%i_len-il_isize
+
+      il_jmin=1+il_jsize
+      il_jmax=td_var%t_dim(2)%i_len-il_jsize
+      
+      td_var%t_dim(1)%i_len = td_var%t_dim(1)%i_len - 2*il_isize
+      td_var%t_dim(2)%i_len = td_var%t_dim(2)%i_len - 2*il_jsize
+
+      DEALLOCATE(td_var%d_value)
+      ALLOCATE( td_var%d_value(td_var%t_dim(1)%i_len, &
+      &                        td_var%t_dim(2)%i_len, &
+      &                        td_var%t_dim(3)%i_len, &
+      &                        td_var%t_dim(4)%i_len ) )
+
+      ! intialise
+      td_var%d_value(:,:,:,:)=td_var%d_fill
+
+      td_var%d_value(:,:,:,:)=dl_value(il_imin:il_imax,&
+      &                                il_jmin:il_jmax,&
+      &                                :,:)
+
+      DEALLOCATE( dl_value )
+
+   END SUBROUTINE extrap_del_extrabands
+   !> @endcode
+!   !-------------------------------------------------------------------
+!   !> @brief
+!   !> This function
+!   !> 
+!   !> @details 
+!   !>
+!   !> @author J.Paul
+!   !> - Nov, 2013- Initial Version
+!   !
+!   !> @param[in]
+!   !> @param[out] 
+!   !-------------------------------------------------------------------
+!   !> @code
+!   FUNCTION extrap_( )
+!      IMPLICIT NONE
+!      ! Argument
+!
+!      ! local variable
+!
+!      ! loop indices
+!      !----------------------------------------------------------------
+!   END FUNCTION extrap_
+!   !> @endcode
+!   !-------------------------------------------------------------------
+!   !> @brief
+!   !> This subroutine
+!   !> 
+!   !> @details 
+!   !>
+!   !> @author J.Paul
+!   !> - Nov, 2013- Initial Version
+!   !
+!   !> @param[in]
+!   !> @param[out] 
+!   !-------------------------------------------------------------------
+!   !> @code
+!   SUBROUTINE extrap_( )
+!      IMPLICIT NONE
+!      ! Argument
+!
+!      ! local variable
+!
+!      ! loop indices
+!      !----------------------------------------------------------------
+!   END SUBROUTINE extrap_
+!   !> @endcode
+END MODULE extrap
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/file.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/file.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/file.f90	(revision 4245)
@@ -0,0 +1,2020 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: file
+!
+!> @brief 
+!> This module manage file structure.
+!
+!> @details
+!>
+!>    define type TFILE:<br/>
+!>    TYPE(TFILE) :: tl_file<br/>
+!>
+!>    to initialise a file structure:<br/>
+!>    tl_file=file_init(cd_file [,cd_type] [,ld_wrt])
+!>       - cd_file is the file name
+!>       - cd_type is the type of the file ('cdf', 'dimg') (optional)
+!>       - ld_wrt  file in write mode or not (optional)
+!>
+!>    to get file name:<br/>
+!>    - tl_file\%c_name
+!>
+!>    to get file id (units):<br/>
+!>    - tl_file\%i_id
+!>    
+!>    to get the type of the file (cdf, cdf4, dimg):<br/>
+!>    - tl_file\%c_type
+!> 
+!>    to know if file was open in write mode:<br/>
+!>    - tl_file\%l_wrt
+!>
+!>    to get the record length of the file:<br/>
+!>    - tl_file\%i_recl
+!>
+!>    Files variables<br/>
+!>    to get the number of variable in the file:<br/>
+!>    - tl_file\%i_nvar
+!>
+!>    to get the table of variable structure associated to the file:<br/>
+!>    - tl_file\%t_var(:)
+!>
+!>    Files attributes<br/>
+!>    to get the nmber of global attributes of the file:<br/>
+!>    - tl_file\%i_natt
+!>
+!>    to get the table of attributes structure associated to the file:<br/>
+!>    - tl_file\%t_att(:)
+!>
+!>    Files dimensions<br/>
+!>    to get the number of dimension used in the file:<br/>
+!>    - tl_file\%i_ndim
+!>
+!>    to get the table of dimension structure (4 elts) associated to the
+!>    file:<br/>
+!>    - tl_file\%t_dim(:)
+!>
+!>    to print information about file structure:<br/>
+!>    CALL file_print(td_file)
+!>
+!>    to add a global attribute structure in file structure:<br/>
+!>    CALL file_add_att(td_file, td_att)
+!>       - td_att is an attribute structure
+!>
+!>    to add a dimension structure in file structure:<br/>
+!>    CALL file_add_dim(td_file, td_dim)
+!>       - td_dim is a dimension structure
+!>
+!>    to add a variable structure in file structure:<br/>
+!>    CALL file_add_var(td_file, td_var)
+!>       - td_var is a variable structure
+!>
+!>    to delete a global attribute structure in file structure:<br/>
+!>    CALL file_del_att(td_file, td_att)
+!>       - td_att is an attribute structure
+!>
+!>    to delete a dimension structure in file structure:<br/>
+!>    CALL file_del_dim(td_file, td_dim)
+!>       - td_dim is a dimension structure
+!>
+!>    to delete a variable structure in file structure:<br/>
+!>    CALL file_del_var(td_file, td_var)
+!>       - td_var is a variable structure
+!>
+!>    to overwrite one attribute structure in file structure:<br/>
+!>    CALL file_move_att(td_file, td_att)
+!>       - td_att is an attribute structure
+!>
+!>    to  overwrite one dimension strucutre in file structure:<br/>
+!>    CALL file_move_dim(td_file, td_dim)
+!>       - td_dim is a dimension structure
+!>
+!>    to overwrite one variable  structure in file structure:<br/>
+!>    CALL file_move_var(td_file, td_var)
+!>       - td_var is a variable structure
+!> 
+!>    to check if file and variable structure share same dimension:<br/>
+!>    ll_check_dim = file_check_var_dim(td_file, td_var)
+!>       - td_var is a variable structure
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013- Initial Version
+!>
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!> @todo
+!> - file_get_var(td_file, varname)
+!> - add description generique de l'objet file
+!----------------------------------------------------------------------
+MODULE file
+   USE kind                            ! F90 kind parameter
+   USE global                          ! global variable
+   USE fct                             ! basic useful function
+   USE logger                             ! log file manager
+   USE dim                             ! dimension manager
+   USE att                             ! attribute manager
+   USE var                             ! variable manager
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+   PUBLIC :: TFILE   ! file structure
+
+   ! function and subroutine
+   PUBLIC :: ASSIGNMENT(=)   !< copy file structure
+   PUBLIC :: file_print      !< print information about file structure
+   PUBLIC :: file_clean      !< clean file structure
+   PUBLIC :: file_init       !< initialise file structure
+   PUBLIC :: file_add_att    !< add one attribute structure in file structure
+   PUBLIC :: file_add_var    !< add one variable  structure in file structure
+   PUBLIC :: file_add_dim    !< add one dimension strucutre in file structure
+   PUBLIC :: file_del_att    !< delete one attribute structure of file structure
+   PUBLIC :: file_del_var    !< delete one variable  structure of file structure
+   PUBLIC :: file_del_dim    !< delete one dimension strucutre of file structure
+   PUBLIC :: file_move_att   !< overwrite one attribute structure in file structure
+   PUBLIC :: file_move_var   !< overwrite one variable  structure in file structure
+   PUBLIC :: file_move_dim   !< overwrite one dimension strucutre in file structure
+   PUBLIC :: file_check_var_dim  !< check if file and variable structure use same dimension.
+   PUBLIC :: file_get_type   !< get type of file
+   PUBLIC :: file_get_id     !< get file id
+   PUBLIC :: file_rename     !< rename file name
+   PUBLIC :: file_add_suffix !< add suffix to file name
+ 
+   PRIVATE :: file__del_var_name !< delete a variable structure in file structure, given variable name or standard name
+   PRIVATE :: file__del_var_str  !< delete a variable structure in file structure, given variable structure
+   PRIVATE :: file__del_att_name !< delete a attribute structure in file structure, given attribute name
+   PRIVATE :: file__del_att_str  !< delete a attribute structure in file structure, given attribute structure
+   PRIVATE :: file__get_number   !< get number in file name without suffix
+   PRIVATE :: file__get_suffix   !< get suffix of file name
+   PRIVATE :: file__copy_unit    !< copy file structure
+   PRIVATE :: file__copy_tab     !< copy file structure
+
+   !> @struct
+   TYPE TFILE
+
+      ! general 
+      CHARACTER(LEN=lc)                 :: c_name = "" !< file name
+      CHARACTER(LEN=lc)                 :: c_type = "" !< type of the file (cdf, cdf4, dimg)
+      INTEGER(i4)                       :: i_id   = 0         !< file id
+      LOGICAL                           :: l_wrt  = .FALSE.   !< read or write mode
+      INTEGER(i4)                       :: i_nvar = 0         !< number of variable
+      TYPE(TVAR), DIMENSION(:), POINTER :: t_var  => NULL()   !< file variables
+
+      CHARACTER(LEN=lc)                 :: c_grid = 'ARAKAWA-C' !< grid type
+
+      INTEGER(i4)                       :: i_ew    =-1   !< east-west overlap
+      INTEGER(i4)                       :: i_perio =-1   !< NEMO periodicity index
+      INTEGER(i4)                       :: i_pivot =-1   !< NEMO pivot point index F(0),T(1)
+
+      INTEGER(i4)                       :: i_depthid = 0         !< variable id of depth
+      INTEGER(i4)                       :: i_timeid  = 0         !< variable id of time
+
+      ! netcdf file
+      INTEGER(i4)                       :: i_ndim  = 0        !< number of dimensions used in the file
+      INTEGER(i4)                       :: i_natt  = 0        !< number of global attributes in the file
+      INTEGER(i4)                       :: i_uldid = 0        !< id of the unlimited dimension in the file
+      LOGICAL                           :: l_def   = .FALSE.  !< define mode or not
+      TYPE(TATT), DIMENSION(:), POINTER :: t_att   => NULL()  !< global attributes
+      TYPE(TDIM), DIMENSION(ip_maxdim)  :: t_dim              !< dimension structure
+      
+      ! dimg file
+      INTEGER(i4)                       :: i_recl = 0         !< record length (binary file)
+      INTEGER(i4)                       :: i_n0d  = 0         !< number of scalar variable
+      INTEGER(i4)                       :: i_n1d  = 0         !< number of 1D variable
+      INTEGER(i4)                       :: i_n2d  = 0         !< number of 2D variable
+      INTEGER(i4)                       :: i_n3d  = 0         !< number of 3D variable
+      INTEGER(i4)                       :: i_rhd  = 0         !< record of the header infos (last record)
+
+      ! mpp
+      ! only use for massively parallel processing
+      INTEGER(i4)                       :: i_pid  = -1        !< processor id (start to 1)
+      INTEGER(i4)                       :: i_impp = 0         !< i-indexes for mpp-subdomain left bottom
+      INTEGER(i4)                       :: i_jmpp = 0         !< j-indexes for mpp-subdomain left bottom
+      INTEGER(i4)                       :: i_lci  = 0         !< i-dimensions of subdomain
+      INTEGER(i4)                       :: i_lcj  = 0         !< j-dimensions of subdomain
+      INTEGER(i4)                       :: i_ldi  = 0         !< first indoor i-indices
+      INTEGER(i4)                       :: i_ldj  = 0         !< first indoor j-indices
+      INTEGER(i4)                       :: i_lei  = 0         !< last  indoor i-indices
+      INTEGER(i4)                       :: i_lej  = 0         !< last  indoor j-indices
+
+      LOGICAL                           :: l_ctr  = .FALSE.   !< domain is on border
+      LOGICAL                           :: l_use  = .FALSE.   !< domain is used
+
+      ! only use to draw domain decomposition when initialise with mpp_init
+      INTEGER(i4)                       :: i_iind = 0         !< i-direction indices
+      INTEGER(i4)                       :: i_jind = 0         !< j-direction indices
+
+   END TYPE TFILE
+
+   INTERFACE file_del_var
+      MODULE PROCEDURE file__del_var_name
+      MODULE PROCEDURE file__del_var_str
+   END INTERFACE file_del_var
+
+   INTERFACE file_del_att
+      MODULE PROCEDURE file__del_att_name
+      MODULE PROCEDURE file__del_att_str
+   END INTERFACE file_del_att
+   
+   INTERFACE file_rename
+      MODULE PROCEDURE file__rename_char
+      MODULE PROCEDURE file__rename_str
+   END INTERFACE file_rename
+
+    INTERFACE ASSIGNMENT(=)
+      MODULE PROCEDURE file__copy_unit   ! copy file structure
+      MODULE PROCEDURE file__copy_tab    ! copy file structure
+   END INTERFACE
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function copy file structure in another file
+   !> structure
+   !> @details 
+   !> file variable and attribute value are copied in a temporary table, 
+   !> so input and output file structure value do not point on the same 
+   !> "memory cell", and so on are independant. 
+   !>
+   !> @note new file is assume to be closed.
+   !>
+   !> @warning to avoid infinite loop, do not use any function inside 
+   !> this subroutine
+   !>   
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[out] td_file1  : file structure
+   !> @param[in] td_file2  : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file__copy_unit( td_file1, td_file2 )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE), INTENT(  OUT) :: td_file1
+      TYPE(TFILE), INTENT(IN   )  :: td_file2
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      CALL logger_trace("COPY: file "//TRIM(td_file2%c_name) )
+
+      ! copy file variable
+      td_file1%c_name = TRIM(td_file2%c_name)
+      td_file1%c_type = TRIM(td_file2%c_type)
+      ! file1 should be closed even if file2 is opened right now
+      td_file1%i_id   = 0
+      td_file1%l_wrt  = td_file2%l_wrt
+      td_file1%i_nvar = td_file2%i_nvar
+
+      td_file1%c_grid = td_file2%c_grid
+
+      td_file1%i_ew   = td_file2%i_ew
+      td_file1%i_perio= td_file2%i_perio
+      td_file1%i_pivot= td_file2%i_pivot
+
+      ! copy variable structure
+      IF( ASSOCIATED(td_file1%t_var) ) DEALLOCATE(td_file1%t_var)
+      IF( ASSOCIATED(td_file2%t_var) .AND. td_file1%i_nvar > 0 )THEN
+         ALLOCATE( td_file1%t_var(td_file1%i_nvar) )
+         DO ji=1,td_file1%i_nvar
+            td_file1%t_var(ji) = td_file2%t_var(ji)
+         ENDDO
+      ENDIF
+      
+      ! copy netcdf variable
+      td_file1%i_ndim    = td_file2%i_ndim
+      td_file1%i_natt    = td_file2%i_natt
+      td_file1%i_uldid   = td_file2%i_uldid
+      td_file1%l_def     = td_file2%l_def
+
+      ! copy dimension
+      td_file1%t_dim(:) = td_file2%t_dim(:)
+      
+      ! copy attribute structure
+      IF( ASSOCIATED(td_file1%t_att) ) DEALLOCATE(td_file1%t_att)
+      IF( ASSOCIATED(td_file2%t_att) .AND. td_file1%i_natt > 0 )THEN
+         ALLOCATE( td_file1%t_att(td_file1%i_natt) )
+         DO ji=1,td_file1%i_natt
+            td_file1%t_att(ji) = td_file2%t_att(ji)
+         ENDDO
+      ENDIF
+
+      ! copy dimg variable
+      td_file1%i_recl = td_file2%i_recl
+      td_file1%i_n0d  = td_file2%i_n0d
+      td_file1%i_n1d  = td_file2%i_n1d
+      td_file1%i_n2d  = td_file2%i_n2d
+      td_file1%i_n3d  = td_file2%i_n3d 
+      td_file1%i_rhd  = td_file2%i_rhd
+      
+      ! copy mpp variable
+      td_file1%i_pid  = td_file2%i_pid
+      td_file1%i_impp = td_file2%i_impp
+      td_file1%i_jmpp = td_file2%i_jmpp
+      td_file1%i_lci  = td_file2%i_lci
+      td_file1%i_lcj  = td_file2%i_lcj
+      td_file1%i_ldi  = td_file2%i_ldi
+      td_file1%i_ldj  = td_file2%i_ldj
+      td_file1%i_lei  = td_file2%i_lei
+      td_file1%i_lej  = td_file2%i_lej
+      td_file1%l_ctr  = td_file2%l_ctr
+      td_file1%l_use  = td_file2%l_use
+      td_file1%i_iind = td_file2%i_iind
+      td_file1%i_jind = td_file2%i_jind
+
+   END SUBROUTINE file__copy_unit
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function copy file structure in another file
+   !> structure
+   !> @details 
+   !> file variable and attribute value are copied in a temporary table, 
+   !> so input and output file structure value do not point on the same 
+   !> "memory cell", and so on are independant. 
+   !>
+   !> @note new file is assume to be closed.
+   !>
+   !> @warning to avoid infinite loop, do not use any function inside 
+   !> this subroutine
+   !>   
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[out] td_file1  : file structure
+   !> @param[in] td_file2  : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file__copy_tab( td_file1, td_file2 )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE), DIMENSION(:)                , INTENT(IN   )  :: td_file2
+      TYPE(TFILE), DIMENSION(SIZE(td_file2(:))), INTENT(  OUT) :: td_file1
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      DO ji=1,SIZE(td_file2(:))
+         td_file1(ji)=td_file2(ji)
+      ENDDO
+
+   END SUBROUTINE file__copy_tab
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initialise file structure.<br/>
+   !> If cd_type is not specify, check if file name include '.nc' or
+   !> .'dimg'<br/>
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_file : file name
+   !> @param[in] cd_type : file type ('cdf', 'dimg')
+   !> @param[in] ld_wrt  : write mode (default .FALSE.)
+   !> @return file structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TFILE) FUNCTION file_init( cd_file, cd_type, ld_wrt, &
+   &                               id_ew, id_perio, id_pivot,&
+   &                               cd_grid)
+      IMPLICIT NONE
+      ! Argument      
+      CHARACTER(LEN=*), INTENT(IN) :: cd_file
+      CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: cd_type
+      LOGICAL         , INTENT(IN), OPTIONAL :: ld_wrt
+      INTEGER(i4)     , INTENT(IN), OPTIONAL :: id_ew
+      INTEGER(i4)     , INTENT(IN), OPTIONAL :: id_perio
+      INTEGER(i4)     , INTENT(IN), OPTIONAL :: id_pivot
+      CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: cd_grid
+
+      ! local variable
+      TYPE(TATT) :: tl_att
+      !----------------------------------------------------------------
+
+      ! clean file
+      CALL file_clean(file_init)
+
+      file_init%c_name=TRIM(ADJUSTL(cd_file))
+      CALL logger_trace("INIT: initialise file "//TRIM(file_init%c_name))
+
+      ! create some global attribute
+      tl_att=att_init("Conventions","CF-1.5")
+      CALL file_add_att(file_init,tl_att)
+     
+      tl_att=att_init("Grid",TRIM(file_init%c_grid))
+      CALL file_add_att(file_init,tl_att)
+
+      ! check type
+      IF( PRESENT(cd_type) )THEN
+         SELECT CASE(TRIM(cd_type))
+            CASE('cdf')
+               file_init%c_type='cdf'
+            CASE('dimg')
+               file_init%c_type='dimg'
+            CASE DEFAULT
+               CALL logger_error( " INIT: can't initialise file "//&
+               &               TRIM(file_init%c_name)//" : type unknown " )
+         END SELECT
+      ELSE
+         file_init%c_type=TRIM(file_get_type(cd_file))
+      ENDIF
+
+      IF( PRESENT(ld_wrt) )THEN
+         file_init%l_wrt=ld_wrt
+      ENDIF
+
+      IF( PRESENT(id_ew) )THEN
+         file_init%i_ew=id_ew
+         IF( id_ew >= 0 )THEN
+            tl_att=att_init('ew_overlap',id_ew)
+            CALL file_move_att(file_init, tl_att)
+         ENDIF
+      ENDIF
+
+      IF( PRESENT(id_perio) )THEN
+         file_init%i_perio=id_perio
+         IF( id_perio >= 0 )THEN
+            tl_att=att_init('periodicity',id_perio)
+            CALL file_move_att(file_init, tl_att)
+         ENDIF
+      ENDIF
+
+      IF( PRESENT(id_pivot) )THEN
+         file_init%i_pivot=id_pivot
+         IF( id_pivot > 0 )THEN
+            tl_att=att_init('pivot_point',id_pivot)
+            CALL file_move_att(file_init, tl_att)
+         ENDIF
+      ENDIF
+
+      IF( PRESENT(cd_grid) )THEN
+         file_init%c_grid=cd_grid
+      ENDIF
+
+   END FUNCTION file_init
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This function get type of file, given file name.
+   !> @details
+   !> Actually it get suffix of the file name, and compare it to 'nc', 'cdf' or
+   !> 'dimg'<br/>
+   !> If no suffix or suffix not identify, we assume file is dimg
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_file : file name
+   !> @return type of file
+   !-------------------------------------------------------------------
+   !> @code
+   CHARACTER(LEN=lc) FUNCTION file_get_type(cd_file)
+      IMPLICIT NONE
+      ! Argument      
+      CHARACTER(LEN=*), INTENT(IN) :: cd_file
+      !local variable
+      CHARACTER(LEN=lc) :: cl_suffix
+      !----------------------------------------------------------------
+
+      cl_suffix=file__get_suffix(cd_file)
+      SELECT CASE( TRIM(fct_lower(cl_suffix)) )
+         CASE('.nc','.cdf')
+            CALL logger_debug(" GET TYPE: file "//TRIM(cd_file)//" is cdf")
+            file_get_type='cdf'
+         CASE('.dimg')
+            CALL logger_debug(" GET TYPE: file "//TRIM(cd_file)//" is dimg" )
+            file_get_type='dimg'
+         CASE DEFAULT
+            CALL logger_warn(" GET TYPE: type unknown, we assume file: "//&
+            &              TRIM(cd_file)//" is dimg ")
+            file_get_type='dimg'
+      END SELECT
+
+   END FUNCTION file_get_type
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function check if variable dimension to be used 
+   !> have the same length that in file structure.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] td_var : variable structure
+   !> @return dimension of variable and file structure agree (or not)
+   !-------------------------------------------------------------------
+   !> @code
+   LOGICAL FUNCTION file_check_var_dim(td_file, td_var)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_file
+      TYPE(TVAR),  INTENT(IN) :: td_var
+
+      ! local variable
+      INTEGER(i4) :: il_ndim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      file_check_var_dim=.TRUE.
+      ! check used dimension 
+      IF( ANY( td_var%t_dim(:)%l_use .AND. &
+      &        td_var%t_dim(:)%i_len /= td_file%t_dim(:)%i_len) )THEN
+
+         file_check_var_dim=.FALSE.
+
+         CALL logger_error( &
+         &  " FILE CHECK VAR DIM: variable and file dimension differ"//&
+         &  " for variable "//TRIM(td_var%c_name)//&
+         &  " and file "//TRIM(td_file%c_name))
+
+
+         CALL logger_debug( &
+         &  " file dimension: "//TRIM(fct_str(td_file%i_ndim))//&
+         &  " variable dimension: "//TRIM(fct_str(td_var%i_ndim)) )
+         il_ndim=MIN(td_var%i_ndim, td_file%i_ndim )
+         DO ji = 1, il_ndim
+            CALL logger_debug( &
+            &  " FILE CHECK VAR DIM: for dimension "//&
+            &  TRIM(td_file%t_dim(ji)%c_name)//&
+            &  ", file length: "//&
+            &  TRIM(fct_str(td_file%t_dim(ji)%i_len))//&
+            &  ", variable length: "//&
+            &  TRIM(fct_str(td_var%t_dim(ji)%i_len))//&
+            &  ", variable used "//TRIM(fct_str(td_var%t_dim(ji)%l_use)))
+         ENDDO
+      ELSE
+         IF( ANY( td_var%t_dim(:)%l_use .AND. &
+         &  .NOT. td_file%t_dim(:)%l_use ) )THEN
+            
+            CALL logger_info("FILE CHECK VAR DIM: variable use more dimension "//&
+            &  " than file do until now. file dimension use will change.")
+
+         ENDIF
+      ENDIF
+
+   END FUNCTION file_check_var_dim
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a variable structure in a file structure.<br/>
+   !> Do not overwrite, if variable already in file structure.
+   !
+   !> @note variable value is suppose to be ordered ('x','y','z','t')
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] td_var : variable structure
+   !
+   !> @todo 
+   !> - check dimension order
+   !> - voir pour ajouter variable avec plus de dim que deja presente dans fichier
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file_add_var(td_file, td_var)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      TYPE(TVAR) , INTENT(IN   ) :: td_var
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_varid
+      INTEGER(i4) :: il_rec
+      INTEGER(i4) :: il_ind
+
+      TYPE(TVAR), DIMENSION(:), ALLOCATABLE :: tl_var
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! check if file opened
+      !IF( TRIM(td_file%c_name) == "unknown" )THEN
+      IF( TRIM(td_file%c_name) == '' )THEN
+
+         CALL logger_error( " ADD VAR: structure file unknown" )
+         CALL logger_debug( " ADD VAR: you should have used file_init before "//&
+         & "running file_add_var" )
+
+      ELSE
+         ! check if variable exist
+         IF( TRIM(td_var%c_name) == '' .AND. &
+         &   TRIM(td_var%c_stdname) == '' )THEN
+            CALL logger_error(" ADD VAR: variable not define ")
+         ELSE
+            ! check if variable already in file structure
+            il_varid=0
+            IF( ASSOCIATED(td_file%t_var) )THEN
+               il_varid=var_get_id( td_file%t_var(:), td_var%c_name,   &
+               &                                      td_var%c_stdname )
+            ENDIF
+
+            IF( il_varid /= 0 )THEN
+
+               CALL logger_error( &
+               &  " ADD VAR: variable "//TRIM(td_var%c_name)//&
+               &  ", standard name "//TRIM(td_var%c_stdname)//&
+               &  ", already in file "//TRIM(td_file%c_name) )
+
+               DO ji=1,td_file%i_nvar
+                  CALL logger_debug( " ADD VAR: in file : &
+                  &  variable "//TRIM(td_file%t_var(ji)%c_name)//&
+                  &  ", standard name "//TRIM(td_file%t_var(ji)%c_stdname) )
+               ENDDO
+
+            ELSE
+
+               CALL logger_info( &
+               &  " ADD VAR: add variable "//TRIM(td_var%c_name)//&
+               &  ", standard name "//TRIM(td_var%c_stdname)//&
+               &  ", in file "//TRIM(td_file%c_name) )
+
+               ! if none, force to use variable dimension
+               IF( ALL( .NOT. td_file%t_dim(:)%l_use) )THEN
+                  td_file%t_dim(:)=td_var%t_dim(:)
+               ENDIF
+
+               ! check used dimension 
+               IF( file_check_var_dim(td_file, td_var) )THEN
+
+                  SELECT CASE(td_var%i_ndim)
+                     CASE(0)
+                        il_ind=td_file%i_n0d+1
+                        il_rec=0
+                     CASE(1)
+                        il_ind=td_file%i_n0d+td_file%i_n1d+1
+                        il_rec=1
+                     CASE(2)
+                        il_ind=td_file%i_n0d+td_file%i_n1d+td_file%i_n2d+1
+                        il_rec=1
+                     CASE(3,4)
+                        il_ind=td_file%i_n0d+td_file%i_n1d+td_file%i_n2d+td_file%i_n3d+1
+                        il_rec=td_file%t_dim(3)%i_len
+                  END SELECT
+
+                  IF( td_file%i_nvar > 0 )THEN
+                  ! already other variable in file structure
+                     ALLOCATE( tl_var(td_file%i_nvar), stat=il_status )
+                     IF(il_status /= 0 )THEN
+
+                        CALL logger_error( &
+                        &  " ADD VAR: not enough space to put variables "//&
+                        &  "from "//TRIM(td_file%c_name)//&
+                        &  " in variable structure")
+
+                     ELSE
+
+                        ! save temporary variable of file structure
+                        tl_var(:)=td_file%t_var(:)
+
+                        DEALLOCATE( td_file%t_var )
+                        ALLOCATE( td_file%t_var(td_file%i_nvar+1), &
+                        &         stat=il_status)
+                        IF(il_status /= 0 )THEN
+
+                           CALL logger_error( &
+                           &  " ADD VAR: not enough space to put variable "//&
+                           &  "in file structure "//TRIM(td_file%c_name) )
+
+                        ENDIF
+
+                        ! copy variable in file before
+                        ! variable with less than or equal dimension that new variable
+                        td_file%t_var( 1:il_ind-1 ) = tl_var( 1:il_ind-1 )
+
+                        ! variable with greater dimension than new variable
+                        td_file%t_var( il_ind+1 : td_file%i_nvar+1 ) = &
+                        &                 tl_var( il_ind : td_file%i_nvar )
+
+                        ! update id
+                        td_file%t_var( il_ind+1 : td_file%i_nvar+1 )%i_id = &
+                        &           tl_var( il_ind : td_file%i_nvar )%i_id + 1
+
+                        ! update record index
+                        td_file%t_var( il_ind+1 : td_file%i_nvar+1 )%i_rec = &
+                        & tl_var( il_ind : td_file%i_nvar )%i_rec + il_rec
+
+                        DEALLOCATE(tl_var)
+                     ENDIF
+
+                  ELSE
+                  ! no variable in file structure
+                     IF( ASSOCIATED(td_file%t_var) )THEN
+                        DEALLOCATE(td_file%t_var)
+                     ENDIF
+                     ALLOCATE( td_file%t_var(td_file%i_nvar+1), stat=il_status )
+                     IF(il_status /= 0 )THEN
+
+                        CALL logger_error( &
+                        &  " ADD VAR: not enough space to put variable "//&
+                        &  "in file structure "//TRIM(td_file%c_name) )
+
+                     ENDIF
+
+                  ENDIF
+
+                  ALLOCATE( tl_var(1), stat=il_status )
+                  IF(il_status /= 0 )THEN
+
+                     CALL logger_error( &
+                     &  " ADD VAR: not enough space to put variables from "//&
+                     &  TRIM(td_var%c_name)//" in variable structure")
+
+                  ELSE
+                     tl_var(1)=td_var
+
+                     ! update dimension name in new variable
+                     tl_var(1)%t_dim(:)%c_name = td_file%t_dim(:)%c_name
+                  
+                     ! add new variable
+                     td_file%t_var(il_ind)=tl_var(1)
+
+                     ! update number of variable
+                     td_file%i_nvar=td_file%i_nvar+1
+                     SELECT CASE(tl_var(1)%i_ndim)
+                        CASE(0)
+                           td_file%i_n0d=td_file%i_n0d+1
+                        CASE(1)
+                           td_file%i_n1d=td_file%i_n1d+1
+                        CASE(2)
+                           td_file%i_n2d=td_file%i_n2d+1
+                        CASE(3)
+                           td_file%i_n3d=td_file%i_n3d+1
+                     END SELECT
+
+                     ! update variable id
+                     td_file%t_var(il_ind)%i_id=il_ind
+
+                     ! update record header index
+                     td_file%i_rhd=td_file%i_rhd+il_rec
+
+                     ! update record index
+                     IF( il_ind > 1 )THEN
+                        td_file%t_var(il_ind)%i_rec = &
+                        &     td_file%t_var(il_ind-1)%i_rec+il_rec
+                     ELSE
+                        td_file%t_var(il_ind)%i_rec = il_rec
+                     ENDIF
+
+                     ! update dimension used
+                     td_file%t_dim(:)%l_use=.FALSE.
+                     DO ji=1,ip_maxdim
+                        IF( ANY(td_file%t_var(:)%t_dim(ji)%l_use) )THEN
+                           td_file%t_dim(ji)%l_use=.TRUE.
+                        ENDIF
+                     ENDDO
+                     CALL dim_reorder(td_file%t_dim(:))
+                     ! update number of dimension
+                     td_file%i_ndim=COUNT(td_file%t_dim(:)%l_use)
+
+                     DEALLOCATE( tl_var )
+                  ENDIF
+
+               ENDIF
+            ENDIF
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE file_add_var
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine delete a variable structure 
+   !> in file structure.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] cd_name : variable name or standard name
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file__del_var_name(td_file, cd_name )
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE)     , INTENT(INOUT) :: td_file
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_name
+
+      ! local variable
+      INTEGER(i4)       :: il_varid
+      !----------------------------------------------------------------
+
+      ! check if file opened
+      IF( TRIM(td_file%c_name) == '' )THEN
+
+         CALL logger_error( " DEL VAR NAME: file structure unknown ")
+         CALL logger_debug( " DEL VAR NAME: you should have used file_init before "//&
+         & "running file_del_var" )
+
+      ELSE
+
+         IF( td_file%i_nvar /= 0 )THEN
+
+            ! get the variable id, in file variable structure
+            il_varid=0
+            IF( ASSOCIATED(td_file%t_var) )THEN
+               il_varid=var_get_id(td_file%t_var(:), cd_name )
+            ENDIF
+            IF( il_varid /= 0 )THEN
+   
+               CALL file_del_var(td_file, td_file%t_var(il_varid))
+
+            ELSE
+
+               CALL logger_warn( &
+               &  " DEL VAR NAME: there is no variable with name or "//&
+               &  "standard name "//TRIM(cd_name)//" in file "//&
+               &  TRIM(td_file%c_name))
+
+            ENDIF
+
+         ELSE
+            CALL logger_debug( " DEL VAR NAME: no variable associated to file "//&
+            &               TRIM(td_file%c_name) )
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE file__del_var_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine delete a variable structure 
+   !> in file structure, given variable structure.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] td_var : variable structure
+   !> @todo
+   !> - verifier pose pas de souci de ne pas modifier id
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file__del_var_str(td_file, td_var)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      TYPE(TVAR),  INTENT(IN)    :: td_var
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_varid
+      INTEGER(i4) :: il_rec
+      TYPE(TVAR), DIMENSION(:), ALLOCATABLE :: tl_var
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! check if file opened
+      !IF( TRIM(td_file%c_name) == "unknown" )THEN
+      IF( TRIM(td_file%c_name) == '' )THEN
+
+         CALL logger_error( " DEL VAR: file structure unknown ")
+         CALL logger_debug( " DEL VAR: you should have used file_init before "//&
+         & "running file_del_var" )      
+
+      ELSE
+
+         ! check if variable already in file structure
+         il_varid=var_get_id(td_file%t_var(:), td_var%c_name, td_var%c_stdname )
+         IF( il_varid == 0 )THEN
+
+            CALL logger_error( &
+            &  " DEL VAR: no variable "//TRIM(td_var%c_name)//&
+            &  ", in file "//TRIM(td_file%c_name) )
+
+            DO ji=1,td_file%i_nvar
+               CALL logger_debug( &
+               &  " DEL VAR: in file "//TRIM(td_file%t_var(ji)%c_name)//&
+               &  ", standard name "//TRIM(td_file%t_var(ji)%c_stdname) )
+            ENDDO
+
+         ELSE
+            
+            CALL logger_trace( &
+            &  " DEL VAR: delete variable "//TRIM(td_var%c_name)//&
+            &  ", from file "//TRIM(td_file%c_name) )
+
+            ALLOCATE( tl_var(td_file%i_nvar-1), stat=il_status )
+            IF(il_status /= 0 )THEN
+
+               CALL logger_error( &
+               &  " DEL VAR: not enough space to put variables from "//&
+               &  TRIM(td_file%c_name)//" in temporary variable structure")
+
+            ELSE
+
+               ! save temporary variable's file structure
+               tl_var(1:il_varid-1)=td_file%t_var(1:il_varid-1)
+               tl_var(il_varid:)=td_file%t_var(il_varid+1:)
+
+               ! new number of variable in file
+               td_file%i_nvar=td_file%i_nvar-1
+
+               SELECT CASE(td_var%i_ndim)
+                  CASE(0)
+                     td_file%i_n0d=td_file%i_n0d-1
+                     il_rec=0
+                  CASE(1)
+                     td_file%i_n1d=td_file%i_n1d-1
+                     il_rec=1
+                  CASE(2)
+                     td_file%i_n2d=td_file%i_n2d-1
+                     il_rec=1
+                  CASE(3,4)
+                     td_file%i_n3d=td_file%i_n3d-1
+                     il_rec=td_file%t_dim(3)%i_len
+               END SELECT
+
+               DEALLOCATE( td_file%t_var )
+
+               IF( td_file%i_nvar > 0 )THEN
+                  ALLOCATE( td_file%t_var(td_file%i_nvar), stat=il_status )
+                  IF(il_status /= 0 )THEN
+
+                     CALL logger_error( &
+                     &  " DEL VAR: not enough space to put variables "//&
+                     &  "in file structure "//TRIM(td_file%c_name) )
+
+                  ENDIF
+
+                  ! copy attribute in file before
+                  td_file%t_var(:)=tl_var(:)
+
+                  ! update record header index
+                  td_file%i_rhd = td_file%i_rhd - il_rec
+
+!                  ! update id
+!                  td_file%t_var( il_varid : td_file%i_nvar )%i_id = &
+!                  &     td_file%t_var( il_varid : td_file%i_nvar )%i_id - 1
+
+                  ! update record index
+                  td_file%t_var( il_varid : td_file%i_nvar )%i_rec = &
+                  &     td_file%t_var( il_varid : td_file%i_nvar )%i_rec - il_rec
+
+                  ! update dimension used
+                  td_file%t_dim(:)%l_use=.FALSE.
+                  DO ji=1,ip_maxdim
+                     IF( ANY(td_file%t_var(:)%t_dim(ji)%l_use) )THEN
+                        td_file%t_dim(ji)%l_use=.TRUE.
+                     ENDIF
+                  ENDDO
+                  CALL dim_reorder(td_file%t_dim(:))
+                  ! update number of dimension
+                  td_file%i_ndim=COUNT(td_file%t_dim(:)%l_use)
+
+               ENDIF
+               DEALLOCATE(tl_var)
+               
+            ENDIF 
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE file__del_var_str
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine overwrite variable structure 
+   !> in file structure.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] td_var : variable structure
+   !> @todo
+   !> - check independance td_var (cf move dim variable)
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file_move_var(td_file, td_var)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      TYPE(TVAR),  INTENT(IN)    :: td_var
+
+      ! local variable
+      TYPE(TVAR) :: tl_var
+      INTEGER(i4):: il_varid
+      !----------------------------------------------------------------
+
+      ! copy variable
+      tl_var=td_var
+
+      IF( ASSOCIATED(td_file%t_var) )THEN
+         il_varid=var_get_id(td_file%t_var(:),TRIM(tl_var%c_name))
+         IF( il_varid /= 0 )THEN
+            ! remove variable with same name or standard name
+            CALL file_del_var(td_file, tl_var)
+         ENDIF
+      ENDIF
+
+      ! add new variable
+      CALL file_add_var(td_file, tl_var)
+
+   END SUBROUTINE file_move_var
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a global attribute 
+   !> in a file structure.<br/>
+   !> Do not overwrite, if attribute already in file structure.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] td_att : attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file_add_att(td_file, td_att)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      TYPE(TATT),  INTENT(IN)    :: td_att
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_attid
+      TYPE(TATT), DIMENSION(:), ALLOCATABLE :: tl_att
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! check if file opened
+      !IF( TRIM(td_file%c_name) == "unknown" )THEN
+      IF( TRIM(td_file%c_name) == '' )THEN
+
+         CALL logger_error( " ADD ATT: file structure unknown ")
+         CALL logger_debug( " ADD ATT: you should have used file_init before "//&
+         & "running file_add_att" )      
+
+      ELSE
+
+         ! check if attribute already in file structure
+         il_attid=0
+         IF( ASSOCIATED(td_file%t_att) )THEN
+            il_attid=att_get_id( td_file%t_att(:), td_att%c_name )
+         ENDIF
+
+         IF( il_attid /= 0 )THEN
+         
+            CALL logger_error( &
+            &  " ADD ATT: attribute "//TRIM(td_att%c_name)//&
+            &  ", already in file "//TRIM(td_file%c_name) )
+            CALL logger_flush()
+
+            DO ji=1,td_file%i_natt
+               CALL logger_debug( &
+               &  " ADD ATT: in file "//TRIM(td_file%t_att(ji)%c_name) )
+            ENDDO
+
+         ELSE
+            
+            CALL logger_debug( &
+            &  " ADD ATT: add attribute "//TRIM(td_att%c_name)//&
+            &  ", in file "//TRIM(td_file%c_name) )
+
+            IF( td_file%i_natt > 0 )THEN
+            ! already other attribute in file structure
+               ALLOCATE( tl_att(td_file%i_natt), stat=il_status )
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( &
+                  &  " ADD ATT: not enough space to put attributes from "//&
+                  &  TRIM(td_file%c_name)//" in temporary attribute structure")
+
+               ELSE
+
+                  ! save temporary global attribute's file structure
+                  tl_att(:)=td_file%t_att(:)
+
+                  DEALLOCATE( td_file%t_att )
+                  ALLOCATE( td_file%t_att(td_file%i_natt+1), stat=il_status )
+                  IF(il_status /= 0 )THEN
+
+                     CALL logger_error( &
+                     &  " ADD ATT: not enough space to put attributes "//&
+                     &  "in file structure "//TRIM(td_file%c_name) )
+
+                  ENDIF
+
+                  ! copy attribute in file before
+                  td_file%t_att(1:td_file%i_natt)=tl_att(:)
+
+                  DEALLOCATE(tl_att)
+               ENDIF
+            ELSE
+            ! no attribute in file structure
+               IF( ASSOCIATED(td_file%t_att) )THEN
+                  DEALLOCATE(td_file%t_att)
+               ENDIF
+               CALL logger_debug(" natt "//TRIM(fct_str(td_file%i_natt)) )
+               ALLOCATE( td_file%t_att(td_file%i_natt+1), stat=il_status )
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( &
+                  &  " ADD ATT: not enough space to put attributes "//&
+                  &  "in file structure "//TRIM(td_file%c_name) )
+
+               ENDIF
+            ENDIF
+            ! add new attributes
+            td_file%t_att(td_file%i_natt+1)=td_att
+
+            ! update attributes id
+            td_file%t_att(td_file%i_natt+1)%i_id=td_file%i_natt+1
+
+            ! update number of attribute
+            td_file%i_natt=td_file%i_natt+1
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE file_add_att
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine delete a variable structure 
+   !> in file structure.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] cd_name : variable name or standard name
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file__del_att_name(td_file, cd_name )
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE)     , INTENT(INOUT) :: td_file
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_name
+
+      ! local variable
+      INTEGER(i4)       :: il_attid
+      !----------------------------------------------------------------
+
+      ! check if file opened
+      IF( TRIM(td_file%c_name) == '' )THEN
+
+         CALL logger_error( " DEL ATT NAME: file structure unknown ")
+         CALL logger_debug( " DEL ATT NAME: you should have used file_init before "//&
+         & "running file_del_var" )
+
+      ELSE
+
+         IF( td_file%i_natt /= 0 )THEN
+
+            ! get the variable id, in file variable structure
+            il_attid=0
+            IF( ASSOCIATED(td_file%t_att) )THEN
+               il_attid=att_get_id(td_file%t_att(:), cd_name )
+            ENDIF
+            IF( il_attid /= 0 )THEN
+   
+               CALL file_del_att(td_file, td_file%t_att(il_attid))
+
+            ELSE
+
+               CALL logger_warn( &
+               &  " DEL ATT NAME: there is no attribute with name "//&
+               &  TRIM(cd_name)//" in file "//TRIM(td_file%c_name))
+
+            ENDIF
+
+         ELSE
+            CALL logger_debug( " DEL ATT NAME: no attribute associated to file "//&
+            &               TRIM(td_file%c_name) )
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE file__del_att_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine delete a global attribute structure 
+   !> from file structure.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] td_att : attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file__del_att_str(td_file, td_att)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      TYPE(TATT),  INTENT(IN)    :: td_att
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_attid
+      TYPE(TATT), DIMENSION(:), ALLOCATABLE :: tl_att
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! check if file opened
+      !IF( TRIM(td_file%c_name) == "unknown" )THEN
+      IF( TRIM(td_file%c_name) == '' )THEN
+
+         CALL logger_error( " DEL ATT: file structure unknown ")
+         CALL logger_debug( " DEL ATT: you should have used file_init before "//&
+         & "running file_del_att" )      
+
+      ELSE
+
+         ! check if attribute already in file structure
+         il_attid=0
+         IF( ASSOCIATED(td_file%t_att) )THEN
+            il_attid=att_get_id( td_file%t_att(:), td_att%c_name )
+         ENDIF
+
+         IF( il_attid == 0 )THEN
+
+            CALL logger_error( &
+            &  " DEL ATT: no attribute "//TRIM(td_att%c_name)//&
+            &  ", in file "//TRIM(td_file%c_name) )
+
+         ELSE
+            
+            CALL logger_debug( &
+            &  " DEL ATT: del attribute "//TRIM(td_att%c_name)//&
+            &  ", in file "//TRIM(td_file%c_name) )
+
+            ALLOCATE( tl_att(td_file%i_natt-1), stat=il_status )
+            IF(il_status /= 0 )THEN
+
+               CALL logger_error( &
+               &  " ADD ATT: not enough space to put attributes from "//&
+               &  TRIM(td_file%c_name)//" in temporary attribute structure")
+
+            ELSE
+
+               ! save temporary global attribute's file structure
+               tl_att(1:il_attid-1)=td_file%t_att(1:il_attid-1)
+               tl_att(il_attid:)=td_file%t_att(il_attid+1:)
+
+               DEALLOCATE( td_file%t_att )
+
+               ! new number of attribute in file
+               td_file%i_natt=td_file%i_natt-1
+
+               ALLOCATE( td_file%t_att(td_file%i_natt), stat=il_status )
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( &
+                  &  " ADD ATT: not enough space to put attributes "//&
+                  &  "in file structure "//TRIM(td_file%c_name) )
+
+               ENDIF
+
+               ! copy attribute in file before
+               td_file%t_att(1:td_file%i_natt)=tl_att(:)
+
+               ! update attribute id
+               DO ji=1,td_file%i_natt
+                  td_file%t_att(ji)%i_id=ji
+               ENDDO
+
+               DEALLOCATE(tl_att)
+            ENDIF 
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE file__del_att_str
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine move a global attribute structure 
+   !> from file structure.
+   !> @note attribute id could be change
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] td_att : attribute structure
+   !> @todo
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file_move_att(td_file, td_att)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      TYPE(TATT),  INTENT(IN)    :: td_att
+
+      ! local variable
+      TYPE(TATT)  :: tl_att
+      INTEGER(i4) :: il_attid
+      !----------------------------------------------------------------
+
+      ! copy attribute
+      tl_att=td_att
+
+      IF( ASSOCIATED(td_file%t_att) )THEN
+         il_attid=att_get_id(td_file%t_att(:),TRIM(tl_att%c_name))
+         IF( il_attid /= 0 )THEN
+            ! remove attribute with same name
+            CALL file_del_att(td_file, tl_att)
+         ENDIF
+      ENDIF
+
+      ! add new attribute
+      CALL file_add_att(td_file, tl_att)
+
+   END SUBROUTINE file_move_att
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a dimension structure in file 
+   !> structure.
+   !> Do not overwrite, if dimension already in file structure.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] td_dim : dimension structure
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file_add_dim(td_file, td_dim)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      TYPE(TDIM),  INTENT(IN)    :: td_dim
+
+      ! local variable
+      INTEGER(i4) :: il_dimid
+      !----------------------------------------------------------------
+      ! check if file opened
+      !IF( TRIM(td_file%c_name) == "unknown" )THEN
+      IF( TRIM(td_file%c_name) == '' )THEN
+
+         CALL logger_error( " ADD DIM: file structure unknown ")
+         CALL logger_debug( " ADD DIM: you should have used file_init before "//&
+         & "running file_add_dim" )      
+
+      ELSE
+
+         IF( td_file%i_ndim <= 4 )THEN
+
+            ! check if dimension already in file structure
+            il_dimid=dim_get_id(td_file%t_dim(:), td_dim%c_name, td_dim%c_sname)
+            IF( il_dimid /= 0 )THEN
+
+               CALL logger_warn("ADD DIM: dimension "//TRIM(td_dim%c_name)//&
+               &  ", short name "//TRIM(td_dim%c_sname)//&
+               &  ", already in file "//TRIM(td_file%c_name) )
+
+               IF( td_file%t_dim(il_dimid)%i_len /= td_dim%i_len )THEN
+                  CALL logger_error( &
+                  &  "ADD DIM: dimension "//TRIM(td_dim%c_name)//&
+                  &  " already in file "//TRIM(td_file%c_name)//&
+                  &  " differ from added dimension ")
+               ENDIF
+
+            ELSE
+
+               CALL logger_debug( &
+               &  " ADD DIM: add dimension "//TRIM(td_dim%c_name)//&
+               &  ", short name "//TRIM(td_dim%c_sname)//&
+               &  ", in file "//TRIM(td_file%c_name) )
+
+               IF( td_file%i_ndim == 4 )THEN
+                  ! search empty dimension
+                  il_dimid=dim_get_void_id(td_file%t_dim(:),TRIM(td_dim%c_name), &
+                  &                                         TRIM(td_dim%c_sname))
+                  ! replace empty dimension
+                  td_file%t_dim(il_dimid)=td_dim
+                  td_file%t_dim(il_dimid)%i_id=il_dimid
+                  td_file%t_dim(il_dimid)%l_use=.TRUE.
+               ELSE
+                  ! add new dimension
+                  il_dimid=dim_get_void_id(td_file%t_dim(:),TRIM(td_dim%c_name), &
+                  &                                         TRIM(td_dim%c_sname))
+                  td_file%t_dim(il_dimid)=td_dim
+                  td_file%t_dim(il_dimid)%i_id=td_file%i_ndim+1
+                  td_file%t_dim(il_dimid)%l_use=.TRUE.
+                  ! update number of attribute
+                  td_file%i_ndim=COUNT(td_file%t_dim(:)%l_use)
+               ENDIF
+
+               ! reorder dimension to ('x','y','z','t')
+               CALL dim_reorder(td_file%t_dim)
+               
+            ENDIF
+         ELSE
+            CALL logger_error( &
+            &  " ADD DIM: too much dimension in file "//&
+            &  TRIM(td_file%c_name)//" ("//TRIM(fct_str(td_file%i_ndim))//")")
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE file_add_dim
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine delete a dimension structure in file 
+   !> structure.<br/>
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] td_dim : dimension structure
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file_del_dim(td_file, td_dim)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      TYPE(TDIM),  INTENT(IN)    :: td_dim
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_dimid
+      TYPE(TDIM), DIMENSION(:), ALLOCATABLE  :: tl_dim
+      !----------------------------------------------------------------
+      ! check if file opened
+      !IF( TRIM(td_file%c_name) == "unknown" )THEN
+      IF( TRIM(td_file%c_name) == '' )THEN
+
+         CALL logger_error( " DEL DIM: file structure unknown ")
+         CALL logger_debug( " DEL DIM: you should have used file_init before "//&
+         & "running file_del_dim" )      
+
+      ELSE
+
+         IF( td_file%i_ndim <= 4 )THEN
+
+            ! check if dimension already in file structure
+            il_dimid=dim_get_id(td_file%t_dim(:), td_dim%c_name, td_dim%c_sname)
+            IF( il_dimid == 0 )THEN
+
+               CALL logger_error( &
+               &  " DEL DIM: no dimension "//TRIM(td_dim%c_name)//&
+               &  ", short name "//TRIM(td_dim%c_sname)//&
+               &  ", in file "//TRIM(td_file%c_name) )
+
+            ELSE
+
+               CALL logger_debug( &
+               &  " DEL DIM: delete dimension "//TRIM(td_dim%c_name)//&
+               &  ", short name "//TRIM(td_dim%c_sname)//&
+               &  ", in file "//TRIM(td_file%c_name) )
+
+               IF( td_file%i_ndim == 4 )THEN
+                  ALLOCATE( tl_dim(1), stat=il_status )
+                  IF(il_status /= 0 )THEN
+                     CALL logger_error( &
+                     &  " DEL DIM: not enough space to put dimensions from "//&
+                     &  TRIM(td_file%c_name)//" in temporary dimension structure")
+                  ELSE
+                     ! replace dimension by empty one
+                     td_file%t_dim(il_dimid)=tl_dim(1)
+                  ENDIF
+                  DEALLOCATE(tl_dim)
+               ELSE
+                  ! 
+                  !ALLOCATE( tl_dim(td_file%i_ndim), stat=il_status )
+                  ALLOCATE( tl_dim(ip_maxdim), stat=il_status )
+                  IF(il_status /= 0 )THEN
+
+                     CALL logger_error( &
+                     &  " DEL DIM: not enough space to put dimensions from "//&
+                     &  TRIM(td_file%c_name)//" in temporary dimension structure")
+
+                  ELSE
+
+                     print *,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
+                     print *,'il_dimid '//TRIM(fct_str(il_dimid))
+                     CALL dim_print(td_file%t_dim(:))
+                     ! save temporary dimension's file structure
+                     tl_dim( 1 : il_dimid-1 ) = td_file%t_dim( 1 : il_dimid-1 )
+                     !tl_dim( il_dimid : td_file%i_ndim-1 ) = &
+                     !&           td_file%t_dim( il_dimid+1 : td_file%i_ndim )
+                     tl_dim( il_dimid : ip_maxdim-1 ) = &
+                     &           td_file%t_dim( il_dimid+1 : ip_maxdim )
+                     print *,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
+                     CALL dim_print(tl_dim(:))
+
+                     ! copy dimension in file, except one
+                     !td_file%t_dim(1:td_file%i_ndim)=tl_dim(:)
+                     td_file%t_dim(:)=tl_dim(:)
+                     print *,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
+                     CALL dim_print(td_file%t_dim(:))
+
+                     ! update number of dimension
+                     td_file%i_ndim=td_file%i_ndim-1
+
+                  ENDIF
+               ENDIF
+
+               ! reorder dimension to ('x','y','z','t')
+               CALL dim_reorder(td_file%t_dim)
+
+            ENDIF
+         ELSE
+            CALL logger_error( &
+            &  " DEL DIM: too much dimension in file "//&
+            &  TRIM(td_file%c_name)//" ("//TRIM(fct_str(td_file%i_ndim))//")")
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE file_del_dim
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine move a dimension structure 
+   !> in file structure.
+   !> @warning dimension order Nov have changed
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] td_dim : dimension structure
+   !> @todo
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file_move_dim(td_file, td_dim)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      TYPE(TDIM),  INTENT(IN)    :: td_dim
+
+      ! local variable
+      TYPE(TDIM)  :: tl_dim
+      INTEGER(i4) :: il_dimid
+      !----------------------------------------------------------------
+
+      ! copy dimension
+      tl_dim=td_dim
+
+      il_dimid=dim_get_id(td_file%t_dim(:), TRIM(td_dim%c_name), &
+      &                                     TRIM(td_dim%c_sname))
+      IF( il_dimid /= 0 )THEN
+         ! remove dimension with same name
+         CALL file_del_dim(td_file, tl_dim)
+      ENDIF
+
+      ! add new dimension
+      CALL file_add_dim(td_file, tl_dim)
+
+   END SUBROUTINE file_move_dim
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine print some information about file strucutre.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file_print(td_file)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_file
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_mode
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      cl_mode='READ'
+      IF( td_file%l_wrt ) cl_mode='WRITE'
+
+      WRITE(*,'((a,a),2(/3x,a,a),4(/3x,a,i0))')&
+      &  "File : ",TRIM(td_file%c_name), &
+      &  " type : ",TRIM(td_file%c_type), &
+      &  " mode : ",TRIM(cl_mode), &
+      &  " id   : ",td_file%i_id, &
+      &  " ndim : ",td_file%i_ndim, &
+      &  " natt : ",td_file%i_natt, &
+      &  " nvar : ",td_file%i_nvar
+
+      SELECT CASE(TRIM(td_file%c_type))
+         CASE('cdf')
+            WRITE(*,'((/3x,a,a),(/3x,a,i3))')&
+            &  "define mode : ",TRIM(fct_str(td_file%l_def)),&
+            &  "unlimited id : ",td_file%i_uldid
+         CASE('dimg')
+            WRITE(*,'(5(/3x,a,i0))')&
+            &  " record length : ",td_file%i_recl, &
+            &  " n0d : ",td_file%i_n0d, &
+            &  " n1d : ",td_file%i_n1d, &
+            &  " n2d : ",td_file%i_n2d, &
+            &  " n3d : ",td_file%i_n3d
+      END SELECT
+
+      ! print dimension
+      IF(  td_file%i_ndim /= 0 )THEN
+         WRITE(*,'(/a)') " File dimension"
+         DO ji=1,ip_maxdim
+            IF( td_file%t_dim(ji)%l_use )THEN
+               CALL dim_print(td_file%t_dim(ji))
+            ENDIF
+         ENDDO
+      ENDIF
+
+      ! print global attribute
+      IF( td_file%i_natt /= 0 )THEN
+         WRITE(*,'(/a)') " File attribute"
+         DO ji=1,td_file%i_natt
+            CALL att_print(td_file%t_att(ji))
+         ENDDO
+      ENDIF
+
+      ! print variable
+      IF( td_file%i_nvar /= 0 )THEN
+         WRITE(*,'(/a)') " File variable"
+         DO ji=1,td_file%i_nvar
+            CALL var_print(td_file%t_var(ji))!,.FALSE.)
+         ENDDO
+      ENDIF
+
+   END SUBROUTINE file_print
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function get suffix of file name.
+   !> @details
+   !> we assume suffix is define as alphanumeric character following the
+   !> last '.' in file name
+   !> If no suffix is found, return empty character.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_file : file structure
+   !> @return suffix
+   !-------------------------------------------------------------------
+   !> @code
+   CHARACTER(LEN=lc) FUNCTION file__get_suffix(cd_file)
+      IMPLICIT NONE
+
+      ! Argument      
+      CHARACTER(LEN=*), INTENT(IN) :: cd_file
+
+      ! local variable
+      INTEGER(i4) :: il_ind
+      !----------------------------------------------------------------
+
+      CALL logger_trace( "GET SUFFIX: look for suffix in file name "//&
+      &               TRIM(cd_file) )
+
+      il_ind=INDEX(TRIM(cd_file),'.',BACK=.TRUE.)
+      IF( il_ind /= 0 )THEN
+         ! read number in basename
+         READ( cd_file(il_ind:),'(a)' ) file__get_suffix
+
+         IF( fct_is_num(file__get_suffix) )THEN
+            file__get_suffix=''
+         ENDIF
+
+      ELSE
+         file__get_suffix=''
+      ENDIF
+
+   END FUNCTION file__get_suffix
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function get number in file name without suffix.
+   !> @details
+   !> Actually it get the number following the last separator.
+   !> separator could be '.' or '_'
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_file : file name (without suffix)
+   !> @return file structure
+   !-------------------------------------------------------------------
+   !> @code
+   CHARACTER(LEN=lc) FUNCTION file__get_number(cd_file)
+      IMPLICIT NONE
+
+      ! Argument      
+      CHARACTER(LEN=lc), INTENT(IN) :: cd_file
+
+      ! local variable
+      INTEGER(i4) :: il_indmax
+      INTEGER(i4) :: il_ind
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! get number position in file name
+      il_indmax=0
+      DO ji=1,ig_nsep
+         il_ind=INDEX(TRIM(cd_file),TRIM(cg_sep(ji)),BACK=.TRUE.)
+         IF( il_ind > il_indmax )THEN
+            il_indmax=il_ind
+         ENDIF
+      ENDDO
+
+      IF( il_indmax /= 0 )THEN
+         ! read number in basename
+         READ( cd_file(il_indmax:),'(a)' ) file__get_number
+
+         IF( .NOT. fct_is_num(file__get_number(2:)) )THEN
+            file__get_number=''
+         ENDIF
+      ELSE
+         file__get_number=''
+      ENDIF
+
+   END FUNCTION file__get_number
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function rename file name.
+   !> @details
+   !> If no processor number is given, return file name without number
+   !> If processor number is given, return file name with new number
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_num : processor number (start to 1)
+   !> @return file structure
+   !-------------------------------------------------------------------
+   !> @code
+   CHARACTER(LEN=lc) FUNCTION file__rename_char(cd_file, id_num)
+      IMPLICIT NONE
+
+      ! Argument      
+      CHARACTER(LEN=*), INTENT(IN) :: cd_file
+      INTEGER(i4),      INTENT(IN), OPTIONAL :: id_num
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_suffix
+      CHARACTER(LEN=lc) :: cl_file
+      CHARACTER(LEN=lc) :: cl_number
+      CHARACTER(LEN=lc) :: cl_base
+      CHARACTER(LEN=lc) :: cl_sep
+      CHARACTER(LEN=lc) :: cl_format
+      INTEGER(i4)       :: il_ind
+      INTEGER(i4)       :: il_numlen
+      !----------------------------------------------------------------
+
+      ! get suffix
+      cl_suffix=file__get_suffix(cd_file)
+      IF( TRIM(cl_suffix) /= '' )THEN
+         il_ind=INDEX(TRIM(cd_file),TRIM(cl_suffix(1:1)),BACK=.TRUE.)
+         cl_file=TRIM(cd_file(:il_ind-1))
+      ELSE
+         cl_file=TRIM(cd_file)
+      ENDIF
+
+      cl_number=file__get_number(cl_file)
+      IF( TRIM(cl_number) /= '' )THEN
+         il_ind=INDEX(TRIM(cl_file),TRIM(cl_number(1:1)),BACK=.TRUE.)
+         cl_base=TRIM(cl_file(:il_ind-1))
+
+         cl_sep=TRIM(cl_number(1:1))
+         il_numlen=LEN(TRIM(cl_number))-1
+      ELSE
+         cl_base=TRIM(cl_file)
+         il_numlen=4
+         cl_sep='_'
+      ENDIF
+
+      IF( PRESENT(id_num) )THEN
+         ! format
+         WRITE(cl_format,'(a,i1.1,a,i1.1,a)') '(a,a,i',il_numlen,'.',il_numlen,',a)'
+         WRITE(file__rename_char,cl_format) TRIM(cl_base),TRIM(cl_sep),id_num,TRIM(cl_suffix)
+      ELSE
+         WRITE(file__rename_char,'(a,a)') TRIM(cl_base),TRIM(cl_suffix)
+      ENDIF
+      CALL logger_trace(" RENAME : "//TRIM(file__rename_char))
+
+   END FUNCTION file__rename_char
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function rename file name, given file structure.
+   !> @details
+   !> If no processor number is given, return file name without number
+   !> I processor number is given, return file name with new number
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_num : processor number (start to 1)
+   !> @return file structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TFILE) FUNCTION file__rename_str(td_file, id_num)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_file
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_num
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_name
+      !----------------------------------------------------------------
+
+      ! change name
+      cl_name=TRIM( file_rename(td_file%c_name, id_num) )
+
+      file__rename_str=file_init(TRIM(cl_name), TRIM(td_file%c_type))
+
+   END FUNCTION file__rename_str
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function add suffix to file name.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @return file structure
+   !-------------------------------------------------------------------
+   !> @code
+   CHARACTER(LEN=lc) FUNCTION file_add_suffix(cd_file, cd_type)
+      IMPLICIT NONE
+
+      ! Argument      
+      CHARACTER(LEN=*), INTENT(IN) :: cd_file
+      CHARACTER(LEN=*), INTENT(IN) :: cd_type
+
+      ! local variable
+      INTEGER(i4)       :: il_ind
+      CHARACTER(LEN=lc) :: cl_file
+      CHARACTER(LEN=lc) :: cl_suffix
+      !----------------------------------------------------------------
+      ! get suffix 
+      cl_suffix=file__get_suffix(cd_file)
+      IF( TRIM(cl_suffix) /= '' )THEN
+         il_ind=INDEX(TRIM(cd_file),TRIM(cl_suffix(1:1)),BACK=.TRUE.)
+         cl_file=TRIM(cd_file(:il_ind-1))
+      ELSE
+         cl_file=TRIM(cd_file)
+      ENDIF
+
+      SELECT CASE(TRIM(cd_type))
+         CASE('cdf')
+            file_add_suffix=TRIM(cl_file)//'.nc'
+         CASE('dimg')
+            IF( TRIM(cl_suffix) /= '' )THEN
+               file_add_suffix=TRIM(cl_file)//'.dimg'
+            ELSE
+               file_add_suffix=TRIM(cl_file)
+            ENDIF
+         CASE DEFAULT
+            CALL logger_error( " ADD SUFFIX: type unknown "//TRIM(cd_type) )
+      END SELECT
+
+   END FUNCTION file_add_suffix
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !>  This subroutine clean mpp strcuture.
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE file_clean( td_file )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE),  INTENT(INOUT) :: td_file
+
+      ! local variable
+      TYPE(TFILE) :: tl_file ! empty file structure
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      CALL logger_info( &
+      &  " CLEAN: reset file "//TRIM(td_file%c_name) )
+
+      ! del attribute
+      IF( ASSOCIATED( td_file%t_att ) )THEN
+         DO ji=td_file%i_natt,1,-1
+            CALL att_clean( td_file%t_att(ji) )
+         ENDDO
+         DEALLOCATE( td_file%t_att )
+      ENDIF
+
+      ! del dimension
+      IF( td_file%i_ndim /= 0 )THEN
+         DO ji=td_file%i_ndim,1,-1
+            CALL dim_clean( td_file%t_dim(ji) )
+         ENDDO
+      ENDIF
+
+      ! del variable
+      IF( ASSOCIATED( td_file%t_var ) )THEN
+         DO ji=td_file%i_nvar,1,-1
+            CALL var_clean( td_file%t_var(ji) )
+         ENDDO
+         DEALLOCATE( td_file%t_var )
+      ENDIF
+
+      ! replace by empty structure
+      td_file=tl_file
+
+   END SUBROUTINE file_clean
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function return the file id, in a table of file
+   !> structure,  given file name 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : table of file structure
+   !> @param[in] cd_name : file name
+   !> @return file id in table of file structure (0 if not found)
+   !-------------------------------------------------------------------
+   !> @code
+   INTEGER(i4) FUNCTION file_get_id(td_file, cd_name)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE)     , DIMENSION(:), INTENT(IN) :: td_file
+      CHARACTER(LEN=*),               INTENT(IN) :: cd_name
+
+      ! local variable
+      INTEGER(i4) :: il_size
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      file_get_id=0
+      il_size=SIZE(td_file(:))
+
+      ! check if file is in table of file structure
+      DO ji=1,il_size
+         ! look for file name
+         CALL logger_debug(" cd_name "//TRIM(fct_lower(cd_name)) )
+         IF( fct_lower(td_file(ji)%c_name) == fct_lower(cd_name) )THEN
+         
+            file_get_id=ji
+            EXIT
+
+         ENDIF
+      ENDDO
+
+   END FUNCTION file_get_id
+   !> @endcode
+END MODULE file
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/filter.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/filter.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/filter.f90	(revision 4245)
@@ -0,0 +1,1277 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: filter
+!
+! DESCRIPTION:
+!> @brief filter manager <br/>
+!>
+!> @details
+!> 
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!> @todo
+!----------------------------------------------------------------------
+MODULE filter
+   USE kind                            ! F90 kind parameter
+   USE phycst                          ! physical constant
+   USE logger                             ! log file manager
+   USE fct                             ! basic usefull function
+   use att                             ! attribute manager
+   USE var                             ! variable manager
+   USE extrap                          ! extrapolation manager
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+
+
+   ! function and subroutine
+   PUBLIC :: filter_fill_value
+
+   PRIVATE :: filter__fill_value_wrapper
+   PRIVATE :: filter__fill_value
+   PRIVATE :: filter__3D_fill_value
+   PRIVATE :: filter__2D_fill_value
+   PRIVATE :: filter__2D
+   PRIVATE :: filter__2D_coef
+   PRIVATE :: filter__2D_hann
+   PRIVATE :: filter__2D_hamming
+   PRIVATE :: filter__2D_blackman
+   PRIVATE :: filter__2D_gauss
+   PRIVATE :: filter__2D_butterworth
+
+   INTERFACE filter_fill_value
+      MODULE PROCEDURE filter__fill_value_wrapper
+   END INTERFACE filter_fill_value
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine filtering variable value.
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE filter__fill_value_wrapper( td_var )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_filter
+      CHARACTER(LEN=lc) :: cl_method
+      INTEGER(I4)       :: il_radius
+      INTEGER(I4)       :: il_nturn
+      REAL(dp)          :: dl_cutoff 
+      REAL(dp)          :: dl_alpha
+
+      TYPE(TATT)        :: tl_att
+
+      ! loop indices
+      INTEGER(I4) :: jl
+      !----------------------------------------------------------------
+
+      IF( .NOT. ASSOCIATED(td_var%d_value) )THEN
+         CALL logger_error("FILTER FILL VALUE: no table of value "//&
+         &  "associted to variable "//TRIM(td_var%c_name) )
+      ELSE
+
+         SELECT CASE(TRIM(td_var%c_filter(1)))
+
+         CASE DEFAULT
+         
+            CALL logger_info("FILTER FILL VALUE: no filter selected "//&
+            &  "for variable "//TRIM(td_var%c_name))
+
+         CASE('hann','hamming','blackman','gauss','butterworth')
+
+            cl_method=TRIM(td_var%c_filter(1))
+
+            ! look for number of turn to be done
+            READ(td_var%c_filter(2),*) il_nturn
+            IF( il_nturn < 0 )THEN
+               CALL logger_error("FILTER FILL VALUE: invalid "//&
+               &  "number of turn ("//TRIM(td_var%c_filter(2))//")")
+            ENDIF
+
+            ! look for cut-off frequency
+            dl_cutoff=2
+            IF( TRIM(td_var%c_filter(3)) /= '' )THEN
+               READ(td_var%c_filter(3),*) dl_cutoff
+            ENDIF
+            IF( dl_cutoff < 0 )THEN
+               CALL logger_error("FILTER FILL VALUE: invalid cut-off "//&
+               &  "frequency ("//TRIM(td_var%c_filter(3))//")")
+            ENDIF
+
+            ! look for halo size
+            il_radius=1
+            IF( TRIM(td_var%c_filter(4)) /= '' )THEN
+               READ(td_var%c_filter(4),*) il_radius
+            ENDIF
+            IF( il_radius < 0 )THEN
+               CALL logger_error("FILTER FILL VALUE: invalid halo radius "//&
+               &  " ("//TRIM(td_var%c_filter(4))//")")
+            ENDIF
+
+            IF( REAL(2*il_radius+1,dp) < dl_cutoff )THEN
+               CALL logger_error("FILTER FILL VALUE: radius of halo and "//&
+               &  "spatial cut-off frequency are not suitable.")
+            ENDIF
+
+            ! look for alpha parameter
+            dl_alpha=2
+            IF( TRIM(td_var%c_filter(5)) /= '' )THEN
+               READ(td_var%c_filter(5),*) dl_alpha
+            ENDIF
+
+            SELECT CASE(TRIM(cl_method))
+            CASE('gauss','butterworth')
+               CALL logger_info("FILTER FILL VALUE: filtering "//&
+               &   " variable "//TRIM(td_var%c_name)//&
+               &   " using "//TRIM(fct_str(il_nturn))//" turn"//&
+               &   " of "//TRIM(cl_method)//" method,"//&
+               &   " with cut-off frequency of "//&
+               &        TRIM(fct_str(REAL(dl_cutoff,sp)))//&
+               &   ", halo's radius of "//&
+               &        TRIM(fct_str(il_radius))//&
+               &   ", and alpha parameter of "//&
+               &        TRIM(fct_str(REAL(dl_alpha,sp))) )
+            CASE DEFAULT
+               CALL logger_info("FILTER FILL VALUE: filtering "//&
+               &   " variable "//TRIM(td_var%c_name)//&
+               &   " using "//TRIM(fct_str(il_nturn))//" turn"//&
+               &   " of "//TRIM(cl_method)//" method,"//&
+               &   " with cut-off frequency of "//&
+               &        TRIM(fct_str(REAL(dl_cutoff,sp)))//&
+               &   " and halo's radius of "//&
+               &        TRIM(fct_str(il_radius)) )
+            END SELECT
+      
+            IF( .NOT. ANY(td_var%t_dim(1:3)%l_use) )THEN
+               ! no dimension I-J-K used
+               CALL logger_debug("FILTER FILL VALUE: no filtering can "//&
+               &  "be done for variable "//TRIM(td_var%c_name))
+            ELSE 
+
+               ! add attribute to variable
+               SELECT CASE(TRIM(cl_method))
+               CASE('gauss','butterworth')
+                  cl_filter=TRIM(fct_str(il_nturn))//'*'//TRIM(cl_method)//&
+                  &                    '('//TRIM(fct_str(REAL(dl_cutoff,sp)))//","//&
+                  &                         TRIM(fct_str(il_radius))//","//&
+                  &                         TRIM(fct_str(REAL(dl_alpha,sp)))//')'
+               CASE DEFAULT
+                  cl_filter=TRIM(fct_str(il_nturn))//'*'//TRIM(cl_method)//&
+                  &                    '('//TRIM(fct_str(REAL(dl_cutoff,sp)))//","//&
+                  &                         TRIM(fct_str(il_radius))//')'
+               END SELECT
+               tl_att=att_init('filter',cl_filter)
+               CALL var_move_att(td_var,tl_att)
+               
+               DO jl=1,il_nturn
+                  CALL filter__fill_value( td_var, TRIM(cl_method),  & 
+                  &                        dl_cutoff, il_radius, dl_alpha )
+               ENDDO
+            ENDIF               
+
+         END SELECT
+
+      ENDIF
+   END SUBROUTINE filter__fill_value_wrapper
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine filtering variable value.
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable 
+   !> @param[in] cd_name : filter name
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @param[in] dd_alpha : filter parameter
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE filter__fill_value( td_var, cd_name, &
+   &                              dd_cutoff, id_radius, dd_alpha )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR)      , INTENT(INOUT) :: td_var
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_name
+      REAL(dp)        , INTENT(IN   ) :: dd_cutoff 
+      INTEGER(I4)     , INTENT(IN   ) :: id_radius
+      REAL(dp)        , INTENT(IN   ) :: dd_alpha
+
+      ! local variable
+      TYPE(TVAR)                                         :: tl_mask
+
+      INTEGER(i1)      , DIMENSION(:,:,:,:), ALLOCATABLE :: bl_mask
+
+      ! loop indices
+      INTEGER(i4) :: jl
+      !----------------------------------------------------------------
+
+      CALL logger_debug("FILTER: "//TRIM(fct_str(td_var%d_fill)) )
+
+      !1-add extraband
+      CALL extrap_add_extrabands(td_var, id_radius, id_radius)
+
+      !2-compute mask
+      ALLOCATE(bl_mask(td_var%t_dim(1)%i_len, &
+      &                td_var%t_dim(2)%i_len, &
+      &                td_var%t_dim(3)%i_len, &
+      &                td_var%t_dim(4)%i_len) )
+
+      bl_mask(:,:,:,:)=1
+      WHERE(td_var%d_value(:,:,:,:)==td_var%d_fill) bl_mask(:,:,:,:)=0      
+
+      tl_mask=var_init('tmask', bl_mask(:,:,:,:))
+
+      DEALLOCATE(bl_mask)
+
+      !3-extrapolate
+      CALL extrap_fill_value( td_var, id_iext=id_radius, id_jext=id_radius )
+
+      !4-filtering
+      DO jl=1,td_var%t_dim(4)%i_len
+         IF( ALL(td_var%t_dim(1:3)%l_use) )THEN
+            ! dimension I-J-K used
+            CALL filter__3D_fill_value( td_var%d_value(:,:,:,jl),       &
+            &                           td_var%d_fill, TRIM(cd_name), &
+            &                           dd_cutoff, id_radius, dd_alpha)
+         ELSE IF( ALL(td_var%t_dim(1:2)%l_use) )THEN 
+            ! dimension I-J used
+            CALL filter__2D_fill_value( td_var%d_value(:,:,1,jl),       &
+            &                           td_var%d_fill, TRIM(cd_name), &
+            &                           dd_cutoff, id_radius, dd_alpha)         
+         ELSE IF( td_var%t_dim(3)%l_use )THEN 
+            ! dimension K used
+            CALL filter__1D_fill_value( td_var%d_value(1,1,:,jl),       &
+            &                           td_var%d_fill, TRIM(cd_name), &
+            &                           dd_cutoff, id_radius, dd_alpha)         
+         ENDIF
+      ENDDO
+
+      !5-keep original mask
+      WHERE( tl_mask%d_value(:,:,:,:) == 0 )
+         td_var%d_value(:,:,:,:)=td_var%d_fill
+      END WHERE
+
+      !6-remove extraband
+      CALL extrap_del_extrabands(td_var, id_radius, id_radius)
+
+   END SUBROUTINE filter__fill_value
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine compute filtered value of 3D table. 
+   !>
+   !> @details
+   !>
+   !> @warning table of value should have been already extrapolated before
+   !> running this subroutine.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] dd_value : table of value to be filtered 
+   !> @param[in] dd_fill : fill value 
+   !> @param[in] cd_name : filter name
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @param[in] dd_alpha : filter parameter
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE filter__3D_fill_value( dd_value, dd_fill, cd_name, &
+   &                                 dd_cutoff, id_radius, dd_alpha)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)        , DIMENSION(:,:,:), INTENT(INOUT) :: dd_value
+      REAL(dp)        ,                   INTENT(IN   ) :: dd_fill
+      CHARACTER(LEN=*),                   INTENT(IN   ) :: cd_name
+      REAL(dp)        ,                   INTENT(IN   ) :: dd_cutoff
+      INTEGER(i4)     ,                   INTENT(IN   ) :: id_radius
+      REAL(dp)        ,                   INTENT(IN   ) :: dd_alpha      
+
+      ! local variable
+      INTEGER(i4), DIMENSION(3)                :: il_shape
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_coef
+
+      ! loop indices
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+      
+      il_shape(:)=SHAPE(dd_value(:,:,:))
+
+      ALLOCATE( dl_coef(2*id_radius+1,2*id_radius+1) )
+
+      dl_coef(:,:)=filter__2D_coef(cd_name, dd_cutoff, id_radius, dd_alpha)
+
+      DO jk=1,il_shape(3)
+         CALL filter__2D(dd_value(:,:,jk), dd_fill,dl_coef(:,:),id_radius)
+      ENDDO
+
+      DEALLOCATE( dl_coef )
+
+   END SUBROUTINE filter__3D_fill_value
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine compute filtered value of 2D table.
+   !
+   !> @details
+   !
+   !> @warning table of value should have been already extrapolated before
+   !> running this subroutine.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] dd_value : table of value to be filtered 
+   !> @param[in] dd_fill : fill value 
+   !> @param[in] cd_name : filter name
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @param[in] dd_alpha : filter parameter
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE filter__2D_fill_value( dd_value, dd_fill, cd_name, &
+   &                                 dd_cutoff, id_radius, dd_alpha)
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)        , DIMENSION(:,:), INTENT(INOUT) :: dd_value
+      REAL(dp)        ,                 INTENT(IN   ) :: dd_fill
+      CHARACTER(LEN=*),                 INTENT(IN   ) :: cd_name
+      REAL(dp)        ,                 INTENT(IN   ) :: dd_cutoff
+      INTEGER(i4)     ,                 INTENT(IN   ) :: id_radius
+      REAL(dp)        ,                 INTENT(IN   ) :: dd_alpha      
+
+      ! local variable
+
+      REAL(dp), DIMENSION(:,:), ALLOCATABLE :: dl_coef
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ALLOCATE( dl_coef(2*id_radius+1,2*id_radius+1) )
+
+      dl_coef(:,:)=filter__2D_coef(cd_name, dd_cutoff, id_radius, dd_alpha)
+
+      CALL filter__2D(dd_value(:,:), dd_fill, dl_coef(:,:), id_radius)
+
+      DEALLOCATE( dl_coef )
+
+   END SUBROUTINE filter__2D_fill_value
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine compute filtered value of 1D table.
+   !
+   !> @details
+   !
+   !> @warning table of value should have been already extrapolated before
+   !> running this subroutine.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] dd_value : table of value to be filtered 
+   !> @param[in] dd_fill : fill value 
+   !> @param[in] cd_name : filter name
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @param[in] dd_alpha : filter parameter
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE filter__1D_fill_value( dd_value, dd_fill, cd_name, &
+   &                                 dd_cutoff, id_radius, dd_alpha)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)        , DIMENSION(:), INTENT(INOUT) :: dd_value
+      REAL(dp)        ,               INTENT(IN   ) :: dd_fill
+      CHARACTER(LEN=*),               INTENT(IN   ) :: cd_name
+      REAL(dp)        ,               INTENT(IN   ) :: dd_cutoff
+      INTEGER(i4)     ,               INTENT(IN   ) :: id_radius
+      REAL(dp)        ,               INTENT(IN   ) :: dd_alpha      
+
+      ! local variable
+
+      REAL(dp), DIMENSION(:), ALLOCATABLE :: dl_coef
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ALLOCATE( dl_coef(2*id_radius+1) )
+
+      dl_coef(:)=filter__1D_coef(cd_name, dd_cutoff, id_radius, dd_alpha)
+
+      CALL filter__1D(dd_value(:), dd_fill, dl_coef(:),id_radius)
+
+      DEALLOCATE( dl_coef )
+
+   END SUBROUTINE filter__1D_fill_value
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine 
+   !
+   !> @details
+   !
+   !> @note 
+   !> if fill value are detected in the computing area, 
+   !> no filtering is done.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] dd_value : table of value to be filtered 
+   !> @param[in] dd_fill : fill value 
+   !> @param[in] dd_coef :  filter coefficent table
+   !> @param[in] id_radius : filter halo radius
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE filter__2D(dd_value, dd_fill, dd_coef, id_radius)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)        , DIMENSION(:,:), INTENT(INOUT) :: dd_value
+      REAL(dp)        ,                 INTENT(IN   ) :: dd_fill 
+      REAL(dp)        , DIMENSION(:,:), INTENT(IN   ) :: dd_coef 
+      INTEGER(i4)     ,                 INTENT(IN   ) :: id_radius
+
+      ! local variable
+      INTEGER(i4), DIMENSION(2)                :: il_shape
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_value
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_area
+
+      ! loop indices
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      il_shape(:)=SHAPE(dd_value(:,:))
+
+      ALLOCATE(dl_value(il_shape(1),il_shape(2)))
+      dl_value(:,:)=dd_value(:,:)
+
+      ALLOCATE(dl_area(2*id_radius+1,2*id_radius+1))
+
+      DO jj=1+id_radius,il_shape(2)-id_radius
+         DO ji=1+id_radius,il_shape(1)-id_radius
+
+            dl_area(:,:)=dd_fill
+            dl_area(:,:)=dl_value(ji-id_radius:ji+id_radius, &
+            &                     jj-id_radius:jj+id_radius)
+
+            IF( ALL(dl_area(:,:)/=dd_fill) )THEN
+               dd_value(ji,jj)=SUM(dl_area(:,:)*dd_coef(:,:))
+            ENDIF
+
+         ENDDO
+      ENDDO
+
+      DEALLOCATE(dl_area)
+      DEALLOCATE(dl_value)
+
+   END SUBROUTINE filter__2D
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine 
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] dd_value : table of value to be filtered 
+   !> @param[in] dd_fill : fill value 
+   !> @param[in] dd_coef :  filter coefficent table
+   !> @param[in] id_radius : filter halo radius
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE filter__1D(dd_value, dd_fill, dd_coef, id_radius)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)        , DIMENSION(:), INTENT(INOUT) :: dd_value
+      REAL(dp)        ,               INTENT(IN   ) :: dd_fill 
+      REAL(dp)        , DIMENSION(:), INTENT(IN   ) :: dd_coef 
+      INTEGER(i4)     ,               INTENT(IN   ) :: id_radius
+
+      ! local variable
+      INTEGER(i4), DIMENSION(1)                :: il_shape
+      REAL(dp)   , DIMENSION(:), ALLOCATABLE :: dl_value
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      il_shape(:)=SHAPE(dd_value(:))
+
+      ALLOCATE(dl_value(2*id_radius+1))
+
+      DO ji=1+id_radius,il_shape(1)-id_radius
+
+         dl_value(:)=dd_value(ji-id_radius:ji+id_radius)
+
+         IF( ANY(dl_value(:)==dd_fill) )THEN
+            CALL logger_error("FILTER FILL VALUE: fill value detected. "//&
+            &  " can't compute filtered value. "//&
+            &  "you should have extrapolate table before running "//&
+            &  " filter_fill_value")
+         ELSE
+            dd_value(ji)=SUM(dl_value(:)*dd_coef(:))
+         ENDIF
+
+      ENDDO
+
+      DEALLOCATE(dl_value)
+
+   END SUBROUTINE filter__1D
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute filter coefficient. 
+   !
+   !> @details
+   !> 
+   !> filter could be choose between :
+   !> - hann
+   !> - hamming
+   !> - blackman
+   !> - gauss
+   !> - butterworth
+   !> Cut-off frequency could be specify.
+   !> As well as a filter parameter for gauss an butterworth filter
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : filter name
+   !> @param[in] dd_cutoff : cut-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @param[in] dd_alpha : filter parameter 
+   !> @return table of filter coefficient
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION filter__2D_coef(cd_name, dd_cutoff, id_radius, dd_alpha)
+      IMPLICIT NONE
+      ! Argument      
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+      REAL(dp)        , INTENT(IN) :: dd_cutoff
+      INTEGER(i4)     , INTENT(IN) :: id_radius
+      REAL(dp)        , INTENT(IN) :: dd_alpha
+
+      ! function
+      REAL(dp), DIMENSION(2*id_radius+1,2*id_radius+1) :: filter__2D_coef
+
+      ! local variable
+
+      ! loop indices
+      !----------------------------------------------------------------
+      IF( REAL(id_radius,dp) < dd_cutoff )THEN
+         CALL logger_warn("FILTER COEF: radius of the filter halo "//&
+         &  "is lower than cut-off frequency")
+      ENDIF
+
+      SELECT CASE(TRIM(fct_lower(cd_name)))
+      CASE('hann')
+         filter__2D_coef(:,:)=filter__2D_hann(dd_cutoff, id_radius)
+      CASE('hamming')
+         filter__2D_coef(:,:)=filter__2D_hamming(dd_cutoff, id_radius)
+      CASE('blackman')
+         filter__2D_coef(:,:)=filter__2D_blackman(dd_cutoff, id_radius)
+      CASE('gauss')
+         filter__2D_coef(:,:)=filter__2D_gauss(dd_cutoff, id_radius, dd_alpha)
+      CASE('butterworth')
+         filter__2D_coef(:,:)=filter__2D_butterworth(dd_cutoff, id_radius, dd_alpha)
+      CASE DEFAULT
+         CALL logger_error("FILTER COEF: invalid filter name :"//TRIM(cd_name))
+      END SELECT
+
+   END FUNCTION filter__2D_coef
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute filter coefficient. 
+   !
+   !> @details
+   !> 
+   !> filter could be choose between :
+   !> - hann
+   !> - hamming
+   !> - blackman
+   !> - gauss
+   !> - butterworth
+   !> Cut-off frequency could be specify.
+   !> As well as a filter parameter for gauss an butterworth filter
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : filter name
+   !> @param[in] dd_cutoff : cut-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @param[in] dd_alpha : filter parameter 
+   !> @return table of filter coefficient
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION filter__1D_coef(cd_name, dd_cutoff, id_radius, dd_alpha)
+      IMPLICIT NONE
+      ! Argument      
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+      REAL(dp)        , INTENT(IN) :: dd_cutoff
+      INTEGER(i4)     , INTENT(IN) :: id_radius
+      REAL(dp)        , INTENT(IN) :: dd_alpha
+
+      ! function
+      REAL(dp), DIMENSION(2*id_radius+1) :: filter__1D_coef
+
+      ! local variable
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      SELECT CASE(TRIM(fct_lower(cd_name)))
+      CASE('hann')
+         filter__1D_coef(:)=filter__1D_hann(dd_cutoff, id_radius)
+      CASE('hamming')
+         filter__1D_coef(:)=filter__1D_hamming(dd_cutoff, id_radius)
+      CASE('blackman')
+         filter__1D_coef(:)=filter__1D_blackman(dd_cutoff, id_radius)
+      CASE('gauss')
+         filter__1D_coef(:)=filter__1D_gauss(dd_cutoff, id_radius, dd_alpha)
+      CASE('butterworth')
+         filter__1D_coef(:)=filter__1D_butterworth(dd_cutoff, id_radius, dd_alpha)
+      CASE DEFAULT
+         CALL logger_error("FILTER COEF: invalid filter name :"//TRIM(cd_name))
+      END SELECT
+
+   END FUNCTION filter__1D_coef
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute coefficient for HANN filter.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @return table of hann filter coefficient 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION filter__1D_hann(dd_cutoff, id_radius)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)        , INTENT(IN) :: dd_cutoff 
+      INTEGER(i4)     , INTENT(IN) :: id_radius
+
+      ! function
+      REAL(dp), DIMENSION(2*id_radius+1) :: filter__1D_hann
+
+      ! local variable
+      REAL(dp) :: dl_rad
+      REAL(dp) :: dl_sum
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( dd_cutoff < 1 )THEN
+         CALL logger_error("FILTER COEF: cut-off frequency "//&
+         &  "should be greater than or equal to 1. No filter will be apply ")
+         filter__1D_hann(:)=0.
+         filter__1D_hann(id_radius+1)=1.
+      ELSE
+         DO ji=1,2*id_radius+1
+
+            dl_rad=SQRT(REAL(ji-id_radius+1,dp)**2 )
+            
+            IF( dl_rad < dd_cutoff )THEN
+               filter__1D_hann(ji)=0.5 + 0.5*COS(dg_pi*dl_rad/dd_cutoff)
+            ELSE
+               filter__1D_hann(ji)=0
+            ENDIF
+
+         ENDDO
+
+         ! normalize
+         dl_sum=SUM(filter__1D_hann(:))
+
+         filter__1D_hann(:)=filter__1D_hann(:)/dl_sum
+      ENDIF
+
+   END FUNCTION filter__1D_hann
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute coefficient for HANN filter.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @return table of hann filter coefficient 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION filter__2D_hann(dd_cutoff, id_radius)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)   , INTENT(IN) :: dd_cutoff 
+      INTEGER(i4), INTENT(IN) :: id_radius
+
+      ! function
+      REAL(dp), DIMENSION(2*id_radius+1,2*id_radius+1) :: filter__2D_hann
+
+      ! local variable
+      REAL(dp) :: dl_rad
+      REAL(dp) :: dl_sum
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      IF( dd_cutoff < 1.0_dp )THEN
+         CALL logger_error("FILTER COEF: cut-off frequency "//&
+         &  "should be greater than or equal to 1. No filter will be apply ")
+         filter__2D_hann(:,:)=0.
+         filter__2D_hann(id_radius+1,id_radius+1)=1.
+      ELSE
+         DO jj=1,2*id_radius+1
+            DO ji=1,2*id_radius+1
+
+               ! radius
+               dl_rad= SQRT( REAL(ji-(id_radius+1),dp)**2 + &
+               &             REAL(jj-(id_radius+1),dp)**2 )
+               
+               IF( dl_rad < dd_cutoff )THEN
+                  filter__2D_hann(ji,jj)=0.5 + 0.5*COS(dg_pi*dl_rad/dd_cutoff)
+               ELSE
+                  filter__2D_hann(ji,jj)=0
+               ENDIF
+
+            ENDDO
+         ENDDO
+
+         ! normalize
+         dl_sum=SUM(filter__2D_hann(:,:))
+
+         filter__2D_hann(:,:)=filter__2D_hann(:,:)/dl_sum
+      ENDIF
+
+   END FUNCTION filter__2D_hann
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute coefficient for HAMMING filter.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @return table of hamming filter coefficient 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION filter__1D_hamming(dd_cutoff, id_radius)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)        , INTENT(IN) :: dd_cutoff 
+      INTEGER(i4)     , INTENT(IN) :: id_radius
+
+      ! function
+      REAL(dp), DIMENSION(2*id_radius+1) :: filter__1D_hamming
+
+      ! local variable
+      REAL(dp) :: dl_rad
+      REAL(dp) :: dl_sum
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( dd_cutoff < 1 )THEN
+         CALL logger_error("FILTER COEF: cut-off frequency "//&
+         &  "should be greater than or equal to 1. No filter will be apply ")
+         filter__1D_hamming(:)=0.
+         filter__1D_hamming(id_radius+11)=1.
+      ELSE
+         DO ji=1,2*id_radius+1
+
+            dl_rad= SQRT( REAL(ji-(id_radius+1),dp)**2 )
+         
+            IF( dl_rad < dd_cutoff )THEN
+               filter__1D_hamming(ji)= 0.54 &
+               &                     + 0.46*COS(dg_pi*dl_rad/dd_cutoff)
+            ELSE
+               filter__1D_hamming(ji)=0
+            ENDIF
+
+         ENDDO
+
+         ! normalize
+         dl_sum=SUM(filter__1D_hamming(:))
+
+         filter__1D_hamming(:)=filter__1D_hamming(:)/dl_sum
+      ENDIF
+
+   END FUNCTION filter__1D_hamming
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute coefficient for HAMMING filter.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @return table of hamming filter coefficient 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION filter__2D_hamming(dd_cutoff, id_radius)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)        , INTENT(IN) :: dd_cutoff 
+      INTEGER(i4)     , INTENT(IN) :: id_radius
+
+      ! function
+      REAL(dp), DIMENSION(2*id_radius+1,2*id_radius+1) :: filter__2D_hamming
+
+      ! local variable
+      REAL(dp) :: dl_rad
+      REAL(dp) :: dl_sum
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      IF( dd_cutoff < 1 )THEN
+         CALL logger_error("FILTER COEF: cut-off frequency "//&
+         &  "should be greater than or equal to 1. No filter will be apply ")
+         filter__2D_hamming(:,:)=0.
+         filter__2D_hamming(id_radius+1,id_radius+1)=1.
+      ELSE
+         DO jj=1,2*id_radius+1
+            DO ji=1,2*id_radius+1
+
+               dl_rad= SQRT( REAL(ji-(id_radius+1),dp)**2 + &
+               &             REAL(jj-(id_radius+1),dp)**2 )
+            
+               IF( dl_rad < dd_cutoff )THEN
+                  filter__2D_hamming(ji,jj)= 0.54 &
+                  &                        + 0.46*COS(dg_pi*dl_rad/dd_cutoff)
+               ELSE
+                  filter__2D_hamming(ji,jj)=0
+               ENDIF
+
+            ENDDO
+         ENDDO
+
+         ! normalize
+         dl_sum=SUM(filter__2D_hamming(:,:))
+
+         filter__2D_hamming(:,:)=filter__2D_hamming(:,:)/dl_sum
+      ENDIF
+
+   END FUNCTION filter__2D_hamming
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute coefficient for BLACKMAN filter.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @return table of blackman filter coefficient 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION filter__1D_blackman(dd_cutoff, id_radius)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)        , INTENT(IN) :: dd_cutoff
+      INTEGER(i4)     , INTENT(IN) :: id_radius
+
+      ! function
+      REAL(dp), DIMENSION(2*id_radius+1) :: filter__1D_blackman
+
+      ! local variable
+      REAL(dp) :: dl_rad
+      REAL(dp) :: dl_sum
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( dd_cutoff < 1 )THEN
+         CALL logger_error("FILTER COEF: cut-off frequency "//&
+         &  "should be greater than or equal to 1. No filter will be apply ")
+         filter__1D_blackman(:)=0.
+         filter__1D_blackman(id_radius+1)=1.
+      ELSE      
+         DO ji=1,2*id_radius+1
+
+            dl_rad= SQRT( REAL(ji-(id_radius+1),dp)**2 )
+            
+            IF( dl_rad < dd_cutoff )THEN
+               filter__1D_blackman(ji)= 0.42 &
+               &                      + 0.5 *COS(  dg_pi*dl_rad/dd_cutoff) &
+               &                      + 0.08*COS(2*dg_pi*dl_rad/dd_cutoff)
+            ELSE
+               filter__1D_blackman(ji)=0
+            ENDIF                                
+
+         ENDDO
+
+         ! normalize
+         dl_sum=SUM(filter__1D_blackman(:))
+
+         filter__1D_blackman(:)=filter__1D_blackman(:)/dl_sum
+      ENDIF
+
+   END FUNCTION filter__1D_blackman
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute coefficient for BLACKMAN filter.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @return table of blackman filter coefficient 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION filter__2D_blackman(dd_cutoff, id_radius)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)        , INTENT(IN) :: dd_cutoff 
+      INTEGER(i4)     , INTENT(IN) :: id_radius
+
+      ! function
+      REAL(dp), DIMENSION(2*id_radius+1,2*id_radius+1) :: filter__2D_blackman
+
+      ! local variable
+      REAL(dp) :: dl_rad
+      REAL(dp) :: dl_sum
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      IF( dd_cutoff < 1 )THEN
+         CALL logger_error("FILTER COEF: cut-off frequency "//&
+         &  "should be greater than or equal to 1. No filter will be apply ")
+         filter__2D_blackman(:,:)=0.
+         filter__2D_blackman(id_radius+1,id_radius+1)=1.
+      ELSE      
+         DO jj=1,2*id_radius+1
+            DO ji=1,2*id_radius+1
+
+               dl_rad= SQRT( REAL(ji-(id_radius+1),dp)**2 + &
+               &             REAL(jj-(id_radius+1),dp)**2 )
+               
+               IF( dl_rad < dd_cutoff )THEN
+                  filter__2D_blackman(ji,jj)= 0.42 &
+                  &                         + 0.5 *COS(  dg_pi*dl_rad/dd_cutoff) &
+                  &                         + 0.08*COS(2*dg_pi*dl_rad/dd_cutoff)
+               ELSE
+                  filter__2D_blackman(ji,jj)=0
+               ENDIF                                
+
+            ENDDO
+         ENDDO
+
+         ! normalize
+         dl_sum=SUM(filter__2D_blackman(:,:))
+
+         filter__2D_blackman(:,:)=filter__2D_blackman(:,:)/dl_sum
+      ENDIF
+
+   END FUNCTION filter__2D_blackman
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute coefficient for GAUSS filter.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @param[in] dd_alpha : filter parameter
+   !> @return table of gauss filter coefficient 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION filter__1D_gauss(dd_cutoff, id_radius, dd_alpha)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)        , INTENT(IN) :: dd_cutoff 
+      INTEGER(i4)     , INTENT(IN) :: id_radius
+      REAL(dp)        , INTENT(IN) :: dd_alpha 
+
+      ! function
+      REAL(dp), DIMENSION(2*id_radius+1) :: filter__1D_gauss
+
+      ! local variable
+      REAL(dp) :: dl_rad
+      REAL(dp) :: dl_sum
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( dd_cutoff < 1 )THEN
+         CALL logger_error("FILTER COEF: cut-off frequency "//&
+         &  "should be greater than or equal to 1. No filter will be apply ")
+         filter__1D_gauss(:)=0.
+         filter__1D_gauss(id_radius+1)=1.
+      ELSE
+         DO ji=1,2*id_radius+1
+
+            dl_rad= SQRT( REAL(ji-(id_radius+1),dp)**2 )
+            
+            filter__1D_gauss(ji)=EXP(-(dd_alpha*dl_rad**2)/(2*dd_cutoff**2))
+
+         ENDDO
+
+         ! normalize
+         dl_sum=SUM(filter__1D_gauss(:))
+
+         filter__1D_gauss(:)=filter__1D_gauss(:)/dl_sum
+      ENDIF
+
+   END FUNCTION filter__1D_gauss
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute coefficient for GAUSS filter.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @param[in] dd_alpha : filter parameter
+   !> @return table of gauss filter coefficient 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION filter__2D_gauss(dd_cutoff, id_radius, dd_alpha)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)        , INTENT(IN) :: dd_cutoff 
+      INTEGER(i4)     , INTENT(IN) :: id_radius
+      REAL(dp)        , INTENT(IN) :: dd_alpha 
+
+      ! function
+      REAL(dp), DIMENSION(2*id_radius+1,2*id_radius+1) :: filter__2D_gauss
+
+      ! local variable
+      REAL(dp) :: dl_rad
+      REAL(dp) :: dl_sum
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      IF( dd_cutoff < 1 )THEN
+         CALL logger_error("FILTER COEF: cut-off frequency "//&
+         &  "should be greater than or equal to 1. No filter will be apply ")
+         filter__2D_gauss(:,:)=0.
+         filter__2D_gauss(id_radius+1,id_radius+1)=1.
+      ELSE
+         DO jj=1,2*id_radius+1
+            DO ji=1,2*id_radius+1
+
+               dl_rad= SQRT( REAL(ji-(id_radius+1),dp)**2 + &
+               &             REAL(jj-(id_radius+1),dp)**2 )
+               
+               filter__2D_gauss(ji,jj)=EXP(-(dd_alpha*dl_rad**2)/(2*dd_cutoff**2))
+
+            ENDDO
+         ENDDO
+
+         ! normalize
+         dl_sum=SUM(filter__2D_gauss(:,:))
+
+         filter__2D_gauss(:,:)=filter__2D_gauss(:,:)/dl_sum
+      ENDIF
+
+   END FUNCTION filter__2D_gauss
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute coefficient for BUTTERWORTH filter.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @param[in] dd_alpha : filter parameter
+   !> @return table of butterworth filter coefficient 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION filter__1D_butterworth(dd_cutoff, id_radius, dd_alpha)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)        , INTENT(IN) :: dd_cutoff 
+      INTEGER(i4)     , INTENT(IN) :: id_radius
+      REAL(dp)        , INTENT(IN) :: dd_alpha 
+
+      ! function
+      REAL(dp), DIMENSION(2*id_radius+1) :: filter__1D_butterworth
+
+      ! local variable
+      REAL(dp) :: dl_rad
+      REAL(dp) :: dl_sum
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( dd_cutoff <= 1 )THEN
+         CALL logger_error("FILTER COEF: cut-off frequency "//&
+         &  "should be greater than 1. No filter will be apply ")
+         filter__1D_butterworth(:)=0.
+         filter__1D_butterworth(id_radius+1)=1.
+      ELSE
+         DO ji=1,2*id_radius+1
+
+            dl_rad= SQRT( REAL(ji-(id_radius+1),dp)**2 )
+            
+            filter__1D_butterworth(ji)= 1 / (1+(dl_rad**2/dd_cutoff**2)**dd_alpha)
+
+         ENDDO
+
+         ! normalize
+         dl_sum=SUM(filter__1D_butterworth(:))
+
+         filter__1D_butterworth(:)=filter__1D_butterworth(:)/dl_sum
+      ENDIF
+
+   END FUNCTION filter__1D_butterworth
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute coefficient for BUTTERWORTH filter.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_cutoff : cuto-off frequency
+   !> @param[in] id_radius : filter halo radius
+   !> @param[in] dd_alpha : filter parameter
+   !> @return table of butterworth filter coefficient 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION filter__2D_butterworth(dd_cutoff,  id_radius, dd_alpha)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp)        , INTENT(IN) :: dd_cutoff 
+      INTEGER(i4)     , INTENT(IN) :: id_radius
+      REAL(dp)        , INTENT(IN) :: dd_alpha 
+
+      ! function
+      REAL(dp), DIMENSION(2*id_radius+1,2*id_radius+1) :: filter__2D_butterworth
+
+      ! local variable
+      REAL(dp) :: dl_rad
+      REAL(dp) :: dl_sum
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      IF( dd_cutoff <= 1 )THEN
+         CALL logger_error("FILTER COEF: cut-off frequency "//&
+         &  "should be greater than 1. No filter will be apply ")
+         filter__2D_butterworth(:,:)=0.
+         filter__2D_butterworth(id_radius+1,id_radius+1)=1.
+      ELSE
+         DO jj=1,2*id_radius+1
+            DO ji=1,2*id_radius+1
+
+               dl_rad= SQRT( REAL(ji-(id_radius+1),dp)**2 + &
+               &             REAL(jj-(id_radius+1),dp)**2 )
+               
+               filter__2D_butterworth(ji,jj)= 1 / (1+(dl_rad**2/dd_cutoff**2)**dd_alpha)
+
+            ENDDO
+         ENDDO
+
+         ! normalize
+         dl_sum=SUM(filter__2D_butterworth(:,:))
+
+         filter__2D_butterworth(:,:)=filter__2D_butterworth(:,:)/dl_sum
+      ENDIF
+
+   END FUNCTION filter__2D_butterworth
+   !> @endcode
+!   !-------------------------------------------------------------------
+!   !> @brief This function 
+!   !
+!   !> @details
+!   !
+!   !> @author J.Paul
+!   !> - Nov, 2013- Initial Version
+!   !
+!   !> @param[in] 
+!   !-------------------------------------------------------------------
+!   !> @code
+!   FUNCTION filter_()
+!      IMPLICIT NONE
+!      ! Argument      
+!      ! function
+!      ! local variable
+!      ! loop indices
+!      !----------------------------------------------------------------
+!
+!   END FUNCTION filter_
+!   !> @endcode
+!   !-------------------------------------------------------------------
+!   !> @brief This subroutine 
+!   !
+!   !> @details
+!   !
+!   !> @author J.Paul
+!   !> - Nov, 2013- Initial Version
+!   !
+!   !> @param[in] 
+!   !-------------------------------------------------------------------
+!   !> @code
+!   SUBROUTINE filter_()
+!      IMPLICIT NONE
+!      ! Argument      
+!      ! local variable
+!      ! loop indices
+!      !----------------------------------------------------------------
+!
+!   END SUBROUTINE filter_
+!   !> @endcode
+END MODULE filter
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/function.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/function.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/function.f90	(revision 4245)
@@ -0,0 +1,761 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: fct
+!
+! DESCRIPTION:
+!> @brief
+!> This module group some basic useful function
+!
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @todo
+!> - TODO_describe_appropriate_changes - TODO_name
+!> @param MyModule_type : brief_description
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!----------------------------------------------------------------------
+MODULE fct
+   USE kind                            ! F90 kind parameter
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! function and subroutine
+   PUBLIC :: OPERATOR(//)
+   PUBLIC :: fct_getunit! returns free unit number
+   PUBLIC :: fct_err    ! handle fortran error status
+   PUBLIC :: fct_str    ! convert numeric to string character
+   PUBLIC :: fct_concat ! concatenate all the element of a character table
+   PUBLIC :: fct_upper  ! convert lower character to upper case
+   PUBLIC :: fct_lower  ! convert upper character to lower case
+   PUBLIC :: fct_is_num ! check if character is numeric
+   PUBLIC :: fct_split  ! split string into substring
+   PUBLIC :: fct_basename ! return basename (name without path)
+   PUBLIC :: fct_dirname ! return dirname (path without name)
+
+   PRIVATE :: fct__i1_str ! convert integer(1) to string character
+   PRIVATE :: fct__i2_str ! convert integer(2) to string character
+   PRIVATE :: fct__i4_str ! convert integer(4) to string character
+   PRIVATE :: fct__i8_str ! convert integer(8) to string character
+   PRIVATE :: fct__r4_str ! convert real(4) to string character
+   PRIVATE :: fct__r8_str ! convert real(8) to string character
+   PRIVATE :: fct__l_str  ! convert logical to string character
+
+
+   INTERFACE fct_str
+      MODULE PROCEDURE fct__i1_str ! convert integer(1) to string character
+      MODULE PROCEDURE fct__i2_str ! convert integer(2) to string character
+      MODULE PROCEDURE fct__i4_str ! convert integer(4) to string character
+      MODULE PROCEDURE fct__i8_str ! convert integer(8) to string character
+      MODULE PROCEDURE fct__r4_str ! convert real(4) to string character
+      MODULE PROCEDURE fct__r8_str ! convert real(8) to string character
+      MODULE PROCEDURE fct__l_str  ! convert logical to string character
+   END INTERFACE fct_str
+
+   INTERFACE OPERATOR(//)
+      MODULE PROCEDURE fct__i4_cat ! concatenate integer(4) to string character
+      MODULE PROCEDURE fct__i8_cat ! concatenate integer(8) to string character
+      MODULE PROCEDURE fct__r4_cat ! concatenate real(4) to string character
+      MODULE PROCEDURE fct__r8_cat ! concatenate real(8) to string character
+      MODULE PROCEDURE fct__l_cat  ! concatenate logical to string character
+   END INTERFACE
+
+CONTAINS
+   !------------------------------------------------------------------- 
+   !> @brief This routine concatenate character and integer(4) (as character). 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @return string character 
+   !------------------------------------------------------------------- 
+   ! @code 
+   PURE CHARACTER(LEN=lc) FUNCTION fct__i4_cat(cd_char, id_val) 
+ 
+      ! arguments
+      CHARACTER(LEN=lc), INTENT(IN) :: cd_char
+      INTEGER(i4),       INTENT(IN) :: id_val
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_val
+      !---------------------------------------------------------------- 
+ 
+      cl_val = fct_str(id_val)
+      fct__i4_cat=TRIM(cd_char)//TRIM(cl_val)
+
+   END FUNCTION fct__i4_cat 
+   ! @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This routine concatenate character and integer(8) (as character). 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @return string character 
+   !------------------------------------------------------------------- 
+   ! @code 
+   PURE CHARACTER(LEN=lc) FUNCTION fct__i8_cat(cd_char, kd_val) 
+ 
+      ! arguments
+      CHARACTER(LEN=lc), INTENT(IN) :: cd_char
+      INTEGER(i8),       INTENT(IN) :: kd_val
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_val
+      !---------------------------------------------------------------- 
+ 
+      cl_val = fct_str(kd_val)
+      fct__i8_cat=TRIM(cd_char)//TRIM(cl_val)
+
+   END FUNCTION fct__i8_cat 
+   ! @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This routine concatenate character and real(4) (as character). 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @return string character 
+   !------------------------------------------------------------------- 
+   ! @code 
+   PURE CHARACTER(LEN=lc) FUNCTION fct__r4_cat(cd_char, rd_val) 
+ 
+      ! arguments
+      CHARACTER(LEN=lc), INTENT(IN) :: cd_char
+      REAL(sp),          INTENT(IN) :: rd_val
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_val
+      !---------------------------------------------------------------- 
+ 
+      cl_val = fct_str(rd_val)
+      fct__r4_cat=TRIM(cd_char)//TRIM(cl_val)
+
+   END FUNCTION fct__r4_cat 
+   ! @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This routine concatenate character and real(8) (as character). 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @return string character 
+   !------------------------------------------------------------------- 
+   ! @code 
+   PURE CHARACTER(LEN=lc) FUNCTION fct__r8_cat(cd_char, dd_val) 
+ 
+      ! arguments
+      CHARACTER(LEN=lc), INTENT(IN) :: cd_char
+      REAL(dp),          INTENT(IN) :: dd_val
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_val
+      !---------------------------------------------------------------- 
+ 
+      cl_val = fct_str(dd_val)
+      fct__r8_cat=TRIM(cd_char)//TRIM(cl_val)
+
+   END FUNCTION fct__r8_cat 
+   ! @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This routine concatenate character and logical (as character). 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @return string character 
+   !------------------------------------------------------------------- 
+   ! @code 
+   PURE CHARACTER(LEN=lc) FUNCTION fct__l_cat(cd_char, ld_val) 
+ 
+      ! arguments
+      CHARACTER(LEN=lc), INTENT(IN) :: cd_char
+      LOGICAL,           INTENT(IN) :: ld_val
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_val
+      !---------------------------------------------------------------- 
+ 
+      cl_val = fct_str(ld_val)
+      fct__l_cat=TRIM(cd_char)//TRIM(cl_val)
+
+   END FUNCTION fct__l_cat 
+   ! @endcode
+   !------------------------------------------------------------------- 
+   !> @brief This routine returns the next available I/O unit number. 
+   ! 
+   !> @author J.Paul 
+   !> - Nov, 2013- Initial Version 
+   ! 
+   !> @return file id 
+   !------------------------------------------------------------------- 
+   ! @code 
+   INTEGER(i4) FUNCTION fct_getunit() 
+ 
+      ! local variable 
+      LOGICAL ::  ll_opened 
+      !---------------------------------------------------------------- 
+      ! initialise 
+      fct_getunit = 10 
+ 
+      INQUIRE(UNIT=fct_getunit, OPENED=ll_opened) 
+      DO WHILE( ll_opened ) 
+         fct_getunit = fct_getunit + 1 
+         INQUIRE(UNIT=fct_getunit, OPENED=ll_opened)  
+      ENDDO 
+ 
+   END FUNCTION fct_getunit 
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This routine handle Fortran status.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE fct_err(id_status)
+
+      ! Argument
+      INTEGER(i4),       INTENT(IN) :: id_status
+      !----------------------------------------------------------------
+
+      IF( id_status /= 0 )THEN
+         !CALL ERRSNS() ! not F95 standard
+         PRINT *, "FORTRAN ERROR"
+         !STOP
+      ENDIF
+
+   END SUBROUTINE fct_err
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function convert logical to string character.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] ld_var : logical variable
+   !> @return character of this integer variable
+   !-------------------------------------------------------------------
+   ! @code
+   PURE CHARACTER(LEN=lc) FUNCTION fct__l_str(ld_var)
+      IMPLICIT NONE
+      ! Argument      
+      LOGICAL, INTENT(IN) :: ld_var
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_tmp
+      !----------------------------------------------------------------
+
+      write(cl_tmp,*) ld_var
+      fct__l_str=TRIM(ADJUSTL(cl_tmp))
+
+   END FUNCTION fct__l_str
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function convert integer(1) to string character.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] bd_var : integer(1) variable
+   !> @return character of this integer variable
+   !-------------------------------------------------------------------
+   ! @code
+   PURE CHARACTER(LEN=lc) FUNCTION fct__i1_str(bd_var)
+      IMPLICIT NONE
+      ! Argument      
+      INTEGER(i1), INTENT(IN) :: bd_var
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_tmp
+      !----------------------------------------------------------------
+
+      write(cl_tmp,*) bd_var
+      fct__i1_str=TRIM(ADJUSTL(cl_tmp))
+
+   END FUNCTION fct__i1_str
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function convert integer(2) to string character.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] sd_var : integer(2) variable
+   !> @return character of this integer variable
+   !-------------------------------------------------------------------
+   ! @code
+   PURE CHARACTER(LEN=lc) FUNCTION fct__i2_str(sd_var)
+      IMPLICIT NONE
+      ! Argument      
+      INTEGER(i2), INTENT(IN) :: sd_var
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_tmp
+      !----------------------------------------------------------------
+
+      write(cl_tmp,*) sd_var
+      fct__i2_str=TRIM(ADJUSTL(cl_tmp))
+
+   END FUNCTION fct__i2_str
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function convert integer(4) to string character.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] id_var : integer(4) variable
+   !> @return character of this integer variable
+   !-------------------------------------------------------------------
+   ! @code
+   PURE CHARACTER(LEN=lc) FUNCTION fct__i4_str(id_var)
+      IMPLICIT NONE
+      ! Argument      
+      INTEGER(i4), INTENT(IN) :: id_var
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_tmp
+      !----------------------------------------------------------------
+
+      write(cl_tmp,*) id_var
+      fct__i4_str=TRIM(ADJUSTL(cl_tmp))
+
+   END FUNCTION fct__i4_str
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function convert integer(8) to string character.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] kd_var : integer(8) variable
+   !> @return character of this integer variable
+   !-------------------------------------------------------------------
+   ! @code
+   PURE CHARACTER(LEN=lc) FUNCTION fct__i8_str(kd_var)
+      IMPLICIT NONE
+      ! Argument      
+      INTEGER(i8), INTENT(IN) :: kd_var
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_tmp
+      !----------------------------------------------------------------
+
+      write(cl_tmp,*) kd_var
+      fct__i8_str=TRIM(ADJUSTL(cl_tmp))
+
+   END FUNCTION fct__i8_str
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function convert real(4) to string character.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] rd_var : real(4) variable
+   !> @return character of this integer variable
+   !-------------------------------------------------------------------
+   ! @code
+   PURE CHARACTER(LEN=lc) FUNCTION fct__r4_str(rd_var)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(sp), INTENT(IN) :: rd_var
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_tmp
+      !----------------------------------------------------------------
+
+      write(cl_tmp,*) rd_var
+      fct__r4_str=TRIM(ADJUSTL(cl_tmp))
+
+   END FUNCTION fct__r4_str
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function convert real(8) to string character.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_var : real(8) variable
+   !> @return character of this integer variable
+   !-------------------------------------------------------------------
+   ! @code
+   PURE CHARACTER(LEN=lc) FUNCTION fct__r8_str(dd_var)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp), INTENT(IN) :: dd_var
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_tmp
+      !----------------------------------------------------------------
+
+      write(cl_tmp,*) dd_var
+      fct__r8_str=TRIM(ADJUSTL(cl_tmp))
+
+   END FUNCTION fct__r8_str
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function concatenate all the element of a character table 
+   !> except unknown one, in a character string.
+   !>
+   !> optionnally a separator could be added between each element
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_tab : table of character
+   !> @return character
+   !-------------------------------------------------------------------
+   ! @code
+   PURE CHARACTER(LEN=lc) FUNCTION fct_concat(cd_tab,cd_sep)
+      IMPLICIT NONE
+      ! Argument      
+      CHARACTER(*), DIMENSION(:), INTENT(IN) :: cd_tab
+      CHARACTER(*),               INTENT(IN), OPTIONAL :: cd_sep
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_tmp
+      CHARACTER(LEN=lc) :: cl_sep
+      INTEGER(i4)       :: il_size
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      cl_sep=''
+      IF(PRESENT(cd_sep)) cl_sep=cd_sep
+
+      il_size=SIZE(cd_tab)
+      fct_concat=''
+      cl_tmp=''
+      DO ji=1,il_size
+
+         !IF( TRIM(ADJUSTL(cd_tab(ji))) /= 'unknown' )THEN
+            WRITE(cl_tmp,*) TRIM(fct_concat)//TRIM(ADJUSTL(cd_tab(ji)))//TRIM(cl_sep)
+         !ENDIF
+      
+         fct_concat=TRIM(ADJUSTL(cl_tmp))
+      
+      ENDDO
+
+   END FUNCTION fct_concat
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function convert string character upper case to lower case.
+   !
+   !> @details
+   !> The function IACHAR returns the ASCII value of the character passed 
+   !> as argument. The ASCII code has the uppercase alphabet starting at 
+   !> code 65, and the lower case one at code 101, therefore 
+   !> IACHAR('a')- IACHAR('A') would be the difference between the uppercase
+   !> and the lowercase codes.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_var : character
+   !> @return lower case character
+   !-------------------------------------------------------------------
+   ! @code
+   PURE CHARACTER(LEN=lc) FUNCTION fct_lower(cd_var)
+      IMPLICIT NONE
+      ! Argument      
+      CHARACTER(*), INTENT(IN) :: cd_var
+
+      ! local variable
+      INTEGER(i4)                                  :: il_nletter ! number of letters in variable
+      CHARACTER(LEN=lc)                            :: cl_var
+      CHARACTER(LEN=lc), DIMENSION(:), ALLOCATABLE :: cl_tmp
+
+      INTEGER(i4) :: il_icode    ! ASCII value
+      INTEGER(i4) :: il_lacode   ! ASCII value of the lower case 'a'
+      INTEGER(i4) :: il_uacode   ! ASCII value of the upper case 'A'
+      INTEGER(i4) :: il_uzcode   ! ASCII value of the upper case 'z'
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      il_lacode=IACHAR('a')
+      il_uacode=IACHAR('A')
+      il_uzcode=IACHAR('Z')
+
+      cl_var=TRIM(ADJUSTL(cd_var))
+      il_nletter=LEN(TRIM(cl_var))
+      ALLOCATE(cl_tmp(il_nletter))
+      DO ji=1,il_nletter
+         il_icode=IACHAR(cl_var(ji:ji))
+         IF( il_icode >= il_uacode .AND. il_icode <= il_uzcode )THEN
+            ! upper case
+            cl_tmp(ji)=TRIM(CHAR(il_icode + (il_lacode - il_uacode) ))
+         ELSE
+            ! lower case and other character
+            cl_tmp(ji)=TRIM(CHAR(il_icode))
+         ENDIF
+      ENDDO
+
+      fct_lower=TRIM(ADJUSTL(fct_concat(cl_tmp(:))))
+      DEALLOCATE(cl_tmp)
+
+   END FUNCTION fct_lower
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function convert string character lower case to upper case.
+   !
+   !> @details
+   !> The function IACHAR returns the ASCII value of the character passed 
+   !> as argument. The ASCII code has the uppercase alphabet starting at 
+   !> code 65, and the lower case one at code 101, therefore 
+   !> IACHAR('a')- IACHAR('A') would be the difference between the uppercase
+   !> and the lowercase codes.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_var : character
+   !> @return upper case character
+   !-------------------------------------------------------------------
+   ! @code
+   PURE CHARACTER(LEN=lc) FUNCTION fct_upper(cd_var)
+      IMPLICIT NONE
+      ! Argument      
+      CHARACTER(*), INTENT(IN) :: cd_var
+
+      ! local variable
+      INTEGER(i4)                                  :: il_nletter ! number of letters in cd_var
+      CHARACTER(LEN=lc)                            :: cl_var
+      CHARACTER(LEN=lc), DIMENSION(:), ALLOCATABLE :: cl_tmp
+
+      INTEGER(i4) :: il_icode    ! ASCII value
+      INTEGER(i4) :: il_lacode   ! ASCII value of the lower case 'a'
+      INTEGER(i4) :: il_uacode   ! ASCII value of the upper case 'A'
+      INTEGER(i4) :: il_lzcode   ! ASCII value of the lower case 'z'
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      il_lacode=ICHAR('a')
+      il_uacode=ICHAR('A')
+      il_lzcode=IACHAR('z')
+
+      cl_var=TRIM(ADJUSTL(cd_var))
+      il_nletter=LEN(TRIM(cl_var))
+      ALLOCATE(cl_tmp(il_nletter))
+      DO ji=1,il_nletter
+         il_icode=IACHAR(cl_var(ji:ji))
+         IF( il_icode >= il_lacode .AND. il_icode <= il_lzcode )THEN
+            ! lower case
+            cl_tmp(ji)=CHAR(il_icode - (il_lacode - il_uacode) )
+         ELSE
+            ! upper case and other character
+            cl_tmp(ji)=CHAR(il_icode)
+         ENDIF
+      ENDDO
+
+      fct_upper=TRIM(ADJUSTL(fct_concat(cl_tmp(:))))
+      DEALLOCATE(cl_tmp)
+
+   END FUNCTION fct_upper
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function check if character is numeric.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_var : character
+   !> @return character is numeric
+   !-------------------------------------------------------------------
+   ! @code
+   PURE LOGICAL FUNCTION fct_is_num(cd_var)
+      IMPLICIT NONE
+      ! Argument      
+      CHARACTER(LEN=*), INTENT(IN) :: cd_var
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      DO ji=1,LEN(TRIM(cd_var))
+         IF( IACHAR(cd_var(ji:ji)) >= IACHAR('0') .AND. &
+         &   IACHAR(cd_var(ji:ji)) <= IACHAR('9') )THEN
+            fct_is_num=.TRUE.
+         ELSE
+            fct_is_num=.FALSE.
+            EXIT
+         ENDIF
+      ENDDO
+
+   END FUNCTION fct_is_num
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function split string of character 
+   !> using separator character, by default '|',
+   !> and return the element on index ind
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_string : string of character
+   !> @param[in] id_ind : indice
+   !> @param[in] cd_sep   separator character
+   !> @return return the element on index id_ind
+   !-------------------------------------------------------------------
+   ! @code
+   PURE FUNCTION fct_split(cd_string, id_ind, cd_sep)
+      IMPLICIT NONE
+      ! Argument      
+      CHARACTER(LEN=*), INTENT(IN) :: cd_string
+      INTEGER(i4)     , INTENT(IN) :: id_ind
+      CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: cd_sep
+
+      ! function
+      CHARACTER(LEN=lc) :: fct_split
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_sep
+      CHARACTER(LEN=lc) :: cl_string
+
+      INTEGER(i4) :: il_sep
+      
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! initialize
+      fct_split=''
+      cl_string=ADJUSTL(cd_string)
+
+      ! get separator
+      cl_sep='|'
+      IF( PRESENT(cd_sep) ) cl_sep=TRIM(ADJUSTL(cd_sep))
+      
+      ! get separator index
+      il_sep=INDEX( TRIM(cl_string), TRIM(cl_sep) )
+      
+      IF( il_sep /= 0 )THEN
+         fct_split=TRIM(ADJUSTL(cl_string(1:il_sep-1)))
+      ELSE
+         fct_split=TRIM(ADJUSTL(cl_string))
+      ENDIF
+
+      ji=1
+      DO WHILE( il_sep /= 0 .AND. ji /= id_ind )
+         
+         ji=ji+1
+         
+         cl_string=TRIM(cl_string(il_sep+1:))
+         il_sep=INDEX( TRIM(cl_string), TRIM(cl_sep) )
+
+         IF( il_sep /= 0 )THEN
+            fct_split=TRIM(ADJUSTL(cl_string(1:il_sep-1)))
+         ELSE
+            fct_split=TRIM(ADJUSTL(cl_string))
+         ENDIF
+
+      ENDDO
+
+      IF( ji /= id_ind ) fct_split=''
+
+   END FUNCTION fct_split
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function return basename of a filename.
+   !
+   !> @details
+   !> actually it splits filename using sperarator '/'
+   !> and return last string character
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_string : filename
+   !> @return basename (filename without path)
+   !-------------------------------------------------------------------
+   ! @code
+   PURE FUNCTION fct_basename(cd_string, cd_sep)
+      IMPLICIT NONE
+      ! Argument      
+      CHARACTER(LEN=*), INTENT(IN) :: cd_string
+      CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: cd_sep
+
+      ! function
+      CHARACTER(LEN=lc) :: fct_basename
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_sep
+      CHARACTER(LEN=lc) :: cl_string
+      INTEGER(i4)       :: il_sep
+      
+      ! loop indices
+      !----------------------------------------------------------------
+      ! initialize
+      cl_string=TRIM(ADJUSTL(cd_string))
+
+      ! get separator
+      cl_sep='/'
+      IF( PRESENT(cd_sep) ) cl_sep=TRIM(ADJUSTL(cd_sep))
+
+      il_sep=INDEX( TRIM(cl_string), TRIM(cl_sep), BACK=.TRUE.)
+      fct_basename=TRIM(cl_string(il_sep+1:))
+
+   END FUNCTION fct_basename
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function return dirname of a filename.
+   !
+   !> @details
+   !> actually it splits filename using sperarator '/'
+   !> and return all exept last string character
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_string : filename
+   !> @return dirname (path of the filename)
+   !-------------------------------------------------------------------
+   ! @code
+   PURE FUNCTION fct_dirname(cd_string, cd_sep)
+      IMPLICIT NONE
+      ! Argument      
+      CHARACTER(LEN=*), INTENT(IN) :: cd_string
+      CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: cd_sep
+
+      ! function
+      CHARACTER(LEN=lc) :: fct_dirname
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_sep
+      CHARACTER(LEN=lc) :: cl_string
+      INTEGER(i4)       :: il_sep
+      
+      ! loop indices
+      !----------------------------------------------------------------
+      ! initialize
+      cl_string=TRIM(ADJUSTL(cd_string))
+
+      ! get separator
+      cl_sep='/'
+      IF( PRESENT(cd_sep) ) cl_sep=TRIM(ADJUSTL(cd_sep))
+
+      il_sep=INDEX( TRIM(cl_string), TRIM(cl_sep), BACK=.TRUE.)
+      IF( il_sep == 0 )THEN
+         fct_dirname=''
+      ELSE
+         fct_dirname=TRIM(cl_string(1:il_sep))
+      ENDIF
+
+   END FUNCTION fct_dirname
+   ! @endcode
+END MODULE fct
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/global.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/global.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/global.f90	(revision 4245)
@@ -0,0 +1,106 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: global
+!
+! DESCRIPTION:
+!> @brief This module defines global variables, and parameters that can't 
+!> be associated with a module
+!
+!> @author
+!> J.paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!----------------------------------------------------------------------
+MODULE global
+   USE kind                         ! F90 kind parameter
+   USE netcdf
+
+   IMPLICIT NONE
+
+   PUBLIC :: dg_fill !< default fill value
+   PUBLIC :: ig_nsep !< number of separator listed
+   PUBLIC :: ig_ncom !< number of comment character listed
+   PUBLIC :: cg_sep  !< list of separator
+   PUBLIC :: cg_com  !< list of comment character
+
+   PUBLIC :: ig_npoint
+   PUBLIC :: jp_T
+   PUBLIC :: jp_U
+   PUBLIC :: jp_V
+   PUBLIC :: jp_F
+
+   PUBLIC :: ig_ndim
+   PUBLIC :: jp_I
+   PUBLIC :: jp_J
+   PUBLIC :: jp_K
+   PUBLIC :: jp_L
+
+   PUBLIC :: ig_maxvar  !< maximum number of variable
+   PUBLIC :: ig_maxmtx  !< matrix variable maximum dimension
+   PUBLIC :: ig_maxseg  !< maximum number of segment
+   PUBLIC :: ig_ghost   !< number of ghost cell
+
+   PUBLIC :: ig_ninterp      !< number of available interpolation method
+   PUBLIC :: cg_interp_list  !< list of interpolation name
+   
+   PUBLIC :: ig_nextrap      !< number of available extrapolation method
+   PUBLIC :: cg_extrap_list  !< list of extrapolation name
+   
+   PUBLIC :: ig_nfilter      !< number of available filter
+   PUBLIC :: cg_filter_list  !< list of filter name
+
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   INTEGER(i4)                             , PARAMETER :: ig_maxvar =200   !< maximum number of variable
+   INTEGER(i4)                             , PARAMETER :: ig_maxmtx =100   !< matrix variable maximum dimension (cf create_bathy)
+   INTEGER(i4)                             , PARAMETER :: ig_maxseg =50    !< maximum number of segment for each boundary
+
+   INTEGER(i4)                             , PARAMETER :: ig_nsep=2  !< number of separator listed
+   CHARACTER(1)     , DIMENSION(ig_nsep)   , PARAMETER :: cg_sep = (/'.','_'/) !< list of separator 
+
+   INTEGER(i4)                             , PARAMETER :: ig_ncom=2  !< number of comment character listed
+   CHARACTER(1)     , DIMENSION(ig_ncom)   , PARAMETER :: cg_com = (/'#','!'/) !< list of comment character 
+    
+   INTEGER(i4)                             , PARAMETER :: ig_ghost=1    !< number of ghost cell
+
+   INTEGER(i4)                             , PARAMETER :: ig_ninterp=3
+   CHARACTER(LEN=lc), DIMENSION(ig_ninterp), PARAMETER :: cg_interp_list = &
+   &  (/ 'nearest', &
+   &     'cubic  ', &
+   &     'linear '  /)
+
+   INTEGER(i4)                             , PARAMETER :: ig_nextrap=2
+   CHARACTER(LEN=lc), DIMENSION(ig_nextrap), PARAMETER :: cg_extrap_list = &
+   &  (/ 'dist_weight', &
+   &     'min_error  ' /)
+
+   INTEGER(i4)                             , PARAMETER :: ig_nfilter=5
+   CHARACTER(LEN=lc), DIMENSION(ig_nfilter), PARAMETER :: cg_filter_list = &
+   &  (/ 'butterworth', &
+   &     'blackman   ', &
+   &     'hamming    ', &
+   &     'hann       ', &
+   &     'gauss      '/)
+
+   REAL(dp)                                , PARAMETER :: dg_fill=NF90_FILL_DOUBLE !< default fill value
+   INTEGER(i4)                             , PARAMETER :: ig_fill=NF90_FILL_INT    !< default fill value
+
+   INTEGER(i4)                             , PARAMETER :: ig_npoint=4
+   INTEGER(i4)                             , PARAMETER :: jp_T=1
+   INTEGER(i4)                             , PARAMETER :: jp_U=2
+   INTEGER(i4)                             , PARAMETER :: jp_V=3
+   INTEGER(i4)                             , PARAMETER :: jp_F=4
+
+   INTEGER(i4)                             , PARAMETER :: ig_ndim=2
+   INTEGER(i4)                             , PARAMETER :: jp_I=1
+   INTEGER(i4)                             , PARAMETER :: jp_J=2
+   INTEGER(i4)                             , PARAMETER :: jp_K=3
+   INTEGER(i4)                             , PARAMETER :: jp_L=4
+
+END MODULE global
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/grid.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/grid.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/grid.f90	(revision 4245)
@@ -0,0 +1,2737 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: grid
+!
+! DESCRIPTION:
+!> @brief grid manager <br/>
+!>
+!> @details
+!> 
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!> @todo
+!----------------------------------------------------------------------
+MODULE grid
+   USE netcdf
+   USE kind                            ! F90 kind parameter
+   USE fct                             ! basic usefull function
+   USE global                          ! global parameter
+   USE phycst                          ! physical constant
+   USE logger                             ! log file manager
+   USE file                            ! file manager
+   USE var                             ! variable manager
+   USE dim                             ! dimension manager
+   USE dom                             ! domain manager
+   USE iom                             ! I/O manager
+   USE mpp                             ! MPP manager
+   USE iom_mpp                         ! MPP I/O manager
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+
+   ! function and subroutine
+   PUBLIC :: grid_check_dom !< check domain validity 
+   PUBLIC :: grid_get_coarse_index !< get closest coarse grid indices of fine grid domain.
+   PUBLIC :: grid_is_global !< check if grid is global or not
+   PUBLIC :: grid_get_closest !< return closest coarse grid point from another point
+   PUBLIC :: grid_distance !< compute grid distance to a point
+   PUBLIC :: grid_get_fine_offset !< get fine grid offset
+   PUBLIC :: grid_check_coincidence !< check fine and coarse grid coincidence
+   PUBLIC :: grid_get_perio !< return NEMO periodicity index
+   PUBLIC :: grid_get_pivot !< return NEMO pivot point index
+   PUBLIC :: grid_add_ghost !< add ghost cell at boundaries.
+   PUBLIC :: grid_del_ghost !< delete ghost cell at boundaries.
+   PUBLIC :: grid_get_ghost !< return ghost cell factor
+   PUBLIC :: grid_split_domain !< 
+   PUBLIC :: grid_fill_small_dom !< 
+
+   PRIVATE :: grid_get_coarse_index_ff
+   PRIVATE :: grid_get_coarse_index_cf
+   PRIVATE :: grid_get_coarse_index_fc
+   PRIVATE :: grid_get_coarse_index_cc
+   PRIVATE :: grid__get_ghost_f  
+   PRIVATE :: grid__get_ghost_ll
+   PRIVATE :: grid__check_corner
+   
+   INTERFACE  grid_get_ghost
+      MODULE PROCEDURE grid__get_ghost_ll
+      MODULE PROCEDURE grid__get_ghost_f
+   END INTERFACE  grid_get_ghost
+
+   INTERFACE  grid_get_coarse_index
+      MODULE PROCEDURE grid_get_coarse_index_ff
+      MODULE PROCEDURE grid_get_coarse_index_cf
+      MODULE PROCEDURE grid_get_coarse_index_fc
+      MODULE PROCEDURE grid_get_coarse_index_cc
+   END INTERFACE grid_get_coarse_index
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This funtion return NEMO pivot point index of the input variable.
+   !> - F-point : 0
+   !> - T-point : 1
+   !>
+   !> @warning 
+   !> - variable must be nav_lon or nav_lat
+   !> - do not work with ORCA2 grid (T-point)
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @todo 
+   !> - improve check between T or F pivot.
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] cd_varname : variable name
+   !> @return NEMO pivot point index
+   !-------------------------------------------------------------------
+   !> @code
+   INTEGER(i4) FUNCTION grid_get_pivot(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),       INTENT(IN) :: td_file
+
+      ! local variable
+      TYPE(TVAR)                        :: tl_var
+      INTEGER(i4)                       :: il_varid
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+
+      INTEGER(i4) :: it1
+      INTEGER(i4) :: it2
+      INTEGER(i4) :: jt1
+      INTEGER(i4) :: jt2
+
+      INTEGER(i4) :: if1
+      INTEGER(i4) :: if2
+      INTEGER(i4) :: jf1
+      INTEGER(i4) :: jf2
+      !----------------------------------------------------------------
+      ! initialise
+      grid_get_pivot=-1
+
+      ! look for suitable variable
+      il_varid=0
+      DO ji=1,td_file%i_nvar
+         IF( .NOT. ALL(td_file%t_var(ji)%t_dim(1:2)%l_use) ) CYCLE
+         SELECT CASE(TRIM(fct_lower(td_file%t_var(ji)%c_stdname)) )
+            CASE('longitude','latitude')
+            CASE DEFAULT
+               il_varid=ji
+               EXIT
+         END SELECT
+      ENDDO
+
+      IF( il_varid/=0 )THEN
+         IF( ASSOCIATED(td_file%t_var(il_varid)%d_value) )THEN
+            CALL logger_debug("GRID GET PIVOT: ASSOCIATED")
+            tl_var=td_file%t_var(il_varid)
+         ELSE
+            ! read variable
+            il_dim(:)=td_file%t_var(il_varid)%t_dim(:)%i_len
+
+            CALL logger_debug("GRID GET PIVOT: read variable")
+            tl_var=iom_read_var(td_file, td_file%t_var(il_varid)%c_name,     &
+            &                   id_start=(/1,il_dim(2)-3,1,1/), &
+            &                   id_count=(/3,4,1,1/) )
+         ENDIF
+
+         CALL logger_debug("GRID GET PIVOT: use variable "//TRIM(tl_var%c_name))
+
+         IF( ASSOCIATED(tl_var%d_value) )THEN
+
+            CALL logger_debug("GRID GET PIVOT: point "//TRIM(tl_var%c_point))
+            ! T-point pivot !case of ORCA2, ORCA025, ORCA12 grid
+            it1=1 ; jt1=4 
+            it2=3 ; jt2=2 
+
+            ! F-point pivot !case of ORCA05 grid
+            if1=1 ; jf1=4 
+            if2=2 ; jf2=3 
+
+            SELECT CASE(TRIM(tl_var%c_point))
+            CASE('T')
+               IF( ABS(tl_var%d_value(it1,jt1,1,1)) == &
+               &   ABS(tl_var%d_value(it2,jt2,1,1)) )THEN
+                  CALL logger_info("GRID GET PIVOT: T-pivot")
+                  grid_get_pivot=1
+               ELSEIF( ABS(tl_var%d_value(if1,jf1,1,1)) == &
+               &       ABS(tl_var%d_value(if2,jf2,1,1)) )THEN
+                  CALL logger_info("GRID GET PIVOT: F-pivot")
+                  grid_get_pivot=0
+               ELSE
+                  CALL logger_error("GRID GET PIVOT: something wrong when "//&
+                  &  "computing pivot point")
+               ENDIF
+            CASE('U')
+               IF( ABS(tl_var%d_value(it1  ,jt1,1,1)) == &
+               &   ABS(tl_var%d_value(it2-1,jt2,1,1)) )THEN
+                  CALL logger_info("GRID GET PIVOT: T-pivot")
+                  grid_get_pivot=1
+               ELSEIF( ABS(tl_var%d_value(if1  ,jf1,1,1)) == &
+               &       ABS(tl_var%d_value(if2-1,jf2,1,1)) )THEN
+                  CALL logger_info("GRID GET PIVOT: F-pivot")
+                  grid_get_pivot=0
+               ELSE
+                  CALL logger_error("GRID GET PIVOT: something wrong when "//&
+                  &  "computing pivot point")
+               ENDIF
+            CASE('V')
+               IF( ABS(tl_var%d_value(it1,jt1  ,1,1)) == &
+               &   ABS(tl_var%d_value(it2,jt2-1,1,1)) )THEN
+                  CALL logger_info("GRID GET PIVOT: T-pivot")
+                  grid_get_pivot=1
+               ELSEIF( ABS(tl_var%d_value(if1,jf1  ,1,1)) == &
+               &       ABS(tl_var%d_value(if2,jf2-1,1,1)) )THEN
+                  CALL logger_info("GRID GET PIVOT: F-pivot")
+                  grid_get_pivot=0
+               ELSE
+                  CALL logger_error("GRID GET PIVOT: something wrong when "//&
+                  &  "computing pivot point")
+               ENDIF
+            CASE('F')
+               IF( ABS(tl_var%d_value(it1  ,jt1  ,1,1)) == &
+               &   ABS(tl_var%d_value(it2-1,jt2-1,1,1)) )THEN
+                  CALL logger_info("GRID GET PIVOT: T-pivot")
+                  grid_get_pivot=1
+               ELSEIF( ABS(tl_var%d_value(if1  ,jf1  ,1,1)) == &
+               &       ABS(tl_var%d_value(if2-1,jf2-1,1,1)) )THEN
+                  CALL logger_info("GRID GET PIVOT: F-pivot")
+                  grid_get_pivot=0
+               ELSE
+                  CALL logger_error("GRID GET PIVOT: something wrong when "//&
+                  &  "computing pivot point")
+               ENDIF
+            END SELECT
+         ELSE
+            CALL logger_error("GRID GET PIVOT: can't compute pivot point. "//&
+            &  "no value associated to variable "//TRIM(tl_var%c_name) )
+         ENDIF
+
+      ELSE
+         CALL logger_error("GRID GET PIVOT: no suitable variable to compute "//&
+         &              "pivot point in file "//TRIM(td_file%c_name))
+      ENDIF
+
+   END FUNCTION grid_get_pivot
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This funtion return NEMO periodicity index of the input file.
+   !> The variable used must be on T point.
+   !>
+   !> @note the NEMO periodicity index can't be compute from coordinates file,
+   !> neither with mpp files.
+   !>
+   !> 0: closed boundaries
+   !> 1: cyclic east-west boundary
+   !> 2: symmetric boundary condition across the equator
+   !> 3: North fold boundary (with a F-point pivot)
+   !> 4: North fold boundary (with a F-point pivot) and cyclic east-west boundary
+   !> 5: North fold boundary (with a T-point pivot)
+   !> 6: North fold boundary (with a T-point pivot) and cyclic east-west boundary
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Subroutine written
+   !
+   !> @todo 
+   !> - improve check between T or F pivot.
+   !> - manage mpp case (read only border files)
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_pivot : pivot point
+   !> @return NEMO periodicity index
+   !-------------------------------------------------------------------
+   !> @code
+   INTEGER(i4) FUNCTION grid_get_perio(td_file, id_pivot)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_file
+      INTEGER(i4), INTENT(IN) :: id_pivot
+
+      ! local variable
+      TYPE(TVAR)                        :: tl_var
+      INTEGER(i4)                       :: il_varid
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! initialise
+      grid_get_perio=-1
+
+      IF( id_pivot < 0 .OR. id_pivot > 1 )THEN
+         CALL logger_error("GRID GET PERIO: invalid pivot point index. "//&
+         &  "you should use grid_get_pivot to compute it")
+      ENDIF
+
+      ! look for suitable variable
+      il_varid=0
+      DO ji=1,td_file%i_nvar
+         IF( .NOT. ALL(td_file%t_var(ji)%t_dim(1:2)%l_use) ) CYCLE
+         SELECT CASE(TRIM(fct_lower(td_file%t_var(ji)%c_stdname)) )
+            CASE('longitude','latitude')
+            CASE DEFAULT
+               il_varid=ji
+               EXIT
+         END SELECT
+      ENDDO
+
+      IF( il_varid==0 )THEN
+
+         CALL logger_error("GRID GET PERIO: no suitable variable to compute "//&
+         &              " periodicity in file "//TRIM(td_file%c_name))
+      ELSE
+         il_dim(:)=td_file%t_var(il_varid)%t_dim(:)%i_len
+
+         IF( ASSOCIATED(td_file%t_var(il_varid)%d_value) )THEN
+            tl_var=td_file%t_var(il_varid)
+         ELSE
+            ! read variable
+            tl_var=iom_read_var(td_file, td_file%t_var(il_varid)%c_name, &
+            &                   id_start=(/1,1,1,1/), &
+            &                   id_count=(/il_dim(1),il_dim(2),1,1/) )
+         ENDIF
+
+         IF(ALL(tl_var%d_value(    1    ,    :    ,1,1)/=tl_var%d_fill).AND.&
+         &  ALL(tl_var%d_value(il_dim(1),    :    ,1,1)/=tl_var%d_fill).AND.&
+         &  ALL(tl_var%d_value(    :    ,    1    ,1,1)/=tl_var%d_fill).AND.&
+         &  ALL(tl_var%d_value(    :    ,il_dim(2),1,1)/=tl_var%d_fill))THEN
+         ! no boundary closed
+            CALL logger_warn("GRID GET PERIO: can't determined periodicity. "//&
+            &             "there is no boundary closed for variable "//&
+            &              TRIM(tl_var%c_name)//" in file "//&
+            &              TRIM(td_file%c_name) )
+         ELSE
+            ! check periodicity
+            IF(ANY(tl_var%d_value(   1     ,:,1,1)/=tl_var%d_fill).OR.&
+            &  ANY(tl_var%d_value(il_dim(1),:,1,1)/=tl_var%d_fill))THEN
+            ! East-West cyclic (1,4,6)
+
+               IF( ANY(tl_var%d_value(:, 1, 1, 1) /= tl_var%d_fill) )THEN
+               ! South boundary not closed 
+
+                  CALL logger_error("GRID GET PERIO: should have been an "//&
+                  &              "impossible case")
+                  CALL logger_debug("GRID GET PERIO: East_West cyclic")
+                  CALL logger_debug("GRID GET PERIO: South boundary not closed")
+
+               ELSE
+               ! South boundary closed (1,4,6)
+                  CALL logger_info("GRID GET PERIO: South boundary closed")
+
+                  IF(ANY(tl_var%d_value(:,il_dim(2),1,1)/=tl_var%d_fill) )THEN
+                  ! North boundary not closed (4,6)
+                     CALL logger_info("GRID GET PERIO: North boundary not closed")
+                     ! check pivot
+                     SELECT CASE(id_pivot)
+                        CASE(0)
+                           ! F pivot
+                           grid_get_perio=4
+                        CASE(1)
+                           ! T pivot
+                           grid_get_perio=6
+                        CASE DEFAULT
+                           CALL logger_error("GRID GET PERIO: invalid pivot ")
+                     END SELECT
+                  ELSE
+                  ! North boundary closed
+                     CALL logger_info("GRID GET PERIO: North boundary closed")
+                     grid_get_perio=1 ! North and South boundaries closed
+                  ENDIF
+
+               ENDIF
+
+            ELSE
+            ! East-West boundaries closed (0,2,3,5)
+               CALL logger_info("GRID GET PERIO: East West boundaries closed")
+
+               IF( ANY(tl_var%d_value(:, 1, 1, 1) /= tl_var%d_fill) )THEN
+               ! South boundary not closed (2)
+                  CALL logger_info("GRID GET PERIO: South boundary not closed")
+
+                  IF(ANY(tl_var%d_value(:,il_dim(2),1,1)/=tl_var%d_fill))THEN
+                  ! North boundary not closed
+                     CALL logger_error("GRID GET PERIO: should have been "//&
+                     &              "an impossible case")
+                     CALL logger_debug("GRID GET PERIO: East West boundaries "//&
+                     &              "closed")
+                     CALL logger_debug("GRID GET PERIO: South boundary not closed")
+                     CALL logger_debug("GRID GET PERIO: North boundary not closed")
+                  ELSE
+                  ! North boundary closed
+                     grid_get_perio=2   ! East-West and North boundaries closed 
+                  ENDIF
+
+               ELSE
+               ! South boundary closed (0,3,5)
+                  CALL logger_info("GRID GET PERIO: South boundary closed")
+
+                  IF(ANY(tl_var%d_value(:,il_dim(2),1,1)/=tl_var%d_fill))THEN
+                  ! North boundary not closed (3,5)
+                     CALL logger_info("GRID GET PERIO: North boundary not closed")
+                     ! check pivot
+                     SELECT CASE(id_pivot)
+                        CASE(0)
+                           ! F pivot
+                           grid_get_perio=3
+                        CASE(1)
+                           ! T pivot
+                           grid_get_perio=5
+                        CASE DEFAULT
+                           CALL logger_error("GRID GET PERIO: invalid pivot")
+                     END SELECT
+                  ELSE
+                  ! North boundary closed   
+                     CALL logger_info("GRID GET PERIO: North boundary closed")
+                     grid_get_perio=0   ! all boundary closed
+                  ENDIF
+
+               ENDIF
+
+            ENDIF
+
+         ENDIF
+      ENDIF
+
+   END FUNCTION grid_get_perio
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine check domain validity.
+   !
+   !> @details
+   !> If maximum latitude greater than 88°N, program will stop. 
+   !> It is not able to manage north fold boundary for now.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_coord : coordinate file 
+   !> @param[in] id_imin : i-direction lower left  point indice  
+   !> @param[in] id_imax : i-direction upper right point indice 
+   !> @param[in] id_jmin : j-direction lower left  point indice 
+   !> @param[in] id_jmax : j-direction upper right point indice 
+   !>
+   !> @todo
+   !> - use domain instead of start count
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE grid_check_dom(td_coord, id_imin, id_imax, id_jmin, id_jmax)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_coord
+      INTEGER(i4), INTENT(IN) :: id_imin
+      INTEGER(i4), INTENT(IN) :: id_imax
+      INTEGER(i4), INTENT(IN) :: id_jmin
+      INTEGER(i4), INTENT(IN) :: id_jmax
+
+      ! local variable
+      TYPE(TVAR)                        :: tl_var
+
+      TYPE(TFILE)                       :: tl_coord
+
+      TYPE(TMPP)                        :: tl_mppcoord
+
+      TYPE(TDOM)                        :: tl_dom
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      IF( id_jmin >= id_jmax )THEN
+
+         CALL logger_fatal("GRID CHECK DOM: invalid domain. "//&
+         &  "can not create configuration with north pole.")
+
+      ELSE
+
+         IF( td_coord%i_id == 0 )THEN
+            CALL logger_error("GRID CHECK DOM: can not check domain. "//&
+            &  " file "//TRIM(td_coord%c_name)//" not opened." )
+         ELSE
+
+            IF( id_imin == id_imax .AND. td_coord%i_ew < 0 )THEN
+               CALL logger_fatal("GRID CHECK DOM: invalid domain."//&
+               &  " can not create east-west cyclic fine grid"//&
+               &  " inside closed coarse grid")
+            ENDIF
+
+            !1- read domain
+            tl_coord=td_coord
+            CALL iom_open(tl_coord)
+
+            !1-1 compute domain
+            tl_dom=dom_init( tl_coord,        &
+            &                 id_imin, id_imax,&
+            &                 id_jmin, id_jmax )
+            
+            !1-2 close file
+            CALL iom_close(tl_coord)
+
+            !1-3 read variables on domain (ugly way to do it, have to work on it)
+            !1-3-1 init mpp structure
+            tl_mppcoord=mpp_init(tl_coord)   
+
+            CALL file_clean(tl_coord)
+
+            !1-3-2 get processor to be used
+            CALL mpp_get_use( tl_mppcoord, tl_dom )
+
+            !1-3-3 open mpp files
+            CALL iom_mpp_open(tl_mppcoord)
+
+            !1-3-4 read variable value on domain
+            tl_var=iom_mpp_read_var(tl_mppcoord,'latitude',td_dom=tl_dom)
+
+            !1-3-5 close mpp files
+            CALL iom_mpp_close(tl_mppcoord)
+
+            !1-3-6 clean structure
+            CALL mpp_clean(tl_mppcoord)
+
+            IF( MAXVAL(tl_var%d_value(:,:,:,:), &
+            &          tl_var%d_value(:,:,:,:)/= tl_var%d_fill) >= 88.0 )THEN
+               
+               CALL logger_debug("GRID CHECK DOM: max latitude "//&
+               &  TRIM(fct_str(MAXVAL(tl_var%d_value(:,:,:,:)))) )
+               CALL logger_fatal("GRID CHECK DOM: invalid domain. "//&
+               &  "can not create configuration too close from north pole.")
+
+            ENDIF
+
+            ! clean
+            CALL var_clean(tl_var)
+
+         ENDIF
+
+
+      ENDIF
+
+   END SUBROUTINE grid_check_dom
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function get closest coarse grid indices of fine grid domain.
+   !
+   !> @details
+   !>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_coord0 : coarse grid coordinate structure
+   !> @param[in] td_coord1 : fine grid coordinate structure
+   !> @return coarse grid indices (/ (/imin0, imax0/), (/jmin0, jmax0/) /)
+   !> @todo
+   !> - use domain instead of start count
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION grid_get_coarse_index_ff( td_coord0, td_coord1, &
+   &                                  id_rho )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE), INTENT(IN) :: td_coord0
+      TYPE(TFILE), INTENT(IN) :: td_coord1
+      INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_rho
+
+      ! function
+      INTEGER(i4), DIMENSION(2,2,2) :: grid_get_coarse_index_ff
+
+      ! local variable
+      TYPE(TVAR)  :: tl_lon0
+      TYPE(TVAR)  :: tl_lat0
+      TYPE(TVAR)  :: tl_lon1
+      TYPE(TVAR)  :: tl_lat1
+
+      INTEGER(i4) , DIMENSION(:), ALLOCATABLE :: il_rho
+
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_start
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_count
+      INTEGER(i4), DIMENSION(2)         :: il_xghost0
+      INTEGER(i4), DIMENSION(2)         :: il_xghost1
+
+      INTEGER(i4) :: il_imin0
+      INTEGER(i4) :: il_imax0
+      INTEGER(i4) :: il_jmin0
+      INTEGER(i4) :: il_jmax0
+
+      INTEGER(i4) :: il_imin1
+      INTEGER(i4) :: il_imax1
+      INTEGER(i4) :: il_jmin1
+      INTEGER(i4) :: il_jmax1
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! init
+      grid_get_coarse_index_ff(:,:,:)=0
+
+      ALLOCATE(il_rho(ig_ndim))
+      il_rho(:)=1
+      IF( PRESENT(id_rho) ) il_rho(:)=id_rho(:)
+
+      IF( td_coord0%i_id == 0 .OR. td_coord1%i_id == 0 )THEN
+         CALL logger_error("GRID GET COARSE INDEX: can not get corase "//&
+         &  "grid indices. file "//TRIM(td_coord0%c_name)//" and/or "//&
+         &   TRIM(td_coord1%c_name)//" not opened." )
+      ELSE
+         !1- Coarse grid
+         ! read coarse longitue and latitude
+         tl_lon0=iom_read_var(td_coord0,'longitude')
+         tl_lat0=iom_read_var(td_coord0,'latitude')
+
+         ! get ghost cell factor on coarse grid
+         il_xghost0(:)=grid_get_ghost( tl_lon0, tl_lat0 )
+
+         il_imin0=1+il_xghost0(1)*ig_ghost
+         il_jmin0=1+il_xghost0(2)*ig_ghost
+
+         il_imax0=tl_lon0%t_dim(1)%i_len-il_xghost0(1)*ig_ghost
+         il_jmax0=tl_lon0%t_dim(2)%i_len-il_xghost0(2)*ig_ghost
+
+         CALL var_clean(tl_lon0)
+         CALL var_clean(tl_lat0)
+
+         ! read coarse longitue and latitude without ghost cell
+         il_start(:)=(/il_imin0,il_jmin0,1,1/)
+         il_count(:)=(/il_imax0-il_imin0+1, &
+         &             il_jmax0-il_jmin0+1, &
+         &             tl_lon0%t_dim(3)%i_len, &
+         &             tl_lon0%t_dim(4)%i_len /)
+
+         tl_lon0=iom_read_var(td_coord0,'longitude',il_start(:), il_count(:))
+         tl_lat0=iom_read_var(td_coord0,'latitude' ,il_start(:), il_count(:))
+         
+         !2- Fine grid
+         ! read fine longitue and latitude
+         tl_lon1=iom_read_var(td_coord1,'longitude')
+         tl_lat1=iom_read_var(td_coord1,'latitude')
+
+         ! get ghost cell factor on fine grid
+         il_xghost1(:)=grid_get_ghost( tl_lon1, tl_lat1 )
+
+         il_imin1=1+il_xghost1(1)*ig_ghost
+         il_jmin1=1+il_xghost1(2)*ig_ghost
+
+         il_imax1=tl_lon1%t_dim(1)%i_len-il_xghost1(1)*ig_ghost
+         il_jmax1=tl_lon1%t_dim(2)%i_len-il_xghost1(2)*ig_ghost
+
+         CALL var_clean(tl_lon1)
+         CALL var_clean(tl_lat1)
+
+         ! read fine longitue and latitude without ghost cell
+         il_start(:)=(/il_imin1,il_jmin1,1,1/)
+         il_count(:)=(/il_imax1-il_imin1+1, &
+         &             il_jmax1-il_jmin1+1, &
+         &             tl_lon1%t_dim(3)%i_len, &
+         &             tl_lon1%t_dim(4)%i_len /)
+
+         tl_lon1=iom_read_var(td_coord1,'longitude',il_start(:), il_count(:))
+
+         tl_lat1=iom_read_var(td_coord1,'latitude' ,il_start(:), il_count(:))
+ 
+         !3- compute
+         
+         grid_get_coarse_index_ff(:,:,:)=grid_get_coarse_index(tl_lon0,tl_lat0,&
+         &                                                     tl_lon1,tl_lat1,&
+         &                                                     il_rho(:) )
+
+         il_imin0=grid_get_coarse_index_ff(1,1,1)-il_xghost0(1)*ig_ghost
+         il_imax0=grid_get_coarse_index_ff(1,2,1)+il_xghost0(1)*ig_ghost
+         il_jmin0=grid_get_coarse_index_ff(2,1,1)-il_xghost0(2)*ig_ghost
+         il_jmax0=grid_get_coarse_index_ff(2,2,1)+il_xghost0(2)*ig_ghost
+
+         grid_get_coarse_index_ff(1,1,1)=il_imin0
+         grid_get_coarse_index_ff(1,2,1)=il_imax0
+         grid_get_coarse_index_ff(2,1,1)=il_jmin0
+         grid_get_coarse_index_ff(2,2,1)=il_jmax0
+
+         CALL var_clean(tl_lon0)
+         CALL var_clean(tl_lat0)         
+         CALL var_clean(tl_lon1)
+         CALL var_clean(tl_lat1)         
+
+      ENDIF
+
+   END FUNCTION grid_get_coarse_index_ff
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function get closest coarse grid indices of fine grid domain.
+   !
+   !> @details
+   !>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_longitude0 : coarse grid longitude
+   !> @param[in] td_latitude0  : coarse grid latitude
+   !> @param[in] td_coord1 : fine grid coordinate structure
+   !> @return coarse grid indices (/ (/imin0, imax0/), (/jmin0, jmax0/) /)
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION grid_get_coarse_index_cf( td_lon0, td_lat0, td_coord1, &
+   &                                  id_rho )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR ), INTENT(IN) :: td_lon0
+      TYPE(TVAR ), INTENT(IN) :: td_lat0
+      TYPE(TFILE), INTENT(IN) :: td_coord1
+      INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_rho
+
+      ! function
+      INTEGER(i4), DIMENSION(2,2,2) :: grid_get_coarse_index_cf
+
+      ! local variable
+      TYPE(TVAR)  :: tl_lon1
+      TYPE(TVAR)  :: tl_lat1
+
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_rho
+
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_start
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_count
+      INTEGER(i4), DIMENSION(2)         :: il_xghost
+
+      INTEGER(i4) :: il_imin1
+      INTEGER(i4) :: il_imax1
+      INTEGER(i4) :: il_jmin1
+      INTEGER(i4) :: il_jmax1
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! init
+      grid_get_coarse_index_cf(:,:,:)=0
+
+      ALLOCATE(il_rho(ig_ndim) )
+      il_rho(:)=1
+      IF( PRESENT(id_rho) ) il_rho(:)=id_rho(:)
+
+      IF( td_coord1%i_id == 0 )THEN
+         CALL logger_error("GRID GET COARSE INDEX: file "//&
+         &   TRIM(td_coord1%c_name)//" not opened." )
+
+      ELSE IF( .NOT. ASSOCIATED(td_lon0%d_value) .OR. &
+      &        .NOT. ASSOCIATED(td_lat0%d_value) )THEN
+
+         CALL logger_error("GRID GET COARSE INDEX: some coarse grid"//&
+         &                 " coordinate value are not associated.")         
+
+      ELSE
+         
+         !1- Fine grid
+         ! read fine longitue and latitude
+         tl_lon1=iom_read_var(td_coord1,'longitude')
+         tl_lat1=iom_read_var(td_coord1,'latitude')
+
+         ! get ghost cell factor on fine grid
+         il_xghost(:)=grid_get_ghost( tl_lon1, tl_lat1 )
+
+         il_imin1=1+il_xghost(1)*ig_ghost
+         il_jmin1=1+il_xghost(2)*ig_ghost
+
+         il_imax1=tl_lon1%t_dim(1)%i_len-il_xghost(1)*ig_ghost
+         il_jmax1=tl_lon1%t_dim(2)%i_len-il_xghost(2)*ig_ghost
+
+         CALL var_clean(tl_lon1)
+         CALL var_clean(tl_lat1)
+
+         ! read fine longitue and latitude without ghost cell
+         il_start(:)=(/il_imin1,il_jmin1,1,1/)
+         il_count(:)=(/il_imax1-il_imin1+1, &
+         &             il_jmax1-il_jmin1+1, &
+         &             tl_lon1%t_dim(3)%i_len, &
+         &             tl_lon1%t_dim(4)%i_len /)
+
+         tl_lon1=iom_read_var(td_coord1,'longitude',il_start(:), il_count(:))
+         tl_lat1=iom_read_var(td_coord1,'latitude' ,il_start(:), il_count(:))
+         
+         !3- compute
+         grid_get_coarse_index_cf(:,:,:)=grid_get_coarse_index(td_lon0,td_lat0,&
+         &                                                     tl_lon1,tl_lat1,&
+         &                                                     il_rho(:) )
+
+         CALL var_clean(tl_lon1)
+         CALL var_clean(tl_lat1)         
+
+      ENDIF
+
+   END FUNCTION grid_get_coarse_index_cf
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function get closest coarse grid indices of fine grid domain.
+   !
+   !> @details
+   !>
+   !> @warning use ghost cell so can not be used on extracted domain without
+   !> ghost cell
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_coord0 : coarse grid coordinate structure
+   !> @param[in] td_lon1 : fine grid longitude
+   !> @param[in] td_lat1 : fine grid latitude
+   !> @return coarse grid indices (/ (/imin0, imax0/), (/jmin0, jmax0/) /)
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION grid_get_coarse_index_fc( td_coord0, td_lon1, td_lat1, &
+   &                                  id_rho )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE), INTENT(IN) :: td_coord0
+      TYPE(TVAR ), INTENT(IN) :: td_lon1
+      TYPE(TVAR ), INTENT(IN) :: td_lat1
+      INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_rho
+
+      ! function
+      INTEGER(i4), DIMENSION(2,2,2) :: grid_get_coarse_index_fc
+
+      ! local variable
+      TYPE(TVAR)  :: tl_lon0
+      TYPE(TVAR)  :: tl_lat0
+
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_rho
+
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_start
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_count
+      INTEGER(i4), DIMENSION(2)         :: il_xghost
+
+      INTEGER(i4) :: il_imin0
+      INTEGER(i4) :: il_imax0
+      INTEGER(i4) :: il_jmin0
+      INTEGER(i4) :: il_jmax0
+
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! init
+      grid_get_coarse_index_fc(:,:,:)=0
+
+      ALLOCATE(il_rho(ig_ndim))
+      il_rho(:)=1
+      IF( PRESENT(id_rho) ) il_rho(:)=id_rho(:)
+
+      IF( td_coord0%i_id == 0 )THEN
+         CALL logger_error("GRID GET COARSE INDEX: file "//&
+         &                 TRIM(td_coord0%c_name)//" not opened." )
+
+      ELSE IF( .NOT. ASSOCIATED(td_lon1%d_value) .OR. &
+      &        .NOT. ASSOCIATED(td_lat1%d_value) )THEN
+
+         CALL logger_error("GRID GET COARSE INDEX: some fine grid"//&
+         &                 " coordinate value are not associated.")
+
+      ELSE
+         ! read coarse longitue and latitude
+         tl_lon0=iom_read_var(td_coord0,'longitude')
+         tl_lat0=iom_read_var(td_coord0,'latitude')
+
+         ! get ghost cell factor on coarse grid
+         il_xghost(:)=grid_get_ghost( tl_lon0, tl_lat0 )
+
+         il_imin0=1+il_xghost(1)*ig_ghost
+         il_jmin0=1+il_xghost(2)*ig_ghost
+
+         il_imax0=tl_lon0%t_dim(1)%i_len-il_xghost(1)*ig_ghost
+         il_jmax0=tl_lon0%t_dim(2)%i_len-il_xghost(2)*ig_ghost
+
+         CALL var_clean(tl_lon0)
+         CALL var_clean(tl_lat0)
+
+         ! read coarse longitue and latitude without ghost cell
+         il_start(:)=(/il_imin0,il_jmin0,1,1/)
+         il_count(:)=(/il_imax0-il_imin0+1, &
+         &             il_jmax0-il_jmin0+1, &
+         &             tl_lon0%t_dim(3)%i_len, &
+         &             tl_lon0%t_dim(4)%i_len /)
+
+         tl_lon0=iom_read_var(td_coord0,'longitude',il_start(:), il_count(:))
+         tl_lat0=iom_read_var(td_coord0,'latitude' ,il_start(:), il_count(:))
+
+         grid_get_coarse_index_fc(:,:,:)=grid_get_coarse_index(tl_lon0,tl_lat0,&
+         &                                                     td_lon1,td_lat1,&
+         &                                                     il_rho(:) )
+
+         ! remove ghost cell
+         il_imin0=grid_get_coarse_index_fc(1,1,1)+il_xghost(1)*ig_ghost
+         il_imax0=grid_get_coarse_index_fc(1,2,1)+il_xghost(1)*ig_ghost
+         il_jmin0=grid_get_coarse_index_fc(2,1,1)+il_xghost(2)*ig_ghost
+         il_jmax0=grid_get_coarse_index_fc(2,2,1)+il_xghost(2)*ig_ghost
+
+         grid_get_coarse_index_fc(1,1,1)=il_imin0
+         grid_get_coarse_index_fc(1,2,1)=il_imax0
+         grid_get_coarse_index_fc(2,1,1)=il_jmin0
+         grid_get_coarse_index_fc(2,2,1)=il_jmax0
+
+         CALL var_clean(tl_lon0)
+         CALL var_clean(tl_lat0)
+
+      ENDIF
+
+   END FUNCTION grid_get_coarse_index_fc
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function get closest coarse grid indices of fine grid domain.
+   !
+   !> @details
+   !>
+   !> @warning use ghost cell so can not be used on extracted domain without
+   !> ghost cell
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_lon0 : coarse grid longitude
+   !> @param[in] td_lat0 : coarse grid latitude
+   !> @param[in] td_lon1 : fine grid longitude
+   !> @param[in] td_lat1 : fine grid latitude
+   !> @return coarse grid indices (/ (/imin0, imax0/), (/jmin0, jmax0/) /)
+   !>
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION grid_get_coarse_index_cc( td_lon0, td_lat0, td_lon1, td_lat1, &
+   &                                  id_rho )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_lon0
+      TYPE(TVAR) , INTENT(IN) :: td_lat0
+      TYPE(TVAR) , INTENT(IN) :: td_lon1
+      TYPE(TVAR) , INTENT(IN) :: td_lat1
+      INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_rho
+
+      ! function
+      INTEGER(i4), DIMENSION(2,2,2) :: grid_get_coarse_index_cc
+
+      ! local variable
+      REAL(dp)    :: dl_lon1_ll
+      REAL(dp)    :: dl_lon1_ul
+      REAL(dp)    :: dl_lon1_lr
+      REAL(dp)    :: dl_lon1_ur
+
+      REAL(dp)    :: dl_lat1_ll
+      REAL(dp)    :: dl_lat1_ul
+      REAL(dp)    :: dl_lat1_lr
+      REAL(dp)    :: dl_lat1_ur
+
+      REAL(dp)    :: dl_dlon
+      REAL(dp)    :: dl_dlat
+
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_rho
+
+      INTEGER(i4), DIMENSION(2) :: il_ill
+      INTEGER(i4), DIMENSION(2) :: il_ilr
+      INTEGER(i4), DIMENSION(2) :: il_iul
+      INTEGER(i4), DIMENSION(2) :: il_iur
+
+      INTEGER(i4) :: il_ew0 
+      INTEGER(i4) :: il_imin0
+      INTEGER(i4) :: il_imax0
+      INTEGER(i4) :: il_jmin0
+      INTEGER(i4) :: il_jmax0
+
+      INTEGER(i4) :: il_ew1 
+      INTEGER(i4) :: il_imin1
+      INTEGER(i4) :: il_imax1
+      INTEGER(i4) :: il_jmin1
+      INTEGER(i4) :: il_jmax1
+
+      INTEGER(i4) :: il_imin
+      INTEGER(i4) :: il_imax
+      INTEGER(i4) :: il_jmin
+      INTEGER(i4) :: il_jmax      
+
+      INTEGER(i4), DIMENSION(2,2) :: il_offset
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      ! init
+      grid_get_coarse_index_cc(:,:,:)=0
+
+      ALLOCATE( il_rho(ig_ndim) )
+      il_rho(:)=1
+      IF( PRESENT(id_rho) ) il_rho(:)=id_rho(:)
+
+      IF( .NOT. ASSOCIATED(td_lon0%d_value) .OR. &
+      &   .NOT. ASSOCIATED(td_lat0%d_value) .OR. &
+      &   .NOT. ASSOCIATED(td_lon1%d_value) .OR. &
+      &   .NOT. ASSOCIATED(td_lat1%d_value) )THEN
+         CALL logger_error("GRID GET COARSE INDEX: some fine or coarse grid"//&
+         &                 " coordinate value not associated.")
+      ELSE
+
+         IF( grid_is_global(td_lon1, td_lat1) )THEN
+
+            IF( grid_is_global(td_lon0, td_lat0) )THEN
+               CALL logger_trace("GRID GET COARSE INDEX: fine grid is global ")
+               grid_get_coarse_index_cc(:,:,1) = 1
+               grid_get_coarse_index_cc(:,:,2) = 0
+            ELSE
+               CALL logger_error("GRID GET COARSE INDEX: fine grid is "//&
+               &                 "global, coarse grid not.")
+            ENDIF
+
+         ELSE
+
+            ! "global" coarse grid indice
+            il_imin0=1
+            il_jmin0=1
+
+            il_imax0=td_lon0%t_dim(1)%i_len
+            il_jmax0=td_lon0%t_dim(2)%i_len
+
+            ! get east west overlap for coarse grid
+            il_ew0=dom_get_ew_overlap(td_lon0)
+            IF( il_ew0 >= 0 )THEN
+               ! last point before overlap
+               il_imax0=il_imax0-il_ew0
+            ENDIF
+
+            ! "global" fine grid indice
+            il_imin1=1
+            il_jmin1=1
+
+            il_imax1=td_lon1%t_dim(1)%i_len
+            il_jmax1=td_lon1%t_dim(2)%i_len
+
+            ! get east west overlap for coarse grid
+            il_ew1=dom_get_ew_overlap(td_lon1)
+            IF( il_ew1 >= 0 )THEN
+               ! last point before overlap
+               il_imax1=il_imax1-il_ew1
+            ENDIF
+
+            ! get indices for each corner
+            !1- search lower left corner indices
+            dl_lon1_ll=td_lon1%d_value( il_imin1, il_jmin1, 1, 1 )
+            dl_lat1_ll=td_lat1%d_value( il_imin1, il_jmin1, 1, 1 )
+
+            dl_dlon=ABS(td_lon1%d_value(il_imin1+1,il_jmin1  ,1,1)-dl_lon1_ll)
+            dl_dlat=ABS(td_lat1%d_value(il_imin1  ,il_jmin1+1,1,1)-dl_lat1_ll)
+
+!            CALL logger_debug("GRID GET COARSE INDEX: lon1 ll "//&
+!            &  TRIM(fct_str(dl_lon1_ll)) )
+!            CALL logger_debug("GRID GET COARSE INDEX: lat1 ll "//&
+!            &  TRIM(fct_str(dl_lat1_ll)) )
+!
+!            CALL logger_debug("GRID GET COARSE INDEX: lon0 min "//&
+!            &  TRIM(fct_str(minval(td_lon0%d_value(2:,2:,:,:)))) )
+!            CALL logger_debug("GRID GET COARSE INDEX: lon0 max "//&
+!            &  TRIM(fct_str(maxval(td_lon0%d_value(2:,2:,:,:)))) )
+!
+!            CALL logger_debug("GRID GET COARSE INDEX: lat0 min "//&
+!            &  TRIM(fct_str(minval(td_lat0%d_value(2:,2:,:,:)))) )
+!            CALL logger_debug("GRID GET COARSE INDEX: lat0 max "//&
+!            &  TRIM(fct_str(maxval(td_lat0%d_value(2:,2:,:,:)))) )
+
+            ! look for closest point on coarse grid
+            il_ill(:)= grid_get_closest(td_lon0%d_value(il_imin0:il_imax0, &
+            &                                           il_jmin0:il_jmax0, &
+            &                                           1,1), &
+            &                           td_lat0%d_value(il_imin0:il_imax0, &
+            &                                           il_jmin0:il_jmax0, &
+            &                                           1,1), &
+            &                           dl_lon1_ll, dl_lat1_ll   )
+
+            ! coarse grid point should be south west of fine grid domain
+            ji = il_ill(1)
+            jj = il_ill(2)
+
+            IF( ABS(td_lon0%d_value(ji,jj,1,1)-dl_lon1_ll) > dl_dlon*1.e-3 )THEN
+               IF(td_lon0%d_value(ji,jj,1,1) > dl_lon1_ll ) il_ill(1)=il_ill(1)-1
+            ENDIF
+            IF( ABS(td_lat0%d_value(ji,jj,1,1)-dl_lat1_ll) > dl_dlat*1.e-3 )THEN
+               IF(td_lat0%d_value(ji,jj,1,1) > dl_lat1_ll ) il_ill(2)=il_ill(2)-1
+            ENDIF
+
+            !2- search upper left corner indices
+            dl_lon1_ul=td_lon1%d_value( il_imin1, il_jmax1, 1, 1 )
+            dl_lat1_ul=td_lat1%d_value( il_imin1, il_jmax1, 1, 1 )
+
+            dl_dlon=ABS(td_lon1%d_value(il_imin1+1,il_jmax1  ,1,1)-dl_lon1_ll)
+            dl_dlat=ABS(td_lat1%d_value(il_imin1  ,il_jmax1-1,1,1)-dl_lat1_ll)
+            
+            ! look for closest point on coarse grid
+            il_iul(:)= grid_get_closest(td_lon0%d_value(il_imin0:il_imax0, &
+            &                                           il_jmin0:il_jmax0, &
+            &                                           1,1), &
+            &                           td_lat0%d_value(il_imin0:il_imax0, &
+            &                                           il_jmin0:il_jmax0, &
+            &                                           1,1), &
+            &                           dl_lon1_ul, dl_lat1_ul   )
+
+            ! coarse grid point should be north west of fine grid domain
+            ji = il_iul(1)
+            jj = il_iul(2)
+
+            IF( ABS(td_lon0%d_value(ji,jj,1,1)-dl_lon1_ul) > dl_dlon*1.e-3 )THEN
+               IF(td_lon0%d_value(ji,jj,1,1) > dl_lon1_ul ) il_iul(1)=il_iul(1)-1
+            ENDIF
+            IF( ABS(td_lat0%d_value(ji,jj,1,1)-dl_lat1_ul) > dl_dlat*1.e-3 )THEN
+               IF(td_lat0%d_value(ji,jj,1,1) < dl_lat1_ul ) il_iul(2)=il_iul(2)+1
+            ENDIF
+
+            !3- search lower right corner indices
+            dl_lon1_lr=td_lon1%d_value( il_imax1, il_jmin1, 1, 1 )
+            dl_lat1_lr=td_lat1%d_value( il_imax1, il_jmin1, 1, 1 )
+
+            dl_dlon=ABS(td_lon1%d_value(il_imax1-1,il_jmin1  ,1,1)-dl_lon1_ll)
+            dl_dlat=ABS(td_lat1%d_value(il_imax1  ,il_jmin1+1,1,1)-dl_lat1_ll)
+            
+            ! look for closest point on coarse grid
+            il_ilr(:)= grid_get_closest(td_lon0%d_value(il_imin0:il_imax0, &
+            &                                           il_jmin0:il_jmax0, &
+            &                                           1,1), &
+            &                           td_lat0%d_value(il_imin0:il_imax0, &
+            &                                           il_jmin0:il_jmax0, &
+            &                                           1,1), &
+            &                           dl_lon1_lr, dl_lat1_lr   )
+
+            ! coarse grid point should be south east of fine grid domain
+            ji = il_ilr(1)
+            jj = il_ilr(2)
+            IF( ABS(td_lon0%d_value(ji,jj,1,1)-dl_lon1_lr) > dl_dlon*1.e-3 )THEN
+               IF( td_lon0%d_value(ji,jj,1,1) < dl_lon1_lr ) il_ilr(1)=il_ilr(1)+1
+            ENDIF
+            IF( ABS(td_lat0%d_value(ji,jj,1,1)-dl_lat1_lr) > dl_dlat*1.e-3 )THEN
+               IF( td_lat0%d_value(ji,jj,1,1) > dl_lat1_lr ) il_ilr(2)=il_ilr(2)-1
+            ENDIF
+
+            !4- search upper right corner indices
+            dl_lon1_ur=td_lon1%d_value( il_imax1, il_jmax1, 1, 1 )
+            dl_lat1_ur=td_lat1%d_value( il_imax1, il_jmax1, 1, 1 )
+
+            dl_dlon=ABS(td_lon1%d_value(il_imax1-1,il_jmax1  ,1,1)-dl_lon1_ll)
+            dl_dlat=ABS(td_lat1%d_value(il_imax1  ,il_jmax1-1,1,1)-dl_lat1_ll)
+            
+            ! look for closest point on coarse grid
+            il_iur(:)= grid_get_closest(td_lon0%d_value(il_imin0:il_imax0, &
+            &                                           il_jmin0:il_jmax0, &
+            &                                           1,1), &
+            &                           td_lat0%d_value(il_imin0:il_imax0, &
+            &                                           il_jmin0:il_jmax0, &
+            &                                           1,1), &
+            &                           dl_lon1_ur, dl_lat1_ur   )
+
+            ! coarse grid point should be north east fine grid domain
+            ji = il_iur(1)
+            jj = il_iur(2)
+            IF( ABS(td_lon0%d_value(ji,jj,1,1)-dl_lon1_ur) > dl_dlon*1.e-3 )THEN
+               IF( td_lon0%d_value(ji,jj,1,1) < dl_lon1_ur ) il_iur(1)=il_iur(1)+1
+            ENDIF
+            IF( ABS(td_lat0%d_value(ji,jj,1,1)-dl_lat1_ur) > dl_dlat*1.e-3 )THEN
+               IF( td_lat0%d_value(ji,jj,1,1) < dl_lat1_ur ) il_iur(2)=il_iur(2)+1
+            ENDIF
+
+            ! coarse grid indices
+            il_imin = il_imin0-1+MIN(il_ill(1), il_iul(1))
+            il_imax = il_imin0-1+MAX(il_ilr(1), il_iur(1))
+
+            IF( il_imax <= il_ew0 )THEN
+               il_imax = td_lon0%t_dim(1)%i_len - il_ew0 + il_imax 
+            ENDIF
+
+            il_jmin = il_jmin0-1+MIN(il_ill(2), il_ilr(2))
+            il_jmax = il_jmin0-1+MAX(il_iul(2), il_iur(2))
+
+            il_offset(:,:)= grid_get_fine_offset( td_lon0%d_value( :,:,1,1 ), &
+            &                                     td_lat0%d_value( :,:,1,1 ), &
+            &                                     il_imin, il_jmin, &
+            &                                     il_imax, il_jmax, &
+            &                                     td_lon1%d_value( :,:,1,1 ), &
+            &                                     td_lat1%d_value( :,:,1,1 ), &
+            &                                     il_rho(:) )
+
+            grid_get_coarse_index_cc(1,1,2) = il_offset(1,1)
+            grid_get_coarse_index_cc(1,2,2) = il_offset(1,2)
+
+            grid_get_coarse_index_cc(2,1,2) = il_offset(2,1)
+            grid_get_coarse_index_cc(2,2,2) = il_offset(2,2) 
+
+            ! special case if east west overlap
+            IF( il_ew1 >= 0 )THEN
+               CALL logger_debug("GRID GET COARSE INDEX: East-West overlap "//&
+               &                 "found for fine grid " )
+
+               il_imin = 1
+               il_imax = 1
+
+               grid_get_coarse_index_cc(1,1,2) = 0
+               grid_get_coarse_index_cc(1,2,2) = 0
+            ENDIF
+
+         ENDIF
+
+         IF( il_imin == il_imax ) il_imax=td_lon0%t_dim(1)%i_len
+         IF( il_jmin == il_jmax ) il_jmax=td_lon0%t_dim(2)%i_len
+
+         grid_get_coarse_index_cc(1,1,1) = il_imin
+         grid_get_coarse_index_cc(1,2,1) = il_imax
+
+         grid_get_coarse_index_cc(2,1,1) = il_jmin
+         grid_get_coarse_index_cc(2,2,1) = il_jmax
+ 
+      ENDIF
+
+   END FUNCTION grid_get_coarse_index_cc
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function check if grid is global or not
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_lon : longitude structure 
+   !> @param[in] td_lat : latitude structure 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION grid_is_global(td_lon, td_lat)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR), INTENT(IN) :: td_lon
+      TYPE(TVAR), INTENT(IN) :: td_lat
+
+      ! function
+      LOGICAL :: grid_is_global
+      
+      ! local variable
+      INTEGER(i4)               :: il_ew
+      INTEGER(i4)               :: il_south
+      INTEGER(i4)               :: il_north
+
+      REAL(dp)                  :: dl_lat_min
+      REAL(dp)                  :: dl_lat_max
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! init
+      grid_is_global=.FALSE.
+
+      IF( ANY( td_lon%t_dim(:)%i_len /= td_lat%t_dim(:)%i_len )  )THEN
+         CALL logger_fatal("GRID IS GLOBAL: dimension of longitude and "//&
+         &              " latitude differ")
+      ENDIF
+
+      IF( .NOT. ASSOCIATED(td_lon%d_value) .OR. &
+      &   .NOT. ASSOCIATED(td_lat%d_value) )THEN
+         CALL logger_error("GRID IS GLOBAL: na value associated to "//&
+         &              " longitude or latitude strucutre")      
+      ELSE
+
+         il_south=1
+         il_north=td_lon%t_dim(2)%i_len
+
+         dl_lat_min=MINVAL(td_lat%d_value(:,il_south,1,1))
+         dl_lat_max=MAXVAL(td_lat%d_value(:,il_north,1,1))
+
+         IF( dl_lat_min < -77.0 .AND. dl_lat_max > 89.0 )THEN
+
+            il_ew=td_lon%i_ew
+            IF( il_ew >= 0 )THEN
+
+               grid_is_global=.TRUE.
+
+            ENDIF
+
+         ENDIF
+      ENDIF
+
+   END FUNCTION grid_is_global
+   !> @endcode
+
+   !-------------------------------------------------------------------
+   !> @brief This function return coarse grid indices of the closest point
+   !> from fine grid point (lon1,lat1) 
+   !> 
+   !
+   !> @details
+   !
+   !> @note overlap band should have been already removed from coarse grid table 
+   !> of longitude and latitude, before running this function
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_lon0 : coarse grid table of longitude
+   !> @param[in] dd_lat0 : coarse grid table of latitude
+   !> @param[in] dd_lon1 : fine   grid longitude
+   !> @param[in] dd_lat1 : fine   grid latitude
+   !> @return coarse grid indices of closest point of fine grid point
+   !>
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION grid_get_closest( dd_lon0, dd_lat0, dd_lon1, dd_lat1  )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_lon0
+      REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_lat0
+      REAL(dp),                 INTENT(IN) :: dd_lon1
+      REAL(dp),                 INTENT(IN) :: dd_lat1
+
+      ! function
+      INTEGER(i4), DIMENSION(2) :: grid_get_closest
+
+      ! local variable
+      INTEGER(i4)                              :: il_iinf
+      INTEGER(i4)                              :: il_imid
+      INTEGER(i4)                              :: il_isup
+      INTEGER(i4)                              :: il_jinf
+      INTEGER(i4)                              :: il_jmid
+      INTEGER(i4)                              :: il_jsup
+      INTEGER(i4), DIMENSION(2)                :: il_shape
+      INTEGER(i4), DIMENSION(1)                :: il_ind
+    
+      LOGICAL                                  :: ll_north
+      LOGICAL                                  :: ll_continue
+
+      REAL(dp)                                 :: dl_lon1
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_dist
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_lon0
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      IF( ANY( SHAPE(dd_lon0(:,:)) /= SHAPE(dd_lat0(:,:)) ) )THEN
+         CALL logger_fatal("GRID GET CLOSEST: dimension of longitude and "//&
+         &              " latitude differ")
+      ENDIF
+
+      il_shape(:)=SHAPE(dd_lon0(:,:))
+      
+      ALLOCATE( dl_lon0(il_shape(1),il_shape(2)) ) 
+      
+      dl_lon0(:,:) = dd_lon0(:,:)
+      WHERE(dd_lon0(:,:) < 0 ) dl_lon0(:,:) = dd_lon0(:,:) + 360.
+
+      dl_lon1 = dd_lon1
+      IF( dd_lon1 < 0 ) dl_lon1 = dd_lon1 + 360.
+
+      !1- first, use dichotomy to reduce domain
+      il_iinf = 1              ; il_jinf = 1
+      il_isup = il_shape(1)    ; il_jsup = il_shape(2)
+
+      il_shape(1)= il_isup - il_iinf + 1
+      il_shape(2)= il_jsup - il_jinf + 1
+
+      ll_north=.FALSE.
+      ll_continue=.TRUE.
+
+      !1-1 look for meridian 0°/360°
+      il_jmid = il_jinf + INT(il_shape(2)/2)
+      il_ind(:) = MAXLOC( dl_lon0(:,il_jmid), dl_lon0(:,il_jmid) <= 360._dp )
+
+      il_imid=il_ind(1)
+
+      IF( dl_lon1 == dl_lon0(il_imid,il_jmid) .AND. &
+      &   dd_lat1 == dd_lat0(il_imid,il_jmid) )THEN
+
+         il_iinf = il_imid ;  il_isup = il_imid
+         il_jinf = il_jmid ;  il_jsup = il_jmid
+
+         ll_continue=.FALSE.
+
+      ELSE
+         IF( dl_lon1 < dl_lon0(il_isup,il_jmid) .AND. &
+         &   il_imid /= il_isup )THEN
+
+            ! point east
+            il_iinf = il_imid
+      
+         ELSE IF( dl_lon1 > dl_lon0(il_iinf,il_jmid) .AND. &
+         &        il_imid /= il_iinf )THEN
+
+            ! point west
+            il_isup = il_imid
+
+         ENDIF
+
+         il_shape(1)= il_isup - il_iinf + 1
+         il_shape(2)= il_jsup - il_jinf + 1
+
+         il_imid = il_iinf + INT(il_shape(1)/2) 
+         il_jmid = il_jinf + INT(il_shape(2)/2)
+
+         ! exit if too close from north fold (safer)
+         IF( dd_lat0(il_imid,il_jmid) > 50.0 ) ll_north=.TRUE.
+
+         ! exit when close enough of point
+         IF( ANY(il_shape(:) < 10 ) ) ll_continue=.FALSE.
+      ENDIF
+
+      !1-2
+      DO WHILE( ll_continue .AND. .NOT. ll_north )
+
+         IF( dl_lon1 == dl_lon0(il_imid,il_jmid) .AND. &
+         &   dd_lat1 == dd_lat0(il_imid,il_jmid) )THEN
+
+            il_iinf = il_imid ;  il_isup = il_imid
+            il_jinf = il_jmid ;  il_jsup = il_jmid
+
+            ll_continue=.FALSE.
+
+         ELSE
+            IF( dl_lon1 > dl_lon0(il_imid,il_jmid) )THEN
+
+               ! point east
+               il_iinf = il_imid
+        
+            ELSE IF(dl_lon1 < dl_lon0(il_imid,il_jmid) )THEN
+
+               ! point west
+               il_isup = il_imid
+
+            ENDIF
+
+
+            IF( dd_lat1 > dd_lat0(il_imid,il_jmid) )THEN
+               
+               ! point north
+               il_jinf = il_jmid
+
+            ELSE IF(dd_lat1 < dd_lat0(il_imid,il_jmid) )THEN
+
+               ! point south
+               il_jsup = il_jmid
+            
+            ENDIF
+
+            il_shape(1)= il_isup - il_iinf + 1
+            il_shape(2)= il_jsup - il_jinf + 1
+
+            il_imid = il_iinf + INT(il_shape(1)/2) 
+            il_jmid = il_jinf + INT(il_shape(2)/2)
+
+            ! exit if too close from north fold (safer)
+            IF( dd_lat0(il_imid,il_jmid) > 50.0 ) ll_north=.TRUE.
+
+            ! exit when close enough of point
+            IF( ANY(il_shape(:) < 10 ) ) ll_continue=.FALSE.
+         ENDIF
+         
+      ENDDO
+
+      !2- then find closest point by computing distances
+      il_shape(1)= il_isup - il_iinf + 1
+      il_shape(2)= il_jsup - il_jinf + 1
+
+      ALLOCATE( dl_dist(il_shape(1), il_shape(2)) )
+
+      dl_dist(:,:)=grid_distance(dl_lon0(il_iinf:il_isup,il_jinf:il_jsup), &
+      &                          dd_lat0(il_iinf:il_isup,il_jinf:il_jsup), &
+      &                          dl_lon1, dd_lat1 )
+
+      grid_get_closest(:)=MINLOC(dl_dist(:,:),dl_dist(:,:)/=NF90_FILL_DOUBLE)
+
+      grid_get_closest(1)=grid_get_closest(1)+il_iinf-1
+      grid_get_closest(2)=grid_get_closest(2)+il_jinf-1
+
+      DEALLOCATE( dl_dist )
+      DEALLOCATE( dl_lon0 )
+
+   END FUNCTION grid_get_closest
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function compute the distance between a point A and 
+   !> points of a grid  
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_lon : grid longitude table
+   !> @param[in] dd_lat : grid latitude  table
+   !> @param[in] dd_lonA : longitude of point A
+   !> @param[in] dd_latA : latitude  of point A
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION grid_distance(dd_lon, dd_lat, dd_lonA, dd_latA)
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_lon
+      REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_lat
+      REAL(dp),                 INTENT(IN) :: dd_lonA
+      REAL(dp),                 INTENT(IN) :: dd_latA
+
+      ! function
+      REAL(dp), DIMENSION(SIZE(dd_lon(:,:),DIM=1),&
+      &                   SIZE(dd_lon(:,:),DIM=2)) :: grid_distance
+
+      ! local variable
+      INTEGER(i4), DIMENSION(2) :: il_shape
+
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_lon
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_lat
+      REAL(dp)                                 :: dl_lonA
+      REAL(dp)                                 :: dl_latA
+
+      REAL(dp)                                 :: dl_tmp
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      IF( ANY( SHAPE(dd_lon(:,:)) /= SHAPE(dd_lat(:,:)) ) )THEN
+         CALL logger_fatal("GRID DISTANCE: dimension of longitude and "//&
+         &              " latitude differ")
+      ENDIF
+      il_shape(:)=SHAPE(dd_lon(:,:))
+      
+      ALLOCATE(dl_lon(il_shape(1),il_shape(2)))
+      ALLOCATE(dl_lat(il_shape(1),il_shape(2)))
+
+      dl_lon(:,:) = dd_lon(:,:)
+      dl_lonA     = dd_lonA
+
+      WHERE(dd_lon(:,:) < 0 ) dl_lon(:,:) = dd_lon(:,:) + 360.
+      IF(   dd_lonA     < 0 ) dl_lonA     = dd_lonA     + 360.
+      
+      dl_lonA = dd_lonA * dg_deg2rad
+      dl_latA = dd_latA * dg_deg2rad
+
+      dl_lon(:,:) = dl_lon(:,:) * dg_deg2rad
+      dl_lat(:,:) = dd_lat(:,:) * dg_deg2rad
+
+      grid_distance(:,:)=NF90_FILL_DOUBLE
+
+      DO jj=1,il_shape(2)
+         DO ji=1,il_shape(1)
+            IF( dl_lon(ji,jj) == dl_lonA .AND. &
+            &   dl_lat(ji,jj) == dl_lATA )THEN
+               grid_distance(ji,jj)=0.0
+            ELSE
+               dl_tmp= SIN(dl_latA)*SIN(dl_lat(ji,jj)) + &
+               &       COS(dl_latA)*COS(dl_lat(ji,jj))*COS(dl_lon(ji,jj)-dl_lonA)
+               ! check to avoid mistake with ACOS
+               IF( dl_tmp < -1.0 ) dl_tmp = -1.0
+               IF( dl_tmp >  1.0 ) dl_tmp =  1.0
+               grid_distance(ji,jj)=ACOS(dl_tmp)*dg_rearth
+            ENDIF
+         ENDDO
+      ENDDO
+
+      DEALLOCATE(dl_lon)
+      DEALLOCATE(dl_lat)
+
+   END FUNCTION grid_distance
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function get fine grid offset.
+   !
+   !> @details
+   !> offset value could be 0,1,..,rho-1
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_lon0 : coarse grid longitude table 
+   !> @param[in] dd_lat0 : coarse grid latitude  table
+   !> @param[in] dd_lon1 : fine   grid longitude table 
+   !> @param[in] dd_lat1 : fine   grid latitude  table
+   !> @param[in] id_imin0 : coarse grid lower left corner i-indice of fine grid domain
+   !> @param[in] id_jmin0 : coarse grid lower left corner j-indice of fine grid domain
+   !> @param[in] id_imax0 : coarse grid upper right corner i-indice of fine grid domain
+   !> @param[in] id_jmax0 : coarse grid upper right corner j-indice of fine grid domain
+   !> @param[in] id_rhoi : i-direction refinement factor
+   !> @param[in] id_rhoj : j-direction refinement factor
+   !> @return offset table (/ (/i_offset_left,i_offset_right!/),(/j_offset_lower,j_offset_upper/) /)
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION grid_get_fine_offset( dd_lon0, dd_lat0, &
+   &                              id_imin0, id_jmin0, id_imax0, id_jmax0, &
+   &                              dd_lon1, dd_lat1, id_rho )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)   , DIMENSION(:,:), INTENT(IN) :: dd_lon0
+      REAL(dp)   , DIMENSION(:,:), INTENT(IN) :: dd_lat0
+      REAL(dp)   , DIMENSION(:,:), INTENT(IN) :: dd_lon1
+      REAL(dp)   , DIMENSION(:,:), INTENT(IN) :: dd_lat1
+
+      INTEGER(i4),                 INTENT(IN) :: id_imin0
+      INTEGER(i4),                 INTENT(IN) :: id_jmin0
+      INTEGER(i4),                 INTENT(IN) :: id_imax0
+      INTEGER(i4),                 INTENT(IN) :: id_jmax0
+
+      INTEGER(i4), DIMENSION(:)  , INTENT(IN) :: id_rho
+
+      ! function
+      INTEGER(i4), DIMENSION(2,2) :: grid_get_fine_offset
+
+      ! local variable
+      INTEGER(i4), DIMENSION(2) :: il_shape0
+      INTEGER(i4), DIMENSION(2) :: il_shape1
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_lon0
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_lon1
+      
+      REAL(dp) :: dl_dlon
+      REAL(dp) :: dl_dlat
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+
+      INTEGER(i4) :: ii
+      INTEGER(i4) :: ij
+      !----------------------------------------------------------------
+      IF( ANY( SHAPE(dd_lon0(:,:)) /= SHAPE(dd_lat0(:,:)) ) )THEN
+         CALL logger_fatal("GRID GET FINE OFFSET: dimension of coarse "//&
+         &              "longitude and latitude differ")
+      ENDIF
+
+      IF( ANY( SHAPE(dd_lon1(:,:)) /= SHAPE(dd_lat1(:,:)) ) )THEN
+         CALL logger_fatal("GRID GET FINE OFFSET: dimension of fine "//&
+         &              "longitude and latitude differ")
+      ENDIF      
+
+      il_shape0(:)=SHAPE(dd_lon0(:,:))
+      ALLOCATE( dl_lon0(il_shape0(1),il_shape0(2)) )
+
+      dl_lon0(:,:)=dd_lon0(:,:)
+      WHERE( dd_lon0(:,:) < 0 ) dl_lon0(:,:)=dd_lon0(:,:)+360.
+
+      il_shape1(:)=SHAPE(dd_lon1(:,:))
+      ALLOCATE( dl_lon1(il_shape1(1),il_shape1(2)) )
+
+      dl_lon1(:,:)=dd_lon1(:,:)
+      WHERE( dd_lon1(:,:) < 0 ) dl_lon1(:,:)=dd_lon1(:,:)+360.         
+
+      grid_get_fine_offset(:,:)=-1
+
+      ! look for i-direction left offset 
+      IF( dl_lon1(1,1) < dl_lon0(id_imin0+1,id_jmin0) )THEN
+         DO ji=1,id_rho(jp_I)+2
+            dl_dlon=ABS(dl_lon1(ji+1,1)-dl_lon1(ji,1))*1.e-3
+            IF( dl_lon1(ji,1) > dl_lon0(id_imin0+1,id_jmin0) + dl_dlon )THEN
+               grid_get_fine_offset(1,1)=(id_rho(jp_I)+1)-ji+MOD(id_rho(jp_I),2)
+               EXIT
+            ENDIF
+         ENDDO
+      ELSE
+         CALL logger_error("GRID GET FINE OFFSET: coarse grid indices do "//&
+         &                 " not match fine grid lower left corner.")
+      ENDIF
+
+      ! look for i-direction right offset
+      IF( dl_lon1(il_shape1(1),1) > dl_lon0(id_imax0-1,id_jmin0) )THEN
+         DO ji=1,id_rho(jp_I)+2
+            ii=il_shape1(1)-ji+1
+            dl_dlon=ABS(dl_lon1(ii,1)-dl_lon1(ii-1,1))*1.e-3
+            IF( dl_lon1(ii,1) < dl_lon0(id_imax0-1,id_jmin0) - dl_dlon )THEN
+               grid_get_fine_offset(1,2)=(id_rho(jp_I)+1)-ji+MOD(id_rho(jp_I),2)
+               EXIT
+            ENDIF
+         ENDDO
+      ELSE
+         CALL logger_error("GRID GET FINE OFFSET: coarse grid indices do "//&
+         &                 " not match fine grid lower right corner.")
+      ENDIF
+
+      ! look for j-direction lower offset 
+      IF( dd_lat1(1,1) < dd_lat0(id_imin0,id_jmin0+1) )THEN
+         DO jj=1,id_rho(jp_J)+2
+            dl_dlat=ABS(dd_lat1(1,jj+1)-dd_lat1(1,jj))*1.e-3
+            IF( dd_lat1(1,jj) > dd_lat0(id_imin0,id_jmin0+1) + dl_dlat )THEN
+               grid_get_fine_offset(2,1)=(id_rho(jp_J)+1)-jj+MOD(id_rho(jp_J),2)
+               EXIT
+            ENDIF
+         ENDDO
+      ELSE
+         CALL logger_error("GRID GET FINE OFFSET: coarse grid indices do "//&
+         &                 " not match fine grid upper left corner.")
+      ENDIF
+
+      ! look for j-direction upper offset 
+      IF( dd_lat1(1,il_shape1(2)) > dd_lat0(id_imin0,id_jmax0-1) )THEN
+         DO jj=1,id_rho(jp_J)+2
+            ij=il_shape1(2)-jj+1
+            dl_dlat=ABS(dd_lat1(1,ij)-dd_lat1(1,ij-1))*1.e-3
+            IF( dd_lat1(1,ij) < dd_lat0(id_imin0,id_jmax0-1) - dl_dlat )THEN
+               grid_get_fine_offset(2,2)=(id_rho(jp_J)+1)-jj+MOD(id_rho(jp_J),2)
+               EXIT
+            ENDIF
+         ENDDO
+      ELSE
+         CALL logger_error("GRID GET FINE OFFSET: coarse grid indices do "//&
+         &                 " not match fine grid upper right corner.")
+      ENDIF
+
+      DEALLOCATE( dl_lon0 )
+      DEALLOCATE( dl_lon1 )
+
+   END FUNCTION grid_get_fine_offset
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function check if ghost cell are used or not, and return ghost
+   !> cell factor (0,1) in i- and j-direction.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_lon  : grid longitude sturcture 
+   !> @param[in] td_lat  : grid latitude  structure
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION grid__get_ghost_ll( td_lon, td_lat )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR), INTENT(IN) :: td_lon
+      TYPE(TVAR), INTENT(IN) :: td_lat
+
+      ! function
+      INTEGER(i4), DIMENSION(2) :: grid__get_ghost_ll
+
+      ! local variable
+      INTEGER(i4) :: il_ew
+      ! loop indices
+      !----------------------------------------------------------------
+      ! init
+      grid__get_ghost_ll(:)=0
+
+      IF( grid_is_global(td_lon, td_lat) )THEN
+         grid__get_ghost_ll(:)=0
+      ELSE
+         grid__get_ghost_ll(2)=1
+
+         il_ew=td_lon%i_ew
+         IF( il_ew < 0 )THEN
+            grid__get_ghost_ll(1)=1
+         ELSE
+            grid__get_ghost_ll(1)=0
+         ENDIF
+      ENDIF
+
+   END FUNCTION grid__get_ghost_ll
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function check if ghost cell are used or not, and return ghost
+   !> cell factor (0,1) in i- and j-direction.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file sturcture 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION grid__get_ghost_f( td_file )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE), INTENT(IN) :: td_file
+
+      ! function
+      INTEGER(i4), DIMENSION(2) :: grid__get_ghost_f
+
+      ! local variable
+      TYPE(TVAR)  :: tl_lon
+      TYPE(TVAR)  :: tl_lat
+
+      INTEGER(i4) :: il_lonid
+      INTEGER(i4) :: il_latid
+      ! loop indices
+      INTEGER(i4)  :: ji
+      !----------------------------------------------------------------
+      ! init
+      grid__get_ghost_f(:)=0
+
+      IF( td_file%i_id == 0 )THEN
+         CALL logger_error("GRID GET GHOST: file "//&
+         &                 TRIM(td_file%c_name)//" not opened." )
+
+      ELSE
+
+         IF( ASSOCIATED(td_file%t_var) )THEN
+            ! read coarse longitue and latitude
+            il_lonid=var_get_id(td_file%t_var(:),'longitude')
+            il_latid=var_get_id(td_file%t_var(:),'latitude')
+
+            print *,'file ',trim(td_file%c_name),td_file%i_ew
+            DO ji=1,td_file%i_nvar
+               print *,ji,trim(td_file%t_var(ji)%c_name),': ',td_file%t_var(ji)%i_ew
+            ENDDO
+            print *,'lonid ',il_lonid
+            print *,'latid ',il_latid
+            IF( il_lonid /=0 .AND. il_latid /= 0 )THEN
+               tl_lon=iom_read_var(td_file,il_lonid)
+               print *,'lon ',tl_lon%i_ew
+               tl_lat=iom_read_var(td_file,il_latid)
+               print *,'lat ',tl_lat%i_ew
+               ! get ghost cell factor on coarse grid
+               grid__get_ghost_f(:)=grid_get_ghost( tl_lon, tl_lat )
+            ELSE
+               CALL logger_error("GRID GET GHOST: can not find "//&
+               &           "longitude or latitude "//&
+               &           "in file "//TRIM(td_file%c_name))
+            ENDIF
+         ELSE
+           CALL logger_error("GRID GET GHOST: no variable "//&
+           &           "associated to file "//TRIM(td_file%c_name))
+         ENDIF
+
+      ENDIF
+
+   END FUNCTION grid__get_ghost_f
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine check fine and coarse grid coincidence
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_coord0 : coarse grid coordinate file structure 
+   !> @param[in] td_coord1 : fine   grid coordinate file structure 
+   !> @param[in] id_imin0 : coarse grid lower left  corner i-indice of fine grid domain 
+   !> @param[in] id_imax0 : coarse grid upper right corner i-indice of fine grid domain
+   !> @param[in] id_jmin0 : coarse grid lower left  corner j-indice of fine grid domain 
+   !> @param[in] id_jmax0 : coarse grid upper right corner j-indice of fine grid domain  
+   !> @param[in] id_rho   : table of refinement factor 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE grid_check_coincidence( td_coord0, td_coord1, &
+   &                                  id_imin0, id_imax0, &
+   &                                  id_jmin0, id_jmax0, &
+   &                                  id_rho )
+      IMPLICIT NONE
+      
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_coord0
+      TYPE(TFILE), INTENT(IN) :: td_coord1
+      INTEGER(i4), INTENT(IN) :: id_imin0
+      INTEGER(i4), INTENT(IN) :: id_imax0
+      INTEGER(i4), INTENT(IN) :: id_jmin0
+      INTEGER(i4), INTENT(IN) :: id_jmax0
+      INTEGER(i4), DIMENSION(:), INTENT(IN) :: id_rho
+
+      ! local variable
+      INTEGER(i4) :: il_imid1
+      INTEGER(i4) :: il_jmid1
+      
+      INTEGER(i4) :: il_ew0
+      INTEGER(i4) :: il_ew1
+
+      INTEGER(i4) :: il_imin1
+      INTEGER(i4) :: il_imax1
+      INTEGER(i4) :: il_jmin1
+      INTEGER(i4) :: il_jmax1
+
+      INTEGER(i4), DIMENSION(2) :: il_indC
+      INTEGER(i4), DIMENSION(2) :: il_indF
+      INTEGER(i4), DIMENSION(2) :: il_iind
+      INTEGER(i4), DIMENSION(2) :: il_jind
+
+      REAL(dp)    :: dl_lon0
+      REAL(dp)    :: dl_lat0
+      REAL(dp)    :: dl_lon1
+      REAL(dp)    :: dl_lat1
+
+      REAL(dp)    :: dl_lon1p
+      REAL(dp)    :: dl_lat1p
+
+      REAL(dp)    :: dl_dlon
+      REAL(dp)    :: dl_dlat
+
+      LOGICAL     :: ll_coincidence
+
+      TYPE(TVAR)  :: tl_lon0
+      TYPE(TVAR)  :: tl_lat0
+      TYPE(TVAR)  :: tl_lon1
+      TYPE(TVAR)  :: tl_lat1
+
+      TYPE(TFILE) :: tl_coord0
+
+      TYPE(TMPP)  :: tl_mppcoord0
+
+      TYPE(TDOM)  :: tl_dom0
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      ll_coincidence=.TRUE.
+
+      ! read coarse longitue and latitude on domain
+      tl_coord0=td_coord0
+      CALL iom_open(tl_coord0)
+
+      !2-1 compute domain
+      tl_dom0=dom_init( tl_coord0,         &
+      &                 id_imin0, id_imax0,&
+      &                 id_jmin0, id_jmax0 )
+
+      !2-2 close file
+      CALL iom_close(tl_coord0)
+
+      !2-3 read variables on domain (ugly way to do it, have to work on it)
+      !2-3-1 init mpp structure
+      tl_mppcoord0=mpp_init(tl_coord0)
+
+      CALL file_clean(tl_coord0)
+
+      !2-3-2 get processor to be used
+      CALL mpp_get_use( tl_mppcoord0, tl_dom0 )
+
+      !2-3-3 open mpp files
+      CALL iom_mpp_open(tl_mppcoord0)
+
+      !2-3-4 read variable value on domain
+      tl_lon0=iom_mpp_read_var(tl_mppcoord0,'longitude',td_dom=tl_dom0)
+      tl_lat0=iom_mpp_read_var(tl_mppcoord0,'latitude' ,td_dom=tl_dom0)
+
+      !2-3-5 close mpp files
+      CALL iom_mpp_close(tl_mppcoord0)
+
+      !2-3-6 clean structure
+      CALL mpp_clean(tl_mppcoord0)
+
+      ! read fine longitue and latitude
+      tl_lon1=iom_read_var(td_coord1,'longitude')
+      tl_lat1=iom_read_var(td_coord1,'latitude')
+      
+      CALL logger_debug("GRID CHECK COINCIDENCE:"//&
+      &        " fine   grid "//TRIM(td_coord1%c_name) )
+      CALL logger_debug("GRID CHECK COINCIDENCE:"//&
+      &        " coarse grid "//TRIM(td_coord0%c_name) )
+
+      !1- check domain
+      !1-1 check global grid
+      IF( .NOT. grid_is_global(tl_lon0, tl_lat0) )THEN
+         IF( grid_is_global(tl_lon1, tl_lat1) )THEN
+
+            ll_coincidence=.FALSE.
+            CALL logger_fatal("GRID CHECK COINCIDENCE:"//&
+            &        " fine   grid is global,"//&
+            &        " coarse grid is not ")
+
+         ELSE
+            !1-2 ew overlap
+            il_ew1=tl_lon1%i_ew
+            IF( il_ew1 >= 0 )THEN
+
+               il_ew0=tl_lon0%i_ew
+               IF( il_ew0 < 0 )THEN
+                  CALL logger_fatal("GRID CHECK COINCIDENCE: "//&
+                  &        "fine grid has east west overlap,"//&
+                  &        " coarse grid not ")
+               ENDIF
+
+               il_jmin1=1+ig_ghost
+               il_jmax1=tl_lon1%t_dim(2)%i_len-ig_ghost
+
+               ll_coincidence=grid__check_lat(&
+               &                     tl_lat0%d_value(1,:,1,1),&
+               &                     tl_lat1%d_value(1,il_jmin1:il_jmax1,1,1),&
+               &                     id_rho(jp_J) )
+
+            ELSE
+               !1-3 other case
+               il_imin1=1+ig_ghost
+               il_jmin1=1+ig_ghost
+
+               il_imax1=tl_lon1%t_dim(1)%i_len-ig_ghost
+               il_jmax1=tl_lon1%t_dim(2)%i_len-ig_ghost
+
+               ll_coincidence=grid__check_corner(&
+               &                      tl_lon0%d_value(:,:,1,1),&
+               &                      tl_lat0%d_value(:,:,1,1),&
+               &                      tl_lon1%d_value(il_imin1:il_imax1, &
+               &                                      il_jmin1:il_jmax1, &
+               &                                      1,1),&
+               &                      tl_lat1%d_value(il_imin1:il_imax1, &
+               &                                      il_jmin1:il_jmax1, &
+               &                                      1,1) )
+
+            ENDIF
+            
+         ENDIF
+
+         IF( .NOT. ll_coincidence )THEN
+            CALL logger_fatal("GRID CHECK COINCIDENCE: no coincidence "//&
+            &              "between fine grid and coarse grid. invalid domain" )
+         ENDIF
+
+      ENDIF
+ 
+      !2- check refinement factor
+      ! select point in middle of fine grid
+      il_imid1=INT(tl_lon1%t_dim(1)%i_len*0.5)
+      il_jmid1=INT(tl_lon1%t_dim(2)%i_len*0.5)
+      
+      dl_lon1=tl_lon1%d_value(il_imid1, il_jmid1,1,1)
+      dl_lat1=tl_lat1%d_value(il_imid1, il_jmid1,1,1)
+
+      ! select closest point on coarse grid
+      il_indC(:)=grid_get_closest(tl_lon0%d_value(:,:,1,1),&
+      &                           tl_lat0%d_value(:,:,1,1),&
+      &                           dl_lon1, dl_lat1   )
+
+      IF( ANY(il_indC(:)==0) )THEN
+         CALL logger_fatal("GRID CHECK COINCIDENCE: can not find valid "//&
+         &              "coarse grid indices. invalid domain" )
+      ENDIF
+
+      dl_lon0=tl_lon0%d_value(il_indC(1),il_indC(2),1,1)
+      dl_lat0=tl_lat0%d_value(il_indC(1),il_indC(2),1,1)
+
+      ! look for closest fine grid point from selected coarse grid point
+      il_iind(:)=MAXLOC( tl_lon1%d_value(:,:,1,1), &
+      &                  tl_lon1%d_value(:,:,1,1) <= dl_lon0)
+
+      il_jind(:)=MAXLOC( tl_lat1%d_value(:,:,1,1), &
+      &                  tl_lat1%d_value(:,:,1,1) <= dl_lat0 )
+
+      il_indF(1)=il_iind(1)
+      il_indF(2)=il_jind(2)
+
+      IF( ANY(il_indF(:)==0) )THEN
+         CALL logger_fatal("GRID CHECK COINCIDENCE: can not find valid "//&
+         &              "fine grid indices. invalid domain" )
+      ENDIF
+
+      dl_lon1=tl_lon1%d_value(il_indF(1),il_indF(2),1,1)
+      dl_lat1=tl_lat1%d_value(il_indF(1),il_indF(2),1,1)
+
+      !2-1 check i-direction refinement factor
+      DO ji=1,MIN(3,il_imid1)
+
+         IF( il_indF(1)+ji*id_rho(jp_I)+1 > tl_lon1%t_dim(1)%i_len )THEN
+            CALL logger_debug("GRID CHECK COINCIDENCE: tl_lon1%t_dim(1)%i_len "//TRIM(fct_str(tl_lon1%t_dim(1)%i_len)))
+            CALL logger_debug("GRID CHECK COINCIDENCE: il_indF(1)+ji*id_rhoi+1 "//TRIM(fct_str(il_indF(1)+ji*id_rho(jp_I)+1)))
+            CALL logger_debug("GRID CHECK COINCIDENCE: il_indF(1) "//TRIM(fct_str(il_indF(1))))
+            CALL logger_debug("GRID CHECK COINCIDENCE: id_rhoi "//TRIM(fct_str(id_rho(jp_I))))
+            CALL logger_warn("GRID CHECK COINCIDENCE: domain to small "//&
+            &  " to check i-direction refinement factor ")
+            EXIT
+         ELSE
+            dl_lon1=tl_lon1%d_value(il_indF(1)+ji*id_rho(jp_I),il_indF(2),1,1)
+            dl_lon0=tl_lon0%d_value(il_indC(1)+ji,il_indC(2),1,1)
+
+            dl_lon1p=tl_lon1%d_value(il_indF(1)+ji*id_rho(jp_I)+1,il_indF(2),1,1)
+
+            dl_dlon=ABS(dl_lon1p-dl_lon1)*1.e-3
+
+            SELECT CASE(MOD(id_rho(jp_I),2))
+
+            CASE(0)
+
+               IF( dl_lon1 >= dl_lon0 .OR. dl_lon0 >= dl_lon1p )THEN
+                  ll_coincidence=.FALSE.
+                  CALL logger_debug("GRID CHECK COINCIDENCE: invalid "//&
+                  &  "i-direction refinement factor ("//&
+                  &   TRIM(fct_str(id_rho(jp_I)))//&
+                  &   ") between fine grid and coarse grid ")
+               ENDIF
+
+            CASE DEFAULT         
+            
+               IF( ABS(dl_lon1 - dl_lon0) > dl_dlon )THEN
+                  ll_coincidence=.FALSE.
+                  CALL logger_debug("GRID CHECK COINCIDENCE: invalid "//&
+                  &  "i-direction refinement factor ("//&
+                  &   TRIM(fct_str(id_rho(jp_I)))//&
+                  &  ") between fine grid and coarse grid ")
+               ENDIF
+            
+            END SELECT
+         ENDIF
+
+      ENDDO
+
+      !2-2 check j-direction refinement factor
+      DO jj=1,MIN(3,il_jmid1)
+
+         IF( il_indF(2)+jj*id_rho(jp_J)+1 > tl_lat1%t_dim(2)%i_len )THEN
+            CALL logger_warn("GRID CHECK COINCIDENCE: domain to small "//&
+            &  " to check j-direction refinement factor ")
+            EXIT
+         ELSE      
+            dl_lat1=tl_lat1%d_value(il_indF(1),il_indF(2)+jj*id_rho(jp_J),1,1)
+            dl_lat0=tl_lat0%d_value(il_indC(1),il_indC(2)+jj,1,1)
+
+            dl_lat1p=tl_lat1%d_value(il_indF(1),il_indF(2)+jj*id_rho(jp_J)+1,1,1)
+
+            dl_dlat=ABS(dl_lat1p-dl_lat1)*1.e-3
+
+            SELECT CASE(MOD(id_rho(jp_J),2))
+
+            CASE(0)
+               
+               IF( dl_lat1 >= dl_lat0 .OR. dl_lat0 >= dl_lat1p )THEN
+                  ll_coincidence=.FALSE.
+                  CALL logger_debug("GRID CHECK COINCIDENCE: invalid "//&
+                  &  "j-direction refinement factor ("//&
+                  &   TRIM(fct_str(id_rho(jp_J)))//&
+                  &  ") between fine grid and coarse grid ")
+               ENDIF
+
+            CASE DEFAULT
+
+               IF( ABS(dl_lat1-dl_lat0) > dl_dlat )THEN
+                  ll_coincidence=.FALSE.
+                  CALL logger_debug("GRID CHECK COINCIDENCE: invalid "//&
+                  &  "j-direction refinement factor ("//&
+                  &   TRIM(fct_str(id_rho(jp_J)))//&
+                  &  ") between fine grid and coarse grid ")
+               ENDIF
+
+            END SELECT
+         ENDIF
+
+      ENDDO
+
+      IF( .NOT. ll_coincidence )THEN
+         CALL logger_fatal("GRID CHECK COINCIDENCE: no coincidence "//&
+         &              "between fine and coarse grid: "//&
+         &              "invalid refinement factor" )
+      ENDIF
+
+   END SUBROUTINE grid_check_coincidence
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function check that fine grid is 
+   !> inside coarse grid 
+   !
+   !> @details
+   !> 
+   !> @note deltalon and delatlat are used only to avoid issue due to 
+   !> cubic interpolation approximation on the firsts grid points  
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_lon0 : table of coarse grid longitude
+   !> @param[in] dd_lat0 : table of coarse grid latitude
+   !> @param[in] dd_lon1 : table of fine   grid longitude 
+   !> @param[in] dd_lat1 : table of fine   grid latitude
+   !> @return logical, fine grid is inside coarse grid
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION grid__check_corner(dd_lon0, dd_lat0, &
+   &                           dd_lon1, dd_lat1 )
+   IMPLICIT NONE
+      ! Argument      
+      REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_lon0
+      REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_lat0
+      REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_lon1
+      REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_lat1
+
+      ! function
+      LOGICAL :: grid__check_corner
+
+      ! local variable
+      INTEGER(i4), DIMENSION(2) :: il_shape0
+      INTEGER(i4), DIMENSION(2) :: il_shape1
+
+      INTEGER(i4) :: il_imin0
+      INTEGER(i4) :: il_jmin0
+      INTEGER(i4) :: il_imax0
+      INTEGER(i4) :: il_jmax0
+
+      INTEGER(i4) :: il_imin1
+      INTEGER(i4) :: il_jmin1
+      INTEGER(i4) :: il_imax1
+      INTEGER(i4) :: il_jmax1
+
+      REAL(dp)    :: dl_lon0
+      REAL(dp)    :: dl_lat0
+
+      REAL(dp)    :: dl_lon1
+      REAL(dp)    :: dl_lat1
+
+      REAL(dp)    :: dl_dlon
+      REAL(dp)    :: dl_dlat
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! init
+      grid__check_corner=.TRUE.
+
+      il_shape0=SHAPE(dd_lon0(:,:))
+      il_shape1=SHAPE(dd_lon1(:,:))
+
+      !1- check if fine grid inside coarse grid domain
+      il_imin0=1 ; il_imax0=il_shape0(1)
+      il_jmin0=1 ; il_jmax0=il_shape0(2)
+
+      il_imin1=1 ; il_imax1=il_shape1(1)
+      il_jmin1=1 ; il_jmax1=il_shape1(2)
+
+      ! check lower left corner
+      dl_lon0 = dd_lon0(il_imin0, il_jmin0  )
+      dl_lat0 = dd_lat0(il_imin0, il_jmin0  )
+
+      dl_lon1 = dd_lon1(il_imin1, il_jmin1)
+      dl_lat1 = dd_lat1(il_imin1, il_jmin1)
+
+      dl_dlon=ABS(dd_lon1(il_imin1+1,il_jmin1  )-dl_lon1)*1.e-3
+      dl_dlat=ABS(dd_lat1(il_imin1  ,il_jmin1+1)-dl_lat1)*1.e-3
+
+      IF( (ABS(dl_lon1-dl_lon0)>dl_dlon) .AND. (dl_lon1 < dl_lon0 ) .OR. & 
+      &   (ABS(dl_lat1-dl_lat0)>dl_dlat) .AND. (dl_lat1 < dl_lat0 ) )THEN
+
+         CALL logger_error("GRID CHECK COINCIDENCE: fine grid lower left "//&
+         &     "corner  not north east of coarse grid (imin,jmin) ")
+         CALL logger_debug(" fine   grid lower left ( "//&
+         &              TRIM(fct_str(dl_lon1))//","//&
+         &              TRIM(fct_str(dl_lat1))//")" )
+         CALL logger_debug(" coarse grid lower left ( "//&
+         &              TRIM(fct_str(dl_lon0))//","//&
+         &              TRIM(fct_str(dl_lat0))//")" )
+         grid__check_corner=.FALSE.
+
+      ENDIF
+
+      ! check upper left corner
+      dl_lon0 = dd_lon0(il_imin0, il_jmax0  )
+      dl_lat0 = dd_lat0(il_imin0, il_jmax0  )
+
+      dl_lon1 = dd_lon1(il_imin1, il_jmax1)
+      dl_lat1 = dd_lat1(il_imin1, il_jmax1)
+
+      dl_dlon=ABS(dd_lon1(il_imin1+1,il_jmax1  )-dl_lon1)*1.e-3
+      dl_dlat=ABS(dd_lat1(il_imin1  ,il_jmax1-1)-dl_lat1)*1.e-3
+
+      IF( (ABS(dl_lon1-dl_lon0)>dl_dlon) .AND. (dl_lon1 < dl_lon0) .OR. &
+      &   (ABS(dl_lat1-dl_lat0)>dl_dlat) .AND. (dl_lat1 > dl_lat0) )THEN
+
+         CALL logger_error("GRID CHECK COINCIDENCE: fine grid upper left "//&
+         &     "corner not south east of coarse grid (imin,jmax) ")
+         CALL logger_debug(" fine   grid upper left ("//&
+         &              TRIM(fct_str(dl_lon1))//","//&
+         &              TRIM(fct_str(dl_lat1))//")")
+         CALL logger_debug(" coasre grid upper left ("//&
+         &              TRIM(fct_str(dl_lon0))//","//&
+         &              TRIM(fct_str(dl_lat0))//")")
+         grid__check_corner=.FALSE.
+
+      ENDIF
+
+      ! check lower right corner
+      dl_lon0 = dd_lon0(il_imax0, il_jmin0  )
+      dl_lat0 = dd_lat0(il_imax0, il_jmin0  )
+
+      dl_lon1 = dd_lon1(il_imax1, il_jmin1)
+      dl_lat1 = dd_lat1(il_imax1, il_jmin1)
+
+      dl_dlon=ABS(dd_lon1(il_imax1-1,il_jmin1  )-dl_lon1)*1.e-3
+      dl_dlat=ABS(dd_lat1(il_imax1  ,il_jmin1+1)-dl_lat1)*1.e-3
+
+      IF( (ABS(dl_lon1-dl_lon0)>dl_dlon) .AND. (dl_lon1 > dl_lon0) .OR. &
+      &   (ABS(dl_lat1-dl_lat0)>dl_dlat) .AND. (dl_lat1 < dl_lat0) )THEN
+
+         CALL logger_error("GRID CHECK COINCIDENCE: fine grid lower right "//&
+         &     "corner not north west west of coarse grid (imax,jmin) ")
+         CALL logger_debug(" fine   grid lower right ( "//&
+         &              TRIM(fct_str(dl_lon1))//","//&
+         &              TRIM(fct_str(dl_lat1))//")" )
+         CALL logger_debug(" coarse grid lower right ( "//&
+         &              TRIM(fct_str(dl_lon0))//","//&
+         &              TRIM(fct_str(dl_lat0))//")" )   
+         grid__check_corner=.FALSE.
+
+      ENDIF
+
+      ! check upper right corner
+      dl_lon0 = dd_lon0(il_imax0, il_jmax0  )
+      dl_lat0 = dd_lat0(il_imax0, il_jmax0  )
+
+      dl_lon1 = dd_lon1(il_imax1, il_jmax1)
+      dl_lat1 = dd_lat1(il_imax1, il_jmax1)
+
+      dl_dlon=ABS(dd_lon1(il_imax1-1,il_jmax1  )-dl_lon1)*1.e-3
+      dl_dlat=ABS(dd_lat1(il_imax1  ,il_jmax1-1)-dl_lat1)*1.e-3
+
+      IF( (ABS(dl_lon1-dl_lon0)>dl_dlon) .AND. (dl_lon1 > dl_lon0) .OR. &
+      &   (ABS(dl_lat1-dl_lat0)>dl_dlat) .AND. (dl_lat1 > dl_lat0) )THEN
+
+         CALL logger_error("GRID CHECK COINCIDENCE: fine grid upper right "//&
+         &     "corner not south west of coarse grid (imax,jmax) ")
+         CALL logger_debug(" fine   grid upper right ( "//&
+         &              TRIM(fct_str(dl_lon1))//","//&
+         &              TRIM(fct_str(dl_lat1))//")" )
+         CALL logger_debug(" fine   imax1 jmax1 ( "//&
+         &              TRIM(fct_str(il_imax1))//","//&
+         &              TRIM(fct_str(il_jmax1))//")" )
+         CALL logger_debug(" coarse grid upper right ( "//&
+         &              TRIM(fct_str(dl_lon0))//","//&
+         &              TRIM(fct_str(dl_lat0))//")" )    
+         CALL logger_debug(" fine   imax0 jmax0 ( "//&
+         &              TRIM(fct_str(il_imax0))//","//&
+         &              TRIM(fct_str(il_jmax0))//")" )
+         grid__check_corner=.FALSE.
+
+      ENDIF      
+
+   END FUNCTION grid__check_corner
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function check that fine grid latitude are 
+   !> inside coarse grid latitude
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] dd_lat0 : table of coarse grid latitude 
+   !> @param[in] dd_lat1 : table of fine grid latitude 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION grid__check_lat(dd_lat0, dd_lat1, id_rhoj)
+      IMPLICIT NONE
+      ! Argument 
+      REAL(dp), DIMENSION(:), INTENT(IN) :: dd_lat0
+      REAL(dp), DIMENSION(:), INTENT(IN) :: dd_lat1
+      INTEGER(i4)           , INTENT(IN) :: id_rhoj
+
+      ! function
+      LOGICAL :: grid__check_lat
+
+      ! local variable
+      INTEGER(i4), DIMENSION(1) :: il_shape0
+      INTEGER(i4), DIMENSION(1) :: il_shape1
+
+      INTEGER(i4) :: il_jmin0
+      INTEGER(i4) :: il_jmax0
+
+      INTEGER(i4) :: il_jmin1
+      INTEGER(i4) :: il_jmax1
+
+      REAL(dp)    :: dl_dlat
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! init
+      grid__check_lat=.TRUE.
+
+      il_shape0(:)=SHAPE(dd_lat0(:))
+      il_shape1(:)=SHAPE(dd_lat1(:))
+
+      !1- check if fine grid inside coarse grid domain
+      il_jmin0=1+1 ; il_jmax0=il_shape0(1)-1
+
+      il_jmin1=1+id_rhoj ; il_jmax1=il_shape1(1)-id_rhoj
+
+      dl_dlat=ABS(dd_lat1(il_jmin1+1)-dd_lat1(il_jmin1))*1.e-3
+
+      ! check lower left fine grid
+      IF( ABS(dd_lat1(il_jmin1)-dd_lat0(il_jmin0)) > dl_dlat .AND. &
+      &   dd_lat1(il_jmin1) < dd_lat0(il_jmin0) )THEN
+
+         CALL logger_error("GRID CHECK COINCIDENCE: fine grid lower point"//&
+         &     " not north of coarse grid (jmin) ")
+         CALL logger_debug(" fine grid lower point ( "//&
+         &              TRIM(fct_str(dd_lat1(il_jmin1)))//")" )
+         CALL logger_debug(" coarse grid lower point ( "//&
+         &              TRIM(fct_str(dd_lat0(il_jmin0)))//")" )
+         grid__check_lat=.FALSE.
+
+      ENDIF
+
+      dl_dlat=ABS(dd_lat1(il_jmax1-1)-dd_lat1(il_jmax1))*1.e-3
+
+      ! check upper left fine grid
+      IF( ABS(dd_lat1(il_jmax1)-dd_lat0(il_jmax0)) > dl_dlat .AND. &
+      &   dd_lat1(il_jmax1) > dd_lat0(il_jmax0) )THEN
+
+         CALL logger_error("GRID CHECK COINCIDENCE: fine grid upper point"//&
+         &     " not south of coarse grid (jmax) ")
+         CALL logger_debug(" fine grid upper point ("//&
+         &              TRIM(fct_str(dd_lat1(il_jmax1)))//")")
+         CALL logger_debug(" coasre grid upper point ("//&
+         &              TRIM(fct_str(dd_lat0(il_jmax0)))//")")
+         grid__check_lat=.FALSE.
+
+      ENDIF
+      
+   END FUNCTION grid__check_lat
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine add ghost cell at boundaries.
+   !> 
+   !> @author J.Paul
+   !> - Nov, 2013-Initial version
+   !
+   !> @param[inout] td_var : table of variable structure 
+   !> @param[in] id_ighost : i-direction ghost cell factor 
+   !> @param[in] id_jghost : j-direction ghost cell factor 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE grid_add_ghost(td_var, id_ighost, id_jghost)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(INOUT) :: td_var
+      INTEGER(i4), INTENT(IN   ) :: id_ighost
+      INTEGER(i4), INTENT(IN   ) :: id_jghost
+
+      ! local variable
+      INTEGER(i4) :: il_imin
+      INTEGER(i4) :: il_jmin
+      INTEGER(i4) :: il_imax
+      INTEGER(i4) :: il_jmax
+
+      REAL(dp), DIMENSION(:,:,:,:) , ALLOCATABLE :: dl_value
+      
+      TYPE(TVAR) :: tl_var
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      IF( ALL(td_var%t_dim(1:2)%l_use) )THEN
+
+         CALL logger_warn( "ADD GHOST: dimension change in variable "//&
+         &              TRIM(td_var%c_name) )
+
+         ! copy variable
+         tl_var=td_var
+
+         CALL var_del_value(td_var)
+
+         ! compute indice to fill center
+         il_imin=1+id_ighost*ig_ghost
+         il_jmin=1+id_jghost*ig_ghost
+
+         il_imax=il_imin+tl_var%t_dim(1)%i_len-1
+         il_jmax=il_jmin+tl_var%t_dim(2)%i_len-1
+
+         ! compute new dimension
+         td_var%t_dim(1)%i_len = tl_var%t_dim(1)%i_len + 2*id_ighost*ig_ghost
+         td_var%t_dim(2)%i_len = tl_var%t_dim(2)%i_len + 2*id_jghost*ig_ghost
+
+         ALLOCATE(dl_value(td_var%t_dim(1)%i_len, &
+         &                 td_var%t_dim(2)%i_len, &
+         &                 td_var%t_dim(3)%i_len, &
+         &                 td_var%t_dim(4)%i_len) )
+
+         dl_value(:,:,:,:)=tl_var%d_fill
+
+         dl_value(il_imin:il_imax, &
+         &        il_jmin:il_jmax, &
+         &              :,:)  =  tl_var%d_value(:,:,:,:)
+
+         ! add variable value
+         CALL var_add_value(td_var,dl_value(:,:,:,:))
+
+         ! save variable type
+         td_var%i_type=tl_var%i_type
+         
+         DEALLOCATE( dl_value )
+
+         CALL var_clean(tl_var)
+
+      ENDIF
+
+   END SUBROUTINE grid_add_ghost
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine delete ghost cell at boundaries.
+   !> 
+   !> @author J.Paul
+   !> - Nov, 2013-Initial version
+   !
+   !> @param[inout] td_var : table of variable structure 
+   !> @param[in] id_ighost : i-direction ghost cell factor 
+   !> @param[in] id_jghost : j-direction ghost cell factor 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE grid_del_ghost(td_var, id_ighost, id_jghost)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(INOUT) :: td_var
+      INTEGER(i4), INTENT(IN   ) :: id_ighost
+      INTEGER(i4), INTENT(IN   ) :: id_jghost
+
+      ! local variable
+      INTEGER(i4) :: il_imin
+      INTEGER(i4) :: il_jmin
+      INTEGER(i4) :: il_imax
+      INTEGER(i4) :: il_jmax
+
+      REAL(dp), DIMENSION(:,:,:,:) , ALLOCATABLE :: dl_value
+      
+      TYPE(TVAR) :: tl_var
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      IF( ALL(td_var%t_dim(1:2)%l_use) )THEN
+
+         CALL logger_warn( "DEL GHOST: dimension change in variable "//&
+         &              TRIM(td_var%c_name) )
+
+         ! copy variable
+         tl_var=td_var
+
+         CALL var_del_value(td_var)
+
+         ! compute indice to get center
+         il_imin=1+id_ighost*ig_ghost
+         il_jmin=1+id_jghost*ig_ghost
+
+         il_imax=tl_var%t_dim(1)%i_len-id_ighost*ig_ghost
+         il_jmax=tl_var%t_dim(2)%i_len-id_jghost*ig_ghost
+
+         ! compute new dimension
+         td_var%t_dim(1)%i_len = tl_var%t_dim(1)%i_len - 2*id_ighost*ig_ghost
+         td_var%t_dim(2)%i_len = tl_var%t_dim(2)%i_len - 2*id_jghost*ig_ghost
+
+         ALLOCATE(dl_value(td_var%t_dim(1)%i_len, &
+         &                 td_var%t_dim(2)%i_len, &
+         &                 td_var%t_dim(3)%i_len, &
+         &                 td_var%t_dim(4)%i_len) )
+
+         dl_value(:,:,:,:)=tl_var%d_fill
+
+         dl_value(:,:,:,:)  =  tl_var%d_value(il_imin:il_imax, &
+         &                                    il_jmin:il_jmax, &
+         &                                    :,:)
+
+         ! add variable value
+         CALL var_add_value(td_var,dl_value(:,:,:,:))
+
+         ! save variable type
+         td_var%i_type=tl_var%i_type
+         
+         DEALLOCATE( dl_value )
+
+         CALL var_clean(tl_var)
+
+      ENDIF
+
+   END SUBROUTINE grid_del_ghost
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill small closed sea with fill value. 
+   !
+   !> @details
+   !> the minimum size (nbumber of point) of closed sea to be kept could be
+   !> sepcify with id_minsize.
+   !> By default only the biggest sea is preserve.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] id_mask : domain mask (from grid_split_domain)
+   !> @param[in] id_minsize : minimum size of sea to be kept
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE grid_fill_small_dom(td_var, id_mask, id_minsize)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR) ,                 INTENT(INOUT) :: td_var
+      INTEGER(i4), DIMENSION(:,:), INTENT(IN   ), OPTIONAL :: id_mask
+      INTEGER(i4),                 INTENT(IN   ), OPTIONAL :: id_minsize
+
+      ! local variable
+      INTEGER(i4)                              :: il_ndom
+      INTEGER(i4)                              :: il_minsize
+      INTEGER(i4), DIMENSION(2)                :: il_shape
+      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_tmp
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jk
+      INTEGER(i4) :: jl
+      !----------------------------------------------------------------
+
+      il_shape(:)=SHAPE(id_mask(:,:))
+      IF( ANY(il_shape(:) /= td_var%t_dim(1:2)%i_len) )THEN
+         CALL logger_error("GRID FILL SMALL DOM: variable and mask "//&
+         &              "dimension differ")
+      ELSE
+
+         il_ndom=MINVAL(id_mask(:,:))
+
+         ALLOCATE( il_tmp(il_shape(1),il_shape(2)) )
+         il_tmp(:,:)=0
+         DO ji=-1,il_ndom,-1
+            WHERE( id_mask(:,:)==ji ) 
+               il_tmp(:,:)=SUM(id_mask(:,:),id_mask(:,:)==ji)/ji
+            END WHERE
+         ENDDO
+
+         il_minsize=MAXVAL(il_tmp(:,:))
+         IF( PRESENT(id_minsize) ) il_minsize=id_minsize
+
+         DO jl=1,td_var%t_dim(4)%i_len
+            DO jk=1,td_var%t_dim(3)%i_len
+               WHERE( il_tmp(:,:) < il_minsize ) 
+                  td_var%d_value(:,:,jk,jl)=td_var%d_fill
+               END WHERE
+            ENDDO
+         ENDDO
+
+         DEALLOCATE( il_tmp )
+
+      ENDIF
+
+   END SUBROUTINE grid_fill_small_dom
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine compute closed sea domain.
+   !
+   !> @details
+   !> to each domain is associated a negative value id (from -1 to ...)
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var : variable strucutre 
+   !> @param[in] id_level : level
+   !> @return domain mask  
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION grid_split_domain(td_var, id_level)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_var
+      INTEGER(i4), INTENT(IN), OPTIONAL :: id_level
+
+      ! function
+      INTEGER(i4), DIMENSION(td_var%t_dim(1)%i_len, &
+      &                      td_var%t_dim(2)%i_len ) :: grid_split_domain
+
+      ! local variable
+      INTEGER(i4)                              :: il_domid
+      INTEGER(i4)                              :: il_level
+      INTEGER(i4), DIMENSION(2)                :: il_shape
+      INTEGER(i4), DIMENSION(2)                :: il_ind
+      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_mask
+      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_tmp
+
+      LOGICAL                                  :: ll_full
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jim
+      INTEGER(i4) :: jip
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jjm
+      INTEGER(i4) :: jjp
+      !----------------------------------------------------------------
+      il_level=1
+      IF( PRESENT(id_level) ) il_level=id_level
+
+      ! init
+      il_domid=-1
+
+      il_shape(:)=td_var%t_dim(1:2)%i_len
+      ALLOCATE( il_mask(il_shape(1),il_shape(2)) )
+      il_mask(:,:)=0
+      WHERE( td_var%d_value(:,:,il_level,1)/=td_var%d_fill ) il_mask(:,:)=1
+
+      il_ind(:)=MAXLOC( il_mask(:,:) )
+      DO WHILE( il_mask(il_ind(1), il_ind(2)) == 1 )
+
+         il_mask(il_ind(1),il_ind(2))=il_domid
+         ll_full=.FALSE.
+
+         ALLOCATE( il_tmp(il_shape(1),il_shape(2)) )
+
+         DO WHILE( .NOT. ll_full )
+            il_tmp(:,:)=0
+
+            ll_full=.TRUE.
+            DO jj=1,il_shape(2)
+               DO ji=1,il_shape(1)
+                  IF( il_mask(ji,jj)==il_domid )THEN
+                     jim=MAX(1,ji-1)   ;  jip=MIN(il_shape(1),ji+1)
+                     jjm=MAX(1,jj-1)   ;  jjp=MIN(il_shape(2),jj+1)
+                     
+                     WHERE( il_mask(jim:jip,jjm:jjp)==1 )
+                        il_mask(jim:jip,jjm:jjp)=il_domid
+                        il_tmp(jim:jip,jjm:jjp)=1
+                     END WHERE
+                  ENDIF
+               ENDDO
+            ENDDO
+            IF( SUM(il_tmp(:,:))/=0 ) ll_full=.FALSE.
+
+         ENDDO
+         DEALLOCATE( il_tmp )
+
+         il_ind(:)=MAXLOC( il_mask(:,:) )
+         il_domid=il_domid-1
+
+      ENDDO
+
+      ! save result
+      grid_split_domain(:,:)=il_mask(:,:)
+
+      DEALLOCATE( il_mask )
+
+      CALL logger_info("GRID SPLIT DOMAIN: "//TRIM( fct_str(ABS(il_domid+1)) )//&
+      &             " domain found" ) 
+
+   END FUNCTION grid_split_domain
+   !> @endcode
+!   !-------------------------------------------------------------------
+!   !> @brief This function 
+!   !
+!   !> @details
+!   !
+!   !> @author J.Paul
+!   !> - Nov, 2013- Initial Version
+!   !
+!   !> @param[in] 
+!   !-------------------------------------------------------------------
+!   !> @code
+!   FUNCTION grid_()
+!      IMPLICIT NONE
+!      ! Argument      
+!      ! function
+!      ! local variable
+!      ! loop indices
+!      !----------------------------------------------------------------
+!
+!   END FUNCTION grid_
+!   !> @endcode
+!   !-------------------------------------------------------------------
+!   !> @brief This subroutine 
+!   !
+!   !> @details
+!   !
+!   !> @author J.Paul
+!   !> - Nov, 2013- Initial Version
+!   !
+!   !> @param[in] 
+!   !-------------------------------------------------------------------
+!   !> @code
+!   SUBROUTINE grid_()
+!      IMPLICIT NONE
+!      ! Argument      
+!      ! local variable
+!      ! loop indices
+!      !----------------------------------------------------------------
+!
+!   END SUBROUTINE grid_
+!   !> @endcode
+END MODULE grid
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/interp.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/interp.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/interp.f90	(revision 4245)
@@ -0,0 +1,2322 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: interp
+!
+! DESCRIPTION:
+!> @brief 
+!> This module manage interpolation on regular grid.
+!> @note It is used to work on ORCA grid, as we work only with grid indices.
+!>
+!> @warning due to the use of second derivative when using cubic interpolation
+!> you should add 2 extrabands
+!>
+!> @details
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!> @todo
+!> - interp 3D
+!> - see issue when fill value is zero for check cubic_fill..
+!----------------------------------------------------------------------
+MODULE interp
+
+   USE netcdf                          ! nf90 library
+   USE global                          ! global variable
+   USE kind                            ! F90 kind parameter
+   USE logger                             ! log file manager
+   USE fct                             ! basic useful function
+!   USE date                            ! date manager
+   USE att                             ! attribute manager
+   USE dim                             ! dimension manager
+   USE var                             ! variable manager
+!   USE file                            ! file manager
+!   USE iom                             ! I/O manager
+!   USE dom                             ! domain manager
+   USE grid                            ! grid manager
+   USE extrap                          ! extrapolation manager
+!   USE interp                          ! interpolation manager
+!   USE filter                          ! filter manager
+!   USE mpp                             ! MPP manager
+!   USE iom_mpp                         ! MPP I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+
+   ! function and subroutine
+   PUBLIC :: interp_detect             !< detected point to be interpolated
+   PUBLIC :: interp_fill_value         !< interpolate value over detectected point
+   PUBLIC :: interp_create_mixed_grid  !< create mixed grid
+   PUBLIC :: interp_clean_mixed_grid   !< clean mixed grid
+
+   PRIVATE :: interp__detect           !< detected point to be interpolated
+   PRIVATE :: interp__detect_wrapper   !< detected point to be interpolated
+   PRIVATE :: interp__fill_value_wrapper !< interpolate value over detectected point
+   PRIVATE :: interp__fill_value       !< interpolate value over detectected point
+   PRIVATE :: interp__clean_even_grid  !< clean even mixed grid
+   PRIVATE :: interp__del_offset       !< remove offset from interpolated grid
+   PRIVATE :: interp__check_method     !< check if interpolation method available
+!   PRIVATE :: interp__3D               !< interpolate 3D grid
+   PRIVATE :: interp__2D               !< interpolate 2D grid
+   PRIVATE :: interp__1D               !< interpolate 1D grid 
+   PRIVATE :: interp__2D_cubic_coef    !< compute coefficient for bicubic interpolation 
+   PRIVATE :: interp__2D_cubic_fill    !< compute bicubic interpolation 
+   PRIVATE :: interp__2D_linear_coef   !< compute coefficient for bilinear interpolation
+   PRIVATE :: interp__2D_linear_fill   !< compute bilinear interpolation 
+   PRIVATE :: interp__2D_nearest_fill  !< compute nearest interpolation 
+   PRIVATE :: interp__1D_cubic_coef    !< compute coefficient for cubic interpolation 
+   PRIVATE :: interp__1D_cubic_fill    !< compute cubic interpolation 
+   PRIVATE :: interp__1D_linear_coef   !< compute coefficient for linear interpolation
+   PRIVATE :: interp__1D_linear_fill   !< compute linear interpolation 
+   PRIVATE :: interp__1D_nearest_fill  !< compute nearest interpolation 
+!   PRIVATE :: interp__longitude
+   
+   TYPE TINTERP
+      !CHARACTER(LEN=lc) :: c_name = 'unknown'   !< interpolation method name
+      !CHARACTER(LEN=lc) :: c_factor = 'unknown' !< interpolation factor
+      !CHARACTER(LEN=lc) :: c_divisor = 'unknown'   !< interpolation divisor
+      CHARACTER(LEN=lc) :: c_name   = '' !< interpolation method name
+      CHARACTER(LEN=lc) :: c_factor = '' !< interpolation factor
+      CHARACTER(LEN=lc) :: c_divisor= '' !< interpolation divisor
+   END TYPE TINTERP
+
+   INTERFACE interp_detect
+      MODULE PROCEDURE interp__detect_wrapper !< detected point to be interpolated
+   END INTERFACE interp_detect
+
+   INTERFACE interp_fill_value
+      MODULE PROCEDURE interp__fill_value_wrapper !< detected point to be interpolated
+   END INTERFACE interp_fill_value
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function check if interpolation method available.
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_method : interpolation method
+   !> @return 
+   !> @todo see extrap_detect
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION interp__check_method( cd_method )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=lc) :: cd_method
+
+      ! function
+      LOGICAL :: interp__check_method
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_interp
+      CHARACTER(LEN=lc) :: cl_method
+
+      ! loop indices
+      INTEGER(I4) :: ji
+      !----------------------------------------------------------------
+
+      cl_method=fct_lower(cd_method)
+
+      interp__check_method=.FALSE.
+      DO ji=1,ig_ninterp
+         cl_interp=fct_lower(cg_interp_list(ji))
+         IF( TRIM(cl_interp) == TRIM(cl_method) )THEN
+            interp__check_method=.TRUE.
+            EXIT
+         ENDIF
+      ENDDO
+
+   END FUNCTION interp__check_method
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function detected point to be interpolated.
+   !> 
+   !> @details 
+   !> Actually it checks, the number of dimension used for this variable
+   !> and launch interp__detect which detected point to be interpolated.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mix : mixed grid variable (to interpolate)
+   !> @param[in] id_rho : table of refinement factor
+   !> @return table of detected point to be interpolated 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION interp__detect_wrapper( td_mix, id_rho )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_mix
+      INTEGER(I4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_rho
+
+      ! function
+      INTEGER(i4), DIMENSION(td_mix%t_dim(1)%i_len,&
+      &                      td_mix%t_dim(2)%i_len,&
+      &                      td_mix%t_dim(3)%i_len ) :: interp__detect_wrapper
+
+      ! local variable
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      IF( .NOT. ANY(td_mix%t_dim(1:3)%l_use) )THEN
+         ! no dimension I-J-K used
+         CALL logger_debug(" INTERP DETECT: nothing done for variable"//&
+         &              TRIM(td_mix%c_name) )
+         
+         interp__detect_wrapper(:,:,:)=0
+
+      ELSE IF( ALL(td_mix%t_dim(1:3)%l_use) )THEN
+         
+         ! detect point to be interpolated on I-J-K
+         CALL logger_debug(" INTERP DETECT: detect point "//&
+         &              TRIM(td_mix%c_point)//" for variable "//&
+         &              TRIM(td_mix%c_name) )
+         
+         interp__detect_wrapper(:,:,:)=interp__detect( td_mix, id_rho(:) )
+
+      ELSE IF( ALL(td_mix%t_dim(1:2)%l_use) )THEN
+
+         ! detect point to be interpolated on I-J
+         CALL logger_debug(" INTERP DETECT: detect point "//&
+         &              TRIM(td_mix%c_point)//" for variable "//&
+         &              TRIM(td_mix%c_name) )
+         
+         interp__detect_wrapper(:,:,1:1)=interp__detect( td_mix, id_rho(:))
+
+      ELSE IF( td_mix%t_dim(3)%l_use )THEN
+         
+         ! detect point to be interpolated on K
+         CALL logger_debug(" INTERP DETECT: detect vertical point "//&
+         &              " for variable "//TRIM(td_mix%c_name) )
+         
+         interp__detect_wrapper(1:1,1:1,:)=interp__detect( td_mix, id_rho(:) )
+
+      ENDIF              
+
+   END FUNCTION interp__detect_wrapper
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function detected point to be interpolated.
+   !> 
+   !> @details 
+   !> A special case is done for even refinement on ARAKAWA-C grid.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mix : mixed grid variable (to interpolate)
+   !> @param[in] id_rho : table of refinement factor
+   !> @return table of detected point to be interpolated 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION interp__detect( td_mix, id_rho )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_mix
+      INTEGER(I4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_rho
+
+      ! function
+      INTEGER(i4), DIMENSION(td_mix%t_dim(1)%i_len,&
+      &                      td_mix%t_dim(2)%i_len,&
+      &                      td_mix%t_dim(3)%i_len ) :: interp__detect
+
+      ! local variable
+      INTEGER(I4), DIMENSION(:), ALLOCATABLE :: il_rho
+
+      INTEGER(I4) :: il_xextra
+      INTEGER(I4) :: il_yextra
+      INTEGER(I4) :: il_zextra
+
+      INTEGER(i4), DIMENSION(3) :: il_dim
+
+      LOGICAL    , DIMENSION(3) :: ll_even
+
+      ! loop indices
+      INTEGER(I4) :: ji
+      INTEGER(I4) :: jj
+      INTEGER(I4) :: jk
+      !----------------------------------------------------------------
+      ALLOCATE( il_rho(ip_maxdim) )
+      il_rho(:)=1
+      IF( PRESENT(id_rho) ) il_rho(:)=id_rho(:)
+
+      ! special case for even refinement on ARAKAWA-C grid
+      ll_even(:)=.FALSE.
+      IF( MOD(il_rho(jp_I),2) == 0 ) ll_even(1)=.TRUE.
+      IF( MOD(il_rho(jp_J),2) == 0 ) ll_even(2)=.TRUE.
+      IF( MOD(il_rho(jp_K),2) == 0 ) ll_even(3)=.TRUE.         
+
+      SELECT CASE(TRIM(td_mix%c_point))
+         CASE('U')
+            ll_even(1)=.FALSE.
+         CASE('V')
+            ll_even(2)=.FALSE.
+         CASE('F')
+            ll_even(:)=.FALSE.
+      END SELECT
+
+      IF( ll_even(1) ) il_rho(jp_I)=il_rho(jp_I)+1
+      IF( ll_even(2) ) il_rho(jp_J)=il_rho(jp_J)+1
+      IF( ll_even(3) ) il_rho(jp_K)=il_rho(jp_K)+1
+
+      ! special case for cubic interpolation
+      il_xextra=0
+      il_yextra=0
+      il_zextra=0
+      SELECT CASE(TRIM(td_mix%c_interp(1)))
+      CASE('cubic')
+         ! those points can not be compute cause cubic interpolation
+         ! need second derivative.
+         IF( il_rho(jp_I) /= 1 ) il_xextra=3*il_rho(jp_I)
+         IF( il_rho(jp_J) /= 1 ) il_yextra=3*il_rho(jp_J)
+         IF( il_rho(jp_K) /= 1 ) il_zextra=3*il_rho(jp_K)
+      END SELECT
+
+      il_dim(:)=td_mix%t_dim(1:3)%i_len
+
+      interp__detect(:,:,:)=1
+
+      ! do not compute coarse grid point
+      interp__detect(1:td_mix%t_dim(1)%i_len:il_rho(jp_I), &
+      &              1:td_mix%t_dim(2)%i_len:il_rho(jp_J), &
+      &              1:td_mix%t_dim(3)%i_len:il_rho(jp_K)  ) = 0
+
+      ! do not compute point near fill value
+      FORALL( ji=1:il_dim(1):il_rho(jp_I), &
+      &       jj=1:il_dim(2):il_rho(jp_J), &
+      &       jk=1:il_dim(3):il_rho(jp_K), &
+      &       td_mix%d_value(ji,jj,jk,1) == td_mix%d_fill )
+
+         ! i-direction
+         interp__detect(MAX(1,ji-il_xextra):MIN(ji+il_xextra,il_dim(1)),&
+         &              MAX(1,jj-(il_rho(jp_J)-1)):MIN(jj+(il_rho(jp_J)-1),il_dim(2)),&
+         &              MAX(1,jk-(il_rho(jp_K)-1)):MIN(jk+(il_rho(jp_K)-1),il_dim(3)) )=0 
+         ! j-direction
+         interp__detect(MAX(1,ji-(il_rho(jp_I)-1)):MIN(ji+(il_rho(jp_I)-1),il_dim(1)),&
+         &              MAX(1,jj-il_yextra):MIN(jj+il_yextra,il_dim(2)),&
+         &              MAX(1,jk-(il_rho(jp_K)-1)):MIN(jk+(il_rho(jp_K)-1),il_dim(3)) )=0
+         ! k-direction
+         interp__detect(MAX(1,ji-(il_rho(jp_I)-1)):MIN(ji+(il_rho(jp_I)-1),il_dim(1)),&
+         &              MAX(1,jj-(il_rho(jp_J)-1)):MIN(jj+(il_rho(jp_J)-1),il_dim(2)),&
+         &              MAX(1,jk-il_zextra):MIN(jk+il_zextra,il_dim(3)) )=0         
+
+      END FORALL
+
+   END FUNCTION interp__detect
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine create mixed grid.
+   !> 
+   !> @details 
+   !> Created grid is fine resolution grid.
+   !> First and last point are coasre grid point. 
+   !>
+   !> A special case is done for even refinement on ARAKAWA-C grid.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var : coarse grid variable (should be extrapolated)
+   !> @param[out] td_mix : mixed grid variable
+   !> @param[in] id_rho  : table of refinment factor 
+   !>
+   !> @todo
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp_create_mixed_grid( td_var, td_mix, id_rho )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) ,               INTENT(IN   ) :: td_var 
+      TYPE(TVAR) ,               INTENT(  OUT) :: td_mix 
+      INTEGER(I4), DIMENSION(:), INTENT(IN   ), OPTIONAL :: id_rho
+
+      ! local variable
+      INTEGER(I4), DIMENSION(:), ALLOCATABLE :: il_rho
+
+      INTEGER(i4) :: il_xextra
+      INTEGER(i4) :: il_yextra
+      INTEGER(i4) :: il_zextra
+
+      LOGICAL, DIMENSION(3) :: ll_even
+
+      ! loop indices
+      !----------------------------------------------------------------
+      ALLOCATE(il_rho(ip_maxdim))
+      il_rho(:)=1
+      IF( PRESENT(id_rho) ) il_rho(:)=id_rho(:)
+
+      ! special case for even refinement on ARAKAWA-C grid
+      ll_even(:)=.FALSE.
+      IF( MOD(il_rho(jp_I),2) == 0 ) ll_even(1)=.TRUE.
+      IF( MOD(il_rho(jp_J),2) == 0 ) ll_even(2)=.TRUE.
+      IF( MOD(il_rho(jp_K),2) == 0 ) ll_even(3)=.TRUE.         
+
+      SELECT CASE(TRIM(td_var%c_point))
+         CASE('U')
+            ll_even(1)=.FALSE.
+         CASE('V')
+            ll_even(2)=.FALSE.
+         CASE('F')
+            ll_even(:)=.FALSE.
+      END SELECT
+
+      IF( ll_even(1) ) il_rho(jp_I)=il_rho(jp_I)+1
+      IF( ll_even(2) ) il_rho(jp_J)=il_rho(jp_J)+1
+      IF( ll_even(3) ) il_rho(jp_K)=il_rho(jp_K)+1
+
+      ! copy variable
+      td_mix=td_var
+
+      ! compute new dimension length
+      il_xextra=il_rho(jp_I)-1
+      td_mix%t_dim(1)%i_len=td_mix%t_dim(1)%i_len*il_rho(jp_I)-il_xextra
+
+      il_yextra=il_rho(jp_J)-1
+      td_mix%t_dim(2)%i_len=td_mix%t_dim(2)%i_len*il_rho(jp_J)-il_yextra
+
+      il_zextra=il_rho(jp_K)-1
+      td_mix%t_dim(3)%i_len=td_mix%t_dim(3)%i_len*il_rho(jp_K)-il_zextra
+
+      IF( ASSOCIATED(td_mix%d_value) ) DEALLOCATE( td_mix%d_value )
+      ALLOCATE( td_mix%d_value( td_mix%t_dim(1)%i_len, &
+      &                         td_mix%t_dim(2)%i_len, &
+      &                         td_mix%t_dim(3)%i_len, &
+      &                         td_mix%t_dim(4)%i_len) )
+
+      ! initialise to FillValue
+      td_mix%d_value(:,:,:,:)=td_mix%d_fill
+
+      ! quid qd coord ou bathy fourni par user ?? (offset ??)
+      td_mix%d_value(1:td_mix%t_dim(1)%i_len:il_rho(jp_I), &
+      &              1:td_mix%t_dim(2)%i_len:il_rho(jp_J), &
+      &              1:td_mix%t_dim(3)%i_len:il_rho(jp_K), :) = &
+      &     td_var%d_value(:,:,:,:)
+
+   END SUBROUTINE interp_create_mixed_grid
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine remove points added to mixed grid to compute
+   !> interpolation in the special case of even refinement on ARAKAWA-C grid.
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in]  td_mix : mixed grid variable
+   !> @param[in] id_rho  : table of refinment factor 
+   !>
+   !> @todo
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp__clean_even_grid( td_mix, id_rho )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(INOUT) :: td_mix 
+      INTEGER(I4), DIMENSION(:), INTENT(IN   ), OPTIONAL :: id_rho
+
+      ! local variable
+      INTEGER(I4), DIMENSION(:), ALLOCATABLE :: il_rho
+
+      INTEGER(i4) :: il_xextra
+      INTEGER(i4) :: il_yextra
+      INTEGER(i4) :: il_zextra
+
+      LOGICAL, DIMENSION(3) :: ll_even
+
+      LOGICAL, DIMENSION(:,:,:,:), ALLOCATABLE :: ll_mask
+
+      REAL(dp), DIMENSION(:)     , ALLOCATABLE :: dl_vect
+
+      TYPE(TVAR) :: tl_mix
+
+      ! loop indices
+      !----------------------------------------------------------------
+      ALLOCATE(il_rho(ip_maxdim))
+      il_rho(:)=1
+      IF( PRESENT(id_rho) ) il_rho(:)=id_rho(:)
+
+      ! special case for even refinement on ARAKAWA-C grid
+      ll_even(:)=.FALSE.
+      IF( MOD(il_rho(jp_I),2) == 0 ) ll_even(1)=.TRUE.
+      IF( MOD(il_rho(jp_J),2) == 0 ) ll_even(2)=.TRUE.
+      IF( MOD(il_rho(jp_K),2) == 0 ) ll_even(3)=.TRUE.         
+
+      SELECT CASE(TRIM(td_mix%c_point))
+         CASE('U')
+            ll_even(1)=.FALSE.
+         CASE('V')
+            ll_even(2)=.FALSE.
+         CASE('F')
+            ll_even(:)=.FALSE.
+      END SELECT
+
+      ! copy variable
+      tl_mix=td_mix
+
+      ! remove some point only if refinement in some direction is even
+      IF( ANY(ll_even(:)) )THEN
+
+         ALLOCATE( ll_mask( tl_mix%t_dim(1)%i_len, &
+         &                  tl_mix%t_dim(2)%i_len, &
+         &                  tl_mix%t_dim(3)%i_len, &
+         &                  tl_mix%t_dim(4)%i_len) )
+
+         ll_mask(:,:,:,:)=.TRUE.
+
+         IF( tl_mix%t_dim(1)%l_use .AND. ll_even(1) )THEN
+
+            il_rho(jp_I)=il_rho(jp_I)+1
+
+            ! locate wrong point on mixed grid
+            ll_mask(1:td_mix%t_dim(1)%i_len:il_rho(jp_I),:,:,:)=.FALSE.
+
+            ! compute coasre grid dimension length
+            il_xextra=il_rho(jp_I)-1
+            td_mix%t_dim(1)%i_len=(tl_mix%t_dim(1)%i_len+il_xextra)/il_rho(jp_I)
+
+            il_rho(jp_I)=il_rho(jp_I)-1
+            ! compute right fine grid dimension length
+            td_mix%t_dim(1)%i_len=td_mix%t_dim(1)%i_len*il_rho(jp_I)-il_xextra
+
+         ENDIF
+
+         IF( tl_mix%t_dim(2)%l_use .AND. ll_even(2) )THEN
+
+            il_rho(jp_J)=il_rho(jp_J)+1
+
+            ! locate wrong point on mixed grid
+            ll_mask(:,1:tl_mix%t_dim(2)%i_len:il_rho(jp_J),:,:)=.FALSE.
+
+            ! compute coasre grid dimension length
+            il_yextra=il_rho(jp_J)-1
+            td_mix%t_dim(2)%i_len=(tl_mix%t_dim(2)%i_len+il_yextra)/il_rho(jp_J)
+
+            il_rho(jp_J)=il_rho(jp_J)-1
+            ! compute right fine grid dimension length
+            td_mix%t_dim(2)%i_len=td_mix%t_dim(2)%i_len*il_rho(jp_J)-il_yextra
+            
+         ENDIF
+
+         IF( tl_mix%t_dim(3)%l_use .AND. ll_even(3) )THEN
+
+            il_rho(jp_K)=il_rho(jp_K)+1
+
+            ! locate wrong point on mixed grid
+            ll_mask(:,:,1:tl_mix%t_dim(3)%i_len:il_rho(jp_K),:)=.FALSE.
+
+            ! compute coasre grid dimension length
+            il_zextra=il_rho(jp_K)-1
+            td_mix%t_dim(3)%i_len=(tl_mix%t_dim(3)%i_len+il_zextra)/il_rho(jp_K)
+
+            il_rho(jp_K)=il_rho(jp_K)-1
+            ! compute right fine grid dimension length
+            td_mix%t_dim(3)%i_len=td_mix%t_dim(3)%i_len*il_rho(jp_K)-il_zextra
+
+         ENDIF      
+
+         IF( ASSOCIATED(td_mix%d_value) ) DEALLOCATE( td_mix%d_value )
+         ALLOCATE( td_mix%d_value( td_mix%t_dim(1)%i_len, &
+         &                         td_mix%t_dim(2)%i_len, &
+         &                         td_mix%t_dim(3)%i_len, &
+         &                         td_mix%t_dim(4)%i_len) )
+
+         ! initialise to FillValue
+         td_mix%d_value(:,:,:,:)=td_mix%d_fill
+
+         IF( COUNT(ll_mask(:,:,:,:)) /= SIZE(td_mix%d_value(:,:,:,:)) )THEN
+
+            CALL logger_error("INTERP CLEAN EVEN GRID: output value size "//&
+            &  " and mask count differ ")
+
+         ELSE
+
+            ALLOCATE( dl_vect(COUNT(ll_mask(:,:,:,:))) )
+
+            dl_vect(:)= PACK( tl_mix%d_value(:,:,:,:), &
+            &                 MASK=ll_mask(:,:,:,:)     )
+
+            td_mix%d_value(:,:,:,:)=RESHAPE( dl_vect(:), &
+            &                                SHAPE=td_mix%t_dim(:)%i_len )
+
+            DEALLOCATE( dl_vect )
+
+         ENDIF
+
+         DEALLOCATE( ll_mask )
+
+      ENDIF
+
+      CALL var_clean(tl_mix)
+
+   END SUBROUTINE interp__clean_even_grid
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine save interpolated value over domain. 
+   !> And so remove points added on mixed grid 
+   !> to compute interpolation
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var : table of mixed grid variable (to interpolate)
+   !> @param[in] id_rho : table of refinement factor
+   !> @return 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp_clean_mixed_grid( td_mix, td_var, &
+   &                                   id_rho, &
+   &                                   id_offset )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR)                 , INTENT(IN   ) :: td_mix
+      TYPE(TVAR)                 , INTENT(  OUT) :: td_var
+      INTEGER(I4), DIMENSION(:)  , INTENT(IN   ), OPTIONAL :: id_rho
+      INTEGER(I4), DIMENSION(:,:), INTENT(IN   ), OPTIONAL :: id_offset
+
+      ! local variable
+      INTEGER(i4) :: il_imin0
+      INTEGER(i4) :: il_imax0
+      INTEGER(i4) :: il_jmin0
+      INTEGER(i4) :: il_jmax0
+
+      INTEGER(i4) :: il_imin1
+      INTEGER(i4) :: il_jmin1
+      INTEGER(i4) :: il_imax1
+      INTEGER(i4) :: il_jmax1
+
+      INTEGER(i4), DIMENSION(2,2) :: il_offset
+
+      REAL(dp), DIMENSION(:,:,:,:) , ALLOCATABLE :: dl_value
+
+      TYPE(TVAR) :: tl_mix
+
+      ! loop indices
+      !----------------------------------------------------------------
+      il_offset(:,:)=0 
+      IF( PRESENT(id_offset) )THEN
+         IF( ANY( SHAPE(id_offset(:,:)) /= SHAPE(il_offset(:,:)) ) )THEN
+            CALL logger_error("INTERP CLEAN MIXED GRID: invalid dimension of"//&
+            &                 " offset table")
+         ELSE
+            il_offset(:,:)=id_offset(:,:)
+         ENDIF
+      ENDIF
+      ! copy mixed variable in temporary structure
+      tl_mix=td_mix
+
+      ! remove unusefull points over mixed grid for even refinement
+      CALL interp__clean_even_grid(tl_mix, id_rho(:))
+
+      ! copy cleaned mixed variable
+      td_var=tl_mix
+      IF( ALL(td_var%t_dim(1:2)%l_use) )THEN
+
+         ! delete table of value
+         CALL var_del_value(td_var)
+
+         ! compute domain indices
+         il_imin0=1  ; il_imax0=td_var%t_dim(1)%i_len
+         il_jmin0=1  ; il_jmax0=td_var%t_dim(2)%i_len
+   
+         il_imin1=il_imin0+il_offset(1,1)
+         il_jmin1=il_jmin0+il_offset(2,1)
+   
+         il_imax1=il_imax0-il_offset(1,2)
+         il_jmax1=il_jmax0-il_offset(2,2)
+
+         SELECT CASE(TRIM(td_var%c_point))
+         CASE('U')
+            il_imin1=il_imin0+(il_offset(1,1)-1)
+            il_imax1=il_imax0-(il_offset(1,2)+1)
+         CASE('V')
+            il_jmin1=il_jmin0+(il_offset(2,1)-1)
+            il_jmax1=il_jmax0-(il_offset(2,2)+1)
+         CASE('F')
+            il_imin1=il_imin0+(il_offset(1,1)-1)
+            il_imax1=il_imax0-(il_offset(1,2)+1)
+
+            il_jmin1=il_jmin0+(il_offset(2,1)-1)
+            il_jmax1=il_jmax0-(il_offset(2,2)+1)
+         END SELECT
+
+         ! compute new dimension
+         td_var%t_dim(1)%i_len=il_imax1-il_imin1+1
+         td_var%t_dim(2)%i_len=il_jmax1-il_jmin1+1
+ 
+         ALLOCATE(dl_value(td_var%t_dim(1)%i_len, &
+         &                 td_var%t_dim(2)%i_len, &
+         &                 td_var%t_dim(3)%i_len, &
+         &                 td_var%t_dim(4)%i_len) )
+
+         dl_value( 1:td_var%t_dim(1)%i_len, &
+         &         :,:,:) = tl_mix%d_value( il_imin1:il_imax1, &
+         &                                  il_jmin1:il_jmax1, &
+         &                                      :, : )
+
+         ! add variable value
+         CALL var_add_value(td_var,dl_value(:,:,:,:))
+
+         ! save variable type
+         td_var%i_type=tl_mix%i_type
+
+         DEALLOCATE(dl_value)
+
+      ENDIF
+      
+      CALL var_clean(tl_mix)
+
+   END SUBROUTINE interp_clean_mixed_grid
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine save interpolated value over domain. 
+   !> And so remove points added on mixed grid 
+   !> to compute interpolation
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var : table of mixed grid variable (to interpolate)
+   !> @param[in] id_offset : table of offset
+   !> @return 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp__del_offset( td_var, id_offset )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR)                 , INTENT(INOUT) :: td_var
+      INTEGER(i4), DIMENSION(:,:), INTENT(IN   ) :: id_offset
+
+      ! local variable
+      INTEGER(i4) :: il_imin1
+      INTEGER(i4) :: il_jmin1
+      INTEGER(i4) :: il_imax1
+      INTEGER(i4) :: il_jmax1
+
+      REAL(dp), DIMENSION(:,:,:,:) , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+   
+      IF( ALL(td_var%t_dim(1:2)%l_use) )THEN
+
+         il_imin1=1+id_offset(1,1)
+         il_jmin1=1+id_offset(2,1)
+
+         il_imax1=td_var%t_dim(1)%i_len-id_offset(2,1)
+         il_jmax1=td_var%t_dim(2)%i_len-id_offset(2,2)
+
+         ! compute new dimension
+         td_var%t_dim(1)%i_len=il_imax1-il_imin1+1
+         td_var%t_dim(2)%i_len=il_jmax1-il_jmin1+1
+         ALLOCATE( dl_value( td_var%t_dim(1)%i_len, &
+         &                   td_var%t_dim(2)%i_len, &
+         &                   td_var%t_dim(3)%i_len, &
+         &                   td_var%t_dim(4)%i_len) )
+
+         dl_value(:,:,:,:)=td_var%d_value( il_imin1:il_imax1, &
+         &                                 il_jmin1:il_jmax1, &
+         &                                 :,: )
+
+         ! delete table of value
+         CALL var_del_value(td_var)
+
+         ! add variable value
+         CALL var_add_value(td_var,dl_value(:,:,:,:))
+
+         DEALLOCATE(dl_value)
+
+      ENDIF
+
+   END SUBROUTINE interp__del_offset
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine interpolate detected point.
+   !> 
+   !> @details 
+   !> Actually it checks, the number of dimension used for this variable
+   !> and launch interp__fill_value.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var : variable to be interpolated
+   !> @param[in] id_rho : table of refinement factor
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp__fill_value_wrapper( td_var, & 
+   &                                      id_rho, &
+   &                                      id_offset )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) ,                 INTENT(INOUT) :: td_var
+      INTEGER(I4), DIMENSION(:),   INTENT(IN   ), OPTIONAL :: id_rho
+      INTEGER(I4), DIMENSION(:,:), INTENT(IN   ), OPTIONAL :: id_offset
+
+      ! local variable
+      CHARACTER(LEN=lc)                 :: cl_method
+      INTEGER(i4)      , DIMENSION(:), ALLOCATABLE  :: il_rho
+      INTEGER(i4)      , DIMENSION(2,2) :: il_offset
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      SELECT CASE(TRIM(td_var%c_interp(1)))
+         CASE('cubic','linear','nearest')
+            cl_method=TRIM(td_var%c_interp(1))
+         CASE DEFAULT
+            CALL logger_warn("INTERP FILL: interpolation method unknown."//&
+            &  " use linear interpolation")
+            cl_method='linear'
+
+            ! update variable structure value
+            td_var%c_interp(1)='linear'
+      END SELECT
+
+      ALLOCATE( il_rho(ip_maxdim) )
+      il_rho(:)=1
+      IF( PRESENT(id_rho) ) il_rho(:)=id_rho(:)
+      IF( ANY(il_rho(:) < 0) )THEN
+         CALL logger_error("INTERP FILL VALUE: invalid "//&
+         &  " refinement factor ")
+      ENDIF
+
+      il_offset(:,:)=0
+      IF( PRESENT(id_offset) )THEN
+         IF( ANY(SHAPE(id_offset(:,:)) /= (/2,2/)) )THEN
+            CALL logger_error("INTERP FILL VALUE: invalid table of offset")
+         ELSE
+            il_offset(:,:)=id_offset(:,:)
+         ENDIF
+      ENDIF
+
+      IF( (il_rho(jp_I) /= 1 .AND. td_var%t_dim(1)%l_use) .OR. &
+      &   (il_rho(jp_J) /= 1 .AND. td_var%t_dim(2)%l_use) .OR. &
+      &   (il_rho(jp_K) /= 1 .AND. td_var%t_dim(3)%l_use) )THEN
+
+         CALL logger_info("INTERP FILL: interpolate "//TRIM(td_var%c_name)//&
+         &             " using "//TRIM(cl_method)//" method." )
+         CALL logger_info("INTERP FILL: refinement factor "//&
+         &                        TRIM(fct_str(il_rho(jp_I)))//&
+         &                   " "//TRIM(fct_str(il_rho(jp_J)))//&
+         &                   " "//TRIM(fct_str(il_rho(jp_K))) )
+ 
+         CALL interp__fill_value( td_var, cl_method, & 
+         &                        il_rho(:), &
+         &                        il_offset(:,:) )
+
+         SELECT CASE(TRIM(td_var%c_interp(2)))
+         CASE('/rhoi')
+            WHERE( td_var%d_value(:,:,:,:) /= td_var%d_fill )
+               td_var%d_value(:,:,:,:) = &
+               &  td_var%d_value(:,:,:,:) / REAL(il_rho(jp_I),dp)
+            END WHERE
+         CASE('/rhoj')
+            WHERE( td_var%d_value(:,:,:,:) /= td_var%d_fill )
+               td_var%d_value(:,:,:,:) = &
+               &  td_var%d_value(:,:,:,:) / REAL(il_rho(jp_J),dp)
+            END WHERE
+         CASE('/rhok')
+            WHERE( td_var%d_value(:,:,:,:) /= td_var%d_fill )
+               td_var%d_value(:,:,:,:) = &
+               &  td_var%d_value(:,:,:,:) / REAL(il_rho(jp_K),dp)
+            END WHERE
+         CASE('*rhoi')
+            WHERE( td_var%d_value(:,:,:,:) /= td_var%d_fill )
+               td_var%d_value(:,:,:,:) = &
+               &  td_var%d_value(:,:,:,:) * REAL(il_rho(jp_I),dp)
+            END WHERE
+         CASE('*rhoj')
+            WHERE( td_var%d_value(:,:,:,:) /= td_var%d_fill ) 
+               td_var%d_value(:,:,:,:) = &
+               &  td_var%d_value(:,:,:,:) * REAL(il_rho(jp_J),dp)
+            END WHERE
+         CASE('*rhok')
+            WHERE( td_var%d_value(:,:,:,:) /= td_var%d_fill ) 
+               td_var%d_value(:,:,:,:) = &
+               &  td_var%d_value(:,:,:,:) * REAL(il_rho(jp_K),dp)
+            END WHERE
+         CASE DEFAULT
+            td_var%c_interp(2)=''
+         END SELECT
+
+      ENDIF
+
+   END SUBROUTINE interp__fill_value_wrapper
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine interpolate value over mixed grid.
+   !> 
+   !> @details 
+   !> 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable
+   !> @param[in] cd_method : interpolation method 
+   !> @param[in] id_rho : table of refinment factor 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp__fill_value( td_var, cd_method, &
+   &                              id_rho, &
+   &                              id_offset )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR)                      , INTENT(INOUT) :: td_var 
+      CHARACTER(LEN=*)                , INTENT(IN   ) :: cd_method
+      INTEGER(I4)     , DIMENSION(:)  , INTENT(IN   ) :: id_rho
+      INTEGER(I4)     , DIMENSION(:,:), INTENT(IN   ) :: id_offset
+
+      ! local variable
+      CHARACTER(LEN=lc)                                :: cl_interp
+
+      INTEGER(I4)    , DIMENSION(:)      , ALLOCATABLE :: il_rho
+      INTEGER(i4)    , DIMENSION(:,:,:)  , ALLOCATABLE :: il_detect
+ 
+      REAL(dp)                                         :: dl_min
+      REAL(dp)                                         :: dl_max
+
+      LOGICAL        , DIMENSION(3)                    :: ll_even
+      LOGICAL                                          :: ll_discont
+ 
+      TYPE(TVAR)                                       :: tl_mix
+
+      TYPE(TATT)                                       :: tl_att
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jk
+      INTEGER(i4) :: jl
+      !----------------------------------------------------------------
+
+      !1- create mixed grid
+      CALL interp_create_mixed_grid( td_var, tl_mix, id_rho(:) )
+
+      ! clean variable structure
+      CALL var_clean(td_var)
+
+      !2- detect point to be interpolated
+      ALLOCATE( il_detect( tl_mix%t_dim(1)%i_len, &
+      &                    tl_mix%t_dim(2)%i_len, &
+      &                    tl_mix%t_dim(3)%i_len) )
+
+      il_detect(:,:,:)=0
+
+      il_detect(:,:,:)=interp_detect(tl_mix, id_rho(:) )
+
+      ! add attribute to variable
+      cl_interp=fct_concat(tl_mix%c_interp(:))
+      tl_att=att_init('interpolation',cl_interp)
+      CALL var_move_att(tl_mix, tl_att)
+
+      ! special case for even refinement on ARAKAWA-C grid
+      ll_even(:)=.FALSE.
+      IF( MOD(id_rho(jp_I),2) == 0 ) ll_even(1)=.TRUE.
+      IF( MOD(id_rho(jp_J),2) == 0 ) ll_even(2)=.TRUE.
+      IF( MOD(id_rho(jp_K),2) == 0 ) ll_even(3)=.TRUE.         
+
+      SELECT CASE(TRIM(tl_mix%c_point))
+         CASE('U')
+            ll_even(1)=.FALSE.
+         CASE('V')
+            ll_even(2)=.FALSE.
+         CASE('F')
+            ll_even(:)=.FALSE.
+      END SELECT
+
+      ALLOCATE(il_rho(ip_maxdim))
+      il_rho(:)=id_rho(:)
+
+      IF( ll_even(1) ) il_rho(jp_I)=id_rho(jp_I)+1
+      IF( ll_even(2) ) il_rho(jp_J)=id_rho(jp_J)+1
+      IF( ll_even(3) ) il_rho(jp_K)=id_rho(jp_K)+1
+
+      ! special case for longitude
+      ll_discont=.FALSE.
+      IF( TRIM(tl_mix%c_units) == 'degrees_east' )THEN
+         dl_min=MINVAL( tl_mix%d_value(:,:,:,:), &
+         &              tl_mix%d_value(:,:,:,:)/=tl_mix%d_fill)
+         dl_max=MAXVAL( tl_mix%d_value(:,:,:,:), &
+         &              tl_mix%d_value(:,:,:,:)/=tl_mix%d_fill)         
+         IF( dl_min < -170_dp .AND. dl_max > 170_dp .OR. &
+         &   dl_min <   10_dp .AND. dl_max > 350_dp )THEN
+            ll_discont=.TRUE.
+         ENDIF
+      ENDIF
+
+      !3- interpolate
+      DO jl=1,tl_mix%t_dim(4)%i_len
+         IF( il_rho(jp_K) /= 1 )THEN
+!            CALL interp__3D(tl_mix%d_value(:,:,:,jl), tl_mix%d_fill, &
+!              &             il_detect(:,:,:), cd_method,             &
+!              &             il_rhoi, il_rhoj, il_rhok,               &
+!              &             ll_even(:), ll_discont )
+             CALL logger_error("INTERP FILL: can not interpolate "//&
+             &                "vertically for now ")
+         ENDIF
+
+         IF( ANY(il_detect(:,:,:)==1) )THEN
+            ! I-J plan
+            DO jk=1,tl_mix%t_dim(3)%i_len
+              CALL interp__2D(tl_mix%d_value(:,:,jk,jl), tl_mix%d_fill, &
+              &               il_detect(:,:,jk), cd_method,             &
+              &               il_rho(jp_I), il_rho(jp_J),               &
+              &               ll_even(1:2), ll_discont)
+            ENDDO
+            IF( ALL(il_detect(:,:,:)==0) ) CYCLE
+            IF( il_rho(jp_K) /= 1 )THEN
+               ! I-K plan
+               DO jj=1,tl_mix%t_dim(2)%i_len
+                  CALL interp__2D(tl_mix%d_value(:,jj,:,jl), tl_mix%d_fill, &
+                  &               il_detect(:,jj,:), cd_method,             &
+                  &               il_rho(jp_J), il_rho(jp_K),               &
+                  &               ll_even(1:3:2), ll_discont  )
+               ENDDO
+               IF( ALL(il_detect(:,:,:)==0) ) CYCLE
+               ! J-K plan
+               DO ji=1,tl_mix%t_dim(1)%i_len
+                  CALL interp__2D(tl_mix%d_value(ji,:,:,jl), tl_mix%d_fill, &
+                  &               il_detect(ji,:,:), cd_method,             &
+                  &               il_rho(jp_J), il_rho(jp_K),               &
+                  &               ll_even(2:3), ll_discont )
+               ENDDO
+
+            ENDIF
+            IF( ANY(il_detect(:,:,:)==1) )THEN
+               ! I direction
+               DO jk=1,tl_mix%t_dim(3)%i_len
+                  DO jj=1,tl_mix%t_dim(2)%i_len
+                     CALL interp__1D( tl_mix%d_value(:,jj,jk,jl),    &
+                     &                tl_mix%d_fill,                 &
+                     &                il_detect(:,jj,jk), cd_method, &
+                     &                il_rho(jp_I),                  &
+                     &                ll_even(1), ll_discont )
+                  ENDDO
+               ENDDO
+               IF( ALL(il_detect(:,:,:)==0) ) CYCLE
+               ! J direction
+               DO jk=1,tl_mix%t_dim(3)%i_len
+                  DO ji=1,tl_mix%t_dim(1)%i_len
+                     CALL interp__1D( tl_mix%d_value(ji,:,jk,jl),    &
+                     &                tl_mix%d_fill,                 &
+                     &                il_detect(ji,:,jk), cd_method, &
+                     &                il_rho(jp_J),                  &
+                     &                ll_even(2), ll_discont )
+                  ENDDO
+               ENDDO
+               IF( il_rho(jp_K) /= 1 )THEN
+                  IF( ALL(il_detect(:,:,:)==0) ) CYCLE
+                  ! K direction
+                  DO jj=1,tl_mix%t_dim(2)%i_len
+                     DO ji=1,tl_mix%t_dim(1)%i_len
+                        CALL interp__1D( tl_mix%d_value(ji,jj,:,jl),    &
+                        &                tl_mix%d_fill,                 & 
+                        &                il_detect(ji,jj,:), cd_method, &
+                        &                il_rho(jp_K),                  &
+                        &                ll_even(3), ll_discont  )
+                     ENDDO
+                  ENDDO
+               ENDIF
+            ENDIF
+         ENDIF
+      ENDDO
+
+      IF( ANY(il_detect(:,:,:)==1) )THEN
+         CALL logger_warn("INTERP FILL: some points can not be interpolated "//&
+         &             "for variable "//TRIM(tl_mix%c_name) )
+      ENDIF
+
+      DEALLOCATE(il_detect)
+      !4- save useful domain (remove offset)
+      CALL interp_clean_mixed_grid( tl_mix, td_var, &
+      &                             id_rho(:),      &
+      &                             id_offset(:,:) )      
+
+      ! clean variable structure
+      CALL var_clean(tl_mix)
+
+   END SUBROUTINE interp__fill_value
+   !> @endcode
+!   !-------------------------------------------------------------------
+!   !> @brief
+!   !> This subroutine 
+!   !> 
+!   !> @details 
+!   !>
+!   !> @author J.Paul
+!   !> - Nov, 2013- Initial Version
+!   !
+!   !> @param[in]
+!   !> @param[out] 
+!   !-------------------------------------------------------------------
+!   !> @code
+!   SUBROUTINE interp__3D( dd_value,  dd_fill,   &
+!      &                   id_detect, cd_method, &
+!      &                   id_rhoi, id_rhoj, id_rhok, &
+!      &                   ld_even,  ld_discont )
+!      IMPLICIT NONE
+!      ! Argument
+!      REAL(dp)        , DIMENSION(:,:,:), INTENT(INOUT) :: dd_value 
+!      REAL(dp)                          , INTENT(IN   ) :: dd_fill 
+!      INTEGER(I4)     , DIMENSION(:,:,:), INTENT(INOUT) :: id_detect
+!      CHARACTER(LEN=*)                  , INTENT(IN   ) :: cd_method
+!      INTEGER(I4)                       , INTENT(IN   ) :: id_rhoi
+!      INTEGER(I4)                       , INTENT(IN   ) :: id_rhoj
+!      INTEGER(I4)                       , INTENT(IN   ) :: id_rhok
+!      LOGICAL         , DIMENSION(:)    , INTENT(IN   ) :: ld_even
+!      LOGICAL                           , INTENT(IN   ), OPTIONAL :: ld_discont
+!
+!      ! local variable
+!      INTEGER(i4), DIMENSION(3)                  :: il_shape
+!      INTEGER(i4), DIMENSION(3)                  :: il_dim
+!
+!      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_coarse
+!      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_dfdx
+!      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_dfdy
+!      REAL(dp)   , DIMENSION(:,:,:), ALLOCATABLE :: dl_d2fdxy
+!
+!      LOGICAL                                    :: ll_discont
+!
+!      ! loop indices
+!!      INTEGER(i4) :: ji
+!!      INTEGER(i4) :: jj
+!!      INTEGER(i4) :: ii
+!!      INTEGER(i4) :: ij
+!      !----------------------------------------------------------------
+!      ll_discont=.FALSE.
+!      IF( PRESENT(ld_discont) ) ll_discont=ld_discont
+!
+!      il_shape(:)=SHAPE(dd_value)
+!      il_dim(:)=(il_shape(:)-1)/2
+!
+!      ALLOCATE( dl_coarse(il_dim(1),il_dim(2),il_dim(3)) )
+!      ! value on coarse grid
+!      dl_coarse(:,:,:)=dd_value( 1:il_shape(1):id_rhoi, &
+!      &                        1:il_shape(2):id_rhoj, &
+!      &                        1:il_shape(3):id_rhok )
+!      SELECT CASE(TRIM(cd_method))
+!
+!         CASE('cubic')
+!            
+!            ALLOCATE( dl_dfdx(  il_dim(1),il_dim(2),il_dim(3)), &
+!            &         dl_dfdy(  il_dim(1),il_dim(2),il_dim(3)), &
+!            &         dl_d2fdxy(il_dim(1),il_dim(2),il_dim(3)) )
+!
+!!            ! compute derivative on coarse grid
+!!            dl_dfdx(:,:)=extrap_deriv_2D(dl_coarse(:,:,:), dd_fill, 'I')
+!!            dl_dfdy(:,:)=extrap_deriv_2D(dl_coarse(:,:,:), dd_fill, 'J')
+!!
+!!            ! compute cross derivative on coarse grid
+!!            dl_d2fdxy(:,:)=extrap_deriv_2D(dl_dfdx(:,:,:), dd_fill, 'J')
+!!
+!!            DO jj=1,il_shape(2)-1,id_rhoj
+!!               ij=((jj-1)/id_rhoj)+1
+!!               DO ji=1,il_shape(1)-1,id_rhoi
+!!                  ii=((ji-1)/id_rhoi)+1
+!!            
+!!                  IF( ANY(dl_coarse(ii:ii+1,ij:ij+1)==dd_fill ) ) CYCLE
+!!                  ! compute bicubic coefficient
+!!                  dl_coef(:)=interp__2D_cubic_coef(dl_coarse(ii:ii+1,ij:ij+1),&
+!!                  &                                dl_dfdx(  ii:ii+1,ij:ij+1),&
+!!                  &                                dl_dfdy(  ii:ii+1,ij:ij+1),&
+!!                  &                                dl_d2fdxy(ii:ii+1,ij:ij+1) )
+!!
+!!                  ! compute value on detetected point
+!!                  CALL interp__2D_cubic_fill(dl_coef(:), &
+!!                  &                          dd_value( ji:ji+id_rhoi,   &
+!!                  &                                    jj:jj+id_rhoj ), &
+!!                  &                          id_detect(ji:ji+id_rhoi,   &
+!!                  &                                    jj:jj+id_rhoj )  )
+!!
+!!               ENDDO
+!!            ENDDO
+!
+!            DEALLOCATE( dl_dfdx, &
+!            &           dl_dfdy, &
+!            &           dl_d2fdxy )
+!
+!         CASE('nearest')
+!
+!         CASE DEFAULT ! linear 
+!
+!!            DO jj=1,il_shape(2)-1,id_rhoj
+!!               ij=((jj-1)/id_rhoj)+1
+!!               DO ji=1,il_shape(1)-1,id_rhoi
+!!                  ii=((ji-1)/id_rhoi)+1            
+!!
+!!                  IF( ANY(dl_coarse(ii:ii+1,ij:ij+1)==dd_fill ) ) CYCLE
+!!                  ! compute bilinear coefficient
+!!                  dl_coef(:)=interp__2D_linear_coef(dl_coarse(ii:ii+1,ij:ij+1))
+!!
+!!                  ! compute value on detetected point
+!!                  CALL interp__2D_linear_fill(dl_coef(:), &
+!!                  &                          dd_value( ji:ji+id_rhoi,   &
+!!                  &                                    jj:jj+id_rhoj ), &
+!!                  &                          id_detect(ji:ji+id_rhoi,   &
+!!                  &                                    jj:jj+id_rhoj )  )
+!!
+!!               ENDDO
+!!            ENDDO
+!
+!      END SELECT
+!
+!      DEALLOCATE( dl_coarse )
+!
+!   END SUBROUTINE interp__3D
+!   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in]
+   !> @param[out] 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp__2D( dd_value,  dd_fill,   &
+      &                   id_detect, cd_method, &
+      &                   id_rhoi, id_rhoj,     &
+      &                   ld_even,  ld_discont )
+
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)        , DIMENSION(:,:), INTENT(INOUT) :: dd_value 
+      REAL(dp)                        , INTENT(IN   ) :: dd_fill 
+      INTEGER(I4)     , DIMENSION(:,:), INTENT(INOUT) :: id_detect
+      CHARACTER(LEN=*)                , INTENT(IN   ) :: cd_method
+      INTEGER(I4)                     , INTENT(IN   ) :: id_rhoi
+      INTEGER(I4)                     , INTENT(IN   ) :: id_rhoj
+      LOGICAL         , DIMENSION(:)  , INTENT(IN   ) :: ld_even
+      LOGICAL                         , INTENT(IN   ), OPTIONAL :: ld_discont
+
+      ! local variable
+      INTEGER(I4)                              :: il_xextra
+      INTEGER(I4)                              :: il_yextra
+      INTEGER(i4), DIMENSION(2)                :: il_shape
+      INTEGER(i4), DIMENSION(2)                :: il_dim
+
+      REAL(dp)                                 :: dl_min 
+      REAL(dp)                                 :: dl_max 
+      REAL(dp)   , DIMENSION(:)  , ALLOCATABLE :: dl_coef
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_coarse
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_tmp
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_dfdx
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_dfdy
+      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_d2fdxy
+
+      LOGICAL                                  :: ll_discont
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: ii
+      INTEGER(i4) :: ij
+
+      !----------------------------------------------------------------
+      ll_discont=.FALSE.
+      IF( PRESENT(ld_discont) ) ll_discont=ld_discont
+
+      CALL logger_debug("INTERP 2D: interpolation method "//TRIM(cd_method)//&
+      &  " discont "//TRIM(fct_str(ll_discont)) )
+
+      il_shape(:)=SHAPE(dd_value)
+
+      ! compute coarse grid dimension
+      il_xextra=id_rhoi-1
+      il_dim(1)=(il_shape(1)+il_xextra)/id_rhoi
+
+      il_yextra=id_rhoj-1
+      il_dim(2)=(il_shape(2)+il_yextra)/id_rhoj
+
+      ALLOCATE( dl_coarse(il_dim(1),il_dim(2)) )
+
+      ! value on coarse grid
+      dl_coarse(:,:)=dd_value( 1:il_shape(1):id_rhoi, &
+      &                        1:il_shape(2):id_rhoj )
+
+      SELECT CASE(TRIM(cd_method))
+
+         CASE('cubic')
+            
+            ALLOCATE( dl_dfdx(  il_dim(1),il_dim(2)), &
+            &         dl_dfdy(  il_dim(1),il_dim(2)), &
+            &         dl_d2fdxy(il_dim(1),il_dim(2)) )
+
+            ! compute derivative on coarse grid
+            dl_dfdx(:,:)=extrap_deriv_2D(dl_coarse(:,:), dd_fill, 'I', ll_discont)
+            dl_dfdy(:,:)=extrap_deriv_2D(dl_coarse(:,:), dd_fill, 'J', ll_discont)
+
+            ! compute cross derivative on coarse grid
+            dl_d2fdxy(:,:)=extrap_deriv_2D(dl_dfdx(:,:), dd_fill, 'J', ll_discont)
+
+            ALLOCATE( dl_tmp(2,2) )
+            ALLOCATE( dl_coef(16) )
+
+            DO jj=1,il_shape(2)-1,id_rhoj
+               ij=((jj-1)/id_rhoj)+1
+               DO ji=1,il_shape(1)-1,id_rhoi
+                  ii=((ji-1)/id_rhoi)+1
+            
+                  IF( ANY(dl_coarse(ii:ii+1,ij:ij+1)==dd_fill) .OR. &
+                  &   ANY(  dl_dfdx(ii:ii+1,ij:ij+1)==dd_fill) .OR. &
+                  &   ANY(  dl_dfdy(ii:ii+1,ij:ij+1)==dd_fill) .OR. &
+                  &   ANY(dl_d2fdxy(ii:ii+1,ij:ij+1)==dd_fill) ) CYCLE
+
+                  dl_tmp(:,:)=dl_coarse(ii:ii+1,ij:ij+1)
+                  IF( ll_discont )THEN
+
+                     dl_min=MINVAL( dl_tmp(:,:), dl_tmp(:,:)/=dd_fill )
+                     dl_max=MAXVAL( dl_tmp(:,:), dl_tmp(:,:)/=dd_fill )
+                     IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN
+                        WHERE( dl_tmp(:,:) < 0_dp ) 
+                           dl_tmp(:,:) = dl_tmp(:,:)+360._dp
+                        END WHERE
+                     ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN
+                        WHERE( dl_tmp(:,:) > 180_dp ) 
+                           dl_tmp(:,:) = dl_tmp(:,:)-180._dp
+                        END WHERE
+                     ENDIF
+                  ENDIF
+
+                  ! compute bicubic coefficient
+                  dl_coef(:)=interp__2D_cubic_coef(dl_tmp(:,:),&
+                  &                                dl_dfdx(   ii:ii+1,ij:ij+1),&
+                  &                                dl_dfdy(   ii:ii+1,ij:ij+1),&
+                  &                                dl_d2fdxy( ii:ii+1,ij:ij+1),&
+                  &                                dd_fill )
+
+                  ! compute value on detetected point
+                  CALL interp__2D_cubic_fill(dd_value( ji:ji+id_rhoi,   &
+                  &                                    jj:jj+id_rhoj ), &
+                  &                          id_detect(ji:ji+id_rhoi,   &
+                  &                                    jj:jj+id_rhoj ), &
+                  &                          dl_coef(:), dd_fill,       &
+                  &                          ld_even(:), id_rhoi, id_rhoj )
+
+                  IF( ll_discont )THEN
+                     WHERE( dd_value( ji:ji+id_rhoi, &
+                        &             jj:jj+id_rhoj ) >= 180._dp .AND. &
+                        &   dd_value( ji:ji+id_rhoi, &
+                        &             jj:jj+id_rhoj ) /= dd_fill )
+                        dd_value( ji:ji+id_rhoi, &
+                        &         jj:jj+id_rhoj ) = &
+                        &           dd_value( ji:ji+id_rhoi, &
+                        &                     jj:jj+id_rhoj ) - 360._dp
+                     END WHERE
+                  ENDIF
+
+               ENDDO
+            ENDDO
+
+            DEALLOCATE(dl_coef)
+            DEALLOCATE(dl_tmp )
+
+            DEALLOCATE(dl_dfdx, &
+            &          dl_dfdy, &
+            &          dl_d2fdxy )
+
+         CASE('nearest') 
+
+            DO jj=1,il_shape(2)-1,id_rhoj
+               ij=((jj-1)/id_rhoj)+1
+               DO ji=1,il_shape(1)-1,id_rhoi
+                  ii=((ji-1)/id_rhoi)+1            
+
+                  ! compute value on detetected point
+                  CALL interp__2D_nearest_fill(dd_value( ji:ji+id_rhoi,   &
+                  &                                      jj:jj+id_rhoj ), &
+                  &                            id_detect(ji:ji+id_rhoi,   &
+                  &                                      jj:jj+id_rhoj )  )
+
+               ENDDO
+            ENDDO
+
+         CASE DEFAULT ! linear 
+
+            ALLOCATE( dl_coef(4)  )
+            ALLOCATE( dl_tmp(2,2) )
+
+            DO jj=1,il_shape(2)-1,id_rhoj
+               ij=((jj-1)/id_rhoj)+1
+               DO ji=1,il_shape(1)-1,id_rhoi
+                  ii=((ji-1)/id_rhoi)+1            
+
+                  IF( ANY(dl_coarse(ii:ii+1,ij:ij+1)==dd_fill ) ) CYCLE
+
+                  dl_tmp(:,:)=dl_coarse(ii:ii+1,ij:ij+1)
+                  IF( ll_discont )THEN
+
+                     dl_min=MINVAL( dl_tmp(:,:), dl_tmp(:,:)/=dd_fill )
+                     dl_max=MAXVAL( dl_tmp(:,:), dl_tmp(:,:)/=dd_fill )
+                     IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN
+                        WHERE( dl_tmp(:,:) < 0_dp ) 
+                           dl_tmp(:,:) = dl_tmp(:,:)+360._dp
+                        END WHERE
+                     ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN
+                        WHERE( dl_tmp(:,:) > 180_dp ) 
+                           dl_tmp(:,:) = dl_tmp(:,:)-180._dp
+                        END WHERE
+                     ENDIF
+                  ENDIF
+
+                  ! compute bilinear coefficient
+                  dl_coef(:)=interp__2D_linear_coef(dl_tmp(:,:), dd_fill)
+
+                  ! compute value on detetected point
+                  CALL interp__2D_linear_fill(dd_value( ji:ji+id_rhoi,   &
+                  &                                     jj:jj+id_rhoj ), &
+                  &                           id_detect(ji:ji+id_rhoi,   &
+                  &                                     jj:jj+id_rhoj ), &
+                  &                           dl_coef(:), dd_fill,       &
+                  &                           ld_even(:), id_rhoi, id_rhoj )
+
+                  IF( ll_discont )THEN
+                     WHERE( dd_value( ji:ji+id_rhoi, &
+                        &             jj:jj+id_rhoj ) >= 180._dp .AND. &
+                        &   dd_value( ji:ji+id_rhoi, &
+                        &             jj:jj+id_rhoj ) /= dd_fill )
+                        dd_value( ji:ji+id_rhoi, &
+                        &         jj:jj+id_rhoj ) = &
+                        &           dd_value( ji:ji+id_rhoi, &
+                        &                     jj:jj+id_rhoj ) - 360._dp
+                     END WHERE
+                  ENDIF
+
+               ENDDO
+            ENDDO
+
+            DEALLOCATE(dl_coef)
+            DEALLOCATE(dl_tmp )
+
+      END SELECT
+
+      DEALLOCATE( dl_coarse )
+
+   END SUBROUTINE interp__2D
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in]
+   !> @param[out] 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp__1D( dd_value,  dd_fill,   &
+      &                   id_detect, cd_method, &
+      &                   id_rhoi,              &
+      &                   ld_even, ld_discont )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)        , DIMENSION(:), INTENT(INOUT) :: dd_value 
+      REAL(dp)                      , INTENT(IN   ) :: dd_fill 
+      INTEGER(I4)     , DIMENSION(:), INTENT(INOUT) :: id_detect
+      CHARACTER(LEN=*)              , INTENT(IN   ) :: cd_method
+      INTEGER(I4)                   , INTENT(IN   ) :: id_rhoi
+      LOGICAL                       , INTENT(IN   ) :: ld_even
+      LOGICAL                       , INTENT(IN   ), OPTIONAL :: ld_discont
+
+      ! local variable
+      INTEGER(i4), DIMENSION(1)              :: il_shape
+      INTEGER(i4), DIMENSION(1)              :: il_dim
+      INTEGER(I4)                            :: il_xextra
+
+      REAL(dp)                               :: dl_min 
+      REAL(dp)                               :: dl_max 
+      REAL(dp)   , DIMENSION(:), ALLOCATABLE :: dl_coarse
+      REAL(dp)   , DIMENSION(:), ALLOCATABLE :: dl_tmp
+      REAL(dp)   , DIMENSION(:), ALLOCATABLE :: dl_dfdx
+
+      REAL(dp)   , DIMENSION(:), ALLOCATABLE :: dl_coef
+
+      LOGICAL                                :: ll_discont
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: ii
+      !----------------------------------------------------------------
+      ll_discont=.FALSE.
+      IF( PRESENT(ld_discont) ) ll_discont=ld_discont
+
+      CALL logger_debug("INTERP 1D: interpolation method "//TRIM(cd_method)//&
+      &  " discont "//TRIM(fct_str(ll_discont)) )
+
+      il_shape(:)=SHAPE(dd_value)
+
+      il_xextra=id_rhoi-1
+      il_dim(1)=(il_shape(1)+il_xextra)/id_rhoi
+
+      ALLOCATE( dl_coarse(il_dim(1)) )
+      ! value on coarse grid
+      dl_coarse(:)=dd_value( 1:il_shape(1):id_rhoi )
+
+      SELECT CASE(TRIM(cd_method))
+
+         CASE('cubic')
+            
+            ALLOCATE( dl_dfdx( il_dim(1)) )
+
+            ! compute derivative on coarse grid
+            dl_dfdx(:)=extrap_deriv_1D(dl_coarse(:), dd_fill, ll_discont)
+
+            ALLOCATE( dl_coef(4))
+            ALLOCATE( dl_tmp(2) )
+
+            DO ji=1,il_shape(1)-1,id_rhoi
+               ii=((ji-1)/id_rhoi)+1
+            
+               IF( ANY( dl_tmp(:)==dd_fill ) .OR. &
+               &   ANY(dl_dfdx(:)==dd_fill ) ) CYCLE
+
+               dl_tmp(:)=dl_coarse(ii:ii+1)
+               IF( ll_discont )THEN
+
+                  dl_min=MINVAL( dl_tmp(:), dl_tmp(:)/=dd_fill )
+                  dl_max=MAXVAL( dl_tmp(:), dl_tmp(:)/=dd_fill )
+                  IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN
+                     WHERE( dl_tmp(:) < 0_dp ) 
+                        dl_tmp(:) = dl_tmp(:)+360._dp
+                     END WHERE
+                  ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN
+                     WHERE( dl_tmp(:) > 180_dp ) 
+                        dl_tmp(:) = dl_tmp(:)-180._dp
+                     END WHERE
+                  ENDIF
+               ENDIF
+
+               ! compute bicubic coefficient
+               dl_coef(:)=interp__1D_cubic_coef(dl_tmp(:),&
+               &                                dl_dfdx(   ii:ii+1), &
+               &                                dd_fill )
+
+               ! compute value on detetected point
+               CALL interp__1D_cubic_fill(dd_value( ji:ji+id_rhoi),&
+               &                          id_detect(ji:ji+id_rhoi),&
+               &                          dl_coef(:), dd_fill,     &
+               &                          ld_even, id_rhoi )
+
+               IF( ll_discont )THEN
+                  WHERE( dd_value( ji:ji+id_rhoi ) >= 180._dp .AND. &
+                     &   dd_value( ji:ji+id_rhoi ) /= dd_fill )
+                     dd_value( ji:ji+id_rhoi ) = &
+                     &           dd_value( ji:ji+id_rhoi ) - 360._dp
+                  END WHERE
+               ENDIF
+
+            ENDDO
+
+            DEALLOCATE(dl_coef)
+            DEALLOCATE(dl_tmp )
+
+         CASE('nearest') 
+
+            DO ji=1,il_shape(1)-1,id_rhoi
+               ii=((ji-1)/id_rhoi)+1            
+
+               ! compute value on detetected point
+               CALL interp__1D_nearest_fill(dd_value( ji:ji+id_rhoi), &
+               &                            id_detect(ji:ji+id_rhoi)  )
+
+            ENDDO
+
+         CASE DEFAULT ! linear 
+
+            ALLOCATE(dl_coef(2))
+            ALLOCATE( dl_tmp(2) )
+
+            DO ji=1,il_shape(1)-1,id_rhoi
+               ii=((ji-1)/id_rhoi)+1            
+
+               IF( ANY(dl_coarse(ii:ii+1)==dd_fill ) ) CYCLE
+
+               dl_tmp(:)=dl_coarse(ii:ii+1)
+               IF( ll_discont )THEN
+
+                  dl_min=MINVAL( dl_tmp(:), dl_tmp(:)/=dd_fill )
+                  dl_max=MAXVAL( dl_tmp(:), dl_tmp(:)/=dd_fill )
+                  IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN
+                     WHERE( dl_tmp(:) < 0_dp ) 
+                        dl_tmp(:) = dl_tmp(:)+360._dp
+                     END WHERE
+                  ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN
+                     WHERE( dl_tmp(:) > 180_dp ) 
+                        dl_tmp(:) = dl_tmp(:)-180._dp
+                     END WHERE
+                  ENDIF
+               ENDIF
+
+               ! compute bilinear coefficient
+               dl_coef(:)=interp__1D_linear_coef(dl_tmp(:), dd_fill)
+
+               ! compute value on detetected point
+               CALL interp__1D_linear_fill( dd_value( ji:ji+id_rhoi),&
+               &                            id_detect(ji:ji+id_rhoi),&
+               &                            dl_coef(:), dd_fill,     &
+               &                            ld_even, id_rhoi  )
+
+               IF( ll_discont )THEN
+                  WHERE( dd_value( ji:ji+id_rhoi ) >= 180._dp .AND. &
+                     &   dd_value( ji:ji+id_rhoi ) /= dd_fill )
+                     dd_value( ji:ji+id_rhoi ) = &
+                     &           dd_value( ji:ji+id_rhoi ) - 360._dp
+                  END WHERE
+               ENDIF
+
+            ENDDO
+
+            DEALLOCATE(dl_coef)
+
+      END SELECT
+
+      DEALLOCATE( dl_coarse )
+
+   END SUBROUTINE interp__1D
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in]
+   !> @param[out] 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION interp__2D_cubic_coef( dd_value, &
+      &                            dd_dfdx,  &
+      &                            dd_dfdy,  &
+      &                            dd_d2fdxy,&
+      &                            dd_fill )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_value 
+      REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_dfdx  
+      REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_dfdy  
+      REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_d2fdxy
+      REAL(dp)                , INTENT(IN) :: dd_fill
+
+      ! function
+      REAL(dp), DIMENSION(16) :: interp__2D_cubic_coef
+
+      ! local variable
+      REAL(dp), DIMENSION(16,16), PARAMETER :: dp_matrix = RESHAPE( &
+      & (/ 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,& 
+           0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,& 
+          -3 , 3 , 0 , 0 ,-2 ,-1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,& 
+           2 ,-2 , 0 , 0 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,& 
+           0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,& 
+           0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 ,& 
+           0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,-3 , 3 , 0 , 0 ,-2 ,-1 , 0 , 0 ,& 
+           0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 ,-2 , 0 , 0 , 1 , 1 , 0 , 0 ,& 
+          -3 , 0 , 3 , 0 , 0 , 0 , 0 , 0 ,-2 , 0 ,-1 , 0 , 0 , 0 , 0 , 0 ,& 
+           0 , 0 , 0 , 0 ,-3 , 0 , 3 , 0 , 0 , 0 , 0 , 0 ,-2 , 0 ,-1 , 0 ,& 
+           9 ,-9 ,-9 , 9 , 6 , 3 ,-6 ,-3 , 6 ,-6 , 3 ,-3 , 4 , 2 , 2 , 1 ,& 
+          -6 , 6 , 6 ,-6 ,-3 ,-3 , 3 , 3 ,-4 , 4 ,-2 , 2 ,-2 ,-2 ,-1 ,-1 ,& 
+           2 , 0 ,-2 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 0 , 0 , 0 ,& 
+           0 , 0 , 0 , 0 , 2 , 0 ,-2 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 ,& 
+          -6 , 6 , 6 ,-6 ,-4 ,-2 , 4 , 2 ,-3 , 3 ,-3 , 3 ,-2 ,-1 ,-2 ,-1 ,& 
+           4 ,-4 ,-4 , 4 , 2 , 2 ,-2 ,-2 , 2 ,-2 , 2 ,-2 , 1 , 1 , 1 , 1 /), &
+      & (/ 16, 16 /) )
+
+      REAL(dp), DIMENSION(16) :: dl_vect
+
+      !----------------------------------------------------------------
+      ! init
+      interp__2D_cubic_coef(:)=dd_fill
+
+      IF( ANY(SHAPE( dd_value(:,:))/= 2) .OR. &
+      &   ANY(SHAPE(  dd_dfdx(:,:))/= 2) .OR. &
+      &   ANY(SHAPE(  dd_dfdy(:,:))/= 2) .OR. &
+      &   ANY(SHAPE(dd_d2fdxy(:,:))/= 2) )THEN
+   
+         CALL logger_error("INTERP CUBIC COEF: invalid dimension of "//&
+         &              "input tables. shape should be (/2,2/)")
+
+      ELSEIF( ANY( dd_value(:,:) == dd_fill) .OR. &
+      &       ANY(  dd_dfdx(:,:) == dd_fill) .OR. &
+      &       ANY(  dd_dfdy(:,:) == dd_fill) .OR. &
+      &       ANY(dd_d2fdxy(:,:) == dd_fill) )THEN
+      
+         CALL logger_warn("INTERP CUBIC COEF: fill value detected. "//&
+         &  "can not compute coefficient ")
+
+      ELSE
+
+         dl_vect( 1: 4)=PACK(dd_value(:,:),.TRUE. )
+         dl_vect( 5: 8)=PACK(dd_dfdx(:,:),.TRUE. )
+         dl_vect( 9:12)=PACK(dd_dfdy(:,:),.TRUE. )
+         dl_vect(13:16)=PACK(dd_d2fdxy(:,:),.TRUE. )
+
+         interp__2D_cubic_coef(:)=MATMUL(TRANSPOSE(dp_matrix(:,:)),dl_vect(:))
+
+      ENDIF
+   END FUNCTION interp__2D_cubic_coef
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in]
+   !> @param[out] 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp__2D_cubic_fill( dd_value, id_detect, dd_coef, dd_fill, &
+   &                                 ld_even, id_rhoi, id_rhoj )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)        , DIMENSION(:,:), INTENT(INOUT) :: dd_value 
+      INTEGER(i4)     , DIMENSION(:,:), INTENT(INOUT) :: id_detect
+      REAL(dp)        , DIMENSION(:)  , INTENT(IN   ) :: dd_coef 
+      REAL(dp)                        , INTENT(IN   ) :: dd_fill 
+      LOGICAL         , DIMENSION(:),   INTENT(IN   ) :: ld_even
+      INTEGER(I4)     ,                 INTENT(IN   ) :: id_rhoi
+      INTEGER(I4)     ,                 INTENT(IN   ) :: id_rhoj
+
+      ! local variable
+      INTEGER(i4), DIMENSION(2)  :: il_shape
+
+      REAL(dp)   , DIMENSION(16) :: dl_vect
+      REAL(dp)                   :: dl_dx
+      REAL(dp)                   :: dl_dy
+      REAL(dp)                   :: dl_x
+      REAL(dp)                   :: dl_x2
+      REAL(dp)                   :: dl_x3
+      REAL(dp)                   :: dl_y
+      REAL(dp)                   :: dl_y2
+      REAL(dp)                   :: dl_y3
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      IF( SIZE(dd_coef(:)) /= 16 )THEN
+         CALL logger_error("INTERP CUBIC FILL: invalid dimension of "//&
+         &              "coef table. shape should be (/16/)")
+      ELSEIF( ANY(   dd_coef(:)==dd_fill ) )THEN
+         CALL logger_error("INTERP CUBIC FILL: fill value detected in coef . "//&
+         &              "can not compute interpolation.")
+      ELSE
+
+         il_shape(:)=SHAPE(dd_value(:,:))
+
+         dl_dx=1./REAL(id_rhoi)
+         dl_dy=1./REAL(id_rhoj)
+
+         DO jj=1,il_shape(2)
+
+            IF( ld_even(2) )THEN
+               dl_y=(jj-1)*dl_dy - dl_dy*0.5
+            ELSE ! odd refinement
+               dl_y=(jj-1)*dl_dy
+            ENDIF
+            dl_y2=dl_y*dl_y
+            dl_y3=dl_y2*dl_y
+
+            DO ji=1,il_shape(1)
+               
+               IF(id_detect(ji,jj)==1)THEN
+                  
+                  IF( ld_even(1) )THEN
+                     dl_x=(ji-1)*dl_dx - dl_dx*0.5 
+                  ELSE ! odd refinement
+                     dl_x=(ji-1)*dl_dx 
+                  ENDIF
+                  dl_x2=dl_x*dl_x
+                  dl_x3=dl_x2*dl_x
+
+                  dl_vect(:)=(/1._dp, dl_x      , dl_x2      , dl_x3      , &
+                  &            dl_y , dl_x*dl_y , dl_x2*dl_y , dl_x3*dl_y , &
+                  &            dl_y2, dl_x*dl_y2, dl_x2*dl_y2, dl_x3*dl_y2, &
+                  &            dl_y3, dl_x*dl_y3, dl_x2*dl_y3, dl_x3*dl_y3 /)
+
+                  dd_value(ji,jj)=DOT_PRODUCT(dd_coef(:),dl_vect(:))
+                  id_detect(ji,jj)=0
+
+               ENDIF
+
+            ENDDO
+         ENDDO
+
+      ENDIF
+
+   END SUBROUTINE interp__2D_cubic_fill
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in]
+   !> @param[out] 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION interp__2D_linear_coef( dd_value, dd_fill )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp), DIMENSION(:,:)  , INTENT(IN) :: dd_value 
+      REAL(dp)                  , INTENT(IN) :: dd_fill 
+
+      ! function
+      REAL(dp), DIMENSION(4) :: interp__2D_linear_coef
+
+      ! local variable
+
+      REAL(dp), DIMENSION(4,4), PARAMETER :: dp_matrix = RESHAPE( &
+      & (/  1 , 0 , 0 , 0 ,& 
+           -1 , 1 , 0 , 0 ,& 
+           -1 , 0 , 1 , 0 ,& 
+            1 ,-1 ,-1 , 1 /), &
+      & (/ 4, 4 /) )
+
+      REAL(dp), DIMENSION(4) :: dl_vect
+
+      !----------------------------------------------------------------
+
+      IF( ANY(SHAPE(dd_value(:,:))/= 2) )THEN
+         CALL logger_error("INTERP LINEAR COEF: invalid dimension of "//&
+         &              "input tables. shape should be (/2,2/)")
+      ELSEIF( ANY(dd_value(:,:)==dd_fill) )THEN
+         CALL logger_error("INTERP LINEAR COEF: fill value detected. "//&
+         &              "can not compute coefficient.")
+      ELSE
+
+         dl_vect( 1: 4)=PACK(dd_value(:,:),.TRUE. )
+
+         interp__2D_linear_coef(:)=MATMUL(TRANSPOSE(dp_matrix(:,:)),dl_vect(:))
+
+      ENDIF
+   END FUNCTION interp__2D_linear_coef
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in]
+   !> @param[out] 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp__2D_linear_fill( dd_value, id_detect, dd_coef, dd_fill, &
+   &                                  ld_even, id_rhoi, id_rhoj )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)        , DIMENSION(:,:), INTENT(INOUT) :: dd_value 
+      INTEGER(i4)     , DIMENSION(:,:), INTENT(INOUT) :: id_detect
+      REAL(dp)        , DIMENSION(:)  , INTENT(IN   ) :: dd_coef 
+      REAL(dp)                        , INTENT(IN   ) :: dd_fill 
+      LOGICAL         , DIMENSION(:),   INTENT(IN   ) :: ld_even
+      INTEGER(I4)     ,                 INTENT(IN   ) :: id_rhoi
+      INTEGER(I4)     ,                 INTENT(IN   ) :: id_rhoj
+
+      ! local variable
+      INTEGER(i4), DIMENSION(2) :: il_shape
+
+      REAL(dp)   , DIMENSION(4) :: dl_vect
+      REAL(dp)                  :: dl_dx
+      REAL(dp)                  :: dl_dy
+      REAL(dp)                  :: dl_x
+      REAL(dp)                  :: dl_y
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      IF( SIZE(dd_coef(:)) /= 4 )THEN
+         CALL logger_error("INTERP LINEAR FILL: invalid dimension of "//&
+         &              "coef table. shape should be (/4/)")
+      ELSEIF( ANY( dd_coef(:)==dd_fill ) )THEN
+         CALL logger_error("INTERP LINEAR FILL: fill value detected in coef. "//&
+         &              "can not compute interpolation.")
+      ELSE
+
+         il_shape(:)=SHAPE(dd_value(:,:))
+
+         dl_dx=1./REAL(id_rhoi)
+         dl_dy=1./REAL(id_rhoj)
+
+         DO jj=1,il_shape(2)
+
+            IF( ld_even(2) )THEN
+               dl_y=(jj-1)*dl_dy - dl_dy*0.5
+            ELSE ! odd refinement
+               dl_y=(jj-1)*dl_dy
+            ENDIF
+
+            DO ji=1,il_shape(1)
+               
+               IF(id_detect(ji,jj)==1)THEN
+
+                  IF( ld_even(1) )THEN
+                     dl_x=(ji-1)*dl_dx - dl_dx*0.5 
+                  ELSE ! odd refinement
+                     dl_x=(ji-1)*dl_dx 
+                  ENDIF
+
+                  dl_vect(:)=(/1._dp, dl_x, dl_y, dl_x*dl_y /)
+
+                  dd_value(ji,jj)=DOT_PRODUCT(dd_coef(:),dl_vect(:))
+                  id_detect(ji,jj)=0
+
+               ENDIF
+
+            ENDDO
+         ENDDO
+
+      ENDIF
+
+   END SUBROUTINE interp__2D_linear_fill
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in]
+   !> @param[out] 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp__2D_nearest_fill( dd_value, id_detect )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)   , DIMENSION(:,:)  , INTENT(INOUT) :: dd_value 
+      INTEGER(i4), DIMENSION(:,:)  , INTENT(INOUT) :: id_detect
+
+      ! local variable
+      INTEGER(i4), DIMENSION(2) :: il_shape
+
+      INTEGER(i4) :: il_i1
+      INTEGER(i4) :: il_i2
+      INTEGER(i4) :: il_j1
+      INTEGER(i4) :: il_j2
+
+      INTEGER(i4) :: il_half1
+      INTEGER(i4) :: il_half2
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      il_shape(:)=SHAPE(dd_value(:,:))
+
+      il_i1=1
+      il_i2=il_shape(1)
+
+      il_j1=1
+      il_j2=il_shape(2)
+
+      il_half1=CEILING(il_shape(1)*0.5)
+      il_half2=CEILING(il_shape(2)*0.5)
+
+      DO jj=1,il_half2
+
+         DO ji=1,il_half1
+            
+            ! lower left point
+            IF(id_detect(ji,jj)==1)THEN
+
+               dd_value( ji,jj)=dd_value(il_i1,il_j1)
+               id_detect(ji,jj)=0
+
+            ENDIF
+
+            ! lower right point
+            IF(id_detect(il_shape(1)-ji+1,jj)==1)THEN
+
+               dd_value( il_shape(1)-ji+1,jj)=dd_value(il_i2,il_j1)
+               id_detect(il_shape(1)-ji+1,jj)=0
+
+            ENDIF
+
+            ! upper left point
+            IF(id_detect(ji,il_shape(2)-jj+1)==1)THEN
+
+               dd_value( ji,il_shape(2)-jj+1)=dd_value(il_i1,il_j2)
+               id_detect(ji,il_shape(2)-jj+1)=0
+
+            ENDIF            
+
+            ! upper right point
+            IF(id_detect(il_shape(1)-ji+1,il_shape(2)-jj+1)==1)THEN
+
+               dd_value( il_shape(1)-ji+1,il_shape(2)-jj+1)=dd_value(il_i2,il_j2)
+               id_detect(il_shape(1)-ji+1,il_shape(2)-jj+1)=0
+
+            ENDIF            
+
+         ENDDO
+
+      ENDDO
+
+   END SUBROUTINE interp__2D_nearest_fill
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in]
+   !> @param[out] 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION interp__1D_cubic_coef( dd_value, &
+      &                            dd_dfdx,  &
+      &                            dd_fill )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp), DIMENSION(:)  , INTENT(IN) :: dd_value 
+      REAL(dp), DIMENSION(:)  , INTENT(IN) :: dd_dfdx  
+      REAL(dp)                , INTENT(IN) :: dd_fill  
+
+      ! function
+      REAL(dp), DIMENSION(4) :: interp__1D_cubic_coef
+
+      ! local variable
+
+      REAL(dp), DIMENSION(4,4), PARAMETER :: dp_matrix = RESHAPE( &
+      & (/  1 , 0 , 0 , 0 ,& 
+           -1 , 1 , 0 , 0 ,& 
+           -3 , 3 ,-2 ,-1 ,& 
+            2 ,-2 , 1 , 1  /), &
+      & (/ 4, 4 /) )
+
+      REAL(dp), DIMENSION(4) :: dl_vect
+
+      !----------------------------------------------------------------
+      IF( SIZE(dd_value(:))/= 2 .OR. &
+      &   SIZE(dd_dfdx(:) )/= 2  )THEN
+   
+         CALL logger_error("INTERP CUBIC COEF: invalid dimension of "//&
+         &              "input tables. shape should be (/2,2/)")
+
+      ELSEIF( ANY(dd_value(:)==dd_fill) .OR. &
+      &       ANY( dd_dfdx(:)==dd_fill) )THEN
+         CALL logger_error("INTERP CUBIC COEF: fill value detected. "//&
+         &              "can not compute coefficient.")
+      ELSE
+
+         dl_vect( 1: 2)=PACK(dd_value(:),.TRUE. )
+         dl_vect( 3: 4)=PACK(dd_dfdx(:),.TRUE. )
+
+         interp__1D_cubic_coef(:)=MATMUL(TRANSPOSE(dp_matrix(:,:)),dl_vect(:))
+
+      ENDIF
+
+   END FUNCTION interp__1D_cubic_coef
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in]
+   !> @param[out] 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp__1D_cubic_fill( dd_value, id_detect, dd_coef, dd_fill, &
+   &                                 ld_even, id_rhoi )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)        , DIMENSION(:), INTENT(INOUT) :: dd_value 
+      INTEGER(i4)     , DIMENSION(:), INTENT(INOUT) :: id_detect
+      REAL(dp)        , DIMENSION(:), INTENT(IN   ) :: dd_coef 
+      REAL(dp)                      , INTENT(IN   ) :: dd_fill 
+      LOGICAL         ,               INTENT(IN   ) :: ld_even
+      INTEGER(I4)     ,               INTENT(IN   ) :: id_rhoi
+
+      ! local variable
+      INTEGER(i4), DIMENSION(1)  :: il_shape
+
+      REAL(dp)   , DIMENSION(4) :: dl_vect
+      REAL(dp)                   :: dl_dx
+      REAL(dp)                   :: dl_x
+      REAL(dp)                   :: dl_x2
+      REAL(dp)                   :: dl_x3
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(dd_coef(:)) /= 4 )THEN
+         CALL logger_error("INTERP CUBIC FILL: invalid dimension of "//&
+         &              "coef table. shape should be (/4/)")
+      !ELSEIF( ANY(dd_value(:)==dd_fill .AND. id_detect(:)==0 ) .OR. &
+      ELSEIF( ANY( dd_coef(:)==dd_fill ) )THEN
+         CALL logger_error("INTERP CUBIC FILL: fill value detected. "//&
+         &              "can not compute interpolation")
+      ELSE
+
+         il_shape(:)=SHAPE(dd_value(:))
+
+         dl_dx=1./REAL(id_rhoi)
+         
+         DO ji=1,il_shape(1)
+            
+            IF(id_detect(ji)==1)THEN
+
+               IF( ld_even )THEN
+                  dl_x=(ji-1)*dl_dx - dl_dx*0.5 
+               ELSE ! odd refinement
+                  dl_x=(ji-1)*dl_dx 
+               ENDIF
+               dl_x2=dl_x*dl_x
+               dl_x3=dl_x2*dl_x
+
+               dl_vect(:)=(/1._dp, dl_x, dl_x2, dl_x3 /)
+
+               dd_value(ji)=DOT_PRODUCT(dd_coef(:),dl_vect(:))
+               id_detect(ji)=0
+
+            ENDIF
+
+         ENDDO
+
+      ENDIF
+
+   END SUBROUTINE interp__1D_cubic_fill
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in]
+   !> @param[out] 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION interp__1D_linear_coef( dd_value, dd_fill )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp), DIMENSION(:)  , INTENT(IN) :: dd_value 
+      REAL(dp)                , INTENT(IN) :: dd_fill  
+
+      ! function
+      REAL(dp), DIMENSION(2) :: interp__1D_linear_coef
+
+      ! local variable
+
+      REAL(dp), DIMENSION(2,2), PARAMETER :: dp_matrix = RESHAPE( &
+      & (/  1 , 0 ,& 
+           -1 , 1  /), &
+      &  (/ 2, 2 /) )
+
+      REAL(dp), DIMENSION(2) :: dl_vect
+
+      !----------------------------------------------------------------
+
+      IF( ANY(SHAPE(dd_value(:))/= 2) )THEN
+         CALL logger_error("INTERP LINEAR COEF: invalid dimension of "//&
+         &              "input tables. shape should be (/2/)")
+      ELSEIF( ANY(dd_value(:)==dd_fill) )THEN
+         CALL logger_error("INTERP LINEAR COEF: fill value detected. "//&
+         &              "can not compute coefficient.")
+      ELSE
+         
+         dl_vect( 1: 2)=PACK(dd_value(:),.TRUE. )
+
+         interp__1D_linear_coef(:)=MATMUL(TRANSPOSE(dp_matrix(:,:)),dl_vect(:))
+
+      ENDIF
+
+   END FUNCTION interp__1D_linear_coef
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in]
+   !> @param[out] 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp__1D_linear_fill( dd_value, id_detect, dd_coef, dd_fill, &
+   &                                  ld_even, id_rhoi )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)        , DIMENSION(:), INTENT(INOUT) :: dd_value 
+      INTEGER(i4)     , DIMENSION(:), INTENT(INOUT) :: id_detect
+      REAL(dp)        , DIMENSION(:), INTENT(IN   ) :: dd_coef 
+      REAL(dp)                      , INTENT(IN   ) :: dd_fill 
+      LOGICAL         ,               INTENT(IN   ) :: ld_even
+      INTEGER(I4)     ,               INTENT(IN   ) :: id_rhoi      
+
+      ! local variable
+      INTEGER(i4), DIMENSION(1) :: il_shape
+
+      REAL(dp)   , DIMENSION(2) :: dl_vect
+      REAL(dp)                  :: dl_dx
+      REAL(dp)                  :: dl_x
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(dd_coef(:)) /= 2 )THEN
+         CALL logger_error("INTERP LINEAR FILL: invalid dimension of "//&
+         &              "coef table. shape should be (/2/)")
+      !ELSEIF( ANY(dd_value(:)==dd_fill .AND. id_detect(:)==0 ) .OR. &
+      ELSEIF( ANY( dd_coef(:)==dd_fill ) )THEN
+         CALL logger_error("INTERP LINEAR FILL: fill value detected. "//&
+         &              "can not compute interpolation")
+      ELSE
+
+         il_shape(:)=SHAPE(dd_value)
+
+         dl_dx=1./REAL(id_rhoi)
+
+         DO ji=1,il_shape(1)
+            
+            IF(id_detect(ji)==1)THEN
+
+               IF( ld_even )THEN
+                  dl_x=(ji-1)*dl_dx - dl_dx*0.5 
+               ELSE ! odd refinement
+                  dl_x=(ji-1)*dl_dx 
+               ENDIF
+
+               dl_vect(:)=(/1._dp, dl_x /)
+
+               dd_value(ji)=DOT_PRODUCT(dd_coef(:),dl_vect(:))
+               id_detect(ji)=0
+
+            ENDIF
+
+         ENDDO
+
+      ENDIF
+
+   END SUBROUTINE interp__1D_linear_fill
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in]
+   !> @param[out] 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE interp__1D_nearest_fill( dd_value, id_detect )
+      IMPLICIT NONE
+      ! Argument
+      REAL(dp)   , DIMENSION(:), INTENT(INOUT) :: dd_value 
+      INTEGER(i4), DIMENSION(:), INTENT(INOUT) :: id_detect
+
+      ! local variable
+      INTEGER(i4), DIMENSION(1) :: il_shape
+
+      INTEGER(i4) :: il_i1
+      INTEGER(i4) :: il_i2
+
+      INTEGER(i4) :: il_half1
+      
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      il_shape(:)=SHAPE(dd_value)
+
+      il_i1=1
+      il_i2=il_shape(1)
+
+      il_half1=CEILING(il_shape(1)*0.5)
+      
+      DO ji=1,il_half1
+         
+         ! lower left point
+         IF(id_detect(ji)==1)THEN
+
+            dd_value( ji)=dd_value(il_i1)
+            id_detect(ji)=0
+
+         ENDIF
+
+         ! lower right point
+         IF(id_detect(il_shape(1)-ji+1)==1)THEN
+
+            dd_value( il_shape(1)-ji+1)=dd_value(il_i2)
+            id_detect(il_shape(1)-ji+1)=0
+
+         ENDIF
+
+      ENDDO
+
+   END SUBROUTINE interp__1D_nearest_fill
+   !> @endcode
+END MODULE interp
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/iom.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/iom.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/iom.f90	(revision 4245)
@@ -0,0 +1,754 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: iom
+!
+! DESCRIPTION:
+!> @brief Input/Output manager :  Library to read input files<br/>
+!>
+!> @details
+!> 
+!>    to open file:<br/>
+!>    CALL iom_open(td_file)
+!>       - td_file is file structure
+!>
+!>    to write in file:<br/>
+!>    CALL  iom_write_file(td_file)
+!>
+!>    to close file:<br/>
+!>    CALL iom_close(tl_file)
+!>
+!>    to read one dimension in file:<br/>
+!>    tl_dim = iom_read_dim(tl_file, id_dimid)<br/>
+!>    or<br/>
+!>    tl_dim = iom_read_dim(tl_file, cd_name)<br/>
+!>       - id_dimid is dimension id
+!>       - cd_name is dimension name
+!>
+!>    to read variable or global attribute in file:<br/>
+!>    tl_att = iom_read_att(tl_file, id_varid, id_attid)<br/>
+!>    or<br/>
+!>    tl_att = iom_read_att(tl_file, id_varid, cd_attname)<br/>
+!>    or<br/>
+!>    tl_att = iom_read_att(tl_file, cd_varname, cd_attid, [cd_stdname])<br/>
+!>    or<br/>
+!>    tl_att = iom_read_att(tl_file, cd_varname, cd_attname, cd_stdname)
+!>       - id_varid is variable id
+!>       - id_attid is attribute id
+!>       - cd_attname is attribute name
+!>       - cd_varname is variable name
+!>       - cd_stdname is variable standard name (optional)
+!>    
+!>    to read one variable in file:<br/>
+!>    tl_var = iom_read_var(td_file, id_varid, [id_start, id_count])<br/>
+!>    or<br/>
+!>    tl_var = iom_read_var(td_file, cd_name, [id_start, [id_count,]] [cd_stdname])
+!>       - id_varid is variabale id
+!>       - cd_name is variabale name
+!>       - id_start is a integer(4) 1D table of index from which the data 
+!>          values will be read (optional)
+!>       - id_count is a integer(4) 1D table of the number of indices selected
+!>          along each dimension (optional)
+!>       - cd_stdname is variable standard name (optional)
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!> @todo
+!> - see lbc_lnk
+!> - see goup netcdf4
+!> - add iom_fill_var_value : complete tl_file avec valeur de la variable
+!----------------------------------------------------------------------
+MODULE iom
+   USE netcdf                          ! nf90 library
+   USE kind                            ! F90 kind parameter
+   USE fct                             ! basic useful function
+   USE logger                             ! log file manager
+   USE dim                             ! dimension manager
+   USE att                             ! attribute manager
+   USE var                             ! variable manager
+   USE file                            ! file manager
+   USE iom_cdf                         ! netcdf I/O manager
+   USE iom_rstdimg                     ! restart dimg I/O manager
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! function and subroutine
+   PUBLIC :: iom_open        !< open or create file, fill file structure
+   PUBLIC :: iom_create      !< create file, fill file structure
+   PUBLIC :: iom_close       !< close file
+   PUBLIC :: iom_read_dim    !< read one dimension in an opened file
+   PUBLIC :: iom_read_att    !< read one attribute in an opened file
+   PUBLIC :: iom_read_var    !< read one variable  in an opened file   
+   PUBLIC :: iom_fill_var    !< fill variable value
+   PUBLIC :: iom_write_file  !< write file structure contents in an opened file
+   ! PUBLIC :: iom_get_mpp     ! get sub domain decomposition 
+
+                                          !< read variable or global attribute in an opened file
+   PRIVATE :: iom__read_var_name_att_id   !< given variable name or standard name and attribute id.
+   PRIVATE :: iom__read_var_id_att_id     !< given variable id and attribute id.
+   PRIVATE :: iom__read_var_name_att_name !< given variable name or standard name, and attribute name.
+   PRIVATE :: iom__read_var_id_att_name   !< given variable id and attribute name.
+
+   PRIVATE :: iom__read_dim_id            !< read one dimension in an opened file, given dimension id.
+   PRIVATE :: iom__read_dim_name          !< read one dimension in an opened netcdf file, given dimension name.
+   PRIVATE :: iom__read_var_id            !< read variable value in an opened file, given variable id.
+   PRIVATE :: iom__read_var_name          !< read variable value in an opened file, given variable name or standard name.
+   PRIVATE :: iom__fill_var_id            !< fill variable value in an opened file, given variable id
+   PRIVATE :: iom__fill_var_name          !< fill variable value in an opened file, given variable name
+   PRIVATE :: iom__fill_var_all           !< fill all variable value in an opened file
+
+   INTERFACE iom_read_var
+      MODULE PROCEDURE iom__read_var_id
+      MODULE PROCEDURE iom__read_var_name
+   END INTERFACE iom_read_var
+
+   INTERFACE iom_fill_var
+      MODULE PROCEDURE iom__fill_var_id
+      MODULE PROCEDURE iom__fill_var_name
+      MODULE PROCEDURE iom__fill_var_all
+   END INTERFACE 
+
+   INTERFACE iom_read_dim
+      MODULE PROCEDURE iom__read_dim_id
+      MODULE PROCEDURE iom__read_dim_name
+   END INTERFACE iom_read_dim
+
+   INTERFACE iom_read_att    !< read variable or global attribute in an opened file
+      MODULE PROCEDURE iom__read_var_name_att_id   !< given variable name or standard name and attribute id.
+      MODULE PROCEDURE iom__read_var_id_att_id     !< given variable id and attribute id.
+      MODULE PROCEDURE iom__read_var_name_att_name !< given variable name or standard name, and attribute name.
+      MODULE PROCEDURE iom__read_var_id_att_name   !< given variable id and attribute name.
+   END INTERFACE iom_read_att
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief This function open a file in read or write mode<br/>
+   !> If try to open a file in write mode that did not exist, create it.<br/>
+   !> 
+   !> If file already exist, get information about:
+   !> - the number of variables
+   !> - the number of dimensions
+   !> - the number of global attributes
+   !> - the ID of the unlimited dimension
+   !> - the file format
+   !> and finally read dimensions.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_open(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT)  :: td_file
+      !----------------------------------------------------------------
+
+      ! add suffix to file name
+      td_file%c_name = file_add_suffix( TRIM(td_file%c_name), &
+      &                                 TRIM(td_file%c_type)  )
+      ! check type
+      SELECT CASE(TRIM(ADJUSTL(fct_lower(td_file%c_type))))
+
+         CASE('cdf')
+            CALL iom_cdf_open(td_file)
+         CASE('dimg')
+            CALL iom_rstdimg_open(td_file)
+         CASE DEFAULT
+            CALL logger_error("OPEN: unknow type : "//TRIM(td_file%c_name))
+
+      END SELECT
+
+   END SUBROUTINE iom_open
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function create a file<br/>
+   !> 
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_create(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT)  :: td_file
+
+      ! local variable
+      LOGICAL     :: ll_exist
+      !----------------------------------------------------------------
+
+      INQUIRE(FILE=TRIM(td_file%c_name), EXIST=ll_exist )
+      IF( ll_exist )THEN
+         CALL logger_fatal("IOM CREATE: can not create file "//&
+         &  TRIM(td_file%c_name)//". file exist already.")
+      ENDIF
+
+      ! forced to open in write mode
+      td_file%l_wrt=.TRUE.
+      ! check type
+      SELECT CASE(TRIM(td_file%c_type))
+         CASE('cdf')
+            CALL iom_cdf_open(td_file)
+         CASE('dimg')
+            CALL iom_rstdimg_open(td_file)
+         CASE DEFAULT
+            CALL logger_error( "CREATE: can't create file "//&
+            &               TRIM(td_file%c_name)//": type unknown " )
+      END SELECT
+
+   END SUBROUTINE iom_create
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine close file
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_close(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      !----------------------------------------------------------------
+
+      ! open file
+      SELECT CASE(TRIM(td_file%c_type))
+         CASE('cdf')
+            CALL iom_cdf_close(td_file)
+         CASE('dimg')
+            CALL iom_rstdimg_close(td_file)
+         CASE DEFAULT
+            CALL logger_error( " CLOSE: can't close file "//&
+            &               TRIM(td_file%c_name)//": type unknown " )
+      END SELECT
+
+   END SUBROUTINE iom_close
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read attribute (of variable or global) in an opened 
+   !> file, given variable name or standard name and attribute id.
+   !> to get global attribute use 'GLOBAL' as variable name 
+   !>
+   !> To check only standard name of the variable, put variable name to ''
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] cd_varname : variable name. use 'GLOBAL' to read global 
+   !> attribute in a file
+   !> @param[in] id_attid : attribute id
+   !> @param[in] cd_stdname : variable standard name
+   !> @return  attribute structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION iom__read_var_name_att_id( td_file, cd_varname, &
+   &                                              id_attid)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE),       INTENT(IN) :: td_file
+      CHARACTER(LEN=lc), INTENT(IN) :: cd_varname
+      INTEGER(i4),       INTENT(IN) :: id_attid
+
+      ! local variable
+      INTEGER(i4) :: il_varid
+      !----------------------------------------------------------------
+
+      ! get variable id
+      IF( TRIM(fct_upper(cd_varname)) == 'GLOBAL' )THEN
+         il_varid=NF90_GLOBAL
+      ELSE
+         il_varid=var_get_id(td_file%t_var(:), cd_varname)
+      ENDIF
+
+      IF( il_varid /= 0 .OR. TRIM(fct_upper(cd_varname)) == 'GLOBAL' )THEN
+         ! open file
+         SELECT CASE(TRIM(td_file%c_type))
+            CASE('cdf')
+               iom__read_var_name_att_id=iom_read_att( td_file, il_varid, &
+               &                                       id_attid)
+            CASE('dimg')
+               CALL logger_warn( " READ ATT: can't read attribute "//&
+               &              "in dimg file : "//TRIM(td_file%c_name) )
+            CASE DEFAULT
+               CALL logger_error( " READ ATT: can't read attribute in file "//&
+               &               TRIM(td_file%c_name)//" : type unknown " )
+         END SELECT
+      ENDIF
+
+   END FUNCTION iom__read_var_name_att_id
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function read attribute (of variable or global) in an opened 
+   !> file, given variable id and attribute id.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_varid : variable id. use NF90_GLOBAL to read global 
+   !> attribute in a file
+   !> @param[in] id_attid : attribute id
+   !> @return  attribute structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION iom__read_var_id_att_id( td_file, id_varid, &
+   &                                            id_attid)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE), INTENT(IN) :: td_file
+      INTEGER(i4), INTENT(IN) :: id_varid
+      INTEGER(i4), INTENT(IN) :: id_attid
+      !----------------------------------------------------------------
+
+      ! open file
+      SELECT CASE(TRIM(td_file%c_type))
+         CASE('cdf')
+            iom__read_var_id_att_id=iom_cdf_read_att( td_file, id_varid, &
+            &                                         id_attid)
+         CASE('dimg')
+            CALL logger_warn( " READ ATT: can't read attribute in dimg file "//&
+            &              TRIM(td_file%c_name) )
+         CASE DEFAULT
+            CALL logger_error( " READ ATT: can't read attribute in file "//&
+            &               TRIM(td_file%c_name)//" : type unknown " )
+      END SELECT
+
+   END FUNCTION iom__read_var_id_att_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read attribute (of variable or global) in an opened 
+   !> file, given variable name or standard name, and attribute name.
+   !> to get global attribute use 'GLOBAL' as variable name.
+   !>
+   !> To check only standard name of the variable, put variable name to ''
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] cd_varname : variable name or standard name. use 'GLOBAL' to read global
+   !> attribute in a file
+   !> @param[in] cd_attname : attribute name
+   !> @return  attribute structure    
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION iom__read_var_name_att_name( td_file, cd_varname, &
+   &                                                cd_attname)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE),      INTENT(IN) :: td_file
+      CHARACTER(LEN=*), INTENT(IN) :: cd_varname
+      CHARACTER(LEN=*), INTENT(IN) :: cd_attname
+
+      ! local variable
+      INTEGER(i4) :: il_varid
+      !----------------------------------------------------------------
+
+      ! get variable id
+      IF( TRIM(fct_upper(cd_varname)) == 'GLOBAL' )THEN
+         il_varid=NF90_GLOBAL
+      ELSE
+         il_varid=var_get_id(td_file%t_var(:), cd_varname)
+      ENDIF
+
+      IF( il_varid /= 0 .OR. TRIM(fct_upper(cd_varname)) == 'GLOBAL' )THEN
+         ! open file
+         SELECT CASE(TRIM(td_file%c_type))
+            CASE('cdf')
+               iom__read_var_name_att_name=iom_cdf_read_att( td_file, il_varid, &
+               &                                             cd_attname)
+            CASE('dimg')
+               CALL logger_warn( " READ ATT: can't read attribute "//&
+               &              "in dimg file :"//TRIM(td_file%c_name) )
+            CASE DEFAULT
+               CALL logger_error( " READ ATT: can't read attribute in file "//&
+               &               TRIM(td_file%c_name)//" : type unknown " )
+         END SELECT
+      ENDIF
+
+   END FUNCTION iom__read_var_name_att_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read attribute (of variable or global) in an opened 
+   !> file, given variable id and attribute name.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_varid : variable id. use NF90_GLOBAL to read global
+   !> attribute in a file
+   !> @param[in] cd_name : attribute name
+   !> @return  attribute structure    
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION iom__read_var_id_att_name( td_file, id_varid, &
+   &                                              cd_attname)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE), INTENT(IN) :: td_file
+      INTEGER(i4), INTENT(IN) :: id_varid
+      CHARACTER(LEN=*), INTENT(IN) :: cd_attname
+      !----------------------------------------------------------------
+
+      ! open file
+      SELECT CASE(TRIM(td_file%c_type))
+         CASE('cdf')
+            iom__read_var_id_att_name=iom_cdf_read_att( td_file, id_varid, &
+            &                                           cd_attname)
+         CASE('dimg')
+            CALL logger_warn( " READ ATT: can't read attribute in dimg file :"&
+            &              //TRIM(td_file%c_name) )
+         CASE DEFAULT
+            CALL logger_error( " READ ATT: can't read attribute in file "//&
+            &               TRIM(td_file%c_name)//" : type unknown " )
+      END SELECT
+
+   END FUNCTION iom__read_var_id_att_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read one dimension in an opened file, 
+   !> given dimension id.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_dimid : dimension id
+   !> @return  dimension structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TDIM) FUNCTION iom__read_dim_id(td_file, id_dimid)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_file
+      INTEGER(i4), INTENT(IN) :: id_dimid
+      !----------------------------------------------------------------
+
+      ! open file
+      SELECT CASE(TRIM(td_file%c_type))
+         CASE('cdf')
+            iom__read_dim_id=iom_cdf_read_dim(td_file, id_dimid)
+         CASE('dimg')
+            iom__read_dim_id=iom_rstdimg_read_dim(td_file, id_dimid)
+         CASE DEFAULT
+            CALL logger_error( " READ DIM: can't read dimension in file "//&
+            &               TRIM(td_file%c_name)//" : type unknown " )
+      END SELECT      
+
+   END FUNCTION iom__read_dim_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read one dimension in an opened netcdf file, 
+   !> given dimension name.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] cd_name : dimension name
+   !> @return  dimension structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TDIM) FUNCTION iom__read_dim_name(td_file, cd_name)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),      INTENT(IN) :: td_file
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+      !----------------------------------------------------------------
+
+      ! open file
+      SELECT CASE(TRIM(td_file%c_type))
+         CASE('cdf')
+            iom__read_dim_name=iom_cdf_read_dim(td_file, cd_name)
+         CASE('dimg')
+            iom__read_dim_name=iom_rstdimg_read_dim(td_file, cd_name)
+         CASE DEFAULT
+            CALL logger_error( " READ DIM: can't read dimension in file "//&
+            &               TRIM(td_file%c_name)//" : type unknown " )
+      END SELECT      
+
+   END FUNCTION iom__read_dim_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read variable value in an opened 
+   !> file, given variable id.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_varid : variable id
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @return  variable structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION iom__read_var_id( td_file, id_varid,&
+   &                                     id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),                       INTENT(IN) :: td_file
+      INTEGER(i4),                       INTENT(IN) :: id_varid
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_count
+      !----------------------------------------------------------------
+
+      ! open file
+      SELECT CASE(TRIM(td_file%c_type))
+         CASE('cdf')
+            iom__read_var_id=iom_cdf_read_var(td_file, id_varid, &
+            &                                 id_start, id_count)
+         CASE('dimg')
+            iom__read_var_id=iom_rstdimg_read_var(td_file, id_varid, &
+            &                                     id_start, id_count)
+         CASE DEFAULT
+            CALL logger_error( " READ VAR: can't read variable in file "//&
+            &               TRIM(td_file%c_name)//" : type unknown " )
+      END SELECT
+
+   END FUNCTION iom__read_var_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read variable value in an opened 
+   !> file, given variable name or standard name.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @details
+   !> look first for variable name. If it doesn't
+   !> exist in file, look for variable standard name.<br/>
+   !> If variable name is not present, check variable standard name.<br/>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file  : file structure
+   !> @param[in] cd_name  : variable name or standard name
+   !> @param[in] id_start : index in the variable from which the data values
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @return  variable structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION iom__read_var_name(td_file, cd_name,   &
+   &                                      id_start, id_count  )
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE)                   , INTENT(IN) :: td_file
+      CHARACTER(LEN=*)              , INTENT(IN), OPTIONAL :: cd_name
+      INTEGER(i4)     , DIMENSION(:), INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:), INTENT(IN), OPTIONAL :: id_count
+      !INTEGER(i4),      DIMENSION(ip_maxdim),  INTENT(IN), OPTIONAL :: id_start
+      !INTEGER(i4),      DIMENSION(ip_maxdim),  INTENT(IN), OPTIONAL :: id_count
+      !----------------------------------------------------------------
+      
+      ! open file
+      SELECT CASE(TRIM(td_file%c_type))
+         CASE('cdf')
+            iom__read_var_name=iom_cdf_read_var(td_file, cd_name, &
+            &                                   id_start, id_count )
+         CASE('dimg')
+            iom__read_var_name=iom_rstdimg_read_var(td_file, cd_name, &
+            &                                   id_start, id_count )
+         CASE DEFAULT
+            CALL logger_error( " READ VAR: can't read variable in file "//&
+            &               TRIM(td_file%c_name)//" : type unknown " )
+      END SELECT
+
+   END FUNCTION iom__read_var_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill all variables value in an opened 
+   !> file.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom__fill_var_all( td_file, id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),                       INTENT(INOUT) :: td_file
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL :: id_start
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL :: id_count
+      !----------------------------------------------------------------
+
+      ! open file
+      SELECT CASE(TRIM(td_file%c_type))
+         CASE('cdf')
+            CALL iom_cdf_fill_var(td_file, id_start, id_count)
+         CASE('dimg')
+            CALL iom_rstdimg_fill_var(td_file, id_start, id_count)
+         CASE DEFAULT
+            CALL logger_error( " FILL VAR: can't read variable in file "//&
+            &               TRIM(td_file%c_name)//" : type unknown " )
+      END SELECT
+
+   END SUBROUTINE iom__fill_var_all
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill variable value in an opened 
+   !> file, given variable id.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] id_varid : variable id
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom__fill_var_id( td_file, id_varid, id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),                       INTENT(INOUT) :: td_file
+      INTEGER(i4),                       INTENT(IN)    :: id_varid
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL :: id_start
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL :: id_count
+      !----------------------------------------------------------------
+
+      ! open file
+      SELECT CASE(TRIM(td_file%c_type))
+         CASE('cdf')
+            CALL iom_cdf_fill_var(td_file, id_varid, id_start, id_count)
+         CASE('dimg')
+            CALL iom_rstdimg_fill_var(td_file, id_varid, id_start, id_count)
+         CASE DEFAULT
+            CALL logger_error( " FILL VAR: can't read variable in file "//&
+            &               TRIM(td_file%c_name)//" : type unknown " )
+      END SELECT
+
+   END SUBROUTINE iom__fill_var_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill variable value in an opened 
+   !> file, given variable name or standard name.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @details
+   !> look first for variable name. If it doesn't
+   !> exist in file, look for variable standard name.<br/>
+   !> If variable name is not present, check variable standard name.<br/>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] cd_name  : variable name or standard name
+   !> @param[in] id_start : index in the variable from which the data values
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom__fill_var_name( td_file, cd_name, id_start, id_count )
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),                             INTENT(INOUT) :: td_file
+      CHARACTER(LEN=*),                        INTENT(IN)    :: cd_name
+      INTEGER(i4),      DIMENSION(ip_maxdim),  INTENT(IN),   OPTIONAL :: id_start
+      INTEGER(i4),      DIMENSION(ip_maxdim),  INTENT(IN),   OPTIONAL :: id_count
+      !----------------------------------------------------------------
+      
+      ! open file
+      SELECT CASE(TRIM(td_file%c_type))
+         CASE('cdf')
+            CALL iom_cdf_fill_var(td_file, cd_name, id_start, id_count )
+         CASE('dimg')
+            CALL iom_rstdimg_fill_var(td_file, cd_name, id_start, id_count )
+         CASE DEFAULT
+            CALL logger_error( " FILL VAR: can't read variable in file "//&
+            &               TRIM(td_file%c_name)//" : type unknown " )
+      END SELECT
+
+   END SUBROUTINE iom__fill_var_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write file structure in an opened file.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_write_file(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      !----------------------------------------------------------------
+
+      ! open file
+      SELECT CASE(TRIM(td_file%c_type))
+         CASE('cdf')
+            CALL iom_cdf_write_file(td_file)
+         CASE('dimg')
+            CALL iom_rstdimg_write_file(td_file)
+         CASE DEFAULT
+            CALL logger_error( " WRITE: can't write file "//&
+            &               TRIM(td_file%c_name)//" : type unknown " )
+      END SELECT
+
+   END SUBROUTINE iom_write_file
+   !> @endcode   
+!   !-------------------------------------------------------------------
+!   !> @brief This function get sub domain decomposition.
+!   !
+!   !> @details
+!   !
+!   !> @author J.Paul
+!   !> - Nov, 2013- Initial Version
+!   !
+!   !> @param[in] td_file : file structure
+!   !-------------------------------------------------------------------
+!   !> @code
+!   TYPE(TMPP) FUNCTION iom_get_mpp(td_file)
+!      IMPLICIT NONE
+!      ! Argument      
+!      TYPE(TFILE), INTENT(INOUT) :: td_file
+!      !----------------------------------------------------------------
+!
+!      ! open file
+!      SELECT CASE(TRIM(td_file%c_type))
+!         CASE('cdf')
+!            iom_get_mpp = iom_cdf_get_mpp(td_file)
+!         CASE('dimg')
+!            iom_get_mpp = iom_rstdimg_get_mpp(td_file)
+!         CASE DEFAULT
+!            CALL logger_error( " WRITE: can't write file "//&
+!            &               TRIM(td_file%c_name)//" : type unknown " )
+!      END SELECT
+!
+!   END FUNCTION iom_get_mpp
+!   !> @endcode
+END MODULE iom
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/iom_cdf.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/iom_cdf.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/iom_cdf.f90	(revision 4245)
@@ -0,0 +1,2240 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: iom_cdf
+!
+! DESCRIPTION:
+!> @brief
+!> This module is a library to read/write Netcdf file.
+!>
+!> @details
+!>
+!>    to open netcdf file:<br/>
+!>    CALL iom_cdf_open(td_file)
+!>       - td_file is file structure (see file.f90)
+!>
+!>    to write in netcdf file:<br/>
+!>    CALL  iom_cdf_write_file(td_file)
+!>
+!>    to close netcdf file:<br/>
+!>    CALL iom_cdf_close(tl_file)
+!>
+!>    to read one dimension in netcdf file:<br/>
+!>    tl_dim = iom_cdf_read_dim(tl_file, id_dimid)<br/>
+!>    or<br/>
+!>    tl_dim = iom_cdf_read_dim(tl_file, cd_name)
+!>       - id_dimid is dimension id<br/>
+!>       - cd_name is dimension name
+!>
+!>    to read one global attribute in netcdf file:<br/>
+!>    tl_att = iom_cdf_read_att(tl_file, id_varid, id_attid)<br/>
+!>    or<br/>
+!>    tl_att = iom_cdf_read_att(tl_file, id_varid, cd_name)
+!>       - id_varid is variable id
+!>       - id_attid is attribute id<br/>
+!>       - cd_name is attribute name
+!>    
+!>    to read one variable in netcdf file:<br/>
+!>    tl_var = iom_cdf_read_var(td_file, id_varid, [id_start, id_count])<br/>
+!>    or<br/>
+!>    tl_var = iom_cdf_read_var(td_file, cd_name, [id_start, [id_count,]] [cd_stdname])
+!>       - id_varid is variabale id
+!>       - cd_name is variabale name
+!>       - id_start is a integer(4) 1D table of index from which the data 
+!>          values will be read (optional)
+!>       - id_count is a integer(4) 1D table of the number of indices selected
+!>          along each dimension (optional)
+!>       - cd_stdname is variable standard name (optional)
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @param MyModule_type : brief_description
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!
+!> @todo 
+!> - inform variable pni, pnj, pnij, area, iglo, jglo 
+!> - use var_init when read new variable
+!> - use dim_init when read new dimension
+!> - use att_init when read new attribute
+!> - add read td_dom
+!> @todo
+!> - voir si il ne faut pas redefinir (__copy) variable si elle vient de mpp
+!> exemple CALL  mpp_move_var( td_mpp, td_mpp%t_var )
+!----------------------------------------------------------------------
+MODULE iom_cdf
+   USE netcdf                          ! nf90 library
+   USE global                          ! global parameter
+   USE kind                            ! F90 kind parameter
+   USE fct                             ! basic useful function
+   USE logger                             ! log file manager
+   USE att                             ! attribute manage
+   USE dim                             ! dimension manager
+   USE var                             ! variable manager
+   USE file                            ! file manager
+   USE dom                             ! domain manager
+!   USE proc                            ! processor manager
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! function and subroutine
+   PUBLIC :: iom_cdf_open        !< open or create netcdf file, return file structure
+   PUBLIC :: iom_cdf_close       !< close netcdf file
+   PUBLIC :: iom_cdf_read_dim    !< read one dimension in an opened netcdf file, return dimension structure
+   PUBLIC :: iom_cdf_read_att    !< read one attribute in an opened netcdf file, return attribute structure
+   PUBLIC :: iom_cdf_read_var    !< read one variable  in an opened netcdf file, return variable  structure
+   PUBLIC :: iom_cdf_fill_var    !< fill variable value in an opened netcdf file
+   PUBLIC :: iom_cdf_write_file  !< write file structure contents in an opened netcdf file
+   ! PUBLIC :: iom_cdf_get_mpp     ! get sub domain decomposition in a netcdf file
+
+   PRIVATE :: iom_cdf__check           !< provides a simple interface to netcdf error message
+   PRIVATE :: iom_cdf__get_info        !< get global information in an opened netcdf file
+   PRIVATE :: iom_cdf__get_file_dim    !< read dimension on an opened netcdf file, and reorder it
+   PRIVATE :: iom_cdf__get_file_att    !< read global attribute on an opened netcdf file
+   PRIVATE :: iom_cdf__get_file_var    !< read information about variable on an opened netcdf file
+   PRIVATE :: iom_cdf__read_dim_id     !< read one dimension in an opened netcdf file, given dimension id.
+   PRIVATE :: iom_cdf__read_dim_name   !< read one dimension in an opened netcdf file, given dimension name.
+   PRIVATE :: iom_cdf__read_att_name   !< read variable or global attribute in an opened netcdf file, given attribute name. 
+   PRIVATE :: iom_cdf__read_att_id     !< read variable or global attribute in an opened netcdf file, given attribute id.
+   PRIVATE :: iom_cdf__read_var_id     !< read variable value in an opened netcdf file, given variable id.
+   PRIVATE :: iom_cdf__read_var_name   !< read variable value in an opened netcdf file, given variable name or standard name.
+   PRIVATE :: iom_cdf__read_var_meta   !< read metadata of a variable in an opened netcdf file.
+   PRIVATE :: iom_cdf__read_var_dim    !< read variable dimension in an opened netcdf file.
+   PRIVATE :: iom_cdf__read_var_att    !< read variable attributes in an opened netcdf file.
+   PRIVATE :: iom_cdf__read_var_value  !< read variable value in an opened netcdf file.
+   PRIVATE :: iom_cdf__write_dim       !< write one dimension in an opened netcdf file in write mode.
+   PRIVATE :: iom_cdf__write_att       !< write a variable attribute in an opened netcdf file.
+   PRIVATE :: iom_cdf__write_var       !< write a variable in an opened netcdf file.
+   PRIVATE :: iom_cdf__write_var_def   !< define variable in an opened netcdf file.
+   PRIVATE :: iom_cdf__write_var_value !< put variable value in an opened netcdf file.
+   PRIVATE :: iom_cdf__fill_var_id     !< fill variable value in an opened netcdf file, given variable id
+   PRIVATE :: iom_cdf__fill_var_name   !< fill variable value in an opened netcdf file, given variable name
+   PRIVATE :: iom_cdf__fill_var_all    !< fill all variable value in an opened netcdf file
+   PRIVATE :: iom_cdf__del_var_dim     !< remove variable dimension from an opened netcdf file
+
+   INTERFACE iom_cdf_read_var
+      MODULE PROCEDURE iom_cdf__read_var_id
+      MODULE PROCEDURE iom_cdf__read_var_name
+   END INTERFACE iom_cdf_read_var
+
+   INTERFACE iom_cdf_fill_var
+      MODULE PROCEDURE iom_cdf__fill_var_id
+      MODULE PROCEDURE iom_cdf__fill_var_name
+      MODULE PROCEDURE iom_cdf__fill_var_all
+   END INTERFACE iom_cdf_fill_var
+
+   INTERFACE iom_cdf_read_dim
+      MODULE PROCEDURE iom_cdf__read_dim_id
+      MODULE PROCEDURE iom_cdf__read_dim_name
+   END INTERFACE iom_cdf_read_dim
+
+   INTERFACE iom_cdf_read_att
+      MODULE PROCEDURE iom_cdf__read_att_id
+      MODULE PROCEDURE iom_cdf__read_att_name
+   END INTERFACE iom_cdf_read_att
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief This subroutine provides a simple interface to 
+   !> netcdf error message 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] id_status : error status
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__check(id_status)
+      IMPLICIT NONE
+      ! Argument      
+      INTEGER(i4), INTENT(IN) :: id_status
+      !----------------------------------------------------------------
+
+      IF( id_status /= NF90_NOERR )THEN
+         CALL logger_error(TRIM(NF90_STRERROR(id_status)))
+      ENDIF
+
+   END SUBROUTINE iom_cdf__check
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine open a netcdf file in read or write mode<br/>
+   !> if try to open a file in write mode that did not exist, create it.<br/>
+   !> if file already exist, get information about:
+   !> - the number of variables
+   !> - the number of dimensions
+   !> - the number of global attributes
+   !> - the ID of the unlimited dimension
+   !> - the file format
+   !> and finally read dimensions.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf_open(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT)  :: td_file
+
+      ! local variable
+      LOGICAL     :: ll_exist
+      LOGICAL     :: ll_open
+
+      INTEGER(i4) :: il_status
+
+      TYPE(TVAR)  :: tl_lon
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! check file existence
+      INQUIRE(FILE=TRIM(td_file%c_name), EXIST=ll_exist, OPENED=ll_open)
+      ! ll_open do not work for netcdf file, always return FALSE
+      IF( .NOT. ll_exist .OR. TRIM(td_file%c_type) /= 'cdf' )THEN
+
+         IF( .NOT. td_file%l_wrt )THEN
+
+            CALL logger_fatal( " OPEN: can not open file "//&
+            &               TRIM(td_file%c_name) )
+            td_file%i_id=-1
+         
+         ELSE
+
+            CALL logger_info( " CREATE: file "//TRIM(td_file%c_name) )
+
+            il_status = NF90_CREATE( TRIM(td_file%c_name),&
+            &                        NF90_WRITE,               &
+            &                        td_file%i_id)
+            CALL iom_cdf__check(il_status)
+
+            td_file%l_def=.TRUE.
+
+         ENDIF
+
+      ELSE
+
+         IF( td_file%i_id /= 0 )THEN
+
+            CALL logger_error( " OPEN: file "//&
+            &               TRIM(td_file%c_name)//" already opened")
+
+         ELSE
+
+            IF( .NOT. td_file%l_wrt )THEN
+
+               CALL logger_info( " OPEN: file "//&
+               &              TRIM(td_file%c_name)//" in read only mode" )
+
+               il_status = NF90_OPEN( TRIM(td_file%c_name), &
+               &                      NF90_NOWRITE,              &
+               &                      td_file%i_id)
+               CALL iom_cdf__check(il_status)
+
+               CALL logger_debug("OPEN "//TRIM(td_file%c_name)//" "//TRIM(fct_str(td_file%i_id)))
+            ELSE
+
+               CALL logger_info( " OPEN: file "//&
+               &              TRIM(td_file%c_name)//" in write mode" )
+
+               il_status = NF90_OPEN( TRIM(td_file%c_name), &
+               &                      NF90_WRITE,           &
+               &                      td_file%i_id)
+               CALL iom_cdf__check(il_status)
+
+            ENDIF
+
+            ! get general information about file
+            CALL iom_cdf__get_info(td_file)
+
+            ! read dimension in file
+            CALL iom_cdf__get_file_dim(td_file) 
+
+            ! read global attribute in file
+            CALL iom_cdf__get_file_att(td_file)
+
+            ! get information about variables in file
+            CALL iom_cdf__get_file_var(td_file)
+
+            ! get ew overlap
+            tl_lon=iom_cdf_read_var(td_file,'longitude')
+            td_file%i_ew=dom_get_ew_overlap(tl_lon)
+            CALL logger_debug(" IOM OPEN EW "//TRIM(fct_str(td_file%i_ew)) )
+            WHERE( td_file%t_var(:)%t_dim(1)%l_use )
+               td_file%t_var(:)%i_ew=td_file%i_ew
+            END WHERE
+            CALL var_clean(tl_lon)
+
+            DO ji=1,td_file%i_nvar
+               CALL logger_debug(TRIM(td_file%t_var(ji)%c_name)//": "//TRIM(fct_str(td_file%t_var(ji)%i_ew)) )
+            ENDDO
+ 
+            ! remove dimension variable from list of variable
+            CALL iom_cdf__del_var_dim(td_file)
+
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE iom_cdf_open
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine close netcdf file
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf_close(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      !----------------------------------------------------------------
+
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " CLOSE: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+         CALL logger_info( &
+         &  " CLOSE: file "//TRIM(td_file%c_name))
+
+         il_status = NF90_CLOSE(td_file%i_id)
+         CALL iom_cdf__check(il_status)
+
+         td_file%i_id = 0
+
+      ENDIF
+
+   END SUBROUTINE iom_cdf_close
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine get global information in an opened netcdf 
+   !> file.<br/>
+   !> @details
+   !> It gets the number of variables, the number of dimensions, 
+   !> the number of global attributes, the ID of the unlimited dimension
+   !> and finally the format version and filled file strucuture with it.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @return file structure completed 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__get_info(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! local variable
+      INTEGER(i4) :: il_fmt   ! format version
+      INTEGER(i4) :: il_status
+      !----------------------------------------------------------------
+
+      CALL logger_trace( &
+      &  " GET INFO: about netcdf file "//TRIM(td_file%c_name))
+
+      il_status=NF90_INQUIRE(td_file%i_id, td_file%i_ndim, &
+      &     td_file%i_nvar, td_file%i_natt, td_file%i_uldid, il_fmt)
+      CALL iom_cdf__check(il_status)
+
+      SELECT CASE(il_fmt)
+         CASE(nf90_format_classic, nf90_format_64bit)
+            td_file%c_type='cdf'
+         CASE(nf90_format_netcdf4, nf90_format_netcdf4_classic)
+            td_file%c_type='cdf4'
+      END SELECT
+
+      ! record header infos
+      td_file%i_rhd=1
+
+   END SUBROUTINE iom_cdf__get_info
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read dimension on an opened netcdf file, and
+   !> reorder dimension to ('x', 'y', 'z', 't').<br/>
+   !> The dimension structure inside file structure is then completed.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @return file structure completed 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__get_file_dim(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! clean dimension
+      DO ji=1,ip_maxdim
+         CALL dim_clean(td_file%t_dim(ji))
+      ENDDO
+
+      IF( td_file%i_ndim > 0 )THEN
+         DO ji = 1, td_file%i_ndim
+            ! read dimension information
+            td_file%t_dim(ji)=iom_cdf_read_dim( td_file, ji)
+         ENDDO
+
+         ! inform unlimited dimension
+         IF( td_file%i_uldid == -1 )THEN
+            CALL logger_warn( &
+            &  " GET FILE DIM: there is no unlimited dimension in file "//&
+            &  TRIM(td_file%c_name))
+         ELSE
+            td_file%t_dim( td_file%i_uldid )%l_uld=.TRUE.
+         ENDIF
+
+      ELSE
+
+         CALL logger_warn( &
+         &  " GET FILE DIM: there is no dimension in file "//&
+         &  TRIM(td_file%c_name))
+
+      ENDIF
+
+      ! reorder dimension to ('x','y','z','t')
+      CALL dim_reorder(td_file%t_dim(:))
+
+   END SUBROUTINE iom_cdf__get_file_dim
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read global attribute on an opened netcdf 
+   !> file.<br/>
+   !> The attribute structure inside file structure is then completed.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @return file structure completed 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__get_file_att(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( td_file%i_natt > 0 )THEN
+         IF(ASSOCIATED(td_file%t_att))THEN
+            DEALLOCATE(td_file%t_att)
+         ENDIF
+         ALLOCATE(td_file%t_att(td_file%i_natt))
+
+         DO ji = 1, td_file%i_natt
+            ! read global attribute
+            td_file%t_att(ji)=iom_cdf_read_att( td_file, NF90_GLOBAL, ji)
+            
+            SELECT CASE(TRIM(td_file%t_att(ji)%c_name))
+               CASE('periodicity')
+                  td_file%i_perio=INT(td_file%t_att(ji)%d_value(1),i4)
+               CASE('pivot_point')
+                  td_file%i_pivot=INT(td_file%t_att(ji)%d_value(1),i4)
+               CASE('ew_overlap')
+                  td_file%i_ew=INT(td_file%t_att(ji)%d_value(1),i4)
+            END SELECT
+
+         ENDDO
+
+      ELSE
+         CALL logger_debug( &
+         &  " GET FILE ATT: there is no global attribute in file "//&
+         &  TRIM(td_file%c_name))
+      ENDIF
+
+   END SUBROUTINE iom_cdf__get_file_att
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read information about variable of an 
+   !> opened netcdf file.<br/>
+   !> The variable structure inside file structure is then completed.
+   !> @note variable value are not read !
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @return file structure completed 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__get_file_var(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! local variable
+      INTEGER(i4) :: il_attid
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( td_file%i_nvar > 0 )THEN
+         IF(ASSOCIATED(td_file%t_var))THEN
+            DEALLOCATE(td_file%t_var)
+         ENDIF
+         ALLOCATE(td_file%t_var(td_file%i_nvar))
+
+         DO ji = 1, td_file%i_nvar
+            ! read dimension information
+            td_file%t_var(ji)=iom_cdf__read_var_meta( td_file, ji)
+
+            SELECT CASE(td_file%t_var(ji)%i_ndim)
+               CASE(0)
+                  td_file%i_n0d=td_file%i_n0d+1
+               CASE(1)
+                  td_file%i_n1d=td_file%i_n1d+1
+                  td_file%i_rhd=td_file%i_rhd+1
+               CASE(2)
+                  td_file%i_n2d=td_file%i_n2d+1
+                  td_file%i_rhd=td_file%i_rhd+1
+               CASE(3)
+                  td_file%i_n3d=td_file%i_n3d+1
+                  td_file%i_rhd=td_file%i_rhd+td_file%t_dim(3)%i_len
+            END SELECT
+
+            ! look for depth id
+            IF( INDEX(TRIM(td_file%t_var(ji)%c_name),'depth') /= 0 )THEN
+               IF( td_file%i_depthid == 0 )THEN
+                  td_file%i_depthid=ji
+               ELSE
+                  CALL logger_error("IOM OPEN: find more than one "//&
+                  &                 "depth variable in file "//&
+                  &                 TRIM(td_file%c_name) )
+               ENDIF
+            ENDIF
+
+            ! look for time id
+            IF( INDEX(TRIM(td_file%t_var(ji)%c_name),'time') /= 0 )THEN
+               IF( td_file%i_timeid == 0 )THEN
+                  td_file%i_timeid=ji
+               ELSE
+                  il_attid=0
+                  IF( ASSOCIATED(td_file%t_var(ji)%t_att) )THEN
+                     il_attid=att_get_id(td_file%t_var(ji)%t_att(:),'calendar')
+                  ENDIF
+                  IF( il_attid /= 0 )THEN
+                     td_file%i_timeid=ji
+                  !ELSE
+                  !   print *,'error'
+                  !   CALL logger_error("IOM OPEN: find more than one "//&
+                  !   &                 "time variable in file "//&
+                  !   &                 TRIM(td_file%c_name) )
+                  ENDIF
+               ENDIF
+            ENDIF
+
+         ENDDO
+
+      ELSE
+         CALL logger_debug( &
+         &  " GET FILE VAR: there is no variable in file "//&
+         &  TRIM(td_file%c_name))
+      ENDIF
+
+   END SUBROUTINE iom_cdf__get_file_var
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine delete variable dimension from an 
+   !> opened netcdf file.<br/>
+   !
+   !> @author J.Paul
+   !> - 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__del_var_dim(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_name
+      CHARACTER(LEN=lc) :: cl_sname
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+      IF( td_file%i_nvar > 0 )THEN
+         DO ji=td_file%i_nvar,1,-1
+            cl_name=TRIM(td_file%t_var(ji)%c_name)
+            DO jj=1,ip_maxdim
+               IF( td_file%t_dim(jj)%l_use )THEN
+                  cl_sname=fct_upper(td_file%t_dim(jj)%c_sname)
+                  IF( TRIM(cl_name) == TRIM(cl_sname) )THEN
+                     CALL file_del_var(td_file,TRIM(cl_name))
+                     EXIT
+                  ENDIF
+               ENDIF
+            ENDDO
+         ENDDO
+      ELSE
+         CALL logger_debug( &
+         &  " DEL VAR DIM: there is no variable in file "//&
+         &  TRIM(td_file%c_name))
+      ENDIF
+   END SUBROUTINE iom_cdf__del_var_dim
+   !> @endcode
+!   !-------------------------------------------------------------------
+!   !> @brief This subroutine get variable time from an 
+!   !> opened netcdf file.<br/>
+!   !
+!   !> @author J.Paul
+!   !> - 2013- Initial Version
+!   !
+!   !> @param[inout] td_file : file structure
+!   !-------------------------------------------------------------------
+!   !> @code
+!   SUBROUTINE iom_cdf__get_var_time(td_file)
+!      IMPLICIT NONE
+!      ! Argument      
+!      TYPE(TFILE), INTENT(INOUT) :: td_file
+!
+!      ! local variable
+!      CHARACTER(LEN=lc) :: cl_name
+!
+!      ! loop indices
+!      INTEGER(i4) :: ji
+!      !----------------------------------------------------------------
+!      IF( td_file%i_nvar > 0 )THEN
+!         DO ji=1,td_file%i_nvar
+!            cl_name=TRIM(td_file%t_var(ji)%c_name)
+!            IF( INDEX(cl_name,'time') /= 0 )THEN
+!               ! read time variable
+!               td_file%t_time=iom_cdf_read_var(td_file,ji)
+!               ! remove time variable from variable list
+!               CALL file_del_ver(td_file,TRIM(cl_name))
+!               EXIT
+!            ENDIF
+!         ENDDO
+!      ELSE
+!         CALL logger_debug( &
+!         &  " GET VAR TIME: there is no variable in file "//&
+!         &  TRIM(td_file%c_name))
+!      ENDIF
+!   END SUBROUTINE iom_cdf__get_var_time
+!   !> @endcode
+!   !-------------------------------------------------------------------
+!   !> @brief This subroutine get variable depth from an 
+!   !> opened netcdf file.<br/>
+!   !
+!   !> @author J.Paul
+!   !> - 2013- Initial Version
+!   !
+!   !> @param[inout] td_file : file structure
+!   !-------------------------------------------------------------------
+!   !> @code
+!   SUBROUTINE iom_cdf__get_var_depth(td_file)
+!      IMPLICIT NONE
+!      ! Argument      
+!      TYPE(TFILE), INTENT(INOUT) :: td_file
+!
+!      ! local variable
+!      CHARACTER(LEN=lc) :: cl_name
+!
+!      ! loop indices
+!      INTEGER(i4) :: ji
+!      !----------------------------------------------------------------
+!      IF( td_file%i_nvar > 0 )THEN
+!         DO ji=1,td_file%i_nvar
+!            cl_name=TRIM(td_file%t_var(ji)%c_name)
+!            IF( INDEX(cl_name,'depth') /= 0 )THEN
+!               ! read depth variable
+!               td_file%t_depth=iom_cdf_read_var(td_file,ji)
+!               ! remove depth variable from variable list
+!               CALL file_del_ver(td_file,TRIM(cl_name))
+!               EXIT
+!            ENDIF
+!         ENDDO
+!      ELSE
+!         CALL logger_debug( &
+!         &  " GET VAR TIME: there is no variable in file "//&
+!         &  TRIM(td_file%c_name))
+!      ENDIF
+!   END SUBROUTINE iom_cdf__get_var_depth
+!   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read one dimension in an opened netcdf file, 
+   !> given dimension id.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_dimid : dimension id
+   !> @return  dimension structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TDIM) FUNCTION iom_cdf__read_dim_id(td_file, id_dimid)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_file
+      INTEGER(i4), INTENT(IN) :: id_dimid
+
+      ! local variable
+      INTEGER(i4)       :: il_status
+      INTEGER(i4)       :: il_len
+      CHARACTER(LEN=lc) :: cl_name
+      !----------------------------------------------------------------
+
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " READ DIM: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE      
+
+         iom_cdf__read_dim_id%i_id=id_dimid
+
+         CALL logger_debug( &
+         &  " READ DIM: dimension "//TRIM(fct_str(id_dimid))//&
+         &  " in file "//TRIM(td_file%c_name))
+
+         il_status=NF90_INQUIRE_DIMENSION(td_file%i_id, id_dimid, &
+         &                                cl_name, il_len )
+         CALL iom_cdf__check(il_status)
+
+         iom_cdf__read_dim_id=dim_init(cl_name, il_len)
+
+      ENDIF
+
+   END FUNCTION iom_cdf__read_dim_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read one dimension in an opened netcdf file, 
+   !> given dimension name.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] cd_name : dimension name
+   !> @return  dimension structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TDIM) FUNCTION iom_cdf__read_dim_name(td_file, cd_name)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),      INTENT(IN) :: td_file
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_dimid
+      !----------------------------------------------------------------
+
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " READ DIM: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE      
+
+         il_status=NF90_INQ_DIMID( td_file%i_id, TRIM(ADJUSTL(cd_name)), &
+         &                         il_dimid)
+         CALL iom_cdf__check(il_status)
+
+         iom_cdf__read_dim_name=iom_cdf_read_dim(td_file, il_dimid)
+
+      ENDIF
+
+   END FUNCTION iom_cdf__read_dim_name
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function read variable or global attribute in an opened 
+   !> netcdf file, given attribute name.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_varid : variable id. use NF90_GLOBAL to read global
+   !> attribute in a file
+   !> @param[in] cd_name : attribute name
+   !> @return  attribute structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION iom_cdf__read_att_name(td_file, id_varid, cd_name)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),      INTENT(IN) :: td_file
+      INTEGER(i4),      INTENT(IN) :: id_varid
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_name
+
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_attid
+      INTEGER(i4) :: il_type
+      INTEGER(i4) :: il_len
+
+      CHARACTER(LEN=lc) :: cl_value
+      INTEGER(i1), DIMENSION(:), ALLOCATABLE :: bl_value
+      INTEGER(i2), DIMENSION(:), ALLOCATABLE :: sl_value
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_value
+      REAL(sp)   , DIMENSION(:), ALLOCATABLE :: fl_value
+      REAL(dp)   , DIMENSION(:), ALLOCATABLE :: dl_value
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " READ ATT: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE      
+
+         cl_name=TRIM(ADJUSTL(cd_name))
+
+         ! inquire attribute
+         IF( id_varid == NF90_GLOBAL )THEN
+
+            CALL logger_debug( &
+            &  " READ ATT: inquire global attribute "//&
+            &  " in file "//TRIM(td_file%c_name))
+
+         ELSE
+
+            CALL logger_debug( &
+            &  " READ ATT: inquire attribute "//&
+            &  " of variable "//TRIM(fct_str(id_varid))//&
+            &  " in file "//TRIM(td_file%c_name))
+
+         ENDIF
+
+         il_status=NF90_INQUIRE_ATTRIBUTE(td_file%i_id, id_varid,  &
+         &                                cl_name,&
+         &                                il_type,&
+         &                                il_len, &
+         &                                il_attid )
+         CALL iom_cdf__check(il_status)
+
+         !! get attribute value
+         CALL logger_debug( " READ ATT: get attribute "//TRIM(cl_name)//&
+         &               " in file "//TRIM(td_file%c_name))
+
+         SELECT CASE( il_type )
+
+            CASE(NF90_CHAR)
+
+               ! check string lengths
+               IF( LEN(cl_value) < il_len )THEN
+
+                  CALL logger_error( &
+                  &  " READ ATT: not enough space to put attribute "//&
+                  &  TRIM(cl_name) )
+
+               ELSE
+
+                  ! Read the attributes
+                  il_status=NF90_GET_ATT(td_file%i_id, id_varid, &
+                  &                      cl_name, &
+                  &                      cl_value )
+                  CALL iom_cdf__check(il_status)
+
+                  iom_cdf__read_att_name=att_init(cl_name, cl_value)
+
+               ENDIF
+         
+            CASE(NF90_BYTE)
+
+               ALLOCATE( bl_value( il_len), &
+               &         stat=il_status)
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( &
+                  &  " READ ATT: not enough space to put attribute "//&
+                  &  TRIM(cl_name) )
+
+               ELSE
+
+                  ! Read the attributes
+                  il_status=NF90_GET_ATT(td_file%i_id, id_varid, &
+                  &                      cl_name, &
+                  &                      bl_value(:))
+                  CALL iom_cdf__check(il_status)   
+
+                  iom_cdf__read_att_name=att_init(cl_name, bl_value(:))
+
+               ENDIF
+
+               DEALLOCATE(bl_value)
+
+            CASE(NF90_SHORT)
+
+               ALLOCATE( sl_value( il_len), &
+               &         stat=il_status)
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( &
+                  &  " READ ATT: not enough space to put attribute "//&
+                  &  TRIM(cl_name) )
+
+               ELSE
+
+                  ! Read the attributes
+                  il_status=NF90_GET_ATT(td_file%i_id, id_varid, &
+                  &                      cl_name, &
+                  &                      sl_value(:))
+                  CALL iom_cdf__check(il_status)   
+
+                  iom_cdf__read_att_name=att_init(cl_name, sl_value(:))
+
+               ENDIF
+
+               DEALLOCATE(sl_value)
+
+            CASE(NF90_INT)
+
+               ALLOCATE( il_value( il_len), &
+               &         stat=il_status)
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( &
+                  &  " READ ATT: not enough space to put attribute "//&
+                  &  TRIM(cl_name) )
+
+               ELSE
+
+                  ! Read the attributes
+                  il_status=NF90_GET_ATT(td_file%i_id, id_varid, &
+                  &                      cl_name, &
+                  &                      il_value(:))
+                  CALL iom_cdf__check(il_status)   
+
+                  iom_cdf__read_att_name=att_init(cl_name, il_value(:))
+               ENDIF
+
+               DEALLOCATE(il_value)
+
+            CASE(NF90_FLOAT)
+
+               ALLOCATE( fl_value( il_len), &
+               &         stat=il_status)
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( &
+                  &  " READ ATT: not enough space to put attribute "//&
+                  &  TRIM(cl_name) )
+
+               ELSE
+
+                  ! Read the attributes
+                  il_status=NF90_GET_ATT(td_file%i_id, id_varid, &
+                  &                      cl_name, &
+                  &                      fl_value(:))
+                  CALL iom_cdf__check(il_status)   
+
+                  iom_cdf__read_att_name=att_init(cl_name, fl_value(:))
+
+               ENDIF
+
+               DEALLOCATE(fl_value)
+
+            CASE(NF90_DOUBLE)
+
+               ALLOCATE( dl_value( il_len), &
+               &         stat=il_status)
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( &
+                  &  " READ ATT: not enough space to put attribute "//&
+                  &  TRIM(cl_name) )
+
+               ELSE
+
+                  ! Read the attributes
+                  il_status=NF90_GET_ATT(td_file%i_id, id_varid, &
+                  &                      cl_name, &
+                  &                      dl_value(:))
+                  CALL iom_cdf__check(il_status)   
+
+                  iom_cdf__read_att_name=att_init(cl_name, dl_value(:))
+
+               ENDIF
+
+               DEALLOCATE(dl_value)
+
+         END SELECT
+
+         iom_cdf__read_att_name%i_id=il_attid
+
+      ENDIF
+
+   END FUNCTION iom_cdf__read_att_name
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function read variable or global attribute in an opened 
+   !> netcdf file, given attribute id.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_varid : variable id. use NF90_GLOBAL to read global 
+   !> attribute in a file
+   !> @param[in] id_attid : attribute id
+   !> @return  attribute structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TATT) FUNCTION iom_cdf__read_att_id(td_file, id_varid, id_attid)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_file
+      INTEGER(i4), INTENT(IN) :: id_varid
+      INTEGER(i4), INTENT(IN) :: id_attid
+
+      ! local variable
+      INTEGER(i4)       :: il_status
+      CHARACTER(LEN=lc) :: cl_name
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " READ ATT: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE      
+
+         ! get attribute name
+         il_status=NF90_INQ_ATTNAME(td_file%i_id, id_varid, id_attid, cl_name)
+         CALL iom_cdf__check(il_status)
+
+         ! read attribute
+         iom_cdf__read_att_id=iom_cdf__read_att_name(td_file, id_varid, cl_name)
+
+      ENDIF
+
+   END FUNCTION iom_cdf__read_att_id
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function read variable value in an opened 
+   !> netcdf file, given variable id.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_varid : variable id
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @return  variable structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION iom_cdf__read_var_id(td_file, id_varid,&
+   &                                        id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),               INTENT(IN) :: td_file
+      INTEGER(i4),               INTENT(IN) :: id_varid
+      INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_count
+
+      ! local variable
+      INTEGER(i4), DIMENSION(1) :: il_ind
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " IOM READ VAR: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+
+         ! look for variable id
+         il_ind(:)=MINLOC(td_file%t_var(:)%i_id,mask=(td_file%t_var(:)%i_id==id_varid))
+         IF( il_ind(1) /= 0 )THEN
+
+            iom_cdf__read_var_id=td_file%t_var(il_ind(1))
+
+            print *,"iom_cdf__read_var_id ",trim(iom_cdf__read_var_id%c_name)," ",iom_cdf__read_var_id%i_ew
+            !!! read variable value
+            CALL iom_cdf__read_var_value(td_file, iom_cdf__read_var_id, &
+            &                            id_start, id_count)
+
+         ELSE
+            print *,"iom_cdf__read_var_id "
+            CALL logger_error( &
+            &  " IOM READ VAR: there is no variable with id "//&
+            &  TRIM(fct_str(id_varid))//" in file "//TRIM(td_file%c_name))
+         ENDIF
+
+      ENDIF
+   END FUNCTION iom_cdf__read_var_id
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function read variable value in an opened 
+   !> netcdf file, given variable name or standard name.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @details
+   !> look first for variable name. If it doesn't
+   !> exist in file, look for variable standard name.<br/>
+   !> If variable name is not present, check variable standard name.<br/>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] cd_name  : variable name
+   !> @param[in] id_start : index in the variable from which the data values will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] cd_stdname : variable standard name
+   !> @return  variable structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION iom_cdf__read_var_name(td_file, cd_name,  &
+   &                                          id_start, id_count )
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE)     ,                INTENT(IN) :: td_file
+      CHARACTER(LEN=*),                INTENT(IN), OPTIONAL :: cd_name
+      INTEGER(i4)     , DIMENSION(:),  INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:),  INTENT(IN), OPTIONAL :: id_count
+
+      ! local variable
+      INTEGER(i4)       :: il_ind
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " IOM READ VAR: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+
+         IF( .NOT. PRESENT(cd_name) )THEN
+
+            CALL logger_error( &
+            &  " IOM READ VAR: you must specify a variable to read "//&
+            &  " in file "//TRIM(td_file%c_name))
+
+         ELSE
+
+            il_ind=var_get_id(td_file%t_var(:), cd_name)
+            IF( il_ind /= 0 )THEN
+
+               iom_cdf__read_var_name=td_file%t_var(il_ind)
+
+               !!! read variable value
+               CALL iom_cdf__read_var_value( td_file, &
+               &                             iom_cdf__read_var_name, &
+               &                             id_start, id_count)
+
+            ELSE
+
+               CALL logger_error( &
+               &  " IOM READ VAR: there is no variable with "//&
+               &  " name or standard name "//TRIM(cd_name)//&
+               &  " in file "//TRIM(td_file%c_name) )
+            ENDIF
+
+         ENDIF
+
+      ENDIF
+      
+   END FUNCTION iom_cdf__read_var_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill variable value in an opened 
+   !> netcdf file, given variable id.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @note ne peut pas marcher qd on fait boucle sur les variable d'un
+   !> fichier. puisque change id.
+
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__fill_var_all(td_file, id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),               INTENT(INOUT) :: td_file
+      INTEGER(i4), DIMENSION(:), INTENT(IN   ),  OPTIONAL :: id_start
+      INTEGER(i4), DIMENSION(:), INTENT(IN   ),  OPTIONAL :: id_count
+
+      ! local variable
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " FILL VAR: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+
+         DO ji=1,td_file%i_nvar
+            CALL iom_cdf_fill_var(td_file, ji, id_start, id_count)
+         ENDDO
+
+      ENDIF
+   END SUBROUTINE iom_cdf__fill_var_all
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill variable value in an opened 
+   !> netcdf file, given variable id.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @note ne peut pas marcher qd on fait boucle sur les variable d'un
+   !> fichier. puisque change id.
+
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] id_varid : variable id
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__fill_var_id(td_file, id_varid, id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),               INTENT(INOUT) :: td_file
+      INTEGER(i4),               INTENT(IN)    :: id_varid
+      INTEGER(i4), DIMENSION(:), INTENT(IN),  OPTIONAL :: id_start
+      INTEGER(i4), DIMENSION(:), INTENT(IN),  OPTIONAL :: id_count
+
+      ! local variable
+      INTEGER(i4), DIMENSION(1) :: il_ind
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " FILL VAR: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+
+         ! look for variable id
+         il_ind(:)=MINLOC( td_file%t_var(:)%i_id, &
+         &                 mask=(td_file%t_var(:)%i_id==id_varid))
+         IF( il_ind(1) /= 0 )THEN
+
+            !!! read variable value
+            CALL iom_cdf__read_var_value(td_file, td_file%t_var(il_ind(1)), &
+            &                            id_start, id_count)
+
+            DO ji=1,td_file%i_nvar
+               CALL logger_debug(" var id "//TRIM(td_file%t_var(ji)%c_name)//" "//TRIM(fct_str(td_file%t_var(ji)%i_id)) )
+            ENDDO
+         ELSE
+            CALL logger_error( &
+            &  " FILL VAR: there is no variable with id "//&
+            &  TRIM(fct_str(id_varid))//" in file "//TRIM(td_file%c_name))
+         ENDIF
+
+      ENDIF
+   END SUBROUTINE iom_cdf__fill_var_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill variable value in an opened 
+   !> netcdf file, given variable name or standard name.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @details
+   !> look first for variable name. If it doesn't
+   !> exist in file, look for variable standard name.<br/>
+   !> If variable name is not present, check variable standard name.<br/>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] cd_name  : variable name or standard name
+   !> @param[in] id_start : index in the variable from which the data values will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__fill_var_name(td_file, cd_name, id_start, id_count )
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),                   INTENT(INOUT) :: td_file
+      CHARACTER(LEN=*),              INTENT(IN)    :: cd_name
+      INTEGER(i4),     DIMENSION(:), INTENT(IN),  OPTIONAL :: id_start
+      INTEGER(i4),     DIMENSION(:), INTENT(IN),  OPTIONAL :: id_count
+
+      ! local variable
+      INTEGER(i4)       :: il_ind
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " FILL VAR: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+
+            il_ind=var_get_id(td_file%t_var(:), cd_name)
+            IF( il_ind /= 0 )THEN
+
+               !!! read variable value
+               CALL iom_cdf__read_var_value(td_file, td_file%t_var(il_ind), &
+               &                            id_start, id_count)
+
+            ELSE
+
+               CALL logger_error( &
+               &  " FILL VAR: there is no variable with "//&
+               &  "name or standard name"//TRIM(cd_name)//&
+               &  " in file "//TRIM(td_file%c_name))
+            ENDIF
+
+      ENDIF
+      
+   END SUBROUTINE iom_cdf__fill_var_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read metadata of a variable in an opened 
+   !> netcdf file.</br/>
+   !
+   !> @note variable value are not read
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] id_fileid : file id
+   !> @param[in] id_varid : variable id
+   !> @return  variable structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION iom_cdf__read_var_meta(td_file, id_varid)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_file
+      INTEGER(i4), INTENT(IN) :: id_varid
+
+      ! local variable
+      CHARACTER(LEN=lc)                                       :: cl_name
+
+      INTEGER(i4)                                             :: il_status
+      INTEGER(i4)                                             :: il_type
+      INTEGER(i4)                                             :: il_ndim
+      INTEGER(i4)                                             :: il_natt
+      INTEGER(i4)                                             :: il_attid
+      INTEGER(i4), DIMENSION(NF90_MAX_VAR_DIMS)               :: il_dimid
+
+      TYPE(TDIM) , DIMENSION(ip_maxdim)                       :: tl_dim
+      TYPE(TATT)                                              :: tl_fill
+      TYPE(TATT) , DIMENSION(:)                 , ALLOCATABLE :: tl_att
+      TYPE(TATT) , DIMENSION(:)                 , ALLOCATABLE :: tl_tmp
+
+      ! loop indices
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " READ ATT: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+
+         ! inquire variable
+         CALL logger_trace( &
+         &  " READ VAR: inquire variable "//TRIM(fct_str(id_varid))//&
+         &  " in file "//TRIM(td_file%c_name))
+         
+         il_dimid(:)=0
+
+         il_status=NF90_INQUIRE_VARIABLE( td_file%i_id, id_varid,        &
+         &                                cl_name,    &
+         &                                il_type,    &
+         &                                il_ndim,    &
+         &                                il_dimid(:),&
+         &                                il_natt )
+         CALL iom_cdf__check(il_status)
+
+         !!! fill variable dimension structure
+         tl_dim(:)=iom_cdf__read_var_dim( td_file, il_ndim, il_dimid(:) )
+
+         IF( il_natt /= 0 )THEN
+            ALLOCATE( tl_att(il_natt) )
+            !!! fill variable attribute structure
+            tl_att(:)=iom_cdf__read_var_att(td_file, id_varid, il_natt)
+
+            !! look for _FillValue. if none add one
+            il_attid=att_get_id(tl_att(:),'_FillValue')
+            IF( il_attid == 0 )THEN
+               CALL logger_warn("IOM READ VAR: no _FillValue for variable "//&
+               &  TRIM(cl_name)//" in file "//TRIM(td_file%c_name) )
+
+               il_attid=att_get_id(tl_att(:),'missing_value')
+               IF( il_attid /= 0 )THEN
+                  ! create attribute _FillValue
+                  CALL logger_warn("IOM READ VAR: assume _FillValue is equal to "//&
+                  &                "missing_value for variable "//TRIM(cl_name) )
+                  tl_fill=att_init('_FillValue',tl_att(il_attid)%d_value(:))
+               ELSE
+                  ! create attribute _FillValue
+                  CALL logger_warn("IOM READ VAR: assume _FillValue is equal to "//&
+                  &                "zero for variable "//TRIM(cl_name) )
+                  tl_fill=att_init('_FillValue',0.)
+                  !tl_fill=att_init('_FillValue',1.e20)
+               ENDIF
+
+               ALLOCATE( tl_tmp(il_natt) )
+               ! save read attribut
+               tl_tmp(:)=tl_att(:)
+               ! change number of attribute in table
+               DEALLOCATE( tl_att )
+               ALLOCATE( tl_att(il_natt+1) )
+               ! copy read attribut
+               tl_att(1:il_natt)=tl_tmp(:)
+               DEALLOCATE( tl_tmp )
+
+               ! create attribute _FillValue
+               tl_att(il_natt+1)=tl_fill
+
+            ENDIF
+
+         ELSE
+            ALLOCATE(tl_att(il_natt+1) )
+            ! create attribute _FillValue
+            CALL logger_warn("IOM READ VAR: assume _FillValue is equal to "//&
+            &                "zero for variable "//TRIM(cl_name) )
+            tl_fill=att_init('_FillValue',0.)
+            ! create attribute _FillValue
+            tl_att(il_natt+1)=tl_fill
+         ENDIF
+
+         !! initialize variable
+         iom_cdf__read_var_meta=var_init( cl_name, il_type, tl_dim(:), &
+         &                                tl_att(:), id_id=id_varid )
+
+         DEALLOCATE( tl_att )
+
+      ENDIF
+
+   END FUNCTION iom_cdf__read_var_meta
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read variable dimension
+   !> in an opened netcdf file.
+   !
+   !> @details
+   !> the number of dimension can't exceed 4, 
+   !> and should be 'x', 'y', 'z', 't' (whatever their order).<br/>
+   !> If the number of dimension read is less than 4, the table of dimension
+   !> strucure is filled with unused dimension.<br/>
+   !> So the table of dimension structure of a variable is always compose of 4
+   !> dimension (use or not). 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @return file structure completed 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION iom_cdf__read_var_dim(td_file, id_ndim, id_dimid)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),               INTENT(IN) :: td_file
+      INTEGER(i4),               INTENT(IN) :: id_ndim
+      INTEGER(i4), DIMENSION(:), INTENT(IN) :: id_dimid
+
+      ! function
+      TYPE(TDIM), DIMENSION(ip_maxdim) :: iom_cdf__read_var_dim
+
+      ! local variable
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_2xyzt
+
+      TYPE(TDIM) , DIMENSION(ip_maxdim) :: tl_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( id_ndim == 0 )THEN
+
+         tl_dim(:)%l_use=.FALSE.
+
+         ! reorder dimension to ('x','y','z','t')
+         CALL dim_reorder(tl_dim(:))
+
+         iom_cdf__read_var_dim(:)=tl_dim(:)
+
+      ELSE IF( id_ndim > 0 .AND. id_ndim <= 4 )THEN
+
+
+         DO ji = 1, id_ndim
+            CALL logger_debug( " READ VAR DIM: get variable dimension "//&
+            &               TRIM(fct_str(ji)) )
+
+            il_2xyzt(ji)=td_file%t_dim(id_dimid(ji))%i_2xyzt
+
+            ! read dimension information
+            tl_dim(ji) = dim_init( td_file%t_dim(il_2xyzt(ji))%c_name, &
+            &                      td_file%t_dim(il_2xyzt(ji))%i_len )
+         ENDDO
+
+         ! reorder dimension to ('x','y','z','t')
+         CALL dim_reorder(tl_dim(:))
+      
+         iom_cdf__read_var_dim(:)=tl_dim(:)
+
+      ELSE
+
+         CALL logger_error(" READ VAR DIM: can't manage "//&
+         &              TRIM(fct_str(id_ndim))//" dimension(s)" )
+
+      ENDIF
+
+   END FUNCTION iom_cdf__read_var_dim
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read variable attributes
+   !> in an opened netcdf file.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[inout] td_var : variable structure
+   !> @return filled variable attribute structure 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION iom_cdf__read_var_att(td_file, id_varid, id_natt)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_file
+      INTEGER(i4), INTENT(IN) :: id_varid
+      INTEGER(i4), INTENT(IN) :: id_natt      
+
+      ! function
+      TYPE(TATT), DIMENSION(id_natt) :: iom_cdf__read_var_att
+
+      ! local variable
+      TYPE(TATT), DIMENSION(id_natt) :: tl_att
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( id_natt > 0 )THEN
+
+         ! read attributes
+         DO ji = 1, id_natt
+            CALL logger_debug( " READ VAR ATT: get attribute "//&
+            &               TRIM(fct_str(ji)) )
+
+            tl_att(ji)=iom_cdf_read_att(td_file, id_varid, ji)
+
+         ENDDO
+
+         iom_cdf__read_var_att(:)=tl_att(:)
+
+      ELSE
+
+         CALL logger_debug( " READ VAR ATT: no attribute for variable " )
+
+      ENDIF
+
+   END FUNCTION iom_cdf__read_var_att
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read variable value
+   !> in an opened netcdf file.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[inout] td_var : variable structure
+   !> @param[in] id_start : index in the variable from which the data values will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @return variable structure completed 
+   !
+   !> @todo
+   !> - warning do not change fill value when use scale factor..
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__read_var_value(td_file, td_var, &
+   &                                  id_start, id_count )
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),               INTENT(IN)    :: td_file
+      TYPE(TVAR) ,               INTENT(INOUT) :: td_var
+      INTEGER(i4), DIMENSION(:), INTENT(IN),   OPTIONAL :: id_start
+      INTEGER(i4), DIMENSION(:), INTENT(IN),   OPTIONAL :: id_count
+
+      ! local variable
+      INTEGER(i4)                       :: il_status
+      INTEGER(i4)                       :: il_tmp1, il_tmp2, il_varid
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_start
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_count
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_start_ord
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_count_ord
+      REAL(dp)   , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      TYPE(TDIM),  DIMENSION(ip_maxdim) :: tl_dim
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! check id_count and id_start optionals parameters...
+      IF( (       PRESENT(id_start)  .AND. (.NOT. PRESENT(id_count))) .OR. &
+          ((.NOT. PRESENT(id_start)) .AND.        PRESENT(id_count) ) )THEN
+         CALL logger_warn( &
+         &  " READ VAR VALUE: id_start and id_count should be both specify")
+      ENDIF
+
+      IF( PRESENT(id_start).AND.PRESENT(id_count) )THEN
+
+         IF( SIZE(id_start(:)) /= ip_maxdim .OR. &
+         &   SIZE(id_count(:)) /= ip_maxdim )THEN
+            CALL logger_error("READ VAR: dimension of table start or count "//&
+            &      " are invalid to read variable "//TRIM(td_var%c_name)//&
+            &      " in file "//TRIM(td_file%c_name) )
+         ENDIF
+
+         ! change dimension order from ('x','y','z','t')
+         il_start(:)=dim_reorder_xyzt2(td_var%t_dim, id_start(:))
+         il_count(:)=dim_reorder_xyzt2(td_var%t_dim, id_count(:))
+
+         ! keep ordered table ('x','y','z','t')
+         il_start_ord(:)=il_start(:)
+         il_count_ord(:)=il_count(:)
+
+      ELSE
+
+         ! change dimension order from ('x','y','z','t')
+         il_start(:)=(/1,1,1,1/)
+         il_count(:)=dim_reorder_xyzt2(td_var%t_dim(:),td_var%t_dim(:)%i_len)
+
+         ! keep ordered table ('x','y','z','t')
+         il_start_ord(:)=(/1,1,1,1/)
+         il_count_ord(:)=td_var%t_dim(:)%i_len
+
+      ENDIF
+
+      ! check dimension
+      IF( .NOT. ALL(il_start_ord(:)>=(/1,1,1,1/)) )THEN
+
+         CALL logger_error( &
+         &" READ VAR VALUE: start indices should be greater than or equal to 1")
+
+      ENDIF
+
+      IF(.NOT.ALL(il_start_ord(:)+il_count_ord(:)-1<=(/td_var%t_dim(1)%i_len,&
+         &                                             td_var%t_dim(2)%i_len,&
+         &                                             td_var%t_dim(3)%i_len,&
+         &                                             td_var%t_dim(4)%i_len &
+         &                                            /)) )THEN
+
+         CALL logger_error( &
+         &  " READ VAR VALUE: start + count exceed variable dimension" )
+
+         DO ji = 1, ip_maxdim
+            il_tmp1=il_start_ord(ji)+il_count_ord(ji)
+            il_tmp2=td_var%t_dim(ji)%i_len
+            CALL logger_debug( &
+            &  " READ VAR VALUE: start + count -1 "//TRIM(fct_str(il_tmp1))//&
+            &  " variable dimension"//TRIM(fct_str(il_tmp2)))
+         ENDDO
+
+      ELSE
+
+         ! Allocate space to hold variable value (unorder)
+         ALLOCATE(dl_value( il_count(1), &
+            &               il_count(2), &
+            &               il_count(3), &
+            &               il_count(4)),&
+            &               stat=il_status)
+         IF( il_status /= 0 )THEN
+
+           CALL logger_error( &
+            &  " READ VAR VALUE: not enough space to put variable "//&
+            &  TRIM(td_var%c_name))
+
+         ENDIF
+
+         ! read values
+         CALL logger_debug( &
+         &  " READ VAR VALUE: get variable "//TRIM(td_var%c_name)//&
+         &  " in file "//TRIM(td_file%c_name))
+         CALL logger_debug("start "//TRIM(fct_str(il_start(1)))//','//&
+         &                           TRIM(fct_str(il_start(2)))//','//&
+         &                           TRIM(fct_str(il_start(3)))//','//&
+         &                           TRIM(fct_str(il_start(4)))//')'  )
+         CALL logger_debug("count "//TRIM(fct_str(il_count(1)))//','//&
+         &                           TRIM(fct_str(il_count(2)))//','//&
+         &                           TRIM(fct_str(il_count(3)))//','//&
+         &                           TRIM(fct_str(il_count(4)))//')'  )
+         CALL logger_debug("dim "//TRIM(fct_str(td_file%t_dim(1)%i_len))//','//&
+         &                         TRIM(fct_str(td_file%t_dim(2)%i_len))//','//&
+         &                         TRIM(fct_str(td_file%t_dim(3)%i_len))//','//&
+         &                         TRIM(fct_str(td_file%t_dim(4)%i_len))//')'  )
+         CALL logger_debug("shape "//TRIM(fct_str(SIZE(dl_value,DIM=1)))//","//&
+         &                           TRIM(fct_str(SIZE(dl_value,DIM=2)))//","//&
+         &                           TRIM(fct_str(SIZE(dl_value,DIM=3)))//","//&
+         &                           TRIM(fct_str(SIZE(dl_value,DIM=4)))//")" )
+         CALL logger_debug("var "//TRIM(td_var%c_name))
+         il_varid=var_get_id(td_file%t_var(:),TRIM(td_var%c_name))
+         CALL logger_debug("var id "//TRIM(fct_str(il_varid))//' '//TRIM(fct_str(td_var%i_id)))
+         CALL logger_debug("file id "//TRIM(fct_str(td_file%i_id)))
+         il_status = NF90_GET_VAR( td_file%i_id, td_var%i_id,        &
+         &                                       dl_value(:,:,:,:),  &
+         &                                       start = il_start(:),&
+         &                                       count = il_count(:) )
+         CALL iom_cdf__check(il_status)
+
+         ! Allocate space to hold variable value in structure
+         IF( ASSOCIATED(td_var%d_value) )THEN
+            DEALLOCATE(td_var%d_value)   
+         ENDIF
+  
+         ! new dimension length
+         td_var%t_dim(:)%i_len=il_count_ord(:)
+
+         ALLOCATE(td_var%d_value( il_count_ord(1), &
+         &                        il_count_ord(2), &
+         &                        il_count_ord(3), &
+         &                        il_count_ord(4)),&
+         &        stat=il_status)
+         IF(il_status /= 0 )THEN
+
+            CALL logger_error( &
+            &  " READ VAR VALUE: not enough space to put variable "//&
+            &  TRIM(td_var%c_name)//&
+            &  " in variable structure")
+
+         ENDIF
+         ! FillValue by default
+         td_var%d_value(:,:,:,:)=td_var%d_fill
+
+         ! reshape values to be ordered as ('x','y','z','t')
+         tl_dim(:)=td_var%t_dim(:)
+         td_var%d_value(:,:,:,:)=dim_reshape_2xyzt(tl_dim,dl_value(:,:,:,:))
+
+         DEALLOCATE(dl_value)
+
+         ! force to change _FillValue to avoid mistake 
+         ! with dummy zero _FillValue
+         IF( td_var%d_fill == 0._dp )THEN
+            CALL var_chg_FillValue(td_var)
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE iom_cdf__read_var_value
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write file structure in an opened netcdf file.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf_write_file(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! local variable
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_value
+
+      TYPE(TVAR)                             :: tl_var
+
+      TYPE(TDIM), DIMENSION(ip_maxdim)       :: tl_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " WRITE FILE: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+         IF( td_file%l_wrt )THEN
+
+            ! delete dummy variable
+            CALL file_del_var( td_file, 'no0d' )
+            CALL file_del_var( td_file, 'no1d' )
+            CALL file_del_var( td_file, 'no2d' )
+            CALL file_del_var( td_file, 'no3d' )
+
+            DO ji = 1, td_file%i_nvar
+               CALL var_check_dim( td_file%t_var(ji) )
+            ENDDO
+
+            ! save usefull dimension
+            tl_dim(:)=var_max_dim(td_file%t_var(:))
+
+            DO ji=1,ip_maxdim
+               IF( tl_dim(ji)%l_use ) CALL file_move_dim(td_file, tl_dim(ji))
+            ENDDO
+
+            ! write dimension in file
+            DO ji = 1, ip_maxdim
+               IF( td_file%t_dim(ji)%l_use )THEN
+                  CALL iom_cdf__write_dim(td_file, td_file%t_dim(ji))
+
+                  ! write dimension variable
+                  ALLOCATE(il_value(td_file%t_dim(ji)%i_len))
+                  il_value(:)=(/(jj,jj=1,td_file%t_dim(ji)%i_len)/)
+
+                  tl_var=var_init( fct_upper(td_file%t_dim(ji)%c_sname), &
+                  &                il_value(:),                          &
+                  &                td_dim=td_file%t_dim(ji) )
+
+                  DEALLOCATE(il_value)
+                   
+                  CALL iom_cdf__write_var(td_file,tl_var)
+                  CALL var_clean(tl_var)
+
+               ENDIF
+            ENDDO
+
+            ! write global attibute in file
+            DO ji = 1, td_file%i_natt
+               CALL iom_cdf__write_att(td_file, NF90_GLOBAL, td_file%t_att(ji))
+            ENDDO
+
+            ! write variable in file
+            DO ji = 1, td_file%i_nvar
+               CALL iom_cdf__write_var(td_file, td_file%t_var(ji)) 
+            ENDDO
+
+         ELSE
+
+            CALL logger_error( &
+            &  " WRITE FILE: try to write in file "//TRIM(td_file%c_name)//&
+            &  ", not opened in write mode")
+
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE iom_cdf_write_file
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write one dimension in an opened netcdf 
+   !> file in write mode.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[inout] td_dim : dimension structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__write_dim(td_file, td_dim)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      TYPE(TDIM),  INTENT(INOUT) :: td_dim
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      !----------------------------------------------------------------
+
+      IF( .NOT. td_file%l_def )THEN
+
+         CALL logger_debug( &
+         &  " WRITE FILE DIM: Enter define mode, file "//TRIM(td_file%c_name))
+
+         ! Enter define mode
+         il_status=NF90_REDEF(td_file%i_id)
+         CALL iom_cdf__check(il_status)
+
+         td_file%l_def=.TRUE.
+
+      ENDIF
+
+      IF( td_dim%l_use )THEN
+         IF( td_dim%l_uld )THEN
+            ! write unlimited dimension
+            CALL logger_debug( &
+            &  " WRITE FILE DIM: write unlimited dimension "//&
+            &  TRIM(td_dim%c_name)//" in file "//TRIM(td_file%c_name))
+
+            il_status=NF90_DEF_DIM(td_file%i_id, fct_upper(td_dim%c_sname), &
+            &                      NF90_UNLIMITED, td_dim%i_id)
+            CALL iom_cdf__check(il_status)
+
+         ELSE
+            ! write not unlimited dimension
+            CALL logger_debug( &
+            &  " WRITE FILE DIM: write dimension "//TRIM(td_dim%c_name)//&
+            &  " in file "//TRIM(td_file%c_name))
+            
+            il_status=NF90_DEF_DIM(td_file%i_id, fct_upper(td_dim%c_sname), &
+            &                      td_dim%i_len, td_dim%i_id)
+            CALL iom_cdf__check(il_status)
+
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE iom_cdf__write_dim
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write a variable attribute in
+   !> an opened netcdf file.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] id_varid : variable id. use NF90_GLOBAL to write global attribute
+   !> in a file
+   !> @param[in] td_att : attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__write_att(td_file, id_varid, td_att)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      INTEGER(i4), INTENT(IN)    :: id_varid
+      TYPE(TATT),  INTENT(IN)    :: td_att
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      !----------------------------------------------------------------
+
+      IF( .NOT. td_file%l_def )THEN
+
+         CALL logger_debug( &
+         &  " WRITE FILE ATT: Enter define mode, file "//TRIM(td_file%c_name))
+
+         ! Enter define mode
+         il_status=NF90_REDEF(td_file%i_id)
+         CALL iom_cdf__check(il_status)
+
+         td_file%l_def=.TRUE.
+
+      ENDIF
+
+      !! put attribute value
+      CALL logger_debug( &
+      &  " WRITE FILE ATT: write attribute "//TRIM(td_att%c_name)//&
+      &  " of variable "//TRIM(fct_str(id_varid))//&
+      &  " in file "//TRIM(td_file%c_name))
+      SELECT CASE( td_att%i_type )
+
+         CASE(NF90_CHAR)
+            ! put the attribute
+            il_status = NF90_PUT_ATT(td_file%i_id, id_varid, &
+            &  td_att%c_name, td_att%c_value )
+            CALL iom_cdf__check(il_status)
+
+         CASE(NF90_BYTE, NF90_SHORT, NF90_INT, NF90_FLOAT, NF90_DOUBLE)
+            ! put the attribute
+            il_status = NF90_PUT_ATT(td_file%i_id, id_varid, &
+            &  td_att%c_name, td_att%d_value )
+            CALL iom_cdf__check(il_status)
+
+      END SELECT
+
+   END SUBROUTINE iom_cdf__write_att
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write a variable in an opened netcdf file.</br/>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[inout] td_var : variable structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__write_var(td_file, td_var)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+      TYPE(TVAR),  INTENT(INOUT) :: td_var
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      !----------------------------------------------------------------
+
+      IF( .NOT. td_file%l_def )THEN
+
+         CALL logger_debug( &
+         &  " WRITE FILE VAR: Enter define mode, file "//TRIM(td_file%c_name))
+
+         ! Enter define mode
+         il_status=NF90_REDEF(td_file%i_id)
+         CALL iom_cdf__check(il_status)
+
+         td_file%l_def=.TRUE.
+
+      ENDIF
+      
+      ! check if file and variable dimension conform
+      IF( file_check_var_dim(td_file, td_var) )THEN
+
+         ! check variable dimension expected
+         CALL var_check_dim(td_var)
+
+         ! change fill value to NETCDF standard
+         CALL var_chg_FillValue(td_var)
+
+         ! define variable in file
+         td_var%i_id=iom_cdf__write_var_def(td_file, td_var) 
+
+         IF( td_file%l_def )THEN
+
+            CALL logger_debug( &
+            &  " WRITE FILE VAR: Leave define mode, file "//TRIM(td_file%c_name))
+
+            ! Leave define mode
+            il_status=NF90_ENDDEF(td_file%i_id)
+            CALL iom_cdf__check(il_status)
+
+            td_file%l_def=.FALSE.
+
+         ENDIF
+
+         IF( ASSOCIATED(td_var%d_value) )THEN
+            ! write variable value in file
+            CALL iom_cdf__write_var_value(td_file, td_var)
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE iom_cdf__write_var
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function define variable in an opened netcdf file.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] td_var : variable structure
+   !> @return  variable id
+   !-------------------------------------------------------------------
+   !> @code
+   INTEGER(i4) FUNCTION iom_cdf__write_var_def(td_file, td_var)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_file
+      TYPE(TVAR),  INTENT(IN) :: td_var
+
+      ! local variable
+      INTEGER(i4)                       :: il_status
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_dimid
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      CALL logger_debug( &
+      &  " WRITE FILE VAR DEF: get dimension to be used for variable "//&
+      &  TRIM(td_var%c_name)//" in file "//TRIM(td_file%c_name))
+
+      IF( ALL( .NOT. td_var%t_dim(:)%l_use ) )THEN
+         ! scalar value
+         il_status = NF90_DEF_VAR(td_file%i_id, TRIM(td_var%c_name), &
+         &                        td_var%i_type, varid=iom_cdf__write_var_def) 
+         CALL iom_cdf__check(il_status)
+      ELSE
+
+         ! check which dimension use
+         jj=0
+         il_dimid(:)=0
+         ! reorder dimension, so unused dimension won't be written
+         DO ji = 1,  ip_maxdim
+            IF( td_var%t_dim(ji)%l_use )THEN
+               jj=jj+1
+               CALL logger_debug(" get dim id for dimension "//TRIM(td_var%t_dim(ji)%c_name))
+               il_dimid(jj)=dim_get_id(td_file%t_dim(:),td_var%t_dim(ji)%c_name)
+            ENDIF
+         ENDDO
+
+         CALL logger_debug( &
+         &  " WRITE FILE VAR DEF: define dimension to be used for variable "//&
+         &  TRIM(td_var%c_name)//" in file "//TRIM(td_file%c_name))
+
+         DO ji=1,jj
+            CALL logger_debug(" WRITE FILE VAR DEF: dimid "//TRIM(fct_str(il_dimid(ji))) )
+         ENDDO
+         il_status = NF90_DEF_VAR(td_file%i_id, TRIM(td_var%c_name),     &
+         &                        td_var%i_type,                         &
+         &                        il_dimid(1:jj),                        &
+         &                        varid=iom_cdf__write_var_def           )
+         CALL iom_cdf__check(il_status)
+      ENDIF
+
+      DO ji = 1, td_var%i_natt
+         CALL logger_debug( &
+         &  " WRITE FILE VAR DEF: put attribute "//TRIM(td_var%t_att(ji)%c_name)//&
+         &  " for variable "//TRIM(td_var%c_name)//&
+         &  " in file "//TRIM(td_file%c_name) )
+
+         IF( td_var%t_att(ji)%i_type == NF90_CHAR )THEN
+            !IF( TRIM(td_var%t_att(ji)%c_value) /= 'unknown' )THEN
+            IF( TRIM(td_var%t_att(ji)%c_value) /= '' )THEN
+               il_status = NF90_PUT_ATT(td_file%i_id, iom_cdf__write_var_def, &
+               &                        TRIM(td_var%t_att(ji)%c_name),        &
+               &                        TRIM(td_var%t_att(ji)%c_value)        )
+               CALL iom_cdf__check(il_status)
+            ENDIF
+         ELSE
+            SELECT CASE(td_var%t_att(ji)%i_type)
+               CASE(NF90_BYTE)
+                  il_status = NF90_PUT_ATT(td_file%i_id,                   &
+                  &                        iom_cdf__write_var_def,         &
+                  &                        TRIM(td_var%t_att(ji)%c_name),  &
+                  &                        INT(td_var%t_att(ji)%d_value(:),i1))
+               CASE(NF90_SHORT)
+                  il_status = NF90_PUT_ATT(td_file%i_id,                   &
+                  &                        iom_cdf__write_var_def,         &
+                  &                        TRIM(td_var%t_att(ji)%c_name),  &
+                  &                        INT(td_var%t_att(ji)%d_value(:),i2))
+               CASE(NF90_INT)
+                  il_status = NF90_PUT_ATT(td_file%i_id,                   &
+                  &                        iom_cdf__write_var_def,         &
+                  &                        TRIM(td_var%t_att(ji)%c_name),  &
+                  &                        INT(td_var%t_att(ji)%d_value(:),i4))
+               CASE(NF90_FLOAT)
+                  il_status = NF90_PUT_ATT(td_file%i_id,                   &
+                  &                        iom_cdf__write_var_def,         &
+                  &                        TRIM(td_var%t_att(ji)%c_name),  &
+                  &                        REAL(td_var%t_att(ji)%d_value(:),sp))
+               CASE(NF90_DOUBLE)
+                  il_status = NF90_PUT_ATT(td_file%i_id,                   &
+                  &                        iom_cdf__write_var_def,         &
+                  &                        TRIM(td_var%t_att(ji)%c_name),  &
+                  &                        REAL(td_var%t_att(ji)%d_value(:),dp))
+               END SELECT
+            CALL iom_cdf__check(il_status)
+         ENDIF
+      ENDDO
+
+   END FUNCTION iom_cdf__write_var_def
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine put variable value in an opened netcdf file.
+   !
+   !> @details
+   !> The variable is written in the type define in variable structure.
+   !> Only dimension used are printed, and fillValue in table are
+   !> replaced by default fill values defined in module netcdf for each type. 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] td_var : variable structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_cdf__write_var_value(td_file, td_var)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_file
+      TYPE(TVAR),  INTENT(IN) :: td_var
+
+      ! local variable
+      INTEGER(i4)                       :: il_status
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_order
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_shape
+      REAL(dp),    DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      ! loop indices
+      INTEGER(i4) :: ji, jj
+      !----------------------------------------------------------------
+
+      ! check which dimension use
+      CALL logger_debug( &
+      &  " WRITE FILE VAR VALUE: get dimension to be used for variable "//&
+      &  TRIM(td_var%c_name)//" in file "//TRIM(td_file%c_name))
+
+      jj=0
+      DO ji = 1, ip_maxdim
+         IF( td_var%t_dim(ji)%l_use )THEN
+            jj=jj+1
+            !il_order(ji)=jj
+            !il_shape(ji)=td_var%t_dim(jj)%i_len
+            il_order(jj)=ji
+            il_shape(jj)=td_var%t_dim(ji)%i_len
+         ENDIF
+      ENDDO
+      ! dimension not use
+      DO ji = 1, ip_maxdim
+         IF( .NOT. td_var%t_dim(ji)%l_use )THEN
+            jj=jj+1
+            !il_order(ji)=jj
+            !il_shape(ji)=td_var%t_dim(jj)%i_len
+            il_order(jj)=ji
+            il_shape(jj)=td_var%t_dim(ji)%i_len
+         ENDIF
+      ENDDO
+
+      ALLOCATE( dl_value( il_shape(1),il_shape(2),il_shape(3),il_shape(4) ) )
+
+      ! reshape table, so unused dimension won't be written
+      dl_value(:,:,:,:)=RESHAPE(source=td_var%d_value(:,:,:,:),&
+      &                         SHAPE = il_shape(:), &
+      &                         ORDER = il_order(:))
+
+      ! put value
+      CALL logger_debug( &
+      &  " WRITE FILE VAR VALUE: put "//TRIM(td_var%c_name)//" value "//&
+      &  "in file "//TRIM(td_file%c_name))
+
+      il_status = NF90_PUT_VAR( td_file%i_id, td_var%i_id, dl_value(:,:,:,:))
+      CALL iom_cdf__check(il_status)
+
+      DEALLOCATE( dl_value )
+
+   END SUBROUTINE iom_cdf__write_var_value
+   !> @endcode
+END MODULE iom_cdf
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/iom_mpp.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/iom_mpp.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/iom_mpp.f90	(revision 4245)
@@ -0,0 +1,1323 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: iom_mpp
+!
+! DESCRIPTION:
+!> @brief massively parallel processing Input/Output manager :  
+!> Library to read/write mpp files<br/>
+!>
+!> @details
+!> 
+!>    to open mpp files (only file to be used (see mpp_get_use) 
+!>    will be open):<br/>
+!>    CALL iom_mpp_open(td_mpp)
+!>       - td_mpp is a mpp structure
+!>
+!>    to creates mpp files:<br/>
+!>    CALL iom_mpp_create(td_mpp)
+!>       - td_mpp is a mpp structure
+!>
+!>    to write in mpp files :<br/>
+!>    CALL  iom_mpp_write_file(td_mpp)
+!>       - td_mpp is a mpp structure
+!>
+!>    to close mpp files:<br/>
+!>    CALL iom_mpp_close(td_mpp)
+!>
+!>    to read one variable in an mpp files:<br/>
+!>    - tl_var=iom_mpp_read_var( td_mpp, id_varid, [td_dom,] [ld_border] ) 
+!>    - tl_var=iom_mpp_read_var( td_mpp, [cd_name,] [td_dom,] [ld_border,] [cd_stdname] ) 
+!>       - td_mpp is a mpp structure
+!>       - id_varid is a variable id
+!>       - td_dom is a domain structure (optional, can't be used with ld_border)
+!>       - ld_border is true if we want to read border of global domain only
+!>       (optional, can't be used with td_dom)
+!>       - cd_name is variable name (optional, cd_name and/or cd_stdname should be specify.)
+!>       - cd_stdname is variable standard name (optional, cd_name and/or cd_stdname should be specify.)
+!>
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!> @todo
+!> - add read var with start and count as in iom
+!> - add iom_mpp_fill_var_value : cf iom_fill_var_value 
+!> - not so easy to use that it should be, have to work on it
+!> - improve mpp init
+!> - improve mpp_get_use
+!> - imporve dom_init
+!----------------------------------------------------------------------
+MODULE iom_mpp
+   USE netcdf                          ! nf90 library
+   USE kind                            ! F90 kind parameter
+   USE fct                             ! basic useful function
+   USE logger                             ! log file manager
+   USE dim                             ! dimension manager
+   USE att                             ! attribute manager
+   USE var                             ! variable manager
+   USE file                            ! file manager
+   USE iom                             ! I/O manager
+   USE mpp                             ! mpp manager
+   USE dom                             ! domain manager
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! function and subroutine
+   PUBLIC :: iom_mpp_open                    !< open files composing mpp structure to be used
+   PUBLIC :: iom_mpp_create                  !< creates files composing mpp structure to be used
+   PUBLIC :: iom_mpp_close                   !< close file composing mpp structure
+   PUBLIC :: iom_mpp_read_var                !< read one variable in an mpp structure
+   PUBLIC :: iom_mpp_fill_var                !< fill variable value in mpp structure
+   PUBLIC :: iom_mpp_write_file              !< write mpp structure in files
+
+   PRIVATE :: iom_mpp__read_var_id           !< read one variable in an mpp structure, given variable id
+   PRIVATE :: iom_mpp__read_var_name         !< read one variable in an mpp structure, given variable name
+   PRIVATE :: iom_mpp__read_var_value        !< read variable value in an mpp structure
+   PRIVATE :: iom_mpp__no_pole_no_overlap    !< do not overlap north fold boundary or east-west boundary
+   PRIVATE :: iom_mpp__no_pole_cyclic        !< do not overlap north fold boundary. However uses cyclic east-west boundary
+   PRIVATE :: iom_mpp__no_pole_overlap       !< do not overlap north fold boundary. However overlaps east-west boundary
+!   PRIVATE :: iom_mpp__pole_no_overlap       !< overlaps north fold boundary. However do not overlap east-west boundary
+!   PRIVATE :: iom_mpp__pole_cyclic           !< overlaps north fold boundary and uses cyclic east-west boundary
+!   PRIVATE :: iom_mpp__pole_overlap          !< overlaps north fold boundary and east-west boundary
+
+   INTERFACE iom_mpp_read_var                   !< read one variable in an mpp structure
+      MODULE PROCEDURE iom_mpp__read_var_id     !< given variable id
+      MODULE PROCEDURE iom_mpp__read_var_name   !< given variable name 
+   END INTERFACE iom_mpp_read_var
+
+   INTERFACE iom_mpp_fill_var                !< fill variable value in an mpp structure
+      MODULE PROCEDURE iom_mpp__fill_var_id   !< given variable id
+      MODULE PROCEDURE iom_mpp__fill_var_name !< given variable name
+      MODULE PROCEDURE iom_mpp__fill_var_all  !< fill all variable
+   END INTERFACE iom_mpp_fill_var
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief This subroutine open files composing mpp structure to be used<br/>
+   !> If try to open a file in write mode that did not exist, create it.<br/>
+   !> 
+   !> If file already exist, get information about:
+   !> - the number of variables
+   !> - the number of dimensions
+   !> - the number of global attributes
+   !> - the ID of the unlimited dimension
+   !> - the file format
+   !> and finally read dimensions.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_mpp : mpp structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_mpp_open(td_mpp)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP), INTENT(INOUT)  :: td_mpp
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_name
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( " IOM MPP OPEN: domain decomposition not define "//&
+         &               " in mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+         IF( ANY(td_mpp%t_proc(:)%l_use) )THEN
+
+            ! add suffix to mpp name
+            td_mpp%c_name=file_add_suffix( TRIM(td_mpp%c_name), &
+                                         & TRIM(td_mpp%c_type) )
+
+            td_mpp%t_proc(:)%c_type=TRIM(td_mpp%c_type) 
+            IF( td_mpp%i_nproc > 1 )THEN
+               DO ji=1,td_mpp%i_nproc
+                  IF( td_mpp%t_proc(ji)%l_use )THEN
+
+                     cl_name=TRIM( file_rename(td_mpp%c_name, ji) )
+                     td_mpp%t_proc(ji)%c_name=TRIM(cl_name)
+
+                     CALL iom_open(td_mpp%t_proc(ji))
+
+                  ENDIF
+               ENDDO
+            ELSE ! td_mpp%i_nproc == 1 
+                  cl_name=TRIM( file_rename(td_mpp%c_name) )
+                  td_mpp%t_proc(1)%c_name=TRIM(cl_name)
+
+                  CALL iom_open(td_mpp%t_proc(1))
+            ENDIF
+
+         ELSE
+
+            IF( ANY(td_mpp%t_proc(:)%l_ctr) )THEN
+
+               CALL logger_warn("IOM MPP OPEN: open file on border")
+               DO ji=1,td_mpp%i_nproc
+                  IF( td_mpp%t_proc(ji)%l_ctr )THEN
+                     CALL iom_open(td_mpp%t_proc(ji))
+                  ENDIF
+               ENDDO
+
+            ELSE
+               CALL logger_error( " IOM MPP OPEN: no processor to be used.")
+               CALL logger_debug( " use mpp_get_use before running iom_mpp_open")
+            ENDIF
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE iom_mpp_open
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine create files, composing mpp structure to be used,
+   !> in write mode<br/>
+   !> 
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_mpp : mpp structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_mpp_create(td_mpp)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP), INTENT(INOUT)  :: td_mpp
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( " IOM MPP CREATE: domain decomposition not define "//&
+         &               " in mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+         ! forced to open in write mode
+         td_mpp%t_proc(:)%l_wrt=.TRUE.
+         td_mpp%t_proc(:)%l_use=.TRUE.
+         CALL iom_mpp_open(td_mpp)
+      ENDIF
+
+   END SUBROUTINE iom_mpp_create
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine close files composing mpp structure.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp : mpp structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_mpp_close(td_mpp)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP), INTENT(INOUT) :: td_mpp
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( " IOM MPP CLOSE: domain decomposition not define "//&
+         &               " in mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+         DO ji=1,td_mpp%i_nproc
+            IF( td_mpp%t_proc(ji)%i_id /= 0 )THEN
+               CALL iom_close(td_mpp%t_proc(ji))
+            ENDIF
+         ENDDO
+      ENDIF
+
+   END SUBROUTINE iom_mpp_close
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read variable value in opened mpp files,
+   !> given variable id.</br/>
+   !>
+   !> @details
+   !> If domain is given, read only domain.
+   !> If border is .TRUE., read only border processor   
+   !>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp : mpp structure
+   !> @param[in] id_varid : variable id
+   !> @param[in] td_dom : domain structure
+   !> @param[in] ld_border : read only border
+   !> @return  variable structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION iom_mpp__read_var_id(td_mpp, id_varid,&
+   &                                        td_dom, ld_border)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP),    INTENT(IN) :: td_mpp
+      INTEGER(i4),   INTENT(IN) :: id_varid
+      TYPE(TDOM) ,   INTENT(IN), OPTIONAL :: td_dom
+      LOGICAL,       INTENT(IN), OPTIONAL :: ld_border
+
+      ! local variable
+      INTEGER(i4), DIMENSION(1) :: il_ind
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( " IOM MPP READ VAR: domain decomposition not define "//&
+         &               " in mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+
+         IF( ANY(td_mpp%t_proc(:)%i_id /= 0) )THEN
+            ! look for variable id
+            il_ind(:)=MINLOC( td_mpp%t_proc(1)%t_var(:)%i_id, &
+            &           mask=(td_mpp%t_proc(1)%t_var(:)%i_id==id_varid))
+            IF( il_ind(1) /= 0 )THEN
+
+               iom_mpp__read_var_id=td_mpp%t_proc(1)%t_var(il_ind(1))
+
+               !!! read variable value
+               CALL iom_mpp__read_var_value(td_mpp, iom_mpp__read_var_id, &
+               &                            td_dom, ld_border)
+
+            ELSE
+               CALL logger_error( &
+               &  " IOM MPP READ VAR: there is no variable with id "//&
+               &  TRIM(fct_str(id_varid))//" in processor/file "//&
+               &  TRIM(td_mpp%t_proc(1)%c_name))
+            ENDIF
+         ELSE
+            CALL logger_error(" IOM MPP READ VAR: can't read variable, mpp "//&
+            &  TRIM(td_mpp%c_name)//" not opened")
+         ENDIF
+
+      ENDIF
+
+   END FUNCTION iom_mpp__read_var_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read variable value in opened mpp files, 
+   !> given variable name or standard name.</br/>
+   !> @details
+   !> If domain is given, read only domain.
+   !> If border is .TRUE., read only border processor
+   !
+   !> @details
+   !> look first for variable name. If it doesn't
+   !> exist in file, look for variable standard name.<br/>
+   !> If variable name is not present, check variable standard name.<br/>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp : mpp structure
+   !> @param[in] cd_name : variable name
+   !> @param[in] td_dom : domain structure
+   !> @param[in] ld_border : read only border 
+   !> @return  variable structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION iom_mpp__read_var_name(td_mpp, cd_name,    &
+   &                                          td_dom, ld_border   )
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP),       INTENT(IN) :: td_mpp
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+      TYPE(TDOM) ,      INTENT(IN), OPTIONAL :: td_dom
+      LOGICAL,          INTENT(IN), OPTIONAL :: ld_border
+
+      ! local variable
+      INTEGER(i4)       :: il_varid
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( " IOM MPP READ VAR: domain decomposition not define "//&
+         &               " in mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+
+            il_varid=var_get_id( td_mpp%t_proc(1)%t_var(:), cd_name)
+            IF( il_varid /= 0 )THEN
+
+               iom_mpp__read_var_name=td_mpp%t_proc(1)%t_var(il_varid)
+
+               !!! read variable value
+               CALL iom_mpp__read_var_value( td_mpp, &
+               &                             iom_mpp__read_var_name, &
+               &                             td_dom, ld_border)
+
+            ELSE
+
+               CALL logger_error( &
+               &  " IOM MPP READ VAR: there is no variable with "//&
+               &  "name or standard name"//TRIM(cd_name)//&
+               &  " in processor/file "//TRIM(td_mpp%t_proc(1)%c_name))
+            ENDIF
+
+      ENDIF
+      
+   END FUNCTION iom_mpp__read_var_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill all variable value in opened mpp files,
+   !> given variable id.</br/>
+   !>
+   !> @details
+   !> If domain is given, read only domain.
+   !> If border is .TRUE., read only border processor   
+   !> 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_mpp : mpp structure
+   !> @param[in] td_dom : domain structure
+   !> @param[in] ld_border : read only border
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_mpp__fill_var_all(td_mpp, td_dom, ld_border)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP),    INTENT(INOUT) :: td_mpp
+      TYPE(TDOM) ,   INTENT(IN),   OPTIONAL :: td_dom
+      LOGICAL,       INTENT(IN),   OPTIONAL :: ld_border
+
+      ! local variable
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( " IOM MPP FILL VAR : domain decomposition not define "//&
+         &               " in mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+
+         DO ji=1,td_mpp%t_proc(1)%i_nvar
+            CALL iom_mpp_fill_var(td_mpp, ji, td_dom, ld_border )
+         ENDDO
+
+      ENDIF
+
+   END SUBROUTINE iom_mpp__fill_var_all
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill variable value in opened mpp files,
+   !> given variable id.</br/>
+   !>
+   !> @details
+   !> If domain is given, read only domain.
+   !> If border is .TRUE., read only border processor   
+   !> 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_mpp : mpp structure
+   !> @param[in] id_varid : variable id
+   !> @param[in] td_dom : domain structure
+   !> @param[in] ld_border : read only border
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_mpp__fill_var_id(td_mpp, id_varid, td_dom, ld_border)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP),    INTENT(INOUT) :: td_mpp
+      INTEGER(i4),   INTENT(IN)    :: id_varid
+      TYPE(TDOM) ,   INTENT(IN),   OPTIONAL :: td_dom
+      LOGICAL,       INTENT(IN),   OPTIONAL :: ld_border
+
+      ! local variable
+      INTEGER(i4), DIMENSION(1) :: il_ind
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( " IOM MPP FILL VAR: domain decomposition not define "//&
+         &               " in mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+
+         IF( ANY(td_mpp%t_proc(:)%i_id /= 0) )THEN
+            ! look for variable id
+            il_ind(:)=MINLOC( td_mpp%t_proc(1)%t_var(:)%i_id, &
+            &           mask=(td_mpp%t_proc(1)%t_var(:)%i_id==id_varid))
+            IF( il_ind(1) /= 0 )THEN
+
+               !!! read variable value
+               CALL iom_mpp__read_var_value( td_mpp, &
+               &                     td_mpp%t_proc(1)%t_var(il_ind(1)), &
+               &                     td_dom, ld_border)
+
+            ELSE
+               CALL logger_error( &
+               &  " IOM MPP FILL VAR : there is no variable with id "//&
+               &  TRIM(fct_str(id_varid))//" in processor/file "//&
+               &  TRIM(td_mpp%t_proc(1)%c_name))
+            ENDIF
+         ELSE
+            CALL logger_error(" IOM MPP FILL VAR : can't read variable, mpp "//&
+            &  TRIM(td_mpp%c_name)//" not opened")
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE iom_mpp__fill_var_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill variable value in opened mpp files, 
+   !> given variable name or standard name.</br/>
+   !> @details
+   !> If domain is given, read only domain.
+   !> If border is .TRUE., read only border processor   
+   !
+   !> @details
+   !> look first for variable name. If it doesn't
+   !> exist in file, look for variable standard name.<br/>
+   !> If variable name is not present, check variable standard name.<br/>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_mpp : mpp structure
+   !> @param[in] cd_name : variable name or standard name
+   !> @param[in] td_dom : domain structure
+   !> @param[in] ld_border : read only border 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_mpp__fill_var_name(td_mpp, cd_name, td_dom, ld_border )
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP),       INTENT(INOUT) :: td_mpp
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_name
+      TYPE(TDOM) ,      INTENT(IN   ), OPTIONAL :: td_dom
+      LOGICAL,          INTENT(IN   ), OPTIONAL :: ld_border
+
+      ! local variable
+      INTEGER(i4)       :: il_ind
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( " IOM MPP FILL VAR : domain decomposition not define "//&
+         &               " in mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+
+            il_ind=var_get_id( td_mpp%t_proc(1)%t_var(:), cd_name, cd_name)
+            IF( il_ind /= 0 )THEN
+
+               !!! read variable value
+               CALL iom_mpp__read_var_value(td_mpp, &
+               &                    td_mpp%t_proc(1)%t_var(il_ind), &
+               &                    td_dom, ld_border)
+
+            ELSE
+
+               CALL logger_error( &
+               &  " IOM MPP FILL VAR : there is no variable with "//&
+               &  "name or standard name "//TRIM(cd_name)//&
+               &  " in processor/file "//TRIM(td_mpp%t_proc(1)%c_name))
+
+            ENDIF
+
+      ENDIF
+      
+   END SUBROUTINE iom_mpp__fill_var_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read variable value
+   !> in an mpp structure.
+   !>
+   !> @details
+   !> If domain is given, read only domain.
+   !> If border is .TRUE., read only border processor
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp    : mpp structure
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_dom    : domain structure
+   !> @param[in] ld_border : read only border
+   !> @return variable structure completed 
+   !
+   !> @todo
+   !> - modif en fonction dimension de la variable lu pour cas dom
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_mpp__read_var_value(td_mpp, td_var, &
+   &                                  td_dom, ld_border )
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP),   INTENT(IN)    :: td_mpp
+      TYPE(TVAR),   INTENT(INOUT) :: td_var
+      TYPE(TDOM),   INTENT(IN),   OPTIONAL :: td_dom
+      LOGICAL,      INTENT(IN),   OPTIONAL :: ld_border
+
+      ! local variable
+      INTEGER(i4)                       :: il_status
+      INTEGER(i4), DIMENSION(4)         :: il_ind
+      INTEGER(i4)                       :: il_i1p
+      INTEGER(i4)                       :: il_i2p
+      INTEGER(i4)                       :: il_j1p
+      INTEGER(i4)                       :: il_j2p
+
+      LOGICAL                           :: ll_border
+      TYPE(TVAR)                        :: tl_var
+      TYPE(TMPP)                        :: tl_mpp
+      TYPE(TDOM)                        :: tl_dom
+
+      ! loop indices
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      ll_border=.FALSE.
+      IF( PRESENT(ld_border) ) ll_border=ld_border
+      ! check td_dom and ld_border optionals parameters...
+      IF( ll_border .AND. PRESENT(td_dom) )THEN
+         CALL logger_error( "IOM MPP READ VAR VALUE: &
+         &                domain and border can't be both specify")
+      ENDIF
+
+      IF( ll_border )THEN
+           
+         ! copy mpp structure
+         tl_mpp=td_mpp
+         ! forced to keep same id
+         tl_mpp%t_proc(:)%i_id=td_mpp%t_proc(:)%i_id
+
+         IF( ALL(td_mpp%t_proc(:)%l_ctr) )THEN
+            CALL logger_warn( "IOM MPP READ VAR VALUE: &
+            &               contour not define. look for it")
+            ! get contour
+            CALL mpp_get_contour( tl_mpp )
+         ENDIF
+         
+         ! Allocate space to hold variable value in structure
+         IF( ASSOCIATED(td_var%d_value) )THEN
+            DEALLOCATE(td_var%d_value)   
+         ENDIF
+
+         DO jk=1,ip_maxdim
+            IF( .NOT. td_var%t_dim(jk)%l_use ) tl_mpp%t_dim(jk)%i_len = 1
+         ENDDO
+  
+         ! use mpp global dimension 
+         td_var%t_dim(:)%i_len=tl_mpp%t_dim(:)%i_len
+
+         ALLOCATE(td_var%d_value( td_var%t_dim(1)%i_len, &
+         &                        td_var%t_dim(2)%i_len, &
+         &                        td_var%t_dim(3)%i_len, &
+         &                        td_var%t_dim(4)%i_len),&
+         &        stat=il_status)
+         IF(il_status /= 0 )THEN
+
+           CALL logger_error( &
+            &  " IOM MPP READ VAR VALUE: not enough space to put variable "//&
+            &  TRIM(td_var%c_name)//&
+            &  " in variable structure")
+
+         ENDIF
+
+         ! read border processor
+         DO jk=1,tl_mpp%i_nproc
+            IF( tl_mpp%t_proc(jk)%l_ctr )THEN
+                
+               CALL logger_debug(" IOM MPP READ VAR VALUE: name "//TRIM(td_var%c_name) )
+               CALL logger_debug(" IOM MPP READ VAR VALUE: ndim "//TRIM(fct_str(td_var%i_ndim)) )
+               tl_var=iom_read_var( tl_mpp%t_proc(jk), td_var%c_name )
+
+               ! get processor indices
+               il_ind(:)=mpp_get_proc_index( tl_mpp, jk )
+               il_i1p = il_ind(1)
+               il_i2p = il_ind(2)
+               il_j1p = il_ind(3)
+               il_j2p = il_ind(4)
+
+               IF( .NOT. td_var%t_dim(1)%l_use )THEN
+                  il_i1p=1 
+                  il_i2p=1 
+               ENDIF
+
+               IF( .NOT. td_var%t_dim(2)%l_use )THEN
+                  il_j1p=1 
+                  il_j2p=1 
+               ENDIF
+
+               ! replace value in mpp domain
+               td_var%d_value(il_i1p:il_i2p,il_j1p:il_j2p,:,:) = &
+               &  tl_var%d_value(:,:,:,:)
+
+               ! clean variable
+               CALL var_clean(tl_var)
+            ENDIF
+         ENDDO
+
+      ENDIF
+
+      IF( PRESENT(td_dom) )THEN
+
+         ! copy mpp structure
+         tl_mpp=td_mpp
+         ! forced to keep same id
+         tl_mpp%t_proc(:)%i_id=td_mpp%t_proc(:)%i_id         
+
+         IF( ALL(.NOT. td_mpp%t_proc(:)%l_use) )THEN
+            CALL logger_warn( "IOM MPP READ VAR VALUE: &
+            &               processor to be used not defined. look for it")
+            ! get processor to be used
+            CALL mpp_get_use( tl_mpp, td_dom )
+         ENDIF
+
+         ! Allocate space to hold variable value in structure
+         IF( ASSOCIATED(td_var%d_value) )THEN
+            DEALLOCATE(td_var%d_value)   
+         ENDIF
+         
+         tl_dom=td_dom
+         DO jk=1,ip_maxdim
+            IF( .NOT. td_var%t_dim(jk)%l_use ) tl_dom%t_dim(jk)%i_len = 1
+         ENDDO
+
+         ! use domain dimension 
+         td_var%t_dim(1:2)%i_len=tl_dom%t_dim(1:2)%i_len
+
+         ALLOCATE(td_var%d_value( tl_dom%t_dim(1)%i_len, &
+         &                        tl_dom%t_dim(2)%i_len, &
+         &                        td_var%t_dim(3)%i_len, &
+         &                        td_var%t_dim(4)%i_len),&
+         &        stat=il_status)
+         IF(il_status /= 0 )THEN
+
+           CALL logger_error( &
+            &  " IOM MPP READ VAR VALUE: not enough space to put variable "//&
+            &  TRIM(td_var%c_name)//&
+            &  " in variable structure")
+
+         ENDIF
+         CALL logger_debug("IOM MPP READ VAR VALUE: shape ("//&
+         &  TRIM(fct_str(SIZE(td_var%d_value(:,:,:,:),DIM=1)))//","//&
+         &  TRIM(fct_str(SIZE(td_var%d_value(:,:,:,:),DIM=2)))//","//&
+         &  TRIM(fct_str(SIZE(td_var%d_value(:,:,:,:),DIM=3)))//","//&
+         &  TRIM(fct_str(SIZE(td_var%d_value(:,:,:,:),DIM=4)))//")" )         
+         ! FillValue by default
+         td_var%d_value(:,:,:,:)=td_var%d_fill
+
+         IF( tl_dom%i_jmin < tl_dom%i_jmax )THEN
+         ! no north pole
+
+            IF( tl_dom%i_imin == 1 .AND. &
+            &   tl_dom%i_imax == tl_dom%t_dim0(1)%i_len )THEN
+            ! east west cyclic
+
+               CALL iom_mpp__no_pole_cyclic(tl_mpp, td_var, tl_dom)
+
+            ELSEIF( tl_dom%i_imin < tl_dom%i_imax )THEN
+            ! no east west overlap
+               
+               CALL iom_mpp__no_pole_no_overlap(tl_mpp, td_var, tl_dom)
+
+               ! no more EW overlap in variable
+               td_var%i_ew=-1
+
+            ELSEIF( tl_dom%i_imin > tl_dom%i_imax )THEN
+            ! east west overlap
+
+               CALL iom_mpp__no_pole_overlap(tl_mpp, td_var, tl_dom)
+
+               ! no more EW overlap in variable
+               td_var%i_ew=-1
+
+            ELSE
+
+               CALL logger_error(" IOM MPP READ VAR VALUE: invalid domain definition.")
+
+            ENDIF
+
+         ELSE ! tl_dom%i_jmin >= tl_dom%i_jmax
+         ! north pole
+
+         CALL logger_error("IOM MPP READ VAR VALUE: siren is not able to do so now "//&
+         &  "maybe in the next release")
+         !   IF( tl_dom%i_imin < tl_dom%i_imax )THEN
+         !   ! no east west overlap
+
+         !      CALL iom_mpp__pole_no_overlap(tl_mpp, td_var, tl_dom)
+
+         !   ELSEIF(tl_dom%i_imin == tl_dom%i_imax)THEN
+         !   ! east west cyclic
+
+         !      CALL iom_mpp__pole_cyclic(tl_mpp, td_var, tl_dom)
+
+         !    ELSE ! tl_dom%i_imin > tl_dom%i_imax
+         !    ! east west overlap
+
+         !      CALL iom_mpp__pole_overlap(tl_mpp, td_var, tl_dom)
+
+         !   ENDIF
+         ENDIF
+
+      ENDIF
+
+      ! force to change _FillValue to avoid mistake 
+      ! with dummy zero _FillValue
+      IF( td_var%d_fill == 0._dp )THEN
+         CALL var_chg_FillValue(td_var)
+      ENDIF      
+
+   END SUBROUTINE iom_mpp__read_var_value
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read variable value
+   !> in an mpp structure. The output domain do not overlap
+   !> north fold boundary or east-west boundary.
+   !>
+   !> @details
+   !> If domain is given, read only domain.
+   !> If border is .TRUE., read only border processor
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp    : mpp structure
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_dom    : domain structure
+   !> @return variable structure completed 
+   !
+   !> @todo
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_mpp__no_pole_no_overlap(td_mpp, td_var, td_dom )
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP),  INTENT(IN)    :: td_mpp
+      TYPE(TVAR),  INTENT(INOUT) :: td_var
+      TYPE(TDOM),  INTENT(IN),   OPTIONAL :: td_dom
+
+      ! local variable
+      INTEGER(i4), DIMENSION(4) :: il_ind
+      INTEGER(i4)               :: il_i1p
+      INTEGER(i4)               :: il_j1p
+      INTEGER(i4)               :: il_i2p
+      INTEGER(i4)               :: il_j2p
+
+      INTEGER(i4)               :: il_i1
+      INTEGER(i4)               :: il_j1
+      INTEGER(i4)               :: il_i2
+      INTEGER(i4)               :: il_j2
+
+      INTEGER(i4), DIMENSION(4) :: il_start
+      INTEGER(i4), DIMENSION(4) :: il_count
+      TYPE(TVAR)                :: tl_var
+      TYPE(TDOM)                :: tl_dom
+
+      ! loop indices
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+      
+      ! change dimension length if not use
+      tl_dom=td_dom
+      IF( .NOT. td_var%t_dim(1)%l_use )THEN 
+         tl_dom%i_imin=1 ; tl_dom%i_imax=1
+      ENDIF
+      IF( .NOT. td_var%t_dim(2)%l_use )THEN 
+         tl_dom%i_jmin=1 ; tl_dom%i_jmax=1
+      ENDIF
+!      IF( .NOT. td_var%t_dim(3)%l_use )THEN 
+!         tl_dom%i_kmin=1 ; tl_dom%i_kmax=1
+!      ENDIF
+!      IF( .NOT. td_var%t_dim(4)%l_use )THEN 
+!         tl_dom%i_lmin=1 ; tl_dom%i_lmax=1
+!      ENDIF
+
+      ! read processor 
+      DO jk=1,td_mpp%i_nproc
+         IF( td_mpp%t_proc(jk)%l_use )THEN
+
+            ! get processor indices
+            il_ind(:)=mpp_get_proc_index( td_mpp, jk )
+            il_i1p = il_ind(1)
+            il_i2p = il_ind(2)
+            il_j1p = il_ind(3)
+            il_j2p = il_ind(4)
+
+            IF( .NOT. td_var%t_dim(1)%l_use )THEN
+               il_i1p=tl_dom%i_imin ; il_i2p=tl_dom%i_imax
+            ENDIF
+            IF( .NOT. td_var%t_dim(2)%l_use )THEN
+               il_j1p=tl_dom%i_jmin ; il_j2p=tl_dom%i_jmax
+            ENDIF
+
+            il_i1=MAX(il_i1p, tl_dom%i_imin)
+            il_i2=MIN(il_i2p, tl_dom%i_imax)
+
+            il_j1=MAX(il_j1p, tl_dom%i_jmin)
+            il_j2=MIN(il_j2p, tl_dom%i_jmax)
+
+            IF( (il_i1<=il_i2).AND.(il_j1<=il_j2) )THEN
+
+               il_start(:)=(/ il_i1-il_i1p+1, &
+               &              il_j1-il_j1p+1, &
+               &              1,1 /)
+!               &              tl_dom%i_kmin,  &
+!               &              tl_dom%i_lmin /)
+
+               il_count(:)=(/ il_i2-il_i1+1,         &
+               &              il_j2-il_j1+1,         &
+               &              td_var%t_dim(3)%i_len, &
+               &              td_var%t_dim(4)%i_len /)
+!               &              tl_dom%t_dim(3)%i_len, &
+!               &              tl_dom%t_dim(4)%i_len /)
+
+               tl_var=iom_read_var( td_mpp%t_proc(jk), td_var%c_name,&
+               &                    il_start(:), il_count(:) )
+
+               ! replace value in output variable structure
+               td_var%d_value( il_i1 - tl_dom%i_imin + 1 : &
+               &               il_i2 - tl_dom%i_imin + 1, &
+               &               il_j1 - tl_dom%i_jmin + 1 : &
+               &               il_j2 - tl_dom%i_jmin + 1, &
+               &               :,:) = tl_var%d_value(:,:,:,:)
+
+            ENDIF
+
+         ENDIF
+      ENDDO
+
+   END SUBROUTINE iom_mpp__no_pole_no_overlap
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read variable value
+   !> in an mpp structure. The output domain do not overlap north fold boundary.
+   !> However it uses cyclic east-west boundary.
+   !>
+   !> @details
+   !> If domain is given, read only domain.
+   !> If border is .TRUE., read only border processor
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp    : mpp structure
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_dom    : domain structure
+   !> @return variable structure completed 
+   !
+   !> @todo
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_mpp__no_pole_cyclic(td_mpp, td_var, td_dom )
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP),   INTENT(IN   ) :: td_mpp
+      TYPE(TVAR),   INTENT(INOUT) :: td_var
+      TYPE(TDOM),   INTENT(IN   ), OPTIONAL :: td_dom
+
+      ! local variable
+      INTEGER(i4), DIMENSION(4) :: il_ind
+      INTEGER(i4)               :: il_i1p
+      INTEGER(i4)               :: il_j1p
+      INTEGER(i4)               :: il_i2p
+      INTEGER(i4)               :: il_j2p
+
+      INTEGER(i4)               :: il_i1
+      INTEGER(i4)               :: il_j1
+      INTEGER(i4)               :: il_i2
+      INTEGER(i4)               :: il_j2
+
+      INTEGER(i4), DIMENSION(4) :: il_start
+      INTEGER(i4), DIMENSION(4) :: il_count
+      TYPE(TVAR)                :: tl_var
+      TYPE(TDOM)                :: tl_dom
+
+      ! loop indices
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      ! change dimension length if not use
+      tl_dom=td_dom
+      IF( .NOT. td_var%t_dim(1)%l_use )THEN 
+         tl_dom%i_imin=1 ; tl_dom%i_imax=1
+      ENDIF
+      IF( .NOT. td_var%t_dim(2)%l_use )THEN 
+         tl_dom%i_jmin=1 ; tl_dom%i_jmax=1
+      ENDIF
+!      IF( .NOT. td_var%t_dim(3)%l_use )THEN 
+!         tl_dom%i_kmin=1 ; tl_dom%i_kmax=1
+!      ENDIF
+!      IF( .NOT. td_var%t_dim(4)%l_use )THEN 
+!         tl_dom%i_lmin=1 ; tl_dom%i_lmax=1
+!      ENDIF
+
+      ! read processor 
+      DO jk=1,td_mpp%i_nproc
+         IF( td_mpp%t_proc(jk)%l_use )THEN
+             
+            ! get processor indices
+            il_ind(:)=mpp_get_proc_index( td_mpp, jk )
+            il_i1p = il_ind(1)
+            il_i2p = il_ind(2)
+            il_j1p = il_ind(3)
+            il_j2p = il_ind(4)
+
+            IF( .NOT. td_var%t_dim(1)%l_use )THEN
+               il_i1p=tl_dom%i_imin ; il_i2p=tl_dom%i_imax
+            ENDIF
+            IF( .NOT. td_var%t_dim(2)%l_use )THEN
+               il_j1p=tl_dom%i_jmin ; il_j2p=tl_dom%i_jmax
+            ENDIF
+
+            il_i1=il_i1p
+            il_j1=MAX(il_j1p, td_dom%i_jmin)
+
+            il_i2=il_i2p
+            il_j2=MIN(il_j2p, td_dom%i_jmax)
+
+            IF( (il_i1<=il_i2).AND.(il_j1<=il_j2) )THEN
+
+               il_start(:)=(/ il_i1,          &
+               &              il_j1-il_j1p+1, &
+               &              1,1 /)
+!               &              tl_dom%i_kmin,  &
+!               &              tl_dom%i_lmin /)
+
+               il_count(:)=(/ il_i2-il_i1+1,         &
+               &              il_j2-il_j1+1,         &
+               &              td_var%t_dim(3)%i_len, &
+               &              td_var%t_dim(4)%i_len /)
+!               &              tl_dom%t_dim(3)%i_len, &
+!               &              tl_dom%t_dim(4)%i_len /)
+
+               tl_var=iom_read_var( td_mpp%t_proc(jk), td_var%c_name,&
+               &                    il_start(:), il_count(:) )
+
+               ! replace value in output variable structure
+               td_var%d_value( il_i1 : il_i2,  &
+               &               il_j1 - td_dom%i_jmin + 1 : &
+               &               il_j2 - td_dom%i_jmin + 1,  &
+               &               :,:) = tl_var%d_value(:,:,:,:)
+
+            ENDIF
+
+         ENDIF
+      ENDDO
+
+   END SUBROUTINE iom_mpp__no_pole_cyclic
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read variable value
+   !> in an mpp structure. The output domain do not overlap north fold boundary. 
+   !> However it overlaps east-west boundary. 
+   !>
+   !> @details
+   !> If domain is given, read only domain.
+   !> If border is .TRUE., read only border processor
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp    : mpp structure
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_dom    : domain structure
+   !> @return variable structure completed 
+   !
+   !> @todo
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_mpp__no_pole_overlap(td_mpp, td_var, td_dom )
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP),   INTENT(IN)    :: td_mpp
+      TYPE(TVAR),   INTENT(INOUT) :: td_var
+      TYPE(TDOM),   INTENT(IN),   OPTIONAL :: td_dom
+
+      ! local variable
+      INTEGER(i4), DIMENSION(4) :: il_ind
+      INTEGER(i4)               :: il_i1p
+      INTEGER(i4)               :: il_j1p
+      INTEGER(i4)               :: il_i2p
+      INTEGER(i4)               :: il_j2p
+
+      INTEGER(i4)               :: il_i1
+      INTEGER(i4)               :: il_j1
+      INTEGER(i4)               :: il_i2
+      INTEGER(i4)               :: il_j2
+
+      INTEGER(i4)               :: il_ioffset
+
+      INTEGER(i4), DIMENSION(4) :: il_start
+      INTEGER(i4), DIMENSION(4) :: il_count
+      TYPE(TVAR)                :: tl_var
+      TYPE(TDOM)                :: tl_dom
+
+      ! loop indices
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      il_ioffset  = (td_mpp%t_dim(1)%i_len-2) - td_dom%i_imin + 1
+
+      ! change dimension length if not use
+      tl_dom=td_dom
+      IF( .NOT. td_var%t_dim(1)%l_use )THEN 
+         tl_dom%i_imin=1 ; tl_dom%i_imax=1
+         il_ioffset=0
+      ENDIF
+      IF( .NOT. td_var%t_dim(2)%l_use )THEN 
+         tl_dom%i_jmin=1 ; tl_dom%i_jmax=1
+      ENDIF
+!      IF( .NOT. td_var%t_dim(3)%l_use )THEN 
+!         tl_dom%i_kmin=1 ; tl_dom%i_kmax=1
+!      ENDIF
+!      IF( .NOT. td_var%t_dim(4)%l_use )THEN 
+!         tl_dom%i_lmin=1 ; tl_dom%i_lmax=1
+!      ENDIF
+
+      ! read processor 
+      DO jk=1,td_mpp%i_nproc
+         IF( td_mpp%t_proc(jk)%l_use )THEN
+             
+            ! get processor indices
+            il_ind(:)=mpp_get_proc_index( td_mpp, jk )
+            il_i1p = il_ind(1)
+            il_i2p = il_ind(2)
+            il_j1p = il_ind(3)
+            il_j2p = il_ind(4)
+
+            IF( .NOT. td_var%t_dim(1)%l_use )THEN
+               il_i1p=tl_dom%i_imin ; il_i2p=tl_dom%i_imax
+            ENDIF
+            IF( .NOT. td_var%t_dim(2)%l_use )THEN
+               il_j1p=tl_dom%i_jmin ; il_j2p=tl_dom%i_jmax
+            ENDIF
+            
+            !!!!!! get first part of domain
+            il_i1=MAX(il_i1p, td_dom%i_imin)
+            il_j1=MAX(il_j1p, td_dom%i_jmin)
+
+            il_i2=MIN(il_i2p, td_mpp%t_dim(1)%i_len-td_var%i_ew) ! east-west overlap
+            il_j2=MIN(il_j2p, td_dom%i_jmax)
+
+            IF( (il_i1<=il_i2).AND.(il_j1<=il_j2) )THEN
+
+               il_start(:)=(/ il_i1-il_i1p+1, &
+               &              il_j1-il_j1p+1, &
+               &              1,1 /)
+!               &              tl_dom%i_kmin,  &
+!               &              tl_dom%i_lmin /)
+
+               il_count(:)=(/ il_i2-il_i1+1,         &
+               &              il_j2-il_j1+1,         &
+               &              td_var%t_dim(3)%i_len, &
+               &              td_var%t_dim(4)%i_len /)
+!               &              tl_dom%t_dim(3)%i_len, &
+!               &              tl_dom%t_dim(4)%i_len /)
+
+               tl_var=iom_read_var( td_mpp%t_proc(jk), td_var%c_name,&
+               &                    il_start(:), il_count(:) )
+
+               ! replace value in output variable structure
+               td_var%d_value( il_i1 - td_dom%i_imin + 1 : &
+               &               il_i2 - td_dom%i_imin + 1,  &
+               &               il_j1 - td_dom%i_jmin + 1 : &
+               &               il_j2 - td_dom%i_jmin + 1,  &
+               &               :,:) = tl_var%d_value(:,:,:,:)
+
+            ENDIF
+
+            !!!!! get second part of domain
+            il_i1=MAX(il_i1p, 1)
+            il_j1=MAX(il_j1p, td_dom%i_jmin)
+
+            il_i2=MIN(il_i2p, td_dom%i_imax)
+            il_j2=MIN(il_j2p, td_dom%i_jmax)
+
+            IF( (il_i1<=il_i2).AND.(il_j1<=il_j2) )THEN
+
+               il_start(:)=(/ il_i1,          &
+               &              il_j1-il_j1p+1, &
+               &              1,1 /)
+!               &              tl_dom%i_kmin,  &
+!               &              tl_dom%i_lmin /)
+
+               il_count(:)=(/ il_i2-il_i1+1,         &
+               &              il_j2-il_j1+1,         &
+               &              td_var%t_dim(3)%i_len, &
+               &              td_var%t_dim(4)%i_len /)
+!               &              tl_dom%t_dim(3)%i_len, &
+!               &              tl_dom%t_dim(4)%i_len /)
+
+               tl_var=iom_read_var( td_mpp%t_proc(jk), td_var%c_name,&
+               &                    il_start(:), il_count(:) )
+
+               ! replace value in output variable structure
+               td_var%d_value( il_ioffset + il_i1 :  &
+               &               il_ioffset + il_i2,   &
+               &               il_j1 - td_dom%i_jmin + 1 : &
+               &               il_j2 - td_dom%i_jmin + 1,  &
+               &               :,:) = tl_var%d_value(:,:,:,:)
+
+            ENDIF
+
+         ENDIF
+      ENDDO
+
+   END SUBROUTINE iom_mpp__no_pole_overlap
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read variable value
+   !> in an mpp structure. The output domain overlaps
+   !> north fold boundary. However it do not overlap east-west boundary.
+   !>
+   !> @details
+   !> If domain is given, read only domain.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp    : mpp structure
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_dom    : domain structure
+   !> @return variable structure completed 
+   !
+   !> @todo
+   !-------------------------------------------------------------------
+   !> @code
+!   SUBROUTINE iom_mpp__pole_no_overlap(td_mpp, td_var, td_dom )
+!      IMPLICIT NONE
+!      ! Argument      
+!      TYPE(TMPP),   INTENT(IN)    :: td_mpp
+!      TYPE(TVAR),   INTENT(INOUT) :: td_var
+!      TYPE(TDOM),   INTENT(IN),   OPTIONAL :: td_dom
+!
+!      ! local variable
+!
+!      ! loop indices
+!      !----------------------------------------------------------------
+!
+!   END SUBROUTINE iom_mpp__pole_no_overlap
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read variable value
+   !> in an mpp structure. The output domain overlaps north fold boundary.
+   !> and uses cyclic east-west boundary.
+   !>
+   !> @details
+   !> If domain is given, read only domain.
+   !> If border is .TRUE., read only border processor
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp    : mpp structure
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_dom    : domain structure
+   !> @param[in] ld_border : read only border
+   !> @return variable structure completed 
+   !
+   !> @todo
+   !-------------------------------------------------------------------
+   !> @code
+!   SUBROUTINE iom_mpp__pole_cyclic(td_mpp, td_var, td_dom )
+!      IMPLICIT NONE
+!      ! Argument      
+!      TYPE(TMPP),   INTENT(IN)    :: td_mpp
+!      TYPE(TVAR),   INTENT(INOUT) :: td_var
+!      TYPE(TDOM),   INTENT(IN),   OPTIONAL :: td_dom
+!
+!      ! local variable
+!
+!      ! loop indices
+!      !----------------------------------------------------------------
+!
+!   END SUBROUTINE iom_mpp__pole_cyclic
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read variable value
+   !> in an mpp structure. The output domain overlaps north fold boundary. 
+   !> and east-west boundary. 
+   !>
+   !> @details
+   !> If domain is given, read only domain.
+   !> If border is .TRUE., read only border processor
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp    : mpp structure
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_dom    : domain structure
+   !> @param[in] ld_border : read only border
+   !> @return variable structure completed 
+   !
+   !> @todo
+   !-------------------------------------------------------------------
+   !> @code
+!   SUBROUTINE iom_mpp__pole_overlap(td_mpp, td_var, td_dom )
+!      IMPLICIT NONE
+!      ! Argument      
+!      TYPE(TMPP),   INTENT(IN)    :: td_mpp
+!      TYPE(TVAR),   INTENT(INOUT) :: td_var
+!      TYPE(TDOM),   INTENT(IN),   OPTIONAL :: td_dom
+!
+!      ! local variable
+!
+!      ! loop indices
+!      !----------------------------------------------------------------
+!
+!   END SUBROUTINE iom_mpp__pole_overlap
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write mpp structure in opened files.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_mpp_write_file(td_mpp)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP), INTENT(INOUT) :: td_mpp
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( " MPP WRITE: domain decomposition not define "//&
+         &               " in mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+         DO ji=1, td_mpp%i_nproc
+            IF( td_mpp%t_proc(ji)%i_id /= 0 )THEN
+               CALL iom_write_file(td_mpp%t_proc(ji))
+            ELSE
+               CALL logger_debug( " MPP WRITE: no id associated to file "//&
+               &              TRIM(td_mpp%t_proc(ji)%c_name) )
+            ENDIF
+         ENDDO
+      ENDIF
+   END SUBROUTINE iom_mpp_write_file
+   !> @endcode
+END MODULE iom_mpp
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/iom_rstdimg.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/iom_rstdimg.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/iom_rstdimg.f90	(revision 4245)
@@ -0,0 +1,1834 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: iom_rstdimg
+!
+! DESCRIPTION:
+!> @brief
+!> This module is a library to read/write dimg file.
+!>
+!> @details
+!>
+!>    to open dimg file (create file structure):<br/>
+!>    CALL iom_rstdimg_open(td_file)
+!>       - td_file is file structure (see file.f90)
+!>
+!>    to write in dimg file:<br/>
+!>    CALL  iom_rstdimg_write_file(td_file)
+!>
+!>    to close dimg file:<br/>
+!>    CALL iom_rstdimg_close(tl_file)
+!>
+!>    to read one dimension in dimg file:<br/>
+!>    tl_dim = iom_rstdimg_read_dim(tl_file, id_dimid)<br/>
+!>    or<br/>
+!>    tl_dim = iom_rstdimg_read_dim(tl_file, cd_name)
+!>       - id_dimid is dimension id<br/>
+!>       - cd_name is dimension name
+!>
+!>    to read one global attribute in dimg file:<br/>
+!>    tl_att = iom_rstdimg_read_att(tl_file, id_varid, id_attid)<br/>
+!>    or<br/>
+!>    tl_att = iom_rstdimg_read_att(tl_file, id_varid, cd_name)
+!>       - id_varid is variable id
+!>       - id_attid is attribute id<br/>
+!>       - cd_name is attribute name
+!>  
+!>    to read one variable in dimg file:<br/>
+!>    tl_var = iom_rstdimg_read_var(td_file, id_varid, [id_start, id_count])<br/>
+!>    or<br/>
+!>    tl_var = iom_rstdimg_read_var(td_file, cd_name, [id_start, [id_count,]] [cd_stdname])
+!>       - id_varid is variabale id
+!>       - cd_name is variabale name
+!>       - id_start is a integer(4) 1D table of index from which the data 
+!>          values will be read (optional)
+!>       - id_count is a integer(4) 1D table of the number of indices selected
+!>          along each dimension (optional)
+!>       - cd_stdname is variable standard name (optional)
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @param MyModule_type : brief_description
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!
+!> @todo
+!----------------------------------------------------------------------
+MODULE iom_rstdimg
+   USE netcdf                          ! nf90 library
+   USE kind                            ! F90 kind parameter
+   USE fct                             ! basic useful function
+   USE logger                             ! log file manager
+   USE att                             ! attribute manager
+   USE dim                             ! dimension manager
+   USE var                             ! variable manager
+   USE file                            ! file manager
+   USE dom                             ! domain manager
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! function and subroutine
+   PUBLIC :: iom_rstdimg_open        !< open or create dimg file, return file structure
+   PUBLIC :: iom_rstdimg_close       !< close dimg file
+   PUBLIC :: iom_rstdimg_read_dim    !< read one dimension in an opened dimg file, return variable structure
+   PUBLIC :: iom_rstdimg_read_var    !< read one variable  in an opened dimg file, return dimension structure
+   PUBLIC :: iom_rstdimg_fill_var    !< fill variable value in an opened dimg file
+   PUBLIC :: iom_rstdimg_write_file  !< write file structure contents in an opened dimg file
+   PUBLIC :: iom_rstdimg_get_mpp     !< get sub domain decomppistion in a dimg file
+
+   PRIVATE :: iom_rstdimg__get_info       !< get global information in an opened dimg file
+   PRIVATE :: iom_rstdimg__get_file_var   !< read information about variable on an opened dimg file.
+   PRIVATE :: iom_rstdimg__get_file_var_0d !< put information about scalar variable in file structure
+   PRIVATE :: iom_rstdimg__get_file_var_1d !< put information about variable 1D in file structure
+   PRIVATE :: iom_rstdimg__get_file_var_2d !< put information about variable 2D in file structure
+   PRIVATE :: iom_rstdimg__get_file_var_3d !< put information about variable 3D in file structure
+   PRIVATE :: iom_rstdimg__read_dim_id    !< read dimension structure in an opened dimg file, given variable id.
+   PRIVATE :: iom_rstdimg__read_dim_name  !< read dimension structure in an opened dimg file, given variable name or standard name.
+   PRIVATE :: iom_rstdimg__read_var_id    !< read variable value in an opened dimg file, given variable id.
+   PRIVATE :: iom_rstdimg__read_var_name  !< read variable value in an opened dimg file, given variable name or standard name.
+   PRIVATE :: iom_rstdimg__read_var_value !< read variable value in an opened dimg file, for variable 1,2,3d
+   PRIVATE :: iom_rstdimg__write_header   !< write header in an opened dimg file
+   PRIVATE :: iom_rstdimg__write_var      !< write variables in an opened dimg file 
+   PRIVATE :: iom_rstdimg__fill_var_id    !< fill variable value in an opened dimg file, given variable id
+   PRIVATE :: iom_rstdimg__fill_var_name  !< fill variable value in an opened dimg file, given variable name
+   PRIVATE :: iom_rstdimg__fill_var_all   !< fill all variable value in an opened dimg file
+
+   ! module variable
+   INTEGER(i4), PARAMETER :: ip_vnl = 32 ! variable name length
+
+   INTERFACE iom_rstdimg_read_dim
+      MODULE PROCEDURE iom_rstdimg__read_dim_id
+      MODULE PROCEDURE iom_rstdimg__read_dim_name
+   END INTERFACE iom_rstdimg_read_dim
+
+   INTERFACE iom_rstdimg_read_var
+      MODULE PROCEDURE iom_rstdimg__read_var_id
+      MODULE PROCEDURE iom_rstdimg__read_var_name
+   END INTERFACE iom_rstdimg_read_var
+
+   INTERFACE iom_rstdimg_fill_var
+      MODULE PROCEDURE iom_rstdimg__fill_var_id
+      MODULE PROCEDURE iom_rstdimg__fill_var_name
+      MODULE PROCEDURE iom_rstdimg__fill_var_all
+   END INTERFACE iom_rstdimg_fill_var   
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief This subroutine open a dimg file in read or write mode<br/>
+   !> if try to open a file in write mode that did not exist, create it.<br/>
+   !> if file already exist, get information about:
+   !> - the number of variables
+   !> - the number of dimensions
+   !> - the number of global attributes
+   !> - the ID of the unlimited dimension
+   !> - the file format
+   !> and finally read dimensions.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg_open(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT)  :: td_file
+
+      ! local variable
+      LOGICAL           :: ll_exist
+      LOGICAL           :: ll_open
+
+      INTEGER(i4)       :: il_status
+      
+      TYPE(TVAR)        :: tl_lon
+      !----------------------------------------------------------------
+
+      ! check file existence
+      ! WARNING may be some issue with dimg file !!!
+      INQUIRE(FILE=TRIM(td_file%c_name), EXIST=ll_exist, OPENED=ll_open)
+      IF( .NOT. ll_exist .OR. TRIM(td_file%c_type) /= 'dimg' )THEN
+
+         IF( .NOT. td_file%l_wrt )THEN
+
+            CALL logger_fatal( " OPEN: can not open dimg file "//&
+            &               TRIM(td_file%c_name) )
+         
+         ELSE
+
+            CALL logger_info( " CREATE: dimg file "//TRIM(td_file%c_name) )
+
+            ! get free unit
+            td_file%i_id=fct_getunit()
+
+            OPEN( td_file%i_id, FILE=TRIM(td_file%c_name),&
+            &                         FORM='UNFORMATTED',              &
+            &                         ACCESS='DIRECT',                 &
+            &                         STATUS='NEW',                    &
+            &                         ACTION='WRITE',                  &
+            &                         RECL=8,                          &
+            &                         IOSTAT=il_status)
+            CALL fct_err(il_status)
+            IF( il_status /= 0 )THEN
+               CALL logger_error("CREATE: dimg file "//&
+               &              TRIM(td_file%c_name))
+            ENDIF
+
+
+         ENDIF
+
+      ELSE
+
+         IF( ll_open )THEN
+
+            CALL logger_error( " OPEN: dimg file "//&
+            &                TRIM(td_file%c_name)//" already opened")
+
+         ELSE
+
+            ! get free unit
+            td_file%i_id=fct_getunit()
+
+            ! open temporary in read only mode
+            OPEN( td_file%i_id, FILE=TRIM(td_file%c_name),&
+            &                         FORM='UNFORMATTED',              &
+            &                         ACCESS='DIRECT',                 &
+            &                         STATUS='OLD',                    &
+            &                         ACTION='READ',                   &
+            &                         RECL=8,                          &
+            &                         IOSTAT=il_status)
+            CALL fct_err(il_status)
+            IF( il_status /= 0 )THEN
+               CALL logger_error("OPEN: file "//TRIM(td_file%c_name))
+            ENDIF
+
+            ! get record length
+            READ( td_file%i_id, IOSTAT=il_status, &
+            &                         REC=1) td_file%i_recl
+            CALL fct_err(il_status)
+            IF( il_status /= 0 )THEN
+               CALL logger_error("OPEN: read record length : "//&
+               &    TRIM(fct_str(td_file%i_recl))//" in file "//&
+               &    TRIM(td_file%c_name) )
+            ENDIF
+
+            CLOSE( td_file%i_id, IOSTAT=il_status )
+            CALL fct_err(il_status)
+            IF( il_status /= 0 )THEN
+               CALL logger_error("OPEN: close file "//TRIM(td_file%c_name))
+            ENDIF
+
+
+            IF( .NOT. td_file%l_wrt )THEN
+
+               CALL logger_info( " OPEN: dimg file "//&
+               &              TRIM(td_file%c_name)//" in read only mode" )
+
+               ! open file in read mode
+               OPEN( td_file%i_id, FILE=TRIM(td_file%c_name),&
+               &                         FORM='UNFORMATTED',              &
+               &                         ACCESS='DIRECT',                 &
+               &                         STATUS='OLD',                    &
+               &                         ACTION='READ',                   &
+               &                         RECL=td_file%i_recl,    &
+               &                         IOSTAT=il_status)
+               CALL fct_err(il_status)
+               IF( il_status /= 0 )THEN
+                  CALL logger_error("OPEN: file "//TRIM(td_file%c_name)&
+                  &  //" with record length "//TRIM(fct_str(td_file%i_recl)))
+               ENDIF               
+
+            ELSE
+
+               CALL logger_info( " OPEN: dimg file "//&
+               &              TRIM(td_file%c_name)//&
+               &              " in read and write mode")
+
+               ! open file in read mode
+               OPEN( td_file%i_id, FILE=TRIM(td_file%c_name),&
+               &                         FORM='UNFORMATTED',              &
+               &                         ACCESS='DIRECT',                 &
+               &                         STATUS='OLD',                    &
+               &                         ACTION='READWRITE',              &
+               &                         RECL=td_file%i_recl,    &
+               &                         IOSTAT=il_status)
+               CALL fct_err(il_status)
+               IF( il_status /= 0 )THEN
+                  CALL logger_error("OPEN: file "//TRIM(td_file%c_name))
+               ENDIF        
+
+            ENDIF
+
+            ! get general information about file
+            CALL iom_rstdimg__get_info(td_file)
+
+            ! get domain decomposition in file
+            CALL iom_rstdimg_get_mpp(td_file)
+
+            ! get information about variables in file
+            CALL iom_rstdimg__get_file_var(td_file)
+
+            ! get ew overlap
+            tl_lon=iom_rstdimg_read_var(td_file,'longitude')
+            td_file%i_ew=dom_get_ew_overlap(tl_lon)
+            WHERE( td_file%t_var(:)%t_dim(1)%l_use )
+               td_file%t_var(:)%i_ew=td_file%i_ew
+            ENDWHERE
+            CALL var_clean(tl_lon) 
+
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE iom_rstdimg_open
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine close dimg file
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg_close(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      !----------------------------------------------------------------
+
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " CLOSE: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE      
+         CALL logger_info( &
+         &  " CLOSE: file "//TRIM(td_file%c_name))
+
+         CLOSE( td_file%i_id, IOSTAT=il_status )
+         CALL fct_err(il_status)
+         IF( il_status /= 0 )THEN
+            CALL logger_error("CLOSE "//TRIM(td_file%c_name))
+         ENDIF
+
+         td_file%i_id = 0 
+
+      ENDIF
+
+   END SUBROUTINE iom_rstdimg_close
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine get global information in an opened dimg 
+   !> file.<br/>
+   !> @details
+   !> It gets the number of variables, the  domain decompistion, 
+   !> the record of the header infos.<br/>
+   !> It read dimensions, and add it to dimension structure inside 
+   !> file structure.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @return file structure completed 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg__get_info(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_recl                          ! record length 
+      INTEGER(i4) :: il_nx, il_ny, il_nz              ! x,y,z dimension 
+      INTEGER(i4) :: il_n0d, il_n1d, il_n2d, il_n3d   ! number of 0/1/2/3D variables 
+      INTEGER(i4) :: il_rhd                           ! record of the header infos
+
+      TYPE(TDIM)  :: tl_dim ! dimension structure 
+      !----------------------------------------------------------------
+
+      CALL logger_debug( &
+      &  " GET INFO: about dimg file "//TRIM(td_file%c_name))
+
+      ! read first record 
+      READ( td_file%i_id, IOSTAT=il_status, REC=1 )& 
+      &     il_recl,                         &
+      &     il_nx, il_ny, il_nz,             &
+      &     il_n0d, il_n1d, il_n2d, il_n3d,  &
+      &     il_rhd
+      CALL fct_err(il_status)
+      IF( il_status /= 0 )THEN
+         CALL logger_error("GET INFO: read first line of "//TRIM(td_file%c_name))
+      ENDIF
+
+      CALL logger_trace( &
+      &  " GET INFO: about dimg file "//TRIM(td_file%c_name))
+
+      td_file%c_type='dimg'
+
+      ! add dimension to file structure
+      tl_dim=dim_init('X', il_nx)
+      CALL file_add_dim(td_file, tl_dim)
+      tl_dim=dim_init('Y', il_ny)
+      CALL file_add_dim(td_file, tl_dim)
+      tl_dim=dim_init('Z', il_nz)
+      CALL file_add_dim(td_file, tl_dim)
+
+      ! reorder dimension to ('x','y','z','t')
+      ! actually fill unused dimension
+      CALL dim_reorder(td_file%t_dim)
+
+      ! save total number of variable 
+      td_file%i_n0d=il_n0d
+      td_file%i_n1d=il_n1d
+      td_file%i_n2d=il_n2d
+      td_file%i_n3d=il_n3d
+      td_file%i_nvar=il_n0d+il_n1d+il_n2d+il_n3d
+
+      ! record header infos
+      td_file%i_rhd=il_rhd
+
+   END SUBROUTINE iom_rstdimg__get_info
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine get sub domain decomposition in a dimg file.<br/>
+   !> @details
+   !> domain decomposition informations are saved in attributes.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @return mpp structure 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg_get_mpp(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! local variable
+      TYPE(TATT)  :: tl_att
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_recl                          ! record length 
+      INTEGER(i4) :: il_nx, il_ny, il_nz              ! x,y,z dimension 
+      INTEGER(i4) :: il_n0d, il_n1d, il_n2d, il_n3d   ! number of 0/1/2/3D variables 
+      INTEGER(i4) :: il_iglo, il_jglo                 ! domain global size
+      INTEGER(i4) :: il_rhd                           ! record of the header infos
+      INTEGER(i4) :: il_niproc, il_njproc, il_nproc   ! domain decomposition
+      INTEGER(i4) :: il_area                          ! domain index
+
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_impp
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_jmpp
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_lci
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_lcj
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_ldi
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_ldj
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_lei
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_lej
+      !----------------------------------------------------------------
+
+      CALL logger_trace( " GET MPP: dimg file "//TRIM(td_file%c_name))
+
+      ! read first record 
+      READ( td_file%i_id, IOSTAT=il_status, REC=1 )& 
+      &     il_recl,                         &
+      &     il_nx, il_ny, il_nz,             &
+      &     il_n0d, il_n1d, il_n2d, il_n3d,  &
+      &     il_rhd,                          &
+      &     il_niproc, il_njproc, il_nproc,  &
+      &     il_area,                         &
+      &     il_iglo, il_jglo
+      CALL fct_err(il_status)
+      IF( il_status /= 0 )THEN
+         CALL logger_error("GET MPP: read first line of "//TRIM(td_file%c_name))
+      ENDIF
+
+      ! create attributes to save mpp value
+      tl_att=att_init( "DOMAIN_number_total", il_nproc)
+      CALL file_add_att(td_file, tl_att)
+
+      tl_att=att_init( "DOMAIN_I_number_total", il_niproc)
+      CALL file_add_att(td_file, tl_att)
+
+      tl_att=att_init( "DOMAIN_J_number_total", il_njproc)
+      CALL file_add_att(td_file, tl_att)
+
+      tl_att=att_init( "DOMAIN_number", il_area)
+      CALL file_add_att(td_file, tl_att)
+
+      tl_att=att_init( "DOMAIN_size_global", (/il_iglo, il_jglo/))
+      CALL file_add_att(td_file, tl_att)
+
+      ! allocate local variable
+      ALLOCATE( il_impp(il_nproc), il_jmpp(il_nproc),&
+      &         il_lci(il_nproc),  il_lcj(il_nproc), &
+      &         il_ldi(il_nproc),  il_ldj(il_nproc), &
+      &         il_lei(il_nproc),  il_lej(il_nproc), &
+      &         stat=il_status)
+      IF(il_status /= 0 )THEN
+
+         CALL logger_error( " GET MPP: not enough space to put domain &
+         &  decomposition in file "//TRIM(td_file%c_name) )
+
+      ENDIF
+
+      ! read first record 
+      READ( td_file%i_id, IOSTAT=il_status, REC=1 )& 
+      &     il_recl,                         &
+      &     il_nx, il_ny, il_nz,             &
+      &     il_n0d, il_n1d, il_n2d, il_n3d,  &
+      &     il_rhd,                          &
+      &     il_niproc, il_njproc, il_nproc,  &
+      &     il_area,                         &
+      &     il_iglo, il_jglo,                &
+      &     il_lci(:), il_lcj(:),            &
+      &     il_ldi(:), il_ldj(:),            &
+      &     il_lei(:), il_lej(:),            &
+      &     il_impp(:),il_jmpp(:)
+      CALL fct_err(il_status)
+      IF( il_status /= 0 )THEN
+         CALL logger_error("GET INFO: read domain decomposition on first &
+         &              line of "//TRIM(td_file%c_name))
+      ENDIF
+
+      tl_att=att_init( "DOMAIN_position_first", (/il_impp(il_area), il_jmpp(il_area)/))
+      CALL file_add_att(td_file, tl_att)
+
+      tl_att=att_init( "DOMAIN_position_last", (/il_lci(il_area), il_lcj(il_area)/))
+      CALL file_add_att(td_file, tl_att)
+
+      tl_att=att_init( "DOMAIN_halo_size_start", (/il_ldi(il_area), il_ldj(il_area)/))
+      CALL file_add_att(td_file, tl_att)
+
+      tl_att=att_init( "DOMAIN_halo_size_end", (/il_lei(il_area), il_lej(il_area)/))
+      CALL file_add_att(td_file, tl_att)
+
+      tl_att=att_init( "DOMAIN_I_position_first", il_impp(:) )
+      CALL file_add_att(td_file, tl_att)
+      tl_att=att_init( "DOMAIN_J_position_first", il_jmpp(:) )
+      CALL file_add_att(td_file, tl_att)
+
+      tl_att=att_init( "DOMAIN_I_position_last", il_lci(:) )
+      CALL file_add_att(td_file, tl_att)
+      tl_att=att_init( "DOMAIN_J_position_last", il_lcj(:) )
+      CALL file_add_att(td_file, tl_att)
+
+      tl_att=att_init( "DOMAIN_I_halo_size_start", il_ldi(:) )
+      CALL file_add_att(td_file, tl_att)
+      tl_att=att_init( "DOMAIN_J_halo_size_start", il_ldj(:) )
+      CALL file_add_att(td_file, tl_att)
+
+      tl_att=att_init( "DOMAIN_I_halo_size_end", il_lei(:) )
+      CALL file_add_att(td_file, tl_att)
+      tl_att=att_init( "DOMAIN_J_halo_size_end", il_lej(:) )
+      CALL file_add_att(td_file, tl_att)
+
+      DEALLOCATE( il_impp, il_jmpp,&
+      &           il_lci,  il_lcj, &
+      &           il_ldi,  il_ldj, &
+      &           il_lei,  il_lej  )
+
+   END SUBROUTINE iom_rstdimg_get_mpp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read information about variable on an 
+   !> opened dimg file.<br/>
+   !> The variable structure inside file structure is then completed.
+   !> @note variable value are read only for scalar variable (0d).
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @return file structure completed 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg__get_file_var(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! local variable
+      CHARACTER(LEN=ip_vnl), DIMENSION(:), ALLOCATABLE :: cl_name
+
+      REAL(dp)             , DIMENSION(:), ALLOCATABLE :: dl_value
+
+      INTEGER(i4)                                      :: il_status
+      INTEGER(i4)          , DIMENSION(:), ALLOCATABLE :: il_start
+      INTEGER(i4)          , DIMENSION(:), ALLOCATABLE :: il_count
+
+      !----------------------------------------------------------------
+
+      IF( td_file%i_nvar > 0 )THEN
+
+         ALLOCATE( il_start(4), il_count(4) )
+
+         il_start(1) = 1
+         il_count(1) = td_file%i_n0d
+         
+         il_start(2) = 1 + il_count(1)
+         il_count(2) = il_start(2) - 1 + td_file%i_n1d
+         
+         il_start(3) = 1 + il_count(2)
+         il_count(3) = il_start(3) - 1 + td_file%i_n2d
+         
+         il_start(4) = 1 + il_count(3)
+         il_count(4) = il_start(4) - 1 + td_file%i_n3d
+         
+         ALLOCATE( cl_name(td_file%i_nvar), dl_value(td_file%i_nvar) )
+
+         ! read first record 
+         READ( td_file%i_id, IOSTAT=il_status, REC=td_file%i_rhd )& 
+         & cl_name(il_start(1):il_count(1)), dl_value(il_start(1):il_count(1)),&
+         & cl_name(il_start(2):il_count(2)), dl_value(il_start(2):il_count(2)),&
+         & cl_name(il_start(3):il_count(3)), dl_value(il_start(3):il_count(3)),&
+         & cl_name(il_start(4):il_count(4)), dl_value(il_start(4):il_count(4))
+         CALL fct_err(il_status)
+         IF( il_status /= 0 )THEN
+            CALL logger_error("GET FILE: reading headers in file "//&
+            &   TRIM(td_file%c_name))
+         ENDIF
+
+         DEALLOCATE( il_start, il_count )
+
+         IF(ASSOCIATED(td_file%t_var))THEN
+            DEALLOCATE(td_file%t_var)
+         ENDIF
+         ALLOCATE(td_file%t_var(td_file%i_nvar))
+
+         ! put information about variable 0D inside file structure
+         CALL iom_rstdimg__get_file_var_0d(td_file, cl_name(:), dl_value(:))
+
+         ! put information about variable 1D inside file structure
+         CALL iom_rstdimg__get_file_var_1d(td_file, cl_name(:), dl_value(:))
+
+         ! put information about variable 2D inside file structure
+         CALL iom_rstdimg__get_file_var_2d(td_file, cl_name(:), dl_value(:))
+
+         ! put information about variable 3D inside file structure
+         CALL iom_rstdimg__get_file_var_3d(td_file, cl_name(:), dl_value(:))
+
+         DEALLOCATE( cl_name, dl_value )
+
+         ! delete dummy variable
+         CALL file_del_var( td_file, 'no0d' )
+         CALL file_del_var( td_file, 'no1d' )
+         CALL file_del_var( td_file, 'no2d' )
+         CALL file_del_var( td_file, 'no3d' )
+
+      ELSE
+
+         CALL logger_debug( &
+         &  " GET FILE VAR: there is no variable in file "//&
+         &  TRIM(td_file%c_name))
+
+      ENDIF
+
+   END SUBROUTINE iom_rstdimg__get_file_var
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine put information about scalar variable 
+   !> inside file structure.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] cd_name : table of variable name
+   !> @param[in] dd_value : table of variable value
+   !> @return file structure completed 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg__get_file_var_0d(td_file, cd_name, dd_value)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),                         INTENT(INOUT) :: td_file
+      CHARACTER(LEN=ip_vnl), DIMENSION(:), INTENT(IN)    :: cd_name
+      REAL(dp),              DIMENSION(:), INTENT(IN)    :: dd_value
+
+      ! local variable
+      TYPE(TDIM), DIMENSION(ip_maxdim) :: tl_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! define same dimension as in file
+      tl_dim(:)=td_file%t_dim(:)
+      ! do not use any dimension
+      tl_dim(:)%l_use=.FALSE.
+      tl_dim(:)%i_len=1
+      
+      ! case scalar variable
+      DO ji = 1, td_file%i_n0d
+   
+         td_file%t_var(ji)=var_init( TRIM(cd_name(ji)), NF90_DOUBLE, &
+         &                           tl_dim(:), id_id=ji, id_rec=1 )
+
+         ! get value of scalar
+         IF( ASSOCIATED(td_file%t_var(ji)%d_value) )THEN
+            DEALLOCATE(td_file%t_var(ji)%d_value)
+         ENDIF
+         ALLOCATE(td_file%t_var(ji)%d_value(1,1,1,1))
+
+         td_file%t_var(ji)%d_value(1,1,1,1)=dd_value(ji)
+
+      ENDDO
+
+   END SUBROUTINE iom_rstdimg__get_file_var_0d
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine put information about variable 1D 
+   !> inside file structure.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] cd_name : table of variable name
+   !> @param[in] dd_value : table of variable record
+   !> @return file structure completed 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg__get_file_var_1d(td_file, cd_name, dd_value)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),                         INTENT(INOUT) :: td_file
+      CHARACTER(LEN=ip_vnl), DIMENSION(:), INTENT(IN)    :: cd_name
+      REAL(dp),              DIMENSION(:), INTENT(IN)    :: dd_value
+
+      ! local variable
+      TYPE(TDIM), DIMENSION(ip_maxdim) :: tl_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! case variable 1D
+      DO ji = td_file%i_n0d + 1, &
+      &       td_file%i_n0d + td_file%i_n1d
+
+         ! define same dimension as in file
+         tl_dim(:)=td_file%t_dim(:)
+         ! do not use X and Y dimension
+         td_file%t_var(ji)%t_dim(1:2)%l_use=.FALSE.
+         td_file%t_var(ji)%t_dim(1:2)%i_len=1
+      
+         td_file%t_var(ji)=var_init( TRIM(cd_name(ji)), NF90_DOUBLE, &
+         &                           tl_dim(:), id_id=ji,            &
+         &                           id_rec=INT(dd_value(ji),i4) )
+
+      ENDDO
+
+   END SUBROUTINE iom_rstdimg__get_file_var_1d
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine put information about variable 2D 
+   !> inside file structure.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] cd_name : table of variable name
+   !> @param[in] dd_value : table of variable record
+   !> @return file structure completed 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg__get_file_var_2d(td_file, cd_name, dd_value)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),                         INTENT(INOUT) :: td_file
+      CHARACTER(LEN=ip_vnl), DIMENSION(:), INTENT(IN)    :: cd_name
+      REAL(dp),              DIMENSION(:), INTENT(IN)    :: dd_value
+
+      ! local variable
+      TYPE(TDIM), DIMENSION(ip_maxdim) :: tl_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! case variable 2D (X,Y)
+      DO ji = td_file%i_n0d + td_file%i_n1d + 1 , &
+      &       td_file%i_n0d + td_file%i_n1d + td_file%i_n2d
+
+         ! define same dimension as in file
+         tl_dim(:)=td_file%t_dim(:)
+         ! do not use Z dimension
+         tl_dim(3)%l_use=.FALSE.
+         tl_dim(3)%i_len=1       
+
+         td_file%t_var(ji)=var_init( TRIM(cd_name(ji)), NF90_DOUBLE, &
+         &                           tl_dim(:), id_id=ji,            &
+         &                           id_rec=INT(dd_value(ji),i4) )
+
+      ENDDO
+
+   END SUBROUTINE iom_rstdimg__get_file_var_2d
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine put information about variable 3D 
+   !> inside file structure.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] cd_name : table of variable name
+   !> @param[in] dd_value : table of variable record
+   !> @return file structure completed 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg__get_file_var_3d(td_file, cd_name, dd_value)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),                         INTENT(INOUT) :: td_file
+      CHARACTER(LEN=ip_vnl), DIMENSION(:), INTENT(IN)    :: cd_name
+      REAL(dp),              DIMENSION(:), INTENT(IN)    :: dd_value
+
+      ! local variable
+      TYPE(TDIM), DIMENSION(ip_maxdim) :: tl_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! case variable 3D (X,Y,Z)
+      DO ji = td_file%i_n0d + td_file%i_n1d + td_file%i_n2d +1 , &
+      &       td_file%i_n0d + td_file%i_n1d + td_file%i_n2d + td_file%i_n3d
+
+         ! define same dimension as in file
+         tl_dim(:)=td_file%t_dim(:) 
+
+         td_file%t_var(ji)=var_init( TRIM(cd_name(ji)), NF90_DOUBLE, &
+         &                           tl_dim(:), id_id=ji,            &
+         &                           id_rec=INT(dd_value(ji),i4) )
+
+      ENDDO
+
+   END SUBROUTINE iom_rstdimg__get_file_var_3d
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read one dimension in an opened netcdf file, 
+   !> given dimension id.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_dimid : dimension id
+   !> @return  dimension structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TDIM) FUNCTION iom_rstdimg__read_dim_id(td_file, id_dimid)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(IN) :: td_file
+      INTEGER(i4), INTENT(IN) :: id_dimid
+      !----------------------------------------------------------------
+
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " READ DIM: no id associated to dimg file "//TRIM(td_file%c_name))
+
+      ELSE      
+
+         iom_rstdimg__read_dim_id%i_id=id_dimid
+
+         CALL logger_debug( &
+         &  " READ DIM: dimension "//TRIM(fct_str(id_dimid))//&
+         &  " in file "//TRIM(td_file%c_name))
+
+         IF( id_dimid <= 4 )THEN
+            iom_rstdimg__read_dim_id=td_file%t_dim(id_dimid)
+         ELSE
+            CALL logger_error( &
+            &  " READ DIM: no dimension with id "//TRIM(fct_str(id_dimid))//&
+            &  " in file "//TRIM(td_file%c_name))
+         ENDIF
+
+      ENDIF
+
+   END FUNCTION iom_rstdimg__read_dim_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read one dimension in an opened netcdf file, 
+   !> given dimension name.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] cd_name : dimension name
+   !> @return  dimension structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TDIM) FUNCTION iom_rstdimg__read_dim_name(td_file, cd_name)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),      INTENT(IN) :: td_file
+      CHARACTER(LEN=*), INTENT(IN) :: cd_name
+
+      ! local variable
+      INTEGER(i4) :: il_dimid
+      !----------------------------------------------------------------
+
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " READ DIM: no id associated to dimg file "//TRIM(td_file%c_name))
+
+      ELSE      
+
+         il_dimid=dim_get_id(td_file%t_dim(:), TRIM(cd_name))
+         IF( il_dimid /= 0 )THEN
+            iom_rstdimg__read_dim_name=iom_rstdimg_read_dim(td_file, il_dimid)
+         ELSE
+            CALL logger_error( &
+            &  " READ DIM: no dimension "//TRIM(cd_name)//&
+            &  " in file "//TRIM(td_file%c_name))
+         ENDIF
+
+      ENDIF
+
+   END FUNCTION iom_rstdimg__read_dim_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function read variable value in an opened 
+   !> dimg file, given variable id.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] id_varid : variable id
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @return  variable structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION iom_rstdimg__read_var_id(td_file, id_varid,&
+   &                                            id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),               INTENT(IN) :: td_file
+      INTEGER(i4),               INTENT(IN) :: id_varid
+      INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_count
+      !INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_start
+      !INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_count
+
+      ! local variable
+      INTEGER(i4), DIMENSION(1) :: il_ind
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " READ VAR: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+
+         ! look for variable id
+         il_ind(:)=MINLOC(td_file%t_var(:)%i_id,mask=(td_file%t_var(:)%i_id==id_varid))
+         IF( il_ind(1) /= 0 )THEN
+
+            iom_rstdimg__read_var_id=td_file%t_var(il_ind(1))
+
+            IF( iom_rstdimg__read_var_id%i_ndim /= 0 )THEN
+               !!! read variable value
+               CALL iom_rstdimg__read_var_value( td_file, &
+               &                                 iom_rstdimg__read_var_id, &
+               &                                 id_start, id_count)
+            ELSE
+               CALL logger_debug( " READ VAR: variable 0d "//&
+               &               TRIM(td_file%t_var(il_ind(1))%c_name)//&
+               &               " should be already read ")
+            ENDIF            
+
+         ELSE
+            CALL logger_error( &
+            &  " READ VAR: there is no variable with id "//&
+            &  TRIM(fct_str(id_varid))//" in file "//TRIM(td_file%c_name))
+         ENDIF
+
+      ENDIF
+   END FUNCTION iom_rstdimg__read_var_id
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This function read variable value in an opened 
+   !> dimg file, given variable name or standard name.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @details
+   !> look first for variable name. If it doesn't
+   !> exist in file, look for variable standard name.<br/>
+   !> If variable name is not present, check variable standard name.<br/>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] cd_name  : variable name or standard name 
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @return  variable structure 
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION iom_rstdimg__read_var_name(td_file, cd_name,   &
+   &                                              id_start, id_count  )
+      IMPLICIT NONE
+      ! Argument 
+      TYPE(TFILE),                     INTENT(IN) :: td_file
+      CHARACTER(LEN=*),                INTENT(IN) :: cd_name
+      INTEGER(i4),      DIMENSION(:),  INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4),      DIMENSION(:),  INTENT(IN), OPTIONAL :: id_count
+      !INTEGER(i4),      DIMENSION(ip_maxdim),  INTENT(IN), OPTIONAL :: id_start
+      !INTEGER(i4),      DIMENSION(ip_maxdim),  INTENT(IN), OPTIONAL :: id_count
+
+      ! local variable
+      INTEGER(i4)       :: il_ind
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " READ VAR: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+
+         il_ind=var_get_id(td_file%t_var(:), cd_name)
+         IF( il_ind /= 0 )THEN
+
+            iom_rstdimg__read_var_name=td_file%t_var(il_ind)
+
+            IF( td_file%t_var(il_ind)%i_ndim /= 0 )THEN
+               !!! read variable value
+               CALL iom_rstdimg__read_var_value( td_file, &
+               &                                 iom_rstdimg__read_var_name, &
+               &                                 id_start, id_count)
+            ELSE
+               CALL logger_debug( " READ VAR: variable 0d "//&
+               &               TRIM(td_file%t_var(il_ind)%c_name)//&
+               &               " should have been already read ")
+            ENDIF
+
+         ELSE
+
+            CALL logger_error( &
+            &  " READ VAR NAME: there is no variable with "//&
+            &  " name or standard name "//TRIM(cd_name)//&
+            &  " in file "//TRIM(td_file%c_name) )
+
+         ENDIF
+
+      ENDIF
+      
+   END FUNCTION iom_rstdimg__read_var_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill all variable value in an opened 
+   !> dimg file.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg__fill_var_all(td_file, id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),               INTENT(INOUT) :: td_file
+      INTEGER(i4), DIMENSION(:), INTENT(IN),   OPTIONAL :: id_start
+      INTEGER(i4), DIMENSION(:), INTENT(IN),   OPTIONAL :: id_count
+      !INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL :: id_start
+      !INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL :: id_count
+
+      ! local variable
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " FILL VAR: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+
+         DO ji=1,td_file%i_nvar
+            CALL iom_rstdimg_fill_var(td_file, ji, id_start, id_count)
+         ENDDO
+
+      ENDIF
+   END SUBROUTINE iom_rstdimg__fill_var_all
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill variable value in an opened 
+   !> dimg file, given variable id.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] id_varid : variable id
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg__fill_var_id(td_file, id_varid, id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),               INTENT(INOUT) :: td_file
+      INTEGER(i4),               INTENT(IN)    :: id_varid
+      INTEGER(i4), DIMENSION(:), INTENT(IN),   OPTIONAL :: id_start
+      INTEGER(i4), DIMENSION(:), INTENT(IN),   OPTIONAL :: id_count
+      !INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL :: id_start
+      !INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL :: id_count
+
+      ! local variable
+      INTEGER(i4), DIMENSION(1) :: il_ind
+      TYPE(TVAR)                :: tl_var
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " FILL VAR: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+
+         ! look for variable id
+         il_ind(:) = MINLOC( td_file%t_var(:)%i_id, &
+         &                   mask=(td_file%t_var(:)%i_id==id_varid))
+         IF( il_ind(1) /= 0 )THEN
+
+            IF( tl_var%i_ndim /= 0 )THEN
+               !!! read variable value
+               CALL iom_rstdimg__read_var_value(td_file, td_file%t_var(il_ind(1)), &
+               &                                id_start, id_count)
+
+            ELSE
+               CALL logger_debug( " FILL VAR: variable 0d "//&
+               &               TRIM(td_file%t_var(il_ind(1))%c_name)//&
+               &               " should be already read ")
+            ENDIF            
+
+         ELSE
+            CALL logger_error( &
+            &  " FILL VAR: there is no variable with id "//&
+            &  TRIM(fct_str(id_varid))//" in file "//TRIM(td_file%c_name))
+         ENDIF
+
+      ENDIF
+   END SUBROUTINE iom_rstdimg__fill_var_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill variable value in an opened 
+   !> dimg file, given variable name or standard name.</br/>
+   !> start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
+   !
+   !> @details
+   !> look first for variable name. If it doesn't
+   !> exist in file, look for variable standard name.<br/>
+   !> If variable name is not present, check variable standard name.<br/>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_file : file structure
+   !> @param[in] cd_name  : variable name or standard name
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @return  variable structure 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg__fill_var_name(td_file, cd_name, id_start, id_count )
+      IMPLICIT NONE
+      ! Argument 
+      TYPE(TFILE),                    INTENT(INOUT) :: td_file
+      CHARACTER(LEN=*),               INTENT(IN)    :: cd_name
+      INTEGER(i4),      DIMENSION(:), INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4),      DIMENSION(:), INTENT(IN), OPTIONAL :: id_count
+      !INTEGER(i4),      DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_start
+      !INTEGER(i4),      DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_count
+      !CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+
+      ! local variable
+      INTEGER(i4)       :: il_ind
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " FILL VAR: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+
+         il_ind=var_get_id(td_file%t_var, cd_name)
+         IF( il_ind /= 0 )THEN
+
+            IF( td_file%t_var(il_ind)%i_ndim /= 0 )THEN
+               !!! read variable value
+               CALL iom_rstdimg__read_var_value( td_file, td_file%t_var(il_ind), &
+               &                                 id_start, id_count)
+
+            ELSE
+               CALL logger_debug( " FILL VAR: variable 0d "//&
+               &               TRIM(td_file%t_var(il_ind)%c_name)//&
+               &               " should have been already read ")
+            ENDIF
+
+         ELSE
+
+            CALL logger_error( &
+            &  " FILL VAR: there is no variable with "//&
+            &  " name or standard name "//TRIM(cd_name)//&
+            &  " in file "//TRIM(td_file%c_name))
+
+         ENDIF
+
+      ENDIF
+      
+   END SUBROUTINE iom_rstdimg__fill_var_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine read variable value in an opened dimg file, for
+   !> variable 1,2,3d.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[inout] td_var : variable structure
+   !> @param[in] id_start : index in the variable from which the data values will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @return variable structure completed 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg__read_var_value(td_file, td_var, &
+   &                                      id_start, id_count )
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE),               INTENT(IN)    :: td_file
+      TYPE(TVAR) ,               INTENT(INOUT) :: td_var
+      INTEGER(i4), DIMENSION(:), INTENT(IN),  OPTIONAL :: id_start
+      INTEGER(i4), DIMENSION(:), INTENT(IN),  OPTIONAL :: id_count
+      !INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),  OPTIONAL :: id_start
+      !INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),  OPTIONAL :: id_count
+
+      ! local variable
+      INTEGER(i4)                                  :: il_status
+      INTEGER(i4)                                  :: il_tmp1, il_tmp2
+      INTEGER(i4), DIMENSION(ip_maxdim)            :: il_start
+      INTEGER(i4), DIMENSION(ip_maxdim)            :: il_count
+      REAL(dp),    DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! check id_count and id_start optionals parameters...
+      IF( (       PRESENT(id_start)  .AND. (.NOT. PRESENT(id_count))) .OR. &
+          ((.NOT. PRESENT(id_start)) .AND.        PRESENT(id_count) ) )THEN
+         CALL logger_warn( &
+         &  " READ VAR VALUE: id_start and id_count should be both specify")
+      ENDIF
+
+      IF( PRESENT(id_start).AND.PRESENT(id_count) )THEN
+
+         IF( SIZE(id_start(:)) /= ip_maxdim .OR. &
+         &   SIZE(id_count(:)) /= ip_maxdim )THEN
+            CALL logger_error("READ VAR: dimension of table start or count "//&
+            &      " are invalid to read variable "//TRIM(td_var%c_name)//&
+            &      " in file "//TRIM(td_file%c_name) )
+         ENDIF
+
+         ! dimension order assume to be ('x','y','z','t')
+         il_start(:)=id_start(:)
+         il_count(:)=id_count(:)
+
+      ELSE
+
+         ! dimension order assume to be ('x','y','z','t')
+         il_start(:)=(/1,1,1,1/)
+         il_count(:)=td_var%t_dim(:)%i_len
+
+      ENDIF
+
+      ! check dimension
+      IF( .NOT. ALL(il_start(:)>=(/1,1,1,1/)) )THEN
+
+         CALL logger_error( " READ VAR VALUE: "//&
+         &               " start indices should be greater than or equal to 1")
+
+      ENDIF
+
+      IF(.NOT.ALL(il_start(:)+il_count(:)-1<=(/td_var%t_dim(1)%i_len,&
+         &                                     td_var%t_dim(2)%i_len,&
+         &                                     td_var%t_dim(3)%i_len,&
+         &                                     td_var%t_dim(4)%i_len &
+         &                                    /)) )THEN
+
+         CALL logger_error( " READ VAR VALUE: "//&
+         &               "start + count exceed variable dimension" )
+
+         DO ji = 1, ip_maxdim
+            il_tmp1=il_start(ji)+il_count(ji)-1
+            il_tmp2=td_var%t_dim(ji)%i_len
+            CALL logger_debug( &
+            &  " READ VAR VALUE: start + count - 1 "//TRIM(fct_str(il_tmp1))//&
+            &  " variable dimension"//TRIM(fct_str(il_tmp2)))
+         ENDDO
+
+      ELSE
+
+         ! Allocate space to hold variable value
+         ALLOCATE(dl_value( td_var%t_dim(1)%i_len, &
+         &                  td_var%t_dim(2)%i_len, &
+         &                  td_var%t_dim(3)%i_len, &
+         &                  td_var%t_dim(4)%i_len),&
+         &        stat=il_status)
+         IF(il_status /= 0 )THEN
+
+           CALL logger_error( &
+            &  " READ VAR VALUE: not enough space to put variable "//&
+            &  TRIM(td_var%c_name)//&
+            &  " in temporary table")
+
+         ENDIF
+
+         ! read values
+         CALL logger_trace( &
+         &  " READ VAR VALUE: get variable "//TRIM(td_var%c_name)//&
+         &  " in file "//TRIM(td_file%c_name))     
+
+         IF( ALL(td_var%t_dim(1:3)%l_use) )THEN
+            ! 3D variable (X,Y,Z)
+            DO ji=1,td_var%t_dim(3)%i_len
+               READ(td_file%i_id, IOSTAT=il_status, REC=td_var%i_rec +ji-1) &
+               &  dl_value(:,:,ji,:)
+               CALL fct_err(il_status)
+               IF( il_status /= 0 )THEN
+                  CALL logger_error("READ VAR VALUE: reading 3D variable "//&
+                  &              TRIM(td_var%c_name))
+               ENDIF
+            ENDDO
+         ELSEIF( ALL(td_var%t_dim(1:2)%l_use) )THEN
+            ! 2D variable (X,Y)
+            READ(td_file%i_id, IOSTAT=il_status, REC=td_var%i_rec ) &
+            &  dl_value(:,:,:,:)
+            CALL fct_err(il_status)
+            IF( il_status /= 0 )THEN
+               CALL logger_error("READ VAR VALUE: reading 2D variable "//&
+                  &            TRIM(td_var%c_name))
+            ENDIF
+         ELSEIF( td_var%t_dim(3)%l_use )THEN
+            ! 1d variable (Z)
+            READ(td_file%i_id, IOSTAT=il_status, REC=td_var%i_rec ) &
+            &  dl_value(:,:,:,:)
+            CALL fct_err(il_status)
+            IF( il_status /= 0 )THEN
+               CALL logger_error("READ VAR VALUE: reading 1D variable "//&
+                  &            TRIM(td_var%c_name))
+            ENDIF
+         ENDIF
+ 
+         ! Allocate space to hold variable value in structure
+         IF( ASSOCIATED(td_var%d_value) )THEN
+            DEALLOCATE(td_var%d_value)   
+         ENDIF
+
+         ALLOCATE(td_var%d_value( il_count(1), &
+         &                        il_count(2), &
+         &                        il_count(3), &
+         &                        il_count(4)),&
+         &        stat=il_status)
+         IF(il_status /= 0 )THEN
+
+           CALL logger_error( &
+            &  " READ VAR VALUE: not enough space to put variable "//&
+            &  TRIM(td_var%c_name)//&
+            &  " in variable structure")
+
+         ENDIF
+         ! FillValue by default
+         td_var%d_value(:,:,:,:)=td_var%d_fill
+
+         ! new dimension length
+         td_var%t_dim(:)%i_len=il_count(:)
+
+         ! extract value 
+         td_var%d_value(:,:,:,:) = dl_value(il_start(1):il_start(1)+il_count(1)-1,&
+         &                                  il_start(2):il_start(2)+il_count(2)-1,&
+         &                                  il_start(3):il_start(3)+il_count(3)-1,&
+         &                                  il_start(4):il_start(4)+il_count(4)-1)
+
+         DEALLOCATE(dl_value)
+
+      ENDIF
+
+   END SUBROUTINE iom_rstdimg__read_var_value
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write file structure in an opened dimg file.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg_write_file(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_attid
+      !----------------------------------------------------------------
+      ! check if file opened
+      IF( td_file%i_id == 0 )THEN
+
+         CALL logger_error( &
+         &  " WRITE FILE: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
+         IF( td_file%l_wrt )THEN
+
+            ! close and open file with right record length
+            CALL iom_rstdimg_close(td_file)
+
+            ! compute record length
+            il_attid=att_get_id(td_file%t_att(:),"DOMAIN_number_total")
+            IF( il_attid /= 0 )THEN
+               td_file%i_recl = MAX( &
+               &     td_file%t_dim(1)%i_len * td_file%t_dim(2)%i_len * 8, &
+               &     ( 8 * INT(td_file%t_att(il_attid)%d_value(1)) + 15 ) * 4 )
+            ELSE
+               td_file%i_recl = td_file%t_dim(1)%i_len * &
+               &                td_file%t_dim(2)%i_len * 8
+            ENDIF
+
+            OPEN( td_file%i_id, FILE=TRIM(td_file%c_name),&
+            &                         FORM='UNFORMATTED',              &
+            &                         ACCESS='DIRECT',                 &
+            &                         STATUS='REPLACE',                &
+            &                         ACTION='WRITE',                  &
+            &                         RECL=td_file%i_recl,             &
+            &                         IOSTAT=il_status)
+            CALL fct_err(il_status)
+            IF( il_status /= 0 )THEN
+               CALL logger_error("REPLACE: file "//TRIM(td_file%c_name)//&
+               &  " with record length "//TRIM(fct_str(td_file%i_recl)))
+            ELSE
+               CALL logger_debug("REPLACE: file "//TRIM(td_file%c_name)//&
+               &  " with record length "//TRIM(fct_str(td_file%i_recl)))
+            ENDIF
+
+            ! write header
+            CALL iom_rstdimg__write_header(td_file)
+
+            ! write variable in file
+            CALL iom_rstdimg__write_var(td_file) 
+
+         ELSE
+
+            CALL logger_error( &
+            &  " WRITE FILE: try to write in file "//TRIM(td_file%c_name)//&
+            &  ", not opened in write mode")
+
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE iom_rstdimg_write_file
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write header in an opened dimg 
+   !> file in write mode.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file structure
+   !> @param[in] td_dim : dimension structure
+   !> @return  dimension id 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg__write_header(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_attid
+      INTEGER(i4) :: il_nproc
+      INTEGER(i4) :: il_niproc
+      INTEGER(i4) :: il_njproc
+      INTEGER(i4) :: il_area
+      INTEGER(i4) :: il_iglo
+      INTEGER(i4) :: il_jglo
+
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_impp
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_jmpp
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_lci
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_lcj
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_ldi
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_ldj
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_lei
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_lej
+      
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! check record length
+      IF( td_file%i_recl <= 8 )THEN
+         CALL logger_warn(" WRITE FILE: record length seems to be tiny!! &
+         & ("//TRIM(fct_str(td_file%i_recl))//")")
+      ENDIF
+
+      ! check dimension
+      IF( ANY(td_file%t_dim(1:3)%i_len <= 0 ) )THEN
+         CALL logger_error(" WRITE FILE: at least one dimension size is less &
+         &                than or equal to zero !! ")
+         DO ji=1,3
+            CALL logger_debug(" WRITE FILE: dimension "//&
+            &               TRIM(td_file%t_dim(ji)%c_name)//" : "//&
+            &               TRIM(fct_str(td_file%t_dim(ji)%i_len)) )
+         ENDDO
+      ENDIF
+
+      ! get domain decomposition
+      il_attid=att_get_id( td_file%t_att, "DOMAIN_number_total" )
+      il_nproc = 1
+      IF( il_attid /= 0 )THEN
+         il_nproc = INT(td_file%t_att(il_attid)%d_value(1))
+      ENDIF
+
+      il_attid=att_get_id( td_file%t_att, "DOMAIN_I_number_total" )
+      il_niproc = 0
+      IF( il_attid /= 0 )THEN
+         il_niproc = INT(td_file%t_att(il_attid)%d_value(1))
+      ENDIF
+
+      il_attid=att_get_id( td_file%t_att, "DOMAIN_J_number_total" )
+      il_njproc = 0
+      IF( il_attid /= 0 )THEN
+         il_njproc = INT(td_file%t_att(il_attid)%d_value(1))
+      ENDIF
+
+      ! check domain decomposition
+      IF( il_niproc  <= 0 .OR. &
+      &   il_njproc  <= 0 .OR. &
+      &   il_nproc <= 0 .OR. &
+      &   il_nproc > il_niproc * il_njproc )THEN
+      
+         CALL logger_error(" WRITE FILE: invalid domain splitting ")
+
+         CALL logger_debug(" WRITE FILE: niproc "//TRIM(fct_str(il_niproc)) )
+         CALL logger_debug(" WRITE FILE: njproc "//TRIM(fct_str(il_njproc)) )
+         CALL logger_debug(" WRITE FILE: nproc "//TRIM(fct_str(il_nproc)) )
+
+      ENDIF
+      
+      ! get domain number
+      il_attid=att_get_id( td_file%t_att, "DOMAIN_number" )
+      il_area = 0
+      IF( il_attid /= 0 )THEN
+         il_area = INT(td_file%t_att(il_attid)%d_value(1))
+      ENDIF
+
+      ! get domain global size
+      il_attid=att_get_id( td_file%t_att, "DOMAIN_size_global" )
+      il_iglo = 0
+      il_jglo = 0
+      IF( il_attid /= 0 )THEN
+         il_iglo = INT(td_file%t_att(il_attid)%d_value(1))
+         il_jglo = INT(td_file%t_att(il_attid)%d_value(2))
+      ENDIF
+
+      ! check domain global size
+      IF( il_iglo < td_file%t_dim(1)%i_len .OR. &
+      &   il_jglo < td_file%t_dim(2)%i_len )THEN
+         CALL logger_error(" WRITE FILE: invalid global domain ")
+
+         CALL logger_debug(" WRITE FILE: global domain : "//&
+         &              TRIM(fct_str(il_iglo))//" x "//&
+         &              TRIM(fct_str(il_jglo)) )
+         CALL logger_debug(" WRITE FILE: local domain : "//&
+         &              TRIM(fct_str(td_file%t_dim(1)%i_len))//" x "//&
+         &              TRIM(fct_str(td_file%t_dim(2)%i_len)) )
+      ENDIF
+
+      ! allocate local variable
+      ALLOCATE( il_impp(il_nproc), il_jmpp(il_nproc),&
+      &         il_lci(il_niproc),  il_lcj(il_njproc), &
+      &         il_ldi(il_niproc),  il_ldj(il_njproc), &
+      &         il_lei(il_niproc),  il_lej(il_njproc) )
+
+      ! get domain first poistion
+      il_attid=att_get_id( td_file%t_att, "DOMAIN_I_position_first" )
+      il_impp(:) = 0
+      IF( il_attid /= 0 )THEN
+         il_impp(:) = INT(td_file%t_att(il_attid)%d_value(:))
+      ENDIF
+
+      il_attid=att_get_id( td_file%t_att, "DOMAIN_J_position_first" )
+      il_jmpp(:) = 0
+      IF( il_attid /= 0 )THEN
+         il_jmpp(:) = INT(td_file%t_att(il_attid)%d_value(:))
+      ENDIF
+      
+      ! check domain first poistion
+      IF( ANY(il_impp(:)==0) .OR. ANY(il_jmpp(:)==0) )THEN
+         CALL logger_warn("WRITE FILE: no data for domain first position")
+      ENDIF
+
+      ! get domain last poistion
+      il_attid=att_get_id( td_file%t_att, "DOMAIN_I_position_last" )
+      il_lci(:) = 0
+      IF( il_attid /= 0 )THEN
+         il_lci(:) = INT(td_file%t_att(il_attid)%d_value(:))
+      ENDIF
+
+      il_attid=att_get_id( td_file%t_att, "DOMAIN_J_position_last" )
+      il_lcj(:) = 0
+      IF( il_attid /= 0 )THEN
+         il_lcj(:) = INT(td_file%t_att(il_attid)%d_value(:))
+      ENDIF
+
+      ! check domain last poistion
+      IF( ANY(il_lci(:)==0) .OR. ANY(il_lcj(:)==0) )THEN
+         CALL logger_warn("WRITE FILE: no data for domain last position")
+      ENDIF
+
+      ! get halo size start
+      il_attid=att_get_id( td_file%t_att, "DOMAIN_I_halo_size_start" )
+      il_ldi(:) = 0
+      IF( il_attid /= 0 )THEN
+         il_ldi(:) = INT(td_file%t_att(il_attid)%d_value(:))
+      ENDIF
+
+      il_attid=att_get_id( td_file%t_att, "DOMAIN_J_halo_size_start" )
+      il_ldj(:) = 0
+      IF( il_attid /= 0 )THEN
+         il_ldj(:) = INT(td_file%t_att(il_attid)%d_value(:))
+      ENDIF
+      
+      ! check halo size start
+      IF( ANY(il_ldi(:)==0) .OR. ANY(il_ldj(:)==0) )THEN
+         CALL logger_warn("WRITE FILE: no data for halo size start")
+      ENDIF
+
+      ! get halo size end
+      il_attid=att_get_id( td_file%t_att, "DOMAIN_I_halo_size_end" )
+      il_lei(:) = 0
+      IF( il_attid /= 0 )THEN
+         il_lei(:) = INT(td_file%t_att(il_attid)%d_value(:))
+      ENDIF
+
+      il_attid=att_get_id( td_file%t_att, "DOMAIN_J_halo_size_end" )
+      il_lej(:) = 0
+      IF( il_attid /= 0 )THEN
+         il_lej(:) = INT(td_file%t_att(il_attid)%d_value(:))
+      ENDIF
+
+      ! check halo size end
+      IF( ANY(il_lei(:)==0) .OR. ANY(il_lej(:)==0) )THEN
+         CALL logger_warn("WRITE FILE: no data for halo size end")
+      ENDIF      
+
+      ! write file header
+      WRITE(td_file%i_id, IOSTAT=il_status, REC=1 )&
+      &  td_file%i_recl, &
+      &  td_file%t_dim(1)%i_len, &
+      &  td_file%t_dim(2)%i_len, &
+      &  td_file%t_dim(3)%i_len, &
+      &  td_file%i_n0d, &
+      &  td_file%i_n1d, &
+      &  td_file%i_n2d, &
+      &  td_file%i_n3d, &
+      &  td_file%i_rhd, &
+      &  il_niproc, il_njproc, il_nproc, &
+      &  il_area,                &
+      &  il_iglo, il_jglo,       &
+      &  il_impp(:), il_jmpp(:), &
+      &  il_lci(:), il_lcj(:),   &
+      &  il_ldi(:), il_ldj(:),   &
+      &  il_lei(:), il_lej(:)
+
+      DEALLOCATE( il_impp, il_jmpp,&
+      &           il_lci,  il_lcj, &
+      &           il_ldi,  il_ldj, &
+      &           il_lei,  il_lej  )
+
+      END SUBROUTINE iom_rstdimg__write_header
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write variables in an opened dimg file.</br/>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] id_fileid : file id
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE iom_rstdimg__write_var(td_file)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TFILE), INTENT(INOUT) :: td_file
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      TYPE(TVAR)  :: tl_var
+
+      INTEGER(i4),            DIMENSION(:), ALLOCATABLE :: il_start
+      INTEGER(i4),            DIMENSION(:), ALLOCATABLE :: il_count
+      CHARACTER(LEN=ip_vnl),  DIMENSION(:), ALLOCATABLE :: cl_name
+      REAL(dp),               DIMENSION(:), ALLOCATABLE :: dl_value
+
+      INTEGER(i4),            DIMENSION(:,:,:,:), ALLOCATABLE :: il_tmp
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! add dummy variable if necessary
+      IF( td_file%i_n0d == 0 )THEN
+         ! create var
+         tl_var=var_init('no0d')
+         ! add value
+         ALLOCATE( il_tmp(1,1,1,1) )
+         il_tmp(:,:,:,:)=-1
+         CALL var_add_value(tl_var, il_tmp)
+         DEALLOCATE( il_tmp )
+
+         CALL file_add_var( td_file, tl_var )
+      ENDIF
+
+      IF( td_file%i_n1d == 0 )THEN
+         ! create var
+         tl_var=var_init('no1d')
+         ! add dimension
+         CALL var_add_dim(tl_var, td_file%t_dim(3))
+         ! add value
+         ALLOCATE( il_tmp(1,1,td_file%t_dim(3)%i_len, 1) )
+         il_tmp(:,:,:,:)=-1
+         CALL var_add_value(tl_var, il_tmp)
+         DEALLOCATE( il_tmp )
+
+         CALL file_add_var( td_file, tl_var ) 
+      ENDIF
+ 
+      IF( td_file%i_n2d == 0 )THEN
+         ! create var
+         tl_var=var_init('no2d' )
+         ! add dimension
+         CALL var_add_dim(tl_var, td_file%t_dim(1))
+         CALL var_add_dim(tl_var, td_file%t_dim(2))
+         ! add value
+         ALLOCATE( il_tmp( td_file%t_dim(1)%i_len, &
+         &                 td_file%t_dim(2)%i_len, &
+         &                            1,             &
+         &                            1            ) )
+         il_tmp(:,:,:,:)=-1
+         CALL var_add_value(tl_var, il_tmp)
+         DEALLOCATE( il_tmp )
+
+         CALL file_add_var( td_file, tl_var ) 
+      ENDIF
+ 
+      IF( td_file%i_n3d == 0 )THEN
+         ! create var
+         tl_var=var_init('no3d' )
+         ! add dimension
+         CALL var_add_dim(tl_var, td_file%t_dim(1))
+         CALL var_add_dim(tl_var, td_file%t_dim(2))
+         CALL var_add_dim(tl_var, td_file%t_dim(3))
+         ! add value
+         ALLOCATE( il_tmp( td_file%t_dim(1)%i_len, &
+         &                 td_file%t_dim(2)%i_len, &
+         &                 td_file%t_dim(3)%i_len, &
+         &                            1            ) )
+         il_tmp(:,:,:,:)=-1
+         CALL var_add_value(tl_var, il_tmp)
+         DEALLOCATE( il_tmp )
+
+         CALL file_add_var( td_file, tl_var ) 
+      ENDIF
+
+      ! reform name and record
+      ALLOCATE( cl_name(td_file%i_nvar), dl_value(td_file%i_nvar) )
+      DO ji=1,td_file%i_nvar
+         cl_name(ji)  = TRIM(td_file%t_var(ji)%c_name)
+         dl_value(ji) = REAL(td_file%t_var(ji)%i_rec,dp)
+      ENDDO
+
+      ! special case for 0d
+      DO ji=1,td_file%i_n0d
+         dl_value(ji)=td_file%t_var(ji)%d_value(1,1,1,1)
+      ENDDO
+
+      ALLOCATE( il_start(4), il_count(4) )
+
+      il_start(1) = 1
+      il_count(1) = td_file%i_n0d
+      
+      il_start(2) = 1 + il_count(1)
+      il_count(2) = il_start(2) - 1 + td_file%i_n1d
+      
+      il_start(3) = 1 + il_count(2)
+      il_count(3) = il_start(3) - 1 + td_file%i_n2d
+      
+      il_start(4) = 1 + il_count(3)
+      il_count(4) = il_start(4) - 1 + td_file%i_n3d
+ 
+
+      WRITE(td_file%i_id, IOSTAT=il_status, REC=td_file%i_rhd )&
+      &  cl_name(il_start(1):il_count(1)), dl_value(il_start(1):il_count(1)),&
+      &  cl_name(il_start(2):il_count(2)), dl_value(il_start(2):il_count(2)),&
+      &  cl_name(il_start(3):il_count(3)), dl_value(il_start(3):il_count(3)),&
+      &  cl_name(il_start(4):il_count(4)), dl_value(il_start(4):il_count(4))
+
+      DEALLOCATE( il_start, il_count )
+
+   END SUBROUTINE iom_rstdimg__write_var
+   !> @endcode   
+END MODULE iom_rstdimg
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/kind.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/kind.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/kind.f90	(revision 4245)
@@ -0,0 +1,47 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: kind
+!
+! DESCRIPTION:
+!> This module defines the F90 kind parameter for common data types.
+!> 
+!
+!> @author
+!> G. Madec
+! REVISION HISTORY:
+!> @date June, 2006 - Initial Version
+!> @date December, 2012 - G. Madec
+!>  - add a standard length of character strings
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!
+!> @todo
+!> - check i8 max value
+!----------------------------------------------------------------------
+MODULE kind
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   !                                                                !!** Floating point **
+   ! SELECTED_REAL_KIND(P,R) returns the kind value of a real data type 
+   ! with decimal precision of at least P digits, exponent range of at least R
+   INTEGER, PUBLIC, PARAMETER ::   sp = SELECTED_REAL_KIND( 6, 37)   !< single precision (real 4)
+   INTEGER, PUBLIC, PARAMETER ::   dp = SELECTED_REAL_KIND(12,307)   !< double precision (real 8)
+   INTEGER, PUBLIC, PARAMETER ::   wp = dp                           !< working precision
+
+   !                                                                !!** Integer **
+   ! SELECTED_INT_KIND(R) return the kind value of the smallest integer type 
+   ! that can represent all values ranging ] -10^R , 10^R [
+   INTEGER, PUBLIC, PARAMETER ::   i1 = SELECTED_INT_KIND( 1)        !< single precision (integer 1) 
+   INTEGER, PUBLIC, PARAMETER ::   i2 = SELECTED_INT_KIND( 4)        !< single precision (integer 2) 
+   INTEGER, PUBLIC, PARAMETER ::   i4 = SELECTED_INT_KIND( 9)        !< single precision (integer 4) 
+   INTEGER, PUBLIC, PARAMETER ::   i8 = SELECTED_INT_KIND(14)        !< double precision (integer 8)
+   
+   !                                                                !!** Integer **
+   INTEGER, PUBLIC, PARAMETER ::   lc = 256                          !< Length of Character strings
+
+END MODULE kind
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/logger.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/logger.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/logger.f90	(revision 4245)
@@ -0,0 +1,606 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: logger
+!
+! DESCRIPTION:
+!> @brief This module create logger file and inform it depending 
+!>  of verbosity choose between :
+!>    - trace : Most detailed information.
+!>    - debug : Detailed information on the flow through the system.
+!>    - info  : Interesting runtime events (startup/shutdown).
+!>    - warning: Use of deprecated APIs, poor use of API, 'almost' errors, 
+!> other runtime situations that are undesirable or unexpected, 
+!> but not necessarily "wrong". 
+!>    - error : Other runtime errors or unexpected conditions.
+!>    - fatal : Severe errors that cause premature termination.<br />
+!>  default verbosity is warning
+!
+!> @details
+!>    If total number of error exceeded maximum number 
+!>    authorized, program stop.
+!>
+!>    to open/create logger file:<br/>
+!>    CALL logger_open(cd_file, [cd_verbosity,] [id_loggerid,] [id_maxerror])
+!>       - cd_file is logger file name
+!>       - cd_verbosity is verbosity to be used (optional, default 'warning')
+!>       - id_loggerid is file id (optional, use only to flush)
+!>       - id_maxerror is the mximum number of error authorized before stop program (optional, default 5)
+!>
+!>    to close logger file:<br/>
+!>    CALL logger_close()
+!>
+!>    to write header in logger file:<br/>
+!>    CALL logger_header()
+!>
+!>    to write footer in logger file:<br/>
+!>    CALL logger_footer()
+!>
+!>    to flushing output:<br/>
+!>    CALL logger_flush()
+!>
+!>    to write TRACE message in logger file:<br/>
+!>    CALL logger_trace(cd_msg)
+!>       - cd_msg is TRACE message
+!>
+!>    to write DEBUG message in logger file:<br/>
+!>    CALL logger_debug(cd_msg)
+!>       - cd_msg is DEBUG message
+!>
+!>    to write INFO message in logger file:<br/>
+!>    CALL logger_info(cd_msg)
+!>       - cd_msg is INFO message
+!>
+!>    to write WARNING message in logger file:<br/>
+!>    CALL logger_warn(cd_msg)
+!>       - cd_msg is WARNING message
+!>
+!>    to write ERROR message in logger file:<br/>
+!>    CALL logger_error(cd_msg)
+!>       - cd_msg is ERROR message
+!>
+!>    to write FATAL message in logger file:<br/>
+!>    CALL logger_fatal(cd_msg)
+!>       - cd_msg is FATAL message
+!>
+!>  Examples :<br />
+!>   CALL logger_open('loggerfile.txt','info')
+!>
+!>   CALL logger_header()<br />
+!>   CALL logger_info('une petite info')<br />
+!>   CALL logger_debug('une info de debug')<br />
+!>   CALL logger_warn('une info de warning')<br />
+!>   CALL logger_error('une info d erreur')<br />
+!>   CALL logger_footer()<br />
+!>   CALL logger_close()<br />
+!>
+!> !--------------------------------------------------------------------<br />
+!>   CALL logger_open('loggerfile.txt')
+!>
+!>   CALL logger_header()<br />
+!>   CALL logger_info('une petite info')<br />
+!>   CALL logger_debug('une info de debug')<br />
+!>   CALL logger_warn('une info de warning')<br />
+!>   CALL logger_error('une info d erreur')<br />
+!>   CALL logger_footer()<br />
+!>   CALL logger_close()<br />
+!
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013- Initial Version
+!>
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!>
+!> @todo
+!> - verifier flush remet pas compteur error à zero
+!----------------------------------------------------------------------
+MODULE logger
+   USE kind                            ! F90 kind parameter
+   USE fct                             ! basic useful function
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+   !PUBLIC :: TLOGGER            ! logger structure
+
+   ! function and subroutine
+   PUBLIC :: logger_open        ! create a log file with given verbosity
+   PUBLIC :: logger_close       ! close log file
+   PUBLIC :: logger_flush       ! flushing output
+   PUBLIC :: logger_header      ! write header on log file
+   PUBLIC :: logger_footer      ! write footer on log file
+   PUBLIC :: logger_trace       ! write trace    message in log file
+   PUBLIC :: logger_debug       ! write debug    message in log file 
+   PUBLIC :: logger_info        ! write info     message in log file
+   PUBLIC :: logger_warn        ! write warning  message in log file
+   PUBLIC :: logger_error       ! write error    message in log file
+   PUBLIC :: logger_fatal       ! write fatal    message in log file, and stop
+
+   PRIVATE :: logger__write     ! cut message to get maximum of 80 character by line in log file
+
+   !> @struct TLOG
+   TYPE TLOGGER
+      INTEGER(i4)       :: i_id = 0                 !< log file id
+      CHARACTER(LEN=lc) :: c_name                   !< log file name
+      CHARACTER(LEN=lc) :: c_verbosity = "warning"  !< verbosity choose
+      CHARACTER(LEN=lc) :: c_verb = ""              !< table of "verbosities" to used 
+      INTEGER(i4)       :: i_nerror   = 0           !< number of error
+      INTEGER(i4)       :: i_nfatal   = 0           !< number of fatal error
+      INTEGER(i4)       :: i_maxerror = 5           !< maximum number of error before stoping program
+   END TYPE TLOGGER   
+
+   !  module variable
+   INTEGER(i4), PARAMETER :: im_nverbosity=6     !< number of log level
+   CHARACTER(len=*), DIMENSION(im_nverbosity), PARAMETER :: cm_verbosity= & !< verbosity table 
+   &               (/ 'trace   ',&
+   &                  'debug   ',&
+   &                  'info    ',& 
+   &                  'warning ',&
+   &                  'error   ',&
+   &                  'fatal   '/)
+
+   TYPE(TLOGGER), SAVE :: tm_logger      !< logger structure
+                                                 
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief This subroutine create a log file with given verbosity.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_file : log file name
+   !> @param[in] cd_verbosity : log file verbosity
+   !> @param[in] id_logid : log file id (use to flush)
+   !> @param[in] id_maxerror : maximum number of error
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE logger_open(cd_file, cd_verbosity, id_logid, id_maxerror)
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(len=*), INTENT(IN) :: cd_file                ! log file name
+      CHARACTER(len=*), INTENT(IN), OPTIONAL :: cd_verbosity ! log file verbosity
+      INTEGER(i4),      INTENT(IN), OPTIONAL :: id_logid     ! log file id
+      INTEGER(i4),      INTENT(IN), OPTIONAL :: id_maxerror  ! log max error
+
+      ! local variable
+      INTEGER(i4) :: il_status
+
+      ! loop
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! get id if not already define
+      IF( PRESENT(id_logid) )THEN
+         tm_logger%i_id=id_logid
+      ELSE
+         tm_logger%i_id=fct_getunit()
+      ENDIF
+
+      ! open log file
+      OPEN( tm_logger%i_id, &
+      &     STATUS="unknown",    &
+      &     FILE=TRIM(ADJUSTL(cd_file)),  &
+      &     ACTION="write",      &
+      &     POSITION="append",   &
+      &     IOSTAT=il_status)
+      CALL fct_err(il_status)
+
+      ! keep filename
+      tm_logger%c_name=TRIM(ADJUSTL(cd_file))
+
+      ! if present, change verbosity value
+      IF( PRESENT(cd_verbosity) )THEN
+         tm_logger%c_verbosity=TRIM(ADJUSTL(cd_verbosity))
+      ENDIF
+
+      ! compute "tab" of verbosity to be used
+      IF( TRIM(ADJUSTL(tm_logger%c_verb)) == "" )THEN
+         DO ji=im_nverbosity,1,-1
+            tm_logger%c_verb = &
+            &  TRIM(tm_logger%c_verb)//" "//TRIM(ADJUSTL(cm_verbosity(ji)))
+            IF( TRIM(tm_logger%c_verbosity) == TRIM(cm_verbosity(ji)) )THEN
+               EXIT
+            ENDIF
+         ENDDO
+      ENDIF
+
+      IF( PRESENT(id_maxerror) )THEN
+         tm_logger%i_maxerror=id_maxerror
+      ENDIF
+
+   END SUBROUTINE logger_open
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine close a log file.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE logger_close()
+      IMPLICIT NONE
+      ! local variable
+      INTEGER(i4) :: il_status
+      !----------------------------------------------------------------
+      IF( tm_logger%i_id /= 0 )THEN
+         CLOSE( tm_logger%i_id, &
+         &      IOSTAT=il_status)      
+         CALL fct_err(il_status)
+      ELSE
+          CALL logger_open('logger.log')
+          CALL logger_header()
+          CALL logger_fatal('you must have create logger to use logger_close')
+      ENDIF
+
+   END SUBROUTINE logger_close
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine flushing output into log file.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE logger_flush()
+      IMPLICIT NONE
+      !----------------------------------------------------------------
+      IF( tm_logger%i_id /= 0 )THEN
+         CALL logger_close()
+         CALL logger_open( tm_logger%c_name, tm_logger%c_verbosity, tm_logger%i_id, &
+         &              tm_logger%i_maxerror )     
+      ELSE
+          CALL logger_open('logger.log')
+          CALL logger_header()
+          CALL logger_fatal('you must have create logger to use logger_flush')
+      ENDIF
+
+   END SUBROUTINE logger_flush
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write header on log file.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !-------------------------------------------------------------------
+   ! @code
+   RECURSIVE SUBROUTINE logger_header()
+      IMPLICIT NONE
+      ! local variable
+      INTEGER(i4) :: il_status
+      !----------------------------------------------------------------
+      IF( tm_logger%i_id /= 0 )THEN
+         WRITE( tm_logger%i_id,    &
+            &   FMT='(a/a/a)',     &
+            &   IOSTAT=il_status ) &
+            &   "--------------------------------------------------", &
+            &   "INIT     : log start with verbosity "//&
+            &   TRIM(tm_logger%c_verbosity), &
+            &   "--------------------------------------------------"
+         CALL fct_err(il_status)
+      ELSE
+          CALL logger_open('logger.log')
+          CALL logger_header()
+          CALL logger_fatal('you must have create logger to use logger_header')
+      ENDIF
+
+   END SUBROUTINE logger_header
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write footer on log file.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE logger_footer()
+      IMPLICIT NONE
+      ! local variable
+      INTEGER(i4) :: il_status
+      !----------------------------------------------------------------
+      IF( tm_logger%i_id /= 0 )THEN
+         WRITE( tm_logger%i_id,    &
+            &   FMT='(a/a/a/a/a)',     &
+            &   IOSTAT=il_status ) &
+            &   "--------------------------------------------------",&
+            &   "END      : log ended ",                             &
+            &   "END      : "//TRIM(fct_str(tm_logger%i_nerror))//   &
+            &   " ERROR detected ",                                  &
+            &   "END      : "//TRIM(fct_str(tm_logger%i_nfatal))//   &
+            &   " FATAL detected ",                                  &
+            &   "--------------------------------------------------"
+         CALL fct_err(il_status)
+      ELSE
+          CALL logger_open('logger.log')
+          CALL logger_header()
+          CALL logger_fatal('you must have create logger to use logger_footer')
+      ENDIF
+   END SUBROUTINE logger_footer
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write trace message on log file.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_msg : message to write
+   !> @param[in] ld_flush : flushing ouput
+   !
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE logger_trace(cd_msg, ld_flush)
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN)  :: cd_msg
+      LOGICAL,          INTENT(IN), OPTIONAL :: ld_flush
+      !----------------------------------------------------------------
+      IF( tm_logger%i_id /= 0 )THEN
+         IF( INDEX(TRIM(tm_logger%c_verb),'trace')/=0 )THEN
+
+            CALL logger__write("TRACE   :",cd_msg)
+
+            IF( PRESENT(ld_flush) )THEN
+               IF( ld_flush )THEN
+                  CALL logger_flush()
+               ENDIF
+            ENDIF      
+         ENDIF
+      ELSE
+          CALL logger_open('logger.log')
+          CALL logger_header()
+          CALL logger_fatal('you must have create logger to use logger_trace')
+      ENDIF
+   END SUBROUTINE logger_trace
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write debug message on log file.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_msg : message to write
+   !> @param[in] ld_flush : flushing ouput
+   !
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE logger_debug(cd_msg, ld_flush)
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN)  :: cd_msg
+      LOGICAL,          INTENT(IN), OPTIONAL :: ld_flush
+      !----------------------------------------------------------------
+      IF( tm_logger%i_id /= 0 )THEN
+         IF( INDEX(TRIM(tm_logger%c_verb),'debug')/=0 )THEN
+
+            CALL logger__write("DEBUG   :",cd_msg)
+
+            IF( PRESENT(ld_flush) )THEN
+               IF( ld_flush )THEN
+                  CALL logger_flush()
+               ENDIF
+            ENDIF      
+         ENDIF
+      ELSE
+          CALL logger_open('logger.log')
+          CALL logger_header()
+          CALL logger_fatal('you must have create logger to use logger_debug')
+      ENDIF
+   END SUBROUTINE logger_debug
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write info message on log file.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_msg : message to write
+   !> @param[in] ld_flush : flushing ouput
+   !
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE logger_info(cd_msg, ld_flush)
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN)  :: cd_msg
+      LOGICAL,          INTENT(IN), OPTIONAL :: ld_flush
+      !----------------------------------------------------------------
+      IF( tm_logger%i_id /= 0 )THEN
+         IF( INDEX(TRIM(tm_logger%c_verb),'info')/=0 )THEN
+
+            CALL logger__write("INFO    :",cd_msg)
+
+            IF( PRESENT(ld_flush) )THEN
+               IF( ld_flush )THEN
+                  CALL logger_flush()
+               ENDIF
+            ENDIF      
+         ENDIF
+      ELSE
+          CALL logger_open('logger.log')
+          CALL logger_header()
+          CALL logger_fatal('you must have create logger to use logger_info')
+      ENDIF
+   END SUBROUTINE logger_info
+   ! @endcode    
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write warning message on log file.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_msg : message to write
+   !> @param[in] ld_flush : flushing ouput
+   !
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE logger_warn(cd_msg, ld_flush)
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN)  :: cd_msg
+      LOGICAL,          INTENT(IN), OPTIONAL :: ld_flush
+      !----------------------------------------------------------------
+      IF( tm_logger%i_id /= 0 )THEN
+         IF( INDEX(TRIM(tm_logger%c_verb),'warn')/=0 )THEN
+
+            CALL logger__write("WARNING :",cd_msg)
+
+            IF( PRESENT(ld_flush) )THEN
+               IF( ld_flush )THEN
+                  CALL logger_flush()
+               ENDIF
+            ENDIF      
+         ENDIF
+      ELSE
+          CALL logger_open('logger.log')
+          CALL logger_header()
+          CALL logger_fatal('you must have create logger to use logger_warn')
+      ENDIF
+   END SUBROUTINE logger_warn
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write error message on log file.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_msg : message to write
+   !> @param[in] ld_flush : flushing ouput
+   !
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE logger_error(cd_msg, ld_flush)
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN)  :: cd_msg
+      LOGICAL,          INTENT(IN), OPTIONAL :: ld_flush
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_nerror
+      !----------------------------------------------------------------
+      IF( tm_logger%i_id /= 0 )THEN
+         ! increment the error number
+         tm_logger%i_nerror=tm_logger%i_nerror+1
+
+         IF( INDEX(TRIM(tm_logger%c_verb),'error')/=0 )THEN
+
+            CALL logger__write("ERROR   :",cd_msg)
+
+            IF( PRESENT(ld_flush) )THEN
+               IF( ld_flush )THEN
+                  CALL logger_flush()
+               ENDIF
+            ENDIF      
+         ENDIF
+
+         IF( tm_logger%i_nerror >= tm_logger%i_maxerror )THEN
+            WRITE(cl_nerror,*) tm_logger%i_maxerror
+            CALL logger_fatal(&
+            &  'Error count reached limit of '//TRIM(ADJUSTL(cl_nerror)) )
+         ENDIF
+      ELSE
+          CALL logger_open('logger.log')
+          CALL logger_header()
+          CALL logger_fatal('you must have create logger to use logger_error')
+      ENDIF
+
+   END SUBROUTINE logger_error
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write fatal error message on log file, 
+   !> close log file and stop process.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_msg : message to write
+   !
+   !-------------------------------------------------------------------
+   ! @code
+   RECURSIVE SUBROUTINE logger_fatal(cd_msg)
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),           INTENT(IN) :: cd_msg
+      !----------------------------------------------------------------
+      IF( tm_logger%i_id /= 0 )THEN
+         IF( INDEX(TRIM(tm_logger%c_verb),'fatal')/=0 )THEN
+            ! increment the error number
+            tm_logger%i_nfatal=tm_logger%i_nfatal+1
+
+            CALL logger__write("FATAL   :",cd_msg)
+
+            CALL logger_footer()
+            CALL logger_close()
+
+            STOP
+         ENDIF
+      ELSE
+          CALL logger_open('logger.log')
+          CALL logger_header()
+          CALL logger_fatal('you must have create logger to use logger_fatal')
+      ENDIF
+   END SUBROUTINE logger_fatal
+   ! @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine cut message to get maximum of 80 character 
+   !> by line in log file.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_verb : verbosity of the message to write
+   !> @param[in] cd_msg : message to write
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE logger__write(cd_verb, cd_msg)
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),           INTENT(IN) :: cd_verb
+      CHARACTER(LEN=*),           INTENT(IN) :: cd_msg
+
+      ! local variable
+      INTEGER(i4)       :: il_status
+      INTEGER(i4)       :: il_verb
+      INTEGER(i4)       :: il_msg
+      CHARACTER(LEN=lc) :: cl_verb
+      CHARACTER(LEN=lc) :: cl_msg
+      CHARACTER(LEN=lc) :: cl_tmp
+
+      !----------------------------------------------------------------
+      cl_verb=TRIM(ADJUSTL(cd_verb))
+      cl_msg=TRIM(ADJUSTL(cd_msg))
+
+      il_verb=LEN_TRIM(cl_verb)
+      il_msg=LEN_TRIM(cl_msg)
+      DO WHILE( il_verb + il_msg > 78 )
+         cl_tmp=TRIM(cl_verb)//' '//TRIM(cl_msg(1:78-il_verb))
+
+         WRITE( tm_logger%i_id,  &
+         &      FMT=*,           &
+         &      IOSTAT=il_status &
+         &      ) TRIM(cl_tmp)
+         CALL fct_err(il_status)
+
+
+         cl_msg=cl_msg(78-il_verb+1:il_msg)
+         cl_verb="        :"
+
+         il_msg=LEN_TRIM(cl_msg)
+
+      ENDDO
+
+      cl_tmp=TRIM(cl_verb)//' '//TRIM(cl_msg)
+      WRITE( tm_logger%i_id,  &
+      &      FMT=*,           &
+      &      IOSTAT=il_status &
+      &      ) TRIM(cl_tmp)
+      CALL fct_err(il_status)
+
+   END SUBROUTINE logger__write
+   ! @endcode   
+END MODULE logger
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/merge_bathy.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/merge_bathy.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/merge_bathy.f90	(revision 4245)
@@ -0,0 +1,884 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+!
+! PROGRAM: merge_bathy
+!
+! DESCRIPTION:
+!> @brief 
+!> This program merge bathymetry file at boundaries.
+!>
+!> @details
+!> Coarse grid Bathymetry is interpolated on fine grid. 
+!> Then fine Bathymetry and refined coarse bathymetry are merged at boundaries.
+!>
+!> BathyFine= weight * BathyCoarse + (1-weight)*BathyFine
+!>
+!> The weight function used is : 0.5 + 0.5*COS( (pi*dist) / width ) 
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!>
+!> @todo
+!----------------------------------------------------------------------
+!> @code
+PROGRAM merge_bathy
+
+   USE netcdf                          ! nf90 library
+   USE global                          ! global variable
+   USE phycst                          ! physical constant
+   USE kind                            ! F90 kind parameter
+   USE logger                          ! log file manager
+   USE fct                             ! basic useful function
+   USE date                            ! date manager
+   USE att                             ! attribute manager
+   USE dim                             ! dimension manager
+   USE var                             ! variable manager
+   USE file                            ! file manager
+   USE boundary                        ! boundary manager
+   USE iom                             ! I/O manager
+   USE dom                             ! domain manager
+   USE grid                            ! grid manager
+   USE extrap                          ! extrapolation manager
+   USE interp                          ! interpolation manager
+   USE filter                          ! filter manager
+   USE mpp                             ! MPP manager
+   USE iom_mpp                         ! MPP I/O manager
+
+   IMPLICIT NONE
+
+   ! local variable
+   CHARACTER(LEN=lc)                                  :: cl_namelist
+   CHARACTER(LEN=lc)                                  :: cl_date
+
+   INTEGER(i4)                                        :: il_narg
+   INTEGER(i4)                                        :: il_status
+   INTEGER(i4)                                        :: il_fileid
+   INTEGER(i4)                                        :: il_attid
+   INTEGER(i4)                                        :: il_imin0
+   INTEGER(i4)                                        :: il_imax0
+   INTEGER(i4)                                        :: il_jmin0
+   INTEGER(i4)                                        :: il_jmax0
+   INTEGER(i4)      , DIMENSION(ip_maxdim)            :: il_rho
+   INTEGER(i4)      , DIMENSION(2,2)                  :: il_offset
+   INTEGER(i4)      , DIMENSION(2,2,2)                :: il_ind
+!   INTEGER(i4)      , DIMENSION(:,:,:,:), ALLOCATABLE :: il_value
+
+   LOGICAL                                            :: ll_exist
+
+   REAL(dp)                                           :: dl_fill
+   REAL(dp)         , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_refined
+   REAL(dp)         , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_weight
+
+   TYPE(TFILE)                                        :: tl_bathy0
+   TYPE(TFILE)                                        :: tl_bathy1
+   TYPE(TFILE)                                        :: tl_fileout
+   
+   TYPE(TATT)                                         :: tl_att
+   
+   TYPE(TVAR)                                         :: tl_var
+   TYPE(TVAR)                                         :: tl_lon
+   TYPE(TVAR)                                         :: tl_lat
+!   TYPE(TVAR)                                         :: tl_depth
+!   TYPE(TVAR)                                         :: tl_time
+   
+   TYPE(TDIM)       , DIMENSION(ip_maxdim)            :: tl_dim
+   
+   TYPE(TBDY)       , DIMENSION(ip_ncard)             :: tl_bdy
+
+   ! loop indices
+   INTEGER(i4) :: ji
+   INTEGER(i4) :: jk
+   INTEGER(i4) :: jl
+
+   ! namelist variable
+   CHARACTER(LEN=lc)                       :: cn_logfile = 'merge_bathy.log' 
+   CHARACTER(LEN=lc)                       :: cn_verbosity = 'warning' 
+
+   CHARACTER(LEN=lc)                       :: cn_bathy0 = '' 
+   INTEGER(i4)                             :: in_perio0 = -1
+
+   CHARACTER(LEN=lc)                       :: cn_bathy1 = '' 
+   INTEGER(i4)                             :: in_perio1 = -1
+
+   CHARACTER(LEN=lc)                       :: cn_varcfg = 'variable.cfg' 
+
+   CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varinfo = ''
+
+   INTEGER(i4)                             :: in_imin0 = 0
+   INTEGER(i4)                             :: in_imax0 = 0
+   INTEGER(i4)                             :: in_jmin0 = 0
+   INTEGER(i4)                             :: in_jmax0 = 0
+   INTEGER(i4)                             :: in_rhoi  = 0
+   INTEGER(i4)                             :: in_rhoj  = 0
+
+   LOGICAL                                 :: ln_north = .TRUE.
+   LOGICAL                                 :: ln_south = .TRUE.
+   LOGICAL                                 :: ln_east  = .TRUE.
+   LOGICAL                                 :: ln_west  = .TRUE.
+   LOGICAL                                 :: ln_oneseg= .TRUE.
+   CHARACTER(LEN=lc)                       :: cn_north = ''
+   CHARACTER(LEN=lc)                       :: cn_south = ''
+   CHARACTER(LEN=lc)                       :: cn_east  = ''
+   CHARACTER(LEN=lc)                       :: cn_west  = ''
+
+   CHARACTER(LEN=lc)                       :: cn_fileout = 'bathy_merged.nc' 
+   !-------------------------------------------------------------------
+
+   NAMELIST /namlog/ &  !< logger namelist
+   &  cn_logfile,    &  !< log file
+   &  cn_verbosity      !< log verbosity
+
+   NAMELIST /namcfg/ &  !< config namelist
+   &  cn_varcfg         !< variable configuration file
+
+   NAMELIST /namcrs/ &  !< coarse grid namelist
+   &  cn_bathy0,  &     !< bathymetry file
+   &  in_perio0         !< periodicity index
+   
+   NAMELIST /namfin/ &  !< fine grid namelist
+   &  cn_bathy1,     &  !< bathymetry file
+   &  in_perio1         !< periodicity index
+ 
+   NAMELIST /namvar/ &  !< variable namelist
+   &  cn_varinfo        !< list of variable and interpolation 
+                        !< method to be used. 
+                        !< (ex: 'votemper|linear','vosaline|cubic' ) 
+   
+   NAMELIST /namnst/ &  !< nesting namelist
+   &  in_imin0,   &     !< i-direction lower left  point indice on coarse grid 
+   &  in_imax0,   &     !< i-direction upper right point indice on coarse grid
+   &  in_jmin0,   &     !< j-direction lower left  point indice on coarse grid
+   &  in_jmax0,   &     !< j-direction upper right point indice on coarse grid
+   &  in_rhoi,    &     !< refinement factor in i-direction
+   &  in_rhoj           !< refinement factor in j-direction
+
+   NAMELIST /nambdy/ &  !< boundary namelist
+   &  ln_north,   &     !< use north boundary
+   &  ln_south,   &     !< use south boundary
+   &  ln_east ,   &     !< use east  boundary
+   &  ln_west ,   &     !< use west  boundary
+   &  cn_north,   &     !< north boundary indices on fine grid
+   &  cn_south,   &     !< south boundary indices on fine grid
+   &  cn_east ,   &     !< east  boundary indices on fine grid
+   &  cn_west ,   &     !< west  boundary indices on fine grid
+   &  ln_oneseg         !< use only one segment for each boundary or not
+
+   NAMELIST /namout/ &  !< output namelist
+   &  cn_fileout       !< fine grid merged bathymetry file   
+   !-------------------------------------------------------------------
+
+   !1- namelist
+   !1-1 get namelist
+   il_narg=COMMAND_ARGUMENT_COUNT() !f03 intrinsec
+   IF( il_narg/=1 )THEN
+      PRINT *,"MERGE BATHY: ERROR. need a namelist"
+      STOP
+   ELSE
+      CALL GET_COMMAND_ARGUMENT(1,cl_namelist) !f03 intrinsec
+   ENDIF
+   
+   !1-2 read namelist
+   INQUIRE(FILE=TRIM(cl_namelist), EXIST=ll_exist)
+   IF( ll_exist )THEN
+      
+      il_fileid=fct_getunit()
+
+      OPEN( il_fileid, FILE=TRIM(cl_namelist), &
+      &                FORM='FORMATTED',       &
+      &                ACCESS='SEQUENTIAL',    &
+      &                STATUS='OLD',           &
+      &                ACTION='READ',          &
+      &                IOSTAT=il_status)
+      CALL fct_err(il_status)
+      IF( il_status /= 0 )THEN
+         PRINT *,"MERGE BATHY: ERROR opening "//TRIM(cl_namelist)
+         STOP
+      ENDIF
+
+      READ( il_fileid, NML = namlog )
+      !1-2-1 define log file
+      CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity))
+      CALL logger_header()
+
+      READ( il_fileid, NML = namcfg )
+      !1-2-2 get variable extra information
+      CALL var_def_extra(TRIM(cn_varcfg))
+
+      READ( il_fileid, NML = namcrs )
+      READ( il_fileid, NML = namfin )
+      READ( il_fileid, NML = namvar )
+      !1-2-3 add user change in extra information
+      CALL var_chg_extra(cn_varinfo)
+
+      READ( il_fileid, NML = namnst )
+      READ( il_fileid, NML = nambdy )
+
+      READ( il_fileid, NML = namout )
+
+      CLOSE( il_fileid, IOSTAT=il_status )
+      CALL fct_err(il_status)
+      IF( il_status /= 0 )THEN
+         CALL logger_error("MERGE BATHY: ERROR closing "//TRIM(cl_namelist))
+      ENDIF
+
+   ELSE
+
+      PRINT *,"MERGE BATHY: ERROR. can not find "//TRIM(cl_namelist)
+
+   ENDIF
+
+   !2- open files
+   IF( TRIM(cn_bathy0) /= '' )THEN
+      tl_bathy0=file_init(TRIM(cn_bathy0),id_perio=in_perio0)
+      CALL iom_open(tl_bathy0)
+   ELSE
+      CALL logger_fatal("MERGE BATHY: can not find coarse grid bathymetry "//&
+      &  "file. check namelist")
+   ENDIF
+
+   IF( TRIM(cn_bathy1) /= '' )THEN
+      tl_bathy1=file_init(TRIM(cn_bathy1),id_perio=in_perio1)
+      CALL iom_open(tl_bathy1)
+   ELSE
+      CALL logger_fatal("MERGE BATHY: can not find fine grid bathymetry "//&
+      &  "file. check namelist")
+   ENDIF
+
+   !3- check
+   !3-1 check output file do not already exist
+   INQUIRE(FILE=TRIM(cn_fileout), EXIST=ll_exist)
+   IF( ll_exist )THEN
+      CALL logger_fatal("CREATE BATHY: output file "//TRIM(cn_fileout)//&
+      &  " already exist.")
+   ENDIF
+
+   !3-2 check namelist
+   !3-2-1 check refinament factor
+   il_rho(:)=1
+   IF( in_rhoi < 1 .OR. in_rhoj < 1 )THEN
+      CALL logger_error("MERGE BATHY: invalid refinement factor."//&
+      &  " check namelist "//TRIM(cl_namelist))
+   ELSE
+      il_rho(jp_I)=in_rhoi
+      il_rho(jp_J)=in_rhoj
+   ENDIF
+
+   !3-2-2 check domain indices
+   IF( in_imin0 < 1 .OR. in_imax0 < 1 .OR. in_jmin0 < 1 .OR. in_jmax0 < 1)THEN
+      ! compute coarse grid indices around fine grid
+      il_ind(:,:,:)=grid_get_coarse_index(tl_bathy0, tl_bathy1 )
+
+      il_imin0=il_ind(1,1,1) ; il_imax0=il_ind(1,2,1)
+      il_jmin0=il_ind(2,1,1) ; il_jmax0=il_ind(2,2,1)
+
+      il_offset(:,:)=il_ind(:,:,2)
+   ELSE
+      il_imin0=in_imin0 ; il_imax0=in_imax0
+      il_jmin0=in_jmin0 ; il_jmax0=in_jmax0
+
+      il_offset(1,:)=FLOOR(REAL(il_rho(jp_I)-1,dp)*0.5)
+      il_offset(2,:)=FLOOR(REAL(il_rho(jp_J)-1,dp)*0.5)
+   ENDIF
+
+   !3-3 check domain validity
+   CALL grid_check_dom(tl_bathy0, il_imin0, il_imax0, il_jmin0, il_jmax0)
+
+   !3-4 check coincidence between coarse and fine grid
+   CALL grid_check_coincidence( tl_bathy0, tl_bathy1, &
+   &                            il_imin0, il_imax0, &
+   &                            il_jmin0, il_jmax0, &
+   &                            il_rho(:) )
+
+   !4- read or compute boundary
+   tl_var=iom_read_var(tl_bathy1,'Bathymetry')
+
+   tl_bdy(:)=boundary_init(tl_var, ln_north, ln_south, ln_east, ln_west, &
+   &                               cn_north, cn_south, cn_east, cn_west, &
+   &                               ln_oneseg ) 
+
+   !5- get boundary on coarse grid
+   !5-1 define refined bathymetry table (for coarse grid)
+   dl_fill=tl_var%d_fill
+   ALLOCATE( dl_refined(tl_var%t_dim(1)%i_len, &
+   &                    tl_var%t_dim(2)%i_len, &
+   &                    tl_var%t_dim(3)%i_len, &
+   &                    tl_var%t_dim(4)%i_len) )
+
+   dl_refined(:,:,:,:)=dl_fill
+
+   !5-2 define weight table
+   ALLOCATE( dl_weight(tl_var%t_dim(1)%i_len, &
+   &                   tl_var%t_dim(2)%i_len, &
+   &                   1,1) )
+
+   dl_weight(:,:,:,:)=dl_fill 
+
+   !5-3 compute coarse grid refined bathymetry on boundary.
+   DO jk=1,ip_ncard
+
+      CALL merge_bathy_get_boundary(tl_bathy0, tl_bathy1, tl_bdy(jk), &
+      &                             il_rho(:),                        &
+      &                             dl_refined(:,:,:,:), dl_weight(:,:,:,:), &
+      &                             dl_fill)
+
+   ENDDO
+
+   !6- merge bathy on boundary
+   DO jl=1,tl_var%t_dim(4)%i_len
+      DO jk=1,tl_var%t_dim(3)%i_len
+         WHERE(    dl_refined(:,:,jk,jl) /= dl_fill .AND. &
+         &      tl_var%d_value(:,:,jk,jl)/= tl_var%d_fill )
+            tl_var%d_value(:,:,jk,jl)=  &
+            &           dl_weight(:,:,1,1) *    dl_refined(:,:,jk,jl) + &
+            &        (1-dl_weight(:,:,1,1))*tl_var%d_value(:,:,jk,jl)
+         ELSE WHERE( dl_refined(:,:,jk,jl)== dl_fill .AND. &
+         &           dl_weight(:,:,1,1)  /= dl_fill )
+         ! to keep coarse grid mask on boundary
+            tl_var%d_value(:,:,jk,jl)=dl_fill
+         END WHERE
+      ENDDO
+   ENDDO
+
+   DEALLOCATE(dl_refined)
+
+   !7- create file
+   tl_fileout=file_init(TRIM(cn_fileout),id_perio=in_perio1)
+
+   !7-1 add dimension
+   tl_dim(:)=tl_var%t_dim(:)
+
+   DO ji=1,ip_maxdim
+      IF( tl_dim(ji)%l_use ) CALL file_add_dim(tl_fileout, tl_dim(ji))
+   ENDDO
+
+   !7-2 add variables
+   IF( ALL( tl_dim(1:2)%l_use ) )THEN
+
+      tl_lon=iom_read_var(tl_bathy1,'longitude')
+      CALL file_add_var(tl_fileout, tl_lon)
+      CALL var_clean(tl_lon)
+
+      tl_lat=iom_read_var(tl_bathy1,'latitude')
+      CALL file_add_var(tl_fileout, tl_lat)
+      CALL var_clean(tl_lat)
+
+   ENDIF
+
+   CALL file_add_var(tl_fileout, tl_var)
+   CALL var_clean(tl_var)
+
+   ! only 2 first dimension to be used
+   tl_dim(:)=tl_fileout%t_dim(:)
+   tl_dim(3:4)%l_use=.FALSE.
+   tl_var=var_init('weight',dl_weight(:,:,:,:),td_dim=tl_dim(:),dd_fill=dl_fill)
+   CALL file_add_var(tl_fileout, tl_var)
+   CALL var_clean(tl_var)
+
+   !7-3 add some attribute
+   tl_att=att_init("Created_by","SIREN merge_bathy")
+   CALL file_add_att(tl_fileout, tl_att)
+
+   cl_date=date_print(date_now())
+   tl_att=att_init("Creation_date",cl_date)
+   CALL file_add_att(tl_fileout, tl_att)
+
+   tl_att=att_init("coarse_grid_source_file",TRIM(fct_basename(tl_bathy0%c_name)))
+   CALL file_add_att(tl_fileout, tl_att)
+
+   tl_att=att_init("fine_grid_source_file",TRIM(fct_basename(tl_bathy1%c_name)))
+   CALL file_add_att(tl_fileout, tl_att)
+
+   ! a voir
+   ! add attribute periodicity
+   il_attid=0
+   IF( ASSOCIATED(tl_fileout%t_att) )THEN
+      il_attid=att_get_id(tl_fileout%t_att(:),'periodicity')
+   ENDIF
+   IF( tl_bathy1%i_perio >= 0 .AND. il_attid == 0 )THEN
+      tl_att=att_init('periodicity',tl_bathy1%i_perio)
+      CALL file_add_att(tl_fileout,tl_att)
+   ENDIF
+
+   il_attid=0
+   IF( ASSOCIATED(tl_fileout%t_att) )THEN
+      il_attid=att_get_id(tl_fileout%t_att(:),'ew_overlap')
+   ENDIF
+   IF( tl_bathy1%i_ew >= 0 .AND. il_attid == 0 )THEN
+      tl_att=att_init('ew_overlap',tl_bathy1%i_ew)
+      CALL file_add_att(tl_fileout,tl_att)
+   ENDIF
+
+   !7-4 create file
+   CALL iom_create(tl_fileout)
+
+   !7-5 write file
+   CALL iom_write_file(tl_fileout)
+
+   !7-6 close file
+   CALL iom_close(tl_fileout)
+
+   CALL iom_close(tl_bathy1)
+   CALL iom_close(tl_bathy0)
+
+   !8- clean
+   CALL file_clean(tl_fileout)
+   CALL file_clean(tl_bathy1)
+   CALL file_clean(tl_bathy0)
+   DEALLOCATE(dl_weight)
+
+   ! close log file
+   CALL logger_footer()
+   CALL logger_close()
+
+!> @endcode
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] 
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE merge_bathy_get_boundary( td_bathy0, td_bathy1, td_bdy, &
+   &                                    id_rho,                       &
+   &                                    dd_refined, dd_weight, dd_fill )
+
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TFILE)                    , INTENT(IN   ) :: td_bathy0
+      TYPE(TFILE)                    , INTENT(IN   ) :: td_bathy1
+      TYPE(TBDY)                     , INTENT(IN   ) :: td_bdy
+      INTEGER(i4), DIMENSION(:)      , INTENT(IN   ) :: id_rho
+      REAL(dp)   , DIMENSION(:,:,:,:), INTENT(INOUT) :: dd_refined
+      REAL(dp)   , DIMENSION(:,:,:,:), INTENT(INOUT) :: dd_weight
+      REAL(dp)                       , INTENT(IN   ) :: dd_fill  
+
+      ! local variable
+      INTEGER(i4) :: il_imin1
+      INTEGER(i4) :: il_imax1
+      INTEGER(i4) :: il_jmin1
+      INTEGER(i4) :: il_jmax1
+      
+      INTEGER(i4) :: il_imin0
+      INTEGER(i4) :: il_imax0
+      INTEGER(i4) :: il_jmin0
+      INTEGER(i4) :: il_jmax0
+
+      INTEGER(i4) :: il_imin
+      INTEGER(i4) :: il_imax
+      INTEGER(i4) :: il_jmin
+      INTEGER(i4) :: il_jmax
+
+      INTEGER(i4), DIMENSION(2,2)         :: il_offset
+      INTEGER(i4), DIMENSION(2,2,2)       :: il_ind
+
+      REAL(dp)   , DIMENSION(:)      , ALLOCATABLE :: dl_tmp1d
+      REAL(dp)   , DIMENSION(:,:)    , ALLOCATABLE :: dl_tmp2d
+      REAL(dp)   , DIMENSION(:,:)    , ALLOCATABLE :: dl_wseg
+
+      TYPE(TVAR) :: tl_var0
+      TYPE(TVAR) :: tl_lon1
+      TYPE(TVAR) :: tl_lat1
+
+      TYPE(TFILE) :: tl_bathy1
+      TYPE(TFILE) :: tl_bathy0
+
+      TYPE(TMPP)  :: tl_mppbathy1
+      TYPE(TMPP)  :: tl_mppbathy0
+
+      TYPE(TDOM)  :: tl_dom1
+      TYPE(TDOM)  :: tl_dom0
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jl
+      !----------------------------------------------------------------
+
+      IF( td_bdy%l_use )THEN
+         DO jl=1,td_bdy%i_nseg
+            
+            !1- get boundary definition
+            SELECT CASE(TRIM(td_bdy%c_card))
+            CASE('north')
+
+               il_imin1=td_bdy%t_seg(jl)%i_first
+               il_imax1=td_bdy%t_seg(jl)%i_last 
+               il_jmin1=td_bdy%t_seg(jl)%i_index-(td_bdy%t_seg(jl)%i_width-1)
+               il_jmax1=td_bdy%t_seg(jl)%i_index
+
+               il_imin=1
+               il_imax=il_imax1-il_imin1+1
+               il_jmin=td_bdy%t_seg(jl)%i_width
+               il_jmax=1
+
+            CASE('south')
+
+               il_imin1=td_bdy%t_seg(jl)%i_first
+               il_imax1=td_bdy%t_seg(jl)%i_last 
+               il_jmin1=td_bdy%t_seg(jl)%i_index
+               il_jmax1=td_bdy%t_seg(jl)%i_index+(td_bdy%t_seg(jl)%i_width-1)
+
+               il_imin=1
+               il_imax=il_imax1-il_imin1+1
+               il_jmin=1
+               il_jmax=td_bdy%t_seg(jl)%i_width
+               
+            CASE('east')
+
+               il_imin1=td_bdy%t_seg(jl)%i_index-(td_bdy%t_seg(jl)%i_width-1)
+               il_imax1=td_bdy%t_seg(jl)%i_index
+               il_jmin1=td_bdy%t_seg(jl)%i_first
+               il_jmax1=td_bdy%t_seg(jl)%i_last 
+
+               il_imin=td_bdy%t_seg(jl)%i_width
+               il_imax=1
+               il_jmin=1
+               il_jmax=il_jmax1-il_jmin1+1
+
+            CASE('west')
+
+               il_imin1=td_bdy%t_seg(jl)%i_index
+               il_imax1=td_bdy%t_seg(jl)%i_index+(td_bdy%t_seg(jl)%i_width-1)
+               il_jmin1=td_bdy%t_seg(jl)%i_first
+               il_jmax1=td_bdy%t_seg(jl)%i_last 
+
+               il_imin=1
+               il_imax=td_bdy%t_seg(jl)%i_width
+               il_jmin=1
+               il_jmax=il_jmax1-il_jmin1+1
+
+            END SELECT
+
+            !2 -read fine grid domain
+            tl_bathy1=td_bathy1
+            CALL iom_open(tl_bathy1)
+
+            !2-1 compute domain
+            tl_dom1=dom_init( tl_bathy1,         &
+            &                 il_imin1, il_imax1,&
+            &                 il_jmin1, il_jmax1 )
+
+            !2-2 close file
+            CALL iom_close(tl_bathy1)
+
+            !2-3 read variables on domain (ugly way to do it, have to work on it)
+            !2-3-1 init mpp structure
+            tl_mppbathy1=mpp_init(tl_bathy1)
+ 
+            CALL file_clean(tl_bathy1)
+
+            !2-3-2 get processor to be used
+            CALL mpp_get_use( tl_mppbathy1, tl_dom1 )
+
+            !2-3-3 open mpp files
+            CALL iom_mpp_open(tl_mppbathy1)
+
+            !2-3-4 read variable value on domain
+            tl_lon1=iom_mpp_read_var(tl_mppbathy1,'longitude',td_dom=tl_dom1)
+            tl_lat1=iom_mpp_read_var(tl_mppbathy1,'latitude' ,td_dom=tl_dom1)
+
+            !2-3-5 close mpp files
+            CALL iom_mpp_close(tl_mppbathy1)
+
+            !2-3-6 clean structure
+            CALL mpp_clean(tl_mppbathy1)
+
+            !3- get coarse grid indices
+            il_ind(:,:,:)=grid_get_coarse_index(td_bathy0, tl_lon1, tl_lat1, &
+            &                                   id_rho=id_rho(:))
+
+            il_imin0=il_ind(1,1,1)
+            il_imax0=il_ind(1,2,1)
+
+            il_jmin0=il_ind(2,1,1)
+            il_jmax0=il_ind(2,2,1)
+
+            il_offset(:,:)=il_ind(:,:,2)
+
+            !4- read coarse grid bathymetry on domain
+            tl_bathy0=td_bathy0
+            CALL iom_open(tl_bathy0)
+
+            !4-1 compute domain
+            tl_dom0=dom_init( tl_bathy0,         &
+            &                 il_imin0, il_imax0,&
+            &                 il_jmin0, il_jmax0 )
+
+            !4-2 close file
+            CALL iom_close(tl_bathy0)
+
+            !4-3 add extra band (if possible) to compute interpolation
+            CALL dom_add_extra(tl_dom0)
+
+            !4-4 read variables on domain (ugly way to do it, have to work on it)
+            !4-4-1 init mpp structure
+            tl_mppbathy0=mpp_init(tl_bathy0)
+            
+            CALL file_clean(tl_bathy0)
+
+            !4-4-2 get processor to be used
+            CALL mpp_get_use( tl_mppbathy0, tl_dom0 )
+
+            !4-4-3 open mpp files
+            CALL iom_mpp_open(tl_mppbathy0)
+
+            !4-4-4 read variable value on domain
+            tl_var0=iom_mpp_read_var(tl_mppbathy0,'Bathymetry',td_dom=tl_dom0)
+
+            !4-4-5 close mpp files
+            CALL iom_mpp_close(tl_mppbathy0)
+
+            !4-4-6 clean structure
+            CALL mpp_clean(tl_mppbathy0)
+
+            !5- interpolate variable
+            CALL merge_bathy_interp( tl_var0,         &
+            &                        id_rho(:),       &
+            &                        il_offset(:,:) )
+
+            !6- remove extraband added to domain
+            CALL dom_del_extra( tl_var0, tl_dom0, id_rho(:) )
+
+            !6-1 remove extraband added to domain
+            CALL dom_clean_extra( tl_dom0 )
+
+            !7- fill refined table  
+            !7-1 keep only useful point
+            ! interpolation could create more point than necessary
+            CALL boundary_clean_interp(tl_var0, td_bdy )
+
+            ! use add request ????
+
+            !7-2 fill refined table
+            dd_refined( il_imin1:il_imax1, &
+            &           il_jmin1:il_jmax1, &
+            &           :,: )= tl_var0%d_value(:,:,:,:)
+
+            !8- compute weight function
+            ALLOCATE( dl_tmp1d(td_bdy%t_seg(jl)%i_width) )
+
+            SELECT CASE(TRIM(td_bdy%c_card))
+            CASE('north')
+
+               ! compute "distance"
+               dl_tmp1d(:)=(/(ji-1,ji=td_bdy%t_seg(jl)%i_width,1,-1)/)
+
+               ! compute weight on segment
+               dl_tmp1d(:)= 0.5 + 0.5*COS( (dg_pi*dl_tmp1d(:)) / &
+               &                           (td_bdy%t_seg(jl)%i_width) )
+
+               ALLOCATE( dl_wseg(tl_dom1%t_dim(1)%i_len, &
+               &                 tl_dom1%t_dim(2)%i_len) )
+               dl_wseg(:,:)=dd_fill
+               dl_wseg(:,:)=SPREAD( dl_tmp1d(:), &
+               &                    DIM=1,       &
+               &                    NCOPIES=tl_dom1%t_dim(1)%i_len )
+
+            CASE('south')
+
+               ! compute "distance"
+               dl_tmp1d(:)=(/(ji-1,ji=1,td_bdy%t_seg(jl)%i_width)/)               
+
+               ! compute weight on segment
+               dl_tmp1d(:)= 0.5 + 0.5*COS( (dg_pi*dl_tmp1d(:)) / &
+               &                           (td_bdy%t_seg(jl)%i_width) )
+
+               ALLOCATE( dl_wseg(tl_dom1%t_dim(1)%i_len, &
+               &                 tl_dom1%t_dim(2)%i_len) )
+               dl_wseg(:,:)=dd_fill
+               dl_wseg(:,:)=SPREAD( dl_tmp1d(:), &
+               &                    DIM=1,       &
+               &                    NCOPIES=tl_dom1%t_dim(1)%i_len )
+
+            CASE('east')
+
+               ! compute "distance"
+               dl_tmp1d(:)=(/(ji-1,ji=td_bdy%t_seg(jl)%i_width,1,-1)/)
+
+               ! compute weight on segment
+               dl_tmp1d(:)= 0.5 + 0.5*COS( (dg_pi*dl_tmp1d(:)) / &
+               &                           (td_bdy%t_seg(jl)%i_width) )
+
+               ALLOCATE( dl_wseg(tl_dom1%t_dim(1)%i_len, &
+               &                 tl_dom1%t_dim(2)%i_len) )
+               dl_wseg(:,:)=dd_fill
+               dl_wseg(:,:)=SPREAD( dl_tmp1d(:), &
+               &                    DIM=2,       &
+               &                    NCOPIES=tl_dom1%t_dim(2)%i_len )
+
+            CASE('west')
+
+               ! compute "distance"
+               dl_tmp1d(:)=(/(ji-1,ji=1,td_bdy%t_seg(jl)%i_width)/)               
+
+               ! compute weight on segment
+               dl_tmp1d(:)= 0.5 + 0.5*COS( (dg_pi*dl_tmp1d(:)) / &
+               &                           (td_bdy%t_seg(jl)%i_width) )
+
+               ALLOCATE( dl_wseg(tl_dom1%t_dim(1)%i_len, &
+               &                 tl_dom1%t_dim(2)%i_len) )
+               dl_wseg(:,:)=dd_fill
+               dl_wseg(:,:)=SPREAD( dl_tmp1d(:), &
+               &                    DIM=2,       &
+               &                    NCOPIES=tl_dom1%t_dim(2)%i_len )
+
+            END SELECT
+
+            DEALLOCATE( dl_tmp1d )
+
+            !8-1 fill weight table
+            ALLOCATE( dl_tmp2d( tl_dom1%t_dim(1)%i_len, &
+            &                   tl_dom1%t_dim(2)%i_len) )
+
+            dl_tmp2d(:,:)=dd_weight( il_imin1:il_imax1, &
+            &                        il_jmin1:il_jmax1, &
+            &                        1,1 )
+
+            WHERE( dl_tmp2d(:,:) == dd_fill )
+               dl_tmp2d(:,:)= dl_wseg(:,:)
+            ELSE WHERE
+               dl_tmp2d(:,:)= MAX( dl_tmp2d(:,:), dl_wseg(:,:) )
+            END WHERE
+
+            dd_weight( il_imin1:il_imax1, &
+            &          il_jmin1:il_jmax1, &
+            &          1,1 ) = dl_tmp2d(:,:)
+
+            DEALLOCATE( dl_wseg )
+            DEALLOCATE( dl_tmp2d )
+
+         ENDDO
+      ENDIF
+   END SUBROUTINE merge_bathy_get_boundary
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !>
+   !> @param[in] 
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE merge_bathy_interp( td_var,          &
+   &                              id_rho,          &
+   &                              id_offset,       &
+   &                              id_iext, id_jext)
+
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TVAR) ,                 INTENT(INOUT) :: td_var
+      INTEGER(i4), DIMENSION(:)  , INTENT(IN   ) :: id_rho
+      INTEGER(i4), DIMENSION(:,:), INTENT(IN   ) :: id_offset
+      INTEGER(i4),                 INTENT(IN   ), OPTIONAL :: id_iext
+      INTEGER(i4),                 INTENT(IN   ), OPTIONAL :: id_jext
+
+      ! local variable
+      TYPE(TVAR)  :: tl_var
+      TYPE(TVAR)  :: tl_mask
+
+      INTEGER(i1), DIMENSION(:,:,:,:), ALLOCATABLE :: bl_mask
+
+      INTEGER(i4) :: il_iext
+      INTEGER(i4) :: il_jext
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! copy variable
+      tl_var=td_var
+
+      !WARNING: two extrabands are required for cubic interpolation
+      il_iext=3
+      IF( PRESENT(id_iext) ) il_iext=id_iext
+
+      il_jext=3
+      IF( PRESENT(id_jext) ) il_jext=id_jext
+
+      IF( il_iext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN
+         CALL logger_warn("CREATE BATHY INTERP: at least extrapolation "//&
+         &  "on two points are required with cubic interpolation ")
+         il_iext=2
+      ENDIF
+
+      IF( il_jext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN
+         CALL logger_warn("CREATE BATHY INTERP: at least extrapolation "//&
+         &  "on two points are required with cubic interpolation ")
+         il_jext=2
+      ENDIF
+
+      !1- work on mask
+      !1-1 create mask
+      ALLOCATE(bl_mask(tl_var%t_dim(1)%i_len, &
+      &                tl_var%t_dim(2)%i_len, &
+      &                tl_var%t_dim(3)%i_len, &
+      &                tl_var%t_dim(4)%i_len) )
+
+      bl_mask(:,:,:,:)=1
+      WHERE(tl_var%d_value(:,:,:,:)==tl_var%d_fill) bl_mask(:,:,:,:)=0      
+
+      SELECT CASE(TRIM(tl_var%c_point))
+      CASE DEFAULT ! 'T'
+         tl_mask=var_init('tmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
+      CASE('U')
+         tl_mask=var_init('umask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
+      CASE('V')
+         tl_mask=var_init('vmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
+      CASE('F')
+         tl_mask=var_init('fmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
+      END SELECT
+
+      DEALLOCATE(bl_mask)
+
+      !1-2 interpolate mask
+      CALL interp_fill_value( tl_mask, id_rho(:),  &
+      &                       id_offset=id_offset(:,:) )
+
+      !2- work on variable
+      !2-0 add extraband
+      CALL extrap_add_extrabands(tl_var, il_iext, il_iext)
+
+      !2-1 extrapolate variable
+      CALL extrap_fill_value( tl_var, id_offset=id_offset(:,:), &
+      &                               id_rho=id_rho(:),         &
+      &                               id_iext=il_iext, id_jext=il_jext )
+
+      !2-2 interpolate Bathymetry
+      CALL interp_fill_value( tl_var, id_rho(:), &
+      &                       id_offset=id_offset(:,:) )
+
+      !2-3 remove extraband
+      CALL extrap_del_extrabands(tl_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J))
+
+      !2-4 keep original mask 
+      WHERE( tl_mask%d_value(:,:,:,:) == 0 )
+         tl_var%d_value(:,:,:,:)=tl_var%d_fill
+      END WHERE
+
+      !3- save result
+      td_var=tl_var
+
+      ! clean variable structure
+      CALL var_clean(tl_var)
+
+   END SUBROUTINE merge_bathy_interp
+   !> @endcode
+END PROGRAM merge_bathy
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/mpp.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/mpp.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/mpp.f90	(revision 4245)
@@ -0,0 +1,3204 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: mpp
+!
+!
+! DESCRIPTION:
+!> This module manage massively parallel processing
+!
+!> @details
+!> define type TMPP:<br/>
+!> TYPE(TMPP) :: tl_mpp<br/>
+!>
+!>    to initialise a mpp structure:<br/>
+!>    - tl_mpp=mpp_init( cd_file, id_mask, [id_niproc,] [id_njproc,] 
+!>         [id_nproc] [id_preci,] [id_precj,] [cd_type])
+!>    - tl_mpp=mpp_init( cd_file, td_var, [id_niproc,] [id_njproc,] 
+!>         [id_nproc] [id_preci,] [id_precj,] [cd_type])
+!>    - tl_mpp=mpp_init( td_file )
+!>       - cd_file is the filename of the global domain file, in which 
+!>         MPP will be done (example: Bathymetry) 
+!>       - td_file is the file structure of one processor file composing an MPP
+!>       - id_mask is the 2D mask of global domain 
+!>       - td_var is a variable structure (on T-point) from global domain file.
+!>         mask of the domain will be computed using FillValue
+!>       - id_niproc is the number of processor following I-direction to be used
+!>         (optional)
+!>       - id_njproc is the number of processor following J-direction to be used 
+!>         (optional)
+!>       - id_nproc is the total number of processor to be used (optional)
+!>       - id_preci is the size of the overlap region following I-direction
+!>       - id_precj is the size of the overlap region following J-direction
+!>       - cd_type is the type of files composing MPP<br/>
+!>  
+!>    to get mpp name:<br/>
+!>    - tl_mpp\%c_name
+!>
+!>    to get the total number of processor:<br/>
+!>    - tl_mpp\%i_nproc
+!>
+!>    to get the number of processor following I-direction:<br/>
+!>    - tl_mpp\%i_niproc
+!>
+!>    to get the number of processor following J-direction:<br/>
+!>    - tl_mpp\%i_njproc
+!>
+!>    to get the length of the overlap region following I-direction:<br/>
+!>    - tl_mpp\%i_preci
+!>
+!>    to get the length of the overlap region following J-direction:<br/>
+!>    - tl_mpp\%i_precj
+!>
+!>    to get the type of files composing mpp structure:<br/>
+!>    - tl_mpp\%c_type
+!>
+!>    to get the type of the global domain:<br/>
+!>    - tl_mpp\%c_dom
+!>
+!>    MPP dimensions (global domain)<br/>
+!>    to get the number of dimensions to be used in mpp strcuture:<br/>
+!>    - tl_mpp\%i_ndim
+!>
+!>    to get the table of dimension structure (4 elts) associated to the
+!>    mpp structure:<br/>
+!>    - tl_mpp\%t_dim(:)
+!>
+!>    MPP processor (files composing domain)<br/>
+!>    - tl_mpp\%t_proc(:)
+!>
+!>    to clean a mpp structure:<br/>
+!>    - CALL mpp_clean(tl_mpp)
+!>
+!>    to print information about mpp:<br/>
+!>    CALL mpp_print(tl_mpp)
+!>
+!>    to add variable to mpp:<br/>
+!>    CALL mpp_add_var(td_mpp, td_var)
+!>       - td_var is a variable structure
+!>
+!>    to add dimension to mpp:<br/>
+!>    CALL mpp_add_dim(td_mpp, td_dim)
+!>       - td_dim is a dimension structure
+!>
+!>    to delete variable to mpp:<br/>
+!>    CALL mpp_del_var(td_mpp, td_var)
+!>       - td_var is a variable structure
+!>
+!>    to delete dimension to mpp:<br/>
+!>    CALL mpp_del_dim(td_mpp, td_dim)
+!>       - td_dim is a dimension structure
+!>
+!>    to overwrite variable to mpp:<br/>
+!>    CALL mpp_move_var(td_mpp, td_var)
+!>       - td_var is a variable structure
+!>
+!>    to overwrite dimension to mpp:<br/>
+!>    CALL mpp_move_dim(td_mpp, td_dim)
+!>       - td_dim is a dimension structure
+!>
+!>    to determine domain decomposition type:<br/>
+!>    CALL mpp_get_dom(td_mpp)
+!>
+!>    to get processors to be used:<br/>
+!>    CALL mpp_get_use( td_mpp, td_dom )
+!>       - td_dom is a domain structure
+!>
+!>    to get sub domains which form global domain contour:<br/>
+!>    CALL mpp_get_contour( td_mpp ) 
+!>
+!>    to get global domain indices of one processor:<br/>
+!>    il_ind(1:4)=mpp_get_proc_index( td_mpp, id_procid )
+!>       - il_ind(1:4) are global domain indices (i1,i2,j1,j2)
+!>       - id_procid is the processor id
+!>
+!>    to get the processor domain size:<br/>
+!>    il_size(1:2)=mpp_get_proc_size( td_mpp, id_procid )
+!>       - il_size(1:2) are the size of domain following I and J
+!>       - id_procid is the processor id
+!>
+!> @author
+!>  J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!> @todo
+!>  - add description generique de l'objet mpp
+!>  - mpp_print
+!>  - voir pour mettre cd_file systematiquement pour mpp_init
+!>  + modifier utilisation la haut
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!----------------------------------------------------------------------
+MODULE mpp
+   USE kind                            ! F90 kind parameter
+   USE logger                             ! log file manager
+   USE fct                             ! basic useful function
+   USE dim                             ! dimension manager
+   USE att                             ! attribute manager
+   USE var                             ! variable manager
+   USE file                            ! file manager
+   USE iom                             ! I/O manager
+!   USE proc                            ! proc manager
+   USE dom                             ! domain manager
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+   PUBLIC :: TMPP       ! mpp structure
+
+   ! function and subroutine
+   PUBLIC :: ASSIGNMENT(=)      !< copy mpp structure
+   PUBLIC :: mpp_init           !< initialise mpp structure
+   PUBLIC :: mpp_clean          !< clean mpp strcuture
+   PUBLIC :: mpp_print          !< print information about mpp structure
+   PUBLIC :: mpp_add_var        !< split/add one variable strucutre in mpp structure
+   PUBLIC :: mpp_add_dim        !< add one dimension to mpp structure
+   PUBLIC :: mpp_add_att        !< add one attribute strucutre in mpp structure
+   PUBLIC :: mpp_del_var        !< delete one variable strucutre in mpp structure
+   PUBLIC :: mpp_del_dim        !< delete one dimension strucutre in mpp structure
+   PUBLIC :: mpp_del_att        !< delete one attribute strucutre in mpp structure
+   PUBLIC :: mpp_move_var       !< overwrite variable structure in mpp structure
+   PUBLIC :: mpp_move_dim       !< overwrite one dimension strucutre in mpp structure
+   PUBLIC :: mpp_move_att       !< overwrite one attribute strucutre in mpp structure
+
+   PUBLIC :: mpp_get_dom        !< determine domain decomposition type (full, overlap, noverlap)
+   PUBLIC :: mpp_get_use        !< get sub domains to be used (which cover "zoom domain")
+   PUBLIC :: mpp_get_contour    !< get sub domains which form global domain contour
+   PUBLIC :: mpp_get_proc_index !< get processor domain indices
+   PUBLIC :: mpp_get_proc_size  !< get processor domain size
+
+   PRIVATE :: mpp__add_proc     !< add one proc strucutre in mpp structure
+   PRIVATE :: mpp__del_proc     !< delete one proc strucutre in mpp structure
+   PRIVATE :: mpp__move_proc    !< overwrite proc strucutre in mpp structure
+   PRIVATE :: mpp__compute      !< compute domain decomposition
+   PRIVATE :: mpp__del_land     !< remove land sub domain from domain decomposition
+   PRIVATE :: mpp__optimiz      !< compute optimum domain decomposition
+   PRIVATE :: mpp__land_proc    !< check if processor is a land processor
+   PRIVATE :: mpp__check_dim    !< check mpp structure dimension with proc or variable dimension
+   PRIVATE :: mpp__del_var_name !< delete variable in mpp structure, given variable name
+   PRIVATE :: mpp__del_var_str  !< delete variable in mpp structure, given variable structure
+   PRIVATE :: mpp__del_att_name !< delete variable in mpp structure, given variable name
+   PRIVATE :: mpp__del_att_str  !< delete variable in mpp structure, given variable structure
+   PRIVATE :: mpp__split_var    !< extract variable part that will be written in processor 
+   PRIVATE :: mpp__copy         !< copy mpp structure
+
+   !> @struct TMPP
+   TYPE TMPP
+
+      ! general 
+      CHARACTER(LEN=lc)                   :: c_name = ''   !< base name ???
+
+      INTEGER(i4)                         :: i_niproc = 0         !< number of processors following i
+      INTEGER(i4)                         :: i_njproc = 0         !< number of processors following j
+      INTEGER(i4)                         :: i_nproc  = 0         !< total number of proccessors used
+      INTEGER(i4)                         :: i_preci = 1          !< i-direction overlap region length
+      INTEGER(i4)                         :: i_precj = 1          !< j-direction overlap region length
+
+      CHARACTER(LEN=lc)                   :: c_type = ''   !< type of the files (cdf, cdf4, dimg)
+      CHARACTER(LEN=lc)                   :: c_dom  = ''   !< type of domain (full, overlap, nooverlap)
+
+      INTEGER(i4)                         :: i_ndim = 0           !< number of dimensions used in mpp
+      TYPE(TDIM),  DIMENSION(ip_maxdim)   :: t_dim                !< global domain dimension
+
+      TYPE(TFILE), DIMENSION(:), POINTER  :: t_proc => NULL()     !< files/processors composing mpp
+
+   END TYPE
+
+   INTERFACE mpp__check_dim
+      MODULE PROCEDURE mpp__check_proc_dim !< check if processor and mpp structure use same dimension
+      MODULE PROCEDURE mpp__check_var_dim  !< check if variable  and mpp structure use same dimension
+   END INTERFACE mpp__check_dim
+
+   INTERFACE mpp__del_proc
+      MODULE PROCEDURE mpp__del_proc_id
+      MODULE PROCEDURE mpp__del_proc_str
+   END INTERFACE mpp__del_proc
+
+   INTERFACE mpp_del_var
+      MODULE PROCEDURE mpp__del_var_name
+      MODULE PROCEDURE mpp__del_var_str
+   END INTERFACE mpp_del_var
+
+   INTERFACE mpp_del_att
+      MODULE PROCEDURE mpp__del_att_name
+      MODULE PROCEDURE mpp__del_att_str
+   END INTERFACE mpp_del_att
+
+   INTERFACE mpp_init
+      MODULE PROCEDURE mpp__init_mask
+      MODULE PROCEDURE mpp__init_var
+      MODULE PROCEDURE mpp__init_read
+   END INTERFACE mpp_init
+
+   INTERFACE ASSIGNMENT(=)
+      MODULE PROCEDURE mpp__copy   ! copy mpp structure
+   END INTERFACE
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine copy mpp structure in another mpp
+   !> structure
+   !> @details 
+   !> mpp file are copied in a temporary table, 
+   !> so input and output mpp structure do not point on the same 
+   !> "memory cell", and so on are independant. 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[out] td_mpp1  : mpp structure
+   !> @param[in] td_mpp2  : mpp structure
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE mpp__copy( td_mpp1, td_mpp2 )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP), INTENT(OUT) :: td_mpp1
+      TYPE(TMPP), INTENT(IN)  :: td_mpp2
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      CALL logger_trace("COPY: mpp "//TRIM(td_mpp2%c_name)//" in "//&
+      &  TRIM(td_mpp1%c_name))
+      ! copy mpp variable
+      td_mpp1%c_name     = TRIM(td_mpp2%c_name)
+      td_mpp1%i_niproc   = td_mpp2%i_niproc
+      td_mpp1%i_njproc   = td_mpp2%i_njproc
+      td_mpp1%i_nproc    = td_mpp2%i_nproc
+      td_mpp1%i_preci    = td_mpp2%i_preci
+      td_mpp1%i_precj    = td_mpp2%i_precj
+      td_mpp1%c_type     = TRIM(td_mpp2%c_type)
+      td_mpp1%c_dom      = TRIM(td_mpp2%c_dom)
+      td_mpp1%i_ndim     = td_mpp2%i_ndim
+
+      ! copy dimension
+      td_mpp1%t_dim(:) = td_mpp2%t_dim(:)
+      
+      ! copy file structure
+      IF( ASSOCIATED(td_mpp1%t_proc) ) DEALLOCATE(td_mpp1%t_proc)
+      IF( ASSOCIATED(td_mpp2%t_proc) )THEN
+         ALLOCATE( td_mpp1%t_proc(td_mpp1%i_nproc) )
+         DO ji=1,td_mpp1%i_nproc
+            td_mpp1%t_proc(ji) = td_mpp2%t_proc(ji)
+         ENDDO
+      ENDIF
+
+   END SUBROUTINE mpp__copy
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine print some information about mpp strucutre.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp : mpp structure
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE mpp_print(td_mpp)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TMPP), INTENT(IN) :: td_mpp
+
+      ! local variable
+      INTEGER(i4), PARAMETER :: ip_freq = 4
+
+      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_proc
+      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_lci
+      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_lcj
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jk
+      INTEGER(i4) :: jl
+      INTEGER(i4) :: jm
+      !----------------------------------------------------------------
+
+      WRITE(*,'((a,a),2(/3x,a,a),6(/3x,a,i0))')&
+      &  "MPP : ",TRIM(td_mpp%c_name), &
+      &  " type   : ",TRIM(td_mpp%c_type), &
+      &  " dom    : ",TRIM(td_mpp%c_dom), &
+      &  " nproc  : ",td_mpp%i_nproc, &
+      &  " niproc : ",td_mpp%i_niproc, &
+      &  " njproc : ",td_mpp%i_njproc, &
+      &  " preci  : ",td_mpp%i_preci, &
+      &  " precj  : ",td_mpp%i_precj, &
+      &  " ndim   : ",td_mpp%i_ndim
+
+      ! print dimension
+      IF(  td_mpp%i_ndim /= 0 )THEN
+         WRITE(*,'(/a)') " File dimension"
+         DO ji=1,ip_maxdim
+            IF( td_mpp%t_dim(ji)%l_use )THEN
+               CALL dim_print(td_mpp%t_dim(ji))
+            ENDIF
+         ENDDO
+      ENDIF
+
+      ! print file
+      IF( td_mpp%i_nproc /= 0 .AND. ASSOCIATED(td_mpp%t_proc) )THEN
+         IF( ALL( td_mpp%t_proc(:)%i_iind==0 ) .OR. &
+         &   ALL( td_mpp%t_proc(:)%i_jind==0 ) )THEN
+
+            DO ji=1,td_mpp%i_nproc
+               CALL file_print(td_mpp%t_proc(ji))
+               WRITE(*,'((a),(/3x,a,i0),2(/3x,a,a),4(/3x,a,i0,a,i0)/)')&
+               &  " Domain decomposition : ", &
+               &  " id          : ",td_mpp%t_proc(ji)%i_pid, &
+               &  " used        : ",TRIM(fct_str(td_mpp%t_proc(ji)%l_use)), &
+               &  " contour     : ",TRIM(fct_str(td_mpp%t_proc(ji)%l_ctr)), &
+               &  " left-bottom : ",td_mpp%t_proc(ji)%i_impp,', ',&
+               &  td_mpp%t_proc(ji)%i_jmpp, &
+               &  " dimension   : ",td_mpp%t_proc(ji)%i_lci,' x ',&
+               &  td_mpp%t_proc(ji)%i_lcj, &
+               &  " first indoor indices : ",td_mpp%t_proc(ji)%i_ldi,', ',&
+               &  td_mpp%t_proc(ji)%i_ldj, &
+               &  " last  indoor indices : ",td_mpp%t_proc(ji)%i_lei,', ',&
+               &  td_mpp%t_proc(ji)%i_lej
+
+               !! attribute
+               !DO jj=1, td_mpp%t_proc(ji)%i_natt
+               !   CALL att_print(td_mpp%t_proc(ji)%t_att(jj))
+               !ENDDO
+
+
+            ENDDO
+
+         ELSE
+
+            DO ji=1,td_mpp%i_nproc
+               WRITE(*,'((a, a),(/3x,a,i0),(/3x,a,a),4(/3x,a,i0,a,i0)/)')&
+               &  " Domain decomposition : ",TRIM(td_mpp%t_proc(ji)%c_name),&
+               &  " id          : ",td_mpp%t_proc(ji)%i_pid, &
+               &  " used        : ",TRIM(fct_str(td_mpp%t_proc(ji)%l_use)),&
+               &  " left-bottom : ",td_mpp%t_proc(ji)%i_impp,', ',&
+               &  td_mpp%t_proc(ji)%i_jmpp, &
+               &  " dimension   : ",td_mpp%t_proc(ji)%i_lci,' x ',&
+               &  td_mpp%t_proc(ji)%i_lcj, &
+               &  " first indoor indices : ",td_mpp%t_proc(ji)%i_ldi,',',&
+               &  td_mpp%t_proc(ji)%i_ldj, &
+               &  " last  indoor indices : ",td_mpp%t_proc(ji)%i_lei,', ',&
+               &  td_mpp%t_proc(ji)%i_lej
+
+               !! attribute
+               !DO jj=1, td_mpp%t_proc(ji)%i_natt
+               !   CALL att_print(td_mpp%t_proc(ji)%t_att(jj))
+               !ENDDO
+
+            ENDDO
+            
+            ALLOCATE( il_proc(td_mpp%i_niproc,td_mpp%i_njproc) )
+            ALLOCATE( il_lci(td_mpp%i_niproc,td_mpp%i_njproc) )
+            ALLOCATE( il_lcj(td_mpp%i_niproc,td_mpp%i_njproc) )
+
+            DO jk=1,td_mpp%i_nproc
+               ji=td_mpp%t_proc(jk)%i_iind
+               jj=td_mpp%t_proc(jk)%i_jind
+               il_proc(ji,jj)=jk
+               il_lci(ji,jj)=td_mpp%t_proc(jk)%i_lci
+               il_lcj(ji,jj)=td_mpp%t_proc(jk)%i_lcj
+            ENDDO
+
+            jl = 1
+            DO jk = 1,(td_mpp%i_niproc-1)/ip_freq+1
+               jm = MIN(td_mpp%i_niproc, jl+ip_freq-1)
+               WRITE(*,*)
+               WRITE(*,9401) (ji, ji = jl,jm)
+               WRITE(*,9400) ('***', ji = jl,jm-1)
+               DO jj = 1, td_mpp%i_njproc
+                  WRITE(*,9403) ('   ', ji = jl,jm-1)
+                  WRITE(*,9402) jj, ( il_lci(ji,jj), il_lcj(ji,jj), ji = jl,jm)
+                  WRITE(*,9404) (il_proc(ji,jj), ji= jl,jm)
+                  WRITE(*,9403) ('   ', ji = jl,jm-1)
+                  WRITE(*,9400) ('***', ji = jl,jm-1)
+               ENDDO
+               jl = jl+ip_freq
+            ENDDO
+         
+            DEALLOCATE( il_proc )
+            DEALLOCATE( il_lci )
+            DEALLOCATE( il_lcj )
+
+         ENDIF
+      ELSE
+         WRITE(*,'(/a)') " Domain decomposition : none"
+      ENDIF
+
+
+9400   FORMAT('     ***',20('*************',a3))
+9403   FORMAT('     *     ',20('         *   ',a3))
+9401   FORMAT('        ',20('   ',i3,'          '))
+9402   FORMAT(' ',i3,' *  ',20(i0,'  x',i0,'   *   '))
+9404   FORMAT('     *  ',20('      ',i3,'   *   '))
+
+   END SUBROUTINE mpp_print
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function initialised mpp structure, given file name, mask and number of
+   !> processor following I and J
+   !> @detail
+   !> - If no total number of processor is defined (id_nproc), optimize 
+   !> the domain decomposition (look for the domain decomposition with 
+   !> the most land processor to remove)
+   !> - length of the overlap region (id_preci, id_precj) could be specify
+   !> in I and J direction (default value is 1)
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[in] cd_file : file name of one file composing mpp domain
+   !> @param[in] id_mask : domain mask
+   !> @param[in] id_niproc : number of processors following i
+   !> @param[in] id_njproc : number of processors following j
+   !> @param[in] id_nproc  : total number of processors
+   !> @param[in] id_preci  : i-direction overlap region
+   !> @param[in] id_precj  : j-direction overlap region
+   !> @param[in] cd_type   : type of the files (cdf, cdf4, dimg)
+   !> @return mpp structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TMPP) FUNCTION mpp__init_mask(cd_file, id_mask,              &
+   &                                  id_niproc, id_njproc, id_nproc,&
+   &                                  id_preci, id_precj,            &
+                                      cd_type)
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),            INTENT(IN) :: cd_file
+      INTEGER(i4), DIMENSION(:,:), INTENT(IN), OPTIONAL :: id_mask
+      INTEGER(i4),                 INTENT(IN), OPTIONAL :: id_niproc
+      INTEGER(i4),                 INTENT(IN), OPTIONAL :: id_njproc
+      INTEGER(i4),                 INTENT(IN), OPTIONAL :: id_nproc
+      INTEGER(i4),                 INTENT(IN), OPTIONAL :: id_preci
+      INTEGER(i4),                 INTENT(IN), OPTIONAL :: id_precj
+      CHARACTER(LEN=*),            INTENT(IN), OPTIONAL :: cd_type
+
+      ! local variable
+      CHARACTER(LEN=lc)                :: cl_type
+
+      INTEGER(i4)      , DIMENSION(2) :: il_shape
+
+      TYPE(TDIM)                      :: tl_dim
+
+      TYPE(TATT)                      :: tl_att
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! clean mpp
+      CALL mpp_clean(mpp__init_mask)
+
+      ! get mpp name
+      mpp__init_mask%c_name=TRIM(file_rename(cd_file))
+
+      ! check type
+      cl_type=''
+      IF( PRESENT(cd_type) ) cl_type=TRIM(ADJUSTL(cd_type))
+
+      IF( TRIM(cl_type) /= '' )THEN
+         SELECT CASE(TRIM(cd_type))
+            CASE('cdf')
+               mpp__init_mask%c_type='cdf'
+            CASE('dimg')
+               mpp__init_mask%c_type='dimg'
+            CASE DEFAULT
+               CALL logger_warn( "MPP INIT: type "//TRIM(cd_type)//&
+               & " unknown. type dimg will be used for mpp "//&
+               &  TRIM(mpp__init_mask%c_name) )
+               mpp__init_mask%c_type='dimg'
+         END SELECT
+      ELSE
+         mpp__init_mask%c_type=TRIM(file_get_type(cd_file))
+      ENDIF
+
+      IF( PRESENT(id_mask) )THEN
+         ! get global domain dimension
+         il_shape(:)=SHAPE(id_mask)
+
+         tl_dim=dim_init('X',il_shape(1))
+         CALL mpp_add_dim(mpp__init_mask, tl_dim)
+
+         tl_dim=dim_init('Y',il_shape(2))
+         CALL mpp_add_dim(mpp__init_mask,tl_dim)
+      ENDIF
+
+      IF( (       PRESENT(id_niproc)  .AND. (.NOT. PRESENT(id_niproc))) .OR. &
+          ((.NOT. PRESENT(id_niproc)) .AND.        PRESENT(id_njproc) ) )THEN
+          CALL logger_warn( "MPP INIT: number of processors following I and J "//&
+          & "should be both specified")
+      ELSE
+         ! get number of processors following I and J
+         IF( PRESENT(id_niproc) ) mpp__init_mask%i_niproc=id_niproc
+         IF( PRESENT(id_njproc) ) mpp__init_mask%i_njproc=id_njproc
+      ENDIF
+
+      ! get maximum number of processors to be used
+      IF( PRESENT(id_nproc) ) mpp__init_mask%i_nproc = id_nproc
+
+      ! get overlap region length
+      IF( PRESENT(id_preci) ) mpp__init_mask%i_preci= id_preci
+      IF( PRESENT(id_precj) ) mpp__init_mask%i_precj= id_precj
+
+      IF( mpp__init_mask%i_nproc  /= 0 .AND. &
+      &   mpp__init_mask%i_niproc /= 0 .AND. &
+      &   mpp__init_mask%i_njproc /= 0 .AND. &
+      &   mpp__init_mask%i_nproc > &
+      &   mpp__init_mask%i_niproc * mpp__init_mask%i_njproc )THEN
+
+         CALL logger_error("MPP INIT: invalid domain decomposition ")
+         CALL logger_debug("MPP INIT: "// &
+         & TRIM(fct_str(mpp__init_mask%i_nproc))//" > "//&
+         & TRIM(fct_str(mpp__init_mask%i_niproc))//" x "//&
+         & TRIM(fct_str(mpp__init_mask%i_njproc)) )
+
+      ELSE
+
+         IF( mpp__init_mask%i_niproc /= 0 .AND. mpp__init_mask%i_njproc /= 0 )THEN
+            ! compute domain decomposition
+            CALL mpp__compute( mpp__init_mask )
+            ! remove land sub domain
+            CALL mpp__del_land( mpp__init_mask, id_mask )
+         ELSEIF( mpp__init_mask%i_nproc  /= 0 )THEN
+            ! optimiz
+            CALL mpp__optimiz( mpp__init_mask, id_mask )
+
+         ELSE
+            CALL logger_error("MPP INIT: can't define domain decomposition")
+            CALL logger_debug ("MPP INIT: maximum number of processor to be used "//&
+            &  "or number of processor following I and J direction must "//&
+            &  "be specified.")
+         ENDIF
+
+         ! get domain type
+         CALL mpp_get_dom( mpp__init_mask )
+
+         DO ji=1,mpp__init_mask%i_nproc
+
+            ! get processor size
+            il_shape(:)=mpp_get_proc_size( mpp__init_mask, ji )
+
+            tl_dim=dim_init('X',il_shape(1))
+            CALL file_move_dim(mpp__init_mask%t_proc(ji), tl_dim)
+
+            tl_dim=dim_init('Y',il_shape(2))
+            CALL file_move_dim(mpp__init_mask%t_proc(ji), tl_dim)            
+
+            ! add type
+            mpp__init_mask%t_proc(ji)%c_type=TRIM(mpp__init_mask%c_type)
+
+         ENDDO
+
+         ! add global attribute
+         tl_att=att_init("DOMAIN_number_total",mpp__init_mask%i_nproc)
+         CALL mpp_add_att(mpp__init_mask, tl_att)
+
+         tl_att=att_init("DOMAIN_I_number_total",mpp__init_mask%i_niproc)
+         CALL mpp_add_att(mpp__init_mask, tl_att)
+
+         tl_att=att_init("DOMAIN_J_number_total",mpp__init_mask%i_njproc)
+         CALL mpp_add_att(mpp__init_mask, tl_att)
+
+         tl_att=att_init("DOMAIN_size_global",mpp__init_mask%t_dim(1:2)%i_len)
+         CALL mpp_add_att(mpp__init_mask, tl_att)
+
+         tl_att=att_init( "DOMAIN_I_position_first", &
+         &                mpp__init_mask%t_proc(:)%i_impp )
+         CALL mpp_add_att(mpp__init_mask, tl_att)
+
+         tl_att=att_init( "DOMAIN_J_position_first", &
+         &                mpp__init_mask%t_proc(:)%i_jmpp )
+         CALL mpp_add_att(mpp__init_mask, tl_att)
+
+         tl_att=att_init( "DOMAIN_I_position_last", &
+         &                mpp__init_mask%t_proc(:)%i_lci )
+         CALL mpp_add_att(mpp__init_mask, tl_att)
+
+         tl_att=att_init( "DOMAIN_J_position_last", &
+         &                mpp__init_mask%t_proc(:)%i_lcj )
+         CALL mpp_add_att(mpp__init_mask, tl_att)
+
+         tl_att=att_init( "DOMAIN_I_halo_size_start", &
+         &                mpp__init_mask%t_proc(:)%i_ldi )
+         CALL mpp_add_att(mpp__init_mask, tl_att)
+
+         tl_att=att_init( "DOMAIN_J_halo_size_start", &
+         &                mpp__init_mask%t_proc(:)%i_ldj )
+         CALL mpp_add_att(mpp__init_mask, tl_att)
+
+         tl_att=att_init( "DOMAIN_I_halo_size_end", &
+         &                mpp__init_mask%t_proc(:)%i_lei )
+         CALL mpp_add_att(mpp__init_mask, tl_att)
+
+         tl_att=att_init( "DOMAIN_J_halo_size_end", &
+         &                mpp__init_mask%t_proc(:)%i_lej )
+         CALL mpp_add_att(mpp__init_mask, tl_att)         
+
+      ENDIF
+
+   END FUNCTION mpp__init_mask
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function initialised mpp structure, given variable strcuture 
+   !> and number of processor following I and J
+   !> @detail
+   !> - If no total number of processor is defined (id_nproc), optimize 
+   !> the domain decomposition (look for the domain decomposition with 
+   !> the most land processor to remove)
+   !> - length of the overlap region (id_preci, id_precj) could be specify
+   !> in I and J direction (default value is 1)
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[in] cd_file : file name of one file composing mpp domain
+   !> @param[in] td_var : variable structure
+   !> @param[in] id_niproc : number of processors following i
+   !> @param[in] id_njproc : number of processors following j
+   !> @param[in] id_nproc  : total number of processors
+   !> @param[in] id_preci  : i-direction overlap region
+   !> @param[in] id_precj  : j-direction overlap region
+   !> @param[in] cd_type   : type of the files (cdf, cdf4, dimg)
+   !> @return mpp structure
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TMPP) FUNCTION mpp__init_var( cd_file, td_var,               &
+   &                                  id_niproc, id_njproc, id_nproc,&
+   &                                  id_preci, id_precj, cd_type )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN) :: cd_file
+      TYPE(TVAR),       INTENT(IN) :: td_var
+      INTEGER(i4),      INTENT(IN), OPTIONAL :: id_niproc
+      INTEGER(i4),      INTENT(IN), OPTIONAL :: id_njproc
+      INTEGER(i4),      INTENT(IN), OPTIONAL :: id_nproc
+      INTEGER(i4),      INTENT(IN), OPTIONAL :: id_preci
+      INTEGER(i4),      INTENT(IN), OPTIONAL :: id_precj
+      CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: cd_type
+
+      ! local variable
+      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_mask
+      !----------------------------------------------------------------
+
+      IF( ASSOCIATED(td_var%d_value) )THEN
+         ALLOCATE( il_mask(td_var%t_dim(1)%i_len, td_var%t_dim(2)%i_len) )
+         il_mask(:,:)=var_get_mask(td_var)
+         
+         mpp__init_var=mpp_init( cd_file, il_mask(:,:),         &
+         &                       id_niproc, id_njproc, id_nproc,&
+         &                       id_preci, id_precj, cd_type )
+
+         DEALLOCATE(il_mask)
+      ELSE
+         CALL logger_error("MPP INIT: variable value not define.")
+      ENDIF
+
+   END FUNCTION mpp__init_var
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a mpp structure, 
+   !> reading one restart dimg file, or some netcdf files.
+   !
+   !> @details 
+   !>
+   !> @warning td_file should be not opened
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file strcuture
+   !> @return mpp structure
+   !-------------------------------------------------------------------
+   ! @code
+   TYPE(TMPP) FUNCTION mpp__init_read( td_file )
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TFILE), INTENT(IN) :: td_file
+
+      ! local variable
+      TYPE(TMPP)  :: tl_mpp
+      TYPE(TFILE) :: tl_file
+      TYPE(TDIM)  :: tl_dim
+      TYPE(TATT)  :: tl_att
+      INTEGER(i4) :: il_nproc
+      INTEGER(i4) :: il_attid
+
+      INTEGER(i4), DIMENSION(2) :: il_shape
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! clean mpp
+      CALL mpp_clean(mpp__init_read)
+
+      ! check file type
+      SELECT CASE( TRIM(td_file%c_type) )
+         CASE('cdf')
+            ! need to read all file to get domain decomposition
+
+            tl_file=td_file
+
+            ! open file
+            CALL iom_open(tl_file)
+
+            ! read first file domain decomposition
+            tl_mpp=mpp__init_read_cdf(tl_file)
+
+            ! get number of processor/file to be read
+            il_nproc = 1
+            il_attid = 0
+
+            IF( ASSOCIATED(tl_file%t_att) )THEN
+               il_attid=att_get_id( tl_file%t_att, "DOMAIN_number_total" )
+            ENDIF
+            IF( il_attid /= 0 )THEN
+               il_nproc = INT(tl_file%t_att(il_attid)%d_value(1))
+            ENDIF
+
+            ! close file
+            CALL iom_close(tl_file)
+
+            IF( il_nproc /= 1 )THEN
+               DO ji=1,il_nproc
+
+                  ! clean mpp strcuture
+                  CALL mpp_clean(tl_mpp)
+ 
+                  ! get filename 
+                  tl_file=file_rename(td_file,ji)
+ 
+                  ! open file
+                  CALL iom_open(tl_file)
+
+                  ! read domain decomposition
+                  tl_mpp = mpp__init_read_cdf(tl_file)
+                  IF( ji == 1 )THEN
+                     mpp__init_read=tl_mpp
+                  ELSE
+                     IF( ANY( mpp__init_read%t_dim(1:2)%i_len /= &
+                                      tl_mpp%t_dim(1:2)%i_len) )THEN
+
+                        CALL logger_error("INIT READ: dimension from file "//&
+                        &     TRIM(tl_file%c_name)//" and mpp strcuture "//&
+                        &     TRIM(mpp__init_read%c_name)//"differ ")
+
+                     ELSE
+
+                        ! add processor to mpp strcuture
+                        CALL mpp__add_proc(mpp__init_read, tl_mpp%t_proc(1))
+
+                     ENDIF
+                  ENDIF
+
+                  ! close file
+                  CALL iom_close(tl_file)
+
+               ENDDO
+               IF( mpp__init_read%i_nproc /= il_nproc )THEN
+                  CALL logger_error("INIT READ: some processors can't be added &
+                  &               to mpp structure")
+               ENDIF
+
+            ELSE
+               mpp__init_read=tl_mpp
+            ENDIF
+
+            ! mpp type
+            mpp__init_read%c_type=TRIM(td_file%c_type)
+
+            ! mpp domain type
+            CALL mpp_get_dom(mpp__init_read)
+
+            ! create some attributes for domain decomposition (use with dimg file)
+            tl_att=att_init( "DOMAIN_number_total", mpp__init_read%i_nproc )
+            CALL mpp_add_att(mpp__init_read, tl_att)
+
+            tl_att=att_init( "DOMAIN_I_position_first", mpp__init_read%t_proc(:)%i_impp )
+            CALL mpp_add_att(mpp__init_read, tl_att)
+
+            tl_att=att_init( "DOMAIN_J_position_first", mpp__init_read%t_proc(:)%i_jmpp )
+            CALL mpp_add_att(mpp__init_read, tl_att)
+
+            tl_att=att_init( "DOMAIN_I_position_last", mpp__init_read%t_proc(:)%i_lci )
+            CALL mpp_add_att(mpp__init_read, tl_att)
+
+            tl_att=att_init( "DOMAIN_J_position_last", mpp__init_read%t_proc(:)%i_lcj )
+            CALL mpp_add_att(mpp__init_read, tl_att)
+
+            tl_att=att_init( "DOMAIN_I_halo_size_start", mpp__init_read%t_proc(:)%i_ldi )
+            CALL mpp_add_att(mpp__init_read, tl_att)
+
+            tl_att=att_init( "DOMAIN_J_halo_size_start", mpp__init_read%t_proc(:)%i_ldj )
+            CALL mpp_add_att(mpp__init_read, tl_att)
+
+            tl_att=att_init( "DOMAIN_I_halo_size_end", mpp__init_read%t_proc(:)%i_lei )
+            CALL mpp_add_att(mpp__init_read, tl_att)
+
+            tl_att=att_init( "DOMAIN_J_halo_size_end", mpp__init_read%t_proc(:)%i_lej )
+            CALL mpp_add_att(mpp__init_read, tl_att)
+            
+
+         CASE('dimg')
+            ! domain decomposition could be read in one file
+
+            tl_file=td_file
+            ! open file
+            CALL iom_open(tl_file)
+
+            ! read mpp structure
+            mpp__init_read=mpp__init_read_rstdimg(tl_file)
+
+            ! mpp type
+            mpp__init_read%c_type=TRIM(td_file%c_type)
+
+            ! mpp domain type
+            CALL mpp_get_dom(mpp__init_read)
+
+            ! get processor size
+            DO ji=1,mpp__init_read%i_nproc
+
+               il_shape(:)=mpp_get_proc_size( mpp__init_read, ji )
+
+               tl_dim=dim_init('X',il_shape(1))
+               CALL file_add_dim(mpp__init_read%t_proc(ji), tl_dim)
+
+               tl_dim=dim_init('Y',il_shape(2))
+               CALL file_add_dim(mpp__init_read%t_proc(ji), tl_dim)            
+
+            ENDDO
+
+            ! close file
+            CALL iom_close(tl_file)
+
+         CASE DEFAULT
+            CALL logger_error("INIT READ: invalid type for file "//&
+            &              TRIM(tl_file%c_name))
+      END SELECT
+
+   END FUNCTION mpp__init_read
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a mpp structure, 
+   !> reading some netcdf files.
+   !
+   !> @details 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file strcuture
+   !> @return mpp structure
+   !-------------------------------------------------------------------
+   ! @code
+   TYPE(TMPP) FUNCTION mpp__init_read_cdf( td_file )
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TFILE), INTENT(IN) :: td_file
+
+      ! local variable
+      INTEGER(i4) :: il_attid  ! attribute id
+      LOGICAL     :: ll_exist
+      LOGICAL     :: ll_open
+
+      TYPE(TATT)  :: tl_att
+      TYPE(TFILE) :: tl_proc
+      !----------------------------------------------------------------
+
+      CALL logger_trace(" INIT READ: netcdf file "//TRIM(td_file%c_name))
+
+      INQUIRE( FILE=TRIM(td_file%c_name), EXIST=ll_exist, OPENED=ll_open )
+      ! ll_open do not work for netcdf file, return always FALSE
+      IF( ll_exist )THEN
+
+         IF( td_file%i_id == 0 )THEN
+            CALL logger_info(" id "//TRIM(fct_str(td_file%i_id))) 
+            CALL logger_error("INIT READ: netcdf file "//TRIM(td_file%c_name)//&
+            &  " not opened")
+         ELSE
+
+            ! get mpp name
+            mpp__init_read_cdf%c_name=TRIM( file_rename(td_file%c_name) )
+
+            ! add type
+            mpp__init_read_cdf%c_type="cdf"
+
+            ! global domain size
+            il_attid = 0
+            IF( ASSOCIATED(td_file%t_att) )THEN
+               il_attid=att_get_id( td_file%t_att, "DOMAIN_size_global" )
+            ENDIF
+            IF( il_attid /= 0 )THEN
+               mpp__init_read_cdf%t_dim(1)= &
+               &  dim_init('X',INT(td_file%t_att(il_attid)%d_value(1)))
+               mpp__init_read_cdf%t_dim(2)= &
+               &  dim_init('Y',INT(td_file%t_att(il_attid)%d_value(2)))
+            ELSE
+               mpp__init_read_cdf%t_dim(1)= &
+               &  dim_init( td_file%t_dim(1)%c_name, td_file%t_dim(1)%i_len)
+               mpp__init_read_cdf%t_dim(2)= &
+               &  dim_init( td_file%t_dim(2)%c_name, td_file%t_dim(2)%i_len)
+
+            ENDIF
+            mpp__init_read_cdf%t_dim(3)= &
+            &  dim_init( td_file%t_dim(3)%c_name, td_file%t_dim(1)%i_len)
+            mpp__init_read_cdf%t_dim(4)= &
+            &  dim_init( td_file%t_dim(4)%c_name, td_file%t_dim(2)%i_len)
+
+            ! initialise file/processor
+            tl_proc=td_file
+
+            ! processor id
+            il_attid = 0
+            IF( ASSOCIATED(td_file%t_att) )THEN
+               il_attid=att_get_id( td_file%t_att, "DOMAIN_number" )
+            ENDIF
+            IF( il_attid /= 0 )THEN
+               tl_proc%i_pid = INT(td_file%t_att(il_attid)%d_value(1))
+            ELSE
+               tl_proc%i_pid = 1
+            ENDIF
+
+            ! processor dimension
+            tl_proc%t_dim(:)=td_file%t_dim(:)
+
+            ! DOMAIN_position_first
+            il_attid = 0
+            IF( ASSOCIATED(td_file%t_att) )THEN
+               il_attid=att_get_id( td_file%t_att, "DOMAIN_position_first" )
+            ENDIF
+            IF( il_attid /= 0 )THEN
+               tl_proc%i_impp = INT(td_file%t_att(il_attid)%d_value(1))
+               tl_proc%i_jmpp = INT(td_file%t_att(il_attid)%d_value(2))
+            ELSE
+               tl_proc%i_impp = 1
+               tl_proc%i_jmpp = 1
+            ENDIF
+
+            ! DOMAIN_position_last
+            il_attid = 0
+            IF( ASSOCIATED(td_file%t_att) )THEN
+               il_attid=att_get_id( td_file%t_att, "DOMAIN_position_last" )
+            ENDIF
+            IF( il_attid /= 0 )THEN
+               tl_proc%i_lci = INT(td_file%t_att(il_attid)%d_value(1)) + tl_proc%i_impp
+               tl_proc%i_lcj = INT(td_file%t_att(il_attid)%d_value(2)) + tl_proc%i_jmpp
+            ELSE
+               tl_proc%i_lci = mpp__init_read_cdf%t_dim(1)%i_len
+               tl_proc%i_lcj = mpp__init_read_cdf%t_dim(2)%i_len
+            ENDIF
+
+            ! DOMAIN_halo_size_start
+            il_attid = 0
+            IF( ASSOCIATED(td_file%t_att) )THEN
+               il_attid=att_get_id( td_file%t_att, "DOMAIN_halo_size_start" )
+            ENDIF
+            IF( il_attid /= 0 )THEN
+               tl_proc%i_ldi = INT(td_file%t_att(il_attid)%d_value(1))
+               tl_proc%i_ldj = INT(td_file%t_att(il_attid)%d_value(2))
+            ELSE
+               tl_proc%i_ldi = 1
+               tl_proc%i_ldj = 1
+            ENDIF
+
+            ! DOMAIN_halo_size_end
+            il_attid = 0
+            IF( ASSOCIATED(td_file%t_att) )THEN
+               il_attid=att_get_id( td_file%t_att, "DOMAIN_halo_size_end" )
+            ENDIF
+            IF( il_attid /= 0 )THEN
+               tl_proc%i_lei = INT(td_file%t_att(il_attid)%d_value(1))
+               tl_proc%i_lej = INT(td_file%t_att(il_attid)%d_value(2))
+            ELSE
+               tl_proc%i_lei = mpp__init_read_cdf%t_dim(1)%i_len
+               tl_proc%i_lej = mpp__init_read_cdf%t_dim(2)%i_len
+            ENDIF
+
+            ! add attributes
+            tl_att=att_init( "DOMAIN_size_global", &
+            &                mpp__init_read_cdf%t_dim(:)%i_len)
+            CALL file_move_att(tl_proc, tl_att)
+
+            tl_att=att_init( "DOMAIN_number", tl_proc%i_pid )
+            CALL file_move_att(tl_proc, tl_att)
+
+            tl_att=att_init( "DOMAIN_position_first", &
+            &                (/tl_proc%i_impp, tl_proc%i_jmpp /) )
+            CALL file_move_att(tl_proc, tl_att)
+
+            tl_att=att_init( "DOMAIN_position_last", &
+            &                (/tl_proc%i_lci, tl_proc%i_lcj /) )
+            CALL file_move_att(tl_proc, tl_att)
+
+            tl_att=att_init( "DOMAIN_halo_size_start", &
+            &                (/tl_proc%i_ldi, tl_proc%i_ldj /) )
+            CALL file_move_att(tl_proc, tl_att)
+
+            tl_att=att_init( "DOMAIN_halo_size_end", &
+            &                (/tl_proc%i_lei, tl_proc%i_lej /) )
+            CALL file_move_att(tl_proc, tl_att)
+
+            ! add processor to mpp structure
+            CALL mpp__add_proc(mpp__init_read_cdf, tl_proc)
+
+         ENDIF
+
+      ELSE
+
+         CALL logger_error("INIT READ: netcdf file "//TRIM(td_file%c_name)//&
+         &  " do not exist")
+
+      ENDIF      
+   END FUNCTION mpp__init_read_cdf
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a mpp structure, 
+   !> reading one dimg restart file.
+   !
+   !> @details 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_file : file strcuture
+   !> @return mpp structure
+   !-------------------------------------------------------------------
+   ! @code
+   TYPE(TMPP) FUNCTION mpp__init_read_rstdimg( td_file )
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TFILE), INTENT(IN) :: td_file
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_recl                          ! record length 
+      INTEGER(i4) :: il_nx, il_ny, il_nz              ! x,y,z dimension 
+      INTEGER(i4) :: il_n0d, il_n1d, il_n2d, il_n3d   ! number of 0/1/2/3D variables 
+      INTEGER(i4) :: il_iglo, il_jglo                 ! domain global size
+      INTEGER(i4) :: il_rhd                           ! record of the header infos
+      INTEGER(i4) :: il_pni, il_pnj, il_pnij          ! domain decomposition
+      INTEGER(i4) :: il_area                          ! domain index
+
+      LOGICAL     ::  ll_exist
+      LOGICAL     ::  ll_open
+
+      CHARACTER(LEN=lc) :: cl_file
+
+      TYPE(TDIM)  :: tl_dim ! dimension structure
+      TYPE(TATT)  :: tl_att
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      INQUIRE( FILE=TRIM(td_file%c_name), EXIST=ll_exist, OPENED=ll_open)
+      IF( ll_exist )THEN
+
+         IF( .NOT. ll_open )THEN
+            CALL logger_error("INIT READ: dimg file "//TRIM(td_file%c_name)//&
+            &  " not opened")
+         ELSE
+
+            ! read first record 
+            READ( td_file%i_id, IOSTAT=il_status, REC=1 )& 
+            &     il_recl,                         &
+            &     il_nx, il_ny, il_nz,             &
+            &     il_n0d, il_n1d, il_n2d, il_n3d,  &
+            &     il_rhd,                          &
+            &     il_pni, il_pnj, il_pnij,         &
+            &     il_area
+            CALL fct_err(il_status)
+            IF( il_status /= 0 )THEN
+               CALL logger_error("INIT READ: read first line header of "//&
+               &              TRIM(td_file%c_name))
+            ENDIF
+
+            ! get mpp name
+            mpp__init_read_rstdimg%c_name=TRIM( file_rename(td_file%c_name) )
+
+            ! number of processors to be read
+            mpp__init_read_rstdimg%i_nproc  = il_pnij
+            mpp__init_read_rstdimg%i_niproc = il_pni
+            mpp__init_read_rstdimg%i_njproc = il_pnj
+
+            IF( ASSOCIATED(mpp__init_read_rstdimg%t_proc) )THEN
+               DEALLOCATE(mpp__init_read_rstdimg%t_proc)
+            ENDIF
+            ALLOCATE( mpp__init_read_rstdimg%t_proc(il_pnij) , stat=il_status )
+            IF( il_status /= 0 )THEN
+               CALL logger_error("INIT READ: not enough space to read domain &
+               &              decomposition in file "//TRIM(td_file%c_name))
+            ENDIF
+
+            ! read first record 
+            READ( td_file%i_id, IOSTAT=il_status, REC=1 )& 
+            &     il_recl,                         &
+            &     il_nx, il_ny, il_nz,             &
+            &     il_n0d, il_n1d, il_n2d, il_n3d,  &
+            &     il_rhd,                          &
+            &     il_pni, il_pnj, il_pnij,         &
+            &     il_area,                         &
+            &     il_iglo, il_jglo,                &
+            &     mpp__init_read_rstdimg%t_proc(:)%i_lci,    &
+            &     mpp__init_read_rstdimg%t_proc(:)%i_lcj,    &
+            &     mpp__init_read_rstdimg%t_proc(:)%i_ldi,    &
+            &     mpp__init_read_rstdimg%t_proc(:)%i_ldj,    &
+            &     mpp__init_read_rstdimg%t_proc(:)%i_lei,    &
+            &     mpp__init_read_rstdimg%t_proc(:)%i_lej,    &
+            &     mpp__init_read_rstdimg%t_proc(:)%i_impp,   &
+            &     mpp__init_read_rstdimg%t_proc(:)%i_jmpp
+            CALL fct_err(il_status)
+            IF( il_status /= 0 )THEN
+               CALL logger_error("INIT READ: read first line of "//&
+               &              TRIM(td_file%c_name))
+            ENDIF
+
+            ! mpp dimension
+            tl_dim=dim_init('X',il_iglo)
+            CALL mpp_add_dim(mpp__init_read_rstdimg,tl_dim)
+            tl_dim=dim_init('Y',il_jglo)
+            CALL mpp_add_dim(mpp__init_read_rstdimg,tl_dim)
+
+            DO ji=1,mpp__init_read_rstdimg%i_nproc
+               ! get file name
+               cl_file =  file_rename(td_file%c_name,ji)
+               mpp__init_read_rstdimg%t_proc(ji)%c_name = TRIM(cl_file)
+               ! update processor id
+               mpp__init_read_rstdimg%t_proc(ji)%i_pid=ji
+
+               ! add attributes
+               tl_att=att_init( "DOMAIN_number", ji )
+               CALL file_move_att(mpp__init_read_rstdimg%t_proc(ji), tl_att) 
+
+               tl_att=att_init( "DOMAIN_position_first", &
+               &                (/mpp__init_read_rstdimg%t_proc(ji)%i_impp, &
+               &                  mpp__init_read_rstdimg%t_proc(ji)%i_jmpp /) )
+               CALL file_move_att(mpp__init_read_rstdimg%t_proc(ji), tl_att)
+
+               tl_att=att_init( "DOMAIN_position_last", &
+               &                (/mpp__init_read_rstdimg%t_proc(ji)%i_lci, &
+               &                  mpp__init_read_rstdimg%t_proc(ji)%i_lcj /) )
+               CALL file_move_att(mpp__init_read_rstdimg%t_proc(ji), tl_att)
+
+               tl_att=att_init( "DOMAIN_halo_size_start", &
+               &                (/mpp__init_read_rstdimg%t_proc(ji)%i_ldi, &
+               &                  mpp__init_read_rstdimg%t_proc(ji)%i_ldj /) )
+               CALL file_move_att(mpp__init_read_rstdimg%t_proc(ji), tl_att)               
+
+               tl_att=att_init( "DOMAIN_halo_size_end", &
+               &                (/mpp__init_read_rstdimg%t_proc(ji)%i_lei, &
+               &                  mpp__init_read_rstdimg%t_proc(ji)%i_lej /) )
+               CALL file_move_att(mpp__init_read_rstdimg%t_proc(ji), tl_att)
+            ENDDO
+      
+            ! add type
+            mpp__init_read_rstdimg%t_proc(:)%c_type="dimg"
+
+            ! add attributes
+            tl_att=att_init( "DOMAIN_size_global", &
+            &                mpp__init_read_rstdimg%t_dim(:)%i_len)
+            CALL mpp_move_att(mpp__init_read_rstdimg, tl_att)
+
+            tl_att=att_init( "DOMAIN_number_total", &
+            &                 mpp__init_read_rstdimg%i_nproc )
+            CALL mpp_add_att(mpp__init_read_rstdimg, tl_att)
+
+            tl_att=att_init( "DOMAIN_I_number_total", &
+            &                 mpp__init_read_rstdimg%i_niproc )
+            CALL mpp_add_att(mpp__init_read_rstdimg, tl_att)
+
+            tl_att=att_init( "DOMAIN_J_number_total", &
+            &                 mpp__init_read_rstdimg%i_njproc )
+            CALL mpp_add_att(mpp__init_read_rstdimg, tl_att)
+
+            tl_att=att_init( "DOMAIN_I_position_first", &
+            &                 mpp__init_read_rstdimg%t_proc(:)%i_impp )
+            CALL mpp_add_att(mpp__init_read_rstdimg, tl_att)
+
+            tl_att=att_init( "DOMAIN_J_position_first", &
+            &                 mpp__init_read_rstdimg%t_proc(:)%i_jmpp )
+            CALL mpp_add_att(mpp__init_read_rstdimg, tl_att)
+
+            tl_att=att_init( "DOMAIN_I_position_last", &
+            &                 mpp__init_read_rstdimg%t_proc(:)%i_lci )
+            CALL mpp_add_att(mpp__init_read_rstdimg, tl_att)
+
+            tl_att=att_init( "DOMAIN_J_position_last", &
+            &                 mpp__init_read_rstdimg%t_proc(:)%i_lcj )
+            CALL mpp_add_att(mpp__init_read_rstdimg, tl_att)
+
+            tl_att=att_init( "DOMAIN_I_halo_size_start", &
+            &                 mpp__init_read_rstdimg%t_proc(:)%i_ldi )
+            CALL mpp_add_att(mpp__init_read_rstdimg, tl_att)
+
+            tl_att=att_init( "DOMAIN_J_halo_size_start", &
+            &                 mpp__init_read_rstdimg%t_proc(:)%i_ldj )
+            CALL mpp_add_att(mpp__init_read_rstdimg, tl_att)
+
+            tl_att=att_init( "DOMAIN_I_halo_size_end", &
+            &                 mpp__init_read_rstdimg%t_proc(:)%i_lei )
+            CALL mpp_add_att(mpp__init_read_rstdimg, tl_att)
+
+            tl_att=att_init( "DOMAIN_J_halo_size_end", &
+            &                 mpp__init_read_rstdimg%t_proc(:)%i_lej )
+            CALL mpp_add_att(mpp__init_read_rstdimg, tl_att)
+         ENDIF
+
+      ELSE
+
+         CALL logger_error("INIT READ: dimg file "//TRIM(td_file%c_name)//&
+         &  " do not exist")
+
+      ENDIF
+
+   END FUNCTION mpp__init_read_rstdimg
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function check if variable and mpp structure use same
+   !> dimension.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp : mpp structure
+   !> @param[in] td_proc : processor structure
+   !> @return dimension of processor and mpp structure agree (or not)
+   !-------------------------------------------------------------------
+   ! @code
+   LOGICAL FUNCTION mpp__check_proc_dim(td_mpp, td_proc)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP),  INTENT(IN) :: td_mpp
+      TYPE(TFILE), INTENT(IN) :: td_proc
+
+      ! local variable
+      INTEGER(i4) :: il_isize !< i-direction maximum sub domain size 
+      INTEGER(i4) :: il_jsize !< j-direction maximum sub domain size
+
+      !----------------------------------------------------------------
+      mpp__check_proc_dim=.TRUE.
+      ! check used dimension 
+      IF( td_mpp%i_niproc /= 0 .AND. td_mpp%i_njproc /= 0 )THEN
+         ! check with maximum size of sub domain
+         il_isize = ( td_mpp%t_dim(1)%i_len - 2*td_mpp%i_preci + &
+         &           (td_mpp%i_niproc-1) ) / td_mpp%i_niproc + 2*td_mpp%i_preci
+         il_jsize = ( td_mpp%t_dim(2)%i_len - 2*td_mpp%i_precj + &
+         &           (td_mpp%i_njproc-1) ) / td_mpp%i_njproc + 2*td_mpp%i_precj
+
+         IF( il_isize < td_proc%i_lci .OR.                     &
+         &   il_jsize < td_proc%i_lcj )THEN
+
+            mpp__check_proc_dim=.FALSE.
+
+            CALL logger_error( " CHECK DIM: processor and mpp dimension differ" )
+
+         ENDIF
+
+      ELSE
+         ! check with global domain size
+         IF( td_mpp%t_dim(1)%i_len < td_proc%i_lci .OR.                     &
+         &   td_mpp%t_dim(2)%i_len < td_proc%i_lcj )THEN
+
+            mpp__check_proc_dim=.FALSE.
+
+            CALL logger_error( " CHECK DIM: processor and mpp dimension differ" )
+
+         ENDIF
+      ENDIF
+
+   END FUNCTION mpp__check_proc_dim
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine add variable to mpp structure.
+   !>
+   !> @detail
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in]    td_var : variable strcuture
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp_add_var( td_mpp, td_var )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP), INTENT(INOUT) :: td_mpp
+      TYPE(TVAR), INTENT(IN)    :: td_var
+
+      ! local variable
+      INTEGER(i4) :: il_varid
+      TYPE(TVAR)  :: tl_var
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( "MPP ADD VAR: domain decomposition not define "//&
+         &               "for mpp "//TRIM(td_mpp%c_name))
+
+      ELSEIF( td_mpp%i_ndim == 0 )THEN
+
+         CALL logger_error( " MPP ADD VAR: no dimension define for "//&
+         &               " mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+         ! check if variable exist
+         IF( TRIM(td_var%c_name) == '' .AND. &
+         &   TRIM(td_var%c_stdname) == '' )THEN
+            CALL logger_error("MPP ADD VAR: variable not define ")
+         ELSE
+            ! check if variable already in mpp structure
+            il_varid=0
+            IF( ASSOCIATED(td_mpp%t_proc(1)%t_var) )THEN
+               il_varid=var_get_id( td_mpp%t_proc(1)%t_var(:), &
+               &                    td_var%c_name, td_var%c_stdname )
+            ENDIF
+
+            IF( il_varid /= 0 )THEN
+
+               CALL logger_error( " MPP ADD VAR: variable "//TRIM(td_var%c_name)//&
+               &  ", standard name "//TRIM(td_var%c_stdname)//&
+               &  ", already in mpp "//TRIM(td_mpp%c_name) )
+
+               DO ji=1,td_mpp%t_proc(1)%i_nvar
+                  CALL logger_debug( " MPP ADD VAR: in mpp structure : &
+                  &  variable "//TRIM(td_mpp%t_proc(1)%t_var(ji)%c_name)//&
+                  &  ", standard name "//&
+                  &  TRIM(td_mpp%t_proc(1)%t_var(ji)%c_stdname) )
+               ENDDO
+
+            ELSE
+            
+               CALL logger_info( &
+               &  " MPP ADD VAR: add variable "//TRIM(td_var%c_name)//&
+               &  ", standard name "//TRIM(td_var%c_stdname)//&
+               &  ", in mpp "//TRIM(td_mpp%c_name) )
+               ! check used dimension 
+               IF( mpp__check_dim(td_mpp, td_var) )THEN
+
+                  ! add variable in each processor
+                  DO ji=1,td_mpp%i_nproc
+
+                     ! split variable on domain decomposition
+                     tl_var=mpp__split_var(td_mpp, td_var, ji)
+
+                     CALL file_add_var(td_mpp%t_proc(ji), tl_var)
+
+                  ENDDO
+
+               ENDIF
+            ENDIF
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE mpp_add_var
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function extract from variable structure, part that will 
+   !> be written in processor id_procid.<br/>
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp : mpp structure
+   !> @param[in] td_var : variable structure
+   !> @param[in] id_procid : processor id
+   !> @return variable structure
+   !-------------------------------------------------------------------
+   ! @code   
+   TYPE(TVAR) FUNCTION mpp__split_var(td_mpp, td_var, id_procid)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP),  INTENT(IN) :: td_mpp
+      TYPE(TVAR),  INTENT(IN) :: td_var
+      INTEGER(i4), INTENT(IN) :: id_procid
+
+      ! local variable
+      TYPE(TDIM)  :: tl_dim
+
+      INTEGER(i4), DIMENSION(4) :: il_ind
+      INTEGER(i4), DIMENSION(2) :: il_size
+      INTEGER(i4) :: il_i1
+      INTEGER(i4) :: il_i2
+      INTEGER(i4) :: il_j1
+      INTEGER(i4) :: il_j2
+      !----------------------------------------------------------------
+
+      ! copy mpp
+      mpp__split_var=td_var
+
+      ! remove value over global domain from pointer
+      CALL var_del_value( mpp__split_var )
+
+      ! get processor dimension
+      il_size(:)=mpp_get_proc_size( td_mpp, id_procid )
+
+      ! define new dimension in variable structure 
+      IF( td_var%t_dim(1)%l_use )THEN
+         tl_dim=dim_init( TRIM(td_var%t_dim(1)%c_name), il_size(1) )
+         CALL var_move_dim( mpp__split_var, tl_dim )
+      ENDIF
+      IF( td_var%t_dim(2)%l_use )THEN
+         tl_dim=dim_init( TRIM(td_var%t_dim(2)%c_name), il_size(2) )
+         CALL var_move_dim( mpp__split_var, tl_dim )      
+      ENDIF
+
+      ! get processor indices
+      il_ind(:)=mpp_get_proc_index( td_mpp, id_procid )
+      il_i1 = il_ind(1)
+      il_i2 = il_ind(2)
+      il_j1 = il_ind(3)
+      il_j2 = il_ind(4)
+
+      IF( .NOT. td_var%t_dim(1)%l_use )THEN
+         il_i1=1 
+         il_i2=1 
+      ENDIF
+
+      IF( .NOT. td_var%t_dim(2)%l_use )THEN
+         il_j1=1 
+         il_j2=1 
+      ENDIF      
+
+      ! add variable value on processor
+      CALL var_add_value( mpp__split_var, &
+      &                   td_var%d_value(il_i1:il_i2, il_j1:il_j2, :, :) )
+
+   END FUNCTION mpp__split_var
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine delete variable in mpp structure, given variable
+   !> structure.
+   !>
+   !> @detail
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in]    td_var : variable strcuture
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp__del_var_str( td_mpp, td_var )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP), INTENT(INOUT) :: td_mpp
+      TYPE(TVAR), INTENT(IN)    :: td_var
+
+      ! local variable
+      INTEGER(i4)       :: il_varid
+      CHARACTER(LEN=lc) :: cl_name
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( " DEL VAR: domain decomposition not define "//&
+         &               " in mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+
+         ! check if variable already in mpp structure
+         il_varid = 0
+         IF( ASSOCIATED(td_mpp%t_proc(1)%t_var) )THEN
+            il_varid=var_get_id( td_mpp%t_proc(1)%t_var(:), &
+            &                    td_var%c_name, td_var%c_stdname )
+         ENDIF
+         IF( il_varid == 0 )THEN
+            CALL logger_error( &
+            &  " DEL VAR: no variable "//TRIM(td_var%c_name)//&
+            &  ", in mpp structure "//TRIM(td_mpp%c_name) )
+
+            DO ji=1,td_mpp%t_proc(1)%i_nvar
+               CALL logger_debug( " DEL VAR: in mpp structure : &
+               &  variable : "//TRIM(td_mpp%t_proc(1)%t_var(ji)%c_name)//&
+               &  ", standard name "//&
+               &  TRIM(td_mpp%t_proc(1)%t_var(ji)%c_stdname) )
+            ENDDO
+
+         ELSE
+
+            cl_name=TRIM(td_var%c_name)
+            DO ji=1,td_mpp%i_nproc
+               CALL file_del_var(td_mpp%t_proc(ji), TRIM(cl_name)) 
+            ENDDO
+
+         ENDIF
+
+      ENDIF
+   END SUBROUTINE mpp__del_var_str
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine delete variable in mpp structure, given variable name.
+   !>
+   !> @detail
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in]    cd_name: variable name
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp__del_var_name( td_mpp, cd_name )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP)      , INTENT(INOUT) :: td_mpp
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_name
+
+      ! local variable
+      INTEGER(i4)       :: il_varid
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( " DEL VAR: domain decomposition not define "//&
+         &               " in mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+
+         IF( td_mpp%t_proc(1)%i_nvar == 0 )THEN
+            CALL logger_debug( " DEL VAR NAME: no variable associated to mpp &
+            &                 structure "//TRIM(td_mpp%c_name) )
+         ELSE
+
+            ! get the variable id, in file variable structure
+            il_varid=0
+            IF( ASSOCIATED(td_mpp%t_proc(1)%t_var) )THEN
+               il_varid=var_get_id( td_mpp%t_proc(1)%t_var(:), &
+               &                    cd_name )
+            ENDIF
+            IF( il_varid == 0 )THEN
+
+               CALL logger_warn( &
+               &  "DEL VAR : there is no variable with name "//&
+               &  "or standard name "//TRIM(ADJUSTL(cd_name))//&
+               &  " in mpp structure "//TRIM(td_mpp%c_name))
+
+            ELSE
+
+               CALL mpp_del_var(td_mpp, td_mpp%t_proc(1)%t_var(il_varid)) 
+
+            ENDIF
+         ENDIF
+
+      ENDIF
+   END SUBROUTINE mpp__del_var_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine overwrite variable in mpp structure.
+   !>
+   !> @detail
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in]    td_var : variable structure
+   !> @todo
+   !> - voir si il ne faut pas redefinir (__copy) variable si elle vient de mpp
+   !> exemple CALL  mpp_move_var( td_mpp, td_mpp%t_proc()%t_var )
+   !> remarque cas probabelement impossible puisque td_var doit avoir dim de td_mpp
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp_move_var( td_mpp, td_var )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP), INTENT(INOUT) :: td_mpp
+      TYPE(TVAR), INTENT(IN)    :: td_var
+
+      !local variable
+      TYPE(TVAR) :: tl_var
+      !----------------------------------------------------------------
+      ! copy variable
+      tl_var=td_var
+
+      ! remove processor
+      CALL mpp_del_var(td_mpp, tl_var)
+
+      ! add processor
+      CALL mpp_add_var(td_mpp, tl_var)
+
+   END SUBROUTINE mpp_move_var
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine add processor to mpp structure.
+   !>
+   !> @detail
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in]    td_proc : processor strcuture
+   !
+   !> @todo 
+   !> - check proc type
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp__add_proc( td_mpp, td_proc )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP) , INTENT(INOUT) :: td_mpp
+      TYPE(TFILE), INTENT(IN)    :: td_proc
+
+      ! local variable
+      INTEGER(i4)                                  :: il_status
+      INTEGER(i4)                                  :: il_procid
+      INTEGER(i4)      , DIMENSION(1)              :: il_ind
+
+      TYPE(TFILE)      , DIMENSION(:), ALLOCATABLE :: tl_proc
+
+      CHARACTER(LEN=lc)                            :: cl_name
+      !----------------------------------------------------------------
+
+      ! check file name
+      cl_name=TRIM( file_rename(td_proc%c_name) )
+      IF( TRIM(cl_name) /=  TRIM(td_mpp%c_name) )THEN
+         CALL logger_warn("MPP ADD PROC: processor name do not match mpp name")
+      ENDIF
+
+      il_procid=0
+      IF( ASSOCIATED(td_mpp%t_proc) )THEN
+         ! check if processor already in mpp structure
+         il_ind(:)=MINLOC( td_mpp%t_proc(:)%i_pid, &
+                     mask=(td_mpp%t_proc(:)%i_pid==td_proc%i_pid) )
+         il_procid=il_ind(1)
+      ENDIF
+
+      IF( il_procid /= 0 )THEN
+
+            CALL logger_error( &
+            &  " ADD PROC: processor "//TRIM(fct_str(td_proc%i_pid))//&
+            &  ", already in mpp structure " )
+
+      ELSE
+         
+         CALL logger_trace("ADD PROC: add processor "//&
+         &               TRIM(fct_str(td_mpp%i_nproc+1))//" in mpp structure")
+
+         IF( td_mpp%i_nproc > 0 )THEN
+            ! 
+            il_ind(:)=MAXLOC( td_mpp%t_proc(:)%i_pid, &
+                        mask=(td_mpp%t_proc(:)%i_pid < td_proc%i_pid) )
+            il_procid=il_ind(1)
+
+            ! already other processor in mpp structure
+            ALLOCATE( tl_proc(td_mpp%i_nproc), stat=il_status )
+            IF(il_status /= 0 )THEN
+
+               CALL logger_error( " ADD PROC: not enough space to put processor &
+               &               in mpp structure")
+
+            ELSE
+               ! save temporary mpp structure
+               tl_proc(:)=td_mpp%t_proc(:)
+
+               DEALLOCATE( td_mpp%t_proc )
+               ALLOCATE( td_mpp%t_proc(td_mpp%i_nproc+1), stat=il_status)
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( " ADD PROC: not enough space to put "//&
+                  &  "processor in mpp structure ")
+
+               ENDIF
+
+               ! copy processor in mpp before
+               ! processor with lesser id than new processor
+               td_mpp%t_proc( 1:il_procid ) = tl_proc( 1:il_procid )
+
+               ! processor with greater id than new processor
+               td_mpp%t_proc( il_procid+1 : td_mpp%i_nproc+1 ) = &
+               &                 tl_proc( il_procid : td_mpp%i_nproc )
+
+               DEALLOCATE(tl_proc)
+            ENDIF
+
+         ELSE
+            ! no processor in mpp structure
+            IF( ASSOCIATED(td_mpp%t_proc) )THEN
+               DEALLOCATE(td_mpp%t_proc)
+            ENDIF
+            ALLOCATE( td_mpp%t_proc(td_mpp%i_nproc+1), stat=il_status )
+            IF(il_status /= 0 )THEN
+
+               CALL logger_error( " ADD PROC: not enough space to put "//&
+               &  "processor in mpp structure " )
+
+            ENDIF
+         ENDIF
+
+         ! check dimension
+         IF( ANY(td_mpp%t_dim(1:2)%i_len < td_proc%t_dim(1:2)%i_len) )THEN
+            CALL logger_error( "ADD PROC: mpp structure and new processor "//&
+            &  " dimension differ. ")
+            CALL logger_debug("ADD PROC: mpp dimension ("//&
+            &  TRIM(fct_str(td_mpp%t_dim(1)%i_len))//","//&
+            &  TRIM(fct_str(td_mpp%t_dim(2)%i_len))//")" )
+            CALL logger_debug("ADD PROC: processor dimension ("//&
+            &  TRIM(fct_str(td_proc%t_dim(1)%i_len))//","//&
+            &  TRIM(fct_str(td_proc%t_dim(2)%i_len))//")" )
+         ELSE
+            td_mpp%i_nproc=td_mpp%i_nproc+1
+
+            ! add new processor
+            td_mpp%t_proc(td_mpp%i_nproc)=td_proc
+         ENDIF
+
+      ENDIF
+   END SUBROUTINE mpp__add_proc
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine delete processor in mpp structure, given processor id.
+   !>
+   !> @detail
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in]    id_procid : processor id
+   !
+   !> @todo check proc id exist
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp__del_proc_id( td_mpp, id_procid )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP),   INTENT(INOUT) :: td_mpp
+      INTEGER(i4),  INTENT(IN)    :: id_procid
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_procid
+      INTEGER(i4), DIMENSION(1) :: il_ind
+      TYPE(TFILE), DIMENSION(:), ALLOCATABLE :: tl_proc
+      !----------------------------------------------------------------
+
+      il_ind(:)=MINLOC(td_mpp%t_proc(:)%i_pid,td_mpp%t_proc(:)%i_pid==id_procid)
+      il_procid=il_ind(1)
+      IF( il_procid == 0 )THEN
+         CALL logger_error("DEL PROC: no processor "//TRIM(fct_str(id_procid))//&
+         &              " associated to mpp structure")
+      ELSE
+         CALL logger_trace("DEL PROC: remove processor "//TRIM(fct_str(id_procid)))
+
+         IF( td_mpp%i_nproc > 1 )THEN
+            ALLOCATE( tl_proc(td_mpp%i_nproc-1), stat=il_status )
+            IF(il_status /= 0 )THEN
+               CALL logger_error( " DEL PROC: not enough space to put processor &
+               &                 in temporary mpp structure")
+
+            ELSE
+
+               ! save temporary processor's mpp structure
+               IF( il_procid > 1 )THEN
+                  tl_proc(1:il_procid-1)=td_mpp%t_proc(1:il_procid-1)
+               ENDIF
+               tl_proc(il_procid:)=td_mpp%t_proc(il_procid+1:)
+
+               ! new number of processor in mpp
+               td_mpp%i_nproc=td_mpp%i_nproc-1
+
+               DEALLOCATE( td_mpp%t_proc )
+               ALLOCATE( td_mpp%t_proc(td_mpp%i_nproc), stat=il_status )
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( " DEL PROC: not enough space to put processors &
+                  &               in mpp structure " )
+
+               ELSE
+
+                  ! copy processor in mpp before
+                  td_mpp%t_proc(:)=tl_proc(:)
+
+                  ! update processor id
+                  td_mpp%t_proc( il_procid : td_mpp%i_nproc )%i_pid = &
+                  &     td_mpp%t_proc( il_procid : td_mpp%i_nproc )%i_pid - 1
+
+               ENDIF
+            ENDIF
+         ELSE
+            DEALLOCATE( td_mpp%t_proc )
+
+            ! new number of processor in mpp
+            td_mpp%i_nproc=td_mpp%i_nproc-1
+         ENDIF
+      ENDIF
+   END SUBROUTINE mpp__del_proc_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine delete processor in mpp structure, given processor
+   !>    structure.
+   !>
+   !> @detail
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in]    td_proc : file/processor structure
+   !
+   !> @todo check proc id exist
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp__del_proc_str( td_mpp, td_proc )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP),   INTENT(INOUT) :: td_mpp
+      TYPE(TFILE),  INTENT(IN)    :: td_proc
+      !----------------------------------------------------------------
+
+      IF( td_proc%i_pid >= 0 )THEN
+         CALL mpp__del_proc( td_mpp, td_proc%i_pid )
+      ELSE
+         CALL logger_error("DEL PROC: processor not defined")
+      ENDIF
+
+   END SUBROUTINE mpp__del_proc_str
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine overwrite processor in mpp structure.
+   !>
+   !> @detail
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in]    id_procid : processor id
+   !> @todo
+   !> - voir si il ne faut pas redefinir (__copy) proc si il vient de mpp
+   !> exemple CALL  mpp_move_proc( td_mpp, td_mpp%t_proc )   
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp__move_proc( td_mpp, td_proc )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP),  INTENT(INOUT) :: td_mpp
+      TYPE(TFILE), INTENT(IN)    :: td_proc
+      !----------------------------------------------------------------
+
+      ! remove processor
+      CALL mpp__del_proc(td_mpp, td_proc)
+
+      ! add processor
+      CALL mpp__add_proc(td_mpp, td_proc)
+
+   END SUBROUTINE mpp__move_proc
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a dimension structure in a mpp 
+   !> structure.
+   !> Do not overwrite, if dimension already in mpp structure.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_mpp : mpp structure
+   !> @param[in] td_dim : dimension structure
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE mpp_add_dim(td_mpp, td_dim)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP), INTENT(INOUT) :: td_mpp
+      TYPE(TDIM), INTENT(IN)    :: td_dim
+
+      ! local variable
+      INTEGER(i4) :: il_dimid
+
+      ! loop indices
+      !----------------------------------------------------------------
+      IF( td_mpp%i_ndim <= 4 )THEN
+
+         ! check if dimension already in mpp structure
+         il_dimid=dim_get_id(td_mpp%t_dim(:), td_dim%c_name, td_dim%c_sname)
+         IF( il_dimid /= 0 )THEN
+
+            CALL logger_error( &
+            &  " ADD DIM: dimension "//TRIM(td_dim%c_name)//&
+            &  ", short name "//TRIM(td_dim%c_sname)//&
+            &  ", already in mpp "//TRIM(td_mpp%c_name) )
+
+         ELSE
+
+            CALL logger_debug( &
+            &  " ADD DIM: add dimension "//TRIM(td_dim%c_name)//&
+            &  ", short name "//TRIM(td_dim%c_sname)//&
+            &  ", in mpp "//TRIM(td_mpp%c_name) )
+
+            IF( td_mpp%i_ndim == 4 )THEN
+               ! search empty dimension
+               il_dimid=dim_get_void_id(td_mpp%t_dim(:),TRIM(td_dim%c_name), &
+               &                                        TRIM(td_dim%c_sname))
+               ! replace empty dimension
+               td_mpp%t_dim(il_dimid)=td_dim
+               td_mpp%t_dim(il_dimid)%i_id=il_dimid
+               td_mpp%t_dim(il_dimid)%l_use=.TRUE.
+            ELSE
+               il_dimid=dim_get_void_id(td_mpp%t_dim(:),TRIM(td_dim%c_name), &
+               &                                        TRIM(td_dim%c_sname))
+               ! add new dimension
+               td_mpp%t_dim(il_dimid)=td_dim
+               td_mpp%t_dim(il_dimid)%i_id=td_mpp%i_ndim+1
+               td_mpp%t_dim(il_dimid)%l_use=.TRUE.
+               ! update number of attribute
+               td_mpp%i_ndim=COUNT(td_mpp%t_dim(:)%l_use)
+            ENDIF
+
+            ! reorder dimension to ('x','y','z','t')
+            CALL dim_reorder(td_mpp%t_dim)
+
+         ENDIF
+
+      ELSE
+         CALL logger_error( &
+         &  " ADD DIM: too much dimension in mpp "//&
+         &  TRIM(td_mpp%c_name)//" ("//TRIM(fct_str(td_mpp%i_ndim))//")")
+      ENDIF
+
+   END SUBROUTINE mpp_add_dim
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine delete a dimension structure in a mpp 
+   !> structure.<br/>
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_mpp : mpp structure
+   !> @param[in] td_dim : dimension structure
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE mpp_del_dim(td_mpp, td_dim)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP), INTENT(INOUT) :: td_mpp
+      TYPE(TDIM), INTENT(IN)    :: td_dim
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_dimid
+      TYPE(TDIM), DIMENSION(:), ALLOCATABLE  :: tl_dim
+
+      ! loop indices
+      !----------------------------------------------------------------
+      IF( td_mpp%i_ndim <= 4 )THEN
+
+         ! check if dimension already in mpp structure
+         il_dimid=dim_get_id(td_mpp%t_dim(:), td_dim%c_name, td_dim%c_sname)
+         IF( il_dimid == 0 )THEN
+
+            CALL logger_error( &
+            &  " DEL DIM: no dimension "//TRIM(td_dim%c_name)//&
+            &  ", short name "//TRIM(td_dim%c_sname)//&
+            &  ", in mpp "//TRIM(td_mpp%c_name) )
+
+         ELSE
+
+            CALL logger_debug( &
+            &  " DEL DIM: delete dimension "//TRIM(td_dim%c_name)//&
+            &  ", short name "//TRIM(td_dim%c_sname)//&
+            &  ", in mpp "//TRIM(td_mpp%c_name) )
+
+            IF( td_mpp%i_ndim == 4 )THEN
+               ALLOCATE( tl_dim(1), stat=il_status )
+               IF(il_status /= 0 )THEN
+                  CALL logger_error( &
+                  &  " DEL DIM: not enough space to put dimensions from "//&
+                  &  TRIM(td_mpp%c_name)//" in temporary dimension structure")
+               ELSE
+                  ! replace dimension by empty one
+                  td_mpp%t_dim(il_dimid)=tl_dim(1)
+               ENDIF
+               DEALLOCATE(tl_dim)
+            ELSE
+               ! 
+               ALLOCATE( tl_dim(td_mpp%i_ndim), stat=il_status )
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( &
+                  &  " DEL DIM: not enough space to put dimensions from "//&
+                  &  TRIM(td_mpp%c_name)//" in temporary dimension structure")
+
+               ELSE
+
+                  ! save temporary dimension's mpp structure
+                  tl_dim( 1 : il_dimid-1 ) = td_mpp%t_dim( 1 : il_dimid-1 )
+                  tl_dim( il_dimid : td_mpp%i_ndim-1 ) = &
+                  &           td_mpp%t_dim( il_dimid+1 : td_mpp%i_ndim )
+
+                  ! copy dimension in file, except one
+                  td_mpp%t_dim(1:td_mpp%i_ndim)=tl_dim(:)
+
+                  ! update number of dimension
+                  td_mpp%i_ndim=td_mpp%i_ndim-1
+
+               ENDIF
+            ENDIF
+
+            ! reorder dimension to ('x','y','z','t')
+            CALL dim_reorder(td_mpp%t_dim)
+
+            !IF( ASSOCIATED(td_mpp%t_proc) )THEN
+            !   ! del dimension of processor
+            !   DO ji=1,td_mpp%i_nproc
+            !      CALL file_del_dim(td_mpp%t_proc(ji), td_dim)
+            !   ENDDO
+            !ENDIF
+
+         ENDIF
+      ELSE
+         CALL logger_error( &
+         &  " DEL DIM: too much dimension in mpp "//&
+         &  TRIM(td_mpp%c_name)//" ("//TRIM(fct_str(td_mpp%i_ndim))//")")
+      ENDIF
+
+   END SUBROUTINE mpp_del_dim
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine move a dimension structure 
+   !> in mpp structure.
+   !> @warning dimension order may have changed
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_mpp : mpp structure
+   !> @param[in] td_dim : dimension structure
+   !> @todo
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE mpp_move_dim(td_mpp, td_dim)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP), INTENT(INOUT) :: td_mpp
+      TYPE(TDIM), INTENT(IN)    :: td_dim
+
+      ! local variable
+      INTEGER(i4) :: il_dimid
+
+      !----------------------------------------------------------------
+
+      il_dimid=dim_get_id(td_mpp%t_dim(:), TRIM(td_dim%c_name), &
+      &                                    TRIM(td_dim%c_sname))
+      IF( il_dimid /= 0 )THEN
+         ! remove dimension with same name
+         CALL mpp_del_dim(td_mpp, td_dim)
+      ENDIF
+
+      ! add new dimension
+      CALL mpp_add_dim(td_mpp, td_dim)
+
+   END SUBROUTINE mpp_move_dim
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine add global attribute to mpp structure.
+   !>
+   !> @detail
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in]    td_att : attribute strcuture
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp_add_att( td_mpp, td_att )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP), INTENT(INOUT) :: td_mpp
+      TYPE(TATT), INTENT(IN)    :: td_att
+
+      ! local variable
+      INTEGER(i4) :: il_attid
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( "MPP ADD ATT: domain decomposition not define "//&
+         &               "for mpp "//TRIM(td_mpp%c_name))
+
+      ELSE
+         ! check if variable exist
+         IF( TRIM(td_att%c_name) == '' )THEN
+            CALL logger_error("MPP ADD ATT: attribute not define ")
+         ELSE
+            ! check if attribute already in mpp structure
+            il_attid=0
+            IF( ASSOCIATED(td_mpp%t_proc(1)%t_att) )THEN
+               il_attid=att_get_id( td_mpp%t_proc(1)%t_att(:), &
+               &                    td_att%c_name )
+            ENDIF
+            IF( il_attid /= 0 )THEN
+
+               CALL logger_error( " MPP ADD ATT: attribute "//TRIM(td_att%c_name)//&
+               &  ", already in mpp "//TRIM(td_mpp%c_name) )
+
+               DO ji=1,td_mpp%t_proc(1)%i_natt
+                  CALL logger_debug( " MPP ADD ATT: in mpp structure : &
+                  &  attribute "//TRIM(td_mpp%t_proc(1)%t_att(ji)%c_name) )
+               ENDDO
+
+            ELSE
+            
+               CALL logger_info( &
+               &  " MPP ADD VAR: add attribute "//TRIM(td_att%c_name)//&
+               &  ", in mpp "//TRIM(td_mpp%c_name) )
+
+               ! add attribute in each processor
+               DO ji=1,td_mpp%i_nproc
+
+                  CALL file_add_att(td_mpp%t_proc(ji), td_att)
+
+               ENDDO
+
+            ENDIF
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE mpp_add_att
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine delete attribute in mpp structure, given attribute
+   !> structure.
+   !>
+   !> @detail
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in]    td_att : attribute strcuture
+   !
+   !> @todo 
+   !> - check proc id exist
+   !> - check proc dimension
+   !> - check proc file name
+   !> - check proc type
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp__del_att_str( td_mpp, td_att )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP), INTENT(INOUT) :: td_mpp
+      TYPE(TATT), INTENT(IN)    :: td_att
+
+      ! local variable
+      INTEGER(i4)       :: il_attid
+      CHARACTER(LEN=lc) :: cl_name
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( " DEL VAR: domain decomposition not define "//&
+         &               " in mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+
+         ! check if attribute already in mpp structure
+         il_attid=0
+         IF( ASSOCIATED(td_mpp%t_proc(1)%t_att) )THEN
+            il_attid=att_get_id( td_mpp%t_proc(1)%t_att(:), &
+            &                    td_att%c_name )
+         ENDIF
+         IF( il_attid == 0 )THEN
+            CALL logger_error( &
+            &  " DEL VAR: no attribute "//TRIM(td_att%c_name)//&
+            &  ", in mpp structure "//TRIM(td_mpp%c_name) )
+
+            DO ji=1,td_mpp%t_proc(1)%i_natt
+               CALL logger_debug( " DEL ATT: in mpp structure : &
+               &  attribute : "//TRIM(td_mpp%t_proc(1)%t_var(ji)%c_name) )
+            ENDDO
+
+         ELSE
+
+            cl_name=TRIM(td_att%c_name)
+            DO ji=1,td_mpp%i_nproc
+               CALL file_del_att(td_mpp%t_proc(ji), TRIM(cl_name)) 
+            ENDDO
+
+         ENDIF
+
+      ENDIF
+   END SUBROUTINE mpp__del_att_str
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine delete attribute in mpp structure, given attribute name.
+   !>
+   !> @detail
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in]    cd_name: attribute name
+   !
+   !> @todo 
+   !> - check proc id exist
+   !> - check proc dimension
+   !> - check proc file name
+   !> - check proc type
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp__del_att_name( td_mpp, cd_name )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP)       , INTENT(INOUT) :: td_mpp
+      CHARACTER(LEN=*) , INTENT(IN   ) :: cd_name
+
+      ! local variable
+      INTEGER(i4)       :: il_attid
+      !----------------------------------------------------------------
+      ! check if mpp exist
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+
+         CALL logger_error( " DEL ATT: domain decomposition not define "//&
+         &               " in mpp strcuture "//TRIM(td_mpp%c_name))
+
+      ELSE
+
+         IF( td_mpp%t_proc(1)%i_natt == 0 )THEN
+            CALL logger_debug( " DEL ATT NAME: no attribute associated to mpp &
+            &                 structure "//TRIM(td_mpp%c_name) )
+         ELSE
+
+            ! get the attribute id, in file variable structure
+            il_attid=0
+            IF( ASSOCIATED(td_mpp%t_proc(1)%t_att) )THEN
+               il_attid=att_get_id( td_mpp%t_proc(1)%t_att(:), &
+               &                    cd_name )
+            ENDIF
+
+            IF( il_attid == 0 )THEN
+
+               CALL logger_warn( &
+               &  " DEL ATT : there is no attribute with "//&
+               &  "name "//TRIM(cd_name)//" in mpp structure "//&
+               &  TRIM(td_mpp%c_name))
+
+            ELSE
+
+               CALL mpp_del_att(td_mpp, td_mpp%t_proc(1)%t_att(il_attid)) 
+
+            ENDIF
+         ENDIF
+
+      ENDIF
+   END SUBROUTINE mpp__del_att_name
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine overwrite attribute in mpp structure.
+   !>
+   !> @detail
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in]    td_att : attribute structure
+   !> @todo
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp_move_att( td_mpp, td_att )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP), INTENT(INOUT) :: td_mpp
+      TYPE(TATT), INTENT(IN)    :: td_att
+
+      !local variable
+      TYPE(TATT) :: tl_att
+      !----------------------------------------------------------------
+      ! copy variable
+      tl_att=td_att
+
+      ! remove processor
+      CALL mpp_del_att(td_mpp, tl_att)
+
+      ! add processor
+      CALL mpp_add_att(td_mpp, tl_att)
+
+   END SUBROUTINE mpp_move_att
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine compute domain decomposition for niproc and njproc 
+   !> processors following I and J.
+   !>
+   !> @detail
+   !> To do so, it need to know :
+   !> - global domain dimension
+   !> - overlap region length
+   !> - number of processors following I and J
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp__compute( td_mpp )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP), INTENT(INOUT) :: td_mpp
+
+      ! local variable
+      INTEGER(i4)                              :: il_isize !< i-direction maximum sub domain size 
+      INTEGER(i4)                              :: il_jsize !< j-direction maximum sub domain size
+      INTEGER(i4)                              :: il_resti !<  
+      INTEGER(i4)                              :: il_restj !<  
+      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_nlci
+      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_nlcj
+      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_impp
+      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_jmpp
+
+      CHARACTER(LEN=lc)                        :: cl_file
+      TYPE(TFILE)                              :: tl_proc
+      TYPE(TATT)                               ::tl_att
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      ! intialise
+      td_mpp%i_nproc=0
+
+      CALL logger_trace( "COMPUTE: compute domain decomposition with "//&
+      &               TRIM(fct_str(td_mpp%i_niproc))//" x "//&
+      &               TRIM(fct_str(td_mpp%i_njproc))//" processors")
+      ! maximum size of sub domain
+      il_isize = ((td_mpp%t_dim(1)%i_len - 2*td_mpp%i_preci + (td_mpp%i_niproc-1))/ &
+      &           td_mpp%i_niproc) + 2*td_mpp%i_preci
+      il_jsize = ((td_mpp%t_dim(2)%i_len - 2*td_mpp%i_precj + (td_mpp%i_njproc-1))/ &
+      &           td_mpp%i_njproc) + 2*td_mpp%i_precj
+
+      il_resti = MOD(td_mpp%t_dim(1)%i_len - 2*td_mpp%i_preci, td_mpp%i_niproc)
+      il_restj = MOD(td_mpp%t_dim(2)%i_len - 2*td_mpp%i_precj, td_mpp%i_njproc)
+      IF( il_resti == 0 ) il_resti = td_mpp%i_niproc
+      IF( il_restj == 0 ) il_restj = td_mpp%i_njproc
+
+      ! compute dimension of each sub domain
+      ALLOCATE( il_nlci(td_mpp%i_niproc,td_mpp%i_njproc) )
+      ALLOCATE( il_nlcj(td_mpp%i_niproc,td_mpp%i_njproc) )
+
+      il_nlci( 1 : il_resti                , : ) = il_isize
+      il_nlci( il_resti+1 : td_mpp%i_niproc, : ) = il_isize-1
+
+      il_nlcj( : , 1 : il_restj                ) = il_jsize
+      il_nlcj( : , il_restj+1 : td_mpp%i_njproc) = il_jsize-1
+
+      ! compute first index of each sub domain
+      ALLOCATE( il_impp(td_mpp%i_niproc,td_mpp%i_njproc) )
+      ALLOCATE( il_jmpp(td_mpp%i_niproc,td_mpp%i_njproc) )
+
+      il_impp(:,:)=1
+      il_jmpp(:,:)=1
+
+      DO jj=1,td_mpp%i_njproc
+         DO ji=2,td_mpp%i_niproc
+            il_impp(ji,jj)=il_impp(ji-1,jj)+il_nlci(ji-1,jj)-2*td_mpp%i_preci
+         ENDDO
+      ENDDO
+
+      DO jj=2,td_mpp%i_njproc
+         DO ji=1,td_mpp%i_niproc
+            il_jmpp(ji,jj)=il_jmpp(ji,jj-1)+il_nlcj(ji,jj-1)-2*td_mpp%i_precj
+         ENDDO
+      ENDDO 
+
+      DO jj=1,td_mpp%i_njproc
+         DO ji=1,td_mpp%i_niproc
+
+            jk=ji+(jj-1)*td_mpp%i_niproc
+
+            ! get processor file name
+            cl_file=file_rename(td_mpp%c_name,jk)
+            ! initialise file structure
+            tl_proc=file_init(cl_file,td_mpp%c_type)
+
+            ! procesor id
+            tl_proc%i_pid=jk
+
+            tl_att=att_init("DOMAIN_number",tl_proc%i_pid)
+            CALL file_add_att(tl_proc, tl_att)
+
+            ! processor indices
+            tl_proc%i_iind=ji
+            tl_proc%i_jind=jj
+
+            ! fill processor dimension and first indices
+            tl_proc%i_impp = il_impp(ji,jj)
+            tl_proc%i_jmpp = il_jmpp(ji,jj)
+
+            tl_att=att_init( "DOMAIN_poistion_first", &
+            &                (/tl_proc%i_impp, tl_proc%i_jmpp/) )
+            CALL file_add_att(tl_proc, tl_att)
+
+            tl_proc%i_lci  = il_nlci(ji,jj)
+            tl_proc%i_lcj  = il_nlcj(ji,jj)
+
+            tl_att=att_init( "DOMAIN_poistion_last", &
+            &                (/tl_proc%i_lci, tl_proc%i_lcj/) )
+            CALL file_add_att(tl_proc, tl_att)
+
+
+            ! compute first and last indoor indices
+            
+            ! west boundary
+            IF( ji == 1 )THEN
+               tl_proc%i_ldi = 1 
+               tl_proc%l_ctr = .TRUE.
+            ELSE
+               tl_proc%i_ldi = 1 + td_mpp%i_preci
+            ENDIF
+
+            ! south boundary
+            IF( jj == 1 )THEN
+               tl_proc%i_ldj = 1 
+               tl_proc%l_ctr = .TRUE.
+            ELSE
+               tl_proc%i_ldj = 1 + td_mpp%i_precj
+            ENDIF
+
+            ! east boundary
+            IF( ji == td_mpp%i_niproc )THEN
+               tl_proc%i_lei = il_nlci(ji,jj)
+               tl_proc%l_ctr = .TRUE.
+            ELSE
+               tl_proc%i_lei = il_nlci(ji,jj) - td_mpp%i_preci
+            ENDIF
+
+            ! north boundary
+            IF( jj == td_mpp%i_njproc )THEN
+               tl_proc%i_lej = il_nlcj(ji,jj)
+               tl_proc%l_ctr = .TRUE.
+            ELSE
+               tl_proc%i_lej = il_nlcj(ji,jj) - td_mpp%i_precj
+            ENDIF
+
+            tl_att=att_init( "DOMAIN_halo_size_start", &
+            &                (/tl_proc%i_ldi, tl_proc%i_ldj/) )
+            CALL file_add_att(tl_proc, tl_att)
+            tl_att=att_init( "DOMAIN_halo_size_end", &
+            &                (/tl_proc%i_ldi, tl_proc%i_ldj/) )
+            CALL file_add_att(tl_proc, tl_att)
+
+            ! add processor to mpp structure
+            CALL mpp__add_proc(td_mpp, tl_proc)
+
+         ENDDO
+      ENDDO
+
+      DEALLOCATE( il_impp, il_jmpp )
+      DEALLOCATE( il_nlci, il_nlcj )
+
+   END SUBROUTINE mpp__compute
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !>  This subroutine remove land processor from domain decomposition.
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in] id_mask : sub domain mask (sea=1, land=0)
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp__del_land( td_mpp, id_mask )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP),                  INTENT(INOUT) :: td_mpp
+      INTEGER(i4), DIMENSION(:,:), INTENT(IN)    :: id_mask
+
+      ! loop indices
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      IF( ASSOCIATED(td_mpp%t_proc) )THEN
+         jk=1
+         DO WHILE( jk <= td_mpp%i_nproc )
+            IF( mpp__land_proc(td_mpp, jk, id_mask(:,:)) )THEN
+               CALL mpp__del_proc(td_mpp, jk)
+            ELSE
+               jk=jk+1
+            ENDIF
+         ENDDO
+      ELSE
+         CALL logger_error("DEL LAND: domain decomposition not define.")
+      ENDIF
+
+   END SUBROUTINE mpp__del_land
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !>  This subroutine optimize the number of sub domain to be used, given mask.
+   !> @details
+   !>  Actually it get the domain decomposition with the most land 
+   !>  processor removed.
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp__optimiz( td_mpp, id_mask )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP),                  INTENT(INOUT) :: td_mpp
+      INTEGER(i4), DIMENSION(:,:), INTENT(IN)    :: id_mask
+
+      ! local variable
+      TYPE(TMPP)  :: tl_mpp
+      INTEGER(i4) :: il_maxproc
+
+      TYPE(TFILE), DIMENSION(:), ALLOCATABLE :: tl_proc
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      CALL logger_trace("OPTIMIZ: look for best domain decomposition")
+      tl_mpp=td_mpp
+
+      ! save maximum number of processor to be used
+      il_maxproc=td_mpp%i_nproc
+      ! 
+      td_mpp%i_nproc=0
+      DO ji=1,il_maxproc
+         DO jj=1,il_maxproc
+
+            ! clean mpp processor
+            IF( ASSOCIATED(tl_mpp%t_proc) )THEN
+               DEALLOCATE(tl_mpp%t_proc)
+            ENDIF
+
+            ! compute domain decomposition
+            tl_mpp%i_niproc=ji
+            tl_mpp%i_njproc=jj
+            
+            CALL mpp__compute( tl_mpp )
+            
+            ! remove land sub domain
+            CALL mpp__del_land( tl_mpp, id_mask )
+
+            CALL logger_info("OPTIMIZ: number of processor "//&
+            &  TRIM(fct_str(tl_mpp%i_nproc)) )
+            IF( tl_mpp%i_nproc > td_mpp%i_nproc .AND. &
+            &   tl_mpp%i_nproc <= il_maxproc )THEN
+               ! save optimiz decomposition 
+
+               ! clean mpp
+               CALL mpp_clean(td_mpp)
+
+               ! save processor table
+               ALLOCATE( tl_proc(tl_mpp%i_nproc) )
+               tl_proc(:)=tl_mpp%t_proc(:)
+
+               ! remove pointer on processor table
+               DEALLOCATE(tl_mpp%t_proc)
+ 
+               ! save data except processor table
+               td_mpp=tl_mpp
+               ! save processor table
+               ALLOCATE( td_mpp%t_proc(td_mpp%i_nproc) )
+               td_mpp%t_proc(:)=tl_proc(:)
+
+               DEALLOCATE( tl_proc )
+
+            ENDIF
+            
+         ENDDO
+      ENDDO
+
+   END SUBROUTINE mpp__optimiz
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This function check if processor is a land processor.
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[in] td_mpp : mpp strcuture
+   !> @param[in] id_proc : processor id
+   !> @param[in] id_mask : sub domain mask (sea=1, land=0)
+   !-------------------------------------------------------------------
+   !> @code
+   LOGICAL FUNCTION mpp__land_proc( td_mpp , id_proc, id_mask )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP),                  INTENT(IN) :: td_mpp
+      INTEGER(i4),                 INTENT(IN) :: id_proc
+      INTEGER(i4), DIMENSION(:,:), INTENT(IN) :: id_mask
+
+      ! local variable
+      INTEGER(i4), DIMENSION(2) :: il_shape
+      !----------------------------------------------------------------
+
+      CALL logger_trace("LAND PROC: check processor "//TRIM(fct_str(id_proc))//&
+      &  " of mpp "//TRIM(td_mpp%c_name) )
+      mpp__land_proc=.FALSE.
+      IF( ASSOCIATED(td_mpp%t_proc) )THEN
+
+         il_shape(:)=SHAPE(id_mask)
+         IF( il_shape(1) /= td_mpp%t_dim(1)%i_len .OR. &
+         &   il_shape(2) /= td_mpp%t_dim(2)%i_len )THEN
+             CALL logger_error("LAND PROC: mask and domain size differ")
+         ELSE
+            IF( ALL(id_mask( td_mpp%t_proc(id_proc)%i_impp +            &
+            &                       td_mpp%t_proc(id_proc)%i_ldi - 1 : &
+            &                td_mpp%t_proc(id_proc)%i_impp +            &
+            &                       td_mpp%t_proc(id_proc)%i_lei - 1,  &
+            &                td_mpp%t_proc(id_proc)%i_jmpp +            &
+            &                       td_mpp%t_proc(id_proc)%i_ldj - 1 : &
+            &                td_mpp%t_proc(id_proc)%i_jmpp +            &
+            &                       td_mpp%t_proc(id_proc)%i_lej - 1)  &
+            &      /= 1 ) )THEN
+               ! land domain
+               CALL logger_info(" LAND PROC: processor "//TRIM(fct_str(id_proc))//&
+               &             " is land processor")
+               mpp__land_proc=.TRUE.
+            ENDIF
+         ENDIF
+
+      ELSE
+         CALL logger_error("LAND PROC: domain decomposition not define.")
+      ENDIF
+
+   END FUNCTION mpp__land_proc
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !>  This subroutine clean mpp strcuture.
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp_clean( td_mpp )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP),  INTENT(INOUT) :: td_mpp
+
+      ! local variable
+      TYPE(TMPP) :: tl_mpp ! empty mpp structure
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      CALL logger_info( &
+      &  " CLEAN: reset mpp "//TRIM(td_mpp%c_name) )
+
+      ! del dimension
+      IF( td_mpp%i_ndim /= 0 )THEN
+         DO ji=td_mpp%i_ndim,1,-1
+            CALL dim_clean( td_mpp%t_dim(ji) )
+         ENDDO
+      ENDIF
+
+      IF( ASSOCIATED(td_mpp%t_proc) )THEN
+         ! clean each proc
+         DO ji=1,td_mpp%i_nproc
+            CALL file_clean( td_mpp%t_proc(ji) )
+         ENDDO
+         DEALLOCATE(td_mpp%t_proc)
+      ENDIF
+
+      ! replace by empty structure
+      td_mpp=tl_mpp
+
+   END SUBROUTINE mpp_clean
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !>  This subroutine get sub domains which cover "zoom domain".
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @param[in] td_dom : domain strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp_get_use( td_mpp, td_dom )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP),  INTENT(INOUT) :: td_mpp
+      TYPE(TDOM),  INTENT(IN)    :: td_dom
+
+      ! local variable
+      INTEGER(i4) :: il_jmin
+      LOGICAL     :: ll_iuse
+      LOGICAL     :: ll_juse
+
+      ! loop indices
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+      IF( ASSOCIATED(td_mpp%t_proc) )THEN
+   
+         ! check domain
+         IF( td_mpp%t_dim(1)%i_len == td_dom%t_dim0(1)%i_len .AND. &
+         &   td_mpp%t_dim(2)%i_len == td_dom%t_dim0(2)%i_len )THEN
+
+            td_mpp%t_proc(:)%l_use=.FALSE.
+            DO jk=1,td_mpp%i_nproc
+
+               ! check i-direction
+               ll_iuse=.FALSE.
+               IF( td_dom%i_imin < td_dom%i_imax )THEN
+
+                  ! not overlap east west boundary
+                  IF( td_mpp%t_proc(jk)%i_impp + td_mpp%t_proc(jk)%i_lci > &
+                  &   td_dom%i_imin .AND.                                  &
+                  &   td_mpp%t_proc(jk)%i_impp < td_dom%i_imax )THEN
+                      ll_iuse=.TRUE.
+                  ENDIF
+
+               ELSEIF( td_dom%i_imin == td_dom%i_imax )THEN
+
+                  ! east west cyclic
+                  ll_iuse=.TRUE.
+
+               ELSE ! td_dom%i_imin > td_dom%i_imax
+
+                  ! overlap east west boundary
+                  IF( ( td_mpp%t_proc(jk)%i_impp + td_mpp%t_proc(jk)%i_lci >  &
+                  &     td_dom%i_imin .AND.                                   &
+                  &     td_mpp%t_proc(jk)%i_impp < td_dom%t_dim0(1)%i_len )    &
+                  &   .OR.                                                    &
+                  &   ( td_mpp%t_proc(jk)%i_impp + td_mpp%t_proc(jk)%i_lci >  &
+                  &     1 .AND.                                               &
+                  &     td_mpp%t_proc(jk)%i_impp < td_dom%i_imax) )THEN
+                     ll_iuse=.TRUE.
+                  ENDIF
+
+               ENDIF
+
+               ! check j-direction
+               ll_juse=.FALSE.
+               IF( td_dom%i_jmin < td_dom%i_jmax )THEN
+
+                  ! not overlap north fold
+                  IF( td_mpp%t_proc(jk)%i_jmpp + td_mpp%t_proc(jk)%i_lcj > &
+                  &   td_dom%i_jmin .AND.                                  &
+                  &   td_mpp%t_proc(jk)%i_jmpp < td_dom%i_jmax )THEN
+                     ll_juse=.TRUE.
+                  ENDIF
+
+               ELSE ! td_dom%i_jmin >= td_dom%i_jmax
+
+                  il_jmin=MIN(td_dom%i_jmin,td_dom%i_jmax)
+                  IF( td_mpp%t_proc(jk)%i_jmpp + td_mpp%t_proc(jk)%i_lcj > &
+                  &  il_jmin )THEN
+                     ll_juse=.TRUE.
+                  ENDIF
+
+               ENDIF
+
+               IF( ll_iuse .AND. ll_juse ) td_mpp%t_proc(jk)%l_use=.TRUE.
+
+            ENDDO
+         ELSE
+            CALL logger_error("GET USE: domain differ")
+         ENDIF
+
+      ELSE
+         CALL logger_error("GET USE: domain decomposition not define.")
+      ENDIF
+
+   END SUBROUTINE mpp_get_use
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !>  This subroutine get sub domains which form global domain border.
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp_get_contour( td_mpp )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP),  INTENT(INOUT) :: td_mpp
+
+      ! loop indices
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      IF( ASSOCIATED(td_mpp%t_proc) )THEN
+
+         td_mpp%t_proc(:)%l_ctr = .FALSE.
+         DO jk=1,td_mpp%i_nproc
+            IF( td_mpp%t_proc(jk)%i_ldi == 1 .OR. &
+            &   td_mpp%t_proc(jk)%i_ldj == 1 .OR. &
+            &   td_mpp%t_proc(jk)%i_lei == td_mpp%t_proc(jk)%i_lci .OR. &
+            &   td_mpp%t_proc(jk)%i_lej == td_mpp%t_proc(jk)%i_lcj )THEN
+
+               td_mpp%t_proc(jk)%l_ctr = .TRUE.
+            
+            ENDIF
+         ENDDO
+   
+      ELSE
+         CALL logger_error("GET CONTOUR: domain decomposition not define.")
+      ENDIF
+
+   END SUBROUTINE mpp_get_contour
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function return processor indices, without overlap boundary,
+   !> given processor id. This depends of domain decompisition type. 
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[in] td_mpp : mpp strcuture
+   !> @param[in] id_procid : processor id
+   !> @return table of index (/ i1, i2, j1, j2 /)
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION mpp_get_proc_index( td_mpp, id_procid )
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TMPP),  INTENT(IN) :: td_mpp
+      INTEGER(i4), INTENT(IN) :: id_procid
+
+      ! function
+      INTEGER(i4), DIMENSION(4) :: mpp_get_proc_index
+
+      ! local variable
+      INTEGER(i4) :: il_i1, il_i2
+      INTEGER(i4) :: il_j1, il_j2
+      TYPE(TMPP)  :: tl_mpp
+      !----------------------------------------------------------------
+
+      IF( ASSOCIATED(td_mpp%t_proc) )THEN
+
+         tl_mpp=td_mpp
+         !IF( TRIM(td_mpp%c_dom) == "unknown" )THEN
+         IF( TRIM(td_mpp%c_dom) == '' )THEN
+            CALL logger_warn("GET PROC INDEX: decomposition type unknown. "//&
+            &             "look for it")
+            CALL mpp_get_dom( tl_mpp )
+         ENDIF
+
+         SELECT CASE(TRIM(tl_mpp%c_dom))
+            CASE('full')
+               il_i1 = 1 ; il_i2 = td_mpp%t_dim(1)%i_len
+               il_j1 = 1 ; il_j2 = td_mpp%t_dim(2)%i_len
+            CASE('overlap')
+                il_i1 = td_mpp%t_proc(id_procid)%i_impp
+                il_j1 = td_mpp%t_proc(id_procid)%i_jmpp
+
+                il_i2 = il_i1 + td_mpp%t_proc(id_procid)%i_lci - 1 ! attention lei dans ioRestartDimg
+                il_j2 = il_j1 + td_mpp%t_proc(id_procid)%i_lcj - 1 
+            CASE('nooverlap')
+               il_i1 = td_mpp%t_proc(id_procid)%i_impp + &
+               &        td_mpp%t_proc(id_procid)%i_ldi - 1
+               il_j1 = td_mpp%t_proc(id_procid)%i_jmpp + &
+               &        td_mpp%t_proc(id_procid)%i_ldj - 1
+
+               il_i2 = td_mpp%t_proc(id_procid)%i_impp + &
+               &        td_mpp%t_proc(id_procid)%i_lei - 1
+               il_j2 = td_mpp%t_proc(id_procid)%i_jmpp + &
+               &        td_mpp%t_proc(id_procid)%i_lej - 1
+            CASE DEFAULT
+               CALL logger_error("GET PROC INDEX: invalid decomposition type.")
+         END SELECT
+
+         mpp_get_proc_index(:)=(/il_i1, il_i2, il_j1, il_j2/)
+
+      ELSE
+         CALL logger_error("GET PROC INDEX: domain decomposition not define.")
+      ENDIF
+
+   END FUNCTION mpp_get_proc_index
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function return processor domain size, depending of domain 
+   !> decompisition type, given sub domain id. 
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[in] td_mpp : mpp strcuture
+   !> @param[in] id_procid : sub domain id
+   !> @return table of index (/ isize, jsize /)
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION mpp_get_proc_size( td_mpp, id_procid )
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TMPP),  INTENT(IN) :: td_mpp
+      INTEGER(i4), INTENT(IN) :: id_procid
+
+      ! function
+      INTEGER(i4), DIMENSION(2) :: mpp_get_proc_size
+
+      ! local variable
+      INTEGER(i4) :: il_isize
+      INTEGER(i4) :: il_jsize
+      TYPE(TMPP)  :: tl_mpp
+      !----------------------------------------------------------------
+
+      IF( ASSOCIATED(td_mpp%t_proc) )THEN
+
+         tl_mpp=td_mpp
+         !IF( TRIM(td_mpp%c_dom) == "unknown" )THEN
+         IF( TRIM(td_mpp%c_dom) == '' )THEN
+            CALL logger_warn("GET PROC SIZE: decomposition type unknown. "//&
+            &              "look for it")
+            CALL mpp_get_dom( tl_mpp )
+         ENDIF
+
+         SELECT CASE(TRIM(tl_mpp%c_dom))
+            CASE('full')
+               
+               il_isize = td_mpp%t_dim(1)%i_len
+               il_jsize = td_mpp%t_dim(2)%i_len
+
+            CASE('overlap')
+
+                il_isize = td_mpp%t_proc(id_procid)%i_lci
+                il_jsize = td_mpp%t_proc(id_procid)%i_lcj
+
+            CASE('nooverlap')
+               il_isize = td_mpp%t_proc(id_procid)%i_lei - &
+               &          td_mpp%t_proc(id_procid)%i_ldi + 1
+               il_jsize = td_mpp%t_proc(id_procid)%i_lej - &
+               &          td_mpp%t_proc(id_procid)%i_ldj + 1
+            CASE DEFAULT
+               CALL logger_error("GET PROC SIZE: invalid decomposition type : "//&
+               &  TRIM(tl_mpp%c_dom) )
+         END SELECT
+
+         mpp_get_proc_size(:)=(/il_isize, il_jsize/)
+
+      ELSE
+         CALL logger_error("GET PROC SIZE: domain decomposition not define.")
+      ENDIF
+
+   END FUNCTION mpp_get_proc_size
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !>  This subroutine determine domain decomposition type.
+   !>  (full, overlap, noverlap)
+   !
+   !> @author J.Paul
+   !> @date Nov, 2013
+   !
+   !> @param[inout] td_mpp : mpp strcuture
+   !> @todo
+   !> - change name, confusing with domain.f90
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE mpp_get_dom( td_mpp )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP),  INTENT(INOUT) :: td_mpp
+
+      ! local variable
+      INTEGER(i4) :: il_isize
+      INTEGER(i4) :: il_jsize
+      !----------------------------------------------------------------
+
+      IF( ASSOCIATED(td_mpp%t_proc) )THEN
+
+         IF( td_mpp%i_niproc == 0 .AND. td_mpp%i_niproc == 0 )THEN
+            CALL logger_info("GET DOM: use indoor indices to get domain "//&
+            &             "decomposition type.")
+            IF((td_mpp%t_proc(1)%t_dim(1)%i_len ==                         &
+            &   td_mpp%t_proc(1)%i_lei - td_mpp%t_proc(1)%i_ldi + 1) .AND. &
+            &  (td_mpp%t_proc(1)%t_dim(2)%i_len ==                         &
+            &   td_mpp%t_proc(1)%i_lej - td_mpp%t_proc(1)%i_ldj + 1) )THEN
+
+               td_mpp%c_dom='nooverlap'
+
+            ELSEIF((td_mpp%t_proc(1)%t_dim(1)%i_len ==                     &
+            &       td_mpp%t_proc(1)%i_lci                     )     .AND. &
+            &      (td_mpp%t_proc(1)%t_dim(2)%i_len ==                     &
+            &       td_mpp%t_proc(1)%i_lcj                     )     )THEN
+
+               td_mpp%c_dom='overlap'
+
+            ELSEIF((td_mpp%t_proc(1)%t_dim(1)%i_len ==                     &
+            &       td_mpp%t_dim(1)%i_len             )              .AND. &
+            &      (td_mpp%t_proc(1)%t_dim(2)%i_len ==                     &
+            &       td_mpp%t_dim(2)%i_len )                          )THEN
+
+               td_mpp%c_dom='full'
+
+            ELSE
+
+               CALL logger_error("GET DOM: should have been an impossible case")
+
+               il_isize=td_mpp%t_proc(1)%t_dim(1)%i_len
+               il_jsize=td_mpp%t_proc(1)%t_dim(2)%i_len
+               CALL logger_debug("GET DOM: proc size "//&
+               &  TRIM(fct_str(il_isize))//" x "//TRIM(fct_str(il_jsize)) )
+
+               il_isize=td_mpp%t_proc(1)%i_lei - td_mpp%t_proc(1)%i_ldi + 1
+               il_jsize=td_mpp%t_proc(1)%i_lej - td_mpp%t_proc(1)%i_ldj + 1
+               CALL logger_debug("GET DOM: no overlap size "//&
+               &  TRIM(fct_str(il_isize))//" x "//TRIM(fct_str(il_jsize)) )
+
+               il_isize=td_mpp%t_proc(1)%i_lci
+               il_jsize=td_mpp%t_proc(1)%i_lcj
+               CALL logger_debug("GET DOM: overlap size "//&
+               &  TRIM(fct_str(il_isize))//" x "//TRIM(fct_str(il_jsize)) )
+
+               il_isize=td_mpp%t_dim(1)%i_len
+               il_jsize=td_mpp%t_dim(2)%i_len
+               CALL logger_debug("GET DOM: full size "//&
+               &  TRIM(fct_str(il_isize))//" x "//TRIM(fct_str(il_jsize)) )
+
+            ENDIF
+
+         ELSE
+
+            CALL logger_info("GET DOM: use number of processors following "//&
+            &             "I and J to get domain decomposition type.")
+            IF( td_mpp%i_niproc*td_mpp%i_njproc==td_mpp%i_nproc )THEN
+               IF( td_mpp%i_nproc == 1 )THEN
+                  td_mpp%c_dom='full'
+               ENDIF
+               td_mpp%c_dom='nooverlap'
+            ELSE
+               td_mpp%c_dom='overlap'
+            ENDIF
+
+         ENDIF
+
+      ELSE
+         CALL logger_error("GET DOM: domain decomposition not define.")
+      ENDIF
+
+   END SUBROUTINE mpp_get_dom
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function check if variable  and mpp structure use same
+   !> dimension.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp : mpp structure
+   !> @param[in] td_var : variable structure
+   !> @return dimension of variable and mpp structure agree (or not)
+   !-------------------------------------------------------------------
+   ! @code
+   LOGICAL FUNCTION mpp__check_var_dim(td_mpp, td_var)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TMPP), INTENT(IN) :: td_mpp
+      TYPE(TVAR), INTENT(IN) :: td_var
+
+      ! local variable
+      INTEGER(i4) :: il_ndim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      mpp__check_var_dim=.TRUE.
+      ! check used dimension 
+      IF( ANY( td_var%t_dim(:)%l_use .AND. &
+      &        td_var%t_dim(:)%i_len /= td_mpp%t_dim(:)%i_len) )THEN
+
+         mpp__check_var_dim=.FALSE.
+
+         CALL logger_error( &
+         &  " CHECK DIM: variable and mpp dimension differ"//&
+         &  " for variable "//TRIM(td_var%c_name)//&
+         &  " and mpp "//TRIM(td_mpp%c_name))
+
+         CALL logger_debug( &
+         &  " mpp dimension: "//TRIM(fct_str(td_mpp%i_ndim))//&
+         &  " variable dimension: "//TRIM(fct_str(td_var%i_ndim)) )
+         il_ndim=MIN(td_var%i_ndim, td_mpp%i_ndim )
+         DO ji = 1, il_ndim
+            CALL logger_debug( &
+            &  " CHECK DIM: for dimension "//&
+            &  TRIM(td_mpp%t_dim(ji)%c_name)//&
+            &  ", mpp length: "//&
+            &  TRIM(fct_str(td_mpp%t_dim(ji)%i_len))//&
+            &  ", variable length: "//&
+            &  TRIM(fct_str(td_var%t_dim(ji)%i_len))//&
+            &  ", variable used "//TRIM(fct_str(td_var%t_dim(ji)%l_use)))
+         ENDDO
+      ENDIF
+
+   END FUNCTION mpp__check_var_dim
+   ! @endcode
+END MODULE mpp
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/multi.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/multi.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/multi.f90	(revision 4245)
@@ -0,0 +1,362 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: multi
+!
+!
+! DESCRIPTION:
+!> This module manage multi file structure
+!
+!> @details
+!> define type TMULTI:<br/>
+!> TYPE(TMULTI) :: tl_multi<br/>
+!>
+!> @author
+!>  J.Paul
+! REVISION HISTORY:
+!> @date 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!----------------------------------------------------------------------
+MODULE multi
+   USE kind                            ! F90 kind parameter
+   USE logger                             ! log file manager
+   USE fct                             ! basic useful function
+   USE dim                             ! dimension manager
+   USE att                             ! attribute manager
+   USE var                             ! variable manager
+   USE file                            ! file manager
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+   PUBLIC :: TMULTI       ! multi file structure
+
+   ! function and subroutine
+   PUBLIC :: ASSIGNMENT(=)     !< copy multi structure
+   PUBLIC :: multi_init        !< initialise mpp structure
+   PUBLIC :: multi_clean       !< clean mpp strcuture
+   PUBLIC :: multi_print       !< print information about mpp structure
+
+   PUBLIC :: multi_add_file    !< add one proc strucutre in mpp structure
+!   PUBLIC :: multi_del_file    !< delete one proc strucutre in mpp structure
+!   PUBLIC :: multi_move_file   !< overwrite proc strucutre in mpp structure
+
+   !> @struct TMULTI
+   TYPE TMULTI
+      ! general 
+      INTEGER(i4)                         :: i_nfile = 0         !< number of files 
+      INTEGER(i4)                         :: i_nvar  = 0         !< total number of variables
+      TYPE(TFILE), DIMENSION(:), POINTER  :: t_file => NULL()    !< files composing multi
+   END TYPE
+
+   INTERFACE ASSIGNMENT(=)
+      MODULE PROCEDURE multi__copy   ! copy multi file structure
+   END INTERFACE   
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function copy multi file structure in another multi file
+   !> structure
+   !> @details 
+   !> file variable value are copied in a temporary table, 
+   !> so input and output file structure value do not point on the same 
+   !> "memory cell", and so on are independant. 
+   !>
+   !> @warning to avoid infinite loop, do not use any function inside 
+   !> this subroutine
+   !>   
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[out] td_multi1  : file structure
+   !> @param[in] td_multi2  : file structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE multi__copy( td_multi1, td_multi2 )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMULTI), INTENT(OUT) :: td_multi1
+      TYPE(TMULTI), INTENT(IN)  :: td_multi2
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      CALL logger_trace("COPY: mulit file ")
+
+      td_multi1%i_nfile = td_multi2%i_nfile
+      td_multi1%i_nvar  = td_multi2%i_nvar
+
+      ! copy variable structure
+      IF( ASSOCIATED(td_multi1%t_file) ) DEALLOCATE(td_multi1%t_file)
+      IF( ASSOCIATED(td_multi2%t_file) .AND. td_multi1%i_nfile > 0 )THEN
+         ALLOCATE( td_multi1%t_file(td_multi1%i_nfile) )
+         DO ji=1,td_multi1%i_nfile
+            td_multi1%t_file(ji) = td_multi2%t_file(ji)
+         ENDDO
+      ENDIF
+
+   END SUBROUTINE multi__copy
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine initialize multi file structure.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_varfile : variable location information (from namelist) 
+   !> @return td_multi : multi structure
+   !-------------------------------------------------------------------
+   ! @code
+   FUNCTION multi_init(cd_varfile)
+      IMPLICIT NONE
+
+      ! Argument
+      CHARACTER(LEN=*), DIMENSION(:), INTENT(IN) :: cd_varfile
+
+      ! function
+      TYPE(TMULTI) :: multi_init
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_name
+      CHARACTER(LEN=lc) :: cl_file
+      CHARACTER(LEN=lc) :: cl_matrix
+
+      INTEGER(i4)       :: il_fileid
+
+      TYPE(TVAR)        :: tl_var
+
+      TYPE(TFILE)       :: tl_file
+
+      TYPE(TMULTI)      :: tl_multi
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ji=1
+      DO WHILE( TRIM(cd_varfile(ji)) /= '' )
+
+         cl_name=fct_lower(fct_split(cd_varfile(ji),1,':'))
+         cl_file=fct_split(cd_varfile(ji),2,':')
+
+         IF( TRIM(cl_name) /= '' )THEN
+            IF( TRIM(cl_file) /= '' )THEN
+               cl_matrix=''
+               IF( fct_is_num(cl_file(1:1)) )THEN
+                  cl_matrix=TRIM(cl_file)
+                  WRITE(cl_file,'(a,i2.2)')'data_',ji
+               ENDIF
+               
+               ! get file id
+               tl_file=file_init(TRIM(cl_file))
+               il_fileid=multi_add_file(tl_multi,tl_file) 
+ 
+               ! define variable
+               tl_var=var_init(TRIM(cl_name))
+               CALL var_read_matrix(tl_var, cl_matrix)
+
+               ! add variable
+               CALL file_add_var(tl_multi%t_file(il_fileid),tl_var)
+
+               ! update total number of variable
+               tl_multi%i_nvar=tl_multi%i_nvar+1
+
+               ! clean structure
+               CALL var_clean(tl_var)
+
+            ELSE
+               CALL logger_error("MULTI INIT: file name matching variable "//&
+               &                 TRIM(cl_name)//" is empty. check namelist.")
+            ENDIF
+         ELSE
+            CALL logger_error("MULTI INIT: variable name "//&
+            &                 "is empty. check namelist.")
+         ENDIF
+
+         ji=ji+1
+      ENDDO
+
+      ! save result
+      multi_init=tl_multi
+
+   END FUNCTION multi_init
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine clean multi file strucutre.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_multi : multi file structure
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE multi_clean(td_multi)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TMULTI), INTENT(INOUT) :: td_multi
+
+      ! local variable
+      TYPE(TMULTI) :: tl_multi ! empty multi file structure
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      CALL logger_info( " CLEAN: reset multi file " )
+
+      IF( ASSOCIATED( td_multi%t_file ) )THEN
+         DO ji=td_multi%i_nfile,1,-1
+            CALL file_clean(td_multi%t_file(ji))
+         ENDDO
+         DEALLOCATE(td_multi%t_file)
+      ENDIF
+
+      ! replace by empty structure
+      td_multi=tl_multi
+
+   END SUBROUTINE multi_clean
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine print some information about mpp strucutre.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_mpp : mpp structure
+   !-------------------------------------------------------------------
+   ! @code
+   SUBROUTINE multi_print(td_multi)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TMULTI), INTENT(IN) :: td_multi
+
+      ! local variable
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      ! print file
+      IF( td_multi%i_nfile /= 0 .AND. ASSOCIATED(td_multi%t_file) )THEN
+         WRITE(*,'(/a,i3)') 'MULTI: total number of file: ',&
+         &  td_multi%i_nfile
+         WRITE(*,'(6x,a,i3)') ' total number of variable: ',&
+         &  td_multi%i_nvar
+         DO ji=1,td_multi%i_nfile
+            WRITE(*,'(3x,3a)') 'FILE ',TRIM(td_multi%t_file(ji)%c_name),&
+            & ' CONTAINS'
+            DO jj=1,td_multi%t_file(ji)%i_nvar
+               IF( ASSOCIATED(td_multi%t_file(ji)%t_var) )THEN
+                  WRITE(*,'(6x,a/)') TRIM(td_multi%t_file(ji)%t_var(jj)%c_name)
+               ENDIF
+            ENDDO
+         ENDDO
+      ENDIF
+
+   END SUBROUTINE multi_print
+   ! @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !>    This subroutine add file to multi file structure.
+   !>
+   !> @detail
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_multi : multi file strcuture
+   !> @param[in]    td_file  : file strcuture
+   !> @return file id in multi structure
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION multi_add_file( td_multi, td_file )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMULTI), INTENT(INOUT) :: td_multi
+      TYPE(TFILE) , INTENT(IN)    :: td_file
+
+      ! function
+      INTEGER(i4) :: multi_add_file
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_fileid
+      TYPE(TFILE), DIMENSION(:), ALLOCATABLE :: tl_file
+      !----------------------------------------------------------------
+
+      il_fileid=0
+      IF( ASSOCIATED(td_multi%t_file) )THEN
+         il_fileid=file_get_id(td_multi%t_file(:),TRIM(td_file%c_name))
+      ENDIF
+
+      IF( il_fileid /= 0 )THEN
+
+            multi_add_file=il_fileid
+
+      ELSE
+         
+         CALL logger_trace("MULTI ADD FILE: add file "//&
+         &               TRIM(td_file%c_name)//" in multi structure")
+
+         IF( td_multi%i_nfile > 0 )THEN
+            ! 
+            ! already other file in multi structure
+            ALLOCATE( tl_file(td_multi%i_nfile), stat=il_status )
+            IF(il_status /= 0 )THEN
+
+               CALL logger_error( " MULTI ADD FILE: not enough space to put file &
+               &               in multi structure")
+
+            ELSE
+               ! save temporary multi structure
+               tl_file(:)=td_multi%t_file(:)
+
+               DEALLOCATE( td_multi%t_file )
+               ALLOCATE( td_multi%t_file(td_multi%i_nfile+1), stat=il_status)
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( " MULTI ADD FILE: not enough space to put "//&
+                  &  "file in multi structure ")
+
+               ENDIF
+
+               ! copy file in multi before
+               td_multi%t_file(1:td_multi%i_nfile) = tl_file(:)
+
+               DEALLOCATE(tl_file)
+            ENDIF
+
+         ELSE
+            ! no processor in mpp structure
+            IF( ASSOCIATED(td_multi%t_file) )THEN
+               DEALLOCATE(td_multi%t_file)
+            ENDIF
+            ALLOCATE( td_multi%t_file(td_multi%i_nfile+1), stat=il_status )
+            IF(il_status /= 0 )THEN
+
+               CALL logger_error( " MULTI ADD FILE: not enough space to put "//&
+               &  "file in multi structure " )
+
+            ENDIF
+         ENDIF
+
+         td_multi%i_nfile=td_multi%i_nfile+1
+
+         ! add new file
+         td_multi%t_file(td_multi%i_nfile)=td_file
+
+         multi_add_file=td_multi%i_nfile
+
+      ENDIF
+   END FUNCTION multi_add_file
+   !> @endcode
+END MODULE multi
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/phycst.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/phycst.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/phycst.f90	(revision 4245)
@@ -0,0 +1,35 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: phycst
+!
+! DESCRIPTION:
+!> @brief This module defines physical constant.
+!
+!> @author
+!> J.paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!----------------------------------------------------------------------
+MODULE phycst
+   USE kind                         ! F90 kind parameter
+
+   IMPLICIT NONE
+
+   PUBLIC :: dg_pi      !< pi
+   PUBLIC :: dg_eps     !< epsilon value
+   PUBLIC :: dg_rearth  !< earth radius (km)
+   PUBLIC :: dg_deg2rad !< 
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   REAL(dp), PARAMETER :: dg_pi = 3.14159274101257_dp
+   REAL(dp), PARAMETER :: dg_eps = EPSILON(1._dp)
+   REAL(dp), PARAMETER :: dg_rearth = 6871._dp
+   REAL(dp), PARAMETER :: dg_deg2rad = dg_pi/180.0
+
+END MODULE phycst
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/variable.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/variable.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/variable.f90	(revision 4245)
@@ -0,0 +1,6902 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: var
+!
+! DESCRIPTION:
+!> @brief 
+!> This module manage variable structure.
+!>
+!> @details
+!>    define type TVAR:<br/>
+!>    TYPE(TVAR) :: tl_var<br/>
+!>
+!>    the variable value will always be 4D table of real(8).<br/>
+!>    However the variable value could be initialised with
+!>    table of real(4), real(8), integer(4) or integer(8)
+!>        
+!>    to initialise a variable structure:<br/>
+!>    tl_var=var_init( cd_name, [value,] [id_start, [id_count,]] [td_dim,] [td_att] )
+!>       - cd_name is the variable name
+!>       - value is a 4D table ordered as ('x','y','z','t') (optional)
+!>          (real(4), real(8), integer(4) or integer(8)
+!>       - id_start is a integer(4) 1D table of index from which the data 
+!>          values will be read (optional)
+!>       - id_count is a integer(4) 1D table of the number of indices selected
+!>          along each dimension (optional)
+!>       - td_dim is the table of dimension structure (optional)
+!>       - td_att is the table of attribute structure (optional)
+!>
+!>    to print information about variable structure:<br/>
+!>    CALL var_print(tl_var)
+!>
+!>    to get variable name:<br/>
+!>    - tl_var\%c_name
+!>    
+!>    to get variable value:<br/>
+!>    - tl_var\%d_value(:,:,:,:)
+!>    
+!>    to get the type number (based on NETCDF type constants) of the variable 
+!>    (as define initially or read in file):<br/>
+!>    - tl_var\%i_type
+!>
+!>    to get variable id (affected when variable will be added to a file):<br/>
+!>    - tl_var\%i_id
+!>
+!>    Variable dimension<br/>
+!>    to get the number of dimension used in the variable:<br/>
+!>    - tl_var\%i_ndim
+!>
+!>    to get the table of dimension structure (4 elts) associated to the
+!>    variable:<br/>
+!>    - tl_var\%t_dim(:)
+!>
+!>    Variable attributes<br/>
+!>    attribue value are always character or real(8) 1D table.<br/>
+!>    to get the number of attributes of the variable:<br/>
+!>    - tl_var\%i_natt
+!>
+!>    to get the table of attribute structure associated to the
+!>    variable:<br/>
+!>    - tl_var\%t_att(:)
+!>
+!>    Some attribute are highlight, to be easily used.
+!>    to get variable standard name:<br/>
+!>    - tl_var\%c_stdname
+!>
+!>    to get variable units:<br/>
+!>    - tl_var\%c_units
+!>
+!>    to get variable scale factor:<br/>
+!>    - tl_var\%d_scf
+!>
+!>    to get variable add offset:<br/>
+!>    - tl_var\%d_ofs
+!>
+!>    to get variable FillValue:<br/>
+!>    - tl_var\%d_fill
+!>
+!>    to add value to a variable structure:<br/>
+!>    CALL var_add_value(tl_var, value, [id_start, [id_count]]) 
+!>       - value : 4D table of value (real(4), real(8), integer(4), integer(8))
+!>       - id_start : 1D table of the index in the variable from which the data
+!>       values will be read (integer(4), optional)
+!>       - id_count : 1D table of the number of indices selected along each 
+!>       dimension (integer(4), optional)
+!>
+!>    to add one attribute to a variable structure:<br/>
+!>    CALL var_add_att(tl_var, td_att)
+!>       - td_att is an attribute structure 
+!>
+!>    to add one dimension to a variable structure:<br/>
+!>    CALL var_add_dim(tl_var, td_dim)
+!>       - td_dim is a dimension structure
+!> 
+!>    to delete value of a variable structure:<br/>
+!>    CALL var_del_value(tl_var)
+!>
+!>    to delete one attribute of a variable structure:<br/>
+!>    CALL var_del_att(tl_var, td_att)
+!>       - td_att is an attribute structure 
+!>
+!>    to delete one dimension of a variable structure:<br/>
+!>    CALL var_del_dim(tl_var, td_dim)
+!>       - td_dim is a dimension structure
+!>
+!>    to overwrite one attribute structure in variable structure:<br/>
+!>    CALL var_move_att(tl_var, td_att)
+!>       - td_att is an attribute structure
+!>
+!>    to overwrite one dimension structure in variable structure:<br/>
+!>    CALL var_move_dim(tl_var, td_dim)
+!>       - td_dim is a dimension structure
+!>
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!> @todo
+!> - manage ew_wrap in structure
+!> - manage c_point in structure
+!> - think about create init for 0D 1D 2D 3D input table
+!> - creer module cfg qui lit et def tg_varcfg (pb var_get_extra appele ds
+!> var_init)
+!----------------------------------------------------------------------
+MODULE var
+   USE netcdf                          ! nf90 library
+   USE global                          ! global variable
+   USE kind                            ! F90 kind parameter
+   USE logger                             ! log file manager
+   USE fct                             ! basic useful function
+   USE att                             ! attribute manager
+   USE dim                             ! dimension manager
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+   PUBLIC :: TVAR        !< variable structure
+
+   PUBLIC :: tg_varextra !< table of variable structure with extra information.
+
+   ! function and subroutine
+   PUBLIC :: ASSIGNMENT(=) !< copy variable structure
+   PUBLIC :: var_init      !< initialize variable structure
+   PUBLIC :: var_print     !< print variable information
+   PUBLIC :: var_clean     !< clean variable structure
+   PUBLIC :: var_get_id    !< return the variable id, from a table of variable structure 
+   PUBLIC :: var_add_value !< add table of value in variable structure
+   PUBLIC :: var_add_att   !< add attribute structure in variable structure
+   PUBLIC :: var_add_dim   !< add dimension structure in variable structure
+   PUBLIC :: var_del_value !< delete table of value of variable structure
+   PUBLIC :: var_del_att   !< delete one attribute structure of variable structure
+   PUBLIC :: var_del_dim   !< delete one dimension structure of variable structure
+   PUBLIC :: var_move_att  !< overwrite one attribute structure in variable structure
+   PUBLIC :: var_move_dim  !< overwrite one dimension structure in variable structure 
+   PUBLIC :: var_get_mask  !< return the mask of variable
+   PUBLIC :: var_chg_FillValue  !< change FillValue to standard NETCDF Fill Value
+   PUBLIC :: var_def_extra  !< read variable configuration file, and save extra information.
+   PUBLIC :: var_chg_extra  !< read variable namelist information, and modify extra information.
+   PUBLIC :: var_read_matrix !<  
+!   PUBLIC :: var_match_file !< read variable namelist information, and modify extra information.
+   PUBLIC :: var_max_dim    !< get table of maximum dimension use
+   PUBLIC :: var_concat       !< concatenate two variables
+   PUBLIC :: var_limit_value  !< forced min and max value
+   PUBLIC :: var_check_dim    !< check variable dimension expected
+
+!   PUBLIC :: var_ended     !< deallocate global variable
+
+   PRIVATE :: var__add_value_dp  !< add table of value real(8) in variable structure
+   PRIVATE :: var__add_value_rp  !< add table of value real(4) in variable structure
+   PRIVATE :: var__add_value_i1  !< add table of value integer(1) in variable structure
+   PRIVATE :: var__add_value_i2  !< add table of value integer(2) in variable structure
+   PRIVATE :: var__add_value_i4  !< add table of value integer(4) in variable structure
+   PRIVATE :: var__add_value_i8  !< add table of value integer(8) in variable structure
+   PRIVATE :: var__init          !< initialse variable structure without table of value
+   PRIVATE :: var__init_dp       !< initialse variable structure with real(8) 4D table of value
+   PRIVATE :: var__init_1D_dp    !< initialse variable structure with real(8) 1D table of value
+   PRIVATE :: var__init_2D_dp    !< initialse variable structure with real(8) 2D table of value
+   PRIVATE :: var__init_3D_dp    !< initialse variable structure with real(8) 3D table of value
+   PRIVATE :: var__init_sp       !< initialse variable structure with real(4) 4D table of value
+   PRIVATE :: var__init_1D_sp    !< initialse variable structure with real(4) 1D table of value
+   PRIVATE :: var__init_2D_sp    !< initialse variable structure with real(4) 2D table of value
+   PRIVATE :: var__init_3D_sp    !< initialse variable structure with real(4) 3D table of value
+   PRIVATE :: var__init_i1       !< initialse variable structure with integer(1) 4D table of value
+   PRIVATE :: var__init_1D_i1    !< initialse variable structure with integer(1) 1D table of value
+   PRIVATE :: var__init_2D_i1    !< initialse variable structure with integer(1) 2D table of value
+   PRIVATE :: var__init_3D_i1    !< initialse variable structure with integer(1) 3D table of value
+   PRIVATE :: var__init_i2       !< initialse variable structure with integer(2) 4D table of value
+   PRIVATE :: var__init_1D_i2    !< initialse variable structure with integer(2) 1D table of value
+   PRIVATE :: var__init_2D_i2    !< initialse variable structure with integer(2) 2D table of value
+   PRIVATE :: var__init_3D_i2    !< initialse variable structure with integer(2) 3D table of value
+   PRIVATE :: var__init_i4       !< initialse variable structure with integer(4) 4D table of value
+   PRIVATE :: var__init_1D_i4    !< initialse variable structure with integer(4) 1D table of value
+   PRIVATE :: var__init_2D_i4    !< initialse variable structure with integer(4) 2D table of value
+   PRIVATE :: var__init_3D_i4    !< initialse variable structure with integer(4) 3D table of value
+   PRIVATE :: var__init_i8       !< initialse variable structure with integer(8) 4D table of value
+   PRIVATE :: var__init_1D_i8    !< initialse variable structure with integer(8) 1D table of value
+   PRIVATE :: var__init_2D_i8    !< initialse variable structure with integer(8) 2D table of value
+   PRIVATE :: var__init_3D_i8    !< initialse variable structure with integer(8) 3D table of value
+   PRIVATE :: var__add_dim_unit  !< add one dimension structure in variable structure
+   PRIVATE :: var__add_dim_tab   !< add a table of dimension structure in variable structure
+   PRIVATE :: var__add_att_unit  !< add one attribute structure in variable structure
+   PRIVATE :: var__add_att_tab   !< add a table of attribute structure in variable structure
+   PRIVATE :: var__add_dim       !< add a dimension structure in a variable structure.
+   PRIVATE :: var__add_value     !< add a 4D table of double value in a variable structure.
+   PRIVATE :: var__copy_unit     !< copy variable structure
+   PRIVATE :: var__copy_tab      !< copy variable structure
+   PRIVATE :: var__get_extra     !< add extra information in variable structure
+   PRIVATE :: var__concat_i      !< concatenate varibales in i-direction
+   PRIVATE :: var__concat_j      !< concatenate varibales in j-direction
+   PRIVATE :: var__concat_k      !< concatenate varibales in k-direction
+   PRIVATE :: var__concat_l      !< concatenate varibales in l-direction
+   PRIVATE :: var__get_max       !< get maximum value from namelist 
+   PRIVATE :: var__get_min       !< get minimum value from namelist
+   PRIVATE :: var__get_interp    !< get interpolation method from namelist
+   PRIVATE :: var__get_extrap    !< get extrapolation method from namelist
+   PRIVATE :: var__get_filter    !< get filter method from namelist
+
+   !> @struct TVAR
+   TYPE TVAR
+
+      CHARACTER(LEN=lc) :: c_name  = ''  !< variable name
+      CHARACTER(LEN=lc) :: c_point = '' !< type of grid point
+      INTEGER(i4)       :: i_id = 0      !< variable id
+      INTEGER(i4)       :: i_ew = 0      !< east-west overlap
+
+      REAL(dp)   , DIMENSION(:,:,:,:), POINTER :: d_value => NULL() !< variable value
+
+      !!! netcdf
+      INTEGER(i4)       :: i_type = 0           !< variable type
+      INTEGER(i4)       :: i_natt = 0           !< number of attributes
+      INTEGER(i4)       :: i_ndim = 0           !< number of dimensions
+      TYPE(TATT), DIMENSION(:), POINTER :: t_att => NULL() !< variable attributes
+      TYPE(TDIM), DIMENSION(ip_maxdim)  :: t_dim           !< variable dimension
+      
+      ! highlight some attribute
+      CHARACTER(LEN=lc) :: c_stdname  = ''!< variable standard name
+      CHARACTER(LEN=lc) :: c_longname = ''!< variable long name
+      CHARACTER(LEN=lc) :: c_units    = ''!< variable units
+      CHARACTER(LEN=lc) :: c_axis     = ''!< variable axis
+      REAL(dp)          :: d_scf = 1.           !< scale factor
+      REAL(dp)          :: d_ofs = 0.           !< offset
+      REAL(dp)          :: d_fill= 0.           !< fill value     ! NF90_FILL_DOUBLE 
+      REAL(dp)          :: d_min = dg_fill      !< minimum value 
+      REAL(dp)          :: d_max = dg_fill      !< maximum value 
+      
+      !!! netcdf4
+      LOGICAL           :: l_contiguous = .FALSE. !< use contiguous storage or not
+      LOGICAL           :: l_shuffle    = .FALSE. !< shuffle filter is turned on or not
+      LOGICAL           :: l_fletcher32 = .FALSE. !< fletcher32 filter is turned on or not
+      INTEGER(i4)       :: i_deflvl = 0           !< deflate level from 0 to 9, 0 indicates no deflation is in use
+      INTEGER(i4), DIMENSION(ip_maxdim) :: i_chunksz = (/1,1,1,1/) !< chunk size
+
+      !!! dimg
+      INTEGER(i4) :: i_rec = 0 !< record number
+
+      CHARACTER(LEN=lc), DIMENSION(2) :: c_interp = '' !< interpolation method
+      CHARACTER(LEN=lc), DIMENSION(1) :: c_extrap = '' !< extrapolation method
+      CHARACTER(LEN=lc), DIMENSION(5) :: c_filter = '' !< filter method
+
+   END TYPE TVAR
+
+   TYPE(TVAR), DIMENSION(:), ALLOCATABLE :: tg_varextra !< table of variable structure with extra information.
+                                                        !< fill when running var_def_extra() 
+
+   INTERFACE var_add_value
+      MODULE PROCEDURE var__add_value_dp  ! add table of value real(8) in variable structure
+      MODULE PROCEDURE var__add_value_rp  ! add table of value real(4) in variable structure
+      MODULE PROCEDURE var__add_value_i1  ! add table of value integer(1) in variable structure
+      MODULE PROCEDURE var__add_value_i2  ! add table of value integer(2) in variable structure
+      MODULE PROCEDURE var__add_value_i4  ! add table of value integer(4) in variable structure
+      MODULE PROCEDURE var__add_value_i8  ! add table of value integer(8) in variable structure
+   END INTERFACE var_add_value
+
+   INTERFACE var_init
+      MODULE PROCEDURE var__init       ! initialse variable structure without table of value
+      MODULE PROCEDURE var__init_dp    ! initialse variable structure with real(8) 4D table of value
+      MODULE PROCEDURE var__init_1D_dp ! initialse variable structure with real(8) 1D table of value
+      MODULE PROCEDURE var__init_2D_dp ! initialse variable structure with real(8) 2D table of value
+      MODULE PROCEDURE var__init_3D_dp ! initialse variable structure with real(8) 3D table of value
+      MODULE PROCEDURE var__init_sp    ! initialse variable structure with real(4) 4D table of value
+      MODULE PROCEDURE var__init_1D_sp ! initialse variable structure with real(4) 1D table of value
+      MODULE PROCEDURE var__init_2D_sp ! initialse variable structure with real(4) 2D table of value
+      MODULE PROCEDURE var__init_3D_sp ! initialse variable structure with real(4) 3D table of value
+      MODULE PROCEDURE var__init_i1    ! initialse variable structure with integer(1) 4D table of value
+      MODULE PROCEDURE var__init_1D_i1 ! initialse variable structure with integer(1) 1D table of value
+      MODULE PROCEDURE var__init_2D_i1 ! initialse variable structure with integer(1) 2D table of value
+      MODULE PROCEDURE var__init_3D_i1 ! initialse variable structure with integer(1) 3D table of value
+      MODULE PROCEDURE var__init_i2    ! initialse variable structure with integer(2) 4D table of value
+      MODULE PROCEDURE var__init_1D_i2 ! initialse variable structure with integer(2) 1D table of value
+      MODULE PROCEDURE var__init_2D_i2 ! initialse variable structure with integer(2) 2D table of value
+      MODULE PROCEDURE var__init_3D_i2 ! initialse variable structure with integer(2) 3D table of value
+      MODULE PROCEDURE var__init_i4    ! initialse variable structure with integer(4) 4D table of value
+      MODULE PROCEDURE var__init_1D_i4 ! initialse variable structure with integer(4) 1D table of value
+      MODULE PROCEDURE var__init_2D_i4 ! initialse variable structure with integer(4) 2D table of value
+      MODULE PROCEDURE var__init_3D_i4 ! initialse variable structure with integer(4) 3D table of value
+      MODULE PROCEDURE var__init_i8    ! initialse variable structure with integer(8) 4D table of value
+      MODULE PROCEDURE var__init_1D_i8 ! initialse variable structure with integer(8) 1D table of value
+      MODULE PROCEDURE var__init_2D_i8 ! initialse variable structure with integer(8) 2D table of value
+      MODULE PROCEDURE var__init_3D_i8 ! initialse variable structure with integer(8) 3D table of value
+   END INTERFACE var_init
+
+   INTERFACE var_add_dim
+      MODULE PROCEDURE var__add_dim_unit ! add one dimension structure in variable structure
+      MODULE PROCEDURE var__add_dim_tab  ! add a table of dimension structure in variable structure
+   END INTERFACE var_add_dim
+
+   INTERFACE var_add_att
+      MODULE PROCEDURE var__add_att_unit ! add one attribute structure in variable structure
+      MODULE PROCEDURE var__add_att_tab  ! add a table of attribute structure in variable structure
+   END INTERFACE var_add_att
+
+   INTERFACE ASSIGNMENT(=)
+      MODULE PROCEDURE var__copy_unit   ! copy variable structure
+      MODULE PROCEDURE var__copy_tab    ! copy variable structure
+   END INTERFACE
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine copy variable structure in another variable
+   !> structure
+   !> @details 
+   !> variable value are copied in a temporary table, so input and output
+   !> variable structure value do not point on the same "memory cell", and so
+   !> are independant. 
+   !>
+   !> @warning to avoid infinite loop, do not use any function inside 
+   !> this subroutine
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[out] td_var1  : variable structure
+   !> @param[in] td_var2  : variable structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__copy_unit( td_var1, td_var2 )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR), INTENT(OUT) :: td_var1
+      TYPE(TVAR), INTENT(IN)  :: td_var2
+
+      ! local variable
+      TYPE(TATT)                                :: tl_att
+      REAL(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! copy variable name, id, ..
+      td_var1%c_name     = TRIM(td_var2%c_name)
+      td_var1%c_point    = TRIM(td_var2%c_point)
+      td_var1%i_id       = td_var2%i_id
+      td_var1%i_ew       = td_var2%i_ew
+
+      td_var1%d_min      = td_var2%d_min
+      td_var1%d_max      = td_var2%d_max
+
+      td_var1%i_type     = td_var2%i_type
+      td_var1%i_natt     = td_var2%i_natt
+      td_var1%i_ndim     = td_var2%i_ndim
+      td_var1%i_ndim     = td_var2%i_ndim
+
+      ! copy dimension
+      td_var1%t_dim(:)   = td_var2%t_dim(:)
+
+      ! copy attribute
+      IF( ASSOCIATED(td_var1%t_att) ) DEALLOCATE(td_var1%t_att)
+      IF( ASSOCIATED(td_var2%t_att) .AND. td_var1%i_natt > 0 )THEN
+         ALLOCATE( td_var1%t_att(td_var1%i_natt) )
+         DO ji=1,td_var1%i_natt
+            tl_att=td_var2%t_att(ji)
+            td_var1%t_att(ji)=tl_att
+         ENDDO
+      ENDIF
+
+      ! copy highlight attribute
+      td_var1%c_stdname  = TRIM(td_var2%c_stdname)
+      td_var1%c_longname = TRIM(td_var2%c_longname)
+      td_var1%c_units    = TRIM(td_var2%c_units)
+      td_var1%c_axis     = TRIM(td_var2%c_axis)
+      td_var1%d_scf      = td_var2%d_scf
+      td_var1%d_ofs      = td_var2%d_ofs
+      td_var1%d_fill     = td_var2%d_fill
+      
+      ! copy netcdf4 variable
+      td_var1%l_contiguous  = td_var2%l_contiguous
+      td_var1%l_shuffle     = td_var2%l_shuffle
+      td_var1%l_fletcher32  = td_var2%l_fletcher32 
+      td_var1%i_deflvl      = td_var2%i_deflvl
+      td_var1%i_chunksz(:)  = td_var2%i_chunksz(:)
+      
+      ! copy dimg variable
+      td_var1%i_rec = td_var2%i_rec
+
+      ! copy pointer in an independant variable
+      IF( ASSOCIATED(td_var1%d_value) ) DEALLOCATE(td_var1%d_value)
+      IF( ASSOCIATED(td_var2%d_value) )THEN
+         ALLOCATE( dl_value( td_var2%t_dim(1)%i_len, &
+         &                   td_var2%t_dim(2)%i_len, &
+         &                   td_var2%t_dim(3)%i_len, &
+         &                   td_var2%t_dim(4)%i_len ) )
+         dl_value(:,:,:,:)=td_var2%d_value(:,:,:,:)
+
+         ALLOCATE( td_var1%d_value( td_var1%t_dim(1)%i_len, &
+         &                          td_var1%t_dim(2)%i_len, &
+         &                          td_var1%t_dim(3)%i_len, &
+         &                          td_var1%t_dim(4)%i_len ) )
+         td_var1%d_value(:,:,:,:)=dl_value(:,:,:,:)
+
+         DEALLOCATE( dl_value )
+      ENDIF
+
+      td_var1%c_interp(:)=td_var2%c_interp(:)
+      td_var1%c_extrap(:)=td_var2%c_extrap(:)
+      td_var1%c_filter(:)=td_var2%c_filter(:)
+
+   END SUBROUTINE var__copy_unit
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine copy variable structure in another variable
+   !> structure
+   !> @details 
+   !> variable value are copied in a temporary table, so input and output
+   !> variable structure value do not point on the same "memory cell", and so
+   !> are independant. 
+   !>
+   !> @warning to avoid infinite loop, do not use any function inside 
+   !> this subroutine
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[out] td_var1  : variable structure
+   !> @param[in] td_var2  : variable structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__copy_tab( td_var1, td_var2 )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR), DIMENSION(:), INTENT(IN   )  :: td_var2
+      TYPE(TVAR), DIMENSION(:), INTENT(  OUT) :: td_var1
+
+      ! local variable
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_var2(:))/=SIZE(td_var1(:)) )THEN
+         CALL logger_error("VAR COPY: variable structure dimension differ")
+      ELSE
+         DO ji=1,SIZE(td_var2(:))
+            td_var1(ji)=td_var2(ji)
+         ENDDO
+      ENDIF
+
+   END SUBROUTINE var__copy_tab
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine clean variable structure
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var : variable strucutre
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var_clean( td_var )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+
+      ! local variable
+      TYPE(TVAR) :: tl_var ! empty variable strucutre
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      CALL logger_info( &
+      &  " CLEAN: reset variable "//TRIM(td_var%c_name) )
+
+      ! del attribute
+      IF( ASSOCIATED(td_var%t_att) )THEN
+         ! clean each attribute
+         DO ji=td_var%i_natt,1,-1
+            CALL att_clean(td_var%t_att(ji) )
+         ENDDO
+         DEALLOCATE( td_var%t_att )
+      ENDIF
+
+      ! del dimension
+      IF( td_var%i_ndim /= 0 )THEN
+         ! clean each dimension
+         DO ji=td_var%i_ndim,1,-1
+            CALL dim_clean(td_var%t_dim(ji))
+         ENDDO
+      ENDIF
+
+      ! del value
+      IF( ASSOCIATED(td_var%d_value) )THEN
+         CALL var_del_value(td_var)
+      ENDIF
+
+      ! replace by empty structure
+      td_var=tl_var
+
+   END SUBROUTINE var_clean
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !
+   !> @details 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] dd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !> @param[in] cd_interp  : interpolation method
+   !> @param[in] cd_extrap  : extrapolation method
+   !> @param[in] cd_filter  : filter method
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init( cd_name, id_type, td_dim, &
+   &                              td_att, dd_fill, cd_units, cd_axis, &
+   &                              cd_stdname, cd_longname,  &
+   &                              cd_point, id_id, id_ew,   &
+   &                              dd_scf, dd_ofs,  id_rec,  &
+   &                              dd_min, dd_max,           &
+   &                              ld_contiguous, ld_shuffle,&
+   &                              ld_fletcher32, id_deflvl, id_chunksz, &
+   &                              cd_interp, cd_extrap, cd_filter )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_att
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_axis 
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+      CHARACTER(LEN=*), DIMENSION(2)        , INTENT(IN), OPTIONAL :: cd_interp
+      CHARACTER(LEN=*), DIMENSION(1)        , INTENT(IN), OPTIONAL :: cd_extrap
+      CHARACTER(LEN=*), DIMENSION(5)        , INTENT(IN), OPTIONAL :: cd_filter
+
+
+      ! local variable
+      INTEGER(i4) :: il_attid
+
+      TYPE(TATT)  :: tl_att
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init)
+
+      var__init%c_name=TRIM(ADJUSTL(cd_name))
+
+      ! standard name
+      IF( PRESENT(cd_stdname) )THEN
+         var__init%c_stdname=TRIM(ADJUSTL(cd_stdname))
+      ENDIF
+
+      ! long name
+      IF( PRESENT(cd_longname) )THEN
+         var__init%c_longname=TRIM(ADJUSTL(cd_longname))
+      ENDIF
+
+      ! point
+      IF( PRESENT(cd_point) )THEN
+         var__init%c_point=TRIM(ADJUSTL(cd_point))
+      ENDIF
+
+      ! variable id
+      IF( PRESENT(id_id) )THEN
+         var__init%i_id=id_id
+      ENDIF
+
+      ! east west wrap
+      IF( PRESENT(id_ew) )THEN
+         var__init%i_ew=id_ew
+      ENDIF
+
+      ! type
+      IF( PRESENT(id_type) )THEN
+         var__init%i_type=id_type
+      ELSE
+         var__init%i_type=NF90_DOUBLE
+      ENDIF
+
+      ! add attribute
+      IF( PRESENT(td_att) )THEN
+         CALL var_add_att(var__init, td_att(:))
+      ENDIF
+
+      ! add _FillValue
+      IF( PRESENT(dd_fill) )THEN
+         tl_att=att_init('_FillValue',dd_fill)
+         CALL var_move_att(var__init, tl_att)
+      ELSE
+         il_attid=0
+         IF( ASSOCIATED(var__init%t_att) )THEN
+            il_attid=att_get_id(var__init%t_att(:),'_FillValue')
+         ENDIF
+         IF( il_attid == 0 )THEN
+            SELECT CASE( var__init%i_type )
+
+               CASE(NF90_BYTE)
+                  tl_att=att_init('_FillValue',NF90_FILL_BYTE)
+               CASE(NF90_SHORT)
+                  tl_att=att_init('_FillValue',NF90_FILL_SHORT)
+               CASE(NF90_INT)
+                  tl_att=att_init('_FillValue',NF90_FILL_INT)
+               CASE(NF90_FLOAT)
+                  tl_att=att_init('_FillValue',NF90_FILL_FLOAT)
+               CASE DEFAULT ! NF90_DOUBLE
+                  tl_att=att_init('_FillValue',NF90_FILL_DOUBLE)
+
+            END SELECT         
+            CALL var_add_att(var__init, tl_att)
+         ENDIF
+      ENDIF
+
+      ! scale factor
+      IF( PRESENT(dd_scf) )THEN
+         tl_att=att_init('scale_factor',dd_scf)
+         CALL var_move_att(var__init, tl_att)
+      ENDIF
+
+      ! add offset
+      IF( PRESENT(dd_ofs) )THEN
+         tl_att=att_init('add_offset',dd_ofs)
+         CALL var_move_att(var__init, tl_att)
+      ENDIF
+
+      IF( PRESENT(cd_units) )THEN
+         tl_att=att_init('units',cd_units)
+         CALL var_move_att(var__init, tl_att)
+      ENDIF
+
+      IF( PRESENT(cd_axis) )THEN
+         var__init%c_axis=TRIM(cd_axis)
+      ENDIF
+
+      ! add dimension
+      IF( PRESENT(td_dim) )THEN
+         CALL var_add_dim(var__init, td_dim(:))
+      ENDIF
+
+      IF( PRESENT(id_rec) )THEN
+         var__init%i_rec=id_rec
+      ENDIF
+
+      ! add minimum value
+      IF( PRESENT(dd_min) )THEN
+         var__init%d_min=dd_min
+      ENDIF
+
+      ! add maximum value
+      IF( PRESENT(dd_max) )THEN
+         var__init%d_max=dd_max
+      ENDIF
+
+      IF( PRESENT(ld_contiguous) )THEN
+         var__init%l_contiguous=ld_contiguous
+      ENDIF
+
+      IF( PRESENT(ld_shuffle) )THEN
+         var__init%l_shuffle=ld_shuffle
+      ENDIF
+
+      IF( PRESENT(ld_fletcher32) )THEN
+         var__init%l_fletcher32=ld_fletcher32
+      ENDIF
+
+       IF( PRESENT(id_deflvl) )THEN
+         var__init%i_deflvl=id_deflvl
+      ENDIF     
+      
+      IF( PRESENT(id_chunksz) )THEN
+         var__init%i_chunksz(:)=id_chunksz(:)
+      ENDIF
+
+      IF( PRESENT(cd_interp) )THEN
+         var__init%c_interp(:)=cd_interp(:)
+      ENDIF
+
+      IF( PRESENT(cd_extrap) )THEN
+         var__init%c_extrap(:)=cd_extrap(:)
+      ENDIF
+
+      IF( PRESENT(cd_filter) )THEN
+         var__init%c_filter(:)=cd_filter(:)
+      ENDIF
+
+      ! add extra information
+      CALL var__get_extra(var__init)
+
+      ! delete some attribute
+      il_attid=att_get_id(var__init%t_att(:),'interpolation')
+      IF( il_attid /= 0 )THEN
+         tl_att=var__init%t_att(il_attid)
+         CALL var_del_att(var__init, tl_att)
+      ENDIF
+      il_attid=att_get_id(var__init%t_att(:),'extrapolation')
+      IF( il_attid /= 0 )THEN
+         tl_att=var__init%t_att(il_attid)
+         CALL var_del_att(var__init, tl_att)
+      ENDIF
+      il_attid=att_get_id(var__init%t_att(:),'filter')
+      IF( il_attid /= 0 )THEN
+         tl_att=var__init%t_att(il_attid)
+         CALL var_del_att(var__init, tl_att)
+      ENDIF
+      il_attid=att_get_id(var__init%t_att(:),'src_file')
+      IF( il_attid /= 0 )THEN
+         tl_att=var__init%t_att(il_attid)
+         CALL var_del_att(var__init, tl_att)
+      ENDIF
+      ! those attribute are deleted cause seems not to be informed correctly
+      il_attid=att_get_id(var__init%t_att(:),'valid_min')
+      IF( il_attid /= 0 )THEN
+         tl_att=var__init%t_att(il_attid)
+         CALL var_del_att(var__init, tl_att)
+      ENDIF
+      il_attid=att_get_id(var__init%t_att(:),'valid_max')
+      IF( il_attid /= 0 )THEN
+         tl_att=var__init%t_att(il_attid)
+         CALL var_del_att(var__init, tl_att)
+      ENDIF
+      il_attid=att_get_id(var__init%t_att(:),'missing_value')
+      IF( il_attid /= 0 )THEN
+         tl_att=var__init%t_att(il_attid)
+         CALL var_del_att(var__init, tl_att)
+      ENDIF
+
+   END FUNCTION var__init
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - real(8) 1D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> Dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('z') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] dd_value : 1D table of real(8) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] dd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_1D_dp( cd_name, dd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, dd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      REAL(dp)        , DIMENSION(:)        , INTENT(IN) :: dd_value
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      ,                       INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:)        , INTENT(IN), OPTIONAL :: td_att
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                    :: il_type
+      INTEGER(i4), DIMENSION(ip_maxdim)              :: il_start
+      INTEGER(i4), DIMENSION(ip_maxdim)              :: il_count
+
+      REAL(dp)   , DIMENSION(:,:,:,:)  , ALLOCATABLE :: dl_value
+
+      TYPE(TDIM) , DIMENSION(ip_maxdim)              :: tl_dim
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_1D_dp)
+
+      ! ugly call to avoid warning
+      il_type=NF90_DOUBLE
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      tl_dim(1)=dim_init( 'Z', id_len=SIZE(dd_value(:)) )
+      IF( PRESENT(td_dim) )THEN
+         tl_dim(1)=td_dim
+      ENDIF
+
+      il_start(:)=1
+      IF( PRESENT(id_start) )THEN
+         il_start(1)=id_start
+      ENDIF
+
+      il_count(:)=tl_dim(:)%i_len
+      IF( PRESENT(id_count) )THEN
+         il_count(1)=id_count
+      ENDIF
+
+      ! reorder dimension
+      CALL dim_reorder(tl_dim(:))
+      ! reorder table
+      il_start(:)=dim_reorder_2xyzt(tl_dim(:),il_start(:))
+      il_count(:)=dim_reorder_2xyzt(tl_dim(:),il_count(:))
+
+      var__init_1D_dp=var__init( cd_name, id_type=il_type,           &
+      &                          td_dim=tl_dim(:), td_att=td_att,    &
+      &                          dd_fill=dd_fill, cd_units=cd_units, &
+      &                          cd_stdname=cd_stdname,              &
+      &                          cd_longname=cd_longname,            &
+      &                          cd_point=cd_point, id_id=id_id,     &
+      &                          id_ew=id_ew, dd_scf=dd_scf,         &
+      &                          dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                          dd_min=dd_min, dd_max=dd_max,       &
+      &                          ld_contiguous=ld_contiguous,        &
+      &                          ld_shuffle=ld_shuffle,              &
+      &                          ld_fletcher32=ld_fletcher32,        &
+      &                          id_deflvl=id_deflvl,                &
+      &                          id_chunksz=id_chunksz(:))
+   
+      ! add value
+      ALLOCATE( dl_value(tl_dim(1)%i_len, &
+      &                  tl_dim(2)%i_len, &
+      &                  tl_dim(3)%i_len, &
+      &                  tl_dim(4)%i_len) )
+
+      IF( tl_dim(1)%l_use )THEN
+         dl_value(:,1,1,1) = dd_value(:)
+      ELSEIF( tl_dim(2)%l_use )THEN
+         dl_value(1,:,1,1) = dd_value(:)
+      ELSEIF( tl_dim(3)%l_use )THEN
+         dl_value(1,1,:,1) = dd_value(:)
+      ELSEIF( tl_dim(4)%l_use )THEN
+         dl_value(1,1,1,:) = dd_value(:)
+      ELSE
+         CALL logger_fatal("VAR INIT: can not add value from variable "//&
+         &  TRIM(cd_name)//". invalid dimension to be used")
+      ENDIF
+
+      CALL var_add_value( var__init_1D_dp, dl_value(:,:,:,:), &
+      &                   il_start(:), il_count(:) )
+
+      DEALLOCATE( dl_value )
+
+   END FUNCTION var__init_1D_dp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - real(8) 2D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> table of 2 dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] dd_value : 1D table of real(8) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] dd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_2D_dp( cd_name, dd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, dd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      REAL(dp)        , DIMENSION(:,:)      , INTENT(IN) :: dd_value
+      INTEGER(i4)     , DIMENSION(:)        , INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:)        , INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:)        , INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:)        , INTENT(IN), OPTIONAL :: td_att
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                    :: il_type
+      INTEGER(i4), DIMENSION(ip_maxdim)              :: il_start
+      INTEGER(i4), DIMENSION(ip_maxdim)              :: il_count
+
+      REAL(dp)   , DIMENSION(:,:,:,:)  , ALLOCATABLE :: dl_value
+
+      TYPE(TDIM) , DIMENSION(ip_maxdim)              :: tl_dim
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_2D_dp)
+
+      ! ugly call to avoid warning
+      il_type=NF90_DOUBLE
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      tl_dim(1)=dim_init( 'X', id_len=SIZE(dd_value(:,:),DIM=1) )
+      tl_dim(2)=dim_init( 'Y', id_len=SIZE(dd_value(:,:),DIM=2) )
+      IF( PRESENT(td_dim) )THEN
+         IF( SIZE(td_dim(:)) /= 2 )THEN
+            CALL logger_error("VAR INIT: dimension of dimension structure "//&
+            &                 " not conform")
+         ELSE
+            tl_dim(1)=td_dim(1)
+            tl_dim(2)=td_dim(2)
+         ENDIF
+      ENDIF
+
+      il_start(:)=1
+      IF( PRESENT(id_start) )THEN
+         IF( SIZE(id_start(:)) /= 2 )THEN
+            CALL logger_error("VAR INIT: dimension of start table "//&
+            &                 " not conform")
+         ELSE
+            il_start(1)=id_start(1)
+            il_start(2)=id_start(2)
+         ENDIF
+      ENDIF
+
+      il_count(:)=tl_dim(1)%i_len
+      IF( PRESENT(id_count) )THEN
+         IF( SIZE(id_count(:)) /= 2 )THEN
+            CALL logger_error("VAR INIT: dimension of count table "//&
+            &                 " not conform")
+         ELSE
+            il_count(1)=id_count(1)
+            il_count(2)=id_count(2)
+         ENDIF
+      ENDIF
+
+      ! reorder dimension
+      CALL dim_reorder(tl_dim(:))
+      ! reorder table
+      il_start(:)=dim_reorder_2xyzt(tl_dim(:),il_start(:))
+      il_count(:)=dim_reorder_2xyzt(tl_dim(:),il_count(:))
+
+      var__init_2D_dp=var__init( cd_name, id_type=il_type,           &
+      &                          td_dim=tl_dim(:), td_att=td_att,    &
+      &                          dd_fill=dd_fill, cd_units=cd_units, &
+      &                          cd_stdname=cd_stdname,              &
+      &                          cd_longname=cd_longname,            &
+      &                          cd_point=cd_point, id_id=id_id,     &
+      &                          id_ew=id_ew, dd_scf=dd_scf,         &
+      &                          dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                          dd_min=dd_min, dd_max=dd_max,       &
+      &                          ld_contiguous=ld_contiguous,        &
+      &                          ld_shuffle=ld_shuffle,              &
+      &                          ld_fletcher32=ld_fletcher32,        &
+      &                          id_deflvl=id_deflvl,                &
+      &                          id_chunksz=id_chunksz(:))
+   
+      ! add value
+      ALLOCATE( dl_value(tl_dim(1)%i_len, &
+      &                  tl_dim(2)%i_len, &
+      &                  tl_dim(3)%i_len, &
+      &                  tl_dim(4)%i_len) )
+
+      IF( tl_dim(1)%l_use .AND. tl_dim(2)%l_use )THEN
+         dl_value(:,:,1,1)=dd_value(:,:)
+      ELSEIF( tl_dim(1)%l_use .AND. tl_dim(3)%l_use )THEN
+         dl_value(:,1,:,1)=dd_value(:,:)
+      ELSEIF( tl_dim(1)%l_use .AND. tl_dim(4)%l_use )THEN
+         dl_value(:,1,1,:)=dd_value(:,:)
+      ELSEIF( tl_dim(2)%l_use .AND. tl_dim(3)%l_use )THEN
+         dl_value(1,:,:,1)=dd_value(:,:)
+      ELSEIF( tl_dim(2)%l_use .AND. tl_dim(4)%l_use )THEN
+         dl_value(1,:,1,:)=dd_value(:,:)
+      ELSEIF( tl_dim(3)%l_use .AND. tl_dim(4)%l_use )THEN
+         dl_value(1,1,:,:)=dd_value(:,:)
+      ELSE
+         CALL logger_fatal("VAR INIT: can not add value from variable "//&
+         &  TRIM(cd_name)//". invalid dimension to be used")
+      ENDIF
+
+      CALL var_add_value( var__init_2D_dp, dl_value(:,:,:,:), &
+      &                   il_start(:), il_count(:) )
+
+      DEALLOCATE( dl_value )
+
+   END FUNCTION var__init_2D_dp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - real(8) 3D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> table of 3 dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y','z') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] dd_value : 1D table of real(8) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] dd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_3D_dp( cd_name, dd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, dd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      REAL(dp)        , DIMENSION(:,:,:)    , INTENT(IN) :: dd_value
+      INTEGER(i4)     , DIMENSION(:)        , INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:)        , INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:)        , INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:)        , INTENT(IN), OPTIONAL :: td_att
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                    :: il_type
+      INTEGER(i4), DIMENSION(ip_maxdim)              :: il_start
+      INTEGER(i4), DIMENSION(ip_maxdim)              :: il_count
+
+      REAL(dp)   , DIMENSION(:,:,:,:)  , ALLOCATABLE :: dl_value
+
+      TYPE(TDIM) , DIMENSION(ip_maxdim)              :: tl_dim
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_3D_dp)
+
+      ! ugly call to avoid warning
+      il_type=NF90_DOUBLE
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      tl_dim(1)=dim_init( 'X', id_len=SIZE(dd_value(:,:,:),DIM=1) )
+      tl_dim(2)=dim_init( 'Y', id_len=SIZE(dd_value(:,:,:),DIM=2) )
+      tl_dim(3)=dim_init( 'Z', id_len=SIZE(dd_value(:,:,:),DIM=3) )
+      IF( PRESENT(td_dim) )THEN
+         IF( SIZE(td_dim(:)) /= 3 )THEN
+            CALL logger_error("VAR INIT: dimension of dimension structure "//&
+            &                 " not conform")
+         ELSE
+            tl_dim(1)=td_dim(1)
+            tl_dim(2)=td_dim(2)
+            tl_dim(3)=td_dim(3)
+         ENDIF
+      ENDIF
+
+      il_start(:)=1
+      IF( PRESENT(id_start) )THEN
+         IF( SIZE(id_start(:)) /= 3 )THEN
+            CALL logger_error("VAR INIT: dimension of start table "//&
+            &                 " not conform")
+         ELSE
+            il_start(1)=id_start(1)
+            il_start(2)=id_start(2)
+            il_start(3)=id_start(3)
+         ENDIF
+      ENDIF
+
+      il_count(:)=tl_dim(:)%i_len
+      IF( PRESENT(id_count) )THEN
+         IF( SIZE(id_count(:)) /= 3 )THEN
+            CALL logger_error("VAR INIT: dimension of count table "//&
+            &                 " not conform")
+         ELSE
+            il_count(1)=id_count(1)
+            il_count(2)=id_count(2)
+            il_count(3)=id_count(3)
+         ENDIF
+      ENDIF
+
+      ! reorder dimension
+      CALL dim_reorder(tl_dim(:))
+      ! reorder table
+      il_start(:)=dim_reorder_2xyzt(tl_dim(:),il_start(:))
+      il_count(:)=dim_reorder_2xyzt(tl_dim(:),il_count(:))
+
+      var__init_3D_dp=var__init( cd_name, id_type=il_type,           &
+      &                          td_dim=tl_dim(:), td_att=td_att,    &
+      &                          dd_fill=dd_fill, cd_units=cd_units, &
+      &                          cd_stdname=cd_stdname,              &
+      &                          cd_longname=cd_longname,            &
+      &                          cd_point=cd_point, id_id=id_id,     &
+      &                          id_ew=id_ew, dd_scf=dd_scf,         &
+      &                          dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                          dd_min=dd_min, dd_max=dd_max,       &
+      &                          ld_contiguous=ld_contiguous,        &
+      &                          ld_shuffle=ld_shuffle,              &
+      &                          ld_fletcher32=ld_fletcher32,        &
+      &                          id_deflvl=id_deflvl,                &
+      &                          id_chunksz=id_chunksz(:))
+   
+      ! add value
+      ALLOCATE( dl_value(tl_dim(1)%i_len, &
+      &                  tl_dim(2)%i_len, &
+      &                  tl_dim(3)%i_len, &
+      &                  tl_dim(4)%i_len) )
+
+      IF( tl_dim(1)%l_use .AND. tl_dim(2)%l_use .AND. tl_dim(3)%l_use )THEN
+         dl_value(:,:,:,1)=dd_value(:,:,:)
+      ELSEIF( tl_dim(1)%l_use .AND. tl_dim(2)%l_use .AND. tl_dim(4)%l_use  )THEN
+         dl_value(:,:,1,:)=dd_value(:,:,:)
+      ELSEIF( tl_dim(1)%l_use .AND. tl_dim(3)%l_use .AND. tl_dim(4)%l_use )THEN
+         dl_value(:,1,:,:)=dd_value(:,:,:)
+      ELSEIF( tl_dim(2)%l_use .AND. tl_dim(3)%l_use .AND. tl_dim(4)%l_use )THEN
+         dl_value(1,:,:,:)=dd_value(:,:,:)
+      ELSE
+         CALL logger_fatal("VAR INIT: can not add value from variable "//&
+         &  TRIM(cd_name)//". invalid dimension to be used")
+      ENDIF
+
+      CALL var_add_value( var__init_3D_dp, dl_value(:,:,:,:), &
+      &                   il_start(:), il_count(:) )
+
+      DEALLOCATE( dl_value )
+
+   END FUNCTION var__init_3D_dp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - real(8) 4D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> Dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y','z','t') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] dd_value : 4D table of real(8) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] dd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_dp( cd_name, dd_value,        &
+   &                                 id_start, id_count, id_type, td_dim, &
+   &                                 td_att, dd_fill, cd_units,&
+   &                                 cd_stdname, cd_longname,  &
+   &                                 cd_point, id_id, id_ew,   &
+   &                                 dd_scf, dd_ofs,  id_rec,  &
+   &                                 dd_min, dd_max,           &
+   &                                 ld_contiguous, ld_shuffle,&
+   &                                 ld_fletcher32, id_deflvl, id_chunksz)
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      REAL(dp)        , DIMENSION(:,:,:,:),   INTENT(IN) :: dd_value
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_att
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_shape
+      TYPE(TDIM)                        :: tl_dim
+
+      INTEGER(i4) :: il_type
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_dp)
+
+      ! ugly call to avoid warning
+      il_type=NF90_DOUBLE
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      var__init_dp=var__init( cd_name, id_type=il_type,           &
+      &                       td_dim=td_dim, td_att=td_att,       &
+      &                       dd_fill=dd_fill, cd_units=cd_units, &
+      &                       cd_stdname=cd_stdname,              &
+      &                       cd_longname=cd_longname,            &
+      &                       cd_point=cd_point, id_id=id_id,     &
+      &                       id_ew=id_ew, dd_scf=dd_scf,         &
+      &                       dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                       dd_min=dd_min, dd_max=dd_max,       &
+      &                       ld_contiguous=ld_contiguous,        &
+      &                       ld_shuffle=ld_shuffle,              &
+      &                       ld_fletcher32=ld_fletcher32,        &
+      &                       id_deflvl=id_deflvl,                &
+      &                       id_chunksz=id_chunksz(:))
+   
+      ! add value
+      IF( .NOT. PRESENT(td_dim) )THEN
+         il_shape(:)=SHAPE(dd_value(:,:,:,:)) 
+         DO ji=1,ip_maxdim
+            tl_dim=dim_init( cp_dimorder(ji:ji), id_len=il_shape(ji)) 
+            CALL var_add_dim(var__init_dp, tl_dim)
+         ENDDO
+      ENDIF
+
+      CALL var_add_value( var__init_dp, dd_value(:,:,:,:), &
+      &                   id_start(:), id_count(:) )
+
+   END FUNCTION var__init_dp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - real(4) 1D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('z') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] rd_value : 1D table of real(4) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] rd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_1D_sp( cd_name, rd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, rd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      REAL(sp)        , DIMENSION(:)        , INTENT(IN) :: rd_value
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      ,                       INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_att
+      REAL(sp)        ,                       INTENT(IN), OPTIONAL :: rd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                       :: il_type
+      INTEGER(i4)                                       :: il_shape
+
+      REAL(dp)                                          :: dl_fill
+      REAL(dp)        , DIMENSION(:)      , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_1D_sp)      
+
+      il_type=NF90_FLOAT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_FLOAT
+      IF( PRESENT(rd_fill) ) dl_fill=REAL(rd_fill,dp)
+
+      il_shape=SIZE(rd_value(:))
+      ALLOCATE( dl_value( il_shape) )
+
+      dl_value(:)=REAL(rd_value(:),dp)
+
+      var__init_1D_sp=var_init( cd_name, dl_value(:),               &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+ 
+      DEALLOCATE( dl_value )
+ 
+   END FUNCTION var__init_1D_sp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - real(4) 2D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> table of 2 dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] rd_value : 2D table of real(4) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] rd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_2D_sp( cd_name, rd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, rd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      REAL(sp)        , DIMENSION(:,:)     ,  INTENT(IN) :: rd_value
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_att
+      REAL(sp)        ,                       INTENT(IN), OPTIONAL :: rd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                  :: il_type
+      INTEGER(i4), DIMENSION(2)                    :: il_shape
+
+      REAL(dp)                                     :: dl_fill
+      REAL(dp)   , DIMENSION(:,:)    , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_2D_sp)      
+
+      il_type=NF90_FLOAT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_FLOAT
+      IF( PRESENT(rd_fill) ) dl_fill=REAL(rd_fill,dp)
+
+      il_shape(:)=SHAPE(rd_value(:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2)) )
+
+      dl_value(:,:)=REAL(rd_value(:,:),dp)
+
+      var__init_2D_sp=var_init( cd_name, dl_value(:,:),             &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+   END FUNCTION var__init_2D_sp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - real(4) 2D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> table of 2 dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] rd_value : 2D table of real(4) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] rd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_3D_sp( cd_name, rd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, rd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      REAL(sp)        , DIMENSION(:,:,:)   ,  INTENT(IN) :: rd_value
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_att
+      REAL(sp)        ,                       INTENT(IN), OPTIONAL :: rd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                  :: il_type
+      INTEGER(i4), DIMENSION(3)                    :: il_shape
+
+      REAL(dp)                                     :: dl_fill
+      REAL(dp)   , DIMENSION(:,:,:)  , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_3D_sp)      
+
+      il_type=NF90_FLOAT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_FLOAT
+      IF( PRESENT(rd_fill) ) dl_fill=REAL(rd_fill,dp)
+
+      il_shape(:)=SHAPE(rd_value(:,:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2), &
+      &                   il_shape(3)) )
+
+      dl_value(:,:,:)=REAL(rd_value(:,:,:),dp)
+
+      var__init_3D_sp=var_init( cd_name, dl_value(:,:,:),           &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+   END FUNCTION var__init_3D_sp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - real(4) 4D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> Dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y','z','t') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] rd_value : 4D table of real(4) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] rd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_sp( cd_name, rd_value,        &
+   &                                 id_start, id_count, id_type, td_dim, &
+   &                                 td_att, rd_fill, cd_units,&
+   &                                 cd_stdname, cd_longname,  &
+   &                                 cd_point, id_id, id_ew,   &
+   &                                 dd_scf, dd_ofs,  id_rec,  &
+   &                                 dd_min, dd_max,           &
+   &                                 ld_contiguous, ld_shuffle,&
+   &                                 ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      REAL(sp)        , DIMENSION(:,:,:,:),   INTENT(IN) :: rd_value
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_att
+      REAL(sp)        ,                       INTENT(IN), OPTIONAL :: rd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                       :: il_type
+      INTEGER(i4), DIMENSION(ip_maxdim)                 :: il_shape
+
+      REAL(dp)                                          :: dl_fill
+      REAL(dp)        , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_sp)      
+
+      il_type=NF90_FLOAT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_FLOAT
+      IF( PRESENT(rd_fill) ) dl_fill=REAL(rd_fill,dp)
+
+      il_shape(:)=SHAPE(rd_value(:,:,:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2), &
+      &                   il_shape(3), &
+      &                   il_shape(4)) )
+
+      dl_value(:,:,:,:)=REAL(rd_value(:,:,:,:),dp)
+
+      var__init_sp=var_init( cd_name, dl_value(:,:,:,:),         &
+      &                      id_start=id_start,                  &
+      &                      id_count=id_count,                  &
+      &                      id_type=il_type,                    &
+      &                      td_dim=td_dim, td_att=td_att,       &
+      &                      dd_fill=dl_fill,                    &
+      &                      cd_units=cd_units,                  &
+      &                      cd_stdname=cd_stdname,              &
+      &                      cd_longname=cd_longname,            &
+      &                      cd_point=cd_point, id_id=id_id,     &
+      &                      id_ew=id_ew, dd_scf=dd_scf,         &
+      &                      dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                      dd_min=dd_min, dd_max=dd_max,       &
+      &                      ld_contiguous=ld_contiguous,        &
+      &                      ld_shuffle=ld_shuffle,              &
+      &                      ld_fletcher32=ld_fletcher32,        &
+      &                      id_deflvl=id_deflvl,                &
+      &                      id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+   END FUNCTION var__init_sp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(8) 1D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('z') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] kd_value : 1D table of integer(8) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] kd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_1D_i8( cd_name, kd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, kd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i8)     , DIMENSION(:)        , INTENT(IN) :: kd_value
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      ,                       INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i8)     ,                       INTENT(IN), OPTIONAL :: kd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                       :: il_type
+      INTEGER(i4)                                       :: il_shape
+
+      REAL(dp)                                          :: dl_fill
+      REAL(dp)        , DIMENSION(:)      , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_1D_i8)      
+
+      il_type=NF90_INT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_INT
+      IF( PRESENT(kd_fill) ) dl_fill=REAL(kd_fill,dp)
+
+      il_shape=SIZE(kd_value(:))
+      ALLOCATE( dl_value( il_shape) )
+
+      dl_value(:)=REAL(kd_value(:),dp)
+
+      var__init_1D_i8=var_init( cd_name, dl_value(:),               &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+ 
+      DEALLOCATE( dl_value )
+ 
+   END FUNCTION var__init_1D_i8
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(8) 2D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> table of 2 dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] kd_value : 2D table of integer(8) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] kd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_2D_i8( cd_name, kd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, kd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i8)     , DIMENSION(:,:)     ,  INTENT(IN) :: kd_value
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i8)     ,                       INTENT(IN), OPTIONAL :: kd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                  :: il_type
+      INTEGER(i4), DIMENSION(2)                    :: il_shape
+
+      REAL(dp)                                     :: dl_fill
+      REAL(dp)   , DIMENSION(:,:)    , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_2D_i8)      
+
+      il_type=NF90_INT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_INT
+      IF( PRESENT(kd_fill) ) dl_fill=REAL(kd_fill,dp)
+
+      il_shape(:)=SHAPE(kd_value(:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2)) )
+
+      dl_value(:,:)=REAL(kd_value(:,:),dp)
+
+      var__init_2D_i8=var_init( cd_name, dl_value(:,:),             &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+   END FUNCTION var__init_2D_i8
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(8) 2D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> table of 2 dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] kd_value : 2D table of integer(8) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] kd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_3D_i8( cd_name, kd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, kd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i8)     , DIMENSION(:,:,:)   ,  INTENT(IN) :: kd_value
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i8)     ,                       INTENT(IN), OPTIONAL :: kd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                  :: il_type
+      INTEGER(i4), DIMENSION(3)                    :: il_shape
+
+      REAL(dp)                                     :: dl_fill
+      REAL(dp)   , DIMENSION(:,:,:)  , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_3D_i8)      
+
+      il_type=NF90_INT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_INT
+      IF( PRESENT(kd_fill) ) dl_fill=REAL(kd_fill,dp)
+
+      il_shape(:)=SHAPE(kd_value(:,:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2), &
+      &                   il_shape(3)) )
+
+      dl_value(:,:,:)=REAL(kd_value(:,:,:),dp)
+
+      var__init_3D_i8=var_init( cd_name, dl_value(:,:,:),           &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+   END FUNCTION var__init_3D_i8
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(8) 4D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> Dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y','z','t') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] kd_value : 4D table of integer(8) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] kd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_i8( cd_name, kd_value,        &
+   &                                 id_start, id_count, id_type, td_dim, &
+   &                                 td_att, kd_fill, cd_units,&
+   &                                 cd_stdname, cd_longname,  &
+   &                                 cd_point, id_id, id_ew,   &
+   &                                 dd_scf, dd_ofs,  id_rec,  &
+   &                                 dd_min, dd_max,           &
+   &                                 ld_contiguous, ld_shuffle,&
+   &                                 ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i8)     , DIMENSION(:,:,:,:),   INTENT(IN) :: kd_value
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i8)     ,                       INTENT(IN), OPTIONAL :: kd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                       :: il_type
+      INTEGER(i4), DIMENSION(ip_maxdim)                 :: il_shape
+
+      REAL(dp)                                          :: dl_fill
+      REAL(dp)        , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_i8)      
+
+      il_type=NF90_INT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_INT
+      IF( PRESENT(kd_fill) ) dl_fill=REAL(kd_fill,dp)
+
+      il_shape(:)=SHAPE(kd_value(:,:,:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2), &
+      &                   il_shape(3), &
+      &                   il_shape(4)) )
+
+      dl_value(:,:,:,:)=REAL(kd_value(:,:,:,:),dp)
+
+      var__init_i8=var_init( cd_name, dl_value(:,:,:,:),         &
+      &                      id_start=id_start,                  &
+      &                      id_count=id_count,                  &
+      &                      id_type=il_type,                    &
+      &                      td_dim=td_dim, td_att=td_att,       &
+      &                      dd_fill=dl_fill,                    &
+      &                      cd_units=cd_units,                  &
+      &                      cd_stdname=cd_stdname,              &
+      &                      cd_longname=cd_longname,            &
+      &                      cd_point=cd_point, id_id=id_id,     &
+      &                      id_ew=id_ew, dd_scf=dd_scf,         &
+      &                      dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                      dd_min=dd_min, dd_max=dd_max,       &
+      &                      ld_contiguous=ld_contiguous,        &
+      &                      ld_shuffle=ld_shuffle,              &
+      &                      ld_fletcher32=ld_fletcher32,        &
+      &                      id_deflvl=id_deflvl,                &
+      &                      id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+   END FUNCTION var__init_i8
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(4) 1D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('z') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] id_value : 1D table of integer(4) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] id_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_1D_i4( cd_name, id_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, id_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i4)     , DIMENSION(:)        , INTENT(IN) :: id_value
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      ,                       INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                       :: il_type
+      INTEGER(i4)                                       :: il_shape
+
+      REAL(dp)                                          :: dl_fill
+      REAL(dp)        , DIMENSION(:)      , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_1D_i4)      
+
+      il_type=NF90_INT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_INT
+      IF( PRESENT(id_fill) ) dl_fill=REAL(id_fill,dp)
+
+      il_shape=SIZE(id_value(:))
+      ALLOCATE( dl_value( il_shape) )
+
+      dl_value(:)=REAL(id_value(:),dp)
+
+      var__init_1D_i4=var_init( cd_name, dl_value(:),               &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+ 
+      DEALLOCATE( dl_value )
+ 
+   END FUNCTION var__init_1D_i4
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(4) 2D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> table of 2 dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] id_value : 2D table of integer(4) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] id_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_2D_i4( cd_name, id_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, id_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i4)     , DIMENSION(:,:)     ,  INTENT(IN) :: id_value
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                  :: il_type
+      INTEGER(i4), DIMENSION(2)                    :: il_shape
+
+      REAL(dp)                                     :: dl_fill
+      REAL(dp)   , DIMENSION(:,:)    , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_2D_i4)      
+
+      il_type=NF90_INT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_INT
+      IF( PRESENT(id_fill) ) dl_fill=REAL(id_fill,dp)
+
+      il_shape(:)=SHAPE(id_value(:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2)) )
+
+      dl_value(:,:)=REAL(id_value(:,:),dp)
+
+      var__init_2D_i4=var_init( cd_name, dl_value(:,:),             &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+   END FUNCTION var__init_2D_i4
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(4) 2D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> table of 2 dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] id_value : 2D table of integer(4) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] id_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_3D_i4( cd_name, id_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, id_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i4)     , DIMENSION(:,:,:)   ,  INTENT(IN) :: id_value
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                  :: il_type
+      INTEGER(i4), DIMENSION(3)                    :: il_shape
+
+      REAL(dp)                                     :: dl_fill
+      REAL(dp)   , DIMENSION(:,:,:)  , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_3D_i4)      
+
+      il_type=NF90_INT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_INT
+      IF( PRESENT(id_fill) ) dl_fill=REAL(id_fill,dp)
+
+      il_shape(:)=SHAPE(id_value(:,:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2), &
+      &                   il_shape(3)) )
+
+      dl_value(:,:,:)=REAL(id_value(:,:,:),dp)
+
+      var__init_3D_i4=var_init( cd_name, dl_value(:,:,:),           &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+   END FUNCTION var__init_3D_i4
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(4) 4D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> Dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y','z','t') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] id_value : 4D table of integer(4) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] id_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_i4( cd_name, id_value,        &
+   &                                 id_start, id_count, id_type, td_dim, &
+   &                                 td_att, id_fill, cd_units,&
+   &                                 cd_stdname, cd_longname,  &
+   &                                 cd_point, id_id, id_ew,   &
+   &                                 dd_scf, dd_ofs,  id_rec,  &
+   &                                 dd_min, dd_max,           &
+   &                                 ld_contiguous, ld_shuffle,&
+   &                                 ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i4)     , DIMENSION(:,:,:,:),   INTENT(IN) :: id_value
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                       :: il_type
+      INTEGER(i4), DIMENSION(ip_maxdim)                 :: il_shape
+
+      REAL(dp)                                          :: dl_fill
+      REAL(dp)        , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_i4)      
+
+      il_type=NF90_INT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_INT
+      IF( PRESENT(id_fill) ) dl_fill=REAL(id_fill,dp)
+
+      il_shape(:)=SHAPE(id_value(:,:,:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2), &
+      &                   il_shape(3), &
+      &                   il_shape(4)) )
+
+      dl_value(:,:,:,:)=REAL(id_value(:,:,:,:),dp)
+
+      var__init_i4=var_init( cd_name, dl_value(:,:,:,:),         &
+      &                      id_start=id_start,                  &
+      &                      id_count=id_count,                  &
+      &                      id_type=il_type,                    &
+      &                      td_dim=td_dim, td_att=td_att,       &
+      &                      dd_fill=dl_fill,                    &
+      &                      cd_units=cd_units,                  &
+      &                      cd_stdname=cd_stdname,              &
+      &                      cd_longname=cd_longname,            &
+      &                      cd_point=cd_point, id_id=id_id,     &
+      &                      id_ew=id_ew, dd_scf=dd_scf,         &
+      &                      dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                      dd_min=dd_min, dd_max=dd_max,       &
+      &                      ld_contiguous=ld_contiguous,        &
+      &                      ld_shuffle=ld_shuffle,              &
+      &                      ld_fletcher32=ld_fletcher32,        &
+      &                      id_deflvl=id_deflvl,                &
+      &                      id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+!      ! add value
+!      IF( .NOT. PRESENT(td_dim) )THEN
+!         il_shape(:)=SHAPE(id_value(:,:,:,:)) 
+!         DO ji=1,ip_maxdim
+!            tl_dim=dim_init( cp_dimorder(ji:ji), id_len=il_shape(ji)) 
+!            CALL var_add_dim(var__init_i4, tl_dim)
+!         ENDDO
+!      ENDIF
+!      CALL var_add_value(var__init_i4, id_value(:,:,:,:), &
+!      &                  id_start(:), id_count(:))
+      
+   END FUNCTION var__init_i4
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(2) 1D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('z') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] sd_value : 1D table of integer(2) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] sd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_1D_i2( cd_name, sd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, sd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i2)     , DIMENSION(:)        , INTENT(IN) :: sd_value
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      ,                       INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i2)     ,                       INTENT(IN), OPTIONAL :: sd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                       :: il_type
+      INTEGER(i4)                                       :: il_shape
+
+      REAL(dp)                                          :: dl_fill
+      REAL(dp)        , DIMENSION(:)      , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_1D_i2)      
+
+      il_type=NF90_SHORT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_SHORT
+      IF( PRESENT(sd_fill) ) dl_fill=REAL(sd_fill,dp)
+
+      il_shape=SIZE(sd_value(:))
+      ALLOCATE( dl_value( il_shape) )
+
+      dl_value(:)=REAL(sd_value(:),dp)
+
+      var__init_1D_i2=var_init( cd_name, dl_value(:),               &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+ 
+      DEALLOCATE( dl_value )
+ 
+   END FUNCTION var__init_1D_i2
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(2) 2D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> table of 2 dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] sd_value : 2D table of integer(2) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] sd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_2D_i2( cd_name, sd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, sd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i2)     , DIMENSION(:,:)     ,  INTENT(IN) :: sd_value
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i2)     ,                       INTENT(IN), OPTIONAL :: sd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                  :: il_type
+      INTEGER(i4), DIMENSION(2)                    :: il_shape
+
+      REAL(dp)                                     :: dl_fill
+      REAL(dp)   , DIMENSION(:,:)    , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_2D_i2)      
+
+      il_type=NF90_SHORT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_SHORT
+      IF( PRESENT(sd_fill) ) dl_fill=REAL(sd_fill,dp)
+
+      il_shape(:)=SHAPE(sd_value(:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2)) )
+
+      dl_value(:,:)=REAL(sd_value(:,:),dp)
+
+      var__init_2D_i2=var_init( cd_name, dl_value(:,:),             &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+   END FUNCTION var__init_2D_i2
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(2) 2D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> table of 2 dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] sd_value : 2D table of integer(2) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] sd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_3D_i2( cd_name, sd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, sd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i2)     , DIMENSION(:,:,:)   ,  INTENT(IN) :: sd_value
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i2)     ,                       INTENT(IN), OPTIONAL :: sd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                  :: il_type
+      INTEGER(i4), DIMENSION(3)                    :: il_shape
+
+      REAL(dp)                                     :: dl_fill
+      REAL(dp)   , DIMENSION(:,:,:)  , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_3D_i2)      
+
+      il_type=NF90_SHORT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_SHORT
+      IF( PRESENT(sd_fill) ) dl_fill=REAL(sd_fill,dp)
+
+      il_shape(:)=SHAPE(sd_value(:,:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2), &
+      &                   il_shape(3)) )
+
+      dl_value(:,:,:)=REAL(sd_value(:,:,:),dp)
+
+      var__init_3D_i2=var_init( cd_name, dl_value(:,:,:),           &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+   END FUNCTION var__init_3D_i2
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(2) 4D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> Dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y','z','t') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] sd_value : 4D table of integer(2) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] sd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_i2( cd_name, sd_value,        &
+   &                                 id_start, id_count, id_type, td_dim, &
+   &                                 td_att, sd_fill, cd_units,&
+   &                                 cd_stdname, cd_longname,  &
+   &                                 cd_point, id_id, id_ew,   &
+   &                                 dd_scf, dd_ofs,  id_rec,  &
+   &                                 dd_min, dd_max,           &
+   &                                 ld_contiguous, ld_shuffle,&
+   &                                 ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i2)     , DIMENSION(:,:,:,:),   INTENT(IN) :: sd_value
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i2)     ,                       INTENT(IN), OPTIONAL :: sd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                       :: il_type
+      INTEGER(i4), DIMENSION(ip_maxdim)                 :: il_shape
+
+      REAL(dp)                                          :: dl_fill
+      REAL(dp)        , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_i2)      
+
+      il_type=NF90_SHORT
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_SHORT
+      IF( PRESENT(sd_fill) ) dl_fill=REAL(sd_fill,dp)
+
+      il_shape(:)=SHAPE(sd_value(:,:,:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2), &
+      &                   il_shape(3), &
+      &                   il_shape(4)) )
+
+      dl_value(:,:,:,:)=REAL(sd_value(:,:,:,:),dp)
+
+      var__init_i2=var_init( cd_name, dl_value(:,:,:,:),         &
+      &                      id_start=id_start,                  &
+      &                      id_count=id_count,                  &
+      &                      id_type=il_type,                    &
+      &                      td_dim=td_dim, td_att=td_att,       &
+      &                      dd_fill=dl_fill,                    &
+      &                      cd_units=cd_units,                  &
+      &                      cd_stdname=cd_stdname,              &
+      &                      cd_longname=cd_longname,            &
+      &                      cd_point=cd_point, id_id=id_id,     &
+      &                      id_ew=id_ew, dd_scf=dd_scf,         &
+      &                      dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                      dd_min=dd_min, dd_max=dd_max,       &
+      &                      ld_contiguous=ld_contiguous,        &
+      &                      ld_shuffle=ld_shuffle,              &
+      &                      ld_fletcher32=ld_fletcher32,        &
+      &                      id_deflvl=id_deflvl,                &
+      &                      id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+!      ! add value
+!      IF( .NOT. PRESENT(td_dim) )THEN
+!         il_shape(:)=SHAPE(sd_value(:,:,:,:)) 
+!         DO ji=1,ip_maxdim
+!            tl_dim=dim_init( cp_dimorder(ji:ji), id_len=il_shape(ji)) 
+!            CALL var_add_dim(var__init_i2, tl_dim)
+!         ENDDO
+!      ENDIF
+!      CALL var_add_value(var__init_i2, sd_value(:,:,:,:), &
+!      &                  id_start(:), id_count(:))
+      
+   END FUNCTION var__init_i2
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(1) 1D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('z') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] bd_value : 1D table of integer(1) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] bd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_1D_i1( cd_name, bd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, bd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i1)     , DIMENSION(:)        , INTENT(IN) :: bd_value
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      ,                       INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i1)     ,                       INTENT(IN), OPTIONAL :: bd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                       :: il_type
+      INTEGER(i4)                                       :: il_shape
+
+      REAL(dp)                                          :: dl_fill
+      REAL(dp)        , DIMENSION(:)      , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_1D_i1)      
+
+      il_type=NF90_BYTE
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_BYTE
+      IF( PRESENT(bd_fill) ) dl_fill=REAL(bd_fill,dp)
+
+      il_shape=SIZE(bd_value(:))
+      ALLOCATE( dl_value( il_shape) )
+
+      dl_value(:)=REAL(bd_value(:),dp)
+
+      var__init_1D_i1=var_init( cd_name, dl_value(:),               &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+ 
+      DEALLOCATE( dl_value )
+ 
+   END FUNCTION var__init_1D_i1
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(1) 2D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> table of 2 dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] bd_value : 2D table of integer(1) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] bd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_2D_i1( cd_name, bd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, bd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i1)     , DIMENSION(:,:)     ,  INTENT(IN) :: bd_value
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i1)     ,                       INTENT(IN), OPTIONAL :: bd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                  :: il_type
+      INTEGER(i4), DIMENSION(2)                    :: il_shape
+
+      REAL(dp)                                     :: dl_fill
+      REAL(dp)   , DIMENSION(:,:)    , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_2D_i1)      
+
+      il_type=NF90_BYTE
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_BYTE
+      IF( PRESENT(bd_fill) ) dl_fill=REAL(bd_fill,dp)
+
+      il_shape(:)=SHAPE(bd_value(:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2)) )
+
+      dl_value(:,:)=REAL(bd_value(:,:),dp)
+
+      var__init_2D_i1=var_init( cd_name, dl_value(:,:),             &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+   END FUNCTION var__init_2D_i1
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(1) 2D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> table of 2 dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] bd_value : 2D table of integer(1) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] bd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_3D_i1( cd_name, bd_value,        &
+   &                                    id_start, id_count, id_type, td_dim, &
+   &                                    td_att, bd_fill, cd_units,&
+   &                                    cd_stdname, cd_longname,  &
+   &                                    cd_point, id_id, id_ew,   &
+   &                                    dd_scf, dd_ofs,  id_rec,  &
+   &                                    dd_min, dd_max,           &
+   &                                    ld_contiguous, ld_shuffle,&
+   &                                    ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i1)     , DIMENSION(:,:,:)   ,  INTENT(IN) :: bd_value
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(:)       , INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:)       ,  INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i1)     ,                       INTENT(IN), OPTIONAL :: bd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                  :: il_type
+      INTEGER(i4), DIMENSION(3)                    :: il_shape
+
+      REAL(dp)                                     :: dl_fill
+      REAL(dp)   , DIMENSION(:,:,:)  , ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_3D_i1)      
+
+      il_type=NF90_BYTE
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_BYTE
+      IF( PRESENT(bd_fill) ) dl_fill=REAL(bd_fill,dp)
+
+      il_shape(:)=SHAPE(bd_value(:,:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2), &
+      &                   il_shape(3)) )
+
+      dl_value(:,:,:)=REAL(bd_value(:,:,:),dp)
+
+      var__init_3D_i1=var_init( cd_name, dl_value(:,:,:),           &
+      &                         id_start=id_start,                  &
+      &                         id_count=id_count,                  &
+      &                         id_type=il_type,                    &
+      &                         td_dim=td_dim, td_att=td_att,       &
+      &                         dd_fill=dl_fill,                    &
+      &                         cd_units=cd_units,                  &
+      &                         cd_stdname=cd_stdname,              &
+      &                         cd_longname=cd_longname,            &
+      &                         cd_point=cd_point, id_id=id_id,     &
+      &                         id_ew=id_ew, dd_scf=dd_scf,         &
+      &                         dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                         dd_min=dd_min, dd_max=dd_max,       &
+      &                         ld_contiguous=ld_contiguous,        &
+      &                         ld_shuffle=ld_shuffle,              &
+      &                         ld_fletcher32=ld_fletcher32,        &
+      &                         id_deflvl=id_deflvl,                &
+      &                         id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+   END FUNCTION var__init_3D_i1
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function initalise a variable structure.
+   !> - integer(1) 4D table of value could be added. 
+   !> - dimension structure could be added.
+   !> - attribute structure could be added
+   !
+   !> @details 
+   !> Dimension structure is needed to put value in variable structure. 
+   !> If none is given, we assume table is ordered as ('x','y','z','t') and we 
+   !> use table size as lentgh dimension. 
+   !>
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. Dimension structure is needed in that 
+   !> case.    
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_name : variable name
+   !> @param[in] bd_value : 4D table of integer(1) value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_type : variable type 
+   !> @param[in] td_dim   : table of dimension structure
+   !> @param[in] td_att  : table of attribute structure
+   !> @param[in] bd_fill : fill value
+   !> @param[in] cd_units : units
+   !> @param[in] cd_stdname : variable standard name
+   !> @param[in] cd_longname : variable long name
+   !> @param[in] cd_point : point on Arakawa-C grid (T,U,V,F)
+   !> @param[in] id_id : variable id
+   !> @param[in] id_ew : east west wrap
+   !> @param[in] dd_scf  : scale factor
+   !> @param[in] dd_ofs  : add offset
+   !> @param[in] id_rec : record id (for rstdimg file)
+   !> @param[in] dd_min : minimum value
+   !> @param[in] dd_max : maximum value
+   !> @param[in] ld_contiguous : use contiguous storage or not 
+   !> @param[in] ld_shuffle :  shuffle filter is turned on or not
+   !> @param[in] ld_fletcher32 : fletcher32 filter is turned on or not
+   !> @param[in] id_deflvl : deflate level from 0 to 9, 0 indicates no deflation is in use
+   !> @param[in] id_chunksz : chunk size
+   !-------------------------------------------------------------------
+   !> @code
+   TYPE(TVAR) FUNCTION var__init_i1( cd_name, bd_value,        &
+   &                                 id_start, id_count, id_type, td_dim, &
+   &                                 td_att, bd_fill, cd_units,&
+   &                                 cd_stdname, cd_longname,  &
+   &                                 cd_point, id_id, id_ew,   &
+   &                                 dd_scf, dd_ofs,  id_rec,  &
+   &                                 dd_min, dd_max,           &
+   &                                 ld_contiguous, ld_shuffle,&
+   &                                 ld_fletcher32, id_deflvl, id_chunksz)
+
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*),                       INTENT(IN) :: cd_name
+      INTEGER(i1)     , DIMENSION(:,:,:,:),   INTENT(IN) :: bd_value
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_start
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_count
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_type 
+      TYPE(TDIM)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_dim
+      TYPE(TATT)      , DIMENSION(:),         INTENT(IN), OPTIONAL :: td_att
+      INTEGER(i1)     ,                       INTENT(IN), OPTIONAL :: bd_fill
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_units
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_stdname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_longname
+      CHARACTER(LEN=*),                       INTENT(IN), OPTIONAL :: cd_point
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_id 
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_ew 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_scf
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_ofs
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_rec 
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_min
+      REAL(dp)        ,                       INTENT(IN), OPTIONAL :: dd_max
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_contiguous
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_shuffle
+      LOGICAL         ,                       INTENT(IN), OPTIONAL :: ld_fletcher32
+      INTEGER(i4)     ,                       INTENT(IN), OPTIONAL :: id_deflvl
+      INTEGER(i4)     , DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_chunksz
+
+      ! local variable
+      INTEGER(i4)                                       :: il_type
+      INTEGER(i4), DIMENSION(ip_maxdim)                 :: il_shape
+
+      REAL(dp)                                          :: dl_fill
+      REAL(dp)        , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! clean variable
+      CALL var_clean(var__init_i1)      
+
+      il_type=NF90_BYTE
+      IF( PRESENT(id_type) ) il_type=id_type
+
+      dl_fill=NF90_FILL_BYTE
+      IF( PRESENT(bd_fill) ) dl_fill=REAL(bd_fill,dp)
+
+      il_shape(:)=SHAPE(bd_value(:,:,:,:))
+
+      ALLOCATE( dl_value( il_shape(1), &
+      &                   il_shape(2), &
+      &                   il_shape(3), &
+      &                   il_shape(4)) )
+
+      dl_value(:,:,:,:)=REAL(bd_value(:,:,:,:),dp)
+
+      var__init_i1=var_init( cd_name, dl_value(:,:,:,:),         &
+      &                      id_start=id_start,                  &
+      &                      id_count=id_count,                  &
+      &                      id_type=il_type,                    &
+      &                      td_dim=td_dim, td_att=td_att,       &
+      &                      dd_fill=dl_fill,                    &
+      &                      cd_units=cd_units,                  &
+      &                      cd_stdname=cd_stdname,              &
+      &                      cd_longname=cd_longname,            &
+      &                      cd_point=cd_point, id_id=id_id,     &
+      &                      id_ew=id_ew, dd_scf=dd_scf,         &
+      &                      dd_ofs=dd_ofs,  id_rec=id_rec,      &
+      &                      dd_min=dd_min, dd_max=dd_max,       &
+      &                      ld_contiguous=ld_contiguous,        &
+      &                      ld_shuffle=ld_shuffle,              &
+      &                      ld_fletcher32=ld_fletcher32,        &
+      &                      id_deflvl=id_deflvl,                &
+      &                      id_chunksz=id_chunksz(:))
+      
+      DEALLOCATE( dl_value )
+      
+!      ! add value
+!      IF( .NOT. PRESENT(td_dim) )THEN
+!         il_shape(:)=SHAPE(bd_value(:,:,:,:)) 
+!         DO ji=1,ip_maxdim
+!            tl_dim=dim_init( cp_dimorder(ji:ji), id_len=il_shape(ji)) 
+!            CALL var_add_dim(var__init_i1, tl_dim)
+!         ENDDO
+!      ENDIF
+!      CALL var_add_value(var__init_i1, bd_value(:,:,:,:), &
+!      &                  id_start(:), id_count(:))
+      
+   END FUNCTION var__init_i1
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief  This function concatenate variable value following DIM direction.
+   !> 
+   !> @details
+   !> By default variable are concatenate following time dimension. To
+   !> concatenate following another dimension, specify DIM=x where x is the
+   !> dimension number (1,2,3,4) 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var1 : variable structure
+   !> @param[in] td_var2 : variable structure
+   !> @param[in] DIM : dimension following which concatenate  
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION var_concat(td_var1, td_var2, DIM)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_var1
+      TYPE(TVAR) , INTENT(IN) :: td_var2
+      INTEGER(i4), INTENT(IN), OPTIONAL :: DIM
+
+      ! function
+      TYPE(TVAR) :: var_concat
+
+      ! local variable
+      INTEGER(i4) :: il_dim
+      !----------------------------------------------------------------
+      il_dim=4
+      IF( PRESENT(DIM) )il_dim=DIM
+
+      IF( .NOT. ASSOCIATED(td_var1%d_value) )THEN
+         CALL logger_error("VAR CONCAT: no value associated to variable "//&
+         &  TRIM(td_var1%c_name) )
+      ELSEIF( .NOT. ASSOCIATED(td_var2%d_value) )THEN
+         CALL logger_error("VAR CONCAT: no value associated to variable "//&
+         &  TRIM(td_var2%c_name) )
+      ELSEIF( il_dim < 0 .OR. il_dim > 4 )THEN
+         CALL logger_error("VAR CONCAT: invalid concatenate dimension ")
+      ELSE
+         ! check other dimension
+         SELECT CASE(il_dim)
+         CASE(1)
+            var_concat=var__concat_i(td_var1, td_var2)
+         CASE(2)
+            var_concat=var__concat_j(td_var1, td_var2)
+         CASE(3)
+            var_concat=var__concat_k(td_var1, td_var2)
+         CASE(4)
+            var_concat=var__concat_l(td_var1, td_var2)
+         END SELECT
+
+      ENDIF
+
+   END FUNCTION var_concat
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief  This function concatenate variable value following i-direction.
+   !> 
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var1 : variable structure
+   !> @param[in] td_var2 : variable structure
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION var__concat_i(td_var1, td_var2)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_var1
+      TYPE(TVAR) , INTENT(IN) :: td_var2
+
+      ! function
+      TYPE(TVAR) :: var__concat_i
+
+      ! local variable
+      TYPE(TVAR)        :: tl_var
+      CHARACTER(LEN=lc) :: cl_tmp
+
+      !----------------------------------------------------------------
+      IF( ANY(td_var1%t_dim(2:4)%i_len /=  td_var2%t_dim(2:4)%i_len) )THEN
+         CALL logger_error("VAR CONCAT: dimension not conform")
+
+         cl_tmp='('//":"//","//&
+         &           TRIM(fct_str(td_var1%t_dim(2)%i_len))//','//&
+         &           TRIM(fct_str(td_var1%t_dim(3)%i_len))//','//&
+         &           TRIM(fct_str(td_var1%t_dim(4)%i_len))//')'
+         CALL logger_debug("VAR CONCAT: first variable dimensions "//&
+         &  TRIM(cl_tmp) )
+         cl_tmp='('//":"//","//&
+         &           TRIM(fct_str(td_var2%t_dim(2)%i_len))//','//&
+         &           TRIM(fct_str(td_var2%t_dim(3)%i_len))//','//&
+         &           TRIM(fct_str(td_var2%t_dim(4)%i_len))//')'         
+         CALL logger_debug("VAR CONCAT: second variable dimensions "//&
+         &  TRIM(cl_tmp) )
+      ELSE
+         tl_var=td_var1
+
+         DEALLOCATE(tl_var%d_value)
+         ! change dimension length
+         tl_var%t_dim(1)%i_len=td_var1%t_dim(1)%i_len+td_var2%t_dim(1)%i_len
+         
+         ALLOCATE(tl_var%d_value(tl_var%t_dim(1)%i_len, &
+         &                       tl_var%t_dim(2)%i_len, &
+         &                       tl_var%t_dim(3)%i_len, &
+         &                       tl_var%t_dim(4)%i_len) )
+
+         ! copy first variable value
+         tl_var%d_value(1:td_var1%t_dim(1)%i_len,:,:,:) = &
+         &  td_var1%d_value(:,:,:,:)
+
+         ! copy second variable value
+         tl_var%d_value(td_var1%t_dim(1)%i_len+1:tl_var%t_dim(1)%i_len,:,:,:)=&
+         &  td_var2%d_value(:,:,:,:)
+
+         ! save result
+         var__concat_i=tl_var
+
+         CALL var_clean(tl_var)
+      ENDIF
+
+   END FUNCTION var__concat_i
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief  This function concatenate variable value following j-direction.
+   !> 
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var1 : variable structure
+   !> @param[in] td_var2 : variable structure
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION var__concat_j(td_var1, td_var2)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_var1
+      TYPE(TVAR) , INTENT(IN) :: td_var2
+
+      ! function
+      TYPE(TVAR) :: var__concat_j
+
+      ! local variable
+      TYPE(TVAR)        :: tl_var
+      CHARACTER(LEN=lc) :: cl_tmp
+
+      !----------------------------------------------------------------
+      IF(     td_var1%t_dim(1)%i_len   /=  td_var2%t_dim(1)%i_len  .OR. &
+      &   ANY(td_var1%t_dim(3:4)%i_len /=  td_var2%t_dim(3:4)%i_len) )THEN
+         CALL logger_error("VAR CONCAT: dimension not conform")
+
+         cl_tmp='('//&
+         &           TRIM(fct_str(td_var1%t_dim(1)%i_len))//','//&
+         &           ":"//','//&
+         &           TRIM(fct_str(td_var1%t_dim(3)%i_len))//','//&
+         &           TRIM(fct_str(td_var1%t_dim(4)%i_len))//')'
+         CALL logger_debug("VAR CONCAT: first variable dimensions "//&
+         &  TRIM(cl_tmp) )
+         cl_tmp='('//&
+         &           TRIM(fct_str(td_var1%t_dim(1)%i_len))//','//&
+         &           ":"//','//&
+         &           TRIM(fct_str(td_var2%t_dim(3)%i_len))//','//&
+         &           TRIM(fct_str(td_var2%t_dim(4)%i_len))//')'         
+         CALL logger_debug("VAR CONCAT: second variable dimensions "//&
+         &  TRIM(cl_tmp) )
+      ELSE
+         tl_var=td_var1
+
+         DEALLOCATE(tl_var%d_value)
+         ! change dimension length
+         tl_var%t_dim(2)%i_len=td_var1%t_dim(2)%i_len+td_var2%t_dim(2)%i_len
+         
+         ALLOCATE(tl_var%d_value(tl_var%t_dim(1)%i_len, &
+         &                       tl_var%t_dim(2)%i_len, &
+         &                       tl_var%t_dim(3)%i_len, &
+         &                       tl_var%t_dim(4)%i_len) )
+
+         ! copy first variable value
+         tl_var%d_value(:,1:td_var1%t_dim(2)%i_len,:,:)= &
+         &  td_var1%d_value(:,:,:,:)
+
+         ! copy second variable value
+         tl_var%d_value(:,td_var1%t_dim(2)%i_len+1:tl_var%t_dim(2)%i_len,:,:)=&
+         &  td_var2%d_value(:,:,:,:)
+
+         ! save result
+         var__concat_j=tl_var
+
+         CALL var_clean(tl_var)
+      ENDIF
+
+   END FUNCTION var__concat_j
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief  This function concatenate variable value following k-direction.
+   !> 
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var1 : variable structure
+   !> @param[in] td_var2 : variable structure
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION var__concat_k(td_var1, td_var2)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_var1
+      TYPE(TVAR) , INTENT(IN) :: td_var2
+
+      ! function
+      TYPE(TVAR) :: var__concat_k
+
+      ! local variable
+      TYPE(TVAR)        :: tl_var
+      CHARACTER(LEN=lc) :: cl_tmp
+
+      !----------------------------------------------------------------
+      IF(     td_var1%t_dim(4)%i_len   /=  td_var2%t_dim(4)%i_len  .OR. &
+      &   ANY(td_var1%t_dim(1:2)%i_len /=  td_var2%t_dim(1:2)%i_len) )THEN
+         CALL logger_error("VAR CONCAT: dimension not conform")
+
+         cl_tmp='('//&
+         &           TRIM(fct_str(td_var1%t_dim(1)%i_len))//','//&
+         &           TRIM(fct_str(td_var1%t_dim(2)%i_len))//','//&
+         &           ":"//','//&
+         &           TRIM(fct_str(td_var1%t_dim(4)%i_len))//')'
+         CALL logger_debug("VAR CONCAT: first variable dimensions "//&
+         &  TRIM(cl_tmp) )
+         cl_tmp='('//&
+         &           TRIM(fct_str(td_var1%t_dim(1)%i_len))//','//&
+         &           TRIM(fct_str(td_var2%t_dim(2)%i_len))//','//&
+         &           ":"//','//&
+         &           TRIM(fct_str(td_var2%t_dim(4)%i_len))//')'         
+         CALL logger_debug("VAR CONCAT: second variable dimensions "//&
+         &  TRIM(cl_tmp) )
+      ELSE
+         tl_var=td_var1
+
+         DEALLOCATE(tl_var%d_value)
+         ! change dimension length
+         tl_var%t_dim(3)%i_len=td_var1%t_dim(3)%i_len+td_var2%t_dim(3)%i_len
+         
+         ALLOCATE(tl_var%d_value(tl_var%t_dim(1)%i_len, &
+         &                       tl_var%t_dim(2)%i_len, &
+         &                       tl_var%t_dim(3)%i_len, &
+         &                       tl_var%t_dim(4)%i_len) )
+
+         ! copy first variable value
+         tl_var%d_value(:,:,1:td_var1%t_dim(3)%i_len,:)= &
+         &  td_var1%d_value(:,:,:,:)
+
+         ! copy second variable value
+         tl_var%d_value(:,:,td_var1%t_dim(3)%i_len+1:tl_var%t_dim(3)%i_len,:)=&
+         &  td_var2%d_value(:,:,:,:)
+
+         ! save result
+         var__concat_k=tl_var
+
+         CALL var_clean(tl_var)
+      ENDIF
+
+   END FUNCTION var__concat_k
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief  This function concatenate variable value following l-direction.
+   !> 
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var1 : variable structure
+   !> @param[in] td_var2 : variable structure
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION var__concat_l(td_var1, td_var2)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR) , INTENT(IN) :: td_var1
+      TYPE(TVAR) , INTENT(IN) :: td_var2
+
+      ! function
+      TYPE(TVAR) :: var__concat_l
+
+      ! local variable
+      TYPE(TVAR)        :: tl_var
+      CHARACTER(LEN=lc) :: cl_tmp
+
+      !----------------------------------------------------------------
+      IF( ANY(td_var1%t_dim(1:3)%i_len /=  td_var2%t_dim(1:3)%i_len) )THEN
+         CALL logger_error("VAR CONCAT: dimension not conform")
+
+         cl_tmp='('//&
+         &           TRIM(fct_str(td_var1%t_dim(1)%i_len))//','//&
+         &           TRIM(fct_str(td_var1%t_dim(2)%i_len))//','//&
+         &           TRIM(fct_str(td_var1%t_dim(3)%i_len))//','//&
+         &           ":"//','//')'
+         CALL logger_debug("VAR CONCAT: first variable dimensions "//&
+         &  TRIM(cl_tmp) )
+         cl_tmp='('//&
+         &           TRIM(fct_str(td_var1%t_dim(1)%i_len))//','//&
+         &           TRIM(fct_str(td_var2%t_dim(2)%i_len))//','//&
+         &           TRIM(fct_str(td_var2%t_dim(3)%i_len))//','//&
+         &           ":"//','//')'         
+         CALL logger_debug("VAR CONCAT: second variable dimensions "//&
+         &  TRIM(cl_tmp) )
+      ELSE
+         tl_var=td_var1
+
+         DEALLOCATE(tl_var%d_value)
+         ! change dimension length
+         tl_var%t_dim(4)%i_len=td_var1%t_dim(4)%i_len+td_var2%t_dim(4)%i_len
+         
+         ALLOCATE(tl_var%d_value(tl_var%t_dim(1)%i_len, &
+         &                       tl_var%t_dim(2)%i_len, &
+         &                       tl_var%t_dim(3)%i_len, &
+         &                       tl_var%t_dim(4)%i_len) )
+
+         ! copy first variable value
+         tl_var%d_value(:,:,1:td_var1%t_dim(4)%i_len,:)= &
+         &  td_var1%d_value(:,:,:,:)
+
+         ! copy second variable value
+         tl_var%d_value(:,:,td_var1%t_dim(4)%i_len+1:tl_var%t_dim(4)%i_len,:)=&
+         &  td_var2%d_value(:,:,:,:)
+
+         ! save result
+         var__concat_l=tl_var
+
+         CALL var_clean(tl_var)
+      ENDIF
+
+   END FUNCTION var__concat_l
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a table of attribute structure 
+   !> in a variable structure.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_att : table of attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__add_att_tab(td_var, td_att)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR),               INTENT(INOUT) :: td_var
+      TYPE(TATT), DIMENSION(:), INTENT(IN)    :: td_att
+
+      ! local variable
+      INTEGER(i4) :: il_natt
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      il_natt=SIZE(td_att(:))
+
+      DO ji=1,il_natt
+         CALL var_add_att(td_var, td_att(ji))
+      ENDDO
+
+   END SUBROUTINE var__add_att_tab
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add an attribute structure 
+   !> in a variable structure.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_att : attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__add_att_unit(td_var, td_att)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+      TYPE(TATT), INTENT(IN)    :: td_att
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_attid
+      TYPE(TATT), DIMENSION(:), ALLOCATABLE :: tl_att
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! check if attribute already in variable structure
+      il_attid=0
+      IF( ASSOCIATED(td_var%t_att) )THEN
+         il_attid=att_get_id( td_var%t_att(:), td_att%c_name )
+      ENDIF
+
+      IF( il_attid /= 0 )THEN
+
+         CALL logger_error( &
+         &  " ADD ATT: attribute "//TRIM(td_att%c_name)//&
+         &  ", already in variable "//TRIM(td_var%c_name) )
+
+         DO ji=1,td_var%i_natt
+            CALL logger_debug( &
+            &  " ADD ATT: in variable "//TRIM(td_var%t_att(ji)%c_name) )
+         ENDDO
+
+      ELSE
+         
+         CALL logger_debug( &
+         &  " ADD ATT: add attribute "//TRIM(td_att%c_name)//&
+         &  ", in variable "//TRIM(td_var%c_name) )
+
+         IF( td_var%i_natt > 0 )THEN
+         ! already other attribute in variable structure
+            ALLOCATE( tl_att(td_var%i_natt), stat=il_status )
+            IF(il_status /= 0 )THEN
+
+               CALL logger_error( &
+               &  " ADD ATT: not enough space to put attributes from "//&
+               &  TRIM(td_var%c_name)//" in temporary attribute structure")
+
+            ELSE
+
+               ! save temporary global attribute's variable structure
+               tl_att(:)=td_var%t_att(:)
+
+               DEALLOCATE( td_var%t_att )
+               ALLOCATE( td_var%t_att(td_var%i_natt+1), stat=il_status )
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( &
+                  &  " ADD ATT: not enough space to put attributes "//&
+                  &  "in variable structure "//TRIM(td_var%c_name) )
+
+               ENDIF
+
+               ! copy attribute in variable before
+               td_var%t_att(1:td_var%i_natt)=tl_att(:)
+
+               DEALLOCATE(tl_att)
+               
+            ENDIF
+         ELSE
+         ! no attribute in variable structure
+            IF( ASSOCIATED(td_var%t_att) )THEN
+               DEALLOCATE(td_var%t_att)
+            ENDIF
+            ALLOCATE( td_var%t_att(td_var%i_natt+1), stat=il_status )
+            IF(il_status /= 0 )THEN
+
+               CALL logger_error( &
+               &  " ADD ATT: not enough space to put attributes "//&
+               &  "in variable structure "//TRIM(td_var%c_name) )
+
+            ENDIF
+         ENDIF
+         ! update number of attribute
+         td_var%i_natt=td_var%i_natt+1
+
+         ! add new attributes
+         td_var%t_att(td_var%i_natt)=td_att
+
+         ! change attribute id
+         DO ji=1,td_var%i_natt
+            td_var%t_att(ji)%i_id=ji
+         ENDDO
+
+         ! highlight some attribute
+         IF( ASSOCIATED(td_var%t_att(td_var%i_natt)%d_value) .OR. &
+           & td_var%t_att(td_var%i_natt)%c_value /= "none" )THEN
+            SELECT CASE(TRIM(td_var%t_att(td_var%i_natt)%c_name))
+
+               CASE("add_offset")
+                  td_var%d_ofs = td_var%t_att(td_var%i_natt)%d_value(1)
+               CASE("scale_factor")
+                  td_var%d_scf = td_var%t_att(td_var%i_natt)%d_value(1)
+               CASE("_FillValue")
+                  td_var%d_fill = td_var%t_att(td_var%i_natt)%d_value(1)
+               CASE("standard_name")
+                  td_var%c_stdname = TRIM(td_var%t_att(td_var%i_natt)%c_value)
+               CASE("units")
+                  td_var%c_units = TRIM(td_var%t_att(td_var%i_natt)%c_value)
+
+            END SELECT
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE var__add_att_unit
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine delete an attribute 
+   !> from variable structure.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_att : attribute structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var_del_att(td_var, td_att)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+      TYPE(TATT), INTENT(IN)    :: td_att
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4) :: il_attid
+      TYPE(TATT), DIMENSION(:), ALLOCATABLE :: tl_att
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! check if attribute already in variable structure
+      il_attid=0
+      IF( ASSOCIATED(td_var%t_att) )THEN
+         il_attid=att_get_id( td_var%t_att(:), td_att%c_name )
+      ENDIF
+
+      IF( il_attid == 0 )THEN
+
+         CALL logger_warn( &
+         &  " DEL ATT: no attribute "//TRIM(td_att%c_name)//&
+         &  ", in variable "//TRIM(td_var%c_name) )
+
+      ELSE
+         
+         CALL logger_debug( &
+         &  " DEL ATT: del attribute "//TRIM(td_att%c_name)//&
+         &  ", in var "//TRIM(td_var%c_name) )
+
+         IF( td_var%i_natt == 1 )THEN
+
+            DEALLOCATE(td_var%t_att)
+
+            ! new number of attribute in variable
+            td_var%i_natt=td_var%i_natt-1
+
+         ELSE
+            ALLOCATE( tl_att(td_var%i_natt-1), stat=il_status )
+            IF(il_status /= 0 )THEN
+
+               CALL logger_error( &
+               &  " ADD ATT: not enough space to put attributes from "//&
+               &  TRIM(td_var%c_name)//" in temporary attribute structure")
+
+            ELSE
+
+               ! save temporary global attribute's variable structure
+               tl_att(1:il_attid-1)=td_var%t_att(1:il_attid-1)
+               IF( il_attid < td_var%i_natt )THEN
+                  tl_att(il_attid:)=td_var%t_att(il_attid+1:)
+               ENDIF
+
+               DEALLOCATE( td_var%t_att )
+
+               ! new number of attribute in variable
+               td_var%i_natt=td_var%i_natt-1
+
+               ALLOCATE( td_var%t_att(td_var%i_natt), stat=il_status )
+               IF(il_status /= 0 )THEN
+
+                  CALL logger_error( &
+                  &  " ADD ATT: not enough space to put attributes "//&
+                  &  "in variable structure "//TRIM(td_var%c_name) )
+
+               ENDIF
+
+               ! copy attribute in variable before
+               td_var%t_att(1:td_var%i_natt)=tl_att(:)
+
+               ! change attribute id
+               DO ji=1,td_var%i_natt
+                  td_var%t_att(ji)%i_id=ji
+               ENDDO
+
+               DEALLOCATE(tl_att)
+            ENDIF 
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE var_del_att
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine move a global attribute structure 
+   !> from variable structure.
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_att : attribute structure
+   !> @todo
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var_move_att(td_var, td_att)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+      TYPE(TATT), INTENT(IN)    :: td_att
+
+      ! local variable
+      TYPE(TATT) :: tl_att
+
+      !----------------------------------------------------------------
+      ! copy attribute
+      tl_att=td_att
+
+      ! remove attribute with same name
+      CALL var_del_att(td_var, tl_att)
+
+      ! add new attribute
+      CALL var_add_att(td_var, tl_att)
+
+   END SUBROUTINE var_move_att
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a table of dimension structure in a variable 
+   !> structure.
+   !> - number of dimension in variable can't be greater than 4
+   !> - dimension can't be already uses in variable structure
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_dim : dimension structure
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__add_dim_tab(td_var, td_dim)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR),               INTENT(INOUT) :: td_var
+      TYPE(TDIM), DIMENSION(:), INTENT(IN)    :: td_dim
+
+      ! local variable
+      INTEGER(i4) :: il_ndim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      il_ndim=SIZE(td_dim(:))
+      IF( il_ndim <= 4 )THEN
+
+         DO ji=1,il_ndim
+            CALL var_add_dim(td_var, td_dim(ji))
+         ENDDO
+
+      ELSE
+         CALL logger_error( &
+         &  " ADD DIM: too much dimension to put in structure "//&
+         &  "("//TRIM(fct_str(il_ndim))//")" )
+      ENDIF
+
+   END SUBROUTINE var__add_dim_tab
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add one dimension in a variable 
+   !> structure, after some check.
+   !> - number of dimension in variable can't be greater than 4
+   !> - dimension can't be already uses in variable structure 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_dim : dimension structure
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__add_dim_unit(td_var, td_dim)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+      TYPE(TDIM), INTENT(IN) :: td_dim
+
+      ! local variable
+      INTEGER(i4) :: il_dimid
+      !----------------------------------------------------------------
+      IF( td_var%i_ndim <= 4 )THEN
+
+         ! check if dimension already used in variable structure
+         il_dimid=dim_get_id( td_var%t_dim(:), td_dim%c_name, td_dim%c_sname )
+
+         IF( il_dimid == 0 )THEN
+
+               ! add dimension
+               CALL var__add_dim(td_var, td_dim)
+
+         ELSE
+
+            IF( td_var%t_dim(il_dimid)%l_use )THEN
+
+               CALL logger_error( &
+               &  " ADD DIM: dimension "//TRIM(td_dim%c_name)//&
+               &  ", short name "//TRIM(td_dim%c_sname)//&
+               &  ", already used in variable "//TRIM(td_var%c_name) )
+            ELSE
+               ! add dimension
+               CALL var__add_dim(td_var, td_dim)
+            ENDIF
+
+         ENDIF
+
+      ELSE
+         CALL logger_error( &
+         &  " ADD DIM: too much dimension in variable "//&
+         &  TRIM(td_var%c_name)//" ("//TRIM(fct_str(td_var%i_ndim))//")")
+      ENDIF
+
+   END SUBROUTINE var__add_dim_unit
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a dimension structure in a variable 
+   !> structure.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_dim : dimension structure
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__add_dim(td_var, td_dim)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+      TYPE(TDIM), INTENT(IN) :: td_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      CALL logger_info( &
+      &  " ADD DIM: add dimension "//TRIM(td_dim%c_name)//&
+      &  ", short name "//TRIM(td_dim%c_sname)//&
+      &  ", length "//TRIM(fct_str(td_dim%i_len))//&
+      &  ", in variable "//TRIM(td_var%c_name) )
+
+      ! if dimension order already changed
+      IF( ANY(td_var%t_dim(:)%i_xyzt2 /= 0 ) )THEN
+         ! unordered dimension structure
+         CALL dim_unorder(td_var%t_dim(:))
+      ENDIF
+
+      ! search unused dimension
+      DO ji=1,ip_maxdim
+         IF( .NOT. td_var%t_dim(ji)%l_use )THEN
+            ! add new dimension
+            td_var%t_dim(ji)=td_dim
+            td_var%t_dim(ji)%i_id=ji
+            !!td_var%t_dim(ji)%l_use=.TRUE.
+            IF( td_var%t_dim(ji)%l_use )THEN
+               ! update number of attribute
+               td_var%i_ndim=td_var%i_ndim+1
+            ENDIF
+            EXIT
+         ENDIF
+      ENDDO
+
+      ! reorder dimension to ('x','y','z','t')
+      CALL dim_reorder(td_var%t_dim(:))
+
+   END SUBROUTINE var__add_dim
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine delete a dimension structure in a variable 
+   !> structure.<br/>
+   !
+   !> @warning delete variable value too
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_dim : dimension structure
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var_del_dim(td_var, td_dim)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+      TYPE(TDIM), INTENT(IN) :: td_dim
+
+      ! local variable
+      INTEGER(i4) :: il_dimid
+      TYPE(TDIM)  :: tl_dim ! empty dimension structure
+
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_shape
+
+      !----------------------------------------------------------------
+      IF( td_var%i_ndim <= 4 )THEN
+
+         ! check if dimension already in variable structure
+         il_dimid=dim_get_id( td_var%t_dim(:), td_dim%c_name, td_dim%c_sname )
+         IF( il_dimid == 0 )THEN
+
+            CALL logger_warn( &
+            &  " DEL DIM: no dimension "//TRIM(td_dim%c_name)//&
+            &  ", short name "//TRIM(td_dim%c_sname)//&
+            &  ", in variable "//TRIM(td_var%c_name) )
+
+         ELSE
+
+            CALL logger_debug( &
+            &  " DEL DIM: delete dimension "//TRIM(td_dim%c_name)//&
+            &  ", short name "//TRIM(td_dim%c_sname)//&
+            &  ", in variable "//TRIM(td_var%c_name)//&
+            &  " id "//TRIM(fct_str(il_dimid)) )
+
+            ! replace dimension by empty one
+            td_var%t_dim(il_dimid)=tl_dim
+
+            ! update number of dimension
+            td_var%i_ndim=td_var%i_ndim-1
+
+            IF( ASSOCIATED(td_var%d_value) )THEN
+               il_shape(:)=SHAPE(td_var%d_value(:,:,:,:))
+               IF(il_shape(il_dimid)/=td_dim%i_len)THEN
+                  CALL logger_warn("VAR DEL DIM: remove value of variable "//&
+                  &  TRIM(td_var%c_name) )
+                  CALL var_del_value(td_var)
+               ENDIF
+            ENDIF
+
+            ! reorder dimension to ('x','y','z','t')
+            CALL dim_reorder(td_var%t_dim)
+
+         ENDIF
+      ELSE
+         CALL logger_error( &
+         &  " DEL DIM: too much dimension in variable "//&
+         &  TRIM(td_var%c_name)//" ("//TRIM(fct_str(td_var%i_ndim))//")")
+      ENDIF
+
+   END SUBROUTINE var_del_dim
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine move a dimension structure 
+   !> in variable structure.
+   !>
+   !> @warning 
+   !> - dimension order could be changed
+   !> - delete variable value 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] td_dim : dimension structure
+   !> @todo
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var_move_dim(td_var, td_dim)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+      TYPE(TDIM), INTENT(IN)    :: td_dim
+
+      ! local variable
+      TYPE(TDIM) :: tl_dim
+      !----------------------------------------------------------------
+
+      ! copy dimension
+      tl_dim=td_dim
+
+      ! remove dimension with same name
+      CALL var_del_dim(td_var, tl_dim)
+
+      ! add new dimension
+      CALL var_add_dim(td_var, tl_dim)
+
+   END SUBROUTINE var_move_dim
+   !> @endcode    
+   !-------------------------------------------------------------------
+   !> @brief This subroutine print variable information.</br/>
+   !> If ld_more is TRUE (default), print information about variable dimensions
+   !> and variable attributes.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var : variable structure
+   !> @param[in] ld_more : print more infomration about variable
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var_print(td_var, ld_more)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TVAR), INTENT(IN) :: td_var
+      LOGICAL,    INTENT(IN), OPTIONAL :: ld_more
+
+      ! local vairbale
+      CHARACTER(LEN=lc) :: cl_type
+      REAL(dp)          :: dl_min
+      REAL(dp)          :: dl_max
+      LOGICAL           :: ll_more
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ll_more=.TRUE.
+      IF( PRESENT(ld_more) )THEN
+         ll_more=ld_more
+      ENDIF
+
+      SELECT CASE( td_var%i_type )
+
+         CASE(NF90_CHAR)
+            cl_type='CHAR'
+         CASE(NF90_BYTE)
+            cl_type='BYTE'
+         CASE(NF90_SHORT)
+            cl_type='SHORT'
+         CASE(NF90_INT)
+            cl_type='INT'
+         CASE(NF90_FLOAT)
+            cl_type='FLOAT'
+         CASE(NF90_DOUBLE)
+            cl_type='DOUBLE'
+         CASE DEFAULT
+            !cl_type='unknown'
+            cl_type=''
+      END SELECT      
+
+      IF( ASSOCIATED(td_var%d_value) )THEN
+         WRITE(*,*) "ASSOCIATED"
+         dl_min=MINVAL(td_var%d_value(:,:,:,:), &
+         &             mask=(td_var%d_value(:,:,:,:)/=td_var%d_fill) )&
+         &      *td_var%d_scf+td_var%d_ofs
+         dl_max=MAXVAL(td_var%d_value(:,:,:,:), &
+         &             mask=(td_var%d_value(:,:,:,:)/=td_var%d_fill) )&
+         &      *td_var%d_scf+td_var%d_ofs
+      ELSE
+         WRITE(*,*) "NOT ASSOCIATED"
+         dl_min=0.
+         dl_max=0.
+      ENDIF
+
+      WRITE(*,'((a,a),3(/3x,a,a),3(/3x,a,i3),&
+      &         (/3x,a,a),5(/3x,a,ES12.4))')&
+      &        " Variable : ",TRIM(td_var%c_name),    &
+      &        " standard name : ",TRIM(td_var%c_stdname), &
+      &        " units         : ",TRIM(td_var%c_units),   &
+      &        " point         : ",TRIM(td_var%c_point),   &
+      &        " id            : ",td_var%i_id,            &
+      &        " ndim          : ",td_var%i_ndim,          &
+      &        " natt          : ",td_var%i_natt,          &
+      &        " type          : ",TRIM(cl_type),          &
+      &        " scale factor  : ",td_var%d_scf,           &
+      &        " add offset    : ",td_var%d_ofs,           &
+      &        " _FillValue    : ",td_var%d_fill,          &
+      &        " min value     : ",dl_min,                 &        
+      &        " max value     : ",dl_max
+
+      IF( ll_more )THEN
+         ! print dimension
+         IF(  td_var%i_ndim /= 0 )THEN
+            WRITE(*,'(/a)') " Variable dimension"
+            DO ji=1,ip_maxdim
+               IF( td_var%t_dim(ji)%l_use )THEN
+                  CALL dim_print(td_var%t_dim(ji))
+               ENDIF
+            ENDDO
+         ENDIF
+
+         ! print attribute
+         IF( td_var%i_natt /= 0 )THEN
+            WRITE(*,'(/a)') " Variable attribute"
+            DO ji=1,td_var%i_natt
+               CALL att_print(td_var%t_att(ji))
+            ENDDO
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE var_print
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a 4D table of double value in a variable 
+   !> structure.
+   !>
+   !> @warning Dimension of the table must be ordered as ('x','y','z','t')
+   !
+   !> @details 
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given. 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] dd_value : table of variable value
+   !> @param[in] id_start : index in the variable from which the data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__add_value(td_var, dd_value, id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR),                        INTENT(INOUT) :: td_var
+      REAL(dp),    DIMENSION(:,:,:,:),   INTENT(IN)    :: dd_value
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_start
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_count
+
+      ! local variable
+      INTEGER(i4) :: il_status
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_start
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_count
+      INTEGER(i4), DIMENSION(ip_maxdim) :: il_shape
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ! check id_count and id_start optionals parameters...
+      IF( (       PRESENT(id_start)  .AND. (.NOT. PRESENT(id_count))) .OR. &
+          ((.NOT. PRESENT(id_start)) .AND.        PRESENT(id_count) ) )THEN
+         CALL logger_warn( &
+         &  " ADD VALUE: id_start and id_count should be both specified")
+      ENDIF
+
+      IF( PRESENT(id_start).AND.PRESENT(id_count) )THEN
+
+         ! keep ordered table ('x','y','z','t')
+         il_start(:)=id_start(:)
+         il_count(:)=id_count(:)
+
+      ELSE
+
+         ! keep ordered table ('x','y','z','t')
+         il_start(:)=(/1,1,1,1/)
+         il_count(:)=td_var%t_dim(:)%i_len
+
+      ENDIF
+
+      ! check dimension of input table
+      il_shape(:)=SHAPE(dd_value(:,:,:,:))
+      IF(.NOT.ALL( il_count(:) == il_shape(:)) )THEN
+         CALL logger_error( &
+         &  " ADD VALUE: dimension of input table, and count table differ " )
+
+         CALL logger_debug(" ADD VALUE: check dimension order !!")
+         DO ji = 1, ip_maxdim
+            CALL logger_debug( &
+            &  " ADD VALUE: count : "//TRIM(fct_str(il_count(ji)))//&
+            &  " table dimension : "//TRIM(fct_str(il_shape(ji))))
+         ENDDO
+
+      ELSE
+
+         ! check dimension of variable
+         IF(.NOT.ALL(il_start(:)+il_count(:)-1 <= td_var%t_dim(:)%i_len) )THEN
+            CALL logger_error( &
+            &  " ADD VALUE: start + count exceed variable dimension. " )
+
+            CALL logger_debug(" ADD VALUE: check dimension order !!")
+            DO ji = 1, ip_maxdim
+               CALL logger_debug( &
+               &  " ADD VALUE: start ("//TRIM(fct_str(il_start(ji)))//") "//&
+               &  "+ count ("//TRIM(fct_str(il_count(ji)))//") "//&
+               &  "variable dimension "//TRIM(fct_str(td_var%t_dim(ji)%i_len)))
+            ENDDO
+
+         ELSE
+
+            ! special case for scalar variable
+            IF( td_var%i_ndim == 0 )THEN
+               ! reorder dimension to ('x','y','z','t')
+               CALL dim_reorder(td_var%t_dim)
+            ENDIF
+
+            IF( ASSOCIATED(td_var%d_value) )THEN
+
+               CALL logger_warn( &
+               &  " ADD VALUE: value already in variable "//&
+               &  TRIM(td_var%c_name)//&
+               &  " (standard name "//TRIM(td_var%c_stdname)//")" )
+
+            ELSE
+
+               ! Allocate space to hold variable value in structure
+               ALLOCATE(td_var%d_value( td_var%t_dim(1)%i_len, &
+               &                        td_var%t_dim(2)%i_len, &
+               &                        td_var%t_dim(3)%i_len, &
+               &                        td_var%t_dim(4)%i_len),&
+               &        stat=il_status)
+               IF(il_status /= 0 )THEN
+
+                 CALL logger_error( &
+                  &  " ADD VALUE: not enough space to put variable "//&
+                  &  TRIM(td_var%c_name)//&
+                  &  " in variable structure")
+
+               ENDIF
+               
+               ! initialise table
+               CALL logger_info( &
+               &  " ADD VALUE: value in variable "//TRIM(td_var%c_name)//&
+               &  ", initialise to FillValue "//TRIM(fct_str(td_var%d_fill)) )
+               td_var%d_value(:,:,:,:)=td_var%d_fill
+
+            ENDIF
+
+            CALL logger_info( &
+            &  " ADD VALUE: put value in variable "//TRIM(td_var%c_name)//&
+            &  " (standard name "//TRIM(td_var%c_stdname)//")" )
+
+            ! put value in variable structure
+            td_var%d_value( il_start(1):il_start(1)+il_count(1)-1, &
+            &               il_start(2):il_start(2)+il_count(2)-1, &
+            &               il_start(3):il_start(3)+il_count(3)-1, &
+            &               il_start(4):il_start(4)+il_count(4)-1 ) = dd_value(:,:,:,:)
+
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE var__add_value
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a 4D table of real(8) value in a variable 
+   !> structure. Dimension of the table must be ordered as ('x','y','z','t')
+   !
+   !> @details 
+   !> indices of the variable where value will be written could be specify
+   !> with start and count table.
+   !>
+   !> @note variable type is forced to DOUBLE
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] dd_value : table of variable value
+   !> @param[in] id_start : start indices of the variable where data values 
+   !> will be written
+   !> @param[in] id_count : number of indices selected along each dimension
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__add_value_dp(td_var, dd_value, id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR),                        INTENT(INOUT) :: td_var
+      REAL(dp),    DIMENSION(:,:,:,:),   INTENT(IN)    :: dd_value
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_start
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_count
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_type
+      !----------------------------------------------------------------
+
+      IF( td_var%i_type == 0 )THEN
+         td_var%i_type=NF90_DOUBLE
+      ELSE
+         cl_type=''
+         SELECT CASE(td_var%i_type)
+         CASE(NF90_DOUBLE)
+            cl_type='DOUBLE'
+         CASE(NF90_FLOAT)
+            cl_type='FLOAT'
+         CASE(NF90_INT)
+            cl_type='INT'
+         CASE(NF90_SHORT)
+            cl_type='SHORT'
+         CASE(NF90_BYTE)
+            cl_type='BYTE'
+         END SELECT
+         CALL logger_info("VAR ADD VALUE: "//TRIM(td_var%c_name)//&
+         &                " value will be saved as "//TRIM(cl_type)) 
+      ENDIF
+
+      CALL var__add_value(td_var, dd_value, id_start, id_count)
+
+   END SUBROUTINE var__add_value_dp
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a 4D table of real value in a variable 
+   !> structure. Dimension of the table must be ordered as ('x','y','z','t')
+   !
+   !> @details 
+   !> indices of the variable where value will be written could be specify
+   !> wiht start and count table.   
+   !>
+   !> @note variable type is forced to FLOAT
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] rd_value : table of variable value
+   !> @param[in] id_start : start indices of the variable where data values 
+   !> will be written
+   !> @param[in] id_count : number of indices selected along each dimension
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__add_value_rp(td_var, rd_value, id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR),                        INTENT(INOUT) :: td_var
+      REAL(sp),    DIMENSION(:,:,:,:),   INTENT(IN)    :: rd_value
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_start
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_count
+
+      ! local variable
+      CHARACTER(LEN=lc)                                    :: cl_type
+
+      INTEGER(i4)                                          :: il_status
+      INTEGER(i4)      , DIMENSION(ip_maxdim)              :: il_shape
+
+      REAL(dp)         , DIMENSION(:,:,:,:)  , ALLOCATABLE :: dl_value
+      !----------------------------------------------------------------
+
+      IF( td_var%i_type == 0 )THEN
+         td_var%i_type=NF90_FLOAT
+      ELSE
+         cl_type=''
+         SELECT CASE(td_var%i_type)
+         CASE(NF90_DOUBLE)
+            cl_type='DOUBLE'
+         CASE(NF90_FLOAT)
+            cl_type='FLOAT'
+         CASE(NF90_INT)
+            cl_type='INT'
+         CASE(NF90_SHORT)
+            cl_type='SHORT'
+         CASE(NF90_BYTE)
+            cl_type='BYTE'
+         END SELECT
+         CALL logger_info("VAR ADD VALUE: "//TRIM(td_var%c_name)//&
+         &                " value will be saved as "//TRIM(cl_type)) 
+      ENDIF      
+
+      il_shape=SHAPE(rd_value)
+      ALLOCATE( dl_value(il_shape(1), il_shape(2), il_shape(3), il_shape(4)),&
+      &         stat=il_status)
+      IF(il_status /= 0 )THEN
+
+        CALL logger_error( &
+         &  " ADD VALUE: not enough space to put variable "//&
+         &  TRIM(td_var%c_name)//&
+         &  " in variable structure")
+
+      ENDIF
+      dl_value(:,:,:,:)=REAL(rd_value(:,:,:,:), dp)
+      
+      CALL var__add_value(td_var, dl_value(:,:,:,:), id_start(:), id_count(:))
+
+      DEALLOCATE(dl_value)
+
+   END SUBROUTINE var__add_value_rp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a 4D table of integer(1) value in a variable 
+   !> structure. Dimension of the table must be ordered as ('x','y','z','t')
+   !
+   !> @details 
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given.   
+   !>
+   !> @note variable type is forced to BYTE
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variabele structure
+   !> @param[in] bd_value : table of variable value
+   !> @param[in] id_start : start indices of the variable where data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__add_value_i1(td_var, bd_value, id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR),                        INTENT(INOUT) :: td_var
+      INTEGER(i1), DIMENSION(:,:,:,:),   INTENT(IN)    :: bd_value
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_start
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_count
+
+      ! local variable
+      CHARACTER(LEN=lc)                                    :: cl_type
+
+      INTEGER(i4)                                          :: il_status
+      INTEGER(i4)      , DIMENSION(ip_maxdim)              :: il_shape
+
+      REAL(dp)         , DIMENSION(:,:,:,:)  , ALLOCATABLE :: dl_value
+      !----------------------------------------------------------------
+
+      IF( td_var%i_type == 0 )THEN
+         td_var%i_type=NF90_BYTE
+      ELSE
+         cl_type=''
+         SELECT CASE(td_var%i_type)
+         CASE(NF90_DOUBLE)
+            cl_type='DOUBLE'
+         CASE(NF90_FLOAT)
+            cl_type='FLOAT'
+         CASE(NF90_INT)
+            cl_type='INT'
+         CASE(NF90_SHORT)
+            cl_type='SHORT'
+         CASE(NF90_BYTE)
+            cl_type='BYTE'
+         END SELECT
+         CALL logger_info("VAR ADD VALUE: "//TRIM(td_var%c_name)//&
+         &                " value will be saved as "//TRIM(cl_type)) 
+      ENDIF
+
+      il_shape=SHAPE(bd_value)
+      ALLOCATE( dl_value(il_shape(1), il_shape(2), il_shape(3), il_shape(4)),&
+      &         stat=il_status)
+      IF(il_status /= 0 )THEN
+
+        CALL logger_error( &
+         &  " ADD VALUE: not enough space to put variable "//&
+         &  TRIM(td_var%c_name)//&
+         &  " in variable structure")
+
+      ENDIF
+      dl_value(:,:,:,:)=REAL(bd_value(:,:,:,:),dp)      
+
+      CALL var__add_value(td_var, dl_value(:,:,:,:), id_start(:), id_count(:))
+
+      DEALLOCATE(dl_value)
+
+   END SUBROUTINE var__add_value_i1
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a 4D table of integer(1) value in a variable 
+   !> structure. Dimension of the table must be ordered as ('x','y','z','t')
+   !
+   !> @details 
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given.   
+   !>
+   !> @note variable type is forced to SHORT
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variabele structure
+   !> @param[in] sd_value : table of variable value
+   !> @param[in] id_start : start indices of the variable where data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__add_value_i2(td_var, sd_value, id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR),                        INTENT(INOUT) :: td_var
+      INTEGER(i2), DIMENSION(:,:,:,:),   INTENT(IN)    :: sd_value
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_start
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_count
+
+      ! local variable
+      CHARACTER(LEN=lc)                                    :: cl_type
+
+      INTEGER(i4)                                          :: il_status
+      INTEGER(i4)      , DIMENSION(ip_maxdim)              :: il_shape
+
+      REAL(dp)         , DIMENSION(:,:,:,:)  , ALLOCATABLE :: dl_value
+      !----------------------------------------------------------------
+
+      IF( td_var%i_type == 0 )THEN
+         td_var%i_type=NF90_SHORT
+      ELSE
+         cl_type=''
+         SELECT CASE(td_var%i_type)
+         CASE(NF90_DOUBLE)
+            cl_type='DOUBLE'
+         CASE(NF90_FLOAT)
+            cl_type='FLOAT'
+         CASE(NF90_INT)
+            cl_type='INT'
+         CASE(NF90_SHORT)
+            cl_type='SHORT'
+         CASE(NF90_BYTE)
+            cl_type='BYTE'
+         END SELECT
+         CALL logger_info("VAR ADD VALUE: "//TRIM(td_var%c_name)//&
+         &                " value will be saved as "//TRIM(cl_type)) 
+      ENDIF
+
+      il_shape=SHAPE(sd_value)
+      ALLOCATE( dl_value(il_shape(1), il_shape(2), il_shape(3), il_shape(4)),&
+      &         stat=il_status)
+      IF(il_status /= 0 )THEN
+
+        CALL logger_error( &
+         &  " ADD VALUE: not enough space to put variable "//&
+         &  TRIM(td_var%c_name)//&
+         &  " in variable structure")
+
+      ENDIF
+      dl_value(:,:,:,:)=REAL(sd_value(:,:,:,:),dp)      
+
+      CALL var__add_value(td_var, dl_value(:,:,:,:), id_start(:), id_count(:))
+
+      DEALLOCATE(dl_value)
+
+   END SUBROUTINE var__add_value_i2
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a 4D table of integer(4) value in a variable 
+   !> structure. Dimension of the table must be ordered as ('x','y','z','t')
+   !
+   !> @details 
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given.   
+   !>
+   !> @note variable type is forced to INT
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variabele structure
+   !> @param[in] id_value : table of variable value
+   !> @param[in] id_start : start indices of the variable where data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__add_value_i4(td_var, id_value, id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR),                        INTENT(INOUT) :: td_var
+      INTEGER(i4), DIMENSION(:,:,:,:),   INTENT(IN)    :: id_value
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_start
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_count
+
+      ! local variable
+      CHARACTER(LEN=lc)                                    :: cl_type
+
+      INTEGER(i4)                                          :: il_status
+      INTEGER(i4)      , DIMENSION(ip_maxdim)              :: il_shape
+
+      REAL(dp)         , DIMENSION(:,:,:,:)  , ALLOCATABLE :: dl_value
+      !----------------------------------------------------------------
+
+      IF( td_var%i_type == 0 )THEN
+         td_var%i_type=NF90_INT
+      ELSE
+         cl_type=''
+         SELECT CASE(td_var%i_type)
+         CASE(NF90_DOUBLE)
+            cl_type='DOUBLE'
+         CASE(NF90_FLOAT)
+            cl_type='FLOAT'
+         CASE(NF90_INT)
+            cl_type='INT'
+         CASE(NF90_SHORT)
+            cl_type='SHORT'
+         CASE(NF90_BYTE)
+            cl_type='BYTE'
+         END SELECT
+         CALL logger_info("VAR ADD VALUE: "//TRIM(td_var%c_name)//&
+         &                " value will be saved as "//TRIM(cl_type)) 
+      ENDIF
+
+      il_shape=SHAPE(id_value)
+      ALLOCATE( dl_value(il_shape(1), il_shape(2), il_shape(3), il_shape(4)),&
+      &         stat=il_status)
+      IF(il_status /= 0 )THEN
+
+        CALL logger_error( &
+         &  " ADD VALUE: not enough space to put variable "//&
+         &  TRIM(td_var%c_name)//&
+         &  " in variable structure")
+
+      ENDIF
+      dl_value(:,:,:,:)=REAL(id_value(:,:,:,:),dp)      
+
+      CALL var__add_value(td_var, dl_value(:,:,:,:), id_start(:), id_count(:))
+
+      DEALLOCATE(dl_value)
+
+   END SUBROUTINE var__add_value_i4
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine add a 4D table of integer(4) value in a variable 
+   !> structure. Dimension of the table must be ordered as ('x','y','z','t')
+   !
+   !> @details 
+   !> indices in the variable where value will be written could be specify if
+   !> start and count table are given.   
+   !>
+   !> @note variable type is forced to INT
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] kd_value : table of variable value
+   !> @param[in] id_start : start indices of the variable where data values 
+   !> will be read
+   !> @param[in] id_count : number of indices selected along each dimension
+   !
+   !> @todo 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__add_value_i8(td_var, kd_value, id_start, id_count)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR),                        INTENT(INOUT) :: td_var
+      INTEGER(i8), DIMENSION(:,:,:,:),   INTENT(IN)    :: kd_value
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_start
+      INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN),   OPTIONAL  :: id_count
+
+      ! local variable
+      CHARACTER(LEN=lc)                                    :: cl_type
+
+      INTEGER(i4)                                          :: il_status
+      INTEGER(i4)      , DIMENSION(ip_maxdim)              :: il_shape
+
+      REAL(dp)         , DIMENSION(:,:,:,:)  , ALLOCATABLE :: dl_value
+      !----------------------------------------------------------------
+
+      IF( td_var%i_type == 0 )THEN
+         td_var%i_type=NF90_INT
+      ELSE
+         cl_type=''
+         SELECT CASE(td_var%i_type)
+         CASE(NF90_DOUBLE)
+            cl_type='DOUBLE'
+         CASE(NF90_FLOAT)
+            cl_type='FLOAT'
+         CASE(NF90_INT)
+            cl_type='INT'
+         CASE(NF90_SHORT)
+            cl_type='SHORT'
+         CASE(NF90_BYTE)
+            cl_type='BYTE'
+         END SELECT
+         CALL logger_info("VAR ADD VALUE: "//TRIM(td_var%c_name)//&
+         &                " value will be saved as "//TRIM(cl_type)) 
+      ENDIF
+
+      il_shape=SHAPE(kd_value)
+      ALLOCATE( dl_value(il_shape(1), il_shape(2), il_shape(3), il_shape(4)),&
+      &         stat=il_status)
+      IF(il_status /= 0 )THEN
+
+        CALL logger_error( &
+         &  " ADD VALUE: not enough space to put variable "//&
+         &  TRIM(td_var%c_name)//&
+         &  " in variable structure")
+
+      ENDIF
+      dl_value(:,:,:,:)=REAL(kd_value(:,:,:,:),dp)
+
+      CALL var__add_value(td_var, dl_value, id_start, id_count)
+
+      DEALLOCATE(dl_value)
+
+   END SUBROUTINE var__add_value_i8
+   !> @endcode   
+   !-------------------------------------------------------------------
+   !> @brief This subroutine remove variable value in a variable 
+   !> structure.
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var_del_value(td_var)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+
+      !----------------------------------------------------------------
+      CALL logger_warn( &
+      &  " DEL VALUE: value in variable "//TRIM(td_var%c_name)//&
+      &  ", standard name "//TRIM(td_var%c_stdname)//&
+      &  " will be remove ")
+
+      DEALLOCATE(td_var%d_value)
+
+   END SUBROUTINE var_del_value
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function return the variable id, in a table of variable
+   !> structure,  given variable name or standard name 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var : table of variable structure
+   !> @param[in] cd_name : variable name
+   !> @param[in] cd_stdname : variable standard name
+   !> @return variable id in table of variable structure (0 if not found)
+   !-------------------------------------------------------------------
+   !> @code
+   INTEGER(i4) FUNCTION var_get_id(td_var, cd_name, cd_stdname)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR)      , DIMENSION(:), INTENT(IN) :: td_var
+      CHARACTER(LEN=*),               INTENT(IN) :: cd_name
+      CHARACTER(LEN=*),               INTENT(IN), OPTIONAL :: cd_stdname
+
+      ! local variable
+      INTEGER(i4) :: il_size
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      var_get_id=0
+      il_size=SIZE(td_var(:))
+
+      ! check if variable is in table of variable structure
+      DO ji=1,il_size
+         ! look for variable name
+         IF( fct_lower(td_var(ji)%c_name) == fct_lower(cd_name) )THEN
+         
+            var_get_id=ji
+            EXIT
+
+         ! look for variable standard name
+         ELSE IF( fct_lower(td_var(ji)%c_stdname) == fct_lower(cd_name) .AND.&
+         &    TRIM(fct_lower(td_var(ji)%c_stdname)) /= '' )THEN
+         !&    TRIM(ADJUSTL(cd_stdname)) /= 'unknown' )THEN
+            
+            var_get_id=ji
+            EXIT
+
+         ELSE IF( PRESENT(cd_stdname) )THEN 
+            IF( fct_lower(td_var(ji)%c_stdname) == fct_lower(cd_stdname) .AND.&
+            &    TRIM(fct_lower(td_var(ji)%c_stdname)) /= '' )THEN
+            !&    TRIM(ADJUSTL(cd_stdname)) /= 'unknown' )THEN
+            
+               var_get_id=ji
+               EXIT
+            ENDIF
+         ENDIF
+
+      ENDDO
+
+   END FUNCTION var_get_id
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function return the mask of variable, given variable structure 
+   !> @detail
+   !> 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var : table of variable structure
+   !> @return variable id in table of variable structure
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION var_get_mask(td_var)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR), INTENT(IN) :: td_var
+
+      ! function
+      !INTEGER(i4), DIMENSION(:,:), POINTER :: var_get_mask
+      INTEGER(i4), DIMENSION(td_var%t_dim(1)%i_len, &
+      &                      td_var%t_dim(2)%i_len) :: var_get_mask
+
+      ! local variable
+      !----------------------------------------------------------------
+      IF( ASSOCIATED(td_var%d_value) )THEN
+
+         CALL logger_trace( "GET MASK: create mask from variable "//&
+         &               TRIM(td_var%c_name) )
+         var_get_mask(:,:)=1
+         WHERE( td_var%d_value(:,:,1,1) == td_var%d_fill )
+            var_get_mask(:,:)=0
+         ENDWHERE
+
+      ELSE
+         CALL logger_error("GET MASK: variable value not define.")
+      ENDIF
+   END FUNCTION var_get_mask
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine change Fill Value of the variable to 
+   !> standard NETCDF Fill Value 
+   !> @detail
+   !> 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : table of variable structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var_chg_FillValue(td_var)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+
+      ! local variable
+      TYPE(TATT) :: tl_att
+      !----------------------------------------------------------------
+
+      CALL logger_debug( "CHG FILL VALUE: change _FillValue in variable "//&
+      &  TRIM(td_var%c_name) )
+
+      ! define attribute FillValue
+      SELECT CASE( td_var%i_type )
+
+         CASE(NF90_BYTE)
+            tl_att=att_init('_FillValue',NF90_FILL_BYTE)
+         CASE(NF90_SHORT)
+            tl_att=att_init('_FillValue',NF90_FILL_SHORT)
+         CASE(NF90_INT)
+            tl_att=att_init('_FillValue',NF90_FILL_INT)
+         CASE(NF90_FLOAT)
+            tl_att=att_init('_FillValue',NF90_FILL_FLOAT)
+         CASE(NF90_DOUBLE)
+            tl_att=att_init('_FillValue',NF90_FILL_DOUBLE)
+         CASE DEFAULT
+            tl_att=att_init('_FillValue',NF90_FILL_DOUBLE)
+
+      END SELECT
+
+      IF( ASSOCIATED(td_var%d_value) )THEN
+         ! change FillValue in variable value
+         WHERE( td_var%d_value(:,:,:,:) == td_var%d_fill )
+            td_var%d_value(:,:,:,:)=tl_att%d_value(1)
+         END WHERE
+      ENDIF
+
+      ! change attribute _FillValue
+      CALL var_move_att(td_var, tl_att)
+
+   END SUBROUTINE var_chg_FillValue
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine read variable configuration file, fill and save 
+   !> a global table of variable structure with extra information :tg_varextra.
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_file : configuration file of variable
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var_def_extra( cd_file )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN) :: cd_file
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_line
+      CHARACTER(LEN=lc) :: cl_interp
+
+      INTEGER(i4)       :: il_nvar
+      INTEGER(i4)       :: il_fileid
+      INTEGER(i4)       :: il_status
+
+      LOGICAL           :: ll_exist
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( ALLOCATED(tg_varextra) ) DEALLOCATE(tg_varextra)
+
+      ! read config variable file
+      INQUIRE(FILE=TRIM(cd_file), EXIST=ll_exist)
+      IF( ll_exist )THEN
+         
+         ! get number of variable to be read
+         il_fileid=fct_getunit()
+
+         CALL logger_debug("VAR DEF EXTRA: open "//TRIM(cd_file))
+         OPEN( il_fileid, FILE=TRIM(cd_file), &
+         &                FORM='FORMATTED',   &
+         &                ACCESS='SEQUENTIAL',&
+         &                STATUS='OLD',       &
+         &                ACTION='READ',      &
+         &                IOSTAT=il_status)
+         CALL fct_err(il_status)
+         IF( il_status /= 0 )THEN
+            CALL logger_error("VAR DEF EXTRA: opening file "//TRIM(cd_file))
+         ENDIF
+
+         ! read file
+         READ( il_fileid, FMT='(a)', IOSTAT=il_status ) cl_line
+         cl_line=TRIM(ADJUSTL(cl_line))
+         il_nvar=0
+         DO WHILE( il_status == 0 )
+
+         ! search line do not beginning with comment character
+            IF( SCAN( TRIM(fct_concat(cg_com(:))) ,cl_line(1:1)) == 0 )THEN
+               il_nvar=il_nvar+1
+            ENDIF
+            
+            READ( il_fileid, FMT='(a)', IOSTAT=il_status ) cl_line
+            cl_line=TRIM(ADJUSTL(cl_line))
+         ENDDO
+
+         IF( il_nvar <= 0 )THEN
+            CALL logger_warn("VAR DEF EXTRA: no variable to be read")
+
+            CLOSE( il_fileid, IOSTAT=il_status )
+            CALL fct_err(il_status)
+            IF( il_status /= 0 )THEN
+               CALL logger_error("VAR DEF EXTRA: closing file "//TRIM(cd_file))
+            ENDIF
+
+         ELSE
+            CALL logger_info("VAR DEF EXTRA: "//TRIM(fct_str(il_nvar))//&
+            &            " variable to be read on varaible config file")
+
+            CALL logger_debug("VAR DEF EXTRA: rewind "//TRIM(cd_file))
+            REWIND( il_fileid, IOSTAT=il_status)
+            CALL fct_err(il_status)
+            IF( il_status /= 0 )THEN
+               CALL logger_error("VAR DEF EXTRA: opening file "//TRIM(cd_file))
+            ENDIF
+
+            ALLOCATE( tg_varextra(il_nvar) )
+
+            ! read file
+            READ( il_fileid, FMT='(a)', IOSTAT=il_status ) cl_line
+            cl_line=TRIM(ADJUSTL(cl_line))
+            ji=1
+            DO WHILE( il_status == 0 )
+
+               IF( SCAN( TRIM(fct_concat(cg_com(:))) ,cl_line(1:1)) == 0 )THEN
+                  tg_varextra(ji)%i_id      = ji
+                  tg_varextra(ji)%c_name    =TRIM(fct_split(cl_line,1))
+                  tg_varextra(ji)%c_units   =TRIM(fct_split(cl_line,2))
+                  tg_varextra(ji)%c_axis    =TRIM(fct_split(cl_line,3))
+                  tg_varextra(ji)%c_point   =TRIM(fct_split(cl_line,4))
+                  tg_varextra(ji)%c_stdname =TRIM(fct_split(cl_line,5))
+                  tg_varextra(ji)%c_longname=TRIM(fct_split(cl_line,6))
+
+                  cl_interp=TRIM(fct_split(cl_line,7))
+                  tg_varextra(ji)%c_interp(:) = &
+                  &  var__get_interp(TRIM(tg_varextra(ji)%c_name), cl_interp)
+                  CALL logger_debug("VAR DEF EXTRA: "//&
+                  &  TRIM(tg_varextra(ji)%c_name)//&
+                  &  " "//TRIM(cl_interp))
+               ELSE
+                  ji=ji-1
+               ENDIF
+               
+               READ( il_fileid, FMT='(a)', IOSTAT=il_status ) cl_line
+               cl_line=TRIM(ADJUSTL(cl_line))
+               ji=ji+1
+            ENDDO
+
+            CLOSE( il_fileid, IOSTAT=il_status )
+            CALL fct_err(il_status)
+            IF( il_status /= 0 )THEN
+               CALL logger_error("VAR DEF EXTRA: closing file "//TRIM(cd_file))
+            ENDIF
+         ENDIF
+
+      ELSE
+
+         CALL logger_error("VAR DEF EXTRA: can't find file "//TRIM(cd_file))
+
+      ENDIF      
+
+   END SUBROUTINE var_def_extra
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine add variable information get from namelist in 
+   !> global table of variable structure with extra information :tg_varextra.
+   !> 
+   !> @details 
+   !> string character format must be : "varname:interp|filter|extrap"
+   !> you could specify only interpolation, filter or extrapolation method, 
+   !> or two whatever the order. you could find more
+   !> information about available method in interpolation, filter, and
+   !> extrapolation module. Here you cuold find some exemples: 
+   !> cn_varinfo='Bathymetry:2*hamming(2,3)'
+   !> cn_varinfo='votemper:cubic|dist_weight'
+   !>
+   !> @note If you do not specify one method which is required, default one is
+   !> apply.
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_varinfo : variable information from namelist
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var_chg_extra( cd_varinfo )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), DIMENSION(:), INTENT(IN) :: cd_varinfo
+
+      ! local variable
+      CHARACTER(LEN=lc)                            :: cl_name
+      CHARACTER(LEN=lc)                            :: cl_method
+      CHARACTER(LEN=lc), DIMENSION(2)              :: cl_interp
+      CHARACTER(LEN=lc), DIMENSION(1)              :: cl_extrap
+      CHARACTER(LEN=lc), DIMENSION(5)              :: cl_filter
+
+      INTEGER(i4)                                  :: il_varid
+      INTEGER(i4)                                  :: il_nvar
+
+      REAL(dp)                                     :: dl_min
+      REAL(dp)                                     :: dl_max
+
+      TYPE(TVAR)       , DIMENSION(:), ALLOCATABLE :: tl_varextra
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      ji=1
+      DO WHILE( TRIM(cd_varinfo(ji)) /= '' )
+
+         cl_name  =fct_lower(fct_split(cd_varinfo(ji),1,':'))
+         cl_method=fct_split(cd_varinfo(ji),2,':')
+
+         dl_min=var__get_min(cl_name, cl_method)
+         dl_max=var__get_max(cl_name, cl_method)
+         cl_interp(:)=var__get_interp(cl_name, cl_method)
+         cl_extrap(:)=var__get_extrap(cl_name, cl_method)
+         cl_filter(:)=var__get_filter(cl_name, cl_method)
+
+         il_varid=var_get_id(tg_varextra(:), TRIM(cl_name))
+         IF( il_varid /= 0 )THEN
+            IF( dl_min /= dg_fill ) tg_varextra(il_varid)%d_min=dl_min
+            IF( dl_max /= dg_fill ) tg_varextra(il_varid)%d_max=dl_max
+            IF(cl_interp(1)/='') tg_varextra(il_varid)%c_interp(:)=cl_interp(:)
+            IF(cl_extrap(1)/='') tg_varextra(il_varid)%c_extrap(:)=cl_extrap(:)
+            IF(cl_filter(1)/='') tg_varextra(il_varid)%c_filter(:)=cl_filter(:)
+         ELSE
+
+            IF( ALLOCATED(tg_varextra) )THEN
+               il_nvar=SIZE(tg_varextra(:))
+               ! save older variable
+               ALLOCATE( tl_varextra(il_nvar) )
+               tl_varextra(:)=tg_varextra(:)
+
+               DEALLOCATE(tg_varextra)
+               ALLOCATE( tg_varextra(il_nvar+1) )
+               
+               tg_varextra(1:il_nvar)=tl_varextra(:)
+               DEALLOCATE(tl_varextra)
+
+            ELSE
+
+               il_varid=0
+               ALLOCATE( tg_varextra(1) )
+
+            ENDIF
+
+            ! add new variable
+            il_varid=il_nvar+1
+            tg_varextra(il_varid)=var_init( TRIM(cl_name), &
+            &                               cd_interp=cl_interp(:), &
+            &                               cd_extrap=cl_extrap(:), &
+            &                               cd_filter=cl_filter(:), &
+            &                               dd_min = dl_min, &
+            &                               dd_max = dl_max )
+
+         ENDIF
+
+         ji=ji+1
+         CALL logger_trace( "VAR CHG EXTRA: name       "//&
+         &                  TRIM(tg_varextra(il_varid)%c_name) )
+         CALL logger_trace( "VAR CHG EXTRA: interp     "//&
+         &                  TRIM(tg_varextra(il_varid)%c_interp(1)) )         
+         CALL logger_trace( "VAR CHG EXTRA: filter     "//&
+         &                  TRIM(tg_varextra(il_varid)%c_filter(1)) )         
+         CALL logger_trace( "VAR CHG EXTRA: extrap     "//&
+         &                  TRIM(tg_varextra(il_varid)%c_extrap(1)) )
+         IF( tg_varextra(il_varid)%d_min /= dg_fill )THEN
+            CALL logger_trace( "VAR CHG EXTRA: min value  "//&
+            &                  TRIM(fct_str(tg_varextra(il_varid)%d_min)) )
+         ENDIF
+         IF( tg_varextra(il_varid)%d_max /= dg_fill )THEN
+            CALL logger_trace( "VAR CHG EXTRA: max value  "//&
+            &                  TRIM(fct_str(tg_varextra(il_varid)%d_max)) )
+         ENDIF
+      ENDDO
+
+   END SUBROUTINE var_chg_extra
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine read matrix value from character string
+   !> and fill variable strucutre value.
+
+   !> @detail
+   !> 
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !> @param[in] cd_matrix : matrix value
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var_read_matrix(td_var, cd_matrix)
+      IMPLICIT NONE
+      ! Argument      
+      TYPE(TVAR)      , INTENT(INOUT) :: td_var
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_matrix
+
+      ! local variable
+      CHARACTER(LEN=lc)                                  :: cl_table
+      CHARACTER(LEN=lc)                                  :: cl_line
+      CHARACTER(LEN=lc)                                  :: cl_elt
+
+      REAL(dp)         , DIMENSION(:,:,:)  , ALLOCATABLE :: dl_matrix
+      REAL(dp)         , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
+
+      TYPE(TDIM)       , DIMENSION(:)      , ALLOCATABLE :: tl_dim
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jk      
+      !----------------------------------------------------------------
+
+      IF( TRIM(cd_matrix) == '' )THEN
+         CALL logger_debug("VAR READ MATRIX: no matrix to be read")
+      ELSE
+
+         !1- read matrix
+         ALLOCATE( dl_matrix(ig_maxmtx, ig_maxmtx, ig_maxmtx) )
+         dl_matrix(:,:,:)=td_var%d_fill
+
+         jk=1
+         cl_table=fct_split(TRIM(cd_matrix),jk,'\ ')
+         CALL logger_debug("VAR MATRIX table "//TRIM(cl_table) )
+         DO WHILE( TRIM(cl_table) /= '' )
+            jj=1
+            cl_line=fct_split(TRIM(cl_table),jj,'/')
+            CALL logger_debug("VAR MATRIX line "//TRIM(cl_line) )
+            DO WHILE( TRIM(cl_line) /= '' )
+               ji=1
+               cl_elt=fct_split(TRIM(cl_line),ji,',')
+               CALL logger_debug("VAR MATRIX elt "//TRIM(cl_elt) )
+               DO WHILE( TRIM(cl_elt) /= '') 
+                  READ(cl_elt,*) dl_matrix(ji,jj,jk)
+                  ji=ji+1
+                  cl_elt=fct_split(TRIM(cl_line),ji,',')
+                  CALL logger_debug("VAR MATRIX elt "//TRIM(cl_elt) )
+               ENDDO
+               jj=jj+1
+               cl_line=fct_split(TRIM(cl_table),jj,'/')
+               CALL logger_debug("VAR MATRIX line "//TRIM(cl_line) )
+            ENDDO
+            jk=jk+1
+            cl_table=fct_split(TRIM(cd_matrix),jk,'\ ')
+            CALL logger_debug("VAR MATRIX table "//TRIM(cl_table) )
+         ENDDO
+
+         ! save useful value
+         ALLOCATE( dl_value(ji-1,jj-1,jk-1,1) )
+         dl_value(:,:,:,1)=dl_matrix(1:ji-1,1:jj-1,1:jk-1)
+
+         DEALLOCATE(dl_matrix)
+
+         ALLOCATE( tl_dim(3) )
+
+         IF( ji-1 > 0 ) tl_dim(1)=dim_init('x',ji-1)
+         IF( jj-1 > 0 ) tl_dim(2)=dim_init('y',jj-1)
+         IF( jk-1 > 0 ) tl_dim(3)=dim_init('z',jk-1)
+         
+         CALL var_add_dim(td_var, tl_dim(:))
+         CALL dim_clean(tl_dim)
+         DEALLOCATE( tl_dim )
+
+         IF( ASSOCIATED(td_var%d_value) ) DEALLOCATE(td_var%d_value)
+         CALL var_add_value(td_var, dl_value(:,:,:,:))
+
+         DEALLOCATE( dl_value )
+      ENDIF
+
+   END SUBROUTINE var_read_matrix
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine add extra information in variable structure
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var__get_extra( td_var )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+
+      ! local variable
+      INTEGER(i4)       :: il_varid
+      TYPE(TATT)        :: tl_att
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      IF( ALLOCATED(tg_varextra) )THEN
+
+         il_varid=var_get_id( tg_varextra(:), TRIM(td_var%c_name),  &
+                                              TRIM(td_var%c_stdname))
+         IF( il_varid /= 0 )THEN
+
+            ! name
+            IF( TRIM(td_var%c_name) == '' .AND. &
+            &   TRIM(tg_varextra(il_varid)%c_name) /= '' )THEN
+               td_var%c_name=TRIM(tg_varextra(il_varid)%c_name)
+            ENDIF
+
+            ! standard name
+            IF( TRIM(td_var%c_stdname) == '' .AND. &
+            &   TRIM(tg_varextra(il_varid)%c_stdname) /= ''  )THEN
+               td_var%c_stdname=TRIM(tg_varextra(il_varid)%c_stdname)
+               ! create attibute
+               tl_att=att_init('standard_name',TRIM(td_var%c_stdname))
+               CALL var_move_att(td_var, tl_att)
+            ENDIF
+
+            ! long_name
+            IF( TRIM(td_var%c_longname) == '' .AND. &
+            &   TRIM(tg_varextra(il_varid)%c_longname) /= '' )THEN
+               td_var%c_longname=TRIM(tg_varextra(il_varid)%c_longname)
+               ! create attibute
+               tl_att=att_init('long_name',TRIM(td_var%c_stdname))
+               CALL var_move_att(td_var, tl_att)               
+            ENDIF
+
+            ! units
+            IF( TRIM(td_var%c_units) == '' .AND. & 
+            &   TRIM(tg_varextra(il_varid)%c_units) /= '' )THEN
+               td_var%c_units=TRIM(tg_varextra(il_varid)%c_units)
+               ! create attibute
+               tl_att=att_init('units',TRIM(td_var%c_units))
+               CALL var_move_att(td_var, tl_att)               
+            ENDIF
+
+            ! axis
+            IF( TRIM(td_var%c_axis) == '' .AND. & 
+            &   TRIM(tg_varextra(il_varid)%c_axis) /= '' )THEN
+               td_var%c_axis=TRIM(tg_varextra(il_varid)%c_axis)
+               ! create attibute
+               tl_att=att_init('axis',TRIM(td_var%c_axis))
+               CALL var_move_att(td_var, tl_att)               
+            ENDIF
+
+            ! grid point
+            IF( TRIM(td_var%c_point) == '' .AND. &
+            &   TRIM(tg_varextra(il_varid)%c_point) /= '' )THEN
+               td_var%c_point=TRIM(tg_varextra(il_varid)%c_point)
+            ELSE
+               CALL logger_warn("VAR GET EXTRA: unknown grid point "//&
+               &  "for variable "//TRIM(td_var%c_name)//&
+               &  ". assume it is a T-point.")
+               td_var%c_point='T'
+            ENDIF
+            ! create attibute
+            tl_att=att_init('grid_point',TRIM(td_var%c_point))
+            CALL var_move_att(td_var, tl_att)               
+
+            ! interp
+            IF( TRIM(td_var%c_interp(1)) == '' .AND. &
+            &   TRIM(tg_varextra(il_varid)%c_interp(1)) /= '' )THEN
+               td_var%c_interp(:)=tg_varextra(il_varid)%c_interp(:)
+            ENDIF
+
+            ! extrap
+            IF( TRIM(td_var%c_extrap(1)) == '' .AND. &
+            &   TRIM(tg_varextra(il_varid)%c_extrap(1)) /= '' )THEN
+               td_var%c_extrap(:)=tg_varextra(il_varid)%c_extrap(:)
+            ENDIF
+
+            ! filter
+            IF( TRIM(td_var%c_filter(1)) == '' .AND. &
+            &   TRIM(tg_varextra(il_varid)%c_filter(1)) /= '' )THEN
+               td_var%c_filter(:)=tg_varextra(il_varid)%c_filter(:)
+            ENDIF            
+
+            ! min value
+            IF( td_var%d_min == dg_fill .AND. &
+            &   tg_varextra(il_varid)%d_min /= dg_fill )THEN
+               td_var%d_min=tg_varextra(il_varid)%d_min
+            ENDIF
+
+            ! max value
+            IF( td_var%d_max == dg_fill .AND. &
+            &   tg_varextra(il_varid)%d_max /= dg_fill )THEN
+               td_var%d_max=tg_varextra(il_varid)%d_max
+            ENDIF
+
+         CALL logger_trace("VAR GET EXTRA: name       "//TRIM(td_var%c_name))
+         CALL logger_trace("VAR GET EXTRA: stdname    "//TRIM(td_var%c_stdname))
+         CALL logger_trace("VAR GET EXTRA: longname   "//TRIM(td_var%c_longname))
+         CALL logger_trace("VAR GET EXTRA: units      "//TRIM(td_var%c_units))
+         CALL logger_trace("VAR GET EXTRA: point      "//TRIM(td_var%c_point))
+         CALL logger_trace("VAR GET EXTRA: interp     "//TRIM(td_var%c_interp(1)))
+         CALL logger_trace("VAR GET EXTRA: filter     "//TRIM(td_var%c_filter(1)))
+         CALL logger_trace("VAR GET EXTRA: min value  "//TRIM(fct_str(td_var%d_min)))
+         CALL logger_trace("VAR GET EXTRA: max value  "//TRIM(fct_str(td_var%d_max)))
+         ENDIF
+
+      ELSE
+
+         CALL logger_debug("VAR GET EXTRA: no extra information on variable "//&
+         &             " you should have run var_def_extra. ")
+
+      ENDIF
+
+   END SUBROUTINE var__get_extra
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function check if variable information read in namelist contains 
+   !> minimum value and return it if true 
+   !> 
+   !> @details
+   !> minimum value is assume to follow sign '>'
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_varinfo : variable information read in namelist 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION var__get_min( cd_name, cd_varinfo )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_name
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_varinfo
+
+      ! function
+      REAL(dp) :: var__get_min
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_tmp
+      CHARACTER(LEN=lc) :: cl_min
+      
+      INTEGER(i4)       :: il_ind
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! init
+      cl_min=''
+      var__get_min=dg_fill
+
+      ji=1
+      cl_tmp=fct_split(cd_varinfo,ji,';')
+      DO WHILE( TRIM(cl_tmp) /= '' )
+         il_ind=SCAN(TRIM(cl_tmp),'>')
+         IF( il_ind /= 0 )THEN
+            cl_min=TRIM(ADJUSTL(cl_tmp(il_ind+1:)))
+            EXIT
+         ENDIF
+         ji=ji+1
+         cl_tmp=fct_split(cd_varinfo,ji,';')         
+      ENDDO
+
+      IF( TRIM(cl_min) /= '' )THEN
+         IF( fct_is_num(cl_min) )THEN
+            READ(cl_min,*) var__get_min
+            CALL logger_info("VAR GET MIN: will use minimum value of "//&
+            &  TRIM(fct_str(var__get_min))//" for variable "//TRIM(cd_name) )
+         ELSE
+            CALL logger_error("VAR GET MIN: invalid minimum value for "//&
+            &  "variable "//TRIM(cd_name)//". check namelist." )
+         ENDIF
+      ENDIF
+
+   END FUNCTION var__get_min
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function check if variable information read in namelist contains 
+   !> maximum value and return it if true 
+   !> 
+   !> @details
+   !> maximum value is assume to follow sign '<'
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_varinfo : variable information read in namelist 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION var__get_max( cd_name, cd_varinfo )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_name
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_varinfo
+
+      ! function
+      REAL(dp) :: var__get_max
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_tmp
+      CHARACTER(LEN=lc) :: cl_max
+      
+      INTEGER(i4)       :: il_ind
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+      ! init
+      cl_max=''
+      var__get_max=dg_fill
+
+      ji=1
+      cl_tmp=fct_split(cd_varinfo,ji,';')
+      DO WHILE( TRIM(cl_tmp) /= '' )
+         il_ind=SCAN(TRIM(cl_tmp),'<')
+         IF( il_ind /= 0 )THEN
+            cl_max=TRIM(ADJUSTL(cl_tmp(il_ind+1:)))
+            EXIT
+         ENDIF
+         ji=ji+1
+         cl_tmp=fct_split(cd_varinfo,ji,';')         
+      ENDDO
+
+      IF( TRIM(cl_max) /= '' )THEN
+         IF( fct_is_num(cl_max) )THEN
+            READ(cl_max,*) var__get_max
+            CALL logger_info("VAR GET MAX: will use maximum value of "//&
+            &  TRIM(fct_str(var__get_max))//" for variable "//TRIM(cd_name) )
+         ELSE
+            CALL logger_error("VAR GET MAX: invalid maximum value for "//&
+            &  "variable "//TRIM(cd_name)//". check namelist." )
+         ENDIF
+      ENDIF
+
+   END FUNCTION var__get_max
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function check if variable information read in namelist contains 
+   !> interpolation method and return it if true 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_varinfo : variable information read in namelist 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION var__get_interp( cd_name, cd_varinfo )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_name
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_varinfo
+
+      ! function
+      CHARACTER(LEN=lc), DIMENSION(2) :: var__get_interp
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_tmp
+      CHARACTER(LEN=lc) :: cl_factor
+      
+      INTEGER(i4)       :: il_ind
+      INTEGER(i4)       :: il_len
+
+      INTEGER(i4)       :: il_mul
+      INTEGER(i4)       :: il_div
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      var__get_interp(:)=''
+
+      ji=1
+      cl_tmp=fct_split(cd_varinfo,ji,';')
+      DO WHILE( TRIM(cl_tmp) /= '' )
+         DO jj=1,ig_ninterp
+            il_ind= INDEX(fct_lower(cl_tmp),TRIM(cg_interp_list(jj)))
+            IF( il_ind /= 0 )THEN
+
+               var__get_interp(1)=TRIM(cg_interp_list(jj))
+               il_len=LEN(TRIM(cg_interp_list(jj)))
+               
+               ! look for factor
+               IF( il_ind==1 )THEN
+                  cl_factor=cl_tmp(il_len+1:)
+               ELSE
+                  cl_factor=cl_tmp(1:il_ind-1)
+               ENDIF
+               il_mul=SCAN(TRIM(cl_factor),'*')
+               il_div=SCAN(TRIM(cl_factor),'/')
+               
+               il_len=LEN(cl_factor)
+               IF( il_mul /= 0 )THEN
+                  IF( il_mul==1 )THEN
+                     cl_factor=cl_factor(2:il_len)
+                  ELSE
+                     cl_factor=cl_factor(1:il_mul-1)
+                  ENDIF
+
+               ELSE IF( il_div /=0 )THEN
+                  IF( il_div==1 )THEN
+                     cl_factor=cl_factor(2:il_len)
+                  ELSE
+                     cl_factor=cl_factor(1:il_div-1)
+                  ENDIF
+
+               ELSE
+                  cl_factor=''
+               ENDIF
+
+               SELECT CASE(TRIM(cl_factor))
+                  CASE('rhoi','rhoj','rhok')
+                     IF( il_mul /= 0 ) var__get_interp(2)='*'//TRIM(cl_factor)
+                     IF( il_div /= 0 ) var__get_interp(2)='/'//TRIM(cl_factor)
+                  CASE('')
+                     var__get_interp(2)=''
+                  CASE DEFAULT
+                     var__get_interp(2)=''
+                     CALL logger_error("VAR GET INTERP: variable "//&
+                     &     TRIM(cd_name)//&
+                     &     " invalid factor coefficient. check namelist. "//&
+                     &     " factor should be choose between rhox rhoy rhoz.")
+               END SELECT
+
+               EXIT
+            ENDIF
+         ENDDO
+         IF( jj /= ig_ninterp + 1 ) EXIT
+         ji=ji+1
+         cl_tmp=fct_split(cd_varinfo,ji,';')         
+      ENDDO
+
+   END FUNCTION var__get_interp
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function check if variable information read in namelist contains 
+   !> extrapolation method and return it if true 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_varinfo : variable information read in namelist 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION var__get_extrap( cd_name, cd_varinfo )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_name
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_varinfo
+
+      ! function
+      CHARACTER(LEN=lc), DIMENSION(1) :: var__get_extrap
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_tmp
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      var__get_extrap(:)=''
+
+      ji=1
+      cl_tmp=fct_split(cd_varinfo,ji,';')
+      DO WHILE( TRIM(cl_tmp) /= '' )
+         DO jj=1,ig_nextrap
+            IF( TRIM(fct_lower(cl_tmp)) == TRIM(cg_extrap_list(jj)) )THEN
+               var__get_extrap(1)=TRIM(cg_extrap_list(jj))
+
+               CALL logger_info("VAR GET EXTRAP: variable "//TRIM(cd_name)//&
+               &  " will use extrapolation method "//TRIM(var__get_extrap(1)) )
+
+               EXIT
+            ENDIF
+         ENDDO
+         IF( jj /= ig_nextrap + 1 ) EXIT
+         ji=ji+1
+         cl_tmp=fct_split(cd_varinfo,ji,';')         
+      ENDDO
+
+
+   END FUNCTION var__get_extrap
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This function check if variable information read in namelist contains 
+   !> filter method and return it if true 
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] cd_varinfo : variable information read in namelist 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION var__get_filter( cd_name, cd_varinfo )
+      IMPLICIT NONE
+      ! Argument
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_name
+      CHARACTER(LEN=*), INTENT(IN   ) :: cd_varinfo
+
+      ! function
+      CHARACTER(LEN=lc), DIMENSION(5) :: var__get_filter
+
+      ! local variable
+      CHARACTER(LEN=lc) :: cl_tmp
+      INTEGER(i4)       :: il_ind
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      var__get_filter(:)=''
+
+      ji=1
+      cl_tmp=fct_split(cd_varinfo,ji,';')
+      DO WHILE( TRIM(cl_tmp) /= '' )
+         DO jj=1,ig_nfilter
+            il_ind=INDEX(fct_lower(cl_tmp),TRIM(cg_filter_list(jj)))
+            IF( il_ind /= 0 )THEN
+               var__get_filter(1)=TRIM(cg_filter_list(jj))
+
+               ! look for number of turn
+               il_ind=SCAN(fct_lower(cl_tmp),'*')
+               IF( il_ind /=0 )THEN
+                  IF( fct_is_num(cl_tmp(1:il_ind-1)) )THEN
+                     var__get_filter(2)=TRIM(cl_tmp(1:il_ind-1))
+                  ELSE IF( fct_is_num(cl_tmp(il_ind+1:)) )THEN
+                     var__get_filter(2)=TRIM(cl_tmp(il_ind+1:))
+                  ELSE
+                     var__get_filter(2)='1'
+                  ENDIF
+               ELSE
+                  var__get_filter(2)='1'
+               ENDIF
+
+               ! look for filter parameter
+               il_ind=SCAN(fct_lower(cl_tmp),'(')
+               IF( il_ind /=0 )THEN
+                  cl_tmp=TRIM(cl_tmp(il_ind+1:))
+                  il_ind=SCAN(fct_lower(cl_tmp),')')
+                  IF( il_ind /=0 )THEN
+                     cl_tmp=TRIM(cl_tmp(1:il_ind-1))
+                     ! look for cut-off frequency
+                     var__get_filter(3)=fct_split(cl_tmp,1,',')
+                     ! look for halo size
+                     var__get_filter(4)=fct_split(cl_tmp,2,',')
+                     ! look for alpha parameter
+                     var__get_filter(5)=fct_split(cl_tmp,3,',')
+                  ELSE
+                     CALL logger_error("VAR GET FILTER: variable "//&
+                     &  TRIM(cd_name)//&
+                     &  " unclosed parentheses. check namelist. ")
+                  ENDIF
+               ELSE
+                  var__get_filter(3)=''
+                  var__get_filter(4)=''
+                  var__get_filter(5)=''
+               ENDIF
+   
+               CALL logger_trace("VAR GET FILTER: name "//TRIM(var__get_filter(1)))
+               CALL logger_trace("VAR GET FILTER: nturn "//TRIM(var__get_filter(2)))
+               CALL logger_trace("VAR GET FILTER: cutoff "//TRIM(var__get_filter(3)))
+               CALL logger_trace("VAR GET FILTER: halo "//TRIM(var__get_filter(4)))
+               CALL logger_trace("VAR GET FILTER: alpha "//TRIM(var__get_filter(5)))
+
+               EXIT
+            ENDIF
+         ENDDO
+         IF( jj /= ig_nfilter + 1 ) EXIT
+         ji=ji+1
+         cl_tmp=fct_split(cd_varinfo,ji,';')         
+      ENDDO
+
+   END FUNCTION var__get_filter
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief 
+   !> This function search and save the biggest dimensions use 
+   !> in those variables.
+   !>
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] td_var : table of variable structure
+   !> @return table of dimension 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION var_max_dim(td_var)
+      IMPLICIT NONE
+
+      ! Argument      
+      TYPE(TVAR), DIMENSION(:), INTENT(IN) :: td_var
+      
+      ! function
+      TYPE(TDIM), DIMENSION(ip_maxdim) :: var_max_dim
+
+      ! local variable
+      INTEGER(i4) :: il_nvar
+      
+      ! loop indices
+      INTEGER(i4) :: ji   
+      !-------------------------------------------------------------------
+                          
+      il_nvar=SIZE(td_var(:))
+                          
+      var_max_dim(:)=td_var(1)%t_dim(:)
+
+      DO ji=2,il_nvar     
+                          
+         IF( td_var(ji)%t_dim(1)%l_use .AND. &
+         &   td_var(ji)%t_dim(1)%i_len >= var_max_dim(1)%i_len )THEN
+            var_max_dim(1)=td_var(ji)%t_dim(1)
+         ENDIF            
+                          
+         IF( td_var(ji)%t_dim(2)%l_use .AND. &
+         &   td_var(ji)%t_dim(2)%i_len >= var_max_dim(2)%i_len )THEN 
+            var_max_dim(2)=td_var(ji)%t_dim(2)
+         ENDIF            
+                          
+         IF( td_var(ji)%t_dim(3)%l_use .AND. &
+         &   td_var(ji)%t_dim(3)%i_len >= var_max_dim(3)%i_len )THEN 
+            var_max_dim(3)=td_var(ji)%t_dim(3)
+         ENDIF            
+                          
+         IF( td_var(ji)%t_dim(4)%l_use .AND. &
+         &   td_var(ji)%t_dim(4)%i_len >= var_max_dim(4)%i_len )THEN
+            var_max_dim(4)=td_var(ji)%t_dim(4)
+         ENDIF
+
+      ENDDO
+
+   END FUNCTION var_max_dim
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine forced minimum and maximum value of variable.
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var_limit_value( td_var )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+
+      ! local variable
+
+      ! loop indices
+      !----------------------------------------------------------------
+
+      IF( ASSOCIATED(td_var%d_value) )THEN
+         !1- forced minimum value
+         IF( td_var%d_min /= dg_fill )THEN
+            WHERE( td_var%d_value(:,:,:,:) /= td_var%d_fill .AND. &
+               &   td_var%d_value(:,:,:,:) <  td_var%d_min )
+               td_var%d_value(:,:,:,:)=td_var%d_min
+            END WHERE
+         ENDIF
+
+         !2- forced maximum value 
+         IF( td_var%d_max /= dg_fill )THEN
+            WHERE( td_var%d_value(:,:,:,:) /= td_var%d_fill .AND. &
+               &   td_var%d_value(:,:,:,:) >  td_var%d_max )
+               td_var%d_value(:,:,:,:)=td_var%d_max
+            END WHERE
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE var_limit_value
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine forced minimum and maximum value of variable.
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[inout] td_var : variable structure
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE var_check_dim( td_var )
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+
+      ! local variable
+      INTEGER(i4)       :: il_naxis
+      INTEGER(i4)       :: il_ndim
+      CHARACTER(LEN=lc) :: cl_dim
+
+      LOGICAL           :: ll_warn
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( TRIM(td_var%c_axis) /= '' )THEN
+
+         cl_dim=''
+         DO ji=1,ip_maxdim
+            IF( td_var%t_dim(ji)%l_use )THEN
+               cl_dim=TRIM(cl_dim)//TRIM(fct_upper(td_var%t_dim(ji)%c_sname))
+            ENDIF
+         ENDDO
+
+         il_naxis=LEN( TRIM(ADJUSTL(td_var%c_axis)) )
+         il_ndim =LEN( TRIM(ADJUSTL(cl_dim)) )
+         IF( il_naxis >= il_ndim )THEN
+            ll_warn=.FALSE.
+            DO ji=1,il_naxis
+               IF( INDEX(TRIM(cl_dim),td_var%c_axis(ji:ji)) == 0 )THEN
+                  CALL logger_debug("VAR CHECK DIM: "//TRIM(cl_dim)//&
+                  &                 " "//TRIM(td_var%c_axis(ji:ji)) )
+                  ll_warn=.TRUE.
+                  EXIT
+               ENDIF
+            ENDDO
+
+            IF( ll_warn )THEN
+               CALL logger_warn("VAR CHECK DIM: variable dimension ("//&
+               &                TRIM(cl_dim)//") not conform with dimension"//&
+               &                 " expected ("//TRIM(td_var%c_axis)//"). ") 
+            ENDIF
+         ELSE
+            ! too much dimension
+            CALL logger_warn("VAR CHECK DIM: too much dimension for "//&
+            &                "variable "//TRIM(td_var%c_name)//".")
+            DO ji=1,il_ndim 
+               IF( INDEX(TRIM(td_var%c_axis),cl_dim(ji:ji)) == 0 )THEN
+                  IF( td_var%t_dim(ji)%i_len == 1 )THEN
+                     ! remove unuseful dimension
+                     CALL var_del_dim(td_var,td_var%t_dim(ji))
+                  ELSE
+                     CALL logger_warn("VAR CHECK DIM: variable "//&
+                     &           TRIM(td_var%c_name)//" should not use"//&
+                     &           " dimension "//TRIM(td_var%t_dim(ji)%c_name))
+                  ENDIF
+               ENDIF
+            ENDDO
+         ENDIF
+
+      ELSE
+         ! no information on variable dimension expected
+      ENDIF
+
+   END SUBROUTINE var_check_dim
+   !> @endcode
+END MODULE var
+
Index: branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/vgrid.f90
===================================================================
--- branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/vgrid.f90	(revision 4245)
+++ branches/2013/dev_LOCEAN_CMCC_INGV_MERC_UKMO_2013/NEMOGCM/TOOLS/SIREN/src/vgrid.f90	(revision 4245)
@@ -0,0 +1,752 @@
+!----------------------------------------------------------------------
+! NEMO system team, System and Interface for oceanic RElocable Nesting
+!----------------------------------------------------------------------
+!
+! MODULE: vgrid
+!
+! DESCRIPTION:
+!> @brief vertical grid manager <br/>
+!>
+!> @details
+!> 
+!> @author
+!> J.Paul
+! REVISION HISTORY:
+!> @date Nov, 2013 - Initial Version
+!
+!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+!> @todo
+!----------------------------------------------------------------------
+MODULE vgrid
+   USE netcdf
+   USE kind                            ! F90 kind parameter
+   USE fct                             ! basic usefull function
+   USE global                          ! global parameter
+   USE phycst                          ! physical constant
+   USE logger                             ! log file manager
+   USE file                            ! file manager
+   USE var                             ! variable manager
+   USE dim                             ! dimension manager
+   USE dom                             ! domain manager
+   USE iom                             ! I/O manager
+   USE mpp                             ! MPP manager
+   USE iom_mpp                         ! I/O MPP manager
+   IMPLICIT NONE
+   PRIVATE
+   ! NOTE_avoid_public_variables_if_possible
+
+   ! type and variable
+
+   ! function and subroutine
+   PUBLIC :: vgrid_zgr_z 
+   PUBLIC :: vgrid_zgr_zps
+   PUBLIC :: vgrid_zgr_bat_ctl
+   PUBLIC :: vgrid_get_level
+
+!   PRIVATE :: 
+
+
+CONTAINS
+   !-------------------------------------------------------------------
+   !> @brief This subroutine set the depth of model levels and the resulting 
+   !>      vertical scale factors.
+   !
+   !> @details
+   !> ** Method  :   z-coordinate system (use in all type of coordinate)
+   !>        The depth of model levels is defined from an analytical
+   !>      function the derivative of which gives the scale factors.
+   !>        both depth and scale factors only depend on k (1d arrays). <\br>
+   !>              w-level: gdepw  = fsdep(k)                           <\br>
+   !>                       e3w(k) = dk(fsdep)(k)     = fse3(k)         <\br>
+   !>              t-level: gdept  = fsdep(k+0.5)                       <\br>
+   !>                       e3t(k) = dk(fsdep)(k+0.5) = fse3(k+0.5)     <\br>
+   !>
+   !> ** Action  : - gdept, gdepw : depth of T- and W-point (m)          <\br>
+   !>              -  e3t, e3w    : scale factors at T- and W-levels (m) <\br>
+   !>
+   !> @author G. Madec
+   !> - 03,08-  G. Madec: F90: Free form and module
+   !
+   !> @note Reference : Marti, Madec & Delecluse, 1992, JGR, 97, No8, 12,763-12,766.
+   !>
+   !> @param[inout] dd_gdepw
+   !> @param[inout] dd_gedpt
+   !> @param[inout] dd_e3w
+   !> @param[inout] dd_e2t
+   !> @param[in] dd_ppkth 
+   !> @param[in] dd_ppkth2
+   !> @param[in] dd_ppacr
+   !> @param[in] dd_ppacr2
+   !> @param[in] dd_ppdzmin
+   !> @param[in] dd_pphmax 
+   !> @param[in] dd_pp_to_be_computed
+   !> @param[in] dd_ppa1
+   !> @param[in] dd_ppa2 
+   !> @param[in] dd_ppa0
+   !> @param[in] dd_ppsur
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE vgrid_zgr_z( dd_gdepw, dd_gdept, dd_e3w, dd_e3t,          &
+   &                       dd_ppkth, dd_ppkth2, dd_ppacr, dd_ppacr2,    &
+   &                       dd_ppdzmin, dd_pphmax, dd_pp_to_be_computed, &
+   &                       dd_ppa0, dd_ppa1, dd_ppa2, dd_ppsur )
+      IMPLICIT NONE
+      ! Argument      
+      REAL(dp), DIMENSION(:), INTENT(INOUT) :: dd_gdepw
+      REAL(dp), DIMENSION(:), INTENT(INOUT) :: dd_gdept
+      REAL(dp), DIMENSION(:), INTENT(INOUT) :: dd_e3w
+      REAL(dp), DIMENSION(:), INTENT(INOUT) :: dd_e3t
+
+      REAL(dp)              , INTENT(IN   ) :: dd_ppkth
+      REAL(dp)              , INTENT(IN   ) :: dd_ppkth2
+      REAL(dp)              , INTENT(IN   ) :: dd_ppacr
+      REAL(dp)              , INTENT(IN   ) :: dd_ppacr2
+
+      REAL(dp)              , INTENT(IN   ) :: dd_ppdzmin
+      REAL(dp)              , INTENT(IN   ) :: dd_pphmax
+      REAL(dp)              , INTENT(IN   ) :: dd_pp_to_be_computed
+
+      REAL(dp)              , INTENT(IN   ) :: dd_ppa0
+      REAL(dp)              , INTENT(IN   ) :: dd_ppa1
+      REAL(dp)              , INTENT(IN   ) :: dd_ppa2
+      REAL(dp)              , INTENT(IN   ) :: dd_ppsur
+
+      ! local variable
+      REAL(dp) :: dl_zkth
+      REAL(dp) :: dl_zkth2
+      REAL(dp) :: dl_zdzmin
+      REAL(dp) :: dl_zhmax
+      REAL(dp) :: dl_zacr
+      REAL(dp) :: dl_zacr2
+
+      REAL(dp) :: dl_ppacr
+      REAL(dp) :: dl_ppacr2
+
+      REAL(dp) :: dl_za0
+      REAL(dp) :: dl_za1
+      REAL(dp) :: dl_za2
+      REAL(dp) :: dl_zsur
+      REAL(dp) :: dl_zw
+      REAL(dp) :: dl_zt
+
+      INTEGER(i4) :: il_jpk
+
+      ! loop indices
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+       dl_ppacr = dd_ppacr
+       IF( dd_ppa1 == 0._dp ) dl_ppacr =1.0
+       dl_ppacr2= dd_ppacr2
+       IF( dd_ppa2 == 0._dp ) dl_ppacr2=1.0
+
+      ! Set variables from parameters
+      ! ------------------------------
+       dl_zkth   = dd_ppkth       ;   dl_zacr  = dl_ppacr
+       dl_zdzmin = dd_ppdzmin     ;   dl_zhmax = dd_pphmax
+       dl_zkth2  = dd_ppkth2      ;   dl_zacr2 = dl_ppacr2
+
+       il_jpk = SIZE(dd_gdepw(:))
+
+      ! If ppa1 and ppa0 and ppsur are et to pp_to_be_computed
+      !  za0, za1, zsur are computed from ppdzmin , pphmax, ppkth, ppacr
+      !
+       IF(  dd_ppa1  == dd_pp_to_be_computed  .AND.  &
+         &  dd_ppa0  == dd_pp_to_be_computed  .AND.  &
+         &  dd_ppsur == dd_pp_to_be_computed           ) THEN
+         dl_za1 = ( dl_zdzmin - dl_zhmax / REAL((il_jpk-1),dp) ) &
+             &     / ( TANH((1-dl_zkth)/dl_zacr) - dl_zacr/REAL((il_jpk-1),dp) &
+             &     * (  LOG( COSH( (REAL(il_jpk,dp) - dl_zkth) / dl_zacr) )    &
+             &        - LOG( COSH(( 1.0  - dl_zkth) / dl_zacr) ) )  )
+
+         dl_za0  = dl_zdzmin - dl_za1 * TANH( (1.0-dl_zkth) / dl_zacr )
+         dl_zsur = - dl_za0 - dl_za1 * dl_zacr * LOG( COSH( (1-dl_zkth) / dl_zacr )  )
+
+       ELSE
+         dl_za1 = dd_ppa1 ;       dl_za0 = dd_ppa0 ;  dl_zsur = dd_ppsur
+         dl_za2 = dd_ppa2
+       ENDIF
+
+      ! Reference z-coordinate (depth - scale factor at T- and W-points)
+      ! ======================
+      IF(  dd_ppkth == 0. )THEN            !  uniform vertical grid       
+
+         dl_za1 = dl_zhmax/REAL((il_jpk-1),dp) 
+         DO jk = 1, il_jpk
+            dl_zw = REAL(jk,dp)
+            dl_zt = REAL(jk,dp) + 0.5
+            dd_gdepw(jk) = ( dl_zw - 1.0 ) * dl_za1
+            dd_gdept(jk) = ( dl_zt - 1.0 ) * dl_za1
+            dd_e3w  (jk) =  dl_za1
+            dd_e3t  (jk) =  dl_za1
+         END DO
+
+      ELSE
+
+         DO jk = 1, il_jpk
+            dl_zw = REAL( jk,dp)
+            dl_zt = REAL( jk,dp) + 0.5
+            dd_gdepw(jk) = ( dl_zsur + dl_za0 * dl_zw + &
+            &                dl_za1 * dl_zacr * LOG( COSH( (dl_zw-dl_zkth)/dl_zacr ) ) + &
+            &                dl_za2 * dl_zacr2* LOG( COSH( (dl_zw-dl_zkth2)/dl_zacr2 ) ) )
+            dd_gdept(jk) = ( dl_zsur + dl_za0 * dl_zt + &
+            &                dl_za1 * dl_zacr * LOG( COSH( (dl_zt-dl_zkth)/dl_zacr ) ) + &
+            &                dl_za2 * dl_zacr2* LOG( COSH( (dl_zt-dl_zkth2)/dl_zacr2 ) ) )
+            dd_e3w  (jk) =             dl_za0 + &
+            &                          dl_za1 * TANH(      (dl_zw-dl_zkth)/dl_zacr   ) + &
+            &                          dl_za2 * TANH(      (dl_zw-dl_zkth2)/dl_zacr2 )
+            dd_e3t  (jk) =             dl_za0 + &
+            &                          dl_za1 * TANH(      (dl_zt-dl_zkth)/dl_zacr   ) + &
+            &                          dl_za2 * TANH(      (dl_zt-dl_zkth2)/dl_zacr2 )
+         END DO
+         dd_gdepw(1) = 0.e0   ! force first w-level to be exactly at zero
+
+      ENDIF
+
+      ! Control and  print
+      ! ==================
+
+      DO jk = 1, il_jpk
+         IF( dd_e3w(jk)  <= 0. .OR. dd_e3t(jk)  <= 0. )then
+            CALL logger_debug("VGRID ZGR Z: e3w or e3t =< 0 ")
+         ENDIF   
+
+         IF( dd_gdepw(jk) < 0. .OR. dd_gdept(jk) < 0. )then
+            CALL logger_debug("VGRID ZGR Z: gdepw or gdept < 0 ")
+         ENDIF
+      END DO
+
+   END SUBROUTINE vgrid_zgr_z
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine set the depth and vertical scale factor in partial step
+   !>      z-coordinate case 
+   !
+   !> @details
+   !> ** Method  :   Partial steps : computes the 3D vertical scale factors
+   !>      of T-, U-, V-, W-, UW-, VW and F-points that are associated with
+   !>      a partial step representation of bottom topography.
+   !>
+   !>        The reference depth of model levels is defined from an analytical
+   !>      function the derivative of which gives the reference vertical
+   !>      scale factors.
+   !>        From  depth and scale factors reference, we compute there new value
+   !>      with partial steps  on 3d arrays ( i, j, k ).
+   !>
+   !>              w-level: gdepw_ps(i,j,k)  = fsdep(k)
+   !>                       e3w_ps(i,j,k) = dk(fsdep)(k)     = fse3(i,j,k)
+   !>              t-level: gdept_ps(i,j,k)  = fsdep(k+0.5)
+   !>                       e3t_ps(i,j,k) = dk(fsdep)(k+0.5) = fse3(i,j,k+0.5)
+   !>
+   !>        With the help of the bathymetric file ( bathymetry_depth_ORCA_R2.nc),
+   !>      we find the mbathy index of the depth at each grid point.
+   !>      This leads us to three cases:
+   !>
+   !>              - bathy = 0 => mbathy = 0
+   !>              - 1 < mbathy < jpkm1    
+   !>              - bathy > gdepw(jpk) => mbathy = jpkm1  
+   !>
+   !>        Then, for each case, we find the new depth at t- and w- levels
+   !>      and the new vertical scale factors at t-, u-, v-, w-, uw-, vw- 
+   !>      and f-points.
+   !> 
+   !>        This routine is given as an example, it must be modified
+   !>      following the user s desiderata. nevertheless, the output as
+   !>      well as the way to compute the model levels and scale factors
+   !>      must be respected in order to insure second order accuracy
+   !>      schemes.
+   !>
+   !>         c a u t i o n : gdept, gdepw and e3 are positives
+   !>         - - - - - - -   gdept_ps, gdepw_ps and e3_ps are positives
+   !
+   !> @author A. Bozec, G. Madec
+   !> - 02-09 (A. Bozec, G. Madec) F90: Free form and module
+   !> - 02-09 (A. de Miranda)  rigid-lid + islands
+   !>
+   !> @note Reference : Pacanowsky & Gnanadesikan 1997, Mon. Wea. Rev., 126, 3248-3270.
+   !>
+   !> @param[inout] id_mbathy
+   !> @param[inout] dd_bathy
+   !> @param[inout] id_jpkmax 
+   !> @param[in] dd_gdepw
+   !> @param[in] dd_e3t 
+   !> @param[in] dd_e3zps_min
+   !> @param[in] dd_e3zps_rat
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE vgrid_zgr_zps( id_mbathy, dd_bathy, id_jpkmax, &
+   &                         dd_gdepw, dd_e3t,               &
+   &                         dd_e3zps_min, dd_e3zps_rat )
+      IMPLICIT NONE
+      ! Argument      
+      INTEGER(i4), DIMENSION(:,:), INTENT(  OUT) :: id_mbathy
+      REAL(dp)   , DIMENSION(:,:), INTENT(INOUT) :: dd_bathy
+      INTEGER(i4)                , INTENT(INOUT) :: id_jpkmax
+      REAL(dp)   , DIMENSION(:)  , INTENT(IN   ) :: dd_gdepw
+      REAL(dp)   , DIMENSION(:)  , INTENT(IN   ) :: dd_e3t
+      REAL(dp)                                   :: dd_e3zps_min
+      REAL(dp)                                   :: dd_e3zps_rat
+
+      ! local variable
+      REAL(dp) :: dl_zmax     ! Maximum depth
+      REAL(dp) :: dl_zmin     ! Minimum depth
+      REAL(dp) :: dl_zdepth   ! Ajusted ocean depth to avoid too small e3t 
+
+      INTEGER(i4) :: il_jpk
+      INTEGER(i4) :: il_jpkm1
+      INTEGER(i4) :: il_jpiglo
+      INTEGER(i4) :: il_jpjglo
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      INTEGER(i4) :: jk
+      !----------------------------------------------------------------
+
+      il_jpk=SIZE(dd_gdepw(:))
+      il_jpiglo=SIZE(id_mbathy(:,:),DIM=1)
+      il_jpjglo=SIZE(id_mbathy(:,:),DIM=2)
+
+      ! Initialization of constant
+      dl_zmax = dd_gdepw(il_jpk) + dd_e3t(il_jpk)
+      dl_zmin = dd_gdepw(4)
+
+      ! bathymetry in level (from bathy_meter)
+      ! ===================
+      il_jpkm1=il_jpk-1
+      ! initialize mbathy to the maximum ocean level available
+      id_mbathy(:,:) = il_jpkm1
+
+      ! storage of land and island's number (zera and negative values) in mbathy
+      DO jj = 1, il_jpjglo
+         DO ji= 1, il_jpiglo
+            IF( dd_bathy(ji,jj) <= 0. )   id_mbathy(ji,jj) = INT(dd_bathy(ji,jj),i4)
+         END DO
+      END DO
+
+      ! bounded value of bathy
+      ! minimum depth == 3 levels
+      ! maximum depth == gdepw(jpk)+e3t(jpk) 
+      ! i.e. the last ocean level thickness cannot exceed e3t(jpkm1)+e3t(jpk)
+      DO jj = 1, il_jpjglo
+         DO ji= 1, il_jpiglo
+            IF( dd_bathy(ji,jj) <= 0. ) THEN
+               dd_bathy(ji,jj) = 0.e0
+            ELSE
+               dd_bathy(ji,jj) = MAX( dd_bathy(ji,jj), dl_zmin )
+               dd_bathy(ji,jj) = MIN( dd_bathy(ji,jj), dl_zmax )
+            ENDIF
+         END DO
+      END DO
+
+      ! Compute mbathy for ocean points (i.e. the number of ocean levels)
+      ! find the number of ocean levels such that the last level thickness
+      ! is larger than the minimum of e3zps_min and e3zps_rat * e3t (where
+      ! e3t is the reference level thickness
+
+      DO jk = il_jpkm1, 1, -1
+         dl_zdepth = dd_gdepw(jk) + MIN( dd_e3zps_min, dd_e3t(jk)*dd_e3zps_rat )
+
+         DO jj = 1, il_jpjglo
+            DO ji = 1, il_jpiglo
+               IF( 0. < dd_bathy(ji,jj) .AND. dd_bathy(ji,jj) <= dl_zdepth ) id_mbathy(ji,jj) = jk-1
+            END DO
+         END DO
+      END DO
+
+      ! ================
+      ! Bathymetry check
+      ! ================
+
+      CALL vgrid_zgr_bat_ctl( id_mbathy, id_jpkmax, il_jpk)
+
+   END SUBROUTINE vgrid_zgr_zps
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This subroutine check the bathymetry in levels 
+   !
+   !> @details
+   !> ** Method  :   The array mbathy is checked to verified its consistency
+   !>      with the model options. in particular:
+   !>            mbathy must have at least 1 land grid-points (mbathy<=0)
+   !>                  along closed boundary.
+   !>            mbathy must be cyclic IF jperio=1.
+   !>            mbathy must be lower or equal to jpk-1.
+   !>            isolated ocean grid points are suppressed from mbathy
+   !>                  since they are only connected to remaining
+   !>                  ocean through vertical diffusion.
+   !>      C A U T I O N : mbathy will be modified during the initializa-
+   !>      tion phase to become the number of non-zero w-levels of a water
+   !>      column, with a minimum value of 1.
+   !>
+   !> ** Action  : - update mbathy: level bathymetry (in level index)
+   !>              - update bathy : meter bathymetry (in meters)
+
+   !> @author G.Madec
+   !> - 03-08 Original code
+   !
+   !> @param[in] 
+   !-------------------------------------------------------------------
+   !> @code
+   SUBROUTINE vgrid_zgr_bat_ctl( id_mbathy, id_jpkmax, id_jpk)
+      IMPLICIT NONE
+      ! Argument      
+      INTEGER(i4), DIMENSION(:,:), INTENT(INOUT) :: id_mbathy
+      INTEGER(i4)                , INTENT(INOUT) :: id_jpkmax
+      INTEGER(i4)                , INTENT(INOUT) :: id_jpk
+
+      ! local variable
+      INTEGER(i4) :: il_jpiglo
+      INTEGER(i4) :: il_jpjglo
+
+      INTEGER(i4) :: il_icompt
+      INTEGER(i4) :: il_ibtest
+      INTEGER(i4) :: il_ikmax
+      INTEGER(i4) :: il_jpkm1
+
+      INTEGER(i4) :: il_jim
+      INTEGER(i4) :: il_jip
+      INTEGER(i4) :: il_jjm
+      INTEGER(i4) :: il_jjp
+
+      ! loop indices
+      INTEGER(i4) :: jl
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+      !----------------------------------------------------------------
+
+      il_jpiglo=SIZE(id_mbathy(:,:),DIM=1)
+      il_jpjglo=SIZE(id_mbathy(:,:),DIM=2)
+
+      ! ================
+      ! Bathymetry check
+      ! ================
+
+      ! suppress isolated ocean grid points'
+      il_icompt = 0
+
+      DO jl = 1, 2
+         DO jj = 1, il_jpjglo
+            DO ji = 1, il_jpiglo
+               il_jim=max(ji-1,1) ; il_jip=min(ji+1,il_jpiglo)
+               il_jjm=max(jj-1,1) ; il_jjp=min(jj+1,il_jpjglo)
+
+               if(il_jim==ji) il_jim=il_jip ; if(il_jip==ji) il_jip=il_jim
+               if(il_jjm==jj) il_jjm=il_jjp ; if(il_jjp==jj) il_jjp=il_jjm
+
+               il_ibtest = MAX( id_mbathy(il_jim,jj), id_mbathy(il_jip,jj),  &
+                                id_mbathy(ji,il_jjm),id_mbathy(ji,il_jjp) )
+
+               IF( il_ibtest < id_mbathy(ji,jj) ) THEN
+                  id_mbathy(ji,jj) = il_ibtest
+                  il_icompt = il_icompt + 1
+               ENDIF
+            END DO
+         END DO
+
+      END DO
+      IF( il_icompt == 0 ) THEN
+         CALL logger_info("VGRID ZGR BAT CTL:  no isolated ocean grid points")
+      ELSE
+         CALL logger_info("VGRID ZGR BAT CTL:"//TRIM(fct_str(il_icompt))//&
+         &              " ocean grid points suppressed")
+      ENDIF
+
+      id_mbathy(:,:) = MAX( 0, id_mbathy(:,:))
+
+      ! Number of ocean level inferior or equal to jpkm1
+
+      il_ikmax = 0
+      DO jj = 1, il_jpjglo
+         DO ji = 1, il_jpiglo
+            il_ikmax = MAX( il_ikmax, id_mbathy(ji,jj) )
+         END DO
+      END DO
+
+      id_jpkmax=id_jpk
+
+      il_jpkm1=id_jpk-1
+      IF( il_ikmax > il_jpkm1 ) THEN
+         CALL logger_error("VGRID ZGR BAT CTL: maximum number of ocean level = "//&
+         &              TRIM(fct_str(il_ikmax))//" >  jpk-1."//&
+         &              " Change jpk to "//TRIM(fct_str(il_ikmax+1))//&
+         &              " to use the exact ead bathymetry" )
+      ELSE IF( il_ikmax < il_jpkm1 ) THEN
+         id_jpkmax=il_ikmax+1
+      ENDIF
+
+   END SUBROUTINE vgrid_zgr_bat_ctl
+   !> @endcode
+   !-------------------------------------------------------------------
+   !> @brief This function 
+   !
+   !> @details
+   !
+   !> @author J.Paul
+   !> - Nov, 2013- Initial Version
+   !
+   !> @param[in] 
+   !-------------------------------------------------------------------
+   !> @code
+   FUNCTION vgrid_get_level(td_bathy, cd_namelist, td_dom, id_nlevel)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TFILE)     , INTENT(IN) :: td_bathy
+      CHARACTER(LEN=*), INTENT(IN) :: cd_namelist
+      TYPE(TDOM)      , INTENT(IN), OPTIONAL :: td_dom
+      INTEGER(i4)     , INTENT(IN), OPTIONAL :: id_nlevel
+
+      ! function
+      TYPE(TVAR), DIMENSION(ig_npoint) :: vgrid_get_level
+
+      ! local variable
+      TYPE(TFILE) :: tl_bathy
+      TYPE(TMPP)  :: tl_mppbathy
+
+      TYPE(TDOM)  :: tl_dom
+
+      TYPE(TVAR)  :: tl_var
+      TYPE(TVAR) , DIMENSION(ig_npoint)            :: tl_level
+
+      TYPE(TDIM) , DIMENSION(ip_maxdim)            :: tl_dim
+
+      REAL(dp)   , DIMENSION(:)      , ALLOCATABLE :: dl_gdepw 
+      REAL(dp)   , DIMENSION(:)      , ALLOCATABLE :: dl_gdept 
+      REAL(dp)   , DIMENSION(:)      , ALLOCATABLE :: dl_e3w 
+      REAL(dp)   , DIMENSION(:)      , ALLOCATABLE :: dl_e3t
+
+      INTEGER(i4)                                  :: il_status
+      INTEGER(i4)                                  :: il_fileid
+      INTEGER(i4)                                  :: il_jpkmax
+      INTEGER(i4), DIMENSION(:,:)    , ALLOCATABLE :: il_mbathy
+      INTEGER(i4), DIMENSION(:,:,:,:), ALLOCATABLE :: il_level
+      
+      LOGICAL                                      :: ll_exist
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jj
+
+      INTEGER(i4) :: jip
+      INTEGER(i4) :: jjp
+
+      !namelist (intialise with GLORYS 75 levels parameters)
+      REAL(dp)                                :: dn_pp_to_be_computed = 0._dp
+      REAL(dp)                                :: dn_ppsur     = -3958.951371276829_dp
+      REAL(dp)                                :: dn_ppa0      =   103.9530096000000_dp
+      REAL(dp)                                :: dn_ppa1      =     2.4159512690000_dp
+      REAL(dp)                                :: dn_ppa2      =   100.7609285000000_dp
+      REAL(dp)                                :: dn_ppkth     =    15.3510137000000_dp
+      REAL(dp)                                :: dn_ppkth2    =    48.0298937200000_dp
+      REAL(dp)                                :: dn_ppacr     =     7.0000000000000_dp
+      REAL(dp)                                :: dn_ppacr2    =    13.000000000000_dp
+      REAL(dp)                                :: dn_ppdzmin   = 6._dp
+      REAL(dp)                                :: dn_pphmax    = 5750._dp
+      INTEGER(i4)                             :: in_nlevel    = 75
+
+      REAL(dp)                                :: dn_e3zps_min = 25._dp
+      REAL(dp)                                :: dn_e3zps_rat = 0.2_dp
+      !----------------------------------------------------------------
+      NAMELIST /namzgr/ &
+      &  dn_pp_to_be_computed, &
+      &  dn_ppsur,     &
+      &  dn_ppa0,      &
+      &  dn_ppa1,      &
+      &  dn_ppa2,      &
+      &  dn_ppkth,     &
+      &  dn_ppkth2,    &
+      &  dn_ppacr,     &
+      &  dn_ppacr2,    &
+      &  dn_ppdzmin,   &
+      &  dn_pphmax,    &
+      &  in_nlevel
+
+      NAMELIST /namzps/ &
+      &  dn_e3zps_min, &
+      &  dn_e3zps_rat
+      !----------------------------------------------------------------
+
+      !1- read namelist
+      INQUIRE(FILE=TRIM(cd_namelist), EXIST=ll_exist)
+      IF( ll_exist )THEN
+ 
+         il_fileid=fct_getunit()
+
+         OPEN( il_fileid, FILE=TRIM(cd_namelist), &
+         &                FORM='FORMATTED',       &
+         &                ACCESS='SEQUENTIAL',    &
+         &                STATUS='OLD',           &
+         &                ACTION='READ',          &
+         &                IOSTAT=il_status)
+         CALL fct_err(il_status)
+         IF( il_status /= 0 )THEN
+            CALL logger_fatal("VGRID GET LEVEL: ERROR opening "//TRIM(cd_namelist))
+         ENDIF
+
+         READ( il_fileid, NML = namzgr )
+         READ( il_fileid, NML = namzps )
+
+         CLOSE( il_fileid, IOSTAT=il_status )
+         CALL fct_err(il_status)
+         IF( il_status /= 0 )THEN
+            CALL logger_error("VGRID GET LEVELL: ERROR closing "//TRIM(cd_namelist))
+         ENDIF
+
+      ELSE
+
+         CALL logger_fatal("VGRID GET LEVEL: ERROR. can not find "//TRIM(cd_namelist))
+
+      ENDIF
+
+      !2- open files
+      tl_bathy=td_bathy
+      !2-1 get domain
+      IF( PRESENT(td_dom) )THEN
+         tl_dom=td_dom
+      ELSE
+         CALL iom_open(tl_bathy)
+
+         CALL logger_debug("VGRID GET LEVEL: get dom from "//&
+         &  TRIM(tl_bathy%c_name))
+         tl_dom=dom_init(tl_bathy)
+
+         CALL iom_close(tl_bathy)
+      ENDIF
+
+      !2-2 open mpp 
+      tl_mppbathy=mpp_init(tl_bathy)
+      CALL file_clean(tl_bathy)
+
+      !2-3 get processor to be used
+      CALL mpp_get_use( tl_mppbathy, tl_dom )
+
+      !2-4 open mpp files
+      CALL iom_mpp_open(tl_mppbathy)
+
+      !3- check namelist
+      IF( PRESENT(id_nlevel) ) in_nlevel=id_nlevel
+      IF( in_nlevel == 0 )THEN
+         CALL logger_fatal("VGRID GET LEVEL: number of level to be used "//&
+         &                 "is not specify. check namelist.")
+      ENDIF
+
+      !4- read bathymetry
+      tl_var=iom_mpp_read_var(tl_mppbathy,'bathymetry',td_dom=tl_dom)
+
+      WHERE( tl_var%d_value(:,:,1,1) == tl_var%d_fill )
+         tl_var%d_value(:,:,1,1)=0
+      END WHERE
+
+      !5 clean
+      CALL iom_mpp_close(tl_mppbathy)
+      CALL mpp_clean(tl_mppbathy)
+
+      !5- compute vertical grid
+      ALLOCATE( dl_gdepw(in_nlevel), dl_gdept(in_nlevel) ) 
+      ALLOCATE(   dl_e3w(in_nlevel),   dl_e3t(in_nlevel) ) 
+      CALL vgrid_zgr_z( dl_gdepw(:), dl_gdept(:), dl_e3w(:), dl_e3t(:), &
+      &                 dn_ppkth, dn_ppkth2, dn_ppacr, dn_ppacr2,       &
+      &                 dn_ppdzmin, dn_pphmax, dn_pp_to_be_computed,    &
+      &                 dn_ppa0, dn_ppa1, dn_ppa2, dn_ppsur )
+
+      !6- compute bathy level on T point
+      ALLOCATE( il_mbathy(tl_var%t_dim(1)%i_len, &
+      &                   tl_var%t_dim(2)%i_len ) )
+      CALL vgrid_zgr_zps( il_mbathy(:,:), tl_var%d_value(:,:,1,1), il_jpkmax, &
+      &                   dl_gdepw(:), dl_e3t(:),               &
+      &                   dn_e3zps_min, dn_e3zps_rat )
+
+      DEALLOCATE( dl_gdepw, dl_gdept ) 
+      DEALLOCATE(   dl_e3w,   dl_e3t )
+
+      !7- compute bathy level in T,U,V,F point
+      ALLOCATE( il_level(tl_var%t_dim(1)%i_len, &
+      &                  tl_var%t_dim(2)%i_len, &
+      &                  ig_npoint,1) )
+
+      DO jj=1,tl_var%t_dim(2)%i_len
+         DO ji= 1,tl_var%t_dim(1)%i_len
+
+         jip=MIN(ji+1,tl_var%t_dim(1)%i_len)
+         jjp=MIN(jj+1,tl_var%t_dim(2)%i_len)
+
+         ! T point
+         il_level(ji,jj,jp_T,1)=il_mbathy(ji,jj)
+         ! U point
+         il_level(ji,jj,jp_U,1)=MIN( il_mbathy(ji, jj ), il_mbathy(jip, jj ))
+         ! V point
+         il_level(ji,jj,jp_V,1)=MIN( il_mbathy(ji, jj ), il_mbathy(ji , jjp))
+         ! F point
+         il_level(ji,jj,jp_F,1)=MIN( il_mbathy(ji, jj ), il_mbathy(jip, jj ), &
+         &                           il_mbathy(ji, jjp), il_mbathy(jip, jjp))
+
+         ENDDO
+      ENDDO
+
+      DEALLOCATE( il_mbathy )
+
+      tl_dim(:)=tl_var%t_dim(:)
+      CALL var_clean(tl_var)
+
+      ! only 2 first dimension to be used
+      tl_dim(3:4)%l_use=.FALSE.
+
+      tl_level(jp_T)=var_init('tlevel',il_level(:,:,jp_T:jp_T,:),td_dim=tl_dim(:))
+      tl_level(jp_U)=var_init('ulevel',il_level(:,:,jp_U:jp_U,:),td_dim=tl_dim(:))
+      tl_level(jp_V)=var_init('vlevel',il_level(:,:,jp_V:jp_V,:),td_dim=tl_dim(:))
+      tl_level(jp_F)=var_init('flevel',il_level(:,:,jp_F:jp_F,:),td_dim=tl_dim(:))
+
+      DEALLOCATE( il_level )
+
+      ! save result
+      vgrid_get_level(:)=tl_level(:)
+
+      DO ji=1,ig_npoint
+         CALL var_clean(tl_level(ji))
+      ENDDO
+
+   END FUNCTION vgrid_get_level
+   !> @endcode
+!   !-------------------------------------------------------------------
+!   !> @brief This function 
+!   !
+!   !> @details
+!   !
+!   !> @author J.Paul
+!   !> - Nov, 2013- Initial Version
+!   !
+!   !> @param[in] 
+!   !-------------------------------------------------------------------
+!   !> @code
+!   FUNCTION vgrid_()
+!      IMPLICIT NONE
+!      ! Argument      
+!      ! function
+!      ! local variable
+!      ! loop indices
+!      !----------------------------------------------------------------
+!
+!   END FUNCTION vgrid_
+!   !> @endcode
+!   !-------------------------------------------------------------------
+!   !> @brief This subroutine 
+!   !
+!   !> @details
+!   !
+!   !> @author J.Paul
+!   !> - Nov, 2013- Initial Version
+!   !
+!   !> @param[in] 
+!   !-------------------------------------------------------------------
+!   !> @code
+!   SUBROUTINE vgrid_()
+!      IMPLICIT NONE
+!      ! Argument      
+!      ! local variable
+!      ! loop indices
+!      !----------------------------------------------------------------
+!
+!   END SUBROUTINE vgrid_
+!   !> @endcode
+END MODULE vgrid
+
