Index: /trunk/DOC/NEMO_book.tex
===================================================================
--- /trunk/DOC/NEMO_book.tex	(revision 6139)
+++ /trunk/DOC/NEMO_book.tex	(revision 6140)
@@ -215,6 +215,6 @@
 %\date{\today}
 \date{
-November 2014  \\
-{\small  -- version 3.6 --} \\
+November 2015  \\
+{\small  -- draft of version 4.0 --} \\
 ~  \\
 \textit{\small Note du P\^ole de mod\'{e}lisation de l'Institut Pierre-Simon Laplace No 27 }\\
@@ -301,4 +301,6 @@
 
 \include{./TexFiles/Chapters/Chap_STO}          % Stochastic param.
+
+\include{./TexFiles/Chapters/Chap_DIU}          % Diurnal SST models.
 
 \include{./TexFiles/Chapters/Chap_MISC}			% Miscellaneous topics
Index: /trunk/DOC/TexFiles/Biblio/Biblio.bib
===================================================================
--- /trunk/DOC/TexFiles/Biblio/Biblio.bib	(revision 6139)
+++ /trunk/DOC/TexFiles/Biblio/Biblio.bib	(revision 6140)
@@ -149,4 +149,17 @@
   volume = {36},
   pages = {1502--1522}
+}
+
+@ARTICLE{Artale_al_JGR02,
+  author={V. Artale and D. Iudicone and R. Santoleri and V. Rupolo and S. Marullo
+          and F. {D'O}rtenzio},
+  title={{Role of surface fluxes in ocean general circulation models using satellite
+          sea surface temperature: Validation of and sensitivity to the forcing
+          frequency of the Mediterranean thermohaline circulation}},
+  journal=JGR,
+  year={2002},
+  volume={107},
+  pages={1978-2012},
+  doi = {10.1029/2000JC000452},
 }
 
@@ -276,7 +289,7 @@
   author = {A. Beckmann and H. Goosse},
   title = {A parameterization of ice shelf-ocean interaction for climate models},
-  journal = OM
-  year = {2003}
-  volume = {5}
+  journal = OM,
+  year = {2003},
+  volume = {5},
   pages = {157--170}
 }
@@ -763,4 +776,12 @@
 }
 
+@PHDTHESIS{Demange_PhD2014,
+  author = {J. Farge},
+  title = {Sch\'{e}́mas num\'{e}́riques d’advection et de propagation d’ondes de gravit\'{e}́ 
+           dans les mod\`{e}les de circulation oc\'{e}́anique.},
+  school = {Doctorat es Applied Mathematiques, Grenoble University, France},
+  year = {2014},
+  pages = {138pp}
+}
 
 @ARTICLE{Dobricic_al_OS07,
@@ -983,5 +1004,5 @@
   author = {M. Farge},
   title = {Dynamique non lineaire des ondes et des tourbillons dans les equations de Saint Venant},
-  school = {Doctorat es Mathematiques, Paris VI University},
+  school = {Doctorat es Mathematiques, Paris VI University, France},
   year = {1987},
   pages = {401pp}
@@ -1059,4 +1080,16 @@
   volume = {20},  number = {1},
   pages = {150--155},
+}
+
+@Article{Gentemann_al_JGR09,
+  author = 	 {C. L. Gentemann  and P. J. Minnett and B. Ward},
+  title =        {Profiles of Ocean Surface heating ({POSH}): A new model 
+                  of upper ocean diurnal warming},
+  journal = 	 JGR,
+  year = 	 {2009},
+  Volume = 	 {114},
+  Pages = 	 {C07017},
+  doi = 	 {10.1029/2008JC004825},
+  OPTannote = 	 {}
 }
 
@@ -1122,4 +1155,14 @@
   doi = {10.1029/2006GL028210},
   url = {http://dx.doi.org/10.1029/2006GL028210}
+}
+
+@ARTICLE{Graham_McDougall_JPO13,
+  author = {F.S. Graham and T.J. McDougall},
+  title = {Quantifying the nonconservative production of conservative temperature, potential temperature, and entropy},
+  journal = JPO,
+  year = {2013},
+  volume = {43},
+  pages = {838--862},
+  url ={http://dx.doi.org/10.1175/JPO-D-11-0188.1}
 }
 
@@ -1347,4 +1390,13 @@
 }
 
+@ARTICLE{Holland1999, 
+  author = {D. Holland and A. Jenkins},
+  title = {Modeling Thermodynamic Ice-Ocean Interactions at the Base of an Ice Shelf},
+  journal = JPO,
+  year = {1999},
+  volume = {29},  
+  pages = {1787--1800},
+}
+
 @ARTICLE{HollowayOM86,
   author = {Greg Holloway},
@@ -1430,4 +1482,14 @@
 }
 
+@TECHREPORT{TEOS10,
+  author = {IOC and SCOR and IAPSO},
+  title = {The international thermodynamic equation of seawater - 2010: Calculation and use of thermodynamic properties},
+  institution = {Intergovernmental Oceanographic Commission},
+  publisher = {Manuals and Guides No. 56, UNESCO (English)},
+  year = {2010},
+  pages = {196pp},
+  url = {http://www.teos-10.org/pubs/TEOS-10_Manual.pdf}
+}
+
 @ARTICLE{Iudicone_al_JPO08b,
   author = {D. Iudicone and G. Madec and B. Blanke and S. Speich},
@@ -1493,4 +1555,22 @@
 }
 
+@ARTICLE{Jenkins1991,
+  author = {A. Jenkins},
+  title = {A one-dimensional model of ice shelf-ocean interaction},
+  journal = JGR,
+  year = {1991},
+  volume = {96},  number = {C11},
+  pages = {2298--2312}
+}
+
+@ARTICLE{Jenkins2010,
+  author = {A. Jenkins},
+  title = {observation and parameterization of ablation at the base of Ronne Ice Shelf, Antarctica},
+  journal = JPO,
+  year = {2010},
+  volume = {40},  number = {10},
+  pages = {2298--2312}
+}
+
 @BOOK{Jerlov_Bk68,
   title = {Optical Oceanography},
@@ -1643,4 +1723,17 @@
 }
 
+
+@ARTICLE{Lemarie_OM2015,
+  author = {F. Lemari\'{e} and L. Debreu and J. Demange and  G. Madec and J.M. Molines and M. Honnorat},
+  title = {Stability Constraints for Oceanic Numerical Models: 
+           Implications for the Formulation of time and space Discretizations},
+  journal = OM,
+  year = {2015},
+  volume = {92}, 
+  pages = {124--148},
+  doi = {10.1016/j.ocemod.2015.06.006},
+  url = {http://dx.doi.org/10.1016/j.ocemod.2015.06.006}
+}
+
 @ARTICLE{Lermusiaux2001,
   author = {P. F. J. Lermusiaux},
@@ -1655,5 +1748,5 @@
   author = {M. L\'{e}vy},
   title = {Mod\'{e}lisation des processus biog\'{e}ochimiques en M\'{e}diterran\'{e}e
-	nord-occidentale. Cycle saisonnier et variabilit\'{e} m\'{e}so\'{e}chelle},
+	        nord-occidentale. Cycle saisonnier et variabilit\'{e} m\'{e}so\'{e}chelle},
   school = {Universit\'{e} Pierre et Marie Curie, Paris, France, 207pp},
   year = {1996}
@@ -1796,4 +1889,13 @@
 }
 
+@ARTICLE{Lele_JCP1992,
+  author = {S.K. Lele},
+  title = {Compact finite difference schemes with spectral-like resolution},
+  journal = JCP,
+  year = {1992},
+  volume = {103}
+  pages = {16--42}
+}
+
 @ARTICLE{Lengaigne_al_JC03,
   author = {M. Lengaigne and J.-P. Boulanger and C. Menkes and G. Madec and P.
@@ -1898,4 +2000,12 @@
   volume = {51},
   pages = {737--769}
+}
+
+@ARTICLE{Losch2008,
+  author = {M. Losch},
+  title = {Modeling ice shelf cavities in a z coordinate ocean general circulation model},
+  journal = JGR,
+  year = {2008},
+  volume = {113},  number = {C13},
 }
 
@@ -2488,4 +2598,27 @@
 }
 
+@article{Roquet_OM2015,
+author = "F. Roquet and G. Madec and T.J. McDougall and P.M. Barker",
+title = "Accurate polynomial expressions for the density and specific volume of seawater using the TEOS-10 standard ",
+journal = OM,
+volume = "90",
+pages = "29--43",
+year = "2015",
+issn = "1463-5003",
+doi = "10.1016/j.ocemod.2015.04.002",
+url = "http://dx.doi.org/10.1016/j.ocemod.2015.04.002"
+}
+
+@article{Roquet_JPO2015,
+author = "F. Roquet and G. Madec and L. Brodeau and J. Nycander",
+title = "Defining a Simplified Yet Realistic Equation of State for Seawater",
+journal = JPO,
+volume = "45",
+pages = "2564--2579",
+year = "2015",
+doi = "10.1175/JPO-D-15-0080.1",
+url = "http://dx.doi.org/10.1175/JPO-D-15-0080.1"
+}
+
 @ARTICLE{Roullet_Madec_JGR00,
   author = {G. Roullet and G. Madec},
@@ -2514,4 +2647,14 @@
   volume = {87},
   pages = {394--409}
+}
+
+@ARTICLE{Saunders_JAS82,
+  author={P. M. Saunders},
+  title={{The Temperature at the Ocean-air Interface}},
+  journal=JAS,
+  year={1967},
+  volume={24},
+  pages={269-273},
+  doi = {10.1175/1520-0469(1967)024<0269:TTATOA>2.0.CO;2},
 }
 
@@ -2688,4 +2831,15 @@
   volume = {359},
   pages = {123--129}
+}
+
+@ARTICLE{Takaya_al_JGR10,
+  author = 	 {Y. Takaya and J-R. Bidlot and A. C. M. Beljaars and 
+                  P. A. E. M. Janssen},
+  title =        {Refinements to a prognostic scheme of sea surface skin temperature},
+  journal = 	 JGR,
+  year = 	 {2010},
+  Volume = 	 {115},
+  Pages = 	 {C06009},
+  doi = 	 {10.1029/2009JC005985},
 }
 
@@ -2793,4 +2947,14 @@
 }
 
+@ARTICLE{Tu_Tsuang_GRL05,
+  title={{Cool-skin simulation by a one-column ocean model}},
+  author={{C-Y}. Tu  and {B-J}. Tsuang},
+  journal=GRL,
+  year={2005},
+  volume={32},
+  pages={L22602},
+  doi = {10.1029/2005GL024252},
+}
+
 @ARTICLE{Umlauf_Burchard_JMS03,
   author = {L. Umlauf and H. Burchard},
@@ -2842,4 +3006,13 @@
   volume = {27},
   pages = {54--69}
+}
+
+@book{Vallis06,
+author = {Vallis, G. K.},
+title = {Atmospheric and Oceanic Fluid Dynamics},
+publisher = {Cambridge University Press},
+address = {Cambridge, U.K.},
+year = {2006},
+pages = {745},
 }
 
Index: /trunk/DOC/TexFiles/Chapters/Abstracts_Foreword.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Abstracts_Foreword.tex	(revision 6139)
+++ /trunk/DOC/TexFiles/Chapters/Abstracts_Foreword.tex	(revision 6140)
@@ -13,13 +13,13 @@
 be a flexible tool for studying the ocean and its interactions with the others components of 
 the earth climate system over a wide range of space and time scales. 
-Prognostic variables are the three-dimensional velocity field, a linear 
-or non-linear sea surface height, the temperature and the salinity. In the horizontal direction, 
-the model uses a curvilinear orthogonal grid and in the vertical direction, a full or partial step 
-$z$-coordinate, or $s$-coordinate, or a mixture of the two. The distribution of variables is a 
-three-dimensional Arakawa C-type grid. Various physical choices are available to describe 
-ocean physics, including TKE, GLS and KPP vertical physics. Within NEMO, the ocean is 
-interfaced with a sea-ice model (LIM v2 and v3), passive tracer and biogeochemical models (TOP) 
-and, via the OASIS coupler, with several atmospheric general circulation models. It also 
-support two-way grid embedding via the AGRIF software.
+Prognostic variables are the three-dimensional velocity field, a non-linear sea surface height, 
+the \textit{Conservative} Temperature and the \textit{Absolut} Salinity. 
+In the horizontal direction, the model uses a curvilinear orthogonal grid and in the vertical direction, 
+a full or partial step $z$-coordinate, or $s$-coordinate, or a mixture of the two. 
+The distribution of variables is a three-dimensional Arakawa C-type grid. 
+Various physical choices are available to describe ocean physics, including TKE, and GLS vertical physics. 
+Within NEMO, the ocean is interfaced with a sea-ice model (LIM or CICE), passive tracer and 
+biogeochemical models (TOP) and, via the OASIS coupler, with several atmospheric general circulation models. 
+It also support two-way grid embedding via the AGRIF software.
 
 % ================================================================
@@ -31,13 +31,13 @@
 interactions avec les autres composantes du syst\`{e}me climatique terrestre. 
 Les variables pronostiques sont le champ tridimensionnel de vitesse, une hauteur de la mer 
-lin\'{e}aire ou non, la temperature et la salinit\'{e}. 
+lin\'{e}aire, la Ttemperature Conservative et la Salinit\'{e} Absolue. 
 La distribution des variables se fait sur une grille C d'Arakawa tridimensionnelle utilisant une 
 coordonn\'{e}e verticale $z$ \`{a} niveaux entiers ou partiels, ou une coordonn\'{e}e s, ou encore 
 une combinaison des deux. Diff\'{e}rents choix sont propos\'{e}s pour d\'{e}crire la physique 
-oc\'{e}anique, incluant notamment des physiques verticales TKE, GLS et KPP. A travers l'infrastructure 
-NEMO, l'oc\'{e}an est interfac\'{e} avec des mod\`{e}les de glace de mer, de biog\'{e}ochimie 
-et de traceurs passifs, et, via le coupleur OASIS, \`{a} plusieurs mod\`{e}les de circulation 
-g\'{e}n\'{e}rale atmosph\'{e}rique. Il supporte \'{e}galement l'embo\^{i}tement interactif de 
-maillages via le logiciel AGRIF.
+oc\'{e}anique, incluant notamment des physiques verticales TKE et GLS. A travers l'infrastructure 
+NEMO, l'oc\'{e}an est interfac\'{e} avec des mod\`{e}les de glace de mer (LIM ou CICE), 
+de biog\'{e}ochimie marine et de traceurs passifs, et, via le coupleur OASIS, \`{a} plusieurs 
+mod\`{e}les de circulation g\'{e}n\'{e}rale atmosph\'{e}rique. 
+Il supporte \'{e}galement l'embo\^{i}tement interactif de maillages via le logiciel AGRIF.
 } 
 
Index: /trunk/DOC/TexFiles/Chapters/Annex_C.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Annex_C.tex	(revision 6139)
+++ /trunk/DOC/TexFiles/Chapters/Annex_C.tex	(revision 6140)
@@ -410,5 +410,5 @@
 \end{aligned}   } \right.
 \end{equation} 
-where the indices $i_p$ and $k_p$ take the following value: 
+where the indices $i_p$ and $j_p$ take the following value: 
 $i_p = -1/2$ or $1/2$ and $j_p = -1/2$ or $1/2$,
 and the vorticity triads, ${^i_j}\mathbb{Q}^{i_p}_{j_p}$, defined at $T$-point, are given by: 
Index: /trunk/DOC/TexFiles/Chapters/Chap_DIA.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Chap_DIA.tex	(revision 6139)
+++ /trunk/DOC/TexFiles/Chapters/Chap_DIA.tex	(revision 6140)
@@ -2,10 +2,10 @@
 % Chapter I/O & Diagnostics
 % ================================================================
-\chapter{Ouput and Diagnostics (IOM, DIA, TRD, FLO)}
+\chapter{Output and Diagnostics (IOM, DIA, TRD, FLO)}
 \label{DIA}
 \minitoc
 
 \newpage
-$\ $\newline    % force a new ligne
+$\ $\newline    % force a new line
 
 % ================================================================
@@ -33,5 +33,5 @@
 "\textit{grep -i numout}" in the source code directory.
 
-By default, diagnostic output files are written in NetCDF format but an IEEE binary output format, called DIMG, can be choosen by defining \key{dimgout}. 
+By default, diagnostic output files are written in NetCDF format but an IEEE binary output format, called DIMG, can be chosen by defining \key{dimgout}. 
 
 Since version 3.2, when defining \key{iomput}, an I/O server has been added which provides more flexibility in the choice of the fields to be written as well as how the writing work is distributed over the processors in massively parallel computing. The complete description of the use of this I/O server is presented in the next section. 
@@ -57,5 +57,5 @@
 \item The choice of output frequencies that can be different for each file (including real months and years).
 \item The choice of file contents; includes complete flexibility over which data are written in which files (the same data can be written in different files). 
-\item The possibility to split output files at a choosen frequency.
+\item The possibility to split output files at a chosen frequency.
 \item The possibility to extract a vertical or an horizontal subdomain.
 \item The choice of the temporal operation to perform, e.g.: average, accumulate, instantaneous, min, max and once.
@@ -1319,4 +1319,30 @@
 
 % -------------------------------------------------------------------------------------------------------------
+%       25 hour mean and hourly Surface, Mid and Bed 
+% -------------------------------------------------------------------------------------------------------------
+\section{25 hour mean output for tidal models }
+
+A module is available to compute a crudely detided M2 signal by obtaining a 25 hour mean.
+The 25 hour mean is available for daily runs by summing up the 25 hourly instantananeous hourly values from
+midnight at the start of the day to midight at the day end.
+This diagnostic is actived with the logical  $ln\_dia25h$
+
+%------------------------------------------nam_dia25h------------------------------------------------------
+\namdisplay{nam_dia25h}
+%----------------------------------------------------------------------------------------------------------
+
+\section{Top Middle and Bed hourly output }
+
+A module is available to output the surface (top), mid water and bed diagnostics of a set of standard variables. 
+This can be a useful diagnostic when hourly or sub-hourly output is required in high resolution tidal outputs.
+The tidal signal is retained but the overall data usage is cut to just three vertical levels. Also the bottom level 
+is calculated for each cell.
+This diagnostic is actived with the logical  $ln\_diatmb$
+
+%------------------------------------------nam_diatmb-----------------------------------------------------
+\namdisplay{nam_diatmb}
+%----------------------------------------------------------------------------------------------------------
+
+% -------------------------------------------------------------------------------------------------------------
 %       Sections transports
 % -------------------------------------------------------------------------------------------------------------
@@ -1522,4 +1548,13 @@
 \\
 
+\section{Courant numbers}
+Courant numbers provide a theoretical indication of the model's numerical stability. The advective Courant numbers can be calculated according to
+\begin{equation}
+\label{eq:CFL}
+C_u = |u|\frac{\rdt}{e_{1u}}, \quad C_v = |v|\frac{\rdt}{e_{2v}}, \quad C_w = |w|\frac{\rdt}{e_{3w}}
+\end{equation}
+in the zonal, meridional and vertical directions respectively. The vertical component is included although it is not strictly valid as the vertical velocity is calculated from the continuity equation rather than as a prognostic variable. Physically this represents the rate at which information is propogated across a grid cell. Values greater than 1 indicate that information is propagated across more than one grid cell in a single time step.
+
+The variables can be activated by setting the \np{nn\_diacfl} namelist parameter to 1 in the \ngn{namctl} namelist. The diagnostics will be written out to an ascii file named cfl\_diagnostics.ascii. In this file the maximum value of $C_u$, $C_v$, and $C_w$ are printed at each timestep along with the coordinates of where the maximum value occurs. At the end of the model run the maximum value of $C_u$, $C_v$, and $C_w$ for the whole model run is printed along with the coordinates of each. The maximum values from the run are also copied to the ocean.output file. 
 
 
Index: /trunk/DOC/TexFiles/Chapters/Chap_DIU.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Chap_DIU.tex	(revision 6140)
+++ /trunk/DOC/TexFiles/Chapters/Chap_DIU.tex	(revision 6140)
@@ -0,0 +1,164 @@
+% ================================================================
+% Diurnal SST models (DIU)
+% Edited by James While
+% ================================================================
+\chapter{Diurnal SST models (DIU)}
+\label{DIU}
+
+\minitoc
+
+
+\newpage
+$\ $\newline % force a new line
+
+Code to produce an estimate of the diurnal warming and cooling of the sea surface skin
+temperature (skin SST) is found in the DIU directory.  The skin
+temperature can be split into three parts:
+\begin{itemize}
+\item A foundation SST which is free from diurnal warming.
+\item A warm layer, typically ~3\,m thick, where heating from solar radiation can
+cause a warm stably stratified layer during the daytime
+\item A cool skin, a thin layer, approximately ~1\,mm thick, where long wave cooling
+is dominant and cools the immediate ocean surface.
+\end{itemize}
+
+Models are provided for both the warm layer, diurnal\_bulk.F90, and the cool skin,
+cool\_skin.F90.  Foundation SST is not considered as it can be obtained
+either from the main NEMO model (i.e. from the temperature of the top few model levels)
+or from
+some other source.  It must be noted that both the cool skin and
+warm layer models produce estimates of the change in temperature ($\Delta T_{\rm{cs}}$
+and $\Delta T_{\rm{wl}}$) and both must
+be added to a foundation SST to obtain the true skin temperature.
+
+Both the cool skin and warm layer models are controlled through the namelist `namdiu':
+\namdisplay{namdiu}
+This namelist contains only two variables:
+\begin{description}
+\item[ln\_diurnal] A logical switch for turning on/off both the cool skin and warm layer.
+\item[ln\_diurnal\_only] A logical switch which if .TRUE. will run the diurnal model
+without the other dynamical parts of NEMO.  ln\_diurnal\_only must be
+.FALSE. if ln\_diurnal is .FALSE.
+\end{description}
+
+Output for the diurnal model is through the variables `sst\_wl' (warm\_layer) and
+`sst\_cs' (cool skin).  These are 2-D variables which will be included in the model
+output if they are specified in the iodef.xml file.
+
+Initialisation is through the restart file.  Specifically the code will expect the presence of the 2-D variable ``Dsst'' to initialise the warm layer.  The cool skin model, which is determined purely by the instantaneous fluxes, has no initialisation variable.  
+
+%===============================================================
+
+\section{Warm Layer model}
+\label{warm_layer_sec}
+
+%===============================================================
+
+The warm layer is calculated using the model of \citet{Takaya_al_JGR10} (TAKAYA10 model
+hereafter).  This is a simple flux based model that is defined by the equations
+\begin{eqnarray}
+\frac{\partial{\Delta T_{\rm{wl}}}}{\partial{t}}&=&\frac{Q(\nu+1)}{D_T\rho_w c_p
+\nu}-\frac{(\nu+1)ku^*_{w}f(L_a)\Delta T}{D_T\Phi\!\left(\frac{D_T}{L}\right)} \mbox{,}
+\label{ecmwf1} \\
+L&=&\frac{\rho_w c_p u^{*^3}_{w}}{\kappa g \alpha_w Q }\mbox{,}\label{ecmwf2}
+\end{eqnarray}
+where $\Delta T_{\rm{wl}}$ is the temperature difference between the top of the warm
+layer and the depth $D_T=3$\,m at which there is assumed to be no diurnal signal. In
+equation (\ref{ecmwf1}) $\alpha_w=2\times10^{-4}$ is the thermal expansion
+coefficient of water, $\kappa=0.4$ is von K\'{a}rm\'{a}n's constant, $c_p$ is the heat
+capacity at constant pressure of sea water, $\rho_w$ is the
+water density, and $L$ is the Monin-Obukhov length. The tunable
+variable $\nu$ is a shape parameter that defines the expected
+subskin temperature profile via $T(z)=T(0)-\left(\frac{z}{D_T}\right)^\nu\Delta
+T_{\rm{wl}}$,
+where $T$ is the absolute temperature and $z\le D_T$ is the depth
+below the top of the warm layer.
+The influence of wind on TAKAYA10 comes through the magnitude of the friction velocity
+of the water
+$u^*_{w}$, which can be related to the 10\,m wind speed $u_{10}$ through the relationship
+$u^*_{w} = u_{10}\sqrt{\frac{C_d\rho_a}{\rho_w}}$, where $C_d$ is
+the drag coefficient, and $\rho_a$ is the density of air.  The symbol $Q$ in equation
+(\ref{ecmwf1}) is the instantaneous total thermal energy
+flux into
+the diurnal layer, i.e.
+\begin{equation}
+Q = Q_{\rm{sol}} + Q_{\rm{lw}} + Q_{\rm{h}}\mbox{,} \label{e_flux_eqn}
+\end{equation}
+where $Q_{\rm{h}}$ is the sensible and latent heat flux, $Q_{\rm{lw}}$ is the long
+wave flux, and $Q_{\rm{sol}}$ is the solar flux absorbed
+within the diurnal warm layer. For $Q_{\rm{sol}}$ the 9 term
+representation of \citet{Gentemann_al_JGR09} is used.  In equation \ref{ecmwf1}
+the function $f(L_a)=\max(1,L_a^{\frac{2}{3}})$, where $L_a=0.3$\footnote{This
+is a global average value, more accurately $L_a$ could be computed as
+$L_a=(u^*_{w}/u_s)^{\frac{1}{2}}$, where $u_s$ is the stokes drift, but this is not
+currently done} is the turbulent Langmuir number and is a
+parametrization of the effect of waves.
+The function $\Phi\!\left(\frac{D_T}{L}\right)$ is the similarity function that
+parametrizes the stability of the water column and
+is given by:
+\begin{equation}
+\Phi(\zeta) = \left\{ \begin{array}{cc} 1 + \frac{5\zeta +
+4\zeta^2}{1+3\zeta+0.25\zeta^2} &(\zeta \ge 0) \\
+                                    (1 - 16\zeta)^{-\frac{1}{2}} & (\zeta < 0) \mbox{,}
+                                    \end{array} \right. \label{stab_func_eqn}
+\end{equation}
+where $\zeta=\frac{D_T}{L}$.  It is clear that the first derivative of
+(\ref{stab_func_eqn}), and thus of (\ref{ecmwf1}),
+is discontinuous at $\zeta=0$ (i.e. $Q\rightarrow0$ in equation (\ref{ecmwf2})).
+
+The two terms on the right hand side of (\ref{ecmwf1}) represent different processes.
+The first term is simply the diabatic heating or cooling of the
+diurnal warm
+layer due to thermal energy
+fluxes into and out of the layer.  The second term
+parametrizes turbulent fluxes of heat out of the diurnal warm layer due to wind
+induced mixing. In practice the second term acts as a relaxation
+on the temperature.
+
+%===============================================================
+
+\section{Cool Skin model}
+\label{cool_skin_sec}
+
+%===============================================================
+
+The cool skin is modelled using the framework of \citet{Saunders_JAS82} who used a
+formulation of the near surface temperature difference based upon the heat flux and
+the friction velocity $u^*_{w}$.  As the cool skin
+is so thin (~1\,mm) we ignore the solar flux component to the heat flux and the
+Saunders equation for the cool skin temperature difference $\Delta T_{\rm{cs}}$ becomes
+\begin{equation}
+\label{sunders_eqn}
+\Delta T_{\rm{cs}}=\frac{Q_{\rm{ns}}\delta}{k_t} \mbox{,}
+\end{equation}
+where $Q_{\rm{ns}}$ is the, usually negative, non-solar heat flux into the ocean and
+$k_t$ is the thermal conductivity of sea water. $\delta$ is the thickness of the
+skin layer and is given by
+\begin{equation}
+\label{sunders_thick_eqn}
+\delta=\frac{\lambda \mu}{u^*_{w}} \mbox{,}
+\end{equation}
+where $\mu$ is the kinematic viscosity of sea water and $\lambda$ is a constant of
+proportionality which \citet{Saunders_JAS82} suggested varied between 5 and 10.
+
+The value of $\lambda$ used in equation (\ref{sunders_thick_eqn}) is that of
+\citet{Artale_al_JGR02},
+which is shown in \citet{Tu_Tsuang_GRL05} to outperform a number of other
+parametrisations at both low and high wind speeds. Specifically,
+\begin{equation}
+\label{artale_lambda_eqn}
+\lambda = \frac{ 8.64\times10^4 u^*_{w} k_t }{ \rho c_p h \mu \gamma }\mbox{,}
+\end{equation}
+where $h=10$\,m is a reference depth and
+$\gamma$ is a dimensionless function of wind speed $u$:
+\begin{equation}
+\label{artale_gamma_eqn}
+\gamma = \left\{ \begin{matrix}
+                     0.2u+0.5\mbox{,} & u \le 7.5\,\mbox{ms}^{-1} \\
+                     1.6u-10\mbox{,} & 7.5 < u < 10\,\mbox{ms}^{-1} \\
+                     6\mbox{,} & \ge 10\,\mbox{ms}^{-1} \\
+                 \end{matrix}
+          \right.
+\end{equation}
+
+
Index: /trunk/DOC/TexFiles/Chapters/Chap_DOM.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Chap_DOM.tex	(revision 6139)
+++ /trunk/DOC/TexFiles/Chapters/Chap_DOM.tex	(revision 6140)
@@ -1,4 +1,4 @@
 % ================================================================
-% Chapter 2 � Space and Time Domain (DOM)
+% Chapter 2 ——— Space and Time Domain (DOM)
 % ================================================================
 \chapter{Space Domain (DOM) }
@@ -364,5 +364,5 @@
 For both grids here,  the same $w$-point depth has been chosen but in (a) the 
 $t$-points are set half way between $w$-points while in (b) they are defined from 
-an analytical function: $z(k)=5\,(i-1/2)^3 - 45\,(i-1/2)^2 + 140\,(i-1/2) - 150$. 
+an analytical function: $z(k)=5\,(k-1/2)^3 - 45\,(k-1/2)^2 + 140\,(k-1/2) - 150$. 
 Note the resulting difference between the value of the grid-size $\Delta_k$ and 
 those of the scale factor $e_k$. }
@@ -475,11 +475,11 @@
 (d) hybrid $s-z$ coordinate, 
 (e) hybrid $s-z$ coordinate with partial step, and 
-(f) same as (e) but with variable volume associated with the non-linear free surface. 
-Note that the variable volume option (\key{vvl}) can be used with any of the 
+(f) same as (e) but in the non-linear free surface (\np{ln\_linssh}=false). 
+Note that the non-linear free surface can be used with any of the 
 5 coordinates (a) to (e).}
 \end{center}   \end{figure}
 %>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 
-The choice of a vertical coordinate, even if it is made through a namelist parameter, 
+The choice of a vertical coordinate, even if it is made through \ngn{namzgr} namelist parameters, 
 must be done once of all at the beginning of an experiment. It is not intended as an 
 option which can be enabled or disabled in the middle of an experiment. Three main 
@@ -488,18 +488,23 @@
 (\np{ln\_zps}~=~true), or generalized, $s$-coordinate (\np{ln\_sco}~=~true). 
 Hybridation of the three main coordinates are available: $s-z$ or $s-zps$ coordinate 
-(Fig.~\ref{Fig_z_zps_s_sps}d and \ref{Fig_z_zps_s_sps}e). When using the variable 
-volume option \key{vvl} ($i.e.$ non-linear free surface), the coordinate follow the 
-time-variation of the free surface so that the transformation is time dependent: 
-$z(i,j,k,t)$ (Fig.~\ref{Fig_z_zps_s_sps}f). This option can be used with full step 
-bathymetry or $s$-coordinate (hybrid and partial step coordinates have not 
-yet been tested in NEMO v2.3). If using $z$-coordinate with partial step bathymetry
-(\np{ln\_zps}~=~true), ocean cavity beneath ice shelves can be open (\np{ln\_isfcav}~=~true).
+(Fig.~\ref{Fig_z_zps_s_sps}d and \ref{Fig_z_zps_s_sps}e). By default a non-linear free surface is used:
+the coordinate follow the time-variation of the free surface so that the transformation is time dependent: 
+$z(i,j,k,t)$ (Fig.~\ref{Fig_z_zps_s_sps}f). When a linear free surface is assumed (\np{ln\_linssh}=true), 
+the vertical coordinate are fixed in time, but the seawater can move up and down across the z=0 surface 
+(in other words, the top of the ocean in not a rigid-lid). 
+The last choice in terms of vertical coordinate concerns the presence (or not) in the model domain 
+of ocean cavities beneath ice shelves. Setting \np{ln\_isfcav} to true allows to manage ocean cavities, 
+otherwise they are filled in.
 
 Contrary to the horizontal grid, the vertical grid is computed in the code and no 
 provision is made for reading it from a file. The only input file is the bathymetry 
-(in meters) (\ifile{bathy\_meter}) 
+(in meters) (\ifile{bathy\_meter}). 
 \footnote{N.B. in full step $z$-coordinate, a \ifile{bathy\_level} file can replace the 
 \ifile{bathy\_meter} file, so that the computation of the number of wet ocean point 
 in each water column is by-passed}. 
+If \np{ln\_isfcav}~=~true, an extra file input file describing the ice shelf draft 
+(in meters) (\ifile{isf\_draft\_meter}) is needed and all the location where the isf cavity thinnest
+ than \np{rn\_isfhmin} meters are grounded (ie masked). 
+
 After reading the bathymetry, the algorithm for vertical grid definition differs 
 between the different options:
@@ -519,17 +524,12 @@
 %%%
 
-The arrays describing the grid point depths and vertical scale factors 
-are three dimensional arrays $(i,j,k)$ even in the case of $z$-coordinate with 
-full step bottom topography. In non-linear free surface (\key{vvl}), their knowledge
-is required at \textit{before}, \textit{now} and \textit{after} time step, while they 
-do not vary in time in linear free surface case. 
-To improve the code readability while providing this flexibility, the vertical coordinate 
-and scale factors are defined as functions of 
-$(i,j,k)$ with "fs" as prefix (examples: \textit{fse3t\_b, fse3t\_n, fse3t\_a,} 
-for the  \textit{before}, \textit{now} and \textit{after} scale factors at $t$-point) 
-that can be either three different arrays when \key{vvl} is defined, or a single fixed arrays. 
-These functions are defined in the file \hf{domzgr\_substitute} of the DOM directory. 
-They are used throughout the code, and replaced by the corresponding arrays at 
-the time of pre-processing (CPP capability).
+Unless a linear free surface is used (\np{ln\_linssh}=false), the arrays describing 
+the grid point depths and vertical scale factors are three set of three dimensional arrays $(i,j,k)$ 
+defined at \textit{before}, \textit{now} and \textit{after} time step. The time at which they are
+defined is indicated by a suffix:$\_b$, $\_n$, or $\_a$, respectively. They are updated at each model time step
+using a fixed reference coordinate system which computer names have a $\_0$ suffix. 
+When the linear free surface option is used (\np{ln\_linssh}=true), \textit{before}, \textit{now} 
+and \textit{after} arrays are simply set one for all to their reference counterpart. 
+
 
 % -------------------------------------------------------------------------------------------------------------
@@ -840,6 +840,6 @@
 %        z*- or s*-coordinate
 % -------------------------------------------------------------------------------------------------------------
-\subsection{$z^*$- or $s^*$-coordinate (add \key{vvl}) }
-\label{DOM_zgr_vvl}
+\subsection{$z^*$- or $s^*$-coordinate (\np{ln\_linssh}=false) }
+\label{DOM_zgr_star}
 
 This option is described in the Report by Levier \textit{et al.} (2007), available on 
Index: /trunk/DOC/TexFiles/Chapters/Chap_DYN.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Chap_DYN.tex	(revision 6139)
+++ /trunk/DOC/TexFiles/Chapters/Chap_DYN.tex	(revision 6140)
@@ -1,10 +1,8 @@
 % ================================================================
-% Chapter � Ocean Dynamics (DYN)
+% Chapter ——— Ocean Dynamics (DYN)
 % ================================================================
 \chapter{Ocean Dynamics (DYN)}
 \label{DYN}
 \minitoc
-
-% add a figure for  dynvor ens, ene latices
 
 %\vspace{2.cm}
Index: /trunk/DOC/TexFiles/Chapters/Chap_LDF.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Chap_LDF.tex	(revision 6139)
+++ /trunk/DOC/TexFiles/Chapters/Chap_LDF.tex	(revision 6140)
@@ -1,5 +1,5 @@
 
 % ================================================================
-% Chapter � Lateral Ocean Physics (LDF)
+% Chapter ———  Lateral Ocean Physics (LDF)
 % ================================================================
 \chapter{Lateral Ocean Physics (LDF)}
@@ -15,12 +15,11 @@
 described in \S\ref{PE_zdf} and their discrete formulation in \S\ref{TRA_ldf} 
 and \S\ref{DYN_ldf}). In this section we further discuss each lateral physics option. 
-Choosing one lateral physics scheme means for the user defining, (1) the space 
-and time variations of the eddy coefficients ; (2) the direction along which the 
-lateral diffusive fluxes are evaluated (model level, geopotential or isopycnal 
-surfaces); and (3) the type of operator used (harmonic, or biharmonic operators, 
-and for tracers only, eddy induced advection on tracers). These three aspects 
-of the lateral diffusion are set through namelist parameters and CPP keys 
-(see the \textit{\ngn{nam\_traldf}} and \textit{\ngn{nam\_dynldf}} below). Note
-that this chapter describes the default implementation of iso-neutral
+Choosing one lateral physics scheme means for the user defining, 
+(1) the type of operator used (laplacian or bilaplacian operators, or no lateral mixing term) ; 
+(2) the direction along which the lateral diffusive fluxes are evaluated (model level, geopotential or isopycnal surfaces) ; and 
+(3) the space and time variations of the eddy coefficients. 
+These three aspects of the lateral diffusion are set through namelist parameters 
+(see the \textit{\ngn{nam\_traldf}} and \textit{\ngn{nam\_dynldf}} below). 
+Note that this chapter describes the standard implementation of iso-neutral
 tracer mixing, and Griffies's implementation, which is used if
 \np{traldf\_grif}=true, is described in Appdx\ref{sec:triad}
@@ -33,4 +32,283 @@
 
 % ================================================================
+% Direction of lateral Mixing
+% ================================================================
+\section  [Direction of Lateral Mixing (\textit{ldfslp})]
+		{Direction of Lateral Mixing (\mdl{ldfslp})}
+\label{LDF_slp}
+
+%%%
+\gmcomment{  we should emphasize here that the implementation is a rather old one. 
+Better work can be achieved by using \citet{Griffies_al_JPO98, Griffies_Bk04} iso-neutral scheme. }
+
+A direction for lateral mixing has to be defined when the desired operator does 
+not act along the model levels. This occurs when $(a)$ horizontal mixing is 
+required on tracer or momentum (\np{ln\_traldf\_hor} or \np{ln\_dynldf\_hor}) 
+in $s$- or mixed $s$-$z$- coordinates, and $(b)$ isoneutral mixing is required 
+whatever the vertical coordinate is. This direction of mixing is defined by its 
+slopes in the \textbf{i}- and \textbf{j}-directions at the face of the cell of the 
+quantity to be diffused. For a tracer, this leads to the following four slopes : 
+$r_{1u}$, $r_{1w}$, $r_{2v}$, $r_{2w}$ (see \eqref{Eq_tra_ldf_iso}), while 
+for momentum the slopes are  $r_{1t}$, $r_{1uw}$, $r_{2f}$, $r_{2uw}$ for 
+$u$ and  $r_{1f}$, $r_{1vw}$, $r_{2t}$, $r_{2vw}$ for $v$. 
+
+%gm% add here afigure of the slope in i-direction
+
+\subsection{slopes for tracer geopotential mixing in the $s$-coordinate}
+
+In $s$-coordinates, geopotential mixing ($i.e.$ horizontal mixing) $r_1$ and 
+$r_2$ are the slopes between the geopotential and computational surfaces. 
+Their discrete formulation is found by locally solving \eqref{Eq_tra_ldf_iso} 
+when the diffusive fluxes in the three directions are set to zero and $T$ is 
+assumed to be horizontally uniform, $i.e.$ a linear function of $z_T$, the 
+depth of a $T$-point. 
+%gm { Steven : My version is obviously wrong since I'm left with an arbitrary constant which is the local vertical temperature gradient}
+
+\begin{equation} \label{Eq_ldfslp_geo}
+\begin{aligned}
+ r_{1u} &= \frac{e_{3u}}{ \left( e_{1u}\;\overline{\overline{e_{3w}}}^{\,i+1/2,\,k} \right)}
+ 			  \;\delta_{i+1/2}[z_t] 
+ 		&\approx \frac{1}{e_{1u}}\; \delta_{i+1/2}[z_t] 
+\\
+ r_{2v} &= \frac{e_{3v}}{\left( e_{2v}\;\overline{\overline{e_{3w}}}^{\,j+1/2,\,k} \right)} 
+ 			  \;\delta_{j+1/2} [z_t] 
+		&\approx \frac{1}{e_{2v}}\; \delta_{j+1/2}[z_t] 
+\\
+ r_{1w} &= \frac{1}{e_{1w}}\;\overline{\overline{\delta_{i+1/2}[z_t]}}^{\,i,\,k+1/2}
+ 		&\approx \frac{1}{e_{1w}}\; \delta_{i+1/2}[z_{uw}] 
+ \\
+ r_{2w} &= \frac{1}{e_{2w}}\;\overline{\overline{\delta_{j+1/2}[z_t]}}^{\,j,\,k+1/2}
+		&\approx \frac{1}{e_{2w}}\; \delta_{j+1/2}[z_{vw}] 
+ \\
+\end{aligned}
+\end{equation}
+
+%gm%  caution I'm not sure the simplification was a good idea! 
+
+These slopes are computed once in \rou{ldfslp\_init} when \np{ln\_sco}=True, 
+and either \np{ln\_traldf\_hor}=True or \np{ln\_dynldf\_hor}=True. 
+
+\subsection{Slopes for tracer iso-neutral mixing}\label{LDF_slp_iso}
+In iso-neutral mixing  $r_1$ and $r_2$ are the slopes between the iso-neutral 
+and computational surfaces. Their formulation does not depend on the vertical 
+coordinate used. Their discrete formulation is found using the fact that the 
+diffusive fluxes of locally referenced potential density ($i.e.$ $in situ$ density) 
+vanish. So, substituting $T$ by $\rho$ in \eqref{Eq_tra_ldf_iso} and setting the 
+diffusive fluxes in the three directions to zero leads to the following definition for 
+the neutral slopes:
+
+\begin{equation} \label{Eq_ldfslp_iso}
+\begin{split}
+ r_{1u} &= \frac{e_{3u}}{e_{1u}}\; \frac{\delta_{i+1/2}[\rho]}
+ 								{\overline{\overline{\delta_{k+1/2}[\rho]}}^{\,i+1/2,\,k}}
+\\
+ r_{2v} &= \frac{e_{3v}}{e_{2v}}\; \frac{\delta_{j+1/2}\left[\rho \right]}
+ 								{\overline{\overline{\delta_{k+1/2}[\rho]}}^{\,j+1/2,\,k}}
+\\
+ r_{1w} &= \frac{e_{3w}}{e_{1w}}\; 
+ 			\frac{\overline{\overline{\delta_{i+1/2}[\rho]}}^{\,i,\,k+1/2}}
+				 {\delta_{k+1/2}[\rho]}
+\\
+ r_{2w} &= \frac{e_{3w}}{e_{2w}}\; 
+ 			\frac{\overline{\overline{\delta_{j+1/2}[\rho]}}^{\,j,\,k+1/2}}
+				 {\delta_{k+1/2}[\rho]}
+\\
+\end{split}
+\end{equation}
+
+%gm% rewrite this as the explanation is not very clear !!!
+%In practice, \eqref{Eq_ldfslp_iso} is of little help in evaluating the neutral surface slopes. Indeed, for an unsimplified equation of state, the density has a strong dependancy on pressure (here approximated as the depth), therefore applying \eqref{Eq_ldfslp_iso} using the $in situ$ density, $\rho$, computed at T-points leads to a flattening of slopes as the depth increases. This is due to the strong increase of the $in situ$ density with depth. 
+
+%By definition, neutral surfaces are tangent to the local $in situ$ density \citep{McDougall1987}, therefore in \eqref{Eq_ldfslp_iso}, all the derivatives have to be evaluated at the same local pressure (which in decibars is approximated by the depth in meters).
+
+%In the $z$-coordinate, the derivative of the  \eqref{Eq_ldfslp_iso} numerator is evaluated at the same depth \nocite{as what?} ($T$-level, which is the same as the $u$- and $v$-levels), so  the $in situ$ density can be used for its evaluation. 
+
+As the mixing is performed along neutral surfaces, the gradient of $\rho$ in 
+\eqref{Eq_ldfslp_iso} has to be evaluated at the same local pressure (which, 
+in decibars, is approximated by the depth in meters in the model). Therefore 
+\eqref{Eq_ldfslp_iso} cannot be used as such, but further transformation is 
+needed depending on the vertical coordinate used:
+
+\begin{description}
+
+\item[$z$-coordinate with full step : ] in \eqref{Eq_ldfslp_iso} the densities 
+appearing in the $i$ and $j$ derivatives  are taken at the same depth, thus 
+the $in situ$ density can be used. This is not the case for the vertical 
+derivatives: $\delta_{k+1/2}[\rho]$ is replaced by $-\rho N^2/g$, where $N^2$ 
+is the local Brunt-Vais\"{a}l\"{a} frequency evaluated following 
+\citet{McDougall1987} (see \S\ref{TRA_bn2}). 
+
+\item[$z$-coordinate with partial step : ] this case is identical to the full step 
+case except that at partial step level, the \emph{horizontal} density gradient 
+is evaluated as described in \S\ref{TRA_zpshde}.
+
+\item[$s$- or hybrid $s$-$z$- coordinate : ] in the current release of \NEMO, 
+iso-neutral mixing is only employed for $s$-coordinates if the
+Griffies scheme is used (\np{traldf\_grif}=true; see Appdx \ref{sec:triad}). 
+In other words, iso-neutral mixing will only be accurately represented with a 
+linear equation of state (\np{nn\_eos}=1 or 2). In the case of a "true" equation 
+of state, the evaluation of $i$ and $j$ derivatives in \eqref{Eq_ldfslp_iso} 
+will include a pressure dependent part, leading to the wrong evaluation of 
+the neutral slopes.
+
+%gm% 
+Note: The solution for $s$-coordinate passes trough the use of different 
+(and better) expression for the constraint on iso-neutral fluxes. Following 
+\citet{Griffies_Bk04}, instead of specifying directly that there is a zero neutral 
+diffusive flux of locally referenced potential density, we stay in the $T$-$S$ 
+plane and consider the balance between the neutral direction diffusive fluxes 
+of potential temperature and salinity:
+\begin{equation}
+\alpha \ \textbf{F}(T) = \beta \ \textbf{F}(S)
+\end{equation}
+%gm{  where vector F is ....}
+
+This constraint leads to the following definition for the slopes:
+
+\begin{equation} \label{Eq_ldfslp_iso2}
+\begin{split}
+ r_{1u} &= \frac{e_{3u}}{e_{1u}}\; \frac
+ 		{\alpha_u \;\delta_{i+1/2}[T] - \beta_u \;\delta_{i+1/2}[S]}
+		{\alpha_u \;\overline{\overline{\delta_{k+1/2}[T]}}^{\,i+1/2,\,k}
+		 -\beta_u  \;\overline{\overline{\delta_{k+1/2}[S]}}^{\,i+1/2,\,k} }
+\\
+ r_{2v} &= \frac{e_{3v}}{e_{2v}}\; \frac
+ 		{\alpha_v \;\delta_{j+1/2}[T] - \beta_v \;\delta_{j+1/2}[S]}
+		{\alpha_v \;\overline{\overline{\delta_{k+1/2}[T]}}^{\,j+1/2,\,k}
+		 -\beta_v  \;\overline{\overline{\delta_{k+1/2}[S]}}^{\,j+1/2,\,k} }
+\\
+ r_{1w} &= \frac{e_{3w}}{e_{1w}}\; \frac
+		{\alpha_w \;\overline{\overline{\delta_{i+1/2}[T]}}^{\,i,\,k+1/2}
+		 -\beta_w  \;\overline{\overline{\delta_{i+1/2}[S]}}^{\,i,\,k+1/2} }
+ 		{\alpha_w \;\delta_{k+1/2}[T] - \beta_w \;\delta_{k+1/2}[S]}
+\\
+ r_{2w} &= \frac{e_{3w}}{e_{2w}}\; \frac
+		{\alpha_w \;\overline{\overline{\delta_{j+1/2}[T]}}^{\,j,\,k+1/2}
+		 -\beta_w  \;\overline{\overline{\delta_{j+1/2}[S]}}^{\,j,\,k+1/2} }
+ 		{\alpha_w \;\delta_{k+1/2}[T] - \beta_w \;\delta_{k+1/2}[S]}
+\\
+\end{split}
+\end{equation}
+where $\alpha$ and $\beta$, the thermal expansion and saline contraction 
+coefficients introduced in \S\ref{TRA_bn2}, have to be evaluated at the three 
+velocity points. In order to save computation time, they should be approximated 
+by the mean of their values at $T$-points (for example in the case of $\alpha$:  
+$\alpha_u=\overline{\alpha_T}^{i+1/2}$,  $\alpha_v=\overline{\alpha_T}^{j+1/2}$ 
+and $\alpha_w=\overline{\alpha_T}^{k+1/2}$).
+
+Note that such a formulation could be also used in the $z$-coordinate and 
+$z$-coordinate with partial steps cases.
+
+\end{description}
+
+This implementation is a rather old one. It is similar to the one
+proposed by Cox [1987], except for the background horizontal
+diffusion. Indeed, the Cox implementation of isopycnal diffusion in
+GFDL-type models requires a minimum background horizontal diffusion
+for numerical stability reasons.  To overcome this problem, several
+techniques have been proposed in which the numerical schemes of the
+ocean model are modified \citep{Weaver_Eby_JPO97,
+  Griffies_al_JPO98}. Griffies's scheme is now available in \NEMO if
+\np{traldf\_grif\_iso} is set true; see Appdx \ref{sec:triad}. Here,
+another strategy is presented \citep{Lazar_PhD97}: a local
+filtering of the iso-neutral slopes (made on 9 grid-points) prevents
+the development of grid point noise generated by the iso-neutral
+diffusion operator (Fig.~\ref{Fig_LDF_ZDF1}). This allows an
+iso-neutral diffusion scheme without additional background horizontal
+mixing. This technique can be viewed as a diffusion operator that acts
+along large-scale (2~$\Delta$x) \gmcomment{2deltax doesnt seem very
+  large scale} iso-neutral surfaces. The diapycnal diffusion required
+for numerical stability is thus minimized and its net effect on the
+flow is quite small when compared to the effect of an horizontal
+background mixing.
+
+Nevertheless, this iso-neutral operator does not ensure that variance cannot increase, 
+contrary to the \citet{Griffies_al_JPO98} operator which has that property. 
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!ht]      \begin{center}
+\includegraphics[width=0.70\textwidth]{./TexFiles/Figures/Fig_LDF_ZDF1.pdf}
+\caption {    \label{Fig_LDF_ZDF1}
+averaging procedure for isopycnal slope computation.}
+\end{center}    \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+%There are three additional questions about the slope calculation. 
+%First the expression for the rotation tensor has been obtain assuming the "small slope" approximation, so a bound has to be imposed on slopes. 
+%Second, numerical stability issues also require a bound on slopes. 
+%Third, the question of boundary condition specified on slopes...
+
+%from griffies: chapter 13.1....
+
+
+
+% In addition and also for numerical stability reasons \citep{Cox1987, Griffies_Bk04}, 
+% the slopes are bounded by $1/100$ everywhere. This limit is decreasing linearly 
+% to zero fom $70$ meters depth and the surface (the fact that the eddies "feel" the 
+% surface motivates this flattening of isopycnals near the surface).
+
+For numerical stability reasons \citep{Cox1987, Griffies_Bk04}, the slopes must also 
+be bounded by $1/100$ everywhere. This constraint is applied in a piecewise linear 
+fashion, increasing from zero at the surface to $1/100$ at $70$ metres and thereafter 
+decreasing to zero at the bottom of the ocean. (the fact that the eddies "feel" the 
+surface motivates this flattening of isopycnals near the surface).
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!ht]     \begin{center}
+\includegraphics[width=0.70\textwidth]{./TexFiles/Figures/Fig_eiv_slp.pdf}
+\caption {     \label{Fig_eiv_slp}
+Vertical profile of the slope used for lateral mixing in the mixed layer : 
+\textit{(a)} in the real ocean the slope is the iso-neutral slope in the ocean interior, 
+which has to be adjusted at the surface boundary (i.e. it must tend to zero at the 
+surface since there is no mixing across the air-sea interface: wall boundary 
+condition). Nevertheless, the profile between the surface zero value and the interior 
+iso-neutral one is unknown, and especially the value at the base of the mixed layer ; 
+\textit{(b)} profile of slope using a linear tapering of the slope near the surface and 
+imposing a maximum slope of 1/100 ; \textit{(c)} profile of slope actually used in 
+\NEMO: a linear decrease of the slope from zero at the surface to its ocean interior 
+value computed just below the mixed layer. Note the huge change in the slope at the 
+base of the mixed layer between  \textit{(b)}  and \textit{(c)}.}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+\colorbox{yellow}{add here a discussion about the flattening of the slopes, vs  tapering the coefficient.}
+
+\subsection{slopes for momentum iso-neutral mixing}
+
+The iso-neutral diffusion operator on momentum is the same as the one used on 
+tracers but applied to each component of the velocity separately (see 
+\eqref{Eq_dyn_ldf_iso} in section~\ref{DYN_ldf_iso}). The slopes between the 
+surface along which the diffusion operator acts and the surface of computation 
+($z$- or $s$-surfaces) are defined at $T$-, $f$-, and \textit{uw}- points for the 
+$u$-component, and $T$-, $f$- and \textit{vw}- points for the $v$-component. 
+They are computed from the slopes used for tracer diffusion, $i.e.$ 
+\eqref{Eq_ldfslp_geo} and \eqref{Eq_ldfslp_iso} :
+
+\begin{equation} \label{Eq_ldfslp_dyn}
+\begin{aligned}
+&r_{1t}\ \ = \overline{r_{1u}}^{\,i}       &&&    r_{1f}\ \ &= \overline{r_{1u}}^{\,i+1/2} \\
+&r_{2f} \ \ = \overline{r_{2v}}^{\,j+1/2} &&& 	r_{2t}\ &= \overline{r_{2v}}^{\,j} \\
+&r_{1uw}  = \overline{r_{1w}}^{\,i+1/2} &&\ \ \text{and} \ \ &   r_{1vw}&= \overline{r_{1w}}^{\,j+1/2} \\
+&r_{2uw}= \overline{r_{2w}}^{\,j+1/2} &&&         r_{2vw}&= \overline{r_{2w}}^{\,j+1/2}\\
+\end{aligned}
+\end{equation}
+
+The major issue remaining is in the specification of the boundary conditions. 
+The same boundary conditions are chosen as those used for lateral 
+diffusion along model level surfaces, i.e. using the shear computed along 
+the model levels and with no additional friction at the ocean bottom (see 
+{\S\ref{LBC_coast}).
+
+
+% ================================================================
+% Lateral Mixing Operator
+% ================================================================
+\section [Lateral Mixing Operators (\textit{ldftra}, \textit{ldfdyn})] 
+		  {Lateral Mixing Operators (\mdl{traldf}, \mdl{traldf}) }
+\label{LDF_op}
+
+
+   
+% ================================================================
 % Lateral Mixing Coefficients
 % ================================================================
@@ -38,5 +316,4 @@
 		  {Lateral Mixing Coefficient (\mdl{ldftra}, \mdl{ldfdyn}) }
 \label{LDF_coef}
-
 
 Introducing a space variation in the lateral eddy mixing coefficients changes 
@@ -165,274 +442,4 @@
 
 % ================================================================
-% Direction of lateral Mixing
-% ================================================================
-\section  [Direction of Lateral Mixing (\textit{ldfslp})]
-		{Direction of Lateral Mixing (\mdl{ldfslp})}
-\label{LDF_slp}
-
-%%%
-\gmcomment{  we should emphasize here that the implementation is a rather old one. 
-Better work can be achieved by using \citet{Griffies_al_JPO98, Griffies_Bk04} iso-neutral scheme. }
-
-A direction for lateral mixing has to be defined when the desired operator does 
-not act along the model levels. This occurs when $(a)$ horizontal mixing is 
-required on tracer or momentum (\np{ln\_traldf\_hor} or \np{ln\_dynldf\_hor}) 
-in $s$- or mixed $s$-$z$- coordinates, and $(b)$ isoneutral mixing is required 
-whatever the vertical coordinate is. This direction of mixing is defined by its 
-slopes in the \textbf{i}- and \textbf{j}-directions at the face of the cell of the 
-quantity to be diffused. For a tracer, this leads to the following four slopes : 
-$r_{1u}$, $r_{1w}$, $r_{2v}$, $r_{2w}$ (see \eqref{Eq_tra_ldf_iso}), while 
-for momentum the slopes are  $r_{1t}$, $r_{1uw}$, $r_{2f}$, $r_{2uw}$ for 
-$u$ and  $r_{1f}$, $r_{1vw}$, $r_{2t}$, $r_{2vw}$ for $v$. 
-
-%gm% add here afigure of the slope in i-direction
-
-\subsection{slopes for tracer geopotential mixing in the $s$-coordinate}
-
-In $s$-coordinates, geopotential mixing ($i.e.$ horizontal mixing) $r_1$ and 
-$r_2$ are the slopes between the geopotential and computational surfaces. 
-Their discrete formulation is found by locally solving \eqref{Eq_tra_ldf_iso} 
-when the diffusive fluxes in the three directions are set to zero and $T$ is 
-assumed to be horizontally uniform, $i.e.$ a linear function of $z_T$, the 
-depth of a $T$-point. 
-%gm { Steven : My version is obviously wrong since I'm left with an arbitrary constant which is the local vertical temperature gradient}
-
-\begin{equation} \label{Eq_ldfslp_geo}
-\begin{aligned}
- r_{1u} &= \frac{e_{3u}}{ \left( e_{1u}\;\overline{\overline{e_{3w}}}^{\,i+1/2,\,k} \right)}
- 			  \;\delta_{i+1/2}[z_t] 
- 		&\approx \frac{1}{e_{1u}}\; \delta_{i+1/2}[z_t] 
-\\
- r_{2v} &= \frac{e_{3v}}{\left( e_{2v}\;\overline{\overline{e_{3w}}}^{\,j+1/2,\,k} \right)} 
- 			  \;\delta_{j+1/2} [z_t] 
-		&\approx \frac{1}{e_{2v}}\; \delta_{j+1/2}[z_t] 
-\\
- r_{1w} &= \frac{1}{e_{1w}}\;\overline{\overline{\delta_{i+1/2}[z_t]}}^{\,i,\,k+1/2}
- 		&\approx \frac{1}{e_{1w}}\; \delta_{i+1/2}[z_{uw}] 
- \\
- r_{2w} &= \frac{1}{e_{2w}}\;\overline{\overline{\delta_{j+1/2}[z_t]}}^{\,j,\,k+1/2}
-		&\approx \frac{1}{e_{2w}}\; \delta_{j+1/2}[z_{vw}] 
- \\
-\end{aligned}
-\end{equation}
-
-%gm%  caution I'm not sure the simplification was a good idea! 
-
-These slopes are computed once in \rou{ldfslp\_init} when \np{ln\_sco}=True, 
-and either \np{ln\_traldf\_hor}=True or \np{ln\_dynldf\_hor}=True. 
-
-\subsection{Slopes for tracer iso-neutral mixing}\label{LDF_slp_iso}
-In iso-neutral mixing  $r_1$ and $r_2$ are the slopes between the iso-neutral 
-and computational surfaces. Their formulation does not depend on the vertical 
-coordinate used. Their discrete formulation is found using the fact that the 
-diffusive fluxes of locally referenced potential density ($i.e.$ $in situ$ density) 
-vanish. So, substituting $T$ by $\rho$ in \eqref{Eq_tra_ldf_iso} and setting the 
-diffusive fluxes in the three directions to zero leads to the following definition for 
-the neutral slopes:
-
-\begin{equation} \label{Eq_ldfslp_iso}
-\begin{split}
- r_{1u} &= \frac{e_{3u}}{e_{1u}}\; \frac{\delta_{i+1/2}[\rho]}
- 								{\overline{\overline{\delta_{k+1/2}[\rho]}}^{\,i+1/2,\,k}}
-\\
- r_{2v} &= \frac{e_{3v}}{e_{2v}}\; \frac{\delta_{j+1/2}\left[\rho \right]}
- 								{\overline{\overline{\delta_{k+1/2}[\rho]}}^{\,j+1/2,\,k}}
-\\
- r_{1w} &= \frac{e_{3w}}{e_{1w}}\; 
- 			\frac{\overline{\overline{\delta_{i+1/2}[\rho]}}^{\,i,\,k+1/2}}
-				 {\delta_{k+1/2}[\rho]}
-\\
- r_{2w} &= \frac{e_{3w}}{e_{2w}}\; 
- 			\frac{\overline{\overline{\delta_{j+1/2}[\rho]}}^{\,j,\,k+1/2}}
-				 {\delta_{k+1/2}[\rho]}
-\\
-\end{split}
-\end{equation}
-
-%gm% rewrite this as the explanation is not very clear !!!
-%In practice, \eqref{Eq_ldfslp_iso} is of little help in evaluating the neutral surface slopes. Indeed, for an unsimplified equation of state, the density has a strong dependancy on pressure (here approximated as the depth), therefore applying \eqref{Eq_ldfslp_iso} using the $in situ$ density, $\rho$, computed at T-points leads to a flattening of slopes as the depth increases. This is due to the strong increase of the $in situ$ density with depth. 
-
-%By definition, neutral surfaces are tangent to the local $in situ$ density \citep{McDougall1987}, therefore in \eqref{Eq_ldfslp_iso}, all the derivatives have to be evaluated at the same local pressure (which in decibars is approximated by the depth in meters).
-
-%In the $z$-coordinate, the derivative of the  \eqref{Eq_ldfslp_iso} numerator is evaluated at the same depth \nocite{as what?} ($T$-level, which is the same as the $u$- and $v$-levels), so  the $in situ$ density can be used for its evaluation. 
-
-As the mixing is performed along neutral surfaces, the gradient of $\rho$ in 
-\eqref{Eq_ldfslp_iso} has to be evaluated at the same local pressure (which, 
-in decibars, is approximated by the depth in meters in the model). Therefore 
-\eqref{Eq_ldfslp_iso} cannot be used as such, but further transformation is 
-needed depending on the vertical coordinate used:
-
-\begin{description}
-
-\item[$z$-coordinate with full step : ] in \eqref{Eq_ldfslp_iso} the densities 
-appearing in the $i$ and $j$ derivatives  are taken at the same depth, thus 
-the $in situ$ density can be used. This is not the case for the vertical 
-derivatives: $\delta_{k+1/2}[\rho]$ is replaced by $-\rho N^2/g$, where $N^2$ 
-is the local Brunt-Vais\"{a}l\"{a} frequency evaluated following 
-\citet{McDougall1987} (see \S\ref{TRA_bn2}). 
-
-\item[$z$-coordinate with partial step : ] this case is identical to the full step 
-case except that at partial step level, the \emph{horizontal} density gradient 
-is evaluated as described in \S\ref{TRA_zpshde}.
-
-\item[$s$- or hybrid $s$-$z$- coordinate : ] in the current release of \NEMO, 
-iso-neutral mixing is only employed for $s$-coordinates if the
-Griffies scheme is used (\np{traldf\_grif}=true; see Appdx \ref{sec:triad}). 
-In other words, iso-neutral mixing will only be accurately represented with a 
-linear equation of state (\np{nn\_eos}=1 or 2). In the case of a "true" equation 
-of state, the evaluation of $i$ and $j$ derivatives in \eqref{Eq_ldfslp_iso} 
-will include a pressure dependent part, leading to the wrong evaluation of 
-the neutral slopes.
-
-%gm% 
-Note: The solution for $s$-coordinate passes trough the use of different 
-(and better) expression for the constraint on iso-neutral fluxes. Following 
-\citet{Griffies_Bk04}, instead of specifying directly that there is a zero neutral 
-diffusive flux of locally referenced potential density, we stay in the $T$-$S$ 
-plane and consider the balance between the neutral direction diffusive fluxes 
-of potential temperature and salinity:
-\begin{equation}
-\alpha \ \textbf{F}(T) = \beta \ \textbf{F}(S)
-\end{equation}
-%gm{  where vector F is ....}
-
-This constraint leads to the following definition for the slopes:
-
-\begin{equation} \label{Eq_ldfslp_iso2}
-\begin{split}
- r_{1u} &= \frac{e_{3u}}{e_{1u}}\; \frac
- 		{\alpha_u \;\delta_{i+1/2}[T] - \beta_u \;\delta_{i+1/2}[S]}
-		{\alpha_u \;\overline{\overline{\delta_{k+1/2}[T]}}^{\,i+1/2,\,k}
-		 -\beta_u  \;\overline{\overline{\delta_{k+1/2}[S]}}^{\,i+1/2,\,k} }
-\\
- r_{2v} &= \frac{e_{3v}}{e_{2v}}\; \frac
- 		{\alpha_v \;\delta_{j+1/2}[T] - \beta_v \;\delta_{j+1/2}[S]}
-		{\alpha_v \;\overline{\overline{\delta_{k+1/2}[T]}}^{\,j+1/2,\,k}
-		 -\beta_v  \;\overline{\overline{\delta_{k+1/2}[S]}}^{\,j+1/2,\,k} }
-\\
- r_{1w} &= \frac{e_{3w}}{e_{1w}}\; \frac
-		{\alpha_w \;\overline{\overline{\delta_{i+1/2}[T]}}^{\,i,\,k+1/2}
-		 -\beta_w  \;\overline{\overline{\delta_{i+1/2}[S]}}^{\,i,\,k+1/2} }
- 		{\alpha_w \;\delta_{k+1/2}[T] - \beta_w \;\delta_{k+1/2}[S]}
-\\
- r_{2w} &= \frac{e_{3w}}{e_{2w}}\; \frac
-		{\alpha_w \;\overline{\overline{\delta_{j+1/2}[T]}}^{\,j,\,k+1/2}
-		 -\beta_w  \;\overline{\overline{\delta_{j+1/2}[S]}}^{\,j,\,k+1/2} }
- 		{\alpha_w \;\delta_{k+1/2}[T] - \beta_w \;\delta_{k+1/2}[S]}
-\\
-\end{split}
-\end{equation}
-where $\alpha$ and $\beta$, the thermal expansion and saline contraction 
-coefficients introduced in \S\ref{TRA_bn2}, have to be evaluated at the three 
-velocity points. In order to save computation time, they should be approximated 
-by the mean of their values at $T$-points (for example in the case of $\alpha$:  
-$\alpha_u=\overline{\alpha_T}^{i+1/2}$,  $\alpha_v=\overline{\alpha_T}^{j+1/2}$ 
-and $\alpha_w=\overline{\alpha_T}^{k+1/2}$).
-
-Note that such a formulation could be also used in the $z$-coordinate and 
-$z$-coordinate with partial steps cases.
-
-\end{description}
-
-This implementation is a rather old one. It is similar to the one
-proposed by Cox [1987], except for the background horizontal
-diffusion. Indeed, the Cox implementation of isopycnal diffusion in
-GFDL-type models requires a minimum background horizontal diffusion
-for numerical stability reasons.  To overcome this problem, several
-techniques have been proposed in which the numerical schemes of the
-ocean model are modified \citep{Weaver_Eby_JPO97,
-  Griffies_al_JPO98}. Griffies's scheme is now available in \NEMO if
-\np{traldf\_grif\_iso} is set true; see Appdx \ref{sec:triad}. Here,
-another strategy is presented \citep{Lazar_PhD97}: a local
-filtering of the iso-neutral slopes (made on 9 grid-points) prevents
-the development of grid point noise generated by the iso-neutral
-diffusion operator (Fig.~\ref{Fig_LDF_ZDF1}). This allows an
-iso-neutral diffusion scheme without additional background horizontal
-mixing. This technique can be viewed as a diffusion operator that acts
-along large-scale (2~$\Delta$x) \gmcomment{2deltax doesnt seem very
-  large scale} iso-neutral surfaces. The diapycnal diffusion required
-for numerical stability is thus minimized and its net effect on the
-flow is quite small when compared to the effect of an horizontal
-background mixing.
-
-Nevertheless, this iso-neutral operator does not ensure that variance cannot increase, 
-contrary to the \citet{Griffies_al_JPO98} operator which has that property. 
-
-%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-\begin{figure}[!ht]      \begin{center}
-\includegraphics[width=0.70\textwidth]{./TexFiles/Figures/Fig_LDF_ZDF1.pdf}
-\caption {    \label{Fig_LDF_ZDF1}
-averaging procedure for isopycnal slope computation.}
-\end{center}    \end{figure}
-%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
-%There are three additional questions about the slope calculation. 
-%First the expression for the rotation tensor has been obtain assuming the "small slope" approximation, so a bound has to be imposed on slopes. 
-%Second, numerical stability issues also require a bound on slopes. 
-%Third, the question of boundary condition specified on slopes...
-
-%from griffies: chapter 13.1....
-
-
-
-% In addition and also for numerical stability reasons \citep{Cox1987, Griffies_Bk04}, 
-% the slopes are bounded by $1/100$ everywhere. This limit is decreasing linearly 
-% to zero fom $70$ meters depth and the surface (the fact that the eddies "feel" the 
-% surface motivates this flattening of isopycnals near the surface).
-
-For numerical stability reasons \citep{Cox1987, Griffies_Bk04}, the slopes must also 
-be bounded by $1/100$ everywhere. This constraint is applied in a piecewise linear 
-fashion, increasing from zero at the surface to $1/100$ at $70$ metres and thereafter 
-decreasing to zero at the bottom of the ocean. (the fact that the eddies "feel" the 
-surface motivates this flattening of isopycnals near the surface).
-
-%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-\begin{figure}[!ht]     \begin{center}
-\includegraphics[width=0.70\textwidth]{./TexFiles/Figures/Fig_eiv_slp.pdf}
-\caption {     \label{Fig_eiv_slp}
-Vertical profile of the slope used for lateral mixing in the mixed layer : 
-\textit{(a)} in the real ocean the slope is the iso-neutral slope in the ocean interior, 
-which has to be adjusted at the surface boundary (i.e. it must tend to zero at the 
-surface since there is no mixing across the air-sea interface: wall boundary 
-condition). Nevertheless, the profile between the surface zero value and the interior 
-iso-neutral one is unknown, and especially the value at the base of the mixed layer ; 
-\textit{(b)} profile of slope using a linear tapering of the slope near the surface and 
-imposing a maximum slope of 1/100 ; \textit{(c)} profile of slope actually used in 
-\NEMO: a linear decrease of the slope from zero at the surface to its ocean interior 
-value computed just below the mixed layer. Note the huge change in the slope at the 
-base of the mixed layer between  \textit{(b)}  and \textit{(c)}.}
-\end{center}   \end{figure}
-%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
-\colorbox{yellow}{add here a discussion about the flattening of the slopes, vs  tapering the coefficient.}
-
-\subsection{slopes for momentum iso-neutral mixing}
-
-The iso-neutral diffusion operator on momentum is the same as the one used on 
-tracers but applied to each component of the velocity separately (see 
-\eqref{Eq_dyn_ldf_iso} in section~\ref{DYN_ldf_iso}). The slopes between the 
-surface along which the diffusion operator acts and the surface of computation 
-($z$- or $s$-surfaces) are defined at $T$-, $f$-, and \textit{uw}- points for the 
-$u$-component, and $T$-, $f$- and \textit{vw}- points for the $v$-component. 
-They are computed from the slopes used for tracer diffusion, $i.e.$ 
-\eqref{Eq_ldfslp_geo} and \eqref{Eq_ldfslp_iso} :
-
-\begin{equation} \label{Eq_ldfslp_dyn}
-\begin{aligned}
-&r_{1t}\ \ = \overline{r_{1u}}^{\,i}       &&&    r_{1f}\ \ &= \overline{r_{1u}}^{\,i+1/2} \\
-&r_{2f} \ \ = \overline{r_{2v}}^{\,j+1/2} &&& 	r_{2t}\ &= \overline{r_{2v}}^{\,j} \\
-&r_{1uw}  = \overline{r_{1w}}^{\,i+1/2} &&\ \ \text{and} \ \ &   r_{1vw}&= \overline{r_{1w}}^{\,j+1/2} \\
-&r_{2uw}= \overline{r_{2w}}^{\,j+1/2} &&&         r_{2vw}&= \overline{r_{2w}}^{\,j+1/2}\\
-\end{aligned}
-\end{equation}
-
-The major issue remaining is in the specification of the boundary conditions. 
-The same boundary conditions are chosen as those used for lateral 
-diffusion along model level surfaces, i.e. using the shear computed along 
-the model levels and with no additional friction at the ocean bottom (see 
-{\S\ref{LBC_coast}).
-
-
-% ================================================================
 % Eddy Induced Mixing
 % ================================================================
Index: /trunk/DOC/TexFiles/Chapters/Chap_Model_Basics.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Chap_Model_Basics.tex	(revision 6139)
+++ /trunk/DOC/TexFiles/Chapters/Chap_Model_Basics.tex	(revision 6140)
@@ -247,75 +247,15 @@
 sufficient to solve a linearized version of (\ref{Eq_PE_ssh}), which still allows 
 to take into account freshwater fluxes applied at the ocean surface \citep{Roullet_Madec_JGR00}.
+Nevertheless, with the linearization, an exact conservation of heat and salt contents is lost.
 
 The filtering of EGWs in models with a free surface is usually a matter of discretisation 
-of the temporal derivatives, using the time splitting method \citep{Killworth_al_JPO91, Zhang_Endoh_JGR92} 
-or the implicit scheme \citep{Dukowicz1994}. In \NEMO, we use a slightly different approach 
-developed by \citet{Roullet_Madec_JGR00}: the damping of EGWs is ensured by introducing an 
-additional force in the momentum equation. \eqref{Eq_PE_dyn} becomes: 
-\begin{equation} \label{Eq_PE_flt}
-\frac{\partial {\rm {\bf U}}_h }{\partial t}= {\rm {\bf M}}
-- g \nabla \left( \tilde{\rho} \ \eta \right) 
-- g \ T_c \nabla \left( \widetilde{\rho} \ \partial_t \eta \right) 
-\end{equation}
-where $T_c$, is a parameter with dimensions of time which characterizes the force, 
-$\widetilde{\rho} = \rho / \rho_o$ is the dimensionless density, and $\rm {\bf M}$ 
-represents the collected contributions of the Coriolis, hydrostatic pressure gradient, 
-non-linear and viscous terms in \eqref{Eq_PE_dyn}.
-
-The new force can be interpreted as a diffusion of vertically integrated volume flux divergence. 
-The time evolution of $D$ is thus governed by a balance of two terms, $-g$ \textbf{A} $\eta$ 
-and $g \, T_c \,$ \textbf{A} $D$, associated with a propagative regime and a diffusive regime 
-in the temporal spectrum, respectively. In the diffusive regime, the EGWs no longer propagate, 
-$i.e.$ they are stationary and damped. The diffusion regime applies to the modes shorter than 
-$T_c$. For longer ones, the diffusion term vanishes. Hence, the temporally unresolved EGWs 
-can be damped by choosing $T_c > \rdt$. \citet{Roullet_Madec_JGR00} demonstrate that 
-(\ref{Eq_PE_flt}) can be integrated with a leap frog scheme except the additional term which 
-has to be computed implicitly. This is not surprising since the use of a large time step has a 
-necessarily numerical cost. Two gains arise in comparison with the previous formulations. 
-Firstly, the damping of EGWs can be quantified through the magnitude of the additional term. 
-Secondly, the numerical scheme does not need any tuning. Numerical stability is ensured as 
-soon as $T_c > \rdt$.
-
-When the variations of free surface elevation are small compared to the thickness of the first 
-model layer, the free surface equation (\ref{Eq_PE_ssh}) can be linearized. As emphasized 
-by \citet{Roullet_Madec_JGR00} the linearization of (\ref{Eq_PE_ssh}) has consequences on the 
-conservation of salt in the model. With the nonlinear free surface equation, the time evolution 
-of the total salt content is 
-\begin{equation} \label{Eq_PE_salt_content}
-    \frac{\partial }{\partial t}\int\limits_{D\eta } {S\;dv} 
-                        =\int\limits_S {S\;(-\frac{\partial \eta }{\partial t}-D+P-E)\;ds}
-\end{equation}
-where $S$ is the salinity, and the total salt is integrated over the whole ocean volume 
-$D_\eta$ bounded by the time-dependent free surface. The right hand side (which is an 
-integral over the free surface) vanishes when the nonlinear equation (\ref{Eq_PE_ssh}) 
-is satisfied, so that the salt is perfectly conserved. When the free surface equation is 
-linearized, \citet{Roullet_Madec_JGR00} show that the total salt content integrated in the fixed 
-volume $D$ (bounded by the surface $z=0$) is no longer conserved:
-\begin{equation} \label{Eq_PE_salt_content_linear}
-         \frac{\partial }{\partial t}\int\limits_D {S\;dv} 
-         		= - \int\limits_S {S\;\frac{\partial \eta }{\partial t}ds} 
-\end{equation}
-
-The right hand side of (\ref{Eq_PE_salt_content_linear}) is small in equilibrium solutions 
-\citep{Roullet_Madec_JGR00}. It can be significant when the freshwater forcing is not balanced and 
-the globally averaged free surface is drifting. An increase in sea surface height \textit{$\eta $} 
-results in a decrease of the salinity in the fixed volume $D$. Even in that case though, 
-the total salt integrated in the variable volume $D_{\eta}$ varies much less, since 
-(\ref{Eq_PE_salt_content_linear}) can be rewritten as 
-\begin{equation} \label{Eq_PE_salt_content_corrected}
-\frac{\partial }{\partial t}\int\limits_{D\eta } {S\;dv} 
-=\frac{\partial}{\partial t} \left[ \;{\int\limits_D {S\;dv} +\int\limits_S {S\eta \;ds} } \right]
-=\int\limits_S {\eta \;\frac{\partial S}{\partial t}ds}
-\end{equation}
-
-Although the total salt content is not exactly conserved with the linearized free surface, 
-its variations are driven by correlations of the time variation of surface salinity with the 
-sea surface height, which is a negligible term. This situation contrasts with the case of 
-the rigid lid approximation in which case freshwater forcing is represented by a virtual 
-salt flux, leading to a spurious source of salt at the ocean surface 
-\citep{Huang_JPO93, Roullet_Madec_JGR00}.
-
-\newpage
-$\ $\newline    % force a new ligne
+of the temporal derivatives, using a split-explicit method \citep{Killworth_al_JPO91, Zhang_Endoh_JGR92} 
+or the implicit scheme \citep{Dukowicz1994} or the addition of a filtering force in the momentum equation 
+\citep{Roullet_Madec_JGR00}. With the present release, \NEMO offers the choice between 
+an explicit free surface (see \S\ref{DYN_spg_exp}) or a split-explicit scheme strongly 
+inspired the one proposed by \citet{Shchepetkin_McWilliams_OM05} (see \S\ref{DYN_spg_ts}).
+
+%\newpage
+%$\ $\newline    % force a new ligne
 
 % ================================================================
@@ -655,9 +595,5 @@
 the surface pressure, is given by:
 \begin{equation} \label{Eq_PE_spg}
-p_s = \left\{ \begin{split} 
-\rho \,g \,\eta &                                 \qquad  \qquad  \;   \qquad \text{ standard free surface} \\ 
-\rho \,g \,\eta &+ \rho_o \,\mu \,\frac{\partial \eta }{\partial t}      \qquad \text{ filtered     free surface}    
-\end{split} 
-\right.
+p_s =  \rho \,g \,\eta 
 \end{equation}
 with $\eta$ is solution of \eqref{Eq_PE_ssh}
@@ -773,10 +709,10 @@
 \end{equation}
 
-The equations solved by the ocean model \eqref{Eq_PE} in $s-$coordinate can be written as follows:
+The equations solved by the ocean model \eqref{Eq_PE} in $s-$coordinate can be written as follows (see Appendix~\ref{Apdx_A_momentum}):
 
  \vspace{0.5cm}
-* momentum equation:
+$\bullet$ Vector invariant form of the momentum equation :
 \begin{multline} \label{Eq_PE_sco_u}
-\frac{1}{e_3} \frac{\partial \left(  e_3\,u  \right) }{\partial t}=
+\frac{\partial  u   }{\partial t}=
 	+   \left( {\zeta +f} \right)\,v                                    
 	-   \frac{1}{2\,e_1} \frac{\partial}{\partial i} \left(  u^2+v^2   \right) 
@@ -787,5 +723,5 @@
 \end{multline}
 \begin{multline} \label{Eq_PE_sco_v}
-\frac{1}{e_3} \frac{\partial \left(  e_3\,v  \right) }{\partial t}=
+\frac{\partial v }{\partial t}=
 	-   \left( {\zeta +f} \right)\,u   
 	-   \frac{1}{2\,e_2 }\frac{\partial }{\partial j}\left(  u^2+v^2  \right)     	
@@ -795,9 +731,38 @@
 	+  D_v^{\vect{U}}  +   F_v^{\vect{U}} \quad
 \end{multline}
+
+ \vspace{0.5cm}
+$\bullet$ Vector invariant form of the momentum equation :
+\begin{multline} \label{Eq_PE_sco_u}
+\frac{1}{e_3} \frac{\partial \left(  e_3\,u  \right) }{\partial t}=
+   +   \left( { f + \frac{1}{e_1 \; e_2 }
+					\left( 	 v \frac{\partial e_2}{\partial i}
+						-u \frac{\partial e_1}{\partial j} 	\right)} 	\right) \, v    \\
+   - \frac{1}{e_1 \; e_2 \; e_3 } 	\left( 
+					\frac{\partial \left( {e_2 \, e_3 \, u\,u} \right)}{\partial i}
+		+			\frac{\partial \left( {e_1 \, e_3 \, v\,u} \right)}{\partial j}	\right)
+   - \frac{1}{e_3 }\frac{\partial \left( { \omega\,u} \right)}{\partial k}    \\
+	- \frac{1}{e_1} \frac{\partial}{\partial i} \left( \frac{p_s + p_h}{\rho _o}    \right)    
+	+  g\frac{\rho }{\rho _o}\sigma _1 
+	+   D_u^{\vect{U}}  +   F_u^{\vect{U}} \quad
+\end{multline}
+\begin{multline} \label{Eq_PE_sco_v}
+\frac{1}{e_3} \frac{\partial \left(  e_3\,v  \right) }{\partial t}=
+   -   \left( { f + \frac{1}{e_1 \; e_2}
+					\left( 	 v \frac{\partial e_2}{\partial i}
+						-u \frac{\partial e_1}{\partial j} 	\right)} 	\right) \, u   \\
+   - \frac{1}{e_1 \; e_2 \; e_3 } 	\left( 
+					\frac{\partial \left( {e_2 \; e_3  \,u\,v} \right)}{\partial i}
+		+			\frac{\partial \left( {e_1 \; e_3  \,v\,v} \right)}{\partial j}	\right)
+                 - \frac{1}{e_3 } \frac{\partial \left( { \omega\,v} \right)}{\partial k}    \\
+	-   \frac{1}{e_2 }\frac{\partial }{\partial j}\left( \frac{p_s+p_h }{\rho _o}  \right) 
+	 +  g\frac{\rho }{\rho _o }\sigma _2   
+	+  D_v^{\vect{U}}  +   F_v^{\vect{U}} \quad
+\end{multline}
+
 where the relative vorticity, \textit{$\zeta $}, the surface pressure gradient, and the hydrostatic 
 pressure have the same expressions as in $z$-coordinates although they do not represent 
 exactly the same quantities. $\omega$ is provided by the continuity equation 
 (see Appendix~\ref{Apdx_A}):
-
 \begin{equation} \label{Eq_PE_sco_continuity}
 \frac{\partial e_3}{\partial t} + e_3 \; \chi + \frac{\partial \omega }{\partial s} = 0   
@@ -809,5 +774,5 @@
 
  \vspace{0.5cm}
-* tracer equations:
+$\bullet$ tracer equations:
 \begin{multline} \label{Eq_PE_sco_t}
 \frac{1}{e_3} \frac{\partial \left(  e_3\,T  \right) }{\partial t}=
@@ -1024,5 +989,7 @@
 
 The $\tilde{z}$-coordinate has been developed by \citet{Leclair_Madec_OM10s}.
-It is not available in the current version of \NEMO.
+It is available in \NEMO since the version 3.4. Nevertheless, it is currently not robust enough 
+to be used in all possible configurations. Its use is therefore not recommended.
+We 
 
 \newpage 
@@ -1180,8 +1147,10 @@
 ocean (see Appendix~\ref{Apdx_B}).
 
+For \textit{iso-level} diffusion, $r_1$ and $r_2 $ are zero. $\Re $ reduces to the identity 
+in the horizontal direction, no rotation is applied. 
+
 For \textit{geopotential} diffusion, $r_1$ and $r_2 $ are the slopes between the 
-geopotential and computational surfaces: in $z$-coordinates they are zero 
-($r_1 = r_2 = 0$) while in $s$-coordinate (including $\textit{z*}$ case) they are 
-equal to $\sigma _1$ and $\sigma _2$, respectively (see \eqref{Eq_PE_sco_slope} ).
+geopotential and computational surfaces: they are equal to $\sigma _1$ and $\sigma _2$, 
+respectively (see \eqref{Eq_PE_sco_slope} ).
 
 For \textit{isoneutral} diffusion $r_1$ and $r_2$ are the slopes between the isoneutral 
@@ -1235,10 +1204,9 @@
 The lateral fourth order tracer diffusive operator is defined by:
 \begin{equation} \label{Eq_PE_bilapT}
-D^{lT}=\Delta \left( {A^{lT}\;\Delta T} \right) 
-\qquad \text{where} \  D^{lT}=\Delta \left( {A^{lT}\;\Delta T} \right)
+D^{lT}=\Delta \left( \;\Delta T \right) 
+\qquad \text{where} \;\; \Delta \bullet = \nabla \left( {\sqrt{B^{lT}\,}\;\Re \;\nabla \bullet} \right)
  \end{equation}
-
 It is the second order operator given by \eqref{Eq_PE_iso_tensor} applied twice with 
-the eddy diffusion coefficient correctly placed. 
+the harmonic eddy diffusion coefficient set to the square root of the biharmonic one. 
 
 
@@ -1262,13 +1230,13 @@
 
 Such a formulation ensures a complete separation between the vorticity and 
-horizontal divergence fields (see Appendix~\ref{Apdx_C}). Unfortunately, it is not 
-available for geopotential diffusion in $s-$coordinates and for isoneutral 
-diffusion in both $z$- and $s$-coordinates ($i.e.$ when a rotation is required). 
-In these two cases, the $u$ and $v-$fields are considered as independent scalar 
-fields, so that the diffusive operator is given by:
+horizontal divergence fields (see Appendix~\ref{Apdx_C}). 
+Unfortunately, it is only available in \textit{iso-level} direction. 
+When a rotation is required ($i.e.$ geopotential diffusion in $s-$coordinates 
+or isoneutral diffusion in both $z$- and $s$-coordinates), the $u$ and $v-$fields 
+are considered as independent scalar fields, so that the diffusive operator is given by:
 \begin{equation} \label{Eq_PE_lapU_iso}
 \begin{split}
- D_u^{l{\rm {\bf U}}} &= \nabla .\left( {\Re \;\nabla u} \right) \\ 
- D_v^{l{\rm {\bf U}}} &= \nabla .\left( {\Re \;\nabla v} \right)
+ D_u^{l{\rm {\bf U}}} &= \nabla .\left( {A^{lm} \;\Re \;\nabla u} \right) \\ 
+ D_v^{l{\rm {\bf U}}} &= \nabla .\left( {A^{lm} \;\Re \;\nabla v} \right)
  \end{split}
  \end{equation}
@@ -1282,29 +1250,5 @@
 
 As for tracers, the fourth order momentum diffusive operator along $z$ or $s$-surfaces 
-is a re-entering second order operator \eqref{Eq_PE_lapU} or \eqref{Eq_PE_lapU} 
-with the eddy viscosity coefficient correctly placed:
-
-geopotential diffusion in $z$-coordinate:
-\begin{equation} \label{Eq_PE_bilapU}
-\begin{split}
-{\rm {\bf D}}^{l{\rm {\bf U}}} &=\nabla _h \left\{ {\;\nabla _h {\rm {\bf 
-.}}\left[ {A^{lm}\,\nabla _h \left( \chi \right)} \right]\;} 
-\right\}\;   \\
-&+\nabla _h \times \left\{ {\;{\rm {\bf k}}\cdot \nabla \times 
-\left[ {A^{lm}\,\nabla _h \times \left( {\zeta \;{\rm {\bf k}}} \right)} 
-\right]\;} \right\}
-\end{split}
-\end{equation}
-
-\gmcomment{  change the position of the coefficient, both here and in the code}
-
-geopotential diffusion in $s$-coordinate:
-\begin{equation} \label{Eq_bilapU_iso}
-   \left\{   \begin{aligned}
-         D_u^{l{\rm {\bf U}}} =\Delta \left( {A^{lm}\;\Delta u} \right) \\ 
-         D_v^{l{\rm {\bf U}}} =\Delta \left( {A^{lm}\;\Delta v} \right)
-   \end{aligned}    \right.
-   \quad \text{where} \quad 
-   \Delta \left( \bullet \right) = \nabla \cdot \left( \Re \nabla(\bullet) \right) 
-\end{equation}
-
+is a re-entering second order operator \eqref{Eq_PE_lapU} or \eqref{Eq_PE_lapU_iso} 
+with the harmonic eddy diffusion coefficient set to the square root of the biharmonic one.
+
Index: /trunk/DOC/TexFiles/Chapters/Chap_Model_Basics_zstar.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Chap_Model_Basics_zstar.tex	(revision 6139)
+++ /trunk/DOC/TexFiles/Chapters/Chap_Model_Basics_zstar.tex	(revision 6140)
@@ -1,4 +1,4 @@
 % ================================================================
-% Chapter 1 � Model Basics
+% Chapter 1 ——— Model Basics
 % ================================================================
 % ================================================================
Index: /trunk/DOC/TexFiles/Chapters/Chap_OBS.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Chap_OBS.tex	(revision 6139)
+++ /trunk/DOC/TexFiles/Chapters/Chap_OBS.tex	(revision 6140)
@@ -18,10 +18,10 @@
 location and nearest model timestep. The resulting data are saved in a ``feedback'' file (or
 files). The code was originally developed for use with the NEMOVAR data assimilation code, but
-can be used for validation or verification of model or  any other data assimilation system.
-
-The OBS code is called from \mdl{nemogcm.F90} for model initialisation and to calculate the model
+can be used for validation or verification of the model or with any other data assimilation system.
+
+The OBS code is called from \mdl{nemogcm} for model initialisation and to calculate the model
 equivalent values for observations on the 0th timestep. The code is then called again after
-each timestep from \mdl{step.F90}. To build with the OBS code active \key{diaobs} must be
-set.
+each timestep from \mdl{step}. The code is only activated if the namelist logical \np{ln\_diaobs}
+is set to true.
 
 For all data types a 2D horizontal  interpolator is needed to interpolate the model fields to
@@ -29,13 +29,15 @@
 addition to provide model fields at the observation depths. Currently this only works in
 z-level model configurations, but is being developed to work with a generalised vertical
-coordinate system. Temperature data from moored buoys (TAO, TRITON, PIRATA) in the
-ENACT/ENSEMBLES data-base are available as daily averaged quantities. For this type of
-observation the observation operator will compare such observations to the model temperature
-fields averaged over one day. The relevant observation type may be specified in the namelist
-using \np{endailyavtypes}. Otherwise the model value from the nearest timestep to the
+coordinate system. 
+
+Some profile observation types (e.g. tropical moored buoys) are made available as daily averaged quantities.
+The observation operator code can be set-up to calculated the equivalent daily average model temperature fields
+using the \np{nn\_profdavtypes} namelist array. Some SST observations are equivalent to a night-time
+average value and the observation operator code can calculate equivalent night-time average model SST fields by
+setting the namelist value \np{ln\_sstnight} to true. Otherwise the model value from the nearest timestep to the
 observation time is used.
 
 The code is controlled by the namelist \textit{nam\_obs}. See the following sections for more
-details on setting up the namelist. 
+details on setting up the namelist.
 
 Section~\ref{OBS_example} introduces a test example of the observation operator code including
@@ -59,14 +61,23 @@
 
 \begin{enumerate}
-\item Compile NEMO with \key{diaobs} set.
-
-\item Download some ENSEMBLES EN3 data from 
-\href{http://www.hadobs.org}{http://www.hadobs.org}. Choose observations which are
+\item Compile NEMO.
+
+\item Download some EN4 data from 
+\href{http://www.metoffice.gov.uk/hadobs}{http://www.metoffice.gov.uk/hadobs}. Choose observations which are
 valid for the period of your test run because the observation operator compares
 the model and observations for a matching date and time. 
 
-\item Add the following to the NEMO namelist to run the observation
-operator on this data. Set the \np{enactfiles} namelist variable to the
-observation  file name:
+\item Compile the OBSTOOLS code using: 
+\begin{verbatim}
+./maketools -n OBSTOOLS -m [ARCH].
+\end{verbatim}
+
+\item Convert the EN4 data into feedback format: 
+\begin{verbatim}
+enact2fb.exe profiles_01.nc EN.4.1.1.f.profiles.g10.YYYYMM.nc
+\end{verbatim}
+
+\item Include the following in the NEMO namelist to run the observation
+operator on this data:
 \end{enumerate}
 
@@ -77,7 +88,6 @@
 Options are defined through the  \ngn{namobs} namelist variables.
 The options \np{ln\_t3d} and \np{ln\_s3d} switch on the temperature and salinity
-profile observation operator code. The \np{ln\_ena} switch turns on the reading
-of ENACT/ENSEMBLES type profile data. The filename or array of filenames are
-specified using the \np{enactfiles} variable. The model grid points for a
+profile observation operator code. The filename or array of filenames are
+specified using the \np{cn\_profbfiles} variable. The model grid points for a
 particular  observation latitude and longitude are found using the grid
 searching part of the code. This can be expensive, particularly for large
@@ -92,4 +102,6 @@
 A number of utilities are now provided to plot the feedback files, convert and
 recombine the files. These are explained in more detail in section~\ref{OBS_obsutils}.
+Utilites to convert other input data formats into the feedback format are also 
+described in section~\ref{OBS_obsutils}.
 
 \section{Technical details}
@@ -104,6 +116,6 @@
 %-------------------------------------------------------------------------------------------------------------
 
-This name list uses the "feedback" type observation file input format for
-profile, sea level anomaly and sea surface temperature data. All the
+The observation operator code uses the "feedback" observation file format for
+all data types. All the
 observation files must be in NetCDF format. Some example headers (produced using
 \mbox{\textit{ncdump~-h}}) for profile
Index: /trunk/DOC/TexFiles/Chapters/Chap_SBC.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Chap_SBC.tex	(revision 6139)
+++ /trunk/DOC/TexFiles/Chapters/Chap_SBC.tex	(revision 6140)
@@ -49,6 +49,5 @@
 (\np{nn\_ice}~=~0,1, 2 or 3); the addition of river runoffs as surface freshwater 
 fluxes or lateral inflow (\np{ln\_rnf}~=~true); the addition of isf melting as lateral inflow (parameterisation) 
-(\np{nn\_isf}~=~2 or 3 and \np{ln\_isfcav}~=~false) or as surface flux at the land-ice ocean interface
-(\np{nn\_isf}~=~1 or 4 and \np{ln\_isfcav}~=~true); 
+ or as surface flux at the land-ice ocean interface (\np{ln\_isf}=~true); 
 the addition of a freshwater flux adjustment in order to avoid a mean sea-level drift (\np{nn\_fwb}~=~0,~1~or~2); the 
 transformation of the solar radiation (if provided as daily mean) into a diurnal 
@@ -958,8 +957,9 @@
 \namdisplay{namsbc_isf}
 %--------------------------------------------------------------------------------------------------------
-Namelist variable in \ngn{namsbc}, \np{nn\_isf},  control the kind of ice shelf representation used. 
+Namelist variable in \ngn{namsbc}, \np{nn\_isf}, control the kind of ice shelf representation used. 
 \begin{description}
 \item[\np{nn\_isf}~=~1]
-The ice shelf cavity is represented. The fwf and heat flux are computed. 
+The ice shelf cavity is represented. The fwf and heat flux are computed. 2 bulk formulations are available: the ISOMIP one (\np{nn\_isfblk = 1}) described in (\np{nn\_isfblk = 2}), the 3 equation formulation described in \citet{Jenkins1991}. In addition to this, 
+3 different way to compute the exchange coefficient are available. $\gamma\_{T/S}$ is constant (\np{nn\_gammablk = 0}), $\gamma\_{T/S}$ is velocity dependant \citep{Jenkins2010} (\np{nn\_gammablk = 1}) and $\gamma\_{T/S}$ is velocity dependant and stratification dependent \citep{Holland1999} (\np{nn\_gammablk = 2}). For each of them, the thermal/salt exchange coefficient (\np{rn\_gammat0} and \np{rn\_gammas0}) have to be specified (the default values are for the ISOMIP case). 
 Full description, sensitivity and validation in preparation. 
 
@@ -969,5 +969,5 @@
 (\np{sn\_depmax\_isf}) and the base of the ice shelf along the calving front (\np{sn\_depmin\_isf}) as in (\np{nn\_isf}~=~3). 
 Furthermore the fwf is computed using the \citet{Beckmann2003} parameterisation of isf melting. 
-The effective melting length (\np{sn\_Leff\_isf}) is read from a file.
+The effective melting length (\np{sn\_Leff\_isf}) is read from a file and the exchange coefficients are set as (\np{rn\_gammat0}) and (\np{rn\_gammas0}).
 
 \item[\np{nn\_isf}~=~3]
@@ -987,13 +987,45 @@
 \np{nn\_isf}~=~3 and \np{nn\_isf}~=~4 read the melt rate and heat flux from a file. You have total control of the fwf scenario.
 
- This can be usefull if the water masses on the shelf are not realistic or the resolution (horizontal/vertical) are too 
+This can be usefull if the water masses on the shelf are not realistic or the resolution (horizontal/vertical) are too 
 coarse to have realistic melting or for sensitivity studies where you want to control your input. 
 Full description, sensitivity and validation in preparation. 
 
-There is 2 ways to apply the fwf to NEMO. The first possibility (\np{ln\_divisf}~=~false) applied the fwf
- and heat flux directly on the salinity and temperature tendancy. The second possibility (\np{ln\_divisf}~=~true)
- apply the fwf as for the runoff fwf (see \S\ref{SBC_rnf}). The mass/volume addition due to the ice shelf melting is,
- at each relevant depth level, added to the horizontal divergence (\textit{hdivn}) in the subroutine \rou{sbc\_isf\_div} 
-(called from \mdl{divcur}). 
+\np{rn\_hisf\_tbl} is the top boundary layer (tbl) thickness used by the Losch parametrisation \citep{Losch2008} to compute the melt. if 0, temperature/salt/velocity in the top cell is used to compute the melt.
+Otherwise, NEMO used the mean value into the tbl. 
+
+\section{ Ice sheet coupling}
+\label{SBC_iscpl}
+%------------------------------------------namsbc_iscpl----------------------------------------------------
+\namdisplay{namsbc_iscpl}
+%--------------------------------------------------------------------------------------------------------
+Ice sheet/ocean coupling is done through file exchange at the restart step. NEMO, at each restart step, 
+read the bathymetry and ice shelf draft variable in a netcdf file. 
+If \np{ln\_iscpl = ~true}, the isf draft is assume to be different at each restart step 
+with potentially some new wet/dry cells due to the ice sheet dynamics/thermodynamics.
+The wetting and drying scheme applied on the restart is very simple and described below for the 6 different cases:
+\begin{description}
+\item[Thin a cell down:]
+	T/S/ssh are unchanged and U/V in the top cell are corrected to keep the barotropic transport (bt) constant ($bt_b=bt_n$).
+\item[Enlarge  a cell:]
+	See case "Thin a cell down"
+\item[Dry a cell:]
+	mask, T/S, U/V and ssh are set to 0. Furthermore, U/V into the water column are modified to satisfy ($bt_b=bt_n$).
+\item[Wet a cell:] 
+	mask is set to 1, T/S is extrapolated from neighbours, $ssh_n = ssh_b$ and U/V set to 0. If no neighbours along i,j and k, T/S/U/V and mask are set to 0.
+\item[Dry a column:]
+	mask, T/S, U/V are set to 0 everywhere in the column and ssh set to 0.
+\item[Wet a column:]
+	set mask to 1, T/S is extrapolated from neighbours, ssh is extrapolated from neighbours and U/V set to 0. If no neighbour, T/S/U/V and mask set to 0.
+\end{description}
+The extrapolation is call \np{nn\_drown} times. It means that if the grounding line retreat by more than \np{nn\_drown} cells between 2 coupling steps,
+ the code will be unable to fill all the new wet cells properly. The default number is set up for the MISOMIP idealised experiments.\\
+This coupling procedure is able to take into account grounding line and calving front migration. However, it is a non-conservative processe. 
+This could lead to a trend in heat/salt content and volume. In order to remove the trend and keep the conservation level as close to 0 as possible,
+ a simple conservation scheme is available with \np{ln\_hsb = ~true}. The heat/salt/vol. gain/loss is diagnose, as well as the location. 
+Based on what is done on sbcrnf to prescribed a source of heat/salt/vol., the heat/salt/vol. gain/loss is removed/added,
+ over a period of \np{rn\_fiscpl} time step, into the system. 
+So after \np{rn\_fiscpl} time step, all the heat/salt/vol. gain/loss due to extrapolation process is canceled.\\
+
+As the before and now fields are not compatible (modification of the geometry), the restart time step is prescribed to be an euler time step instead of a leap frog and $fields_b = fields_n$.
 %
 % ================================================================
Index: /trunk/DOC/TexFiles/Chapters/Chap_STP.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Chap_STP.tex	(revision 6139)
+++ /trunk/DOC/TexFiles/Chapters/Chap_STP.tex	(revision 6140)
@@ -1,5 +1,5 @@
 
 % ================================================================
-% Chapter 2 � Time Domain (step.F90)
+% Chapter 2 ——— Time Domain (step.F90)
 % ================================================================
 \chapter{Time Domain (STP) }
@@ -21,5 +21,7 @@
 
 Having defined the continuous equations in Chap.~\ref{PE}, we need now to choose 
-a time discretization. In the present chapter, we provide a general description of the \NEMO 
+a time discretization, a key feature of an ocean model as it exerts a strong influence  
+on the structure of the computer code ($i.e.$ on its flowchart). 
+In the present chapter, we provide a general description of the \NEMO 
 time stepping strategy and the consequences for the order in which the equations are
 solved.
@@ -158,4 +160,8 @@
 \end{equation} 
 
+%%gm
+%%gm   UPDATE the next paragraphs with time varying thickness ...
+%%gm
+
 This scheme is rather time consuming since it requires a matrix inversion, 
 but it becomes attractive since a value of 3 or more is needed for N in
@@ -188,8 +194,10 @@
 
 % -------------------------------------------------------------------------------------------------------------
-%        Hydrostatic Pressure gradient
-% -------------------------------------------------------------------------------------------------------------
-\section{Hydrostatic Pressure Gradient --- semi-implicit scheme}
-\label{STP_hpg_imp}
+%        Surface Pressure gradient
+% -------------------------------------------------------------------------------------------------------------
+\section{Surface Pressure Gradient}
+\label{STP_spg_ts}
+
+===>>>>  TO BE written....  :-)
 
 %\gmcomment{ 
@@ -209,34 +217,4 @@
 %>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 %}
-
-The range of stability of the Leap-Frog scheme can be extended by a factor of two
-by introducing a semi-implicit computation of the hydrostatic pressure gradient term
-\citep{Brown_Campana_MWR78}. Instead of evaluating the pressure at $t$, a linear 
-combination of values at $t-\rdt$, $t$ and $t+\rdt$ is used (see \S~\ref{DYN_hpg_imp}).  
-This technique, controlled by the \np{nn\_dynhpg\_rst} namelist parameter, does not 
-introduce a significant additional computational cost when tracers and thus density 
-is time stepped before the dynamics. This time step ordering is used in \NEMO 
-(Fig.\ref{Fig_TimeStep_flowchart}).
-
-
-This technique, used in several GCMs (\NEMO, POP or MOM for instance), 
-makes the Leap-Frog scheme as efficient 
-\footnote{The efficiency is defined as the maximum allowed Courant number of the time 
-stepping scheme divided by the number of computations of the right-hand side per time step.} 
-as the Forward-Backward scheme used in MOM \citep{Griffies_al_OS05} and more 
-efficient than the LF-AM3 scheme (leapfrog time stepping combined with a third order
-Adams-Moulthon interpolation for the predictor phase) used in ROMS 
-\citep{Shchepetkin_McWilliams_OM05}. 
-
-In fact, this technique is efficient when the physical phenomenon that 
-limits the time-step is internal gravity waves (IGWs). Indeed, it is 
-equivalent to applying a time filter to the pressure gradient to eliminate high 
-frequency IGWs. Obviously, the doubling of the time-step is achievable only 
-if no other factors control the time-step, such as the stability limits associated 
-with advection, diffusion or Coriolis terms. For example, it is inefficient in low resolution
-global ocean configurations, since inertial oscillations in the vicinity of the North Pole 
-are the limiting factor for the time step. It is also often inefficient in very high 
-resolution configurations where strong currents and small grid cells exert 
-the strongest constraint on the time step.
 
 % -------------------------------------------------------------------------------------------------------------
Index: /trunk/DOC/TexFiles/Chapters/Chap_TRA.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Chap_TRA.tex	(revision 6139)
+++ /trunk/DOC/TexFiles/Chapters/Chap_TRA.tex	(revision 6140)
@@ -1,4 +1,4 @@
 % ================================================================
-% Chapter 1 � Ocean Tracers (TRA)
+% Chapter 1 ——— Ocean Tracers (TRA)
 % ================================================================
 \chapter{Ocean Tracers (TRA)}
@@ -40,9 +40,7 @@
 described in chapters \S\ref{SBC}, \S\ref{LDF} and  \S\ref{ZDF}, respectively. 
 Note that \mdl{tranpc}, the non-penetrative convection module,  although 
-(temporarily) located in the NEMO/OPA/TRA directory, is described with the 
-model vertical physics (ZDF).
-%%%
-\gmcomment{change the position of eosbn2 in the reference code}
-%%%
+located in the NEMO/OPA/TRA directory as it directly modifies the tracer fields, 
+is described with the model vertical physics (ZDF) together with other available 
+parameterization of convection.
 
 In the present chapter we also describe the diagnostic equations used to compute 
@@ -50,12 +48,12 @@
 freezing point with associated modules \mdl{eosbn2} and \mdl{phycst}).
 
-The different options available to the user are managed by namelist logicals or 
-CPP keys. For each equation term \textit{ttt}, the namelist logicals are \textit{ln\_trattt\_xxx}, 
+The different options available to the user are managed by namelist logicals or CPP keys. 
+For each equation term  \textit{TTT}, the namelist logicals are \textit{ln\_traTTT\_xxx}, 
 where \textit{xxx} is a 3 or 4 letter acronym corresponding to each optional scheme. 
-The CPP key (when it exists) is \textbf{key\_trattt}. The equivalent code can be 
-found in the \textit{trattt} or \textit{trattt\_xxx} module, in the NEMO/OPA/TRA directory.
+The CPP key (when it exists) is \textbf{key\_traTTT}. The equivalent code can be 
+found in the \textit{traTTT} or \textit{traTTT\_xxx} module, in the NEMO/OPA/TRA directory.
 
 The user has the option of extracting each tendency term on the rhs of the tracer 
-equation for output (\key{trdtra} is defined), as described in Chap.~\ref{MISC}.
+equation for output (\np{ln\_tra\_trd} or \np{ln\_tra\_mxl}~=~true), as described in Chap.~\ref{MISC}.
 
 $\ $\newline    % force a new ligne
@@ -82,10 +80,10 @@
 implicitly requires the use of the continuity equation. Indeed, it is obtained
 by using the following equality : $\nabla \cdot \left( \vect{U}\,T \right)=\vect{U} \cdot \nabla T$ 
-which results from the use of the continuity equation, $\nabla \cdot \vect{U}=0$ or 
-$ \partial _t e_3 + e_3\;\nabla \cdot \vect{U}=0$ in constant volume or variable volume case, respectively. 
+which results from the use of the continuity equation,  $\partial _t e_3 + e_3\;\nabla \cdot \vect{U}=0$ 
+(which reduces to $\nabla \cdot \vect{U}=0$ in linear free surface, $i.e.$ \np{ln\_linssh}=true). 
 Therefore it is of paramount importance to design the discrete analogue of the 
 advection tendency so that it is consistent with the continuity equation in order to 
 enforce the conservation properties of the continuous equations. In other words, 
-by replacing $\tau$ by the number 1 in (\ref{Eq_tra_adv}) we recover the discrete form of 
+by setting $\tau = 1$ in (\ref{Eq_tra_adv}) we recover the discrete form of 
 the continuity equation which is used to calculate the vertical velocity.
 %>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -113,5 +111,5 @@
 boundary condition depends on the type of sea surface chosen: 
 \begin{description}
-\item [linear free surface:] the first level thickness is constant in time: 
+\item [linear free surface:] (\np{ln\_linssh}=true) the first level thickness is constant in time: 
 the vertical boundary condition is applied at the fixed surface $z=0$ 
 rather than on the moving surface $z=\eta$. There is a non-zero advective 
@@ -119,5 +117,5 @@
 $\left. {\tau _w } \right|_{k=1/2} =T_{k=1} $, $i.e.$ 
 the product of surface velocity (at $z=0$) by the first level tracer value.
-\item [non-linear free surface:] (\key{vvl} is defined) 
+\item [non-linear free surface:] (\np{ln\_linssh}=false) 
 convergence/divergence in the first ocean level moves the free surface 
 up/down. There is no tracer advection through it so that the advective 
@@ -125,29 +123,37 @@
 \end{description}
 In all cases, this boundary condition retains local conservation of tracer. 
-Global conservation is obtained in both rigid-lid and non-linear free surface 
-cases, but not in the linear free surface case. Nevertheless, in the latter
-case, it is achieved to a good approximation since the non-conservative 
+Global conservation is obtained in non-linear free surface case, 
+but \textit{not} in the linear free surface case. Nevertheless, in the latter case, 
+it is achieved to a good approximation since the non-conservative 
 term is the product of the time derivative of the tracer and the free surface 
-height, two quantities that are not correlated (see \S\ref{PE_free_surface}, 
-and also \citet{Roullet_Madec_JGR00,Griffies_al_MWR01,Campin2004}).
+height, two quantities that are not correlated \citep{Roullet_Madec_JGR00,Griffies_al_MWR01,Campin2004}.
 
 The velocity field that appears in (\ref{Eq_tra_adv}) and (\ref{Eq_tra_adv_zco}) 
-is the centred (\textit{now}) \textit{eulerian} ocean velocity (see Chap.~\ref{DYN}). 
-When eddy induced velocity (\textit{eiv}) parameterisation is used it is the \textit{now} 
-\textit{effective} velocity ($i.e.$ the sum of the eulerian and eiv velocities) which is used.
-
-The choice of an advection scheme is made in the \textit{\ngn{nam\_traadv}} namelist, by 
-setting to \textit{true} one and only one of the logicals \textit{ln\_traadv\_xxx}. The 
-corresponding code can be found in the \textit{traadv\_xxx.F90} module, where 
-\textit{xxx} is a 3 or 4 letter acronym corresponding to each scheme. Details 
-of the advection schemes are given below. The choice of an advection scheme 
+is the centred (\textit{now}) \textit{effective} ocean velocity, $i.e.$ the \textit{eulerian} velocity
+(see Chap.~\ref{DYN}) plus the eddy induced velocity (\textit{eiv}) 
+and/or the mixed layer eddy induced velocity (\textit{eiv})
+when those parameterisations are used (see Chap.~\ref{LDF}).
+
+Several tracer advection scheme are proposed, namely 
+a $2^{nd}$ or $4^{th}$ order centred schemes (CEN), 
+a $2^{nd}$ or $4^{th}$ order Flux Corrected Transport scheme (FCT),
+a Monotone Upstream Scheme for Conservative Laws scheme (MUSCL),
+a $3^{rd}$ Upstream Biased Scheme (UBS, also often called UP3), and
+a Quadratic Upstream Interpolation for Convective Kinematics with 
+Estimated Streaming Terms scheme (QUICKEST).
+The choice is made in the \textit{\ngn{namtra\_adv}} namelist, by 
+setting to \textit{true} one of the logicals \textit{ln\_traadv\_xxx}. 
+The corresponding code can be found in the \textit{traadv\_xxx.F90} module, 
+where \textit{xxx} is a 3 or 4 letter acronym corresponding to each scheme. 
+By default ($i.e.$ in the reference namelist, \ngn{namelist\_ref}), all the logicals 
+are set to \textit{false}. If the user does not select an advection scheme 
+in the configuration namelist (\ngn{namelist\_cfg}), the tracers will \textit{not} be advected !
+
+Details of the advection schemes are given below. The choosing an advection scheme 
 is a complex matter which depends on the model physics, model resolution, 
-type of tracer, as well as the issue of numerical cost. 
-
-Note that 
-(1) cen2, cen4 and TVD schemes require an explicit diffusion 
-operator while the other schemes are diffusive enough so that they do not 
-require additional diffusion ; 
-(2) cen2, cen4, MUSCL2, and UBS are not \textit{positive} schemes
+type of tracer, as well as the issue of numerical cost. In particular, we note that
+(1) CEN and FCT schemes require an explicit diffusion operator 
+while the other schemes are diffusive enough so that they do not necessarily need additional diffusion ; 
+(2) CEN and UBS are not \textit{positive} schemes
 \footnote{negative values can appear in an initially strictly positive tracer field 
 which is advected}
@@ -163,12 +169,19 @@
 
 % -------------------------------------------------------------------------------------------------------------
+%        2nd and 4th order centred schemes
+% -------------------------------------------------------------------------------------------------------------
+\subsection [centred schemes (CEN) (\np{ln\_traadv\_cen})]
+			   {centred schemes (CEN) (\np{ln\_traadv\_cen}=true)}
+\label{TRA_adv_cen}
+
 %        2nd order centred scheme  
-% -------------------------------------------------------------------------------------------------------------
-\subsection   [$2^{nd}$ order centred scheme (cen2) (\np{ln\_traadv\_cen2})]
-			{$2^{nd}$ order centred scheme (cen2) (\np{ln\_traadv\_cen2}=true)}
-\label{TRA_adv_cen2}
-
-In the centred second order formulation, the tracer at velocity points is 
-evaluated as the mean of the two neighbouring $T$-point values. 
+
+The centred advection scheme (CEN) is used when \np{ln\_traadv\_cen}~=~\textit{true}. 
+Its order ($2^{nd}$ or $4^{th}$) can be chosen independently on horizontal (iso-level) 
+and vertical direction by setting \np{nn\_cen\_h} and \np{nn\_cen\_v} to $2$ or $4$. 
+CEN implementation can be found in the \mdl{traadv\_cen} module.
+
+In the $2^{nd}$ order centred formulation (CEN2), the tracer at velocity points 
+is evaluated as the mean of the two neighbouring $T$-point values. 
 For example, in the $i$-direction :
 \begin{equation} \label{Eq_tra_adv_cen2}
@@ -176,73 +189,70 @@
 \end{equation}
 
-The scheme is non diffusive ($i.e.$ it conserves the tracer variance, $\tau^2)$ 
+CEN2 is non diffusive ($i.e.$ it conserves the tracer variance, $\tau^2)$ 
 but dispersive ($i.e.$ it may create false extrema). It is therefore notoriously 
 noisy and must be used in conjunction with an explicit diffusion operator to 
 produce a sensible solution. The associated time-stepping is performed using 
 a leapfrog scheme in conjunction with an Asselin time-filter, so $T$ in 
-(\ref{Eq_tra_adv_cen2}) is the \textit{now} tracer value. The centered second 
-order advection is computed in the \mdl{traadv\_cen2} module. In this module,
-it is advantageous to combine the \textit{cen2} scheme with an upstream scheme
-in specific areas which require a strong diffusion in order to avoid the generation 
-of false extrema. These areas are the vicinity of large river mouths, some straits 
-with coarse resolution, and the vicinity of ice cover area ($i.e.$ when the ocean 
-temperature is close to the freezing point).
-This combined scheme has been included for specific grid points in the ORCA2 
-and ORCA4 configurations only. This is an obsolescent feature as the recommended 
-advection scheme for the ORCA configuration is TVD (see  \S\ref{TRA_adv_tvd}).
-
-Note that using the cen2 scheme, the overall tracer advection is of second 
+(\ref{Eq_tra_adv_cen2}) is the \textit{now} tracer value. 
+
+Note that using the CEN2, the overall tracer advection is of second 
 order accuracy since both (\ref{Eq_tra_adv}) and (\ref{Eq_tra_adv_cen2}) 
-have this order of accuracy. \gmcomment{Note also that ... blah, blah}
-
-% -------------------------------------------------------------------------------------------------------------
+have this order of accuracy.
+
 %        4nd order centred scheme  
-% -------------------------------------------------------------------------------------------------------------
-\subsection   [$4^{nd}$ order centred scheme (cen4) (\np{ln\_traadv\_cen4})]
-		     {$4^{nd}$ order centred scheme (cen4) (\np{ln\_traadv\_cen4}=true)}
-\label{TRA_adv_cen4}
-
-In the $4^{th}$ order formulation (to be implemented), tracer values are 
-evaluated at velocity points as a $4^{th}$ order interpolation, and thus depend on 
-the four neighbouring $T$-points. For example, in the $i$-direction:
+
+In the $4^{th}$ order formulation (CEN4), tracer values are evaluated at u- and v-points as 
+a $4^{th}$ order interpolation, and thus depend on the four neighbouring $T$-points. 
+For example, in the $i$-direction:
 \begin{equation} \label{Eq_tra_adv_cen4}
 \tau _u^{cen4} 
 =\overline{   T - \frac{1}{6}\,\delta _i \left[ \delta_{i+1/2}[T] \,\right]   }^{\,i+1/2}
 \end{equation}
-
-Strictly speaking, the cen4 scheme is not a $4^{th}$ order advection scheme 
+In the vertical direction (\np{nn\_cen\_v}=$4$), a $4^{th}$ COMPACT interpolation 
+has been prefered \citep{Demange_PhD2014}.
+In the COMPACT scheme, both the field and its derivative are interpolated, 
+which leads, after a matrix inversion, spectral characteristics 
+similar to schemes of higher order \citep{Lele_JCP1992}.
+ 
+
+Strictly speaking, the CEN4 scheme is not a $4^{th}$ order advection scheme 
 but a $4^{th}$ order evaluation of advective fluxes, since the divergence of 
-advective fluxes \eqref{Eq_tra_adv} is kept at $2^{nd}$ order. The phrase ``$4^{th}$ 
-order scheme'' used in oceanographic literature is usually associated 
-with the scheme presented here. Introducing a \textit{true} $4^{th}$ order advection 
-scheme is feasible but, for consistency reasons, it requires changes in the 
-discretisation of the tracer advection together with changes in both the 
-continuity equation and the momentum advection terms.  
+advective fluxes \eqref{Eq_tra_adv} is kept at $2^{nd}$ order. 
+The expression \textit{$4^{th}$ order scheme} used in oceanographic literature 
+is usually associated with the scheme presented here. 
+Introducing a \textit{true} $4^{th}$ order advection scheme is feasible but, 
+for consistency reasons, it requires changes in the discretisation of the tracer 
+advection together with changes in the continuity equation, 
+and the momentum advection and pressure terms.  
 
 A direct consequence of the pseudo-fourth order nature of the scheme is that 
-it is not non-diffusive, i.e. the global variance of a tracer is not preserved using 
-\textit{cen4}. Furthermore, it must be used in conjunction with an explicit 
-diffusion operator to produce a sensible solution. The time-stepping is also 
-performed using a leapfrog scheme in conjunction with an Asselin time-filter, 
-so $T$ in (\ref{Eq_tra_adv_cen4}) is the \textit{now} tracer.
-
-At a $T$-grid cell adjacent to a boundary (coastline, bottom and surface), an 
-additional hypothesis must be made to evaluate $\tau _u^{cen4}$. This 
-hypothesis usually reduces the order of the scheme. Here we choose to set 
-the gradient of $T$ across the boundary to zero. Alternative conditions can be 
-specified, such as a reduction to a second order scheme for these near boundary 
-grid points.
-
-% -------------------------------------------------------------------------------------------------------------
-%        TVD scheme  
-% -------------------------------------------------------------------------------------------------------------
-\subsection   [Total Variance Dissipation scheme (TVD) (\np{ln\_traadv\_tvd})]
-			{Total Variance Dissipation scheme (TVD) (\np{ln\_traadv\_tvd}=true)}
+it is not non-diffusive, $i.e.$ the global variance of a tracer is not preserved using CEN4. 
+Furthermore, it must be used in conjunction with an explicit diffusion operator 
+to produce a sensible solution. 
+As in CEN2 case, the time-stepping is performed using a leapfrog scheme in conjunction 
+with an Asselin time-filter, so $T$ in (\ref{Eq_tra_adv_cen4}) is the \textit{now} tracer.
+
+At a $T$-grid cell adjacent to a boundary (coastline, bottom and surface), 
+an additional hypothesis must be made to evaluate $\tau _u^{cen4}$. 
+This hypothesis usually reduces the order of the scheme. 
+Here we choose to set the gradient of $T$ across the boundary to zero. 
+Alternative conditions can be specified, such as a reduction to a second order scheme 
+for these near boundary grid points.
+
+% -------------------------------------------------------------------------------------------------------------
+%        FCT scheme  
+% -------------------------------------------------------------------------------------------------------------
+\subsection   [Flux Corrected Transport schemes (FCT) (\np{ln\_traadv\_fct})]
+			{Flux Corrected Transport schemes (FCT) (\np{ln\_traadv\_fct}=true)}
 \label{TRA_adv_tvd}
 
-In the Total Variance Dissipation (TVD) formulation, the tracer at velocity 
-points is evaluated using a combination of an upstream and a centred scheme. 
-For example, in the $i$-direction :
-\begin{equation} \label{Eq_tra_adv_tvd}
+The Flux Corrected Transport schemes (FCT) is used when \np{ln\_traadv\_fct}~=~\textit{true}. 
+Its order ($2^{nd}$ or $4^{th}$) can be chosen independently on horizontal (iso-level) 
+and vertical direction by setting \np{nn\_fct\_h} and \np{nn\_fct\_v} to $2$ or $4$.
+FCT implementation can be found in the \mdl{traadv\_fct} module.
+
+In FCT formulation, the tracer at velocity points is evaluated using a combination of 
+an upstream and a centred scheme. For example, in the $i$-direction :
+\begin{equation} \label{Eq_tra_adv_fct}
 \begin{split}
 \tau _u^{ups}&= \begin{cases}
@@ -251,35 +261,44 @@
 				  \end{cases}     \\
 \\
-\tau _u^{tvd}&=\tau _u^{ups} +c_u \;\left( {\tau _u^{cen2} -\tau _u^{ups} } \right)
+\tau _u^{fct}&=\tau _u^{ups} +c_u \;\left( {\tau _u^{cen} -\tau _u^{ups} } \right)
 \end{split}
 \end{equation}
 where $c_u$ is a flux limiter function taking values between 0 and 1. 
+The FCT order is the one of the centred scheme used ($i.e.$ it depends on the setting of
+\np{nn\_fct\_h} and \np{nn\_fct\_v}.
 There exist many ways to define $c_u$, each corresponding to a different 
-total variance decreasing scheme. The one chosen in \NEMO is described in 
-\citet{Zalesak_JCP79}. $c_u$ only departs from $1$ when the advective term 
-produces a local extremum in the tracer field. The resulting scheme is quite 
-expensive but \emph{positive}. It can be used on both active and passive tracers. 
-This scheme is tested and compared with MUSCL and the MPDATA scheme in 
-\citet{Levy_al_GRL01}; note that in this paper it is referred to as "FCT" (Flux corrected 
-transport) rather than TVD. The TVD scheme is implemented in the \mdl{traadv\_tvd} module.
-
-For stability reasons (see \S\ref{STP}),
-$\tau _u^{cen2}$ is evaluated  in (\ref{Eq_tra_adv_tvd}) using the \textit{now} tracer while $\tau _u^{ups}$ 
-is evaluated using the \textit{before} tracer. In other words, the advective part of 
-the scheme is time stepped with a leap-frog scheme while a forward scheme is 
-used for the diffusive part. 
+FCT scheme. The one chosen in \NEMO is described in \citet{Zalesak_JCP79}. 
+$c_u$ only departs from $1$ when the advective term produces a local extremum in the tracer field. 
+The resulting scheme is quite expensive but \emph{positive}. 
+It can be used on both active and passive tracers. 
+A comparison of FCT-2 with MUSCL and a MPDATA scheme can be found in \citet{Levy_al_GRL01}. 
+
+An additional option has been added controlled by \np{nn\_fct\_zts}. By setting this integer to 
+a value larger than zero, a $2^{nd}$ order FCT scheme is used on both horizontal and vertical direction, 
+but on the latter, a split-explicit time stepping is used, with a number of sub-timestep equals
+to \np{nn\_fct\_zts}. This option can be useful when the size of the timestep is limited 
+by vertical advection \citep{Lemarie_OM2015)}. Note that in this case, a similar split-explicit 
+time stepping should be used on vertical advection of momentum to insure a better stability
+(see \S\ref{DYN_zad}).
+
+For stability reasons (see \S\ref{STP}), $\tau _u^{cen}$ is evaluated in (\ref{Eq_tra_adv_fct}) 
+using the \textit{now} tracer while $\tau _u^{ups}$ is evaluated using the \textit{before} tracer. In other words, 
+the advective part of the scheme is time stepped with a leap-frog scheme 
+while a forward scheme is used for the diffusive part. 
 
 % -------------------------------------------------------------------------------------------------------------
 %        MUSCL scheme  
 % -------------------------------------------------------------------------------------------------------------
-\subsection[MUSCL scheme  (\np{ln\_traadv\_muscl})]
-	{Monotone Upstream Scheme for Conservative Laws (MUSCL) (\np{ln\_traadv\_muscl}=T)}
-\label{TRA_adv_muscl}
-
-The Monotone Upstream Scheme for Conservative Laws (MUSCL) has been 
-implemented by \citet{Levy_al_GRL01}. In its formulation, the tracer at velocity points 
+\subsection[MUSCL scheme  (\np{ln\_traadv\_mus})]
+	{Monotone Upstream Scheme for Conservative Laws (MUSCL) (\np{ln\_traadv\_mus}=T)}
+\label{TRA_adv_mus}
+
+The Monotone Upstream Scheme for Conservative Laws (MUSCL) is used when \np{ln\_traadv\_mus}~=~\textit{true}. 
+MUSCL implementation can be found in the \mdl{traadv\_mus} module.
+
+MUSCL has been first implemented in \NEMO by \citet{Levy_al_GRL01}. In its formulation, the tracer at velocity points 
 is evaluated assuming a linear tracer variation between two $T$-points 
 (Fig.\ref{Fig_adv_scheme}). For example, in the $i$-direction :
-\begin{equation} \label{Eq_tra_adv_muscl}
+\begin{equation} \label{Eq_tra_adv_mus}
    \tau _u^{mus} = \left\{      \begin{aligned}
          &\tau _i  &+ \frac{1}{2} \;\left( 1-\frac{u_{i+1/2} \;\rdt}{e_{1u}} \right)
@@ -296,10 +315,8 @@
 
 For an ocean grid point adjacent to land and where the ocean velocity is 
-directed toward land, two choices are available: an upstream flux 
-(\np{ln\_traadv\_muscl}=true) or a second order flux 
-(\np{ln\_traadv\_muscl2}=true). Note that the latter choice does not ensure 
-the \textit{positive} character of the scheme. Only the former can be used 
-on both active and passive tracers. The two MUSCL schemes are implemented 
-in the \mdl{traadv\_tvd} and \mdl{traadv\_tvd2} modules.
+directed toward land, an upstream flux is used. This choice ensure 
+the \textit{positive} character of the scheme. 
+In addition, fluxes round a grid-point where a runoff is applied can optionally be 
+computed using upstream fluxes (\np{ln\_mus\_ups}~=~\textit{true}).
 
 % -------------------------------------------------------------------------------------------------------------
@@ -310,8 +327,11 @@
 \label{TRA_adv_ubs}
 
-The UBS advection scheme is an upstream-biased third order scheme based on 
-an upstream-biased parabolic interpolation. It is also known as the Cell 
-Averaged QUICK scheme (Quadratic Upstream Interpolation for Convective 
-Kinematics). For example, in the $i$-direction :
+The Upstream-Biased Scheme (UBS) is used when \np{ln\_traadv\_ubs}~=~\textit{true}. 
+UBS implementation can be found in the \mdl{traadv\_mus} module.
+
+The UBS scheme, often called UP3, is also known as the Cell Averaged QUICK scheme 
+(Quadratic Upstream Interpolation for Convective Kinematics). It is an upstream-biased 
+third order scheme based on an upstream-biased parabolic interpolation.  
+For example, in the $i$-direction :
 \begin{equation} \label{Eq_tra_adv_ubs}
    \tau _u^{ubs} =\overline T ^{i+1/2}-\;\frac{1}{6} \left\{      
@@ -324,21 +344,21 @@
 
 This results in a dissipatively dominant (i.e. hyper-diffusive) truncation 
-error \citep{Shchepetkin_McWilliams_OM05}. The overall performance of the advection 
-scheme is similar to that reported in \cite{Farrow1995}. 
+error \citep{Shchepetkin_McWilliams_OM05}. The overall performance of
+ the advection scheme is similar to that reported in \cite{Farrow1995}. 
 It is a relatively good compromise between accuracy and smoothness. 
-It is not a \emph{positive} scheme, meaning that false extrema are permitted, 
+Nevertheless the scheme is not \emph{positive}, meaning that false extrema are permitted, 
 but the amplitude of such are significantly reduced over the centred second 
-order method. Nevertheless it is not recommended that it should be applied 
-to a passive tracer that requires positivity. 
+or fourth order method. therefore it is not recommended that it should be 
+applied to a passive tracer that requires positivity. 
 
 The intrinsic diffusion of UBS makes its use risky in the vertical direction 
-where the control of artificial diapycnal fluxes is of paramount importance. 
-Therefore the vertical flux is evaluated using the TVD scheme when 
-\np{ln\_traadv\_ubs}=true.
+where the control of artificial diapycnal fluxes is of paramount importance \citep{Shchepetkin_McWilliams_OM05, Demange_PhD2014}. 
+Therefore the vertical flux is evaluated using either a $2^nd$ order FCT scheme 
+or a $4^th$ order COMPACT scheme (\np{nn\_cen\_v}=2 or 4).
 
 For stability reasons  (see \S\ref{STP}),
-the first term  in \eqref{Eq_tra_adv_ubs} (which corresponds to a second order centred scheme) 
-is evaluated using the \textit{now} tracer (centred in time) while the 
-second term (which is the diffusive part of the scheme), is 
+the first term  in \eqref{Eq_tra_adv_ubs} (which corresponds to a second order 
+centred scheme) is evaluated using the \textit{now} tracer (centred in time) 
+while the second term (which is the diffusive part of the scheme), is 
 evaluated using the \textit{before} tracer (forward in time). 
 This choice is discussed by \citet{Webb_al_JAOT98} in the context of the 
@@ -350,23 +370,5 @@
 substitution in the \mdl{traadv\_ubs} module and obtain a QUICK scheme.
 
-Four different options are possible for the vertical 
-component used in the UBS scheme. $\tau _w^{ubs}$ can be evaluated 
-using either \textit{(a)} a centred $2^{nd}$ order scheme, or  \textit{(b)} 
-a TVD scheme, or  \textit{(c)} an interpolation based on conservative 
-parabolic splines following the \citet{Shchepetkin_McWilliams_OM05} 
-implementation of UBS in ROMS, or  \textit{(d)} a UBS. The $3^{rd}$ case 
-has dispersion properties similar to an eighth-order accurate conventional scheme.
-The current reference version uses method b)
-
-Note that :
-
-(1) When a high vertical resolution $O(1m)$ is used, the model stability can 
-be controlled by vertical advection (not vertical diffusion which is usually 
-solved using an implicit scheme). Computer time can be saved by using a 
-time-splitting technique on vertical advection. Such a technique has been 
-implemented and validated in ORCA05 with 301 levels. It is not available 
-in the current reference version. 
-
-(2) It is straightforward to rewrite \eqref{Eq_tra_adv_ubs} as follows:
+Note that it is straightforward to rewrite \eqref{Eq_tra_adv_ubs} as follows:
 \begin{equation} \label{Eq_traadv_ubs2}
 \tau _u^{ubs} = \tau _u^{cen4} + \frac{1}{12} \left\{	 
@@ -390,9 +392,6 @@
 Thirdly, the diffusion term is in fact a biharmonic operator with an eddy 
 coefficient which is simply proportional to the velocity:
- $A_u^{lm}= - \frac{1}{12}\,{e_{1u}}^3\,|u|$. Note that NEMO v3.4 still uses 
- \eqref{Eq_tra_adv_ubs}, not \eqref{Eq_traadv_ubs2}.
- %%%
- \gmcomment{the change in UBS scheme has to be done}
- %%%
+ $A_u^{lm}= \frac{1}{12}\,{e_{1u}}^3\,|u|$. Note the current version of NEMO uses 
+the computationally more efficient formulation \eqref{Eq_tra_adv_ubs}.
 
 % -------------------------------------------------------------------------------------------------------------
@@ -405,5 +404,8 @@
 The Quadratic Upstream Interpolation for Convective Kinematics with 
 Estimated Streaming Terms (QUICKEST) scheme proposed by \citet{Leonard1979} 
-is the third order Godunov scheme. It is associated with the ULTIMATE QUICKEST 
+is used when \np{ln\_traadv\_qck}~=~\textit{true}. 
+QUICKEST implementation can be found in the \mdl{traadv\_mus} module.
+
+QUICKEST is the third order Godunov scheme which is associated with the ULTIMATE QUICKEST 
 limiter \citep{Leonard1991}. It has been implemented in NEMO by G. Reffray 
 (MERCATOR-ocean) and can be found in the \mdl{traadv\_qck} module.
@@ -416,18 +418,6 @@
 direction (as for the UBS case) should be implemented to restore this property.
 
-
-% -------------------------------------------------------------------------------------------------------------
-%        PPM scheme  
-% -------------------------------------------------------------------------------------------------------------
-\subsection   [Piecewise Parabolic Method (PPM) (\np{ln\_traadv\_ppm})]
-			{Piecewise Parabolic Method (PPM) (\np{ln\_traadv\_ppm}=true)}
-\label{TRA_adv_ppm}
-
-The Piecewise Parabolic Method (PPM) proposed by Colella and Woodward (1984) 
-\sgacomment{reference?}
-is based on a quadradic piecewise construction. Like the QCK scheme, it is associated 
-with the ULTIMATE QUICKEST limiter \citep{Leonard1991}. It has been implemented 
-in \NEMO by G. Reffray (MERCATOR-ocean) but is not yet offered in the reference 
-version 3.3.
+%%%gmcomment   :  Cross term are missing in the current implementation....
+
 
 % ================================================================
@@ -1167,61 +1157,116 @@
 %        Equation of State
 % -------------------------------------------------------------------------------------------------------------
-\subsection{Equation of State (\np{nn\_eos} = 0, 1 or 2)}
+\subsection{Equation Of Seawater (\np{nn\_eos} = -1, 0, or 1)}
 \label{TRA_eos}
 
-It is necessary to know the equation of state for the ocean very accurately 
-to determine stability properties (especially the Brunt-Vais\"{a}l\"{a} frequency), 
-particularly in the deep ocean. The ocean seawater volumic mass, $\rho$, 
-abusively called density, is a non linear empirical function of \textit{in situ} 
-temperature, salinity and pressure. The reference equation of state is that 
-defined by the Joint Panel on Oceanographic Tables and Standards 
-\citep{UNESCO1983}. It was the standard equation of state used in early 
-releases of OPA. However, even though this computation is fully vectorised, 
-it is quite time consuming ($15$ to $20${\%} of the total CPU time) since 
-it requires the prior computation of the \textit{in situ} temperature from the 
-model \textit{potential} temperature using the \citep{Bryden1973} polynomial 
-for adiabatic lapse rate and a $4^th$ order Runge-Kutta integration scheme. 
-Since OPA6, we have used the \citet{JackMcD1995} equation of state for 
-seawater instead. It allows the computation of the \textit{in situ} ocean density 
-directly as a function of \textit{potential} temperature relative to the surface 
-(an \NEMO variable), the practical salinity (another \NEMO variable) and the 
-pressure (assuming no pressure variation along geopotential surfaces, $i.e.$ 
-the pressure in decibars is approximated by the depth in meters). 
-Both the \citet{UNESCO1983} and \citet{JackMcD1995} equations of state 
-have exactly the same except that the values of the various coefficients have 
-been adjusted by \citet{JackMcD1995} in order to directly use the \textit{potential} 
-temperature instead of the \textit{in situ} one. This reduces the CPU time of the 
-\textit{in situ} density computation to about $3${\%} of the total CPU time, 
-while maintaining a quite accurate equation of state.
-
-In the computer code, a \textit{true} density anomaly, $d_a= \rho / \rho_o - 1$, 
-is computed, with $\rho_o$ a reference volumic mass. Called \textit{rau0} 
-in the code, $\rho_o$ is defined in \mdl{phycst}, and a value of $1,035~Kg/m^3$. 
+The Equation Of Seawater (EOS) is an empirical nonlinear thermodynamic relationship 
+linking seawater density, $\rho$, to a number of state variables, 
+most typically temperature, salinity and pressure. 
+Because density gradients control the pressure gradient force through the hydrostatic balance, 
+the equation of state provides a fundamental bridge between the distribution of active tracers 
+and the fluid dynamics. Nonlinearities of the EOS are of major importance, in particular 
+influencing the circulation through determination of the static stability below the mixed layer, 
+thus controlling rates of exchange between the atmosphere  and the ocean interior \citep{Roquet_JPO2015}. 
+Therefore an accurate EOS based on either the 1980 equation of state (EOS-80, \cite{UNESCO1983}) 
+or TEOS-10 \citep{TEOS10} standards should be used anytime a simulation of the real 
+ocean circulation is attempted \citep{Roquet_JPO2015}. 
+The use of TEOS-10 is highly recommended because 
+\textit{(i)} it is the new official EOS, 
+\textit{(ii)} it is more accurate, being based on an updated database of laboratory measurements, and 
+\textit{(iii)} it uses Conservative Temperature and Absolute Salinity (instead of potential temperature 
+and practical salinity for EOS-980, both variables being more suitable for use as model variables 
+\citep{TEOS10, Graham_McDougall_JPO13}. 
+EOS-80 is an obsolescent feature of the NEMO system, kept only for backward compatibility.
+For process studies, it is often convenient to use an approximation of the EOS. To that purposed, 
+a simplified EOS (S-EOS) inspired by \citet{Vallis06} is also available.
+
+In the computer code, a density anomaly, $d_a= \rho / \rho_o - 1$, 
+is computed, with $\rho_o$ a reference density. Called \textit{rau0} 
+in the code, $\rho_o$ is set in \mdl{phycst} to a value of $1,026~Kg/m^3$. 
 This is a sensible choice for the reference density used in a Boussinesq ocean 
 climate model, as, with the exception of only a small percentage of the ocean, 
-density in the World Ocean varies by no more than 2$\%$ from $1,035~kg/m^3$ 
-\citep{Gill1982}.
-
-Options are defined through the  \ngn{nameos} namelist variables.
-The default option (namelist parameter \np{nn\_eos}=0) is the \citet{JackMcD1995} 
-equation of state. Its use is highly recommended. However, for process studies, 
-it is often convenient to use a linear approximation of the density.
+density in the World Ocean varies by no more than 2$\%$ from that value \citep{Gill1982}.
+
+Options are defined through the  \ngn{nameos} namelist variables, and in particular \np{nn\_eos} 
+which controls the EOS used (=-1 for TEOS10 ; =0 for EOS-80 ; =1 for S-EOS).
+\begin{description}
+
+\item[\np{nn\_eos}$=-1$] the polyTEOS10-bsq equation of seawater \citep{Roquet_OM2015} is used.  
+The accuracy of this approximation is comparable to the TEOS-10 rational function approximation, 
+but it is optimized for a boussinesq fluid and the polynomial expressions have simpler 
+and more computationally efficient expressions for their derived quantities 
+which make them more adapted for use in ocean models. 
+Note that a slightly higher precision polynomial form is now used replacement of the TEOS-10 
+rational function approximation for hydrographic data analysis  \citep{TEOS10}. 
+A key point is that conservative state variables are used: 
+Absolute Salinity (unit: g/kg, notation: $S_A$) and Conservative Temperature (unit: $\degres C$, notation: $\Theta$).
+The pressure in decibars is approximated by the depth in meters. 
+With TEOS10, the specific heat capacity of sea water, $C_p$, is a constant. It is set to 
+$C_p=3991.86795711963~J\,Kg^{-1}\,\degres K^{-1}$, according to \citet{TEOS10}.
+
+Choosing polyTEOS10-bsq implies that the state variables used by the model are 
+$\Theta$ and $S_A$. In particular, the initial state deined by the user have to be given as 
+\textit{Conservative} Temperature and \textit{Absolute} Salinity. 
+In addition, setting \np{ln\_useCT} to \textit{true} convert the Conservative SST to potential SST 
+prior to either computing the air-sea and ice-sea fluxes (forced mode) 
+or sending the SST field to the atmosphere (coupled mode).
+
+\item[\np{nn\_eos}$=0$] the polyEOS80-bsq equation of seawater is used.
+It takes the same polynomial form as the polyTEOS10, but the coefficients have been optimized 
+to accurately fit EOS80 (Roquet, personal comm.). The state variables used in both the EOS80 
+and the ocean model are: 
+the Practical Salinity ((unit: psu, notation: $S_p$)) and Potential Temperature (unit: $\degres C$, notation: $\theta$).
+The pressure in decibars is approximated by the depth in meters.  
+With thsi EOS, the specific heat capacity of sea water, $C_p$, is a function of temperature, 
+salinity and pressure \citep{UNESCO1983}. Nevertheless, a severe assumption is made in order to 
+have a heat content ($C_p T_p$) which is conserved by the model: $C_p$ is set to a constant 
+value, the TEOS10 value. 
+ 
+\item[\np{nn\_eos}$=1$] a simplified EOS (S-EOS) inspired by \citet{Vallis06} is chosen, 
+the coefficients of which has been optimized to fit the behavior of TEOS10 (Roquet, personal comm.) 
+(see also \citet{Roquet_JPO2015}). It provides a simplistic linear representation of both 
+cabbeling and thermobaricity effects which is enough for a proper treatment of the EOS 
+in theoretical studies \citep{Roquet_JPO2015}.
 With such an equation of state there is no longer a distinction between 
-\textit{in situ} and \textit{potential} density and both cabbeling and thermobaric
-effects are removed.
-Two linear formulations are available: a function of $T$ only (\np{nn\_eos}=1) 
-and a function of both $T$ and $S$ (\np{nn\_eos}=2):
-\begin{equation} \label{Eq_tra_eos_linear}
+\textit{conservative} and \textit{potential} temperature, as well as between \textit{absolute} 
+and \textit{practical} salinity.
+S-EOS takes the following expression:
+\begin{equation} \label{Eq_tra_S-EOS}
 \begin{split}
-  d_a(T)       &=  \rho (T)      /  \rho_o   - 1     =  \  0.0285         -  \alpha   \;T     \\ 
-  d_a(T,S)    &=  \rho (T,S)   /  \rho_o   - 1     =  \  \beta \; S       -  \alpha   \;T    
+  d_a(T,S,z)  =  ( & - a_0 \; ( 1 + 0.5 \; \lambda_1 \; T_a + \mu_1 \; z ) * T_a  \\
+                                & + b_0 \; ( 1 - 0.5 \; \lambda_2 \; S_a - \mu_2 \; z ) * S_a  \\
+                                & - \nu \; T_a \; S_a \;  ) \; / \; \rho_o                     \\
+  with \ \  T_a = T-10  \; ;  & \;  S_a = S-35  \; ;\;  \rho_o = 1026~Kg/m^3
 \end{split}
 \end{equation} 
-where $\alpha$ and $\beta$ are the thermal and haline expansion 
-coefficients, and $\rho_o$, the reference volumic mass, $rau0$. 
-($\alpha$ and $\beta$ can be modified through the \np{rn\_alpha} and 
-\np{rn\_beta} namelist variables). Note that when $d_a$ is a function 
-of $T$ only (\np{nn\_eos}=1), the salinity is a passive tracer and can be 
-used as such.
+where the computer name of the coefficients as well as their standard value are given in \ref{Tab_SEOS}.
+In fact, when choosing S-EOS, various approximation of EOS can be specified simply by changing 
+the associated coefficients. 
+Setting to zero the two thermobaric coefficients ($\mu_1$, $\mu_2$) remove thermobaric effect from S-EOS.
+setting to zero the three cabbeling coefficients ($\lambda_1$, $\lambda_2$, $\nu$) remove cabbeling effect from S-EOS.
+Keeping non-zero value to $a_0$ and $b_0$ provide a linear EOS function of T and S.
+
+\end{description}
+
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{table}[!tb]
+\begin{center} \begin{tabular}{|p{26pt}|p{72pt}|p{56pt}|p{136pt}|}
+\hline
+coeff.	& computer name   & S-EOS		&  description		                  \\ \hline
+$a_0$       & \np{rn\_a0}     & 1.6550 $10^{-1}$ &  linear thermal expansion coeff. 	\\ \hline
+$b_0$	      & \np{rn\_b0} 	   & 7.6554 $10^{-1}$ &  linear haline  expansion coeff. 	\\ \hline
+$\lambda_1$	& \np{rn\_lambda1}& 5.9520 $10^{-2}$ &  cabbeling coeff. in $T^2$ 	      \\ \hline
+$\lambda_2$	& \np{rn\_lambda2}& 5.4914 $10^{-4}$ &  cabbeling coeff. in $S^2$	 	   \\ \hline
+$\nu$       & \np{rn\_nu}     & 2.4341 $10^{-3}$ &  cabbeling coeff. in $T \, S$ 	   \\ \hline
+$\mu_1$     & \np{rn\_mu1} 	& 1.4970 $10^{-4}$ &  thermobaric coeff. in T    	   \\ \hline
+$\mu_2$     & \np{rn\_mu2} 	& 1.1090 $10^{-5}$ &  thermobaric coeff. in S   	      \\ \hline
+\end{tabular}
+\caption{ \label{Tab_SEOS}
+Standard value of S-EOS coefficients. }
+\end{center}
+\end{table}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
 
 % -------------------------------------------------------------------------------------------------------------
@@ -1232,50 +1277,18 @@
 
 An accurate computation of the ocean stability (i.e. of $N$, the brunt-Vais\"{a}l\"{a}
- frequency) is of paramount importance as it is used in several ocean 
- parameterisations (namely TKE, KPP, Richardson number dependent 
- vertical diffusion, enhanced vertical diffusion, non-penetrative convection, 
- iso-neutral diffusion). In particular, one must be aware that $N^2$ has to 
- be computed with an \textit{in situ} reference. The expression for $N^2$ 
- depends on the type of equation of state used (\np{nn\_eos} namelist parameter).
-
-For \np{nn\_eos}=0 (\citet{JackMcD1995} equation of state), the \citet{McDougall1987} 
-polynomial expression is used (with the pressure in decibar approximated by 
-the depth in meters): 
+ frequency) is of paramount importance as determine the ocean stratification and 
+ is used in several ocean parameterisations (namely TKE, GLS, Richardson number dependent 
+ vertical diffusion, enhanced vertical diffusion, non-penetrative convection, tidal mixing 
+ parameterisation, iso-neutral diffusion). In particular, $N^2$ has to be computed at the local pressure 
+ (pressure in decibar being approximated by the depth in meters). The expression for $N^2$ 
+ is given by: 
 \begin{equation} \label{Eq_tra_bn2}
-N^2 = \frac{g}{e_{3w}} \; \beta   \ 
-	   \left(  \alpha / \beta \ \delta_{k+1/2}[T]     - \delta_{k+1/2}[S]   \right) 
-\end{equation} 
-where $\alpha$ and $\beta$ are the thermal and haline expansion coefficients. 
-They are a function of  $\overline{T}^{\,k+1/2},\widetilde{S}=\overline{S}^{\,k+1/2} - 35.$, 
-and  $z_w$, with $T$ the \textit{potential} temperature and $\widetilde{S}$ a salinity anomaly. 
-Note that both $\alpha$ and $\beta$ depend on \textit{potential} 
-temperature and salinity which are averaged at $w$-points prior 
-to the computation instead of being computed at $T$-points and 
-then averaged to $w$-points.
-
-When a linear equation of state is used (\np{nn\_eos}=1 or 2, 
-\eqref{Eq_tra_bn2} reduces to:
-\begin{equation} \label{Eq_tra_bn2_linear}
 N^2 =	\frac{g}{e_{3w}} \left(   \beta \;\delta_{k+1/2}[S] - \alpha \;\delta_{k+1/2}[T]   \right)
 \end{equation} 
-where $\alpha$ and $\beta $ are the constant coefficients used to 
-defined the linear equation of state \eqref{Eq_tra_eos_linear}.
-
-% -------------------------------------------------------------------------------------------------------------
-%        Specific Heat
-% -------------------------------------------------------------------------------------------------------------
-\subsection   	[Specific Heat (\textit{phycst})]
-			{Specific Heat (\mdl{phycst})}
-\label{TRA_adv_ldf}
-
-The specific heat of sea water, $C_p$, is a function of temperature, salinity 
-and pressure \citep{UNESCO1983}. It is only used in the model to convert 
-surface heat fluxes into surface temperature increase and so the pressure 
-dependence is neglected. The dependence on $T$ and $S$ is weak. 
-For example, with $S=35~psu$, $C_p$ increases from $3989$ to $4002$ 
-when $T$ varies from -2~\degres C to 31~\degres C. Therefore, $C_p$ has 
-been chosen as a constant: $C_p=4.10^3~J\,Kg^{-1}\,\degres K^{-1}$. 
-Its value is set in \mdl{phycst} module. 
-
+where $(T,S) = (\Theta, S_A)$ for TEOS10, $= (\theta, S_p)$ for TEOS-80, or $=(T,S)$ for S-EOS, 
+and, $\alpha$ and $\beta$ are the thermal and haline expansion coefficients. 
+The coefficients are a polynomial function of temperature, salinity and depth which expression 
+depends on the chosen EOS. They are computed through \textit{eos\_rab}, a \textsc{Fortran} 
+function that can be found in \mdl{eosbn2}.
 
 % -------------------------------------------------------------------------------------------------------------
@@ -1298,6 +1311,17 @@
 sea water ($i.e.$ referenced to the surface $p=0$), thus the pressure dependent 
 terms in \eqref{Eq_tra_eos_fzp} (last term) have been dropped. The freezing
-point is computed through \textit{tfreez}, a \textsc{Fortran} function that can be found 
+point is computed through \textit{eos\_fzp}, a \textsc{Fortran} function that can be found 
 in \mdl{eosbn2}.  
+
+
+% -------------------------------------------------------------------------------------------------------------
+%        Potential Energy     
+% -------------------------------------------------------------------------------------------------------------
+%\subsection{Potential Energy anomalies}
+%\label{TRA_bn2}
+
+%    =====>>>>> TO BE written
+%
+
 
 % ================================================================
Index: /trunk/DOC/TexFiles/Chapters/Introduction.tex
===================================================================
--- /trunk/DOC/TexFiles/Chapters/Introduction.tex	(revision 6139)
+++ /trunk/DOC/TexFiles/Chapters/Introduction.tex	(revision 6140)
@@ -24,15 +24,14 @@
 release 8.2, described in \citet{Madec1998}. This model has been used for a wide 
 range of applications, both regional or global, as a forced ocean model and as a 
-model coupled with the atmosphere. A complete list of references is found on the 
-\NEMO web site. 
+model coupled with the sea-ice and/or the atmosphere.  
 
 This manual is organised in as follows. Chapter~\ref{PE} presents the model basics, 
 $i.e.$ the equations and their assumptions, the vertical coordinates used, and the 
 subgrid scale physics. This part deals with the continuous equations of the model 
-(primitive equations, with potential temperature, salinity and an equation of state). 
+(primitive equations, with temperature, salinity and an equation of seawater). 
 The equations are written in a curvilinear coordinate system, with a choice of vertical 
-coordinates ($z$ or $s$, with the rescaled height coordinate formulation \textit{z*}, or  
-\textit{s*}). Momentum equations are formulated in the vector invariant form or in the 
-flux form. Dimensional units in the meter, kilogram, second (MKS) international system 
+coordinates ($z$, $s$, \textit{z*}, \textit{s*}, $\tilde{z}$, $\tilde{s}$, and a mixture of them). 
+Momentum equations are formulated in the vector invariant form or in the flux form. 
+Dimensional units in the meter, kilogram, second (MKS) international system 
 are used throughout.
 
@@ -79,9 +78,10 @@
 space and time variable coefficient \citet{Treguier1997}. The model has vertical harmonic 
 viscosity and diffusion with a space and time variable coefficient, with options to compute 
-the coefficients with \citet{Blanke1993}, \citet{Large_al_RG94}, \citet{Pacanowski_Philander_JPO81}, 
+the coefficients with \citet{Blanke1993}, \citet{Pacanowski_Philander_JPO81}, 
 or \citet{Umlauf_Burchard_JMS03} mixing schemes.
  \vspace{1cm}
  
- 
+%%gm    To be put somewhere else ....
+
 \noindent CPP keys and namelists are used for inputs to the code.  \newline
 
@@ -112,4 +112,5 @@
  \vspace{1cm}
 
+%%gm  end
 
 Model outputs management and specific online diagnostics are described in chapters~\ref{DIA}.
@@ -249,2 +250,16 @@
 
 
+ \vspace{1cm}
+$\bullet$ The main modifications from NEMO/OPA v3.4 and  v3.6 are :\\
+\begin{enumerate}
+\item ... ; 
+\end{enumerate}
+
+
+ \vspace{1cm}
+$\bullet$ The main modifications from NEMO/OPA v3.6 and  v4.0 are :\\
+\begin{enumerate}
+\item ... ; 
+\end{enumerate}
+
+
Index: /trunk/DOC/TexFiles/Namelist/nam_dia25h
===================================================================
--- /trunk/DOC/TexFiles/Namelist/nam_dia25h	(revision 6140)
+++ /trunk/DOC/TexFiles/Namelist/nam_dia25h	(revision 6140)
@@ -0,0 +1,5 @@
+!-----------------------------------------------------------------------
+&nam_dia25h  !   25h Mean Output
+!-----------------------------------------------------------------------
+   ln_dia25h  = .true.    !  Choose 25 mean output or not
+/
Index: /trunk/DOC/TexFiles/Namelist/nam_diatmb
===================================================================
--- /trunk/DOC/TexFiles/Namelist/nam_diatmb	(revision 6140)
+++ /trunk/DOC/TexFiles/Namelist/nam_diatmb	(revision 6140)
@@ -0,0 +1,5 @@
+!-----------------------------------------------------------------------
+&nam_diatmb  !   25h Mean Output
+!-----------------------------------------------------------------------
+   ln_diatmb  = .true.    !  Choose Top Middle and Bottom output or not
+/
Index: /trunk/DOC/TexFiles/Namelist/nam_tide
===================================================================
--- /trunk/DOC/TexFiles/Namelist/nam_tide	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/nam_tide	(revision 6140)
@@ -1,16 +1,8 @@
 !-----------------------------------------------------------------------
-&nam_tide      !   tide parameters (#ifdef key_tide)
+&nam_tide      !   tide parameters                                      ("key_tide")
 !-----------------------------------------------------------------------
    ln_tide_pot   = .true.   !  use tidal potential forcing
-   clname(1)     =   'M2'   !  name of constituent
-   clname(2)     =   'S2'
-   clname(3)     =   'N2'
-   clname(4)     =   'K1'
-   clname(5)     =   'O1'
-   clname(6)     =   'Q1'
-   clname(7)     =   'M4'
-   clname(8)     =   'K2'
-   clname(9)     =   'P1'
-   clname(10)    =   'Mf'
-   clname(11)    =   'Mm'
+   ln_tide_ramp  = .false.  !
+   rdttideramp   =    0.    !
+   clname(1)     = 'DUMMY'  !  name of constituent - all tidal components must be set in namelist_cfg
 /
Index: /trunk/DOC/TexFiles/Namelist/namagrif
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namagrif	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namagrif	(revision 6140)
@@ -6,3 +6,4 @@
    rn_sponge_tra = 2880.   !  coefficient for tracer   sponge layer [m2/s]
    rn_sponge_dyn = 2880.   !  coefficient for dynamics sponge layer [m2/s]
+   ln_chk_bathy  = .FALSE. !
 /
Index: /trunk/DOC/TexFiles/Namelist/nambbl
===================================================================
--- /trunk/DOC/TexFiles/Namelist/nambbl	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/nambbl	(revision 6140)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme
+&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
 !-----------------------------------------------------------------------
    nn_bbl_ldf  =  1      !  diffusive bbl (=1)   or not (=0)
Index: /trunk/DOC/TexFiles/Namelist/nambdy
===================================================================
--- /trunk/DOC/TexFiles/Namelist/nambdy	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/nambdy	(revision 6140)
@@ -2,22 +2,33 @@
 &nambdy        !  unstructured open boundaries                          ("key_bdy")
 !-----------------------------------------------------------------------
-    nb_bdy = 1                            !  number of open boundary sets
+    nb_bdy         = 0                    !  number of open boundary sets
     ln_coords_file = .true.               !  =T : read bdy coordinates from file
     cn_coords_file = 'coordinates.bdy.nc' !  bdy coordinates files
-    ln_mask_file = .false.                !  =T : read mask from file
-    cn_mask_file = ''                     !  name of mask file (if ln_mask_file=.TRUE.)
-    nn_dyn2d      =  2                    !  boundary conditions for barotropic fields
-    nn_dyn2d_dta  =  3                    !  = 0, bdy data are equal to the initial state
+    ln_mask_file   = .false.              !  =T : read mask from file
+    cn_mask_file   = ''                   !  name of mask file (if ln_mask_file=.TRUE.)
+    cn_dyn2d       = 'none'               !
+    nn_dyn2d_dta   =  0                   !  = 0, bdy data are equal to the initial state
                                           !  = 1, bdy data are read in 'bdydata   .nc' files
                                           !  = 2, use tidal harmonic forcing data from files
                                           !  = 3, use external data AND tidal harmonic forcing
-    nn_dyn3d      =  0                    !  boundary conditions for baroclinic velocities
+    cn_dyn3d      =  'none'               !
     nn_dyn3d_dta  =  0                    !  = 0, bdy data are equal to the initial state
-                           !  = 1, bdy data are read in 'bdydata   .nc' files
-    nn_tra        =  1                    !  boundary conditions for T and S
-    nn_tra_dta    =  1                    !  = 0, bdy data are equal to the initial state
-                           !  = 1, bdy data are read in 'bdydata   .nc' files
-    nn_rimwidth  = 10                      !  width of the relaxation zone
-    ln_vol     = .false.                  !  total volume correction (see nn_volctl parameter)
-    nn_volctl  = 1                        !  = 0, the total water flux across open boundaries is zero
+                                          !  = 1, bdy data are read in 'bdydata   .nc' files
+    cn_tra        =  'none'               !
+    nn_tra_dta    =  0                    !  = 0, bdy data are equal to the initial state
+                                          !  = 1, bdy data are read in 'bdydata   .nc' files
+    cn_ice_lim      =  'none'             !
+    nn_ice_lim_dta  =  0                  !  = 0, bdy data are equal to the initial state
+                                          !  = 1, bdy data are read in 'bdydata   .nc' files
+    rn_ice_tem      = 270.                !  lim3 only: arbitrary temperature of incoming sea ice
+    rn_ice_sal      = 10.                 !  lim3 only:      --   salinity           --
+    rn_ice_age      = 30.                 !  lim3 only:      --   age                --
+
+    ln_tra_dmp    =.false.                !  open boudaries conditions for tracers
+    ln_dyn3d_dmp  =.false.                !  open boundary condition for baroclinic velocities
+    rn_time_dmp   =  1.                   ! Damping time scale in days
+    rn_time_dmp_out =  1.                 ! Outflow damping time scale
+    nn_rimwidth   = 10                    !  width of the relaxation zone
+    ln_vol        = .false.               !  total volume correction (see nn_volctl parameter)
+    nn_volctl     = 1                     !  = 0, the total water flux across open boundaries is zero
 /
Index: /trunk/DOC/TexFiles/Namelist/nambdy_dta
===================================================================
--- /trunk/DOC/TexFiles/Namelist/nambdy_dta	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/nambdy_dta	(revision 6140)
@@ -1,15 +1,24 @@
 !-----------------------------------------------------------------------
-&nambdy_dta      !  open boundaries - external data           ("key_bdy")
+&nambdy_dta    !  open boundaries - external data                       ("key_bdy")
 !-----------------------------------------------------------------------
-!              !   file name    ! frequency (hours) !  variable  ! time interpol. !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
-!              !                !  (if <0  months)  !    name    !    (logical)   !  (T/F)  ! 'monthly' ! filename ! pairing  ! filename      !
-   bn_ssh =     'amm12_bdyT_u2d' ,         24        , 'sossheig' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''    , ''
-   bn_u2d =     'amm12_bdyU_u2d' ,         24        , 'vobtcrtx' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''    , ''
-   bn_v2d =     'amm12_bdyV_u2d' ,         24        , 'vobtcrty' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''    , ''
-   bn_u3d  =    'amm12_bdyU_u3d' ,         24        , 'vozocrtx' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''    , ''
-   bn_v3d  =    'amm12_bdyV_u3d' ,         24        , 'vomecrty' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''    , ''
-   bn_tem  =    'amm12_bdyT_tra' ,         24        , 'votemper' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''    , ''
-   bn_sal  =    'amm12_bdyT_tra' ,         24        , 'vosaline' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''    , ''
-   cn_dir  =    'bdydta/'
-   ln_full_vel = .false.
+!              !  file name      ! frequency (hours) ! variable  ! time interp. !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !                 !  (if <0  months)  !   name    !  (logical)   !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
+   bn_ssh =     'amm12_bdyT_u2d' ,         24        , 'sossheig',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+   bn_u2d =     'amm12_bdyU_u2d' ,         24        , 'vobtcrtx',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+   bn_v2d =     'amm12_bdyV_u2d' ,         24        , 'vobtcrty',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+   bn_u3d  =    'amm12_bdyU_u3d' ,         24        , 'vozocrtx',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+   bn_v3d  =    'amm12_bdyV_u3d' ,         24        , 'vomecrty',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+   bn_tem  =    'amm12_bdyT_tra' ,         24        , 'votemper',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+   bn_sal  =    'amm12_bdyT_tra' ,         24        , 'vosaline',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+! for lim2
+!   bn_frld  =   'amm12_bdyT_ice' ,         24        , 'ileadfra',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_hicif =   'amm12_bdyT_ice' ,         24        , 'iicethic',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_hsnif =   'amm12_bdyT_ice' ,         24        , 'isnowthi',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+! for lim3
+!   bn_a_i  =    'amm12_bdyT_ice' ,         24        , 'ileadfra',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_ht_i =    'amm12_bdyT_ice' ,         24        , 'iicethic',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_ht_s =    'amm12_bdyT_ice' ,         24        , 'isnowthi',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+
+   cn_dir      =    'bdydta/'   !  root directory for the location of the bulk files
+   ln_full_vel = .false.        !  
 /
Index: /trunk/DOC/TexFiles/Namelist/nambdy_tide
===================================================================
--- /trunk/DOC/TexFiles/Namelist/nambdy_tide	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/nambdy_tide	(revision 6140)
@@ -2,6 +2,6 @@
 &nambdy_tide     ! tidal forcing at open boundaries
 !-----------------------------------------------------------------------
-   filtide          = 'bdydta/amm12_bdytide_'         !  file name root of tidal forcing files
-   ln_bdytide_2ddta = .false.
-   ln_bdytide_conj  = .false.
+   filtide          = 'bdydta/amm12_bdytide_'   !  file name root of tidal forcing files
+   ln_bdytide_2ddta = .false.   !
+   ln_bdytide_conj  = .false.   ! 
 /
Index: /trunk/DOC/TexFiles/Namelist/namberg
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namberg	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namberg	(revision 6140)
@@ -1,6 +1,6 @@
 !-----------------------------------------------------------------------
-&namberg       !   iceberg parameters
+&namberg       !   iceberg parameters                                   (default: No iceberg)
 !-----------------------------------------------------------------------
-      ln_icebergs              = .false.
+      ln_icebergs              = .false.              ! iceberg floats or not
       ln_bergdia               = .true.               ! Calculate budgets
       nn_verbose_level         = 1                    ! Turn on more verbose output if level > 0
@@ -9,8 +9,8 @@
                                                       ! Initial mass required for an iceberg of each class
       rn_initial_mass          = 8.8e7, 4.1e8, 3.3e9, 1.8e10, 3.8e10, 7.5e10, 1.2e11, 2.2e11, 3.9e11, 7.4e11
-                                                      ! Proportion of calving mass to apportion to each class  
+                                                      ! Proportion of calving mass to apportion to each class
       rn_distribution          = 0.24, 0.12, 0.15, 0.18, 0.12, 0.07, 0.03, 0.03, 0.03, 0.02
                                                       ! Ratio between effective and real iceberg mass (non-dim)
-                                                      ! i.e. number of icebergs represented at a point         
+                                                      ! i.e. number of icebergs represented at a point
       rn_mass_scaling          = 2000, 200, 50, 20, 10, 5, 2, 1, 1, 1
                                                       ! thickness of newly calved bergs (m)
@@ -21,14 +21,14 @@
       rn_bits_erosion_fraction = 0.                   ! Fraction of erosion melt flux to divert to bergy bits
       rn_sicn_shift            = 0.                   ! Shift of sea-ice concn in erosion flux (0<sicn_shift<1)
-      ln_passive_mode          = .false.              ! iceberg - ocean decoupling   
+      ln_passive_mode          = .false.              ! iceberg - ocean decoupling
       nn_test_icebergs         =  10                  ! Create test icebergs of this class (-1 = no)
                                                       ! Put a test iceberg at each gridpoint in box (lon1,lon2,lat1,lat2)
       rn_test_box              = 108.0,  116.0, -66.0, -58.0
-      rn_speed_limit           = 0.                   ! CFL speed limit for a berg   
+      rn_speed_limit           = 0.                   ! CFL speed limit for a berg
 
-               ! filename ! freq (hours) ! variable ! time interp. ! clim  !'yearly' or ! weights  ! rotation ! land/sea mask !
-               !          ! (<0  months) !   name   !  (logical)   ! (T/F) ! 'monthly'  ! filename ! pairing  ! filename      !
-      sn_icb =  'calving' ,     -1       , 'calvingmask',  .true.      , .true., 'yearly'   , ' '      , ' '  , ''
-   
-      cn_dir = './' 
+!              ! file name ! frequency (hours) !   variable   ! time interp.   !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !           !  (if <0  months)  !     name     !   (logical)    !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
+      sn_icb =  'calving' ,       -1           , 'calvingmask',  .true.        , .true.  , 'yearly'  , ''       , ''       , ''
+
+      cn_dir = './'
 /
Index: /trunk/DOC/TexFiles/Namelist/nambfr
===================================================================
--- /trunk/DOC/TexFiles/Namelist/nambfr	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/nambfr	(revision 6140)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
+&nambfr        !   bottom friction                                      (default: linear)
 !-----------------------------------------------------------------------
    nn_bfr      =    1      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
Index: /trunk/DOC/TexFiles/Namelist/namctl
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namctl	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namctl	(revision 6140)
@@ -13,3 +13,4 @@
                            !     (no physical validity of the results)
    nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
+   nn_diacfl   =    0      !  Write out cfl diagnostics (=1) in cfl_diagnostics.ascii, or not (=0)
 /
Index: /trunk/DOC/TexFiles/Namelist/namdct
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namdct	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namdct	(revision 6140)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&namdct        ! transports through sections
+&namdct        ! transports through some sections
 !-----------------------------------------------------------------------
     nn_dct      = 15       !  time step frequency for transports computing
Index: /trunk/DOC/TexFiles/Namelist/namdiu
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namdiu	(revision 6140)
+++ /trunk/DOC/TexFiles/Namelist/namdiu	(revision 6140)
@@ -0,0 +1,6 @@
+!-----------------------------------------------------------------------
+&namdiu        !   Control of diurnal SST models
+!-----------------------------------------------------------------------
+   ln_diurnal = .TRUE.   ! Turn diurnal models on/off
+   ln_diurnal_only = .FALSE.   ! Only run diurnal model, dynamical models switched off
+/
Index: /trunk/DOC/TexFiles/Namelist/namdom
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namdom	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namdom	(revision 6140)
@@ -3,7 +3,9 @@
 !-----------------------------------------------------------------------
    nn_bathy    =    1      !  compute (=0) or read (=1) the bathymetry file
-   nn_closea    =   0      !  remove (=0) or keep (=1) closed seas and lakes (ORCA)
-   nn_msh      =    0      !  create (=1) a mesh file or not (=0)
+   rn_bathy    =    0.     !  value of the bathymetry. if (=0) bottom flat at jpkm1
+   nn_closea   =    0      !  remove (=0) or keep (=1) closed seas and lakes (ORCA)
+   nn_msh      =    1      !  create (=1) a mesh file or not (=0)
    rn_hmin     =   -3.     !  min depth of the ocean (>0) or min number of ocean level (<0)
+   rn_isfhmin  =    1.00   !  treshold (m) to discriminate grounding ice to floating ice
    rn_e3zps_min=   20.     !  partial step thickness is set larger than the minimum of
    rn_e3zps_rat=    0.1    !  rn_e3zps_min and rn_e3zps_rat*e3t, with 0<rn_e3zps_rat<1
@@ -16,4 +18,5 @@
    rn_rdtmax   = 28800.          !  maximum time step on tracers (used if nn_acc=1)
    rn_rdth     =  800.           !  depth variation of tracer time step  (used if nn_acc=1)
+   ln_crs      = .false.      !  Logical switch for coarsening module
    jphgr_msh   =       0               !  type of horizontal mesh
                                        !  = 0 curvilinear coordinate on the sphere read in coordinate.nc
Index: /trunk/DOC/TexFiles/Namelist/namdyn_adv
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namdyn_adv	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namdyn_adv	(revision 6140)
@@ -1,7 +1,9 @@
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
+&namdyn_adv    !   formulation of the momentum advection                (default: vector form)
 !-----------------------------------------------------------------------
-   ln_dynadv_vec = .true.  !  vector form (T) or flux form (F)  
+   ln_dynadv_vec = .true.  !  vector form (T) or flux form (F)
+   nn_dynkeg     = 0       ! scheme for grad(KE): =0   C2  ;  =1   Hollingsworth correction
    ln_dynadv_cen2= .false. !  flux form - 2nd order centered scheme
-   ln_dynadv_ubs = .false. !  flux form - 3rd order UBS      scheme 
-/  
+   ln_dynadv_ubs = .false. !  flux form - 3rd order UBS      scheme
+   ln_dynzad_zts = .false. !  Use (T) sub timestepping for vertical momentum advection
+/
Index: /trunk/DOC/TexFiles/Namelist/namdyn_hpg
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namdyn_hpg	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namdyn_hpg	(revision 6140)
@@ -1,12 +1,10 @@
 !-----------------------------------------------------------------------
-&namdyn_hpg    !   Hydrostatic pressure gradient option
+&namdyn_hpg    !   Hydrostatic pressure gradient option                 (default: zps)
 !-----------------------------------------------------------------------
    ln_hpg_zco  = .false.   !  z-coordinate - full steps
    ln_hpg_zps  = .true.    !  z-coordinate - partial steps (interpolation)
    ln_hpg_sco  = .false.   !  s-coordinate (standard jacobian formulation)
-   ln_hpg_isf  = .false.   !  s-coordinate (sco ) adapted to ice shelf cavity
+   ln_hpg_isf  = .false.   !  s-coordinate (sco ) adapted to isf
    ln_hpg_djc  = .false.   !  s-coordinate (Density Jacobian with Cubic polynomial)
    ln_hpg_prj  = .false.   !  s-coordinate (Pressure Jacobian scheme)
-   ln_dynhpg_imp = .false. !  time stepping: semi-implicit time scheme  (T)
-                                 !           centered      time scheme  (F)
 /
Index: /trunk/DOC/TexFiles/Namelist/namdyn_ldf
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namdyn_ldf	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namdyn_ldf	(revision 6140)
@@ -1,20 +1,26 @@
 !-----------------------------------------------------------------------
-&namdyn_ldf    !   lateral diffusion on momentum
+&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO)
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
-   ln_dynldf_lap    =  .true.   !  laplacian operator
-   ln_dynldf_bilap  =  .false.  !  bilaplacian operator
+   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
+   ln_dynldf_lap =  .false.    !    laplacian operator
+   ln_dynldf_blp =  .false.    !  bilaplacian operator
    !                       !  Direction of action  :
-   ln_dynldf_level  =  .false.  !  iso-level
-   ln_dynldf_hor    =  .true.   !  horizontal (geopotential)            (require "key_ldfslp" in s-coord.)
-   ln_dynldf_iso    =  .false.  !  iso-neutral                          (require "key_ldfslp")
+   ln_dynldf_lev =  .false.    !  iso-level
+   ln_dynldf_hor =  .false.    !  horizontal (geopotential)
+   ln_dynldf_iso =  .false.    !  iso-neutral
    !                       !  Coefficient
-   rn_ahm_0_lap     = 40000.    !  horizontal laplacian eddy viscosity   [m2/s]
-   rn_ahmb_0        =     0.    !  background eddy viscosity for ldf_iso [m2/s]
-   rn_ahm_0_blp     =     0.    !  horizontal bilaplacian eddy viscosity [m4/s]
-   rn_cmsmag_1      =     3.    !  constant in laplacian Smagorinsky viscosity
-   rn_cmsmag_2      =     3     !  constant in bilaplacian Smagorinsky viscosity
-   rn_cmsh          =     1.    !  1 or 0 , if 0 -use only shear for Smagorinsky viscosity
-   rn_ahm_m_blp     =    -1.e12 !  upper limit for bilap  abs(ahm) < min( dx^4/128rdt, rn_ahm_m_blp)
-   rn_ahm_m_lap     = 40000.    !  upper limit for lap  ahm < min(dx^2/16rdt, rn_ahm_m_lap)
+   nn_ahm_ijk_t  = 0           !  space/time variation of eddy coef
+   !                                !  =-30  read in eddy_viscosity_3D.nc file
+   !                                !  =-20  read in eddy_viscosity_2D.nc file
+   !                                !  =  0  constant 
+   !                                !  = 10  F(k)=c1d
+   !                                !  = 20  F(i,j)=F(grid spacing)=c2d
+   !                                !  = 30  F(i,j,k)=c2d*c1d
+   !                                !  = 31  F(i,j,k)=F(grid spacing and local velocity)
+   rn_ahm_0      =  40000.     !  horizontal laplacian eddy viscosity   [m2/s]
+   rn_ahm_b      =      0.     !  background eddy viscosity for ldf_iso [m2/s]
+   rn_bhm_0      = 1.e+12      !  horizontal bilaplacian eddy viscosity [m4/s]
+   !
+   ! Caution in 20 and 30 cases the coefficient have to be given for a 1 degree grid (~111km)
 /
Index: /trunk/DOC/TexFiles/Namelist/namdyn_spg
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namdyn_spg	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namdyn_spg	(revision 6140)
@@ -1,6 +1,14 @@
 !-----------------------------------------------------------------------
-!namdyn_spg    !   surface pressure gradient   (CPP key only)
+&namdyn_spg    !   surface pressure gradient                            (default: NO)
 !-----------------------------------------------------------------------
-!                          !  explicit free surface                     ("key_dynspg_exp")
-!                          !  filtered free surface                     ("key_dynspg_flt")
-!                          !  split-explicit free surface               ("key_dynspg_ts")
+   ln_dynspg_exp  = .false.   ! explicit free surface
+   ln_dynspg_ts   = .false.   ! split-explicit free surface
+      ln_bt_fw      = .true.     ! Forward integration of barotropic Eqs.
+      ln_bt_av      = .true.     ! Time filtering of barotropic variables
+         nn_bt_flt     = 1          ! Time filter choice  = 0 None
+         !                          !                     = 1 Boxcar over   nn_baro sub-steps
+         !                          !                     = 2 Boxcar over 2*nn_baro  "    "
+      ln_bt_auto    = .true.     ! Number of sub-step defined from:
+         rn_bt_cmax   =  0.8        ! =T : the Maximum Courant Number allowed
+         nn_baro      = 30          ! =F : the number of sub-step in rn_rdt seconds
+/
Index: /trunk/DOC/TexFiles/Namelist/namdyn_vor
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namdyn_vor	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namdyn_vor	(revision 6140)
@@ -1,8 +1,10 @@
 !-----------------------------------------------------------------------
-&namdyn_vor    !   option of physics/algorithm (not control by CPP keys)
+&namdyn_vor    !   option of physics/algorithm                          (default: NO)
 !-----------------------------------------------------------------------
    ln_dynvor_ene = .false. !  enstrophy conserving scheme
    ln_dynvor_ens = .false. !  energy conserving scheme
    ln_dynvor_mix = .false. !  mixed scheme
-   ln_dynvor_een = .true.  !  energy & enstrophy scheme
+   ln_dynvor_een = .false. !  energy & enstrophy scheme
+      nn_een_e3f = 1          ! e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
+   ln_dynvor_msk = .false. !  vorticity multiplied by fmask (=T) or not (=F) (all vorticity schemes)  ! PLEASE DO NOT USE
 /
Index: /trunk/DOC/TexFiles/Namelist/nameos
===================================================================
--- /trunk/DOC/TexFiles/Namelist/nameos	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/nameos	(revision 6140)
@@ -2,9 +2,18 @@
 &nameos        !   ocean physical parameters
 !-----------------------------------------------------------------------
-   nn_eos      =   0       !  type of equation of state and Brunt-Vaisala frequency
-                           !     = 0, UNESCO (formulation of Jackett and McDougall (1994) and of McDougall (1987) )
-                           !     = 1, linear: rho(T)   = rau0 * ( 1.028 - ralpha * T )
-                           !     = 2, linear: rho(T,S) = rau0 * ( rbeta * S - ralpha * T )
-   rn_alpha    =   2.0e-4  !  thermal expension coefficient (nn_eos= 1 or 2)
-   rn_beta     =   7.7e-4  !  saline  expension coefficient (nn_eos= 2)
+   nn_eos      =  -1     !  type of equation of state and Brunt-Vaisala frequency
+                                 !  =-1, TEOS-10
+                                 !  = 0, EOS-80
+                                 !  = 1, S-EOS   (simplified eos)
+   ln_useCT    = .true.  ! use of Conservative Temp. ==> surface CT converted in Pot. Temp. in sbcssm
+                                 !
+   !                     ! S-EOS coefficients :
+                                 !  rd(T,S,Z)*rau0 = -a0*(1+.5*lambda*dT+mu*Z+nu*dS)*dT+b0*dS
+   rn_a0       =  1.6550e-1      !  thermal expension coefficient (nn_eos= 1)
+   rn_b0       =  7.6554e-1      !  saline  expension coefficient (nn_eos= 1)
+   rn_lambda1  =  5.9520e-2      !  cabbeling coeff in T^2  (=0 for linear eos)
+   rn_lambda2  =  7.4914e-4      !  cabbeling coeff in S^2  (=0 for linear eos)
+   rn_mu1      =  1.4970e-4      !  thermobaric coeff. in T (=0 for linear eos)
+   rn_mu2      =  1.1090e-5      !  thermobaric coeff. in S (=0 for linear eos)
+   rn_nu       =  2.4341e-3      !  cabbeling coeff in T*S  (=0 for linear eos)
 /
Index: /trunk/DOC/TexFiles/Namelist/namhsb
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namhsb	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namhsb	(revision 6140)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&namhsb       !  Heat and salt budgets 
+&namhsb       !  Heat and salt budgets                                  (default F)
 !-----------------------------------------------------------------------
    ln_diahsb  = .false.    !  check the heat and salt budgets (T) or not (F)
Index: /trunk/DOC/TexFiles/Namelist/namlbc
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namlbc	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namlbc	(revision 6140)
@@ -2,6 +2,6 @@
 &namlbc        !   lateral momentum boundary condition
 !-----------------------------------------------------------------------
+   !                       !  free slip  !   partial slip  !   no slip   ! strong slip
    rn_shlat    =    2.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
-                           !  free slip  !   partial slip  !   no slip   ! strong slip
-   ln_vorlat   = .false.   !  consistency of vorticity boundary condition with analytical eqs.
+   ln_vorlat   = .false.   !  consistency of vorticity boundary condition with analytical Eqs.
 /
Index: /trunk/DOC/TexFiles/Namelist/namobs
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namobs	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namobs	(revision 6140)
@@ -1,63 +1,34 @@
 !-----------------------------------------------------------------------
-&namobs       !  observation usage switch                               ('key_diaobs')
+&namobs       !  observation usage switch
 !-----------------------------------------------------------------------
-   ln_t3d     = .false.    ! Logical switch for T profile observations
-   ln_s3d     = .false.    ! Logical switch for S profile observations
-   ln_ena     = .false.    ! Logical switch for ENACT insitu data set
-   !                       !     ln_cor                  Logical switch for Coriolis insitu data set
-   ln_profb   = .false.    ! Logical switch for feedback insitu data set
-   ln_sla     = .false.    ! Logical switch for SLA observations
-
-   ln_sladt   = .false.    ! Logical switch for AVISO SLA data
-
-   ln_slafb   = .false.    ! Logical switch for feedback SLA data
-                           !     ln_ssh                  Logical switch for SSH observations
-
-   ln_sst     = .true.     ! Logical switch for SST observations
-   ln_reysst  = .true.     !     ln_reysst               Logical switch for Reynolds observations
-   ln_ghrsst  = .false.    !     ln_ghrsst               Logical switch for GHRSST observations      
-
-   ln_sstfb   = .false.    ! Logical switch for feedback SST data
-                           !     ln_sss                  Logical switch for SSS observations
-                           !     ln_seaice               Logical switch for Sea Ice observations
-                           !     ln_vel3d                Logical switch for velocity observations
-                           !     ln_velavcur             Logical switch for velocity daily av. cur.
-                           !     ln_velhrcur             Logical switch for velocity high freq. cur.
-                           !     ln_velavadcp            Logical switch for velocity daily av. ADCP
-                           !     ln_velhradcp            Logical switch for velocity high freq. ADCP
-                           !     ln_velfb                Logical switch for feedback velocity data
-                           !     ln_grid_global          Global distribtion of observations
-                           !     ln_grid_search_lookup   Logical switch for obs grid search w/lookup table
-                           !     grid_search_file        Grid search lookup file header
-                           !     enactfiles              ENACT input observation file names
-                           !     coriofiles              Coriolis input observation file name
-   !                       ! profbfiles: Profile feedback input observation file name
-   profbfiles = 'profiles_01.nc'
-                           !     ln_profb_enatim         Enact feedback input time setting switch
-                           !     slafilesact             Active SLA input observation file name
-                           !     slafilespas             Passive SLA input observation file name
-   !                       ! slafbfiles: Feedback SLA input observation file name
-   slafbfiles = 'sla_01.nc'
-                           !     sstfiles                GHRSST input observation file name
-   !                       ! sstfbfiles: Feedback SST input observation file name
-   sstfbfiles = 'sst_01.nc' 'sst_02.nc' 'sst_03.nc' 'sst_04.nc' 'sst_05.nc'
-                           !     seaicefiles             Sea Ice input observation file name
-                           !     velavcurfiles           Vel. cur. daily av. input file name
-                           !     velhvcurfiles           Vel. cur. high freq. input file name
-                           !     velavadcpfiles          Vel. ADCP daily av. input file name
-                           !     velhvadcpfiles          Vel. ADCP high freq. input file name
-                           !     velfbfiles              Vel. feedback input observation file name
-                           !     dobsini                 Initial date in window YYYYMMDD.HHMMSS
-                           !     dobsend                 Final date in window YYYYMMDD.HHMMSS
-                           !     n1dint                  Type of vertical interpolation method
-                           !     n2dint                  Type of horizontal interpolation method
-                           !     ln_nea                  Rejection of observations near land switch
-   nmsshc     = 0          ! MSSH correction scheme
-                           !     mdtcorr                 MDT  correction
-                           !     mdtcutoff               MDT cutoff for computed correction
-   ln_altbias = .false.    ! Logical switch for alt bias
-   ln_ignmis  = .true.     ! Logical switch for ignoring missing files
-                           !     endailyavtypes   ENACT daily average types
-   ln_grid_global = .true.
-   ln_grid_search_lookup = .false.
+   ln_diaobs  = .true.                 ! Logical switch for the observation operator
+   ln_t3d     = .true.                 ! Logical switch for T profile observations
+   ln_s3d     = .true.                 ! Logical switch for S profile observations
+   ln_sla     = .true.                 ! Logical switch for SLA observations
+   ln_sst     = .true.                 ! Logical switch for SST observations
+   ln_sic     = .false.                ! Logical switch for Sea Ice observations
+   ln_vel3d   = .false.                ! Logical switch for velocity observations
+   ln_altbias = .false.                ! Logical switch for altimeter bias correction
+   ln_nea     = .false.                ! Logical switch for rejection of observations near land
+   ln_grid_global = .true.             ! Logical switch for global distribution of observations
+   ln_grid_search_lookup = .false.     ! Logical switch for obs grid search w/lookup table
+   ln_ignmis  = .true.                 ! Logical switch for ignoring missing files
+   ln_s_at_t  = .false.                ! Logical switch for computing model S at T obs if not there
+   ln_sstnight = .false.               ! Logical switch for calculating night-time average for SST obs
+   cn_profbfiles = 'profiles_01.nc'    ! Profile feedback input observation file names
+   cn_slafbfiles = 'sla_01.nc'         ! SLA feedback input observation file names
+   cn_sstfbfiles = 'sst_01.nc'         ! SST feedback input observation file names
+   cn_sicfbfiles = 'sic_01.nc'         ! SIC feedback input observation file names
+   cn_velfbfiles = 'vel_01.nc'         ! Velocity feedback input observation file names
+   cn_altbiasfile = 'altbias.nc'       ! Altimeter bias input file name
+   cn_gridsearchfile = 'gridsearch.nc' ! Grid search file name
+   rn_gridsearchres = 0.5              ! Grid search resolution
+   rn_dobsini = 20150101.000000        ! Initial date in window YYYYMMDD.HHMMSS
+   rn_dobsend = 20150102.000000        ! Final date in window YYYYMMDD.HHMMSS
+   nn_1dint = 0                        ! Type of vertical interpolation method
+   nn_2dint = 0                        ! Type of horizontal interpolation method
+   nn_msshc = 0                        ! MSSH correction scheme
+   rn_mdtcorr = 1.61                   ! MDT  correction
+   rn_mdtcutoff = 65.0                 ! MDT cutoff for computed correction
+   nn_profdavtypes = -1                ! Profile daily average types - array
 /
Index: /trunk/DOC/TexFiles/Namelist/namobs_example
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namobs_example	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namobs_example	(revision 6140)
@@ -1,63 +1,34 @@
 !-----------------------------------------------------------------------
-!       namobs    observation usage switch
+&namobs       !  observation usage switch
 !-----------------------------------------------------------------------
-!
-!  ln_t3d                  Logical switch for T profile observations         
-!  ln_s3d                  Logical switch for S profile observations          
-!  ln_ena                  Logical switch for ENACT insitu data set           
-!  ln_cor                  Logical switch for Coriolis insitu data set       
-!  ln_profb                Logical switch for feedback insitu data set     
-!  ln_sla                  Logical switch for SLA observations               
-!  ln_sladt                Logical switch for AVISO SLA data              
-!  ln_slafb                Logical switch for feedback SLA data            
-!  ln_ssh                  Logical switch for SSH observations              
-!  ln_sst                  Logical switch for SST observations              
-!  ln_reysst               Logical switch for Reynolds observations       
-!  ln_ghrsst               Logical switch for GHRSST observations          
-!  ln_sstfb                Logical switch for feedback SST data          
-!  ln_sss                  Logical switch for SSS observations              
-!  ln_seaice               Logical switch for Sea Ice observations        
-!  ln_vel3d                Logical switch for velocity observations         
-!  ln_velavcur             Logical switch for velocity daily av. cur.    
-!  ln_velhrcur             Logical switch for velocity high freq. cur.   
-!  ln_velavadcp            Logical switch for velocity daily av. ADCP  
-!  ln_velhradcp            Logical switch for velocity high freq. ADCP
-!  ln_velfb                Logical switch for feedback velocity data       
-!  ln_grid_global          Global distribtion of observations         
-!  ln_grid_search_lookup   Logical switch for obs grid search w/lookup table  
-!  grid_search_file        Grid search lookup file header 
-!  enactfiles              ENACT input observation file names 
-!  coriofiles              Coriolis input observation file name  
-!  profbfiles              Profile feedback input observation file name 
-!  ln_profb_enatim         Enact feedback input time setting switch    
-!  slafilesact             Active SLA input observation file name
-!  slafilespas             Passive SLA input observation file name 
-!  slafbfiles              Feedback SLA input observation file name 
-!  sstfiles                GHRSST input observation file name       
-!  sstfbfiles              Feedback SST input observation file name 
-!  seaicefiles             Sea Ice input observation file name 
-!  velavcurfiles           Vel. cur. daily av. input file name  
-!  velhvcurfiles           Vel. cur. high freq. input file name  
-!  velavadcpfiles          Vel. ADCP daily av. input file name    
-!  velhvadcpfiles          Vel. ADCP high freq. input file name 
-!  velfbfiles              Vel. feedback input observation file name 
-!  dobsini                 Initial date in window YYYYMMDD.HHMMSS       
-!  dobsend                 Final date in window YYYYMMDD.HHMMSS         
-!  n1dint                  Type of vertical interpolation method        
-!  n2dint                  Type of horizontal interpolation method       
-!  ln_nea                  Rejection of observations near land switch    
-!  nmsshc                  MSSH correction scheme                         
-!  mdtcorr                 MDT  correction                               
-!  mdtcutoff               MDT cutoff for computed correction          
-!  ln_altbias              Logical switch for alt bias                
-!  ln_ignmis               Logical switch for ignoring missing files   
-!  endailyavtypes          ENACT daily average types                    
- &namobs
-   ln_t3d = .true.
-   ln_s3d = .true.
-   ln_ena = .true.
-   enactfiles = 'enact.1.nc'
-   ln_grid_global = .true.
-   ln_grid_search_lookup = .true.
-   ln_ignmis = .true.  
-/ 
+   ln_diaobs  = .true.                 ! Logical switch for the observation operator
+   ln_t3d     = .true.                 ! Logical switch for T profile observations
+   ln_s3d     = .true.                 ! Logical switch for S profile observations
+   ln_sla     = .false.                ! Logical switch for SLA observations
+   ln_sst     = .false.                ! Logical switch for SST observations
+   ln_sic     = .false.                ! Logical switch for Sea Ice observations
+   ln_vel3d   = .false.                ! Logical switch for velocity observations
+   ln_altbias = .false.                ! Logical switch for altimeter bias correction
+   ln_nea     = .false.                ! Logical switch for rejection of observations near land
+   ln_grid_global = .true.             ! Logical switch for global distribution of observations
+   ln_grid_search_lookup = .false.     ! Logical switch for obs grid search w/lookup table
+   ln_ignmis  = .true.                 ! Logical switch for ignoring missing files
+   ln_s_at_t  = .false.                ! Logical switch for computing model S at T obs if not there
+   ln_sstnight = .false.               ! Logical switch for calculating night-time average for SST obs
+   cn_profbfiles = 'profiles_01.nc'    ! Profile feedback input observation file names
+   cn_slafbfiles = 'sla_01.nc'         ! SLA feedback input observation file names
+   cn_sstfbfiles = 'sst_01.nc'         ! SST feedback input observation file names
+   cn_sicfbfiles = 'sic_01.nc'         ! SIC feedback input observation file names
+   cn_velfbfiles = 'vel_01.nc'         ! Velocity feedback input observation file names
+   cn_altbiasfile = 'altbias.nc'       ! Altimeter bias input file name
+   cn_gridsearchfile = 'gridsearch.nc' ! Grid search file name
+   rn_gridsearchres = 0.5              ! Grid search resolution
+   rn_dobsini = 00010101.000000        ! Initial date in window YYYYMMDD.HHMMSS
+   rn_dobsend = 00010102.000000        ! Final date in window YYYYMMDD.HHMMSS
+   nn_1dint = 0                        ! Type of vertical interpolation method
+   nn_2dint = 0                        ! Type of horizontal interpolation method
+   nn_msshc = 0                        ! MSSH correction scheme
+   rn_mdtcorr = 1.61                   ! MDT  correction
+   rn_mdtcutoff = 65.0                 ! MDT cutoff for computed correction
+   nn_profdavtypes = -1                ! Profile daily average types - array
+/
Index: /trunk/DOC/TexFiles/Namelist/namptr
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namptr	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namptr	(revision 6140)
@@ -1,11 +1,6 @@
 !-----------------------------------------------------------------------
-&namptr       !   Poleward Transport Diagnostic
+&namptr       !   Poleward Transport Diagnostic                         (default F)
 !-----------------------------------------------------------------------
    ln_diaptr  = .false.    !  Poleward heat and salt transport (T) or not (F)
-   ln_diaznl  = .true.     !  Add zonal means and meridional stream functions
-   ln_subbas  = .true.     !  Atlantic/Pacific/Indian basins computation (T) or not
-                           !  (orca configuration only, need input basins mask file named "subbasins.nc"
-   ln_ptrcomp = .true.     !  Add decomposition : overturning
-   nn_fptr    =  1         !  Frequency of ptr computation [time step]
-   nn_fwri    =  15        !  Frequency of ptr outputs [time step]
+   ln_subbas  = .false.     !  Atlantic/Pacific/Indian basins computation (T) or not
 /
Index: /trunk/DOC/TexFiles/Namelist/namrun
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namrun	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namrun	(revision 6140)
@@ -9,16 +9,23 @@
    nn_leapy    =       0   !  Leap year calendar (1) or not (0)
    ln_rstart   = .false.   !  start from rest (F) or from a restart file (T)
-   nn_rstctl   =       0   !  restart control => activated only if ln_rstart = T
-                           !    = 0 nn_date0 read in namelist ; nn_it000 : read in namelist
-                           !    = 1 nn_date0 read in namelist ; nn_it000 : check consistancy between namelist and restart
-                           !    = 2 nn_date0 read in restart  ; nn_it000 : check consistancy between namelist and restart
-   cn_ocerst_in  = "restart"   !  suffix of ocean restart name (input)
-   cn_ocerst_out = "restart"   !  suffix of ocean restart name (output)
+      nn_euler    =    1         !  = 0 : start with forward time step if ln_rstart=T
+      nn_rstctl   =    0         !  restart control ==> activated only if ln_rstart=T
+                                 !    = 0 nn_date0 read in namelist ; nn_it000 : read in namelist
+                                 !    = 1 nn_date0 read in namelist ; nn_it000 : check consistancy between namelist and restart
+                                 !    = 2 nn_date0 read in restart  ; nn_it000 : check consistancy between namelist and restart
+      cn_ocerst_in  = "restart"  !  suffix of ocean restart name (input)
+      cn_ocerst_indir = "."      !  directory from which to read input ocean restarts
+      cn_ocerst_out = "restart"  !  suffix of ocean restart name (output)
+      cn_ocerst_outdir = "."     !  directory in which to write output ocean restarts
+   ln_iscpl    = .false.   !  cavity evolution forcing or coupling to ice sheet model (ln_iscpl = T => namsbc_iscpl)
    nn_istate   =       0   !  output the initial state (1) or not (0)
+   ln_rst_list = .false.   !  output restarts at list of times using nn_stocklist (T) or at set frequency with nn_stock (F)
    nn_stock    =    5475   !  frequency of creation of a restart file (modulo referenced to 1)
+   nn_stocklist = 0,0,0,0,0,0,0,0,0,0 ! List of timesteps when a restart file is to be written
    nn_write    =    5475   !  frequency of write in the output file   (modulo referenced to nn_it000)
    ln_dimgnnn  = .false.   !  DIMG file format: 1 file for all processors (F) or by processor (T)
    ln_mskland  = .false.   !  mask land points in NetCDF outputs (costly: + ~15%)
-   ln_clobber  = .false.   !  clobber (overwrite) an existing file
+   ln_cfmeta   = .false.   !  output additional data to netCDF files required for compliance with the CF metadata standard
+   ln_clobber  = .true.    !  clobber (overwrite) an existing file
    nn_chunksz  =       0   !  chunksize (bytes) for NetCDF file (works only with iom_nf90 routines)
 /
Index: /trunk/DOC/TexFiles/Namelist/namsbc
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namsbc	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namsbc	(revision 6140)
@@ -3,5 +3,6 @@
 !-----------------------------------------------------------------------
    nn_fsbc     = 5         !  frequency of surface boundary condition computation
-                           !     (also = the frequency of sea-ice model call)
+                           !     (also = the frequency of sea-ice & iceberg model call)
+                     ! Type of air-sea fluxes 
    ln_ana      = .false.   !  analytical formulation                    (T => fill namsbc_ana )
    ln_flx      = .false.   !  flux formulation                          (T => fill namsbc_flx )
@@ -9,29 +10,35 @@
    ln_blk_core = .true.    !  CORE bulk formulation                     (T => fill namsbc_core)
    ln_blk_mfs  = .false.   !  MFS bulk formulation                      (T => fill namsbc_mfs )
-   ln_cpl      = .false.   !  Coupled formulation                       (T => fill namsbc_cpl )
-   ln_apr_dyn  = .false.   !  Patm gradient added in ocean & ice Eqs.   (T => fill namsbc_apr )
+                     ! Type of coupling (Ocean/Ice/Atmosphere) :
+   ln_cpl      = .false.   !  atmosphere coupled   formulation          ( requires key_oasis3 )
+   ln_mixcpl   = .false.   !  forced-coupled mixed formulation          ( requires key_oasis3 )
+   nn_components = 0       !  configuration of the opa-sas OASIS coupling
+                           !  =0 no opa-sas OASIS coupling: default single executable configuration
+                           !  =1 opa-sas OASIS coupling: multi executable configuration, OPA component
+                           !  =2 opa-sas OASIS coupling: multi executable configuration, SAS component 
+   nn_limflx = -1          !  LIM3 Multi-category heat flux formulation (use -1 if LIM3 is not used)
+                           !  =-1  Use per-category fluxes, bypass redistributor, forced mode only, not yet implemented coupled
+                           !  = 0  Average per-category fluxes (forced and coupled mode)
+                           !  = 1  Average and redistribute per-category fluxes, forced mode only, not yet implemented coupled
+                           !  = 2  Redistribute a single flux over categories (coupled mode only)
+                     ! Sea-ice :
    nn_ice      = 2         !  =0 no ice boundary condition   ,
                            !  =1 use observed ice-cover      ,
-                           !  =2 ice-model used                         ("key_lim3" or "key_lim2)
-   nn_ice_embd = 0         !  =0 levitating ice (no mass exchange, concentration/dilution effect)
+                           !  =2 ice-model used                         ("key_lim3", "key_lim2", "key_cice")
+   nn_ice_embd = 1         !  =0 levitating ice (no mass exchange, concentration/dilution effect)
                            !  =1 levitating ice with mass and salt exchange but no presure effect
                            !  =2 embedded sea-ice (full salt and mass exchanges and pressure)
-   ln_dm2dc    = .false.   !  daily mean to diurnal cycle on short wave
+                     ! Misc. options of sbc : 
+   ln_traqsr   = .true.    !  Light penetration in the ocean            (T => fill namtra_qsr )
+      ln_dm2dc = .false.      !  daily mean to diurnal cycle on short wave
    ln_rnf      = .true.    !  runoffs                                   (T => fill namsbc_rnf)
-   nn_isf      = 0         !  ice shelf melting/freezing                (/=0 => fill namsbc_isf)
-                           !  0 =no isf                  1 = presence of ISF
-                           !  2 = bg03 parametrisation   3 = rnf file for isf
-                           !  4 = ISF fwf specified
-                           !  option 1 and 4 need ln_isfcav = .true. (domzgr)
    ln_ssr      = .true.    !  Sea Surface Restoring on T and/or S       (T => fill namsbc_ssr)
-   nn_fwb      = 3         !  FreshWater Budget: =0 unchecked
+   nn_fwb      = 2         !  FreshWater Budget: =0 unchecked
                            !     =1 global mean of e-p-r set to zero at each time step
                            !     =2 annual global mean of e-p-r set to zero
-                           !     =3 global emp set to zero and spread out over erp area
-   ln_wave = .false.       !  Activate coupling with wave (either Stokes Drift or Drag coefficient, or both)  (T => fill namsbc_wave)
-   ln_cdgw = .false.       !  Neutral drag coefficient read from wave model (T => fill namsbc_wave)
-   ln_sdw  = .false.       !  Computation of 3D stokes drift                (T => fill namsbc_wave)
-   nn_lsm  = 0             !  =0   land/sea mask for input fields is not applied (the field land/sea mask filename
-                           !       is left empty in namelist)  ,
-                           !  =1:n number of iterations of land/sea mask application for input fields
+   ln_apr_dyn  = .false.   !  Patm gradient added in ocean & ice Eqs.   (T => fill namsbc_apr )
+   ln_isf      = .false.   !  ice shelf melting/freezing                (T => fill namsbc_isf)
+   ln_wave = .false.       !  coupling with surface wave                    (T => fill namsbc_wave)
+   nn_lsm  = 0             !  =0 land/sea mask for input fields is not applied (keep empty land/sea mask filename field) ,
+                           !  =1:n number of iterations of land/sea mask application for input fields (fill land/sea mask filename field)
 /
Index: /trunk/DOC/TexFiles/Namelist/namsbc_apr
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namsbc_apr	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namsbc_apr	(revision 6140)
@@ -1,11 +1,11 @@
 !-----------------------------------------------------------------------
-&namsbc_apr    !   Atmospheric pressure used as ocean forcing or in bulk
+&namsbc_apr    !   Atmospheric pressure forcing (in ocean or bulk)      (ln_apr_dyn=T)
 !-----------------------------------------------------------------------
-!              ! file name ! frequency (hours) ! variable ! time interpol. !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
-!              !           !  (if <0  months)  !   name   !    (logical)   !  (T/F)  ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_apr      = 'patm'    ,         -1        ,'somslpre',    .true.      , .true.  , 'yearly'  ,  ''      ,   ''     , ''
+!              !  file name ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !            !  (if <0  months)  !   name    !  (logical)   !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_apr      = 'patm'     ,         -1        ,'somslpre',    .true.     , .true. , 'yearly'  ,  ''      ,   ''     , ''
 
    cn_dir      = './'       !  root directory for the location of the bulk files
-   rn_pref     = 101000._wp !  reference atmospheric pressure   [N/m2]/
+   rn_pref     = 101000.    !  reference atmospheric pressure   [N/m2]/
    ln_ref_apr  = .false.    !  ref. pressure: global mean Patm (T) or a constant (F)
    ln_apr_obc  = .false.    !  inverse barometer added to OBC ssh data
Index: /trunk/DOC/TexFiles/Namelist/namsbc_core
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namsbc_core	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namsbc_core	(revision 6140)
@@ -2,19 +2,23 @@
 &namsbc_core   !   namsbc_core  CORE bulk formulae
 !-----------------------------------------------------------------------
-!              !  file name                    ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
-!              !                               !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  !  filename     !
-   sn_wndi     = 'u_10.15JUNE2009_orca2'       ,         6         , 'U_10_MOD',   .false.    , .true. , 'yearly'  , ''       , 'Uwnd'   , ''
-   sn_wndj     = 'v_10.15JUNE2009_orca2'       ,         6         , 'V_10_MOD',   .false.    , .true. , 'yearly'  , ''       , 'Vwnd'   , ''
-   sn_qsr      = 'ncar_rad.15JUNE2009_orca2'   ,        24         , 'SWDN_MOD',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
-   sn_qlw      = 'ncar_rad.15JUNE2009_orca2'   ,        24         , 'LWDN_MOD',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
-   sn_tair     = 't_10.15JUNE2009_orca2'       ,         6         , 'T_10_MOD',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
-   sn_humi     = 'q_10.15JUNE2009_orca2'       ,         6         , 'Q_10_MOD',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
-   sn_prec     = 'ncar_precip.15JUNE2009_orca2',        -1         , 'PRC_MOD1',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
-   sn_snow     = 'ncar_precip.15JUNE2009_orca2',        -1         , 'SNOW'    ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
-   sn_tdif     = 'taudif_core'                 ,        24         , 'taudif'  ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
-!
+!              !  file name                   ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights                               ! rotation ! land/sea mask !
+!              !                              !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename                              ! pairing  ! filename      !
+   sn_wndi     = 'u_10.15JUNE2009_fill'       ,         6         , 'U_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'   , 'Uwnd'   , ''
+   sn_wndj     = 'v_10.15JUNE2009_fill'       ,         6         , 'V_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'   , 'Vwnd'   , ''
+   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,        24         , 'SWDN_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,        24         , 'LWDN_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_tair     = 't_10.15JUNE2009_fill'       ,         6         , 'T_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_humi     = 'q_10.15JUNE2009_fill'       ,         6         , 'Q_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_prec     = 'ncar_precip.15JUNE2009_fill',        -1         , 'PRC_MOD1',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_snow     = 'ncar_precip.15JUNE2009_fill',        -1         , 'SNOW'    ,   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_tdif     = 'taudif_core'                ,        24         , 'taudif'  ,   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+
    cn_dir      = './'      !  root directory for the location of the bulk files
-   ln_2m       = .false.   !  air temperature and humidity referenced at 2m (T) instead 10m (F)
    ln_taudif   = .false.   !  HF tau contribution: use "mean of stress module - module of the mean stress" data
+   rn_zqt      = 10.       !  Air temperature and humidity reference height (m)
+   rn_zu       = 10.       !  Wind vector reference height (m)
    rn_pfac     = 1.        !  multiplicative factor for precipitation (total & snow)
+   rn_efac     = 1.        !  multiplicative factor for evaporation (0. or 1.)
+   rn_vfac     = 0.        !  multiplicative factor for ocean/ice velocity
+                           !  in the calculation of the wind stress (0.=absolute winds or 1.=relative winds)
 /
Index: /trunk/DOC/TexFiles/Namelist/namsbc_cpl
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namsbc_cpl	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namsbc_cpl	(revision 6140)
@@ -1,23 +1,27 @@
 !-----------------------------------------------------------------------
-&namsbc_cpl    !   coupled ocean/atmosphere model                       ("key_coupled")
+&namsbc_cpl    !   coupled ocean/atmosphere model                       ("key_oasis3")
 !-----------------------------------------------------------------------
-!                    !     description       !  multiple  !    vector   !      vector          ! vector !
-!                    !                       ! categories !  reference  !    orientation       ! grids  !
+!                    !     description      !  multiple  !    vector   !      vector          ! vector !
+!                    !                      ! categories !  reference  !    orientation       ! grids  !
 ! send
-sn_snd_temp   =       'weighted oce and ice' ,    'no'    ,     ''      ,         ''           ,   ''
-sn_snd_alb    =       'weighted ice'         ,    'no'    ,     ''      ,         ''           ,   ''
-sn_snd_thick  =       'none'                 ,    'no'   ,     ''      ,         ''           ,   ''
-sn_snd_crt    =       'none'                 ,    'no'    , 'spherical' , 'eastward-northward' ,  'T'
-sn_snd_co2    =       'coupled'              ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_temp   =   'weighted oce and ice' ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_alb    =   'weighted ice'         ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_thick  =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_crt    =   'none'                 ,    'no'    , 'spherical' , 'eastward-northward' ,  'T'
+   sn_snd_co2    =   'coupled'              ,    'no'    ,     ''      ,         ''           ,   ''
 ! receive
-sn_rcv_w10m   =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
-sn_rcv_taumod =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
-sn_rcv_tau    =       'oce only'             ,    'no'    , 'cartesian' , 'eastward-northward',  'U,V'
-sn_rcv_dqnsdt =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
-sn_rcv_qsr    =       'oce and ice'          ,    'no'    ,     ''      ,         ''          ,   ''
-sn_rcv_qns    =       'oce and ice'          ,    'no'    ,     ''      ,         ''          ,   ''
-sn_rcv_emp    =       'conservative'         ,    'no'    ,     ''      ,         ''          ,   ''
-sn_rcv_rnf    =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
-sn_rcv_cal    =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
-sn_rcv_co2    =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_w10m   =   'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_taumod =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_tau    =   'oce only'             ,    'no'    , 'cartesian' , 'eastward-northward',  'U,V'
+   sn_rcv_dqnsdt =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_qsr    =   'oce and ice'          ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_qns    =   'oce and ice'          ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_emp    =   'conservative'         ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_rnf    =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_cal    =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_co2    =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+!
+   nn_cplmodel   =     1     !  Maximum number of models to/from which NEMO is potentialy sending/receiving data
+   ln_usecplmask = .false.   !  use a coupling mask file to merge data received from several models
+                             !   -> file cplmask.nc with the float variable called cplmask (jpi,jpj,nn_cplmodel)
 /
Index: /trunk/DOC/TexFiles/Namelist/namsbc_iscpl
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namsbc_iscpl	(revision 6140)
+++ /trunk/DOC/TexFiles/Namelist/namsbc_iscpl	(revision 6140)
@@ -0,0 +1,7 @@
+!-----------------------------------------------------------------------
+&namsbc_iscpl  !   land ice / ocean coupling option
+!-----------------------------------------------------------------------
+   nn_drown  = 10       ! number of iterations of the extrapolation loop (fill the new wet cells)
+   ln_hsb    = .false.  ! activate conservation module (conservation exact after a time of rn_fiscpl)
+   nn_fiscpl = 43800    ! (number of time step) conservation period (maybe should be fix to the coupling frequencey of restart frequency)
+/
Index: /trunk/DOC/TexFiles/Namelist/namsbc_isf
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namsbc_isf	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namsbc_isf	(revision 6140)
@@ -1,27 +1,31 @@
 !-----------------------------------------------------------------------
-&namsbc_isf    !  Top boundary layer (ISF)
+&namsbc_isf    !  Top boundary layer (ISF)                              (nn_isf >0)
 !-----------------------------------------------------------------------
+   nn_isf      = -99       !  ice shelf melting/freezing                (/=0 => fill namsbc_isf)
+                           !  1 = ISF explicit (cavity open)
+                           !  2 = bg03 parametrisation (cavity closed)  
+                           !  3 = ISF  specified in depth along the calving front (cavity closed)
+                           !  4 = ISF melting specified (cavity open)
+                           !  option 1 and 4 need ln_isfcav = .true. (domzgr)
 !              ! file name ! frequency (hours) ! variable ! time interpol. !  clim   ! 'yearly'/ ! weights  ! rotation !
 !              !           !  (if <0  months)  !   name   !    (logical)   !  (T/F)  ! 'monthly' ! filename ! pairing  !
 ! nn_isf == 4
-   sn_qisf      = 'rnfisf' ,         -12      ,'sohflisf',    .false.      , .true.  , 'yearly'  ,  ''      ,   ''
-   sn_fwfisf    = 'rnfisf' ,         -12      ,'sowflisf',    .false.      , .true.  , 'yearly'  ,  ''      ,   ''
+   sn_fwfisf     = 'rnfisf',         -12       ,'sowflisf',    .false.      , .true.  , 'yearly'  ,  ''      ,   ''
 ! nn_isf == 3
-   sn_rnfisf    = 'runoffs' ,         -12      ,'sofwfisf',    .false.      , .true.  , 'yearly'  ,  ''      ,   ''
-! nn_isf == 2 and 3
-   sn_depmax_isf = 'runoffs' ,       -12        ,'sozisfmax' ,   .false.  , .true.  , 'yearly'  ,  ''      ,   ''
-   sn_depmin_isf = 'runoffs' ,       -12        ,'sozisfmin' ,   .false.  , .true.  , 'yearly'  ,  ''      ,   ''
+   sn_rnfisf     = 'rnfisf',         -12       ,'sofwfisf',    .false.   , .true. , 'yearly'  ,  ''      ,   ''
+! nn_isf == 2 or 3
+   sn_depmax_isf = 'rnfisf',         -12       ,'sozisfmax',   .false.   , .true. , 'yearly'  ,  ''      ,   ''
+   sn_depmin_isf = 'rnfisf',         -12       ,'sozisfmin',   .false.   , .true. , 'yearly'  ,  ''      ,   ''
 ! nn_isf == 2
-   sn_Leff_isf = 'rnfisf' ,       0          ,'Leff'         ,   .false.  , .true.  , 'yearly'  ,  ''      ,   ''
-! for all case
-   ln_divisf   = .true.  ! apply isf melting as a mass flux or in the salinity trend. (maybe I should remove this option as for runoff?)
+   sn_Leff_isf = 'rnfisf'  ,         -12       ,'Leff'     ,    .false.  , .true. , 'yearly'  ,  ''      ,   ''
+
 ! only for nn_isf = 1 or 2
-   rn_gammat0  = 1.0e-4   ! gammat coefficient used in blk formula
-   rn_gammas0  = 1.0e-4   ! gammas coefficient used in blk formula
+   rn_gammat0  = 1.e-4    ! gammat coefficient used in blk formula
+   rn_gammas0  = 1.e-4    ! gammas coefficient used in blk formula
+! only for nn_isf = 1 or 4
+   nn_isfblk   =  1       ! 1 ISOMIP ; 2 conservative (3 equation formulation, Jenkins et al. 1991 ??)
 ! only for nn_isf = 1
-   nn_isfblk   =  1       ! 1 ISOMIP ; 2 conservative (3 equation formulation, Jenkins et al. 1991 ??)
-   rn_hisf_tbl =  30.      ! thickness of the top boundary layer           (Losh et al. 2008)
+   rn_hisf_tbl =  30.     ! thickness of the top boundary layer           (Losh et al. 2008)
                           ! 0 => thickness of the tbl = thickness of the first wet cell
-   ln_conserve = .true.   ! conservative case (take into account meltwater advection)
    nn_gammablk = 1        ! 0 = cst Gammat (= gammat/s)
                           ! 1 = velocity dependend Gamma (u* * gammat/s)  (Jenkins et al. 2010)
Index: /trunk/DOC/TexFiles/Namelist/namsbc_mfs
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namsbc_mfs	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namsbc_mfs	(revision 6140)
@@ -2,13 +2,14 @@
 &namsbc_mfs   !   namsbc_mfs  MFS bulk formulae
 !-----------------------------------------------------------------------
-!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
-!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_wndi     =   'ecmwf'   ,        6          , 'u10'     ,    .true.    , .false. , 'daily'  ,'bicubic.nc' , ''    , ''
-   sn_wndj     =   'ecmwf'   ,        6          , 'v10'     ,    .true.    , .false. , 'daily'  ,'bicubic.nc' , ''    , ''
-   sn_clc      =   'ecmwf'   ,        6          , 'clc'     ,    .true.    , .false. , 'daily'  ,'bilinear.nc', ''    , ''
-   sn_msl      =   'ecmwf'   ,        6          , 'msl'     ,    .true.    , .false. , 'daily'  ,'bicubic.nc' , ''    , ''
-   sn_tair     =   'ecmwf'   ,        6          , 't2'      ,    .true.    , .false. , 'daily'  ,'bicubic.nc' , ''    , ''
-   sn_rhm      =   'ecmwf'   ,        6          , 'rh'      ,    .true.    , .false. , 'daily'  ,'bilinear.nc', ''    , ''
-   sn_prec     =   'precip'  ,        6          , 'precip'  ,    .true.    , .false. , 'daily'  ,'bicubic'    , ''    , ''
-   cn_dir      =   './'      !  root directory for the location of the bulk files
+!              !  file name  ! frequency (hours) ! variable ! time interp. !  clim  ! 'yearly'/ ! weights     ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name   !   (logical)  !  (T/F) ! 'monthly' ! filename    ! pairing  ! filename      !
+   sn_wndi     =   'ecmwf'   ,        6          , 'u10'    ,    .true.    , .false., 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+   sn_wndj     =   'ecmwf'   ,        6          , 'v10'    ,    .true.    , .false., 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+   sn_clc      =   'ecmwf'   ,        6          , 'clc'    ,    .true.    , .false., 'daily'   ,'bilinear.nc',   ''     ,   ''
+   sn_msl      =   'ecmwf'   ,        6          , 'msl'    ,    .true.    , .false., 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+   sn_tair     =   'ecmwf'   ,        6          , 't2'     ,    .true.    , .false., 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+   sn_rhm      =   'ecmwf'   ,        6          , 'rh'     ,    .true.    , .false., 'daily'   ,'bilinear.nc',   ''     ,   ''
+   sn_prec     =   'ecmwf'   ,        6          , 'precip' ,    .true.    , .true. , 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+
+   cn_dir      = './ECMWF/'      !  root directory for the location of the bulk files
 /
Index: /trunk/DOC/TexFiles/Namelist/namsbc_rnf
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namsbc_rnf	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namsbc_rnf	(revision 6140)
@@ -1,15 +1,14 @@
 !-----------------------------------------------------------------------
-&namsbc_rnf    !   runoffs namelist surface boundary condition
+&namsbc_rnf    !   runoffs namelist surface boundary condition          (ln_rnf=T)
 !-----------------------------------------------------------------------
-!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
-!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_rnf      = 'runoff_core_monthly',    -1    , 'sorunoff',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
-   sn_cnf      = 'runoff_core_monthly',     0    , 'socoefr0',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
-   sn_s_rnf    = 'runoffs'            ,    24    , 'rosaline',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
-   sn_t_rnf    = 'runoffs'            ,    24    , 'rotemper',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
-   sn_dep_rnf  = 'runoffs'            ,     0    , 'rodepth' ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+!              !  file name           ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !                      !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_rnf      = 'runoff_core_monthly',        -1         , 'sorunoff',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_cnf      = 'runoff_core_monthly',         0         , 'socoefr0',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+   sn_s_rnf    = 'runoffs'            ,        24         , 'rosaline',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_t_rnf    = 'runoffs'            ,        24         , 'rotemper',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_dep_rnf  = 'runoffs'            ,         0         , 'rodepth' ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
 
    cn_dir       = './'      !  root directory for the location of the runoff files
-   ln_rnf_emp   = .false.   !  runoffs included into precipitation field (T) or into a file (F)
    ln_rnf_mouth = .true.    !  specific treatment at rivers mouths
    rn_hrnf      =  15.e0    !  depth over which enhanced vertical mixing is used
@@ -19,3 +18,7 @@
    ln_rnf_tem   = .false.   !  read in temperature information for runoff
    ln_rnf_sal   = .false.   !  read in salinity information for runoff
+   ln_rnf_depth_ini = .false.  ! compute depth at initialisation from runoff file
+   rn_rnf_max   = 5.735e-4  !  max value of the runoff climatologie over global domain ( ln_rnf_depth_ini = .true )
+   rn_dep_max   = 150.      !  depth over which runoffs is spread ( ln_rnf_depth_ini = .true )
+   nn_rnf_depth_file = 0    !  create (=1) a runoff depth file or not (=0)
 /
Index: /trunk/DOC/TexFiles/Namelist/namsbc_sas
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namsbc_sas	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namsbc_sas	(revision 6140)
@@ -4,11 +4,14 @@
 !              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
 !              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_usp      = 'sas_grid_U' ,    120    , 'vozocrtx' ,  .true.    , .true. ,   'yearly'  , ''       , ''             , ''
-   sn_vsp      = 'sas_grid_V' ,    120    , 'vomecrty' ,  .true.    , .true. ,   'yearly'  , ''       , ''             , ''
-   sn_tem      = 'sas_grid_T' ,    120    , 'sosstsst' ,  .true.    , .true. ,   'yearly'  , ''       , ''             , ''
-   sn_sal      = 'sas_grid_T' ,    120    , 'sosaline' ,  .true.    , .true. ,   'yearly'  , ''       , ''             , ''
-   sn_ssh      = 'sas_grid_T' ,    120    , 'sossheig' ,  .true.    , .true. ,   'yearly'  , ''       , ''             , ''
+   sn_usp      = 'sas_grid_U' ,    120           , 'vozocrtx' ,  .true.    , .true. ,   'yearly'  , ''       , ''             , ''
+   sn_vsp      = 'sas_grid_V' ,    120           , 'vomecrty' ,  .true.    , .true. ,   'yearly'  , ''       , ''             , ''
+   sn_tem      = 'sas_grid_T' ,    120           , 'sosstsst' ,  .true.    , .true. ,   'yearly'  , ''       , ''             , ''
+   sn_sal      = 'sas_grid_T' ,    120           , 'sosaline' ,  .true.    , .true. ,   'yearly'  , ''       , ''             , ''
+   sn_ssh      = 'sas_grid_T' ,    120           , 'sossheig' ,  .true.    , .true. ,   'yearly'  , ''       , ''             , ''
+   sn_e3t      = 'sas_grid_T' ,    120           , 'e3t_m'    ,  .true.    , .true. ,   'yearly'  , ''       , ''             , ''
+   sn_frq      = 'sas_grid_T' ,    120           , 'frq_m'    ,  .true.    , .true. ,   'yearly'  , ''       , ''             , ''
 
-   ln_3d_uv    = .true.    !  specify whether we are supplying a 3D u,v field
+   ln_3d_uve   = .true.    !  specify whether we are supplying a 3D u,v and e3 field
+   ln_read_frq = .false.    !  specify whether we must read frq or not
    cn_dir      = './'      !  root directory for the location of the bulk files are
 /
Index: /trunk/DOC/TexFiles/Namelist/namsbc_ssr
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namsbc_ssr	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namsbc_ssr	(revision 6140)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&namsbc_ssr    !   surface boundary condition : sea surface restoring
+&namsbc_ssr    !   surface boundary condition : sea surface restoring   (ln_ssr=T)
 !-----------------------------------------------------------------------
 !              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
Index: /trunk/DOC/TexFiles/Namelist/namsbc_wave
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namsbc_wave	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namsbc_wave	(revision 6140)
@@ -1,12 +1,14 @@
 !-----------------------------------------------------------------------
-&namsbc_wave   ! External fields from wave model
+&namsbc_wave   ! External fields from wave model                        (ln_wave=T)
 !-----------------------------------------------------------------------
-!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
-!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_cdg      =  'cdg_wave' ,        1          , 'drag_coeff' , .true.    , .false. , 'daily'  , ''       , ''       , ''
-   sn_usd      =  'sdw_wave' ,        1          , 'u_sd2d'     , .true.   , .false. , 'daily'  ,''         , ''       , ''
-   sn_vsd      =  'sdw_wave' ,        1          , 'v_sd2d'     , .true.   , .false. , 'daily'  ,''         , ''       , ''
-   sn_wn       =  'sdw_wave' ,        1          , 'wave_num'   , .true.   , .false. , 'daily'  ,''         , ''       , ''
+!              !  file name  ! frequency (hours) ! variable    ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name      !  (logical)   !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_cdg      =  'cdg_wave' ,        1          , 'drag_coeff',     .true.   , .false., 'daily'   ,  ''      , ''       , ''
+   sn_usd      =  'sdw_wave' ,        1          , 'u_sd2d'    ,     .true.   , .false., 'daily'   ,  ''      , ''       , ''
+   sn_vsd      =  'sdw_wave' ,        1          , 'v_sd2d'    ,     .true.   , .false., 'daily'   ,  ''      , ''       , ''
+   sn_wn       =  'sdw_wave' ,        1          , 'wave_num'  ,     .true.   , .false., 'daily'   ,  ''      , ''       , ''
 !
-   cn_dir_cdg  = './'  !  root directory for the location of drag coefficient files
+   cn_dir_cdg  = './'      !  root directory for the location of drag coefficient files
+   ln_cdgw = .false.       !  Neutral drag coefficient read from wave model
+   ln_sdw  = .false.       !  Computation of 3D stokes drift               
 /
Index: /trunk/DOC/TexFiles/Namelist/namtra_adv
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namtra_adv	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namtra_adv	(revision 6140)
@@ -1,11 +1,17 @@
 !-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer
+&namtra_adv    !   advection scheme for tracer                          (default: NO advection)
 !-----------------------------------------------------------------------
-   ln_traadv_cen2   =  .false.  !  2nd order centered scheme
-   ln_traadv_tvd    =  .true.   !  TVD scheme
-   ln_traadv_muscl  =  .false.  !  MUSCL scheme
-   ln_traadv_muscl2 =  .false.  !  MUSCL2 scheme + cen2 at boundaries
-   ln_traadv_ubs    =  .false.  !  UBS scheme
-   ln_traadv_qck    =  .false.  !  QUICKEST scheme
-   ln_traadv_msc_ups=  .false.  !  use upstream scheme within muscl
+   ln_traadv_cen =  .false.  !  2nd order centered scheme
+      nn_cen_h   =  4               !  =2/4, horizontal 2nd order CEN / 4th order CEN
+      nn_cen_v   =  4               !  =2/4, vertical   2nd order CEN / 4th order COMPACT
+   ln_traadv_fct =  .false.  !  FCT scheme
+      nn_fct_h   =  2               !  =2/4, horizontal 2nd / 4th order 
+      nn_fct_v   =  2               !  =2/4, vertical   2nd / COMPACT 4th order 
+      nn_fct_zts =  0               !  >=1,  2nd order FCT scheme with vertical sub-timestepping
+      !                             !        (number of sub-timestep = nn_fct_zts)
+   ln_traadv_mus =  .false.  !  MUSCL scheme
+      ln_mus_ups =  .false.         !  use upstream scheme near river mouths
+   ln_traadv_ubs =  .false.  !  UBS scheme
+      nn_ubs_v   =  2               !  =2  , vertical 2nd order FCT / COMPACT 4th order
+   ln_traadv_qck =  .false.  !  QUICKEST scheme
 /
Index: /trunk/DOC/TexFiles/Namelist/namtra_dmp
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namtra_dmp	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namtra_dmp	(revision 6140)
@@ -1,10 +1,9 @@
 !-----------------------------------------------------------------------
-&namtra_dmp    !   tracer: T & S newtonian damping
+&namtra_dmp    !   tracer: T & S newtonian damping                      (default: NO)
 !-----------------------------------------------------------------------
-   ln_tradmp   =  .true.     !  add a damping termn (T) or not (F)
-   nn_zdmp     =    0        !  vertical   shape =0    damping throughout the water column
-                             !                   =1 no damping in the mixing layer (kz  criteria)
-                             !                   =2 no damping in the mixed  layer (rho crieria)
-   cn_resto    = 'resto.nc'  ! Name of file containing restoration coefficient field (use dmp_tools to create this)
-
+   ln_tradmp   =  .true.   !  add a damping termn (T) or not (F)
+   nn_zdmp     =    0      !  vertical   shape =0    damping throughout the water column
+                           !                   =1 no damping in the mixing layer (kz  criteria)
+                           !                   =2 no damping in the mixed  layer (rho crieria)
+   cn_resto    ='resto.nc' !  Name of file containing restoration coeff. field (use dmp_tools to create this)
 /
Index: /trunk/DOC/TexFiles/Namelist/namtra_ldf
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namtra_ldf	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namtra_ldf	(revision 6140)
@@ -1,28 +1,32 @@
-!----------------------------------------------------------------------------------
-&namtra_ldf    !   lateral diffusion scheme for tracers
-!----------------------------------------------------------------------------------
+!-----------------------------------------------------------------------
+&namtra_ldf    !   lateral diffusion scheme for tracers                 (default: NO diffusion)
+!-----------------------------------------------------------------------
    !                       !  Operator type:
-   ln_traldf_lap    =  .true.   !  laplacian operator
-   ln_traldf_bilap  =  .false.  !  bilaplacian operator
+   !                           !  no diffusion: set ln_traldf_lap=..._blp=F 
+   ln_traldf_lap   =  .false.  !    laplacian operator
+   ln_traldf_blp   =  .false.  !  bilaplacian operator
    !                       !  Direction of action:
-   ln_traldf_level  =  .false.  !  iso-level
-   ln_traldf_hor    =  .false.  !  horizontal (geopotential)   (needs "key_ldfslp" when ln_sco=T)
-   ln_traldf_iso    =  .true.   !  iso-neutral                 (needs "key_ldfslp")
-   !		       	   !  Griffies parameters              (all need "key_ldfslp")
-   ln_traldf_grif   =  .false.  !  use griffies triads
-   ln_traldf_gdia   =  .false.  !  output griffies eddy velocities
-   ln_triad_iso     =  .false.  !  pure lateral mixing in ML
-   ln_botmix_grif   =  .false.  !  lateral mixing on bottom
-   !                       !  Coefficients
-   ! Eddy-induced (GM) advection always used with Griffies; otherwise needs "key_traldf_eiv"
-   ! Value rn_aeiv_0 is ignored unless = 0 with Held-Larichev spatially varying aeiv
-   !                                  (key_traldf_c2d & key_traldf_eiv & key_orca_r2, _r1 or _r05)
-   rn_aeiv_0        =  2000.    !  eddy induced velocity coefficient [m2/s]
-   rn_aht_0         =  2000.    !  horizontal eddy diffusivity for tracers [m2/s]
-   rn_ahtb_0        =     0.    !  background eddy diffusivity for ldf_iso [m2/s]
-   !                                           (normally=0; not used with Griffies)
-   rn_slpmax        =     0.01  !  slope limit
-   rn_chsmag        =     1.    !  multiplicative factor in Smagorinsky diffusivity
-   rn_smsh          =     1.    !  Smagorinsky diffusivity: = 0 - use only sheer
-   rn_aht_m         =  2000.    !  upper limit or stability criteria for lateral eddy diffusivity (m2/s)
+   ln_traldf_lev   =  .false.  !  iso-level
+   ln_traldf_hor   =  .false.  !  horizontal (geopotential)
+   ln_traldf_iso   =  .false.  !  iso-neutral (standard operator)
+   ln_traldf_triad =  .false.  !  iso-neutral (triad    operator)
+   !
+   !		       	         !  iso-neutral options:        
+   ln_traldf_msc   =  .false.  !  Method of Stabilizing Correction (both operators)
+   rn_slpmax       =   0.01    !  slope limit                      (both operators)
+   ln_triad_iso    =  .false.  !  pure horizontal mixing in ML              (triad only)
+   rn_sw_triad     =  1        !  =1 switching triad ; =0 all 4 triads used (triad only)
+   ln_botmix_triad =  .false.  !  lateral mixing on bottom                  (triad only)
+   !
+   !                       !  Coefficients:
+   nn_aht_ijk_t    = 0         !  space/time variation of eddy coef
+   !                                !   =-20 (=-30)    read in eddy_diffusivity_2D.nc (..._3D.nc) file
+   !                                !   =  0           constant 
+   !                                !   = 10 F(k)      =ldf_c1d 
+   !                                !   = 20 F(i,j)    =ldf_c2d 
+   !                                !   = 21 F(i,j,t)  =Treguier et al. JPO 1997 formulation
+   !                                !   = 30 F(i,j,k)  =ldf_c2d * ldf_c1d
+   !                                !   = 31 F(i,j,k,t)=F(local velocity and grid-spacing)
+   rn_aht_0        = 2000.     !  lateral eddy diffusivity   (lap. operator) [m2/s]
+   rn_bht_0        = 1.e+12    !  lateral eddy diffusivity (bilap. operator) [m4/s]
 /
Index: /trunk/DOC/TexFiles/Namelist/namtra_qsr
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namtra_qsr	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namtra_qsr	(revision 6140)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&namtra_qsr    !   penetrative solar radiation
+&namtra_qsr    !   penetrative solar radiation                          (ln_traqsr=T)
 !-----------------------------------------------------------------------
 !              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
@@ -7,5 +7,4 @@
 
    cn_dir      = './'      !  root directory for the location of the runoff files
-   ln_traqsr   = .true.    !  Light penetration (T) or not (F)
    ln_qsr_rgb  = .true.    !  RGB (Red-Green-Blue) light penetration
    ln_qsr_2bd  = .false.   !  2 bands              light penetration
@@ -15,3 +14,4 @@
    rn_si0      =   0.35    !  RGB & 2 bands: shortess depth of extinction
    rn_si1      =   23.0    !  2 bands: longest depth of extinction
+   ln_qsr_ice  = .true.    !  light penetration for ice-model LIM3
 /
Index: /trunk/DOC/TexFiles/Namelist/namtrd
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namtrd	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namtrd	(revision 6140)
@@ -1,12 +1,14 @@
 !-----------------------------------------------------------------------
-&namtrd        !   diagnostics on dynamics and/or tracer trends         ("key_trddyn" and/or "key_trdtra")
-!              !       or mixed-layer trends or barotropic vorticity    ("key_trdmld" or     "key_trdvor")
+&namtrd        !   diagnostics on dynamics and/or tracer trends         (default F)
+!              !   and/or mixed-layer trends and/or barotropic vorticity
 !-----------------------------------------------------------------------
-   nn_trd      = 365       !  time step frequency dynamics and tracers trends
-   nn_ctls     =   0       !  control surface type in mixed-layer trends (0,1 or n<jpk)
-   rn_ucf      =   1.      !  unit conversion factor (=1 -> /seconds ; =86400. -> /day)
-   cn_trdrst_in      = "restart_mld"   ! suffix of ocean restart name (input)
-   cn_trdrst_out     = "restart_mld"   ! suffix of ocean restart name (output)
-   ln_trdmld_restart = .false.         !  restart for ML diagnostics
-   ln_trdmld_instant = .false.         !  flag to diagnose trends of instantantaneous or mean ML T/S
+   ln_glo_trd  = .false.   ! (T) global domain averaged diag for T, T^2, KE, and PE
+   ln_dyn_trd  = .false.   ! (T) 3D momentum trend output
+   ln_dyn_mxl  = .false.   ! (T) 2D momentum trends averaged over the mixed layer (not coded yet)
+   ln_vor_trd  = .false.   ! (T) 2D barotropic vorticity trends (not coded yet)
+   ln_KE_trd   = .false.   ! (T) 3D Kinetic   Energy     trends
+   ln_PE_trd   = .false.   ! (T) 3D Potential Energy     trends
+   ln_tra_trd  = .false.   ! (T) 3D tracer trend output
+   ln_tra_mxl  = .false.   ! (T) 2D tracer trends averaged over the mixed layer (not coded yet)
+   nn_trd      = 365       !  print frequency (ln_glo_trd=T) (unit=time step)
 /
Index: /trunk/DOC/TexFiles/Namelist/namtsd
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namtsd	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namtsd	(revision 6140)
@@ -2,8 +2,8 @@
 &namtsd    !   data : Temperature  & Salinity
 !-----------------------------------------------------------------------
-!          ! file name ! frequency (hours)         ! variable     ! time interp. ! clim  !'yearly' or ! weights  ! rotation ! land/sea mask !
-!          !           !  (if <0  months)          !   name       !  (logical)   ! (T/F) ! 'monthly'  ! filename ! pairing  ! filename      !
-   sn_tem  = 'data_1m_potential_temperature_nomask', -1,'votemper',  .true.      , .true., 'yearly'   , ' '      , ' '      , ''
-   sn_sal  = 'data_1m_salinity_nomask'             , -1,'vosaline',  .true.      , .true., 'yearly'   , ''       , ' '      , ''
+!          !  file name                            ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!          !                                       !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_tem  = 'data_1m_potential_temperature_nomask',         -1        ,'votemper' ,    .true.    , .true. , 'yearly'   , ''       ,   ''    ,    ''
+   sn_sal  = 'data_1m_salinity_nomask'             ,         -1        ,'vosaline' ,    .true.    , .true. , 'yearly'   , ''       ,   ''    ,    ''
    !
    cn_dir        = './'     !  root directory for the location of the runoff files
Index: /trunk/DOC/TexFiles/Namelist/namzdf_gls
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namzdf_gls	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namzdf_gls	(revision 6140)
@@ -2,17 +2,17 @@
 &namzdf_gls                !   GLS vertical diffusion                   ("key_zdfgls")
 !-----------------------------------------------------------------------
-   rn_emin       = 1.e-6   !  minimum value of e   [m2/s2]
+   rn_emin       = 1.e-7   !  minimum value of e   [m2/s2]
    rn_epsmin     = 1.e-12  !  minimum value of eps [m2/s3]
    ln_length_lim = .true.  !  limit on the dissipation rate under stable stratification (Galperin et al., 1988)
-   rn_clim_galp  = 0.53    !  galperin limit
-   ln_crban      = .true.  !  Use Craig & Banner (1994) surface wave mixing parametrisation
+   rn_clim_galp  = 0.267   !  galperin limit
    ln_sigpsi     = .true.  !  Activate or not Burchard 2001 mods on psi schmidt number in the wb case
    rn_crban      = 100.    !  Craig and Banner 1994 constant for wb tke flux
    rn_charn      = 70000.  !  Charnock constant for wb induced roughness length
-   nn_tkebc_surf =   1     !  surface tke condition (0/1/2=Dir/Neum/Dir Mellor-Blumberg)
-   nn_tkebc_bot  =   1     !  bottom tke condition (0/1=Dir/Neum)
-   nn_psibc_surf =   1     !  surface psi condition (0/1/2=Dir/Neum/Dir Mellor-Blumberg)
-   nn_psibc_bot  =   1     !  bottom psi condition (0/1=Dir/Neum)
-   nn_stab_func  =   2     !  stability function (0=Galp, 1= KC94, 2=CanutoA, 3=CanutoB)
-   nn_clos       =   1     !  predefined closure type (0=MY82, 1=k-eps, 2=k-w, 3=Gen)
+   rn_hsro       =  0.02   !  Minimum surface roughness
+   rn_frac_hs    =   1.3   !  Fraction of wave height as roughness (if nn_z0_met=2)
+   nn_z0_met     =     2   !  Method for surface roughness computation (0/1/2)
+   nn_bc_surf    =     1   !  surface condition (0/1=Dir/Neum)
+   nn_bc_bot     =     1   !  bottom condition (0/1=Dir/Neum)
+   nn_stab_func  =     2   !  stability function (0=Galp, 1= KC94, 2=CanutoA, 3=CanutoB)
+   nn_clos       =     1   !  predefined closure type (0=MY82, 1=k-eps, 2=k-w, 3=Gen)
 /
Index: /trunk/DOC/TexFiles/Namelist/namzdf_tke
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namzdf_tke	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namzdf_tke	(revision 6140)
@@ -21,5 +21,5 @@
                            !        = 1 add a tke source below the ML
                            !        = 2 add a tke source just at the base of the ML
-                           !        = 3 as = 1 applied on HF part of the stress    ("key_coupled")
+                           !        = 3 as = 1 applied on HF part of the stress    ("key_oasis3")
    rn_efr      =   0.05    !  fraction of surface tke value which penetrates below the ML (nn_etau=1 or 2)
    nn_htau     =   1       !  type of exponential decrease of tke penetration below the ML
Index: /trunk/DOC/TexFiles/Namelist/namzgr
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namzgr	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namzgr	(revision 6140)
@@ -1,8 +1,9 @@
 !-----------------------------------------------------------------------
-&namzgr        !   vertical coordinate
+&namzgr        !   vertical coordinate                                  (default: NO selection)
 !-----------------------------------------------------------------------
-   ln_zco      = .false.   !  z-coordinate - full    steps   (T/F)      ("key_zco" may also be defined)
-   ln_zps      = .true.    !  z-coordinate - partial steps   (T/F)
-   ln_sco      = .false.   !  s- or hybrid z-s-coordinate    (T/F)
-   ln_isfcav   = .false.   !  ice shelf cavity               (T/F)
+   ln_zco      = .false.   !  z-coordinate - full    steps
+   ln_zps      = .false.   !  z-coordinate - partial steps
+   ln_sco      = .false.   !  s- or hybrid z-s-coordinate
+   ln_isfcav   = .false.   !  ice shelf cavity
+   ln_linssh   = .false.   !  linear free surface
 /
Index: /trunk/DOC/TexFiles/Namelist/namzgr_sco
===================================================================
--- /trunk/DOC/TexFiles/Namelist/namzgr_sco	(revision 6139)
+++ /trunk/DOC/TexFiles/Namelist/namzgr_sco	(revision 6140)
@@ -2,5 +2,5 @@
 &namzgr_sco    !   s-coordinate or hybrid z-s-coordinate
 !-----------------------------------------------------------------------
-   ln_s_sh94   = .true.    !  Song & Haidvogel 1994 hybrid S-sigma   (T)|
+   ln_s_sh94   = .false.    !  Song & Haidvogel 1994 hybrid S-sigma   (T)|
    ln_s_sf12   = .false.   !  Siddorn & Furner 2012 hybrid S-z-sigma (T)| if both are false the NEMO tanh stretching is applied
    ln_sigcrit  = .false.   !  use sigma coordinates below critical depth (T) or Z coordinates (F) for Siddorn & Furner stretch
@@ -13,5 +13,5 @@
                         !!!!!!!  SH94 stretching coefficients  (ln_s_sh94 = .true.)
    rn_theta    =    6.0    !  surface control parameter (0<=theta<=20)
-   rn_bb       =    0.8    !  stretching with SH94 s-sigma   
+   rn_bb       =    0.8    !  stretching with SH94 s-sigma
                         !!!!!!!  SF12 stretching coefficient  (ln_s_sf12 = .true.)
    rn_alpha    =    4.4    !  stretching with SF12 s-sigma
@@ -22,4 +22,4 @@
    rn_zb_b     =   -0.2    !  offset for calculating Zb
                         !!!!!!!! Other stretching (not SH94 or SF12) [also uses rn_theta above]
-   rn_thetb    =    1.0    !  bottom control parameter  (0<=thetb<= 1) 
+   rn_thetb    =    1.0    !  bottom control parameter  (0<=thetb<= 1)
 /
Index: unk/NEMOGCM/ARCH/CMCC/arch-PW6_calypso.fcm
===================================================================
--- /trunk/NEMOGCM/ARCH/CMCC/arch-PW6_calypso.fcm	(revision 6139)
+++ 	(revision )
@@ -1,34 +1,0 @@
-# vargas IBM POWER6 at french IDRIS, http://www.idris.fr/su/Scalaire/vargas/hw-vargas.html
-# NCDF_INC    netcdf include file
-# NCDF_LIB    netcdf library
-# FC          Fortran compiler command
-# FCFLAGS     Fortran compiler flags
-# FFLAGS      Fortran 77 compiler flags
-# LD          linker
-# LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
-# FPPFLAGS    pre-processing flags
-# AR          assembler
-# ARFLAGS     assembler flags
-# MK          make  
-# USER_INC    additional include files for the compiler,  e.g. -I<include dir> 
-# USER_LIB    additional libraries to pass to the linker, e.g. -l<library>
-# CC          C compiler used to compile conv for AGRIF
-# CFLAGS      compiler flags used with CC
-
-
-%NCDF_INC            -I/usr/local/netcdf-3.6.3/include
-%NCDF_LIB            -L/usr/local/netcdf-3.6.3/lib -lnetcdf
-%CPP                 cpp
-%FC                  mpxlf90_r
-%FCFLAGS             -O3 -qsuffix=f=f90  -qstrict -qalias=intptr -qsuppress=1501-245 -qarch=pwr6 -q64 -qrealsize=8 -qtune=pwr6 -qextname -qlargepage -qmaxmem=-1
-%FFLAGS              -O3 -qsuffix=f=f90  -qstrict -qalias=intptr -qsuppress=1501-245 -qarch=pwr6 -q64 -qrealsize=8 -qtune=pwr6 -qextname -qlargepage -qmaxmem=-1
-%LD                  mpxlf90_r
-%LDFLAGS             -bloadmap:LinkerErrorMap 
-%FPPFLAGS            -P -C
-%AR                  ar  
-%ARFLAGS             rs
-%MK                  gmake 
-%USER_INC            %NCDF_INC
-%USER_LIB            %NCDF_LIB 
-%CC                  xlc
-%CFLAGS              -O -qcpluscmt
Index: unk/NEMOGCM/ARCH/CMCC/arch-PW6_calypso_debug.fcm
===================================================================
--- /trunk/NEMOGCM/ARCH/CMCC/arch-PW6_calypso_debug.fcm	(revision 6139)
+++ 	(revision )
@@ -1,34 +1,0 @@
-# vargas IBM POWER6 at french IDRIS, http://www.idris.fr/su/Scalaire/vargas/hw-vargas.html
-# NCDF_INC    netcdf include file
-# NCDF_LIB    netcdf library
-# FC          Fortran compiler command
-# FCFLAGS     Fortran compiler flags
-# FFLAGS      Fortran 77 compiler flags
-# LD          linker
-# LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
-# FPPFLAGS    pre-processing flags
-# AR          assembler
-# ARFLAGS     assembler flags
-# MK          make  
-# USER_INC    additional include files for the compiler,  e.g. -I<include dir> 
-# USER_LIB    additional libraries to pass to the linker, e.g. -l<library>
-# CC          C compiler used to compile conv for AGRIF
-# CFLAGS      compiler flags used with CC
-
-
-%NCDF_INC            -I/usr/local/netcdf-3.6.3/include
-%NCDF_LIB            -L/usr/local/netcdf-3.6.3/lib -lnetcdf
-%CPP                 cpp
-%FC                  mpxlf90_r
-%FCFLAGS             -g -qsuffix=f=f90  -qstrict -qalias=intptr -qsuppress=1501-245 -qarch=pwr6 -q64 -qrealsize=8 -qtune=pwr6 -qextname -qlargepage -qmaxmem=-1
-%FFLAGS              -g -qsuffix=f=f90  -qstrict -qalias=intptr -qsuppress=1501-245 -qarch=pwr6 -q64 -qrealsize=8 -qtune=pwr6 -qextname -qlargepage -qmaxmem=-1
-%LD                  mpxlf90_r
-%LDFLAGS             -bloadmap:LinkerErrorMap 
-%FPPFLAGS            -P -C
-%AR                  ar  
-%ARFLAGS             rs
-%MK                  gmake 
-%USER_INC            %NCDF_INC
-%USER_LIB            %NCDF_LIB 
-%CC                  xlc
-%CFLAGS              -O -qcpluscmt
Index: unk/NEMOGCM/ARCH/CMCC/arch-PW6_calypso_tools.fcm
===================================================================
--- /trunk/NEMOGCM/ARCH/CMCC/arch-PW6_calypso_tools.fcm	(revision 6139)
+++ 	(revision )
@@ -1,34 +1,0 @@
-# vargas IBM POWER6 at french IDRIS, http://www.idris.fr/su/Scalaire/vargas/hw-vargas.html
-# NCDF_INC    netcdf include file
-# NCDF_LIB    netcdf library
-# FC          Fortran compiler command
-# FCFLAGS     Fortran compiler flags
-# FFLAGS      Fortran 77 compiler flags
-# LD          linker
-# LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
-# FPPFLAGS    pre-processing flags
-# AR          assembler
-# ARFLAGS     assembler flags
-# MK          make  
-# USER_INC    additional include files for the compiler,  e.g. -I<include dir> 
-# USER_LIB    additional libraries to pass to the linker, e.g. -l<library>
-# CC          C compiler used to compile conv for AGRIF
-# CFLAGS      compiler flags used with CC
-
-
-%NCDF_INC            -I/usr/local/netcdf-3.6.3/include
-%NCDF_LIB            -L/usr/local/netcdf-3.6.3/lib -lnetcdf
-%CPP                 cpp
-%FC                  xlf90
-%FCFLAGS             -O3 -qsuffix=f=f90  -qstrict -qsuppress=1501-245 -qarch=pwr6 -q64 -qrealsize=8 -qtune=pwr6 -qextname -qlargepage -qmaxmem=-1
-%FFLAGS              -O3 -qsuffix=f=f90  -qstrict -qsuppress=1501-245 -qarch=pwr6 -q64 -qrealsize=8 -qtune=pwr6 -qextname -qlargepage -qmaxmem=-1
-%LD                  xlf90
-%LDFLAGS             -bloadmap:LinkerErrorMap 
-%FPPFLAGS            -P -C
-%AR                  ar  
-%ARFLAGS             rs
-%MK                  gmake 
-%USER_INC            %NCDF_INC
-%USER_LIB            %NCDF_LIB 
-%CC                  xlc
-%CFLAGS              -O -qcpluscmt
Index: /trunk/NEMOGCM/ARCH/CMCC/arch-ifort_athena.fcm
===================================================================
--- /trunk/NEMOGCM/ARCH/CMCC/arch-ifort_athena.fcm	(revision 6139)
+++ /trunk/NEMOGCM/ARCH/CMCC/arch-ifort_athena.fcm	(revision 6140)
@@ -17,6 +17,6 @@
 
 
-%NCDF_INC -I$NETCDF/include
-%NCDF_LIB -L$NETCDF/lib -lnetcdf -lnetcdff
+%NCDF_INC -I${NETCDF}/include
+%NCDF_LIB -L${NETCDF}/lib -lnetcdf -lnetcdff
 %CPP                 cpp
 %FC mpiifort
Index: /trunk/NEMOGCM/ARCH/CMCC/arch-ifort_athena_xios.fcm
===================================================================
--- /trunk/NEMOGCM/ARCH/CMCC/arch-ifort_athena_xios.fcm	(revision 6139)
+++ /trunk/NEMOGCM/ARCH/CMCC/arch-ifort_athena_xios.fcm	(revision 6140)
@@ -34,22 +34,24 @@
 
 # required modules
-# module load  INTEL/intel_xe_2013 NETCDF/netcdf-4.3_parallel NETCDF/parallel-netcdf-1.3.1 HDF5/hdf5-1.8.11_parallel
+# module load  INTEL/intel_xe_2013 NETCDF/netcdf-4.3_parallel_shared NETCDF/parallel-netcdf-1.3.1 HDF5/hdf5-1.8.11_parallel_shared
 
 # Environment variables set by user. Others should automatically define when loading modules.
-# export XIOS=/users/home/models/nemo/xios
+#export XIOS=/users/home/models/nemo/xios
+#export HDF5=/users/home/opt/hdf5/hdf5-1.8.11_parallel_shared
+#export NETCDF=/users/home/opt/netcdf/netcdf-4.3_parallel_shared
 
-%NCDF_INC            -I$NETCDF/include -I$PNETCDF/include
-%NCDF_LIB            -L$NETCDF/lib -lnetcdff -lnetcdf -L$PNETCDF/lib -lpnetcdf
-%HDF5_INC            -I$PHDF5/include
-%HDF5_LIB            -L$PHDF5/lib -lhdf5_hl -lhdf5
-%XIOS_INC            -I$XIOS/inc
-%XIOS_LIB            -L$XIOS/lib -lxios
+%NCDF_INC            -I${NETCDF}/include 
+%NCDF_LIB            -L${NETCDF}/lib -lnetcdff -lnetcdf
+%HDF5_INC            -I${HDF5}/include
+%HDF5_LIB            -L${HDF5}/lib -lhdf5_hl -lhdf5
+%XIOS_INC            -I${XIOS}/inc
+%XIOS_LIB            -L${XIOS}/lib -lxios
 %CPP                 cpp
 %FC                  mpiifort
-%FCFLAGS             -r8 -O3 -xHost -fp-model source -traceback
+%FCFLAGS             -r8 -O3 -xHost -fp-model source -traceback ${CFLAGS} 
 %FFLAGS              %FCFLAGS
 %LD                  mpiifort
 %FPPFLAGS            -P -C -traditional
-%LDFLAGS             -lstdc++ -lz -lgpfs -lcurl
+%LDFLAGS             -lstdc++ -lz -lgpfs -lcurl  ${LDFLAGS}
 %AR                  ar 
 %ARFLAGS             -r
Index: /trunk/NEMOGCM/ARCH/arch-X64_MOBILIS.fcm
===================================================================
--- /trunk/NEMOGCM/ARCH/arch-X64_MOBILIS.fcm	(revision 6139)
+++ /trunk/NEMOGCM/ARCH/arch-X64_MOBILIS.fcm	(revision 6140)
@@ -38,5 +38,5 @@
 %NCDF_HOME           /home/acc/shared
 %HDF5_HOME           /home/acc/shared
-%XIOS_HOME           /home/acc/XIOS_1.0
+%XIOS_HOME           /home/acc/XIOS_1.0_r777
 %OASIS_HOME          
 
@@ -61,4 +61,4 @@
 %USER_LIB            %XIOS_LIB %OASIS_LIB %NCDF_LIB
 
-%CC                  cc
+%CC                  icc
 %CFLAGS              -O0
Index: /trunk/NEMOGCM/ARCH/arch-openmpi_NAVITI_MERCATOR.fcm
===================================================================
--- /trunk/NEMOGCM/ARCH/arch-openmpi_NAVITI_MERCATOR.fcm	(revision 6139)
+++ /trunk/NEMOGCM/ARCH/arch-openmpi_NAVITI_MERCATOR.fcm	(revision 6140)
@@ -23,5 +23,5 @@
 %CPP	             cpp
 %FC                  mpif90
-%FCFLAGS             -O1 -fp-model precise  -traceback -r8  -convert big_endian -assume byterecl
+%FCFLAGS             -O2 -fp-model precise  -traceback -r8  -convert big_endian -assume byterecl
 %FFLAGS              %FCFLAGS
 %LD                   mpif90
Index: /trunk/NEMOGCM/CONFIG/AMM12/EXP00/iodef.xml
===================================================================
--- /trunk/NEMOGCM/CONFIG/AMM12/EXP00/iodef.xml	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/AMM12/EXP00/iodef.xml	(revision 6140)
@@ -25,9 +25,66 @@
       <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
 
-      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+<!--old      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> old --> <!-- 1h files --> 
+   <!-- TMB files -->
+      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."  >                      
+
+   <file id="file9" name_suffix="_shelftmb_grid_T" description="ocean T grid variables" enabled=".TRUE." >
+     <field field_ref="top_temp"           name="votemper_top"   operation="instant" enabled=".TRUE." />
+     <field field_ref="mid_temp"           name="votemper_mid"   operation="instant" enabled=".TRUE." />
+     <field field_ref="bot_temp"           name="votemper_bot"   operation="instant" enabled=".TRUE." />
+     <field field_ref="sshnmasked"         name="sossheig"       operation="instant" enabled=".TRUE." /> 
+     <field field_ref="top_sal"            name="vosaline_top"   operation="instant" enabled=".TRUE." />
+     <field field_ref="mid_sal"            name="vosaline_mid"   operation="instant" enabled=".TRUE." />
+     <field field_ref="bot_sal"            name="vosaline_bot"   operation="instant" enabled=".TRUE." />
+   </file>
+
+   <file id="file10" name_suffix="_shelftmb_grid_U" description="TMB ocean U grid variables" enabled=".TRUE." >
+     <field field_ref="top_u"         name="vozocrtx_top"   operation="instant" />
+     <field field_ref="mid_u"         name="vozocrtx_mid"   operation="instant" />
+     <field field_ref="bot_u"         name="vozocrtx_bot"   operation="instant" />
+     <field field_ref="baro_u"        name="vobtcrtx"       operation="instant" />
+   </file>
+
+   <file id="file11" name_suffix="_shelftmb_grid_V" description="TMB ocean V grid variables" enabled=".TRUE." >
+     <field field_ref="top_v"         name="vomecrty_top"   operation="instant" />
+     <field field_ref="mid_v"         name="vomecrty_mid"   operation="instant" />
+     <field field_ref="bot_v"         name="vomecrty_bot"   operation="instant" />
+     <field field_ref="baro_v"        name="vobtcrty"       operation="instant" />
+   </file>
+
+      </file_group>
+
       <file_group id="2h" output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
       <file_group id="3h" output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
       <file_group id="4h" output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
       <file_group id="6h" output_freq="6h"  output_level="10" enabled=".TRUE."/> <!-- 6h files -->
+
+      <file_group id="25h_mean" output_freq="1d" output_level="10" enabled=".TRUE.">
+
+
+     <file id="file12" name_suffix="_25hourm_grid_T" description="ocean T grid variables, 25h meaned" enabled=".TRUE." >
+     <field field_ref="temper25h"   name="votemper"  operation="instant" enabled=".TRUE."/>
+     <field field_ref="tempis25h"   name="votempis"  operation="instant" enabled=".TRUE."/>
+     <field field_ref="salin25h"    name="vosaline"  operation="instant" enabled=".TRUE."/>
+     <field field_ref="ssh25h"      name="sossheig"  operation="instant" enabled=".TRUE."/>
+    </file>
+
+     <file id="file13" name_suffix="_25hourm_grid_U" description="ocean U grid variables, 25h meaned" enabled=".TRUE." >
+     <field field_ref="vozocrtx25h" name="vozocrtx"  operation="instant" enabled=".TRUE."/>
+    </file>
+
+     <file id="file14" name_suffix="_25hourm_grid_V" description="ocean V grid variables, 25h meaned" enabled=".TRUE." >
+     <field field_ref="vomecrty25h" name="vomecrty"  operation="instant" enabled=".TRUE."/>
+    </file>
+
+     <file id="file15" name_suffix="_25hourm_grid_W" description="ocean W grid variables, 25h meaned" enabled=".TRUE." >
+     <field field_ref="vomecrtz25h"          name="vomerctz"  operation="instant" enabled=".TRUE."/>
+     <field field_ref="woce"                 name="vovecrtz"  operation="instant" enabled=".TRUE."/>
+     <field field_ref="avt25h"               name="votkeavt"  operation="instant" enabled=".TRUE."/>
+     <field field_ref="avm25h"               name="votkeavm"  operation="instant" enabled=".TRUE."/>
+     <field field_ref="tke25h"               name="votke"  operation="instant" enabled=".TRUE."/>
+     <field field_ref="mxln25h"              name="mxln"   operation="instant" enabled=".TRUE."/>
+    </file>
+      </file_group>
      
       <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."> <!-- 1d files -->
@@ -98,4 +155,5 @@
       <file_group id="5y"  output_freq="5y" output_level="10" enabled=".TRUE."/> <!-- real 5y files -->
       <file_group id="10y" output_freq="10y" output_level="10" enabled=".TRUE."/> <!-- real 10y files -->
+
 
    </file_definition>
Index: /trunk/NEMOGCM/CONFIG/AMM12/EXP00/namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/AMM12/EXP00/namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/AMM12/EXP00/namelist_cfg	(revision 6140)
@@ -34,6 +34,5 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
-   ln_zps      = .false.   !  z-coordinate - partial steps   (T/F)
-   ln_sco      = .true.    !  s- or hybrid z-s-coordinate    (T/F)
+   ln_sco      = .true.    !  s- or hybrid z-s-coordinate
 /
 !-----------------------------------------------------------------------
@@ -50,7 +49,4 @@
 !-----------------------------------------------------------------------
    rn_rdt      =   600.    !  time step for the dynamics (and tracer if nn_acc=0)
-   rn_rdtmin   =   600.          !  minimum time step on tracers (used if nn_acc=1)
-   rn_rdtmax   =   600.          !  maximum time step on tracers (used if nn_acc=1)
-   rn_rdth     =   600.          !  depth variation of tracer time step  (used if nn_acc=1)
    ppglam0     =  999999.0             !  longitude of first raw and column T-point (jphgr_msh = 1)
    ppgphi0     =  999999.0             ! latitude  of first raw and column T-point (jphgr_msh = 1)
@@ -93,4 +89,5 @@
    nn_fwb      = 0         !  FreshWater Budget: =0 unchecked
    ln_apr_dyn  = .false.    !  Patm gradient added in ocean & ice Eqs.   (T => fill namsbc_apr )
+   ln_traqsr   = .false.   !  Light penetration (T) or not (F)
 
 /
@@ -130,5 +127,4 @@
 &namtra_qsr    !   penetrative solar radiation
 !-----------------------------------------------------------------------
-   ln_traqsr   = .false.   !  Light penetration (T) or not (F)
    nn_chldta   =      0    !  RGB : Chl data (=1) or cst value (=0)
 /
@@ -250,7 +246,6 @@
 /
 !-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition
-!-----------------------------------------------------------------------
-   ln_trabbc   = .false.   !  Apply a geothermal heating at the ocean bottom
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
@@ -339,7 +334,7 @@
 &namdyn_spg    !   surface pressure gradient 
 !-----------------------------------------------------------------------
-   ln_dynspg_ts   = .true.    ! split-explicit free surface
-      ln_bt_auto    = .false.   ! Number of sub-step defined from:
-         nn_baro      = 30        ! =F : the number of sub-step in rn_rdt seconds
+   ln_dynspg_ts = .true.    ! split-explicit free surface
+      ln_bt_auto    = .false.  ! Number of sub-step defined from:
+         nn_baro       = 30       ! =F : the number of sub-step in rn_rdt seconds
 /
 !-----------------------------------------------------------------------
@@ -449,5 +444,12 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
-/
+&nam_diatmb  !  Top Middle Bottom Output
+!-----------------------------------------------------------------------
+   ln_diatmb  = .true.    !  Choose Top Middle and Bottom output or not
+/
+!-----------------------------------------------------------------------
+&nam_dia25h  !  25h Mean Output
+!-----------------------------------------------------------------------
+   ln_dia25h  = .true.    ! Choose 25h mean output or not
+/
+
Index: /trunk/NEMOGCM/CONFIG/AMM12/cpp_AMM12.fcm
===================================================================
--- /trunk/NEMOGCM/CONFIG/AMM12/cpp_AMM12.fcm	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/AMM12/cpp_AMM12.fcm	(revision 6140)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys  key_bdy key_tide  key_zdfgls  key_vvl key_diainstant key_mpp_mpi key_iomput
+ bld::tool::fppkeys  key_bdy key_tide key_zdfgls key_diainstant key_mpp_mpi key_iomput
Index: /trunk/NEMOGCM/CONFIG/C1D_PAPA/EXP00/namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/C1D_PAPA/EXP00/namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/C1D_PAPA/EXP00/namelist_cfg	(revision 6140)
@@ -30,4 +30,5 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
+   ln_zps      = .true.    !  z-coordinate - partial steps
 /
 !-----------------------------------------------------------------------
@@ -41,7 +42,5 @@
    rn_bathy    = 4198.     !  value of the bathymetry. if (=0) bottom flat at jpkm1
    nn_msh      =    0      !  create (=1) a mesh file or not (=0)
-   rn_rdt      =  360.     !  time step for the dynamics (and tracer if nn_acc=0)
-   rn_rdtmin   =  360.     !  minimum time step on tracers (used if nn_acc=1)
-   rn_rdtmax   =  360.     !  maximum time step on tracers (used if nn_acc=1)
+   rn_rdt      =  360.     !  time step for the dynamics 
    jphgr_msh   =       1                 !  type of horizontal mesh
    ppglam0     =    -150.0               !  longitude of first raw and column T-point (jphgr_msh = 1)
@@ -196,8 +195,6 @@
 /
 !-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition
-!-----------------------------------------------------------------------
-   ln_trabbc   = .false.   !  Apply a geothermal heating at the ocean bottom
-   nn_geoflx   =    0      !  geothermal heat flux: = 0 no flux
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
@@ -260,5 +257,5 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_spg    !   surface pressure gradient
+&namdyn_spg    !   surface pressure gradient                            (default: NO spg)
 !-----------------------------------------------------------------------
 /
@@ -342,7 +339,2 @@
 !-----------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
-   ln_neptramp       = .false.  ! ramp down Neptune velocity in shallow water
-/
Index: /trunk/NEMOGCM/CONFIG/GYRE/EXP00/namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/GYRE/EXP00/namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/GYRE/EXP00/namelist_cfg	(revision 6140)
@@ -32,6 +32,6 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
-   ln_zco      = .true.    !  z-coordinate - full    steps   (T/F)      ("key_zco" may also be defined)
-   ln_zps      = .false.   !  z-coordinate - partial steps   (T/F)
+   ln_zco      = .true.    !  z-coordinate - full    steps
+   ln_linssh   = .true.    !  linear free surface
 /
 !-----------------------------------------------------------------------
@@ -43,7 +43,5 @@
 !-----------------------------------------------------------------------
    nn_bathy    =    0      !  compute (=0) or read (=1) the bathymetry file
-   rn_rdt      = 7200.     !  time step for the dynamics (and tracer if nn_acc=0)
-   rn_rdtmin   = 7200.           !  minimum time step on tracers (used if nn_acc=1)
-   rn_rdtmax   = 7200.           !  maximum time step on tracers (used if nn_acc=1)
+   rn_rdt      = 7200.     !  time step for the dynamics 
    jphgr_msh   =       5                 !  type of horizontal mesh
    ppglam0     =       0.0               !  longitude of first raw and column T-point (jphgr_msh = 1)
@@ -401,7 +399,2 @@
 !-----------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
-   ln_neptramp       = .false.  ! ramp down Neptune velocity in shallow water
-/
Index: /trunk/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg	(revision 6140)
@@ -35,6 +35,6 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
-   ln_zco      = .true.    !  z-coordinate - full    steps   (T/F)      ("key_zco" may also be defined)
-   ln_zps      = .false.   !  z-coordinate - partial steps   (T/F)
+   ln_zco      = .true.    !  z-coordinate - full    steps
+   ln_linssh   = .true.   !  linear free surface
 /
 !-----------------------------------------------------------------------
@@ -46,7 +46,5 @@
 !-----------------------------------------------------------------------
    nn_bathy    =    0      !  compute (=0) or read (=1) the bathymetry file
-   rn_rdt      = 7200.     !  time step for the dynamics (and tracer if nn_acc=0)
-   rn_rdtmin   = 7200.           !  minimum time step on tracers (used if nn_acc=1)
-   rn_rdtmax   = 7200.           !  maximum time step on tracers (used if nn_acc=1)
+   rn_rdt      = 7200.     !  time step for the dynamics 
    jphgr_msh   =       5                 !  type of horizontal mesh
    ppglam0     =       0.0               !  longitude of first raw and column T-point (jphgr_msh = 1)
@@ -182,8 +180,6 @@
 /
 !-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition
-!-----------------------------------------------------------------------
-   ln_trabbc   = .false.   !  Apply a geothermal heating at the ocean bottom
-   nn_geoflx   =    0      !  geothermal heat flux: = 0 no flux
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
@@ -390,7 +386,2 @@
 !-----------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
-   ln_neptramp       = .false.  ! ramp down Neptune velocity in shallow water
-/
Index: /trunk/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_cfg	(revision 6140)
@@ -29,6 +29,6 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
-   ln_zco      = .true.    !  z-coordinate - full    steps   (T/F)      ("key_zco" may also be defined)
-   ln_zps      = .false.   !  z-coordinate - partial steps   (T/F)
+   ln_zco      = .true.    !  z-coordinate - full    steps
+   ln_linssh   = .true.    !  linear free surface
 /
 !-----------------------------------------------------------------------
@@ -36,7 +36,5 @@
 !-----------------------------------------------------------------------
    nn_bathy    =    0      !  compute (=0) or read (=1) the bathymetry file
-   rn_rdt      = 7200.     !  time step for the dynamics (and tracer if nn_acc=0)
-   rn_rdtmin   = 7200.           !  minimum time step on tracers (used if nn_acc=1)
-   rn_rdtmax   = 7200.           !  maximum time step on tracers (used if nn_acc=1)
+   rn_rdt      = 7200.     !  time step for the dynamics 
    jphgr_msh   =       5                 !  type of horizontal mesh
    ppglam0     =       0.0               !  longitude of first raw and column T-point (jphgr_msh = 1)
@@ -105,8 +103,6 @@
 /
 !-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition
-!-----------------------------------------------------------------------
-   ln_trabbc   = .false.   !  Apply a geothermal heating at the ocean bottom
-   nn_geoflx   =    0      !  geothermal heat flux: = 0 no flux
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
@@ -260,7 +256,2 @@
 !-----------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
-   ln_neptramp       = .false.  ! ramp down Neptune velocity in shallow water
-/
Index: /trunk/NEMOGCM/CONFIG/GYRE_XIOS/EXP00/namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/GYRE_XIOS/EXP00/namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/GYRE_XIOS/EXP00/namelist_cfg	(revision 6140)
@@ -29,6 +29,6 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
-   ln_zco      = .true.    !  z-coordinate - full    steps   (T/F)      ("key_zco" may also be defined)
-   ln_zps      = .false.   !  z-coordinate - partial steps   (T/F)
+   ln_zco      = .true.    !  z-coordinate - full    steps
+   ln_linssh   = .true.    !  linear free surface
 /
 !-----------------------------------------------------------------------
@@ -40,7 +40,6 @@
 !-----------------------------------------------------------------------
    nn_bathy    =    0      !  compute (=0) or read (=1) the bathymetry file
-   rn_rdt      = 7200.     !  time step for the dynamics (and tracer if nn_acc=0)
-   rn_rdtmin   = 7200.           !  minimum time step on tracers (used if nn_acc=1)
-   rn_rdtmax   = 7200.           !  maximum time step on tracers (used if nn_acc=1)
+   rn_rdt      = 7200.     !  time step for the dynamics 
+!   nn_baro     =   60      !  number of barotropic time step            ("key_dynspg_ts")
    jphgr_msh   =       5                 !  type of horizontal mesh
    ppglam0     =       0.0               !  longitude of first raw and column T-point (jphgr_msh = 1)
@@ -174,8 +173,6 @@
 /
 !-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition
-!-----------------------------------------------------------------------
-   ln_trabbc   = .false.   !  Apply a geothermal heating at the ocean bottom
-   nn_geoflx   =    0      !  geothermal heat flux: = 0 no flux
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
@@ -348,7 +345,2 @@
 !-----------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
-   ln_neptramp       = .false.  ! ramp down Neptune velocity in shallow water
-/
Index: /trunk/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/1_namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/1_namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/1_namelist_cfg	(revision 6140)
@@ -29,4 +29,6 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
+   ln_zps      = .true.    !  z-coordinate - partial steps
+   ln_linssh   = .true.    !  linear free surface
 /
 !-----------------------------------------------------------------------
@@ -52,6 +54,4 @@
    ppacr2      =  999999.              !
    rn_rdt      = 2880.     !  time step for the dynamics (and tracer if nn_acc=0)
-   rn_rdtmin   = 14400.          !  minimum time step on tracers (used if nn_acc=1)
-   rn_rdtmax   = 14400.          !  maximum time step on tracers (used if nn_acc=1)
 /
 !-----------------------------------------------------------------------
@@ -121,6 +121,7 @@
 /
 !-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition
-!-----------------------------------------------------------------------
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
+   ln_trabbc   = .true.    !  Apply a geothermal heating at the ocean bottom
 /
 !-----------------------------------------------------------------------
@@ -200,7 +201,7 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_spg    !   surface pressure gradient
-!-----------------------------------------------------------------------
-   ln_dynspg_ts  = .true.  !  split-explicit free surface
+&namdyn_spg    !   Surface pressure gradient
+!-----------------------------------------------------------------------
+   ln_dynspg_ts = .true.   !  Split-explicit free surface
 /
 !-----------------------------------------------------------------------
@@ -266,8 +267,4 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &namobs       !  observation usage                                      ('key_diaobs')
 !-----------------------------------------------------------------------
Index: /trunk/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/namelist_cfg	(revision 6140)
@@ -6,4 +6,8 @@
 &namrun        !   parameters of the run
 !-----------------------------------------------------------------------
+   nn_no       =       0   !  job number (no more used...)
+   cn_exp      =  "ORCA2"  !  experience name
+   nn_it000    =       1   !  first time step
+   nn_itend    =     300   !  last  time step (std 5475)
 /
 !-----------------------------------------------------------------------
@@ -24,4 +28,6 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
+   ln_zps      = .true.    !  z-coordinate - partial steps
+   ln_linssh   = .true.    !  linear free surface
 /
 !-----------------------------------------------------------------------
@@ -93,6 +99,7 @@
 /
 !-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition
-!-----------------------------------------------------------------------
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
+   ln_trabbc   = .true.    !  Apply a geothermal heating at the ocean bottom
 /
 !-----------------------------------------------------------------------
@@ -177,5 +184,5 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .true.  !  energy & enstrophy scheme
-      nn_een_e3f = 1             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
+      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
@@ -184,7 +191,7 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_spg    !   surface pressure gradient
-!-----------------------------------------------------------------------
-   ln_dynspg_ts  = .true.  !  split-explicit free surface
+&namdyn_spg    !   Surface pressure gradient
+!-----------------------------------------------------------------------
+   ln_dynspg_ts = .true.   !  Split-explicit free surface
 /
 !-----------------------------------------------------------------------
@@ -245,9 +252,5 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namobs       !  observation usage                                      ('key_diaobs')
+&namobs       !  observation usage
 !-----------------------------------------------------------------------
 /
Index: /trunk/NEMOGCM/CONFIG/ORCA2_LIM/cpp_ORCA2_LIM.fcm
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_LIM/cpp_ORCA2_LIM.fcm	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_LIM/cpp_ORCA2_LIM.fcm	(revision 6140)
@@ -1,1 +1,1 @@
-bld::tool::fppkeys key_trabbl key_lim2 key_zdftke key_zdfddm key_zdftmx  key_mpp_mpi key_iomput
+bld::tool::fppkeys key_trabbl key_lim2 key_zdftke key_zdfddm key_zdftmx  key_mpp_mpi key_iomput key_nosignedzero
Index: /trunk/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/1_namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/1_namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/1_namelist_cfg	(revision 6140)
@@ -28,4 +28,5 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
+   ln_zps      = .true.    !  z-coordinate - partial steps
 /
 !-----------------------------------------------------------------------
@@ -51,6 +52,4 @@
    ppacr2      =  999999.              !
    rn_rdt      = 2880.     !  time step for the dynamics (and tracer if nn_acc=0)
-   rn_rdtmin   = 14400.          !  minimum time step on tracers (used if nn_acc=1)
-   rn_rdtmax   = 14400.          !  maximum time step on tracers (used if nn_acc=1)
 /
 !-----------------------------------------------------------------------
@@ -122,4 +121,5 @@
 &nambbc        !   bottom temperature boundary condition
 !-----------------------------------------------------------------------
+   ln_trabbc   = .true.    !  Apply a geothermal heating at the ocean bottom
 /
 !-----------------------------------------------------------------------
@@ -266,8 +266,4 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &namobs       !  observation usage                                      ('key_diaobs')
 !-----------------------------------------------------------------------
Index: /trunk/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/namelist_cfg	(revision 6140)
@@ -6,4 +6,8 @@
 &namrun        !   parameters of the run
 !-----------------------------------------------------------------------
+   nn_no       =       0   !  job number (no more used...)
+   cn_exp      =  "ORCA2"  !  experience name
+   nn_it000    =       1   !  first time step
+   nn_itend    =     300   !  last  time step (std 5475)
 /
 !-----------------------------------------------------------------------
@@ -24,4 +28,5 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
+   ln_zps      = .true.    !  z-coordinate - partial steps
 /
 !-----------------------------------------------------------------------
@@ -93,6 +98,7 @@
 /
 !-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition
-!-----------------------------------------------------------------------
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
+   ln_trabbc   = .true.    !  Apply a geothermal heating at the ocean bottom
 /
 !-----------------------------------------------------------------------
@@ -161,5 +167,6 @@
    !                                !   = 21 F(i,j,t)  =Treguier et al. JPO 1997 formulation
    !                                !   = 30 F(i,j,k)  =ldf_c2d + ldf_c1d
-/!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
 &namtra_dmp    !   tracer: T & S newtonian damping
 !-----------------------------------------------------------------------
@@ -181,9 +188,6 @@
 &namdyn_hpg    !   Hydrostatic pressure gradient option
 !-----------------------------------------------------------------------
-   ln_hpg_zco  = .false.   !  z-coordinate - full steps
+   ln_hpg_sco  = .true.    !  s-coordinate (standard jacobian formulation)
    ln_hpg_zps  = .false.   !  z-coordinate - partial steps (interpolation)
-   ln_hpg_sco  = .false.   !  s-coordinate (standard jacobian formulation)
-   ln_hpg_djc  = .false.   !  s-coordinate (Density Jacobian with Cubic polynomial)
-   ln_hpg_prj  = .true.    !  s-coordinate (Pressure Jacobian scheme)
 /
 !-----------------------------------------------------------------------
@@ -247,10 +251,7 @@
 /
 !-----------------------------------------------------------------------
-&namhsb       !  Heat and salt budgets
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
+&namhsb       !  Heat and salt budgets                                  (default F)
+!-----------------------------------------------------------------------
+   ln_diahsb  = .true.    !  check the heat and salt budgets (T) or not (F)
 /
 !-----------------------------------------------------------------------
Index: /trunk/NEMOGCM/CONFIG/ORCA2_LIM3/cpp_ORCA2_LIM3.fcm
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_LIM3/cpp_ORCA2_LIM3.fcm	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_LIM3/cpp_ORCA2_LIM3.fcm	(revision 6140)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys key_trabbl key_lim3 key_vvl key_zdftke key_zdfddm key_zdftmx  key_mpp_mpi key_diaobs key_asminc key_iomput key_nosignedzero
+bld::tool::fppkeys key_trabbl key_lim3 key_zdftke key_zdfddm key_zdftmx key_iomput key_mpp_mpi key_asminc key_nosignedzero
Index: /trunk/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/1_namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/1_namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/1_namelist_cfg	(revision 6140)
@@ -11,5 +11,5 @@
 !!              8 - Verical physics  (namzdf, namzdf_ric, namzdf_tke, namzdf_kpp, namzdf_ddm, namzdf_tmx)
 !!              9 - diagnostics      (namnc4, namtrd, namspr, namflo, namptr, namhsb)
-!!             10 - miscellaneous    (nammpp, nammpp_dyndist, namctl)
+!!             10 - miscellaneous    (namsol, nammpp, nammpp_dyndist, namctl)
 !!             11 - Obs & Assim      (namobs, nam_asminc)
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -59,7 +59,6 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
-   ln_zco      = .false.   !  z-coordinate - full    steps   (T/F)      ("key_zco" may also be defined)
    ln_zps      = .true.    !  z-coordinate - partial steps   (T/F)
-   ln_sco      = .false.   !  s- or hybrid z-s-coordinate    (T/F)
+   ln_linssh   = .true.    !  linear free surface
 /
 !-----------------------------------------------------------------------
@@ -87,9 +86,4 @@
    rn_rdt      = 2880.     !  time step for the dynamics (and tracer if nn_acc=0)
    rn_atfp     =    0.1    !  asselin time filter parameter
-   nn_acc      =    0      !  acceleration of convergence : =1      used, rdt < rdttra(k)
-                                 !                          =0, not used, rdt = rdttra
-   rn_rdtmin   = 14400.          !  minimum time step on tracers (used if nn_acc=1)
-   rn_rdtmax   = 14400.          !  maximum time step on tracers (used if nn_acc=1)
-   rn_rdth     =  800.           !  depth variation of tracer time step  (used if nn_acc=1)
 /
 !-----------------------------------------------------------------------
@@ -295,4 +289,13 @@
    rn_alphc    =    0.65   !  compute albedo between two extremes values 
    rn_alphdi   =    0.72   !  (Pyane, 1972)
+/
+!-----------------------------------------------------------------------
+&namsbc_wave   ! External fields from wave model
+!-----------------------------------------------------------------------
+!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation !
+!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  !
+   sn_cdg      =  'cdg_wave' ,        1          , 'drag_coeff' , .true.   , .false. , 'daily'  ,''         , ''
+!
+   cn_dir_cdg  = './'  !  root directory for the location of drag coefficient files
 /
 
@@ -860,5 +863,4 @@
    ln_ignmis  = .true.     ! Logical switch for ignoring missing files   
                            !     endailyavtypes   ENACT daily average types                    
-   ln_grid_global = .true.
    ln_grid_search_lookup = .false.
 / 
@@ -880,26 +882,2 @@
     salfixmin = -9999      !  Minimum salinity after applying the increments
 /
-!-----------------------------------------------------------------------
-&namsbc_wave   ! External fields from wave model
-!-----------------------------------------------------------------------
-!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation !
-!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  !
-   sn_cdg      =  'cdg_wave' ,        1          , 'drag_coeff' , .true.   , .false. , 'daily'  ,''         , ''
-!
-   cn_dir_cdg  = './'  !  root directory for the location of drag coefficient files
-/
-!-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
-   ! Suggested lengthscale values are those of Eby & Holloway (1994) for a coarse model
-   ln_neptsimp       = .false.  ! yes/no use simplified neptune
-
-   ln_smooth_neptvel = .false.  ! yes/no smooth zunep, zvnep
-   rn_tslse          =  1.2e4   ! value of lengthscale L at the equator
-   rn_tslsp          =  3.0e3   ! value of lengthscale L at the pole
-   ! Specify whether to ramp down the Neptune velocity in shallow
-   ! water, and if so the depth range controlling such ramping down
-   ln_neptramp       = .true.   ! ramp down Neptune velocity in shallow water
-   rn_htrmin         =  100.0   ! min. depth of transition range
-   rn_htrmax         =  200.0   ! max. depth of transition range
-/
Index: /trunk/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/namelist_cfg	(revision 6140)
@@ -31,4 +31,6 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
+   ln_zps      = .true.    !  z-coordinate - partial steps
+   ln_linssh   = .true.    !  linear free surface
 /
 !-----------------------------------------------------------------------
@@ -67,4 +69,8 @@
 /
 !-----------------------------------------------------------------------
+&namsplit      !   time splitting parameters                            ("key_dynspg_ts")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
 &namcrs        !   Grid coarsening for dynamics output and/or
                !   passive tracer coarsened online simulations
@@ -152,6 +158,7 @@
 /
 !-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition
+&nambbc        !   bottom temperature boundary condition                (default: NO)
 !----------------------------------------------------------------------- 
+   ln_trabbc   = .true.    !  Apply a geothermal heating at the ocean bottom
 /
 !-----------------------------------------------------------------------
@@ -244,8 +251,6 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_spg    !   surface pressure gradient
-!-----------------------------------------------------------------------
-   ln_dynspg_ts  = .true.  !  split-explicit free surface
-/
+!namdyn_spg    !   surface pressure gradient   (CPP key only)
+!-----------------------------------------------------------------------
 !-----------------------------------------------------------------------
 &namdyn_ldf    !   lateral diffusion on momentum
@@ -297,4 +302,8 @@
 /
 !-----------------------------------------------------------------------
+&namsol        !   elliptic solver / island / free surface 
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
 &nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi)
 !-----------------------------------------------------------------------
@@ -345,6 +354,2 @@
 !-----------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
-/
Index: /trunk/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/namelist_cfg	(revision 6140)
@@ -24,4 +24,6 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
+   ln_zps      = .true.    !  z-coordinate - partial steps
+   ln_linssh   = .true.    !  linear free surface
 /
 !-----------------------------------------------------------------------
@@ -93,6 +95,7 @@
 /
 !-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition
-!-----------------------------------------------------------------------
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
+   ln_trabbc   = .true.    !  Apply a geothermal heating at the ocean bottom
 /
 !-----------------------------------------------------------------------
@@ -244,6 +247,2 @@
 !-----------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
-/
Index: /trunk/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/namelist_top_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/namelist_top_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/namelist_top_cfg	(revision 6140)
@@ -62,6 +62,6 @@
 &namtrc_adv    !   advection scheme for passive tracer 
 !-----------------------------------------------------------------------
-   ln_trcadv_mus  =  .true.  !  MUSCL scheme
-      ln_mus_ups  =  .false.         !  use upstream scheme near river mouths
+   ln_trcadv_mus =  .true.  !  MUSCL scheme
+      ln_mus_ups =  .false.         !  use upstream scheme near river mouths
 /
 !-----------------------------------------------------------------------
Index: /trunk/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist_cfg	(revision 6140)
@@ -27,4 +27,6 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
+   ln_zps      = .true.    !  z-coordinate - partial steps
+   ln_linssh   = .true.    !  linear free surface
 /
 !-----------------------------------------------------------------------
@@ -32,7 +34,5 @@
 !-----------------------------------------------------------------------
    nn_msh      =    1      !  create (=1) a mesh file or not (=0)
-   rn_rdt      = 21600.    !  time step for the dynamics (and tracer if nn_acc=0)
-   rn_rdtmin   = 21600.          !  minimum time step on tracers (used if nn_acc=1)
-   rn_rdtmax   = 21600.          !  maximum time step on tracers (used if nn_acc=1)
+   rn_rdt      = 21600.    !  time step for the dynamics 
    jphgr_msh   =       0               !  type of horizontal mesh
    ppglam0     =  999999.0             !  longitude of first raw and column T-point (jphgr_msh = 1)
@@ -55,4 +55,8 @@
 /
 !-----------------------------------------------------------------------
+&namsplit      !   time splitting parameters                            ("key_dynspg_ts")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
 &namcrs        !   Grid coarsening for dynamics output and/or
                !   passive tracer coarsened online simulations
@@ -64,9 +68,9 @@
    nn_fsbc     = 1         !  frequency of surface boundary condition computation 
    ln_rnf      = .false.   !  runoffs
+   ln_traqsr   = .false.   !  Light penetration (T) or not (F)
 /  
 !-----------------------------------------------------------------------
 &namtra_qsr    !   penetrative solar radiation
 !-----------------------------------------------------------------------
-   ln_traqsr   = .false.   !  Light penetration (T) or not (F)
 /
 !-----------------------------------------------------------------------
Index: /trunk/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist_top_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist_top_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist_top_cfg	(revision 6140)
@@ -65,5 +65,5 @@
 &namtrc_adv    !   advection scheme for passive tracer 
 !-----------------------------------------------------------------------
-   ln_trcadv_mus =  .true.   !  MUSCL scheme
+   ln_trcadv_mus =  .true.  !  MUSCL scheme
       ln_mus_ups =  .false.         !  use upstream scheme near river mouths
 /
Index: /trunk/NEMOGCM/CONFIG/ORCA2_SAS_LIM/EXP00/namelist_cfg
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_SAS_LIM/EXP00/namelist_cfg	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_SAS_LIM/EXP00/namelist_cfg	(revision 6140)
@@ -26,4 +26,6 @@
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
+   ln_zco      = .true.    !  z-coordinate - full    steps
+   ln_linssh   = .true.    !  linear free surface
 /
 !-----------------------------------------------------------------------
Index: /trunk/NEMOGCM/CONFIG/ORCA2_SAS_LIM/cpp_ORCA2_SAS_LIM.fcm
===================================================================
--- /trunk/NEMOGCM/CONFIG/ORCA2_SAS_LIM/cpp_ORCA2_SAS_LIM.fcm	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/ORCA2_SAS_LIM/cpp_ORCA2_SAS_LIM.fcm	(revision 6140)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys key_trabbl key_lim2 key_zdftke key_zdfddm key_zdftmx key_iomput key_mpp_mpi
+ bld::tool::fppkeys key_trabbl key_lim2  key_zdftke key_zdfddm key_zdftmx key_iomput key_mpp_mpi
Index: /trunk/NEMOGCM/CONFIG/SHARED/field_def.xml
===================================================================
--- /trunk/NEMOGCM/CONFIG/SHARED/field_def.xml	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/SHARED/field_def.xml	(revision 6140)
@@ -40,5 +40,8 @@
          <field id="sstgrad2"     long_name="square of module of sst gradient"                                                        unit="degC2/m2" />
          <field id="sbt"          long_name="sea bottom temperature"                                                                  unit="degC"     />
-	 
+         <field id="sst_wl"       long_name="Delta SST of warm layer"                                                                 unit="degC"     />
+         <field id="sst_cs"       long_name="Delta SST of cool skin"                                                                  unit="degC"     />
+	 <field id="temp_3m"      long_name="temperature at 3m"                                                                       unit="degC"     />
+         
          <field id="sss"          long_name="sea surface salinity"             standard_name="sea_surface_salinity"   unit="1e-3" />
          <field id="sss2"         long_name="square of sea surface salinity"                                          unit="1e-6"  > sss * sss </field >
@@ -197,10 +200,16 @@
 
          <!-- * variable related to ice shelf forcing * -->
-         <field id="fwfisf"       long_name="Ice shelf melting"                             unit="kg/m2/s"  />
-         <field id="qisf"         long_name="Ice Shelf Heat Flux"                           unit="W/m2"     />
-         <field id="isfgammat"    long_name="transfert coefficient for isf (temperature)"   unit="m/s"      />
-         <field id="isfgammas"    long_name="transfert coefficient for isf (salinity)"      unit="m/s"      />
-         <field id="stbl"         long_name="salinity in the Losh tbl"                      unit="1e-3"     />
-         <field id="ttbl"         long_name="temperature in the Losh tbl"                   unit="degC"     />
+         <field id="fwfisf"       long_name="Ice shelf melting"                                            unit="Kg/m2/s"  />
+         <field id="qisf"         long_name="Ice Shelf Heat Flux"                                          unit="W/m2"     />
+         <field id="isfgammat"    long_name="transfert coefficient for isf (temperature) "                 unit="m/s"      />
+         <field id="isfgammas"    long_name="transfert coefficient for isf (salinity)    "                 unit="m/s"      />
+ 	 <field id="stbl"         long_name="salinity in the Losh tbl                    "                 unit="PSU"      />
+	 <field id="ttbl"         long_name="temperature in the Losh tbl                 "                 unit="C"        />
+	 <field id="utbl"         long_name="zonal current in the Losh tbl at T point    "                 unit="m/s"      />
+	 <field id="vtbl"         long_name="merid current in the Losh tbl at T point    "                 unit="m/s"      />
+	 <field id="thermald"     long_name="thermal driving of ice shelf melting        "                 unit="C"        />
+	 <field id="tfrz"         long_name="top freezing point (used to compute melt)   "                 unit="C"        />
+	 <field id="tinsitu"      long_name="top insitu temperature (used to cmpt melt)  "                 unit="C"        />
+	 <field id="ustar"        long_name="ustar at T point used in ice shelf melting  "                 unit="m/s"      />
 
          <!-- *_oce variables available with ln_blk_clio or ln_blk_core -->
@@ -672,4 +681,7 @@
       <field id="ketrd_hpg"     long_name="ke-trend: hydrostatic pressure gradient"          unit="W/s^3"                        />
       <field id="ketrd_spg"     long_name="ke-trend: surface     pressure gradient"          unit="W/s^3"                        />
+      <field id="ketrd_spgexp"  long_name="ke-trend: surface pressure gradient (explicit)"   unit="W/s^3"                        />
+      <field id="ketrd_spgflt"  long_name="ke-trend: surface pressure gradient (filter)"     unit="W/s^3"                        />
+      <field id="ssh_flt"       long_name="filtered contribution to ssh (dynspg_flt)"        unit="m"       grid_ref="grid_T_2D" />
       <field id="w0"            long_name="surface vertical velocity"                        unit="m/s"     grid_ref="grid_T_2D" />
       <field id="pw0_exp"       long_name="surface pressure flux due to ssh"                 unit="W/s^2"   grid_ref="grid_T_2D" />
@@ -713,4 +725,6 @@
      <field id="utrd_hpg"       long_name="i-trend: hydrostatic pressure gradient"          unit="m/s^2"                        />
      <field id="utrd_spg"       long_name="i-trend: surface     pressure gradient"          unit="m/s^2"                        />
+     <field id="utrd_spgexp"    long_name="i-trend: surface pressure gradient (explicit)"   unit="m/s^2"                        />
+     <field id="utrd_spgflt"    long_name="i-trend: surface pressure gradient (filtered)"   unit="m/s^2"                        />
      <field id="utrd_keg"       long_name="i-trend: KE gradient         or hor. adv."       unit="m/s^2"                        />
      <field id="utrd_rvo"       long_name="i-trend: relative  vorticity or metric term"     unit="m/s^2"                        />
@@ -731,4 +745,6 @@
      <field id="vtrd_hpg"       long_name="j-trend: hydrostatic pressure gradient"          unit="m/s^2"                        />
      <field id="vtrd_spg"       long_name="j-trend: surface     pressure gradient"          unit="m/s^2"                        />
+     <field id="vtrd_spgexp"    long_name="j-trend: surface pressure gradient (explicit)"   unit="m/s^2"                        />
+     <field id="vtrd_spgflt"    long_name="j-trend: surface pressure gradient (filtered)"   unit="m/s^2"                        />
      <field id="vtrd_keg"       long_name="j-trend: KE gradient         or hor. adv."       unit="m/s^2"                        />
      <field id="vtrd_rvo"       long_name="j-trend: relative  vorticity or metric term"     unit="m/s^2"                        />
@@ -1032,5 +1048,52 @@
       <field field_ref="woce"         name="wo"       long_name="ocean vertical velocity"  />
     </field_group>
-    
+
+       <!-- TMB diagnostic output -->
+    <field_group  id="1h_grid_T_tmb" grid_ref="grid_T_2D" operation="instant">
+     <field id="top_temp"           name="votemper_top"  unit="degC"  />
+     <field id="mid_temp"           name="votemper_mid"  unit="degC"  />
+     <field id="bot_temp"           name="votemper_bot"  unit="degC"  />
+     <field id="top_sal"            name="vosaline_top"  unit="psu"   />
+     <field id="mid_sal"            name="vosaline_mid"  unit="psu"   />
+     <field id="bot_sal"            name="vosaline_bot"  unit="psu"   />
+     <field id="sshnmasked"         name="sossheig"      unit="m"     /> 
+   </field_group>
+    <field_group  id="1h_grid_U_tmb" grid_ref="grid_U_2D" operation="instant">
+     <field id="top_u"           name="vozocrtx_top"  unit="m/s"  />
+     <field id="mid_u"           name="vozocrtx_mid"  unit="m/s"  />
+     <field id="bot_u"           name="vozocrtx_bot"  unit="m/s"  />
+     <field id="baro_u"          name="vobtcrtx"      unit="m/s"  />
+   </field_group>
+    <field_group  id="1h_grid_V_tmb" grid_ref="grid_V_2D" operation="instant">
+     <field id="top_v"           name="vomecrty_top"  unit="m/s"  />
+     <field id="mid_v"           name="vomecrty_mid"  unit="m/s"  />
+     <field id="bot_v"           name="vomecrty_bot"  unit="m/s"  />
+     <field id="baro_v"          name="vobtcrty"      unit="m/s"  />
+   </field_group>
+       <!-- 25h diagnostic output -->
+      <field_group id="25h_grid_T" grid_ref="grid_T_3D" operation="instant">
+   <field id="temper25h"         name="potential temperature 25h mean"    unit="degC" />
+   <field id="tempis25h"         name="insitu temperature 25h mean"    unit="degC" />
+   <field id="salin25h"          name="salinity 25h mean"                 unit="psu"  />
+   <field id="ssh25h"            name="sea surface height 25h mean"  grid_ref="grid_T_2D"      unit="m"    />
+      </field_group>
+
+      <field_group id="25h_grid_U" grid_ref="grid_U_3D" operation="instant" >
+   <field id="vozocrtx25h"         name="i current 25h mean"    unit="m/s"   />
+      </field_group>
+
+      <field_group id="25h_grid_V" grid_ref="grid_V_3D" operation="instant">
+   <field id="vomecrty25h"         name="j current 25h mean"    unit="m/s"    />
+      </field_group>
+
+      <field_group id="25h_grid_W" grid_ref="grid_W_3D" operation="instant">
+   <field id="vomecrtz25h"         name="k current 25h mean"                 unit="m/s"      />
+   <field id="avt25h"             name="vertical diffusivity25h mean"       unit="m2/s" />
+   <field id="avm25h"              name="vertical viscosity 25h mean"        unit="m2/s" />
+   <field id="tke25h"              name="turbulent kinetic energy 25h mean" />
+   <field id="mxln25h"             name="mixing length 25h mean"             unit="m" />
+      </field_group>
+
+
 
    </field_definition>
Index: /trunk/NEMOGCM/CONFIG/SHARED/namelist_ref
===================================================================
--- /trunk/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 6140)
@@ -6,5 +6,5 @@
 !!              3 - Surface boundary (namsbc, namsbc_ana, namsbc_flx, namsbc_clio, namsbc_core, namsbc_sas
 !!                                    namsbc_cpl, namtra_qsr, namsbc_rnf,
-!!                                    namsbc_apr, namsbc_ssr, namsbc_alb)
+!!                                    namsbc_apr, namsbc_ssr, namsbc_alb, namsbc_wave)
 !!              4 - lateral boundary (namlbc, namagrif, nambdy, nambdy_tide)
 !!              5 - bottom  boundary (nambfr, nambbc, nambbl)
@@ -31,15 +31,17 @@
    nn_itend    =    5475   !  last  time step (std 5475)
    nn_date0    =  010101   !  date at nit_0000 (format yyyymmdd) used if ln_rstart=F or (ln_rstart=T and nn_rstctl=0 or 1)
+   nn_time0    =       0   !  initial time of day in hhmm
    nn_leapy    =       0   !  Leap year calendar (1) or not (0)
    ln_rstart   = .false.   !  start from rest (F) or from a restart file (T)
-   nn_euler    =       1   !  = 0 : start with forward time step if ln_rstart=T
-   nn_rstctl   =       0   !  restart control ==> activated only if ln_rstart=T
-                           !    = 0 nn_date0 read in namelist ; nn_it000 : read in namelist
-                           !    = 1 nn_date0 read in namelist ; nn_it000 : check consistancy between namelist and restart
-                           !    = 2 nn_date0 read in restart  ; nn_it000 : check consistancy between namelist and restart
-   cn_ocerst_in  = "restart"   !  suffix of ocean restart name (input)
-   cn_ocerst_indir = "."       !  directory from which to read input ocean restarts
-   cn_ocerst_out = "restart"   !  suffix of ocean restart name (output)
-   cn_ocerst_outdir = "."      !  directory in which to write output ocean restarts
+      nn_euler    =    1            !  = 0 : start with forward time step if ln_rstart=T
+      nn_rstctl   =    0            !  restart control ==> activated only if ln_rstart=T
+      !                             !    = 0 nn_date0 read in namelist ; nn_it000 : read in namelist
+      !                             !    = 1 nn_date0 read in namelist ; nn_it000 : check consistancy between namelist and restart
+      !                             !    = 2 nn_date0 read in restart  ; nn_it000 : check consistancy between namelist and restart
+      cn_ocerst_in    = "restart"   !  suffix of ocean restart name (input)
+      cn_ocerst_indir = "."         !  directory from which to read input ocean restarts
+      cn_ocerst_out   = "restart"   !  suffix of ocean restart name (output)
+      cn_ocerst_outdir= "."         !  directory in which to write output ocean restarts
+   ln_iscpl    = .false.   !  cavity evolution forcing or coupling to ice sheet model
    nn_istate   =       0   !  output the initial state (1) or not (0)
    ln_rst_list = .false.   !  output restarts at list of times using nn_stocklist (T) or at set frequency with nn_stock (F)
@@ -47,8 +49,7 @@
    nn_stocklist = 0,0,0,0,0,0,0,0,0,0 ! List of timesteps when a restart file is to be written
    nn_write    =    5475   !  frequency of write in the output file   (modulo referenced to nn_it000)
-   ln_dimgnnn  = .false.   !  DIMG file format: 1 file for all processors (F) or by processor (T)
    ln_mskland  = .false.   !  mask land points in NetCDF outputs (costly: + ~15%)
    ln_cfmeta   = .false.   !  output additional data to netCDF files required for compliance with the CF metadata standard
-   ln_clobber  = .true.   !  clobber (overwrite) an existing file
+   ln_clobber  = .true.    !  clobber (overwrite) an existing file
    nn_chunksz  =       0   !  chunksize (bytes) for NetCDF file (works only with iom_nf90 routines)
 /
@@ -61,41 +62,46 @@
 !!   namzgr_sco   s-coordinate or hybrid z-s-coordinate
 !!   namdom       space and time domain (bathymetry, mesh, timestep)
+!!   namcrs       coarsened grid (for outputs and/or TOP)               ("key_crs")
+!!   namc1d       1D configuration options                              ("key_c1d")
+!!   namc1d_uvd   1D data (currents)                                    ("key_c1d")
+!!   namc1d_dyndmp 1D newtonian damping applied on currents             ("key_c1d")
 !!   namtsd       data: temperature & salinity
 !!======================================================================
 !
 !-----------------------------------------------------------------------
-&namcfg     !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =  "default"            !  name of the configuration
-   cp_cfz      =  "no zoom"            !  name of the zoom of configuration
-   jp_cfg      =       0               !  resolution of the configuration
-   jpidta      =      10               !  1st lateral dimension ( >= jpi )
-   jpjdta      =      12               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      31               !  number of levels      ( >= jpk )
-   jpiglo      =      10               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =      12               !  2nd    -                  -    --> j =jpjdta
-   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
-   jpjzoom     =       1               !  in data domain indices
-   jperio      =       0               !  lateral cond. type (between 0 and 6)
-                                       !  = 0 closed                 ;   = 1 cyclic East-West
-                                       !  = 2 equatorial symmetric   ;   = 3 North fold T-point pivot
-                                       !  = 4 cyclic East-West AND North fold T-point pivot
-                                       !  = 5 North fold F-point pivot
-                                       !  = 6 cyclic East-West AND North fold F-point pivot
-   ln_use_jattr = .false.              !  use (T) the file attribute: open_ocean_jstart, if present
-                                       !  in netcdf input files, as the start j-row for reading
-/
-!-----------------------------------------------------------------------
-&namzgr        !   vertical coordinate
-!-----------------------------------------------------------------------
-   ln_zco      = .false.   !  z-coordinate - full    steps   (T/F)      ("key_zco" may also be defined)
-   ln_zps      = .true.    !  z-coordinate - partial steps   (T/F)
-   ln_sco      = .false.   !  s- or hybrid z-s-coordinate    (T/F)
-   ln_isfcav   = .false.   !  ice shelf cavity               (T/F)
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      = "default" !  name of the configuration
+   cp_cfz      = "no zoom" !  name of the zoom of configuration
+   jp_cfg      =      0    !  resolution of the configuration
+   jpidta      =     10    !  1st lateral dimension ( >= jpi )
+   jpjdta      =     12    !  2nd    "         "    ( >= jpj )
+   jpkdta      =     31    !  number of levels      ( >= jpk )
+   jpiglo      =     10    !  1st dimension of global domain --> i =jpidta
+   jpjglo      =     12    !  2nd    -                  -    --> j =jpjdta
+   jpizoom     =      1    !  left bottom (i,j) indices of the zoom
+   jpjzoom     =      1    !  in data domain indices
+   jperio      =      0    !  lateral cond. type (between 0 and 6)
+                                 !  = 0 closed                 ;   = 1 cyclic East-West
+                                 !  = 2 equatorial symmetric   ;   = 3 North fold T-point pivot
+                                 !  = 4 cyclic East-West AND North fold T-point pivot
+                                 !  = 5 North fold F-point pivot
+                                 !  = 6 cyclic East-West AND North fold F-point pivot
+   ln_use_jattr = .false.  !  use (T) the file attribute: open_ocean_jstart, if present
+                           !  in netcdf input files, as the start j-row for reading
+/
+!-----------------------------------------------------------------------
+&namzgr        !   vertical coordinate                                  (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_zco      = .false.   !  z-coordinate - full    steps
+   ln_zps      = .false.   !  z-coordinate - partial steps
+   ln_sco      = .false.   !  s- or hybrid z-s-coordinate
+   ln_isfcav   = .false.   !  ice shelf cavity
+   ln_linssh   = .false.   !  linear free surface
 /
 !-----------------------------------------------------------------------
 &namzgr_sco    !   s-coordinate or hybrid z-s-coordinate
 !-----------------------------------------------------------------------
-   ln_s_sh94   = .true.    !  Song & Haidvogel 1994 hybrid S-sigma   (T)|
+   ln_s_sh94   = .false.    !  Song & Haidvogel 1994 hybrid S-sigma   (T)|
    ln_s_sf12   = .false.   !  Siddorn & Furner 2012 hybrid S-z-sigma (T)| if both are false the NEMO tanh stretching is applied
    ln_sigcrit  = .false.   !  use sigma coordinates below critical depth (T) or Z coordinates (F) for Siddorn & Furner stretch
@@ -127,4 +133,5 @@
    nn_msh      =    1      !  create (=1) a mesh file or not (=0)
    rn_hmin     =   -3.     !  min depth of the ocean (>0) or min number of ocean level (<0)
+   rn_isfhmin  =    1.00   !  treshold (m) to discriminate grounding ice to floating ice
    rn_e3zps_min=   20.     !  partial step thickness is set larger than the minimum of
    rn_e3zps_rat=    0.1    !  rn_e3zps_min and rn_e3zps_rat*e3t, with 0<rn_e3zps_rat<1
@@ -132,9 +139,4 @@
    rn_rdt      = 5760.     !  time step for the dynamics (and tracer if nn_acc=0)
    rn_atfp     =    0.1    !  asselin time filter parameter
-   nn_acc      =    0      !  acceleration of convergence : =1      used, rdt < rdttra(k)
-                                 !                          =0, not used, rdt = rdttra
-   rn_rdtmin   = 28800.          !  minimum time step on tracers (used if nn_acc=1)
-   rn_rdtmax   = 28800.          !  maximum time step on tracers (used if nn_acc=1)
-   rn_rdth     =  800.           !  depth variation of tracer time step  (used if nn_acc=1)
    ln_crs      = .false.      !  Logical switch for coarsening module
    jphgr_msh   =       0               !  type of horizontal mesh
@@ -163,6 +165,5 @@
 /
 !-----------------------------------------------------------------------
-&namcrs        !   Grid coarsening for dynamics output and/or
-               !   passive tracer coarsened online simulations
+&namcrs        !   coarsened grid (for outputs and/or TOP)              ("key_crs")
 !-----------------------------------------------------------------------
    nn_factx    = 3         !  Reduction factor of x-direction
@@ -186,4 +187,21 @@
 /
 !-----------------------------------------------------------------------
+&namc1d_dyndmp !   U & V newtonian damping                              ("key_c1d")
+!-----------------------------------------------------------------------
+   ln_dyndmp   =  .false.  !  add a damping term (T) or not (F)
+/
+!-----------------------------------------------------------------------
+&namc1d_uvd    !   data: U & V currents                                 ("key_c1d")
+!-----------------------------------------------------------------------
+!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_ucur     = 'ucurrent'  ,         -1        ,'u_current',   .false.    , .true. , 'monthly' ,  ''      ,  'Ume'   , ''
+   sn_vcur     = 'vcurrent'  ,         -1        ,'v_current',   .false.    , .true. , 'monthly' ,  ''      ,  'Vme'   , ''
+!
+   cn_dir        = './'    !  root directory for the location of the files
+   ln_uvd_init   = .false. !  Initialisation of ocean U & V with U & V input data (T) or not (F)
+   ln_uvd_dyndmp = .false. !  damping of ocean U & V toward U & V input data (T) or not (F)
+/
+!-----------------------------------------------------------------------
 &namtsd    !   data : Temperature  & Salinity
 !-----------------------------------------------------------------------
@@ -197,21 +215,25 @@
    ln_tsd_tradmp = .true.   !  damping of ocean T & S toward T &S input data (T) or not (F)
 /
+
 !!======================================================================
 !!            ***  Surface Boundary Condition namelists  ***
 !!======================================================================
 !!   namsbc          surface boundary condition
-!!   namsbc_ana      analytical         formulation
-!!   namsbc_flx      flux               formulation
-!!   namsbc_clio     CLIO bulk formulae formulation
-!!   namsbc_core     CORE bulk formulae formulation
-!!   namsbc_mfs      MFS  bulk formulae formulation
-!!   namsbc_cpl      CouPLed            formulation                     ("key_oasis3")
+!!   namsbc_ana      analytical         formulation                     (ln_ana     =T)
+!!   namsbc_flx      flux               formulation                     (ln_flx     =T)
+!!   namsbc_clio     CLIO bulk formulae formulation                     (ln_blk_clio=T)
+!!   namsbc_core     CORE bulk formulae formulation                     (ln_blk_core=T)
+!!   namsbc_mfs      MFS  bulk formulae formulation                     (ln_blk_mfs =T)
+!!   namsbc_cpl      CouPLed            formulation                     ("key_oasis3" )
 !!   namsbc_sas      StAndalone Surface module
-!!   namtra_qsr      penetrative solar radiation
-!!   namsbc_rnf      river runoffs
-!!   namsbc_isf      ice shelf melting/freezing
-!!   namsbc_apr      Atmospheric Pressure
-!!   namsbc_ssr      sea surface restoring term (for T and/or S)
+!!   namtra_qsr      penetrative solar radiation                        (ln_traqsr  =T)
+!!   namsbc_rnf      river runoffs                                      (ln_rnf     =T)
+!!   namsbc_isf      ice shelf melting/freezing                         (nn_isf     >0)
+!!   namsbc_iscpl    coupling option between land ice model and ocean
+!!   namsbc_apr      Atmospheric Pressure                               (ln_apr_dyn =T)
+!!   namsbc_ssr      sea surface restoring term (for T and/or S)        (ln_ssr     =T)
 !!   namsbc_alb      albedo parameters
+!!   namsbc_wave     external fields from wave model                    (ln_wave    =T)
+!!   namberg         iceberg floats                                     (ln_icebergs=T)
 !!======================================================================
 !
@@ -220,5 +242,6 @@
 !-----------------------------------------------------------------------
    nn_fsbc     = 5         !  frequency of surface boundary condition computation
-                           !     (also = the frequency of sea-ice model call)
+                           !     (also = the frequency of sea-ice & iceberg model call)
+                     ! Type of air-sea fluxes 
    ln_ana      = .false.   !  analytical formulation                    (T => fill namsbc_ana )
    ln_flx      = .false.   !  flux formulation                          (T => fill namsbc_flx )
@@ -226,4 +249,5 @@
    ln_blk_core = .true.    !  CORE bulk formulation                     (T => fill namsbc_core)
    ln_blk_mfs  = .false.   !  MFS bulk formulation                      (T => fill namsbc_mfs )
+                     ! Type of coupling (Ocean/Ice/Atmosphere) :
    ln_cpl      = .false.   !  atmosphere coupled   formulation          ( requires key_oasis3 )
    ln_mixcpl   = .false.   !  forced-coupled mixed formulation          ( requires key_oasis3 )
@@ -232,27 +256,4 @@
                            !  =1 opa-sas OASIS coupling: multi executable configuration, OPA component
                            !  =2 opa-sas OASIS coupling: multi executable configuration, SAS component 
-   ln_apr_dyn  = .false.   !  Patm gradient added in ocean & ice Eqs.   (T => fill namsbc_apr )
-   nn_ice      = 2         !  =0 no ice boundary condition   ,
-                           !  =1 use observed ice-cover      ,
-                           !  =2 ice-model used                         ("key_lim3" or "key_lim2")
-   nn_ice_embd = 1         !  =0 levitating ice (no mass exchange, concentration/dilution effect)
-                           !  =1 levitating ice with mass and salt exchange but no presure effect
-                           !  =2 embedded sea-ice (full salt and mass exchanges and pressure)
-   ln_dm2dc    = .false.   !  daily mean to diurnal cycle on short wave
-   ln_rnf      = .true.    !  runoffs                                   (T   => fill namsbc_rnf)
-   nn_isf      = 0         !  ice shelf melting/freezing                (/=0 => fill namsbc_isf)
-                           !  0 =no isf                  1 = presence of ISF
-                           !  2 = bg03 parametrisation   3 = rnf file for isf
-                           !  4 = ISF fwf specified
-                           !  option 1 and 4 need ln_isfcav = .true. (domzgr)
-   ln_ssr      = .true.    !  Sea Surface Restoring on T and/or S       (T => fill namsbc_ssr)
-   nn_fwb      = 2         !  FreshWater Budget: =0 unchecked
-                           !     =1 global mean of e-p-r set to zero at each time step
-                           !     =2 annual global mean of e-p-r set to zero
-   ln_wave = .false.       !  Activate coupling with wave (either Stokes Drift or Drag coefficient, or both)  (T => fill namsbc_wave)
-   ln_cdgw = .false.       !  Neutral drag coefficient read from wave model (T => fill namsbc_wave)
-   ln_sdw  = .false.       !  Computation of 3D stokes drift                (T => fill namsbc_wave)
-   nn_lsm  = 0             !  =0 land/sea mask for input fields is not applied (keep empty land/sea mask filename field) ,
-                           !  =1:n number of iterations of land/sea mask application for input fields (fill land/sea mask filename field)
    nn_limflx = -1          !  LIM3 Multi-category heat flux formulation (use -1 if LIM3 is not used)
                            !  =-1  Use per-category fluxes, bypass redistributor, forced mode only, not yet implemented coupled
@@ -260,4 +261,24 @@
                            !  = 1  Average and redistribute per-category fluxes, forced mode only, not yet implemented coupled
                            !  = 2  Redistribute a single flux over categories (coupled mode only)
+                     ! Sea-ice :
+   nn_ice      = 2         !  =0 no ice boundary condition   ,
+                           !  =1 use observed ice-cover      ,
+                           !  =2 ice-model used                         ("key_lim3", "key_lim2", "key_cice")
+   nn_ice_embd = 1         !  =0 levitating ice (no mass exchange, concentration/dilution effect)
+                           !  =1 levitating ice with mass and salt exchange but no presure effect
+                           !  =2 embedded sea-ice (full salt and mass exchanges and pressure)
+                     ! Misc. options of sbc : 
+   ln_traqsr   = .true.    !  Light penetration in the ocean            (T => fill namtra_qsr )
+   ln_dm2dc    = .false.   !  daily mean to diurnal cycle on short wave
+   ln_rnf      = .true.    !  runoffs                                   (T => fill namsbc_rnf)
+   ln_ssr      = .true.    !  Sea Surface Restoring on T and/or S       (T => fill namsbc_ssr)
+   nn_fwb      = 2         !  FreshWater Budget: =0 unchecked
+                           !     =1 global mean of e-p-r set to zero at each time step
+                           !     =2 annual global mean of e-p-r set to zero
+   ln_apr_dyn  = .false.   !  Patm gradient added in ocean & ice Eqs.   (T => fill namsbc_apr )
+   ln_isf      = .false.   !  ice shelf                                 (T   => fill namsbc_isf)
+   ln_wave = .false.       !  coupling with surface wave                (T => fill namsbc_wave)
+   nn_lsm  = 0             !  =0 land/sea mask for input fields is not applied (keep empty land/sea mask filename field) ,
+                           !  =1:n number of iterations of land/sea mask application for input fields (fill land/sea mask filename field)
 /
 !-----------------------------------------------------------------------
@@ -302,20 +323,20 @@
 &namsbc_core   !   namsbc_core  CORE bulk formulae
 !-----------------------------------------------------------------------
-!              !  file name                    ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights                               ! rotation ! land/sea mask !
-!              !                               !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename                              ! pairing  ! filename      !
-   sn_wndi     = 'u_10.15JUNE2009_fill'        ,         6         , 'U_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'   , 'Uwnd'   , ''
-   sn_wndj     = 'v_10.15JUNE2009_fill'        ,         6         , 'V_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'   , 'Vwnd'   , ''
-   sn_qsr      = 'ncar_rad.15JUNE2009_fill'    ,        24         , 'SWDN_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
-   sn_qlw      = 'ncar_rad.15JUNE2009_fill'    ,        24         , 'LWDN_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
-   sn_tair     = 't_10.15JUNE2009_fill'        ,         6         , 'T_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
-   sn_humi     = 'q_10.15JUNE2009_fill'        ,         6         , 'Q_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
-   sn_prec     = 'ncar_precip.15JUNE2009_fill' ,        -1         , 'PRC_MOD1',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
-   sn_snow     = 'ncar_precip.15JUNE2009_fill' ,        -1         , 'SNOW'    ,   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
-   sn_tdif     = 'taudif_core'                 ,        24         , 'taudif'  ,   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+!              !  file name                   ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights                               ! rotation ! land/sea mask !
+!              !                              !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename                              ! pairing  ! filename      !
+   sn_wndi     = 'u_10.15JUNE2009_fill'       ,         6         , 'U_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'   , 'Uwnd'   , ''
+   sn_wndj     = 'v_10.15JUNE2009_fill'       ,         6         , 'V_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'   , 'Vwnd'   , ''
+   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,        24         , 'SWDN_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,        24         , 'LWDN_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_tair     = 't_10.15JUNE2009_fill'       ,         6         , 'T_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_humi     = 'q_10.15JUNE2009_fill'       ,         6         , 'Q_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_prec     = 'ncar_precip.15JUNE2009_fill',        -1         , 'PRC_MOD1',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_snow     = 'ncar_precip.15JUNE2009_fill',        -1         , 'SNOW'    ,   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_tdif     = 'taudif_core'                ,        24         , 'taudif'  ,   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
 
    cn_dir      = './'      !  root directory for the location of the bulk files
    ln_taudif   = .false.   !  HF tau contribution: use "mean of stress module - module of the mean stress" data
-   rn_zqt      = 10.        !  Air temperature and humidity reference height (m)
-   rn_zu       = 10.        !  Wind vector reference height (m)
+   rn_zqt      = 10.       !  Air temperature and humidity reference height (m)
+   rn_zu       = 10.       !  Wind vector reference height (m)
    rn_pfac     = 1.        !  multiplicative factor for precipitation (total & snow)
    rn_efac     = 1.        !  multiplicative factor for evaporation (0. or 1.)
@@ -326,13 +347,13 @@
 &namsbc_mfs   !   namsbc_mfs  MFS bulk formulae
 !-----------------------------------------------------------------------
-!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights     ! rotation ! land/sea mask !
-!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename    ! pairing  ! filename      !
-   sn_wndi     =   'ecmwf'   ,        6          , 'u10'     ,    .true.    , .false. , 'daily'  ,'bicubic.nc' , ''       , ''
-   sn_wndj     =   'ecmwf'   ,        6          , 'v10'     ,    .true.    , .false. , 'daily'  ,'bicubic.nc' , ''       , ''
-   sn_clc      =   'ecmwf'   ,        6          , 'clc'     ,    .true.    , .false. , 'daily'  ,'bilinear.nc', ''       , ''
-   sn_msl      =   'ecmwf'   ,        6          , 'msl'     ,    .true.    , .false. , 'daily'  ,'bicubic.nc' , ''       , ''
-   sn_tair     =   'ecmwf'   ,        6          , 't2'      ,    .true.    , .false. , 'daily'  ,'bicubic.nc' , ''       , ''
-   sn_rhm      =   'ecmwf'   ,        6          , 'rh'      ,    .true.    , .false. , 'daily'  ,'bilinear.nc', ''       , ''
-   sn_prec     =   'ecmwf'   ,        6          , 'precip'  ,    .true.    , .true.  , 'daily'  ,'bicubic.nc' , ''       , ''
+!              !  file name  ! frequency (hours) ! variable ! time interp. !  clim  ! 'yearly'/ ! weights     ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name   !   (logical)  !  (T/F) ! 'monthly' ! filename    ! pairing  ! filename      !
+   sn_wndi     =   'ecmwf'   ,        6          , 'u10'    ,    .true.    , .false., 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+   sn_wndj     =   'ecmwf'   ,        6          , 'v10'    ,    .true.    , .false., 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+   sn_clc      =   'ecmwf'   ,        6          , 'clc'    ,    .true.    , .false., 'daily'   ,'bilinear.nc',   ''     ,   ''
+   sn_msl      =   'ecmwf'   ,        6          , 'msl'    ,    .true.    , .false., 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+   sn_tair     =   'ecmwf'   ,        6          , 't2'     ,    .true.    , .false., 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+   sn_rhm      =   'ecmwf'   ,        6          , 'rh'     ,    .true.    , .false., 'daily'   ,'bilinear.nc',   ''     ,   ''
+   sn_prec     =   'ecmwf'   ,        6          , 'precip' ,    .true.    , .true. , 'daily'   ,'bicubic.nc' ,   ''     ,   ''
 
    cn_dir      = './ECMWF/'      !  root directory for the location of the bulk files
@@ -341,23 +362,23 @@
 &namsbc_cpl    !   coupled ocean/atmosphere model                       ("key_oasis3")
 !-----------------------------------------------------------------------
-!                    !     description       !  multiple  !    vector   !      vector          ! vector !
-!                    !                       ! categories !  reference  !    orientation       ! grids  !
+!                    !     description      !  multiple  !    vector   !      vector          ! vector !
+!                    !                      ! categories !  reference  !    orientation       ! grids  !
 ! send
-   sn_snd_temp   =       'weighted oce and ice' ,    'no'    ,     ''      ,         ''           ,   ''
-   sn_snd_alb    =       'weighted ice'         ,    'no'    ,     ''      ,         ''           ,   ''
-   sn_snd_thick  =       'none'                 ,    'no'   ,     ''      ,         ''           ,   ''
-   sn_snd_crt    =       'none'                 ,    'no'    , 'spherical' , 'eastward-northward' ,  'T'
-   sn_snd_co2    =       'coupled'              ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_temp   =   'weighted oce and ice' ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_alb    =   'weighted ice'         ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_thick  =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_crt    =   'none'                 ,    'no'    , 'spherical' , 'eastward-northward' ,  'T'
+   sn_snd_co2    =   'coupled'              ,    'no'    ,     ''      ,         ''           ,   ''
 ! receive
-   sn_rcv_w10m   =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_taumod =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_tau    =       'oce only'             ,    'no'    , 'cartesian' , 'eastward-northward',  'U,V'
-   sn_rcv_dqnsdt =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_qsr    =       'oce and ice'          ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_qns    =       'oce and ice'          ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_emp    =       'conservative'         ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_rnf    =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_cal    =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_co2    =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_w10m   =   'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_taumod =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_tau    =   'oce only'             ,    'no'    , 'cartesian' , 'eastward-northward',  'U,V'
+   sn_rcv_dqnsdt =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_qsr    =   'oce and ice'          ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_qns    =   'oce and ice'          ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_emp    =   'conservative'         ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_rnf    =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_cal    =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_co2    =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
 !
    nn_cplmodel   =     1     !  Maximum number of models to/from which NEMO is potentialy sending/receiving data
@@ -383,5 +404,5 @@
 /
 !-----------------------------------------------------------------------
-&namtra_qsr    !   penetrative solar radiation
+&namtra_qsr    !   penetrative solar radiation                          (ln_traqsr=T)
 !-----------------------------------------------------------------------
 !              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
@@ -390,5 +411,4 @@
 
    cn_dir      = './'      !  root directory for the location of the runoff files
-   ln_traqsr   = .true.    !  Light penetration (T) or not (F)
    ln_qsr_rgb  = .true.    !  RGB (Red-Green-Blue) light penetration
    ln_qsr_2bd  = .false.   !  2 bands              light penetration
@@ -401,5 +421,5 @@
 /
 !-----------------------------------------------------------------------
-&namsbc_rnf    !   runoffs namelist surface boundary condition
+&namsbc_rnf    !   runoffs namelist surface boundary condition          (ln_rnf=T)
 !-----------------------------------------------------------------------
 !              !  file name           ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
@@ -425,39 +445,49 @@
 /
 !-----------------------------------------------------------------------
-&namsbc_isf    !  Top boundary layer (ISF)
-!-----------------------------------------------------------------------
-!              ! file name ! frequency (hours) ! variable ! time interpol. !  clim   ! 'yearly'/ ! weights  ! rotation !
-!              !           !  (if <0  months)  !   name   !    (logical)   !  (T/F)  ! 'monthly' ! filename ! pairing  !
+&namsbc_isf    !  Top boundary layer (ISF)                              (nn_isf >0)
+!-----------------------------------------------------------------------
+!              ! file name ! frequency (hours) ! variable ! time interp. !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !           !  (if <0  months)  !   name   !  (logical)   !  (T/F)  ! 'monthly' ! filename ! pairing  ! filename      !
 ! nn_isf == 4
-   sn_qisf      = 'rnfisf' ,         -12      ,'sohflisf',    .false.      , .true.  , 'yearly'  ,  ''      ,   ''
-   sn_fwfisf    = 'rnfisf' ,         -12      ,'sowflisf',    .false.      , .true.  , 'yearly'  ,  ''      ,   ''
+   sn_fwfisf   = 'rnfisf'  ,         -12       ,'sowflisf',   .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
 ! nn_isf == 3
-   sn_rnfisf    = 'runoffs' ,         -12      ,'sofwfisf',    .false.      , .true.  , 'yearly'  ,  ''      ,   ''
+   sn_rnfisf   = 'rnfisf'  ,         -12       ,'sofwfisf',   .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
 ! nn_isf == 2 and 3
-   sn_depmax_isf = 'runoffs' ,       -12        ,'sozisfmax' ,   .false.  , .true.  , 'yearly'  ,  ''      ,   ''
-   sn_depmin_isf = 'runoffs' ,       -12        ,'sozisfmin' ,   .false.  , .true.  , 'yearly'  ,  ''      ,   ''
+   sn_depmax_isf='rnfisf'  ,         -12       ,'sozisfmax',  .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
+   sn_depmin_isf='rnfisf'  ,         -12       ,'sozisfmin',  .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
 ! nn_isf == 2
-   sn_Leff_isf = 'rnfisf' ,       0          ,'Leff'         ,   .false.  , .true.  , 'yearly'  ,  ''      ,   ''
+   sn_Leff_isf = 'rnfisf'  ,         -12       ,'Leff'    ,   .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
+!
 ! for all case
-   ln_divisf   = .true.  ! apply isf melting as a mass flux or in the salinity trend. (maybe I should remove this option as for runoff?)
+   nn_isf      = 1         !  ice shelf melting/freezing
+                           !  1 = presence of ISF    2 = bg03 parametrisation 
+                           !  3 = rnf file for isf   4 = ISF fwf specified
+                           !  option 1 and 4 need ln_isfcav = .true. (domzgr)
 ! only for nn_isf = 1 or 2
-   rn_gammat0  = 1.0e-4   ! gammat coefficient used in blk formula
-   rn_gammas0  = 1.0e-4   ! gammas coefficient used in blk formula
+   rn_gammat0  = 1.e-4    ! gammat coefficient used in blk formula
+   rn_gammas0  = 1.e-4    ! gammas coefficient used in blk formula
+! only for nn_isf = 1 or 4
+   rn_hisf_tbl =  30.      ! thickness of the top boundary layer    (Losh et al. 2008)
+                          ! 0 => thickness of the tbl = thickness of the first wet cell
 ! only for nn_isf = 1
-   nn_isfblk   =  1       ! 1 ISOMIP ; 2 conservative (3 equation formulation, Jenkins et al. 1991 ??)
-   rn_hisf_tbl =  30.      ! thickness of the top boundary layer           (Losh et al. 2008)
-                          ! 0 => thickness of the tbl = thickness of the first wet cell
-   ln_conserve = .true.   ! conservative case (take into account meltwater advection)
+   nn_isfblk   = 1        ! 1 ISOMIP  like: 2 equations formulation (Hunter et al., 2006)
+                          ! 2 ISOMIP+ like: 3 equations formulation (Asay-Davis et al., 2015)
    nn_gammablk = 1        ! 0 = cst Gammat (= gammat/s)
                           ! 1 = velocity dependend Gamma (u* * gammat/s)  (Jenkins et al. 2010)
-                          !     if you want to keep the cd as in global config, adjust rn_gammat0 to compensate
-                          ! 2 = velocity and stability dependent Gamma    Holland et al. 1999
+                          ! 2 = velocity and stability dependent Gamma    (Holland et al. 1999)
+/
+!-----------------------------------------------------------------------
+&namsbc_iscpl  !   land ice / ocean coupling option                     
+!-----------------------------------------------------------------------
+   nn_drown  = 10       ! number of iteration of the extrapolation loop (fill the new wet cells)
+   ln_hsb    = .false.  ! activate conservation module (conservation exact after a time of rn_fiscpl)
+   nn_fiscpl = 43800    ! (number of time step) conservation period (maybe should be fix to the coupling frequencey of restart frequency)
 /
 !-----------------------------------------------------------------------
 &namsbc_apr    !   Atmospheric pressure used as ocean forcing or in bulk
 !-----------------------------------------------------------------------
-!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
-!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_apr      = 'patm'      ,         -1        ,'somslpre',    .true.     , .true. , 'yearly'  ,  ''      ,   ''     , ''
+!              !  file name ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !            !  (if <0  months)  !   name    !  (logical)   !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_apr      = 'patm'     ,         -1        ,'somslpre',    .true.     , .true. , 'yearly'  ,  ''      ,   ''     , ''
 
    cn_dir      = './'       !  root directory for the location of the bulk files
@@ -467,5 +497,5 @@
 /
 !-----------------------------------------------------------------------
-&namsbc_ssr    !   surface boundary condition : sea surface restoring
+&namsbc_ssr    !   surface boundary condition : sea surface restoring   (ln_ssr=T)
 !-----------------------------------------------------------------------
 !              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
@@ -493,7 +523,21 @@
 /
 !-----------------------------------------------------------------------
-&namberg       !   iceberg parameters
-!-----------------------------------------------------------------------
-      ln_icebergs              = .false.
+&namsbc_wave   ! External fields from wave model                        (ln_wave=T)
+!-----------------------------------------------------------------------
+!              !  file name  ! frequency (hours) ! variable    ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name      !  (logical)   !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_cdg      =  'cdg_wave' ,        1          , 'drag_coeff',     .true.   , .false., 'daily'   ,  ''      , ''       , ''
+   sn_usd      =  'sdw_wave' ,        1          , 'u_sd2d'    ,     .true.   , .false., 'daily'   ,  ''      , ''       , ''
+   sn_vsd      =  'sdw_wave' ,        1          , 'v_sd2d'    ,     .true.   , .false., 'daily'   ,  ''      , ''       , ''
+   sn_wn       =  'sdw_wave' ,        1          , 'wave_num'  ,     .true.   , .false., 'daily'   ,  ''      , ''       , ''
+!
+   cn_dir_cdg  = './'      !  root directory for the location of drag coefficient files
+   ln_cdgw = .false.       !  Neutral drag coefficient read from wave model
+   ln_sdw  = .false.       !  Computation of 3D stokes drift               
+/
+!-----------------------------------------------------------------------
+&namberg       !   iceberg parameters                                   (default: No iceberg)
+!-----------------------------------------------------------------------
+      ln_icebergs              = .false.              ! iceberg floats or not
       ln_bergdia               = .true.               ! Calculate budgets
       nn_verbose_level         = 1                    ! Turn on more verbose output if level > 0
@@ -520,7 +564,7 @@
       rn_speed_limit           = 0.                   ! CFL speed limit for a berg
 
-!              ! file name ! frequency (hours) !   variable   ! time interp.   !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
-!              !           !  (if <0  months)  !     name     !   (logical)    !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
-      sn_icb =  'calving' ,       -1           , 'calvingmask',  .true.        , .true.  , 'yearly'  , ''       , ''       , ''
+!            ! file name ! frequency (hours) !   variable   ! time interp. !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!            !           !  (if <0  months)  !     name     !   (logical)  !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
+      sn_icb =  'calving',       -1          , 'calvingmask',  .true.      , .true.  , 'yearly'  , ''       , ''       , ''
 
       cn_dir = './'
@@ -540,7 +584,7 @@
 &namlbc        !   lateral momentum boundary condition
 !-----------------------------------------------------------------------
+   !                       !  free slip  !   partial slip  !   no slip   ! strong slip
    rn_shlat    =    2.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
-                           !  free slip  !   partial slip  !   no slip   ! strong slip
-   ln_vorlat   = .false.   !  consistency of vorticity boundary condition with analytical eqs.
+   ln_vorlat   = .false.   !  consistency of vorticity boundary condition with analytical Eqs.
 /
 !-----------------------------------------------------------------------
@@ -554,5 +598,5 @@
 /
 !-----------------------------------------------------------------------
-&nam_tide      !   tide parameters (#ifdef key_tide)
+&nam_tide      !   tide parameters                                      ("key_tide")
 !-----------------------------------------------------------------------
    ln_tide_pot   = .true.   !  use tidal potential forcing
@@ -596,32 +640,33 @@
 /
 !-----------------------------------------------------------------------
-&nambdy_dta      !  open boundaries - external data           ("key_bdy")
-!-----------------------------------------------------------------------
-!              !  file name      ! frequency (hours) ! variable   ! time interp.   !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
-!              !                 !  (if <0  months)  !   name     !   (logical)    !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
-   bn_ssh =     'amm12_bdyT_u2d' ,         24        , 'sossheig' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
-   bn_u2d =     'amm12_bdyU_u2d' ,         24        , 'vobtcrtx' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
-   bn_v2d =     'amm12_bdyV_u2d' ,         24        , 'vobtcrty' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
-   bn_u3d  =    'amm12_bdyU_u3d' ,         24        , 'vozocrtx' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
-   bn_v3d  =    'amm12_bdyV_u3d' ,         24        , 'vomecrty' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
-   bn_tem  =    'amm12_bdyT_tra' ,         24        , 'votemper' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
-   bn_sal  =    'amm12_bdyT_tra' ,         24        , 'vosaline' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+&nambdy_dta    !  open boundaries - external data                       ("key_bdy")
+!-----------------------------------------------------------------------
+!              !  file name      ! frequency (hours) ! variable  ! time interp. !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !                 !  (if <0  months)  !   name    !  (logical)   !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
+   bn_ssh =     'amm12_bdyT_u2d' ,         24        , 'sossheig',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+   bn_u2d =     'amm12_bdyU_u2d' ,         24        , 'vobtcrtx',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+   bn_v2d =     'amm12_bdyV_u2d' ,         24        , 'vobtcrty',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+   bn_u3d  =    'amm12_bdyU_u3d' ,         24        , 'vozocrtx',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+   bn_v3d  =    'amm12_bdyV_u3d' ,         24        , 'vomecrty',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+   bn_tem  =    'amm12_bdyT_tra' ,         24        , 'votemper',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+   bn_sal  =    'amm12_bdyT_tra' ,         24        , 'vosaline',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
 ! for lim2
-!   bn_frld  =    'amm12_bdyT_ice' ,         24        , 'ileadfra' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
-!   bn_hicif =    'amm12_bdyT_ice' ,         24        , 'iicethic' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
-!   bn_hsnif =    'amm12_bdyT_ice' ,         24        , 'isnowthi' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_frld  =   'amm12_bdyT_ice' ,         24        , 'ileadfra',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_hicif =   'amm12_bdyT_ice' ,         24        , 'iicethic',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_hsnif =   'amm12_bdyT_ice' ,         24        , 'isnowthi',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
 ! for lim3
-!   bn_a_i  =    'amm12_bdyT_ice' ,         24        , 'ileadfra' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
-!   bn_ht_i =    'amm12_bdyT_ice' ,         24        , 'iicethic' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
-!   bn_ht_s =    'amm12_bdyT_ice' ,         24        , 'isnowthi' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
-   cn_dir  =    'bdydta/'
-   ln_full_vel = .false.
+!   bn_a_i  =    'amm12_bdyT_ice' ,         24        , 'ileadfra',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_ht_i =    'amm12_bdyT_ice' ,         24        , 'iicethic',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_ht_s =    'amm12_bdyT_ice' ,         24        , 'isnowthi',     .true.   , .false. ,  'daily'  ,    ''    ,   ''     , ''
+
+   cn_dir      =    'bdydta/'   !  root directory for the location of the bulk files
+   ln_full_vel = .false.        !  
 /
 !-----------------------------------------------------------------------
 &nambdy_tide     ! tidal forcing at open boundaries
 !-----------------------------------------------------------------------
-   filtide          = 'bdydta/amm12_bdytide_'         !  file name root of tidal forcing files
-   ln_bdytide_2ddta = .false.
-   ln_bdytide_conj  = .false.
+   filtide          = 'bdydta/amm12_bdytide_'   !  file name root of tidal forcing files
+   ln_bdytide_2ddta = .false.                   !
+   ln_bdytide_conj  = .false.                   ! 
 /
 !!======================================================================
@@ -634,5 +679,5 @@
 !
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
+&nambfr        !   bottom friction                                      (default: linear)
 !-----------------------------------------------------------------------
    nn_bfr      =    1      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
@@ -657,20 +702,19 @@
 /
 !-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition
-!-----------------------------------------------------------------------
-!              !                              !  (if <0  months)  !  
-!              !  file name      ! frequency (hours) ! variable   ! time interp.   !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
-!              !                 !  (if <0  months)  !   name     !   (logical)    !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_qgh      ='geothermal_heating.nc',  -12.  , 'heatflow'      ,   .false.      , .true.  , 'yearly'  , ''       , ''       , ''
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
+!              !  file name      ! frequency (hours) ! variable  ! time interp.!  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !                 !  (if <0  months)  !   name    !  (logical)  !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_qgh      ='geothermal_heating.nc',  -12.       , 'heatflow',   .false.   , .true.  , 'yearly'  ,   ''     ,   ''     ,   ''
    !
-   cn_dir      = './'      !  root directory for the location of the runoff files
-   ln_trabbc   = .true.    !  Apply a geothermal heating at the ocean bottom
+   ln_trabbc   = .false.   !  Apply a geothermal heating at the ocean bottom
    nn_geoflx   =    2      !  geothermal heat flux: = 0 no flux
                            !     = 1 constant flux
                            !     = 2 variable flux (read in geothermal_heating.nc in mW/m2)
    rn_geoflx_cst = 86.4e-3 !  Constant value of geothermal heat flux [W/m2]
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme
+   cn_dir      = './'      !  root directory for the location of the runoff files 
+/
+!-----------------------------------------------------------------------
+&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
 !-----------------------------------------------------------------------
    nn_bbl_ldf  =  1      !  diffusive bbl (=1)   or not (=0)
@@ -711,5 +755,5 @@
 /
 !-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer
+&namtra_adv    !   advection scheme for tracer                          (default: NO advection)
 !-----------------------------------------------------------------------
    ln_traadv_cen =  .false.  !  2nd order centered scheme
@@ -724,9 +768,9 @@
       ln_mus_ups =  .false.         !  use upstream scheme near river mouths
    ln_traadv_ubs =  .false.  !  UBS scheme
-      nn_ubs_v   =  2               !  =2  , vertical 2nd order FCT
+      nn_ubs_v   =  2               !  =2  , vertical 2nd order FCT / COMPACT 4th order
    ln_traadv_qck =  .false.  !  QUICKEST scheme
 /
 !-----------------------------------------------------------------------
-&namtra_adv_mle !   mixed layer eddy parametrisation (Fox-Kemper param)
+&namtra_adv_mle !   mixed layer eddy parametrisation (Fox-Kemper param) (default: NO)
 !-----------------------------------------------------------------------
    ln_mle    = .false.      ! (T) use the Mixed Layer Eddy (MLE) parameterisation
@@ -740,7 +784,7 @@
    rn_rho_c_mle  = 0.01    ! delta rho criterion used to calculate MLD for FK
 /
-!----------------------------------------------------------------------------------
-&namtra_ldf    !   lateral diffusion scheme for tracers
-!----------------------------------------------------------------------------------
+!-----------------------------------------------------------------------
+&namtra_ldf    !   lateral diffusion scheme for tracers                 (default: NO diffusion)
+!-----------------------------------------------------------------------
    !                       !  Operator type:
    !                           !  no diffusion: set ln_traldf_lap=..._blp=F 
@@ -772,11 +816,11 @@
    rn_bht_0        = 1.e+12    !  lateral eddy diffusivity (bilap. operator) [m4/s]
 /
-!----------------------------------------------------------------------------------
-&namtra_ldfeiv !   eddy induced velocity param.
-!----------------------------------------------------------------------------------
-   ln_ldfeiv     =.false.   ! use eddy induced velocity parameterization
-   ln_ldfeiv_dia =.false.   ! diagnose eiv stream function and velocities
-   rn_aeiv_0     = 2000.    ! eddy induced velocity coefficient   [m2/s]
-   nn_aei_ijk_t  = 21       ! space/time variation of the eiv coeficient
+!-----------------------------------------------------------------------
+&namtra_ldfeiv !   eddy induced velocity param.                         (default: NO)
+!-----------------------------------------------------------------------
+   ln_ldfeiv     =.false.  ! use eddy induced velocity parameterization
+   ln_ldfeiv_dia =.false.  ! diagnose eiv stream function and velocities
+   rn_aeiv_0     = 2000.   ! eddy induced velocity coefficient   [m2/s]
+   nn_aei_ijk_t  = 21      ! space/time variation of the eiv coeficient
    !                                !   =-20 (=-30)    read in eddy_induced_velocity_2D.nc (..._3D.nc) file
    !                                !   =  0           constant 
@@ -787,5 +831,5 @@
 /
 !-----------------------------------------------------------------------
-&namtra_dmp    !   tracer: T & S newtonian damping
+&namtra_dmp    !   tracer: T & S newtonian damping                      (default: NO)
 !-----------------------------------------------------------------------
    ln_tradmp   =  .true.   !  add a damping termn (T) or not (F)
@@ -793,5 +837,5 @@
                            !                   =1 no damping in the mixing layer (kz  criteria)
                            !                   =2 no damping in the mixed  layer (rho crieria)
-   cn_resto    = 'resto.nc' ! Name of file containing restoration coefficient field (use dmp_tools to create this)
+   cn_resto    ='resto.nc' !  Name of file containing restoration coeff. field (use dmp_tools to create this)
 /
 
@@ -807,5 +851,5 @@
 !
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
+&namdyn_adv    !   formulation of the momentum advection                (default: vector form)
 !-----------------------------------------------------------------------
    ln_dynadv_vec = .true.  !  vector form (T) or flux form (F)
@@ -816,5 +860,5 @@
 /
 !-----------------------------------------------------------------------
-&nam_vvl    !   vertical coordinate options
+&nam_vvl    !   vertical coordinate options                             (default: zstar)
 !-----------------------------------------------------------------------
    ln_vvl_zstar  = .true.           !  zstar vertical coordinate
@@ -830,5 +874,5 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_vor    !   option of physics/algorithm (not control by CPP keys)
+&namdyn_vor    !   option of physics/algorithm                          (default: NO)
 !-----------------------------------------------------------------------
    ln_dynvor_ene = .false. !  enstrophy conserving scheme
@@ -836,9 +880,9 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .false. !  energy & enstrophy scheme
-      nn_een_e3f = 1             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
-   ln_dynvor_msk = .false. !  vorticity multiplied by fmask (=T) or not (=F) (all vorticity schemes)  ! PLEASE DO NOT USE
-/
-!-----------------------------------------------------------------------
-&namdyn_hpg    !   Hydrostatic pressure gradient option
+      nn_een_e3f = 1          ! e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
+   ln_dynvor_msk = .false. !  vorticity multiplied by fmask (=T) or not (=F) (all vorticity schemes)  ! PLEASE DO NOT ACTIVATE
+/
+!-----------------------------------------------------------------------
+&namdyn_hpg    !   Hydrostatic pressure gradient option                 (default: zps)
 !-----------------------------------------------------------------------
    ln_hpg_zco  = .false.   !  z-coordinate - full steps
@@ -850,19 +894,19 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_spg    !   surface pressure gradient
+&namdyn_spg    !   surface pressure gradient                            (default: NO)
 !-----------------------------------------------------------------------
    ln_dynspg_exp  = .false.   ! explicit free surface
    ln_dynspg_ts   = .false.   ! split-explicit free surface
-      ln_bt_fw      = .true.    ! Forward integration of barotropic Eqs.
-      ln_bt_av      = .true.    ! Time filtering of barotropic variables
-         nn_bt_flt    =  1        ! Time filter choice  = 0 None
-         !                        !                     = 1 Boxcar over   nn_baro sub-steps
-         !                        !                     = 2 Boxcar over 2*nn_baro  "    "
-      ln_bt_auto    = .true.    ! Number of sub-step defined from:
-         rn_bt_cmax   =  0.8      ! =T : the Maximum Courant Number allowed
-         nn_baro      = 30        ! =F : the number of sub-step in rn_rdt seconds
-/
-!-----------------------------------------------------------------------
-&namdyn_ldf    !   lateral diffusion on momentum
+      ln_bt_fw      = .true.     ! Forward integration of barotropic Eqs.
+      ln_bt_av      = .true.     ! Time filtering of barotropic variables
+         nn_bt_flt     = 1          ! Time filter choice  = 0 None
+         !                          !                     = 1 Boxcar over   nn_baro sub-steps
+         !                          !                     = 2 Boxcar over 2*nn_baro  "    "
+      ln_bt_auto    = .true.     ! Number of sub-step defined from:
+         rn_bt_cmax   =  0.8        ! =T : the Maximum Courant Number allowed
+         nn_baro      = 30          ! =F : the number of sub-step in rn_rdt seconds
+/
+!-----------------------------------------------------------------------
+&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO)
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
@@ -896,4 +940,5 @@
 !!    namzdf_ric    richardson number dependent vertical mixing         ("key_zdfric")
 !!    namzdf_tke    TKE dependent vertical mixing                       ("key_zdftke")
+!!    namzdf_gls    GLS vertical mixing                                 ("key_zdfgls")
 !!    namzdf_ddm    double diffusive mixing parameterization            ("key_zdfddm")
 !!    namzdf_tmx    tidal mixing parameterization                       ("key_zdftmx")
@@ -927,5 +972,5 @@
    rn_wtmix    =  10.0     !  vertical eddy viscosity coeff [m2/s] in the mixed-layer
    rn_wvmix    =  10.0     !  vertical eddy diffusion coeff [m2/s] in the mixed-layer
-   ln_mldw     = .true.    !  Flag to use or not the mized layer depth param.
+   ln_mldw     = .true.    !  Flag to use or not the mixed layer depth param.
 /
 !-----------------------------------------------------------------------
@@ -997,7 +1042,4 @@
 !!   nammpp            Massively Parallel Processing                    ("key_mpp_mpi)
 !!   namctl            Control prints & Benchmark
-!!   namc1d            1D configuration options                         ("key_c1d")
-!!   namc1d_uvd        data: U & V currents                             ("key_c1d")
-!!   namc1d_dyndmp     U & V newtonian damping                          ("key_c1d")
 !!   namsto            Stochastic parametrization of EOS
 !!======================================================================
@@ -1028,38 +1070,21 @@
                            !     (no physical validity of the results)
    nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
-/
-!-----------------------------------------------------------------------
-&namc1d_uvd    !   data: U & V currents                                 ("key_c1d")
-!-----------------------------------------------------------------------
-!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
-!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_ucur     = 'ucurrent'  ,         -1        ,'u_current',   .false.    , .true. , 'monthly' ,  ''      ,  'Ume'   , ''
-   sn_vcur     = 'vcurrent'  ,         -1        ,'v_current',   .false.    , .true. , 'monthly' ,  ''      ,  'Vme'   , ''
-!
-   cn_dir        = './'    !  root directory for the location of the files
-   ln_uvd_init   = .false. !  Initialisation of ocean U & V with U & V input data (T) or not (F)
-   ln_uvd_dyndmp = .false. !  damping of ocean U & V toward U & V input data (T) or not (F)
-/
-!-----------------------------------------------------------------------
-&namc1d_dyndmp !   U & V newtonian damping                              ("key_c1d")
-!-----------------------------------------------------------------------
-   ln_dyndmp   =  .false.  !  add a damping term (T) or not (F)
-/
-!-----------------------------------------------------------------------
-&namsto       ! Stochastic parametrization of EOS
-!-----------------------------------------------------------------------
-   ln_rststo = .false.           ! start from mean parameter (F) or from restart file (T)
+   nn_diacfl   =    0      !  Write out CFL diagnostics (=1) in cfl_diagnostics.ascii, or not (=0)
+/
+!-----------------------------------------------------------------------
+&namsto       ! Stochastic parametrization of EOS                       (default: NO)
+!-----------------------------------------------------------------------
+   ln_sto_eos   = .false.  ! stochastic equation of state
+   nn_sto_eos   = 1        ! number of independent random walks
+   rn_eos_stdxy = 1.4      ! random walk horz. standard deviation (in grid points)
+   rn_eos_stdz  = 0.7      ! random walk vert. standard deviation (in grid points)
+   rn_eos_tcor  = 1440.    ! random walk time correlation (in timesteps)
+   nn_eos_ord   = 1        ! order of autoregressive processes
+   nn_eos_flt   = 0        ! passes of Laplacian filter
+   rn_eos_lim   = 2.0      ! limitation factor (default = 3.0)
+   ln_rststo    = .false.  ! start from mean parameter (F) or from restart file (T)
    ln_rstseed = .true.           ! read seed of RNG from restart file
    cn_storst_in  = "restart_sto" !  suffix of stochastic parameter restart file (input)
    cn_storst_out = "restart_sto" !  suffix of stochastic parameter restart file (output)
-
-   ln_sto_eos = .false.          ! stochastic equation of state
-   nn_sto_eos = 1                ! number of independent random walks
-   rn_eos_stdxy = 1.4            ! random walk horz. standard deviation (in grid points)
-   rn_eos_stdz  = 0.7            ! random walk vert. standard deviation (in grid points)
-   rn_eos_tcor  = 1440.0         ! random walk time correlation (in timesteps)
-   nn_eos_ord  = 1               ! order of autoregressive processes
-   nn_eos_flt  = 0               ! passes of Laplacian filter
-   rn_eos_lim  = 2.0             ! limitation factor (default = 3.0)
 /
 
@@ -1067,33 +1092,24 @@
 !!                  ***  Diagnostics namelists  ***
 !!======================================================================
-!!   namnc4       netcdf4 chunking and compression settings             ("key_netcdf4")
 !!   namtrd       dynamics and/or tracer trends
 !!   namptr       Poleward Transport Diagnostics
+!!   namhsb       Heat and salt budgets
 !!   namflo       float parameters                                      ("key_float")
-!!   namhsb       Heat and salt budgets
-!!======================================================================
-!
-!-----------------------------------------------------------------------
-&namnc4        !   netcdf4 chunking and compression settings            ("key_netcdf4")
-!-----------------------------------------------------------------------
-   nn_nchunks_i=   4       !  number of chunks in i-dimension
-   nn_nchunks_j=   4       !  number of chunks in j-dimension
-   nn_nchunks_k=   31      !  number of chunks in k-dimension
-                           !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
-                           !  is optimal for postprocessing which works exclusively with horizontal slabs
-   ln_nc4zip   = .true.    !  (T) use netcdf4 chunking and compression
-                           !  (F) ignore chunking information and produce netcdf3-compatible files
-/
-!-----------------------------------------------------------------------
-&namtrd        !   diagnostics on dynamics and/or tracer trends
-!              !       and/or mixed-layer trends and/or barotropic vorticity
+!!   nam_diaharm  Harmonic analysis of tidal constituents               ('key_diaharm')
+!!   namdct       transports through some sections
+!!   namnc4       netcdf4 chunking and compression settings             ("key_netcdf4")
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namtrd        !   diagnostics on dynamics and/or tracer trends         (default F)
+!              !   and/or mixed-layer trends and/or barotropic vorticity
 !-----------------------------------------------------------------------
    ln_glo_trd  = .false.   ! (T) global domain averaged diag for T, T^2, KE, and PE
    ln_dyn_trd  = .false.   ! (T) 3D momentum trend output
-   ln_dyn_mxl  = .FALSE.   ! (T) 2D momentum trends averaged over the mixed layer (not coded yet)
-   ln_vor_trd  = .FALSE.   ! (T) 2D barotropic vorticity trends (not coded yet)
+   ln_dyn_mxl  = .false.   ! (T) 2D momentum trends averaged over the mixed layer (not coded yet)
+   ln_vor_trd  = .false.   ! (T) 2D barotropic vorticity trends (not coded yet)
    ln_KE_trd   = .false.   ! (T) 3D Kinetic   Energy     trends
    ln_PE_trd   = .false.   ! (T) 3D Potential Energy     trends
-   ln_tra_trd  = .FALSE.   ! (T) 3D tracer trend output
+   ln_tra_trd  = .false.   ! (T) 3D tracer trend output
    ln_tra_mxl  = .false.   ! (T) 2D tracer trends averaged over the mixed layer (not coded yet)
    nn_trd      = 365       !  print frequency (ln_glo_trd=T) (unit=time step)
@@ -1106,4 +1122,15 @@
 !!gm   ln_trdmld_instant = .false.         !  flag to diagnose trends of instantantaneous or mean ML T/S
 !!gm
+!-----------------------------------------------------------------------
+&namptr       !   Poleward Transport Diagnostic                         (default F)
+!-----------------------------------------------------------------------
+   ln_diaptr  = .false.    !  Poleward heat and salt transport (T) or not (F)
+   ln_subbas  = .false.     !  Atlantic/Pacific/Indian basins computation (T) or not
+/
+!-----------------------------------------------------------------------
+&namhsb       !  Heat and salt budgets                                  (default F)
+!-----------------------------------------------------------------------
+   ln_diahsb  = .false.    !  check the heat and salt budgets (T) or not (F)
+/
 !-----------------------------------------------------------------------
 &namflo       !   float parameters                                      ("key_float")
@@ -1121,16 +1148,5 @@
 /
 !-----------------------------------------------------------------------
-&namptr       !   Poleward Transport Diagnostic
-!-----------------------------------------------------------------------
-   ln_diaptr  = .false.    !  Poleward heat and salt transport (T) or not (F)
-   ln_subbas  = .false.     !  Atlantic/Pacific/Indian basins computation (T) or not
-/
-!-----------------------------------------------------------------------
-&namhsb       !  Heat and salt budgets
-!-----------------------------------------------------------------------
-   ln_diahsb  = .false.    !  check the heat and salt budgets (T) or not (F)
-/
-!-----------------------------------------------------------------------
-&nam_diaharm   !   Harmonic analysis of tidal constituents ('key_diaharm')
+&nam_diaharm   !   Harmonic analysis of tidal constituents              ('key_diaharm')
 !-----------------------------------------------------------------------
     nit000_han = 1         ! First time step used for harmonic analysis
@@ -1141,5 +1157,5 @@
 /
 !-----------------------------------------------------------------------
-&namdct        ! transports through sections
+&namdct        ! transports through some sections
 !-----------------------------------------------------------------------
     nn_dct      = 15       !  time step frequency for transports computing
@@ -1149,68 +1165,59 @@
                            !  0 < n : debug section number n
 /
-
-!!======================================================================
-!!            ***  Observation & Assimilation namelists ***
-!!======================================================================
-!!   namobs       observation and model comparison                      ('key_diaobs')
+!-----------------------------------------------------------------------
+&namnc4        !   netcdf4 chunking and compression settings            ("key_netcdf4")
+!-----------------------------------------------------------------------
+   nn_nchunks_i=   4       !  number of chunks in i-dimension
+   nn_nchunks_j=   4       !  number of chunks in j-dimension
+   nn_nchunks_k=   31      !  number of chunks in k-dimension
+                           !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                           !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip   = .true.    !  (T) use netcdf4 chunking and compression
+                           !  (F) ignore chunking information and produce netcdf3-compatible files
+/
+
+!!======================================================================
+!!               ***  Observation & Assimilation  ***
+!!======================================================================
+!!   namobs       observation and model comparison
 !!   nam_asminc   assimilation increments                               ('key_asminc')
 !!======================================================================
 !
 !-----------------------------------------------------------------------
-&namobs       !  observation usage switch                               ('key_diaobs')
-!-----------------------------------------------------------------------
-   ln_t3d     = .false.    ! Logical switch for T profile observations
-   ln_s3d     = .false.    ! Logical switch for S profile observations
-   ln_ena     = .false.    ! Logical switch for ENACT insitu data set
-   ln_cor     = .false.    ! Logical switch for Coriolis insitu data set
-   ln_profb   = .false.    ! Logical switch for feedback insitu data set
-   ln_sla     = .false.    ! Logical switch for SLA observations
-   ln_sladt   = .false.    ! Logical switch for AVISO SLA data
-   ln_slafb   = .false.    ! Logical switch for feedback SLA data
-   ln_ssh     = .false.    ! Logical switch for SSH observations
-   ln_sst     = .false.    ! Logical switch for SST observations
-   ln_reysst  = .false.    ! Logical switch for Reynolds observations
-   ln_ghrsst  = .false.    ! Logical switch for GHRSST observations
-   ln_sstfb   = .false.    ! Logical switch for feedback SST data
-   ln_sss     = .false.    ! Logical switch for SSS observations
-   ln_seaice  = .false.    ! Logical switch for Sea Ice observations
-   ln_vel3d   = .false.    ! Logical switch for velocity observations
-   ln_velavcur= .false     ! Logical switch for velocity daily av. cur.
-   ln_velhrcur= .false     ! Logical switch for velocity high freq. cur.
-   ln_velavadcp = .false.  ! Logical switch for velocity daily av. ADCP
-   ln_velhradcp = .false.  ! Logical switch for velocity high freq. ADCP
-   ln_velfb   = .false.    ! Logical switch for feedback velocity data
-   ln_grid_global = .false. ! Global distribtion of observations
-   ln_grid_search_lookup = .false. !  Logical switch for obs grid search w/lookup table
-   grid_search_file = 'grid_search'  !  Grid search lookup file header
+&namobs       !  observation usage switch
+!-----------------------------------------------------------------------
+   ln_diaobs  = .false.             ! Logical switch for the observation operator
+   ln_t3d     = .false.             ! Logical switch for T profile observations
+   ln_s3d     = .false.             ! Logical switch for S profile observations
+   ln_sla     = .false.             ! Logical switch for SLA observations
+   ln_sst     = .false.             ! Logical switch for SST observations
+   ln_sic     = .false.             ! Logical switch for Sea Ice observations
+   ln_vel3d   = .false.             ! Logical switch for velocity observations
+   ln_altbias = .false.             ! Logical switch for altimeter bias correction
+   ln_nea     = .false.             ! Logical switch for rejection of observations near land
+   ln_grid_global = .true.          ! Logical switch for global distribution of observations
+   ln_grid_search_lookup = .false.  ! Logical switch for obs grid search w/lookup table
+   ln_ignmis  = .true.              ! Logical switch for ignoring missing files
+   ln_s_at_t  = .false.             ! Logical switch for computing model S at T obs if not there
+   ln_sstnight = .false.            ! Logical switch for calculating night-time average for SST obs
 ! All of the *files* variables below are arrays. Use namelist_cfg to add more files
-   enactfiles = 'enact.nc' !  ENACT input observation file names (specify full array in namelist_cfg)
-   coriofiles = 'corio.nc' !  Coriolis input observation file name
-   profbfiles = 'profiles_01.nc' ! Profile feedback input observation file name
-   ln_profb_enatim = .false !        Enact feedback input time setting switch
-   slafilesact = 'sla_act.nc' !  Active SLA input observation file names
-   slafilespas = 'sla_pass.nc' ! Passive SLA input observation file names
-   slafbfiles = 'sla_01.nc' ! slafbfiles: Feedback SLA input observation file names
-   sstfiles = 'ghrsst.nc'   ! GHRSST input observation file names
-   sstfbfiles = 'sst_01.nc' ! Feedback SST input observation file names
-   seaicefiles = 'seaice_01.nc' ! Sea Ice input observation file names
-   velavcurfiles = 'velavcurfile.nc'  ! Vel. cur. daily av. input file name
-   velhrcurfiles = 'velhrcurfile.nc'  ! Vel. cur. high freq. input file name
-   velavadcpfiles = 'velavadcpfile.nc' ! Vel. ADCP daily av. input file name
-   velhradcpfiles = 'velhradcpfile.nc' ! Vel. ADCP high freq. input file name
-   velfbfiles = 'velfbfile.nc' ! Vel. feedback input observation file name
-   dobsini = 20000101.000000  !  Initial date in window YYYYMMDD.HHMMSS
-   dobsend = 20010101.000000  !  Final date in window YYYYMMDD.HHMMSS
-   n1dint = 0  !               Type of vertical interpolation method
-   n2dint = 0  !               Type of horizontal interpolation method
-   ln_nea = .false.   !        Rejection of observations near land switch
-   nmsshc     = 0     !        MSSH correction scheme
-   mdtcorr = 1.61     !        MDT  correction
-   mdtcutoff = 65.0   !        MDT cutoff for computed correction
-   ln_altbias = .false.    ! Logical switch for alt bias
-   ln_ignmis  = .true.     ! Logical switch for ignoring missing files
-   endailyavtypes = 820    ! ENACT daily average types - array (use namelist_cfg to set more values)
-   ln_grid_global = .true.
-   ln_grid_search_lookup = .false.
+   cn_profbfiles = 'profiles_01.nc'    ! Profile feedback input observation file names
+   cn_slafbfiles = 'sla_01.nc'         ! SLA feedback input observation file names
+   cn_sstfbfiles = 'sst_01.nc'         ! SST feedback input observation file names
+   cn_sicfbfiles = 'sic_01.nc'         ! SIC feedback input observation file names
+   cn_velfbfiles = 'vel_01.nc'         ! Velocity feedback input observation file names
+   cn_altbiasfile = 'altbias.nc'       ! Altimeter bias input file name
+   cn_gridsearchfile = 'gridsearch.nc' ! Grid search file name
+   rn_gridsearchres = 0.5              ! Grid search resolution
+   rn_dobsini = 00010101.000000        ! Initial date in window YYYYMMDD.HHMMSS
+   rn_dobsend = 00010102.000000        ! Final date in window YYYYMMDD.HHMMSS
+   nn_1dint = 0                        ! Type of vertical interpolation method
+   nn_2dint = 0                        ! Type of horizontal interpolation method
+   nn_msshc = 0                        ! MSSH correction scheme
+   rn_mdtcorr = 1.61                   ! MDT  correction
+   rn_mdtcutoff = 65.0                 ! MDT cutoff for computed correction
+   nn_profdavtypes = -1                ! Profile daily average types - array
+   ln_sstbias = .false. 
+   cn_sstbias_files = 'sstbias.nc'
 /
 !-----------------------------------------------------------------------
@@ -1233,28 +1240,17 @@
 /
 !-----------------------------------------------------------------------
-&namsbc_wave   ! External fields from wave model
-!-----------------------------------------------------------------------
-!              !  file name  ! frequency (hours) ! variable     ! time interp. !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
-!              !             !  (if <0  months)  !   name       !   (logical)  !  (T/F)  ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_cdg      =  'cdg_wave' ,        1          , 'drag_coeff' ,     .true.   , .false. , 'daily'   ,  ''      , ''       , ''
-   sn_usd      =  'sdw_wave' ,        1          , 'u_sd2d'     ,     .true.   , .false. , 'daily'   ,  ''      , ''       , ''
-   sn_vsd      =  'sdw_wave' ,        1          , 'v_sd2d'     ,     .true.   , .false. , 'daily'   ,  ''      , ''       , ''
-   sn_wn       =  'sdw_wave' ,        1          , 'wave_num'   ,     .true.   , .false. , 'daily'   ,  ''      , ''       , ''
-!
-   cn_dir_cdg  = './'  !  root directory for the location of drag coefficient files
-/
-!-----------------------------------------------------------------------
-&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
-!-----------------------------------------------------------------------
-   ! Suggested lengthscale values are those of Eby & Holloway (1994) for a coarse model
-   ln_neptsimp       = .false.  ! yes/no use simplified neptune
-
-   ln_smooth_neptvel = .false.  ! yes/no smooth zunep, zvnep
-   rn_tslse          =  1.2e4   ! value of lengthscale L at the equator
-   rn_tslsp          =  3.0e3   ! value of lengthscale L at the pole
-   ! Specify whether to ramp down the Neptune velocity in shallow
-   ! water, and if so the depth range controlling such ramping down
-   ln_neptramp       = .true.   ! ramp down Neptune velocity in shallow water
-   rn_htrmin         =  100.0   ! min. depth of transition range
-   rn_htrmax         =  200.0   ! max. depth of transition range
-/
+&namdiu !   Cool skin and warm layer models
+!-----------------------------------------------------------------------
+   ln_diurnal      = .false.   ! 
+   ln_diurnal_only = .false.   !
+/
+!-----------------------------------------------------------------------
+&nam_diatmb  !  Top Middle Bottom Output
+!-----------------------------------------------------------------------
+   ln_diatmb  = .false.    !  Choose Top Middle and Bottom output or not
+/
+!-----------------------------------------------------------------------
+&nam_dia25h  !  25h Mean Output
+!-----------------------------------------------------------------------
+   ln_dia25h  = .false.    ! Choose 25h mean output or not
+/
Index: /trunk/NEMOGCM/CONFIG/SHARED/namelist_top_ref
===================================================================
--- /trunk/NEMOGCM/CONFIG/SHARED/namelist_top_ref	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/SHARED/namelist_top_ref	(revision 6140)
@@ -11,13 +11,13 @@
 !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 !-----------------------------------------------------------------------
-&namtrc_run     !   run information
+&namtrc_run      !   run information
 !-----------------------------------------------------------------------
    nn_dttrc      =  1        !  time step frequency for passive sn_tracers
    nn_writetrc   =  5475     !  time step frequency for sn_tracer outputs
-   ln_top_euler  = .false.    !  use Euler time-stepping for TOP
+   ln_top_euler  = .false.   !  use Euler time-stepping for TOP
    ln_rsttr      = .false.   !  start from a restart file (T) or not (F)
    nn_rsttr      =   0       !  restart control = 0 initial time step is not compared to the restart file value
-                           !                  = 1 do not use the value in the restart file
-                           !                  = 2 calendar parameters read in the restart file
+                             !                  = 1 do not use the value in the restart file
+                             !                  = 2 calendar parameters read in the restart file
    cn_trcrst_in  = "restart_trc"   !  suffix of pass. sn_tracer restart name (input)
    cn_trcrst_indir = "."           !  directory from which to read input passive tracer restarts
@@ -26,5 +26,5 @@
 /
 !-----------------------------------------------------------------------
-&namtrc     !   tracers definition
+&namtrc          !   tracers definition
 !-----------------------------------------------------------------------
    ln_trcdta     =   .true.  !  Initialisation from data input file (T) or not (F)
@@ -35,9 +35,8 @@
 &namtrc_dta      !    Initialisation from data input file
 !-----------------------------------------------------------------------
-!
-   cn_dir        =  './'      !  root directory for the location of the data files
+   cn_dir        =  './'     !  root directory for the location of the data files
 /
 !-----------------------------------------------------------------------
-&namtrc_adv    !   advection scheme for passive tracer 
+&namtrc_adv      !   advection scheme for passive tracer 
 !-----------------------------------------------------------------------
    ln_trcadv_cen =  .false.  !  2nd order centered scheme
@@ -56,71 +55,82 @@
 /
 !-----------------------------------------------------------------------
-&namtrc_ldf    !   lateral diffusion scheme for passive tracer 
+&namtrc_ldf      !   lateral diffusion scheme for passive tracer 
 !-----------------------------------------------------------------------
-!                          !  Type of the operator:  
-   ln_trcldf_lap   =  .true.   !    laplacian operator
-   ln_trcldf_blp   =  .false.  !  bilaplacian operator
-   !                       !  Direction of action:
-   ln_trcldf_lev   =  .false.  !  iso-level
-   ln_trcldf_hor   =  .false.  !  horizontal (geopotential)
-   ln_trcldf_iso   =  .true.   !  iso-neutral (standard operator)
-   ln_trcldf_triad =  .false.  !  iso-neutral (triad    operator)
-   !                       !  Coefficient 
-   rn_ahtrc_0      = 2000.     !  lateral eddy diffusivity   (lap. operator) [m2/s]
-   rn_bhtrc_0      = 1.e+12    !  lateral eddy diffusivity (bilap. operator) [m4/s]
+!                            !  Type of the operator:  
+   ln_trcldf_lap   =  .true.     !    laplacian operator
+   ln_trcldf_blp   =  .false.    !  bilaplacian operator
+   !                         !  Direction of action:
+   ln_trcldf_lev   =  .false.    !  iso-level
+   ln_trcldf_hor   =  .false.    !  horizontal (geopotential)
+   ln_trcldf_iso   =  .true.     !  iso-neutral (standard operator)
+   ln_trcldf_triad =  .false.    !  iso-neutral (triad    operator)
+   !                         !  Coefficient 
+   rn_ahtrc_0      = 2000.       !  lateral eddy diffusivity   (lap. operator) [m2/s]
+   rn_bhtrc_0      = 1.e+12      !  lateral eddy diffusivity (bilap. operator) [m4/s]
 /
 !-----------------------------------------------------------------------
-&namtrc_zdf        !   vertical physics
+&namtrc_zdf      !   vertical physics
 !-----------------------------------------------------------------------
-   ln_trczdf_exp   =  .false.  !  split explicit (T) or implicit (F) time stepping
-   nn_trczdf_exp   =   3       !  number of sub-timestep for ln_trczdfexp=T
+   ln_trczdf_exp =  .false.  !  split explicit (T) or implicit (F) time stepping
+   nn_trczdf_exp =   3       !  number of sub-timestep for ln_trczdfexp=T
 /
 !-----------------------------------------------------------------------
-&namtrc_rad        !  treatment of negative concentrations 
+&namtrc_rad      !  treatment of negative concentrations 
 !-----------------------------------------------------------------------
-   ln_trcrad   =  .true.  !  artificially correct negative concentrations (T) or not (F)
+   ln_trcrad     =  .true.   !  artificially correct negative concentrations (T) or not (F)
 /
 !-----------------------------------------------------------------------
-&namtrc_dmp    !   passive tracer newtonian damping   
+&namtrc_dmp      !   passive tracer newtonian damping   
 !-----------------------------------------------------------------------
-   nn_zdmp_tr  =    1      !  vertical   shape =0    damping throughout the water column
-                           !                   =1 no damping in the mixing layer (kz  criteria)
-                           !                   =2 no damping in the mixed  layer (rho crieria)
-   cn_resto_tr  = 'resto_tr.nc'    !  create a damping.coeff NetCDF file (=1) or not (=0)
+   nn_zdmp_tr    =    1      !  vertical   shape =0    damping throughout the water column
+                             !                   =1 no damping in the mixing layer (kz  criteria)
+                             !                   =2 no damping in the mixed  layer (rho crieria)
+   cn_resto_tr   = 'resto_tr.nc'    !  create a damping.coeff NetCDF file (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
-&namtrc_ice       !    Representation of sea ice growth & melt effects
+&namtrc_ice      !    Representation of sea ice growth & melt effects
 !-----------------------------------------------------------------------
-   nn_ice_tr   =  -1        !  tracer concentration in sea ice 
-                           !    =-1 (no vvl: identical cc in ice and ocean / vvl: cc_ice = 0)
-                           !    = 0 (no vvl: cc_ice = zero / vvl: cc_ice = )
-                           !    = 1 prescribed to a namelist value (implemented in pisces only)
+   nn_ice_tr     =  -1       !  tracer concentration in sea ice 
+                             !    =-1 (no vvl: identical cc in ice and ocean / vvl: cc_ice = 0)
+                             !    = 0 (no vvl: cc_ice = zero / vvl: cc_ice = )
+                             !    = 1 prescribed to a namelist value (implemented in pisces only)
 /
 !-----------------------------------------------------------------------
-&namtrc_trd       !   diagnostics on tracer trends        ('key_trdtrc')
-!                          or mixed-layer trends          ('key_trdmld_trc')
+&namtrc_trd      !   diagnostics on tracer trends                       ('key_trdtrc')
+!                          or mixed-layer trends                        ('key_trdmld_trc')
 !----------------------------------------------------------------------
-   nn_trd_trc  =  5475      !  time step frequency and tracers trends
-   nn_ctls_trc =   0        !  control surface type in mixed-layer trends (0,1 or n<jpk)
-   rn_ucf_trc  =   1        !  unit conversion factor (=1 -> /seconds ; =86400. -> /day)
-   ln_trdmld_trc_restart = .false.  !  restart for ML diagnostics
+   nn_trd_trc    =  5475     !  time step frequency and tracers trends
+   nn_ctls_trc   =   0       !  control surface type in mixed-layer trends (0,1 or n<jpk)
+   rn_ucf_trc    =   1       !  unit conversion factor (=1 -> /seconds ; =86400. -> /day)
+   ln_trdmld_trc_restart = .false. !  restart for ML diagnostics
    ln_trdmld_trc_instant = .true.  !  flag to diagnose trends of instantantaneous or mean ML T/S
-   ln_trdtrc(1)  =   .true.
-   ln_trdtrc(2)  =   .true.
-   ln_trdtrc(23) =   .true.
+   ln_trdtrc( 1) = .true.
+   ln_trdtrc( 2) = .true.
+   ln_trdtrc(23) = .true.
 /
 !-----------------------------------------------------------------------
-&namtrc_dia       !   parameters for passive tracer additional diagnostics
+&namtrc_dia      !   parameters for passive tracer additional diagnostics
 !----------------------------------------------------------------------
    ln_diatrc     =  .true.   !  save additional diag. (T) or not (F)
    ln_diabio     =  .true.   !  output biological trends
    nn_writedia   =  5475     !  time step frequency for diagnostics
-   nn_writebio   =    10     !: frequency of biological outputs
+   nn_writebio   =    10     !  frequency of biological outputs
 /
 !----------------------------------------------------------------------
-! namtrc_bc       !   data for boundary conditions
+&namtrc_bc       !   data for boundary conditions
 !-----------------------------------------------------------------------
-&namtrc_bc
-!
-   cn_dir        =  './'      !  root directory for the location of the data files
+   cn_dir_sbc    =  './'     !  root directory for the location of SURFACE data files
+   cn_dir_cbc    =  './'     !  root directory for the location of COASTAL data files
+   cn_dir_obc    =  './'     !  root directory for the location of OPEN data files
 /
+!----------------------------------------------------------------------
+&namtrc_bdy      !   Setup of tracer boundary conditions
+!-----------------------------------------------------------------------
+   cn_trc_dflt   = 'neumann' !  OBC applied by default to all tracers
+   cn_trc        = 'none'    !  Boundary conditions used for tracers with data files (selected in namtrc)
+
+   nn_trcdmp_bdy = 0         !  Use damping timescales defined in nambdy of namelist
+                             !  = 0 NO damping of tracers at open boudaries
+                             !  = 1 Only for tracers forced with external data
+                             !  = 2 Damping applied to all tracers
+/
Index: /trunk/NEMOGCM/CONFIG/cfg.txt
===================================================================
--- /trunk/NEMOGCM/CONFIG/cfg.txt	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/cfg.txt	(revision 6140)
@@ -7,6 +7,6 @@
 AMM12 OPA_SRC
 ORCA2_LIM_PISCES OPA_SRC LIM_SRC_2 NST_SRC TOP_SRC
-GYRE OPA_SRC
 ORCA2_LIM3 OPA_SRC LIM_SRC_3 NST_SRC
 ORCA2_LIM OPA_SRC LIM_SRC_2 NST_SRC
 ORCA2_OFF_PISCES OPA_SRC OFF_SRC TOP_SRC
+GYRE OPA_SRC
Index: /trunk/NEMOGCM/CONFIG/uspcfg.txt
===================================================================
--- /trunk/NEMOGCM/CONFIG/uspcfg.txt	(revision 6139)
+++ /trunk/NEMOGCM/CONFIG/uspcfg.txt	(revision 6140)
@@ -1,2 +1,2 @@
 ORCA1_CICE # ORCA2_LIM # OPA_SRC TOP_SRC  # http://gws-access.ceda.ac.uk/public/nemo/uspconfigs/ORCA1_CICE/v3.6.0/ORCA1_CICE_ctl.txt
-ISOMIP     # GYRE      # OPA_SRC          # http://gws-access.ceda.ac.uk/public/nemo/uspconfigs/ISOMIP/v3.6.0/ISOMIP_ctl.txt
+ISOMIP     # GYRE      # OPA_SRC          # http://gws-access.ceda.ac.uk/public/nemo/uspconfigs/ISOMIP/trunk/ISOMIP_ctl.txt
Index: /trunk/NEMOGCM/NEMO/LIM_SRC_2/iceini_2.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/LIM_SRC_2/iceini_2.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/LIM_SRC_2/iceini_2.F90	(revision 6140)
@@ -83,5 +83,5 @@
       CALL ice_run_2                   ! read in namelist some run parameters
       !          
-      rdt_ice = nn_fsbc * rdttra(1)    ! sea-ice time step
+      rdt_ice = nn_fsbc * rdt           ! sea-ice time step
       numit   = nit000 - 1
       !
Index: /trunk/NEMOGCM/NEMO/LIM_SRC_2/limrst_2.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/LIM_SRC_2/limrst_2.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/LIM_SRC_2/limrst_2.F90	(revision 6140)
@@ -71,6 +71,4 @@
                WRITE(numout,*)
                SELECT CASE ( jprstlib )
-               CASE ( jprstdimg )
-                  WRITE(numout,*) '             open ice restart binary file: ',TRIM(clpath)//clname
                CASE DEFAULT
                   WRITE(numout,*) '             open ice restart NetCDF file: ',TRIM(clpath)//clname
@@ -192,11 +190,4 @@
       ENDIF
 
-      IF ( jprstlib == jprstdimg ) THEN
-        ! eventually read netcdf file (monobloc)  for restarting on different number of processors
-        ! if {cn_icerst_in}.nc exists, then set jlibalt to jpnf90
-        INQUIRE( FILE = TRIM(cn_icerst_indir)//'/'//TRIM(cn_icerst_in)//'.nc', EXIST = llok )
-        IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
-      ENDIF
-
       CALL iom_open ( TRIM(cn_icerst_indir)//'/'//TRIM(cn_icerst_in), numrir, kiolib = jlibalt )
 
Index: /trunk/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90	(revision 6140)
@@ -29,7 +29,8 @@
    USE sbc_ice          ! surface boundary condition: ice
    USE sbc_oce          ! surface boundary condition: ocean
-   USE sbccpl
+   USE sbccpl           ! surface boundary condition: coupled interface
    USE oce       , ONLY : sshn, sshb, snwice_mass, snwice_mass_b, snwice_fmass 
    USE albedo           ! albedo parameters
+   !
    USE lbclnk           ! ocean lateral boundary condition - MPP exchanges
    USE lib_mpp          ! MPP library
@@ -43,7 +44,7 @@
    PRIVATE
 
-   PUBLIC   lim_sbc_init_2     ! called by ice_init_2
-   PUBLIC   lim_sbc_flx_2      ! called by sbc_ice_lim_2
-   PUBLIC   lim_sbc_tau_2      ! called by sbc_ice_lim_2
+   PUBLIC   lim_sbc_init_2   ! called by ice_init_2
+   PUBLIC   lim_sbc_flx_2    ! called by sbc_ice_lim_2
+   PUBLIC   lim_sbc_tau_2    ! called by sbc_ice_lim_2
 
    REAL(wp)  ::   r1_rdtice            ! = 1. / rdt_ice 
@@ -52,5 +53,5 @@
    REAL(wp)  ::   rone   = 1._wp       !     -      -
    !
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   soce_0, sice_0   ! constant SSS and ice salinity used in levitating sea-ice case
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   soce_0, sice_0       ! fix SSS and ice salinity used in levitating case 0
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   utau_oce, vtau_oce   ! air-ocean surface i- & j-stress              [N/m2]
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmod_io              ! modulus of the ice-ocean relative velocity   [m/s]
@@ -58,5 +59,4 @@
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/LIM2 4.0 , UCL - NEMO Consortium (2011)
@@ -102,5 +102,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt    ! number of iteration
-      !!
+      !
       INTEGER  ::   ji, jj   ! dummy loop indices
       INTEGER  ::   ii0, ii1, ij0, ij1         ! local integers
@@ -114,13 +114,13 @@
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   zalb, zalbp   ! 2D/3D workspace
       !!---------------------------------------------------------------------
-     
+      !
       CALL wrk_alloc( jpi, jpj, zqnsoce )
       CALL wrk_alloc( jpi, jpj, 1, zalb, zalbp )
-
-      SELECT CASE( nn_ice_embd )                 ! levitating or embedded sea-ice option
-        CASE( 0    )   ;   zswitch = 1           ! (0) standard levitating sea-ice : salt exchange only
-        CASE( 1, 2 )   ;   zswitch = 0           ! (1) levitating sea-ice: salt and volume exchange but no pressure effect
-                                                 ! (2) embedded sea-ice : salt and volume fluxes and pressure
-      END SELECT                                 !    
+      !
+      SELECT CASE( nn_ice_embd )             ! levitating or embedded sea-ice option
+         CASE( 0    )   ;   zswitch = 1         ! (0) old levitating sea-ice : salt exchange only
+         CASE( 1, 2 )   ;   zswitch = 0         ! (1) levitating sea-ice: salt and volume exchange but no pressure effect
+         !                                      ! (2) embedded sea-ice : salt and volume fluxes and pressure
+      END SELECT
 
       !------------------------------------------!
@@ -303,5 +303,5 @@
       INTEGER ,                     INTENT(in) ::   kt               ! ocean time-step index
       REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pu_oce, pv_oce   ! surface ocean currents
-      !!
+      !
       INTEGER  ::   ji, jj   ! dummy loop indices
       REAL(wp) ::   zfrldu, zat_u, zu_i, zutau_ice, zu_t, zmodt   ! local scalar
@@ -435,6 +435,6 @@
       !! ** input   : Namelist namicedia
       !!-------------------------------------------------------------------
-      !
-      INTEGER :: jk           ! local integer
+      INTEGER ::   jk   ! local integer
+      !!-------------------------------------------------------------------
       !
       IF(lwp) WRITE(numout,*)
@@ -470,35 +470,37 @@
          sshn(:,:) = sshn(:,:) - snwice_mass(:,:) * r1_rau0
          sshb(:,:) = sshb(:,:) - snwice_mass(:,:) * r1_rau0
-         do jk = 1,jpkm1                     ! adjust initial vertical scale factors
-          fse3t_n(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshn(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
-          fse3t_b(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshb(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
-         end do
-         fse3t_a(:,:,:) = fse3t_b(:,:,:)
-         ! Reconstruction of all vertical scale factors at now and before time steps
-         ! =============================================================================
-         ! Horizontal scale factor interpolations
-         ! --------------------------------------
-         CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3u_b(:,:,:), 'U' )
-         CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3v_b(:,:,:), 'V' )
-         CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3u_n(:,:,:), 'U' )
-         CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3v_n(:,:,:), 'V' )
-         CALL dom_vvl_interpol( fse3u_n(:,:,:), fse3f_n(:,:,:), 'F' )
-         ! Vertical scale factor interpolations
-         ! ------------------------------------
-         CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3w_n (:,:,:), 'W'  )
-         CALL dom_vvl_interpol( fse3u_n(:,:,:), fse3uw_n(:,:,:), 'UW' )
-         CALL dom_vvl_interpol( fse3v_n(:,:,:), fse3vw_n(:,:,:), 'VW' )
-         CALL dom_vvl_interpol( fse3u_b(:,:,:), fse3uw_b(:,:,:), 'UW' )
-         CALL dom_vvl_interpol( fse3v_b(:,:,:), fse3vw_b(:,:,:), 'VW' )
-         ! t- and w- points depth
-         ! ----------------------
-         fsdept_n(:,:,1) = 0.5_wp * fse3w_n(:,:,1)
-         fsdepw_n(:,:,1) = 0.0_wp
-         fsde3w_n(:,:,1) = fsdept_n(:,:,1) - sshn(:,:)
-         DO jk = 2, jpk
-            fsdept_n(:,:,jk) = fsdept_n(:,:,jk-1) + fse3w_n(:,:,jk)
-            fsdepw_n(:,:,jk) = fsdepw_n(:,:,jk-1) + fse3t_n(:,:,jk-1)
-            fsde3w_n(:,:,jk) = fsdept_n(:,:,jk  ) - sshn   (:,:)
-         END DO
+!!gm I really don't like this staff here...  Find a way to put that elsewhere or differently
+!!gm
+         IF( .NOT.ln_linssh ) THEN
+
+            do jk = 1,jpkm1                     ! adjust initial vertical scale factors
+               e3t_n(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshn(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
+               e3t_b(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshb(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
+            end do
+            e3t_a(:,:,:) = e3t_b(:,:,:)
+            ! Reconstruction of all vertical scale factors at now and before time steps
+            !        ! Horizontal scale factor interpolations
+            CALL dom_vvl_interpol( e3t_b(:,:,:), e3u_b(:,:,:), 'U' )
+            CALL dom_vvl_interpol( e3t_b(:,:,:), e3v_b(:,:,:), 'V' )
+            CALL dom_vvl_interpol( e3t_n(:,:,:), e3u_n(:,:,:), 'U' )
+            CALL dom_vvl_interpol( e3t_n(:,:,:), e3v_n(:,:,:), 'V' )
+            CALL dom_vvl_interpol( e3u_n(:,:,:), e3f_n(:,:,:), 'F' )
+            !        ! Vertical scale factor interpolations
+            CALL dom_vvl_interpol( e3t_n(:,:,:), e3w_n (:,:,:), 'W'  )
+            CALL dom_vvl_interpol( e3u_n(:,:,:), e3uw_n(:,:,:), 'UW' )
+            CALL dom_vvl_interpol( e3v_n(:,:,:), e3vw_n(:,:,:), 'VW' )
+            CALL dom_vvl_interpol( e3u_b(:,:,:), e3uw_b(:,:,:), 'UW' )
+            CALL dom_vvl_interpol( e3v_b(:,:,:), e3vw_b(:,:,:), 'VW' )
+            !        ! t- and w- points depth
+            gdept_n(:,:,1) = 0.5_wp * e3w_n(:,:,1)
+            gdepw_n(:,:,1) = 0.0_wp
+            gde3w_n(:,:,1) = gdept_n(:,:,1) - sshn(:,:)
+            DO jk = 2, jpk
+               gdept_n(:,:,jk) = gdept_n(:,:,jk-1) + e3w_n(:,:,jk)
+               gdepw_n(:,:,jk) = gdepw_n(:,:,jk-1) + e3t_n(:,:,jk-1)
+               gde3w_n(:,:,jk) = gdept_n(:,:,jk  ) - sshn   (:,:)
+            END DO
+         ENDIF
+!!gm end
       ENDIF
       !
Index: /trunk/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90	(revision 6140)
@@ -18,18 +18,19 @@
    USE phycst           ! physical constants
    USE dom_oce          ! ocean space and time domain variables
-   USE domvvl
-   USE lbclnk
+   USE domvvl           ! ocean domain
+   USE ice_2            ! LIM sea-ice variables
+   USE sbc_oce          ! surface boundary condition: ocean
+   USE sbc_ice          ! surface boundary condition: sea-ice
+   USE thd_ice_2        ! LIM thermodynamic sea-ice variables
+   USE dom_ice_2        ! LIM sea-ice domain
+   USE limthd_zdf_2     !
+   USE limthd_lac_2     !
+   USE limtab_2         !
+   !
    USE in_out_manager   ! I/O manager
-   USE lib_mpp
+   USE lbclnk           !
+   USE lib_mpp          !
    USE wrk_nemo         ! work arrays
    USE iom              ! IOM library
-   USE ice_2            ! LIM sea-ice variables
-   USE sbc_oce          ! 
-   USE sbc_ice          ! 
-   USE thd_ice_2        ! LIM thermodynamic sea-ice variables
-   USE dom_ice_2        ! LIM sea-ice domain
-   USE limthd_zdf_2
-   USE limthd_lac_2
-   USE limtab_2
    USE prtctl           ! Print control
    USE lib_fortran      ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
@@ -43,9 +44,8 @@
    REAL(wp) ::   epsi16 = 1.e-16   !
    REAL(wp) ::   epsi04 = 1.e-04   !
-   REAL(wp) ::   rzero  = 0.e0     !
-   REAL(wp) ::   rone   = 1.e0     !
+   REAL(wp) ::   rzero  = 0._wp    !
+   REAL(wp) ::   rone   = 1._wp    !
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!-------- -------------------------------------------------------------
@@ -75,5 +75,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt     ! number of iteration
-      !!
+      !
       INTEGER  ::   ji, jj               ! dummy loop indices
       INTEGER  ::   nbpb                 ! nb of icy pts for thermo. cal.
@@ -233,5 +233,5 @@
             
             !  energy needed to bring ocean surface layer until its freezing
-            qcmif  (ji,jj) =  rau0 * rcp * fse3t_m(ji,jj) * ( tfu(ji,jj) - sst_m(ji,jj) - rt0 ) * ( 1 - zinda )
+            qcmif  (ji,jj) =  rau0 * rcp * e3t_m(ji,jj) * ( tfu(ji,jj) - sst_m(ji,jj) - rt0 ) * ( 1 - zinda )
             
             !  calculate oceanic heat flux.
Index: /trunk/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90	(revision 6140)
@@ -85,10 +85,4 @@
 
 #if ! defined key_iomput
-# if defined key_dimgout
-   !!----------------------------------------------------------------------
-   !!   'key_dimgout'                                    Direct Access file
-   !!----------------------------------------------------------------------
-# include "limwri_dimg_2.h90"
-# else
    SUBROUTINE lim_wri_2( kt )
       !!-------------------------------------------------------------------
@@ -215,6 +209,4 @@
       !
    END SUBROUTINE lim_wri_2
-     
-#endif     
 
    SUBROUTINE lim_wri_init_2
Index: unk/NEMOGCM/NEMO/LIM_SRC_2/limwri_dimg_2.h90
===================================================================
--- /trunk/NEMOGCM/NEMO/LIM_SRC_2/limwri_dimg_2.h90	(revision 6139)
+++ 	(revision )
@@ -1,217 +1,0 @@
-    SUBROUTINE lim_wri_2(kt)
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM2 3.3 , UCL - NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-    !!-------------------------------------------------------------------
-    !!  This routine computes the average of some variables and write it
-    !!  on the ouput files.
-    !!  ATTENTION cette routine n'est valable que si le pas de temps est
-    !!  egale a une fraction entiere de 1 jours.
-    !!  Diff 1-D 3-D : suppress common also included in etat
-    !!                 suppress cmoymo 11-18
-    !!  modif : 03/06/98
-    !!-------------------------------------------------------------------
-    USE  diadimg                ! use of dia_wri_dimg
-
-    INTEGER, INTENT(in) ::   kt     ! number of iteration
-
-    INTEGER , SAVE ::   nmoyice   !: counter for averaging
-    INTEGER , SAVE ::   nwf       !: number of fields to write on disk
-    INTEGER, SAVE,DIMENSION (:), ALLOCATABLE  :: nsubindex   !: subindex to be saved
-    INTEGER , SAVE ::   nice, nhorid, ndim, niter, ndepid
-    REAL(wp), SAVE, DIMENSION(:,:,:), ALLOCATABLE :: rcmoy
-
-    INTEGER ::  ji, jj, jf, ii   ! dummy loop indices and array index
-    INTEGER :: iyear, iday, imon ! 
-    INTEGER :: ialloc
-    CHARACTER(LEN=80) :: clname, cltext, clmode
-    REAL(wp), DIMENSION(1) ::   zdept
-    REAL(wp) ::   zsto, zsec, zjulian,zout
-    REAL(wp) ::   zindh, zinda, zindb, ztmu
-    REAL(wp), POINTER, DIMENSION(:,:)     ::   zfield
-
-#if ! defined key_diainstant
-    LOGICAL, PARAMETER :: ll_dia_inst=.false.      ! local logical variable 
-#else
-    LOGICAL, PARAMETER :: ll_dia_inst=.true.
-#endif
-    !!-------------------------------------------------------------------
-    IF( .NOT. ALLOCATED(rcmoy) )THEN
-        ALLOCATE(rcmoy(jpi,jpj,jpnoumax),  STAT=ialloc )
-       !
-       IF( lk_mpp      )   CALL mpp_sum ( ialloc  )
-       IF( ialloc /= 0 )   CALL ctl_warn('lim_wri_2 (limwri_dimg_2.h90) : failed to allocate arrays')
-    ENDIF
-
-    CALL wrk_alloc( jpi, jpj, zfield )
-
-    IF ( kt == nit000 ) THEN 
-       !
-       CALL lim_wri_init_2 
-
-       nwf = 0 
-       ii  = 0
-
-       IF (lwp ) THEN
-          WRITE(numout,*) 'lim_wri_2 : Write ice outputs in dimg'
-          WRITE(numout,*) '~~~~~~~~'
-          WRITE(numout,*) '   According to namelist_ice, following fields saved:'
-          DO jf =1, noumef
-             IF (nc(jf) == 1 ) THEN
-                WRITE(numout,* ) '    -',titn(jf), nam(jf), uni(jf)
-             ENDIF
-          END DO
-       ENDIF
-
-       DO jf = 1, noumef
-          IF (nc(jf) == 1 ) nwf = nwf + 1
-       END DO
-
-       ALLOCATE( nsubindex (nwf) )
-
-       DO jf = 1, noumef
-          IF (nc(jf) == 1 ) THEN 
-             ii = ii +1 
-             nsubindex(ii) = jf
-          END IF
-       END DO
-
-       rcmoy(:,:,:) = 0.0_wp
-       zsto     = rdt_ice
-       zout     = nwrite * rdt_ice / nn_fsbc
-       zsec     = 0.
-       niter    = 0
-       zdept(1) = 0.
-       nmoyice  = 0
-
-    ENDIF
-
-#if ! defined key_diainstant 
-    !-- Compute mean values
-
-    zcmo(:,:, 1:jpnoumax ) = 0.e0 
-    DO jj = 2 , jpjm1
-       DO ji = 2 , jpim1
-          zindh  = MAX( zzero , SIGN( zone , hicif(ji,jj) * (1.0 - frld(ji,jj) ) - 0.10 ) )
-          zinda  = MAX( zzero , SIGN( zone , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
-          zindb  = zindh * zinda
-          zcmo(ji,jj,1)  = hsnif (ji,jj)
-          zcmo(ji,jj,2)  = hicif (ji,jj)
-          zcmo(ji,jj,3)  = hicifp(ji,jj)
-          zcmo(ji,jj,4)  = frld  (ji,jj)
-          zcmo(ji,jj,5)  = sist  (ji,jj)
-          zcmo(ji,jj,6)  = fbif  (ji,jj)
-          IF (lk_lim2_vp) THEN
-            ztmu   = MAX( 0.5 * zone , ( tmu(ji,jj) + tmu(ji+1,jj) + tmu(ji,jj+1) + tmu(ji+1,jj+1) ) ) 
-            zcmo(ji,jj,7)  = zindb * (  u_ice(ji,jj  ) * tmu(ji,jj  ) + u_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
-             &                      + u_ice(ji,jj+1) * tmu(ji,jj+1) + u_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
-               / ztmu 
-
-            zcmo(ji,jj,8)  = zindb * (  v_ice(ji,jj  ) * tmu(ji,jj  ) + v_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
-             &                      + v_ice(ji,jj+1) * tmu(ji,jj+1) + v_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
-               / ztmu
-           ELSE
-            zcmo(ji,jj,7)  = zindb * (  u_ice(ji,jj  ) * tmu(ji,jj) + u_ice(ji-1,jj) * tmu(ji-1,jj) )/ 2.0
-            zcmo(ji,jj,8)  = zindb * (  v_ice(ji,jj  ) * tmv(ji,jj) + v_ice(ji,jj-1) * tmv(ji,jj-1) )/ 2.0
-           ENDIF
-
-          zcmo(ji,jj,9)  = sst_m(ji,jj)
-          zcmo(ji,jj,10) = sss_m(ji,jj)
-
-          zcmo(ji,jj,11) = qns(ji,jj) + qsr(ji,jj)
-          zcmo(ji,jj,12) = qsr(ji,jj)
-          zcmo(ji,jj,13) = qns(ji,jj)
-          ! See thersf for the coefficient
-          zcmo(ji,jj,14) = - sfx (ji,jj) * rday * ( sss_m(ji,jj) + epsi16 ) / soce
-          zcmo(ji,jj,15) = utau_ice(ji,jj)
-          zcmo(ji,jj,16) = vtau_ice(ji,jj)
-          zcmo(ji,jj,17) = qsr_ice(ji,jj,1)
-          zcmo(ji,jj,18) = qns_ice(ji,jj,1)
-          zcmo(ji,jj,19) = sprecip(ji,jj)
-       END DO
-    END DO
-    ! Cumulates values between outputs           
-    rcmoy(:,:,:)= rcmoy(:,:,:) + zcmo(:,:,:)
-    nmoyice = nmoyice + 1 
-    ! compute mean value if it is time to write on file
-    IF ( MOD(kt+nn_fsbc-1-nit000+1,nwrite) == 0 ) THEN
-       rcmoy(:,:,:) = rcmoy(:,:,:) / FLOAT(nmoyice)
-#else  
-       IF ( MOD(kt-nn_fsbc-1-nit000+1,nwrite) == 0 ) THEN 
-          !  case of instantaneaous output rcmoy(:,:, 1:jpnoumax ) = 0.e0
-          DO jj = 2 , jpjm1
-             DO ji = 2 , jpim1
-                zindh  = MAX( zzero , SIGN( zone , hicif(ji,jj) * (1.0 - frld(ji,jj) ) - 0.10 ) )
-                zinda  = MAX( zzero , SIGN( zone , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
-                zindb  = zindh * zinda
-                rcmoy(ji,jj,1)  = hsnif (ji,jj)
-                rcmoy(ji,jj,2)  = hicif (ji,jj)
-                rcmoy(ji,jj,3)  = hicifp(ji,jj)
-                rcmoy(ji,jj,4)  = frld  (ji,jj)
-                rcmoy(ji,jj,5)  = sist  (ji,jj)
-                rcmoy(ji,jj,6)  = fbif  (ji,jj)
-                IF (lk_lim2_vp) THEN
-                   ztmu   = MAX( 0.5 * zone , ( tmu(ji,jj) + tmu(ji+1,jj) + tmu(ji,jj+1) + tmu(ji+1,jj+1) ) )
-                   rcmoy(ji,jj,7)  = zindb * (  u_ice(ji,jj  ) * tmu(ji,jj  ) + u_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
-                      &                      + u_ice(ji,jj+1) * tmu(ji,jj+1) + u_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
-                        / ztmu
-
-                   rcmoy(ji,jj,8)  = zindb * (  v_ice(ji,jj  ) * tmu(ji,jj  ) + v_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
-                      &                      + v_ice(ji,jj+1) * tmu(ji,jj+1) + v_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
-                       / ztmu
-                ELSE
-                   rcmoy(ji,jj,7)  = zindb * (  u_ice(ji,jj  ) * tmu(ji,jj) + u_ice(ji-1,jj) * tmu(ji-1,jj) )/ 2.0
-                   rcmoy(ji,jj,8)  = zindb * (  v_ice(ji,jj  ) * tmv(ji,jj) + v_ice(ji,jj-1) * tmv(ji,jj-1) )/ 2.0
-                ENDIF
-                rcmoy(ji,jj,9)  = sst_m(ji,jj)
-                rcmoy(ji,jj,10) = sss_m(ji,jj)
-
-                rcmoy(ji,jj,11) = qns(ji,jj) + qsr(ji,jj)
-                rcmoy(ji,jj,12) = qsr(ji,jj)
-                rcmoy(ji,jj,13) = qns(ji,jj)
-                ! See thersf for the coefficient
-                rcmoy(ji,jj,14) = - sfx (ji,jj) * rday * ( sss_m(ji,jj) + epsi16 ) / soce
-                rcmoy(ji,jj,15) = utau_ice(ji,jj)
-                rcmoy(ji,jj,16) = vtau_ice(ji,jj)
-                rcmoy(ji,jj,17) = qsr_ice(ji,jj,1)
-                rcmoy(ji,jj,18) = qns_ice(ji,jj,1)
-                rcmoy(ji,jj,19) = sprecip(ji,jj)
-             END DO
-          END DO
-#endif
-
-          !
-          niter = niter + 1
-          DO jf = 1 , noumef
-             zfield(:,:) = (rcmoy(:,:,jf) * cmulti(jf) + cadd(jf)) * tmask(:,:,1)
-
-             SELECT CASE (jf) 
-             CASE ( 7, 8, 15, 16 ) ! velocity or stress fields (vectors)
-                CALL lbc_lnk( zfield, 'T', -1. )
-             CASE DEFAULT          ! scalar fields
-                CALL lbc_lnk( zfield, 'T',  1. )
-             END SELECT
-             rcmoy(:,:,jf) = zfield(:,:)
-          END DO
-
-          IF (ll_dia_inst) THEN
-           clmode='instantaneous'
-          ELSE
-           WRITE(clmode,'(f5.1,a)' ) nwrite*rdt/86400.,' days average'
-          END IF
-          iyear = ndastp/10000
-          imon = (ndastp-iyear*10000)/100
-          iday = ndastp - imon*100 - iyear*10000
-          WRITE(clname,9000) TRIM(cexper),'ICEMOD',iyear,imon,iday
-          cltext=TRIM(cexper)//' ice modele output'//TRIM(clmode)
-          CALL dia_wri_dimg (clname, cltext, rcmoy, nwf , 'I', nsubindex)
-9000      FORMAT(a,"_",a,"_y",i4.4,"m",i2.2,"d",i2.2,".dimgproc")
-
-          rcmoy(:,:,:) = 0.0
-          nmoyice = 0 
-       END IF     !  MOD(kt+nn_fsbc-1-nit000+1, nwrite == 0 ) !
-       CALL wrk_dealloc( jpi,jpj, zfield )
-
-     END SUBROUTINE lim_wri_2
Index: /trunk/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 6140)
@@ -28,4 +28,6 @@
    USE lib_fortran      ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
    USE wrk_nemo         ! work arrays
+   USE fldread          ! read input fields
+   USE iom
 
    IMPLICIT NONE
@@ -47,5 +49,15 @@
    REAL(wp) ::   rn_tmi_ini_s   ! initial temperature
 
-   LOGICAL  ::  ln_iceini    ! initialization or not
+   INTEGER , PARAMETER ::   jpfldi = 6           ! maximum number of files to read
+   INTEGER , PARAMETER ::   jp_hti = 1           ! index of ice thickness (m)    at T-point
+   INTEGER , PARAMETER ::   jp_hts = 2           ! index of snow thicknes (m)    at T-point
+   INTEGER , PARAMETER ::   jp_ati = 3           ! index of ice fraction (%) at T-point
+   INTEGER , PARAMETER ::   jp_tsu = 4           ! index of ice surface temp (K)    at T-point
+   INTEGER , PARAMETER ::   jp_tmi = 5           ! index of ice temp at T-point
+   INTEGER , PARAMETER ::   jp_smi = 6           ! index of ice sali at T-point
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   si    ! structure of input fields (file informations, fields read)
+
+   LOGICAL  ::  ln_iceini        ! initialization or not
+   LOGICAL  ::  ln_iceini_file   ! Ice initialization state from 2D netcdf file
    !!----------------------------------------------------------------------
    !!   LIM 3.0,  UCL-LOCEAN-IPSL (2008)
@@ -88,15 +100,14 @@
       REAL(wp)   :: ztmelts, zdh
       INTEGER    :: i_hemis, i_fill, jl0  
-      REAL(wp)   :: ztest_1, ztest_2, ztest_3, ztest_4, ztests, zsigma, zarg, zA, zV, zA_cons, zV_cons, zconv
-      REAL(wp), POINTER, DIMENSION(:)     :: zht_i_ini, zat_i_ini, zvt_i_ini, zht_s_ini, zsm_i_ini, ztm_i_ini
-      REAL(wp), POINTER, DIMENSION(:,:)   :: zh_i_ini, za_i_ini, zv_i_ini
+      REAL(wp)   :: ztest_1, ztest_2, ztest_3, ztest_4, ztests, zsigma, zarg, zA, zV, zA_cons, zV_cons, zconv 
       REAL(wp), POINTER, DIMENSION(:,:)   :: zswitch    ! ice indicator
-      INTEGER,  POINTER, DIMENSION(:,:)   :: zhemis   ! hemispheric index
-      !--------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zswitch )
-      CALL wrk_alloc( jpi, jpj, zhemis )
-      CALL wrk_alloc( jpl,   2, zh_i_ini,  za_i_ini,  zv_i_ini )
-      CALL wrk_alloc(   2,      zht_i_ini, zat_i_ini, zvt_i_ini, zht_s_ini, zsm_i_ini, ztm_i_ini )
+      REAL(wp), POINTER, DIMENSION(:,:)   :: zht_i_ini, zat_i_ini, zvt_i_ini            !data from namelist or nc file
+      REAL(wp), POINTER, DIMENSION(:,:)   :: zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini !data from namelist or nc file
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zh_i_ini, za_i_ini, zv_i_ini               !data by cattegories to fill
+      !--------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, jpl, zh_i_ini,  za_i_ini,  zv_i_ini )
+      CALL wrk_alloc( jpi, jpj,      zht_i_ini, zat_i_ini, zvt_i_ini, zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini )
+      CALL wrk_alloc( jpi, jpj,      zswitch )
 
       IF(lwp) WRITE(numout,*)
@@ -120,263 +131,292 @@
       t_bo(:,:) = ( t_bo(:,:) + rt0 ) * tmask(:,:,1) 
 
+
       IF( ln_iceini ) THEN
 
-      !--------------------------------------------------------------------
-      ! 2) Basal temperature, ice mask and hemispheric index
-      !--------------------------------------------------------------------
-
-      DO jj = 1, jpj                                       ! ice if sst <= t-freez + ttest
-         DO ji = 1, jpi
-            IF( ( sst_m(ji,jj)  - ( t_bo(ji,jj) - rt0 ) ) * tmask(ji,jj,1) >= rn_thres_sst ) THEN 
-               zswitch(ji,jj) = 0._wp * tmask(ji,jj,1)    ! no ice
-            ELSE                                                                                   
-               zswitch(ji,jj) = 1._wp * tmask(ji,jj,1)    !    ice
-            ENDIF
+         !--------------------------------------------------------------------
+         ! 2) Basal temperature, ice mask and hemispheric index
+         !--------------------------------------------------------------------
+
+         DO jj = 1, jpj                                       ! ice if sst <= t-freez + ttest
+            DO ji = 1, jpi
+               IF( ( sst_m(ji,jj)  - ( t_bo(ji,jj) - rt0 ) ) * tmask(ji,jj,1) >= rn_thres_sst ) THEN 
+                  zswitch(ji,jj) = 0._wp * tmask(ji,jj,1)    ! no ice
+               ELSE                                                                                   
+                  zswitch(ji,jj) = 1._wp * tmask(ji,jj,1)    !    ice
+               ENDIF
+            END DO
          END DO
-      END DO
-
-
-      ! Hemispheric index
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( fcor(ji,jj) >= 0._wp ) THEN    
-               zhemis(ji,jj) = 1 ! Northern hemisphere
-            ELSE
-               zhemis(ji,jj) = 2 ! Southern hemisphere
-            ENDIF
-         END DO
-      END DO
-
-      !--------------------------------------------------------------------
-      ! 3) Initialization of sea ice state variables
-      !--------------------------------------------------------------------
-
-      !-----------------------------
-      ! 3.1) Hemisphere-dependent arrays
-      !-----------------------------
-      ! assign initial thickness, concentration, snow depth and salinity to an hemisphere-dependent array
-      zht_i_ini(1) = rn_hti_ini_n ; zht_i_ini(2) = rn_hti_ini_s  ! ice thickness
-      zht_s_ini(1) = rn_hts_ini_n ; zht_s_ini(2) = rn_hts_ini_s  ! snow depth
-      zat_i_ini(1) = rn_ati_ini_n ; zat_i_ini(2) = rn_ati_ini_s  ! ice concentration
-      zsm_i_ini(1) = rn_smi_ini_n ; zsm_i_ini(2) = rn_smi_ini_s  ! bulk ice salinity
-      ztm_i_ini(1) = rn_tmi_ini_n ; ztm_i_ini(2) = rn_tmi_ini_s  ! temperature (ice and snow)
-
-      zvt_i_ini(:) = zht_i_ini(:) * zat_i_ini(:)   ! ice volume
-
-      !---------------------------------------------------------------------
-      ! 3.2) Distribute ice concentration and thickness into the categories
-      !---------------------------------------------------------------------
-      ! a gaussian distribution for ice concentration is used
-      ! then we check whether the distribution fullfills
-      ! volume and area conservation, positivity and ice categories bounds
-      DO i_hemis = 1, 2
-
-      ztest_1 = 0 ; ztest_2 = 0 ; ztest_3 = 0 ; ztest_4 = 0
-
-      ! note for the great nemo engineers: 
-      ! only very few of the WRITE statements are necessary for the reference version
-      ! they were one day useful, but now i personally doubt of their
-      ! potential for bringing anything useful
-
-      DO i_fill = jpl, 1, -1
-         IF ( ( ztest_1 + ztest_2 + ztest_3 + ztest_4 ) .NE. 4 ) THEN
-            !----------------------------
-            ! fill the i_fill categories
-            !----------------------------
-            ! *** 1 category to fill
-            IF ( i_fill .EQ. 1 ) THEN
-               zh_i_ini(1,i_hemis)       = zht_i_ini(i_hemis)
-               za_i_ini(1,i_hemis)       = zat_i_ini(i_hemis)
-               zh_i_ini(2:jpl,i_hemis)   = 0._wp
-               za_i_ini(2:jpl,i_hemis)   = 0._wp
-            ELSE
-
-               ! *** >1 categores to fill
-               !--- Ice thicknesses in the i_fill - 1 first categories
-               DO jl = 1, i_fill - 1
-                  zh_i_ini(jl,i_hemis) = hi_mean(jl)
-               END DO
-               
-               !--- jl0: most likely index where cc will be maximum
-               DO jl = 1, jpl
-                  IF ( ( zht_i_ini(i_hemis) >  hi_max(jl-1) ) .AND. &
-                     & ( zht_i_ini(i_hemis) <= hi_max(jl)   ) ) THEN
-                     jl0 = jl
+
+         !--------------------------------------------------------------------
+         ! 3) Initialization of sea ice state variables
+         !--------------------------------------------------------------------
+         IF( ln_iceini_file )THEN
+
+            zht_i_ini(:,:)  = si(jp_hti)%fnow(:,:,1)
+            zht_s_ini(:,:)  = si(jp_hts)%fnow(:,:,1)
+            zat_i_ini(:,:)  = si(jp_ati)%fnow(:,:,1)
+            zts_u_ini(:,:)  = si(jp_tsu)%fnow(:,:,1)
+            ztm_i_ini(:,:)  = si(jp_tmi)%fnow(:,:,1)
+            zsm_i_ini(:,:)  = si(jp_smi)%fnow(:,:,1)
+
+         ELSE ! ln_iceini_file = F
+
+            !-----------------------------
+            ! 3.1) Hemisphere-dependent arrays
+            !-----------------------------
+            ! assign initial thickness, concentration, snow depth and salinity to an hemisphere-dependent array
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF( fcor(ji,jj) >= 0._wp ) THEN
+                     zht_i_ini(ji,jj) = rn_hti_ini_n
+                     zht_s_ini(ji,jj) = rn_hts_ini_n
+                     zat_i_ini(ji,jj) = rn_ati_ini_n
+                     zts_u_ini(ji,jj) = rn_tmi_ini_n
+                     zsm_i_ini(ji,jj) = rn_smi_ini_n
+                     ztm_i_ini(ji,jj) = rn_tmi_ini_n
+                  ELSE
+                     zht_i_ini(ji,jj) = rn_hti_ini_s
+                     zht_s_ini(ji,jj) = rn_hts_ini_s
+                     zat_i_ini(ji,jj) = rn_ati_ini_s
+                     zts_u_ini(ji,jj) = rn_tmi_ini_s
+                     zsm_i_ini(ji,jj) = rn_smi_ini_s
+                     ztm_i_ini(ji,jj) = rn_tmi_ini_s
                   ENDIF
                END DO
-               jl0 = MIN(jl0, i_fill)
-               
-               !--- Concentrations
-               za_i_ini(jl0,i_hemis)      = zat_i_ini(i_hemis) / SQRT(REAL(jpl))
-               DO jl = 1, i_fill - 1
-                  IF ( jl .NE. jl0 ) THEN
-                     zsigma               = 0.5 * zht_i_ini(i_hemis)
-                     zarg                 = ( zh_i_ini(jl,i_hemis) - zht_i_ini(i_hemis) ) / zsigma
-                     za_i_ini(jl,i_hemis) = za_i_ini(jl0,i_hemis) * EXP(-zarg**2)
-                  ENDIF
-               END DO
-               
-               zA = 0. ! sum of the areas in the jpl categories 
-               DO jl = 1, i_fill - 1
-                 zA = zA + za_i_ini(jl,i_hemis)
-               END DO
-               za_i_ini(i_fill,i_hemis)   = zat_i_ini(i_hemis) - zA ! ice conc in the last category
-               IF ( i_fill .LT. jpl ) za_i_ini(i_fill+1:jpl, i_hemis) = 0._wp
-         
-               !--- Ice thickness in the last category
-               zV = 0. ! sum of the volumes of the N-1 categories
-               DO jl = 1, i_fill - 1
-                  zV = zV + za_i_ini(jl,i_hemis)*zh_i_ini(jl,i_hemis)
-               END DO
-               zh_i_ini(i_fill,i_hemis) = ( zvt_i_ini(i_hemis) - zV ) / za_i_ini(i_fill,i_hemis) 
-               IF ( i_fill .LT. jpl ) zh_i_ini(i_fill+1:jpl, i_hemis) = 0._wp
-
-               !--- volumes
-               zv_i_ini(:,i_hemis) = za_i_ini(:,i_hemis) * zh_i_ini(:,i_hemis)
-               IF ( i_fill .LT. jpl ) zv_i_ini(i_fill+1:jpl, i_hemis) = 0._wp
-
-            ENDIF ! i_fill
-
-            !---------------------
-            ! Compatibility tests
-            !---------------------
-            ! Test 1: area conservation
-            zA_cons = SUM(za_i_ini(:,i_hemis)) ; zconv = ABS(zat_i_ini(i_hemis) - zA_cons )
-            IF ( zconv .LT. 1.0e-6 ) THEN
-               ztest_1 = 1
-            ELSE 
-              ! this write is useful
-              IF(lwp)  WRITE(numout,*) ' * TEST1 AREA NOT CONSERVED *** zA_cons = ', zA_cons,' zat_i_ini = ',zat_i_ini(i_hemis) 
-               ztest_1 = 0
-            ENDIF
-
-            ! Test 2: volume conservation
-            zV_cons = SUM(zv_i_ini(:,i_hemis))
-            zconv = ABS(zvt_i_ini(i_hemis) - zV_cons)
-
-            IF ( zconv .LT. 1.0e-6 ) THEN
-               ztest_2 = 1
-            ELSE
-              ! this write is useful
-              IF(lwp)  WRITE(numout,*) ' * TEST2 VOLUME NOT CONSERVED *** zV_cons = ', zV_cons, &
-                            ' zvt_i_ini = ', zvt_i_ini(i_hemis)
-               ztest_2 = 0
-            ENDIF
-
-            ! Test 3: thickness of the last category is in-bounds ?
-            IF ( zh_i_ini(i_fill, i_hemis) > hi_max(i_fill-1) ) THEN
-               ztest_3 = 1
-            ELSE
-               ! this write is useful
-               IF(lwp) WRITE(numout,*) ' * TEST 3 THICKNESS OF THE LAST CATEGORY OUT OF BOUNDS *** zh_i_ini(i_fill,i_hemis) = ', &
-               zh_i_ini(i_fill,i_hemis), ' hi_max(jpl-1) = ', hi_max(i_fill-1)
-               ztest_3 = 0
-            ENDIF
-
-            ! Test 4: positivity of ice concentrations
-            ztest_4 = 1
-            DO jl = 1, jpl
-               IF ( za_i_ini(jl,i_hemis) .LT. 0._wp ) THEN 
-                  ! this write is useful
-                  IF(lwp) WRITE(numout,*) ' * TEST 4 POSITIVITY NOT OK FOR CAT ', jl, ' WITH A = ', za_i_ini(jl,i_hemis)
-                  ztest_4 = 0
-               ENDIF
-            END DO
-
-         ENDIF ! ztest_1 + ztest_2 + ztest_3 + ztest_4
- 
-         ztests = ztest_1 + ztest_2 + ztest_3 + ztest_4
-
-      END DO ! i_fill
-
-      IF(lwp) THEN 
-         WRITE(numout,*) ' ztests : ', ztests
-         IF ( ztests .NE. 4 ) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) ' !!!! ALERT                  !!! '
-            WRITE(numout,*) ' !!!! Something is wrong in the LIM3 initialization procedure '
-            WRITE(numout,*)
-            WRITE(numout,*) ' *** ztests is not equal to 4 '
-            WRITE(numout,*) ' *** ztest_i (i=1,4) = ', ztest_1, ztest_2, ztest_3, ztest_4
-            WRITE(numout,*) ' zat_i_ini : ', zat_i_ini(i_hemis)
-            WRITE(numout,*) ' zht_i_ini : ', zht_i_ini(i_hemis)
-         ENDIF ! ztests .NE. 4
-      ENDIF
-      
-      END DO ! i_hemis
-
-      !---------------------------------------------------------------------
-      ! 3.3) Space-dependent arrays for ice state variables
-      !---------------------------------------------------------------------
-
-      ! Ice concentration, thickness and volume, ice salinity, ice age, surface temperature
-      DO jl = 1, jpl ! loop over categories
+            END DO
+
+         ENDIF ! ln_iceini_file
+
+         zvt_i_ini(:,:) = zht_i_ini(:,:) * zat_i_ini(:,:)   ! ice volume
+
+         !---------------------------------------------------------------------
+         ! 3.2) Distribute ice concentration and thickness into the categories
+         !---------------------------------------------------------------------
+         ! a gaussian distribution for ice concentration is used
+         ! then we check whether the distribution fullfills
+         ! volume and area conservation, positivity and ice categories bounds
+         zh_i_ini(:,:,:) = 0._wp 
+         za_i_ini(:,:,:) = 0._wp
+         zv_i_ini(:,:,:) = 0._wp
+
          DO jj = 1, jpj
             DO ji = 1, jpi
-               a_i(ji,jj,jl)   = zswitch(ji,jj) * za_i_ini (jl,zhemis(ji,jj))  ! concentration
-               ht_i(ji,jj,jl)  = zswitch(ji,jj) * zh_i_ini(jl,zhemis(ji,jj))   ! ice thickness
-               ht_s(ji,jj,jl)  = ht_i(ji,jj,jl) * ( zht_s_ini( zhemis(ji,jj) ) / zht_i_ini( zhemis(ji,jj) ) )  ! snow depth
-               sm_i(ji,jj,jl)  = zswitch(ji,jj) * zsm_i_ini(zhemis(ji,jj))     ! salinity
-               o_i(ji,jj,jl)   = zswitch(ji,jj) * 1._wp                        ! age (1 day)
-               t_su(ji,jj,jl)  = zswitch(ji,jj) * ztm_i_ini(zhemis(ji,jj)) + ( 1._wp - zswitch(ji,jj) ) * rt0 ! surf temp
-
-               ! This case below should not be used if (ht_s/ht_i) is ok in namelist
-               ! In case snow load is in excess that would lead to transformation from snow to ice
-               ! Then, transfer the snow excess into the ice (different from limthd_dh)
-               zdh = MAX( 0._wp, ( rhosn * ht_s(ji,jj,jl) + ( rhoic - rau0 ) * ht_i(ji,jj,jl) ) * r1_rau0 ) 
-               ! recompute ht_i, ht_s avoiding out of bounds values
-               ht_i(ji,jj,jl) = MIN( hi_max(jl), ht_i(ji,jj,jl) + zdh )
-               ht_s(ji,jj,jl) = MAX( 0._wp, ht_s(ji,jj,jl) - zdh * rhoic * r1_rhosn )
-
-               ! ice volume, salt content, age content
-               v_i(ji,jj,jl)   = ht_i(ji,jj,jl) * a_i(ji,jj,jl)              ! ice volume
-               v_s(ji,jj,jl)   = ht_s(ji,jj,jl) * a_i(ji,jj,jl)              ! snow volume
-               smv_i(ji,jj,jl) = MIN( sm_i(ji,jj,jl) , sss_m(ji,jj) ) * v_i(ji,jj,jl) ! salt content
-               oa_i(ji,jj,jl)  = o_i(ji,jj,jl) * a_i(ji,jj,jl)               ! age content
-            END DO
-         END DO
-      END DO
-
-      ! Snow temperature and heat content
-      DO jk = 1, nlay_s
+
+               IF( zat_i_ini(ji,jj) > 0._wp .AND. zht_i_ini(ji,jj) > 0._wp )THEN
+
+                  ztest_1 = 0 ; ztest_2 = 0 ; ztest_3 = 0 ; ztest_4 = 0
+!                  ztests  = 0 
+
+                  DO i_fill = jpl, 1, -1
+
+!                     IF( ztests .NE. 4 ) THEN
+                     IF ( ( ztest_1 + ztest_2 + ztest_3 + ztest_4 ) .NE. 4 ) THEN
+                        !----------------------------
+                        ! fill the i_fill categories
+                        !----------------------------
+                        ! *** 1 category to fill
+                        IF ( i_fill .EQ. 1 ) THEN
+                           zh_i_ini(ji,jj,    1)   = zht_i_ini(ji,jj)
+                           za_i_ini(ji,jj,    1)   = zat_i_ini(ji,jj)
+                           zh_i_ini(ji,jj,2:jpl)   = 0._wp
+                           za_i_ini(ji,jj,2:jpl)   = 0._wp
+                        ELSE
+
+                           ! *** >1 categores to fill
+                           !--- Ice thicknesses in the i_fill - 1 first categories
+                           DO jl = 1, i_fill - 1
+                              zh_i_ini(ji,jj,jl) = hi_mean(jl)
+                           END DO
+               
+                           !--- jl0: most likely index where cc will be maximum
+                           DO jl = 1, jpl
+                              IF ( ( zht_i_ini(ji,jj) >  hi_max(jl-1) ) .AND. &
+                                 & ( zht_i_ini(ji,jj) <= hi_max(jl)   ) ) THEN
+                                 jl0 = jl
+                              ENDIF
+                           END DO
+                           jl0 = MIN(jl0, i_fill)
+               
+                           !--- Concentrations
+                           za_i_ini(ji,jj,jl0) = zat_i_ini(ji,jj) / SQRT(REAL(jpl))
+                           DO jl = 1, i_fill - 1
+                              IF( jl .NE. jl0 )THEN
+                                 zsigma             = 0.5 * zht_i_ini(ji,jj)
+                                 zarg               = ( zh_i_ini(ji,jj,jl) - zht_i_ini(ji,jj) ) / zsigma
+                                 za_i_ini(ji,jj,jl) = za_i_ini(ji,jj,jl0) * EXP(-zarg**2)
+                              ENDIF
+                           END DO
+               
+                           zA = 0. ! sum of the areas in the jpl categories 
+                           DO jl = 1, i_fill - 1
+                              zA = zA + za_i_ini(ji,jj,jl)
+                           END DO
+                           za_i_ini(ji,jj,i_fill)   = zat_i_ini(ji,jj) - zA ! ice conc in the last category
+                           IF ( i_fill .LT. jpl ) za_i_ini(ji,jj,i_fill+1:jpl) = 0._wp
+         
+                           !--- Ice thickness in the last category
+                           zV = 0. ! sum of the volumes of the N-1 categories
+                           DO jl = 1, i_fill - 1
+                              zV = zV + za_i_ini(ji,jj,jl)*zh_i_ini(ji,jj,jl)
+                           END DO
+                           zh_i_ini(ji,jj,i_fill) = ( zvt_i_ini(ji,jj) - zV ) / za_i_ini(ji,jj,i_fill) 
+                           IF ( i_fill .LT. jpl ) zh_i_ini(ji,jj,i_fill+1:jpl) = 0._wp
+
+                           !--- volumes
+                           zv_i_ini(ji,jj,:) = za_i_ini(ji,jj,:) * zh_i_ini(ji,jj,:)
+                           IF ( i_fill .LT. jpl ) zv_i_ini(ji,jj,i_fill+1:jpl) = 0._wp
+
+                        ENDIF ! i_fill
+
+                        !---------------------
+                        ! Compatibility tests
+                        !---------------------
+                        ! Test 1: area conservation
+                        zA_cons = SUM(za_i_ini(ji,jj,:)) ; zconv = ABS(zat_i_ini(ji,jj) - zA_cons )
+                        IF ( zconv .LT. 1.0e-6 ) THEN
+                           ztest_1 = 1
+                        ELSE 
+                          !this write is useful
+                          IF(lwp)  WRITE(numout,*) ' * TEST1 AREA NOT CONSERVED *** zA_cons = ', zA_cons,' zat_i_ini = ',zat_i_ini(ji,jj) 
+                          ztest_1 = 0
+                        ENDIF
+
+                        ! Test 2: volume conservation
+                        zV_cons = SUM(zv_i_ini(ji,jj,:))
+                        zconv = ABS(zvt_i_ini(ji,jj) - zV_cons)
+
+                        IF( zconv .LT. 1.0e-6 ) THEN
+                           ztest_2 = 1
+                        ELSE
+                           !this write is useful
+                           IF(lwp)  WRITE(numout,*) ' * TEST2 VOLUME NOT CONSERVED *** zV_cons = ', zV_cons, &
+                                                    ' zvt_i_ini = ', zvt_i_ini(ji,jj)
+                           ztest_2 = 0
+                        ENDIF
+
+                        ! Test 3: thickness of the last category is in-bounds ?
+                        IF ( zh_i_ini(ji,jj,i_fill) > hi_max(i_fill-1) ) THEN
+                           ztest_3 = 1
+                        ELSE
+                           ! this write is useful
+                           IF(lwp) WRITE(numout,*) ' * TEST 3 THICKNESS OF THE LAST CATEGORY OUT OF BOUNDS *** zh_i_ini(ji,jj,i_fill) = ', &
+                           zh_i_ini(ji,jj,i_fill), ' hi_max(jpl-1) = ', hi_max(i_fill-1)
+                           IF(lwp) WRITE(numout,*) ' ji,jj,i_fill ',ji,jj,i_fill
+                           IF(lwp) WRITE(numout,*) 'zht_i_ini ',zht_i_ini(ji,jj)
+                           ztest_3 = 0
+                        ENDIF
+
+                        ! Test 4: positivity of ice concentrations
+                        ztest_4 = 1
+                        DO jl = 1, jpl
+                           IF ( za_i_ini(ji,jj,jl) .LT. 0._wp ) THEN 
+                              ! this write is useful
+                              IF(lwp) WRITE(numout,*) ' * TEST 4 POSITIVITY NOT OK FOR CAT ', jl, ' WITH A = ', za_i_ini(ji,jj,jl)
+                              ztest_4 = 0
+                           ENDIF
+                        END DO
+
+                     ENDIF ! ztest_1 + ztest_2 + ztest_3 + ztest_4
+ 
+                     ztests = ztest_1 + ztest_2 + ztest_3 + ztest_4
+
+                  END DO ! i_fill
+
+                  IF(lwp) THEN 
+                     WRITE(numout,*) ' ztests : ', ztests
+                     IF( ztests .NE. 4 )THEN
+                        WRITE(numout,*)
+                        WRITE(numout,*) ' !!!! ALERT                  !!! '
+                        WRITE(numout,*) ' !!!! Something is wrong in the LIM3 initialization procedure '
+                        WRITE(numout,*)
+                        WRITE(numout,*) ' *** ztests is not equal to 4 '
+                        WRITE(numout,*) ' *** ztest_i (i=1,4) = ', ztest_1, ztest_2, ztest_3, ztest_4
+                        WRITE(numout,*) ' zat_i_ini : ', zat_i_ini(ji,jj)
+                        WRITE(numout,*) ' zht_i_ini : ', zht_i_ini(ji,jj)
+                     ENDIF ! ztests .NE. 4
+                  ENDIF
+      
+               ENDIF !  zat_i_ini(ji,jj) > 0._wp .AND. zhm_i_ini(ji,jj) > 0._wp
+
+            ENDDO   
+         ENDDO   
+
+         !---------------------------------------------------------------------
+         ! 3.3) Space-dependent arrays for ice state variables
+         !---------------------------------------------------------------------
+
+         ! Ice concentration, thickness and volume, ice salinity, ice age, surface temperature
          DO jl = 1, jpl ! loop over categories
             DO jj = 1, jpj
                DO ji = 1, jpi
-                   t_s(ji,jj,jk,jl) = zswitch(ji,jj) * ztm_i_ini(zhemis(ji,jj)) + ( 1._wp - zswitch(ji,jj) ) * rt0
-                   ! Snow energy of melting
-                   e_s(ji,jj,jk,jl) = zswitch(ji,jj) * rhosn * ( cpic * ( rt0 - t_s(ji,jj,jk,jl) ) + lfus )
-
-                   ! Mutliply by volume, and divide by number of layers to get heat content in J/m2
-                   e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * v_s(ji,jj,jl) * r1_nlay_s
+                  a_i(ji,jj,jl)   = zswitch(ji,jj) * za_i_ini(ji,jj,jl)                       ! concentration
+                  ht_i(ji,jj,jl)  = zswitch(ji,jj) * zh_i_ini(ji,jj,jl)                       ! ice thickness
+                  sm_i(ji,jj,jl)  = zswitch(ji,jj) * zsm_i_ini(ji,jj)                         ! salinity
+                  o_i(ji,jj,jl)   = zswitch(ji,jj) * 1._wp                                    ! age (1 day)
+                  t_su(ji,jj,jl)  = zswitch(ji,jj) * zts_u_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rt0 ! surf temp
+
+                  IF( zht_i_ini(ji,jj) > 0._wp )THEN
+                    ht_s(ji,jj,jl)= ht_i(ji,jj,jl) * ( zht_s_ini(ji,jj) / zht_i_ini(ji,jj) )  ! snow depth
+                  ELSE
+                    ht_s(ji,jj,jl)= 0._wp
+                  ENDIF
+
+                  ! This case below should not be used if (ht_s/ht_i) is ok in namelist
+                  ! In case snow load is in excess that would lead to transformation from snow to ice
+                  ! Then, transfer the snow excess into the ice (different from limthd_dh)
+                  zdh = MAX( 0._wp, ( rhosn * ht_s(ji,jj,jl) + ( rhoic - rau0 ) * ht_i(ji,jj,jl) ) * r1_rau0 ) 
+                  ! recompute ht_i, ht_s avoiding out of bounds values
+                  ht_i(ji,jj,jl) = MIN( hi_max(jl), ht_i(ji,jj,jl) + zdh )
+                  ht_s(ji,jj,jl) = MAX( 0._wp, ht_s(ji,jj,jl) - zdh * rhoic * r1_rhosn )
+
+                  ! ice volume, salt content, age content
+                  v_i(ji,jj,jl)   = ht_i(ji,jj,jl) * a_i(ji,jj,jl)              ! ice volume
+                  v_s(ji,jj,jl)   = ht_s(ji,jj,jl) * a_i(ji,jj,jl)              ! snow volume
+                  smv_i(ji,jj,jl) = MIN( sm_i(ji,jj,jl) , sss_m(ji,jj) ) * v_i(ji,jj,jl) ! salt content
+                  oa_i(ji,jj,jl)  = o_i(ji,jj,jl) * a_i(ji,jj,jl)               ! age content
                END DO
             END DO
          END DO
-      END DO
-
-      ! Ice salinity, temperature and heat content
-      DO jk = 1, nlay_i
-         DO jl = 1, jpl ! loop over categories
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                   t_i(ji,jj,jk,jl) = zswitch(ji,jj) * ztm_i_ini(zhemis(ji,jj)) + ( 1._wp - zswitch(ji,jj) ) * rt0 
-                   s_i(ji,jj,jk,jl) = zswitch(ji,jj) * zsm_i_ini(zhemis(ji,jj)) !+ ( 1._wp - zswitch(ji,jj) ) * rn_simin
-                   ztmelts          = - tmut * s_i(ji,jj,jk,jl) + rt0 !Melting temperature in K
-
-                   ! heat content per unit volume
-                   e_i(ji,jj,jk,jl) = zswitch(ji,jj) * rhoic * (   cpic    * ( ztmelts - t_i(ji,jj,jk,jl) ) &
-                      +   lfus    * ( 1._wp - (ztmelts-rt0) / MIN((t_i(ji,jj,jk,jl)-rt0),-epsi20) ) &
-                      -   rcp     * ( ztmelts - rt0 ) )
-
-                   ! Mutliply by ice volume, and divide by number of layers to get heat content in J/m2
-                   e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * v_i(ji,jj,jl) * r1_nlay_i
+
+         ! Snow temperature and heat content
+         DO jk = 1, nlay_s
+            DO jl = 1, jpl ! loop over categories
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     t_s(ji,jj,jk,jl) = zswitch(ji,jj) * ztm_i_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rt0
+                     ! Snow energy of melting
+                     e_s(ji,jj,jk,jl) = zswitch(ji,jj) * rhosn * ( cpic * ( rt0 - t_s(ji,jj,jk,jl) ) + lfus )
+
+                     ! Mutliply by volume, and divide by number of layers to get heat content in J/m2
+                     e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * v_s(ji,jj,jl) * r1_nlay_s
+                  END DO
                END DO
             END DO
          END DO
-      END DO
-
-      tn_ice (:,:,:) = t_su (:,:,:)
-
-      ELSE 
-         ! if ln_iceini=false
+
+         ! Ice salinity, temperature and heat content
+         DO jk = 1, nlay_i
+            DO jl = 1, jpl ! loop over categories
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     t_i(ji,jj,jk,jl) = zswitch(ji,jj) * ztm_i_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rt0 
+                     s_i(ji,jj,jk,jl) = zswitch(ji,jj) * zsm_i_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rn_simin
+                     ztmelts          = - tmut * s_i(ji,jj,jk,jl) + rt0 !Melting temperature in K
+
+                     ! heat content per unit volume
+                     e_i(ji,jj,jk,jl) = zswitch(ji,jj) * rhoic * (   cpic    * ( ztmelts - t_i(ji,jj,jk,jl) ) &
+                        +   lfus    * ( 1._wp - (ztmelts-rt0) / MIN((t_i(ji,jj,jk,jl)-rt0),-epsi20) ) &
+                        -   rcp     * ( ztmelts - rt0 ) )
+
+                     ! Mutliply by ice volume, and divide by number of layers to get heat content in J/m2
+                     e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * v_i(ji,jj,jl) * r1_nlay_i
+                  END DO
+               END DO
+            END DO
+         END DO
+
+         tn_ice (:,:,:) = t_su (:,:,:)
+
+      ELSE ! if ln_iceini=false
          a_i  (:,:,:) = 0._wp
          v_i  (:,:,:) = 0._wp
@@ -400,5 +440,5 @@
             END DO
          END DO
-      
+
       ENDIF ! ln_iceini
       
@@ -452,8 +492,7 @@
 
 
-      CALL wrk_dealloc( jpi, jpj, zswitch )
-      CALL wrk_dealloc( jpi, jpj, zhemis )
-      CALL wrk_dealloc( jpl,   2, zh_i_ini,  za_i_ini,  zv_i_ini )
-      CALL wrk_dealloc(   2,      zht_i_ini, zat_i_ini, zvt_i_ini, zht_s_ini, zsm_i_ini, ztm_i_ini )
+      CALL wrk_dealloc( jpi, jpj, jpl, zh_i_ini,  za_i_ini,  zv_i_ini )
+      CALL wrk_dealloc( jpi, jpj,      zht_i_ini, zat_i_ini, zvt_i_ini, zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini )
+      CALL wrk_dealloc( jpi, jpj,      zswitch )
 
    END SUBROUTINE lim_istate
@@ -475,7 +514,17 @@
       !!  8.5  ! 07-11 (M. Vancoppenolle) rewritten initialization
       !!-----------------------------------------------------------------------------
-      NAMELIST/namiceini/ ln_iceini, rn_thres_sst, rn_hts_ini_n, rn_hts_ini_s, rn_hti_ini_n, rn_hti_ini_s,  &
-         &                                      rn_ati_ini_n, rn_ati_ini_s, rn_smi_ini_n, rn_smi_ini_s, rn_tmi_ini_n, rn_tmi_ini_s
-      INTEGER :: ios                 ! Local integer output status for namelist read
+      !
+      INTEGER :: ios,ierr,inum_ice                 ! Local integer output status for namelist read
+      INTEGER :: ji,jj
+      INTEGER :: ifpr, ierror
+      !
+      CHARACTER(len=100) ::  cn_dir          ! Root directory for location of ice files
+      TYPE(FLD_N)                    ::   sn_hti, sn_hts, sn_ati, sn_tsu, sn_tmi, sn_smi
+      TYPE(FLD_N), DIMENSION(jpfldi) ::   slf_i                 ! array of namelist informations on the fields to read
+      !
+      NAMELIST/namiceini/ ln_iceini, ln_iceini_file, rn_thres_sst, rn_hts_ini_n, rn_hts_ini_s,  &
+         &                rn_hti_ini_n, rn_hti_ini_s, rn_ati_ini_n, rn_ati_ini_s, rn_smi_ini_n, &
+         &                rn_smi_ini_s, rn_tmi_ini_n, rn_tmi_ini_s,                             &
+         &                sn_hti, sn_hts, sn_ati, sn_tsu, sn_tmi, sn_smi, cn_dir
       !!-----------------------------------------------------------------------------
       !
@@ -489,4 +538,8 @@
       IF(lwm) WRITE ( numoni, namiceini )
 
+      slf_i(jp_hti) = sn_hti  ;  slf_i(jp_hts) = sn_hts
+      slf_i(jp_ati) = sn_ati  ;  slf_i(jp_tsu) = sn_tsu
+      slf_i(jp_tmi) = sn_tmi  ;  slf_i(jp_smi) = sn_smi
+
       ! Define the initial parameters
       ! -------------------------
@@ -497,4 +550,5 @@
          WRITE(numout,*) '~~~~~~~~~~~~~~~'
          WRITE(numout,*) '   initialization with ice (T) or not (F)       ln_iceini     = ', ln_iceini
+         WRITE(numout,*) '   ice initialization from a netcdf file      ln_iceini_file  = ', ln_iceini_file
          WRITE(numout,*) '   threshold water temp. for initial sea-ice    rn_thres_sst  = ', rn_thres_sst
          WRITE(numout,*) '   initial snow thickness in the north          rn_hts_ini_n  = ', rn_hts_ini_n
@@ -510,4 +564,24 @@
       ENDIF
 
+      IF( ln_iceini_file ) THEN                      ! Ice initialization using input file
+         !
+         ! set si structure
+         ALLOCATE( si(jpfldi), STAT=ierror )
+         IF( ierror > 0 ) THEN
+            CALL ctl_stop( 'Ice_ini in limistate: unable to allocate si structure' )   ;   RETURN
+         ENDIF
+
+         DO ifpr = 1, jpfldi
+            ALLOCATE( si(ifpr)%fnow(jpi,jpj,1) )
+            ALLOCATE( si(ifpr)%fdta(jpi,jpj,1,2) )
+         END DO
+
+         ! fill si with slf_i and control print
+         CALL fld_fill( si, slf_i, cn_dir, 'lim_istate', 'lim istate ini', 'numnam_ice' )
+
+         CALL fld_read( nit000, 1, si )                ! input fields provided at the current time-step
+
+      ENDIF
+
    END SUBROUTINE lim_istate_init
 
Index: /trunk/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90	(revision 6140)
@@ -77,6 +77,4 @@
                WRITE(numout,*)
                SELECT CASE ( jprstlib )
-               CASE ( jprstdimg )
-                  WRITE(numout,*) '             open ice restart binary file: ',TRIM(clpath)//clname
                CASE DEFAULT
                   WRITE(numout,*) '             open ice restart NetCDF file: ',TRIM(clpath)//clname
@@ -331,11 +329,4 @@
       ENDIF
 
-      IF ( jprstlib == jprstdimg ) THEN
-        ! eventually read netcdf file (monobloc)  for restarting on different number of processors
-        ! if {cn_icerst_in}.nc exists, then set jlibalt to jpnf90
-        INQUIRE( FILE = TRIM(cn_icerst_indir)//'/'//TRIM(cn_icerst_in)//'.nc', EXIST = llok )
-        IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
-      ENDIF
-
       CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kiolib = jprstlib )
 
Index: /trunk/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90	(revision 6140)
@@ -23,29 +23,30 @@
    !!   lim_sbc_tau   : update i- and j-stresses, and its modulus at the ocean surface
    !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE phycst           ! physical constants
-   USE dom_oce          ! ocean domain
-   USE ice              ! LIM sea-ice variables
-   USE sbc_ice          ! Surface boundary condition: sea-ice fields
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE sbccpl
-   USE oce       , ONLY : sshn, sshb, snwice_mass, snwice_mass_b, snwice_fmass
-   USE albedo           ! albedo parameters
-   USE lbclnk           ! ocean lateral boundary condition - MPP exchanges
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE in_out_manager   ! I/O manager
-   USE prtctl           ! Print control
-   USE lib_fortran      ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE traqsr           ! add penetration of solar flux in the calculation of heat budget
-   USE iom
-   USE domvvl           ! Variable volume
-   USE limctl
-   USE limcons
+   USE par_oce        ! ocean parameters
+   USE oce     , ONLY : sshn, sshb, snwice_mass, snwice_mass_b, snwice_fmass
+   USE phycst         ! physical constants
+   USE dom_oce        ! ocean domain
+   USE ice            ! LIM sea-ice variables
+   USE sbc_ice        ! Surface boundary condition: sea-ice fields
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE sbccpl         ! Surface boundary condition: coupled interface
+   USE albedo         ! albedo parameters
+   USE traqsr         ! add penetration of solar flux in the calculation of heat budget
+   USE domvvl         ! Variable volume
+   USE limctl         ! 
+   USE limcons        ! 
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! xIO server
+   USE lbclnk         ! ocean lateral boundary condition - MPP exchanges
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! work arrays
+   USE prtctl         ! Print control
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   lim_sbc_init   ! called by sbc_lim_init
+   PUBLIC   lim_sbc_init   ! called by sbcice_lim
    PUBLIC   lim_sbc_flx    ! called by sbc_ice_lim
    PUBLIC   lim_sbc_tau    ! called by sbc_ice_lim
@@ -57,5 +58,4 @@
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
@@ -101,12 +101,12 @@
       !!              The ref should be Rousset et al., 2015
       !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt                                  ! number of iteration
-      INTEGER  ::   ji, jj, jl, jk                                 ! dummy loop indices
-      REAL(wp) ::   zqmass                                         ! Heat flux associated with mass exchange ice->ocean (W.m-2)
-      REAL(wp) ::   zqsr                                           ! New solar flux received by the ocean
-      !
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zalb_cs, zalb_os     ! 2D/3D workspace
+      INTEGER, INTENT(in) ::   kt   ! number of iteration
+      !
+      INTEGER  ::   ji, jj, jl, jk   ! dummy loop indices
+      REAL(wp) ::   zqmass           ! Heat flux associated with mass exchange ice->ocean (W.m-2)
+      REAL(wp) ::   zqsr             ! New solar flux received by the ocean
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zalb_cs, zalb_os     ! 3D workspace
       !!---------------------------------------------------------------------
-
+      !
       ! make calls for heat fluxes before it is modified
       IF( iom_use('qsr_oce') )   CALL iom_put( "qsr_oce" , qsr_oce(:,:) * pfrld(:,:) )                                   !     solar flux at ocean surface
@@ -198,15 +198,15 @@
       !    Snow/ice albedo (only if sent to coupler, useless in forced mode)   !
       !------------------------------------------------------------------------!
-      CALL wrk_alloc( jpi, jpj, jpl, zalb_cs, zalb_os )    
+      CALL wrk_alloc( jpi,jpj,jpl,   zalb_cs, zalb_os )    
       CALL albedo_ice( t_su, ht_i, ht_s, zalb_cs, zalb_os )  ! cloud-sky and overcast-sky ice albedos
       alb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
-      CALL wrk_dealloc( jpi, jpj, jpl, zalb_cs, zalb_os )
+      CALL wrk_dealloc( jpi,jpj,jpl,   zalb_cs, zalb_os )
 
       ! conservation test
-      IF( ln_limdiahsb ) CALL lim_cons_final( 'limsbc' )
+      IF( ln_limdiahsb )   CALL lim_cons_final( 'limsbc' )
 
       ! control prints
       IF( ln_icectl )   CALL lim_prt( kt, iiceprt, jiceprt, 3, ' - Final state lim_sbc - ' )
-
+      !
       IF(ln_ctl) THEN
          CALL prt_ctl( tab2d_1=qsr   , clinfo1=' lim_sbc: qsr    : ', tab2d_2=qns , clinfo2=' qns     : ' )
@@ -215,5 +215,5 @@
          CALL prt_ctl( tab3d_1=tn_ice, clinfo1=' lim_sbc: tn_ice : ', kdim=jpl )
       ENDIF
-
+      !
    END SUBROUTINE lim_sbc_flx
 
@@ -246,5 +246,5 @@
       INTEGER ,                     INTENT(in) ::   kt               ! ocean time-step index
       REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pu_oce, pv_oce   ! surface ocean currents
-      !!
+      !
       INTEGER  ::   ji, jj   ! dummy loop indices
       REAL(wp) ::   zat_u, zutau_ice, zu_t, zmodt   ! local scalar
@@ -303,6 +303,8 @@
       !! ** input   : Namelist namicedia
       !!-------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk                       ! dummy loop indices
-      REAL(wp) ::   zcoefu, zcoefv, zcoeff          ! local scalar
+      INTEGER  ::   ji, jj, jk               ! dummy loop indices
+      REAL(wp) ::   zcoefu, zcoefv, zcoeff   ! local scalar
+      !!-------------------------------------------------------------------
+      !
       IF(lwp) WRITE(numout,*)
       IF(lwp) WRITE(numout,*) 'lim_sbc_init : LIM-3 sea-ice - surface boundary condition'
@@ -335,43 +337,44 @@
             sshn(:,:) = sshn(:,:) - snwice_mass(:,:) * r1_rau0
             sshb(:,:) = sshb(:,:) - snwice_mass(:,:) * r1_rau0
-#if defined key_vvl            
-           ! key_vvl necessary? clem: yes for compilation purpose
-            DO jk = 1,jpkm1                     ! adjust initial vertical scale factors
-               fse3t_n(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshn(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
-               fse3t_b(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshb(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
-            ENDDO
-            fse3t_a(:,:,:) = fse3t_b(:,:,:)
-            ! Reconstruction of all vertical scale factors at now and before time
-            ! steps
-            ! =============================================================================
-            ! Horizontal scale factor interpolations
-            ! --------------------------------------
-            CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3u_b(:,:,:), 'U' )
-            CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3v_b(:,:,:), 'V' )
-            CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3u_n(:,:,:), 'U' )
-            CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3v_n(:,:,:), 'V' )
-            CALL dom_vvl_interpol( fse3u_n(:,:,:), fse3f_n(:,:,:), 'F' )
-            ! Vertical scale factor interpolations
-            ! ------------------------------------
-            CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3w_n (:,:,:), 'W'  )
-            CALL dom_vvl_interpol( fse3u_n(:,:,:), fse3uw_n(:,:,:), 'UW' )
-            CALL dom_vvl_interpol( fse3v_n(:,:,:), fse3vw_n(:,:,:), 'VW' )
-            CALL dom_vvl_interpol( fse3u_b(:,:,:), fse3uw_b(:,:,:), 'UW' )
-            CALL dom_vvl_interpol( fse3v_b(:,:,:), fse3vw_b(:,:,:), 'VW' )
-            ! t- and w- points depth
-            ! ----------------------
-            fsdept_n(:,:,1) = 0.5_wp * fse3w_n(:,:,1)
-            fsdepw_n(:,:,1) = 0.0_wp
-            fsde3w_n(:,:,1) = fsdept_n(:,:,1) - sshn(:,:)
-            DO jk = 2, jpk
-               fsdept_n(:,:,jk) = fsdept_n(:,:,jk-1) + fse3w_n(:,:,jk)
-               fsdepw_n(:,:,jk) = fsdepw_n(:,:,jk-1) + fse3t_n(:,:,jk-1)
-               fsde3w_n(:,:,jk) = fsdept_n(:,:,jk  ) - sshn   (:,:)
-            END DO
-#endif
+
+!!gm I really don't like this staff here...  Find a way to put that elsewhere or differently
+!!gm
+            IF( .NOT.ln_linssh ) THEN
+               DO jk = 1,jpkm1                     ! adjust initial vertical scale factors
+                  e3t_n(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshn(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
+                  e3t_b(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshb(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
+               END DO
+               e3t_a(:,:,:) = e3t_b(:,:,:)
+               ! Reconstruction of all vertical scale factors at now and before time-steps
+               ! =========================================================================
+               ! Horizontal scale factor interpolations
+               ! --------------------------------------
+               CALL dom_vvl_interpol( e3t_b(:,:,:), e3u_b(:,:,:), 'U' )
+               CALL dom_vvl_interpol( e3t_b(:,:,:), e3v_b(:,:,:), 'V' )
+               CALL dom_vvl_interpol( e3t_n(:,:,:), e3u_n(:,:,:), 'U' )
+               CALL dom_vvl_interpol( e3t_n(:,:,:), e3v_n(:,:,:), 'V' )
+               CALL dom_vvl_interpol( e3u_n(:,:,:), e3f_n(:,:,:), 'F' )
+               ! Vertical scale factor interpolations
+                 ! ------------------------------------
+               CALL dom_vvl_interpol( e3t_n(:,:,:), e3w_n (:,:,:), 'W'  )
+               CALL dom_vvl_interpol( e3u_n(:,:,:), e3uw_n(:,:,:), 'UW' )
+               CALL dom_vvl_interpol( e3v_n(:,:,:), e3vw_n(:,:,:), 'VW' )
+               CALL dom_vvl_interpol( e3u_b(:,:,:), e3uw_b(:,:,:), 'UW' )
+               CALL dom_vvl_interpol( e3v_b(:,:,:), e3vw_b(:,:,:), 'VW' )
+               ! t- and w- points depth
+               ! ----------------------
+!!gm not sure of that....
+               gdept_n(:,:,1) = 0.5_wp * e3w_n(:,:,1)
+               gdepw_n(:,:,1) = 0.0_wp
+               gde3w_n(:,:,1) = gdept_n(:,:,1) - sshn(:,:)
+               DO jk = 2, jpk
+                  gdept_n(:,:,jk) = gdept_n(:,:,jk-1) + e3w_n(:,:,jk)
+                  gdepw_n(:,:,jk) = gdepw_n(:,:,jk-1) + e3t_n(:,:,jk-1)
+                  gde3w_n(:,:,jk) = gdept_n(:,:,jk  ) - sshn   (:,:)
+               END DO
+            ENDIF
          ENDIF
       ENDIF ! .NOT. ln_rstart
       !
-
    END SUBROUTINE lim_sbc_init
 
Index: /trunk/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 6140)
@@ -25,23 +25,24 @@
    USE sbc_oce        ! Surface boundary condition: ocean fields
    USE sbc_ice        ! Surface boundary condition: ice fields
-   USE thd_ice        ! LIM thermodynamic sea-ice variables
-   USE dom_ice        ! LIM sea-ice domain
+   USE dom_ice        ! LIM: sea-ice domain
+   USE thd_ice        ! LIM: thermodynamic sea-ice variables
    USE limthd_dif     ! LIM: thermodynamics, vertical diffusion
    USE limthd_dh      ! LIM: thermodynamics, ice and snow thickness variation
    USE limthd_sal     ! LIM: thermodynamics, ice salinity
    USE limthd_ent     ! LIM: thermodynamics, ice enthalpy redistribution
-   USE limthd_lac     ! LIM-3 lateral accretion
-   USE limitd_th      ! remapping thickness distribution
+   USE limthd_lac     ! LIM: lateral accretion
+   USE limitd_th      ! LIM: remapping thickness distribution
    USE limtab         ! LIM: 1D <==> 2D transformation
    USE limvar         ! LIM: sea-ice variables
+   USE limcons        ! LIM: conservation tests
+   USE limctl         ! LIM: control print
+   !
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
    USE lbclnk         ! lateral boundary condition - MPP links
    USE lib_mpp        ! MPP library
    USE wrk_nemo       ! work arrays
-   USE in_out_manager ! I/O manager
-   USE prtctl         ! Print control
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
    USE timing         ! Timing
-   USE limcons        ! conservation tests
-   USE limctl
 
    IMPLICIT NONE
@@ -52,5 +53,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -81,19 +81,17 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) :: kt    ! number of iteration
-      !!
+      !
       INTEGER  :: ji, jj, jk, jl   ! dummy loop indices
       INTEGER  :: nbpb             ! nb of icy pts for vertical thermo calculations
-      INTEGER  :: ii, ij           ! temporary dummy loop index
       REAL(wp) :: zfric_u, zqld, zqfr
       REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
       REAL(wp), PARAMETER :: zfric_umin = 0._wp           ! lower bound for the friction velocity (cice value=5.e-04)
       REAL(wp), PARAMETER :: zch        = 0.0057_wp       ! heat transfer coefficient
-      !
       !!-------------------------------------------------------------------
 
-      IF( nn_timing == 1 )  CALL timing_start('limthd')
+      IF( nn_timing == 1 )   CALL timing_start('limthd')
 
       ! conservation test
-      IF( ln_limdiahsb ) CALL lim_cons_hsm(0, 'limthd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      IF( ln_limdiahsb )   CALL lim_cons_hsm( 0, 'limthd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b )
 
       CALL lim_var_glo2eqv
@@ -147,5 +145,5 @@
 
             ! --- Energy needed to bring ocean surface layer until its freezing (<0, J.m-2) --- !
-            zqfr = tmask(ji,jj,1) * rau0 * rcp * fse3t_m(ji,jj) * ( t_bo(ji,jj) - ( sst_m(ji,jj) + rt0 ) )
+            zqfr = tmask(ji,jj,1) * rau0 * rcp * e3t_m(ji,jj) * ( t_bo(ji,jj) - ( sst_m(ji,jj) + rt0 ) )
 
             ! --- Energy from the turbulent oceanic heat flux (W/m2) --- !
@@ -226,47 +224,25 @@
 
          IF( nbpb > 0 ) THEN  ! If there is no ice, do nothing.
-
-            !-------------------------!
-            ! --- Move to 1D arrays ---
-            !-------------------------!
-            CALL lim_thd_1d2d( nbpb, jl, 1 )
-
-            !--------------------------------------!
-            ! --- Ice/Snow Temperature profile --- !
-            !--------------------------------------!
-            CALL lim_thd_dif( 1, nbpb )
-
-            !---------------------------------!
-            ! --- Ice/Snow thickness ---      !
-            !---------------------------------!
-            CALL lim_thd_dh( 1, nbpb )    
-
-            ! --- Ice enthalpy remapping --- !
-            CALL lim_thd_ent( 1, nbpb, q_i_1d(1:nbpb,:) ) 
-                                            
-            !---------------------------------!
-            ! --- Ice salinity ---            !
-            !---------------------------------!
-            CALL lim_thd_sal( 1, nbpb )    
-
-            !---------------------------------!
-            ! --- temperature update ---      !
-            !---------------------------------!
-            CALL lim_thd_temp( 1, nbpb )
-
-            !------------------------------------!
-            ! --- lateral melting if monocat --- !
-            !------------------------------------!
+            !
+            CALL lim_thd_1d2d( nbpb, jl, 1 )                ! --- Move to 1D arrays ---!
+            !
+            CALL lim_thd_dif ( 1, nbpb )                    ! --- Ice/Snow Temperature profile --- !
+            !
+            CALL lim_thd_dh  ( 1, nbpb )                    ! --- Ice/Snow thickness ---!
+            !
+            CALL lim_thd_ent ( 1, nbpb, q_i_1d(1:nbpb,:) )  ! --- Ice enthalpy remapping --- !
+            !
+            CALL lim_thd_sal ( 1, nbpb )                    ! --- Ice salinity ---            !
+            !
+            CALL lim_thd_temp( 1, nbpb )                    ! --- temperature update ---      !
+            !
+            !                                               ! --- lateral melting if monocat --- !
             IF ( ( nn_monocat == 1 .OR. nn_monocat == 4 ) .AND. jpl == 1 ) THEN
                CALL lim_thd_lam( 1, nbpb )
             END IF
-
-            !-------------------------!
-            ! --- Move to 2D arrays ---
-            !-------------------------!
-            CALL lim_thd_1d2d( nbpb, jl, 2 )
-
-            !
-            IF( lk_mpp )   CALL mpp_comm_free( ncomm_ice ) !RB necessary ??
+            !
+            CALL lim_thd_1d2d( nbpb, jl, 2 )                ! --- Move to 2D arrays ---
+            !
+            IF( lk_mpp )   CALL mpp_comm_free( ncomm_ice )  !RB necessary ??
          ENDIF
          !
@@ -410,6 +386,6 @@
       ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_stop('limthd')
-
+      IF( nn_timing == 1 )   CALL timing_stop('limthd')
+      !
    END SUBROUTINE lim_thd 
 
@@ -424,5 +400,5 @@
       !!-------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kideb, kiut   ! bounds for the spatial loop
-      !!
+      !
       INTEGER  ::   ji, jk   ! dummy loop indices
       REAL(wp) ::   ztmelts, zaaa, zbbb, zccc, zdiscrim  ! local scalar 
@@ -444,6 +420,7 @@
          END DO 
       END DO 
-
+      !
    END SUBROUTINE lim_thd_temp
+
 
    SUBROUTINE lim_thd_lam( kideb, kiut )
@@ -455,9 +432,11 @@
       !!-----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kideb, kiut        ! bounds for the spatial loop
-      INTEGER             ::   ji                 ! dummy loop indices
-      REAL(wp)            ::   zhi_bef            ! ice thickness before thermo
-      REAL(wp)            ::   zdh_mel, zda_mel   ! net melting
-      REAL(wp)            ::   zvi, zvs           ! ice/snow volumes 
-
+      !
+      INTEGER  ::   ji                 ! dummy loop indices
+      REAL(wp) ::   zhi_bef            ! ice thickness before thermo
+      REAL(wp) ::   zdh_mel, zda_mel   ! net melting
+      REAL(wp) ::   zvi, zvs           ! ice/snow volumes 
+      !!-----------------------------------------------------------------------
+      !
       DO ji = kideb, kiut
          zdh_mel = MIN( 0._wp, dh_i_surf(ji) + dh_i_bott(ji) + dh_snowice(ji) )
@@ -477,6 +456,7 @@
          END IF
       END DO
-      
+      !
    END SUBROUTINE lim_thd_lam
+
 
    SUBROUTINE lim_thd_1d2d( nbpb, jl, kn )
@@ -486,19 +466,20 @@
       !! ** Purpose :   move arrays from 1d to 2d and the reverse
       !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kn       ! 1= from 2D to 1D
-                                        ! 2= from 1D to 2D
+      INTEGER, INTENT(in) ::   kn       ! 1= from 2D to 1D   ;   2= from 1D to 2D
       INTEGER, INTENT(in) ::   nbpb     ! size of 1D arrays
       INTEGER, INTENT(in) ::   jl       ! ice cat
+      !
       INTEGER             ::   jk       ! dummy loop indices
-
+      !!-----------------------------------------------------------------------
+      !
       SELECT CASE( kn )
-
-      CASE( 1 )
-
+      !
+      CASE( 1 )            ! from 2D to 1D
+         !
          CALL tab_2d_1d( nbpb, at_i_1d     (1:nbpb), at_i            , jpi, jpj, npb(1:nbpb) )
          CALL tab_2d_1d( nbpb, a_i_1d      (1:nbpb), a_i(:,:,jl)     , jpi, jpj, npb(1:nbpb) )
          CALL tab_2d_1d( nbpb, ht_i_1d     (1:nbpb), ht_i(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
          CALL tab_2d_1d( nbpb, ht_s_1d     (1:nbpb), ht_s(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
-         
+         !
          CALL tab_2d_1d( nbpb, t_su_1d     (1:nbpb), t_su(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
          CALL tab_2d_1d( nbpb, sm_i_1d     (1:nbpb), sm_i(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
@@ -512,5 +493,5 @@
             CALL tab_2d_1d( nbpb, s_i_1d(1:nbpb,jk), s_i(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
          END DO
-         
+         !
          CALL tab_2d_1d( nbpb, qprec_ice_1d(1:nbpb), qprec_ice(:,:) , jpi, jpj, npb(1:nbpb) )
          CALL tab_2d_1d( nbpb, qsr_ice_1d (1:nbpb), qsr_ice(:,:,jl) , jpi, jpj, npb(1:nbpb) )
@@ -526,8 +507,8 @@
          CALL tab_2d_1d( nbpb, qlead_1d   (1:nbpb), qlead           , jpi, jpj, npb(1:nbpb) )
          CALL tab_2d_1d( nbpb, fhld_1d    (1:nbpb), fhld            , jpi, jpj, npb(1:nbpb) )
-         
+         !
          CALL tab_2d_1d( nbpb, wfx_snw_1d (1:nbpb), wfx_snw         , jpi, jpj, npb(1:nbpb) )
          CALL tab_2d_1d( nbpb, wfx_sub_1d (1:nbpb), wfx_sub         , jpi, jpj, npb(1:nbpb) )
-         
+         !
          CALL tab_2d_1d( nbpb, wfx_bog_1d (1:nbpb), wfx_bog         , jpi, jpj, npb(1:nbpb) )
          CALL tab_2d_1d( nbpb, wfx_bom_1d (1:nbpb), wfx_bom         , jpi, jpj, npb(1:nbpb) )
@@ -536,5 +517,5 @@
          CALL tab_2d_1d( nbpb, wfx_res_1d (1:nbpb), wfx_res         , jpi, jpj, npb(1:nbpb) )
          CALL tab_2d_1d( nbpb, wfx_spr_1d (1:nbpb), wfx_spr         , jpi, jpj, npb(1:nbpb) )
-         
+         !
          CALL tab_2d_1d( nbpb, sfx_bog_1d (1:nbpb), sfx_bog         , jpi, jpj, npb(1:nbpb) )
          CALL tab_2d_1d( nbpb, sfx_bom_1d (1:nbpb), sfx_bom         , jpi, jpj, npb(1:nbpb) )
@@ -543,5 +524,5 @@
          CALL tab_2d_1d( nbpb, sfx_bri_1d (1:nbpb), sfx_bri         , jpi, jpj, npb(1:nbpb) )
          CALL tab_2d_1d( nbpb, sfx_res_1d (1:nbpb), sfx_res         , jpi, jpj, npb(1:nbpb) )
-         
+         !
          CALL tab_2d_1d( nbpb, hfx_thd_1d (1:nbpb), hfx_thd         , jpi, jpj, npb(1:nbpb) )
          CALL tab_2d_1d( nbpb, hfx_spr_1d (1:nbpb), hfx_spr         , jpi, jpj, npb(1:nbpb) )
@@ -557,7 +538,7 @@
          CALL tab_2d_1d( nbpb, hfx_err_dif_1d (1:nbpb), hfx_err_dif , jpi, jpj, npb(1:nbpb) )
          CALL tab_2d_1d( nbpb, hfx_err_rem_1d (1:nbpb), hfx_err_rem , jpi, jpj, npb(1:nbpb) )
-
-      CASE( 2 )
-
+         !
+      CASE( 2 )            ! from 1D to 2D
+         !
          CALL tab_1d_2d( nbpb, at_i          , npb, at_i_1d    (1:nbpb)   , jpi, jpj )
          CALL tab_1d_2d( nbpb, ht_i(:,:,jl)  , npb, ht_i_1d    (1:nbpb)   , jpi, jpj )
@@ -576,8 +557,8 @@
          END DO
          CALL tab_1d_2d( nbpb, qlead         , npb, qlead_1d  (1:nbpb)   , jpi, jpj )
-         
+         !
          CALL tab_1d_2d( nbpb, wfx_snw       , npb, wfx_snw_1d(1:nbpb)   , jpi, jpj )
          CALL tab_1d_2d( nbpb, wfx_sub       , npb, wfx_sub_1d(1:nbpb)   , jpi, jpj )
-         
+         !
          CALL tab_1d_2d( nbpb, wfx_bog       , npb, wfx_bog_1d(1:nbpb)   , jpi, jpj )
          CALL tab_1d_2d( nbpb, wfx_bom       , npb, wfx_bom_1d(1:nbpb)   , jpi, jpj )
@@ -586,5 +567,5 @@
          CALL tab_1d_2d( nbpb, wfx_res       , npb, wfx_res_1d(1:nbpb)   , jpi, jpj )
          CALL tab_1d_2d( nbpb, wfx_spr       , npb, wfx_spr_1d(1:nbpb)   , jpi, jpj )
-         
+         !
          CALL tab_1d_2d( nbpb, sfx_bog       , npb, sfx_bog_1d(1:nbpb)   , jpi, jpj )
          CALL tab_1d_2d( nbpb, sfx_bom       , npb, sfx_bom_1d(1:nbpb)   , jpi, jpj )
@@ -593,5 +574,5 @@
          CALL tab_1d_2d( nbpb, sfx_res       , npb, sfx_res_1d(1:nbpb)   , jpi, jpj )
          CALL tab_1d_2d( nbpb, sfx_bri       , npb, sfx_bri_1d(1:nbpb)   , jpi, jpj )
-         
+         !
          CALL tab_1d_2d( nbpb, hfx_thd       , npb, hfx_thd_1d(1:nbpb)   , jpi, jpj )
          CALL tab_1d_2d( nbpb, hfx_spr       , npb, hfx_spr_1d(1:nbpb)   , jpi, jpj )
@@ -612,5 +593,5 @@
          !         
       END SELECT
-
+      !
    END SUBROUTINE lim_thd_1d2d
 
@@ -629,6 +610,7 @@
       !!-------------------------------------------------------------------
       INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicethd/ rn_hnewice, ln_frazil, rn_maxfrazb, rn_vfrazb, rn_Cfrazb,                       &
-         &                rn_himin, rn_betas, rn_kappa_i, nn_conv_dif, rn_terr_dif, nn_ice_thcon, &
+      !!
+      NAMELIST/namicethd/ rn_hnewice, ln_frazil, rn_maxfrazb, rn_vfrazb, rn_Cfrazb,                &
+         &                rn_himin, rn_betas, rn_kappa_i, nn_conv_dif, rn_terr_dif, nn_ice_thcon,  &
          &                nn_monocat, ln_it_qnsice
       !!-------------------------------------------------------------------
Index: /trunk/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90	(revision 6140)
@@ -41,7 +41,4 @@
 CONTAINS
 
-#if defined key_dimgout
-# include "limwri_dimg.h90"
-#else
 
    SUBROUTINE lim_wri( kindic )
@@ -298,5 +295,4 @@
       
    END SUBROUTINE lim_wri
-#endif
 
  
Index: unk/NEMOGCM/NEMO/LIM_SRC_3/limwri_dimg.h90
===================================================================
--- /trunk/NEMOGCM/NEMO/LIM_SRC_3/limwri_dimg.h90	(revision 6139)
+++ 	(revision )
@@ -1,198 +1,0 @@
-SUBROUTINE lim_wri
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 3.3 , UCL - NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-   !!-------------------------------------------------------------------
-   !!  This routine computes the average of some variables and write it
-   !!  on the ouput files.
-   !!  ATTENTION cette routine n'est valable que si le pas de temps est
-   !!  egale a une fraction entiere de 1 jours.
-   !!  Diff 1-D 3-D : suppress common also included in etat
-   !!                 suppress cmoymo 11-18
-   !!  modif : 03/06/98
-   !!-------------------------------------------------------------------
-   USE  diawri, ONLY : dia_wri_dimg
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
-
-   REAL(wp),DIMENSION(1) ::   zdept
-
-   REAL(wp) ::   zsto, zsec, zjulian,zout, &
-   REAL(wp) ::   zindh,zinda,zindb, ztmu
-   REAL(wp), DIMENSION(jpi,jpj,jpnoumax) ::   zcmo
-   REAL(wp), DIMENSION(jpi,jpj) ::   zfield
-   INTEGER, SAVE ::   nmoyice   !: counter for averaging
-   INTEGER, SAVE ::   nwf       !: number of fields to write on disk
-   INTEGER, SAVE,DIMENSION (:), ALLOCATABLE  :: nsubindex   !: subindex to be saved
-   ! according to namelist
-
-   REAL(wp), SAVE, DIMENSION(jpi,jpj,jpnoumax) :: rcmoy
-#if ! defined key_diainstant
-   LOGICAL, PARAMETER :: ll_dia_inst=.false.      ! local logical variable 
-#else
-   LOGICAL, PARAMETER :: ll_dia_inst=.true.
-#endif
-   INTEGER ::  ji, jj, jf, ii   ! dummy loop indices and array index
-   INTEGER :: iyear, iday, imon ! 
-
-   CHARACTER(LEN=80) :: clname, cltext, clmode
-
-
-   INTEGER , SAVE ::   nice, nhorid, ndim, niter, ndepid
-   INTEGER , DIMENSION( jpij ) , SAVE ::   ndex51  
-   !!-------------------------------------------------------------------
-   IF ( numit == nstart ) THEN 
-
-      CALL lim_wri_init 
-
-      nwf = 0 
-      ii  = 0
-
-      IF (lwp ) THEN
-         WRITE(numout,*) 'lim_wri : Write ice outputs in dimg'
-         WRITE(numout,*) '~~~~~~~~'
-         WRITE(numout,*) '   According to namelist_ice, following fields saved:'
-         DO jf =1, noumef
-            IF (nc(jf) == 1 ) THEN
-               WRITE(numout,* ) '    -',titn(jf), nam(jf), uni(jf)
-            ENDIF
-         END DO
-      ENDIF
-
-      DO jf = 1, noumef
-         IF (nc(jf) == 1 ) nwf = nwf + 1
-      END DO
-
-      ALLOCATE( nsubindex (nwf) )
-
-      DO jf = 1, noumef
-         IF (nc(jf) == 1 ) THEN 
-            ii = ii +1 
-            nsubindex(ii) = jf
-         END IF
-      END DO
-
-      zsto     = rdt_ice
-      zout     = nwrite * rdt_ice / nn_fsbc
-      zsec     = 0.
-      niter    = 0
-      zdept(1) = 0.
-      nmoyice  = 0
-
-   ENDIF
-
-#if ! defined key_diainstant 
-   !-- calculs des valeurs instantanees
-
-   zcmo(:,:, 1:jpnoumax ) = 0.e0 
-   DO jj = 2 , jpjm1
-      DO ji = 2 , jpim1   ! NO vector opt.
-         zindh  = MAX( 0._wp , SIGN( 1._wp , ht_i(ji,jj,1) * (1.0 - frld(ji,jj) ) - 0.10 ) )
-         zinda  = MAX( 0._wp , SIGN( 1._wp , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
-         zindb  = zindh * zinda
-         ztmu   = MAX( 0.5 * 1._wp , ( umask(ji,jj,1) + umask(ji+1,jj,1) + umask(ji,jj+1,1) + umask(ji+1,jj+1,1) ) ) 
-         zcmo(ji,jj,1)  = ht_s (ji,jj,1)
-         zcmo(ji,jj,2)  = ht_i (ji,jj,1)
-         zcmo(ji,jj,3)  = 0.
-         zcmo(ji,jj,4)  = frld  (ji,jj)
-         zcmo(ji,jj,5)  = sist  (ji,jj)
-         zcmo(ji,jj,6)  = fhtur  (ji,jj)
-         zcmo(ji,jj,7)  = zindb * (  u_ice(ji,jj  ) * umask(ji,jj,1) + u_ice(ji+1,jj  ) * umask(ji+1,jj,1)   &
-            + u_ice(ji,jj+1) * umask(ji,jj+1,1) + u_ice(ji+1,jj+1) * umask(ji+1,jj+1,1) ) &
-            / ztmu 
-
-         zcmo(ji,jj,8)  = zindb * (  v_ice(ji,jj  ) * umask(ji,jj,1) + v_ice(ji+1,jj  ) * umask(ji+1,jj,1)   &
-            + v_ice(ji,jj+1) * umask(ji,jj+1,1) + v_ice(ji+1,jj+1) * umask(ji+1,jj+1,1) ) &
-            / ztmu
-         zcmo(ji,jj,9)  = sst_m(ji,jj)
-         zcmo(ji,jj,10) = sss_m(ji,jj)
-
-         zcmo(ji,jj,11) = qns(ji,jj) + qsr(ji,jj)
-         zcmo(ji,jj,12) = qsr(ji,jj)
-         zcmo(ji,jj,13) = qns(ji,jj)
-         ! See thersf for the coefficient
-         zcmo(ji,jj,14) = - sfx (ji,jj) * rday      ! converted in Kg/m2/day = mm/day
-         zcmo(ji,jj,15) = utau_ice(ji,jj)
-         zcmo(ji,jj,16) = vtau_ice(ji,jj)
-         zcmo(ji,jj,17) = qsr (ji,jj)
-         zcmo(ji,jj,18) = qns(ji,jj)
-         zcmo(ji,jj,19) = sprecip(ji,jj)
-      END DO
-   END DO
-   ! Cumulates values between outputs           
-   rcmoy(:,:,:)= rcmoy(:,:,:) + zcmo(:,:,:)
-   nmoyice = nmoyice + 1 
-   ! compute mean value if it is time to write on file
-   IF ( MOD(numit,nwrite) == 0 ) THEN
-      rcmoy(:,:,:) = rcmoy(:,:,:) / FLOAT(nmoyice)
-#else  
-      IF ( MOD(numit,nwrite) == 0 ) THEN 
-         !  case of instantaneaous output rcmoy(:,:, 1:jpnoumax ) = 0.e0
-         DO jj = 2 , jpjm1
-            DO ji = 2 , jpim1   ! NO vector opt.
-               zindh  = MAX( 0._wp , SIGN( 1._wp , ht_i(ji,jj,1) * (1.0 - frld(ji,jj) ) - 0.10 ) )
-               zinda  = MAX( 0._wp , SIGN( 1._wp , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
-               zindb  = zindh * zinda
-               ztmu   = MAX( 0.5 * 1._wp , ( umask(ji,jj,1) + umask(ji+1,jj,1) + umask(ji,jj+1,1) + umask(ji+1,jj+1,1) ) )
-               rcmoy(ji,jj,1)  = ht_s (ji,jj,1)
-               rcmoy(ji,jj,2)  = ht_i (ji,jj,1)
-               rcmoy(ji,jj,3)  = 0.
-               rcmoy(ji,jj,4)  = frld  (ji,jj)
-               rcmoy(ji,jj,5)  = sist  (ji,jj)
-               rcmoy(ji,jj,6)  = fhtur  (ji,jj)
-               rcmoy(ji,jj,7)  = zindb * (  u_ice(ji,jj  ) * umask(ji,jj,1) + u_ice(ji+1,jj  ) * umask(ji+1,jj,1)   &
-                  + u_ice(ji,jj+1) * umask(ji,jj+1,1) + u_ice(ji+1,jj+1) * umask(ji+1,jj+1,1) ) &
-                  / ztmu
-
-               rcmoy(ji,jj,8)  = zindb * (  v_ice(ji,jj  ) * umask(ji,jj,1) + v_ice(ji+1,jj  ) * umask(ji+1,jj,1)   &
-                  + v_ice(ji,jj+1) * umask(ji,jj+1,1) + v_ice(ji+1,jj+1) * umask(ji+1,jj+1,1) ) &
-                  / ztmu
-               rcmoy(ji,jj,9)  = sst_m(ji,jj)
-               rcmoy(ji,jj,10) = sss_m(ji,jj)
-
-               rcmoy(ji,jj,11) = qns(ji,jj) + qsr(ji,jj)
-               rcmoy(ji,jj,12) = qsr(ji,jj)
-               rcmoy(ji,jj,13) = qns(ji,jj)
-               ! See thersf for the coefficient
-               rcmoy(ji,jj,14) = - sfx (ji,jj) * rday      ! converted in mm/day
-               rcmoy(ji,jj,15) = utau_ice(ji,jj)
-               rcmoy(ji,jj,16) = vtau_ice(ji,jj)
-               rcmoy(ji,jj,17) = qsr(ji,jj)
-               rcmoy(ji,jj,18) = qns(ji,jj)
-               rcmoy(ji,jj,19) = sprecip(ji,jj)
-            END DO
-         END DO
-#endif
-
-         !
-         niter = niter + 1
-         DO jf = 1 , noumef
-            zfield(:,:) = (rcmoy(:,:,jf) * cmulti(jf) + cadd(jf)) * tmask(:,:,1)
-
-            IF ( jf == 7  .OR. jf == 8  .OR. jf == 15 .OR. jf == 16 ) THEN 
-               CALL lbc_lnk( zfield, 'T', -1. )
-            ELSE 
-               CALL lbc_lnk( zfield, 'T',  1. )
-            ENDIF
-            rcmoy(:,:,jf) = zfield(:,:)
-         END DO
-
-         IF (ll_dia_inst) THEN
-            clmode='instantaneous'
-         ELSE
-            WRITE(clmode,'(f5.1,a)' ) nwrite*rdt/86400.,' days average'
-         END IF
-         iyear = ndastp/10000
-         imon = (ndastp-iyear*10000)/100
-         iday = ndastp - imon*100 - iyear*10000
-         WRITE(clname,9000) TRIM(cexper),'ICEMOD',iyear,imon,iday
-         cltext=TRIM(cexper)//' ice modele output'//TRIM(clmode)
-         CALL dia_wri_dimg (clname, cltext, rcmoy, nwf , 'I', nsubindex)
-9000     FORMAT(a,"_",a,"_y",i4.4,"m",i2.2,"d",i2.2,".dimgproc")
-
-         rcmoy(:,:,:) = 0.0
-         nmoyice = 0 
-      END IF     !  MOD(numit, nwrite == 0 ) !
-
-   END SUBROUTINE lim_wri
Index: /trunk/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 6140)
@@ -22,16 +22,15 @@
    USE oce
    USE dom_oce      
+   USE zdf_oce
    USE agrif_oce
    USE phycst
+   !
    USE in_out_manager
    USE agrif_opa_sponge
    USE lib_mpp
    USE wrk_nemo
-   USE zdf_oce
  
    IMPLICIT NONE
    PRIVATE
-
-   INTEGER :: bdy_tinterp = 0
 
    PUBLIC   Agrif_tra, Agrif_dyn, Agrif_ssh, Agrif_dyn_ts, Agrif_ssh_ts, Agrif_dta_ts
@@ -44,12 +43,12 @@
 # endif
 
-#  include "domzgr_substitute.h90"  
+   INTEGER ::   bdy_tinterp = 0
+
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.6 , NEMO Consortium (2010)
+   !! NEMO/NST 3.7 , NEMO Consortium (2015)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -60,9 +59,10 @@
       !
       IF( Agrif_Root() )   RETURN
-
-      Agrif_SpecialValue    = 0.e0
+      !
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = .TRUE.
-
+      !
       CALL Agrif_Bc_variable( tsn_id, procname=interptsn )
+      !
       Agrif_UseSpecialValue = .FALSE.
       !
@@ -74,50 +74,47 @@
       !!                  ***  ROUTINE Agrif_DYN  ***
       !!----------------------------------------------------------------------  
-      !! 
       INTEGER, INTENT(in) ::   kt
-      !!
-      INTEGER :: ji,jj,jk, j1,j2, i1,i2
-      REAL(wp), POINTER, DIMENSION(:,:) :: zub, zvb
-      !!----------------------------------------------------------------------  
-
+      !
+      INTEGER ::   ji, jj, jk       ! dummy loop indices
+      INTEGER ::   j1, j2, i1, i2
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zub, zvb
+      !!----------------------------------------------------------------------  
+      !
       IF( Agrif_Root() )   RETURN
-
-      CALL wrk_alloc( jpi, jpj, zub, zvb )
-
-      Agrif_SpecialValue=0.
+      !
+      CALL wrk_alloc( jpi,jpj,   zub, zvb )
+      !
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = ln_spc_dyn
-
-      CALL Agrif_Bc_variable(un_interp_id,procname=interpun)
-      CALL Agrif_Bc_variable(vn_interp_id,procname=interpvn)
-
+      !
+      CALL Agrif_Bc_variable( un_interp_id, procname=interpun )
+      CALL Agrif_Bc_variable( vn_interp_id, procname=interpvn )
+      !
       Agrif_UseSpecialValue = .FALSE.
- 
+      !
       ! prevent smoothing in ghost cells
-      i1=1
-      i2=jpi
-      j1=1
-      j2=jpj
-      IF((nbondj == -1).OR.(nbondj == 2)) j1 = 3
-      IF((nbondj == +1).OR.(nbondj == 2)) j2 = nlcj-2
-      IF((nbondi == -1).OR.(nbondi == 2)) i1 = 3
-      IF((nbondi == +1).OR.(nbondi == 2)) i2 = nlci-2
-
-
-      IF((nbondi == -1).OR.(nbondi == 2)) THEN
-
+      i1 =  1   ;   i2 = jpi
+      j1 =  1   ;   j2 = jpj
+      IF( nbondj == -1 .OR. nbondj == 2 )   j1 = 3
+      IF( nbondj == +1 .OR. nbondj == 2 )   j2 = nlcj-2
+      IF( nbondi == -1 .OR. nbondi == 2 )   i1 = 3
+      IF( nbondi == +1 .OR. nbondi == 2 )   i2 = nlci-2
+
+      IF( nbondi == -1 .OR. nbondi == 2 ) THEN
+         !
          ! Smoothing
          ! ---------
-         IF ( .NOT.ln_dynspg_ts ) THEN ! Store transport
-            ua_b(2,:)=0._wp
-            DO jk=1,jpkm1
-               DO jj=1,jpj
-                  ua_b(2,jj) = ua_b(2,jj) + fse3u_a(2,jj,jk) * ua(2,jj,jk)
-               END DO
-            END DO
-            DO jj=1,jpj
-               ua_b(2,jj) = ua_b(2,jj) * hur_a(2,jj)            
-            END DO
-         ENDIF
-
+         IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
+            ua_b(2,:) = 0._wp
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ua_b(2,jj) = ua_b(2,jj) + e3u_a(2,jj,jk) * ua(2,jj,jk)
+               END DO
+            END DO
+            DO jj = 1, jpj
+               ua_b(2,jj) = ua_b(2,jj) * r1_hu_a(2,jj)            
+            END DO
+         ENDIF
+         !
          DO jk=1,jpkm1                 ! Smooth
             DO jj=j1,j2
@@ -126,13 +123,13 @@
             END DO
          END DO
-
-         zub(2,:)=0._wp                ! Correct transport
-         DO jk=1,jpkm1
-            DO jj=1,jpj
-               zub(2,jj) = zub(2,jj) + fse3u_a(2,jj,jk) * ua(2,jj,jk)
+         !
+         zub(2,:) = 0._wp              ! Correct transport
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               zub(2,jj) = zub(2,jj) + e3u_a(2,jj,jk) * ua(2,jj,jk)
             END DO
          END DO
          DO jj=1,jpj
-            zub(2,jj) = zub(2,jj) * hur_a(2,jj)
+            zub(2,jj) = zub(2,jj) * r1_hu_a(2,jj)
          END DO
 
@@ -145,68 +142,136 @@
          ! Set tangential velocities to time splitting estimate
          !-----------------------------------------------------
-         IF ( ln_dynspg_ts) THEN
-            zvb(2,:)=0._wp
+         IF( ln_dynspg_ts ) THEN
+            zvb(2,:) = 0._wp
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  zvb(2,jj) = zvb(2,jj) + e3v_a(2,jj,jk) * va(2,jj,jk)
+               END DO
+            END DO
+            DO jj = 1, jpj
+               zvb(2,jj) = zvb(2,jj) * r1_hv_a(2,jj)
+            END DO
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  va(2,jj,jk) = (va(2,jj,jk)+va_b(2,jj)-zvb(2,jj)) * vmask(2,jj,jk)
+               END DO
+            END DO
+         ENDIF
+         !
+         ! Mask domain edges:
+         !-------------------
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               ua(1,jj,jk) = 0._wp
+               va(1,jj,jk) = 0._wp
+            END DO
+         END DO         
+         !
+      ENDIF
+
+      IF( nbondi == 1 .OR. nbondi == 2 ) THEN
+
+         ! Smoothing
+         ! ---------
+         IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
+            ua_b(nlci-2,:) = 0._wp
             DO jk=1,jpkm1
                DO jj=1,jpj
-                  zvb(2,jj) = zvb(2,jj) + fse3v_a(2,jj,jk) * va(2,jj,jk)
+                  ua_b(nlci-2,jj) = ua_b(nlci-2,jj) + e3u_a(nlci-2,jj,jk) * ua(nlci-2,jj,jk)
                END DO
             END DO
             DO jj=1,jpj
-               zvb(2,jj) = zvb(2,jj) * hvr_a(2,jj)
-            END DO
-            DO jk=1,jpkm1
-               DO jj=1,jpj
-                  va(2,jj,jk) = (va(2,jj,jk)+va_b(2,jj)-zvb(2,jj))*vmask(2,jj,jk)
-               END DO
-            END DO
-         ENDIF
-
+               ua_b(nlci-2,jj) = ua_b(nlci-2,jj) * r1_hu_a(nlci-2,jj)            
+            END DO
+         ENDIF
+
+         DO jk = 1, jpkm1              ! Smooth
+            DO jj = j1, j2
+               ua(nlci-2,jj,jk) = 0.25_wp * umask(nlci-2,jj,jk)      &
+                  &             * ( ua(nlci-3,jj,jk) + 2._wp*ua(nlci-2,jj,jk) + ua(nlci-1,jj,jk) )
+            END DO
+         END DO
+
+         zub(nlci-2,:) = 0._wp        ! Correct transport
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               zub(nlci-2,jj) = zub(nlci-2,jj) + e3u_a(nlci-2,jj,jk) * ua(nlci-2,jj,jk)
+            END DO
+         END DO
+         DO jj = 1, jpj
+            zub(nlci-2,jj) = zub(nlci-2,jj) * r1_hu_a(nlci-2,jj)
+         END DO
+
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               ua(nlci-2,jj,jk) = ( ua(nlci-2,jj,jk) + ua_b(nlci-2,jj) - zub(nlci-2,jj) ) * umask(nlci-2,jj,jk)
+            END DO
+         END DO
+         !
+         ! Set tangential velocities to time splitting estimate
+         !-----------------------------------------------------
+         IF( ln_dynspg_ts ) THEN
+            zvb(nlci-1,:) = 0._wp
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  zvb(nlci-1,jj) = zvb(nlci-1,jj) + e3v_a(nlci-1,jj,jk) * va(nlci-1,jj,jk)
+               END DO
+            END DO
+            DO jj=1,jpj
+               zvb(nlci-1,jj) = zvb(nlci-1,jj) * r1_hv_a(nlci-1,jj)
+            END DO
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  va(nlci-1,jj,jk) = ( va(nlci-1,jj,jk) + va_b(nlci-1,jj) - zvb(nlci-1,jj) ) * vmask(nlci-1,jj,jk)
+               END DO
+            END DO
+         ENDIF
+         !
          ! Mask domain edges:
          !-------------------
-         DO jk=1,jpkm1
-            DO jj=1,jpj
-               ua(1,jj,jk) = 0._wp
-               va(1,jj,jk) = 0._wp
-            END DO
-         END DO         
-
-      ENDIF
-
-      IF((nbondi == 1).OR.(nbondi == 2)) THEN
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               ua(nlci-1,jj,jk) = 0._wp
+               va(nlci  ,jj,jk) = 0._wp
+            END DO
+         END DO 
+         !
+      ENDIF
+
+      IF( nbondj == -1 .OR. nbondj == 2 ) THEN
 
          ! Smoothing
          ! ---------
-         IF ( .NOT.ln_dynspg_ts ) THEN ! Store transport
-            ua_b(nlci-2,:)=0._wp
-            DO jk=1,jpkm1
-               DO jj=1,jpj
-                  ua_b(nlci-2,jj) = ua_b(nlci-2,jj) + fse3u_a(nlci-2,jj,jk) * ua(nlci-2,jj,jk)
-               END DO
-            END DO
-            DO jj=1,jpj
-               ua_b(nlci-2,jj) = ua_b(nlci-2,jj) * hur_a(nlci-2,jj)            
-            END DO
-         ENDIF
-
-         DO jk=1,jpkm1                 ! Smooth
-            DO jj=j1,j2
-               ua(nlci-2,jj,jk) = 0.25_wp*(ua(nlci-3,jj,jk)+2._wp*ua(nlci-2,jj,jk)+ua(nlci-1,jj,jk))
-               ua(nlci-2,jj,jk) = ua(nlci-2,jj,jk) * umask(nlci-2,jj,jk)
-            END DO
-         END DO
-
-         zub(nlci-2,:)=0._wp           ! Correct transport
+         IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
+            va_b(:,2) = 0._wp
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  va_b(ji,2) = va_b(ji,2) + e3v_a(ji,2,jk) * va(ji,2,jk)
+               END DO
+            END DO
+            DO ji=1,jpi
+               va_b(ji,2) = va_b(ji,2) * r1_hv_a(ji,2)            
+            END DO
+         ENDIF
+         !
+         DO jk = 1, jpkm1              ! Smooth
+            DO ji = i1, i2
+               va(ji,2,jk) = 0.25_wp * vmask(ji,2,jk)    &
+                  &        * ( va(ji,1,jk) + 2._wp*va(ji,2,jk) + va(ji,3,jk) )
+            END DO
+         END DO
+         !
+         zvb(:,2) = 0._wp              ! Correct transport
          DO jk=1,jpkm1
-            DO jj=1,jpj
-               zub(nlci-2,jj) = zub(nlci-2,jj) + fse3u_a(nlci-2,jj,jk) * ua(nlci-2,jj,jk)
-            END DO
-         END DO
-         DO jj=1,jpj
-            zub(nlci-2,jj) = zub(nlci-2,jj) * hur_a(nlci-2,jj)
-         END DO
-
-         DO jk=1,jpkm1
-            DO jj=1,jpj
-               ua(nlci-2,jj,jk) = (ua(nlci-2,jj,jk)+ua_b(nlci-2,jj)-zub(nlci-2,jj))*umask(nlci-2,jj,jk)
+            DO ji=1,jpi
+               zvb(ji,2) = zvb(ji,2) + e3v_a(ji,2,jk) * va(ji,2,jk) * vmask(ji,2,jk)
+            END DO
+         END DO
+         DO ji = 1, jpi
+            zvb(ji,2) = zvb(ji,2) * r1_hv_a(ji,2)
+         END DO
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+               va(ji,2,jk) = ( va(ji,2,jk) + va_b(ji,2) - zvb(ji,2) ) * vmask(ji,2,jk)
             END DO
          END DO
@@ -214,17 +279,18 @@
          ! Set tangential velocities to time splitting estimate
          !-----------------------------------------------------
-         IF ( ln_dynspg_ts) THEN
-            zvb(nlci-1,:)=0._wp
-            DO jk=1,jpkm1
-               DO jj=1,jpj
-                  zvb(nlci-1,jj) = zvb(nlci-1,jj) + fse3v_a(nlci-1,jj,jk) * va(nlci-1,jj,jk)
-               END DO
-            END DO
-            DO jj=1,jpj
-               zvb(nlci-1,jj) = zvb(nlci-1,jj) * hvr_a(nlci-1,jj)
-            END DO
-            DO jk=1,jpkm1
-               DO jj=1,jpj
-                  va(nlci-1,jj,jk) = (va(nlci-1,jj,jk)+va_b(nlci-1,jj)-zvb(nlci-1,jj))*vmask(nlci-1,jj,jk)
+         IF( ln_dynspg_ts ) THEN
+            zub(:,2) = 0._wp
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  zub(ji,2) = zub(ji,2) + e3u_a(ji,2,jk) * ua(ji,2,jk) * umask(ji,2,jk)
+               END DO
+            END DO
+            DO ji = 1, jpi
+               zub(ji,2) = zub(ji,2) * r1_hu_a(ji,2)
+            END DO
+
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ua(ji,2,jk) = ( ua(ji,2,jk) + ua_b(ji,2) - zub(ji,2) ) * umask(ji,2,jk)
                END DO
             END DO
@@ -233,8 +299,8 @@
          ! Mask domain edges:
          !-------------------
-         DO jk=1,jpkm1
-            DO jj=1,jpj
-               ua(nlci-1,jj,jk) = 0._wp
-               va(nlci  ,jj,jk) = 0._wp
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+               ua(ji,1,jk) = 0._wp
+               va(ji,1,jk) = 0._wp
             END DO
          END DO 
@@ -242,144 +308,77 @@
       ENDIF
 
-      IF((nbondj == -1).OR.(nbondj == 2)) THEN
-
+      IF( nbondj == 1 .OR. nbondj == 2 ) THEN
+         !
          ! Smoothing
          ! ---------
-         IF ( .NOT.ln_dynspg_ts ) THEN ! Store transport
-            va_b(:,2)=0._wp
-            DO jk=1,jpkm1
-               DO ji=1,jpi
-                  va_b(ji,2) = va_b(ji,2) + fse3v_a(ji,2,jk) * va(ji,2,jk)
-               END DO
-            END DO
-            DO ji=1,jpi
-               va_b(ji,2) = va_b(ji,2) * hvr_a(ji,2)            
-            END DO
-         ENDIF
-
-         DO jk=1,jpkm1                 ! Smooth
-            DO ji=i1,i2
-               va(ji,2,jk)=0.25_wp*(va(ji,1,jk)+2._wp*va(ji,2,jk)+va(ji,3,jk))
-               va(ji,2,jk)=va(ji,2,jk)*vmask(ji,2,jk)
-            END DO
-         END DO
-
-         zvb(:,2)=0._wp                ! Correct transport
-         DO jk=1,jpkm1
-            DO ji=1,jpi
-               zvb(ji,2) = zvb(ji,2) + fse3v_a(ji,2,jk) * va(ji,2,jk) * vmask(ji,2,jk)
-            END DO
-         END DO
-         DO ji=1,jpi
-            zvb(ji,2) = zvb(ji,2) * hvr_a(ji,2)
-         END DO
-         DO jk=1,jpkm1
-            DO ji=1,jpi
-               va(ji,2,jk) = (va(ji,2,jk)+va_b(ji,2)-zvb(ji,2))*vmask(ji,2,jk)
-            END DO
-         END DO
-
+         IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
+            va_b(:,nlcj-2) = 0._wp
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  va_b(ji,nlcj-2) = va_b(ji,nlcj-2) + e3v_a(ji,nlcj-2,jk) * va(ji,nlcj-2,jk)
+               END DO
+            END DO
+            DO ji = 1, jpi
+               va_b(ji,nlcj-2) = va_b(ji,nlcj-2) * r1_hv_a(ji,nlcj-2)            
+            END DO
+         ENDIF
+         !
+         DO jk = 1, jpkm1              ! Smooth
+            DO ji = i1, i2
+               va(ji,nlcj-2,jk) = 0.25_wp * vmask(ji,nlcj-2,jk)   &
+                  &             * ( va(ji,nlcj-3,jk) + 2._wp * va(ji,nlcj-2,jk) + va(ji,nlcj-1,jk) )
+            END DO
+         END DO
+         !
+         zvb(:,nlcj-2) = 0._wp         ! Correct transport
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+               zvb(ji,nlcj-2) = zvb(ji,nlcj-2) + e3v_a(ji,nlcj-2,jk) * va(ji,nlcj-2,jk) * vmask(ji,nlcj-2,jk)
+            END DO
+         END DO
+         DO ji = 1, jpi
+            zvb(ji,nlcj-2) = zvb(ji,nlcj-2) * r1_hv_a(ji,nlcj-2)
+         END DO
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+               va(ji,nlcj-2,jk) = ( va(ji,nlcj-2,jk) + va_b(ji,nlcj-2) - zvb(ji,nlcj-2) ) * vmask(ji,nlcj-2,jk)
+            END DO
+         END DO
+         !
          ! Set tangential velocities to time splitting estimate
          !-----------------------------------------------------
-         IF ( ln_dynspg_ts ) THEN
-            zub(:,2)=0._wp
-            DO jk=1,jpkm1
-               DO ji=1,jpi
-                  zub(ji,2) = zub(ji,2) + fse3u_a(ji,2,jk) * ua(ji,2,jk) * umask(ji,2,jk)
-               END DO
-            END DO
-            DO ji=1,jpi
-               zub(ji,2) = zub(ji,2) * hur_a(ji,2)
-            END DO
-
-            DO jk=1,jpkm1
-               DO ji=1,jpi
-                  ua(ji,2,jk) = (ua(ji,2,jk)+ua_b(ji,2)-zub(ji,2))*umask(ji,2,jk)
-               END DO
-            END DO
-         ENDIF
-
+         IF( ln_dynspg_ts ) THEN
+            zub(:,nlcj-1) = 0._wp
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  zub(ji,nlcj-1) = zub(ji,nlcj-1) + e3u_a(ji,nlcj-1,jk) * ua(ji,nlcj-1,jk) * umask(ji,nlcj-1,jk)
+               END DO
+            END DO
+            DO ji = 1, jpi
+               zub(ji,nlcj-1) = zub(ji,nlcj-1) * r1_hu_a(ji,nlcj-1)
+            END DO
+            !
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ua(ji,nlcj-1,jk) = ( ua(ji,nlcj-1,jk) + ua_b(ji,nlcj-1) - zub(ji,nlcj-1) ) * umask(ji,nlcj-1,jk)
+               END DO
+            END DO
+         ENDIF
+         !
          ! Mask domain edges:
          !-------------------
-         DO jk=1,jpkm1
-            DO ji=1,jpi
-               ua(ji,1,jk) = 0._wp
-               va(ji,1,jk) = 0._wp
-            END DO
-         END DO 
-
-      ENDIF
-
-      IF((nbondj == 1).OR.(nbondj == 2)) THEN
-         ! Smoothing
-         ! ---------
-         IF ( .NOT.ln_dynspg_ts ) THEN ! Store transport
-            va_b(:,nlcj-2)=0._wp
-            DO jk=1,jpkm1
-               DO ji=1,jpi
-                  va_b(ji,nlcj-2) = va_b(ji,nlcj-2) + fse3v_a(ji,nlcj-2,jk) * va(ji,nlcj-2,jk)
-               END DO
-            END DO
-            DO ji=1,jpi
-               va_b(ji,nlcj-2) = va_b(ji,nlcj-2) * hvr_a(ji,nlcj-2)            
-            END DO
-         ENDIF
-
-         DO jk=1,jpkm1                 ! Smooth
-            DO ji=i1,i2
-               va(ji,nlcj-2,jk)=0.25_wp*(va(ji,nlcj-3,jk)+2._wp*va(ji,nlcj-2,jk)+va(ji,nlcj-1,jk))
-               va(ji,nlcj-2,jk)=va(ji,nlcj-2,jk)*vmask(ji,nlcj-2,jk)
-            END DO
-         END DO
-
-         zvb(:,nlcj-2)=0._wp           ! Correct transport
-         DO jk=1,jpkm1
-            DO ji=1,jpi
-               zvb(ji,nlcj-2) = zvb(ji,nlcj-2) + fse3v_a(ji,nlcj-2,jk) * va(ji,nlcj-2,jk) * vmask(ji,nlcj-2,jk)
-            END DO
-         END DO
-         DO ji=1,jpi
-            zvb(ji,nlcj-2) = zvb(ji,nlcj-2) * hvr_a(ji,nlcj-2)
-         END DO
-         DO jk=1,jpkm1
-            DO ji=1,jpi
-               va(ji,nlcj-2,jk) = (va(ji,nlcj-2,jk)+va_b(ji,nlcj-2)-zvb(ji,nlcj-2))*vmask(ji,nlcj-2,jk)
-            END DO
-         END DO
-
-         ! Set tangential velocities to time splitting estimate
-         !-----------------------------------------------------
-         IF ( ln_dynspg_ts ) THEN
-            zub(:,nlcj-1)=0._wp
-            DO jk=1,jpkm1
-               DO ji=1,jpi
-                  zub(ji,nlcj-1) = zub(ji,nlcj-1) + fse3u_a(ji,nlcj-1,jk) * ua(ji,nlcj-1,jk) * umask(ji,nlcj-1,jk)
-               END DO
-            END DO
-            DO ji=1,jpi
-               zub(ji,nlcj-1) = zub(ji,nlcj-1) * hur_a(ji,nlcj-1)
-            END DO
-
-            DO jk=1,jpkm1
-               DO ji=1,jpi
-                  ua(ji,nlcj-1,jk) = (ua(ji,nlcj-1,jk)+ua_b(ji,nlcj-1)-zub(ji,nlcj-1))*umask(ji,nlcj-1,jk)
-               END DO
-            END DO
-         ENDIF
-
-         ! Mask domain edges:
-         !-------------------
-         DO jk=1,jpkm1
-            DO ji=1,jpi
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
                ua(ji,nlcj  ,jk) = 0._wp
                va(ji,nlcj-1,jk) = 0._wp
             END DO
          END DO 
-
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, zub, zvb )
+         !
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi,jpj,   zub, zvb )
       !
    END SUBROUTINE Agrif_dyn
+
 
    SUBROUTINE Agrif_dyn_ts( jn )
@@ -392,7 +391,7 @@
       INTEGER :: ji, jj
       !!----------------------------------------------------------------------  
-
+      !
       IF( Agrif_Root() )   RETURN
-
+      !
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
          DO jj=1,jpj
@@ -405,5 +404,5 @@
          END DO
       ENDIF
-
+      !
       IF((nbondi == 1).OR.(nbondi == 2)) THEN
          DO jj=1,jpj
@@ -416,5 +415,5 @@
          END DO
       ENDIF
-
+      !
       IF((nbondj == -1).OR.(nbondj == 2)) THEN
          DO ji=1,jpi
@@ -427,5 +426,5 @@
          END DO
       ENDIF
-
+      !
       IF((nbondj == 1).OR.(nbondj == 2)) THEN
          DO ji=1,jpi
@@ -441,4 +440,5 @@
    END SUBROUTINE Agrif_dyn_ts
 
+
    SUBROUTINE Agrif_dta_ts( kt )
       !!----------------------------------------------------------------------
@@ -452,47 +452,46 @@
       REAL(wp) :: zrhot, zt
       !!----------------------------------------------------------------------  
-
+      !
       IF( Agrif_Root() )   RETURN
-
-      ll_int_cons = ln_bt_fw ! Assume conservative temporal integration in
-      ! the forward case only
-
+      !
+      ll_int_cons = ln_bt_fw ! Assume conservative temporal integration in the forward case only
+      !
       zrhot = Agrif_rhot()
-
+      !
       ! "Central" time index for interpolation:
-      IF (ln_bt_fw) THEN
-         zt = REAL(Agrif_NbStepint()+0.5_wp,wp) / zrhot
+      IF( ln_bt_fw ) THEN
+         zt = REAL( Agrif_NbStepint()+0.5_wp, wp ) / zrhot
       ELSE
-         zt = REAL(Agrif_NbStepint(),wp) / zrhot
-      ENDIF
-
+         zt = REAL( Agrif_NbStepint()       , wp ) / zrhot
+      ENDIF
+      !
       ! Linear interpolation of sea level
-      Agrif_SpecialValue    = 0.e0
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = .TRUE.
-      CALL Agrif_Bc_variable(sshn_id,calledweight=zt, procname=interpsshn )
+      CALL Agrif_Bc_variable( sshn_id, calledweight=zt, procname=interpsshn )
       Agrif_UseSpecialValue = .FALSE.
-
+      !
       ! Interpolate barotropic fluxes
       Agrif_SpecialValue=0.
       Agrif_UseSpecialValue = ln_spc_dyn
-
-      IF (ll_int_cons) THEN ! Conservative interpolation
+      !
+      IF( ll_int_cons ) THEN  ! Conservative interpolation
          ! orders matters here !!!!!!
-         CALL Agrif_Bc_variable(ub2b_interp_id,calledweight=1._wp, procname=interpub2b) ! Time integrated
-         CALL Agrif_Bc_variable(vb2b_interp_id,calledweight=1._wp, procname=interpvb2b)
+         CALL Agrif_Bc_variable( ub2b_interp_id, calledweight=1._wp, procname=interpub2b ) ! Time integrated
+         CALL Agrif_Bc_variable( vb2b_interp_id, calledweight=1._wp, procname=interpvb2b )
          bdy_tinterp = 1
-         CALL Agrif_Bc_variable(unb_id ,calledweight=1._wp, procname=interpunb) ! After
-         CALL Agrif_Bc_variable(vnb_id ,calledweight=1._wp, procname=interpvnb)
+         CALL Agrif_Bc_variable( unb_id        , calledweight=1._wp, procname=interpunb  ) ! After
+         CALL Agrif_Bc_variable( vnb_id        , calledweight=1._wp, procname=interpvnb  )
          bdy_tinterp = 2
-         CALL Agrif_Bc_variable(unb_id ,calledweight=0._wp, procname=interpunb) ! Before
-         CALL Agrif_Bc_variable(vnb_id ,calledweight=0._wp, procname=interpvnb)         
+         CALL Agrif_Bc_variable( unb_id        , calledweight=0._wp, procname=interpunb  ) ! Before
+         CALL Agrif_Bc_variable( vnb_id        , calledweight=0._wp, procname=interpvnb  )         
       ELSE ! Linear interpolation
          bdy_tinterp = 0
-         ubdy_w(:) = 0.e0 ; vbdy_w(:) = 0.e0 
-         ubdy_e(:) = 0.e0 ; vbdy_e(:) = 0.e0 
-         ubdy_n(:) = 0.e0 ; vbdy_n(:) = 0.e0 
-         ubdy_s(:) = 0.e0 ; vbdy_s(:) = 0.e0 
-         CALL Agrif_Bc_variable(unb_id,calledweight=zt, procname=interpunb)
-         CALL Agrif_Bc_variable(vnb_id,calledweight=zt, procname=interpvnb)
+         ubdy_w(:) = 0._wp   ;   vbdy_w(:) = 0._wp 
+         ubdy_e(:) = 0._wp   ;   vbdy_e(:) = 0._wp 
+         ubdy_n(:) = 0._wp   ;   vbdy_n(:) = 0._wp 
+         ubdy_s(:) = 0._wp   ;   vbdy_s(:) = 0._wp
+         CALL Agrif_Bc_variable( unb_id, calledweight=zt, procname=interpunb )
+         CALL Agrif_Bc_variable( vnb_id, calledweight=zt, procname=interpvnb )
       ENDIF
       Agrif_UseSpecialValue = .FALSE.
@@ -500,4 +499,5 @@
    END SUBROUTINE Agrif_dta_ts
 
+
    SUBROUTINE Agrif_ssh( kt )
       !!----------------------------------------------------------------------
@@ -507,28 +507,29 @@
       !!
       !!----------------------------------------------------------------------  
-
+      !
       IF( Agrif_Root() )   RETURN
-
+      !
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
          ssha(2,:)=ssha(3,:)
          sshn(2,:)=sshn(3,:)
       ENDIF
-
+      !
       IF((nbondi == 1).OR.(nbondi == 2)) THEN
          ssha(nlci-1,:)=ssha(nlci-2,:)
          sshn(nlci-1,:)=sshn(nlci-2,:)
       ENDIF
-
+      !
       IF((nbondj == -1).OR.(nbondj == 2)) THEN
          ssha(:,2)=ssha(:,3)
          sshn(:,2)=sshn(:,3)
       ENDIF
-
+      !
       IF((nbondj == 1).OR.(nbondj == 2)) THEN
          ssha(:,nlcj-1)=ssha(:,nlcj-2)
          sshn(:,nlcj-1)=sshn(:,nlcj-2)
       ENDIF
-
+      !
    END SUBROUTINE Agrif_ssh
+
 
    SUBROUTINE Agrif_ssh_ts( jn )
@@ -540,32 +541,33 @@
       INTEGER :: ji,jj
       !!----------------------------------------------------------------------  
-
+      !
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
-         DO jj=1,jpj
+         DO jj = 1, jpj
             ssha_e(2,jj) = hbdy_w(jj)
          END DO
       ENDIF
-
+      !
       IF((nbondi == 1).OR.(nbondi == 2)) THEN
-         DO jj=1,jpj
+         DO jj = 1, jpj
             ssha_e(nlci-1,jj) = hbdy_e(jj)
          END DO
       ENDIF
-
+      !
       IF((nbondj == -1).OR.(nbondj == 2)) THEN
-         DO ji=1,jpi
+         DO ji = 1, jpi
             ssha_e(ji,2) = hbdy_s(ji)
          END DO
       ENDIF
-
+      !
       IF((nbondj == 1).OR.(nbondj == 2)) THEN
-         DO ji=1,jpi
+         DO ji = 1, jpi
             ssha_e(ji,nlcj-1) = hbdy_n(ji)
          END DO
       ENDIF
-
+      !
    END SUBROUTINE Agrif_ssh_ts
 
 # if defined key_zdftke
+
    SUBROUTINE Agrif_tke
       !!----------------------------------------------------------------------
@@ -573,33 +575,36 @@
       !!----------------------------------------------------------------------  
       REAL(wp) ::   zalpha
+      !!----------------------------------------------------------------------  
       !
       zalpha = REAL( Agrif_NbStepint() + Agrif_IRhot() - 1, wp ) / REAL( Agrif_IRhot(), wp )
       IF( zalpha > 1. )   zalpha = 1.
-      
+      !
       Agrif_SpecialValue    = 0.e0
       Agrif_UseSpecialValue = .TRUE.
-      
+      !
       CALL Agrif_Bc_variable(avm_id ,calledweight=zalpha, procname=interpavm)       
-              
+      !
       Agrif_UseSpecialValue = .FALSE.
       !
    END SUBROUTINE Agrif_tke
+   
 # endif
 
-   SUBROUTINE interptsn(ptab,i1,i2,j1,j2,k1,k2,n1,n2,before,nb,ndir)
-      !!---------------------------------------------
+   SUBROUTINE interptsn( ptab, i1, i2, j1, j2, k1, k2, n1, n2, before, nb, ndir )
+      !!----------------------------------------------------------------------
       !!   *** ROUTINE interptsn ***
-      !!---------------------------------------------
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: ptab
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2,n1,n2
-      LOGICAL, INTENT(in) :: before
-      INTEGER, INTENT(in) :: nb , ndir
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) ::   ptab
+      INTEGER                                     , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, n1, n2
+      LOGICAL                                     , INTENT(in   ) ::   before
+      INTEGER                                     , INTENT(in   ) ::   nb , ndir
       !
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
-      INTEGER :: imin, imax, jmin, jmax
+      INTEGER  ::   imin, imax, jmin, jmax
       REAL(wp) ::   zrhox , zalpha1, zalpha2, zalpha3
       REAL(wp) ::   zalpha4, zalpha5, zalpha6, zalpha7
-      LOGICAL :: western_side, eastern_side,northern_side,southern_side
-
+      LOGICAL  ::   western_side, eastern_side,northern_side,southern_side
+      !!----------------------------------------------------------------------
+      !
       IF (before) THEN         
          ptab(i1:i2,j1:j2,k1:k2,n1:n2) = tsn(i1:i2,j1:j2,k1:k2,n1:n2)
@@ -634,14 +639,14 @@
          IF((nbondi == +1).OR.(nbondi == 2)) imax = nlci-2        
          !
-         IF( eastern_side) THEN
+         IF( eastern_side ) THEN
             DO jn = 1, jpts
                tsa(nlci,j1:j2,k1:k2,jn) = zalpha1 * ptab(nlci,j1:j2,k1:k2,jn) + zalpha2 * ptab(nlci-1,j1:j2,k1:k2,jn)
                DO jk = 1, jpkm1
                   DO jj = jmin,jmax
-                     IF( umask(nlci-2,jj,jk) == 0.e0 ) THEN
+                     IF( umask(nlci-2,jj,jk) == 0._wp ) THEN
                         tsa(nlci-1,jj,jk,jn) = tsa(nlci,jj,jk,jn) * tmask(nlci-1,jj,jk)
                      ELSE
                         tsa(nlci-1,jj,jk,jn)=(zalpha4*tsa(nlci,jj,jk,jn)+zalpha3*tsa(nlci-2,jj,jk,jn))*tmask(nlci-1,jj,jk)
-                        IF( un(nlci-2,jj,jk) > 0.e0 ) THEN
+                        IF( un(nlci-2,jj,jk) > 0._wp ) THEN
                            tsa(nlci-1,jj,jk,jn)=( zalpha6*tsa(nlci-2,jj,jk,jn)+zalpha5*tsa(nlci,jj,jk,jn) & 
                                  + zalpha7*tsa(nlci-3,jj,jk,jn) ) * tmask(nlci-1,jj,jk)
@@ -651,5 +656,5 @@
                END DO
                tsa(nlci,j1:j2,k1:k2,jn) = 0._wp
-            ENDDO
+            END DO
          ENDIF
          ! 
@@ -659,9 +664,9 @@
                DO jk = 1, jpkm1
                   DO ji = imin,imax
-                     IF( vmask(ji,nlcj-2,jk) == 0.e0 ) THEN
+                     IF( vmask(ji,nlcj-2,jk) == 0._wp ) THEN
                         tsa(ji,nlcj-1,jk,jn) = tsa(ji,nlcj,jk,jn) * tmask(ji,nlcj-1,jk)
                      ELSE
                         tsa(ji,nlcj-1,jk,jn)=(zalpha4*tsa(ji,nlcj,jk,jn)+zalpha3*tsa(ji,nlcj-2,jk,jn))*tmask(ji,nlcj-1,jk)        
-                        IF (vn(ji,nlcj-2,jk) > 0.e0 ) THEN
+                        IF (vn(ji,nlcj-2,jk) > 0._wp ) THEN
                            tsa(ji,nlcj-1,jk,jn)=( zalpha6*tsa(ji,nlcj-2,jk,jn)+zalpha5*tsa(ji,nlcj,jk,jn)  &
                                  + zalpha7*tsa(ji,nlcj-3,jk,jn) ) * tmask(ji,nlcj-1,jk)
@@ -671,17 +676,17 @@
                END DO
                tsa(i1:i2,nlcj,k1:k2,jn) = 0._wp
-            ENDDO
-         ENDIF
-         !
-         IF( western_side) THEN            
+            END DO
+         ENDIF
+         !
+         IF( western_side ) THEN            
             DO jn = 1, jpts
                tsa(1,j1:j2,k1:k2,jn) = zalpha1 * ptab(1,j1:j2,k1:k2,jn) + zalpha2 * ptab(2,j1:j2,k1:k2,jn)
                DO jk = 1, jpkm1
                   DO jj = jmin,jmax
-                     IF( umask(2,jj,jk) == 0.e0 ) THEN
+                     IF( umask(2,jj,jk) == 0._wp ) THEN
                         tsa(2,jj,jk,jn) = tsa(1,jj,jk,jn) * tmask(2,jj,jk)
                      ELSE
                         tsa(2,jj,jk,jn)=(zalpha4*tsa(1,jj,jk,jn)+zalpha3*tsa(3,jj,jk,jn))*tmask(2,jj,jk)        
-                        IF( un(2,jj,jk) < 0.e0 ) THEN
+                        IF( un(2,jj,jk) < 0._wp ) THEN
                            tsa(2,jj,jk,jn)=(zalpha6*tsa(3,jj,jk,jn)+zalpha5*tsa(1,jj,jk,jn)+zalpha7*tsa(4,jj,jk,jn))*tmask(2,jj,jk)
                         ENDIF
@@ -696,11 +701,11 @@
             DO jn = 1, jpts
                tsa(i1:i2,1,k1:k2,jn) = zalpha1 * ptab(i1:i2,1,k1:k2,jn) + zalpha2 * ptab(i1:i2,2,k1:k2,jn)
-               DO jk=1,jpk      
+               DO jk = 1, jpk      
                   DO ji=imin,imax
-                     IF( vmask(ji,2,jk) == 0.e0 ) THEN
+                     IF( vmask(ji,2,jk) == 0._wp ) THEN
                         tsa(ji,2,jk,jn)=tsa(ji,1,jk,jn) * tmask(ji,2,jk)
                      ELSE
                         tsa(ji,2,jk,jn)=(zalpha4*tsa(ji,1,jk,jn)+zalpha3*tsa(ji,3,jk,jn))*tmask(ji,2,jk)
-                        IF( vn(ji,2,jk) < 0.e0 ) THEN
+                        IF( vn(ji,2,jk) < 0._wp ) THEN
                            tsa(ji,2,jk,jn)=(zalpha6*tsa(ji,3,jk,jn)+zalpha5*tsa(ji,1,jk,jn)+zalpha7*tsa(ji,4,jk,jn))*tmask(ji,2,jk)
                         ENDIF
@@ -709,5 +714,5 @@
                END DO
                tsa(i1:i2,1,k1:k2,jn) = 0._wp
-            ENDDO
+            END DO
          ENDIF
          !
@@ -735,12 +740,14 @@
    END SUBROUTINE interptsn
 
-   SUBROUTINE interpsshn(ptab,i1,i2,j1,j2,before,nb,ndir)
+
+   SUBROUTINE interpsshn( ptab, i1, i2, j1, j2, before, nb, ndir )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interpsshn  ***
       !!----------------------------------------------------------------------  
-      INTEGER, INTENT(in) :: i1,i2,j1,j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
-      INTEGER, INTENT(in) :: nb , ndir
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      INTEGER                         , INTENT(in   ) ::   nb , ndir
+      !
       LOGICAL :: western_side, eastern_side,northern_side,southern_side
       !!----------------------------------------------------------------------  
@@ -761,32 +768,26 @@
    END SUBROUTINE interpsshn
 
-   SUBROUTINE interpun(ptab,i1,i2,j1,j2,k1,k2, before)
-      !!---------------------------------------------
+
+   SUBROUTINE interpun( ptab, i1, i2, j1, j2, k1, k2, before )
+      !!----------------------------------------------------------------------
       !!   *** ROUTINE interpun ***
-      !!---------------------------------------------    
-      !!
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
-      !!
-      INTEGER :: ji,jj,jk
-      REAL(wp) :: zrhoy	
-      !!---------------------------------------------    
-      !
-      IF (before) THEN 
-         DO jk=1,jpk
-            DO jj=j1,j2
-               DO ji=i1,i2
-                  ptab(ji,jj,jk) = e2u(ji,jj) * un(ji,jj,jk)
-                  ptab(ji,jj,jk) = ptab(ji,jj,jk) * fse3u(ji,jj,jk)
-               END DO
-            END DO
+      !!----------------------------------------------------------------------
+      INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   ptab
+      LOGICAL                               , INTENT(in   ) ::   before
+      !
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zrhoy	
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN 
+         DO jk = k1, jpk
+            ptab(i1:i2,j1:j2,jk) = e2u(i1:i2,j1:j2) * e3u_n(i1:i2,j1:j2,jk) * un(i1:i2,j1:j2,jk)
          END DO
       ELSE
          zrhoy = Agrif_Rhoy()
-         DO jk=1,jpkm1
+         DO jk = 1, jpkm1
             DO jj=j1,j2
-               ua(i1:i2,jj,jk) = (ptab(i1:i2,jj,jk)/(zrhoy*e2u(i1:i2,jj)))
-               ua(i1:i2,jj,jk) = ua(i1:i2,jj,jk) / fse3u(i1:i2,jj,jk)
+               ua(i1:i2,jj,jk) = ptab(i1:i2,jj,jk) / ( zrhoy * e2u(i1:i2,jj) * e3u_n(i1:i2,jj,jk) )
             END DO
          END DO
@@ -795,59 +796,47 @@
    END SUBROUTINE interpun
 
-   SUBROUTINE interpvn(ptab,i1,i2,j1,j2,k1,k2, before)
-      !!---------------------------------------------
+
+   SUBROUTINE interpvn( ptab, i1, i2, j1, j2, k1, k2, before )
+      !!----------------------------------------------------------------------
       !!   *** ROUTINE interpvn ***
-      !!---------------------------------------------    
-      !
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
-      !
-      INTEGER :: ji,jj,jk
-      REAL(wp) :: zrhox	
-      !!---------------------------------------------    
+      !!----------------------------------------------------------------------
+      INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   ptab
+      LOGICAL                               , INTENT(in   ) ::   before
+      !
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zrhox	
+      !!----------------------------------------------------------------------
       !      
-      IF (before) THEN          
-         !interpv entre 1 et k2 et interpv2d en jpkp1
-         DO jk=k1,jpk
-            DO jj=j1,j2
-               DO ji=i1,i2
-                  ptab(ji,jj,jk) = e1v(ji,jj) * vn(ji,jj,jk)
-                  ptab(ji,jj,jk) = ptab(ji,jj,jk) * fse3v(ji,jj,jk)
-               END DO
-            END DO
+      IF( before ) THEN       !interpv entre 1 et k2 et interpv2d en jpkp1
+         DO jk = k1, jpk
+            ptab(i1:i2,j1:j2,jk) = e1v(i1:i2,j1:j2) * e3v_n(i1:i2,j1:j2,jk) * vn(i1:i2,j1:j2,jk)
          END DO
       ELSE          
          zrhox= Agrif_Rhox()
-         DO jk=1,jpkm1
-            DO jj=j1,j2
-               va(i1:i2,jj,jk) = (ptab(i1:i2,jj,jk)/(zrhox*e1v(i1:i2,jj)))
-               va(i1:i2,jj,jk) = va(i1:i2,jj,jk) / fse3v(i1:i2,jj,jk)
-            END DO
+         DO jk = 1, jpkm1
+            va(i1:i2,j1:j2,jk) = ptab(i1:i2,j1:j2,jk) / ( zrhox * e1v(i1:i2,j1:j2) * e3v_n(i1:i2,j1:j2,jk) )
          END DO
       ENDIF
       !        
    END SUBROUTINE interpvn
-
-   SUBROUTINE interpunb(ptab,i1,i2,j1,j2,before,nb,ndir)
+   
+
+   SUBROUTINE interpunb( ptab, i1, i2, j1, j2, before, nb, ndir )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interpunb  ***
       !!----------------------------------------------------------------------  
-      INTEGER, INTENT(in) :: i1,i2,j1,j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
-      INTEGER, INTENT(in) :: nb , ndir
-      !!
-      INTEGER :: ji,jj
-      REAL(wp) :: zrhoy, zrhot, zt0, zt1, ztcoeff
-      LOGICAL :: western_side, eastern_side,northern_side,southern_side
-      !!----------------------------------------------------------------------  
-      !
-      IF (before) THEN 
-         DO jj=j1,j2
-            DO ji=i1,i2
-               ptab(ji,jj) = un_b(ji,jj) * e2u(ji,jj) * hu(ji,jj) 
-            END DO
-         END DO
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      INTEGER                         , INTENT(in   ) ::   nb , ndir
+      !
+      INTEGER  ::   ji, jj
+      REAL(wp) ::   zrhoy, zrhot, zt0, zt1, ztcoeff
+      LOGICAL  ::   western_side, eastern_side,northern_side,southern_side
+      !!----------------------------------------------------------------------  
+      !
+      IF( before ) THEN 
+         ptab(i1:i2,j1:j2) = e2u(i1:i2,j1:j2) * hu_n(i1:i2,j1:j2) * un_b(i1:i2,j1:j2)
       ELSE
          western_side  = (nb == 1).AND.(ndir == 1)
@@ -863,8 +852,8 @@
          IF( bdy_tinterp == 1 ) THEN
             ztcoeff = zrhot * (  zt1**2._wp * (       zt1 - 1._wp)        &
-                  &      - zt0**2._wp * (       zt0 - 1._wp)        )
+               &               - zt0**2._wp * (       zt0 - 1._wp)        )
          ELSEIF( bdy_tinterp == 2 ) THEN
             ztcoeff = zrhot * (  zt1        * (       zt1 - 1._wp)**2._wp &
-                  &      - zt0        * (       zt0 - 1._wp)**2._wp ) 
+               &               - zt0        * (       zt0 - 1._wp)**2._wp ) 
 
          ELSE
@@ -887,18 +876,14 @@
          IF( bdy_tinterp == 0 .OR. bdy_tinterp == 2) THEN
             IF(western_side) THEN
-               ubdy_w(j1:j2) = ubdy_w(j1:j2) / (zrhoy*e2u(i1,j1:j2))   &
-                     &                                  * umask(i1,j1:j2,1)
+               ubdy_w(j1:j2) = ubdy_w(j1:j2) / (zrhoy*e2u(i1,j1:j2)) * umask(i1,j1:j2,1)
             ENDIF
             IF(eastern_side) THEN
-               ubdy_e(j1:j2) = ubdy_e(j1:j2) / (zrhoy*e2u(i1,j1:j2))   &
-                     &                                  * umask(i1,j1:j2,1)
+               ubdy_e(j1:j2) = ubdy_e(j1:j2) / (zrhoy*e2u(i1,j1:j2)) * umask(i1,j1:j2,1)
             ENDIF
             IF(southern_side) THEN
-               ubdy_s(i1:i2) = ubdy_s(i1:i2) / (zrhoy*e2u(i1:i2,j1))   &
-                     &                                  * umask(i1:i2,j1,1)
+               ubdy_s(i1:i2) = ubdy_s(i1:i2) / (zrhoy*e2u(i1:i2,j1)) * umask(i1:i2,j1,1)
             ENDIF
             IF(northern_side) THEN
-               ubdy_n(i1:i2) = ubdy_n(i1:i2) / (zrhoy*e2u(i1:i2,j1))   &
-                     &                                  * umask(i1:i2,j1,1)
+               ubdy_n(i1:i2) = ubdy_n(i1:i2) / (zrhoy*e2u(i1:i2,j1)) * umask(i1:i2,j1,1)
             ENDIF
          ENDIF
@@ -907,24 +892,21 @@
    END SUBROUTINE interpunb
 
-   SUBROUTINE interpvnb(ptab,i1,i2,j1,j2,before,nb,ndir)
+
+   SUBROUTINE interpvnb( ptab, i1, i2, j1, j2, before, nb, ndir )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interpvnb  ***
       !!----------------------------------------------------------------------  
-      INTEGER, INTENT(in) :: i1,i2,j1,j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
-      INTEGER, INTENT(in) :: nb , ndir
-      !!
-      INTEGER :: ji,jj
-      REAL(wp) :: zrhox, zrhot, zt0, zt1, ztcoeff   
-      LOGICAL :: western_side, eastern_side,northern_side,southern_side
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      INTEGER                         , INTENT(in   ) ::   nb , ndir
+      !
+      INTEGER  ::   ji,jj
+      REAL(wp) ::   zrhox, zrhot, zt0, zt1, ztcoeff   
+      LOGICAL  ::   western_side, eastern_side,northern_side,southern_side
       !!----------------------------------------------------------------------  
       ! 
-      IF (before) THEN 
-         DO jj=j1,j2
-            DO ji=i1,i2
-               ptab(ji,jj) = vn_b(ji,jj) * e1v(ji,jj) * hv(ji,jj) 
-            END DO
-         END DO
+      IF( before ) THEN 
+         ptab(i1:i2,j1:j2) = e1v(i1:i2,j1:j2) * hv_n(i1:i2,j1:j2) * vn_b(i1:i2,j1:j2)
       ELSE
          western_side  = (nb == 1).AND.(ndir == 1)
@@ -939,9 +921,8 @@
          IF( bdy_tinterp == 1 ) THEN
             ztcoeff = zrhot * (  zt1**2._wp * (       zt1 - 1._wp)        &
-                  &      - zt0**2._wp * (       zt0 - 1._wp)        )
+               &               - zt0**2._wp * (       zt0 - 1._wp)        )
          ELSEIF( bdy_tinterp == 2 ) THEN
             ztcoeff = zrhot * (  zt1        * (       zt1 - 1._wp)**2._wp &
-                  &      - zt0        * (       zt0 - 1._wp)**2._wp ) 
-
+               &               - zt0        * (       zt0 - 1._wp)**2._wp ) 
          ELSE
             ztcoeff = 1
@@ -983,23 +964,20 @@
    END SUBROUTINE interpvnb
 
-   SUBROUTINE interpub2b(ptab,i1,i2,j1,j2,before,nb,ndir)
+
+   SUBROUTINE interpub2b( ptab, i1, i2, j1, j2, before, nb, ndir )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interpub2b  ***
       !!----------------------------------------------------------------------  
-      INTEGER, INTENT(in) :: i1,i2,j1,j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
-      INTEGER, INTENT(in) :: nb , ndir
-      !!
-      INTEGER :: ji,jj
-      REAL(wp) :: zrhot, zt0, zt1,zat
-      LOGICAL :: western_side, eastern_side,northern_side,southern_side
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      INTEGER                         , INTENT(in   ) ::   nb , ndir
+      !
+      INTEGER  ::   ji,jj
+      REAL(wp) ::   zrhot, zt0, zt1,zat
+      LOGICAL  ::   western_side, eastern_side,northern_side,southern_side
       !!----------------------------------------------------------------------  
       IF( before ) THEN
-         DO jj=j1,j2
-            DO ji=i1,i2
-               ptab(ji,jj) = ub2_b(ji,jj) * e2u(ji,jj)
-            END DO
-         END DO
+         ptab(i1:i2,j1:j2) = e2u(i1:i2,j1:j2) * ub2_b(i1:i2,j1:j2)
       ELSE
          western_side  = (nb == 1).AND.(ndir == 1)
@@ -1012,6 +990,6 @@
          zt1 = REAL(Agrif_NbStepint()+1, wp) / zrhot
          ! Polynomial interpolation coefficients:
-         zat = zrhot * (  zt1**2._wp * (-2._wp*zt1 + 3._wp)        &
-               &      - zt0**2._wp * (-2._wp*zt0 + 3._wp)        ) 
+         zat = zrhot * (  zt1**2._wp * (-2._wp*zt1 + 3._wp)    &
+            &           - zt0**2._wp * (-2._wp*zt0 + 3._wp)    ) 
          ! 
          IF(western_side ) ubdy_w(j1:j2) = zat * ptab(i1,j1:j2)  
@@ -1022,25 +1000,22 @@
       ! 
    END SUBROUTINE interpub2b
-
-   SUBROUTINE interpvb2b(ptab,i1,i2,j1,j2,before,nb,ndir)
+   
+
+   SUBROUTINE interpvb2b( ptab, i1, i2, j1, j2, before, nb, ndir )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interpvb2b  ***
       !!----------------------------------------------------------------------  
-      INTEGER, INTENT(in) :: i1,i2,j1,j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
-      INTEGER, INTENT(in) :: nb , ndir
-      !!
-      INTEGER :: ji,jj
-      REAL(wp) :: zrhot, zt0, zt1,zat
-      LOGICAL :: western_side, eastern_side,northern_side,southern_side
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      INTEGER                         , INTENT(in   ) ::   nb , ndir
+      !
+      INTEGER ::   ji,jj
+      REAL(wp) ::   zrhot, zt0, zt1,zat
+      LOGICAL ::   western_side, eastern_side,northern_side,southern_side
       !!----------------------------------------------------------------------  
       !
       IF( before ) THEN
-         DO jj=j1,j2
-            DO ji=i1,i2
-               ptab(ji,jj) = vb2_b(ji,jj) * e1v(ji,jj)
-            END DO
-         END DO
+         ptab(i1:i2,j1:j2) = e1v(i1:i2,j1:j2) * vb2_b(i1:i2,j1:j2)
       ELSE      
          western_side  = (nb == 1).AND.(ndir == 1)
@@ -1053,24 +1028,24 @@
          zt1 = REAL(Agrif_NbStepint()+1, wp) / zrhot
          ! Polynomial interpolation coefficients:
-         zat = zrhot * (  zt1**2._wp * (-2._wp*zt1 + 3._wp)        &
-               &      - zt0**2._wp * (-2._wp*zt0 + 3._wp)        ) 
-         !
-         IF(western_side ) vbdy_w(j1:j2) = zat * ptab(i1,j1:j2)  
-         IF(eastern_side ) vbdy_e(j1:j2) = zat * ptab(i1,j1:j2)  
-         IF(southern_side) vbdy_s(i1:i2) = zat * ptab(i1:i2,j1) 
-         IF(northern_side) vbdy_n(i1:i2) = zat * ptab(i1:i2,j1) 
+         zat = zrhot * (  zt1**2._wp * (-2._wp*zt1 + 3._wp)    &
+            &           - zt0**2._wp * (-2._wp*zt0 + 3._wp)    ) 
+         !
+         IF(western_side )   vbdy_w(j1:j2) = zat * ptab(i1,j1:j2)  
+         IF(eastern_side )   vbdy_e(j1:j2) = zat * ptab(i1,j1:j2)  
+         IF(southern_side)   vbdy_s(i1:i2) = zat * ptab(i1:i2,j1) 
+         IF(northern_side)   vbdy_n(i1:i2) = zat * ptab(i1:i2,j1) 
       ENDIF
       !      
    END SUBROUTINE interpvb2b
 
-   SUBROUTINE interpe3t(ptab,i1,i2,j1,j2,k1,k2,before,nb,ndir)
+
+   SUBROUTINE interpe3t( ptab, i1, i2, j1, j2, k1, k2, before, nb, ndir )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interpe3t  ***
       !!----------------------------------------------------------------------  
-      ! 
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
+      INTEGER                              , INTENT(in   ) :: i1, i2, j1, j2, k1, k2
       REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
-      LOGICAL :: before
-      INTEGER, INTENT(in) :: nb , ndir
+      LOGICAL                              , INTENT(in   ) :: before
+      INTEGER                              , INTENT(in   ) :: nb , ndir
       !
       INTEGER :: ji, jj, jk
@@ -1079,12 +1054,6 @@
       !!----------------------------------------------------------------------  
       !    
-      IF (before) THEN
-         DO jk=k1,k2
-            DO jj=j1,j2
-               DO ji=i1,i2
-                  ptab(ji,jj,jk) = tmask(ji,jj,jk) * e3t_0(ji,jj,jk)
-               END DO
-            END DO
-         END DO
+      IF( before ) THEN
+         ptab(i1:i2,j1:j2,k1:k2) = tmask(i1:i2,j1:j2,k1:k2) * e3t_0(i1:i2,j1:j2,k1:k2)
       ELSE
          western_side  = (nb == 1).AND.(ndir == 1)
@@ -1093,14 +1062,14 @@
          northern_side = (nb == 2).AND.(ndir == 2)
 
-         DO jk=k1,k2
-            DO jj=j1,j2
-               DO ji=i1,i2
+         DO jk = k1, k2
+            DO jj = j1, j2
+               DO ji = i1, i2
                   ! Get velocity mask at boundary edge points:
-                  IF (western_side)  ztmpmsk = umask(ji    ,jj    ,1)
-                  IF (eastern_side)  ztmpmsk = umask(nlci-2,jj    ,1)
-                  IF (northern_side) ztmpmsk = vmask(ji    ,nlcj-2,1)
-                  IF (southern_side) ztmpmsk = vmask(ji    ,2     ,1)
-
-                  IF (ABS(ptab(ji,jj,jk) - tmask(ji,jj,jk) * e3t_0(ji,jj,jk))*ztmpmsk > 1.D-2) THEN
+                  IF( western_side )   ztmpmsk = umask(ji    ,jj    ,1)
+                  IF( eastern_side )   ztmpmsk = umask(nlci-2,jj    ,1)
+                  IF( northern_side)   ztmpmsk = vmask(ji    ,nlcj-2,1)
+                  IF( southern_side)   ztmpmsk = vmask(ji    ,2     ,1)
+                  !
+                  IF( ABS( ptab(ji,jj,jk) - tmask(ji,jj,jk) * e3t_0(ji,jj,jk) )*ztmpmsk > 1.D-2) THEN
                      IF (western_side) THEN
                         WRITE(numout,*) 'ERROR bathymetry merge at the western border ji,jj,jk ', ji+nimpp-1,jj+njmpp-1,jk
@@ -1112,5 +1081,5 @@
                         WRITE(numout,*) 'ERROR bathymetry merge at the northen border ji,jj,jk', ji+nimpp-1,jj+njmpp-1,jk
                      ENDIF
-                     WRITE(numout,*) '      ptab(ji,jj,jk), fse3t(ji,jj,jk) ', ptab(ji,jj,jk), e3t_0(ji,jj,jk)
+                     WRITE(numout,*) '      ptab(ji,jj,jk), e3t(ji,jj,jk) ', ptab(ji,jj,jk), e3t_0(ji,jj,jk)
                      kindic_agr = kindic_agr + 1
                   ENDIF
@@ -1118,38 +1087,31 @@
             END DO
          END DO
-
+         !
       ENDIF
       ! 
    END SUBROUTINE interpe3t
 
-   SUBROUTINE interpumsk(ptab,i1,i2,j1,j2,k1,k2,before,nb,ndir)
+
+   SUBROUTINE interpumsk( ptab, i1, i2, j1, j2, k1, k2, before, nb, ndir )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interpumsk  ***
       !!----------------------------------------------------------------------  
-      ! 
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
-      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
-      LOGICAL :: before
-      INTEGER, INTENT(in) :: nb , ndir
-      !
-      INTEGER :: ji, jj, jk
-      LOGICAL :: western_side, eastern_side   
+      INTEGER                              , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   ptab
+      LOGICAL                              , INTENT(in   ) ::   before
+      INTEGER                              , INTENT(in   ) ::   nb , ndir
+      !
+      INTEGER ::   ji, jj, jk
+      LOGICAL ::   western_side, eastern_side   
       !!----------------------------------------------------------------------  
       !    
-      IF (before) THEN
-         DO jk=k1,k2
-            DO jj=j1,j2
-               DO ji=i1,i2
-                  ptab(ji,jj,jk) = umask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
+      IF( before ) THEN
+         ptab(i1:i2,j1:j2,k1:k2) = umask(i1:i2,j1:j2,k1:k2)
       ELSE
-
-         western_side  = (nb == 1).AND.(ndir == 1)
-         eastern_side  = (nb == 1).AND.(ndir == 2)
-         DO jk=k1,k2
-            DO jj=j1,j2
-               DO ji=i1,i2
+         western_side = (nb == 1).AND.(ndir == 1)
+         eastern_side = (nb == 1).AND.(ndir == 2)
+         DO jk = k1, k2
+            DO jj = j1, j2
+               DO ji = i1, i2
                    ! Velocity mask at boundary edge points:
                   IF (ABS(ptab(ji,jj,jk) - umask(ji,jj,jk)) > 1.D-2) THEN
@@ -1167,38 +1129,31 @@
             END DO
          END DO
-
+         !
       ENDIF
       ! 
    END SUBROUTINE interpumsk
 
-   SUBROUTINE interpvmsk(ptab,i1,i2,j1,j2,k1,k2,before,nb,ndir)
+
+   SUBROUTINE interpvmsk( ptab, i1, i2, j1, j2, k1, k2, before, nb, ndir )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interpvmsk  ***
       !!----------------------------------------------------------------------  
-      ! 
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
-      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
-      LOGICAL :: before
-      INTEGER, INTENT(in) :: nb , ndir
-      !
-      INTEGER :: ji, jj, jk
-      LOGICAL :: northern_side, southern_side     
+      INTEGER                              , INTENT(in   ) ::   i1,i2,j1,j2,k1,k2
+      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   ptab
+      LOGICAL                              , INTENT(in   ) ::   before
+      INTEGER                              , INTENT(in   ) :: nb , ndir
+      !
+      INTEGER ::   ji, jj, jk
+      LOGICAL ::   northern_side, southern_side     
       !!----------------------------------------------------------------------  
       !    
-      IF (before) THEN
-         DO jk=k1,k2
-            DO jj=j1,j2
-               DO ji=i1,i2
-                  ptab(ji,jj,jk) = vmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
+      IF( before ) THEN
+         ptab(i1:i2,j1:j2,k1:k2) = vmask(i1:i2,j1:j2,k1:k2)
       ELSE
-
          southern_side = (nb == 2).AND.(ndir == 1)
          northern_side = (nb == 2).AND.(ndir == 2)
-         DO jk=k1,k2
-            DO jj=j1,j2
-               DO ji=i1,i2
+         DO jk = k1, k2
+            DO jj = j1, j2
+               DO ji = i1, i2
                    ! Velocity mask at boundary edge points:
                   IF (ABS(ptab(ji,jj,jk) - vmask(ji,jj,jk)) > 1.D-2) THEN
@@ -1216,5 +1171,5 @@
             END DO
          END DO
-
+         !
       ENDIF
       ! 
@@ -1223,14 +1178,14 @@
 # if defined key_zdftke
 
-   SUBROUTINE interpavm(ptab,i1,i2,j1,j2,k1,k2,before)
+   SUBROUTINE interpavm( ptab, i1, i2, j1, j2, k1, k2, before )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interavm  ***
       !!----------------------------------------------------------------------  
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
-      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
+      INTEGER                              , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   ptab
+      LOGICAL                              , INTENT(in   ) ::   before
       !!----------------------------------------------------------------------  
       !      
-      IF( before) THEN
+      IF( before ) THEN
          ptab (i1:i2,j1:j2,k1:k2) = avm_k(i1:i2,j1:j2,k1:k2)
       ELSE
Index: /trunk/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 6140)
@@ -2,4 +2,10 @@
 
 MODULE agrif_opa_sponge
+   !!======================================================================
+   !!                ***  MODULE agrif_opa_update  ***
+   !! AGRIF :   
+   !!======================================================================
+   !! History :  
+   !!----------------------------------------------------------------------
 #if defined key_agrif  && ! defined key_offline
    USE par_oce
@@ -17,12 +23,9 @@
    PUBLIC interptsn_sponge, interpun_sponge, interpvn_sponge
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.3 , NEMO Consortium (2010)
+   !! NEMO/NST 3.7 , NEMO Consortium (2015)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -31,7 +34,7 @@
       !!   *** ROUTINE Agrif_Sponge_Tra ***
       !!---------------------------------------------
-      !!
       REAL(wp) :: timecoeff
-
+      !!---------------------------------------------
+      !
 #if defined SPONGE
       timecoeff = REAL(Agrif_NbStepint(),wp)/Agrif_rhot()
@@ -46,13 +49,14 @@
       Agrif_UseSpecialValue = .FALSE.
 #endif
-
+      !
    END SUBROUTINE Agrif_Sponge_Tra
 
+
    SUBROUTINE Agrif_Sponge_dyn
       !!---------------------------------------------
       !!   *** ROUTINE Agrif_Sponge_dyn ***
       !!---------------------------------------------
-      !!
       REAL(wp) :: timecoeff
+      !!---------------------------------------------
 
 #if defined SPONGE
@@ -72,6 +76,7 @@
       Agrif_UseSpecialValue = .FALSE.
 #endif
-
+      !
    END SUBROUTINE Agrif_Sponge_dyn
+
 
    SUBROUTINE Agrif_Sponge
@@ -183,6 +188,7 @@
       !
 #endif
-
+      !
    END SUBROUTINE Agrif_Sponge
+
 
    SUBROUTINE interptsn_sponge(tabres,i1,i2,j1,j2,k1,k2,n1,n2,before)
@@ -193,6 +199,5 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: tabres
       LOGICAL, INTENT(in) :: before
-
-
+      !
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
       INTEGER  ::   iku, ikv
@@ -201,8 +206,8 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2) ::tsbdiff
       !
-      IF (before) THEN
+      IF( before ) THEN
          tabres(i1:i2,j1:j2,k1:k2,n1:n2) = tsn(i1:i2,j1:j2,k1:k2,n1:n2)
       ELSE   
-   
+         !
          tsbdiff(:,:,:,:) = tsb(i1:i2,j1:j2,:,:) - tabres(:,:,:,:)    
          DO jn = 1, jpts            
@@ -210,11 +215,11 @@
                DO jj = j1,j2-1
                   DO ji = i1,i2-1
-                     zabe1 = fsaht_spu(ji,jj) * umask(ji,jj,jk) * e2_e1u(ji,jj) * fse3u_n(ji,jj,jk)
-                     zabe2 = fsaht_spv(ji,jj) * vmask(ji,jj,jk) * e1_e2v(ji,jj) * fse3v_n(ji,jj,jk)
+                     zabe1 = fsaht_spu(ji,jj) * umask(ji,jj,jk) * e2_e1u(ji,jj) * e3u_n(ji,jj,jk)
+                     zabe2 = fsaht_spv(ji,jj) * vmask(ji,jj,jk) * e1_e2v(ji,jj) * e3v_n(ji,jj,jk)
                      ztu(ji,jj,jk) = zabe1 * ( tsbdiff(ji+1,jj  ,jk,jn) - tsbdiff(ji,jj,jk,jn) ) 
                      ztv(ji,jj,jk) = zabe2 * ( tsbdiff(ji  ,jj+1,jk,jn) - tsbdiff(ji,jj,jk,jn) )
-                  ENDDO
-               ENDDO
-
+                  END DO
+               END DO
+               !
                IF( ln_zps ) THEN      ! set gradient at partial step level
                   DO jj = j1,j2-1
@@ -223,21 +228,16 @@
                         iku = mbku(ji,jj)
                         ikv = mbkv(ji,jj)
-                        IF( iku == jk ) THEN
-                           ztu(ji,jj,jk) = 0._wp
-                        ENDIF
-                        IF( ikv == jk ) THEN
-                           ztv(ji,jj,jk) = 0._wp
-                        ENDIF
+                        IF( iku == jk )   ztu(ji,jj,jk) = 0._wp
+                        IF( ikv == jk )   ztv(ji,jj,jk) = 0._wp
                      END DO
                   END DO
                ENDIF
-            ENDDO
-
+            END DO
+            !
             DO jk = 1, jpkm1
                DO jj = j1+1,j2-1
                   DO ji = i1+1,i2-1
-
                      IF (.NOT. tabspongedone_tsn(ji,jj)) THEN 
-                        zbtr = r1_e1e2t(ji,jj) / fse3t_n(ji,jj,jk)
+                        zbtr = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                         ! horizontal diffusive trends
                         ztsa = zbtr * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk) + ztv(ji,jj,jk) - ztv(ji  ,jj-1,jk)  )
@@ -245,16 +245,16 @@
                         tsa(ji,jj,jk,jn) = tsa(ji,jj,jk,jn) + ztsa
                      ENDIF
-
-                  ENDDO
-               ENDDO
-
-            ENDDO
-         ENDDO
-
+                  END DO
+               END DO
+            END DO
+            !
+         END DO
+         !
          tabspongedone_tsn(i1+1:i2-1,j1+1:j2-1) = .TRUE.
-
-      ENDIF
-
+         !
+      ENDIF
+      !
    END SUBROUTINE interptsn_sponge
+
 
    SUBROUTINE interpun_sponge(tabres,i1,i2,j1,j2,k1,k2, before)
@@ -273,13 +273,11 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: rotdiff, hdivdiff
       INTEGER :: jmax
-      !
-
-
-      IF (before) THEN
+      !!---------------------------------------------    
+      !
+      IF( before ) THEN
          tabres = un(i1:i2,j1:j2,:)
       ELSE
-
          ubdiff(i1:i2,j1:j2,:) = (ub(i1:i2,j1:j2,:) - tabres(:,:,:))*umask(i1:i2,j1:j2,:)
-
+         !
          DO jk = 1, jpkm1                                 ! Horizontal slab
             !                                             ! ===============
@@ -290,7 +288,7 @@
             DO jj = j1,j2
                DO ji = i1+1,i2   ! vector opt.
-                  zbtr = r1_e1e2t(ji,jj) / fse3t_n(ji,jj,jk) * fsahm_spt(ji,jj)
-                  hdivdiff(ji,jj,jk) = (  e2u(ji  ,jj)*fse3u_n(ji  ,jj,jk) * ubdiff(ji  ,jj,jk) &
-                                     &   -e2u(ji-1,jj)*fse3u_n(ji-1,jj,jk) * ubdiff(ji-1,jj,jk) ) * zbtr
+                  zbtr = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk) * fsahm_spt(ji,jj)
+                  hdivdiff(ji,jj,jk) = (  e2u(ji  ,jj)*e3u_n(ji  ,jj,jk) * ubdiff(ji  ,jj,jk) &
+                                     &   -e2u(ji-1,jj)*e3u_n(ji-1,jj,jk) * ubdiff(ji-1,jj,jk) ) * zbtr
                END DO
             END DO
@@ -298,5 +296,5 @@
             DO jj = j1,j2-1
                DO ji = i1,i2   ! vector opt.
-                  zbtr = r1_e1e2f(ji,jj) * fse3f_n(ji,jj,jk) * fsahm_spf(ji,jj)
+                  zbtr = r1_e1e2f(ji,jj) * e3f_n(ji,jj,jk) * fsahm_spf(ji,jj)
                   rotdiff(ji,jj,jk) = (-e1u(ji,jj+1) * ubdiff(ji,jj+1,jk) &
                                        +e1u(ji,jj  ) * ubdiff(ji,jj  ,jk) & 
@@ -304,10 +302,6 @@
                END DO
             END DO
-         ENDDO
-
-         !
-
-
-
+         END DO
+         !
          DO jj = j1+1, j2-1
             DO ji = i1+1, i2-1   ! vector opt.
@@ -318,5 +312,5 @@
                      ze1v = hdivdiff(ji,jj,jk)
                      ! horizontal diffusive trends
-                     zua = - ( ze2u - rotdiff (ji,jj-1,jk)) / ( e2u(ji,jj) * fse3u_n(ji,jj,jk) )   &
+                     zua = - ( ze2u - rotdiff (ji,jj-1,jk)) / ( e2u(ji,jj) * e3u_n(ji,jj,jk) )   &
                            + ( hdivdiff(ji+1,jj,jk) - ze1v  ) / e1u(ji,jj)
 
@@ -344,5 +338,5 @@
 
                      ! horizontal diffusive trends
-                     zva = + ( ze2u - rotdiff (ji-1,jj,jk)) / ( e1v(ji,jj) * fse3v_n(ji,jj,jk) )   &
+                     zva = + ( ze2u - rotdiff (ji-1,jj,jk)) / ( e1v(ji,jj) * e3v_n(ji,jj,jk) )   &
                            + ( hdivdiff(ji,jj+1,jk) - ze1v  ) / e2v(ji,jj)
 
@@ -351,14 +345,12 @@
                   END DO
                ENDIF
-
-            END DO
-         END DO
-
-
+               !
+            END DO
+         END DO
+         !
          tabspongedone_v(i1+1:i2,j1+1:jmax) = .TRUE.
-
-      ENDIF
-
-
+         !
+      ENDIF
+      !
    END SUBROUTINE interpun_sponge
 
@@ -372,20 +364,18 @@
       LOGICAL, INTENT(in) :: before
       INTEGER, INTENT(in) :: nb , ndir
-
-      INTEGER :: ji,jj,jk
-
-      REAL(wp) :: ze2u, ze1v, zua, zva, zbtr
-
+      !
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   ze2u, ze1v, zua, zva, zbtr
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: vbdiff
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: rotdiff, hdivdiff
       INTEGER :: imax
-      !
-
-      IF (before) THEN 
+      !!--------------------------------------------- 
+
+      IF( before ) THEN 
          tabres = vn(i1:i2,j1:j2,:)
       ELSE
-
+         !
          vbdiff(i1:i2,j1:j2,:) = (vb(i1:i2,j1:j2,:) - tabres(:,:,:))*vmask(i1:i2,j1:j2,:)
-
+         !
          DO jk = 1, jpkm1                                 ! Horizontal slab
             !                                             ! ===============
@@ -396,18 +386,17 @@
             DO jj = j1+1,j2
                DO ji = i1,i2   ! vector opt.
-                  zbtr = r1_e1e2t(ji,jj) / fse3t_n(ji,jj,jk) * fsahm_spt(ji,jj)
-                  hdivdiff(ji,jj,jk) = ( e1v(ji,jj  ) * fse3v(ji,jj  ,jk) * vbdiff(ji,jj  ,jk)  &
-                                     &  -e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * vbdiff(ji,jj-1,jk)  ) * zbtr
+                  zbtr = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk) * fsahm_spt(ji,jj)
+                  hdivdiff(ji,jj,jk) = ( e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * vbdiff(ji,jj  ,jk)  &
+                                     &  -e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * vbdiff(ji,jj-1,jk)  ) * zbtr
                END DO
             END DO
             DO jj = j1,j2
                DO ji = i1,i2-1   ! vector opt.
-                  zbtr = r1_e1e2f(ji,jj) * fse3f_n(ji,jj,jk) * fsahm_spf(ji,jj)
+                  zbtr = r1_e1e2f(ji,jj) * e3f_n(ji,jj,jk) * fsahm_spf(ji,jj)
                   rotdiff(ji,jj,jk) = ( e2v(ji+1,jj) * vbdiff(ji+1,jj,jk) & 
-                                    &  -e2v(ji  ,jj) * vbdiff(ji  ,jj,jk) &
-                                    & ) * fmask(ji,jj,jk) * zbtr
-               END DO
-            END DO
-         ENDDO
+                                    &  -e2v(ji  ,jj) * vbdiff(ji  ,jj,jk)  ) * fmask(ji,jj,jk) * zbtr
+               END DO
+            END DO
+         END DO
 
          !                                                ! ===============
@@ -415,40 +404,27 @@
 
          imax = i2-1
-         IF ((nbondi == 1).OR.(nbondi == 2)) imax = MIN(imax,nlci-3)
+         IF ((nbondi == 1).OR.(nbondi == 2))   imax = MIN(imax,nlci-3)
 
          DO jj = j1+1, j2
             DO ji = i1+1, imax   ! vector opt.
-               IF (.NOT. tabspongedone_u(ji,jj)) THEN
-                  DO jk = 1, jpkm1                                 ! Horizontal slab
-                     ze2u = rotdiff (ji,jj,jk)
-                     ze1v = hdivdiff(ji,jj,jk)
-                     ! horizontal diffusive trends
-                     zua = - ( ze2u - rotdiff (ji,jj-1,jk)) / ( e2u(ji,jj) * fse3u_n(ji,jj,jk) ) + ( hdivdiff(ji+1,jj,jk) - ze1v) &
-                           / e1u(ji,jj)
-
-
-                     ! add it to the general momentum trends
-                     ua(ji,jj,jk) = ua(ji,jj,jk) + zua
-                  END DO
-
-               ENDIF
-            END DO
-         END DO
-
+               IF( .NOT. tabspongedone_u(ji,jj) ) THEN
+                  DO jk = 1, jpkm1
+                     ua(ji,jj,jk) = ua(ji,jj,jk)                                                               &
+                        & - ( rotdiff (ji  ,jj,jk) - rotdiff (ji,jj-1,jk)) / ( e2u(ji,jj) * e3u_n(ji,jj,jk) )  &
+                        & + ( hdivdiff(ji+1,jj,jk) - hdivdiff(ji,jj  ,jk)) * r1_e1u(ji,jj)
+                  END DO
+               ENDIF
+            END DO
+         END DO
+         !
          tabspongedone_u(i1+1:imax,j1+1:j2) = .TRUE.
-
+         !
          DO jj = j1+1, j2-1
             DO ji = i1+1, i2-1   ! vector opt.
-               IF (.NOT. tabspongedone_v(ji,jj)) THEN
-                  DO jk = 1, jpkm1                                 ! Horizontal slab
-                     ze2u = rotdiff (ji,jj,jk)
-                     ze1v = hdivdiff(ji,jj,jk)
-                     ! horizontal diffusive trends
-
-                     zva = + ( ze2u - rotdiff (ji-1,jj,jk)) / ( e1v(ji,jj) * fse3v_n(ji,jj,jk) ) + ( hdivdiff(ji,jj+1,jk) - ze1v) &
-                           / e2v(ji,jj)
-
-                     ! add it to the general momentum trends
-                     va(ji,jj,jk) = va(ji,jj,jk) + zva
+               IF( .NOT. tabspongedone_v(ji,jj) ) THEN
+                  DO jk = 1, jpkm1
+                     va(ji,jj,jk) = va(ji,jj,jk)                                                                  &
+                        &  + ( rotdiff (ji,jj  ,jk) - rotdiff (ji-1,jj,jk) ) / ( e1v(ji,jj) * e3v_n(ji,jj,jk) )   &
+                        &  + ( hdivdiff(ji,jj+1,jk) - hdivdiff(ji  ,jj,jk) ) * r1_e2v(ji,jj)
                   END DO
                ENDIF
@@ -457,10 +433,9 @@
          tabspongedone_v(i1+1:i2-1,j1+1:j2-1) = .TRUE.
       ENDIF
-
+      !
    END SUBROUTINE interpvn_sponge
 
 #else
 CONTAINS
-
    SUBROUTINE agrif_opa_sponge_empty
       !!---------------------------------------------
@@ -471,3 +446,4 @@
 #endif
 
+   !!======================================================================
 END MODULE agrif_opa_sponge
Index: /trunk/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 6140)
@@ -25,5 +25,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -66,4 +65,5 @@
       !
    END SUBROUTINE Agrif_Update_Tra
+
 
    RECURSIVE SUBROUTINE Agrif_Update_Dyn( )
@@ -150,4 +150,5 @@
 
 # if defined key_zdftke
+
    SUBROUTINE Agrif_Update_Tke( kt )
       !!---------------------------------------------
@@ -172,4 +173,5 @@
       
    END SUBROUTINE Agrif_Update_Tke
+   
 # endif /* key_zdftke */
 
@@ -178,5 +180,4 @@
       !!           *** ROUTINE updateT ***
       !!---------------------------------------------
-#  include "domzgr_substitute.h90"
       INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2,n1,n2
       REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: tabres
@@ -228,34 +229,27 @@
    END SUBROUTINE updateTS
 
+
    SUBROUTINE updateu( tabres, i1, i2, j1, j2, k1, k2, before )
       !!---------------------------------------------
       !!           *** ROUTINE updateu ***
       !!---------------------------------------------
-#  include "domzgr_substitute.h90"
-      !!
-      INTEGER, INTENT(in) :: i1, i2, j1, j2, k1, k2
+      INTEGER                               , INTENT(in   ) :: i1, i2, j1, j2, k1, k2
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !! 
-      INTEGER :: ji, jj, jk
-      REAL(wp) :: zrhoy
-      !!---------------------------------------------
-      ! 
-      IF (before) THEN
+      LOGICAL                               , INTENT(in   ) :: before
+      !
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zrhoy
+      !!---------------------------------------------
+      ! 
+      IF( before ) THEN
          zrhoy = Agrif_Rhoy()
+         DO jk = k1, k2
+            tabres(i1:i2,j1:j2,jk) = zrhoy * e2u(i1:i2,j1:j2) * e3u_n(i1:i2,j1:j2,jk) * un(i1:i2,j1:j2,jk)
+         END DO
+      ELSE
          DO jk=k1,k2
             DO jj=j1,j2
                DO ji=i1,i2
-                  tabres(ji,jj,jk) = e2u(ji,jj) * un(ji,jj,jk)
-                  tabres(ji,jj,jk) = tabres(ji,jj,jk) * fse3u_n(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         tabres = zrhoy * tabres
-      ELSE
-         DO jk=k1,k2
-            DO jj=j1,j2
-               DO ji=i1,i2
-                  tabres(ji,jj,jk) = tabres(ji,jj,jk) / e2u(ji,jj) / fse3u_n(ji,jj,jk)
+                  tabres(ji,jj,jk) = tabres(ji,jj,jk) * r1_e2u(ji,jj) / e3u_n(ji,jj,jk)
                   !
                   IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN ! Add asselin part
@@ -272,10 +266,9 @@
    END SUBROUTINE updateu
 
+
    SUBROUTINE updatev( tabres, i1, i2, j1, j2, k1, k2, before )
       !!---------------------------------------------
       !!           *** ROUTINE updatev ***
       !!---------------------------------------------
-#  include "domzgr_substitute.h90"
-      !!
       INTEGER :: i1,i2,j1,j2,k1,k2
       INTEGER :: ji,jj,jk
@@ -291,15 +284,13 @@
             DO jj=j1,j2
                DO ji=i1,i2
-                  tabres(ji,jj,jk) = e1v(ji,jj) * vn(ji,jj,jk)
-                  tabres(ji,jj,jk) = tabres(ji,jj,jk) * fse3v_n(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         tabres = zrhox * tabres
+                  tabres(ji,jj,jk) = zrhox * e1v(ji,jj) * e3v_n(ji,jj,jk) * vn(ji,jj,jk)
+               END DO
+            END DO
+         END DO
       ELSE
          DO jk=k1,k2
             DO jj=j1,j2
                DO ji=i1,i2
-                  tabres(ji,jj,jk) = tabres(ji,jj,jk) / e1v(ji,jj) / fse3v_n(ji,jj,jk)
+                  tabres(ji,jj,jk) = tabres(ji,jj,jk) * r1_e1v(ji,jj) / e3v_n(ji,jj,jk)
                   !
                   IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN ! Add asselin part
@@ -316,10 +307,9 @@
    END SUBROUTINE updatev
 
+
    SUBROUTINE updateu2d( tabres, i1, i2, j1, j2, before )
       !!---------------------------------------------
       !!          *** ROUTINE updateu2d ***
       !!---------------------------------------------
-#  include "domzgr_substitute.h90"
-      !!
       INTEGER, INTENT(in) :: i1, i2, j1, j2
       REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
@@ -335,19 +325,18 @@
          DO jj=j1,j2
             DO ji=i1,i2
-               tabres(ji,jj) = un_b(ji,jj) * hu(ji,jj) * e2u(ji,jj)
-            END DO
-         END DO
-         tabres = zrhoy * tabres
-      ELSE
-         DO jj=j1,j2
-            DO ji=i1,i2
-               tabres(ji,jj) =  tabres(ji,jj) * hur(ji,jj) / e2u(ji,jj)  
+               tabres(ji,jj) = zrhoy * un_b(ji,jj) * hu_n(ji,jj) * e2u(ji,jj)
+            END DO
+         END DO
+      ELSE
+         DO jj=j1,j2
+            DO ji=i1,i2
+               tabres(ji,jj) =  tabres(ji,jj) * r1_hu_n(ji,jj) * r1_e2u(ji,jj)  
                !    
                ! Update "now" 3d velocities:
-               spgu(ji,jj) = 0.e0
+               spgu(ji,jj) = 0._wp
                DO jk=1,jpkm1
-                  spgu(ji,jj) = spgu(ji,jj) + fse3u_n(ji,jj,jk) * un(ji,jj,jk)
-               END DO
-               spgu(ji,jj) = spgu(ji,jj) * hur(ji,jj)
+                  spgu(ji,jj) = spgu(ji,jj) + e3u_n(ji,jj,jk) * un(ji,jj,jk)
+               END DO
+               spgu(ji,jj) = spgu(ji,jj) * r1_hu_n(ji,jj)
                !
                zcorr = tabres(ji,jj) - spgu(ji,jj)
@@ -368,7 +357,7 @@
                spgu(ji,jj) = 0.e0
                DO jk=1,jpkm1
-                  spgu(ji,jj) = spgu(ji,jj) + fse3u_b(ji,jj,jk) * ub(ji,jj,jk)
-               END DO
-               spgu(ji,jj) = spgu(ji,jj) * hur_b(ji,jj)
+                  spgu(ji,jj) = spgu(ji,jj) + e3u_b(ji,jj,jk) * ub(ji,jj,jk)
+               END DO
+               spgu(ji,jj) = spgu(ji,jj) * r1_hu_b(ji,jj)
                !
                zcorr = ub_b(ji,jj) - spgu(ji,jj)
@@ -382,4 +371,5 @@
       !
    END SUBROUTINE updateu2d
+
 
    SUBROUTINE updatev2d( tabres, i1, i2, j1, j2, before )
@@ -400,19 +390,18 @@
          DO jj=j1,j2
             DO ji=i1,i2
-               tabres(ji,jj) = vn_b(ji,jj) * hv(ji,jj) * e1v(ji,jj) 
-            END DO
-         END DO
-         tabres = zrhox * tabres
-      ELSE
-         DO jj=j1,j2
-            DO ji=i1,i2
-               tabres(ji,jj) =  tabres(ji,jj) * hvr(ji,jj) / e1v(ji,jj)  
+               tabres(ji,jj) = zrhox * vn_b(ji,jj) * hv_n(ji,jj) * e1v(ji,jj) 
+            END DO
+         END DO
+      ELSE
+         DO jj=j1,j2
+            DO ji=i1,i2
+               tabres(ji,jj) =  tabres(ji,jj) * r1_hv_n(ji,jj) * r1_e1v(ji,jj)  
                !    
                ! Update "now" 3d velocities:
                spgv(ji,jj) = 0.e0
                DO jk=1,jpkm1
-                  spgv(ji,jj) = spgv(ji,jj) + fse3v_n(ji,jj,jk) * vn(ji,jj,jk)
-               END DO
-               spgv(ji,jj) = spgv(ji,jj) * hvr(ji,jj)
+                  spgv(ji,jj) = spgv(ji,jj) + e3v_n(ji,jj,jk) * vn(ji,jj,jk)
+               END DO
+               spgv(ji,jj) = spgv(ji,jj) * r1_hv_n(ji,jj)
                !
                zcorr = tabres(ji,jj) - spgv(ji,jj)
@@ -433,7 +422,7 @@
                spgv(ji,jj) = 0.e0
                DO jk=1,jpkm1
-                  spgv(ji,jj) = spgv(ji,jj) + fse3v_b(ji,jj,jk) * vb(ji,jj,jk)
-               END DO
-               spgv(ji,jj) = spgv(ji,jj) * hvr_b(ji,jj)
+                  spgv(ji,jj) = spgv(ji,jj) + e3v_b(ji,jj,jk) * vb(ji,jj,jk)
+               END DO
+               spgv(ji,jj) = spgv(ji,jj) * r1_hv_b(ji,jj)
                !
                zcorr = vb_b(ji,jj) - spgv(ji,jj)
@@ -467,5 +456,5 @@
          END DO
       ELSE
-         IF ( .NOT.ln_dynspg_ts .OR. (ln_dynspg_ts.AND.(.NOT.ln_bt_fw)) ) THEN
+         IF( .NOT.ln_dynspg_ts .OR. ( ln_dynspg_ts .AND. .NOT.ln_bt_fw ) ) THEN
             IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN
                DO jj=j1,j2
@@ -477,5 +466,5 @@
             ENDIF
          ENDIF
-
+         !
          DO jj=j1,j2
             DO ji=i1,i2
@@ -486,4 +475,5 @@
       !
    END SUBROUTINE updateSSH
+
 
    SUBROUTINE updateub2b( tabres, i1, i2, j1, j2, before )
@@ -517,4 +507,5 @@
    END SUBROUTINE updateub2b
 
+
    SUBROUTINE updatevb2b( tabres, i1, i2, j1, j2, before )
       !!---------------------------------------------
@@ -553,12 +544,11 @@
       !!           *** ROUTINE updateT ***
       !!---------------------------------------------
-#  include "domzgr_substitute.h90"
-
       INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2,n1,n2
       REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: tabres
       LOGICAL, iNTENT(in) :: before
-
+      !
       INTEGER :: ji,jj,jk
       REAL(wp) :: ztemp
+      !!---------------------------------------------
 
       IF (before) THEN
@@ -598,4 +588,5 @@
 
 # if defined key_zdftke
+
    SUBROUTINE updateEN( ptab, i1, i2, j1, j2, k1, k2, before )
       !!---------------------------------------------
Index: /trunk/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90	(revision 6140)
@@ -16,5 +16,4 @@
    PUBLIC Agrif_trc, interptrn
 
-#  include "domzgr_substitute.h90"  
 #  include "vectopt_loop_substitute.h90"
   !!----------------------------------------------------------------------
@@ -23,6 +22,5 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
-   CONTAINS
+CONTAINS
 
    SUBROUTINE Agrif_trc
@@ -40,4 +38,5 @@
       !
    END SUBROUTINE Agrif_trc
+
 
    SUBROUTINE interptrn(ptab,i1,i2,j1,j2,k1,k2,n1,n2,before,nb,ndir)
Index: /trunk/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90	(revision 6140)
@@ -2,13 +2,25 @@
 
 MODULE agrif_top_sponge
+   !!======================================================================
+   !!                ***  MODULE agrif_top_sponge  ***
+   !! AGRIF :   define in memory AGRIF variables for sea-ice
+   !!======================================================================
+   !! History :  2.0  ! 2006-08  (R. Benshila, L. Debreu)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   Agrif_Sponge_trc : 
+   !!   interptrn_sponge :  
+   !!----------------------------------------------------------------------
 #if defined key_agrif && defined key_top
    USE par_oce
    USE par_trc
    USE oce
+   USE trc
    USE dom_oce
-   USE in_out_manager
    USE agrif_oce
    USE agrif_opa_sponge
-   USE trc
+   !
+   USE in_out_manager
    USE lib_mpp
    USE wrk_nemo  
@@ -19,83 +31,74 @@
    PUBLIC Agrif_Sponge_trc, interptrn_sponge
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.6 , NEMO Consortium (2010)
+   !! NEMO/NST 3.7 , NEMO Consortium (2015)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
    SUBROUTINE Agrif_Sponge_trc
-      !!---------------------------------------------
-      !!   *** ROUTINE Agrif_Sponge_Trc ***
-      !!---------------------------------------------
-      !! 
-      REAL(wp) :: timecoeff
-
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE Agrif_Sponge_Trc ***
+      !!----------------------------------------------------------------------
+      REAL(wp) ::   timecoeff
+      !!----------------------------------------------------------------------
+      !
 #if defined SPONGE_TOP
-      timecoeff = REAL(Agrif_NbStepint(),wp)/Agrif_rhot()
+      timecoeff = REAL( Agrif_NbStepint(), wp ) / Agrif_rhot()
       CALL Agrif_sponge
-      Agrif_SpecialValue=0.
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = .TRUE.
-      tabspongedone_trn = .FALSE.
-      CALL Agrif_Bc_Variable(trn_sponge_id,calledweight=timecoeff,procname=interptrn_sponge)
+      tabspongedone_trn     = .FALSE.
+      CALL Agrif_Bc_Variable( trn_sponge_id, calledweight=timecoeff, procname=interptrn_sponge )
       Agrif_UseSpecialValue = .FALSE.
-
 #endif
-
+      !
    END SUBROUTINE Agrif_Sponge_Trc
 
-   SUBROUTINE interptrn_sponge(tabres,i1,i2,j1,j2,k1,k2,n1,n2,before)
-      !!---------------------------------------------
-      !!   *** ROUTINE interptrn_sponge ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2,n1,n2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
 
-
+   SUBROUTINE interptrn_sponge( tabres, i1, i2, j1, j2, k1, k2, n1, n2, before )
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE interptrn_sponge ***
+      !!----------------------------------------------------------------------
+      INTEGER                                     , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, n1, n2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) ::   tabres
+      LOGICAL                                     , INTENT(in   ) ::   before
+      !
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
-
-      REAL(wp) :: ztra, zabe1, zabe2, zbtr
-      REAL(wp), DIMENSION(i1:i2,j1:j2) :: ztu, ztv
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2) ::trbdiff
+      REAL(wp) ::   zabe1, zabe2
+      REAL(wp), DIMENSION(i1:i2,j1:j2)             ::   ztu, ztv
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2) ::   trbdiff
+      !!----------------------------------------------------------------------
       !
-      IF (before) THEN
+      IF( before ) THEN
          tabres(i1:i2,j1:j2,k1:k2,n1:n2) = trn(i1:i2,j1:j2,k1:k2,n1:n2)
       ELSE      
-
+!!gm line below use of :,:  versus i1:i2,j1:j2  ....   strange, not wrong.    ===>> to be corrected
          trbdiff(:,:,:,:) = trb(i1:i2,j1:j2,:,:) - tabres(:,:,:,:)      
          DO jn = 1, jptra
             DO jk = 1, jpkm1
-
                DO jj = j1,j2-1
                   DO ji = i1,i2-1
-                     zabe1 = fsaht_spu(ji,jj) * umask(ji,jj,jk) * e2_e1u(ji,jj) * fse3u_n(ji,jj,jk)
-                     zabe2 = fsaht_spv(ji,jj) * vmask(ji,jj,jk) * e1_e2v(ji,jj) * fse3v_n(ji,jj,jk)
+                     zabe1 = fsaht_spu(ji,jj) * e2_e1u(ji,jj) * e3u_n(ji,jj,jk) * umask(ji,jj,jk)
+                     zabe2 = fsaht_spv(ji,jj) * e1_e2v(ji,jj) * e3v_n(ji,jj,jk) * vmask(ji,jj,jk)
                      ztu(ji,jj) = zabe1 * ( trbdiff(ji+1,jj  ,jk,jn) - trbdiff(ji,jj,jk,jn) )
                      ztv(ji,jj) = zabe2 * ( trbdiff(ji  ,jj+1,jk,jn) - trbdiff(ji,jj,jk,jn) )
-                  ENDDO
-               ENDDO
-
+                  END DO
+               END DO
+               !
                DO jj = j1+1,j2-1
                   DO ji = i1+1,i2-1
-
-                     IF (.NOT. tabspongedone_trn(ji,jj)) THEN 
-                        zbtr = r1_e1e2t(ji,jj) / fse3t(ji,jj,jk)
-                        ! horizontal diffusive trends
-                        ztra = zbtr * (  ztu(ji,jj) - ztu(ji-1,jj  ) + ztv(ji,jj) - ztv(ji  ,jj-1)  )
-                        ! add it to the general tracer trends
-                        tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra
+                     IF( .NOT. tabspongedone_trn(ji,jj) ) THEN 
+                        tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + (  ztu(ji,jj) - ztu(ji-1,jj  )     &
+                           &                                   + ztv(ji,jj) - ztv(ji  ,jj-1)  )  &
+                           &                                * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                      ENDIF
-
-                  ENDDO
-               ENDDO
-
-            ENDDO
-         ENDDO
-
+                  END DO
+               END DO
+            END DO
+            !
+         END DO
+         !
          tabspongedone_trn(i1+1:i2-1,j1+1:j2-1) = .TRUE.
       ENDIF
@@ -104,13 +107,11 @@
 
 #else
+
 CONTAINS
-
    SUBROUTINE agrif_top_sponge_empty
-      !!---------------------------------------------
-      !!   *** ROUTINE agrif_top_sponge_empty ***
-      !!---------------------------------------------
       WRITE(*,*)  'agrif_top_sponge : You should not have seen this print! error?'
    END SUBROUTINE agrif_top_sponge_empty
 #endif
 
+   !!======================================================================
 END MODULE agrif_top_sponge
Index: /trunk/NEMOGCM/NEMO/NST_SRC/agrif_top_update.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/NST_SRC/agrif_top_update.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/NST_SRC/agrif_top_update.F90	(revision 6140)
@@ -3,12 +3,18 @@
 
 MODULE agrif_top_update
+   !!======================================================================
+   !!                ***  MODULE agrif_top_update  ***
+   !! AGRIF :   
+   !!----------------------------------------------------------------------
+   !! History :  
+   !!----------------------------------------------------------------------
 
 #if defined key_agrif && defined key_top
    USE par_oce
    USE oce
+   USE par_trc
+   USE trc
    USE dom_oce
    USE agrif_oce
-   USE par_trc
-   USE trc
    USE wrk_nemo  
 
@@ -18,37 +24,36 @@
    PUBLIC Agrif_Update_Trc
 
-   INTEGER, PUBLIC :: nbcline_trc = 0
+   INTEGER, PUBLIC ::   nbcline_trc = 0   !: ???
 
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.3 , NEMO Consortium (2010)
+   !! NEMO/NST 3.7 , NEMO Consortium (2015)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
    SUBROUTINE Agrif_Update_Trc( kt )
-      !!---------------------------------------------
-      !!   *** ROUTINE Agrif_Update_Trc ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: kt
-      !!---------------------------------------------
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE Agrif_Update_Trc ***
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt
+      !!----------------------------------------------------------------------
       ! 
       IF((Agrif_NbStepint() .NE. (Agrif_irhot()-1)).AND.(kt /= 0)) RETURN
 #if defined TWO_WAY   
       Agrif_UseSpecialValueInUpdate = .TRUE.
-      Agrif_SpecialValueFineGrid = 0.
+      Agrif_SpecialValueFineGrid    = 0._wp
       ! 
-      IF (MOD(nbcline_trc,nbclineupdate) == 0) THEN
+      IF( MOD(nbcline_trc,nbclineupdate) == 0 ) THEN
 # if ! defined DECAL_FEEDBACK
-         CALL Agrif_Update_Variable(trn_id, procname=updateTRC)
+         CALL Agrif_Update_Variable(trn_id, procname=updateTRC )
 # else
-         CALL Agrif_Update_Variable(trn_id, locupdate=(/1,0/),procname=updateTRC)
+         CALL Agrif_Update_Variable(trn_id, locupdate=(/1,0/),procname=updateTRC )
 # endif
       ELSE
 # if ! defined DECAL_FEEDBACK
-         CALL Agrif_Update_Variable(trn_id,locupdate=(/0,2/), procname=updateTRC)
+         CALL Agrif_Update_Variable( trn_id, locupdate=(/0,2/), procname=updateTRC )
 # else
-         CALL Agrif_Update_Variable(trn_id,locupdate=(/1,2/), procname=updateTRC)
+         CALL Agrif_Update_Variable( trn_id, locupdate=(/1,2/), procname=updateTRC )
 # endif
       ENDIF
@@ -60,48 +65,40 @@
    END SUBROUTINE Agrif_Update_Trc
 
+
    SUBROUTINE updateTRC( ptab, i1, i2, j1, j2, k1, k2, n1, n2, before )
-      !!---------------------------------------------
-      !!           *** ROUTINE updateT ***
-      !!---------------------------------------------
-#  include "domzgr_substitute.h90"
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2,n1,n2
-      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updateT ***
+      !!----------------------------------------------------------------------
+      INTEGER                                    , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, n1, n2
+      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) ::   ptab
+      LOGICAL                                    , INTENT(in   ) ::   before
       !!
-      INTEGER :: ji,jj,jk,jn
-      !!---------------------------------------------
+      INTEGER ::   ji, jj, jk, jn
+      !!----------------------------------------------------------------------
       !
-      IF (before) THEN
-         DO jn = n1,n2
-            DO jk=k1,k2
-               DO jj=j1,j2
-                  DO ji=i1,i2
-                     ptab(ji,jj,jk,jn) = trn(ji,jj,jk,jn)
+      IF( before ) THEN
+         ptab(i1:i2,j1:j2,k1:k2,n1:n2) = trn(i1:i2,j1:j2,k1:k2,n1:n2)
+      ELSE
+         IF( .NOT.(lk_agrif_fstep.AND.(neuler==0)) ) THEN
+            ! Add asselin part
+            DO jn = n1,n2
+               DO jk = k1, k2
+                  DO jj = j1, j2
+                     DO ji = i1, i2
+                        IF( ptab(ji,jj,jk,jn) /= 0._wp ) THEN
+                           trb(ji,jj,jk,jn) = trb(ji,jj,jk,jn)             & 
+                              &             + atfp * ( ptab(ji,jj,jk,jn)   &
+                                 &                    - trn(ji,jj,jk,jn) ) * tmask(ji,jj,jk)
+                        ENDIF
+                     END DO
                   END DO
                END DO
             END DO
-         END DO
-      ELSE
-         IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN
-            ! Add asselin part
-            DO jn = n1,n2
-               DO jk=k1,k2
-                  DO jj=j1,j2
-                     DO ji=i1,i2
-                        IF( ptab(ji,jj,jk,jn) .NE. 0. ) THEN
-                           trb(ji,jj,jk,jn) = trb(ji,jj,jk,jn) & 
-                                 & + atfp * ( ptab(ji,jj,jk,jn) &
-                                 &             - trn(ji,jj,jk,jn) ) * tmask(ji,jj,jk)
-                        ENDIF
-                     ENDDO
-                  ENDDO
-               ENDDO
-            ENDDO
          ENDIF
-         DO jn = n1,n2
-            DO jk=k1,k2
-               DO jj=j1,j2
-                  DO ji=i1,i2
-                     IF( ptab(ji,jj,jk,jn) .NE. 0. ) THEN 
+         DO jn = n1, n2
+            DO jk = k1, k2
+               DO jj = j1, j2
+                  DO ji = i1, i2
+                     IF( ptab(ji,jj,jk,jn) /= 0._wp ) THEN 
                         trn(ji,jj,jk,jn) = ptab(ji,jj,jk,jn) * tmask(ji,jj,jk)
                      END IF
@@ -123,3 +120,5 @@
    END SUBROUTINE agrif_top_update_empty
 #endif
+
+   !!======================================================================
 END MODULE agrif_top_update
Index: /trunk/NEMOGCM/NEMO/NST_SRC/agrif_user.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 6140)
@@ -1,5 +1,5 @@
 #if defined key_agrif
 !!----------------------------------------------------------------------
-!! NEMO/NST 3.4 , NEMO Consortium (2012)
+!! NEMO/NST 3.7 , NEMO Consortium (2015)
 !! $Id$
 !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -330,5 +330,5 @@
    !
    Agrif_UseSpecialValueInUpdate = .FALSE.
-   nbcline = 0 
+   nbcline = 0
    lk_agrif_doupd = .FALSE.
    !
Index: /trunk/NEMOGCM/NEMO/OFF_SRC/domrea.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OFF_SRC/domrea.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OFF_SRC/domrea.F90	(revision 6140)
@@ -34,5 +34,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -76,4 +75,5 @@
       r1_e1f(:,:) = 1._wp / e1f(:,:)   ;   r1_e2f (:,:) = 1._wp / e2f(:,:)
       !
+!!gm BUG if scale factor reduction !!!!
       e1e2t (:,:) = e1t(:,:) * e2t(:,:)   ;   r1_e1e2t(:,:) = 1._wp / e1e2t(:,:)
       e1e2u (:,:) = e1u(:,:) * e2u(:,:)   ;   r1_e1e2u(:,:) = 1._wp / e1e2u(:,:)
@@ -84,13 +84,13 @@
       e1_e2v(:,:) = e1v(:,:) / e2v(:,:)
       !
-      hu(:,:) = 0._wp                        ! Ocean depth at U- and V-points
-      hv(:,:) = 0._wp
-      DO jk = 1, jpk
-         hu(:,:) = hu(:,:) + fse3u_n(:,:,jk) * umask(:,:,jk)
-         hv(:,:) = hv(:,:) + fse3v_n(:,:,jk) * vmask(:,:,jk)
+      hu_n(:,:) = e3u_n(:,:,1) * umask(:,:,1)     ! Ocean depth at U- and V-points
+      hv_n(:,:) = e3v_n(:,:,1) * vmask(:,:,1)
+      DO jk = 2, jpk
+         hu_n(:,:) = hu_n(:,:) + e3u_n(:,:,jk) * umask(:,:,jk)
+         hv_n(:,:) = hv_n(:,:) + e3v_n(:,:,jk) * vmask(:,:,jk)
       END DO
       !                                        ! Inverse of the local depth
-      hur(:,:) = 1._wp / ( hu(:,:) + 1._wp - umask(:,:,1) ) * umask(:,:,1)
-      hvr(:,:) = 1._wp / ( hv(:,:) + 1._wp - vmask(:,:,1) ) * vmask(:,:,1)
+      r1_hu_n(:,:) = 1._wp / ( hu_n(:,:) + 1._wp - umask(:,:,1) ) * umask(:,:,1)
+      r1_hv_n(:,:) = 1._wp / ( hv_n(:,:) + 1._wp - vmask(:,:,1) ) * vmask(:,:,1)
       !
       CALL dom_stp      ! Time step
@@ -113,12 +113,10 @@
       INTEGER  ::   ios   ! Local integer output status for namelist read
       !
-      NAMELIST/namrun/ cn_ocerst_indir, cn_ocerst_outdir, nn_stocklist, ln_rst_list,               &
-         &             nn_no   , cn_exp    , cn_ocerst_in, cn_ocerst_out, ln_rstart , nn_rstctl,   &
-         &             nn_it000, nn_itend  , nn_date0    , nn_leapy     , nn_istate , nn_stock ,   &
-         &             nn_write, ln_dimgnnn, ln_mskland  , ln_cfmeta    , ln_clobber, nn_chunksz, nn_euler
-      NAMELIST/namdom/ nn_bathy , rn_bathy, rn_e3zps_min, rn_e3zps_rat, nn_msh    , rn_hmin,   &
-         &             nn_acc   , rn_atfp     , rn_rdt      , rn_rdtmin ,            &
-         &             rn_rdtmax, rn_rdth     , nn_baro     , nn_closea , ln_crs, &
-         &             jphgr_msh, &
+      NAMELIST/namrun/ cn_ocerst_indir, cn_ocerst_outdir, nn_stocklist, ln_rst_list,                         &
+         &             nn_no   , cn_exp    , cn_ocerst_in, cn_ocerst_out, ln_rstart , nn_rstctl,             &
+         &             nn_it000, nn_itend  , nn_date0    , nn_time0, nn_leapy     , nn_istate , nn_stock ,   &
+         &             nn_write, ln_iscpl  , ln_mskland  , ln_cfmeta    , ln_clobber, nn_chunksz, nn_euler
+      NAMELIST/namdom/ nn_bathy , rn_bathy , rn_e3zps_min, rn_e3zps_rat , nn_msh    , rn_hmin   , rn_isfhmin,&
+         &             rn_atfp  , rn_rdt   , nn_baro     , nn_closea    , ln_crs    , jphgr_msh,             &
          &             ppglam0, ppgphi0, ppe1_deg, ppe2_deg, ppe1_m, ppe2_m, &
          &             ppsur, ppa0, ppa1, ppkth, ppacr, ppdzmin, pphmax, ldbletanh, &
@@ -154,5 +152,4 @@
          WRITE(numout,*) '      frequency of restart file       nn_stock   = ', nn_stock
          WRITE(numout,*) '      frequency of output file        nn_write   = ', nn_write
-         WRITE(numout,*) '      multi file dimgout              ln_dimgnnn = ', ln_dimgnnn
          WRITE(numout,*) '      mask land points                ln_mskland = ', ln_mskland
          WRITE(numout,*) '      additional CF standard metadata ln_cfmeta  = ', ln_cfmeta
@@ -186,5 +183,5 @@
       ! parameters correspondting to nit000 - 1 (as we start the step loop with a call to day)
       ndastp = ndate0 - 1        ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00
-      adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday
+      adatrj = ( REAL( nit000-1, wp ) * rdt ) / rday
 
 #if defined key_agrif
@@ -231,8 +228,4 @@
          WRITE(numout,*) '      asselin time filter parameter        rn_atfp   = ', rn_atfp
          WRITE(numout,*) '      time-splitting: nb of sub time-step  nn_baro   = ', nn_baro
-         WRITE(numout,*) '      acceleration of converge             nn_acc    = ', nn_acc
-         WRITE(numout,*) '        nn_acc=1: surface tracer rdt       rn_rdtmin = ', rn_rdtmin
-         WRITE(numout,*) '                  bottom  tracer rdt       rdtmax    = ', rn_rdtmax
-         WRITE(numout,*) '                  depth of transition      rn_rdth   = ', rn_rdth
          WRITE(numout,*) '      suppression of closed seas (=0)      nn_closea = ', nn_closea
          WRITE(numout,*) '      type of horizontal mesh jphgr_msh           = ', jphgr_msh
@@ -260,11 +253,6 @@
       e3zps_rat = rn_e3zps_rat
       nmsh      = nn_msh
-      nacc      = nn_acc
       atfp      = rn_atfp
       rdt       = rn_rdt
-      rdtmin    = rn_rdtmin
-      rdtmax    = rn_rdtmin
-      rdth      = rn_rdth
-
 #if defined key_netcdf4
       !                             ! NetCDF 4 case   ("key_netcdf4" defined)
@@ -319,5 +307,5 @@
       INTEGER ::   ios
       !!
-      NAMELIST/namzgr/ ln_zco, ln_zps, ln_sco, ln_isfcav
+      NAMELIST/namzgr/ ln_zco, ln_zps, ln_sco, ln_isfcav, ln_linssh
       !!----------------------------------------------------------------------
 
@@ -340,4 +328,5 @@
          WRITE(numout,*) '             s- or hybrid z-s-coordinate    ln_sco    = ', ln_sco
          WRITE(numout,*) '             ice shelf cavity               ln_isfcav = ', ln_isfcav
+         WRITE(numout,*) '             Linear free surface            ln_linssh = ', ln_linssh
       ENDIF
 
@@ -554,8 +543,8 @@
             CALL iom_get( inum4, jpdom_unknown, 'esigw', esigw )
 
-            CALL iom_get( inum4, jpdom_data, 'e3t_0', fse3t_n(:,:,:) ) ! scale factors
-            CALL iom_get( inum4, jpdom_data, 'e3u_0', fse3u_n(:,:,:) )
-            CALL iom_get( inum4, jpdom_data, 'e3v_0', fse3v_n(:,:,:) )
-            CALL iom_get( inum4, jpdom_data, 'e3w_0', fse3w_n(:,:,:) )
+            CALL iom_get( inum4, jpdom_data, 'e3t_0', e3t_0(:,:,:) ) ! scale factors
+            CALL iom_get( inum4, jpdom_data, 'e3u_0', e3u_0(:,:,:) )
+            CALL iom_get( inum4, jpdom_data, 'e3v_0', e3v_0(:,:,:) )
+            CALL iom_get( inum4, jpdom_data, 'e3w_0', e3w_0(:,:,:) )
 
             CALL iom_get( inum4, jpdom_unknown, 'gdept_1d', gdept_1d ) ! depth
@@ -571,8 +560,8 @@
             !
             IF( nmsh <= 6 ) THEN                                        ! 3D vertical scale factors
-               CALL iom_get( inum4, jpdom_data, 'e3t_0', fse3t_n(:,:,:) )
-               CALL iom_get( inum4, jpdom_data, 'e3u_0', fse3u_n(:,:,:) )
-               CALL iom_get( inum4, jpdom_data, 'e3v_0', fse3v_n(:,:,:) )
-               CALL iom_get( inum4, jpdom_data, 'e3w_0', fse3w_n(:,:,:) )
+               CALL iom_get( inum4, jpdom_data, 'e3t_0', e3t_0(:,:,:) )
+               CALL iom_get( inum4, jpdom_data, 'e3u_0', e3u_0(:,:,:) )
+               CALL iom_get( inum4, jpdom_data, 'e3v_0', e3v_0(:,:,:) )
+               CALL iom_get( inum4, jpdom_data, 'e3w_0', e3w_0(:,:,:) )
             ELSE                                                        ! 2D bottom scale factors
                CALL iom_get( inum4, jpdom_data, 'e3t_ps', e3tp )
@@ -580,14 +569,14 @@
                !                                                        ! deduces the 3D scale factors
                DO jk = 1, jpk
-                  fse3t_n(:,:,jk) = e3t_1d(jk)                                    ! set to the ref. factors
-                  fse3u_n(:,:,jk) = e3t_1d(jk)
-                  fse3v_n(:,:,jk) = e3t_1d(jk)
-                  fse3w_n(:,:,jk) = e3w_1d(jk)
+                  e3t_0(:,:,jk) = e3t_1d(jk)                                    ! set to the ref. factors
+                  e3u_0(:,:,jk) = e3t_1d(jk)
+                  e3v_0(:,:,jk) = e3t_1d(jk)
+                  e3w_0(:,:,jk) = e3w_1d(jk)
                END DO
                DO jj = 1,jpj                                                  ! adjust the deepest values
                   DO ji = 1,jpi
                      ik = mbkt(ji,jj)
-                     fse3t_n(ji,jj,ik) = e3tp(ji,jj) * tmask(ji,jj,1) + e3t_1d(1) * ( 1._wp - tmask(ji,jj,1) )
-                     fse3w_n(ji,jj,ik) = e3wp(ji,jj) * tmask(ji,jj,1) + e3w_1d(1) * ( 1._wp - tmask(ji,jj,1) )
+                     e3t_0(ji,jj,ik) = e3tp(ji,jj) * tmask(ji,jj,1) + e3t_1d(1) * ( 1._wp - tmask(ji,jj,1) )
+                     e3w_0(ji,jj,ik) = e3wp(ji,jj) * tmask(ji,jj,1) + e3w_1d(1) * ( 1._wp - tmask(ji,jj,1) )
                   END DO
                END DO
@@ -595,21 +584,21 @@
                   DO jj = 1, jpjm1
                      DO ji = 1, jpim1
-                        fse3u_n(ji,jj,jk) = MIN( fse3t_n(ji,jj,jk), fse3t_n(ji+1,jj,jk) )
-                        fse3v_n(ji,jj,jk) = MIN( fse3t_n(ji,jj,jk), fse3t_n(ji,jj+1,jk) )
+                        e3u_0(ji,jj,jk) = MIN( e3t_0(ji,jj,jk), e3t_0(ji+1,jj,jk) )
+                        e3v_0(ji,jj,jk) = MIN( e3t_0(ji,jj,jk), e3t_0(ji,jj+1,jk) )
                      END DO
                   END DO
                END DO
-               CALL lbc_lnk( fse3u_n(:,:,:) , 'U', 1._wp )   ;   CALL lbc_lnk( fse3uw_n(:,:,:), 'U', 1._wp )   ! lateral boundary conditions
-               CALL lbc_lnk( fse3v_n(:,:,:) , 'V', 1._wp )   ;   CALL lbc_lnk( fse3vw_n(:,:,:), 'V', 1._wp )
+               CALL lbc_lnk( e3u_0(:,:,:) , 'U', 1._wp )   ;   CALL lbc_lnk( e3uw_0(:,:,:), 'U', 1._wp )   ! lateral boundary conditions
+               CALL lbc_lnk( e3v_0(:,:,:) , 'V', 1._wp )   ;   CALL lbc_lnk( e3vw_0(:,:,:), 'V', 1._wp )
                !
                DO jk = 1, jpk                        ! set to z-scale factor if zero (i.e. along closed boundaries)
-                  WHERE( fse3u_n(:,:,jk) == 0._wp )   fse3u_n(:,:,jk) = e3t_1d(jk)
-                  WHERE( fse3v_n(:,:,jk) == 0._wp )   fse3v_n(:,:,jk) = e3t_1d(jk)
+                  WHERE( e3u_0(:,:,jk) == 0._wp )   e3u_0(:,:,jk) = e3t_1d(jk)
+                  WHERE( e3v_0(:,:,jk) == 0._wp )   e3v_0(:,:,jk) = e3t_1d(jk)
                END DO
             END IF
 
             IF( iom_varid( inum4, 'gdept_0', ldstop = .FALSE. ) > 0 ) THEN   ! 3D depth of t- and w-level
-               CALL iom_get( inum4, jpdom_data, 'gdept_0', fsdept_n(:,:,:) )
-               CALL iom_get( inum4, jpdom_data, 'gdepw_0', fsdepw_n(:,:,:) )
+               CALL iom_get( inum4, jpdom_data, 'gdept_0', gdept_0(:,:,:) )
+               CALL iom_get( inum4, jpdom_data, 'gdepw_0', gdepw_0(:,:,:) )
             ELSE                                                           ! 2D bottom depth
                CALL iom_get( inum4, jpdom_data, 'hdept', zprt )
@@ -617,6 +606,6 @@
                !
                DO jk = 1, jpk                                              ! deduces the 3D depth
-                  fsdept_n(:,:,jk) = gdept_1d(jk)
-                  fsdepw_n(:,:,jk) = gdepw_1d(jk)
+                  gdept_0(:,:,jk) = gdept_1d(jk)
+                  gdepw_0(:,:,jk) = gdepw_1d(jk)
                END DO
                DO jj = 1, jpj
@@ -624,7 +613,7 @@
                      ik = mbkt(ji,jj)
                      IF( ik > 0 ) THEN
-                        fsdepw_n(ji,jj,ik+1) = zprw(ji,jj)
-                        fsdept_n(ji,jj,ik  ) = zprt(ji,jj)
-                        fsdept_n(ji,jj,ik+1) = fsdept_n(ji,jj,ik) + fse3t_n(ji,jj,ik)
+                        gdepw_0(ji,jj,ik+1) = zprw(ji,jj)
+                        gdept_0(ji,jj,ik  ) = zprt(ji,jj)
+                        gdept_0(ji,jj,ik+1) = gdept_0(ji,jj,ik) + e3t_0(ji,jj,ik)
                      ENDIF
                   END DO
@@ -640,12 +629,29 @@
             CALL iom_get( inum4, jpdom_unknown, 'e3w_1d'  , e3w_1d   )
             DO jk = 1, jpk
-               fse3t_n(:,:,jk) = e3t_1d(jk)                              ! set to the ref. factors
-               fse3u_n(:,:,jk) = e3t_1d(jk)
-               fse3v_n(:,:,jk) = e3t_1d(jk)
-               fse3w_n(:,:,jk) = e3w_1d(jk)
-               fsdept_n(:,:,jk) = gdept_1d(jk)
-               fsdepw_n(:,:,jk) = gdepw_1d(jk)
+               e3t_0(:,:,jk) = e3t_1d(jk)                              ! set to the ref. factors
+               e3u_0(:,:,jk) = e3t_1d(jk)
+               e3v_0(:,:,jk) = e3t_1d(jk)
+               e3w_0(:,:,jk) = e3w_1d(jk)
+               gdept_0(:,:,jk) = gdept_1d(jk)
+               gdepw_0(:,:,jk) = gdepw_1d(jk)
             END DO
          ENDIF
+
+      !
+      !              !==  time varying part of coordinate system  ==!
+      !
+      !       before        !          now          !       after         !
+      ;  gdept_b = gdept_0  ;   gdept_n = gdept_0   !        ---          ! depth of grid-points
+      ;  gdepw_b = gdepw_0  ;   gdepw_n = gdepw_0   !        ---          !
+      ;                     ;   gde3w_n = gde3w_0   !        ---          !
+      !
+      ;    e3t_b =   e3t_0  ;     e3t_n =   e3t_0   ;   e3t_a =  e3t_0    ! scale factors
+      ;    e3u_b =   e3u_0  ;     e3u_n =   e3u_0   ;   e3u_a =  e3u_0    !
+      ;    e3v_b =   e3v_0  ;     e3v_n =   e3v_0   ;   e3v_a =  e3v_0    !
+      ;                     ;     e3f_n =   e3f_0   !        ---          !
+      ;    e3w_b =   e3w_0  ;     e3w_n =   e3w_0   !        ---          !
+      ;   e3uw_b =  e3uw_0  ;    e3uw_n =  e3uw_0   !        ---          !
+      ;   e3vw_b =  e3vw_0  ;    e3vw_n =  e3vw_0   !        ---          !
+      !
 
 !!gm BUG in s-coordinate this does not work!
@@ -677,14 +683,4 @@
             &                     e2t  (1,jj), e2u  (1,jj),   &
             &                     e2v  (1,jj), jj = 1, jpj, 10 )
-      ENDIF
-
-
-      IF( nprint == 1 .AND. lwp ) THEN
-         WRITE(numout,*) '          e1u e2u '
-         CALL prihre( e1u,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
-         CALL prihre( e2u,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
-         WRITE(numout,*) '          e1v e2v  '
-         CALL prihre( e1v,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
-         CALL prihre( e2v,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
       ENDIF
 
@@ -813,15 +809,15 @@
       DO jj = 1, jpjm1
          DO ji = 1, fs_jpim1   ! vector loop
-            umask_i(ji,jj)  = ssmask(ji,jj) * ssmask(ji+1,jj  )  * MIN(1._wp,SUM(umask(ji,jj,:)))
-            vmask_i(ji,jj)  = ssmask(ji,jj) * ssmask(ji  ,jj+1)  * MIN(1._wp,SUM(vmask(ji,jj,:)))
+            ssumask(ji,jj)  = ssmask(ji,jj) * ssmask(ji+1,jj  )  * MIN(1._wp,SUM(umask(ji,jj,:)))
+            ssvmask(ji,jj)  = ssmask(ji,jj) * ssmask(ji  ,jj+1)  * MIN(1._wp,SUM(vmask(ji,jj,:)))
          END DO
          DO ji = 1, jpim1      ! NO vector opt.
-            fmask_i(ji,jj) =  ssmask(ji,jj  ) * ssmask(ji+1,jj  )   &
+            ssfmask(ji,jj) =  ssmask(ji,jj  ) * ssmask(ji+1,jj  )   &
                &            * ssmask(ji,jj+1) * ssmask(ji+1,jj+1) * MIN(1._wp,SUM(fmask(ji,jj,:)))
          END DO
       END DO
-      CALL lbc_lnk( umask_i, 'U', 1._wp )      ! Lateral boundary conditions
-      CALL lbc_lnk( vmask_i, 'V', 1._wp )
-      CALL lbc_lnk( fmask_i, 'F', 1._wp )
+      CALL lbc_lnk( ssumask, 'U', 1._wp )      ! Lateral boundary conditions
+      CALL lbc_lnk( ssvmask, 'V', 1._wp )
+      CALL lbc_lnk( ssfmask, 'F', 1._wp )
 
       ! 3. Ocean/land mask at wu-, wv- and w points 
@@ -836,19 +832,4 @@
       END DO
       !
-      IF( nprint == 1 .AND. lwp ) THEN    ! Control print
-         imsk(:,:) = INT( tmask_i(:,:) )
-         WRITE(numout,*) ' tmask_i : '
-         CALL prihin( imsk(:,:), jpi, jpj, 1, jpi, 1, 1, jpj, 1, 1, numout)
-         WRITE (numout,*)
-         WRITE (numout,*) ' dommsk: tmask for each level'
-         WRITE (numout,*) ' ----------------------------'
-         DO jk = 1, jpk
-            imsk(:,:) = INT( tmask(:,:,jk) )
-            WRITE(numout,*)
-            WRITE(numout,*) ' level = ',jk
-            CALL prihin( imsk(:,:), jpi, jpj, 1, jpi, 1, 1, jpj, 1, 1, numout)
-         END DO
-      ENDIF
-      !
       CALL wrk_dealloc( jpi, jpj, imsk )
       !
Index: /trunk/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90	(revision 6140)
@@ -85,5 +85,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -107,9 +106,9 @@
       USE oce, ONLY:  zts    => tsa
       USE oce, ONLY:  zuslp  => ua   , zvslp  => va
-      USE zdf_oce, ONLY:  zwslpi => avmu , zwslpj => avmv 
       USE oce, ONLY:  zu     => ub   , zv     => vb,  zw => rke
       !
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !
+       REAL(wp), DIMENSION(jpi,jpj,jpk     )  :: zwslpi, zwslpj
 !      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts)  :: zts
 !      REAL(wp), DIMENSION(jpi,jpj,jpk     )  :: zuslp, zvslp, zwslpi, zwslpj
@@ -359,4 +358,8 @@
                 jf_rnf = jfld + 1  ;  jfld  = jf_rnf
          slf_d(jf_rnf) = sn_rnf
+         ! Activate runoff key of sbc_oce
+         ln_rnf = .true.
+         WRITE(numout,*) 'dta_dyn : Activate the runoff data structure from ocean core ( force ln_rnf = .true.) '
+         WRITE(numout,*)
       ELSE
          rnf (:,:) = 0._wp
@@ -421,4 +424,5 @@
    END SUBROUTINE dta_dyn_init
 
+
    SUBROUTINE dta_dyn_wzv( pu, pv, pw )
       !!----------------------------------------------------------------------
@@ -449,15 +453,14 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zu  = pu(ji  ,jj  ,jk) * umask(ji  ,jj  ,jk) * e2u(ji  ,jj  ) * fse3u(ji  ,jj  ,jk)
-               zu1 = pu(ji-1,jj  ,jk) * umask(ji-1,jj  ,jk) * e2u(ji-1,jj  ) * fse3u(ji-1,jj  ,jk)
-               zv  = pv(ji  ,jj  ,jk) * vmask(ji  ,jj  ,jk) * e1v(ji  ,jj  ) * fse3v(ji  ,jj  ,jk)
-               zv1 = pv(ji  ,jj-1,jk) * vmask(ji  ,jj-1,jk) * e1v(ji  ,jj-1) * fse3v(ji  ,jj-1,jk)
-               zet = 1. / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
-               zhdiv(ji,jj,jk) = ( zu - zu1 + zv - zv1 ) * zet 
+               zu  = pu(ji  ,jj  ,jk) * umask(ji  ,jj  ,jk) * e2u(ji  ,jj  ) * e3u_n(ji  ,jj  ,jk)
+               zu1 = pu(ji-1,jj  ,jk) * umask(ji-1,jj  ,jk) * e2u(ji-1,jj  ) * e3u_n(ji-1,jj  ,jk)
+               zv  = pv(ji  ,jj  ,jk) * vmask(ji  ,jj  ,jk) * e1v(ji  ,jj  ) * e3v_n(ji  ,jj  ,jk)
+               zv1 = pv(ji  ,jj-1,jk) * vmask(ji  ,jj-1,jk) * e1v(ji  ,jj-1) * e3v_n(ji  ,jj-1,jk)
+               zhdiv(ji,jj,jk) = ( zu - zu1 + zv - zv1 ) * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk) 
             END DO
          END DO
       END DO
       !                              !  update the horizontal divergence with the runoff inflow
-      IF( ln_dynrnf )  zhdiv(:,:,1) = zhdiv(:,:,1) - rnf(:,:) * r1_rau0 / fse3t(:,:,1)
+      IF( ln_dynrnf )   zhdiv(:,:,1) = zhdiv(:,:,1) - rnf(:,:) * r1_rau0 / e3t_n(:,:,1)
       !
       CALL lbc_lnk( zhdiv, 'T', 1. )      ! Lateral boundary conditions on zhdiv
@@ -465,5 +468,5 @@
       pw(:,:,jpk) = 0._wp
       DO jk = jpkm1, 1, -1
-         pw(:,:,jk) = pw(:,:,jk+1) - fse3t(:,:,jk) * zhdiv(:,:,jk)
+         pw(:,:,jk) = pw(:,:,jk+1) - e3t_n(:,:,jk) * zhdiv(:,:,jk)
       END DO
       !
@@ -489,12 +492,11 @@
          CALL bn2    ( pts, rab_n, rn2  ) ! now    Brunt-Vaisala
 
-         ! Partial steps: before Horizontal DErivative
-         IF( ln_zps  .AND. .NOT. ln_isfcav)                            &
-            &            CALL zps_hde    ( kt, jpts, pts, gtsu, gtsv,  &  ! Partial steps: before horizontal gradient
-            &                                        rhd, gru , grv    )  ! of t, s, rd at the last ocean level
-         IF( ln_zps .AND.        ln_isfcav)                            &
-            &            CALL zps_hde_isf( kt, jpts, pts, gtsu, gtsv,  &    ! Partial steps for top cell (ISF)
-            &                                        rhd, gru , grv , aru , arv , gzu , gzv , ge3ru , ge3rv ,   &
-            &                                 gtui, gtvi, grui, grvi, arui, arvi, gzui, gzvi, ge3rui, ge3rvi    ) ! of t, s, rd at the first ocean level
+      ! Partial steps: before Horizontal DErivative
+      IF( ln_zps  .AND. .NOT. ln_isfcav)                            &
+         &            CALL zps_hde    ( kt, jpts, pts, gtsu, gtsv,  &  ! Partial steps: before horizontal gradient
+         &                                        rhd, gru , grv    )  ! of t, s, rd at the last ocean level
+      IF( ln_zps .AND.        ln_isfcav)                            &
+         &            CALL zps_hde_isf( kt, jpts, pts, gtsu, gtsv, gtui, gtvi,  &  ! Partial steps for top cell (ISF)
+         &                                        rhd, gru , grv , grui, grvi   )  ! of t, s, rd at the first ocean level
 
          rn2b(:,:,:) = rn2(:,:,:)         ! need for zdfmxl
Index: /trunk/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 6140)
@@ -52,4 +52,6 @@
    USE trcrst
    USE diaptr         ! Need to initialise this as some variables are used in if statements later
+   USE sbc_oce, ONLY: ln_rnf
+   USE sbcrnf
 
    IMPLICIT NONE
@@ -94,4 +96,7 @@
       !                            !-----------------------!
       istp = nit000
+      !
+      ! Initialize arrays of runoffs structures and read data from the namelist
+      IF ( ln_rnf ) CALL sbc_rnf(istp)
       ! 
       CALL iom_init( cxios_context )            ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
@@ -148,5 +153,5 @@
       NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
          &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
-         &             nn_bench, nn_timing
+         &             nn_bench, nn_timing, nn_diacfl
       NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
          &             jpizoom, jpjzoom, jperio, ln_use_jattr
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90	(revision 6140)
@@ -33,5 +33,5 @@
    USE eosbn2             ! Equation of state (eos_bn2 routine)
    USE zdfmxl             ! Mixed layer depth
-   USE dom_oce, ONLY :   ndastp
+   USE dom_oce     , ONLY :   ndastp
    USE in_out_manager     ! I/O manager
    USE iom                ! I/O module
@@ -44,4 +44,5 @@
    USE ice
 #endif
+
    IMPLICIT NONE
    PRIVATE
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 6140)
@@ -11,9 +11,10 @@
    !!             -   ! 2010-05  (D. Lea)  add calc_month_len routine based on day_init 
    !!            3.4  ! 2012-10  (A. Weaver and K. Mogensen) Fix for direct initialization
+   !!                 ! 2014-09  (D. Lea)  Local calc_date removed use routine from OBS
+   !!                 ! 2015-11  (D. Lea)  Handle non-zero initial time of day
    !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
    !!   asm_inc_init   : Initialize the increment arrays and IAU weights
-   !!   calc_date      : Compute the calendar date YYYYMMDD on a given step
    !!   tra_asm_inc    : Apply the tracer (T and S) increments
    !!   dyn_asm_inc    : Apply the dynamic (u and v) increments
@@ -38,4 +39,5 @@
 #endif
    USE sbc_oce          ! Surface boundary condition variables.
+   USE diaobs, ONLY: calc_date     ! Compute the calendar date on a given step
 
    IMPLICIT NONE
@@ -43,5 +45,4 @@
    
    PUBLIC   asm_inc_init   !: Initialize the increment arrays and IAU weights
-   PUBLIC   calc_date      !: Compute the calendar date YYYYMMDD on a given step
    PUBLIC   tra_asm_inc    !: Apply the tracer (T and S) increments
    PUBLIC   dyn_asm_inc    !: Apply the dynamic (u and v) increments
@@ -87,8 +88,7 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -111,10 +111,10 @@
       INTEGER :: iiauper         ! Number of time steps in the IAU period
       INTEGER :: icycper         ! Number of time steps in the cycle
-      INTEGER :: iitend_date     ! Date YYYYMMDD of final time step
-      INTEGER :: iitbkg_date     ! Date YYYYMMDD of background time step for Jb term
-      INTEGER :: iitdin_date     ! Date YYYYMMDD of background time step for DI
-      INTEGER :: iitiaustr_date  ! Date YYYYMMDD of IAU interval start time step
-      INTEGER :: iitiaufin_date  ! Date YYYYMMDD of IAU interval final time step
-      !
+      REAL(KIND=dp) :: ditend_date     ! Date YYYYMMDD.HHMMSS of final time step
+      REAL(KIND=dp) :: ditbkg_date     ! Date YYYYMMDD.HHMMSS of background time step for Jb term
+      REAL(KIND=dp) :: ditdin_date     ! Date YYYYMMDD.HHMMSS of background time step for DI
+      REAL(KIND=dp) :: ditiaustr_date  ! Date YYYYMMDD.HHMMSS of IAU interval start time step
+      REAL(KIND=dp) :: ditiaufin_date  ! Date YYYYMMDD.HHMMSS of IAU interval final time step
+
       REAL(wp) :: znorm        ! Normalization factor for IAU weights
       REAL(wp) :: ztotwgt      ! Value of time-integrated IAU weights (should be equal to one)
@@ -178,10 +178,19 @@
       icycper = nitend      - nit000      + 1  ! Cycle interval length
 
-      CALL calc_date( nit000, nitend     , ndate0, iitend_date    )     ! Date of final time step
-      CALL calc_date( nit000, nitbkg_r   , ndate0, iitbkg_date    )     ! Background time for Jb referenced to ndate0
-      CALL calc_date( nit000, nitdin_r   , ndate0, iitdin_date    )     ! Background time for DI referenced to ndate0
-      CALL calc_date( nit000, nitiaustr_r, ndate0, iitiaustr_date )     ! IAU start time referenced to ndate0
-      CALL calc_date( nit000, nitiaufin_r, ndate0, iitiaufin_date )     ! IAU end time referenced to ndate0
-      !
+      ! Date of final time step
+      CALL calc_date( nitend, ditend_date )
+
+      ! Background time for Jb referenced to ndate0
+      CALL calc_date( nitbkg_r, ditbkg_date )
+
+      ! Background time for DI referenced to ndate0
+      CALL calc_date( nitdin_r, ditdin_date )
+
+      ! IAU start time referenced to ndate0
+      CALL calc_date( nitiaustr_r, ditiaustr_date )
+
+      ! IAU end time referenced to ndate0
+      CALL calc_date( nitiaufin_r, ditiaufin_date )
+
       IF(lwp) THEN
          WRITE(numout,*)
@@ -198,15 +207,12 @@
          WRITE(numout,*) '       ndastp         = ', ndastp
          WRITE(numout,*) '       ndate0         = ', ndate0
-         WRITE(numout,*) '       iitend_date    = ', iitend_date
-         WRITE(numout,*) '       iitbkg_date    = ', iitbkg_date
-         WRITE(numout,*) '       iitdin_date    = ', iitdin_date
-         WRITE(numout,*) '       iitiaustr_date = ', iitiaustr_date
-         WRITE(numout,*) '       iitiaufin_date = ', iitiaufin_date
+         WRITE(numout,*) '       nn_time0       = ', nn_time0
+         WRITE(numout,*) '       ditend_date    = ', ditend_date
+         WRITE(numout,*) '       ditbkg_date    = ', ditbkg_date
+         WRITE(numout,*) '       ditdin_date    = ', ditdin_date
+         WRITE(numout,*) '       ditiaustr_date = ', ditiaustr_date
+         WRITE(numout,*) '       ditiaufin_date = ', ditiaufin_date
       ENDIF
 
-      IF ( nacc /= 0 ) &
-         & CALL ctl_stop( ' nacc /= 0 and key_asminc :',  &
-         &                ' Assimilation increments have only been implemented', &
-         &                ' for synchronous time stepping' )
 
       IF ( ( ln_asmdin ).AND.( ln_asmiau ) )   &
@@ -360,15 +366,15 @@
             WRITE(numout,*) 
             WRITE(numout,*) 'asm_inc_init : Assimilation increments valid ', &
-               &            ' between dates ', NINT( z_inc_dateb ),' and ',  &
-               &            NINT( z_inc_datef )
+               &            ' between dates ', z_inc_dateb,' and ',  &
+               &            z_inc_datef
             WRITE(numout,*) '~~~~~~~~~~~~'
          ENDIF
 
-         IF (     ( NINT( z_inc_dateb ) < ndastp      ) &
-            & .OR.( NINT( z_inc_datef ) > iitend_date ) ) &
+         IF (     ( z_inc_dateb < ndastp + nn_time0*0.0001_wp ) &
+            & .OR.( z_inc_datef > ditend_date ) ) &
             & CALL ctl_warn( ' Validity time of assimilation increments is ', &
             &                ' outside the assimilation interval' )
 
-         IF ( ( ln_asmdin ).AND.( NINT( zdate_inc ) /= iitdin_date ) ) &
+         IF ( ( ln_asmdin ).AND.( zdate_inc /= ditdin_date ) ) &
             & CALL ctl_warn( ' Validity time of assimilation increments does ', &
             &                ' not agree with Direct Initialization time' )
@@ -430,14 +436,12 @@
          DO jt = 1, nn_divdmp
             !
-            DO jk = 1, jpkm1
+            DO jk = 1, jpkm1           ! hdiv = e1e1 * div
                hdiv(:,:) = 0._wp
                DO jj = 2, jpjm1
                   DO ji = fs_2, fs_jpim1   ! vector opt.
-                     hdiv(ji,jj) =   &
-                        (  e2u(ji  ,jj  ) * fse3u(ji  ,jj  ,jk) * u_bkginc(ji  ,jj  ,jk)     &
-                         - e2u(ji-1,jj  ) * fse3u(ji-1,jj  ,jk) * u_bkginc(ji-1,jj  ,jk)     &
-                         + e1v(ji  ,jj  ) * fse3v(ji  ,jj  ,jk) * v_bkginc(ji  ,jj  ,jk)     &
-                         - e1v(ji  ,jj-1) * fse3v(ji  ,jj-1,jk) * v_bkginc(ji  ,jj-1,jk)  )  &
-                         / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
+                     hdiv(ji,jj) = (  e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) * u_bkginc(ji  ,jj,jk)    &
+                        &           - e2u(ji-1,jj) * e3u_n(ji-1,jj,jk) * u_bkginc(ji-1,jj,jk)    &
+                        &           + e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * v_bkginc(ji,jj  ,jk)    &
+                        &           - e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * v_bkginc(ji,jj-1,jk)  ) / e3t_n(ji,jj,jk)
                   END DO
                END DO
@@ -446,10 +450,8 @@
                DO jj = 2, jpjm1
                   DO ji = fs_2, fs_jpim1   ! vector opt.
-                     u_bkginc(ji,jj,jk) = u_bkginc(ji,jj,jk) + 0.2_wp * ( e1e2t(ji+1,jj) * hdiv(ji+1,jj)   &
-                        &                                               - e1e2t(ji  ,jj) * hdiv(ji  ,jj) ) &
-                        &                                             * r1_e1u(ji,jj) * umask(ji,jj,jk) 
-                     v_bkginc(ji,jj,jk) = v_bkginc(ji,jj,jk) + 0.2_wp * ( e1e2t(ji,jj+1) * hdiv(ji,jj+1)   &
-                        &                                               - e1e2t(ji,jj  ) * hdiv(ji,jj  ) ) &
-                        &                                             * r1_e2v(ji,jj) * vmask(ji,jj,jk) 
+                     u_bkginc(ji,jj,jk) = u_bkginc(ji,jj,jk)                         &
+                        &               + 0.2_wp * ( hdiv(ji+1,jj) - hdiv(ji  ,jj) ) * r1_e1u(ji,jj) * umask(ji,jj,jk)
+                     v_bkginc(ji,jj,jk) = v_bkginc(ji,jj,jk)                         &
+                        &               + 0.2_wp * ( hdiv(ji,jj+1) - hdiv(ji,jj  ) ) * r1_e2v(ji,jj) * vmask(ji,jj,jk) 
                   END DO
                END DO
@@ -490,9 +492,10 @@
          IF(lwp) THEN
             WRITE(numout,*) 
-            WRITE(numout,*) 'asm_inc_init : Assimilation background state valid at : ', NINT( zdate_bkg )
+            WRITE(numout,*) 'asm_inc_init : Assimilation background state valid at : ', &
+               &  zdate_bkg
             WRITE(numout,*) '~~~~~~~~~~~~'
          ENDIF
          !
-         IF ( NINT( zdate_bkg ) /= iitdin_date ) &
+         IF ( zdate_bkg /= ditdin_date ) &
             & CALL ctl_warn( ' Validity time of assimilation background state does', &
             &                ' not agree with Direct Initialization time' )
@@ -522,106 +525,4 @@
       !
    END SUBROUTINE asm_inc_init
-
-
-   SUBROUTINE calc_date( kit000, kt, kdate0, kdate )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE calc_date  ***
-      !!          
-      !! ** Purpose : Compute the calendar date YYYYMMDD at a given time step.
-      !!
-      !! ** Method  : Compute the calendar date YYYYMMDD at a given time step.
-      !!
-      !! ** Action  : 
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(IN) :: kit000  ! Initial time step
-      INTEGER, INTENT(IN) :: kt      ! Current time step referenced to kit000
-      INTEGER, INTENT(IN) :: kdate0  ! Initial date
-      INTEGER, INTENT(OUT) :: kdate  ! Current date reference to kdate0
-      !
-      INTEGER :: iyea0    ! Initial year
-      INTEGER :: imon0    ! Initial month
-      INTEGER :: iday0    ! Initial day
-      INTEGER :: iyea     ! Current year
-      INTEGER :: imon     ! Current month
-      INTEGER :: iday     ! Current day
-      INTEGER :: idaystp  ! Number of days between initial and current date
-      INTEGER :: idaycnt  ! Day counter
-
-      INTEGER, DIMENSION(12) ::   imonth_len    !: length in days of the months of the current year
-
-      !-----------------------------------------------------------------------
-      ! Compute the calendar date YYYYMMDD
-      !-----------------------------------------------------------------------
-
-      ! Initial date
-      iyea0 =   kdate0 / 10000
-      imon0 = ( kdate0 - ( iyea0 * 10000 ) ) / 100
-      iday0 =   kdate0 - ( iyea0 * 10000 ) - ( imon0 * 100 ) 
-
-      ! Check that kt >= kit000 - 1
-      IF ( kt < kit000 - 1 ) CALL ctl_stop( ' kt must be >= kit000 - 1')
-
-      ! If kt = kit000 - 1 then set the date to the restart date
-      IF ( kt == kit000 - 1 ) THEN
-         kdate = ndastp
-         RETURN
-      ENDIF
-
-      ! Compute the number of days from the initial date
-      idaystp = INT( REAL( kt - kit000 ) * rdt / 86400. )
-   
-      iday    = iday0
-      imon    = imon0
-      iyea    = iyea0
-      idaycnt = 0
-
-      CALL calc_month_len( iyea, imonth_len )
-
-      DO WHILE ( idaycnt < idaystp )
-         iday = iday + 1
-         IF ( iday > imonth_len(imon) )  THEN
-            iday = 1
-            imon = imon + 1
-         ENDIF
-         IF ( imon > 12 ) THEN
-            imon = 1
-            iyea = iyea + 1
-            CALL calc_month_len( iyea, imonth_len )  ! update month lengths
-         ENDIF                 
-         idaycnt = idaycnt + 1
-      END DO
-      !
-      kdate = iyea * 10000 + imon * 100 + iday
-      !
-   END SUBROUTINE
-
-
-   SUBROUTINE calc_month_len( iyear, imonth_len )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE calc_month_len  ***
-      !!          
-      !! ** Purpose : Compute the number of days in a months given a year.
-      !!
-      !! ** Method  : 
-      !!----------------------------------------------------------------------
-      INTEGER, DIMENSION(12) ::   imonth_len    !: length in days of the months of the current year
-      INTEGER :: iyear         !: year
-      !!----------------------------------------------------------------------
-      !
-      ! length of the month of the current year (from nleapy, read in namelist)
-      IF ( nleapy < 2 ) THEN 
-         imonth_len(:) = (/ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 /)
-         IF ( nleapy == 1 ) THEN   ! we are using calendar with leap years
-            IF ( MOD(iyear, 4) == 0 .AND. ( MOD(iyear, 400) == 0 .OR. MOD(iyear, 100) /= 0 ) ) THEN
-               imonth_len(2) = 29
-            ENDIF
-         ENDIF
-      ELSE
-         imonth_len(:) = nleapy   ! all months with nleapy days per year
-      ENDIF
-      !
-   END SUBROUTINE
-
-
    SUBROUTINE tra_asm_inc( kt )
       !!----------------------------------------------------------------------
@@ -645,5 +546,5 @@
       ! used to prevent the applied increments taking the temperature below the local freezing point 
       DO jk = 1, jpkm1
-        CALL eos_fzp( tsn(:,:,jk,jp_sal), fzptnz(:,:,jk), fsdept(:,:,jk) )
+        CALL eos_fzp( tsn(:,:,jk,jp_sal), fzptnz(:,:,jk), gdept_n(:,:,jk) )
       END DO
          !
@@ -726,15 +627,11 @@
 !!gm
 
-            IF( ln_zps .AND. .NOT. lk_c1d ) THEN      ! Partial steps: before horizontal gradient
-               IF(ln_isfcav) THEN                        ! ocean cavities: top and bottom cells (ISF)
-                  CALL zps_hde_isf( nit000, jpts, tsb, gtsu, gtsv, gtui, gtvi,     &
-                     &                            rhd, gru , grv , aru , arv , gzu , gzv , ge3ru , ge3rv ,   &
-                     &                     grui, grvi, arui, arvi, gzui, gzvi, ge3rui, ge3rvi    )
-               ELSE                                      ! no ocean cavities: bottom cells
-                  CALL zps_hde    ( kt, jpts, tsb, gtsu, gtsv,        &  ! 
-                     &                        rhd, gru , grv          )  ! of t, s, rd at the last ocean level
-               ENDIF
-            ENDIF
-            !
+            IF( ln_zps .AND. .NOT. lk_c1d .AND. .NOT. ln_isfcav)      &
+               &  CALL zps_hde    ( kt, jpts, tsb, gtsu, gtsv,        &  ! Partial steps: before horizontal gradient
+               &                              rhd, gru , grv          )  ! of t, s, rd at the last ocean level
+            IF( ln_zps .AND. .NOT. lk_c1d .AND.       ln_isfcav)      &
+               &  CALL zps_hde_isf( nit000, jpts, tsb, gtsu, gtsv, gtui, gtvi,    &    ! Partial steps for top cell (ISF)
+               &                                  rhd, gru , grv , grui, grvi     )    ! of t, s, rd at the last ocean level
+
             DEALLOCATE( t_bkginc )
             DEALLOCATE( s_bkginc )
@@ -874,10 +771,6 @@
             !
             sshb(:,:) = sshn(:,:)                        ! Update before fields
-            !
-            IF( lk_vvl ) THEN
-               DO jk = 1, jpk
-                  fse3t_b(:,:,jk) = fse3t_n(:,:,jk)
-               END DO
-            ENDIF
+            e3t_b(:,:,:) = e3t_n(:,:,:)
+!!gm why not e3u_b, e3v_b, gdept_b ????
             !
             DEALLOCATE( ssh_bkg    )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 6140)
@@ -70,4 +70,10 @@
       REAL(wp), POINTER, DIMENSION(:,:) ::   ht_i   !: Now ice  thickness climatology
       REAL(wp), POINTER, DIMENSION(:,:) ::   ht_s   !: now snow thickness
+#endif
+#if defined key_top
+      CHARACTER(LEN=20)                   :: cn_obc  !: type of boundary condition to apply
+      REAL(wp)                            :: rn_fac  !: multiplicative scaling factor
+      REAL(wp), POINTER, DIMENSION(:,:)   :: trc     !: now field of the tracer
+      LOGICAL                             :: dmp     !: obc damping term
 #endif
    END TYPE OBC_DATA
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 6140)
@@ -45,5 +45,4 @@
    INTEGER, ALLOCATABLE, DIMENSION(:)   ::   nb_bdy_fld        ! Number of fields to update for each boundary set.
    INTEGER                              ::   nb_bdy_fld_sum    ! Total number of fields to update for all boundary sets.
-
    LOGICAL,           DIMENSION(jp_bdy) ::   ln_full_vel_array ! =T => full velocities in 3D boundary conditions
                                                                ! =F => baroclinic velocities in 3D boundary conditions
@@ -58,5 +57,4 @@
 #endif
 
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -75,26 +73,24 @@
       !!                
       !!----------------------------------------------------------------------
-      !!
-      INTEGER, INTENT( in )           ::   kt    ! ocean time-step index 
-      INTEGER, INTENT( in ), OPTIONAL ::   jit   ! subcycle time-step index (for timesplitting option)
-      INTEGER, INTENT( in ), OPTIONAL ::   time_offset  ! time offset in units of timesteps. NB. if jit
-                                                        ! is present then units = subcycle timesteps.
-                                                        ! time_offset = 0 => get data at "now" time level
-                                                        ! time_offset = -1 => get data at "before" time level
-                                                        ! time_offset = +1 => get data at "after" time level
-                                                        ! etc.
-      !!
-      INTEGER     ::  ib_bdy, jfld, jstart, jend, ib, ii, ij, ik, igrd, jl  ! local indices
+      INTEGER, INTENT(in)           ::   kt           ! ocean time-step index 
+      INTEGER, INTENT(in), OPTIONAL ::   jit          ! subcycle time-step index (for timesplitting option)
+      INTEGER, INTENT(in), OPTIONAL ::   time_offset  ! time offset in units of timesteps. NB. if jit
+      !                                               ! is present then units = subcycle timesteps.
+      !                                               ! time_offset = 0 => get data at "now" time level
+      !                                               ! time_offset = -1 => get data at "before" time level
+      !                                               ! time_offset = +1 => get data at "after" time level
+      !                                               ! etc.
+      !
+      INTEGER ::  ib_bdy, jfld, jstart, jend, ib, ii, ij, ik, igrd, jl  ! local indices
       INTEGER,          DIMENSION(jpbgrd) ::   ilen1 
       INTEGER, POINTER, DIMENSION(:)      ::   nblen, nblenrim  ! short cuts
       TYPE(OBC_DATA), POINTER             ::   dta              ! short cut
-      !!
       !!---------------------------------------------------------------------------
-      !!
-      IF( nn_timing == 1 ) CALL timing_start('bdy_dta')
-
+      !
+      IF( nn_timing == 1 )   CALL timing_start('bdy_dta')
+      !
       ! Initialise data arrays once for all from initial conditions where required
       !---------------------------------------------------------------------------
-      IF( kt .eq. nit000 .and. .not. PRESENT(jit) ) THEN
+      IF( kt == nit000 .AND. .NOT.PRESENT(jit) ) THEN
 
          ! Calculate depth-mean currents
@@ -102,10 +98,10 @@
          
          DO ib_bdy = 1, nb_bdy
-
+            !
             nblen => idx_bdy(ib_bdy)%nblen
             nblenrim => idx_bdy(ib_bdy)%nblenrim
             dta => dta_bdy(ib_bdy)
 
-            IF( nn_dyn2d_dta(ib_bdy) .eq. 0 ) THEN 
+            IF( nn_dyn2d_dta(ib_bdy) == 0 ) THEN 
                ilen1(:) = nblen(:)
                IF( dta%ll_ssh ) THEN 
@@ -135,5 +131,5 @@
             ENDIF
 
-            IF( nn_dyn3d_dta(ib_bdy) .eq. 0 ) THEN 
+            IF( nn_dyn3d_dta(ib_bdy) == 0 ) THEN 
                ilen1(:) = nblen(:)
                IF( dta%ll_u3d ) THEN 
@@ -159,5 +155,5 @@
             ENDIF
 
-            IF( nn_tra_dta(ib_bdy) .eq. 0 ) THEN 
+            IF( nn_tra_dta(ib_bdy) == 0 ) THEN 
                ilen1(:) = nblen(:)
                IF( dta%ll_tem ) THEN
@@ -184,5 +180,5 @@
 
 #if defined key_lim2
-            IF( nn_ice_lim_dta(ib_bdy) .eq. 0 ) THEN 
+            IF( nn_ice_lim_dta(ib_bdy) == 0 ) THEN 
                ilen1(:) = nblen(:)
                IF( dta%ll_frld ) THEN
@@ -212,5 +208,5 @@
             ENDIF
 #elif defined key_lim3
-            IF( nn_ice_lim_dta(ib_bdy) .eq. 0 ) THEN 
+            IF( nn_ice_lim_dta(ib_bdy) == 0 ) THEN 
                ilen1(:) = nblen(:)
                IF( dta%ll_a_i ) THEN
@@ -246,9 +242,7 @@
             ENDIF
 #endif
-
-         ENDDO ! ib_bdy
-
-
-      ENDIF ! kt .eq. nit000
+         END DO ! ib_bdy
+         !
+      ENDIF ! kt == nit000
 
       ! update external data from files
@@ -258,5 +252,5 @@
       DO ib_bdy = 1, nb_bdy   
          dta => dta_bdy(ib_bdy)
-         IF( nn_dta(ib_bdy) .eq. 1 ) THEN ! skip this bit if no external data required
+         IF( nn_dta(ib_bdy) == 1 ) THEN ! skip this bit if no external data required
       
             IF( PRESENT(jit) ) THEN
@@ -264,11 +258,11 @@
                ! jit is optional argument for fld_read and bdytide_update
                IF( cn_dyn2d(ib_bdy) /= 'none' ) THEN
-                  IF( nn_dyn2d_dta(ib_bdy) .eq. 2 ) THEN ! tidal harmonic forcing ONLY: initialise arrays
-                     IF( dta%ll_ssh ) dta%ssh(:) = 0.0
-                     IF( dta%ll_u2d ) dta%u2d(:) = 0.0
-                     IF( dta%ll_u3d ) dta%v2d(:) = 0.0
+                  IF( nn_dyn2d_dta(ib_bdy) == 2 ) THEN ! tidal harmonic forcing ONLY: initialise arrays
+                     IF( dta%ll_ssh ) dta%ssh(:) = 0._wp
+                     IF( dta%ll_u2d ) dta%u2d(:) = 0._wp
+                     IF( dta%ll_u3d ) dta%v2d(:) = 0._wp
                   ENDIF
                   IF (cn_tra(ib_bdy) /= 'runoff') THEN
-                     IF( nn_dyn2d_dta(ib_bdy) .EQ. 1 .OR. nn_dyn2d_dta(ib_bdy) .EQ. 3 ) THEN
+                     IF( nn_dyn2d_dta(ib_bdy) == 1 .OR. nn_dyn2d_dta(ib_bdy) == 3 ) THEN
 
                         jend = jstart + dta%nread(2) - 1
@@ -278,9 +272,9 @@
                         ! If full velocities in boundary data then extract barotropic velocities from 3D fields
                         IF( ln_full_vel_array(ib_bdy) .AND.                                             &
-                          &    ( nn_dyn2d_dta(ib_bdy) .EQ. 1 .OR. nn_dyn2d_dta(ib_bdy) .EQ. 3 .OR.  &
-                          &      nn_dyn3d_dta(ib_bdy) .EQ. 1 ) )THEN
+                          &    ( nn_dyn2d_dta(ib_bdy) == 1 .OR. nn_dyn2d_dta(ib_bdy) == 3 .OR.  &
+                          &      nn_dyn3d_dta(ib_bdy) == 1 ) )THEN
 
                            igrd = 2                      ! zonal velocity
-                           dta%u2d(:) = 0.0
+                           dta%u2d(:) = 0._wp
                            DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
                               ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
@@ -288,10 +282,10 @@
                               DO ik = 1, jpkm1
                                  dta%u2d(ib) = dta%u2d(ib) &
-                       &                          + fse3u(ii,ij,ik) * umask(ii,ij,ik) * dta%u3d(ib,ik)
+                       &                          + e3u_n(ii,ij,ik) * umask(ii,ij,ik) * dta%u3d(ib,ik)
                               END DO
-                              dta%u2d(ib) =  dta%u2d(ib) * hur(ii,ij)
+                              dta%u2d(ib) =  dta%u2d(ib) * r1_hu_n(ii,ij)
                            END DO
                            igrd = 3                      ! meridional velocity
-                           dta%v2d(:) = 0.0
+                           dta%v2d(:) = 0._wp
                            DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
                               ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
@@ -299,7 +293,7 @@
                               DO ik = 1, jpkm1
                                  dta%v2d(ib) = dta%v2d(ib) &
-                       &                       + fse3v(ii,ij,ik) * vmask(ii,ij,ik) * dta%v3d(ib,ik)
+                       &                       + e3v_n(ii,ij,ik) * vmask(ii,ij,ik) * dta%v3d(ib,ik)
                               END DO
-                              dta%v2d(ib) =  dta%v2d(ib) * hvr(ii,ij)
+                              dta%v2d(ib) =  dta%v2d(ib) * r1_hv_n(ii,ij)
                            END DO
                         ENDIF                    
@@ -331,8 +325,8 @@
                   END DO
                ELSE
-                  IF( nn_dyn2d_dta(ib_bdy) .eq. 2 ) THEN ! tidal harmonic forcing ONLY: initialise arrays
-                     IF( dta%ll_ssh ) dta%ssh(:) = 0.0
-                     IF( dta%ll_u2d ) dta%u2d(:) = 0.0
-                     IF( dta%ll_v2d ) dta%v2d(:) = 0.0
+                  IF( nn_dyn2d_dta(ib_bdy) == 2 ) THEN ! tidal harmonic forcing ONLY: initialise arrays
+                     IF( dta%ll_ssh ) dta%ssh(:) = 0._wp
+                     IF( dta%ll_u2d ) dta%u2d(:) = 0._wp
+                     IF( dta%ll_v2d ) dta%v2d(:) = 0._wp
                   ENDIF
                   IF( dta%nread(1) .gt. 0 ) THEN ! update external data
@@ -343,8 +337,8 @@
                   ! If full velocities in boundary data then split into barotropic and baroclinic data
                   IF( ln_full_vel_array(ib_bdy) .and.                                             &
-                    & ( nn_dyn2d_dta(ib_bdy) .EQ. 1 .OR. nn_dyn2d_dta(ib_bdy) .EQ. 3 .OR. &
-                    &   nn_dyn3d_dta(ib_bdy) .EQ. 1 ) ) THEN
+                    & ( nn_dyn2d_dta(ib_bdy) == 1 .OR. nn_dyn2d_dta(ib_bdy) == 3 .OR. &
+                    &   nn_dyn3d_dta(ib_bdy) == 1 ) ) THEN
                      igrd = 2                      ! zonal velocity
-                     dta%u2d(:) = 0.0
+                     dta%u2d(:) = 0._wp
                      DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
                         ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
@@ -352,7 +346,7 @@
                         DO ik = 1, jpkm1
                            dta%u2d(ib) = dta%u2d(ib) &
-                 &                       + fse3u(ii,ij,ik) * umask(ii,ij,ik) * dta%u3d(ib,ik)
+                 &                       + e3u_n(ii,ij,ik) * umask(ii,ij,ik) * dta%u3d(ib,ik)
                         END DO
-                        dta%u2d(ib) =  dta%u2d(ib) * hur(ii,ij)
+                        dta%u2d(ib) =  dta%u2d(ib) * r1_hu_n(ii,ij)
                         DO ik = 1, jpkm1
                            dta%u3d(ib,ik) = dta%u3d(ib,ik) - dta%u2d(ib)
@@ -360,5 +354,5 @@
                      END DO
                      igrd = 3                      ! meridional velocity
-                     dta%v2d(:) = 0.0
+                     dta%v2d(:) = 0._wp
                      DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
                         ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
@@ -366,7 +360,7 @@
                         DO ik = 1, jpkm1
                            dta%v2d(ib) = dta%v2d(ib) &
-                 &                       + fse3v(ii,ij,ik) * vmask(ii,ij,ik) * dta%v3d(ib,ik)
+                 &                       + e3v_n(ii,ij,ik) * vmask(ii,ij,ik) * dta%v3d(ib,ik)
                         END DO
-                        dta%v2d(ib) =  dta%v2d(ib) * hvr(ii,ij)
+                        dta%v2d(ib) =  dta%v2d(ib) * r1_hv_n(ii,ij)
                         DO ik = 1, jpkm1
                            dta%v3d(ib,ik) = dta%v3d(ib,ik) - dta%v2d(ib)
@@ -413,15 +407,15 @@
                   ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
                   dta_bdy(ib_bdy)%ssh(ib) = dta_bdy(ib_bdy)%ssh(ib) + ssh_ib(ii,ij)
-               ENDDO
-            ENDIF
-         ENDDO
+               END DO
+            ENDIF
+         END DO
       ENDIF
-
+      !
       IF( nn_timing == 1 ) CALL timing_stop('bdy_dta')
-
-      END SUBROUTINE bdy_dta
-
-
-      SUBROUTINE bdy_dta_init
+      !
+   END SUBROUTINE bdy_dta
+
+
+   SUBROUTINE bdy_dta_init
       !!----------------------------------------------------------------------
       !!                   ***  SUBROUTINE bdy_dta_init  ***
@@ -433,8 +427,6 @@
       !!                
       !!----------------------------------------------------------------------
-      !!
-      INTEGER     ::  ib_bdy, jfld, jstart, jend, ierror  ! local indices
-      INTEGER      ::   ios                               ! Local integer output status for namelist read
-      !!
+      INTEGER ::   ib_bdy, jfld, jstart, jend, ierror, ios     ! Local integers
+      !
       CHARACTER(len=100)                     ::   cn_dir        ! Root directory for location of data files
       CHARACTER(len=100), DIMENSION(nb_bdy)  ::   cn_dir_array  ! Root directory for location of data files
@@ -469,7 +461,7 @@
       NAMELIST/nambdy_dta/ ln_full_vel
       !!---------------------------------------------------------------------------
-
-      IF( nn_timing == 1 ) CALL timing_start('bdy_dta_init')
-
+      !
+      IF( nn_timing == 1 )   CALL timing_start('bdy_dta_init')
+      !
       IF(lwp) WRITE(numout,*)
       IF(lwp) WRITE(numout,*) 'bdy_dta_ini : initialization of data at the open boundaries'
@@ -486,5 +478,5 @@
 #endif
                               )
-         IF(nn_dta(ib_bdy) .gt. 1) nn_dta(ib_bdy) = 1
+         IF(nn_dta(ib_bdy) > 1) nn_dta(ib_bdy) = 1
       END DO
 
@@ -494,20 +486,20 @@
       nb_bdy_fld(:) = 0
       DO ib_bdy = 1, nb_bdy         
-         IF( cn_dyn2d(ib_bdy) /= 'none' .and. ( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) ) THEN
+         IF( cn_dyn2d(ib_bdy) /= 'none' .and. ( nn_dyn2d_dta(ib_bdy) == 1 .or. nn_dyn2d_dta(ib_bdy) == 3 ) ) THEN
             nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 3
          ENDIF
-         IF( cn_dyn3d(ib_bdy) /= 'none' .and. nn_dyn3d_dta(ib_bdy) .eq. 1 ) THEN
+         IF( cn_dyn3d(ib_bdy) /= 'none' .and. nn_dyn3d_dta(ib_bdy) == 1 ) THEN
             nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 2
          ENDIF
-         IF( cn_tra(ib_bdy) /= 'none' .and. nn_tra_dta(ib_bdy) .eq. 1  ) THEN
+         IF( cn_tra(ib_bdy) /= 'none' .and. nn_tra_dta(ib_bdy) == 1  ) THEN
             nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 2
          ENDIF
 #if ( defined key_lim2 || defined key_lim3 )
-         IF( cn_ice_lim(ib_bdy) /= 'none' .and. nn_ice_lim_dta(ib_bdy) .eq. 1  ) THEN
+         IF( cn_ice_lim(ib_bdy) /= 'none' .and. nn_ice_lim_dta(ib_bdy) == 1  ) THEN
             nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 3
          ENDIF
 #endif               
          IF(lwp) WRITE(numout,*) 'Maximum number of files to open =',nb_bdy_fld(ib_bdy)
-      ENDDO            
+      END DO            
 
       nb_bdy_fld_sum = SUM( nb_bdy_fld )
@@ -535,11 +527,11 @@
       jfld = 0 
       DO ib_bdy = 1, nb_bdy         
-         IF( nn_dta(ib_bdy) .eq. 1 ) THEN
+         IF( nn_dta(ib_bdy) == 1 ) THEN
             READ  ( numnam_ref, nambdy_dta, IOSTAT = ios, ERR = 901)
-901         IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy_dta in reference namelist', lwp )
+901         IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy_dta in reference namelist', lwp )
 
             READ  ( numnam_cfg, nambdy_dta, IOSTAT = ios, ERR = 902 )
-902         IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy_dta in configuration namelist', lwp )
-            IF(lwm) WRITE ( numond, nambdy_dta )
+902         IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy_dta in configuration namelist', lwp )
+            IF(lwm) WRITE( numond, nambdy_dta )
 
             cn_dir_array(ib_bdy) = cn_dir
@@ -553,5 +545,5 @@
             ! Only read in necessary fields for this set.
             ! Important that barotropic variables come first.
-            IF( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) THEN 
+            IF( nn_dyn2d_dta(ib_bdy) == 1 .or. nn_dyn2d_dta(ib_bdy) == 3 ) THEN 
 
                IF( dta%ll_ssh ) THEN 
@@ -592,8 +584,8 @@
             ! read 3D velocities if baroclinic velocities require OR if
             ! barotropic velocities required and ln_full_vel set to .true.
-            IF( nn_dyn3d_dta(ib_bdy) .eq. 1 .or. &
-           &  ( ln_full_vel_array(ib_bdy) .and. ( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) ) ) THEN
-
-               IF( dta%ll_u3d .or. ( ln_full_vel_array(ib_bdy) .and. dta%ll_u2d ) ) THEN
+            IF( nn_dyn3d_dta(ib_bdy) == 1 .OR. &
+           &  ( ln_full_vel_array(ib_bdy) .AND. ( nn_dyn2d_dta(ib_bdy) == 1 .or. nn_dyn2d_dta(ib_bdy) == 3 ) ) ) THEN
+
+               IF( dta%ll_u3d .OR. ( ln_full_vel_array(ib_bdy) .and. dta%ll_u2d ) ) THEN
                   if(lwp) write(numout,*) '++++++ reading in u3d field'
                   jfld = jfld + 1
@@ -606,5 +598,5 @@
                ENDIF
 
-               IF( dta%ll_v3d .or. ( ln_full_vel_array(ib_bdy) .and. dta%ll_v2d ) ) THEN
+               IF( dta%ll_v3d .OR. ( ln_full_vel_array(ib_bdy) .and. dta%ll_v2d ) ) THEN
                   if(lwp) write(numout,*) '++++++ reading in v3d field'
                   jfld = jfld + 1
@@ -620,5 +612,5 @@
 
             ! temperature and salinity
-            IF( nn_tra_dta(ib_bdy) .eq. 1 ) THEN
+            IF( nn_tra_dta(ib_bdy) == 1 ) THEN
 
                IF( dta%ll_tem ) THEN
@@ -646,5 +638,5 @@
 #if defined key_lim2
             ! sea ice
-            IF( nn_ice_lim_dta(ib_bdy) .eq. 1 ) THEN
+            IF( nn_ice_lim_dta(ib_bdy) == 1 ) THEN
 
                IF( dta%ll_frld ) THEN
@@ -678,5 +670,5 @@
 #elif defined key_lim3
             ! sea ice
-            IF( nn_ice_lim_dta(ib_bdy) .eq. 1 ) THEN
+            IF( nn_ice_lim_dta(ib_bdy) == 1 ) THEN
                ! Test for types of ice input (lim2 or lim3) 
                ! Build file name to find dimensions 
@@ -733,5 +725,5 @@
             ! Recalculate field counts
             !-------------------------
-            IF( ib_bdy .eq. 1 ) THEN 
+            IF( ib_bdy == 1 ) THEN 
                nb_bdy_fld_sum = 0
                nb_bdy_fld(ib_bdy) = jfld
@@ -744,5 +736,5 @@
             dta%nread(1) = nb_bdy_fld(ib_bdy)
 
-         ENDIF ! nn_dta .eq. 1
+         ENDIF ! nn_dta == 1
       ENDDO ! ib_bdy
 
@@ -785,5 +777,5 @@
          endif
 
-         IF ( nn_dyn2d_dta(ib_bdy) .eq. 0 .or. nn_dyn2d_dta(ib_bdy) .eq. 2 ) THEN
+         IF ( nn_dyn2d_dta(ib_bdy) == 0 .or. nn_dyn2d_dta(ib_bdy) == 2 ) THEN
             if(lwp) write(numout,*) '++++++ dta%ssh/u2d/u3d allocated space'
             IF( dta%ll_ssh ) ALLOCATE( dta%ssh(nblen(1)) )
@@ -791,5 +783,5 @@
             IF( dta%ll_v2d ) ALLOCATE( dta%v2d(nblen(3)) )
          ENDIF
-         IF ( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) THEN
+         IF ( nn_dyn2d_dta(ib_bdy) == 1 .or. nn_dyn2d_dta(ib_bdy) == 3 ) THEN
             IF( dta%ll_ssh ) THEN
                if(lwp) write(numout,*) '++++++ dta%ssh pointing to fnow'
@@ -819,11 +811,11 @@
          ENDIF
 
-         IF ( nn_dyn3d_dta(ib_bdy) .eq. 0 ) THEN
+         IF ( nn_dyn3d_dta(ib_bdy) == 0 ) THEN
             if(lwp) write(numout,*) '++++++ dta%u3d/v3d allocated space'
             IF( dta%ll_u3d ) ALLOCATE( dta_bdy(ib_bdy)%u3d(nblen(2),jpk) )
             IF( dta%ll_v3d ) ALLOCATE( dta_bdy(ib_bdy)%v3d(nblen(3),jpk) )
          ENDIF
-         IF ( nn_dyn3d_dta(ib_bdy) .eq. 1 .or. &
-           &  ( ln_full_vel_array(ib_bdy) .and. ( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) ) ) THEN
+         IF ( nn_dyn3d_dta(ib_bdy) == 1 .or. &
+           &  ( ln_full_vel_array(ib_bdy) .and. ( nn_dyn2d_dta(ib_bdy) == 1 .or. nn_dyn2d_dta(ib_bdy) == 3 ) ) ) THEN
             IF ( dta%ll_u3d .or. ( ln_full_vel_array(ib_bdy) .and. dta%ll_u2d ) ) THEN
                if(lwp) write(numout,*) '++++++ dta%u3d pointing to fnow'
@@ -838,5 +830,5 @@
          ENDIF
 
-         IF( nn_tra_dta(ib_bdy) .eq. 0 ) THEN
+         IF( nn_tra_dta(ib_bdy) == 0 ) THEN
             if(lwp) write(numout,*) '++++++ dta%tem/sal allocated space'
             IF( dta%ll_tem ) ALLOCATE( dta_bdy(ib_bdy)%tem(nblen(1),jpk) )
@@ -857,5 +849,5 @@
 #if defined key_lim2
          IF (cn_ice_lim(ib_bdy) /= 'none') THEN
-            IF( nn_ice_lim_dta(ib_bdy) .eq. 0 ) THEN
+            IF( nn_ice_lim_dta(ib_bdy) == 0 ) THEN
                ALLOCATE( dta_bdy(ib_bdy)%frld(nblen(1)) )
                ALLOCATE( dta_bdy(ib_bdy)%hicif(nblen(1)) )
@@ -872,5 +864,5 @@
 #elif defined key_lim3
          IF (cn_ice_lim(ib_bdy) /= 'none') THEN
-            IF( nn_ice_lim_dta(ib_bdy) .eq. 0 ) THEN
+            IF( nn_ice_lim_dta(ib_bdy) == 0 ) THEN
                ALLOCATE( dta_bdy(ib_bdy)%a_i (nblen(1),jpl) )
                ALLOCATE( dta_bdy(ib_bdy)%ht_i(nblen(1),jpl) )
@@ -892,18 +884,18 @@
                   ALLOCATE( dta_bdy(ib_bdy)%ht_i(nblen(1),jpl) )
                   ALLOCATE( dta_bdy(ib_bdy)%ht_s(nblen(1),jpl) )
-                  dta_bdy(ib_bdy)%a_i (:,:) = 0.0
-                  dta_bdy(ib_bdy)%ht_i(:,:) = 0.0
-                  dta_bdy(ib_bdy)%ht_s(:,:) = 0.0
-               ENDIF
-
-            ENDIF
-         ENDIF
-#endif
-
-      ENDDO ! ib_bdy 
-
+                  dta_bdy(ib_bdy)%a_i (:,:) = 0._wp
+                  dta_bdy(ib_bdy)%ht_i(:,:) = 0._wp
+                  dta_bdy(ib_bdy)%ht_s(:,:) = 0._wp
+               ENDIF
+
+            ENDIF
+         ENDIF
+#endif
+         !
+      END DO ! ib_bdy 
+      !
       IF( nn_timing == 1 ) CALL timing_stop('bdy_dta_init')
-
-      END SUBROUTINE bdy_dta_init
+      !
+   END SUBROUTINE bdy_dta_init
 
 #else
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90	(revision 6140)
@@ -36,5 +36,4 @@
    PUBLIC   bdy_dyn    ! routine called in dyn_nxt
 
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -51,27 +50,26 @@
       !!
       !!----------------------------------------------------------------------
-      !!
-      INTEGER, INTENT( in )           :: kt               ! Main time step counter
-      LOGICAL, INTENT( in ), OPTIONAL :: dyn3d_only       ! T => only update baroclinic velocities
-      !!
-      INTEGER               :: jk,ii,ij,ib_bdy,ib,igrd     ! Loop counter
-      LOGICAL               :: ll_dyn2d, ll_dyn3d, ll_orlanski
-      !!
+      INTEGER, INTENT(in)           ::   kt           ! Main time step counter
+      LOGICAL, INTENT(in), OPTIONAL ::   dyn3d_only   ! T => only update baroclinic velocities
+      !
+      INTEGER ::   jk, ii, ij, ib_bdy, ib, igrd     ! Loop counter
+      LOGICAL ::   ll_dyn2d, ll_dyn3d, ll_orlanski
       REAL(wp), POINTER, DIMENSION(:,:) :: pua2d, pva2d     ! after barotropic velocities
-
-      IF( nn_timing == 1 ) CALL timing_start('bdy_dyn')
-
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('bdy_dyn')
+      !
       ll_dyn2d = .true.
       ll_dyn3d = .true.
-
+      !
       IF( PRESENT(dyn3d_only) ) THEN
-         IF( dyn3d_only ) ll_dyn2d = .false.
+         IF( dyn3d_only )   ll_dyn2d = .false.
       ENDIF
-
+      !
       ll_orlanski = .false.
       DO ib_bdy = 1, nb_bdy
-         IF ( cn_dyn2d(ib_bdy) == 'orlanski' .or. cn_dyn2d(ib_bdy) == 'orlanski_npo' &
-     &   .or. cn_dyn3d(ib_bdy) == 'orlanski' .or. cn_dyn3d(ib_bdy) == 'orlanski_npo') ll_orlanski = .true.
-      ENDDO
+         IF ( cn_dyn2d(ib_bdy) == 'orlanski' .OR. cn_dyn2d(ib_bdy) == 'orlanski_npo' &
+     &   .OR. cn_dyn3d(ib_bdy) == 'orlanski' .OR. cn_dyn3d(ib_bdy) == 'orlanski_npo')   ll_orlanski = .true.
+      END DO
 
       !-------------------------------------------------------
@@ -79,5 +77,5 @@
       !-------------------------------------------------------
 
-      CALL wrk_alloc(jpi,jpj,pua2d,pva2d) 
+      CALL wrk_alloc( jpi,jpj,   pua2d, pva2d ) 
 
       !-------------------------------------------------------
@@ -85,29 +83,26 @@
       !-------------------------------------------------------
 
-      ! "After" velocities: 
+      !                          ! "After" velocities: 
+      pua2d(:,:) = 0._wp
+      pva2d(:,:) = 0._wp     
+      DO jk = 1, jpkm1
+         pua2d(:,:) = pua2d(:,:) + e3u_a(:,:,jk) * ua(:,:,jk) * umask(:,:,jk)
+         pva2d(:,:) = pva2d(:,:) + e3v_a(:,:,jk) * va(:,:,jk) * vmask(:,:,jk)
+      END DO
+      pua2d(:,:) = pua2d(:,:) * r1_hu_a(:,:)
+      pva2d(:,:) = pva2d(:,:) * r1_hv_a(:,:)
 
-      pua2d(:,:) = 0.e0
-      pva2d(:,:) = 0.e0      
-      DO jk = 1, jpkm1
-         pua2d(:,:) = pua2d(:,:) + fse3u_a(:,:,jk) * umask(:,:,jk) * ua(:,:,jk)
-         pva2d(:,:) = pva2d(:,:) + fse3v_a(:,:,jk) * vmask(:,:,jk) * va(:,:,jk)
+      DO jk = 1 , jpkm1
+         ua(:,:,jk) = ( ua(:,:,jk) - pua2d(:,:) ) * umask(:,:,jk)
+         va(:,:,jk) = ( va(:,:,jk) - pva2d(:,:) ) * vmask(:,:,jk)
       END DO
 
-      pua2d(:,:) = pua2d(:,:) * hur_a(:,:)
-      pva2d(:,:) = pva2d(:,:) * hvr_a(:,:)
 
-      DO jk = 1 , jpkm1
-         ua(:,:,jk) = (ua(:,:,jk) - pua2d(:,:)) * umask(:,:,jk)
-         va(:,:,jk) = (va(:,:,jk) - pva2d(:,:)) * vmask(:,:,jk)
-      END DO
-
-      ! "Before" velocities (required for Orlanski condition): 
-
-      IF ( ll_orlanski ) THEN          
+      IF( ll_orlanski ) THEN     ! "Before" velocities (Orlanski condition only) 
          DO jk = 1 , jpkm1
-            ub(:,:,jk) = (ub(:,:,jk) - ub_b(:,:)) * umask(:,:,jk)
-            vb(:,:,jk) = (vb(:,:,jk) - vb_b(:,:)) * vmask(:,:,jk)
+            ub(:,:,jk) = ( ub(:,:,jk) - ub_b(:,:) ) * umask(:,:,jk)
+            vb(:,:,jk) = ( vb(:,:,jk) - vb_b(:,:) ) * vmask(:,:,jk)
          END DO
-      END IF
+      ENDIF
 
       !-------------------------------------------------------
@@ -116,17 +111,17 @@
       !-------------------------------------------------------
 
-      IF( ll_dyn2d ) CALL bdy_dyn2d( kt, pua2d, pva2d, ub_b, vb_b, hur_a(:,:), hvr_a(:,:), ssha )
+      IF( ll_dyn2d )   CALL bdy_dyn2d( kt, pua2d, pva2d, ub_b, vb_b, r1_hu_a(:,:), r1_hv_a(:,:), ssha )
 
-      IF( ll_dyn3d ) CALL bdy_dyn3d( kt )
+      IF( ll_dyn3d )   CALL bdy_dyn3d( kt )
 
       !-------------------------------------------------------
       ! Recombine velocities
       !-------------------------------------------------------
-
+      !
       DO jk = 1 , jpkm1
          ua(:,:,jk) = ( ua(:,:,jk) + pua2d(:,:) ) * umask(:,:,jk)
          va(:,:,jk) = ( va(:,:,jk) + pva2d(:,:) ) * vmask(:,:,jk)
       END DO
-
+      !
       IF ( ll_orlanski ) THEN
          DO jk = 1 , jpkm1
@@ -135,9 +130,9 @@
          END DO
       END IF
-
-      CALL wrk_dealloc(jpi,jpj,pua2d,pva2d) 
-
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_dyn')
-
+      !
+      CALL wrk_dealloc( jpi,jpj,  pua2d, pva2d ) 
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_dyn')
+      !
    END SUBROUTINE bdy_dyn
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn3d.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn3d.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn3d.F90	(revision 6140)
@@ -29,6 +29,4 @@
    PUBLIC   bdy_dyn3d_dmp ! routine called by step
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -45,30 +43,24 @@
       !!
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) :: kt     ! Main time step counter
-      !!
-      INTEGER               :: ib_bdy ! loop index
-      !!
-
+      INTEGER, INTENT(in) ::   kt   ! Main time step counter
+      !
+      INTEGER ::   ib_bdy   ! loop index
+      !!----------------------------------------------------------------------
+      !
       DO ib_bdy=1, nb_bdy
-
+         !
          SELECT CASE( cn_dyn3d(ib_bdy) )
-         CASE('none')
-            CYCLE
-         CASE('frs')
-            CALL bdy_dyn3d_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
-         CASE('specified')
-            CALL bdy_dyn3d_spe( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
-         CASE('zero')
-            CALL bdy_dyn3d_zro( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
-         CASE('orlanski')
-            CALL bdy_dyn3d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, ll_npo=.false. )
-         CASE('orlanski_npo')
-            CALL bdy_dyn3d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, ll_npo=.true. )
-         CASE DEFAULT
-            CALL ctl_stop( 'bdy_dyn3d : unrecognised option for open boundaries for baroclinic velocities' )
+         CASE('none')        ;   CYCLE
+         CASE('frs' )        ;   CALL bdy_dyn3d_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
+         CASE('specified')   ;   CALL bdy_dyn3d_spe( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
+         CASE('zero')        ;   CALL bdy_dyn3d_zro( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
+         CASE('orlanski' )   ;   CALL bdy_dyn3d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, ll_npo=.false. )
+         CASE('orlanski_npo');   CALL bdy_dyn3d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, ll_npo=.true. )
+         CASE DEFAULT        ;   CALL ctl_stop( 'bdy_dyn3d : unrecognised option for open boundaries for baroclinic velocities' )
          END SELECT
-      ENDDO
-
+      END DO
+      !
    END SUBROUTINE bdy_dyn3d
+
 
    SUBROUTINE bdy_dyn3d_spe( idx, dta, kt , ib_bdy )
@@ -80,9 +72,9 @@
       !!
       !!----------------------------------------------------------------------
-      INTEGER                     ::   kt
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
-      INTEGER,         INTENT(in) ::   ib_bdy  ! BDY set index
-      !!
+      INTEGER        , INTENT(in) ::   kt      ! time step index
+      TYPE(OBC_INDEX), INTENT(in) ::   idx     ! OBC indices
+      TYPE(OBC_DATA) , INTENT(in) ::   dta     ! OBC external data
+      INTEGER        , INTENT(in) ::   ib_bdy  ! BDY set index
+      !
       INTEGER  ::   jb, jk         ! dummy loop indices
       INTEGER  ::   ii, ij, igrd   ! local integers
@@ -112,10 +104,11 @@
       CALL lbc_bdy_lnk( va, 'V', -1., ib_bdy )   
       !
-      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
-
+      IF( kt == nit000 )   CLOSE( unit = 102 )
+      !
       IF( nn_timing == 1 ) CALL timing_stop('bdy_dyn3d_spe')
-
+      !
    END SUBROUTINE bdy_dyn3d_spe
 
+
    SUBROUTINE bdy_dyn3d_zro( idx, dta, kt, ib_bdy )
       !!----------------------------------------------------------------------
@@ -125,11 +118,11 @@
       !!
       !!----------------------------------------------------------------------
-      INTEGER                     ::   kt
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
+      INTEGER        , INTENT(in) ::   kt      ! time step index
+      TYPE(OBC_INDEX), INTENT(in) ::   idx     ! OBC indices
+      TYPE(OBC_DATA) , INTENT(in) ::   dta     ! OBC external data
       INTEGER,         INTENT(in) ::   ib_bdy  ! BDY set index
-      !!
+      !
       INTEGER  ::   ib, ik         ! dummy loop indices
-      INTEGER  ::   ii, ij, igrd, zcoef   ! local integers
+      INTEGER  ::   ii, ij, igrd   ! local integers
       REAL(wp) ::   zwgt           ! boundary weight
       !!----------------------------------------------------------------------
@@ -157,9 +150,10 @@
       CALL lbc_bdy_lnk( ua, 'U', -1., ib_bdy )   ;   CALL lbc_bdy_lnk( va, 'V', -1.,ib_bdy )   ! Boundary points should be updated
       !
-      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
-
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_dyn3d_zro')
-
+      IF( kt == nit000 )   CLOSE( unit = 102 )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_dyn3d_zro')
+      !
    END SUBROUTINE bdy_dyn3d_zro
+
 
    SUBROUTINE bdy_dyn3d_frs( idx, dta, kt, ib_bdy )
@@ -174,9 +168,9 @@
       !!               topography. Tellus, 365-382.
       !!----------------------------------------------------------------------
-      INTEGER                     ::   kt
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
+      INTEGER        , INTENT(in) ::   kt      ! time step index
+      TYPE(OBC_INDEX), INTENT(in) ::   idx     ! OBC indices
+      TYPE(OBC_DATA) , INTENT(in) ::   dta     ! OBC external data
       INTEGER,         INTENT(in) ::   ib_bdy  ! BDY set index
-      !!
+      !
       INTEGER  ::   jb, jk         ! dummy loop indices
       INTEGER  ::   ii, ij, igrd   ! local integers
@@ -208,9 +202,10 @@
       CALL lbc_bdy_lnk( va, 'V', -1., ib_bdy )   
       !
-      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
-
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_dyn3d_frs')
-
+      IF( kt == nit000 )   CLOSE( unit = 102 )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_dyn3d_frs')
+      !
    END SUBROUTINE bdy_dyn3d_frs
+
 
    SUBROUTINE bdy_dyn3d_orlanski( idx, dta, ib_bdy, ll_npo )
@@ -259,16 +254,14 @@
       !!
       !!----------------------------------------------------------------------
-      INTEGER                     ::   kt
-      !!
+      INTEGER, INTENT(in) ::   kt   ! time step index
+      !
       INTEGER  ::   jb, jk         ! dummy loop indices
+      INTEGER  ::   ib_bdy         ! loop index
       INTEGER  ::   ii, ij, igrd   ! local integers
       REAL(wp) ::   zwgt           ! boundary weight
-      INTEGER  ::  ib_bdy          ! loop index
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 ) CALL timing_start('bdy_dyn3d_dmp')
-      !
-      !-------------------------------------------------------
-
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('bdy_dyn3d_dmp')
+      !
       DO ib_bdy=1, nb_bdy
          IF ( ln_dyn3d_dmp(ib_bdy) .and. cn_dyn3d(ib_bdy) /= 'none' ) THEN
@@ -295,10 +288,10 @@
             END DO
          ENDIF
-      ENDDO
+      END DO
       !
       CALL lbc_lnk( ua, 'U', -1. )   ;   CALL lbc_lnk( va, 'V', -1. )   ! Boundary points should be updated
       !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_dyn3d_dmp')
-
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_dyn3d_dmp')
+      !
    END SUBROUTINE bdy_dyn3d_dmp
 
@@ -311,9 +304,7 @@
       WRITE(*,*) 'bdy_dyn3d: You should not have seen this print! error?', kt
    END SUBROUTINE bdy_dyn3d
-
    SUBROUTINE bdy_dyn3d_dmp( kt )      ! Empty routine
       WRITE(*,*) 'bdy_dyn3d_dmp: You should not have seen this print! error?', kt
    END SUBROUTINE bdy_dyn3d_dmp
-
 #endif
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 6140)
@@ -12,6 +12,5 @@
    !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
    !!            3.4  !  2012     (J. Chanut) straight open boundary case update
-   !!            3.5  !  2012     (S. Mocavero, I. Epicoco) Updates for the 
-   !!                             optimization of BDY communications
+   !!            3.5  !  2012     (S. Mocavero, I. Epicoco) optimization of BDY communications
    !!----------------------------------------------------------------------
 #if defined key_bdy
@@ -19,17 +18,18 @@
    !!   'key_bdy'                     Unstructured Open Boundary Conditions
    !!----------------------------------------------------------------------
-   !!   bdy_init       : Initialization of unstructured open boundaries
+   !!   bdy_init      : Initialization of unstructured open boundaries
    !!----------------------------------------------------------------------
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain
-   USE bdy_oce         ! unstructured open boundary conditions
-   USE in_out_manager  ! I/O units
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp         ! for mpp_sum  
-   USE iom             ! I/O
-   USE sbctide, ONLY: lk_tide ! Tidal forcing or not
-   USE phycst, ONLY: rday
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain
+   USE bdy_oce        ! unstructured open boundary conditions
+   USE sbctide  , ONLY: lk_tide ! Tidal forcing or not
+   USE phycst   , ONLY: rday
+   !
+   USE in_out_manager ! I/O units
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp        ! for mpp_sum  
+   USE iom            ! I/O
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -38,15 +38,15 @@
    PUBLIC   bdy_init   ! routine called in nemo_init
 
-   INTEGER, PARAMETER          :: jp_nseg = 100
-   INTEGER, PARAMETER          :: nrimmax = 20 ! maximum rimwidth in structured
+   INTEGER, PARAMETER ::   jp_nseg = 100   ! 
+   INTEGER, PARAMETER ::   nrimmax =  20   ! maximum rimwidth in structured
                                                ! open boundary data files
    ! Straight open boundary segment parameters:
-   INTEGER  :: nbdysege, nbdysegw, nbdysegn, nbdysegs 
-   INTEGER, DIMENSION(jp_nseg) :: jpieob, jpjedt, jpjeft, npckge
-   INTEGER, DIMENSION(jp_nseg) :: jpiwob, jpjwdt, jpjwft, npckgw
-   INTEGER, DIMENSION(jp_nseg) :: jpjnob, jpindt, jpinft, npckgn
-   INTEGER, DIMENSION(jp_nseg) :: jpjsob, jpisdt, jpisft, npckgs
+   INTEGER  ::   nbdysege, nbdysegw, nbdysegn, nbdysegs 
+   INTEGER, DIMENSION(jp_nseg) ::   jpieob, jpjedt, jpjeft, npckge   !
+   INTEGER, DIMENSION(jp_nseg) ::   jpiwob, jpjwdt, jpjwft, npckgw   !
+   INTEGER, DIMENSION(jp_nseg) ::   jpjnob, jpindt, jpinft, npckgn   !
+   INTEGER, DIMENSION(jp_nseg) ::   jpjsob, jpisdt, jpisft, npckgs   !
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -66,9 +66,4 @@
       !! ** Input   :  bdy_init.nc, input file for unstructured open boundaries
       !!----------------------------------------------------------------------      
-      ! namelist variables
-      !-------------------
-      CHARACTER(LEN=80),DIMENSION(jpbgrd)  ::   clfile
-      CHARACTER(LEN=1)   ::   ctypebdy
-      INTEGER :: nbdyind, nbdybeg, nbdyend
 
       ! local variables
@@ -81,5 +76,5 @@
       INTEGER  ::   ib_bdy1, ib_bdy2, ib1, ib2             !   -       -
       INTEGER  ::   i_offset, j_offset                     !   -       -
-      INTEGER, POINTER  ::  nbi, nbj, nbr                  ! short cuts
+      INTEGER , POINTER  ::  nbi, nbj, nbr                 ! short cuts
       REAL(wp), POINTER  ::  flagu, flagv                  !    -   -
       REAL(wp), POINTER, DIMENSION(:,:)       ::   pmask    ! pointer to 2D mask fields
@@ -94,5 +89,8 @@
       INTEGER :: iw_b(4), ie_b(4), is_b(4), in_b(4)                ! Arrays for neighbours coordinates
       REAL(wp), POINTER, DIMENSION(:,:)       ::   zfmask  ! temporary fmask array excluding coastal boundary condition (shlat)
-
+      !!
+      CHARACTER(LEN=80),DIMENSION(jpbgrd)  ::   clfile     ! Namelist variables
+      CHARACTER(LEN=1)                     ::   ctypebdy   !     -        - 
+      INTEGER                              ::   nbdyind, nbdybeg, nbdyend
       !!
       NAMELIST/nambdy/ nb_bdy, ln_coords_file, cn_coords_file,                 &
@@ -103,32 +101,30 @@
          &             rn_ice_tem, rn_ice_sal, rn_ice_age,                 &
          &             ln_vol, nn_volctl, nn_rimwidth
-      !!
+         !
       NAMELIST/nambdy_index/ ctypebdy, nbdyind, nbdybeg, nbdyend
       INTEGER  ::   ios                 ! Local integer output status for namelist read
       !!----------------------------------------------------------------------
-
-      IF( nn_timing == 1 ) CALL timing_start('bdy_init')
-
+      !
+      IF( nn_timing == 1 )   CALL timing_start('bdy_init')
+      !
       IF(lwp) WRITE(numout,*)
       IF(lwp) WRITE(numout,*) 'bdy_init : initialization of open boundaries'
       IF(lwp) WRITE(numout,*) '~~~~~~~~'
       !
-
       IF( jperio /= 0 )   CALL ctl_stop( 'Cyclic or symmetric,',   &
          &                               ' and general open boundary condition are not compatible' )
 
-      cgrid= (/'t','u','v'/)
+      cgrid = (/'t','u','v'/)
       
       ! ------------------------
       ! Read namelist parameters
       ! ------------------------
-
       REWIND( numnam_ref )              ! Namelist nambdy in reference namelist :Unstructured open boundaries  
       READ  ( numnam_ref, nambdy, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy in reference namelist', lwp )
-
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy in reference namelist', lwp )
+      !
       REWIND( numnam_cfg )              ! Namelist nambdy in configuration namelist :Unstructured open boundaries
       READ  ( numnam_cfg, nambdy, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy in configuration namelist', lwp )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy in configuration namelist', lwp )
       IF(lwm) WRITE ( numond, nambdy )
 
@@ -137,10 +133,10 @@
       ! -----------------------------------------
       !                                   ! control prints
-      IF(lwp) WRITE(numout,*) '         nambdy'
-
-      IF( nb_bdy .eq. 0 ) THEN 
+      IF(lwp) WRITE(numout,*) '   nambdy'
+
+      IF( nb_bdy == 0 ) THEN 
         IF(lwp) WRITE(numout,*) 'nb_bdy = 0, NO OPEN BOUNDARIES APPLIED.'
       ELSE
-        IF(lwp) WRITE(numout,*) 'Number of open boundary sets : ',nb_bdy
+        IF(lwp) WRITE(numout,*) 'Number of open boundary sets : ', nb_bdy
       ENDIF
 
@@ -158,25 +154,25 @@
         IF(lwp) WRITE(numout,*) 'Boundary conditions for barotropic solution:  '
         SELECT CASE( cn_dyn2d(ib_bdy) )                  
-          CASE('none')         
+          CASE( 'none' )         
              IF(lwp) WRITE(numout,*) '      no open boundary condition'        
              dta_bdy(ib_bdy)%ll_ssh = .false.
              dta_bdy(ib_bdy)%ll_u2d = .false.
              dta_bdy(ib_bdy)%ll_v2d = .false.
-          CASE('frs')          
+          CASE( 'frs' )          
              IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
              dta_bdy(ib_bdy)%ll_ssh = .false.
              dta_bdy(ib_bdy)%ll_u2d = .true.
              dta_bdy(ib_bdy)%ll_v2d = .true.
-          CASE('flather')      
+          CASE( 'flather' )      
              IF(lwp) WRITE(numout,*) '      Flather radiation condition'
              dta_bdy(ib_bdy)%ll_ssh = .true.
              dta_bdy(ib_bdy)%ll_u2d = .true.
              dta_bdy(ib_bdy)%ll_v2d = .true.
-          CASE('orlanski')     
+          CASE( 'orlanski' )     
              IF(lwp) WRITE(numout,*) '      Orlanski (fully oblique) radiation condition with adaptive nudging'
              dta_bdy(ib_bdy)%ll_ssh = .false.
              dta_bdy(ib_bdy)%ll_u2d = .true.
              dta_bdy(ib_bdy)%ll_v2d = .true.
-          CASE('orlanski_npo') 
+          CASE( 'orlanski_npo' ) 
              IF(lwp) WRITE(numout,*) '      Orlanski (NPO) radiation condition with adaptive nudging'
              dta_bdy(ib_bdy)%ll_ssh = .false.
@@ -392,8 +388,4 @@
       REWIND( numnam_cfg )     
 
-      !!----------------------------------------------------------------------
-
-              
-               
       nblendta(:,:) = 0
       nbdysege = 0
@@ -492,10 +484,10 @@
                nblendta(igrd,ib_bdy) = MAXVAL(kdimsz)
                jpbdtau = MAX(jpbdtau, MAXVAL(kdimsz))
-            ENDDO
+            END DO
             CALL iom_close( inum )
-
+            !
          ENDIF 
-
-      ENDDO ! ib_bdy
+         !
+      END DO ! ib_bdy
 
       IF (nb_bdy>0) THEN
@@ -514,5 +506,5 @@
       ! Now look for crossings in user (namelist) defined open boundary segments:
       !--------------------------------------------------------------------------
-      IF ( icount>0 ) CALL bdy_ctl_seg
+      IF( icount>0 )   CALL bdy_ctl_seg
 
       ! Calculate global boundary index arrays or read in from file
@@ -520,7 +512,7 @@
       ! 1. Read global index arrays from boundary coordinates file.
       DO ib_bdy = 1, nb_bdy
-
+         !
          IF( ln_coords_file(ib_bdy) ) THEN
-
+            !
             CALL iom_open( cn_coords_file(ib_bdy), inum )
             DO igrd = 1, jpbgrd
@@ -537,5 +529,5 @@
                   nbrdta(ii,igrd,ib_bdy) = INT( dta_global(ii,1,1) )
                END DO
-
+               !
                ibr_max = MAXVAL( nbrdta(:,igrd,ib_bdy) )
                IF(lwp) WRITE(numout,*)
@@ -546,8 +538,8 @@
             END DO
             CALL iom_close( inum )
-
+            !
          ENDIF 
-
-      ENDDO      
+         !
+      END DO      
     
       ! 2. Now fill indices corresponding to straight open boundary arrays:
@@ -792,5 +784,5 @@
 
       ! Work out dimensions of boundary data on each neighbour process
-      IF(nbondi .eq. 0) THEN
+      IF(nbondi == 0) THEN
          iw_b(1) = jpizoom + nimppt(nowe+1)
          ie_b(1) = jpizoom + nimppt(nowe+1)+nlcit(nowe+1)-3
@@ -802,10 +794,10 @@
          is_b(2) = jpjzoom + njmppt(noea+1)
          in_b(2) = jpjzoom + njmppt(noea+1)+nlcjt(noea+1)-3
-      ELSEIF(nbondi .eq. 1) THEN
+      ELSEIF(nbondi == 1) THEN
          iw_b(1) = jpizoom + nimppt(nowe+1)
          ie_b(1) = jpizoom + nimppt(nowe+1)+nlcit(nowe+1)-3
          is_b(1) = jpjzoom + njmppt(nowe+1)
          in_b(1) = jpjzoom + njmppt(nowe+1)+nlcjt(nowe+1)-3
-      ELSEIF(nbondi .eq. -1) THEN
+      ELSEIF(nbondi == -1) THEN
          iw_b(2) = jpizoom + nimppt(noea+1)
          ie_b(2) = jpizoom + nimppt(noea+1)+nlcit(noea+1)-3
@@ -814,5 +806,5 @@
       ENDIF
 
-      IF(nbondj .eq. 0) THEN
+      IF(nbondj == 0) THEN
          iw_b(3) = jpizoom + nimppt(noso+1)
          ie_b(3) = jpizoom + nimppt(noso+1)+nlcit(noso+1)-3
@@ -824,10 +816,10 @@
          is_b(4) = jpjzoom + njmppt(nono+1)
          in_b(4) = jpjzoom + njmppt(nono+1)+nlcjt(nono+1)-3
-      ELSEIF(nbondj .eq. 1) THEN
+      ELSEIF(nbondj == 1) THEN
          iw_b(3) = jpizoom + nimppt(noso+1)
          ie_b(3) = jpizoom + nimppt(noso+1)+nlcit(noso+1)-3
          is_b(3) = jpjzoom + njmppt(noso+1)
          in_b(3) = jpjzoom + njmppt(noso+1)+nlcjt(noso+1)-3
-      ELSEIF(nbondj .eq. -1) THEN
+      ELSEIF(nbondj == -1) THEN
          iw_b(4) = jpizoom + nimppt(nono+1)
          ie_b(4) = jpizoom + nimppt(nono+1)+nlcit(nono+1)-3
@@ -867,25 +859,25 @@
          ! Allocate index arrays for this boundary set
          !--------------------------------------------
-         ilen1 = MAXVAL(idx_bdy(ib_bdy)%nblen(:))
-         ALLOCATE( idx_bdy(ib_bdy)%nbi(ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%nbj(ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%nbr(ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%nbd(ilen1,jpbgrd) )
+         ilen1 = MAXVAL( idx_bdy(ib_bdy)%nblen(:) )
+         ALLOCATE( idx_bdy(ib_bdy)%nbi   (ilen1,jpbgrd) )
+         ALLOCATE( idx_bdy(ib_bdy)%nbj   (ilen1,jpbgrd) )
+         ALLOCATE( idx_bdy(ib_bdy)%nbr   (ilen1,jpbgrd) )
+         ALLOCATE( idx_bdy(ib_bdy)%nbd   (ilen1,jpbgrd) )
          ALLOCATE( idx_bdy(ib_bdy)%nbdout(ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%nbmap(ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%nbw(ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%flagu(ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%flagv(ilen1,jpbgrd) )
+         ALLOCATE( idx_bdy(ib_bdy)%nbmap (ilen1,jpbgrd) )
+         ALLOCATE( idx_bdy(ib_bdy)%nbw   (ilen1,jpbgrd) )
+         ALLOCATE( idx_bdy(ib_bdy)%flagu (ilen1,jpbgrd) )
+         ALLOCATE( idx_bdy(ib_bdy)%flagv (ilen1,jpbgrd) )
 
          ! Dispatch mapping indices and discrete distances on each processor
          ! -----------------------------------------------------------------
 
-         com_east = 0
-         com_west = 0
+         com_east  = 0
+         com_west  = 0
          com_south = 0
          com_north = 0
 
-         com_east_b = 0
-         com_west_b = 0
+         com_east_b  = 0
+         com_west_b  = 0
          com_south_b = 0
          com_north_b = 0
@@ -912,12 +904,12 @@
                      ii = idx_bdy(ib_bdy)%nbi(icount,igrd)
                      ij = idx_bdy(ib_bdy)%nbj(icount,igrd)
-                     if((com_east .ne. 1) .and. (ii .eq. (nlci-1)) .and. (nbondi .le. 0)) then
+                     if((com_east .ne. 1) .and. (ii == (nlci-1)) .and. (nbondi .le. 0)) then
                         com_east = 1
-                     elseif((com_west .ne. 1) .and. (ii .eq. 2) .and. (nbondi .ge. 0) .and. (nbondi .ne. 2)) then
+                     elseif((com_west .ne. 1) .and. (ii == 2) .and. (nbondi .ge. 0) .and. (nbondi .ne. 2)) then
                         com_west = 1
                      endif 
-                     if((com_south .ne. 1) .and. (ij .eq. 2) .and. (nbondj .ge. 0) .and. (nbondj .ne. 2)) then
+                     if((com_south .ne. 1) .and. (ij == 2) .and. (nbondj .ge. 0) .and. (nbondj .ne. 2)) then
                         com_south = 1
-                     elseif((com_north .ne. 1) .and. (ij .eq. (nlcj-1)) .and. (nbondj .le. 0)) then
+                     elseif((com_north .ne. 1) .and. (ij == (nlcj-1)) .and. (nbondj .le. 0)) then
                         com_north = 1
                      endif 
@@ -926,14 +918,14 @@
                   ENDIF
                   ! check if point has to be received from a neighbour
-                  IF(nbondi .eq. 0) THEN
+                  IF(nbondi == 0) THEN
                      IF( nbidta(ib,igrd,ib_bdy) >= iw_b(1) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(1) .AND.   &
                        & nbjdta(ib,igrd,ib_bdy) >= is_b(1) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(1) .AND.   &
                        & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
                        ii = nbidta(ib,igrd,ib_bdy)- iw_b(1)+2
-                       if((com_west_b .ne. 1) .and. (ii .eq. (nlcit(nowe+1)-1))) then
+                       if((com_west_b .ne. 1) .and. (ii == (nlcit(nowe+1)-1))) then
                           ij = nbjdta(ib,igrd,ib_bdy) - is_b(1)+2
-                          if((ij .eq. 2) .and. (nbondj .eq. 0 .or. nbondj .eq. 1)) then
+                          if((ij == 2) .and. (nbondj == 0 .or. nbondj == 1)) then
                             com_south = 1
-                          elseif((ij .eq. nlcjt(nowe+1)-1) .and. (nbondj .eq. 0 .or. nbondj .eq. -1)) then
+                          elseif((ij == nlcjt(nowe+1)-1) .and. (nbondj == 0 .or. nbondj == -1)) then
                             com_north = 1
                           endif
@@ -945,9 +937,9 @@
                        & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
                        ii = nbidta(ib,igrd,ib_bdy)- iw_b(2)+2
-                       if((com_east_b .ne. 1) .and. (ii .eq. 2)) then
+                       if((com_east_b .ne. 1) .and. (ii == 2)) then
                           ij = nbjdta(ib,igrd,ib_bdy) - is_b(2)+2
-                          if((ij .eq. 2) .and. (nbondj .eq. 0 .or. nbondj .eq. 1)) then
+                          if((ij == 2) .and. (nbondj == 0 .or. nbondj == 1)) then
                             com_south = 1
-                          elseif((ij .eq. nlcjt(noea+1)-1) .and. (nbondj .eq. 0 .or. nbondj .eq. -1)) then
+                          elseif((ij == nlcjt(noea+1)-1) .and. (nbondj == 0 .or. nbondj == -1)) then
                             com_north = 1
                           endif
@@ -955,14 +947,14 @@
                        endif 
                      ENDIF
-                  ELSEIF(nbondi .eq. 1) THEN
+                  ELSEIF(nbondi == 1) THEN
                      IF( nbidta(ib,igrd,ib_bdy) >= iw_b(1) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(1) .AND.   &
                        & nbjdta(ib,igrd,ib_bdy) >= is_b(1) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(1) .AND.   &
                        & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
                        ii = nbidta(ib,igrd,ib_bdy)- iw_b(1)+2
-                       if((com_west_b .ne. 1) .and. (ii .eq. (nlcit(nowe+1)-1))) then
+                       if((com_west_b .ne. 1) .and. (ii == (nlcit(nowe+1)-1))) then
                           ij = nbjdta(ib,igrd,ib_bdy) - is_b(1)+2
-                          if((ij .eq. 2) .and. (nbondj .eq. 0 .or. nbondj .eq. 1)) then
+                          if((ij == 2) .and. (nbondj == 0 .or. nbondj == 1)) then
                             com_south = 1
-                          elseif((ij .eq. nlcjt(nowe+1)-1) .and. (nbondj .eq. 0 .or. nbondj .eq. -1)) then
+                          elseif((ij == nlcjt(nowe+1)-1) .and. (nbondj == 0 .or. nbondj == -1)) then
                             com_north = 1
                           endif
@@ -970,14 +962,14 @@
                        endif 
                      ENDIF
-                  ELSEIF(nbondi .eq. -1) THEN
+                  ELSEIF(nbondi == -1) THEN
                      IF( nbidta(ib,igrd,ib_bdy) >= iw_b(2) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(2) .AND.   &
                        & nbjdta(ib,igrd,ib_bdy) >= is_b(2) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(2) .AND.   &
                        & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
                        ii = nbidta(ib,igrd,ib_bdy)- iw_b(2)+2
-                       if((com_east_b .ne. 1) .and. (ii .eq. 2)) then
+                       if((com_east_b .ne. 1) .and. (ii == 2)) then
                           ij = nbjdta(ib,igrd,ib_bdy) - is_b(2)+2
-                          if((ij .eq. 2) .and. (nbondj .eq. 0 .or. nbondj .eq. 1)) then
+                          if((ij == 2) .and. (nbondj == 0 .or. nbondj == 1)) then
                             com_south = 1
-                          elseif((ij .eq. nlcjt(noea+1)-1) .and. (nbondj .eq. 0 .or. nbondj .eq. -1)) then
+                          elseif((ij == nlcjt(noea+1)-1) .and. (nbondj == 0 .or. nbondj == -1)) then
                             com_north = 1
                           endif
@@ -986,5 +978,5 @@
                      ENDIF
                   ENDIF
-                  IF(nbondj .eq. 0) THEN
+                  IF(nbondj == 0) THEN
                      IF(com_north_b .ne. 1 .AND. (nbidta(ib,igrd,ib_bdy) == iw_b(4)-1  &
                        & .OR. nbidta(ib,igrd,ib_bdy) == ie_b(4)+1) .AND. &
@@ -1001,5 +993,5 @@
                        & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
                        ij = nbjdta(ib,igrd,ib_bdy)- is_b(3)+2
-                       if((com_south_b .ne. 1) .and. (ij .eq. (nlcjt(noso+1)-1))) then
+                       if((com_south_b .ne. 1) .and. (ij == (nlcjt(noso+1)-1))) then
                           com_south_b = 1
                        endif 
@@ -1009,9 +1001,9 @@
                        & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
                        ij = nbjdta(ib,igrd,ib_bdy)- is_b(4)+2
-                       if((com_north_b .ne. 1) .and. (ij .eq. 2)) then
+                       if((com_north_b .ne. 1) .and. (ij == 2)) then
                           com_north_b = 1
                        endif 
                      ENDIF
-                  ELSEIF(nbondj .eq. 1) THEN
+                  ELSEIF(nbondj == 1) THEN
                      IF( com_south_b .ne. 1 .AND. (nbidta(ib,igrd,ib_bdy) == iw_b(3)-1 .OR. &
                        & nbidta(ib,igrd,ib_bdy) == ie_b(3)+1) .AND. &
@@ -1023,9 +1015,9 @@
                        & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
                        ij = nbjdta(ib,igrd,ib_bdy)- is_b(3)+2
-                       if((com_south_b .ne. 1) .and. (ij .eq. (nlcjt(noso+1)-1))) then
+                       if((com_south_b .ne. 1) .and. (ij == (nlcjt(noso+1)-1))) then
                           com_south_b = 1
                        endif 
                      ENDIF
-                  ELSEIF(nbondj .eq. -1) THEN
+                  ELSEIF(nbondj == -1) THEN
                      IF(com_north_b .ne. 1 .AND. (nbidta(ib,igrd,ib_bdy) == iw_b(4)-1  &
                        & .OR. nbidta(ib,igrd,ib_bdy) == ie_b(4)+1) .AND. &
@@ -1037,5 +1029,5 @@
                        & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
                        ij = nbjdta(ib,igrd,ib_bdy)- is_b(4)+2
-                       if((com_north_b .ne. 1) .and. (ij .eq. 2)) then
+                       if((com_north_b .ne. 1) .and. (ij == 2)) then
                           com_north_b = 1
                        endif 
@@ -1046,38 +1038,22 @@
          ENDDO 
 
-         ! definition of the i- and j- direction local boundaries arrays
-         ! used for sending the boudaries
-         IF((com_east .eq. 1) .and. (com_west .eq. 1)) THEN
-            nbondi_bdy(ib_bdy) = 0
-         ELSEIF ((com_east .eq. 1) .and. (com_west .eq. 0)) THEN
-            nbondi_bdy(ib_bdy) = -1
-         ELSEIF ((com_east .eq. 0) .and. (com_west .eq. 1)) THEN
-            nbondi_bdy(ib_bdy) = 1
+         ! definition of the i- and j- direction local boundaries arrays used for sending the boundaries
+         IF(     (com_east  == 1) .and. (com_west  == 1) ) THEN   ;   nbondi_bdy(ib_bdy) =  0
+         ELSEIF( (com_east  == 1) .and. (com_west  == 0) ) THEN   ;   nbondi_bdy(ib_bdy) = -1
+         ELSEIF( (com_east  == 0) .and. (com_west  == 1) ) THEN   ;   nbondi_bdy(ib_bdy) =  1
          ENDIF
-
-         IF((com_north .eq. 1) .and. (com_south .eq. 1)) THEN
-            nbondj_bdy(ib_bdy) = 0
-         ELSEIF ((com_north .eq. 1) .and. (com_south .eq. 0)) THEN
-            nbondj_bdy(ib_bdy) = -1
-         ELSEIF ((com_north .eq. 0) .and. (com_south .eq. 1)) THEN
-            nbondj_bdy(ib_bdy) = 1
+         IF(     (com_north == 1) .and. (com_south == 1) ) THEN   ;   nbondj_bdy(ib_bdy) =  0
+         ELSEIF( (com_north == 1) .and. (com_south == 0) ) THEN   ;   nbondj_bdy(ib_bdy) = -1
+         ELSEIF( (com_north == 0) .and. (com_south == 1) ) THEN   ;   nbondj_bdy(ib_bdy) =  1
          ENDIF
 
-         ! definition of the i- and j- direction local boundaries arrays
-         ! used for receiving the boudaries
-         IF((com_east_b .eq. 1) .and. (com_west_b .eq. 1)) THEN
-            nbondi_bdy_b(ib_bdy) = 0
-         ELSEIF ((com_east_b .eq. 1) .and. (com_west_b .eq. 0)) THEN
-            nbondi_bdy_b(ib_bdy) = -1
-         ELSEIF ((com_east_b .eq. 0) .and. (com_west_b .eq. 1)) THEN
-            nbondi_bdy_b(ib_bdy) = 1
+         ! definition of the i- and j- direction local boundaries arrays used for receiving the boundaries
+         IF(     (com_east_b  == 1) .and. (com_west_b  == 1) ) THEN   ;   nbondi_bdy_b(ib_bdy) =  0
+         ELSEIF( (com_east_b  == 1) .and. (com_west_b  == 0) ) THEN   ;   nbondi_bdy_b(ib_bdy) = -1
+         ELSEIF( (com_east_b  == 0) .and. (com_west_b  == 1) ) THEN   ;   nbondi_bdy_b(ib_bdy) =  1
          ENDIF
-
-         IF((com_north_b .eq. 1) .and. (com_south_b .eq. 1)) THEN
-            nbondj_bdy_b(ib_bdy) = 0
-         ELSEIF ((com_north_b .eq. 1) .and. (com_south_b .eq. 0)) THEN
-            nbondj_bdy_b(ib_bdy) = -1
-         ELSEIF ((com_north_b .eq. 0) .and. (com_south_b .eq. 1)) THEN
-            nbondj_bdy_b(ib_bdy) = 1
+         IF(     (com_north_b == 1) .and. (com_south_b == 1) ) THEN   ;   nbondj_bdy_b(ib_bdy) =  0
+         ELSEIF( (com_north_b == 1) .and. (com_south_b == 0) ) THEN   ;   nbondj_bdy_b(ib_bdy) = -1
+         ELSEIF( (com_north_b == 0) .and. (com_south_b == 1) ) THEN   ;   nbondj_bdy_b(ib_bdy) =  1
          ENDIF
 
@@ -1087,7 +1063,7 @@
             DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
                nbr => idx_bdy(ib_bdy)%nbr(ib,igrd)
-               idx_bdy(ib_bdy)%nbw(ib,igrd) = 1.- TANH( FLOAT( nbr - 1 ) *0.5 )      ! tanh formulation
-!               idx_bdy(ib_bdy)%nbw(ib,igrd) = (FLOAT(nn_rimwidth(ib_bdy)+1-nbr)/FLOAT(nn_rimwidth(ib_bdy)))**2.  ! quadratic
-!               idx_bdy(ib_bdy)%nbw(ib,igrd) =  FLOAT(nn_rimwidth(ib_bdy)+1-nbr)/FLOAT(nn_rimwidth(ib_bdy))       ! linear
+               idx_bdy(ib_bdy)%nbw(ib,igrd) = 1.- TANH( REAL( nbr - 1 ) *0.5 )      ! tanh formulation
+!               idx_bdy(ib_bdy)%nbw(ib,igrd) = (REAL(nn_rimwidth(ib_bdy)+1-nbr)/REAL(nn_rimwidth(ib_bdy)))**2.  ! quadratic
+!               idx_bdy(ib_bdy)%nbw(ib,igrd) =  REAL(nn_rimwidth(ib_bdy)+1-nbr)/REAL(nn_rimwidth(ib_bdy))       ! linear
             END DO
          END DO 
@@ -1099,7 +1075,7 @@
                nbr => idx_bdy(ib_bdy)%nbr(ib,igrd)
                idx_bdy(ib_bdy)%nbd(ib,igrd) = 1. / ( rn_time_dmp(ib_bdy) * rday ) & 
-               & *(FLOAT(nn_rimwidth(ib_bdy)+1-nbr)/FLOAT(nn_rimwidth(ib_bdy)))**2.   ! quadratic
+               & *(REAL(nn_rimwidth(ib_bdy)+1-nbr)/REAL(nn_rimwidth(ib_bdy)))**2.   ! quadratic
                idx_bdy(ib_bdy)%nbdout(ib,igrd) = 1. / ( rn_time_dmp_out(ib_bdy) * rday ) & 
-               & *(FLOAT(nn_rimwidth(ib_bdy)+1-nbr)/FLOAT(nn_rimwidth(ib_bdy)))**2.   ! quadratic
+               & *(REAL(nn_rimwidth(ib_bdy)+1-nbr)/REAL(nn_rimwidth(ib_bdy)))**2.   ! quadratic
             END DO
          END DO 
@@ -1122,10 +1098,10 @@
 
          ! Derive mask on U and V grid from mask on T grid
-         bdyumask(:,:) = 0.e0
-         bdyvmask(:,:) = 0.e0
+         bdyumask(:,:) = 0._wp
+         bdyvmask(:,:) = 0._wp
          DO ij=1, jpjm1
             DO ii=1, jpim1
-               bdyumask(ii,ij)=bdytmask(ii,ij)*bdytmask(ii+1, ij )
-               bdyvmask(ii,ij)=bdytmask(ii,ij)*bdytmask(ii  ,ij+1)  
+               bdyumask(ii,ij) = bdytmask(ii,ij) * bdytmask(ii+1, ij )
+               bdyvmask(ii,ij) = bdytmask(ii,ij) * bdytmask(ii  ,ij+1)  
             END DO
          END DO
@@ -1143,7 +1119,4 @@
                END DO      
             END DO
-         END DO
-
-         DO ik = 1, jpkm1
             DO ij = 2, jpjm1
                DO ii = 2, jpim1
@@ -1153,19 +1126,17 @@
             END DO
          END DO
-
          tmask_i (:,:) = ssmask(:,:) * tmask_i(:,:)
-
+         !
       ENDIF ! ln_mask_file=.TRUE.
       
       bdytmask(:,:) = ssmask(:,:)
-      IF( .not. ln_mask_file ) THEN
-         ! If .not. ln_mask_file then we need to derive mask on U and V grid 
-         ! from mask on T grid here.
-         bdyumask(:,:) = 0.e0
-         bdyvmask(:,:) = 0.e0
-         DO ij=1, jpjm1
-            DO ii=1, jpim1
-               bdyumask(ii,ij)=bdytmask(ii,ij)*bdytmask(ii+1, ij )
-               bdyvmask(ii,ij)=bdytmask(ii,ij)*bdytmask(ii  ,ij+1)  
+      IF( .NOT.ln_mask_file ) THEN
+         ! If .not. ln_mask_file then we need to derive mask on U and V grid from mask on T grid here.
+         bdyumask(:,:) = 0._wp
+         bdyvmask(:,:) = 0._wp
+         DO ij = 1, jpjm1
+            DO ii = 1, jpim1
+               bdyumask(ii,ij) = bdytmask(ii,ij) * bdytmask(ii+1, ij )
+               bdyvmask(ii,ij) = bdytmask(ii,ij) * bdytmask(ii  ,ij+1)  
             END DO
          END DO
@@ -1178,19 +1149,19 @@
       DO ib_bdy = 1, nb_bdy
         DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)      
-          bdytmask(idx_bdy(ib_bdy)%nbi(ib,igrd), idx_bdy(ib_bdy)%nbj(ib,igrd)) = 0.e0
-        ENDDO
-      ENDDO
+          bdytmask(idx_bdy(ib_bdy)%nbi(ib,igrd), idx_bdy(ib_bdy)%nbj(ib,igrd)) = 0._wp
+        END DO
+      END DO
       !
       igrd = 2
       DO ib_bdy = 1, nb_bdy
         DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
-          bdyumask(idx_bdy(ib_bdy)%nbi(ib,igrd), idx_bdy(ib_bdy)%nbj(ib,igrd)) = 0.e0
-        ENDDO
-      ENDDO
+          bdyumask(idx_bdy(ib_bdy)%nbi(ib,igrd), idx_bdy(ib_bdy)%nbj(ib,igrd)) = 0._wp
+        END DO
+      END DO
       !
       igrd = 3
       DO ib_bdy = 1, nb_bdy
         DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
-          bdyvmask(idx_bdy(ib_bdy)%nbi(ib,igrd), idx_bdy(ib_bdy)%nbj(ib,igrd)) = 0.e0
+          bdyvmask(idx_bdy(ib_bdy)%nbi(ib,igrd), idx_bdy(ib_bdy)%nbj(ib,igrd)) = 0._wp
         ENDDO
       ENDDO
@@ -1198,5 +1169,5 @@
       ! For the flagu/flagv calculation below we require a version of fmask without
       ! the land boundary condition (shlat) included:
-      CALL wrk_alloc(jpi,jpj,zfmask) 
+      CALL wrk_alloc(jpi,jpj,  zfmask ) 
       DO ij = 2, jpjm1
          DO ii = 2, jpim1
@@ -1213,6 +1184,6 @@
       DO ib_bdy = 1, nb_bdy       ! Indices and directions of rim velocity components
 
-         idx_bdy(ib_bdy)%flagu(:,:) = 0.e0
-         idx_bdy(ib_bdy)%flagv(:,:) = 0.e0
+         idx_bdy(ib_bdy)%flagu(:,:) = 0._wp
+         idx_bdy(ib_bdy)%flagv(:,:) = 0._wp
          icount = 0 
 
@@ -1224,13 +1195,7 @@
          DO igrd = 1,jpbgrd 
             SELECT CASE( igrd )
-               CASE( 1 )
-                  pmask => umask(:,:,1)
-                  i_offset = 0
-               CASE( 2 ) 
-                  pmask => bdytmask
-                  i_offset = 1
-               CASE( 3 ) 
-                  pmask => zfmask(:,:)
-                  i_offset = 0
+               CASE( 1 )   ;   pmask => umask   (:,:,1)   ;   i_offset = 0
+               CASE( 2 )   ;   pmask => bdytmask(:,:)     ;   i_offset = 1
+               CASE( 3 )   ;   pmask => zfmask  (:,:)     ;   i_offset = 0
             END SELECT 
             icount = 0
@@ -1263,15 +1228,9 @@
          ! flagv =  1 : v is normal to the boundary and is direction is inward
 
-         DO igrd = 1,jpbgrd 
+         DO igrd = 1, jpbgrd 
             SELECT CASE( igrd )
-               CASE( 1 )
-                  pmask => vmask(:,:,1)
-                  j_offset = 0
-               CASE( 2 )
-                  pmask => zfmask(:,:)
-                  j_offset = 0
-               CASE( 3 )
-                  pmask => bdytmask
-                  j_offset = 1
+               CASE( 1 )   ;   pmask => vmask (:,:,1)   ;   j_offset = 0
+               CASE( 2 )   ;   pmask => zfmask(:,:)     ;   j_offset = 0
+               CASE( 3 )   ;   pmask => bdytmask        ;   j_offset = 1
             END SELECT 
             icount = 0
@@ -1279,6 +1238,6 @@
                nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
                nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
-               znfl = pmask(nbi,nbj+j_offset-1  )
-               zsfl = pmask(nbi,nbj+j_offset)
+               znfl = pmask(nbi,nbj+j_offset-1)
+               zsfl = pmask(nbi,nbj+j_offset  )
                ! This error check only works if you are using the bdyXmask arrays
                IF( j_offset == 1 .and. znfl + zsfl == 2 ) THEN
@@ -1298,11 +1257,11 @@
             ENDIF 
          END DO
-
+         !
       END DO
 
       ! Compute total lateral surface for volume correction:
       ! ----------------------------------------------------
-      ! JC: this must be done at each time step with key_vvl
-      bdysurftot = 0.e0 
+      ! JC: this must be done at each time step with non-linear free surface
+      bdysurftot = 0._wp 
       IF( ln_vol ) THEN  
          igrd = 2      ! Lateral surface at U-points
@@ -1312,10 +1271,10 @@
                nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
                flagu => idx_bdy(ib_bdy)%flagu(ib,igrd)
-               bdysurftot = bdysurftot + hu     (nbi  , nbj)                           &
+               bdysurftot = bdysurftot + hu_n   (nbi  , nbj)                           &
                   &                    * e2u    (nbi  , nbj) * ABS( flagu ) &
                   &                    * tmask_i(nbi  , nbj)                           &
                   &                    * tmask_i(nbi+1, nbj)                   
-            ENDDO
-         ENDDO
+            END DO
+         END DO
 
          igrd=3 ! Add lateral surface at V-points
@@ -1325,10 +1284,10 @@
                nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
                flagv => idx_bdy(ib_bdy)%flagv(ib,igrd)
-               bdysurftot = bdysurftot + hv     (nbi, nbj  )                           &
+               bdysurftot = bdysurftot + hv_n   (nbi, nbj  )                           &
                   &                    * e1v    (nbi, nbj  ) * ABS( flagv ) &
                   &                    * tmask_i(nbi, nbj  )                           &
                   &                    * tmask_i(nbi, nbj+1)
-            ENDDO
-         ENDDO
+            END DO
+         END DO
          !
          IF( lk_mpp )   CALL mpp_sum( bdysurftot )      ! sum over the global domain
@@ -1337,13 +1296,12 @@
       ! Tidy up
       !--------
-      IF (nb_bdy>0) THEN
-         DEALLOCATE(nbidta, nbjdta, nbrdta)
-      ENDIF
-
-      CALL wrk_dealloc(jpi,jpj,zfmask) 
-
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_init')
-
+      IF( nb_bdy>0 )   DEALLOCATE( nbidta, nbjdta, nbrdta )
+      !
+      CALL wrk_dealloc(jpi,jpj,   zfmask ) 
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_init')
+      !
    END SUBROUTINE bdy_init
+
 
    SUBROUTINE bdy_ctl_seg
@@ -1736,15 +1694,15 @@
       itest = 0
 
-      IF (cn_dyn2d(ib1)/=cn_dyn2d(ib2)) itest = itest + 1
-      IF (cn_dyn3d(ib1)/=cn_dyn3d(ib2)) itest = itest + 1
-      IF (cn_tra(ib1)/=cn_tra(ib2)) itest = itest + 1
-      !
-      IF (nn_dyn2d_dta(ib1)/=nn_dyn2d_dta(ib2)) itest = itest + 1
-      IF (nn_dyn3d_dta(ib1)/=nn_dyn3d_dta(ib2)) itest = itest + 1
-      IF (nn_tra_dta(ib1)/=nn_tra_dta(ib2)) itest = itest + 1
-      !
-      IF (nn_rimwidth(ib1)/=nn_rimwidth(ib2)) itest = itest + 1   
-      !
-      IF ( itest>0 ) THEN
+      IF( cn_dyn2d(ib1) /= cn_dyn2d(ib2) )   itest = itest + 1
+      IF( cn_dyn3d(ib1) /= cn_dyn3d(ib2) )   itest = itest + 1
+      IF( cn_tra  (ib1) /= cn_tra  (ib2) )   itest = itest + 1
+      !
+      IF( nn_dyn2d_dta(ib1) /= nn_dyn2d_dta(ib2) )   itest = itest + 1
+      IF( nn_dyn3d_dta(ib1) /= nn_dyn3d_dta(ib2) )   itest = itest + 1
+      IF( nn_tra_dta  (ib1) /= nn_tra_dta  (ib2) )   itest = itest + 1
+      !
+      IF( nn_rimwidth(ib1) /= nn_rimwidth(ib2) )   itest = itest + 1   
+      !
+      IF( itest>0 ) THEN
          IF(lwp) WRITE(numout,*) ' E R R O R : Segments ', ib1, 'and ', ib2
          IF(lwp) WRITE(numout,*) ' ==========  have different open bdy schemes'                                                  
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdylib.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdylib.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdylib.F90	(revision 6140)
@@ -4,5 +4,5 @@
    !! Unstructured Open Boundary Cond. :  Library module of generic boundary algorithms.
    !!======================================================================
-   !! History :  3.6  !  2013     (D. Storkey) new module
+   !! History :  3.6  !  2013     (D. Storkey) original code
    !!----------------------------------------------------------------------
 #if defined key_bdy 
@@ -13,11 +13,12 @@
    !!   bdy_orlanski_3d
    !!----------------------------------------------------------------------
-   USE timing          ! Timing
-   USE oce             ! ocean dynamics and tracers 
-   USE dom_oce         ! ocean space and time domain
-   USE bdy_oce         ! ocean open boundary conditions
-   USE phycst          ! physical constants
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE in_out_manager  !
+   USE oce            ! ocean dynamics and tracers 
+   USE dom_oce        ! ocean space and time domain
+   USE bdy_oce        ! ocean open boundary conditions
+   USE phycst         ! physical constants
+   !
+   USE in_out_manager !
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -45,11 +46,11 @@
       !! References:  Marchesiello, McWilliams and Shchepetkin, Ocean Modelling vol. 3 (2001)    
       !!----------------------------------------------------------------------
-      TYPE(OBC_INDEX),            INTENT(in)     ::   idx      ! BDY indices
-      INTEGER,                    INTENT(in)     ::   igrd     ! grid index
-      REAL(wp), DIMENSION(:,:),   INTENT(in)     ::   phib     ! model before 2D field
-      REAL(wp), DIMENSION(:,:),   INTENT(inout)  ::   phia     ! model after 2D field (to be updated)
-      REAL(wp), DIMENSION(:),     INTENT(in)     ::   phi_ext  ! external forcing data
-      LOGICAL,                    INTENT(in)     ::   ll_npo   ! switch for NPO version
-
+      TYPE(OBC_INDEX),          INTENT(in   ) ::   idx      ! BDY indices
+      INTEGER ,                 INTENT(in   ) ::   igrd     ! grid index
+      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   phib     ! model before 2D field
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   phia     ! model after 2D field (to be updated)
+      REAL(wp), DIMENSION(:)  , INTENT(in   ) ::   phi_ext  ! external forcing data
+      LOGICAL ,                 INTENT(in   ) ::   ll_npo   ! switch for NPO version
+      !
       INTEGER  ::   jb                                     ! dummy loop indices
       INTEGER  ::   ii, ij, iibm1, iibm2, ijbm1, ijbm2     ! 2D addresses
@@ -70,7 +71,7 @@
       REAL(wp), POINTER, DIMENSION(:,:)          :: pe_ydif    ! scale factors for y-derivatives
       !!----------------------------------------------------------------------
-
-      IF( nn_timing == 1 ) CALL timing_start('bdy_orlanski_2d')
-
+      !
+      IF( nn_timing == 1 )   CALL timing_start('bdy_orlanski_2d')
+      !
       ! ----------------------------------!
       ! Orlanski boundary conditions     :!
@@ -79,25 +80,25 @@
       SELECT CASE(igrd)
          CASE(1)
-            pmask => tmask(:,:,1)
+            pmask      => tmask(:,:,1)
             pmask_xdif => umask(:,:,1)
             pmask_ydif => vmask(:,:,1)
-            pe_xdif => e1u(:,:)
-            pe_ydif => e2v(:,:)
+            pe_xdif    => e1u(:,:)
+            pe_ydif    => e2v(:,:)
             ii_offset = 0
             ij_offset = 0
          CASE(2)
-            pmask => umask(:,:,1)
+            pmask      => umask(:,:,1)
             pmask_xdif => tmask(:,:,1)
             pmask_ydif => fmask(:,:,1)
-            pe_xdif => e1t(:,:)
-            pe_ydif => e2f(:,:)
+            pe_xdif    => e1t(:,:)
+            pe_ydif    => e2f(:,:)
             ii_offset = 1
             ij_offset = 0
          CASE(3)
-            pmask => vmask(:,:,1)
+            pmask      => vmask(:,:,1)
             pmask_xdif => fmask(:,:,1)
             pmask_ydif => tmask(:,:,1)
-            pe_xdif => e1f(:,:)
-            pe_ydif => e2t(:,:)
+            pe_xdif    => e1f(:,:)
+            pe_ydif    => e2t(:,:)
             ii_offset = 0
             ij_offset = 1
@@ -188,6 +189,6 @@
       END DO
       !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_orlanski_2d')
-
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_orlanski_2d')
+      !
    END SUBROUTINE bdy_orlanski_2d
 
@@ -204,11 +205,11 @@
       !! References:  Marchesiello, McWilliams and Shchepetkin, Ocean Modelling vol. 3 (2001)    
       !!----------------------------------------------------------------------
-      TYPE(OBC_INDEX),            INTENT(in)     ::   idx      ! BDY indices
-      INTEGER,                    INTENT(in)     ::   igrd     ! grid index
-      REAL(wp), DIMENSION(:,:,:), INTENT(in)     ::   phib     ! model before 3D field
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout)  ::   phia     ! model after 3D field (to be updated)
-      REAL(wp), DIMENSION(:,:),   INTENT(in)     ::   phi_ext  ! external forcing data
-      LOGICAL,                    INTENT(in)     ::   ll_npo   ! switch for NPO version
-
+      TYPE(OBC_INDEX),            INTENT(in   ) ::   idx      ! BDY indices
+      INTEGER ,                   INTENT(in   ) ::   igrd     ! grid index
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   phib     ! model before 3D field
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   phia     ! model after 3D field (to be updated)
+      REAL(wp), DIMENSION(:,:)  , INTENT(in   ) ::   phi_ext  ! external forcing data
+      LOGICAL ,                   INTENT(in   ) ::   ll_npo   ! switch for NPO version
+      !
       INTEGER  ::   jb, jk                                 ! dummy loop indices
       INTEGER  ::   ii, ij, iibm1, iibm2, ijbm1, ijbm2     ! 2D addresses
@@ -229,34 +230,34 @@
       REAL(wp), POINTER, DIMENSION(:,:)          :: pe_ydif    ! scale factors for y-derivatives
       !!----------------------------------------------------------------------
-
-      IF( nn_timing == 1 ) CALL timing_start('bdy_orlanski_3d')
-
+      !
+      IF( nn_timing == 1 )   CALL timing_start('bdy_orlanski_3d')
+      !
       ! ----------------------------------!
       ! Orlanski boundary conditions     :!
       ! ----------------------------------! 
-     
+      !
       SELECT CASE(igrd)
          CASE(1)
-            pmask => tmask(:,:,:)
+            pmask      => tmask(:,:,:)
             pmask_xdif => umask(:,:,:)
             pmask_ydif => vmask(:,:,:)
-            pe_xdif => e1u(:,:)
-            pe_ydif => e2v(:,:)
+            pe_xdif    => e1u(:,:)
+            pe_ydif    => e2v(:,:)
             ii_offset = 0
             ij_offset = 0
          CASE(2)
-            pmask => umask(:,:,:)
+            pmask      => umask(:,:,:)
             pmask_xdif => tmask(:,:,:)
             pmask_ydif => fmask(:,:,:)
-            pe_xdif => e1t(:,:)
-            pe_ydif => e2f(:,:)
+            pe_xdif    => e1t(:,:)
+            pe_ydif    => e2f(:,:)
             ii_offset = 1
             ij_offset = 0
          CASE(3)
-            pmask => vmask(:,:,:)
+            pmask      => vmask(:,:,:)
             pmask_xdif => fmask(:,:,:)
             pmask_ydif => tmask(:,:,:)
-            pe_xdif => e1f(:,:)
-            pe_ydif => e2t(:,:)
+            pe_xdif    => e1f(:,:)
+            pe_ydif    => e2t(:,:)
             ii_offset = 0
             ij_offset = 1
@@ -349,7 +350,7 @@
          !
       END DO
-
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_orlanski_3d')
-
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_orlanski_3d')
+      !
    END SUBROUTINE bdy_orlanski_3d
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 6140)
@@ -15,22 +15,21 @@
    !!   'key_bdy'     Open Boundary Condition
    !!----------------------------------------------------------------------
-   !!   PUBLIC
-   !!      bdytide_init     : read of namelist and initialisation of tidal harmonics data
-   !!      tide_update   : calculation of tidal forcing at each timestep
-   !!----------------------------------------------------------------------
-   USE timing          ! Timing
-   USE oce             ! ocean dynamics and tracers 
-   USE dom_oce         ! ocean space and time domain
-   USE iom
-   USE in_out_manager  ! I/O units
-   USE phycst          ! physical constants
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE bdy_par         ! Unstructured boundary parameters
-   USE bdy_oce         ! ocean open boundary conditions
-   USE daymod          ! calendar
-   USE wrk_nemo        ! Memory allocation
-   USE tideini
-!   USE tide_mod       ! Useless ??
-   USE fldread
+   !!   bdytide_init  : read of namelist and initialisation of tidal harmonics data
+   !!   tide_update   : calculation of tidal forcing at each timestep
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers 
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE bdy_par        ! Unstructured boundary parameters
+   USE bdy_oce        ! ocean open boundary conditions
+   USE tideini        ! 
+   USE daymod         ! calendar
+   !
+   USE in_out_manager ! I/O units
+   USE iom            ! xIO server
+   USE fldread        !
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE wrk_nemo       ! Memory allocation
+   USE timing         ! timing
 
    IMPLICIT NONE
@@ -42,10 +41,8 @@
 
    TYPE, PUBLIC ::   TIDES_DATA     !: Storage for external tidal harmonics data
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   ssh0       !: Tidal constituents : SSH0 (read in file)
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   u0         !: Tidal constituents : U0   (read in file)
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   v0         !: Tidal constituents : V0   (read in file)
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   ssh        !: Tidal constituents : SSH  (after nodal cor.)
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   u          !: Tidal constituents : U    (after nodal cor.)
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   v          !: Tidal constituents : V    (after nodal cor.)
+      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   ssh0     !: Tidal constituents : SSH0   (read in file)
+      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   u0, v0   !: Tidal constituents : U0, V0 (read in file)
+      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   ssh      !: Tidal constituents : SSH    (after nodal cor.)
+      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   u , v    !: Tidal constituents : U , V  (after nodal cor.)
    END TYPE TIDES_DATA
 
@@ -57,5 +54,5 @@
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
+   !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -91,7 +88,7 @@
       NAMELIST/nambdy_tide/filtide, ln_bdytide_2ddta, ln_bdytide_conj
       !!----------------------------------------------------------------------
-
-      IF( nn_timing == 1 ) CALL timing_start('bdytide_init')
-
+      !
+      IF( nn_timing == 1 )   CALL timing_start('bdytide_init')
+      !
       IF (nb_bdy>0) THEN
          IF(lwp) WRITE(numout,*)
@@ -263,5 +260,5 @@
             ENDIF ! ln_bdytide_2ddta=.true.
             !
-            IF ( ln_bdytide_conj ) THEN ! assume complex conjugate in data files
+            IF( ln_bdytide_conj ) THEN    ! assume complex conjugate in data files
                td%ssh0(:,:,2) = - td%ssh0(:,:,2)
                td%u0  (:,:,2) = - td%u0  (:,:,2)
@@ -274,17 +271,18 @@
             ALLOCATE( dta_bdy_s(ib_bdy)%u2d ( ilen0(2) ) )
             ALLOCATE( dta_bdy_s(ib_bdy)%v2d ( ilen0(3) ) )
-            dta_bdy_s(ib_bdy)%ssh(:) = 0.e0
-            dta_bdy_s(ib_bdy)%u2d(:) = 0.e0
-            dta_bdy_s(ib_bdy)%v2d(:) = 0.e0
+            dta_bdy_s(ib_bdy)%ssh(:) = 0._wp
+            dta_bdy_s(ib_bdy)%u2d(:) = 0._wp
+            dta_bdy_s(ib_bdy)%v2d(:) = 0._wp
             !
          ENDIF ! nn_dyn2d_dta(ib_bdy) .ge. 2
          !
       END DO ! loop on ib_bdy
-
-      IF( nn_timing == 1 ) CALL timing_stop('bdytide_init')
-
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('bdytide_init')
+      !
    END SUBROUTINE bdytide_init
 
-   SUBROUTINE bdytide_update ( kt, idx, dta, td, jit, time_offset )
+
+   SUBROUTINE bdytide_update( kt, idx, dta, td, jit, time_offset )
       !!----------------------------------------------------------------------
       !!                 ***  SUBROUTINE bdytide_update  ***
@@ -293,25 +291,25 @@
       !!                
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in )            ::   kt          ! Main timestep counter
-      TYPE(OBC_INDEX), INTENT( in )    ::   idx         ! OBC indices
-      TYPE(OBC_DATA),  INTENT(inout)   ::   dta         ! OBC external data
-      TYPE(TIDES_DATA),INTENT( inout ) ::   td          ! tidal harmonics data
-      INTEGER,INTENT(in),OPTIONAL      ::   jit         ! Barotropic timestep counter (for timesplitting option)
-      INTEGER,INTENT( in ), OPTIONAL   ::   time_offset ! time offset in units of timesteps. NB. if jit
-                                                        ! is present then units = subcycle timesteps.
-                                                        ! time_offset = 0  => get data at "now"    time level
-                                                        ! time_offset = -1 => get data at "before" time level
-                                                        ! time_offset = +1 => get data at "after"  time level
-                                                        ! etc.
-      !!
-      INTEGER, DIMENSION(3)            ::   ilen0       !: length of boundary data (from OBC arrays)
-      INTEGER                          :: itide, igrd, ib   ! dummy loop indices
-      INTEGER                          :: time_add          ! time offset in units of timesteps
-      REAL(wp)                         :: z_arg, z_sarg, zflag, zramp      
+      INTEGER          , INTENT(in   ) ::   kt          ! Main timestep counter
+      TYPE(OBC_INDEX)  , INTENT(in   ) ::   idx         ! OBC indices
+      TYPE(OBC_DATA)   , INTENT(inout) ::   dta         ! OBC external data
+      TYPE(TIDES_DATA) , INTENT(inout) ::   td          ! tidal harmonics data
+      INTEGER, OPTIONAL, INTENT(in   ) ::   jit         ! Barotropic timestep counter (for timesplitting option)
+      INTEGER, OPTIONAL, INTENT(in   ) ::   time_offset ! time offset in units of timesteps. NB. if jit
+      !                                                 ! is present then units = subcycle timesteps.
+      !                                                 ! time_offset = 0  => get data at "now"    time level
+      !                                                 ! time_offset = -1 => get data at "before" time level
+      !                                                 ! time_offset = +1 => get data at "after"  time level
+      !                                                 ! etc.
+      !
+      INTEGER  ::   itide, igrd, ib       ! dummy loop indices
+      INTEGER  ::   time_add              ! time offset in units of timesteps
+      INTEGER, DIMENSION(3) ::   ilen0    ! length of boundary data (from OBC arrays)
+      REAL(wp) ::   z_arg, z_sarg, zflag, zramp   ! local scalars    
       REAL(wp), DIMENSION(jpmax_harmo) :: z_sist, z_cost
       !!----------------------------------------------------------------------
-
-      IF( nn_timing == 1 ) CALL timing_start('bdytide_update')
-
+      !
+      IF( nn_timing == 1 )   CALL timing_start('bdytide_update')
+      !
       ilen0(1) =  SIZE(td%ssh(:,1,1))
       ilen0(2) =  SIZE(td%u(:,1,1))
@@ -323,7 +321,7 @@
       ENDIF
 
-      IF ( nsec_day == NINT(0.5_wp * rdttra(1)) .AND. zflag==1 ) THEN
+      IF ( (nsec_day == NINT(0.5_wp * rdt) .OR. kt==nit000) .AND. zflag==1 ) THEN
         !
-        kt_tide = kt
+        kt_tide = kt - (nsec_day - 0.5_wp * rdt)/rdt
         !
         IF(lwp) THEN
@@ -374,5 +372,5 @@
       END DO
       !
-      IF( nn_timing == 1 ) CALL timing_stop('bdytide_update')
+      IF( nn_timing == 1 )   CALL timing_stop('bdytide_update')
       !
    END SUBROUTINE bdytide_update
@@ -385,23 +383,23 @@
       !!                
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in )            ::   kt          ! Main timestep counter
-      INTEGER, INTENT( in ),OPTIONAL   ::   kit         ! Barotropic timestep counter (for timesplitting option)
-      INTEGER, INTENT( in ),OPTIONAL   ::   time_offset ! time offset in units of timesteps. NB. if kit
-                                                        ! is present then units = subcycle timesteps.
-                                                        ! time_offset = 0  => get data at "now"    time level
-                                                        ! time_offset = -1 => get data at "before" time level
-                                                        ! time_offset = +1 => get data at "after"  time level
-                                                        ! etc.
-      !!
-      LOGICAL  :: lk_first_btstp  ! =.TRUE. if time splitting and first barotropic step
-      INTEGER, DIMENSION(jpbgrd) :: ilen0 
-      INTEGER, DIMENSION(1:jpbgrd) :: nblen, nblenrim  ! short cuts
-      INTEGER  :: itide, ib_bdy, ib, igrd                     ! loop indices
-      INTEGER  :: time_add                                    ! time offset in units of timesteps
-      REAL(wp) :: z_arg, z_sarg, zramp, zoff, z_cost, z_sist      
-      !!----------------------------------------------------------------------
-
-      IF( nn_timing == 1 ) CALL timing_start('bdy_dta_tides')
-
+      INTEGER,           INTENT(in) ::   kt          ! Main timestep counter
+      INTEGER, OPTIONAL, INTENT(in) ::   kit         ! Barotropic timestep counter (for timesplitting option)
+      INTEGER, OPTIONAL, INTENT(in) ::   time_offset ! time offset in units of timesteps. NB. if kit
+      !                                              ! is present then units = subcycle timesteps.
+      !                                              ! time_offset = 0  => get data at "now"    time level
+      !                                              ! time_offset = -1 => get data at "before" time level
+      !                                              ! time_offset = +1 => get data at "after"  time level
+      !                                              ! etc.
+      !
+      LOGICAL  ::   lk_first_btstp            ! =.TRUE. if time splitting and first barotropic step
+      INTEGER  ::   itide, ib_bdy, ib, igrd   ! loop indices
+      INTEGER  ::   time_add                  ! time offset in units of timesteps
+      INTEGER, DIMENSION(jpbgrd)   ::   ilen0 
+      INTEGER, DIMENSION(1:jpbgrd) ::   nblen, nblenrim  ! short cuts
+      REAL(wp) ::   z_arg, z_sarg, zramp, zoff, z_cost, z_sist      
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('bdy_dta_tides')
+      !
       lk_first_btstp=.TRUE.
       IF ( PRESENT(kit).AND.( kit /= 1 ) ) THEN ; lk_first_btstp=.FALSE. ; ENDIF
@@ -438,7 +436,7 @@
             ! We refresh nodal factors every day below
             ! This should be done somewhere else
-            IF ( nsec_day == NINT(0.5_wp * rdttra(1)) .AND. lk_first_btstp ) THEN
-               !
-               kt_tide = kt               
+            IF ( ( nsec_day == NINT(0.5_wp * rdt) .OR. kt==nit000 ) .AND. lk_first_btstp ) THEN
+               !
+               kt_tide = kt - (nsec_day - 0.5_wp * rdt)/rdt
                !
                IF(lwp) THEN
@@ -502,22 +500,23 @@
    END SUBROUTINE bdy_dta_tides
 
+
    SUBROUTINE tide_init_elevation( idx, td )
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE tide_init_elevation  ***
       !!----------------------------------------------------------------------
-      TYPE(OBC_INDEX), INTENT( in )      ::   idx     ! OBC indices
-      TYPE(TIDES_DATA),INTENT( inout )   ::   td      ! tidal harmonics data
-      !! * Local declarations
-      INTEGER, DIMENSION(1)            ::   ilen0       !: length of boundary data (from OBC arrays)
+      TYPE(OBC_INDEX) , INTENT(in   ) ::   idx   ! OBC indices
+      TYPE(TIDES_DATA), INTENT(inout) ::   td    ! tidal harmonics data
+      !
+      INTEGER ::   itide, igrd, ib       ! dummy loop indices
+      INTEGER, DIMENSION(1) ::   ilen0   ! length of boundary data (from OBC arrays)
       REAL(wp),ALLOCATABLE, DIMENSION(:) ::   mod_tide, phi_tide
-      INTEGER                            ::   itide, igrd, ib      ! dummy loop indices
-
+      !!----------------------------------------------------------------------
+      !
       igrd=1   
                               ! SSH on tracer grid.
-   
       ilen0(1) =  SIZE(td%ssh0(:,1,1))
-
-      ALLOCATE(mod_tide(ilen0(igrd)),phi_tide(ilen0(igrd)))
-
+      !
+      ALLOCATE( mod_tide(ilen0(igrd)), phi_tide(ilen0(igrd)) )
+      !
       DO itide = 1, nb_harmo
          DO ib = 1, ilen0(igrd)
@@ -534,27 +533,29 @@
          ENDDO
       END DO
-
-      DEALLOCATE(mod_tide,phi_tide)
-
+      !
+      DEALLOCATE( mod_tide, phi_tide )
+      !
    END SUBROUTINE tide_init_elevation
 
+
    SUBROUTINE tide_init_velocities( idx, td )
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE tide_init_elevation  ***
       !!----------------------------------------------------------------------
-      TYPE(OBC_INDEX), INTENT( in )      ::   idx     ! OBC indices
-      TYPE(TIDES_DATA),INTENT( inout )      ::   td      ! tidal harmonics data
-      !! * Local declarations
-      INTEGER, DIMENSION(3)            ::   ilen0       !: length of boundary data (from OBC arrays)
+      TYPE(OBC_INDEX) , INTENT(in   ) ::   idx   ! OBC indices
+      TYPE(TIDES_DATA), INTENT(inout) ::   td    ! tidal harmonics data
+      !
+      INTEGER ::   itide, igrd, ib       ! dummy loop indices
+      INTEGER, DIMENSION(3) ::   ilen0   ! length of boundary data (from OBC arrays)
       REAL(wp),ALLOCATABLE, DIMENSION(:) ::   mod_tide, phi_tide
-      INTEGER                            ::   itide, igrd, ib      ! dummy loop indices
-
+      !!----------------------------------------------------------------------
+      !
       ilen0(2) =  SIZE(td%u0(:,1,1))
       ilen0(3) =  SIZE(td%v0(:,1,1))
-
+      !
       igrd=2                                 ! U grid.
-
-      ALLOCATE(mod_tide(ilen0(igrd)),phi_tide(ilen0(igrd)))
-
+      !
+      ALLOCATE( mod_tide(ilen0(igrd)) , phi_tide(ilen0(igrd)) )
+      !
       DO itide = 1, nb_harmo
          DO ib = 1, ilen0(igrd)
@@ -571,10 +572,10 @@
          ENDDO
       END DO
-
-      DEALLOCATE(mod_tide,phi_tide)
-
+      !
+      DEALLOCATE( mod_tide , phi_tide )
+      !
       igrd=3                                 ! V grid.
-
-      ALLOCATE(mod_tide(ilen0(igrd)),phi_tide(ilen0(igrd)))
+      !
+      ALLOCATE( mod_tide(ilen0(igrd)) , phi_tide(ilen0(igrd)) )
 
       DO itide = 1, nb_harmo
@@ -592,8 +593,9 @@
          ENDDO
       END DO
-
-      DEALLOCATE(mod_tide,phi_tide)
-
+      !
+      DEALLOCATE( mod_tide, phi_tide )
+      !
   END SUBROUTINE tide_init_velocities
+
 #else
    !!----------------------------------------------------------------------
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90	(revision 6140)
@@ -16,19 +16,19 @@
    !!   bdy_tra_frs        : Apply Flow Relaxation Scheme
    !!----------------------------------------------------------------------
-   USE timing          ! Timing
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables 
-   USE bdy_oce         ! ocean open boundary conditions
-   USE bdylib          ! for orlanski library routines
-   USE bdydta, ONLY:   bf
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE in_out_manager  ! I/O manager
-
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables 
+   USE bdy_oce        ! ocean open boundary conditions
+   USE bdylib         ! for orlanski library routines
+   USE bdydta   , ONLY:   bf   ! 
+   !
+   USE in_out_manager ! I/O manager
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE timing         ! Timing
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC bdy_tra      ! routine called in tranxt.F90 
-   PUBLIC bdy_tra_dmp  ! routine called in step.F90 
+   PUBLIC   bdy_tra      ! called in tranxt.F90 
+   PUBLIC   bdy_tra_dmp  ! called in step.F90 
 
    !!----------------------------------------------------------------------
@@ -46,36 +46,29 @@
       !!
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) :: kt     ! Main time step counter
-      !!
-      INTEGER               :: ib_bdy ! Loop index
+      INTEGER, INTENT(in) ::   kt   ! Main time step counter
+      !
+      INTEGER ::   ib_bdy   ! Loop index
+      !!----------------------------------------------------------------------
 
       DO ib_bdy=1, nb_bdy
-
+         !
          SELECT CASE( cn_tra(ib_bdy) )
-         CASE('none')
-            CYCLE
-         CASE('frs')
-            CALL bdy_tra_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
-         CASE('specified')
-            CALL bdy_tra_spe( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
-         CASE('neumann')
-            CALL bdy_tra_nmn( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
-         CASE('orlanski')
-            CALL bdy_tra_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ll_npo=.false. )
-         CASE('orlanski_npo')
-            CALL bdy_tra_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ll_npo=.true. )
-         CASE('runoff')
-            CALL bdy_tra_rnf( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
-         CASE DEFAULT
-            CALL ctl_stop( 'bdy_tra : unrecognised option for open boundaries for T and S' )
+         CASE('none'        )   ;   CYCLE
+         CASE('frs'         )   ;   CALL bdy_tra_frs     ( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
+         CASE('specified'   )   ;   CALL bdy_tra_spe     ( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
+         CASE('neumann'     )   ;   CALL bdy_tra_nmn     ( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
+         CASE('orlanski'    )   ;   CALL bdy_tra_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ll_npo=.false. )
+         CASE('orlanski_npo')   ;   CALL bdy_tra_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ll_npo=.true. )
+         CASE('runoff'      )   ;   CALL bdy_tra_rnf     ( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
+         CASE DEFAULT           ;   CALL ctl_stop( 'bdy_tra : unrecognised option for open boundaries for T and S' )
          END SELECT
          ! Boundary points should be updated
          CALL lbc_bdy_lnk( tsa(:,:,:,jp_tem), 'T', 1., ib_bdy )
          CALL lbc_bdy_lnk( tsa(:,:,:,jp_sal), 'T', 1., ib_bdy )
-      ENDDO
-      !
-
+      END DO
+      !
    END SUBROUTINE bdy_tra
 
+
    SUBROUTINE bdy_tra_frs( idx, dta, kt )
       !!----------------------------------------------------------------------
@@ -86,8 +79,8 @@
       !! Reference : Engedahl H., 1995, Tellus, 365-382.
       !!----------------------------------------------------------------------
-      INTEGER,         INTENT(in) ::   kt
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
-      !! 
+      INTEGER,         INTENT(in) ::   kt    !
+      TYPE(OBC_INDEX), INTENT(in) ::   idx   ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta   ! OBC external data
+      !
       REAL(wp) ::   zwgt           ! boundary weight
       INTEGER  ::   ib, ik, igrd   ! dummy loop indices
@@ -95,5 +88,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 ) CALL timing_start('bdy_tra_frs')
+      IF( nn_timing == 1 )   CALL timing_start('bdy_tra_frs')
       !
       igrd = 1                       ! Everything is at T-points here
@@ -108,10 +101,11 @@
       END DO 
       !
-      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_tra_frs')
+      IF( kt .eq. nit000 )   CLOSE( unit = 102 )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_tra_frs')
       !
    END SUBROUTINE bdy_tra_frs
-  
+
+
    SUBROUTINE bdy_tra_spe( idx, dta, kt )
       !!----------------------------------------------------------------------
@@ -121,8 +115,8 @@
       !! 
       !!----------------------------------------------------------------------
-      INTEGER,         INTENT(in) ::   kt
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
-      !! 
+      INTEGER,         INTENT(in) ::   kt    !
+      TYPE(OBC_INDEX), INTENT(in) ::   idx   ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta   ! OBC external data
+      !
       REAL(wp) ::   zwgt           ! boundary weight
       INTEGER  ::   ib, ik, igrd   ! dummy loop indices
@@ -142,10 +136,11 @@
       END DO
       !
-      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_tra_spe')
+      IF( kt == nit000 )   CLOSE( unit = 102 )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_tra_spe')
       !
    END SUBROUTINE bdy_tra_spe
 
+
    SUBROUTINE bdy_tra_nmn( idx, dta, kt )
       !!----------------------------------------------------------------------
@@ -155,8 +150,8 @@
       !! 
       !!----------------------------------------------------------------------
-      INTEGER,         INTENT(in) ::   kt
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
-      !! 
+      INTEGER,         INTENT(in) ::   kt    ! 
+      TYPE(OBC_INDEX), INTENT(in) ::   idx   ! OBC indices
+      TYPE(OBC_DATA) , INTENT(in) ::   dta   ! OBC external data
+      !
       REAL(wp) ::   zwgt           ! boundary weight
       INTEGER  ::   ib, ik, igrd   ! dummy loop indices
@@ -164,5 +159,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 ) CALL timing_start('bdy_tra_nmn')
+      IF( nn_timing == 1 )   CALL timing_start('bdy_tra_nmn')
       !
       igrd = 1                       ! Everything is at T-points here
@@ -196,7 +191,7 @@
       END DO
       !
-      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_tra_nmn')
+      IF( kt == nit000 )   CLOSE( unit = 102 )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_tra_nmn')
       !
    END SUBROUTINE bdy_tra_nmn
@@ -213,11 +208,11 @@
       !! References:  Marchesiello, McWilliams and Shchepetkin, Ocean Modelling vol. 3 (2001)    
       !!----------------------------------------------------------------------
-      TYPE(OBC_INDEX),              INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),               INTENT(in) ::   dta  ! OBC external data
-      LOGICAL,                      INTENT(in) ::   ll_npo  ! switch for NPO version
-
+      TYPE(OBC_INDEX), INTENT(in) ::   idx     ! OBC indices
+      TYPE(OBC_DATA) , INTENT(in) ::   dta     ! OBC external data
+      LOGICAL        , INTENT(in) ::   ll_npo  ! switch for NPO version
+      !
       INTEGER  ::   igrd                                    ! grid index
       !!----------------------------------------------------------------------
-
+      !
       IF( nn_timing == 1 ) CALL timing_start('bdy_tra_orlanski')
       !
@@ -230,7 +225,6 @@
       CALL bdy_orlanski_3d( idx, igrd, tsb(:,:,:,jp_sal), tsa(:,:,:,jp_sal), dta%sal, ll_npo )
       !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_tra_orlanski')
-      !
-
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_tra_orlanski')
+      !
    END SUBROUTINE bdy_tra_orlanski
 
@@ -245,8 +239,8 @@
       !! 
       !!----------------------------------------------------------------------
-      INTEGER,         INTENT(in) ::   kt
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
-      !! 
+      INTEGER        , INTENT(in) ::   kt    ! 
+      TYPE(OBC_INDEX), INTENT(in) ::   idx   ! OBC indices
+      TYPE(OBC_DATA) , INTENT(in) ::   dta   ! OBC external data
+      !
       REAL(wp) ::   zwgt           ! boundary weight
       INTEGER  ::   ib, ik, igrd   ! dummy loop indices
@@ -254,5 +248,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 ) CALL timing_start('bdy_tra_rnf')
+      IF( nn_timing == 1 )   CALL timing_start('bdy_tra_rnf')
       !
       igrd = 1                       ! Everything is at T-points here
@@ -268,10 +262,11 @@
       END DO
       !
-      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_tra_rnf')
+      IF( kt == nit000 )   CLOSE( unit = 102 )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_tra_rnf')
       !
    END SUBROUTINE bdy_tra_rnf
 
+
    SUBROUTINE bdy_tra_dmp( kt )
       !!----------------------------------------------------------------------
@@ -281,6 +276,6 @@
       !! 
       !!----------------------------------------------------------------------
-      INTEGER,         INTENT(in) ::   kt
-      !! 
+      INTEGER, INTENT(in) ::   kt   !
+      !
       REAL(wp) ::   zwgt           ! boundary weight
       REAL(wp) ::   zta, zsa, ztime
@@ -290,8 +285,8 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 ) CALL timing_start('bdy_tra_dmp')
-      !
-      DO ib_bdy=1, nb_bdy
-         IF ( ln_tra_dmp(ib_bdy) ) THEN
+      IF( nn_timing == 1 )   CALL timing_start('bdy_tra_dmp')
+      !
+      DO ib_bdy = 1, nb_bdy
+         IF( ln_tra_dmp(ib_bdy) ) THEN
             igrd = 1                       ! Everything is at T-points here
             DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
@@ -307,7 +302,7 @@
             END DO
          ENDIF
-      ENDDO
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_tra_dmp')
+      END DO
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_tra_dmp')
       !
    END SUBROUTINE bdy_tra_dmp
@@ -325,5 +320,4 @@
       WRITE(*,*) 'bdy_tra_dmp: You should not have seen this print! error?', kt
    END SUBROUTINE bdy_tra_dmp
-
 #endif
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90	(revision 6140)
@@ -10,29 +10,27 @@
    !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
    !!----------------------------------------------------------------------
-#if   defined key_bdy
+#if defined key_bdy
    !!----------------------------------------------------------------------
-   !!   'key_bdy'      unstructured open boundary conditions
+   !!   'key_bdy'                     unstructured open boundary conditions
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers 
-   USE bdy_oce         ! ocean open boundary conditions
-   USE sbc_oce         ! ocean surface boundary conditions
-   USE dom_oce         ! ocean space and time domain 
-   USE phycst          ! physical constants
-   USE sbcisf          ! ice shelf
+   USE oce            ! ocean dynamics and tracers 
+   USE bdy_oce        ! ocean open boundary conditions
+   USE sbc_oce        ! ocean surface boundary conditions
+   USE dom_oce        ! ocean space and time domain 
+   USE phycst         ! physical constants
+   USE sbcisf         ! ice shelf
    !
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! for mppsum
-   USE timing          ! Timing
-   USE lib_fortran     ! Fortran routines library
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! for mppsum
+   USE timing         ! Timing
+   USE lib_fortran    ! Fortran routines library
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC bdy_vol      
+   PUBLIC   bdy_vol    ! called by ???
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.6 , NEMO Consortium (2014)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
    !! $Id$ 
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -45,8 +43,8 @@
       !!
       !! ** Purpose :   This routine controls the volume of the system. 
-      !!      A correction velocity is calculated
-      !!      to correct the total transport through the unstructured OBC. 
+      !!      A correction velocity is calculated to correct the total transport 
+      !!      through the unstructured OBC. 
       !!      The total depth used is constant (H0) to be consistent with the 
-      !!      linear free surface coded in OPA 8.2
+      !!      linear free surface coded in OPA 8.2    <<<=== !!gm  ???? true ????
       !!
       !! ** Method  :   The correction velocity (zubtpecor here) is defined calculating
@@ -72,6 +70,6 @@
       !!            (set nn_volctl to 1 in tne namelist for this option)
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-      !!
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
       INTEGER  ::   ji, jj, jk, jb, jgrd
       INTEGER  ::   ib_bdy, ii, ij
@@ -93,5 +91,5 @@
       ! -----------------------------------------------------------------------
 !!gm replace these lines :
-      z_cflxemp = SUM ( ( emp(:,:)-rnf(:,:)+fwfisf(:,:) ) * bdytmask(:,:) * e1e2t(:,:) ) / rau0
+      z_cflxemp = SUM ( ( emp(:,:) - rnf(:,:) + fwfisf(:,:) ) * bdytmask(:,:) * e1e2t(:,:) ) / rau0
       IF( lk_mpp )   CALL mpp_sum( z_cflxemp )     ! sum over the global domain
 !!gm   by :
@@ -110,5 +108,5 @@
                ii = idx%nbi(jb,jgrd)
                ij = idx%nbj(jb,jgrd)
-               zubtpecor = zubtpecor + idx%flagu(jb,jgrd) * ua(ii,ij, jk) * e2u(ii,ij) * fse3u(ii,ij,jk)
+               zubtpecor = zubtpecor + idx%flagu(jb,jgrd) * ua(ii,ij, jk) * e2u(ii,ij) * e3u_n(ii,ij,jk)
             END DO
          END DO
@@ -118,5 +116,5 @@
                ii = idx%nbi(jb,jgrd)
                ij = idx%nbj(jb,jgrd)
-               zubtpecor = zubtpecor + idx%flagv(jb,jgrd) * va(ii,ij, jk) * e1v(ii,ij) * fse3v(ii,ij,jk) 
+               zubtpecor = zubtpecor + idx%flagv(jb,jgrd) * va(ii,ij, jk) * e1v(ii,ij) * e3v_n(ii,ij,jk) 
             END DO
          END DO
@@ -127,6 +125,6 @@
       ! The normal velocity correction
       ! ------------------------------
-      IF( nn_volctl==1 ) THEN   ;   zubtpecor = ( zubtpecor - z_cflxemp) / bdysurftot 
-      ELSE                      ;   zubtpecor =   zubtpecor             / bdysurftot
+      IF( nn_volctl==1 ) THEN   ;   zubtpecor = ( zubtpecor - z_cflxemp ) / bdysurftot 
+      ELSE                      ;   zubtpecor =   zubtpecor               / bdysurftot
       END IF
 
@@ -143,5 +141,5 @@
                ij = idx%nbj(jb,jgrd)
                ua(ii,ij,jk) = ua(ii,ij,jk) - idx%flagu(jb,jgrd) * zubtpecor * umask(ii,ij,jk)
-               ztranst = ztranst + idx%flagu(jb,jgrd) * ua(ii,ij,jk) * e2u(ii,ij) * fse3u(ii,ij,jk)
+               ztranst = ztranst + idx%flagu(jb,jgrd) * ua(ii,ij,jk) * e2u(ii,ij) * e3u_n(ii,ij,jk)
             END DO
          END DO
@@ -152,5 +150,5 @@
                ij = idx%nbj(jb,jgrd)
                va(ii,ij,jk) = va(ii,ij,jk) -idx%flagv(jb,jgrd) * zubtpecor * vmask(ii,ij,jk)
-               ztranst = ztranst + idx%flagv(jb,jgrd) * va(ii,ij,jk) * e1v(ii,ij) * fse3v(ii,ij,jk)
+               ztranst = ztranst + idx%flagv(jb,jgrd) * va(ii,ij,jk) * e1v(ii,ij) * e3v_n(ii,ij,jk)
             END DO
          END DO
@@ -161,5 +159,5 @@
       ! Check the cumulated transport through unstructured OBC once barotropic velocities corrected
       ! ------------------------------------------------------
-      IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
+      IF( lwp .AND. MOD( kt, nwrite ) == 0 ) THEN
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*)'bdy_vol : time step :', kt
@@ -171,5 +169,5 @@
       END IF 
       !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_vol')
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_vol')
       !
       END IF ! ln_vol
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/c1d.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/c1d.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/c1d.F90	(revision 6140)
@@ -4,7 +4,7 @@
    !! Ocean domain  :  1D configuration
    !!=====================================================================
-   !! History :   2.0  !  2004-09 (C. Ethe)     Original code
-   !!             3.0  !  2008-04 (G. Madec)    adaptation to SBC
-   !!             3.5  !  2013-10 (D. Calvert)  add namelist
+   !! History :  2.0  !  2004-09 (C. Ethe)     Original code
+   !!            3.0  !  2008-04 (G. Madec)    adaptation to SBC
+   !!            3.5  !  2013-10 (D. Calvert)  add namelist
    !!----------------------------------------------------------------------
 #if defined key_c1d
@@ -12,23 +12,24 @@
    !!   'key_c1d'                                   1D column configuration
    !!----------------------------------------------------------------------
-   !!   c1d_init       : read in the C1D namelist
+   !!   c1d_init      : read in the C1D namelist
    !!----------------------------------------------------------------------
-   USE in_out_manager   ! I/O manager
-   USE par_kind         ! kind parameters
-   USE lib_mpp
+   USE par_kind       ! kind parameters
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   c1d_init                                 ! called by nemogcm.F90
+   PUBLIC   c1d_init   ! called by nemogcm.F90
 
    LOGICAL , PUBLIC, PARAMETER ::  lk_c1d = .TRUE.   ! 1D config. flag
 
-   REAL(wp), PUBLIC            ::  rn_lat1d     ! Column latitude
-   REAL(wp), PUBLIC            ::  rn_lon1d     ! Column longitude
-   LOGICAL , PUBLIC            ::  ln_c1d_locpt ! Localization (or not) of 1D column in a grid
+   REAL(wp), PUBLIC ::  rn_lat1d     !: Column latitude
+   REAL(wp), PUBLIC ::  rn_lon1d     !: Column longitude
+   LOGICAL , PUBLIC ::  ln_c1d_locpt !: Localization (or not) of 1D column in a grid
 
    !!----------------------------------------------------------------------
-   !! NEMO/C1D 3.3 , NEMO Consortium (2010)
+   !! NEMO/C1D 3.7 , NEMO Consortium (2015)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -44,5 +45,6 @@
       !! ** Method  :   Read namelist namc1d 
       !!----------------------------------------------------------------------
-      INTEGER ::   ios                 ! Local integer output status for namelist read
+      INTEGER ::   ios   ! Local integer
+      !!
       NAMELIST/namc1d/ rn_lat1d, rn_lon1d , ln_c1d_locpt
       !!----------------------------------------------------------------------
@@ -50,9 +52,9 @@
       REWIND( numnam_ref )              ! Namelist namc1d in reference namelist : Tracer advection scheme
       READ  ( numnam_ref, namc1d, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namc1d in reference namelist', lwp )
-
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc1d in reference namelist', lwp )
+      !
       REWIND( numnam_cfg )              ! Namelist namtra_adv in configuration namelist : Tracer advection scheme
       READ  ( numnam_cfg, namc1d, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namc1d in configuration namelist', lwp )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc1d in configuration namelist', lwp )
       IF(lwm) WRITE ( numond, namc1d )
       !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/domc1d.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/domc1d.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/domc1d.F90	(revision 6140)
@@ -12,8 +12,9 @@
    !!   dom_c1d     : Determine jpizoom/jpjzoom from a given lat/lon
    !!----------------------------------------------------------------------
-   USE phycst                        ! Physical constants (and par_oce)
-   USE iom                           ! I/O library (iom_get)
-   USE in_out_manager                ! I/O manager (ctmp1)
-   USE dom_oce , ONLY : nimpp, njmpp ! Shared/distributed memory setting (mpp_init routine)
+   USE phycst         ! Physical constants (and par_oce)
+   USE dom_oce , ONLY : nimpp, njmpp ! Shared/distributed memory setting
+   !
+   USE iom            ! I/O library (iom_get)
+   USE in_out_manager ! I/O manager (ctmp1)
    USE wrk_nemo                      ! Memory allocation
    USE timing                        ! Timing
@@ -22,8 +23,8 @@
    PRIVATE
 
-   PUBLIC   dom_c1d                  ! Routine called in domcfg.F90
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   PUBLIC   dom_c1d   ! called in domcfg.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -43,29 +44,23 @@
       !! ** Action  : Recalculate jpizoom, jpjzoom (indices of C1D zoom)
       !!----------------------------------------------------------------------
-      NAMELIST/namdom/ nn_bathy, rn_bathy , rn_e3zps_min, rn_e3zps_rat, nn_msh, rn_hmin,   &
-         &             nn_acc   , rn_atfp     , rn_rdt      , rn_rdtmin ,                  &
-         &             rn_rdtmax, rn_rdth     , nn_closea , ln_crs,    &
-         &             jphgr_msh, &
-         &             ppglam0, ppgphi0, ppe1_deg, ppe2_deg, ppe1_m, ppe2_m, &
-         &             ppsur, ppa0, ppa1, ppkth, ppacr, ppdzmin, pphmax, ldbletanh, &
-         &             ppa2, ppkth2, ppacr2
-
-      INTEGER  ::  ji, jj                          ! Dummy loop indices
-      INTEGER  ::  inum                            ! Coordinate file handle (case 0)
-      INTEGER  ::  ijeq                            ! Index of equator T point (case 4)
-      INTEGER  ::  ios                             ! Local integer output status for namelist read
-
-      INTEGER , DIMENSION(2) ::   iloc             ! Minloc returned indices
-
-      REAL(wp), INTENT(in) ::  plat                ! Column latitude
-      REAL(wp), INTENT(in) ::  plon                ! Column longitude
-
+      REAL(wp), INTENT(in) ::  plat, plon    ! Column latitude &  longitude
+      !
+      INTEGER  ::  ji, jj   ! Dummy loop indices
+      INTEGER  ::  inum     ! Coordinate file handle (case 0)
+      INTEGER  ::  ijeq     ! Index of equator T point (case 4)
+      INTEGER  ::  ios      ! Local integer output status for namelist read
+      INTEGER , DIMENSION(2) ::   iloc   ! Minloc returned indices
       REAL(wp) ::  zlon                            ! Wraparound longitude
       REAL(wp) ::  zti, ztj, zarg                  ! Local scalars
       REAL(wp) ::  glam0, gphi0                    ! Variables corresponding to parameters ppglam0 ppgphi0 set in par_oce
       REAL(wp) ::  zlam1, zcos_alpha, ze1, ze1deg  ! Case 5 local scalars
-      REAL(wp) ::  zphi1, zsin_alpha, zim05, zjm05 !          "
-
+      REAL(wp) ::  zphi1, zsin_alpha, zim05, zjm05 !          
       REAL(wp) , POINTER, DIMENSION(:,:) ::  gphidta, glamdta, zdist ! Global lat/lon
+      !!
+      NAMELIST/namdom/ nn_bathy, rn_bathy , rn_e3zps_min, rn_e3zps_rat, nn_msh, rn_hmin,   &
+         &             rn_atfp     , rn_rdt      ,nn_closea , ln_crs,  jphgr_msh, &
+         &             ppglam0, ppgphi0, ppe1_deg, ppe2_deg, ppe1_m, ppe2_m, &
+         &             ppsur, ppa0, ppa1, ppkth, ppacr, ppdzmin, pphmax, ldbletanh, &
+         &             ppa2, ppkth2, ppacr2
       !!----------------------------------------------------------------------
 
@@ -74,13 +69,11 @@
       REWIND( numnam_ref )              ! Namelist namdom in reference namelist : space & time domain (bathymetry, mesh, timestep)
       READ  ( numnam_ref, namdom, IOSTAT = ios, ERR = 901 )
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdom in reference namelist', lwp )
-  
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdom in reference namelist', lwp )
       !
       REWIND( numnam_cfg )              ! Namelist namdom in configuration namelist : space & time domain (bathymetry, mesh, timestep)
       READ  ( numnam_cfg, namdom, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdom in configuration namelist', lwp )
-
-      CALL wrk_alloc( jpidta, jpjdta, gphidta, glamdta, zdist )
-
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdom in configuration namelist', lwp )
+
+      CALL wrk_alloc( jpidta,jpjdta,   gphidta, glamdta, zdist )
 
       ! ============================= !
@@ -171,5 +164,4 @@
       END SELECT
 
-
       ! ============================== !
       !  Code from dom_ngb:            !
@@ -192,5 +184,5 @@
       jpjzoom = iloc(2) + njmpp - 2  ! corner index of the zoom domain.
 
-      CALL wrk_dealloc( jpidta, jpjdta, gphidta, glamdta, zdist )
+      CALL wrk_dealloc( jpidta,jpjdta,   gphidta, glamdta, zdist )
 
       IF (lwp) THEN
@@ -202,7 +194,7 @@
          WRITE(numout,*)
       ENDIF
-
+      !
       IF( nn_timing == 1 )   CALL timing_stop('dom_c1d')
-
+      !
    END SUBROUTINE dom_c1d
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/dtauvd.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/dtauvd.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/dtauvd.F90	(revision 6140)
@@ -4,19 +4,20 @@
    !! Ocean data  :  read ocean U & V current data from gridded data
    !!======================================================================
-   !! History :  3.5   ! 2013-08  (D. Calvert)  Original code
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dta_uvd_init   : read namelist and allocate data structures
-   !!   dta_uvd        : read and time-interpolate ocean U & V current data
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE fldread         ! read input fields
-   USE in_out_manager  ! I/O manager
-   USE phycst          ! physical constants
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory allocation
-   USE timing          ! Timing
+   !! History :  3.5  ! 2013-08  (D. Calvert)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dta_uvd_init  : read namelist and allocate data structures
+   !!   dta_uvd       : read and time-interpolate ocean U & V current data
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE phycst         ! physical constants
+   USE dom_oce        ! ocean space and time domain
+   !
+   USE in_out_manager ! I/O manager
+   USE fldread        ! read input fields
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -26,13 +27,11 @@
    PUBLIC   dta_uvd        ! called by istate.F90 and dyndmp.90
 
-   LOGICAL , PUBLIC ::   ln_uvd_init         ! Flag to initialise with U & V current data
-   LOGICAL , PUBLIC ::   ln_uvd_dyndmp       ! Flag for Newtonian damping toward U & V current data
+   LOGICAL , PUBLIC ::   ln_uvd_init     ! Flag to initialise with U & V current data
+   LOGICAL , PUBLIC ::   ln_uvd_dyndmp   ! Flag for Newtonian damping toward U & V current data
 
    TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_uvd   ! structure for input U & V current (file information and data)
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -50,27 +49,25 @@
       !!              - fld_fill data structure with namelist information
       !!----------------------------------------------------------------------
-      LOGICAL, INTENT(in), OPTIONAL ::   ld_dyndmp         ! force the initialization when dyndmp is used
-      !
-      INTEGER ::   ierr0, ierr1, ierr2, ierr3              ! temporary integers
-      !
-      CHARACTER(len=100)            ::   cn_dir            ! Root directory for location of files to be used
-      TYPE(FLD_N), DIMENSION(2)     ::   suv_i             ! Combined U & V namelist information
-      TYPE(FLD_N)                   ::   sn_ucur, sn_vcur  ! U & V data namelist information
+      LOGICAL, INTENT(in), OPTIONAL ::   ld_dyndmp   ! force the initialization when dyndmp is used
+      !
+      INTEGER ::   ios, ierr0, ierr1, ierr2, ierr3     ! local integers
+      CHARACTER(len=100)        ::   cn_dir            ! Root directory for location of files to be used
+      TYPE(FLD_N), DIMENSION(2) ::   suv_i             ! Combined U & V namelist information
+      TYPE(FLD_N)               ::   sn_ucur, sn_vcur  ! U & V data namelist information
       !!
       NAMELIST/namc1d_uvd/ ln_uvd_init, ln_uvd_dyndmp, cn_dir, sn_ucur, sn_vcur
-      INTEGER  ::   ios
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('dta_uvd_init')
-      !
-      ierr0 = 0  ;  ierr1 = 0  ;  ierr2 = 0  ;  ierr3 = 0
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('dta_uvd_init')
+      !
+      ierr0 = 0   ;   ierr1 = 0   ;   ierr2 = 0  ;   ierr3 = 0
 
       REWIND( numnam_ref )              ! Namelist namc1d_uvd in reference namelist : 
       READ  ( numnam_ref, namc1d_uvd, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namc1d_uvd in reference namelist', lwp )
-
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc1d_uvd in reference namelist', lwp )
+      !
       REWIND( numnam_cfg )              ! Namelist namc1d_uvd in configuration namelist : Parameters of the run
       READ  ( numnam_cfg, namc1d_uvd, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namc1d_uvd in configuration namelist', lwp )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc1d_uvd in configuration namelist', lwp )
       IF(lwm) WRITE ( numond, namc1d_uvd )
 
@@ -149,13 +146,7 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dta_uvd')
+      IF( nn_timing == 1 )   CALL timing_start('dta_uvd')
       !
       CALL fld_read( kt, 1, sf_uvd )      !==   read U & V current data at time step kt   ==!
-      !
-      !
-      !                                   !==   ORCA_R2 configuration and U & V current damping   ==! 
-      IF( cp_cfg == "orca" .AND. jp_cfg == 2 .AND. ln_uvd_dyndmp ) THEN    ! some hand made alterations
-         !!! EMPTY- to be added for running in 3D context !!!
-      ENDIF
       !
       puvd(:,:,:,1) = sf_uvd(1)%fnow(:,:,:)                 ! NO mask
@@ -164,5 +155,5 @@
       IF( ln_sco ) THEN                   !==   s- or mixed s-zps-coordinate   ==!
          !
-         CALL wrk_alloc( jpk, zup, zvp )
+         CALL wrk_alloc( jpk,   zup, zvp )
          !
          IF( kt == nit000 .AND. lwp )THEN
@@ -174,5 +165,5 @@
             DO ji = 1, jpi                ! determines the interpolated U & V current profiles at each (i,j) point
                DO jk = 1, jpk
-                  zl = fsdept(ji,jj,jk)
+                  zl = gdept_n(ji,jj,jk)
                   IF    ( zl < gdept_1d(1  ) ) THEN          ! extrapolate above the first level of data
                      zup(jk) =  puvd(ji,jj,1    ,1)
@@ -200,5 +191,5 @@
          END DO
          ! 
-         CALL wrk_dealloc( jpk, zup, zvp )
+         CALL wrk_dealloc( jpk,   zup, zvp )
          ! 
       ELSE                                !==   z- or zps- coordinate   ==!
@@ -222,25 +213,4 @@
       ENDIF
       !
-      IF( lwp .AND. kt == nit000 ) THEN   ! control print
-         WRITE(numout,*) ' U current '
-         WRITE(numout,*)
-         WRITE(numout,*)'  level = 1'
-         CALL prihre( puvd(:,:,1    ,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-         WRITE(numout,*)'  level = ', jpk/2
-         CALL prihre( puvd(:,:,jpk/2,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-         WRITE(numout,*)'  level = ', jpkm1
-         CALL prihre( puvd(:,:,jpkm1,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-         WRITE(numout,*)
-         WRITE(numout,*) ' V current '
-         WRITE(numout,*)
-         WRITE(numout,*)'  level = 1'
-         CALL prihre( puvd(:,:,1    ,2), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-         WRITE(numout,*)'  level = ', jpk/2
-         CALL prihre( puvd(:,:,jpk/2,2), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-         WRITE(numout,*)'  level = ', jpkm1
-         CALL prihre( puvd(:,:,jpkm1,2), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-         WRITE(numout,*)
-      ENDIF
-      !
       IF( .NOT. ln_uvd_dyndmp    ) THEN   !==   deallocate U & V current structure   ==! 
          !                                !==   (data used only for initialization)  ==!
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/dyncor_c1d.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/dyncor_c1d.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/dyncor_c1d.F90	(revision 6140)
@@ -11,23 +11,24 @@
    !!   'key_c1d'                                          1D Configuration
    !!----------------------------------------------------------------------
-   !!   cor_c1d      : Coriolis factor at T-point (1D configuration)
-   !!   dyn_cor_c1d  : vorticity trend due to Coriolis at T-point
+   !!   cor_c1d       : Coriolis factor at T-point (1D configuration)
+   !!   dyn_cor_c1d   : vorticity trend due to Coriolis at T-point
    !!----------------------------------------------------------------------
-   USE oce               ! ocean dynamics and tracers
-   USE dom_oce           ! ocean space and time domain
-   USE phycst            ! physical constants
-   USE in_out_manager    ! I/O manager
-   USE prtctl            ! Print control
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   !
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   cor_c1d      ! routine called by OPA.F90
-   PUBLIC   dyn_cor_c1d  ! routine called by step1d.F90
+   PUBLIC   cor_c1d      ! called by nemogcm.F90
+   PUBLIC   dyn_cor_c1d  ! called by step1d.F90
 
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/C1D 3.3 , NEMO Consortium (2010)
+   !! NEMO/C1D 3.7 , NEMO Consortium (2015)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -41,5 +42,5 @@
       !! ** Purpose : set the Coriolis factor at T-point
       !!----------------------------------------------------------------------
-      REAL(wp) ::   zphi0, zbeta, zf0         !  temporary scalars
+      REAL(wp) ::   zphi0, zbeta, zf0   ! local scalars
       !!----------------------------------------------------------------------
 
@@ -87,5 +88,5 @@
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
       !!
-      INTEGER ::   ji, jj, jk         ! dummy loop indices
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
       !!----------------------------------------------------------------------
       !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/dyndmp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/dyndmp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/dyndmp.F90	(revision 6140)
@@ -23,4 +23,5 @@
    USE dtauvd         ! data: U & V current
    USE zdfmxl         ! vertical physics: mixed layer depth
+   !
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
@@ -36,15 +37,14 @@
    PUBLIC   dyn_dmp      ! routine called by step_c1d.F90
 
-   LOGICAL, PUBLIC ::   ln_dyndmp           ! Flag for Newtonian damping
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  utrdmp    ! damping U current trend (m/s2)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  vtrdmp    ! damping V current trend (m/s2)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  resto_uv  ! restoring coeff. on U & V current
+   LOGICAL, PUBLIC ::   ln_dyndmp   !: Flag for Newtonian damping
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  utrdmp    !: damping U current trend (m/s2)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  vtrdmp    !: damping V current trend (m/s2)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  resto_uv  !: restoring coeff. on U & V current
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -75,18 +75,18 @@
       !!              - calculate damping coefficient
       !!----------------------------------------------------------------------
+      INTEGER ::   ios, imask   ! local integers
+      !!
       NAMELIST/namc1d_dyndmp/ ln_dyndmp
-      INTEGER :: ios
-      INTEGER :: imask
-      !!----------------------------------------------------------------------
-
+      !!----------------------------------------------------------------------
+      !
       REWIND( numnam_ref )              ! Namelist namc1d_dyndmp in reference namelist : 
       READ  ( numnam_ref, namc1d_dyndmp, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namc1d_dyndmp in reference namelist', lwp )
-
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc1d_dyndmp in reference namelist', lwp )
+      !
       REWIND( numnam_cfg )              ! Namelist namc1d_dyndmp in configuration namelist : Parameters of the run
       READ  ( numnam_cfg, namc1d_dyndmp, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namc1d_dyndmp in configuration namelist', lwp )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc1d_dyndmp in configuration namelist', lwp )
       IF(lwm) WRITE ( numond, namc1d_dyndmp )
-
+      !
       IF(lwp) THEN                           ! control print
          WRITE(numout,*)
@@ -101,5 +101,5 @@
          WRITE(numout,*)
       ENDIF
-
+      !
       IF( ln_dyndmp ) THEN
          !                                   !==   allocate the data arrays   ==!
@@ -150,14 +150,14 @@
       !! ** Action  : - (ua,va)   momentum trends updated with the damping trend
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt                        ! ocean time-step index
-      !!
-      INTEGER  ::   ji, jj, jk                           ! dummy loop indices
-      REAL(wp) ::   zua, zva                             ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::  zuv_dta  ! Read in data 
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zua, zva     ! local scalars
+      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   zuv_dta   ! Read in data 
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start( 'dyn_dmp' )
       !
-      CALL wrk_alloc( jpi, jpj, jpk, 2,  zuv_dta )
+      CALL wrk_alloc( jpi,jpj,jpk,2,   zuv_dta )
       !
       !                           !==   read and interpolate U & V current data at kt   ==!
@@ -204,5 +204,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  IF( fsdept(ji,jj,jk) >= hmlp (ji,jj) ) THEN
+                  IF( gdept_n(ji,jj,jk) >= hmlp (ji,jj) ) THEN
                      zua = resto_uv(ji,jj,jk) * ( zuv_dta(ji,jj,jk,1) - ub(ji,jj,jk) )
                      zva = resto_uv(ji,jj,jk) * ( zuv_dta(ji,jj,jk,2) - vb(ji,jj,jk) )
@@ -221,12 +221,9 @@
       END SELECT
       !
-!!gm      !                           ! Trend diagnostic
-!!gm      IF( l_trddyn )   CALL trd_mod( utrdmp, vtrdmp, jpdyn_trd_dat, 'DYN', kt )
-      !
       !                           ! Control print
       IF( ln_ctl   )   CALL prt_ctl( tab3d_1=ua(:,:,:), clinfo1=' dmp  - Ua: ', mask1=umask,   &
          &                           tab3d_2=va(:,:,:), clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
       !
-      CALL wrk_dealloc( jpi, jpj, jpk, 2,  zuv_dta )
+      CALL wrk_dealloc( jpi,jpj,jpk,2,   zuv_dta )
       !
       IF( nn_timing == 1 )  CALL timing_stop( 'dyn_dmp')
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90	(revision 6140)
@@ -28,8 +28,7 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "zdfddm_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/C1D 3.3 , NEMO Consortium (2010)
+   !! NEMO/C1D 3.7 , NEMO Consortium (2015)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -55,4 +54,5 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
+      !
       INTEGER ::   jk       ! dummy loop indice
       INTEGER ::   indic    ! error indicator if < 0
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crs.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crs.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crs.F90	(revision 6140)
@@ -11,9 +11,7 @@
    USE in_out_manager
 
-
    IMPLICIT NONE
    PUBLIC
 
-   
    PUBLIC crs_dom_alloc  ! Called from crsini.F90
    PUBLIC crs_dom_alloc2  ! Called from crsini.F90
@@ -161,8 +159,9 @@
       INTEGER,  PUBLIC, ALLOCATABLE, DIMENSION(:,:)    ::  nmln_crs, hmld_crs, hmlp_crs, hmlpt_crs                       
 
-      ! Direction of lateral diffusion
-
-
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
    !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
    
@@ -258,5 +257,6 @@
 
    END FUNCTION crs_dom_alloc
-   
+
+
    INTEGER FUNCTION crs_dom_alloc2()
       !!-------------------------------------------------------------------
@@ -272,5 +272,6 @@
       crs_dom_alloc2 = MAXVAL(ierr)
 
-      END FUNCTION crs_dom_alloc2
+   END FUNCTION crs_dom_alloc2
+
 
    SUBROUTINE dom_grid_glo
@@ -312,4 +313,5 @@
    END SUBROUTINE dom_grid_glo
 
+
    SUBROUTINE dom_grid_crs
       !!--------------------------------------------------------------------
@@ -318,5 +320,4 @@
       !! ** Purpose :  Save the parent grid information & Switch to coarse grid domain
       !!---------------------------------------------------------------------
-
       !
       !                        Switch to coarse grid domain
@@ -349,12 +350,8 @@
       nlejt(:)  = nlejt_crs(:)
       njmppt(:) = njmppt_crs(:)
-
-
       !
    END SUBROUTINE dom_grid_crs
    
-      
    !!======================================================================
-
 END MODULE crs
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crsdom.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crsdom.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crsdom.F90	(revision 6140)
@@ -30,13 +30,12 @@
    !!       Original.   May 2012.  (J. Simeon, C. Calone, G. Madec, C. Ethe)
    !!===================================================================
-
    USE dom_oce        ! ocean space and time domain and to get jperio
-   USE wrk_nemo       ! work arrays
    USE crs            ! domain for coarse grid
+   !
    USE in_out_manager 
    USE par_kind
    USE crslbclnk
+   USE wrk_nemo       ! work arrays
    USE lib_mpp
-   
 
    IMPLICIT NONE
@@ -54,10 +53,10 @@
    REAL(wp) :: r_inf = 1e+36
 
-   !! Substitutions
-#  include "domzgr_substitute.h90"
-   
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
    !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
-
 
    SUBROUTINE crs_dom_msk
@@ -133,4 +132,5 @@
    END SUBROUTINE crs_dom_msk
 
+
    SUBROUTINE crs_dom_coordinates( p_gphi, p_glam, cd_type, p_gphi_crs, p_glam_crs )
       !!----------------------------------------------------------------
@@ -334,5 +334,5 @@
       !!              cd_type     = grid type (T,U,V,F) for scale factors; for velocities (U or V)
       !!              cd_op       = applied operation (SUM, VOL, WGT)
-      !!              p_fse3      = (Optional) parent grid vertical level thickness (fse3u or fse3v)
+      !!              p_e3      = (Optional) parent grid vertical level thickness (e3u or e3v)
       !! ** Outputs : p_cfield2d_1 = (Optional) 2D field on coarse grid
       !!              p_cfield2d_2 = (Optional) 2D field on coarse grid
@@ -342,32 +342,27 @@
       !! History.     4 Jun.  Write for WGT and scale factors only
       !!----------------------------------------------------------------
-      !! 
-      !!  Arguments
-      CHARACTER(len=1),                         INTENT(in)  :: cd_type  ! grid type U,V 
-      REAL(wp), DIMENSION(jpi,jpj,jpk)        , INTENT(in)  :: p_mask  ! Parent grid U,V mask
-      REAL(wp), DIMENSION(jpi,jpj)            , INTENT(in)  :: p_e1     ! Parent grid U,V scale factors (e1)
-      REAL(wp), DIMENSION(jpi,jpj)            , INTENT(in)  :: p_e2     ! Parent grid U,V scale factors (e2)
-      REAL(wp), DIMENSION(jpi,jpj,jpk)        , INTENT(in)  :: p_e3     ! Parent grid vertical level thickness (fse3u, fse3v)
-
-      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(out) :: p_fld1_crs ! Coarse grid box 3D quantity 
-      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(out) :: p_fld2_crs ! Coarse grid box 3D quantity 
-
-      !! Local variables
-      REAL(wp)                                :: zdAm
-      INTEGER                                 :: ji, jj, jk , ii, ij, je_2
-
-      REAL(wp), DIMENSION(:,:,:), POINTER     :: zvol, zmask      
+      CHARACTER(len=1),                         INTENT(in   ) ::   cd_type    ! grid type U,V 
+      REAL(wp), DIMENSION(jpi,jpj,jpk)        , INTENT(in   ) ::   p_mask     ! Parent grid U,V mask
+      REAL(wp), DIMENSION(jpi,jpj)            , INTENT(in   ) ::   p_e1       ! Parent grid U,V scale factors (e1)
+      REAL(wp), DIMENSION(jpi,jpj)            , INTENT(in   ) ::   p_e2       ! Parent grid U,V scale factors (e2)
+      REAL(wp), DIMENSION(jpi,jpj,jpk)        , INTENT(in   ) ::   p_e3       ! Parent grid vertical level thickness (e3u, e3v)
+      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(  out) ::   p_fld1_crs ! Coarse grid box 3D quantity 
+      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(  out) ::   p_fld2_crs ! Coarse grid box 3D quantity 
+      !
+      INTEGER  ::   ji, jj, jk , ii, ij, je_2
+      REAL(wp) ::   zdAm
+      REAL(wp), DIMENSION(:,:,:), POINTER ::   zvol, zmask      
       !!----------------------------------------------------------------  
-   
-      CALL wrk_alloc( jpi, jpj, jpk, zvol, zmask )
-
-      p_fld1_crs(:,:,:) = 0.0
-      p_fld2_crs(:,:,:) = 0.0
+      !
+      CALL wrk_alloc( jpi,jpj,jpk,   zvol, zmask )
+      !
+      p_fld1_crs(:,:,:) = 0._wp
+      p_fld2_crs(:,:,:) = 0._wp
 
       DO jk = 1, jpk
          zvol(:,:,jk) =  p_e1(:,:) * p_e2(:,:) * p_e3(:,:,jk) 
-      ENDDO
-
-      zmask(:,:,:) = 0.0
+      END DO
+
+      zmask(:,:,:) = 0._wp
       IF( cd_type == 'W' ) THEN
          zmask(:,:,1) = p_mask(:,:,1) 
@@ -469,5 +464,5 @@
       !!              p_pmask     = parent grid mask (T,U,V,F) for scale factors; 
       !!                                       for velocities (U or V)
-      !!              p_fse3      = parent grid vertical level thickness (fse3u or fse3v)
+      !!              p_e3      = parent grid vertical level thickness (e3u or e3v)
       !!              p_pfield    = U or V on the parent grid
       !!              p_surf_crs  = (Optional) Coarse grid weight for averaging
@@ -478,38 +473,33 @@
       !!            5 Jun.  Streamline for area-weighted average only ; separate scale factor and weights.
       !!----------------------------------------------------------------
-      !! 
-      !!  Arguments
-      REAL(wp), DIMENSION(jpi,jpj,jpk),         INTENT(in)           :: p_fld   ! T, U, V or W on parent grid
-      CHARACTER(len=3),                         INTENT(in)           :: cd_op    ! Operation SUM, MAX or MIN
+      REAL(wp), DIMENSION(jpi,jpj,jpk),         INTENT(in)           :: p_fld      ! T, U, V or W on parent grid
+      CHARACTER(len=3),                         INTENT(in)           :: cd_op      ! Operation SUM, MAX or MIN
       CHARACTER(len=1),                         INTENT(in)           :: cd_type    ! grid type U,V 
-      REAL(wp), DIMENSION(jpi,jpj,jpk),         INTENT(in)           :: p_mask    ! Parent grid T,U,V mask
-      REAL(wp), DIMENSION(jpi,jpj),             INTENT(in), OPTIONAL :: p_e12    ! Parent grid T,U,V scale factors (e1 or e2)
-      REAL(wp), DIMENSION(jpi,jpj,jpk),         INTENT(in), OPTIONAL :: p_e3     ! Parent grid vertical level thickness (fse3u, fse3v)
+      REAL(wp), DIMENSION(jpi,jpj,jpk),         INTENT(in)           :: p_mask     ! Parent grid T,U,V mask
+      REAL(wp), DIMENSION(jpi,jpj),             INTENT(in), OPTIONAL :: p_e12      ! Parent grid T,U,V scale factors (e1 or e2)
+      REAL(wp), DIMENSION(jpi,jpj,jpk),         INTENT(in), OPTIONAL :: p_e3       ! Parent grid vertical level thickness (e3u, e3v)
       REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(in), OPTIONAL :: p_surf_crs ! Coarse grid area-weighting denominator    
-      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(in), OPTIONAL :: p_mask_crs    ! Coarse grid T,U,V maska
-      REAL(wp),                                 INTENT(in)           :: psgn    ! sign 
-
-
-      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(out)          :: p_fld_crs ! Coarse grid box 3D quantity 
-
-      !! Local variables
-      INTEGER  :: ji, jj, jk 
-      INTEGER  :: ii, ij, ijie, ijje, je_2
-      REAL(wp) :: zflcrs, zsfcrs   
-      REAL(wp), DIMENSION(:,:,:), POINTER :: zsurf, zsurfmsk, zmask  
+      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(in), OPTIONAL :: p_mask_crs ! Coarse grid T,U,V maska
+      REAL(wp),                                 INTENT(in)           :: psgn       ! sign 
+      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(  out)        :: p_fld_crs  ! Coarse grid box 3D quantity 
+      !
+      INTEGER  ::   ji, jj, jk 
+      INTEGER  ::   ii, ij, ijie, ijje, je_2
+      REAL(wp) ::   zflcrs, zsfcrs   
+      REAL(wp), DIMENSION(:,:,:), POINTER ::   zsurf, zsurfmsk, zmask  
       !!----------------------------------------------------------------  
-   
-      p_fld_crs(:,:,:) = 0.0
-
+      !
+      p_fld_crs(:,:,:) = 0._wp
+      !
       SELECT CASE ( cd_op )
-      
-         CASE ( 'VOL' )
-      
-            CALL wrk_alloc( jpi, jpj, jpk, zsurf, zsurfmsk )
-         
-            SELECT CASE ( cd_type )
-            
-               CASE( 'T', 'W' )
-                  IF( cd_type == 'T' ) THEN
+      !
+      CASE ( 'VOL' )
+         !
+         CALL wrk_alloc( jpi,jpj,jpk,   zsurf, zsurfmsk )
+         !   
+         SELECT CASE ( cd_type )
+         !   
+         CASE( 'T', 'W' )
+               IF( cd_type == 'T' ) THEN
                      DO jk = 1, jpk
                         zsurf   (:,:,jk) =  p_e12(:,:) * p_e3(:,:,jk) *  p_mask(:,:,jk) 
@@ -1136,5 +1126,5 @@
       !!              p_pmask     = parent grid mask (T,U,V,F) for scale factors; 
       !!                                       for velocities (U or V)
-      !!              p_fse3      = parent grid vertical level thickness (fse3u or fse3v)
+      !!              p_e3      = parent grid vertical level thickness (e3u or e3v)
       !!              p_pfield    = U or V on the parent grid
       !!              p_surf_crs  = (Optional) Coarse grid weight for averaging
@@ -1145,6 +1135,4 @@
       !!            5 Jun.  Streamline for area-weighted average only ; separate scale factor and weights.
       !!----------------------------------------------------------------
-      !! 
-      !!  Arguments
       REAL(wp), DIMENSION(jpi,jpj),             INTENT(in)           :: p_fld   ! T, U, V or W on parent grid
       CHARACTER(len=3),                         INTENT(in)           :: cd_op    ! Operation SUM, MAX or MIN
@@ -1152,21 +1140,18 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk),         INTENT(in)           :: p_mask    ! Parent grid T,U,V mask
       REAL(wp), DIMENSION(jpi,jpj),             INTENT(in), OPTIONAL :: p_e12    ! Parent grid T,U,V scale factors (e1 or e2)
-      REAL(wp), DIMENSION(jpi,jpj,jpk),         INTENT(in), OPTIONAL :: p_e3     ! Parent grid vertical level thickness (fse3u, fse3v)
+      REAL(wp), DIMENSION(jpi,jpj,jpk),         INTENT(in), OPTIONAL :: p_e3     ! Parent grid vertical level thickness (e3u, e3v)
       REAL(wp), DIMENSION(jpi_crs,jpj_crs)    , INTENT(in), OPTIONAL :: p_surf_crs ! Coarse grid area-weighting denominator    
       REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(in), OPTIONAL :: p_mask_crs    ! Coarse grid T,U,V mask
       REAL(wp),                                 INTENT(in)           :: psgn   
-
       REAL(wp), DIMENSION(jpi_crs,jpj_crs)    , INTENT(out)          :: p_fld_crs ! Coarse grid box 3D quantity 
-
-      !! Local variables
+      !
       INTEGER  :: ji, jj, jk                 ! dummy loop indices
       INTEGER  :: ijie, ijje, ii, ij, je_2
       REAL(wp) :: zflcrs, zsfcrs   
       REAL(wp), DIMENSION(:,:), POINTER :: zsurfmsk   
-
       !!----------------------------------------------------------------  
-   
-      p_fld_crs(:,:) = 0.0
-
+      !
+      p_fld_crs(:,:) = 0._wp
+      !
       SELECT CASE ( cd_op )
       
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crsdomwri.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crsdomwri.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crsdomwri.F90	(revision 6140)
@@ -33,5 +33,9 @@
    PUBLIC crs_dom_wri        ! routine called by crsini.F90
 
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
    !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crsfld.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crsfld.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crsfld.F90	(revision 6140)
@@ -33,6 +33,4 @@
 
    !! * Substitutions
-#  include "zdfddm_substitute.h90"
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -52,5 +50,5 @@
       !!      2. At time of output, rescale [1] by dimension and time
       !!         to yield the spatial and temporal average.
-      !!  See. diawri_dimg.h90, sbcmod.F90
+      !!  See. sbcmod.F90
       !!
       !! ** Method  :  
@@ -61,5 +59,5 @@
       REAL(wp) ::   z2dcrsu, z2dcrsv  ! local scalars
       !
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zfse3t, zfse3u, zfse3v, zfse3w   ! 3D workspace for e3
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ze3t, ze3u, ze3v, ze3w   ! 3D workspace for e3
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   zt, zt_crs
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   zs, zs_crs  
@@ -69,15 +67,15 @@
 
       !  Initialize arrays
-      CALL wrk_alloc( jpi,jpj,jpk,   zfse3t, zfse3w )
-      CALL wrk_alloc( jpi,jpj,jpk,   zfse3u, zfse3v )
-      CALL wrk_alloc( jpi,jpj,jpk,   zt    , zs     )
-      !
-      CALL wrk_alloc( jpi_crs, jpj_crs, jpk, zt_crs, zs_crs )
+      CALL wrk_alloc( jpi,jpj,jpk,   ze3t, ze3w )
+      CALL wrk_alloc( jpi,jpj,jpk,   ze3u, ze3v )
+      CALL wrk_alloc( jpi,jpj,jpk,   zt  , zs   )
+      !
+      CALL wrk_alloc( jpi_crs,jpj_crs,jpk,   zt_crs, zs_crs )
 
       ! Depth work arrrays
-      zfse3t(:,:,:) = fse3t(:,:,:)
-      zfse3u(:,:,:) = fse3u(:,:,:)
-      zfse3v(:,:,:) = fse3v(:,:,:)
-      zfse3w(:,:,:) = fse3w(:,:,:)
+      ze3t(:,:,:) = e3t_n(:,:,:)
+      ze3u(:,:,:) = e3u_n(:,:,:)
+      ze3v(:,:,:) = e3v_n(:,:,:)
+      ze3w(:,:,:) = e3w_n(:,:,:)
 
       IF( kt == nit000  ) THEN
@@ -107,5 +105,5 @@
       !  Temperature
       zt(:,:,:) = tsn(:,:,:,jp_tem)  ;      zt_crs(:,:,:) = 0._wp
-      CALL crs_dom_ope( zt, 'VOL', 'T', tmask, zt_crs, p_e12=e1e2t, p_e3=zfse3t, psgn=1.0 )
+      CALL crs_dom_ope( zt, 'VOL', 'T', tmask, zt_crs, p_e12=e1e2t, p_e3=ze3t, psgn=1.0 )
       tsn_crs(:,:,:,jp_tem) = zt_crs(:,:,:)
 
@@ -116,5 +114,5 @@
       !  Salinity
       zs(:,:,:) = tsn(:,:,:,jp_sal)  ;      zs_crs(:,:,:) = 0._wp
-      CALL crs_dom_ope( zs, 'VOL', 'T', tmask, zs_crs, p_e12=e1e2t, p_e3=zfse3t, psgn=1.0 )
+      CALL crs_dom_ope( zs, 'VOL', 'T', tmask, zs_crs, p_e12=e1e2t, p_e3=ze3t, psgn=1.0 )
       tsn_crs(:,:,:,jp_sal) = zt_crs(:,:,:)
 
@@ -123,5 +121,5 @@
 
       !  U-velocity
-      CALL crs_dom_ope( un, 'SUM', 'U', umask, un_crs, p_e12=e2u, p_e3=zfse3u, p_surf_crs=e2e3u_msk, psgn=-1.0 )
+      CALL crs_dom_ope( un, 'SUM', 'U', umask, un_crs, p_e12=e2u, p_e3=ze3u, p_surf_crs=e2e3u_msk, psgn=-1.0 )
       !
       zt(:,:,:) = 0._wp     ;    zs(:,:,:) = 0._wp  ;   zt_crs(:,:,:) = 0._wp   ;    zs_crs(:,:,:) = 0._wp
@@ -134,6 +132,6 @@
          END DO
       END DO
-      CALL crs_dom_ope( zt, 'SUM', 'U', umask, zt_crs, p_e12=e2u, p_e3=zfse3u, p_surf_crs=e2e3u_msk, psgn=-1.0 )
-      CALL crs_dom_ope( zs, 'SUM', 'U', umask, zs_crs, p_e12=e2u, p_e3=zfse3u, p_surf_crs=e2e3u_msk, psgn=-1.0 )
+      CALL crs_dom_ope( zt, 'SUM', 'U', umask, zt_crs, p_e12=e2u, p_e3=ze3u, p_surf_crs=e2e3u_msk, psgn=-1.0 )
+      CALL crs_dom_ope( zs, 'SUM', 'U', umask, zs_crs, p_e12=e2u, p_e3=ze3u, p_surf_crs=e2e3u_msk, psgn=-1.0 )
 
       CALL iom_put( "uoce"  , un_crs )   ! i-current 
@@ -142,5 +140,5 @@
 
       !  V-velocity
-      CALL crs_dom_ope( vn, 'SUM', 'V', vmask, vn_crs, p_e12=e1v, p_e3=zfse3v, p_surf_crs=e1e3v_msk, psgn=-1.0 )
+      CALL crs_dom_ope( vn, 'SUM', 'V', vmask, vn_crs, p_e12=e1v, p_e3=ze3v, p_surf_crs=e1e3v_msk, psgn=-1.0 )
       !                                                                                 
       zt(:,:,:) = 0._wp     ;    zs(:,:,:) = 0._wp  ;   zt_crs(:,:,:) = 0._wp   ;    zs_crs(:,:,:) = 0._wp
@@ -153,6 +151,6 @@
          END DO
       END DO
-      CALL crs_dom_ope( zt, 'SUM', 'V', vmask, zt_crs, p_e12=e1v, p_e3=zfse3v, p_surf_crs=e1e3v_msk, psgn=-1.0 )
-      CALL crs_dom_ope( zs, 'SUM', 'V', vmask, zs_crs, p_e12=e1v, p_e3=zfse3v, p_surf_crs=e1e3v_msk, psgn=-1.0 )
+      CALL crs_dom_ope( zt, 'SUM', 'V', vmask, zt_crs, p_e12=e1v, p_e3=ze3v, p_surf_crs=e1e3v_msk, psgn=-1.0 )
+      CALL crs_dom_ope( zs, 'SUM', 'V', vmask, zs_crs, p_e12=e1v, p_e3=ze3v, p_surf_crs=e1e3v_msk, psgn=-1.0 )
  
       CALL iom_put( "voce"  , vn_crs )   ! i-current 
@@ -162,5 +160,5 @@
      
       !  Kinetic energy
-      CALL crs_dom_ope( rke, 'VOL', 'T', tmask, rke_crs, p_e12=e1e2t, p_e3=zfse3t, psgn=1.0 )
+      CALL crs_dom_ope( rke, 'VOL', 'T', tmask, rke_crs, p_e12=e1e2t, p_e3=ze3t, psgn=1.0 )
       CALL iom_put( "eken", rke_crs )
 
@@ -188,5 +186,5 @@
       IF( ln_crs_wn ) THEN
          CALL crs_dom_ope( wn, 'SUM', 'W', tmask, wn_crs, p_e12=e1e2t, p_surf_crs=e1e2w_msk, psgn=1.0 )
-       !  CALL crs_dom_ope( wn, 'VOL', 'W', tmask, wn_crs, p_e12=e1e2t, p_e3=zfse3w )
+       !  CALL crs_dom_ope( wn, 'VOL', 'W', tmask, wn_crs, p_e12=e1e2t, p_e3=ze3w )
       ELSE
         wn_crs(:,:,jpk) = 0._wp
@@ -199,11 +197,12 @@
 
       !  avt, avs
+!!gm BUG   TOP always uses avs !!!
       SELECT CASE ( nn_crs_kz )
          CASE ( 0 )
-            CALL crs_dom_ope( avt, 'VOL', 'W', tmask, avt_crs, p_e12=e1e2t, p_e3=zfse3w, psgn=1.0 )
+            CALL crs_dom_ope( avt, 'VOL', 'W', tmask, avt_crs, p_e12=e1e2t, p_e3=ze3w, psgn=1.0 )
          CASE ( 1 )
-            CALL crs_dom_ope( avt, 'MAX', 'W', tmask, avt_crs, p_e12=e1e2t, p_e3=zfse3w, psgn=1.0 )
+            CALL crs_dom_ope( avt, 'MAX', 'W', tmask, avt_crs, p_e12=e1e2t, p_e3=ze3w, psgn=1.0 )
          CASE ( 2 )
-            CALL crs_dom_ope( avt, 'MIN', 'W', tmask, avt_crs, p_e12=e1e2t, p_e3=zfse3w, psgn=1.0 )
+            CALL crs_dom_ope( avt, 'MIN', 'W', tmask, avt_crs, p_e12=e1e2t, p_e3=ze3w, psgn=1.0 )
       END SELECT
       !
@@ -211,5 +210,5 @@
       
       !  sbc fields  
-      CALL crs_dom_ope( sshn , 'VOL', 'T', tmask, sshn_crs , p_e12=e1e2t, p_e3=zfse3t         , psgn=1.0 )  
+      CALL crs_dom_ope( sshn , 'VOL', 'T', tmask, sshn_crs , p_e12=e1e2t, p_e3=ze3t           , psgn=1.0 )  
       CALL crs_dom_ope( utau , 'SUM', 'U', umask, utau_crs , p_e12=e2u  , p_surf_crs=e2u_crs  , psgn=1.0 )
       CALL crs_dom_ope( vtau , 'SUM', 'V', vmask, vtau_crs , p_e12=e1v  , p_surf_crs=e1v_crs  , psgn=1.0 )
@@ -233,8 +232,8 @@
 
       !  free memory
-      CALL wrk_dealloc( jpi, jpj, jpk, zfse3t, zfse3w )
-      CALL wrk_dealloc( jpi, jpj, jpk, zfse3u, zfse3v )
-      CALL wrk_dealloc( jpi, jpj, jpk, zt, zs       )
-      CALL wrk_dealloc( jpi_crs, jpj_crs, jpk, zt_crs, zs_crs )
+      CALL wrk_dealloc( jpi,jpj,jpk,   ze3t, ze3w )
+      CALL wrk_dealloc( jpi,jpj,jpk,   ze3u, ze3v )
+      CALL wrk_dealloc( jpi,jpj,jpk,   zt  , zs   )
+      CALL wrk_dealloc( jpi_crs,jpj_crs,jpk,   zt_crs, zs_crs )
       !
       CALL iom_swap( "nemo" )     ! return back on high-resolution grid
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crsini.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crsini.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crsini.F90	(revision 6140)
@@ -12,5 +12,5 @@
    USE par_kind, ONLY: wp
    USE par_oce                  ! For parameter jpi,jpj,jphgr_msh
-   USE dom_oce                  ! For parameters in par_oce (jperio, lk_vvl)
+   USE dom_oce                  ! For parameters in par_oce
    USE crs                      ! Coarse grid domain
    USE phycst, ONLY: omega, rad ! physical constants
@@ -30,8 +30,8 @@
    PUBLIC   crs_init   ! called by nemogcm.F90 module
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
    !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 CONTAINS
@@ -64,5 +64,5 @@
       !! output C*dA or C*dV as summation not mran, then do mean (division) at moment of output.
       !! As is, crsfun takes into account vvl.   
-      !!      Talked about pre-setting the surface array to avoid IF/ENDIFS and division.
+      !!      Talked about pre-setting the surface array to avoid IF/ENDIF and division.
       !!      But have then to make that preset array here and elsewhere.
       !!      that is called every timestep...
@@ -73,5 +73,5 @@
       INTEGER  :: ierr                                ! allocation error status
       INTEGER  ::   ios                 ! Local integer output status for namelist read
-      REAL(wp), DIMENSION(:,:,:), POINTER :: zfse3t, zfse3u, zfse3v, zfse3w
+      REAL(wp), DIMENSION(:,:,:), POINTER :: ze3t, ze3u, ze3v, ze3w
 
       NAMELIST/namcrs/ nn_factx, nn_facty, nn_binref, nn_msh_crs, nn_crs_kz, ln_crs_wn
@@ -187,15 +187,15 @@
      
      !
-     CALL wrk_alloc( jpi,jpj,jpk,   zfse3t, zfse3u, zfse3v, zfse3w )
-     !
-     zfse3t(:,:,:) = fse3t(:,:,:)
-     zfse3u(:,:,:) = fse3u(:,:,:)
-     zfse3v(:,:,:) = fse3v(:,:,:)
-     zfse3w(:,:,:) = fse3w(:,:,:)
+     CALL wrk_alloc( jpi,jpj,jpk,   ze3t, ze3u, ze3v, ze3w )
+     !
+     ze3t(:,:,:) = e3t_n(:,:,:)
+     ze3u(:,:,:) = e3u_n(:,:,:)
+     ze3v(:,:,:) = e3v_n(:,:,:)
+     ze3w(:,:,:) = e3w_n(:,:,:)
 
      !    3.d.2   Surfaces 
-     CALL crs_dom_sfc( tmask, 'W', e1e2w_crs, e1e2w_msk, p_e1=e1t, p_e2=e2t    )
-     CALL crs_dom_sfc( umask, 'U', e2e3u_crs, e2e3u_msk, p_e2=e2u, p_e3=zfse3u )
-     CALL crs_dom_sfc( vmask, 'V', e1e3v_crs, e1e3v_msk, p_e1=e1v, p_e3=zfse3v )
+     CALL crs_dom_sfc( tmask, 'W', e1e2w_crs, e1e2w_msk, p_e1=e1t, p_e2=e2t  )
+     CALL crs_dom_sfc( umask, 'U', e2e3u_crs, e2e3u_msk, p_e2=e2u, p_e3=ze3u )
+     CALL crs_dom_sfc( vmask, 'V', e1e3v_crs, e1e3v_msk, p_e1=e1v, p_e3=ze3v )
    
      facsurfu(:,:,:) = umask_crs(:,:,:) * e2e3u_msk(:,:,:) / e2e3u_crs(:,:,:)
@@ -204,8 +204,8 @@
      !    3.d.3   Vertical scale factors
      !
-     CALL crs_dom_e3( e1t, e2t, zfse3t, e1e2w_crs, 'T', tmask, e3t_crs, e3t_max_crs)
-     CALL crs_dom_e3( e1u, e2u, zfse3u, e2e3u_crs, 'U', umask, e3u_crs, e3u_max_crs)
-     CALL crs_dom_e3( e1v, e2v, zfse3v, e1e3v_crs, 'V', vmask, e3v_crs, e3v_max_crs)
-     CALL crs_dom_e3( e1t, e2t, zfse3w, e1e2w_crs, 'W', tmask, e3w_crs, e3w_max_crs)
+     CALL crs_dom_e3( e1t, e2t, ze3t, e1e2w_crs, 'T', tmask, e3t_crs, e3t_max_crs)
+     CALL crs_dom_e3( e1u, e2u, ze3u, e2e3u_crs, 'U', umask, e3u_crs, e3u_max_crs)
+     CALL crs_dom_e3( e1v, e2v, ze3v, e1e3v_crs, 'V', vmask, e3v_crs, e3v_max_crs)
+     CALL crs_dom_e3( e1t, e2t, ze3w, e1e2w_crs, 'W', tmask, e3w_crs, e3w_max_crs)
 
      ! Replace 0 by e3t_0 or e3w_0
@@ -222,6 +222,6 @@
 
      !    3.d.3   Vertical depth (meters)
-     CALL crs_dom_ope( gdept_0, 'MAX', 'T', tmask, gdept_crs, p_e3=zfse3t, psgn=1.0 ) 
-     CALL crs_dom_ope( gdepw_0, 'MAX', 'W', tmask, gdepw_crs, p_e3=zfse3w, psgn=1.0 )
+     CALL crs_dom_ope( gdept_0, 'MAX', 'T', tmask, gdept_crs, p_e3=ze3t, psgn=1.0 ) 
+     CALL crs_dom_ope( gdepw_0, 'MAX', 'W', tmask, gdepw_crs, p_e3=ze3w, psgn=1.0 )
 
 
@@ -230,5 +230,5 @@
      !---------------------------------------------------------
      ! 4.a. Ocean volume or area unmasked and masked
-     CALL crs_dom_facvol( tmask, 'T', e1t, e2t, zfse3t, ocean_volume_crs_t, facvol_t )
+     CALL crs_dom_facvol( tmask, 'T', e1t, e2t, ze3t, ocean_volume_crs_t, facvol_t )
      !
      bt_crs(:,:,:) = ocean_volume_crs_t(:,:,:) * facvol_t(:,:,:)
@@ -237,5 +237,5 @@
      WHERE( bt_crs /= 0._wp ) r1_bt_crs(:,:,:) = 1._wp / bt_crs(:,:,:)
 
-     CALL crs_dom_facvol( tmask, 'W', e1t, e2t, zfse3w, ocean_volume_crs_w, facvol_w )
+     CALL crs_dom_facvol( tmask, 'W', e1t, e2t, ze3w, ocean_volume_crs_w, facvol_w )
      !
      !---------------------------------------------------------
@@ -252,5 +252,5 @@
       ! 7. Finish and clean-up
       !---------------------------------------------------------
-      CALL wrk_dealloc( jpi,jpj,jpk,   zfse3t, zfse3u, zfse3v, zfse3w )
+      CALL wrk_dealloc( jpi,jpj,jpk,   ze3t, ze3u, ze3v, ze3w )
       !
    END SUBROUTINE crs_init
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crslbclnk.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crslbclnk.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/CRS/crslbclnk.F90	(revision 6140)
@@ -1,4 +1,3 @@
 MODULE crslbclnk
-
    !!======================================================================
    !!                       ***  MODULE  crslbclnk  ***
@@ -7,12 +6,11 @@
    !!=====================================================================
    !! History :   ! 2012-06  (J. Simeon, G. Madec, C. Ethe, C. Calone)     Original code
-
+   !!----------------------------------------------------------------------
+   USE par_kind, ONLY: wp
    USE dom_oce
    USE crs
+   !
    USE lbclnk
-   USE par_kind, ONLY: wp
    USE in_out_manager
-
-   
    
    INTERFACE crs_lbc_lnk
@@ -22,5 +20,9 @@
    PUBLIC crs_lbc_lnk
    
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
    !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
 
@@ -35,33 +37,30 @@
       !!                Upon exiting, switch back to full domain indices.
       !!----------------------------------------------------------------------
-      !! Arguments
-      CHARACTER(len=1)                , INTENT(in   )           ::   cd_type1 ! grid type
-      REAL(wp)                        , INTENT(in   )           ::   psgn     ! control of the sign
-
-      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(inout)   ::   pt3d1 ! 3D array on which the lbc is applied
-      REAL(wp)                        , INTENT(in   ), OPTIONAL ::   pval     ! valeur sur les halo
-      CHARACTER(len=3)                , INTENT(in   ), OPTIONAL ::   cd_mpp    ! MPP only (here do nothing)
-      
-      !! local vairables
-      LOGICAL                                                   ::   ll_grid_crs
-      REAL(wp)                                                  ::   zval     ! valeur sur les halo
-
+      CHARACTER(len=1)                        , INTENT(in   ) ::   cd_type1 ! grid type
+      REAL(wp)                                , INTENT(in   ) ::   psgn     ! control of the sign
+      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(inout) ::   pt3d1    ! 3D array on which the lbc is applied
+      REAL(wp)                      , OPTIONAL, INTENT(in   ) ::   pval     ! valeur sur les halo
+      CHARACTER(len=3)              , OPTIONAL, INTENT(in   ) ::   cd_mpp   ! MPP only (here do nothing)
+      !
+      LOGICAL  ::   ll_grid_crs
+      REAL(wp) ::   zval   ! valeur sur les halo
       !!----------------------------------------------------------------------
-      
+      !
       ll_grid_crs = ( jpi == jpi_crs )
-      
+      !
       IF( PRESENT(pval) ) THEN  ;  zval = pval
-      ELSE                      ;  zval = 0.0
+      ELSE                      ;  zval = 0._wp
       ENDIF
-      
-      IF( .NOT. ll_grid_crs )   CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
-
+      !
+      IF( .NOT.ll_grid_crs )   CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
+      !
       IF( PRESENT( cd_mpp ) ) THEN ; CALL lbc_lnk( pt3d1, cd_type1, psgn, cd_mpp, pval=zval  )
       ELSE                         ; CALL lbc_lnk( pt3d1, cd_type1, psgn, pval=zval  )
       ENDIF
-
-      IF( .NOT. ll_grid_crs )   CALL dom_grid_glo   ! Return to parent grid domain
-
+      !
+      IF( .NOT.ll_grid_crs )   CALL dom_grid_glo   ! Return to parent grid domain
+      !
    END SUBROUTINE crs_lbc_lnk_3d
+   
    
    SUBROUTINE crs_lbc_lnk_3d_gather( pt3d1, cd_type1, pt3d2, cd_type2, psgn )
@@ -75,22 +74,19 @@
       !!                Upon exiting, switch back to full domain indices.
       !!----------------------------------------------------------------------
-      !! Arguments
-      CHARACTER(len=1)                , INTENT(in   )           ::   cd_type1,cd_type2 ! grid type
-      REAL(wp)                        , INTENT(in   )           ::   psgn     ! control of the sign
-
-      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(inout)   ::   pt3d1,pt3d2 ! 3D array on which the lbc is applied
-      
-      !! local vairables
-      LOGICAL                                                   ::   ll_grid_crs
+      CHARACTER(len=1)                        , INTENT(in   ) ::   cd_type1, cd_type2 ! grid type
+      REAL(wp)                                , INTENT(in   ) ::   psgn               ! control of the sign
+      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(inout) ::   pt3d1   , pt3d2    ! 3D array on which the lbc is applied
+      !
+      LOGICAL ::   ll_grid_crs
       !!----------------------------------------------------------------------
-      
+      !
       ll_grid_crs = ( jpi == jpi_crs )
-      
-      IF( .NOT. ll_grid_crs )   CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
-
+      !
+      IF( .NOT.ll_grid_crs )   CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
+      !
       CALL lbc_lnk( pt3d1, cd_type1, pt3d2, cd_type2, psgn  )
-
-      IF( .NOT. ll_grid_crs )   CALL dom_grid_glo   ! Return to parent grid domain
-
+      !
+      IF( .NOT.ll_grid_crs )   CALL dom_grid_glo   ! Return to parent grid domain
+      !
    END SUBROUTINE crs_lbc_lnk_3d_gather
 
@@ -107,34 +103,30 @@
       !!                Upon exiting, switch back to full domain indices.
       !!----------------------------------------------------------------------
-      !! Arguments
-      CHARACTER(len=1)                , INTENT(in   )           ::   cd_type  ! grid type
-      REAL(wp)                        , INTENT(in   )           ::   psgn     ! control of the sign
-
-      REAL(wp), DIMENSION(jpi_crs,jpj_crs),     INTENT(inout)   ::   pt2d     ! 2D array on which the lbc is applied
-      REAL(wp)                        , INTENT(in   ), OPTIONAL ::   pval     ! valeur sur les halo
-      CHARACTER(len=3)                , INTENT(in   ), OPTIONAL ::   cd_mpp   ! MPP only (here do nothing)
-      !! local variables
-      
-      LOGICAL                                                   ::   ll_grid_crs
-      REAL(wp)                                                  ::   zval     ! valeur sur les halo
-
+      CHARACTER(len=1)                    , INTENT(in   ) ::   cd_type  ! grid type
+      REAL(wp)                            , INTENT(in   ) ::   psgn     ! control of the sign
+      REAL(wp), DIMENSION(jpi_crs,jpj_crs), INTENT(inout) ::   pt2d     ! 2D array on which the lbc is applied
+      REAL(wp)                  , OPTIONAL, INTENT(in   ) ::   pval     ! valeur sur les halo
+      CHARACTER(len=3)          , OPTIONAL, INTENT(in   ) ::   cd_mpp   ! MPP only (here do nothing)
+      !      
+      LOGICAL  ::   ll_grid_crs
+      REAL(wp) ::   zval     ! valeur sur les halo
       !!----------------------------------------------------------------------
-      
+      !
       ll_grid_crs = ( jpi == jpi_crs )
-      
+      !
       IF( PRESENT(pval) ) THEN  ;  zval = pval
-      ELSE                      ;  zval = 0.0
+      ELSE                      ;  zval = 0._wp
       ENDIF
-      
-      IF( .NOT. ll_grid_crs )   CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
-
+      !
+      IF( .NOT.ll_grid_crs )   CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
+      !
       IF( PRESENT( cd_mpp ) ) THEN ; CALL lbc_lnk( pt2d, cd_type, psgn, cd_mpp, pval=zval  )
       ELSE                         ; CALL lbc_lnk( pt2d, cd_type, psgn, pval=zval  )
       ENDIF
-
-      IF( .NOT. ll_grid_crs )   CALL dom_grid_glo   ! Return to parent grid domain
-
+      !
+      IF( .NOT.ll_grid_crs )   CALL dom_grid_glo   ! Return to parent grid domain
+      !
    END SUBROUTINE crs_lbc_lnk_2d
 
-
+   !!======================================================================
 END MODULE crslbclnk
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90	(revision 6140)
@@ -0,0 +1,326 @@
+MODULE dia25h 
+   !!======================================================================
+   !!                       ***  MODULE  diaharm  ***
+   !! Harmonic analysis of tidal constituents 
+   !!======================================================================
+   !! History :  3.6  !  2014  (E O'Dea)  Original code
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O units
+   USE iom             ! I/0 library
+   USE wrk_nemo        ! working arrays
+#if defined key_zdftke 
+   USE zdf_oce, ONLY: en
+#endif
+   USE zdf_oce, ONLY: avt, avm
+#if defined key_zdfgls
+   USE zdf_oce, ONLY: en
+   USE zdfgls, ONLY: mxln
+#endif
+
+   IMPLICIT NONE
+   PRIVATE
+
+   LOGICAL , PUBLIC ::   ln_dia25h     !:  25h mean output
+   PUBLIC   dia_25h_init               ! routine called by nemogcm.F90
+   PUBLIC   dia_25h                    ! routine called by diawri.F90
+
+  !! * variables for calculating 25-hourly means
+   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   tn_25h  , sn_25h
+   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:)   ::   sshn_25h 
+   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   un_25h  , vn_25h  , wn_25h
+   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   avt_25h , avm_25h
+#if defined key_zdfgls || key_zdftke
+   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   en_25h
+#endif
+#if defined key_zdfgls 
+   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   rmxln_25h
+#endif
+   INTEGER, SAVE :: cnt_25h     ! Counter for 25 hour means
+
+
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.6 , NEMO Consortium (2014)
+   !! $Id:$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE dia_25h_init 
+      !!---------------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_25h_init  ***
+      !!     
+      !! ** Purpose: Initialization of 25h mean namelist 
+      !!        
+      !! ** Method : Read namelist
+      !!   History
+      !!   3.6  !  08-14  (E. O'Dea) Routine to initialize dia_25h
+      !!---------------------------------------------------------------------------
+      !!
+      INTEGER ::   ios                 ! Local integer output status for namelist read
+      INTEGER ::   ierror              ! Local integer for memory allocation
+      !
+      NAMELIST/nam_dia25h/ ln_dia25h
+      !!----------------------------------------------------------------------
+      !
+      REWIND ( numnam_ref )              ! Read Namelist nam_dia25h in reference namelist : 25hour mean diagnostics
+      READ   ( numnam_ref, nam_dia25h, IOSTAT=ios, ERR= 901 )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_dia25h in reference namelist', lwp )
+
+      REWIND( numnam_cfg )              ! Namelist nam_dia25h in configuration namelist  25hour diagnostics
+      READ  ( numnam_cfg, nam_dia25h, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_dia25h in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, nam_dia25h )
+
+      IF(lwp) THEN                   ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'dia_25h_init : Output 25 hour mean diagnostics'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) 'Namelist nam_dia25h : set 25h outputs '
+         WRITE(numout,*) 'Switch for 25h diagnostics (T) or not (F)  ln_dia25h  = ', ln_dia25h
+      ENDIF
+      IF( .NOT. ln_dia25h )   RETURN
+      ! ------------------- !
+      ! 1 - Allocate memory !
+      ! ------------------- !
+      ALLOCATE( tn_25h(jpi,jpj,jpk), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate tn_25h' )   ;   RETURN
+      ENDIF
+      ALLOCATE( sn_25h(jpi,jpj,jpk), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate sn_25h' )   ;   RETURN
+      ENDIF
+      ALLOCATE( un_25h(jpi,jpj,jpk), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate un_25h' )   ;   RETURN
+      ENDIF
+      ALLOCATE( vn_25h(jpi,jpj,jpk), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate vn_25h' )   ;   RETURN
+      ENDIF
+      ALLOCATE( wn_25h(jpi,jpj,jpk), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate wn_25h' )   ;   RETURN
+      ENDIF
+      ALLOCATE( avt_25h(jpi,jpj,jpk), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate avt_25h' )   ;   RETURN
+      ENDIF
+      ALLOCATE( avm_25h(jpi,jpj,jpk), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate avm_25h' )   ;   RETURN
+      ENDIF
+# if defined key_zdfgls || defined key_zdftke
+      ALLOCATE( en_25h(jpi,jpj,jpk), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate en_25h' )   ;   RETURN
+      ENDIF
+#endif
+# if defined key_zdfgls 
+      ALLOCATE( rmxln_25h(jpi,jpj,jpk), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate rmxln_25h' )   ;   RETURN
+      ENDIF
+#endif
+      ALLOCATE( sshn_25h(jpi,jpj), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate sshn_25h' )   ;   RETURN
+      ENDIF
+      ! ------------------------- !
+      ! 2 - Assign Initial Values !
+      ! ------------------------- !
+      cnt_25h = 1  ! sets the first value of sum at timestep 1 (note - should strictly be at timestep zero so before values used where possible) 
+      tn_25h(:,:,:) = tsb(:,:,:,jp_tem)
+      sn_25h(:,:,:) = tsb(:,:,:,jp_sal)
+      sshn_25h(:,:) = sshb(:,:)
+      un_25h(:,:,:) = ub(:,:,:)
+      vn_25h(:,:,:) = vb(:,:,:)
+      wn_25h(:,:,:) = wn(:,:,:)
+      avt_25h(:,:,:) = avt(:,:,:)
+      avm_25h(:,:,:) = avm(:,:,:)
+# if defined key_zdfgls || defined key_zdftke
+         en_25h(:,:,:) = en(:,:,:)
+#endif
+# if defined key_zdfgls
+         rmxln_25h(:,:,:) = mxln(:,:,:)
+#endif
+#if defined key_lim3 || defined key_lim2
+         CALL ctl_stop('STOP', 'dia_25h not setup yet to do tidemean ice')
+#endif 
+
+      ! -------------------------- !
+      ! 3 - Return to dia_wri      !
+      ! -------------------------- !
+
+
+   END SUBROUTINE dia_25h_init
+
+
+   SUBROUTINE dia_25h( kt )  
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE dia_25h  ***
+      !!         
+      !!
+      !!--------------------------------------------------------------------
+      !!                   
+      !! ** Purpose :   Write diagnostics with M2/S2 tide removed
+      !!
+      !! ** Method  :   
+      !!      25hr mean outputs for shelf seas
+      !!
+      !! History :
+      !!   ?.0  !  07-04  (A. Hines) New routine, developed from dia_wri_foam
+      !!   3.4  !  02-13  (J. Siddorn) Routine taken from old dia_wri_foam
+      !!   3.6  !  08-14  (E. O'Dea) adapted for VN3.6
+      !!----------------------------------------------------------------------
+      !! * Modules used
+
+      IMPLICIT NONE
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk
+
+      LOGICAL ::   ll_print = .FALSE.    ! =T print and flush numout
+      REAL(wp)                         ::   zsto, zout, zmax, zjulian, zmdi       ! temporary reals
+      INTEGER                          ::   i_steps                               ! no of timesteps per hour
+      REAL(wp), DIMENSION(jpi,jpj    ) ::   zw2d, un_dm, vn_dm                    ! temporary workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zw3d                                  ! temporary workspace
+      REAL(wp), DIMENSION(jpi,jpj,3)   ::   zwtmb                                 ! temporary workspace
+      INTEGER                          ::   iyear0, nimonth0,iday0                ! start year,imonth,day
+
+      !!----------------------------------------------------------------------
+
+      ! 0. Initialisation
+      ! -----------------
+      ! Define frequency of summing to create 25 h mean
+      IF( MOD( 3600,INT(rdt) ) == 0 ) THEN
+         i_steps = 3600/INT(rdt)
+      ELSE
+         CALL ctl_stop('STOP', 'dia_wri_tide: timestep must give MOD(3600,rdt) = 0 otherwise no hourly values are possible')
+      ENDIF
+
+#if defined key_lim3 || defined key_lim2
+      CALL ctl_stop('STOP', 'dia_wri_tide not setup yet to do tidemean ice')
+#endif
+
+      ! local variable for debugging
+      ll_print = ll_print .AND. lwp
+
+      ! Sum of 25 hourly instantaneous values to give a 25h mean from 24hours
+      ! every day
+      IF( MOD( kt, i_steps ) == 0  .and. kt .ne. nn_it000 ) THEN
+
+         IF (lwp) THEN
+              WRITE(numout,*) 'dia_wri_tide : Summing instantaneous hourly diagnostics at timestep ',kt
+              WRITE(numout,*) '~~~~~~~~~~~~ '
+         ENDIF
+
+         tn_25h(:,:,:)        = tn_25h(:,:,:) + tsn(:,:,:,jp_tem)
+         sn_25h(:,:,:)        = sn_25h(:,:,:) + tsn(:,:,:,jp_sal)
+         sshn_25h(:,:)        = sshn_25h(:,:) + sshn (:,:)
+         un_25h(:,:,:)        = un_25h(:,:,:) + un(:,:,:)
+         vn_25h(:,:,:)        = vn_25h(:,:,:) + vn(:,:,:)
+         wn_25h(:,:,:)        = wn_25h(:,:,:) + wn(:,:,:)
+         avt_25h(:,:,:)       = avt_25h(:,:,:) + avt(:,:,:)
+         avm_25h(:,:,:)       = avm_25h(:,:,:) + avm(:,:,:)
+# if defined key_zdfgls || defined key_zdftke
+         en_25h(:,:,:)        = en_25h(:,:,:) + en(:,:,:)
+#endif
+# if defined key_zdfgls
+         rmxln_25h(:,:,:)      = rmxln_25h(:,:,:) + mxln(:,:,:)
+#endif
+         cnt_25h = cnt_25h + 1
+
+         IF (lwp) THEN
+            WRITE(numout,*) 'dia_tide : Summed the following number of hourly values so far',cnt_25h
+         ENDIF
+
+      ENDIF ! MOD( kt, i_steps ) == 0
+
+         ! Write data for 25 hour mean output streams
+      IF( cnt_25h .EQ. 25 .AND.  MOD( kt, i_steps*24) == 0 .AND. kt .NE. nn_it000 ) THEN
+
+            IF(lwp) THEN
+               WRITE(numout,*) 'dia_wri_tide : Writing 25 hour mean tide diagnostics at timestep', kt
+               WRITE(numout,*) '~~~~~~~~~~~~ '
+            ENDIF
+
+            tn_25h(:,:,:)        = tn_25h(:,:,:) / 25.0_wp
+            sn_25h(:,:,:)        = sn_25h(:,:,:) / 25.0_wp
+            sshn_25h(:,:)        = sshn_25h(:,:) / 25.0_wp
+            un_25h(:,:,:)        = un_25h(:,:,:) / 25.0_wp
+            vn_25h(:,:,:)        = vn_25h(:,:,:) / 25.0_wp
+            wn_25h(:,:,:)        = wn_25h(:,:,:) / 25.0_wp
+            avt_25h(:,:,:)       = avt_25h(:,:,:) / 25.0_wp
+            avm_25h(:,:,:)       = avm_25h(:,:,:) / 25.0_wp
+# if defined key_zdfgls || defined key_zdftke
+            en_25h(:,:,:)        = en_25h(:,:,:) / 25.0_wp
+#endif
+# if defined key_zdfgls
+            rmxln_25h(:,:,:)       = rmxln_25h(:,:,:) / 25.0_wp
+#endif
+
+            IF (lwp)  WRITE(numout,*) 'dia_wri_tide : Mean calculated by dividing 25 hour sums and writing output'
+            zmdi=1.e+20 !missing data indicator for masking
+            ! write tracers (instantaneous)
+            zw3d(:,:,:) = tn_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+            CALL iom_put("temper25h", zw3d)   ! potential temperature
+            zw3d(:,:,:) = sn_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+            CALL iom_put( "salin25h", zw3d  )   ! salinity
+            zw2d(:,:) = sshn_25h(:,:)*tmask(:,:,1) + zmdi*(1.0-tmask(:,:,1))
+            CALL iom_put( "ssh25h", zw2d )   ! sea surface 
+
+
+            ! Write velocities (instantaneous)
+            zw3d(:,:,:) = un_25h(:,:,:)*umask(:,:,:) + zmdi*(1.0-umask(:,:,:))
+            CALL iom_put("vozocrtx25h", zw3d)    ! i-current
+            zw3d(:,:,:) = vn_25h(:,:,:)*vmask(:,:,:) + zmdi*(1.0-vmask(:,:,:))
+            CALL iom_put("vomecrty25h", zw3d  )   ! j-current
+
+            zw3d(:,:,:) = wn_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+            CALL iom_put("vomecrtz25h", zw3d )   ! k-current
+            zw3d(:,:,:) = avt_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+            CALL iom_put("avt25h", zw3d )   ! diffusivity
+            zw3d(:,:,:) = avm_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+            CALL iom_put("avm25h", zw3d)   ! viscosity
+#if defined key_zdftke || defined key_zdfgls 
+            zw3d(:,:,:) = en_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+            CALL iom_put("tke25h", zw3d)   ! tke
+#endif
+#if defined key_zdfgls 
+            zw3d(:,:,:) = rmxln_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+            CALL iom_put( "mxln25h",zw3d)
+#endif
+
+            ! After the write reset the values to cnt=1 and sum values equal current value 
+            tn_25h(:,:,:) = tsn(:,:,:,jp_tem)
+            sn_25h(:,:,:) = tsn(:,:,:,jp_sal)
+            sshn_25h(:,:) = sshn (:,:)
+            un_25h(:,:,:) = un(:,:,:)
+            vn_25h(:,:,:) = vn(:,:,:)
+            wn_25h(:,:,:) = wn(:,:,:)
+            avt_25h(:,:,:) = avt(:,:,:)
+            avm_25h(:,:,:) = avm(:,:,:)
+# if defined key_zdfgls || defined key_zdftke
+            en_25h(:,:,:) = en(:,:,:)
+#endif
+# if defined key_zdfgls
+            rmxln_25h(:,:,:) = mxln(:,:,:)
+#endif
+            cnt_25h = 1
+            IF (lwp)  WRITE(numout,*) 'dia_wri_tide : After 25hr mean write, reset sum to current value and cnt_25h to one for overlapping average',cnt_25h
+
+      ENDIF !  cnt_25h .EQ. 25 .AND.  MOD( kt, i_steps * 24) == 0 .AND. kt .NE. nn_it000
+
+
+   END SUBROUTINE dia_25h 
+
+   !!======================================================================
+END MODULE dia25h
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90	(revision 6140)
@@ -40,6 +40,4 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   sn0          ! initial salinity
       
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -99,12 +97,12 @@
       ztsn(:,:,:,jp_tem) = tsn(:,:,:,jp_tem)                    ! thermosteric ssh
       ztsn(:,:,:,jp_sal) = sn0(:,:,:)
-      CALL eos( ztsn, zrhd, fsdept_n(:,:,:) )                       ! now in situ density using initial salinity
+      CALL eos( ztsn, zrhd, gdept_n(:,:,:) )                       ! now in situ density using initial salinity
       !
       zbotpres(:,:) = 0._wp                        ! no atmospheric surface pressure, levitating sea-ice
       DO jk = 1, jpkm1
-         zbotpres(:,:) = zbotpres(:,:) + fse3t(:,:,jk) * zrhd(:,:,jk)
-      END DO
-      IF( .NOT.lk_vvl ) THEN
-         IF ( ln_isfcav ) THEN
+         zbotpres(:,:) = zbotpres(:,:) + e3t_n(:,:,jk) * zrhd(:,:,jk)
+      END DO
+      IF( ln_linssh ) THEN
+         IF( ln_isfcav ) THEN
             DO ji=1,jpi
                DO jj=1,jpj
@@ -115,4 +113,7 @@
             zbotpres(:,:) = zbotpres(:,:) + sshn(:,:) * zrhd(:,:,1)
          END IF
+!!gm
+!!gm   riceload should be added in both ln_linssh=T or F, no?
+!!gm
       END IF
       !                                         
@@ -123,5 +124,5 @@
       
       !                                         ! steric sea surface height
-      CALL eos( tsn, zrhd, zrhop, fsdept_n(:,:,:) )                 ! now in situ and potential density
+      CALL eos( tsn, zrhd, zrhop, gdept_n(:,:,:) )                 ! now in situ and potential density
       zrhop(:,:,jpk) = 0._wp
       CALL iom_put( 'rhop', zrhop )
@@ -129,7 +130,7 @@
       zbotpres(:,:) = 0._wp                        ! no atmospheric surface pressure, levitating sea-ice
       DO jk = 1, jpkm1
-         zbotpres(:,:) = zbotpres(:,:) + fse3t(:,:,jk) * zrhd(:,:,jk)
-      END DO
-      IF( .NOT.lk_vvl ) THEN
+         zbotpres(:,:) = zbotpres(:,:) + e3t_n(:,:,jk) * zrhd(:,:,jk)
+      END DO
+      IF( ln_linssh ) THEN
          IF ( ln_isfcav ) THEN
             DO ji=1,jpi
@@ -159,5 +160,5 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               zztmp = area(ji,jj) * fse3t(ji,jj,jk)
+               zztmp = area(ji,jj) * e3t_n(ji,jj,jk)
                ztemp = ztemp + zztmp * tsn(ji,jj,jk,jp_tem)
                zsal  = zsal  + zztmp * tsn(ji,jj,jk,jp_sal)
@@ -165,6 +166,6 @@
          END DO
       END DO
-      IF( .NOT.lk_vvl ) THEN
-         IF ( ln_isfcav ) THEN
+      IF( ln_linssh ) THEN
+         IF( ln_isfcav ) THEN
             DO ji=1,jpi
                DO jj=1,jpj
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diacfl.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diacfl.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diacfl.F90	(revision 6140)
@@ -0,0 +1,206 @@
+MODULE diacfl
+   !!==============================================================================
+   !!                       ***  MODULE  diacfl  ***
+   !! Output CFL diagnostics to ascii file
+   !!==============================================================================
+   !! History :  1.0  !  2010-03  (E. Blockley)  Original code
+   !!                 !  2014-06  (T Graham) Removed CPP key & Updated to vn3.6
+   !! 
+   !!----------------------------------------------------------------------
+   !!   dia_cfl        : Compute and output Courant numbers at each timestep
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and active tracers
+   USE dom_oce         ! ocean space and time domain
+   USE lib_mpp         ! distribued memory computing
+   USE lbclnk          ! ocean lateral boundary condition (or mpp link)
+   USE in_out_manager  ! I/O manager
+   USE domvvl     
+   USE timing          ! Performance output
+
+   IMPLICIT NONE
+   PRIVATE
+
+   REAL(wp) :: cu_max, cv_max, cw_max                      ! Run max U Courant number 
+   INTEGER, DIMENSION(3) :: cu_loc, cv_loc, cw_loc         ! Run max locations
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: zcu_cfl           ! Courant number arrays
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: zcv_cfl           ! Courant number arrays
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: zcw_cfl           ! Courant number arrays
+
+   INTEGER  :: numcfl                                       ! outfile unit
+   CHARACTER(LEN=50) :: clname="cfl_diagnostics.ascii"      ! ascii filename
+
+   PUBLIC   dia_cfl       ! routine called by step.F90
+   PUBLIC   dia_cfl_init  ! routine called by nemogcm
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.2 , LOCEAN-IPSL (2009) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+
+CONTAINS
+
+
+   SUBROUTINE dia_cfl ( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_cfl  ***
+      !!
+      !! ** Purpose :  Compute the Courant numbers Cu=u*dt/dx and Cv=v*dt/dy
+      !!               and output to ascii file 'cfl_diagnostics.ascii'
+      !!----------------------------------------------------------------------
+
+      INTEGER, INTENT(in) ::  kt                            ! ocean time-step index
+
+      REAL(wp) :: zcu_max, zcv_max, zcw_max                 ! max Courant numbers per timestep
+      INTEGER, DIMENSION(3) :: zcu_loc, zcv_loc, zcw_loc    ! max Courant number locations
+
+      REAL(wp) :: dt                                        ! temporary scalars
+      INTEGER, DIMENSION(3) :: zlocu, zlocv, zlocw          ! temporary arrays 
+      INTEGER  :: ji, jj, jk                                ! dummy loop indices
+
+      
+      IF( nn_diacfl == 1) THEN
+         IF( nn_timing == 1 )   CALL timing_start('dia_cfl')
+         ! setup timestep multiplier to account for initial Eulerian timestep
+         IF( neuler == 0 .AND. kt == nit000 ) THEN   ;    dt = rdt
+         ELSE                                        ;    dt = rdt * 2.0
+         ENDIF
+
+             ! calculate Courant numbers
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, fs_jpim1   ! vector opt.
+
+                  ! Courant number for x-direction (zonal current)
+                  zcu_cfl(ji,jj,jk) = ABS(un(ji,jj,jk))*dt/e1u(ji,jj)
+
+                  ! Courant number for y-direction (meridional current)
+                  zcv_cfl(ji,jj,jk) = ABS(vn(ji,jj,jk))*dt/e2v(ji,jj)
+
+                  ! Courant number for z-direction (vertical current)
+                  zcw_cfl(ji,jj,jk) = ABS(wn(ji,jj,jk))*dt/e3w_n(ji,jj,jk)
+               END DO
+            END DO         
+         END DO
+
+         ! calculate maximum values and locations
+         IF( lk_mpp ) THEN
+            CALL mpp_maxloc(zcu_cfl,umask,zcu_max, zcu_loc(1), zcu_loc(2), zcu_loc(3))
+            CALL mpp_maxloc(zcv_cfl,vmask,zcv_max, zcv_loc(1), zcv_loc(2), zcv_loc(3))
+            CALL mpp_maxloc(zcw_cfl,tmask,zcw_max, zcw_loc(1), zcw_loc(2), zcw_loc(3))
+         ELSE
+            zlocu = MAXLOC( ABS( zcu_cfl(:,:,:) ) )
+            zcu_loc(1) = zlocu(1) + nimpp - 1
+            zcu_loc(2) = zlocu(2) + njmpp - 1
+            zcu_loc(3) = zlocu(3)
+            zcu_max = zcu_cfl(zcu_loc(1),zcu_loc(2),zcu_loc(3))
+
+            zlocv = MAXLOC( ABS( zcv_cfl(:,:,:) ) )
+            zcv_loc(1) = zlocv(1) + nimpp - 1
+            zcv_loc(2) = zlocv(2) + njmpp - 1
+            zcv_loc(3) = zlocv(3)
+            zcv_max = zcv_cfl(zcv_loc(1),zcv_loc(2),zcv_loc(3))
+
+            zlocw = MAXLOC( ABS( zcw_cfl(:,:,:) ) )
+            zcw_loc(1) = zlocw(1) + nimpp - 1
+            zcw_loc(2) = zlocw(2) + njmpp - 1
+            zcw_loc(3) = zlocw(3)
+            zcw_max = zcw_cfl(zcw_loc(1),zcw_loc(2),zcw_loc(3))
+         ENDIF
+      
+         ! write out to file
+         IF( lwp ) THEN
+            WRITE(numcfl,FMT='(2x,i4,5x,a6,5x,f6.4,1x,i4,1x,i4,1x,i4)') kt, 'Max Cu', zcu_max, zcu_loc(1), zcu_loc(2), zcu_loc(3)
+            WRITE(numcfl,FMT='(11x,a6,5x,f6.4,1x,i4,1x,i4,1x,i4)') 'Max Cv', zcv_max, zcv_loc(1), zcv_loc(2), zcv_loc(3)
+            WRITE(numcfl,FMT='(11x,a6,5x,f6.4,1x,i4,1x,i4,1x,i4)') 'Max Cw', zcw_max, zcw_loc(1), zcw_loc(2), zcw_loc(3)
+         ENDIF
+
+         ! update maximum Courant numbers from whole run if applicable
+         IF( zcu_max > cu_max ) THEN
+            cu_max = zcu_max
+            cu_loc = zcu_loc
+         ENDIF
+         IF( zcv_max > cv_max ) THEN
+            cv_max = zcv_max
+            cv_loc = zcv_loc
+         ENDIF
+         IF( zcw_max > cw_max ) THEN
+            cw_max = zcw_max
+            cw_loc = zcw_loc
+         ENDIF
+
+         ! at end of run output max Cu and Cv and close ascii file
+         IF( kt == nitend .AND. lwp ) THEN
+            ! to ascii file
+            WRITE(numcfl,*) '******************************************'
+            WRITE(numcfl,FMT='(3x,a12,7x,f6.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cu', cu_max, cu_loc(1), cu_loc(2), cu_loc(3)
+            WRITE(numcfl,FMT='(3x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cu_max)
+            WRITE(numcfl,*) '******************************************'
+            WRITE(numcfl,FMT='(3x,a12,7x,f6.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cv', cv_max, cv_loc(1), cv_loc(2), cv_loc(3)
+            WRITE(numcfl,FMT='(3x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cv_max)
+            WRITE(numcfl,*) '******************************************'
+            WRITE(numcfl,FMT='(3x,a12,7x,f6.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cw', cw_max, cw_loc(1), cw_loc(2), cw_loc(3)
+            WRITE(numcfl,FMT='(3x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cw_max)
+            CLOSE( numcfl ) 
+
+            ! to ocean output
+            WRITE(numout,*)
+            WRITE(numout,*) 'dia_cfl     : Maximum Courant number information for the run:'
+            WRITE(numout,*) '~~~~~~~~~~~~'
+            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cu', cu_max, 'at (i, j, k) = (', cu_loc(1), cu_loc(2), cu_loc(3), ')'
+            WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cu_max)
+            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cv', cv_max, 'at (i, j, k) = (', cv_loc(1), cv_loc(2), cv_loc(3), ')'
+            WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cv_max)
+            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cw', cw_max, 'at (i, j, k) = (', cw_loc(1), cw_loc(2), cw_loc(3), ')'
+            WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cw_max)
+
+         ENDIF
+
+         IF( nn_timing == 1 )   CALL timing_stop('dia_cfl')
+      ENDIF
+
+   END SUBROUTINE dia_cfl
+
+   SUBROUTINE dia_cfl_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_cfl_init  ***
+      !!                   
+      !! ** Purpose :   create output file, initialise arrays
+      !!----------------------------------------------------------------------
+
+
+      IF( nn_diacfl == 1 ) THEN
+         IF( nn_timing == 1 )   CALL timing_start('dia_cfl_init')
+
+         cu_max=0.0
+         cv_max=0.0
+         cw_max=0.0
+
+         ALLOCATE( zcu_cfl(jpi, jpj, jpk), zcv_cfl(jpi, jpj, jpk), zcw_cfl(jpi, jpj, jpk) )
+
+         zcu_cfl(:,:,:)=0.0
+         zcv_cfl(:,:,:)=0.0
+         zcw_cfl(:,:,:)=0.0
+
+         IF( lwp ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'dia_cfl     : Outputting CFL diagnostics to '//TRIM(clname)
+            WRITE(numout,*) '~~~~~~~~~~~~'
+            WRITE(numout,*)
+
+            ! create output ascii file
+            CALL ctl_opn( numcfl, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
+            WRITE(numcfl,*) 'Timestep  Direction  Max C     i    j    k'
+            WRITE(numcfl,*) '******************************************'
+         ENDIF
+
+         IF( nn_timing == 1 )   CALL timing_stop('dia_cfl_init')
+
+      ENDIF
+
+   END SUBROUTINE dia_cfl_init
+
+END MODULE diacfl
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90	(revision 6140)
@@ -1,118 +1,110 @@
 MODULE diadct
-  !!=====================================================================
-  !!                       ***  MODULE  diadct  ***
-  !! Ocean diagnostics: Compute the transport trough a sec.
-  !!===============================================================
-  !! History : 
-  !!
-  !!         original  : 02/99 (Y Drillet)
-  !!         addition  : 10/01 (Y Drillet, R Bourdalle Badie)
-  !!                   : 10/05 (M Laborie) F90
-  !!         addition  : 04/07 (G Garric) Ice sections
-  !!         bugfix    : 04/07 (C Bricaud) test on sec%nb_point
-  !!                                      initialisation of ztransp1,ztransp2,...
-  !!         nemo_v_3_4: 09/2011 (C Bricaud)
-  !!
-  !!
-  !!----------------------------------------------------------------------
+   !!======================================================================
+   !!                       ***  MODULE  diadct  ***
+   !! Ocean diagnostics: Compute the transport trough a sec.
+   !!======================================================================
+   !! History :  OPA  ! 02/1999 (Y Drillet)  original code
+   !!                 ! 10/2001 (Y Drillet, R Bourdalle Badie)
+   !!   NEMO     1.0  ! 10/2005 (M Laborie) F90
+   !!            3.0  ! 04/2007 (G Garric) Ice sections
+   !!             -   ! 04/2007 (C Bricaud) test on sec%nb_point, initialisation of ztransp1,ztransp2,...
+   !!            3.4  ! 09/2011 (C Bricaud)
+   !!----------------------------------------------------------------------
 #if defined key_diadct
-  !!----------------------------------------------------------------------
-  !!   'key_diadct' :
-  !!----------------------------------------------------------------------
-  !!----------------------------------------------------------------------
-  !!   dia_dct      :  Compute the transport through a sec.
-  !!   dia_dct_init :  Read namelist.
-  !!   readsec      :  Read sections description and pathway
-  !!   removepoints :  Remove points which are common to 2 procs
-  !!   transport    :  Compute transport for each sections
-  !!   dia_dct_wri  :  Write tranports results in ascii files
-  !!   interp       :  Compute temperature/salinity/density at U-point or V-point
-  !!   
-  !!----------------------------------------------------------------------
-  !! * Modules used
-  USE oce             ! ocean dynamics and tracers
-  USE dom_oce         ! ocean space and time domain
-  USE phycst          ! physical constants
-  USE in_out_manager  ! I/O manager
-  USE daymod          ! calendar
-  USE dianam          ! build name of file
-  USE lib_mpp         ! distributed memory computing library
+   !!----------------------------------------------------------------------
+   !!   'key_diadct' :
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   dia_dct      :  Compute the transport through a sec.
+   !!   dia_dct_init :  Read namelist.
+   !!   readsec      :  Read sections description and pathway
+   !!   removepoints :  Remove points which are common to 2 procs
+   !!   transport    :  Compute transport for each sections
+   !!   dia_dct_wri  :  Write tranports results in ascii files
+   !!   interp       :  Compute temperature/salinity/density at U-point or V-point
+   !!   
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE daymod          ! calendar
+   USE dianam          ! build name of file
+   USE lib_mpp         ! distributed memory computing library
 #if defined key_lim2
-  USE ice_2
+   USE ice_2
 #endif
 #if defined key_lim3
-  USE ice
+   USE ice
 #endif
-  USE domvvl
-  USE timing          ! preformance summary
-  USE wrk_nemo        ! working arrays
-
-  IMPLICIT NONE
-  PRIVATE
-
-  !! * Routine accessibility
-  PUBLIC   dia_dct      ! routine called by step.F90
-  PUBLIC   dia_dct_init ! routine called by opa.F90
-  PUBLIC   diadct_alloc ! routine called by nemo_init in nemogcm.F90 
-  PRIVATE  readsec
-  PRIVATE  removepoints
-  PRIVATE  transport
-  PRIVATE  dia_dct_wri
-
-#include "domzgr_substitute.h90"
-
-  !! * Shared module variables
-  LOGICAL, PUBLIC, PARAMETER ::   lk_diadct = .TRUE.   !: model-data diagnostics flag
-
-  !! * Module variables
-  INTEGER :: nn_dct        ! Frequency of computation
-  INTEGER :: nn_dctwri     ! Frequency of output
-  INTEGER :: nn_secdebug   ! Number of the section to debug
+   USE domvvl
+   USE timing          ! preformance summary
+   USE wrk_nemo        ! working arrays
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dia_dct      ! routine called by step.F90
+   PUBLIC   dia_dct_init ! routine called by opa.F90
+   PUBLIC   diadct_alloc ! routine called by nemo_init in nemogcm.F90 
+   PRIVATE  readsec
+   PRIVATE  removepoints
+   PRIVATE  transport
+   PRIVATE  dia_dct_wri
+
+   LOGICAL, PUBLIC, PARAMETER ::   lk_diadct = .TRUE.   !: model-data diagnostics flag
+
+   INTEGER :: nn_dct        ! Frequency of computation
+   INTEGER :: nn_dctwri     ! Frequency of output
+   INTEGER :: nn_secdebug   ! Number of the section to debug
    
-  INTEGER, PARAMETER :: nb_class_max  = 10
-  INTEGER, PARAMETER :: nb_sec_max    = 150
-  INTEGER, PARAMETER :: nb_point_max  = 2000
-  INTEGER, PARAMETER :: nb_type_class = 10
-  INTEGER, PARAMETER :: nb_3d_vars    = 3 
-  INTEGER, PARAMETER :: nb_2d_vars    = 2 
-  INTEGER            :: nb_sec 
-
-  TYPE POINT_SECTION
-     INTEGER :: I,J
-  END TYPE POINT_SECTION
-
-  TYPE COORD_SECTION
-     REAL(wp) :: lon,lat
-  END TYPE COORD_SECTION
-
-  TYPE SECTION
-     CHARACTER(len=60)                            :: name              ! name of the sec
-     LOGICAL                                      :: llstrpond         ! true if you want the computation of salt and
+   INTEGER, PARAMETER :: nb_class_max  = 10
+   INTEGER, PARAMETER :: nb_sec_max    = 150
+   INTEGER, PARAMETER :: nb_point_max  = 2000
+   INTEGER, PARAMETER :: nb_type_class = 10
+   INTEGER, PARAMETER :: nb_3d_vars    = 3 
+   INTEGER, PARAMETER :: nb_2d_vars    = 2 
+   INTEGER            :: nb_sec 
+
+   TYPE POINT_SECTION
+      INTEGER :: I,J
+   END TYPE POINT_SECTION
+
+   TYPE COORD_SECTION
+      REAL(wp) :: lon,lat
+   END TYPE COORD_SECTION
+
+   TYPE SECTION
+      CHARACTER(len=60)                            :: name              ! name of the sec
+      LOGICAL                                      :: llstrpond         ! true if you want the computation of salt and
                                                                        ! heat transports
-     LOGICAL                                      :: ll_ice_section    ! ice surface and ice volume computation
-     LOGICAL                                      :: ll_date_line      ! = T if the section crosses the date-line
-     TYPE(COORD_SECTION), DIMENSION(2)            :: coordSec          ! longitude and latitude of the extremities of the sec
-     INTEGER                                      :: nb_class          ! number of boundaries for density classes
-     INTEGER, DIMENSION(nb_point_max)             :: direction         ! vector direction of the point in the section
-     CHARACTER(len=40),DIMENSION(nb_class_max)    :: classname         ! characteristics of the class
-     REAL(wp), DIMENSION(nb_class_max)            :: zsigi           ,&! in-situ   density classes    (99 if you don't want)
-                                                     zsigp           ,&! potential density classes    (99 if you don't want)
-                                                     zsal            ,&! salinity classes   (99 if you don't want)
-                                                     ztem            ,&! temperature classes(99 if you don't want)
-                                                     zlay              ! level classes      (99 if you don't want)
-     REAL(wp), DIMENSION(nb_type_class,nb_class_max)  :: transport     ! transport output
-     REAL(wp)                                         :: slopeSection  ! slope of the section
-     INTEGER                                          :: nb_point      ! number of points in the section
-     TYPE(POINT_SECTION),DIMENSION(nb_point_max)      :: listPoint     ! list of points in the sections
-  END TYPE SECTION
-
-  TYPE(SECTION),DIMENSION(nb_sec_max) :: secs ! Array of sections
- 
-  REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::  transports_3d 
-  REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::  transports_2d  
-
+      LOGICAL                                      :: ll_ice_section    ! ice surface and ice volume computation
+      LOGICAL                                      :: ll_date_line      ! = T if the section crosses the date-line
+      TYPE(COORD_SECTION), DIMENSION(2)            :: coordSec          ! longitude and latitude of the extremities of the sec
+      INTEGER                                      :: nb_class          ! number of boundaries for density classes
+      INTEGER, DIMENSION(nb_point_max)             :: direction         ! vector direction of the point in the section
+      CHARACTER(len=40),DIMENSION(nb_class_max)    :: classname         ! characteristics of the class
+      REAL(wp), DIMENSION(nb_class_max)            :: zsigi           ,&! in-situ   density classes    (99 if you don't want)
+                                                      zsigp           ,&! potential density classes    (99 if you don't want)
+                                                      zsal            ,&! salinity classes   (99 if you don't want)
+                                                      ztem            ,&! temperature classes(99 if you don't want)
+                                                      zlay              ! level classes      (99 if you don't want)
+      REAL(wp), DIMENSION(nb_type_class,nb_class_max)  :: transport     ! transport output
+      REAL(wp)                                         :: slopeSection  ! slope of the section
+      INTEGER                                          :: nb_point      ! number of points in the section
+      TYPE(POINT_SECTION),DIMENSION(nb_point_max)      :: listPoint     ! list of points in the sections
+   END TYPE SECTION
+
+   TYPE(SECTION),DIMENSION(nb_sec_max) :: secs ! Array of sections
+ 
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::  transports_3d 
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::  transports_2d  
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
    !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
-
  
   INTEGER FUNCTION diadct_alloc() 
@@ -130,4 +122,5 @@
  
   END FUNCTION diadct_alloc 
+
 
   SUBROUTINE dia_dct_init
@@ -208,8 +201,6 @@
      !!               Reinitialise all relevant arrays to zero 
      !!---------------------------------------------------------------------
-     !! * Arguments
-     INTEGER,INTENT(IN)        ::kt
-
-     !! * Local variables
+     INTEGER,INTENT(in)        ::kt
+     !
      INTEGER             :: jsec,            &! loop on sections
                             itotal            ! nb_sec_max*nb_type_class*nb_class_max
@@ -220,6 +211,6 @@
      REAL(wp), POINTER, DIMENSION(:)    :: zwork !   "  
      REAL(wp), POINTER, DIMENSION(:,:,:):: zsum  !   "
-
      !!---------------------------------------------------------------------    
+     !
      IF( nn_timing == 1 )   CALL timing_start('dia_dct')
 
@@ -619,142 +610,140 @@
                             zumid_ice, zvmid_ice,                &!U/V ice velocity 
                             zTnorm                                !transport of velocity through one cell's sides 
-     REAL(wp)            :: ztn, zsn, zrhoi, zrhop, zsshn, zfsdep !temperature/salinity/potential density/ssh/depth at u/v point
+     REAL(wp)            :: ztn, zsn, zrhoi, zrhop, zsshn, zdep !temperature/salinity/potential density/ssh/depth at u/v point
 
      TYPE(POINT_SECTION) :: k
-     !!--------------------------------------------------------
-
-     IF( ld_debug )WRITE(numout,*)'      Compute transport'
-
-     !---------------------------!
-     !  COMPUTE TRANSPORT        !
-     !---------------------------!
-     IF(sec%nb_point .NE. 0)THEN   
-
-        !----------------------------------------------------------------------------------------------------
-        !Compute sign for velocities:
-        !
-        !convention:
-        !   non horizontal section: direction + is toward left hand of section
-        !       horizontal section: direction + is toward north of section
-        !
-        !
-        !       slopeSection < 0     slopeSection > 0       slopeSection=inf            slopeSection=0
-        !       ----------------      -----------------     ---------------             --------------
-        !
-        !   isgnv=1         direction +      
-        !  ______         _____             ______                                                   
-        !        |           //|            |                  |                         direction +   
-        !        | isgnu=1  // |            |isgnu=1           |isgnu=1                     /|\
-        !        |_______  //         ______|    \\            | ---\                        |
-        !               |             | isgnv=-1  \\ |         | ---/ direction +       ____________
-        !               |             |          __\\|         |                    
-        !               |             |     direction +        |                      isgnv=1                                 
-        !                                                      
-        !----------------------------------------------------------------------------------------------------
-        isgnu = 1
-        IF( sec%slopeSection .GT. 0 ) THEN  ; isgnv = -1 
-        ELSE                                ; isgnv =  1
-        ENDIF
-        IF( sec%slopeSection .GE. 9999. )     isgnv =  1
-
-        IF( ld_debug )write(numout,*)"sec%slopeSection isgnu isgnv ",sec%slopeSection,isgnu,isgnv
-
-        !--------------------------------------!
-        ! LOOP ON THE SEGMENT BETWEEN 2 NODES  !
-        !--------------------------------------!
-        DO jseg=1,MAX(sec%nb_point-1,0)
+      !!--------------------------------------------------------
+      !
+      IF( ld_debug )WRITE(numout,*)'      Compute transport'
+
+      !---------------------------!
+      !  COMPUTE TRANSPORT        !
+      !---------------------------!
+      IF(sec%nb_point .NE. 0)THEN   
+
+         !----------------------------------------------------------------------------------------------------
+         !Compute sign for velocities:
+         !
+         !convention:
+         !   non horizontal section: direction + is toward left hand of section
+         !       horizontal section: direction + is toward north of section
+         !
+         !
+         !       slopeSection < 0     slopeSection > 0       slopeSection=inf            slopeSection=0
+         !       ----------------      -----------------     ---------------             --------------
+         !
+         !   isgnv=1         direction +      
+         !  ______         _____             ______                                                   
+         !        |           //|            |                  |                         direction +   
+         !        | isgnu=1  // |            |isgnu=1           |isgnu=1                     /|\
+         !        |_______  //         ______|    \\            | ---\                        |
+         !               |             | isgnv=-1  \\ |         | ---/ direction +       ____________
+         !               |             |          __\\|         |                    
+         !               |             |     direction +        |                      isgnv=1                                 
+         !                                                      
+         !----------------------------------------------------------------------------------------------------
+         isgnu = 1
+         IF( sec%slopeSection .GT. 0 ) THEN  ; isgnv = -1 
+         ELSE                                ; isgnv =  1
+         ENDIF
+         IF( sec%slopeSection .GE. 9999. )     isgnv =  1
+
+         IF( ld_debug )write(numout,*)"sec%slopeSection isgnu isgnv ",sec%slopeSection,isgnu,isgnv
+
+         !--------------------------------------!
+         ! LOOP ON THE SEGMENT BETWEEN 2 NODES  !
+         !--------------------------------------!
+         DO jseg=1,MAX(sec%nb_point-1,0)
               
-           !-------------------------------------------------------------------------------------------
-           ! Select the appropriate coordinate for computing the velocity of the segment
-           !
-           !                      CASE(0)                                    Case (2)
-           !                      -------                                    --------
-           !  listPoint(jseg)                 listPoint(jseg+1)       listPoint(jseg)  F(i,j)      
-           !      F(i,j)----------V(i+1,j)-------F(i+1,j)                               |
-           !                                                                            |
-           !                                                                            |
-           !                                                                            |
-           !                      Case (3)                                            U(i,j)
-           !                      --------                                              |
-           !                                                                            |
-           !  listPoint(jseg+1) F(i,j+1)                                                |
-           !                        |                                                   |
-           !                        |                                                   |
-           !                        |                                 listPoint(jseg+1) F(i,j-1)
-           !                        |                                            
-           !                        |                                            
-           !                     U(i,j+1)                                            
-           !                        |                                       Case(1)     
-           !                        |                                       ------      
-           !                        |                                            
-           !                        |                 listPoint(jseg+1)             listPoint(jseg)                           
-           !                        |                 F(i-1,j)-----------V(i,j) -------f(jseg)                           
-           ! listPoint(jseg)     F(i,j)
-           ! 
-           !-------------------------------------------------------------------------------------------
-
-           SELECT CASE( sec%direction(jseg) )
-           CASE(0)  ;   k = sec%listPoint(jseg)
-           CASE(1)  ;   k = POINT_SECTION(sec%listPoint(jseg)%I+1,sec%listPoint(jseg)%J)
-           CASE(2)  ;   k = sec%listPoint(jseg)
-           CASE(3)  ;   k = POINT_SECTION(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J+1)
-           END SELECT
-
-           !---------------------------| 
-           !     LOOP ON THE LEVEL     | 
-           !---------------------------| 
-           !Sum of the transport on the vertical  
-           DO jk=1,mbathy(k%I,k%J) 
- 
-              ! compute temperature, salinity, insitu & potential density, ssh and depth at U/V point 
-              SELECT CASE( sec%direction(jseg) ) 
-              CASE(0,1) 
-                 ztn   = interp(k%I,k%J,jk,'V',tsn(:,:,:,jp_tem) ) 
-                 zsn   = interp(k%I,k%J,jk,'V',tsn(:,:,:,jp_sal) ) 
-                 zrhop = interp(k%I,k%J,jk,'V',rhop) 
-                 zrhoi = interp(k%I,k%J,jk,'V',rhd*rau0+rau0) 
-                 zsshn =  0.5*( sshn(k%I,k%J)    + sshn(k%I,k%J+1)    ) * vmask(k%I,k%J,1) 
-              CASE(2,3) 
-                 ztn   = interp(k%I,k%J,jk,'U',tsn(:,:,:,jp_tem) ) 
-                 zsn   = interp(k%I,k%J,jk,'U',tsn(:,:,:,jp_sal) ) 
-                 zrhop = interp(k%I,k%J,jk,'U',rhop) 
-                 zrhoi = interp(k%I,k%J,jk,'U',rhd*rau0+rau0) 
-                 zsshn =  0.5*( sshn(k%I,k%J)    + sshn(k%I+1,k%J)    ) * umask(k%I,k%J,1)  
-              END SELECT 
- 
-              zfsdep= fsdept(k%I,k%J,jk) 
+            !-------------------------------------------------------------------------------------------
+            ! Select the appropriate coordinate for computing the velocity of the segment
+            !
+            !                      CASE(0)                                    Case (2)
+            !                      -------                                    --------
+            !  listPoint(jseg)                 listPoint(jseg+1)       listPoint(jseg)  F(i,j)      
+            !      F(i,j)----------V(i+1,j)-------F(i+1,j)                               |
+            !                                                                            |
+            !                                                                            |
+            !                                                                            |
+            !                      Case (3)                                            U(i,j)
+            !                      --------                                              |
+            !                                                                            |
+            !  listPoint(jseg+1) F(i,j+1)                                                |
+            !                        |                                                   |
+            !                        |                                                   |
+            !                        |                                 listPoint(jseg+1) F(i,j-1)
+            !                        |                                            
+            !                        |                                            
+            !                     U(i,j+1)                                            
+            !                        |                                       Case(1)     
+            !                        |                                       ------      
+            !                        |                                            
+            !                        |                 listPoint(jseg+1)             listPoint(jseg)                           
+            !                        |                 F(i-1,j)-----------V(i,j) -------f(jseg)                           
+            ! listPoint(jseg)     F(i,j)
+            ! 
+            !-------------------------------------------------------------------------------------------
+
+            SELECT CASE( sec%direction(jseg) )
+            CASE(0)   ;    k = sec%listPoint(jseg)
+            CASE(1)   ;    k = POINT_SECTION(sec%listPoint(jseg)%I+1,sec%listPoint(jseg)%J)
+            CASE(2)   ;    k = sec%listPoint(jseg)
+            CASE(3)   ;    k = POINT_SECTION(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J+1)
+            END SELECT
+
+            !---------------------------| 
+            !     LOOP ON THE LEVEL     | 
+            !---------------------------| 
+            DO jk = 1, mbathy(k%I,k%J)            !Sum of the transport on the vertical
+            !           ! compute temperature, salinity, insitu & potential density, ssh and depth at U/V point 
+            SELECT CASE( sec%direction(jseg) )
+               CASE(0,1) 
+                  ztn   = interp(k%I,k%J,jk,'V',tsn(:,:,:,jp_tem) ) 
+                  zsn   = interp(k%I,k%J,jk,'V',tsn(:,:,:,jp_sal) ) 
+                  zrhop = interp(k%I,k%J,jk,'V',rhop) 
+                  zrhoi = interp(k%I,k%J,jk,'V',rhd*rau0+rau0) 
+                  zsshn =  0.5*( sshn(k%I,k%J) + sshn(k%I,k%J+1)    ) * vmask(k%I,k%J,1) 
+               CASE(2,3) 
+                  ztn   = interp(k%I,k%J,jk,'U',tsn(:,:,:,jp_tem) ) 
+                  zsn   = interp(k%I,k%J,jk,'U',tsn(:,:,:,jp_sal) ) 
+                  zrhop = interp(k%I,k%J,jk,'U',rhop) 
+                  zrhoi = interp(k%I,k%J,jk,'U',rhd*rau0+rau0) 
+                  zsshn =  0.5*( sshn(k%I,k%J) + sshn(k%I+1,k%J)    ) * umask(k%I,k%J,1)  
+               END SELECT 
+               !
+               zdep= gdept_n(k%I,k%J,jk) 
   
-              !compute velocity with the correct direction 
-              SELECT CASE( sec%direction(jseg) ) 
-              CASE(0,1)   
-                 zumid=0. 
-                 zvmid=isgnv*vn(k%I,k%J,jk)*vmask(k%I,k%J,jk) 
-              CASE(2,3) 
-                 zumid=isgnu*un(k%I,k%J,jk)*umask(k%I,k%J,jk) 
-                 zvmid=0. 
-              END SELECT 
- 
-              !zTnorm=transport through one cell; 
-              !velocity* cell's length * cell's thickness 
-              zTnorm=zumid*e2u(k%I,k%J)*  fse3u(k%I,k%J,jk)+     & 
-                     zvmid*e1v(k%I,k%J)*  fse3v(k%I,k%J,jk) 
-
-#if ! defined key_vvl
-              !add transport due to free surface 
-              IF( jk==1 )THEN 
-                 zTnorm = zTnorm + zumid* e2u(k%I,k%J) * zsshn * umask(k%I,k%J,jk) + & 
-                                   zvmid* e1v(k%I,k%J) * zsshn * vmask(k%I,k%J,jk) 
-              ENDIF 
-#endif
+               SELECT CASE( sec%direction(jseg) )                !compute velocity with the correct direction 
+               CASE(0,1)   
+                  zumid=0._wp
+                  zvmid=isgnv*vn(k%I,k%J,jk)*vmask(k%I,k%J,jk) 
+               CASE(2,3) 
+                  zumid=isgnu*un(k%I,k%J,jk)*umask(k%I,k%J,jk) 
+                  zvmid=0._wp
+               END SELECT 
+ 
+               !zTnorm=transport through one cell; 
+               !velocity* cell's length * cell's thickness 
+               zTnorm = zumid*e2u(k%I,k%J) * e3u_n(k%I,k%J,jk)     & 
+                  &   + zvmid*e1v(k%I,k%J) * e3v_n(k%I,k%J,jk) 
+
+!!gm  THIS is WRONG  no transport due to ssh in linear free surface case !!!!!
+               IF( ln_linssh ) THEN              !add transport due to free surface 
+                  IF( jk==1 ) THEN 
+                     zTnorm = zTnorm + zumid* e2u(k%I,k%J) * zsshn * umask(k%I,k%J,jk)   & 
+                        &            + zvmid* e1v(k%I,k%J) * zsshn * vmask(k%I,k%J,jk) 
+                  ENDIF 
+               ENDIF
+!!gm end
               !COMPUTE TRANSPORT  
  
               transports_3d(1,jsec,jseg,jk) = transports_3d(1,jsec,jseg,jk) + zTnorm 
   
-              IF ( sec%llstrpond ) THEN 
+              IF( sec%llstrpond ) THEN 
                  transports_3d(2,jsec,jseg,jk) = transports_3d(2,jsec,jseg,jk)  + zTnorm * ztn * zrhop * rcp
                  transports_3d(3,jsec,jseg,jk) = transports_3d(3,jsec,jseg,jk)  + zTnorm * zsn * zrhop * 0.001
               ENDIF
    
-           ENDDO !end of loop on the level
+           END DO !end of loop on the level
 
 #if defined key_lim2 || defined key_lim3
@@ -797,5 +786,5 @@
                  transports_2d(2,jsec,jseg) = transports_2d(2,jsec,jseg) + (zTnorm)*   &
                                    a_i(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J,jl)
-              ENDDO
+              END DO
 #endif
    
@@ -803,10 +792,11 @@
 #endif
  
-        ENDDO !end of loop on the segment
+        END DO !end of loop on the segment
 
      ENDIF !end of sec%nb_point =0 case
      !
   END SUBROUTINE transport
-  
+
+
   SUBROUTINE dia_dct_sum(sec,jsec) 
      !!------------------------------------------------------------- 
@@ -828,5 +818,4 @@
      !! 
      !!------------------------------------------------------------- 
-     !! * arguments 
      TYPE(SECTION),INTENT(INOUT) :: sec 
      INTEGER      ,INTENT(IN)    :: jsec        ! numeric identifier of section 
@@ -834,5 +823,5 @@
      TYPE(POINT_SECTION) :: k 
      INTEGER  :: jk,jseg,jclass                        ! dummy variables for looping on level/segment/classes  
-     REAL(wp) :: ztn, zsn, zrhoi, zrhop, zsshn, zfsdep ! temperature/salinity/ssh/potential density /depth at u/v point 
+     REAL(wp) :: ztn, zsn, zrhoi, zrhop, zsshn, zdep ! temperature/salinity/ssh/potential density /depth at u/v point 
      !!------------------------------------------------------------- 
  
@@ -903,5 +892,5 @@
               END SELECT 
  
-              zfsdep= fsdept(k%I,k%J,jk) 
+              zdep= gdept_n(k%I,k%J,jk) 
   
               !------------------------------- 
@@ -932,6 +921,6 @@
                     ( sec%ztem(jclass) .EQ.99.)) .AND.                     & 
  
-                    ((( zfsdep .GE. sec%zlay(jclass)) .AND.                & 
-                    (   zfsdep .LE. sec%zlay(jclass+1))) .OR.              & 
+                    ((( zdep .GE. sec%zlay(jclass)) .AND.                & 
+                    (   zdep .LE. sec%zlay(jclass+1))) .OR.              & 
                     ( sec%zlay(jclass) .EQ. 99. ))                         & 
                                                                    ))   THEN 
@@ -991,5 +980,5 @@
 #endif 
   
-        ENDDO !end of loop on the segment 
+        END DO !end of loop on the segment 
  
      ELSE  !if sec%nb_point =0 
@@ -1000,5 +989,6 @@
  
   END SUBROUTINE dia_dct_sum 
-  
+
+
   SUBROUTINE dia_dct_wri(kt,ksec,sec)
      !!-------------------------------------------------------------
@@ -1138,13 +1128,15 @@
                               sec%transport(9,1),sec%transport(10,1), &
                               sec%transport(9,1)+sec%transport(10,1) 
-     ENDIF
+      ENDIF
                                               
-118 FORMAT(I8,1X,I8,1X,I4,1X,A30,1X,f9.2,1X,I4,3X,A8,1X,2F12.4,5X,3F12.4)
-119 FORMAT(I8,1X,I8,1X,I4,1X,A30,1X,f9.2,1X,I4,3X,A8,1X,2F12.4,5X,3E15.6)
-
-     CALL wrk_dealloc(nb_type_class , zsumclasses )  
-  END SUBROUTINE dia_dct_wri
-
-  FUNCTION interp(ki, kj, kk, cd_point, ptab)
+118   FORMAT(I8,1X,I8,1X,I4,1X,A30,1X,f9.2,1X,I4,3X,A8,1X,2F12.4,5X,3F12.4)
+119   FORMAT(I8,1X,I8,1X,I4,1X,A30,1X,f9.2,1X,I4,3X,A8,1X,2F12.4,5X,3E15.6)
+
+      CALL wrk_dealloc(nb_type_class , zsumclasses )  
+      !
+   END SUBROUTINE dia_dct_wri
+
+
+   FUNCTION interp(ki, kj, kk, cd_point, ptab)
   !!----------------------------------------------------------------------
   !!
@@ -1214,5 +1206,5 @@
   !*local declations
   INTEGER :: ii1, ij1, ii2, ij2                                ! local integer
-  REAL(wp):: ze3t, zfse3, zwgt1, zwgt2, zbis, zdepu            ! local real
+  REAL(wp):: ze3t, ze3, zwgt1, zwgt2, zbis, zdepu            ! local real
   REAL(wp):: zet1, zet2                                        ! weight for interpolation 
   REAL(wp):: zdep1,zdep2                                       ! differences of depth
@@ -1241,7 +1233,7 @@
   IF( ln_sco )THEN   ! s-coordinate case
 
-     zdepu = ( fsdept(ii1,ij1,kk) +  fsdept(ii2,ij2,kk) ) /2 
-     zdep1 = fsdept(ii1,ij1,kk) - zdepu
-     zdep2 = fsdept(ii2,ij2,kk) - zdepu
+     zdepu = ( gdept_n(ii1,ij1,kk) +  gdept_n(ii2,ij2,kk) ) * 0.5_wp 
+     zdep1 = gdept_n(ii1,ij1,kk) - zdepu
+     zdep2 = gdept_n(ii2,ij2,kk) - zdepu
 
      ! weights
@@ -1255,17 +1247,7 @@
   ELSE       ! full step or partial step case 
 
-#if defined key_vvl
-
-     ze3t  = fse3t_n(ii2,ij2,kk) - fse3t_n(ii1,ij1,kk) 
-     zwgt1 = ( fse3w_n(ii2,ij2,kk) - fse3w_n(ii1,ij1,kk) ) / fse3w_n(ii2,ij2,kk)
-     zwgt2 = ( fse3w_n(ii1,ij1,kk) - fse3w_n(ii2,ij2,kk) ) / fse3w_n(ii1,ij1,kk)
-
-#else
-
-     ze3t  = fse3t(ii2,ij2,kk)   - fse3t(ii1,ij1,kk) 
-     zwgt1 = ( fse3w(ii2,ij2,kk) - fse3w(ii1,ij1,kk) ) / fse3w(ii2,ij2,kk)
-     zwgt2 = ( fse3w(ii1,ij1,kk) - fse3w(ii2,ij2,kk) ) / fse3w(ii1,ij1,kk)
-
-#endif
+     ze3t  = e3t_n(ii2,ij2,kk) - e3t_n(ii1,ij1,kk) 
+     zwgt1 = ( e3w_n(ii2,ij2,kk) - e3w_n(ii1,ij1,kk) ) / e3w_n(ii2,ij2,kk)
+     zwgt2 = ( e3w_n(ii1,ij1,kk) - e3w_n(ii2,ij2,kk) ) / e3w_n(ii1,ij1,kk)
 
      IF(kk .NE. 1)THEN
@@ -1288,7 +1270,6 @@
 
   ENDIF
-
-
-  END FUNCTION interp
+      !
+   END FUNCTION interp
 
 #else
@@ -1311,3 +1292,4 @@
 #endif
 
+   !!======================================================================
 END MODULE diadct
Index: unk/NEMOGCM/NEMO/OPA_SRC/DIA/diadimg.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diadimg.F90	(revision 6139)
+++ 	(revision )
@@ -1,229 +1,0 @@
-MODULE diadimg
-   !!======================================================================
-   !!                     ***  MODULE  diadimg  ***
-   !! Ocean diagnostics :  write ocean output files in dimg direct access format (mpp)
-   !!=====================================================================
-# if defined key_dimgout
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers 
-   USE dom_oce         ! ocean space and time domain
-   USE in_out_manager  ! I/O manager
-   USE daymod          ! calendar
-   USE lib_mpp
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC dia_wri_dimg            ! called by trd_mld (eg)
-   PUBLIC dia_wri_dimg_alloc      ! called by nemo_alloc in nemogcm.F90
-
-
-   !! These workspace arrays are inside the module so that we can make them
-   !! allocatable in a clean way. Not done in wrk_nemo because these are of KIND(sp).
-   REAL(sp), ALLOCATABLE, SAVE, DIMENSION(:,:) :: z42d    ! 2d temporary workspace (sp)
-   REAL(sp), ALLOCATABLE, SAVE, DIMENSION(:)   :: z4dep   ! vertical level (sp)
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   FUNCTION dia_wri_dimg_alloc()
-      !!---------------------------------------------------------------------
-      !!        *** ROUTINE dia_wri_dimg_alloc ***
-      !!
-      !!---------------------------------------------------------------------
-      INTEGER :: dia_wri_dimg_alloc   ! return value
-      !!---------------------------------------------------------------------
-      !
-      IF( .NOT. ALLOCATED( z42d ) )THEN
-
-         ALLOCATE( z42d(jpi,jpj), z4dep(jpk), STAT=dia_wri_dimg_alloc )
-
-         IF( lk_mpp                  )   CALL mpp_sum ( dia_wri_dimg_alloc )
-         IF( dia_wri_dimg_alloc /= 0 )   CALL ctl_warn('dia_wri_dimg_alloc: allocation of array failed.')
-
-      ELSE
-
-         dia_wri_dimg_alloc = 0
-
-      ENDIF
-      !
-  END FUNCTION dia_wri_dimg_alloc
-
-
-  SUBROUTINE dia_wri_dimg( cd_name, cd_text, ptab, klev, cd_type , ksubi )
-    !!-------------------------------------------------------------------------
-    !!        *** ROUTINE dia_wri_dimg ***
-    !!
-    !! ** Purpose :   write ptab in the dimg file cd_name, with comment cd_text.
-    !!              ptab has klev x 2D fields
-    !!
-    !! ** Action :   Define header variables from the config parameters
-    !!               Open the dimg file on unit inum = 14 ( IEEE I4R4 file )
-    !!               Write header on record 1
-    !!               Write ptab on the following klev records
-    !!
-    !! History :  2003-12 (J.M. Molines ) : Original. Replace ctl_opn, writn2d
-    !!---------------------------------------------------------------------------
-    CHARACTER(len=*),INTENT(in) ::   &
-         &                            cd_name,  &  ! dimg file name
-         &                            cd_text      ! comment to write on record #1
-    INTEGER, INTENT(in) ::            klev         ! number of level in ptab to write
-    REAL(wp),INTENT(in), DIMENSION(:,:,:) :: ptab  ! 3D array to write 
-    CHARACTER(LEN=1),INTENT(in) ::    cd_type      ! either 'T', 'W' or '2' , depending on the vertical
-    !                                              ! grid for ptab. 2 stands for 2D file
-    INTEGER, INTENT(in), OPTIONAL, DIMENSION(klev) :: ksubi 
-
-    !! * Local declarations
-    INTEGER :: jk, jn           ! dummy loop indices
-    INTEGER :: irecl4,             &    ! record length in bytes
-         &       inum,             &    ! logical unit (set to 14)
-         &       irec,             &    ! current record to be written
-         &       irecend                ! record number where nclit... are stored
-    REAL(sp)                    :: zdx,zdy,zspval,zwest,ztimm
-    REAL(sp)                    :: zsouth
-
-    CHARACTER(LEN=80) :: clname                ! name of file in case of dimgnnn
-    CHARACTER(LEN=4) :: clver='@!01'           ! dimg string identifier
-    !!---------------------------------------------------------------------------
-
-    !                                      ! allocate dia_wri_dimg array
-    IF( dia_wri_dimg_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dia_wri_dimg : unable to allocate arrays' )
-
-    !! * Initialisations
-
-    irecl4 = MAX(jpi*jpj*sp , 84+(18+1+jpk)*sp )
-
-    zspval=0.0_sp    ! special values on land
-    !  the 'numerical' grid is described. The geographical one is in a grid file
-    zdx=1._sp
-    zdy=1._sp
-    zsouth=njmpp * 1._sp
-    zwest=nimpp * 1._sp
-    !  time in days since the historical begining of the run (nit000 = 0 ) 
-    ztimm=adatrj
-
-    SELECT CASE ( cd_type )
-
-    CASE ( 'T')
-       z4dep(:)=gdept_1d(:)
-
-    CASE ( 'W' )
-       z4dep(:)=gdepw_1d(:)
-
-    CASE ( '2' )
-       z4dep(1:klev) =(/(jk, jk=1,klev)/)
-
-    CASE ( 'I' )
-       z4dep(1:klev) = ksubi(1:klev)
-
-    CASE DEFAULT
-       IF(lwp) WRITE(numout,*) ' E R R O R : bad cd_type in dia_wri_dimg '
-       STOP 'dia_wri_dimg'
-
-    END SELECT
-
-    IF ( ln_dimgnnn  ) THEN
-     irecl4 = MAX(jpi*jpj*sp , 84+(18+jpk)*sp + 8*jpnij*sp  )
-       WRITE(clname,'(a,a,i3.3)') TRIM(cd_name),'.',narea
-       CALL ctl_opn(inum, clname,'UNKNOWN','UNFORMATTED','DIRECT',irecl4,numout,lwp)
-       WRITE(inum,REC=1 ) clver, cd_text, irecl4, &
-            &     jpi,jpj, klev, 1 , 1 ,            &
-            &     zwest, zsouth, zdx, zdy, zspval,  &
-            &     z4dep(1:klev),                    &
-            &     ztimm,                            &
-            &     narea, jpnij,jpiglo,jpjglo,jpizoom, jpjzoom,    &    ! extension to dimg for mpp output
-            &     nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt  !
-
-       !! * Write klev levels
-       IF ( cd_type == 'I' ) THEN
-
-          DO jk = 1, klev
-             irec =1 + jk
-             z42d(:,:) = ptab(:,:,ksubi(jk))
-             WRITE(inum,REC=irec)  z42d(:,:)
-          END DO
-       ELSE
-          DO jk = 1, klev
-             irec =1 + jk
-             z42d(:,:) = ptab(:,:,jk)
-             WRITE(inum,REC=irec)  z42d(:,:)
-          END DO
-       ENDIF
-    ELSE
-       clver='@!03'           ! dimg string identifier
-       ! note that version @!02 is optimized with respect to record length.
-       ! The vertical dep variable is reduced to klev instead of klev*jpnij :
-       !   this is OK for jpnij < 181 (jpk=46)
-       ! for more processors, irecl4 get huge and that's why we switch to '@!03':
-       !  In this case we just add an extra integer to the standard dimg structure,
-       !  which is a record number where the arrays nlci etc... starts (1 per record)
-       
-       !! Standard dimgproc (1 file per variable, all procs. write to this file )
-       !! * Open file
-       CALL ctl_opn(inum, cd_name,'UNKNOWN','UNFORMATTED','DIRECT',irecl4,numout,lwp)
-
-       !! * Write header on record #1
-       irecend=1 + klev*jpnij 
-       IF(lwp) WRITE(inum,REC=1 ) clver, cd_text, irecl4, &
-            &     jpi,jpj, klev, 1 , 1 ,            &
-            &     zwest, zsouth, zdx, zdy, zspval,  &
-            &     z4dep(1:klev),       &
-            &     ztimm,                            &
-            &     narea, jpnij,jpiglo,jpjglo,jpizoom, jpjzoom, irecend 
-       IF (lwp ) THEN
-         WRITE(inum,REC=irecend + 1 ) nlcit
-         WRITE(inum,REC=irecend + 2 ) nlcjt
-         WRITE(inum,REC=irecend + 3 ) nldit
-         WRITE(inum,REC=irecend + 4 ) nldjt
-         WRITE(inum,REC=irecend + 5 ) nleit
-         WRITE(inum,REC=irecend + 6 ) nlejt
-         WRITE(inum,REC=irecend + 7 ) nimppt
-         WRITE(inum,REC=irecend + 8 ) njmppt
-       ENDIF
-      !   &    ! extension to dimg for mpp output
-      !   &     nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt  !
-
-       !! * Write klev levels
-       IF ( cd_type == 'I' ) THEN
-
-          DO jk = 1, klev
-             irec =1 + klev * (narea -1) + jk
-             z42d(:,:) = ptab(:,:,ksubi(jk))
-             WRITE(inum,REC=irec)  z42d(:,:)
-          END DO
-       ELSE
-          DO jk = 1, klev
-             irec =1 + klev * (narea -1) + jk
-             z42d(:,:) = ptab(:,:,jk)
-             WRITE(inum,REC=irec)  z42d(:,:)
-          END DO
-       ENDIF
-    ENDIF
-
-    !! * Close the file
-    CLOSE(inum)
-
-  END SUBROUTINE dia_wri_dimg
-
-#  else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                       Empty module
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dia_wri_dimg( cd_name, cd_exper, ptab, klev, cd_type )
-      REAL, DIMENSION(:,:,:) :: ptab
-      INTEGER :: klev
-      CHARACTER(LEN=80) :: cd_name, cd_exper,cd_type
-      WRITE(*,*) ' This print must never occur ', cd_name, cd_exper,ptab, klev, cd_type
-      WRITE(*,*) ' this routine is here just for compilation '
-   END SUBROUTINE dia_wri_dimg
-# endif
-   !!======================================================================
-END MODULE diadimg
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diafwb.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diafwb.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diafwb.F90	(revision 6140)
@@ -33,5 +33,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -40,5 +39,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -80,5 +78,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zwei  = e1e2t(ji,jj) * fse3t(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+                  zwei  = e1e2t(ji,jj) * e3t_n(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
                   a_salb = a_salb + ( tsb(ji,jj,jk,jp_sal) - zsm0 ) * zwei
                END DO
@@ -106,5 +104,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zwei  = e1e2t(ji,jj) * fse3t(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+                  zwei  = e1e2t(ji,jj) * e3t_n(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
                   a_saln = a_saln + ( tsn(ji,jj,jk,jp_sal) - zsm0 ) * zwei
                   zvol  = zvol  + zwei
@@ -116,5 +114,5 @@
          
          ! Conversion in m3
-         a_fwf    = a_fwf * rdttra(1) * 1.e-3 
+         a_fwf    = a_fwf * rdt * 1.e-3 
          
          ! fwf correction to bring back the mean ssh to zero
@@ -186,5 +184,5 @@
                   zt = 0.5 * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
                   zs = 0.5 * ( tsn(ji,jj,jk,jp_sal) + tsn(ji+1,jj,jk,jp_sal) )
-                  zu = un(ji,jj,jk) * fse3t(ji,jj,jk) * e2u(ji,jj) * tmask_i(ji,jj)
+                  zu = un(ji,jj,jk) * e3t_n(ji,jj,jk) * e2u(ji,jj) * tmask_i(ji,jj)
 
                   IF( un(ji,jj,jk) > 0.e0 ) THEN 
@@ -238,5 +236,5 @@
                   zt = 0.5 * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
                   zs = 0.5 * ( tsn(ji,jj,jk,jp_sal) + tsn(ji+1,jj,jk,jp_sal) )
-                  zu = un(ji,jj,jk) * fse3t(ji,jj,jk) * e2u(ji,jj) * tmask_i(ji,jj)
+                  zu = un(ji,jj,jk) * e3t_n(ji,jj,jk) * e2u(ji,jj) * tmask_i(ji,jj)
                   
                   IF( un(ji,jj,jk) > 0.e0 ) THEN 
@@ -290,5 +288,5 @@
                   zt = 0.5 * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
                   zs = 0.5 * ( tsn(ji,jj,jk,jp_sal) + tsn(ji+1,jj,jk,jp_sal) )
-                  zu = un(ji,jj,jk) * fse3t(ji,jj,jk) * e2u(ji,jj) * tmask_i(ji,jj)
+                  zu = un(ji,jj,jk) * e3t_n(ji,jj,jk) * e2u(ji,jj) * tmask_i(ji,jj)
                   
                   IF( un(ji,jj,jk) > 0.e0 ) THEN 
@@ -342,5 +340,5 @@
                   zt = 0.5 * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
                   zs = 0.5 * ( tsn(ji,jj,jk,jp_sal) + tsn(ji+1,jj,jk,jp_sal) )
-                  zu = un(ji,jj,jk) * fse3t(ji,jj,jk) * e2u(ji,jj) * tmask_i(ji,jj)
+                  zu = un(ji,jj,jk) * e3t_n(ji,jj,jk) * e2u(ji,jj) * tmask_i(ji,jj)
                   
                   IF( un(ji,jj,jk) > 0.e0 ) THEN 
@@ -404,5 +402,5 @@
          WRITE(inum,*)
          WRITE(inum,*)    'Net freshwater budget '
-         WRITE(inum,9010) '  fwf    = ',a_fwf,   ' m3 =', a_fwf   /(FLOAT(nitend-nit000+1)*rdttra(1)) * 1.e-6,' Sv'
+         WRITE(inum,9010) '  fwf    = ',a_fwf,   ' m3 =', a_fwf   /(FLOAT(nitend-nit000+1)*rdt) * 1.e-6,' Sv'
          WRITE(inum,*)
          WRITE(inum,9010) '  zarea =',zarea
@@ -460,5 +458,5 @@
       ENDIF
 
-      IF( nn_timing == 1 )   CALL timing_start('dia_fwb')
+      IF( nn_timing == 1 )   CALL timing_stop('dia_fwb')
 
  9005 FORMAT(1X,A,ES24.16)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90	(revision 6140)
@@ -21,5 +21,4 @@
    USE ioipsl          ! NetCDF IPSL library
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE diadimg         ! To write dimg
    USE timing          ! preformance summary
    USE wrk_nemo        ! working arrays
@@ -135,5 +134,5 @@
       DO jk=1,nb_ana
        DO ji=1,jpmax_harmo
-          IF (TRIM(tname(jk)) .eq. Wave(ji)%cname_tide) THEN
+          IF (TRIM(tname(jk)) ==  Wave(ji)%cname_tide) THEN
              name(jk) = ji
              EXIT
@@ -194,7 +193,7 @@
                   DO ji = 1,jpi
                      ! Elevation
-                     ana_temp(ji,jj,nhc,1) = ana_temp(ji,jj,nhc,1) + ztemp*sshn(ji,jj)*tmask_i(ji,jj)        
-                     ana_temp(ji,jj,nhc,2) = ana_temp(ji,jj,nhc,2) + ztemp*un_b(ji,jj)*umask_i(ji,jj)
-                     ana_temp(ji,jj,nhc,3) = ana_temp(ji,jj,nhc,3) + ztemp*vn_b(ji,jj)*vmask_i(ji,jj)
+                     ana_temp(ji,jj,nhc,1) = ana_temp(ji,jj,nhc,1) + ztemp*sshn(ji,jj)*ssmask (ji,jj)        
+                     ana_temp(ji,jj,nhc,2) = ana_temp(ji,jj,nhc,2) + ztemp*un_b(ji,jj)*ssumask(ji,jj)
+                     ana_temp(ji,jj,nhc,3) = ana_temp(ji,jj,nhc,3) + ztemp*vn_b(ji,jj)*ssvmask(ji,jj)
                   END DO
                END DO
@@ -324,6 +323,6 @@
                X1= ana_amp(ji,jj,jh,1)
                X2=-ana_amp(ji,jj,jh,2)
-               out_u(ji,jj,       jh) = X1 * umask_i(ji,jj)
-               out_u(ji,jj,nb_ana+jh) = X2 * umask_i(ji,jj)
+               out_u(ji,jj,       jh) = X1 * ssumask(ji,jj)
+               out_u(ji,jj,nb_ana+jh) = X2 * ssumask(ji,jj)
             ENDDO
          ENDDO
@@ -358,6 +357,6 @@
                X1=ana_amp(ji,jj,jh,1)
                X2=-ana_amp(ji,jj,jh,2)
-               out_v(ji,jj,       jh)=X1 * vmask_i(ji,jj)
-               out_v(ji,jj,nb_ana+jh)=X2 * vmask_i(ji,jj)
+               out_v(ji,jj,       jh)=X1 * ssvmask(ji,jj)
+               out_v(ji,jj,nb_ana+jh)=X2 * ssvmask(ji,jj)
             END DO
          END DO
@@ -384,17 +383,6 @@
       !!----------------------------------------------------------------------
 
-#if defined key_dimgout
-      cdfile_name_T = TRIM(cexper)//'_Tidal_harmonics_gridT.dimgproc'
-      cdfile_name_U = TRIM(cexper)//'_Tidal_harmonics_gridU.dimgproc'
-      cdfile_name_V = TRIM(cexper)//'_Tidal_harmonics_gridV.dimgproc'
-#endif
-
       IF(lwp) WRITE(numout,*) '  '
       IF(lwp) WRITE(numout,*) 'dia_wri_harm : Write harmonic analysis results'
-#if defined key_dimgout
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~  Output files: ', TRIM(cdfile_name_T)
-      IF(lwp) WRITE(numout,*) '                             ', TRIM(cdfile_name_U)
-      IF(lwp) WRITE(numout,*) '                             ', TRIM(cdfile_name_V)
-#endif
       IF(lwp) WRITE(numout,*) '  '
 
@@ -402,39 +390,24 @@
       !/////////////
       !
-#if defined key_dimgout
-      cltext='Elevation amplitude and phase'
-      CALL dia_wri_dimg(TRIM(cdfile_name_T), TRIM(cltext), out_eta, 2*nb_ana, '2')
-#else
       DO jh = 1, nb_ana
       CALL iom_put( TRIM(tname(jh))//'x', out_eta(:,:,jh) )
       CALL iom_put( TRIM(tname(jh))//'y', out_eta(:,:,nb_ana+jh) )
       END DO
-#endif
 
       ! B) ubar
       !/////////
       !
-#if defined key_dimgout
-      cltext='ubar amplitude and phase'
-      CALL dia_wri_dimg(TRIM(cdfile_name_U), TRIM(cltext), out_u, 2*nb_ana, '2')
-#else
       DO jh = 1, nb_ana
       CALL iom_put( TRIM(tname(jh))//'x_u', out_u(:,:,jh) )
       CALL iom_put( TRIM(tname(jh))//'y_u', out_u(:,:,nb_ana+jh) )
       END DO
-#endif
 
       ! C) vbar
       !/////////
       !
-#if defined key_dimgout
-      cltext='vbar amplitude and phase'
-      CALL dia_wri_dimg(TRIM(cdfile_name_V), TRIM(cltext), out_v, 2*nb_ana, '2')
-#else
       DO jh = 1, nb_ana
          CALL iom_put( TRIM(tname(jh))//'x_v', out_v(:,:,jh       ) )
          CALL iom_put( TRIM(tname(jh))//'y_v', out_v(:,:,jh+nb_ana) )
       END DO
-#endif
       !
    END SUBROUTINE dia_wri_harm
@@ -488,5 +461,5 @@
             DO jj_sd = ji_sd, ninco
                zval2 = ABS(ztmp3(ji_sd,jj_sd))
-               IF( zval2.GE.zval1 )THEN
+               IF( zval2 >= zval1 )THEN
                   ipivot(ji_sd) = jj_sd
                   zval1         = zval2
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 6140)
@@ -46,10 +46,10 @@
    REAL(wp) ::   frc_wn_t, frc_wn_s    ! global forcing trends
    !
-   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE ::   surf          , ssh_ini          !
+   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE ::   surf 
+   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE ::   surf_ini      , ssh_ini          !
    REAL(wp), DIMENSION(:,:)  , ALLOCATABLE ::   ssh_hc_loc_ini, ssh_sc_loc_ini   !
    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   hc_loc_ini, sc_loc_ini, e3t_ini  !
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -100,9 +100,5 @@
       IF( ln_rnf_sal)   z_frc_trd_s = z_frc_trd_s + glob_sum( rnf_tsc(:,:,jp_sal) * surf(:,:) )
       ! Add ice shelf heat & salt input
-      IF( nn_isf .GE. 1 )  THEN
-          z_frc_trd_t = z_frc_trd_t + glob_sum( risf_tsc(:,:,jp_tem) * surf(:,:) )
-          z_frc_trd_s = z_frc_trd_s + glob_sum( risf_tsc(:,:,jp_sal) * surf(:,:) )
-      ENDIF
-
+      IF( ln_isf    ) z_frc_trd_t = z_frc_trd_t + glob_sum( risf_tsc(:,:,jp_tem) * surf(:,:) )
       ! Add penetrative solar radiation
       IF( ln_traqsr )   z_frc_trd_t = z_frc_trd_t + r1_rau0_rcp * glob_sum( qsr     (:,:) * surf(:,:) )
@@ -110,12 +106,12 @@
       IF( ln_trabbc )   z_frc_trd_t = z_frc_trd_t +               glob_sum( qgh_trd0(:,:) * surf(:,:) )
       !
-      IF( .NOT. lk_vvl ) THEN
-         IF ( ln_isfcav ) THEN
+      IF( ln_linssh ) THEN
+         IF( ln_isfcav ) THEN
             DO ji=1,jpi
                DO jj=1,jpj
                   z2d0(ji,jj) = surf(ji,jj) * wn(ji,jj,mikt(ji,jj)) * tsb(ji,jj,mikt(ji,jj),jp_tem)
                   z2d1(ji,jj) = surf(ji,jj) * wn(ji,jj,mikt(ji,jj)) * tsb(ji,jj,mikt(ji,jj),jp_sal)
-               ENDDO
-            ENDDO
+               END DO
+            END DO
          ELSE
             z2d0(:,:) = surf(:,:) * wn(:,:,1) * tsb(:,:,1,jp_tem)
@@ -130,5 +126,5 @@
       frc_s = frc_s + z_frc_trd_s * rdt
       !                                          ! Advection flux through fixed surface (z=0)
-      IF( .NOT. lk_vvl ) THEN
+      IF( ln_linssh ) THEN
          frc_wn_t = frc_wn_t + z_wn_trd_t * rdt
          frc_wn_s = frc_wn_s + z_wn_trd_s * rdt
@@ -138,4 +134,5 @@
       ! 2 -  Content variations !
       ! ------------------------ !
+      ! glob_sum_full is needed because you keep the full interior domain to compute the sum (iscpl)
       zdiff_v2 = 0._wp
       zdiff_hc = 0._wp
@@ -143,9 +140,9 @@
 
       ! volume variation (calculated with ssh)
-      zdiff_v1 = glob_sum( surf(:,:) * ( sshn(:,:) - ssh_ini(:,:) ) )
+      zdiff_v1 = glob_sum_full( surf(:,:) * sshn(:,:) - surf_ini(:,:) * ssh_ini(:,:) )
 
       ! heat & salt content variation (associated with ssh)
-      IF( .NOT. lk_vvl ) THEN
-         IF ( ln_isfcav ) THEN
+      IF( ln_linssh ) THEN
+         IF( ln_isfcav ) THEN
             DO ji = 1, jpi
                DO jj = 1, jpj
@@ -158,26 +155,26 @@
             z2d1(:,:) = surf(:,:) * ( tsn(:,:,1,jp_sal) * sshn(:,:) - ssh_sc_loc_ini(:,:) ) 
          END IF
-         z_ssh_hc = glob_sum( z2d0 ) 
-         z_ssh_sc = glob_sum( z2d1 ) 
+         z_ssh_hc = glob_sum_full( z2d0 ) 
+         z_ssh_sc = glob_sum_full( z2d1 ) 
       ENDIF
 
       DO jk = 1, jpkm1
          ! volume variation (calculated with scale factors)
-         zdiff_v2 = zdiff_v2 + glob_sum( surf(:,:) * tmask(:,:,jk) &
-            &                           * ( fse3t_n(:,:,jk) - e3t_ini(:,:,jk) ) )
+         zdiff_v2 = zdiff_v2 + glob_sum_full( surf(:,:) * tmask(:,:,jk)            &
+            &                           * e3t_n(:,:,jk) - surf_ini(:,:) * e3t_ini(:,:,jk) )
          ! heat content variation
-         zdiff_hc = zdiff_hc + glob_sum(  surf(:,:) * tmask(:,:,jk) & 
-            &                           * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_tem) - hc_loc_ini(:,:,jk) ) )
+         zdiff_hc = zdiff_hc + glob_sum_full(  surf(:,:) * tmask(:,:,jk)                                   & 
+            &                           * e3t_n(:,:,jk) * tsn(:,:,jk,jp_tem) - surf_ini(:,:) * hc_loc_ini(:,:,jk) ) 
          ! salt content variation
-         zdiff_sc = zdiff_sc + glob_sum(  surf(:,:) * tmask(:,:,jk)   &
-            &                           * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_sal) - sc_loc_ini(:,:,jk) ) )
+         zdiff_sc = zdiff_sc + glob_sum_full( surf    (:,:) * tmask(:,:,jk)                           &
+                                        * e3t_n(:,:,jk) * tsn(:,:,jk,jp_sal) - surf_ini(:,:) * sc_loc_ini(:,:,jk) )
       ENDDO
 
       ! Substract forcing from heat content, salt content and volume variations
       zdiff_v1 = zdiff_v1 - frc_v
-      IF( lk_vvl )   zdiff_v2 = zdiff_v2 - frc_v
+      IF( .NOT.ln_linssh )   zdiff_v2 = zdiff_v2 - frc_v
       zdiff_hc = zdiff_hc - frc_t
       zdiff_sc = zdiff_sc - frc_s
-      IF( .NOT. lk_vvl ) THEN
+      IF( ln_linssh ) THEN
          zdiff_hc1 = zdiff_hc + z_ssh_hc 
          zdiff_sc1 = zdiff_sc + z_ssh_sc
@@ -191,14 +188,25 @@
       zvol_tot = 0._wp                    ! total ocean volume (calculated with scale factors)
       DO jk = 1, jpkm1
-         zvol_tot  = zvol_tot + glob_sum( surf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) )
+         zvol_tot  = zvol_tot + glob_sum_full( surf(:,:) * tmask(:,:,jk) * e3t_n(:,:,jk) )
       END DO
 
 !!gm to be added ?
-!      IF( .NOT. lk_vvl ) THEN            ! fixed volume, add the ssh contribution
+!      IF( ln_linssh ) THEN            ! fixed volume, add the ssh contribution
 !        zvol_tot = zvol_tot + glob_sum( surf(:,:) * sshn(:,:) )
 !      ENDIF
 !!gm end
 
-      IF( lk_vvl ) THEN
+      IF( ln_linssh ) THEN
+        CALL iom_put( 'bgtemper' , zdiff_hc1 / zvol_tot)              ! Heat content variation (C) 
+        CALL iom_put( 'bgsaline' , zdiff_sc1 / zvol_tot)              ! Salt content variation (psu)
+        CALL iom_put( 'bgheatco' , zdiff_hc1 * 1.e-20 * rau0 * rcp )  ! Heat content variation (1.e20 J) 
+        CALL iom_put( 'bgsaltco' , zdiff_sc1 * 1.e-9   )              ! Salt content variation (psu*km3)
+        CALL iom_put( 'bgvolssh' , zdiff_v1  * 1.e-9   )              ! volume ssh variation (km3)  
+        CALL iom_put( 'bgfrcvol' , frc_v    * 1.e-9    )              ! vol - surface forcing (km3) 
+        CALL iom_put( 'bgfrctem' , frc_t / zvol_tot    )              ! hc  - surface forcing (C) 
+        CALL iom_put( 'bgfrcsal' , frc_s / zvol_tot    )              ! sc  - surface forcing (psu) 
+        CALL iom_put( 'bgmistem' , zerr_hc1 / zvol_tot )              ! hc  - error due to free surface (C)
+        CALL iom_put( 'bgmissal' , zerr_sc1 / zvol_tot )              ! sc  - error due to free surface (psu)
+      ELSE
         CALL iom_put( 'bgtemper' , zdiff_hc / zvol_tot )              ! Temperature variation (C) 
         CALL iom_put( 'bgsaline' , zdiff_sc / zvol_tot )              ! Salinity    variation (psu)
@@ -210,21 +218,10 @@
         CALL iom_put( 'bgfrctem' , frc_t / zvol_tot    )              ! hc  - surface forcing (C) 
         CALL iom_put( 'bgfrcsal' , frc_s / zvol_tot    )              ! sc  - surface forcing (psu) 
-      ELSE
-        CALL iom_put( 'bgtemper' , zdiff_hc1 / zvol_tot)              ! Heat content variation (C) 
-        CALL iom_put( 'bgsaline' , zdiff_sc1 / zvol_tot)              ! Salt content variation (psu)
-        CALL iom_put( 'bgheatco' , zdiff_hc1 * 1.e-20 * rau0 * rcp )  ! Heat content variation (1.e20 J) 
-        CALL iom_put( 'bgsaltco' , zdiff_sc1 * 1.e-9    )             ! Salt content variation (psu*km3)
-        CALL iom_put( 'bgvolssh' , zdiff_v1 * 1.e-9    )              ! volume ssh variation (km3)  
-        CALL iom_put( 'bgfrcvol' , frc_v    * 1.e-9    )              ! vol - surface forcing (km3) 
-        CALL iom_put( 'bgfrctem' , frc_t / zvol_tot    )              ! hc  - surface forcing (C) 
-        CALL iom_put( 'bgfrcsal' , frc_s / zvol_tot    )              ! sc  - surface forcing (psu) 
-        CALL iom_put( 'bgmistem' , zerr_hc1 / zvol_tot )              ! hc  - error due to free surface (C)
-        CALL iom_put( 'bgmissal' , zerr_sc1 / zvol_tot )              ! sc  - error due to free surface (psu)
       ENDIF
       !
       IF( lrst_oce )   CALL dia_hsb_rst( kt, 'WRITE' )
-
+      !
       CALL wrk_dealloc( jpi,jpj,   z2d0, z2d1 )
-
+      !
       IF( nn_timing == 1 )   CALL timing_stop('dia_hsb')
       !
@@ -257,13 +254,14 @@
            CALL iom_get( numror, 'frc_t', frc_t )
            CALL iom_get( numror, 'frc_s', frc_s )
-           IF( .NOT. lk_vvl ) THEN
+           IF( ln_linssh ) THEN
               CALL iom_get( numror, 'frc_wn_t', frc_wn_t )
               CALL iom_get( numror, 'frc_wn_s', frc_wn_s )
            ENDIF
+           CALL iom_get( numror, jpdom_autoglo, 'surf_ini', surf_ini ) ! ice sheet coupling
            CALL iom_get( numror, jpdom_autoglo, 'ssh_ini', ssh_ini )
            CALL iom_get( numror, jpdom_autoglo, 'e3t_ini', e3t_ini )
            CALL iom_get( numror, jpdom_autoglo, 'hc_loc_ini', hc_loc_ini )
            CALL iom_get( numror, jpdom_autoglo, 'sc_loc_ini', sc_loc_ini )
-           IF( .NOT. lk_vvl ) THEN
+           IF( ln_linssh ) THEN
               CALL iom_get( numror, jpdom_autoglo, 'ssh_hc_loc_ini', ssh_hc_loc_ini )
               CALL iom_get( numror, jpdom_autoglo, 'ssh_sc_loc_ini', ssh_sc_loc_ini )
@@ -273,14 +271,16 @@
           IF(lwp) WRITE(numout,*) ' dia_hsb at initial state '
           IF(lwp) WRITE(numout,*) '~~~~~~~'
-          ssh_ini(:,:) = sshn(:,:)                                       ! initial ssh
+          surf_ini(:,:) = e1e2t(:,:) * tmask_i(:,:)         ! initial ocean surface
+          ssh_ini(:,:) = sshn(:,:)                          ! initial ssh
           DO jk = 1, jpk
-             e3t_ini   (:,:,jk) = fse3t_n(:,:,jk)                        ! initial vertical scale factors
-             hc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_tem) * fse3t_n(:,:,jk)   ! initial heat content
-             sc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_sal) * fse3t_n(:,:,jk)   ! initial salt content
+             ! if ice sheet/oceqn coupling, need to mask ini variables here (mask could change at the next NEMO instance).
+             e3t_ini   (:,:,jk) = e3t_n(:,:,jk)                      * tmask(:,:,jk)  ! initial vertical scale factors
+             hc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_tem) * e3t_n(:,:,jk) * tmask(:,:,jk)  ! initial heat content
+             sc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_sal) * e3t_n(:,:,jk) * tmask(:,:,jk)  ! initial salt content
           END DO
           frc_v = 0._wp                                           ! volume       trend due to forcing
           frc_t = 0._wp                                           ! heat content   -    -   -    -   
           frc_s = 0._wp                                           ! salt content   -    -   -    -        
-          IF( .NOT. lk_vvl ) THEN
+          IF( ln_linssh ) THEN
              IF ( ln_isfcav ) THEN
                 DO ji=1,jpi
@@ -308,13 +308,14 @@
         CALL iom_rstput( kt, nitrst, numrow, 'frc_t'   , frc_t     )
         CALL iom_rstput( kt, nitrst, numrow, 'frc_s'   , frc_s     )
-        IF( .NOT. lk_vvl ) THEN
+        IF( ln_linssh ) THEN
            CALL iom_rstput( kt, nitrst, numrow, 'frc_wn_t', frc_wn_t )
            CALL iom_rstput( kt, nitrst, numrow, 'frc_wn_s', frc_wn_s )
         ENDIF
+        CALL iom_rstput( kt, nitrst, numrow, 'surf_ini', surf_ini )      ! ice sheet coupling
         CALL iom_rstput( kt, nitrst, numrow, 'ssh_ini', ssh_ini )
         CALL iom_rstput( kt, nitrst, numrow, 'e3t_ini', e3t_ini )
         CALL iom_rstput( kt, nitrst, numrow, 'hc_loc_ini', hc_loc_ini )
         CALL iom_rstput( kt, nitrst, numrow, 'sc_loc_ini', sc_loc_ini )
-        IF( .NOT. lk_vvl ) THEN
+        IF( ln_linssh ) THEN
            CALL iom_rstput( kt, nitrst, numrow, 'ssh_hc_loc_ini', ssh_hc_loc_ini )
            CALL iom_rstput( kt, nitrst, numrow, 'ssh_sc_loc_ini', ssh_sc_loc_ini )
@@ -379,11 +380,11 @@
       ! 1 - Allocate memory !
       ! ------------------- !
-      ALLOCATE( hc_loc_ini(jpi,jpj,jpk), sc_loc_ini(jpi,jpj,jpk), &
-         &      e3t_ini(jpi,jpj,jpk), surf(jpi,jpj),  ssh_ini(jpi,jpj), STAT=ierror )
+      ALLOCATE( hc_loc_ini(jpi,jpj,jpk), sc_loc_ini(jpi,jpj,jpk), surf_ini(jpi,jpj), &
+         &      e3t_ini(jpi,jpj,jpk), surf(jpi,jpj),  ssh_ini(jpi,jpj), STAT=ierror  )
       IF( ierror > 0 ) THEN
          CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN
       ENDIF
 
-      IF(.NOT. lk_vvl ) ALLOCATE( ssh_hc_loc_ini(jpi,jpj), ssh_sc_loc_ini(jpi,jpj),STAT=ierror )
+      IF( ln_linssh )   ALLOCATE( ssh_hc_loc_ini(jpi,jpj), ssh_sc_loc_ini(jpi,jpj),STAT=ierror )
       IF( ierror > 0 ) THEN
          CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90	(revision 6140)
@@ -20,4 +20,5 @@
    USE dom_oce         ! ocean space and time domain
    USE phycst          ! physical constants
+   !
    USE in_out_manager  ! I/O manager
    USE lib_mpp         ! MPP library
@@ -31,5 +32,6 @@
    PUBLIC   dia_hth_alloc ! routine called by nemogcm.F90
 
-   LOGICAL , PUBLIC, PARAMETER          ::   lk_diahth = .TRUE.    !: thermocline-20d depths flag
+   LOGICAL , PUBLIC, PARAMETER ::   lk_diahth = .TRUE.    !: thermocline-20d depths flag
+   
    ! note: following variables should move to local variables once iom_put is always used 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hth    !: depth of the max vertical temperature gradient [m]
@@ -38,6 +40,4 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   htc3   !: heat content of first 300 m                    [W]
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 4.0 , NEMO Consortium (2011)
@@ -52,5 +52,5 @@
       !!---------------------------------------------------------------------
       !
-      ALLOCATE(hth(jpi,jpj), hd20(jpi,jpj), hd28(jpi,jpj), htc3(jpi,jpj), STAT=dia_hth_alloc)
+      ALLOCATE( hth(jpi,jpj), hd20(jpi,jpj), hd28(jpi,jpj), htc3(jpi,jpj), STAT=dia_hth_alloc )
       !
       IF( lk_mpp           )   CALL mpp_sum ( dia_hth_alloc )
@@ -108,7 +108,7 @@
       IF( kt == nit000 ) THEN
          !                                      ! allocate dia_hth array
-         IF( dia_hth_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'lim_sbc_init : unable to allocate standard arrays' )
-
-         IF(.not. ALLOCATED(ik20))THEN
+         IF( dia_hth_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dia_hth : unable to allocate standard arrays' )
+
+         IF(.NOT. ALLOCATED(ik20) ) THEN
             ALLOCATE(ik20(jpi,jpj), ik28(jpi,jpj), &
                &      zabs2(jpi,jpj),   &
@@ -187,5 +187,5 @@
             DO ji = 1, jpi
                !
-               zzdep = fsdepw(ji,jj,jk)
+               zzdep = gdepw_n(ji,jj,jk)
                zztmp = ( tsn(ji,jj,jk-1,jp_tem) - tsn(ji,jj,jk,jp_tem) ) / zzdep * tmask(ji,jj,jk)   ! vertical gradient of temperature (dT/dz)
                zzdep = zzdep * tmask(ji,jj,1)
@@ -223,5 +223,5 @@
             DO ji = 1, jpi
                !
-               zzdep = fsdepw(ji,jj,jk) * tmask(ji,jj,1)
+               zzdep = gdepw_n(ji,jj,jk) * tmask(ji,jj,1)
                !
                zztmp = tsn(ji,jj,nla10,jp_tem) - tsn(ji,jj,jk,jp_tem)  ! - delta T(10m)
@@ -270,10 +270,10 @@
          DO ji = 1, jpi
             !
-            zzdep = fsdepw(ji,jj,mbkt(ji,jj)+1)       ! depth of the oean bottom
+            zzdep = gdepw_n(ji,jj,mbkt(ji,jj)+1)       ! depth of the oean bottom
             !
             iid = ik20(ji,jj)
             IF( iid /= 1 ) THEN 
-               zztmp =      fsdept(ji,jj,iid  )   &                     ! linear interpolation
-                  &  + (    fsdept(ji,jj,iid+1) - fsdept(ji,jj,iid)                       )   &
+               zztmp =      gdept_n(ji,jj,iid  )   &                     ! linear interpolation
+                  &  + (    gdept_n(ji,jj,iid+1) - gdept_n(ji,jj,iid)                       )   &
                   &  * ( 20.*tmask(ji,jj,iid+1) - tsn(ji,jj,iid,jp_tem)                       )   &
                   &  / ( tsn(ji,jj,iid+1,jp_tem) - tsn(ji,jj,iid,jp_tem) + (1.-tmask(ji,jj,1)) )
@@ -285,6 +285,6 @@
             iid = ik28(ji,jj)
             IF( iid /= 1 ) THEN 
-               zztmp =      fsdept(ji,jj,iid  )   &                     ! linear interpolation
-                  &  + (    fsdept(ji,jj,iid+1) - fsdept(ji,jj,iid)                       )   &
+               zztmp =      gdept_n(ji,jj,iid  )   &                     ! linear interpolation
+                  &  + (    gdept_n(ji,jj,iid+1) - gdept_n(ji,jj,iid)                       )   &
                   &  * ( 28.*tmask(ji,jj,iid+1) -    tsn(ji,jj,iid,jp_tem)                       )   &
                   &  / (  tsn(ji,jj,iid+1,jp_tem) -    tsn(ji,jj,iid,jp_tem) + (1.-tmask(ji,jj,1)) )
@@ -311,11 +311,11 @@
       END DO
       ! surface boundary condition
-      IF( lk_vvl ) THEN   ;   zthick(:,:) = 0._wp       ;   htc3(:,:) = 0._wp                                   
-      ELSE                ;   zthick(:,:) = sshn(:,:)   ;   htc3(:,:) = tsn(:,:,1,jp_tem) * sshn(:,:) * tmask(:,:,1)   
+      IF( ln_linssh ) THEN   ;   zthick(:,:) = sshn(:,:)   ;   htc3(:,:) = tsn(:,:,1,jp_tem) * sshn(:,:) * tmask(:,:,1)  
+      ELSE                   ;   zthick(:,:) = 0._wp       ;   htc3(:,:) = 0._wp                                   
       ENDIF
       ! integration down to ilevel
       DO jk = 1, ilevel
-         zthick(:,:) = zthick(:,:) + fse3t(:,:,jk)
-         htc3  (:,:) = htc3  (:,:) + fse3t(:,:,jk) * tsn(:,:,jk,jp_tem) * tmask(:,:,jk)
+         zthick(:,:) = zthick(:,:) + e3t_n(:,:,jk)
+         htc3  (:,:) = htc3  (:,:) + e3t_n(:,:,jk) * tsn(:,:,jk,jp_tem) * tmask(:,:,jk)
       END DO
       ! deepest layer
@@ -323,6 +323,6 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            htc3(ji,jj) = htc3(ji,jj) + tsn(ji,jj,ilevel+1,jp_tem) * MIN( fse3t(ji,jj,ilevel+1), zthick(ji,jj) )  &
-                                                                   * tmask(ji,jj,ilevel+1)
+            htc3(ji,jj) = htc3(ji,jj) + tsn(ji,jj,ilevel+1,jp_tem)                  &
+               &                      * MIN( e3t_n(ji,jj,ilevel+1), zthick(ji,jj) ) * tmask(ji,jj,ilevel+1)
          END DO
       END DO
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/dianam.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/dianam.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/dianam.F90	(revision 6140)
@@ -72,5 +72,5 @@
 
       IF( llfsec .OR. kfreq < 0 ) THEN   ;   inbsec = kfreq                       ! output frequency already in seconds
-      ELSE                               ;   inbsec = kfreq * NINT( rdttra(1) )   ! from time-step to seconds
+      ELSE                               ;   inbsec = kfreq * NINT( rdt )   ! from time-step to seconds
       ENDIF
       iddss = NINT( rday          )                                         ! number of seconds in 1 day
@@ -116,6 +116,6 @@
       ! date of the beginning and the end of the run
 
-      zdrun = rdttra(1) / rday * REAL( nitend - nit000, wp )                ! length of the run in days
-      zjul  = fjulday - rdttra(1) / rday
+      zdrun = rdt / rday * REAL( nitend - nit000, wp )                ! length of the run in days
+      zjul  = fjulday - rdt / rday
       CALL ju2ymds( zjul        , iyear1, imonth1, iday1, zsec1 )           ! year/month/day of the beginning of run
       CALL ju2ymds( zjul + zdrun, iyear2, imonth2, iday2, zsec2 )           ! year/month/day of the end       of run
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 6140)
@@ -59,7 +59,5 @@
    REAL(wp), TARGET, ALLOCATABLE, SAVE, DIMENSION(:,:)   :: p_fval2d
 
-
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -118,11 +116,11 @@
                DO jj = 1, jpj
                   DO ji = 1, jpi
-                     zsfc = e1t(ji,jj) * fse3t(ji,jj,jk)
+                     zsfc = e1t(ji,jj) * e3t_n(ji,jj,jk)
                      zmask(ji,jj,jk)      = tmask(ji,jj,jk)      * zsfc
                      zts(ji,jj,jk,jp_tem) = tsn(ji,jj,jk,jp_tem) * zsfc
                      zts(ji,jj,jk,jp_sal) = tsn(ji,jj,jk,jp_sal) * zsfc
-                  ENDDO
-               ENDDO
-            ENDDO
+                  END DO
+               END DO
+            END DO
             DO jn = 1, nptr
                zmask(1,:,:) = ptr_sjk( zmask(:,:,:), btmsk(:,:,jn) )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diatmb.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diatmb.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diatmb.F90	(revision 6140)
@@ -0,0 +1,169 @@
+MODULE diatmb 
+   !!======================================================================
+   !!                       ***  MODULE  diaharm  ***
+   !! Harmonic analysis of tidal constituents 
+   !!======================================================================
+   !! History :  3.6  !  2014  (E O'Dea)  Original code
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O units
+   USE iom             ! I/0 library
+   USE wrk_nemo        ! working arrays
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   LOGICAL , PUBLIC ::   ln_diatmb     !: Top Middle and Bottom output 
+   PUBLIC   dia_tmb_init            ! routine called by nemogcm.F90
+   PUBLIC   dia_tmb                 ! routine called by diawri.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.6 , NEMO Consortium (2014)
+   !! $Id:$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE dia_tmb_init 
+      !!---------------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_tmb_init  ***
+      !!     
+      !! ** Purpose: Initialization of tmb namelist 
+      !!        
+      !! ** Method : Read namelist
+      !!   History
+      !!   3.6  !  08-14  (E. O'Dea) Routine to initialize dia_tmb
+      !!---------------------------------------------------------------------------
+      !!
+      INTEGER ::   ios                 ! Local integer output status for namelist read
+      !
+      NAMELIST/nam_diatmb/ ln_diatmb
+      !!----------------------------------------------------------------------
+      !
+      REWIND ( numnam_ref )              ! Read Namelist nam_diatmb in reference namelist : TMB diagnostics
+      READ   ( numnam_ref, nam_diatmb, IOSTAT=ios, ERR= 901 )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diatmb in reference namelist', lwp )
+ 
+      REWIND( numnam_cfg )              ! Namelist nam_diatmb in configuration namelist  TMB diagnostics
+      READ  ( numnam_cfg, nam_diatmb, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diatmb in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, nam_diatmb )
+
+      IF(lwp) THEN                   ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'dia_tmb_init : Output Top, Middle, Bottom Diagnostics'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) 'Namelist nam_diatmb : set tmb outputs '
+         WRITE(numout,*) 'Switch for TMB diagnostics (T) or not (F)  ln_diatmb  = ', ln_diatmb
+      ENDIF
+
+   END SUBROUTINE dia_tmb_init
+
+   SUBROUTINE dia_calctmb( pinfield,pouttmb )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_tmb  ***
+      !!                   
+      !! ** Purpose :    Find the Top, Mid and Bottom fields of water Column
+      !!
+      !! ** Method  :   
+      !!      use mbathy to find surface, mid and bottom of model levels
+      !!
+      !! History :
+      !!   3.6  !  08-14  (E. O'Dea) Routine based on dia_wri_foam
+      !!----------------------------------------------------------------------
+      !! * Modules used
+
+      ! Routine to map 3d field to top, middle, bottom
+      IMPLICIT NONE
+
+
+      ! Routine arguments
+      REAL(wp), DIMENSION(jpi, jpj, jpk), INTENT(IN   ) :: pinfield    ! Input 3d field and mask
+      REAL(wp), DIMENSION(jpi, jpj, 3  ), INTENT(  OUT) :: pouttmb     ! Output top, middle, bottom
+
+
+
+      ! Local variables
+      INTEGER :: ji,jj,jk  ! Dummy loop indices
+
+      ! Local Real
+      REAL(wp)                         ::   zmdi  !  set masked values
+
+      zmdi=1.e+20 !missing data indicator for masking
+
+      ! Calculate top
+      pouttmb(:,:,1) = pinfield(:,:,1)*tmask(:,:,1)  + zmdi*(1.0-tmask(:,:,1))
+
+      ! Calculate middle
+      DO jj = 1,jpj
+         DO ji = 1,jpi
+            jk              = max(1,mbathy(ji,jj)/2)
+            pouttmb(ji,jj,2) = pinfield(ji,jj,jk)*tmask(ji,jj,jk)  + zmdi*(1.0-tmask(ji,jj,jk))
+         END DO
+      END DO
+
+      ! Calculate bottom
+      DO jj = 1,jpj
+         DO ji = 1,jpi
+            jk              = max(1,mbathy(ji,jj) - 1)
+            pouttmb(ji,jj,3) = pinfield(ji,jj,jk)*tmask(ji,jj,jk)  + zmdi*(1.0-tmask(ji,jj,jk))
+         END DO
+      END DO
+
+   END SUBROUTINE dia_calctmb
+
+
+
+   SUBROUTINE dia_tmb
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE dia_tmb  ***
+      !! ** Purpose :   Write diagnostics for Top, Mid and Bottom of water Column
+      !!
+      !! ** Method  :   
+      !!      use mbathy to find surface, mid and bottom of model levels
+      !!      calls calctmb to retrieve TMB values before sending to iom_put
+      !!
+      !! History :
+      !!   3.6  !  08-14  (E. O'Dea) 
+      !!         
+      !!--------------------------------------------------------------------
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwtmb    ! temporary workspace 
+      REAL(wp)                         ::   zmdi      ! set masked values
+
+      zmdi=1.e+20 !missing data indicator for maskin
+
+      IF (ln_diatmb) THEN
+         CALL wrk_alloc( jpi , jpj, 3 , zwtmb )
+         CALL dia_calctmb(  tsn(:,:,:,jp_tem),zwtmb )
+         !ssh already output but here we output it masked
+         CALL iom_put( "sshnmasked" , sshn(:,:)*tmask(:,:,1) + zmdi*(1.0 - tmask(:,:,1)) )   ! tmb Temperature
+         CALL iom_put( "top_temp" , zwtmb(:,:,1) )    ! tmb Temperature
+         CALL iom_put( "mid_temp" , zwtmb(:,:,2) )    ! tmb Temperature
+         CALL iom_put( "bot_temp" , zwtmb(:,:,3) )    ! tmb Temperature
+!         CALL iom_put( "sotrefml" , hmld_tref(:,:) )    ! "T criterion Mixed Layer Depth
+
+         CALL dia_calctmb(  tsn(:,:,:,jp_sal),zwtmb )
+         CALL iom_put( "top_sal" , zwtmb(:,:,1) )    ! tmb Salinity 
+         CALL iom_put( "mid_sal" , zwtmb(:,:,2) )    ! tmb Salinity
+         CALL iom_put( "bot_sal" , zwtmb(:,:,3) )    ! tmb Salinity
+
+         CALL dia_calctmb(  un(:,:,:),zwtmb )
+         CALL iom_put( "top_u" , zwtmb(:,:,1) )    ! tmb  U Velocity
+         CALL iom_put( "mid_u" , zwtmb(:,:,2) )    ! tmb  U Velocity
+         CALL iom_put( "bot_u" , zwtmb(:,:,3) )    ! tmb  U Velocity
+!Called in  dynspg_ts.F90        CALL iom_put( "baro_u" , un_b )    ! Barotropic  U Velocity
+
+         CALL dia_calctmb(  vn(:,:,:),zwtmb )
+         CALL iom_put( "top_v" , zwtmb(:,:,1) )    ! tmb  V Velocity
+         CALL iom_put( "mid_v" , zwtmb(:,:,2) )    ! tmb  V Velocity
+         CALL iom_put( "bot_v" , zwtmb(:,:,3) )    ! tmb  V Velocity
+!Called in  dynspg_ts.F90       CALL iom_put( "baro_v" , vn_b )    ! Barotropic  V Velocity
+      ELSE
+         CALL ctl_warn('dia_tmb: tmb diagnostic is set to false you should not have seen this')
+      ENDIF
+
+   END SUBROUTINE dia_tmb
+   !!======================================================================
+END MODULE diatmb
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 6140)
@@ -30,4 +30,5 @@
    USE zdf_oce         ! ocean vertical physics
    USE ldftra          ! lateral physics: eddy diffusivity coef.
+   USE ldfdyn          ! lateral physics: eddy viscosity   coef.
    USE sbc_oce         ! Surface boundary condition: ocean fields
    USE sbc_ice         ! Surface boundary condition: ice fields
@@ -40,7 +41,9 @@
    USE zdfddm          ! vertical  physics: double diffusion
    USE diahth          ! thermocline diagnostics
+   !
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE in_out_manager  ! I/O manager
-   USE diadimg         ! dimg direct access file format output
+   USE diatmb          ! Top,middle,bottom output
+   USE dia25h          ! 25h Mean output
    USE iom
    USE ioipsl
@@ -53,4 +56,6 @@
    USE lib_mpp         ! MPP library
    USE timing          ! preformance summary
+   USE diurnal_bulk    ! diurnal warm layer
+   USE cool_skin       ! Cool skin
    USE wrk_nemo        ! working array
 
@@ -74,5 +79,4 @@
    !! * Substitutions
 #  include "zdfddm_substitute.h90"
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -97,15 +101,8 @@
   END FUNCTION dia_wri_alloc
 
-#if defined key_dimgout
-   !!----------------------------------------------------------------------
-   !!   'key_dimgout'                                      DIMG output file
-   !!----------------------------------------------------------------------
-#   include "diawri_dimg.h90"
-
-#else
    !!----------------------------------------------------------------------
    !!   Default option                                   NetCDF output file
    !!----------------------------------------------------------------------
-# if defined key_iomput
+#if defined key_iomput
    !!----------------------------------------------------------------------
    !!   'key_iomput'                                        use IOM library
@@ -143,9 +140,9 @@
       ENDIF
 
-      IF( .NOT.lk_vvl ) THEN
-         CALL iom_put( "e3t" , fse3t_n(:,:,:) )
-         CALL iom_put( "e3u" , fse3u_n(:,:,:) )
-         CALL iom_put( "e3v" , fse3v_n(:,:,:) )
-         CALL iom_put( "e3w" , fse3w_n(:,:,:) )
+      IF( ln_linssh ) THEN
+         CALL iom_put( "e3t" , e3t_n(:,:,:) )
+         CALL iom_put( "e3u" , e3u_n(:,:,:) )
+         CALL iom_put( "e3v" , e3v_n(:,:,:) )
+         CALL iom_put( "e3w" , e3w_n(:,:,:) )
       ENDIF
 
@@ -204,10 +201,4 @@
          CALL iom_put( "sbu", z2d )                ! bottom i-current
       ENDIF
-
-      IF ( ln_dynspg_ts ) THEN
-         CALL iom_put(  "ubar", un_adv(:,:)      )    ! barotropic i-current
-      ELSE
-         CALL iom_put(  "ubar", un_b(:,:)        )    ! barotropic i-current
-      ENDIF
       
       CALL iom_put( "voce", vn(:,:,:)         )    ! 3D j-current
@@ -223,10 +214,4 @@
       ENDIF
 
-      IF ( ln_dynspg_ts ) THEN
-         CALL iom_put(  "vbar", vn_adv(:,:)      )    ! barotropic j-current
-      ELSE
-         CALL iom_put(  "vbar", vn_b(:,:)        )    ! barotropic j-current
-      ENDIF
-
       CALL iom_put( "woce", wn )                   ! vertical velocity
       IF( iom_use('w_masstr') .OR. iom_use('w_masstr2') ) THEN   ! vertical mass transport & its square value
@@ -266,5 +251,5 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  z2d(ji,jj) = z2d(ji,jj) + fse3t(ji,jj,jk) * tsn(ji,jj,jk,jp_tem) * tmask(ji,jj,jk)
+                  z2d(ji,jj) = z2d(ji,jj) + e3t_n(ji,jj,jk) * tsn(ji,jj,jk,jp_tem) * tmask(ji,jj,jk)
                END DO
             END DO
@@ -278,5 +263,5 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  z2d(ji,jj) = z2d(ji,jj) + fse3t(ji,jj,jk) * tsn(ji,jj,jk,jp_sal) * tmask(ji,jj,jk)
+                  z2d(ji,jj) = z2d(ji,jj) + e3t_n(ji,jj,jk) * tsn(ji,jj,jk,jp_sal) * tmask(ji,jj,jk)
                END DO
             END DO
@@ -290,11 +275,11 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zztmp   = 1._wp / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
-                  zztmpx  = 0.5 * (  un(ji-1,jj,jk) * un(ji-1,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk)    &
-                     &             + un(ji  ,jj,jk) * un(ji  ,jj,jk) * e2u(ji  ,jj) * fse3u(ji  ,jj,jk) )  &
+                  zztmp   = 1._wp / ( e1e2t(ji,jj) * e3t_n(ji,jj,jk) )
+                  zztmpx  = 0.5 * (  un(ji-1,jj,jk) * un(ji-1,jj,jk) * e2u(ji-1,jj) * e3u_n(ji-1,jj,jk)    &
+                     &             + un(ji  ,jj,jk) * un(ji  ,jj,jk) * e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) )  &
                      &          *  zztmp 
                   !
-                  zztmpy  = 0.5 * (  vn(ji,jj-1,jk) * vn(ji,jj-1,jk) * e1v(ji,jj-1) * fse3v(ji,jj-1,jk)    &
-                     &             + vn(ji,jj  ,jk) * vn(ji,jj  ,jk) * e1v(ji,jj  ) * fse3v(ji,jj  ,jk) )  &
+                  zztmpy  = 0.5 * (  vn(ji,jj-1,jk) * vn(ji,jj-1,jk) * e1v(ji,jj-1) * e3v_n(ji,jj-1,jk)    &
+                     &             + vn(ji,jj  ,jk) * vn(ji,jj  ,jk) * e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) )  &
                      &          *  zztmp 
                   !
@@ -311,5 +296,5 @@
          z3d(:,:,jpk) = 0.e0
          DO jk = 1, jpkm1
-            z3d(:,:,jk) = rau0 * un(:,:,jk) * e2u(:,:) * fse3u(:,:,jk) * umask(:,:,jk)
+            z3d(:,:,jk) = rau0 * un(:,:,jk) * e2u(:,:) * e3u_n(:,:,jk) * umask(:,:,jk)
          END DO
          CALL iom_put( "u_masstr", z3d )                  ! mass transport in i-direction
@@ -346,5 +331,5 @@
          z3d(:,:,jpk) = 0.e0
          DO jk = 1, jpkm1
-            z3d(:,:,jk) = rau0 * vn(:,:,jk) * e1v(:,:) * fse3v(:,:,jk) * vmask(:,:,jk)
+            z3d(:,:,jk) = rau0 * vn(:,:,jk) * e1v(:,:) * e3v_n(:,:,jk) * vmask(:,:,jk)
          END DO
          CALL iom_put( "v_masstr", z3d )                  ! mass transport in j-direction
@@ -380,4 +365,13 @@
       CALL wrk_dealloc( jpi , jpj, jpk , z3d )
       !
+      ! If we want tmb values 
+
+      IF (ln_diatmb) THEN
+         CALL dia_tmb 
+      ENDIF 
+      IF (ln_dia25h) THEN
+         CALL dia_25h( kt )
+      ENDIF 
+
       IF( nn_timing == 1 )   CALL timing_stop('dia_wri')
       !
@@ -410,5 +404,5 @@
       INTEGER  ::   iimi, iima, ipk, it, itmod, ijmi, ijma   ! local integers
       INTEGER  ::   jn, ierror                               ! local integers
-      REAL(wp) ::   zsto, zout, zmax, zjulian, zdt           ! local scalars
+      REAL(wp) ::   zsto, zout, zmax, zjulian                ! local scalars
       !
       REAL(wp), POINTER, DIMENSION(:,:)   :: zw2d       ! 2D workspace
@@ -418,6 +412,6 @@
       IF( nn_timing == 1 )   CALL timing_start('dia_wri')
       !
-                     CALL wrk_alloc( jpi,jpj      , zw2d )
-      IF( lk_vvl )   CALL wrk_alloc( jpi,jpj,jpk  , zw3d )
+                             CALL wrk_alloc( jpi,jpj      , zw2d )
+      IF( .NOT.ln_linssh )   CALL wrk_alloc( jpi,jpj,jpk  , zw3d )
       !
       ! Output the initial state and forcings
@@ -435,16 +429,14 @@
 
       ! Define frequency of output and means
-      zdt = rdt
-      IF( nacc == 1 ) zdt = rdtmin
       clop = "x"         ! no use of the mask value (require less cpu time and otherwise the model crashes)
 #if defined key_diainstant
-      zsto = nwrite * zdt
+      zsto = nwrite * rdt
       clop = "inst("//TRIM(clop)//")"
 #else
-      zsto=zdt
+      zsto=rdt
       clop = "ave("//TRIM(clop)//")"
 #endif
-      zout = nwrite * zdt
-      zmax = ( nitend - nit000 + 1 ) * zdt
+      zout = nwrite * rdt
+      zmax = ( nitend - nit000 + 1 ) * rdt
 
       ! Define indices of the horizontal output zoom and vertical limit storage
@@ -488,5 +480,5 @@
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_T, nid_T, domain_id=nidom, snc4chunks=snc4set )
+            &          nit000-1, zjulian, rdt, nh_T, nid_T, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_T, "deptht", "Vertical T levels",      &  ! Vertical grid: gdept
             &           "m", ipk, gdept_1d, nz_T, "down" )
@@ -524,5 +516,5 @@
          CALL histbeg( clhstnam, jpi, glamu, jpj, gphiu,           &  ! Horizontal grid: glamu and gphiu
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_U, nid_U, domain_id=nidom, snc4chunks=snc4set )
+            &          nit000-1, zjulian, rdt, nh_U, nid_U, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_U, "depthu", "Vertical U levels",      &  ! Vertical grid: gdept
             &           "m", ipk, gdept_1d, nz_U, "down" )
@@ -537,5 +529,5 @@
          CALL histbeg( clhstnam, jpi, glamv, jpj, gphiv,           &  ! Horizontal grid: glamv and gphiv
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_V, nid_V, domain_id=nidom, snc4chunks=snc4set )
+            &          nit000-1, zjulian, rdt, nh_V, nid_V, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_V, "depthv", "Vertical V levels",      &  ! Vertical grid : gdept
             &          "m", ipk, gdept_1d, nz_V, "down" )
@@ -550,5 +542,5 @@
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_W, nid_W, domain_id=nidom, snc4chunks=snc4set )
+            &          nit000-1, zjulian, rdt, nh_W, nid_W, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_W, "depthw", "Vertical W levels",      &  ! Vertical grid: gdepw
             &          "m", ipk, gdepw_1d, nz_W, "down" )
@@ -562,5 +554,5 @@
          CALL histdef( nid_T, "vosaline", "Salinity"                           , "PSU"    ,   &  ! sn
             &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
-         IF(  lk_vvl  ) THEN
+         IF(  .NOT.ln_linssh  ) THEN
             CALL histdef( nid_T, "vovvle3t", "Level thickness"                    , "m"      ,&  ! e3t_n
             &             jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
@@ -583,5 +575,5 @@
          CALL histdef( nid_T, "sosfldow", "downward salt flux"                 , "PSU/m2/s",  &  ! sfx
             &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         IF(  .NOT. lk_vvl  ) THEN
+         IF(  ln_linssh  ) THEN
             CALL histdef( nid_T, "sosst_cd", "Concentration/Dilution term on temperature"     &  ! emp * tsn(:,:,1,jp_tem)
             &                                                                  , "KgC/m2/s",  &  ! sosst_cd
@@ -729,9 +721,9 @@
       ENDIF
 
-      IF( lk_vvl ) THEN
-         CALL histwrite( nid_T, "votemper", it, tsn(:,:,:,jp_tem) * fse3t_n(:,:,:) , ndim_T , ndex_T  )   ! heat content
-         CALL histwrite( nid_T, "vosaline", it, tsn(:,:,:,jp_sal) * fse3t_n(:,:,:) , ndim_T , ndex_T  )   ! salt content
-         CALL histwrite( nid_T, "sosstsst", it, tsn(:,:,1,jp_tem) * fse3t_n(:,:,1) , ndim_hT, ndex_hT )   ! sea surface heat content
-         CALL histwrite( nid_T, "sosaline", it, tsn(:,:,1,jp_sal) * fse3t_n(:,:,1) , ndim_hT, ndex_hT )   ! sea surface salinity content
+      IF( .NOT.ln_linssh ) THEN
+         CALL histwrite( nid_T, "votemper", it, tsn(:,:,:,jp_tem) * e3t_n(:,:,:) , ndim_T , ndex_T  )   ! heat content
+         CALL histwrite( nid_T, "vosaline", it, tsn(:,:,:,jp_sal) * e3t_n(:,:,:) , ndim_T , ndex_T  )   ! salt content
+         CALL histwrite( nid_T, "sosstsst", it, tsn(:,:,1,jp_tem) * e3t_n(:,:,1) , ndim_hT, ndex_hT )   ! sea surface heat content
+         CALL histwrite( nid_T, "sosaline", it, tsn(:,:,1,jp_sal) * e3t_n(:,:,1) , ndim_hT, ndex_hT )   ! sea surface salinity content
       ELSE
          CALL histwrite( nid_T, "votemper", it, tsn(:,:,:,jp_tem) , ndim_T , ndex_T  )   ! temperature
@@ -740,8 +732,8 @@
          CALL histwrite( nid_T, "sosaline", it, tsn(:,:,1,jp_sal) , ndim_hT, ndex_hT )   ! sea surface salinity
       ENDIF
-      IF( lk_vvl ) THEN
-         zw3d(:,:,:) = ( ( fse3t_n(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2
-         CALL histwrite( nid_T, "vovvle3t", it, fse3t_n (:,:,:) , ndim_T , ndex_T  )   ! level thickness
-         CALL histwrite( nid_T, "vovvldep", it, fsdept_n(:,:,:) , ndim_T , ndex_T  )   ! t-point depth
+      IF( .NOT.ln_linssh ) THEN
+         zw3d(:,:,:) = ( ( e3t_n(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2
+         CALL histwrite( nid_T, "vovvle3t", it, e3t_n (:,:,:) , ndim_T , ndex_T  )   ! level thickness
+         CALL histwrite( nid_T, "vovvldep", it, gdept_n(:,:,:) , ndim_T , ndex_T  )   ! t-point depth
          CALL histwrite( nid_T, "vovvldef", it, zw3d             , ndim_T , ndex_T  )   ! level thickness deformation
       ENDIF
@@ -752,5 +744,5 @@
                                                                                   ! (includes virtual salt flux beneath ice 
                                                                                   ! in linear free surface case)
-      IF( .NOT. lk_vvl ) THEN
+      IF( ln_linssh ) THEN
          zw2d(:,:) = emp (:,:) * tsn(:,:,1,jp_tem)
          CALL histwrite( nid_T, "sosst_cd", it, zw2d, ndim_hT, ndex_hT )          ! c/d term on sst
@@ -837,12 +829,10 @@
       ENDIF
       !
-                     CALL wrk_dealloc( jpi , jpj        , zw2d )
-      IF( lk_vvl )   CALL wrk_dealloc( jpi , jpj , jpk  , zw3d )
+                             CALL wrk_dealloc( jpi , jpj        , zw2d )
+      IF( .NOT.ln_linssh )   CALL wrk_dealloc( jpi , jpj , jpk  , zw3d )
       !
       IF( nn_timing == 1 )   CALL timing_stop('dia_wri')
       !
    END SUBROUTINE dia_wri
-# endif
-
 #endif
 
@@ -867,5 +857,5 @@
       INTEGER  ::   id_i , nz_i, nh_i       
       INTEGER, DIMENSION(1) ::   idex             ! local workspace
-      REAL(wp) ::   zsto, zout, zmax, zjulian, zdt
+      REAL(wp) ::   zsto, zout, zmax, zjulian
       !!----------------------------------------------------------------------
       ! 
@@ -876,9 +866,8 @@
       clname = cdfile_name
       IF( .NOT. Agrif_Root() ) clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
-      zdt  = rdt
       zsto = rdt
       clop = "inst(x)"           ! no use of the mask value (require less cpu time)
       zout = rdt
-      zmax = ( nitend - nit000 + 1 ) * zdt
+      zmax = ( nitend - nit000 + 1 ) * rdt
 
       IF(lwp) WRITE(numout,*)
@@ -895,5 +884,5 @@
       zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
       CALL histbeg( clname, jpi, glamt, jpj, gphit,   &
-          1, jpi, 1, jpj, nit000-1, zjulian, zdt, nh_i, id_i, domain_id=nidom, snc4chunks=snc4set ) ! Horizontal grid : glamt and gphit
+          1, jpi, 1, jpj, nit000-1, zjulian, rdt, nh_i, id_i, domain_id=nidom, snc4chunks=snc4set ) ! Horizontal grid : glamt and gphit
       CALL histvert( id_i, "deptht", "Vertical T levels",   &    ! Vertical grid : gdept
           "m", jpk, gdept_1d, nz_i, "down")
@@ -913,4 +902,14 @@
       CALL histdef( id_i, "vovecrtz", "Vertical Velocity"     , "m/s"    ,   &   ! vertical current
          &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout ) 
+         !
+      CALL histdef( id_i, "ahtu"    , "u-eddy diffusivity"    , "m2/s"    ,   &   ! zonal current
+         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
+      CALL histdef( id_i, "ahtv"    , "v-eddy diffusivity"    , "m2/s"    ,   &   ! meridonal current
+         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout ) 
+      CALL histdef( id_i, "ahmt"    , "t-eddy viscosity"      , "m2/s"    ,   &   ! zonal current
+         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
+      CALL histdef( id_i, "ahmf"    , "f-eddy viscosity"      , "m2/s"    ,   &   ! meridonal current
+         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout ) 
+         !
       CALL histdef( id_i, "sowaflup", "Net Upward Water Flux" , "Kg/m2/S",   &   ! net freshwater 
          &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
@@ -925,6 +924,8 @@
       CALL histdef( id_i, "sometauy", "Meridional Wind Stress", "N/m2"   ,   &   ! j-wind stress
          &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      IF( lk_vvl ) THEN
-         CALL histdef( id_i, "vovvldep", "T point depth"         , "m"      ,   &   ! t-point depth
+      IF( .NOT.ln_linssh ) THEN
+         CALL histdef( id_i, "vovvldep", "T point depth"         , "m"      , &   ! t-point depth
+            &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
+         CALL histdef( id_i, "vovvle3t", "T point thickness"     , "m"      , &   ! t-point depth
             &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
       ENDIF
@@ -952,4 +953,10 @@
       CALL histwrite( id_i, "vomecrty", kt, vn               , jpi*jpj*jpk, idex )    ! now j-velocity
       CALL histwrite( id_i, "vovecrtz", kt, wn               , jpi*jpj*jpk, idex )    ! now k-velocity
+      !
+      CALL histwrite( id_i, "ahtu"    , kt, ahtu             , jpi*jpj*jpk, idex )    ! aht at u-point
+      CALL histwrite( id_i, "ahtv"    , kt, ahtv             , jpi*jpj*jpk, idex )    !  -  at v-point
+      CALL histwrite( id_i, "ahmt"    , kt, ahmt             , jpi*jpj*jpk, idex )    ! ahm at t-point
+      CALL histwrite( id_i, "ahmf"    , kt, ahmf             , jpi*jpj*jpk, idex )    !  -  at f-point
+      !
       CALL histwrite( id_i, "sowaflup", kt, emp-rnf          , jpi*jpj    , idex )    ! freshwater budget
       CALL histwrite( id_i, "sohefldo", kt, qsr + qns        , jpi*jpj    , idex )    ! total heat flux
@@ -959,8 +966,12 @@
       CALL histwrite( id_i, "sometauy", kt, vtau             , jpi*jpj    , idex )    ! j-wind stress
 
+      IF(  .NOT.ln_linssh  ) THEN             
+         CALL histwrite( id_i, "vovvldep", kt, gdept_n(:,:,:), jpi*jpj*jpk, idex )!  T-cell depth 
+         CALL histwrite( id_i, "vovvle3t", kt, e3t_n (:,:,:) , jpi*jpj*jpk, idex )!  T-cell thickness  
+      END IF 
       ! 3. Close the file
       ! -----------------
       CALL histclo( id_i )
-#if ! defined key_iomput && ! defined key_dimgout
+#if ! defined key_iomput
       IF( ninist /= 1  ) THEN
          CALL histclo( nid_T )
@@ -972,4 +983,5 @@
       ! 
    END SUBROUTINE dia_wri_state
+
    !!======================================================================
 END MODULE diawri
Index: unk/NEMOGCM/NEMO/OPA_SRC/DIA/diawri_dimg.h90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIA/diawri_dimg.h90	(revision 6139)
+++ 	(revision )
@@ -1,372 +1,0 @@
-  !!----------------------------------------------------------------------
-  !!                        ***  diawri_dimg.h90  ***
-  !!----------------------------------------------------------------------
-  !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-  !! $Id $
-  !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-  !!----------------------------------------------------------------------
-
-  SUBROUTINE dia_wri( kt )
-    !!----------------------------------------------------------------------
-    !!           *** routine dia_wri ***
-    !!
-    !! ** Purpose : output dynamics and tracer fields on direct access file
-    !!              suitable for MPP computing
-    !!
-    !! ** define key : 'key_dimgout'
-    !!
-    !! **  Method : Default is to cumulate the values over the interval between
-    !!      2 output, and each nwrite time-steps  the mean value is  computed 
-    !!      and written to the direct access file.
-    !!     If 'key_diainstant' is defined, no mean values are computed and the 
-    !!     instantaneous fields are dump.
-    !!       Each processor creates its own file with its local data
-    !!     Merging all the files is performed off line by a dedicated program
-    !!
-    !! ** Arguments :
-    !!     kt      : time-step number
-    !!     kindinc :  error condition indicator : >=0 :  OK, < 0 : error.
-    !!
-    !! ** Naming convention for files
-    !!
-    !! {cexper}_{var}_y----m--d--.dimg
-    !!   cexper is the name of the experience, given in the namelist
-    !!   var can be either U, V, T, S, KZ, SSH, ...
-    !!   var can also be 2D, which means that each level of the file is a 2D field as described below
-    !!    y----m--d--  is the date at the time of the dump
-    !!    For mpp output, each processor dumps its own memory, on appropriate record range 
-    !!    (direct access : for level jk of a klev field on proc narea irec = 1+ klev*(narea -1) + jk )
-    !!    To be tested with a lot of procs !!!!
-    !!
-    !!  level 1:  utau(:,:) * umask(:,:,1) zonal stress in N.m-2
-    !!  level 2:  vtau(:,:) * vmask(:,:,1) meridional stress in N. m-2
-    !!  level 3:  qsr + qns                total heat flux (W/m2)
-    !!  level 4:  ( emp (:,:)-rnf(:,:) )   E-P flux (mm/day)
-    !!  level 5:  tb  (:,:,1)-sst          model SST -forcing sst (degree C) ! deprecated
-    !!  level 6:  bsfb(:,:)		   streamfunction (m**3/s)
-    !!  level 7:  qsr (:,:)		   solar flux (W/m2)
-    !!  level 8:  qrp (:,:)                relax component of T flux.
-    !!  level 9:  erp (:,:)                relax component of S flux
-    !!  level 10: hmld(:,:)                turbocline depth
-    !!  level 11: hmlp(:,:)                mixed layer depth
-    !!  level 12: fr_i(:,:)                ice fraction (between 0 and 1)
-    !!  level 13: sst(:,:)                 the observed SST we relax to. ! deprecated
-    !!  level 14: qct(:,:)                 equivalent flux due to treshold SST
-    !!  level 15: fbt(:,:)                 feedback term .
-    !!  level 16: ( emp * sss )            concentration/dilution term on salinity
-    !!  level 17: ( emp * sst )            concentration/dilution term on temperature
-    !!  level 17: fsalt(:,:)               Ice=>ocean net freshwater
-    !!  level 18: gps(:,:)                 the surface pressure (m).
-    !!  level 19: spgu(:,:)                the surface pressure gradient in X direction.
-    !!  level 20: spgv(:,:)                the surface pressure gradient in Y direction.
-    !! 
-    !! History:  OPA  ! 1997-02 ( Clipper Group ) dimg files
-    !!            -   ! 2003-12 ( J.M. Molines) f90, mpp output for OPA9.0
-    !!   NEMO    1.0  ! 2005-05  (S. Theetten) add emps fsalt move gps spgu spgv 2 lines below
-    !!            -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
-    !!----------------------------------------------------------------------
-    USE lib_mpp
-    !!
-    INTEGER ,INTENT(in) :: kt
-    !!
-#if defined key_diainstant
-    LOGICAL, PARAMETER :: ll_dia_inst=.TRUE.  !: for instantaneous output
-#else
-    LOGICAL, PARAMETER :: ll_dia_inst=.FALSE. !: for average output
-#endif
-    INTEGER              , SAVE                    ::  nmoyct 
-    REAL(wp), ALLOCATABLE, SAVE, DIMENSION (:,:,:) ::  um , vm, wm   ! mean u, v, w fields
-    REAL(wp), ALLOCATABLE, SAVE, DIMENSION (:,:,:) ::  avtm          ! mean kz fields
-    REAL(wp), ALLOCATABLE, SAVE, DIMENSION (:,:,:) ::  tm , sm       ! mean t, s fields
-    REAL(wp), ALLOCATABLE, SAVE, DIMENSION (:,:,:) ::  fsel          ! mean 2d fields
-    
-    INTEGER :: inbsel, jk
-    INTEGER :: iyear,imon,iday
-    INTEGER :: ialloc
-    REAL(wp) :: zdtj
-    CHARACTER(LEN=80) :: clname
-    CHARACTER(LEN=80) :: cltext
-    CHARACTER(LEN=80) :: clmode
-    CHARACTER(LEN= 4) :: clver
-    !!----------------------------------------------------------------------
-    IF( nn_timing == 1 )   CALL timing_start('dia_wri')
-    !
-    !  Initialization
-    !  ---------------
-    !
-    IF( .NOT. ALLOCATED(um) )THEN
-       ALLOCATE(um(jpi,jpj,jpk), vm(jpi,jpj,jpk), &
-                wm(jpi,jpj,jpk),                  &
-                avtm(jpi,jpj,jpk),                &
-                tm(jpi,jpj,jpk), sm(jpi,jpj,jpk), &
-                fsel(jpi,jpj,jpk),                &
-                STAT=ialloc )
-       !
-       IF( lk_mpp      )   CALL mpp_sum ( ialloc  )
-       IF( ialloc /= 0 )   CALL ctl_warn('dia_wri( diawri_dimg.h90) : failed to allocate arrays')
-    ENDIF
-
-
-    inbsel = 18
-
-    IF( inbsel >  jpk ) THEN
-       IF(lwp) WRITE(numout,*)  ' STOP inbsel =',inbsel,' is larger than jpk=',jpk
-       STOP
-    ENDIF
-
-    iyear = ndastp/10000
-    imon = (ndastp-iyear*10000)/100
-    iday = ndastp - imon*100 - iyear*10000
-
-    !     
-    !! dimg format V1.0 should start with the 4 char. string '@!01'
-    !!
-    clver='@!01'
-    !
-    IF( .NOT. ll_dia_inst ) THEN
-       !
-       !! * Mean output section
-       !! ----------------------
-       !
-       IF( kt == nit000 .AND. lwp ) WRITE(numout,*) &
-            'THE OUTPUT FILES CONTAINS THE AVERAGE OF EACH FIELD'
-       !
-       IF( kt == nit000  ) THEN
-          ! reset arrays for average computation
-          nmoyct = 0
-          !
-          um(:,:,:) = 0._wp
-          vm(:,:,:) = 0._wp
-          wm(:,:,:) = 0._wp
-          avtm(:,:,:) = 0._wp
-          tm(:,:,:) = 0._wp
-          sm(:,:,:) = 0._wp
-          fsel(:,:,:) = 0._wp
-          !
-       ENDIF
-
-       !  cumulate values
-       !  ---------------
-
-       nmoyct = nmoyct+1
-       !
-       um(:,:,:)=um(:,:,:) + un (:,:,:)
-       vm(:,:,:)=vm(:,:,:) + vn (:,:,:)
-       wm(:,:,:)=wm(:,:,:) + wn (:,:,:)
-       avtm(:,:,:)=avtm(:,:,:) + avt (:,:,:)
-       tm(:,:,:)=tm(:,:,:) + tsn(:,:,:,jp_tem)
-       sm(:,:,:)=sm(:,:,:) + tsn(:,:,:,jp_sal)
-       !
-       fsel(:,:,1 ) = fsel(:,:,1 ) + utau(:,:) * umask(:,:,1)
-       fsel(:,:,2 ) = fsel(:,:,2 ) + vtau(:,:) * vmask(:,:,1)
-       fsel(:,:,3 ) = fsel(:,:,3 ) + qsr (:,:) + qns  (:,:) 
-       fsel(:,:,4 ) = fsel(:,:,4 ) + ( emp(:,:)-rnf(:,:) ) 
-       !        fsel(:,:,5 ) = fsel(:,:,5 ) + tsb(:,:,1,jp_tem)  !RB not used
-       fsel(:,:,6 ) = fsel(:,:,6 ) + sshn(:,:) 
-       fsel(:,:,7 ) = fsel(:,:,7 ) + qsr(:,:)
-       IF( ln_ssr ) THEN
-          IF( nn_sstr /= 0 )   fsel(:,:,8 ) = fsel(:,:,8 ) + qrp (:,:)
-          IF( nn_sssr /= 0 )   fsel(:,:,9 ) = fsel(:,:,9 ) + erp (:,:)
-       ENDIF
-       fsel(:,:,10) = fsel(:,:,10) + hmld(:,:)
-       fsel(:,:,11) = fsel(:,:,11) + hmlp(:,:)
-       fsel(:,:,12) = fsel(:,:,12) + fr_i(:,:)
-       !        fsel(:,:,13) = fsel(:,:,13)   !RB not used
-       !        fsel(:,:,14) = fsel(:,:,14) + qct(:,:)
-       !        fsel(:,:,15) = fsel(:,:,15) + fbt(:,:)
-       fsel(:,:,16) = fsel(:,:,16) + ( emp(:,:)*tsn(:,:,1,jp_sal) ) 
-       fsel(:,:,17) = fsel(:,:,17) + ( emp(:,:)*tsn(:,:,1,jp_tem) ) 
-       !
-       ! Output of dynamics and tracer fields and selected fields
-       ! --------------------------------------------------------
-       !
-       !
-       zdtj=rdt/86400.   ! time step in days
-       WRITE(clmode,'(f5.1,a)' ) nwrite*zdtj,' days average'
-
-       !       iwrite=NINT(adatrj/rwrite)
-       !      IF (abs(adatrj-iwrite*rwrite) < zdtj/2.      &
-
-       IF(  ( MOD (kt-nit000+1,nwrite) ==  0 )          &
-            &   .OR. ( kt == 1 .AND. ninist ==1 )  ) THEN
-          ! it is time to make a dump on file 
-          ! compute average
-          um(:,:,:) = um(:,:,:) / nmoyct
-          vm(:,:,:) = vm(:,:,:) / nmoyct
-          wm(:,:,:) = wm(:,:,:) / nmoyct
-          avtm(:,:,:) = avtm(:,:,:) / nmoyct
-          tm(:,:,:) = tm(:,:,:) / nmoyct
-          sm(:,:,:) = sm(:,:,:) / nmoyct
-          !
-          fsel(:,:,:) = fsel(:,:,:) / nmoyct
-          !
-          ! note : the surface pressure is not averaged, but rather 
-          ! computed from the averaged gradients.
-          !
-          ! mask mean field with tmask except utau vtau (1,2)
-          DO jk=3,inbsel
-            fsel(:,:,jk)=fsel(:,:,jk)*tmask(:,:,1)
-          END DO
-       ENDIF
-       !
-    ELSE   ! ll_dia_inst true
-       !
-       !! * Instantaneous output section
-       !! ------------------------------
-       !
-       IF( kt == nit000 .AND. lwp ) WRITE(numout,*) &
-            'THE OUTPUT FILES CONTAINS INSTANTANEOUS VALUES OF EACH FIELD'
-       !
-       zdtj=rdt/86400.   ! time step in days
-       !  iwrite=NINT(adatrj/rwrite)
-       clmode='instantaneous'
-       !     IF (abs(adatrj-iwrite*rwrite) < zdtj/2.  &
-       IF (  ( MOD (kt-nit000+1,nwrite) ==  0 )          &
-            &   .OR. ( kt == 1 .AND. ninist == 1 )  ) THEN
-          !
-          ! transfer wp arrays to sp arrays for dimg files
-          fsel(:,:,:) = 0._wp
-          !
-          fsel(:,:,1 ) = utau(:,:) * umask(:,:,1)
-          fsel(:,:,2 ) = vtau(:,:) * vmask(:,:,1)
-          fsel(:,:,3 ) = (qsr (:,:) + qns (:,:)) * tmask(:,:,1)
-          fsel(:,:,4 ) = ( emp(:,:)-rnf(:,:) ) * tmask(:,:,1) 
-          !         fsel(:,:,5 ) = (tsb(:,:,1,jp_tem) - sf_sst(1)%fnow(:,:) ) *tmask(:,:,1) !RB not used
-
-          fsel(:,:,6 ) = sshn(:,:)
-          fsel(:,:,7 ) = qsr (:,:) * tmask(:,:,1)
-          IF( ln_ssr ) THEN
-             IF( nn_sstr /= 0 )   fsel(:,:,8 ) = qrp (:,:) * tmask(:,:,1)
-             IF( nn_sssr /= 0 )   fsel(:,:,9 ) = erp (:,:) * tmask(:,:,1)
-          ENDIF
-          fsel(:,:,10) = hmld(:,:) * tmask(:,:,1)
-          fsel(:,:,11) = hmlp(:,:) * tmask(:,:,1)
-          fsel(:,:,12) = fr_i(:,:) * tmask(:,:,1)
-          !         fsel(:,:,13) = sf_sst(1)%fnow(:,:) !RB not used
-          !         fsel(:,:,14) =  qct(:,:)
-          !         fsel(:,:,15) =  fbt(:,:)
-          fsel(:,:,16) = ( emp(:,:)-tsn(:,:,1,jp_sal) ) * tmask(:,:,1) 
-          fsel(:,:,17) = ( emp(:,:)-tsn(:,:,1,jp_tem) ) * tmask(:,:,1) 
-          !
-          !         qct(:,:) = 0._wp
-       ENDIF
-    ENDIF
-    !
-    ! Opening of the datrj.out file with the absolute time in day of each dump
-    ! this file gives a record of the dump date for post processing ( ASCII file )
-    !
-    IF(  ( MOD (kt-nit000+1,nwrite) ==  0 )          &
-         &   .OR. ( kt == 1 .AND. ninist == 1 )  ) THEN
-
-       IF( lwp) WRITE(numout,*)'Days since the begining of the run :',adatrj
-
-       !! * U section
-
-       WRITE(clname,9000) TRIM(cexper),'U',iyear,imon,iday
-       cltext=TRIM(cexper)//' U(m/s) '//TRIM(clmode)
-       !
-       IF( ll_dia_inst) THEN   ;   CALL dia_wri_dimg(clname, cltext, un, jpk, 'T')
-       ELSE                    ;   CALL dia_wri_dimg(clname, cltext, um, jpk, 'T')
-       ENDIF
-
-       !! * V section
-
-       WRITE(clname,9000) TRIM(cexper),'V',iyear,imon,iday
-       cltext=TRIM(cexper)//' V(m/s) '//TRIM(clmode)
-       !
-       IF( ll_dia_inst) THEN
-          CALL dia_wri_dimg(clname, cltext, vn, jpk, 'T')
-       ELSE
-          CALL dia_wri_dimg(clname, cltext, vm, jpk, 'T')
-       ENDIF
-       !
-
-       !! * KZ section
-
-       WRITE(clname,9000) TRIM(cexper),'KZ',iyear,imon,iday
-       cltext=TRIM(cexper)//' KZ(m2/s) '//TRIM(clmode)
-
-       IF( ll_dia_inst) THEN
-          CALL dia_wri_dimg(clname, cltext, avt, jpk, 'W')
-       ELSE
-          CALL dia_wri_dimg(clname, cltext, avtm, jpk, 'W')
-       ENDIF
-       !
-
-       !! * W section
-
-       WRITE(clname,9000) TRIM(cexper),'W',iyear,imon,iday
-       cltext=TRIM(cexper)//' W(m/s) '//TRIM(clmode)
-
-       IF( ll_dia_inst) THEN
-          CALL dia_wri_dimg(clname, cltext, wn, jpk, 'W')
-       ELSE
-          CALL dia_wri_dimg(clname, cltext, wm, jpk, 'W')
-       ENDIF
-
-       !! * T section
-
-       WRITE(clname,9000) TRIM(cexper),'T',iyear,imon,iday
-       cltext=TRIM(cexper)//' T (DegC) '//TRIM(clmode)
-
-       IF( ll_dia_inst) THEN
-          CALL dia_wri_dimg(clname, cltext, tsn(:,:,:,jp_tem), jpk, 'T')
-       ELSE
-          CALL dia_wri_dimg(clname, cltext, tm               , jpk, 'T')
-       ENDIF
-       !
-
-       !! * S section
-
-       WRITE(clname,9000) TRIM(cexper),'S',iyear,imon,iday
-       cltext=TRIM(cexper)//' S (PSU) '//TRIM(clmode)
-
-       IF( ll_dia_inst) THEN
-          CALL dia_wri_dimg(clname, cltext, tsn(:,:,:,jp_sal), jpk, 'T')
-       ELSE
-          CALL dia_wri_dimg(clname, cltext, sm               , jpk, 'T')
-       ENDIF
-       !
-
-       !! * 2D section
-
-       WRITE(clname,9000) TRIM(cexper),'2D',iyear,imon,iday
-       cltext='2D fields '//TRIM(clmode)
-
-       IF( ll_dia_inst) THEN
-          CALL dia_wri_dimg(clname, cltext, fsel, inbsel, '2')
-       ELSE
-          CALL dia_wri_dimg(clname, cltext, fsel, inbsel, '2')
-       ENDIF
-
-       IF( lk_mpp )   CALL mppsync   ! synchronization in mpp
-
-       !! * Log message in numout 
-
-       IF( lwp)WRITE(numout,*) ' '
-       IF( lwp)WRITE(numout,*) ' **** WRITE in dimg file ',kt
-
-       IF( lwp .AND.        ll_dia_inst) WRITE(numout,*) '    instantaneous fields'
-       IF( lwp .AND. .NOT.  ll_dia_inst) WRITE(numout,*) '    average fields with ',nmoyct,'pdt'
-       !
-       !
-       !! * Reset cumulating arrays  and counter to 0 after writing
-       !
-       IF( .NOT. ll_dia_inst ) THEN
-          nmoyct = 0
-          !
-          um(:,:,:) = 0._wp
-          vm(:,:,:) = 0._wp
-          wm(:,:,:) = 0._wp
-          tm(:,:,:) = 0._wp
-          sm(:,:,:) = 0._wp
-          fsel(:,:,:) = 0._wp
-          avtm(:,:,:) = 0._wp
-       ENDIF
-    ENDIF
-    !
-    IF( nn_timing == 1 )   CALL timing_stop('dia_wri')
-    !
-9000 FORMAT(a,"_",a,"_y",i4.4,"m",i2.2,"d",i2.2,".dimgproc")
-    !
-  END SUBROUTINE dia_wri
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIU/cool_skin.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIU/cool_skin.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIU/cool_skin.F90	(revision 6140)
@@ -0,0 +1,153 @@
+MODULE cool_skin
+   !!======================================================================
+   !!                    ***  MODULE  cool_skin  ***
+   !!     Cool skin thickness and delta T correction using Artele et al. (2002)
+   !!     [see also Tu and Tsuang (2005)]
+   !!
+   !!=====================================================================
+   !! History :        !  2012-01  (P. Sykes)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   diurnal_sst_coolskin_step  : time-step the cool skin corrections
+   !!----------------------------------------------------------------------
+   USE par_kind
+   USE phycst
+   USE dom_oce
+   USE in_out_manager
+   USE sbc_oce
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   
+   IMPLICIT NONE
+   
+   ! Namelist parameters
+
+   ! Parameters
+   REAL(wp), PRIVATE, PARAMETER :: pp_k = 0.596_wp          ! Thermal conductivity of seawater
+   REAL(wp), PRIVATE, PARAMETER :: pp_v = 1.05e-6_wp        ! Kinematic viscosity of seawater
+   REAL(wp), PRIVATE, PARAMETER :: pp_C = 86400             ! seconds [see Tu and Tsuang (2005)]
+   REAL(wp), PRIVATE, PARAMETER :: pp_cw = 3993._wp         ! specific heat capacity of seawater
+   REAL(wp), PRIVATE, PARAMETER :: pp_h = 10._wp            ! reference depth [using 10m from Artale et al. (2002)]
+   REAL(wp), PRIVATE, PARAMETER :: pp_rhoa = 1.20421_wp     ! density of air (at 20C)
+   REAL(wp), PRIVATE, PARAMETER :: pp_cda = 1.45e-3_wp      ! assumed air-sea drag coefficient for calculating wind speed
+   
+   ! Key variables
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:) :: x_csdsst    ! Cool skin delta SST
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:) :: x_csthick   ! Cool skin thickness
+
+   PRIVATE
+   PUBLIC diurnal_sst_coolskin_step, diurnal_sst_coolskin_init
+
+      !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   
+   CONTAINS 
+   
+   SUBROUTINE diurnal_sst_coolskin_init
+      !!----------------------------------------------------------------------
+      !! *** ROUTINE diurnal_sst_coolskin_init ***
+      !!
+      !! ** Purpose :   initialise the cool skin model
+      !!
+      !! ** Method : 
+      !!
+      !! ** Reference :
+      !! 
+      !!----------------------------------------------------------------------
+      
+      IMPLICIT NONE
+      
+      ALLOCATE( x_csdsst(jpi,jpj), x_csthick(jpi,jpj) )
+      x_csdsst = 0.
+      x_csthick = 0.
+      
+   END SUBROUTINE diurnal_sst_coolskin_init
+ 
+   SUBROUTINE diurnal_sst_coolskin_step(psqflux, pstauflux, psrho, rdt)
+      !!----------------------------------------------------------------------
+      !! *** ROUTINE diurnal_sst_takaya_step ***
+      !!
+      !! ** Purpose :   Time-step the Artale cool skin model
+      !!
+      !! ** Method : 
+      !!
+      !! ** Reference : 
+      !!----------------------------------------------------------------------
+     
+      IMPLICIT NONE
+     
+      ! Dummy variables
+      REAL(wp), INTENT(IN), DIMENSION(jpi,jpj) :: psqflux     ! Heat (non-solar)(Watts)
+      REAL(wp), INTENT(IN), DIMENSION(jpi,jpj) :: pstauflux   ! Wind stress (kg/ m s^2)
+      REAL(wp), INTENT(IN), DIMENSION(jpi,jpj) :: psrho       ! Water density (kg/m^3)
+      REAL(wp), INTENT(IN) :: rdt                             ! Time-step
+     
+      ! Local variables
+      REAL(wp), DIMENSION(jpi,jpj) :: z_fv                    ! Friction velocity     
+      REAL(wp), DIMENSION(jpi,jpj) :: z_gamma                 ! Dimensionless function of wind speed
+      REAL(wp), DIMENSION(jpi,jpj) :: z_lamda                 ! Sauders (dimensionless) proportionality constant
+      REAL(wp), DIMENSION(jpi,jpj) :: z_wspd                  ! Wind speed (m/s)
+      REAL(wp) :: z_ztx                                       ! Temporary u wind stress
+      REAL(wp) :: z_zty                                       ! Temporary v wind stress
+      REAL(wp) :: z_zmod                                      ! Temporary total wind stress
+     
+      INTEGER :: ji,jj
+     
+      IF ( .NOT. ln_blk_core ) THEN
+         CALL ctl_stop("cool_skin.f90: diurnal flux processing only implemented"//&
+         &             " for core bulk forcing")
+      ENDIF
+ 
+      DO jj = 1,jpj
+         DO ji = 1,jpi
+            
+            ! Calcualte wind speed from wind stress and friction velocity
+            IF( tmask(ji,jj,1) == 1. .AND. pstauflux(ji,jj) /= 0 .AND. psrho(ji,jj) /=0 ) THEN
+               z_fv(ji,jj) = SQRT( pstauflux(ji,jj) / psrho(ji,jj) )
+               z_wspd(ji,jj) = SQRT( pstauflux(ji,jj) / ( pp_cda * pp_rhoa ) )
+            ELSE
+               z_fv(ji,jj) = 0.
+               z_wspd(ji,jj) = 0.     
+            ENDIF
+
+ 
+            ! Calculate gamma function which is dependent upon wind speed
+            IF( tmask(ji,jj,1) == 1. ) THEN
+               IF( ( z_wspd(ji,jj) <= 7.5 ) ) z_gamma(ji,jj) = ( 0.2 * z_wspd(ji,jj) ) + 0.5
+               IF( ( z_wspd(ji,jj) > 7.5 ) .AND. ( z_wspd(ji,jj) < 10. ) ) z_gamma(ji,jj) = ( 1.6 * z_wspd(ji,jj) ) - 10.
+               IF( ( z_wspd(ji,jj) >= 10. ) ) z_gamma(ji,jj) = 6.
+            ENDIF
+
+
+            ! Calculate lamda function
+            IF( tmask(ji,jj,1) == 1. .AND. z_fv(ji,jj) /= 0 ) THEN
+               z_lamda(ji,jj) = ( z_fv(ji,jj) * pp_k * pp_C ) / ( z_gamma(ji,jj) * psrho(ji,jj) * pp_cw * pp_h * pp_v )
+            ELSE
+               z_lamda(ji,jj) = 0.
+            ENDIF
+
+
+
+            ! Calculate the cool skin thickness - only when heat flux is out of the ocean
+            IF( tmask(ji,jj,1) == 1. .AND. z_fv(ji,jj) /= 0 .AND. psqflux(ji,jj) < 0 ) THEN
+                x_csthick(ji,jj) = ( z_lamda(ji,jj) * pp_v ) / z_fv(ji,jj)
+            ELSE
+                x_csthick(ji,jj) = 0.
+            ENDIF
+
+
+
+            ! Calculate the cool skin correction - only when the heat flux is out of the ocean
+            IF( tmask(ji,jj,1) == 1. .AND. x_csthick(ji,jj) /= 0. .AND. psqflux(ji,jj) < 0. ) THEN
+               x_csdsst(ji,jj) = ( psqflux(ji,jj) * x_csthick(ji,jj) ) / pp_k
+             ELSE
+               x_csdsst(ji,jj) = 0.
+            ENDIF
+
+         ENDDO
+      ENDDO
+
+   END SUBROUTINE diurnal_sst_coolskin_step
+
+
+END MODULE cool_skin
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIU/diurnal_bulk.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIU/diurnal_bulk.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIU/diurnal_bulk.F90	(revision 6140)
@@ -0,0 +1,297 @@
+MODULE diurnal_bulk
+   !!======================================================================
+   !!                    ***  MODULE  diurnal_bulk  ***
+   !!     Takaya model of diurnal warming (Takaya, 2010)
+   !!=====================================================================
+   !! History :        !  11-10  (J. While)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   diurnal_sst_bulk_init  : initialise diurnal model
+   !!   diurnal_sst_bulk_step  : time-step the diurnal model
+   !!----------------------------------------------------------------------
+   USE par_kind
+   USE phycst
+   USE dom_oce
+   USE lib_mpp
+   USE solfrac_mod
+   USE in_out_manager
+   
+   IMPLICIT NONE
+   
+   ! Namelist parameters
+   LOGICAL, PUBLIC :: ln_diurnal
+   LOGICAL, PUBLIC :: ln_diurnal_only
+
+   ! Parameters
+   REAL(wp), PRIVATE, PARAMETER :: pp_alpha = 2.0e-4_wp
+   REAL(wp), PRIVATE, PARAMETER :: pp_veltol = 0._wp
+   REAL(wp), PRIVATE, PARAMETER :: pp_min_fvel = 1.e-10_wp 
+   
+   ! Key variables
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:) :: x_dsst     ! Delta SST
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:) :: x_solfrac  ! Fraction of 
+   !                                                           ! absorbed radiation
+
+   PRIVATE
+   PUBLIC diurnal_sst_bulk_init, diurnal_sst_takaya_step
+   
+   CONTAINS 
+   
+   SUBROUTINE diurnal_sst_bulk_init
+      !!----------------------------------------------------------------------
+      !! *** ROUTINE diurnal_sst_init ***
+      !!
+      !! ** Purpose : Initialise the Takaya diurnal model
+      
+      !!----------------------------------------------------------------------
+      
+      IMPLICIT NONE
+      
+      INTEGER :: ios
+      
+      NAMELIST /namdiu/ ln_diurnal, ln_diurnal_only
+      
+      ! Read the namelist
+      REWIND( numnam_ref )
+      READ( numnam_ref, namdiu, IOSTAT = ios, ERR = 901 )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdiu in reference namelist', lwp )
+      REWIND( numnam_cfg )
+      READ( numnam_cfg, namdiu, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdiu in configuration namelist', lwp )      
+      
+      IF ( ln_diurnal_only .AND. ( .NOT. ln_diurnal ) ) THEN
+         CALL ctl_stop( "ln_diurnal_only set, but ln_diurnal = FALSE !" )
+      ENDIF
+      
+      IF ( ln_diurnal ) THEN      
+         
+         ! Allocate arrays
+         ALLOCATE( x_dsst(jpi,jpj), x_solfrac(jpi,jpj) )
+         
+         ! Initialise the solar fraction
+         x_solfrac = 0._wp
+         x_dsst = 0._wp
+
+         IF ( ln_diurnal_only ) THEN
+            CALL ctl_warn( "ln_diurnal_only set; only the diurnal component of SST will be calculated" )
+         ENDIF
+      ENDIF
+      
+   END SUBROUTINE diurnal_sst_bulk_init
+   
+   SUBROUTINE diurnal_sst_takaya_step(kt, psolflux, pqflux, ptauflux, prho, p_rdt,&
+            &                  pla, pthick, pcoolthick, pmu, &
+            &                  p_fvel_bkginc, p_hflux_bkginc)
+      !!----------------------------------------------------------------------
+      !! *** ROUTINE diurnal_sst_takaya_step ***
+      !!
+      !! ** Purpose :   Time-step the Takaya diurnal model
+      !!
+      !! ** Method :    1) Calculate the Obukhov length
+      !!                2) Calculate the Similarity function
+      !!                2) Calculate the increment to dsst
+      !!                3) Apply the increment
+      !! ** Reference : Refinements to a prognostic scheme of skin sea surface
+      !!                temperature, Takaya et al, JGR, 2010 
+      !!----------------------------------------------------------------------
+      
+      IMPLICIT NONE
+      
+      ! Dummy variables
+      REAL(wp), INTENT(IN), DIMENSION(jpi,jpj) :: psolflux  ! solar flux (Watts)
+      REAL(wp), INTENT(IN), DIMENSION(jpi,jpj) :: pqflux    ! heat (non-solar) 
+      !                                                     ! flux (Watts)
+      REAL(wp), INTENT(IN), DIMENSION(jpi,jpj) :: ptauflux  ! wind stress 
+      !                                                     ! (kg/ m s^2)
+      REAL(wp), INTENT(IN), DIMENSION(jpi,jpj) :: prho      ! water density 
+      !                                                     ! (kg/m^3)
+      REAL(wp), OPTIONAL, INTENT(IN), DIMENSION(jpi,jpj) :: pLa    
+      !                                                     ! Langmuir number
+      REAL(wp), OPTIONAL, INTENT(IN), DIMENSION(jpi,jpj) :: pthick 
+      !                                                     ! warm layer thickness (m)
+      REAL(wp), OPTIONAL, INTENT(IN), DIMENSION(jpi,jpj) :: pcoolthick 
+      !                                                     ! cool skin thickness (m)
+      REAL(wp), OPTIONAL, INTENT(IN), DIMENSION(jpi,jpj) :: pmu    
+      !                                                     ! mu parameter
+      REAL(wp), OPTIONAL, INTENT(IN), DIMENSION(jpi,jpj) :: p_hflux_bkginc  
+      !                                                     ! optional increment to the
+      !                                                     ! heat flux
+      REAL(wp), OPTIONAL, INTENT(IN), DIMENSION(jpi,jpj) :: p_fvel_bkginc  
+      !                                                     ! optional increment to the
+      !                                                     ! friction velocity
+      REAL(wp), INTENT(IN) :: p_rdt                         ! time-step
+      
+      ! Local variables 
+      REAL(wp), DIMENSION(jpi,jpj) :: z_fvel              ! friction velocity     
+      REAL(wp), DIMENSION(jpi,jpj) :: zthick, zcoolthick, zmu, zla
+      REAL(wp), DIMENSION(jpi,jpj) :: z_abflux            ! absorbed flux           
+      REAL(wp), DIMENSION(jpi,jpj) :: z_fla               ! Langmuir function value 
+      
+      LOGICAL  :: ll_calcfrac
+      
+      INTEGER :: ji,jj
+      INTEGER, INTENT(IN) :: kt                           ! time step
+
+      ! Set optional arguments to their defaults
+      IF ( .NOT. PRESENT(pthick) ) THEN 
+         zthick(:,:) = 3._wp
+      ELSE
+         zthick(:,:) = pthick(:,:)
+      ENDIF
+      IF ( .NOT. PRESENT(pcoolthick) ) THEN 
+         zcoolthick(:,:) = 0._wp
+      ELSE
+         zcoolthick(:,:) = pcoolthick(:,:)
+      ENDIF
+      IF ( .NOT. PRESENT(pmu) ) THEN
+         zmu(:,:) = 0.3_wp
+      ELSE
+         zmu(:,:) = pmu(:,:)
+      ENDIF
+      IF ( .NOT. PRESENT(pla) ) THEN
+         zla(:,:) = 0.3_wp
+      ELSE
+         zla(:,:) = pla(:,:)
+      ENDIF
+      
+      ! If not done already, calculate the solar fraction
+      IF ( kt==nit000 ) THEN
+         DO jj = 1,jpj
+            DO ji = 1, jpi
+               IF(  ( x_solfrac(ji,jj) == 0._wp ) .AND. ( tmask(ji,jj,1) == 1._wp ) ) &
+               &   x_solfrac(ji,jj) = solfrac( zcoolthick(ji,jj),zthick(ji,jj) )
+            END DO
+         END DO   
+      ENDIF   
+
+      ! convert solar flux and heat flux to absorbed flux   
+      WHERE ( tmask(:,:,1) == 1._wp) 
+         z_abflux(:,:) = (  x_solfrac(:,:) *  psolflux (:,:)) + pqflux(:,:)     
+      ELSEWHERE
+         z_abflux(:,:) = 0._wp
+      ENDWHERE
+      IF( PRESENT(p_hflux_bkginc) ) z_abflux(:,:) = z_abflux(:,:) + p_hflux_bkginc   ! Optional increment
+      WHERE ( ABS( z_abflux(:,:) ) < rsmall )
+         z_abflux(:,:) = rsmall
+      ENDWHERE 
+      
+      ! Calculate the friction velocity
+      WHERE ( (ptauflux /= 0) .AND. ( tmask(:,:,1) == 1.) )   
+         z_fvel(:,:) = SQRT( ptauflux(:,:) / prho(:,:) )
+      ELSEWHERE
+         z_fvel(:,:) = 0._wp
+      ENDWHERE
+      IF( PRESENT(p_fvel_bkginc) ) z_fvel(:,:) = z_fvel(:,:) + p_fvel_bkginc   ! Optional increment
+      
+       
+       
+      ! Calculate the Langmuir function value
+      WHERE ( tmask(:,:,1) == 1.)
+         z_fla(:,:) = MAX( 1._wp, zla(:,:)**( -2._wp / 3._wp ) )  
+      ELSEWHERE
+         z_fla(:,:) = 0._wp
+      ENDWHERE     
+      
+      ! Increment the temperature using the implicit solution
+      x_dsst(:,:) = t_imp( x_dsst(:,:), p_rdt, z_abflux(:,:), z_fvel(:,:), &
+                                 z_fla(:,:), zmu(:,:), zthick(:,:), prho(:,:))
+      
+                                
+      
+   END SUBROUTINE diurnal_sst_takaya_step
+
+   
+   FUNCTION t_imp(p_dsst, p_rdt, p_abflux, p_fvel, &
+                          p_fla, pmu, pthick, prho )
+                          
+      IMPLICIT NONE
+      
+      ! Function definition
+      REAL(wp), DIMENSION(jpi,jpj) :: t_imp
+      ! Dummy variables
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN) :: p_dsst     ! Delta SST
+      REAL(wp), INTENT(IN)                     :: p_rdt      ! Time-step
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN) :: p_abflux   ! Heat forcing
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN) :: p_fvel     ! Friction velocity
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN) :: p_fla      ! Langmuir number
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN) :: pmu        ! Structure parameter
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN) :: pthick     ! Layer thickness
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN) :: prho       ! Water density
+   
+      ! Local variables
+      REAL(wp) :: z_olength          ! Obukhov length
+      REAL(wp) :: z_sigma, z_sigma2
+      REAL(wp) :: z_term1, z_term2     
+      REAL(wp) :: z_stabfunc         ! stability function value
+      REAL(wp) :: z_fvel      
+      
+      CHARACTER(200) :: warn_string
+       
+      INTEGER :: ji,jj
+                     
+      DO jj = 1, jpj
+         DO ji = 1, jpi   
+            
+            ! Only calculate outside tmask
+            IF ( tmask(ji,jj,1) /= 1._wp ) THEN
+               t_imp(ji,jj) = 0._wp
+               CYCLE   
+            END IF
+            
+            IF (p_fvel(ji,jj) < pp_min_fvel) THEN
+               z_fvel = pp_min_fvel
+               WRITE(warn_string,*) "diurnal_sst_takaya step: "&
+               &//"friction velocity < minimum\n" &
+               &//"Setting friction velocity =",pp_min_fvel
+               CALL ctl_warn(warn_string)
+               
+            ELSE
+               z_fvel = p_fvel(ji,jj)
+            ENDIF
+                 
+            ! Calculate the Obukhov length
+            IF ( (z_fvel < pp_veltol ) .AND. &
+            &    (p_dsst(ji,jj) > 0._wp) ) THEN
+               z_olength =  z_fvel  / &
+               &     SQRT( p_dsst(ji,jj) * vkarmn * grav * &
+               &             pp_alpha / ( 5._wp * pthick(ji,jj) ) )
+            ELSE
+               z_olength = &
+               &   ( prho(ji,jj) * rcp * z_fvel**3._wp ) / &
+               &   ( vkarmn * grav * pp_alpha *&
+               &     p_abflux(ji,jj) )
+            ENDIF
+             
+            ! Calculate the stability function          
+            z_sigma = pthick(ji,jj) / z_olength
+            z_sigma2 = z_sigma * z_sigma
+  
+            IF ( z_sigma >= 0. ) THEN
+               z_stabfunc = 1._wp + &
+               &  ( ( 5._wp * z_sigma + 4._wp * z_sigma2 ) / &
+               &  ( 1._wp + 3._wp * z_sigma + 0.25_wp * &
+               &    z_sigma2 ) )
+            ELSE
+               z_stabfunc = 1._wp / &
+               &                   SQRT( 1._wp - 16._wp * z_sigma )
+            ENDIF
+
+            ! Calculate the T increment
+            z_term1 = ( p_abflux(ji,jj) * ( pmu(ji,jj) + 1._wp)  / &
+            & ( pmu(ji,jj) * pthick(ji,jj) * prho(ji,jj) * rcp ) )
+            
+             
+            z_term2 = -( ( pmu(ji,jj) + 1._wp) * &
+            &                       ( vkarmn * z_fvel * p_fla(ji,jj) ) / &
+            &      ( pthick(ji,jj) * z_stabfunc ) )     
+          
+            t_imp(ji,jj) = ( p_dsst(ji,jj) + p_rdt * z_term1 ) / &
+                           ( 1._wp - p_rdt * z_term2 )
+
+         END DO
+      END DO
+      
+      END FUNCTION t_imp
+
+END MODULE diurnal_bulk
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIU/solfrac_mod.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIU/solfrac_mod.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIU/solfrac_mod.F90	(revision 6140)
@@ -0,0 +1,56 @@
+MODULE solfrac_mod
+   !!======================================================================
+   !!                    ***  MODULE  solfrac  ***
+   !!     POSH representation of solar absorption (Gntermann, 2009)
+   !!=====================================================================
+   !! History :        !  11-10  (J. While)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   solfrac  : function to calculate the solar fraction
+   !!----------------------------------------------------------------------
+   
+   USE par_kind
+   IMPLICIT NONE
+     
+   ! Parameters 
+   REAL(wp), PRIVATE, PARAMETER, DIMENSION(9) :: &
+   &                                     pp_wgt = (/0.2370, 0.36,  0.1790, &
+   &                                                0.087,  0.08,  0.025,  &
+   &                                                0.025,  0.007, 0.0004/)
+   REAL(wp), PRIVATE, PARAMETER, DIMENSION(9) :: &
+   &                                    pp_len = (/34.84,   2.266,   0.0315,  &
+   &                                               0.0055,  8.32e-4, 1.26e-4, &
+   &                                                3.13e-4, 7.82e-4, 1.44e-5/)
+   
+   PUBLIC solfrac
+                                                   
+CONTAINS
+
+   REAL(dp) FUNCTION solfrac(ptop,pbottom)
+       !!----------------------------------------------------------------------
+      !! *** ROUTINE solfrac ***
+      !!
+      !! ** Purpose :   Calculate the solar fraction absorbed between two 
+      !!                layers
+      !!
+      !! ** Reference : POSH a model of diurnal warming, Gentemann et al, 
+      !!                 JGR, 2009 
+      !!----------------------------------------------------------------------
+      
+      ! Dummy variabes
+      REAL(wp), INTENT(IN) :: ptop, pbottom   ! Top and bottom of layer
+      
+      ! local variables
+      INTEGER :: jt
+      
+      ! Calculate the solar fraction absorbed between the two layers
+      solfrac = 0._wp
+      DO jt = 1, 9
+           solfrac = solfrac + pp_wgt(jt) * ( exp ( -ptop / pp_len(jt) ) &
+            &                                 - exp ( -pbottom / pp_len(jt) ) )
+      END DO
+      
+   END FUNCTION
+   
+END MODULE solfrac_mod
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DIU/step_diu.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DIU/step_diu.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DIU/step_diu.F90	(revision 6140)
@@ -0,0 +1,96 @@
+MODULE step_diu
+   !!======================================================================
+   !!                       ***  MODULE stp_diu  ***
+   !! Time-stepping of diurnal cycle models
+   !!======================================================================
+   !! History :  3.7  ! 2015-11  (J. While)  Original code
+
+   USE diurnal_bulk    ! diurnal SST bulk routines  (diurnal_sst_takaya routine) 
+   USE cool_skin       ! diurnal cool skin correction (diurnal_sst_coolskin routine)   
+   USE iom
+   USE sbc_oce
+   USE sbcmod           ! surface boundary condition       (sbc     routine)
+   USE diaobs           ! Observation operator
+   USE oce
+   USE daymod
+   USE restart          ! ocean restart                    (rst_wri routine)
+   USE timing           ! Timing
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   stp_diurnal   ! called by nemogcm.F90 or step.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
+   !! $Id:$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   CONTAINS
+
+   SUBROUTINE stp_diurnal( kstp ) 
+      INTEGER, INTENT(in) ::   kstp   ! ocean time-step index 
+      !!---------------------------------------------------------------------- 
+      !!                     ***  ROUTINE stp_diurnal  *** 
+      !!                       
+      !! ** Purpose : - Time stepping of diurnal SST model only 
+      !!   
+      !! ** Method  : -1- Update forcings and data   
+      !!              -2- Update ocean physics   
+      !!              -3- Compute the t and s trends   
+      !!              -4- Update t and s   
+      !!              -5- Compute the momentum trends 
+      !!              -6- Update the horizontal velocity 
+      !!              -7- Compute the diagnostics variables (rd,N2, div,cur,w) 
+      !!              -8- Outputs and diagnostics 
+      !!---------------------------------------------------------------------- 
+      INTEGER ::   jk       ! dummy loop indices
+      INTEGER ::   indic    ! error indicator if < 0 
+      REAL(wp), DIMENSION(jpi,jpj) :: z_fvel_bkginc, z_hflux_bkginc     
+      !! --------------------------------------------------------------------- 
+      
+      IF(ln_diurnal_only) THEN
+         indic = 0                                 ! reset to no error condition 
+         IF( kstp /= nit000 )   CALL day( kstp )   ! Calendar (day was already called at nit000 in day_init) 
+ 
+         CALL iom_setkt( kstp - nit000 + 1, cxios_context )   ! tell iom we are at time step kstp
+         IF( ln_crs ) THEN
+            CALL iom_setkt( kstp - nit000 + 1, TRIM(cxios_context)//"_crs" ) ! tell iom we are at time step kstp
+         ENDIF
+       
+            CALL sbc    ( kstp )                      ! Sea Boundary Conditions 
+      ENDIF
+     
+      ! Cool skin
+      IF ( .NOT.ln_diurnal ) CALL ctl_stop(  "stp_diurnal: ln_diurnal not set"  )
+         
+      IF ( .NOT. ln_blk_core ) THEN
+         CALL ctl_stop("step.f90: diurnal flux processing only implemented"//&
+         &             " for core forcing") 
+      ENDIF
+
+      CALL diurnal_sst_coolskin_step( qns, taum, rhop(:,:,1), rdt)
+
+      CALL iom_put( "sst_wl"   , x_dsst               )    ! warm layer (write out before update below).
+      CALL iom_put( "sst_cs"   , x_csdsst             )    ! cool skin
+
+      ! Diurnal warm layer model       
+      CALL diurnal_sst_takaya_step( kstp, & 
+      &    qsr, qns, taum, rhop(:,:,1), rdt) 
+
+      IF(ln_diurnal_only) THEN
+         IF( ln_diaobs )         CALL dia_obs( kstp )         ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
+     
+         !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
+         ! Control and restarts 
+         !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
+         IF( kstp == nit000   )   CALL iom_close( numror )     ! close input  ocean restart file 
+         IF( lrst_oce         )   CALL rst_write    ( kstp )   ! write output ocean restart file
+     
+         IF( nn_timing == 1 .AND.  kstp == nit000  )   CALL timing_reset 
+      ENDIF
+       
+   END SUBROUTINE stp_diurnal  
+   
+END MODULE step_diu
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90	(revision 6140)
@@ -11,4 +11,5 @@
    !!                 ! 2004-01  (A.M. Treguier) new calculation based on adatrj
    !!                 ! 2006-08  (G. Madec)  surface module major update
+   !!                 ! 2015-11  (D. Lea) Allow non-zero initial time of day
    !!----------------------------------------------------------------------
 
@@ -20,5 +21,5 @@
    !!
    !!   we suppose that the time step is deviding the number of second of in a day
-   !!             ---> MOD( rday, rdttra(1) ) == 0
+   !!             ---> MOD( rday, rdt ) == 0
    !!
    !!           ----------- WARNING -----------
@@ -26,13 +27,13 @@
    !!
    !!----------------------------------------------------------------------
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE in_out_manager  ! I/O manager
-   USE iom             !
-   USE ioipsl, ONLY :   ymds2ju   ! for calendar
-   USE prtctl          ! Print control
-   USE trc_oce, ONLY : lk_offline ! offline flag
-   USE timing          ! Timing
-   USE restart         ! restart
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE in_out_manager ! I/O manager
+   USE iom            !
+   USE ioipsl  , ONLY :   ymds2ju   ! for calendar
+   USE prtctl         ! Print control
+   USE trc_oce , ONLY : lk_offline ! offline flag
+   USE timing         ! Timing
+   USE restart        ! restart
 
    IMPLICIT NONE
@@ -43,5 +44,5 @@
    PUBLIC   day_mth    ! Needed by TAM
 
-   INTEGER, PUBLIC ::   nsecd, nsecd05, ndt, ndt05 ! (PUBLIC for TAM)
+   INTEGER, PUBLIC ::   nsecd, nsecd05, ndt, ndt05   !: (PUBLIC for TAM)
 
    !!----------------------------------------------------------------------
@@ -78,12 +79,12 @@
             &           'You must do a restart at higher frequency (or remove this stop and recompile the code in I8)' )
       ENDIF
-      ! all calendar staff is based on the fact that MOD( rday, rdttra(1) ) == 0
-      IF( MOD( rday     , rdttra(1) ) /= 0. )   CALL ctl_stop( 'the time step must devide the number of second of in a day' )
-      IF( MOD( rday     , 2.        ) /= 0. )   CALL ctl_stop( 'the number of second of in a day must be an even number'    )
-      IF( MOD( rdttra(1), 2.        ) /= 0. )   CALL ctl_stop( 'the time step (in second) must be an even number'           )
-      nsecd   = NINT(rday           )
-      nsecd05 = NINT(0.5 * rday     )
-      ndt     = NINT(      rdttra(1))
-      ndt05   = NINT(0.5 * rdttra(1))
+      ! all calendar staff is based on the fact that MOD( rday, rdt ) == 0
+      IF( MOD( rday     , rdt   ) /= 0. )   CALL ctl_stop( 'the time step must devide the number of second of in a day' )
+      IF( MOD( rday     , 2.    ) /= 0. )   CALL ctl_stop( 'the number of second of in a day must be an even number'    )
+      IF( MOD( rdt      , 2.    ) /= 0. )   CALL ctl_stop( 'the time step (in second) must be an even number'           )
+      nsecd   = NINT(rday       )
+      nsecd05 = NINT(0.5 * rday )
+      ndt     = NINT(      rdt  )
+      ndt05   = NINT(0.5 * rdt  )
 
       IF( .NOT. lk_offline ) CALL day_rst( nit000, 'READ' )
@@ -95,7 +96,10 @@
       nday    =   ndastp - (nyear * 10000) - ( nmonth * 100 )
 
-      CALL ymds2ju( nyear, nmonth, nday, 0.0, fjulday )  ! we assume that we start run at 00:00
+      nhour   =   nn_time0 / 100
+      nminute = ( nn_time0 - nhour * 100 )
+
+      CALL ymds2ju( nyear, nmonth, nday, nhour*3600._wp+nminute*60._wp, fjulday )  
       IF( ABS(fjulday - REAL(NINT(fjulday),wp)) < 0.1 / rday )   fjulday = REAL(NINT(fjulday),wp)   ! avoid truncation error
-      fjulday = fjulday + 1.                             ! move back to the day at nit000 (and not at nit000 - 1)
+      IF( nn_time0*3600 - ndt05 .lt. 0 ) fjulday = fjulday + 1.                    ! move back to the day at nit000 (and not at nit000 - 1)
 
       nsec1jan000 = 0
@@ -118,16 +122,27 @@
       !compute number of days between last monday and today
       CALL ymds2ju( 1900, 01, 01, 0.0, zjul )  ! compute julian day value of 01.01.1900 (our reference that was a Monday)
-      inbday = NINT(fjulday - zjul)            ! compute nb day between  01.01.1900 and current day
+      inbday = FLOOR(fjulday - zjul)            ! compute nb day between  01.01.1900 and start of current day
       idweek = MOD(inbday, 7)                  ! compute nb day between last monday and current day
+      IF (idweek .lt. 0) idweek=idweek+7       ! Avoid negative values for dates before 01.01.1900
 
       ! number of seconds since the beginning of current year/month/week/day at the middle of the time-step
-      nsec_year  = nday_year * nsecd - ndt05   ! 1 time step before the middle of the first time step
-      nsec_month = nday      * nsecd - ndt05   ! because day will be called at the beginning of step
-      nsec_week  = idweek    * nsecd - ndt05
-      nsec_day   =             nsecd - ndt05
+      IF (nhour*3600+nminute*60-ndt05 .gt. 0) THEN
+         ! 1 timestep before current middle of first time step is still the same day
+         nsec_year  = (nday_year-1) * nsecd + nhour*3600+nminute*60 - ndt05 
+         nsec_month = (nday-1)      * nsecd + nhour*3600+nminute*60 - ndt05    
+      ELSE
+         ! 1 time step before the middle of the first time step is the previous day 
+         nsec_year  = nday_year * nsecd + nhour*3600+nminute*60 - ndt05 
+         nsec_month = nday      * nsecd + nhour*3600+nminute*60 - ndt05   
+      ENDIF
+      nsec_week  = idweek    * nsecd + nhour*3600+nminute*60 - ndt05
+      nsec_day   =             nhour*3600+nminute*60 - ndt05 
+      IF( nsec_day .lt. 0 ) nsec_day = nsec_day + nsecd
+      IF( nsec_week .lt. 0 ) nsec_week = nsec_week + nsecd*7
 
       ! control print
-      IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i8,a,i8)')' =======>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
-           &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day, '  nsec_week:', nsec_week
+      IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i8,a,i8,a,i8,a,i8)')' =======>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
+           &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day, '  nsec_week:', nsec_week, '  &
+           &                   nsec_month:', nsec_month , '  nsec_year:' , nsec_year
 
       ! Up to now, calendar parameters are related to the end of previous run (nit000-1)
@@ -223,6 +238,6 @@
       nsec_week  = nsec_week  + ndt
       nsec_day   = nsec_day   + ndt
-      adatrj  = adatrj  + rdttra(1) / rday
-      fjulday = fjulday + rdttra(1) / rday
+      adatrj  = adatrj  + rdt / rday
+      fjulday = fjulday + rdt / rday
       IF( ABS(fjulday - REAL(NINT(fjulday),wp)) < zprec )   fjulday = REAL(NINT(fjulday),wp)   ! avoid truncation error
       IF( ABS(adatrj  - REAL(NINT(adatrj ),wp)) < zprec )   adatrj  = REAL(NINT(adatrj ),wp)   ! avoid truncation error
@@ -302,5 +317,6 @@
       CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
       !
-      REAL(wp) ::   zkt, zndastp
+      REAL(wp) ::   zkt, zndastp, zdayfrac, ksecs, ktime
+      INTEGER  ::   ihour, iminute
       !!----------------------------------------------------------------------
 
@@ -327,18 +343,48 @@
             ! define ndastp and adatrj
             IF ( nrstdt == 2 ) THEN
-               ! read the parameters correspondting to nit000 - 1 (last time step of previous run)
+               ! read the parameters corresponding to nit000 - 1 (last time step of previous run)
                CALL iom_get( numror, 'ndastp', zndastp )
                ndastp = NINT( zndastp )
                CALL iom_get( numror, 'adatrj', adatrj  )
+	       CALL iom_get( numror, 'ntime', ktime )
+	       nn_time0=INT(ktime)
+               ! calculate start time in hours and minutes
+	       zdayfrac=adatrj-INT(adatrj)
+	       ksecs = NINT(zdayfrac*86400)	       ! Nearest second to catch rounding errors in adatrj	       
+	       ihour = INT(ksecs/3600)
+	       iminute = ksecs/60-ihour*60
+ 	        
+               ! Add to nn_time0
+               nhour   =   nn_time0 / 100
+               nminute = ( nn_time0 - nhour * 100 )
+	       nminute=nminute+iminute
+	       
+	       IF( nminute >= 60 ) THEN
+	          nminute=nminute-60
+		  nhour=nhour+1
+	       ENDIF
+	       nhour=nhour+ihour
+	       IF( nhour >= 24 ) THEN
+		  nhour=nhour-24
+	          adatrj=adatrj+1
+	       ENDIF	       
+	       nn_time0 = nhour * 100 + nminute
+	       adatrj = INT(adatrj)                    ! adatrj set to integer as nn_time0 updated	       
             ELSE
-               ! parameters correspondting to nit000 - 1 (as we start the step loop with a call to day)
-               ndastp = ndate0 - 1     ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00
-               adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday
+               ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day)
+               ndastp = ndate0        ! ndate0 read in the namelist in dom_nam
+               nhour   =   nn_time0 / 100
+               nminute = ( nn_time0 - nhour * 100 )
+               IF( nhour*3600+nminute*60-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0)
+               adatrj = ( REAL( nit000-1, wp ) * rdt ) / rday
                ! note this is wrong if time step has changed during run
             ENDIF
          ELSE
-            ! parameters correspondting to nit000 - 1 (as we start the step loop with a call to day)
-            ndastp = ndate0 - 1        ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00
-            adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday
+            ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day)
+            ndastp = ndate0           ! ndate0 read in the namelist in dom_nam
+            nhour   =   nn_time0 / 100
+	    nminute = ( nn_time0 - nhour * 100 )
+            IF( nhour*3600+nminute*60-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0)
+            adatrj = ( REAL( nit000-1, wp ) * rdt ) / rday
          ENDIF
          IF( ABS(adatrj  - REAL(NINT(adatrj),wp)) < 0.1 / rday )   adatrj = REAL(NINT(adatrj),wp)   ! avoid truncation error
@@ -348,4 +394,5 @@
             WRITE(numout,*) '   date ndastp                                      : ', ndastp
             WRITE(numout,*) '   number of elapsed days since the begining of run : ', adatrj
+	    WRITE(numout,*) '   nn_time0                                         : ',nn_time0
             WRITE(numout,*)
          ENDIF
@@ -363,4 +410,5 @@
          CALL iom_rstput( kt, nitrst, numrow, 'adatrj' , adatrj            )   ! number of elapsed days since
          !                                                                     ! the begining of the run [s]
+	 CALL iom_rstput( kt, nitrst, numrow, 'ntime'  , REAL( nn_time0, wp) ) ! time
       ENDIF
       !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 6140)
@@ -11,4 +11,5 @@
    !!                             to the optimization of BDY communications
    !!            3.7  ! 2015-11  (G. Madec) introduce surface and scale factor ratio
+   !!             -   ! 2015-11  (G. Madec, A. Coward)  time varying zgr by default
    !!----------------------------------------------------------------------
 
@@ -32,21 +33,19 @@
    REAL(wp), PUBLIC ::   rn_bathy        !: depth of flat bottom (active if nn_bathy=0; if =0 depth=jpkm1)
    REAL(wp), PUBLIC ::   rn_hmin         !: minimum ocean depth (>0) or minimum number of ocean levels (<0)
+   REAL(wp), PUBLIC ::   rn_isfhmin      !: threshold to discriminate grounded ice to floating ice
    REAL(wp), PUBLIC ::   rn_e3zps_min    !: miminum thickness for partial steps (meters)
    REAL(wp), PUBLIC ::   rn_e3zps_rat    !: minimum thickness ration for partial steps
    INTEGER , PUBLIC ::   nn_msh          !: = 1 create a mesh-mask file
-   INTEGER , PUBLIC ::   nn_acc          !: = 0/1 use of the acceleration of convergence technique
    REAL(wp), PUBLIC ::   rn_atfp         !: asselin time filter parameter
-   REAL(wp), PUBLIC ::   rn_rdt          !: time step for the dynamics (and tracer if nacc=0)
-   REAL(wp), PUBLIC ::   rn_rdtmin       !: minimum time step on tracers
-   REAL(wp), PUBLIC ::   rn_rdtmax       !: maximum time step on tracers
-   REAL(wp), PUBLIC ::   rn_rdth         !: depth variation of tracer step
+   REAL(wp), PUBLIC ::   rn_rdt          !: time step for the dynamics and tracer
    INTEGER , PUBLIC ::   nn_closea       !: =0 suppress closed sea/lake from the ORCA domain or not (=1)
    INTEGER , PUBLIC ::   nn_euler        !: =0 start with forward time step or not (=1)
+   LOGICAL , PUBLIC ::   ln_iscpl       !: coupling with ice sheet
    LOGICAL , PUBLIC ::   ln_crs          !: Apply grid coarsening to dynamical model output or online passive tracers
 
    !! Free surface parameters
    !! =======================
-   LOGICAL, PUBLIC :: ln_dynspg_exp      !: Explicit free surface flag
-   LOGICAL, PUBLIC :: ln_dynspg_ts       !: Split-Explicit free surface flag
+   LOGICAL , PUBLIC :: ln_dynspg_exp     !: Explicit free surface flag
+   LOGICAL , PUBLIC :: ln_dynspg_ts      !: Split-Explicit free surface flag
 
    !! Time splitting parameters
@@ -61,5 +60,5 @@
    !! Horizontal grid parameters for domhgr
    !! =====================================
-   INTEGER       ::   jphgr_msh        !: type of horizontal mesh
+   INTEGER       ::   jphgr_msh          !: type of horizontal mesh
    !                                       !  = 0 curvilinear coordinate on the sphere read in coordinate.nc
    !                                       !  = 1 geographical mesh on the sphere with regular grid-spacing
@@ -68,29 +67,29 @@
    !                                       !  = 4 Mercator grid with T/U point at the equator
 
-   REAL(wp)      ::   ppglam0              !: longitude of first raw and column T-point (jphgr_msh = 1)
-   REAL(wp)      ::   ppgphi0              !: latitude  of first raw and column T-point (jphgr_msh = 1)
+   REAL(wp)      ::   ppglam0            !: longitude of first raw and column T-point (jphgr_msh = 1)
+   REAL(wp)      ::   ppgphi0            !: latitude  of first raw and column T-point (jphgr_msh = 1)
    !                                                        !  used for Coriolis & Beta parameters (jphgr_msh = 2 or 3)
-   REAL(wp)      ::   ppe1_deg             !: zonal      grid-spacing (degrees)
-   REAL(wp)      ::   ppe2_deg             !: meridional grid-spacing (degrees)
-   REAL(wp)      ::   ppe1_m               !: zonal      grid-spacing (degrees)
-   REAL(wp)      ::   ppe2_m               !: meridional grid-spacing (degrees)
+   REAL(wp)      ::   ppe1_deg           !: zonal      grid-spacing (degrees)
+   REAL(wp)      ::   ppe2_deg           !: meridional grid-spacing (degrees)
+   REAL(wp)      ::   ppe1_m             !: zonal      grid-spacing (degrees)
+   REAL(wp)      ::   ppe2_m             !: meridional grid-spacing (degrees)
 
    !! Vertical grid parameter for domzgr
    !! ==================================
-   REAL(wp)      ::   ppsur                !: ORCA r4, r2 and r05 coefficients
-   REAL(wp)      ::   ppa0                 !: (default coefficients)
-   REAL(wp)      ::   ppa1                 !:
-   REAL(wp)      ::   ppkth                !:
-   REAL(wp)      ::   ppacr                !:
+   REAL(wp)      ::   ppsur              !: ORCA r4, r2 and r05 coefficients
+   REAL(wp)      ::   ppa0               !: (default coefficients)
+   REAL(wp)      ::   ppa1               !:
+   REAL(wp)      ::   ppkth              !:
+   REAL(wp)      ::   ppacr              !:
    !
    !  If both ppa0 ppa1 and ppsur are specified to 0, then
    !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
-   REAL(wp)      ::   ppdzmin              !: Minimum vertical spacing
-   REAL(wp)      ::   pphmax               !: Maximum depth
+   REAL(wp)      ::   ppdzmin            !: Minimum vertical spacing
+   REAL(wp)      ::   pphmax             !: Maximum depth
    !
-   LOGICAL       ::   ldbletanh            !: Use/do not use double tanf function for vertical coordinates
-   REAL(wp)      ::   ppa2                 !: Double tanh function parameters
-   REAL(wp)      ::   ppkth2               !:
-   REAL(wp)      ::   ppacr2               !:
+   LOGICAL       ::   ldbletanh          !: Use/do not use double tanf function for vertical coordinates
+   REAL(wp)      ::   ppa2               !: Double tanh function parameters
+   REAL(wp)      ::   ppkth2             !:
+   REAL(wp)      ::   ppacr2             !:
 
    !                                    !! old non-DOCTOR names still used in the model
@@ -99,16 +98,11 @@
    REAL(wp), PUBLIC ::   e3zps_rat       !: minimum thickness ration for partial steps
    INTEGER , PUBLIC ::   nmsh            !: = 1 create a mesh-mask file
-   INTEGER , PUBLIC ::   nacc            !: = 0/1 use of the acceleration of convergence technique
    REAL(wp), PUBLIC ::   atfp            !: asselin time filter parameter
-   REAL(wp), PUBLIC ::   rdt             !: time step for the dynamics (and tracer if nacc=0)
-   REAL(wp), PUBLIC ::   rdtmin          !: minimum time step on tracers
-   REAL(wp), PUBLIC ::   rdtmax          !: maximum time step on tracers
-   REAL(wp), PUBLIC ::   rdth            !: depth variation of tracer step
+   REAL(wp), PUBLIC ::   rdt             !: time step for the dynamics and tracer
 
    !                                                  !!! associated variables
    INTEGER , PUBLIC                 ::   neuler        !: restart euler forward option (0=Euler)
    REAL(wp), PUBLIC                 ::   atfp1         !: asselin time filter coeff. (atfp1= 1-2*atfp)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   rdttra  !: vertical profile of tracer time step
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   r2dtra  !: = 2*rdttra except at nit000 (=rdttra) if neuler=0
+   REAL(wp), PUBLIC                 ::   r2dt          !: = 2*rdt except at nit000 (=rdt) if neuler=0
 
    !!----------------------------------------------------------------------
@@ -177,53 +171,37 @@
    !! vertical coordinate and scale factors
    !! ---------------------------------------------------------------------
-   !                                 !!* Namelist namzgr : vertical coordinate *
-   LOGICAL, PUBLIC ::   ln_zco        !: z-coordinate - full step
-   LOGICAL, PUBLIC ::   ln_zps        !: z-coordinate - partial step
-   LOGICAL, PUBLIC ::   ln_sco        !: s-coordinate or hybrid z-s coordinate
-   LOGICAL, PUBLIC ::   ln_isfcav     !: presence of ISF 
-
-   !! All coordinates
-   !! ---------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdep3w_0           !: depth of t-points (sum of e3w) (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdept_0, gdepw_0   !: analytical (time invariant) depth at t-w  points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3v_0  , e3f_0     !: analytical (time invariant) vertical scale factors at  v-f
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3t_0  , e3u_0     !:                                      t-u  points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3vw_0             !: analytical (time invariant) vertical scale factors at  vw
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3w_0  , e3uw_0    !:                                      w-uw points (m)
-#if defined key_vvl
-   LOGICAL, PUBLIC, PARAMETER ::   lk_vvl = .TRUE.    !: variable grid flag
-
-   !! All coordinates
-   !! ---------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdep3w_n           !: now depth of T-points (sum of e3w) (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdept_n, gdepw_n   !: now depth at T-W  points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdept_b, gdepw_b   !: before depth at T-W  points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3t_n              !: now    vertical scale factors at  t       point  (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3u_n  , e3v_n     !:            -      -      -    -   u --v   points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3w_n  , e3f_n     !:            -      -      -    -   w --f   points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3uw_n , e3vw_n    !:            -      -      -    -   uw--vw  points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3t_b              !: before     -      -      -    -   t       points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3w_b              !: before     -      -      -    -   t       points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3u_b  , e3v_b     !:   -        -      -      -    -   u --v   points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3uw_b , e3vw_b    !:   -        -      -      -    -   uw--vw  points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3t_a              !: after      -      -      -    -   t       point  (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3u_a  , e3v_a     !:   -        -      -      -    -   u --v   points (m)
-#else
-   LOGICAL, PUBLIC, PARAMETER ::   lk_vvl = .FALSE.   !: fixed grid flag
-#endif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hur  , hvr     !: Now    inverse of u and v-points ocean depth (1/m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hu   , hv      !:        depth at u- and v-points (meters)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ht             !:        depth at t-points (meters)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ehur_a, ehvr_a !: After  inverse of u and v-points ocean depth (1/m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ehu_a , ehv_a  !:        depth at u- and v-points (meters)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ehur_b, ehvr_b !: Before inverse of u and v-points ocean depth (1/m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ehu_b , ehv_b  !:        depth at u- and v-points (meters)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ht_0           !: reference depth at t-       points (meters)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hu_0 , hv_0    !: reference depth at u- and v-points (meters)
+   !                                !!* Namelist namzgr : vertical coordinate *
+   LOGICAL, PUBLIC ::   ln_zco       !: z-coordinate - full step
+   LOGICAL, PUBLIC ::   ln_zps       !: z-coordinate - partial step
+   LOGICAL, PUBLIC ::   ln_sco       !: s-coordinate or hybrid z-s coordinate
+   LOGICAL, PUBLIC ::   ln_isfcav    !: presence of ISF 
+   LOGICAL, PUBLIC ::   ln_linssh    !: variable grid flag
+
+   !                                                        !  ref.   ! before  !   now   ! after  !
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3t_0 ,   e3t_b ,   e3t_n ,  e3t_a   !: t- vert. scale factor [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3u_0 ,   e3u_b ,   e3u_n ,  e3u_a   !: u- vert. scale factor [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3v_0 ,   e3v_b ,   e3v_n ,  e3v_a   !: v- vert. scale factor [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3f_0           ,   e3f_n            !: f- vert. scale factor [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3w_0 ,   e3w_b ,   e3w_n            !: w- vert. scale factor [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::    e3uw_0 ,  e3uw_b ,  e3uw_n            !: uw-vert. scale factor [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::    e3vw_0 ,  e3vw_b ,  e3vw_n            !: vw-vert. scale factor [m]
+
+   !                                                        !  ref.   ! before  !   now   !
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdept_0 , gdept_b , gdept_n   !: t- depth              [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdepw_0 , gdepw_b , gdepw_n   !: w- depth              [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gde3w_0           , gde3w_n   !: w- depth (sum of e3w) [m]
+   
+   !                                                      !  ref. ! before  !   now   !  after  !
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ht_0            ,    ht_n             !: t-depth              [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hu_0  ,    hu_b ,    hu_n ,    hu_a   !: u-depth              [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hv_0  ,    hv_b ,    hv_n ,    hv_a   !: u-depth              [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::           r1_hu_b , r1_hu_n , r1_hu_a   !: inverse of u-depth [1/m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::           r1_hv_b , r1_hv_n , r1_hv_a   !: inverse of v-depth [1/m]
+
 
    INTEGER, PUBLIC ::   nla10              !: deepest    W level Above  ~10m (nlb10 - 1)
    INTEGER, PUBLIC ::   nlb10              !: shallowest W level Bellow ~10m (nla10 + 1) 
 
-   !! z-coordinate with full steps (also used in the other cases as reference z-coordinate)
+   !! 1D reference  vertical coordinate
    !! =-----------------====------
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   gdept_1d, gdepw_1d !: reference depth of t- and w-points (m)
@@ -231,4 +209,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   e3tp    , e3wp     !: ocean bottom level thickness at T and W points
 
+!!gm  This should be removed from here....  ==>>> only used in domzgr at initialization phase
    !! s-coordinate and hybrid z-s-coordinate
    !! =----------------======---------------
@@ -244,4 +223,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hift  , hifu       !: and quasi-uniform spacing             t--u points (m)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rx1                !: Maximum grid stiffness ratio
+!!gm end
 
    !!----------------------------------------------------------------------
@@ -251,12 +231,13 @@
    INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbkt               !: vertical index of the bottom last T- ocean level
    INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbku, mbkv         !: vertical index of the bottom last U- and W- ocean level
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bathy                              !: ocean depth (meters)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmask_i, umask_i, vmask_i, fmask_i !: interior domain T-point mask
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bathy              !: ocean depth (meters)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmask_i            !: interior domain T-point mask
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmask_h            !: internal domain T-point mask (Figure 8.5 NEMO book)
 
    INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   misfdep                 !: top first ocean level                (ISF)
    INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mikt, miku, mikv, mikf  !: first wet T-, U-, V-, F- ocean level (ISF)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   risfdep                 !: Iceshelf draft                       (ISF)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ssmask                   !: surface domain T-point mask 
-
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ssmask, ssumask, ssvmask, ssfmask    !: surface mask at T-,U-, V- and F-pts
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:), TARGET :: tmask, umask, vmask, fmask   !: land/ocean mask at T-, U-, V- and F-pts
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:), TARGET :: wmask, wumask, wvmask        !: land/ocean mask at WT-, WU- and WV-pts
@@ -270,4 +251,6 @@
    INTEGER , PUBLIC ::   nmonth        !: current month
    INTEGER , PUBLIC ::   nday          !: current day of the month
+   INTEGER , PUBLIC ::   nhour         !: current hour
+   INTEGER , PUBLIC ::   nminute       !: current minute
    INTEGER , PUBLIC ::   ndastp        !: time step date in yyyymmdd format
    INTEGER , PUBLIC ::   nday_year     !: current day counted from jan 1st of the current year
@@ -306,5 +289,5 @@
    !!----------------------------------------------------------------------
    !! NEMO/OPA 4.0 , NEMO Consortium (2011)
-   !! $Id$ 
+   !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -330,5 +313,5 @@
       ierr(:) = 0
       !
-      ALLOCATE( rdttra(jpk), r2dtra(jpk), mig(jpi), mjg(jpj), nfiimpp(jpni,jpnj),  &
+      ALLOCATE( mig(jpi), mjg(jpj), nfiimpp(jpni,jpnj),  &
          &      nfipproc(jpni,jpnj), nfilcit(jpni,jpnj), STAT=ierr(1) )
          !
@@ -351,24 +334,22 @@
          &        ff (jpi,jpj)                                                         , STAT=ierr(3) )
          !
-      ALLOCATE( gdep3w_0(jpi,jpj,jpk) , e3v_0(jpi,jpj,jpk) , e3f_0 (jpi,jpj,jpk) ,                         &
-         &      gdept_0 (jpi,jpj,jpk) , e3t_0(jpi,jpj,jpk) , e3u_0 (jpi,jpj,jpk) ,                         &
-         &      gdepw_0 (jpi,jpj,jpk) , e3w_0(jpi,jpj,jpk) , e3vw_0(jpi,jpj,jpk) , e3uw_0(jpi,jpj,jpk) , STAT=ierr(4) )
-         !
-#if defined key_vvl
-      ALLOCATE( gdep3w_n(jpi,jpj,jpk) , e3t_n (jpi,jpj,jpk) , e3u_n (jpi,jpj,jpk) ,                           &
-         &      gdept_n (jpi,jpj,jpk) , e3v_n (jpi,jpj,jpk) , e3w_n (jpi,jpj,jpk) ,                           &
-         &      gdepw_n (jpi,jpj,jpk) , e3f_n (jpi,jpj,jpk) , e3vw_n(jpi,jpj,jpk) , e3uw_n(jpi,jpj,jpk) ,     &
-         &      e3t_b   (jpi,jpj,jpk) , e3u_b (jpi,jpj,jpk) , e3v_b (jpi,jpj,jpk) ,                           &
-         &      e3uw_b  (jpi,jpj,jpk) , e3vw_b(jpi,jpj,jpk) ,                                                 &
-         &      gdept_b (jpi,jpj,jpk) ,gdepw_b(jpi,jpj,jpk) , e3w_b (jpi,jpj,jpk) ,                           &
-         &      e3t_a   (jpi,jpj,jpk) , e3u_a (jpi,jpj,jpk) , e3v_a (jpi,jpj,jpk) ,                           &
-         &      ehu_a   (jpi,jpj)     , ehv_a (jpi,jpj),                                                     &
-         &      ehur_a  (jpi,jpj)     , ehvr_a(jpi,jpj),                                                     &
-         &      ehu_b   (jpi,jpj)     , ehv_b (jpi,jpj),                                                     &
-         &      ehur_b  (jpi,jpj)     , ehvr_b(jpi,jpj),                                  STAT=ierr(5) )                          
-#endif
-         !
-      ALLOCATE( hu(jpi,jpj) , hur(jpi,jpj) , hu_0(jpi,jpj) , ht_0(jpi,jpj) ,     &
-         &      hv(jpi,jpj) , hvr(jpi,jpj) , hv_0(jpi,jpj) , ht  (jpi,jpj) , STAT=ierr(6)  )
+      ALLOCATE( gdept_0(jpi,jpj,jpk) , gdepw_0(jpi,jpj,jpk) , gde3w_0(jpi,jpj,jpk) ,     &
+         &      gdept_b(jpi,jpj,jpk) , gdepw_b(jpi,jpj,jpk) ,                             &
+         &      gdept_n(jpi,jpj,jpk) , gdepw_n(jpi,jpj,jpk) , gde3w_n(jpi,jpj,jpk) , STAT=ierr(4) )
+         !
+      ALLOCATE( e3t_0(jpi,jpj,jpk) , e3u_0(jpi,jpj,jpk) , e3v_0(jpi,jpj,jpk) , e3f_0(jpi,jpj,jpk) , e3w_0(jpi,jpj,jpk) ,   &
+         &      e3t_b(jpi,jpj,jpk) , e3u_b(jpi,jpj,jpk) , e3v_b(jpi,jpj,jpk) ,                      e3w_b(jpi,jpj,jpk) ,   & 
+         &      e3t_n(jpi,jpj,jpk) , e3u_n(jpi,jpj,jpk) , e3v_n(jpi,jpj,jpk) , e3f_n(jpi,jpj,jpk) , e3w_n(jpi,jpj,jpk) ,   & 
+         &      e3t_a(jpi,jpj,jpk) , e3u_a(jpi,jpj,jpk) , e3v_a(jpi,jpj,jpk) ,                                             &
+         !                                                          !
+         &      e3uw_0(jpi,jpj,jpk) , e3vw_0(jpi,jpj,jpk) ,         &
+         &      e3uw_b(jpi,jpj,jpk) , e3vw_b(jpi,jpj,jpk) ,         &               
+         &      e3uw_n(jpi,jpj,jpk) , e3vw_n(jpi,jpj,jpk) ,     STAT=ierr(5) )                       
+         !
+      ALLOCATE( ht_0(jpi,jpj) , hu_0(jpi,jpj) , hv_0(jpi,jpj) ,                                           &
+         &                      hu_b(jpi,jpj) , hv_b(jpi,jpj) , r1_hu_b(jpi,jpj) , r1_hv_b(jpi,jpj) ,     &
+         &      ht_n(jpi,jpj) , hu_n(jpi,jpj) , hv_n(jpi,jpj) , r1_hu_n(jpi,jpj) , r1_hv_n(jpi,jpj) ,     &
+         &                      hu_a(jpi,jpj) , hv_a(jpi,jpj) , r1_hu_a(jpi,jpj) , r1_hv_a(jpi,jpj) , STAT=ierr(6)  )
+         !
          !
       ALLOCATE( gdept_1d(jpk) , gdepw_1d(jpk) ,                                     &
@@ -383,12 +364,13 @@
          &      hift  (jpi,jpj) , hifu  (jpi,jpj) , rx1(jpi,jpj) , STAT=ierr(8) )
 
-      ALLOCATE( mbathy(jpi,jpj) , bathy(jpi,jpj) ,                                      &
-         &     tmask_i(jpi,jpj) , umask_i(jpi,jpj), vmask_i(jpi,jpj), fmask_i(jpi,jpj), &
-         &     mbkt   (jpi,jpj) , mbku (jpi,jpj) , mbkv(jpi,jpj) , STAT=ierr(9) )
+      ALLOCATE( mbathy(jpi,jpj) , bathy  (jpi,jpj) ,                                       &
+         &     tmask_i(jpi,jpj) , tmask_h(jpi,jpj) ,                                       & 
+         &     ssmask (jpi,jpj) , ssumask(jpi,jpj) , ssvmask(jpi,jpj) , ssfmask(jpi,jpj) , &
+         &     mbkt   (jpi,jpj) , mbku   (jpi,jpj) , mbkv   (jpi,jpj) , STAT=ierr(9) )
 
 ! (ISF) Allocation of basic array   
-      ALLOCATE( misfdep(jpi,jpj) , risfdep(jpi,jpj),                   &
-         &      mikt(jpi,jpj), miku(jpi,jpj), mikv(jpi,jpj) ,           &
-         &      mikf(jpi,jpj), ssmask(jpi,jpj), STAT=ierr(10) )
+      ALLOCATE( misfdep(jpi,jpj) , risfdep(jpi,jpj),     &
+         &     mikt(jpi,jpj), miku(jpi,jpj), mikv(jpi,jpj) ,           &
+         &     mikf(jpi,jpj), STAT=ierr(10) )
 
       ALLOCATE( tmask(jpi,jpj,jpk) , umask(jpi,jpj,jpk),     & 
@@ -403,3 +385,2 @@
    !!======================================================================
 END MODULE dom_oce
-
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 6140)
@@ -13,4 +13,5 @@
    !!            3.3  !  2010-11  (G. Madec)  initialisation in C1D configuration
    !!            3.6  !  2013     ( J. Simeon, C. Calone, G. Madec, C. Ethe ) Online coarsening of outputs
+   !!            3.7  !  2015-11  (G. Madec, A. Coward)  time varying zgr by default
    !!----------------------------------------------------------------------
    
@@ -36,4 +37,5 @@
    !
    USE in_out_manager  ! I/O manager
+   USE wrk_nemo        ! Memory Allocation
    USE lib_mpp         ! distributed memory computing library
    USE lbclnk          ! ocean lateral boundary condition (or mpp link)
@@ -45,6 +47,4 @@
    PUBLIC   dom_init   ! called by opa.F90
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!-------------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -70,6 +70,7 @@
       !!              - 1D configuration, move Coriolis, u and v at T-point
       !!----------------------------------------------------------------------
-      INTEGER ::   jk          ! dummy loop argument
+      INTEGER ::   jk          ! dummy loop indices
       INTEGER ::   iconf = 0   ! local integers
+      REAL(wp), POINTER, DIMENSION(:,:) ::   z1_hu_0, z1_hv_0
       !!----------------------------------------------------------------------
       !
@@ -82,15 +83,17 @@
       ENDIF
       !
-                             CALL dom_nam      ! read namelist ( namrun, namdom )
-                             CALL dom_clo      ! Closed seas and lake
-                             CALL dom_hgr      ! Horizontal mesh
-                             CALL dom_zgr      ! Vertical mesh and bathymetry
-                             CALL dom_msk      ! Masks
-      IF( ln_sco )           CALL dom_stiff    ! Maximum stiffness ratio/hydrostatic consistency
-      !
-      ht_0(:,:) = 0._wp                        ! Reference ocean depth at T-points
-      hu_0(:,:) = 0._wp                        ! Reference ocean depth at U-points
-      hv_0(:,:) = 0._wp                        ! Reference ocean depth at V-points
-      DO jk = 1, jpk
+      !                       !==  Reference coordinate system  ==!
+      !
+                     CALL dom_nam               ! read namelist ( namrun, namdom )
+                     CALL dom_clo               ! Closed seas and lake
+                     CALL dom_hgr               ! Horizontal mesh
+                     CALL dom_zgr               ! Vertical mesh and bathymetry
+                     CALL dom_msk               ! Masks
+      IF( ln_sco )   CALL dom_stiff             ! Maximum stiffness ratio/hydrostatic consistency
+      !
+      ht_0(:,:) = e3t_0(:,:,1) * tmask(:,:,1)   ! Reference ocean thickness
+      hu_0(:,:) = e3u_0(:,:,1) * umask(:,:,1)
+      hv_0(:,:) = e3v_0(:,:,1) * vmask(:,:,1)
+      DO jk = 2, jpk
          ht_0(:,:) = ht_0(:,:) + e3t_0(:,:,jk) * tmask(:,:,jk)
          hu_0(:,:) = hu_0(:,:) + e3u_0(:,:,jk) * umask(:,:,jk)
@@ -98,24 +101,46 @@
       END DO
       !
-      IF( lk_vvl         )   CALL dom_vvl_init ! Vertical variable mesh
-      !
-      IF( lk_c1d         )   CALL cor_c1d      ! 1D configuration: Coriolis set at T-point
-      !
-      !
-      hu(:,:) = 0._wp                          ! Ocean depth at U-points
-      hv(:,:) = 0._wp                          ! Ocean depth at V-points
-      ht(:,:) = 0._wp                          ! Ocean depth at T-points
-      DO jk = 1, jpkm1
-         hu(:,:) = hu(:,:) + fse3u_n(:,:,jk) * umask(:,:,jk)
-         hv(:,:) = hv(:,:) + fse3v_n(:,:,jk) * vmask(:,:,jk)
-         ht(:,:) = ht(:,:) + fse3t_n(:,:,jk) * tmask(:,:,jk)
-      END DO
-      !                                        ! Inverse of the local depth
-      hur(:,:) = 1._wp / ( hu(:,:) + 1._wp - umask_i(:,:) ) * umask_i(:,:)
-      hvr(:,:) = 1._wp / ( hv(:,:) + 1._wp - vmask_i(:,:) ) * vmask_i(:,:)
-
-                             CALL dom_stp      ! time step
-      IF( nmsh /= 0      )   CALL dom_wri      ! Create a domain file
-      IF( .NOT.ln_rstart )   CALL dom_ctl      ! Domain control
+      !              !==  time varying part of coordinate system  ==!
+      !
+      IF( ln_linssh ) THEN          ! Fix in time : set to the reference one for all
+         !       before        !          now          !       after         !
+         ;  gdept_b = gdept_0  ;   gdept_n = gdept_0   !        ---          ! depth of grid-points
+         ;  gdepw_b = gdepw_0  ;   gdepw_n = gdepw_0   !        ---          !
+         ;                     ;   gde3w_n = gde3w_0   !        ---          !
+         !                                                                  
+         ;    e3t_b =   e3t_0  ;     e3t_n =   e3t_0   ;   e3t_a =  e3t_0    ! scale factors
+         ;    e3u_b =   e3u_0  ;     e3u_n =   e3u_0   ;   e3u_a =  e3u_0    !
+         ;    e3v_b =   e3v_0  ;     e3v_n =   e3v_0   ;   e3v_a =  e3v_0    !
+         ;                     ;     e3f_n =   e3f_0   !        ---          !
+         ;    e3w_b =   e3w_0  ;     e3w_n =   e3w_0   !        ---          !
+         ;   e3uw_b =  e3uw_0  ;    e3uw_n =  e3uw_0   !        ---          !
+         ;   e3vw_b =  e3vw_0  ;    e3vw_n =  e3vw_0   !        ---          !
+         !
+         CALL wrk_alloc( jpi,jpj,   z1_hu_0, z1_hv_0 )
+         !
+         z1_hu_0(:,:) = ssumask(:,:) / ( hu_0(:,:) + 1._wp - ssumask(:,:) )     ! _i mask due to ISF
+         z1_hv_0(:,:) = ssvmask(:,:) / ( hv_0(:,:) + 1._wp - ssvmask(:,:) )
+         !
+         !        before       !          now          !       after         !
+         ;                     ;      ht_n =    ht_0   !                     ! water column thickness
+         ;     hu_b =    hu_0  ;      hu_n =    hu_0   ;    hu_a =    hu_0   ! 
+         ;     hv_b =    hv_0  ;      hv_n =    hv_0   ;    hv_a =    hv_0   !
+         ;  r1_hu_b = z1_hu_0  ;   r1_hu_n = z1_hu_0   ; r1_hu_a = z1_hu_0   ! inverse of water column thickness
+         ;  r1_hv_b = z1_hv_0  ;   r1_hv_n = z1_hv_0   ; r1_hv_a = z1_hv_0   !
+         !
+         CALL wrk_dealloc( jpi,jpj,   z1_hu_0, z1_hv_0 )
+         !
+      ELSE                         ! time varying : initialize before/now/after variables
+         !
+         CALL dom_vvl_init 
+         !
+      ENDIF
+      !
+      IF( lk_c1d         )   CALL cor_c1d       ! 1D configuration: Coriolis set at T-point
+      !
+                             CALL dom_stp       ! time step
+      IF( nmsh /= 0 .AND. .NOT. ln_iscpl )                         CALL dom_wri      ! Create a domain file
+      IF( nmsh /= 0 .AND.       ln_iscpl .AND. .NOT. ln_rstart )   CALL dom_wri      ! Create a domain file
+      IF( .NOT.ln_rstart )   CALL dom_ctl       ! Domain control
       !
       IF( nn_timing == 1 )   CALL timing_stop('dom_init')
@@ -135,14 +160,13 @@
       !!----------------------------------------------------------------------
       USE ioipsl
-      NAMELIST/namrun/ cn_ocerst_indir, cn_ocerst_outdir, nn_stocklist, ln_rst_list,               &
-         &             nn_no   , cn_exp    , cn_ocerst_in, cn_ocerst_out, ln_rstart , nn_rstctl,   &
-         &             nn_it000, nn_itend  , nn_date0    , nn_leapy     , nn_istate , nn_stock ,   &
-         &             nn_write, ln_dimgnnn, ln_mskland  , ln_cfmeta    , ln_clobber, nn_chunksz, nn_euler
-      NAMELIST/namdom/ nn_bathy, rn_bathy , rn_e3zps_min, rn_e3zps_rat, nn_msh, rn_hmin,   &
-         &             nn_acc   , rn_atfp     , rn_rdt      , rn_rdtmin ,                  &
-         &             rn_rdtmax, rn_rdth     , nn_closea , ln_crs,    &
-         &             jphgr_msh, &
-         &             ppglam0, ppgphi0, ppe1_deg, ppe2_deg, ppe1_m, ppe2_m, &
-         &             ppsur, ppa0, ppa1, ppkth, ppacr, ppdzmin, pphmax, ldbletanh, &
+      NAMELIST/namrun/ cn_ocerst_indir, cn_ocerst_outdir, nn_stocklist, ln_rst_list,                 &
+                       nn_no   , cn_exp   , cn_ocerst_in, cn_ocerst_out, ln_rstart , nn_rstctl ,     &
+         &             nn_it000, nn_itend , nn_date0    , nn_time0     , nn_leapy  , nn_istate ,     &
+         &             nn_stock, nn_write , ln_mskland  , ln_clobber   , nn_chunksz, nn_euler  ,     &
+         &             ln_cfmeta, ln_iscpl
+      NAMELIST/namdom/ nn_bathy, rn_bathy , rn_e3zps_min, rn_e3zps_rat, nn_msh, rn_hmin, rn_isfhmin, &
+         &             rn_atfp , rn_rdt   , nn_closea   , ln_crs      , jphgr_msh ,                  &
+         &             ppglam0, ppgphi0, ppe1_deg, ppe2_deg, ppe1_m, ppe2_m,                         &
+         &             ppsur, ppa0, ppa1, ppkth, ppacr, ppdzmin, pphmax, ldbletanh,                  &
          &             ppa2, ppkth2, ppacr2
 #if defined key_netcdf4
@@ -178,4 +202,5 @@
          WRITE(numout,*) '      number of the last time step    nn_itend   = ', nn_itend
          WRITE(numout,*) '      initial calendar date aammjj    nn_date0   = ', nn_date0
+         WRITE(numout,*) '      initial time of day in hhmm     nn_time0   = ', nn_time0
          WRITE(numout,*) '      leap year calendar (0/1)        nn_leapy   = ', nn_leapy
          WRITE(numout,*) '      initial state output            nn_istate  = ', nn_istate
@@ -186,9 +211,9 @@
          ENDIF
          WRITE(numout,*) '      frequency of output file        nn_write   = ', nn_write
-         WRITE(numout,*) '      multi file dimgout              ln_dimgnnn = ', ln_dimgnnn
          WRITE(numout,*) '      mask land points                ln_mskland = ', ln_mskland
          WRITE(numout,*) '      additional CF standard metadata ln_cfmeta  = ', ln_cfmeta
          WRITE(numout,*) '      overwrite an existing file      ln_clobber = ', ln_clobber
          WRITE(numout,*) '      NetCDF chunksize (bytes)        nn_chunksz = ', nn_chunksz
+         WRITE(numout,*) '      IS coupling at the restart step ln_iscpl   = ', ln_iscpl
       ENDIF
 
@@ -258,4 +283,5 @@
          WRITE(numout,*) '      min depth of the ocean    (>0) or    rn_hmin   = ', rn_hmin
          WRITE(numout,*) '      min number of ocean level (<0)       '
+         WRITE(numout,*) '      treshold to open the isf cavity   rn_isfhmin   = ', rn_isfhmin, ' (m)'
          WRITE(numout,*) '      minimum thickness of partial      rn_e3zps_min = ', rn_e3zps_min, ' (m)'
          WRITE(numout,*) '         step level                     rn_e3zps_rat = ', rn_e3zps_rat
@@ -267,8 +293,4 @@
          WRITE(numout,*) '      ocean time step                       rn_rdt    = ', rn_rdt
          WRITE(numout,*) '      asselin time filter parameter         rn_atfp   = ', rn_atfp
-         WRITE(numout,*) '      acceleration of converge              nn_acc    = ', nn_acc
-         WRITE(numout,*) '        nn_acc=1: surface tracer rdt        rn_rdtmin = ', rn_rdtmin
-         WRITE(numout,*) '                  bottom  tracer rdt        rdtmax    = ', rn_rdtmax
-         WRITE(numout,*) '                  depth of transition       rn_rdth   = ', rn_rdth
          WRITE(numout,*) '      suppression of closed seas (=0)       nn_closea = ', nn_closea
          WRITE(numout,*) '      online coarsening of dynamical fields ln_crs    = ', ln_crs
@@ -297,10 +319,6 @@
       e3zps_rat = rn_e3zps_rat
       nmsh      = nn_msh
-      nacc      = nn_acc
       atfp      = rn_atfp
       rdt       = rn_rdt
-      rdtmin    = rn_rdtmin
-      rdtmax    = rn_rdtmin
-      rdth      = rn_rdth
 
 #if defined key_netcdf4
@@ -403,5 +421,5 @@
       INTEGER  ::   ji, jj, jk 
       REAL(wp) ::   zrxmax
-      REAL(wp), DIMENSION(4) :: zr1
+      REAL(wp), DIMENSION(4) ::   zr1
       !!----------------------------------------------------------------------
       rx1(:,:) = 0._wp
@@ -412,22 +430,22 @@
          DO jj = 2, jpjm1
             DO jk = 1, jpkm1
-               zr1(1) = umask(ji-1,jj  ,jk) *abs( (gdepw_0(ji  ,jj  ,jk  )-gdepw_0(ji-1,jj  ,jk  )  & 
-                    &                         +gdepw_0(ji  ,jj  ,jk+1)-gdepw_0(ji-1,jj  ,jk+1)) &
-                    &                        /(gdepw_0(ji  ,jj  ,jk  )+gdepw_0(ji-1,jj  ,jk  )  &
-                    &                         -gdepw_0(ji  ,jj  ,jk+1)-gdepw_0(ji-1,jj  ,jk+1) + rsmall) )
-               zr1(2) = umask(ji  ,jj  ,jk) *abs( (gdepw_0(ji+1,jj  ,jk  )-gdepw_0(ji  ,jj  ,jk  )  &
-                    &                         +gdepw_0(ji+1,jj  ,jk+1)-gdepw_0(ji  ,jj  ,jk+1)) &
-                    &                        /(gdepw_0(ji+1,jj  ,jk  )+gdepw_0(ji  ,jj  ,jk  )  &
-                    &                         -gdepw_0(ji+1,jj  ,jk+1)-gdepw_0(ji  ,jj  ,jk+1) + rsmall) )
-               zr1(3) = vmask(ji  ,jj  ,jk) *abs( (gdepw_0(ji  ,jj+1,jk  )-gdepw_0(ji  ,jj  ,jk  )  &
-                    &                         +gdepw_0(ji  ,jj+1,jk+1)-gdepw_0(ji  ,jj  ,jk+1)) &
-                    &                        /(gdepw_0(ji  ,jj+1,jk  )+gdepw_0(ji  ,jj  ,jk  )  &
-                    &                         -gdepw_0(ji  ,jj+1,jk+1)-gdepw_0(ji  ,jj  ,jk+1) + rsmall) )
-               zr1(4) = vmask(ji  ,jj-1,jk) *abs( (gdepw_0(ji  ,jj  ,jk  )-gdepw_0(ji  ,jj-1,jk  )  &
-                    &                         +gdepw_0(ji  ,jj  ,jk+1)-gdepw_0(ji  ,jj-1,jk+1)) &
-                    &                        /(gdepw_0(ji  ,jj  ,jk  )+gdepw_0(ji  ,jj-1,jk  )  &
-                    &                         -gdepw_0(ji,  jj  ,jk+1)-gdepw_0(ji  ,jj-1,jk+1) + rsmall) )
-               zrxmax = MAXVAL(zr1(1:4))
-               rx1(ji,jj) = MAX(rx1(ji,jj), zrxmax)
+               zr1(1) = ABS(  ( gdepw_0(ji  ,jj,jk  )-gdepw_0(ji-1,jj,jk  )               & 
+                    &          +gdepw_0(ji  ,jj,jk+1)-gdepw_0(ji-1,jj,jk+1) )             &
+                    &       / ( gdepw_0(ji  ,jj,jk  )+gdepw_0(ji-1,jj,jk  )               &
+                    &          -gdepw_0(ji  ,jj,jk+1)-gdepw_0(ji-1,jj,jk+1) + rsmall )  ) * umask(ji-1,jj,jk)
+               zr1(2) = ABS(  ( gdepw_0(ji+1,jj,jk  )-gdepw_0(ji  ,jj,jk  )               &
+                    &          +gdepw_0(ji+1,jj,jk+1)-gdepw_0(ji  ,jj,jk+1) )             &
+                    &       / ( gdepw_0(ji+1,jj,jk  )+gdepw_0(ji  ,jj,jk  )               &
+                    &          -gdepw_0(ji+1,jj,jk+1)-gdepw_0(ji  ,jj,jk+1) + rsmall )  ) * umask(ji  ,jj,jk)
+               zr1(3) = ABS(  ( gdepw_0(ji,jj+1,jk  )-gdepw_0(ji,jj  ,jk  )               &
+                    &          +gdepw_0(ji,jj+1,jk+1)-gdepw_0(ji,jj  ,jk+1) )             &
+                    &       / ( gdepw_0(ji,jj+1,jk  )+gdepw_0(ji,jj  ,jk  )               &
+                    &          -gdepw_0(ji,jj+1,jk+1)-gdepw_0(ji,jj  ,jk+1) + rsmall )  ) * vmask(ji,jj  ,jk)
+               zr1(4) = ABS(  ( gdepw_0(ji,jj  ,jk  )-gdepw_0(ji,jj-1,jk  )               &
+                    &          +gdepw_0(ji,jj  ,jk+1)-gdepw_0(ji,jj-1,jk+1) )             &
+                    &       / ( gdepw_0(ji,jj  ,jk  )+gdepw_0(ji,jj-1,jk  )               &
+                    &          -gdepw_0(ji,jj  ,jk+1)-gdepw_0(ji,jj-1,jk+1) + rsmall )  ) * vmask(ji,jj-1,jk)
+               zrxmax = MAXVAL( zr1(1:4) )
+               rx1(ji,jj) = MAX( rx1(ji,jj) , zrxmax )
             END DO
          END DO
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domcfg.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domcfg.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domcfg.F90	(revision 6140)
@@ -118,22 +118,24 @@
          WRITE(numout,*) '          south-west indices    jpizoom = ', jpizoom,   &
             &                                           ' jpjzoom = ', jpjzoom
-         WRITE(numout,*)
-         WRITE(numout,*) '          conversion local  ==> data i-index domain'
-         WRITE(numout,25)              (mig(ji),ji = 1,jpi)
-         WRITE(numout,*)
-         WRITE(numout,*) '          conversion data   ==> local  i-index domain'
-         WRITE(numout,*) '             starting index'
-         WRITE(numout,25)              (mi0(ji),ji = 1,jpidta)
-         WRITE(numout,*) '             ending index'
-         WRITE(numout,25)              (mi1(ji),ji = 1,jpidta)
-         WRITE(numout,*)
-         WRITE(numout,*) '          conversion local  ==> data j-index domain'
-         WRITE(numout,25)              (mjg(jj),jj = 1,jpj)
-         WRITE(numout,*)
-         WRITE(numout,*) '          conversion data  ==> local j-index domain'
-         WRITE(numout,*) '             starting index'
-         WRITE(numout,25)              (mj0(jj),jj = 1,jpjdta)
-         WRITE(numout,*) '             ending index'
-         WRITE(numout,25)              (mj1(jj),jj = 1,jpjdta)
+         IF( nn_print >= 1 ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) '          conversion local  ==> data i-index domain'
+            WRITE(numout,25)              (mig(ji),ji = 1,jpi)
+            WRITE(numout,*)
+            WRITE(numout,*) '          conversion data   ==> local  i-index domain'
+            WRITE(numout,*) '             starting index'
+            WRITE(numout,25)              (mi0(ji),ji = 1,jpidta)
+            WRITE(numout,*) '             ending index'
+            WRITE(numout,25)              (mi1(ji),ji = 1,jpidta)
+            WRITE(numout,*)
+            WRITE(numout,*) '          conversion local  ==> data j-index domain'
+            WRITE(numout,25)              (mjg(jj),jj = 1,jpj)
+            WRITE(numout,*)
+            WRITE(numout,*) '          conversion data  ==> local j-index domain'
+            WRITE(numout,*) '             starting index'
+            WRITE(numout,25)              (mj0(jj),jj = 1,jpjdta)
+            WRITE(numout,*) '             ending index'
+            WRITE(numout,25)              (mj1(jj),jj = 1,jpjdta)
+         ENDIF
       ENDIF
  25   FORMAT( 100(10x,19i4,/) )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domhgr.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domhgr.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domhgr.F90	(revision 6140)
@@ -348,5 +348,5 @@
       e1_e2v(:,:) = e1v(:,:) / e2v(:,:)
 
-      IF( lwp .AND. .NOT.ln_rstart ) THEN      ! Control print : Grid informations (if not restart)
+      IF( lwp .AND. nn_print >=1 .AND. .NOT.ln_rstart ) THEN      ! Control print : Grid informations (if not restart)
          WRITE(numout,*)
          WRITE(numout,*) '          longitude and e1 scale factors'
@@ -391,6 +391,6 @@
          !
 #if defined key_agrif
-         IF ( cp_cfg == 'eel' .AND. jp_cfg == 6 ) THEN    ! for EEL6 configuration only
-            IF( .NOT. Agrif_Root() ) THEN
+         IF( cp_cfg == 'eel' .AND. jp_cfg == 6 ) THEN       ! for EEL6 configuration only
+            IF( .NOT.Agrif_Root() ) THEN
               zphi0 = ppgphi0 - REAL( Agrif_Parent(jpjglo)/2)*Agrif_Parent(ppe2_m) / (ra * rad)
             ENDIF
@@ -506,34 +506,4 @@
       CALL iom_close( inum )
       
-!!gm   THIS is TO BE REMOVED !!!!!!!
-
-! need to be define for the extended grid south of -80S
-! some point are undefined but you need to have e1 and e2 .NE. 0
-      WHERE (e1t==0.0_wp)
-         e1t=1.0e2
-      END WHERE
-      WHERE (e1v==0.0_wp)
-         e1v=1.0e2
-      END WHERE
-      WHERE (e1u==0.0_wp)
-         e1u=1.0e2
-      END WHERE
-      WHERE (e1f==0.0_wp)
-         e1f=1.0e2
-      END WHERE
-      WHERE (e2t==0.0_wp)
-         e2t=1.0e2
-      END WHERE
-      WHERE (e2v==0.0_wp)
-         e2v=1.0e2
-      END WHERE
-      WHERE (e2u==0.0_wp)
-         e2u=1.0e2
-      END WHERE
-      WHERE (e2f==0.0_wp)
-         e2f=1.0e2
-      END WHERE
-!!gm end
-       
     END SUBROUTINE hgr_read
     
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 6140)
@@ -7,6 +7,5 @@
    !!            6.0  ! 1993-03  (M. Guyon)  symetrical conditions (M. Guyon)
    !!            7.0  ! 1996-01  (G. Madec)  suppression of common work arrays
-   !!             -   ! 1996-05  (G. Madec)  mask computed from tmask and sup-
-   !!                 !                      pression of the double computation of bmask
+   !!             -   ! 1996-05  (G. Madec)  mask computed from tmask
    !!            8.0  ! 1997-02  (G. Madec)  mesh information put in domhgr.F
    !!            8.1  ! 1997-07  (G. Madec)  modification of mbathy and fmask
@@ -25,7 +24,8 @@
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
+   !
    USE in_out_manager  ! I/O manager
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp
+   USE lib_mpp         !
    USE wrk_nemo        ! Memory allocation
    USE timing          ! Timing
@@ -34,5 +34,5 @@
    PRIVATE
 
-   PUBLIC   dom_msk         ! routine called by inidom.F90
+   PUBLIC   dom_msk    ! routine called by inidom.F90
 
    !                            !!* Namelist namlbc : lateral boundary condition *
@@ -171,4 +171,6 @@
       ! --------------------
       tmask_i(:,:) = ssmask(:,:)            ! (ISH) tmask_i = 1 even on the ice shelf
+
+      tmask_h(:,:) = 1._wp                 ! 0 on the halo and 1 elsewhere
       iif = jpreci                         ! ???
       iil = nlci - jpreci + 1
@@ -176,8 +178,8 @@
       ijl = nlcj - jprecj + 1
 
-      tmask_i( 1 :iif,   :   ) = 0._wp      ! first columns
-      tmask_i(iil:jpi,   :   ) = 0._wp      ! last  columns (including mpp extra columns)
-      tmask_i(   :   , 1 :ijf) = 0._wp      ! first rows
-      tmask_i(   :   ,ijl:jpj) = 0._wp      ! last  rows (including mpp extra rows)
+      tmask_h( 1 :iif,   :   ) = 0._wp      ! first columns
+      tmask_h(iil:jpi,   :   ) = 0._wp      ! last  columns (including mpp extra columns)
+      tmask_h(   :   , 1 :ijf) = 0._wp      ! first rows
+      tmask_h(   :   ,ijl:jpj) = 0._wp      ! last  rows (including mpp extra rows)
 
       ! north fold mask
@@ -190,8 +192,11 @@
          IF( mjg(nlej) == jpjglo ) THEN                  ! only half of the nlcj-1 row
             DO ji = iif+1, iil-1
-               tmask_i(ji,nlej-1) = tmask_i(ji,nlej-1) * tpol(mig(ji))
+               tmask_h(ji,nlej-1) = tmask_h(ji,nlej-1) * tpol(mig(ji))
             END DO
          ENDIF
       ENDIF
+     
+      tmask_i(:,:) = tmask_i(:,:) * tmask_h(:,:)
+
       IF( jperio == 5 .OR. jperio == 6 ) THEN      ! F-point pivot
          tpol(     1    :jpiglo) = 0._wp
@@ -213,21 +218,21 @@
          END DO
       END DO
-      ! (ISF) MIN(1,SUM(umask)) is here to check if you have effectively at least 1 wet u point
+      ! (ISF) MIN(1,SUM(umask)) is here to check if you have effectively at least 1 wet cell at u point
       DO jj = 1, jpjm1
          DO ji = 1, fs_jpim1   ! vector loop
-            umask_i(ji,jj)  = ssmask(ji,jj) * ssmask(ji+1,jj  )  * MIN(1._wp,SUM(umask(ji,jj,:)))
-            vmask_i(ji,jj)  = ssmask(ji,jj) * ssmask(ji  ,jj+1)  * MIN(1._wp,SUM(vmask(ji,jj,:)))
+            ssumask(ji,jj)  = ssmask(ji,jj) * ssmask(ji+1,jj  )  * MIN(1._wp,SUM(umask(ji,jj,:)))
+            ssvmask(ji,jj)  = ssmask(ji,jj) * ssmask(ji  ,jj+1)  * MIN(1._wp,SUM(vmask(ji,jj,:)))
          END DO
          DO ji = 1, jpim1      ! NO vector opt.
-            fmask_i(ji,jj) =  ssmask(ji,jj  ) * ssmask(ji+1,jj  )   &
+            ssfmask(ji,jj) =  ssmask(ji,jj  ) * ssmask(ji+1,jj  )   &
                &            * ssmask(ji,jj+1) * ssmask(ji+1,jj+1) * MIN(1._wp,SUM(fmask(ji,jj,:)))
          END DO
       END DO
-      CALL lbc_lnk( umask, 'U', 1._wp )      ! Lateral boundary conditions
-      CALL lbc_lnk( vmask, 'V', 1._wp )
-      CALL lbc_lnk( fmask, 'F', 1._wp )
-      CALL lbc_lnk( umask_i, 'U', 1._wp )      ! Lateral boundary conditions
-      CALL lbc_lnk( vmask_i, 'V', 1._wp )
-      CALL lbc_lnk( fmask_i, 'F', 1._wp )
+      CALL lbc_lnk( umask  , 'U', 1._wp )      ! Lateral boundary conditions
+      CALL lbc_lnk( vmask  , 'V', 1._wp )
+      CALL lbc_lnk( fmask  , 'F', 1._wp )
+      CALL lbc_lnk( ssumask, 'U', 1._wp )      ! Lateral boundary conditions
+      CALL lbc_lnk( ssvmask, 'V', 1._wp )
+      CALL lbc_lnk( ssfmask, 'F', 1._wp )
 
       ! 3. Ocean/land mask at wu-, wv- and w points 
@@ -341,44 +346,6 @@
       !
       CALL lbc_lnk( fmask, 'F', 1._wp )      ! Lateral boundary conditions on fmask
-
+      !
       ! CAUTION : The fmask may be further modified in dyn_vor_init ( dynvor.F90 )
-            
-      IF( nprint == 1 .AND. lwp ) THEN      ! Control print
-         imsk(:,:) = INT( tmask_i(:,:) )
-         WRITE(numout,*) ' tmask_i : '
-         CALL prihin( imsk(:,:), jpi, jpj, 1, jpi, 1,   &
-               &                           1, jpj, 1, 1, numout)
-         WRITE (numout,*)
-         WRITE (numout,*) ' dommsk: tmask for each level'
-         WRITE (numout,*) ' ----------------------------'
-         DO jk = 1, jpk
-            imsk(:,:) = INT( tmask(:,:,jk) )
-
-            WRITE(numout,*)
-            WRITE(numout,*) ' level = ',jk
-            CALL prihin( imsk(:,:), jpi, jpj, 1, jpi, 1,   &
-               &                              1, jpj, 1, 1, numout)
-         END DO
-         WRITE(numout,*)
-         WRITE(numout,*) ' dom_msk: vmask for each level'
-         WRITE(numout,*) ' -----------------------------'
-         DO jk = 1, jpk
-            imsk(:,:) = INT( vmask(:,:,jk) )
-            WRITE(numout,*)
-            WRITE(numout,*) ' level = ',jk
-            CALL prihin( imsk(:,:), jpi, jpj, 1, jpi, 1,   &
-               &                              1, jpj, 1, 1, numout)
-         END DO
-         WRITE(numout,*)
-         WRITE(numout,*) ' dom_msk: fmask for each level'
-         WRITE(numout,*) ' -----------------------------'
-         DO jk = 1, jpk
-            imsk(:,:) = INT( fmask(:,:,jk) )
-            WRITE(numout,*)
-            WRITE(numout,*) ' level = ',jk
-            CALL prihin( imsk(:,:), jpi, jpj, 1, jpi, 1,   &
-               &                              1, jpj, 1, 1, numout )
-         END DO
-      ENDIF
       !
       CALL wrk_dealloc( jpi, jpj, imsk )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domngb.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domngb.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domngb.F90	(revision 6140)
@@ -28,5 +28,5 @@
 CONTAINS
 
-   SUBROUTINE dom_ngb( plon, plat, kii, kjj, cdgrid )
+   SUBROUTINE dom_ngb( plon, plat, kii, kjj, cdgrid, kkk )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE dom_ngb  ***
@@ -39,6 +39,8 @@
       REAL(wp)        , INTENT(in   ) ::   plon, plat   ! longitude,latitude of the point
       INTEGER         , INTENT(  out) ::   kii, kjj     ! i-,j-index of the closes grid point
+      INTEGER         , INTENT(in   ), OPTIONAL :: kkk  ! k-index of the mask level used
       CHARACTER(len=1), INTENT(in   ) ::   cdgrid       ! grid name 'T', 'U', 'V', 'W'
       !
+      INTEGER :: ik         ! working level
       INTEGER , DIMENSION(2) ::   iloc
       REAL(wp)               ::   zlon, zmini
@@ -51,17 +53,23 @@
       !
       zmask(:,:) = 0._wp
+      ik = 1
+      IF ( PRESENT(kkk) ) ik=kkk
       SELECT CASE( cdgrid )
-      CASE( 'U' )  ; zglam(:,:) = glamu(:,:) ; zgphi(:,:) = gphiu(:,:) ; zmask(nldi:nlei,nldj:nlej) = umask(nldi:nlei,nldj:nlej,1)
-      CASE( 'V' )  ; zglam(:,:) = glamv(:,:) ; zgphi(:,:) = gphiv(:,:) ; zmask(nldi:nlei,nldj:nlej) = vmask(nldi:nlei,nldj:nlej,1)
-      CASE( 'F' )  ; zglam(:,:) = glamf(:,:) ; zgphi(:,:) = gphif(:,:) ; zmask(nldi:nlei,nldj:nlej) = fmask(nldi:nlei,nldj:nlej,1)
-      CASE DEFAULT ; zglam(:,:) = glamt(:,:) ; zgphi(:,:) = gphit(:,:) ; zmask(nldi:nlei,nldj:nlej) = tmask(nldi:nlei,nldj:nlej,1)
+      CASE( 'U' )  ; zglam(:,:) = glamu(:,:) ; zgphi(:,:) = gphiu(:,:) ; zmask(nldi:nlei,nldj:nlej) = umask(nldi:nlei,nldj:nlej,ik)
+      CASE( 'V' )  ; zglam(:,:) = glamv(:,:) ; zgphi(:,:) = gphiv(:,:) ; zmask(nldi:nlei,nldj:nlej) = vmask(nldi:nlei,nldj:nlej,ik)
+      CASE( 'F' )  ; zglam(:,:) = glamf(:,:) ; zgphi(:,:) = gphif(:,:) ; zmask(nldi:nlei,nldj:nlej) = fmask(nldi:nlei,nldj:nlej,ik)
+      CASE DEFAULT ; zglam(:,:) = glamt(:,:) ; zgphi(:,:) = gphit(:,:) ; zmask(nldi:nlei,nldj:nlej) = tmask(nldi:nlei,nldj:nlej,ik)
       END SELECT
 
-      zlon       = MOD( plon       + 720., 360. )                                     ! plon between    0 and 360
-      zglam(:,:) = MOD( zglam(:,:) + 720., 360. )                                     ! glam between    0 and 360
-      IF( zlon > 270. )   zlon = zlon - 360.                                          ! zlon between  -90 and 270
-      IF( zlon <  90. )   WHERE( zglam(:,:) > 180. ) zglam(:,:) = zglam(:,:) - 360.   ! glam between -180 and 180
+      IF (jphgr_msh /= 2 .AND. jphgr_msh /= 3) THEN
+         zlon       = MOD( plon       + 720., 360. )                                     ! plon between    0 and 360
+         zglam(:,:) = MOD( zglam(:,:) + 720., 360. )                                     ! glam between    0 and 360
+         IF( zlon > 270. )   zlon = zlon - 360.                                          ! zlon between  -90 and 270
+         IF( zlon <  90. )   WHERE( zglam(:,:) > 180. ) zglam(:,:) = zglam(:,:) - 360.   ! glam between -180 and 180
+         zglam(:,:) = zglam(:,:) - zlon
+      ELSE
+         zglam(:,:) = zglam(:,:) - plon
+      END IF
 
-      zglam(:,:) = zglam(:,:) - zlon
       zgphi(:,:) = zgphi(:,:) - plat
       zdist(:,:) = zglam(:,:) * zglam(:,:) + zgphi(:,:) * zgphi(:,:)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domstp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domstp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domstp.F90	(revision 6140)
@@ -22,6 +22,4 @@
    PUBLIC   dom_stp   ! routine called by inidom.F90
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -41,17 +39,9 @@
       !!      filter parameter read in namelist
       !!              - Model time step:
-      !!      nacc = 0 : synchronous time intergration. 
-      !!      There is one time step only, defined by: rdt, rdttra(k)=rdt
-      !!      nacc = 1 : accelerating the convergence. There is 2 different
-      !!      time steps for dynamics and tracers:
-      !!        rdt      : dynamical part
-      !!        rdttra(k): temperature and salinity
-      !!      The tracer time step is a function of vertical level. the model
-      !!      reference time step ( i.e. for wind stress, surface heat and
-      !!      salt fluxes) is the surface tracer time step is rdttra(1).
-      !!         N.B. depth dependent acceleration of convergence is not im-
-      !!      plemented for s-coordinate.
+      !!                synchronous time intergration.
+      !!      There is one time step only, defined by: rdt for dynamics and
+      !!      tracer,wind stress, surface heat and salt fluxes
       !!
-      !! ** Action  : - rdttra   : vertical profile of tracer time step
+      !! ** Action  : [REMOVED - rdttra: vertical profile of tracer time step]
       !!              - atfp1    : = 1 - 2*atfp
       !!
@@ -72,37 +62,7 @@
       atfp1 = 1. - 2. * atfp
 
-      SELECT CASE ( nacc )
+      IF(lwp) WRITE(numout,*)'               synchronous time stepping'
+      IF(lwp) WRITE(numout,*)'               dynamics and tracer time step = ', rdt/3600., ' hours'
 
-         CASE ( 0 )                ! Synchronous time stepping
-            IF(lwp) WRITE(numout,*)'               synchronous time stepping'
-            IF(lwp) WRITE(numout,*)'               dynamics and tracer time step = ', rdt/3600., ' hours'
-
-            rdttra(:) = rdt
-
-         CASE ( 1 )                ! Accelerating the convergence
-            IF(lwp) WRITE(numout,*) '              no tracer damping in the turbocline'
-            IF(lwp) WRITE(numout,*)'               accelerating the convergence'
-            IF(lwp) WRITE(numout,*)'               dynamics time step = ', rdt/3600., ' hours'
-            IF( ln_sco .AND. rdtmin /= rdtmax .AND. lk_vvl )   &
-                 & CALL ctl_stop ( ' depth dependent acceleration of convergence not implemented in s-coordinates &
-                 &                   nor in variable volume' )
-            IF(lwp) WRITE(numout,*)'         tracers   time step :  dt (hours)  level'
-
-            DO jk = 1, jpk
-               IF( gdept_1d(jk) <= rdth ) rdttra(jk) = rdtmin
-               IF( gdept_1d(jk) >  rdth ) THEN
-                  rdttra(jk) = rdtmin + ( rdtmax - rdtmin )   &
-                                      * ( EXP( ( gdept_1d(jk ) - rdth ) / rdth ) - 1. )   &
-                                      / ( EXP( ( gdept_1d(jpk) - rdth ) / rdth ) - 1. )
-               ENDIF
-               IF(lwp) WRITE(numout,"(36x,f5.2,5x,i3)") rdttra(jk)/3600., jk
-            END DO  
-
-         CASE DEFAULT              ! E R R O R 
-
-            WRITE(ctmp1,*) ' nacc value e r r o r, nacc= ',nacc
-            CALL ctl_stop( ctmp1 )
-
-      END SELECT
 
    END SUBROUTINE dom_stp
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 6140)
@@ -20,9 +20,11 @@
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers
+   USE phycst          ! physical constant
    USE dom_oce         ! ocean space and time domain
    USE sbc_oce         ! ocean surface boundary condition
+   USE restart         ! ocean restart
+   !
    USE in_out_manager  ! I/O manager
    USE iom             ! I/O manager library
-   USE restart         ! ocean restart
    USE lib_mpp         ! distributed memory computing library
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
@@ -60,12 +62,10 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO-Consortium (2010) 
+   !! NEMO/OPA 3.7 , NEMO-Consortium (2015) 
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -74,5 +74,5 @@
       !!                ***  FUNCTION dom_vvl_alloc  ***
       !!----------------------------------------------------------------------
-      IF( ln_vvl_zstar ) dom_vvl_alloc = 0
+      IF( ln_vvl_zstar )   dom_vvl_alloc = 0
       IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
          ALLOCATE( tilde_e3t_b(jpi,jpj,jpk)  , tilde_e3t_n(jpi,jpj,jpk) , tilde_e3t_a(jpi,jpj,jpk) ,   &
@@ -81,6 +81,6 @@
          IF( lk_mpp             )   CALL mpp_sum ( dom_vvl_alloc )
          IF( dom_vvl_alloc /= 0 )   CALL ctl_warn('dom_vvl_alloc: failed to allocate arrays')
-         un_td = 0.0_wp
-         vn_td = 0.0_wp
+         un_td = 0._wp
+         vn_td = 0._wp
       ENDIF
       IF( ln_vvl_ztilde ) THEN
@@ -89,5 +89,5 @@
          IF( dom_vvl_alloc /= 0 )   CALL ctl_warn('dom_vvl_alloc: failed to allocate arrays')
       ENDIF
-
+      !
    END FUNCTION dom_vvl_alloc
 
@@ -103,11 +103,11 @@
       !!               - interpolate scale factors
       !!
-      !! ** Action  : - fse3t_(n/b) and tilde_e3t_(n/b)
-      !!              - Regrid: fse3(u/v)_n
-      !!                        fse3(u/v)_b       
-      !!                        fse3w_n           
-      !!                        fse3(u/v)w_b      
-      !!                        fse3(u/v)w_n      
-      !!                        fsdept_n, fsdepw_n and fsde3w_n
+      !! ** Action  : - e3t_(n/b) and tilde_e3t_(n/b)
+      !!              - Regrid: e3(u/v)_n
+      !!                        e3(u/v)_b       
+      !!                        e3w_n           
+      !!                        e3(u/v)w_b      
+      !!                        e3(u/v)w_n      
+      !!                        gdept_n, gdepw_n and gde3w_n
       !!              - h(t/u/v)_0
       !!              - frq_rst_e3t and frq_rst_hdv
@@ -115,108 +115,110 @@
       !! Reference  : Leclair, M., and G. Madec, 2011, Ocean Modelling.
       !!----------------------------------------------------------------------
-      USE phycst,  ONLY : rpi, rsmall, rad
-      !! * Local declarations
-      INTEGER ::   ji,jj,jk
+      INTEGER ::   ji, jj, jk
       INTEGER ::   ii0, ii1, ij0, ij1
       REAL(wp)::   zcoef
       !!----------------------------------------------------------------------
-      IF( nn_timing == 1 )  CALL timing_start('dom_vvl_init')
-
+      !
+      IF( nn_timing == 1 )   CALL timing_start('dom_vvl_init')
+      !
       IF(lwp) WRITE(numout,*)
       IF(lwp) WRITE(numout,*) 'dom_vvl_init : Variable volume activated'
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
-
-      ! choose vertical coordinate (z_star, z_tilde or layer)
-      ! ==========================
-      CALL dom_vvl_ctl
-
-      ! Allocate module arrays
-      ! ======================
+      !
+      CALL dom_vvl_ctl     ! choose vertical coordinate (z_star, z_tilde or layer)
+      !
+      !                    ! Allocate module arrays
       IF( dom_vvl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_init : unable to allocate arrays' )
-
-      ! Read or initialize fse3t_(b/n), tilde_e3t_(b/n) and hdiv_lf (and e3t_a(jpk))
-      ! ============================================================================
+      !
+      !                    ! Read or initialize e3t_(b/n), tilde_e3t_(b/n) and hdiv_lf
       CALL dom_vvl_rst( nit000, 'READ' )
-      fse3t_a(:,:,jpk) = e3t_0(:,:,jpk)
-
-      ! Reconstruction of all vertical scale factors at now and before time steps
-      ! =============================================================================
-      ! Horizontal scale factor interpolations
-      ! --------------------------------------
-      CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3u_b(:,:,:), 'U' )
-      CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3v_b(:,:,:), 'V' )
-      CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3u_n(:,:,:), 'U' )
-      CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3v_n(:,:,:), 'V' )
-      CALL dom_vvl_interpol( fse3u_n(:,:,:), fse3f_n(:,:,:), 'F' )
-      ! Vertical scale factor interpolations
-      ! ------------------------------------
-      CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3w_n (:,:,:), 'W'  )
-      CALL dom_vvl_interpol( fse3u_n(:,:,:), fse3uw_n(:,:,:), 'UW' )
-      CALL dom_vvl_interpol( fse3v_n(:,:,:), fse3vw_n(:,:,:), 'VW' )
-      CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3w_b (:,:,:), 'W'  )
-      CALL dom_vvl_interpol( fse3u_b(:,:,:), fse3uw_b(:,:,:), 'UW' )
-      CALL dom_vvl_interpol( fse3v_b(:,:,:), fse3vw_b(:,:,:), 'VW' )
-      ! t- and w- points depth
-      ! ----------------------
-      ! set the isf depth as it is in the initial step
-      fsdept_n(:,:,1) = 0.5_wp * fse3w_n(:,:,1)
-      fsdepw_n(:,:,1) = 0.0_wp
-      fsde3w_n(:,:,1) = fsdept_n(:,:,1) - sshn(:,:)
-      fsdept_b(:,:,1) = 0.5_wp * fse3w_b(:,:,1)
-      fsdepw_b(:,:,1) = 0.0_wp
-
-      DO jk = 2, jpk
+      e3t_a(:,:,jpk) = e3t_0(:,:,jpk)  ! last level always inside the sea floor set one for all
+      !
+      !                    !== Set of all other vertical scale factors  ==!  (now and before)
+      !                                ! Horizontal interpolation of e3t
+      CALL dom_vvl_interpol( e3t_b(:,:,:), e3u_b(:,:,:), 'U' )    ! from T to U
+      CALL dom_vvl_interpol( e3t_n(:,:,:), e3u_n(:,:,:), 'U' )
+      CALL dom_vvl_interpol( e3t_b(:,:,:), e3v_b(:,:,:), 'V' )    ! from T to V 
+      CALL dom_vvl_interpol( e3t_n(:,:,:), e3v_n(:,:,:), 'V' )
+      CALL dom_vvl_interpol( e3u_n(:,:,:), e3f_n(:,:,:), 'F' )    ! from U to F
+      !                                ! Vertical interpolation of e3t,u,v 
+      CALL dom_vvl_interpol( e3t_n(:,:,:), e3w_n (:,:,:), 'W'  )  ! from T to W
+      CALL dom_vvl_interpol( e3t_b(:,:,:), e3w_b (:,:,:), 'W'  )
+      CALL dom_vvl_interpol( e3u_n(:,:,:), e3uw_n(:,:,:), 'UW' )  ! from U to UW
+      CALL dom_vvl_interpol( e3u_b(:,:,:), e3uw_b(:,:,:), 'UW' )
+      CALL dom_vvl_interpol( e3v_n(:,:,:), e3vw_n(:,:,:), 'VW' )  ! from V to UW
+      CALL dom_vvl_interpol( e3v_b(:,:,:), e3vw_b(:,:,:), 'VW' )
+      !
+      !                    !==  depth of t and w-point  ==!   (set the isf depth as it is in the initial timestep)
+      gdept_n(:,:,1) = 0.5_wp * e3w_n(:,:,1)       ! reference to the ocean surface (used for MLD and light penetration)
+      gdepw_n(:,:,1) = 0.0_wp
+      gde3w_n(:,:,1) = gdept_n(:,:,1) - sshn(:,:)  ! reference to a common level z=0 for hpg
+      gdept_b(:,:,1) = 0.5_wp * e3w_b(:,:,1)
+      gdepw_b(:,:,1) = 0.0_wp
+      DO jk = 2, jpk                               ! vertical sum
          DO jj = 1,jpj
             DO ji = 1,jpi
-              !    zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))   ! 0 everywhere tmask = wmask, ie everywhere expect at jk = mikt
-                                                     ! 1 everywhere from mbkt to mikt + 1 or 1 (if no isf)
-                                                     ! 0.5 where jk = mikt  
-               zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))
-               fsdepw_n(ji,jj,jk) = fsdepw_n(ji,jj,jk-1) + fse3t_n(ji,jj,jk-1)
-               fsdept_n(ji,jj,jk) =      zcoef  * ( fsdepw_n(ji,jj,jk  ) + 0.5 * fse3w_n(ji,jj,jk))  &
-                   &                + (1-zcoef) * ( fsdept_n(ji,jj,jk-1) +       fse3w_n(ji,jj,jk)) 
-               fsde3w_n(ji,jj,jk) = fsdept_n(ji,jj,jk) - sshn(ji,jj)
-               fsdepw_b(ji,jj,jk) = fsdepw_b(ji,jj,jk-1) + fse3t_b(ji,jj,jk-1)
-               fsdept_b(ji,jj,jk) =      zcoef  * ( fsdepw_b(ji,jj,jk  ) + 0.5 * fse3w_b(ji,jj,jk))  &
-                   &                + (1-zcoef) * ( fsdept_b(ji,jj,jk-1) +       fse3w_b(ji,jj,jk)) 
+               !    zcoef = tmask - wmask    ! 0 everywhere tmask = wmask, ie everywhere expect at jk = mikt
+               !                             ! 1 everywhere from mbkt to mikt + 1 or 1 (if no isf)
+               !                             ! 0.5 where jk = mikt     
+!!gm ???????   BUG ?  gdept_n as well as gde3w_n  does not include the thickness of ISF ??
+               zcoef = ( tmask(ji,jj,jk) - wmask(ji,jj,jk) )
+               gdepw_n(ji,jj,jk) = gdepw_n(ji,jj,jk-1) + e3t_n(ji,jj,jk-1)
+               gdept_n(ji,jj,jk) =      zcoef  * ( gdepw_n(ji,jj,jk  ) + 0.5 * e3w_n(ji,jj,jk))  &
+                  &                + (1-zcoef) * ( gdept_n(ji,jj,jk-1) +       e3w_n(ji,jj,jk)) 
+               gde3w_n(ji,jj,jk) = gdept_n(ji,jj,jk) - sshn(ji,jj)
+               gdepw_b(ji,jj,jk) = gdepw_b(ji,jj,jk-1) + e3t_b(ji,jj,jk-1)
+               gdept_b(ji,jj,jk) =      zcoef  * ( gdepw_b(ji,jj,jk  ) + 0.5 * e3w_b(ji,jj,jk))  &
+                  &                + (1-zcoef) * ( gdept_b(ji,jj,jk-1) +       e3w_b(ji,jj,jk)) 
             END DO
          END DO
       END DO
-
-      ! Before depth and Inverse of the local depth of the water column at u- and v- points
-      ! -----------------------------------------------------------------------------------
-      hu_b(:,:) = 0.
-      hv_b(:,:) = 0.
-      DO jk = 1, jpkm1
-         hu_b(:,:) = hu_b(:,:) + fse3u_b(:,:,jk) * umask(:,:,jk)
-         hv_b(:,:) = hv_b(:,:) + fse3v_b(:,:,jk) * vmask(:,:,jk)
+      !
+      !                    !==  thickness of the water column  !!   (ocean portion only)
+      ht_n(:,:) = e3t_n(:,:,1) * tmask(:,:,1)   !!gm  BUG  :  this should be 1/2 * e3w(k=1) ....
+      hu_b(:,:) = e3u_b(:,:,1) * umask(:,:,1)
+      hu_n(:,:) = e3u_n(:,:,1) * umask(:,:,1)
+      hv_b(:,:) = e3v_b(:,:,1) * vmask(:,:,1)
+      hv_n(:,:) = e3v_n(:,:,1) * vmask(:,:,1)
+      DO jk = 2, jpkm1
+         ht_n(:,:) = ht_n(:,:) + e3t_n(:,:,jk) * tmask(:,:,jk)
+         hu_b(:,:) = hu_b(:,:) + e3u_b(:,:,jk) * umask(:,:,jk)
+         hu_n(:,:) = hu_n(:,:) + e3u_n(:,:,jk) * umask(:,:,jk)
+         hv_b(:,:) = hv_b(:,:) + e3v_b(:,:,jk) * vmask(:,:,jk)
+         hv_n(:,:) = hv_n(:,:) + e3v_n(:,:,jk) * vmask(:,:,jk)
       END DO
-      hur_b(:,:) = umask_i(:,:) / ( hu_b(:,:) + 1. - umask_i(:,:) )
-      hvr_b(:,:) = vmask_i(:,:) / ( hv_b(:,:) + 1. - vmask_i(:,:) )
-
-      ! Restoring frequencies for z_tilde coordinate
-      ! ============================================
+      !
+      !                    !==  inverse of water column thickness   ==!   (u- and v- points)
+      r1_hu_b(:,:) = ssumask(:,:) / ( hu_b(:,:) + 1._wp - ssumask(:,:) )    ! _i mask due to ISF
+      r1_hu_n(:,:) = ssumask(:,:) / ( hu_n(:,:) + 1._wp - ssumask(:,:) )
+      r1_hv_b(:,:) = ssvmask(:,:) / ( hv_b(:,:) + 1._wp - ssvmask(:,:) )
+      r1_hv_n(:,:) = ssvmask(:,:) / ( hv_n(:,:) + 1._wp - ssvmask(:,:) )
+
+      !                    !==   z_tilde coordinate case  ==!   (Restoring frequencies)
       IF( ln_vvl_ztilde ) THEN
-         ! Values in days provided via the namelist; use rsmall to avoid possible division by zero errors with faulty settings
-         frq_rst_e3t(:,:) = 2.0_wp * rpi / ( MAX( rn_rst_e3t  , rsmall ) * 86400.0_wp )
-         frq_rst_hdv(:,:) = 2.0_wp * rpi / ( MAX( rn_lf_cutoff, rsmall ) * 86400.0_wp )
-         IF( ln_vvl_ztilde_as_zstar ) THEN
-            ! Ignore namelist settings and use these next two to emulate z-star using z-tilde
-            frq_rst_e3t(:,:) = 0.0_wp 
-            frq_rst_hdv(:,:) = 1.0_wp / rdt
-         ENDIF
-         IF ( ln_vvl_zstar_at_eqtor ) THEN
+!!gm : idea: add here a READ in a file of custumized restoring frequency
+         !                                   ! Values in days provided via the namelist
+         !                                   ! use rsmall to avoid possible division by zero errors with faulty settings
+         frq_rst_e3t(:,:) = 2._wp * rpi / ( MAX( rn_rst_e3t  , rsmall ) * 86400.0_wp )
+         frq_rst_hdv(:,:) = 2._wp * rpi / ( MAX( rn_lf_cutoff, rsmall ) * 86400.0_wp )
+         !
+         IF( ln_vvl_ztilde_as_zstar ) THEN   ! z-star emulation using z-tile
+            frq_rst_e3t(:,:) = 0._wp               !Ignore namelist settings
+            frq_rst_hdv(:,:) = 1._wp / rdt
+         ENDIF
+         IF ( ln_vvl_zstar_at_eqtor ) THEN   ! use z-star in vicinity of the Equator
             DO jj = 1, jpj
                DO ji = 1, jpi
+!!gm  case |gphi| >= 6 degrees is useless   initialized just above by default
                   IF( ABS(gphit(ji,jj)) >= 6.) THEN
                      ! values outside the equatorial band and transition zone (ztilde)
                      frq_rst_e3t(ji,jj) =  2.0_wp * rpi / ( MAX( rn_rst_e3t  , rsmall ) * 86400.e0_wp )
                      frq_rst_hdv(ji,jj) =  2.0_wp * rpi / ( MAX( rn_lf_cutoff, rsmall ) * 86400.e0_wp )
-                  ELSEIF( ABS(gphit(ji,jj)) <= 2.5) THEN
+                  ELSEIF( ABS(gphit(ji,jj)) <= 2.5) THEN    ! Equator strip ==> z-star
                      ! values inside the equatorial band (ztilde as zstar)
                      frq_rst_e3t(ji,jj) =  0.0_wp
                      frq_rst_hdv(ji,jj) =  1.0_wp / rdt
-                  ELSE
-                     ! values in the transition band (linearly vary from ztilde to ztilde as zstar values)
+                  ELSE                                      ! transition band (2.5 to 6 degrees N/S)
+                     !                                      ! (linearly transition from z-tilde to z-star)
                      frq_rst_e3t(ji,jj) = 0.0_wp + (frq_rst_e3t(ji,jj)-0.0_wp)*0.5_wp   &
                         &            * (  1.0_wp - COS( rad*(ABS(gphit(ji,jj))-2.5_wp)  &
@@ -229,6 +231,6 @@
                END DO
             END DO
-            IF( cp_cfg == "orca" .AND. jp_cfg == 3 ) THEN
-               ii0 = 103   ;   ii1 = 111        ! Suppress ztilde in the Foxe Basin for ORCA2
+            IF( cp_cfg == "orca" .AND. jp_cfg == 3 ) THEN   ! ORCA2: Suppress ztilde in the Foxe Basin for ORCA2
+               ii0 = 103   ;   ii1 = 111       
                ij0 = 128   ;   ij1 = 135   ;   
                frq_rst_e3t( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  0.0_wp
@@ -237,7 +239,7 @@
          ENDIF
       ENDIF
-
+      !
       IF( nn_timing == 1 )  CALL timing_stop('dom_vvl_init')
-
+      !
    END SUBROUTINE dom_vvl_init
 
@@ -261,25 +263,27 @@
       !!               - tilde_e3t_a: after increment of vertical scale factor 
       !!                              in z_tilde case
-      !!               - fse3(t/u/v)_a
+      !!               - e3(t/u/v)_a
       !!
       !! Reference  : Leclair, M., and Madec, G. 2011, Ocean Modelling.
       !!----------------------------------------------------------------------
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: ze3t
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: zht, z_scale, zwu, zwv, zhdiv
-      !! * Arguments
-      INTEGER, INTENT( in )                  :: kt                    ! time step
-      INTEGER, INTENT( in ), OPTIONAL        :: kcall                 ! optional argument indicating call sequence
-      !! * Local declarations
-      INTEGER                                :: ji, jj, jk            ! dummy loop indices
-      INTEGER , DIMENSION(3)                 :: ijk_max, ijk_min      ! temporary integers
-      REAL(wp)                               :: z2dt                  ! temporary scalars
-      REAL(wp)                               :: z_tmin, z_tmax        ! temporary scalars
-      LOGICAL                                :: ll_do_bclinic         ! temporary logical
-      !!----------------------------------------------------------------------
-      IF( nn_timing == 1 )  CALL timing_start('dom_vvl_sf_nxt')
-      CALL wrk_alloc( jpi, jpj, zht, z_scale, zwu, zwv, zhdiv )
-      CALL wrk_alloc( jpi, jpj, jpk, ze3t                     )
-
-      IF(kt == nit000)   THEN
+      INTEGER, INTENT( in )           ::   kt      ! time step
+      INTEGER, INTENT( in ), OPTIONAL ::   kcall   ! optional argument indicating call sequence
+      !
+      INTEGER                ::   ji, jj, jk            ! dummy loop indices
+      INTEGER , DIMENSION(3) ::   ijk_max, ijk_min      ! temporary integers
+      REAL(wp)               ::   z2dt, z_tmin, z_tmax  ! local scalars
+      LOGICAL                ::   ll_do_bclinic         ! local logical
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ze3t
+      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zht, z_scale, zwu, zwv, zhdiv
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
+      !
+      IF( nn_timing == 1 )   CALL timing_start('dom_vvl_sf_nxt')
+      !
+      CALL wrk_alloc( jpi,jpj,zht,   z_scale, zwu, zwv, zhdiv )
+      CALL wrk_alloc( jpi,jpj,jpk,   ze3t )
+
+      IF( kt == nit000 ) THEN
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*) 'dom_vvl_sf_nxt : compute after scale factors'
@@ -289,5 +293,5 @@
       ll_do_bclinic = .TRUE.
       IF( PRESENT(kcall) ) THEN
-         IF ( kcall == 2 .AND. ln_vvl_ztilde ) ll_do_bclinic = .FALSE.
+         IF( kcall == 2 .AND. ln_vvl_ztilde )   ll_do_bclinic = .FALSE.
       ENDIF
 
@@ -295,18 +299,16 @@
       ! After acale factors at t-points !
       ! ******************************* !
-
       !                                                ! --------------------------------------------- !
-                                                       ! z_star coordinate and barotropic z-tilde part !
+      !                                                ! z_star coordinate and barotropic z-tilde part !
       !                                                ! --------------------------------------------- !
-
+      !
       z_scale(:,:) = ( ssha(:,:) - sshb(:,:) ) * ssmask(:,:) / ( ht_0(:,:) + sshn(:,:) + 1. - ssmask(:,:) )
       DO jk = 1, jpkm1
-         ! formally this is the same as fse3t_a = e3t_0*(1+ssha/ht_0)
-         fse3t_a(:,:,jk) = fse3t_b(:,:,jk) + fse3t_n(:,:,jk) * z_scale(:,:) * tmask(:,:,jk)
+         ! formally this is the same as e3t_a = e3t_0*(1+ssha/ht_0)
+         e3t_a(:,:,jk) = e3t_b(:,:,jk) + e3t_n(:,:,jk) * z_scale(:,:) * tmask(:,:,jk)
       END DO
-
+      !
       IF( ln_vvl_ztilde .OR. ln_vvl_layer .AND. ll_do_bclinic ) THEN   ! z_tilde or layer coordinate !
          !                                                            ! ------baroclinic part------ !
-
          ! I - initialization
          ! ==================
@@ -314,9 +316,9 @@
          ! 1 - barotropic divergence
          ! -------------------------
-         zhdiv(:,:) = 0.
-         zht(:,:)   = 0.
+         zhdiv(:,:) = 0._wp
+         zht(:,:)   = 0._wp
          DO jk = 1, jpkm1
-            zhdiv(:,:) = zhdiv(:,:) + fse3t_n(:,:,jk) * hdivn(:,:,jk)
-            zht  (:,:) = zht  (:,:) + fse3t_n(:,:,jk) * tmask(:,:,jk)
+            zhdiv(:,:) = zhdiv(:,:) + e3t_n(:,:,jk) * hdivn(:,:,jk)
+            zht  (:,:) = zht  (:,:) + e3t_n(:,:,jk) * tmask(:,:,jk)
          END DO
          zhdiv(:,:) = zhdiv(:,:) / ( zht(:,:) + 1. - tmask_i(:,:) )
@@ -325,15 +327,15 @@
          ! --------------------------------------------------
          IF( ln_vvl_ztilde ) THEN
-            IF( kt .GT. nit000 ) THEN
+            IF( kt > nit000 ) THEN
                DO jk = 1, jpkm1
                   hdiv_lf(:,:,jk) = hdiv_lf(:,:,jk) - rdt * frq_rst_hdv(:,:)   &
-                     &          * ( hdiv_lf(:,:,jk) - fse3t_n(:,:,jk) * ( hdivn(:,:,jk) - zhdiv(:,:) ) )
+                     &          * ( hdiv_lf(:,:,jk) - e3t_n(:,:,jk) * ( hdivn(:,:,jk) - zhdiv(:,:) ) )
                END DO
             ENDIF
-         END IF
+         ENDIF
 
          ! II - after z_tilde increments of vertical scale factors
          ! =======================================================
-         tilde_e3t_a(:,:,:) = 0.0_wp  ! tilde_e3t_a used to store tendency terms
+         tilde_e3t_a(:,:,:) = 0._wp  ! tilde_e3t_a used to store tendency terms
 
          ! 1 - High frequency divergence term
@@ -341,11 +343,11 @@
          IF( ln_vvl_ztilde ) THEN     ! z_tilde case
             DO jk = 1, jpkm1
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - ( fse3t_n(:,:,jk) * ( hdivn(:,:,jk) - zhdiv(:,:) ) - hdiv_lf(:,:,jk) )
+               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - ( e3t_n(:,:,jk) * ( hdivn(:,:,jk) - zhdiv(:,:) ) - hdiv_lf(:,:,jk) )
             END DO
          ELSE                         ! layer case
             DO jk = 1, jpkm1
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) -   fse3t_n(:,:,jk) * ( hdivn(:,:,jk) - zhdiv(:,:) ) * tmask(:,:,jk)
-            END DO
-         END IF
+               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) -   e3t_n(:,:,jk) * ( hdivn(:,:,jk) - zhdiv(:,:) ) * tmask(:,:,jk)
+            END DO
+         ENDIF
 
          ! 2 - Restoring term (z-tilde case only)
@@ -355,12 +357,11 @@
                tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - frq_rst_e3t(:,:) * tilde_e3t_b(:,:,jk)
             END DO
-         END IF
+         ENDIF
 
          ! 3 - Thickness diffusion term
          ! ----------------------------
-         zwu(:,:) = 0.0_wp
-         zwv(:,:) = 0.0_wp
-         ! a - first derivative: diffusive fluxes
-         DO jk = 1, jpkm1
+         zwu(:,:) = 0._wp
+         zwv(:,:) = 0._wp
+         DO jk = 1, jpkm1        ! a - first derivative: diffusive fluxes
             DO jj = 1, jpjm1
                DO ji = 1, fs_jpim1   ! vector opt.
@@ -374,6 +375,5 @@
             END DO
          END DO
-         ! b - correction for last oceanic u-v points
-         DO jj = 1, jpj
+         DO jj = 1, jpj          ! b - correction for last oceanic u-v points
             DO ji = 1, jpi
                un_td(ji,jj,mbku(ji,jj)) = un_td(ji,jj,mbku(ji,jj)) - zwu(ji,jj)
@@ -381,6 +381,5 @@
             END DO
          END DO
-         ! c - second derivative: divergence of diffusive fluxes
-         DO jk = 1, jpkm1
+         DO jk = 1, jpkm1        ! c - second derivative: divergence of diffusive fluxes
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -391,6 +390,6 @@
             END DO
          END DO
-         ! d - thickness diffusion transport: boundary conditions
-         !     (stored for tracer advction and continuity equation)
+         !                       ! d - thickness diffusion transport: boundary conditions
+         !                             (stored for tracer advction and continuity equation)
          CALL lbc_lnk( un_td , 'U' , -1._wp)
          CALL lbc_lnk( vn_td , 'V' , -1._wp)
@@ -410,5 +409,5 @@
          ! Maximum deformation control
          ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         ze3t(:,:,jpk) = 0.0_wp
+         ze3t(:,:,jpk) = 0._wp
          DO jk = 1, jpkm1
             ze3t(:,:,jk) = tilde_e3t_a(:,:,jk) / e3t_0(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:)
@@ -419,5 +418,5 @@
          IF( lk_mpp )   CALL mpp_min( z_tmin )                 ! min over the global domain
          ! - ML - test: for the moment, stop simulation for too large e3_t variations
-         IF( ( z_tmax .GT. rn_zdef_max ) .OR. ( z_tmin .LT. - rn_zdef_max ) ) THEN
+         IF( ( z_tmax >  rn_zdef_max ) .OR. ( z_tmin < - rn_zdef_max ) ) THEN
             IF( lk_mpp ) THEN
                CALL mpp_maxloc( ze3t, tmask, z_tmax, ijk_max(1), ijk_max(2), ijk_max(3) )
@@ -462,5 +461,5 @@
          z_scale(:,:) =  - zht(:,:) / ( ht_0(:,:) + sshn(:,:) + 1. - ssmask(:,:) )
          DO jk = 1, jpkm1
-            dtilde_e3t_a(:,:,jk) = dtilde_e3t_a(:,:,jk) + fse3t_n(:,:,jk) * z_scale(:,:) * tmask(:,:,jk)
+            dtilde_e3t_a(:,:,jk) = dtilde_e3t_a(:,:,jk) + e3t_n(:,:,jk) * z_scale(:,:) * tmask(:,:,jk)
          END DO
 
@@ -470,5 +469,5 @@
       !                                           ! ---baroclinic part--------- !
          DO jk = 1, jpkm1
-            fse3t_a(:,:,jk) = fse3t_a(:,:,jk) + dtilde_e3t_a(:,:,jk) * tmask(:,:,jk)
+            e3t_a(:,:,jk) = e3t_a(:,:,jk) + dtilde_e3t_a(:,:,jk) * tmask(:,:,jk)
          END DO
       ENDIF
@@ -485,25 +484,25 @@
          zht(:,:) = 0.0_wp
          DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + fse3t_n(:,:,jk) * tmask(:,:,jk)
+            zht(:,:) = zht(:,:) + e3t_n(:,:,jk) * tmask(:,:,jk)
          END DO
          z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + sshn(:,:) - zht(:,:) ) )
          IF( lk_mpp ) CALL mpp_max( z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshn-SUM(fse3t_n))) =', z_tmax
+         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshn-SUM(e3t_n))) =', z_tmax
          !
          zht(:,:) = 0.0_wp
          DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + fse3t_a(:,:,jk) * tmask(:,:,jk)
+            zht(:,:) = zht(:,:) + e3t_a(:,:,jk) * tmask(:,:,jk)
          END DO
          z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssha(:,:) - zht(:,:) ) )
          IF( lk_mpp ) CALL mpp_max( z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+ssha-SUM(fse3t_a))) =', z_tmax
+         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+ssha-SUM(e3t_a))) =', z_tmax
          !
          zht(:,:) = 0.0_wp
          DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + fse3t_b(:,:,jk) * tmask(:,:,jk)
+            zht(:,:) = zht(:,:) + e3t_b(:,:,jk) * tmask(:,:,jk)
          END DO
          z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + sshb(:,:) - zht(:,:) ) )
          IF( lk_mpp ) CALL mpp_max( z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshb-SUM(fse3t_b))) =', z_tmax
+         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshb-SUM(e3t_b))) =', z_tmax
          !
          z_tmax = MAXVAL( tmask(:,:,1) *  ABS( sshb(:,:) ) )
@@ -524,6 +523,6 @@
       ! *********************************** !
 
-      CALL dom_vvl_interpol( fse3t_a(:,:,:), fse3u_a(:,:,:), 'U' )
-      CALL dom_vvl_interpol( fse3t_a(:,:,:), fse3v_a(:,:,:), 'V' )
+      CALL dom_vvl_interpol( e3t_a(:,:,:), e3u_a(:,:,:), 'U' )
+      CALL dom_vvl_interpol( e3t_a(:,:,:), e3v_a(:,:,:), 'V' )
 
       ! *********************************** !
@@ -531,19 +530,20 @@
       ! *********************************** !
 
-      hu_a(:,:) = 0._wp                        ! Ocean depth at U-points
-      hv_a(:,:) = 0._wp                        ! Ocean depth at V-points
-      DO jk = 1, jpkm1
-         hu_a(:,:) = hu_a(:,:) + fse3u_a(:,:,jk) * umask(:,:,jk)
-         hv_a(:,:) = hv_a(:,:) + fse3v_a(:,:,jk) * vmask(:,:,jk)
+      hu_a(:,:) = e3u_a(:,:,1) * umask(:,:,1)
+      hv_a(:,:) = e3v_a(:,:,1) * vmask(:,:,1)
+      DO jk = 2, jpkm1
+         hu_a(:,:) = hu_a(:,:) + e3u_a(:,:,jk) * umask(:,:,jk)
+         hv_a(:,:) = hv_a(:,:) + e3v_a(:,:,jk) * vmask(:,:,jk)
       END DO
       !                                        ! Inverse of the local depth
-      hur_a(:,:) = 1._wp / ( hu_a(:,:) + 1._wp - umask_i(:,:) ) * umask_i(:,:)
-      hvr_a(:,:) = 1._wp / ( hv_a(:,:) + 1._wp - vmask_i(:,:) ) * vmask_i(:,:)
-
-      CALL wrk_dealloc( jpi, jpj, zht, z_scale, zwu, zwv, zhdiv )
-      CALL wrk_dealloc( jpi, jpj, jpk, ze3t                     )
-
+!!gm BUG ?  don't understand the use of umask_i here .....
+      r1_hu_a(:,:) = ssumask(:,:) / ( hu_a(:,:) + 1._wp - ssumask(:,:) )
+      r1_hv_a(:,:) = ssvmask(:,:) / ( hv_a(:,:) + 1._wp - ssvmask(:,:) )
+      !
+      CALL wrk_dealloc( jpi,jpj,       zht, z_scale, zwu, zwv, zhdiv )
+      CALL wrk_dealloc( jpi,jpj,jpk,   ze3t )
+      !
       IF( nn_timing == 1 )  CALL timing_stop('dom_vvl_sf_nxt')
-
+      !
    END SUBROUTINE dom_vvl_sf_nxt
 
@@ -561,11 +561,11 @@
       !!               - recompute depths and water height fields
       !!
-      !! ** Action  :  - fse3t_(b/n), tilde_e3t_(b/n) and fse3(u/v)_n ready for next time step
+      !! ** Action  :  - e3t_(b/n), tilde_e3t_(b/n) and e3(u/v)_n ready for next time step
       !!               - Recompute:
-      !!                    fse3(u/v)_b       
-      !!                    fse3w_n           
-      !!                    fse3(u/v)w_b      
-      !!                    fse3(u/v)w_n      
-      !!                    fsdept_n, fsdepw_n  and fsde3w_n
+      !!                    e3(u/v)_b       
+      !!                    e3w_n           
+      !!                    e3(u/v)w_b      
+      !!                    e3(u/v)w_n      
+      !!                    gdept_n, gdepw_n  and gde3w_n
       !!                    h(u/v) and h(u/v)r
       !!
@@ -573,11 +573,12 @@
       !!              Leclair, M., and G. Madec, 2011, Ocean Modelling.
       !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in )               :: kt       ! time step
-      !! * Local declarations
-      INTEGER                             :: ji,jj,jk       ! dummy loop indices
-      REAL(wp)                            :: zcoef
-      !!----------------------------------------------------------------------
-
+      INTEGER, INTENT( in ) ::   kt   ! time step
+      !
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zcoef        ! local scalar
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
+      !
       IF( nn_timing == 1 )  CALL timing_start('dom_vvl_sf_swp')
       !
@@ -590,5 +591,5 @@
       ! Time filter and swap of scale factors
       ! =====================================
-      ! - ML - fse3(t/u/v)_b are allready computed in dynnxt.
+      ! - ML - e3(t/u/v)_b are allready computed in dynnxt.
       IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
          IF( neuler == 0 .AND. kt == nit000 ) THEN
@@ -600,10 +601,10 @@
          tilde_e3t_n(:,:,:) = tilde_e3t_a(:,:,:)
       ENDIF
-      fsdept_b(:,:,:) = fsdept_n(:,:,:)
-      fsdepw_b(:,:,:) = fsdepw_n(:,:,:)
-
-      fse3t_n(:,:,:) = fse3t_a(:,:,:)
-      fse3u_n(:,:,:) = fse3u_a(:,:,:)
-      fse3v_n(:,:,:) = fse3v_a(:,:,:)
+      gdept_b(:,:,:) = gdept_n(:,:,:)
+      gdepw_b(:,:,:) = gdepw_n(:,:,:)
+
+      e3t_n(:,:,:) = e3t_a(:,:,:)
+      e3u_n(:,:,:) = e3u_a(:,:,:)
+      e3v_n(:,:,:) = e3v_a(:,:,:)
 
       ! Compute all missing vertical scale factor and depths
@@ -611,22 +612,21 @@
       ! Horizontal scale factor interpolations
       ! --------------------------------------
-      ! - ML - fse3u_b and fse3v_b are allready computed in dynnxt
+      ! - ML - e3u_b and e3v_b are allready computed in dynnxt
       ! - JC - hu_b, hv_b, hur_b, hvr_b also
-      CALL dom_vvl_interpol( fse3u_n(:,:,:), fse3f_n (:,:,:), 'F'  )
+      
+      CALL dom_vvl_interpol( e3u_n(:,:,:), e3f_n(:,:,:), 'F'  )
+      
       ! Vertical scale factor interpolations
-      ! ------------------------------------
-      CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3w_n (:,:,:), 'W'  )
-      CALL dom_vvl_interpol( fse3u_n(:,:,:), fse3uw_n(:,:,:), 'UW' )
-      CALL dom_vvl_interpol( fse3v_n(:,:,:), fse3vw_n(:,:,:), 'VW' )
-      CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3w_b (:,:,:), 'W'  )
-      CALL dom_vvl_interpol( fse3u_b(:,:,:), fse3uw_b(:,:,:), 'UW' )
-      CALL dom_vvl_interpol( fse3v_b(:,:,:), fse3vw_b(:,:,:), 'VW' )
-      ! t- and w- points depth
-      ! ----------------------
-      ! set the isf depth as it is in the initial step
-      fsdept_n(:,:,1) = 0.5_wp * fse3w_n(:,:,1)
-      fsdepw_n(:,:,1) = 0.0_wp
-      fsde3w_n(:,:,1) = fsdept_n(:,:,1) - sshn(:,:)
-
+      CALL dom_vvl_interpol( e3t_n(:,:,:),  e3w_n(:,:,:), 'W'  )
+      CALL dom_vvl_interpol( e3u_n(:,:,:), e3uw_n(:,:,:), 'UW' )
+      CALL dom_vvl_interpol( e3v_n(:,:,:), e3vw_n(:,:,:), 'VW' )
+      CALL dom_vvl_interpol( e3t_b(:,:,:),  e3w_b(:,:,:), 'W'  )
+      CALL dom_vvl_interpol( e3u_b(:,:,:), e3uw_b(:,:,:), 'UW' )
+      CALL dom_vvl_interpol( e3v_b(:,:,:), e3vw_b(:,:,:), 'VW' )
+
+      ! t- and w- points depth (set the isf depth as it is in the initial step)
+      gdept_n(:,:,1) = 0.5_wp * e3w_n(:,:,1)
+      gdepw_n(:,:,1) = 0.0_wp
+      gde3w_n(:,:,1) = gdept_n(:,:,1) - sshn(:,:)
       DO jk = 2, jpk
          DO jj = 1,jpj
@@ -635,44 +635,38 @@
                                                                  ! 1 for jk = mikt
                zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))
-               fsdepw_n(ji,jj,jk) = fsdepw_n(ji,jj,jk-1) + fse3t_n(ji,jj,jk-1)
-               fsdept_n(ji,jj,jk) =      zcoef  * ( fsdepw_n(ji,jj,jk  ) + 0.5 * fse3w_n(ji,jj,jk))  &
-                   &                + (1-zcoef) * ( fsdept_n(ji,jj,jk-1) +       fse3w_n(ji,jj,jk)) 
-               fsde3w_n(ji,jj,jk) = fsdept_n(ji,jj,jk) - sshn(ji,jj)
+               gdepw_n(ji,jj,jk) = gdepw_n(ji,jj,jk-1) + e3t_n(ji,jj,jk-1)
+               gdept_n(ji,jj,jk) =    zcoef  * ( gdepw_n(ji,jj,jk  ) + 0.5 * e3w_n(ji,jj,jk) )  &
+                   &             + (1-zcoef) * ( gdept_n(ji,jj,jk-1) +       e3w_n(ji,jj,jk) ) 
+               gde3w_n(ji,jj,jk) = gdept_n(ji,jj,jk) - sshn(ji,jj)
             END DO
          END DO
       END DO
 
-      ! Local depth and Inverse of the local depth of the water column at u- and v- points
-      ! ----------------------------------------------------------------------------------
-      hu (:,:) = hu_a (:,:)
-      hv (:,:) = hv_a (:,:)
-
-      ! Inverse of the local depth
-      hur(:,:) = hur_a(:,:)
-      hvr(:,:) = hvr_a(:,:)
-
-      ! Local depth of the water column at t- points
-      ! --------------------------------------------
-      ht(:,:) = 0.
-      DO jk = 1, jpkm1
-         ht(:,:) = ht(:,:) + fse3t_n(:,:,jk) * tmask(:,:,jk)
+      ! Local depth and Inverse of the local depth of the water
+      ! -------------------------------------------------------
+      hu_n(:,:) = hu_a(:,:)   ;   r1_hu_n(:,:) = r1_hu_a(:,:)
+      hv_n(:,:) = hv_a(:,:)   ;   r1_hv_n(:,:) = r1_hv_a(:,:)
+      !
+      ht_n(:,:) = e3t_n(:,:,1) * tmask(:,:,1)
+      DO jk = 2, jpkm1
+         ht_n(:,:) = ht_n(:,:) + e3t_n(:,:,jk) * tmask(:,:,jk)
       END DO
 
       ! Write outputs
       ! =============
-      CALL iom_put(     "e3t" , fse3t_n  (:,:,:) )
-      CALL iom_put(     "e3u" , fse3u_n  (:,:,:) )
-      CALL iom_put(     "e3v" , fse3v_n  (:,:,:) )
-      CALL iom_put(     "e3w" , fse3w_n  (:,:,:) )
-      CALL iom_put( "tpt_dep" , fsde3w_n (:,:,:) )
+      CALL iom_put(     "e3t",   e3t_n(:,:,:) )
+      CALL iom_put(     "e3u",   e3u_n(:,:,:) )
+      CALL iom_put(     "e3v",   e3v_n(:,:,:) )
+      CALL iom_put(     "e3w",   e3w_n(:,:,:) )
+      CALL iom_put( "tpt_dep", gde3w_n(:,:,:) )
       IF( iom_use("e3tdef") )   &
-         CALL iom_put( "e3tdef"  , ( ( fse3t_n(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2 )
+         CALL iom_put( "e3tdef", ( ( e3t_n(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100. * tmask(:,:,:) ) ** 2 )
 
       ! write restart file
       ! ==================
-      IF( lrst_oce ) CALL dom_vvl_rst( kt, 'WRITE' )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dom_vvl_sf_swp')
-
+      IF( lrst_oce )   CALL dom_vvl_rst( kt, 'WRITE' )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('dom_vvl_sf_swp')
+      !
    END SUBROUTINE dom_vvl_sf_swp
 
@@ -696,5 +690,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dom_vvl_interpol')
+      IF( nn_timing == 1 )   CALL timing_start('dom_vvl_interpol')
       !
       SELECT CASE ( pout )    !==  type of interpolation  ==!
@@ -770,5 +764,5 @@
       END SELECT
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dom_vvl_interpol')
+      IF( nn_timing == 1 )   CALL timing_stop('dom_vvl_interpol')
       !
    END SUBROUTINE dom_vvl_interpol
@@ -801,6 +795,6 @@
             CALL iom_get( numror, jpdom_autoglo, 'sshn'   , sshn    )
             !
-            id1 = iom_varid( numror, 'fse3t_b', ldstop = .FALSE. )
-            id2 = iom_varid( numror, 'fse3t_n', ldstop = .FALSE. )
+            id1 = iom_varid( numror, 'e3t_b', ldstop = .FALSE. )
+            id2 = iom_varid( numror, 'e3t_n', ldstop = .FALSE. )
             id3 = iom_varid( numror, 'tilde_e3t_b', ldstop = .FALSE. )
             id4 = iom_varid( numror, 'tilde_e3t_n', ldstop = .FALSE. )
@@ -810,39 +804,39 @@
             !                             ! --------- !
             IF( MIN( id1, id2 ) > 0 ) THEN       ! all required arrays exist
-               CALL iom_get( numror, jpdom_autoglo, 'fse3t_b', fse3t_b(:,:,:) )
-               CALL iom_get( numror, jpdom_autoglo, 'fse3t_n', fse3t_n(:,:,:) )
+               CALL iom_get( numror, jpdom_autoglo, 'e3t_b', e3t_b(:,:,:) )
+               CALL iom_get( numror, jpdom_autoglo, 'e3t_n', e3t_n(:,:,:) )
                ! needed to restart if land processor not computed 
-               IF(lwp) write(numout,*) 'dom_vvl_rst : fse3t_b and fse3t_n found in restart files'
+               IF(lwp) write(numout,*) 'dom_vvl_rst : e3t_b and e3t_n found in restart files'
                WHERE ( tmask(:,:,:) == 0.0_wp ) 
-                  fse3t_n(:,:,:) = e3t_0(:,:,:)
-                  fse3t_b(:,:,:) = e3t_0(:,:,:)
+                  e3t_n(:,:,:) = e3t_0(:,:,:)
+                  e3t_b(:,:,:) = e3t_0(:,:,:)
                END WHERE
                IF( neuler == 0 ) THEN
-                  fse3t_b(:,:,:) = fse3t_n(:,:,:)
+                  e3t_b(:,:,:) = e3t_n(:,:,:)
                ENDIF
             ELSE IF( id1 > 0 ) THEN
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : fse3t_n not found in restart files'
-               IF(lwp) write(numout,*) 'fse3t_n set equal to fse3t_b.'
+               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t_n not found in restart files'
+               IF(lwp) write(numout,*) 'e3t_n set equal to e3t_b.'
                IF(lwp) write(numout,*) 'neuler is forced to 0'
-               CALL iom_get( numror, jpdom_autoglo, 'fse3t_b', fse3t_b(:,:,:) )
-               fse3t_n(:,:,:) = fse3t_b(:,:,:)
+               CALL iom_get( numror, jpdom_autoglo, 'e3t_b', e3t_b(:,:,:) )
+               e3t_n(:,:,:) = e3t_b(:,:,:)
                neuler = 0
             ELSE IF( id2 > 0 ) THEN
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : fse3t_b not found in restart files'
-               IF(lwp) write(numout,*) 'fse3t_b set equal to fse3t_n.'
+               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t_b not found in restart files'
+               IF(lwp) write(numout,*) 'e3t_b set equal to e3t_n.'
                IF(lwp) write(numout,*) 'neuler is forced to 0'
-               CALL iom_get( numror, jpdom_autoglo, 'fse3t_n', fse3t_n(:,:,:) )
-               fse3t_b(:,:,:) = fse3t_n(:,:,:)
+               CALL iom_get( numror, jpdom_autoglo, 'e3t_n', e3t_n(:,:,:) )
+               e3t_b(:,:,:) = e3t_n(:,:,:)
                neuler = 0
             ELSE
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : fse3t_n not found in restart file'
+               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t_n not found in restart file'
                IF(lwp) write(numout,*) 'Compute scale factor from sshn'
                IF(lwp) write(numout,*) 'neuler is forced to 0'
-               DO jk=1,jpk
-                  fse3t_n(:,:,jk) =  e3t_0(:,:,jk) * ( ht_0(:,:) + sshn(:,:) ) &
-                      &                            / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk) &
-                      &            + e3t_0(:,:,jk) * (1._wp -tmask(:,:,jk))
+               DO jk = 1, jpk
+                  e3t_n(:,:,jk) =  e3t_0(:,:,jk) * ( ht_0(:,:) + sshn(:,:) ) &
+                      &                          / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
+                      &          + e3t_0(:,:,jk)                               * (1._wp -tmask(:,:,jk))
                END DO
-               fse3t_b(:,:,:) = fse3t_n(:,:,:)
+               e3t_b(:,:,:) = e3t_n(:,:,:)
                neuler = 0
             ENDIF
@@ -875,6 +869,6 @@
             !
          ELSE                                   !* Initialize at "rest"
-            fse3t_b(:,:,:) = e3t_0(:,:,:)
-            fse3t_n(:,:,:) = e3t_0(:,:,:)
+            e3t_b(:,:,:) = e3t_0(:,:,:)
+            e3t_n(:,:,:) = e3t_0(:,:,:)
             sshn(:,:) = 0.0_wp
             IF( ln_vvl_ztilde .OR. ln_vvl_layer) THEN
@@ -891,6 +885,6 @@
          !                                           ! all cases !
          !                                           ! --------- !
-         CALL iom_rstput( kt, nitrst, numrow, 'fse3t_b', fse3t_b(:,:,:) )
-         CALL iom_rstput( kt, nitrst, numrow, 'fse3t_n', fse3t_n(:,:,:) )
+         CALL iom_rstput( kt, nitrst, numrow, 'e3t_b', e3t_b(:,:,:) )
+         CALL iom_rstput( kt, nitrst, numrow, 'e3t_n', e3t_n(:,:,:) )
          !                                           ! ----------------------- !
          IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN  ! z_tilde and layer cases !
@@ -975,5 +969,5 @@
       !
       IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE vertical coordinate in namelist nam_vvl' )
-      IF( .NOT. ln_vvl_zstar .AND. nn_isf .NE. 0) CALL ctl_stop( 'Only vvl_zstar has been tested with ice shelf cavity' )
+      IF( .NOT. ln_vvl_zstar .AND. ln_isf ) CALL ctl_stop( 'Only vvl_zstar has been tested with ice shelf cavity' )
       !
       IF(lwp) THEN                   ! Print the choice
@@ -989,5 +983,5 @@
       !
 #if defined key_agrif
-      IF (.NOT.Agrif_Root()) CALL ctl_stop( 'AGRIF not implemented with non-linear free surface (key_vvl)' )
+      IF(.NOT.Agrif_Root() )   CALL ctl_stop( 'AGRIF not implemented with non-linear free surface' )
 #endif
       !
@@ -996,5 +990,2 @@
    !!======================================================================
 END MODULE domvvl
-
-
-
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 6140)
@@ -2,5 +2,5 @@
    !!==============================================================================
    !!                       ***  MODULE domzgr   ***
-   !! Ocean initialization : domain initialization
+   !! Ocean domain : definition of the vertical coordinate system
    !!==============================================================================
    !! History :  OPA  ! 1995-12  (G. Madec)  Original code : s vertical coordinate
@@ -38,4 +38,5 @@
    USE closea            ! closed seas
    USE c1d               ! 1D vertical configuration
+   !
    USE in_out_manager    ! I/O manager
    USE iom               ! I/O library
@@ -73,5 +74,4 @@
 
   !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -102,5 +102,5 @@
       INTEGER ::   ios
       !
-      NAMELIST/namzgr/ ln_zco, ln_zps, ln_sco, ln_isfcav
+      NAMELIST/namzgr/ ln_zco, ln_zps, ln_sco, ln_isfcav, ln_linssh
       !!----------------------------------------------------------------------
       !
@@ -120,10 +120,13 @@
          WRITE(numout,*) 'dom_zgr : vertical coordinate'
          WRITE(numout,*) '~~~~~~~'
-         WRITE(numout,*) '          Namelist namzgr : set vertical coordinate'
-         WRITE(numout,*) '             z-coordinate - full steps      ln_zco    = ', ln_zco
-         WRITE(numout,*) '             z-coordinate - partial steps   ln_zps    = ', ln_zps
-         WRITE(numout,*) '             s- or hybrid z-s-coordinate    ln_sco    = ', ln_sco
-         WRITE(numout,*) '             ice shelf cavities             ln_isfcav = ', ln_isfcav
+         WRITE(numout,*) '   Namelist namzgr : set vertical coordinate'
+         WRITE(numout,*) '      z-coordinate - full steps      ln_zco    = ', ln_zco
+         WRITE(numout,*) '      z-coordinate - partial steps   ln_zps    = ', ln_zps
+         WRITE(numout,*) '      s- or hybrid z-s-coordinate    ln_sco    = ', ln_sco
+         WRITE(numout,*) '      ice shelf cavities             ln_isfcav = ', ln_isfcav
+         WRITE(numout,*) '      linear free surface            ln_linssh = ', ln_linssh
       ENDIF
+
+      IF( ln_linssh .AND. lwp) WRITE(numout,*) '   linear free surface: the vertical mesh does not change in time'
 
       ioptio = 0                       ! Check Vertical coordinate options
@@ -155,18 +158,18 @@
       !
       IF( nprint == 1 .AND. lwp )   THEN
-         WRITE(numout,*) ' MIN val mbathy ', MINVAL( mbathy(:,:) ), ' MAX ', MAXVAL( mbathy(:,:) )
+         WRITE(numout,*) ' MIN val mbathy  ', MINVAL(  mbathy(:,:) ), ' MAX ', MAXVAL( mbathy(:,:) )
          WRITE(numout,*) ' MIN val depth t ', MINVAL( gdept_0(:,:,:) ),   &
-            &                   ' w ',   MINVAL( gdepw_0(:,:,:) ), '3w ', MINVAL( gdep3w_0(:,:,:) )
-         WRITE(numout,*) ' MIN val e3    t ', MINVAL( e3t_0(:,:,:) ), ' f ', MINVAL( e3f_0(:,:,:) ),  &
-            &                   ' u ',   MINVAL( e3u_0(:,:,:) ), ' u ', MINVAL( e3v_0(:,:,:) ),  &
-            &                   ' uw',   MINVAL( e3uw_0(:,:,:)), ' vw', MINVAL( e3vw_0(:,:,:)),   &
-            &                   ' w ',   MINVAL( e3w_0(:,:,:) )
+            &                          ' w ', MINVAL( gdepw_0(:,:,:) ), '3w ', MINVAL( gde3w_0(:,:,:) )
+         WRITE(numout,*) ' MIN val e3    t ', MINVAL(   e3t_0(:,:,:) ), ' f ', MINVAL(   e3f_0(:,:,:) ),  &
+            &                          ' u ', MINVAL(   e3u_0(:,:,:) ), ' u ', MINVAL(   e3v_0(:,:,:) ),  &
+            &                          ' uw', MINVAL(  e3uw_0(:,:,:) ), ' vw', MINVAL(  e3vw_0(:,:,:)),   &
+            &                          ' w ', MINVAL(   e3w_0(:,:,:) )
 
          WRITE(numout,*) ' MAX val depth t ', MAXVAL( gdept_0(:,:,:) ),   &
-            &                   ' w ',   MAXVAL( gdepw_0(:,:,:) ), '3w ', MAXVAL( gdep3w_0(:,:,:) )
-         WRITE(numout,*) ' MAX val e3    t ', MAXVAL( e3t_0(:,:,:) ), ' f ', MAXVAL( e3f_0(:,:,:) ),  &
-            &                   ' u ',   MAXVAL( e3u_0(:,:,:) ), ' u ', MAXVAL( e3v_0(:,:,:) ),  &
-            &                   ' uw',   MAXVAL( e3uw_0(:,:,:)), ' vw', MAXVAL( e3vw_0(:,:,:)),   &
-            &                   ' w ',   MAXVAL( e3w_0(:,:,:) )
+            &                          ' w ', MAXVAL( gdepw_0(:,:,:) ), '3w ', MAXVAL( gde3w_0(:,:,:) )
+         WRITE(numout,*) ' MAX val e3    t ', MAXVAL(   e3t_0(:,:,:) ), ' f ', MAXVAL(   e3f_0(:,:,:) ),  &
+            &                          ' u ', MAXVAL(   e3u_0(:,:,:) ), ' u ', MAXVAL(   e3v_0(:,:,:) ),  &
+            &                          ' uw', MAXVAL(  e3uw_0(:,:,:) ), ' vw', MAXVAL(  e3vw_0(:,:,:) ),  &
+            &                          ' w ', MAXVAL(   e3w_0(:,:,:) )
       ENDIF
       !
@@ -379,5 +382,5 @@
       !!              - bathy : meter bathymetry (in meters)
       !!----------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jl, jk            ! dummy loop indices
+      INTEGER  ::   ji, jj, jk            ! dummy loop indices
       INTEGER  ::   inum                      ! temporary logical unit
       INTEGER  ::   ierror                    ! error flag
@@ -541,4 +544,11 @@
                CALL iom_close( inum )
                WHERE( bathy(:,:) <= 0._wp )  risfdep(:,:) = 0._wp
+
+               ! set grounded point to 0 
+               ! (a treshold could be set here if needed, or set it offline based on the grounded fraction)
+               WHERE ( bathy(:,:) <= risfdep(:,:) + rn_isfhmin )
+                  misfdep(:,:) = 0 ; risfdep(:,:) = 0._wp
+                  mbathy (:,:) = 0 ; bathy  (:,:) = 0._wp
+               END WHERE
             END IF
             !       
@@ -578,11 +588,4 @@
       !                       
       IF ( .not. ln_sco ) THEN                                !==  set a minimum depth  ==!
-         ! patch to avoid case bathy = ice shelf draft and bathy between 0 and zhmin
-         IF ( ln_isfcav ) THEN
-            WHERE (bathy == risfdep)
-               bathy   = 0.0_wp ; risfdep = 0.0_wp
-            END WHERE
-         END IF
-         ! end patch
          IF( rn_hmin < 0._wp ) THEN    ;   ik = - INT( rn_hmin )                                      ! from a nb of level
          ELSE                          ;   ik = MINLOC( gdepw_1d, mask = gdepw_1d > rn_hmin, dim = 1 )  ! from a depth
@@ -674,9 +677,7 @@
       !!              - update bathy : meter bathymetry (in meters)
       !!----------------------------------------------------------------------
-      !!
       INTEGER ::   ji, jj, jl                    ! dummy loop indices
       INTEGER ::   icompt, ibtest, ikmax         ! temporary integers
       REAL(wp), POINTER, DIMENSION(:,:) ::  zbathy
-
       !!----------------------------------------------------------------------
       !
@@ -775,12 +776,4 @@
          IF(lwp) WRITE(numout,*) ' you can decrease jpk to ', ikmax+1
       ENDIF
-
-      IF( lwp .AND. nprint == 1 ) THEN      ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) ' bathymetric field :   number of non-zero T-levels '
-         WRITE(numout,*) ' ------------------'
-         CALL prihin( mbathy, jpi, jpj, 1, jpi, 1, 1, jpj, 1, 3, numout )
-         WRITE(numout,*)
-      ENDIF
       !
       CALL wrk_dealloc( jpi, jpj, zbathy )
@@ -803,5 +796,4 @@
       !!                                     (min value = 1 over land)
       !!----------------------------------------------------------------------
-      !!
       INTEGER ::   ji, jj   ! dummy loop indices
       REAL(wp), POINTER, DIMENSION(:,:) ::  zmbk
@@ -835,7 +827,8 @@
    END SUBROUTINE zgr_bot_level
 
-      SUBROUTINE zgr_top_level
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE zgr_bot_level  ***
+
+   SUBROUTINE zgr_top_level
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE zgr_top_level  ***
       !!
       !! ** Purpose :   defines the vertical index of ocean top (mik. arrays)
@@ -847,5 +840,4 @@
       !!                                     (min value = 1)
       !!----------------------------------------------------------------------
-      !!
       INTEGER ::   ji, jj   ! dummy loop indices
       REAL(wp), POINTER, DIMENSION(:,:) ::  zmik
@@ -881,9 +873,10 @@
    END SUBROUTINE zgr_top_level
 
+
    SUBROUTINE zgr_zco
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE zgr_zco  ***
       !!
-      !! ** Purpose :   define the z-coordinate system
+      !! ** Purpose :   define the reference z-coordinate system
       !!
       !! ** Method  :   set 3D coord. arrays to reference 1D array 
@@ -895,14 +888,14 @@
       !
       DO jk = 1, jpk
-         gdept_0 (:,:,jk) = gdept_1d(jk)
-         gdepw_0 (:,:,jk) = gdepw_1d(jk)
-         gdep3w_0(:,:,jk) = gdepw_1d(jk)
-         e3t_0   (:,:,jk) = e3t_1d  (jk)
-         e3u_0   (:,:,jk) = e3t_1d  (jk)
-         e3v_0   (:,:,jk) = e3t_1d  (jk)
-         e3f_0   (:,:,jk) = e3t_1d  (jk)
-         e3w_0   (:,:,jk) = e3w_1d  (jk)
-         e3uw_0  (:,:,jk) = e3w_1d  (jk)
-         e3vw_0  (:,:,jk) = e3w_1d  (jk)
+         gdept_0(:,:,jk) = gdept_1d(jk)
+         gdepw_0(:,:,jk) = gdepw_1d(jk)
+         gde3w_0(:,:,jk) = gdepw_1d(jk)
+         e3t_0  (:,:,jk) = e3t_1d  (jk)
+         e3u_0  (:,:,jk) = e3t_1d  (jk)
+         e3v_0  (:,:,jk) = e3t_1d  (jk)
+         e3f_0  (:,:,jk) = e3t_1d  (jk)
+         e3w_0  (:,:,jk) = e3w_1d  (jk)
+         e3uw_0 (:,:,jk) = e3w_1d  (jk)
+         e3vw_0 (:,:,jk) = e3w_1d  (jk)
       END DO
       !
@@ -917,5 +910,5 @@
       !!                     
       !! ** Purpose :   the depth and vertical scale factor in partial step
-      !!      z-coordinate case
+      !!              reference z-coordinate case
       !!
       !! ** Method  :   Partial steps : computes the 3D vertical scale factors
@@ -957,13 +950,10 @@
       !!  Reference :   Pacanowsky & Gnanadesikan 1997, Mon. Wea. Rev., 126, 3248-3270.
       !!----------------------------------------------------------------------
-      !!
       INTEGER  ::   ji, jj, jk       ! dummy loop indices
       INTEGER  ::   ik, it, ikb, ikt ! temporary integers
-      LOGICAL  ::   ll_print         ! Allow  control print for debugging
       REAL(wp) ::   ze3tp , ze3wp    ! Last ocean level thickness at T- and W-points
       REAL(wp) ::   zdepwp, zdepth   ! Ajusted ocean depth to avoid too small e3t
-      REAL(wp) ::   zmax             ! Maximum depth
       REAL(wp) ::   zdiff            ! temporary scalar
-      REAL(wp) ::   zrefdep          ! temporary scalar
+      REAL(wp) ::   zmax             ! temporary scalar
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  zprt
       !!---------------------------------------------------------------------
@@ -971,5 +961,5 @@
       IF( nn_timing == 1 )  CALL timing_start('zgr_zps')
       !
-      CALL wrk_alloc( jpi, jpj, jpk, zprt )
+      CALL wrk_alloc( jpi,jpj,jpk,   zprt )
       !
       IF(lwp) WRITE(numout,*)
@@ -977,13 +967,4 @@
       IF(lwp) WRITE(numout,*) '    ~~~~~~~ '
       IF(lwp) WRITE(numout,*) '              mbathy is recomputed : bathy_level file is NOT used'
-
-      ll_print = .FALSE.                   ! Local variable for debugging
-      
-      IF(lwp .AND. ll_print) THEN          ! control print of the ocean depth
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_zgr_zps:  bathy (in hundred of meters)'
-         CALL prihre( bathy, jpi, jpj, 1,jpi, 1, 1, jpj, 1, 1.e-2, numout )
-      ENDIF
-
 
       ! bathymetry in level (from bathy_meter)
@@ -1004,6 +985,4 @@
       END DO
 
-      IF ( ln_isfcav ) CALL zgr_isf
-
       ! Scale factors and depth at T- and W-points
       DO jk = 1, jpk                        ! intitialization to the reference z-coordinate
@@ -1013,5 +992,736 @@
          e3w_0  (:,:,jk) = e3w_1d  (jk)
       END DO
+      
+      ! Bathy, iceshelf draft, scale factor and depth at T- and W- points in case of isf
+      IF ( ln_isfcav ) CALL zgr_isf
+
+      ! Scale factors and depth at T- and W-points
+      IF ( .NOT. ln_isfcav ) THEN
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ik = mbathy(ji,jj)
+               IF( ik > 0 ) THEN               ! ocean point only
+                  ! max ocean level case
+                  IF( ik == jpkm1 ) THEN
+                     zdepwp = bathy(ji,jj)
+                     ze3tp  = bathy(ji,jj) - gdepw_1d(ik)
+                     ze3wp = 0.5_wp * e3w_1d(ik) * ( 1._wp + ( ze3tp/e3t_1d(ik) ) )
+                     e3t_0(ji,jj,ik  ) = ze3tp
+                     e3t_0(ji,jj,ik+1) = ze3tp
+                     e3w_0(ji,jj,ik  ) = ze3wp
+                     e3w_0(ji,jj,ik+1) = ze3tp
+                     gdepw_0(ji,jj,ik+1) = zdepwp
+                     gdept_0(ji,jj,ik  ) = gdept_1d(ik-1) + ze3wp
+                     gdept_0(ji,jj,ik+1) = gdept_0(ji,jj,ik) + ze3tp
+                     !
+                  ELSE                         ! standard case
+                     IF( bathy(ji,jj) <= gdepw_1d(ik+1) ) THEN  ;   gdepw_0(ji,jj,ik+1) = bathy(ji,jj)
+                     ELSE                                       ;   gdepw_0(ji,jj,ik+1) = gdepw_1d(ik+1)
+                     ENDIF
+   !gm Bug?  check the gdepw_1d
+                     !       ... on ik
+                     gdept_0(ji,jj,ik) = gdepw_1d(ik) + ( gdepw_0(ji,jj,ik+1) - gdepw_1d(ik) )   &
+                        &                             * ((gdept_1d(     ik  ) - gdepw_1d(ik) )   &
+                        &                             / ( gdepw_1d(     ik+1) - gdepw_1d(ik) ))
+                     e3t_0  (ji,jj,ik) = e3t_1d  (ik) * ( gdepw_0 (ji,jj,ik+1) - gdepw_1d(ik) )   & 
+                        &                             / ( gdepw_1d(      ik+1) - gdepw_1d(ik) ) 
+                     e3w_0(ji,jj,ik) = 0.5_wp * ( gdepw_0(ji,jj,ik+1) + gdepw_1d(ik+1) - 2._wp * gdepw_1d(ik) )   &
+                        &                     * ( e3w_1d(ik) / ( gdepw_1d(ik+1) - gdepw_1d(ik) ) )
+                     !       ... on ik+1
+                     e3w_0  (ji,jj,ik+1) = e3t_0  (ji,jj,ik)
+                     e3t_0  (ji,jj,ik+1) = e3t_0  (ji,jj,ik)
+                     gdept_0(ji,jj,ik+1) = gdept_0(ji,jj,ik) + e3t_0(ji,jj,ik)
+                  ENDIF
+               ENDIF
+            END DO
+         END DO
+         !
+         it = 0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ik = mbathy(ji,jj)
+               IF( ik > 0 ) THEN               ! ocean point only
+                  e3tp (ji,jj) = e3t_0(ji,jj,ik)
+                  e3wp (ji,jj) = e3w_0(ji,jj,ik)
+                  ! test
+                  zdiff= gdepw_0(ji,jj,ik+1) - gdept_0(ji,jj,ik  )
+                  IF( zdiff <= 0._wp .AND. lwp ) THEN 
+                     it = it + 1
+                     WRITE(numout,*) ' it      = ', it, ' ik      = ', ik, ' (i,j) = ', ji, jj
+                     WRITE(numout,*) ' bathy = ', bathy(ji,jj)
+                     WRITE(numout,*) ' gdept_0 = ', gdept_0(ji,jj,ik), ' gdepw_0 = ', gdepw_0(ji,jj,ik+1), ' zdiff = ', zdiff
+                     WRITE(numout,*) ' e3tp    = ', e3t_0  (ji,jj,ik), ' e3wp    = ', e3w_0  (ji,jj,ik  )
+                  ENDIF
+               ENDIF
+            END DO
+         END DO
+      END IF
+      !
+      ! Scale factors and depth at U-, V-, UW and VW-points
+      DO jk = 1, jpk                        ! initialisation to z-scale factors
+         e3u_0 (:,:,jk) = e3t_1d(jk)
+         e3v_0 (:,:,jk) = e3t_1d(jk)
+         e3uw_0(:,:,jk) = e3w_1d(jk)
+         e3vw_0(:,:,jk) = e3w_1d(jk)
+      END DO
+
+      DO jk = 1,jpk                         ! Computed as the minimum of neighbooring scale factors
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               e3u_0 (ji,jj,jk) = MIN( e3t_0(ji,jj,jk), e3t_0(ji+1,jj,jk) )
+               e3v_0 (ji,jj,jk) = MIN( e3t_0(ji,jj,jk), e3t_0(ji,jj+1,jk) )
+               e3uw_0(ji,jj,jk) = MIN( e3w_0(ji,jj,jk), e3w_0(ji+1,jj,jk) )
+               e3vw_0(ji,jj,jk) = MIN( e3w_0(ji,jj,jk), e3w_0(ji,jj+1,jk) )
+            END DO
+         END DO
+      END DO
+      IF ( ln_isfcav ) THEN
+      ! (ISF) define e3uw (adapted for 2 cells in the water column)
+         DO jj = 2, jpjm1 
+            DO ji = 2, fs_jpim1   ! vector opt. 
+               ikb = MAX(mbathy (ji,jj),mbathy (ji+1,jj))
+               ikt = MAX(misfdep(ji,jj),misfdep(ji+1,jj))
+               IF (ikb == ikt+1) e3uw_0(ji,jj,ikb) =  MIN( gdept_0(ji,jj,ikb  ), gdept_0(ji+1,jj  ,ikb  ) ) &
+                                       &            - MAX( gdept_0(ji,jj,ikb-1), gdept_0(ji+1,jj  ,ikb-1) )
+               ikb = MAX(mbathy (ji,jj),mbathy (ji,jj+1))
+               ikt = MAX(misfdep(ji,jj),misfdep(ji,jj+1))
+               IF (ikb == ikt+1) e3vw_0(ji,jj,ikb) =  MIN( gdept_0(ji,jj,ikb  ), gdept_0(ji  ,jj+1,ikb  ) ) &
+                                       &            - MAX( gdept_0(ji,jj,ikb-1), gdept_0(ji  ,jj+1,ikb-1) )
+            END DO
+         END DO
+      END IF
+
+      CALL lbc_lnk( e3u_0 , 'U', 1._wp )   ;   CALL lbc_lnk( e3uw_0, 'U', 1._wp )   ! lateral boundary conditions
+      CALL lbc_lnk( e3v_0 , 'V', 1._wp )   ;   CALL lbc_lnk( e3vw_0, 'V', 1._wp )
+      !
+
+      DO jk = 1, jpk                        ! set to z-scale factor if zero (i.e. along closed boundaries)
+         WHERE( e3u_0 (:,:,jk) == 0._wp )   e3u_0 (:,:,jk) = e3t_1d(jk)
+         WHERE( e3v_0 (:,:,jk) == 0._wp )   e3v_0 (:,:,jk) = e3t_1d(jk)
+         WHERE( e3uw_0(:,:,jk) == 0._wp )   e3uw_0(:,:,jk) = e3w_1d(jk)
+         WHERE( e3vw_0(:,:,jk) == 0._wp )   e3vw_0(:,:,jk) = e3w_1d(jk)
+      END DO
+      
+      ! Scale factor at F-point
+      DO jk = 1, jpk                        ! initialisation to z-scale factors
+         e3f_0(:,:,jk) = e3t_1d(jk)
+      END DO
+      DO jk = 1, jpk                        ! Computed as the minimum of neighbooring V-scale factors
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               e3f_0(ji,jj,jk) = MIN( e3v_0(ji,jj,jk), e3v_0(ji+1,jj,jk) )
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk( e3f_0, 'F', 1._wp )       ! Lateral boundary conditions
+      !
+      DO jk = 1, jpk                        ! set to z-scale factor if zero (i.e. along closed boundaries)
+         WHERE( e3f_0(:,:,jk) == 0._wp )   e3f_0(:,:,jk) = e3t_1d(jk)
+      END DO
+!!gm  bug ? :  must be a do loop with mj0,mj1
       ! 
+      e3t_0(:,mj0(1),:) = e3t_0(:,mj0(2),:)     ! we duplicate factor scales for jj = 1 and jj = 2
+      e3w_0(:,mj0(1),:) = e3w_0(:,mj0(2),:) 
+      e3u_0(:,mj0(1),:) = e3u_0(:,mj0(2),:) 
+      e3v_0(:,mj0(1),:) = e3v_0(:,mj0(2),:) 
+      e3f_0(:,mj0(1),:) = e3f_0(:,mj0(2),:) 
+
+      ! Control of the sign
+      IF( MINVAL( e3t_0  (:,:,:) ) <= 0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   e3t_0 <= 0' )
+      IF( MINVAL( e3w_0  (:,:,:) ) <= 0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   e3w_0 <= 0' )
+      IF( MINVAL( gdept_0(:,:,:) ) <  0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   gdept_0 <  0' )
+      IF( MINVAL( gdepw_0(:,:,:) ) <  0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   gdepw_0 <  0' )
+     
+      ! Compute gde3w_0 (vertical sum of e3w)
+      IF ( ln_isfcav ) THEN ! if cavity
+         WHERE( misfdep == 0 )   misfdep = 1
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+               gde3w_0(ji,jj,1) = 0.5_wp * e3w_0(ji,jj,1)
+               DO jk = 2, misfdep(ji,jj)
+                  gde3w_0(ji,jj,jk) = gde3w_0(ji,jj,jk-1) + e3w_0(ji,jj,jk) 
+               END DO
+               IF( misfdep(ji,jj) >= 2 )   gde3w_0(ji,jj,misfdep(ji,jj)) = risfdep(ji,jj) + 0.5_wp * e3w_0(ji,jj,misfdep(ji,jj))
+               DO jk = misfdep(ji,jj) + 1, jpk
+                  gde3w_0(ji,jj,jk) = gde3w_0(ji,jj,jk-1) + e3w_0(ji,jj,jk) 
+               END DO
+            END DO
+         END DO
+      ELSE ! no cavity
+         gde3w_0(:,:,1) = 0.5_wp * e3w_0(:,:,1)
+         DO jk = 2, jpk
+            gde3w_0(:,:,jk) = gde3w_0(:,:,jk-1) + e3w_0(:,:,jk)
+         END DO
+      END IF
+      !
+      CALL wrk_dealloc( jpi,jpj,jpk,   zprt )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('zgr_zps')
+      !
+   END SUBROUTINE zgr_zps
+
+
+   SUBROUTINE zgr_isf
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE zgr_isf  ***
+      !!   
+      !! ** Purpose :   check the bathymetry in levels
+      !!   
+      !! ** Method  :   THe water column have to contained at least 2 cells
+      !!                Bathymetry and isfdraft are modified (dig/close) to respect
+      !!                this criterion.
+      !!   
+      !! ** Action  : - test compatibility between isfdraft and bathy 
+      !!              - bathy and isfdraft are modified
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jl, jk       ! dummy loop indices
+      INTEGER  ::   ik, it               ! temporary integers
+      INTEGER  ::   icompt, ibtest       ! (ISF)
+      INTEGER  ::   ibtestim1, ibtestip1 ! (ISF)
+      INTEGER  ::   ibtestjm1, ibtestjp1 ! (ISF)
+      REAL(wp) ::   zdepth           ! Ajusted ocean depth to avoid too small e3t
+      REAL(wp) ::   zmax             ! Maximum and minimum depth
+      REAL(wp) ::   zbathydiff       ! isf temporary scalar
+      REAL(wp) ::   zrisfdepdiff     ! isf temporary scalar
+      REAL(wp) ::   ze3tp , ze3wp    ! Last ocean level thickness at T- and W-points
+      REAL(wp) ::   zdepwp           ! Ajusted ocean depth to avoid too small e3t
+      REAL(wp) ::   zdiff            ! temporary scalar
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   zrisfdep, zbathy, zmask   ! 2D workspace (ISH)
+      INTEGER , POINTER, DIMENSION(:,:)   ::   zmbathy, zmisfdep         ! 2D workspace (ISH)
+      !!---------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('zgr_isf')
+      !
+      CALL wrk_alloc( jpi,jpj,   zbathy, zmask, zrisfdep)
+      CALL wrk_alloc( jpi,jpj,   zmisfdep, zmbathy )
+
+      ! (ISF) compute misfdep
+      WHERE( risfdep(:,:) == 0._wp .AND. bathy(:,:) /= 0 ) ;   misfdep(:,:) = 1   ! open water : set misfdep to 1  
+      ELSEWHERE                      ;                         misfdep(:,:) = 2   ! iceshelf : initialize misfdep to second level 
+      END WHERE  
+
+      ! Compute misfdep for ocean points (i.e. first wet level) 
+      ! find the first ocean level such that the first level thickness 
+      ! is larger than the bot_level of e3zps_min and e3zps_rat * e3t_0 (where 
+      ! e3t_0 is the reference level thickness 
+      DO jk = 2, jpkm1 
+         zdepth = gdepw_1d(jk+1) - MIN( e3zps_min, e3t_1d(jk)*e3zps_rat ) 
+         WHERE( 0._wp < risfdep(:,:) .AND. risfdep(:,:) >= zdepth )   misfdep(:,:) = jk+1 
+      END DO 
+      WHERE ( 0._wp < risfdep(:,:) .AND. risfdep(:,:) <= e3t_1d(1) )
+         risfdep(:,:) = 0. ; misfdep(:,:) = 1
+      END WHERE
+
+      ! remove very shallow ice shelf (less than ~ 10m if 75L)
+      WHERE (risfdep(:,:) <= 10._wp .AND. misfdep(:,:) > 1)
+         misfdep = 0; risfdep = 0.0_wp;
+         mbathy  = 0; bathy   = 0.0_wp;
+      END WHERE
+      WHERE (bathy(:,:) <= 30.0_wp .AND. gphit < -60._wp)
+         misfdep = 0; risfdep = 0.0_wp;
+         mbathy  = 0; bathy   = 0.0_wp;
+      END WHERE
+ 
+! basic check for the compatibility of bathy and risfdep. I think it should be offline because it is not perfect and cannot solved all the situation
+      icompt = 0 
+! run the bathy check 10 times to be sure all the modif in the bathy or iceshelf draft are compatible together
+      DO jl = 1, 10     
+         ! check at each iteration if isf is grounded or not (1cm treshold have to be update after first coupling experiments)
+         WHERE (bathy(:,:) <= risfdep(:,:) + rn_isfhmin)
+            misfdep(:,:) = 0 ; risfdep(:,:) = 0._wp
+            mbathy (:,:) = 0 ; bathy  (:,:) = 0._wp
+         END WHERE
+         WHERE (mbathy(:,:) <= 0) 
+            misfdep(:,:) = 0; risfdep(:,:) = 0._wp 
+            mbathy (:,:) = 0; bathy  (:,:) = 0._wp
+         END WHERE
+         IF( lk_mpp ) THEN
+            zbathy(:,:)  = FLOAT( misfdep(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            misfdep(:,:) = INT( zbathy(:,:) )
+
+            CALL lbc_lnk( risfdep,'T', 1. )
+            CALL lbc_lnk( bathy,  'T', 1. )
+
+            zbathy(:,:)  = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            mbathy(:,:)  = INT( zbathy(:,:) )
+         ENDIF
+         IF( nperio == 1 .OR. nperio  ==  4 .OR. nperio  ==  6 ) THEN 
+            misfdep( 1 ,:) = misfdep(jpim1,:)            ! local domain is cyclic east-west 
+            misfdep(jpi,:) = misfdep(  2  ,:) 
+            mbathy( 1 ,:)  = mbathy(jpim1,:)             ! local domain is cyclic east-west
+            mbathy(jpi,:)  = mbathy(  2  ,:)
+         ENDIF
+
+         ! split last cell if possible (only where water column is 2 cell or less)
+         ! if coupled to ice sheet, we do not modify the bathymetry (can be discuss).
+         IF ( .NOT. ln_iscpl) THEN
+            DO jk = jpkm1, 1, -1
+               zmax = gdepw_1d(jk) + MIN( e3zps_min, e3t_1d(jk)*e3zps_rat )
+               WHERE( gdepw_1d(jk) < bathy(:,:) .AND. bathy(:,:) <= zmax .AND. misfdep + 1 >= mbathy)
+                  mbathy(:,:) = jk
+                  bathy(:,:)  = zmax
+               END WHERE
+            END DO
+         END IF
+ 
+         ! split top cell if possible (only where water column is 2 cell or less)
+         DO jk = 2, jpkm1
+            zmax = gdepw_1d(jk+1) - MIN( e3zps_min, e3t_1d(jk)*e3zps_rat )
+            WHERE( gdepw_1d(jk+1) > risfdep(:,:) .AND. risfdep(:,:) >= zmax .AND. misfdep + 1 >= mbathy)
+               misfdep(:,:) = jk
+               risfdep(:,:) = zmax
+            END WHERE
+         END DO
+
+ 
+ ! Case where bathy and risfdep compatible but not the level variable mbathy/misfdep because of partial cell condition
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ! find the minimum change option:
+               ! test bathy
+               IF (risfdep(ji,jj) > 1) THEN
+                  IF ( .NOT. ln_iscpl ) THEN
+                     zbathydiff  =ABS(bathy(ji,jj)   - (gdepw_1d(mbathy (ji,jj)+1) &
+                         &            + MIN( e3zps_min, e3t_1d(mbathy (ji,jj)+1)*e3zps_rat )))
+                     zrisfdepdiff=ABS(risfdep(ji,jj) - (gdepw_1d(misfdep(ji,jj)  ) &
+                         &            - MIN( e3zps_min, e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )))
+                     IF (bathy(ji,jj) > risfdep(ji,jj) .AND. mbathy(ji,jj) <  misfdep(ji,jj)) THEN
+                        IF (zbathydiff <= zrisfdepdiff) THEN
+                           bathy(ji,jj) = gdepw_1d(mbathy(ji,jj)) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj)+1)*e3zps_rat )
+                           mbathy(ji,jj)= mbathy(ji,jj) + 1
+                        ELSE
+                           risfdep(ji,jj) = gdepw_1d(misfdep(ji,jj)) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )
+                           misfdep(ji,jj) = misfdep(ji,jj) - 1
+                        END IF
+                     ENDIF
+                  ELSE
+                     IF (bathy(ji,jj) > risfdep(ji,jj) .AND. mbathy(ji,jj) <  misfdep(ji,jj)) THEN
+                        risfdep(ji,jj) = gdepw_1d(misfdep(ji,jj)) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )
+                        misfdep(ji,jj) = misfdep(ji,jj) - 1
+                     END IF
+                  END IF
+               END IF
+            END DO
+         END DO
+ 
+         ! At least 2 levels for water thickness at T, U, and V point.
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ! find the minimum change option:
+               ! test bathy
+               IF( misfdep(ji,jj) == mbathy(ji,jj) .AND. mbathy(ji,jj) > 1) THEN
+                  IF ( .NOT. ln_iscpl ) THEN 
+                     zbathydiff  =ABS(bathy(ji,jj)   - ( gdepw_1d(mbathy (ji,jj)+1) &
+                         &                             + MIN( e3zps_min,e3t_1d(mbathy (ji,jj)+1)*e3zps_rat )))
+                     zrisfdepdiff=ABS(risfdep(ji,jj) - ( gdepw_1d(misfdep(ji,jj)  ) & 
+                         &                             - MIN( e3zps_min,e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )))
+                     IF (zbathydiff <= zrisfdepdiff) THEN
+                        mbathy(ji,jj) = mbathy(ji,jj) + 1
+                        bathy(ji,jj)  = gdepw_1d(mbathy (ji,jj)) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj) +1)*e3zps_rat )
+                     ELSE
+                        misfdep(ji,jj)= misfdep(ji,jj) - 1
+                        risfdep(ji,jj) = gdepw_1d(misfdep(ji,jj)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj))*e3zps_rat )
+                     END IF
+                  ELSE
+                     misfdep(ji,jj)= misfdep(ji,jj) - 1
+                     risfdep(ji,jj)= gdepw_1d(misfdep(ji,jj)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj))*e3zps_rat )
+                  END IF
+               ENDIF
+            END DO
+         END DO
+ 
+ ! point V mbathy(ji,jj) == misfdep(ji,jj+1) 
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               IF( misfdep(ji,jj+1) == mbathy(ji,jj) .AND. mbathy(ji,jj) > 1) THEN
+                  IF ( .NOT. ln_iscpl ) THEN 
+                     zbathydiff  =ABS(bathy(ji,jj    ) - ( gdepw_1d(mbathy (ji,jj)+1) &
+                          &                              + MIN( e3zps_min, e3t_1d(mbathy (ji,jj  )+1)*e3zps_rat )))
+                     zrisfdepdiff=ABS(risfdep(ji,jj+1) - ( gdepw_1d(misfdep(ji,jj+1)) &
+                          &                              - MIN( e3zps_min, e3t_1d(misfdep(ji,jj+1)-1)*e3zps_rat )))
+                     IF (zbathydiff <= zrisfdepdiff) THEN
+                        mbathy(ji,jj) = mbathy(ji,jj) + 1
+                        bathy(ji,jj)  = gdepw_1d(mbathy (ji,jj  )) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj   )+1)*e3zps_rat )
+                     ELSE
+                        misfdep(ji,jj+1)  = misfdep(ji,jj+1) - 1
+                        risfdep (ji,jj+1) = gdepw_1d(misfdep(ji,jj+1)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj+1))*e3zps_rat )
+                     END IF
+                  ELSE
+                     misfdep(ji,jj+1)  = misfdep(ji,jj+1) - 1
+                     risfdep (ji,jj+1) = gdepw_1d(misfdep(ji,jj+1)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj+1))*e3zps_rat )
+                  END IF
+               ENDIF
+            END DO
+         END DO
+ 
+         IF( lk_mpp ) THEN
+            zbathy(:,:)  = FLOAT( misfdep(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            misfdep(:,:) = INT( zbathy(:,:) )
+
+            CALL lbc_lnk( risfdep,'T', 1. )
+            CALL lbc_lnk( bathy,  'T', 1. )
+
+            zbathy(:,:)  = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            mbathy(:,:)  = INT( zbathy(:,:) )
+         ENDIF
+ ! point V misdep(ji,jj) == mbathy(ji,jj+1) 
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               IF( misfdep(ji,jj) == mbathy(ji,jj+1) .AND. mbathy(ji,jj) > 1) THEN
+                  IF ( .NOT. ln_iscpl ) THEN 
+                     zbathydiff  =ABS(  bathy(ji,jj+1) - ( gdepw_1d(mbathy (ji,jj+1)+1) &
+                           &                             + MIN( e3zps_min, e3t_1d(mbathy (ji,jj+1)+1)*e3zps_rat )))
+                     zrisfdepdiff=ABS(risfdep(ji,jj  ) - ( gdepw_1d(misfdep(ji,jj  )  ) &
+                           &                             - MIN( e3zps_min, e3t_1d(misfdep(ji,jj  )-1)*e3zps_rat )))
+                     IF (zbathydiff <= zrisfdepdiff) THEN
+                        mbathy (ji,jj+1) = mbathy(ji,jj+1) + 1
+                        bathy  (ji,jj+1) = gdepw_1d(mbathy (ji,jj+1)  ) + MIN( e3zps_min, e3t_1d(mbathy (ji,jj+1)+1)*e3zps_rat )
+                     ELSE
+                        misfdep(ji,jj)   = misfdep(ji,jj) - 1
+                        risfdep(ji,jj)   = gdepw_1d(misfdep(ji,jj  )+1) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj  )  )*e3zps_rat )
+                     END IF
+                  ELSE
+                     misfdep(ji,jj)   = misfdep(ji,jj) - 1
+                     risfdep(ji,jj)   = gdepw_1d(misfdep(ji,jj  )+1) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj  )  )*e3zps_rat )
+                  END IF
+               ENDIF
+            END DO
+         END DO
+ 
+ 
+         IF( lk_mpp ) THEN 
+            zbathy(:,:)  = FLOAT( misfdep(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            misfdep(:,:) = INT( zbathy(:,:) )
+
+            CALL lbc_lnk( risfdep,'T', 1. )
+            CALL lbc_lnk( bathy,  'T', 1. )
+
+            zbathy(:,:)  = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            mbathy(:,:)  = INT( zbathy(:,:) )
+         ENDIF 
+ 
+ ! point U mbathy(ji,jj) == misfdep(ji,jj+1) 
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               IF( misfdep(ji+1,jj) == mbathy(ji,jj) .AND. mbathy(ji,jj) > 1) THEN
+                  IF ( .NOT. ln_iscpl ) THEN 
+                  zbathydiff  =ABS(  bathy(ji  ,jj) - ( gdepw_1d(mbathy (ji,jj)+1) &
+                       &                              + MIN( e3zps_min, e3t_1d(mbathy (ji  ,jj)+1)*e3zps_rat )))
+                  zrisfdepdiff=ABS(risfdep(ji+1,jj) - ( gdepw_1d(misfdep(ji+1,jj)) &
+                       &                              - MIN( e3zps_min, e3t_1d(misfdep(ji+1,jj)-1)*e3zps_rat )))
+                  IF (zbathydiff <= zrisfdepdiff) THEN
+                     mbathy(ji,jj) = mbathy(ji,jj) + 1
+                     bathy(ji,jj)  = gdepw_1d(mbathy (ji,jj)) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj) +1)*e3zps_rat )
+                  ELSE
+                     misfdep(ji+1,jj)= misfdep(ji+1,jj) - 1
+                     risfdep(ji+1,jj) = gdepw_1d(misfdep(ji+1,jj)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji+1,jj))*e3zps_rat )
+                  END IF
+                  ELSE
+                     misfdep(ji+1,jj)= misfdep(ji+1,jj) - 1
+                     risfdep(ji+1,jj) = gdepw_1d(misfdep(ji+1,jj)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji+1,jj))*e3zps_rat )
+                  ENDIF
+               ENDIF
+            ENDDO
+         ENDDO
+ 
+         IF( lk_mpp ) THEN 
+            zbathy(:,:)  = FLOAT( misfdep(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            misfdep(:,:) = INT( zbathy(:,:) )
+
+            CALL lbc_lnk( risfdep,'T', 1. )
+            CALL lbc_lnk( bathy,  'T', 1. )
+
+            zbathy(:,:)  = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            mbathy(:,:)  = INT( zbathy(:,:) )
+         ENDIF 
+ 
+ ! point U misfdep(ji,jj) == bathy(ji,jj+1) 
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               IF( misfdep(ji,jj) == mbathy(ji+1,jj) .AND. mbathy(ji,jj) > 1) THEN
+                  IF ( .NOT. ln_iscpl ) THEN 
+                     zbathydiff  =ABS(  bathy(ji+1,jj) - ( gdepw_1d(mbathy (ji+1,jj)+1) &
+                          &                              + MIN( e3zps_min, e3t_1d(mbathy (ji+1,jj)+1)*e3zps_rat )))
+                     zrisfdepdiff=ABS(risfdep(ji  ,jj) - ( gdepw_1d(misfdep(ji  ,jj)  ) &
+                          &                              - MIN( e3zps_min, e3t_1d(misfdep(ji  ,jj)-1)*e3zps_rat )))
+                     IF (zbathydiff <= zrisfdepdiff) THEN
+                        mbathy(ji+1,jj)  = mbathy (ji+1,jj) + 1
+                        bathy (ji+1,jj)  = gdepw_1d(mbathy (ji+1,jj)  ) + MIN( e3zps_min, e3t_1d(mbathy (ji+1,jj) +1)*e3zps_rat )
+                     ELSE
+                        misfdep(ji,jj)   = misfdep(ji  ,jj) - 1
+                        risfdep(ji,jj)   = gdepw_1d(misfdep(ji  ,jj)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji  ,jj)   )*e3zps_rat )
+                     END IF
+                  ELSE
+                     misfdep(ji,jj)   = misfdep(ji  ,jj) - 1
+                     risfdep(ji,jj)   = gdepw_1d(misfdep(ji  ,jj)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji  ,jj)   )*e3zps_rat )
+                  ENDIF
+               ENDIF
+            ENDDO
+         ENDDO
+ 
+         IF( lk_mpp ) THEN
+            zbathy(:,:)  = FLOAT( misfdep(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            misfdep(:,:) = INT( zbathy(:,:) )
+
+            CALL lbc_lnk( risfdep,'T', 1. )
+            CALL lbc_lnk( bathy,  'T', 1. )
+
+            zbathy(:,:)  = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            mbathy(:,:)  = INT( zbathy(:,:) )
+         ENDIF
+      END DO
+      ! end dig bathy/ice shelf to be compatible
+      ! now fill single point in "coastline" of ice shelf, bathy, hole, and test again one cell tickness
+      DO jl = 1,20
+ 
+ ! remove single point "bay" on isf coast line in the ice shelf draft'
+         DO jk = 2, jpk
+            WHERE (misfdep==0) misfdep=jpk
+            zmask=0._wp
+            WHERE (misfdep <= jk) zmask=1
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  IF (misfdep(ji,jj) == jk) THEN
+                     ibtest = zmask(ji-1,jj) + zmask(ji+1,jj) + zmask(ji,jj-1) + zmask(ji,jj+1)
+                     IF (ibtest <= 1) THEN
+                        risfdep(ji,jj)=gdepw_1d(jk+1) ; misfdep(ji,jj)=jk+1
+                        IF (misfdep(ji,jj) > mbathy(ji,jj)) misfdep(ji,jj) = jpk
+                     END IF
+                  END IF
+               END DO
+            END DO
+         END DO
+         WHERE (misfdep==jpk)
+             misfdep=0 ; risfdep=0._wp ; mbathy=0 ; bathy=0._wp
+         END WHERE
+         IF( lk_mpp ) THEN
+            zbathy(:,:)  = FLOAT( misfdep(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            misfdep(:,:) = INT( zbathy(:,:) )
+
+            CALL lbc_lnk( risfdep,'T', 1. )
+            CALL lbc_lnk( bathy,  'T', 1. )
+
+            zbathy(:,:)  = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            mbathy(:,:)  = INT( zbathy(:,:) )
+         ENDIF
+ 
+ ! remove single point "bay" on bathy coast line beneath an ice shelf'
+         DO jk = jpk,1,-1
+            zmask=0._wp
+            WHERE (mbathy >= jk ) zmask=1
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  IF (mbathy(ji,jj) == jk .AND. misfdep(ji,jj) >= 2) THEN
+                     ibtest = zmask(ji-1,jj) + zmask(ji+1,jj) + zmask(ji,jj-1) + zmask(ji,jj+1)
+                     IF (ibtest <= 1) THEN
+                        bathy(ji,jj)=gdepw_1d(jk) ; mbathy(ji,jj)=jk-1
+                        IF (misfdep(ji,jj) > mbathy(ji,jj)) mbathy(ji,jj) = 0
+                     END IF
+                  END IF
+               END DO
+            END DO
+         END DO
+         WHERE (mbathy==0)
+             misfdep=0 ; risfdep=0._wp ; mbathy=0 ; bathy=0._wp
+         END WHERE
+         IF( lk_mpp ) THEN
+            zbathy(:,:)  = FLOAT( misfdep(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            misfdep(:,:) = INT( zbathy(:,:) )
+
+            CALL lbc_lnk( risfdep,'T', 1. )
+            CALL lbc_lnk( bathy,  'T', 1. )
+
+            zbathy(:,:)  = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            mbathy(:,:)  = INT( zbathy(:,:) )
+         ENDIF
+ 
+ ! fill hole in ice shelf
+         zmisfdep = misfdep
+         zrisfdep = risfdep
+         WHERE (zmisfdep <= 1._wp) zmisfdep=jpk
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               ibtestim1 = zmisfdep(ji-1,jj  ) ; ibtestip1 = zmisfdep(ji+1,jj  )
+               ibtestjm1 = zmisfdep(ji  ,jj-1) ; ibtestjp1 = zmisfdep(ji  ,jj+1)
+               IF( zmisfdep(ji,jj) >= mbathy(ji-1,jj  ) ) ibtestim1 = jpk
+               IF( zmisfdep(ji,jj) >= mbathy(ji+1,jj  ) ) ibtestip1 = jpk
+               IF( zmisfdep(ji,jj) >= mbathy(ji  ,jj-1) ) ibtestjm1 = jpk
+               IF( zmisfdep(ji,jj) >= mbathy(ji  ,jj+1) ) ibtestjp1 = jpk
+               ibtest=MIN(ibtestim1, ibtestip1, ibtestjm1, ibtestjp1)
+               IF( ibtest == jpk .AND. misfdep(ji,jj) >= 2) THEN
+                  mbathy(ji,jj) = 0 ; bathy(ji,jj) = 0.0_wp ; misfdep(ji,jj) = 0 ; risfdep(ji,jj) = 0.0_wp
+               END IF
+               IF( zmisfdep(ji,jj) < ibtest .AND. misfdep(ji,jj) >= 2) THEN
+                  misfdep(ji,jj) = ibtest
+                  risfdep(ji,jj) = gdepw_1d(ibtest)
+               ENDIF
+            ENDDO
+         ENDDO
+ 
+         IF( lk_mpp ) THEN 
+            zbathy(:,:)  = FLOAT( misfdep(:,:) ) 
+            CALL lbc_lnk( zbathy,  'T', 1. ) 
+            misfdep(:,:) = INT( zbathy(:,:) ) 
+
+            CALL lbc_lnk( risfdep, 'T', 1. ) 
+            CALL lbc_lnk( bathy,   'T', 1. )
+
+            zbathy(:,:) = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy,  'T', 1. )
+            mbathy(:,:) = INT( zbathy(:,:) )
+         ENDIF 
+ !
+ !! fill hole in bathymetry
+         zmbathy (:,:)=mbathy (:,:)
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               ibtestim1 = zmbathy(ji-1,jj  ) ; ibtestip1 = zmbathy(ji+1,jj  )
+               ibtestjm1 = zmbathy(ji  ,jj-1) ; ibtestjp1 = zmbathy(ji  ,jj+1)
+               IF( zmbathy(ji,jj) <  misfdep(ji-1,jj  ) ) ibtestim1 = 0
+               IF( zmbathy(ji,jj) <  misfdep(ji+1,jj  ) ) ibtestip1 = 0
+               IF( zmbathy(ji,jj) <  misfdep(ji  ,jj-1) ) ibtestjm1 = 0
+               IF( zmbathy(ji,jj) <  misfdep(ji  ,jj+1) ) ibtestjp1 = 0
+               ibtest=MAX(ibtestim1, ibtestip1, ibtestjm1, ibtestjp1)
+               IF( ibtest == 0 .AND. misfdep(ji,jj) >= 2) THEN
+                  mbathy(ji,jj) = 0 ; bathy(ji,jj) = 0.0_wp ; misfdep(ji,jj) = 0 ; risfdep(ji,jj) = 0.0_wp ;
+               END IF
+               IF( ibtest < zmbathy(ji,jj) .AND. misfdep(ji,jj) >= 2) THEN
+                  mbathy(ji,jj) = ibtest
+                  bathy(ji,jj)  = gdepw_1d(ibtest+1) 
+               ENDIF
+            END DO
+         END DO
+         IF( lk_mpp ) THEN 
+            zbathy(:,:)  = FLOAT( misfdep(:,:) ) 
+            CALL lbc_lnk( zbathy,  'T', 1. ) 
+            misfdep(:,:) = INT( zbathy(:,:) ) 
+
+            CALL lbc_lnk( risfdep, 'T', 1. ) 
+            CALL lbc_lnk( bathy,   'T', 1. )
+
+            zbathy(:,:) = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy,  'T', 1. )
+            mbathy(:,:) = INT( zbathy(:,:) )
+         ENDIF 
+ ! if not compatible after all check (ie U point water column less than 2 cells), mask U
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               IF (mbathy(ji,jj) == misfdep(ji+1,jj) .AND. mbathy(ji,jj) >= 1 .AND. mbathy(ji+1,jj) >= 1) THEN
+                  mbathy(ji,jj)  = mbathy(ji,jj) - 1 ; bathy(ji,jj)   = gdepw_1d(mbathy(ji,jj)+1) ;
+               END IF
+            END DO
+         END DO
+         IF( lk_mpp ) THEN 
+            zbathy(:,:)  = FLOAT( misfdep(:,:) ) 
+            CALL lbc_lnk( zbathy,  'T', 1. ) 
+            misfdep(:,:) = INT( zbathy(:,:) ) 
+
+            CALL lbc_lnk( risfdep, 'T', 1. ) 
+            CALL lbc_lnk( bathy,   'T', 1. )
+
+            zbathy(:,:) = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy,  'T', 1. )
+            mbathy(:,:) = INT( zbathy(:,:) )
+         ENDIF 
+ ! if not compatible after all check (ie U point water column less than 2 cells), mask U
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               IF (misfdep(ji,jj) == mbathy(ji+1,jj) .AND. mbathy(ji,jj) >= 1 .AND. mbathy(ji+1,jj) >= 1) THEN
+                  mbathy(ji+1,jj)  = mbathy(ji+1,jj) - 1;   bathy(ji+1,jj)   = gdepw_1d(mbathy(ji+1,jj)+1) ;
+               END IF
+            END DO
+         END DO
+         IF( lk_mpp ) THEN 
+            zbathy(:,:)  = FLOAT( misfdep(:,:) ) 
+            CALL lbc_lnk( zbathy, 'T', 1. ) 
+            misfdep(:,:) = INT( zbathy(:,:) ) 
+
+            CALL lbc_lnk( risfdep,'T', 1. ) 
+            CALL lbc_lnk( bathy,  'T', 1. )
+
+            zbathy(:,:) = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            mbathy(:,:) = INT( zbathy(:,:) )
+         ENDIF 
+ ! if not compatible after all check (ie V point water column less than 2 cells), mask V
+         DO jj = 1, jpjm1
+            DO ji = 1, jpi
+               IF (mbathy(ji,jj) == misfdep(ji,jj+1) .AND. mbathy(ji,jj) >= 1 .AND. mbathy(ji,jj+1) >= 1) THEN
+                  mbathy(ji,jj)  = mbathy(ji,jj) - 1 ; bathy(ji,jj)   = gdepw_1d(mbathy(ji,jj)+1) ;
+               END IF
+            END DO
+         END DO
+         IF( lk_mpp ) THEN 
+            zbathy(:,:)  = FLOAT( misfdep(:,:) ) 
+            CALL lbc_lnk( zbathy, 'T', 1. ) 
+            misfdep(:,:) = INT( zbathy(:,:) ) 
+
+            CALL lbc_lnk( risfdep,'T', 1. ) 
+            CALL lbc_lnk( bathy,  'T', 1. )
+
+            zbathy(:,:) = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            mbathy(:,:) = INT( zbathy(:,:) )
+         ENDIF 
+ ! if not compatible after all check (ie V point water column less than 2 cells), mask V
+         DO jj = 1, jpjm1
+            DO ji = 1, jpi
+               IF (misfdep(ji,jj) == mbathy(ji,jj+1) .AND. mbathy(ji,jj) >= 1 .AND. mbathy(ji,jj+1) >= 1) THEN
+                  mbathy(ji,jj+1)  = mbathy(ji,jj+1) - 1 ; bathy(ji,jj+1) = gdepw_1d(mbathy(ji,jj+1)+1) ;
+               END IF
+            END DO
+         END DO
+         IF( lk_mpp ) THEN 
+            zbathy(:,:)  = FLOAT( misfdep(:,:) ) 
+            CALL lbc_lnk( zbathy, 'T', 1. ) 
+            misfdep(:,:) = INT( zbathy(:,:) ) 
+
+            CALL lbc_lnk( risfdep,'T', 1. ) 
+            CALL lbc_lnk( bathy,  'T', 1. )
+
+            zbathy(:,:) = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            mbathy(:,:) = INT( zbathy(:,:) )
+         ENDIF 
+ ! if not compatible after all check, mask T
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF (mbathy(ji,jj) <= misfdep(ji,jj)) THEN
+                  misfdep(ji,jj) = 0 ; risfdep(ji,jj) = 0._wp ; mbathy(ji,jj)  = 0 ; bathy(ji,jj)   = 0._wp ;
+               END IF
+            END DO
+         END DO
+ 
+         WHERE (mbathy(:,:) == 1)
+            mbathy = 0; bathy = 0.0_wp ; misfdep = 0 ; risfdep = 0.0_wp
+         END WHERE
+      END DO 
+! end check compatibility ice shelf/bathy
+      ! remove very shallow ice shelf (less than ~ 10m if 75L)
+      WHERE (risfdep(:,:) <= 10._wp)
+         misfdep = 1; risfdep = 0.0_wp;
+      END WHERE
+
+      IF( icompt == 0 ) THEN 
+         IF(lwp) WRITE(numout,*)'     no points with ice shelf too close to bathymetry' 
+      ELSE 
+         IF(lwp) WRITE(numout,*)'    ',icompt,' ocean grid points with ice shelf thickness reduced to avoid bathymetry' 
+      ENDIF 
+
+      ! compute scale factor and depth at T- and W- points
       DO jj = 1, jpj
          DO ji = 1, jpi
@@ -1035,4 +1745,5 @@
                   ELSE                                       ;   gdepw_0(ji,jj,ik+1) = gdepw_1d(ik+1)
                   ENDIF
+      !            gdepw_0(ji,jj,ik+1) = gdepw_1d(ik+1)
 !gm Bug?  check the gdepw_1d
                   !       ... on ik
@@ -1040,12 +1751,9 @@
                      &                             * ((gdept_1d(     ik  ) - gdepw_1d(ik) )   &
                      &                             / ( gdepw_1d(     ik+1) - gdepw_1d(ik) ))
-                  e3t_0  (ji,jj,ik) = e3t_1d  (ik) * ( gdepw_0 (ji,jj,ik+1) - gdepw_1d(ik) )   & 
-                     &                             / ( gdepw_1d(      ik+1) - gdepw_1d(ik) ) 
-                  e3w_0(ji,jj,ik) = 0.5_wp * ( gdepw_0(ji,jj,ik+1) + gdepw_1d(ik+1) - 2._wp * gdepw_1d(ik) )   &
-                     &                     * ( e3w_1d(ik) / ( gdepw_1d(ik+1) - gdepw_1d(ik) ) )
+                  e3t_0  (ji,jj,ik  ) = gdepw_0(ji,jj,ik+1) - gdepw_1d(ik  )
+                  e3w_0  (ji,jj,ik  ) = gdept_0(ji,jj,ik  ) - gdept_1d(ik-1)
                   !       ... on ik+1
                   e3w_0  (ji,jj,ik+1) = e3t_0  (ji,jj,ik)
                   e3t_0  (ji,jj,ik+1) = e3t_0  (ji,jj,ik)
-                  gdept_0(ji,jj,ik+1) = gdept_0(ji,jj,ik) + e3t_0(ji,jj,ik)
                ENDIF
             ENDIF
@@ -1073,687 +1781,58 @@
       END DO
       !
-      IF ( ln_isfcav ) THEN
       ! (ISF) Definition of e3t, u, v, w for ISF case
-         DO jj = 1, jpj 
-            DO ji = 1, jpi 
-               ik = misfdep(ji,jj) 
-               IF( ik > 1 ) THEN               ! ice shelf point only 
-                  IF( risfdep(ji,jj) < gdepw_1d(ik) )  risfdep(ji,jj)= gdepw_1d(ik) 
-                  gdepw_0(ji,jj,ik) = risfdep(ji,jj) 
+      DO jj = 1, jpj 
+         DO ji = 1, jpi 
+            ik = misfdep(ji,jj) 
+            IF( ik > 1 ) THEN               ! ice shelf point only 
+               IF( risfdep(ji,jj) < gdepw_1d(ik) )  risfdep(ji,jj)= gdepw_1d(ik) 
+               gdepw_0(ji,jj,ik) = risfdep(ji,jj) 
 !gm Bug?  check the gdepw_0 
-               !       ... on ik 
-                  gdept_0(ji,jj,ik) = gdepw_1d(ik+1) - ( gdepw_1d(ik+1) - gdepw_0(ji,jj,ik) )   & 
-                     &                               * ( gdepw_1d(ik+1) - gdept_1d(ik)      )   & 
-                     &                               / ( gdepw_1d(ik+1) - gdepw_1d(ik)      ) 
-                  e3t_0  (ji,jj,ik  ) = gdepw_1d(ik+1) - gdepw_0(ji,jj,ik) 
-                  e3w_0  (ji,jj,ik+1) = gdept_1d(ik+1) - gdept_0(ji,jj,ik)
-
-                  IF( ik + 1 == mbathy(ji,jj) ) THEN               ! ice shelf point only (2 cell water column) 
-                     e3w_0  (ji,jj,ik+1) = gdept_0(ji,jj,ik+1) - gdept_0(ji,jj,ik) 
-                  ENDIF 
-               !       ... on ik / ik-1 
-                  e3w_0  (ji,jj,ik  ) = 2._wp * (gdept_0(ji,jj,ik) - gdepw_0(ji,jj,ik)) 
-                  e3t_0  (ji,jj,ik-1) = gdepw_0(ji,jj,ik) - gdepw_1d(ik-1)
+            !       ... on ik 
+               gdept_0(ji,jj,ik) = gdepw_1d(ik+1) - ( gdepw_1d(ik+1) - gdepw_0(ji,jj,ik) )   & 
+                  &                               * ( gdepw_1d(ik+1) - gdept_1d(ik)      )   & 
+                  &                               / ( gdepw_1d(ik+1) - gdepw_1d(ik)      ) 
+               e3t_0  (ji,jj,ik  ) = gdepw_1d(ik+1) - gdepw_0(ji,jj,ik) 
+               e3w_0  (ji,jj,ik+1) = gdept_1d(ik+1) - gdept_0(ji,jj,ik)
+
+               IF( ik + 1 == mbathy(ji,jj) ) THEN               ! ice shelf point only (2 cell water column) 
+                  e3w_0  (ji,jj,ik+1) = gdept_0(ji,jj,ik+1) - gdept_0(ji,jj,ik) 
+               ENDIF 
+            !       ... on ik / ik-1 
+               e3w_0  (ji,jj,ik  ) = e3t_0  (ji,jj,ik) !2._wp * (gdept_0(ji,jj,ik) - gdepw_0(ji,jj,ik)) 
+               e3t_0  (ji,jj,ik-1) = gdepw_0(ji,jj,ik) - gdepw_1d(ik-1)
 ! The next line isn't required and doesn't affect results - included for consistency with bathymetry code 
-                  gdept_0(ji,jj,ik-1) = gdept_1d(ik-1)
+               gdept_0(ji,jj,ik-1) = gdept_1d(ik-1)
+            ENDIF 
+         END DO 
+      END DO 
+   
+      it = 0 
+      DO jj = 1, jpj 
+         DO ji = 1, jpi 
+            ik = misfdep(ji,jj) 
+            IF( ik > 1 ) THEN               ! ice shelf point only 
+               e3tp (ji,jj) = e3t_0(ji,jj,ik  ) 
+               e3wp (ji,jj) = e3w_0(ji,jj,ik+1 ) 
+            ! test 
+               zdiff= gdept_0(ji,jj,ik) - gdepw_0(ji,jj,ik  ) 
+               IF( zdiff <= 0. .AND. lwp ) THEN  
+                  it = it + 1 
+                  WRITE(numout,*) ' it      = ', it, ' ik      = ', ik, ' (i,j) = ', ji, jj 
+                  WRITE(numout,*) ' risfdep = ', risfdep(ji,jj) 
+                  WRITE(numout,*) ' gdept = ', gdept_0(ji,jj,ik), ' gdepw = ', gdepw_0(ji,jj,ik+1), ' zdiff = ', zdiff 
+                  WRITE(numout,*) ' e3tp  = ', e3tp(ji,jj), ' e3wp  = ', e3wp(ji,jj) 
                ENDIF 
-            END DO 
+            ENDIF 
          END DO 
-      ! 
-         it = 0 
-         DO jj = 1, jpj 
-            DO ji = 1, jpi 
-               ik = misfdep(ji,jj) 
-               IF( ik > 1 ) THEN               ! ice shelf point only 
-                  e3tp (ji,jj) = e3t_0(ji,jj,ik  ) 
-                  e3wp (ji,jj) = e3w_0(ji,jj,ik+1 ) 
-               ! test 
-                  zdiff= gdept_0(ji,jj,ik) - gdepw_0(ji,jj,ik  ) 
-                  IF( zdiff <= 0. .AND. lwp ) THEN  
-                     it = it + 1 
-                     WRITE(numout,*) ' it      = ', it, ' ik      = ', ik, ' (i,j) = ', ji, jj 
-                     WRITE(numout,*) ' risfdep = ', risfdep(ji,jj) 
-                     WRITE(numout,*) ' gdept = ', gdept_0(ji,jj,ik), ' gdepw = ', gdepw_0(ji,jj,ik+1), ' zdiff = ', zdiff 
-                     WRITE(numout,*) ' e3tp  = ', e3tp(ji,jj), ' e3wp  = ', e3wp(ji,jj) 
-                  ENDIF 
-               ENDIF 
-            END DO 
-         END DO 
-      END IF
-      ! END (ISF)
-
-      ! Scale factors and depth at U-, V-, UW and VW-points
-      DO jk = 1, jpk                        ! initialisation to z-scale factors
-         e3u_0 (:,:,jk) = e3t_1d(jk)
-         e3v_0 (:,:,jk) = e3t_1d(jk)
-         e3uw_0(:,:,jk) = e3w_1d(jk)
-         e3vw_0(:,:,jk) = e3w_1d(jk)
-      END DO
-      DO jk = 1,jpk                         ! Computed as the minimum of neighbooring scale factors
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1   ! vector opt.
-               e3u_0 (ji,jj,jk) = MIN( e3t_0(ji,jj,jk), e3t_0(ji+1,jj,jk) )
-               e3v_0 (ji,jj,jk) = MIN( e3t_0(ji,jj,jk), e3t_0(ji,jj+1,jk) )
-               e3uw_0(ji,jj,jk) = MIN( e3w_0(ji,jj,jk), e3w_0(ji+1,jj,jk) )
-               e3vw_0(ji,jj,jk) = MIN( e3w_0(ji,jj,jk), e3w_0(ji,jj+1,jk) )
-            END DO
-         END DO
-      END DO
-      IF ( ln_isfcav ) THEN
-      ! (ISF) define e3uw (adapted for 2 cells in the water column)
-         DO jj = 2, jpjm1 
-            DO ji = 2, fs_jpim1   ! vector opt. 
-               ikb = MAX(mbathy (ji,jj),mbathy (ji+1,jj))
-               ikt = MAX(misfdep(ji,jj),misfdep(ji+1,jj))
-               IF (ikb == ikt+1) e3uw_0(ji,jj,ikb) =  MIN( gdept_0(ji,jj,ikb  ), gdept_0(ji+1,jj  ,ikb  ) ) &
-                                       &            - MAX( gdept_0(ji,jj,ikb-1), gdept_0(ji+1,jj  ,ikb-1) )
-               ikb = MAX(mbathy (ji,jj),mbathy (ji,jj+1))
-               ikt = MAX(misfdep(ji,jj),misfdep(ji,jj+1))
-               IF (ikb == ikt+1) e3vw_0(ji,jj,ikb) =  MIN( gdept_0(ji,jj,ikb  ), gdept_0(ji  ,jj+1,ikb  ) ) &
-                                       &            - MAX( gdept_0(ji,jj,ikb-1), gdept_0(ji  ,jj+1,ikb-1) )
-            END DO
-         END DO
-      END IF
-
-      CALL lbc_lnk( e3u_0 , 'U', 1._wp )   ;   CALL lbc_lnk( e3uw_0, 'U', 1._wp )   ! lateral boundary conditions
-      CALL lbc_lnk( e3v_0 , 'V', 1._wp )   ;   CALL lbc_lnk( e3vw_0, 'V', 1._wp )
-      !
-      DO jk = 1, jpk                        ! set to z-scale factor if zero (i.e. along closed boundaries)
-         WHERE( e3u_0 (:,:,jk) == 0._wp )   e3u_0 (:,:,jk) = e3t_1d(jk)
-         WHERE( e3v_0 (:,:,jk) == 0._wp )   e3v_0 (:,:,jk) = e3t_1d(jk)
-         WHERE( e3uw_0(:,:,jk) == 0._wp )   e3uw_0(:,:,jk) = e3w_1d(jk)
-         WHERE( e3vw_0(:,:,jk) == 0._wp )   e3vw_0(:,:,jk) = e3w_1d(jk)
-      END DO
-      
-      ! Scale factor at F-point
-      DO jk = 1, jpk                        ! initialisation to z-scale factors
-         e3f_0(:,:,jk) = e3t_1d(jk)
-      END DO
-      DO jk = 1, jpk                        ! Computed as the minimum of neighbooring V-scale factors
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1   ! vector opt.
-               e3f_0(ji,jj,jk) = MIN( e3v_0(ji,jj,jk), e3v_0(ji+1,jj,jk) )
-            END DO
-         END DO
-      END DO
-      CALL lbc_lnk( e3f_0, 'F', 1._wp )       ! Lateral boundary conditions
-      !
-      DO jk = 1, jpk                        ! set to z-scale factor if zero (i.e. along closed boundaries)
-         WHERE( e3f_0(:,:,jk) == 0._wp )   e3f_0(:,:,jk) = e3t_1d(jk)
-      END DO
-!!gm  bug ? :  must be a do loop with mj0,mj1
-      ! 
-      e3t_0(:,mj0(1),:) = e3t_0(:,mj0(2),:)     ! we duplicate factor scales for jj = 1 and jj = 2
-      e3w_0(:,mj0(1),:) = e3w_0(:,mj0(2),:) 
-      e3u_0(:,mj0(1),:) = e3u_0(:,mj0(2),:) 
-      e3v_0(:,mj0(1),:) = e3v_0(:,mj0(2),:) 
-      e3f_0(:,mj0(1),:) = e3f_0(:,mj0(2),:) 
-
-      ! Control of the sign
-      IF( MINVAL( e3t_0  (:,:,:) ) <= 0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   e3t_0 <= 0' )
-      IF( MINVAL( e3w_0  (:,:,:) ) <= 0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   e3w_0 <= 0' )
-      IF( MINVAL( gdept_0(:,:,:) ) <  0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   gdept_0 <  0' )
-      IF( MINVAL( gdepw_0(:,:,:) ) <  0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   gdepw_0 <  0' )
-     
-      ! Compute gdep3w_0 (vertical sum of e3w)
-      IF ( ln_isfcav ) THEN ! if cavity
-         WHERE (misfdep == 0) misfdep = 1
-         DO jj = 1,jpj
-            DO ji = 1,jpi
-               gdep3w_0(ji,jj,1) = 0.5_wp * e3w_0(ji,jj,1)
-               DO jk = 2, misfdep(ji,jj)
-                  gdep3w_0(ji,jj,jk) = gdep3w_0(ji,jj,jk-1) + e3w_0(ji,jj,jk) 
-               END DO
-               IF (misfdep(ji,jj) .GE. 2) gdep3w_0(ji,jj,misfdep(ji,jj)) = risfdep(ji,jj) + 0.5_wp * e3w_0(ji,jj,misfdep(ji,jj))
-               DO jk = misfdep(ji,jj) + 1, jpk
-                  gdep3w_0(ji,jj,jk) = gdep3w_0(ji,jj,jk-1) + e3w_0(ji,jj,jk) 
-               END DO
-            END DO
-         END DO
-      ELSE ! no cavity
-         gdep3w_0(:,:,1) = 0.5_wp * e3w_0(:,:,1)
-         DO jk = 2, jpk
-            gdep3w_0(:,:,jk) = gdep3w_0(:,:,jk-1) + e3w_0(:,:,jk)
-         END DO
-      END IF
-      !                                               ! ================= !
-      IF(lwp .AND. ll_print) THEN                     !   Control print   !
-         !                                            ! ================= !
-         DO jj = 1,jpj
-            DO ji = 1, jpi
-               ik = MAX( mbathy(ji,jj), 1 )
-               zprt(ji,jj,1) = e3t_0   (ji,jj,ik)
-               zprt(ji,jj,2) = e3w_0   (ji,jj,ik)
-               zprt(ji,jj,3) = e3u_0   (ji,jj,ik)
-               zprt(ji,jj,4) = e3v_0   (ji,jj,ik)
-               zprt(ji,jj,5) = e3f_0   (ji,jj,ik)
-               zprt(ji,jj,6) = gdep3w_0(ji,jj,ik)
-            END DO
-         END DO
-         WRITE(numout,*)
-         WRITE(numout,*) 'domzgr e3t(mbathy)'      ;   CALL prihre(zprt(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-         WRITE(numout,*)
-         WRITE(numout,*) 'domzgr e3w(mbathy)'      ;   CALL prihre(zprt(:,:,2),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-         WRITE(numout,*)
-         WRITE(numout,*) 'domzgr e3u(mbathy)'      ;   CALL prihre(zprt(:,:,3),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-         WRITE(numout,*)
-         WRITE(numout,*) 'domzgr e3v(mbathy)'      ;   CALL prihre(zprt(:,:,4),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-         WRITE(numout,*)
-         WRITE(numout,*) 'domzgr e3f(mbathy)'      ;   CALL prihre(zprt(:,:,5),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-         WRITE(numout,*)
-         WRITE(numout,*) 'domzgr gdep3w(mbathy)'   ;   CALL prihre(zprt(:,:,6),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-      ENDIF  
-      !
-      CALL wrk_dealloc( jpi, jpj, jpk, zprt )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('zgr_zps')
-      !
-   END SUBROUTINE zgr_zps
-
-   SUBROUTINE zgr_isf
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE zgr_isf  ***
-      !!   
-      !! ** Purpose :   check the bathymetry in levels
-      !!   
-      !! ** Method  :   THe water column have to contained at least 2 cells
-      !!                Bathymetry and isfdraft are modified (dig/close) to respect
-      !!                this criterion.
-      !!                 
-      !!   
-      !! ** Action  : - test compatibility between isfdraft and bathy 
-      !!              - bathy and isfdraft are modified
-      !!----------------------------------------------------------------------
-      !!   
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      INTEGER  ::   ik, it           ! temporary integers
-      INTEGER  ::   id, jd, nprocd
-      INTEGER  ::   icompt, ibtest, ibtestim1, ibtestip1, ibtestjm1, ibtestjp1   ! (ISF)
-      LOGICAL  ::   ll_print         ! Allow  control print for debugging
-      REAL(wp) ::   ze3tp , ze3wp    ! Last ocean level thickness at T- and W-points
-      REAL(wp) ::   zdepwp, zdepth   ! Ajusted ocean depth to avoid too small e3t
-      REAL(wp) ::   zmax, zmin       ! Maximum and minimum depth
-      REAL(wp) ::   zdiff            ! temporary scalar
-      REAL(wp) ::   zrefdep          ! temporary scalar
-      REAL(wp) ::   zbathydiff, zrisfdepdiff  ! isf temporary scalar
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zrisfdep, zbathy, zmask   ! 2D workspace (ISH)
-      INTEGER , POINTER, DIMENSION(:,:)   ::   zmbathy, zmisfdep         ! 2D workspace (ISH)
-      !!---------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('zgr_isf')
-      !
-      CALL wrk_alloc( jpi, jpj, zbathy, zmask, zrisfdep)
-      CALL wrk_alloc( jpi, jpj, zmisfdep, zmbathy )
-
-
-      ! (ISF) compute misfdep
-      WHERE( risfdep(:,:) == 0._wp .AND. bathy(:,:) .NE. 0) ;   misfdep(:,:) = 1   ! open water : set misfdep to 1  
-      ELSEWHERE                      ;                          misfdep(:,:) = 2   ! iceshelf : initialize misfdep to second level 
-      END WHERE  
-
-      ! Compute misfdep for ocean points (i.e. first wet level) 
-      ! find the first ocean level such that the first level thickness 
-      ! is larger than the bot_level of e3zps_min and e3zps_rat * e3t_0 (where 
-      ! e3t_0 is the reference level thickness 
-      DO jk = 2, jpkm1 
-         zdepth = gdepw_1d(jk+1) - MIN( e3zps_min, e3t_1d(jk)*e3zps_rat ) 
-         WHERE( 0._wp < risfdep(:,:) .AND. risfdep(:,:) >= zdepth )   misfdep(:,:) = jk+1 
       END DO 
-      WHERE (risfdep(:,:) <= e3t_1d(1) .AND. risfdep(:,:) .GT. 0._wp)
-         risfdep(:,:) = 0. ; misfdep(:,:) = 1
-      END WHERE
- 
-! basic check for the compatibility of bathy and risfdep. I think it should be offline because it is not perfect and cannot solved all the situation
-      icompt = 0 
-! run the bathy check 10 times to be sure all the modif in the bathy or iceshelf draft are compatible together
-      DO jl = 1, 10     
-         WHERE (bathy(:,:) .EQ. risfdep(:,:) )
-            misfdep(:,:) = 0 ; risfdep(:,:) = 0._wp
-            mbathy (:,:) = 0 ; bathy  (:,:) = 0._wp
-         END WHERE
-         WHERE (mbathy(:,:) <= 0) 
-            misfdep(:,:) = 0; risfdep(:,:) = 0._wp 
-            mbathy (:,:) = 0; bathy  (:,:) = 0._wp
-         ENDWHERE
-         IF( lk_mpp ) THEN
-            zbathy(:,:) = FLOAT( misfdep(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            misfdep(:,:) = INT( zbathy(:,:) )
-            CALL lbc_lnk( risfdep, 'T', 1. )
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF
-         IF( nperio == 1 .OR. nperio  ==  4 .OR. nperio  ==  6 ) THEN 
-            misfdep( 1 ,:) = misfdep(jpim1,:)           ! local domain is cyclic east-west 
-            misfdep(jpi,:) = misfdep(  2  ,:) 
-         ENDIF
-
-         IF( nperio == 1 .OR. nperio  ==  4 .OR. nperio  ==  6 ) THEN
-            mbathy( 1 ,:) = mbathy(jpim1,:)             ! local domain is cyclic east-west
-            mbathy(jpi,:) = mbathy(  2  ,:)
-         ENDIF
-
-         ! split last cell if possible (only where water column is 2 cell or less)
-         DO jk = jpkm1, 1, -1
-            zmax = gdepw_1d(jk) + MIN( e3zps_min, e3t_1d(jk)*e3zps_rat )
-            WHERE( gdepw_1d(jk) < bathy(:,:) .AND. bathy(:,:) <= zmax .AND. misfdep + 1 >= mbathy)
-               mbathy(:,:) = jk
-               bathy(:,:)  = zmax
-            END WHERE
-         END DO
- 
-         ! split top cell if possible (only where water column is 2 cell or less)
-         DO jk = 2, jpkm1
-            zmax = gdepw_1d(jk+1) - MIN( e3zps_min, e3t_1d(jk)*e3zps_rat )
-            WHERE( gdepw_1d(jk+1) > risfdep(:,:) .AND. risfdep(:,:) >= zmax .AND. misfdep + 1 >= mbathy)
-               misfdep(:,:) = jk
-               risfdep(:,:) = zmax
-            END WHERE
-         END DO
-
- 
- ! Case where bathy and risfdep compatible but not the level variable mbathy/misfdep because of partial cell condition
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! find the minimum change option:
-               ! test bathy
-               IF (risfdep(ji,jj) .GT. 1) THEN
-               zbathydiff =ABS(bathy(ji,jj)   - (gdepw_1d(mbathy (ji,jj)+1) &
-                 &   + MIN( e3zps_min, e3t_1d(mbathy (ji,jj)+1)*e3zps_rat )))
-               zrisfdepdiff=ABS(risfdep(ji,jj) - (gdepw_1d(misfdep(ji,jj)  ) &
-                 &   - MIN( e3zps_min, e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )))
- 
-                  IF (bathy(ji,jj) .GT. risfdep(ji,jj) .AND. mbathy(ji,jj) .LT. misfdep(ji,jj)) THEN
-                     IF (zbathydiff .LE. zrisfdepdiff) THEN
-                        bathy(ji,jj) = gdepw_1d(mbathy(ji,jj)) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj)+1)*e3zps_rat )
-                        mbathy(ji,jj)= mbathy(ji,jj) + 1
-                     ELSE
-                        risfdep(ji,jj) = gdepw_1d(misfdep(ji,jj)) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )
-                        misfdep(ji,jj) = misfdep(ji,jj) - 1
-                     END IF
-                  END IF
-               END IF
-            END DO
-         END DO
- 
-          ! At least 2 levels for water thickness at T, U, and V point.
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! find the minimum change option:
-               ! test bathy
-               IF( misfdep(ji,jj) == mbathy(ji,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff  =ABS(bathy(ji,jj)  - (gdepw_1d(mbathy (ji,jj)+1)&
-                    & + MIN( e3zps_min,e3t_1d(mbathy (ji,jj)+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji,jj) - (gdepw_1d(misfdep(ji,jj)  )  &
-                    & - MIN( e3zps_min,e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )))
-                  IF (zbathydiff .LE. zrisfdepdiff) THEN
-                     mbathy(ji,jj) = mbathy(ji,jj) + 1
-                     bathy(ji,jj)  = gdepw_1d(mbathy (ji,jj)) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj) +1)*e3zps_rat )
-                  ELSE
-                     misfdep(ji,jj)= misfdep(ji,jj) - 1
-                     risfdep(ji,jj) = gdepw_1d(misfdep(ji,jj)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj))*e3zps_rat )
-                  END IF
-               ENDIF
-            END DO
-         END DO
- 
- ! point V mbathy(ji,jj) EQ misfdep(ji,jj+1) 
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               IF( misfdep(ji,jj+1) == mbathy(ji,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff =ABS(bathy(ji,jj    ) - (gdepw_1d(mbathy (ji,jj)+1)   &
-                    &   + MIN( e3zps_min, e3t_1d(mbathy (ji,jj  )+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji,jj+1) - (gdepw_1d(misfdep(ji,jj+1))  &
-                    &  - MIN( e3zps_min, e3t_1d(misfdep(ji,jj+1)-1)*e3zps_rat )))
-                  IF (zbathydiff .LE. zrisfdepdiff) THEN
-                     mbathy(ji,jj) = mbathy(ji,jj) + 1
-                     bathy(ji,jj)  = gdepw_1d(mbathy (ji,jj  )) &
-                   &    + MIN( e3zps_min, e3t_1d(mbathy(ji,jj   )+1)*e3zps_rat )
-                  ELSE
-                     misfdep(ji,jj+1)  = misfdep(ji,jj+1) - 1
-                     risfdep (ji,jj+1) = gdepw_1d(misfdep(ji,jj+1)+1) &
-                   &   - MIN( e3zps_min, e3t_1d(misfdep(ji,jj+1))*e3zps_rat )
-                  END IF
-               ENDIF
-            END DO
-         END DO
- 
-         IF( lk_mpp ) THEN
-            zbathy(:,:) = FLOAT( misfdep(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            misfdep(:,:) = INT( zbathy(:,:) )
-            CALL lbc_lnk( risfdep, 'T', 1. )
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF
- ! point V misdep(ji,jj) EQ mbathy(ji,jj+1) 
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               IF( misfdep(ji,jj) == mbathy(ji,jj+1) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff =ABS(  bathy(ji,jj+1) - (gdepw_1d(mbathy (ji,jj+1)+1) &
-                   &   + MIN( e3zps_min, e3t_1d(mbathy (ji,jj+1)+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji,jj  ) - (gdepw_1d(misfdep(ji,jj  )  )  &
-                   &   - MIN( e3zps_min, e3t_1d(misfdep(ji,jj  )-1)*e3zps_rat )))
-                  IF (zbathydiff .LE. zrisfdepdiff) THEN
-                     mbathy (ji,jj+1) = mbathy(ji,jj+1) + 1
-                     bathy  (ji,jj+1) = gdepw_1d(mbathy (ji,jj+1)  ) + MIN( e3zps_min, e3t_1d(mbathy (ji,jj+1)+1)*e3zps_rat )
-                  ELSE
-                     misfdep(ji,jj)   = misfdep(ji,jj) - 1
-                     risfdep(ji,jj)   = gdepw_1d(misfdep(ji,jj  )+1) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj  )  )*e3zps_rat )
-                  END IF
-               ENDIF
-            END DO
-         END DO
- 
- 
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- 
- ! point U mbathy(ji,jj) EQ misfdep(ji,jj+1) 
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               IF( misfdep(ji+1,jj) == mbathy(ji,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff =ABS(  bathy(ji  ,jj) - (gdepw_1d(mbathy (ji,jj)+1) &
-                    &   + MIN( e3zps_min, e3t_1d(mbathy (ji  ,jj)+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji+1,jj) - (gdepw_1d(misfdep(ji+1,jj)) &
-                    &  - MIN( e3zps_min, e3t_1d(misfdep(ji+1,jj)-1)*e3zps_rat )))
-                  IF (zbathydiff .LE. zrisfdepdiff) THEN
-                     mbathy(ji,jj) = mbathy(ji,jj) + 1
-                     bathy(ji,jj)  = gdepw_1d(mbathy (ji,jj)) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj) +1)*e3zps_rat )
-                  ELSE
-                     misfdep(ji+1,jj)= misfdep(ji+1,jj) - 1
-                     risfdep(ji+1,jj) = gdepw_1d(misfdep(ji+1,jj)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji+1,jj))*e3zps_rat )
-                  END IF
-               ENDIF
-            ENDDO
-         ENDDO
- 
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- 
- ! point U misfdep(ji,jj) EQ bathy(ji,jj+1) 
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               IF( misfdep(ji,jj) == mbathy(ji+1,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff =ABS(  bathy(ji+1,jj) - (gdepw_1d(mbathy (ji+1,jj)+1) &
-                      &   + MIN( e3zps_min, e3t_1d(mbathy (ji+1,jj)+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji  ,jj) - (gdepw_1d(misfdep(ji  ,jj)  )  &
-                      &  - MIN( e3zps_min, e3t_1d(misfdep(ji  ,jj)-1)*e3zps_rat )))
-                  IF (zbathydiff .LE. zrisfdepdiff) THEN
-                     mbathy(ji+1,jj)  = mbathy (ji+1,jj) + 1
-                     bathy (ji+1,jj)  = gdepw_1d(mbathy (ji+1,jj)  )  &
-                      &   + MIN( e3zps_min, e3t_1d(mbathy (ji+1,jj) +1)*e3zps_rat )
-                  ELSE
-                     misfdep(ji,jj)   = misfdep(ji  ,jj) - 1
-                     risfdep(ji,jj)   = gdepw_1d(misfdep(ji  ,jj)+1) &
-                      &   - MIN( e3zps_min, e3t_1d(misfdep(ji  ,jj)   )*e3zps_rat )
-                  END IF
-               ENDIF
-            ENDDO
-         ENDDO
- 
-         IF( lk_mpp ) THEN
-            zbathy(:,:) = FLOAT( misfdep(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            misfdep(:,:) = INT( zbathy(:,:) )
-            CALL lbc_lnk( risfdep, 'T', 1. )
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF
-      END DO
-      ! end dig bathy/ice shelf to be compatible
-      ! now fill single point in "coastline" of ice shelf, bathy, hole, and test again one cell tickness
-      DO jl = 1,20
- 
- ! remove single point "bay" on isf coast line in the ice shelf draft'
-         DO jk = 2, jpk
-            WHERE (misfdep==0) misfdep=jpk
-            zmask=0
-            WHERE (misfdep .LE. jk) zmask=1
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  IF (misfdep(ji,jj) .EQ. jk) THEN
-                     ibtest = zmask(ji-1,jj) + zmask(ji+1,jj) + zmask(ji,jj-1) + zmask(ji,jj+1)
-                     IF (ibtest .LE. 1) THEN
-                        risfdep(ji,jj)=gdepw_1d(jk+1) ; misfdep(ji,jj)=jk+1
-                        IF (misfdep(ji,jj) .GT. mbathy(ji,jj)) misfdep(ji,jj) = jpk
-                     END IF
-                  END IF
-               END DO
-            END DO
-         END DO
-         WHERE (misfdep==jpk)
-             misfdep=0 ; risfdep=0. ; mbathy=0 ; bathy=0.
-         END WHERE
-         IF( lk_mpp ) THEN
-            zbathy(:,:) = FLOAT( misfdep(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            misfdep(:,:) = INT( zbathy(:,:) )
-            CALL lbc_lnk( risfdep, 'T', 1. )
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF
- 
- ! remove single point "bay" on bathy coast line beneath an ice shelf'
-         DO jk = jpk,1,-1
-            zmask=0
-            WHERE (mbathy .GE. jk ) zmask=1
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  IF (mbathy(ji,jj) .EQ. jk .AND. misfdep(ji,jj) .GE. 2) THEN
-                     ibtest = zmask(ji-1,jj) + zmask(ji+1,jj) + zmask(ji,jj-1) + zmask(ji,jj+1)
-                     IF (ibtest .LE. 1) THEN
-                        bathy(ji,jj)=gdepw_1d(jk) ; mbathy(ji,jj)=jk-1
-                        IF (misfdep(ji,jj) .GT. mbathy(ji,jj)) mbathy(ji,jj) = 0
-                     END IF
-                  END IF
-               END DO
-            END DO
-         END DO
-         WHERE (mbathy==0)
-             misfdep=0 ; risfdep=0. ; mbathy=0 ; bathy=0.
-         END WHERE
-         IF( lk_mpp ) THEN
-            zbathy(:,:) = FLOAT( misfdep(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            misfdep(:,:) = INT( zbathy(:,:) )
-            CALL lbc_lnk( risfdep, 'T', 1. )
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF
- 
- ! fill hole in ice shelf
-         zmisfdep = misfdep
-         zrisfdep = risfdep
-         WHERE (zmisfdep .LE. 1) zmisfdep=jpk
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-               ibtestim1 = zmisfdep(ji-1,jj  ) ; ibtestip1 = zmisfdep(ji+1,jj  )
-               ibtestjm1 = zmisfdep(ji  ,jj-1) ; ibtestjp1 = zmisfdep(ji  ,jj+1)
-               IF( zmisfdep(ji,jj) .GE. mbathy(ji-1,jj  ) ) ibtestim1 = jpk!MAX(0, mbathy(ji-1,jj  ) - 1)
-               IF( zmisfdep(ji,jj) .GE. mbathy(ji+1,jj  ) ) ibtestip1 = jpk!MAX(0, mbathy(ji+1,jj  ) - 1)
-               IF( zmisfdep(ji,jj) .GE. mbathy(ji  ,jj-1) ) ibtestjm1 = jpk!MAX(0, mbathy(ji  ,jj-1) - 1)
-               IF( zmisfdep(ji,jj) .GE. mbathy(ji  ,jj+1) ) ibtestjp1 = jpk!MAX(0, mbathy(ji  ,jj+1) - 1)
-               ibtest=MIN(ibtestim1, ibtestip1, ibtestjm1, ibtestjp1)
-               IF( ibtest == jpk .AND. misfdep(ji,jj) .GE. 2) THEN
-                  mbathy(ji,jj) = 0 ; bathy(ji,jj) = 0.0_wp ; misfdep(ji,jj) = 0 ; risfdep(ji,jj) = 0.0_wp
-               END IF
-               IF( zmisfdep(ji,jj) < ibtest .AND. misfdep(ji,jj) .GE. 2) THEN
-                  misfdep(ji,jj) = ibtest
-                  risfdep(ji,jj) = gdepw_1d(ibtest)
-               ENDIF
-            ENDDO
-         ENDDO
- 
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- !
- !! fill hole in bathymetry
-         zmbathy (:,:)=mbathy (:,:)
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-               ibtestim1 = zmbathy(ji-1,jj  ) ; ibtestip1 = zmbathy(ji+1,jj  )
-               ibtestjm1 = zmbathy(ji  ,jj-1) ; ibtestjp1 = zmbathy(ji  ,jj+1)
-               IF( zmbathy(ji,jj) .LT. misfdep(ji-1,jj  ) ) ibtestim1 = 0!MIN(jpk-1, misfdep(ji-1,jj  ) + 1)
-               IF( zmbathy(ji,jj) .LT. misfdep(ji+1,jj  ) ) ibtestip1 = 0
-               IF( zmbathy(ji,jj) .LT. misfdep(ji  ,jj-1) ) ibtestjm1 = 0
-               IF( zmbathy(ji,jj) .LT. misfdep(ji  ,jj+1) ) ibtestjp1 = 0
-               ibtest=MAX(ibtestim1, ibtestip1, ibtestjm1, ibtestjp1)
-               IF( ibtest == 0 .AND. misfdep(ji,jj) .GE. 2) THEN
-                  mbathy(ji,jj) = 0 ; bathy(ji,jj) = 0.0_wp ; misfdep(ji,jj) = 0 ; risfdep(ji,jj) = 0.0_wp ;
-               END IF
-               IF( ibtest < zmbathy(ji,jj) .AND. misfdep(ji,jj) .GE. 2) THEN
-                  mbathy(ji,jj) = ibtest
-                  bathy(ji,jj)  = gdepw_1d(ibtest+1) 
-               ENDIF
-            END DO
-         END DO
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- ! if not compatible after all check (ie U point water column less than 2 cells), mask U
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               IF (mbathy(ji,jj) == misfdep(ji+1,jj) .AND. mbathy(ji,jj) .GE. 1 .AND. mbathy(ji+1,jj) .GE. 1) THEN
-                  mbathy(ji,jj)  = mbathy(ji,jj) - 1 ; bathy(ji,jj)   = gdepw_1d(mbathy(ji,jj)+1) ;
-               END IF
-            END DO
-         END DO
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- ! if not compatible after all check (ie U point water column less than 2 cells), mask U
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               IF (misfdep(ji,jj) == mbathy(ji+1,jj) .AND. mbathy(ji,jj) .GE. 1 .AND. mbathy(ji+1,jj) .GE. 1) THEN
-                  mbathy(ji+1,jj)  = mbathy(ji+1,jj) - 1;   bathy(ji+1,jj)   = gdepw_1d(mbathy(ji+1,jj)+1) ;
-               END IF
-            END DO
-         END DO
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- ! if not compatible after all check (ie V point water column less than 2 cells), mask V
-         DO jj = 1, jpjm1
-            DO ji = 1, jpi
-               IF (mbathy(ji,jj) == misfdep(ji,jj+1) .AND. mbathy(ji,jj) .GE. 1 .AND. mbathy(ji,jj+1) .GE. 1) THEN
-                  mbathy(ji,jj)  = mbathy(ji,jj) - 1 ; bathy(ji,jj)   = gdepw_1d(mbathy(ji,jj)+1) ;
-               END IF
-            END DO
-         END DO
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- ! if not compatible after all check (ie V point water column less than 2 cells), mask V
-         DO jj = 1, jpjm1
-            DO ji = 1, jpi
-               IF (misfdep(ji,jj) == mbathy(ji,jj+1) .AND. mbathy(ji,jj) .GE. 1 .AND. mbathy(ji,jj+1) .GE. 1) THEN
-                  mbathy(ji,jj+1)  = mbathy(ji,jj+1) - 1 ; bathy(ji,jj+1)   = gdepw_1d(mbathy(ji,jj+1)+1) ;
-               END IF
-            END DO
-         END DO
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- ! if not compatible after all check, mask T
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF (mbathy(ji,jj) <= misfdep(ji,jj)) THEN
-                  misfdep(ji,jj) = 0 ; risfdep(ji,jj) = 0._wp ; mbathy(ji,jj)  = 0 ; bathy(ji,jj)   = 0._wp ;
-               END IF
-            END DO
-         END DO
- 
-         WHERE (mbathy(:,:) == 1)
-            mbathy = 0; bathy = 0.0_wp ; misfdep = 0 ; risfdep = 0.0_wp
-         END WHERE
-      END DO 
-! end check compatibility ice shelf/bathy
-      ! remove very shallow ice shelf (less than ~ 10m if 75L)
-      WHERE (misfdep(:,:) <= 5)
-         misfdep = 1; risfdep = 0.0_wp;
-      END WHERE
-
-      IF( icompt == 0 ) THEN 
-         IF(lwp) WRITE(numout,*)'     no points with ice shelf too close to bathymetry' 
-      ELSE 
-         IF(lwp) WRITE(numout,*)'    ',icompt,' ocean grid points with ice shelf thickness reduced to avoid bathymetry' 
-      ENDIF 
 
       CALL wrk_dealloc( jpi, jpj, zmask, zbathy, zrisfdep )
       CALL wrk_dealloc( jpi, jpj, zmisfdep, zmbathy )
-
-      IF( nn_timing == 1 )  CALL timing_stop('zgr_isf')
-      
-   END SUBROUTINE
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('zgr_isf')
+      !      
+   END SUBROUTINE zgr_isf
+
 
    SUBROUTINE zgr_sco
@@ -1801,5 +1880,4 @@
       !!
       !!----------------------------------------------------------------------
-      !
       INTEGER  ::   ji, jj, jk, jl           ! dummy loop argument
       INTEGER  ::   iip1, ijp1, iim1, ijm1   ! temporary integers
@@ -1810,12 +1888,12 @@
       REAL(wp), POINTER, DIMENSION(:,:  ) :: ztmpi1, ztmpi2, ztmpj1, ztmpj2
       REAL(wp), POINTER, DIMENSION(:,:  ) :: zenv, ztmp, zmsk, zri, zrj, zhbat
-
+      !!
       NAMELIST/namzgr_sco/ln_s_sh94, ln_s_sf12, ln_sigcrit, rn_sbot_min, rn_sbot_max, rn_hc, rn_rmax,rn_theta, &
-                           rn_thetb, rn_bb, rn_alpha, rn_efold, rn_zs, rn_zb_a, rn_zb_b
+         &                rn_thetb, rn_bb, rn_alpha, rn_efold, rn_zs, rn_zb_a, rn_zb_b
      !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('zgr_sco')
       !
-      CALL wrk_alloc( jpi, jpj, zenv, ztmp, zmsk, zri, zrj, zhbat , ztmpi1, ztmpi2, ztmpj1, ztmpj2 )
+      CALL wrk_alloc( jpi,jpj,   zenv, ztmp, zmsk, zri, zrj, zhbat , ztmpi1, ztmpi2, ztmpj1, ztmpj2 )
       !
       REWIND( numnam_ref )              ! Namelist namzgr_sco in reference namelist : Sigma-stretching parameters
@@ -1876,13 +1954,19 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-           IF( bathy(ji,jj) == 0._wp ) THEN
-             iip1 = MIN( ji+1, jpi )
-             ijp1 = MIN( jj+1, jpj )
-             iim1 = MAX( ji-1, 1 )
-             ijm1 = MAX( jj-1, 1 )
-             IF( (bathy(iip1,jj) + bathy(iim1,jj) + bathy(ji,ijp1) + bathy(ji,ijm1) +              &
-        &         bathy(iip1,ijp1) + bathy(iim1,ijm1) + bathy(iip1,ijp1) + bathy(iim1,ijm1)) > 0._wp ) THEN
-               zenv(ji,jj) = rn_sbot_min
-             ENDIF
+            IF( bathy(ji,jj) == 0._wp ) THEN
+               iip1 = MIN( ji+1, jpi )
+               ijp1 = MIN( jj+1, jpj )
+               iim1 = MAX( ji-1, 1 )
+               ijm1 = MAX( jj-1, 1 )
+!!gm BUG fix see ticket #1617
+               IF( ( + bathy(iim1,ijm1) + bathy(ji,ijp1) + bathy(iip1,ijp1)            &
+                  &  + bathy(iim1,jj  )                  + bathy(iip1,jj  )            &
+                  &  + bathy(iim1,ijm1) + bathy(ji,ijm1) + bathy(iip1,ijp1)  ) > 0._wp )   zenv(ji,jj) = rn_sbot_min
+!!gm
+!!gm               IF( ( bathy(iip1,jj  ) + bathy(iim1,jj  ) + bathy(ji,ijp1  ) + bathy(ji,ijm1) +         &
+!!gm                  &  bathy(iip1,ijp1) + bathy(iim1,ijm1) + bathy(iip1,ijp1) + bathy(iim1,ijm1)) > 0._wp ) THEN
+!!gm               zenv(ji,jj) = rn_sbot_min
+!!gm             ENDIF
+!!gm end
            ENDIF
          END DO
@@ -1975,15 +2059,4 @@
       ENDIF
       !
-      IF(lwp) THEN                             ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) ' domzgr: hbatt field; ocean depth in meters'
-         WRITE(numout,*)
-         CALL prihre( hbatt(1,1), jpi, jpj, 1, jpi, 1, 1, jpj, 1, 0._wp, numout )
-         IF( nprint == 1 )   THEN        
-            WRITE(numout,*) ' bathy  MAX ', MAXVAL( bathy(:,:) ), ' MIN ', MINVAL( bathy(:,:) )
-            WRITE(numout,*) ' hbatt  MAX ', MAXVAL( hbatt(:,:) ), ' MIN ', MINVAL( hbatt(:,:) )
-         ENDIF
-      ENDIF
-
       !                                        ! ==============================
       !                                        !   hbatu, hbatv, hbatf fields
@@ -2080,49 +2153,37 @@
       CALL lbc_lnk( e3uw_0, 'U', 1._wp )
       CALL lbc_lnk( e3vw_0, 'V', 1._wp )
-
-      fsdepw(:,:,:) = gdepw_0 (:,:,:)
-      fsde3w(:,:,:) = gdep3w_0(:,:,:)
-      !
-      where (e3t_0   (:,:,:).eq.0.0)  e3t_0(:,:,:) = 1.0
-      where (e3u_0   (:,:,:).eq.0.0)  e3u_0(:,:,:) = 1.0
-      where (e3v_0   (:,:,:).eq.0.0)  e3v_0(:,:,:) = 1.0
-      where (e3f_0   (:,:,:).eq.0.0)  e3f_0(:,:,:) = 1.0
-      where (e3w_0   (:,:,:).eq.0.0)  e3w_0(:,:,:) = 1.0
-      where (e3uw_0  (:,:,:).eq.0.0)  e3uw_0(:,:,:) = 1.0
-      where (e3vw_0  (:,:,:).eq.0.0)  e3vw_0(:,:,:) = 1.0
+      !
+      WHERE( e3t_0 (:,:,:) == 0._wp )   e3t_0 (:,:,:) = 1._wp
+      WHERE( e3u_0 (:,:,:) == 0._wp )   e3u_0 (:,:,:) = 1._wp
+      WHERE( e3v_0 (:,:,:) == 0._wp )   e3v_0 (:,:,:) = 1._wp
+      WHERE( e3f_0 (:,:,:) == 0._wp )   e3f_0 (:,:,:) = 1._wp
+      WHERE( e3w_0 (:,:,:) == 0._wp )   e3w_0 (:,:,:) = 1._wp
+      WHERE( e3uw_0(:,:,:) == 0._wp )   e3uw_0(:,:,:) = 1._wp
+      WHERE( e3vw_0(:,:,:) == 0._wp )   e3vw_0(:,:,:) = 1._wp
 
 #if defined key_agrif
-      ! Ensure meaningful vertical scale factors in ghost lines/columns
-      IF( .NOT. Agrif_Root() ) THEN
-         !  
-         IF((nbondi == -1).OR.(nbondi == 2)) THEN
-            e3u_0(1,:,:) = e3u_0(2,:,:)
-         ENDIF
-         !
-         IF((nbondi ==  1).OR.(nbondi == 2)) THEN
-            e3u_0(nlci-1,:,:) = e3u_0(nlci-2,:,:)
-         ENDIF
-         !
-         IF((nbondj == -1).OR.(nbondj == 2)) THEN
-            e3v_0(:,1,:) = e3v_0(:,2,:)
-         ENDIF
-         !
-         IF((nbondj ==  1).OR.(nbondj == 2)) THEN
-            e3v_0(:,nlcj-1,:) = e3v_0(:,nlcj-2,:)
-         ENDIF
-         !
-      ENDIF
+      IF( .NOT. Agrif_Root() ) THEN    ! Ensure meaningful vertical scale factors in ghost lines/columns
+         IF( nbondi == -1 .OR. nbondi == 2 )   e3u_0(  1   ,  :   ,:) = e3u_0(  2   ,  :   ,:)
+         IF( nbondi ==  1 .OR. nbondi == 2 )   e3u_0(nlci-1,  :   ,:) = e3u_0(nlci-2,  :   ,:)
+         IF( nbondj == -1 .OR. nbondj == 2 )   e3v_0(  :   ,  1   ,:) = e3v_0(  :   ,  2   ,:)
+         IF( nbondj ==  1 .OR. nbondj == 2 )   e3v_0(  :   ,nlcj-1,:) = e3v_0(  :   ,nlcj-2,:)
+       ENDIF
 #endif
 
-      fsdept(:,:,:) = gdept_0 (:,:,:)
-      fsdepw(:,:,:) = gdepw_0 (:,:,:)
-      fsde3w(:,:,:) = gdep3w_0(:,:,:)
-      fse3t (:,:,:) = e3t_0   (:,:,:)
-      fse3u (:,:,:) = e3u_0   (:,:,:)
-      fse3v (:,:,:) = e3v_0   (:,:,:)
-      fse3f (:,:,:) = e3f_0   (:,:,:)
-      fse3w (:,:,:) = e3w_0   (:,:,:)
-      fse3uw(:,:,:) = e3uw_0  (:,:,:)
-      fse3vw(:,:,:) = e3vw_0  (:,:,:)
+!!gm   I don't like that HERE we are supposed to set the reference coordinate (i.e. _0 arrays)
+!!gm   and only that !!!!!
+!!gm   THIS should be removed from here !
+      gdept_n(:,:,:) = gdept_0(:,:,:)
+      gdepw_n(:,:,:) = gdepw_0(:,:,:)
+      gde3w_n(:,:,:) = gde3w_0(:,:,:)
+      e3t_n  (:,:,:) = e3t_0  (:,:,:)
+      e3u_n  (:,:,:) = e3u_0  (:,:,:)
+      e3v_n  (:,:,:) = e3v_0  (:,:,:)
+      e3f_n  (:,:,:) = e3f_0  (:,:,:)
+      e3w_n  (:,:,:) = e3w_0  (:,:,:)
+      e3uw_n (:,:,:) = e3uw_0 (:,:,:)
+      e3vw_n (:,:,:) = e3vw_0 (:,:,:)
+!!gm and obviously in the following, use the _0 arrays until the end of this subroutine
+!! gm end
 !!
       ! HYBRID : 
@@ -2130,7 +2191,7 @@
          DO ji = 1, jpi
             DO jk = 1, jpkm1
-               IF( scobot(ji,jj) >= fsdept(ji,jj,jk) )   mbathy(ji,jj) = MAX( 2, jk )
-            END DO
-            IF( scobot(ji,jj) == 0._wp               )   mbathy(ji,jj) = 0
+               IF( scobot(ji,jj) >= gdept_n(ji,jj,jk) )   mbathy(ji,jj) = MAX( 2, jk )
+            END DO
+            IF( scobot(ji,jj) == 0._wp                )   mbathy(ji,jj) = 0
          END DO
       END DO
@@ -2141,15 +2202,15 @@
          WRITE(numout,*) ' MIN val mbathy  ', MINVAL( mbathy(:,:)    ), ' MAX ', MAXVAL( mbathy(:,:) )
          WRITE(numout,*) ' MIN val depth t ', MINVAL( gdept_0(:,:,:) ),   &
-            &                          ' w ', MINVAL( gdepw_0(:,:,:) ), '3w '  , MINVAL( gdep3w_0(:,:,:) )
-         WRITE(numout,*) ' MIN val e3    t ', MINVAL( e3t_0  (:,:,:) ), ' f '  , MINVAL( e3f_0   (:,:,:) ),   &
-            &                          ' u ', MINVAL( e3u_0  (:,:,:) ), ' u '  , MINVAL( e3v_0   (:,:,:) ),   &
-            &                          ' uw', MINVAL( e3uw_0 (:,:,:) ), ' vw'  , MINVAL( e3vw_0  (:,:,:) ),   &
+            &                          ' w ', MINVAL( gdepw_0(:,:,:) ), '3w '  , MINVAL( gde3w_0(:,:,:) )
+         WRITE(numout,*) ' MIN val e3    t ', MINVAL( e3t_0  (:,:,:) ), ' f '  , MINVAL( e3f_0  (:,:,:) ),   &
+            &                          ' u ', MINVAL( e3u_0  (:,:,:) ), ' u '  , MINVAL( e3v_0  (:,:,:) ),   &
+            &                          ' uw', MINVAL( e3uw_0 (:,:,:) ), ' vw'  , MINVAL( e3vw_0 (:,:,:) ),   &
             &                          ' w ', MINVAL( e3w_0  (:,:,:) )
 
          WRITE(numout,*) ' MAX val depth t ', MAXVAL( gdept_0(:,:,:) ),   &
-            &                          ' w ', MAXVAL( gdepw_0(:,:,:) ), '3w '  , MAXVAL( gdep3w_0(:,:,:) )
-         WRITE(numout,*) ' MAX val e3    t ', MAXVAL( e3t_0  (:,:,:) ), ' f '  , MAXVAL( e3f_0   (:,:,:) ),   &
-            &                          ' u ', MAXVAL( e3u_0  (:,:,:) ), ' u '  , MAXVAL( e3v_0   (:,:,:) ),   &
-            &                          ' uw', MAXVAL( e3uw_0 (:,:,:) ), ' vw'  , MAXVAL( e3vw_0  (:,:,:) ),   &
+            &                          ' w ', MAXVAL( gdepw_0(:,:,:) ), '3w '  , MAXVAL( gde3w_0(:,:,:) )
+         WRITE(numout,*) ' MAX val e3    t ', MAXVAL( e3t_0  (:,:,:) ), ' f '  , MAXVAL( e3f_0  (:,:,:) ),   &
+            &                          ' u ', MAXVAL( e3u_0  (:,:,:) ), ' u '  , MAXVAL( e3v_0  (:,:,:) ),   &
+            &                          ' uw', MAXVAL( e3uw_0 (:,:,:) ), ' vw'  , MAXVAL( e3vw_0 (:,:,:) ),   &
             &                          ' w ', MAXVAL( e3w_0  (:,:,:) )
       ENDIF
@@ -2183,50 +2244,48 @@
          END DO
       ENDIF
-
-!================================================================================
-! check the coordinate makes sense
-!================================================================================
+      !
+      !================================================================================
+      ! check the coordinate makes sense
+      !================================================================================
       DO ji = 1, jpi
          DO jj = 1, jpj
-
+            !
             IF( hbatt(ji,jj) > 0._wp) THEN
                DO jk = 1, mbathy(ji,jj)
                  ! check coordinate is monotonically increasing
-                 IF (fse3w(ji,jj,jk) <= 0._wp .OR. fse3t(ji,jj,jk) <= 0._wp ) THEN
+                 IF (e3w_n(ji,jj,jk) <= 0._wp .OR. e3t_n(ji,jj,jk) <= 0._wp ) THEN
                     WRITE(ctmp1,*) 'ERROR zgr_sco :   e3w   or e3t   =< 0  at point (i,j,k)= ', ji, jj, jk
                     WRITE(numout,*) 'ERROR zgr_sco :   e3w   or e3t   =< 0  at point (i,j,k)= ', ji, jj, jk
-                    WRITE(numout,*) 'e3w',fse3w(ji,jj,:)
-                    WRITE(numout,*) 'e3t',fse3t(ji,jj,:)
+                    WRITE(numout,*) 'e3w',e3w_n(ji,jj,:)
+                    WRITE(numout,*) 'e3t',e3t_n(ji,jj,:)
                     CALL ctl_stop( ctmp1 )
                  ENDIF
                  ! and check it has never gone negative
-                 IF( fsdepw(ji,jj,jk) < 0._wp .OR. fsdept(ji,jj,jk) < 0._wp ) THEN
+                 IF( gdepw_n(ji,jj,jk) < 0._wp .OR. gdept_n(ji,jj,jk) < 0._wp ) THEN
                     WRITE(ctmp1,*) 'ERROR zgr_sco :   gdepw or gdept =< 0  at point (i,j,k)= ', ji, jj, jk
                     WRITE(numout,*) 'ERROR zgr_sco :   gdepw   or gdept   =< 0  at point (i,j,k)= ', ji, jj, jk
-                    WRITE(numout,*) 'gdepw',fsdepw(ji,jj,:)
-                    WRITE(numout,*) 'gdept',fsdept(ji,jj,:)
+                    WRITE(numout,*) 'gdepw',gdepw_n(ji,jj,:)
+                    WRITE(numout,*) 'gdept',gdept_n(ji,jj,:)
                     CALL ctl_stop( ctmp1 )
                  ENDIF
                  ! and check it never exceeds the total depth
-                 IF( fsdepw(ji,jj,jk) > hbatt(ji,jj) ) THEN
+                 IF( gdepw_n(ji,jj,jk) > hbatt(ji,jj) ) THEN
                     WRITE(ctmp1,*) 'ERROR zgr_sco :   gdepw > hbatt  at point (i,j,k)= ', ji, jj, jk
                     WRITE(numout,*) 'ERROR zgr_sco :   gdepw > hbatt  at point (i,j,k)= ', ji, jj, jk
-                    WRITE(numout,*) 'gdepw',fsdepw(ji,jj,:)
+                    WRITE(numout,*) 'gdepw',gdepw_n(ji,jj,:)
                     CALL ctl_stop( ctmp1 )
                  ENDIF
                END DO
-
+               !
                DO jk = 1, mbathy(ji,jj)-1
                  ! and check it never exceeds the total depth
-                IF( fsdept(ji,jj,jk) > hbatt(ji,jj) ) THEN
+                IF( gdept_n(ji,jj,jk) > hbatt(ji,jj) ) THEN
                     WRITE(ctmp1,*) 'ERROR zgr_sco :   gdept > hbatt  at point (i,j,k)= ', ji, jj, jk
                     WRITE(numout,*) 'ERROR zgr_sco :   gdept > hbatt  at point (i,j,k)= ', ji, jj, jk
-                    WRITE(numout,*) 'gdept',fsdept(ji,jj,:)
+                    WRITE(numout,*) 'gdept',gdept_n(ji,jj,:)
                     CALL ctl_stop( ctmp1 )
                  ENDIF
                END DO
-
             ENDIF
-
          END DO
       END DO
@@ -2238,7 +2297,6 @@
    END SUBROUTINE zgr_sco
 
-!!======================================================================
+
    SUBROUTINE s_sh94()
-
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE s_sh94  ***
@@ -2251,5 +2309,4 @@
       !! Reference : Song and Haidvogel 1994. 
       !!----------------------------------------------------------------------
-      !
       INTEGER  ::   ji, jj, jk           ! dummy loop argument
       REAL(wp) ::   zcoeft, zcoefw   ! temporary scalars
@@ -2257,7 +2314,8 @@
       REAL(wp), POINTER, DIMENSION(:,:,:) :: z_gsigw3, z_gsigt3, z_gsi3w3
       REAL(wp), POINTER, DIMENSION(:,:,:) :: z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3           
-
-      CALL wrk_alloc( jpi, jpj, jpk, z_gsigw3, z_gsigt3, z_gsi3w3                                      )
-      CALL wrk_alloc( jpi, jpj, jpk, z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3 )
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi,jpj,jpk,   z_gsigw3, z_gsigt3, z_gsi3w3                                      )
+      CALL wrk_alloc( jpi,jpj,jpk,   z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3 )
 
       z_gsigw3  = 0._wp   ;   z_gsigt3  = 0._wp   ;   z_gsi3w3  = 0._wp
@@ -2265,8 +2323,8 @@
       z_esigtu3 = 0._wp   ;   z_esigtv3 = 0._wp   ;   z_esigtf3 = 0._wp
       z_esigwu3 = 0._wp   ;   z_esigwv3 = 0._wp
-
+      !
       DO ji = 1, jpi
          DO jj = 1, jpj
-
+            !
             IF( hbatt(ji,jj) > rn_hc ) THEN    !deep water, stretched sigma
                DO jk = 1, jpk
@@ -2297,7 +2355,7 @@
                zcoeft = ( REAL(jk,wp) - 0.5_wp ) / REAL(jpkm1,wp)
                zcoefw = ( REAL(jk,wp) - 1.0_wp ) / REAL(jpkm1,wp)
-               gdept_0 (ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsigt3(ji,jj,jk)+rn_hc*zcoeft )
-               gdepw_0 (ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsigw3(ji,jj,jk)+rn_hc*zcoefw )
-               gdep3w_0(ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsi3w3(ji,jj,jk)+rn_hc*zcoeft )
+               gdept_0(ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsigt3(ji,jj,jk)+rn_hc*zcoeft )
+               gdepw_0(ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsigw3(ji,jj,jk)+rn_hc*zcoefw )
+               gde3w_0(ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsi3w3(ji,jj,jk)+rn_hc*zcoeft )
             END DO
            !
@@ -2331,12 +2389,12 @@
         END DO
       END DO
-
-      CALL wrk_dealloc( jpi, jpj, jpk, z_gsigw3, z_gsigt3, z_gsi3w3                                      )
-      CALL wrk_dealloc( jpi, jpj, jpk, z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3 )
-
+      !
+      CALL wrk_dealloc( jpi,jpj,jpk,   z_gsigw3, z_gsigt3, z_gsi3w3                                      )
+      CALL wrk_dealloc( jpi,jpj,jpk,   z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3 )
+      !
    END SUBROUTINE s_sh94
 
+
    SUBROUTINE s_sf12
-
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE s_sf12 *** 
@@ -2354,5 +2412,4 @@
       !! Reference : Siddorn and Furner 2012 (submitted Ocean modelling).
       !!----------------------------------------------------------------------
-      !
       INTEGER  ::   ji, jj, jk           ! dummy loop argument
       REAL(wp) ::   zsmth               ! smoothing around critical depth
@@ -2361,5 +2418,5 @@
       REAL(wp), POINTER, DIMENSION(:,:,:) :: z_gsigw3, z_gsigt3, z_gsi3w3
       REAL(wp), POINTER, DIMENSION(:,:,:) :: z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3           
-
+      !!----------------------------------------------------------------------
       !
       CALL wrk_alloc( jpi, jpj, jpk, z_gsigw3, z_gsigt3, z_gsi3w3                                      )
@@ -2425,7 +2482,7 @@
 
           DO jk = 1, jpk
-             gdept_0 (ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsigt3(ji,jj,jk)
-             gdepw_0 (ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsigw3(ji,jj,jk)
-             gdep3w_0(ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsi3w3(ji,jj,jk)
+             gdept_0(ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsigt3(ji,jj,jk)
+             gdepw_0(ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsigw3(ji,jj,jk)
+             gde3w_0(ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsi3w3(ji,jj,jk)
           END DO
 
@@ -2454,5 +2511,5 @@
              e3f_0(ji,jj,jk)=(scosrf(ji,jj)+hbatf(ji,jj))*z_esigtf3(ji,jj,jk)
              !
-             e3w_0(ji,jj,jk)=hbatt(ji,jj)*z_esigw3(ji,jj,jk)
+             e3w_0 (ji,jj,jk)=hbatt(ji,jj)*z_esigw3(ji,jj,jk)
              e3uw_0(ji,jj,jk)=hbatu(ji,jj)*z_esigwu3(ji,jj,jk)
              e3vw_0(ji,jj,jk)=hbatv(ji,jj)*z_esigwv3(ji,jj,jk)
@@ -2467,13 +2524,11 @@
       CALL lbc_lnk(e3uw_0,'T',1.) ; CALL lbc_lnk(e3vw_0,'T',1.)
       !
-      !                                               ! =============
-
-      CALL wrk_dealloc( jpi, jpj, jpk, z_gsigw3, z_gsigt3, z_gsi3w3                                      )
-      CALL wrk_dealloc( jpi, jpj, jpk, z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3 )
-
+      CALL wrk_dealloc( jpi,jpj,jpk,   z_gsigw3, z_gsigt3, z_gsi3w3                                      )
+      CALL wrk_dealloc( jpi,jpj,jpk,   z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3 )
+      !
    END SUBROUTINE s_sf12
 
+
    SUBROUTINE s_tanh()
-
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE s_tanh*** 
@@ -2485,13 +2540,12 @@
       !! Reference : Madec, Lott, Delecluse and Crepon, 1996. JPO, 26, 1393-1408.
       !!----------------------------------------------------------------------
-
-      INTEGER  ::   ji, jj, jk           ! dummy loop argument
+      INTEGER  ::   ji, jj, jk       ! dummy loop argument
       REAL(wp) ::   zcoeft, zcoefw   ! temporary scalars
-
       REAL(wp), POINTER, DIMENSION(:) :: z_gsigw, z_gsigt, z_gsi3w
       REAL(wp), POINTER, DIMENSION(:) :: z_esigt, z_esigw
-
-      CALL wrk_alloc( jpk, z_gsigw, z_gsigt, z_gsi3w                                      )
-      CALL wrk_alloc( jpk, z_esigt, z_esigw                                               )
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpk,   z_gsigw, z_gsigt, z_gsi3w )
+      CALL wrk_alloc( jpk,   z_esigt, z_esigw )
 
       z_gsigw  = 0._wp   ;   z_gsigt  = 0._wp   ;   z_gsi3w  = 0._wp
@@ -2523,7 +2577,7 @@
          zcoeft = ( REAL(jk,wp) - 0.5_wp ) / REAL(jpkm1,wp)
          zcoefw = ( REAL(jk,wp) - 1.0_wp ) / REAL(jpkm1,wp)
-         gdept_0 (:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsigt(jk) + hift(:,:)*zcoeft )
-         gdepw_0 (:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsigw(jk) + hift(:,:)*zcoefw )
-         gdep3w_0(:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsi3w(jk) + hift(:,:)*zcoeft )
+         gdept_0(:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsigt(jk) + hift(:,:)*zcoeft )
+         gdepw_0(:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsigw(jk) + hift(:,:)*zcoefw )
+         gde3w_0(:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsi3w(jk) + hift(:,:)*zcoeft )
       END DO
 !!gm: e3uw, e3vw can be suppressed  (modif in dynzdf, dynzdf_iso, zdfbfr) (save 2 3D arrays)
@@ -2542,9 +2596,10 @@
          END DO
       END DO
-
-      CALL wrk_dealloc( jpk, z_gsigw, z_gsigt, z_gsi3w                                      )
-      CALL wrk_dealloc( jpk, z_esigt, z_esigw                                               )
-
+      !
+      CALL wrk_dealloc( jpk,   z_gsigw, z_gsigt, z_gsi3w )
+      CALL wrk_dealloc( jpk,   z_esigt, z_esigw          )
+      !
    END SUBROUTINE s_tanh
+
 
    FUNCTION fssig( pk ) RESULT( pf )
@@ -2618,33 +2673,32 @@
       REAL(wp), INTENT(in   ) ::   pk1(jpk)       ! continuous "k" coordinate
       REAL(wp)                ::   p_gamma(jpk)   ! stretched coordinate
-      REAL(wp), INTENT(in   ) ::   pzb           ! Bottom box depth
-      REAL(wp), INTENT(in   ) ::   pzs           ! surface box depth
-      REAL(wp), INTENT(in   ) ::   psmth       ! Smoothing parameter
-      REAL(wp)                ::   za1,za2,za3    ! local variables
-      REAL(wp)                ::   zn1,zn2        ! local variables
-      REAL(wp)                ::   za,zb,zx       ! local variables
-      integer                 ::   jk
-      !!----------------------------------------------------------------------
-      !
-
-      zn1  =  1./(jpk-1.)
-      zn2  =  1. -  zn1
-
+      REAL(wp), INTENT(in   ) ::   pzb            ! Bottom box depth
+      REAL(wp), INTENT(in   ) ::   pzs            ! surface box depth
+      REAL(wp), INTENT(in   ) ::   psmth          ! Smoothing parameter
+      !
+      INTEGER  ::   jk             ! dummy loop index
+      REAL(wp) ::   za1,za2,za3    ! local scalar
+      REAL(wp) ::   zn1,zn2        !   -      - 
+      REAL(wp) ::   za,zb,zx       !   -      - 
+      !!----------------------------------------------------------------------
+      !
+      zn1  =  1._wp / REAL( jpkm1, wp )
+      zn2  =  1._wp -  zn1
+      !
       za1 = (rn_alpha+2.0_wp)*zn1**(rn_alpha+1.0_wp)-(rn_alpha+1.0_wp)*zn1**(rn_alpha+2.0_wp) 
       za2 = (rn_alpha+2.0_wp)*zn2**(rn_alpha+1.0_wp)-(rn_alpha+1.0_wp)*zn2**(rn_alpha+2.0_wp)
       za3 = (zn2**3.0_wp - za2)/( zn1**3.0_wp - za1)
-     
+      !
       za = pzb - za3*(pzs-za1)-za2
       za = za/( zn2-0.5_wp*(za2+zn2**2.0_wp) - za3*(zn1-0.5_wp*(za1+zn1**2.0_wp) ) )
       zb = (pzs - za1 - za*( zn1-0.5_wp*(za1+zn1**2.0_wp ) ) ) / (zn1**3.0_wp - za1)
       zx = 1.0_wp-za/2.0_wp-zb
- 
+      !
       DO jk = 1, jpk
-        p_gamma(jk) = za*(pk1(jk)*(1.0_wp-pk1(jk)/2.0_wp))+zb*pk1(jk)**3.0_wp +  &
-                    & zx*( (rn_alpha+2.0_wp)*pk1(jk)**(rn_alpha+1.0_wp)- &
-                    &      (rn_alpha+1.0_wp)*pk1(jk)**(rn_alpha+2.0_wp) )
+         p_gamma(jk) = za*(pk1(jk)*(1.0_wp-pk1(jk)/2.0_wp))+zb*pk1(jk)**3.0_wp +  &
+            &          zx*( (rn_alpha+2.0_wp)*pk1(jk)**(rn_alpha+1.0_wp)- &
+            &               (rn_alpha+1.0_wp)*pk1(jk)**(rn_alpha+2.0_wp) )
         p_gamma(jk) = p_gamma(jk)*psmth+pk1(jk)*(1.0_wp-psmth)
-      ENDDO 
-
+      END DO
       !
    END FUNCTION fgamma
Index: unk/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr_substitute.h90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr_substitute.h90	(revision 6139)
+++ 	(revision )
@@ -1,122 +1,0 @@
-   !!----------------------------------------------------------------------
-   !!                    ***  domzgr_substitute.h90   ***
-   !!----------------------------------------------------------------------
-   !! ** purpose :   substitute fsdep. and fse.., the vert. depth and scale
-   !!      factors depending on the vertical coord. used, using CPP macro.
-   !!----------------------------------------------------------------------
-   !! History :  1.0  !  2005-10  (A. Beckmann, G. Madec) generalisation to all coord.
-   !!            3.1  !  2009-02  (G. Madec, M. Leclair)  pure z* coordinate
-   !!----------------------------------------------------------------------
-
-#if defined key_vvl
-! s* or z*-coordinate (3D + time dependency) + use of additional now arrays (..._n)
-
-#   define  fse3t_b(i,j,k)   e3t_b(i,j,k)
-#   define  fse3u_b(i,j,k)   e3u_b(i,j,k)
-#   define  fse3v_b(i,j,k)   e3v_b(i,j,k)
-#   define  fse3uw_b(i,j,k)  e3uw_b(i,j,k)
-#   define  fse3vw_b(i,j,k)  e3vw_b(i,j,k)
-
-#   define  fsdept_n(i,j,k)  gdept_n(i,j,k)
-#   define  fsdepw_n(i,j,k)  gdepw_n(i,j,k)
-#   define  fsde3w_n(i,j,k)  gdep3w_n(i,j,k)
-#   define  fse3t_n(i,j,k)   e3t_n(i,j,k)
-#   define  fse3u_n(i,j,k)   e3u_n(i,j,k)
-#   define  fse3v_n(i,j,k)   e3v_n(i,j,k)
-#   define  fse3f_n(i,j,k)   e3f_n(i,j,k)
-#   define  fse3w_n(i,j,k)   e3w_n(i,j,k)
-#   define  fse3uw_n(i,j,k)  e3uw_n(i,j,k)
-#   define  fse3vw_n(i,j,k)  e3vw_n(i,j,k)
-
-#   define  fsdept_b(i,j,k)  gdept_b(i,j,k)
-#   define  fsdepw_b(i,j,k)  gdepw_b(i,j,k)
-#   define  fse3w_b(i,j,k)   e3w_b(i,j,k)
-
-#   define  fse3t_a(i,j,k)   e3t_a(i,j,k)
-#   define  fse3u_a(i,j,k)   e3u_a(i,j,k)
-#   define  fse3v_a(i,j,k)   e3v_a(i,j,k)
-
-#   define  fse3t_m(i,j)     e3t_m(i,j)
-
-#   define  hu_a(i,j)        ehu_a(i,j)
-#   define  hur_a(i,j)       ehur_a(i,j)
-#   define  hv_a(i,j)        ehv_a(i,j)
-#   define  hvr_a(i,j)       ehvr_a(i,j)
-#   define  hu_b(i,j)        ehu_b(i,j)
-#   define  hur_b(i,j)       ehur_b(i,j)
-#   define  hv_b(i,j)        ehv_b(i,j)
-#   define  hvr_b(i,j)       ehvr_b(i,j)
-
-! This part should be removed one day ...
-! ... In that case all occurence of the above statement functions
-!     have to be replaced in the code by xxx_n
-#   define  fsdept(i,j,k)    gdept_n(i,j,k)
-#   define  fsdepw(i,j,k)    gdepw_n(i,j,k)
-#   define  fsde3w(i,j,k)    gdep3w_n(i,j,k)
-#   define  fse3t(i,j,k)     e3t_n(i,j,k) 
-#   define  fse3u(i,j,k)     e3u_n(i,j,k) 
-#   define  fse3v(i,j,k)     e3v_n(i,j,k) 
-#   define  fse3f(i,j,k)     e3f_n(i,j,k) 
-#   define  fse3w(i,j,k)     e3w_n(i,j,k) 
-#   define  fse3uw(i,j,k)    e3uw_n(i,j,k)
-#   define  fse3vw(i,j,k)    e3vw_n(i,j,k)
-
-#else
-! z- or s-coordinate (1D or 3D + no time dependency) use reference in all cases
-
-#   define  fse3t_b(i,j,k)   e3t_0(i,j,k)
-#   define  fse3u_b(i,j,k)   e3u_0(i,j,k)
-#   define  fse3v_b(i,j,k)   e3v_0(i,j,k)
-#   define  fse3uw_b(i,j,k)  e3uw_0(i,j,k)
-#   define  fse3vw_b(i,j,k)  e3vw_0(i,j,k)
-
-#   define  fsdept_n(i,j,k)  gdept_0(i,j,k)
-#   define  fsdepw_n(i,j,k)  gdepw_0(i,j,k)
-#   define  fsde3w_n(i,j,k)  gdep3w_0(i,j,k)
-#   define  fse3t_n(i,j,k)   e3t_0(i,j,k)
-#   define  fse3u_n(i,j,k)   e3u_0(i,j,k)
-#   define  fse3v_n(i,j,k)   e3v_0(i,j,k)
-#   define  fse3f_n(i,j,k)   e3f_0(i,j,k)
-#   define  fse3w_n(i,j,k)   e3w_0(i,j,k)
-#   define  fse3uw_n(i,j,k)  e3uw_0(i,j,k)
-#   define  fse3vw_n(i,j,k)  e3vw_0(i,j,k)
-
-#   define  fsdept_b(i,j,k)  gdept_0(i,j,k)
-#   define  fsdepw_b(i,j,k)  gdepw_0(i,j,k)
-#   define  fse3w_b(i,j,k)   e3w_0(i,j,k)
-
-#   define  fse3t_a(i,j,k)   e3t_0(i,j,k)
-#   define  fse3u_a(i,j,k)   e3u_0(i,j,k)
-#   define  fse3v_a(i,j,k)   e3v_0(i,j,k)
-
-#   define  fse3t_m(i,j)     e3t_0(i,j,1)
-
-#   define  hu_a(i,j)        hu(i,j)
-#   define  hur_a(i,j)       hur(i,j)
-#   define  hv_a(i,j)        hv(i,j)
-#   define  hvr_a(i,j)       hvr(i,j)
-#   define  hu_b(i,j)        hu(i,j)
-#   define  hur_b(i,j)       hur(i,j)
-#   define  hv_b(i,j)        hv(i,j)
-#   define  hvr_b(i,j)       hvr(i,j)
-
-! This part should be removed one day ...
-! ... In that case all occurence of the above statement functions
-!     have to be replaced in the code by xxx_n
-#   define  fsdept(i,j,k)    gdept_0(i,j,k)
-#   define  fsdepw(i,j,k)    gdepw_0(i,j,k)
-#   define  fsde3w(i,j,k)    gdep3w_0(i,j,k)
-#   define  fse3t(i,j,k)     e3t_0(i,j,k)
-#   define  fse3u(i,j,k)     e3u_0(i,j,k)
-#   define  fse3v(i,j,k)     e3v_0(i,j,k)
-#   define  fse3f(i,j,k)     e3f_0(i,j,k)
-#   define  fse3w(i,j,k)     e3w_0(i,j,k)
-#   define  fse3uw(i,j,k)    e3uw_0(i,j,k)
-#   define  fse3vw(i,j,k)    e3vw_0(i,j,k)
-
-#endif
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/dtatsd.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/dtatsd.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/dtatsd.F90	(revision 6140)
@@ -35,6 +35,4 @@
    TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_tsd   ! structure of input SST (file informations, fields read)
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -250,25 +248,4 @@
       ENDIF
       !
-      IF( lwp .AND. kt == nit000 ) THEN
-         WRITE(numout,*) ' temperature Levitus '
-         WRITE(numout,*)
-         WRITE(numout,*)'  level = 1'
-         CALL prihre( ptsd(:,:,1    ,jp_tem), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-         WRITE(numout,*)'  level = ', jpk/2
-         CALL prihre( ptsd(:,:,jpk/2,jp_tem), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-         WRITE(numout,*)'  level = ', jpkm1
-         CALL prihre( ptsd(:,:,jpkm1,jp_tem), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-         WRITE(numout,*)
-         WRITE(numout,*) ' salinity Levitus '
-         WRITE(numout,*)
-         WRITE(numout,*)'  level = 1'
-         CALL prihre( ptsd(:,:,1    ,jp_sal), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-         WRITE(numout,*)'  level = ', jpk/2
-         CALL prihre( ptsd(:,:,jpk/2,jp_sal), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-         WRITE(numout,*)'  level = ', jpkm1
-         CALL prihre( ptsd(:,:,jpkm1,jp_sal), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-         WRITE(numout,*)
-      ENDIF
-      !
       IF( .NOT.ln_tsd_tradmp ) THEN                   !==   deallocate T & S structure   ==! 
          !                                              (data used only for initialisation)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/iscplhsb.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/iscplhsb.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/iscplhsb.F90	(revision 6140)
@@ -0,0 +1,321 @@
+MODULE iscplhsb
+   !!======================================================================
+   !!                       ***  MODULE  iscplhsb***
+   !! Ocean forcing: ice sheet/ocean coupling (conservation)
+   !!=====================================================================
+   !! History :  NEMO  ! 2015-01 P. Mathiot: original 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   iscpl_alloc    : variable allocation
+   !!   iscpl_hsb      : compute and store the input of heat/salt/volume 
+   !!                    into the system due to the coupling process
+   !!   iscpl_div      : correction of divergence to keep volume conservation
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE domwri          ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE sbc_oce         ! surface boundary condition variables
+   USE oce             ! global tra/dyn variable
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! MPP library
+   USE lib_fortran     ! MPP library
+   USE wrk_nemo        ! Memory allocation
+   USE lbclnk          !
+   USE domngb          !
+   USE iscplini
+
+   IMPLICIT NONE
+   PRIVATE
+   
+   PUBLIC   iscpl_div   
+   PUBLIC   iscpl_cons       
+   !! * Substitutions  
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: sbcrnf.F90 4666 2014-06-11 12:52:23Z mathiot $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE iscpl_cons(ptmask_b, psmask_b, pe3t_b, pts_flx, pvol_flx, prdt_iscpl)
+      !!---------------------------------------------------------------------- 
+      !!                   ***  ROUTINE iscpl_cons  ***
+      !! 
+      !! ** Purpose :   compute input into the system during the coupling step
+      !!                compute the correction term
+      !!                compute where the correction have to be applied
+      !! 
+      !! ** Method  :   compute tsn*e3t-tsb*e3tb and e3t-e3t_b
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:  ), INTENT(in ) :: ptmask_b    !! mask before
+      REAL(wp), DIMENSION(:,:,:  ), INTENT(in ) :: pe3t_b      !! scale factor before
+      REAL(wp), DIMENSION(:,:    ), INTENT(in ) :: psmask_b    !! mask before
+      REAL(wp), DIMENSION(:,:,:,:), INTENT(out) :: pts_flx     !! corrective flux to have tracer conservation
+      REAL(wp), DIMENSION(:,:,:  ), INTENT(out) :: pvol_flx    !! corrective flux to have volume conservation
+      REAL(wp),                     INTENT(in ) :: prdt_iscpl  !! coupling period 
+      !!
+      INTEGER :: ji, jj, jk                                    !! loop index
+      INTEGER :: jip1, jim1, jjp1, jjm1
+      !!
+      REAL(wp):: summsk, zsum, zsum1, zarea, zsumn, zsumb
+      REAL(wp):: r1_rdtiscpl
+      REAL(wp):: zjip1_ratio  , zjim1_ratio  , zjjp1_ratio  , zjjm1_ratio
+      !!
+      REAL(wp):: zde3t, zdtem, zdsal
+      REAL(wp), DIMENSION(:,:), POINTER :: zdssh
+      !!
+      REAL(wp), DIMENSION(:), ALLOCATABLE :: zlon, zlat
+      REAL(wp), DIMENSION(:), ALLOCATABLE :: zcorr_vol, zcorr_tem, zcorr_sal
+      INTEGER , DIMENSION(:), ALLOCATABLE :: ixpts, iypts, izpts, inpts
+      INTEGER :: jpts, npts
+
+      CALL wrk_alloc(jpi,jpj, zdssh )
+
+      ! get imbalance (volume heat and salt)
+      ! initialisation difference
+      zde3t = 0.0_wp; zdsal = 0.0_wp ; zdtem = 0.0_wp
+
+      ! initialisation correction term
+      pvol_flx(:,:,:  ) = 0.0_wp
+      pts_flx (:,:,:,:) = 0.0_wp
+      
+      r1_rdtiscpl = 1._wp / prdt_iscpl 
+
+      ! mask tsn and tsb 
+      tsb(:,:,:,jp_tem)=tsb(:,:,:,jp_tem)*ptmask_b(:,:,:); tsn(:,:,:,jp_tem)=tsn(:,:,:,jp_tem)*tmask(:,:,:);
+      tsb(:,:,:,jp_sal)=tsb(:,:,:,jp_sal)*ptmask_b(:,:,:); tsn(:,:,:,jp_sal)=tsn(:,:,:,jp_sal)*tmask(:,:,:);
+
+      !==============================================================================
+      ! diagnose the heat, salt and volume input and compute the correction variable
+      !==============================================================================
+
+      ! 
+      zdssh(:,:) = sshn(:,:) * ssmask(:,:) - sshb(:,:) * psmask_b(:,:)
+      IF (.NOT. ln_linssh ) zdssh = 0.0_wp ! already included in the levels by definition
+      
+      DO jk = 1,jpk-1
+         DO jj = 2,jpj-1
+            DO ji = fs_2,fs_jpim1
+               IF (tmask_h(ji,jj) == 1._wp) THEN
+
+                  ! volume differences
+                  zde3t = e3t_n(ji,jj,jk) * tmask(ji,jj,jk) - pe3t_b(ji,jj,jk) * ptmask_b(ji,jj,jk)
+
+                  ! heat diff
+                  zdtem = tsn(ji,jj,jk,jp_tem) * e3t_n(ji,jj,jk) *  tmask  (ji,jj,jk)   &
+                        - tsb(ji,jj,jk,jp_tem) * pe3t_b (ji,jj,jk) * ptmask_b(ji,jj,jk)
+                  ! salt diff
+                  zdsal = tsn(ji,jj,jk,jp_sal) * e3t_n(ji,jj,jk) *  tmask  (ji,jj,jk)   &
+                        - tsb(ji,jj,jk,jp_sal) * pe3t_b (ji,jj,jk) * ptmask_b(ji,jj,jk)
+               
+                  ! shh changes
+                  IF ( ptmask_b(ji,jj,jk) == 1._wp .OR. tmask(ji,jj,jk) == 1._wp ) THEN 
+                     zde3t = zde3t + zdssh(ji,jj) ! zdssh = 0 if vvl
+                     zdssh(ji,jj) = 0._wp
+                  END IF
+
+                  ! volume, heat and salt differences in each cell 
+                  pvol_flx(ji,jj,jk)       =   pvol_flx(ji,jj,jk)        + zde3t * r1_rdtiscpl
+                  pts_flx (ji,jj,jk,jp_sal)=   pts_flx (ji,jj,jk,jp_sal) + zdsal * r1_rdtiscpl 
+                  pts_flx (ji,jj,jk,jp_tem)=   pts_flx (ji,jj,jk,jp_tem) + zdtem * r1_rdtiscpl
+
+                  ! case where we close a cell: check if the neighbour cells are wet 
+                  IF ( tmask(ji,jj,jk) == 0._wp .AND. ptmask_b(ji,jj,jk) == 1._wp ) THEN
+
+                     jip1=ji+1 ; jim1=ji-1 ; jjp1=jj+1 ; jjm1=jj-1 ;
+
+                     zsum =   e1e2t(ji  ,jjp1) * tmask(ji  ,jjp1,jk) + e1e2t(ji  ,jjm1) * tmask(ji  ,jjm1,jk) &
+                       &    + e1e2t(jim1,jj  ) * tmask(jim1,jj  ,jk) + e1e2t(jip1,jj  ) * tmask(jip1,jj  ,jk)
+
+                     IF ( zsum /= 0._wp ) THEN
+                        zjip1_ratio   = e1e2t(jip1,jj  ) * tmask(jip1,jj  ,jk) / zsum
+                        zjim1_ratio   = e1e2t(jim1,jj  ) * tmask(jim1,jj  ,jk) / zsum
+                        zjjp1_ratio   = e1e2t(ji  ,jjp1) * tmask(ji  ,jjp1,jk) / zsum
+                        zjjm1_ratio   = e1e2t(ji  ,jjm1) * tmask(ji  ,jjm1,jk) / zsum
+
+                        pvol_flx(ji  ,jjp1,jk       ) = pvol_flx(ji  ,jjp1,jk       ) + pvol_flx(ji,jj,jk       ) * zjjp1_ratio
+                        pvol_flx(ji  ,jjm1,jk       ) = pvol_flx(ji  ,jjm1,jk       ) + pvol_flx(ji,jj,jk       ) * zjjm1_ratio
+                        pvol_flx(jip1,jj  ,jk       ) = pvol_flx(jip1,jj  ,jk       ) + pvol_flx(ji,jj,jk       ) * zjip1_ratio
+                        pvol_flx(jim1,jj  ,jk       ) = pvol_flx(jim1,jj  ,jk       ) + pvol_flx(ji,jj,jk       ) * zjim1_ratio
+                        pts_flx (ji  ,jjp1,jk,jp_sal) = pts_flx (ji  ,jjp1,jk,jp_sal) + pts_flx (ji,jj,jk,jp_sal) * zjjp1_ratio
+                        pts_flx (ji  ,jjm1,jk,jp_sal) = pts_flx (ji  ,jjm1,jk,jp_sal) + pts_flx (ji,jj,jk,jp_sal) * zjjm1_ratio
+                        pts_flx (jip1,jj  ,jk,jp_sal) = pts_flx (jip1,jj  ,jk,jp_sal) + pts_flx (ji,jj,jk,jp_sal) * zjip1_ratio
+                        pts_flx (jim1,jj  ,jk,jp_sal) = pts_flx (jim1,jj  ,jk,jp_sal) + pts_flx (ji,jj,jk,jp_sal) * zjim1_ratio
+                        pts_flx (ji  ,jjp1,jk,jp_tem) = pts_flx (ji  ,jjp1,jk,jp_tem) + pts_flx (ji,jj,jk,jp_tem) * zjjp1_ratio
+                        pts_flx (ji  ,jjm1,jk,jp_tem) = pts_flx (ji  ,jjm1,jk,jp_tem) + pts_flx (ji,jj,jk,jp_tem) * zjjm1_ratio
+                        pts_flx (jip1,jj  ,jk,jp_tem) = pts_flx (jip1,jj  ,jk,jp_tem) + pts_flx (ji,jj,jk,jp_tem) * zjip1_ratio
+                        pts_flx (jim1,jj  ,jk,jp_tem) = pts_flx (jim1,jj  ,jk,jp_tem) + pts_flx (ji,jj,jk,jp_tem) * zjim1_ratio
+
+                        ! set to 0 the cell we distributed over neigbourg cells
+                        pvol_flx(ji,jj,jk       ) = 0._wp
+                        pts_flx (ji,jj,jk,jp_sal) = 0._wp
+                        pts_flx (ji,jj,jk,jp_tem) = 0._wp
+
+                     ELSE IF (zsum == 0._wp ) THEN
+                        ! case where we close a cell and no adjacent cell open
+                        ! check if the cell beneath is wet
+                        IF ( tmask(ji,jj,jk+1) == 1._wp ) THEN
+                           pvol_flx(ji,jj,jk+1)       =  pvol_flx(ji,jj,jk+1)        + pvol_flx(ji,jj,jk)
+                           pts_flx (ji,jj,jk+1,jp_sal)=  pts_flx (ji,jj,jk+1,jp_sal) + pts_flx (ji,jj,jk,jp_sal)
+                           pts_flx (ji,jj,jk+1,jp_tem)=  pts_flx (ji,jj,jk+1,jp_tem) + pts_flx (ji,jj,jk,jp_tem)
+
+                           ! set to 0 the cell we distributed over neigbourg cells
+                           pvol_flx(ji,jj,jk       ) = 0._wp
+                           pts_flx (ji,jj,jk,jp_sal) = 0._wp
+                           pts_flx (ji,jj,jk,jp_tem) = 0._wp
+                        ELSE
+                        ! case no adjacent cell on the horizontal and on the vertical
+                           IF ( lwp ) THEN   ! JMM : cAution this warning may occur on any mpp subdomain but numout is only
+                                             ! open for narea== 1 (lwp=T)
+                           WRITE(numout,*) 'W A R N I N G iscpl: no adjacent cell on the vertical and horizontal'
+                           WRITE(numout,*) '                     ',mig(ji),' ',mjg(jj),' ',jk
+                           WRITE(numout,*) '                     ',ji,' ',jj,' ',jk,' ',narea
+                           WRITE(numout,*) ' we are now looking for the closest wet cell on the horizontal '
+                           ENDIF
+                        ! We deal with these points later.
+                        END IF
+                     END IF
+                  END IF
+               END IF
+            END DO
+         END DO
+      END DO
+
+      CALL lbc_sum(pvol_flx(:,:,:       ),'T',1.)
+      CALL lbc_sum(pts_flx (:,:,:,jp_sal),'T',1.)
+      CALL lbc_sum(pts_flx (:,:,:,jp_tem),'T',1.)
+
+      ! if no neighbour wet cell in case of 2close a cell", need to find the nearest wet point 
+      ! allocation and initialisation of the list of problematic point
+      ALLOCATE(inpts(jpnij))
+      inpts(:)=0
+
+      ! fill narea location with the number of problematic point
+      DO jk = 1,jpk-1
+         DO jj = 2,jpj-1
+            DO ji = fs_2,fs_jpim1
+               IF (     ptmask_b(ji,jj,jk) == 1._wp .AND. tmask(ji,jj,jk+1)  == 0._wp .AND. tmask_h(ji,jj) == 1._wp  &
+                  .AND. SUM(tmask(ji-1:ji+1,jj,jk)) + SUM(tmask(ji,jj-1:jj+1,jk)) == 0._wp) THEN
+                  inpts(narea) = inpts(narea) + 1 
+               END IF
+            END DO
+         END DO
+      END DO
+
+      ! build array of total problematic point on each cpu (share to each cpu)
+      CALL mpp_max(inpts,jpnij) 
+
+      ! size of the new variable
+      npts  = SUM(inpts)    
+      
+      ! allocation of the coordinates, correction, index vector for the problematic points 
+      ALLOCATE(ixpts(npts), iypts(npts), izpts(npts), zcorr_vol(npts), zcorr_sal(npts), zcorr_tem(npts), zlon(npts), zlat(npts))
+      ixpts(:) = -9999 ; iypts(:) = -9999 ; izpts(:) = -9999 ; zlon(:) = -1.0e20_wp ; zlat(:) = -1.0e20_wp
+      zcorr_vol(:) = -1.0e20_wp
+      zcorr_sal(:) = -1.0e20_wp
+      zcorr_tem(:) = -1.0e20_wp
+
+      ! fill new variable
+      jpts = SUM(inpts(1:narea-1))
+      DO jk = 1,jpk-1
+         DO jj = 2,jpj-1
+            DO ji = fs_2,fs_jpim1
+               IF (     ptmask_b(ji,jj,jk) == 1._wp .AND. tmask(ji,jj,jk+1)  == 0._wp .AND. tmask_h(ji,jj) == 1._wp  &
+                  .AND. SUM(tmask(ji-1:ji+1,jj,jk)) + SUM(tmask(ji,jj-1:jj+1,jk)) == 0._wp) THEN
+                  jpts = jpts + 1  ! positioning in the inpts vector for the area narea
+                  ixpts(jpts) = ji           ; iypts(jpts) = jj ; izpts(jpts) = jk
+                  zlon (jpts) = glamt(ji,jj) ; zlat (jpts) = gphit(ji,jj)
+                  zcorr_vol(jpts) = pvol_flx(ji,jj,jk)
+                  zcorr_sal(jpts) = pts_flx (ji,jj,jk,jp_sal)
+                  zcorr_tem(jpts) = pts_flx (ji,jj,jk,jp_tem)
+
+                  ! set flx to 0 (safer)
+                  pvol_flx(ji,jj,jk       ) = 0.0_wp
+                  pts_flx (ji,jj,jk,jp_sal) = 0.0_wp
+                  pts_flx (ji,jj,jk,jp_tem) = 0.0_wp
+               END IF
+            END DO
+         END DO
+      END DO
+
+      ! build array of total problematic point on each cpu (share to each cpu)
+      ! point coordinates
+      CALL mpp_max(zlat ,npts)
+      CALL mpp_max(zlon ,npts)
+      CALL mpp_max(izpts,npts)
+
+      ! correction values 
+      CALL mpp_max(zcorr_vol,npts)
+      CALL mpp_max(zcorr_sal,npts)
+      CALL mpp_max(zcorr_tem,npts)
+
+      ! put correction term in the closest cell          
+      DO jpts = 1,npts
+         CALL dom_ngb(zlon(jpts), zlat(jpts), ixpts(jpts), iypts(jpts),'T', izpts(jpts))
+         DO jj = mj0(iypts(jpts)),mj1(iypts(jpts))
+            DO ji = mi0(ixpts(jpts)),mi1(ixpts(jpts))
+               jk = izpts(jpts)
+
+               IF (tmask_h(ji,jj) == 1._wp) THEN
+                  ! correct the vol_flx in the closest cell
+                  pvol_flx(ji,jj,jk)        =  pvol_flx(ji,jj,jk       ) + zcorr_vol(jpts)
+                  pts_flx (ji,jj,jk,jp_sal) =  pts_flx (ji,jj,jk,jp_sal) + zcorr_sal(jpts)
+                  pts_flx (ji,jj,jk,jp_tem) =  pts_flx (ji,jj,jk,jp_tem) + zcorr_tem(jpts)
+
+                  ! set correction to 0
+                  zcorr_vol(jpts) = 0.0_wp
+                  zcorr_sal(jpts) = 0.0_wp
+                  zcorr_tem(jpts) = 0.0_wp
+               END IF
+            END DO
+         END DO
+      END DO
+
+      ! deallocate variables 
+      DEALLOCATE(inpts)
+      DEALLOCATE(ixpts, iypts, izpts, zcorr_vol, zcorr_sal, zcorr_tem, zlon, zlat)
+    
+      ! add contribution store on the hallo (lbclnk remove one of the contribution)
+      pvol_flx(:,:,:       ) = pvol_flx(:,:,:       ) * tmask(:,:,:)
+      pts_flx (:,:,:,jp_sal) = pts_flx (:,:,:,jp_sal) * tmask(:,:,:)
+      pts_flx (:,:,:,jp_tem) = pts_flx (:,:,:,jp_tem) * tmask(:,:,:)
+
+      ! compute sum over the halo and set it to 0.
+      CALL lbc_sum(pvol_flx(:,:,:       ),'T',1._wp)
+      CALL lbc_sum(pts_flx (:,:,:,jp_sal),'T',1._wp)
+      CALL lbc_sum(pts_flx (:,:,:,jp_tem),'T',1._wp)
+
+      ! deallocate variables
+      CALL wrk_dealloc(jpi,jpj, zdssh ) 
+
+   END SUBROUTINE iscpl_cons
+
+   SUBROUTINE iscpl_div( phdivn )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE iscpl_div  ***
+      !!
+      !! ** Purpose :   update the horizontal divergenc
+      !!
+      !! ** Method  :
+      !!                CAUTION : iscpl is positive (inflow) and expressed in m/s
+      !!
+      !! ** Action  :   phdivn   increase by the iscpl correction term
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   phdivn   ! horizontal divergence
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               phdivn(ji,jj,jk) = phdivn(ji,jj,jk) + hdiv_iscpl(ji,jj,jk) / e3t_n(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE iscpl_div
+
+END MODULE iscplhsb
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/iscplini.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/iscplini.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/iscplini.F90	(revision 6140)
@@ -0,0 +1,85 @@
+MODULE iscplini
+   !!======================================================================
+   !!                       ***  MODULE  sbciscpl***
+   !! Ocean forcing:  river runoff
+   !!=====================================================================
+   !! History :  NEMO  ! 2015-01 P. Mathiot: original 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   iscpl_init     : initialisation routine (namelist)
+   !!   iscpl_alloc    : allocation of correction variables
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE oce             ! global tra/dyn variable
+   USE lib_mpp         ! MPP library
+   USE lib_fortran     ! MPP library
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+   
+   PUBLIC   iscpl_init      
+   PUBLIC   iscpl_alloc 
+   !!                                                      !!* namsbc_iscpl namelist *
+   LOGICAL , PUBLIC                                        ::   ln_hsb
+   INTEGER , PUBLIC                                        ::   nn_fiscpl, nstp_iscpl
+   INTEGER , PUBLIC                                        ::   nn_drown
+   REAL(wp), PUBLIC                                        ::   rdt_iscpl
+   !!                                                      !!* namsbc_iscpl namelist *
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  ) ::   hdiv_iscpl
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   htsc_iscpl
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: sbcrnf.F90 4666 2014-06-11 12:52:23Z mathiot $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION iscpl_alloc()
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE sbc_iscpl_alloc  ***
+      !!----------------------------------------------------------------------
+      ALLOCATE( htsc_iscpl(jpi,jpj,jpk,jpts) , hdiv_iscpl(jpi,jpj,jpk) , STAT=iscpl_alloc )
+         !
+      IF( lk_mpp          )   CALL mpp_sum ( iscpl_alloc )
+      IF( iscpl_alloc > 0 )   CALL ctl_warn('iscpl_alloc: allocation of arrays failed')
+   END FUNCTION iscpl_alloc
+
+   SUBROUTINE iscpl_init()
+      INTEGER ::   ios           ! Local integer output status for namelist read
+      NAMELIST/namsbc_iscpl/nn_fiscpl,ln_hsb,nn_drown
+      !!----------------------------------------------------------------------
+      !                                   ! ============
+      !                                   !   Namelist
+      !                                   ! ============
+      !
+      nn_fiscpl = 0
+      ln_hsb    = .FALSE.
+      REWIND( numnam_ref )              ! Namelist namsbc_iscpl in reference namelist : Ice sheet coupling
+      READ  ( numnam_ref, namsbc_iscpl, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_iscpl in reference namelist', lwp )
+
+      REWIND( numnam_cfg )              ! Namelist namsbc_iscpl in configuration namelist : Ice Sheet coupling
+      READ  ( numnam_cfg, namsbc_iscpl, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_iscpl in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namsbc_iscpl )
+      !
+      nstp_iscpl=MIN(nn_fiscpl, nitend-nit000+1) ! the coupling period have to be less or egal than the total number of time step
+      rdt_iscpl = nstp_iscpl * rn_rdt
+      !
+      IF (lwp) THEN
+         WRITE(numout,*) 'iscpl_rst:'
+         WRITE(numout,*) '~~~~~~~~~'
+         WRITE(numout,*) ' coupling     flag (ln_iscpl )            = ', ln_iscpl
+         WRITE(numout,*) ' conservation flag (ln_hsb   )            = ', ln_hsb
+         WRITE(numout,*) ' nb of stp for cons (rn_fiscpl)           = ', nstp_iscpl
+         IF (nstp_iscpl .NE. nn_fiscpl) WRITE(numout,*) 'W A R N I N G: nb of stp for cons has been modified &
+            &                                           (larger than run length)'
+         WRITE(numout,*) ' coupling time step                       = ', rdt_iscpl
+         WRITE(numout,*) ' number of call of the extrapolation loop = ', nn_drown
+      END IF
+
+   END SUBROUTINE iscpl_init
+
+END MODULE iscplini
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/iscplrst.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/iscplrst.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/iscplrst.F90	(revision 6140)
@@ -0,0 +1,441 @@
+MODULE iscplrst
+   !!======================================================================
+   !!                       ***  MODULE  iscplrst***
+   !! Ocean forcing: update the restart file in case of ice sheet/ocean coupling
+   !!=====================================================================
+   !! History :  NEMO  ! 2015-01 P. Mathiot: original 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   iscpl_stp          : step management
+   !!   iscpl_rst_interpol : restart interpolation in case of coupling with ice sheet
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE domwri          ! ocean space and time domain
+   USE domvvl, ONLY : dom_vvl_interpol
+   USE phycst          ! physical constants
+   USE sbc_oce         ! surface boundary condition variables
+   USE oce             ! global tra/dyn variable
+   USE in_out_manager  ! I/O manager
+   USE iom             ! I/O module
+   USE lib_mpp         ! MPP library
+   USE lib_fortran     ! MPP library
+   USE wrk_nemo        ! Memory allocation
+   USE lbclnk          ! communication
+   USE iscplini        ! ice sheet coupling: initialisation
+   USE iscplhsb        ! ice sheet coupling: conservation
+
+   IMPLICIT NONE
+   PRIVATE
+   
+   PUBLIC   iscpl_stp          ! step management 
+   !!
+   !! * Substitutions  
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: sbcrnf.F90 4666 2014-06-11 12:52:23Z mathiot $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE iscpl_stp
+      !!---------------------------------------------------------------------- 
+      !!                   ***  ROUTINE iscpl_stp  ***
+      !! 
+      !! ** Purpose : compute initialisation
+      !!              compute extrapolation of restart variable un, vn, tsn, sshn (wetting/drying)   
+      !!              compute correction term if needed
+      !! 
+      !!----------------------------------------------------------------------
+      INTEGER  ::   inum0
+      REAL(wp), DIMENSION(:,:  ), POINTER :: zsmask_b
+      REAL(wp), DIMENSION(:,:,:), POINTER :: ztmask_b, zumask_b, zvmask_b
+      REAL(wp), DIMENSION(:,:,:), POINTER :: ze3t_b  , ze3u_b  , ze3v_b  
+      REAL(wp), DIMENSION(:,:,:), POINTER :: zdepw_b
+      CHARACTER(20) :: cfile
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc(jpi,jpj,jpk, ztmask_b, zumask_b, zvmask_b) ! mask before
+      CALL wrk_alloc(jpi,jpj,jpk, ze3t_b  , ze3u_b  , ze3v_b  ) ! e3   before
+      CALL wrk_alloc(jpi,jpj,jpk, zdepw_b )
+      CALL wrk_alloc(jpi,jpj,     zsmask_b                    )
+
+
+      !! get restart variable
+      CALL iom_get( numror, jpdom_autoglo, 'tmask'  , ztmask_b   ) ! need to extrapolate T/S
+      CALL iom_get( numror, jpdom_autoglo, 'umask'  , zumask_b   ) ! need to correct barotropic velocity
+      CALL iom_get( numror, jpdom_autoglo, 'vmask'  , zvmask_b   ) ! need to correct barotropic velocity
+      CALL iom_get( numror, jpdom_autoglo, 'smask'  , zsmask_b   ) ! need to correct barotropic velocity
+      CALL iom_get( numror, jpdom_autoglo, 'e3t_n'  , ze3t_b(:,:,:) )  ! need to compute temperature correction
+      CALL iom_get( numror, jpdom_autoglo, 'e3u_n'  , ze3u_b(:,:,:) )  ! need to correct barotropic velocity
+      CALL iom_get( numror, jpdom_autoglo, 'e3v_n'  , ze3v_b(:,:,:) )  ! need to correct barotropic velocity
+      CALL iom_get( numror, jpdom_autoglo, 'gdepw_n', zdepw_b(:,:,:) ) ! need to interpol vertical profile (vvl)
+
+      !! read namelist
+      CALL iscpl_init()
+
+      !!  ! Extrapolation/interpolation of modify cell and new cells ... (maybe do it later after domvvl)
+      CALL iscpl_rst_interpol( ztmask_b, zumask_b, zvmask_b, zsmask_b, ze3t_b, ze3u_b, ze3v_b, zdepw_b )
+
+      !! compute correction if conservation needed
+      IF ( ln_hsb ) THEN
+         IF( iscpl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'rst_iscpl : unable to allocate rst_iscpl arrays' )
+         CALL iscpl_cons(ztmask_b, zsmask_b, ze3t_b, htsc_iscpl, hdiv_iscpl, rdt_iscpl)
+      END IF
+         
+      !! print mesh/mask
+      IF( nmsh /= 0 .AND. ln_iscpl )   CALL dom_wri      ! Create a domain file
+
+      IF ( ln_hsb ) THEN
+         cfile='correction'
+         cfile = TRIM( cfile )
+         CALL iom_open  ( cfile, inum0, ldwrt = .TRUE., kiolib = jprstlib )
+         CALL iom_rstput( 0, 0, inum0, 'vol_cor', hdiv_iscpl(:,:,:) )
+         CALL iom_rstput( 0, 0, inum0, 'tem_cor', htsc_iscpl(:,:,:,jp_tem) )
+         CALL iom_rstput( 0, 0, inum0, 'sal_cor', htsc_iscpl(:,:,:,jp_sal) )
+         CALL iom_close ( inum0 )
+      END IF
+
+      CALL wrk_dealloc(jpi,jpj,jpk, ztmask_b,zumask_b,zvmask_b )  
+      CALL wrk_dealloc(jpi,jpj,jpk, ze3t_b  ,ze3u_b  ,ze3v_b   )  
+      CALL wrk_dealloc(jpi,jpj,jpk, zdepw_b                    )
+      CALL wrk_dealloc(jpi,jpj,     zsmask_b                   )
+
+      !! next step is an euler time step
+      neuler = 0
+
+      !! set _b and _n variables equal
+      tsb (:,:,:,:) = tsn (:,:,:,:)
+      ub  (:,:,:  ) = un  (:,:,:  )
+      vb  (:,:,:  ) = vn  (:,:,:  )
+      sshb(:,:    ) = sshn(:,:)
+
+      !! set _b and _n vertical scale factor equal
+      e3t_b (:,:,:) = e3t_n (:,:,:)
+      e3u_b (:,:,:) = e3u_n (:,:,:)
+      e3v_b (:,:,:) = e3v_n (:,:,:)
+
+      e3uw_b(:,:,:)  = e3uw_n(:,:,:)
+      e3vw_b(:,:,:)  = e3vw_n(:,:,:)
+      gdept_b(:,:,:)  = gdept_n(:,:,:)
+      gdepw_b(:,:,:) = gdepw_n(:,:,:)
+      hu_b (:,:) = hu_n(:,:)
+      hv_b (:,:) = hv_n(:,:)
+      r1_hu_b(:,:) = r1_hu_n(:,:)
+      r1_hv_b(:,:) = r1_hv_n(:,:)
+      !
+   END SUBROUTINE iscpl_stp
+   
+   SUBROUTINE iscpl_rst_interpol (ptmask_b, pumask_b, pvmask_b, psmask_b, pe3t_b, pe3u_b, pe3v_b, pdepw_b)
+      !!---------------------------------------------------------------------- 
+      !!                   ***  ROUTINE iscpl_rst_interpol  ***
+      !! 
+      !! ** Purpose :   compute new tn, sn, un, vn and sshn in case of evolving geometry of ice shelves 
+      !!                compute 2d fields of heat, salt and volume correction
+      !! 
+      !! ** Method  :   tn, sn : extrapolation from neigbourg cells
+      !!                un, vn : fill with 0 velocity and keep barotropic transport by modifing surface velocity or adjacent velocity
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:  ), INTENT(in ) :: ptmask_b, pumask_b, pvmask_b    !! mask before
+      REAL(wp), DIMENSION(:,:,:  ), INTENT(in ) :: pe3t_b  , pe3u_b  , pe3v_b      !! scale factor before
+      REAL(wp), DIMENSION(:,:,:  ), INTENT(in ) :: pdepw_b                         !! depth w before
+      REAL(wp), DIMENSION(:,:    ), INTENT(in ) :: psmask_b                        !! mask before
+      !!
+      INTEGER :: ji, jj, jk, iz          !! loop index
+      INTEGER :: jip1, jim1, jjp1, jjm1, jkp1, jkm1
+      !!
+      REAL(wp):: summsk, zsum, zsum1, zarea, zsumn, zsumb
+      REAL(wp):: zdz, zdzm1, zdzp1
+      !!
+      REAL(wp), DIMENSION(:,:    ), POINTER :: zdmask , zdsmask, zvcorr, zucorr, zde3t
+      REAL(wp), DIMENSION(:,:    ), POINTER :: zbub   , zbvb   , zbun  , zbvn
+      REAL(wp), DIMENSION(:,:    ), POINTER :: zssh0  , zssh1, zhu1, zhv1
+      REAL(wp), DIMENSION(:,:    ), POINTER :: zsmask0, zsmask1
+      REAL(wp), DIMENSION(:,:,:  ), POINTER :: ztmask0, ztmask1, ztrp
+      REAL(wp), DIMENSION(:,:,:  ), POINTER :: zwmaskn, zwmaskb, ztmp3d
+      REAL(wp), DIMENSION(:,:,:,:), POINTER :: zts0
+      !!----------------------------------------------------------------------
+
+      !! allocate variables
+      CALL wrk_alloc(jpi,jpj,jpk,2, zts0                                   )
+      CALL wrk_alloc(jpi,jpj,jpk,   ztmask0, ztmask1 , ztrp, ztmp3d        ) 
+      CALL wrk_alloc(jpi,jpj,jpk,   zwmaskn, zwmaskb                       ) 
+      CALL wrk_alloc(jpi,jpj,       zsmask0, zsmask1                       ) 
+      CALL wrk_alloc(jpi,jpj,       zdmask , zdsmask, zvcorr, zucorr, zde3t) 
+      CALL wrk_alloc(jpi,jpj,       zbub   , zbvb    , zbun , zbvn         ) 
+      CALL wrk_alloc(jpi,jpj,       zssh0  , zssh1, zhu1, zhv1             ) 
+
+      !! mask value to be sure
+      tsn(:,:,:,jp_tem) = tsn(:,:,:,jp_tem) * ptmask_b(:,:,:)
+      tsn(:,:,:,jp_sal) = tsn(:,:,:,jp_sal) * ptmask_b(:,:,:)
+      
+      ! compute wmask
+      zwmaskn(:,:,1) = tmask   (:,:,1)
+      zwmaskb(:,:,1) = ptmask_b(:,:,1)
+      DO jk = 2,jpk
+         zwmaskn(:,:,jk) =  tmask  (:,:,jk) *  tmask  (:,:,jk-1)
+         zwmaskb(:,:,jk) = ptmask_b(:,:,jk) * ptmask_b(:,:,jk-1)
+      END DO
+           
+      ! compute new ssh if we open a full water column (average of the closest neigbourgs)  
+      sshb (:,:)=sshn(:,:)
+      zssh0(:,:)=sshn(:,:)
+      zsmask0(:,:) = psmask_b(:,:)
+      zsmask1(:,:) = psmask_b(:,:)
+      DO iz = 1,10    ! need to be tuned (configuration dependent) (OK for ISOMIP+)
+         zdsmask(:,:) = ssmask(:,:)-zsmask0(:,:)
+         DO jj = 2,jpj-1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               jip1=ji+1; jim1=ji-1;
+               jjp1=jj+1; jjm1=jj-1;
+               summsk=(zsmask0(jip1,jj)+zsmask0(jim1,jj)+zsmask0(ji,jjp1)+zsmask0(ji,jjm1))
+               IF (zdsmask(ji,jj) == 1._wp .AND. summsk /= 0._wp) THEN
+                  sshn(ji,jj)=( zssh0(jip1,jj)*zsmask0(jip1,jj)     &
+                  &           + zssh0(jim1,jj)*zsmask0(jim1,jj)     &
+                  &           + zssh0(ji,jjp1)*zsmask0(ji,jjp1)     &
+                  &           + zssh0(ji,jjm1)*zsmask0(ji,jjm1))/summsk
+                  zsmask1(ji,jj)=1._wp
+               END IF
+            END DO
+         END DO
+         CALL lbc_lnk(sshn,'T',1._wp)
+         CALL lbc_lnk(zsmask1,'T',1._wp)
+         zssh0   = sshn
+         zsmask0 = zsmask1
+      END DO
+      sshn(:,:) = sshn(:,:) * ssmask(:,:)
+
+!=============================================================================
+!PM: Is this needed since introduction of VVL by default?
+      IF (.NOT.ln_linssh) THEN
+      ! Reconstruction of all vertical scale factors at now time steps
+      ! =============================================================================
+      ! Horizontal scale factor interpolations
+      ! --------------------------------------
+         DO jk = 1,jpk
+            DO jj=1,jpj
+               DO ji=1,jpi
+                  IF (tmask(ji,jj,1) == 0._wp .OR. ptmask_b(ji,jj,1) == 0._wp) THEN
+                     e3t_n(ji,jj,jk) = e3t_0(ji,jj,jk) * ( 1._wp + sshn(ji,jj) / ( ht_0(ji,jj) + 1._wp - ssmask(ji,jj) ) * tmask(ji,jj,jk) )
+                  ENDIF
+               END DO
+            END DO
+         END DO
+
+         CALL dom_vvl_interpol( e3t_n(:,:,:), e3u_n(:,:,:), 'U' )
+         CALL dom_vvl_interpol( e3t_n(:,:,:), e3v_n(:,:,:), 'V' )
+         CALL dom_vvl_interpol( e3u_n(:,:,:), e3f_n(:,:,:), 'F' )
+
+      ! Vertical scale factor interpolations
+      ! ------------------------------------
+         CALL dom_vvl_interpol( e3t_n(:,:,:), e3w_n (:,:,:), 'W'  )
+         CALL dom_vvl_interpol( e3u_n(:,:,:), e3uw_n(:,:,:), 'UW' )
+         CALL dom_vvl_interpol( e3v_n(:,:,:), e3vw_n(:,:,:), 'VW' )
+
+      ! t- and w- points depth
+      ! ----------------------
+         gdept_n(:,:,1) = 0.5_wp * e3w_n(:,:,1)
+         gdepw_n(:,:,1) = 0.0_wp
+         gde3w_n(:,:,1) = gdept_n(:,:,1) - sshn(:,:)
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+               DO jk = 2,mikt(ji,jj)-1
+                  gdept_n(ji,jj,jk) = gdept_0(ji,jj,jk)
+                  gdepw_n(ji,jj,jk) = gdepw_0(ji,jj,jk)
+                  gde3w_n(ji,jj,jk) = gdept_0(ji,jj,jk) - sshn(ji,jj)
+               END DO
+               IF (mikt(ji,jj) > 1) THEN
+                  jk = mikt(ji,jj)
+                  gdept_n(ji,jj,jk) = gdepw_0(ji,jj,jk) + 0.5_wp * e3w_n(ji,jj,jk)
+                  gdepw_n(ji,jj,jk) = gdepw_0(ji,jj,jk)
+                  gde3w_n(ji,jj,jk) = gdept_n(ji,jj,jk  ) - sshn   (ji,jj)
+               END IF
+               DO jk = mikt(ji,jj)+1, jpk
+                  gdept_n(ji,jj,jk) = gdept_n(ji,jj,jk-1) + e3w_n(ji,jj,jk)
+                  gdepw_n(ji,jj,jk) = gdepw_n(ji,jj,jk-1) + e3t_n(ji,jj,jk-1)
+                  gde3w_n(ji,jj,jk) = gdept_n(ji,jj,jk  ) - sshn (ji,jj)
+               END DO
+            END DO
+         END DO
+
+      ! t-, u- and v- water column thickness
+      ! ------------------------------------
+         ht_n(:,:) = 0._wp ; hu_n(:,:) = 0._wp ; hv_n(:,:) = 0._wp
+         DO jk = 1, jpkm1
+            hu_n(:,:) = hu_n(:,:) + e3u_n(:,:,jk) * umask(:,:,jk)
+            hv_n(:,:) = hv_n(:,:) + e3v_n(:,:,jk) * vmask(:,:,jk)
+            ht_n(:,:) = ht_n(:,:) + e3t_n(:,:,jk) * tmask(:,:,jk)
+         END DO
+         !                                        ! Inverse of the local depth
+         r1_hu_n(:,:) = 1._wp / ( hu_n(:,:) + 1._wp - ssumask(:,:) ) * ssumask(:,:)
+         r1_hv_n(:,:) = 1._wp / ( hv_n(:,:) + 1._wp - ssvmask(:,:) ) * ssvmask(:,:)
+
+      END IF
+
+!=============================================================================
+! compute velocity
+! compute velocity in order to conserve barotropic velocity (modification by poderation of the scale factor).
+      ub(:,:,:)=un(:,:,:)
+      vb(:,:,:)=vn(:,:,:)
+      DO jk = 1,jpk
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+               un(ji,jj,jk) = ub(ji,jj,jk)*pe3u_b(ji,jj,jk)*pumask_b(ji,jj,jk)/e3u_n(ji,jj,jk)*umask(ji,jj,jk);
+               vn(ji,jj,jk) = vb(ji,jj,jk)*pe3v_b(ji,jj,jk)*pvmask_b(ji,jj,jk)/e3v_n(ji,jj,jk)*vmask(ji,jj,jk);
+            END DO
+         END DO
+      END DO
+
+! compute new velocity if we close a cell (check barotropic velocity and change velocity over the water column)
+! compute barotropic velocity now and after 
+      ztrp(:,:,:) = ub(:,:,:)*pe3u_b(:,:,:); 
+      zbub(:,:)   = SUM(ztrp,DIM=3)
+      ztrp(:,:,:) = vb(:,:,:)*pe3v_b(:,:,:); 
+      zbvb(:,:)   = SUM(ztrp,DIM=3)
+      ztrp(:,:,:) = un(:,:,:)*e3u_n(:,:,:); 
+      zbun(:,:)   = SUM(ztrp,DIM=3)
+      ztrp(:,:,:) = vn(:,:,:)*e3v_n(:,:,:); 
+      zbvn(:,:)   = SUM(ztrp,DIM=3)
+
+      ! new water column
+      zhu1=0.0_wp ;
+      zhv1=0.0_wp ;
+      DO jk  = 1,jpk
+        zhu1(:,:) = zhu1(:,:) + e3u_n(:,:,jk) * umask(:,:,jk)
+        zhv1(:,:) = zhv1(:,:) + e3v_n(:,:,jk) * vmask(:,:,jk)
+      END DO
+      
+      ! compute correction      
+      zucorr = 0._wp
+      zvcorr = 0._wp
+      DO jj = 1,jpj
+         DO ji = 1,jpi
+            IF (zbun(ji,jj) /= zbub(ji,jj) .AND. zhu1(ji,jj) /= 0._wp ) THEN
+               zucorr(ji,jj) = (zbun(ji,jj) - zbub(ji,jj))/zhu1(ji,jj)
+            END IF
+            IF (zbvn(ji,jj) /= zbvb(ji,jj) .AND. zhv1(ji,jj) /= 0._wp ) THEN
+               zvcorr(ji,jj) = (zbvn(ji,jj) - zbvb(ji,jj))/zhv1(ji,jj)
+            END IF
+         END DO
+      END DO 
+      
+      ! update velocity
+      DO jk  = 1,jpk
+         un(:,:,jk)=(un(:,:,jk) - zucorr(:,:))*umask(:,:,jk)
+         vn(:,:,jk)=(vn(:,:,jk) - zvcorr(:,:))*vmask(:,:,jk)
+      END DO
+
+!=============================================================================
+      ! compute temp and salt
+      ! compute new tn and sn if we open a new cell
+      tsb (:,:,:,:) = tsn(:,:,:,:)
+      zts0(:,:,:,:) = tsn(:,:,:,:)
+      ztmask1(:,:,:) = ptmask_b(:,:,:)
+      ztmask0(:,:,:) = ptmask_b(:,:,:)
+      DO iz = 1,nn_drown ! resolution dependent (OK for ISOMIP+ case)
+          DO jk = 1,jpk-1
+              zdmask=tmask(:,:,jk)-ztmask0(:,:,jk);
+              DO jj = 2,jpj-1
+                 DO ji = fs_2,fs_jpim1
+                      jip1=ji+1; jim1=ji-1;
+                      jjp1=jj+1; jjm1=jj-1;
+                      summsk= (ztmask0(jip1,jj  ,jk)+ztmask0(jim1,jj  ,jk)+ztmask0(ji  ,jjp1,jk)+ztmask0(ji  ,jjm1,jk))
+                      IF (zdmask(ji,jj) == 1._wp .AND. summsk /= 0._wp) THEN
+                      !! horizontal basic extrapolation
+                         tsn(ji,jj,jk,1)=( zts0(jip1,jj  ,jk,1)*ztmask0(jip1,jj  ,jk) &
+                         &                +zts0(jim1,jj  ,jk,1)*ztmask0(jim1,jj  ,jk) &
+                         &                +zts0(ji  ,jjp1,jk,1)*ztmask0(ji  ,jjp1,jk) &
+                         &                +zts0(ji  ,jjm1,jk,1)*ztmask0(ji  ,jjm1,jk) ) / summsk
+                         tsn(ji,jj,jk,2)=( zts0(jip1,jj  ,jk,2)*ztmask0(jip1,jj  ,jk) &
+                         &                +zts0(jim1,jj  ,jk,2)*ztmask0(jim1,jj  ,jk) &
+                         &                +zts0(ji  ,jjp1,jk,2)*ztmask0(ji  ,jjp1,jk) &
+                         &                +zts0(ji  ,jjm1,jk,2)*ztmask0(ji  ,jjm1,jk) ) / summsk
+                         ztmask1(ji,jj,jk)=1
+                      ELSEIF (zdmask(ji,jj) == 1._wp .AND. summsk == 0._wp) THEN
+                      !! vertical extrapolation if horizontal extrapolation failed
+                         jkm1=max(1,jk-1) ; jkp1=min(jpk,jk+1)
+                         summsk=(ztmask0(ji,jj,jkm1)+ztmask0(ji,jj,jkp1))
+                         IF (zdmask(ji,jj) == 1._wp .AND. summsk /= 0._wp ) THEN
+                            tsn(ji,jj,jk,1)=( zts0(ji,jj,jkp1,1)*ztmask0(ji,jj,jkp1)     &
+                            &                +zts0(ji,jj,jkm1,1)*ztmask0(ji,jj,jkm1))/summsk
+                            tsn(ji,jj,jk,2)=( zts0(ji,jj,jkp1,2)*ztmask0(ji,jj,jkp1)     &
+                            &                +zts0(ji,jj,jkm1,2)*ztmask0(ji,jj,jkm1))/summsk
+                            ztmask1(ji,jj,jk)=1._wp
+                         END IF
+                      END IF
+                  END DO
+              END DO
+          END DO
+          
+          CALL lbc_lnk(tsn(:,:,:,1),'T',1._wp)
+          CALL lbc_lnk(tsn(:,:,:,2),'T',1._wp)
+          CALL lbc_lnk(ztmask1,     'T',1._wp)
+
+          ! update
+          zts0(:,:,:,:) = tsn(:,:,:,:)
+          ztmask0 = ztmask1
+
+      END DO
+
+      ! mask new tsn field
+      tsn(:,:,:,jp_tem) = tsn(:,:,:,jp_tem) * tmask(:,:,:)
+      tsn(:,:,:,jp_sal) = tsn(:,:,:,jp_sal) * tmask(:,:,:)
+
+      ! compute new T/S (interpolation) if vvl only for common wet cell in before and after wmask
+      !PM: Is this IF needed since change to VVL by default
+      IF (.NOT.ln_linssh) THEN
+         DO jk = 2,jpk-1
+            DO jj = 1,jpj
+               DO ji = 1,jpi
+                  IF (zwmaskn(ji,jj,jk) * zwmaskb(ji,jj,jk) == 1._wp .AND. (tmask(ji,jj,1)==0._wp .OR. ptmask_b(ji,jj,1)==0._wp) ) THEN
+                     !compute weight
+                     zdzp1 = MAX(0._wp,gdepw_n(ji,jj,jk+1) - pdepw_b(ji,jj,jk+1))
+                     zdz   =           gdepw_n(ji,jj,jk+1) - pdepw_b(ji,jj,jk  ) 
+                     zdzm1 = MAX(0._wp,pdepw_b(ji,jj,jk  ) - gdepw_n(ji,jj,jk  ))
+                     IF (zdz .LT. 0._wp) THEN 
+                        CALL ctl_stop( 'STOP', 'rst_iscpl : unable to compute the interpolation' )
+                     END IF
+                     tsn(ji,jj,jk,jp_tem) = ( zdzp1*tsb(ji,jj,jk+1,jp_tem)      &
+                        &                   + zdz  *tsb(ji,jj,jk  ,jp_tem)      &
+                        &                   + zdzm1*tsb(ji,jj,jk-1,jp_tem)      )/e3t_n(ji,jj,jk)
+                     tsn(ji,jj,jk,jp_sal) = ( zdzp1*tsb(ji,jj,jk+1,jp_sal)      &
+                        &                   + zdz  *tsb(ji,jj,jk  ,jp_sal)      &
+                        &                   + zdzm1*tsb(ji,jj,jk-1,jp_sal)      )/e3t_n(ji,jj,jk)
+                  END IF
+               END DO
+            END DO
+         END DO               
+      END IF
+
+      ! closed pool
+      ! -----------------------------------------------------------------------------------------
+      ! case we open a cell but no neigbour cells available to get an estimate of T and S
+      WHERE (tmask(:,:,:) == 1._wp .AND. tsn(:,:,:,2) == 0._wp) 
+         tsn(:,:,:,2) = -99._wp  ! Special value for closed pool (checking purpose in output.init)
+         tmask(:,:,:) = 0._wp    ! set mask to 0 to run
+         umask(:,:,:) = 0._wp
+         vmask(:,:,:) = 0._wp
+      END WHERE
+      
+      ! set mbkt and mikt to 1 in thiese location
+      WHERE (SUM(tmask,dim=3) == 0)
+         mbkt(:,:)=1 ; mbku(:,:)=1 ; mbkv(:,:)=1
+         mikt(:,:)=1 ; miku(:,:)=1 ; mikv(:,:)=1
+      END WHERE
+      ! -------------------------------------------------------------------------------------------
+      ! compute new tn and sn if we close cell 
+      ! nothing to do
+      ! 
+      ! deallocation tmp arrays
+      CALL wrk_dealloc(jpi,jpj,jpk,2, zts0                                   )
+      CALL wrk_dealloc(jpi,jpj,jpk,   ztmask0, ztmask1 , ztrp                ) 
+      CALL wrk_dealloc(jpi,jpj,jpk,   zwmaskn, zwmaskb , ztmp3d              ) 
+      CALL wrk_dealloc(jpi,jpj,       zsmask0, zsmask1                       ) 
+      CALL wrk_dealloc(jpi,jpj,       zdmask , zdsmask, zvcorr, zucorr, zde3t) 
+      CALL wrk_dealloc(jpi,jpj,       zbub   , zbvb    , zbun  , zbvn        ) 
+      CALL wrk_dealloc(jpi,jpj,       zssh0  , zssh1  , zhu1 , zhv1          ) 
+
+   END SUBROUTINE iscpl_rst_interpol
+
+END MODULE iscplrst
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90	(revision 6140)
@@ -35,4 +35,5 @@
    USE dtauvd          ! data: U & V current             (dta_uvd routine)
    USE domvvl          ! varying vertical mesh
+   USE iscplrst        ! ice sheet coupling
    !
    USE in_out_manager  ! I/O manager
@@ -49,5 +50,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -85,6 +85,7 @@
       IF( ln_rstart ) THEN                    ! Restart from a file
          !                                    ! -------------------
-         CALL rst_read                           ! Read the restart file
-         CALL day_init                           ! model calendar (using both namelist and restart infos)
+         CALL rst_read                        ! Read the restart file
+         IF (ln_iscpl)       CALL iscpl_stp   ! extraloate restart to wet and dry
+         CALL day_init                        ! model calendar (using both namelist and restart infos)
       ELSE
          !                                    ! Start from rest
@@ -120,41 +121,40 @@
             ENDIF
          ENDIF
-         !   
-         ! - ML - sshn could be modified by istate_eel, so that initialization of fse3t_b is done here
-         IF( lk_vvl ) THEN
+         !
+!!gm This is to be changed !!!!
+         ! - ML - sshn could be modified by istate_eel, so that initialization of e3t_b is done here
+         IF( .NOT.ln_linssh ) THEN
             DO jk = 1, jpk
-               fse3t_b(:,:,jk) = fse3t_n(:,:,jk)
+               e3t_b(:,:,jk) = e3t_n(:,:,jk)
             END DO
          ENDIF
+!!gm 
          ! 
       ENDIF
-      !
       ! 
       ! Initialize "now" and "before" barotropic velocities:
-      ! Do it whatever the free surface method, these arrays
-      ! being eventually used
-      !
+      ! Do it whatever the free surface method, these arrays being eventually used
       !
       un_b(:,:) = 0._wp   ;   vn_b(:,:) = 0._wp
       ub_b(:,:) = 0._wp   ;   vb_b(:,:) = 0._wp
       !
+!!gm  the use of umsak & vmask is not necessary belox as un, vn, ub, vb are always masked
       DO jk = 1, jpkm1
          DO jj = 1, jpj
             DO ji = 1, jpi
-               un_b(ji,jj) = un_b(ji,jj) + fse3u_n(ji,jj,jk) * un(ji,jj,jk) * umask(ji,jj,jk)
-               vn_b(ji,jj) = vn_b(ji,jj) + fse3v_n(ji,jj,jk) * vn(ji,jj,jk) * vmask(ji,jj,jk)
+               un_b(ji,jj) = un_b(ji,jj) + e3u_n(ji,jj,jk) * un(ji,jj,jk) * umask(ji,jj,jk)
+               vn_b(ji,jj) = vn_b(ji,jj) + e3v_n(ji,jj,jk) * vn(ji,jj,jk) * vmask(ji,jj,jk)
                !
-               ub_b(ji,jj) = ub_b(ji,jj) + fse3u_b(ji,jj,jk) * ub(ji,jj,jk) * umask(ji,jj,jk)
-               vb_b(ji,jj) = vb_b(ji,jj) + fse3v_b(ji,jj,jk) * vb(ji,jj,jk) * vmask(ji,jj,jk)
+               ub_b(ji,jj) = ub_b(ji,jj) + e3u_b(ji,jj,jk) * ub(ji,jj,jk) * umask(ji,jj,jk)
+               vb_b(ji,jj) = vb_b(ji,jj) + e3v_b(ji,jj,jk) * vb(ji,jj,jk) * vmask(ji,jj,jk)
             END DO
          END DO
       END DO
       !
-      un_b(:,:) = un_b(:,:) * hur  (:,:)
-      vn_b(:,:) = vn_b(:,:) * hvr  (:,:)
-      !
-      ub_b(:,:) = ub_b(:,:) * hur_b(:,:)
-      vb_b(:,:) = vb_b(:,:) * hvr_b(:,:)
-      !
+      un_b(:,:) = un_b(:,:) * r1_hu_n(:,:)
+      vn_b(:,:) = vn_b(:,:) * r1_hv_n(:,:)
+      !
+      ub_b(:,:) = ub_b(:,:) * r1_hu_b(:,:)
+      vb_b(:,:) = vb_b(:,:) * r1_hv_b(:,:)
       !
       IF( nn_timing == 1 )   CALL timing_stop('istate_init')
@@ -184,6 +184,6 @@
       !
       DO jk = 1, jpk
-         tsn(:,:,jk,jp_tem) = (  ( ( 7.5 - 0. * ABS( gphit(:,:) )/30. ) * ( 1.-TANH((fsdept(:,:,jk)-80.)/30.) )   &
-            &                + 10. * ( 5000. - fsdept(:,:,jk) ) /5000.)  ) * tmask(:,:,jk)
+         tsn(:,:,jk,jp_tem) = (  ( ( 7.5 - 0. * ABS( gphit(:,:) )/30. ) * ( 1.-TANH((gdept_n(:,:,jk)-80.)/30.) )   &
+            &                + 10. * ( 5000. - gdept_n(:,:,jk) ) /5000.)  ) * tmask(:,:,jk)
          tsb(:,:,jk,jp_tem) = tsn(:,:,jk,jp_tem)
       END DO
@@ -238,11 +238,7 @@
             !
             DO jk = 1, jpk
-               tsn(:,:,jk,jp_tem) = ( zt2 + zt1 * exp( - fsdept(:,:,jk) / 1000 ) ) * tmask(:,:,jk)
+               tsn(:,:,jk,jp_tem) = ( zt2 + zt1 * exp( - gdept_n(:,:,jk) / 1000 ) ) * tmask(:,:,jk)
                tsb(:,:,jk,jp_tem) = tsn(:,:,jk,jp_tem)
             END DO
-            !
-            IF(lwp) CALL prizre( tsn(:,:,:,jp_tem), jpi   , jpj   , jpk   , jpj/2 ,   &
-               &                             1     , jpi   , 5     , 1     , jpk   ,   &
-               &                             1     , 1.    , numout                  )
             !
             ! set salinity field to a constant value
@@ -314,8 +310,4 @@
             tsn(:,:,:,jp_tem) = tsb(:,:,:,jp_tem)                            ! set nox temperature to tb
             !
-            IF(lwp) CALL prizre( tsn(:,:,:,jp_tem), jpi   , jpj   , jpk   , jpj/2 ,   &
-               &                            1     , jpi   , 5     , 1     , jpk   ,   &
-               &                            1     , 1.    , numout                  )
-            !
             ! set salinity field to a constant value
             ! --------------------------------------
@@ -363,20 +355,20 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  tsn(ji,jj,jk,jp_tem) = (  16. - 12. * TANH( (fsdept(ji,jj,jk) - 400) / 700 )         )   &
-                       &           * (-TANH( (500-fsdept(ji,jj,jk)) / 150 ) + 1) / 2               &
-                       &       + (      15. * ( 1. - TANH( (fsdept(ji,jj,jk)-50.) / 1500.) )       &
-                       &                - 1.4 * TANH((fsdept(ji,jj,jk)-100.) / 100.)               &    
-                       &                + 7.  * (1500. - fsdept(ji,jj,jk)) / 1500.             )   & 
-                       &           * (-TANH( (fsdept(ji,jj,jk) - 500) / 150) + 1) / 2
+                  tsn(ji,jj,jk,jp_tem) = (  16. - 12. * TANH( (gdept_n(ji,jj,jk) - 400) / 700 )         )   &
+                       &           * (-TANH( (500-gdept_n(ji,jj,jk)) / 150 ) + 1) / 2               &
+                       &       + (      15. * ( 1. - TANH( (gdept_n(ji,jj,jk)-50.) / 1500.) )       &
+                       &                - 1.4 * TANH((gdept_n(ji,jj,jk)-100.) / 100.)               &    
+                       &                + 7.  * (1500. - gdept_n(ji,jj,jk)) / 1500.             )   & 
+                       &           * (-TANH( (gdept_n(ji,jj,jk) - 500) / 150) + 1) / 2
                   tsn(ji,jj,jk,jp_tem) = tsn(ji,jj,jk,jp_tem) * tmask(ji,jj,jk)
                   tsb(ji,jj,jk,jp_tem) = tsn(ji,jj,jk,jp_tem)
 
-                  tsn(ji,jj,jk,jp_sal) =  (  36.25 - 1.13 * TANH( (fsdept(ji,jj,jk) - 305) / 460 )  )  &
-                     &              * (-TANH((500 - fsdept(ji,jj,jk)) / 150) + 1) / 2          &
-                     &          + (  35.55 + 1.25 * (5000. - fsdept(ji,jj,jk)) / 5000.         &
-                     &                - 1.62 * TANH( (fsdept(ji,jj,jk) - 60.  ) / 650. )       &
-                     &                + 0.2  * TANH( (fsdept(ji,jj,jk) - 35.  ) / 100. )       &
-                     &                + 0.2  * TANH( (fsdept(ji,jj,jk) - 1000.) / 5000.)    )  &
-                     &              * (-TANH((fsdept(ji,jj,jk) - 500) / 150) + 1) / 2 
+                  tsn(ji,jj,jk,jp_sal) =  (  36.25 - 1.13 * TANH( (gdept_n(ji,jj,jk) - 305) / 460 )  )  &
+                     &              * (-TANH((500 - gdept_n(ji,jj,jk)) / 150) + 1) / 2          &
+                     &          + (  35.55 + 1.25 * (5000. - gdept_n(ji,jj,jk)) / 5000.         &
+                     &                - 1.62 * TANH( (gdept_n(ji,jj,jk) - 60.  ) / 650. )       &
+                     &                + 0.2  * TANH( (gdept_n(ji,jj,jk) - 35.  ) / 100. )       &
+                     &                + 0.2  * TANH( (gdept_n(ji,jj,jk) - 1000.) / 5000.)    )  &
+                     &              * (-TANH((gdept_n(ji,jj,jk) - 500) / 150) + 1) / 2 
                   tsn(ji,jj,jk,jp_sal) = tsn(ji,jj,jk,jp_sal) * tmask(ji,jj,jk)
                   tsb(ji,jj,jk,jp_sal) = tsn(ji,jj,jk,jp_sal)
@@ -451,9 +443,9 @@
       zalfg = 0.5 * grav * rau0
       
-      zprn(:,:,1) = zalfg * fse3w(:,:,1) * ( 1 + rhd(:,:,1) )       ! Surface value
+      zprn(:,:,1) = zalfg * e3w_n(:,:,1) * ( 1 + rhd(:,:,1) )       ! Surface value
 
       DO jk = 2, jpkm1                                              ! Vertical integration from the surface
          zprn(:,:,jk) = zprn(:,:,jk-1)   &
-            &         + zalfg * fse3w(:,:,jk) * ( 2. + rhd(:,:,jk) + rhd(:,:,jk-1) )
+            &         + zalfg * e3w_n(:,:,jk) * ( 2. + rhd(:,:,jk) + rhd(:,:,jk-1) )
       END DO  
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/divhor.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/divhor.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/divhor.F90	(revision 6140)
@@ -20,7 +20,9 @@
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
-   USE sbc_oce, ONLY : ln_rnf, nn_isf ! surface boundary condition: ocean
+   USE sbc_oce, ONLY : ln_rnf, ln_isf ! surface boundary condition: ocean
    USE sbcrnf          ! river runoff 
    USE sbcisf          ! ice shelf
+   USE iscplhsb        ! ice sheet / ocean coupling
+   USE iscplini        ! ice sheet / ocean coupling
    !
    USE in_out_manager  ! I/O manager
@@ -36,5 +38,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -74,9 +75,9 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               hdivn(ji,jj,jk) = (  e2u(ji  ,jj) * fse3u_n(ji  ,jj,jk) * un(ji  ,jj,jk)        &
-                  &               - e2u(ji-1,jj) * fse3u_n(ji-1,jj,jk) * un(ji-1,jj,jk)        &
-                  &               + e1v(ji,jj  ) * fse3v_n(ji,jj  ,jk) * vn(ji,jj  ,jk)        &
-                  &               - e1v(ji,jj-1) * fse3v_n(ji,jj-1,jk) * vn(ji,jj-1,jk)   )    &
-                  &            / ( e1e2t(ji,jj) * fse3t_n(ji,jj,jk) )
+               hdivn(ji,jj,jk) = (  e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) * un(ji  ,jj,jk)        &
+                  &               - e2u(ji-1,jj) * e3u_n(ji-1,jj,jk) * un(ji-1,jj,jk)        &
+                  &               + e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * vn(ji,jj  ,jk)        &
+                  &               - e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * vn(ji,jj-1,jk)   )    &
+                  &            / ( e1e2t(ji,jj) * e3t_n(ji,jj,jk) )
             END DO  
          END DO  
@@ -89,9 +90,11 @@
       END DO
       !
-      IF( ln_rnf                     )   CALL sbc_rnf_div( hdivn )      !==  runoffs    ==!   (update hdivn field)
+      IF( ln_rnf )   CALL sbc_rnf_div( hdivn )      !==  runoffs    ==!   (update hdivn field)
       !
-      IF( ln_divisf .AND. nn_isf > 0 )   CALL sbc_isf_div( hdivn )      !==  ice shelf  ==!   (update hdivn field)
+      IF( ln_isf )   CALL sbc_isf_div( hdivn )      !==  ice shelf  ==!   (update hdivn field)
       !
-      CALL lbc_lnk( hdivn, 'T', 1. )                       !==  lateral boundary cond.  ==!   (no sign change)
+      IF( ln_iscpl .AND. ln_hsb ) CALL iscpl_div( hdivn )  !==  ice sheet  ==!   (update hdivn field)
+      !
+      CALL lbc_lnk( hdivn, 'T', 1. )                !==  lateral boundary cond.  ==!   (no sign change)
       !
       IF( nn_timing == 1 )  CALL timing_stop('div_hor')
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv.F90	(revision 6140)
@@ -39,5 +39,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -98,5 +97,5 @@
       READ  ( numnam_ref, namdyn_adv, IOSTAT = ios, ERR = 901)
 901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_adv in reference namelist', lwp )
-
+      !
       REWIND( numnam_cfg )              ! Namelist namdyn_adv in configuration namelist : Momentum advection scheme
       READ  ( numnam_cfg, namdyn_adv, IOSTAT = ios, ERR = 902 )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90	(revision 6140)
@@ -10,6 +10,5 @@
 
    !!----------------------------------------------------------------------
-   !!   dyn_adv_cen2       : flux form momentum advection (ln_dynadv_cen2=T)
-   !!                        trends using a 2nd order centred scheme  
+   !!   dyn_adv_cen2  : flux form momentum advection (ln_dynadv_cen2=T) using a 2nd order centred scheme  
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers
@@ -30,5 +29,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -53,5 +51,4 @@
       !
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zbu, zbv     ! local scalars
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  zfu_t, zfv_t, zfu_f, zfv_f, zfu_uw, zfv_vw, zfw
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  zfu, zfv
@@ -60,5 +57,5 @@
       IF( nn_timing == 1 )  CALL timing_start('dyn_adv_cen2')
       !
-      CALL wrk_alloc( jpi, jpj, jpk, zfu_t, zfv_t, zfu_f, zfv_f, zfu_uw, zfv_vw, zfu, zfv, zfw )
+      CALL wrk_alloc( jpi,jpj,jpk,   zfu_t, zfv_t, zfu_f, zfv_f, zfu_uw, zfv_vw, zfu, zfv, zfw )
       !
       IF( kt == nit000 .AND. lwp ) THEN
@@ -68,38 +65,33 @@
       ENDIF
       !
-      IF( l_trddyn ) THEN           ! Save ua and va trends
+      IF( l_trddyn ) THEN           ! trends: store the input trends
          zfu_uw(:,:,:) = ua(:,:,:)
          zfv_vw(:,:,:) = va(:,:,:)
       ENDIF
-
-      !                                      ! ====================== !
-      !                                      !  Horizontal advection  !
-      DO jk = 1, jpkm1                       ! ====================== !
-         !                                         ! horizontal volume fluxes
-         zfu(:,:,jk) = 0.25 * e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
-         zfv(:,:,jk) = 0.25 * e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
-         !
-         DO jj = 1, jpjm1                          ! horizontal momentum fluxes at T- and F-point
+      !
+      !                             !==  Horizontal advection  ==!
+      !
+      DO jk = 1, jpkm1                    ! horizontal transport
+         zfu(:,:,jk) = 0.25_wp * e2u(:,:) * e3u_n(:,:,jk) * un(:,:,jk)
+         zfv(:,:,jk) = 0.25_wp * e1v(:,:) * e3v_n(:,:,jk) * vn(:,:,jk)
+         DO jj = 1, jpjm1                 ! horizontal momentum fluxes (at T- and F-point)
             DO ji = 1, fs_jpim1   ! vector opt.
-               zfu_t(ji+1,jj  ,jk) = ( zfu(ji,jj,jk) + zfu(ji+1,jj  ,jk) ) * ( un(ji,jj,jk) + un(ji+1,jj  ,jk) )
-               zfv_f(ji  ,jj  ,jk) = ( zfv(ji,jj,jk) + zfv(ji+1,jj  ,jk) ) * ( un(ji,jj,jk) + un(ji  ,jj+1,jk) )
-               zfu_f(ji  ,jj  ,jk) = ( zfu(ji,jj,jk) + zfu(ji  ,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji+1,jj  ,jk) )
-               zfv_t(ji  ,jj+1,jk) = ( zfv(ji,jj,jk) + zfv(ji  ,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji  ,jj+1,jk) )
+               zfu_t(ji+1,jj  ,jk) = ( zfu(ji,jj,jk) + zfu(ji+1,jj,jk) ) * ( un(ji,jj,jk) + un(ji+1,jj  ,jk) )
+               zfv_f(ji  ,jj  ,jk) = ( zfv(ji,jj,jk) + zfv(ji+1,jj,jk) ) * ( un(ji,jj,jk) + un(ji  ,jj+1,jk) )
+               zfu_f(ji  ,jj  ,jk) = ( zfu(ji,jj,jk) + zfu(ji,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji+1,jj  ,jk) )
+               zfv_t(ji  ,jj+1,jk) = ( zfv(ji,jj,jk) + zfv(ji,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji  ,jj+1,jk) )
             END DO
          END DO
-         DO jj = 2, jpjm1                          ! divergence of horizontal momentum fluxes
+         DO jj = 2, jpjm1                 ! divergence of horizontal momentum fluxes
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zbu = e1e2u(ji,jj) * fse3u(ji,jj,jk)
-               zbv = e1e2v(ji,jj) * fse3v(ji,jj,jk)
-               !
-               ua(ji,jj,jk) = ua(ji,jj,jk) - (  zfu_t(ji+1,jj  ,jk) - zfu_t(ji  ,jj  ,jk)    &
-                  &                           + zfv_f(ji  ,jj  ,jk) - zfv_f(ji  ,jj-1,jk)  ) / zbu
-               va(ji,jj,jk) = va(ji,jj,jk) - (  zfu_f(ji  ,jj  ,jk) - zfu_f(ji-1,jj  ,jk)    &
-                  &                           + zfv_t(ji  ,jj+1,jk) - zfv_t(ji  ,jj  ,jk)  ) / zbv
+               ua(ji,jj,jk) = ua(ji,jj,jk) - (  zfu_t(ji+1,jj,jk) - zfu_t(ji,jj  ,jk)    &
+                  &                           + zfv_f(ji  ,jj,jk) - zfv_f(ji,jj-1,jk)  ) * r1_e1e2u(ji,jj) / e3u_n(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) - (  zfu_f(ji,jj  ,jk) - zfu_f(ji-1,jj,jk)    &
+                  &                           + zfv_t(ji,jj+1,jk) - zfv_t(ji  ,jj,jk)  ) * r1_e1e2v(ji,jj) / e3v_n(ji,jj,jk)
             END DO
          END DO
       END DO
       !
-      IF( l_trddyn ) THEN                          ! save the horizontal advection trend for diagnostic
+      IF( l_trddyn ) THEN           ! trends: send trend to trddyn for diagnostic
          zfu_uw(:,:,:) = ua(:,:,:) - zfu_uw(:,:,:)
          zfv_vw(:,:,:) = va(:,:,:) - zfv_vw(:,:,:)
@@ -109,52 +101,48 @@
       ENDIF
       !
-
-      !                                      ! ==================== !
-      !                                      !  Vertical advection  !
-      DO jk = 1, jpkm1                       ! ==================== !
-         !                                         ! Vertical volume fluxesÊ
-         zfw(:,:,jk) = 0.25 * e1e2t(:,:) * wn(:,:,jk)
-         !
-         IF( jk == 1 ) THEN                        ! surface/bottom advective fluxes                   
-            zfu_uw(:,:,jpk) = 0.e0                      ! Bottom  value : flux set to zero
-            zfv_vw(:,:,jpk) = 0.e0
-            !                                           ! Surface value :
-            IF( lk_vvl ) THEN                                ! variable volume : flux set to zero
-               zfu_uw(:,:, 1 ) = 0.e0    
-               zfv_vw(:,:, 1 ) = 0.e0
-            ELSE                                             ! constant volume : advection through the surface
-               DO jj = 2, jpjm1
-                  DO ji = fs_2, fs_jpim1
-                     zfu_uw(ji,jj, 1 ) = 2.e0 * ( zfw(ji,jj,1) + zfw(ji+1,jj  ,1) ) * un(ji,jj,1)
-                     zfv_vw(ji,jj, 1 ) = 2.e0 * ( zfw(ji,jj,1) + zfw(ji  ,jj+1,1) ) * vn(ji,jj,1)
-                  END DO
-               END DO
-            ENDIF
-         ELSE                                      ! interior fluxes
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zfu_uw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji+1,jj  ,jk) ) * ( un(ji,jj,jk) + un(ji,jj,jk-1) )
-                  zfv_vw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji  ,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji,jj,jk-1) )
-               END DO
+      !                             !==  Vertical advection  ==!
+      !
+      DO jj = 2, jpjm1                    ! surface/bottom advective fluxes set to zero
+         DO ji = fs_2, fs_jpim1
+            zfu_uw(ji,jj,jpk) = 0._wp   ;   zfv_vw(jj,jj,jpk) = 0._wp
+            zfu_uw(ji,jj, 1 ) = 0._wp   ;   zfv_vw(jj,jj, 1 ) = 0._wp
+         END DO
+      END DO
+      IF( ln_linssh ) THEN                ! linear free surface: advection through the surface
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zfu_uw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * wn(ji,jj,1) + e1e2t(ji+1,jj) * wn(ji+1,jj,1) ) * un(ji,jj,1)
+               zfv_vw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * wn(ji,jj,1) + e1e2t(ji,jj+1) * wn(ji,jj+1,1) ) * vn(ji,jj,1)
             END DO
-         ENDIF
+         END DO
+      ENDIF
+      DO jk = 2, jpkm1                    ! interior advective fluxes
+         DO jj = 2, jpjm1                       ! 1/4 * Vertical transport
+            DO ji = fs_2, fs_jpim1
+               zfw(ji,jj,jk) = 0.25_wp * e1e2t(ji,jj) * wn(ji,jj,jk)
+            END DO
+         END DO
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zfu_uw(ji,jj,jk) = ( zfw(ji,jj,jk) + zfw(ji+1,jj  ,jk) ) * ( un(ji,jj,jk) + un(ji,jj,jk-1) )
+               zfv_vw(ji,jj,jk) = ( zfw(ji,jj,jk) + zfw(ji  ,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji,jj,jk-1) )
+            END DO
+         END DO
       END DO
-      DO jk = 1, jpkm1                             ! divergence of vertical momentum flux divergence
+      DO jk = 1, jpkm1                    ! divergence of vertical momentum flux divergence
          DO jj = 2, jpjm1 
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               ua(ji,jj,jk) =  ua(ji,jj,jk) - ( zfu_uw(ji,jj,jk) - zfu_uw(ji,jj,jk+1) )    &
-                  &  / ( e1e2u(ji,jj) * fse3u(ji,jj,jk) )
-               va(ji,jj,jk) =  va(ji,jj,jk) - ( zfv_vw(ji,jj,jk) - zfv_vw(ji,jj,jk+1) )    &
-                  &  / ( e1e2v(ji,jj) * fse3v(ji,jj,jk) )
+               ua(ji,jj,jk) = ua(ji,jj,jk) - ( zfu_uw(ji,jj,jk) - zfu_uw(ji,jj,jk+1) ) * r1_e1e2u(ji,jj) / e3u_n(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) - ( zfv_vw(ji,jj,jk) - zfv_vw(ji,jj,jk+1) ) * r1_e1e2v(ji,jj) / e3v_n(ji,jj,jk)
             END DO
          END DO
       END DO
       !
-      IF( l_trddyn ) THEN                          ! save the vertical advection trend for diagnostic
+      IF( l_trddyn ) THEN                 ! trends: send trend to trddyn for diagnostic
          zfu_t(:,:,:) = ua(:,:,:) - zfu_t(:,:,:)
          zfv_t(:,:,:) = va(:,:,:) - zfv_t(:,:,:)
          CALL trd_dyn( zfu_t, zfv_t, jpdyn_zad, kt )
       ENDIF
-      !                                            ! Control print
+      !                                   ! Control print
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' cen2 adv - Ua: ', mask1=umask,   &
          &                       tab3d_2=va, clinfo2=           ' Va: ', mask2=vmask, clinfo3='dyn' )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90	(revision 6140)
@@ -35,5 +35,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -71,9 +70,8 @@
       !! Reference : Shchepetkin & McWilliams, 2005, Ocean Modelling. 
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt     ! ocean time-step index
-      !
-      INTEGER  ::   ji, jj, jk            ! dummy loop indices
-      REAL(wp) ::   zbu, zbv    ! temporary scalars
-      REAL(wp) ::   zui, zvj, zfuj, zfvi, zl_u, zl_v   ! temporary scalars
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zui, zvj, zfuj, zfvi, zl_u, zl_v   ! local scalars
       REAL(wp), POINTER, DIMENSION(:,:,:  ) ::  zfu, zfv
       REAL(wp), POINTER, DIMENSION(:,:,:  ) ::  zfu_t, zfv_t, zfu_f, zfv_f, zfu_uw, zfv_vw, zfw
@@ -83,6 +81,6 @@
       IF( nn_timing == 1 )  CALL timing_start('dyn_adv_ubs')
       !
-      CALL wrk_alloc( jpi, jpj, jpk,       zfu_t , zfv_t , zfu_f , zfv_f, zfu_uw, zfv_vw, zfu, zfv, zfw )
-      CALL wrk_alloc( jpi, jpj, jpk, jpts, zlu_uu, zlv_vv, zlu_uv, zlv_vu                               )
+      CALL wrk_alloc( jpi,jpj,jpk,        zfu_t , zfv_t , zfu_f , zfv_f, zfu_uw, zfv_vw, zfu, zfv, zfw )
+      CALL wrk_alloc( jpi,jpj,jpk,jpts,   zlu_uu, zlv_vv, zlu_uv, zlv_vu                               )
       !
       IF( kt == nit000 ) THEN
@@ -101,20 +99,18 @@
       zlu_uv(:,:,:,:) = 0._wp 
       zlv_vu(:,:,:,:) = 0._wp 
-
-      IF( l_trddyn ) THEN           ! Save ua and va trends
+      !
+      IF( l_trddyn ) THEN           ! trends: store the input trends
          zfu_uw(:,:,:) = ua(:,:,:)
          zfv_vw(:,:,:) = va(:,:,:)
       ENDIF
-
       !                                      ! =========================== !
       DO jk = 1, jpkm1                       !  Laplacian of the velocity  !
          !                                   ! =========================== !
          !                                         ! horizontal volume fluxes
-         zfu(:,:,jk) = e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
-         zfv(:,:,jk) = e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+         zfu(:,:,jk) = e2u(:,:) * e3u_n(:,:,jk) * un(:,:,jk)
+         zfv(:,:,jk) = e1v(:,:) * e3v_n(:,:,jk) * vn(:,:,jk)
          !            
          DO jj = 2, jpjm1                          ! laplacian
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               !
                zlu_uu(ji,jj,jk,1) = ( ub (ji+1,jj  ,jk) - 2.*ub (ji,jj,jk) + ub (ji-1,jj  ,jk) ) * umask(ji,jj,jk)
                zlv_vv(ji,jj,jk,1) = ( vb (ji  ,jj+1,jk) - 2.*vb (ji,jj,jk) + vb (ji  ,jj-1,jk) ) * vmask(ji,jj,jk)
@@ -137,11 +133,11 @@
       CALL lbc_lnk( zlv_vv(:,:,:,1), 'V', 1. )   ;   CALL lbc_lnk( zlv_vu(:,:,:,1), 'V', 1. )
       CALL lbc_lnk( zlv_vv(:,:,:,2), 'V', 1. )   ;   CALL lbc_lnk( zlv_vu(:,:,:,2), 'V', 1. ) 
-      
+      !
       !                                      ! ====================== !
       !                                      !  Horizontal advection  !
       DO jk = 1, jpkm1                       ! ====================== !
          !                                         ! horizontal volume fluxes
-         zfu(:,:,jk) = 0.25 * e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
-         zfv(:,:,jk) = 0.25 * e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+         zfu(:,:,jk) = 0.25_wp * e2u(:,:) * e3u_n(:,:,jk) * un(:,:,jk)
+         zfv(:,:,jk) = 0.25_wp * e1v(:,:) * e3v_n(:,:,jk) * vn(:,:,jk)
          !
          DO jj = 1, jpjm1                          ! horizontal momentum fluxes at T- and F-point
@@ -150,9 +146,9 @@
                zvj = ( vn(ji,jj,jk) + vn(ji  ,jj+1,jk) )
                !
-               IF (zui > 0) THEN   ;   zl_u = zlu_uu(ji  ,jj,jk,1)
-               ELSE                ;   zl_u = zlu_uu(ji+1,jj,jk,1)
-               ENDIF
-               IF (zvj > 0) THEN   ;   zl_v = zlv_vv(ji,jj  ,jk,1)
-               ELSE                ;   zl_v = zlv_vv(ji,jj+1,jk,1)
+               IF( zui > 0 ) THEN   ;   zl_u = zlu_uu(ji  ,jj,jk,1)
+               ELSE                 ;   zl_u = zlu_uu(ji+1,jj,jk,1)
+               ENDIF
+               IF( zvj > 0 ) THEN   ;   zl_v = zlv_vv(ji,jj  ,jk,1)
+               ELSE                 ;   zl_v = zlv_vv(ji,jj+1,jk,1)
                ENDIF
                !
@@ -166,9 +162,9 @@
                zfuj = ( zfu(ji,jj,jk) + zfu(ji  ,jj+1,jk) )
                zfvi = ( zfv(ji,jj,jk) + zfv(ji+1,jj  ,jk) )
-               IF (zfuj > 0) THEN   ;    zl_v = zlv_vu( ji  ,jj  ,jk,1)
-               ELSE                 ;    zl_v = zlv_vu( ji+1,jj,jk,1)
-               ENDIF
-               IF (zfvi > 0) THEN   ;    zl_u = zlu_uv( ji,jj  ,jk,1)
-               ELSE                 ;    zl_u = zlu_uv( ji,jj+1,jk,1)
+               IF( zfuj > 0 ) THEN   ;    zl_v = zlv_vu( ji  ,jj  ,jk,1)
+               ELSE                  ;    zl_v = zlv_vu( ji+1,jj,jk,1)
+               ENDIF
+               IF( zfvi > 0 ) THEN   ;    zl_u = zlu_uv( ji,jj  ,jk,1)
+               ELSE                  ;    zl_u = zlu_uv( ji,jj+1,jk,1)
                ENDIF
                !
@@ -181,15 +177,12 @@
          DO jj = 2, jpjm1                          ! divergence of horizontal momentum fluxes
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zbu = e1e2u(ji,jj) * fse3u(ji,jj,jk)
-               zbv = e1e2v(ji,jj) * fse3v(ji,jj,jk)
-               !
-               ua(ji,jj,jk) = ua(ji,jj,jk) - (  zfu_t(ji+1,jj  ,jk) - zfu_t(ji  ,jj  ,jk)    &
-                  &                           + zfv_f(ji  ,jj  ,jk) - zfv_f(ji  ,jj-1,jk)  ) / zbu
-               va(ji,jj,jk) = va(ji,jj,jk) - (  zfu_f(ji  ,jj  ,jk) - zfu_f(ji-1,jj  ,jk)    &
-                  &                           + zfv_t(ji  ,jj+1,jk) - zfv_t(ji  ,jj  ,jk)  ) / zbv
-            END DO
-         END DO
-      END DO
-      IF( l_trddyn ) THEN                          ! save the horizontal advection trend for diagnostic
+               ua(ji,jj,jk) = ua(ji,jj,jk) - (  zfu_t(ji+1,jj,jk) - zfu_t(ji,jj  ,jk)    &
+                  &                           + zfv_f(ji  ,jj,jk) - zfv_f(ji,jj-1,jk)  ) * r1_e1e2u(ji,jj) / e3u_n(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) - (  zfu_f(ji,jj  ,jk) - zfu_f(ji-1,jj,jk)    &
+                  &                           + zfv_t(ji,jj+1,jk) - zfv_t(ji  ,jj,jk)  ) * r1_e1e2v(ji,jj) / e3v_n(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      IF( l_trddyn ) THEN                          ! trends: send trends to trddyn for diagnostic
          zfu_uw(:,:,:) = ua(:,:,:) - zfu_uw(:,:,:)
          zfv_vw(:,:,:) = va(:,:,:) - zfv_vw(:,:,:)
@@ -198,57 +191,56 @@
          zfv_t(:,:,:) = va(:,:,:)
       ENDIF
-
       !                                      ! ==================== !
       !                                      !  Vertical advection  !
-      DO jk = 1, jpkm1                       ! ==================== !
-         !                                         ! Vertical volume fluxesÊ
-         zfw(:,:,jk) = 0.25 * e1e2t(:,:) * wn(:,:,jk)
-         !
-         IF( jk == 1 ) THEN                        ! surface/bottom advective fluxes                   
-            zfu_uw(:,:,jpk) = 0.e0                      ! Bottom  value : flux set to zero
-            zfv_vw(:,:,jpk) = 0.e0
-            !                                           ! Surface value :
-            IF( lk_vvl ) THEN                                ! variable volume : flux set to zero
-               zfu_uw(:,:, 1 ) = 0.e0    
-               zfv_vw(:,:, 1 ) = 0.e0
-            ELSE                                             ! constant volume : advection through the surface
-               DO jj = 2, jpjm1
-                  DO ji = fs_2, fs_jpim1
-                     zfu_uw(ji,jj, 1 ) = 2.e0 * ( zfw(ji,jj,1) + zfw(ji+1,jj  ,1) ) * un(ji,jj,1)
-                     zfv_vw(ji,jj, 1 ) = 2.e0 * ( zfw(ji,jj,1) + zfw(ji  ,jj+1,1) ) * vn(ji,jj,1)
-                  END DO
-               END DO
-            ENDIF
-         ELSE                                      ! interior fluxes
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zfu_uw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji+1,jj  ,jk) ) * ( un(ji,jj,jk) + un(ji,jj,jk-1) )
-                  zfv_vw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji  ,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji,jj,jk-1) )
-               END DO
-            END DO
-         ENDIF
-      END DO
-      DO jk = 1, jpkm1                             ! divergence of vertical momentum flux divergence
-         DO jj = 2, jpjm1 
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ua(ji,jj,jk) =  ua(ji,jj,jk) - ( zfu_uw(ji,jj,jk) - zfu_uw(ji,jj,jk+1) )    &
-                  &  / ( e1e2u(ji,jj) * fse3u(ji,jj,jk) )
-               va(ji,jj,jk) =  va(ji,jj,jk) - ( zfv_vw(ji,jj,jk) - zfv_vw(ji,jj,jk+1) )    &
-                  &  / ( e1e2v(ji,jj) * fse3v(ji,jj,jk) )
-            END DO
-         END DO
-      END DO
-      !
-      IF( l_trddyn ) THEN                          ! save the vertical advection trend for diagnostic
+      !                                      ! ==================== !
+      DO jj = 2, jpjm1                             ! surface/bottom advective fluxes set to zero                  
+         DO ji = fs_2, fs_jpim1
+            zfu_uw(ji,jj,jpk) = 0._wp
+            zfv_vw(ji,jj,jpk) = 0._wp
+            zfu_uw(ji,jj, 1 ) = 0._wp
+            zfv_vw(ji,jj, 1 ) = 0._wp
+         END DO
+      END DO
+      IF( ln_linssh ) THEN                         ! constant volume : advection through the surface
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zfu_uw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * wn(ji,jj,1) + e1e2t(ji+1,jj) * wn(ji+1,jj,1) ) * un(ji,jj,1)
+               zfv_vw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * wn(ji,jj,1) + e1e2t(ji,jj+1) * wn(ji,jj+1,1) ) * vn(ji,jj,1)
+            END DO
+         END DO
+      ENDIF
+      DO jk = 2, jpkm1                          ! interior fluxes
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zfw(ji,jj,jk) = 0.25_wp * e1e2t(ji,jj) * wn(ji,jj,jk)
+            END DO
+         END DO
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zfu_uw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji+1,jj,jk) ) * ( un(ji,jj,jk) + un(ji,jj,jk-1) )
+               zfv_vw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji,jj,jk-1) )
+            END DO
+         END DO
+      END DO
+      DO jk = 1, jpkm1                          ! divergence of vertical momentum flux divergence
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ua(ji,jj,jk) =  ua(ji,jj,jk) - ( zfu_uw(ji,jj,jk) - zfu_uw(ji,jj,jk+1) ) * r1_e1e2u(ji,jj) / e3u_n(ji,jj,jk)
+               va(ji,jj,jk) =  va(ji,jj,jk) - ( zfv_vw(ji,jj,jk) - zfv_vw(ji,jj,jk+1) ) * r1_e1e2v(ji,jj) / e3v_n(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+      IF( l_trddyn ) THEN                       ! save the vertical advection trend for diagnostic
          zfu_t(:,:,:) = ua(:,:,:) - zfu_t(:,:,:)
          zfv_t(:,:,:) = va(:,:,:) - zfv_t(:,:,:)
          CALL trd_dyn( zfu_t, zfv_t, jpdyn_zad, kt )
       ENDIF
-      !                                            ! Control print
+      !                                         ! Control print
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' ubs2 adv - Ua: ', mask1=umask,   &
          &                       tab3d_2=va, clinfo2=           ' Va: ', mask2=vmask, clinfo3='dyn' )
       !
-      CALL wrk_dealloc( jpi, jpj, jpk,       zfu_t , zfv_t , zfu_f , zfv_f, zfu_uw, zfv_vw, zfu, zfv, zfw )
-      CALL wrk_dealloc( jpi, jpj, jpk, jpts, zlu_uu, zlv_vv, zlu_uv, zlv_vu                               )
+      CALL wrk_dealloc( jpi,jpj,jpk,        zfu_t , zfv_t , zfu_f , zfv_f, zfu_uw, zfv_vw, zfu, zfv, zfw )
+      CALL wrk_dealloc( jpi,jpj,jpk,jpts,   zlu_uu, zlv_vv, zlu_uv, zlv_vu                               )
       !
       IF( nn_timing == 1 )  CALL timing_stop('dyn_adv_ubs')
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynbfr.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynbfr.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynbfr.F90	(revision 6140)
@@ -29,6 +29,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -65,6 +63,6 @@
         zm1_2dt = - 1._wp / ( 2._wp * rdt )
 
-        IF( l_trddyn )   THEN                      ! temporary save of ua and va trends
-           CALL wrk_alloc( jpi,jpj,jpk, ztrdu, ztrdv )
+        IF( l_trddyn ) THEN      ! trends: store the input trends
+           CALL wrk_alloc( jpi,jpj,jpk,   ztrdu, ztrdv )
            ztrdu(:,:,:) = ua(:,:,:)
            ztrdv(:,:,:) = va(:,:,:)
@@ -78,10 +76,10 @@
               !
               ! Apply stability criteria on absolute value  : abs(bfr/e3) < 1/(2dt) => bfr/e3 > -1/(2dt)
-              ua(ji,jj,ikbu) = ua(ji,jj,ikbu) + MAX(  bfrua(ji,jj) / fse3u(ji,jj,ikbu) , zm1_2dt  ) * ub(ji,jj,ikbu)
-              va(ji,jj,ikbv) = va(ji,jj,ikbv) + MAX(  bfrva(ji,jj) / fse3v(ji,jj,ikbv) , zm1_2dt  ) * vb(ji,jj,ikbv)
+              ua(ji,jj,ikbu) = ua(ji,jj,ikbu) + MAX(  bfrua(ji,jj) / e3u_n(ji,jj,ikbu) , zm1_2dt  ) * ub(ji,jj,ikbu)
+              va(ji,jj,ikbv) = va(ji,jj,ikbv) + MAX(  bfrva(ji,jj) / e3v_n(ji,jj,ikbv) , zm1_2dt  ) * vb(ji,jj,ikbv)
            END DO
         END DO
-        
-        IF ( ln_isfcav ) THEN
+        !
+        IF( ln_isfcav ) THEN        ! ocean cavities
            DO jj = 2, jpjm1
               DO ji = 2, jpim1
@@ -91,7 +89,7 @@
                  !
                  ! Apply stability criteria on absolute value  : abs(bfr/e3) < 1/(2dt) => bfr/e3 > -1/(2dt)
-                 ua(ji,jj,ikbu) = ua(ji,jj,ikbu) + MAX(  tfrua(ji,jj) / fse3u(ji,jj,ikbu) , zm1_2dt  ) * ub(ji,jj,ikbu) &
+                 ua(ji,jj,ikbu) = ua(ji,jj,ikbu) + MAX(  tfrua(ji,jj) / e3u_n(ji,jj,ikbu) , zm1_2dt  ) * ub(ji,jj,ikbu) &
                     &             * (1.-umask(ji,jj,1))
-                 va(ji,jj,ikbv) = va(ji,jj,ikbv) + MAX(  tfrva(ji,jj) / fse3v(ji,jj,ikbv) , zm1_2dt  ) * vb(ji,jj,ikbv) &
+                 va(ji,jj,ikbv) = va(ji,jj,ikbv) + MAX(  tfrva(ji,jj) / e3v_n(ji,jj,ikbv) , zm1_2dt  ) * vb(ji,jj,ikbv) &
                     &             * (1.-vmask(ji,jj,1))
                  ! (ISF)
@@ -99,11 +97,10 @@
            END DO
         END IF
-
         !
-        IF( l_trddyn )   THEN                      ! save the vertical diffusive trends for further diagnostics
+        IF( l_trddyn ) THEN      ! trends: send trends to trddyn for further diagnostics
            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
            CALL trd_dyn( ztrdu(:,:,:), ztrdv(:,:,:), jpdyn_bfr, kt )
-           CALL wrk_dealloc( jpi,jpj,jpk, ztrdu, ztrdv )
+           CALL wrk_dealloc( jpi,jpj,jpk,   ztrdu, ztrdv )
         ENDIF
         !                                          ! print mean trends (used for debugging)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 6140)
@@ -45,4 +45,5 @@
    USE wrk_nemo        ! Memory Allocation
    USE timing          ! Timing
+   USE iom
 
    IMPLICIT NONE
@@ -52,16 +53,15 @@
    PUBLIC   dyn_hpg_init   ! routine called by opa module
 
-   !                                    !!* Namelist namdyn_hpg : hydrostatic pressure gradient
-   LOGICAL , PUBLIC ::   ln_hpg_zco      !: z-coordinate - full steps
-   LOGICAL , PUBLIC ::   ln_hpg_zps      !: z-coordinate - partial steps (interpolation)
-   LOGICAL , PUBLIC ::   ln_hpg_sco      !: s-coordinate (standard jacobian formulation)
-   LOGICAL , PUBLIC ::   ln_hpg_djc      !: s-coordinate (Density Jacobian with Cubic polynomial)
-   LOGICAL , PUBLIC ::   ln_hpg_prj      !: s-coordinate (Pressure Jacobian scheme)
-   LOGICAL , PUBLIC ::   ln_hpg_isf      !: s-coordinate similar to sco modify for isf
+   !                                 !!* Namelist namdyn_hpg : hydrostatic pressure gradient
+   LOGICAL , PUBLIC ::   ln_hpg_zco   !: z-coordinate - full steps
+   LOGICAL , PUBLIC ::   ln_hpg_zps   !: z-coordinate - partial steps (interpolation)
+   LOGICAL , PUBLIC ::   ln_hpg_sco   !: s-coordinate (standard jacobian formulation)
+   LOGICAL , PUBLIC ::   ln_hpg_djc   !: s-coordinate (Density Jacobian with Cubic polynomial)
+   LOGICAL , PUBLIC ::   ln_hpg_prj   !: s-coordinate (Pressure Jacobian scheme)
+   LOGICAL , PUBLIC ::   ln_hpg_isf   !: s-coordinate similar to sco modify for isf
 
    INTEGER , PUBLIC ::   nhpg  =  0   ! = 0 to 7, type of pressure gradient scheme used ! (deduced from ln_hpg_... flags) (PUBLIC for TAM)
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -131,4 +131,10 @@
       INTEGER ::   ios             ! Local integer output status for namelist read
       !!
+      INTEGER  ::   ji, jj, jk, ikt    ! dummy loop indices      ISF
+      REAL(wp) ::   znad
+      REAL(wp), POINTER, DIMENSION(:,:,:)   ::  ztstop, zrhd ! hypothesys on isf density
+      REAL(wp), POINTER, DIMENSION(:,:)     ::  zrhdtop_isf  ! density at bottom of ISF
+      REAL(wp), POINTER, DIMENSION(:,:)     ::  ziceload     ! density at bottom of ISF
+      !!
       NAMELIST/namdyn_hpg/ ln_hpg_zco, ln_hpg_zps, ln_hpg_sco,     &
          &                 ln_hpg_djc, ln_hpg_prj, ln_hpg_isf
@@ -137,9 +143,9 @@
       REWIND( numnam_ref )              ! Namelist namdyn_hpg in reference namelist : Hydrostatic pressure gradient
       READ  ( numnam_ref, namdyn_hpg, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_hpg in reference namelist', lwp )
-
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_hpg in reference namelist', lwp )
+      !
       REWIND( numnam_cfg )              ! Namelist namdyn_hpg in configuration namelist : Hydrostatic pressure gradient
       READ  ( numnam_cfg, namdyn_hpg, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_hpg in configuration namelist', lwp )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_hpg in configuration namelist', lwp )
       IF(lwm) WRITE ( numond, namdyn_hpg )
       !
@@ -162,8 +168,8 @@
                            & either  ln_hpg_sco or  ln_hpg_prj instead')
       !
-      IF( lk_vvl .AND. .NOT. (ln_hpg_sco.OR.ln_hpg_prj.OR.ln_hpg_isf) )   &
-         &   CALL ctl_stop('dyn_hpg_init : variable volume key_vvl requires:&
-                           & the standard jacobian formulation hpg_sco or &
-                           & the pressure jacobian formulation hpg_prj')
+      IF( .NOT.ln_linssh .AND. .NOT.(ln_hpg_sco.OR.ln_hpg_prj.OR.ln_hpg_isf) )        &
+         &   CALL ctl_stop('dyn_hpg_init : non-linear free surface requires either ', &
+         &                 '   the standard jacobian formulation hpg_sco    or '    , &
+         &                 '   the pressure jacobian formulation hpg_prj'            )
 
       IF(       ln_hpg_isf .AND. .NOT. ln_isfcav )   &
@@ -190,6 +196,51 @@
       IF( ioptio /= 1 )   CALL ctl_stop( 'NO or several hydrostatic pressure gradient options used' )
       ! 
-      ! initialisation of ice load
-      riceload(:,:)=0.0
+      ! initialisation of ice shelf load
+      IF ( .NOT. ln_isfcav ) riceload(:,:)=0.0
+      IF (       ln_isfcav ) THEN
+         CALL wrk_alloc( jpi,jpj, 2,  ztstop) 
+         CALL wrk_alloc( jpi,jpj,jpk, zrhd  )
+         CALL wrk_alloc( jpi,jpj,     zrhdtop_isf, ziceload) 
+         !
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:hpg_isf : hydrostatic pressure gradient trend for ice shelf'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'  
+
+         ! To use density and not density anomaly
+         znad=1._wp
+         
+         ! assume water displaced by the ice shelf is at T=-1.9 and S=34.4 (rude)
+         ztstop(:,:,1)=-1.9_wp ; ztstop(:,:,2)=34.4_wp
+
+         ! compute density of the water displaced by the ice shelf 
+         DO jk = 1, jpk
+            CALL eos(ztstop(:,:,:),gdept_n(:,:,jk),zrhd(:,:,jk))
+         END DO
+      
+         ! compute rhd at the ice/oce interface (ice shelf side)
+         CALL eos(ztstop,risfdep,zrhdtop_isf)
+
+         ! Surface value + ice shelf gradient
+         ! compute pressure due to ice shelf load (used to compute hpgi/j for all the level from 1 to miku/v)
+         ! divided by 2 later
+         ziceload = 0._wp
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ikt=mikt(ji,jj)
+               ziceload(ji,jj) = ziceload(ji,jj) + (znad + zrhd(ji,jj,1) ) * e3w_n(ji,jj,1) * (1._wp - tmask(ji,jj,1))
+               DO jk=2,ikt-1
+                  ziceload(ji,jj) = ziceload(ji,jj) + (2._wp * znad + zrhd(ji,jj,jk-1) + zrhd(ji,jj,jk)) * e3w_n(ji,jj,jk) &
+                     &                              * (1._wp - tmask(ji,jj,jk))
+               END DO
+               IF (ikt  >=  2) ziceload(ji,jj) = ziceload(ji,jj) + (2._wp * znad + zrhdtop_isf(ji,jj) + zrhd(ji,jj,ikt-1)) &
+                                  &                              * ( risfdep(ji,jj) - gdept_1d(ikt-1) )
+            END DO
+         END DO
+         riceload(:,:)=ziceload(:,:)  ! need to be saved for diaar5
+
+         CALL wrk_dealloc( jpi,jpj, 2,  ztstop) 
+         CALL wrk_dealloc( jpi,jpj,jpk, zrhd  )
+         CALL wrk_dealloc( jpi,jpj,     zrhdtop_isf, ziceload) 
+      END IF
       !
    END SUBROUTINE dyn_hpg_init
@@ -213,5 +264,5 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt    ! ocean time-step index
-      !!
+      !
       INTEGER  ::   ji, jj, jk       ! dummy loop indices
       REAL(wp) ::   zcoef0, zcoef1   ! temporary scalars
@@ -219,5 +270,5 @@
       !!----------------------------------------------------------------------
       !
-      CALL wrk_alloc( jpi,jpj,jpk, zhpi, zhpj )
+      CALL wrk_alloc( jpi,jpj,jpk,   zhpi, zhpj )
       !
       IF( kt == nit000 ) THEN
@@ -232,8 +283,8 @@
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.
-            zcoef1 = zcoef0 * fse3w(ji,jj,1)
+            zcoef1 = zcoef0 * e3w_n(ji,jj,1)
             ! hydrostatic pressure gradient
-            zhpi(ji,jj,1) = zcoef1 * ( rhd(ji+1,jj,1) - rhd(ji,jj,1) ) / e1u(ji,jj)
-            zhpj(ji,jj,1) = zcoef1 * ( rhd(ji,jj+1,1) - rhd(ji,jj,1) ) / e2v(ji,jj)
+            zhpi(ji,jj,1) = zcoef1 * ( rhd(ji+1,jj,1) - rhd(ji,jj,1) ) * r1_e1u(ji,jj)
+            zhpj(ji,jj,1) = zcoef1 * ( rhd(ji,jj+1,1) - rhd(ji,jj,1) ) * r1_e2v(ji,jj)
             ! add to the general momentum trend
             ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1)
@@ -247,13 +298,13 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zcoef1 = zcoef0 * fse3w(ji,jj,jk)
+               zcoef1 = zcoef0 * e3w_n(ji,jj,jk)
                ! hydrostatic pressure gradient
                zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1)   &
-                  &           + zcoef1 * (  ( rhd(ji+1,jj,jk)+rhd(ji+1,jj,jk-1) )   &
-                  &                       - ( rhd(ji  ,jj,jk)+rhd(ji  ,jj,jk-1) )  ) / e1u(ji,jj)
+                  &           + zcoef1 * (  ( rhd(ji+1,jj,jk)+rhd(ji+1,jj,jk-1) )    &
+                  &                       - ( rhd(ji  ,jj,jk)+rhd(ji  ,jj,jk-1) )  ) * r1_e1u(ji,jj)
 
                zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1)   &
-                  &           + zcoef1 * (  ( rhd(ji,jj+1,jk)+rhd(ji,jj+1,jk-1) )   &
-                  &                       - ( rhd(ji,jj,  jk)+rhd(ji,jj  ,jk-1) )  ) / e2v(ji,jj)
+                  &           + zcoef1 * (  ( rhd(ji,jj+1,jk)+rhd(ji,jj+1,jk-1) )    &
+                  &                       - ( rhd(ji,jj,  jk)+rhd(ji,jj  ,jk-1) )  ) * r1_e2v(ji,jj)
                ! add to the general momentum trend
                ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk)
@@ -263,5 +314,5 @@
       END DO
       !
-      CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zhpj )
+      CALL wrk_dealloc( jpi,jpj,jpk,   zhpi, zhpj )
       !
    END SUBROUTINE hpg_zco
@@ -284,5 +335,5 @@
       !!----------------------------------------------------------------------
       !
-      CALL wrk_alloc( jpi,jpj,jpk, zhpi, zhpj )
+      CALL wrk_alloc( jpi,jpj,jpk,   zhpi, zhpj )
       !
       IF( kt == nit000 ) THEN
@@ -301,8 +352,8 @@
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.
-            zcoef1 = zcoef0 * fse3w(ji,jj,1)
+            zcoef1 = zcoef0 * e3w_n(ji,jj,1)
             ! hydrostatic pressure gradient
-            zhpi(ji,jj,1) = zcoef1 * ( rhd(ji+1,jj  ,1) - rhd(ji,jj,1) ) / e1u(ji,jj)
-            zhpj(ji,jj,1) = zcoef1 * ( rhd(ji  ,jj+1,1) - rhd(ji,jj,1) ) / e2v(ji,jj)
+            zhpi(ji,jj,1) = zcoef1 * ( rhd(ji+1,jj  ,1) - rhd(ji,jj,1) ) * r1_e1u(ji,jj)
+            zhpj(ji,jj,1) = zcoef1 * ( rhd(ji  ,jj+1,1) - rhd(ji,jj,1) ) * r1_e2v(ji,jj)
             ! add to the general momentum trend
             ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1)
@@ -310,5 +361,4 @@
          END DO
       END DO
-
 
       ! interior value (2=<jk=<jpkm1)
@@ -316,13 +366,13 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zcoef1 = zcoef0 * fse3w(ji,jj,jk)
+               zcoef1 = zcoef0 * e3w_n(ji,jj,jk)
                ! hydrostatic pressure gradient
                zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1)   &
                   &           + zcoef1 * (  ( rhd(ji+1,jj,jk) + rhd(ji+1,jj,jk-1) )   &
-                  &                       - ( rhd(ji  ,jj,jk) + rhd(ji  ,jj,jk-1) )  ) / e1u(ji,jj)
+                  &                       - ( rhd(ji  ,jj,jk) + rhd(ji  ,jj,jk-1) )  ) * r1_e1u(ji,jj)
 
                zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1)   &
                   &           + zcoef1 * (  ( rhd(ji,jj+1,jk) + rhd(ji,jj+1,jk-1) )   &
-                  &                       - ( rhd(ji,jj,  jk) + rhd(ji,jj  ,jk-1) )  ) / e2v(ji,jj)
+                  &                       - ( rhd(ji,jj,  jk) + rhd(ji,jj  ,jk-1) )  ) * r1_e2v(ji,jj)
                ! add to the general momentum trend
                ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk)
@@ -331,5 +381,4 @@
          END DO
       END DO
-
 
       ! partial steps correction at the last level  (use gru & grv computed in zpshde.F90)
@@ -338,10 +387,10 @@
             iku = mbku(ji,jj)
             ikv = mbkv(ji,jj)
-            zcoef2 = zcoef0 * MIN( fse3w(ji,jj,iku), fse3w(ji+1,jj  ,iku) )
-            zcoef3 = zcoef0 * MIN( fse3w(ji,jj,ikv), fse3w(ji  ,jj+1,ikv) )
+            zcoef2 = zcoef0 * MIN( e3w_n(ji,jj,iku), e3w_n(ji+1,jj  ,iku) )
+            zcoef3 = zcoef0 * MIN( e3w_n(ji,jj,ikv), e3w_n(ji  ,jj+1,ikv) )
             IF( iku > 1 ) THEN            ! on i-direction (level 2 or more)
                ua  (ji,jj,iku) = ua(ji,jj,iku) - zhpi(ji,jj,iku)         ! subtract old value
                zhpi(ji,jj,iku) = zhpi(ji,jj,iku-1)                   &   ! compute the new one
-                  &            + zcoef2 * ( rhd(ji+1,jj,iku-1) - rhd(ji,jj,iku-1) + gru(ji,jj) ) / e1u(ji,jj)
+                  &            + zcoef2 * ( rhd(ji+1,jj,iku-1) - rhd(ji,jj,iku-1) + gru(ji,jj) ) * r1_e1u(ji,jj)
                ua  (ji,jj,iku) = ua(ji,jj,iku) + zhpi(ji,jj,iku)         ! add the new one to the general momentum trend
             ENDIF
@@ -349,5 +398,5 @@
                va  (ji,jj,ikv) = va(ji,jj,ikv) - zhpj(ji,jj,ikv)         ! subtract old value
                zhpj(ji,jj,ikv) = zhpj(ji,jj,ikv-1)                   &   ! compute the new one
-                  &            + zcoef3 * ( rhd(ji,jj+1,ikv-1) - rhd(ji,jj,ikv-1) + grv(ji,jj) ) / e2v(ji,jj)
+                  &            + zcoef3 * ( rhd(ji,jj+1,ikv-1) - rhd(ji,jj,ikv-1) + grv(ji,jj) ) * r1_e2v(ji,jj)
                va  (ji,jj,ikv) = va(ji,jj,ikv) + zhpj(ji,jj,ikv)         ! add the new one to the general momentum trend
             ENDIF
@@ -355,7 +404,8 @@
       END DO
       !
-      CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zhpj )
+      CALL wrk_dealloc( jpi,jpj,jpk,   zhpi, zhpj )
       !
    END SUBROUTINE hpg_zps
+
 
    SUBROUTINE hpg_sco( kt )
@@ -391,25 +441,23 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   s-coordinate case, OPA original scheme used'
       ENDIF
-
-      ! Local constant initialization
+      !
       zcoef0 = - grav * 0.5_wp
-      ! To use density and not density anomaly
-      IF ( lk_vvl ) THEN   ;     znad = 1._wp          ! Variable volume
-      ELSE                 ;     znad = 0._wp         ! Fixed volume
+      IF ( ln_linssh ) THEN   ;   znad = 0._wp         ! Fixed    volume: density anomaly
+      ELSE                    ;   znad = 1._wp         ! Variable volume: density
       ENDIF
-
+      !
       ! Surface value
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.
             ! hydrostatic pressure gradient along s-surfaces
-            zhpi(ji,jj,1) = zcoef0 / e1u(ji,jj) * ( fse3w(ji+1,jj  ,1) * ( znad + rhd(ji+1,jj  ,1) )   &
-               &                                  - fse3w(ji  ,jj  ,1) * ( znad + rhd(ji  ,jj  ,1) ) )
-            zhpj(ji,jj,1) = zcoef0 / e2v(ji,jj) * ( fse3w(ji  ,jj+1,1) * ( znad + rhd(ji  ,jj+1,1) )   &
-               &                                  - fse3w(ji  ,jj  ,1) * ( znad + rhd(ji  ,jj  ,1) ) )
+            zhpi(ji,jj,1) = zcoef0 * (  e3w_n(ji+1,jj  ,1) * ( znad + rhd(ji+1,jj  ,1) )    &
+               &                      - e3w_n(ji  ,jj  ,1) * ( znad + rhd(ji  ,jj  ,1) )  ) * r1_e1u(ji,jj)
+            zhpj(ji,jj,1) = zcoef0 * (  e3w_n(ji  ,jj+1,1) * ( znad + rhd(ji  ,jj+1,1) )    &
+               &                      - e3w_n(ji  ,jj  ,1) * ( znad + rhd(ji  ,jj  ,1) )  ) * r1_e2v(ji,jj)
             ! s-coordinate pressure gradient correction
-            zuap = -zcoef0 * ( rhd   (ji+1,jj,1) + rhd   (ji,jj,1) + 2._wp * znad )   &
-               &           * ( fsde3w(ji+1,jj,1) - fsde3w(ji,jj,1) ) / e1u(ji,jj)
-            zvap = -zcoef0 * ( rhd   (ji,jj+1,1) + rhd   (ji,jj,1) + 2._wp * znad )   &
-               &           * ( fsde3w(ji,jj+1,1) - fsde3w(ji,jj,1) ) / e2v(ji,jj)
+            zuap = -zcoef0 * ( rhd    (ji+1,jj,1) + rhd    (ji,jj,1) + 2._wp * znad )   &
+               &           * ( gde3w_n(ji+1,jj,1) - gde3w_n(ji,jj,1) ) * r1_e1u(ji,jj)
+            zvap = -zcoef0 * ( rhd    (ji,jj+1,1) + rhd    (ji,jj,1) + 2._wp * znad )   &
+               &           * ( gde3w_n(ji,jj+1,1) - gde3w_n(ji,jj,1) ) * r1_e2v(ji,jj)
             ! add to the general momentum trend
             ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1) + zuap
@@ -423,15 +471,15 @@
             DO ji = fs_2, fs_jpim1   ! vector opt.
                ! hydrostatic pressure gradient along s-surfaces
-               zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) + zcoef0 / e1u(ji,jj)   &
-                  &           * (  fse3w(ji+1,jj,jk) * ( rhd(ji+1,jj,jk) + rhd(ji+1,jj,jk-1) + 2*znad )   &
-                  &              - fse3w(ji  ,jj,jk) * ( rhd(ji  ,jj,jk) + rhd(ji  ,jj,jk-1) + 2*znad )  )
-               zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1) + zcoef0 / e2v(ji,jj)   &
-                  &           * (  fse3w(ji,jj+1,jk) * ( rhd(ji,jj+1,jk) + rhd(ji,jj+1,jk-1) + 2*znad )   &
-                  &              - fse3w(ji,jj  ,jk) * ( rhd(ji,jj,  jk) + rhd(ji,jj  ,jk-1) + 2*znad )  )
+               zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) + zcoef0 * r1_e1u(ji,jj)   &
+                  &           * (  e3w_n(ji+1,jj,jk) * ( rhd(ji+1,jj,jk) + rhd(ji+1,jj,jk-1) + 2*znad )   &
+                  &              - e3w_n(ji  ,jj,jk) * ( rhd(ji  ,jj,jk) + rhd(ji  ,jj,jk-1) + 2*znad )  )
+               zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1) + zcoef0 * r1_e2v(ji,jj)   &
+                  &           * (  e3w_n(ji,jj+1,jk) * ( rhd(ji,jj+1,jk) + rhd(ji,jj+1,jk-1) + 2*znad )   &
+                  &              - e3w_n(ji,jj  ,jk) * ( rhd(ji,jj,  jk) + rhd(ji,jj  ,jk-1) + 2*znad )  )
                ! s-coordinate pressure gradient correction
-               zuap = -zcoef0 * ( rhd   (ji+1,jj  ,jk) + rhd   (ji,jj,jk) + 2._wp * znad )   &
-                  &           * ( fsde3w(ji+1,jj  ,jk) - fsde3w(ji,jj,jk) ) / e1u(ji,jj)
-               zvap = -zcoef0 * ( rhd   (ji  ,jj+1,jk) + rhd   (ji,jj,jk) + 2._wp * znad )   &
-                  &           * ( fsde3w(ji  ,jj+1,jk) - fsde3w(ji,jj,jk) ) / e2v(ji,jj)
+               zuap = -zcoef0 * ( rhd    (ji+1,jj  ,jk) + rhd    (ji,jj,jk) + 2._wp * znad )   &
+                  &           * ( gde3w_n(ji+1,jj  ,jk) - gde3w_n(ji,jj,jk) ) * r1_e1u(ji,jj)
+               zvap = -zcoef0 * ( rhd    (ji  ,jj+1,jk) + rhd    (ji,jj,jk) + 2._wp * znad )   &
+                  &           * ( gde3w_n(ji  ,jj+1,jk) - gde3w_n(ji,jj,jk) ) * r1_e2v(ji,jj)
                ! add to the general momentum trend
                ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk) + zuap
@@ -445,7 +493,8 @@
    END SUBROUTINE hpg_sco
 
+
    SUBROUTINE hpg_isf( kt )
       !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE hpg_sco  ***
+      !!                  ***  ROUTINE hpg_isf  ***
       !!
       !! ** Method  :   s-coordinate case. Jacobian scheme.
@@ -466,57 +515,26 @@
       INTEGER, INTENT(in) ::   kt    ! ocean time-step index
       !!
-      INTEGER  ::   ji, jj, jk, iku, ikv, ikt, iktp1i, iktp1j                 ! dummy loop indices
-      REAL(wp) ::   zcoef0, zuap, zvap, znad, ze3wu, ze3wv, zuapint, zvapint, zhpjint, zhpiint, zdzwt, zdzwtjp1, zdzwtip1             ! temporary scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::  zhpi, zhpj, zrhd
+      INTEGER  ::   ji, jj, jk, ikt, iktp1i, iktp1j   ! dummy loop indices
+      REAL(wp) ::   zcoef0, zuap, zvap, znad          ! temporary scalars
+      REAL(wp), POINTER, DIMENSION(:,:,:)   ::  zhpi, zhpj
       REAL(wp), POINTER, DIMENSION(:,:,:)   ::  ztstop
-      REAL(wp), POINTER, DIMENSION(:,:)     ::  ze3w, zp, zrhdtop_isf, zrhdtop_oce, ziceload, zdept, zpshpi, zpshpj
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi,jpj, 2, ztstop) 
-      CALL wrk_alloc( jpi,jpj,jpk, zhpi, zhpj, zrhd)
-      CALL wrk_alloc( jpi,jpj, ze3w, zp, zrhdtop_isf, zrhdtop_oce, ziceload, zdept, zpshpi, zpshpj) 
-      !
-     IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn:hpg_isf : hydrostatic pressure gradient trend for ice shelf'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   s-coordinate case, OPA original scheme used'
-      ENDIF
-
+      REAL(wp), POINTER, DIMENSION(:,:)     ::  zrhdtop_oce
+      !!----------------------------------------------------------------------
+      !
+      CALL wrk_alloc( jpi,jpj,  2, ztstop) 
+      CALL wrk_alloc( jpi,jpj,jpk, zhpi, zhpj)
+      CALL wrk_alloc( jpi,jpj,     zrhdtop_oce )
+      !
       ! Local constant initialization
       zcoef0 = - grav * 0.5_wp
+  
       ! To use density and not density anomaly
-!      IF ( lk_vvl ) THEN   ;     znad = 1._wp          ! Variable volume
-!      ELSE                 ;     znad = 0._wp         ! Fixed volume
-!      ENDIF
       znad=1._wp
+
       ! iniitialised to 0. zhpi zhpi 
       zhpi(:,:,:)=0._wp ; zhpj(:,:,:)=0._wp
 
-      ! Partial steps: top & bottom before horizontal gradient
-!jc      CALL zps_hde_isf( kt, jpts, tsn, gtsu, gtsv, gtui, gtvi,   & 
-!jc               &       rhd, gru , grv , aru , arv , gzu , gzv , ge3ru , ge3rv ,   &
-!jc               &      grui, grvi, arui, arvi, gzui, gzvi, ge3rui, ge3rvi  )
-
-!==================================================================================     
-!=====Compute iceload and contribution of the half first wet layer ================= 
-!===================================================================================
-
-      ! assume water displaced by the ice shelf is at T=-1.9 and S=34.4 (rude)
-      ztstop(:,:,1)=-1.9_wp ; ztstop(:,:,2)=34.4_wp
-
-      ! compute density of the water displaced by the ice shelf 
-      zrhd = rhd ! save rhd
-      DO jk = 1, jpk
-           zdept(:,:)=gdept_1d(jk)
-           CALL eos(ztstop(:,:,:),zdept(:,:),rhd(:,:,jk))
-      END DO
-      WHERE ( tmask(:,:,:) == 1._wp)
-        rhd(:,:,:) = zrhd(:,:,:) ! replace wet cell by the saved rhd
-      END WHERE
-      
-      ! compute rhd at the ice/oce interface (ice shelf side)
-      CALL eos(ztstop,risfdep,zrhdtop_isf)
-
       ! compute rhd at the ice/oce interface (ocean side)
+      ! usefull to reduce residual current in the test case ISOMIP with no melting
       DO ji=1,jpi
         DO jj=1,jpj
@@ -526,43 +544,31 @@
         END DO
       END DO
-      CALL eos(ztstop,risfdep,zrhdtop_oce)
-      !
-      ! Surface value + ice shelf gradient
-      ! compute pressure due to ice shelf load (used to compute hpgi/j for all the level from 1 to miku/v)
-      ziceload = 0._wp
-      DO jj = 1, jpj
-         DO ji = 1, jpi   ! vector opt.
-            ikt=mikt(ji,jj)
-            ziceload(ji,jj) = ziceload(ji,jj) + (znad + rhd(ji,jj,1) ) * fse3w(ji,jj,1) * (1._wp - tmask(ji,jj,1))
-            DO jk=2,ikt-1
-               ziceload(ji,jj) = ziceload(ji,jj) + (2._wp * znad + rhd(ji,jj,jk-1) + rhd(ji,jj,jk)) * fse3w(ji,jj,jk) &
-                  &                              * (1._wp - tmask(ji,jj,jk))
-            END DO
-            IF (ikt .GE. 2) ziceload(ji,jj) = ziceload(ji,jj) + (2._wp * znad + zrhdtop_isf(ji,jj) + rhd(ji,jj,ikt-1)) &
-                               &                              * ( risfdep(ji,jj) - gdept_1d(ikt-1) )
-         END DO
-      END DO
-      riceload(:,:) = 0.0_wp ; riceload(:,:)=ziceload(:,:)  ! need to be saved for diaar5
-      ! compute zp from z=0 to first T wet point (correction due to zps not yet applied)
+      CALL eos( ztstop, risfdep, zrhdtop_oce )
+
+!==================================================================================     
+!===== Compute surface value ===================================================== 
+!==================================================================================
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.
-            ikt=mikt(ji,jj) ; iktp1i=mikt(ji+1,jj); iktp1j=mikt(ji,jj+1)
+            ikt    = mikt(ji,jj)
+            iktp1i = mikt(ji+1,jj)
+            iktp1j = mikt(ji,jj+1)
             ! hydrostatic pressure gradient along s-surfaces and ice shelf pressure
             ! we assume ISF is in isostatic equilibrium
-            zhpi(ji,jj,1) = zcoef0 / e1u(ji,jj) * ( 0.5_wp * fse3w(ji+1,jj  ,iktp1i)                                    &
-               &                                  * ( 2._wp * znad + rhd(ji+1,jj  ,iktp1i) + zrhdtop_oce(ji+1,jj  ) )   &
-               &                                  - 0.5_wp * fse3w(ji  ,jj  ,ikt   )                                    &
-               &                                  * ( 2._wp * znad + rhd(ji  ,jj  ,ikt   ) + zrhdtop_oce(ji  ,jj  ) )   &
-               &                                  + ( ziceload(ji+1,jj) - ziceload(ji,jj))                              ) 
-            zhpj(ji,jj,1) = zcoef0 / e2v(ji,jj) * ( 0.5_wp * fse3w(ji  ,jj+1,iktp1j)                                    &
-               &                                  * ( 2._wp * znad + rhd(ji  ,jj+1,iktp1j) + zrhdtop_oce(ji  ,jj+1) )   &
-               &                                  - 0.5_wp * fse3w(ji  ,jj  ,ikt   )                                    & 
-               &                                  * ( 2._wp * znad + rhd(ji  ,jj  ,ikt   ) + zrhdtop_oce(ji  ,jj  ) )   &
-               &                                  + ( ziceload(ji,jj+1) - ziceload(ji,jj) )                             ) 
+            zhpi(ji,jj,1) = zcoef0 / e1u(ji,jj) * ( 0.5_wp * e3w_n(ji+1,jj,iktp1i)                                    &
+               &                                    * ( 2._wp * znad + rhd(ji+1,jj,iktp1i) + zrhdtop_oce(ji+1,jj) )   &
+               &                                  - 0.5_wp * e3w_n(ji,jj,ikt)                                         &
+               &                                    * ( 2._wp * znad + rhd(ji,jj,ikt) + zrhdtop_oce(ji,jj) )          &
+               &                                  + ( riceload(ji+1,jj) - riceload(ji,jj))                            ) 
+            zhpj(ji,jj,1) = zcoef0 / e2v(ji,jj) * ( 0.5_wp * e3w_n(ji,jj+1,iktp1j)                                    &
+               &                                    * ( 2._wp * znad + rhd(ji,jj+1,iktp1j) + zrhdtop_oce(ji,jj+1) )   &
+               &                                  - 0.5_wp * e3w_n(ji,jj,ikt)                                         & 
+               &                                    * ( 2._wp * znad + rhd(ji,jj,ikt) + zrhdtop_oce(ji,jj) )          &
+               &                                  + ( riceload(ji,jj+1) - riceload(ji,jj))                            ) 
             ! s-coordinate pressure gradient correction (=0 if z coordinate)
-            zuap = -zcoef0 * ( rhd   (ji+1,jj,1) + rhd   (ji,jj,1) + 2._wp * znad )   &
-               &           * ( fsde3w(ji+1,jj,1) - fsde3w(ji,jj,1) ) / e1u(ji,jj)
-            zvap = -zcoef0 * ( rhd   (ji,jj+1,1) + rhd   (ji,jj,1) + 2._wp * znad )   &
-               &           * ( fsde3w(ji,jj+1,1) - fsde3w(ji,jj,1) ) / e2v(ji,jj)
+            zuap = -zcoef0 * ( rhd    (ji+1,jj,1) + rhd    (ji,jj,1) + 2._wp * znad )   &
+               &           * ( gde3w_n(ji+1,jj,1) - gde3w_n(ji,jj,1) ) * r1_e1u(ji,jj)
+            zvap = -zcoef0 * ( rhd    (ji,jj+1,1) + rhd    (ji,jj,1) + 2._wp * znad )   &
+               &           * ( gde3w_n(ji,jj+1,1) - gde3w_n(ji,jj,1) ) * r1_e2v(ji,jj)
             ! add to the general momentum trend
             ua(ji,jj,1) = ua(ji,jj,1) + (zhpi(ji,jj,1) + zuap) * umask(ji,jj,1)
@@ -571,140 +577,32 @@
       END DO
 !==================================================================================     
-!===== Compute partial cell contribution for the top cell ========================= 
-!==================================================================================
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            iku = miku(ji,jj) ; 
-            zpshpi(ji,jj)=0.0_wp ; zpshpj(ji,jj)=0.0_wp
-            ze3wu  = (gdepw_0(ji+1,jj,iku+1) - gdept_0(ji+1,jj,iku)) - (gdepw_0(ji,jj,iku+1) - gdept_0(ji,jj,iku))
-            ! u direction
-            IF ( iku .GT. 1 ) THEN
-               ! case iku
-               zhpi(ji,jj,iku)   =  zcoef0 / e1u(ji,jj) * ze3wu                                            &
-                      &                                 * ( rhd    (ji+1,jj,iku) + rhd   (ji,jj,iku)       &
-                      &                                   + SIGN(1._wp,ze3wu) * grui(ji,jj) + 2._wp * znad )
-               ! corrective term ( = 0 if z coordinate )
-               zuap              = -zcoef0 * ( arui(ji,jj) + 2._wp * znad ) * gzui(ji,jj) / e1u(ji,jj)
-               ! zhpi will be added in interior loop
-               ua(ji,jj,iku)     = ua(ji,jj,iku) + zuap
-               ! in case of 2 cell water column, need to save the pressure gradient to compute the bottom pressure  
-               IF (mbku(ji,jj) == iku + 1) zpshpi(ji,jj)  = zhpi(ji,jj,iku)
-
-               ! case iku + 1 (remove the zphi term added in the interior loop and compute the one corrected for zps)
-               zhpiint        =  zcoef0 / e1u(ji,jj)                                                               &    
-                  &           * (  fse3w(ji+1,jj  ,iku+1) * ( (rhd(ji+1,jj,iku+1) + znad)                          &
-                  &                                         + (rhd(ji+1,jj,iku  ) + znad) ) * tmask(ji+1,jj,iku)   &
-                  &              - fse3w(ji  ,jj  ,iku+1) * ( (rhd(ji  ,jj,iku+1) + znad)                          &
-                  &                                         + (rhd(ji  ,jj,iku  ) + znad) ) * tmask(ji  ,jj,iku)   )
-               zhpi(ji,jj,iku+1) =  zcoef0 / e1u(ji,jj) * ge3rui(ji,jj) - zhpiint 
-            END IF
-               
-            ! v direction
-            ikv = mikv(ji,jj)
-            ze3wv  = (gdepw_0(ji,jj+1,ikv+1) - gdept_0(ji,jj+1,ikv)) - (gdepw_0(ji,jj,ikv+1) - gdept_0(ji,jj,ikv))
-            IF ( ikv .GT. 1 ) THEN
-               ! case ikv
-               zhpj(ji,jj,ikv)   =  zcoef0 / e2v(ji,jj) * ze3wv                                            &
-                     &                                  * ( rhd(ji,jj+1,ikv) + rhd   (ji,jj,ikv)           &
-                     &                                    + SIGN(1._wp,ze3wv) * grvi(ji,jj) + 2._wp * znad )
-               ! corrective term ( = 0 if z coordinate )
-               zvap              = -zcoef0 * ( arvi(ji,jj) + 2._wp * znad ) * gzvi(ji,jj) / e2v(ji,jj)
-               ! zhpi will be added in interior loop
-               va(ji,jj,ikv)      = va(ji,jj,ikv) + zvap
-               ! in case of 2 cell water column, need to save the pressure gradient to compute the bottom pressure  
-               IF (mbkv(ji,jj) == ikv + 1)  zpshpj(ji,jj)  =  zhpj(ji,jj,ikv) 
-               
-               ! case ikv + 1 (remove the zphj term added in the interior loop and compute the one corrected for zps)
-               zhpjint        =  zcoef0 / e2v(ji,jj)                                                              &
-                  &           * (  fse3w(ji  ,jj+1,ikv+1) * ( (rhd(ji,jj+1,ikv+1) + znad)                         &
-                  &                                       + (rhd(ji,jj+1,ikv  ) + znad) ) * tmask(ji,jj+1,ikv)    &
-                  &              - fse3w(ji  ,jj  ,ikv+1) * ( (rhd(ji,jj  ,ikv+1) + znad)                         &
-                  &                                       + (rhd(ji,jj  ,ikv  ) + znad) ) * tmask(ji,jj  ,ikv)  )
-               zhpj(ji,jj,ikv+1) =  zcoef0 / e2v(ji,jj) * ge3rvi(ji,jj) - zhpjint
-            END IF
-         END DO
-      END DO
-
-!==================================================================================     
 !===== Compute interior value ===================================================== 
 !==================================================================================
-
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            iku=miku(ji,jj); ikv=mikv(ji,jj)
-            DO jk = 2, jpkm1
+      ! interior value (2=<jk=<jpkm1)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
                ! hydrostatic pressure gradient along s-surfaces
-               ! zhpi is masked for the first wet cell  (contribution already done in the upper bloc)
-               zhpi(ji,jj,jk) = zhpi(ji,jj,jk) + zhpi(ji,jj,jk-1)                                                              &
-                  &                            + zcoef0 / e1u(ji,jj)                                                           &
-                  &                                     * ( fse3w(ji+1,jj  ,jk) * ( (rhd(ji+1,jj,jk  ) + znad)                 &
-                  &                                                     + (rhd(ji+1,jj,jk-1) + znad) ) * tmask(ji+1,jj,jk-1)   &
-                  &                                       - fse3w(ji  ,jj  ,jk) * ( (rhd(ji  ,jj,jk  ) + znad)                 &
-                  &                                                     + (rhd(ji  ,jj,jk-1) + znad) ) * tmask(ji  ,jj,jk-1)   ) 
+               zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) + zcoef0 / e1u(ji,jj)   &
+                  &           * (  e3w_n(ji+1,jj,jk) * ( rhd(ji+1,jj,jk) + rhd(ji+1,jj,jk-1) + 2*znad ) * wmask(ji+1,jj,jk)   &
+                  &              - e3w_n(ji  ,jj,jk) * ( rhd(ji  ,jj,jk) + rhd(ji  ,jj,jk-1) + 2*znad ) * wmask(ji  ,jj,jk)   )
+               zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1) + zcoef0 / e2v(ji,jj)   &
+                  &           * (  e3w_n(ji,jj+1,jk) * ( rhd(ji,jj+1,jk) + rhd(ji,jj+1,jk-1) + 2*znad ) * wmask(ji,jj+1,jk)   &
+                  &              - e3w_n(ji,jj  ,jk) * ( rhd(ji,jj,  jk) + rhd(ji,jj  ,jk-1) + 2*znad ) * wmask(ji,jj  ,jk)   )
                ! s-coordinate pressure gradient correction
-               ! corrective term, we mask this term for the first wet level beneath the ice shelf (contribution done in the upper bloc) 
-               zuap = - zcoef0 * ( rhd   (ji+1,jj  ,jk) + rhd   (ji,jj,jk) + 2._wp * znad )                    &
-                  &            * ( fsde3w(ji+1,jj  ,jk) - fsde3w(ji,jj,jk) ) / e1u(ji,jj) * umask(ji,jj,jk-1)
-               ua(ji,jj,jk) = ua(ji,jj,jk) + ( zhpi(ji,jj,jk) + zuap) * umask(ji,jj,jk)
-
-               ! hydrostatic pressure gradient along s-surfaces
-               ! zhpi is masked for the first wet cell  (contribution already done in the upper bloc)
-               zhpj(ji,jj,jk) = zhpj(ji,jj,jk) + zhpj(ji,jj,jk-1)                                                              &
-                  &                            + zcoef0 / e2v(ji,jj)                                                           &
-                  &                                     * ( fse3w(ji  ,jj+1,jk) * ( (rhd(ji,jj+1,jk  ) + znad)                 &
-                  &                                                     + (rhd(ji,jj+1,jk-1) + znad) ) * tmask(ji,jj+1,jk-1)   &
-                  &                                       - fse3w(ji  ,jj  ,jk) * ( (rhd(ji,jj  ,jk  ) + znad)                 &
-                  &                                                     + (rhd(ji,jj  ,jk-1) + znad) ) * tmask(ji,jj  ,jk-1)   )
-               ! s-coordinate pressure gradient correction
-               ! corrective term, we mask this term for the first wet level beneath the ice shelf (contribution done in the upper bloc)
-               zvap = - zcoef0 * ( rhd   (ji  ,jj+1,jk) + rhd   (ji,jj,jk) + 2._wp * znad )                     &
-                  &            * ( fsde3w(ji  ,jj+1,jk) - fsde3w(ji,jj,jk) ) / e2v(ji,jj) * vmask(ji,jj,jk-1)
+               zuap = -zcoef0 * ( rhd   (ji+1,jj  ,jk) + rhd   (ji,jj,jk) + 2._wp * znad )   &
+                  &           * ( gde3w_n(ji+1,jj  ,jk) - gde3w_n(ji,jj,jk) ) / e1u(ji,jj)
+               zvap = -zcoef0 * ( rhd   (ji  ,jj+1,jk) + rhd   (ji,jj,jk) + 2._wp * znad )   &
+                  &           * ( gde3w_n(ji  ,jj+1,jk) - gde3w_n(ji,jj,jk) ) / e2v(ji,jj)
                ! add to the general momentum trend
-               va(ji,jj,jk) = va(ji,jj,jk) + ( zhpj(ji,jj,jk) + zvap ) * vmask(ji,jj,jk)
+               ua(ji,jj,jk) = ua(ji,jj,jk) + (zhpi(ji,jj,jk) + zuap) * umask(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) + (zhpj(ji,jj,jk) + zvap) * vmask(ji,jj,jk)
             END DO
          END DO
       END DO
-
-!==================================================================================     
-!===== Compute bottom cell contribution (partial cell) ============================ 
-!==================================================================================
-
-      DO jj = 2, jpjm1
-         DO ji = 2, jpim1
-            iku = mbku(ji,jj)
-            ikv = mbkv(ji,jj)
-
-            IF (iku .GT. 1) THEN
-               ! remove old value (interior case)
-               zuap            = -zcoef0 * ( rhd   (ji+1,jj  ,iku) + rhd   (ji,jj,iku) + 2._wp * znad )   &
-                     &                   * ( fsde3w(ji+1,jj  ,iku) - fsde3w(ji,jj,iku) ) / e1u(ji,jj)
-               ua(ji,jj,iku)   = ua(ji,jj,iku) - zhpi(ji,jj,iku) - zuap
-               ! put new value
-               ! -zpshpi to avoid double contribution of the partial step in the top layer 
-               zuap            = -zcoef0 * ( aru(ji,jj) + 2._wp * znad ) * gzu(ji,jj)  / e1u(ji,jj)
-               zhpi(ji,jj,iku) =  zhpi(ji,jj,iku-1) + zcoef0 / e1u(ji,jj) * ge3ru(ji,jj) - zpshpi(ji,jj) 
-               ua(ji,jj,iku)   =  ua(ji,jj,iku) + zhpi(ji,jj,iku) + zuap
-            END IF
-            ! v direction
-            IF (ikv .GT. 1) THEN
-               ! remove old value (interior case)
-               zvap            = -zcoef0 * ( rhd   (ji  ,jj+1,ikv) + rhd   (ji,jj,ikv) + 2._wp * znad )   &
-                     &                   * ( fsde3w(ji  ,jj+1,ikv) - fsde3w(ji,jj,ikv) )   / e2v(ji,jj)
-               va(ji,jj,ikv)   = va(ji,jj,ikv) - zhpj(ji,jj,ikv) - zvap
-               ! put new value
-               ! -zpshpj to avoid double contribution of the partial step in the top layer 
-               zvap            = -zcoef0 * ( arv(ji,jj) + 2._wp * znad ) * gzv(ji,jj)     / e2v(ji,jj)
-               zhpj(ji,jj,ikv) =  zhpj(ji,jj,ikv-1) + zcoef0 / e2v(ji,jj) * ge3rv(ji,jj) - zpshpj(ji,jj)   
-               va(ji,jj,ikv)   =  va(ji,jj,ikv) + zhpj(ji,jj,ikv) + zvap
-            END IF
-         END DO
-      END DO
-     
-      ! set back to original density value into the ice shelf cell (maybe useless because it is masked)
-      rhd = zrhd
-      !
-      CALL wrk_dealloc( jpi,jpj,2, ztstop)
-      CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zhpj, zrhd)
-      CALL wrk_dealloc( jpi,jpj, ze3w, zp, zrhdtop_isf, zrhdtop_oce, ziceload, zdept, zpshpi, zpshpj)
+     !
+      CALL wrk_dealloc( jpi,jpj,2  , ztstop)
+      CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zhpj)
+      CALL wrk_dealloc( jpi,jpj    , zrhdtop_oce )
       !
    END SUBROUTINE hpg_isf
@@ -756,10 +654,10 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               drhoz(ji,jj,jk) = rhd   (ji  ,jj  ,jk) - rhd   (ji,jj,jk-1)
-               dzz  (ji,jj,jk) = fsde3w(ji  ,jj  ,jk) - fsde3w(ji,jj,jk-1)
-               drhox(ji,jj,jk) = rhd   (ji+1,jj  ,jk) - rhd   (ji,jj,jk  )
-               dzx  (ji,jj,jk) = fsde3w(ji+1,jj  ,jk) - fsde3w(ji,jj,jk  )
-               drhoy(ji,jj,jk) = rhd   (ji  ,jj+1,jk) - rhd   (ji,jj,jk  )
-               dzy  (ji,jj,jk) = fsde3w(ji  ,jj+1,jk) - fsde3w(ji,jj,jk  )
+               drhoz(ji,jj,jk) = rhd    (ji  ,jj  ,jk) - rhd    (ji,jj,jk-1)
+               dzz  (ji,jj,jk) = gde3w_n(ji  ,jj  ,jk) - gde3w_n(ji,jj,jk-1)
+               drhox(ji,jj,jk) = rhd    (ji+1,jj  ,jk) - rhd    (ji,jj,jk  )
+               dzx  (ji,jj,jk) = gde3w_n(ji+1,jj  ,jk) - gde3w_n(ji,jj,jk  )
+               drhoy(ji,jj,jk) = rhd    (ji  ,jj+1,jk) - rhd    (ji,jj,jk  )
+               dzy  (ji,jj,jk) = gde3w_n(ji  ,jj+1,jk) - gde3w_n(ji,jj,jk  )
             END DO
          END DO
@@ -843,14 +741,14 @@
       !-------------------------------------------------------------
 
-!!bug gm   :  e3w-de3w = 0.5*e3w  ....  and de3w(2)-de3w(1)=e3w(2) ....   to be verified
-!          true if de3w is really defined as the sum of the e3w scale factors as, it seems to me, it should be
+!!bug gm   :  e3w-gde3w = 0.5*e3w  ....  and gde3w(2)-gde3w(1)=e3w(2) ....   to be verified
+!          true if gde3w is really defined as the sum of the e3w scale factors as, it seems to me, it should be
 
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.
-            rho_k(ji,jj,1) = -grav * ( fse3w(ji,jj,1) - fsde3w(ji,jj,1) )               &
-               &                   * (  rhd(ji,jj,1)                                    &
-               &                     + 0.5_wp * ( rhd(ji,jj,2) - rhd(ji,jj,1) )         &
-               &                              * ( fse3w (ji,jj,1) - fsde3w(ji,jj,1) )   &
-               &                              / ( fsde3w(ji,jj,2) - fsde3w(ji,jj,1) )  )
+            rho_k(ji,jj,1) = -grav * ( e3w_n(ji,jj,1) - gde3w_n(ji,jj,1) )               &
+               &                   * (  rhd(ji,jj,1)                                     &
+               &                     + 0.5_wp * ( rhd    (ji,jj,2) - rhd    (ji,jj,1) )  &
+               &                              * ( e3w_n  (ji,jj,1) - gde3w_n(ji,jj,1) )  &
+               &                              / ( gde3w_n(ji,jj,2) - gde3w_n(ji,jj,1) )  )
          END DO
       END DO
@@ -863,29 +761,29 @@
             DO ji = fs_2, fs_jpim1   ! vector opt.
 
-               rho_k(ji,jj,jk) = zcoef0 * ( rhd   (ji,jj,jk) + rhd   (ji,jj,jk-1) )                                   &
-                  &                     * ( fsde3w(ji,jj,jk) - fsde3w(ji,jj,jk-1) )                                   &
-                  &            - grav * z1_10 * (                                                                     &
-                  &     ( drhow (ji,jj,jk) - drhow (ji,jj,jk-1) )                                                     &
-                  &   * ( fsde3w(ji,jj,jk) - fsde3w(ji,jj,jk-1) - z1_12 * ( dzw  (ji,jj,jk) + dzw  (ji,jj,jk-1) ) )   &
-                  &   - ( dzw   (ji,jj,jk) - dzw   (ji,jj,jk-1) )                                                     &
-                  &   * ( rhd   (ji,jj,jk) - rhd   (ji,jj,jk-1) - z1_12 * ( drhow(ji,jj,jk) + drhow(ji,jj,jk-1) ) )   &
+               rho_k(ji,jj,jk) = zcoef0 * ( rhd    (ji,jj,jk) + rhd    (ji,jj,jk-1) )                                   &
+                  &                     * ( gde3w_n(ji,jj,jk) - gde3w_n(ji,jj,jk-1) )                                   &
+                  &            - grav * z1_10 * (                                                                   &
+                  &     ( drhow  (ji,jj,jk) - drhow  (ji,jj,jk-1) )                                                     &
+                  &   * ( gde3w_n(ji,jj,jk) - gde3w_n(ji,jj,jk-1) - z1_12 * ( dzw  (ji,jj,jk) + dzw  (ji,jj,jk-1) ) )   &
+                  &   - ( dzw    (ji,jj,jk) - dzw    (ji,jj,jk-1) )                                                     &
+                  &   * ( rhd    (ji,jj,jk) - rhd    (ji,jj,jk-1) - z1_12 * ( drhow(ji,jj,jk) + drhow(ji,jj,jk-1) ) )   &
                   &                             )
 
-               rho_i(ji,jj,jk) = zcoef0 * ( rhd   (ji+1,jj,jk) + rhd   (ji,jj,jk) )                                   &
-                  &                     * ( fsde3w(ji+1,jj,jk) - fsde3w(ji,jj,jk) )                                   &
-                  &            - grav* z1_10 * (                                                                      &
-                  &     ( drhou (ji+1,jj,jk) - drhou (ji,jj,jk) )                                                     &
-                  &   * ( fsde3w(ji+1,jj,jk) - fsde3w(ji,jj,jk) - z1_12 * ( dzu  (ji+1,jj,jk) + dzu  (ji,jj,jk) ) )   &
-                  &   - ( dzu   (ji+1,jj,jk) - dzu   (ji,jj,jk) )                                                     &
-                  &   * ( rhd   (ji+1,jj,jk) - rhd   (ji,jj,jk) - z1_12 * ( drhou(ji+1,jj,jk) + drhou(ji,jj,jk) ) )   &
+               rho_i(ji,jj,jk) = zcoef0 * ( rhd    (ji+1,jj,jk) + rhd    (ji,jj,jk) )                                   &
+                  &                     * ( gde3w_n(ji+1,jj,jk) - gde3w_n(ji,jj,jk) )                                   &
+                  &            - grav* z1_10 * (                                                                    &
+                  &     ( drhou  (ji+1,jj,jk) - drhou  (ji,jj,jk) )                                                     &
+                  &   * ( gde3w_n(ji+1,jj,jk) - gde3w_n(ji,jj,jk) - z1_12 * ( dzu  (ji+1,jj,jk) + dzu  (ji,jj,jk) ) )   &
+                  &   - ( dzu    (ji+1,jj,jk) - dzu    (ji,jj,jk) )                                                     &
+                  &   * ( rhd    (ji+1,jj,jk) - rhd    (ji,jj,jk) - z1_12 * ( drhou(ji+1,jj,jk) + drhou(ji,jj,jk) ) )   &
                   &                            )
 
-               rho_j(ji,jj,jk) = zcoef0 * ( rhd   (ji,jj+1,jk) + rhd   (ji,jj,jk) )                                   &
-                  &                     * ( fsde3w(ji,jj+1,jk) - fsde3w(ji,jj,jk) )                                   &
-                  &            - grav* z1_10 * (                                                                      &
-                  &     ( drhov (ji,jj+1,jk) - drhov (ji,jj,jk) )                                                     &
-                  &   * ( fsde3w(ji,jj+1,jk) - fsde3w(ji,jj,jk) - z1_12 * ( dzv  (ji,jj+1,jk) + dzv  (ji,jj,jk) ) )   &
-                  &   - ( dzv   (ji,jj+1,jk) - dzv   (ji,jj,jk) )                                                     &
-                  &   * ( rhd   (ji,jj+1,jk) - rhd   (ji,jj,jk) - z1_12 * ( drhov(ji,jj+1,jk) + drhov(ji,jj,jk) ) )   &
+               rho_j(ji,jj,jk) = zcoef0 * ( rhd    (ji,jj+1,jk) + rhd    (ji,jj,jk) )                                 &
+                  &                     * ( gde3w_n(ji,jj+1,jk) - gde3w_n(ji,jj,jk) )                                   &
+                  &            - grav* z1_10 * (                                                                    &
+                  &     ( drhov  (ji,jj+1,jk) - drhov  (ji,jj,jk) )                                                     &
+                  &   * ( gde3w_n(ji,jj+1,jk) - gde3w_n(ji,jj,jk) - z1_12 * ( dzv  (ji,jj+1,jk) + dzv  (ji,jj,jk) ) )   &
+                  &   - ( dzv    (ji,jj+1,jk) - dzv    (ji,jj,jk) )                                                     &
+                  &   * ( rhd    (ji,jj+1,jk) - rhd    (ji,jj,jk) - z1_12 * ( drhov(ji,jj+1,jk) + drhov(ji,jj,jk) ) )   &
                   &                            )
 
@@ -903,6 +801,6 @@
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.
-            zhpi(ji,jj,1) = ( rho_k(ji+1,jj  ,1) - rho_k(ji,jj,1) - rho_i(ji,jj,1) ) / e1u(ji,jj)
-            zhpj(ji,jj,1) = ( rho_k(ji  ,jj+1,1) - rho_k(ji,jj,1) - rho_j(ji,jj,1) ) / e2v(ji,jj)
+            zhpi(ji,jj,1) = ( rho_k(ji+1,jj  ,1) - rho_k(ji,jj,1) - rho_i(ji,jj,1) ) * r1_e1u(ji,jj)
+            zhpj(ji,jj,1) = ( rho_k(ji  ,jj+1,1) - rho_k(ji,jj,1) - rho_j(ji,jj,1) ) * r1_e2v(ji,jj)
             ! add to the general momentum trend
             ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1)
@@ -920,8 +818,8 @@
                zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1)                                &
                   &           + (  ( rho_k(ji+1,jj,jk) - rho_k(ji,jj,jk  ) )    &
-                  &              - ( rho_i(ji  ,jj,jk) - rho_i(ji,jj,jk-1) )  ) / e1u(ji,jj)
+                  &              - ( rho_i(ji  ,jj,jk) - rho_i(ji,jj,jk-1) )  ) * r1_e1u(ji,jj)
                zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1)                                &
                   &           + (  ( rho_k(ji,jj+1,jk) - rho_k(ji,jj,jk  ) )    &
-                  &               -( rho_j(ji,jj  ,jk) - rho_j(ji,jj,jk-1) )  ) / e2v(ji,jj)
+                  &               -( rho_j(ji,jj  ,jk) - rho_j(ji,jj,jk-1) )  ) * r1_e2v(ji,jj)
                ! add to the general momentum trend
                ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk)
@@ -953,6 +851,6 @@
       !!
       INTEGER  ::   ji, jj, jk, jkk                 ! dummy loop indices
-      REAL(wp) ::   zcoef0, znad                    ! temporary scalars
-      !!
+      REAL(wp) ::   zcoef0, znad                    ! local scalars
+      !
       !! The local variables for the correction term
       INTEGER  :: jk1, jis, jid, jjs, jjd
@@ -965,7 +863,7 @@
       !!----------------------------------------------------------------------
       !
-      CALL wrk_alloc( jpi,jpj,jpk, zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp )
-      CALL wrk_alloc( jpi,jpj,jpk, zdept, zrhh )
-      CALL wrk_alloc( jpi,jpj, zsshu_n, zsshv_n )
+      CALL wrk_alloc( jpi,jpj,jpk,   zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp )
+      CALL wrk_alloc( jpi,jpj,jpk,   zdept, zrhh )
+      CALL wrk_alloc( jpi,jpj,       zsshu_n, zsshv_n )
       !
       IF( kt == nit000 ) THEN
@@ -975,9 +873,8 @@
       ENDIF
 
-      !!----------------------------------------------------------------------
       ! Local constant initialization
       zcoef0 = - grav
-      znad = 0.0_wp
-      IF( lk_vvl ) znad = 1._wp
+      znad = 1._wp
+      IF( ln_linssh )   znad = 0._wp
 
       ! Clean 3-D work arrays
@@ -989,10 +886,10 @@
         DO ji = 1, jpi
           jk = mbathy(ji,jj)
-          IF( jk <= 0 ) THEN; zrhh(ji,jj,:) = 0._wp
-          ELSE IF(jk == 1) THEN; zrhh(ji,jj, jk+1:jpk) = rhd(ji,jj,jk)
-          ELSE IF(jk < jpkm1) THEN
+          IF(     jk <=  0   ) THEN   ;   zrhh(ji,jj,    :   ) = 0._wp
+          ELSEIF( jk ==  1   ) THEN   ;   zrhh(ji,jj,jk+1:jpk) = rhd(ji,jj,jk)
+          ELSEIF( jk < jpkm1 ) THEN
              DO jkk = jk+1, jpk
-                zrhh(ji,jj,jkk) = interp1(fsde3w(ji,jj,jkk),   fsde3w(ji,jj,jkk-1), &
-                                         fsde3w(ji,jj,jkk-2), rhd(ji,jj,jkk-1), rhd(ji,jj,jkk-2))
+                zrhh(ji,jj,jkk) = interp1(gde3w_n(ji,jj,jkk  ), gde3w_n(ji,jj,jkk-1),   &
+                   &                      gde3w_n(ji,jj,jkk-2), rhd    (ji,jj,jkk-1), rhd(ji,jj,jkk-2))
              END DO
           ENDIF
@@ -1003,5 +900,5 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            zdept(ji,jj,1) = 0.5_wp * fse3w(ji,jj,1) - sshn(ji,jj) * znad
+            zdept(ji,jj,1) = 0.5_wp * e3w_n(ji,jj,1) - sshn(ji,jj) * znad
          END DO
       END DO
@@ -1010,5 +907,5 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               zdept(ji,jj,jk) = zdept(ji,jj,jk-1) + fse3w(ji,jj,jk)
+               zdept(ji,jj,jk) = zdept(ji,jj,jk-1) + e3w_n(ji,jj,jk)
             END DO
          END DO
@@ -1021,15 +918,14 @@
       ! constrained cubic spline interpolation
       ! rho(z) = asp + bsp*z + csp*z^2 + dsp*z^3
-      CALL cspline(fsp,xsp,asp,bsp,csp,dsp,polynomial_type)
+      CALL cspline( fsp, xsp, asp, bsp, csp, dsp, polynomial_type )
 
       ! Integrate the hydrostatic pressure "zhpi(:,:,:)" at "T(ji,jj,1)"
       DO jj = 2, jpj
         DO ji = 2, jpi
-          zrhdt1 = zrhh(ji,jj,1) - interp3(zdept(ji,jj,1),asp(ji,jj,1), &
-                                         bsp(ji,jj,1),   csp(ji,jj,1), &
-                                         dsp(ji,jj,1) ) * 0.25_wp * fse3w(ji,jj,1)
+          zrhdt1 = zrhh(ji,jj,1) - interp3( zdept(ji,jj,1), asp(ji,jj,1), bsp(ji,jj,1),  &
+             &                                              csp(ji,jj,1), dsp(ji,jj,1) ) * 0.25_wp * e3w_n(ji,jj,1)
 
           ! assuming linear profile across the top half surface layer
-          zhpi(ji,jj,1) =  0.5_wp * fse3w(ji,jj,1) * zrhdt1
+          zhpi(ji,jj,1) =  0.5_wp * e3w_n(ji,jj,1) * zrhdt1
         END DO
       END DO
@@ -1039,8 +935,8 @@
         DO jj = 2, jpj
           DO ji = 2, jpi
-            zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) +                          &
-                             integ_spline(zdept(ji,jj,jk-1), zdept(ji,jj,jk),&
-                                    asp(ji,jj,jk-1),    bsp(ji,jj,jk-1), &
-                                    csp(ji,jj,jk-1),    dsp(ji,jj,jk-1))
+            zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) +                                  &
+               &             integ_spline( zdept(ji,jj,jk-1), zdept(ji,jj,jk),   &
+               &                           asp  (ji,jj,jk-1), bsp  (ji,jj,jk-1), &
+               &                           csp  (ji,jj,jk-1), dsp  (ji,jj,jk-1)  )
           END DO
         END DO
@@ -1052,4 +948,10 @@
       DO jj = 2, jpjm1
         DO ji = 2, jpim1
+!!gm BUG ?    if it is ssh at u- & v-point then it should be:
+!          zsshu_n(ji,jj) = (e1e2t(ji,jj) * sshn(ji,jj) + e1e2t(ji+1,jj) * sshn(ji+1,jj)) * &
+!                         & r1_e1e2u(ji,jj) * umask(ji,jj,1) * 0.5_wp 
+!          zsshv_n(ji,jj) = (e1e2t(ji,jj) * sshn(ji,jj) + e1e2t(ji,jj+1) * sshn(ji,jj+1)) * &
+!                         & r1_e1e2v(ji,jj) * vmask(ji,jj,1) * 0.5_wp 
+!!gm not this:
           zsshu_n(ji,jj) = (e1e2u(ji,jj) * sshn(ji,jj) + e1e2u(ji+1, jj) * sshn(ji+1,jj)) * &
                          & r1_e1e2u(ji,jj) * umask(ji,jj,1) * 0.5_wp 
@@ -1061,6 +963,6 @@
       DO jj = 2, jpjm1
         DO ji = 2, jpim1
-          zu(ji,jj,1) = - ( fse3u(ji,jj,1) - zsshu_n(ji,jj) * znad) 
-          zv(ji,jj,1) = - ( fse3v(ji,jj,1) - zsshv_n(ji,jj) * znad)
+          zu(ji,jj,1) = - ( e3u_n(ji,jj,1) - zsshu_n(ji,jj) * znad) 
+          zv(ji,jj,1) = - ( e3v_n(ji,jj,1) - zsshv_n(ji,jj) * znad)
         END DO
       END DO
@@ -1069,6 +971,6 @@
         DO jj = 2, jpjm1
           DO ji = 2, jpim1
-            zu(ji,jj,jk) = zu(ji,jj,jk-1)- fse3u(ji,jj,jk)
-            zv(ji,jj,jk) = zv(ji,jj,jk-1)- fse3v(ji,jj,jk)
+            zu(ji,jj,jk) = zu(ji,jj,jk-1) - e3u_n(ji,jj,jk)
+            zv(ji,jj,jk) = zv(ji,jj,jk-1) - e3v_n(ji,jj,jk)
           END DO
         END DO
@@ -1078,6 +980,6 @@
         DO jj = 2, jpjm1
           DO ji = 2, jpim1
-            zu(ji,jj,jk) = zu(ji,jj,jk) + 0.5_wp * fse3u(ji,jj,jk)
-            zv(ji,jj,jk) = zv(ji,jj,jk) + 0.5_wp * fse3v(ji,jj,jk)
+            zu(ji,jj,jk) = zu(ji,jj,jk) + 0.5_wp * e3u_n(ji,jj,jk)
+            zv(ji,jj,jk) = zv(ji,jj,jk) + 0.5_wp * e3v_n(ji,jj,jk)
           END DO
         END DO
@@ -1087,8 +989,8 @@
         DO jj = 2, jpjm1
           DO ji = 2, jpim1
-            zu(ji,jj,jk) = min(zu(ji,jj,jk), max(-zdept(ji,jj,jk), -zdept(ji+1,jj,jk)))
-            zu(ji,jj,jk) = max(zu(ji,jj,jk), min(-zdept(ji,jj,jk), -zdept(ji+1,jj,jk)))
-            zv(ji,jj,jk) = min(zv(ji,jj,jk), max(-zdept(ji,jj,jk), -zdept(ji,jj+1,jk)))
-            zv(ji,jj,jk) = max(zv(ji,jj,jk), min(-zdept(ji,jj,jk), -zdept(ji,jj+1,jk)))
+            zu(ji,jj,jk) = MIN(  zu(ji,jj,jk) , MAX( -zdept(ji,jj,jk) , -zdept(ji+1,jj,jk) )  )
+            zu(ji,jj,jk) = MAX(  zu(ji,jj,jk) , MIN( -zdept(ji,jj,jk) , -zdept(ji+1,jj,jk) )  )
+            zv(ji,jj,jk) = MIN(  zv(ji,jj,jk) , MAX( -zdept(ji,jj,jk) , -zdept(ji,jj+1,jk) )  )
+            zv(ji,jj,jk) = MAX(  zv(ji,jj,jk) , MIN( -zdept(ji,jj,jk) , -zdept(ji,jj+1,jk) )  )
           END DO
         END DO
@@ -1148,14 +1050,14 @@
                ! update the momentum trends in u direction
 
-               zdpdx1 = zcoef0 / e1u(ji,jj) * (zhpi(ji+1,jj,jk) - zhpi(ji,jj,jk))
-               IF( lk_vvl ) THEN
-                 zdpdx2 = zcoef0 / e1u(ji,jj) * &
-                         ( REAL(jis-jid, wp) * (zpwes + zpwed) + (sshn(ji+1,jj)-sshn(ji,jj)) )
+               zdpdx1 = zcoef0 * r1_e1u(ji,jj) * ( zhpi(ji+1,jj,jk) - zhpi(ji,jj,jk) )
+               IF( .NOT.ln_linssh ) THEN
+                 zdpdx2 = zcoef0 * r1_e1u(ji,jj) * &
+                    &    ( REAL(jis-jid, wp) * (zpwes + zpwed) + (sshn(ji+1,jj)-sshn(ji,jj)) )
                 ELSE
-                 zdpdx2 = zcoef0 / e1u(ji,jj) * REAL(jis-jid, wp) * (zpwes + zpwed)
+                 zdpdx2 = zcoef0 * r1_e1u(ji,jj) * REAL(jis-jid, wp) * (zpwes + zpwed)
                ENDIF
-
-               ua(ji,jj,jk) = ua(ji,jj,jk) + (zdpdx1 + zdpdx2) * &
-               &           umask(ji,jj,jk) * tmask(ji,jj,jk) * tmask(ji+1,jj,jk)
+!!gm  Since umask(ji,:,:) = tmask(ji,:,:) * tmask(ji+1,:,:)  by definition
+!!gm      in the line below only * umask(ji,jj,jk)  is needed !!
+               ua(ji,jj,jk) = ua(ji,jj,jk) + (zdpdx1 + zdpdx2) * umask(ji,jj,jk) * tmask(ji,jj,jk) * tmask(ji+1,jj,jk)
             ENDIF
 
@@ -1205,29 +1107,28 @@
                ! update the momentum trends in v direction
 
-               zdpdy1 = zcoef0 / e2v(ji,jj) * (zhpi(ji,jj+1,jk) - zhpi(ji,jj,jk))
-               IF( lk_vvl ) THEN
-                   zdpdy2 = zcoef0 / e2v(ji,jj) * &
-                           ( REAL(jjs-jjd, wp) * (zpnss + zpnsd) + (sshn(ji,jj+1)-sshn(ji,jj)) )
+               zdpdy1 = zcoef0 * r1_e2v(ji,jj) * ( zhpi(ji,jj+1,jk) - zhpi(ji,jj,jk) )
+               IF( .NOT.ln_linssh ) THEN
+                  zdpdy2 = zcoef0 * r1_e2v(ji,jj) * &
+                          ( REAL(jjs-jjd, wp) * (zpnss + zpnsd) + (sshn(ji,jj+1)-sshn(ji,jj)) )
                ELSE
-                   zdpdy2 = zcoef0 / e2v(ji,jj) * REAL(jjs-jjd, wp) * (zpnss + zpnsd )
+                  zdpdy2 = zcoef0 * r1_e2v(ji,jj) * REAL(jjs-jjd, wp) * (zpnss + zpnsd )
                ENDIF
-
-               va(ji,jj,jk) = va(ji,jj,jk) + (zdpdy1 + zdpdy2)*&
-               &              vmask(ji,jj,jk)*tmask(ji,jj,jk)*tmask(ji,jj+1,jk)
+!!gm  Since vmask(:,jj,:) = tmask(:,jj,:) * tmask(:,jj+1,:)  by definition
+!!gm      in the line below only * vmask(ji,jj,jk)  is needed !!
+               va(ji,jj,jk) = va(ji,jj,jk) + ( zdpdy1 + zdpdy2 ) * vmask(ji,jj,jk)*tmask(ji,jj,jk)*tmask(ji,jj+1,jk)
             ENDIF
-
-
-           END DO
-        END DO
-      END DO
-      !
-      CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp )
-      CALL wrk_dealloc( jpi,jpj,jpk, zdept, zrhh )
-      CALL wrk_dealloc( jpi,jpj, zsshu_n, zsshv_n )
+               !
+            END DO
+         END DO
+      END DO
+      !
+      CALL wrk_dealloc( jpi,jpj,jpk,   zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp )
+      CALL wrk_dealloc( jpi,jpj,jpk,   zdept, zrhh )
+      CALL wrk_dealloc( jpi,jpj,       zsshu_n, zsshv_n )
       !
    END SUBROUTINE hpg_prj
 
 
-   SUBROUTINE cspline(fsp, xsp, asp, bsp, csp, dsp, polynomial_type)
+   SUBROUTINE cspline( fsp, xsp, asp, bsp, csp, dsp, polynomial_type )
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE cspline  ***
@@ -1239,10 +1140,7 @@
       !! Reference: CJC Kruger, Constrained Cubic Spline Interpoltation
       !!----------------------------------------------------------------------
-      IMPLICIT NONE
-      REAL(wp), DIMENSION(:,:,:), INTENT(in)  :: fsp, xsp           ! value and coordinate
-      REAL(wp), DIMENSION(:,:,:), INTENT(out) :: asp, bsp, csp, dsp ! coefficients of
-                                                                    ! the interpoated function
-      INTEGER, INTENT(in) :: polynomial_type                        ! 1: cubic spline
-                                                                    ! 2: Linear
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   fsp, xsp           ! value and coordinate
+      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   asp, bsp, csp, dsp ! coefficients of the interpoated function
+      INTEGER                   , INTENT(in   ) ::   polynomial_type    ! 1: cubic spline   ;   2: Linear
       !
       INTEGER  ::   ji, jj, jk                 ! dummy loop indices
@@ -1252,10 +1150,10 @@
       REAL(wp) ::   zdf(size(fsp,3))
       !!----------------------------------------------------------------------
-
+      !
+!!gm  WHAT !!!!!   THIS IS VERY DANGEROUS !!!!!  
       jpi   = size(fsp,1)
       jpj   = size(fsp,2)
       jpkm1 = size(fsp,3) - 1
-
-
+      !
       IF (polynomial_type == 1) THEN     ! Constrained Cubic Spline
          DO ji = 1, jpi
@@ -1290,8 +1188,7 @@
 
                zdf(1)     = 1.5_wp * ( fsp(ji,jj,2) - fsp(ji,jj,1) ) / &
-                          &          ( xsp(ji,jj,2) - xsp(ji,jj,1) ) -  0.5_wp * zdf(2)
+                          &          ( xsp(ji,jj,2) - xsp(ji,jj,1) )           -  0.5_wp * zdf(2)
                zdf(jpkm1) = 1.5_wp * ( fsp(ji,jj,jpkm1) - fsp(ji,jj,jpkm1-1) ) / &
-                          &          ( xsp(ji,jj,jpkm1) - xsp(ji,jj,jpkm1-1) ) - &
-                          & 0.5_wp * zdf(jpkm1 - 1)
+                          &          ( xsp(ji,jj,jpkm1) - xsp(ji,jj,jpkm1-1) ) - 0.5_wp * zdf(jpkm1 - 1)
 
                DO jk = 1, jpkm1 - 1
@@ -1316,5 +1213,5 @@
          END DO
 
-      ELSE IF (polynomial_type == 2) THEN     ! Linear
+      ELSEIF ( polynomial_type == 2 ) THEN     ! Linear
          DO ji = 1, jpi
             DO jj = 1, jpj
@@ -1347,21 +1244,20 @@
       !!                extrapolation is also permitted (no value limit)
       !!----------------------------------------------------------------------
-      IMPLICIT NONE
       REAL(wp), INTENT(in) ::  x, xl, xr, fl, fr
       REAL(wp)             ::  f ! result of the interpolation (extrapolation)
       REAL(wp)             ::  zdeltx
       !!----------------------------------------------------------------------
-
+      !
       zdeltx = xr - xl
-      IF(abs(zdeltx) <= 10._wp * EPSILON(x)) THEN
-        f = 0.5_wp * (fl + fr)
+      IF( abs(zdeltx) <= 10._wp * EPSILON(x) ) THEN
+         f = 0.5_wp * (fl + fr)
       ELSE
-        f = ( (x - xl ) * fr - ( x - xr ) * fl ) / zdeltx
+         f = ( (x - xl ) * fr - ( x - xr ) * fl ) / zdeltx
       ENDIF
-
+      !
    END FUNCTION interp1
 
 
-   FUNCTION interp2(x, a, b, c, d)  RESULT(f)
+   FUNCTION interp2( x, a, b, c, d )  RESULT(f)
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE interp1  ***
@@ -1372,15 +1268,14 @@
       !!
       !!----------------------------------------------------------------------
-      IMPLICIT NONE
       REAL(wp), INTENT(in) ::  x, a, b, c, d
       REAL(wp)             ::  f ! value from the interpolation
       !!----------------------------------------------------------------------
-
+      !
       f = a + x* ( b + x * ( c + d * x ) )
-
+      !
    END FUNCTION interp2
 
 
-   FUNCTION interp3(x, a, b, c, d)  RESULT(f)
+   FUNCTION interp3( x, a, b, c, d )  RESULT(f)
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE interp1  ***
@@ -1392,15 +1287,14 @@
       !!
       !!----------------------------------------------------------------------
-      IMPLICIT NONE
       REAL(wp), INTENT(in) ::  x, a, b, c, d
       REAL(wp)             ::  f ! value from the interpolation
       !!----------------------------------------------------------------------
-
+      !
       f = b + x * ( 2._wp * c + 3._wp * d * x)
-
+      !
    END FUNCTION interp3
 
 
-   FUNCTION integ_spline(xl, xr, a, b, c, d)  RESULT(f)
+   FUNCTION integ_spline( xl, xr, a, b, c, d )  RESULT(f)
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE interp1  ***
@@ -1411,17 +1305,16 @@
       !!
       !!----------------------------------------------------------------------
-      IMPLICIT NONE
       REAL(wp), INTENT(in) ::  xl, xr, a, b, c, d
       REAL(wp)             ::  za1, za2, za3
       REAL(wp)             ::  f                   ! integration result
       !!----------------------------------------------------------------------
-
+      !
       za1 = 0.5_wp * b
       za2 = c / 3.0_wp
       za3 = 0.25_wp * d
-
+      !
       f  = xr * ( a + xr * ( za1 + xr * ( za2 + za3 * xr ) ) ) - &
          & xl * ( a + xl * ( za1 + xl * ( za2 + za3 * xl ) ) )
-
+      !
    END FUNCTION integ_spline
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf.F90	(revision 6140)
@@ -36,5 +36,5 @@
    PUBLIC   dyn_ldf_init  ! called by opa  module 
 
-   !                      ! Flag to control the type of lateral viscous operator
+   !                      ! Parameter to control the type of lateral viscous operator
    INTEGER, PARAMETER, PUBLIC ::   np_ERROR  =-10   ! error in setting the operator
    INTEGER, PARAMETER, PUBLIC ::   np_no_ldf = 00   ! without operator (i.e. no lateral viscous trend)
@@ -46,5 +46,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_iso.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_iso.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_iso.F90	(revision 6140)
@@ -41,5 +41,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -135,8 +134,8 @@
             DO jj = 2, jpjm1
                DO ji = 2, jpim1
-                  uslp (ji,jj,jk) = - ( fsdept_b(ji+1,jj,jk) - fsdept_b(ji ,jj ,jk) ) * r1_e1u(ji,jj) * umask(ji,jj,jk)
-                  vslp (ji,jj,jk) = - ( fsdept_b(ji,jj+1,jk) - fsdept_b(ji ,jj ,jk) ) * r1_e2v(ji,jj) * vmask(ji,jj,jk)
-                  wslpi(ji,jj,jk) = - ( fsdepw_b(ji+1,jj,jk) - fsdepw_b(ji-1,jj,jk) ) * r1_e1t(ji,jj) * tmask(ji,jj,jk) * 0.5
-                  wslpj(ji,jj,jk) = - ( fsdepw_b(ji,jj+1,jk) - fsdepw_b(ji,jj-1,jk) ) * r1_e2t(ji,jj) * tmask(ji,jj,jk) * 0.5
+                  uslp (ji,jj,jk) = - ( gdept_b(ji+1,jj,jk) - gdept_b(ji ,jj ,jk) ) * r1_e1u(ji,jj) * umask(ji,jj,jk)
+                  vslp (ji,jj,jk) = - ( gdept_b(ji,jj+1,jk) - gdept_b(ji ,jj ,jk) ) * r1_e2v(ji,jj) * vmask(ji,jj,jk)
+                  wslpi(ji,jj,jk) = - ( gdepw_b(ji+1,jj,jk) - gdepw_b(ji-1,jj,jk) ) * r1_e1t(ji,jj) * tmask(ji,jj,jk) * 0.5
+                  wslpj(ji,jj,jk) = - ( gdepw_b(ji,jj+1,jk) - gdepw_b(ji,jj-1,jk) ) * r1_e2t(ji,jj) * tmask(ji,jj,jk) * 0.5
                END DO
             END DO
@@ -183,5 +182,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, jpi   ! vector opt.
-                  zabe1 = ( ahmt(ji,jj,jk)+rn_ahm_b ) * e2t(ji,jj) * MIN( fse3u(ji,jj,jk), fse3u(ji-1,jj,jk) ) * r1_e1t(ji,jj)
+                  zabe1 = ( ahmt(ji,jj,jk)+rn_ahm_b ) * e2t(ji,jj) * MIN( e3u_n(ji,jj,jk), e3u_n(ji-1,jj,jk) ) * r1_e1t(ji,jj)
 
                   zmskt = 1._wp / MAX(   umask(ji-1,jj,jk  )+umask(ji,jj,jk+1)     &
@@ -198,5 +197,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, jpi   ! vector opt.
-                  zabe1 = ( ahmt(ji,jj,jk)+rn_ahm_b ) * e2t(ji,jj) * fse3t(ji,jj,jk) * r1_e1t(ji,jj)
+                  zabe1 = ( ahmt(ji,jj,jk)+rn_ahm_b ) * e2t(ji,jj) * e3t_n(ji,jj,jk) * r1_e1t(ji,jj)
 
                   zmskt = 1._wp / MAX(   umask(ji-1,jj,jk  ) + umask(ji,jj,jk+1)     &
@@ -215,5 +214,5 @@
          DO jj = 1, jpjm1
             DO ji = 1, fs_jpim1   ! vector opt.
-               zabe2 = ( ahmf(ji,jj,jk) + rn_ahm_b ) * e1f(ji,jj) * fse3f(ji,jj,jk) * r1_e2f(ji,jj)
+               zabe2 = ( ahmf(ji,jj,jk) + rn_ahm_b ) * e1f(ji,jj) * e3f_n(ji,jj,jk) * r1_e2f(ji,jj)
 
                zmskf = 1._wp / MAX(   umask(ji,jj+1,jk  )+umask(ji,jj,jk+1)     &
@@ -236,5 +235,5 @@
          DO jj = 2, jpjm1
             DO ji = 1, fs_jpim1   ! vector opt.
-               zabe1 = ( ahmf(ji,jj,jk) + rn_ahm_b ) * e2f(ji,jj) * fse3f(ji,jj,jk) * r1_e1f(ji,jj)
+               zabe1 = ( ahmf(ji,jj,jk) + rn_ahm_b ) * e2f(ji,jj) * e3f_n(ji,jj,jk) * r1_e1f(ji,jj)
 
                zmskf = 1._wp / MAX(  vmask(ji+1,jj,jk  )+vmask(ji,jj,jk+1)     &
@@ -253,5 +252,5 @@
             DO jj = 2, jpj
                DO ji = 1, fs_jpim1   ! vector opt.
-                  zabe2 = ( ahmt(ji,jj,jk)+rn_ahm_b ) * e1t(ji,jj) * MIN( fse3v(ji,jj,jk), fse3v(ji,jj-1,jk) ) * r1_e2t(ji,jj)
+                  zabe2 = ( ahmt(ji,jj,jk)+rn_ahm_b ) * e1t(ji,jj) * MIN( e3v_n(ji,jj,jk), e3v_n(ji,jj-1,jk) ) * r1_e2t(ji,jj)
 
                   zmskt = 1._wp / MAX(  vmask(ji,jj-1,jk  )+vmask(ji,jj,jk+1)     &
@@ -268,5 +267,5 @@
             DO jj = 2, jpj
                DO ji = 1, fs_jpim1   ! vector opt.
-                  zabe2 = ( ahmt(ji,jj,jk)+rn_ahm_b ) * e1t(ji,jj) * fse3t(ji,jj,jk) * r1_e2t(ji,jj)
+                  zabe2 = ( ahmt(ji,jj,jk)+rn_ahm_b ) * e1t(ji,jj) * e3t_n(ji,jj,jk) * r1_e2t(ji,jj)
 
                   zmskt = 1./MAX(  vmask(ji,jj-1,jk  )+vmask(ji,jj,jk+1)   &
@@ -287,8 +286,8 @@
          DO jj = 2, jpjm1
             DO ji = 2, jpim1          !!gm Question vectop possible??? !!bug
-               ua(ji,jj,jk) = ua(ji,jj,jk) + ( ziut(ji+1,jj) - ziut(ji,jj  )    &
-                  &                          + zjuf(ji  ,jj) - zjuf(ji,jj-1)  ) / ( e1e2u(ji,jj) * fse3u(ji,jj,jk) )
-               va(ji,jj,jk) = va(ji,jj,jk) + ( zivf(ji,jj  ) - zivf(ji-1,jj)    &
-                  &                          + zjvt(ji,jj+1) - zjvt(ji,jj  )  ) / ( e1e2v(ji,jj) * fse3v(ji,jj,jk) )
+               ua(ji,jj,jk) = ua(ji,jj,jk) + (  ziut(ji+1,jj) - ziut(ji,jj  )    &
+                  &                           + zjuf(ji  ,jj) - zjuf(ji,jj-1)  ) * r1_e1e2u(ji,jj) / e3u_n(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) + (  zivf(ji,jj  ) - zivf(ji-1,jj)    &
+                  &                           + zjvt(ji,jj+1) - zjvt(ji,jj  )  ) * r1_e1e2v(ji,jj) / e3v_n(ji,jj,jk)
             END DO
          END DO
@@ -403,6 +402,6 @@
          DO jk = 1, jpkm1
             DO ji = 2, jpim1
-               ua(ji,jj,jk) = ua(ji,jj,jk) + ( zfuw(ji,jk) - zfuw(ji,jk+1) ) / ( e1e2u(ji,jj) * fse3u(ji,jj,jk) )
-               va(ji,jj,jk) = va(ji,jj,jk) + ( zfvw(ji,jk) - zfvw(ji,jk+1) ) / ( e1e2v(ji,jj) * fse3v(ji,jj,jk) )
+               ua(ji,jj,jk) = ua(ji,jj,jk) + ( zfuw(ji,jk) - zfuw(ji,jk+1) ) * r1_e1e2u(ji,jj) / e3u_n(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) + ( zfvw(ji,jk) - zfvw(ji,jk+1) ) * r1_e1e2v(ji,jj) / e3v_n(ji,jj,jk)
             END DO
          END DO
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_lap_blp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_lap_blp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_lap_blp.F90	(revision 6140)
@@ -4,11 +4,5 @@
    !! Ocean dynamics:  lateral viscosity trend (laplacian and bilaplacian)
    !!======================================================================
-   !! History :  OPA  ! 1990-09 (G. Madec) Original code
-   !!            4.0  ! 1991-11 (G. Madec)
-   !!            6.0  ! 1996-01 (G. Madec) statement function for e3 and ahm
-   !!   NEMO     1.0  ! 2002-06 (G. Madec)  F90: Free form and module
-   !!             -   ! 2004-08 (C. Talandier) New trends organization
-   !!            3.7  ! 2014-01  (F. Lemarie, G. Madec)  restructuration/simplification of ahm specification,
-   !!                 !                                  add velocity dependent coefficient and optional read in file
+   !! History : 3.7  ! 2014-01  (G. Madec, S. Masson)  Original code, re-entrant laplacian
    !!----------------------------------------------------------------------
 
@@ -35,5 +29,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -87,13 +80,14 @@
             DO ji = fs_2, jpi   ! vector opt.
                !                                      ! ahm * e3 * curl  (computed from 1 to jpim1/jpjm1)
-!!gm open question here : fse3f  at before or now ?    probably now...
+!!gm open question here : e3f  at before or now ?    probably now...
 !!gm note that ahmf has already been multiplied by fmask
-               zcur(ji-1,jj-1) = ahmf(ji-1,jj-1,jk) * fse3f(ji-1,jj-1,jk) * r1_e1e2f(ji-1,jj-1)       &
+               zcur(ji-1,jj-1) = ahmf(ji-1,jj-1,jk) * e3f_n(ji-1,jj-1,jk) * r1_e1e2f(ji-1,jj-1)       &
                   &     * (  e2v(ji  ,jj-1) * pvb(ji  ,jj-1,jk) - e2v(ji-1,jj-1) * pvb(ji-1,jj-1,jk)  &
-                  &        - e1u(ji-1,jj  ) * pub(ji-1,jj  ,jk) + e1u(ji-1,jj-1) * pub(ji-1,jj-1,jk)  ) 
+                  &        - e1u(ji-1,jj  ) * pub(ji-1,jj  ,jk) + e1u(ji-1,jj-1) * pub(ji-1,jj-1,jk)  )
                !                                      ! ahm * div        (computed from 2 to jpi/jpj)
-               zdiv(ji,jj)     = ahmt(ji,jj,jk) * r1_e1e2t(ji,jj) / fse3t_b(ji,jj,jk) * tmask(ji,jj,jk)                           &
-                  &     * (  e2u(ji,jj)*fse3u_b(ji,jj,jk) * pub(ji,jj,jk) - e2u(ji-1,jj)*fse3u_b(ji-1,jj,jk) * pub(ji-1,jj,jk)  &
-                  &        + e1v(ji,jj)*fse3v_b(ji,jj,jk) * pvb(ji,jj,jk) - e1v(ji,jj-1)*fse3v_b(ji,jj-1,jk) * pvb(ji,jj-1,jk)  )
+!!gm note that ahmt has already been multiplied by tmask
+               zdiv(ji,jj)     = ahmt(ji,jj,jk) * r1_e1e2t(ji,jj) / e3t_b(ji,jj,jk)                                         &
+                  &     * (  e2u(ji,jj)*e3u_b(ji,jj,jk) * pub(ji,jj,jk) - e2u(ji-1,jj)*e3u_b(ji-1,jj,jk) * pub(ji-1,jj,jk)  &
+                  &        + e1v(ji,jj)*e3v_b(ji,jj,jk) * pvb(ji,jj,jk) - e1v(ji,jj-1)*e3v_b(ji,jj-1,jk) * pvb(ji,jj-1,jk)  )
             END DO  
          END DO  
@@ -101,10 +95,10 @@
          DO jj = 2, jpjm1                             ! - curl( curl) + grad( div )
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               pua(ji,jj,jk) = pua(ji,jj,jk) + zsign * (                                                   &
-                  &              - ( zcur(ji  ,jj) - zcur(ji,jj-1) ) /  ( e2u(ji,jj) * fse3u(ji,jj,jk) )   &
+               pua(ji,jj,jk) = pua(ji,jj,jk) + zsign * (                                                 &
+                  &              - ( zcur(ji  ,jj) - zcur(ji,jj-1) ) * r1_e2u(ji,jj) / e3u_n(ji,jj,jk)   &
                   &              + ( zdiv(ji+1,jj) - zdiv(ji,jj  ) ) * r1_e1u(ji,jj)                     )
                   !
-               pva(ji,jj,jk) = pva(ji,jj,jk) + zsign * (                                                   &
-                  &                ( zcur(ji,jj  ) - zcur(ji-1,jj) ) /  ( e1v(ji,jj) * fse3v(ji,jj,jk) )   &
+               pva(ji,jj,jk) = pva(ji,jj,jk) + zsign * (                                                 &
+                  &                ( zcur(ji,jj  ) - zcur(ji-1,jj) ) * r1_e1v(ji,jj) / e3v_n(ji,jj,jk)   &
                   &              + ( zdiv(ji,jj+1) - zdiv(ji  ,jj) ) * r1_e2v(ji,jj)                     )
             END DO
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 6140)
@@ -18,32 +18,33 @@
    !!            3.3  !  2011-03  (P. Oddo) Bug fix for time-splitting+(BDY-OBC) and not VVL
    !!            3.5  !  2013-07  (J. Chanut) Compliant with time splitting changes
-   !!            3.7  !  2014-04  (G. Madec) add the diagnostic of the time filter trends
+   !!            3.6  !  2014-04  (G. Madec) add the diagnostic of the time filter trends
    !!            3.7  !  2015-11  (J. Chanut) Free surface simplification
    !!-------------------------------------------------------------------------
   
    !!-------------------------------------------------------------------------
-   !!   dyn_nxt      : obtain the next (after) horizontal velocity
+   !!   dyn_nxt       : obtain the next (after) horizontal velocity
    !!-------------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE phycst          ! physical constants
-   USE dynadv          ! dynamics: vector invariant versus flux form
-   USE domvvl          ! variable volume
-   USE bdy_oce         ! ocean open boundary conditions
-   USE bdydta          ! ocean open boundary conditions
-   USE bdydyn          ! ocean open boundary conditions
-   USE bdyvol          ! ocean open boundary condition (bdy_vol routines)
-   USE trd_oce         ! trends: ocean variables
-   USE trddyn          ! trend manager: dynamics
-   USE trdken          ! trend manager: kinetic energy
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE phycst         ! physical constants
+   USE dynadv         ! dynamics: vector invariant versus flux form
+   USE dynspg_ts      ! surface pressure gradient: split-explicit scheme
+   USE domvvl         ! variable volume
+   USE bdy_oce        ! ocean open boundary conditions
+   USE bdydta         ! ocean open boundary conditions
+   USE bdydyn         ! ocean open boundary conditions
+   USE bdyvol         ! ocean open boundary condition (bdy_vol routines)
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
+   USE trdken         ! trend manager: kinetic energy
    !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O manager library
-   USE lbclnk          ! lateral boundary condition (or mpp link)
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory Allocation
-   USE prtctl          ! Print control
-   USE timing          ! Timing
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lbclnk         ! lateral boundary condition (or mpp link)
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory Allocation
+   USE prtctl         ! Print control
+   USE timing         ! Timing
 #if defined key_agrif
    USE agrif_opa_interp
@@ -55,6 +56,4 @@
    PUBLIC    dyn_nxt   ! routine called by step.F90
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -85,7 +84,7 @@
       !!                (ub,vb) = (un,vn) + atfp [ (ub,vb) + (ua,va) - 2 (un,vn) ]
       !!                (un,vn) = (ua,va).
-      !!             Note that with flux form advection and variable volume layer
-      !!             (lk_vvl=T), the time filter is applied on thickness weighted
-      !!             velocity.
+      !!             Note that with flux form advection and non linear free surface,
+      !!             the time filter is applied on thickness weighted velocity.
+      !!             As a result, dyn_nxt MUST be called after tra_nxt.
       !!
       !! ** Action :   ub,vb   filtered before horizontal velocity of next time-step
@@ -95,6 +94,6 @@
       !
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      INTEGER  ::   iku, ikv     ! local integers
-      REAL(wp) ::   zue3a, zue3n, zue3b, zuf           ! local scalars
+      INTEGER  ::   ikt          ! local integers
+      REAL(wp) ::   zue3a, zue3n, zue3b, zuf, zcoef    ! local scalars
       REAL(wp) ::   zve3a, zve3n, zve3b, zvf, z1_2dt   !   -      -
       REAL(wp), POINTER, DIMENSION(:,:)   ::  zue, zve
@@ -104,7 +103,6 @@
       IF( nn_timing == 1 )   CALL timing_start('dyn_nxt')
       !
-      IF( ln_dynspg_ts )   CALL wrk_alloc( jpi,jpj, zue, zve )
-      IF( lk_vvl.AND.(.NOT.ln_dynadv_vec ) ) CALL wrk_alloc( jpi,jpj,jpk, ze3u_f, ze3v_f )
-      IF( l_trddyn     )   CALL wrk_alloc( jpi,jpj,jpk, zua, zva )
+      IF( ln_dynspg_ts       )   CALL wrk_alloc( jpi,jpj,       zue, zve)
+      IF( l_trddyn           )   CALL wrk_alloc( jpi,jpj,jpk,   zua, zva)
       !
       IF( kt == nit000 ) THEN
@@ -117,16 +115,16 @@
          ! Ensure below that barotropic velocities match time splitting estimate
          ! Compute actual transport and replace it with ts estimate at "after" time step
-         zue(:,:) = fse3u_a(:,:,1) * ua(:,:,1) * umask(:,:,1)
-         zve(:,:) = fse3v_a(:,:,1) * va(:,:,1) * vmask(:,:,1)
+         zue(:,:) = e3u_a(:,:,1) * ua(:,:,1) * umask(:,:,1)
+         zve(:,:) = e3v_a(:,:,1) * va(:,:,1) * vmask(:,:,1)
          DO jk = 2, jpkm1
-            zue(:,:) = zue(:,:) + fse3u_a(:,:,jk) * ua(:,:,jk) * umask(:,:,jk)
-            zve(:,:) = zve(:,:) + fse3v_a(:,:,jk) * va(:,:,jk) * vmask(:,:,jk)
+            zue(:,:) = zue(:,:) + e3u_a(:,:,jk) * ua(:,:,jk) * umask(:,:,jk)
+            zve(:,:) = zve(:,:) + e3v_a(:,:,jk) * va(:,:,jk) * vmask(:,:,jk)
          END DO
          DO jk = 1, jpkm1
-            ua(:,:,jk) = ( ua(:,:,jk) - zue(:,:) * hur_a(:,:) + ua_b(:,:) ) * umask(:,:,jk)
-            va(:,:,jk) = ( va(:,:,jk) - zve(:,:) * hvr_a(:,:) + va_b(:,:) ) * vmask(:,:,jk)
+            ua(:,:,jk) = ( ua(:,:,jk) - zue(:,:) * r1_hu_a(:,:) + ua_b(:,:) ) * umask(:,:,jk)
+            va(:,:,jk) = ( va(:,:,jk) - zve(:,:) * r1_hv_a(:,:) + va_b(:,:) ) * vmask(:,:,jk)
          END DO
-
-         IF ( .NOT.ln_bt_fw ) THEN
+         !
+         IF( .NOT.ln_bt_fw ) THEN
             ! Remove advective velocity from "now velocities" 
             ! prior to asselin filtering     
@@ -151,6 +149,6 @@
 # if defined key_bdy
       !                                !* BDY open boundaries
-      IF( lk_bdy .AND. ln_dynspg_exp ) CALL bdy_dyn( kt )
-      IF( lk_bdy .AND. ln_dynspg_ts  ) CALL bdy_dyn( kt, dyn3d_only=.true. )
+      IF( lk_bdy .AND. ln_dynspg_exp )   CALL bdy_dyn( kt )
+      IF( lk_bdy .AND. ln_dynspg_ts  )   CALL bdy_dyn( kt, dyn3d_only=.true. )
 
 !!$   Do we need a call to bdy_vol here??
@@ -184,14 +182,14 @@
             vn(:,:,jk) = va(:,:,jk)
          END DO
-         IF (lk_vvl) THEN
+         IF(.NOT.ln_linssh ) THEN
             DO jk = 1, jpkm1
-               fse3t_b(:,:,jk) = fse3t_n(:,:,jk)
-               fse3u_b(:,:,jk) = fse3u_n(:,:,jk)
-               fse3v_b(:,:,jk) = fse3v_n(:,:,jk)
-            ENDDO
+               e3t_b(:,:,jk) = e3t_n(:,:,jk)
+               e3u_b(:,:,jk) = e3u_n(:,:,jk)
+               e3v_b(:,:,jk) = e3v_n(:,:,jk)
+            END DO
          ENDIF
       ELSE                                             !* Leap-Frog : Asselin filter and swap
          !                                ! =============!
-         IF( .NOT. lk_vvl ) THEN          ! Fixed volume !
+         IF( ln_linssh ) THEN             ! Fixed volume !
             !                             ! =============!
             DO jk = 1, jpkm1                              
@@ -214,22 +212,23 @@
             ! (used as a now filtered scale factor until the swap)
             ! ----------------------------------------------------
-            IF (ln_dynspg_ts.AND.ln_bt_fw) THEN
-               ! No asselin filtering on thicknesses if forward time splitting
-               fse3t_b(:,:,:) = fse3t_n(:,:,:)
+            IF( ln_dynspg_ts .AND. ln_bt_fw ) THEN    ! No asselin filtering on thicknesses if forward time splitting
+               e3t_b(:,:,1:jpkm1) = e3t_n(:,:,1:jpkm1)
             ELSE
-               fse3t_b(:,:,:) = fse3t_n(:,:,:) + atfp * ( fse3t_b(:,:,:) - 2._wp * fse3t_n(:,:,:) + fse3t_a(:,:,:) )
+               DO jk = 1, jpkm1
+                  e3t_b(:,:,jk) = e3t_n(:,:,jk) + atfp * ( e3t_b(:,:,jk) - 2._wp * e3t_n(:,:,jk) + e3t_a(:,:,jk) )
+               END DO
                ! Add volume filter correction: compatibility with tracer advection scheme
                ! => time filter + conservation correction (only at the first level)
-               IF ( nn_isf == 0) THEN   ! if no ice shelf melting
-                  fse3t_b(:,:,1) = fse3t_b(:,:,1) - atfp * rdt * r1_rau0 * ( emp_b(:,:) - emp(:,:) &
-                                 &                                          -rnf_b(:,:) + rnf(:,:) ) * tmask(:,:,1)
+               zcoef = atfp * rdt * r1_rau0
+               IF ( .NOT. ln_isf ) THEN   ! if no ice shelf melting
+                  e3t_b(:,:,1) = e3t_b(:,:,1) - zcoef * ( emp_b(:,:) - emp(:,:) &
+                                 &                      - rnf_b(:,:) + rnf(:,:) ) * tmask(:,:,1)
                ELSE                     ! if ice shelf melting
-                  DO jj = 1,jpj
-                     DO ji = 1,jpi
-                        jk = mikt(ji,jj)
-                        fse3t_b(ji,jj,jk) = fse3t_b(ji,jj,jk) - atfp * rdt * r1_rau0                       &
-                                          &                          * ( (emp_b(ji,jj)    - emp(ji,jj)   ) &
-                                          &                            - (rnf_b(ji,jj)    - rnf(ji,jj)   ) &
-                                          &                            + (fwfisf_b(ji,jj) - fwfisf(ji,jj)) ) * tmask(ji,jj,jk)
+                  DO jj = 1, jpj
+                     DO ji = 1, jpi
+                        ikt = mikt(ji,jj)
+                        e3t_b(ji,jj,ikt) = e3t_b(ji,jj,ikt) - zcoef * (  emp_b   (ji,jj) - emp   (ji,jj)  &
+                           &                                           - rnf_b   (ji,jj) + rnf   (ji,jj)  &
+                           &                                           + fwfisf_b(ji,jj) - fwfisf(ji,jj)  ) * tmask(ji,jj,ikt)
                      END DO
                   END DO
@@ -237,11 +236,8 @@
             ENDIF
             !
-            IF( ln_dynadv_vec ) THEN
-               ! Before scale factor at (u/v)-points
-               ! -----------------------------------
-               CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3u_b(:,:,:), 'U' )
-               CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3v_b(:,:,:), 'V' )
-               ! Leap-Frog - Asselin filter and swap: applied on velocity
-               ! -----------------------------------
+            IF( ln_dynadv_vec ) THEN      ! Asselin filter applied on velocity
+               ! Before filtered scale factor at (u/v)-points
+               CALL dom_vvl_interpol( e3t_b(:,:,:), e3u_b(:,:,:), 'U' )
+               CALL dom_vvl_interpol( e3t_b(:,:,:), e3v_b(:,:,:), 'V' )
                DO jk = 1, jpkm1
                   DO jj = 1, jpj
@@ -258,20 +254,19 @@
                END DO
                !
-            ELSE
-               ! Temporary filtered scale factor at (u/v)-points (will become before scale factor)
-               !------------------------------------------------
-               CALL dom_vvl_interpol( fse3t_b(:,:,:), ze3u_f, 'U' )
-               CALL dom_vvl_interpol( fse3t_b(:,:,:), ze3v_f, 'V' )
-               ! Leap-Frog - Asselin filter and swap: applied on thickness weighted velocity
-               ! -----------------------------------             ===========================
+            ELSE                          ! Asselin filter applied on thickness weighted velocity
+               !
+               CALL wrk_alloc( jpi,jpj,jpk,   ze3u_f, ze3v_f )
+               ! Before filtered scale factor at (u/v)-points stored in ze3u_f, ze3v_f
+               CALL dom_vvl_interpol( e3t_b(:,:,:), ze3u_f, 'U' )
+               CALL dom_vvl_interpol( e3t_b(:,:,:), ze3v_f, 'V' )
                DO jk = 1, jpkm1
                   DO jj = 1, jpj
                      DO ji = 1, jpi                  
-                        zue3a = ua(ji,jj,jk) * fse3u_a(ji,jj,jk)
-                        zve3a = va(ji,jj,jk) * fse3v_a(ji,jj,jk)
-                        zue3n = un(ji,jj,jk) * fse3u_n(ji,jj,jk)
-                        zve3n = vn(ji,jj,jk) * fse3v_n(ji,jj,jk)
-                        zue3b = ub(ji,jj,jk) * fse3u_b(ji,jj,jk)
-                        zve3b = vb(ji,jj,jk) * fse3v_b(ji,jj,jk)
+                        zue3a = e3u_a(ji,jj,jk) * ua(ji,jj,jk)
+                        zve3a = e3v_a(ji,jj,jk) * va(ji,jj,jk)
+                        zue3n = e3u_n(ji,jj,jk) * un(ji,jj,jk)
+                        zve3n = e3v_n(ji,jj,jk) * vn(ji,jj,jk)
+                        zue3b = e3u_b(ji,jj,jk) * ub(ji,jj,jk)
+                        zve3b = e3v_b(ji,jj,jk) * vb(ji,jj,jk)
                         !
                         zuf = ( zue3n + atfp * ( zue3b - 2._wp * zue3n  + zue3a ) ) / ze3u_f(ji,jj,jk)
@@ -285,22 +280,24 @@
                   END DO
                END DO
-               fse3u_b(:,:,1:jpkm1) = ze3u_f(:,:,1:jpkm1)      ! e3u_b <-- filtered scale factor
-               fse3v_b(:,:,1:jpkm1) = ze3v_f(:,:,1:jpkm1)
+               e3u_b(:,:,1:jpkm1) = ze3u_f(:,:,1:jpkm1)        ! e3u_b <-- filtered scale factor
+               e3v_b(:,:,1:jpkm1) = ze3v_f(:,:,1:jpkm1)
+               !
+               CALL wrk_dealloc( jpi,jpj,jpk,   ze3u_f, ze3v_f )
             ENDIF
             !
          ENDIF
          !
-         IF (ln_dynspg_ts.AND.ln_bt_fw) THEN
+         IF( ln_dynspg_ts .AND. ln_bt_fw ) THEN
             ! Revert "before" velocities to time split estimate
             ! Doing it here also means that asselin filter contribution is removed  
-            zue(:,:) = fse3u_b(:,:,1) * ub(:,:,1) * umask(:,:,1)
-            zve(:,:) = fse3v_b(:,:,1) * vb(:,:,1) * vmask(:,:,1)    
+            zue(:,:) = e3u_b(:,:,1) * ub(:,:,1) * umask(:,:,1)
+            zve(:,:) = e3v_b(:,:,1) * vb(:,:,1) * vmask(:,:,1)    
             DO jk = 2, jpkm1
-               zue(:,:) = zue(:,:) + fse3u_b(:,:,jk) * ub(:,:,jk) * umask(:,:,jk)
-               zve(:,:) = zve(:,:) + fse3v_b(:,:,jk) * vb(:,:,jk) * vmask(:,:,jk)    
+               zue(:,:) = zue(:,:) + e3u_b(:,:,jk) * ub(:,:,jk) * umask(:,:,jk)
+               zve(:,:) = zve(:,:) + e3v_b(:,:,jk) * vb(:,:,jk) * vmask(:,:,jk)    
             END DO
             DO jk = 1, jpkm1
-               ub(:,:,jk) = ub(:,:,jk) - (zue(:,:) * hur(:,:) - un_b(:,:)) * umask(:,:,jk)
-               vb(:,:,jk) = vb(:,:,jk) - (zve(:,:) * hvr(:,:) - vn_b(:,:)) * vmask(:,:,jk)
+               ub(:,:,jk) = ub(:,:,jk) - (zue(:,:) * r1_hu_n(:,:) - un_b(:,:)) * umask(:,:,jk)
+               vb(:,:,jk) = vb(:,:,jk) - (zve(:,:) * r1_hv_n(:,:) - vn_b(:,:)) * vmask(:,:,jk)
             END DO
          ENDIF
@@ -313,38 +310,34 @@
       !
       !
-      IF (lk_vvl) THEN
-         hu_b(:,:) = 0.
-         hv_b(:,:) = 0.
-         DO jk = 1, jpkm1
-            hu_b(:,:) = hu_b(:,:) + fse3u_b(:,:,jk) * umask(:,:,jk)
-            hv_b(:,:) = hv_b(:,:) + fse3v_b(:,:,jk) * vmask(:,:,jk)
+      IF(.NOT.ln_linssh ) THEN
+         hu_b(:,:) = e3u_b(:,:,1) * umask(:,:,1)
+         hv_b(:,:) = e3v_b(:,:,1) * vmask(:,:,1)
+         DO jk = 2, jpkm1
+            hu_b(:,:) = hu_b(:,:) + e3u_b(:,:,jk) * umask(:,:,jk)
+            hv_b(:,:) = hv_b(:,:) + e3v_b(:,:,jk) * vmask(:,:,jk)
          END DO
-         hur_b(:,:) = umask_i(:,:) / ( hu_b(:,:) + 1._wp - umask_i(:,:) )
-         hvr_b(:,:) = vmask_i(:,:) / ( hv_b(:,:) + 1._wp - vmask_i(:,:) )
-      ENDIF
-      !
-      un_b(:,:) = 0._wp ; vn_b(:,:) = 0._wp
-      ub_b(:,:) = 0._wp ; vb_b(:,:) = 0._wp
-      !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               un_b(ji,jj) = un_b(ji,jj) + fse3u_a(ji,jj,jk) * un(ji,jj,jk) * umask(ji,jj,jk)
-               vn_b(ji,jj) = vn_b(ji,jj) + fse3v_a(ji,jj,jk) * vn(ji,jj,jk) * vmask(ji,jj,jk)
-               !
-               ub_b(ji,jj) = ub_b(ji,jj) + fse3u_b(ji,jj,jk) * ub(ji,jj,jk) * umask(ji,jj,jk)
-               vb_b(ji,jj) = vb_b(ji,jj) + fse3v_b(ji,jj,jk) * vb(ji,jj,jk) * vmask(ji,jj,jk)
-            END DO
-         END DO
+         r1_hu_b(:,:) = ssumask(:,:) / ( hu_b(:,:) + 1._wp - ssumask(:,:) )
+         r1_hv_b(:,:) = ssvmask(:,:) / ( hv_b(:,:) + 1._wp - ssvmask(:,:) )
+      ENDIF
+      !
+      un_b(:,:) = e3u_a(:,:,1) * un(:,:,1) * umask(:,:,1)
+      ub_b(:,:) = e3u_b(:,:,1) * ub(:,:,1) * umask(:,:,1)
+      vn_b(:,:) = e3v_a(:,:,1) * vn(:,:,1) * vmask(:,:,1)
+      vb_b(:,:) = e3v_b(:,:,1) * vb(:,:,1) * vmask(:,:,1)
+      DO jk = 2, jpkm1
+         un_b(:,:) = un_b(:,:) + e3u_a(:,:,jk) * un(:,:,jk) * umask(:,:,jk)
+         ub_b(:,:) = ub_b(:,:) + e3u_b(:,:,jk) * ub(:,:,jk) * umask(:,:,jk)
+         vn_b(:,:) = vn_b(:,:) + e3v_a(:,:,jk) * vn(:,:,jk) * vmask(:,:,jk)
+         vb_b(:,:) = vb_b(:,:) + e3v_b(:,:,jk) * vb(:,:,jk) * vmask(:,:,jk)
       END DO
-      !
-      !
-      un_b(:,:) = un_b(:,:) * hur_a(:,:)
-      vn_b(:,:) = vn_b(:,:) * hvr_a(:,:)
-      ub_b(:,:) = ub_b(:,:) * hur_b(:,:)
-      vb_b(:,:) = vb_b(:,:) * hvr_b(:,:)
-      !
-      !
-
+      un_b(:,:) = un_b(:,:) * r1_hu_a(:,:)
+      vn_b(:,:) = vn_b(:,:) * r1_hv_a(:,:)
+      ub_b(:,:) = ub_b(:,:) * r1_hu_b(:,:)
+      vb_b(:,:) = vb_b(:,:) * r1_hv_b(:,:)
+      !
+      IF( .NOT.ln_dynspg_ts ) THEN        ! output the barotropic currents
+         CALL iom_put(  "ubar", un_b(:,:) )
+         CALL iom_put(  "vbar", vn_b(:,:) )
+      ENDIF
       IF( l_trddyn ) THEN                ! 3D output: asselin filter trends on momentum
          zua(:,:,:) = ( ub(:,:,:) - zua(:,:,:) ) * z1_2dt
@@ -355,8 +348,7 @@
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=un, clinfo1=' nxt  - Un: ', mask1=umask,   &
          &                       tab3d_2=vn, clinfo2=' Vn: '       , mask2=vmask )
-      !
-      IF( ln_dynspg_ts )   CALL wrk_dealloc( jpi,jpj, zue, zve )
-      IF( lk_vvl.AND.(.NOT.ln_dynadv_vec ) ) CALL wrk_dealloc( jpi,jpj,jpk, ze3u_f, ze3v_f )
-      IF( l_trddyn     )   CALL wrk_dealloc( jpi,jpj,jpk, zua, zva )
+      ! 
+      IF( ln_dynspg_ts )   CALL wrk_dealloc( jpi,jpj,       zue, zve )
+      IF( l_trddyn     )   CALL wrk_dealloc( jpi,jpj,jpk,   zua, zva )
       !
       IF( nn_timing == 1 )  CALL timing_stop('dyn_nxt')
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 6140)
@@ -6,5 +6,4 @@
    !! History :  1.0  ! 2005-12  (C. Talandier, G. Madec, V. Garnier)  Original code
    !!            3.2  ! 2009-07  (R. Benshila)  Suppression of rigid-lid option
-   !!            3.7  ! 2015-11  (J. Chanut) Suppression of filtered free surface 
    !!----------------------------------------------------------------------
 
@@ -21,6 +20,6 @@
    USE dynspg_exp     ! surface pressure gradient     (dyn_spg_exp routine)
    USE dynspg_ts      ! surface pressure gradient     (dyn_spg_ts  routine)
-   USE sbctide
-   USE updtide
+   USE sbctide        ! 
+   USE updtide        ! 
    USE trd_oce        ! trends: ocean variables
    USE trddyn         ! trend manager: dynamics
@@ -32,5 +31,4 @@
    USE timing         ! Timing
 
-
    IMPLICIT NONE
    PRIVATE
@@ -39,8 +37,12 @@
    PUBLIC   dyn_spg_init   ! routine called by opa module
 
-   INTEGER ::   nspg = 0   ! type of surface pressure gradient scheme defined from ln_dynspg_... 
+   INTEGER ::   nspg = 0   ! type of surface pressure gradient scheme defined from lk_dynspg_... 
+
+   !                       ! Parameter to control the surface pressure gradient scheme
+   INTEGER, PARAMETER ::   np_TS  = 1   ! split-explicit time stepping (Time-Splitting)
+   INTEGER, PARAMETER ::   np_EXP = 0   !       explicit time stepping
+   INTEGER, PARAMETER ::   np_NO  =-1   ! no surface pressure gradient, no scheme
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -55,14 +57,10 @@
       !!                  ***  ROUTINE dyn_spg  ***
       !!
-      !! ** Purpose :   achieve the momentum time stepping by computing the
-      !!              last trend, the surface pressure gradient including the 
-      !!              atmospheric pressure forcing (ln_apr_dyn=T), and performing
-      !!              the Leap-Frog integration.
-      !!gm              In the current version only the filtered solution provide
-      !!gm            the after velocity, in the 2 other (ua,va) are still the trends
+      !! ** Purpose :   compute surface pressure gradient including the 
+      !!              atmospheric pressure forcing (ln_apr_dyn=T).
       !!
       !! ** Method  :   Two schemes:
-      !!              - explicit computation      : the spg is evaluated at now
-      !!              - split-explicit computation: a time splitting technique is used
+      !!              - explicit       : the spg is evaluated at now
+      !!              - split-explicit : a time splitting technique is used
       !!
       !!              ln_apr_dyn=T : the atmospheric pressure forcing is applied 
@@ -73,5 +71,4 @@
       !!             period is used to prevent the divergence of odd and even time step.
       !!----------------------------------------------------------------------
-      !
       INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
       !
@@ -84,16 +81,10 @@
       IF( nn_timing == 1 )  CALL timing_start('dyn_spg')
       !
-
-!!gm NOTA BENE : the dynspg_exp and dynspg_ts should be modified so that 
-!!gm             they return the after velocity, not the trends (as in trazdf_imp...)
-!!gm             In this case, change/simplify dynnxt
-
-
       IF( l_trddyn )   THEN                      ! temporary save of ta and sa trends
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
+         CALL wrk_alloc( jpi,jpj,jpk,   ztrdu, ztrdv ) 
          ztrdu(:,:,:) = ua(:,:,:)
          ztrdv(:,:,:) = va(:,:,:)
       ENDIF
-
+      !
       IF(      ln_apr_dyn                                                &   ! atmos. pressure
          .OR.  ( .NOT.ln_dynspg_ts .AND. (ln_tide_pot .AND. lk_tide) )   &   ! tide potential (no time slitting)
@@ -107,5 +98,5 @@
          END DO         
          !
-         IF( ln_apr_dyn .AND. (.NOT. ln_dynspg_ts) ) THEN                    !==  Atmospheric pressure gradient (added later in time-split case) ==!
+         IF( ln_apr_dyn .AND. .NOT.ln_dynspg_ts ) THEN   !==  Atmospheric pressure gradient (added later in time-split case) ==!
             zg_2 = grav * 0.5
             DO jj = 2, jpjm1                          ! gradient of Patm using inverse barometer ssh
@@ -133,5 +124,5 @@
          !
          IF( nn_ice_embd == 2 ) THEN          !== embedded sea ice: Pressure gradient due to snow-ice mass ==!
-            CALL wrk_alloc( jpi, jpj, zpice )
+            CALL wrk_alloc( jpi,jpj,   zpice )
             !                                            
             zintp = REAL( MOD( kt-1, nn_fsbc ) ) / REAL( nn_fsbc )
@@ -145,8 +136,8 @@
             END DO
             !
-            CALL wrk_dealloc( jpi, jpj, zpice )         
+            CALL wrk_dealloc( jpi,jpj,   zpice )         
          ENDIF
          !
-         DO jk = 1, jpkm1                     !== Add all terms to the general trend
+         DO jk = 1, jpkm1                    !== Add all terms to the general trend
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -156,24 +147,21 @@
             END DO
          END DO    
-         
+         !
 !!gm add here a call to dyn_trd for ice pressure gradient, the surf pressure trends ????
-              
-      ENDIF
-
-      SELECT CASE ( nspg )                       ! compute surf. pressure gradient trend and add it to the general trend
-      !                                                     
-      CASE (  0 )   ;   CALL dyn_spg_exp( kt )              ! explicit
-      CASE (  1 )   ;   CALL dyn_spg_ts ( kt )              ! time-splitting
-      !                                                    
+         !    
+      ENDIF
+      !
+      SELECT CASE ( nspg )                   !== surface pressure gradient computed and add to the general trend ==!
+      CASE ( np_EXP )   ;   CALL dyn_spg_exp( kt )              ! explicit
+      CASE ( np_TS  )   ;   CALL dyn_spg_ts ( kt )              ! time-splitting
       END SELECT
       !                    
-      IF( l_trddyn )   THEN                      ! save the surface pressure gradient trends for further diagnostics
+      IF( l_trddyn )   THEN                  ! save the surface pressure gradient trends for further diagnostics
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
          CALL trd_dyn( ztrdu, ztrdv, jpdyn_spg, kt )
-         !
-         CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
-      ENDIF
-      !                                          ! print mean trends (used for debugging)
+         CALL wrk_dealloc( jpi,jpj,jpk,   ztrdu, ztrdv ) 
+      ENDIF
+      !                                      ! print mean trends (used for debugging)
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' spg  - Ua: ', mask1=umask, &
          &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
@@ -191,9 +179,9 @@
       !!              surface pressure gradient schemes
       !!----------------------------------------------------------------------
-      INTEGER ::   ioptio, ios
-      !
-      NAMELIST/namdyn_spg/ ln_dynspg_exp, ln_dynspg_ts, &
-      &                    ln_bt_fw, ln_bt_av, ln_bt_auto, &
-      &                    nn_baro, rn_bt_cmax, nn_bt_flt
+      INTEGER ::   ioptio, ios   ! local integers
+      !
+      NAMELIST/namdyn_spg/ ln_dynspg_exp       , ln_dynspg_ts,   &
+      &                    ln_bt_fw, ln_bt_av  , ln_bt_auto  ,   &
+      &                    nn_baro , rn_bt_cmax, nn_bt_flt
       !!----------------------------------------------------------------------
       !
@@ -202,9 +190,9 @@
       REWIND( numnam_ref )              ! Namelist namdyn_spg in reference namelist : Free surface
       READ  ( numnam_ref, namdyn_spg, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_spg in reference namelist', lwp )
-
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_spg in reference namelist', lwp )
+      !
       REWIND( numnam_cfg )              ! Namelist namdyn_spg in configuration namelist : Free surface
       READ  ( numnam_cfg, namdyn_spg, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_spg in configuration namelist', lwp )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_spg in configuration namelist', lwp )
       IF(lwm) WRITE ( numond, namdyn_spg )
       !
@@ -216,29 +204,25 @@
          WRITE(numout,*) '     Free surface with time splitting       ln_dynspg_ts  = ', ln_dynspg_ts
       ENDIF
-
-      IF( ln_dynspg_ts ) THEN
-         CALL dyn_spg_ts_init( nit000  ) ! do it first, to set nn_baro, used to allocate some arrays later on
-         !                               ! allocate dyn_spg arrays
-         IF( dyn_spg_ts_alloc() /= 0 )   CALL ctl_stop('STOP', 'dyn_spg_init: failed to allocate dynspg_ts  arrays')
-         IF ((neuler/=0).AND.(ln_bt_fw)) CALL ts_rst( nit000, 'READ' )
-      ENDIF
-
-      !                        ! Control of surface pressure gradient scheme options
-      ioptio = 0
-      IF(ln_dynspg_exp)   ioptio = ioptio + 1
-      IF(ln_dynspg_ts )   ioptio = ioptio + 1
-      !
-      IF(  ioptio > 1  .OR. ( ioptio == 0 .AND. .NOT. lk_c1d ) )   &
-           &   CALL ctl_stop( ' Choose only one surface pressure gradient scheme' )
-      IF( ln_dynspg_ts .AND. ln_isfcav )   &
-           &   CALL ctl_stop( ' dynspg_ts not tested with ice shelf cavity ' )
-      !
-      IF( ln_dynspg_exp)   nspg =  0
-      IF( ln_dynspg_ts )   nspg =  1
+      !                          ! Control of surface pressure gradient scheme options
+      ;                              nspg =  np_NO    ;   ioptio = 0
+      IF( ln_dynspg_exp ) THEN   ;   nspg =  np_EXP   ;   ioptio = ioptio + 1   ;   ENDIF
+      IF( ln_dynspg_ts  ) THEN   ;   nspg =  np_TS    ;   ioptio = ioptio + 1   ;   ENDIF
+      !
+      IF( ioptio  > 1 )   CALL ctl_stop( 'Choose only one surface pressure gradient scheme' )
+      IF( ioptio == 0 )   CALL ctl_warn( 'NO surface pressure gradient trend in momentum Eqs.' )
+      IF( ln_dynspg_exp .AND. ln_isfcav )   &
+           &   CALL ctl_stop( ' dynspg_exp not tested with ice shelf cavity ' )
       !
       IF(lwp) THEN
          WRITE(numout,*)
-         IF( nspg ==  0 )   WRITE(numout,*) '     explicit free surface'
-         IF( nspg ==  1 )   WRITE(numout,*) '     free surface with time splitting scheme'
+         IF( nspg == np_EXP )   WRITE(numout,*) '     explicit free surface'
+         IF( nspg == np_TS  )   WRITE(numout,*) '     free surface with time splitting scheme'
+         IF( nspg == np_NO  )   WRITE(numout,*) '     No surface surface pressure gradient trend in momentum Eqs.'
+      ENDIF
+      !
+      IF( nspg == np_TS ) THEN   ! split-explicit scheme initialisation
+         CALL dyn_spg_ts_init          ! do it first: set nn_baro used to allocate some arrays later on
+         IF( dyn_spg_ts_alloc() /= 0  )   CALL ctl_stop('STOP', 'dyn_spg_init: failed to allocate dynspg_ts  arrays' )
+         IF( neuler/=0 .AND. ln_bt_fw )   CALL ts_rst( nit000, 'READ' )
       ENDIF
       !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 6140)
@@ -2,11 +2,10 @@
    !!======================================================================
    !!                   ***  MODULE  dynspg_exp  ***
-   !! Ocean dynamics:  surface pressure gradient trend
+   !! Ocean dynamics:  surface pressure gradient trend, explicit scheme
    !!======================================================================
    !! History :  2.0  !  2005-11  (V. Garnier, G. Madec, L. Bessieres) Original code
    !!            3.2  !  2009-06  (G. Madec, M. Leclair, R. Benshila) introduce sshwzv module
    !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!                     explicit free surface
+
    !!----------------------------------------------------------------------
    !!   dyn_spg_exp  : update the momentum trend with the surface 
@@ -26,12 +25,10 @@
    USE timing          ! Timing
 
-
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   dyn_spg_exp   ! routine called by dyn_spg 
+   PUBLIC   dyn_spg_exp   ! routine called by dynspg.F90 
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -73,13 +70,13 @@
          spgu(:,:) = 0._wp   ;   spgv(:,:) = 0._wp
          !
-         IF( lk_vvl .AND. lwp ) WRITE(numout,*) '              lk_vvl=T : spg is included in dynhpg'
+         IF( .NOT.ln_linssh .AND. lwp ) WRITE(numout,*) '      non linear free surface: spg is included in dynhpg'
       ENDIF
 
-      IF( .NOT. lk_vvl ) THEN          !* fixed volume : add the surface pressure gradient trend
+      IF( ln_linssh ) THEN          !* linear free surface : add the surface pressure gradient trend
          !
          DO jj = 2, jpjm1                    ! now surface pressure gradient
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               spgu(ji,jj) = - grav * ( sshn(ji+1,jj) - sshn(ji,jj) ) / e1u(ji,jj)
-               spgv(ji,jj) = - grav * ( sshn(ji,jj+1) - sshn(ji,jj) ) / e2v(ji,jj)
+               spgu(ji,jj) = - grav * ( sshn(ji+1,jj) - sshn(ji,jj) ) * r1_e1u(ji,jj)
+               spgv(ji,jj) = - grav * ( sshn(ji,jj+1) - sshn(ji,jj) ) * r1_e2v(ji,jj)
             END DO 
          END DO
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 6140)
@@ -1,3 +1,6 @@
 MODULE dynspg_ts
+   !!======================================================================
+   !!                   ***  MODULE  dynspg_ts  ***
+   !! Ocean dynamics:  surface pressure gradient trend, split-explicit scheme
    !!======================================================================
    !! History :   1.0  ! 2004-12  (L. Bessieres, G. Madec)  Original code
@@ -13,14 +16,18 @@
    !!             3.7  ! 2015-11  (J. Chanut) free surface simplification
    !!---------------------------------------------------------------------
+
    !!----------------------------------------------------------------------
-   !!                       split explicit free surface
-   !!----------------------------------------------------------------------
-   !!   dyn_spg_ts  : compute surface pressure gradient trend using a time-
-   !!                 splitting scheme and add to the general trend 
+   !!   dyn_spg_ts     : compute surface pressure gradient trend using a time-splitting scheme 
+   !!   dyn_spg_ts_init: initialisation of the time-splitting scheme
+   !!   ts_wgt         : set time-splitting weights for temporal averaging (or not)
+   !!   ts_rst         : read/write time-splitting fields in restart file
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
    USE sbc_oce         ! surface boundary condition: ocean
+   USE zdf_oce         ! Bottom friction coefts
    USE sbcisf          ! ice shelf variable (fwfisf)
+   USE sbcapr          ! surface boundary condition: atmospheric pressure
+   USE dynadv    , ONLY: ln_dynadv_vec
    USE phycst          ! physical constants
    USE dynvor          ! vorticity term
@@ -30,15 +37,14 @@
    USE sbctide         ! tides
    USE updtide         ! tide potential
+   !
+   USE in_out_manager  ! I/O manager
    USE lib_mpp         ! distributed memory computing library
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE prtctl          ! Print control
-   USE in_out_manager  ! I/O manager
    USE iom             ! IOM library
    USE restart         ! only for lrst_oce
-   USE zdf_oce         ! Bottom friction coefts
    USE wrk_nemo        ! Memory Allocation
    USE timing          ! Timing    
-   USE sbcapr          ! surface boundary condition: atmospheric pressure
-   USE dynadv, ONLY: ln_dynadv_vec
+   USE diatmb          ! Top,middle,bottom output
 #if defined key_agrif
    USE agrif_opa_interp ! agrif
@@ -47,4 +53,5 @@
    USE asminc          ! Assimilation increment
 #endif
+
 
    IMPLICIT NONE
@@ -59,14 +66,14 @@
    REAL(wp),SAVE :: rdtbt   ! Barotropic time step
 
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) :: &
-                    wgtbtp1, &              ! Primary weights used for time filtering of barotropic variables
-                    wgtbtp2                 ! Secondary weights used for time filtering of barotropic variables
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  zwz          ! ff/h at F points
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ftnw, ftne   ! triad of coriolis parameter
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ftsw, ftse   ! (only used with een vorticity scheme)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::   wgtbtp1, wgtbtp2   !: 1st & 2nd weights used in time filtering of barotropic fields
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  zwz          !: ff/h at F points
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ftnw, ftne   !: triad of coriolis parameter
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ftsw, ftse   !: (only used with een vorticity scheme)
+
+   !! Time filtered arrays at baroclinic time step:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   un_adv , vn_adv     !: Advection vel. at "now" barocl. step
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -81,26 +88,17 @@
       !!                  ***  routine dyn_spg_ts_alloc  ***
       !!----------------------------------------------------------------------
-      INTEGER :: ierr(4)
+      INTEGER :: ierr(3)
       !!----------------------------------------------------------------------
       ierr(:) = 0
-
-      ALLOCATE( ssha_e(jpi,jpj),  sshn_e(jpi,jpj), sshb_e(jpi,jpj), sshbb_e(jpi,jpj), &
-         &        ua_e(jpi,jpj),    un_e(jpi,jpj),   ub_e(jpi,jpj),   ubb_e(jpi,jpj), &
-         &        va_e(jpi,jpj),    vn_e(jpi,jpj),   vb_e(jpi,jpj),   vbb_e(jpi,jpj), &
-         &        hu_e(jpi,jpj),   hur_e(jpi,jpj),   hv_e(jpi,jpj),   hvr_e(jpi,jpj), STAT= ierr(1) )
-
-      ALLOCATE( wgtbtp1(3*nn_baro), wgtbtp2(3*nn_baro), zwz(jpi,jpj), STAT= ierr(2) )
-
-      IF( ln_dynvor_een ) ALLOCATE( ftnw(jpi,jpj) , ftne(jpi,jpj) , & 
-         &                          ftsw(jpi,jpj) , ftse(jpi,jpj) , STAT=ierr(3) )
-
-      ALLOCATE( ub2_b(jpi,jpj), vb2_b(jpi,jpj), un_adv(jpi,jpj), vn_adv(jpi,jpj), &
-#if defined key_agrif
-         &      ub2_i_b(jpi,jpj), vb2_i_b(jpi,jpj)                              , &
-#endif
-         &      STAT= ierr(4))
-
-      dyn_spg_ts_alloc = MAXVAL(ierr(:))
-
+      !
+      ALLOCATE( wgtbtp1(3*nn_baro), wgtbtp2(3*nn_baro), zwz(jpi,jpj), STAT=ierr(1) )
+      !
+      IF( ln_dynvor_een )   ALLOCATE( ftnw(jpi,jpj) , ftne(jpi,jpj) , & 
+         &                            ftsw(jpi,jpj) , ftse(jpi,jpj) , STAT=ierr(2) )
+         !
+      ALLOCATE( un_adv(jpi,jpj), vn_adv(jpi,jpj)                    , STAT=ierr(3) )
+      !
+      dyn_spg_ts_alloc = MAXVAL( ierr(:) )
+      !
       IF( lk_mpp                )   CALL mpp_sum( dyn_spg_ts_alloc )
       IF( dyn_spg_ts_alloc /= 0 )   CALL ctl_warn('dyn_spg_ts_alloc: failed to allocate arrays')
@@ -112,9 +110,9 @@
       !!----------------------------------------------------------------------
       !!
-      !! ** Purpose :   
-      !!      -Compute the now trend due to the explicit time stepping
-      !!      of the quasi-linear barotropic system. 
+      !! ** Purpose : - Compute the now trend due to the explicit time stepping
+      !!              of the quasi-linear barotropic system, and add it to the
+      !!              general momentum trend. 
       !!
-      !! ** Method  :  
+      !! ** Method  : - split-explicit schem (time splitting) :
       !!      Barotropic variables are advanced from internal time steps
       !!      "n"   to "n+1" if ln_bt_fw=T
@@ -130,13 +128,8 @@
       !!      continuity equation taken at the baroclinic time steps. This 
       !!      ensures tracers conservation.
-      !!      -Update 3d trend (ua, va) with barotropic component.
+      !!      - (ua, va) momentum trend updated with barotropic component.
       !!
-      !! References : Shchepetkin, A.F. and J.C. McWilliams, 2005: 
-      !!              The regional oceanic modeling system (ROMS): 
-      !!              a split-explicit, free-surface,
-      !!              topography-following-coordinate oceanic model. 
-      !!              Ocean Modelling, 9, 347-404. 
+      !! References : Shchepetkin and McWilliams, Ocean Modelling, 2005. 
       !!---------------------------------------------------------------------
-      !
       INTEGER, INTENT(in)  ::   kt   ! ocean time-step index
       !
@@ -145,4 +138,6 @@
       INTEGER  ::   ji, jj, jk, jn   		! dummy loop indices
       INTEGER  ::   ikbu, ikbv, noffset    	! local integers
+      INTEGER  ::   iktu, iktv             	! local integers
+      REAL(wp) ::   zmdi
       REAL(wp) ::   zraur, z1_2dt_b, z2dt_bf  	! local scalars
       REAL(wp) ::   zx1, zy1, zx2, zy2          !   -      -
@@ -163,11 +158,12 @@
       !
       !                                         !* Allocate temporary arrays
-      CALL wrk_alloc( jpi, jpj, zsshp2_e, zhdiv )
-      CALL wrk_alloc( jpi, jpj, zu_trd, zv_trd)
-      CALL wrk_alloc( jpi, jpj, zwx, zwy, zssh_frc, zu_frc, zv_frc)
-      CALL wrk_alloc( jpi, jpj, zhup2_e, zhvp2_e, zhust_e, zhvst_e)
-      CALL wrk_alloc( jpi, jpj, zsshu_a, zsshv_a                                   )
-      CALL wrk_alloc( jpi, jpj, zhf )
-      !
+      CALL wrk_alloc( jpi,jpj,   zsshp2_e, zhdiv )
+      CALL wrk_alloc( jpi,jpj,   zu_trd, zv_trd)
+      CALL wrk_alloc( jpi,jpj,   zwx, zwy, zssh_frc, zu_frc, zv_frc)
+      CALL wrk_alloc( jpi,jpj,   zhup2_e, zhvp2_e, zhust_e, zhvst_e)
+      CALL wrk_alloc( jpi,jpj,   zsshu_a, zsshv_a                                   )
+      CALL wrk_alloc( jpi,jpj,   zhf )
+      !
+      zmdi=1.e+20                               !  missing data indicator for masking
       !                                         !* Local constant initialization
       z1_12 = 1._wp / 12._wp 
@@ -176,17 +172,16 @@
       z1_2  = 0.5_wp     
       zraur = 1._wp / rau0
-      !
-      IF( kt == nit000 .AND. neuler == 0 ) THEN  	! reciprocal of baroclinic time step 
-        z2dt_bf = rdt
-      ELSE
-        z2dt_bf = 2.0_wp * rdt
+      !  	                                       ! reciprocal of baroclinic time step 
+      IF( kt == nit000 .AND. neuler == 0 ) THEN   ;   z2dt_bf =          rdt
+      ELSE                                        ;   z2dt_bf = 2.0_wp * rdt
       ENDIF
       z1_2dt_b = 1.0_wp / z2dt_bf 
       !
-      ll_init = ln_bt_av                       		! if no time averaging, then no specific restart 
+      ll_init     = ln_bt_av                       ! if no time averaging, then no specific restart 
       ll_fw_start = .FALSE.
-      !
-                                     	                ! time offset in steps for bdy data update
-      IF (.NOT.ln_bt_fw) THEN ; noffset=-nn_baro ; ELSE ;  noffset = 0 ; ENDIF
+      !                              	            ! time offset in steps for bdy data update
+      IF( .NOT.ln_bt_fw ) THEN   ;   noffset = - nn_baro
+      ELSE                       ;   noffset =   0 
+      ENDIF
       !
       IF( kt == nit000 ) THEN             	!* initialisation
@@ -197,16 +192,15 @@
          IF(lwp) WRITE(numout,*)
          !
-         IF (neuler==0) ll_init=.TRUE.
-         !
-         IF (ln_bt_fw.OR.(neuler==0)) THEN
-           ll_fw_start=.TRUE.
-           noffset = 0
+         IF( neuler == 0 )   ll_init=.TRUE.
+         !
+         IF( ln_bt_fw .OR. neuler == 0 ) THEN
+            ll_fw_start =.TRUE.
+            noffset     = 0
          ELSE
-           ll_fw_start=.FALSE.
+            ll_fw_start =.FALSE.
          ENDIF
          !
          ! Set averaging weights and cycle length:
-         CALL ts_wgt(ln_bt_av, ll_fw_start, icycle, wgtbtp1, wgtbtp2)
-         !
+         CALL ts_wgt( ln_bt_av, ll_fw_start, icycle, wgtbtp1, wgtbtp2 )
          !
       ENDIF
@@ -219,12 +213,12 @@
       ! and update depths at T-F points (ht and zhf resp.) at each barotropic time step
       !
-      IF ( kt == nit000 .OR. lk_vvl ) THEN
-         IF ( ln_dynvor_een ) THEN              !==  EEN scheme  ==!
+      IF( kt == nit000 .OR. .NOT.ln_linssh ) THEN
+         IF( ln_dynvor_een ) THEN               !==  EEN scheme  ==!
             SELECT CASE( nn_een_e3f )              !* ff/e3 at F-point
             CASE ( 0 )                                   ! original formulation  (masked averaging of e3t divided by 4)
                DO jj = 1, jpjm1
                   DO ji = 1, jpim1
-                     zwz(ji,jj) =   ( ht(ji  ,jj+1) + ht(ji+1,jj+1) +                    &
-                        &             ht(ji  ,jj  ) + ht(ji+1,jj  )   ) / 4._wp  
+                     zwz(ji,jj) =   ( ht_n(ji  ,jj+1) + ht_n(ji+1,jj+1) +                    &
+                        &             ht_n(ji  ,jj  ) + ht_n(ji+1,jj  )   ) * 0.25_wp  
                      IF( zwz(ji,jj) /= 0._wp )   zwz(ji,jj) = ff(ji,jj) / zwz(ji,jj)
                   END DO
@@ -233,6 +227,6 @@
                DO jj = 1, jpjm1
                   DO ji = 1, jpim1
-                     zwz(ji,jj) =   ( ht(ji  ,jj+1) + ht(ji+1,jj+1) +                     &
-                        &             ht(ji  ,jj  ) + ht(ji+1,jj  )   )                   &
+                     zwz(ji,jj) =   ( ht_n(ji  ,jj+1) + ht_n(ji+1,jj+1) +                     &
+                        &             ht_n(ji  ,jj  ) + ht_n(ji+1,jj  )   )                   &
                         &       / ( MAX( 1._wp, tmask(ji  ,jj+1, 1) + tmask(ji+1,jj+1, 1) +    &
                         &                       tmask(ji  ,jj  , 1) + tmask(ji+1,jj  , 1) ) )
@@ -276,5 +270,5 @@
             DO jk = 1, jpkm1
                DO jj = 1, jpjm1
-                  zhf(:,jj) = zhf(:,jj) + fse3f_n(:,jj,jk) * umask(:,jj,jk) * umask(:,jj+1,jk)
+                  zhf(:,jj) = zhf(:,jj) + e3f_n(:,jj,jk) * umask(:,jj,jk) * umask(:,jj+1,jk)
                END DO
             END DO
@@ -308,10 +302,10 @@
       !
       DO jk = 1, jpkm1
-         zu_frc(:,:) = zu_frc(:,:) + fse3u_n(:,:,jk) * ua(:,:,jk) * umask(:,:,jk)
-         zv_frc(:,:) = zv_frc(:,:) + fse3v_n(:,:,jk) * va(:,:,jk) * vmask(:,:,jk)         
+         zu_frc(:,:) = zu_frc(:,:) + e3u_n(:,:,jk) * ua(:,:,jk) * umask(:,:,jk)
+         zv_frc(:,:) = zv_frc(:,:) + e3v_n(:,:,jk) * va(:,:,jk) * vmask(:,:,jk)         
       END DO
       !
-      zu_frc(:,:) = zu_frc(:,:) * hur(:,:)
-      zv_frc(:,:) = zv_frc(:,:) * hvr(:,:)
+      zu_frc(:,:) = zu_frc(:,:) * r1_hu_n(:,:)
+      zv_frc(:,:) = zv_frc(:,:) * r1_hv_n(:,:)
       !
       !
@@ -327,6 +321,6 @@
       !                                   !* barotropic Coriolis trends (vorticity scheme dependent)
       !                                   ! --------------------------------------------------------
-      zwx(:,:) = un_b(:,:) * hu(:,:) * e2u(:,:)        ! now fluxes 
-      zwy(:,:) = vn_b(:,:) * hv(:,:) * e1v(:,:)
+      zwx(:,:) = un_b(:,:) * hu_n(:,:) * e2u(:,:)        ! now fluxes 
+      zwy(:,:) = vn_b(:,:) * hv_n(:,:) * e1v(:,:)
       !
       IF( ln_dynvor_ene .OR. ln_dynvor_mix ) THEN      ! energy conserving or mixed scheme
@@ -373,5 +367,5 @@
       !                                   !* Right-Hand-Side of the barotropic momentum equation
       !                                   ! ----------------------------------------------------
-      IF( lk_vvl ) THEN                         ! Variable volume : remove surface pressure gradient
+      IF( .NOT.ln_linssh ) THEN                 ! Variable volume : remove surface pressure gradient
          DO jj = 2, jpjm1 
             DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -384,6 +378,6 @@
       DO jj = 2, jpjm1                          ! Remove coriolis term (and possibly spg) from barotropic trend
          DO ji = fs_2, fs_jpim1
-             zu_frc(ji,jj) = zu_frc(ji,jj) - zu_trd(ji,jj) * umask(ji,jj,1)
-             zv_frc(ji,jj) = zv_frc(ji,jj) - zv_trd(ji,jj) * vmask(ji,jj,1)
+             zu_frc(ji,jj) = zu_frc(ji,jj) - zu_trd(ji,jj) * ssumask(ji,jj)
+             zv_frc(ji,jj) = zv_frc(ji,jj) - zv_trd(ji,jj) * ssvmask(ji,jj)
           END DO
       END DO 
@@ -411,13 +405,38 @@
       !
       ! Note that the "unclipped" bottom friction parameter is used even with explicit drag
-      zu_frc(:,:) = zu_frc(:,:) + hur(:,:) * bfrua(:,:) * zwx(:,:)
-      zv_frc(:,:) = zv_frc(:,:) + hvr(:,:) * bfrva(:,:) * zwy(:,:)
+      zu_frc(:,:) = zu_frc(:,:) + r1_hu_n(:,:) * bfrua(:,:) * zwx(:,:)
+      zv_frc(:,:) = zv_frc(:,:) + r1_hv_n(:,:) * bfrva(:,:) * zwy(:,:)
+      !       
+      !                                         ! Add top stress contribution from baroclinic velocities:      
+      IF (ln_bt_fw) THEN
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               iktu = miku(ji,jj)
+               iktv = mikv(ji,jj)
+               zwx(ji,jj) = un(ji,jj,iktu) - un_b(ji,jj) ! NOW top baroclinic velocities
+               zwy(ji,jj) = vn(ji,jj,iktv) - vn_b(ji,jj)
+            END DO
+         END DO
+      ELSE
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               iktu = miku(ji,jj)
+               iktv = mikv(ji,jj)
+               zwx(ji,jj) = ub(ji,jj,iktu) - ub_b(ji,jj) ! BEFORE top baroclinic velocities
+               zwy(ji,jj) = vb(ji,jj,iktv) - vb_b(ji,jj)
+            END DO
+         END DO
+      ENDIF
+      !
+      ! Note that the "unclipped" top friction parameter is used even with explicit drag
+      zu_frc(:,:) = zu_frc(:,:) + r1_hu_n(:,:) * tfrua(:,:) * zwx(:,:)
+      zv_frc(:,:) = zv_frc(:,:) + r1_hv_n(:,:) * tfrva(:,:) * zwy(:,:)
       !       
       IF (ln_bt_fw) THEN                        ! Add wind forcing
-         zu_frc(:,:) =  zu_frc(:,:) + zraur * utau(:,:) * hur(:,:)
-         zv_frc(:,:) =  zv_frc(:,:) + zraur * vtau(:,:) * hvr(:,:)
+         zu_frc(:,:) =  zu_frc(:,:) + zraur * utau(:,:) * r1_hu_n(:,:)
+         zv_frc(:,:) =  zv_frc(:,:) + zraur * vtau(:,:) * r1_hv_n(:,:)
       ELSE
-         zu_frc(:,:) =  zu_frc(:,:) + zraur * z1_2 * ( utau_b(:,:) + utau(:,:) ) * hur(:,:)
-         zv_frc(:,:) =  zv_frc(:,:) + zraur * z1_2 * ( vtau_b(:,:) + vtau(:,:) ) * hvr(:,:)
+         zu_frc(:,:) =  zu_frc(:,:) + zraur * z1_2 * ( utau_b(:,:) + utau(:,:) ) * r1_hu_n(:,:)
+         zv_frc(:,:) =  zv_frc(:,:) + zraur * z1_2 * ( vtau_b(:,:) + vtau(:,:) ) * r1_hv_n(:,:)
       ENDIF  
       !
@@ -484,21 +503,21 @@
       !
       IF (ln_bt_fw) THEN                  ! FORWARD integration: start from NOW fields                    
-         sshn_e(:,:) = sshn (:,:)            
-         un_e  (:,:) = un_b (:,:)            
-         vn_e  (:,:) = vn_b (:,:)
-         !
-         hu_e  (:,:) = hu   (:,:)       
-         hv_e  (:,:) = hv   (:,:) 
-         hur_e (:,:) = hur  (:,:)    
-         hvr_e (:,:) = hvr  (:,:)
+         sshn_e(:,:) =    sshn(:,:)            
+         un_e  (:,:) =    un_b(:,:)            
+         vn_e  (:,:) =    vn_b(:,:)
+         !
+         hu_e  (:,:) =    hu_n(:,:)       
+         hv_e  (:,:) =    hv_n(:,:) 
+         hur_e (:,:) = r1_hu_n(:,:)    
+         hvr_e (:,:) = r1_hv_n(:,:)
       ELSE                                ! CENTRED integration: start from BEFORE fields
-         sshn_e(:,:) = sshb (:,:)
-         un_e  (:,:) = ub_b (:,:)         
-         vn_e  (:,:) = vb_b (:,:)
-         !
-         hu_e  (:,:) = hu_b (:,:)       
-         hv_e  (:,:) = hv_b (:,:) 
-         hur_e (:,:) = hur_b(:,:)    
-         hvr_e (:,:) = hvr_b(:,:)
+         sshn_e(:,:) =    sshb(:,:)
+         un_e  (:,:) =    ub_b(:,:)         
+         vn_e  (:,:) =    vb_b(:,:)
+         !
+         hu_e  (:,:) =    hu_b(:,:)       
+         hv_e  (:,:) =    hv_b(:,:) 
+         hur_e (:,:) = r1_hu_b(:,:)    
+         hvr_e (:,:) = r1_hv_b(:,:)
       ENDIF
       !
@@ -518,6 +537,6 @@
          ! Update only tidal forcing at open boundaries
 #if defined key_tide
-         IF ( lk_bdy .AND. lk_tide ) CALL bdy_dta_tides( kt, kit=jn, time_offset=(noffset+1) )
-         IF ( ln_tide_pot .AND. lk_tide ) CALL upd_tide( kt, kit=jn, time_offset=noffset )
+         IF( lk_bdy      .AND. lk_tide )   CALL bdy_dta_tides( kt, kit=jn, time_offset= noffset+1 )
+         IF( ln_tide_pot .AND. lk_tide )   CALL upd_tide     ( kt, kit=jn, time_offset= noffset   )
 #endif
          !
@@ -537,5 +556,5 @@
          va_e(:,:) = za1 * vn_e(:,:) + za2 * vb_e(:,:) + za3 * vbb_e(:,:)
 
-         IF( lk_vvl ) THEN                                !* Update ocean depth (variable volume case only)
+         IF( .NOT.ln_linssh ) THEN                        !* Update ocean depth (variable volume case only)
             !                                             !  ------------------
             ! Extrapolate Sea Level at step jit+0.5:
@@ -544,8 +563,8 @@
             DO jj = 2, jpjm1                                    ! Sea Surface Height at u- & v-points
                DO ji = 2, fs_jpim1   ! Vector opt.
-                  zwx(ji,jj) = z1_2 * umask(ji,jj,1)  * r1_e1e2u(ji,jj)     &
+                  zwx(ji,jj) = z1_2 * ssumask(ji,jj)  * r1_e1e2u(ji,jj)     &
                      &              * ( e1e2t(ji  ,jj) * zsshp2_e(ji  ,jj)  &
                      &              +   e1e2t(ji+1,jj) * zsshp2_e(ji+1,jj) )
-                  zwy(ji,jj) = z1_2 * vmask(ji,jj,1)  * r1_e1e2v(ji,jj)     &
+                  zwy(ji,jj) = z1_2 * ssvmask(ji,jj)  * r1_e1e2v(ji,jj)     &
                      &              * ( e1e2t(ji,jj  ) * zsshp2_e(ji,jj  )  &
                      &              +   e1e2t(ji,jj+1) * zsshp2_e(ji,jj+1) )
@@ -557,6 +576,6 @@
             zhvp2_e (:,:) = hv_0(:,:) + zwy(:,:)
          ELSE
-            zhup2_e (:,:) = hu(:,:)
-            zhvp2_e (:,:) = hv(:,:)
+            zhup2_e (:,:) = hu_n(:,:)
+            zhvp2_e (:,:) = hv_n(:,:)
          ENDIF
          !                                                !* after ssh
@@ -569,7 +588,6 @@
          !
 #if defined key_agrif
-         ! Set fluxes during predictor step to ensure 
-         ! volume conservation
-         IF( (.NOT.Agrif_Root()).AND.ln_bt_fw ) THEN
+         ! Set fluxes during predictor step to ensure volume conservation
+         IF( .NOT.Agrif_Root() .AND. ln_bt_fw ) THEN
             IF((nbondi == -1).OR.(nbondi == 2)) THEN
                DO jj=1,jpj
@@ -607,25 +625,25 @@
             END DO
          END DO
-         ssha_e(:,:) = (  sshn_e(:,:) - rdtbt * ( zssh_frc(:,:) + zhdiv(:,:) )  ) * tmask(:,:,1)
+         ssha_e(:,:) = (  sshn_e(:,:) - rdtbt * ( zssh_frc(:,:) + zhdiv(:,:) )  ) * ssmask(:,:)
          CALL lbc_lnk( ssha_e, 'T',  1._wp )
 
 #if defined key_bdy
-         ! Duplicate sea level across open boundaries (this is only cosmetic if lk_vvl=.false.)
-         IF (lk_bdy) CALL bdy_ssh( ssha_e )
+         ! Duplicate sea level across open boundaries (this is only cosmetic if linssh=T)
+         IF( lk_bdy )   CALL bdy_ssh( ssha_e )
 #endif
 #if defined key_agrif
-         IF( .NOT.Agrif_Root() ) CALL agrif_ssh_ts( jn )
+         IF( .NOT.Agrif_Root() )   CALL agrif_ssh_ts( jn )
 #endif
          !  
          ! Sea Surface Height at u-,v-points (vvl case only)
-         IF ( lk_vvl ) THEN                                
+         IF( .NOT.ln_linssh ) THEN                                
             DO jj = 2, jpjm1
                DO ji = 2, jpim1      ! NO Vector Opt.
-                  zsshu_a(ji,jj) = z1_2 * umask(ji,jj,1)  * r1_e1e2u(ji,jj)  &
-                     &              * ( e1e2t(ji  ,jj  ) * ssha_e(ji  ,jj  ) &
-                     &              +   e1e2t(ji+1,jj  ) * ssha_e(ji+1,jj  ) )
-                  zsshv_a(ji,jj) = z1_2 * vmask(ji,jj,1)  * r1_e1e2v(ji,jj)  &
-                     &              * ( e1e2t(ji  ,jj  ) * ssha_e(ji  ,jj  ) &
-                     &              +   e1e2t(ji  ,jj+1) * ssha_e(ji  ,jj+1) )
+                  zsshu_a(ji,jj) = z1_2 * ssumask(ji,jj) * r1_e1e2u(ji,jj)    &
+                     &              * ( e1e2t(ji  ,jj  )  * ssha_e(ji  ,jj  ) &
+                     &              +   e1e2t(ji+1,jj  )  * ssha_e(ji+1,jj  ) )
+                  zsshv_a(ji,jj) = z1_2 * ssvmask(ji,jj) * r1_e1e2v(ji,jj)    &
+                     &              * ( e1e2t(ji  ,jj  )  * ssha_e(ji  ,jj  ) &
+                     &              +   e1e2t(ji  ,jj+1)  * ssha_e(ji  ,jj+1) )
                END DO
             END DO
@@ -651,18 +669,17 @@
            za3=0.013_wp                     ! za3 = eps
          ENDIF
-
+         !
          zsshp2_e(:,:) = za0 *  ssha_e(:,:) + za1 *  sshn_e (:,:) &
           &            + za2 *  sshb_e(:,:) + za3 *  sshbb_e(:,:)
-
          !
          ! Compute associated depths at U and V points:
-         IF ( lk_vvl.AND.(.NOT.ln_dynadv_vec) ) THEN      
+         IF( .NOT.ln_linssh  .AND. .NOT.ln_dynadv_vec ) THEN 	!* Vector form
             !                                        
             DO jj = 2, jpjm1                            
                DO ji = 2, jpim1
-                  zx1 = z1_2 * umask(ji  ,jj,1) *  r1_e1e2u(ji  ,jj)    &
+                  zx1 = z1_2 * ssumask(ji  ,jj) *  r1_e1e2u(ji  ,jj)    &
                      &      * ( e1e2t(ji  ,jj  ) * zsshp2_e(ji  ,jj)    &
                      &      +   e1e2t(ji+1,jj  ) * zsshp2_e(ji+1,jj  ) )
-                  zy1 = z1_2 * vmask(ji  ,jj,1) *  r1_e1e2v(ji  ,jj  )  &
+                  zy1 = z1_2 * ssvmask(ji  ,jj) *  r1_e1e2v(ji  ,jj  )  &
                      &       * ( e1e2t(ji ,jj  ) * zsshp2_e(ji  ,jj  )  &
                      &       +   e1e2t(ji ,jj+1) * zsshp2_e(ji  ,jj+1) )
@@ -674,5 +691,5 @@
          !
          ! Add Coriolis trend:
-         ! zwz array below or triads normally depend on sea level with key_vvl and should be updated
+         ! zwz array below or triads normally depend on sea level with ln_linssh=F and should be updated
          ! at each time step. We however keep them constant here for optimization.
          ! Recall that zwx and zwy arrays hold fluxes at this stage:
@@ -680,5 +697,5 @@
          ! zwy(:,:) = e1v(:,:) * va_e(:,:) * zhvp2_e(:,:)
          !
-         IF( ln_dynvor_ene .OR. ln_dynvor_mix ) THEN      !==  energy conserving or mixed scheme  ==!
+         IF( ln_dynvor_ene .OR. ln_dynvor_mix ) THEN     !==  energy conserving or mixed scheme  ==!
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -692,5 +709,5 @@
             END DO
             !
-         ELSEIF ( ln_dynvor_ens ) THEN                    !==  enstrophy conserving scheme  ==!
+         ELSEIF ( ln_dynvor_ens ) THEN                   !==  enstrophy conserving scheme  ==!
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -704,5 +721,5 @@
             END DO
             !
-         ELSEIF ( ln_dynvor_een ) THEN !==  energy and enstrophy conserving scheme  ==!
+         ELSEIF ( ln_dynvor_een ) THEN                   !==  energy and enstrophy conserving scheme  ==!
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -736,4 +753,8 @@
          zv_trd(:,:) = zv_trd(:,:) + bfrva(:,:) * vn_e(:,:) * hvr_e(:,:)
          !
+         ! Add top stresses:
+         zu_trd(:,:) = zu_trd(:,:) + tfrua(:,:) * un_e(:,:) * hur_e(:,:)
+         zv_trd(:,:) = zv_trd(:,:) + tfrva(:,:) * vn_e(:,:) * hvr_e(:,:)
+         !
          ! Surface pressure trend:
          DO jj = 2, jpjm1
@@ -748,5 +769,5 @@
          !
          ! Set next velocities:
-         IF( ln_dynadv_vec .OR. (.NOT. lk_vvl) ) THEN 	! Vector form
+         IF( ln_dynadv_vec .OR. ln_linssh ) THEN 	!* Vector form
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -755,5 +776,5 @@
                             &                                 + zu_trd(ji,jj)   &
                             &                                 + zu_frc(ji,jj) ) & 
-                            &   ) * umask(ji,jj,1)
+                            &   ) * ssumask(ji,jj)
 
                   va_e(ji,jj) = (                                 vn_e(ji,jj)   &
@@ -761,19 +782,18 @@
                             &                                 + zv_trd(ji,jj)   &
                             &                                 + zv_frc(ji,jj) ) &
-                            &   ) * vmask(ji,jj,1)
-               END DO
-            END DO
-
-         ELSE					 	! Flux form
+                            &   ) * ssvmask(ji,jj)
+               END DO
+            END DO
+            !
+         ELSE					 	                     !* Flux form
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-
-                  zhura = umask(ji,jj,1)/(hu_0(ji,jj) + zsshu_a(ji,jj) + 1._wp - umask(ji,jj,1))
-                  zhvra = vmask(ji,jj,1)/(hv_0(ji,jj) + zsshv_a(ji,jj) + 1._wp - vmask(ji,jj,1))
+                  zhura = ssumask(ji,jj)/(hu_0(ji,jj) + zsshu_a(ji,jj) + 1._wp - ssumask(ji,jj))
+                  zhvra = ssvmask(ji,jj)/(hv_0(ji,jj) + zsshv_a(ji,jj) + 1._wp - ssvmask(ji,jj))
 
                   ua_e(ji,jj) = (                hu_e(ji,jj)  *   un_e(ji,jj)   & 
                             &     + rdtbt * ( zhust_e(ji,jj)  *    zwx(ji,jj)   & 
                             &               + zhup2_e(ji,jj)  * zu_trd(ji,jj)   &
-                            &               +      hu(ji,jj)  * zu_frc(ji,jj) ) &
+                            &               +    hu_n(ji,jj)  * zu_frc(ji,jj) ) &
                             &   ) * zhura
 
@@ -781,5 +801,5 @@
                             &     + rdtbt * ( zhvst_e(ji,jj)  *    zwy(ji,jj)   &
                             &               + zhvp2_e(ji,jj)  * zv_trd(ji,jj)   &
-                            &               +      hv(ji,jj)  * zv_frc(ji,jj) ) &
+                            &               +    hv_n(ji,jj)  * zv_frc(ji,jj) ) &
                             &   ) * zhvra
                END DO
@@ -787,20 +807,17 @@
          ENDIF
          !
-         IF( lk_vvl ) THEN                             !* Update ocean depth (variable volume case only)
-            !                                          !  ----------------------------------------------        
+         IF( .NOT.ln_linssh ) THEN                     !* Update ocean depth (variable volume case only)
             hu_e (:,:) = hu_0(:,:) + zsshu_a(:,:)
             hv_e (:,:) = hv_0(:,:) + zsshv_a(:,:)
-            hur_e(:,:) = umask(:,:,1) / ( hu_e(:,:) + 1._wp - umask(:,:,1) )
-            hvr_e(:,:) = vmask(:,:,1) / ( hv_e(:,:) + 1._wp - vmask(:,:,1) )
+            hur_e(:,:) = ssumask(:,:) / ( hu_e(:,:) + 1._wp - ssumask(:,:) )
+            hvr_e(:,:) = ssvmask(:,:) / ( hv_e(:,:) + 1._wp - ssvmask(:,:) )
             !
          ENDIF
-         !                                                 !* domain lateral boundary
-         !                                                 !  -----------------------
-         !
+         !                                             !* domain lateral boundary
          CALL lbc_lnk_multi( ua_e, 'U', -1._wp, va_e , 'V', -1._wp )
-
+         !
 #if defined key_bdy  
-                                                           ! open boundaries
-         IF( lk_bdy ) CALL bdy_dyn2d( jn, ua_e, va_e, un_e, vn_e, hur_e, hvr_e, ssha_e )
+         !                                                 ! open boundaries
+         IF( lk_bdy )   CALL bdy_dyn2d( jn, ua_e, va_e, un_e, vn_e, hur_e, hvr_e, ssha_e )
 #endif
 #if defined key_agrif                                                           
@@ -824,8 +841,8 @@
          !                                             !  ----------------------
          za1 = wgtbtp1(jn)                                    
-         IF (( ln_dynadv_vec ).OR. (.NOT. lk_vvl)) THEN    ! Sum velocities
+         IF( ln_dynadv_vec .OR. ln_linssh ) THEN    ! Sum velocities
             ua_b  (:,:) = ua_b  (:,:) + za1 * ua_e  (:,:) 
             va_b  (:,:) = va_b  (:,:) + za1 * va_e  (:,:) 
-         ELSE                     			   ! Sum transports
+         ELSE                                              ! Sum transports
             ua_b  (:,:) = ua_b  (:,:) + za1 * ua_e  (:,:) * hu_e (:,:)
             va_b  (:,:) = va_b  (:,:) + za1 * va_e  (:,:) * hv_e (:,:)
@@ -843,13 +860,13 @@
       zwx(:,:) = un_adv(:,:)
       zwy(:,:) = vn_adv(:,:)
-      IF (((kt==nit000).AND.(neuler==0)).OR.(.NOT.ln_bt_fw)) THEN     
-         un_adv(:,:) = zwx(:,:)*hur(:,:)
-         vn_adv(:,:) = zwy(:,:)*hvr(:,:)
+      IF( ( kt == nit000 .AND. neuler==0 ) .OR. .NOT.ln_bt_fw ) THEN     
+         un_adv(:,:) = zwx(:,:) * r1_hu_n(:,:)
+         vn_adv(:,:) = zwy(:,:) * r1_hv_n(:,:)
       ELSE
-         un_adv(:,:) = z1_2 * ( ub2_b(:,:) + zwx(:,:)) * hur(:,:)
-         vn_adv(:,:) = z1_2 * ( vb2_b(:,:) + zwy(:,:)) * hvr(:,:)
+         un_adv(:,:) = z1_2 * ( ub2_b(:,:) + zwx(:,:) ) * r1_hu_n(:,:)
+         vn_adv(:,:) = z1_2 * ( vb2_b(:,:) + zwy(:,:) ) * r1_hv_n(:,:)
       END IF
 
-      IF (ln_bt_fw) THEN ! Save integrated transport for next computation
+      IF( ln_bt_fw ) THEN ! Save integrated transport for next computation
          ub2_b(:,:) = zwx(:,:)
          vb2_b(:,:) = zwy(:,:)
@@ -857,5 +874,5 @@
       !
       ! Update barotropic trend:
-      IF (( ln_dynadv_vec ).OR. (.NOT. lk_vvl)) THEN
+      IF( ln_dynadv_vec .OR. ln_linssh ) THEN
          DO jk=1,jpkm1
             ua(:,:,jk) = ua(:,:,jk) + ( ua_b(:,:) - ub_b(:,:) ) * z1_2dt_b
@@ -877,18 +894,21 @@
          !
          DO jk=1,jpkm1
-            ua(:,:,jk) = ua(:,:,jk) + hur(:,:) * ( ua_b(:,:) - ub_b(:,:) * hu_b(:,:) ) * z1_2dt_b
-            va(:,:,jk) = va(:,:,jk) + hvr(:,:) * ( va_b(:,:) - vb_b(:,:) * hv_b(:,:) ) * z1_2dt_b
+            ua(:,:,jk) = ua(:,:,jk) + r1_hu_n(:,:) * ( ua_b(:,:) - ub_b(:,:) * hu_b(:,:) ) * z1_2dt_b
+            va(:,:,jk) = va(:,:,jk) + r1_hv_n(:,:) * ( va_b(:,:) - vb_b(:,:) * hv_b(:,:) ) * z1_2dt_b
          END DO
          ! Save barotropic velocities not transport:
-         ua_b  (:,:) =  ua_b(:,:) / ( hu_0(:,:) + zsshu_a(:,:) + 1._wp - umask(:,:,1) )
-         va_b  (:,:) =  va_b(:,:) / ( hv_0(:,:) + zsshv_a(:,:) + 1._wp - vmask(:,:,1) )
+         ua_b(:,:) =  ua_b(:,:) / ( hu_0(:,:) + zsshu_a(:,:) + 1._wp - ssumask(:,:) )
+         va_b(:,:) =  va_b(:,:) / ( hv_0(:,:) + zsshv_a(:,:) + 1._wp - ssvmask(:,:) )
       ENDIF
       !
       DO jk = 1, jpkm1
          ! Correct velocities:
-         un(:,:,jk) = ( un(:,:,jk) + un_adv(:,:) - un_b(:,:) )*umask(:,:,jk)
-         vn(:,:,jk) = ( vn(:,:,jk) + vn_adv(:,:) - vn_b(:,:) )*vmask(:,:,jk)
+         un(:,:,jk) = ( un(:,:,jk) + un_adv(:,:) - un_b(:,:) ) * umask(:,:,jk)
+         vn(:,:,jk) = ( vn(:,:,jk) + vn_adv(:,:) - vn_b(:,:) ) * vmask(:,:,jk)
          !
       END DO
+      !
+      CALL iom_put(  "ubar", un_adv(:,:)      )    ! barotropic i-current
+      CALL iom_put(  "vbar", vn_adv(:,:)      )    ! barotropic i-current
       !
 #if defined key_agrif
@@ -896,8 +916,8 @@
       ! (used to update coarse grid transports at next time step)
       !
-      IF ( (.NOT.Agrif_Root()).AND.(ln_bt_fw) ) THEN
-         IF ( Agrif_NbStepint().EQ.0 ) THEN
-            ub2_i_b(:,:) = 0.e0
-            vb2_i_b(:,:) = 0.e0
+      IF( .NOT.Agrif_Root() .AND. ln_bt_fw ) THEN
+         IF( Agrif_NbStepint() == 0 ) THEN
+            ub2_i_b(:,:) = 0._wp
+            vb2_i_b(:,:) = 0._wp
          END IF
          !
@@ -906,21 +926,23 @@
          vb2_i_b(:,:) = vb2_i_b(:,:) + za1 * vb2_b(:,:)
       ENDIF
-      !
-      !
 #endif      
-      !
       !                                   !* write time-spliting arrays in the restart
-      IF(lrst_oce .AND.ln_bt_fw)   CALL ts_rst( kt, 'WRITE' )
-      !
-      CALL wrk_dealloc( jpi, jpj, zsshp2_e, zhdiv )
-      CALL wrk_dealloc( jpi, jpj, zu_trd, zv_trd )
-      CALL wrk_dealloc( jpi, jpj, zwx, zwy, zssh_frc, zu_frc, zv_frc )
-      CALL wrk_dealloc( jpi, jpj, zhup2_e, zhvp2_e, zhust_e, zhvst_e )
-      CALL wrk_dealloc( jpi, jpj, zsshu_a, zsshv_a                                   )
-      CALL wrk_dealloc( jpi, jpj, zhf )
-      !
+      IF( lrst_oce .AND.ln_bt_fw )   CALL ts_rst( kt, 'WRITE' )
+      !
+      CALL wrk_dealloc( jpi,jpj,   zsshp2_e, zhdiv )
+      CALL wrk_dealloc( jpi,jpj,   zu_trd, zv_trd )
+      CALL wrk_dealloc( jpi,jpj,   zwx, zwy, zssh_frc, zu_frc, zv_frc )
+      CALL wrk_dealloc( jpi,jpj,   zhup2_e, zhvp2_e, zhust_e, zhvst_e )
+      CALL wrk_dealloc( jpi,jpj,   zsshu_a, zsshv_a                                   )
+      CALL wrk_dealloc( jpi,jpj,   zhf )
+      !
+      IF ( ln_diatmb ) THEN
+         CALL iom_put( "baro_u" , un_b*umask(:,:,1)+zmdi*(1-umask(:,:,1 ) ) )  ! Barotropic  U Velocity
+         CALL iom_put( "baro_v" , vn_b*vmask(:,:,1)+zmdi*(1-vmask(:,:,1 ) ) )  ! Barotropic  V Velocity
+      ENDIF
       IF( nn_timing == 1 )  CALL timing_stop('dyn_spg_ts')
       !
    END SUBROUTINE dyn_spg_ts
+
 
    SUBROUTINE ts_wgt( ll_av, ll_fw, jpit, zwgt1, zwgt2)
@@ -1001,4 +1023,5 @@
    END SUBROUTINE ts_wgt
 
+
    SUBROUTINE ts_rst( kt, cdrw )
       !!---------------------------------------------------------------------
@@ -1054,5 +1077,6 @@
    END SUBROUTINE ts_rst
 
-   SUBROUTINE dyn_spg_ts_init( kt )
+
+   SUBROUTINE dyn_spg_ts_init
       !!---------------------------------------------------------------------
       !!                   ***  ROUTINE dyn_spg_ts_init  ***
@@ -1060,15 +1084,12 @@
       !! ** Purpose : Set time splitting options
       !!----------------------------------------------------------------------
-      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
-      !
-      INTEGER  :: ji ,jj
-      REAL(wp) :: zxr2, zyr2, zcmax
-      REAL(wp), POINTER, DIMENSION(:,:) :: zcu
-      !!
+      INTEGER  ::   ji ,jj              ! dummy loop indices
+      REAL(wp) ::   zxr2, zyr2, zcmax   ! local scalar
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zcu
       !!----------------------------------------------------------------------
       !
       ! Max courant number for ext. grav. waves
       !
-      CALL wrk_alloc( jpi, jpj, zcu )
+      CALL wrk_alloc( jpi,jpj,   zcu )
       !
       DO jj = 1, jpj
@@ -1084,5 +1105,5 @@
 
       ! Estimate number of iterations to satisfy a max courant number= rn_bt_cmax
-      IF (ln_bt_auto) nn_baro = CEILING( rdt / rn_bt_cmax * zcmax)
+      IF( ln_bt_auto )   nn_baro = CEILING( rdt / rn_bt_cmax * zcmax)
       
       rdtbt = rdt / REAL( nn_baro , wp )
@@ -1114,13 +1135,13 @@
 #if defined key_agrif
       ! Restrict the use of Agrif to the forward case only
-      IF ((.NOT.ln_bt_fw ).AND.(.NOT.Agrif_Root())) CALL ctl_stop( 'AGRIF not implemented if ln_bt_fw=.FALSE.' )
+      IF( .NOT.ln_bt_fw .AND. .NOT.Agrif_Root() )   CALL ctl_stop( 'AGRIF not implemented if ln_bt_fw=.FALSE.' )
 #endif
       !
       IF(lwp) WRITE(numout,*)    '     Time filter choice, nn_bt_flt: ', nn_bt_flt
       SELECT CASE ( nn_bt_flt )
-           CASE( 0 )  ;   IF(lwp) WRITE(numout,*) '           Dirac'
-           CASE( 1 )  ;   IF(lwp) WRITE(numout,*) '           Boxcar: width = nn_baro'
-           CASE( 2 )  ;   IF(lwp) WRITE(numout,*) '           Boxcar: width = 2*nn_baro' 
-           CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_bt_flt: should 0,1,2' )
+         CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '           Dirac'
+         CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '           Boxcar: width = nn_baro'
+         CASE( 2 )      ;   IF(lwp) WRITE(numout,*) '           Boxcar: width = 2*nn_baro' 
+         CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_bt_flt: should 0,1,2' )
       END SELECT
       !
@@ -1130,12 +1151,12 @@
       IF(lwp) WRITE(numout,*) '     Maximum Courant number is   :', zcmax
       !
-      IF ((.NOT.ln_bt_av).AND.(.NOT.ln_bt_fw)) THEN
+      IF( .NOT.ln_bt_av .AND. .NOT.ln_bt_fw ) THEN
          CALL ctl_stop( 'dynspg_ts ERROR: No time averaging => only forward integration is possible' )
       ENDIF
-      IF ( zcmax>0.9_wp ) THEN
+      IF( zcmax>0.9_wp ) THEN
          CALL ctl_stop( 'dynspg_ts ERROR: Maximum Courant number is greater than 0.9: Inc. nn_baro !' )          
       ENDIF
       !
-      CALL wrk_dealloc( jpi, jpj, zcu )
+      CALL wrk_dealloc( jpi,jpj,   zcu )
       !
    END SUBROUTINE dyn_spg_ts_init
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 6140)
@@ -32,5 +32,4 @@
    USE trd_oce        ! trends: ocean variables
    USE trddyn         ! trend manager: dynamics
-   USE c1d            ! 1D vertical configuration
    !
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
@@ -76,5 +75,4 @@
    
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -285,7 +283,7 @@
 
          IF( ln_sco ) THEN
-            zwz(:,:) = zwz(:,:) / fse3f(:,:,jk)
-            zwx(:,:) = e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
-            zwy(:,:) = e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+            zwz(:,:) = zwz(:,:) / e3f_n(:,:,jk)
+            zwx(:,:) = e2u(:,:) * e3u_n(:,:,jk) * un(:,:,jk)
+            zwy(:,:) = e1v(:,:) * e3v_n(:,:,jk) * vn(:,:,jk)
          ELSE
             zwx(:,:) = e2u(:,:) * un(:,:,jk)
@@ -405,7 +403,7 @@
          !
          IF( ln_sco ) THEN                   !==  horizontal fluxes  ==!
-            zwz(:,:) = zwz(:,:) / fse3f(:,:,jk)
-            zwx(:,:) = e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
-            zwy(:,:) = e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+            zwz(:,:) = zwz(:,:) / e3f_n(:,:,jk)
+            zwx(:,:) = e2u(:,:) * e3u_n(:,:,jk) * un(:,:,jk)
+            zwy(:,:) = e1v(:,:) * e3v_n(:,:,jk) * vn(:,:,jk)
          ELSE
             zwx(:,:) = e2u(:,:) * un(:,:,jk)
@@ -415,8 +413,8 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zuav = r1_8 * r1_e1u(ji,jj) * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1)   &
-                  &                       + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) )
-               zvau =-r1_8 * r1_e2v(ji,jj) * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1)   &
-                  &                       + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) )
+               zuav = r1_8 * r1_e1u(ji,jj) * (  zwy(ji  ,jj-1) + zwy(ji+1,jj-1)  &
+                  &                           + zwy(ji  ,jj  ) + zwy(ji+1,jj  )  )
+               zvau =-r1_8 * r1_e2v(ji,jj) * (  zwx(ji-1,jj  ) + zwx(ji-1,jj+1)  &
+                  &                           + zwx(ji  ,jj  ) + zwx(ji  ,jj+1)  )
                pua(ji,jj,jk) = pua(ji,jj,jk) + zuav * ( zwz(ji  ,jj-1) + zwz(ji,jj) )
                pva(ji,jj,jk) = pva(ji,jj,jk) + zvau * ( zwz(ji-1,jj  ) + zwz(ji,jj) )
@@ -483,8 +481,8 @@
             DO jj = 1, jpjm1
                DO ji = 1, fs_jpim1   ! vector opt.
-                  ze3  = ( fse3t(ji,jj+1,jk)*tmask(ji,jj+1,jk) + fse3t(ji+1,jj+1,jk)*tmask(ji+1,jj+1,jk)   &
-                     &   + fse3t(ji,jj  ,jk)*tmask(ji,jj  ,jk) + fse3t(ji+1,jj  ,jk)*tmask(ji+1,jj  ,jk) )
-                  IF( ze3 /= 0._wp ) THEN   ;   z1_e3f(ji,jj) = 4.0_wp / ze3
-                  ELSE                      ;   z1_e3f(ji,jj) = 0.0_wp
+                  ze3  = (  e3t_n(ji,jj+1,jk)*tmask(ji,jj+1,jk) + e3t_n(ji+1,jj+1,jk)*tmask(ji+1,jj+1,jk)   &
+                     &    + e3t_n(ji,jj  ,jk)*tmask(ji,jj  ,jk) + e3t_n(ji+1,jj  ,jk)*tmask(ji+1,jj  ,jk)  )
+                  IF( ze3 /= 0._wp ) THEN   ;   z1_e3f(ji,jj) = 4._wp / ze3
+                  ELSE                      ;   z1_e3f(ji,jj) = 0._wp
                   ENDIF
                END DO
@@ -493,10 +491,10 @@
             DO jj = 1, jpjm1
                DO ji = 1, fs_jpim1   ! vector opt.
-                  ze3  = ( fse3t(ji,jj+1,jk)*tmask(ji,jj+1,jk) + fse3t(ji+1,jj+1,jk)*tmask(ji+1,jj+1,jk)   &
-                     &   + fse3t(ji,jj  ,jk)*tmask(ji,jj  ,jk) + fse3t(ji+1,jj  ,jk)*tmask(ji+1,jj  ,jk) )
-                  zmsk = (                   tmask(ji,jj+1,jk) +                     tmask(ji+1,jj+1,jk)   &
-                     &                     + tmask(ji,jj  ,jk) +                     tmask(ji+1,jj  ,jk) )
+                  ze3  = (  e3t_n(ji,jj+1,jk)*tmask(ji,jj+1,jk) + e3t_n(ji+1,jj+1,jk)*tmask(ji+1,jj+1,jk)   &
+                     &    + e3t_n(ji,jj  ,jk)*tmask(ji,jj  ,jk) + e3t_n(ji+1,jj  ,jk)*tmask(ji+1,jj  ,jk)  )
+                  zmsk = (                    tmask(ji,jj+1,jk) +                     tmask(ji+1,jj+1,jk)   &
+                     &                      + tmask(ji,jj  ,jk) +                     tmask(ji+1,jj  ,jk)  )
                   IF( ze3 /= 0._wp ) THEN   ;   z1_e3f(ji,jj) = zmsk / ze3
-                  ELSE                      ;   z1_e3f(ji,jj) = 0.0_wp
+                  ELSE                      ;   z1_e3f(ji,jj) = 0._wp
                   ENDIF
                END DO
@@ -559,6 +557,6 @@
          !
          !                                   !==  horizontal fluxes  ==!
-         zwx(:,:) = e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
-         zwy(:,:) = e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+         zwx(:,:) = e2u(:,:) * e3u_n(:,:,jk) * un(:,:,jk)
+         zwy(:,:) = e1v(:,:) * e3v_n(:,:,jk) * vn(:,:,jk)
 
          !                                   !==  compute and add the vorticity term trend  =!
@@ -634,5 +632,5 @@
          WRITE(numout,*) '           enstrophy and energy conserving scheme         ln_dynvor_een = ', ln_dynvor_een
          WRITE(numout,*) '              e3f = averaging /4 (=0) or /sum(tmask) (=1)    nn_een_e3f = ', nn_een_e3f
-         WRITE(numout,*) '           masked (=1) or unmasked(=0) vorticity          ln_dynvor_msk = ', ln_dynvor_msk
+         WRITE(numout,*) '           masked (=T) or unmasked(=F) vorticity          ln_dynvor_msk = ', ln_dynvor_msk
       ENDIF
 
@@ -663,5 +661,5 @@
       IF( ln_dynvor_een ) THEN   ;   ioptio = ioptio + 1   ;    nvor_scheme = np_EEN   ;   ENDIF
       !
-      IF( ( ioptio /= 1).AND.( .NOT.lk_c1d ) ) CALL ctl_stop( ' use ONE and ONLY one vorticity scheme' )
+      IF( ioptio /= 1 ) CALL ctl_stop( ' use ONE and ONLY one vorticity scheme' )
       !                      
       IF(lwp) WRITE(numout,*)        ! type of calculated vorticity (set ncor, nrvm, ntot)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynzad.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynzad.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynzad.F90	(revision 6140)
@@ -32,5 +32,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -90,6 +89,6 @@
          DO jj = 2, jpjm1                 ! vertical momentum advection at w-point
             DO ji = fs_2, fs_jpim1        ! vector opt.
-               zwuw(ji,jj,jk) = ( zww(ji+1,jj  ) + zww(ji,jj) ) * ( un(ji,jj,jk-1)-un(ji,jj,jk) )
-               zwvw(ji,jj,jk) = ( zww(ji  ,jj+1) + zww(ji,jj) ) * ( vn(ji,jj,jk-1)-vn(ji,jj,jk) )
+               zwuw(ji,jj,jk) = ( zww(ji+1,jj  ) + zww(ji,jj) ) * ( un(ji,jj,jk-1) - un(ji,jj,jk) )
+               zwvw(ji,jj,jk) = ( zww(ji  ,jj+1) + zww(ji,jj) ) * ( vn(ji,jj,jk-1) - vn(ji,jj,jk) )
             END DO  
          END DO   
@@ -121,6 +120,6 @@
             DO ji = fs_2, fs_jpim1       ! vector opt.
                !                         ! vertical momentum advective trends
-               zua = - ( zwuw(ji,jj,jk) + zwuw(ji,jj,jk+1) ) / ( e1e2u(ji,jj) * fse3u(ji,jj,jk) )
-               zva = - ( zwvw(ji,jj,jk) + zwvw(ji,jj,jk+1) ) / ( e1e2v(ji,jj) * fse3v(ji,jj,jk) )
+               zua = - ( zwuw(ji,jj,jk) + zwuw(ji,jj,jk+1) ) * r1_e1e2u(ji,jj) / e3u_n(ji,jj,jk)
+               zva = - ( zwvw(ji,jj,jk) + zwvw(ji,jj,jk+1) ) * r1_e1e2v(ji,jj) / e3v_n(ji,jj,jk)
                !                         ! add the trends to the general momentum trends
                ua(ji,jj,jk) = ua(ji,jj,jk) + zua
@@ -252,6 +251,6 @@
                DO ji = fs_2, fs_jpim1       ! vector opt.
                   !                         ! vertical momentum advective trends
-                  zua = - ( zwuw(ji,jj,jk) + zwuw(ji,jj,jk+1) ) / ( e1e2u(ji,jj) * fse3u(ji,jj,jk) )
-                  zva = - ( zwvw(ji,jj,jk) + zwvw(ji,jj,jk+1) ) / ( e1e2v(ji,jj) * fse3v(ji,jj,jk) )
+                  zua = - ( zwuw(ji,jj,jk) + zwuw(ji,jj,jk+1) ) * r1_e1e2u(ji,jj) / e3u_n(ji,jj,jk)
+                  zva = - ( zwvw(ji,jj,jk) + zwvw(ji,jj,jk+1) ) * r1_e1e2v(ji,jj) / e3v_n(ji,jj,jk)
                   zus(ji,jj,jk,jta) = zus(ji,jj,jk,jtb) + zua * zts
                   zvs(ji,jj,jk,jta) = zvs(ji,jj,jk,jtb) + zva * zts
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf.F90	(revision 6140)
@@ -34,9 +34,6 @@
 
    INTEGER  ::   nzdf = 0   ! type vertical diffusion algorithm used, defined from ln_zdf... namlist logicals
-   REAL(wp) ::   r2dt       ! time-step, = 2 rdttra except at nit000 (=rdttra) if neuler=0
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -63,6 +60,6 @@
       !
       !                                          ! set time step
-      IF( neuler == 0 .AND. kt == nit000     ) THEN   ;   r2dt =      rdt   ! = rdtra (restart with Euler time stepping)
-      ELSEIF(               kt <= nit000 + 1 ) THEN   ;   r2dt = 2. * rdt   ! = 2 rdttra (leapfrog)
+      IF( neuler == 0 .AND. kt == nit000     ) THEN   ;   r2dt =      rdt   ! = rdt (restart with Euler time stepping)
+      ELSEIF(               kt <= nit000 + 1 ) THEN   ;   r2dt = 2. * rdt   ! = 2 rdt (leapfrog)
       ENDIF
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_exp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_exp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_exp.F90	(revision 6140)
@@ -12,19 +12,18 @@
 
    !!----------------------------------------------------------------------
-   !!   dyn_zdf_exp  : update the momentum trend with the vertical diffu-
-   !!                  sion using an explicit time-stepping scheme.
+   !!   dyn_zdf_exp   : update the momentum trend with the vertical diffusion using a split-explicit scheme
+   !!                   and perform the Leap-Frog time integration.
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE zdf_oce         ! ocean vertical physics
-   USE dynadv, ONLY: ln_dynadv_vec ! Momentum advection form
-   USE sbc_oce         ! surface boundary condition: ocean
-   USE lib_mpp         ! MPP library
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
-
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE zdf_oce        ! ocean vertical physics
+   USE dynadv   , ONLY: ln_dynadv_vec ! Momentum advection form
+   USE sbc_oce        ! surface boundary condition: ocean
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -34,8 +33,7 @@
    
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -48,7 +46,8 @@
       !!                   
       !! ** Purpose :   Compute the trend due to the vert. momentum diffusion
+      !!              and perform the Leap-Frog time stepping.
       !!
-      !! ** Method  :   Explicit forward time stepping with a time splitting
-      !!      technique. The vertical diffusion of momentum is given by:
+      !! ** Method  : - Split-explicit forward time stepping.
+      !!      The vertical mixing of momentum is given by:
       !!         diffu = dz( avmu dz(u) ) = 1/e3u dk+1( avmu/e3uw dk(ub) )
       !!      Surface boundary conditions: wind stress input (averaged over kt-1/2 & kt+1/2)
@@ -56,18 +55,21 @@
       !!      Add this trend to the general trend ua :
       !!         ua = ua + dz( avmu dz(u) )
+      !!              - Leap-Frog time stepping (Asselin filter will be applied in dyn_nxt) 
+      !!         ua =         ub + 2*dt *       ua             vector form or linear free surf.
+      !!         ua = ( e3u_b*ub + 2*dt * e3u_n*ua ) / e3u_a   otherwise
       !!
-      !! ** Action : - Update (ua,va) with the vertical diffusive trend
+      !! ** Action : - (ua,va) after velocity
       !!---------------------------------------------------------------------
       INTEGER , INTENT(in) ::   kt     ! ocean time-step index
       REAL(wp), INTENT(in) ::   p2dt   ! time-step 
       !
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
+      INTEGER  ::   ji, jj, jk, jl     ! dummy loop indices
       REAL(wp) ::   zlavmr, zua, zva   ! local scalars
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  zwx, zwy, zwz, zww
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_zdf_exp')
+      IF( nn_timing == 1 )   CALL timing_start('dyn_zdf_exp')
       !
-      CALL wrk_alloc( jpi,jpj,jpk, zwx, zwy, zwz, zww ) 
+      CALL wrk_alloc( jpi,jpj,jpk,   zwx, zwy, zwz, zww ) 
       !
       IF( kt == nit000 .AND. lwp ) THEN
@@ -76,9 +78,10 @@
          WRITE(numout,*) '~~~~~~~~~~~ '
       ENDIF
-
+      !
+      !                 !==  vertical mixing trend  ==!
+      !
       zlavmr = 1. / REAL( nn_zdfexp )
-
-
-      DO jj = 2, jpjm1                 ! Surface boundary condition
+      !
+      DO jj = 2, jpjm1           ! Surface boundary condition
          DO ji = 2, jpim1
             zwy(ji,jj,1) = ( utau_b(ji,jj) + utau(ji,jj) ) * r1_rau0
@@ -86,5 +89,5 @@
          END DO  
       END DO  
-      DO jk = 1, jpk                   ! Initialization of x, z and contingently trends array
+      DO jk = 1, jpk             ! Initialization of x, z and contingently trends array
          DO jj = 2, jpjm1 
             DO ji = 2, jpim1
@@ -95,19 +98,19 @@
       END DO  
       !
-      DO jl = 1, nn_zdfexp             ! Time splitting loop
+      DO jl = 1, nn_zdfexp       ! Time splitting loop
          !
-         DO jk = 2, jpk                      ! First vertical derivative
+         DO jk = 2, jpk                ! First vertical derivative
             DO jj = 2, jpjm1 
                DO ji = 2, jpim1
-                  zwy(ji,jj,jk) = avmu(ji,jj,jk) * ( zwx(ji,jj,jk-1) - zwx(ji,jj,jk) ) / fse3uw(ji,jj,jk) 
-                  zww(ji,jj,jk) = avmv(ji,jj,jk) * ( zwz(ji,jj,jk-1) - zwz(ji,jj,jk) ) / fse3vw(ji,jj,jk)
+                  zwy(ji,jj,jk) = avmu(ji,jj,jk) * ( zwx(ji,jj,jk-1) - zwx(ji,jj,jk) ) / e3uw_n(ji,jj,jk) 
+                  zww(ji,jj,jk) = avmv(ji,jj,jk) * ( zwz(ji,jj,jk-1) - zwz(ji,jj,jk) ) / e3vw_n(ji,jj,jk)
                END DO  
             END DO  
          END DO  
-         DO jk = 1, jpkm1                    ! Second vertical derivative and trend estimation at kt+l*rdt/nn_zdfexp
+         DO jk = 1, jpkm1              ! Second vertical derivative and trend estimation at kt+l*rdt/nn_zdfexp
             DO jj = 2, jpjm1 
                DO ji = 2, jpim1
-                  zua = zlavmr * ( zwy(ji,jj,jk) - zwy(ji,jj,jk+1) ) / fse3u(ji,jj,jk)
-                  zva = zlavmr * ( zww(ji,jj,jk) - zww(ji,jj,jk+1) ) / fse3v(ji,jj,jk)
+                  zua = zlavmr * ( zwy(ji,jj,jk) - zwy(ji,jj,jk+1) ) / e3u_n(ji,jj,jk)
+                  zva = zlavmr * ( zww(ji,jj,jk) - zww(ji,jj,jk+1) ) / e3v_n(ji,jj,jk)
                   ua(ji,jj,jk) = ua(ji,jj,jk) + zua
                   va(ji,jj,jk) = va(ji,jj,jk) + zva
@@ -118,28 +121,26 @@
             END DO  
          END DO  
-         !
-      END DO                           ! End of time splitting
-
-      ! Time step momentum here to be compliant with what is done in the implicit case
+      END DO                     ! End of time splitting
       !
-      IF( ln_dynadv_vec .OR. .NOT. lk_vvl ) THEN      ! applied on velocity
+      !
+      !                 !==  Leap-Frog time integration  ==!
+      !
+      IF( ln_dynadv_vec .OR. ln_linssh ) THEN   ! applied on velocity
          DO jk = 1, jpkm1
             ua(:,:,jk) = ( ub(:,:,jk) + p2dt * ua(:,:,jk) ) * umask(:,:,jk)
             va(:,:,jk) = ( vb(:,:,jk) + p2dt * va(:,:,jk) ) * vmask(:,:,jk)
          END DO
-      ELSE                                            ! applied on thickness weighted velocity
+      ELSE                                      ! applied on thickness weighted velocity
          DO jk = 1, jpkm1
-            ua(:,:,jk) = (          ub(:,:,jk) * fse3u_b(:,:,jk)      &
-               &           + p2dt * ua(:,:,jk) * fse3u_n(:,:,jk)  )   &
-               &         / fse3u_a(:,:,jk) * umask(:,:,jk)
-            va(:,:,jk) = (          vb(:,:,jk) * fse3v_b(:,:,jk)      &
-               &           + p2dt * va(:,:,jk) * fse3v_n(:,:,jk)  )   &
-               &         / fse3v_a(:,:,jk) * vmask(:,:,jk)
+            ua(:,:,jk) = (          e3u_b(:,:,jk) * ub(:,:,jk)    &
+               &           + p2dt * e3u_n(:,:,jk) * ua(:,:,jk)  ) / e3u_a(:,:,jk) * umask(:,:,jk)
+            va(:,:,jk) = (          e3v_b(:,:,jk) * vb(:,:,jk)    &
+               &           + p2dt * e3v_n(:,:,jk) * va(:,:,jk)  ) / e3v_a(:,:,jk) * vmask(:,:,jk)
          END DO
       ENDIF
       !
-      CALL wrk_dealloc( jpi,jpj,jpk, zwx, zwy, zwz, zww ) 
+      CALL wrk_dealloc( jpi,jpj,jpk,   zwx, zwy, zwz, zww ) 
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_zdf_exp')
+      IF( nn_timing == 1 )   CALL timing_stop('dyn_zdf_exp')
       !
    END SUBROUTINE dyn_zdf_exp
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90	(revision 6140)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                    ***  MODULE  dynzdf_imp  ***
-   !! Ocean dynamics:  vertical component(s) of the momentum mixing trend
+   !! Ocean dynamics:  vertical component(s) of the momentum mixing trend, implicit scheme
    !!======================================================================
    !! History :  OPA  !  1990-10  (B. Blanke)  Original code
@@ -12,18 +12,20 @@
 
    !!----------------------------------------------------------------------
-   !!   dyn_zdf_imp  : update the momentum trend with the vertical diffusion using a implicit time-stepping
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE domvvl          ! variable volume
-   USE sbc_oce         ! surface boundary condition: ocean
-   USE zdf_oce         ! ocean vertical physics
-   USE phycst          ! physical constants
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! MPP library
-   USE zdfbfr          ! Bottom friction setup
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
-   USE dynadv, ONLY: ln_dynadv_vec ! Momentum advection form
+   !!   dyn_zdf_imp   : compute the vertical diffusion using a implicit scheme
+   !!                   together with the Leap-Frog time integration.
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE phycst         ! physical constants
+   USE dom_oce        ! ocean space and time domain
+   USE domvvl         ! variable volume
+   USE sbc_oce        ! surface boundary condition: ocean
+   USE dynadv   , ONLY: ln_dynadv_vec ! Momentum advection form
+   USE zdf_oce        ! ocean vertical physics
+   USE zdfbfr         ! Bottom friction setup
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -32,8 +34,7 @@
    PUBLIC   dyn_zdf_imp   ! called by step.F90
 
-   REAL(wp) ::  r_vvl     ! variable volume indicator, =1 if lk_vvl=T, =0 otherwise 
+   REAL(wp) ::  r_vvl     ! non-linear free surface indicator: =0 if ln_linssh=T, =1 otherwise 
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -49,24 +50,26 @@
       !!                   
       !! ** Purpose :   Compute the trend due to the vert. momentum diffusion
-      !!      and the surface forcing, and add it to the general trend of 
-      !!      the momentum equations.
+      !!              together with the Leap-Frog time stepping using an 
+      !!              implicit scheme.
       !!
-      !! ** Method  :   The vertical momentum mixing trend is given by :
-      !!             dz( avmu dz(u) ) = 1/e3u dk+1( avmu/e3uw dk(ua) )
-      !!      backward time stepping
-      !!      Surface boundary conditions: wind stress input (averaged over kt-1/2 & kt+1/2)
-      !!      Bottom boundary conditions : bottom stress (cf zdfbfr.F)
-      !!      Add this trend to the general trend ua :
-      !!         ua = ua + dz( avmu dz(u) )
+      !! ** Method  :  - Leap-Frog time stepping on all trends but the vertical mixing
+      !!         ua =         ub + 2*dt *       ua             vector form or linear free surf.
+      !!         ua = ( e3u_b*ub + 2*dt * e3u_n*ua ) / e3u_a   otherwise
+      !!               - update the after velocity with the implicit vertical mixing.
+      !!      This requires to solver the following system: 
+      !!         ua = ua + 1/e3u_a dk+1[ avmu / e3uw_a dk[ua] ]
+      !!      with the following surface/top/bottom boundary condition:
+      !!      surface: wind stress input (averaged over kt-1/2 & kt+1/2)
+      !!      top & bottom : top stress (iceshelf-ocean) & bottom stress (cf zdfbfr.F)
       !!
-      !! ** Action : - Update (ua,va) arrays with the after vertical diffusive mixing trend.
+      !! ** Action :   (ua,va) after velocity 
       !!---------------------------------------------------------------------
       INTEGER , INTENT(in) ::  kt     ! ocean time-step index
       REAL(wp), INTENT(in) ::  p2dt   ! vertical profile of tracer time-step
-      !!
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      INTEGER  ::   ikbu, ikbv   ! local integers
-      REAL(wp) ::   z1_p2dt, zcoef, zzwi, zzws, zrhs   ! local scalars
-      REAL(wp) ::   ze3ua, ze3va
+      !
+      INTEGER  ::   ji, jj, jk    ! dummy loop indices
+      INTEGER  ::   ikbu, ikbv    ! local integers
+      REAL(wp) ::   zzwi, ze3ua   ! local scalars
+      REAL(wp) ::   zzws, ze3va   !   -      -
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  zwi, zwd, zws
       !!----------------------------------------------------------------------
@@ -81,30 +84,27 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
          !
-         IF( lk_vvl ) THEN   ;    r_vvl = 1._wp       ! Variable volume indicator
-         ELSE                ;    r_vvl = 0._wp       
+         If( ln_linssh ) THEN   ;    r_vvl = 0._wp    ! non-linear free surface indicator
+         ELSE                   ;    r_vvl = 1._wp
          ENDIF
       ENDIF
-
-      ! 1. Time step dynamics
-      ! ---------------------
-
-      IF( ln_dynadv_vec .OR. .NOT. lk_vvl ) THEN      ! applied on velocity
+      !
+      !              !==  Time step dynamics  ==!
+      !
+      IF( ln_dynadv_vec .OR. ln_linssh ) THEN      ! applied on velocity
          DO jk = 1, jpkm1
             ua(:,:,jk) = ( ub(:,:,jk) + p2dt * ua(:,:,jk) ) * umask(:,:,jk)
             va(:,:,jk) = ( vb(:,:,jk) + p2dt * va(:,:,jk) ) * vmask(:,:,jk)
          END DO
-      ELSE                                            ! applied on thickness weighted velocity
+      ELSE                                         ! applied on thickness weighted velocity
          DO jk = 1, jpkm1
-            ua(:,:,jk) = (          ub(:,:,jk) * fse3u_b(:,:,jk)      &
-               &           + p2dt * ua(:,:,jk) * fse3u_n(:,:,jk)  )   &
-               &                               / fse3u_a(:,:,jk) * umask(:,:,jk)
-            va(:,:,jk) = (          vb(:,:,jk) * fse3v_b(:,:,jk)      &
-               &           + p2dt * va(:,:,jk) * fse3v_n(:,:,jk)  )   &
-               &                               / fse3v_a(:,:,jk) * vmask(:,:,jk)
-         END DO
-      ENDIF
-
-      ! 2. Apply semi-implicit bottom friction
-      ! --------------------------------------
+            ua(:,:,jk) = (         e3u_b(:,:,jk) * ub(:,:,jk)  &
+               &          + p2dt * e3u_n(:,:,jk) * ua(:,:,jk)  ) / e3u_a(:,:,jk) * umask(:,:,jk)
+            va(:,:,jk) = (         e3v_b(:,:,jk) * vb(:,:,jk)  &
+               &          + p2dt * e3v_n(:,:,jk) * va(:,:,jk)  ) / e3v_a(:,:,jk) * vmask(:,:,jk)
+         END DO
+      ENDIF
+      !
+      !              !==  Apply semi-implicit bottom friction  ==!
+      !
       ! Only needed for semi-implicit bottom friction setup. The explicit
       ! bottom friction has been included in "u(v)a" which act as the R.H.S
@@ -116,6 +116,6 @@
                ikbu = mbku(ji,jj)       ! ocean bottom level at u- and v-points 
                ikbv = mbkv(ji,jj)       ! (deepest ocean u- and v-points)
-               avmu(ji,jj,ikbu+1) = -bfrua(ji,jj) * fse3uw(ji,jj,ikbu+1)
-               avmv(ji,jj,ikbv+1) = -bfrva(ji,jj) * fse3vw(ji,jj,ikbv+1)
+               avmu(ji,jj,ikbu+1) = -bfrua(ji,jj) * e3uw_n(ji,jj,ikbu+1)
+               avmv(ji,jj,ikbv+1) = -bfrva(ji,jj) * e3vw_n(ji,jj,ikbv+1)
             END DO
          END DO
@@ -125,39 +125,38 @@
                   ikbu = miku(ji,jj)       ! ocean top level at u- and v-points 
                   ikbv = mikv(ji,jj)       ! (first wet ocean u- and v-points)
-                  IF (ikbu .GE. 2) avmu(ji,jj,ikbu) = -tfrua(ji,jj) * fse3uw(ji,jj,ikbu)
-                  IF (ikbv .GE. 2) avmv(ji,jj,ikbv) = -tfrva(ji,jj) * fse3vw(ji,jj,ikbv)
+                  IF( ikbu >= 2 )   avmu(ji,jj,ikbu) = -tfrua(ji,jj) * e3uw_n(ji,jj,ikbu)
+                  IF( ikbv >= 2 )   avmv(ji,jj,ikbv) = -tfrva(ji,jj) * e3vw_n(ji,jj,ikbv)
                END DO
             END DO
          END IF
       ENDIF
-
+      !
       ! With split-explicit free surface, barotropic stress is treated explicitly
       ! Update velocities at the bottom.
       ! J. Chanut: The bottom stress is computed considering after barotropic velocities, which does 
       !            not lead to the effective stress seen over the whole barotropic loop. 
-      IF ( ln_bfrimp .AND.ln_dynspg_ts ) THEN
-         ! remove barotropic velocities:
-         DO jk = 1, jpkm1
-            ua(:,:,jk) = (ua(:,:,jk) - ua_b(:,:)) * umask(:,:,jk)
-            va(:,:,jk) = (va(:,:,jk) - va_b(:,:)) * vmask(:,:,jk)
-         END DO
-         ! Add bottom/top stress due to barotropic component only:
-         DO jj = 2, jpjm1        
+      ! G. Madec : in linear free surface, e3u_a = e3u_n = e3u_0, so systematic use of e3u_a
+      IF( ln_bfrimp .AND. ln_dynspg_ts ) THEN
+         DO jk = 1, jpkm1        ! remove barotropic velocities
+            ua(:,:,jk) = ( ua(:,:,jk) - ua_b(:,:) ) * umask(:,:,jk)
+            va(:,:,jk) = ( va(:,:,jk) - va_b(:,:) ) * vmask(:,:,jk)
+         END DO
+         DO jj = 2, jpjm1        ! Add bottom/top stress due to barotropic component only
             DO ji = fs_2, fs_jpim1   ! vector opt.
                ikbu = mbku(ji,jj)         ! ocean bottom level at u- and v-points 
                ikbv = mbkv(ji,jj)         ! (deepest ocean u- and v-points)
-               ze3ua =  ( 1._wp - r_vvl ) * fse3u_n(ji,jj,ikbu) + r_vvl   * fse3u_a(ji,jj,ikbu)
-               ze3va =  ( 1._wp - r_vvl ) * fse3v_n(ji,jj,ikbv) + r_vvl   * fse3v_a(ji,jj,ikbv)
+               ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,ikbu) + r_vvl * e3u_a(ji,jj,ikbu)
+               ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,ikbv) + r_vvl * e3v_a(ji,jj,ikbv)
                ua(ji,jj,ikbu) = ua(ji,jj,ikbu) + p2dt * bfrua(ji,jj) * ua_b(ji,jj) / ze3ua
                va(ji,jj,ikbv) = va(ji,jj,ikbv) + p2dt * bfrva(ji,jj) * va_b(ji,jj) / ze3va
             END DO
          END DO
-         IF ( ln_isfcav ) THEN
+         IF( ln_isfcav ) THEN    ! Ocean cavities (ISF)
             DO jj = 2, jpjm1        
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   ikbu = miku(ji,jj)         ! top ocean level at u- and v-points 
                   ikbv = mikv(ji,jj)         ! (first wet ocean u- and v-points)
-                  ze3ua =  ( 1._wp - r_vvl ) * fse3u_n(ji,jj,ikbu) + r_vvl   * fse3u_a(ji,jj,ikbu)
-                  ze3va =  ( 1._wp - r_vvl ) * fse3v_n(ji,jj,ikbv) + r_vvl   * fse3v_a(ji,jj,ikbv)
+                  ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,ikbu) + r_vvl * e3u_a(ji,jj,ikbu)
+                  ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,ikbv) + r_vvl * e3v_a(ji,jj,ikbv)
                   ua(ji,jj,ikbu) = ua(ji,jj,ikbu) + p2dt * tfrua(ji,jj) * ua_b(ji,jj) / ze3ua
                   va(ji,jj,ikbv) = va(ji,jj,ikbv) + p2dt * tfrva(ji,jj) * va_b(ji,jj) / ze3va
@@ -166,7 +165,7 @@
          END IF
       ENDIF
-
-      ! 3. Vertical diffusion on u
-      ! ---------------------------
+      !
+      !              !==  Vertical diffusion on u  ==!
+      !
       ! Matrix and second member construction
       ! bottom boundary condition: both zwi and zws must be masked as avmu can take
@@ -176,10 +175,9 @@
          DO jj = 2, jpjm1 
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               ze3ua =  ( 1._wp - r_vvl ) * fse3u_n(ji,jj,jk) + r_vvl   * fse3u_a(ji,jj,jk)   ! after scale factor at T-point
-               zcoef = - p2dt / ze3ua      
-               zzwi          = zcoef * avmu  (ji,jj,jk  ) / fse3uw(ji,jj,jk  )
-               zwi(ji,jj,jk) = zzwi  * wumask(ji,jj,jk  )
-               zzws          = zcoef * avmu  (ji,jj,jk+1) / fse3uw(ji,jj,jk+1) 
-               zws(ji,jj,jk) = zzws  * wumask(ji,jj,jk+1)
+               ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,jk) + r_vvl * e3u_a(ji,jj,jk)   ! after scale factor at T-point
+               zzwi = - p2dt * avmu(ji,jj,jk  ) / ( ze3ua * e3uw_n(ji,jj,jk  ) )
+               zzws = - p2dt * avmu(ji,jj,jk+1) / ( ze3ua * e3uw_n(ji,jj,jk+1) )
+               zwi(ji,jj,jk) = zzwi * wumask(ji,jj,jk  )
+               zws(ji,jj,jk) = zzws * wumask(ji,jj,jk+1)
                zwd(ji,jj,jk) = 1._wp - zzwi - zzws
             END DO
@@ -216,7 +214,7 @@
       END DO
       !
-      DO jj = 2, jpjm1        !==  second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1  ==
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            ze3ua =  ( 1._wp - r_vvl ) * fse3u_n(ji,jj,1) + r_vvl   * fse3u_a(ji,jj,1) 
+      DO jj = 2, jpjm1        !==  second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1  ==!
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,1) + r_vvl * e3u_a(ji,jj,1) 
             ua(ji,jj,1) = ua(ji,jj,1) + p2dt * 0.5_wp * ( utau_b(ji,jj) + utau(ji,jj) )   &
                &                                      / ( ze3ua * rau0 ) * umask(ji,jj,1) 
@@ -226,11 +224,10 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1
-               zrhs = ua(ji,jj,jk)   ! zrhs=right hand side
-               ua(ji,jj,jk) = zrhs - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * ua(ji,jj,jk-1)
-            END DO
-         END DO
-      END DO
-      !
-      DO jj = 2, jpjm1        !==  thrid recurrence : SOLk = ( Lk - Uk * Ek+1 ) / Dk  ==
+               ua(ji,jj,jk) = ua(ji,jj,jk) - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * ua(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+      !
+      DO jj = 2, jpjm1        !==  thrid recurrence : SOLk = ( Lk - Uk * Ek+1 ) / Dk  ==!
          DO ji = fs_2, fs_jpim1   ! vector opt.
             ua(ji,jj,jpkm1) = ua(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
@@ -244,7 +241,7 @@
          END DO
       END DO
-
-      ! 4. Vertical diffusion on v
-      ! ---------------------------
+      !
+      !              !==  Vertical diffusion on v  ==!
+      !
       ! Matrix and second member construction
       ! bottom boundary condition: both zwi and zws must be masked as avmv can take
@@ -254,10 +251,9 @@
          DO jj = 2, jpjm1   
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               ze3va =  ( 1._wp - r_vvl ) * fse3v_n(ji,jj,jk)  + r_vvl * fse3v_a(ji,jj,jk)   ! after scale factor at T-point
-               zcoef = - p2dt / ze3va
-               zzwi          = zcoef * avmv (ji,jj,jk  ) / fse3vw(ji,jj,jk  )
-               zwi(ji,jj,jk) =  zzwi * wvmask(ji,jj,jk)
-               zzws          = zcoef * avmv (ji,jj,jk+1) / fse3vw(ji,jj,jk+1)
-               zws(ji,jj,jk) =  zzws * wvmask(ji,jj,jk+1)
+               ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,jk) + r_vvl * e3v_a(ji,jj,jk)   ! after scale factor at T-point
+               zzwi = - p2dt * avmv (ji,jj,jk  ) / ( ze3va * e3vw_n(ji,jj,jk  ) )
+               zzws = - p2dt * avmv (ji,jj,jk+1) / ( ze3va * e3vw_n(ji,jj,jk+1) )
+               zwi(ji,jj,jk) = zzwi * wvmask(ji,jj,jk  )
+               zws(ji,jj,jk) = zzws * wvmask(ji,jj,jk+1)
                zwd(ji,jj,jk) = 1._wp - zzwi - zzws
             END DO
@@ -294,7 +290,7 @@
       END DO
       !
-      DO jj = 2, jpjm1        !==  second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1  ==
+      DO jj = 2, jpjm1        !==  second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1  ==!
          DO ji = fs_2, fs_jpim1   ! vector opt.          
-            ze3va =  ( 1._wp - r_vvl ) * fse3v_n(ji,jj,1) + r_vvl   * fse3v_a(ji,jj,1) 
+            ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,1) + r_vvl * e3v_a(ji,jj,1) 
             va(ji,jj,1) = va(ji,jj,1) + p2dt * 0.5_wp * ( vtau_b(ji,jj) + vtau(ji,jj) )   &
                &                                      / ( ze3va * rau0 ) 
@@ -304,11 +300,10 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zrhs = va(ji,jj,jk)   ! zrhs=right hand side
-               va(ji,jj,jk) = zrhs - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * va(ji,jj,jk-1)
-            END DO
-         END DO
-      END DO
-      !
-      DO jj = 2, jpjm1        !==  third recurrence : SOLk = ( Lk - Uk * SOLk+1 ) / Dk  ==
+               va(ji,jj,jk) = va(ji,jj,jk) - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * va(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+      !
+      DO jj = 2, jpjm1        !==  third recurrence : SOLk = ( Lk - Uk * SOLk+1 ) / Dk  ==!
          DO ji = fs_2, fs_jpim1   ! vector opt.
             va(ji,jj,jpkm1) = va(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
@@ -322,7 +317,8 @@
          END DO
       END DO
-
+      
       ! J. Chanut: Lines below are useless ?
-      !! restore avmu(v)=0. at bottom (and top if ln_isfcav=T interfaces)
+      !! restore bottom layer avmu(v) 
+      !!gm  I almost sure it is !!!!
       IF( ln_bfrimp ) THEN
         DO jj = 2, jpjm1
@@ -330,6 +326,6 @@
               ikbu = mbku(ji,jj)         ! ocean bottom level at u- and v-points 
               ikbv = mbkv(ji,jj)         ! (deepest ocean u- and v-points)
-              avmu(ji,jj,ikbu+1) = 0.e0
-              avmv(ji,jj,ikbv+1) = 0.e0
+              avmu(ji,jj,ikbu+1) = 0._wp
+              avmv(ji,jj,ikbv+1) = 0._wp
            END DO
         END DO
@@ -339,14 +335,14 @@
                  ikbu = miku(ji,jj)         ! ocean top level at u- and v-points 
                  ikbv = mikv(ji,jj)         ! (first wet ocean u- and v-points)
-                 IF (ikbu > 1) avmu(ji,jj,ikbu) = 0.e0
-                 IF (ikbv > 1) avmv(ji,jj,ikbv) = 0.e0
+                 IF( ikbu > 1 )   avmu(ji,jj,ikbu) = 0._wp
+                 IF( ikbv > 1 )   avmv(ji,jj,ikbv) = 0._wp
               END DO
            END DO
-        END IF
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi,jpj,jpk, zwi, zwd, zws) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_zdf_imp')
+        ENDIF
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi,jpj,jpk,   zwi, zwd, zws) 
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('dyn_zdf_imp')
       !
    END SUBROUTINE dyn_zdf_imp
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90	(revision 6140)
@@ -12,30 +12,31 @@
 
    !!----------------------------------------------------------------------
-   !!   ssh_nxt        : after ssh
-   !!   ssh_swp        : filter ans swap the ssh arrays
-   !!   wzv            : compute now vertical velocity
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables 
-   USE sbc_oce         ! surface boundary condition: ocean
-   USE domvvl          ! Variable volume
-   USE divhor          ! horizontal divergence
-   USE phycst          ! physical constants
-   USE bdy_oce
-   USE bdy_par         
-   USE bdydyn2d        ! bdy_ssh routine
+   !!   ssh_nxt       : after ssh
+   !!   ssh_swp       : filter ans swap the ssh arrays
+   !!   wzv           : compute now vertical velocity
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables 
+   USE sbc_oce        ! surface boundary condition: ocean
+   USE domvvl         ! Variable volume
+   USE divhor         ! horizontal divergence
+   USE phycst         ! physical constants
+   USE bdy_oce        ! 
+   USE bdy_par        !
+   USE bdydyn2d       ! bdy_ssh routine
 #if defined key_agrif
    USE agrif_opa_interp
 #endif
 #if defined key_asminc   
-   USE asminc          ! Assimilation increment
-#endif
-   USE in_out_manager  ! I/O manager
-   USE restart         ! only for lrst_oce
-   USE prtctl          ! Print control
-   USE lbclnk          ! ocean lateral boundary condition (or mpp link)
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE   asminc       ! Assimilation increment
+#endif
+   !
+   USE in_out_manager ! I/O manager
+   USE restart        ! only for lrst_oce
+   USE prtctl         ! Print control
+   USE lbclnk         ! ocean lateral boundary condition (or mpp link)
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -47,5 +48,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -97,5 +97,5 @@
       zhdiv(:,:) = 0._wp
       DO jk = 1, jpkm1                                 ! Horizontal divergence of barotropic transports
-        zhdiv(:,:) = zhdiv(:,:) + fse3t_n(:,:,jk) * hdivn(:,:,jk)
+        zhdiv(:,:) = zhdiv(:,:) + e3t_n(:,:,jk) * hdivn(:,:,jk)
       END DO
       !                                                ! Sea surface elevation time stepping
@@ -194,6 +194,6 @@
          DO jk = jpkm1, 1, -1                       ! integrate from the bottom the hor. divergence
             ! computation of w
-            wn(:,:,jk) = wn(:,:,jk+1) - (   fse3t_n(:,:,jk) * hdivn(:,:,jk) + zhdiv(:,:,jk)                    &
-               &                          + z1_2dt * ( fse3t_a(:,:,jk) - fse3t_b(:,:,jk) ) ) * tmask(:,:,jk)
+            wn(:,:,jk) = wn(:,:,jk+1) - (  e3t_n(:,:,jk) * hdivn(:,:,jk) + zhdiv(:,:,jk)    &
+               &                         + z1_2dt * ( e3t_a(:,:,jk) - e3t_b(:,:,jk) )     ) * tmask(:,:,jk)
          END DO
          !          IF( ln_vvl_layer ) wn(:,:,:) = 0.e0
@@ -202,6 +202,6 @@
          DO jk = jpkm1, 1, -1                       ! integrate from the bottom the hor. divergence
             ! computation of w
-            wn(:,:,jk) = wn(:,:,jk+1) - (   fse3t_n(:,:,jk) * hdivn(:,:,jk)                                   &
-               &                          + z1_2dt * ( fse3t_a(:,:,jk) - fse3t_b(:,:,jk) ) ) * tmask(:,:,jk)
+            wn(:,:,jk) = wn(:,:,jk+1) - (  e3t_n(:,:,jk) * hdivn(:,:,jk)                 &
+               &                         + z1_2dt * ( e3t_a(:,:,jk) - e3t_b(:,:,jk) )  ) * tmask(:,:,jk)
          END DO
       ENDIF
@@ -240,4 +240,6 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      REAL(wp) ::   zcoef   ! local scalar
       !!----------------------------------------------------------------------
       !
@@ -249,21 +251,25 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~ '
       ENDIF
-
-      IF( ( neuler == 0 .AND. kt == nit000 ) .OR. ( ln_bt_fw .AND. ln_dynspg_ts ) ) THEN 
-                                                   !** Euler time-stepping: no filter
-         sshb(:,:) = sshn(:,:)                           ! before <-- now
-         sshn(:,:) = ssha(:,:)                           ! now    <-- after  (before already = now)
+      !              !==  Euler time-stepping: no filter, just swap  ==!
+      IF(  ( neuler == 0 .AND. kt == nit000 ) .OR.    &
+         & ( ln_bt_fw    .AND. ln_dynspg_ts )      ) THEN 
+         sshb(:,:) = sshn(:,:)                              ! before <-- now
+         sshn(:,:) = ssha(:,:)                              ! now    <-- after  (before already = now)
          !
-      ELSE                                         !** Leap-Frog time-stepping: Asselin filter + swap
-         sshb(:,:) = sshn(:,:) + atfp * ( sshb(:,:) - 2 * sshn(:,:) + ssha(:,:) )     ! before <-- now filtered
-         IF( lk_vvl ) sshb(:,:) = sshb(:,:) - atfp * rdt / rau0 * ( emp_b(:,:)    - emp(:,:)    &
-                                &                                 - rnf_b(:,:)    + rnf(:,:)    &
-                                &                                 + fwfisf_b(:,:) - fwfisf(:,:) ) * ssmask(:,:)
-         sshn(:,:) = ssha(:,:)                           ! now <-- after
+      ELSE           !==  Leap-Frog time-stepping: Asselin filter + swap  ==!
+         !                                                  ! before <-- now filtered
+         sshb(:,:) = sshn(:,:) + atfp * ( sshb(:,:) - 2 * sshn(:,:) + ssha(:,:) )
+         IF( .NOT.ln_linssh ) THEN                          ! before <-- with forcing removed
+            zcoef = atfp * rdt * r1_rau0
+            sshb(:,:) = sshb(:,:) - zcoef * (     emp_b(:,:) - emp   (:,:)   &
+               &                             -    rnf_b(:,:) + rnf   (:,:)   &
+               &                             + fwfisf_b(:,:) - fwfisf(:,:)   ) * ssmask(:,:)
+         ENDIF
+         sshn(:,:) = ssha(:,:)                              ! now <-- after
       ENDIF
       !
       IF(ln_ctl)   CALL prt_ctl( tab2d_1=sshb, clinfo1=' sshb  - : ', mask1=tmask, ovlap=1 )
       !
-      IF( nn_timing == 1 )  CALL timing_stop('ssh_swp')
+      IF( nn_timing == 1 )   CALL timing_stop('ssh_swp')
       !
    END SUBROUTINE ssh_swp
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/flo4rk.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/flo4rk.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/flo4rk.F90	(revision 6140)
@@ -29,6 +29,4 @@
    REAL(wp), DIMENSION (3) ::   scoef1 = (/  0.5  ,  0.5  ,  1.0  /)           !
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -436,5 +434,5 @@
                      &   ( tcoef1(ki) * wb(iidw(jfl,jind1),ijdw(jfl,jind2),ikdw(jfl,jind3))+   &
                      &     tcoef2(ki) * wn(iidw(jfl,jind1),ijdw(jfl,jind2),ikdw(jfl,jind3)) )  &
-                     &   / fse3w(iidw(jfl,jind1),ijdw(jfl,jind2),ikdw(jfl,jind3))
+                     &   / e3w_n(iidw(jfl,jind1),ijdw(jfl,jind2),ikdw(jfl,jind3))
                END DO
             END DO
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/floblk.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/floblk.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/floblk.F90	(revision 6140)
@@ -23,6 +23,4 @@
    PUBLIC   flo_blk    ! routine called by floats.F90
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -118,13 +116,13 @@
             
             ! compute the transport across the mesh where the float is.            
-!!bug (gm) change e3t into fse3. but never checked 
-            zsurfx(1) = e2u(iiloc(jfl)-1,ijloc(jfl)  ) * fse3u(iiloc(jfl)-1,ijloc(jfl)  ,-ikl(jfl))
-            zsurfx(2) = e2u(iiloc(jfl)  ,ijloc(jfl)  ) * fse3u(iiloc(jfl)  ,ijloc(jfl)  ,-ikl(jfl))
-            zsurfy(1) = e1v(iiloc(jfl)  ,ijloc(jfl)-1) * fse3v(iiloc(jfl)  ,ijloc(jfl)-1,-ikl(jfl))
-            zsurfy(2) = e1v(iiloc(jfl)  ,ijloc(jfl)  ) * fse3v(iiloc(jfl)  ,ijloc(jfl)  ,-ikl(jfl))
+!!bug (gm) change e3t into e3. but never checked 
+            zsurfx(1) = e2u(iiloc(jfl)-1,ijloc(jfl)  ) * e3u_n(iiloc(jfl)-1,ijloc(jfl)  ,-ikl(jfl))
+            zsurfx(2) = e2u(iiloc(jfl)  ,ijloc(jfl)  ) * e3u_n(iiloc(jfl)  ,ijloc(jfl)  ,-ikl(jfl))
+            zsurfy(1) = e1v(iiloc(jfl)  ,ijloc(jfl)-1) * e3v_n(iiloc(jfl)  ,ijloc(jfl)-1,-ikl(jfl))
+            zsurfy(2) = e1v(iiloc(jfl)  ,ijloc(jfl)  ) * e3v_n(iiloc(jfl)  ,ijloc(jfl)  ,-ikl(jfl))
 
             ! for a isobar float zsurfz is put to zero. The vertical velocity will be zero too.
             zsurfz =          e1e2t(iiloc(jfl),ijloc(jfl))
-            zvol   = zsurfz * fse3t(iiloc(jfl),ijloc(jfl),-ikl(jfl))
+            zvol   = zsurfz * e3t_n(iiloc(jfl),ijloc(jfl),-ikl(jfl))
 
             !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/flodom.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/flodom.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/flodom.F90	(revision 6140)
@@ -37,6 +37,4 @@
    REAL(wp), ALLOCATABLE, DIMENSION(:) ::   zgifl, zgjfl,  zgkfl      ! distances in indexes
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -176,5 +174,5 @@
                   ihtest(jfl) = ihtest(jfl)+1
                   DO jk = 1, jpk-1
-                     IF( (fsdepw(ji,jj,jk) <= flzz(jfl)) .AND. (fsdepw(ji,jj,jk+1) > flzz(jfl)) ) THEN
+                     IF( (gdepw_n(ji,jj,jk) <= flzz(jfl)) .AND. (gdepw_n(ji,jj,jk+1) > flzz(jfl)) ) THEN
                         ikmfl(jfl) = jk
                         ivtest(jfl) = ivtest(jfl) + 1
@@ -238,10 +236,10 @@
             zgifl(jfl)= (iimfl(jfl)-0.5) + zdxab/e1u(iimfl(jfl)-1,ijmfl(jfl)) + (mig(1)-jpizoom)
             zgjfl(jfl)= (ijmfl(jfl)-0.5) + zdyad/e2v(iimfl(jfl),ijmfl(jfl)-1) + (mjg(1)-jpjzoom)
-            zgkfl(jfl) = (( fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1) - flzz(jfl) )* ikmfl(jfl))   &
-               &                 / (  fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1)                              &
-               &                    - fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl) ) )                             &
-               &                 + (( flzz(jfl)-fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)) ) *(ikmfl(jfl)+1))   &
-               &                 / (  fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1)                              &
-               &                    - fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)) )
+            zgkfl(jfl) = (( gdepw_n(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1) - flzz(jfl) )* ikmfl(jfl))   &
+               &                 / (  gdepw_n(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1)                              &
+               &                    - gdepw_n(iimfl(jfl),ijmfl(jfl),ikmfl(jfl) ) )                             &
+               &                 + (( flzz(jfl)-gdepw_n(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)) ) *(ikmfl(jfl)+1))   &
+               &                 / (  gdepw_n(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1)                              &
+               &                    - gdepw_n(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)) )
          ELSE
             zgifl(jfl) = 0.e0
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/florst.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/florst.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/florst.F90	(revision 6140)
@@ -26,6 +26,4 @@
    INTEGER, ALLOCATABLE, DIMENSION(:) :: iperproc   ! 1D workspace
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.2 , LODYC-IPSL  (2009)
@@ -52,13 +50,10 @@
       !! ** Purpose :  
       !!             
-      !!    
       !!      
       !! ** Method  :   The frequency of  ??? is nwritefl
       !!      
       !!----------------------------------------------------------------------
-      !! * Arguments
       INTEGER  :: kt                            ! time step
-
-      !! * Local declarations
+      !
       CHARACTER (len=80)       :: clname             ! restart filename
       INTEGER                  :: ic , jc , jpn ,jfl ! temporary integer
@@ -125,9 +120,8 @@
             ENDIF
          ENDIF
-
+         !
       ENDIF
-
+      !
    END SUBROUTINE flo_rst
-
 
 #  else
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/flowri.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/flowri.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/FLO/flowri.F90	(revision 6140)
@@ -40,6 +40,4 @@
    REAL(wp), ALLOCATABLE, DIMENSION(:) ::   ztem , zsal, zrho   ! 2D workspace
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.2 , LODYC-IPSL  (2009)
@@ -125,5 +123,5 @@
                zlon(jfl) = (1.-zafl)*(1.-zbfl)*glamt(iafloc ,ibfloc ) + (1.-zafl) * zbfl * glamt(iafloc ,ib1floc)   &
                      +     zafl *(1.-zbfl)*glamt(ia1floc,ibfloc ) +     zafl  * zbfl * glamt(ia1floc,ib1floc)
-               zdep(jfl) = (1.-zcfl)*fsdepw(iafloc,ibfloc,icfl ) + zcfl * fsdepw(iafloc,ibfloc,ic1fl)     
+               zdep(jfl) = (1.-zcfl)*gdepw_n(iafloc,ibfloc,icfl ) + zcfl * gdepw_n(iafloc,ibfloc,ic1fl)     
 
                !save temperature, salinity and density at this position
@@ -146,5 +144,5 @@
             zlon(jfl) = (1.-zafl)*(1.-zbfl)*glamt(iafloc ,ibfloc ) + (1.-zafl) * zbfl * glamt(iafloc ,ib1floc)   &
                       +     zafl *(1.-zbfl)*glamt(ia1floc,ibfloc ) +     zafl  * zbfl * glamt(ia1floc,ib1floc)
-            zdep(jfl) = (1.-zcfl)*fsdepw(iafloc,ibfloc,icfl ) + zcfl * fsdepw(iafloc,ibfloc,ic1fl)
+            zdep(jfl) = (1.-zcfl)*gdepw_n(iafloc,ibfloc,icfl ) + zcfl * gdepw_n(iafloc,ibfloc,ic1fl)
 
             ztem(jfl) = tsn(iafloc,ibfloc,icfl,jp_tem)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/ICB/icb_oce.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/ICB/icb_oce.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/ICB/icb_oce.F90	(revision 6140)
@@ -43,5 +43,5 @@
    PUBLIC   icb_alloc   ! routine called by icb_init in icbini.F90 module
 
-INTEGER, PUBLIC, PARAMETER ::   nclasses = 10   !: Number of icebergs classes   
+   INTEGER, PUBLIC, PARAMETER ::   nclasses = 10   !: Number of icebergs classes   
    INTEGER, PUBLIC, PARAMETER ::   nkounts  =  3   !: Number of integers combined for unique naming
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/ICB/icbrst.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/ICB/icbrst.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/ICB/icbrst.F90	(revision 6140)
@@ -12,4 +12,6 @@
    !!            -    !                            Currently needs a fixed processor
    !!            -    !                            layout between restarts
+   !!            -    !  2015-11  Dave Storkey     Convert icb_rst_read to use IOM so can
+   !!                                              read single restart files
    !!----------------------------------------------------------------------
    !!----------------------------------------------------------------------
@@ -22,4 +24,5 @@
    USE lib_mpp        ! NEMO MPI library, lk_mpp in particular
    USE netcdf         ! netcdf routines for IO
+   USE iom
    USE icb_oce        ! define iceberg arrays
    USE icbutl         ! iceberg utility routines
@@ -57,10 +60,6 @@
       INTEGER                      ::   idim, ivar, iatt
       INTEGER                      ::   jn, iunlim_dim, ibergs_in_file
-      INTEGER                      ::   iclass
-      INTEGER, DIMENSION(1)        ::   istrt, ilngth, idata
-      INTEGER, DIMENSION(2)        ::   istrt2, ilngth2
-      INTEGER, DIMENSION(nkounts)  ::   idata2
-      REAL(wp), DIMENSION(1)       ::   zdata                                         ! need 1d array to read in with
-                                                                                            ! start and count arrays
+      INTEGER                      ::   ii,ij,iclass
+      REAL(wp), DIMENSION(nkounts) ::   zdata      
       LOGICAL                      ::   ll_found_restart
       CHARACTER(len=256)           ::   cl_path
@@ -71,138 +70,62 @@
       !!----------------------------------------------------------------------
 
-      ! Find a restart file. Assume iceberg restarts in same directory as ocean restarts. 
+      ! Find a restart file. Assume iceberg restarts in same directory as ocean restarts
+      ! and are called TRIM(cn_ocerst)//'_icebergs'
       cl_path = TRIM(cn_ocerst_indir)
       IF( cl_path(LEN_TRIM(cl_path):) /= '/' ) cl_path = TRIM(cl_path) // '/'
-      cl_filename = ' '
-      IF ( lk_mpp ) THEN
-         cl_filename = ' '
-         WRITE( cl_filename, '("restart_icebergs_",I4.4,".nc")' ) narea-1
-         INQUIRE( file=TRIM(cl_path)//TRIM(cl_filename), exist=ll_found_restart )
-      ELSE
-         cl_filename = 'restart_icebergs.nc'
-         INQUIRE( file=TRIM(cl_path)//TRIM(cl_filename), exist=ll_found_restart )
-      ENDIF
-
-      IF ( .NOT. ll_found_restart) THEN                     ! only do the following if a file was found
-         CALL ctl_stop('icebergs: no restart file found')
-      ENDIF
-
-      IF (nn_verbose_level >= 0 .AND. lwp)  &
-         WRITE(numout,'(2a)') 'icebergs, read_restart_bergs: found restart file = ',TRIM(cl_path)//TRIM(cl_filename)
-
-      nret = NF90_OPEN(TRIM(cl_path)//TRIM(cl_filename), NF90_NOWRITE, ncid)
-      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, read_restart_bergs: nf_open failed')
-
-      nret = nf90_inquire(ncid, idim, ivar, iatt, iunlim_dim)
-      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, read_restart_bergs: nf_inquire failed')
-
-      IF( iunlim_dim .NE. -1) THEN
-
-         nret = nf90_inquire_dimension(ncid, iunlim_dim, cl_dname, ibergs_in_file)
-         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, read_restart_bergs: nf_inq_dimlen failed')
-
-         nret = NF90_INQ_VARID(ncid, 'number', numberid)
-         nret = NF90_INQ_VARID(ncid, 'mass_scaling', nscaling_id)
-         nret = NF90_INQ_VARID(ncid, 'xi', nxid)
-         nret = NF90_INQ_VARID(ncid, 'yj', nyid)
-         nret = NF90_INQ_VARID(ncid, 'lon', nlonid)
-         nret = NF90_INQ_VARID(ncid, 'lat', nlatid)
-         nret = NF90_INQ_VARID(ncid, 'uvel', nuvelid)
-         nret = NF90_INQ_VARID(ncid, 'vvel', nvvelid)
-         nret = NF90_INQ_VARID(ncid, 'mass', nmassid)
-         nret = NF90_INQ_VARID(ncid, 'thickness', nthicknessid)
-         nret = NF90_INQ_VARID(ncid, 'width', nwidthid)
-         nret = NF90_INQ_VARID(ncid, 'length', nlengthid)
-         nret = NF90_INQ_VARID(ncid, 'year', nyearid)
-         nret = NF90_INQ_VARID(ncid, 'day', ndayid)
-         nret = NF90_INQ_VARID(ncid, 'mass_of_bits', nmass_of_bits_id)
-         nret = NF90_INQ_VARID(ncid, 'heat_density', nheat_density_id)
-
-         ilngth(1) = 1
-         istrt2(1) = 1
-         ilngth2(1) = nkounts
-         ilngth2(2) = 1
-         DO jn=1, ibergs_in_file
-
-            istrt(1) = jn
-            istrt2(2) = jn
-
-            nret = NF90_GET_VAR(ncid, numberid, idata2, istrt2, ilngth2 )
-            localberg%number(:) = idata2(:)
-
-            nret = NF90_GET_VAR(ncid, nscaling_id, zdata, istrt, ilngth )
-            localberg%mass_scaling = zdata(1)
-
-            nret = NF90_GET_VAR(ncid, nlonid, zdata, istrt, ilngth)
-            localpt%lon = zdata(1)
-            nret = NF90_GET_VAR(ncid, nlatid, zdata, istrt, ilngth)
-            localpt%lat = zdata(1)
-            IF (nn_verbose_level >= 2 .AND. lwp) THEN
-               WRITE(numout,'(a,i5,a,2f10.4,a,i5)') 'icebergs, read_restart_bergs: berg ',jn,' is at ', &
-                                              localpt%lon,localpt%lat,' on PE ',narea-1
+      cl_filename = TRIM(cn_ocerst_in)//'_icebergs'
+      CALL iom_open( TRIM(cl_path)//cl_filename, ncid )
+
+      IF( iom_file(ncid)%iduld .GE. 0) THEN
+
+         ibergs_in_file = iom_file(ncid)%lenuld
+         DO jn = 1,ibergs_in_file
+
+            ! iom_get treats the unlimited dimension as time. Here the unlimited dimension 
+            ! is the iceberg index, but we can still use the ktime keyword to get the iceberg we want. 
+
+            CALL iom_get( ncid, 'xi'     ,localpt%xi  , ktime=jn )
+            CALL iom_get( ncid, 'yj'     ,localpt%yj  , ktime=jn )
+
+            ii = INT( localpt%xi + 0.5 )
+            ij = INT( localpt%yj + 0.5 )
+            ! Only proceed if this iceberg is on the local processor (excluding halos).
+            IF ( ii .GE. nldi+nimpp-1 .AND. ii .LE. nlei+nimpp-1 .AND. &
+           &     ij .GE. nldj+njmpp-1 .AND. ij .LE. nlej+njmpp-1 ) THEN           
+
+               CALL iom_get( ncid, jpdom_unknown, 'number'       , zdata(:) , ktime=jn, kstart=(/1/), kcount=(/nkounts/) )
+               localberg%number(:) = INT(zdata(:))
+               CALL iom_get( ncid, 'mass_scaling' , localberg%mass_scaling, ktime=jn )
+               CALL iom_get( ncid, 'lon'          , localpt%lon           , ktime=jn )
+               CALL iom_get( ncid, 'lat'          , localpt%lat           , ktime=jn )
+               CALL iom_get( ncid, 'uvel'         , localpt%uvel          , ktime=jn )
+               CALL iom_get( ncid, 'vvel'         , localpt%vvel          , ktime=jn )
+               CALL iom_get( ncid, 'mass'         , localpt%mass          , ktime=jn )
+               CALL iom_get( ncid, 'thickness'    , localpt%thickness     , ktime=jn )
+               CALL iom_get( ncid, 'width'        , localpt%width         , ktime=jn )
+               CALL iom_get( ncid, 'length'       , localpt%length        , ktime=jn )
+               CALL iom_get( ncid, 'year'         , zdata(1)              , ktime=jn )
+               localpt%year = INT(zdata(1))
+               CALL iom_get( ncid, 'day'          , localpt%day           , ktime=jn )
+               CALL iom_get( ncid, 'mass_of_bits' , localpt%mass_of_bits  , ktime=jn )
+               CALL iom_get( ncid, 'heat_density' , localpt%heat_density  , ktime=jn )
+
+               !
+               CALL icb_utl_add( localberg, localpt )
+
             ENDIF
-            nret = NF90_GET_VAR(ncid, nxid, zdata, istrt, ilngth)
-            localpt%xi = zdata(1)
-            nret = NF90_GET_VAR(ncid, nyid, zdata, istrt, ilngth)
-            localpt%yj = zdata(1)
-            nret = NF90_GET_VAR(ncid, nuvelid, zdata, istrt, ilngth )
-            localpt%uvel = zdata(1)
-            nret = NF90_GET_VAR(ncid, nvvelid, zdata, istrt, ilngth )
-            localpt%vvel = zdata(1)
-            nret = NF90_GET_VAR(ncid, nmassid, zdata, istrt, ilngth )
-            localpt%mass = zdata(1)
-            nret = NF90_GET_VAR(ncid, nthicknessid, zdata, istrt, ilngth )
-            localpt%thickness = zdata(1)
-            nret = NF90_GET_VAR(ncid, nwidthid, zdata, istrt, ilngth )
-            localpt%width = zdata(1)
-            nret = NF90_GET_VAR(ncid, nlengthid, zdata, istrt, ilngth )
-            localpt%length = zdata(1)
-            nret = NF90_GET_VAR(ncid, nyearid, idata, istrt, ilngth )
-            localpt%year = idata(1)
-            nret = NF90_GET_VAR(ncid, ndayid, zdata, istrt, ilngth )
-            localpt%day = zdata(1)
-            nret = NF90_GET_VAR(ncid, nmass_of_bits_id, zdata, istrt, ilngth )
-            localpt%mass_of_bits = zdata(1)
-            nret = NF90_GET_VAR(ncid, nheat_density_id, zdata, istrt, ilngth )
-            localpt%heat_density = zdata(1)
-            !
-            CALL icb_utl_add( localberg, localpt )
+
          END DO
-         !
-      ENDIF
-
-      nret = NF90_INQ_DIMID( ncid, 'c', nc_dim )
-      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, read_restart: nf_inq_dimid c failed')
-
-      nret = NF90_INQUIRE_DIMENSION( ncid, nc_dim, cl_dname, iclass )
-      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, read_restart: nf_inquire_dimension failed')
-
-      nret = NF90_INQ_VARID(ncid, 'kount'       , nkountid)
-      nret = NF90_INQ_VARID(ncid, 'calving'     , ncalvid)
-      nret = NF90_INQ_VARID(ncid, 'calving_hflx', ncalvhid)
-      nret = NF90_INQ_VARID(ncid, 'stored_ice'  , nsiceid)
-      nret = NF90_INQ_VARID(ncid, 'stored_heat' , nsheatid)
-
-      nstrt3(1) = 1
-      nstrt3(2) = 1
-      nlngth3(1) = jpi
-      nlngth3(2) = jpj
-      nlngth3(3) = 1
-
-      DO jn = 1, iclass
-         nstrt3(3) = jn
-         nret      = NF90_GET_VAR( ncid, nsiceid , griddata, nstrt3, nlngth3 )
-         berg_grid%stored_ice(:,:,jn) = griddata(:,:,1)
-      END DO
-
-      nret = NF90_GET_VAR( ncid, ncalvid , src_calving          (:,:) )
-      nret = NF90_GET_VAR( ncid, ncalvhid, src_calving_hflx     (:,:) )
-      nret = NF90_GET_VAR( ncid, nsheatid, berg_grid%stored_heat(:,:) )
-      nret = NF90_GET_VAR( ncid, nkountid, idata2(:) )
-      num_bergs(:) = idata2(:)
-
-      ! Finish up
-      nret = NF90_CLOSE(ncid)
-      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, read_restart: nf_close failed')
+
+      ENDIF 
+
+      ! Gridded variables
+      CALL iom_get( ncid, jpdom_autoglo,    'calving'     , src_calving  )
+      CALL iom_get( ncid, jpdom_autoglo,    'calving_hflx', src_calving_hflx  )
+      CALL iom_get( ncid, jpdom_autoglo,    'stored_heat' , berg_grid%stored_heat  )
+      CALL iom_get( ncid, jpdom_autoglo_xy, 'stored_ice'  , berg_grid%stored_ice, kstart=(/1,1,1/), kcount=(/1,1,nclasses/) )
+      
+      CALL iom_get( ncid, jpdom_unknown, 'kount' , zdata(:) )
+      num_bergs(:) = INT(zdata(:))
 
       ! Sanity check
@@ -211,9 +134,13 @@
          WRITE(numout,'(2(a,i5))') 'icebergs, read_restart_bergs: # bergs =',jn,' on PE',narea-1
       IF( lk_mpp ) THEN
-         CALL mpp_sum(ibergs_in_file)
+         ! Only mpp_sum ibergs_in_file if we are reading from multiple restart files. 
+         IF( INDEX(iom_file(ncid)%name,'icebergs.nc' ) .EQ. 0 ) CALL mpp_sum(ibergs_in_file)
          CALL mpp_sum(jn)
       ENDIF
       IF(lwp)   WRITE(numout,'(a,i5,a,i5,a)') 'icebergs, read_restart_bergs: there were',ibergs_in_file,   &
          &                                    ' bergs in the restart file and', jn,' bergs have been read'
+      !
+      ! Finish up
+      CALL iom_close( ncid )
       !
       IF( lwp .and. nn_verbose_level >= 0)  WRITE(numout,'(a)') 'icebergs, read_restart_bergs: completed'
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 6140)
@@ -13,5 +13,4 @@
    !!----------------------------------------------------------------------
    USE par_oce       ! ocean parameter
-   USE lib_print     ! formated print library
    USE nc4interface  ! NetCDF4 interface
 
@@ -37,4 +36,5 @@
    INTEGER       ::   nn_itend         !: index of the last time step
    INTEGER       ::   nn_date0         !: initial calendar date aammjj
+   INTEGER       ::   nn_time0         !: initial time of day in hhmm
    INTEGER       ::   nn_leapy         !: Leap year calendar flag (0/1 or 30)
    INTEGER       ::   nn_istate        !: initial state output flag (0/1)
@@ -42,6 +42,4 @@
    INTEGER       ::   nn_stock         !: restart file frequency
    INTEGER, DIMENSION(10) :: nn_stocklist  !: restart dump times
-   LOGICAL       ::   ln_dimgnnn       !: type of dimgout. (F): 1 file for all proc
-                                                       !:                  (T): 1 file per proc
    LOGICAL       ::   ln_mskland       !: mask land points in NetCDF outputs (costly: + ~15%)
    LOGICAL       ::   ln_cfmeta        !: output additional data to netCDF files required for compliance with the CF metadata standard
@@ -99,4 +97,5 @@
    LOGICAL ::   ln_ctl       !: run control for debugging
    INTEGER ::   nn_timing    !: run control for timing
+   INTEGER ::   nn_diacfl    !: flag whether to create CFL diagnostics
    INTEGER ::   nn_print     !: level of print (0 no print)
    INTEGER ::   nn_ictls     !: Start i indice for the SUM control
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 6140)
@@ -8,4 +8,5 @@
    !!            3.0  ! 2007-07  (D. Storkey) Changes to iom_gettime
    !!            3.4  ! 2012-12  (R. Bourdalle-Badie and G. Reffray)  add C1D case  
+   !!            3.6  ! 2014-15  DIMG format removed
    !!--------------------------------------------------------------------
 
@@ -23,7 +24,5 @@
    USE lbclnk          ! lateal boundary condition / mpp exchanges
    USE iom_def         ! iom variables definitions
-   USE iom_ioipsl      ! NetCDF format with IOIPSL library
    USE iom_nf90        ! NetCDF format with native NetCDF library
-   USE iom_rstdimg     ! restarts access direct format "dimg" style...
    USE in_out_manager  ! I/O manager
    USE lib_mpp           ! MPP library
@@ -246,5 +245,5 @@
       CHARACTER(LEN=256)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
       CHARACTER(LEN=256)    ::   cltmpn    ! tempory name to store clname (in writting mode)
-      CHARACTER(LEN=10)     ::   clsuffix  ! ".nc" or ".dimg"
+      CHARACTER(LEN=10)     ::   clsuffix  ! ".nc" 
       CHARACTER(LEN=15)     ::   clcpu     ! the cpu number (max jpmax_digits digits)
       CHARACTER(LEN=256)    ::   clinfo    ! info character
@@ -309,9 +308,7 @@
       ! which suffix should we use?
       SELECT CASE (iolib)
-      CASE (jpioipsl ) ;   clsuffix = '.nc'
       CASE (jpnf90   ) ;   clsuffix = '.nc'
-      CASE (jprstdimg) ;   clsuffix = '.dimg'
       CASE DEFAULT     ;   clsuffix = ''
-         CALL ctl_stop( TRIM(clinfo), 'accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+         CALL ctl_stop( TRIM(clinfo), 'accepted IO library is only jpnf90 (jpioipsl option has been removed) ' )
       END SELECT
       ! Add the suffix if needed
@@ -326,7 +323,6 @@
       IF( .NOT.llok ) THEN
          ! we try to add the cpu number to the name
-         IF( iolib == jprstdimg ) THEN   ;   WRITE(clcpu,*) narea
-         ELSE                            ;   WRITE(clcpu,*) narea-1
-         ENDIF
+         WRITE(clcpu,*) narea-1
+
          clcpu  = TRIM(ADJUSTL(clcpu))
          iln = INDEX(clname,TRIM(clsuffix), back = .TRUE.)
@@ -375,5 +371,5 @@
          END SELECT
       ENDIF
-      ! Open the NetCDF or RSTDIMG file
+      ! Open the NetCDF file
       ! =============
       ! do we have some free file identifier?
@@ -399,9 +395,7 @@
       IF( istop == nstop ) THEN   ! no error within this routine
          SELECT CASE (iolib)
-         CASE (jpioipsl )   ;   CALL iom_ioipsl_open(  clname, kiomid, llwrt, llok, idompar )
          CASE (jpnf90   )   ;   CALL iom_nf90_open(    clname, kiomid, llwrt, llok, idompar )
-         CASE (jprstdimg)   ;   CALL iom_rstdimg_open( clname, kiomid, llwrt, llok, idompar )
          CASE DEFAULT
-            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            CALL ctl_stop( TRIM(clinfo)//' accepted IO library is only jpnf90 (jpioipsl option has been removed) ' )
          END SELECT
       ENDIF
@@ -438,9 +432,7 @@
             IF( iom_file(jf)%nfid > 0 ) THEN
                SELECT CASE (iom_file(jf)%iolib)
-               CASE (jpioipsl )   ;   CALL iom_ioipsl_close(  jf )
                CASE (jpnf90   )   ;   CALL iom_nf90_close(    jf )
-               CASE (jprstdimg)   ;   CALL iom_rstdimg_close( jf )
                CASE DEFAULT
-                  CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+                  CALL ctl_stop( TRIM(clinfo)//' accepted IO library is only jpnf90 (jpioipsl option has been removed)' )
                END SELECT
                iom_file(jf)%nfid       = 0          ! free the id 
@@ -497,9 +489,7 @@
                IF( iiv <= jpmax_vars ) THEN
                   SELECT CASE (iom_file(kiomid)%iolib)
-                  CASE (jpioipsl )   ;   iom_varid = iom_ioipsl_varid( kiomid, cdvar, iiv, kdimsz )
                   CASE (jpnf90   )   ;   iom_varid = iom_nf90_varid  ( kiomid, cdvar, iiv, kdimsz, kndims )
-                  CASE (jprstdimg)   ;   iom_varid = -1   ! all variables are listed in iom_file
-                  CASE DEFAULT   
-                     CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+                  CASE DEFAULT
+                     CALL ctl_stop( TRIM(clinfo)//' accepted IO library is only jpnf90 (jpioipsl option has been removed)' )
                   END SELECT
                ELSE
@@ -559,9 +549,7 @@
                                  &                         'Use ncwa -a to suppress the unnecessary dimensions' )
             SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, pvar, itime )
             CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar, itime )
-            CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idvar, pvar )
-            CASE DEFAULT    
-               CALL ctl_stop( 'iom_g0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            CASE DEFAULT
+               CALL ctl_stop( 'iom_g0d: accepted IO library is only jpnf90 (jpioipsl option has been removed)' )
             END SELECT
          ENDIF
@@ -673,4 +661,5 @@
       CHARACTER(LEN=256)             ::   clname      ! file name
       CHARACTER(LEN=1)               ::   clrankpv, cldmspc      ! 
+      LOGICAL                        ::   ll_depth_spec ! T => if kstart, kcount present then *only* use values for 3rd spatial dimension.
       !---------------------------------------------------------------------
       !
@@ -685,5 +674,6 @@
       IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
       IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
-      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown   ) CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown')
+      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown .AND.  idom /= jpdom_autoglo_xy  ) &
+     &           CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown or kdom = jpdom_autoglo_xy')
 
       luse_jattr = .false.
@@ -694,11 +684,8 @@
       IF( luse_jattr ) THEN
          SELECT CASE (iom_file(kiomid)%iolib)
-         CASE (jpioipsl, jprstdimg )
-             CALL ctl_warn(trim(clinfo), 'lrowattr present and true but this only works with netcdf (jpnf90)')
-             luse_jattr = .false.
          CASE (jpnf90   )   
              ! Ok
          CASE DEFAULT    
-            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            CALL ctl_stop( TRIM(clinfo)//' accepted IO library is only jpnf90 (jpioipsl option has been removed)' )
          END SELECT
       ENDIF
@@ -718,4 +705,10 @@
          ! update idom definition...
          ! Identify the domain in case of jpdom_auto(glo/dta) definition
+         IF( idom == jpdom_autoglo_xy ) THEN
+            ll_depth_spec = .TRUE.
+            idom = jpdom_autoglo
+         ELSE
+            ll_depth_spec = .FALSE.
+         ENDIF
          IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN            
             IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global 
@@ -771,7 +764,7 @@
          istart(idmspc+1) = itime
 
-         IF(              PRESENT(kstart)       ) THEN ; istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
+         IF( PRESENT(kstart) .AND. .NOT. ll_depth_spec ) THEN ; istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
          ELSE
-            IF(           idom == jpdom_unknown ) THEN                                       ; icnt(1:idmspc) = idimsz(1:idmspc)
+            IF(           idom == jpdom_unknown ) THEN                                                ; icnt(1:idmspc) = idimsz(1:idmspc)
             ELSE 
                IF( .NOT. PRESENT(pv_r1d) ) THEN   !   not a 1D array
@@ -796,6 +789,7 @@
                   ENDIF
                   IF( PRESENT(pv_r3d) ) THEN
-                     IF( idom == jpdom_data ) THEN   ; icnt(3) = jpkdta
-                     ELSE                            ; icnt(3) = jpk
+                     IF( idom == jpdom_data ) THEN                                  ; icnt(3) = jpkdta
+                     ELSE IF( ll_depth_spec .AND. PRESENT(kstart) ) THEN            ; istart(3) = kstart(3); icnt(3) = kcount(3)
+                     ELSE                                                           ; icnt(3) = jpk
                      ENDIF
                   ENDIF
@@ -866,12 +860,8 @@
       
          SELECT CASE (iom_file(kiomid)%iolib)
-         CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
-            &                                         pv_r1d, pv_r2d, pv_r3d )
          CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
             &                                         pv_r1d, pv_r2d, pv_r3d )
-         CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idom, idvar, ix1, ix2, iy1, iy2,   &
-            &                                         pv_r1d, pv_r2d, pv_r3d )
-         CASE DEFAULT    
-            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+         CASE DEFAULT
+            CALL ctl_stop( TRIM(clinfo)//' accepted IO library is only jpnf90 (jpioipsl option has been removed)' )
          END SELECT
 
@@ -956,9 +946,7 @@
                   IF( iom_file(kiomid)%dimsz(1,idvar) <= size(ptime) ) THEN
                      SELECT CASE (iom_file(kiomid)%iolib)
-                     CASE (jpioipsl )   ;   CALL iom_ioipsl_gettime( kiomid, idvar, ptime, cdunits, cdcalendar )
                      CASE (jpnf90   )   ;   CALL iom_nf90_gettime(   kiomid, idvar, ptime, cdunits, cdcalendar )
-                     CASE (jprstdimg)   ;   CALL ctl_stop( TRIM(clinfo)//' case IO library == jprstdimg not coded...' )
-                     CASE DEFAULT    
-                        CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+                     CASE DEFAULT
+                        CALL ctl_stop( TRIM(clinfo)//' accepted IO library is only jpnf90 (jpioipsl option has been removed)' )
                      END SELECT
                   ELSE
@@ -991,9 +979,7 @@
          IF( iom_file(kiomid)%nfid > 0 ) THEN
             SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpioipsl )   ;   CALL ctl_stop('iom_getatt: only nf90 available')
             CASE (jpnf90   )   ;   CALL iom_nf90_getatt( kiomid, cdatt, pvar )
-            CASE (jprstdimg)   ;   CALL ctl_stop('iom_getatt: only nf90 available')
-            CASE DEFAULT    
-               CALL ctl_stop( 'iom_g0d_att: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            CASE DEFAULT
+               CALL ctl_stop( 'iom_g0d_att: accepted IO library is only jpnf90' )
             END SELECT
          ENDIF
@@ -1017,9 +1003,7 @@
             ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
             SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
             CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
-            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pvar )
-            CASE DEFAULT     
-               CALL ctl_stop( 'iom_rp0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            CASE DEFAULT
+               CALL ctl_stop( 'iom_rp0d: accepted IO library is only jpnf90 (jpioipsl option has been removed)' )
             END SELECT
          ENDIF
@@ -1039,9 +1023,7 @@
             ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
             SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
             CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
-            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r1d = pvar )
-            CASE DEFAULT     
-               CALL ctl_stop( 'iom_rp1d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            CASE DEFAULT
+               CALL ctl_stop( 'iom_rp1d: accepted IO library is only jpnf90 (jpioipsl option has been removed)' )
             END SELECT
          ENDIF
@@ -1061,9 +1043,7 @@
             ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
             SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
             CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
-            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r2d = pvar ) 
-            CASE DEFAULT     
-               CALL ctl_stop( 'iom_rp2d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            CASE DEFAULT
+               CALL ctl_stop( 'iom_rp2d: accepted IO library is only jpnf90 (jpioipsl option has been removed)' )
             END SELECT
          ENDIF
@@ -1083,9 +1063,7 @@
             ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
             SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
             CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
-            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r3d = pvar )
-            CASE DEFAULT     
-               CALL ctl_stop( 'iom_rp3d: accepted IO library are only jpioipsl and jprstdimg' )
+            CASE DEFAULT
+               CALL ctl_stop( 'iom_rp3d: accepted IO library is only jpnf90 (jpioipsl option has been removed)' )
             END SELECT
          ENDIF
@@ -1645,5 +1623,5 @@
             idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@')
             DO WHILE ( idx /= 0 ) 
-               cldate = iom_sdate( fjulday - rdttra(1) / rday )
+               cldate = iom_sdate( fjulday - rdt / rday )
                clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+11:LEN_TRIM(clname))
                idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@')
@@ -1652,5 +1630,5 @@
             idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@')
             DO WHILE ( idx /= 0 ) 
-               cldate = iom_sdate( fjulday - rdttra(1) / rday, ldfull = .TRUE. )
+               cldate = iom_sdate( fjulday - rdt / rday, ldfull = .TRUE. )
                clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+15:LEN_TRIM(clname))
                idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@')
@@ -1659,5 +1637,5 @@
             idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@')
             DO WHILE ( idx /= 0 ) 
-               cldate = iom_sdate( fjulday + rdttra(1) / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE. )
+               cldate = iom_sdate( fjulday + rdt / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE. )
                clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+9:LEN_TRIM(clname))
                idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@')
@@ -1666,5 +1644,5 @@
             idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@')
             DO WHILE ( idx /= 0 ) 
-               cldate = iom_sdate( fjulday + rdttra(1) / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE., ldfull = .TRUE. )
+               cldate = iom_sdate( fjulday + rdt / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE., ldfull = .TRUE. )
                clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+13:LEN_TRIM(clname))
                idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@')
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom_def.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom_def.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom_def.F90	(revision 6140)
@@ -9,5 +9,5 @@
    !!---------------------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
+   !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!---------------------------------------------------------------------------------
@@ -26,14 +26,10 @@
    INTEGER, PARAMETER, PUBLIC ::   jpdom_unknown       = 7   !: No dimension checking
    INTEGER, PARAMETER, PUBLIC ::   jpdom_autoglo       = 8   !: 
-   INTEGER, PARAMETER, PUBLIC ::   jpdom_autodta       = 9   !: 
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_autoglo_xy    = 9   !: Automatically set horizontal dimensions only
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_autodta       = 10  !: 
 
-   INTEGER, PARAMETER, PUBLIC ::   jpioipsl    = 100      !: Use ioipsl (fliocom only) library
    INTEGER, PARAMETER, PUBLIC ::   jpnf90      = 101      !: Use nf90 library
-   INTEGER, PARAMETER, PUBLIC ::   jprstdimg   = 102      !: Use restart dimgs (fortran direct acces) library
-#if defined key_dimgout
-   INTEGER, PARAMETER, PUBLIC ::   jprstlib  = jprstdimg  !: restarts io library
-#else
+
    INTEGER, PARAMETER, PUBLIC ::   jprstlib  = jpnf90     !: restarts io library
-#endif
 
    INTEGER, PARAMETER, PUBLIC ::   jp_r8    = 200      !: write REAL(8)
@@ -54,7 +50,9 @@
       CHARACTER(LEN=240)                        ::   name     !: name of the file
       INTEGER                                   ::   nfid     !: identifier of the file (0 if closed)
-      INTEGER                                   ::   iolib    !: library used to read the file (jpioipsl, jpnf90 or jprstdimg)
+      INTEGER                                   ::   iolib    !: library used to read the file (jpnf90 or new formats,
+                                                              !: jpioipsl option has been removed)
       INTEGER                                   ::   nvars    !: number of identified varibles in the file
       INTEGER                                   ::   iduld    !: id of the unlimited dimension
+      INTEGER                                   ::   lenuld   !: length of the unlimited dimension (number of records in file)
       INTEGER                                   ::   irec     !: writing record position  
       CHARACTER(LEN=32)                         ::   uldname  !: name of the unlimited dimension
Index: unk/NEMOGCM/NEMO/OPA_SRC/IOM/iom_ioipsl.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom_ioipsl.F90	(revision 6139)
+++ 	(revision )
@@ -1,439 +1,0 @@
-MODULE iom_ioipsl
-   !!=====================================================================
-   !!                    ***  MODULE  iom_ioipsl ***
-   !! Input/Output manager :  Library to read input files with IOIPSL (only fliocom module)
-   !!====================================================================
-   !! History :  9.0  ! 05 12  (J. Belier) Original code
-   !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
-   !!             "   ! 07 07  (D. Storkey) Changes to iom_ioipsl_gettime
-   !!--------------------------------------------------------------------
-   !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
-
-   !!--------------------------------------------------------------------
-   !!   iom_open       : open a file read only
-   !!   iom_close      : close a file or all files opened by iom
-   !!   iom_get        : read a field (interfaced to several routines)
-   !!   iom_gettime    : read the time axis kvid in the file
-   !!   iom_varid      : get the id of a variable in a file
-   !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
-   !!--------------------------------------------------------------------
-   USE dom_oce         ! ocean space and time domain
-   USE iom_def         ! iom variables definitions
-   USE ioipsl          ! IOIPSL library
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! MPP library
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC iom_ioipsl_open, iom_ioipsl_close, iom_ioipsl_varid, iom_ioipsl_get, iom_ioipsl_gettime, iom_ioipsl_rstput
-
-   INTERFACE iom_ioipsl_get
-      MODULE PROCEDURE iom_ioipsl_g0d, iom_ioipsl_g123d
-   END INTERFACE
-   INTERFACE iom_ioipsl_rstput
-      MODULE PROCEDURE iom_ioipsl_rp0123d
-   END INTERFACE
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE iom_ioipsl_open( cdname, kiomid, ldwrt, ldok, kdompar )
-      !!---------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_open  ***
-      !!
-      !! ** Purpose :  open an input file with IOIPSL (only fliocom module)
-      !!---------------------------------------------------------------------
-      CHARACTER(len=*)       , INTENT(inout)           ::   cdname      ! File name
-      INTEGER                , INTENT(  out)           ::   kiomid      ! ioipsl identifier of the opened file
-      LOGICAL                , INTENT(in   )           ::   ldwrt       ! read or write the file?
-      LOGICAL                , INTENT(in   )           ::   ldok        ! check the existence 
-      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar     ! domain parameters: 
-
-      CHARACTER(LEN=100) ::   clinfo      ! info character
-      CHARACTER(LEN=10 ) ::   clstatus    ! status of opened file (REPLACE or NEW)
-      INTEGER            ::   iln         ! lengths of character
-      INTEGER            ::   istop       ! temporary storage of nstop
-      INTEGER            ::   ifliodom    ! model domain identifier (see flio_dom_set)
-      INTEGER            ::   ioipslid    ! ioipsl identifier of the opened file
-      INTEGER            ::   jl          ! loop variable
-      LOGICAL            ::   llclobber   ! local definition of ln_clobber
-      !---------------------------------------------------------------------
-
-      clinfo = '                    iom_ioipsl_open ~~~  '
-      istop = nstop
-      !
-      llclobber = ldwrt .AND. ln_clobber
-      IF( ldok .AND. .NOT. llclobber ) THEN      ! Open existing file...
-         !                 ! =============
-         IF( ldwrt ) THEN  ! ... in write mode
-            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in WRITE mode'
-            CALL flioopfd( TRIM(cdname), ioipslid, "WRITE" )
-         ELSE              ! ... in read mode
-            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READ mode'
-            CALL flioopfd( TRIM(cdname), ioipslid )
-         ENDIF
-      ELSE                 ! the file does not exist
-         !                 ! =============
-         iln = INDEX( cdname, '.nc' )
-         IF( ldwrt ) THEN  ! the file should be open in write mode so we create it...
-            IF( llclobber ) THEN   ;   clstatus = 'REPLACE 64' 
-            ELSE                   ;   clstatus = 'NEW 64'
-            ENDIF
-            IF( jpnij > 1 ) THEN
-               ! define the domain position regarding to the global domain (mainly useful in mpp)
-               CALL flio_dom_set( jpnij, narea-1, (/1, 2/), (/jpiglo, jpjglo/)   &
-                  &             , kdompar(:,1), kdompar(:,2), kdompar(:,3), kdompar(:,4), kdompar(:,5)   &
-                  &             , 'BOX', ifliodom )        
-               ! Note that fliocrfd may change the value of cdname (add the cpu number...)
-               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//cdname(1:iln-1)//'... in WRITE mode'
-               CALL fliocrfd( cdname, (/'x'         , 'y'         , 'z', 't'/)   &
-                  &         , (/kdompar(1,1), kdompar(2,1), jpk, -1 /), ioipslid, ifliodom, mode = clstatus )
-            ELSE              ! the file should be open for read mode so it must exist...
-               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//cdname//' in WRITE mode'
-               CALL fliocrfd( cdname, (/'x'         , 'y'         , 'z', 't'/)   &
-                  &         , (/kdompar(1,1), kdompar(2,1), jpk, -1 /), ioipslid,           mode = clstatus )
-            ENDIF
-         ELSE              ! the file should be open for read mode so it must exist...
-            CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
-         ENDIF
-      ENDIF
-      ! start to fill file informations
-      ! =============
-      IF( istop == nstop ) THEN   ! no error within this routine
-!does not work with some compilers         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
-         kiomid = 0
-         DO jl = jpmax_files, 1, -1
-            IF( iom_file(jl)%nfid == 0 )   kiomid = jl
-         ENDDO
-         iom_file(kiomid)%name   = TRIM(cdname)
-         iom_file(kiomid)%nfid   = ioipslid
-         iom_file(kiomid)%iolib  = jpioipsl
-         iom_file(kiomid)%nvars  = 0
-         iom_file(kiomid)%irec   = -1   ! useless for NetCDF files
-         CALL flioinqf( ioipslid, id_uld = iom_file(kiomid)%iduld )
-         IF(lwp) WRITE(numout,*) '                   ---> '//TRIM(cdname)//' OK'
-      ELSE
-         kiomid = 0               ! return error flag
-      ENDIF
-      !
-   END SUBROUTINE iom_ioipsl_open
-
-
-   SUBROUTINE iom_ioipsl_close( kiomid )
-      !!--------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_ioipsl_close  ***
-      !!
-      !! ** Purpose : close an input file with IOIPSL (only fliocom module) 
-      !!--------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kiomid   ! iom identifier of the file to be closed
-      !---------------------------------------------------------------------
-      !
-      CALL flioclo( iom_file(kiomid)%nfid )
-      !    
-   END SUBROUTINE iom_ioipsl_close
-
-
-   FUNCTION iom_ioipsl_varid ( kiomid, cdvar, kiv, kdimsz )  
-      !!-----------------------------------------------------------------------
-      !!                  ***  FUNCTION  iom_varid  ***
-      !!
-      !! ** Purpose : get the id of a variable in a file with IOIPSL (only fliocom module)
-      !!-----------------------------------------------------------------------
-      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
-      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
-      INTEGER              , INTENT(in   )           ::   kiv   ! 
-      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
-      !
-      INTEGER                        ::   iom_ioipsl_varid  ! iom variable Id
-      INTEGER                        ::   ioipslid          ! ioipsl file identifier
-      INTEGER                        ::   ji                ! dummy loop index
-      INTEGER                        ::   i_nvd             ! number of dimension of the variable
-      INTEGER, DIMENSION(jpmax_dims) ::   idimid            ! dimension ids of the variable
-      LOGICAL                        ::   ll_fnd            ! found test
-      CHARACTER(LEN=100)             ::   clinfo            ! info character
-      !!-----------------------------------------------------------------------
-      clinfo = 'iom_ioipsl_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
-      iom_ioipsl_varid = 0                  ! default definition
-      IF( PRESENT(kdimsz) ) kdimsz(:) = 0   ! default definition
-      ioipslid = iom_file(kiomid)%nfid      ! get back ioipsl file identifier 
-      CALL flioinqv( ioipslid, cdvar, ll_fnd, nb_dims = i_nvd )   ! does the variable exist in the file
-      IF( ll_fnd ) THEN
-         IF( i_nvd <= jpmax_dims ) THEN
-            iom_ioipsl_varid = kiv
-            iom_file(kiomid)%nvars       = kiv
-            iom_file(kiomid)%nvid(kiv)   = -1   ! variable id is not available in ioipsl
-            iom_file(kiomid)%cn_var(kiv) = TRIM(cdvar)
-            iom_file(kiomid)%ndims(kiv)  = i_nvd
-            iom_file(kiomid)%dimsz(:,kiv) = 0   ! reset dimsz in case previously used
-            CALL flioinqv( ioipslid, cdvar, ll_fnd,   &
-                  &           len_dims = iom_file(kiomid)%dimsz(1:i_nvd,kiv), &   ! dimensions size
-                  &           id_dims  = idimid(1:i_nvd) )                        ! dimensions ids
-            iom_file(kiomid)%luld(kiv) = .FALSE.   ! default value
-            DO ji = 1, i_nvd                       ! find the unlimited dimension
-               IF( idimid(ji) == iom_file(kiomid)%iduld ) iom_file(kiomid)%luld(kiv) = .TRUE.
-            END DO
-            !---------- Deal with scale_factor and add_offset
-            CALL flioinqa( ioipslid, cdvar, 'scale_factor', ll_fnd )
-            IF( ll_fnd) THEN
-               CALL fliogeta( ioipslid, cdvar, 'scale_factor', iom_file(kiomid)%scf(kiv) )
-            ELSE
-               iom_file(kiomid)%scf(kiv) = 1.
-            END IF
-            CALL flioinqa( ioipslid, cdvar, 'add_offset', ll_fnd )
-            IF( ll_fnd ) THEN
-               CALL fliogeta( ioipslid, cdvar, 'add_offset', iom_file(kiomid)%ofs(kiv) )
-            ELSE
-               iom_file(kiomid)%ofs(kiv) = 0.
-            END IF
-            ! return the simension size
-            IF( PRESENT(kdimsz) ) THEN 
-               IF( i_nvd == SIZE(kdimsz) ) THEN
-                  kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,kiv)
-               ELSE
-                  WRITE(ctmp1,*) i_nvd, SIZE(kdimsz)
-                  CALL ctl_stop( TRIM(clinfo), 'error in kdimsz size'//TRIM(ctmp1) )
-               ENDIF
-            ENDIF
-         ELSE
-            CALL ctl_stop( TRIM(clinfo), 'Too many dimensions in the file '//iom_file(kiomid)%name,   &
-                  &                       'increase the parameter jpmax_vars')
-         ENDIF
-      ELSE  
-         iom_ioipsl_varid = -1   !   variable not found, return error code: -1
-      ENDIF
-      !
-   END FUNCTION iom_ioipsl_varid
-
-
-   SUBROUTINE iom_ioipsl_g0d( kiomid, kvid, pvar, kstart )
-      !!-----------------------------------------------------------------------
-      !!                  ***  ROUTINE  iom_ioipsl_g0d  ***
-      !!
-      !! ** Purpose : read a scalar with IOIPSL (only fliocom module)
-      !!-----------------------------------------------------------------------
-      INTEGER ,               INTENT(in   )            ::   kiomid    ! Identifier of the file
-      INTEGER ,               INTENT(in   )            ::   kvid      ! variable id
-      REAL(wp),               INTENT(  out)            ::   pvar      ! read field
-      INTEGER , DIMENSION(1), INTENT(in   ), OPTIONAL  ::   kstart    ! start position of the reading in each axis
-      !
-      CALL fliogetv( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), pvar, kstart )
-      ! 
-   END SUBROUTINE iom_ioipsl_g0d
-
-
-   SUBROUTINE iom_ioipsl_g123d( kiomid, kvid, knbdim, kstart, kcount, kx1, kx2, ky1, ky2,   &
-         &                      pv_r1d, pv_r2d, pv_r3d)
-      !!-----------------------------------------------------------------------
-      !!                  ***  ROUTINE  iom_ioipsl_g123d  ***
-      !!
-      !! ** Purpose : read a 1D/2D/3D variable with IOIPSL (only fliocom module)
-      !!
-      !! ** Method : read ONE record at each CALL
-      !!-----------------------------------------------------------------------
-      INTEGER                    , INTENT(in   )           ::   kiomid     ! iom identifier of the file
-      INTEGER                    , INTENT(in   )           ::   kvid       ! Name of the variable
-      INTEGER                    , INTENT(in   )           ::   knbdim     ! number of dimensions of the variable
-      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kstart     ! start position of the reading in each axis 
-      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kcount     ! number of points to be read in each axis
-      INTEGER ,                    INTENT(in   )           ::   kx1, kx2, ky1, ky2   ! subdomain indexes
-      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
-      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
-      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
-      !
-      INTEGER               ::   ioipslid   ! ioipsl file identifier
-      CHARACTER(LEN=100)    ::   clvn       ! variable name
-      !---------------------------------------------------------------------
-      clvn = TRIM(iom_file(kiomid)%cn_var(kvid))   ! get back variable name 
-      ioipslid = iom_file(kiomid)%nfid             ! get back IPIPSL file id
-      !
-      IF( PRESENT(pv_r1d) ) THEN
-         CALL fliogetv( ioipslid, clvn, pv_r1d(:                ), start = kstart(1:knbdim), count = kcount(1:knbdim) )
-      ELSEIF( PRESENT(pv_r2d) ) THEN
-         CALL fliogetv( ioipslid, clvn, pv_r2d(kx1:kx2,ky1:ky2  ), start = kstart(1:knbdim), count = kcount(1:knbdim) )
-      ELSEIF( PRESENT(pv_r3d) ) THEN
-         CALL fliogetv( ioipslid, clvn, pv_r3d(kx1:kx2,ky1:ky2,:), start = kstart(1:knbdim), count = kcount(1:knbdim) )
-      ENDIF
-      !
-      !
-   END SUBROUTINE iom_ioipsl_g123d
-
-
-   SUBROUTINE iom_ioipsl_gettime( kiomid, kvid, ptime, cdunits, cdcalendar )
-      !!--------------------------------------------------------------------
-      !!                   ***  SUBROUTINE iom_gettime  ***
-      !!
-      !! ** Purpose : read the time axis kvid in the file with IOIPSL (only fliocom module)
-      !!--------------------------------------------------------------------
-      INTEGER                   , INTENT(in   ) ::   kiomid     ! file Identifier
-      INTEGER                   , INTENT(in   ) ::   kvid       ! variable id
-      REAL(wp), DIMENSION(:)    , INTENT(  out) ::   ptime      ! the time axis
-      CHARACTER(len=*), OPTIONAL, INTENT(  out) ::   cdunits    ! units attribute
-      CHARACTER(len=*), OPTIONAL, INTENT(  out) ::   cdcalendar ! calendar attribute
-      !---------------------------------------------------------------------
-      !
-      CALL fliogetv( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), ptime(:),   &
-            &         start=(/ 1 /), count=(/ iom_file(kiomid)%dimsz(1, kvid) /) )
-      IF ( PRESENT(cdunits) ) THEN 
-         CALL fliogeta( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), "units", cdunits )
-      ENDIF
-      IF ( PRESENT(cdcalendar) ) THEN 
-         CALL fliogeta( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), "calendar", cdcalendar )
-      ENDIF
-      !
-   END SUBROUTINE iom_ioipsl_gettime
-
-
-   SUBROUTINE iom_ioipsl_rp0123d( kt, kwrite, kiomid, cdvar , kvid  , ktype,   &
-         &                                 pv_r0d, pv_r1d, pv_r2d, pv_r3d )
-      !!--------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_ioipsl_rstput  ***
-      !!
-      !! ** Purpose : read the time axis cdvar in the file 
-      !!--------------------------------------------------------------------
-      INTEGER                     , INTENT(in)           ::   kt       ! ocean time-step
-      INTEGER                     , INTENT(in)           ::   kwrite   ! writing time-step
-      INTEGER                     , INTENT(in)           ::   kiomid   ! Identifier of the file 
-      CHARACTER(len=*)            , INTENT(in)           ::   cdvar    ! variable name
-      INTEGER                     , INTENT(in)           ::   kvid     ! variable id
-      INTEGER                     , INTENT(in), OPTIONAL ::   ktype    ! variable type (default R8)
-      REAL(wp)                    , INTENT(in), OPTIONAL ::   pv_r0d   ! written Od field
-      REAL(wp), DIMENSION(      :), INTENT(in), OPTIONAL ::   pv_r1d   ! written 1d field
-      REAL(wp), DIMENSION(:, :   ), INTENT(in), OPTIONAL ::   pv_r2d   ! written 2d field
-      REAL(wp), DIMENSION(:, :, :), INTENT(in), OPTIONAL ::   pv_r3d   ! written 3d field
-      !
-      INTEGER               :: idims                ! number of dimension
-      INTEGER               :: idvar                ! variable id
-      INTEGER               :: itype                ! variable type
-      INTEGER               :: ix1, ix2, iy1, iy2   ! subdomain indexes
-      INTEGER, DIMENSION(4) :: idimsz               ! dimensions size  
-      INTEGER, DIMENSION(4) :: idimid               ! dimensions id
-      CHARACTER(LEN=100)    :: clinfo               ! info character
-      INTEGER               :: ioipslid             ! ioipsl file identifier
-      !---------------------------------------------------------------------
-      !
-      clinfo = '          iom_ioipsl_rp0123d, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar)
-      ioipslid = iom_file(kiomid)%nfid
-      !
-      ! define dimension variables if it is not already done
-      ! ==========================
-      IF( iom_file(kiomid)%nvars == 0 ) THEN
-         ! define the dimension variables if it is not already done
-         CALL fliodefv( ioipslid,'nav_lon', (/1,2/), v_t=flio_r4   , axis='X',   &
-               &                  long_name="Longitude", units="degrees_east" )
-         CALL fliodefv( ioipslid,'nav_lat', (/1,2/), v_t=flio_r4   , axis='Y',   &
-               &                  long_name="Latitude", units="degrees_north" )
-         CALL fliodefv( ioipslid,'nav_lev', (/3/)  , v_t=flio_i4   , axis='Z',   &
-               &                  long_name="Model levels",units="model_levels")
-         CALL fliodefv( ioipslid,'time_counter', (/4/), v_t=flio_r4, axis='T',   &
-               &                  long_name="Time axis", units='seconds since 0001-01-01 00:00:00' )
-         ! update informations structure related the dimension variable we just added...
-         iom_file(kiomid)%nvars       = 4
-         iom_file(kiomid)%luld(1:4)   = (/ .FALSE., .FALSE., .FALSE., .TRUE. /)
-         iom_file(kiomid)%cn_var(1:3) = (/ 'nav_lon', 'nav_lat', 'nav_lev' /)
-         iom_file(kiomid)%cn_var(4)   = 'time_counter'
-         iom_file(kiomid)%ndims(1:4)  = (/ 2, 2, 1, 1 /)
-         ! trick: defined to 0 to say that dimension variables are defined but not yet written
-         iom_file(kiomid)%dimsz(1, 1) = 0   
-         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' define dimension variables done'
-      ENDIF
-
-      ! define the data if it is not already done
-      ! ===============
-      IF( kvid <= 0 ) THEN
-         ! variable definition
-         IF(     PRESENT(pv_r0d) ) THEN   ;   idims = 0
-         ELSEIF( PRESENT(pv_r1d) ) THEN   ;   idims = 2   ;   idimid(1:idims) = (/    3,4/)
-         ELSEIF( PRESENT(pv_r2d) ) THEN   ;   idims = 3   ;   idimid(1:idims) = (/1,2  ,4/)
-         ELSEIF( PRESENT(pv_r3d) ) THEN   ;   idims = 4   ;   idimid(1:idims) = (/1,2,3,4/)
-         ENDIF
-         IF( PRESENT(ktype) ) THEN   ! variable external type
-            SELECT CASE (ktype)
-            CASE (jp_r8)  ;   itype = flio_r8
-            CASE (jp_r4)  ;   itype = flio_r4
-            CASE (jp_i4)  ;   itype = flio_i4
-            CASE (jp_i2)  ;   itype = flio_i2
-            CASE (jp_i1)  ;   itype = flio_i1   !   fliocom does not handle i1 type of variable
-            CASE DEFAULT   ;   CALL ctl_stop( TRIM(clinfo)//' unknown variable type' )
-            END SELECT
-         ELSE
-            itype = flio_r8
-         ENDIF
-         IF( PRESENT(pv_r0d) ) THEN   ;   CALL fliodefv (ioipslid, TRIM(cdvar)                 , v_t = itype)
-         ELSE                         ;   CALL fliodefv (ioipslid, TRIM(cdvar), idimid(1:idims), v_t = itype)
-         ENDIF
-         ! update informations structure related the new variable we want to add...
-         idvar                          = iom_file(kiomid)%nvars + 1
-         iom_file(kiomid)%nvars         = idvar
-         iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar)
-         iom_file(kiomid)%nvid(idvar)   = -1   ! netcdf variable id is not available in ioipsl
-         iom_file(kiomid)%scf(idvar)    = 1.
-         iom_file(kiomid)%ofs(idvar)    = 0.
-         iom_file(kiomid)%ndims(idvar)  = idims
-         IF( .NOT. PRESENT(pv_r0d) ) THEN
-            iom_file(kiomid)%luld(idvar) = .TRUE.
-            CALL flioinqf( ioipslid, ln_dim = idimsz )
-            iom_file(kiomid)%dimsz(1:idims-1,idvar) = idimsz(idimid(1:idims-1))
-         ELSE                               
-            iom_file(kiomid)%luld(idvar) = .FALSE.
-         ENDIF
-         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' defined ok'
-      ELSE
-         idvar = kvid
-      ENDIF
-
-      ! time step kwrite : write the variable
-      IF( kt == kwrite ) THEN
-         ! on what kind of domain must the data be written?
-         IF( PRESENT(pv_r2d) .OR. PRESENT(pv_r3d) ) THEN
-            idimsz(1:2) = iom_file(kiomid)%dimsz(1:2,idvar)
-            IF(     idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN
-               ix1 = nldi   ;   ix2 = nlei   ;   iy1 = nldj   ;   iy2 = nlej
-            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN
-               ix1 = 1      ;   ix2 = nlci   ;   iy1 = 1      ;   iy2 = nlcj
-            ELSEIF( idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN
-               ix1 = 1      ;   ix2 = jpi    ;   iy1 = 1      ;   iy2 = jpj
-            ELSE 
-               CALL ctl_stop( 'iom_ioipsl_rp0123d: should have been an impossible case...' )
-            ENDIF
-
-            ! write dimension variables if it is not already done
-            ! =============
-            ! trick: is defined to 0 => dimension variable are defined but not yet written
-            IF( iom_file(kiomid)%dimsz(1, 1) == 0 ) THEN
-               CALL flioputv( ioipslid, 'nav_lon'     , glamt(ix1:ix2, iy1:iy2) )
-               CALL flioputv( ioipslid, 'nav_lat'     , gphit(ix1:ix2, iy1:iy2) )
-               CALL flioputv( ioipslid, 'nav_lev'     , gdept_1d )
-               ! +++ WRONG VALUE: to be improved but not really useful...
-               CALL flioputv( ioipslid, 'time_counter', kt )
-               ! update the values of the variables dimensions size
-               CALL flioinqf( ioipslid, ln_dim = idimsz )
-               iom_file(kiomid)%dimsz(1:2, 1) = idimsz(1:2)
-               iom_file(kiomid)%dimsz(1:2, 2) = idimsz(1:2)
-               iom_file(kiomid)%dimsz(1, 3:4) = (/idimsz(3), 1/)
-               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' write dimension variables done'
-            ENDIF
-         ENDIF
-
-         ! write the data
-         ! =============
-         IF(     PRESENT(pv_r0d) ) THEN   ;   CALL flioputv( ioipslid, cdvar, pv_r0d                      )
-         ELSEIF( PRESENT(pv_r1d) ) THEN   ;   CALL flioputv( ioipslid, cdvar, pv_r1d(                  :) )
-         ELSEIF( PRESENT(pv_r2d) ) THEN   ;   CALL flioputv( ioipslid, cdvar, pv_r2d(ix1:ix2, iy1:iy2   ) )
-         ELSEIF( PRESENT(pv_r3d) ) THEN   ;   CALL flioputv( ioipslid, cdvar, pv_r3d(ix1:ix2, iy1:iy2, :) )
-         ENDIF
-         ! add 1 to the size of the temporal dimension (not really useful...)
-         IF( iom_file(kiomid)%luld(idvar) )   iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar)    &
-               &                            = iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar) + 1
-         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' written ok'
-      ENDIF
-      !     
-   END SUBROUTINE iom_ioipsl_rp0123d
-
-
-   !!======================================================================
-END MODULE iom_ioipsl
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 6140)
@@ -154,6 +154,7 @@
          CALL iom_nf90_check(NF90_Inquire(if90id, unlimitedDimId = iom_file(kiomid)%iduld), clinfo)
          IF ( iom_file(kiomid)%iduld .GE. 0 ) THEN
-           CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, iom_file(kiomid)%iduld,   &
-        &                                               name = iom_file(kiomid)%uldname), clinfo)
+           CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, iom_file(kiomid)%iduld,     & 
+        &                                               name = iom_file(kiomid)%uldname,  &
+        &                                               len  = iom_file(kiomid)%lenuld ), clinfo )
          ENDIF
          IF(lwp) WRITE(numout,*) '                   ---> '//TRIM(cdname)//' OK'
Index: unk/NEMOGCM/NEMO/OPA_SRC/IOM/iom_rstdimg.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom_rstdimg.F90	(revision 6139)
+++ 	(revision )
@@ -1,504 +1,0 @@
-MODULE iom_rstdimg
-   !!=====================================================================
-   !!                    ***  MODULE  iom_rstdimg ***
-   !! Input/Output manager :  Library to read input rstdimg files
-   !!====================================================================
-   !! History :  9.0  ! 06 09  (S. Masson) Original code
-   !!--------------------------------------------------------------------
-
-   !!--------------------------------------------------------------------
-   !!   iom_open       : open a file read only
-   !!   iom_close      : close a file or all files opened by iom
-   !!   iom_get        : read a field (interfaced to several routines)
-   !!   iom_gettime    : read the time axis kvid in the file
-   !!   iom_varid      : get the id of a variable in a file
-   !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
-   !!--------------------------------------------------------------------
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! MPP library
-   USE dom_oce         ! ocean space and time domain
-   USE lbclnk          ! lateal boundary condition / mpp exchanges
-   USE iom_def         ! iom variables definitions
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC iom_rstdimg_open, iom_rstdimg_close, iom_rstdimg_get, iom_rstdimg_rstput
-
-   INTERFACE iom_rstdimg_get
-      MODULE PROCEDURE iom_rstdimg_g0d, iom_rstdimg_g123d
-   END INTERFACE
-   INTERFACE iom_rstdimg_rstput
-      MODULE PROCEDURE iom_rstdimg_rp0d, iom_rstdimg_rp123d
-   END INTERFACE
-
-   INTEGER, PARAMETER ::   jpvnl          = 32   ! variable name length
-      
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE iom_rstdimg_open( cdname, kiomid, ldwrt, ldok, kdompar )
-      !!---------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_open  ***
-      !!
-      !! ** Purpose :  open an input file read only (return 0 if not found)
-      !!---------------------------------------------------------------------
-      CHARACTER(len=*)       , INTENT(inout)           ::   cdname      ! File name
-      INTEGER                , INTENT(  out)           ::   kiomid      ! iom identifier of the opened file
-      LOGICAL                , INTENT(in   )           ::   ldwrt       ! read or write the file?
-      LOGICAL                , INTENT(in   )           ::   ldok        ! check the existence 
-      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar     ! domain parameters: 
-
-      CHARACTER(LEN=100)                      ::   clinfo                     ! info character
-      CHARACTER(LEN=100)                      ::   cltmp                      ! temporary character
-      CHARACTER(LEN=10 )                      ::   clstatus                   ! status of opened file (REPLACE or NEW)
-      INTEGER                                 ::   jv                         ! loop counter
-      INTEGER                                 ::   istop                      ! temporary storage of nstop
-      INTEGER                                 ::   idrst                      ! logical unit of the restart file
-      INTEGER                                 ::   iln                        ! lengths of character
-      INTEGER                                 ::   irecl8                     ! record length
-      INTEGER                                 ::   ios                        ! IO status
-      INTEGER                                 ::   irhd                       ! record of the header infos
-      INTEGER                                 ::   ivnum                      ! number of variables
-      INTEGER                                 ::   ishft                      ! counter shift
-      INTEGER                                 ::   inx, iny, inz              ! x,y,z dimension of the variable
-      INTEGER                                 ::   in0d, in1d, in2d, in3d     ! number of 0/1/2/3D variables
-      INTEGER                                 ::   ipni, ipnj, ipnij, iarea   ! domain decomposition 
-      INTEGER                                 ::   iiglo, ijglo               ! domain global size 
-      INTEGER                                 ::   jl                         ! loop variable
-      LOGICAL                                 ::   llclobber                  ! local definition of ln_clobber
-      CHARACTER(LEN=jpvnl), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d     ! name of 0/1/2/3D variables
-      REAL(wp),             DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d     ! value of 0d variables or record
-      !                                                                                   ! position for 1/2/3D variables
-      !---------------------------------------------------------------------
-      clinfo = '                    iom_rstdimg_open ~~~  '
-      istop = nstop      ! store the actual value of nstop
-      ios = 0            ! default definition
-      kiomid = 0         ! default definition
-      llclobber = ldwrt .AND. ln_clobber
-      ! get a free unit
-      idrst = get_unit()  ! get a free logical unit for the restart file
-!!$#if defined key_agrif 
-!!$      idrst = Agrif_Get_Unit()      
-!!$#endif 
-      ! Open the file...
-      ! =============
-      IF( ldok .AND. .NOT. llclobber ) THEN      ! Open existing file...
-         ! find the record length
-         OPEN( idrst, FILE = TRIM(cdname), FORM = 'unformatted', ACCESS = 'direct'   &
-            &       , RECL = 8, STATUS = 'old', ACTION = 'read', IOSTAT = ios, ERR = 987 )
-         READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8
-         CLOSE( idrst )
-         ! Open the file with the appropriate record length and parameters
-         IF( ldwrt ) THEN  ! ... in readwrite mode
-            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READWRITE mode'
-            OPEN( idrst, FILE = TRIM(cdname), FORM = 'unformatted', ACCESS = 'direct'   &
-               &       , RECL = irecl8, STATUS = 'old', ACTION = 'readwrite', IOSTAT = ios, ERR = 987 )
-         ELSE              ! ... in read mode
-            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READ mode'
-            OPEN( idrst, FILE = TRIM(cdname), FORM = 'unformatted', ACCESS = 'direct'   &
-               &       , RECL = irecl8, STATUS = 'old', ACTION = 'read'     , IOSTAT = ios, ERR = 987 )
-         ENDIF
-      ELSE                                       ! the file does not exist (or we overwrite it)
-         iln = INDEX( cdname, '.dimg' )
-         IF( ldwrt ) THEN  ! the file should be open in readwrite mode so we create it...
-            irecl8= MAX( kdompar(1,1) * kdompar(2,1) * wp, ( 8*jpnij + 15 ) * 4 )
-            IF( jpnij > 1 ) THEN
-               WRITE(cltmp,'(a,a,i4.4,a)') cdname(1:iln-1), '_', narea, '.dimg'
-               cdname = TRIM(cltmp)
-            ENDIF
-            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//TRIM(cdname)//' in READWRITE mode'
-            
-            IF( llclobber ) THEN   ;   clstatus = 'REPLACE' 
-            ELSE                   ;   clstatus = 'NEW'
-            ENDIF
-            OPEN( idrst, FILE = TRIM(cdname), FORM = 'UNFORMATTED', ACCESS = 'DIRECT'   &
-               &       , RECL = irecl8, STATUS = TRIM(clstatus), ACTION = 'readwrite', IOSTAT = ios, ERR = 987 )
-         ELSE              ! the file should be open for read mode so it must exist...
-            CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
-         ENDIF
-      ENDIF
-      ! Performs checks on the file
-      ! =============
-      IF( ldok .AND. .NOT. llclobber ) THEN      ! old file
-         READ( idrst, REC = 1   , IOSTAT = ios, ERR = 987 )              &
-              &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd,   &
-              &   ipni, ipnj, ipnij, iarea, iiglo, ijglo
-         READ( idrst, REC = irhd, IOSTAT = ios, ERR = 987 )                       &
-            &   clna0d(1:in0d), zval0d(1:in0d), clna1d(1:in1d), zval1d(1:in1d),   &
-            &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d)
-         clinfo = TRIM(clinfo)//' file '//TRIM(cdname)
-         IF( iiglo /= jpiglo       )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in global domain size in i direction' )
-         IF( ijglo /= jpjglo       )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in global domain size in j direction' )
-         IF( ldwrt ) THEN
-            IF( inx   /= kdompar(1,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in local domain size in i direction' )
-            IF( iny   /= kdompar(2,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in local domain size in j direction' )
-         ENDIF
-         IF( inz   /= jpk          )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in domain size in k direction' )
-         IF( ipni  /= jpni         )   CALL ctl_stop( TRIM(clinfo), 'Processor splitting changed along I' )
-         IF( ipnj  /= jpnj         )   CALL ctl_stop( TRIM(clinfo), 'Processor splitting changed along J' )
-         IF( ipnij /= jpnij        )   CALL ctl_stop( TRIM(clinfo), 'Total number of processors changed' )
-         IF( iarea /= narea        )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in area numbering ...' )
-      ENDIF
-      ! fill file informations
-      ! =============
-      IF( istop == nstop ) THEN   ! no error within this routine
-!does not work with some compilers         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
-         kiomid = 0
-         DO jl = jpmax_files, 1, -1
-            IF( iom_file(jl)%nfid == 0 )   kiomid = jl
-         ENDDO
-         iom_file(kiomid)%name    = TRIM(cdname)
-         iom_file(kiomid)%nfid    = idrst
-         iom_file(kiomid)%iolib   = jprstdimg
-         iom_file(kiomid)%iduld   = -1
-         IF( ldok ) THEN      ! old file
-            ! read variables informations from the file header
-            IF(  TRIM(clna0d(1)) == 'no0d' )   in0d = 0
-            IF(  TRIM(clna1d(1)) == 'no1d' )   in1d = 0
-            IF(  TRIM(clna2d(1)) == 'no2d' )   in2d = 0
-            IF(  TRIM(clna3d(1)) == 'no3d' )   in3d = 0
-            ivnum = in0d + in1d + in2d + in3d
-            iom_file(kiomid)%nvars            = ivnum
-            iom_file(kiomid)%irec             = 2 + in1d + in2d + inz * in3d
-            iom_file(kiomid)%luld(   1:ivnum) = .FALSE.
-            iom_file(kiomid)%scf(    1:ivnum) = 1.
-            ! scalar variable
-            DO jv = 1, in0d
-               iom_file(kiomid)%cn_var(jv) = TRIM(clna0d(jv))
-               iom_file(kiomid)%nvid(  jv) = 1
-               iom_file(kiomid)%ndims( jv) = 0
-               iom_file(kiomid)%ofs(   jv) = zval0d(jv)   ! warning: trick... we use ofs to store the value
-            END DO
-            ! 1d variable
-            ishft = in0d
-            DO jv = 1, in1d
-               iom_file(kiomid)%cn_var(    ishft + jv) = TRIM(clna1d(jv))
-               iom_file(kiomid)%nvid(      ishft + jv) = zval1d(jv)
-               iom_file(kiomid)%ndims(     ishft + jv) = 1
-               iom_file(kiomid)%dimsz(1  , ishft + jv) = jpk
-               iom_file(kiomid)%ofs(       ishft + jv) = 0.
-            END DO
-            ! 2d variable
-            ishft = in0d + in1d
-            DO jv = 1, in2d
-               iom_file(kiomid)%cn_var(    ishft + jv) = TRIM(clna2d(jv))
-               iom_file(kiomid)%nvid(      ishft + jv) = zval2d(jv)
-               iom_file(kiomid)%ndims(     ishft + jv) = 2
-               iom_file(kiomid)%dimsz(1:2, ishft + jv) = (/ inx, iny /)
-               iom_file(kiomid)%ofs(       ishft + jv) = 0.
-            END DO
-            ! 3d variable
-            ishft = in0d + in1d + in2d 
-            DO jv = 1, in3d
-               iom_file(kiomid)%cn_var(    ishft + jv) = TRIM(clna3d(jv))
-               iom_file(kiomid)%nvid(      ishft + jv) = zval3d(jv)
-               iom_file(kiomid)%ndims(     ishft + jv) = 3
-               iom_file(kiomid)%dimsz(1:3, ishft + jv) = (/ inx, iny, jpk /)
-               iom_file(kiomid)%ofs(       ishft + jv) = 0.
-            END DO
-         ELSE                 ! new file
-            iom_file(kiomid)%nvars = 0
-            iom_file(kiomid)%irec  = 2
-            ! store file informations
-            WRITE( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, kdompar(:,1), jpk   ! store domain size
-         ENDIF
-      ENDIF
-987   CONTINUE
-      IF( ios /= 0 ) THEN
-         WRITE(ctmp1,*) '           iostat = ', ios
-         CALL ctl_stop( TRIM(clinfo), '   error in opening file '//TRIM(cdname), ctmp1 )
-      ENDIF
-      !
-   END SUBROUTINE iom_rstdimg_open
-
-
-   SUBROUTINE iom_rstdimg_close( kiomid )
-      !!--------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_rstdimg_close  ***
-      !!
-      !! ** Purpose : close an input file
-      !!--------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kiomid   ! iom identifier of the file to be closed
-      !
-      CHARACTER(LEN=100)                      ::   clinfo                     ! info character
-      INTEGER                                 ::   jv                         ! loop counter
-      INTEGER                                 ::   irecl8                     ! record length
-      INTEGER                                 ::   ios                        ! IO status
-      INTEGER                                 ::   irhd                       ! record of the header infos
-      INTEGER                                 ::   ivnum                      ! number of variables
-      INTEGER                                 ::   idrst                      ! file logical unit
-      INTEGER                                 ::   inx, iny, inz              ! x,y,z dimension of the variable
-      INTEGER                                 ::   in0d, in1d, in2d, in3d     ! number of 0/1/2/3D variables
-      CHARACTER(LEN=jpvnl), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d    ! name of 0/1/2/3D variables
-      REAL(wp),          DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d    ! value of 0d variables or record
-      !                                                                               ! position for 1/2/3D variables
-      !---------------------------------------------------------------------
-      !
-      clinfo = '                    iom_rstdimg_close ~~~  '
-      idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file
-      ! test if we can write in the file (test with INQUIRE gives alsways YES even with read only files...)
-      READ(  idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz   
-      WRITE( idrst, REC = 1, IOSTAT = ios            ) irecl8, inx, iny, inz   
-      ! We can write in the file => we update its header before closing
-      IF( ios == 0 ) THEN
-         READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz   ! get back domain size
-         irhd = iom_file(kiomid)%irec
-         ivnum = iom_file(kiomid)%nvars
-         in0d = 0   ;   in1d = 0   ;   in2d = 0   ;   in3d = 0
-         DO jv = 1, ivnum   ! loop on each variable to get its name and value/record position
-            SELECT CASE (iom_file(kiomid)%ndims(jv))
-            CASE (0)   ! scalar variable
-               in0d = in0d + 1
-               clna0d(in0d) = TRIM(iom_file(kiomid)%cn_var(jv))
-               zval0d(in0d) = iom_file(kiomid)%ofs(jv)   ! warning: trick... we use ofs to store the value
-            CASE (1)   ! 1d variable
-               in1d = in1d + 1
-               clna1d(in1d) = TRIM(iom_file(kiomid)%cn_var(jv))
-               zval1d(in1d) = iom_file(kiomid)%nvid(jv)
-            CASE (2)   ! 2d variable
-               in2d = in2d + 1
-               clna2d(in2d) = TRIM(iom_file(kiomid)%cn_var(jv))
-               zval2d(in2d) = iom_file(kiomid)%nvid(jv)
-            CASE (3)   ! 3d variable
-               in3d = in3d + 1
-               clna3d(in3d) = TRIM(iom_file(kiomid)%cn_var(jv))
-               zval3d(in3d) = iom_file(kiomid)%nvid(jv)
-            CASE DEFAULT   ;   CALL ctl_stop( TRIM(clinfo), 'Should not ne there...' )
-            END SELECT
-         END DO
-         ! force to have at least 1 variable in each list (not necessary (?), but safer...)
-         IF( in0d == 0 ) THEN   ;   in0d = 1   ;   clna0d(1) = 'no0d'   ;   zval0d(1) = -1.   ;   ENDIF
-         IF( in1d == 0 ) THEN   ;   in1d = 1   ;   clna1d(1) = 'no1d'   ;   zval1d(1) = -1.   ;   ENDIF
-         IF( in2d == 0 ) THEN   ;   in2d = 1   ;   clna2d(1) = 'no2d'   ;   zval2d(1) = -1.   ;   ENDIF
-         IF( in3d == 0 ) THEN   ;   in3d = 1   ;   clna3d(1) = 'no3d'   ;   zval3d(1) = -1.   ;   ENDIF
-         ! update the file header before closing it
-         WRITE( idrst, REC = 1, IOSTAT = ios, ERR = 987 )              &
-            &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd,   &
-            &   jpni, jpnj, jpnij, narea, jpiglo, jpjglo,              &
-            &   nlcit, nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt
-         IF( (ivnum * (jpvnl + wp)) > irecl8 ) THEN 
-            CALL ctl_stop( TRIM(clinfo),   &
-                 &   'Last record size is too big... You could reduce the value of jpvnl' )
-         ELSE 
-            WRITE( idrst, REC = irhd, IOSTAT = ios, ERR = 987 )                        &
-                 &   clna0d(1:in0d), zval0d(1:in0d), clna1d(1:in1d), zval1d(1:in1d),   &
-                 &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d)
-         ENDIF
-      ELSE
-         ios = 0   ! we cannot write in the file
-      ENDIF
-      !
-      CLOSE( idrst, IOSTAT = ios, ERR = 987 )
-987   CONTINUE
-      IF( ios /= 0 ) THEN
-         WRITE(ctmp1,*) '           iostat = ', ios
-         CALL ctl_stop( TRIM(clinfo),   &
-            &   '   error when updating the header of '//TRIM(iom_file(kiomid)%name), ctmp1 )
-      ENDIF
-      !    
-   END SUBROUTINE iom_rstdimg_close
-
-
-   SUBROUTINE iom_rstdimg_g0d( kiomid, kvid, pvar )
-      !!-----------------------------------------------------------------------
-      !!                  ***  ROUTINE  iom_rstdimg_g0d  ***
-      !!
-      !! ** Purpose : read a scalar with RSTDIMG
-      !!-----------------------------------------------------------------------
-      INTEGER,  INTENT(in   ) ::   kiomid    ! Identifier of the file
-      INTEGER,  INTENT(in   ) ::   kvid      ! variable id
-      REAL(wp), INTENT(  out) ::   pvar      ! read field
-      !---------------------------------------------------------------------
-      !
-      pvar = iom_file(kiomid)%ofs(kvid)   ! warning: trick... we use ofs to store the value
-      !
-   END SUBROUTINE iom_rstdimg_g0d
-
-
-   SUBROUTINE iom_rstdimg_rp0d( kiomid, cdvar, kvid, pv_r0d )
-      !!--------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_rstdimg_rstput  ***
-      !!
-      !! ** Purpose : write a scalar with RSTDIMG
-      !!--------------------------------------------------------------------
-      INTEGER                   , INTENT(in) ::   kiomid   ! Identifier of the file 
-      CHARACTER(len=*)          , INTENT(in) ::   cdvar    ! time axis name
-      INTEGER                   , INTENT(in) ::   kvid     ! variable id
-      REAL(wp)                  , INTENT(in) ::   pv_r0d   ! written 0d field
-      !
-      CHARACTER(LEN=100) ::   clinfo     ! info character
-      INTEGER            ::   idvar      ! variable id
-      !---------------------------------------------------------------------
-      !  
-      clinfo = '                    iom_rstdimg_rp0d ~~~  '
-      IF( kvid <= 0 ) THEN   !   new variable
-         idvar = iom_file(kiomid)%nvars + 1
-      ELSE                   !   the variable already exists in the file
-         idvar = kvid
-      ENDIF
-      IF( idvar <= jpmax_vars ) THEN
-         iom_file(kiomid)%nvars = idvar
-         iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar)
-         iom_file(kiomid)%nvid(   idvar) = 1   ! useless, Od variables a strored in record 1
-         iom_file(kiomid)%ndims(  idvar) = 0
-         iom_file(kiomid)%luld(   idvar) = .FALSE.
-         iom_file(kiomid)%scf(    idvar) = 1.
-         iom_file(kiomid)%ofs(    idvar) = pv_r0d   ! warning: trick... we use ofs to store the value
-      ELSE
-         CALL ctl_stop( TRIM(clinfo), 'increase the value of jpmax_vars' )
-      ENDIF
-   END SUBROUTINE iom_rstdimg_rp0d
-
-
-   SUBROUTINE iom_rstdimg_g123d( kiomid, kdom  , kvid, kx1, kx2, ky1, ky2,   &
-         &                       pv_r1d, pv_r2d, pv_r3d )
-      !!-----------------------------------------------------------------------
-      !!                  ***  ROUTINE  iom_rstdimg_g123d  ***
-      !!
-      !! ** Purpose : read a 1D/2D/3D variable with RSTDIMG
-      !!
-      !! ** Method : read ONE record at each CALL
-      !!-----------------------------------------------------------------------
-      INTEGER                    , INTENT(in   )           ::   kiomid     ! iom identifier of the file
-      INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read
-      INTEGER                    , INTENT(in   )           ::   kvid       ! variable id
-      INTEGER ,                    INTENT(inout)           ::   kx1, kx2, ky1, ky2   ! subdomain indexes
-      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
-      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
-      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
-
-      CHARACTER(LEN=100) ::   clinfo               ! info character
-      INTEGER            ::   ios                  ! IO status
-      INTEGER            ::   jk                   ! loop counter
-      INTEGER            ::   idrst                ! logical unit of the restart file
-      !---------------------------------------------------------------------
-      clinfo = '                    iom_rstdimg_g123d ~~~  '
-      !
-      IF( kdom == jpdom_data .OR. kdom == jpdom_global ) THEN
-         CALL ctl_stop( TRIM(clinfo), TRIM(iom_file(kiomid)%cn_var(kvid))//': case not coded for rstdimg files' )
-      ELSE
-      !
-         idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file
-         ! modify the subdomain indexes because we cannot directly extract the appropriate subdomaine
-         IF(     kdom == jpdom_local_full    ) THEN   ;   kx1 = 1   ;   kx2 = jpi    ;   ky1 = 1
-         ELSEIF( kdom == jpdom_local_noextra ) THEN   ;   kx1 = 1   ;   kx2 = nlci   ;   ky1 = 1
-         ENDIF
-         !
-         IF(     PRESENT(pv_r1d) ) THEN   ! read 1D variables
-            READ(    idrst, REC = iom_file(kiomid)%nvid(kvid)         , IOSTAT = ios, ERR = 987 )   pv_r1d(:)
-         ELSEIF( PRESENT(pv_r2d) ) THEN   ! read 2D variables
-            READ(    idrst, REC = iom_file(kiomid)%nvid(kvid)         , IOSTAT = ios, ERR = 987 )   pv_r2d(kx1:kx2, ky1:ky2    )
-         ELSEIF( PRESENT(pv_r3d) ) THEN   ! read 3D variables
-            DO jk = 1, iom_file(kiomid)%dimsz(3,kvid)   ! do loop on each level
-               READ( idrst, REC = iom_file(kiomid)%nvid(kvid) + jk - 1, IOSTAT = ios, ERR = 987 )   pv_r3d(kx1:kx2, ky1:ky2, jk)
-            END DO
-         ENDIF
-987      CONTINUE
-         IF( ios /= 0 ) THEN
-            WRITE(ctmp1,*) '           iostat = ', ios
-            CALL ctl_stop( TRIM(clinfo), '   IO error with file '//TRIM(iom_file(kiomid)%name), ctmp1 )
-         ENDIF
-      ENDIF
-      !
-   END SUBROUTINE iom_rstdimg_g123d
-
-
-   SUBROUTINE iom_rstdimg_rp123d( kiomid, cdvar, kvid, pv_r1d, pv_r2d, pv_r3d )
-      !!--------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_rstdimg_rstput  ***
-      !!
-      !! ** Purpose : write a 2D/3D variable with RSTDIMG
-      !!--------------------------------------------------------------------
-      INTEGER                         , INTENT(in)           ::   kiomid   ! Identifier of the file 
-      CHARACTER(len=*)                , INTENT(in)           ::   cdvar    ! time axis name
-      INTEGER                         , INTENT(in)           ::   kvid     ! variable id
-      REAL(wp), DIMENSION(          :), INTENT(in), OPTIONAL ::   pv_r1d   ! written 1d field
-      REAL(wp), DIMENSION(:  ,:      ), INTENT(in), OPTIONAL ::   pv_r2d   ! written 2d field
-      REAL(wp), DIMENSION(:  ,:  ,:  ), INTENT(in), OPTIONAL ::   pv_r3d   ! written 3d field
-      !
-      CHARACTER(LEN=100)    ::   clinfo               ! info character
-      INTEGER               ::   irecl8               ! reacord length
-      INTEGER               ::   ios                  ! IO status
-      INTEGER               ::   idrst                ! reacord length
-      INTEGER               ::   inx, iny, inz        ! x,y,z dimension of the variable
-      INTEGER               ::   idvar                ! variable id
-      INTEGER               ::   istop                ! temporary storage of nstop
-      INTEGER               ::   irec                 ! record number
-      INTEGER               ::   ix1, ix2, iy1, iy2   ! subdomain indexes
-      INTEGER               ::   jk                   ! loop counter
-      !---------------------------------------------------------------------
-      !
-      clinfo = '          iom_rstdimg_rp123d, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar)
-      istop = nstop                   ! store the actual value of nstop
-      irec = iom_file(kiomid)%irec    ! get back the record number of the variable
-      idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file
-      IF( kvid <= 0 ) THEN   !   new variable
-         idvar = iom_file(kiomid)%nvars + 1
-      ELSE                   !   the variable already exists in the file
-         idvar = kvid
-      ENDIF
-      IF( idvar > jpmax_vars )   CALL ctl_stop( TRIM(clinfo), 'increase the value of jpmax_vars' )
-      IF( .NOT. PRESENT(pv_r1d) ) THEN
-         ! find which part of data must be written
-         READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz
-         IF(     inx == (nlei - nldi + 1) .AND. iny == (nlej - nldj + 1) ) THEN
-            ix1 = nldi   ;   ix2 = nlei   ;   iy1 = nldj   ;   iy2 = nlej
-         ELSEIF( inx == nlci              .AND. iny == nlcj              ) THEN
-            ix1 = 1      ;   ix2 = nlci   ;   iy1 = 1      ;   iy2 = nlcj
-         ELSEIF( inx == jpi               .AND. iny == jpj               ) THEN
-            ix1 = 1      ;   ix2 = jpi    ;   iy1 = 1      ;   iy2 = jpj
-         ELSE 
-            CALL ctl_stop( clinfo, 'should have been an impossible case...' )
-         ENDIF
-      ENDIF
-      IF( istop == nstop ) THEN
-         ! write the data
-         IF(     PRESENT(pv_r1d) ) THEN   ! 1D variable
-            WRITE( idrst, REC = irec            , IOSTAT = ios, ERR = 987 ) pv_r1d(:)
-         ELSEIF( PRESENT(pv_r2d) ) THEN   ! 2D variable
-            WRITE( idrst, REC = irec            , IOSTAT = ios, ERR = 987 ) pv_r2d(ix1:ix2, iy1:iy2    )
-         ELSEIF( PRESENT(pv_r3d) ) THEN   ! 3D variable
-            DO jk = 1, jpk   ! do loop on each level
-               WRITE( idrst, REC = irec + jk - 1, IOSTAT = ios, ERR = 987 ) pv_r3d(ix1:ix2, iy1:iy2, jk)
-            END DO
-         ENDIF
-         ! fill the file informations
-         iom_file(kiomid)%nvars = idvar
-         IF(     PRESENT(pv_r1d) ) THEN
-            iom_file(kiomid)%irec              = irec + 1
-            iom_file(kiomid)%ndims(     idvar) = 1
-            iom_file(kiomid)%dimsz(1  , idvar) = inz
-         ELSEIF( PRESENT(pv_r2d) ) THEN
-            iom_file(kiomid)%irec              = irec + 1
-            iom_file(kiomid)%ndims(     idvar) = 2
-            iom_file(kiomid)%dimsz(1:2, idvar) = (/ inx, iny /)
-         ELSEIF( PRESENT(pv_r3d) ) THEN
-            iom_file(kiomid)%irec              = irec + inz
-            iom_file(kiomid)%ndims(     idvar) = 3
-            iom_file(kiomid)%dimsz(1:3, idvar) = (/ inx, iny, inz /)
-         ENDIF
-         iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar)
-         iom_file(kiomid)%nvid(  idvar) = irec
-         iom_file(kiomid)%luld(  idvar) = .FALSE.
-         iom_file(kiomid)%scf(   idvar) = 1.
-         iom_file(kiomid)%ofs(   idvar) = 0.
-      ENDIF
-987   CONTINUE
-      IF( ios /= 0 ) THEN
-         WRITE(ctmp1,*) '           iostat = ', ios
-         CALL ctl_stop( TRIM(clinfo), '   IO error with file '//TRIM(iom_file(kiomid)%name), ctmp1 )
-      ELSE
-         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' written ok'
-      ENDIF
-      !     
-   END SUBROUTINE iom_rstdimg_rp123d
-
-
-   !!======================================================================
-END MODULE iom_rstdimg
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 6140)
@@ -27,5 +27,6 @@
    USE in_out_manager  ! I/O manager
    USE iom             ! I/O module
-
+   USE diurnal_bulk
+   
    IMPLICIT NONE
    PRIVATE
@@ -37,5 +38,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -95,6 +95,4 @@
                WRITE(numout,*)
                SELECT CASE ( jprstlib )
-               CASE ( jprstdimg )   ;   WRITE(numout,*)                            &
-                   '             open ocean restart binary file: ',TRIM(clpath)//clname
                CASE DEFAULT         ;   WRITE(numout,*)                            &
                    '             open ocean restart NetCDF file: ',TRIM(clpath)//clname
@@ -126,7 +124,7 @@
       !!----------------------------------------------------------------------
 
-                     CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rdt       )   ! dynamics time step
-                     CALL iom_rstput( kt, nitrst, numrow, 'rdttra1', rdttra(1) )   ! surface tracer time step
-
+                     CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rdt       )   ! dynamics and tracer time step
+
+      IF ( .NOT. ln_diurnal_only ) THEN
                      CALL iom_rstput( kt, nitrst, numrow, 'ub'     , ub        )     ! before fields
                      CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vb        )
@@ -141,4 +139,20 @@
                      CALL iom_rstput( kt, nitrst, numrow, 'sshn'   , sshn      )
                      CALL iom_rstput( kt, nitrst, numrow, 'rhop'   , rhop      )
+
+                  ! extra variable needed for the ice sheet coupling
+                  IF ( ln_iscpl ) THEN 
+                     CALL iom_rstput( kt, nitrst, numrow, 'tmask'  , tmask     ) ! need to extrapolate T/S
+                     CALL iom_rstput( kt, nitrst, numrow, 'umask'  , umask     ) ! need to correct barotropic velocity
+                     CALL iom_rstput( kt, nitrst, numrow, 'vmask'  , vmask     ) ! need to correct barotropic velocity
+                     CALL iom_rstput( kt, nitrst, numrow, 'smask'  , ssmask    ) ! need to correct barotropic velocity
+                     CALL iom_rstput( kt, nitrst, numrow, 'e3t_n', e3t_n(:,:,:) )   ! need to compute temperature correction
+                     CALL iom_rstput( kt, nitrst, numrow, 'e3u_n', e3u_n(:,:,:) )   ! need to compute bt conservation
+                     CALL iom_rstput( kt, nitrst, numrow, 'e3v_n', e3v_n(:,:,:) )   ! need to compute bt conservation
+                     CALL iom_rstput( kt, nitrst, numrow, 'gdepw_n', gdepw_n(:,:,:) ) ! need to compute extrapolation if vvl
+                  END IF
+      ENDIF
+      
+      IF (ln_diurnal) CALL iom_rstput( kt, nitrst, numrow, 'Dsst', x_dsst    )  
+
       IF( kt == nitrst ) THEN
          CALL iom_close( numrow )     ! close the restart file (only at last time step)
@@ -175,5 +189,4 @@
             SELECT CASE ( jprstlib )
             CASE ( jpnf90    )   ;   WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
-            CASE ( jprstdimg )   ;   WRITE(numout,*) 'rst_read : read oce binary restart file'
             END SELECT
             IF ( snc4set%luse )      WRITE(numout,*) 'rst_read : configured with NetCDF4 support'
@@ -183,10 +196,4 @@
          clpath = TRIM(cn_ocerst_indir)
          IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
-         IF ( jprstlib == jprstdimg ) THEN
-           ! eventually read netcdf file (monobloc)  for restarting on different number of processors
-           ! if {cn_ocerst_in}.nc exists, then set jlibalt to jpnf90
-           INQUIRE( FILE = TRIM(cn_ocerst_indir)//'/'//TRIM(cn_ocerst_in)//'.nc', EXIST = llok )
-           IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
-         ENDIF
          CALL iom_open( TRIM(clpath)//cn_ocerst_in, numror, kiolib = jlibalt )
       ENDIF
@@ -202,7 +209,6 @@
       !! ** Method  :   Read in restart.nc file fields which are necessary for restart
       !!----------------------------------------------------------------------
-      REAL(wp) ::   zrdt, zrdttra1
+      REAL(wp) ::   zrdt
       INTEGER  ::   jk
-      LOGICAL  ::   llok
       !!----------------------------------------------------------------------
 
@@ -214,9 +220,15 @@
          IF( zrdt /= rdt )   neuler = 0
       ENDIF
-      IF( iom_varid( numror, 'rdttra1', ldstop = .FALSE. ) > 0 )   THEN
-         CALL iom_get( numror, 'rdttra1', zrdttra1 )
-         IF( zrdttra1 /= rdttra(1) )   neuler = 0
-      ENDIF
-      ! 
+
+      ! Diurnal DSST 
+      IF( ln_diurnal ) CALL iom_get( numror, jpdom_autoglo, 'Dsst' , x_dsst  ) 
+      IF ( ln_diurnal_only ) THEN 
+         IF(lwp) WRITE( numout, * ) &
+         &   "rst_read:- ln_diurnal_only set, setting rhop=rau0" 
+         rhop = rau0
+         CALL iom_get( numror, jpdom_autoglo, 'tn'     , tsn(:,:,1,jp_tem) ) 
+         RETURN 
+      ENDIF  
+      
       IF( iom_varid( numror, 'ub', ldstop = .FALSE. ) > 0 ) THEN
          CALL iom_get( numror, jpdom_autoglo, 'ub'     , ub      )   ! before fields
@@ -237,5 +249,5 @@
          CALL iom_get( numror, jpdom_autoglo, 'rhop'   , rhop    )   ! now    potential density
       ELSE
-         CALL eos    ( tsn, rhd, rhop, fsdept_n(:,:,:) )   
+         CALL eos( tsn, rhd, rhop, gdept_n(:,:,:) )   
       ENDIF
       !
@@ -246,7 +258,7 @@
          sshb (:,:)     = sshn (:,:)
          !
-         IF( lk_vvl ) THEN
+         IF( .NOT.ln_linssh ) THEN
             DO jk = 1, jpk
-               fse3t_b(:,:,jk) = fse3t_n(:,:,jk)
+               e3t_b(:,:,jk) = e3t_n(:,:,jk)
             END DO
          ENDIF
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90	(revision 6140)
@@ -4,11 +4,9 @@
    !! Ocean        : lateral boundary conditions
    !!=====================================================================
-   !! History :  OPA  ! 1997-06  (G. Madec)     Original code
-   !!   NEMO     1.0  ! 2002-09  (G. Madec)     F90: Free form and module
+   !! History :  OPA  ! 1997-06  (G. Madec)  Original code
+   !!   NEMO     1.0  ! 2002-09  (G. Madec)  F90: Free form and module
    !!            3.2  ! 2009-03  (R. Benshila)  External north fold treatment  
-   !!            3.5  ! 2012     (S.Mocavero, I. Epicoco) Add 'lbc_bdy_lnk' 
-   !!                            and lbc_obc_lnk' routine to optimize  
-   !!                            the BDY/OBC communications
-   !!            3.4  ! 2012-12  (R. Bourdalle-Badie and G. Reffray)  add a C1D case  
+   !!            3.5  ! 2012     (S.Mocavero, I. Epicoco) optimization of BDY comm. via lbc_bdy_lnk and lbc_obc_lnk
+   !!            3.4  ! 2012-12  (R. Bourdalle-Badie, G. Reffray)  add a C1D case  
    !!----------------------------------------------------------------------
 #if defined key_mpp_mpi
@@ -17,35 +15,41 @@
    !!----------------------------------------------------------------------
    !!   lbc_lnk      : generic interface for mpp_lnk_3d and mpp_lnk_2d routines defined in lib_mpp
+   !!   lbc_sum      : generic interface for mpp_lnk_sum_3d and mpp_lnk_sum_2d routines defined in lib_mpp
    !!   lbc_lnk_e    : generic interface for mpp_lnk_2d_e routine defined in lib_mpp
    !!   lbc_bdy_lnk  : generic interface for mpp_lnk_bdy_2d and mpp_lnk_bdy_3d routines defined in lib_mpp
    !!----------------------------------------------------------------------
-   USE lib_mpp          ! distributed memory computing library
-
+   USE lib_mpp        ! distributed memory computing library
 
    INTERFACE lbc_lnk_multi
       MODULE PROCEDURE mpp_lnk_2d_9
    END INTERFACE
-
+   !
    INTERFACE lbc_lnk
       MODULE PROCEDURE mpp_lnk_3d_gather, mpp_lnk_3d, mpp_lnk_2d
    END INTERFACE
+   !
+!JMM interface not defined if not key_mpp_mpi : likely do not compile without this CPP key !!!!
+   INTERFACE lbc_sum
+      MODULE PROCEDURE mpp_lnk_sum_3d, mpp_lnk_sum_2d
+   END INTERFACE
 
    INTERFACE lbc_bdy_lnk
       MODULE PROCEDURE mpp_lnk_bdy_2d, mpp_lnk_bdy_3d
    END INTERFACE
-
+   !
    INTERFACE lbc_lnk_e
       MODULE PROCEDURE mpp_lnk_2d_e
    END INTERFACE
-
+   !
    INTERFACE lbc_lnk_icb
       MODULE PROCEDURE mpp_lnk_2d_icb
    END INTERFACE
 
-   PUBLIC lbc_lnk       ! ocean lateral boundary conditions
-   PUBLIC lbc_lnk_multi ! modified ocean lateral boundary conditions
-   PUBLIC lbc_lnk_e
-   PUBLIC lbc_bdy_lnk   ! ocean lateral BDY boundary conditions
-   PUBLIC lbc_lnk_icb
+   PUBLIC   lbc_lnk       ! ocean lateral boundary conditions
+   PUBLIC   lbc_lnk_multi ! modified ocean lateral boundary conditions
+   PUBLIC   lbc_sum
+   PUBLIC   lbc_lnk_e     !
+   PUBLIC   lbc_bdy_lnk   ! ocean lateral BDY boundary conditions
+   PUBLIC   lbc_lnk_icb   !
 
    !!----------------------------------------------------------------------
@@ -54,13 +58,15 @@
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 #else
    !!----------------------------------------------------------------------
    !!   Default option                              shared memory computing
    !!----------------------------------------------------------------------
-   !!   lbc_lnk      : generic interface for lbc_lnk_3d and lbc_lnk_2d
-   !!   lbc_lnk_3d   : set the lateral boundary condition on a 3D variable on ocean mesh
-   !!   lbc_lnk_2d   : set the lateral boundary condition on a 2D variable on ocean mesh
-   !!   lbc_bdy_lnk  : set the lateral BDY boundary condition
+   !!   lbc_sum       : generic interface for mpp_lnk_sum_3d and mpp_lnk_sum_2d 
+   !!   lbc_lnk_sum_3d: compute sum over the halos on a 3D variable on ocean mesh
+   !!   lbc_lnk_sum_3d: compute sum over the halos on a 2D variable on ocean mesh
+   !!   lbc_lnk       : generic interface for lbc_lnk_3d and lbc_lnk_2d
+   !!   lbc_lnk_3d    : set the lateral boundary condition on a 3D variable on ocean mesh
+   !!   lbc_lnk_2d    : set the lateral boundary condition on a 2D variable on ocean mesh
+   !!   lbc_bdy_lnk   : set the lateral BDY boundary condition
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers   
@@ -75,13 +81,17 @@
       MODULE PROCEDURE lbc_lnk_3d_gather, lbc_lnk_3d, lbc_lnk_2d
    END INTERFACE
+   !
+   INTERFACE lbc_sum
+      MODULE PROCEDURE mpp_lnk_sum_3d, mpp_lnk_sum_2d
+   END INTERFACE
 
    INTERFACE lbc_lnk_e
       MODULE PROCEDURE lbc_lnk_2d_e
    END INTERFACE
-
+   !
    INTERFACE lbc_bdy_lnk
       MODULE PROCEDURE lbc_bdy_lnk_2d, lbc_bdy_lnk_3d
    END INTERFACE
-
+   !
    INTERFACE lbc_lnk_icb
       MODULE PROCEDURE lbc_lnk_2d_e
@@ -89,10 +99,10 @@
 
    PUBLIC   lbc_lnk       ! ocean/ice  lateral boundary conditions
-   PUBLIC   lbc_lnk_e 
+   PUBLIC   lbc_lnk_e     !
    PUBLIC   lbc_bdy_lnk   ! ocean lateral BDY boundary conditions
-   PUBLIC   lbc_lnk_icb
+   PUBLIC   lbc_lnk_icb   !
    
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -230,5 +240,4 @@
          ! this is in mpp case. In this module, just do nothing
       ELSE
-         !
          !                                     !  East-West boundaries
          !                                     ! ======================
@@ -249,5 +258,4 @@
             !
          END SELECT
-         !
          !                                     ! North-South boundaries
          !                                     ! ======================
@@ -287,4 +295,5 @@
    END SUBROUTINE lbc_lnk_3d
 
+
    SUBROUTINE lbc_lnk_2d( pt2d, cd_type, psgn, cd_mpp, pval )
       !!---------------------------------------------------------------------
@@ -316,5 +325,4 @@
          ! this is in mpp case. In this module, just do nothing
       ELSE      
-         !
          !                                     ! East-West boundaries
          !                                     ! ====================
@@ -335,5 +343,4 @@
             !
          END SELECT
-         !
          !                                     ! North-South boundaries
          !                                     ! ======================
@@ -375,5 +382,4 @@
 #endif
 
-
    SUBROUTINE lbc_bdy_lnk_3d( pt3d, cd_type, psgn, ib_bdy )
       !!---------------------------------------------------------------------
@@ -381,17 +387,18 @@
       !!
       !! ** Purpose :   wrapper rountine to 'lbc_lnk_3d'. This wrapper is used
-      !!                to maintain the same interface with regards to the mpp
-      !case
-      !!
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)                , INTENT(in   )           ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout)           ::   pt3d      ! 3D array on which the lbc is applied
-      REAL(wp)                        , INTENT(in   )           ::   psgn      ! control of the sign 
-      INTEGER                                                   ::   ib_bdy    ! BDY boundary set
-      !!
+      !!              to maintain the same interface with regards to the mpp case
+      !!
+      !!----------------------------------------------------------------------
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pt3d      ! 3D array on which the lbc is applied
+      REAL(wp)                        , INTENT(in   ) ::   psgn      ! control of the sign 
+      INTEGER                         , INTENT(in   ) ::   ib_bdy    ! BDY boundary set
+      !!----------------------------------------------------------------------
+      !
       CALL lbc_lnk_3d( pt3d, cd_type, psgn)
-
+      !
    END SUBROUTINE lbc_bdy_lnk_3d
 
+
    SUBROUTINE lbc_bdy_lnk_2d( pt2d, cd_type, psgn, ib_bdy )
       !!---------------------------------------------------------------------
@@ -399,15 +406,15 @@
       !!
       !! ** Purpose :   wrapper rountine to 'lbc_lnk_3d'. This wrapper is used
-      !!                to maintain the same interface with regards to the mpp
-      !case
-      !!
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)                , INTENT(in   )           ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj),     INTENT(inout)           ::   pt2d      ! 3D array on which the lbc is applied
-      REAL(wp)                        , INTENT(in   )           ::   psgn      ! control of the sign 
-      INTEGER                                                   ::   ib_bdy    ! BDY boundary set
-      !!
+      !!              to maintain the same interface with regards to the mpp case
+      !!
+      !!----------------------------------------------------------------------
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d      ! 3D array on which the lbc is applied
+      REAL(wp)                    , INTENT(in   ) ::   psgn      ! control of the sign 
+      INTEGER                     , INTENT(in   ) ::   ib_bdy    ! BDY boundary set
+      !!----------------------------------------------------------------------
+      !
       CALL lbc_lnk_2d( pt2d, cd_type, psgn)
-
+      !
    END SUBROUTINE lbc_bdy_lnk_2d
 
@@ -426,11 +433,11 @@
       !!                             for closed boundaries.
       !!----------------------------------------------------------------------
-      CHARACTER(len=1)            , INTENT(in   )           ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout)           ::   pt2d      ! 2D array on which the lbc is applied
-      REAL(wp)                    , INTENT(in   )           ::   psgn      ! control of the sign 
-      INTEGER                     , INTENT(in   )           ::   jpri      ! size of extra halo (not needed in non-mpp)
-      INTEGER                     , INTENT(in   )           ::   jprj      ! size of extra halo (not needed in non-mpp)
-      !!----------------------------------------------------------------------
-
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d      ! 2D array on which the lbc is applied
+      REAL(wp)                    , INTENT(in   ) ::   psgn      ! control of the sign 
+      INTEGER                     , INTENT(in   ) ::   jpri      ! size of extra halo (not needed in non-mpp)
+      INTEGER                     , INTENT(in   ) ::   jprj      ! size of extra halo (not needed in non-mpp)
+      !!----------------------------------------------------------------------
+      !
       CALL lbc_lnk_2d( pt2d, cd_type, psgn )
       !    
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/lbcnfd.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/lbcnfd.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/lbcnfd.F90	(revision 6140)
@@ -24,17 +24,15 @@
       MODULE PROCEDURE   lbc_nfd_3d, lbc_nfd_2d
    END INTERFACE
-
-   PUBLIC   lbc_nfd   ! north fold conditions
+   !
    INTERFACE mpp_lbc_nfd
       MODULE PROCEDURE   mpp_lbc_nfd_3d, mpp_lbc_nfd_2d
    END INTERFACE
 
-   PUBLIC   mpp_lbc_nfd   ! north fold conditions in parallel case
-
-   INTEGER, PUBLIC,  PARAMETER :: jpmaxngh = 3
-   INTEGER, PUBLIC                                  ::   nsndto, nfsloop, nfeloop
-   INTEGER, PUBLIC,  DIMENSION (jpmaxngh)           ::   isendto ! processes to which communicate
-
-
+   PUBLIC   lbc_nfd       ! north fold conditions
+   PUBLIC   mpp_lbc_nfd   ! north fold conditions (parallel case)
+
+   INTEGER, PUBLIC, PARAMETER            ::   jpmaxngh = 3               !:
+   INTEGER, PUBLIC                       ::   nsndto, nfsloop, nfeloop   !:
+   INTEGER, PUBLIC, DIMENSION (jpmaxngh) ::   isendto                    !: processes to which communicate
 
    !!----------------------------------------------------------------------
@@ -391,12 +389,12 @@
       REAL(wp)                  , INTENT(in   ) ::   psgn      ! control of the sign change
       !                                                        !   = -1. , the sign is changed if north fold boundary
-      !                                                        !   =  1. , the sign is kept  if north fold boundary
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pt3dl      ! 3D array on which the boundary condition is applied
-      REAL(wp), DIMENSION(:,:,:), INTENT(in) ::   pt3dr      ! 3D array on which the boundary condition is applied
+      !                                                        !   =  1. , the sign is kept    if north fold boundary
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pt3dl     ! 3D array on which the boundary condition is applied
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pt3dr     ! 3D array on which the boundary condition is applied
       !
       INTEGER  ::   ji, jk
       INTEGER  ::   ijt, iju, ijpj, ijpjm1, ijta, ijua, jia, startloop, endloop
       !!----------------------------------------------------------------------
-
+      !
       SELECT CASE ( jpni )
       CASE ( 1 )     ;   ijpj = nlcj      ! 1 proc only  along the i-direction
@@ -657,6 +655,6 @@
       !                                                      !   = -1. , the sign is changed if north fold boundary
       !                                                      !   =  1. , the sign is kept  if north fold boundary
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2dl      ! 2D array on which the boundary condition is applied
-      REAL(wp), DIMENSION(:,:), INTENT(in) ::   pt2dr      ! 2D array on which the boundary condition is applied
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2dl     ! 2D array on which the boundary condition is applied
+      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   pt2dr     ! 2D array on which the boundary condition is applied
       !
       INTEGER  ::   ji
@@ -970,3 +968,4 @@
    END SUBROUTINE mpp_lbc_nfd_2d
 
+   !!======================================================================
 END MODULE lbcnfd
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 6140)
@@ -23,13 +23,13 @@
    !!                          the mppobc routine to optimize the BDY and OBC communications
    !!            3.5  !  2013  ( C. Ethe, G. Madec ) message passing arrays as local variables 
-   !!            3.5  !  2013 (S.Mocavero, I.Epicoco - CMCC) north fold optimizations
+   !!            3.5  !  2013  (S.Mocavero, I.Epicoco - CMCC) north fold optimizations
    !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
-   !!   ctl_stop   : update momentum and tracer Kz from a tke scheme
-   !!   ctl_warn   : initialization, namelist read, and parameters control
-   !!   ctl_opn    : Open file and check if required file is available.
-   !!   ctl_nam    : Prints informations when an error occurs while reading a namelist
-   !!   get_unit   : give the index of an unused logical unit
+   !!   ctl_stop      : update momentum and tracer Kz from a tke scheme
+   !!   ctl_warn      : initialization, namelist read, and parameters control
+   !!   ctl_opn       : Open file and check if required file is available.
+   !!   ctl_nam       : Prints informations when an error occurs while reading a namelist
+   !!   get_unit      : give the index of an unused logical unit
    !!----------------------------------------------------------------------
 #if   defined key_mpp_mpi
@@ -43,5 +43,5 @@
    !!   mpp_lnk_e     : interface (defined in lbclnk) for message passing of 2d array with extra halo (mpp_lnk_2d_e)
    !!   mpp_lnk_icb   : interface for message passing of 2d arrays with extra halo for icebergs (mpp_lnk_2d_icb)
-   !!   mpprecv         :
+   !!   mpprecv       :
    !!   mppsend       :   SUBROUTINE mpp_ini_znl
    !!   mppscatter    :
@@ -72,4 +72,5 @@
    PUBLIC   mpp_lnk_3d, mpp_lnk_3d_gather, mpp_lnk_2d, mpp_lnk_2d_e
    PUBLIC   mpp_lnk_2d_9 
+   PUBLIC   mpp_lnk_sum_3d, mpp_lnk_sum_2d
    PUBLIC   mppscatter, mppgather
    PUBLIC   mpp_ini_ice, mpp_ini_znl
@@ -94,5 +95,5 @@
    END INTERFACE
    INTERFACE mpp_sum
-      MODULE PROCEDURE mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real, &
+      MODULE PROCEDURE mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real,   &
                        mppsum_realdd, mppsum_a_realdd
    END INTERFACE
@@ -175,11 +176,11 @@
       !! ** Purpose :   Find processor unit
       !!----------------------------------------------------------------------
-      CHARACTER(len=*),DIMENSION(:), INTENT(  out) ::   ldtxt
-      CHARACTER(len=*)             , INTENT(in   ) ::   ldname
-      INTEGER                      , INTENT(in   ) ::   kumnam_ref     ! logical unit for reference namelist
-      INTEGER                      , INTENT(in   ) ::   kumnam_cfg     ! logical unit for configuration namelist
-      INTEGER                      , INTENT(inout) ::   kumond         ! logical unit for namelist output
-      INTEGER                      , INTENT(inout) ::   kstop          ! stop indicator
-      INTEGER, OPTIONAL            , INTENT(in   ) ::   localComm
+      CHARACTER(len=*),DIMENSION(:), INTENT(  out) ::   ldtxt        !
+      CHARACTER(len=*)             , INTENT(in   ) ::   ldname       !
+      INTEGER                      , INTENT(in   ) ::   kumnam_ref   ! logical unit for reference namelist
+      INTEGER                      , INTENT(in   ) ::   kumnam_cfg   ! logical unit for configuration namelist
+      INTEGER                      , INTENT(inout) ::   kumond       ! logical unit for namelist output
+      INTEGER                      , INTENT(inout) ::   kstop        ! stop indicator
+      INTEGER         , OPTIONAL   , INTENT(in   ) ::   localComm    !
       !
       INTEGER ::   mynode, ierr, code, ji, ii, ios
@@ -190,7 +191,7 @@
       !
       ii = 1
-      WRITE(ldtxt(ii),*)                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'mynode : mpi initialisation'                                            ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~ '                                                                ;   ii = ii + 1
+      WRITE(ldtxt(ii),*)                                                                  ;   ii = ii + 1
+      WRITE(ldtxt(ii),*) 'mynode : mpi initialisation'                                    ;   ii = ii + 1
+      WRITE(ldtxt(ii),*) '~~~~~~ '                                                        ;   ii = ii + 1
       !
 
@@ -204,7 +205,7 @@
 
       !                              ! control print
-      WRITE(ldtxt(ii),*) '   Namelist nammpp'                                                     ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      mpi send type                      cn_mpi_send = ', cn_mpi_send   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      size in bytes of exported buffer   nn_buffer   = ', nn_buffer     ;   ii = ii + 1
+      WRITE(ldtxt(ii),*) '   Namelist nammpp'                                             ;   ii = ii + 1
+      WRITE(ldtxt(ii),*) '      mpi send type          cn_mpi_send = ', cn_mpi_send       ;   ii = ii + 1
+      WRITE(ldtxt(ii),*) '      size exported buffer   nn_buffer   = ', nn_buffer,' bytes';   ii = ii + 1
 
 #if defined key_agrif
@@ -223,9 +224,9 @@
 
       IF( (jpni < 1) .OR. (jpnj < 1) )THEN
-         WRITE(ldtxt(ii),*) '      jpni, jpnj and jpnij will be calculated automatically'; ii = ii + 1
+         WRITE(ldtxt(ii),*) '      jpni, jpnj and jpnij will be calculated automatically' ;   ii = ii + 1
       ELSE
-         WRITE(ldtxt(ii),*) '      processor grid extent in i         jpni = ',jpni; ii = ii + 1
-         WRITE(ldtxt(ii),*) '      processor grid extent in j         jpnj = ',jpnj; ii = ii + 1
-         WRITE(ldtxt(ii),*) '      number of local domains           jpnij = ',jpnij; ii = ii +1
+         WRITE(ldtxt(ii),*) '      processor grid extent in i         jpni = ',jpni       ;   ii = ii + 1
+         WRITE(ldtxt(ii),*) '      processor grid extent in j         jpnj = ',jpnj       ;   ii = ii + 1
+         WRITE(ldtxt(ii),*) '      number of local domains           jpnij = ',jpnij      ;   ii = ii + 1
       END IF
 
@@ -246,35 +247,35 @@
          SELECT CASE ( cn_mpi_send )
          CASE ( 'S' )                ! Standard mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'                     ;   ii = ii + 1
+            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'             ;   ii = ii + 1
          CASE ( 'B' )                ! Buffer mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'                      ;   ii = ii + 1
+            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'              ;   ii = ii + 1
             IF( Agrif_Root() )   CALL mpi_init_opa( ldtxt, ii, ierr )
          CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'                   ;   ii = ii + 1
+            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'           ;   ii = ii + 1
             l_isend = .TRUE.
          CASE DEFAULT
-            WRITE(ldtxt(ii),cform_err)                                                            ;   ii = ii + 1
-            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send             ;   ii = ii + 1
+            WRITE(ldtxt(ii),cform_err)                                                    ;   ii = ii + 1
+            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send     ;   ii = ii + 1
             kstop = kstop + 1
          END SELECT
       ELSE IF ( PRESENT(localComm) .and. .not. mpi_was_called ) THEN
-         WRITE(ldtxt(ii),*) ' lib_mpp: You cannot provide a local communicator '                  ;   ii = ii + 1
-         WRITE(ldtxt(ii),*) '          without calling MPI_Init before ! '                        ;   ii = ii + 1
+         WRITE(ldtxt(ii),*) ' lib_mpp: You cannot provide a local communicator '          ;   ii = ii + 1
+         WRITE(ldtxt(ii),*) '          without calling MPI_Init before ! '                ;   ii = ii + 1
          kstop = kstop + 1
       ELSE
          SELECT CASE ( cn_mpi_send )
          CASE ( 'S' )                ! Standard mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'                     ;   ii = ii + 1
+            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'             ;   ii = ii + 1
             CALL mpi_init( ierr )
          CASE ( 'B' )                ! Buffer mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'                      ;   ii = ii + 1
+            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'              ;   ii = ii + 1
             IF( Agrif_Root() )   CALL mpi_init_opa( ldtxt, ii, ierr )
          CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'                   ;   ii = ii + 1
+            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'           ;   ii = ii + 1
             l_isend = .TRUE.
             CALL mpi_init( ierr )
          CASE DEFAULT
-            WRITE(ldtxt(ii),cform_err)                                                            ;   ii = ii + 1
-            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send             ;   ii = ii + 1
+            WRITE(ldtxt(ii),cform_err)                                                    ;   ii = ii + 1
+            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send     ;   ii = ii + 1
             kstop = kstop + 1
          END SELECT
@@ -319,4 +320,5 @@
    END FUNCTION mynode
 
+
    SUBROUTINE mpp_lnk_3d( ptab, cd_type, psgn, cd_mpp, pval )
       !!----------------------------------------------------------------------
@@ -347,14 +349,12 @@
       CHARACTER(len=3), OPTIONAL      , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
       REAL(wp)        , OPTIONAL      , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
-      !!
+      !
       INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
       INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
       INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
       REAL(wp) ::   zland
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
+      INTEGER , DIMENSION(MPI_STATUS_SIZE)      ::   ml_stat        ! for key_mpi_isend
       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
-
       !!----------------------------------------------------------------------
       
@@ -364,5 +364,5 @@
       !
       IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0.e0      ! zero by default
+      ELSE                         ;   zland = 0._wp     ! zero by default
       ENDIF
 
@@ -455,5 +455,4 @@
       END SELECT
 
-
       ! 3. North and south directions
       ! -----------------------------
@@ -508,5 +507,4 @@
       END SELECT
 
-
       ! 4. north fold treatment
       ! -----------------------
@@ -524,4 +522,5 @@
       !
    END SUBROUTINE mpp_lnk_3d
+
 
    SUBROUTINE mpp_lnk_2d_multiple( pt2d_array , type_array , psgn_array , num_fields , cd_mpp, pval )
@@ -542,9 +541,5 @@
       !!                    noso   : number for local neighboring processors
       !!                    nono   : number for local neighboring processors
-      !!
-      !!----------------------------------------------------------------------
-
-      INTEGER :: num_fields
-      TYPE( arrayptr ), DIMENSION(:) :: pt2d_array
+      !!----------------------------------------------------------------------
       CHARACTER(len=1), DIMENSION(:), INTENT(in   ) ::   type_array   ! define the nature of ptab array grid-points
       !                                                               ! = T , U , V , F , W and I points
@@ -558,19 +553,18 @@
       INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
       INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-
+      INTEGER :: num_fields
+      TYPE( arrayptr ), DIMENSION(:) :: pt2d_array
       REAL(wp) ::   zland
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
+      INTEGER , DIMENSION(MPI_STATUS_SIZE)    ::   ml_stat       ! for key_mpi_isend
       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
 
       !!----------------------------------------------------------------------
-
+      !
       ALLOCATE( zt2ns(jpi,jprecj,2*num_fields), zt2sn(jpi,jprecj,2*num_fields),  &
          &      zt2ew(jpj,jpreci,2*num_fields), zt2we(jpj,jpreci,2*num_fields)   )
-
       !
       IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0.e0      ! zero by default
+      ELSE                         ;   zland = 0._wp     ! zero by default
       ENDIF
 
@@ -744,5 +738,5 @@
          !
       END DO
-      
+      !
       DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we )
       !
@@ -750,18 +744,18 @@
 
    
-   SUBROUTINE load_array(pt2d,cd_type,psgn,pt2d_array, type_array, psgn_array,num_fields)
+   SUBROUTINE load_array( pt2d, cd_type, psgn, pt2d_array, type_array, psgn_array, num_fields )
       !!---------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), TARGET   ,   INTENT(inout) ::   pt2d    ! Second 2D array on which the boundary condition is applied
-      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type ! define the nature of ptab array grid-points
-      REAL(wp)                    , INTENT(in   ) ::   psgn    ! =-1 the sign change across the north fold boundary
+      REAL(wp), DIMENSION(jpi,jpj), TARGET, INTENT(inout) ::   pt2d    ! Second 2D array on which the boundary condition is applied
+      CHARACTER(len=1)                    , INTENT(in   ) ::   cd_type ! define the nature of ptab array grid-points
+      REAL(wp)                            , INTENT(in   ) ::   psgn    ! =-1 the sign change across the north fold boundary
       TYPE(arrayptr)   , DIMENSION(9) ::   pt2d_array
       CHARACTER(len=1) , DIMENSION(9) ::   type_array    ! define the nature of ptab array grid-points
       REAL(wp)         , DIMENSION(9) ::   psgn_array    ! =-1 the sign change across the north fold boundary
-      INTEGER                      , INTENT (inout):: num_fields 
+      INTEGER                            , INTENT (inout) :: num_fields 
       !!---------------------------------------------------------------------
-      num_fields=num_fields+1
-      pt2d_array(num_fields)%pt2d=>pt2d
-      type_array(num_fields)=cd_type
-      psgn_array(num_fields)=psgn
+      num_fields = num_fields + 1
+      pt2d_array(num_fields)%pt2d => pt2d
+      type_array(num_fields)      =  cd_type
+      psgn_array(num_fields)      =  psgn
    END SUBROUTINE load_array
    
@@ -792,21 +786,22 @@
       INTEGER :: num_fields
       !!---------------------------------------------------------------------
-
+      !
       num_fields = 0
-
-      !! Load the first array
-      CALL load_array(pt2dA,cd_typeA,psgnA,pt2d_array, type_array, psgn_array,num_fields)
-
-      !! Look if more arrays are added
-      IF(PRESENT (psgnB) )CALL load_array(pt2dB,cd_typeB,psgnB,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnC) )CALL load_array(pt2dC,cd_typeC,psgnC,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnD) )CALL load_array(pt2dD,cd_typeD,psgnD,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnE) )CALL load_array(pt2dE,cd_typeE,psgnE,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnF) )CALL load_array(pt2dF,cd_typeF,psgnF,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnG) )CALL load_array(pt2dG,cd_typeG,psgnG,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnH) )CALL load_array(pt2dH,cd_typeH,psgnH,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnI) )CALL load_array(pt2dI,cd_typeI,psgnI,pt2d_array, type_array, psgn_array,num_fields)
-      
-      CALL mpp_lnk_2d_multiple(pt2d_array,type_array,psgn_array,num_fields,cd_mpp,pval)
+      !
+      ! Load the first array
+      CALL load_array( pt2dA, cd_typeA, psgnA, pt2d_array, type_array, psgn_array, num_fields )
+      !
+      ! Look if more arrays are added
+      IF( PRESENT(psgnB) )   CALL load_array(pt2dB,cd_typeB,psgnB,pt2d_array, type_array, psgn_array,num_fields)
+      IF( PRESENT(psgnC) )   CALL load_array(pt2dC,cd_typeC,psgnC,pt2d_array, type_array, psgn_array,num_fields)
+      IF( PRESENT(psgnD) )   CALL load_array(pt2dD,cd_typeD,psgnD,pt2d_array, type_array, psgn_array,num_fields)
+      IF( PRESENT(psgnE) )   CALL load_array(pt2dE,cd_typeE,psgnE,pt2d_array, type_array, psgn_array,num_fields)
+      IF( PRESENT(psgnF) )   CALL load_array(pt2dF,cd_typeF,psgnF,pt2d_array, type_array, psgn_array,num_fields)
+      IF( PRESENT(psgnG) )   CALL load_array(pt2dG,cd_typeG,psgnG,pt2d_array, type_array, psgn_array,num_fields)
+      IF( PRESENT(psgnH) )   CALL load_array(pt2dH,cd_typeH,psgnH,pt2d_array, type_array, psgn_array,num_fields)
+      IF( PRESENT(psgnI) )   CALL load_array(pt2dI,cd_typeI,psgnI,pt2d_array, type_array, psgn_array,num_fields)
+      !
+      CALL mpp_lnk_2d_multiple( pt2d_array, type_array, psgn_array, num_fields, cd_mpp,pval )
+      !
    END SUBROUTINE mpp_lnk_2d_9
 
@@ -843,17 +838,14 @@
       INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
       REAL(wp) ::   zland
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
+      INTEGER, DIMENSION(MPI_STATUS_SIZE)     ::   ml_stat       ! for key_mpi_isend
       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
-
-      !!----------------------------------------------------------------------
-
+      !!----------------------------------------------------------------------
+      !
       ALLOCATE( zt2ns(jpi,jprecj,2), zt2sn(jpi,jprecj,2),  &
          &      zt2ew(jpj,jpreci,2), zt2we(jpj,jpreci,2)   )
-
       !
       IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0.e0      ! zero by default
+      ELSE                         ;   zland = 0._wp     ! zero by default
       ENDIF
 
@@ -1046,14 +1038,12 @@
       INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
       INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
+      INTEGER , DIMENSION(MPI_STATUS_SIZE)        ::   ml_stat   ! for key_mpi_isend
       REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE ::   zt4ns, zt4sn   ! 2 x 3d for north-south & south-north
       REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE ::   zt4ew, zt4we   ! 2 x 3d for east-west & west-east
-
-      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      !
       ALLOCATE( zt4ns(jpi,jprecj,jpk,2,2), zt4sn(jpi,jprecj,jpk,2,2) ,    &
          &      zt4ew(jpj,jpreci,jpk,2,2), zt4we(jpj,jpreci,jpk,2,2) )
-
-
+      !
       ! 1. standard boundary treatment
       ! ------------------------------
@@ -1399,7 +1389,350 @@
          END DO
       END SELECT
-
+      !
    END SUBROUTINE mpp_lnk_2d_e
 
+   SUBROUTINE mpp_lnk_sum_3d( ptab, cd_type, psgn, cd_mpp, pval )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_sum_3d  ***
+      !!
+      !! ** Purpose :   Message passing manadgement (sum the overlap region)
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !! ** Action  :   ptab with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
+      !                                                             ! = T , U , V , F , W points
+      REAL(wp)                        , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
+      !                                                             ! =  1. , the sign is kept
+      CHARACTER(len=3), OPTIONAL      , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
+      REAL(wp)        , OPTIONAL      , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
+      !!
+      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      REAL(wp) ::   zland
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
+
+      !!----------------------------------------------------------------------
+      
+      ALLOCATE( zt3ns(jpi,jprecj,jpk,2), zt3sn(jpi,jprecj,jpk,2),   &
+         &      zt3ew(jpj,jpreci,jpk,2), zt3we(jpj,jpreci,jpk,2)  )
+
+      !
+      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
+      ELSE                         ;   zland = 0.e0      ! zero by default
+      ENDIF
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+      iihom = nlci-jpreci
+         DO jl = 1, jpreci
+            zt3ew(:,jl,:,1) = ptab(jl      ,:,:) ; ptab(jl      ,:,:) = 0.0_wp
+            zt3we(:,jl,:,1) = ptab(iihom+jl,:,:) ; ptab(iihom+jl,:,:) = 0.0_wp 
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj * jpk
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
+         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write lateral conditions
+      iihom = nlci-nreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            ptab(iihom+jl,:,:) = ptab(iihom+jl,:,:) + zt3ew(:,jl,:,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            ptab(jpreci+jl,:,:) = ptab(jpreci+jl,:,:) + zt3we(:,jl,:,2)
+            ptab(iihom +jl,:,:) = ptab(iihom +jl,:,:) + zt3ew(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            ptab(jpreci+jl,:,:) = ptab(jpreci+jl,:,:) + zt3we(:,jl,:,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read lateral conditions
+         ijhom = nlcj-jprecj
+         DO jl = 1, jprecj
+            zt3sn(:,jl,:,1) = ptab(:,ijhom+jl,:) ; ptab(:,ijhom+jl,:) = 0.0_wp
+            zt3ns(:,jl,:,1) = ptab(:,jl      ,:) ; ptab(:,jl      ,:) = 0.0_wp
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi * jpk
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
+         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write lateral conditions
+      ijhom = nlcj-nrecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            ptab(:,ijhom+jl,:) = ptab(:,ijhom+jl,:) + zt3ns(:,jl,:,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            ptab(:,jprecj+jl,:) = ptab(:,jprecj+jl,:) + zt3sn(:,jl,:,2)
+            ptab(:,ijhom +jl,:) = ptab(:,ijhom +jl,:) + zt3ns(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            ptab(:,jprecj+jl,:) = ptab(:,jprecj+jl,:) + zt3sn(:,jl   ,:,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt3ns, zt3sn, zt3ew, zt3we )
+      !
+   END SUBROUTINE mpp_lnk_sum_3d
+
+   SUBROUTINE mpp_lnk_sum_2d( pt2d, cd_type, psgn, cd_mpp, pval )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_sum_2d  ***
+      !!
+      !! ** Purpose :   Message passing manadgement for 2d array (sum the overlap region)
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d     ! 2D array on which the boundary condition is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
+      !                                                         ! = T , U , V , F , W and I points
+      REAL(wp)                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
+      !                                                         ! =  1. , the sign is kept
+      CHARACTER(len=3), OPTIONAL  , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
+      REAL(wp)        , OPTIONAL  , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
+      !!
+      INTEGER  ::   ji, jj, jl   ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      REAL(wp) ::   zland
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
+
+      !!----------------------------------------------------------------------
+
+      ALLOCATE( zt2ns(jpi,jprecj,2), zt2sn(jpi,jprecj,2),  &
+         &      zt2ew(jpj,jpreci,2), zt2we(jpj,jpreci,2)   )
+
+      !
+      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
+      ELSE                         ;   zland = 0.e0      ! zero by default
+      ENDIF
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci - jpreci
+         DO jl = 1, jpreci
+            zt2ew(:,jl,1) = pt2d(jl       ,:) ; pt2d(jl       ,:) = 0.0_wp
+            zt2we(:,jl,1) = pt2d(iihom +jl,:) ; pt2d(iihom +jl,:) = 0.0_wp
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
+         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write lateral conditions
+      iihom = nlci-nreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            pt2d(iihom+jl,:) = pt2d(iihom+jl,:) + zt2ew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            pt2d(jpreci+jl,:) = pt2d(jpreci+jl,:) + zt2we(:,jl,2)
+            pt2d(iihom +jl,:) = pt2d(iihom +jl,:) + zt2ew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            pt2d(jpreci+jl,:) = pt2d(jpreci+jl,:) + zt2we(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read lateral conditions
+         ijhom = nlcj - jprecj
+         DO jl = 1, jprecj
+            zt2sn(:,jl,1) = pt2d(:,ijhom +jl) ; pt2d(:,ijhom +jl) = 0.0_wp
+            zt2ns(:,jl,1) = pt2d(:,jl       ) ; pt2d(:,jl       ) = 0.0_wp
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
+         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write lateral conditions
+      ijhom = nlcj-nrecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            pt2d(:,ijhom+jl) = pt2d(:,ijhom+jl) + zt2ns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            pt2d(:,jprecj+jl) = pt2d(:,jprecj+jl) + zt2sn(:,jl,2)
+            pt2d(:,ijhom +jl) = pt2d(:,ijhom +jl) + zt2ns(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            pt2d(:,jprecj+jl) = pt2d(:,jprecj+jl) + zt2sn(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd      ( pt2d, cd_type, psgn )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_lbc_north( pt2d, cd_type, psgn )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we )
+      !
+   END SUBROUTINE mpp_lnk_sum_2d
 
    SUBROUTINE mppsend( ktyp, pmess, kbytes, kdest, md_req )
@@ -1449,12 +1782,9 @@
       !!----------------------------------------------------------------------
       !
-
       ! If a specific process number has been passed to the receive call,
       ! use that one. Default is to use mpi_any_source
-      use_source=mpi_any_source
-      if(present(ksource)) then
-         use_source=ksource
-      end if
-
+      use_source = mpi_any_source
+      IF( PRESENT(ksource) )   use_source = ksource
+      !
       CALL mpi_recv( pmess, kbytes, mpi_double_precision, use_source, ktyp, mpi_comm_opa, istatus, iflag )
       !
@@ -1470,6 +1800,6 @@
       !!
       !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj),       INTENT(in   ) ::   ptab   ! subdomain input array
-      INTEGER ,                           INTENT(in   ) ::   kp     ! record length
+      REAL(wp), DIMENSION(jpi,jpj)      , INTENT(in   ) ::   ptab   ! subdomain input array
+      INTEGER                           , INTENT(in   ) ::   kp     ! record length
       REAL(wp), DIMENSION(jpi,jpj,jpnij), INTENT(  out) ::   pio    ! subdomain input array
       !!
@@ -1492,12 +1822,12 @@
       !!
       !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpnij)  ::  pio        ! output array
-      INTEGER                             ::   kp        ! Tag (not used with MPI
-      REAL(wp), DIMENSION(jpi,jpj)        ::  ptab       ! subdomain array input
+      REAL(wp), DIMENSION(jpi,jpj,jpnij)  ::   pio    ! output array
+      INTEGER                             ::   kp     ! Tag (not used with MPI
+      REAL(wp), DIMENSION(jpi,jpj)        ::   ptab   ! subdomain array input
       !!
       INTEGER :: itaille, ierror   ! temporary integer
       !!---------------------------------------------------------------------
       !
-      itaille=jpi*jpj
+      itaille = jpi * jpj
       !
       CALL mpi_scatter( pio, itaille, mpi_double_precision, ptab, itaille     ,   &
@@ -1517,5 +1847,5 @@
       INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab   ! input array
       INTEGER , INTENT(in   ), OPTIONAL        ::   kcom   !
-      !!
+      !
       INTEGER :: ierror, localcomm   ! temporary integer
       INTEGER, DIMENSION(kdim) ::   iwork
@@ -1539,7 +1869,7 @@
       !!
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(inout)           ::   ktab      ! ???
-      INTEGER, INTENT(in   ), OPTIONAL ::   kcom      ! ???
-      !!
+      INTEGER, INTENT(inout)           ::   ktab   ! ???
+      INTEGER, INTENT(in   ), OPTIONAL ::   kcom   ! ???
+      !
       INTEGER ::   ierror, iwork, localcomm   ! temporary integer
       !!----------------------------------------------------------------------
@@ -1548,5 +1878,5 @@
       IF( PRESENT(kcom) )   localcomm = kcom
       !
-      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_max, localcomm, ierror)
+      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_max, localcomm, ierror )
       !
       ktab = iwork
@@ -1562,7 +1892,7 @@
       !!
       !!----------------------------------------------------------------------
-      INTEGER , INTENT( in  )                  ::   kdim        ! size of array
-      INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab        ! input array
-      INTEGER , INTENT( in  ), OPTIONAL        ::   kcom        ! input array
+      INTEGER , INTENT( in  )                  ::   kdim   ! size of array
+      INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab   ! input array
+      INTEGER , INTENT( in  ), OPTIONAL        ::   kcom   ! input array
       !!
       INTEGER ::   ierror, localcomm   ! temporary integer
@@ -1596,5 +1926,5 @@
       IF( PRESENT(kcom) )   localcomm = kcom
       !
-     CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_min, localcomm, ierror )
+      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_min, localcomm, ierror )
       !
       ktab = iwork
@@ -1610,7 +1940,7 @@
       !!
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in   )                   ::   kdim      ! ???
-      INTEGER, INTENT(inout), DIMENSION (kdim) ::   ktab      ! ???
-      !!
+      INTEGER, INTENT(in   )                   ::   kdim   ! ???
+      INTEGER, INTENT(inout), DIMENSION (kdim) ::   ktab   ! ???
+      !
       INTEGER :: ierror
       INTEGER, DIMENSION (kdim) ::  iwork
@@ -1653,5 +1983,5 @@
       REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
       INTEGER , INTENT(in   ), OPTIONAL        ::   kcom
-      !!
+      !
       INTEGER :: ierror, localcomm
       REAL(wp), DIMENSION(kdim) ::  zwork
@@ -1785,4 +2115,5 @@
    END SUBROUTINE mppsum_real
 
+
    SUBROUTINE mppsum_realdd( ytab, kcom )
       !!----------------------------------------------------------------------
@@ -1793,20 +2124,19 @@
       !!
       !!-----------------------------------------------------------------------
-      COMPLEX(wp), INTENT(inout)         :: ytab    ! input scalar
-      INTEGER , INTENT( in  ), OPTIONAL :: kcom
-
-      !! * Local variables   (MPI version)
-      INTEGER  ::    ierror
-      INTEGER  ::   localcomm
-      COMPLEX(wp) :: zwork
-
+      COMPLEX(wp), INTENT(inout)           ::   ytab    ! input scalar
+      INTEGER    , INTENT(in   ), OPTIONAL ::   kcom
+      !
+      INTEGER     ::   ierror
+      INTEGER     ::   localcomm
+      COMPLEX(wp) ::   zwork
+      !!-----------------------------------------------------------------------
+      !
       localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) ) localcomm = kcom
-
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
       ! reduce local sums into global sum
-      CALL MPI_ALLREDUCE (ytab, zwork, 1, MPI_DOUBLE_COMPLEX, &
-                       MPI_SUMDD,localcomm,ierror)
+      CALL MPI_ALLREDUCE (ytab, zwork, 1, MPI_DOUBLE_COMPLEX, MPI_SUMDD, localcomm, ierror )
       ytab = zwork
-
+      !
    END SUBROUTINE mppsum_realdd
 
@@ -1820,21 +2150,20 @@
       !!
       !!-----------------------------------------------------------------------
-      INTEGER , INTENT( in )                        ::   kdim      ! size of ytab
-      COMPLEX(wp), DIMENSION(kdim), INTENT( inout ) ::   ytab      ! input array
-      INTEGER , INTENT( in  ), OPTIONAL :: kcom
-
-      !! * Local variables   (MPI version)
-      INTEGER                      :: ierror    ! temporary integer
-      INTEGER                      ::   localcomm
+      INTEGER                     , INTENT(in   ) ::   kdim   ! size of ytab
+      COMPLEX(wp), DIMENSION(kdim), INTENT(inout) ::   ytab   ! input array
+      INTEGER    , OPTIONAL       , INTENT(in   ) ::   kcom
+      !
+      INTEGER:: ierror, localcomm    ! local integer
       COMPLEX(wp), DIMENSION(kdim) :: zwork     ! temporary workspace
-
+      !!-----------------------------------------------------------------------
+      !
       localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) ) localcomm = kcom
-
-      CALL MPI_ALLREDUCE (ytab, zwork, kdim, MPI_DOUBLE_COMPLEX, &
-                       MPI_SUMDD,localcomm,ierror)
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL MPI_ALLREDUCE( ytab, zwork, kdim, MPI_DOUBLE_COMPLEX, MPI_SUMDD, localcomm, ierror )
       ytab(:) = zwork(:)
-
+      !
    END SUBROUTINE mppsum_a_realdd
+
 
    SUBROUTINE mpp_minloc2d( ptab, pmask, pmin, ki,kj )
@@ -1852,7 +2181,7 @@
       REAL(wp)                     , INTENT(  out) ::   pmin    ! Global minimum of ptab
       INTEGER                      , INTENT(  out) ::   ki, kj   ! index of minimum in global frame
-      !!
+      !
+      INTEGER :: ierror
       INTEGER , DIMENSION(2)   ::   ilocs
-      INTEGER :: ierror
       REAL(wp) ::   zmin   ! local minimum
       REAL(wp), DIMENSION(2,1) ::   zain, zaout
@@ -2662,5 +2991,6 @@
    END SUBROUTINE mpp_lbc_north_e
 
-      SUBROUTINE mpp_lnk_bdy_3d( ptab, cd_type, psgn, ib_bdy )
+
+   SUBROUTINE mpp_lnk_bdy_3d( ptab, cd_type, psgn, ib_bdy )
       !!----------------------------------------------------------------------
       !!                  ***  routine mpp_lnk_bdy_3d  ***
@@ -2683,9 +3013,4 @@
       !!
       !!----------------------------------------------------------------------
-
-      USE lbcnfd          ! north fold
-
-      INCLUDE 'mpif.h'
-
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
       CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
@@ -2694,48 +3019,44 @@
       !                                                             ! =  1. , the sign is kept
       INTEGER                         , INTENT(in   ) ::   ib_bdy   ! BDY boundary set
+      !
       INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   imigr, iihom, ijhom        ! local integers
       INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland
+      REAL(wp) ::   zland                      ! local scalar
       INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
       !
       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
-
-      !!----------------------------------------------------------------------
-      
+      !!----------------------------------------------------------------------
+      !
       ALLOCATE( zt3ns(jpi,jprecj,jpk,2), zt3sn(jpi,jprecj,jpk,2),   &
          &      zt3ew(jpj,jpreci,jpk,2), zt3we(jpj,jpreci,jpk,2)  )
 
-      zland = 0.e0
+      zland = 0._wp
 
       ! 1. standard boundary treatment
       ! ------------------------------
-      
       !                                   ! East-West boundaries
       !                                        !* Cyclic east-west
-
       IF( nbondi == 2) THEN
-        IF (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
-          ptab( 1 ,:,:) = ptab(jpim1,:,:)
-          ptab(jpi,:,:) = ptab(  2  ,:,:)
-        ELSE
-          IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
-          ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
-        ENDIF
+         IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) THEN
+            ptab( 1 ,:,:) = ptab(jpim1,:,:)
+            ptab(jpi,:,:) = ptab(  2  ,:,:)
+         ELSE
+            IF( .NOT. cd_type == 'F' )   ptab(1:jpreci,:,:) = zland    ! south except F-point
+            ptab(nlci-jpreci+1:jpi,:,:) = zland    ! north
+         ENDIF
       ELSEIF(nbondi == -1) THEN
-        IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
+         IF( .NOT. cd_type == 'F' )   ptab(1:jpreci,:,:) = zland    ! south except F-point
       ELSEIF(nbondi == 1) THEN
-        ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
+         ptab(nlci-jpreci+1:jpi,:,:) = zland    ! north
       ENDIF                                     !* closed
 
       IF (nbondj == 2 .OR. nbondj == -1) THEN
-        IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj,:) = zland       ! south except F-point
+        IF( .NOT. cd_type == 'F' )   ptab(:,1:jprecj,:) = zland       ! south except F-point
       ELSEIF (nbondj == 2 .OR. nbondj == 1) THEN
-        ptab(:,nlcj-jprecj+1:jpj   ,:) = zland       ! north
-      ENDIF
-      
-      !
-
+        ptab(:,nlcj-jprecj+1:jpj,:) = zland       ! north
+      ENDIF
+      !
       ! 2. East and west directions exchange
       ! ------------------------------------
@@ -2794,10 +3115,10 @@
       CASE ( 0 )
          DO jl = 1, jpreci
-            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
+            ptab(      jl,:,:) = zt3we(:,jl,:,2)
             ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
          END DO
       CASE ( 1 )
          DO jl = 1, jpreci
-            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
+            ptab(      jl,:,:) = zt3we(:,jl,:,2)
          END DO
       END SELECT
@@ -2885,5 +3206,6 @@
    END SUBROUTINE mpp_lnk_bdy_3d
 
-      SUBROUTINE mpp_lnk_bdy_2d( ptab, cd_type, psgn, ib_bdy )
+
+   SUBROUTINE mpp_lnk_bdy_2d( ptab, cd_type, psgn, ib_bdy )
       !!----------------------------------------------------------------------
       !!                  ***  routine mpp_lnk_bdy_2d  ***
@@ -2906,17 +3228,13 @@
       !!
       !!----------------------------------------------------------------------
-
-      USE lbcnfd          ! north fold
-
-      INCLUDE 'mpif.h'
-
-      REAL(wp), DIMENSION(jpi,jpj)    , INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
-      !                                                             ! = T , U , V , F , W points
-      REAL(wp)                        , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
-      !                                                             ! =  1. , the sign is kept
-      INTEGER                         , INTENT(in   ) ::   ib_bdy   ! BDY boundary set
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
+      !                                                         ! = T , U , V , F , W points
+      REAL(wp)                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
+      !                                                         ! =  1. , the sign is kept
+      INTEGER                     , INTENT(in   ) ::   ib_bdy   ! BDY boundary set
+      !
       INTEGER  ::   ji, jj, jl             ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   imigr, iihom, ijhom        ! local integers
       INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
       REAL(wp) ::   zland
@@ -2925,5 +3243,4 @@
       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
-
       !!----------------------------------------------------------------------
 
@@ -2931,34 +3248,30 @@
          &      zt2ew(jpj,jpreci,2), zt2we(jpj,jpreci,2)   )
 
-      zland = 0.e0
+      zland = 0._wp
 
       ! 1. standard boundary treatment
       ! ------------------------------
-      
       !                                   ! East-West boundaries
-      !                                        !* Cyclic east-west
-
-      IF( nbondi == 2) THEN
-        IF (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
-          ptab( 1 ,:) = ptab(jpim1,:)
-          ptab(jpi,:) = ptab(  2  ,:)
-        ELSE
-          IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:) = zland    ! south except F-point
-          ptab(nlci-jpreci+1:jpi   ,:) = zland    ! north
-        ENDIF
+      !                                      !* Cyclic east-west
+      IF( nbondi == 2 ) THEN
+         IF (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
+            ptab( 1 ,:) = ptab(jpim1,:)
+            ptab(jpi,:) = ptab(  2  ,:)
+         ELSE
+            IF(.NOT.cd_type == 'F' )  ptab(     1       :jpreci,:) = zland    ! south except F-point
+                                      ptab(nlci-jpreci+1:jpi   ,:) = zland    ! north
+         ENDIF
       ELSEIF(nbondi == -1) THEN
-        IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:) = zland    ! south except F-point
+         IF( .NOT.cd_type == 'F' )    ptab(     1       :jpreci,:) = zland    ! south except F-point
       ELSEIF(nbondi == 1) THEN
-        ptab(nlci-jpreci+1:jpi   ,:) = zland    ! north
-      ENDIF                                     !* closed
-
-      IF (nbondj == 2 .OR. nbondj == -1) THEN
-        IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj) = zland       ! south except F-point
+                                      ptab(nlci-jpreci+1:jpi   ,:) = zland    ! north
+      ENDIF
+      !                                      !* closed
+      IF( nbondj == 2 .OR. nbondj == -1 ) THEN
+         IF( .NOT.cd_type == 'F' )    ptab(:,     1       :jprecj) = zland    ! south except F-point
       ELSEIF (nbondj == 2 .OR. nbondj == 1) THEN
-        ptab(:,nlcj-jprecj+1:jpj) = zland       ! north
-      ENDIF
-      
-      !
-
+                                      ptab(:,nlcj-jprecj+1:jpj   ) = zland    ! north
+      ENDIF
+      !
       ! 2. East and west directions exchange
       ! ------------------------------------
@@ -3107,4 +3420,5 @@
       !
    END SUBROUTINE mpp_lnk_bdy_2d
+
 
    SUBROUTINE mpi_init_opa( ldtxt, ksft, code )
@@ -3196,4 +3510,5 @@
    END SUBROUTINE DDPDD_MPI
 
+
    SUBROUTINE mpp_lbc_north_icb( pt2d, cd_type, psgn, pr2dj)
       !!---------------------------------------------------------------------
@@ -3218,4 +3533,5 @@
       !!                                                    ! north fold, =  1. otherwise
       INTEGER, OPTIONAL       , INTENT(in   ) ::   pr2dj
+      !
       INTEGER ::   ji, jj, jr
       INTEGER ::   ierr, itaille, ildi, ilei, iilb
@@ -3224,5 +3540,4 @@
       REAL(wp), DIMENSION(:,:)  , ALLOCATABLE  ::  ztab_e, znorthloc_e
       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE  ::  znorthgloio_e
-
       !!----------------------------------------------------------------------
       !
@@ -3234,9 +3549,8 @@
       ENDIF
       ALLOCATE( ztab_e(jpiglo,4+2*ipr2dj), znorthloc_e(jpi,4+2*ipr2dj), znorthgloio_e(jpi,4+2*ipr2dj,jpni) )
-
-      !
-      ztab_e(:,:) = 0.e0
-
-      ij=0
+      !
+      ztab_e(:,:) = 0._wp
+      !
+      ij = 0
       ! put in znorthloc_e the last 4 jlines of pt2d
       DO jj = nlcj - ijpj + 1 - ipr2dj, nlcj +ipr2dj
@@ -3280,4 +3594,5 @@
       !
    END SUBROUTINE mpp_lbc_north_icb
+
 
    SUBROUTINE mpp_lnk_2d_icb( pt2d, cd_type, psgn, jpri, jprj )
@@ -3300,5 +3615,4 @@
       !!                    noso   : number for local neighboring processors
       !!                    nono   : number for local neighboring processors
-      !!
       !!----------------------------------------------------------------------
       INTEGER                                             , INTENT(in   ) ::   jpri
@@ -3459,4 +3773,5 @@
 
    END SUBROUTINE mpp_lnk_2d_icb
+   
 #else
    !!----------------------------------------------------------------------
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90	(revision 6140)
@@ -11,5 +11,4 @@
    !!   mpp_init_ioispl: IOIPSL initialization in mpp
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE dom_oce         ! ocean space and time domain 
    USE in_out_manager  ! I/O Manager
@@ -23,6 +22,4 @@
    PUBLIC mpp_init2      ! called by opa.F90
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -457,11 +454,4 @@
 #  include "mppini_2.h90"
 
-# if defined key_dimgout
-   !!----------------------------------------------------------------------
-   !!   'key_dimgout'                  NO use of NetCDF files
-   !!----------------------------------------------------------------------
-   SUBROUTINE mpp_init_ioipsl       ! Dummy routine
-   END SUBROUTINE mpp_init_ioipsl  
-# else
    SUBROUTINE mpp_init_ioipsl
       !!----------------------------------------------------------------------
@@ -509,5 +499,4 @@
    END SUBROUTINE mpp_init_ioipsl  
 
-# endif
 #endif
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/mppini_2.h90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/mppini_2.h90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/LBC/mppini_2.h90	(revision 6140)
@@ -136,5 +136,5 @@
 
       imask(:,:)=1
-      WHERE ( zdta(:,:) - zdtaisf(:,:) <= 0. ) imask = 0
+      WHERE ( zdta(:,:) - zdtaisf(:,:) <= rn_isfhmin ) imask = 0
 
       !  1. Dimension arrays for subdomains
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/LDF/ldfc1d_c2d.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/LDF/ldfc1d_c2d.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/LDF/ldfc1d_c2d.F90	(revision 6140)
@@ -28,5 +28,4 @@
  
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -72,11 +71,11 @@
       CASE( 'DYN' )                     ! T- and F-points
          DO jk = 1, jpk                      ! pah1 at T-point
-            pah1(:,:,jk) = pahs1(:,:) * (  prat + zc * ( 1._wp + TANH( - ( fsdept(:,:,jk) - zh ) * zw) )  ) * tmask(:,:,jk)
+            pah1(:,:,jk) = pahs1(:,:) * (  prat + zc * ( 1._wp + TANH( - ( gdept_n(:,:,jk) - zh ) * zw) )  ) * tmask(:,:,jk)
          END DO
          DO jk = 1, jpk                      ! pah2 at F-point (zdep2 is an approximation in zps-coord.)
             DO jj = 1, jpjm1
                DO ji = 1, fs_jpim1
-                  zdep2 = (  fsdept(ji,jj+1,jk) + fsdept(ji+1,jj+1,jk)   &
-                     &     + fsdept(ji,jj  ,jk) + fsdept(ji+1,jj  ,jk)  ) * 0.25_wp
+                  zdep2 = (  gdept_n(ji,jj+1,jk) + gdept_n(ji+1,jj+1,jk)   &
+                     &     + gdept_n(ji,jj  ,jk) + gdept_n(ji+1,jj  ,jk)  ) * 0.25_wp
                   pah2(ji,jj,jk) = pahs2(ji,jj) * (  prat + zc * ( 1._wp + TANH( - ( zdep2 - zh ) * zw) )  ) * fmask(ji,jj,jk)
                END DO
@@ -89,6 +88,6 @@
             DO jj = 1, jpjm1
                DO ji = 1, fs_jpim1
-                  zdep1 = (  fsdept(ji,jj,jk) + fsdept(ji+1,jj,jk)  ) * 0.5_wp
-                  zdep2 = (  fsdept(ji,jj,jk) + fsdept(ji,jj+1,jk)  ) * 0.5_wp
+                  zdep1 = (  gdept_n(ji,jj,jk) + gdept_n(ji+1,jj,jk)  ) * 0.5_wp
+                  zdep2 = (  gdept_n(ji,jj,jk) + gdept_n(ji,jj+1,jk)  ) * 0.5_wp
                   pah1(ji,jj,jk) = pahs1(ji,jj) * (  prat + zc * ( 1._wp + TANH( - ( zdep1 - zh ) * zw) )  ) * umask(ji,jj,jk)
                   pah2(ji,jj,jk) = pahs2(ji,jj) * (  prat + zc * ( 1._wp + TANH( - ( zdep2 - zh ) * zw) )  ) * vmask(ji,jj,jk)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn.F90	(revision 6140)
@@ -52,5 +52,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/LDF/ldfslp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/LDF/ldfslp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/LDF/ldfslp.F90	(revision 6140)
@@ -73,5 +73,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -112,10 +111,12 @@
       !!
       INTEGER  ::   ji , jj , jk    ! dummy loop indices
-      INTEGER  ::   ii0, ii1, iku   ! temporary integer
-      INTEGER  ::   ij0, ij1, ikv   ! temporary integer
+      INTEGER  ::   ii0, ii1        ! temporary integer
+      INTEGER  ::   ij0, ij1        ! temporary integer
       REAL(wp) ::   zeps, zm1_g, zm1_2g, z1_16, zcofw, z1_slpmax ! local scalars
       REAL(wp) ::   zci, zfi, zau, zbu, zai, zbi   !   -      -
       REAL(wp) ::   zcj, zfj, zav, zbv, zaj, zbj   !   -      -
       REAL(wp) ::   zck, zfk,      zbw             !   -      -
+      REAL(wp) ::   zdepu, zdepv                   !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:  ) ::  zslpml_hmlpu, zslpml_hmlpv
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  zwz, zww
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  zdzr
@@ -126,4 +127,5 @@
       !
       CALL wrk_alloc( jpi,jpj,jpk, zwz, zww, zdzr, zgru, zgrv )
+      CALL wrk_alloc( jpi,jpj, zslpml_hmlpu, zslpml_hmlpv )
 
       zeps   =  1.e-20_wp        !==   Local constant initialization   ==!
@@ -149,4 +151,12 @@
                zgru(ji,jj,mbku(ji,jj)) = gru(ji,jj)
                zgrv(ji,jj,mbkv(ji,jj)) = grv(ji,jj)
+            END DO
+         END DO
+      ENDIF
+      IF( ln_zps .AND. ln_isfcav ) THEN           ! partial steps correction at the bottom ocean level
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               IF ( miku(ji,jj) > 1 ) zgru(ji,jj,miku(ji,jj)) = grui(ji,jj) 
+               IF ( mikv(ji,jj) > 1 ) zgrv(ji,jj,mikv(ji,jj)) = grvi(ji,jj)
             END DO
          END DO
@@ -171,4 +181,22 @@
       ! ===========================      | vslp = d/dj( prd ) / d/dz( prd )
       !
+      IF ( ln_isfcav ) THEN
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zslpml_hmlpu(ji,jj) = uslpml(ji,jj) / ( MAX(hmlpt(ji,jj), hmlpt(ji+1,jj  ), 5._wp)       &
+                  &                                  - 0.5_wp * ( risfdep(ji,jj) + risfdep(ji+1,jj  ) ) )
+               zslpml_hmlpv(ji,jj) = vslpml(ji,jj) / ( MAX(hmlpt(ji,jj), hmlpt(ji  ,jj+1), 5._wp)       &
+                  &                                  - 0.5_wp * ( risfdep(ji,jj) + risfdep(ji  ,jj+1) ) )
+            END DO
+         END DO
+      ELSE
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zslpml_hmlpu(ji,jj) = uslpml(ji,jj) / MAX(hmlpt(ji,jj), hmlpt(ji+1,jj  ), 5._wp)
+               zslpml_hmlpv(ji,jj) = vslpml(ji,jj) / MAX(hmlpt(ji,jj), hmlpt(ji  ,jj+1), 5._wp)
+            END DO
+         END DO
+      END IF
+
       DO jk = 2, jpkm1                            !* Slopes at u and v points
          DO jj = 2, jpjm1
@@ -181,23 +209,25 @@
                !                                      ! bound the slopes: abs(zw.)<= 1/100 and zb..<0
                !                                      ! + kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
-               zbu = MIN(  zbu, - z1_slpmax * ABS( zau ) , -7.e+3_wp/fse3u(ji,jj,jk)* ABS( zau )  )
-               zbv = MIN(  zbv, - z1_slpmax * ABS( zav ) , -7.e+3_wp/fse3v(ji,jj,jk)* ABS( zav )  )
+               zbu = MIN(  zbu, - z1_slpmax * ABS( zau ) , -7.e+3_wp/e3u_n(ji,jj,jk)* ABS( zau )  )
+               zbv = MIN(  zbv, - z1_slpmax * ABS( zav ) , -7.e+3_wp/e3v_n(ji,jj,jk)* ABS( zav )  )
                !                                      ! uslp and vslp output in zwz and zww, resp.
                zfi = MAX( omlmask(ji,jj,jk), omlmask(ji+1,jj,jk) )
                zfj = MAX( omlmask(ji,jj,jk), omlmask(ji,jj+1,jk) )
-               zwz(ji,jj,jk) = ( ( 1. - zfi) * zau / ( zbu - zeps )                                              &
-                  &                   + zfi  * uslpml(ji,jj)                                                     &
-                  &                          * 0.5_wp * ( fsdept(ji+1,jj,jk)+fsdept(ji,jj,jk)-fse3u(ji,jj,1) )   &
-                  &                          / MAX( hmlpt(ji,jj), hmlpt(ji+1,jj), 5._wp ) ) * umask(ji,jj,jk)
-               zww(ji,jj,jk) = ( ( 1. - zfj) * zav / ( zbv - zeps )                                              &
-                  &                   + zfj  * vslpml(ji,jj)                                                     &
-                  &                          * 0.5_wp * ( fsdept(ji,jj+1,jk)+fsdept(ji,jj,jk)-fse3v(ji,jj,1) )   &
-                  &                          / MAX( hmlpt(ji,jj), hmlpt(ji,jj+1), 5. ) ) * vmask(ji,jj,jk)
+               ! thickness of water column between surface and level k at u/v point
+               zdepu = 0.5_wp * ( ( gdept_n (ji,jj,jk) + gdept_n (ji+1,jj  ,jk) )                            &
+                                - ( risfdep(ji,jj)    + risfdep(ji+1,jj)    ) - e3u_n(ji,jj,miku(ji,jj)) )
+               zdepv = 0.5_wp * ( ( gdept_n (ji,jj,jk) + gdept_n (ji,jj+1,jk) )                              &
+                                - ( risfdep(ji,jj)    + risfdep(ji,jj+1)    ) - e3v_n(ji,jj,mikv(ji,jj)) )
+               !
+               zwz(ji,jj,jk) = ( ( 1._wp - zfi) * zau / ( zbu - zeps )                                     &
+                  &                      + zfi  * zdepu * zslpml_hmlpu(ji,jj) ) * umask(ji,jj,jk)
+               zww(ji,jj,jk) = ( ( 1._wp - zfj) * zav / ( zbv - zeps )                                     &
+                  &                      + zfj  * zdepv * zslpml_hmlpv(ji,jj) ) * vmask(ji,jj,jk)
 !!gm  modif to suppress omlmask.... (as in Griffies case)
 !               !                                         ! jk must be >= ML level for zf=1. otherwise  zf=0.
 !               zfi = REAL( 1 - 1/(1 + jk / MAX( nmln(ji+1,jj), nmln(ji,jj) ) ), wp )
 !               zfj = REAL( 1 - 1/(1 + jk / MAX( nmln(ji,jj+1), nmln(ji,jj) ) ), wp )
-!               zci = 0.5 * ( fsdept(ji+1,jj,jk)+fsdept(ji,jj,jk) ) / MAX( hmlpt(ji,jj), hmlpt(ji+1,jj), 10. ) )
-!               zcj = 0.5 * ( fsdept(ji,jj+1,jk)+fsdept(ji,jj,jk) ) / MAX( hmlpt(ji,jj), hmlpt(ji,jj+1), 10. ) )
+!               zci = 0.5 * ( gdept_n(ji+1,jj,jk)+gdept_n(ji,jj,jk) ) / MAX( hmlpt(ji,jj), hmlpt(ji+1,jj), 10. ) )
+!               zcj = 0.5 * ( gdept_n(ji,jj+1,jk)+gdept_n(ji,jj,jk) ) / MAX( hmlpt(ji,jj), hmlpt(ji,jj+1), 10. ) )
 !               zwz(ji,jj,jk) = ( zfi * zai / ( zbi - zeps ) + ( 1._wp - zfi ) * wslpiml(ji,jj) * zci ) * tmask(ji,jj,jk)
 !               zww(ji,jj,jk) = ( zfj * zaj / ( zbj - zeps ) + ( 1._wp - zfj ) * wslpjml(ji,jj) * zcj ) * tmask(ji,jj,jk)
@@ -265,21 +295,21 @@
                   &      + vmask(ji,jj-1,jk-1) + vmask(ji,jj,jk  ) , zeps  ) * e2t(ji,jj)
                zai =    (  zgru (ji-1,jj,jk  ) + zgru (ji,jj,jk-1)           &
-                  &      + zgru (ji-1,jj,jk-1) + zgru (ji,jj,jk  )   ) / zci * tmask (ji,jj,jk)
+                  &      + zgru (ji-1,jj,jk-1) + zgru (ji,jj,jk  )   ) / zci * wmask (ji,jj,jk)
                zaj =    (  zgrv (ji,jj-1,jk  ) + zgrv (ji,jj,jk-1)           &
-                  &      + zgrv (ji,jj-1,jk-1) + zgrv (ji,jj,jk  )   ) / zcj * tmask (ji,jj,jk)
+                  &      + zgrv (ji,jj-1,jk-1) + zgrv (ji,jj,jk  )   ) / zcj * wmask (ji,jj,jk)
                !                                        ! bound the slopes: abs(zw.)<= 1/100 and zb..<0.
                !                                        ! + kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
-               zbi = MIN( zbw ,- 100._wp* ABS( zai ) , -7.e+3_wp/fse3w(ji,jj,jk)* ABS( zai )  )
-               zbj = MIN( zbw , -100._wp* ABS( zaj ) , -7.e+3_wp/fse3w(ji,jj,jk)* ABS( zaj )  )
+               zbi = MIN( zbw ,- 100._wp* ABS( zai ) , -7.e+3_wp/e3w_n(ji,jj,jk)* ABS( zai )  )
+               zbj = MIN( zbw , -100._wp* ABS( zaj ) , -7.e+3_wp/e3w_n(ji,jj,jk)* ABS( zaj )  )
                !                                        ! wslpi and wslpj with ML flattening (output in zwz and zww, resp.)
                zfk = MAX( omlmask(ji,jj,jk), omlmask(ji,jj,jk-1) )   ! zfk=1 in the ML otherwise zfk=0
-               zck = fsdepw(ji,jj,jk) / MAX( hmlp(ji,jj), 10._wp )
-               zwz(ji,jj,jk) = (  zai / ( zbi - zeps ) * ( 1._wp - zfk ) + zck * wslpiml(ji,jj) * zfk  ) * tmask(ji,jj,jk)
-               zww(ji,jj,jk) = (  zaj / ( zbj - zeps ) * ( 1._wp - zfk ) + zck * wslpjml(ji,jj) * zfk  ) * tmask(ji,jj,jk)
+               zck = ( gdepw_n(ji,jj,jk) - gdepw_n(ji,jj,mikt(ji,jj) ) ) / MAX( hmlp(ji,jj) - gdepw_n(ji,jj,mikt(ji,jj)), 10._wp )
+               zwz(ji,jj,jk) = (  zai / ( zbi - zeps ) * ( 1._wp - zfk ) + zck * wslpiml(ji,jj) * zfk  ) * wmask(ji,jj,jk)
+               zww(ji,jj,jk) = (  zaj / ( zbj - zeps ) * ( 1._wp - zfk ) + zck * wslpjml(ji,jj) * zfk  ) * wmask(ji,jj,jk)
 
 !!gm  modif to suppress omlmask....  (as in Griffies operator)
 !               !                                         ! jk must be >= ML level for zfk=1. otherwise  zfk=0.
 !               zfk = REAL( 1 - 1/(1 + jk / nmln(ji+1,jj)), wp )
-!               zck = fsdepw(ji,jj,jk)    / MAX( hmlp(ji,jj), 10. )
+!               zck = gdepw(ji,jj,jk)    / MAX( hmlp(ji,jj), 10. )
 !               zwz(ji,jj,jk) = ( zfk * zai / ( zbi - zeps ) + ( 1._wp - zfk ) * wslpiml(ji,jj) * zck ) * tmask(ji,jj,jk)
 !               zww(ji,jj,jk) = ( zfk * zaj / ( zbj - zeps ) + ( 1._wp - zfk ) * wslpjml(ji,jj) * zck ) * tmask(ji,jj,jk)
@@ -340,5 +370,4 @@
       CALL lbc_lnk( wslpi, 'W', -1. )      ;      CALL lbc_lnk( wslpj, 'W', -1. )
 
-
       IF(ln_ctl) THEN
          CALL prt_ctl(tab3d_1=uslp , clinfo1=' slp  - u : ', tab3d_2=vslp,  clinfo2=' v : ', kdim=jpk)
@@ -347,4 +376,5 @@
       !
       CALL wrk_dealloc( jpi,jpj,jpk, zwz, zww, zdzr, zgru, zgrv )
+      CALL wrk_dealloc( jpi,jpj, zslpml_hmlpu, zslpml_hmlpv )
       !
       IF( nn_timing == 1 )  CALL timing_stop('ldf_slp')
@@ -441,5 +471,5 @@
                      zdks = 0._wp
                   ENDIF
-                  zdzrho_raw = ( - zalbet(ji,jj,jk) * zdkt + zbeta0*zdks ) / fse3w(ji,jj,jk+kp)
+                  zdzrho_raw = ( - zalbet(ji,jj,jk) * zdkt + zbeta0*zdks ) / e3w_n(ji,jj,jk+kp)
                   zdzrho(ji,jj,jk,kp) = - MIN( - repsln , zdzrho_raw )    ! force zdzrho >= repsln
                  END DO
@@ -451,5 +481,5 @@
          DO ji = 1, jpi
             jk = MIN( nmln(ji,jj), mbkt(ji,jj) ) + 1     ! MIN in case ML depth is the ocean depth
-            z1_mlbw(ji,jj) = 1._wp / fsdepw(ji,jj,jk)
+            z1_mlbw(ji,jj) = 1._wp / gdepw_n(ji,jj,jk)
          END DO
       END DO
@@ -480,16 +510,16 @@
                      ! Add s-coordinate slope at t-points (do this by *subtracting* gradient of depth)
                      zti_g_raw = (  zdxrho(ji+ip,jj,jk-kp,1-ip) / zdzrho(ji+ip,jj,jk-kp,kp)      &
-                        &          - ( fsdept(ji+1,jj,jk-kp) - fsdept(ji,jj,jk-kp) ) * r1_e1u(ji,jj)  ) * umask(ji,jj,jk)
-                     ze3_e1    =  fse3w(ji+ip,jj,jk-kp) * r1_e1u(ji,jj) 
+                        &          - ( gdept_n(ji+1,jj,jk-kp) - gdept_n(ji,jj,jk-kp) ) * r1_e1u(ji,jj)  ) * umask(ji,jj,jk)
+                     ze3_e1    =  e3w_n(ji+ip,jj,jk-kp) * r1_e1u(ji,jj) 
                      zti_mlb(ji+ip,jj   ,1-ip,kp) = SIGN( MIN( rn_slpmax, 5.0_wp * ze3_e1  , ABS( zti_g_raw ) ), zti_g_raw )
                   ENDIF
                   !
                   jk = nmln(ji,jj+jp) + 1
-                  IF( jk .GT. mbkt(ji,jj+jp) ) THEN  !ML reaches bottom
+                  IF( jk >  mbkt(ji,jj+jp) ) THEN  !ML reaches bottom
                      ztj_mlb(ji   ,jj+jp,1-jp,kp) = 0.0_wp
                   ELSE
                      ztj_g_raw = (  zdyrho(ji,jj+jp,jk-kp,1-jp) / zdzrho(ji,jj+jp,jk-kp,kp)      &
-                        &      - ( fsdept(ji,jj+1,jk-kp) - fsdept(ji,jj,jk-kp) ) / e2v(ji,jj)  ) * vmask(ji,jj,jk)
-                     ze3_e2    =  fse3w(ji,jj+jp,jk-kp) / e2v(ji,jj)
+                        &      - ( gdept_n(ji,jj+1,jk-kp) - gdept_n(ji,jj,jk-kp) ) / e2v(ji,jj)  ) * vmask(ji,jj,jk)
+                     ze3_e2    =  e3w_n(ji,jj+jp,jk-kp) / e2v(ji,jj)
                      ztj_mlb(ji   ,jj+jp,1-jp,kp) = SIGN( MIN( rn_slpmax, 5.0_wp * ze3_e2  , ABS( ztj_g_raw ) ), ztj_g_raw )
                   ENDIF
@@ -523,11 +553,11 @@
                      !
                      ! Must mask contribution to slope for triad jk=1,kp=0 that poke up though ocean surface
-                     zti_coord = znot_thru_surface * ( fsdept(ji+1,jj  ,jk) - fsdept(ji,jj,jk) ) * r1_e1u(ji,jj)
-                     ztj_coord = znot_thru_surface * ( fsdept(ji  ,jj+1,jk) - fsdept(ji,jj,jk) ) * r1_e2v(ji,jj)     ! unmasked
+                     zti_coord = znot_thru_surface * ( gdept_n(ji+1,jj  ,jk) - gdept_n(ji,jj,jk) ) * r1_e1u(ji,jj)
+                     ztj_coord = znot_thru_surface * ( gdept_n(ji  ,jj+1,jk) - gdept_n(ji,jj,jk) ) * r1_e2v(ji,jj)     ! unmasked
                      zti_g_raw = zti_raw - zti_coord      ! ref to geopot surfaces
                      ztj_g_raw = ztj_raw - ztj_coord
                      ! additional limit required in bilaplacian case
-                     ze3_e1    = fse3w(ji+ip,jj   ,jk+kp) * r1_e1u(ji,jj)
-                     ze3_e2    = fse3w(ji   ,jj+jp,jk+kp) * r1_e2v(ji,jj)
+                     ze3_e1    = e3w_n(ji+ip,jj   ,jk+kp) * r1_e1u(ji,jj)
+                     ze3_e2    = e3w_n(ji   ,jj+jp,jk+kp) * r1_e2v(ji,jj)
                      ! NB: hard coded factor 5 (can be a namelist parameter...)
                      zti_g_lim = SIGN( MIN( rn_slpmax, 5.0_wp * ze3_e1, ABS( zti_g_raw ) ), zti_g_raw )
@@ -542,8 +572,8 @@
                      zti_g_lim =          ( zfacti   * zti_g_lim                       &
                         &      + ( 1._wp - zfacti ) * zti_mlb(ji+ip,jj,1-ip,kp)   &
-                        &                           * fsdepw(ji+ip,jj,jk+kp) * z1_mlbw(ji+ip,jj) ) * umask(ji,jj,jk+kp)
+                        &                           * gdepw_n(ji+ip,jj,jk+kp) * z1_mlbw(ji+ip,jj) ) * umask(ji,jj,jk+kp)
                      ztj_g_lim =          ( zfactj   * ztj_g_lim                       &
                         &      + ( 1._wp - zfactj ) * ztj_mlb(ji,jj+jp,1-jp,kp)   &
-                        &                           * fsdepw(ji,jj+jp,jk+kp) * z1_mlbw(ji,jj+jp) ) * vmask(ji,jj,jk+kp)
+                        &                           * gdepw_n(ji,jj+jp,jk+kp) * z1_mlbw(ji,jj+jp) ) * vmask(ji,jj,jk+kp)
                      !
                      triadi_g(ji+ip,jj   ,jk,1-ip,kp) = zti_g_lim
@@ -577,8 +607,8 @@
                      triadj(ji   ,jj+jp,jk,1-jp,kp) = ztj_lim * zjsw
                      !
-                     zbu  = e1e2u(ji   ,jj   ) * fse3u(ji   ,jj   ,jk   )
-                     zbv  = e1e2v(ji   ,jj   ) * fse3v(ji   ,jj   ,jk   )
-                     zbti = e1e2t(ji+ip,jj   ) * fse3w(ji+ip,jj   ,jk+kp)
-                     zbtj = e1e2t(ji   ,jj+jp) * fse3w(ji   ,jj+jp,jk+kp)
+                     zbu  = e1e2u(ji   ,jj   ) * e3u_n(ji   ,jj   ,jk   )
+                     zbv  = e1e2v(ji   ,jj   ) * e3v_n(ji   ,jj   ,jk   )
+                     zbti = e1e2t(ji+ip,jj   ) * e3w_n(ji+ip,jj   ,jk+kp)
+                     zbtj = e1e2t(ji   ,jj+jp) * e3w_n(ji   ,jj+jp,jk+kp)
                      !
                      wslp2(ji+ip,jj,jk+kp) = wslp2(ji+ip,jj,jk+kp) + 0.25_wp * zbu / zbti * zti_g_lim*zti_g_lim      ! masked
@@ -682,6 +712,6 @@
             !                        !- bound the slopes: abs(zw.)<= 1/100 and zb..<0
             !                           kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
-            zbu = MIN(  zbu , - z1_slpmax * ABS( zau ) , -7.e+3_wp/fse3u(ji,jj,iku)* ABS( zau )  )
-            zbv = MIN(  zbv , - z1_slpmax * ABS( zav ) , -7.e+3_wp/fse3v(ji,jj,ikv)* ABS( zav )  )
+            zbu = MIN(  zbu , - z1_slpmax * ABS( zau ) , -7.e+3_wp/e3u_n(ji,jj,iku)* ABS( zau )  )
+            zbv = MIN(  zbv , - z1_slpmax * ABS( zav ) , -7.e+3_wp/e3v_n(ji,jj,ikv)* ABS( zav )  )
             !                        !- Slope at u- & v-points (uslpml, vslpml)
             uslpml(ji,jj) = zau / ( zbu - zeps ) * umask(ji,jj,iku)
@@ -699,5 +729,5 @@
             zcj = MAX(   vmask(ji,jj-1,ik  ) + vmask(ji,jj,ik  )           &
                &       + vmask(ji,jj-1,ikm1) + vmask(ji,jj,ikm1) , zeps  ) * e2t(ji,jj)
-            zai =    (   p_gru(ji-1,jj,ik  ) + p_gru(ji,jj,ik)           &
+            zai =    (   p_gru(ji-1,jj,ik  ) + p_gru(ji,jj,ik)             &
                &       + p_gru(ji-1,jj,ikm1) + p_gru(ji,jj,ikm1  )  ) / zci  * tmask(ji,jj,ik)
             zaj =    (   p_grv(ji,jj-1,ik  ) + p_grv(ji,jj,ik  )           &
@@ -705,6 +735,6 @@
             !                        !- bound the slopes: abs(zw.)<= 1/100 and zb..<0.
             !                           kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
-            zbi = MIN(  zbw , -100._wp* ABS( zai ) , -7.e+3_wp/fse3w(ji,jj,ik)* ABS( zai )  )
-            zbj = MIN(  zbw , -100._wp* ABS( zaj ) , -7.e+3_wp/fse3w(ji,jj,ik)* ABS( zaj )  )
+            zbi = MIN(  zbw , -100._wp* ABS( zai ) , -7.e+3_wp/e3w_n(ji,jj,ik)* ABS( zai )  )
+            zbj = MIN(  zbw , -100._wp* ABS( zaj ) , -7.e+3_wp/e3w_n(ji,jj,ik)* ABS( zaj )  )
             !                        !- i- & j-slope at w-points (wslpiml, wslpjml)
             wslpiml(ji,jj) = zai / ( zbi - zeps ) * tmask (ji,jj,ik)
@@ -767,5 +797,5 @@
 
          !!gm I no longer understand this.....
-!!gm         IF( (ln_traldf_hor .OR. ln_dynldf_hor) .AND. .NOT. (lk_vvl .AND. ln_rstart) ) THEN
+!!gm         IF( (ln_traldf_hor .OR. ln_dynldf_hor) .AND. .NOT. (.NOT.ln_linssh .AND. ln_rstart) ) THEN
 !            IF(lwp)   WRITE(numout,*) '          Horizontal mixing in s-coordinate: slope = slope of s-surfaces'
 !
@@ -775,12 +805,12 @@
 !
 !            ! set the slope of diffusion to the slope of s-surfaces
-!            !      ( c a u t i o n : minus sign as fsdep has positive value )
+!            !      ( c a u t i o n : minus sign as dep has positive value )
 !            DO jk = 1, jpk
 !               DO jj = 2, jpjm1
 !                  DO ji = fs_2, fs_jpim1   ! vector opt.
-!                     uslp (ji,jj,jk) = - ( fsdept(ji+1,jj,jk) - fsdept(ji ,jj ,jk) ) * r1_e1u(ji,jj) * umask(ji,jj,jk)
-!                     vslp (ji,jj,jk) = - ( fsdept(ji,jj+1,jk) - fsdept(ji ,jj ,jk) ) * r1_e2v(ji,jj) * vmask(ji,jj,jk)
-!                     wslpi(ji,jj,jk) = - ( fsdepw(ji+1,jj,jk) - fsdepw(ji-1,jj,jk) ) * r1_e1t(ji,jj) * wmask(ji,jj,jk) * 0.5
-!                     wslpj(ji,jj,jk) = - ( fsdepw(ji,jj+1,jk) - fsdepw(ji,jj-1,jk) ) * r1_e2t(ji,jj) * wmask(ji,jj,jk) * 0.5
+!                     uslp (ji,jj,jk) = - ( gdept_n(ji+1,jj,jk) - gdept_n(ji ,jj ,jk) ) * r1_e1u(ji,jj) * umask(ji,jj,jk)
+!                     vslp (ji,jj,jk) = - ( gdept_n(ji,jj+1,jk) - gdept_n(ji ,jj ,jk) ) * r1_e2v(ji,jj) * vmask(ji,jj,jk)
+!                     wslpi(ji,jj,jk) = - ( gdepw_n(ji+1,jj,jk) - gdepw_n(ji-1,jj,jk) ) * r1_e1t(ji,jj) * wmask(ji,jj,jk) * 0.5
+!                     wslpj(ji,jj,jk) = - ( gdepw_n(ji,jj+1,jk) - gdepw_n(ji,jj-1,jk) ) * r1_e2t(ji,jj) * wmask(ji,jj,jk) * 0.5
 !                  END DO
 !               END DO
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/LDF/ldftra.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/LDF/ldftra.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/LDF/ldftra.F90	(revision 6140)
@@ -81,5 +81,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -515,9 +514,9 @@
                   ! internal Rossby radius Ro = .5 * sum_jpk(N) / f 
                   zn2 = MAX( rn2b(ji,jj,jk), 0._wp )
-                  zn(ji,jj) = zn(ji,jj) + SQRT( zn2 ) * fse3w(ji,jj,jk)
+                  zn(ji,jj) = zn(ji,jj) + SQRT( zn2 ) * e3w_n(ji,jj,jk)
                   ! Compute elements required for the inverse time scale of baroclinic
                   ! eddies using the isopycnal slopes calculated in ldfslp.F : 
                   ! T^-1 = sqrt(m_jpk(N^2*(r1^2+r2^2)*e3w))
-                  ze3w = fse3w(ji,jj,jk) * tmask(ji,jj,jk)
+                  ze3w = e3w_n(ji,jj,jk) * tmask(ji,jj,jk)
                   zah(ji,jj) = zah(ji,jj) + zn2 * wslp2(ji,jj,jk) * ze3w
                   zhw(ji,jj) = zhw(ji,jj) + ze3w
@@ -533,9 +532,9 @@
                   ! internal Rossby radius Ro = .5 * sum_jpk(N) / f 
                   zn2 = MAX( rn2b(ji,jj,jk), 0._wp )
-                  zn(ji,jj) = zn(ji,jj) + SQRT( zn2 ) * fse3w(ji,jj,jk)
+                  zn(ji,jj) = zn(ji,jj) + SQRT( zn2 ) * e3w_n(ji,jj,jk)
                   ! Compute elements required for the inverse time scale of baroclinic
                   ! eddies using the isopycnal slopes calculated in ldfslp.F : 
                   ! T^-1 = sqrt(m_jpk(N^2*(r1^2+r2^2)*e3w))
-                  ze3w = fse3w(ji,jj,jk) * tmask(ji,jj,jk)
+                  ze3w = e3w_n(ji,jj,jk) * tmask(ji,jj,jk)
                   zah(ji,jj) = zah(ji,jj) + zn2 * ( wslpi(ji,jj,jk) * wslpi(ji,jj,jk)   &
                      &                            + wslpj(ji,jj,jk) * wslpj(ji,jj,jk) ) * ze3w
@@ -711,10 +710,10 @@
       !
       DO jk = 1, jpkm1                                         ! e2u e3u u_eiv = -dk[psi_uw]
-         zw3d(:,:,jk) = ( psi_uw(:,:,jk+1) - psi_uw(:,:,jk) ) / ( e2u(:,:) * fse3u(:,:,jk) )
+         zw3d(:,:,jk) = ( psi_uw(:,:,jk+1) - psi_uw(:,:,jk) ) / ( e2u(:,:) * e3u_n(:,:,jk) )
       END DO
       CALL iom_put( "uoce_eiv", zw3d )
       !
       DO jk = 1, jpkm1                                         ! e1v e3v v_eiv = -dk[psi_vw]
-         zw3d(:,:,jk) = ( psi_vw(:,:,jk+1) - psi_vw(:,:,jk) ) / ( e1v(:,:) * fse3v(:,:,jk) )
+         zw3d(:,:,jk) = ( psi_vw(:,:,jk+1) - psi_vw(:,:,jk) ) / ( e1v(:,:) * e3v_n(:,:,jk) )
       END DO
       CALL iom_put( "voce_eiv", zw3d )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 6140)
@@ -7,13 +7,12 @@
 
    !!----------------------------------------------------------------------
-   !!   'key_diaobs' : Switch on the observation diagnostic computation
-   !!----------------------------------------------------------------------
    !!   dia_obs_init : Reading and prepare observations
    !!   dia_obs      : Compute model equivalent to observations
    !!   dia_obs_wri  : Write observational diagnostics
+   !!   calc_date    : Compute the date of timestep in YYYYMMDD.HHMMSS format
    !!   ini_date     : Compute the initial date YYYYMMDD.HHMMSS
    !!   fin_date     : Compute the final date YYYYMMDD.HHMMSS
    !!----------------------------------------------------------------------
-   !! * Modules used   
+   !! * Modules used
    USE wrk_nemo                 ! Memory Allocation
    USE par_kind                 ! Precision variables
@@ -21,11 +20,8 @@
    USE par_oce
    USE dom_oce                  ! Ocean space and time domain variables
-   USE obs_fbm, ONLY: ln_cl4    ! Class 4 diagnostic switch
-   USE obs_read_prof            ! Reading and allocation of observations (Coriolis)
-   USE obs_read_sla             ! Reading and allocation of SLA observations  
-   USE obs_read_sst             ! Reading and allocation of SST observations  
+   USE obs_read_prof            ! Reading and allocation of profile obs
+   USE obs_read_surf            ! Reading and allocation of surface obs
+   USE obs_sstbias              ! Bias correction routine for SST 
    USE obs_readmdt              ! Reading and allocation of MDT for SLA.
-   USE obs_read_seaice          ! Reading and allocation of Sea Ice observations  
-   USE obs_read_vel             ! Reading and allocation of velocity component observations
    USE obs_prep                 ! Preparation of obs. (grid search etc).
    USE obs_oper                 ! Observation operators
@@ -34,9 +30,5 @@
    USE obs_read_altbias         ! Bias treatment for altimeter
    USE obs_profiles_def         ! Profile data definitions
-   USE obs_profiles             ! Profile data storage
    USE obs_surf_def             ! Surface data definitions
-   USE obs_sla                  ! SLA data storage
-   USE obs_sst                  ! SST data storage
-   USE obs_seaice               ! Sea Ice data storage
    USE obs_types                ! Definitions for observation types
    USE mpp_map                  ! MPP mapping
@@ -50,65 +42,34 @@
       &   dia_obs,      &  ! Compute model equivalent to observations
       &   dia_obs_wri,  &  ! Write model equivalent to observations
-      &   dia_obs_dealloc  ! Deallocate dia_obs data
-
-   !! * Shared Module variables
-   LOGICAL, PUBLIC, PARAMETER :: &
-#if defined key_diaobs
-      & lk_diaobs = .TRUE.   !: Logical switch for observation diangostics
-#else
-      & lk_diaobs = .FALSE.  !: Logical switch for observation diangostics
-#endif
+      &   dia_obs_dealloc, &  ! Deallocate dia_obs data
+      &   calc_date           ! Compute the date of a timestep
 
    !! * Module variables
-   LOGICAL, PUBLIC :: ln_t3d         !: Logical switch for temperature profiles
-   LOGICAL, PUBLIC :: ln_s3d         !: Logical switch for salinity profiles
-   LOGICAL, PUBLIC :: ln_ena         !: Logical switch for the ENACT data set
-   LOGICAL, PUBLIC :: ln_cor         !: Logical switch for the Coriolis data set
-   LOGICAL, PUBLIC :: ln_profb       !: Logical switch for profile feedback datafiles
-   LOGICAL, PUBLIC :: ln_sla         !: Logical switch for sea level anomalies 
-   LOGICAL, PUBLIC :: ln_sladt       !: Logical switch for SLA from AVISO files
-   LOGICAL, PUBLIC :: ln_slafb       !: Logical switch for SLA from feedback files
-   LOGICAL, PUBLIC :: ln_sst         !: Logical switch for sea surface temperature
-   LOGICAL, PUBLIC :: ln_reysst      !: Logical switch for Reynolds sea surface temperature
-   LOGICAL, PUBLIC :: ln_ghrsst      !: Logical switch for GHRSST data
-   LOGICAL, PUBLIC :: ln_sstfb       !: Logical switch for SST from feedback files
-   LOGICAL, PUBLIC :: ln_seaice      !: Logical switch for sea ice concentration
-   LOGICAL, PUBLIC :: ln_vel3d       !: Logical switch for velocity component (u,v) observations
-   LOGICAL, PUBLIC :: ln_velavcur    !: Logical switch for raw daily averaged netCDF current meter vel. data 
-   LOGICAL, PUBLIC :: ln_velhrcur    !: Logical switch for raw high freq netCDF current meter vel. data 
-   LOGICAL, PUBLIC :: ln_velavadcp   !: Logical switch for raw daily averaged netCDF ADCP vel. data 
-   LOGICAL, PUBLIC :: ln_velhradcp   !: Logical switch for raw high freq netCDF ADCP vel. data 
-   LOGICAL, PUBLIC :: ln_velfb       !: Logical switch for velocities from feedback files
-   LOGICAL, PUBLIC :: ln_ssh         !: Logical switch for sea surface height
-   LOGICAL, PUBLIC :: ln_sss         !: Logical switch for sea surface salinity
-   LOGICAL, PUBLIC :: ln_sstnight    !: Logical switch for night mean SST observations
-   LOGICAL, PUBLIC :: ln_nea         !: Remove observations near land
-   LOGICAL, PUBLIC :: ln_altbias     !: Logical switch for altimeter bias  
-   LOGICAL, PUBLIC :: ln_ignmis      !: Logical switch for ignoring missing files
-   LOGICAL, PUBLIC :: ln_s_at_t      !: Logical switch to compute model S at T observations
-
-   REAL(KIND=dp), PUBLIC :: dobsini   !: Observation window start date YYYYMMDD.HHMMSS
-   REAL(KIND=dp), PUBLIC :: dobsend   !: Observation window end date YYYYMMDD.HHMMSS
-  
-   INTEGER, PUBLIC :: n1dint       !: Vertical interpolation method
-   INTEGER, PUBLIC :: n2dint       !: Horizontal interpolation method 
-
+   LOGICAL, PUBLIC :: ln_diaobs   !: Logical switch for the obs operator
+   LOGICAL :: ln_sstnight         !: Logical switch for night mean SST obs
+   
+   INTEGER :: nn_1dint       !: Vertical interpolation method
+   INTEGER :: nn_2dint       !: Horizontal interpolation method
    INTEGER, DIMENSION(imaxavtypes) :: &
-      & endailyavtypes !: ENACT data types which are daily average
-
-   INTEGER, PARAMETER :: MaxNumFiles = 1000
-   LOGICAL, DIMENSION(MaxNumFiles) :: &
-      & ln_profb_ena, & !: Is the feedback files from ENACT data ?
-   !                    !: If so use endailyavtypes
-      & ln_profb_enatim !: Change tim for 820 enact data set.
-   
-   LOGICAL, DIMENSION(MaxNumFiles) :: &
-      & ln_velfb_av   !: Is the velocity feedback files daily average?
-   LOGICAL, DIMENSION(:), ALLOCATABLE :: &
-      & ld_enact     !: Profile data is ENACT so use endailyavtypes
-   LOGICAL, DIMENSION(:), ALLOCATABLE :: &
-      & ld_velav     !: Velocity data is daily averaged
-   LOGICAL, DIMENSION(:), ALLOCATABLE :: &
-      & ld_sstnight  !: SST observation corresponds to night mean
+      & nn_profdavtypes      !: Profile data types representing a daily average
+   INTEGER :: nproftypes     !: Number of profile obs types
+   INTEGER :: nsurftypes     !: Number of surface obs types
+   INTEGER, DIMENSION(:), ALLOCATABLE :: &
+      & nvarsprof, &         !: Number of profile variables
+      & nvarssurf            !: Number of surface variables
+   INTEGER, DIMENSION(:), ALLOCATABLE :: &
+      & nextrprof, &         !: Number of profile extra variables
+      & nextrsurf            !: Number of surface extra variables
+   INTEGER, PUBLIC, ALLOCATABLE, DIMENSION(:) :: sstbias_type !SST bias type    
+   TYPE(obs_surf), PUBLIC, POINTER, DIMENSION(:) :: &
+      & surfdata, &          !: Initial surface data
+      & surfdataqc           !: Surface data after quality control
+   TYPE(obs_prof), PUBLIC, POINTER, DIMENSION(:) :: &
+      & profdata, &          !: Initial profile data
+      & profdataqc           !: Profile data after quality control
+
+   CHARACTER(len=6), PUBLIC, DIMENSION(:), ALLOCATABLE :: &
+      & cobstypesprof, &     !: Profile obs types
+      & cobstypessurf        !: Surface obs types
 
    !!----------------------------------------------------------------------
@@ -135,4 +96,6 @@
       !!        !  06-10  (A. Weaver) Cleaning and add controls
       !!        !  07-03  (K. Mogensen) General handling of profiles
+      !!        !  14-08  (J.While) Incorporated SST bias correction  
+      !!        !  15-02  (M. Martin) Simplification of namelist and code
       !!----------------------------------------------------------------------
 
@@ -140,184 +103,208 @@
 
       !! * Local declarations
-      CHARACTER(len=128) :: enactfiles(MaxNumFiles)
-      CHARACTER(len=128) :: coriofiles(MaxNumFiles)
-      CHARACTER(len=128) :: profbfiles(MaxNumFiles)
-      CHARACTER(len=128) :: sstfiles(MaxNumFiles)      
-      CHARACTER(len=128) :: sstfbfiles(MaxNumFiles) 
-      CHARACTER(len=128) :: slafilesact(MaxNumFiles)      
-      CHARACTER(len=128) :: slafilespas(MaxNumFiles)      
-      CHARACTER(len=128) :: slafbfiles(MaxNumFiles)
-      CHARACTER(len=128) :: seaicefiles(MaxNumFiles)           
-      CHARACTER(len=128) :: velcurfiles(MaxNumFiles)  
-      CHARACTER(len=128) :: veladcpfiles(MaxNumFiles)    
-      CHARACTER(len=128) :: velavcurfiles(MaxNumFiles)
-      CHARACTER(len=128) :: velhrcurfiles(MaxNumFiles)
-      CHARACTER(len=128) :: velavadcpfiles(MaxNumFiles)
-      CHARACTER(len=128) :: velhradcpfiles(MaxNumFiles)
-      CHARACTER(len=128) :: velfbfiles(MaxNumFiles)
-      CHARACTER(LEN=128) :: reysstname
-      CHARACTER(LEN=12)  :: reysstfmt
-      CHARACTER(LEN=128) :: bias_file
-      CHARACTER(LEN=20)  :: datestr=" ", timestr=" "
-      NAMELIST/namobs/ln_ena, ln_cor, ln_profb, ln_t3d, ln_s3d,       &
-         &            ln_sla, ln_sladt, ln_slafb,                     &
-         &            ln_ssh, ln_sst, ln_sstfb, ln_sss, ln_nea,       &
-         &            enactfiles, coriofiles, profbfiles,             &
-         &            slafilesact, slafilespas, slafbfiles,           &
-         &            sstfiles, sstfbfiles,                           &
-         &            ln_seaice, seaicefiles,                         &
-         &            dobsini, dobsend, n1dint, n2dint,               &
-         &            nmsshc, mdtcorr, mdtcutoff,                     &
-         &            ln_reysst, ln_ghrsst, reysstname, reysstfmt,    &
-         &            ln_sstnight,                                    &
+      INTEGER, PARAMETER :: &
+         & jpmaxnfiles = 1000    ! Maximum number of files for each obs type
+      INTEGER, DIMENSION(:), ALLOCATABLE :: &
+         & ifilesprof, &         ! Number of profile files
+         & ifilessurf            ! Number of surface files
+      INTEGER :: ios             ! Local integer output status for namelist read
+      INTEGER :: jtype           ! Counter for obs types
+      INTEGER :: jvar            ! Counter for variables
+      INTEGER :: jfile           ! Counter for files
+
+      CHARACTER(len=128), DIMENSION(jpmaxnfiles) :: &
+         & cn_profbfiles, &      ! T/S profile input filenames
+         & cn_sstfbfiles, &      ! Sea surface temperature input filenames
+         & cn_slafbfiles, &      ! Sea level anomaly input filenames
+         & cn_sicfbfiles, &      ! Seaice concentration input filenames
+         & cn_velfbfiles, &      ! Velocity profile input filenames
+         & cn_sstbias_files      ! SST bias input filenames
+      CHARACTER(LEN=128) :: &
+         & cn_altbiasfile        ! Altimeter bias input filename
+      CHARACTER(len=128), DIMENSION(:,:), ALLOCATABLE :: &
+         & clproffiles, &        ! Profile filenames
+         & clsurffiles           ! Surface filenames
+
+      LOGICAL :: ln_t3d          ! Logical switch for temperature profiles
+      LOGICAL :: ln_s3d          ! Logical switch for salinity profiles
+      LOGICAL :: ln_sla          ! Logical switch for sea level anomalies 
+      LOGICAL :: ln_sst          ! Logical switch for sea surface temperature
+      LOGICAL :: ln_sic          ! Logical switch for sea ice concentration
+      LOGICAL :: ln_vel3d        ! Logical switch for velocity (u,v) obs
+      LOGICAL :: ln_nea          ! Logical switch to remove obs near land
+      LOGICAL :: ln_altbias      ! Logical switch for altimeter bias
+      LOGICAL :: ln_sstbias     !: Logical switch for bias corection of SST 
+      LOGICAL :: ln_ignmis       ! Logical switch for ignoring missing files
+      LOGICAL :: ln_s_at_t       ! Logical switch to compute model S at T obs
+      LOGICAL :: llvar1          ! Logical for profile variable 1
+      LOGICAL :: llvar2          ! Logical for profile variable 1
+      LOGICAL :: llnightav       ! Logical for calculating night-time averages
+      LOGICAL, DIMENSION(jpmaxnfiles) :: lmask ! Used for finding number of sstbias files
+
+      REAL(dp) :: rn_dobsini     ! Obs window start date YYYYMMDD.HHMMSS
+      REAL(dp) :: rn_dobsend     ! Obs window end date   YYYYMMDD.HHMMSS
+      REAL(wp), POINTER, DIMENSION(:,:) :: &
+         & zglam1, &             ! Model longitudes for profile variable 1
+         & zglam2                ! Model longitudes for profile variable 2
+      REAL(wp), POINTER, DIMENSION(:,:) :: &
+         & zgphi1, &             ! Model latitudes for profile variable 1
+         & zgphi2                ! Model latitudes for profile variable 2
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: &
+         & zmask1, &             ! Model land/sea mask associated with variable 1
+         & zmask2                ! Model land/sea mask associated with variable 2
+
+      NAMELIST/namobs/ln_diaobs, ln_t3d, ln_s3d, ln_sla,              &
+         &            ln_sst, ln_sic, ln_vel3d,                       &
+         &            ln_altbias, ln_nea, ln_grid_global,             &
          &            ln_grid_search_lookup,                          &
-         &            grid_search_file, grid_search_res,              &
-         &            ln_grid_global, bias_file, ln_altbias,          &
-         &            endailyavtypes, ln_s_at_t, ln_profb_ena,        &
-         &            ln_vel3d, ln_velavcur, velavcurfiles,           &
-         &            ln_velhrcur, velhrcurfiles,                     &
-         &            ln_velavadcp, velavadcpfiles,                   &
-         &            ln_velhradcp, velhradcpfiles,                   &
-         &            ln_velfb, velfbfiles, ln_velfb_av,              &
-         &            ln_profb_enatim, ln_ignmis, ln_cl4
-
-      INTEGER :: jprofset
-      INTEGER :: jveloset
-      INTEGER :: jvar
-      INTEGER :: jnumenact
-      INTEGER :: jnumcorio
-      INTEGER :: jnumprofb
-      INTEGER :: jnumslaact
-      INTEGER :: jnumslapas
-      INTEGER :: jnumslafb
-      INTEGER :: jnumsst
-      INTEGER :: jnumsstfb
-      INTEGER :: jnumseaice
-      INTEGER :: jnumvelavcur
-      INTEGER :: jnumvelhrcur  
-      INTEGER :: jnumvelavadcp
-      INTEGER :: jnumvelhradcp   
-      INTEGER :: jnumvelfb
-      INTEGER :: ji
-      INTEGER :: jset
-      INTEGER :: ios                 ! Local integer output status for namelist read
-      LOGICAL :: lmask(MaxNumFiles), ll_u3d, ll_v3d
+         &            ln_ignmis, ln_s_at_t, ln_sstnight,              &
+         &            cn_profbfiles, cn_slafbfiles,                   &
+         &            cn_sstfbfiles, cn_sicfbfiles,                   &
+         &            cn_velfbfiles, cn_altbiasfile,                  &
+         &            cn_gridsearchfile, rn_gridsearchres,            &
+         &            rn_dobsini, rn_dobsend, nn_1dint, nn_2dint,     &
+         &            nn_msshc, rn_mdtcorr, rn_mdtcutoff,             &
+         &            nn_profdavtypes, ln_sstbias, cn_sstbias_files
+
+      INTEGER :: jnumsstbias
+      CALL wrk_alloc( jpi, jpj, zglam1 )
+      CALL wrk_alloc( jpi, jpj, zglam2 )
+      CALL wrk_alloc( jpi, jpj, zgphi1 )
+      CALL wrk_alloc( jpi, jpj, zgphi2 )
+      CALL wrk_alloc( jpi, jpj, jpk, zmask1 )
+      CALL wrk_alloc( jpi, jpj, jpk, zmask2 )
 
       !-----------------------------------------------------------------------
       ! Read namelist parameters
       !-----------------------------------------------------------------------
-
-      enactfiles(:) = ''
-      coriofiles(:) = ''
-      profbfiles(:) = ''
-      slafilesact(:) = ''
-      slafilespas(:) = ''
-      slafbfiles(:) = ''
-      sstfiles(:)   = ''
-      sstfbfiles(:) = ''
-      seaicefiles(:) = ''
-      velcurfiles(:) = ''
-      veladcpfiles(:) = ''
-      velavcurfiles(:) = ''
-      velhrcurfiles(:) = ''
-      velavadcpfiles(:) = ''
-      velhradcpfiles(:) = ''
-      velfbfiles(:) = ''
-      velcurfiles(:) = ''
-      veladcpfiles(:) = ''
-      endailyavtypes(:) = -1
-      endailyavtypes(1) = 820
-      ln_profb_ena(:) = .FALSE.
-      ln_profb_enatim(:) = .TRUE.
-      ln_velfb_av(:) = .FALSE.
-      ln_ignmis = .FALSE.
       
-      CALL ini_date( dobsini )
-      CALL fin_date( dobsend )
- 
-      ! Read Namelist namobs : control observation diagnostics
-      REWIND( numnam_ref )              ! Namelist namobs in reference namelist : Diagnostic: control observation
+      !Initalise all values in namelist arrays
+      ALLOCATE(sstbias_type(jpmaxnfiles))
+      ! Some namelist arrays need initialising
+      cn_profbfiles(:) = ''
+      cn_slafbfiles(:) = ''
+      cn_sstfbfiles(:) = ''
+      cn_sicfbfiles(:) = ''
+      cn_velfbfiles(:) = ''
+      cn_sstbias_files(:) = ''
+      nn_profdavtypes(:) = -1
+
+      CALL ini_date( rn_dobsini )
+      CALL fin_date( rn_dobsend )
+
+      ! Read namelist namobs : control observation diagnostics
+      REWIND( numnam_ref )   ! Namelist namobs in reference namelist
       READ  ( numnam_ref, namobs, IOSTAT = ios, ERR = 901)
 901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namobs in reference namelist', lwp )
 
-      REWIND( numnam_cfg )              ! Namelist namobs in configuration namelist : Diagnostic: control observation
+      REWIND( numnam_cfg )   ! Namelist namobs in configuration namelist
       READ  ( numnam_cfg, namobs, IOSTAT = ios, ERR = 902 )
 902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namobs in configuration namelist', lwp )
       IF(lwm) WRITE ( numond, namobs )
 
-      ! Count number of files for each type
-      IF (ln_ena) THEN
-         lmask(:) = .FALSE.
-         WHERE (enactfiles(:) /= '') lmask(:) = .TRUE.
-         jnumenact = COUNT(lmask)
-      ENDIF
-      IF (ln_cor) THEN
-         lmask(:) = .FALSE.
-         WHERE (coriofiles(:) /= '') lmask(:) = .TRUE.
-         jnumcorio = COUNT(lmask)
-      ENDIF
-      IF (ln_profb) THEN
-         lmask(:) = .FALSE.
-         WHERE (profbfiles(:) /= '') lmask(:) = .TRUE.
-         jnumprofb = COUNT(lmask)
-      ENDIF
-      IF (ln_sladt) THEN
-         lmask(:) = .FALSE.
-         WHERE (slafilesact(:) /= '') lmask(:) = .TRUE.
-         jnumslaact = COUNT(lmask)
-         lmask(:) = .FALSE.
-         WHERE (slafilespas(:) /= '') lmask(:) = .TRUE.
-         jnumslapas = COUNT(lmask)
-      ENDIF
-      IF (ln_slafb) THEN
-         lmask(:) = .FALSE.
-         WHERE (slafbfiles(:) /= '') lmask(:) = .TRUE.
-         jnumslafb = COUNT(lmask)
-         lmask(:) = .FALSE.
-      ENDIF
-      IF (ln_ghrsst) THEN
-         lmask(:) = .FALSE.
-         WHERE (sstfiles(:) /= '') lmask(:) = .TRUE.
-         jnumsst = COUNT(lmask)
+      IF ( .NOT. ln_diaobs ) THEN
+         IF(lwp) WRITE(numout,cform_war)
+         IF(lwp) WRITE(numout,*)' ln_diaobs is set to false so not calling dia_obs'
+         RETURN
+      ENDIF
+      
+      !-----------------------------------------------------------------------
+      ! Set up list of observation types to be used
+      ! and the files associated with each type
+      !-----------------------------------------------------------------------
+
+      nproftypes = COUNT( (/ln_t3d .OR. ln_s3d, ln_vel3d /) )
+      nsurftypes = COUNT( (/ln_sla, ln_sst, ln_sic /) )
+
+      IF (ln_sstbias) THEN 
+         lmask(:) = .FALSE. 
+         WHERE (cn_sstbias_files(:) /= '') lmask(:) = .TRUE. 
+         jnumsstbias = COUNT(lmask) 
+         lmask(:) = .FALSE. 
       ENDIF      
-      IF (ln_sstfb) THEN
-         lmask(:) = .FALSE.
-         WHERE (sstfbfiles(:) /= '') lmask(:) = .TRUE.
-         jnumsstfb = COUNT(lmask)
-         lmask(:) = .FALSE.
-      ENDIF
-      IF (ln_seaice) THEN
-         lmask(:) = .FALSE.
-         WHERE (seaicefiles(:) /= '') lmask(:) = .TRUE.
-         jnumseaice = COUNT(lmask)
-      ENDIF
-      IF (ln_velavcur) THEN
-         lmask(:) = .FALSE.
-         WHERE (velavcurfiles(:) /= '') lmask(:) = .TRUE.
-         jnumvelavcur = COUNT(lmask)
-      ENDIF
-      IF (ln_velhrcur) THEN
-         lmask(:) = .FALSE.
-         WHERE (velhrcurfiles(:) /= '') lmask(:) = .TRUE.
-         jnumvelhrcur = COUNT(lmask)
-      ENDIF
-      IF (ln_velavadcp) THEN
-         lmask(:) = .FALSE.
-         WHERE (velavadcpfiles(:) /= '') lmask(:) = .TRUE.
-         jnumvelavadcp = COUNT(lmask)
-      ENDIF
-      IF (ln_velhradcp) THEN
-         lmask(:) = .FALSE.
-         WHERE (velhradcpfiles(:) /= '') lmask(:) = .TRUE.
-         jnumvelhradcp = COUNT(lmask)
-      ENDIF
-      IF (ln_velfb) THEN
-         lmask(:) = .FALSE.
-         WHERE (velfbfiles(:) /= '') lmask(:) = .TRUE.
-         jnumvelfb = COUNT(lmask)
-         lmask(:) = .FALSE.
-      ENDIF
-      
-      ! Control print
+
+      IF ( nproftypes == 0 .AND. nsurftypes == 0 ) THEN
+         IF(lwp) WRITE(numout,cform_war)
+         IF(lwp) WRITE(numout,*) ' ln_diaobs is set to true, but all obs operator logical flags', &
+            &                    ' ln_t3d, ln_s3d, ln_sla, ln_sst, ln_sic, ln_vel3d', &
+            &                    ' are set to .FALSE. so turning off calls to dia_obs'
+         nwarn = nwarn + 1
+         ln_diaobs = .FALSE.
+         RETURN
+      ENDIF
+
+      IF ( nproftypes > 0 ) THEN
+
+         ALLOCATE( cobstypesprof(nproftypes) )
+         ALLOCATE( ifilesprof(nproftypes) )
+         ALLOCATE( clproffiles(nproftypes,jpmaxnfiles) )
+
+         jtype = 0
+         IF (ln_t3d .OR. ln_s3d) THEN
+            jtype = jtype + 1
+            clproffiles(jtype,:) = cn_profbfiles(:)
+            cobstypesprof(jtype) = 'prof  '
+            ifilesprof(jtype) = 0
+            DO jfile = 1, jpmaxnfiles
+               IF ( trim(clproffiles(jtype,jfile)) /= '' ) &
+                  ifilesprof(jtype) = ifilesprof(jtype) + 1
+            END DO
+         ENDIF
+         IF (ln_vel3d) THEN
+            jtype = jtype + 1
+            clproffiles(jtype,:) = cn_velfbfiles(:)
+            cobstypesprof(jtype) = 'vel   '
+            ifilesprof(jtype) = 0
+            DO jfile = 1, jpmaxnfiles
+               IF ( trim(clproffiles(jtype,jfile)) /= '' ) &
+                  ifilesprof(jtype) = ifilesprof(jtype) + 1
+            END DO
+         ENDIF
+
+      ENDIF
+
+      IF ( nsurftypes > 0 ) THEN
+
+         ALLOCATE( cobstypessurf(nsurftypes) )
+         ALLOCATE( ifilessurf(nsurftypes) )
+         ALLOCATE( clsurffiles(nsurftypes, jpmaxnfiles) )
+
+         jtype = 0
+         IF (ln_sla) THEN
+            jtype = jtype + 1
+            clsurffiles(jtype,:) = cn_slafbfiles(:)
+            cobstypessurf(jtype) = 'sla   '
+            ifilessurf(jtype) = 0
+            DO jfile = 1, jpmaxnfiles
+               IF ( trim(clsurffiles(jtype,jfile)) /= '' ) &
+                  ifilessurf(jtype) = ifilessurf(jtype) + 1
+            END DO
+         ENDIF
+         IF (ln_sst) THEN
+            jtype = jtype + 1
+            clsurffiles(jtype,:) = cn_sstfbfiles(:)
+            cobstypessurf(jtype) = 'sst   '
+            ifilessurf(jtype) = 0
+            DO jfile = 1, jpmaxnfiles
+               IF ( trim(clsurffiles(jtype,jfile)) /= '' ) &
+                  ifilessurf(jtype) = ifilessurf(jtype) + 1
+            END DO
+         ENDIF
+#if defined key_lim2 || defined key_lim3
+         IF (ln_sic) THEN
+            jtype = jtype + 1
+            clsurffiles(jtype,:) = cn_sicfbfiles(:)
+            cobstypessurf(jtype) = 'sic   '
+            ifilessurf(jtype) = 0
+            DO jfile = 1, jpmaxnfiles
+               IF ( trim(clsurffiles(jtype,jfile)) /= '' ) &
+                  ifilessurf(jtype) = ifilessurf(jtype) + 1
+            END DO
+         ENDIF
+#endif
+
+      ENDIF
+
+      !Write namelist settings to stdout
       IF(lwp) THEN
          WRITE(numout,*)
@@ -325,138 +312,55 @@
          WRITE(numout,*) '~~~~~~~~~~~~'
          WRITE(numout,*) '          Namelist namobs : set observation diagnostic parameters' 
-         WRITE(numout,*) '             Logical switch for T profile observations          ln_t3d = ', ln_t3d
-         WRITE(numout,*) '             Logical switch for S profile observations          ln_s3d = ', ln_s3d
-         WRITE(numout,*) '             Logical switch for ENACT insitu data set           ln_ena = ', ln_ena
-         WRITE(numout,*) '             Logical switch for Coriolis insitu data set        ln_cor = ', ln_cor
-         WRITE(numout,*) '             Logical switch for feedback insitu data set      ln_profb = ', ln_profb
-         WRITE(numout,*) '             Logical switch for SLA observations                ln_sla = ', ln_sla
-         WRITE(numout,*) '             Logical switch for AVISO SLA data                ln_sladt = ', ln_sladt
-         WRITE(numout,*) '             Logical switch for feedback SLA data             ln_slafb = ', ln_slafb
-         WRITE(numout,*) '             Logical switch for SSH observations                ln_ssh = ', ln_ssh
-         WRITE(numout,*) '             Logical switch for SST observations                ln_sst = ', ln_sst
-         WRITE(numout,*) '             Logical switch for Reynolds observations        ln_reysst = ', ln_reysst    
-         WRITE(numout,*) '             Logical switch for GHRSST observations          ln_ghrsst = ', ln_ghrsst
-         WRITE(numout,*) '             Logical switch for feedback SST data             ln_sstfb = ', ln_sstfb
-         WRITE(numout,*) '             Logical switch for night-time SST obs         ln_sstnight = ', ln_sstnight
-         WRITE(numout,*) '             Logical switch for SSS observations                ln_sss = ', ln_sss
-         WRITE(numout,*) '             Logical switch for Sea Ice observations         ln_seaice = ', ln_seaice
-         WRITE(numout,*) '             Logical switch for velocity observations         ln_vel3d = ', ln_vel3d
-         WRITE(numout,*) '             Logical switch for velocity daily av. cur.    ln_velavcur = ', ln_velavcur
-         WRITE(numout,*) '             Logical switch for velocity high freq. cur.   ln_velhrcur = ', ln_velhrcur
-         WRITE(numout,*) '             Logical switch for velocity daily av. ADCP   ln_velavadcp = ', ln_velavadcp
-         WRITE(numout,*) '             Logical switch for velocity high freq. ADCP  ln_velhradcp = ', ln_velhradcp
-         WRITE(numout,*) '             Logical switch for feedback velocity data        ln_velfb = ', ln_velfb
-         WRITE(numout,*) '             Global distribtion of observations         ln_grid_global = ',ln_grid_global
-         WRITE(numout,*) &
-   '             Logical switch for obs grid search w/lookup table  ln_grid_search_lookup = ',ln_grid_search_lookup
+         WRITE(numout,*) '             Logical switch for T profile observations                ln_t3d = ', ln_t3d
+         WRITE(numout,*) '             Logical switch for S profile observations                ln_s3d = ', ln_s3d
+         WRITE(numout,*) '             Logical switch for SLA observations                      ln_sla = ', ln_sla
+         WRITE(numout,*) '             Logical switch for SST observations                      ln_sst = ', ln_sst
+         WRITE(numout,*) '             Logical switch for Sea Ice observations                  ln_sic = ', ln_sic
+         WRITE(numout,*) '             Logical switch for velocity observations               ln_vel3d = ', ln_vel3d
+         WRITE(numout,*) '             Global distribution of observations              ln_grid_global = ',ln_grid_global
+         WRITE(numout,*) '             Logical switch for SST bias correction         ln_sstbias = ', ln_sstbias 
+         WRITE(numout,*) '             Logical switch for obs grid search lookup ln_grid_search_lookup = ',ln_grid_search_lookup
          IF (ln_grid_search_lookup) &
-            WRITE(numout,*) '             Grid search lookup file header       grid_search_file = ', grid_search_file
-         IF (ln_ena) THEN
-            DO ji = 1, jnumenact
-               WRITE(numout,'(1X,2A)') '             ENACT input observation file name          enactfiles = ', &
-                  TRIM(enactfiles(ji))
+            WRITE(numout,*) '             Grid search lookup file header                cn_gridsearchfile = ', cn_gridsearchfile
+         WRITE(numout,*) '             Initial date in window YYYYMMDD.HHMMSS               rn_dobsini = ', rn_dobsini
+         WRITE(numout,*) '             Final date in window YYYYMMDD.HHMMSS                 rn_dobsend = ', rn_dobsend
+         WRITE(numout,*) '             Type of vertical interpolation method                  nn_1dint = ', nn_1dint
+         WRITE(numout,*) '             Type of horizontal interpolation method                nn_2dint = ', nn_2dint
+         WRITE(numout,*) '             Rejection of observations near land switch               ln_nea = ', ln_nea
+         WRITE(numout,*) '             MSSH correction scheme                                 nn_msshc = ', nn_msshc
+         WRITE(numout,*) '             MDT  correction                                      rn_mdtcorr = ', rn_mdtcorr
+         WRITE(numout,*) '             MDT cutoff for computed correction                 rn_mdtcutoff = ', rn_mdtcutoff
+         WRITE(numout,*) '             Logical switch for alt bias                          ln_altbias = ', ln_altbias
+         WRITE(numout,*) '             Logical switch for ignoring missing files             ln_ignmis = ', ln_ignmis
+         WRITE(numout,*) '             Daily average types                             nn_profdavtypes = ', nn_profdavtypes
+         WRITE(numout,*) '             Logical switch for night-time SST obs               ln_sstnight = ', ln_sstnight
+         WRITE(numout,*) '          Number of profile obs types: ',nproftypes
+
+         IF ( nproftypes > 0 ) THEN
+            DO jtype = 1, nproftypes
+               DO jfile = 1, ifilesprof(jtype)
+                  WRITE(numout,'(1X,2A)') '             '//cobstypesprof(jtype)//' input observation file names  = ', &
+                     TRIM(clproffiles(jtype,jfile))
+               END DO
             END DO
          ENDIF
-         IF (ln_cor) THEN
-            DO ji = 1, jnumcorio
-               WRITE(numout,'(1X,2A)') '             Coriolis input observation file name       coriofiles = ', &
-                  TRIM(coriofiles(ji))
+
+         WRITE(numout,*)'          Number of surface obs types: ',nsurftypes
+         IF ( nsurftypes > 0 ) THEN
+            DO jtype = 1, nsurftypes
+               DO jfile = 1, ifilessurf(jtype)
+                  WRITE(numout,'(1X,2A)') '             '//cobstypessurf(jtype)//' input observation file names  = ', &
+                     TRIM(clsurffiles(jtype,jfile))
+               END DO
             END DO
          ENDIF
-         IF (ln_profb) THEN
-            DO ji = 1, jnumprofb
-               IF (ln_profb_ena(ji)) THEN
-                  WRITE(numout,'(1X,2A)') '       Enact feedback input observation file name       profbfiles = ', &
-                     TRIM(profbfiles(ji))
-               ELSE
-                  WRITE(numout,'(1X,2A)') '             Feedback input observation file name       profbfiles = ', &
-                     TRIM(profbfiles(ji))
-               ENDIF
-               WRITE(numout,'(1X,2A)') '       Enact feedback input time setting switch    ln_profb_enatim = ', ln_profb_enatim(ji)
-            END DO
-         ENDIF
-         IF (ln_sladt) THEN
-            DO ji = 1, jnumslaact
-               WRITE(numout,'(1X,2A)') '             Active SLA input observation file name    slafilesact = ', &
-                  TRIM(slafilesact(ji))
-            END DO
-            DO ji = 1, jnumslapas
-               WRITE(numout,'(1X,2A)') '             Passive SLA input observation file name   slafilespas = ', &
-                  TRIM(slafilespas(ji))
-            END DO
-         ENDIF
-         IF (ln_slafb) THEN
-            DO ji = 1, jnumslafb
-               WRITE(numout,'(1X,2A)') '             Feedback SLA input observation file name   slafbfiles = ', &
-                  TRIM(slafbfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_ghrsst) THEN
-            DO ji = 1, jnumsst
-               WRITE(numout,'(1X,2A)') '             GHRSST input observation file name           sstfiles = ', &
-                  TRIM(sstfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_sstfb) THEN
-            DO ji = 1, jnumsstfb
-               WRITE(numout,'(1X,2A)') '             Feedback SST input observation file name   sstfbfiles = ', &
-                  TRIM(sstfbfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_seaice) THEN
-            DO ji = 1, jnumseaice
-               WRITE(numout,'(1X,2A)') '             Sea Ice input observation file name       seaicefiles = ', &
-                  TRIM(seaicefiles(ji))
-            END DO
-         ENDIF
-         IF (ln_velavcur) THEN
-            DO ji = 1, jnumvelavcur
-               WRITE(numout,'(1X,2A)') '             Vel. cur. daily av. input file name     velavcurfiles = ', &
-                  TRIM(velavcurfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_velhrcur) THEN
-            DO ji = 1, jnumvelhrcur
-               WRITE(numout,'(1X,2A)') '             Vel. cur. high freq. input file name    velhvcurfiles = ', &
-                  TRIM(velhrcurfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_velavadcp) THEN
-            DO ji = 1, jnumvelavadcp
-               WRITE(numout,'(1X,2A)') '             Vel. ADCP daily av. input file name    velavadcpfiles = ', &
-                  TRIM(velavadcpfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_velhradcp) THEN
-            DO ji = 1, jnumvelhradcp
-               WRITE(numout,'(1X,2A)') '             Vel. ADCP high freq. input file name   velhvadcpfiles = ', &
-                  TRIM(velhradcpfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_velfb) THEN
-            DO ji = 1, jnumvelfb
-               IF (ln_velfb_av(ji)) THEN
-                  WRITE(numout,'(1X,2A)') '             Vel. feedback daily av. input file name    velfbfiles = ', &
-                     TRIM(velfbfiles(ji))
-               ELSE
-                  WRITE(numout,'(1X,2A)') '             Vel. feedback input observation file name  velfbfiles = ', &
-                     TRIM(velfbfiles(ji))
-               ENDIF
-            END DO
-         ENDIF
-         WRITE(numout,*) '             Initial date in window YYYYMMDD.HHMMSS        dobsini = ', dobsini
-         WRITE(numout,*) '             Final date in window YYYYMMDD.HHMMSS          dobsend = ', dobsend
-         WRITE(numout,*) '             Type of vertical interpolation method          n1dint = ', n1dint
-         WRITE(numout,*) '             Type of horizontal interpolation method        n2dint = ', n2dint
-         WRITE(numout,*) '             Rejection of observations near land swithch    ln_nea = ', ln_nea
-         WRITE(numout,*) '             MSSH correction scheme                         nmsshc = ', nmsshc
-         WRITE(numout,*) '             MDT  correction                               mdtcorr = ', mdtcorr
-         WRITE(numout,*) '             MDT cutoff for computed correction          mdtcutoff = ', mdtcutoff
-         WRITE(numout,*) '             Logical switch for alt bias                ln_altbias = ', ln_altbias
-         WRITE(numout,*) '             Logical switch for ignoring missing files   ln_ignmis = ', ln_ignmis
-         WRITE(numout,*) '             ENACT daily average types                             = ',endailyavtypes
-
-      ENDIF
-      
+         WRITE(numout,*) '~~~~~~~~~~~~'
+
+      ENDIF
+
+      !-----------------------------------------------------------------------
+      ! Obs operator parameter checking and initialisations
+      !-----------------------------------------------------------------------
+
       IF ( ln_vel3d .AND. ( .NOT. ln_grid_global ) ) THEN
          CALL ctl_stop( 'Velocity data only works with ln_grid_global=.true.' )
@@ -464,505 +368,135 @@
       ENDIF
 
-      CALL obs_typ_init
-      
-      CALL mppmap_init
-      
-      ! Parameter control
-#if defined key_diaobs
-      IF ( ( .NOT. ln_t3d ).AND.( .NOT. ln_s3d ).AND.( .NOT. ln_sla ).AND. &
-         & ( .NOT. ln_vel3d ).AND.                                         &
-         & ( .NOT. ln_ssh ).AND.( .NOT. ln_sst ).AND.( .NOT. ln_sss ).AND. &
-         & ( .NOT. ln_seaice ).AND.( .NOT. ln_vel3d ) ) THEN
-         IF(lwp) WRITE(numout,cform_war)
-         IF(lwp) WRITE(numout,*) ' key_diaobs is activated but logical flags', &
-            &                    ' ln_t3d, ln_s3d, ln_sla, ln_ssh, ln_sst, ln_sss, ln_seaice, ln_vel3d are all set to .FALSE.'
-         nwarn = nwarn + 1
-      ENDIF
-#endif
-
-      CALL obs_grid_setup( )
-      IF ( ( n1dint < 0 ).OR.( n1dint > 1 ) ) THEN
+      IF ( ln_grid_global ) THEN
+         CALL ctl_warn( 'ln_grid_global=T may cause memory issues when used with a large number of processors' )
+      ENDIF
+
+      IF ( ( nn_1dint < 0 ) .OR. ( nn_1dint > 1 ) ) THEN
          CALL ctl_stop(' Choice of vertical (1D) interpolation method', &
             &                    ' is not available')
       ENDIF
-      IF ( ( n2dint < 0 ).OR.( n2dint > 4 ) ) THEN
+
+      IF ( ( nn_2dint < 0 ) .OR. ( nn_2dint > 4 ) ) THEN
          CALL ctl_stop(' Choice of horizontal (2D) interpolation method', &
             &                    ' is not available')
       ENDIF
 
+      CALL obs_typ_init
+      IF(ln_grid_global) THEN
+         CALL mppmap_init
+      ENDIF
+
+      CALL obs_grid_setup( )
+
       !-----------------------------------------------------------------------
       ! Depending on switches read the various observation types
       !-----------------------------------------------------------------------
-      !  - Temperature/salinity profiles
-
-      IF ( ln_t3d .OR. ln_s3d ) THEN
-
-         ! Set the number of variables for profiles to 2 (T and S)
-         nprofvars = 2
-         ! Set the number of extra variables for profiles to 1 (insitu temp).
-         nprofextr = 1
-
-         ! Count how may insitu data sets we have and allocate data.
-         jprofset = 0
-         IF ( ln_ena ) jprofset = jprofset + 1
-         IF ( ln_cor ) jprofset = jprofset + 1
-         IF ( ln_profb ) jprofset = jprofset + jnumprofb
-         nprofsets = jprofset
-         IF ( nprofsets > 0 ) THEN
-            ALLOCATE(ld_enact(nprofsets))
-            ALLOCATE(profdata(nprofsets))
-            ALLOCATE(prodatqc(nprofsets))
-         ENDIF
-
-         jprofset = 0
-          
-         ! ENACT insitu data
-
-         IF ( ln_ena ) THEN
-
-            jprofset = jprofset + 1
-            
-            ld_enact(jprofset) = .TRUE.
-
-            CALL obs_rea_pro_dri( 1, profdata(jprofset),          &
-               &                  jnumenact, enactfiles(1:jnumenact), &
-               &                  nprofvars, nprofextr,        &
-               &                  nitend-nit000+2,             &
-               &                  dobsini, dobsend, ln_t3d, ln_s3d, &
-               &                  ln_ignmis, ln_s_at_t, .TRUE., .FALSE., &
-               &                  kdailyavtypes = endailyavtypes )
-
-            DO jvar = 1, 2
-
-               CALL obs_prof_staend( profdata(jprofset), jvar )
-
+
+      IF ( nproftypes > 0 ) THEN
+
+         ALLOCATE(profdata(nproftypes))
+         ALLOCATE(profdataqc(nproftypes))
+         ALLOCATE(nvarsprof(nproftypes))
+         ALLOCATE(nextrprof(nproftypes))
+
+         DO jtype = 1, nproftypes
+
+            nvarsprof(jtype) = 2
+            IF ( TRIM(cobstypesprof(jtype)) == 'prof' ) THEN
+               nextrprof(jtype) = 1
+               llvar1 = ln_t3d
+               llvar2 = ln_s3d
+               zglam1 = glamt
+               zgphi1 = gphit
+               zmask1 = tmask
+               zglam2 = glamt
+               zgphi2 = gphit
+               zmask2 = tmask
+            ENDIF
+            IF ( TRIM(cobstypesprof(jtype)) == 'vel' )  THEN
+               nextrprof(jtype) = 2
+               llvar1 = ln_vel3d
+               llvar2 = ln_vel3d
+               zglam1 = glamu
+               zgphi1 = gphiu
+               zmask1 = umask
+               zglam2 = glamv
+               zgphi2 = gphiv
+               zmask2 = vmask
+            ENDIF
+
+            !Read in profile or profile obs types
+            CALL obs_rea_prof( profdata(jtype), ifilesprof(jtype),       &
+               &               clproffiles(jtype,1:ifilesprof(jtype)), &
+               &               nvarsprof(jtype), nextrprof(jtype), nitend-nit000+2, &
+               &               rn_dobsini, rn_dobsend, llvar1, llvar2, &
+               &               ln_ignmis, ln_s_at_t, .FALSE., &
+               &               kdailyavtypes = nn_profdavtypes )
+
+            DO jvar = 1, nvarsprof(jtype)
+               CALL obs_prof_staend( profdata(jtype), jvar )
             END DO
 
-            CALL obs_pre_pro( profdata(jprofset), prodatqc(jprofset),   &
-               &              ln_t3d, ln_s3d, ln_nea, &
-               &              kdailyavtypes=endailyavtypes )
-            
-         ENDIF
-
-         ! Coriolis insitu data
-
-         IF ( ln_cor ) THEN
-           
-            jprofset = jprofset + 1
-
-            ld_enact(jprofset) = .FALSE.
-
-            CALL obs_rea_pro_dri( 2, profdata(jprofset),          &
-               &                  jnumcorio, coriofiles(1:jnumcorio), &
-               &                  nprofvars, nprofextr,        &
-               &                  nitend-nit000+2,             &
-               &                  dobsini, dobsend, ln_t3d, ln_s3d, &
-               &                  ln_ignmis, ln_s_at_t, .FALSE., .FALSE. )
-
-            DO jvar = 1, 2
-
-               CALL obs_prof_staend( profdata(jprofset), jvar )
-
-            END DO
-
-            CALL obs_pre_pro( profdata(jprofset), prodatqc(jprofset),   &
-                 &            ln_t3d, ln_s3d, ln_nea )
-            
-         ENDIF
- 
-         ! Feedback insitu data
-
-         IF ( ln_profb ) THEN
-           
-            DO jset = 1, jnumprofb
-               
-               jprofset = jprofset + 1
-               ld_enact (jprofset) = ln_profb_ena(jset)
-
-               CALL obs_rea_pro_dri( 0, profdata(jprofset),          &
-                  &                  1, profbfiles(jset:jset), &
-                  &                  nprofvars, nprofextr,        &
-                  &                  nitend-nit000+2,             &
-                  &                  dobsini, dobsend, ln_t3d, ln_s3d, &
-                  &                  ln_ignmis, ln_s_at_t, &
-                  &                  ld_enact(jprofset).AND.&
-                  &                  ln_profb_enatim(jset), &
-                  &                  .FALSE., kdailyavtypes = endailyavtypes )
-               
-               DO jvar = 1, 2
-                  
-                  CALL obs_prof_staend( profdata(jprofset), jvar )
-                  
-               END DO
-               
-               IF ( ld_enact(jprofset) ) THEN
-                  CALL obs_pre_pro( profdata(jprofset), prodatqc(jprofset),   &
-                     &              ln_t3d, ln_s3d, ln_nea, &
-                     &              kdailyavtypes = endailyavtypes )
-               ELSE
-                  CALL obs_pre_pro( profdata(jprofset), prodatqc(jprofset),   &
-                     &              ln_t3d, ln_s3d, ln_nea )
-               ENDIF
-               
-            END DO
-
-         ENDIF
-
-      ENDIF
-
-      !  - Sea level anomalies
-      IF ( ln_sla ) THEN
-        ! Set the number of variables for sla to 1
-         nslavars = 1
-
-         ! Set the number of extra variables for sla to 2
-         nslaextr = 2
+            CALL obs_pre_prof( profdata(jtype), profdataqc(jtype), &
+               &               llvar1, llvar2, &
+               &               jpi, jpj, jpk, &
+               &               zmask1, zglam1, zgphi1, zmask2, zglam2, zgphi2,  &
+               &               ln_nea, kdailyavtypes = nn_profdavtypes )
+
+         END DO
+
+         DEALLOCATE( ifilesprof, clproffiles )
+
+      ENDIF
+
+      IF ( nsurftypes > 0 ) THEN
+
+         ALLOCATE(surfdata(nsurftypes))
+         ALLOCATE(surfdataqc(nsurftypes))
+         ALLOCATE(nvarssurf(nsurftypes))
+         ALLOCATE(nextrsurf(nsurftypes))
+
+         DO jtype = 1, nsurftypes
+
+            nvarssurf(jtype) = 1
+            nextrsurf(jtype) = 0
+            llnightav = .FALSE.
+            IF ( TRIM(cobstypessurf(jtype)) == 'sla' ) nextrsurf(jtype) = 2
+            IF ( TRIM(cobstypessurf(jtype)) == 'sst' ) llnightav = ln_sstnight
+
+            !Read in surface obs types
+            CALL obs_rea_surf( surfdata(jtype), ifilessurf(jtype), &
+               &               clsurffiles(jtype,1:ifilessurf(jtype)), &
+               &               nvarssurf(jtype), nextrsurf(jtype), nitend-nit000+2, &
+               &               rn_dobsini, rn_dobsend, ln_ignmis, .FALSE., llnightav )
          
-         ! Set the number of sla data sets to 2
-         nslasets = 0
-         IF ( ln_sladt ) THEN
-            nslasets = nslasets + 2
-         ENDIF
-         IF ( ln_slafb ) THEN
-            nslasets = nslasets + jnumslafb
-         ENDIF
          
-         ALLOCATE(sladata(nslasets))
-         ALLOCATE(sladatqc(nslasets))
-         sladata(:)%nsurf=0
-         sladatqc(:)%nsurf=0
-
-         nslasets = 0
-
-         ! AVISO SLA data
-
-         IF ( ln_sladt ) THEN
-
-            ! Active SLA observations
-            
-            nslasets = nslasets + 1
-            
-            CALL obs_rea_sla( 1, sladata(nslasets), jnumslaact, &
-               &              slafilesact(1:jnumslaact), &
-               &              nslavars, nslaextr, nitend-nit000+2, &
-               &              dobsini, dobsend, ln_ignmis, .FALSE. )
-            CALL obs_pre_sla( sladata(nslasets), sladatqc(nslasets), &
-               &              ln_sla, ln_nea )
-            
-            ! Passive SLA observations
-            
-            nslasets = nslasets + 1
-            
-            CALL obs_rea_sla( 1, sladata(nslasets), jnumslapas, &
-               &              slafilespas(1:jnumslapas), &
-               &              nslavars, nslaextr, nitend-nit000+2, &
-               &              dobsini, dobsend, ln_ignmis, .FALSE. )
-            
-            CALL obs_pre_sla( sladata(nslasets), sladatqc(nslasets), &
-               &              ln_sla, ln_nea )
-
-         ENDIF
-         
-         ! Feedback SLA data
-
-         IF ( ln_slafb ) THEN
-
-            DO jset = 1, jnumslafb
-            
-               nslasets = nslasets + 1
-            
-               CALL obs_rea_sla( 0, sladata(nslasets), 1, &
-                  &              slafbfiles(jset:jset), &
-                  &              nslavars, nslaextr, nitend-nit000+2, &
-                  &              dobsini, dobsend, ln_ignmis, .FALSE. )
-               CALL obs_pre_sla( sladata(nslasets), sladatqc(nslasets), &
-                  &              ln_sla, ln_nea )
-
-            END DO               
-
-         ENDIF
-         
-         CALL obs_rea_mdt( nslasets, sladatqc, n2dint )
-            
-         ! read in altimeter bias
-         
-         IF ( ln_altbias ) THEN     
-            CALL obs_rea_altbias ( nslasets, sladatqc, n2dint, bias_file )
-         ENDIF
-     
-      ENDIF
-
-      !  - Sea surface height
-      IF ( ln_ssh ) THEN
-         IF(lwp) WRITE(numout,*) ' SSH currently not available'
-      ENDIF
-
-      !  - Sea surface temperature
-      IF ( ln_sst ) THEN
-
-         ! Set the number of variables for sst to 1
-         nsstvars = 1
-
-         ! Set the number of extra variables for sst to 0
-         nsstextr = 0
-
-         nsstsets = 0
-
-         IF (ln_reysst) nsstsets = nsstsets + 1
-         IF (ln_ghrsst) nsstsets = nsstsets + 1
-         IF ( ln_sstfb ) THEN
-            nsstsets = nsstsets + jnumsstfb
-         ENDIF
-
-         ALLOCATE(sstdata(nsstsets))
-         ALLOCATE(sstdatqc(nsstsets))
-         ALLOCATE(ld_sstnight(nsstsets))
-         sstdata(:)%nsurf=0
-         sstdatqc(:)%nsurf=0    
-         ld_sstnight(:)=.false.
-
-         nsstsets = 0
-
-         IF (ln_reysst) THEN
-
-            nsstsets = nsstsets + 1
-
-            ld_sstnight(nsstsets) = ln_sstnight
-
-            CALL obs_rea_sst_rey( reysstname, reysstfmt, sstdata(nsstsets), &
-               &                  nsstvars, nsstextr, &
-               &                  nitend-nit000+2, dobsini, dobsend )
-            CALL obs_pre_sst( sstdata(nsstsets), sstdatqc(nsstsets), ln_sst, &
-               &              ln_nea )
-
-        ENDIF
-        
-        IF (ln_ghrsst) THEN
-        
-            nsstsets = nsstsets + 1
-
-            ld_sstnight(nsstsets) = ln_sstnight
-          
-            CALL obs_rea_sst( 1, sstdata(nsstsets), jnumsst, &
-               &              sstfiles(1:jnumsst), &
-               &              nsstvars, nsstextr, nitend-nit000+2, &
-               &              dobsini, dobsend, ln_ignmis, .FALSE. )
-            CALL obs_pre_sst( sstdata(nsstsets), sstdatqc(nsstsets), ln_sst, &
-               &              ln_nea )
-
-        ENDIF
-               
-         ! Feedback SST data
-
-         IF ( ln_sstfb ) THEN
-
-            DO jset = 1, jnumsstfb
-            
-               nsstsets = nsstsets + 1
-
-               ld_sstnight(nsstsets) = ln_sstnight
-            
-               CALL obs_rea_sst( 0, sstdata(nsstsets), 1, &
-                  &              sstfbfiles(jset:jset), &
-                  &              nsstvars, nsstextr, nitend-nit000+2, &
-                  &              dobsini, dobsend, ln_ignmis, .FALSE. )
-               CALL obs_pre_sst( sstdata(nsstsets), sstdatqc(nsstsets), &
-                  &              ln_sst, ln_nea )
-
-            END DO               
-
-         ENDIF
-
-      ENDIF
-
-      !  - Sea surface salinity
-      IF ( ln_sss ) THEN
-         IF(lwp) WRITE(numout,*) ' SSS currently not available'
-      ENDIF
-
-      !  - Sea Ice Concentration
-      
-      IF ( ln_seaice ) THEN
-
-         ! Set the number of variables for seaice to 1
-         nseaicevars = 1
-
-         ! Set the number of extra variables for seaice to 0
-         nseaiceextr = 0
-         
-         ! Set the number of data sets to 1
-         nseaicesets = 1
-
-         ALLOCATE(seaicedata(nseaicesets))
-         ALLOCATE(seaicedatqc(nseaicesets))
-         seaicedata(:)%nsurf=0
-         seaicedatqc(:)%nsurf=0
-
-         CALL obs_rea_seaice( 1, seaicedata(nseaicesets), jnumseaice, &
-            &                 seaicefiles(1:jnumseaice), &
-            &                 nseaicevars, nseaiceextr, nitend-nit000+2, &
-            &                 dobsini, dobsend, ln_ignmis, .FALSE. )
-
-         CALL obs_pre_seaice( seaicedata(nseaicesets), seaicedatqc(nseaicesets), &
-            &                 ln_seaice, ln_nea )
- 
-      ENDIF
-
-      IF (ln_vel3d) THEN
-
-         ! Set the number of variables for profiles to 2 (U and V)
-         nvelovars = 2
-
-         ! Set the number of extra variables for profiles to 2 to store 
-         ! rotation parameters
-         nveloextr = 2
-
-         jveloset = 0
-         
-         IF ( ln_velavcur ) jveloset = jveloset + 1
-         IF ( ln_velhrcur ) jveloset = jveloset + 1
-         IF ( ln_velavadcp ) jveloset = jveloset + 1
-         IF ( ln_velhradcp ) jveloset = jveloset + 1
-         IF (ln_velfb) jveloset = jveloset + jnumvelfb
-
-         nvelosets = jveloset
-         IF ( nvelosets > 0 ) THEN
-            ALLOCATE( velodata(nvelosets) )
-            ALLOCATE( veldatqc(nvelosets) )
-            ALLOCATE( ld_velav(nvelosets) )
-         ENDIF
-         
-         jveloset = 0
-         
-         ! Daily averaged data
-
-         IF ( ln_velavcur ) THEN
-            
-            jveloset = jveloset + 1
-            
-            ld_velav(jveloset) = .TRUE.
-            
-            CALL obs_rea_vel_dri( 1, velodata(jveloset), jnumvelavcur, &
-               &                  velavcurfiles(1:jnumvelavcur), &
-               &                  nvelovars, nveloextr, &
-               &                  nitend-nit000+2,              &
-               &                  dobsini, dobsend, ln_ignmis, &
-               &                  ld_velav(jveloset), &
-               &                  .FALSE. )
-            
-            DO jvar = 1, 2
-               CALL obs_prof_staend( velodata(jveloset), jvar )
-            END DO
-            
-            CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
-               &              ln_vel3d, ln_nea, ld_velav(jveloset) )
-            
-         ENDIF
-
-         ! High frequency data
-
-         IF ( ln_velhrcur ) THEN
-            
-            jveloset = jveloset + 1
-            
-            ld_velav(jveloset) = .FALSE.
-               
-            CALL obs_rea_vel_dri( 1, velodata(jveloset), jnumvelhrcur, &
-               &                  velhrcurfiles(1:jnumvelhrcur), &
-               &                  nvelovars, nveloextr, &
-               &                  nitend-nit000+2,              &
-               &                  dobsini, dobsend, ln_ignmis, &
-               &                  ld_velav(jveloset), &
-               &                  .FALSE. )
-            
-            DO jvar = 1, 2
-               CALL obs_prof_staend( velodata(jveloset), jvar )
-            END DO
-            
-            CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
-               &              ln_vel3d, ln_nea, ld_velav(jveloset) )
-            
-         ENDIF
-
-         ! Daily averaged data
-
-         IF ( ln_velavadcp ) THEN
-            
-            jveloset = jveloset + 1
-            
-            ld_velav(jveloset) = .TRUE.
-            
-            CALL obs_rea_vel_dri( 1, velodata(jveloset), jnumvelavadcp, &
-               &                  velavadcpfiles(1:jnumvelavadcp), &
-               &                  nvelovars, nveloextr, &
-               &                  nitend-nit000+2,              &
-               &                  dobsini, dobsend, ln_ignmis, &
-               &                  ld_velav(jveloset), &
-               &                  .FALSE. )
-            
-            DO jvar = 1, 2
-               CALL obs_prof_staend( velodata(jveloset), jvar )
-            END DO
-            
-            CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
-               &              ln_vel3d, ln_nea, ld_velav(jveloset) )
-            
-         ENDIF
-
-         ! High frequency data
-
-         IF ( ln_velhradcp ) THEN
-            
-            jveloset = jveloset + 1
-            
-            ld_velav(jveloset) = .FALSE.
-               
-            CALL obs_rea_vel_dri( 1, velodata(jveloset), jnumvelhradcp, &
-               &                  velhradcpfiles(1:jnumvelhradcp), &
-               &                  nvelovars, nveloextr, &
-               &                  nitend-nit000+2,              &
-               &                  dobsini, dobsend, ln_ignmis, &
-               &                  ld_velav(jveloset), &
-               &                  .FALSE. )
-            
-            DO jvar = 1, 2
-               CALL obs_prof_staend( velodata(jveloset), jvar )
-            END DO
-            
-            CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
-               &              ln_vel3d, ln_nea, ld_velav(jveloset) )
-            
-         ENDIF
-
-         IF ( ln_velfb ) THEN
-
-            DO jset = 1, jnumvelfb
-            
-               jveloset = jveloset + 1
-
-               ld_velav(jveloset) = ln_velfb_av(jset)
-               
-               CALL obs_rea_vel_dri( 0, velodata(jveloset), 1, &
-                  &                  velfbfiles(jset:jset), &
-                  &                  nvelovars, nveloextr, &
-                  &                  nitend-nit000+2,              &
-                  &                  dobsini, dobsend, ln_ignmis, &
-                  &                  ld_velav(jveloset), &
-                  &                  .FALSE. )
-               
-               DO jvar = 1, 2
-                  CALL obs_prof_staend( velodata(jveloset), jvar )
-               END DO
-               
-               CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
-                  &              ln_vel3d, ln_nea, ld_velav(jveloset) )
-
-
-            END DO
-            
-         ENDIF
-
-      ENDIF
-     
+            CALL obs_pre_surf( surfdata(jtype), surfdataqc(jtype), ln_nea )
+
+            IF ( TRIM(cobstypessurf(jtype)) == 'sla' ) THEN
+               CALL obs_rea_mdt( surfdataqc(jtype), nn_2dint )
+               IF ( ln_altbias ) CALL obs_rea_altbias ( surfdataqc(jtype), nn_2dint, cn_altbiasfile )
+            ENDIF
+            IF ( TRIM(cobstypessurf(jtype)) == 'sst' .AND. ln_sstbias ) THEN
+               !Read in bias field and correct SST.
+               IF ( jnumsstbias == 0 ) CALL ctl_stop("ln_sstbias set,"// &
+                                                     "  but no bias"// &
+                                                     " files to read in")   
+                  CALL obs_app_sstbias( surfdataqc(jtype), nn_2dint, &
+                                        jnumsstbias, cn_sstbias_files(1:jnumsstbias) )
+            ENDIF
+         END DO
+
+         DEALLOCATE( ifilessurf, clsurffiles )
+
+      ENDIF
+
+      CALL wrk_dealloc( jpi, jpj, zglam1 )
+      CALL wrk_dealloc( jpi, jpj, zglam2 )
+      CALL wrk_dealloc( jpi, jpj, zgphi1 )
+      CALL wrk_dealloc( jpi, jpj, zgphi2 )
+      CALL wrk_dealloc( jpi, jpj, jpk, zmask1 )
+      CALL wrk_dealloc( jpi, jpj, jpk, zmask2 )
+
    END SUBROUTINE dia_obs_init
 
@@ -974,13 +508,9 @@
       !!
       !! ** Method  : Call the observation operators on each time step to
-      !!              compute the model equivalent of the following date:
-      !!               - T profiles
-      !!               - S profiles
-      !!               - Sea surface height (referenced to a mean)
-      !!               - Sea surface temperature
-      !!               - Sea surface salinity
-      !!               - Velocity component (U,V) profiles
-      !!
-      !! ** Action  : 
+      !!              compute the model equivalent of the following data:
+      !!               - Profile data, currently T/S or U/V
+      !!               - Surface data, currently SST, SLA or sea-ice concentration.
+      !!
+      !! ** Action  :
       !!
       !! History :
@@ -991,22 +521,26 @@
       !!        !  07-04  (G. Smith) Generalized surface operators
       !!        !  08-10  (M. Valdivieso) obs operator for velocity profiles
+      !!        !  14-08  (J. While) observation operator for profiles in 
+      !!                             generalised vertical coordinates
+      !!        !  15-08  (M. Martin) Combined surface/profile routines.
       !!----------------------------------------------------------------------
       !! * Modules used
       USE dom_oce, ONLY : &             ! Ocean space and time domain variables
-         & rdt,           &                       
-         & gdept_1d,       &             
-         & tmask, umask, vmask                            
+         & gdept_n,       &      
+         & gdept_1d      
       USE phycst, ONLY : &              ! Physical constants
          & rday                         
       USE oce, ONLY : &                 ! Ocean dynamics and tracers variables
          & tsn,  &             
-         & un, vn,  &
-         & sshn
+         & un, vn, &
+         & sshn  
+      USE phycst, ONLY : &         ! Physical constants
+         & rday
 #if defined  key_lim3
-      USE ice, ONLY : &                     ! LIM Ice model variables
+      USE ice, ONLY : &            ! LIM3 Ice model variables
          & frld
 #endif
 #if defined key_lim2
-      USE ice_2, ONLY : &                     ! LIM Ice model variables
+      USE ice_2, ONLY : &          ! LIM2 Ice model variables
          & frld
 #endif
@@ -1014,18 +548,38 @@
 
       !! * Arguments
-      INTEGER, INTENT(IN) :: kstp                         ! Current timestep
+      INTEGER, INTENT(IN) :: kstp  ! Current timestep
       !! * Local declarations
-      INTEGER :: idaystp                ! Number of timesteps per day
-      INTEGER :: jprofset               ! Profile data set loop variable
-      INTEGER :: jslaset                ! SLA data set loop variable
-      INTEGER :: jsstset                ! SST data set loop variable
-      INTEGER :: jseaiceset             ! sea ice data set loop variable
-      INTEGER :: jveloset               ! velocity profile data loop variable
-      INTEGER :: jvar                   ! Variable number    
+      INTEGER :: idaystp           ! Number of timesteps per day
+      INTEGER :: jtype             ! Data loop variable
+      INTEGER :: jvar              ! Variable number
+      INTEGER :: ji, jj            ! Loop counters
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: &
+         & zprofvar1, &            ! Model values for 1st variable in a prof ob
+         & zprofvar2               ! Model values for 2nd variable in a prof ob
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: &
+         & zprofmask1, &           ! Mask associated with zprofvar1
+         & zprofmask2              ! Mask associated with zprofvar2
+      REAL(wp), POINTER, DIMENSION(:,:) :: &
+         & zsurfvar                ! Model values equivalent to surface ob.
+      REAL(wp), POINTER, DIMENSION(:,:) :: &
+         & zglam1,    &            ! Model longitudes for prof variable 1
+         & zglam2,    &            ! Model longitudes for prof variable 2
+         & zgphi1,    &            ! Model latitudes for prof variable 1
+         & zgphi2                  ! Model latitudes for prof variable 2
 #if ! defined key_lim2 && ! defined key_lim3
-      REAL(wp), POINTER, DIMENSION(:,:) :: frld   
+      REAL(wp), POINTER, DIMENSION(:,:) :: frld
 #endif
-      CHARACTER(LEN=20) :: datestr=" ",timestr=" "
- 
+      LOGICAL :: llnightav        ! Logical for calculating night-time average
+
+      !Allocate local work arrays
+      CALL wrk_alloc( jpi, jpj, jpk, zprofvar1 )
+      CALL wrk_alloc( jpi, jpj, jpk, zprofvar2 )
+      CALL wrk_alloc( jpi, jpj, jpk, zprofmask1 )
+      CALL wrk_alloc( jpi, jpj, jpk, zprofmask2 )
+      CALL wrk_alloc( jpi, jpj, zsurfvar )
+      CALL wrk_alloc( jpi, jpj, zglam1 )
+      CALL wrk_alloc( jpi, jpj, zglam2 )
+      CALL wrk_alloc( jpi, jpj, zgphi1 )
+      CALL wrk_alloc( jpi, jpj, zgphi2 )
 #if ! defined key_lim2 && ! defined key_lim3
       CALL wrk_alloc(jpi,jpj,frld) 
@@ -1047,76 +601,112 @@
 #endif
       !-----------------------------------------------------------------------
-      ! Depending on switches call various observation operators
-      !-----------------------------------------------------------------------
-
-      !  - Temperature/salinity profiles
-      IF ( ln_t3d .OR. ln_s3d ) THEN
-         DO jprofset = 1, nprofsets
-            IF ( ld_enact(jprofset) ) THEN
-               CALL obs_pro_opt( prodatqc(jprofset),                     &
-                  &              kstp, jpi, jpj, jpk, nit000, idaystp,   &
-                  &              tsn(:,:,:,jp_tem), tsn(:,:,:,jp_sal),   &
-                  &              gdept_1d, tmask, n1dint, n2dint,        &
-                  &              kdailyavtypes = endailyavtypes )
+      ! Call the profile and surface observation operators
+      !-----------------------------------------------------------------------
+
+      IF ( nproftypes > 0 ) THEN
+
+         DO jtype = 1, nproftypes
+
+            SELECT CASE ( TRIM(cobstypesprof(jtype)) )
+            CASE('prof')
+               zprofvar1(:,:,:) = tsn(:,:,:,jp_tem)
+               zprofvar2(:,:,:) = tsn(:,:,:,jp_sal)
+               zprofmask1(:,:,:) = tmask(:,:,:)
+               zprofmask2(:,:,:) = tmask(:,:,:)
+               zglam1(:,:) = glamt(:,:)
+               zglam2(:,:) = glamt(:,:)
+               zgphi1(:,:) = gphit(:,:)
+               zgphi2(:,:) = gphit(:,:)
+            CASE('vel')
+               zprofvar1(:,:,:) = un(:,:,:)
+               zprofvar2(:,:,:) = vn(:,:,:)
+               zprofmask1(:,:,:) = umask(:,:,:)
+               zprofmask2(:,:,:) = vmask(:,:,:)
+               zglam1(:,:) = glamu(:,:)
+               zglam2(:,:) = glamv(:,:)
+               zgphi1(:,:) = gphiu(:,:)
+               zgphi2(:,:) = gphiv(:,:)
+            END SELECT
+
+            IF( ln_zco .OR. ln_zps ) THEN 
+               CALL obs_prof_opt( profdataqc(jtype), kstp, jpi, jpj, jpk,  &
+                  &               nit000, idaystp,                         &
+                  &               zprofvar1, zprofvar2,                    &
+                  &               gdept_1d, zprofmask1, zprofmask2,        &
+                  &               zglam1, zglam2, zgphi1, zgphi2,          &
+                  &               nn_1dint, nn_2dint,                      &
+                  &               kdailyavtypes = nn_profdavtypes )
+            ELSE IF(TRIM(cobstypesprof(jtype)) == 'prof') THEN
+               !TG - THIS NEEDS MODIFICATION TO MATCH SIMPLIFICATION
+               CALL obs_pro_sco_opt( profdataqc(jtype),                    & 
+                  &              kstp, jpi, jpj, jpk, nit000, idaystp,   & 
+                  &              zprofvar1, zprofvar2,                   & 
+                  &              gdept_n(:,:,:), gdepw_n(:,:,:),           &
+                  &              tmask, nn_1dint, nn_2dint,              & 
+                  &              kdailyavtypes = nn_profdavtypes ) 
             ELSE
-               CALL obs_pro_opt( prodatqc(jprofset),                     &
-                  &              kstp, jpi, jpj, jpk, nit000, idaystp,   &
-                  &              tsn(:,:,:,jp_tem), tsn(:,:,:,jp_sal),   &
-                  &              gdept_1d, tmask, n1dint, n2dint              )
+               CALL ctl_stop('DIA_OBS: Generalised vertical interpolation not'// &
+                         'yet working for velocity data (turn off velocity observations')
             ENDIF
+
          END DO
-      ENDIF
-
-      !  - Sea surface anomaly
-      IF ( ln_sla ) THEN
-         DO jslaset = 1, nslasets
-            CALL obs_sla_opt( sladatqc(jslaset),            &
-               &              kstp, jpi, jpj, nit000, sshn, &
-               &              tmask(:,:,1), n2dint )
-         END DO         
-      ENDIF
-
-      !  - Sea surface temperature
-      IF ( ln_sst ) THEN
-         DO jsstset = 1, nsstsets
-            CALL obs_sst_opt( sstdatqc(jsstset),                &
-               &              kstp, jpi, jpj, nit000, idaystp,  &
-               &              tsn(:,:,1,jp_tem), tmask(:,:,1),  &
-               &              n2dint, ld_sstnight(jsstset) )
+
+      ENDIF
+
+      IF ( nsurftypes > 0 ) THEN
+
+         DO jtype = 1, nsurftypes
+
+            SELECT CASE ( TRIM(cobstypessurf(jtype)) )
+            CASE('sst')
+               zsurfvar(:,:) = tsn(:,:,1,jp_tem)
+               llnightav = ln_sstnight
+            CASE('sla')
+               zsurfvar(:,:) = sshn(:,:)
+               llnightav = .FALSE.
+#if defined key_lim2 || defined key_lim3
+            CASE('sic')
+               IF ( kstp == 0 ) THEN
+                  IF ( lwp .AND. surfdataqc(jtype)%nsstpmpp(1) > 0 ) THEN
+                     CALL ctl_warn( 'Sea-ice not initialised on zeroth '// &
+                        &           'time-step but some obs are valid then.' )
+                     WRITE(numout,*)surfdataqc(jtype)%nsstpmpp(1), &
+                        &           ' sea-ice obs will be missed'
+                  ENDIF
+                  surfdataqc(jtype)%nsurfup = surfdataqc(jtype)%nsurfup + &
+                     &                        surfdataqc(jtype)%nsstp(1)
+                  CYCLE
+               ELSE
+                  zsurfvar(:,:) = 1._wp - frld(:,:)
+               ENDIF
+
+               llnightav = .FALSE.
+#endif
+            END SELECT
+
+            CALL obs_surf_opt( surfdataqc(jtype), kstp, jpi, jpj,       &
+               &               nit000, idaystp, zsurfvar, tmask(:,:,1), &
+               &               nn_2dint, llnightav )
+
          END DO
-      ENDIF
-
-      !  - Sea surface salinity
-      IF ( ln_sss ) THEN
-         IF(lwp) WRITE(numout,*) ' SSS currently not available'
-      ENDIF
-
-#if defined key_lim2 || defined key_lim3
-      IF ( ln_seaice ) THEN
-         DO jseaiceset = 1, nseaicesets
-            CALL obs_seaice_opt( seaicedatqc(jseaiceset),      &
-               &              kstp, jpi, jpj, nit000, 1.-frld, &
-               &              tmask(:,:,1), n2dint )
-         END DO
-      ENDIF      
+
+      ENDIF
+
+      CALL wrk_dealloc( jpi, jpj, jpk, zprofvar1 )
+      CALL wrk_dealloc( jpi, jpj, jpk, zprofvar2 )
+      CALL wrk_dealloc( jpi, jpj, jpk, zprofmask1 )
+      CALL wrk_dealloc( jpi, jpj, jpk, zprofmask2 )
+      CALL wrk_dealloc( jpi, jpj, zsurfvar )
+      CALL wrk_dealloc( jpi, jpj, zglam1 )
+      CALL wrk_dealloc( jpi, jpj, zglam2 )
+      CALL wrk_dealloc( jpi, jpj, zgphi1 )
+      CALL wrk_dealloc( jpi, jpj, zgphi2 )
+#if ! defined key_lim2 && ! defined key_lim3
+      CALL wrk_dealloc(jpi,jpj,frld)
 #endif
 
-      !  - Velocity profiles
-      IF ( ln_vel3d ) THEN
-         DO jveloset = 1, nvelosets
-           ! zonal component of velocity
-           CALL obs_vel_opt( veldatqc(jveloset), kstp, jpi, jpj, jpk, &
-              &              nit000, idaystp, un, vn, gdept_1d, umask, vmask, &
-                             n1dint, n2dint, ld_velav(jveloset) )
-         END DO
-      ENDIF
-
-#if ! defined key_lim2 && ! defined key_lim3
-      CALL wrk_dealloc(jpi,jpj,frld) 
-#endif
-
    END SUBROUTINE dia_obs
-  
-   SUBROUTINE dia_obs_wri 
+
+   SUBROUTINE dia_obs_wri
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE dia_obs_wri  ***
@@ -1126,5 +716,5 @@
       !! ** Method  : Call observation diagnostic output routines
       !!
-      !! ** Action  : 
+      !! ** Action  :
       !!
       !! History :
@@ -1134,258 +724,76 @@
       !!        !  07-03  (K. Mogensen) General handling of profiles
       !!        !  08-09  (M. Valdivieso) Velocity component (U,V) profiles
-      !!----------------------------------------------------------------------
+      !!        !  15-08  (M. Martin) Combined writing for prof and surf types
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE obs_rot_vel          ! Rotation of velocities
+
       IMPLICIT NONE
 
       !! * Local declarations
-
-      INTEGER :: jprofset                 ! Profile data set loop variable
-      INTEGER :: jveloset                 ! Velocity data set loop variable
-      INTEGER :: jslaset                  ! SLA data set loop variable
-      INTEGER :: jsstset                  ! SST data set loop variable
-      INTEGER :: jseaiceset               ! Sea Ice data set loop variable
-      INTEGER :: jset
-      INTEGER :: jfbini
-      CHARACTER(LEN=20) :: datestr=" ",timestr=" "
-      CHARACTER(LEN=10) :: cdtmp
+      INTEGER :: jtype                    ! Data set loop variable
+      INTEGER :: jo, jvar, jk
+      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
+         & zu, &
+         & zv
+
       !-----------------------------------------------------------------------
       ! Depending on switches call various observation output routines
       !-----------------------------------------------------------------------
 
-      !  - Temperature/salinity profiles
-
-      IF( ln_t3d .OR. ln_s3d ) THEN
-
-         ! Copy data from prodatqc to profdata structures
-         DO jprofset = 1, nprofsets
-
-            CALL obs_prof_decompress( prodatqc(jprofset), &
-                 &                    profdata(jprofset), .TRUE., numout )
+      IF ( nproftypes > 0 ) THEN
+
+         DO jtype = 1, nproftypes
+
+            IF ( TRIM(cobstypesprof(jtype)) == 'vel' ) THEN
+
+               ! For velocity data, rotate the model velocities to N/S, E/W
+               ! using the compressed data structure.
+               ALLOCATE( &
+                  & zu(profdataqc(jtype)%nvprot(1)), &
+                  & zv(profdataqc(jtype)%nvprot(2))  &
+                  & )
+
+               CALL obs_rotvel( profdataqc(jtype), nn_2dint, zu, zv )
+
+               DO jo = 1, profdataqc(jtype)%nprof
+                  DO jvar = 1, 2
+                     DO jk = profdataqc(jtype)%npvsta(jo,jvar), profdataqc(jtype)%npvend(jo,jvar)
+
+                        IF ( jvar == 1 ) THEN
+                           profdataqc(jtype)%var(jvar)%vmod(jk) = zu(jk)
+                        ELSE
+                           profdataqc(jtype)%var(jvar)%vmod(jk) = zv(jk)
+                        ENDIF
+
+                     END DO
+                  END DO
+               END DO
+
+               DEALLOCATE( zu )
+               DEALLOCATE( zv )
+
+            END IF
+
+            CALL obs_prof_decompress( profdataqc(jtype), &
+               &                      profdata(jtype), .TRUE., numout )
+
+            CALL obs_wri_prof( profdata(jtype) )
 
          END DO
 
-         ! Write the profiles.
-
-         jprofset = 0
-
-         ! ENACT insitu data
-
-         IF ( ln_ena ) THEN
-           
-            jprofset = jprofset + 1
-
-            CALL obs_wri_p3d( 'enact', profdata(jprofset) )
-
-         ENDIF
-
-         ! Coriolis insitu data
-
-         IF ( ln_cor ) THEN
-            
-            jprofset = jprofset + 1
-
-            CALL obs_wri_p3d( 'corio', profdata(jprofset) )
-            
-         ENDIF
-         
-         ! Feedback insitu data
-
-         IF ( ln_profb ) THEN
-
-            jfbini = jprofset + 1
-
-            DO jprofset = jfbini, nprofsets
-               
-               jset = jprofset - jfbini + 1
-               WRITE(cdtmp,'(A,I2.2)')'profb_',jset
-               CALL obs_wri_p3d( cdtmp, profdata(jprofset) )
-
-            END DO
-
-         ENDIF
-
-      ENDIF
-
-      !  - Sea surface anomaly
-      IF ( ln_sla ) THEN
-
-         ! Copy data from sladatqc to sladata structures
-         DO jslaset = 1, nslasets
-
-              CALL obs_surf_decompress( sladatqc(jslaset), &
-                 &                    sladata(jslaset), .TRUE., numout )
+      ENDIF
+
+      IF ( nsurftypes > 0 ) THEN
+
+         DO jtype = 1, nsurftypes
+
+            CALL obs_surf_decompress( surfdataqc(jtype), &
+               &                      surfdata(jtype), .TRUE., numout )
+
+            CALL obs_wri_surf( surfdata(jtype) )
 
          END DO
 
-         jslaset = 0 
-
-         ! Write the AVISO SLA data
-
-         IF ( ln_sladt ) THEN
-            
-            jslaset = 1
-            CALL obs_wri_sla( 'aviso_act', sladata(jslaset) )
-            jslaset = 2
-            CALL obs_wri_sla( 'aviso_pas', sladata(jslaset) )
-
-         ENDIF
-
-         IF ( ln_slafb ) THEN
-            
-            jfbini = jslaset + 1
-
-            DO jslaset = jfbini, nslasets
-               
-               jset = jslaset - jfbini + 1
-               WRITE(cdtmp,'(A,I2.2)')'slafb_',jset
-               CALL obs_wri_sla( cdtmp, sladata(jslaset) )
-
-            END DO
-
-         ENDIF
-
-      ENDIF
-
-      !  - Sea surface temperature
-      IF ( ln_sst ) THEN
-
-         ! Copy data from sstdatqc to sstdata structures
-         DO jsstset = 1, nsstsets
-     
-              CALL obs_surf_decompress( sstdatqc(jsstset), &
-                 &                    sstdata(jsstset), .TRUE., numout )
-
-         END DO
-
-         jsstset = 0 
-
-         ! Write the AVISO SST data
-
-         IF ( ln_reysst ) THEN
-            
-            jsstset = jsstset + 1
-            CALL obs_wri_sst( 'reynolds', sstdata(jsstset) )
-
-         ENDIF
-
-         IF ( ln_ghrsst ) THEN
-            
-            jsstset = jsstset + 1
-            CALL obs_wri_sst( 'ghr', sstdata(jsstset) )
-
-         ENDIF
-
-         IF ( ln_sstfb ) THEN
-            
-            jfbini = jsstset + 1
-
-            DO jsstset = jfbini, nsstsets
-               
-               jset = jsstset - jfbini + 1
-               WRITE(cdtmp,'(A,I2.2)')'sstfb_',jset
-               CALL obs_wri_sst( cdtmp, sstdata(jsstset) )
-
-            END DO
-
-         ENDIF
-
-      ENDIF
-
-      !  - Sea surface salinity
-      IF ( ln_sss ) THEN
-         IF(lwp) WRITE(numout,*) ' SSS currently not available'
-      ENDIF
-
-      !  - Sea Ice Concentration
-      IF ( ln_seaice ) THEN
-
-         ! Copy data from seaicedatqc to seaicedata structures
-         DO jseaiceset = 1, nseaicesets
-
-              CALL obs_surf_decompress( seaicedatqc(jseaiceset), &
-                 &                    seaicedata(jseaiceset), .TRUE., numout )
-
-         END DO
-
-         ! Write the Sea Ice data
-         DO jseaiceset = 1, nseaicesets
-      
-            WRITE(cdtmp,'(A,I2.2)')'seaicefb_',jseaiceset
-            CALL obs_wri_seaice( cdtmp, seaicedata(jseaiceset) )
-
-         END DO
-
-      ENDIF
-      
-      ! Velocity data
-      IF( ln_vel3d ) THEN
-
-         ! Copy data from veldatqc to velodata structures
-         DO jveloset = 1, nvelosets
-
-            CALL obs_prof_decompress( veldatqc(jveloset), &
-                 &                    velodata(jveloset), .TRUE., numout )
-
-         END DO
-
-         ! Write the profiles.
-
-         jveloset = 0
-
-         ! Daily averaged data
-
-         IF ( ln_velavcur ) THEN
-            
-            jveloset = jveloset + 1
-
-            CALL obs_wri_vel( 'velavcurr', velodata(jveloset), n2dint )
-
-         ENDIF
-
-         ! High frequency data
-
-         IF ( ln_velhrcur ) THEN
-            
-            jveloset = jveloset + 1
-
-            CALL obs_wri_vel( 'velhrcurr', velodata(jveloset), n2dint )
-
-         ENDIF
-
-         ! Daily averaged data
-
-         IF ( ln_velavadcp ) THEN
-            
-            jveloset = jveloset + 1
-
-            CALL obs_wri_vel( 'velavadcp', velodata(jveloset), n2dint )
-
-         ENDIF
-
-         ! High frequency data
-
-         IF ( ln_velhradcp ) THEN
-            
-            jveloset = jveloset + 1
-            
-            CALL obs_wri_vel( 'velhradcp', velodata(jveloset), n2dint )
-               
-         ENDIF
-
-         ! Feedback velocity data
-
-         IF ( ln_velfb ) THEN
-
-            jfbini = jveloset + 1
-
-            DO jveloset = jfbini, nvelosets
-               
-               jset = jveloset - jfbini + 1
-               WRITE(cdtmp,'(A,I2.2)')'velfb_',jset
-               CALL obs_wri_vel( cdtmp, velodata(jveloset), n2dint )
-
-            END DO
-
-         ENDIF
-         
       ENDIF
 
@@ -1405,41 +813,27 @@
       !!
       !!----------------------------------------------------------------------
-      !! obs_grid deallocation
+      ! obs_grid deallocation
       CALL obs_grid_deallocate
 
-      !! diaobs deallocation
-      IF ( nprofsets > 0 ) THEN
-          DEALLOCATE(ld_enact, &
-                  &  profdata, &
-                  &  prodatqc)
-      END IF
-      IF ( ln_sla ) THEN
-          DEALLOCATE(sladata, &
-                  &  sladatqc)
-      END IF
-      IF ( ln_seaice ) THEN
-          DEALLOCATE(sladata, &
-                  &  sladatqc)
-      END IF
-      IF ( ln_sst ) THEN
-          DEALLOCATE(sstdata, &
-                  &  sstdatqc)
-      END IF
-      IF ( ln_vel3d ) THEN
-          DEALLOCATE(ld_velav, &
-                  &  velodata, &
-                  &  veldatqc)
-      END IF
+      ! diaobs deallocation
+      IF ( nproftypes > 0 ) &
+         &   DEALLOCATE( cobstypesprof, profdata, profdataqc, nvarsprof, nextrprof )
+
+      IF ( nsurftypes > 0 ) &
+         &   DEALLOCATE( cobstypessurf, surfdata, surfdataqc, nvarssurf, nextrsurf )
+
    END SUBROUTINE dia_obs_dealloc
 
-   SUBROUTINE ini_date( ddobsini )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE ini_date  ***
+   SUBROUTINE calc_date( kstp, ddobs )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE calc_date  ***
       !!          
-      !! ** Purpose : Get initial data in double precision YYYYMMDD.HHMMSS format
-      !!
-      !! ** Method  : Get initial data in double precision YYYYMMDD.HHMMSS format
-      !!
-      !! ** Action  : Get initial data in double precision YYYYMMDD.HHMMSS format
+      !! ** Purpose : Get date in double precision YYYYMMDD.HHMMSS format
+      !!
+      !! ** Method  : Get date in double precision YYYYMMDD.HHMMSS format
+      !!
+      !! ** Action  : Get date in double precision YYYYMMDD.HHMMSS format
+      !!
+      !! ** Action  : Get initial date in double precision YYYYMMDD.HHMMSS format
       !!
       !! History :
@@ -1449,9 +843,8 @@
       !!        !  06-10  (G. Smith) Calculates initial date the same as method for final date
       !!        !  10-05  (D. Lea) Update to month length calculation for NEMO vn3.2
+      !!        !  2014-09  (D. Lea) New generic routine now deals with arbitrary initial time of day
       !!----------------------------------------------------------------------
       USE phycst, ONLY : &            ! Physical constants
          & rday
-!      USE daymod, ONLY : &            ! Time variables
-!         & nmonth_len           
       USE dom_oce, ONLY : &           ! Ocean space and time domain variables
          & rdt
@@ -1460,5 +853,6 @@
 
       !! * Arguments
-      REAL(KIND=dp), INTENT(OUT) :: ddobsini                         ! Initial date in YYYYMMDD.HHMMSS
+      REAL(KIND=dp), INTENT(OUT) :: ddobs                        ! Date in YYYYMMDD.HHMMSS
+      INTEGER :: kstp
 
       !! * Local declarations
@@ -1468,6 +862,6 @@
       INTEGER :: ihou
       INTEGER :: imin
-      INTEGER :: imday         ! Number of days in month.
-      REAL(KIND=wp) :: zdayfrc ! Fraction of day
+      INTEGER :: imday       ! Number of days in month.
+      REAL(wp) :: zdayfrc    ! Fraction of day
 
       INTEGER, DIMENSION(12) ::   imonth_len    !: length in days of the months of the current year
@@ -1475,27 +869,33 @@
       !!----------------------------------------------------------------------
       !! Initial date initialization (year, month, day, hour, minute)
-      !! (This assumes that the initial date is for 00z))
       !!----------------------------------------------------------------------
       iyea =   ndate0 / 10000
       imon = ( ndate0 - iyea * 10000 ) / 100
       iday =   ndate0 - iyea * 10000 - imon * 100
-      ihou = 0
-      imin = 0
+      ihou =   nn_time0 / 100
+      imin = ( nn_time0 - ihou * 100 ) 
 
       !!----------------------------------------------------------------------
       !! Compute number of days + number of hours + min since initial time
       !!----------------------------------------------------------------------
-      iday = iday + ( nit000 -1 ) * rdt / rday
-      zdayfrc = ( nit000 -1 ) * rdt / rday
+      zdayfrc = kstp * rdt / rday
       zdayfrc = zdayfrc - aint(zdayfrc)
-      ihou = int( zdayfrc * 24 )
-      imin = int( (zdayfrc * 24 - ihou) * 60 )
-
-      !!-----------------------------------------------------------------------
-      !! Convert number of days (iday) into a real date
-      !!----------------------------------------------------------------------
+      imin = imin + int( zdayfrc * 24 * 60 ) 
+      DO WHILE (imin >= 60) 
+        imin=imin-60
+        ihou=ihou+1
+      END DO
+      DO WHILE (ihou >= 24)
+        ihou=ihou-24
+        iday=iday+1
+      END DO 
+      iday = iday + kstp * rdt / rday 
+
+      !-----------------------------------------------------------------------
+      ! Convert number of days (iday) into a real date
+      !----------------------------------------------------------------------
 
       CALL calc_month_len( iyea, imonth_len )
-      
+
       DO WHILE ( iday > imonth_len(imon) )
          iday = iday - imonth_len(imon)
@@ -1508,22 +908,21 @@
       END DO
 
-      !!----------------------------------------------------------------------
-      !! Convert it into YYYYMMDD.HHMMSS format.
-      !!----------------------------------------------------------------------
-      ddobsini = iyea * 10000_dp + imon * 100_dp + &
-         &       iday + ihou * 0.01_dp + imin * 0.0001_dp
-
-
-   END SUBROUTINE ini_date
-
-   SUBROUTINE fin_date( ddobsfin )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE fin_date  ***
+      !----------------------------------------------------------------------
+      ! Convert it into YYYYMMDD.HHMMSS format.
+      !----------------------------------------------------------------------
+      ddobs = iyea * 10000_dp + imon * 100_dp + &
+         &    iday + ihou * 0.01_dp + imin * 0.0001_dp
+
+   END SUBROUTINE calc_date
+
+   SUBROUTINE ini_date( ddobsini )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE ini_date  ***
       !!          
-      !! ** Purpose : Get final data in double precision YYYYMMDD.HHMMSS format
-      !!
-      !! ** Method  : Get final data in double precision YYYYMMDD.HHMMSS format
-      !!
-      !! ** Action  : Get final data in double precision YYYYMMDD.HHMMSS format
+      !! ** Purpose : Get initial date in double precision YYYYMMDD.HHMMSS format
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : 
       !!
       !! History :
@@ -1532,70 +931,42 @@
       !!        !  06-10  (A. Weaver) Cleaning
       !!        !  10-05  (D. Lea) Update to month length calculation for NEMO vn3.2
-      !!----------------------------------------------------------------------
-      USE phycst, ONLY : &            ! Physical constants
-         & rday
-!      USE daymod, ONLY : &            ! Time variables
-!         & nmonth_len                
-      USE dom_oce, ONLY : &           ! Ocean space and time domain variables
-         & rdt
+      !!        !  2014-09  (D. Lea) Change to call generic routine calc_date
+      !!----------------------------------------------------------------------
 
       IMPLICIT NONE
 
       !! * Arguments
-      REAL(KIND=dp), INTENT(OUT) :: ddobsfin                   ! Final date in YYYYMMDD.HHMMSS
-
-      !! * Local declarations
-      INTEGER :: iyea        ! date - (year, month, day, hour, minute)
-      INTEGER :: imon
-      INTEGER :: iday
-      INTEGER :: ihou
-      INTEGER :: imin
-      INTEGER :: imday         ! Number of days in month.
-      REAL(KIND=wp) :: zdayfrc       ! Fraction of day
-         
-      INTEGER, DIMENSION(12) ::   imonth_len    !: length in days of the months of the current year
-            
-      !-----------------------------------------------------------------------
-      ! Initial date initialization (year, month, day, hour, minute)
-      ! (This assumes that the initial date is for 00z)
-      !-----------------------------------------------------------------------
-      iyea =   ndate0 / 10000
-      imon = ( ndate0 - iyea * 10000 ) / 100
-      iday =   ndate0 - iyea * 10000 - imon * 100
-      ihou = 0
-      imin = 0
-      
-      !-----------------------------------------------------------------------
-      ! Compute number of days + number of hours + min since initial time
-      !-----------------------------------------------------------------------
-      iday    = iday +  nitend  * rdt / rday
-      zdayfrc =  nitend  * rdt / rday
-      zdayfrc = zdayfrc - AINT( zdayfrc )
-      ihou    = INT( zdayfrc * 24 )
-      imin    = INT( ( zdayfrc * 24 - ihou ) * 60 )
-
-      !-----------------------------------------------------------------------
-      ! Convert number of days (iday) into a real date
-      !----------------------------------------------------------------------
-
-      CALL calc_month_len( iyea, imonth_len )
-      
-      DO WHILE ( iday > imonth_len(imon) )
-         iday = iday - imonth_len(imon)
-         imon = imon + 1 
-         IF ( imon > 12 ) THEN
-            imon = 1
-            iyea = iyea + 1
-            CALL calc_month_len( iyea, imonth_len )  ! update month lengths
-         ENDIF
-      END DO
-
-      !-----------------------------------------------------------------------
-      ! Convert it into YYYYMMDD.HHMMSS format
-      !-----------------------------------------------------------------------
-      ddobsfin = iyea * 10000_dp + imon * 100_dp    + iday &
-         &     + ihou * 0.01_dp  + imin * 0.0001_dp
-
-    END SUBROUTINE fin_date
-    
+      REAL(KIND=dp), INTENT(OUT) :: ddobsini                   ! Initial date in YYYYMMDD.HHMMSS
+
+      CALL calc_date( nit000 - 1, ddobsini )
+
+   END SUBROUTINE ini_date
+
+   SUBROUTINE fin_date( ddobsfin )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE fin_date  ***
+      !!          
+      !! ** Purpose : Get final date in double precision YYYYMMDD.HHMMSS format
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  06-03  (K. Mogensen)  Original code
+      !!        !  06-05  (K. Mogensen)  Reformatted
+      !!        !  06-10  (A. Weaver) Cleaning
+      !!        !  10-05  (D. Lea) Update to month length calculation for NEMO vn3.2
+      !!        !  2014-09  (D. Lea) Change to call generic routine calc_date
+      !!----------------------------------------------------------------------
+
+      IMPLICIT NONE
+
+      !! * Arguments
+      REAL(dp), INTENT(OUT) :: ddobsfin ! Final date in YYYYMMDD.HHMMSS
+
+      CALL calc_date( nitend, ddobsfin )
+
+   END SUBROUTINE fin_date
+   
 END MODULE diaobs
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_fbm.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_fbm.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_fbm.F90	(revision 6140)
@@ -45,8 +45,4 @@
    INTEGER, PARAMETER    :: fbimdi = -99999   !: Integers
    REAL(fbsp), PARAMETER :: fbrmdi =  99999   !: Reals
-
-   ! Output stream choice
-   LOGICAL               :: ln_cl4 = .FALSE.  !: Logical switch for
-                                              !: class 4 file outputs
  
    ! Main data structure for observation feedback data.
@@ -1030,31 +1026,4 @@
 
    SUBROUTINE write_obfbdata( cdfilename, fbdata )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE write_obfbdata  ***
-      !!
-      !! ** Purpose :   Write an obfbdata structure into a netCDF file.
-      !!
-      !! ** Method  :   Decides which output wrapper to use. 
-      !!
-      !! ** Action  : 
-      !!
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(len=*) :: cdfilename ! Output filename
-      TYPE(obfbdata)   :: fbdata     ! obsfbdata structure
-#if defined key_offobsoper
-      IF (ln_cl4) THEN
-          ! Class 4 file output stream
-          CALL write_obfbdata_cl( cdfilename, fbdata )
-      ELSE
-#endif
-          ! Standard feedback file output stream
-          CALL write_obfbdata_fb( cdfilename, fbdata )
-#if defined key_offobsoper
-      ENDIF
-#endif
-   END SUBROUTINE write_obfbdata
-
-   SUBROUTINE write_obfbdata_fb( cdfilename, fbdata )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE write_obfbdata  ***
@@ -1555,237 +1524,5 @@
 
       
-   END SUBROUTINE write_obfbdata_fb
-
-#if defined key_offobsoper
-   SUBROUTINE write_obfbdata_cl(cdfilename, fbdata)
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE write_obfbdata_cl  ***
-      !!
-      !! ** Purpose : Write an obfbdata structure into a class 4 file.
-      !!
-      !! ** Method  : 1. Allocate memory needed by ooo_write
-      !!              2. Map obfbdata into allocated memory
-      !!              3. Pass mapped data to ooo_write
-      !!              4. Deallocate memory
-      !!----------------------------------------------------------------------
-      USE dom_oce, ONLY: narea
-      USE ooo_write
-      USE ooo_data
-      !! * Arguments
-      CHARACTER(len=*) :: cdfilename ! Feedback filename
-      TYPE(obfbdata)   :: fbdata     ! obsfbdata structure
-      !! * Local variables
-      CHARACTER(len=17), PARAMETER :: cpname = 'write_obfbdata_cl'
-      CHARACTER(len=64) :: &
-              & cdate, &   !: class 4 file validity date 
-              & cconf, &   !: model configuration
-              & csys, &    !: model system
-              & ccont, &   !: contact email
-              & cinst, &   !: institution
-              & cversion   !: model version
-      CHARACTER(len=8) :: &
-              & ckind      !: observation kind
-      CHARACTER(len=3) :: cfield
-      INTEGER :: kobs, &   !: number of observations
-              &  kvars, &  !: number of physical variables
-              &  kdeps, &  !: number of observed depths
-              &  kfcst, &  !: number of forecasts
-              &  kifcst, & !: current forecast number
-              &  kproc     !: processor number
-      INTEGER, DIMENSION(:, :, :), ALLOCATABLE :: &
-              &  kqc       !: quality control counterpart
-      INTEGER(KIND=2), DIMENSION(:, :, :), ALLOCATABLE :: &
-              &  k2qc       !: quality control counterpart
-      REAL(kind=fbdp) :: &
-              &  pmodjuld  !: model Julian day
-      REAL(kind=fbdp), DIMENSION(:), ALLOCATABLE :: &
-              &  plead, &  !: forecast lead time
-              &  plam, &   !: longitude of observation
-              &  pphi, &   !: latitude of observation
-              &  ptim      !: time of observation
-      REAL(kind=fbdp), DIMENSION(:, :), ALLOCATABLE :: &
-              &  pdep      !: depths of observations
-      REAL(kind=fbdp), DIMENSION(:, :, :), ALLOCATABLE :: &
-              &  pob, &    !: observation counterpart
-              &  pextra    !: extra field counterpart
-      REAL(kind=fbdp), DIMENSION(:, :, :), ALLOCATABLE :: &
-              &  pmod      !: model counterpart
-      CHARACTER(len=128) :: &
-              &  clfilename  !: class 4 file name
-      CHARACTER(len=128), DIMENSION(:), ALLOCATABLE :: &
-              &  ctype       !: Instrument type
-      CHARACTER(len=nf90_max_name) :: &
-              & cdtmp        !: NetCDF variable name
-      CHARACTER(len=8), DIMENSION(:), ALLOCATABLE :: &
-              &  cwmo, &     !: Instrument WMO ID
-              &  cunit, &    !: Instrument WMO ID
-              &  cvarname    !: Instrument WMO ID
-      INTEGER :: &
-              &  idep, &     !: Loop variable
-              &  ivar, &     !: Loop variable
-              &  iobs, &     !: Loop variable
-              &  ii, &       !: Loop variable
-              &  ij, &       !: Loop variable
-              &  ik, &       !: Loop variable
-              &  il          !: Loop variable
-      cconf = TRIM(cl4_cfg)
-      csys = TRIM(cl4_sys)
-      cversion = TRIM(cl4_vn)
-      ccont = TRIM(cl4_contact)
-      cinst = TRIM(cl4_inst)
-      cdate = TRIM(cl4_date)
-      CALL locate_kind(cdfilename, ckind)
-      kproc = narea
-      kfcst = cl4_fcst_len
-      kobs = fbdata%nobs
-      kdeps = fbdata%nlev
-      kvars = fbdata%nvar
-      IF (kobs .GT. 0) THEN
-         ALLOCATE(plam(kobs), &
-               &  pphi(kobs), &
-               &  ptim(kobs), &
-               &  plead(kfcst), &
-               &  pdep(kdeps, kobs), &
-               &  kqc(kdeps, kvars, kobs), &
-               &  k2qc(kdeps, kvars, kobs), &
-               &  pob(kdeps, kvars, kobs), &
-               &  pmod(kdeps, kvars, kobs), &
-               &  pextra(kdeps, kvars, kobs), &
-               &  ctype(kobs), &
-               &  cwmo(kobs), &
-               &  cunit(kvars), &
-               &  cvarname(kvars))
-         plam(:) = fbdata%plam(:)
-         pphi(:) = fbdata%pphi(:)
-         ptim(:) = fbdata%ptim(:)
-         pdep(:, :) = fbdata%pdep(:, :)
-         kqc(:,:,:) = 1.
-         DO ii = 1, kvars
-            cvarname(ii)  = fbdata%cname(ii)
-            cunit(ii)     = fbdata%cobunit(ii)
-         END DO
-
-         ! Quality control algorithm
-         k2qc(:,:,:) = NF90_FILL_SHORT
-         DO idep = 1,kdeps
-            DO ivar = 1, kvars
-               DO iobs = 1, kobs
-                  ! 1 symbolises good for fbdata
-                  ! fbimdi symbolises that qc has not been set
-                  ! Essentially, if any fbdata flag is not an element of {1, fbimdi}
-                  ! then set the class 4 flag to bad.
-                  ! Note: fbdata%ioqc is marked good if zero.
-                  IF (((fbdata%ioqc(iobs) /= 0) .AND. &
-                            & (fbdata%ioqc(iobs) /= fbimdi)) .OR. &
-                    & ((fbdata%ipqc(iobs) /= 1) .AND. &
-                            & (fbdata%ipqc(iobs) /= fbimdi)) .OR. &
-                    & ((fbdata%idqc(idep,iobs) /= 1) .AND. &
-                            & (fbdata%idqc(idep,iobs) /= fbimdi)) .OR. &
-                    & ((fbdata%ivqc(iobs,ivar) /= 1) .AND. &
-                            & (fbdata%ivqc(iobs,ivar) /= fbimdi)) .OR. &
-                    & ((fbdata%ivlqc(idep,iobs,ivar) /= 1) .AND. &
-                            & (fbdata%ivlqc(idep,iobs,ivar) /= fbimdi)) .OR. &
-                    & ((fbdata%itqc(iobs) /= 1) .AND. &
-                            & (fbdata%itqc(iobs) /= fbimdi))) THEN
-                     ! 1 symbolises bad for class 4 file
-                     k2qc(idep, ivar, iobs) = 1
-                  ELSE
-                     ! 0 symbolises good for class 4 file
-                     k2qc(idep, ivar, iobs) = 0
-                  END IF 
-               END DO
-            END DO
-         END DO
-
-         ! Permute observation dimensions
-         pob(:,:,:) = RESHAPE(fbdata%pob, (/kdeps, kvars, kobs/), &
-                            & ORDER=(/1, 3, 2/))
-
-         ! Explicit model counterpart dimension permutation
-         ! 1,2,3,4 --> 1,4,2,3
-         pmod(:,:,:) = fbrmdi
-         ij = cl4_fcst_idx(jimatch)
-         DO ii = 1,kdeps
-            DO ik = 1, kvars
-               DO il = 1, kobs
-                  pmod(ii,ik,il) = fbdata%padd(ii,il,1,ik)
-               END DO
-            END DO
-         END DO
-
-         ! Extra fields set to missing for now
-         pextra(:,:,:) = fbrmdi
-
-         ! Lead time of class 4 file is a global parameter
-         plead = cl4_leadtime(1:cl4_fcst_len)
-
-         ! Model Julian day
-         pmodjuld = cl4_modjuld
-
-         ! Observation types
-         ctype(:) = 'X'
-         DO ii = 1,kobs
-            ctype(ii) = fbdata%cdtyp(ii)
-         END DO
-
-         ! World Meteorology Organisation codes
-         cwmo(:) = fbdata%cdwmo(:)
-
-         ! Initialise class 4 file
-         CALL ooo_wri_init(cconf, csys, ckind, cversion, ccont, cinst, cdate, &
-                         & kproc, kobs, kvars, kdeps, kfcst, &
-                         & clfilename)
-
-         ! Write standard variables
-         CALL ooo_wri_default(clfilename, kobs, kvars, kfcst, kdeps, &
-                            & ctype, cwmo, cunit, cvarname, &
-                            & plam, pphi, pdep, ptim, pob, plead, &
-                            & k2qc, pmodjuld)
-         !! Write to optional variables
-         cdtmp = cl4_vars(jimatch)
-         IF ( (TRIM(cdtmp) == "forecast") .OR. &
-              (TRIM(cdtmp) == "persistence") ) THEN
-            !! 4D variables
-            CALL ooo_wri_extra(clfilename, TRIM(cdtmp), kdeps, kfcst, &
-                            &  kvars, kobs, (/ 1,ij,1,1 /), (/ kdeps,1,kvars,kobs /), pmod)
-         ELSE
-            !! 3D variables
-            CALL ooo_wri_extra(clfilename, TRIM(cdtmp), kdeps, &
-                            &  kvars, kobs, (/ 1,1,1 /), (/ kdeps,kvars,kobs /), pmod)
-         ENDIF
-
-         DEALLOCATE(plam, pphi, ptim, pdep, plead, kqc, k2qc, &
-                  & pob, pmod, pextra, ctype, cwmo, &
-                  & cunit, cvarname)
-      END IF
-   END SUBROUTINE write_obfbdata_cl
-#endif
-
-#if defined key_offobsoper
-   SUBROUTINE locate_kind(cdfilename, ckind)
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE locate_kind  ***
-      !!
-      !! ** Purpose : Detect which kind of class 4 file is being produced.
-      !!
-      !! ** Method  : 1. Inspect cdfilename for observation kind.
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*) :: cdfilename ! Feedback filename
-      CHARACTER(len=8) :: ckind
-      IF (cdfilename(1:3) == 'sst') THEN
-         ckind = 'SST'
-      ELSE IF (cdfilename(1:3) == 'sla') THEN
-         ckind = 'SLA'
-      ELSE IF (cdfilename(1:3) == 'pro') THEN
-         ckind = 'profile'
-      ELSE IF (cdfilename(1:3) == 'ena') THEN
-         ckind = 'profile'
-      ELSE IF (cdfilename(1:3) == 'sea') THEN
-         ckind = 'seaice'
-      ELSE
-         ckind = 'unknown'
-      END IF
-   END SUBROUTINE locate_kind
-#endif
+   END SUBROUTINE write_obfbdata
 
    SUBROUTINE putvaratt_obfbdata( idfile, idvar, cdlongname, cdunits, &
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_grd_bruteforce.h90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_grd_bruteforce.h90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_grd_bruteforce.h90	(revision 6140)
@@ -325,5 +325,5 @@
          CALL obs_mpp_max_integer( kobsj, kobs )
       ELSE
-         CALL obs_mpp_find_obs_proc( kproc, kobsi, kobsj, kobs )
+         CALL obs_mpp_find_obs_proc( kproc, kobs )
       ENDIF
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_grid.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_grid.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_grid.F90	(revision 6140)
@@ -52,5 +52,5 @@
 
    !! Default values
-   REAL, PUBLIC :: grid_search_res = 0.5    ! Resolution of grid
+   REAL, PUBLIC :: rn_gridsearchres = 0.5   ! Resolution of grid
    INTEGER, PRIVATE :: gsearch_nlons_def    ! Num of longitudes
    INTEGER, PRIVATE :: gsearch_nlats_def    ! Num of latitudes
@@ -83,5 +83,5 @@
    LOGICAL, PUBLIC :: ln_grid_global         ! Use global distribution of observations
    CHARACTER(LEN=44), PUBLIC :: &
-      & grid_search_file    ! file name head for grid search lookup 
+      & cn_gridsearchfile    ! file name head for grid search lookup 
 
    !!----------------------------------------------------------------------
@@ -613,5 +613,5 @@
          CALL obs_mpp_max_integer( kobsj, kobs )
       ELSE
-         CALL obs_mpp_find_obs_proc( kproc, kobsi, kobsj, kobs )
+         CALL obs_mpp_find_obs_proc( kproc, kobs )
       ENDIF
 
@@ -690,12 +690,12 @@
          
          IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*)'Grid search resolution : ', grid_search_res
-         
-         gsearch_nlons_def  = NINT( 360.0_wp / grid_search_res ) 
-         gsearch_nlats_def  = NINT( 180.0_wp / grid_search_res )
-         gsearch_lonmin_def = -180.0_wp + 0.5_wp * grid_search_res
-         gsearch_latmin_def =  -90.0_wp + 0.5_wp * grid_search_res
-         gsearch_dlon_def   = grid_search_res
-         gsearch_dlat_def   = grid_search_res
+         IF(lwp) WRITE(numout,*)'Grid search resolution : ', rn_gridsearchres
+         
+         gsearch_nlons_def  = NINT( 360.0_wp / rn_gridsearchres ) 
+         gsearch_nlats_def  = NINT( 180.0_wp / rn_gridsearchres )
+         gsearch_lonmin_def = -180.0_wp + 0.5_wp * rn_gridsearchres
+         gsearch_latmin_def =  -90.0_wp + 0.5_wp * rn_gridsearchres
+         gsearch_dlon_def   = rn_gridsearchres
+         gsearch_dlat_def   = rn_gridsearchres
          
          IF (lwp) THEN
@@ -710,8 +710,8 @@
          IF ( ln_grid_global ) THEN
             WRITE(cfname, FMT="(A,'_',A)") &
-               &          TRIM(grid_search_file), 'global.nc'
+               &          TRIM(cn_gridsearchfile), 'global.nc'
          ELSE
             WRITE(cfname, FMT="(A,'_',I4.4,'of',I4.4,'by',I4.4,'.nc')") &
-               &          TRIM(grid_search_file), nproc, jpni, jpnj
+               &          TRIM(cn_gridsearchfile), nproc, jpni, jpnj
          ENDIF
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_inter_sup.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_inter_sup.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_inter_sup.F90	(revision 6140)
@@ -35,5 +35,5 @@
 CONTAINS
 
-   SUBROUTINE obs_int_comm_3d( kptsi, kptsj, kobs, kpk, kgrdi, kgrdj, &
+   SUBROUTINE obs_int_comm_3d( kptsi, kptsj, kobs, kpi, kpj, kpk, kgrdi, kgrdj, &
       &                        pval, pgval, kproc )
       !!----------------------------------------------------------------------
@@ -57,4 +57,6 @@
       INTEGER, INTENT(IN) :: kptsj     ! Number of j horizontal points per stencil
       INTEGER, INTENT(IN) :: kobs      ! Local number of observations
+      INTEGER, INTENT(IN) :: kpi       ! Number of points in i direction
+      INTEGER, INTENT(IN) :: kpj       ! Number of points in j direction
       INTEGER, INTENT(IN) :: kpk       ! Number of levels
       INTEGER, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: &
@@ -63,5 +65,5 @@
       INTEGER, OPTIONAL, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: &
          & kproc            ! Precomputed processor for each i,j,iobs points
-      REAL(KIND=wp), DIMENSION(jpi,jpj,kpk), INTENT(IN) ::&
+      REAL(KIND=wp), DIMENSION(kpi,kpj,kpk), INTENT(IN) ::&
          & pval             ! Local 3D array to extract data from
       REAL(KIND=wp), DIMENSION(kptsi,kptsj,kpk,kobs), INTENT(OUT) ::&
@@ -73,10 +75,10 @@
          IF (PRESENT(kproc)) THEN
 
-            CALL obs_int_comm_3d_global( kptsi, kptsj, kobs, kpk, kgrdi, &
+            CALL obs_int_comm_3d_global( kptsi, kptsj, kobs, kpi, kpj, kpk, kgrdi, &
                &                         kgrdj, pval, pgval, kproc=kproc )
 
          ELSE
 
-            CALL obs_int_comm_3d_global( kptsi, kptsj, kobs, kpk, kgrdi, &
+            CALL obs_int_comm_3d_global( kptsi, kptsj, kobs, kpi, kpj, kpk, kgrdi, &
                &                         kgrdj, pval, pgval )
 
@@ -85,5 +87,5 @@
       ELSE
 
-         CALL obs_int_comm_3d_local( kptsi, kptsj, kobs, kpk, kgrdi, kgrdj, &
+         CALL obs_int_comm_3d_local( kptsi, kptsj, kobs, kpi, kpj, kpk, kgrdi, kgrdj, &
             &                        pval, pgval )
 
@@ -92,5 +94,5 @@
    END SUBROUTINE obs_int_comm_3d
 
-   SUBROUTINE obs_int_comm_2d( kptsi, kptsj, kobs, kgrdi, kgrdj, pval, pgval, &
+   SUBROUTINE obs_int_comm_2d( kptsi, kptsj, kobs, kpi, kpj, kgrdi, kgrdj, pval, pgval, &
       &                        kproc )
       !!----------------------------------------------------------------------
@@ -111,4 +113,6 @@
       INTEGER, INTENT(IN) :: kptsj        ! Number of j horizontal points per stencil
       INTEGER, INTENT(IN) :: kobs          ! Local number of observations
+      INTEGER, INTENT(IN) :: kpi          ! Number of model grid points in i direction
+      INTEGER, INTENT(IN) :: kpj          ! Number of model grid points in j direction
       INTEGER, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: &
          & kgrdi, &         ! i,j indicies for each stencil
@@ -116,5 +120,5 @@
       INTEGER, OPTIONAL, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: &
          & kproc            ! Precomputed processor for each i,j,iobs points
-      REAL(KIND=wp), DIMENSION(jpi,jpj), INTENT(IN) ::&
+      REAL(KIND=wp), DIMENSION(kpi,kpj), INTENT(IN) ::&
          & pval             ! Local 3D array to extra data from
       REAL(KIND=wp), DIMENSION(kptsi,kptsj,kobs), INTENT(OUT) ::&
@@ -136,9 +140,9 @@
       IF (PRESENT(kproc)) THEN
 
-         CALL obs_int_comm_3d( kptsi, kptsj, kobs, 1, kgrdi, kgrdj, zval, &
+         CALL obs_int_comm_3d( kptsi, kptsj, kobs, kpi, kpj, 1, kgrdi, kgrdj, zval, &
             &                  zgval, kproc=kproc )
       ELSE
 
-         CALL obs_int_comm_3d( kptsi, kptsj, kobs, 1, kgrdi, kgrdj, zval, &
+         CALL obs_int_comm_3d( kptsi, kptsj, kobs, kpi, kpj, 1, kgrdi, kgrdj, zval, &
             &                  zgval )
 
@@ -154,5 +158,5 @@
    END SUBROUTINE obs_int_comm_2d
 
-   SUBROUTINE obs_int_comm_3d_global( kptsi, kptsj, kobs, kpk, kgrdi, kgrdj, &
+   SUBROUTINE obs_int_comm_3d_global( kptsi, kptsj, kobs, kpi, kpj, kpk, kgrdi, kgrdj, &
       &                               pval, pgval, kproc )
       !!----------------------------------------------------------------------
@@ -174,4 +178,6 @@
       INTEGER, INTENT(IN) :: kptsj     ! Number of j horizontal points per stencil
       INTEGER, INTENT(IN) :: kobs      ! Local number of observations
+      INTEGER, INTENT(IN) :: kpi       ! Number of model points in i direction
+      INTEGER, INTENT(IN) :: kpj       ! Number of model points in j direction
       INTEGER, INTENT(IN) :: kpk       ! Number of levels
       INTEGER, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: &
@@ -180,5 +186,5 @@
       INTEGER, OPTIONAL, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: &
          & kproc            ! Precomputed processor for each i,j,iobs points
-      REAL(KIND=wp), DIMENSION(jpi,jpj,kpk), INTENT(IN) ::&
+      REAL(KIND=wp), DIMENSION(kpi,kpj,kpk), INTENT(IN) ::&
          & pval             ! Local 3D array to extract data from
       REAL(KIND=wp), DIMENSION(kptsi,kptsj,kpk,kobs), INTENT(OUT) ::&
@@ -207,11 +213,11 @@
 
       ! Check valid points
-      
+
       IF ( ( MAXVAL(kgrdi) > jpiglo ) .OR. ( MINVAL(kgrdi) < 1 ) .OR. &
          & ( MAXVAL(kgrdj) > jpjglo ) .OR. ( MINVAL(kgrdj) < 1 ) ) THEN
-         
+
          CALL ctl_stop( 'Error in obs_int_comm_3d_global', &
             &           'Point outside global domain' )
-         
+
       ENDIF
 
@@ -323,5 +329,5 @@
    END SUBROUTINE obs_int_comm_3d_global
    
-   SUBROUTINE obs_int_comm_3d_local( kptsi, kptsj, kobs, kpk, kgrdi, kgrdj, &
+   SUBROUTINE obs_int_comm_3d_local( kptsi, kptsj, kobs, kpi, kpj, kpk, kgrdi, kgrdj, &
       &                              pval, pgval )
       !!----------------------------------------------------------------------
@@ -343,9 +349,11 @@
       INTEGER, INTENT(IN) :: kptsj        ! Number of j horizontal points per stencil
       INTEGER, INTENT(IN) :: kobs         ! Local number of observations
+      INTEGER, INTENT(IN) :: kpi          ! Number of model points in i direction
+      INTEGER, INTENT(IN) :: kpj          ! Number of model points in j direction
       INTEGER, INTENT(IN) :: kpk          ! Number of levels
       INTEGER, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: &
          & kgrdi, &         ! i,j indicies for each stencil
          & kgrdj
-      REAL(KIND=wp), DIMENSION(jpi,jpj,kpk), INTENT(IN) ::&
+      REAL(KIND=wp), DIMENSION(kpi,kpj,kpk), INTENT(IN) ::&
          & pval             ! Local 3D array to extract data from
       REAL(KIND=wp), DIMENSION(kptsi,kptsj,kpk,kobs), INTENT(OUT) ::&
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_mpp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_mpp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_mpp.F90	(revision 6140)
@@ -7,4 +7,6 @@
    !!             -   ! 2006-05  (K. Mogensen)  Reformatted
    !!             -   ! 2008-01  (K. Mogensen)  add mpp_global_max
+   !!            3.6  ! 2015-01  (J. Waters) obs_mpp_find_obs_proc 
+   !!                            rewritten to avoid global arrays
    !!----------------------------------------------------------------------
 #  define mpivar mpi_double_precision
@@ -12,5 +14,5 @@
    !! obs_mpp_bcast_integer : Broadcast an integer array from a processor to all processors
    !! obs_mpp_max_integer   : Find maximum on all processors of each value in an integer on all processors
-   !! obs_mpp_find_obs_proc : Find processors which should hold the observations
+   !! obs_mpp_find_obs_proc : Find processors which should hold the observations, avoiding global arrays
    !! obs_mpp_sum_integers  : Sum an integer array from all processors
    !! obs_mpp_sum_integer   : Sum an integer from all processors
@@ -111,18 +113,18 @@
 
 
-   SUBROUTINE obs_mpp_find_obs_proc( kobsp, kobsi, kobsj, kno )
-      !!----------------------------------------------------------------------
-      !!               ***  ROUTINE obs_mpp_find_obs_proc ***
-      !!          
-      !! ** Purpose : From the array kobsp containing the results of the grid
+   SUBROUTINE obs_mpp_find_obs_proc( kobsp,kno )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE obs_mpp_find_obs_proc  ***
+      !!         
+      !! ** Purpose : From the array kobsp containing the results of the
       !!              grid search on each processor the processor return a
       !!              decision of which processors should hold the observation.
       !!
-      !! ** Method  : A temporary 2D array holding all the decisions is
-      !!              constructed using mpi_allgather on each processor.
-      !!              If more than one processor has found the observation
-      !!              with the observation in the inner domain gets it
-      !!
-      !! ** Action  : This does only work for MPI. 
+      !! ** Method  : Synchronize the processor number for each obs using
+      !!              obs_mpp_max_integer. If an observation exists on two 
+      !!              processors it will be allocated to the lower numbered
+      !!              processor.
+      !!
+      !! ** Action  : This does only work for MPI.
       !!              It does not work for SHMEM.
       !!
@@ -130,99 +132,44 @@
       !!----------------------------------------------------------------------
       INTEGER                , INTENT(in   ) ::   kno
-      INTEGER, DIMENSION(kno), INTENT(in   ) ::   kobsi, kobsj
       INTEGER, DIMENSION(kno), INTENT(inout) ::   kobsp
       !
 #if defined key_mpp_mpi
       !
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: size
-      INTEGER :: ierr
-      INTEGER :: iobsip
-      INTEGER :: iobsjp
-      INTEGER :: num_sus_obs
-      INTEGER, DIMENSION(kno) ::   iobsig, iobsjg
-      INTEGER, ALLOCATABLE, DIMENSION(:,:) ::   iobsp, iobsi, iobsj
-      !!
-INCLUDE 'mpif.h'
-      !!----------------------------------------------------------------------
-
-      !-----------------------------------------------------------------------
-      ! Call the MPI library to find the maximum accross processors
-      !-----------------------------------------------------------------------
-      CALL mpi_comm_size( mpi_comm_opa, size, ierr )
-      !-----------------------------------------------------------------------
-      ! Convert local grids points to global grid points
-      !-----------------------------------------------------------------------
+      !
+      INTEGER :: ji, isum
+      INTEGER, DIMENSION(kno) ::   iobsp
+      !!
+      !!
+
+      iobsp=kobsp
+
+      WHERE( iobsp(:) == -1 )
+         iobsp(:) = 9999999
+      END WHERE
+
+      iobsp=-1*iobsp
+
+      CALL obs_mpp_max_integer( iobsp, kno )
+
+      kobsp=-1*iobsp
+
+      isum=0
       DO ji = 1, kno
-         IF ( ( kobsi(ji) >= 1 ) .AND. ( kobsi(ji) <= jpi ) .AND. &
-            & ( kobsj(ji) >= 1 ) .AND. ( kobsj(ji) <= jpj ) ) THEN
-            iobsig(ji) = mig( kobsi(ji) )
-            iobsjg(ji) = mjg( kobsj(ji) )
-         ELSE
-            iobsig(ji) = -1
-            iobsjg(ji) = -1
+         IF ( kobsp(ji) == 9999999 ) THEN
+            isum=isum+1
+            kobsp(ji)=-1
          ENDIF
-      END DO
-      !-----------------------------------------------------------------------
-      ! Get the decisions from all processors
-      !-----------------------------------------------------------------------
-      ALLOCATE( iobsp(kno,size) )
-      ALLOCATE( iobsi(kno,size) )
-      ALLOCATE( iobsj(kno,size) )
-      CALL mpi_allgather( kobsp, kno, mpi_integer, &
-         &                iobsp, kno, mpi_integer, &
-         &                mpi_comm_opa, ierr )
-      CALL mpi_allgather( iobsig, kno, mpi_integer, &
-         &                iobsi, kno, mpi_integer, &
-         &                mpi_comm_opa, ierr )
-      CALL mpi_allgather( iobsjg, kno, mpi_integer, &
-         &                iobsj, kno, mpi_integer, &
-         &                mpi_comm_opa, ierr )
-
-      !-----------------------------------------------------------------------
-      ! Find the processor with observations from the lowest processor 
-      ! number among processors holding the observation.
-      !-----------------------------------------------------------------------
-      kobsp(:) = -1
-      num_sus_obs = 0
-      DO ji = 1, kno
-         DO jj = 1, size
-            IF ( ( kobsp(ji) == -1 ) .AND. ( iobsp(ji,jj) /= -1 ) ) THEN
-               kobsp(ji) = iobsp(ji,jj)
-               iobsip = iobsi(ji,jj)
-               iobsjp = iobsj(ji,jj)
-            ENDIF
-            IF ( ( kobsp(ji) /= -1 ) .AND. ( iobsp(ji,jj) /= -1 ) ) THEN
-               IF ( ( iobsip /= iobsi(ji,jj) ) .OR. &
-                  & ( iobsjp /= iobsj(ji,jj) ) ) THEN
-                  IF ( ( kobsp(ji) < 1000000 ) .AND. &
-                     & ( iobsp(ji,jj) < 1000000 ) ) THEN
-                     num_sus_obs=num_sus_obs+1
-                  ENDIF
-               ENDIF
-               IF ( mppmap(iobsip,iobsjp) /= ( kobsp(ji)+1 ) ) THEN
-                  IF ( ( iobsi(ji,jj) /= -1 ) .AND. &
-                     & ( iobsj(ji,jj) /= -1 ) ) THEN
-                     IF ((mppmap(iobsi(ji,jj),iobsj(ji,jj)) == (iobsp(ji,jj)+1))&
-                        & .OR. ( iobsp(ji,jj) < kobsp(ji) ) ) THEN
-                        kobsp(ji) = iobsp(ji,jj)
-                        iobsip = iobsi(ji,jj)
-                        iobsjp = iobsj(ji,jj)
-                     ENDIF
-                  ENDIF
-               ENDIF
-            ENDIF
-         END DO
-      END DO
-      IF (lwp) WRITE(numout,*) 'Number of suspicious observations: ',num_sus_obs
-
-      DEALLOCATE( iobsj )
-      DEALLOCATE( iobsi )
-      DEALLOCATE( iobsp )
+      ENDDO
+
+
+      IF ( isum > 0 ) THEN
+         IF (lwp) WRITE(numout,*) isum, ' observations failed the grid search.'
+         IF (lwp) WRITE(numout,*)'If ln_grid_search_lookup=.TRUE., try reducing grid_search_res'
+      ENDIF
+
 #else
       ! no MPI: empty routine
-#endif
-      !
+#endif     
+      
    END SUBROUTINE obs_mpp_find_obs_proc
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_oper.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_oper.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_oper.F90	(revision 6140)
@@ -7,28 +7,20 @@
 
    !!----------------------------------------------------------------------
-   !!   obs_pro_opt :    Compute the model counterpart of temperature and
-   !!                    salinity observations from profiles
-   !!   obs_sla_opt :    Compute the model counterpart of sea level anomaly
-   !!                    observations
-   !!   obs_sst_opt :    Compute the model counterpart of sea surface temperature
-   !!                    observations
-   !!   obs_sss_opt :    Compute the model counterpart of sea surface salinity
-   !!                    observations
-   !!   obs_seaice_opt : Compute the model counterpart of sea ice concentration
-   !!                    observations
-   !!
-   !!   obs_vel_opt :    Compute the model counterpart of zonal and meridional
-   !!                    components of velocity from observations.
+   !!   obs_prof_opt :    Compute the model counterpart of profile data
+   !!   obs_surf_opt :    Compute the model counterpart of surface data
+   !!   obs_pro_sco_opt: Compute the model counterpart of temperature and 
+   !!                    salinity observations from profiles in generalised 
+   !!                    vertical coordinates 
    !!----------------------------------------------------------------------
 
-   !! * Modules used   
+   !! * Modules used
    USE par_kind, ONLY : &         ! Precision variables
       & wp
    USE in_out_manager             ! I/O manager
    USE obs_inter_sup              ! Interpolation support
-   USE obs_inter_h2d, ONLY : &    ! Horizontal interpolation to the observation pt
+   USE obs_inter_h2d, ONLY : &    ! Horizontal interpolation to the obs pt
       & obs_int_h2d, &
       & obs_int_h2d_init
-   USE obs_inter_z1d, ONLY : &    ! Vertical interpolation to the observation pt
+   USE obs_inter_z1d, ONLY : &    ! Vertical interpolation to the obs pt
       & obs_int_z1d,    &
       & obs_int_z1d_spl
@@ -37,7 +29,12 @@
    USE dom_oce,       ONLY : &
       & glamt, glamu, glamv, &
-      & gphit, gphiu, gphiv
+      & gphit, gphiu, gphiv, & 
+      & gdept_n, gdept_0 
    USE lib_mpp,       ONLY : &
       & ctl_warn, ctl_stop
+   USE obs_grid,      ONLY : & 
+      & obs_level_search     
+   USE sbcdcy,        ONLY : &    ! For calculation of where it is night-time
+      & sbc_dcy, nday_qsr
 
    IMPLICIT NONE
@@ -46,12 +43,10 @@
    PRIVATE
 
-   PUBLIC obs_pro_opt, &  ! Compute the model counterpart of profile observations
-      &   obs_sla_opt, &  ! Compute the model counterpart of SLA observations
-      &   obs_sst_opt, &  ! Compute the model counterpart of SST observations
-      &   obs_sss_opt, &  ! Compute the model counterpart of SSS observations
-      &   obs_seaice_opt, &
-      &   obs_vel_opt     ! Compute the model counterpart of velocity profile data
-
-   INTEGER, PARAMETER, PUBLIC :: imaxavtypes = 20 ! Max number of daily avgd obs types
+   PUBLIC obs_prof_opt, &  ! Compute the model counterpart of profile obs
+      &   obs_pro_sco_opt, &  ! Compute the model counterpart of profile observations 
+      &   obs_surf_opt     ! Compute the model counterpart of surface obs
+
+   INTEGER, PARAMETER, PUBLIC :: &
+      & imaxavtypes = 20   ! Max number of daily avgd obs types
 
    !!----------------------------------------------------------------------
@@ -63,7 +58,10 @@
 CONTAINS
 
-   SUBROUTINE obs_pro_opt( prodatqc, kt, kpi, kpj, kpk, kit000, kdaystp, &
-      &                    ptn, psn, pgdept, ptmask, k1dint, k2dint, &
-      &                    kdailyavtypes )
+   SUBROUTINE obs_prof_opt( prodatqc, kt, kpi, kpj, kpk,          &
+      &                     kit000, kdaystp,                      &
+      &                     pvar1, pvar2, pgdept, pmask1, pmask2, &
+      &                     plam1, plam2, pphi1, pphi2,           &
+      &                     k1dint, k2dint, kdailyavtypes )
+
       !!-----------------------------------------------------------------------
       !!
@@ -78,5 +76,5 @@
       !!
       !!    First, a vertical profile of horizontally interpolated model
-      !!    now temperatures is computed at the obs (lon, lat) point.
+      !!    now values is computed at the obs (lon, lat) point.
       !!    Several horizontal interpolation schemes are available:
       !!        - distance-weighted (great circle) (k2dint = 0)
@@ -86,5 +84,5 @@
       !!        - polynomial (quadrilateral grid)  (k2dint = 4)
       !!
-      !!    Next, the vertical temperature profile is interpolated to the
+      !!    Next, the vertical profile is interpolated to the
       !!    data depth points. Two vertical interpolation schemes are
       !!    available:
@@ -96,14 +94,11 @@
       !!    routine.
       !!
-      !!    For ENACT moored buoy data (e.g., TAO), the model equivalent is
+      !!    If the logical is switched on, the model equivalent is
       !!    a daily mean model temperature field. So, we first compute
       !!    the mean, then interpolate only at the end of the day.
       !!
-      !!    Note: the in situ temperature observations must be converted
+      !!    Note: in situ temperature observations must be converted
       !!    to potential temperature (the model variable) prior to
       !!    assimilation. 
-      !!??????????????????????????????????????????????????????????????
-      !!    INCLUDE POTENTIAL TEMP -> IN SITU TEMP IN OBS OPERATOR???
-      !!??????????????????????????????????????????????????????????????
       !!
       !! ** Action  :
@@ -115,6 +110,7 @@
       !!      ! 07-01 (K. Mogensen) Merge of temperature and salinity
       !!      ! 07-03 (K. Mogensen) General handling of profiles
+      !!      ! 15-02 (M. Martin) Combined routine for all profile types
       !!-----------------------------------------------------------------------
-  
+
       !! * Modules used
       USE obs_profiles_def ! Definition of storage space for profile obs.
@@ -123,22 +119,30 @@
 
       !! * Arguments
-      TYPE(obs_prof), INTENT(INOUT) :: prodatqc  ! Subset of profile data not failing screening
-      INTEGER, INTENT(IN) :: kt        ! Time step
-      INTEGER, INTENT(IN) :: kpi       ! Model grid parameters
+      TYPE(obs_prof), INTENT(INOUT) :: &
+         & prodatqc                  ! Subset of profile data passing QC
+      INTEGER, INTENT(IN) :: kt      ! Time step
+      INTEGER, INTENT(IN) :: kpi     ! Model grid parameters
       INTEGER, INTENT(IN) :: kpj
       INTEGER, INTENT(IN) :: kpk
-      INTEGER, INTENT(IN) :: kit000    ! Number of the first time step 
-                                       !   (kit000-1 = restart time)
-      INTEGER, INTENT(IN) :: k1dint    ! Vertical interpolation type (see header)
-      INTEGER, INTENT(IN) :: k2dint    ! Horizontal interpolation type (see header)
-      INTEGER, INTENT(IN) :: kdaystp   ! Number of time steps per day                    
+      INTEGER, INTENT(IN) :: kit000  ! Number of the first time step
+                                     !   (kit000-1 = restart time)
+      INTEGER, INTENT(IN) :: k1dint  ! Vertical interpolation type (see header)
+      INTEGER, INTENT(IN) :: k2dint  ! Horizontal interpolation type (see header)
+      INTEGER, INTENT(IN) :: kdaystp ! Number of time steps per day
       REAL(KIND=wp), INTENT(IN), DIMENSION(kpi,kpj,kpk) :: &
-         & ptn,    &    ! Model temperature field
-         & psn,    &    ! Model salinity field
-         & ptmask       ! Land-sea mask
+         & pvar1,    &               ! Model field 1
+         & pvar2,    &               ! Model field 2
+         & pmask1,   &               ! Land-sea mask 1
+         & pmask2                    ! Land-sea mask 2
+      REAL(KIND=wp), INTENT(IN), DIMENSION(kpi,kpj) :: &
+         & plam1,    &               ! Model longitudes for variable 1
+         & plam2,    &               ! Model longitudes for variable 2
+         & pphi1,    &               ! Model latitudes for variable 1
+         & pphi2                     ! Model latitudes for variable 2
       REAL(KIND=wp), INTENT(IN), DIMENSION(kpk) :: &
-         & pgdept       ! Model array of depth levels
+         & pgdept                    ! Model array of depth levels
       INTEGER, DIMENSION(imaxavtypes), OPTIONAL :: &
-         & kdailyavtypes! Types for daily averages
+         & kdailyavtypes             ! Types for daily averages
+
       !! * Local declarations
       INTEGER ::   ji
@@ -154,125 +158,158 @@
       INTEGER, DIMENSION(imaxavtypes) :: &
          & idailyavtypes
+      INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: &
+         & igrdi1, &
+         & igrdi2, &
+         & igrdj1, &
+         & igrdj2
       REAL(KIND=wp) :: zlam
       REAL(KIND=wp) :: zphi
       REAL(KIND=wp) :: zdaystp
       REAL(KIND=wp), DIMENSION(kpk) :: &
-         & zobsmask, &
+         & zobsmask1, &
+         & zobsmask2, &
          & zobsk,    &
          & zobs2k
       REAL(KIND=wp), DIMENSION(2,2,kpk) :: &
-         & zweig
+         & zweig1, &
+         & zweig2
       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: &
-         & zmask, &
-         & zintt, &
-         & zints, &
-         & zinmt, &
-         & zinms
+         & zmask1, &
+         & zmask2, &
+         & zint1, &
+         & zint2, &
+         & zinm1, &
+         & zinm2
       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
-         & zglam, &
-         & zgphi
-      INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: &
-         & igrdi, &
-         & igrdj
+         & zglam1, &
+         & zglam2, &
+         & zgphi1, &
+         & zgphi2
+      LOGICAL :: ld_dailyav
 
       !------------------------------------------------------------------------
       ! Local initialization 
       !------------------------------------------------------------------------
-      ! ... Record and data counters
+      ! Record and data counters
       inrc = kt - kit000 + 2
       ipro = prodatqc%npstp(inrc)
- 
+
       ! Daily average types
+      ld_dailyav = .FALSE.
       IF ( PRESENT(kdailyavtypes) ) THEN
          idailyavtypes(:) = kdailyavtypes(:)
+         IF ( ANY (idailyavtypes(:) /= -1) ) ld_dailyav = .TRUE.
       ELSE
          idailyavtypes(:) = -1
       ENDIF
 
-      ! Initialize daily mean for first timestep
+      ! Daily means are calculated for values over timesteps:
+      !  [1 <= kt <= kdaystp], [kdaystp+1 <= kt <= 2*kdaystp], ...
       idayend = MOD( kt - kit000 + 1, kdaystp )
 
-      ! Added kt == 0 test to catch restart case 
-      IF ( idayend == 1 .OR. kt == 0) THEN
-         IF (lwp) WRITE(numout,*) 'Reset prodatqc%vdmean on time-step: ',kt
+      IF ( ld_dailyav ) THEN
+
+         ! Initialize daily mean for first timestep of the day
+         IF ( idayend == 1 .OR. kt == 0 ) THEN
+            DO jk = 1, jpk
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     prodatqc%vdmean(ji,jj,jk,1) = 0.0
+                     prodatqc%vdmean(ji,jj,jk,2) = 0.0
+                  END DO
+               END DO
+            END DO
+         ENDIF
+
          DO jk = 1, jpk
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  prodatqc%vdmean(ji,jj,jk,1) = 0.0
-                  prodatqc%vdmean(ji,jj,jk,2) = 0.0
+                  ! Increment field 1 for computing daily mean
+                  prodatqc%vdmean(ji,jj,jk,1) = prodatqc%vdmean(ji,jj,jk,1) &
+                     &                        + pvar1(ji,jj,jk)
+                  ! Increment field 2 for computing daily mean
+                  prodatqc%vdmean(ji,jj,jk,2) = prodatqc%vdmean(ji,jj,jk,2) &
+                     &                        + pvar2(ji,jj,jk)
                END DO
             END DO
          END DO
-      ENDIF
-
-      DO jk = 1, jpk
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! Increment the temperature field for computing daily mean
-               prodatqc%vdmean(ji,jj,jk,1) = prodatqc%vdmean(ji,jj,jk,1) &
-                  &                        + ptn(ji,jj,jk)
-               ! Increment the salinity field for computing daily mean
-               prodatqc%vdmean(ji,jj,jk,2) = prodatqc%vdmean(ji,jj,jk,2) &
-                  &                        + psn(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-   
-      ! Compute the daily mean at the end of day
-      zdaystp = 1.0 / REAL( kdaystp )
-      IF ( idayend == 0 ) THEN
-         DO jk = 1, jpk
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  prodatqc%vdmean(ji,jj,jk,1) = prodatqc%vdmean(ji,jj,jk,1) &
-                     &                        * zdaystp
-                  prodatqc%vdmean(ji,jj,jk,2) = prodatqc%vdmean(ji,jj,jk,2) &
-                  &                           * zdaystp
+
+         ! Compute the daily mean at the end of day
+         zdaystp = 1.0 / REAL( kdaystp )
+         IF ( idayend == 0 ) THEN
+            IF (lwp) WRITE(numout,*) 'Calculating prodatqc%vdmean on time-step: ',kt
+            CALL FLUSH(numout)
+            DO jk = 1, jpk
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     prodatqc%vdmean(ji,jj,jk,1) = prodatqc%vdmean(ji,jj,jk,1) &
+                        &                        * zdaystp
+                     prodatqc%vdmean(ji,jj,jk,2) = prodatqc%vdmean(ji,jj,jk,2) &
+                        &                        * zdaystp
+                  END DO
                END DO
             END DO
-         END DO
+         ENDIF
+
       ENDIF
 
       ! Get the data for interpolation
       ALLOCATE( &
-         & igrdi(2,2,ipro),      &
-         & igrdj(2,2,ipro),      &
-         & zglam(2,2,ipro),      &
-         & zgphi(2,2,ipro),      &
-         & zmask(2,2,kpk,ipro),  &
-         & zintt(2,2,kpk,ipro),  &
-         & zints(2,2,kpk,ipro)   &
+         & igrdi1(2,2,ipro),      &
+         & igrdi2(2,2,ipro),      &
+         & igrdj1(2,2,ipro),      &
+         & igrdj2(2,2,ipro),      &
+         & zglam1(2,2,ipro),      &
+         & zglam2(2,2,ipro),      &
+         & zgphi1(2,2,ipro),      &
+         & zgphi2(2,2,ipro),      &
+         & zmask1(2,2,kpk,ipro),  &
+         & zmask2(2,2,kpk,ipro),  &
+         & zint1(2,2,kpk,ipro),  &
+         & zint2(2,2,kpk,ipro)   &
          & )
 
       DO jobs = prodatqc%nprofup + 1, prodatqc%nprofup + ipro
          iobs = jobs - prodatqc%nprofup
-         igrdi(1,1,iobs) = prodatqc%mi(jobs,1)-1
-         igrdj(1,1,iobs) = prodatqc%mj(jobs,1)-1
-         igrdi(1,2,iobs) = prodatqc%mi(jobs,1)-1
-         igrdj(1,2,iobs) = prodatqc%mj(jobs,1)
-         igrdi(2,1,iobs) = prodatqc%mi(jobs,1)
-         igrdj(2,1,iobs) = prodatqc%mj(jobs,1)-1
-         igrdi(2,2,iobs) = prodatqc%mi(jobs,1)
-         igrdj(2,2,iobs) = prodatqc%mj(jobs,1)
+         igrdi1(1,1,iobs) = prodatqc%mi(jobs,1)-1
+         igrdj1(1,1,iobs) = prodatqc%mj(jobs,1)-1
+         igrdi1(1,2,iobs) = prodatqc%mi(jobs,1)-1
+         igrdj1(1,2,iobs) = prodatqc%mj(jobs,1)
+         igrdi1(2,1,iobs) = prodatqc%mi(jobs,1)
+         igrdj1(2,1,iobs) = prodatqc%mj(jobs,1)-1
+         igrdi1(2,2,iobs) = prodatqc%mi(jobs,1)
+         igrdj1(2,2,iobs) = prodatqc%mj(jobs,1)
+         igrdi2(1,1,iobs) = prodatqc%mi(jobs,2)-1
+         igrdj2(1,1,iobs) = prodatqc%mj(jobs,2)-1
+         igrdi2(1,2,iobs) = prodatqc%mi(jobs,2)-1
+         igrdj2(1,2,iobs) = prodatqc%mj(jobs,2)
+         igrdi2(2,1,iobs) = prodatqc%mi(jobs,2)
+         igrdj2(2,1,iobs) = prodatqc%mj(jobs,2)-1
+         igrdi2(2,2,iobs) = prodatqc%mi(jobs,2)
+         igrdj2(2,2,iobs) = prodatqc%mj(jobs,2)
       END DO
 
-      CALL obs_int_comm_2d( 2, 2, ipro, igrdi, igrdj, glamt, zglam )
-      CALL obs_int_comm_2d( 2, 2, ipro, igrdi, igrdj, gphit, zgphi )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi, igrdj, ptmask,zmask )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi, igrdj, ptn,   zintt )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi, igrdj, psn,   zints )
+      CALL obs_int_comm_2d( 2, 2, ipro, kpi, kpj, igrdi1, igrdj1, plam1, zglam1 )
+      CALL obs_int_comm_2d( 2, 2, ipro, kpi, kpj, igrdi1, igrdj1, pphi1, zgphi1 )
+      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi1, igrdj1, pmask1, zmask1 )
+      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi1, igrdj1, pvar1,   zint1 )
+      
+      CALL obs_int_comm_2d( 2, 2, ipro, kpi, kpj, igrdi2, igrdj2, plam2, zglam2 )
+      CALL obs_int_comm_2d( 2, 2, ipro, kpi, kpj, igrdi2, igrdj2, pphi2, zgphi2 )
+      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi2, igrdj2, pmask2, zmask2 )
+      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi2, igrdj2, pvar2,   zint2 )
 
       ! At the end of the day also get interpolated means
-      IF ( idayend == 0 ) THEN
+      IF ( ld_dailyav .AND. idayend == 0 ) THEN
 
          ALLOCATE( &
-            & zinmt(2,2,kpk,ipro),  &
-            & zinms(2,2,kpk,ipro)   &
+            & zinm1(2,2,kpk,ipro),  &
+            & zinm2(2,2,kpk,ipro)   &
             & )
 
-         CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi, igrdj, &
-            &                  prodatqc%vdmean(:,:,:,1), zinmt )
-         CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi, igrdj, &
-            &                  prodatqc%vdmean(:,:,:,2), zinms )
+         CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi1, igrdj1, &
+            &                  prodatqc%vdmean(:,:,:,1), zinm1 )
+         CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi2, igrdj2, &
+            &                  prodatqc%vdmean(:,:,:,2), zinm2 )
 
       ENDIF
@@ -283,5 +320,5 @@
 
          IF ( kt /= prodatqc%mstp(jobs) ) THEN
-            
+
             IF(lwp) THEN
                WRITE(numout,*)
@@ -298,47 +335,44 @@
             CALL ctl_stop( 'obs_pro_opt', 'Inconsistent time' )
          ENDIF
-         
+
          zlam = prodatqc%rlam(jobs)
          zphi = prodatqc%rphi(jobs)
-         
+
          ! Horizontal weights and vertical mask
 
-         IF ( ( prodatqc%npvend(jobs,1) > 0 ) .OR. &
-            & ( prodatqc%npvend(jobs,2) > 0 ) ) THEN
+         IF ( prodatqc%npvend(jobs,1) > 0 ) THEN
 
             CALL obs_int_h2d_init( kpk, kpk, k2dint, zlam, zphi,     &
-               &                   zglam(:,:,iobs), zgphi(:,:,iobs), &
-               &                   zmask(:,:,:,iobs), zweig, zobsmask )
+               &                   zglam1(:,:,iobs), zgphi1(:,:,iobs), &
+               &                   zmask1(:,:,:,iobs), zweig1, zobsmask1 )
 
          ENDIF
 
+         IF ( prodatqc%npvend(jobs,2) > 0 ) THEN
+
+            CALL obs_int_h2d_init( kpk, kpk, k2dint, zlam, zphi,     &
+               &                   zglam2(:,:,iobs), zgphi2(:,:,iobs), &
+               &                   zmask2(:,:,:,iobs), zweig2, zobsmask2 )
+ 
+         ENDIF
+
          IF ( prodatqc%npvend(jobs,1) > 0 ) THEN
 
             zobsk(:) = obfillflt
 
-	    IF ( ANY (idailyavtypes(:) == prodatqc%ntyp(jobs)) ) THEN
+            IF ( ANY (idailyavtypes(:) == prodatqc%ntyp(jobs)) ) THEN
 
                IF ( idayend == 0 )  THEN
-                  
-                  ! Daily averaged moored buoy (MRB) data
-                  
+                  ! Daily averaged data
                   CALL obs_int_h2d( kpk, kpk,      &
-                     &              zweig, zinmt(:,:,:,iobs), zobsk )
-                  
-                  
-               ELSE
-               
-                  CALL ctl_stop( ' A nonzero' //     &
-                     &           ' number of profile T BUOY data should' // &
-                     &           ' only occur at the end of a given day' )
+                     &              zweig1, zinm1(:,:,:,iobs), zobsk )
 
                ENDIF
-	       
+
             ELSE 
-               
+
                ! Point data
-
                CALL obs_int_h2d( kpk, kpk,      &
-                  &              zweig, zintt(:,:,:,iobs), zobsk )
+                  &              zweig1, zint1(:,:,:,iobs), zobsk )
 
             ENDIF
@@ -348,10 +382,10 @@
             ! polynomial at obs points
             !-------------------------------------------------------------
-            
+
             IF ( k1dint == 1 ) THEN
                CALL obs_int_z1d_spl( kpk, zobsk, zobs2k,   &
-                  &                  pgdept, zobsmask )
+                  &                  pgdept, zobsmask1 )
             ENDIF
-            
+
             !-----------------------------------------------------------------
             !  Vertical interpolation to the observation point
@@ -365,5 +399,5 @@
                & zobsk, zobs2k,                   &
                & prodatqc%var(1)%vmod(ista:iend), &
-               & pgdept, zobsmask )
+               & pgdept, zobsmask1 )
 
          ENDIF
@@ -377,23 +411,15 @@
                IF ( idayend == 0 )  THEN
 
-                  ! Daily averaged moored buoy (MRB) data
-                  
+                  ! Daily averaged data
                   CALL obs_int_h2d( kpk, kpk,      &
-                     &              zweig, zinms(:,:,:,iobs), zobsk )
-                  
-               ELSE
-
-                  CALL ctl_stop( ' A nonzero' //     &
-                     &           ' number of profile S BUOY data should' // &
-                     &           ' only occur at the end of a given day' )
+                     &              zweig2, zinm2(:,:,:,iobs), zobsk )
 
                ENDIF
 
             ELSE
-               
+
                ! Point data
-
                CALL obs_int_h2d( kpk, kpk,      &
-                  &              zweig, zints(:,:,:,iobs), zobsk )
+                  &              zweig2, zint2(:,:,:,iobs), zobsk )
 
             ENDIF
@@ -404,10 +430,10 @@
             ! polynomial at obs points
             !-------------------------------------------------------------
-            
+
             IF ( k1dint == 1 ) THEN
                CALL obs_int_z1d_spl( kpk, zobsk, zobs2k, &
-                  &                  pgdept, zobsmask )
+                  &                  pgdept, zobsmask2 )
             ENDIF
-            
+
             !----------------------------------------------------------------
             !  Vertical interpolation to the observation point
@@ -421,39 +447,632 @@
                & zobsk, zobs2k, &
                & prodatqc%var(2)%vmod(ista:iend),&
-               & pgdept, zobsmask )
+               & pgdept, zobsmask2 )
 
          ENDIF
 
       END DO
- 
+
       ! Deallocate the data for interpolation
       DEALLOCATE( &
-         & igrdi, &
-         & igrdj, &
-         & zglam, &
-         & zgphi, &
-         & zmask, &
-         & zintt, &
-         & zints  &
+         & igrdi1, &
+         & igrdi2, &
+         & igrdj1, &
+         & igrdj2, &
+         & zglam1, &
+         & zglam2, &
+         & zgphi1, &
+         & zgphi2, &
+         & zmask1, &
+         & zmask2, &
+         & zint1,  &
+         & zint2   &
          & )
+
       ! At the end of the day also get interpolated means
-      IF ( idayend == 0 ) THEN
+      IF ( ld_dailyav .AND. idayend == 0 ) THEN
          DEALLOCATE( &
-            & zinmt,  &
-            & zinms   &
+            & zinm1,  &
+            & zinm2   &
             & )
       ENDIF
 
       prodatqc%nprofup = prodatqc%nprofup + ipro 
+
+   END SUBROUTINE obs_prof_opt
+
+   SUBROUTINE obs_pro_sco_opt( prodatqc, kt, kpi, kpj, kpk, kit000, kdaystp, & 
+      &                    ptn, psn, pgdept, pgdepw, ptmask, k1dint, k2dint, & 
+      &                    kdailyavtypes ) 
+      !!----------------------------------------------------------------------- 
+      !! 
+      !!                     ***  ROUTINE obs_pro_opt  *** 
+      !! 
+      !! ** Purpose : Compute the model counterpart of profiles 
+      !!              data by interpolating from the model grid to the  
+      !!              observation point. Generalised vertical coordinate version 
+      !! 
+      !! ** Method  : Linearly interpolate to each observation point using  
+      !!              the model values at the corners of the surrounding grid box. 
+      !! 
+      !!          First, model values on the model grid are interpolated vertically to the 
+      !!          Depths of the profile observations.  Two vertical interpolation schemes are 
+      !!          available: 
+      !!          - linear       (k1dint = 0) 
+      !!          - Cubic spline (k1dint = 1)    
+      !! 
+      !! 
+      !!         Secondly the interpolated values are interpolated horizontally to the  
+      !!         obs (lon, lat) point. 
+      !!         Several horizontal interpolation schemes are available: 
+      !!        - distance-weighted (great circle) (k2dint = 0) 
+      !!        - distance-weighted (small angle)  (k2dint = 1) 
+      !!        - bilinear (geographical grid)     (k2dint = 2) 
+      !!        - bilinear (quadrilateral grid)    (k2dint = 3) 
+      !!        - polynomial (quadrilateral grid)  (k2dint = 4) 
+      !! 
+      !!    For the cubic spline the 2nd derivative of the interpolating  
+      !!    polynomial is computed before entering the vertical interpolation  
+      !!    routine. 
+      !! 
+      !!    For ENACT moored buoy data (e.g., TAO), the model equivalent is 
+      !!    a daily mean model temperature field. So, we first compute 
+      !!    the mean, then interpolate only at the end of the day. 
+      !! 
+      !!    This is the procedure to be used with generalised vertical model  
+      !!    coordinates (ie s-coordinates. It is ~4x slower than the equivalent 
+      !!    horizontal then vertical interpolation algorithm, but can deal with situations 
+      !!    where the model levels are not flat. 
+      !!    ONLY PERFORMED if ln_sco=.TRUE.  
+      !!       
+      !!    Note: the in situ temperature observations must be converted 
+      !!    to potential temperature (the model variable) prior to 
+      !!    assimilation.  
+      !!?????????????????????????????????????????????????????????????? 
+      !!    INCLUDE POTENTIAL TEMP -> IN SITU TEMP IN OBS OPERATOR??? 
+      !!?????????????????????????????????????????????????????????????? 
+      !! 
+      !! ** Action  : 
+      !! 
+      !! History : 
+      !!      ! 2014-08 (J. While) Adapted from obs_pro_opt to handel generalised 
+      !!                           vertical coordinates
+      !!----------------------------------------------------------------------- 
+   
+      !! * Modules used 
+      USE obs_profiles_def   ! Definition of storage space for profile obs. 
+       
+      IMPLICIT NONE 
+ 
+      !! * Arguments 
+      TYPE(obs_prof), INTENT(INOUT) :: prodatqc   ! Subset of profile data not failing screening 
+      INTEGER, INTENT(IN) :: kt        ! Time step 
+      INTEGER, INTENT(IN) :: kpi       ! Model grid parameters 
+      INTEGER, INTENT(IN) :: kpj 
+      INTEGER, INTENT(IN) :: kpk 
+      INTEGER, INTENT(IN) :: kit000    ! Number of the first time step  
+                                       !   (kit000-1 = restart time) 
+      INTEGER, INTENT(IN) :: k1dint    ! Vertical interpolation type (see header) 
+      INTEGER, INTENT(IN) :: k2dint    ! Horizontal interpolation type (see header) 
+      INTEGER, INTENT(IN) :: kdaystp   ! Number of time steps per day                     
+      REAL(KIND=wp), INTENT(IN), DIMENSION(kpi,kpj,kpk) :: & 
+         & ptn,    &    ! Model temperature field 
+         & psn,    &    ! Model salinity field 
+         & ptmask       ! Land-sea mask 
+      REAL(KIND=wp), INTENT(IN), DIMENSION(kpi,kpj,kpk) :: & 
+         & pgdept,  &    ! Model array of depth T levels    
+         & pgdepw       ! Model array of depth W levels 
+      INTEGER, DIMENSION(imaxavtypes), OPTIONAL :: & 
+         & kdailyavtypes   ! Types for daily averages 
       
-   END SUBROUTINE obs_pro_opt
-
-   SUBROUTINE obs_sla_opt( sladatqc, kt, kpi, kpj, kit000, &
-      &                    psshn, psshmask, k2dint )
+      !! * Local declarations 
+      INTEGER ::   ji 
+      INTEGER ::   jj 
+      INTEGER ::   jk 
+      INTEGER ::   iico, ijco 
+      INTEGER ::   jobs 
+      INTEGER ::   inrc 
+      INTEGER ::   ipro 
+      INTEGER ::   idayend 
+      INTEGER ::   ista 
+      INTEGER ::   iend 
+      INTEGER ::   iobs 
+      INTEGER ::   iin, ijn, ikn, ik   ! looping indices over interpolation nodes 
+      INTEGER, DIMENSION(imaxavtypes) :: & 
+         & idailyavtypes 
+      INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: & 
+         & igrdi, & 
+         & igrdj 
+      INTEGER :: & 
+         & inum_obs
+      INTEGER, ALLOCATABLE, DIMENSION(:) :: iv_indic    
+      REAL(KIND=wp) :: zlam 
+      REAL(KIND=wp) :: zphi 
+      REAL(KIND=wp) :: zdaystp 
+      REAL(KIND=wp), DIMENSION(kpk) :: & 
+         & zobsmask, & 
+         & zobsk,    & 
+         & zobs2k 
+      REAL(KIND=wp), DIMENSION(2,2,1) :: & 
+         & zweig, & 
+         & l_zweig 
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: & 
+         & zmask, & 
+         & zintt, & 
+         & zints, & 
+         & zinmt, & 
+         & zgdept,& 
+         & zgdepw,& 
+         & zinms 
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: & 
+         & zglam, & 
+         & zgphi    
+      REAL(KIND=wp), DIMENSION(1) :: zmsk_1       
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: interp_corner       
+ 
+      !------------------------------------------------------------------------ 
+      ! Local initialization  
+      !------------------------------------------------------------------------ 
+      ! ... Record and data counters 
+      inrc = kt - kit000 + 2 
+      ipro = prodatqc%npstp(inrc) 
+  
+      ! Daily average types 
+      IF ( PRESENT(kdailyavtypes) ) THEN 
+         idailyavtypes(:) = kdailyavtypes(:) 
+      ELSE 
+         idailyavtypes(:) = -1 
+      ENDIF 
+ 
+      ! Initialize daily mean for first time-step 
+      idayend = MOD( kt - kit000 + 1, kdaystp ) 
+ 
+      ! Added kt == 0 test to catch restart case  
+      IF ( idayend == 1 .OR. kt == 0) THEN 
+          
+         IF (lwp) WRITE(numout,*) 'Reset prodatqc%vdmean on time-step: ',kt 
+         DO jk = 1, jpk 
+            DO jj = 1, jpj 
+               DO ji = 1, jpi 
+                  prodatqc%vdmean(ji,jj,jk,1) = 0.0 
+                  prodatqc%vdmean(ji,jj,jk,2) = 0.0 
+               END DO 
+            END DO 
+         END DO 
+       
+      ENDIF 
+       
+      DO jk = 1, jpk 
+         DO jj = 1, jpj 
+            DO ji = 1, jpi 
+               ! Increment the temperature field for computing daily mean 
+               prodatqc%vdmean(ji,jj,jk,1) = prodatqc%vdmean(ji,jj,jk,1) & 
+               &                        + ptn(ji,jj,jk) 
+               ! Increment the salinity field for computing daily mean 
+               prodatqc%vdmean(ji,jj,jk,2) = prodatqc%vdmean(ji,jj,jk,2) & 
+               &                        + psn(ji,jj,jk) 
+            END DO 
+         END DO 
+      END DO 
+    
+      ! Compute the daily mean at the end of day 
+      zdaystp = 1.0 / REAL( kdaystp ) 
+      IF ( idayend == 0 ) THEN 
+         DO jk = 1, jpk 
+            DO jj = 1, jpj 
+               DO ji = 1, jpi 
+                  prodatqc%vdmean(ji,jj,jk,1) = prodatqc%vdmean(ji,jj,jk,1) & 
+                  &                        * zdaystp 
+                  prodatqc%vdmean(ji,jj,jk,2) = prodatqc%vdmean(ji,jj,jk,2) & 
+                  &                           * zdaystp 
+               END DO 
+            END DO 
+         END DO 
+      ENDIF 
+ 
+      ! Get the data for interpolation 
+      ALLOCATE( & 
+         & igrdi(2,2,ipro),      & 
+         & igrdj(2,2,ipro),      & 
+         & zglam(2,2,ipro),      & 
+         & zgphi(2,2,ipro),      & 
+         & zmask(2,2,kpk,ipro),  & 
+         & zintt(2,2,kpk,ipro),  & 
+         & zints(2,2,kpk,ipro),  & 
+         & zgdept(2,2,kpk,ipro), & 
+         & zgdepw(2,2,kpk,ipro)  & 
+         & ) 
+ 
+      DO jobs = prodatqc%nprofup + 1, prodatqc%nprofup + ipro 
+         iobs = jobs - prodatqc%nprofup 
+         igrdi(1,1,iobs) = prodatqc%mi(jobs,1)-1 
+         igrdj(1,1,iobs) = prodatqc%mj(jobs,1)-1 
+         igrdi(1,2,iobs) = prodatqc%mi(jobs,1)-1 
+         igrdj(1,2,iobs) = prodatqc%mj(jobs,1) 
+         igrdi(2,1,iobs) = prodatqc%mi(jobs,1) 
+         igrdj(2,1,iobs) = prodatqc%mj(jobs,1)-1 
+         igrdi(2,2,iobs) = prodatqc%mi(jobs,1) 
+         igrdj(2,2,iobs) = prodatqc%mj(jobs,1) 
+      END DO 
+     
+      ! Initialise depth arrays
+      zgdept = 0.0
+      zgdepw = 0.0
+ 
+      CALL obs_int_comm_2d( 2, 2, ipro, kpi, kpj, igrdi, igrdj, glamt, zglam ) 
+      CALL obs_int_comm_2d( 2, 2, ipro, kpi, kpj, igrdi, igrdj, gphit, zgphi ) 
+      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi, igrdj, ptmask,zmask ) 
+      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi, igrdj, ptn,   zintt ) 
+      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi, igrdj, psn,   zints ) 
+      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi, igrdj, pgdept(:,:,:), & 
+        &                     zgdept ) 
+      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi, igrdj, pgdepw(:,:,:), & 
+        &                     zgdepw ) 
+ 
+      ! At the end of the day also get interpolated means 
+      IF ( idayend == 0 ) THEN 
+ 
+         ALLOCATE( & 
+            & zinmt(2,2,kpk,ipro),  & 
+            & zinms(2,2,kpk,ipro)   & 
+            & ) 
+ 
+         CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi, igrdj, & 
+            &                  prodatqc%vdmean(:,:,:,1), zinmt ) 
+         CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi, igrdj, & 
+            &                  prodatqc%vdmean(:,:,:,2), zinms ) 
+ 
+      ENDIF 
+       
+      ! Return if no observations to process 
+      ! Has to be done after comm commands to ensure processors 
+      ! stay in sync 
+      IF ( ipro == 0 ) RETURN 
+ 
+      DO jobs = prodatqc%nprofup + 1, prodatqc%nprofup + ipro 
+    
+         iobs = jobs - prodatqc%nprofup 
+    
+         IF ( kt /= prodatqc%mstp(jobs) ) THEN 
+             
+            IF(lwp) THEN 
+               WRITE(numout,*) 
+               WRITE(numout,*) ' E R R O R : Observation',              & 
+                  &            ' time step is not consistent with the', & 
+                  &            ' model time step' 
+               WRITE(numout,*) ' =========' 
+               WRITE(numout,*) 
+               WRITE(numout,*) ' Record  = ', jobs,                    & 
+                  &            ' kt      = ', kt,                      & 
+                  &            ' mstp    = ', prodatqc%mstp(jobs), & 
+                  &            ' ntyp    = ', prodatqc%ntyp(jobs) 
+            ENDIF 
+            CALL ctl_stop( 'obs_pro_opt', 'Inconsistent time' ) 
+         ENDIF 
+          
+         zlam = prodatqc%rlam(jobs) 
+         zphi = prodatqc%rphi(jobs) 
+          
+         ! Horizontal weights 
+         ! Only calculated once, for both T and S. 
+         ! Masked values are calculated later.  
+ 
+         IF ( ( prodatqc%npvend(jobs,1) > 0 ) .OR. & 
+            & ( prodatqc%npvend(jobs,2) > 0 ) ) THEN 
+ 
+            CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,     & 
+               &                   zglam(:,:,iobs), zgphi(:,:,iobs), & 
+               &                   zmask(:,:,1,iobs), zweig, zmsk_1 ) 
+ 
+         ENDIF 
+         
+         ! IF zmsk_1 = 0; then ob is on land 
+         IF (zmsk_1(1) < 0.1) THEN 
+            WRITE(numout,*) 'WARNING (obs_oper) :- profile found within landmask' 
+   
+         ELSE  
+             
+            ! Temperature 
+             
+            IF ( prodatqc%npvend(jobs,1) > 0 ) THEN  
+    
+               zobsk(:) = obfillflt 
+    
+               IF ( ANY (idailyavtypes(:) == prodatqc%ntyp(jobs)) ) THEN 
+    
+                  IF ( idayend == 0 )  THEN 
+                   
+                     ! Daily averaged moored buoy (MRB) data 
+                   
+                     ! vertically interpolate all 4 corners 
+                     ista = prodatqc%npvsta(jobs,1) 
+                     iend = prodatqc%npvend(jobs,1) 
+                     inum_obs = iend - ista + 1 
+                     ALLOCATE(interp_corner(2,2,inum_obs),iv_indic(inum_obs)) 
+      
+                     DO iin=1,2 
+                        DO ijn=1,2 
+                                       
+                                       
+           
+                           IF ( k1dint == 1 ) THEN 
+                              CALL obs_int_z1d_spl( kpk, & 
+                                 &     zinmt(iin,ijn,:,iobs), & 
+                                 &     zobs2k, zgdept(iin,ijn,:,iobs), & 
+                                 &     zmask(iin,ijn,:,iobs)) 
+                           ENDIF 
+       
+                           CALL obs_level_search(kpk, & 
+                              &    zgdept(iin,ijn,:,iobs), & 
+                              &    inum_obs, prodatqc%var(1)%vdep(ista:iend), & 
+                              &    iv_indic) 
+                           CALL obs_int_z1d(kpk, iv_indic, k1dint, inum_obs, & 
+                              &    prodatqc%var(1)%vdep(ista:iend), & 
+                              &    zinmt(iin,ijn,:,iobs), & 
+                              &    zobs2k, interp_corner(iin,ijn,:), & 
+                              &    zgdept(iin,ijn,:,iobs), & 
+                              &    zmask(iin,ijn,:,iobs)) 
+       
+                        ENDDO 
+                     ENDDO 
+                   
+                   
+                  ELSE 
+                
+                     CALL ctl_stop( ' A nonzero' //     & 
+                        &           ' number of profile T BUOY data should' // & 
+                        &           ' only occur at the end of a given day' ) 
+    
+                  ENDIF 
+         
+               ELSE  
+                
+                  ! Point data 
+     
+                  ! vertically interpolate all 4 corners 
+                  ista = prodatqc%npvsta(jobs,1) 
+                  iend = prodatqc%npvend(jobs,1) 
+                  inum_obs = iend - ista + 1 
+                  ALLOCATE(interp_corner(2,2,inum_obs), iv_indic(inum_obs)) 
+                  DO iin=1,2  
+                     DO ijn=1,2 
+                                    
+                                    
+                        IF ( k1dint == 1 ) THEN 
+                           CALL obs_int_z1d_spl( kpk, & 
+                              &    zintt(iin,ijn,:,iobs),& 
+                              &    zobs2k, zgdept(iin,ijn,:,iobs), & 
+                              &    zmask(iin,ijn,:,iobs)) 
+  
+                        ENDIF 
+       
+                        CALL obs_level_search(kpk, & 
+                            &        zgdept(iin,ijn,:,iobs),& 
+                            &        inum_obs, prodatqc%var(1)%vdep(ista:iend), & 
+                            &         iv_indic) 
+                        CALL obs_int_z1d(kpk, iv_indic, k1dint, inum_obs,     & 
+                            &          prodatqc%var(1)%vdep(ista:iend),     & 
+                            &          zintt(iin,ijn,:,iobs),            & 
+                            &          zobs2k,interp_corner(iin,ijn,:), & 
+                            &          zgdept(iin,ijn,:,iobs),         & 
+                            &          zmask(iin,ijn,:,iobs) )      
+         
+                     ENDDO 
+                  ENDDO 
+             
+               ENDIF 
+       
+               !------------------------------------------------------------- 
+               ! Compute the horizontal interpolation for every profile level 
+               !------------------------------------------------------------- 
+             
+               DO ikn=1,inum_obs 
+                  iend=ista+ikn-1 
+
+                  l_zweig(:,:,1) = 0._wp 
+
+                  ! This code forces the horizontal weights to be  
+                  ! zero IF the observation is below the bottom of the  
+                  ! corners of the interpolation nodes, Or if it is in  
+                  ! the mask. This is important for observations are near  
+                  ! steep bathymetry 
+                  DO iin=1,2 
+                     DO ijn=1,2 
+     
+                        depth_loop1: DO ik=kpk,2,-1 
+                           IF(zmask(iin,ijn,ik-1,iobs ) > 0.9 )THEN   
+                            
+                              l_zweig(iin,ijn,1) = &  
+                                 & zweig(iin,ijn,1) * & 
+                                 & MAX( SIGN(1._wp,(zgdepw(iin,ijn,ik,iobs) ) & 
+                                 &  - prodatqc%var(1)%vdep(iend)),0._wp) 
+                            
+                              EXIT depth_loop1 
+                           ENDIF 
+                        ENDDO depth_loop1 
+     
+                     ENDDO 
+                  ENDDO 
+   
+                  CALL obs_int_h2d( 1, 1, l_zweig, interp_corner(:,:,ikn), & 
+                  &          prodatqc%var(1)%vmod(iend:iend) ) 
+ 
+               ENDDO 
+ 
+ 
+               DEALLOCATE(interp_corner,iv_indic) 
+          
+            ENDIF 
+       
+ 
+            ! Salinity  
+          
+            IF ( prodatqc%npvend(jobs,2) > 0 ) THEN  
+    
+               zobsk(:) = obfillflt 
+    
+               IF ( ANY (idailyavtypes(:) == prodatqc%ntyp(jobs)) ) THEN 
+    
+                  IF ( idayend == 0 )  THEN 
+                   
+                     ! Daily averaged moored buoy (MRB) data 
+                   
+                     ! vertically interpolate all 4 corners 
+                     ista = prodatqc%npvsta(iobs,2) 
+                     iend = prodatqc%npvend(iobs,2) 
+                     inum_obs = iend - ista + 1 
+                     ALLOCATE(interp_corner(2,2,inum_obs),iv_indic(inum_obs)) 
+      
+                     DO iin=1,2 
+                        DO ijn=1,2 
+                                       
+                                       
+           
+                           IF ( k1dint == 1 ) THEN 
+                              CALL obs_int_z1d_spl( kpk, & 
+                                 &     zinms(iin,ijn,:,iobs), & 
+                                 &     zobs2k, zgdept(iin,ijn,:,iobs), & 
+                                 &     zmask(iin,ijn,:,iobs)) 
+                           ENDIF 
+       
+                           CALL obs_level_search(kpk, & 
+                              &    zgdept(iin,ijn,:,iobs), & 
+                              &    inum_obs, prodatqc%var(2)%vdep(ista:iend), & 
+                              &    iv_indic) 
+                           CALL obs_int_z1d(kpk, iv_indic, k1dint, inum_obs, & 
+                              &    prodatqc%var(2)%vdep(ista:iend), & 
+                              &    zinms(iin,ijn,:,iobs), & 
+                              &    zobs2k, interp_corner(iin,ijn,:), & 
+                              &    zgdept(iin,ijn,:,iobs), & 
+                              &    zmask(iin,ijn,:,iobs)) 
+       
+                        ENDDO 
+                     ENDDO 
+                   
+                   
+                  ELSE 
+                
+                     CALL ctl_stop( ' A nonzero' //     & 
+                        &           ' number of profile T BUOY data should' // & 
+                        &           ' only occur at the end of a given day' ) 
+    
+                  ENDIF 
+         
+               ELSE  
+                
+                  ! Point data 
+     
+                  ! vertically interpolate all 4 corners 
+                  ista = prodatqc%npvsta(jobs,2) 
+                  iend = prodatqc%npvend(jobs,2) 
+                  inum_obs = iend - ista + 1 
+                  ALLOCATE(interp_corner(2,2,inum_obs), iv_indic(inum_obs)) 
+                   
+                  DO iin=1,2     
+                     DO ijn=1,2  
+                                 
+                                 
+                        IF ( k1dint == 1 ) THEN 
+                           CALL obs_int_z1d_spl( kpk, & 
+                              &    zints(iin,ijn,:,iobs),& 
+                              &    zobs2k, zgdept(iin,ijn,:,iobs), & 
+                              &    zmask(iin,ijn,:,iobs)) 
+  
+                        ENDIF 
+       
+                        CALL obs_level_search(kpk, & 
+                           &        zgdept(iin,ijn,:,iobs),& 
+                           &        inum_obs, prodatqc%var(2)%vdep(ista:iend), & 
+                           &         iv_indic) 
+                        CALL obs_int_z1d(kpk, iv_indic, k1dint, inum_obs,  & 
+                           &          prodatqc%var(2)%vdep(ista:iend),     & 
+                           &          zints(iin,ijn,:,iobs),               & 
+                           &          zobs2k,interp_corner(iin,ijn,:),     & 
+                           &          zgdept(iin,ijn,:,iobs),              & 
+                           &          zmask(iin,ijn,:,iobs) )      
+         
+                     ENDDO 
+                  ENDDO 
+             
+               ENDIF 
+       
+               !------------------------------------------------------------- 
+               ! Compute the horizontal interpolation for every profile level 
+               !------------------------------------------------------------- 
+             
+               DO ikn=1,inum_obs 
+                  iend=ista+ikn-1 
+
+                  l_zweig(:,:,1) = 0._wp
+   
+                  ! This code forces the horizontal weights to be  
+                  ! zero IF the observation is below the bottom of the  
+                  ! corners of the interpolation nodes, Or if it is in  
+                  ! the mask. This is important for observations are near  
+                  ! steep bathymetry 
+                  DO iin=1,2 
+                     DO ijn=1,2 
+     
+                        depth_loop2: DO ik=kpk,2,-1 
+                           IF(zmask(iin,ijn,ik-1,iobs ) > 0.9 )THEN   
+                            
+                              l_zweig(iin,ijn,1) = &  
+                                 &  zweig(iin,ijn,1) * & 
+                                 &  MAX( SIGN(1._wp,(zgdepw(iin,ijn,ik,iobs) ) & 
+                                 &  - prodatqc%var(2)%vdep(iend)),0._wp) 
+                            
+                              EXIT depth_loop2 
+                           ENDIF 
+                        ENDDO depth_loop2 
+     
+                     ENDDO 
+                  ENDDO 
+   
+                  CALL obs_int_h2d( 1, 1, l_zweig, interp_corner(:,:,ikn), & 
+                  &          prodatqc%var(2)%vmod(iend:iend) ) 
+ 
+               ENDDO 
+ 
+ 
+               DEALLOCATE(interp_corner,iv_indic) 
+          
+            ENDIF 
+          
+         ENDIF 
+       
+      END DO 
+     
+      ! Deallocate the data for interpolation 
+      DEALLOCATE( & 
+         & igrdi, & 
+         & igrdj, & 
+         & zglam, & 
+         & zgphi, & 
+         & zmask, & 
+         & zintt, & 
+         & zints, & 
+         & zgdept,&
+         & zgdepw &
+         & ) 
+      ! At the end of the day also get interpolated means 
+      IF ( idayend == 0 ) THEN 
+         DEALLOCATE( & 
+            & zinmt,  & 
+            & zinms   & 
+            & ) 
+      ENDIF 
+    
+      prodatqc%nprofup = prodatqc%nprofup + ipro  
+       
+   END SUBROUTINE obs_pro_sco_opt 
+ 
+   SUBROUTINE obs_surf_opt( surfdataqc, kt, kpi, kpj,         &
+      &                    kit000, kdaystp, psurf, psurfmask, &
+      &                    k2dint, ldnightav )
+
       !!-----------------------------------------------------------------------
       !!
-      !!                     ***  ROUTINE obs_sla_opt  ***
-      !!
-      !! ** Purpose : Compute the model counterpart of sea level anomaly
+      !!                     ***  ROUTINE obs_surf_opt  ***
+      !!
+      !! ** Purpose : Compute the model counterpart of surface
       !!              data by interpolating from the model grid to the 
       !!              observation point.
@@ -462,5 +1081,5 @@
       !!              the model values at the corners of the surrounding grid box.
       !!
-      !!    The now model SSH is first computed at the obs (lon, lat) point.
+      !!    The new model value is first computed at the obs (lon, lat) point.
       !!
       !!    Several horizontal interpolation schemes are available:
@@ -470,7 +1089,5 @@
       !!        - bilinear (quadrilateral grid)    (k2dint = 3)
       !!        - polynomial (quadrilateral grid)  (k2dint = 4)
-      !!  
-      !!    The sea level anomaly at the observation points is then computed 
-      !!    by removing a mean dynamic topography (defined at the obs. point).
+      !!
       !!
       !! ** Action  :
@@ -478,6 +1095,7 @@
       !! History :
       !!      ! 07-03 (A. Weaver)
+      !!      ! 15-02 (M. Martin) Combined routine for surface types
       !!-----------------------------------------------------------------------
-  
+
       !! * Modules used
       USE obs_surf_def  ! Definition of storage space for surface observations
@@ -486,15 +1104,18 @@
 
       !! * Arguments
-      TYPE(obs_surf), INTENT(INOUT) :: sladatqc     ! Subset of surface data not failing screening
-      INTEGER, INTENT(IN) :: kt      ! Time step
-      INTEGER, INTENT(IN) :: kpi     ! Model grid parameters
+      TYPE(obs_surf), INTENT(INOUT) :: &
+         & surfdataqc                  ! Subset of surface data passing QC
+      INTEGER, INTENT(IN) :: kt        ! Time step
+      INTEGER, INTENT(IN) :: kpi       ! Model grid parameters
       INTEGER, INTENT(IN) :: kpj
-      INTEGER, INTENT(IN) :: kit000   ! Number of the first time step 
-                                      !   (kit000-1 = restart time)
-      INTEGER, INTENT(IN) :: k2dint   ! Horizontal interpolation type (see header)
-      REAL(KIND=wp), INTENT(IN), DIMENSION(kpi,kpj) :: &
-         & psshn,  &    ! Model SSH field
-         & psshmask     ! Land-sea mask
-         
+      INTEGER, INTENT(IN) :: kit000    ! Number of the first time step 
+                                       !   (kit000-1 = restart time)
+      INTEGER, INTENT(IN) :: kdaystp   ! Number of time steps per day
+      INTEGER, INTENT(IN) :: k2dint    ! Horizontal interpolation type (see header)
+      REAL(wp), INTENT(IN), DIMENSION(kpi,kpj) :: &
+         & psurf,  &                   ! Model surface field
+         & psurfmask                   ! Land-sea mask
+      LOGICAL, INTENT(IN) :: ldnightav ! Logical for averaging night-time data
+
       !! * Local declarations
       INTEGER :: ji
@@ -502,67 +1123,150 @@
       INTEGER :: jobs
       INTEGER :: inrc
-      INTEGER :: isla
+      INTEGER :: isurf
       INTEGER :: iobs
-      REAL(KIND=wp) :: zlam
-      REAL(KIND=wp) :: zphi
-      REAL(KIND=wp) :: zext(1), zobsmask(1)
-      REAL(kind=wp), DIMENSION(2,2,1) :: &
-         & zweig
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
-         & zmask, &
-         & zsshl, &
-         & zglam, &
-         & zgphi
+      INTEGER :: idayend
       INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: &
          & igrdi, &
          & igrdj
+      INTEGER, DIMENSION(:,:), SAVE, ALLOCATABLE :: &
+         & icount_night,      &
+         & imask_night
+      REAL(wp) :: zlam
+      REAL(wp) :: zphi
+      REAL(wp), DIMENSION(1) :: zext, zobsmask
+      REAL(wp) :: zdaystp
+      REAL(wp), DIMENSION(2,2,1) :: &
+         & zweig
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zmask,  &
+         & zsurf,  &
+         & zsurfm, &
+         & zglam,  &
+         & zgphi
+      REAL(wp), DIMENSION(:,:), SAVE, ALLOCATABLE :: &
+         & zintmp,  &
+         & zouttmp, &
+         & zmeanday    ! to compute model sst in region of 24h daylight (pole)
 
       !------------------------------------------------------------------------
       ! Local initialization 
       !------------------------------------------------------------------------
-      ! ... Record and data counters
+      ! Record and data counters
       inrc = kt - kit000 + 2
-      isla = sladatqc%nsstp(inrc)
+      isurf = surfdataqc%nsstp(inrc)
+
+      IF ( ldnightav ) THEN
+
+      ! Initialize array for night mean
+         IF ( kt == 0 ) THEN
+            ALLOCATE ( icount_night(kpi,kpj) )
+            ALLOCATE ( imask_night(kpi,kpj) )
+            ALLOCATE ( zintmp(kpi,kpj) )
+            ALLOCATE ( zouttmp(kpi,kpj) )
+            ALLOCATE ( zmeanday(kpi,kpj) )
+            nday_qsr = -1   ! initialisation flag for nbc_dcy
+         ENDIF
+
+         ! Night-time means are calculated for night-time values over timesteps:
+         !  [1 <= kt <= kdaystp], [kdaystp+1 <= kt <= 2*kdaystp], .....
+         idayend = MOD( kt - kit000 + 1, kdaystp )
+
+         ! Initialize night-time mean for first timestep of the day
+         IF ( idayend == 1 .OR. kt == 0 ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  surfdataqc%vdmean(ji,jj) = 0.0
+                  zmeanday(ji,jj) = 0.0
+                  icount_night(ji,jj) = 0
+               END DO
+            END DO
+         ENDIF
+
+         zintmp(:,:) = 0.0
+         zouttmp(:,:) = sbc_dcy( zintmp(:,:), .TRUE. )
+         imask_night(:,:) = INT( zouttmp(:,:) )
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ! Increment the temperature field for computing night mean and counter
+               surfdataqc%vdmean(ji,jj) = surfdataqc%vdmean(ji,jj)  &
+                      &                    + psurf(ji,jj) * REAL( imask_night(ji,jj) )
+               zmeanday(ji,jj)          = zmeanday(ji,jj) + psurf(ji,jj)
+               icount_night(ji,jj)      = icount_night(ji,jj) + imask_night(ji,jj)
+            END DO
+         END DO
+
+         ! Compute the night-time mean at the end of the day
+         zdaystp = 1.0 / REAL( kdaystp )
+         IF ( idayend == 0 ) THEN
+            IF (lwp) WRITE(numout,*) 'Calculating surfdataqc%vdmean on time-step: ',kt
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ! Test if "no night" point
+                  IF ( icount_night(ji,jj) > 0 ) THEN
+                     surfdataqc%vdmean(ji,jj) = surfdataqc%vdmean(ji,jj) &
+                       &                        / REAL( icount_night(ji,jj) )
+                  ELSE
+                     !At locations where there is no night (e.g. poles),
+                     ! calculate daily mean instead of night-time mean.
+                     surfdataqc%vdmean(ji,jj) = zmeanday(ji,jj) * zdaystp
+                  ENDIF
+               END DO
+            END DO
+         ENDIF
+
+      ENDIF
 
       ! Get the data for interpolation
 
       ALLOCATE( &
-         & igrdi(2,2,isla), &
-         & igrdj(2,2,isla), &
-         & zglam(2,2,isla), &
-         & zgphi(2,2,isla), &
-         & zmask(2,2,isla), &
-         & zsshl(2,2,isla)  &
+         & igrdi(2,2,isurf), &
+         & igrdj(2,2,isurf), &
+         & zglam(2,2,isurf), &
+         & zgphi(2,2,isurf), &
+         & zmask(2,2,isurf), &
+         & zsurf(2,2,isurf)  &
          & )
-      
-      DO jobs = sladatqc%nsurfup + 1, sladatqc%nsurfup + isla
-         iobs = jobs - sladatqc%nsurfup
-         igrdi(1,1,iobs) = sladatqc%mi(jobs)-1
-         igrdj(1,1,iobs) = sladatqc%mj(jobs)-1
-         igrdi(1,2,iobs) = sladatqc%mi(jobs)-1
-         igrdj(1,2,iobs) = sladatqc%mj(jobs)
-         igrdi(2,1,iobs) = sladatqc%mi(jobs)
-         igrdj(2,1,iobs) = sladatqc%mj(jobs)-1
-         igrdi(2,2,iobs) = sladatqc%mi(jobs)
-         igrdj(2,2,iobs) = sladatqc%mj(jobs)
+
+      DO jobs = surfdataqc%nsurfup + 1, surfdataqc%nsurfup + isurf
+         iobs = jobs - surfdataqc%nsurfup
+         igrdi(1,1,iobs) = surfdataqc%mi(jobs)-1
+         igrdj(1,1,iobs) = surfdataqc%mj(jobs)-1
+         igrdi(1,2,iobs) = surfdataqc%mi(jobs)-1
+         igrdj(1,2,iobs) = surfdataqc%mj(jobs)
+         igrdi(2,1,iobs) = surfdataqc%mi(jobs)
+         igrdj(2,1,iobs) = surfdataqc%mj(jobs)-1
+         igrdi(2,2,iobs) = surfdataqc%mi(jobs)
+         igrdj(2,2,iobs) = surfdataqc%mj(jobs)
       END DO
 
-      CALL obs_int_comm_2d( 2, 2, isla, &
+      CALL obs_int_comm_2d( 2, 2, isurf, kpi, kpj, &
          &                  igrdi, igrdj, glamt, zglam )
-      CALL obs_int_comm_2d( 2, 2, isla, &
+      CALL obs_int_comm_2d( 2, 2, isurf, kpi, kpj, &
          &                  igrdi, igrdj, gphit, zgphi )
-      CALL obs_int_comm_2d( 2, 2, isla, &
-         &                  igrdi, igrdj, psshmask, zmask )
-      CALL obs_int_comm_2d( 2, 2, isla, &
-         &                  igrdi, igrdj, psshn, zsshl )
+      CALL obs_int_comm_2d( 2, 2, isurf, kpi, kpj, &
+         &                  igrdi, igrdj, psurfmask, zmask )
+      CALL obs_int_comm_2d( 2, 2, isurf, kpi, kpj, &
+         &                  igrdi, igrdj, psurf, zsurf )
+
+      ! At the end of the day get interpolated means
+      IF ( idayend == 0 .AND. ldnightav ) THEN
+
+         ALLOCATE( &
+            & zsurfm(2,2,isurf)  &
+            & )
+
+         CALL obs_int_comm_2d( 2, 2, isurf, kpi, kpj, igrdi, igrdj, &
+            &               surfdataqc%vdmean(:,:), zsurfm )
+
+      ENDIF
 
       ! Loop over observations
-
-      DO jobs = sladatqc%nsurfup + 1, sladatqc%nsurfup + isla
-
-         iobs = jobs - sladatqc%nsurfup
-
-         IF ( kt /= sladatqc%mstp(jobs) ) THEN
-            
+      DO jobs = surfdataqc%nsurfup + 1, surfdataqc%nsurfup + isurf
+
+         iobs = jobs - surfdataqc%nsurfup
+
+         IF ( kt /= surfdataqc%mstp(jobs) ) THEN
+
             IF(lwp) THEN
                WRITE(numout,*)
@@ -574,27 +1278,34 @@
                WRITE(numout,*) ' Record  = ', jobs,                &
                   &            ' kt      = ', kt,                  &
-                  &            ' mstp    = ', sladatqc%mstp(jobs), &
-                  &            ' ntyp    = ', sladatqc%ntyp(jobs)
+                  &            ' mstp    = ', surfdataqc%mstp(jobs), &
+                  &            ' ntyp    = ', surfdataqc%ntyp(jobs)
             ENDIF
-            CALL ctl_stop( 'obs_sla_opt', 'Inconsistent time' )
-            
+            CALL ctl_stop( 'obs_surf_opt', 'Inconsistent time' )
+
          ENDIF
-         
-         zlam = sladatqc%rlam(jobs)
-         zphi = sladatqc%rphi(jobs)
-
-         ! Get weights to interpolate the model SSH to the observation point
+
+         zlam = surfdataqc%rlam(jobs)
+         zphi = surfdataqc%rphi(jobs)
+
+         ! Get weights to interpolate the model value to the observation point
          CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,         &
             &                   zglam(:,:,iobs), zgphi(:,:,iobs), &
             &                   zmask(:,:,iobs), zweig, zobsmask )
-         
-
-         ! Interpolate the model SSH to the observation point
-         CALL obs_int_h2d( 1, 1,      &
-            &              zweig, zsshl(:,:,iobs),  zext )
-         
-         sladatqc%rext(jobs,1) = zext(1)
-         ! ... Remove the MDT at the observation point
-         sladatqc%rmod(jobs,1) = sladatqc%rext(jobs,1) - sladatqc%rext(jobs,2)
+
+         ! Interpolate the model field to the observation point
+         IF ( ldnightav .AND. idayend == 0 ) THEN
+            ! Night-time averaged data
+            CALL obs_int_h2d( 1, 1, zweig, zsurfm(:,:,iobs), zext )
+         ELSE
+            CALL obs_int_h2d( 1, 1, zweig, zsurf(:,:,iobs),  zext )
+         ENDIF
+
+         IF ( TRIM(surfdataqc%cvars(1)) == 'SLA' .AND. surfdataqc%nextra == 2 ) THEN
+            ! ... Remove the MDT from the SSH at the observation point to get the SLA
+            surfdataqc%rext(jobs,1) = zext(1)
+            surfdataqc%rmod(jobs,1) = surfdataqc%rext(jobs,1) - surfdataqc%rext(jobs,2)
+         ELSE
+            surfdataqc%rmod(jobs,1) = zext(1)
+         ENDIF
 
       END DO
@@ -607,836 +1318,17 @@
          & zgphi, &
          & zmask, &
-         & zsshl  &
+         & zsurf  &
          & )
 
-      sladatqc%nsurfup = sladatqc%nsurfup + isla
-
-   END SUBROUTINE obs_sla_opt
-
-   SUBROUTINE obs_sst_opt( sstdatqc, kt, kpi, kpj, kit000, kdaystp, &
-      &                    psstn, psstmask, k2dint, ld_nightav )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_sst_opt  ***
-      !!
-      !! ** Purpose : Compute the model counterpart of surface temperature
-      !!              data by interpolating from the model grid to the 
-      !!              observation point.
-      !!
-      !! ** Method  : Linearly interpolate to each observation point using 
-      !!              the model values at the corners of the surrounding grid box.
-      !!
-      !!    The now model SST is first computed at the obs (lon, lat) point.
-      !!
-      !!    Several horizontal interpolation schemes are available:
-      !!        - distance-weighted (great circle) (k2dint = 0)
-      !!        - distance-weighted (small angle)  (k2dint = 1)
-      !!        - bilinear (geographical grid)     (k2dint = 2)
-      !!        - bilinear (quadrilateral grid)    (k2dint = 3)
-      !!        - polynomial (quadrilateral grid)  (k2dint = 4)
-      !!
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!        !  07-07  (S. Ricci ) : Original
-      !!      
-      !!-----------------------------------------------------------------------
-
-      !! * Modules used
-      USE obs_surf_def  ! Definition of storage space for surface observations
-      USE sbcdcy
-
-      IMPLICIT NONE
-
-      !! * Arguments
-      TYPE(obs_surf), INTENT(INOUT) :: &
-         & sstdatqc     ! Subset of surface data not failing screening
-      INTEGER, INTENT(IN) :: kt        ! Time step
-      INTEGER, INTENT(IN) :: kpi       ! Model grid parameters
-      INTEGER, INTENT(IN) :: kpj
-      INTEGER, INTENT(IN) :: kit000    ! Number of the first time step 
-                                       !   (kit000-1 = restart time)
-      INTEGER, INTENT(IN) :: k2dint    ! Horizontal interpolation type (see header)
-      INTEGER, INTENT(IN) :: kdaystp   ! Number of time steps per day  
-      REAL(KIND=wp), INTENT(IN), DIMENSION(kpi,kpj) :: &
-         & psstn,  &    ! Model SST field
-         & psstmask     ! Land-sea mask
-
-      !! * Local declarations
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jobs
-      INTEGER :: inrc
-      INTEGER :: isst
-      INTEGER :: iobs
-      INTEGER :: idayend
-      REAL(KIND=wp) :: zlam
-      REAL(KIND=wp) :: zphi
-      REAL(KIND=wp) :: zext(1), zobsmask(1)
-      REAL(KIND=wp) :: zdaystp
-      INTEGER, DIMENSION(:,:), SAVE, ALLOCATABLE :: &
-         & icount_sstnight,      &
-         & imask_night
-      REAL(kind=wp), DIMENSION(:,:), SAVE, ALLOCATABLE :: &
-         & zintmp, &
-         & zouttmp, & 
-         & zmeanday    ! to compute model sst in region of 24h daylight (pole)
-      REAL(kind=wp), DIMENSION(2,2,1) :: &
-         & zweig
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
-         & zmask, &
-         & zsstl, &
-         & zsstm, &
-         & zglam, &
-         & zgphi
-      INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: &
-         & igrdi, &
-         & igrdj
-      LOGICAL, INTENT(IN) :: ld_nightav
-
-      !-----------------------------------------------------------------------
-      ! Local initialization 
-      !-----------------------------------------------------------------------
-      ! ... Record and data counters
-      inrc = kt - kit000 + 2
-      isst = sstdatqc%nsstp(inrc)
-
-      IF ( ld_nightav ) THEN
-
-      ! Initialize array for night mean
-
-      IF ( kt .EQ. 0 ) THEN
-         ALLOCATE ( icount_sstnight(kpi,kpj) )
-         ALLOCATE ( imask_night(kpi,kpj) )
-         ALLOCATE ( zintmp(kpi,kpj) )
-         ALLOCATE ( zouttmp(kpi,kpj) )
-         ALLOCATE ( zmeanday(kpi,kpj) )
-         nday_qsr = -1   ! initialisation flag for nbc_dcy
-      ENDIF
-
-      ! Initialize daily mean for first timestep
-      idayend = MOD( kt - kit000 + 1, kdaystp )
-
-      ! Added kt == 0 test to catch restart case 
-      IF ( idayend == 1 .OR. kt == 0) THEN
-         IF (lwp) WRITE(numout,*) 'Reset sstdatqc%vdmean on time-step: ',kt
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               sstdatqc%vdmean(ji,jj) = 0.0
-               zmeanday(ji,jj) = 0.0
-               icount_sstnight(ji,jj) = 0
-            END DO
-         END DO
-      ENDIF
-
-      zintmp(:,:) = 0.0
-      zouttmp(:,:) = sbc_dcy( zintmp(:,:), .TRUE. )
-      imask_night(:,:) = INT( zouttmp(:,:) )
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            ! Increment the temperature field for computing night mean and counter
-            sstdatqc%vdmean(ji,jj) = sstdatqc%vdmean(ji,jj)  &
-                   &                        + psstn(ji,jj)*imask_night(ji,jj)
-            zmeanday(ji,jj)        = zmeanday(ji,jj) + psstn(ji,jj)
-            icount_sstnight(ji,jj) = icount_sstnight(ji,jj) + imask_night(ji,jj)
-         END DO
-      END DO
-   
-      ! Compute the daily mean at the end of day
-
-      zdaystp = 1.0 / REAL( kdaystp )
-
-      IF ( idayend == 0 ) THEN 
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! Test if "no night" point
-               IF ( icount_sstnight(ji,jj) .NE. 0 ) THEN
-                  sstdatqc%vdmean(ji,jj) = sstdatqc%vdmean(ji,jj) &
-                    &                        / icount_sstnight(ji,jj) 
-               ELSE
-                  sstdatqc%vdmean(ji,jj) = zmeanday(ji,jj) * zdaystp
-               ENDIF
-            END DO
-         END DO
-      ENDIF
-
-      ENDIF
-
-      ! Get the data for interpolation
-      
-      ALLOCATE( &
-         & igrdi(2,2,isst), &
-         & igrdj(2,2,isst), &
-         & zglam(2,2,isst), &
-         & zgphi(2,2,isst), &
-         & zmask(2,2,isst), &
-         & zsstl(2,2,isst)  &
-         & )
-      
-      DO jobs = sstdatqc%nsurfup + 1, sstdatqc%nsurfup + isst
-         iobs = jobs - sstdatqc%nsurfup
-         igrdi(1,1,iobs) = sstdatqc%mi(jobs)-1
-         igrdj(1,1,iobs) = sstdatqc%mj(jobs)-1
-         igrdi(1,2,iobs) = sstdatqc%mi(jobs)-1
-         igrdj(1,2,iobs) = sstdatqc%mj(jobs)
-         igrdi(2,1,iobs) = sstdatqc%mi(jobs)
-         igrdj(2,1,iobs) = sstdatqc%mj(jobs)-1
-         igrdi(2,2,iobs) = sstdatqc%mi(jobs)
-         igrdj(2,2,iobs) = sstdatqc%mj(jobs)
-      END DO
-      
-      CALL obs_int_comm_2d( 2, 2, isst, &
-         &                  igrdi, igrdj, glamt, zglam )
-      CALL obs_int_comm_2d( 2, 2, isst, &
-         &                  igrdi, igrdj, gphit, zgphi )
-      CALL obs_int_comm_2d( 2, 2, isst, &
-         &                  igrdi, igrdj, psstmask, zmask )
-      CALL obs_int_comm_2d( 2, 2, isst, &
-         &                  igrdi, igrdj, psstn, zsstl )
-
-      ! At the end of the day get interpolated means
-      IF ( idayend == 0 .AND. ld_nightav ) THEN
-
-         ALLOCATE( &
-            & zsstm(2,2,isst)  &
-            & )
-
-         CALL obs_int_comm_2d( 2, 2, isst, igrdi, igrdj, &
-            &               sstdatqc%vdmean(:,:), zsstm )
-
-      ENDIF
-
-      ! Loop over observations
-
-      DO jobs = sstdatqc%nsurfup + 1, sstdatqc%nsurfup + isst
-         
-         iobs = jobs - sstdatqc%nsurfup
-         
-         IF ( kt /= sstdatqc%mstp(jobs) ) THEN
-            
-            IF(lwp) THEN
-               WRITE(numout,*)
-               WRITE(numout,*) ' E R R O R : Observation',              &
-                  &            ' time step is not consistent with the', &
-                  &            ' model time step'
-               WRITE(numout,*) ' ========='
-               WRITE(numout,*)
-               WRITE(numout,*) ' Record  = ', jobs,                &
-                  &            ' kt      = ', kt,                  &
-                  &            ' mstp    = ', sstdatqc%mstp(jobs), &
-                  &            ' ntyp    = ', sstdatqc%ntyp(jobs)
-            ENDIF
-            CALL ctl_stop( 'obs_sst_opt', 'Inconsistent time' )
-            
-         ENDIF
-         
-         zlam = sstdatqc%rlam(jobs)
-         zphi = sstdatqc%rphi(jobs)
-         
-         ! Get weights to interpolate the model SST to the observation point
-         CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,         &
-            &                   zglam(:,:,iobs), zgphi(:,:,iobs), &
-            &                   zmask(:,:,iobs), zweig, zobsmask )
-            
-         ! Interpolate the model SST to the observation point 
-
-         IF ( ld_nightav ) THEN
-
-           IF ( idayend == 0 )  THEN
-               ! Daily averaged/diurnal cycle of SST  data
-               CALL obs_int_h2d( 1, 1,      & 
-                     &              zweig, zsstm(:,:,iobs), zext )
-            ELSE 
-               CALL ctl_stop( ' ld_nightav is set to true: a nonzero' //     &
-                     &           ' number of night SST data should' // &
-                     &           ' only occur at the end of a given day' )
-            ENDIF
-
-         ELSE
-
-            CALL obs_int_h2d( 1, 1,      &
-            &              zweig, zsstl(:,:,iobs),  zext )
-
-         ENDIF
-         sstdatqc%rmod(jobs,1) = zext(1)
-         
-      END DO
-      
-      ! Deallocate the data for interpolation
-      DEALLOCATE( &
-         & igrdi, &
-         & igrdj, &
-         & zglam, &
-         & zgphi, &
-         & zmask, &
-         & zsstl  &
-         & )
-
-      ! At the end of the day also get interpolated means
-      IF ( idayend == 0 .AND. ld_nightav ) THEN
+      ! At the end of the day also deallocate night-time mean array
+      IF ( idayend == 0 .AND. ldnightav ) THEN
          DEALLOCATE( &
-            & zsstm  &
+            & zsurfm  &
             & )
       ENDIF
-      
-      sstdatqc%nsurfup = sstdatqc%nsurfup + isst
-
-   END SUBROUTINE obs_sst_opt
-
-   SUBROUTINE obs_sss_opt
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_sss_opt  ***
-      !!
-      !! ** Purpose : Compute the model counterpart of sea surface salinity
-      !!              data by interpolating from the model grid to the 
-      !!              observation point.
-      !!
-      !! ** Method  : 
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!      ! ??-?? 
-      !!-----------------------------------------------------------------------
-
-      IMPLICIT NONE
-
-   END SUBROUTINE obs_sss_opt
-
-   SUBROUTINE obs_seaice_opt( seaicedatqc, kt, kpi, kpj, kit000, &
-      &                    pseaicen, pseaicemask, k2dint )
-
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_seaice_opt  ***
-      !!
-      !! ** Purpose : Compute the model counterpart of surface temperature
-      !!              data by interpolating from the model grid to the 
-      !!              observation point.
-      !!
-      !! ** Method  : Linearly interpolate to each observation point using 
-      !!              the model values at the corners of the surrounding grid box.
-      !!
-      !!    The now model sea ice is first computed at the obs (lon, lat) point.
-      !!
-      !!    Several horizontal interpolation schemes are available:
-      !!        - distance-weighted (great circle) (k2dint = 0)
-      !!        - distance-weighted (small angle)  (k2dint = 1)
-      !!        - bilinear (geographical grid)     (k2dint = 2)
-      !!        - bilinear (quadrilateral grid)    (k2dint = 3)
-      !!        - polynomial (quadrilateral grid)  (k2dint = 4)
-      !!
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!        !  07-07  (S. Ricci ) : Original
-      !!      
-      !!-----------------------------------------------------------------------
-
-      !! * Modules used
-      USE obs_surf_def  ! Definition of storage space for surface observations
-
-      IMPLICIT NONE
-
-      !! * Arguments
-      TYPE(obs_surf), INTENT(INOUT) :: seaicedatqc     ! Subset of surface data not failing screening
-      INTEGER, INTENT(IN) :: kt       ! Time step
-      INTEGER, INTENT(IN) :: kpi      ! Model grid parameters
-      INTEGER, INTENT(IN) :: kpj
-      INTEGER, INTENT(IN) :: kit000   ! Number of the first time step 
-                                      !   (kit000-1 = restart time)
-      INTEGER, INTENT(IN) :: k2dint   ! Horizontal interpolation type (see header)
-      REAL(KIND=wp), INTENT(IN), DIMENSION(kpi,kpj) :: &
-         & pseaicen,  &    ! Model sea ice field
-         & pseaicemask     ! Land-sea mask
-         
-      !! * Local declarations
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jobs
-      INTEGER :: inrc
-      INTEGER :: iseaice
-      INTEGER :: iobs
-       
-      REAL(KIND=wp) :: zlam
-      REAL(KIND=wp) :: zphi
-      REAL(KIND=wp) :: zext(1), zobsmask(1)
-      REAL(kind=wp), DIMENSION(2,2,1) :: &
-         & zweig
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
-         & zmask, &
-         & zseaicel, &
-         & zglam, &
-         & zgphi
-      INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: &
-         & igrdi, &
-         & igrdj
-
-      !------------------------------------------------------------------------
-      ! Local initialization 
-      !------------------------------------------------------------------------
-      ! ... Record and data counters
-      inrc = kt - kit000 + 2
-      iseaice = seaicedatqc%nsstp(inrc)
-
-      ! Get the data for interpolation
-      
-      ALLOCATE( &
-         & igrdi(2,2,iseaice), &
-         & igrdj(2,2,iseaice), &
-         & zglam(2,2,iseaice), &
-         & zgphi(2,2,iseaice), &
-         & zmask(2,2,iseaice), &
-         & zseaicel(2,2,iseaice)  &
-         & )
-      
-      DO jobs = seaicedatqc%nsurfup + 1, seaicedatqc%nsurfup + iseaice
-         iobs = jobs - seaicedatqc%nsurfup
-         igrdi(1,1,iobs) = seaicedatqc%mi(jobs)-1
-         igrdj(1,1,iobs) = seaicedatqc%mj(jobs)-1
-         igrdi(1,2,iobs) = seaicedatqc%mi(jobs)-1
-         igrdj(1,2,iobs) = seaicedatqc%mj(jobs)
-         igrdi(2,1,iobs) = seaicedatqc%mi(jobs)
-         igrdj(2,1,iobs) = seaicedatqc%mj(jobs)-1
-         igrdi(2,2,iobs) = seaicedatqc%mi(jobs)
-         igrdj(2,2,iobs) = seaicedatqc%mj(jobs)
-      END DO
-      
-      CALL obs_int_comm_2d( 2, 2, iseaice, &
-         &                  igrdi, igrdj, glamt, zglam )
-      CALL obs_int_comm_2d( 2, 2, iseaice, &
-         &                  igrdi, igrdj, gphit, zgphi )
-      CALL obs_int_comm_2d( 2, 2, iseaice, &
-         &                  igrdi, igrdj, pseaicemask, zmask )
-      CALL obs_int_comm_2d( 2, 2, iseaice, &
-         &                  igrdi, igrdj, pseaicen, zseaicel )
-      
-      DO jobs = seaicedatqc%nsurfup + 1, seaicedatqc%nsurfup + iseaice
-         
-         iobs = jobs - seaicedatqc%nsurfup
-         
-         IF ( kt /= seaicedatqc%mstp(jobs) ) THEN
-            
-            IF(lwp) THEN
-               WRITE(numout,*)
-               WRITE(numout,*) ' E R R O R : Observation',              &
-                  &            ' time step is not consistent with the', &
-                  &            ' model time step'
-               WRITE(numout,*) ' ========='
-               WRITE(numout,*)
-               WRITE(numout,*) ' Record  = ', jobs,                &
-                  &            ' kt      = ', kt,                  &
-                  &            ' mstp    = ', seaicedatqc%mstp(jobs), &
-                  &            ' ntyp    = ', seaicedatqc%ntyp(jobs)
-            ENDIF
-            CALL ctl_stop( 'obs_seaice_opt', 'Inconsistent time' )
-            
-         ENDIF
-         
-         zlam = seaicedatqc%rlam(jobs)
-         zphi = seaicedatqc%rphi(jobs)
-         
-         ! Get weights to interpolate the model sea ice to the observation point
-         CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,         &
-            &                   zglam(:,:,iobs), zgphi(:,:,iobs), &
-            &                   zmask(:,:,iobs), zweig, zobsmask )
-         
-         ! ... Interpolate the model sea ice to the observation point
-         CALL obs_int_h2d( 1, 1,      &
-            &              zweig, zseaicel(:,:,iobs),  zext )
-         
-         seaicedatqc%rmod(jobs,1) = zext(1)
-         
-      END DO
-      
-      ! Deallocate the data for interpolation
-      DEALLOCATE( &
-         & igrdi,    &
-         & igrdj,    &
-         & zglam,    &
-         & zgphi,    &
-         & zmask,    &
-         & zseaicel  &
-         & )
-      
-      seaicedatqc%nsurfup = seaicedatqc%nsurfup + iseaice
-
-   END SUBROUTINE obs_seaice_opt
-
-   SUBROUTINE obs_vel_opt( prodatqc, kt, kpi, kpj, kpk, kit000, kdaystp, &
-      &                    pun, pvn, pgdept, pumask, pvmask, k1dint, k2dint, &
-      &                    ld_dailyav )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_vel_opt  ***
-      !!
-      !! ** Purpose : Compute the model counterpart of velocity profile
-      !!              data by interpolating from the model grid to the 
-      !!              observation point.
-      !!
-      !! ** Method  : Linearly interpolate zonal and meridional components of velocity 
-      !!              to each observation point using the model values at the corners of 
-      !!              the surrounding grid box. The model velocity components are on a 
-      !!              staggered C- grid.
-      !!
-      !!    For velocity data from the TAO array, the model equivalent is
-      !!    a daily mean velocity field. So, we first compute
-      !!    the mean, then interpolate only at the end of the day.
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!    ! 07-03 (K. Mogensen)      : Temperature and Salinity profiles
-      !!    ! 08-10 (Maria Valdivieso) : Velocity component (U,V) profiles
-      !!-----------------------------------------------------------------------
-    
-      !! * Modules used
-      USE obs_profiles_def ! Definition of storage space for profile obs.
-
-      IMPLICIT NONE
-
-      !! * Arguments
-      TYPE(obs_prof), INTENT(INOUT) :: &
-         & prodatqc        ! Subset of profile data not failing screening
-      INTEGER, INTENT(IN) :: kt        ! Time step
-      INTEGER, INTENT(IN) :: kpi       ! Model grid parameters
-      INTEGER, INTENT(IN) :: kpj
-      INTEGER, INTENT(IN) :: kpk 
-      INTEGER, INTENT(IN) :: kit000    ! Number of the first time step 
-                                       !   (kit000-1 = restart time)
-      INTEGER, INTENT(IN) :: k1dint    ! Vertical interpolation type (see header)
-      INTEGER, INTENT(IN) :: k2dint    ! Horizontal interpolation type (see header)
-      INTEGER, INTENT(IN) :: kdaystp   ! Number of time steps per day                    
-      REAL(KIND=wp), INTENT(IN), DIMENSION(kpi,kpj,kpk) :: &
-         & pun,    &    ! Model zonal component of velocity
-         & pvn,    &    ! Model meridional component of velocity
-         & pumask, &    ! Land-sea mask
-         & pvmask       ! Land-sea mask
-      REAL(KIND=wp), INTENT(IN), DIMENSION(kpk) :: &
-         & pgdept       ! Model array of depth levels
-      LOGICAL, INTENT(IN) :: ld_dailyav
-         
-      !! * Local declarations
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jk
-      INTEGER :: jobs
-      INTEGER :: inrc
-      INTEGER :: ipro
-      INTEGER :: idayend
-      INTEGER :: ista
-      INTEGER :: iend
-      INTEGER :: iobs
-      INTEGER, DIMENSION(imaxavtypes) :: &
-         & idailyavtypes
-      REAL(KIND=wp) :: zlam
-      REAL(KIND=wp) :: zphi
-      REAL(KIND=wp) :: zdaystp
-      REAL(KIND=wp), DIMENSION(kpk) :: &
-         & zobsmasku, &
-         & zobsmaskv, &
-         & zobsmask,  &
-         & zobsk,     &
-         & zobs2k
-      REAL(KIND=wp), DIMENSION(2,2,kpk) :: &
-         & zweigu,zweigv
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: &
-         & zumask, zvmask, &
-         & zintu, &
-         & zintv, &
-         & zinmu, &
-         & zinmv
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
-         & zglamu, zglamv, &
-         & zgphiu, zgphiv
-      INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: &
-         & igrdiu, &
-         & igrdju, &
-         & igrdiv, &
-         & igrdjv
-
-      !------------------------------------------------------------------------
-      ! Local initialization 
-      !------------------------------------------------------------------------
-      ! ... Record and data counters
-      inrc = kt - kit000 + 2
-      ipro = prodatqc%npstp(inrc)
-
-      ! Initialize daily mean for first timestep
-      idayend = MOD( kt - kit000 + 1, kdaystp )
-
-      ! Added kt == 0 test to catch restart case 
-      IF ( idayend == 1 .OR. kt == 0) THEN
-         IF (lwp) WRITE(numout,*) 'Reset prodatqc%vdmean on time-step: ',kt
-         prodatqc%vdmean(:,:,:,1) = 0.0
-         prodatqc%vdmean(:,:,:,2) = 0.0
-      ENDIF
-
-      ! Increment the zonal velocity field for computing daily mean
-      prodatqc%vdmean(:,:,:,1) = prodatqc%vdmean(:,:,:,1) + pun(:,:,:)
-      ! Increment the meridional velocity field for computing daily mean
-      prodatqc%vdmean(:,:,:,2) = prodatqc%vdmean(:,:,:,2) + pvn(:,:,:)
-   
-      ! Compute the daily mean at the end of day
-      zdaystp = 1.0 / REAL( kdaystp )
-      IF ( idayend == 0 ) THEN
-         prodatqc%vdmean(:,:,:,1) = prodatqc%vdmean(:,:,:,1) * zdaystp
-         prodatqc%vdmean(:,:,:,2) = prodatqc%vdmean(:,:,:,2) * zdaystp
-      ENDIF
-
-      ! Get the data for interpolation
-      ALLOCATE( &
-         & igrdiu(2,2,ipro),      &
-         & igrdju(2,2,ipro),      &
-         & igrdiv(2,2,ipro),      &
-         & igrdjv(2,2,ipro),      &
-         & zglamu(2,2,ipro), zglamv(2,2,ipro), &
-         & zgphiu(2,2,ipro), zgphiv(2,2,ipro), &
-         & zumask(2,2,kpk,ipro), zvmask(2,2,kpk,ipro), &
-         & zintu(2,2,kpk,ipro),  &
-         & zintv(2,2,kpk,ipro)   &
-         & )
-
-      DO jobs = prodatqc%nprofup + 1, prodatqc%nprofup + ipro
-         iobs = jobs - prodatqc%nprofup
-         igrdiu(1,1,iobs) = prodatqc%mi(jobs,1)-1
-         igrdju(1,1,iobs) = prodatqc%mj(jobs,1)-1
-         igrdiu(1,2,iobs) = prodatqc%mi(jobs,1)-1
-         igrdju(1,2,iobs) = prodatqc%mj(jobs,1)
-         igrdiu(2,1,iobs) = prodatqc%mi(jobs,1)
-         igrdju(2,1,iobs) = prodatqc%mj(jobs,1)-1
-         igrdiu(2,2,iobs) = prodatqc%mi(jobs,1)
-         igrdju(2,2,iobs) = prodatqc%mj(jobs,1)
-         igrdiv(1,1,iobs) = prodatqc%mi(jobs,2)-1
-         igrdjv(1,1,iobs) = prodatqc%mj(jobs,2)-1
-         igrdiv(1,2,iobs) = prodatqc%mi(jobs,2)-1
-         igrdjv(1,2,iobs) = prodatqc%mj(jobs,2)
-         igrdiv(2,1,iobs) = prodatqc%mi(jobs,2)
-         igrdjv(2,1,iobs) = prodatqc%mj(jobs,2)-1
-         igrdiv(2,2,iobs) = prodatqc%mi(jobs,2)
-         igrdjv(2,2,iobs) = prodatqc%mj(jobs,2)
-      END DO
-
-      CALL obs_int_comm_2d( 2, 2, ipro, igrdiu, igrdju, glamu, zglamu )
-      CALL obs_int_comm_2d( 2, 2, ipro, igrdiu, igrdju, gphiu, zgphiu )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdiu, igrdju, pumask, zumask )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdiu, igrdju, pun, zintu )
-
-      CALL obs_int_comm_2d( 2, 2, ipro, igrdiv, igrdjv, glamv, zglamv )
-      CALL obs_int_comm_2d( 2, 2, ipro, igrdiv, igrdjv, gphiv, zgphiv )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdiv, igrdjv, pvmask, zvmask )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdiv, igrdjv, pvn, zintv )
-
-      ! At the end of the day also get interpolated means
-      IF ( idayend == 0 ) THEN
-
-         ALLOCATE( &
-            & zinmu(2,2,kpk,ipro),  &
-            & zinmv(2,2,kpk,ipro)   &
-            & )
-
-         CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdiu, igrdju, &
-            &                  prodatqc%vdmean(:,:,:,1), zinmu )
-         CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdiv, igrdjv, &
-            &                  prodatqc%vdmean(:,:,:,2), zinmv )
-
-      ENDIF
-
-! loop over observations
-
-      DO jobs = prodatqc%nprofup + 1, prodatqc%nprofup + ipro
-
-         iobs = jobs - prodatqc%nprofup
-
-         IF ( kt /= prodatqc%mstp(jobs) ) THEN
-            
-            IF(lwp) THEN
-               WRITE(numout,*)
-               WRITE(numout,*) ' E R R O R : Observation',              &
-                  &            ' time step is not consistent with the', &
-                  &            ' model time step'
-               WRITE(numout,*) ' ========='
-               WRITE(numout,*)
-               WRITE(numout,*) ' Record  = ', jobs,                    &
-                  &            ' kt      = ', kt,                      &
-                  &            ' mstp    = ', prodatqc%mstp(jobs), &
-                  &            ' ntyp    = ', prodatqc%ntyp(jobs)
-            ENDIF
-            CALL ctl_stop( 'obs_pro_opt', 'Inconsistent time' )
-         ENDIF
-         
-         zlam = prodatqc%rlam(jobs)
-         zphi = prodatqc%rphi(jobs)
-
-         ! Initialize observation masks
-
-         zobsmasku(:) = 0.0
-         zobsmaskv(:) = 0.0
-         
-         ! Horizontal weights and vertical mask
-
-         IF  ( prodatqc%npvend(jobs,1) > 0 ) THEN
-
-            CALL obs_int_h2d_init( kpk, kpk, k2dint, zlam, zphi,     &
-               &                   zglamu(:,:,iobs), zgphiu(:,:,iobs), &
-               &                   zumask(:,:,:,iobs), zweigu, zobsmasku )
-
-         ENDIF
-
-         
-         IF ( prodatqc%npvend(jobs,2) > 0 ) THEN
-
-            CALL obs_int_h2d_init( kpk, kpk, k2dint, zlam, zphi,     &
-               &                   zglamv(:,:,iobs), zgphiv(:,:,iobs), &
-               &                   zvmask(:,:,:,iobs), zweigv, zobsmasku )
-
-         ENDIF
-
-         ! Ensure that the vertical mask on u and v are consistent.
-
-         zobsmask(:) = MIN( zobsmasku(:), zobsmaskv(:) )
-
-         IF ( prodatqc%npvend(jobs,1) > 0 ) THEN
-
-            zobsk(:) = obfillflt
-
-	    IF ( ld_dailyav ) THEN
-
-               IF ( idayend == 0 )  THEN
-                  
-                  ! Daily averaged data
-                  
-                  CALL obs_int_h2d( kpk, kpk,      &
-                     &              zweigu, zinmu(:,:,:,iobs), zobsk )
-                  
-                  
-               ELSE
-               
-                  CALL ctl_stop( ' A nonzero' //     &
-                     &           ' number of U profile data should' // &
-                     &           ' only occur at the end of a given day' )
-
-               ENDIF
-	       
-            ELSE 
-               
-               ! Point data
-
-               CALL obs_int_h2d( kpk, kpk,      &
-                  &              zweigu, zintu(:,:,:,iobs), zobsk )
-
-            ENDIF
-
-            !-------------------------------------------------------------
-            ! Compute vertical second-derivative of the interpolating 
-            ! polynomial at obs points
-            !-------------------------------------------------------------
-            
-            IF ( k1dint == 1 ) THEN
-               CALL obs_int_z1d_spl( kpk, zobsk, zobs2k,   &
-                  &                  pgdept, zobsmask )
-            ENDIF
-            
-            !-----------------------------------------------------------------
-            !  Vertical interpolation to the observation point
-            !-----------------------------------------------------------------
-            ista = prodatqc%npvsta(jobs,1)
-            iend = prodatqc%npvend(jobs,1)
-            CALL obs_int_z1d( kpk,                &
-               & prodatqc%var(1)%mvk(ista:iend),  &
-               & k1dint, iend - ista + 1,         &
-               & prodatqc%var(1)%vdep(ista:iend), &
-               & zobsk, zobs2k,                   &
-               & prodatqc%var(1)%vmod(ista:iend), &
-               & pgdept, zobsmask )
-
-         ENDIF
-
-         IF ( prodatqc%npvend(jobs,2) > 0 ) THEN
-
-            zobsk(:) = obfillflt
-
-            IF ( ld_dailyav ) THEN
-
-               IF ( idayend == 0 )  THEN
-
-                  ! Daily averaged data
-                  
-                  CALL obs_int_h2d( kpk, kpk,      &
-                     &              zweigv, zinmv(:,:,:,iobs), zobsk )
-                  
-               ELSE
-
-                  CALL ctl_stop( ' A nonzero' //     &
-                     &           ' number of V profile data should' // &
-                     &           ' only occur at the end of a given day' )
-
-               ENDIF
-
-            ELSE
-               
-               ! Point data
-
-               CALL obs_int_h2d( kpk, kpk,      &
-                  &              zweigv, zintv(:,:,:,iobs), zobsk )
-
-            ENDIF
-
-
-            !-------------------------------------------------------------
-            ! Compute vertical second-derivative of the interpolating 
-            ! polynomial at obs points
-            !-------------------------------------------------------------
-            
-            IF ( k1dint == 1 ) THEN
-               CALL obs_int_z1d_spl( kpk, zobsk, zobs2k, &
-                  &                  pgdept, zobsmask )
-            ENDIF
-            
-            !----------------------------------------------------------------
-            !  Vertical interpolation to the observation point
-            !----------------------------------------------------------------
-            ista = prodatqc%npvsta(jobs,2)
-            iend = prodatqc%npvend(jobs,2)
-            CALL obs_int_z1d( kpk, &
-               & prodatqc%var(2)%mvk(ista:iend),&
-               & k1dint, iend - ista + 1, &
-               & prodatqc%var(2)%vdep(ista:iend),&
-               & zobsk, zobs2k, &
-               & prodatqc%var(2)%vmod(ista:iend),&
-               & pgdept, zobsmask )
-
-         ENDIF
-
-      END DO
- 
-      ! Deallocate the data for interpolation
-      DEALLOCATE( &
-         & igrdiu, &
-         & igrdju, &
-         & igrdiv, &
-         & igrdjv, &
-         & zglamu, zglamv, &
-         & zgphiu, zgphiv, &
-         & zumask, zvmask, &
-         & zintu, &
-         & zintv  &
-         & )
-      ! At the end of the day also get interpolated means
-      IF ( idayend == 0 ) THEN
-         DEALLOCATE( &
-            & zinmu,  &
-            & zinmv   &
-            & )
-      ENDIF
-
-      prodatqc%nprofup = prodatqc%nprofup + ipro 
-      
-   END SUBROUTINE obs_vel_opt
+
+      surfdataqc%nsurfup = surfdataqc%nsurfup + isurf
+
+   END SUBROUTINE obs_surf_opt
 
 END MODULE obs_oper
-
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 6140)
@@ -7,12 +7,9 @@
 
    !!---------------------------------------------------------------------
-   !!   obs_pre_pro  : First level check and screening of T/S profiles
-   !!   obs_pre_sla  : First level check and screening of SLA observations
-   !!   obs_pre_sst  : First level check and screening of SLA observations
-   !!   obs_pre_seaice : First level check and screening of sea ice observations
-   !!   obs_pre_vel  : First level check and screening of velocity obs.
-   !!   obs_scr      : Basic screening of the observations
-   !!   obs_coo_tim  : Compute number of time steps to the observation time
-   !!   obs_sor      : Sort the observation arrays
+   !!   obs_pre_prof  : First level check and screening of profile observations
+   !!   obs_pre_surf  : First level check and screening of surface observations
+   !!   obs_scr       : Basic screening of the observations
+   !!   obs_coo_tim   : Compute number of time steps to the observation time
+   !!   obs_sor       : Sort the observation arrays
    !!---------------------------------------------------------------------
    !! * Modules used
@@ -36,10 +33,7 @@
 
    PUBLIC &
-      & obs_pre_pro, &    ! First level check and screening of profiles
-      & obs_pre_sla, &    ! First level check and screening of SLA data
-      & obs_pre_sst, &    ! First level check and screening of SLA data
-      & obs_pre_seaice, & ! First level check and screening of sea ice data
-      & obs_pre_vel, &     ! First level check and screening of velocity profiles
-      & calc_month_len     ! Calculate the number of days in the months of a year  
+      & obs_pre_prof, &    ! First level check and screening of profile obs
+      & obs_pre_surf, &    ! First level check and screening of surface obs
+      & calc_month_len     ! Calculate the number of days in the months of a year
 
    !!----------------------------------------------------------------------
@@ -49,299 +43,14 @@
    !!----------------------------------------------------------------------
 
+
 CONTAINS
 
-   SUBROUTINE obs_pre_pro( profdata, prodatqc, ld_t3d, ld_s3d, ld_nea, &
-      &                    kdailyavtypes )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE obs_pre_pro  ***
-      !!
-      !! ** Purpose : First level check and screening of T and S profiles
-      !!
-      !! ** Method  : First level check and screening of T and S profiles
-      !!
-      !! ** Action  : 
-      !!
-      !! References :
-      !!   
-      !! History :
-      !!        !  2007-01  (K. Mogensen) Merge of obs_pre_t3d and obs_pre_s3d 
-      !!        !  2007-03  (K. Mogensen) General handling of profiles
-      !!        !  2007-06  (K. Mogensen et al) Reject obs. near land.
-      !!----------------------------------------------------------------------
-      !! * Modules used
-      USE domstp              ! Domain: set the time-step
-      USE par_oce             ! Ocean parameters
-      USE dom_oce, ONLY : &   ! Geographical information
-         & glamt,   &
-         & gphit,   &
-         & gdept_1d,&
-         & tmask,   &
-         & nproc
-      !! * Arguments
-      TYPE(obs_prof), INTENT(INOUT) :: profdata     ! Full set of profile data
-      TYPE(obs_prof), INTENT(INOUT) :: prodatqc     ! Subset of profile data not failing screening
-      LOGICAL, INTENT(IN) :: ld_t3d         ! Switch for temperature
-      LOGICAL, INTENT(IN) :: ld_s3d         ! Switch for salinity
-      LOGICAL, INTENT(IN) :: ld_nea         ! Switch for rejecting observation near land
-      INTEGER, DIMENSION(imaxavtypes), OPTIONAL :: &
-         & kdailyavtypes! Types for daily averages
-      !! * Local declarations   
-      INTEGER :: iyea0         ! Initial date
-      INTEGER :: imon0         !  - (year, month, day, hour, minute)
-      INTEGER :: iday0   
-      INTEGER :: ihou0
-      INTEGER :: imin0
-      INTEGER :: icycle        ! Current assimilation cycle
-                               ! Counters for observations that
-      INTEGER :: iotdobs       !  - outside time domain
-      INTEGER :: iosdtobs      !  - outside space domain (temperature)
-      INTEGER :: iosdsobs      !  - outside space domain (salinity)
-      INTEGER :: ilantobs      !  - within a model land cell (temperature)
-      INTEGER :: ilansobs      !  - within a model land cell (salinity)
-      INTEGER :: inlatobs      !  - close to land (temperature)
-      INTEGER :: inlasobs      !  - close to land (salinity)
-      INTEGER :: igrdobs       !  - fail the grid search
-                               ! Global counters for observations that
-      INTEGER :: iotdobsmpp    !  - outside time domain
-      INTEGER :: iosdtobsmpp   !  - outside space domain (temperature)
-      INTEGER :: iosdsobsmpp   !  - outside space domain (salinity)
-      INTEGER :: ilantobsmpp   !  - within a model land cell (temperature)
-      INTEGER :: ilansobsmpp   !  - within a model land cell (salinity)
-      INTEGER :: inlatobsmpp   !  - close to land (temperature)
-      INTEGER :: inlasobsmpp   !  - close to land (salinity)
-      INTEGER :: igrdobsmpp    !  - fail the grid search
-      TYPE(obs_prof_valid) ::  llvalid     ! Profile selection 
-      TYPE(obs_prof_valid), DIMENSION(profdata%nvar) :: &
-         & llvvalid            ! T,S selection 
-      INTEGER :: jvar          ! Variable loop variable
-      INTEGER :: jobs          ! Obs. loop variable
-      INTEGER :: jstp          ! Time loop variable
-      INTEGER :: inrc          ! Time index variable
-      
-      IF(lwp) WRITE(numout,*)'obs_pre_pro : Preparing the profile observations...'
-
-      ! Initial date initialization (year, month, day, hour, minute)
-      iyea0 =   ndate0 / 10000
-      imon0 = ( ndate0 - iyea0 * 10000 ) / 100
-      iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
-
-      icycle = no     ! Assimilation cycle
-
-      ! Diagnotics counters for various failures.
-
-      iotdobs  = 0
-      igrdobs  = 0
-      iosdtobs = 0
-      iosdsobs = 0
-      ilantobs = 0
-      ilansobs = 0
-      inlatobs = 0
-      inlasobs = 0
-
-      ! -----------------------------------------------------------------------
-      ! Find time coordinate for profiles
-      ! -----------------------------------------------------------------------
-
-      IF ( PRESENT(kdailyavtypes) ) THEN
-         CALL obs_coo_tim_prof( icycle, &
-            &                iyea0,   imon0,   iday0,   ihou0,   imin0,      &
-            &                profdata%nprof,   profdata%nyea, profdata%nmon, &
-            &                profdata%nday,    profdata%nhou, profdata%nmin, &
-            &                profdata%ntyp,    profdata%nqc,  profdata%mstp, &
-            &                iotdobs, kdailyavtypes = kdailyavtypes        )
-      ELSE
-         CALL obs_coo_tim_prof( icycle, &
-            &                iyea0,   imon0,   iday0,   ihou0,   imin0,      &
-            &                profdata%nprof,   profdata%nyea, profdata%nmon, &
-            &                profdata%nday,    profdata%nhou, profdata%nmin, &
-            &                profdata%ntyp,    profdata%nqc,  profdata%mstp, &
-            &                iotdobs )
-      ENDIF
-      CALL obs_mpp_sum_integer( iotdobs, iotdobsmpp )
-      
-      ! -----------------------------------------------------------------------
-      ! Check for profiles failing the grid search
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_grd( profdata%nprof,   profdata%mi, profdata%mj, &
-         &              profdata%nqc,     igrdobs                         )
-
-      CALL obs_mpp_sum_integer( igrdobs, igrdobsmpp )
-
-      ! -----------------------------------------------------------------------
-      ! Reject all observations for profiles with nqc > 10
-      ! -----------------------------------------------------------------------
-
-      CALL obs_pro_rej( profdata )
-
-      ! -----------------------------------------------------------------------
-      ! Check for land points. This includes points below the model
-      ! bathymetry so this is done for every point in the profile
-      ! -----------------------------------------------------------------------
-
-      ! Temperature
-
-      CALL obs_coo_spc_3d( profdata%nprof,        profdata%nvprot(1),   &
-         &                 profdata%npvsta(:,1),  profdata%npvend(:,1), &
-         &                 jpi,                   jpj,                  &
-         &                 jpk,                                         &
-         &                 profdata%mi,           profdata%mj,          & 
-         &                 profdata%var(1)%mvk,                         &
-         &                 profdata%rlam,         profdata%rphi,        &
-         &                 profdata%var(1)%vdep,                        &
-         &                 glamt,                 gphit,                &
-         &                 gdept_1d,              tmask,                &
-         &                 profdata%nqc,          profdata%var(1)%nvqc, &
-         &                 iosdtobs,              ilantobs,             &
-         &                 inlatobs,              ld_nea                )
-
-      CALL obs_mpp_sum_integer( iosdtobs, iosdtobsmpp )
-      CALL obs_mpp_sum_integer( ilantobs, ilantobsmpp )
-      CALL obs_mpp_sum_integer( inlatobs, inlatobsmpp )
-
-      ! Salinity
-
-      CALL obs_coo_spc_3d( profdata%nprof,        profdata%nvprot(2),   &
-         &                 profdata%npvsta(:,2),  profdata%npvend(:,2), &
-         &                 jpi,                   jpj,                  &
-         &                 jpk,                                         &
-         &                 profdata%mi,           profdata%mj,          & 
-         &                 profdata%var(2)%mvk,                         &
-         &                 profdata%rlam,         profdata%rphi,        &
-         &                 profdata%var(2)%vdep,                        &
-         &                 glamt,                 gphit,                &
-         &                 gdept_1d,              tmask,                &
-         &                 profdata%nqc,          profdata%var(2)%nvqc, &
-         &                 iosdsobs,              ilansobs,             &
-         &                 inlasobs,              ld_nea                )
-
-      CALL obs_mpp_sum_integer( iosdsobs, iosdsobsmpp )
-      CALL obs_mpp_sum_integer( ilansobs, ilansobsmpp )
-      CALL obs_mpp_sum_integer( inlasobs, inlasobsmpp )
-
-      ! -----------------------------------------------------------------------
-      ! Copy useful data from the profdata data structure to
-      ! the prodatqc data structure 
-      ! -----------------------------------------------------------------------
-
-      ! Allocate the selection arrays
-
-      ALLOCATE( llvalid%luse(profdata%nprof) )
-      DO jvar = 1,profdata%nvar
-         ALLOCATE( llvvalid(jvar)%luse(profdata%nvprot(jvar)) )
-      END DO
-
-      ! We want all data which has qc flags <= 10
-
-      llvalid%luse(:) = ( profdata%nqc(:)  <= 10 )
-      DO jvar = 1,profdata%nvar
-         llvvalid(jvar)%luse(:) = ( profdata%var(jvar)%nvqc(:) <= 10 )
-      END DO
-
-      ! The actual copying
-
-      CALL obs_prof_compress( profdata,     prodatqc,       .TRUE.,  numout, &
-         &                    lvalid=llvalid, lvvalid=llvvalid )
-
-      ! Dellocate the selection arrays
-      DEALLOCATE( llvalid%luse )
-      DO jvar = 1,profdata%nvar
-         DEALLOCATE( llvvalid(jvar)%luse )
-      END DO
-
-      ! -----------------------------------------------------------------------
-      ! Print information about what observations are left after qc
-      ! -----------------------------------------------------------------------
-
-      ! Update the total observation counter array
-      
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'obs_pre_pro :'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*)
-         WRITE(numout,*) ' Profiles outside time domain                = ', &
-            &            iotdobsmpp
-         WRITE(numout,*) ' Remaining profiles that failed grid search  = ', &
-            &            igrdobsmpp
-         WRITE(numout,*) ' Remaining T data outside space domain       = ', &
-            &            iosdtobsmpp
-         WRITE(numout,*) ' Remaining T data at land points             = ', &
-            &            ilantobsmpp
-         IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining T data near land points (removed) = ',&
-               &            inlatobsmpp
-         ELSE
-            WRITE(numout,*) ' Remaining T data near land points (kept)    = ',&
-               &            inlatobsmpp
-         ENDIF
-         WRITE(numout,*) ' T data accepted                             = ', &
-            &            prodatqc%nvprotmpp(1)
-         WRITE(numout,*) ' Remaining S data outside space domain       = ', &
-            &            iosdsobsmpp
-         WRITE(numout,*) ' Remaining S data at land points             = ', &
-            &            ilansobsmpp
-         IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining S data near land points (removed) = ',&
-               &            inlasobsmpp
-         ELSE
-            WRITE(numout,*) ' Remaining S data near land points (kept)    = ',&
-               &            inlasobsmpp
-         ENDIF
-         WRITE(numout,*) ' S data accepted                             = ', &
-            &            prodatqc%nvprotmpp(2)
-
-         WRITE(numout,*)
-         WRITE(numout,*) ' Number of observations per time step :'
-         WRITE(numout,*)
-         WRITE(numout,997)
-         WRITE(numout,998)
-      ENDIF
-      
-      DO jobs = 1, prodatqc%nprof
-         inrc = prodatqc%mstp(jobs) + 2 - nit000
-         prodatqc%npstp(inrc)  = prodatqc%npstp(inrc) + 1
-         DO jvar = 1, prodatqc%nvar
-            IF ( prodatqc%npvend(jobs,jvar) > 0 ) THEN
-               prodatqc%nvstp(inrc,jvar) = prodatqc%nvstp(inrc,jvar) + &
-                  &                      ( prodatqc%npvend(jobs,jvar) - &
-                  &                        prodatqc%npvsta(jobs,jvar) + 1 )
-            ENDIF
-         END DO
-      END DO
-      
-      
-      CALL obs_mpp_sum_integers( prodatqc%npstp, prodatqc%npstpmpp, &
-         &                       nitend - nit000 + 2 )
-      DO jvar = 1, prodatqc%nvar
-         CALL obs_mpp_sum_integers( prodatqc%nvstp(:,jvar), &
-            &                       prodatqc%nvstpmpp(:,jvar), &
-            &                       nitend - nit000 + 2 )
-      END DO
-
-      IF ( lwp ) THEN
-         DO jstp = nit000 - 1, nitend
-            inrc = jstp - nit000 + 2
-            WRITE(numout,999) jstp, prodatqc%npstpmpp(inrc), &
-               &                    prodatqc%nvstpmpp(inrc,1), &
-               &                    prodatqc%nvstpmpp(inrc,2)
-         END DO
-      ENDIF
-
-997   FORMAT(10X,'Time step',5X,'Profiles',5X,'Temperature',5X,'Salinity')
-998   FORMAT(10X,'---------',5X,'--------',5X,'-----------',5X,'--------')
-999   FORMAT(10X,I9,5X,I8,5X,I11,5X,I8)
-      
-   END SUBROUTINE obs_pre_pro
-
-   SUBROUTINE obs_pre_sla( sladata, sladatqc, ld_sla, ld_nea )
+   SUBROUTINE obs_pre_surf( surfdata, surfdataqc, ld_nea )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE obs_pre_sla  ***
       !!
-      !! ** Purpose : First level check and screening of SLA observations
-      !!
-      !! ** Method  : First level check and screening of SLA observations
+      !! ** Purpose : First level check and screening of surface observations
+      !!
+      !! ** Method  : First level check and screening of surface observations
       !!
       !! ** Action  : 
@@ -352,4 +61,5 @@
       !!        !  2007-03  (A. Weaver, K. Mogensen) Original
       !!        !  2007-06  (K. Mogensen et al) Reject obs. near land.
+      !!        !  2015-02  (M. Martin) Combined routine for surface types.
       !!----------------------------------------------------------------------
       !! * Modules used
@@ -362,7 +72,6 @@
          & nproc
       !! * Arguments
-      TYPE(obs_surf), INTENT(INOUT) :: sladata    ! Full set of SLA data
-      TYPE(obs_surf), INTENT(INOUT) :: sladatqc   ! Subset of SLA data not failing screening
-      LOGICAL, INTENT(IN) :: ld_sla         ! Switch for SLA data
+      TYPE(obs_surf), INTENT(INOUT) :: surfdata    ! Full set of surface data
+      TYPE(obs_surf), INTENT(INOUT) :: surfdataqc   ! Subset of surface data not failing screening
       LOGICAL, INTENT(IN) :: ld_nea         ! Switch for rejecting observation near land
       !! * Local declarations
@@ -391,12 +100,13 @@
       INTEGER :: inrc         ! Time index variable
 
-      IF(lwp) WRITE(numout,*)'obs_pre_sla : Preparing the SLA observations...'
-
+      IF(lwp) WRITE(numout,*)'obs_pre_surf : Preparing the surface observations...'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      
       ! Initial date initialization (year, month, day, hour, minute)
       iyea0 =   ndate0 / 10000
       imon0 = ( ndate0 - iyea0 * 10000 ) / 100
       iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
+      ihou0 = nn_time0 / 100
+      imin0 = ( nn_time0 - ihou0 * 100 )
 
       icycle = no     ! Assimilation cycle
@@ -411,21 +121,21 @@
 
       ! -----------------------------------------------------------------------
-      ! Find time coordinate for SLA data
+      ! Find time coordinate for surface data
       ! -----------------------------------------------------------------------
 
       CALL obs_coo_tim( icycle, &
          &              iyea0,   imon0,   iday0,   ihou0,   imin0,      &
-         &              sladata%nsurf,   sladata%nyea, sladata%nmon, &
-         &              sladata%nday,    sladata%nhou, sladata%nmin, &
-         &              sladata%nqc,     sladata%mstp, iotdobs        )
+         &              surfdata%nsurf,   surfdata%nyea, surfdata%nmon, &
+         &              surfdata%nday,    surfdata%nhou, surfdata%nmin, &
+         &              surfdata%nqc,     surfdata%mstp, iotdobs        )
 
       CALL obs_mpp_sum_integer( iotdobs, iotdobsmpp )
       
       ! -----------------------------------------------------------------------
-      ! Check for SLA data failing the grid search
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_grd( sladata%nsurf,   sladata%mi, sladata%mj, &
-         &              sladata%nqc,     igrdobs                         )
+      ! Check for surface data failing the grid search
+      ! -----------------------------------------------------------------------
+
+      CALL obs_coo_grd( surfdata%nsurf,   surfdata%mi, surfdata%mj, &
+         &              surfdata%nqc,     igrdobs                         )
 
       CALL obs_mpp_sum_integer( igrdobs, igrdobsmpp )
@@ -435,10 +145,10 @@
       ! -----------------------------------------------------------------------
 
-      CALL obs_coo_spc_2d( sladata%nsurf,              &
+      CALL obs_coo_spc_2d( surfdata%nsurf,              &
          &                 jpi,          jpj,          &
-         &                 sladata%mi,   sladata%mj,   & 
-         &                 sladata%rlam, sladata%rphi, &
+         &                 surfdata%mi,   surfdata%mj,   & 
+         &                 surfdata%rlam, surfdata%rphi, &
          &                 glamt,        gphit,        &
-         &                 tmask(:,:,1), sladata%nqc,  &
+         &                 tmask(:,:,1), surfdata%nqc,  &
          &                 iosdsobs,     ilansobs,     &
          &                 inlasobs,     ld_nea        )
@@ -449,19 +159,19 @@
 
       ! -----------------------------------------------------------------------
-      ! Copy useful data from the sladata data structure to
-      ! the sladatqc data structure 
+      ! Copy useful data from the surfdata data structure to
+      ! the surfdataqc data structure 
       ! -----------------------------------------------------------------------
 
       ! Allocate the selection arrays
 
-      ALLOCATE( llvalid(sladata%nsurf) )
+      ALLOCATE( llvalid(surfdata%nsurf) )
       
       ! We want all data which has qc flags <= 10
 
-      llvalid(:)  = ( sladata%nqc(:)  <= 10 )
+      llvalid(:)  = ( surfdata%nqc(:)  <= 10 )
 
       ! The actual copying
 
-      CALL obs_surf_compress( sladata,     sladatqc,       .TRUE.,  numout, &
+      CALL obs_surf_compress( surfdata,     surfdataqc,       .TRUE.,  numout, &
          &                    lvalid=llvalid )
 
@@ -477,38 +187,36 @@
       IF(lwp) THEN
          WRITE(numout,*)
-         WRITE(numout,*) 'obs_pre_sla :'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*)
-         WRITE(numout,*) ' SLA data outside time domain                  = ', &
+         WRITE(numout,*) ' '//surfdataqc%cvars(1)//' data outside time domain                  = ', &
             &            iotdobsmpp
-         WRITE(numout,*) ' Remaining SLA data that failed grid search    = ', &
+         WRITE(numout,*) ' Remaining '//surfdataqc%cvars(1)//' data that failed grid search    = ', &
             &            igrdobsmpp
-         WRITE(numout,*) ' Remaining SLA data outside space domain       = ', &
+         WRITE(numout,*) ' Remaining '//surfdataqc%cvars(1)//' data outside space domain       = ', &
             &            iosdsobsmpp
-         WRITE(numout,*) ' Remaining SLA data at land points             = ', &
+         WRITE(numout,*) ' Remaining '//surfdataqc%cvars(1)//' data at land points             = ', &
             &            ilansobsmpp
          IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining SLA data near land points (removed) = ', &
+            WRITE(numout,*) ' Remaining '//surfdataqc%cvars(1)//' data near land points (removed) = ', &
                &            inlasobsmpp
          ELSE
-            WRITE(numout,*) ' Remaining SLA data near land points (kept)    = ', &
+            WRITE(numout,*) ' Remaining '//surfdataqc%cvars(1)//' data near land points (kept)    = ', &
                &            inlasobsmpp
          ENDIF
-         WRITE(numout,*) ' SLA data accepted                             = ', &
-            &            sladatqc%nsurfmpp
+         WRITE(numout,*) ' '//surfdataqc%cvars(1)//' data accepted                             = ', &
+            &            surfdataqc%nsurfmpp
 
          WRITE(numout,*)
          WRITE(numout,*) ' Number of observations per time step :'
          WRITE(numout,*)
-         WRITE(numout,1997)
-         WRITE(numout,1998)
+         WRITE(numout,'(10X,A,10X,A)')'Time step',surfdataqc%cvars(1)
+         WRITE(numout,'(10X,A,5X,A)')'---------','-----------------'
+         CALL FLUSH(numout)
       ENDIF
       
-      DO jobs = 1, sladatqc%nsurf
-         inrc = sladatqc%mstp(jobs) + 2 - nit000
-         sladatqc%nsstp(inrc)  = sladatqc%nsstp(inrc) + 1
+      DO jobs = 1, surfdataqc%nsurf
+         inrc = surfdataqc%mstp(jobs) + 2 - nit000
+         surfdataqc%nsstp(inrc)  = surfdataqc%nsstp(inrc) + 1
       END DO
       
-      CALL obs_mpp_sum_integers( sladatqc%nsstp, sladatqc%nsstpmpp, &
+      CALL obs_mpp_sum_integers( surfdataqc%nsstp, surfdataqc%nsstpmpp, &
          &                       nitend - nit000 + 2 )
 
@@ -516,28 +224,32 @@
          DO jstp = nit000 - 1, nitend
             inrc = jstp - nit000 + 2
-            WRITE(numout,1999) jstp, sladatqc%nsstpmpp(inrc)
+            WRITE(numout,1999) jstp, surfdataqc%nsstpmpp(inrc)
+            CALL FLUSH(numout)
          END DO
       ENDIF
 
-1997  FORMAT(10X,'Time step',5X,'Sea level anomaly')
-1998  FORMAT(10X,'---------',5X,'-----------------')
 1999  FORMAT(10X,I9,5X,I17)
 
-   END SUBROUTINE obs_pre_sla
-
-   SUBROUTINE obs_pre_sst( sstdata, sstdatqc, ld_sst, ld_nea )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE obs_pre_sst  ***
-      !!
-      !! ** Purpose : First level check and screening of SST observations
-      !!
-      !! ** Method  : First level check and screening of SST observations
-      !!
-      !! ** Action  : 
-      !!
-      !! References :
-      !!   
+   END SUBROUTINE obs_pre_surf
+
+
+   SUBROUTINE obs_pre_prof( profdata, prodatqc, ld_var1, ld_var2, &
+      &                     kpi, kpj, kpk, &
+      &                     zmask1, pglam1, pgphi1, zmask2, pglam2, pgphi2,  &
+      &                     ld_nea, kdailyavtypes )
+
+!!----------------------------------------------------------------------
+      !!                    ***  ROUTINE obs_pre_prof  ***
+      !!
+      !! ** Purpose : First level check and screening of profiles
+      !!
+      !! ** Method  : First level check and screening of profiles
+      !!
       !! History :
-      !!        !  2007-03  (S. Ricci) SST data preparation 
+      !!        !  2007-06  (K. Mogensen) original : T and S profile data
+      !!        !  2008-09  (M. Valdivieso) : TAO velocity data
+      !!        !  2009-01  (K. Mogensen) : New feedback stricture
+      !!        !  2015-02  (M. Martin) : Combined profile routine.
+      !!
       !!----------------------------------------------------------------------
       !! * Modules used
@@ -545,384 +257,25 @@
       USE par_oce             ! Ocean parameters
       USE dom_oce, ONLY : &   ! Geographical information
-         & glamt,   &
-         & gphit,   &
-         & tmask,   &
+         & gdept_1d,             &
          & nproc
-      !! * Arguments
-      TYPE(obs_surf), INTENT(INOUT) :: sstdata     ! Full set of SST data
-      TYPE(obs_surf), INTENT(INOUT) :: sstdatqc    ! Subset of SST data not failing screening
-      LOGICAL :: ld_sst             ! Switch for SST data
-      LOGICAL :: ld_nea             ! Switch for rejecting observation near land
-      !! * Local declarations
-      INTEGER :: iyea0        ! Initial date
-      INTEGER :: imon0        !  - (year, month, day, hour, minute)
-      INTEGER :: iday0   
-      INTEGER :: ihou0    
-      INTEGER :: imin0
-      INTEGER :: icycle       ! Current assimilation cycle
-                              ! Counters for observations that
-      INTEGER :: iotdobs      !  - outside time domain
-      INTEGER :: iosdsobs     !  - outside space domain
-      INTEGER :: ilansobs     !  - within a model land cell
-      INTEGER :: inlasobs     !  - close to land
-      INTEGER :: igrdobs      !  - fail the grid search
-                              ! Global counters for observations that
-      INTEGER :: iotdobsmpp   !  - outside time domain
-      INTEGER :: iosdsobsmpp  !  - outside space domain
-      INTEGER :: ilansobsmpp  !  - within a model land cell
-      INTEGER :: inlasobsmpp  !  - close to land
-      INTEGER :: igrdobsmpp   !  - fail the grid search
-      LOGICAL, DIMENSION(:), ALLOCATABLE :: & 
-         & llvalid            ! SST data selection
-      INTEGER :: jobs         ! Obs. loop variable
-      INTEGER :: jstp         ! Time loop variable
-      INTEGER :: inrc         ! Time index variable
-
-      IF(lwp) WRITE(numout,*)'obs_pre_sst : Preparing the SST observations...'
-
-      ! Initial date initialization (year, month, day, hour, minute)
-      iyea0 =   ndate0 / 10000
-      imon0 = ( ndate0 - iyea0 * 10000 ) / 100
-      iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
-
-      icycle = no     ! Assimilation cycle
-
-      ! Diagnotics counters for various failures.
-
-      iotdobs  = 0
-      igrdobs  = 0
-      iosdsobs = 0
-      ilansobs = 0
-      inlasobs = 0
-
-      ! -----------------------------------------------------------------------
-      ! Find time coordinate for SST data
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_tim( icycle, &
-         &              iyea0,   imon0,   iday0,   ihou0,   imin0,      &
-         &              sstdata%nsurf,   sstdata%nyea, sstdata%nmon, &
-         &              sstdata%nday,    sstdata%nhou, sstdata%nmin, &
-         &              sstdata%nqc,     sstdata%mstp, iotdobs        )
-      CALL obs_mpp_sum_integer( iotdobs, iotdobsmpp )
-      ! -----------------------------------------------------------------------
-      ! Check for SST data failing the grid search
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_grd( sstdata%nsurf,   sstdata%mi, sstdata%mj, &
-         &              sstdata%nqc,     igrdobs                         )
-      CALL obs_mpp_sum_integer( igrdobs, igrdobsmpp )
-
-      ! -----------------------------------------------------------------------
-      ! Check for land points. 
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_spc_2d( sstdata%nsurf,              &
-         &                 jpi,          jpj,          &
-         &                 sstdata%mi,   sstdata%mj,   & 
-         &                 sstdata%rlam, sstdata%rphi, &
-         &                 glamt,        gphit,        &
-         &                 tmask(:,:,1), sstdata%nqc,  &
-         &                 iosdsobs,     ilansobs,     &
-         &                 inlasobs,     ld_nea        )
-
-      CALL obs_mpp_sum_integer( iosdsobs, iosdsobsmpp )
-      CALL obs_mpp_sum_integer( ilansobs, ilansobsmpp )
-      CALL obs_mpp_sum_integer( inlasobs, inlasobsmpp )
-
-      ! -----------------------------------------------------------------------
-      ! Copy useful data from the sstdata data structure to
-      ! the sstdatqc data structure 
-      ! -----------------------------------------------------------------------
-
-      ! Allocate the selection arrays
-
-      ALLOCATE( llvalid(sstdata%nsurf) )
-      
-      ! We want all data which has qc flags <= 0
-
-      llvalid(:)  = ( sstdata%nqc(:)  <= 10 )
-
-      ! The actual copying
-
-      CALL obs_surf_compress( sstdata,     sstdatqc,       .TRUE.,  numout, &
-         &                    lvalid=llvalid )
-
-      ! Dellocate the selection arrays
-      DEALLOCATE( llvalid )
-
-      ! -----------------------------------------------------------------------
-      ! Print information about what observations are left after qc
-      ! -----------------------------------------------------------------------
-
-      ! Update the total observation counter array
-      
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'obs_pre_sst :'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*)
-         WRITE(numout,*) ' SST data outside time domain                  = ', &
-            &            iotdobsmpp
-         WRITE(numout,*) ' Remaining SST data that failed grid search    = ', &
-            &            igrdobsmpp
-         WRITE(numout,*) ' Remaining SST data outside space domain       = ', &
-            &            iosdsobsmpp
-         WRITE(numout,*) ' Remaining SST data at land points             = ', &
-            &            ilansobsmpp
-         IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining SST data near land points (removed) = ', &
-               &            inlasobsmpp
-         ELSE
-            WRITE(numout,*) ' Remaining SST data near land points (kept)    = ', &
-               &            inlasobsmpp
-         ENDIF
-         WRITE(numout,*) ' SST data accepted                             = ', &
-            &            sstdatqc%nsurfmpp
-
-         WRITE(numout,*)
-         WRITE(numout,*) ' Number of observations per time step :'
-         WRITE(numout,*)
-         WRITE(numout,1997)
-         WRITE(numout,1998)
-      ENDIF
-      
-      DO jobs = 1, sstdatqc%nsurf
-         inrc = sstdatqc%mstp(jobs) + 2 - nit000
-         sstdatqc%nsstp(inrc)  = sstdatqc%nsstp(inrc) + 1
-      END DO
-      
-      CALL obs_mpp_sum_integers( sstdatqc%nsstp, sstdatqc%nsstpmpp, &
-         &                       nitend - nit000 + 2 )
-
-      IF ( lwp ) THEN
-         DO jstp = nit000 - 1, nitend
-            inrc = jstp - nit000 + 2
-            WRITE(numout,1999) jstp, sstdatqc%nsstpmpp(inrc)
-         END DO
-      ENDIF
-
-1997  FORMAT(10X,'Time step',5X,'Sea surface temperature')
-1998  FORMAT(10X,'---------',5X,'-----------------')
-1999  FORMAT(10X,I9,5X,I17)
-      
-   END SUBROUTINE obs_pre_sst
-
-   SUBROUTINE obs_pre_seaice( seaicedata, seaicedatqc, ld_seaice, ld_nea )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE obs_pre_seaice  ***
-      !!
-      !! ** Purpose : First level check and screening of Sea Ice observations
-      !!
-      !! ** Method  : First level check and screening of Sea Ice observations
-      !!
-      !! ** Action  : 
-      !!
-      !! References :
-      !!   
-      !! History :
-      !!        !  2007-11 (D. Lea) based on obs_pre_sst
-      !!----------------------------------------------------------------------
-      !! * Modules used
-      USE domstp              ! Domain: set the time-step
-      USE par_oce             ! Ocean parameters
-      USE dom_oce, ONLY : &   ! Geographical information
-         & glamt,   &
-         & gphit,   &
-         & tmask,   &
-         & nproc
-      !! * Arguments
-      TYPE(obs_surf), INTENT(INOUT) :: seaicedata     ! Full set of Sea Ice data
-      TYPE(obs_surf), INTENT(INOUT) :: seaicedatqc    ! Subset of sea ice data not failing screening
-      LOGICAL :: ld_seaice     ! Switch for sea ice data
-      LOGICAL :: ld_nea        ! Switch for rejecting observation near land
-      !! * Local declarations
-      INTEGER :: iyea0         ! Initial date
-      INTEGER :: imon0         !  - (year, month, day, hour, minute)
-      INTEGER :: iday0    
-      INTEGER :: ihou0    
-      INTEGER :: imin0
-      INTEGER :: icycle       ! Current assimilation cycle
-                              ! Counters for observations that
-      INTEGER :: iotdobs      !  - outside time domain
-      INTEGER :: iosdsobs     !  - outside space domain
-      INTEGER :: ilansobs     !  - within a model land cell
-      INTEGER :: inlasobs     !  - close to land
-      INTEGER :: igrdobs      !  - fail the grid search
-                              ! Global counters for observations that
-      INTEGER :: iotdobsmpp   !  - outside time domain
-      INTEGER :: iosdsobsmpp  !  - outside space domain
-      INTEGER :: ilansobsmpp  !  - within a model land cell
-      INTEGER :: inlasobsmpp  !  - close to land
-      INTEGER :: igrdobsmpp   !  - fail the grid search
-      LOGICAL, DIMENSION(:), ALLOCATABLE :: & 
-         & llvalid            ! data selection
-      INTEGER :: jobs         ! Obs. loop variable
-      INTEGER :: jstp         ! Time loop variable
-      INTEGER :: inrc         ! Time index variable
-
-      IF (lwp) WRITE(numout,*)'obs_pre_seaice : Preparing the sea ice observations...'
-
-      ! Initial date initialization (year, month, day, hour, minute)
-      iyea0 =   ndate0 / 10000
-      imon0 = ( ndate0 - iyea0 * 10000 ) / 100
-      iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
-
-      icycle = no     ! Assimilation cycle
-
-      ! Diagnotics counters for various failures.
-
-      iotdobs  = 0
-      igrdobs  = 0
-      iosdsobs = 0
-      ilansobs = 0
-      inlasobs = 0
-
-      ! -----------------------------------------------------------------------
-      ! Find time coordinate for sea ice data
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_tim( icycle, &
-         &              iyea0,   imon0,   iday0,   ihou0,   imin0,      &
-         &              seaicedata%nsurf,   seaicedata%nyea, seaicedata%nmon, &
-         &              seaicedata%nday,    seaicedata%nhou, seaicedata%nmin, &
-         &              seaicedata%nqc,     seaicedata%mstp, iotdobs        )
-      CALL obs_mpp_sum_integer( iotdobs, iotdobsmpp )
-      ! -----------------------------------------------------------------------
-      ! Check for sea ice data failing the grid search
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_grd( seaicedata%nsurf,   seaicedata%mi, seaicedata%mj, &
-         &              seaicedata%nqc,     igrdobs                         )
-      CALL obs_mpp_sum_integer( igrdobs, igrdobsmpp )
-
-      ! -----------------------------------------------------------------------
-      ! Check for land points. 
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_spc_2d( seaicedata%nsurf,                 &
-         &                 jpi,             jpj,             &
-         &                 seaicedata%mi,   seaicedata%mj,   & 
-         &                 seaicedata%rlam, seaicedata%rphi, &
-         &                 glamt,           gphit,           &
-         &                 tmask(:,:,1),    seaicedata%nqc,  &
-         &                 iosdsobs,        ilansobs,        &
-         &                 inlasobs,        ld_nea           )
-
-      CALL obs_mpp_sum_integer( iosdsobs, iosdsobsmpp )
-      CALL obs_mpp_sum_integer( ilansobs, ilansobsmpp )
-      CALL obs_mpp_sum_integer( inlasobs, inlasobsmpp )
-
-      ! -----------------------------------------------------------------------
-      ! Copy useful data from the seaicedata data structure to
-      ! the seaicedatqc data structure 
-      ! -----------------------------------------------------------------------
-
-      ! Allocate the selection arrays
-
-      ALLOCATE( llvalid(seaicedata%nsurf) )
-      
-      ! We want all data which has qc flags <= 0
-
-      llvalid(:)  = ( seaicedata%nqc(:)  <= 10 )
-
-      ! The actual copying
-
-      CALL obs_surf_compress( seaicedata,     seaicedatqc,       .TRUE.,  numout, &
-         &                    lvalid=llvalid )
-
-      ! Dellocate the selection arrays
-      DEALLOCATE( llvalid )
-
-      ! -----------------------------------------------------------------------
-      ! Print information about what observations are left after qc
-      ! -----------------------------------------------------------------------
-
-      ! Update the total observation counter array
-      
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'obs_pre_seaice :'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*)
-         WRITE(numout,*) ' Sea ice data outside time domain                  = ', &
-            &            iotdobsmpp
-         WRITE(numout,*) ' Remaining sea ice data that failed grid search    = ', &
-            &            igrdobsmpp
-         WRITE(numout,*) ' Remaining sea ice data outside space domain       = ', &
-            &            iosdsobsmpp
-         WRITE(numout,*) ' Remaining sea ice data at land points             = ', &
-            &            ilansobsmpp
-         IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining sea ice data near land points (removed) = ', &
-               &            inlasobsmpp
-         ELSE
-            WRITE(numout,*) ' Remaining sea ice data near land points (kept)    = ', &
-               &            inlasobsmpp
-         ENDIF
-         WRITE(numout,*) ' Sea ice data accepted                             = ', &
-            &            seaicedatqc%nsurfmpp
-
-         WRITE(numout,*)
-         WRITE(numout,*) ' Number of observations per time step :'
-         WRITE(numout,*)
-         WRITE(numout,1997)
-         WRITE(numout,1998)
-      ENDIF
-      
-      DO jobs = 1, seaicedatqc%nsurf
-         inrc = seaicedatqc%mstp(jobs) + 2 - nit000
-         seaicedatqc%nsstp(inrc)  = seaicedatqc%nsstp(inrc) + 1
-      END DO
-      
-      CALL obs_mpp_sum_integers( seaicedatqc%nsstp, seaicedatqc%nsstpmpp, &
-         &                       nitend - nit000 + 2 )
-
-      IF ( lwp ) THEN
-         DO jstp = nit000 - 1, nitend
-            inrc = jstp - nit000 + 2
-            WRITE(numout,1999) jstp, seaicedatqc%nsstpmpp(inrc)
-         END DO
-      ENDIF
-
-1997  FORMAT(10X,'Time step',5X,'Sea ice data           ')
-1998  FORMAT(10X,'---------',5X,'-----------------')
-1999  FORMAT(10X,I9,5X,I17)
-      
-   END SUBROUTINE obs_pre_seaice
-
-   SUBROUTINE obs_pre_vel( profdata, prodatqc, ld_vel3d, ld_nea, ld_dailyav )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE obs_pre_taovel  ***
-      !!
-      !! ** Purpose : First level check and screening of U and V profiles
-      !!
-      !! ** Method  : First level check and screening of U and V profiles
-      !!
-      !! History :
-      !!        !  2007-06  (K. Mogensen) original : T and S profile data
-      !!        !  2008-09  (M. Valdivieso) : TAO velocity data
-      !!        !  2009-01  (K. Mogensen) : New feedback strictuer
-      !!
-      !!----------------------------------------------------------------------
-      !! * Modules used
-      USE domstp              ! Domain: set the time-step
-      USE par_oce             ! Ocean parameters
-      USE dom_oce, ONLY : &   ! Geographical information
-         & glamt, glamu, glamv,    &
-         & gphit, gphiu, gphiv,    &
-         & gdept_1d,             &
-         & tmask, umask, vmask,  &
-         & nproc
+
       !! * Arguments
       TYPE(obs_prof), INTENT(INOUT) :: profdata   ! Full set of profile data
       TYPE(obs_prof), INTENT(INOUT) :: prodatqc   ! Subset of profile data not failing screening
-      LOGICAL, INTENT(IN) :: ld_vel3d      ! Switch for zonal and meridional velocity components
-      LOGICAL, INTENT(IN) :: ld_nea        ! Switch for rejecting observation near land
-      LOGICAL, INTENT(IN) :: ld_dailyav    ! Switch for daily average data
+      LOGICAL, INTENT(IN) :: ld_var1              ! Observed variables switches
+      LOGICAL, INTENT(IN) :: ld_var2
+      LOGICAL, INTENT(IN) :: ld_nea               ! Switch for rejecting observation near land
+      INTEGER, INTENT(IN) :: kpi, kpj, kpk        ! Local domain sizes
+      INTEGER, DIMENSION(imaxavtypes), OPTIONAL :: &
+         & kdailyavtypes                          ! Types for daily averages
+      REAL(wp), INTENT(IN), DIMENSION(kpi,kpj,kpk) :: &
+         & zmask1, &
+         & zmask2
+      REAL(wp), INTENT(IN), DIMENSION(kpi,kpj) :: &
+         & pglam1, &
+         & pglam2, &
+         & pgphi1, &
+         & pgphi2
+
       !! * Local declarations
       INTEGER :: iyea0        ! Initial date
@@ -932,29 +285,29 @@
       INTEGER :: imin0
       INTEGER :: icycle       ! Current assimilation cycle
-                              ! Counters for observations that
+                              ! Counters for observations that are
       INTEGER :: iotdobs      !  - outside time domain
-      INTEGER :: iosduobs     !  - outside space domain (zonal velocity component)
-      INTEGER :: iosdvobs     !  - outside space domain (meridional velocity component)
-      INTEGER :: ilanuobs     !  - within a model land cell (zonal velocity component)
-      INTEGER :: ilanvobs     !  - within a model land cell (meridional velocity component)
-      INTEGER :: inlauobs     !  - close to land (zonal velocity component)
-      INTEGER :: inlavobs     !  - close to land (meridional velocity component)
+      INTEGER :: iosdv1obs    !  - outside space domain (variable 1)
+      INTEGER :: iosdv2obs    !  - outside space domain (variable 2)
+      INTEGER :: ilanv1obs    !  - within a model land cell (variable 1)
+      INTEGER :: ilanv2obs    !  - within a model land cell (variable 2)
+      INTEGER :: inlav1obs    !  - close to land (variable 1)
+      INTEGER :: inlav2obs    !  - close to land (variable 2)
       INTEGER :: igrdobs      !  - fail the grid search
       INTEGER :: iuvchku      !  - reject u if v rejected and vice versa
       INTEGER :: iuvchkv      !
-                              ! Global counters for observations that
+                              ! Global counters for observations that are
       INTEGER :: iotdobsmpp   !  - outside time domain
-      INTEGER :: iosduobsmpp  !  - outside space domain (zonal velocity component)
-      INTEGER :: iosdvobsmpp  !  - outside space domain (meridional velocity component)
-      INTEGER :: ilanuobsmpp  !  - within a model land cell (zonal velocity component)
-      INTEGER :: ilanvobsmpp  !  - within a model land cell (meridional velocity component)
-      INTEGER :: inlauobsmpp  !  - close to land (zonal velocity component)
-      INTEGER :: inlavobsmpp  !  - close to land (meridional velocity component)
+      INTEGER :: iosdv1obsmpp !  - outside space domain (variable 1)
+      INTEGER :: iosdv2obsmpp !  - outside space domain (variable 2)
+      INTEGER :: ilanv1obsmpp !  - within a model land cell (variable 1)
+      INTEGER :: ilanv2obsmpp !  - within a model land cell (variable 2)
+      INTEGER :: inlav1obsmpp !  - close to land (variable 1)
+      INTEGER :: inlav2obsmpp !  - close to land (variable 2)
       INTEGER :: igrdobsmpp   !  - fail the grid search
-      INTEGER :: iuvchkumpp   !  - reject u if v rejected and vice versa
+      INTEGER :: iuvchkumpp   !  - reject var1 if var2 rejected and vice versa
       INTEGER :: iuvchkvmpp   !
       TYPE(obs_prof_valid) ::  llvalid      ! Profile selection 
       TYPE(obs_prof_valid), DIMENSION(profdata%nvar) :: &
-         & llvvalid           ! U,V selection 
+         & llvvalid           ! var1,var2 selection 
       INTEGER :: jvar         ! Variable loop variable
       INTEGER :: jobs         ! Obs. loop variable
@@ -962,5 +315,6 @@
       INTEGER :: inrc         ! Time index variable
 
-      IF(lwp) WRITE(numout,*)'obs_pre_vel: Preparing the velocity profile data'
+      IF(lwp) WRITE(numout,*)'obs_pre_prof: Preparing the profile data...'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
 
       ! Initial date initialization (year, month, day, hour, minute)
@@ -968,6 +322,6 @@
       imon0 = ( ndate0 - iyea0 * 10000 ) / 100
       iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
+      ihou0 = nn_time0 / 100
+      imin0 = ( nn_time0 - ihou0 * 100 )
 
       icycle = no     ! Assimilation cycle
@@ -977,10 +331,10 @@
       iotdobs  = 0
       igrdobs  = 0
-      iosduobs = 0
-      iosdvobs = 0
-      ilanuobs = 0
-      ilanvobs = 0
-      inlauobs = 0
-      inlavobs = 0
+      iosdv1obs = 0
+      iosdv2obs = 0
+      ilanv1obs = 0
+      ilanv2obs = 0
+      inlav1obs = 0
+      inlav2obs = 0
       iuvchku  = 0
       iuvchkv = 0
@@ -990,11 +344,20 @@
       ! -----------------------------------------------------------------------
 
-      CALL obs_coo_tim_prof( icycle, &
-         &              iyea0,   imon0,   iday0,   ihou0,   imin0,      &
-         &              profdata%nprof,   profdata%nyea, profdata%nmon, &
-         &              profdata%nday,    profdata%nhou, profdata%nmin, &
-         &              profdata%ntyp,    profdata%nqc,  profdata%mstp, &
-         &              iotdobs, ld_dailyav = ld_dailyav        )
-	 
+      IF ( PRESENT(kdailyavtypes) ) THEN
+         CALL obs_coo_tim_prof( icycle, &
+            &              iyea0,   imon0,   iday0,   ihou0,   imin0,      &
+            &              profdata%nprof,   profdata%nyea, profdata%nmon, &
+            &              profdata%nday,    profdata%nhou, profdata%nmin, &
+            &              profdata%ntyp,    profdata%nqc,  profdata%mstp, &
+            &              iotdobs, kdailyavtypes = kdailyavtypes )
+      ELSE
+         CALL obs_coo_tim_prof( icycle, &
+            &              iyea0,   imon0,   iday0,   ihou0,   imin0,      &
+            &              profdata%nprof,   profdata%nyea, profdata%nmon, &
+            &              profdata%nday,    profdata%nhou, profdata%nmin, &
+            &              profdata%ntyp,    profdata%nqc,  profdata%mstp, &
+            &              iotdobs )
+      ENDIF
+
       CALL obs_mpp_sum_integer( iotdobs, iotdobsmpp )
       
@@ -1021,26 +384,24 @@
       ! -----------------------------------------------------------------------
 
-      ! Zonal Velocity Component
-
+      ! Variable 1
       CALL obs_coo_spc_3d( profdata%nprof,        profdata%nvprot(1),   &
          &                 profdata%npvsta(:,1),  profdata%npvend(:,1), &
          &                 jpi,                   jpj,                  &
          &                 jpk,                                         &
-         &                 profdata%mi,           profdata%mj,          & 
+         &                 profdata%mi,           profdata%mj,          &
          &                 profdata%var(1)%mvk,                         &
          &                 profdata%rlam,         profdata%rphi,        &
          &                 profdata%var(1)%vdep,                        &
-         &                 glamu,                 gphiu,                &
-         &                 gdept_1d,              umask,                &
+         &                 pglam1,                pgphi1,               &
+         &                 gdept_1d,              zmask1,               &
          &                 profdata%nqc,          profdata%var(1)%nvqc, &
-         &                 iosduobs,              ilanuobs,             &
-         &                 inlauobs,              ld_nea                )
-
-      CALL obs_mpp_sum_integer( iosduobs, iosduobsmpp )
-      CALL obs_mpp_sum_integer( ilanuobs, ilanuobsmpp )
-      CALL obs_mpp_sum_integer( inlauobs, inlauobsmpp )
-
-      ! Meridional Velocity Component
-
+         &                 iosdv1obs,              ilanv1obs,           &
+         &                 inlav1obs,              ld_nea                )
+
+      CALL obs_mpp_sum_integer( iosdv1obs, iosdv1obsmpp )
+      CALL obs_mpp_sum_integer( ilanv1obs, ilanv1obsmpp )
+      CALL obs_mpp_sum_integer( inlav1obs, inlav1obsmpp )
+
+      ! Variable 2
       CALL obs_coo_spc_3d( profdata%nprof,        profdata%nvprot(2),   &
          &                 profdata%npvsta(:,2),  profdata%npvend(:,2), &
@@ -1051,13 +412,13 @@
          &                 profdata%rlam,         profdata%rphi,        &
          &                 profdata%var(2)%vdep,                        &
-         &                 glamv,                 gphiv,                &
-         &                 gdept_1d,              vmask,                &
+         &                 pglam2,                pgphi2,               &
+         &                 gdept_1d,              zmask2,               &
          &                 profdata%nqc,          profdata%var(2)%nvqc, &
-         &                 iosdvobs,              ilanvobs,             &
-         &                 inlavobs,              ld_nea                )
-
-      CALL obs_mpp_sum_integer( iosdvobs, iosdvobsmpp )
-      CALL obs_mpp_sum_integer( ilanvobs, ilanvobsmpp )
-      CALL obs_mpp_sum_integer( inlavobs, inlavobsmpp )
+         &                 iosdv2obs,              ilanv2obs,           &
+         &                 inlav2obs,              ld_nea                )
+
+      CALL obs_mpp_sum_integer( iosdv2obs, iosdv2obsmpp )
+      CALL obs_mpp_sum_integer( ilanv2obs, ilanv2obsmpp )
+      CALL obs_mpp_sum_integer( inlav2obs, inlav2obsmpp )
 
       ! -----------------------------------------------------------------------
@@ -1065,7 +426,9 @@
       ! -----------------------------------------------------------------------
 
-      CALL obs_uv_rej( profdata, iuvchku, iuvchkv )
-      CALL obs_mpp_sum_integer( iuvchku, iuvchkumpp )
-      CALL obs_mpp_sum_integer( iuvchkv, iuvchkvmpp )
+      IF ( TRIM(profdata%cvars(1)) == 'UVEL' ) THEN
+         CALL obs_uv_rej( profdata, iuvchku, iuvchkv )
+         CALL obs_mpp_sum_integer( iuvchku, iuvchkumpp )
+         CALL obs_mpp_sum_integer( iuvchkv, iuvchkvmpp )
+      ENDIF
 
       ! -----------------------------------------------------------------------
@@ -1106,41 +469,43 @@
       
       IF(lwp) THEN
+      
          WRITE(numout,*)
-         WRITE(numout,*) 'obs_pre_vel :'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*)
-         WRITE(numout,*) ' Profiles outside time domain                = ', &
+         WRITE(numout,*) ' Profiles outside time domain                     = ', &
             &            iotdobsmpp
-         WRITE(numout,*) ' Remaining profiles that failed grid search  = ', &
+         WRITE(numout,*) ' Remaining profiles that failed grid search       = ', &
             &            igrdobsmpp
-         WRITE(numout,*) ' Remaining U data outside space domain       = ', &
-            &            iosduobsmpp
-         WRITE(numout,*) ' Remaining U data at land points             = ', &
-            &            ilanuobsmpp
+         WRITE(numout,*) ' Remaining '//prodatqc%cvars(1)//' data outside space domain       = ', &
+            &            iosdv1obsmpp
+         WRITE(numout,*) ' Remaining '//prodatqc%cvars(1)//' data at land points             = ', &
+            &            ilanv1obsmpp
          IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining U data near land points (removed) = ',&
-               &            inlauobsmpp
+            WRITE(numout,*) ' Remaining '//prodatqc%cvars(1)//' data near land points (removed) = ',&
+               &            inlav1obsmpp
          ELSE
-            WRITE(numout,*) ' Remaining U data near land points (kept)    = ',&
-               &            inlauobsmpp
-         ENDIF
-         WRITE(numout,*) ' U observation rejected since V rejected     = ', &
-            &            iuvchku     
-         WRITE(numout,*) ' U data accepted                             = ', &
+            WRITE(numout,*) ' Remaining '//prodatqc%cvars(1)//' data near land points (kept)    = ',&
+               &            inlav1obsmpp
+         ENDIF
+         IF ( TRIM(profdata%cvars(1)) == 'UVEL' ) THEN
+            WRITE(numout,*) ' U observation rejected since V rejected     = ', &
+               &            iuvchku
+         ENDIF
+         WRITE(numout,*) ' '//prodatqc%cvars(1)//' data accepted                             = ', &
             &            prodatqc%nvprotmpp(1)
-         WRITE(numout,*) ' Remaining V data outside space domain       = ', &
-            &            iosdvobsmpp
-         WRITE(numout,*) ' Remaining V data at land points             = ', &
-            &            ilanvobsmpp
+         WRITE(numout,*) ' Remaining '//prodatqc%cvars(2)//' data outside space domain       = ', &
+            &            iosdv2obsmpp
+         WRITE(numout,*) ' Remaining '//prodatqc%cvars(2)//' data at land points             = ', &
+            &            ilanv2obsmpp
          IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining V data near land points (removed) = ',&
-               &            inlavobsmpp
+            WRITE(numout,*) ' Remaining '//prodatqc%cvars(2)//' data near land points (removed) = ',&
+               &            inlav2obsmpp
          ELSE
-            WRITE(numout,*) ' Remaining V data near land points (kept)    = ',&
-               &            inlavobsmpp
-         ENDIF
-         WRITE(numout,*) ' V observation rejected since U rejected     = ', &
-            &            iuvchkv     
-         WRITE(numout,*) ' V data accepted                             = ', &
+            WRITE(numout,*) ' Remaining '//prodatqc%cvars(2)//' data near land points (kept)    = ',&
+               &            inlav2obsmpp
+         ENDIF
+         IF ( TRIM(profdata%cvars(1)) == 'UVEL' ) THEN
+            WRITE(numout,*) ' V observation rejected since U rejected     = ', &
+               &            iuvchkv
+         ENDIF
+         WRITE(numout,*) ' '//prodatqc%cvars(2)//' data accepted                             = ', &
             &            prodatqc%nvprotmpp(2)
 
@@ -1148,5 +513,7 @@
          WRITE(numout,*) ' Number of observations per time step :'
          WRITE(numout,*)
-         WRITE(numout,997)
+         WRITE(numout,'(10X,A,5X,A,5X,A,A)')'Time step','Profiles', &
+            &                               '     '//prodatqc%cvars(1)//'     ', &
+            &                               '     '//prodatqc%cvars(2)//'     '
          WRITE(numout,998)
       ENDIF
@@ -1182,9 +549,8 @@
       ENDIF
 
-997   FORMAT(10X,'Time step',5X,'Profiles',5X,'Zonal Comp.',5X,'Meridional Comp.')
 998   FORMAT(10X,'---------',5X,'--------',5X,'-----------',5X,'----------------')
 999   FORMAT(10X,I9,5X,I8,5X,I11,5X,I8)
 
-   END SUBROUTINE obs_pre_vel
+   END SUBROUTINE obs_pre_prof
 
    SUBROUTINE obs_coo_tim( kcycle, &
@@ -1388,6 +754,5 @@
       &                    kobsno,                                        &
       &                    kobsyea, kobsmon, kobsday, kobshou, kobsmin,   &
-      &                    ktyp,    kobsqc,  kobsstp, kotdobs, kdailyavtypes, &
-      &                    ld_dailyav )
+      &                    ktyp,    kobsqc,  kobsstp, kotdobs, kdailyavtypes )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE obs_coo_tim ***
@@ -1433,5 +798,4 @@
       INTEGER, DIMENSION(imaxavtypes), OPTIONAL :: &
          & kdailyavtypes    ! Types for daily averages
-      LOGICAL, OPTIONAL :: ld_dailyav    ! All types are daily averages
       !! * Local declarations
       INTEGER :: jobs
@@ -1467,24 +831,4 @@
       ENDIF
 
-      !------------------------------------------------------------------------
-      ! If ld_dailyav is set then all data assumed to be daily averaged
-      !------------------------------------------------------------------------
-      
-      IF ( PRESENT( ld_dailyav) ) THEN
-         IF (ld_dailyav) THEN
-            DO jobs = 1, kobsno
-               
-               IF ( kobsqc(jobs) <= 10 ) THEN
-                  
-                  IF ( kobsstp(jobs) == (nit000 - 1) ) THEN
-                     kobsqc(jobs) = kobsqc(jobs) + 14
-                     kotdobs      = kotdobs + 1
-                     CYCLE
-                  ENDIF
-                  
-               ENDIF
-            END DO
-         ENDIF
-      ENDIF
 
    END SUBROUTINE obs_coo_tim_prof
@@ -1614,7 +958,7 @@
       END DO
       
-      CALL obs_int_comm_2d( 2, 2, kobsno, igrdi, igrdj, pmask, zgmsk )
-      CALL obs_int_comm_2d( 2, 2, kobsno, igrdi, igrdj, plam, zglam )
-      CALL obs_int_comm_2d( 2, 2, kobsno, igrdi, igrdj, pphi, zgphi )
+      CALL obs_int_comm_2d( 2, 2, kobsno, kpi, kpj, igrdi, igrdj, pmask, zgmsk )
+      CALL obs_int_comm_2d( 2, 2, kobsno, kpi, kpj, igrdi, igrdj, plam, zglam )
+      CALL obs_int_comm_2d( 2, 2, kobsno, kpi, kpj, igrdi, igrdj, pphi, zgphi )
 
       DO jobs = 1, kobsno
@@ -1709,5 +1053,10 @@
       !! * Modules used
       USE dom_oce, ONLY : &       ! Geographical information
-         & gdepw_1d                        
+         & gdepw_1d,      &
+         & gdepw_0,       &                       
+         & gdepw_n,       &
+         & gdept_n,       &
+         & ln_zco,        &
+         & ln_zps             
 
       !! * Arguments
@@ -1747,4 +1096,6 @@
       REAL(KIND=wp), DIMENSION(2,2,kpk,kprofno) :: &
          & zgmsk              ! Grid mask
+      REAL(KIND=wp), DIMENSION(2,2,kpk,kprofno) :: &
+         & zgdepw
       REAL(KIND=wp), DIMENSION(2,2,kprofno) :: &
          & zglam, &           ! Model longitude at grid points
@@ -1754,4 +1105,5 @@
          & igrdj
       LOGICAL :: lgridobs           ! Is observation on a model grid point.
+      LOGICAL :: ll_next_to_land    ! Is a profile next to land 
       INTEGER :: iig, ijg           ! i,j of observation on model grid point.
       INTEGER :: jobs, jobsp, jk, ji, jj
@@ -1789,7 +1141,12 @@
       END DO
       
-      CALL obs_int_comm_3d( 2, 2, kprofno, kpk, igrdi, igrdj, pmask, zgmsk )
-      CALL obs_int_comm_2d( 2, 2, kprofno, igrdi, igrdj, plam, zglam )
-      CALL obs_int_comm_2d( 2, 2, kprofno, igrdi, igrdj, pphi, zgphi )
+      CALL obs_int_comm_3d( 2, 2, kprofno, kpi, kpj, kpk, igrdi, igrdj, pmask, zgmsk )
+      CALL obs_int_comm_2d( 2, 2, kprofno, kpi, kpj, igrdi, igrdj, plam, zglam )
+      CALL obs_int_comm_2d( 2, 2, kprofno, kpi, kpj, igrdi, igrdj, pphi, zgphi )
+      IF ( .NOT.( ln_zps .OR. ln_zco ) ) THEN
+        ! Need to know the bathy depth for each observation for sco
+        CALL obs_int_comm_3d( 2, 2, kprofno, kpi, kpj, kpk, igrdi, igrdj, gdepw_n(:,:,:), &
+        &                     zgdepw )
+      ENDIF
 
       DO jobs = 1, kprofno
@@ -1816,4 +1173,11 @@
          END DO
 
+         ! Check if next to land
+         IF (  ANY( zgmsk(1:2,1:2,1,jobs) == 0.0_wp ) ) THEN
+            ll_next_to_land=.TRUE.
+         ELSE
+            ll_next_to_land=.FALSE.
+         ENDIF 
+
          ! Reject observations
 
@@ -1832,12 +1196,50 @@
             ENDIF
 
-            ! Flag if the observation falls with a model land cell
-            IF ( SUM( zgmsk(1:2,1:2,kobsk(jobsp)-1:kobsk(jobsp),jobs) ) &
-               &  == 0.0_wp ) THEN
-               kobsqc(jobsp) = kobsqc(jobsp) + 12
-               klanobs = klanobs + 1
-               CYCLE
+            ! To check if an observations falls within land there are two cases:
+            ! 1: z-coordibnates, where the check uses the mask
+            ! 2: terrain following (eg s-coordinates), 
+            !    where we use the depth of the bottom cell to mask observations
+             
+            IF( ln_zps .OR. ln_zco ) THEN !(CASE 1)
+               
+               ! Flag if the observation falls with a model land cell
+               IF ( SUM( zgmsk(1:2,1:2,kobsk(jobsp)-1:kobsk(jobsp),jobs) ) &
+                  &  == 0.0_wp ) THEN
+                  kobsqc(jobsp) = kobsqc(jobsp) + 12
+                  klanobs = klanobs + 1
+                  CYCLE
+               ENDIF
+             
+               ! Flag if the observation is close to land
+              IF ( MINVAL( zgmsk(1:2,1:2,kobsk(jobsp)-1:kobsk(jobsp),jobs) ) == &
+                  &  0.0_wp) THEN
+                  knlaobs = knlaobs + 1
+                  IF (ld_nea) THEN   
+                     kobsqc(jobsp) = kobsqc(jobsp) + 14 
+                  ENDIF 
+               ENDIF
+             
+            ELSE ! Case 2
+ 
+               ! Flag if the observation is deeper than the bathymetry
+               ! Or if it is within the mask
+               IF ( ALL( zgdepw(1:2,1:2,kpk,jobs) < pobsdep(jobsp) ) &
+                  &     .OR. &
+                  &  ( SUM( zgmsk(1:2,1:2,kobsk(jobsp)-1:kobsk(jobsp),jobs) ) &
+                  &  == 0.0_wp) ) THEN
+                  kobsqc(jobsp) = kobsqc(jobsp) + 12
+                  klanobs = klanobs + 1
+                  CYCLE
+               ENDIF
+               
+               ! Flag if the observation is close to land
+               IF ( ll_next_to_land ) THEN
+                  knlaobs = knlaobs + 1
+                  IF (ld_nea) THEN   
+                     kobsqc(jobsp) = kobsqc(jobsp) + 14 
+                  ENDIF 
+               ENDIF
             ENDIF
-
+            
             ! For observations on the grid reject them if their are at
             ! a masked point
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prof_io.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prof_io.F90	(revision 6139)
+++ 	(revision )
@@ -1,32 +1,0 @@
-MODULE obs_prof_io
-   !!======================================================================
-   !!                       ***  MODULE obs_prof_io  ***
-   !! Observation operators : I/O for ENACT and Coriolis files
-   !!======================================================================
-   !! History : 
-   !!             !  09-01  (K. Mogensen) Initial version
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!   read_enactfile    :  Read a obfbdata structure from an ENACT file.
-   !!   read_coriofile    :  Read a obfbdata structure from an Coriolis file.
-   !!----------------------------------------------------------------------
-   USE par_kind
-   USE obs_utils
-   USE obs_fbm
-   USE obs_conv
-   USE netcdf
-   IMPLICIT NONE
-
-   INTEGER, PARAMETER :: imaxlev = 10000
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-#include "obsprof_io.h90"
-
-END MODULE obs_prof_io
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_profiles_def.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_profiles_def.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_profiles_def.F90	(revision 6140)
@@ -104,4 +104,7 @@
       ! Bookkeeping arrays with sizes equal to number of variables
 
+      CHARACTER(len=6), POINTER, DIMENSION(:) :: &
+         & cvars          !: Variable names
+
       INTEGER, POINTER, DIMENSION(:) :: &
          & nvprot,   &    !: Local total number of profile T data
@@ -237,4 +240,5 @@
 
       ALLOCATE( &
+         & prof%cvars(kvar),    &
          & prof%nvprot(kvar),   &
          & prof%nvprotmpp(kvar) &
@@ -242,4 +246,5 @@
          
       DO jvar = 1, kvar
+         prof%cvars    (jvar) = "NotSet"
          prof%nvprot   (jvar) = ko3dt(jvar)
          prof%nvprotmpp(jvar) = 0
@@ -452,5 +457,6 @@
 
       DEALLOCATE( &
-         & prof%nvprot,  &
+         & prof%cvars,    &
+         & prof%nvprot,   &
          & prof%nvprotmpp &
          )
@@ -770,4 +776,5 @@
       newprof%npj      = prof%npj
       newprof%npk      = prof%npk
+      newprof%cvars(:) = prof%cvars(:)
  
       ! Deallocate temporary data
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_altbias.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_altbias.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_altbias.F90	(revision 6140)
@@ -50,5 +50,5 @@
 CONTAINS
 
-   SUBROUTINE obs_rea_altbias( kslano, sladata, k2dint, bias_file )
+   SUBROUTINE obs_rea_altbias( sladata, k2dint, bias_file )
       !!---------------------------------------------------------------------
       !!
@@ -70,6 +70,5 @@
       !
       !! * Arguments
-      INTEGER, INTENT(IN) :: kslano      ! Number of SLA Products
-      TYPE(obs_surf), DIMENSION(kslano), INTENT(INOUT) :: &
+      TYPE(obs_surf), INTENT(INOUT) :: &
          & sladata       ! SLA data
       INTEGER, INTENT(IN) :: k2dint
@@ -80,5 +79,4 @@
       CHARACTER(LEN=12), PARAMETER :: cpname = 'obs_rea_altbias'
 
-      INTEGER :: jslano       ! Data set loop variable
       INTEGER :: jobs         ! Obs loop variable
       INTEGER :: jpialtbias   ! Number of grid point in latitude for the bias
@@ -144,68 +142,63 @@
       ! Intepolate the bias already on the model grid at the observation point
   
-      DO jslano = 1, kslano
-
-         ALLOCATE( &
-            & igrdi(2,2,sladata(jslano)%nsurf), &
-            & igrdj(2,2,sladata(jslano)%nsurf), &
-            & zglam(2,2,sladata(jslano)%nsurf), &
-            & zgphi(2,2,sladata(jslano)%nsurf), &
-            & zmask(2,2,sladata(jslano)%nsurf), &
-            & zbias(2,2,sladata(jslano)%nsurf)  &
-            & )
-         
-         DO jobs = 1, sladata(jslano)%nsurf
-
-            igrdi(1,1,jobs) = sladata(jslano)%mi(jobs)-1
-            igrdj(1,1,jobs) = sladata(jslano)%mj(jobs)-1
-            igrdi(1,2,jobs) = sladata(jslano)%mi(jobs)-1
-            igrdj(1,2,jobs) = sladata(jslano)%mj(jobs)
-            igrdi(2,1,jobs) = sladata(jslano)%mi(jobs)
-            igrdj(2,1,jobs) = sladata(jslano)%mj(jobs)-1
-            igrdi(2,2,jobs) = sladata(jslano)%mi(jobs)
-            igrdj(2,2,jobs) = sladata(jslano)%mj(jobs)
-
-         END DO
-
-         CALL obs_int_comm_2d( 2, 2, sladata(jslano)%nsurf, &
-            &                  igrdi, igrdj, glamt, zglam )
-         CALL obs_int_comm_2d( 2, 2, sladata(jslano)%nsurf, &
-            &                  igrdi, igrdj, gphit, zgphi )
-         CALL obs_int_comm_2d( 2, 2, sladata(jslano)%nsurf, &
-            &                  igrdi, igrdj, tmask(:,:,1), zmask )
-         CALL obs_int_comm_2d( 2, 2, sladata(jslano)%nsurf, &
-            &                  igrdi, igrdj, z_altbias, zbias )
-
-         DO jobs = 1, sladata(jslano)%nsurf
-
-            zlam = sladata(jslano)%rlam(jobs)
-            zphi = sladata(jslano)%rphi(jobs)
-            iico = sladata(jslano)%mi(jobs)
-            ijco = sladata(jslano)%mj(jobs)
+      ALLOCATE( &
+         & igrdi(2,2,sladata%nsurf), &
+         & igrdj(2,2,sladata%nsurf), &
+         & zglam(2,2,sladata%nsurf), &
+         & zgphi(2,2,sladata%nsurf), &
+         & zmask(2,2,sladata%nsurf), &
+         & zbias(2,2,sladata%nsurf)  &
+         & )
+         
+      DO jobs = 1, sladata%nsurf
+
+         igrdi(1,1,jobs) = sladata%mi(jobs)-1
+         igrdj(1,1,jobs) = sladata%mj(jobs)-1
+         igrdi(1,2,jobs) = sladata%mi(jobs)-1
+         igrdj(1,2,jobs) = sladata%mj(jobs)
+         igrdi(2,1,jobs) = sladata%mi(jobs)
+         igrdj(2,1,jobs) = sladata%mj(jobs)-1
+         igrdi(2,2,jobs) = sladata%mi(jobs)
+         igrdj(2,2,jobs) = sladata%mj(jobs)
+
+      END DO
+
+      CALL obs_int_comm_2d( 2, 2, sladata%nsurf, jpi, jpj, &
+         &                  igrdi, igrdj, glamt, zglam )
+      CALL obs_int_comm_2d( 2, 2, sladata%nsurf, jpi, jpj, &
+         &                  igrdi, igrdj, gphit, zgphi )
+      CALL obs_int_comm_2d( 2, 2, sladata%nsurf, jpi, jpj, &
+         &                  igrdi, igrdj, tmask(:,:,1), zmask )
+      CALL obs_int_comm_2d( 2, 2, sladata%nsurf, jpi, jpj, &
+         &                  igrdi, igrdj, z_altbias, zbias )
+
+      DO jobs = 1, sladata%nsurf
+
+         zlam = sladata%rlam(jobs)
+         zphi = sladata%rphi(jobs)
+         iico = sladata%mi(jobs)
+         ijco = sladata%mj(jobs)
             
-            CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,         &
-               &                   zglam(:,:,jobs), zgphi(:,:,jobs), &
-               &                   zmask(:,:,jobs), zweig, zobsmask )
+         CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,         &
+            &                   zglam(:,:,jobs), zgphi(:,:,jobs), &
+            &                   zmask(:,:,jobs), zweig, zobsmask )
             
-            CALL obs_int_h2d( 1, 1,      &
-               &              zweig, zbias(:,:,jobs),  zext )
-
-            ! adjust mdt with bias field
-            sladata(jslano)%rext(jobs,2) = &
-               sladata(jslano)%rext(jobs,2) - zext(1)
+         CALL obs_int_h2d( 1, 1,      &
+            &              zweig, zbias(:,:,jobs),  zext )
+
+         ! adjust mdt with bias field
+         sladata%rext(jobs,2) = sladata%rext(jobs,2) - zext(1)
             
-         END DO
-
-         DEALLOCATE( &
-            & igrdi, &
-            & igrdj, &
-            & zglam, &
-            & zgphi, &
-            & zmask, &
-            & zbias  &
-            & )
-         
       END DO
 
+      DEALLOCATE( &
+         & igrdi, &
+         & igrdj, &
+         & zglam, &
+         & zgphi, &
+         & zmask, &
+         & zbias  &
+         & )
+         
       CALL wrk_dealloc(jpi,jpj,z_altbias) 
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90	(revision 6140)
@@ -25,6 +25,6 @@
    USE netcdf                   ! NetCDF library
    USE obs_oper                 ! Observation operators
-   USE obs_prof_io              ! Profile files I/O (non-FB files)
    USE lib_mpp                  ! For ctl_warn/stop
+   USE obs_fbm                  ! Feedback routines
 
    IMPLICIT NONE
@@ -33,5 +33,5 @@
    PRIVATE
 
-   PUBLIC obs_rea_pro_dri  ! Read the profile observations 
+   PUBLIC obs_rea_prof  ! Read the profile observations 
 
    !!----------------------------------------------------------------------
@@ -42,18 +42,17 @@
 
 CONTAINS
- 
-   SUBROUTINE obs_rea_pro_dri( kformat, &
-      &                        profdata, knumfiles, cfilenames, &
-      &                        kvars, kextr, kstp, ddobsini, ddobsend, &
-      &                        ldt3d, lds3d, ldignmis, ldsatt, ldavtimset, &
-      &                        ldmod, kdailyavtypes )
+
+   SUBROUTINE obs_rea_prof( profdata, knumfiles, cdfilenames, &
+      &                     kvars, kextr, kstp, ddobsini, ddobsend, &
+      &                     ldvar1, ldvar2, ldignmis, ldsatt, &
+      &                     ldmod, kdailyavtypes )
       !!---------------------------------------------------------------------
       !!
-      !!                   *** ROUTINE obs_rea_pro_dri ***
+      !!                   *** ROUTINE obs_rea_prof ***
       !!
       !! ** Purpose : Read from file the profile observations
       !!
-      !! ** Method  : Depending on kformat either ENACT, CORIOLIS or
-      !!              feedback data files are read
+      !! ** Method  : Read feedback data in and transform to NEMO internal 
+      !!              profile data structure
       !!
       !! ** Action  : 
@@ -63,31 +62,30 @@
       !! History :  
       !!      ! :  2009-09 (K. Mogensen) : New merged version of old routines
+      !!      ! :  2015-08 (M. Martin) : Merged profile and velocity routines
       !!----------------------------------------------------------------------
-      !! * Modules used
-   
+
       !! * Arguments
-      INTEGER ::  kformat    ! Format of input data
-      !                      ! 1: ENACT
-      !                      ! 2: Coriolis
-      TYPE(obs_prof), INTENT(OUT) ::  profdata     ! Profile data to be read
-      INTEGER, INTENT(IN) :: knumfiles      ! Number of files to read in
+      TYPE(obs_prof), INTENT(OUT) :: &
+         & profdata                     ! Profile data to be read
+      INTEGER, INTENT(IN) :: knumfiles  ! Number of files to read
       CHARACTER(LEN=128), INTENT(IN) ::  &
-         & cfilenames(knumfiles)  ! File names to read in
+         & cdfilenames(knumfiles)        ! File names to read in
       INTEGER, INTENT(IN) :: kvars      ! Number of variables in profdata
-      INTEGER, INTENT(IN) :: kextr      ! Number of extra fields for each var in profdata
-      INTEGER, INTENT(IN) :: kstp        ! Ocean time-step index
-      LOGICAL, INTENT(IN) :: ldt3d       ! Observed variables switches
-      LOGICAL, INTENT(IN) :: lds3d
-      LOGICAL, INTENT(IN) :: ldignmis    ! Ignore missing files
-      LOGICAL, INTENT(IN) :: ldsatt      ! Compute salinity at all temperature points
-      LOGICAL, INTENT(IN) :: ldavtimset  ! Correct time for daily averaged data
-      LOGICAL, INTENT(IN) :: ldmod       ! Initialize model from input data
-      REAL(KIND=dp), INTENT(IN) :: ddobsini    ! Obs. ini time in YYYYMMDD.HHMMSS
-      REAL(KIND=dp), INTENT(IN) :: ddobsend    ! Obs. end time in YYYYMMDD.HHMMSS
+      INTEGER, INTENT(IN) :: kextr      ! Number of extra fields for each var
+      INTEGER, INTENT(IN) :: kstp       ! Ocean time-step index
+      LOGICAL, INTENT(IN) :: ldvar1     ! Observed variables switches
+      LOGICAL, INTENT(IN) :: ldvar2
+      LOGICAL, INTENT(IN) :: ldignmis   ! Ignore missing files
+      LOGICAL, INTENT(IN) :: ldsatt     ! Compute salinity at all temperature points
+      LOGICAL, INTENT(IN) :: ldmod      ! Initialize model from input data
+      REAL(dp), INTENT(IN) :: ddobsini  ! Obs. ini time in YYYYMMDD.HHMMSS
+      REAL(dp), INTENT(IN) :: ddobsend  ! Obs. end time in YYYYMMDD.HHMMSS
       INTEGER, DIMENSION(imaxavtypes), OPTIONAL :: &
-         & kdailyavtypes
+         & kdailyavtypes                ! Types of daily average observations
 
       !! * Local declarations
-      CHARACTER(LEN=15), PARAMETER :: cpname='obs_rea_pro_dri'
+      CHARACTER(LEN=15), PARAMETER :: cpname='obs_rea_prof'
+      CHARACTER(len=8) :: clrefdate
+      CHARACTER(len=6), DIMENSION(:), ALLOCATABLE :: clvars
       INTEGER :: jvar
       INTEGER :: ji
@@ -105,57 +103,62 @@
       INTEGER :: imin
       INTEGER :: isec
+      INTEGER :: iprof
+      INTEGER :: iproftot
+      INTEGER :: ivar1t0
+      INTEGER :: ivar2t0
+      INTEGER :: ivar1t
+      INTEGER :: ivar2t
+      INTEGER :: ip3dt
+      INTEGER :: ios
+      INTEGER :: ioserrcount
+      INTEGER :: ivar1tmpp
+      INTEGER :: ivar2tmpp
+      INTEGER :: ip3dtmpp
+      INTEGER :: itype
       INTEGER, DIMENSION(knumfiles) :: &
          & irefdate
       INTEGER, DIMENSION(ntyp1770+1) :: &
-         & itypt,    &
-         & ityptmpp, &
-         & ityps,    &
-         & itypsmpp 
-      INTEGER :: it3dtmpp
-      INTEGER :: is3dtmpp
-      INTEGER :: ip3dtmpp
+         & itypvar1,    &
+         & itypvar1mpp, &
+         & itypvar2,    &
+         & itypvar2mpp 
       INTEGER, DIMENSION(:), ALLOCATABLE :: &
-         & iobsi,    &
-         & iobsj,    &
-         & iproc,    &
+         & iobsi1,    &
+         & iobsj1,    &
+         & iproc1,    &
+         & iobsi2,    &
+         & iobsj2,    &
+         & iproc2,    &
          & iindx,    &
          & ifileidx, &
          & iprofidx
-      INTEGER :: itype
       INTEGER, DIMENSION(imaxavtypes) :: &
          & idailyavtypes
+      INTEGER, DIMENSION(kvars) :: &
+         & iv3dt
       REAL(wp), DIMENSION(:), ALLOCATABLE :: &
          & zphi, &
          & zlam
-      real(wp), DIMENSION(:), ALLOCATABLE :: &
+      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
          & zdat
+      REAL(wp), DIMENSION(knumfiles) :: &
+         & djulini, &
+         & djulend
       LOGICAL :: llvalprof
+      LOGICAL :: lldavtimset
       TYPE(obfbdata), POINTER, DIMENSION(:) :: &
          & inpfiles
-      real(wp), DIMENSION(knumfiles) :: &
-         & djulini, &
-         & djulend
-      INTEGER :: iprof
-      INTEGER :: iproftot
-      INTEGER :: it3dt0
-      INTEGER :: is3dt0
-      INTEGER :: it3dt
-      INTEGER :: is3dt
-      INTEGER :: ip3dt
-      INTEGER :: ios
-      INTEGER :: ioserrcount
-      INTEGER, DIMENSION(kvars) :: &
-         & iv3dt
-      CHARACTER(len=8) :: cl_refdate
-   
+
       ! Local initialization
       iprof = 0
-      it3dt0 = 0
-      is3dt0 = 0
+      ivar1t0 = 0
+      ivar2t0 = 0
       ip3dt = 0
 
       ! Daily average types
+      lldavtimset = .FALSE.
       IF ( PRESENT(kdailyavtypes) ) THEN
          idailyavtypes(:) = kdailyavtypes(:)
+         IF ( ANY (idailyavtypes(:) /= -1) ) lldavtimset = .TRUE.
       ELSE
          idailyavtypes(:) = -1
@@ -163,21 +166,13 @@
 
       !-----------------------------------------------------------------------
-      ! Check data the model part is just with feedback data files
-      !-----------------------------------------------------------------------
-      IF ( ldmod .AND. ( kformat /= 0 ) ) THEN
-         CALL ctl_stop( 'Model can only be read from feedback data' )
-         RETURN
-      ENDIF
-
-      !-----------------------------------------------------------------------
       ! Count the number of files needed and allocate the obfbdata type
       !-----------------------------------------------------------------------
-      
+
       inobf = knumfiles
-      
+
       ALLOCATE( inpfiles(inobf) )
 
       prof_files : DO jj = 1, inobf
-          
+
          !---------------------------------------------------------------------
          ! Prints
@@ -186,5 +181,5 @@
             WRITE(numout,*)
             WRITE(numout,*) ' obs_rea_pro_dri : Reading from file = ', &
-               & TRIM( TRIM( cfilenames(jj) ) )
+               & TRIM( TRIM( cdfilenames(jj) ) )
             WRITE(numout,*) ' ~~~~~~~~~~~~~~~'
             WRITE(numout,*)
@@ -194,25 +189,25 @@
          !  Initialization: Open file and get dimensions only
          !---------------------------------------------------------------------
-         
-         iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
+
+         iflag = nf90_open( TRIM( cdfilenames(jj) ), nf90_nowrite, &
             &                      i_file_id )
-         
+
          IF ( iflag /= nf90_noerr ) THEN
 
             IF ( ldignmis ) THEN
                inpfiles(jj)%nobs = 0
-               CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
+               CALL ctl_warn( 'File ' // TRIM( cdfilenames(jj) ) // &
                   &           ' not found' )
             ELSE 
-               CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
+               CALL ctl_stop( 'File ' // TRIM( cdfilenames(jj) ) // &
                   &           ' not found' )
             ENDIF
 
          ELSE 
-            
+
             !------------------------------------------------------------------
-            !  Close the file since it is opened in read_proffile
+            !  Close the file since it is opened in read_obfbdata
             !------------------------------------------------------------------
-            
+
             iflag = nf90_close( i_file_id )
 
@@ -220,39 +215,31 @@
             !  Read the profile file into inpfiles
             !------------------------------------------------------------------
-            IF ( kformat == 0 ) THEN
-               CALL init_obfbdata( inpfiles(jj) )
-               IF(lwp) THEN
-                  WRITE(numout,*)
-                  WRITE(numout,*)'Reading from feedback file :', &
-                     &           TRIM( cfilenames(jj) )
-               ENDIF
-               CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                ldgrid = .TRUE. )
-               IF ( inpfiles(jj)%nvar < 2 ) THEN
-                  CALL ctl_stop( 'Feedback format error' )
-                  RETURN
-               ENDIF
-               IF ( TRIM(inpfiles(jj)%cname(1)) /= 'POTM' ) THEN
-                  CALL ctl_stop( 'Feedback format error' )
-                  RETURN
-               ENDIF
-               IF ( TRIM(inpfiles(jj)%cname(2)) /= 'PSAL' ) THEN
-                  CALL ctl_stop( 'Feedback format error' )
-                  RETURN
-               ENDIF
-               IF ( ldmod .AND. ( inpfiles(jj)%nadd == 0 ) ) THEN
-                  CALL ctl_stop( 'Model not in input data' )
-                  RETURN
-               ENDIF
-            ELSEIF ( kformat == 1 ) THEN
-               CALL read_enactfile( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                 numout, lwp, .TRUE. )
-            ELSEIF ( kformat == 2 ) THEN
-               CALL read_coriofile( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                 numout, lwp, .TRUE. )
+            CALL init_obfbdata( inpfiles(jj) )
+            CALL read_obfbdata( TRIM( cdfilenames(jj) ), inpfiles(jj), &
+               &                ldgrid = .TRUE. )
+
+            IF ( inpfiles(jj)%nvar < 2 ) THEN
+               CALL ctl_stop( 'Feedback format error: ', &
+                  &           ' less than 2 vars in profile file' )
+            ENDIF
+
+            IF ( ldmod .AND. ( inpfiles(jj)%nadd == 0 ) ) THEN
+               CALL ctl_stop( 'Model not in input data' )
+            ENDIF
+
+            IF ( jj == 1 ) THEN
+               ALLOCATE( clvars( inpfiles(jj)%nvar ) )
+               DO ji = 1, inpfiles(jj)%nvar
+                 clvars(ji) = inpfiles(jj)%cname(ji)
+               END DO
             ELSE
-               CALL ctl_stop( 'File format unknown' )
-            ENDIF
-            
+               DO ji = 1, inpfiles(jj)%nvar
+                  IF ( inpfiles(jj)%cname(ji) /= clvars(ji) ) THEN
+                     CALL ctl_stop( 'Feedback file variables not consistent', &
+                        &           ' with previous files for this type' )
+                  ENDIF
+               END DO
+            ENDIF
+
             !------------------------------------------------------------------
             !  Change longitude (-180,180)
@@ -272,7 +259,7 @@
             !  Calculate the date  (change eventually)
             !------------------------------------------------------------------
-            cl_refdate=inpfiles(jj)%cdjuldref(1:8)
-            READ(cl_refdate,'(I8)') irefdate(jj)
-            
+            clrefdate=inpfiles(jj)%cdjuldref(1:8)
+            READ(clrefdate,'(I8)') irefdate(jj)
+
             CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
             CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
@@ -283,26 +270,38 @@
 
             ioserrcount=0
-            IF ( ldavtimset ) THEN
+            IF ( lldavtimset ) THEN
+
+               IF ( ANY ( idailyavtypes(:) /= -1 ) .AND. lwp) THEN
+                  WRITE(numout,*)' Resetting time of daily averaged', &
+                     &           ' observations to the end of the day'
+               ENDIF
+
                DO ji = 1, inpfiles(jj)%nobs
-                  ! 
-                  !  for daily averaged data for example
-                  !  MRB data (itype==820) force the time
-                  !  to be the  end of the day
-                  !
                   READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 900 ) itype
 900               IF ( ios /= 0 ) THEN
-                     itype = 0         ! Set type to zero if there is a problem in the string conversion
-                  ENDIF
-                  IF ( ANY (idailyavtypes == itype ) ) THEN
-                     inpfiles(jj)%ptim(ji) = &
-                     & INT(inpfiles(jj)%ptim(ji)) + 1
-                  ENDIF
+                     ! Set type to zero if there is a problem in the string conversion
+                     itype = 0
+                  ENDIF
+
+                  IF ( ANY ( idailyavtypes(:) == itype ) ) THEN
+                  !  for daily averaged data force the time
+                  !  to be the last time-step of the day, but still within the day.
+                     IF ( inpfiles(jj)%ptim(ji) >= 0. ) THEN
+                        inpfiles(jj)%ptim(ji) = &
+                           & INT(inpfiles(jj)%ptim(ji)) + 0.9999
+                     ELSE
+                        inpfiles(jj)%ptim(ji) = &
+                           & INT(inpfiles(jj)%ptim(ji)) - 0.0001
+                     ENDIF
+                  ENDIF
+
                END DO
-            ENDIF
-            
+
+            ENDIF
+
             IF ( inpfiles(jj)%nobs > 0 ) THEN
-               inpfiles(jj)%iproc = -1
-               inpfiles(jj)%iobsi = -1
-               inpfiles(jj)%iobsj = -1
+               inpfiles(jj)%iproc(:,:) = -1
+               inpfiles(jj)%iobsi(:,:) = -1
+               inpfiles(jj)%iobsj(:,:) = -1
             ENDIF
             inowin = 0
@@ -318,7 +317,10 @@
             ALLOCATE( zlam(inowin)  )
             ALLOCATE( zphi(inowin)  )
-            ALLOCATE( iobsi(inowin) )
-            ALLOCATE( iobsj(inowin) )
-            ALLOCATE( iproc(inowin) )
+            ALLOCATE( iobsi1(inowin) )
+            ALLOCATE( iobsj1(inowin) )
+            ALLOCATE( iproc1(inowin) )
+            ALLOCATE( iobsi2(inowin) )
+            ALLOCATE( iobsj2(inowin) )
+            ALLOCATE( iproc2(inowin) )
             inowin = 0
             DO ji = 1, inpfiles(jj)%nobs
@@ -334,5 +336,16 @@
             END DO
 
-            CALL obs_grid_search( inowin, zlam, zphi, iobsi, iobsj, iproc, 'T' )
+            IF ( TRIM( inpfiles(jj)%cname(1) ) == 'POTM' ) THEN
+               CALL obs_grid_search( inowin, zlam, zphi, iobsi1, iobsj1, &
+                  &                  iproc1, 'T' )
+               iobsi2(:) = iobsi1(:)
+               iobsj2(:) = iobsj1(:)
+               iproc2(:) = iproc1(:)
+            ELSEIF ( TRIM( inpfiles(jj)%cname(1) ) == 'UVEL' ) THEN
+               CALL obs_grid_search( inowin, zlam, zphi, iobsi1, iobsj1, &
+                  &                  iproc1, 'U' )
+               CALL obs_grid_search( inowin, zlam, zphi, iobsi2, iobsj2, &
+                  &                  iproc2, 'V' )
+            ENDIF
 
             inowin = 0
@@ -344,10 +357,18 @@
                   & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
                   inowin = inowin + 1
-                  inpfiles(jj)%iproc(ji,1) = iproc(inowin)
-                  inpfiles(jj)%iobsi(ji,1) = iobsi(inowin)
-                  inpfiles(jj)%iobsj(ji,1) = iobsj(inowin)
+                  inpfiles(jj)%iproc(ji,1) = iproc1(inowin)
+                  inpfiles(jj)%iobsi(ji,1) = iobsi1(inowin)
+                  inpfiles(jj)%iobsj(ji,1) = iobsj1(inowin)
+                  inpfiles(jj)%iproc(ji,2) = iproc2(inowin)
+                  inpfiles(jj)%iobsi(ji,2) = iobsi2(inowin)
+                  inpfiles(jj)%iobsj(ji,2) = iobsj2(inowin)
+                  IF ( inpfiles(jj)%iproc(ji,1) /= &
+                     & inpfiles(jj)%iproc(ji,2) ) THEN
+                     CALL ctl_stop( 'Error in obs_read_prof:', &
+                        & 'var1 and var2 observation on different processors')
+                  ENDIF
                ENDIF
             END DO
-            DEALLOCATE( zlam, zphi, iobsi, iobsj, iproc )
+            DEALLOCATE( zlam, zphi, iobsi1, iobsj1, iproc1, iobsi2, iobsj2, iproc2 )
 
             DO ji = 1, inpfiles(jj)%nobs
@@ -363,5 +384,5 @@
                   ENDIF
                   llvalprof = .FALSE.
-                  IF ( ldt3d ) THEN
+                  IF ( ldvar1 ) THEN
                      loop_t_count : DO ij = 1,inpfiles(jj)%nlev
                         IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
@@ -369,9 +390,9 @@
                         IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
                            & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
-                           it3dt0 = it3dt0 + 1
+                           ivar1t0 = ivar1t0 + 1
                         ENDIF
                      END DO loop_t_count
                   ENDIF
-                  IF ( lds3d ) THEN
+                  IF ( ldvar2 ) THEN
                      loop_s_count : DO ij = 1,inpfiles(jj)%nlev
                         IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
@@ -379,5 +400,5 @@
                         IF ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
                            & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
-                           is3dt0 = is3dt0 + 1
+                           ivar2t0 = ivar2t0 + 1
                         ENDIF
                      END DO loop_s_count
@@ -388,8 +409,8 @@
                      IF ( ( ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
                         &     ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
-                        &     ldt3d ) .OR. &
+                        &     ldvar1 ) .OR. &
                         & ( ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
                         &     ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
-                        &     lds3d ) ) THEN
+                        &     ldvar2 ) ) THEN
                         ip3dt = ip3dt + 1
                         llvalprof = .TRUE.
@@ -405,5 +426,5 @@
 
       END DO prof_files
-      
+
       !-----------------------------------------------------------------------
       ! Get the time ordered indices of the input data
@@ -446,5 +467,5 @@
          &               zdat,     &
          &               iindx   )
-      
+
       iv3dt(:) = -1
       IF (ldsatt) THEN
@@ -452,29 +473,29 @@
          iv3dt(2) = ip3dt
       ELSE
-         iv3dt(1) = it3dt0
-         iv3dt(2) = is3dt0
+         iv3dt(1) = ivar1t0
+         iv3dt(2) = ivar2t0
       ENDIF
       CALL obs_prof_alloc( profdata, kvars, kextr, iprof, iv3dt, &
          &                 kstp, jpi, jpj, jpk )
-      
+
       ! * Read obs/positions, QC, all variable and assign to profdata
 
       profdata%nprof     = 0
       profdata%nvprot(:) = 0
-
+      profdata%cvars(:)  = clvars(:)
       iprof = 0
 
       ip3dt = 0
-      it3dt = 0
-      is3dt = 0
-      itypt   (:) = 0
-      ityptmpp(:) = 0
-      
-      ityps   (:) = 0
-      itypsmpp(:) = 0
-      
-      ioserrcount = 0      
+      ivar1t = 0
+      ivar2t = 0
+      itypvar1   (:) = 0
+      itypvar1mpp(:) = 0
+
+      itypvar2   (:) = 0
+      itypvar2mpp(:) = 0
+
+      ioserrcount = 0
       DO jk = 1, iproftot
-         
+
          jj = ifileidx(iindx(jk))
          ji = iprofidx(iindx(jk))
@@ -486,5 +507,5 @@
          IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
             & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
-            
+
             IF ( nproc == 0 ) THEN
                IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
@@ -492,5 +513,5 @@
                IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
             ENDIF
-            
+
             llvalprof = .FALSE.
 
@@ -501,30 +522,30 @@
 
             loop_prof : DO ij = 1, inpfiles(jj)%nlev
-               
+
                IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
                   & CYCLE
-               
+
                IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
                   & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
-                  
+
                   llvalprof = .TRUE. 
                   EXIT loop_prof
-                  
+
                ENDIF
-               
+
                IF ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
                   & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
-                  
+
                   llvalprof = .TRUE. 
                   EXIT loop_prof
-                  
+
                ENDIF
-               
+
             END DO loop_prof
-            
+
             ! Set profile information
-            
+
             IF ( llvalprof ) THEN
-               
+
                iprof = iprof + 1
 
@@ -545,5 +566,5 @@
                profdata%nhou(iprof) = ihou
                profdata%nmin(iprof) = imin
-               
+
                ! Profile space coordinates
                profdata%rlam(iprof) = inpfiles(jj)%plam(ji)
@@ -551,10 +572,12 @@
 
                ! Coordinate search parameters
-               profdata%mi  (iprof,:) = inpfiles(jj)%iobsi(ji,1)
-               profdata%mj  (iprof,:) = inpfiles(jj)%iobsj(ji,1)
-               
+               profdata%mi  (iprof,1) = inpfiles(jj)%iobsi(ji,1)
+               profdata%mj  (iprof,1) = inpfiles(jj)%iobsj(ji,1)
+               profdata%mi  (iprof,2) = inpfiles(jj)%iobsi(ji,2)
+               profdata%mj  (iprof,2) = inpfiles(jj)%iobsj(ji,2)
+
                ! Profile WMO number
                profdata%cwmo(iprof) = inpfiles(jj)%cdwmo(ji)
-               
+
                ! Instrument type
                READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
@@ -564,7 +587,7 @@
                   itype = 0
                ENDIF
-               
+
                profdata%ntyp(iprof) = itype
-               
+
                ! QC stuff
 
@@ -585,6 +608,6 @@
                profdata%nqc(iprof)  = 0 !TODO
 
-               loop_p : DO ij = 1, inpfiles(jj)%nlev            
-                  
+               loop_p : DO ij = 1, inpfiles(jj)%nlev
+
                   IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
                      & CYCLE
@@ -594,135 +617,137 @@
                      IF ( ( ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
                         &     ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
-                        &     ldt3d ) .OR. &
+                        &     ldvar1 ) .OR. &
                         & ( ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
                         &     ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
-                        &     lds3d ) ) THEN
+                        &     ldvar2 ) ) THEN
                         ip3dt = ip3dt + 1
                      ELSE
                         CYCLE
                      ENDIF
-                     
+
                   ENDIF
 
                   IF ( ( ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
                      &     ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
-                     &       ldt3d ) .OR. ldsatt ) THEN
-                     
+                     &       ldvar1 ) .OR. ldsatt ) THEN
+
                      IF (ldsatt) THEN
 
-                        it3dt = ip3dt
+                        ivar1t = ip3dt
 
                      ELSE
 
-                        it3dt = it3dt + 1
-                        
+                        ivar1t = ivar1t + 1
+
                      ENDIF
 
-                     ! Depth of T observation
-                     profdata%var(1)%vdep(it3dt) = &
+                     ! Depth of var1 observation
+                     profdata%var(1)%vdep(ivar1t) = &
                         &                inpfiles(jj)%pdep(ij,ji)
-                     
-                     ! Depth of T observation QC
-                     profdata%var(1)%idqc(it3dt) = &
+
+                     ! Depth of var1 observation QC
+                     profdata%var(1)%idqc(ivar1t) = &
                         &                inpfiles(jj)%idqc(ij,ji)
-                     
-                     ! Depth of T observation QC flags
-                     profdata%var(1)%idqcf(:,it3dt) = &
+
+                     ! Depth of var1 observation QC flags
+                     profdata%var(1)%idqcf(:,ivar1t) = &
                         &                inpfiles(jj)%idqcf(:,ij,ji)
-                     
+
                      ! Profile index
-                     profdata%var(1)%nvpidx(it3dt) = iprof
-                     
+                     profdata%var(1)%nvpidx(ivar1t) = iprof
+
                      ! Vertical index in original profile
-                     profdata%var(1)%nvlidx(it3dt) = ij
-
-                     ! Profile potential T value
+                     profdata%var(1)%nvlidx(ivar1t) = ij
+
+                     ! Profile var1 value
                      IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
                         & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
-                        profdata%var(1)%vobs(it3dt) = &
+                        profdata%var(1)%vobs(ivar1t) = &
                            &                inpfiles(jj)%pob(ij,ji,1)
                         IF ( ldmod ) THEN
-                           profdata%var(1)%vmod(it3dt) = &
+                           profdata%var(1)%vmod(ivar1t) = &
                               &                inpfiles(jj)%padd(ij,ji,1,1)
                         ENDIF
-                        ! Count number of profile T data as function of type
-                        itypt( profdata%ntyp(iprof) + 1 ) = &
-                           & itypt( profdata%ntyp(iprof) + 1 ) + 1
+                        ! Count number of profile var1 data as function of type
+                        itypvar1( profdata%ntyp(iprof) + 1 ) = &
+                           & itypvar1( profdata%ntyp(iprof) + 1 ) + 1
                      ELSE
-                        profdata%var(1)%vobs(it3dt) = fbrmdi
+                        profdata%var(1)%vobs(ivar1t) = fbrmdi
                      ENDIF
 
-                     ! Profile T qc
-                     profdata%var(1)%nvqc(it3dt) = &
+                     ! Profile var1 qc
+                     profdata%var(1)%nvqc(ivar1t) = &
                         & inpfiles(jj)%ivlqc(ij,ji,1)
 
-                     ! Profile T qc flags
-                     profdata%var(1)%nvqcf(:,it3dt) = &
+                     ! Profile var1 qc flags
+                     profdata%var(1)%nvqcf(:,ivar1t) = &
                         & inpfiles(jj)%ivlqcf(:,ij,ji,1)
 
                      ! Profile insitu T value
-                     profdata%var(1)%vext(it3dt,1) = &
-                        &                inpfiles(jj)%pext(ij,ji,1)
-                     
-                  ENDIF
-                  
+                     IF ( TRIM( inpfiles(jj)%cname(1) ) == 'POTM' ) THEN
+                        profdata%var(1)%vext(ivar1t,1) = &
+                           &                inpfiles(jj)%pext(ij,ji,1)
+                     ENDIF
+
+                  ENDIF
+
                   IF ( ( ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
                      &   ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
-                     &   lds3d ) .OR. ldsatt ) THEN
-                     
+                     &   ldvar2 ) .OR. ldsatt ) THEN
+
                      IF (ldsatt) THEN
 
-                        is3dt = ip3dt
+                        ivar2t = ip3dt
 
                      ELSE
 
-                        is3dt = is3dt + 1
-                        
+                        ivar2t = ivar2t + 1
+
                      ENDIF
 
-                     ! Depth of S observation
-                     profdata%var(2)%vdep(is3dt) = &
+                     ! Depth of var2 observation
+                     profdata%var(2)%vdep(ivar2t) = &
                         &                inpfiles(jj)%pdep(ij,ji)
-                     
-                     ! Depth of S observation QC
-                     profdata%var(2)%idqc(is3dt) = &
+
+                     ! Depth of var2 observation QC
+                     profdata%var(2)%idqc(ivar2t) = &
                         &                inpfiles(jj)%idqc(ij,ji)
-                     
-                     ! Depth of S observation QC flags
-                     profdata%var(2)%idqcf(:,is3dt) = &
+
+                     ! Depth of var2 observation QC flags
+                     profdata%var(2)%idqcf(:,ivar2t) = &
                         &                inpfiles(jj)%idqcf(:,ij,ji)
-                     
+
                      ! Profile index
-                     profdata%var(2)%nvpidx(is3dt) = iprof
-                     
+                     profdata%var(2)%nvpidx(ivar2t) = iprof
+
                      ! Vertical index in original profile
-                     profdata%var(2)%nvlidx(is3dt) = ij
-
-                     ! Profile S value
+                     profdata%var(2)%nvlidx(ivar2t) = ij
+
+                     ! Profile var2 value
                      IF ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
                         & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
-                        profdata%var(2)%vobs(is3dt) = &
+                        profdata%var(2)%vobs(ivar2t) = &
                            &                inpfiles(jj)%pob(ij,ji,2)
                         IF ( ldmod ) THEN
-                           profdata%var(2)%vmod(is3dt) = &
+                           profdata%var(2)%vmod(ivar2t) = &
                               &                inpfiles(jj)%padd(ij,ji,1,2)
                         ENDIF
-                        ! Count number of profile S data as function of type
-                        ityps( profdata%ntyp(iprof) + 1 ) = &
-                           & ityps( profdata%ntyp(iprof) + 1 ) + 1
+                        ! Count number of profile var2 data as function of type
+                        itypvar2( profdata%ntyp(iprof) + 1 ) = &
+                           & itypvar2( profdata%ntyp(iprof) + 1 ) + 1
                      ELSE
-                        profdata%var(2)%vobs(is3dt) = fbrmdi
+                        profdata%var(2)%vobs(ivar2t) = fbrmdi
                      ENDIF
-                     
-                     ! Profile S qc
-                     profdata%var(2)%nvqc(is3dt) = &
+
+                     ! Profile var2 qc
+                     profdata%var(2)%nvqc(ivar2t) = &
                         & inpfiles(jj)%ivlqc(ij,ji,2)
 
-                     ! Profile S qc flags
-                     profdata%var(2)%nvqcf(:,is3dt) = &
+                     ! Profile var2 qc flags
+                     profdata%var(2)%nvqcf(:,ivar2t) = &
                         & inpfiles(jj)%ivlqcf(:,ij,ji,2)
 
                   ENDIF
-            
+
                END DO loop_p
 
@@ -736,12 +761,12 @@
       ! Sum up over processors
       !-----------------------------------------------------------------------
-      
-      CALL obs_mpp_sum_integer ( it3dt0, it3dtmpp )
-      CALL obs_mpp_sum_integer ( is3dt0, is3dtmpp )
-      CALL obs_mpp_sum_integer ( ip3dt, ip3dtmpp )
-      
-      CALL obs_mpp_sum_integers( itypt, ityptmpp, ntyp1770 + 1 )
-      CALL obs_mpp_sum_integers( ityps, itypsmpp, ntyp1770 + 1 )
-      
+
+      CALL obs_mpp_sum_integer ( ivar1t0, ivar1tmpp )
+      CALL obs_mpp_sum_integer ( ivar2t0, ivar2tmpp )
+      CALL obs_mpp_sum_integer ( ip3dt,   ip3dtmpp  )
+
+      CALL obs_mpp_sum_integers( itypvar1, itypvar1mpp, ntyp1770 + 1 )
+      CALL obs_mpp_sum_integers( itypvar2, itypvar2mpp, ntyp1770 + 1 )
+
       !-----------------------------------------------------------------------
       ! Output number of observations.
@@ -749,14 +774,14 @@
       IF(lwp) THEN
          WRITE(numout,*) 
-         WRITE(numout,'(1X,A)') 'Profile data'
+         WRITE(numout,'(A)') ' Profile data'
          WRITE(numout,'(1X,A)') '------------'
          WRITE(numout,*) 
-         WRITE(numout,'(1X,A)') 'Profile T data'
-         WRITE(numout,'(1X,A)') '--------------'
+         WRITE(numout,'(1X,A)') 'Profile data, '//TRIM( profdata%cvars(1) )
+         WRITE(numout,'(1X,A)') '------------------------'
          DO ji = 0, ntyp1770
-            IF ( ityptmpp(ji+1) > 0 ) THEN
+            IF ( itypvar1mpp(ji+1) > 0 ) THEN
                WRITE(numout,'(1X,A3,1X,A48,A3,I8)') ctypshort(ji), &
                   & cwmonam1770(ji)(1:52),' = ', &
-                  & ityptmpp(ji+1)
+                  & itypvar1mpp(ji+1)
             ENDIF
          END DO
@@ -764,16 +789,16 @@
             & '---------------------------------------------------------------'
          WRITE(numout,'(1X,A55,I8)') &
-            & 'Total profile T data                                 = ',&
-            & it3dtmpp
+            & 'Total profile data for variable '//TRIM( profdata%cvars(1) )// &
+            & '             = ', ivar1tmpp
          WRITE(numout,'(1X,A)') &
             & '---------------------------------------------------------------'
          WRITE(numout,*) 
-         WRITE(numout,'(1X,A)') 'Profile S data'
-         WRITE(numout,'(1X,A)') '--------------'
+         WRITE(numout,'(1X,A)') 'Profile data, '//TRIM( profdata%cvars(2) )
+         WRITE(numout,'(1X,A)') '------------------------'
          DO ji = 0, ntyp1770
-            IF ( itypsmpp(ji+1) > 0 ) THEN
+            IF ( itypvar2mpp(ji+1) > 0 ) THEN
                WRITE(numout,'(1X,A3,1X,A48,A3,I8)') ctypshort(ji), &
                   & cwmonam1770(ji)(1:52),' = ', &
-                  & itypsmpp(ji+1)
+                  & itypvar2mpp(ji+1)
             ENDIF
          END DO
@@ -781,11 +806,11 @@
             & '---------------------------------------------------------------'
          WRITE(numout,'(1X,A55,I8)') &
-            & 'Total profile S data                                 = ',&
-            & is3dtmpp
+            & 'Total profile data for variable '//TRIM( profdata%cvars(2) )// &
+            & '             = ', ivar2tmpp
          WRITE(numout,'(1X,A)') &
             & '---------------------------------------------------------------'
          WRITE(numout,*) 
       ENDIF
-      
+
       IF (ldsatt) THEN
          profdata%nvprot(1)    = ip3dt
@@ -794,8 +819,8 @@
          profdata%nvprotmpp(2) = ip3dtmpp
       ELSE
-         profdata%nvprot(1)    = it3dt
-         profdata%nvprot(2)    = is3dt
-         profdata%nvprotmpp(1) = it3dtmpp
-         profdata%nvprotmpp(2) = is3dtmpp
+         profdata%nvprot(1)    = ivar1t
+         profdata%nvprot(2)    = ivar2t
+         profdata%nvprotmpp(1) = ivar1tmpp
+         profdata%nvprotmpp(2) = ivar2tmpp
       ENDIF
       profdata%nprof        = iprof
@@ -804,15 +829,15 @@
       ! Model level search
       !-----------------------------------------------------------------------
-      IF ( ldt3d ) THEN
+      IF ( ldvar1 ) THEN
          CALL obs_level_search( jpk, gdept_1d, &
             & profdata%nvprot(1), profdata%var(1)%vdep, &
             & profdata%var(1)%mvk )
       ENDIF
-      IF ( lds3d ) THEN
+      IF ( ldvar2 ) THEN
          CALL obs_level_search( jpk, gdept_1d, &
             & profdata%nvprot(2), profdata%var(2)%vdep, &
             & profdata%var(2)%mvk )
       ENDIF
-      
+
       !-----------------------------------------------------------------------
       ! Set model equivalent to 99999
@@ -826,5 +851,5 @@
       ! Deallocate temporary data
       !-----------------------------------------------------------------------
-      DEALLOCATE( ifileidx, iprofidx, zdat )
+      DEALLOCATE( ifileidx, iprofidx, zdat, clvars )
 
       !-----------------------------------------------------------------------
@@ -836,5 +861,5 @@
       DEALLOCATE( inpfiles )
 
-   END SUBROUTINE obs_rea_pro_dri
+   END SUBROUTINE obs_rea_prof
 
 END MODULE obs_read_prof
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_seaice.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_seaice.F90	(revision 6139)
+++ 	(revision )
@@ -1,465 +1,0 @@
-MODULE obs_read_seaice
-   !!======================================================================
-   !!                       ***  MODULE obs_read_seaice  ***
-   !! Observation diagnostics: Read the along track SEAICE data from
-   !!                          GHRSST or any SEAICE data from feedback files
-   !!======================================================================
-
-   !!----------------------------------------------------------------------
-   !!   obs_rea_seaice : Driver for reading seaice data from the GHRSST/feedback
-   !!----------------------------------------------------------------------
-
-   !! * Modules used   
-   USE par_kind                 ! Precision variables
-   USE in_out_manager           ! I/O manager
-   USE dom_oce                  ! Ocean space and time domain variables
-   USE obs_mpp                  ! MPP support routines for observation diagnostics
-   USE julian                   ! Julian date routines
-   USE obs_utils                ! Observation operator utility functions
-   USE obs_grid                 ! Grid search
-   USE obs_sort                 ! Sorting observation arrays
-   USE obs_surf_def             ! Surface observation definitions
-   USE obs_types                ! Observation type definitions
-   USE obs_seaice_io            ! I/O for seaice files
-   USE iom                      ! I/O of fields for Reynolds data
-   USE netcdf                   ! NetCDF library
-
-   IMPLICIT NONE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC obs_rea_seaice      ! Read the seaice observations from the point data
-   
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE obs_rea_seaice( kformat, &
-      &                    seaicedata, knumfiles, cfilenames, &
-      &                    kvars, kextr, kstp, ddobsini, ddobsend, &
-      &                    ldignmis, ldmod )
-      !!---------------------------------------------------------------------
-      !!
-      !!                   *** ROUTINE obs_rea_seaice ***
-      !!
-      !! ** Purpose : Read from file the seaice data
-      !!
-      !! ** Method  : Depending on kformat either AVISO or
-      !!              feedback data files are read
-      !!
-      !! ** Action  : 
-      !!
-      !!
-      !! History :  
-      !!      ! :  2009-01 (K. Mogensen) Initial version based on old versions
-      !!----------------------------------------------------------------------
-      !! * Modules used
-
-      !! * Arguments
-      INTEGER :: kformat   ! Format of input data 
-      !                    ! 0: Feedback
-      !                    ! 1: GHRSST
-      TYPE(obs_surf), INTENT(INOUT) :: &
-         & seaicedata     ! seaice data to be read
-      INTEGER, INTENT(IN) :: knumfiles   ! Number of corio format files to read in
-      CHARACTER(LEN=128), INTENT(IN) :: cfilenames(knumfiles) ! File names to read in
-      INTEGER, INTENT(IN) :: kvars    ! Number of variables in seaicedata
-      INTEGER, INTENT(IN) :: kextr    ! Number of extra fields for each var in seaicedata
-      INTEGER, INTENT(IN) :: kstp     ! Ocean time-step index
-      LOGICAL, INTENT(IN) :: ldignmis   ! Ignore missing files
-      LOGICAL, INTENT(IN) :: ldmod      ! Initialize model from input data
-      REAL(KIND=dp), INTENT(IN) :: ddobsini    ! Obs. ini time in YYYYMMDD.HHMMSS
-      REAL(KIND=dp), INTENT(IN) :: ddobsend    ! Obs. end time in YYYYMMDD.HHMMSS
-         
-      !! * Local declarations
-      CHARACTER(LEN=14), PARAMETER :: cpname='obs_rea_seaice'
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jk
-      INTEGER :: iflag
-      INTEGER :: inobf
-      INTEGER :: i_file_id
-      INTEGER :: inowin
-      INTEGER :: iyea
-      INTEGER :: imon
-      INTEGER :: iday
-      INTEGER :: ihou
-      INTEGER :: imin
-      INTEGER :: isec
-      INTEGER, DIMENSION(knumfiles) :: &
-         & irefdate
-      INTEGER :: iobsmpp
-      INTEGER, PARAMETER :: iseaicemaxtype = 1024
-      INTEGER, DIMENSION(0:iseaicemaxtype) :: &
-         & ityp, &
-         & itypmpp
-      INTEGER, DIMENSION(:), ALLOCATABLE :: &
-         & iobsi,    &
-         & iobsj,    &
-         & iproc,    &
-         & iindx,    &
-         & ifileidx, &
-         & iseaiceidx
-      INTEGER :: itype
-      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zphi, &
-         & zlam
-      real(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zdat
-      LOGICAL :: llvalprof
-      TYPE(obfbdata), POINTER, DIMENSION(:) :: &
-         & inpfiles
-      real(wp), DIMENSION(knumfiles) :: &
-         & djulini, &
-         & djulend
-      INTEGER :: iobs
-      INTEGER :: iobstot
-      INTEGER :: ios
-      INTEGER :: ioserrcount
-      CHARACTER(len=8) :: cl_refdate
-   
-      ! Local initialization
-      iobs = 0
- 
-      !-----------------------------------------------------------------------
-      ! Check data the model part is just with feedback data files
-      !-----------------------------------------------------------------------
-      IF ( ldmod .AND. ( kformat /= 0 ) ) THEN
-         CALL ctl_stop( 'Model can only be read from feedback data' )
-         RETURN
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Count the number of files needed and allocate the obfbdata type
-      !-----------------------------------------------------------------------
-      
-      inobf = knumfiles
-      
-      ALLOCATE( inpfiles(inobf) )
-
-      seaice_files : DO jj = 1, inobf
-          
-         !---------------------------------------------------------------------
-         ! Prints
-         !---------------------------------------------------------------------
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) ' obs_rea_seaice : Reading from file = ', &
-               & TRIM( TRIM( cfilenames(jj) ) )
-            WRITE(numout,*) ' ~~~~~~~~~~~~~~'
-            WRITE(numout,*)
-         ENDIF
-
-         !---------------------------------------------------------------------
-         !  Initialization: Open file and get dimensions only
-         !---------------------------------------------------------------------
-         
-         iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
-            &                      i_file_id )
-         
-         IF ( iflag /= nf90_noerr ) THEN
-
-            IF ( ldignmis ) THEN
-               inpfiles(jj)%nobs = 0
-               CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ELSE 
-               CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ENDIF
-
-         ELSE 
-            
-            !------------------------------------------------------------------
-            !  Close the file since it is opened in read_proffile
-            !------------------------------------------------------------------
-            
-            iflag = nf90_close( i_file_id )
-
-            !------------------------------------------------------------------
-            !  Read the profile file into inpfiles
-            !------------------------------------------------------------------
-            IF ( kformat == 0 ) THEN
-               CALL init_obfbdata( inpfiles(jj) )
-               IF(lwp) THEN
-                  WRITE(numout,*)
-                  WRITE(numout,*)'Reading from feedback file :', &
-                     &           TRIM( cfilenames(jj) )
-               ENDIF
-               CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                ldgrid = .TRUE. )
-               IF ( ldmod .AND. ( ( inpfiles(jj)%nadd == 0 ) .OR.&
-                  &               ( inpfiles(jj)%next < 2 ) ) ) THEN
-                  CALL ctl_stop( 'Model not in input data' )
-                  RETURN
-               ENDIF
-            ELSEIF ( kformat == 1) THEN
-               CALL read_seaice( TRIM( cfilenames(jj) ), inpfiles(jj), &
-               &                 numout, lwp, .TRUE. )
-            ELSE
-               CALL ctl_stop( 'File format unknown' )
-            ENDIF
-
-            !------------------------------------------------------------------
-            !  Change longitude (-180,180)
-            !------------------------------------------------------------------
-
-            DO ji = 1, inpfiles(jj)%nobs 
-
-               IF ( inpfiles(jj)%plam(ji) < -180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) + 360.
-
-               IF ( inpfiles(jj)%plam(ji) >  180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) - 360.
-
-            END DO
-
-            !------------------------------------------------------------------
-            !  Calculate the date  (change eventually)
-            !------------------------------------------------------------------
-            cl_refdate=inpfiles(jj)%cdjuldref(1:8)
-            READ(cl_refdate,'(I8)') irefdate(jj)
-            
-            CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
-               &           krefdate = irefdate(jj) )
-            CALL ddatetoymdhms( ddobsend, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulend(jj), &
-               &           krefdate = irefdate(jj) )
-            IF ( inpfiles(jj)%nobs > 0 ) THEN
-               inpfiles(jj)%iproc = -1
-               inpfiles(jj)%iobsi = -1
-               inpfiles(jj)%iobsj = -1
-            ENDIF
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-               ENDIF
-            END DO
-            ALLOCATE( zlam(inowin)  )
-            ALLOCATE( zphi(inowin)  )
-            ALLOCATE( iobsi(inowin) )
-            ALLOCATE( iobsj(inowin) )
-            ALLOCATE( iproc(inowin) )
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  zlam(inowin) = inpfiles(jj)%plam(ji)
-                  zphi(inowin) = inpfiles(jj)%pphi(ji)
-               ENDIF
-            END DO
-
-            CALL obs_grid_search( inowin, zlam, zphi, iobsi, iobsj, iproc, 'T' )
-
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  inpfiles(jj)%iproc(ji,1) = iproc(inowin)
-                  inpfiles(jj)%iobsi(ji,1) = iobsi(inowin)
-                  inpfiles(jj)%iobsj(ji,1) = iobsj(inowin)
-               ENDIF
-            END DO
-            DEALLOCATE( zlam, zphi, iobsi, iobsj, iproc )
-
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  IF ( nproc == 0 ) THEN
-                     IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-                  ELSE
-                     IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-                  ENDIF
-                  llvalprof = .FALSE.
-                  IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-                     & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
-                     iobs = iobs + 1
-                  ENDIF
-               ENDIF
-            END DO
-
-         ENDIF
-
-      END DO seaice_files
-
-      !-----------------------------------------------------------------------
-      ! Get the time ordered indices of the input data
-      !-----------------------------------------------------------------------
-
-      !---------------------------------------------------------------------
-      !  Loop over input data files to count total number of profiles
-      !---------------------------------------------------------------------
-      iobstot = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               iobstot = iobstot + 1
-            ENDIF
-         END DO
-      END DO
-
-      ALLOCATE( iindx(iobstot), ifileidx(iobstot), &
-         &      iseaiceidx(iobstot), zdat(iobstot) )
-      jk = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               jk = jk + 1
-               ifileidx(jk) = jj
-               iseaiceidx(jk) = ji
-               zdat(jk)     = inpfiles(jj)%ptim(ji)
-            ENDIF
-         END DO
-      END DO
-      CALL sort_dp_indx( iobstot, &
-         &               zdat,     &
-         &               iindx   )
-      
-      CALL obs_surf_alloc( seaicedata, iobs, & 
-                           kvars, kextr, kstp, jpi, jpj )
-      
-      ! * Read obs/positions, QC, all variable and assign to seaicedata
- 
-      iobs = 0
-
-      ityp   (:) = 0
-      itypmpp(:) = 0
-
-      ioserrcount=0      
-
-      DO jk = 1, iobstot
-         
-         jj = ifileidx(iindx(jk))
-         ji = iseaiceidx(iindx(jk))
-         IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
-            & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
-            
-            IF ( nproc == 0 ) THEN
-               IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-            ELSE
-               IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-            ENDIF
-            
-            ! Set observation information
-            
-            IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-               & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
-
-               iobs = iobs + 1
-
-               CALL jul2greg( isec,                   &
-                  &           imin,                   &
-                  &           ihou,                   &
-                  &           iday,                   &
-                  &           imon,                   &
-                  &           iyea,                   &
-                  &           inpfiles(jj)%ptim(ji), &
-                  &           irefdate(jj) )
-
-
-               ! seaice time coordinates
-               seaicedata%nyea(iobs) = iyea
-               seaicedata%nmon(iobs) = imon
-               seaicedata%nday(iobs) = iday
-               seaicedata%nhou(iobs) = ihou
-               seaicedata%nmin(iobs) = imin
-               
-               ! seaice space coordinates
-               seaicedata%rlam(iobs) = inpfiles(jj)%plam(ji)
-               seaicedata%rphi(iobs) = inpfiles(jj)%pphi(ji)
-
-               ! Coordinate search parameters
-               seaicedata%mi  (iobs) = inpfiles(jj)%iobsi(ji,1)
-               seaicedata%mj  (iobs) = inpfiles(jj)%iobsj(ji,1)
-               
-               ! Instrument type
-               READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
-901            IF ( ios /= 0 ) THEN
-                  IF (ioserrcount == 0) CALL ctl_warn ( 'Problem converting an instrument type to integer. Setting type to zero' ) 
-                  ioserrcount = ioserrcount + 1
-                  itype = 0
-               ENDIF
-               seaicedata%ntyp(iobs) = itype
-               IF ( itype < iseaicemaxtype + 1 ) THEN
-                  ityp(itype+1) = ityp(itype+1) + 1
-               ELSE
-                  IF(lwp)WRITE(numout,*)'WARNING:Increase iseaicemaxtype in ',&
-                     &                  cpname
-               ENDIF
-
-               ! Bookkeeping data to match observations
-               seaicedata%nsidx(iobs) = iobs
-               seaicedata%nsfil(iobs) = iindx(jk)
-
-               ! QC flags
-               seaicedata%nqc(iobs) = inpfiles(jj)%ivqc(ji,1)
-
-               ! Observed value
-               seaicedata%robs(iobs,1) = inpfiles(jj)%pob(1,ji,1)
-
-
-               ! Model and MDT is set to fbrmdi unless read from file
-               IF ( ldmod ) THEN
-                  seaicedata%rmod(iobs,1) = inpfiles(jj)%padd(1,ji,1,1)
-               ELSE
-                  seaicedata%rmod(iobs,1) = fbrmdi
-               ENDIF
-            ENDIF
-         ENDIF
-
-      END DO
-
-      !-----------------------------------------------------------------------
-      ! Sum up over processors
-      !-----------------------------------------------------------------------
-      
-      CALL obs_mpp_sum_integer( iobs, iobsmpp )
-      
-      !-----------------------------------------------------------------------
-      ! Output number of observations.
-      !-----------------------------------------------------------------------
-      IF (lwp) THEN
-
-         WRITE(numout,*)
-         WRITE(numout,'(1X,A)')'Seaice data types'
-         WRITE(numout,'(1X,A)')'-----------------'
-         DO jj = 1,8
-            IF ( itypmpp(jj) > 0 ) THEN
-               WRITE(numout,'(1X,A4,I4,A3,I10)')'Type ', jj,' = ',itypmpp(jj)
-            ENDIF
-         END DO
-         WRITE(numout,'(1X,A50)')'--------------------------------------------------'
-         WRITE(numout,'(1X,A40,I10)')'Total                                 = ',iobsmpp
-         WRITE(numout,*)
-
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Deallocate temporary data
-      !-----------------------------------------------------------------------
-      DEALLOCATE( ifileidx, iseaiceidx, zdat )
-
-      !-----------------------------------------------------------------------
-      ! Deallocate input data
-      !-----------------------------------------------------------------------
-      DO jj = 1, inobf
-         CALL dealloc_obfbdata( inpfiles(jj) )
-      END DO
-      DEALLOCATE( inpfiles )
-
-   END SUBROUTINE obs_rea_seaice
-
-END MODULE obs_read_seaice
-
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sla.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sla.F90	(revision 6139)
+++ 	(revision )
@@ -1,548 +1,0 @@
-MODULE obs_read_sla
-   !!======================================================================
-   !!                       ***  MODULE obs_read_sla  ***
-   !! Observation diagnostics: Read the along track SLA data from
-   !!                          the AVISO/CLS database or any SLA data 
-   !!                          from feedback files
-   !!======================================================================
-
-   !!----------------------------------------------------------------------
-   !!   obs_rea_sla : Driver for reading SLA data from the AVISO/CLS/feedback
-   !!----------------------------------------------------------------------
-
-   !! * Modules used   
-   USE par_kind                 ! Precision variables
-   USE in_out_manager           ! I/O manager
-   USE dom_oce                  ! Ocean space and time domain variables
-   USE obs_mpp                  ! MPP support routines for observation diagnostics
-   USE julian                   ! Julian date routines
-   USE obs_utils                ! Observation operator utility functions
-   USE obs_grid                 ! Grid search
-   USE obs_sort                 ! Sorting observation arrays
-   USE obs_surf_def             ! Surface observation definitions
-   USE obs_types                ! Observation type definitions
-   USE obs_sla_io               ! I/O for sla files
-   USE netcdf                   ! NetCDF library
-
-   IMPLICIT NONE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC obs_rea_sla  ! Read the SLA observations from the AVISO/SLA database
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE obs_rea_sla( kformat, &
-      &                    sladata, knumfiles, cfilenames, &
-      &                    kvars, kextr, kstp, ddobsini, ddobsend, &
-      &                    ldignmis, ldmod, ldobstd )
-      !!---------------------------------------------------------------------
-      !!
-      !!                   *** ROUTINE obs_rea_sla ***
-      !!
-      !! ** Purpose : Read from file the SLA data
-      !!
-      !! ** Method  : Depending on kformat either AVISO or
-      !!              feedback data files are read
-      !!
-      !! ** Action  : 
-      !!
-      !!
-      !! History :  
-      !!      ! :  2009-01 (K. Mogensen) Initial version based on old versions
-      !!----------------------------------------------------------------------
-      !! * Modules used
-
-      !! * Arguments
-      INTEGER :: kformat    ! Format of input data
-      !                     ! 0: Feedback
-      !                     ! 1: AVISO
-      TYPE(obs_surf), INTENT(INOUT) :: sladata    ! SLA data to be read
-      INTEGER, INTENT(IN) :: knumfiles      ! Number of files to read in
-      CHARACTER(LEN=128), INTENT(IN) ::  &
-         & cfilenames(knumfiles) ! File names to read in
-      INTEGER, INTENT(IN) :: kvars     ! Number of variables in sladata
-      INTEGER, INTENT(IN) :: kextr     ! Number of extra fields for each var in sladata
-      INTEGER, INTENT(IN) :: kstp      ! Ocean time-step index
-      LOGICAL, INTENT(IN) :: ldignmis    ! Ignore missing files
-      LOGICAL, INTENT(IN) :: ldmod       ! Initialize model from input data
-      LOGICAL, INTENT(INOUT), optional :: &
-         & ldobstd        ! Read observation standard deviation from fb. file
-      REAL(KIND=dp), INTENT(IN) :: ddobsini  ! Obs. ini time in YYYYMMDD.HHMMSS
-      REAL(KIND=dp), INTENT(IN) :: ddobsend  ! Obs. end time in YYYYMMDD.HHMMSS
-         
-      !! * Local declarations
-      CHARACTER(LEN=11), PARAMETER :: cpname='obs_rea_sla'
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jk
-      INTEGER :: iflag
-      INTEGER :: inobf
-      INTEGER :: i_file_id
-      INTEGER :: inowin
-      INTEGER :: iyea
-      INTEGER :: imon
-      INTEGER :: iday
-      INTEGER :: ihou
-      INTEGER :: imin
-      INTEGER :: isec
-      INTEGER, DIMENSION(knumfiles) :: &
-         & irefdate
-      INTEGER :: iobsmpp
-      INTEGER, DIMENSION(imaxmissions+1) :: &
-         & ityp, &
-         & itypmpp
-      INTEGER, DIMENSION(:), ALLOCATABLE :: &
-         & iobsi,    &
-         & iobsj,    &
-         & iproc,    &
-         & iindx,    &
-         & ifileidx, &
-         & islaidx
-      INTEGER :: itype 
-      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zphi, &
-         & zlam
-      real(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zdat
-      LOGICAL :: llvalprof
-      LOGICAL :: llobstd
-      TYPE(obfbdata), POINTER, DIMENSION(:) :: &
-         & inpfiles
-      real(wp), DIMENSION(knumfiles) :: &
-         & djulini, &
-         & djulend
-      INTEGER, DIMENSION(knumfiles) :: &
-         & iobspos, &
-         & iobcpos
-      INTEGER :: iobs
-      INTEGER :: iobstot
-      INTEGER :: ios
-      INTEGER :: ioserrcount
-      CHARACTER(len=8) :: cl_refdate
-   
-      ! Local initialization
-      iobs = 0
-      IF ( PRESENT(ldobstd) ) THEN
-         IF (.NOT.ldmod) THEN
-            llobstd = .false.
-         ELSE
-            llobstd = ldobstd
-         ENDIF
-      ELSE
-         llobstd = .FALSE.
-      ENDIF
- 
-      !-----------------------------------------------------------------------
-      ! Check that the model part is just with feedback data files
-      !-----------------------------------------------------------------------
-      IF ( ldmod .AND. ( kformat /= 0 ) ) THEN
-         CALL ctl_stop( 'Model can only be read from feedback data' )
-         RETURN
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Check that the prescribed obs err is just with feedback data files
-      !-----------------------------------------------------------------------
-      IF ( llobstd .AND. ( kformat /= 0 ) ) THEN
-         CALL ctl_stop( 'Observation error can only be read from feedback files' )
-         RETURN
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Count the number of files needed and allocate the obfbdata type
-      !-----------------------------------------------------------------------
-      
-      inobf = knumfiles
-      
-      ALLOCATE( inpfiles(inobf) )
-
-      sla_files : DO jj = 1, inobf
-          
-         !---------------------------------------------------------------------
-         ! Prints
-         !---------------------------------------------------------------------
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) ' obs_rea_sla : Reading from file = ', &
-               & TRIM( TRIM( cfilenames(jj) ) )
-            WRITE(numout,*) ' ~~~~~~~~~~~'
-            WRITE(numout,*)
-         ENDIF
-
-         !---------------------------------------------------------------------
-         !  Initialization: Open file and get dimensions only
-         !---------------------------------------------------------------------
-         
-         iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
-            &                      i_file_id )
-         
-         IF ( iflag /= nf90_noerr ) THEN
-
-            IF ( ldignmis ) THEN
-               inpfiles(jj)%nobs = 0
-               CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ELSE 
-               CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ENDIF
-
-         ELSE 
-            
-            !------------------------------------------------------------------
-            !  Close the file since it is opened in read_proffile
-            !------------------------------------------------------------------
-            
-            iflag = nf90_close( i_file_id )
-
-            !------------------------------------------------------------------
-            !  Read the profile file into inpfiles
-            !------------------------------------------------------------------
-            IF ( kformat == 0 ) THEN
-               CALL init_obfbdata( inpfiles(jj) )
-               IF(lwp) THEN
-                  WRITE(numout,*)
-                  WRITE(numout,*)'Reading from feedback file :', &
-                     &           TRIM( cfilenames(jj) )
-               ENDIF
-               CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                ldgrid = .TRUE. )
-               IF ( inpfiles(jj)%nvar < 1 ) THEN
-                  CALL ctl_stop( 'Feedback format error' )
-                  RETURN
-               ENDIF
-               IF ( TRIM(inpfiles(jj)%cname(1)) /= 'SLA' ) THEN
-                  CALL ctl_stop( 'Feedback format error' )
-                  RETURN
-               ENDIF 
-               IF ( ldmod .AND. ( ( inpfiles(jj)%nadd == 0 ) .OR.&
-                  &               ( inpfiles(jj)%next == 0 ) ) ) THEN
-                  CALL ctl_stop( 'Model not in input data' )
-                  RETURN
-               ENDIF
-            ELSEIF ( kformat == 1) THEN
-               CALL read_avisofile( TRIM( cfilenames(jj) ), inpfiles(jj), &
-               &                    numout, lwp, .TRUE. )
-            ELSE
-               CALL ctl_stop( 'File format unknown' )
-            ENDIF
-
-            !------------------------------------------------------------------
-            !  Change longitude (-180,180)
-            !------------------------------------------------------------------
-
-            DO ji = 1, inpfiles(jj)%nobs 
-
-               IF ( inpfiles(jj)%plam(ji) < -180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) + 360.
-
-               IF ( inpfiles(jj)%plam(ji) >  180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) - 360.
-
-            END DO
-
-            !------------------------------------------------------------------
-            !  Calculate the date  (change eventually)
-            !------------------------------------------------------------------
-            cl_refdate=inpfiles(jj)%cdjuldref(1:8)
-            READ(cl_refdate,'(I8)') irefdate(jj)
-            
-            CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
-               &           krefdate = irefdate(jj) )
-            CALL ddatetoymdhms( ddobsend, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulend(jj), &
-               &           krefdate = irefdate(jj) )
-            IF ( inpfiles(jj)%nobs > 0 ) THEN
-               inpfiles(jj)%iproc = -1
-               inpfiles(jj)%iobsi = -1
-               inpfiles(jj)%iobsj = -1
-            ENDIF
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-               IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-               ENDIF
-            END DO
-            ALLOCATE( zlam(inowin)  )
-            ALLOCATE( zphi(inowin)  )
-            ALLOCATE( iobsi(inowin) )
-            ALLOCATE( iobsj(inowin) )
-            ALLOCATE( iproc(inowin) )
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-               IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  zlam(inowin) = inpfiles(jj)%plam(ji)
-                  zphi(inowin) = inpfiles(jj)%pphi(ji)
-               ENDIF
-            END DO
-
-            CALL obs_grid_search( inowin, zlam, zphi, iobsi, iobsj, iproc, 'T' )
-
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-               IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  inpfiles(jj)%iproc(ji,1) = iproc(inowin)
-                  inpfiles(jj)%iobsi(ji,1) = iobsi(inowin)
-                  inpfiles(jj)%iobsj(ji,1) = iobsj(inowin)
-               ENDIF
-            END DO
-            DEALLOCATE( zlam, zphi, iobsi, iobsj, iproc )
-
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-               IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  IF ( nproc == 0 ) THEN
-                     IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-                  ELSE
-                     IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-                  ENDIF
-                  llvalprof = .FALSE.
-                  IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-                     & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
-                     iobs = iobs + 1
-                  ENDIF
-               ENDIF
-            END DO
-
-         ENDIF
-      
-      END DO sla_files
-
-      IF (llobstd) THEN
-         
-         DO jj = 1, inobf
-            iobspos(jj) = -1
-            iobcpos(jj) = -1
-            DO ji = 1,inpfiles(jj)%nadd
-               IF ( TRIM(inpfiles(jj)%caddname(ji)) == 'OSTD' ) THEN
-                  iobspos(jj)=ji
-               ENDIF
-               IF ( TRIM(inpfiles(jj)%caddname(ji)) == 'OCNT' ) THEN
-                  iobcpos(jj)=ji
-               ENDIF
-            END DO
-         END DO
-         llobstd = ( ( MINVAL(iobspos) > 0 ) .AND. ( MINVAL(iobcpos) > 0 ) )
-         IF (llobstd) THEN
-            IF (lwp) WRITE(numout,*)'SLA superobs information present.'
-         ELSE
-            IF (lwp) WRITE(numout,*)'SLA superobs information not present.'
-         ENDIF
-
-      ENDIF
-      
-      !-----------------------------------------------------------------------
-      ! Get the time ordered indices of the input data
-      !-----------------------------------------------------------------------
-
-      !---------------------------------------------------------------------
-      !  Loop over input data files to count total number of profiles
-      !---------------------------------------------------------------------
-      iobstot = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-            IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               iobstot = iobstot + 1
-            ENDIF
-         END DO
-      END DO
-
-      ALLOCATE( iindx(iobstot), ifileidx(iobstot), &
-         &      islaidx(iobstot), zdat(iobstot) )
-      jk = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-            IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               jk = jk + 1
-               ifileidx(jk) = jj
-               islaidx(jk) = ji
-               zdat(jk)     = inpfiles(jj)%ptim(ji)
-            ENDIF
-         END DO
-      END DO
-      CALL sort_dp_indx( iobstot, &
-         &               zdat,     &
-         &               iindx   )
-      
-      CALL obs_surf_alloc( sladata, iobs, kvars, kextr, kstp, jpi, jpj )
-      
-      ! * Read obs/positions, QC, all variable and assign to sladata
- 
-      iobs = 0
-
-      ityp   (:) = 0
-      itypmpp(:) = 0
-
-      ioserrcount = 0
-      
-      DO jk = 1, iobstot
-         
-         jj = ifileidx(iindx(jk))
-         ji = islaidx(iindx(jk))
-
-         IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-         IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-
-         IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
-            & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
-            
-            IF ( nproc == 0 ) THEN
-               IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-            ELSE
-               IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-            ENDIF
-            
-            ! Set observation information
-            
-            IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-               & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
-
-               iobs = iobs + 1
-
-               CALL jul2greg( isec,                   &
-                  &           imin,                   &
-                  &           ihou,                   &
-                  &           iday,                   &
-                  &           imon,                   &
-                  &           iyea,                   &
-                  &           inpfiles(jj)%ptim(ji), &
-                  &           irefdate(jj) )
-
-
-               ! SLA time coordinates
-               sladata%nyea(iobs) = iyea
-               sladata%nmon(iobs) = imon
-               sladata%nday(iobs) = iday
-               sladata%nhou(iobs) = ihou
-               sladata%nmin(iobs) = imin
-               
-               ! SLA space coordinates
-               sladata%rlam(iobs) = inpfiles(jj)%plam(ji)
-               sladata%rphi(iobs) = inpfiles(jj)%pphi(ji)
-
-               ! Coordinate search parameters
-               sladata%mi  (iobs) = inpfiles(jj)%iobsi(ji,1)
-               sladata%mj  (iobs) = inpfiles(jj)%iobsj(ji,1)
-               
-               ! Instrument type
-               READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
-901            IF ( ios /= 0 ) THEN
-                  IF (ioserrcount == 0) CALL ctl_warn ( 'Problem converting an instrument type to integer. Setting type to zero' ) 
-                  ioserrcount = ioserrcount + 1
-                  itype = 0
-               ENDIF
-               sladata%ntyp(iobs) = itype
-               ityp(itype+1) = ityp(itype+1) + 1
-
-               ! Identifier
-               sladata%cwmo(iobs) = inpfiles(jj)%cdwmo(ji)
-
-               ! Bookkeeping data to match observations
-               sladata%nsidx(iobs) = iobs
-               sladata%nsfil(iobs) = iindx(jk)
-
-               ! QC flags
-               sladata%nqc(iobs) = inpfiles(jj)%ivqc(ji,1)
-
-               ! Observed value
-               sladata%robs(iobs,1) = inpfiles(jj)%pob(1,ji,1)
-
-
-               ! Model and MDT is set to fbrmdi unless read from file
-               IF ( ldmod ) THEN
-                  sladata%rmod(iobs,1) = inpfiles(jj)%padd(1,ji,1,1)
-                  sladata%rext(iobs,1) = inpfiles(jj)%padd(1,ji,2,1)
-                  sladata%rext(iobs,2) = inpfiles(jj)%pext(1,ji,1)
-                  IF (llobstd) THEN
-                     sladata%rext(iobs,3) = &
-                        & inpfiles(jj)%padd(1,ji,iobspos(jj),1)
-                     sladata%rext(iobs,4) = &
-                        & inpfiles(jj)%padd(1,ji,iobcpos(jj),1)
-                  ENDIF
-               ELSE
-                  sladata%rmod(iobs,1) = fbrmdi
-                  sladata%rext(iobs,:) = fbrmdi
-               ENDIF
-
-            ENDIF
-         ENDIF
-
-      END DO
-
-      !-----------------------------------------------------------------------
-      ! Sum up over processors
-      !-----------------------------------------------------------------------
-      
-      CALL obs_mpp_sum_integer( iobs, iobsmpp )
-      CALL obs_mpp_sum_integers( ityp, itypmpp, imaxmissions + 1 )
-      
-      !-----------------------------------------------------------------------
-      ! Output number of observations.
-      !-----------------------------------------------------------------------
-      IF (lwp) THEN
-
-         WRITE(numout,*)
-         WRITE(numout,'(1X,A)')'Altimeter satellites'
-         WRITE(numout,'(1X,A)')'--------------------'
-         DO jj = 1,8
-            IF ( itypmpp(jj) > 0 ) THEN
-               WRITE(numout,'(1X,A38,A2,I10)')calttyp(jj-1),'= ',itypmpp(jj)
-            ENDIF
-         END DO
-         WRITE(numout,'(1X,A50)')'--------------------------------------------------'
-         WRITE(numout,'(1X,A40,I10)')'Total                                 = ',iobsmpp
-         WRITE(numout,*)
-
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Deallocate temporary data
-      !-----------------------------------------------------------------------
-      DEALLOCATE( ifileidx, islaidx, zdat )
-
-      !-----------------------------------------------------------------------
-      ! Deallocate input data
-      !-----------------------------------------------------------------------
-      DO jj = 1, inobf
-         CALL dealloc_obfbdata( inpfiles(jj) )
-      END DO
-      DEALLOCATE( inpfiles )
-
-      !-----------------------------------------------------------------------
-      ! Reset ldobstd if the data is present
-      !-----------------------------------------------------------------------
-      IF ( PRESENT(ldobstd) ) THEN
-         ldobstd = llobstd
-      ENDIF
-
-   END SUBROUTINE obs_rea_sla
-
-END MODULE obs_read_sla
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sst.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sst.F90	(revision 6139)
+++ 	(revision )
@@ -1,771 +1,0 @@
-MODULE obs_read_sst
-   !!======================================================================
-   !!                       ***  MODULE obs_read_sst  ***
-   !! Observation diagnostics: Read the SST data from the GHRSST database 
-   !!                          or any SST data from feedback files
-   !!======================================================================
-
-   !!----------------------------------------------------------------------
-   !!   obs_rea_sst : Driver for reading SST data from the GHRSST/feedback
-   !!   obs_rea_sst_rey : Driver for reading SST data from Reynolds
-   !!----------------------------------------------------------------------
-
-   !! * Modules used   
-   USE par_kind                 ! Precision variables
-   USE in_out_manager           ! I/O manager
-   USE dom_oce                  ! Ocean space and time domain variables
-   USE obs_mpp                  ! MPP support routines for observation diagnostics
-   USE julian                   ! Julian date routines
-   USE obs_utils                ! Observation operator utility functions
-   USE obs_grid                 ! Grid search
-   USE obs_sort                 ! Sorting observation arrays
-   USE obs_surf_def             ! Surface observation definitions
-   USE obs_types                ! Observation type definitions
-   USE obs_sst_io               ! I/O for sst files
-   USE iom                      ! I/O of fields for Reynolds data
-   USE netcdf                   ! NetCDF library
-
-   IMPLICIT NONE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC obs_rea_sst      ! Read the SST observations from the point data
-   PUBLIC obs_rea_sst_rey  ! Read the gridded Reynolds SST 
-   
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE obs_rea_sst( kformat, &
-      &                    sstdata, knumfiles, cfilenames, &
-      &                    kvars, kextr, kstp, ddobsini, ddobsend, &
-      &                    ldignmis, ldmod )
-      !!---------------------------------------------------------------------
-      !!
-      !!                   *** ROUTINE obs_rea_sst ***
-      !!
-      !! ** Purpose : Read from file the SST data
-      !!
-      !! ** Method  : Depending on kformat either AVISO or
-      !!              feedback data files are read
-      !!
-      !! ** Action  : 
-      !!
-      !!
-      !! History :  
-      !!      ! :  2009-01 (K. Mogensen) Initial version based on old versions
-      !!----------------------------------------------------------------------
-      !! * Modules used
-
-      !! * Arguments
-      INTEGER :: kformat   ! Format of input data
-      !                    ! 0: Feedback
-      !                    ! 1: GHRSST
-      TYPE(obs_surf), INTENT(INOUT) :: sstdata   ! SST data to be read
-      INTEGER, INTENT(IN) :: knumfiles    ! Number of corio format files to read in
-      CHARACTER(LEN=128), INTENT(IN) :: cfilenames(knumfiles) ! File names to read in
-      INTEGER, INTENT(IN) :: kvars      ! Number of variables in sstdata
-      INTEGER, INTENT(IN) :: kextr      ! Number of extra fields for each var in sstdata
-      INTEGER, INTENT(IN) :: kstp       ! Ocean time-step index
-      LOGICAL, INTENT(IN) :: ldignmis   ! Ignore missing files
-      LOGICAL, INTENT(IN) :: ldmod      ! Initialize model from input data
-      REAL(KIND=dp), INTENT(IN) :: ddobsini   ! Obs. ini time in YYYYMMDD.HHMMSS
-      REAL(KIND=dp), INTENT(IN) :: ddobsend   ! Obs. end time in YYYYMMDD.HHMMSS
-         
-      !! * Local declarations
-      CHARACTER(LEN=11), PARAMETER :: cpname='obs_rea_sst'
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jk
-      INTEGER :: iflag
-      INTEGER :: inobf
-      INTEGER :: i_file_id
-      INTEGER :: inowin
-      INTEGER :: iyea
-      INTEGER :: imon
-      INTEGER :: iday
-      INTEGER :: ihou
-      INTEGER :: imin
-      INTEGER :: isec
-      INTEGER, DIMENSION(knumfiles) :: irefdate
-      INTEGER :: iobsmpp
-      INTEGER, PARAMETER :: isstmaxtype = 1024
-      INTEGER, DIMENSION(0:isstmaxtype) :: &
-         & ityp, &
-         & itypmpp
-      INTEGER, DIMENSION(:), ALLOCATABLE :: &
-         & iobsi,    &
-         & iobsj,    &
-         & iproc,    &
-         & iindx,    &
-         & ifileidx, &
-         & isstidx
-      INTEGER :: itype
-      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zphi, &
-         & zlam
-      real(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zdat
-      LOGICAL :: llvalprof
-      TYPE(obfbdata), POINTER, DIMENSION(:) :: &
-         & inpfiles
-      real(wp), DIMENSION(knumfiles) :: &
-         & djulini, &
-         & djulend
-      INTEGER :: iobs
-      INTEGER :: iobstot
-      INTEGER :: ios
-      INTEGER :: ioserrcount
-      CHARACTER(len=8) :: cl_refdate
-   
-      ! Local initialization
-      iobs = 0
- 
-      !-----------------------------------------------------------------------
-      ! Check data the model part is just with feedback data files
-      !-----------------------------------------------------------------------
-      IF ( ldmod .AND. ( kformat /= 0 ) ) THEN
-         CALL ctl_stop( 'Model can only be read from feedback data' )
-         RETURN
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Count the number of files needed and allocate the obfbdata type
-      !-----------------------------------------------------------------------
-      
-      inobf = knumfiles
-      
-      ALLOCATE( inpfiles(inobf) )
-
-      sst_files : DO jj = 1, inobf
-
-         CALL init_obfbdata( inpfiles(jj) )
-          
-         !---------------------------------------------------------------------
-         ! Prints
-         !---------------------------------------------------------------------
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) ' obs_rea_sst : Reading from file = ', &
-               & TRIM( TRIM( cfilenames(jj) ) )
-            WRITE(numout,*) ' ~~~~~~~~~~~'
-            WRITE(numout,*)
-         ENDIF
-
-         !---------------------------------------------------------------------
-         !  Initialization: Open file and get dimensions only
-         !---------------------------------------------------------------------
-         
-         iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
-            &                      i_file_id )
-         
-         IF ( iflag /= nf90_noerr ) THEN
-
-            IF ( ldignmis ) THEN
-               inpfiles(jj)%nobs = 0
-               CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ELSE 
-               CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ENDIF
-
-         ELSE 
-            
-            !------------------------------------------------------------------
-            !  Close the file since it is opened in read_proffile
-            !------------------------------------------------------------------
-            
-            iflag = nf90_close( i_file_id )
-
-            !------------------------------------------------------------------
-            !  Read the profile file into inpfiles
-            !------------------------------------------------------------------
-            IF ( kformat == 0 ) THEN
-               IF(lwp) THEN
-                  WRITE(numout,*)
-                  WRITE(numout,*)'Reading from feedback file :', &
-                     &           TRIM( cfilenames(jj) )
-               ENDIF
-               CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                ldgrid = .TRUE. )
-               IF ( ldmod .AND. ( inpfiles(jj)%nadd == 0 ) ) THEN
-                  CALL ctl_stop( 'Model not in input data' )
-                  RETURN
-               ENDIF
-            ELSEIF ( kformat == 1) THEN
-               CALL read_ghrsst( TRIM( cfilenames(jj) ), inpfiles(jj), &
-               &                 numout, lwp, .TRUE. )
-            ELSE
-               CALL ctl_stop( 'File format unknown' )
-            ENDIF
-
-            !------------------------------------------------------------------
-            !  Change longitude (-180,180)
-            !------------------------------------------------------------------
-
-            DO ji = 1, inpfiles(jj)%nobs 
-
-               IF ( inpfiles(jj)%plam(ji) < -180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) + 360.
-
-               IF ( inpfiles(jj)%plam(ji) >  180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) - 360.
-
-            END DO
-
-            !------------------------------------------------------------------
-            !  Calculate the date  (change eventually)
-            !------------------------------------------------------------------
-            cl_refdate=inpfiles(jj)%cdjuldref(1:8)
-            READ(cl_refdate,'(I8)') irefdate(jj)
-            
-            CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
-               &           krefdate = irefdate(jj) )
-            CALL ddatetoymdhms( ddobsend, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulend(jj), &
-               &           krefdate = irefdate(jj) )
-            IF ( inpfiles(jj)%nobs > 0 ) THEN
-               inpfiles(jj)%iproc = -1
-               inpfiles(jj)%iobsi = -1
-               inpfiles(jj)%iobsj = -1
-            ENDIF
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-               ENDIF
-            END DO
-            ALLOCATE( zlam(inowin)  )
-            ALLOCATE( zphi(inowin)  )
-            ALLOCATE( iobsi(inowin) )
-            ALLOCATE( iobsj(inowin) )
-            ALLOCATE( iproc(inowin) )
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  zlam(inowin) = inpfiles(jj)%plam(ji)
-                  zphi(inowin) = inpfiles(jj)%pphi(ji)
-               ENDIF
-            END DO
-
-            CALL obs_grid_search( inowin, zlam, zphi, iobsi, iobsj, iproc, 'T' )
-
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  inpfiles(jj)%iproc(ji,1) = iproc(inowin)
-                  inpfiles(jj)%iobsi(ji,1) = iobsi(inowin)
-                  inpfiles(jj)%iobsj(ji,1) = iobsj(inowin)
-               ENDIF
-            END DO
-            DEALLOCATE( zlam, zphi, iobsi, iobsj, iproc )
-
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  IF ( nproc == 0 ) THEN
-                     IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-                  ELSE
-                     IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-                  ENDIF
-                  llvalprof = .FALSE.
-                  IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-                     & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
-                     iobs = iobs + 1
-                  ENDIF
-               ENDIF
-            END DO
-
-         ENDIF
-
-      END DO sst_files
-
-      !-----------------------------------------------------------------------
-      ! Get the time ordered indices of the input data
-      !-----------------------------------------------------------------------
-
-      !---------------------------------------------------------------------
-      !  Loop over input data files to count total number of profiles
-      !---------------------------------------------------------------------
-      iobstot = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               iobstot = iobstot + 1
-            ENDIF
-         END DO
-      END DO
-
-      ALLOCATE( iindx(iobstot), ifileidx(iobstot), &
-         &      isstidx(iobstot), zdat(iobstot) )
-      jk = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               jk = jk + 1
-               ifileidx(jk) = jj
-               isstidx(jk) = ji
-               zdat(jk)     = inpfiles(jj)%ptim(ji)
-            ENDIF
-         END DO
-      END DO
-      CALL sort_dp_indx( iobstot, &
-         &               zdat,     &
-         &               iindx   )
-      
-      CALL obs_surf_alloc( sstdata, iobs, kvars, kextr, kstp, jpi, jpj )
-      
-      ! * Read obs/positions, QC, all variable and assign to sstdata
- 
-      iobs = 0
-
-      ityp   (:) = 0
-      itypmpp(:) = 0
-      
-      ioserrcount = 0
-      
-      DO jk = 1, iobstot
-         
-         jj = ifileidx(iindx(jk))
-         ji = isstidx(iindx(jk))
-         IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
-            & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
-            
-            IF ( nproc == 0 ) THEN
-               IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-            ELSE
-               IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-            ENDIF
-            
-            ! Set observation information
-            
-            IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-               & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
-
-               iobs = iobs + 1
-
-               CALL jul2greg( isec,                   &
-                  &           imin,                   &
-                  &           ihou,                   &
-                  &           iday,                   &
-                  &           imon,                   &
-                  &           iyea,                   &
-                  &           inpfiles(jj)%ptim(ji), &
-                  &           irefdate(jj) )
-
-
-               ! SST time coordinates
-               sstdata%nyea(iobs) = iyea
-               sstdata%nmon(iobs) = imon
-               sstdata%nday(iobs) = iday
-               sstdata%nhou(iobs) = ihou
-               sstdata%nmin(iobs) = imin
-               
-               ! SST space coordinates
-               sstdata%rlam(iobs) = inpfiles(jj)%plam(ji)
-               sstdata%rphi(iobs) = inpfiles(jj)%pphi(ji)
-
-               ! Coordinate search parameters
-               sstdata%mi  (iobs) = inpfiles(jj)%iobsi(ji,1)
-               sstdata%mj  (iobs) = inpfiles(jj)%iobsj(ji,1)
-               
-               ! Instrument type
-               READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
-901            IF ( ios /= 0 ) THEN
-                  IF (ioserrcount == 0) CALL ctl_warn ( 'Problem converting an instrument type to integer. Setting type to zero' ) 
-                  ioserrcount = ioserrcount + 1
-                  itype = 0
-               ENDIF
-               sstdata%ntyp(iobs) = itype
-               IF ( itype < isstmaxtype + 1 ) THEN
-                  ityp(itype+1) = ityp(itype+1) + 1
-               ELSE
-                  IF(lwp)WRITE(numout,*)'WARNING:Increase isstmaxtype in ',&
-                     &                  cpname
-               ENDIF
-
-               ! Bookkeeping data to match observations
-               sstdata%nsidx(iobs) = iobs
-               sstdata%nsfil(iobs) = iindx(jk)
-
-               ! QC flags
-               sstdata%nqc(iobs) = inpfiles(jj)%ivqc(ji,1)
-
-               ! Observed value
-               sstdata%robs(iobs,1) = inpfiles(jj)%pob(1,ji,1)
-
-
-               ! Model and MDT is set to fbrmdi unless read from file
-               IF ( ldmod ) THEN
-                  sstdata%rmod(iobs,1) = inpfiles(jj)%padd(1,ji,1,1)
-               ELSE
-                  sstdata%rmod(iobs,1) = fbrmdi
-               ENDIF
-            ENDIF
-         ENDIF
-
-      END DO
-
-      !-----------------------------------------------------------------------
-      ! Sum up over processors
-      !-----------------------------------------------------------------------
-      
-      CALL obs_mpp_sum_integer( iobs, iobsmpp )
-      
-      !-----------------------------------------------------------------------
-      ! Output number of observations.
-      !-----------------------------------------------------------------------
-      IF (lwp) THEN
-
-         WRITE(numout,*)
-         WRITE(numout,'(1X,A)')'SST data types'
-         WRITE(numout,'(1X,A)')'--------------'
-         DO jj = 1,8
-            IF ( itypmpp(jj) > 0 ) THEN
-               WRITE(numout,'(1X,A4,I4,A3,I10)')'Type ', jj,' = ',itypmpp(jj)
-            ENDIF
-         END DO
-         WRITE(numout,'(1X,A50)')'--------------------------------------------------'
-         WRITE(numout,'(1X,A40,I10)')'Total                                 = ',iobsmpp
-         WRITE(numout,*)
-
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Deallocate temporary data
-      !-----------------------------------------------------------------------
-      DEALLOCATE( ifileidx, isstidx, zdat )
-
-      !-----------------------------------------------------------------------
-      ! Deallocate input data
-      !-----------------------------------------------------------------------
-      DO jj = 1, inobf
-         IF ( inpfiles(jj)%lalloc ) THEN
-            CALL dealloc_obfbdata( inpfiles(jj) )
-         ENDIF
-      END DO
-      DEALLOCATE( inpfiles )
-
-   END SUBROUTINE obs_rea_sst
-
-   SUBROUTINE obs_rea_sst_rey( sstname, cdsstfmt, sstdata, kvars, kextra, &
-      &                        kstp, ddobsini, ddobsend )
-      !!---------------------------------------------------------------------
-      !!
-      !!                   *** ROUTINE obs_rea_sst ***
-      !!
-      !! ** Purpose : Read from file the pseudo SST data from Reynolds
-      !!
-      !! ** Method  : 
-      !!
-      !! ** Action  : 
-      !!
-      !! References : 
-      !!
-      !! History :  
-      !!      ! :  
-      !!----------------------------------------------------------------------
-      !! * Modules used
-      USE par_oce          ! Ocean parameters
-   
-      !! * Arguments
-      CHARACTER(len=128), INTENT(IN) :: sstname   ! Generic file name
-      CHARACTER(len=12), INTENT(IN) :: cdsstfmt   ! Format of SST files (yearly/monthly)
-      TYPE(obs_surf), INTENT(INOUT) :: sstdata    ! SST data
-      REAL(KIND=dp), INTENT(IN) :: ddobsini    ! Obs. ini time in YYYYMMDD.HHMMSS
-      REAL(KIND=dp), INTENT(IN) :: ddobsend    ! Obs. end time in YYYYMMDD.HHMMSS
-      INTEGER, INTENT(IN) :: kvars      ! Number of variables in sstdata structures
-      INTEGER, INTENT(IN) :: kextra     ! Number of extra variables in sstdata structures
-      INTEGER, INTENT(IN) :: kstp       ! Ocean time-step index
-      
-      INTEGER :: iyear
-      INTEGER :: imon
-      INTEGER :: iday
-      INTEGER :: ihour
-      INTEGER :: imin
-      INTEGER :: isec
-      INTEGER :: ihhmmss
-      INTEGER :: iyear1
-      INTEGER :: iyear2
-      INTEGER :: imon1
-      INTEGER :: imon2
-      INTEGER :: iyearf
-      INTEGER :: imonf
-      REAL(KIND=wp) :: pjulini
-      REAL(KIND=wp) :: pjulend
-      REAL(KIND=wp) :: pjulb
-      REAL(KIND=wp) :: pjule
-      REAL(KIND=wp) :: pjul
-      INTEGER :: inumsst
-      INTEGER :: itotrec
-      INTEGER :: inumobs
-      INTEGER :: irec
-      INTEGER :: ifld
-      INTEGER :: inum
-      INTEGER :: ji, jj
-      CHARACTER(len=128) :: clname
-      CHARACTER(len=4) :: cdyear
-      CHARACTER(len=2) :: cdmon
-      REAL(kind=wp), ALLOCATABLE, DIMENSION(:,:,:) :: zsstin
-
-      IF (lwp) WRITE(numout,*)'In obs_rea_sst_rey',sstname
-
-      !-----------------------------------------------------------------------
-      ! Convert observation window to julian dates.
-      !-----------------------------------------------------------------------
-      iyear1 = NINT( ddobsini / 10000 )
-      imon1 = NINT( ( ddobsini - iyear1 * 10000 ) / 100 )
-      iday = MOD( NINT( ddobsini ), 100 )
-      ihhmmss = ( ddobsini - NINT( ddobsini ) ) * 1000000
-      ihour = ihhmmss / 10000
-      imin = ( ihhmmss - ihour * 100 ) / 100
-      isec = MOD( ihhmmss, 100 )
-      CALL greg2jul ( isec, imin, ihour, iday, imon1, iyear1, pjulini )
-      IF (lwp) WRITE(numout,*)'dateini',ddobsini,iyear1,imon1,iday,ihour, &
-         & imin,isec,pjulini
-
-      iyear2 = NINT( ddobsini / 10000 )
-      imon2 = NINT( ( ddobsend - iyear2 * 10000 ) / 100 )
-      iday = MOD( NINT( ddobsend ), 100 )
-      ihhmmss = ( ddobsend - NINT( ddobsend ) ) * 1000000
-      ihour = ihhmmss / 10000
-      imin = ( ihhmmss - ihour * 100 ) / 100
-      isec = MOD( ihhmmss, 100 )
-      CALL greg2jul ( isec, imin, ihour, iday, imon2, iyear2, pjulend )
-      IF (lwp) WRITE(numout,*)'dateend',ddobsend,iyear2,imon2,iday,ihour, &
-         & imin,isec,pjulend
-
-      itotrec = NINT( pjulend - pjulini ) 
-      ALLOCATE( &
-         & zsstin( jpi, jpj, itotrec) &
-         & )
-      
-      pjul = pjulini + 1
-      
-      iyearf = -1 
-      imonf = -1
-
-      IF ( TRIM(cdsstfmt) == 'yearly' ) THEN
-
-         DO
-         
-            CALL jul2greg( isec, imin, ihour, iday, imon, iyear, &
-               &           pjul, 19500101 )
-            !
-            IF ( iyear /= iyearf ) THEN
-               
-               CALL greg2jul ( 0, 0, 0, 1, 1, iyear, pjulb )
-               
-               IF ( iyearf /= -1 ) THEN
-                  
-                  CALL iom_close ( inumsst )      
-                  
-               ENDIF
-               
-               clname = sstname
-               jj = INDEX( clname, 'YYYY' )
-               
-               IF ( jj == 0 ) THEN
-                  
-                  CALL ctl_stop( 'obs_rea_sst_rey : ', &
-                  &           'Error processing filename ' // TRIM(sstname) )
-                  
-               ENDIF
-               
-               WRITE(cdyear,'(I4.4)') iyear
-               clname(jj:jj+3) = cdyear
-               IF(lwp) WRITE(numout,*)'Reading from Reynolds SST file : ',&
-                  & TRIM(clname)
-               
-               inumsst = 0
-               
-               CALL iom_open ( clname, inumsst )
-               
-               IF ( inumsst == 0 ) THEN
-                  
-                  CALL ctl_stop( 'obs_rea_sst_rey : ', &
-                     &           'Error reading ' // TRIM(clname) )
-                  
-               ENDIF
-               
-               iyearf = iyear
-               
-            ENDIF
-            
-            irec = pjul - pjulb + 1
-            ifld = pjul - pjulini
-            
-            CALL iom_get ( inumsst, jpdom_data, 'sst', zsstin(:,:,ifld), irec )
-            
-            pjul = pjul + 1
-            
-            IF ( pjul > pjulend ) EXIT
-         
-         END DO
-
-      ELSEIF ( TRIM(cdsstfmt) == 'monthly' ) THEN
-
-         DO
-         
-            CALL jul2greg( isec, imin, ihour, iday, imon, iyear, &
-               &           pjul, 19500101 )
-            !
-            IF ( iyear /= iyearf .OR. imon /= imonf ) THEN
-               
-               CALL greg2jul ( 0, 0, 0, 1, imon, iyear, pjulb )
-               
-               IF ( iyearf /= -1 .AND. imonf /= -1 ) THEN
-                  
-                  CALL iom_close ( inumsst )      
-                  
-               ENDIF
-               
-               clname = sstname
-
-               jj = INDEX( clname, 'YYYY' )
-
-               IF ( jj == 0 ) THEN
-                  
-                  CALL ctl_stop( 'obs_rea_sst_rey : ', &
-                  &           'Error processing filename ' // TRIM(sstname) )
-                  
-               ENDIF
-               
-               WRITE(cdyear,'(I4.4)') iyear
-               clname(jj:jj+3) = cdyear
-
-               jj = INDEX( clname, 'MM' )
-               
-               IF ( jj == 0 ) THEN
-                  
-                  CALL ctl_stop( 'obs_rea_sst_rey : ', &
-                  &           'Error processing filename ' // TRIM(sstname) )
-                  
-               ENDIF
-               
-               WRITE(cdmon,'(I2.2)') imon
-               clname(jj:jj+1) = cdmon
-
-
-               IF(lwp) WRITE(numout,*)'Reading from Reynolds SST file : ',&
-                  & TRIM(clname)
-               
-               inumsst = 0
-               
-               CALL iom_open ( clname, inumsst )
-               
-               IF ( inumsst == 0 ) THEN
-                  
-                  CALL ctl_stop( 'obs_rea_sst_rey : ', &
-                     &           'Error reading ' // TRIM(clname) )
-                  
-               ENDIF
-               
-               iyearf = iyear
-               imonf = iyear
-               
-            ENDIF
-            
-            irec = pjul - pjulb + 1
-            ifld = pjul - pjulini
-            
-            CALL iom_get ( inumsst, jpdom_data, 'sst', zsstin(:,:,ifld), irec )
-            
-            pjul = pjul + 1
-            
-            IF ( pjul > pjulend ) EXIT
-         
-         END DO
-
-      ELSE
-         
-         CALL ctl_stop('Unknown REYNOLDS sst input data file format')
-
-      ENDIF
-
-      CALL iom_close ( inumsst )      
-
-      inumobs = 0
-      DO jj = nldj, nlej
-         DO ji = nldi, nlei
-            IF ( tmask(ji,jj,1) == 1.0_wp ) inumobs = inumobs + 1
-         END DO
-      END DO
-      inumobs = inumobs * itotrec
-
-      ! Allocate obs_surf data structure for time sorted data
-         
-      CALL obs_surf_alloc( sstdata, inumobs, kvars, kextra, kstp, jpi, jpj )
-
-      pjul = pjulini + 1
-
-      inumobs = 0
-
-      DO
-
-         CALL jul2greg( isec, imin, ihour, iday, imon, iyear, &
-            &           pjul, 19500101 )
-
-         ifld = pjul - pjulini
-
-         DO jj = nldj, nlej
-            DO ji = nldi, nlei
-
-               IF ( tmask(ji,jj,1) == 1.0_wp ) THEN
-
-                  inumobs = inumobs + 1
-                  
-                  ! Integer values
-                  IF (ln_grid_global) THEN
-                     sstdata%mi(inumobs)     = MAX(mig(ji),2)
-                     sstdata%mj(inumobs)     = MAX(mjg(jj),2)
-                  ELSE
-                     sstdata%mi(inumobs)     = MAX(ji,2)
-                     sstdata%mj(inumobs)     = MAX(jj,2)
-                  ENDIF
-                  sstdata%nsidx(inumobs)  = 0
-                  sstdata%nsfil(inumobs)  = 0
-                  sstdata%nyea(inumobs)   = iyear
-                  sstdata%nmon(inumobs)   = imon
-                  sstdata%nday(inumobs)   = iday
-                  sstdata%nhou(inumobs)   = ihour
-                  sstdata%nmin(inumobs)   = imin
-                  sstdata%mstp(inumobs)   = 0
-                  sstdata%nqc(inumobs)    = 0
-                  sstdata%ntyp(inumobs)   = 0
-         
-                  ! Real values
-                  sstdata%rlam(inumobs)   = glamt(ji,jj)
-                  sstdata%rphi(inumobs)   = gphit(ji,jj)
-                  sstdata%robs(inumobs,1) = zsstin(ji,jj,ifld)
-                  sstdata%rmod(inumobs,1) = fbrmdi
-                  sstdata%rext(inumobs,:) = fbrmdi
-
-               ENDIF
-
-            END DO
-         END DO
-
-         pjul = pjul + 1
-
-         IF ( pjul > pjulend ) EXIT
-
-      END DO
-
-   END SUBROUTINE obs_rea_sst_rey
-
-END MODULE obs_read_sst
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_surf.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_surf.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_surf.F90	(revision 6140)
@@ -0,0 +1,498 @@
+MODULE obs_read_surf
+   !!======================================================================
+   !!                       ***  MODULE obs_read_surf  ***
+   !! Observation diagnostics: Read the surface data from feedback files
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   obs_rea_surf : Driver for reading surface data from feedback files
+   !!----------------------------------------------------------------------
+
+   !! * Modules used
+   USE par_kind                 ! Precision variables
+   USE in_out_manager           ! I/O manager
+   USE dom_oce                  ! Ocean space and time domain variables
+   USE obs_mpp                  ! MPP support routines for observation diagnostics
+   USE julian                   ! Julian date routines
+   USE obs_utils                ! Observation operator utility functions
+   USE obs_grid                 ! Grid search
+   USE obs_sort                 ! Sorting observation arrays
+   USE obs_surf_def             ! Surface observation definitions
+   USE obs_types                ! Observation type definitions
+   USE obs_fbm                  ! Feedback routines
+   USE netcdf                   ! NetCDF library
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+
+   PUBLIC obs_rea_surf      ! Read the surface observations from the point data
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: obs_read_surf.F90 4990 2014-12-15 16:42:49Z timgraham $
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obs_rea_surf( surfdata, knumfiles, cdfilenames, &
+      &                     kvars, kextr, kstp, ddobsini, ddobsend, &
+      &                     ldignmis, ldmod, ldnightav )
+      !!---------------------------------------------------------------------
+      !!
+      !!                   *** ROUTINE obs_rea_surf ***
+      !!
+      !! ** Purpose : Read from file the surface data
+      !!
+      !! ** Method  : Read in the data from feedback format files and 
+      !!              put into the NEMO internal surface data structure
+      !!
+      !! ** Action  : 
+      !!
+      !!
+      !! History :  
+      !!      ! :  2009-01 (K. Mogensen) Initial version based on old versions
+      !!      ! :  2015-02 (M. Martin)   Unify the different surface data type reading.
+      !!----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      TYPE(obs_surf), INTENT(INOUT) :: &
+         & surfdata                     ! Surface data to be read
+      INTEGER, INTENT(IN) :: knumfiles  ! Number of corio format files to read
+      CHARACTER(LEN=128), INTENT(IN) :: &
+         & cdfilenames(knumfiles)       ! File names to read in
+      INTEGER, INTENT(IN) :: kvars      ! Number of variables in surfdata
+      INTEGER, INTENT(IN) :: kextr      ! Number of extra fields for each var
+      INTEGER, INTENT(IN) :: kstp       ! Ocean time-step index
+      LOGICAL, INTENT(IN) :: ldignmis   ! Ignore missing files
+      LOGICAL, INTENT(IN) :: ldmod      ! Initialize model from input data
+      LOGICAL, INTENT(IN) :: ldnightav  ! Observations represent a night-time average
+      REAL(dp), INTENT(IN) :: ddobsini   ! Obs. ini time in YYYYMMDD.HHMMSS
+      REAL(dp), INTENT(IN) :: ddobsend   ! Obs. end time in YYYYMMDD.HHMMSS
+
+      !! * Local declarations
+      CHARACTER(LEN=11), PARAMETER :: cpname='obs_rea_surf'
+      CHARACTER(len=8) :: clrefdate
+      CHARACTER(len=6), DIMENSION(:), ALLOCATABLE :: clvars
+      INTEGER :: ji
+      INTEGER :: jj
+      INTEGER :: jk
+      INTEGER :: iflag
+      INTEGER :: inobf
+      INTEGER :: i_file_id
+      INTEGER :: inowin
+      INTEGER :: iyea
+      INTEGER :: imon
+      INTEGER :: iday
+      INTEGER :: ihou
+      INTEGER :: imin
+      INTEGER :: isec
+      INTEGER :: itype
+      INTEGER :: iobsmpp
+      INTEGER :: iobs
+      INTEGER :: iobstot
+      INTEGER :: ios
+      INTEGER :: ioserrcount
+      INTEGER, PARAMETER :: jpsurfmaxtype = 1024
+      INTEGER, DIMENSION(knumfiles) :: irefdate
+      INTEGER, DIMENSION(jpsurfmaxtype+1) :: &
+         & ityp, &
+         & itypmpp
+      INTEGER, DIMENSION(:), ALLOCATABLE :: &
+         & iobsi,    &
+         & iobsj,    &
+         & iproc,    &
+         & iindx,    &
+         & ifileidx, &
+         & isurfidx
+      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
+         & zphi, &
+         & zlam
+      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
+         & zdat
+      REAL(wp), DIMENSION(knumfiles) :: &
+         & djulini, &
+         & djulend
+      LOGICAL :: llvalprof
+      TYPE(obfbdata), POINTER, DIMENSION(:) :: &
+         & inpfiles
+
+      ! Local initialization
+      iobs = 0
+
+      !-----------------------------------------------------------------------
+      ! Count the number of files needed and allocate the obfbdata type
+      !-----------------------------------------------------------------------
+
+      inobf = knumfiles
+
+      ALLOCATE( inpfiles(inobf) )
+
+      surf_files : DO jj = 1, inobf
+
+         !---------------------------------------------------------------------
+         ! Prints
+         !---------------------------------------------------------------------
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' obs_rea_surf : Reading from file = ', &
+               & TRIM( TRIM( cdfilenames(jj) ) )
+            WRITE(numout,*) ' ~~~~~~~~~~~'
+            WRITE(numout,*)
+         ENDIF
+
+         !---------------------------------------------------------------------
+         !  Initialization: Open file and get dimensions only
+         !---------------------------------------------------------------------
+
+         iflag = nf90_open( TRIM( TRIM( cdfilenames(jj) ) ), nf90_nowrite, &
+            &                      i_file_id )
+
+         IF ( iflag /= nf90_noerr ) THEN
+
+            IF ( ldignmis ) THEN
+               inpfiles(jj)%nobs = 0
+               CALL ctl_warn( 'File ' // TRIM( TRIM( cdfilenames(jj) ) ) // &
+                  &           ' not found' )
+            ELSE 
+               CALL ctl_stop( 'File ' // TRIM( TRIM( cdfilenames(jj) ) ) // &
+                  &           ' not found' )
+            ENDIF
+
+         ELSE 
+
+            !------------------------------------------------------------------
+            !  Close the file since it is opened in read_obfbdata
+            !------------------------------------------------------------------
+
+            iflag = nf90_close( i_file_id )
+
+            !------------------------------------------------------------------
+            !  Read the profile file into inpfiles
+            !------------------------------------------------------------------
+            CALL init_obfbdata( inpfiles(jj) )
+            CALL read_obfbdata( TRIM( cdfilenames(jj) ), inpfiles(jj), &
+               &                ldgrid = .TRUE. )
+
+            IF ( ldmod .AND. ( inpfiles(jj)%nadd == 0 ) ) THEN
+               CALL ctl_stop( 'Model not in input data' )
+               RETURN
+            ENDIF
+
+            IF ( jj == 1 ) THEN
+               ALLOCATE( clvars( inpfiles(jj)%nvar ) )
+               DO ji = 1, inpfiles(jj)%nvar
+                 clvars(ji) = inpfiles(jj)%cname(ji)
+               END DO
+            ELSE
+               DO ji = 1, inpfiles(jj)%nvar
+                  IF ( inpfiles(jj)%cname(ji) /= clvars(ji) ) THEN
+                     CALL ctl_stop( 'Feedback file variables not consistent', &
+                        &           ' with previous files for this type' )
+                  ENDIF
+               END DO
+            ENDIF
+
+            IF (lwp) WRITE(numout,*)'Observation file contains ',inpfiles(jj)%nobs,' observations'
+
+            !------------------------------------------------------------------
+            !  Change longitude (-180,180)
+            !------------------------------------------------------------------
+
+            DO ji = 1, inpfiles(jj)%nobs
+
+               IF ( inpfiles(jj)%plam(ji) < -180. ) &
+                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) + 360.
+
+               IF ( inpfiles(jj)%plam(ji) >  180. ) &
+                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) - 360.
+
+            END DO
+
+            !------------------------------------------------------------------
+            !  Calculate the date  (change eventually)
+            !------------------------------------------------------------------
+            clrefdate=inpfiles(jj)%cdjuldref(1:8)
+            READ(clrefdate,'(I8)') irefdate(jj)
+
+            CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
+            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
+               &           krefdate = irefdate(jj) )
+            CALL ddatetoymdhms( ddobsend, iyea, imon, iday, ihou, imin, isec )
+            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulend(jj), &
+               &           krefdate = irefdate(jj) )
+
+            IF ( ldnightav ) THEN
+
+               IF ( lwp ) THEN
+                  WRITE(numout,*)'Resetting time of night-time averaged observations', &
+                     &             ' to the end of the day'
+               ENDIF
+
+               DO ji = 1, inpfiles(jj)%nobs
+                  !  for night-time averaged data force the time
+                  !  to be the last time-step of the day, but still within the day.
+                  IF ( inpfiles(jj)%ptim(ji) >= 0. ) THEN
+                     inpfiles(jj)%ptim(ji) = &
+                        & INT(inpfiles(jj)%ptim(ji)) + 0.9999
+                  ELSE
+                     inpfiles(jj)%ptim(ji) = &
+                        & INT(inpfiles(jj)%ptim(ji)) - 0.0001
+                  ENDIF
+               END DO
+            ENDIF
+
+            IF ( inpfiles(jj)%nobs > 0 ) THEN
+               inpfiles(jj)%iproc = -1
+               inpfiles(jj)%iobsi = -1
+               inpfiles(jj)%iobsj = -1
+            ENDIF
+            inowin = 0
+            DO ji = 1, inpfiles(jj)%nobs
+               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
+                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
+                  inowin = inowin + 1
+               ENDIF
+            END DO
+            ALLOCATE( zlam(inowin)  )
+            ALLOCATE( zphi(inowin)  )
+            ALLOCATE( iobsi(inowin) )
+            ALLOCATE( iobsj(inowin) )
+            ALLOCATE( iproc(inowin) )
+            inowin = 0
+            DO ji = 1, inpfiles(jj)%nobs
+               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
+                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
+                  inowin = inowin + 1
+                  zlam(inowin) = inpfiles(jj)%plam(ji)
+                  zphi(inowin) = inpfiles(jj)%pphi(ji)
+               ENDIF
+            END DO
+
+            CALL obs_grid_search( inowin, zlam, zphi, iobsi, iobsj, iproc, 'T' )
+
+            inowin = 0
+            DO ji = 1, inpfiles(jj)%nobs
+               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
+                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
+                  inowin = inowin + 1
+                  inpfiles(jj)%iproc(ji,1) = iproc(inowin)
+                  inpfiles(jj)%iobsi(ji,1) = iobsi(inowin)
+                  inpfiles(jj)%iobsj(ji,1) = iobsj(inowin)
+               ENDIF
+            END DO
+            DEALLOCATE( zlam, zphi, iobsi, iobsj, iproc )
+
+            DO ji = 1, inpfiles(jj)%nobs
+               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
+                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
+                  IF ( nproc == 0 ) THEN
+                     IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
+                  ELSE
+                     IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
+                  ENDIF
+                  llvalprof = .FALSE.
+                  IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
+                     & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
+                     iobs = iobs + 1
+                  ENDIF
+               ENDIF
+            END DO
+
+         ENDIF
+
+      END DO surf_files
+
+      !-----------------------------------------------------------------------
+      ! Get the time ordered indices of the input data
+      !-----------------------------------------------------------------------
+
+      !---------------------------------------------------------------------
+      !  Loop over input data files to count total number of profiles
+      !---------------------------------------------------------------------
+      iobstot = 0
+      DO jj = 1, inobf
+         DO ji = 1, inpfiles(jj)%nobs
+            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
+               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
+               iobstot = iobstot + 1
+            ENDIF
+         END DO
+      END DO
+
+      ALLOCATE( iindx(iobstot), ifileidx(iobstot), &
+         &      isurfidx(iobstot), zdat(iobstot) )
+      jk = 0
+      DO jj = 1, inobf
+         DO ji = 1, inpfiles(jj)%nobs
+            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
+               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
+               jk = jk + 1
+               ifileidx(jk) = jj
+               isurfidx(jk) = ji
+               zdat(jk)     = inpfiles(jj)%ptim(ji)
+            ENDIF
+         END DO
+      END DO
+      CALL sort_dp_indx( iobstot, &
+         &               zdat,     &
+         &               iindx   )
+
+      CALL obs_surf_alloc( surfdata, iobs, kvars, kextr, kstp, jpi, jpj )
+
+      ! Read obs/positions, QC, all variable and assign to surfdata
+
+      iobs = 0
+
+      surfdata%cvars(:)  = clvars(:)
+
+      ityp   (:) = 0
+      itypmpp(:) = 0
+
+      ioserrcount = 0
+
+      DO jk = 1, iobstot
+
+         jj = ifileidx(iindx(jk))
+         ji = isurfidx(iindx(jk))
+         IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
+            & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
+
+            IF ( nproc == 0 ) THEN
+               IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
+            ELSE
+               IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
+            ENDIF
+
+            ! Set observation information
+
+            IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
+               & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
+
+               iobs = iobs + 1
+
+               CALL jul2greg( isec,                   &
+                  &           imin,                   &
+                  &           ihou,                   &
+                  &           iday,                   &
+                  &           imon,                   &
+                  &           iyea,                   &
+                  &           inpfiles(jj)%ptim(ji), &
+                  &           irefdate(jj) )
+
+
+               ! Surface time coordinates
+               surfdata%nyea(iobs) = iyea
+               surfdata%nmon(iobs) = imon
+               surfdata%nday(iobs) = iday
+               surfdata%nhou(iobs) = ihou
+               surfdata%nmin(iobs) = imin
+
+               ! Surface space coordinates
+               surfdata%rlam(iobs) = inpfiles(jj)%plam(ji)
+               surfdata%rphi(iobs) = inpfiles(jj)%pphi(ji)
+
+               ! Coordinate search parameters
+               surfdata%mi  (iobs) = inpfiles(jj)%iobsi(ji,1)
+               surfdata%mj  (iobs) = inpfiles(jj)%iobsj(ji,1)
+
+               ! WMO number
+               surfdata%cwmo(iobs) = inpfiles(jj)%cdwmo(ji)
+
+               ! Instrument type
+               READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
+901            IF ( ios /= 0 ) THEN
+                  IF (ioserrcount == 0) THEN
+                     CALL ctl_warn ( 'Problem converting an instrument type ', &
+                        &            'to integer. Setting type to zero' )
+                  ENDIF
+                  ioserrcount = ioserrcount + 1
+                  itype = 0
+               ENDIF
+               surfdata%ntyp(iobs) = itype
+               IF ( itype < jpsurfmaxtype + 1 ) THEN
+                  ityp(itype+1) = ityp(itype+1) + 1
+               ELSE
+                  IF(lwp)WRITE(numout,*)'WARNING:Increase jpsurfmaxtype in ',&
+                     &                  cpname
+               ENDIF
+
+               ! Bookkeeping data to match observations
+               surfdata%nsidx(iobs) = iobs
+               surfdata%nsfil(iobs) = iindx(jk)
+
+               ! QC flags
+               surfdata%nqc(iobs) = inpfiles(jj)%ivqc(ji,1)
+
+               ! Observed value
+               surfdata%robs(iobs,1) = inpfiles(jj)%pob(1,ji,1)
+
+
+               ! Model and MDT is set to fbrmdi unless read from file
+               IF ( ldmod ) THEN
+                  surfdata%rmod(iobs,1) = inpfiles(jj)%padd(1,ji,1,1)
+                  IF ( TRIM(surfdata%cvars(1)) == 'SLA' ) THEN
+                     surfdata%rext(iobs,1) = inpfiles(jj)%padd(1,ji,2,1)
+                     surfdata%rext(iobs,2) = inpfiles(jj)%pext(1,ji,1)
+                  ENDIF
+                ELSE
+                  surfdata%rmod(iobs,1) = fbrmdi
+                  IF ( TRIM(surfdata%cvars(1)) == 'SLA' ) surfdata%rext(iobs,:) = fbrmdi
+               ENDIF
+            ENDIF
+         ENDIF
+
+      END DO
+
+      !-----------------------------------------------------------------------
+      ! Sum up over processors
+      !-----------------------------------------------------------------------
+
+      CALL obs_mpp_sum_integer( iobs, iobsmpp )
+      CALL obs_mpp_sum_integers( ityp, itypmpp, jpsurfmaxtype + 1 )
+
+      !-----------------------------------------------------------------------
+      ! Output number of observations.
+      !-----------------------------------------------------------------------
+      IF (lwp) THEN
+
+         WRITE(numout,*)
+         WRITE(numout,'(1X,A)')TRIM( surfdata%cvars(1) )//' data'
+         WRITE(numout,'(1X,A)')'--------------'
+         DO jj = 1,8
+            IF ( itypmpp(jj) > 0 ) THEN
+               WRITE(numout,'(1X,A4,I4,A3,I10)')'Type ', jj,' = ',itypmpp(jj)
+            ENDIF
+         END DO
+         WRITE(numout,'(1X,A)') &
+            & '---------------------------------------------------------------'
+         WRITE(numout,'(1X,A,I8)') &
+            & 'Total data for variable '//TRIM( surfdata%cvars(1) )// &
+            & '           = ', iobsmpp
+         WRITE(numout,'(1X,A)') &
+            & '---------------------------------------------------------------'
+         WRITE(numout,*)
+
+      ENDIF
+
+      !-----------------------------------------------------------------------
+      ! Deallocate temporary data
+      !-----------------------------------------------------------------------
+      DEALLOCATE( ifileidx, isurfidx, zdat, clvars )
+
+      !-----------------------------------------------------------------------
+      ! Deallocate input data
+      !-----------------------------------------------------------------------
+      DO jj = 1, inobf
+         IF ( inpfiles(jj)%lalloc ) THEN
+            CALL dealloc_obfbdata( inpfiles(jj) )
+         ENDIF
+      END DO
+      DEALLOCATE( inpfiles )
+
+   END SUBROUTINE obs_rea_surf
+
+END MODULE obs_read_surf
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_vel.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_vel.F90	(revision 6139)
+++ 	(revision )
@@ -1,653 +1,0 @@
-MODULE obs_read_vel
-   !!======================================================================
-   !!                       ***  MODULE obs_read_vel  ***
-   !! Observation diagnostics: Read the velocity profile observations
-   !!======================================================================
-
-   !!----------------------------------------------------------------------
-   !!   obs_rea_vel_dri : Driver for reading profile obs
-   !!----------------------------------------------------------------------
-
-   !! * Modules used   
-   USE par_kind                 ! Precision variables
-   USE par_oce                  ! Ocean parameters
-   USE in_out_manager           ! I/O manager
-   USE dom_oce                  ! Ocean space and time domain variables
-   USE obs_mpp                  ! MPP support routines for observation diagnostics
-   USE julian                   ! Julian date routines
-   USE obs_utils                ! Observation operator utility functions
-   USE obs_prep                 ! Prepare observation arrays
-   USE obs_grid                 ! Grid search
-   USE obs_sort                 ! Sorting observation arrays
-   USE obs_profiles_def         ! Profile definitions
-   USE obs_conv                 ! Various conversion routines
-   USE obs_types                ! Observation type definitions
-   USE netcdf                   ! NetCDF library
-   USE obs_oper                 ! Observation operators
-   USE obs_vel_io               ! Velocity profile files I/O (non-FB files)
-   USE lib_mpp                  ! For ctl_warn/stop
-
-   IMPLICIT NONE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC obs_rea_vel_dri  ! Read the profile observations 
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
- 
-   SUBROUTINE obs_rea_vel_dri( kformat, &
-      &                        profdata, knumfiles, cfilenames, &
-      &                        kvars, kextr, kstp, ddobsini, ddobsend, &
-      &                        ldignmis, ldavtimset, ldmod )
-      !!---------------------------------------------------------------------
-      !!
-      !!                   *** ROUTINE obs_rea_pro_dri ***
-      !!
-      !! ** Purpose : Read from file the profile observations
-      !!
-      !! ** Method  : Depending on kformat either ENACT, CORIOLIS or
-      !!              feedback data files are read
-      !!
-      !! ** Action  : 
-      !!
-      !! References : 
-      !!
-      !! History :  
-      !!      ! :  2009-01 (K. Mogensen) : New merged version of old routines
-      !!----------------------------------------------------------------------
-      !! * Modules used
-   
-      !! * Arguments
-      INTEGER :: kformat   ! Format of input data
-      !                    ! 1: ENACT
-      !                    ! 2: Coriolis
-      TYPE(obs_prof), INTENT(OUT) :: profdata    ! Profile data to be read
-      INTEGER, INTENT(IN) :: knumfiles           ! Number of files to read in
-      CHARACTER(LEN=128), INTENT(IN) ::  cfilenames(knumfiles) ! File names to read in
-      INTEGER, INTENT(IN) :: kvars       ! Number of variables in profdata
-      INTEGER, INTENT(IN) :: kextr       ! Number of extra fields for each var in profdata
-      INTEGER, INTENT(IN) :: kstp        !  Ocean time-step index
-      LOGICAL, INTENT(IN) :: ldignmis    ! Ignore missing files
-      LOGICAL, INTENT(IN) :: ldavtimset  ! Set time to be equal to the end of the day
-      LOGICAL, INTENT(IN) :: ldmod       ! Initialize model from input data
-      REAL(KIND=dp), INTENT(IN) :: ddobsini   ! Obs. ini time in YYYYMMDD.HHMMSS
-      REAL(KIND=dp), INTENT(IN) :: ddobsend   ! Obs. end time in YYYYMMDD.HHMMSS
-
-      !! * Local declarations
-      CHARACTER(LEN=15), PARAMETER :: cpname='obs_rea_vel_dri'
-      INTEGER :: jvar
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jk
-      INTEGER :: ij
-      INTEGER :: iflag
-      INTEGER :: inobf
-      INTEGER :: i_file_id
-      INTEGER :: inowin
-      INTEGER :: iyea
-      INTEGER :: imon
-      INTEGER :: iday
-      INTEGER :: ihou
-      INTEGER :: imin
-      INTEGER :: isec
-      INTEGER, DIMENSION(knumfiles) :: &
-         & irefdate
-      INTEGER, DIMENSION(ntyp1770+1) :: &
-         & itypuv,    &
-         & itypuvmpp 
-      INTEGER :: iuv3dtmpp
-      INTEGER, DIMENSION(:), ALLOCATABLE :: &
-         & iobsiu,   &
-         & iobsju,   &
-         & iprocu,   &
-         & iobsiv,   &
-         & iobsjv,   &
-         & iprocv,   &
-         & iindx,    &
-         & ifileidx, &
-         & iprofidx
-      INTEGER :: itype
-      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zphi, &
-         & zlam
-      real(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zdat
-      LOGICAL :: &
-         & llvalprof
-      TYPE(obfbdata), POINTER, DIMENSION(:) :: &
-         & inpfiles
-      real(wp), DIMENSION(knumfiles) :: &
-         & djulini, &
-         & djulend
-      INTEGER :: iprof
-      INTEGER :: iproftot
-      INTEGER :: iuv3dt
-      INTEGER :: ios
-      INTEGER :: ioserrcount
-      INTEGER, DIMENSION(kvars) :: iv3dt
-      CHARACTER(len=8) :: cl_refdate
-   
-      ! Local initialization
-      iprof = 0
-      iuv3dt = 0
-
-      !-----------------------------------------------------------------------
-      ! Check data the model part is just with feedback data files
-      !-----------------------------------------------------------------------
-      IF ( ldmod .AND. ( kformat /= 0 ) ) THEN
-         CALL ctl_stop( 'Model can only be read from feedback data' )
-         RETURN
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Count the number of files needed and allocate the obfbdata type
-      !-----------------------------------------------------------------------
-      
-      inobf = knumfiles
-
-      ALLOCATE( inpfiles(inobf) )
-
-      prof_files : DO jj = 1, inobf
-          
-         !---------------------------------------------------------------------
-         ! Prints
-         !---------------------------------------------------------------------
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) ' obs_rea_vel_dri : Reading from file = ', &
-               & TRIM( TRIM( cfilenames(jj) ) )
-            WRITE(numout,*) ' ~~~~~~~~~~~~~~~'
-            WRITE(numout,*)
-         ENDIF
-
-         !---------------------------------------------------------------------
-         !  Initialization: Open file and get dimensions only
-         !---------------------------------------------------------------------
-         
-         iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
-            &                      i_file_id )
-         
-         IF ( iflag /= nf90_noerr ) THEN
-
-            IF ( ldignmis ) THEN
-               inpfiles(jj)%nobs = 0
-               CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ELSE 
-               CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ENDIF
-
-         ELSE 
-            
-            !------------------------------------------------------------------
-            !  Close the file since it is opened in read_proffile
-            !------------------------------------------------------------------
-            
-            iflag = nf90_close( i_file_id )
-
-            !------------------------------------------------------------------
-            !  Read the profile file into inpfiles
-            !------------------------------------------------------------------
-            IF ( kformat == 0 ) THEN
-               CALL init_obfbdata( inpfiles(jj) )
-               IF(lwp) THEN
-                  WRITE(numout,*)
-                  WRITE(numout,*)'Reading from feedback file :', &
-                     &           TRIM( cfilenames(jj) )
-               ENDIF
-               CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                ldgrid = .TRUE. )
-               IF ( ldmod .AND. ( inpfiles(jj)%nadd == 0 ) ) THEN
-                  CALL ctl_stop( 'Model not in input data' )
-                  RETURN
-               ENDIF
-            ELSEIF ( kformat == 1 ) THEN
-               CALL read_taondbc( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &               numout, lwp, .TRUE. )
-            ELSE
-               CALL ctl_stop( 'File format unknown' )
-            ENDIF
-            
-            !------------------------------------------------------------------
-            !  Change longitude (-180,180)
-            !------------------------------------------------------------------
-
-            DO ji = 1, inpfiles(jj)%nobs 
-
-               IF ( inpfiles(jj)%plam(ji) < -180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) + 360.
-
-               IF ( inpfiles(jj)%plam(ji) >  180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) - 360.
-
-            END DO
-
-            !------------------------------------------------------------------
-            !  Calculate the date  (change eventually)
-            !------------------------------------------------------------------
-            cl_refdate=inpfiles(jj)%cdjuldref(1:8)
-            READ(cl_refdate,'(I8)') irefdate(jj)
-            
-            CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
-               &           krefdate = irefdate(jj) )
-            CALL ddatetoymdhms( ddobsend, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulend(jj), &
-               &           krefdate = irefdate(jj) )
-
-            IF ( ldavtimset ) THEN
-               DO ji = 1, inpfiles(jj)%nobs
-                  ! 
-                  !  for daily averaged data force the time
-                  !  to be the  end of the day
-                  !
-                  inpfiles(jj)%ptim(ji) = &
-                     & INT(inpfiles(jj)%ptim(ji)) + 1
-               END DO
-            ENDIF
-            
-            IF ( inpfiles(jj)%nobs > 0 ) THEN
-               inpfiles(jj)%iproc = -1
-               inpfiles(jj)%iobsi = -1
-               inpfiles(jj)%iobsj = -1
-            ENDIF
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-               ENDIF
-            END DO
-            ALLOCATE( zlam(inowin)  )
-            ALLOCATE( zphi(inowin)  )
-            ALLOCATE( iobsiu(inowin) )
-            ALLOCATE( iobsju(inowin) )
-            ALLOCATE( iprocu(inowin) )
-            ALLOCATE( iobsiv(inowin) )
-            ALLOCATE( iobsjv(inowin) )
-            ALLOCATE( iprocv(inowin) )
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  zlam(inowin) = inpfiles(jj)%plam(ji)
-                  zphi(inowin) = inpfiles(jj)%pphi(ji)
-               ENDIF
-            END DO
-
-            CALL obs_grid_search( inowin, zlam, zphi, iobsiu, iobsju, iprocu, &
-               & 'U' )
-            CALL obs_grid_search( inowin, zlam, zphi, iobsiv, iobsjv, iprocv, &
-               & 'V' )
-
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  inpfiles(jj)%iproc(ji,1) = iprocu(inowin)
-                  inpfiles(jj)%iobsi(ji,1) = iobsiu(inowin)
-                  inpfiles(jj)%iobsj(ji,1) = iobsju(inowin)
-                  inpfiles(jj)%iproc(ji,2) = iprocv(inowin)
-                  inpfiles(jj)%iobsi(ji,2) = iobsiv(inowin)
-                  inpfiles(jj)%iobsj(ji,2) = iobsjv(inowin)
-                  IF ( inpfiles(jj)%iproc(ji,1) /= &
-                     & inpfiles(jj)%iproc(ji,2) ) THEN
-                     CALL ctl_stop( 'Error in obs_read_vel:', &
-                        & 'U and V observation on different processors')
-                  ENDIF
-               ENDIF
-            END DO
-            DEALLOCATE( zlam, zphi, iobsiu, iobsju, iprocu,  &
-               & iobsiv, iobsjv, iprocv )
-
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  IF ( nproc == 0 ) THEN
-                     IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-                  ELSE
-                     IF ( inpfiles(jj)%iproc(ji,1) /=  nproc ) CYCLE
-                  ENDIF
-                  llvalprof = .FALSE.
-                  IF ( ( ( nproc == 0 ) .AND. &
-                     & ( inpfiles(jj)%iproc(ji,1) <=  nproc ) ) .OR. &
-                     & ( inpfiles(jj)%iproc(ji,1) ==  nproc ) ) THEN
-                     loop_uv_count : DO ij = 1,inpfiles(jj)%nlev
-                        IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
-                           & CYCLE
-                        IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
-                           & ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
-                           & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
-                           iuv3dt = iuv3dt + 1
-                           llvalprof = .TRUE.
-                        ENDIF
-                     END DO loop_uv_count
-                  ENDIF
-                  IF ( llvalprof ) iprof = iprof + 1
-               ENDIF
-            END DO
-
-         ENDIF
-         
-      END DO prof_files
-
-      !-----------------------------------------------------------------------
-      ! Get the time ordered indices of the input data
-      !-----------------------------------------------------------------------
-
-      !---------------------------------------------------------------------
-      !  Loop over input data files to count total number of profiles
-      !---------------------------------------------------------------------
-      iproftot = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               iproftot = iproftot + 1
-            ENDIF
-         END DO
-      END DO
-
-      ALLOCATE( iindx(iproftot), ifileidx(iproftot), &
-         &      iprofidx(iproftot), zdat(iproftot) )
-      jk = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               jk = jk + 1
-               ifileidx(jk) = jj
-               iprofidx(jk) = ji
-               zdat(jk)     = inpfiles(jj)%ptim(ji)
-            ENDIF
-         END DO
-      END DO
-      CALL sort_dp_indx( iproftot, &
-         &               zdat,     &
-         &               iindx   )
-      
-      iv3dt(:) = -1
-      iv3dt(1:2) = iuv3dt
-      CALL obs_prof_alloc( profdata, kvars, kextr, iprof, iv3dt, &
-         &                 kstp, jpi, jpj, jpk )
-      
-      ! * Read obs/positions, QC, all variable and assign to profdata
-
-      profdata%nprof     = 0
-      profdata%nvprot(:) = 0
-
-      iprof = 0
-
-      iuv3dt = 0
-      itypuv   (:) = 0
-      itypuvmpp(:) = 0
-      
-      DO jk = 1, iproftot
-         
-         jj = ifileidx(iindx(jk))
-         ji = iprofidx(iindx(jk))
-         IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
-            & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
-            
-            IF ( nproc == 0 ) THEN
-               IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-            ELSE
-               IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-            ENDIF
-            
-            llvalprof = .FALSE.
-
-            loop_prof : DO ij = 1, inpfiles(jj)%nlev
-               
-               IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
-                  & CYCLE
-               
-               IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
-                  & ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
-                  & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
-
-                  llvalprof = .TRUE.
-                  EXIT loop_prof
-
-               ENDIF
-
-            END DO loop_prof
-            
-            ! Set profile information
-            
-            IF ( llvalprof ) THEN
-               
-               iprof = iprof + 1
-
-               CALL jul2greg( isec,                   &
-                  &           imin,                   &
-                  &           ihou,                   &
-                  &           iday,                   &
-                  &           imon,                   &
-                  &           iyea,                   &
-                  &           inpfiles(jj)%ptim(ji), &
-                  &           irefdate(jj) )
-
-
-               ! Profile time coordinates
-               profdata%nyea(iprof) = iyea
-               profdata%nmon(iprof) = imon
-               profdata%nday(iprof) = iday
-               profdata%nhou(iprof) = ihou
-               profdata%nmin(iprof) = imin
-               
-               ! Profile space coordinates
-               profdata%rlam(iprof) = inpfiles(jj)%plam(ji)
-               profdata%rphi(iprof) = inpfiles(jj)%pphi(ji)
-
-               ! Coordinate search parameters
-               profdata%mi  (iprof,1) = inpfiles(jj)%iobsi(ji,1)
-               profdata%mj  (iprof,1) = inpfiles(jj)%iobsj(ji,1)
-               profdata%mi  (iprof,2) = inpfiles(jj)%iobsi(ji,2)
-               profdata%mj  (iprof,2) = inpfiles(jj)%iobsj(ji,2)
-               
-               ! Profile WMO number
-               profdata%cwmo(iprof) = inpfiles(jj)%cdwmo(ji)
-               
-               ! Instrument type
-               READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
-901            IF ( ios /= 0 ) THEN
-                  IF (ioserrcount == 0) CALL ctl_warn ( 'Problem converting an instrument type to integer. Setting type to zero' ) 
-                  ioserrcount = ioserrcount + 1
-                  itype = 0
-               ENDIF
-               profdata%ntyp(iprof) = itype
-               
-               ! QC stuff
-
-               profdata%nqc(iprof)     = inpfiles(jj)%ioqc(ji)
-               profdata%nqcf(:,iprof)  = inpfiles(jj)%ioqcf(:,ji)
-               profdata%ipqc(iprof)    = inpfiles(jj)%ipqc(ji)
-               profdata%ipqcf(:,iprof) = inpfiles(jj)%ipqcf(:,ji)
-               profdata%itqc(iprof)    = inpfiles(jj)%itqc(ji)
-               profdata%itqcf(:,iprof) = inpfiles(jj)%itqcf(:,ji)
-               profdata%ivqc(iprof,:)  = inpfiles(jj)%ivqc(ji,:)
-               profdata%ivqcf(:,iprof,:) = inpfiles(jj)%ivqcf(:,ji,:)
-
-               ! Bookkeeping data to match profiles
-               profdata%npidx(iprof) = iprof
-               profdata%npfil(iprof) = iindx(jk)
-
-               ! Observation QC flag (whole profile)
-               profdata%nqc(iprof)  = 0 !TODO
-
-               loop_uv : DO ij = 1, inpfiles(jj)%nlev            
-                   
-                  IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
-                     & CYCLE
-
-                  IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
-                     & ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
-                     & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
-                     iuv3dt = iuv3dt + 1
-                  ELSE
-                     CYCLE
-                  ENDIF
-
-                  ! Depth of U observation
-                  profdata%var(1)%vdep(iuv3dt) = &
-                     &                inpfiles(jj)%pdep(ij,ji)
-                  
-                  ! Depth of U observation QC
-                  profdata%var(1)%idqc(iuv3dt) = &
-                     &                inpfiles(jj)%idqc(ij,ji)
-                  
-                  ! Depth of U observation QC flags
-                  profdata%var(1)%idqcf(:,iuv3dt) = &
-                     &                inpfiles(jj)%idqcf(:,ij,ji)
-                  
-                  ! Profile index
-                  profdata%var(1)%nvpidx(iuv3dt) = iprof
-                  
-                  ! Vertical index in original profile
-                  profdata%var(1)%nvlidx(iuv3dt) = ij
-
-                  ! Profile U value
-
-                  profdata%var(1)%vobs(iuv3dt) = &
-                     &                inpfiles(jj)%pob(ij,ji,1)
-                  IF ( ldmod ) THEN
-                     profdata%var(1)%vmod(iuv3dt) = &
-                        &                inpfiles(jj)%padd(ij,ji,1,1)
-                  ENDIF
-                  
-                  ! Profile U qc
-                  profdata%var(1)%nvqc(iuv3dt) = &
-                     & inpfiles(jj)%ivlqc(ij,ji,1)
-                  
-                  ! Profile U qc flags
-                  profdata%var(1)%nvqcf(:,iuv3dt) = &
-                     & inpfiles(jj)%ivlqcf(:,ij,ji,1)
-                  
-                  
-                  ! Depth of V observation
-                  profdata%var(2)%vdep(iuv3dt) = &
-                     &                inpfiles(jj)%pdep(ij,ji)
-                  
-                  ! Depth of V observation QC
-                  profdata%var(2)%idqc(iuv3dt) = &
-                     &                inpfiles(jj)%idqc(ij,ji)
-                  
-                  ! Depth of V observation QC flags
-                  profdata%var(2)%idqcf(:,iuv3dt) = &
-                     &                inpfiles(jj)%idqcf(:,ij,ji)
-                  
-                  ! Profile index
-                  profdata%var(2)%nvpidx(iuv3dt) = iprof
-                  
-                  ! Vertical index in original profile
-                  profdata%var(2)%nvlidx(iuv3dt) = ij
-                  
-                  ! Profile V value
-                  profdata%var(2)%vobs(iuv3dt) = &
-                     &                inpfiles(jj)%pob(ij,ji,2)
-                  IF ( ldmod ) THEN
-                     profdata%var(2)%vmod(iuv3dt) = &
-                        &                inpfiles(jj)%padd(ij,ji,1,2)
-                  ENDIF
-                     
-                  ! Profile V qc
-                  profdata%var(2)%nvqc(iuv3dt) = &
-                     & inpfiles(jj)%ivlqc(ij,ji,2)
-                  
-                  ! Profile V qc flags
-                  profdata%var(2)%nvqcf(:,iuv3dt) = &
-                        & inpfiles(jj)%ivlqcf(:,ij,ji,2)
-                  
-                  ! Observation type
-                  itypuv( profdata%ntyp(iprof) + 1 ) = &
-                     & itypuv( profdata%ntyp(iprof) + 1 ) + 1
-
-
-               END DO loop_uv
-
-            ENDIF
-
-         ENDIF
-
-      END DO
-
-      !-----------------------------------------------------------------------
-      ! Sum up over processors
-      !-----------------------------------------------------------------------
-      
-      CALL obs_mpp_sum_integer ( iuv3dt, iuv3dtmpp )
-      
-      CALL obs_mpp_sum_integers( itypuv, itypuvmpp, ntyp1770 + 1 )
-      
-      !-----------------------------------------------------------------------
-      ! Output number of observations.
-      !-----------------------------------------------------------------------
-      IF(lwp) THEN
-         WRITE(numout,*) 
-         WRITE(numout,'(1X,A)') 'Profile U,V velocity data'
-         WRITE(numout,'(1X,A)') '-------------------------'
-         WRITE(numout,*) 
-         DO ji = 0, ntyp1770
-            IF ( itypuvmpp(ji+1) > 0 ) THEN
-               WRITE(numout,'(1X,A3,A3,I8)') ctypshort(ji), ' = ', &
-                  & itypuvmpp(ji+1)
-            ENDIF
-         END DO
-         WRITE(numout,'(1X,A)') '--------------'
-         WRITE(numout,'(1X,A6,I8)') &
-            & 'Total profile UV data                                 = ',&
-            & iuv3dtmpp
-         WRITE(numout,'(1X,A)') '--------------'
-      ENDIF
-      
-      profdata%nvprot(1)    = iuv3dt
-      profdata%nvprot(2)    = iuv3dt
-      profdata%nvprotmpp(1) = iuv3dtmpp
-      profdata%nvprotmpp(2) = iuv3dtmpp
-      profdata%nprof        = iprof
-
-      !-----------------------------------------------------------------------
-      ! Model level search
-      !-----------------------------------------------------------------------
-      CALL obs_level_search( jpk, gdept_1d,          &
-         & profdata%nvprot(1), profdata%var(1)%vdep, &
-         & profdata%var(1)%mvk )
-      CALL obs_level_search( jpk, gdept_1d,          &
-         & profdata%nvprot(2), profdata%var(2)%vdep, &
-         & profdata%var(2)%mvk )
-      
-      !-----------------------------------------------------------------------
-      ! Set model equivalent to 99999
-      !-----------------------------------------------------------------------
-      IF ( .NOT. ldmod ) THEN
-         DO jvar = 1, kvars
-            profdata%var(jvar)%vmod(:) = fbrmdi
-         END DO
-      ENDIF
-      !-----------------------------------------------------------------------
-      ! Deallocate temporary data
-      !-----------------------------------------------------------------------
-      DEALLOCATE( ifileidx, iprofidx, zdat )
-
-      !-----------------------------------------------------------------------
-      ! Deallocate input data
-      !-----------------------------------------------------------------------
-      DO jj = 1, inobf
-         CALL dealloc_obfbdata( inpfiles(jj) )
-      END DO
-      DEALLOCATE( inpfiles )
-
-   END SUBROUTINE obs_rea_vel_dri
-   
-END MODULE obs_read_vel
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_readmdt.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_readmdt.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_readmdt.F90	(revision 6140)
@@ -31,10 +31,10 @@
    PRIVATE
    
-   PUBLIC   obs_rea_mdt     ! called by ?
-   PUBLIC   obs_offset_mdt  ! called by ?
-
-   INTEGER , PUBLIC ::   nmsshc    = 1         ! MDT correction scheme
-   REAL(wp), PUBLIC ::   mdtcorr   = 1.61_wp   ! User specified MDT correction
-   REAL(wp), PUBLIC ::   mdtcutoff = 65.0_wp   ! MDT cutoff for computed correction
+   PUBLIC   obs_rea_mdt     ! called by dia_obs_init
+   PUBLIC   obs_offset_mdt  ! called by obs_rea_mdt
+
+   INTEGER , PUBLIC :: nn_msshc    = 1         ! MDT correction scheme
+   REAL(wp), PUBLIC :: rn_mdtcorr   = 1.61_wp  ! User specified MDT correction
+   REAL(wp), PUBLIC :: rn_mdtcutoff = 65.0_wp  ! MDT cutoff for computed correction
 
    !!----------------------------------------------------------------------
@@ -45,5 +45,5 @@
 CONTAINS
 
-   SUBROUTINE obs_rea_mdt( kslano, sladata, k2dint )
+   SUBROUTINE obs_rea_mdt( sladata, k2dint )
       !!---------------------------------------------------------------------
       !!
@@ -58,12 +58,10 @@
       USE iom
       !
-      INTEGER                          , INTENT(IN)    ::   kslano    ! Number of SLA Products
-      TYPE(obs_surf), DIMENSION(kslano), INTENT(inout) ::   sladata   ! SLA data
-      INTEGER                          , INTENT(in)    ::   k2dint    ! ?
+      TYPE(obs_surf), INTENT(inout) ::   sladata   ! SLA data
+      INTEGER       , INTENT(in)    ::   k2dint    ! ?
       !
       CHARACTER(LEN=12), PARAMETER ::   cpname  = 'obs_rea_mdt'
       CHARACTER(LEN=20), PARAMETER ::   mdtname = 'slaReferenceLevel.nc'
 
-      INTEGER ::   jslano              ! Data set loop variable
       INTEGER ::   jobs                ! Obs loop variable
       INTEGER ::   jpimdt, jpjmdt      ! Number of grid point in lat/lon for the MDT
@@ -88,4 +86,5 @@
       IF(lwp)WRITE(numout,*) ' obs_rea_mdt : Read MDT for referencing altimeter anomalies'
       IF(lwp)WRITE(numout,*) ' ------------- '
+      CALL FLUSH(numout)
 
       CALL iom_open( mdtname, nummdt )       ! Open the file
@@ -109,71 +108,70 @@
 
       ! Remove the offset between the MDT used with the sla and the model MDT
-      IF( nmsshc == 1 .OR. nmsshc == 2 )   CALL obs_offset_mdt( z_mdt, zfill )
+      IF( nn_msshc == 1 .OR. nn_msshc == 2 ) &
+         & CALL obs_offset_mdt( jpi, jpj, z_mdt, zfill )
 
       ! Intepolate the MDT already on the model grid at the observation point
   
-      DO jslano = 1, kslano
-         ALLOCATE( &
-            & igrdi(2,2,sladata(jslano)%nsurf), &
-            & igrdj(2,2,sladata(jslano)%nsurf), &
-            & zglam(2,2,sladata(jslano)%nsurf), &
-            & zgphi(2,2,sladata(jslano)%nsurf), &
-            & zmask(2,2,sladata(jslano)%nsurf), &
-            & zmdtl(2,2,sladata(jslano)%nsurf)  &
-            & )
+      ALLOCATE( &
+         & igrdi(2,2,sladata%nsurf), &
+         & igrdj(2,2,sladata%nsurf), &
+         & zglam(2,2,sladata%nsurf), &
+         & zgphi(2,2,sladata%nsurf), &
+         & zmask(2,2,sladata%nsurf), &
+         & zmdtl(2,2,sladata%nsurf)  &
+         & )
          
-         DO jobs = 1, sladata(jslano)%nsurf
-
-            igrdi(1,1,jobs) = sladata(jslano)%mi(jobs)-1
-            igrdj(1,1,jobs) = sladata(jslano)%mj(jobs)-1
-            igrdi(1,2,jobs) = sladata(jslano)%mi(jobs)-1
-            igrdj(1,2,jobs) = sladata(jslano)%mj(jobs)
-            igrdi(2,1,jobs) = sladata(jslano)%mi(jobs)
-            igrdj(2,1,jobs) = sladata(jslano)%mj(jobs)-1
-            igrdi(2,2,jobs) = sladata(jslano)%mi(jobs)
-            igrdj(2,2,jobs) = sladata(jslano)%mj(jobs)
-
-         END DO
-
-         CALL obs_int_comm_2d( 2, 2, sladata(jslano)%nsurf, igrdi, igrdj, glamt  , zglam )
-         CALL obs_int_comm_2d( 2, 2, sladata(jslano)%nsurf, igrdi, igrdj, gphit  , zgphi )
-         CALL obs_int_comm_2d( 2, 2, sladata(jslano)%nsurf, igrdi, igrdj, mdtmask, zmask )
-         CALL obs_int_comm_2d( 2, 2, sladata(jslano)%nsurf, igrdi, igrdj, z_mdt  , zmdtl )
-
-         DO jobs = 1, sladata(jslano)%nsurf
+      DO jobs = 1, sladata%nsurf
+
+         igrdi(1,1,jobs) = sladata%mi(jobs)-1
+         igrdj(1,1,jobs) = sladata%mj(jobs)-1
+         igrdi(1,2,jobs) = sladata%mi(jobs)-1
+         igrdj(1,2,jobs) = sladata%mj(jobs)
+         igrdi(2,1,jobs) = sladata%mi(jobs)
+         igrdj(2,1,jobs) = sladata%mj(jobs)-1
+         igrdi(2,2,jobs) = sladata%mi(jobs)
+         igrdj(2,2,jobs) = sladata%mj(jobs)
+
+      END DO
+
+      CALL obs_int_comm_2d( 2, 2, sladata%nsurf, jpi, jpj, igrdi, igrdj, glamt  , zglam )
+      CALL obs_int_comm_2d( 2, 2, sladata%nsurf, jpi, jpj, igrdi, igrdj, gphit  , zgphi )
+      CALL obs_int_comm_2d( 2, 2, sladata%nsurf, jpi, jpj, igrdi, igrdj, mdtmask, zmask )
+      CALL obs_int_comm_2d( 2, 2, sladata%nsurf, jpi, jpj, igrdi, igrdj, z_mdt  , zmdtl )
+
+      DO jobs = 1, sladata%nsurf
             
-            zlam = sladata(jslano)%rlam(jobs)
-            zphi = sladata(jslano)%rphi(jobs)
-
-            CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,         &
-               &                   zglam(:,:,jobs), zgphi(:,:,jobs), &
-               &                   zmask(:,:,jobs), zweig, zobsmask )
+         zlam = sladata%rlam(jobs)
+         zphi = sladata%rphi(jobs)
+
+         CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,         &
+            &                   zglam(:,:,jobs), zgphi(:,:,jobs), &
+            &                   zmask(:,:,jobs), zweig, zobsmask )
             
-            CALL obs_int_h2d( 1, 1, zweig, zmdtl(:,:,jobs),  zext )
+         CALL obs_int_h2d( 1, 1, zweig, zmdtl(:,:,jobs),  zext )
  
-            sladata(jslano)%rext(jobs,2) = zext(1)
+         sladata%rext(jobs,2) = zext(1)
 
 ! mark any masked data with a QC flag
-            IF( zobsmask(1) == 0 )   sladata(jslano)%nqc(jobs) = 11
+         IF( zobsmask(1) == 0 )   sladata%nqc(jobs) = 11
 
          END DO
          
-         DEALLOCATE( &
-            & igrdi, &
-            & igrdj, &
-            & zglam, &
-            & zgphi, &
-            & zmask, &
-            & zmdtl  &
-            & )
-
-      END DO
+      DEALLOCATE( &
+         & igrdi, &
+         & igrdj, &
+         & zglam, &
+         & zgphi, &
+         & zmask, &
+         & zmdtl  &
+         & )
 
       CALL wrk_dealloc(jpi,jpj,z_mdt,mdtmask) 
+      IF(lwp)WRITE(numout,*) ' ------------- '
       !
    END SUBROUTINE obs_rea_mdt
 
 
-   SUBROUTINE obs_offset_mdt( mdt, zfill )
+   SUBROUTINE obs_offset_mdt( kpi, kpj, mdt, zfill )
       !!---------------------------------------------------------------------
       !!
@@ -188,6 +186,7 @@
       !! ** Action  : 
       !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   mdt     ! MDT used on the model grid
-      REAL(wp)                    , INTENT(in   ) ::   zfill 
+      INTEGER, INTENT(IN) ::  kpi, kpj
+      REAL(wp), DIMENSION(kpi,kpj), INTENT(INOUT) ::   mdt     ! MDT used on the model grid
+      REAL(wp)                    , INTENT(IN   ) ::   zfill 
       ! 
       INTEGER  :: ji, jj
@@ -205,6 +204,6 @@
         DO jj = 1, jpj
            zpromsk(ji,jj) = tmask_i(ji,jj)
-           IF (    ( gphit(ji,jj) .GT.  mdtcutoff ) &
-              &.OR.( gphit(ji,jj) .LT. -mdtcutoff ) &
+           IF (    ( gphit(ji,jj) .GT.  rn_mdtcutoff ) &
+              &.OR.( gphit(ji,jj) .LT. -rn_mdtcutoff ) &
               &.OR.( mdt(ji,jj) .EQ. zfill ) ) &
               &        zpromsk(ji,jj) = 0.0
@@ -212,5 +211,5 @@
       END DO 
 
-      ! Compute MSSH mean over [0,360] x [-mdtcutoff,mdtcutoff]
+      ! Compute MSSH mean over [0,360] x [-rn_mdtcutoff,rn_mdtcutoff]
 
       zarea = 0.0
@@ -240,22 +239,22 @@
       !  Correct spatial mean of the MSSH
 
-      IF( nmsshc == 1 )   mdt(:,:) = mdt(:,:) - zcorr  
+      IF( nn_msshc == 1 )   mdt(:,:) = mdt(:,:) - zcorr  
 
       ! User defined value : 1.6 m for the Rio MDT compared to ORCA2 MDT
 
-      IF( nmsshc == 2 )   mdt(:,:) = mdt(:,:) - mdtcorr
+      IF( nn_msshc == 2 )   mdt(:,:) = mdt(:,:) - rn_mdtcorr
 
       IF(lwp) THEN
          WRITE(numout,*)
-         WRITE(numout,*) ' obs_readmdt : mdtcutoff     = ', mdtcutoff
+         WRITE(numout,*) ' obs_readmdt : rn_mdtcutoff     = ', rn_mdtcutoff
          WRITE(numout,*) ' -----------   zcorr_mdt     = ', zcorr_mdt
          WRITE(numout,*) '               zcorr_bcketa  = ', zcorr_bcketa
          WRITE(numout,*) '               zcorr         = ', zcorr
-         WRITE(numout,*) '               nmsshc        = ', nmsshc
+         WRITE(numout,*) '               nn_msshc        = ', nn_msshc
       ENDIF
 
-      IF ( nmsshc == 0 ) WRITE(numout,*) '           MSSH correction is not applied'
-      IF ( nmsshc == 1 ) WRITE(numout,*) '           MSSH correction is applied'
-      IF ( nmsshc == 2 ) WRITE(numout,*) '           User defined MSSH correction' 
+      IF ( nn_msshc == 0 ) WRITE(numout,*) '           MSSH correction is not applied'
+      IF ( nn_msshc == 1 ) WRITE(numout,*) '           MSSH correction is applied'
+      IF ( nn_msshc == 2 ) WRITE(numout,*) '           User defined MSSH correction' 
 
       CALL wrk_dealloc( jpi,jpj, zpromsk )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_rot_vel.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_rot_vel.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_rot_vel.F90	(revision 6140)
@@ -140,23 +140,23 @@
       END DO
 
-      CALL obs_int_comm_2d( 2, 2, profdata%nprof, igrdiu, igrdju, &
+      CALL obs_int_comm_2d( 2, 2, profdata%nprof, jpi, jpj, igrdiu, igrdju, &
          &                  glamu, zglamu )
-      CALL obs_int_comm_2d( 2, 2, profdata%nprof, igrdiu, igrdju, &
+      CALL obs_int_comm_2d( 2, 2, profdata%nprof, jpi, jpj, igrdiu, igrdju, &
          &                  gphiu, zgphiu )
-      CALL obs_int_comm_2d( 2, 2, profdata%nprof, igrdiu, igrdju, &
+      CALL obs_int_comm_2d( 2, 2, profdata%nprof, jpi, jpj, igrdiu, igrdju, &
          &                  umask(:,:,1), zmasku )
-      CALL obs_int_comm_2d( 2, 2, profdata%nprof, igrdiu, igrdju, &
+      CALL obs_int_comm_2d( 2, 2, profdata%nprof, jpi, jpj, igrdiu, igrdju, &
          &                  zsingu, zsinlu )
-      CALL obs_int_comm_2d( 2, 2, profdata%nprof, igrdiu, igrdju, &
+      CALL obs_int_comm_2d( 2, 2, profdata%nprof, jpi, jpj, igrdiu, igrdju, &
          &                  zcosgu, zcoslu )
-      CALL obs_int_comm_2d( 2, 2, profdata%nprof, igrdiv, igrdjv, &
+      CALL obs_int_comm_2d( 2, 2, profdata%nprof, jpi, jpj, igrdiv, igrdjv, &
          &                  glamv, zglamv )
-      CALL obs_int_comm_2d( 2, 2, profdata%nprof, igrdiv, igrdjv, &
+      CALL obs_int_comm_2d( 2, 2, profdata%nprof, jpi, jpj, igrdiv, igrdjv, &
          &                  gphiv, zgphiv )
-      CALL obs_int_comm_2d( 2, 2, profdata%nprof, igrdiv, igrdjv, &
+      CALL obs_int_comm_2d( 2, 2, profdata%nprof, jpi, jpj, igrdiv, igrdjv, &
          &                  vmask(:,:,1), zmaskv )
-      CALL obs_int_comm_2d( 2, 2, profdata%nprof, igrdiv, igrdjv, &
+      CALL obs_int_comm_2d( 2, 2, profdata%nprof, jpi, jpj, igrdiv, igrdjv, &
          &                  zsingv, zsinlv )
-      CALL obs_int_comm_2d( 2, 2, profdata%nprof, igrdiv, igrdjv, &
+      CALL obs_int_comm_2d( 2, 2, profdata%nprof, jpi, jpj, igrdiv, igrdjv, &
          &                  zcosgv, zcoslv )
 
@@ -195,7 +195,7 @@
          DO jk = profdata%npvsta(ji,1), profdata%npvend(ji,1)
             IF ( ( profdata%var(1)%vmod(jk) /= fbrmdi ) .AND. &
-               & ( profdata%var(1)%vmod(jk) /= fbrmdi ) ) THEN
+               & ( profdata%var(2)%vmod(jk) /= fbrmdi ) ) THEN
                pu(jk) = profdata%var(1)%vmod(jk) * zcos - &
-                  &     profdata%var(2)%vmod(jk) * zsin 
+                  &     profdata%var(2)%vmod(jk) * zsin
                pv(jk) = profdata%var(2)%vmod(jk) * zcos + &
                   &     profdata%var(1)%vmod(jk) * zsin
@@ -204,4 +204,5 @@
                pv(jk) = fbrmdi
             ENDIF
+
          END DO
 
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_seaice.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_seaice.F90	(revision 6139)
+++ 	(revision )
@@ -1,35 +1,0 @@
-MODULE obs_seaice
-   !!=====================================================================
-   !!                       ***  MODULE  obs_seaice  ***
-   !! Observation diagnostics: Storage space for sea ice observations
-   !!                          arrays and additional flags etc.
-   !!=====================================================================
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   
-   !! * Modules used 
-   USE obs_surf_def ! Definition of sea ice data types and tools
-
-   IMPLICIT NONE
-   
-   SAVE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC nseaicevars, nseaiceextr, nseaicesets, seaicedata, seaicedatqc
-
-   !! * Shared Module variables
-   INTEGER :: nseaicevars                               ! Number of seaicedata variables
-   INTEGER :: nseaiceextr                               ! Number of seaicedata extra 
-                                                     ! variables
-   INTEGER :: nseaicesets                               ! Number of seaicedata sets
-   TYPE(obs_surf), POINTER, DIMENSION(:) :: seaicedata  ! Initial sea ice data
-   TYPE(obs_surf), POINTER, DIMENSION(:) :: seaicedatqc ! Sea ice data after quality control
-
-END MODULE obs_seaice
-
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_seaice_io.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_seaice_io.F90	(revision 6139)
+++ 	(revision )
@@ -1,30 +1,0 @@
-MODULE obs_seaice_io
-   !!======================================================================
-   !!                       ***  MODULE obs_seaice_io  ***
-   !! Observation operators : I/O for GHRSEAICE files
-   !!======================================================================
-   !! History : 
-   !!             !  09-01  (K. Mogensen) Initial version
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!   read_seaicefile    :  Read a obfbdata structure from an GHRSEAICE file
-   !!----------------------------------------------------------------------
-   USE par_kind
-   USE obs_utils
-   USE obs_fbm
-   USE julian
-   USE netcdf
-
-   IMPLICIT NONE
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-#include "obsseaice_io.h90"
-
-END MODULE obs_seaice_io
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sla.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sla.F90	(revision 6139)
+++ 	(revision )
@@ -1,33 +1,0 @@
-MODULE obs_sla
-   !!=====================================================================
-   !!                       ***  MODULE  obs_sla  ***
-   !! Observation diagnostics: Storage space for SLA observations
-   !!                          arrays and additional flags etc.
-   !!=====================================================================
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-   
-   !! * Modules used 
-   USE obs_surf_def ! Definition of SLA data types and tools
-
-   IMPLICIT NONE
-   
-   SAVE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC nslavars, nslaextr, nslasets, sladata, sladatqc
-
-   !! * Shared Module variables
-   INTEGER :: nslavars                               ! Number of sladata variables
-   INTEGER :: nslaextr                               ! Number of sladata extra 
-                                                     ! variables
-   INTEGER :: nslasets                               ! Number of sladata sets                                               
-   TYPE(obs_surf), POINTER, DIMENSION(:) :: sladata  ! Initial SLA data
-   TYPE(obs_surf), POINTER, DIMENSION(:) :: sladatqc ! SLA data after quality control
-
-END MODULE obs_sla
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sla_io.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sla_io.F90	(revision 6139)
+++ 	(revision )
@@ -1,30 +1,0 @@
-MODULE obs_sla_io
-   !!======================================================================
-   !!                       ***  MODULE obs_sla_io  ***
-   !! Observation operators : I/O for AVISO SLA files
-   !!======================================================================
-   !! History : 
-   !!             !  09-01  (K. Mogensen) Initial version
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!   read_enactfile    :  Read a obfbdata structure from an AVISO SLA file
-   !!----------------------------------------------------------------------
-   USE par_kind
-   USE obs_utils
-   USE obs_fbm
-   use obs_sla_types
-   USE netcdf
-
-   IMPLICIT NONE
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-#include "obssla_io.h90"
-
-END MODULE obs_sla_io
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sla_types.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sla_types.F90	(revision 6139)
+++ 	(revision )
@@ -1,19 +1,0 @@
-MODULE obs_sla_types
-   !!======================================================================
-   !!                       ***  MODULE obs_sla_type  ***
-   !! Observation operators : Satellite identifiers for SLA data
-   !!======================================================================
-   !! History : 
-   !!             !  09-01  (K. Mogensen) Initial version
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   IMPLICIT NONE
-
-#include "obssla_types.h90"
-
-END MODULE obs_sla_types
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sst.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sst.F90	(revision 6139)
+++ 	(revision )
@@ -1,35 +1,0 @@
-MODULE obs_sst
-   !!=====================================================================
-   !!                       ***  MODULE  obs_sst  ***
-   !! Observation diagnostics: Storage space for SST observations
-   !!                          arrays and additional flags etc.
-   !!=====================================================================
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   
-   !! * Modules used 
-   USE obs_surf_def ! Definition of SST data types and tools
-
-   IMPLICIT NONE
-   
-   SAVE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC nsstvars, nsstextr, nsstsets, sstdata, sstdatqc
-
-   !! * Shared Module variables
-   INTEGER :: nsstvars                               ! Number of sstdata variables
-   INTEGER :: nsstextr                               ! Number of sstdata extra 
-                                                     ! variables
-   INTEGER :: nsstsets                               ! Number of sstdata sets
-   TYPE(obs_surf), POINTER, DIMENSION(:) :: sstdata  ! Initial SST data
-   TYPE(obs_surf), POINTER, DIMENSION(:) :: sstdatqc ! SST data after quality control
-
-END MODULE obs_sst
-
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sst_io.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sst_io.F90	(revision 6139)
+++ 	(revision )
@@ -1,30 +1,0 @@
-MODULE obs_sst_io
-   !!======================================================================
-   !!                       ***  MODULE obs_sst_io  ***
-   !! Observation operators : I/O for GHRSST files
-   !!======================================================================
-   !! History : 
-   !!             !  09-01  (K. Mogensen) Initial version
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!   read_sstfile    :  Read a obfbdata structure from an GHRSST file
-   !!----------------------------------------------------------------------
-   USE par_kind
-   USE obs_utils
-   USE obs_fbm
-   USE julian
-   USE netcdf
-
-   IMPLICIT NONE
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-#include "obssst_io.h90"
-
-END MODULE obs_sst_io
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sstbias.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sstbias.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sstbias.F90	(revision 6140)
@@ -0,0 +1,244 @@
+MODULE obs_sstbias
+   !!======================================================================
+   !!                       ***  MODULE obs_readsstbias  ***
+   !! Observation diagnostics: Read the bias for SLA data
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !!   obs_rea_sstbias : Driver for reading altimeter bias
+   !!----------------------------------------------------------------------
+   !! * Modules used   
+   USE par_kind, ONLY : &       ! Precision variables
+      & wp, &
+      & dp, &
+      & sp
+   USE par_oce, ONLY : &        ! Domain parameters
+      & jpi, &
+      & jpj, &
+      & jpim1
+   USE in_out_manager, ONLY : & ! I/O manager
+      & lwp,    &
+      & numout 
+   USE obs_surf_def             ! Surface observation definitions
+   USE dom_oce, ONLY : &        ! Domain variables
+      & tmask, &
+      & tmask_i, &
+      & e1t,   &
+      & e2t,   &
+      & gphit, &
+      & glamt
+   USE oce, ONLY : &           ! Model variables
+      & sshn
+   USE obs_inter_h2d
+   USE obs_utils               ! Various observation tools
+   USE obs_inter_sup
+   IMPLICIT NONE
+   !! * Routine accessibility
+   PRIVATE
+   PUBLIC obs_app_sstbias     ! Read the altimeter bias
+CONTAINS
+   SUBROUTINE obs_app_sstbias( sstdata, k2dint, knumtypes, &
+                               cl_bias_files )
+      !!---------------------------------------------------------------------
+      !!
+      !!                   *** ROUTINE obs_app_sstbias ***
+      !!
+      !! ** Purpose : Read SST bias data from files and apply correction to
+      !!             observations
+      !!
+      !! ** Method  :
+      !!
+      !! ** Action  :
+      !!
+      !! References :
+      !!
+      !! History : 
+      !!      ! :  2014-08 (J. While) Bias correction code for SST obs,
+      !!      !                      based on obs_rea_altbias
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE iom
+      USE netcdf
+      !! * Arguments
+
+      TYPE(obs_surf), INTENT(INOUT) :: sstdata       ! SST data
+      INTEGER, INTENT(IN) :: k2dint
+      INTEGER, INTENT(IN) :: knumtypes !number of bias types to read in
+      CHARACTER(LEN=128), DIMENSION(knumtypes), INTENT(IN) :: &
+                          cl_bias_files !List of files to read
+      !! * Local declarations
+      INTEGER :: jobs         ! Obs loop variable
+      INTEGER :: jpisstbias   ! Number of grid point in latitude for the bias
+      INTEGER :: jpjsstbias   ! Number of grid point in longitude for the bias
+      INTEGER :: iico         ! Grid point indices
+      INTEGER :: ijco
+      INTEGER :: jt
+      INTEGER :: i_nx_id      ! Index to read the NetCDF file
+      INTEGER :: i_ny_id      !
+      INTEGER :: i_file_id    !
+      INTEGER :: i_var_id
+      INTEGER, DIMENSION(knumtypes) :: &
+         & ibiastypes             ! Array of the bias types in each file
+      REAL(wp), DIMENSION(jpi,jpj,knumtypes) :: & 
+         & z_sstbias              ! Array to store the SST bias values
+      REAL(wp), DIMENSION(jpi,jpj) :: & 
+         & z_sstbias_2d           ! Array to store the SST bias values   
+      REAL(wp), DIMENSION(1) :: &
+         & zext, &
+         & zobsmask
+      REAL(wp), DIMENSION(2,2,1) :: &
+         & zweig
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zmask, &
+         & zglam, &
+         & zgphi
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zmask_tmp, &
+         & zglam_tmp, &
+         & zgphi_tmp   
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::  zbias   
+      REAL(wp) :: zlam
+      REAL(wp) :: zphi
+      INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: &
+         & igrdi, &
+         & igrdj
+      INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: &
+         & igrdi_tmp, &
+         & igrdj_tmp   
+      INTEGER :: numsstbias
+      INTEGER(KIND=NF90_INT) :: ifile_source
+     
+      INTEGER :: incfile
+      INTEGER :: jtype
+      INTEGER :: iret 
+      INTEGER :: inumtype
+      IF(lwp)WRITE(numout,*) 
+      IF(lwp)WRITE(numout,*) 'obs_rea_sstbias : '
+      IF(lwp)WRITE(numout,*) '----------------- '
+      IF(lwp)WRITE(numout,*) 'Read SST bias '
+      ! Open and read the files
+      z_sstbias(:,:,:)=0.0_wp
+      DO jtype = 1, knumtypes
+     
+         numsstbias=0
+         IF(lwp)WRITE(numout,*) 'Opening ',cl_bias_files(jtype)
+         CALL iom_open( cl_bias_files(jtype), numsstbias, ldstop=.FALSE. )       
+         IF (numsstbias > 0) THEN
+     
+            !Read the bias type from the file
+            !No IOM get attribute command at time of writing, 
+            !so have to use NETCDF
+            !routines directly - should be upgraded in the future
+            iret=NF90_OPEN(TRIM(cl_bias_files(jtype)), NF90_NOWRITE, incfile)
+            iret=NF90_GET_ATT( incfile, NF90_GLOBAL, "SST_source", &
+                              ifile_source )
+            ibiastypes(jtype) = ifile_source                 
+            iret=NF90_CLOSE(incfile)       
+           
+            IF ( iret /= 0  ) CALL ctl_stop( &
+               'obs_rea_sstbias : Cannot read bias type from file '// &
+               cl_bias_files(jtype) )
+            ! Get the SST bias data
+            CALL iom_get( numsstbias, jpdom_data, 'sst', z_sstbias_2d(:,:), 1 )
+            z_sstbias(:,:,jtype) = z_sstbias_2d(:,:)       
+            ! Close the file
+            CALL iom_close(numsstbias)       
+         ELSE
+            CALL ctl_stop('obs_read_sstbias: File '// & 
+                           TRIM( cl_bias_files(jtype) )//' Not found')
+         ENDIF
+      END DO
+           
+      ! Interpolate the bias already on the model grid at the observation point
+      ALLOCATE( &
+         & igrdi(2,2,sstdata%nsurf), &
+         & igrdj(2,2,sstdata%nsurf), &
+         & zglam(2,2,sstdata%nsurf), &
+         & zgphi(2,2,sstdata%nsurf), &
+         & zmask(2,2,sstdata%nsurf)  )
+       
+      DO jobs = 1, sstdata%nsurf 
+         igrdi(1,1,jobs) = sstdata%mi(jobs)-1
+         igrdj(1,1,jobs) = sstdata%mj(jobs)-1
+         igrdi(1,2,jobs) = sstdata%mi(jobs)-1
+         igrdj(1,2,jobs) = sstdata%mj(jobs)
+         igrdi(2,1,jobs) = sstdata%mi(jobs)
+         igrdj(2,1,jobs) = sstdata%mj(jobs)-1
+         igrdi(2,2,jobs) = sstdata%mi(jobs)
+         igrdj(2,2,jobs) = sstdata%mj(jobs)
+      END DO
+      CALL obs_int_comm_2d( 2, 2, sstdata%nsurf, jpi, jpj, &
+         &                  igrdi, igrdj, glamt, zglam )
+      CALL obs_int_comm_2d( 2, 2, sstdata%nsurf, jpi, jpj, &
+         &                  igrdi, igrdj, gphit, zgphi )
+      CALL obs_int_comm_2d( 2, 2, sstdata%nsurf, jpi, jpj, &
+         &                  igrdi, igrdj, tmask(:,:,1), zmask )
+      DO jtype = 1, knumtypes
+         
+         !Find the number observations of type and allocate tempory arrays
+         inumtype = COUNT( sstdata%ntyp(:) == ibiastypes(jtype) )
+         ALLOCATE( &
+            & igrdi_tmp(2,2,inumtype), &
+            & igrdj_tmp(2,2,inumtype), &
+            & zglam_tmp(2,2,inumtype), &
+            & zgphi_tmp(2,2,inumtype), &
+            & zmask_tmp(2,2,inumtype), &
+            & zbias( 2,2,inumtype ) )
+         jt=1
+         DO jobs = 1, sstdata%nsurf 
+            IF ( sstdata%ntyp(jobs) == ibiastypes(jtype) ) THEN
+               igrdi_tmp(:,:,jt) = igrdi(:,:,jobs) 
+               igrdj_tmp(:,:,jt) = igrdj(:,:,jobs)
+               zglam_tmp(:,:,jt) = zglam(:,:,jobs)
+               zgphi_tmp(:,:,jt) = zgphi(:,:,jobs)
+               zgphi_tmp(:,:,jt) = zgphi(:,:,jobs)
+               zmask_tmp(:,:,jt) = zmask(:,:,jobs)
+               jt = jt +1
+            ENDIF
+         END DO
+                         
+         CALL obs_int_comm_2d( 2, 2, inumtype, jpi, jpj, &
+               &           igrdi_tmp(:,:,:), igrdj_tmp(:,:,:), &
+               &           z_sstbias(:,:,jtype), zbias(:,:,:) )
+         jt=1
+         DO jobs = 1, sstdata%nsurf
+            IF ( sstdata%ntyp(jobs) == ibiastypes(jtype) ) THEN
+               zlam = sstdata%rlam(jobs)
+               zphi = sstdata%rphi(jobs)
+               iico = sstdata%mi(jobs)
+               ijco = sstdata%mj(jobs)         
+               CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,         &
+                  &                   zglam_tmp(:,:,jt), &
+                  &                   zgphi_tmp(:,:,jt), &
+                  &                   zmask_tmp(:,:,jt), zweig, zobsmask )
+               CALL obs_int_h2d( 1, 1, zweig, zbias(:,:,jt),  zext )
+               ! adjust sst with bias field
+               sstdata%robs(jobs,1) = sstdata%robs(jobs,1) - zext(1)
+               jt=jt+1
+            ENDIF
+         END DO 
+               
+         !Deallocate arrays
+         DEALLOCATE( &
+         & igrdi_tmp, &
+         & igrdj_tmp, &
+         & zglam_tmp, &
+         & zgphi_tmp, &
+         & zmask_tmp, &
+         & zbias )           
+      END DO
+      DEALLOCATE( &
+         & igrdi, &
+         & igrdj, &
+         & zglam, &
+         & zgphi, &
+         & zmask )
+
+      IF(lwp) THEN
+         WRITE(numout,*) " "
+         WRITE(numout,*) "SST bias correction applied successfully"
+         WRITE(numout,*) "Obs types: ",ibiastypes(:), &
+                              " Have all been bias corrected\n"
+      ENDIF
+   END SUBROUTINE obs_app_sstbias
+ 
+END MODULE obs_sstbias
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_surf_def.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_surf_def.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_surf_def.F90	(revision 6140)
@@ -67,4 +67,7 @@
          & ntyp           !: Type of surface observation product
 
+      CHARACTER(len=6), POINTER, DIMENSION(:) :: &
+         & cvars          !: Variable names
+
       CHARACTER(LEN=8), POINTER, DIMENSION(:) :: &
          & cwmo           !: WMO indentifier
@@ -130,4 +133,5 @@
       !!* Local variables
       INTEGER :: ji
+      INTEGER :: jvar
 
       ! Set bookkeeping variables
@@ -140,4 +144,14 @@
       surf%npi      = kpi
       surf%npj      = kpj
+
+      ! Allocate arrays of size number of variables
+
+      ALLOCATE( &
+         & surf%cvars(kvar)    &
+         & )
+
+      DO jvar = 1, kvar
+         surf%cvars(jvar) = "NotSet"
+      END DO
       
       ! Allocate arrays of number of surface data size
@@ -271,4 +285,10 @@
          & )
 
+      ! Dellocate arrays of size number of variables
+
+      DEALLOCATE( &
+         & surf%cvars     &
+         & )
+
    END SUBROUTINE obs_surf_dealloc
 
@@ -392,5 +412,6 @@
       ! Set book keeping variables which do not depend on number of obs.
 
-      newsurf%nstp  = surf%nstp
+      newsurf%nstp     = surf%nstp
+      newsurf%cvars(:) = surf%cvars(:)
  
       ! Deallocate temporary data
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_types.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_types.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_types.F90	(revision 6140)
@@ -117,5 +117,5 @@
 
          cwmonam1770(ji) = 'Not defined'
-         ctypshort(ji) = 'XBT'
+         ctypshort(ji) = '---'
 
 !         IF ( ji < 1000 ) THEN
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_vel_io.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_vel_io.F90	(revision 6139)
+++ 	(revision )
@@ -1,32 +1,0 @@
-MODULE obs_vel_io
-   !!======================================================================
-   !!                       ***  MODULE obs_vel_io  ***
-   !! Observation operators : I/O for TAO velocity data
-   !!======================================================================
-   !! History : 
-   !!             !  09-01  (K. Mogensen) Initial version based on obs_read_taovel
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!   read_taofile    :  Read a obfbdata structure from an TAO velocity file.
-   !!----------------------------------------------------------------------
-   USE par_kind
-   USE obs_utils
-   USE obs_fbm
-   USE obs_conv
-   USE in_out_manager
-   USE netcdf
-   IMPLICIT NONE
-
-   INTEGER, PARAMETER :: imaxlev = 10000
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-#include "obsvel_io.h90"
-
-END MODULE obs_vel_io
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90	(revision 6140)
@@ -6,9 +6,6 @@
 
    !!----------------------------------------------------------------------
-   !!   obs_wri_p3d   : Write profile observation diagnostics in NetCDF format
-   !!   obs_wri_sla   : Write SLA observation related diagnostics
-   !!   obs_wri_sst   : Write SST observation related diagnostics
-   !!   obs_wri_seaice: Write seaice observation related diagnostics
-   !!   obs_wri_vel   : Write velocity observation diagnostics in NetCDF format
+   !!   obs_wri_prof   : Write profile observations in feedback format
+   !!   obs_wri_surf   : Write surface observations in feedback format
    !!   obs_wri_stats : Print basic statistics on the data being written out
    !!----------------------------------------------------------------------
@@ -30,6 +27,4 @@
    USE obs_conv             ! Conversion between units
    USE obs_const
-   USE obs_sla_types
-   USE obs_rot_vel          ! Rotation of velocities
    USE obs_mpp              ! MPP support routines for observation diagnostics
    USE lib_mpp		    ! MPP routines
@@ -39,10 +34,6 @@
    !! * Routine accessibility
    PRIVATE
-   PUBLIC obs_wri_p3d, &    ! Write profile observation related diagnostics
-      &   obs_wri_sla, &    ! Write SLA observation related diagnostics
-      &   obs_wri_sst, &    ! Write SST observation related diagnostics
-      &   obs_wri_sss, &    ! Write SSS observation related diagnostics
-      &   obs_wri_seaice, & ! Write seaice observation related diagnostics
-      &   obs_wri_vel, &    ! Write velocity observation related diagnostics
+   PUBLIC obs_wri_prof, &    ! Write profile observation files
+      &   obs_wri_surf, &    ! Write surface observation files
       &   obswriinfo
    
@@ -63,11 +54,10 @@
 CONTAINS
 
-   SUBROUTINE obs_wri_p3d( cprefix, profdata, padd, pext )
+   SUBROUTINE obs_wri_prof( profdata, padd, pext )
       !!-----------------------------------------------------------------------
       !!
-      !!                     *** ROUTINE obs_wri_p3d  ***
-      !!
-      !! ** Purpose : Write temperature and salinity (profile) observation 
-      !!              related diagnostics
+      !!                     *** ROUTINE obs_wri_prof  ***
+      !!
+      !! ** Purpose : Write profile feedback files
       !!
       !! ** Method  : NetCDF
@@ -82,17 +72,16 @@
       !!      ! 07-03  (K. Mogensen) General handling of profiles
       !!      ! 09-01  (K. Mogensen) New feedback format
+      !!      ! 15-02  (M. Martin) Combined routine for writing profiles
       !!-----------------------------------------------------------------------
 
-      !! * Modules used
-
       !! * Arguments
-      CHARACTER(LEN=*), INTENT(IN) :: cprefix        ! Prefix for output files
       TYPE(obs_prof), INTENT(INOUT) :: profdata      ! Full set of profile data
       TYPE(obswriinfo), OPTIONAL :: padd             ! Additional info for each variable
       TYPE(obswriinfo), OPTIONAL :: pext             ! Extra info
-      
+
       !! * Local declarations
       TYPE(obfbdata) :: fbdata
-      CHARACTER(LEN=40) :: cfname
+      CHARACTER(LEN=40) :: clfname
+      CHARACTER(LEN=6) :: clfiletype
       INTEGER :: ilevel
       INTEGER :: jvar
@@ -102,20 +91,20 @@
       INTEGER :: ja
       INTEGER :: je
+      INTEGER :: iadd
+      INTEGER :: iext
       REAL(wp) :: zpres
-      INTEGER :: nadd
-      INTEGER :: next
 
       IF ( PRESENT( padd ) ) THEN
-         nadd = padd%inum
+         iadd = padd%inum
       ELSE
-         nadd = 0
+         iadd = 0
       ENDIF
 
       IF ( PRESENT( pext ) ) THEN
-         next = pext%inum
+         iext = pext%inum
       ELSE
-         next = 0
-      ENDIF
-      
+         iext = 0
+      ENDIF
+
       CALL init_obfbdata( fbdata )
 
@@ -125,45 +114,79 @@
          ilevel = MAX( ilevel, MAXVAL( profdata%var(jvar)%nvlidx(:) ) )
       END DO
-      CALL alloc_obfbdata( fbdata, 2, profdata%nprof, ilevel, &
-         &                 1 + nadd, 1 + next, .TRUE. )
-
-      fbdata%cname(1)      = 'POTM'
-      fbdata%cname(2)      = 'PSAL'
-      fbdata%coblong(1)    = 'Potential temperature'
-      fbdata%coblong(2)    = 'Practical salinity'
-      fbdata%cobunit(1)    = 'Degrees centigrade'
-      fbdata%cobunit(2)    = 'PSU'
-      fbdata%cextname(1)   = 'TEMP'
-      fbdata%cextlong(1)   = 'Insitu temperature'
-      fbdata%cextunit(1)   = 'Degrees centigrade'
-      DO je = 1, next
-         fbdata%cextname(1+je) = pext%cdname(je)
-         fbdata%cextlong(1+je) = pext%cdlong(je,1)
-         fbdata%cextunit(1+je) = pext%cdunit(je,1)
-      END DO
+
+      SELECT CASE ( TRIM(profdata%cvars(1)) )
+      CASE('POTM')
+
+         clfiletype='profb'
+         CALL alloc_obfbdata( fbdata, 2, profdata%nprof, ilevel, &
+            &                 1 + iadd, 1 + iext, .TRUE. )
+         fbdata%cname(1)      = profdata%cvars(1)
+         fbdata%cname(2)      = profdata%cvars(2)
+         fbdata%coblong(1)    = 'Potential temperature'
+         fbdata%coblong(2)    = 'Practical salinity'
+         fbdata%cobunit(1)    = 'Degrees centigrade'
+         fbdata%cobunit(2)    = 'PSU'
+         fbdata%cextname(1)   = 'TEMP'
+         fbdata%cextlong(1)   = 'Insitu temperature'
+         fbdata%cextunit(1)   = 'Degrees centigrade'
+         fbdata%caddlong(1,1) = 'Model interpolated potential temperature'
+         fbdata%caddlong(1,2) = 'Model interpolated practical salinity'
+         fbdata%caddunit(1,1) = 'Degrees centigrade'
+         fbdata%caddunit(1,2) = 'PSU'
+         fbdata%cgrid(:)      = 'T'
+         DO je = 1, iext
+            fbdata%cextname(1+je) = pext%cdname(je)
+            fbdata%cextlong(1+je) = pext%cdlong(je,1)
+            fbdata%cextunit(1+je) = pext%cdunit(je,1)
+         END DO
+         DO ja = 1, iadd
+            fbdata%caddname(1+ja) = padd%cdname(ja)
+            DO jvar = 1, 2
+               fbdata%caddlong(1+ja,jvar) = padd%cdlong(ja,jvar)
+               fbdata%caddunit(1+ja,jvar) = padd%cdunit(ja,jvar)
+            END DO
+         END DO
+
+      CASE('UVEL')
+
+         clfiletype='velfb'
+         CALL alloc_obfbdata( fbdata, 2, profdata%nprof, ilevel, 1, 0, .TRUE. )
+         fbdata%cname(1)      = profdata%cvars(1)
+         fbdata%cname(2)      = profdata%cvars(2)
+         fbdata%coblong(1)    = 'Zonal velocity'
+         fbdata%coblong(2)    = 'Meridional velocity'
+         fbdata%cobunit(1)    = 'm/s'
+         fbdata%cobunit(2)    = 'm/s'
+         DO je = 1, iext
+            fbdata%cextname(je) = pext%cdname(je)
+            fbdata%cextlong(je) = pext%cdlong(je,1)
+            fbdata%cextunit(je) = pext%cdunit(je,1)
+         END DO
+         fbdata%caddlong(1,1) = 'Model interpolated zonal velocity'
+         fbdata%caddlong(1,2) = 'Model interpolated meridional velocity'
+         fbdata%caddunit(1,1) = 'm/s'
+         fbdata%caddunit(1,2) = 'm/s'
+         fbdata%cgrid(1)      = 'U' 
+         fbdata%cgrid(2)      = 'V'
+         DO ja = 1, iadd
+            fbdata%caddname(1+ja) = padd%cdname(ja)
+            fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
+            fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
+         END DO
+
+      END SELECT
+
       fbdata%caddname(1)   = 'Hx'
-      fbdata%caddlong(1,1) = 'Model interpolated potential temperature'
-      fbdata%caddlong(1,2) = 'Model interpolated practical salinity'
-      fbdata%caddunit(1,1) = 'Degrees centigrade'
-      fbdata%caddunit(1,2) = 'PSU'
-      fbdata%cgrid(:)      = 'T'
-      DO ja = 1, nadd
-         fbdata%caddname(1+ja) = padd%cdname(ja)
-         DO jvar = 1, 2
-            fbdata%caddlong(1+ja,jvar) = padd%cdlong(ja,jvar)
-            fbdata%caddunit(1+ja,jvar) = padd%cdunit(ja,jvar)
-         END DO
-      END DO
-         
-      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cprefix), nproc
+
+      WRITE(clfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(clfiletype), nproc
 
       IF(lwp) THEN
          WRITE(numout,*)
-         WRITE(numout,*)'obs_wri_p3d :'
+         WRITE(numout,*)'obs_wri_prof :'
          WRITE(numout,*)'~~~~~~~~~~~~~'
-         WRITE(numout,*)'Writing profile feedback file : ',TRIM(cfname)
-      ENDIF
-
-      ! Transform obs_prof data structure into obfbdata structure
+         WRITE(numout,*)'Writing '//TRIM(clfiletype)//' feedback file : ',TRIM(clfname)
+      ENDIF
+
+      ! Transform obs_prof data structure into obfb data structure
       fbdata%cdjuldref = '19500101000000'
       DO jo = 1, profdata%nprof
@@ -222,13 +245,14 @@
                ENDIF
                fbdata%iobsk(ik,jo,jvar)  = profdata%var(jvar)%mvk(jk)
-               DO ja = 1, nadd
+               DO ja = 1, iadd
                   fbdata%padd(ik,jo,1+ja,jvar) = &
                      & profdata%var(jvar)%vext(jk,padd%ipoint(ja))
                END DO
-               DO je = 1, next
+               DO je = 1, iext
                   fbdata%pext(ik,jo,1+je) = &
                      & profdata%var(jvar)%vext(jk,pext%ipoint(je))
                END DO
-               IF ( jvar == 1 ) THEN
+               IF ( ( jvar == 1 ) .AND. &
+                  & ( TRIM(profdata%cvars(1)) == 'POTM' ) ) THEN
                   fbdata%pext(ik,jo,1) = profdata%var(jvar)%vext(jk,1)
                ENDIF 
@@ -237,26 +261,28 @@
       END DO
 
-      ! Convert insitu temperature to potential temperature using the model
-      ! salinity if no potential temperature
-      DO jo = 1, fbdata%nobs
-         IF ( fbdata%pphi(jo) < 9999.0 ) THEN
-            DO jk = 1, fbdata%nlev
-               IF ( ( fbdata%pob(jk,jo,1) >= 9999.0 ) .AND. &
-                  & ( fbdata%pdep(jk,jo) < 9999.0 ) .AND. &
-                  & ( fbdata%padd(jk,jo,1,2) < 9999.0 ) .AND. &
-                  & ( fbdata%pext(jk,jo,1) < 9999.0 ) ) THEN
-                  zpres = dep_to_p( REAL(fbdata%pdep(jk,jo),wp), &
-                     &              REAL(fbdata%pphi(jo),wp) )
-                  fbdata%pob(jk,jo,1) = potemp( &
-                     &                     REAL(fbdata%padd(jk,jo,1,2), wp),  &
-                     &                     REAL(fbdata%pext(jk,jo,1), wp), &
-                     &                     zpres, 0.0_wp )
-               ENDIF
-            END DO
-         ENDIF
-      END DO
-      
+      IF ( TRIM(profdata%cvars(1)) == 'POTM' ) THEN
+         ! Convert insitu temperature to potential temperature using the model
+         ! salinity if no potential temperature
+         DO jo = 1, fbdata%nobs
+            IF ( fbdata%pphi(jo) < 9999.0 ) THEN
+               DO jk = 1, fbdata%nlev
+                  IF ( ( fbdata%pob(jk,jo,1) >= 9999.0 ) .AND. &
+                     & ( fbdata%pdep(jk,jo) < 9999.0 ) .AND. &
+                     & ( fbdata%padd(jk,jo,1,2) < 9999.0 ) .AND. &
+                     & ( fbdata%pext(jk,jo,1) < 9999.0 ) ) THEN
+                     zpres = dep_to_p( REAL(fbdata%pdep(jk,jo),wp), &
+                        &              REAL(fbdata%pphi(jo),wp) )
+                     fbdata%pob(jk,jo,1) = potemp( &
+                        &                     REAL(fbdata%padd(jk,jo,1,2), wp),  &
+                        &                     REAL(fbdata%pext(jk,jo,1), wp), &
+                        &                     zpres, 0.0_wp )
+                  ENDIF
+               END DO
+            ENDIF
+         END DO
+      ENDIF
+
       ! Write the obfbdata structure
-      CALL write_obfbdata( cfname, fbdata )
+      CALL write_obfbdata( clfname, fbdata )
 
       ! Output some basic statistics
@@ -264,14 +290,13 @@
 
       CALL dealloc_obfbdata( fbdata )
-     
-   END SUBROUTINE obs_wri_p3d
-
-   SUBROUTINE obs_wri_sla( cprefix, sladata, padd, pext )
+
+   END SUBROUTINE obs_wri_prof
+
+   SUBROUTINE obs_wri_surf( surfdata, padd, pext )
       !!-----------------------------------------------------------------------
       !!
-      !!                     *** ROUTINE obs_wri_sla  ***
-      !!
-      !! ** Purpose : Write SLA observation diagnostics
-      !!              related 
+      !!                     *** ROUTINE obs_wri_surf  ***
+      !!
+      !! ** Purpose : Write surface observation files
       !!
       !! ** Method  : NetCDF
@@ -281,4 +306,5 @@
       !!      ! 07-03  (K. Mogensen) Original
       !!      ! 09-01  (K. Mogensen) New feedback format.
+      !!      ! 15-02  (M. Martin) Combined surface writing routine.
       !!-----------------------------------------------------------------------
 
@@ -287,6 +313,5 @@
 
       !! * Arguments
-      CHARACTER(LEN=*), INTENT(IN) :: cprefix          ! Prefix for output files
-      TYPE(obs_surf), INTENT(INOUT) :: sladata         ! Full set of SLAa
+      TYPE(obs_surf), INTENT(INOUT) :: surfdata         ! Full set of surface data
       TYPE(obswriinfo), OPTIONAL :: padd               ! Additional info for each variable
       TYPE(obswriinfo), OPTIONAL :: pext               ! Extra info
@@ -294,76 +319,130 @@
       !! * Local declarations
       TYPE(obfbdata) :: fbdata
-      CHARACTER(LEN=40) :: cfname         ! netCDF filename
-      CHARACTER(LEN=12), PARAMETER :: cpname = 'obs_wri_sla'
+      CHARACTER(LEN=40) :: clfname         ! netCDF filename
+      CHARACTER(LEN=6)  :: clfiletype
+      CHARACTER(LEN=12), PARAMETER :: cpname = 'obs_wri_surf'
       INTEGER :: jo
       INTEGER :: ja
       INTEGER :: je
-      INTEGER :: nadd
-      INTEGER :: next
+      INTEGER :: iadd
+      INTEGER :: iext
 
       IF ( PRESENT( padd ) ) THEN
-         nadd = padd%inum
+         iadd = padd%inum
       ELSE
-         nadd = 0
+         iadd = 0
       ENDIF
 
       IF ( PRESENT( pext ) ) THEN
-         next = pext%inum
+         iext = pext%inum
       ELSE
-         next = 0
+         iext = 0
       ENDIF
 
       CALL init_obfbdata( fbdata )
 
-      CALL alloc_obfbdata( fbdata, 1, sladata%nsurf, 1, &
-         &                 2 + nadd, 1 + next, .TRUE. )
-
-      fbdata%cname(1)      = 'SLA'
-      fbdata%coblong(1)    = 'Sea level anomaly'
-      fbdata%cobunit(1)    = 'Metres'
-      fbdata%cextname(1)   = 'MDT'
-      fbdata%cextlong(1)   = 'Mean dynamic topography'
-      fbdata%cextunit(1)   = 'Metres'
-      DO je = 1, next
-         fbdata%cextname(1+je) = pext%cdname(je)
-         fbdata%cextlong(1+je) = pext%cdlong(je,1)
-         fbdata%cextunit(1+je) = pext%cdunit(je,1)
-      END DO
+      SELECT CASE ( TRIM(surfdata%cvars(1)) )
+      CASE('SLA')
+
+         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
+            &                 2 + iadd, 1 + iext, .TRUE. )
+
+         clfiletype = 'slafb'
+         fbdata%cname(1)      = surfdata%cvars(1)
+         fbdata%coblong(1)    = 'Sea level anomaly'
+         fbdata%cobunit(1)    = 'Metres'
+         fbdata%cextname(1)   = 'MDT'
+         fbdata%cextlong(1)   = 'Mean dynamic topography'
+         fbdata%cextunit(1)   = 'Metres'
+         DO je = 1, iext
+            fbdata%cextname(je) = pext%cdname(je)
+            fbdata%cextlong(je) = pext%cdlong(je,1)
+            fbdata%cextunit(je) = pext%cdunit(je,1)
+         END DO
+         fbdata%caddlong(1,1) = 'Model interpolated SSH - MDT'
+         fbdata%caddunit(1,1) = 'Metres' 
+         fbdata%caddname(2)   = 'SSH'
+         fbdata%caddlong(2,1) = 'Model Sea surface height'
+         fbdata%caddunit(2,1) = 'Metres'
+         fbdata%cgrid(1)      = 'T'
+         DO ja = 1, iadd
+            fbdata%caddname(2+ja) = padd%cdname(ja)
+            fbdata%caddlong(2+ja,1) = padd%cdlong(ja,1)
+            fbdata%caddunit(2+ja,1) = padd%cdunit(ja,1)
+         END DO
+
+      CASE('SST')
+
+         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
+            &                 1 + iadd, iext, .TRUE. )
+
+         clfiletype = 'sstfb'
+         fbdata%cname(1)      = surfdata%cvars(1)
+         fbdata%coblong(1)    = 'Sea surface temperature'
+         fbdata%cobunit(1)    = 'Degree centigrade'
+         DO je = 1, iext
+            fbdata%cextname(je) = pext%cdname(je)
+            fbdata%cextlong(je) = pext%cdlong(je,1)
+            fbdata%cextunit(je) = pext%cdunit(je,1)
+         END DO
+         fbdata%caddlong(1,1) = 'Model interpolated SST'
+         fbdata%caddunit(1,1) = 'Degree centigrade'
+         fbdata%cgrid(1)      = 'T'
+         DO ja = 1, iadd
+            fbdata%caddname(1+ja) = padd%cdname(ja)
+            fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
+            fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
+         END DO
+
+      CASE('ICECON')
+
+         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
+            &                 1 + iadd, iext, .TRUE. )
+
+         clfiletype = 'sicfb'
+         fbdata%cname(1)      = surfdata%cvars(1)
+         fbdata%coblong(1)    = 'Sea ice'
+         fbdata%cobunit(1)    = 'Fraction'
+         DO je = 1, iext
+            fbdata%cextname(je) = pext%cdname(je)
+            fbdata%cextlong(je) = pext%cdlong(je,1)
+            fbdata%cextunit(je) = pext%cdunit(je,1)
+         END DO
+         fbdata%caddlong(1,1) = 'Model interpolated ICE'
+         fbdata%caddunit(1,1) = 'Fraction'
+         fbdata%cgrid(1)      = 'T'
+         DO ja = 1, iadd
+            fbdata%caddname(1+ja) = padd%cdname(ja)
+            fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
+            fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
+         END DO
+
+      END SELECT
+
       fbdata%caddname(1)   = 'Hx'
-      fbdata%caddlong(1,1) = 'Model interpolated SSH - MDT'
-      fbdata%caddunit(1,1) = 'Metres' 
-      fbdata%caddname(2)   = 'SSH'
-      fbdata%caddlong(2,1) = 'Model Sea surface height'
-      fbdata%caddunit(2,1) = 'Metres'
-      fbdata%cgrid(1)      = 'T'
-      DO ja = 1, nadd
-         fbdata%caddname(2+ja) = padd%cdname(ja)
-         fbdata%caddlong(2+ja,1) = padd%cdlong(ja,1)
-         fbdata%caddunit(2+ja,1) = padd%cdunit(ja,1)
-      END DO
-
-      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cprefix), nproc
+
+      WRITE(clfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(clfiletype), nproc
 
       IF(lwp) THEN
          WRITE(numout,*)
-         WRITE(numout,*)'obs_wri_sla :'
+         WRITE(numout,*)'obs_wri_surf :'
          WRITE(numout,*)'~~~~~~~~~~~~~'
-         WRITE(numout,*)'Writing SLA feedback file : ',TRIM(cfname)
-      ENDIF
-
-      ! Transform obs_prof data structure into obfbdata structure
+         WRITE(numout,*)'Writing '//TRIM(surfdata%cvars(1))//' feedback file : ',TRIM(clfname)
+      ENDIF
+
+      ! Transform surf data structure into obfbdata structure
       fbdata%cdjuldref = '19500101000000'
-      DO jo = 1, sladata%nsurf
-         fbdata%plam(jo)      = sladata%rlam(jo)
-         fbdata%pphi(jo)      = sladata%rphi(jo)
-         WRITE(fbdata%cdtyp(jo),'(I4)') sladata%ntyp(jo)
+      DO jo = 1, surfdata%nsurf
+         fbdata%plam(jo)      = surfdata%rlam(jo)
+         fbdata%pphi(jo)      = surfdata%rphi(jo)
+         WRITE(fbdata%cdtyp(jo),'(I4)') surfdata%ntyp(jo)
          fbdata%ivqc(jo,:)    = 0
          fbdata%ivqcf(:,jo,:) = 0
-         IF ( sladata%nqc(jo) > 10 ) THEN
+         IF ( surfdata%nqc(jo) > 10 ) THEN
             fbdata%ioqc(jo)    = 4
             fbdata%ioqcf(1,jo) = 0
-            fbdata%ioqcf(2,jo) = sladata%nqc(jo) - 10
+            fbdata%ioqcf(2,jo) = surfdata%nqc(jo) - 10
          ELSE
-            fbdata%ioqc(jo)    = sladata%nqc(jo)
+            fbdata%ioqc(jo)    = surfdata%nqc(jo)
             fbdata%ioqcf(:,jo) = 0
          ENDIF
@@ -372,51 +451,51 @@
          fbdata%itqc(jo)      = 0
          fbdata%itqcf(:,jo)   = 0
-         fbdata%cdwmo(jo)     = sladata%cwmo(jo)
-         fbdata%kindex(jo)    = sladata%nsfil(jo)
+         fbdata%cdwmo(jo)     = surfdata%cwmo(jo)
+         fbdata%kindex(jo)    = surfdata%nsfil(jo)
          IF (ln_grid_global) THEN
-            fbdata%iobsi(jo,1) = sladata%mi(jo)
-            fbdata%iobsj(jo,1) = sladata%mj(jo)
+            fbdata%iobsi(jo,1) = surfdata%mi(jo)
+            fbdata%iobsj(jo,1) = surfdata%mj(jo)
          ELSE
-            fbdata%iobsi(jo,1) = mig(sladata%mi(jo))
-            fbdata%iobsj(jo,1) = mjg(sladata%mj(jo))
+            fbdata%iobsi(jo,1) = mig(surfdata%mi(jo))
+            fbdata%iobsj(jo,1) = mjg(surfdata%mj(jo))
          ENDIF
          CALL greg2jul( 0, &
-            &           sladata%nmin(jo), &
-            &           sladata%nhou(jo), &
-            &           sladata%nday(jo), &
-            &           sladata%nmon(jo), &
-            &           sladata%nyea(jo), &
+            &           surfdata%nmin(jo), &
+            &           surfdata%nhou(jo), &
+            &           surfdata%nday(jo), &
+            &           surfdata%nmon(jo), &
+            &           surfdata%nyea(jo), &
             &           fbdata%ptim(jo),   &
             &           krefdate = 19500101 )
-         fbdata%padd(1,jo,1,1) = sladata%rmod(jo,1)
-         fbdata%padd(1,jo,2,1) = sladata%rext(jo,1)
-         fbdata%pob(1,jo,1)    = sladata%robs(jo,1) 
+         fbdata%padd(1,jo,1,1) = surfdata%rmod(jo,1)
+         IF ( TRIM(surfdata%cvars(1)) == 'SLA' ) fbdata%padd(1,jo,2,1) = surfdata%rext(jo,1)
+         fbdata%pob(1,jo,1)    = surfdata%robs(jo,1) 
          fbdata%pdep(1,jo)     = 0.0
          fbdata%idqc(1,jo)     = 0
          fbdata%idqcf(:,1,jo)  = 0
-         IF ( sladata%nqc(jo) > 10 ) THEN
+         IF ( surfdata%nqc(jo) > 10 ) THEN
             fbdata%ivqc(jo,1)       = 4
             fbdata%ivlqc(1,jo,1)    = 4
             fbdata%ivlqcf(1,1,jo,1) = 0
-            fbdata%ivlqcf(2,1,jo,1) = sladata%nqc(jo) - 10
+            fbdata%ivlqcf(2,1,jo,1) = surfdata%nqc(jo) - 10
          ELSE
-            fbdata%ivqc(jo,1)       = sladata%nqc(jo)
-            fbdata%ivlqc(1,jo,1)    = sladata%nqc(jo)
+            fbdata%ivqc(jo,1)       = surfdata%nqc(jo)
+            fbdata%ivlqc(1,jo,1)    = surfdata%nqc(jo)
             fbdata%ivlqcf(:,1,jo,1) = 0
          ENDIF
          fbdata%iobsk(1,jo,1)  = 0
-         fbdata%pext(1,jo,1) = sladata%rext(jo,2)
-         DO ja = 1, nadd
+         IF ( TRIM(surfdata%cvars(1)) == 'SLA' ) fbdata%pext(1,jo,1) = surfdata%rext(jo,2)
+         DO ja = 1, iadd
             fbdata%padd(1,jo,2+ja,1) = &
-               & sladata%rext(jo,padd%ipoint(ja))
-         END DO
-         DO je = 1, next
+               & surfdata%rext(jo,padd%ipoint(ja))
+         END DO
+         DO je = 1, iext
             fbdata%pext(1,jo,1+je) = &
-               & sladata%rext(jo,pext%ipoint(je))
+               & surfdata%rext(jo,pext%ipoint(je))
          END DO
       END DO
 
       ! Write the obfbdata structure
-      CALL write_obfbdata( cfname, fbdata )
+      CALL write_obfbdata( clfname, fbdata )
 
       ! Output some basic statistics
@@ -425,508 +504,5 @@
       CALL dealloc_obfbdata( fbdata )
 
-   END SUBROUTINE obs_wri_sla
-
-   SUBROUTINE obs_wri_sst( cprefix, sstdata, padd, pext )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     *** ROUTINE obs_wri_sst  ***
-      !!
-      !! ** Purpose : Write SST observation diagnostics
-      !!              related 
-      !!
-      !! ** Method  : NetCDF
-      !! 
-      !! ** Action  :
-      !!
-      !!      ! 07-07  (S. Ricci) Original
-      !!      ! 09-01  (K. Mogensen) New feedback format.
-      !!-----------------------------------------------------------------------
-
-      !! * Modules used
-      IMPLICIT NONE
-
-      !! * Arguments
-      CHARACTER(LEN=*), INTENT(IN) :: cprefix       ! Prefix for output files
-      TYPE(obs_surf), INTENT(INOUT) :: sstdata      ! Full set of SST
-      TYPE(obswriinfo), OPTIONAL :: padd            ! Additional info for each variable
-      TYPE(obswriinfo), OPTIONAL :: pext            ! Extra info
-
-      !! * Local declarations 
-      TYPE(obfbdata) :: fbdata
-      CHARACTER(LEN=40) ::  cfname             ! netCDF filename
-      CHARACTER(LEN=12), PARAMETER :: cpname = 'obs_wri_sst'
-      INTEGER :: jo
-      INTEGER :: ja
-      INTEGER :: je
-      INTEGER :: nadd
-      INTEGER :: next
-
-      IF ( PRESENT( padd ) ) THEN
-         nadd = padd%inum
-      ELSE
-         nadd = 0
-      ENDIF
-
-      IF ( PRESENT( pext ) ) THEN
-         next = pext%inum
-      ELSE
-         next = 0
-      ENDIF
-
-      CALL init_obfbdata( fbdata )
-
-      CALL alloc_obfbdata( fbdata, 1, sstdata%nsurf, 1, &
-         &                 1 + nadd, next, .TRUE. )
-
-      fbdata%cname(1)      = 'SST'
-      fbdata%coblong(1)    = 'Sea surface temperature'
-      fbdata%cobunit(1)    = 'Degree centigrade'
-      DO je = 1, next
-         fbdata%cextname(je) = pext%cdname(je)
-         fbdata%cextlong(je) = pext%cdlong(je,1)
-         fbdata%cextunit(je) = pext%cdunit(je,1)
-      END DO
-      fbdata%caddname(1)   = 'Hx'
-      fbdata%caddlong(1,1) = 'Model interpolated SST'
-      fbdata%caddunit(1,1) = 'Degree centigrade'
-      fbdata%cgrid(1)      = 'T'
-      DO ja = 1, nadd
-         fbdata%caddname(1+ja) = padd%cdname(ja)
-         fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
-         fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
-      END DO
-
-      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cprefix), nproc
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*)'obs_wri_sst :'
-         WRITE(numout,*)'~~~~~~~~~~~~~'
-         WRITE(numout,*)'Writing SST feedback file : ',TRIM(cfname)
-      ENDIF
-
-      ! Transform obs_prof data structure into obfbdata structure
-      fbdata%cdjuldref = '19500101000000'
-      DO jo = 1, sstdata%nsurf
-         fbdata%plam(jo)      = sstdata%rlam(jo)
-         fbdata%pphi(jo)      = sstdata%rphi(jo)
-         WRITE(fbdata%cdtyp(jo),'(I4)') sstdata%ntyp(jo)
-         fbdata%ivqc(jo,:)    = 0
-         fbdata%ivqcf(:,jo,:) = 0
-         IF ( sstdata%nqc(jo) > 10 ) THEN
-            fbdata%ioqc(jo)    = 4
-            fbdata%ioqcf(1,jo) = 0
-            fbdata%ioqcf(2,jo) = sstdata%nqc(jo) - 10
-         ELSE
-            fbdata%ioqc(jo)    = MAX(sstdata%nqc(jo),1)
-            fbdata%ioqcf(:,jo) = 0
-         ENDIF
-         fbdata%ipqc(jo)      = 0
-         fbdata%ipqcf(:,jo)   = 0
-         fbdata%itqc(jo)      = 0
-         fbdata%itqcf(:,jo)   = 0
-         fbdata%cdwmo(jo)     = ''
-         fbdata%kindex(jo)    = sstdata%nsfil(jo)
-         IF (ln_grid_global) THEN
-            fbdata%iobsi(jo,1) = sstdata%mi(jo)
-            fbdata%iobsj(jo,1) = sstdata%mj(jo)
-         ELSE
-            fbdata%iobsi(jo,1) = mig(sstdata%mi(jo))
-            fbdata%iobsj(jo,1) = mjg(sstdata%mj(jo))
-         ENDIF
-         CALL greg2jul( 0, &
-            &           sstdata%nmin(jo), &
-            &           sstdata%nhou(jo), &
-            &           sstdata%nday(jo), &
-            &           sstdata%nmon(jo), &
-            &           sstdata%nyea(jo), &
-            &           fbdata%ptim(jo),   &
-            &           krefdate = 19500101 )
-         fbdata%padd(1,jo,1,1) = sstdata%rmod(jo,1)
-         fbdata%pob(1,jo,1)    = sstdata%robs(jo,1)
-         fbdata%pdep(1,jo)     = 0.0
-         fbdata%idqc(1,jo)     = 0
-         fbdata%idqcf(:,1,jo)  = 0
-         IF ( sstdata%nqc(jo) > 10 ) THEN
-            fbdata%ivqc(jo,1)       = 4
-            fbdata%ivlqc(1,jo,1)    = 4
-            fbdata%ivlqcf(1,1,jo,1) = 0
-            fbdata%ivlqcf(2,1,jo,1) = sstdata%nqc(jo) - 10
-         ELSE
-            fbdata%ivqc(jo,1)       = MAX(sstdata%nqc(jo),1)
-            fbdata%ivlqc(1,jo,1)    = MAX(sstdata%nqc(jo),1)
-            fbdata%ivlqcf(:,1,jo,1) = 0
-         ENDIF
-         fbdata%iobsk(1,jo,1)  = 0
-         DO ja = 1, nadd
-            fbdata%padd(1,jo,1+ja,1) = &
-               & sstdata%rext(jo,padd%ipoint(ja))
-         END DO
-         DO je = 1, next
-            fbdata%pext(1,jo,je) = &
-               & sstdata%rext(jo,pext%ipoint(je))
-         END DO
-
-      END DO
-
-      ! Write the obfbdata structure
-
-      CALL write_obfbdata( cfname, fbdata )
-
-      ! Output some basic statistics
-      CALL obs_wri_stats( fbdata )
-
-      CALL dealloc_obfbdata( fbdata )
-
-   END SUBROUTINE obs_wri_sst
-
-   SUBROUTINE obs_wri_sss
-   END SUBROUTINE obs_wri_sss
-
-   SUBROUTINE obs_wri_seaice( cprefix, seaicedata, padd, pext )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     *** ROUTINE obs_wri_seaice  ***
-      !!
-      !! ** Purpose : Write sea ice observation diagnostics
-      !!              related 
-      !!
-      !! ** Method  : NetCDF
-      !! 
-      !! ** Action  :
-      !!
-      !!      ! 07-07  (S. Ricci) Original
-      !!      ! 09-01  (K. Mogensen) New feedback format.
-      !!-----------------------------------------------------------------------
-
-      !! * Modules used
-      IMPLICIT NONE
-
-      !! * Arguments
-      CHARACTER(LEN=*), INTENT(IN) :: cprefix       ! Prefix for output files
-      TYPE(obs_surf), INTENT(INOUT) :: seaicedata   ! Full set of sea ice
-      TYPE(obswriinfo), OPTIONAL :: padd            ! Additional info for each variable
-      TYPE(obswriinfo), OPTIONAL :: pext            ! Extra info
-
-      !! * Local declarations 
-      TYPE(obfbdata) :: fbdata
-      CHARACTER(LEN=40) :: cfname             ! netCDF filename
-      CHARACTER(LEN=12), PARAMETER :: cpname = 'obs_wri_seaice'
-      INTEGER :: jo
-      INTEGER :: ja
-      INTEGER :: je
-      INTEGER :: nadd
-      INTEGER :: next
-
-      IF ( PRESENT( padd ) ) THEN
-         nadd = padd%inum
-      ELSE
-         nadd = 0
-      ENDIF
-
-      IF ( PRESENT( pext ) ) THEN
-         next = pext%inum
-      ELSE
-         next = 0
-      ENDIF
-
-      CALL init_obfbdata( fbdata )
-
-      CALL alloc_obfbdata( fbdata, 1, seaicedata%nsurf, 1, 1, 0, .TRUE. )
-
-      fbdata%cname(1)      = 'SEAICE'
-      fbdata%coblong(1)    = 'Sea ice'
-      fbdata%cobunit(1)    = 'Fraction'
-      DO je = 1, next
-         fbdata%cextname(je) = pext%cdname(je)
-         fbdata%cextlong(je) = pext%cdlong(je,1)
-         fbdata%cextunit(je) = pext%cdunit(je,1)
-      END DO
-      fbdata%caddname(1)   = 'Hx'
-      fbdata%caddlong(1,1) = 'Model interpolated ICE'
-      fbdata%caddunit(1,1) = 'Fraction'
-      fbdata%cgrid(1)      = 'T'
-      DO ja = 1, nadd
-         fbdata%caddname(1+ja) = padd%cdname(ja)
-         fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
-         fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
-      END DO
-
-      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cprefix), nproc
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*)'obs_wri_seaice :'
-         WRITE(numout,*)'~~~~~~~~~~~~~~~~'
-         WRITE(numout,*)'Writing SEAICE feedback file : ',TRIM(cfname)
-      ENDIF
-
-      ! Transform obs_prof data structure into obfbdata structure
-      fbdata%cdjuldref = '19500101000000'
-      DO jo = 1, seaicedata%nsurf
-         fbdata%plam(jo)      = seaicedata%rlam(jo)
-         fbdata%pphi(jo)      = seaicedata%rphi(jo)
-         WRITE(fbdata%cdtyp(jo),'(I4)') seaicedata%ntyp(jo)
-         fbdata%ivqc(jo,:)    = 0
-         fbdata%ivqcf(:,jo,:) = 0
-         IF ( seaicedata%nqc(jo) > 10 ) THEN
-            fbdata%ioqc(jo)    = 4
-            fbdata%ioqcf(1,jo) = 0
-            fbdata%ioqcf(2,jo) = seaicedata%nqc(jo) - 10
-         ELSE
-            fbdata%ioqc(jo)    = MAX(seaicedata%nqc(jo),1)
-            fbdata%ioqcf(:,jo) = 0
-         ENDIF
-         fbdata%ipqc(jo)      = 0
-         fbdata%ipqcf(:,jo)   = 0
-         fbdata%itqc(jo)      = 0
-         fbdata%itqcf(:,jo)   = 0
-         fbdata%cdwmo(jo)     = ''
-         fbdata%kindex(jo)    = seaicedata%nsfil(jo)
-         IF (ln_grid_global) THEN
-            fbdata%iobsi(jo,1) = seaicedata%mi(jo)
-            fbdata%iobsj(jo,1) = seaicedata%mj(jo)
-         ELSE
-            fbdata%iobsi(jo,1) = mig(seaicedata%mi(jo))
-            fbdata%iobsj(jo,1) = mjg(seaicedata%mj(jo))
-         ENDIF
-         CALL greg2jul( 0, &
-            &           seaicedata%nmin(jo), &
-            &           seaicedata%nhou(jo), &
-            &           seaicedata%nday(jo), &
-            &           seaicedata%nmon(jo), &
-            &           seaicedata%nyea(jo), &
-            &           fbdata%ptim(jo),   &
-            &           krefdate = 19500101 )
-         fbdata%padd(1,jo,1,1) = seaicedata%rmod(jo,1)
-         fbdata%pob(1,jo,1)    = seaicedata%robs(jo,1)
-         fbdata%pdep(1,jo)     = 0.0
-         fbdata%idqc(1,jo)     = 0
-         fbdata%idqcf(:,1,jo)  = 0
-         IF ( seaicedata%nqc(jo) > 10 ) THEN
-            fbdata%ivlqc(1,jo,1) = 4
-            fbdata%ivlqcf(1,1,jo,1) = 0
-            fbdata%ivlqcf(2,1,jo,1) = seaicedata%nqc(jo) - 10
-         ELSE
-            fbdata%ivlqc(1,jo,1) = MAX(seaicedata%nqc(jo),1)
-            fbdata%ivlqcf(:,1,jo,1) = 0
-         ENDIF
-         fbdata%iobsk(1,jo,1)  = 0
-         DO ja = 1, nadd
-            fbdata%padd(1,jo,1+ja,1) = &
-               & seaicedata%rext(jo,padd%ipoint(ja))
-         END DO
-         DO je = 1, next
-            fbdata%pext(1,jo,je) = &
-               & seaicedata%rext(jo,pext%ipoint(je))
-         END DO
-
-      END DO
-
-      ! Write the obfbdata structure
-      CALL write_obfbdata( cfname, fbdata )
-
-      ! Output some basic statistics
-      CALL obs_wri_stats( fbdata )
-
-      CALL dealloc_obfbdata( fbdata )
-
-   END SUBROUTINE obs_wri_seaice
-
-   SUBROUTINE obs_wri_vel( cprefix, profdata, k2dint, padd, pext )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     *** ROUTINE obs_wri_vel  ***
-      !!
-      !! ** Purpose : Write current (profile) observation 
-      !!              related diagnostics
-      !!
-      !! ** Method  : NetCDF
-      !! 
-      !! ** Action  :
-      !!
-      !! History :
-      !!      ! 09-01  (K. Mogensen) New feedback format routine
-      !!-----------------------------------------------------------------------
-
-      !! * Modules used
-
-      !! * Arguments
-      CHARACTER(LEN=*), INTENT(IN) :: cprefix       ! Prefix for output files
-      TYPE(obs_prof), INTENT(INOUT) :: profdata     ! Full set of profile data
-      INTEGER, INTENT(IN) :: k2dint                 ! Horizontal interpolation method
-      TYPE(obswriinfo), OPTIONAL :: padd            ! Additional info for each variable
-      TYPE(obswriinfo), OPTIONAL :: pext            ! Extra info
-
-      !! * Local declarations
-      TYPE(obfbdata) :: fbdata
-      CHARACTER(LEN=40) :: cfname
-      INTEGER :: ilevel
-      INTEGER :: jvar
-      INTEGER :: jk
-      INTEGER :: ik
-      INTEGER :: jo
-      INTEGER :: ja
-      INTEGER :: je
-      INTEGER :: nadd
-      INTEGER :: next
-      REAL(wp) :: zpres
-      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zu, &
-         & zv
-
-      IF ( PRESENT( padd ) ) THEN
-         nadd = padd%inum
-      ELSE
-         nadd = 0
-      ENDIF
-
-      IF ( PRESENT( pext ) ) THEN
-         next = pext%inum
-      ELSE
-         next = 0
-      ENDIF
-
-      CALL init_obfbdata( fbdata )
-
-      ! Find maximum level
-      ilevel = 0
-      DO jvar = 1, 2
-         ilevel = MAX( ilevel, MAXVAL( profdata%var(jvar)%nvlidx(:) ) )
-      END DO
-      CALL alloc_obfbdata( fbdata, 2, profdata%nprof, ilevel, 2, 0, .TRUE. )
-
-      fbdata%cname(1)      = 'UVEL'
-      fbdata%cname(2)      = 'VVEL'
-      fbdata%coblong(1)    = 'Zonal velocity'
-      fbdata%coblong(2)    = 'Meridional velocity'
-      fbdata%cobunit(1)    = 'm/s'
-      fbdata%cobunit(2)    = 'm/s'
-      DO je = 1, next
-         fbdata%cextname(je) = pext%cdname(je)
-         fbdata%cextlong(je) = pext%cdlong(je,1)
-         fbdata%cextunit(je) = pext%cdunit(je,1)
-      END DO
-      fbdata%caddname(1)   = 'Hx'
-      fbdata%caddlong(1,1) = 'Model interpolated zonal velocity'
-      fbdata%caddlong(1,2) = 'Model interpolated meridional velocity'
-      fbdata%caddunit(1,1) = 'm/s'
-      fbdata%caddunit(1,2) = 'm/s'
-      fbdata%caddname(2)   = 'HxG'
-      fbdata%caddlong(2,1) = 'Model interpolated zonal velocity (model grid)'
-      fbdata%caddlong(2,2) = 'Model interpolated meridional velocity (model grid)'
-      fbdata%caddunit(2,1) = 'm/s'
-      fbdata%caddunit(2,2) = 'm/s' 
-      fbdata%cgrid(1)      = 'U' 
-      fbdata%cgrid(2)      = 'V'
-      DO ja = 1, nadd
-         fbdata%caddname(2+ja) = padd%cdname(ja)
-         fbdata%caddlong(2+ja,1) = padd%cdlong(ja,1)
-         fbdata%caddunit(2+ja,1) = padd%cdunit(ja,1)
-      END DO
-
-      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cprefix), nproc
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*)'obs_wri_vel :'
-         WRITE(numout,*)'~~~~~~~~~~~~~'
-         WRITE(numout,*)'Writing velocuty feedback file : ',TRIM(cfname)
-      ENDIF
-
-      ALLOCATE( &
-         & zu(profdata%nvprot(1)), &
-         & zv(profdata%nvprot(2))  &
-         & )
-      CALL obs_rotvel( profdata, k2dint, zu, zv )
-
-      ! Transform obs_prof data structure into obfbdata structure
-      fbdata%cdjuldref = '19500101000000'
-      DO jo = 1, profdata%nprof
-         fbdata%plam(jo)      = profdata%rlam(jo)
-         fbdata%pphi(jo)      = profdata%rphi(jo)
-         WRITE(fbdata%cdtyp(jo),'(I4)') profdata%ntyp(jo)
-         fbdata%ivqc(jo,:)    = profdata%ivqc(jo,:)
-         fbdata%ivqcf(:,jo,:) = profdata%ivqcf(:,jo,:)
-         IF ( profdata%nqc(jo) > 10 ) THEN
-            fbdata%ioqc(jo)    = 4
-            fbdata%ioqcf(1,jo) = profdata%nqcf(1,jo)
-            fbdata%ioqcf(2,jo) = profdata%nqc(jo) - 10
-         ELSE
-            fbdata%ioqc(jo)    = profdata%nqc(jo)
-            fbdata%ioqcf(:,jo) = profdata%nqcf(:,jo)
-         ENDIF
-         fbdata%ipqc(jo)      = profdata%ipqc(jo)
-         fbdata%ipqcf(:,jo)   = profdata%ipqcf(:,jo)
-         fbdata%itqc(jo)      = profdata%itqc(jo)
-         fbdata%itqcf(:,jo)   = profdata%itqcf(:,jo)
-         fbdata%cdwmo(jo)     = profdata%cwmo(jo)
-         fbdata%kindex(jo)    = profdata%npfil(jo)
-         DO jvar = 1, profdata%nvar
-            IF (ln_grid_global) THEN
-               fbdata%iobsi(jo,jvar) = profdata%mi(jo,jvar)
-               fbdata%iobsj(jo,jvar) = profdata%mj(jo,jvar)
-            ELSE
-               fbdata%iobsi(jo,jvar) = mig(profdata%mi(jo,jvar))
-               fbdata%iobsj(jo,jvar) = mjg(profdata%mj(jo,jvar))
-            ENDIF
-         END DO
-         CALL greg2jul( 0, &
-            &           profdata%nmin(jo), &
-            &           profdata%nhou(jo), &
-            &           profdata%nday(jo), &
-            &           profdata%nmon(jo), &
-            &           profdata%nyea(jo), &
-            &           fbdata%ptim(jo),   &
-            &           krefdate = 19500101 )
-         ! Reform the profiles arrays for output
-         DO jvar = 1, 2
-            DO jk = profdata%npvsta(jo,jvar), profdata%npvend(jo,jvar)
-               ik = profdata%var(jvar)%nvlidx(jk)
-               IF ( jvar == 1 ) THEN
-                  fbdata%padd(ik,jo,1,jvar) = zu(jk)
-               ELSE
-                  fbdata%padd(ik,jo,1,jvar) = zv(jk)
-               ENDIF
-               fbdata%padd(ik,jo,2,jvar) = profdata%var(jvar)%vmod(jk)
-               fbdata%pob(ik,jo,jvar)    = profdata%var(jvar)%vobs(jk)
-               fbdata%pdep(ik,jo)        = profdata%var(jvar)%vdep(jk)
-               fbdata%idqc(ik,jo)        = profdata%var(jvar)%idqc(jk)
-               fbdata%idqcf(:,ik,jo)     = profdata%var(jvar)%idqcf(:,jk)
-               IF ( profdata%var(jvar)%nvqc(jk) > 10 ) THEN
-                  fbdata%ivlqc(ik,jo,jvar) = 4
-                  fbdata%ivlqcf(1,ik,jo,jvar) = profdata%var(jvar)%nvqcf(1,jk)
-                  fbdata%ivlqcf(2,ik,jo,jvar) = profdata%var(jvar)%nvqc(jk) - 10
-               ELSE
-                  fbdata%ivlqc(ik,jo,jvar) = profdata%var(jvar)%nvqc(jk)
-                  fbdata%ivlqcf(:,ik,jo,jvar) = profdata%var(jvar)%nvqcf(:,jk)
-               ENDIF
-               fbdata%iobsk(ik,jo,jvar)  = profdata%var(jvar)%mvk(jk)
-               DO ja = 1, nadd
-                  fbdata%padd(ik,jo,2+ja,jvar) = &
-                     & profdata%var(jvar)%vext(jk,padd%ipoint(ja))
-               END DO
-               DO je = 1, next
-                  fbdata%pext(ik,jo,je) = &
-                     & profdata%var(jvar)%vext(jk,pext%ipoint(je))
-               END DO
-            END DO
-         END DO
-      END DO
-
-      ! Write the obfbdata structure
-      CALL write_obfbdata( cfname, fbdata )
-      
-      ! Output some basic statistics
-      CALL obs_wri_stats( fbdata )
-
-      CALL dealloc_obfbdata( fbdata )
-     
-      DEALLOCATE( &
-         & zu, &
-         & zv  &
-         & )
-
-   END SUBROUTINE obs_wri_vel
+   END SUBROUTINE obs_wri_surf
 
    SUBROUTINE obs_wri_stats( fbdata )
@@ -951,18 +527,15 @@
       INTEGER :: jo
       INTEGER :: jk
-
-!      INTEGER :: nlev
-!      INTEGER :: nlevmpp
-!      INTEGER :: nobsmpp
-      INTEGER :: numgoodobs
-      INTEGER :: numgoodobsmpp
+      INTEGER :: inumgoodobs
+      INTEGER :: inumgoodobsmpp
       REAL(wp) :: zsumx
       REAL(wp) :: zsumx2
       REAL(wp) :: zomb
+      
 
       IF (lwp) THEN
          WRITE(numout,*) ''
          WRITE(numout,*) 'obs_wri_stats :'
-         WRITE(numout,*) '~~~~~~~~~~~~~~~' 
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
       ENDIF
 
@@ -970,5 +543,5 @@
          zsumx=0.0_wp
          zsumx2=0.0_wp
-         numgoodobs=0
+         inumgoodobs=0
          DO jo = 1, fbdata%nobs
             DO jk = 1, fbdata%nlev
@@ -976,24 +549,24 @@
                   & ( fbdata%pdep(jk,jo) < 9999.0 ) .AND. &
                   & ( fbdata%padd(jk,jo,1,jvar) < 9999.0 ) ) THEN
-	    
-	          zomb=fbdata%pob(jk, jo, jvar)-fbdata%padd(jk, jo, 1, jvar)
+
+                  zomb=fbdata%pob(jk, jo, jvar)-fbdata%padd(jk, jo, 1, jvar)
                   zsumx=zsumx+zomb
                   zsumx2=zsumx2+zomb**2
-                  numgoodobs=numgoodobs+1
-	       ENDIF
+                  inumgoodobs=inumgoodobs+1
+               ENDIF
             ENDDO
          ENDDO
 
-         CALL obs_mpp_sum_integer( numgoodobs, numgoodobsmpp )
+         CALL obs_mpp_sum_integer( inumgoodobs, inumgoodobsmpp )
          CALL mpp_sum(zsumx)
          CALL mpp_sum(zsumx2)
 
          IF (lwp) THEN
-	    WRITE(numout,*) 'Type: ',fbdata%cname(jvar),'  Total number of good observations: ',numgoodobsmpp 
-	    WRITE(numout,*) 'Overall mean obs minus model of the good observations: ',zsumx/numgoodobsmpp
-            WRITE(numout,*) 'Overall RMS obs minus model of the good observations: ',sqrt( zsumx2/numgoodobsmpp )
-	    WRITE(numout,*) ''
+            WRITE(numout,*) 'Type: ',fbdata%cname(jvar),'  Total number of good observations: ',inumgoodobsmpp 
+            WRITE(numout,*) 'Overall mean obs minus model of the good observations: ',zsumx/inumgoodobsmpp
+            WRITE(numout,*) 'Overall RMS obs minus model of the good observations: ',sqrt( zsumx2/inumgoodobsmpp )
+            WRITE(numout,*) ''
          ENDIF
- 
+
       ENDDO
 
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obsprof_io.h90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obsprof_io.h90	(revision 6139)
+++ 	(revision )
@@ -1,834 +1,0 @@
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE read_enactfile( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_enactfile **
-      !!
-      !! ** Purpose : Read from file the profile ENACT observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      INTEGER :: iobs                ! Number of observations
-      INTEGER :: ilev                      ! Number of levels
-      INTEGER :: i_file_id
-      INTEGER :: i_obs_id
-      INTEGER :: i_lev_id
-      INTEGER :: i_phi_id
-      INTEGER :: i_lam_id
-      INTEGER :: i_depth_id
-      INTEGER :: i_var_id
-      INTEGER :: i_pl_num_id
-      INTEGER :: i_reference_date_time_id
-      INTEGER :: i_format_version_id
-      INTEGER :: i_juld_id
-      INTEGER :: i_data_type_id
-      INTEGER :: i_wmo_inst_type_id
-      INTEGER :: i_qc_var_id
-      INTEGER :: i_dc_ref_id
-      INTEGER :: i_qc_flag_id
-      CHARACTER(LEN=40) :: cl_fld_lam
-      CHARACTER(LEN=40) :: cl_fld_phi
-      CHARACTER(LEN=40) :: cl_fld_depth 
-      CHARACTER(LEN=40) :: cl_fld_var_tp
-      CHARACTER(LEN=40) :: cl_fld_var_s
-      CHARACTER(LEN=40) :: cl_fld_var_ti
-      CHARACTER(LEN=40) :: cl_fld_var_juld_qc
-      CHARACTER(LEN=40) :: cl_fld_var_pos_qc
-      CHARACTER(LEN=40) :: cl_fld_var_depth_qc 
-      CHARACTER(LEN=40) :: cl_fld_var_qc_t
-      CHARACTER(LEN=40) :: cl_fld_var_qc_s
-      CHARACTER(LEN=40) :: cl_fld_var_prof_qc_t
-      CHARACTER(LEN=40) :: cl_fld_var_prof_qc_s
-      CHARACTER(LEN=40) :: cl_fld_reference_date_time
-      CHARACTER(LEN=40) :: cl_fld_juld
-      CHARACTER(LEN=40) :: cl_fld_data_type
-      CHARACTER(LEN=40) :: cl_fld_pl_num
-      CHARACTER(LEN=40) :: cl_fld_format_version
-      CHARACTER(LEN=40) :: cl_fld_wmo_inst_type
-      CHARACTER(LEN=40) :: cl_fld_qc_flags_profiles
-      CHARACTER(LEN=40) :: cl_fld_qc_flags_levels
-
-      CHARACTER(LEN=14), PARAMETER :: cl_name = 'read_enactfile'
-      CHARACTER(LEN=16)            :: cl_data_type = ''
-      CHARACTER(LEN=4 )            :: cl_format_version = ''
-      INTEGER, DIMENSION(1) :: istart1, icount1
-      INTEGER, DIMENSION(2) :: istart2, icount2
-      CHARACTER(len=imaxlev) :: clqc
-      CHARACTER(len=1) :: cqc
-      INTEGER :: ji, jk
-      INTEGER, ALLOCATABLE, DIMENSION(:) :: iqc1
-      INTEGER, ALLOCATABLE, DIMENSION(:,:) :: iqc2
-
-      !-----------------------------------------------------------------------
-      ! Initialization
-      !-----------------------------------------------------------------------
-
-      cl_fld_lam                 = 'LONGITUDE'
-      cl_fld_phi                 = 'LATITUDE'
-      cl_fld_depth               = 'DEPH_CORRECTED'
-      cl_fld_reference_date_time = 'REFERENCE_DATE_TIME'
-      cl_fld_juld                = 'JULD'
-      cl_fld_data_type           = 'DATA_TYPE'
-      cl_fld_format_version      = 'FORMAT_VERSION'
-      cl_fld_wmo_inst_type       = 'WMO_INST_TYPE'
-      cl_fld_pl_num              = 'PLATFORM_NUMBER'
-
-      cl_fld_var_qc_t            = 'POTM_CORRECTED_QC'
-      cl_fld_var_prof_qc_t       = 'PROFILE_POTM_QC'
-      cl_fld_var_tp              = 'POTM_CORRECTED'
-      cl_fld_var_qc_s            = 'PSAL_CORRECTED_QC'
-      cl_fld_var_prof_qc_s       = 'PROFILE_PSAL_QC'
-      cl_fld_var_s               = 'PSAL_CORRECTED'
-      cl_fld_var_depth_qc        = 'DEPH_CORRECTED_QC'
-      cl_fld_var_juld_qc         = 'JULD_QC'
-      cl_fld_var_pos_qc          = 'POSITION_QC'
-      cl_fld_var_ti              = 'TEMP'
-      cl_fld_qc_flags_profiles   = 'QC_FLAGS_PROFILES'
-      cl_fld_qc_flags_levels     = 'QC_FLAGS_LEVELS'
-
-      icount1(1) = 1 
-
-      !-----------------------------------------------------------------------
-      ! Open file
-      !-----------------------------------------------------------------------
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-            &      i_file_id ),           cl_name, __LINE__ )
-
-      !-----------------------------------------------------------------------
-      ! Read the heading of the file
-      !-----------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_data_type,      &
-         &         i_data_type_id ),      cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_data_type_id,        &
-         &         cl_data_type ),        cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_format_version, &
-         &         i_format_version_id ), cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_format_version_id,   &
-         &         cl_format_version ),   cl_name, __LINE__ )
-      
-      CALL str_c_to_for( cl_data_type )
-      CALL str_c_to_for( cl_format_version )
-      
-      IF(ldwp)WRITE(kunit,*)
-      IF(ldwp)WRITE(kunit,*) ' read_enactfile :' 
-      IF(ldwp)WRITE(kunit,*) ' ~~~~~~~~~~~~~~~~'
-      IF(ldwp)WRITE(kunit,*) '               Data type           = ', &
-         &                TRIM( ADJUSTL( cl_data_type ) )
-      IF(ldwp)WRITE(kunit,*) '               Format version      = ',  &
-         &                TRIM( ADJUSTL( cl_format_version ) )
-      
-      IF ( ( ( INDEX( cl_data_type,"ENACT v1.0" ) == 1 ) .OR.   &
-         &   ( INDEX( cl_data_type,"ENACT v1.4" ) == 1 ) .OR.   &
-         &   ( INDEX( cl_data_type,"ENACT v1.5" ) == 1 ) .OR.   &
-         &   ( INDEX( cl_data_type,"ENSEMBLES EN3 v1" ) == 1 )      ) &
-         &   .AND.                                              &
-         &   ( INDEX( cl_format_version,"2.0"   ) == 1 ) ) THEN
-         IF(ldwp)WRITE(kunit,*)'               Valid input file'
-      ELSE
-         CALL fatal_error( 'Invalid input file', __LINE__ )
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Read the number of observations and levels to allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'N_PROF', i_obs_id ),         &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_obs_id, len = iobs ),     &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'N_LEVELS', i_lev_id ),     &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_lev_id, len = ilev ), &
-         &         cl_name, __LINE__ )
-      IF(ldwp)WRITE(kunit,*) '               No. of data records = ', iobs
-      IF(ldwp)WRITE(kunit,*) '               No. of levels       = ', ilev
-      IF(ldwp)WRITE(kunit,*) 
-      IF (ilev > imaxlev) THEN
-         CALL fatal_error( 'Increase imaxlev in obs_prof_io.F90', __LINE__ )
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 1, ldgrid )
-      inpfile%cname(1) = 'POTM'
-      inpfile%cname(2) = 'PSAL'
-      inpfile%coblong(1) = 'Potential temperature'
-      inpfile%coblong(2) = 'Practical salinity'
-      inpfile%cobunit(1) = 'Degrees Celsius'
-      inpfile%cobunit(2) = 'PSU'
-      inpfile%cextname(1) = 'TEMP'
-      inpfile%cextlong(1) = 'Insitu temperature'
-      inpfile%cextunit(1) = 'Degrees Celsius'
-
-      !---------------------------------------------------------------------
-      ! Read the QC atributes
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_t, i_qc_var_id ),                         &
-         &         cl_name, __LINE__ )        
-      istart2(1) = 1
-      icount2(2) = 1
-      icount2(1) = ilev
-      DO ji = 1, iobs 
-         istart2(2) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                   &
-            &                         start = istart2, count = icount2),                              &
-            &         cl_name, __LINE__ )
-         DO jk = 1, ilev
-            inpfile%ivlqc(jk,ji,1) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-         END DO
-      END DO
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_s, i_qc_var_id ),                         &
-         &         cl_name, __LINE__ )
-      DO ji = 1, iobs
-         istart2(2) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                   &
-            &                         start = istart2, count = icount2),                              &
-            &         cl_name, __LINE__ )
-         DO jk = 1, ilev
-            inpfile%ivlqc(jk,ji,2) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-         END DO
-      END DO
-      ! No depth QC in files
-      DO ji = 1, iobs
-         DO jk = 1, ilev
-            inpfile%idqc(jk,ji)  = 1
-            inpfile%idqcf(:,jk,ji) = 0
-         END DO
-      END DO
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_t, i_qc_var_id ),                    &
-         &         cl_name,  __LINE__ )
-      DO ji = 1,iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ivqc(ji,1) = IACHAR( cqc ) - IACHAR( '0' )
-      END DO
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_s, i_qc_var_id ),                    & 
-         &         cl_name, __LINE__ ) 
-      DO ji = 1,iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ivqc(ji,2) = IACHAR( cqc ) - IACHAR( '0' )
-      END DO
-!!      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_juld_qc, i_qc_var_id ),                       &
-!!         &         cl_name, __LINE__ ) 
-!!      !DO ji = 1,iobs
-!!         istart1(1) = ji
-!!         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-!!            &                         start = istart1, count = icount1),                              &
-!!            &         cl_name, __LINE__ )
-!!         inpfile%itqc(ji)    = IACHAR( cqc ) - IACHAR( '0' )
-!!         inpfile%itqcf(:,ji) = 0
-!!      END DO
-      ! Since the flags are not set in the ENACT files we reset them to 0
-      inpfile%itqc(:)    = 1      
-      inpfile%itqcf(:,:) = 0
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_pos_qc, i_qc_var_id ),                       &
-         &         cl_name, __LINE__ ) 
-      DO ji = 1,iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ipqc(ji)    = IACHAR( cqc ) - IACHAR( '0' )
-         inpfile%ipqcf(:,ji) = 0
-      END DO
-      DO ji = 1,iobs
-         inpfile%ioqc(ji) = MIN( inpfile%ivqc(ji,1), inpfile%ivqc(ji,2) )
-      END DO
-      IF ( nf90_inq_varid( i_file_id, cl_fld_qc_flags_profiles, i_qc_flag_id ) == nf90_noerr ) THEN
-         ALLOCATE( &
-            & iqc1(iobs) &
-            & )
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_flag_id, iqc1 ),                                &
-            &         cl_name, __LINE__ )
-         DO ji = 1,iobs
-            inpfile%ioqcf(1,ji)   = iqc1(ji)
-            inpfile%ivqcf(1,ji,:) = iqc1(ji)
-            inpfile%ioqcf(2,ji)   = 0
-            inpfile%ivqcf(2,ji,:) = 0
-         END DO
-         DEALLOCATE( &
-            & iqc1 &
-            & )
-      ELSE
-         IF(ldwp) WRITE(kunit,*)'No QC profile flags in file'
-         inpfile%ioqcf(:,:)   = 0
-         inpfile%ivqcf(:,:,:) = 0
-      ENDIF
-      IF ( nf90_inq_varid( i_file_id, cl_fld_qc_flags_levels, i_qc_flag_id ) == nf90_noerr ) THEN
-         ALLOCATE( &
-            & iqc2(ilev,iobs) &
-            & )
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_flag_id, iqc2 ),                                &
-            &         cl_name, __LINE__ )
-         DO ji = 1,iobs
-            DO jk = 1,ilev
-               inpfile%ivlqcf(1,jk,ji,:) = iqc2(jk,ji)
-               inpfile%ivlqcf(2,jk,ji,:) = 0
-            END DO
-         END DO
-         DEALLOCATE( &
-            & iqc2 &
-            & )
-      ELSE
-         IF(ldwp) WRITE(kunit,*)'No QC level flags in file'
-         inpfile%ivlqcf(:,:,:,:) = 0
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Read the time/position variables 
-      !---------------------------------------------------------------------
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_juld, i_juld_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_juld_id, inpfile%ptim ),                              &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ),                             &
-            &         cl_name, __LINE__ )         
-      CALL chkerr( nf90_get_var  ( i_file_id, i_depth_id, inpfile%pdep ),                             &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_phi_id, inpfile%pphi ),                               &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_lam_id, inpfile%plam ),                               &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_reference_date_time, i_reference_date_time_id ), &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_reference_date_time_id, inpfile%cdjuldref ),          &
-         &         cl_name, __LINE__ )
-      
-      !---------------------------------------------------------------------
-      ! Read the platform information
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_wmo_inst_type, i_wmo_inst_type_id ),             &
-         &         cl_name, __LINE__ )          
-      CALL chkerr( nf90_get_var  ( i_file_id, i_wmo_inst_type_id, inpfile%cdtyp ),                    &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pl_num, i_pl_num_id ),                           &
-         &         cl_name, __LINE__ )         
-      CALL chkerr( nf90_get_var  ( i_file_id, i_pl_num_id, inpfile%cdwmo ),                           &
-         &         cl_name, __LINE__ )         
-
-      !---------------------------------------------------------------------
-      ! Read the variables
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_tp, i_var_id ),                              &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pob(:,:,1) ),                         &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_s, i_var_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pob(:,:,2) ),                         &
-         &         cl_name, __LINE__ )
- 
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_ti, i_var_id ),                              &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pext(:,:,1) ),                        &
-         &         cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Close file
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_close( i_file_id ),           cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Set file indexes
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         inpfile%kindex(ji) = ji
-      END DO
-
-   END SUBROUTINE read_enactfile
-
-   SUBROUTINE read_coriofile( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_coriofile **
-      !!
-      !! ** Purpose : Read from file the profile CORIO observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output enactfile structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      INTEGER  :: &
-         & iobs, &
-         & ilev
-      !! * Local declarations
-      INTEGER :: &
-         & i_file_id,                &
-         & i_obs_id,                 &
-         & i_lev_id,                 &
-         & i_phi_id,                 & 
-         & i_lam_id,                 &
-         & i_depth_id,               &
-         & i_pres_id,                &
-         & i_var_id,                 &
-         & i_pl_num_id,              &
-         & i_format_version_id,      &
-         & i_juld_id,                &
-         & i_data_type_id,           &
-         & i_wmo_inst_type_id,       &
-         & i_qc_var_id,              &
-         & i_dc_ref_id
-      CHARACTER(LEN=40) :: & 
-         & cl_fld_lam,                 &
-         & cl_fld_phi,                 &
-         & cl_fld_depth,               & 
-         & cl_fld_depth_qc,            & 
-         & cl_fld_pres,                & 
-         & cl_fld_pres_qc,             & 
-         & cl_fld_var_t,               &
-         & cl_fld_var_s,               &
-         & cl_fld_var_ti,              &
-         & cl_fld_var_pos_qc,          &
-         & cl_fld_var_qc_t,            &
-         & cl_fld_var_qc_s,            &
-         & cl_fld_var_prof_qc_t,       &
-         & cl_fld_var_prof_qc_s,       &
-         & cl_fld_dc_ref,              &
-         & cl_fld_juld,                &
-         & cl_fld_pl_num,              &
-         & cl_fld_wmo_inst_type
-      CHARACTER(LEN=14), PARAMETER :: &
-         & cl_name = 'read_coriofile'
-      CHARACTER(LEN=4 )            :: &
-         & cl_format_version = ''
-      INTEGER, DIMENSION(1) :: &
-         & istart1, icount1
-      INTEGER, DIMENSION(2) :: &
-         & istart2, icount2
-      CHARACTER(len=imaxlev) :: &
-         & clqc
-      CHARACTER(len=1) :: &
-         & cqc
-      CHARACTER(len=256) :: &
-         & cdjulref
-      INTEGER :: &
-         & ji, jk
-      INTEGER :: &
-         & iformat
-      LOGICAL :: & 
-         & lsal
-      REAL(fbdp), DIMENSION(:,:), ALLOCATABLE :: &
-         & zpres
-      INTEGER, DIMENSION(:,:), ALLOCATABLE :: &
-         & ipresqc
-      CHARACTER(len=256) :: &
-         & cerr
-      !-----------------------------------------------------------------------
-      ! Initialization
-      !-----------------------------------------------------------------------
-
-      icount1(1) = 1 
-      lsal = .TRUE.
-
-      !-----------------------------------------------------------------------
-      ! Open file
-      !-----------------------------------------------------------------------
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-            &      i_file_id ),           cl_name, __LINE__ )
-
-      !-----------------------------------------------------------------------
-      ! Check format and set variables accordingly
-      !-----------------------------------------------------------------------
-
-      IF ( ( nf90_inq_dimid( i_file_id, 'N_PROF', i_obs_id ) == nf90_noerr ) .AND. &
-         & ( nf90_inq_dimid( i_file_id, 'N_LEVELS', i_lev_id ) == nf90_noerr ) ) THEN
-         iformat = 1
-      ELSEIF ( ( nf90_inq_dimid( i_file_id, 'mN_PROF', i_obs_id ) == nf90_noerr ) .AND. &
-         & ( nf90_inq_dimid( i_file_id, 'mN_ZLEV', i_lev_id ) == nf90_noerr ) ) THEN
-         iformat = 2
-      ELSE
-         WRITE(cerr,'(2A)')'Invalid data format in ',cl_name
-         CALL fatal_error( cerr, __LINE__ )
-      ENDIF
-      IF ( iformat == 1 ) THEN
-         cl_fld_lam                 = 'LONGITUDE'
-         cl_fld_phi                 = 'LATITUDE'  
-         cl_fld_depth               = 'DEPH'
-         cl_fld_depth_qc            = 'DEPH_QC'
-         cl_fld_pres                = 'PRES'
-         cl_fld_pres_qc             = 'PRES_QC'
-         cl_fld_juld                = 'JULD'
-         cl_fld_wmo_inst_type       = 'WMO_INST_TYPE'
-         cl_fld_dc_ref              = 'DC_REFERENCE'
-         cl_fld_pl_num              = 'PLATFORM_NUMBER'
-         cl_fld_var_qc_t            = 'TEMP_QC'
-         cl_fld_var_prof_qc_t       = 'PROFILE_TEMP_QC'
-         cl_fld_var_t               = 'TEMP'
-         cl_fld_var_qc_s            = 'PSAL_QC'
-         cl_fld_var_prof_qc_s       = 'PROFILE_PSAL_QC'
-         cl_fld_var_s               = 'PSAL'
-         cl_fld_var_pos_qc          = 'POSITION_QC'
-      ELSEIF ( iformat==2 ) THEN
-         cl_fld_lam                 = 'LONGITUDE'
-         cl_fld_phi                 = 'LATITUDE'  
-         cl_fld_depth               = 'DEPH'
-         cl_fld_depth_qc            = 'QC_DEPH'
-         cl_fld_pres                = 'PRES'
-         cl_fld_pres_qc             = 'QC_PRES'
-         cl_fld_juld                = 'JULD'
-         cl_fld_wmo_inst_type       = 'INST_TYPE'
-         cl_fld_dc_ref              = 'REFERENCE'
-         cl_fld_pl_num              = 'PLATFORM_NUMBER'
-         cl_fld_var_qc_t            = 'QC_TEMP'
-         cl_fld_var_prof_qc_t       = 'Q_PROFILE_TEMP'
-         cl_fld_var_t               = 'TEMP'
-         cl_fld_var_qc_s            = 'QC_PSAL'
-         cl_fld_var_prof_qc_s       = 'Q_PROFILE_PSAL'
-         cl_fld_var_s               = 'PSAL'
-         cl_fld_var_pos_qc          = 'Q_POSITION'
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Read the heading of the file
-      !-----------------------------------------------------------------------
-
-      IF(ldwp)WRITE(kunit,*)
-      IF(ldwp)WRITE(kunit,*) ' read_coriofile :' 
-      IF(ldwp)WRITE(kunit,*) ' ~~~~~~~~~~~~~~~~'
-      IF(ldwp)WRITE(kunit,*) '               Format version      = ', iformat
-
-      !---------------------------------------------------------------------
-      ! Read the number of observations and levels to allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_obs_id, len = iobs ), &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_lev_id, len = ilev ), &
-         &         cl_name, __LINE__ )
-      IF(ldwp)WRITE(kunit,*) '               No. of data records = ', iobs
-      IF(ldwp)WRITE(kunit,*) '               No. of levels       = ', ilev
-      IF(ldwp)WRITE(kunit,*) 
-      IF (ilev > imaxlev) THEN
-         CALL fatal_error( 'Increase imaxlev in obs_prof_io.F90', __LINE__ )
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 1, ldgrid )
-      inpfile%cname(1) = 'POTM'
-      inpfile%cname(2) = 'PSAL'
-      inpfile%coblong(1) = 'Potential temperature'
-      inpfile%coblong(2) = 'Practical salinity'
-      inpfile%cobunit(1) = 'Degrees Celsius'
-      inpfile%cobunit(2) = 'PSU'
-      inpfile%cextname(1) = 'TEMP'
-      inpfile%cextlong(1) = 'Insitu temperature'
-      inpfile%cextunit(1) = 'Degrees Celsius'
-      ALLOCATE( &
-         & zpres(ilev,iobs),  &
-         & ipresqc(ilev,iobs) &
-         & )
-      !---------------------------------------------------------------------
-      ! Get julian data reference (iformat==2)
-      !---------------------------------------------------------------------
-
-      IF (iformat==2) THEN
-         CALL chkerr ( nf90_get_att( i_file_id, nf90_global, &
-            &                        "Reference_date_time", cdjulref ), &
-            &         cl_name, __LINE__ )
-         inpfile%cdjuldref = cdjulref(7:10)//cdjulref(4:5)// &
-            & cdjulref(1:2)//cdjulref(12:13)//cdjulref(15:16)//cdjulref(18:19)
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Read the QC attributes
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_t, i_qc_var_id ),                                &
-         &         cl_name, __LINE__ )
-      istart2(1) = 1
-      icount2(2) = 1
-      icount2(1) = ilev
-      DO ji = 1, iobs 
-         istart2(2) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                   &
-            &                         start = istart2, count = icount2),                              &
-            &         cl_name, __LINE__ )
-         DO jk = 1, ilev
-            inpfile%ivlqc(jk,ji,1) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-         END DO
-      END DO
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_s, i_qc_var_id ) == nf90_noerr ) THEN
-         DO ji = 1, iobs
-            istart2(2) = ji
-            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                &
-               &                         start = istart2, count = icount2),                           &
-               &         cl_name, __LINE__ )
-            DO jk = 1, ilev
-               inpfile%ivlqc(jk,ji,2) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-            END DO
-         END DO
-      ELSE
-         inpfile%ivlqc(:,:,2) = 4
-         inpfile%pob(:,:,2) = fbrmdi
-         lsal = .FALSE.
-      ENDIF
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_t, i_qc_var_id ),                    &
-         &         cl_name,  __LINE__ )
-      DO ji = 1,iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ivqc(ji,1) = IACHAR( cqc ) - IACHAR( '0' )
-      END DO
-      IF (lsal) THEN
-         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_s, i_qc_var_id ),                 & 
-            &         cl_name, __LINE__ ) 
-         DO ji = 1,iobs
-            istart1(1) = ji
-            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                 &
-               &                         start = istart1, count = icount1),                           &
-               &         cl_name, __LINE__ )
-            inpfile%ivqc(ji,2) = IACHAR( cqc ) - IACHAR( '0' )
-         END DO
-      ELSE
-         inpfile%ivqc(:,2) = 4
-      ENDIF
-      DO ji = 1,iobs
-         inpfile%ioqc(ji) = MIN( inpfile%ivqc(ji,1), inpfile%ivqc(ji,2) )
-      END DO
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_pos_qc, i_qc_var_id ),                       &
-         &         cl_name, __LINE__ ) 
-      DO ji = 1, iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ipqc(ji)  = IACHAR( cqc ) - IACHAR( '0' )
-      END DO
-      
-      !---------------------------------------------------------------------
-      ! Read the time/position variables 
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_juld, i_juld_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_juld_id, inpfile%ptim ),                              &
-         &         cl_name, __LINE__ )
-      IF (iformat==1) THEN
-         CALL chkerr ( nf90_get_att( i_file_id, i_juld_id, &
-            &                        "units", cdjulref ), &
-            &         cl_name, __LINE__ )
-         inpfile%cdjuldref = cdjulref(12:15)//cdjulref(17:18)// &
-            & cdjulref(20:21)//cdjulref(23:24)//cdjulref(26:27)//&
-            & cdjulref(29:30)
-      ENDIF
-      
-      IF ( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ) == nf90_noerr ) THEN
-         CALL chkerr( nf90_get_var  ( i_file_id, i_depth_id, inpfile%pdep ),                          &
-            &         cl_name, __LINE__ )
-         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth_qc, i_qc_var_id ),                      & 
-            &         cl_name, __LINE__ ) 
-         DO ji = 1, iobs
-            istart2(2) = ji
-            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                &
-               &                         start = istart2, count = icount2),                           &
-               &         cl_name, __LINE__ )
-            DO jk = 1, ilev
-               inpfile%idqc(jk,ji) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-            END DO
-         END DO
-      ELSE
-         inpfile%pdep(:,:) = fbrmdi
-         inpfile%idqc(:,:) = 4
-      ENDIF
-
-      IF ( nf90_inq_varid( i_file_id, cl_fld_pres, i_pres_id ) == nf90_noerr ) THEN
-         CALL chkerr( nf90_get_var  ( i_file_id, i_pres_id, zpres ),                                  &
-            &         cl_name, __LINE__ )
-         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pres_qc, i_qc_var_id ),                       & 
-            &         cl_name, __LINE__ ) 
-         DO ji = 1, iobs
-            istart2(2) = ji
-            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                &
-               &                         start = istart2, count = icount2),                           &
-               &         cl_name, __LINE__ )
-            DO jk = 1, ilev
-               ipresqc(jk,ji) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-            END DO
-         END DO
-      ELSE
-         zpres(:,:) = fbrmdi
-         ipresqc(:,:) = 4
-      ENDIF
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_phi_id, inpfile%pphi ),                               &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_lam_id, inpfile%plam ),                               &
-         &         cl_name, __LINE__ )
-      
-      !---------------------------------------------------------------------
-      ! Read the platform information
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_wmo_inst_type, i_wmo_inst_type_id ),             &
-         &         cl_name, __LINE__ )          
-      CALL chkerr( nf90_get_var  ( i_file_id, i_wmo_inst_type_id, inpfile%cdtyp ),                    &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pl_num, i_pl_num_id ),                           &
-         &         cl_name, __LINE__ )         
-      CALL chkerr( nf90_get_var  ( i_file_id, i_pl_num_id, inpfile%cdwmo ),                           &
-         &         cl_name, __LINE__ )         
-
-      
-      !---------------------------------------------------------------------
-      ! Read the variables
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_t, i_var_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pext(:,:,1) ),                        &
-         &         cl_name, __LINE__ )
-
-      IF (lsal) THEN      
-         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_s, i_var_id ),                            &
-            &         cl_name, __LINE__ )
-         CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pob(:,:,2) ),                      &
-            &         cl_name, __LINE__ )
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Close file
-      !---------------------------------------------------------------------
-         
-      CALL chkerr( nf90_close( i_file_id ),           cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Set file indexes
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         inpfile%kindex(ji) = ji
-      END DO
-      
-      !---------------------------------------------------------------------
-      !  Coriolis data conversion from insitu to potential temperature
-      !---------------------------------------------------------------------
-      !---------------------------------------------------------------------
-      !  Convert pressure to depth if depth not present
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         IF ( inpfile%pphi(ji) < 9999.0 ) THEN
-            DO jk = 1, inpfile%nlev
-               IF ( inpfile%pdep(jk,ji) >= 9999.0 ) THEN
-                  IF ( zpres(jk,ji) < 9999.0 ) THEN
-                     inpfile%pdep(jk,ji) = &
-                        & p_to_dep( REAL(zpres(jk,ji),wp), REAL(inpfile%pphi(ji),wp) )
-                     inpfile%idqc(jk,ji) = ipresqc(jk,ji)
-                  ENDIF
-               ENDIF
-            END DO
-         ENDIF
-      END DO
-      
-      !---------------------------------------------------------------------
-      !  Convert depth to pressure if pressure not present
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         IF ( inpfile%pphi(ji) < 9999.0 ) THEN
-            DO jk = 1, inpfile%nlev
-               IF ( zpres(jk,ji) >= 9999.0 ) THEN
-                  IF ( inpfile%pdep(jk,ji) < 9999.0 ) THEN
-                     zpres(jk,ji) = dep_to_p( REAL(inpfile%pdep(jk,ji),wp), &
-                        &                            REAL(inpfile%pphi(ji),wp) )
-                     ipresqc(jk,ji) = inpfile%idqc(jk,ji)
-                  ENDIF
-               ENDIF
-            END DO
-         ENDIF
-      END DO
-      
-      !---------------------------------------------------------------------
-      !  Convert insitu temperature to potential temperature if
-      !  salinity, insitu temperature and pressure are present
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         DO jk = 1, inpfile%nlev
-            IF (( inpfile%pob(jk,ji,2) < 9999.0 ) .AND. &
-               &( inpfile%pext(jk,ji,1) < 9999.0 ) .AND. &
-               &( zpres(jk,ji) < 9999.0 ) ) THEN
-               inpfile%pob(jk,ji,1) = potemp( REAL(inpfile%pob(jk,ji,2), wp),  &
-                  &                           REAL(inpfile%pext(jk,ji,1), wp), &
-                  &                           REAL(zpres(jk,ji),wp),  &
-                  &                           0.0_wp )
-            ELSE
-               inpfile%pob(jk,ji,1) = fbrmdi
-            ENDIF
-         END DO
-      END DO
-
-      !---------------------------------------------------------------------
-      !  Initialize flags since they are not in the CORIOLIS input files
-      !---------------------------------------------------------------------
-
-      inpfile%ioqcf(:,:)      = 0
-      inpfile%ipqcf(:,:)      = 0
-      inpfile%itqcf(:,:)      = 0
-      inpfile%idqcf(:,:,:)    = 0
-      inpfile%ivqcf(:,:,:)    = 0
-      inpfile%ivlqcf(:,:,:,:) = 0
-
-   END SUBROUTINE read_coriofile
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obsseaice_io.h90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obsseaice_io.h90	(revision 6139)
+++ 	(revision )
@@ -1,270 +1,0 @@
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE read_seaice( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_seaice **
-      !!
-      !! ** Purpose : Read from file the SEAICE observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! References : 
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      CHARACTER(LEN=12),PARAMETER :: cpname = 'read_seaice'
-      INTEGER :: i_file_id    ! netcdf IDS
-      INTEGER :: i_time_id
-      INTEGER :: i_ni_id
-      INTEGER :: i_data_id
-      INTEGER :: i_var_id
-      INTEGER :: i_data       ! Number of data per parameter in current file
-      INTEGER :: i_time       ! Number of reference times in file
-      INTEGER, DIMENSION(:), POINTER :: &
-         & i_reftime        ! Reference time in file in seconds since 1/1/1981.
-      INTEGER, DIMENSION(:,:), POINTER :: &
-         & i_dtime, &       ! Offset in seconds since reference time
-         & i_qc,    &       ! Quality control flag.
-         & i_type           ! Type of seaice measurement.            
-      REAL(wp), DIMENSION(:), POINTER :: &
-         & z_phi,   &       ! Latitudes
-         & z_lam            ! Longitudes
-      REAL(wp), DIMENSION(:,:), POINTER :: &
-         & z_seaice         ! Seaice data     
-      INTEGER, PARAMETER :: imaxdim = 2    ! Assumed maximum for no. dims. in file
-      INTEGER, DIMENSION(2) :: idims       ! Dimensions in file
-      INTEGER :: iilen          ! Length of netCDF attributes
-      INTEGER :: itype          ! Typeof netCDF attributes
-      REAL(KIND=wp) :: zsca      ! Scale factor
-      REAL(KIND=wp) :: zoff      ! Offset for data in netcdf file
-      REAL(KIND=wp) :: z_offset  ! Offset for time conversion
-      REAL(KIND=wp) :: zfill     ! Fill value in netcdf file
-      CHARACTER (len=33) ::creftime     ! Reference time of file
-      INTEGER :: i_refyear       ! Integer version of reference time
-      INTEGER :: i_refmonth
-      INTEGER :: i_refday
-      INTEGER :: i_refhour
-      INTEGER :: i_refmin
-      INTEGER :: i_refsec
-      INTEGER :: ichunk
-      INTEGER :: jtim
-      INTEGER :: jobs
-      INTEGER :: iobs
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-         &                i_file_id, chunksize=ichunk), cpname, __LINE__ )
-      
-      ! Get the netCDF dimensions
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'time', i_time_id ),  &
-         &       cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_time_id, &
-         &                              len = i_time ),  &
-         &      cpname, __LINE__ )
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'ni', i_ni_id ),  &
-         &       cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_ni_id, &
-         &                              len = i_data ),  &
-         &      cpname, __LINE__ )
-      
-      
-      ! Allocate NetCDF variables
-      
-      ALLOCATE( &
-         & i_reftime    ( i_time                 ), &
-         & i_dtime      ( i_data,i_time  ), &      
-         & i_qc         ( i_data,i_time  ), & 
-         & i_type       ( i_data,i_time  ), &     
-         & z_phi        ( i_data                 ), &   
-         & z_lam        ( i_data                 ), &  
-         & z_seaice        ( i_data,i_time  )  &
-         & )
-      
-      ! Get reference time of file which is in seconds since 1981/1/1 00:00. 
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'time', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_time
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_reftime),&
-         &       cpname, __LINE__ )
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "units") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "units",creftime), cpname,  __LINE__ )
-      ELSE
-         creftime = "seconds since 1981-01-01 00:00:00"
-      ENDIF
-      READ(creftime(15:18),*)i_refyear
-      READ(creftime(20:21),*)i_refmonth
-      READ(creftime(23:24),*)i_refday
-      READ(creftime(26:27),*)i_refhour
-      READ(creftime(29:30),*)i_refmin
-      READ(creftime(32:33),*)i_refsec
-      !Work out offset in days between reference time and 1/1/1950.
-      CALL greg2jul( i_refsec, i_refmin, i_refhour, i_refday, &
-         &           i_refmonth, i_refyear, z_offset)
-      
-      ! Get list of times for each ob in seconds relative to reference time
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'SeaIce_dtime', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_dtime),&
-         &       cpname, __LINE__ )
-      zsca = 1.0      
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "scale_factor",zsca), cpname,  __LINE__ )
-      ENDIF
-      zoff = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "add_offset") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "add_offset",zoff), cpname,  __LINE__ )
-      ENDIF
-      i_dtime(:,:) = NINT((zsca * FLOAT(i_dtime(:,:))) &
-         &                 + zoff)
-      
-      ! Get longitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'lon', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_lam),   &
-         &         cpname, __LINE__ )
-      
-      ! Get latitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'lat', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_phi),   &
-         &         cpname, __LINE__ )
-      
-      ! Get seaice data
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'sea_ice_concentration', &
-         &                         i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_seaice), &
-         &       cpname, __LINE__ )
-      zoff = 0.
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "scale_factor",zsca), cpname, __LINE__ )
-      ENDIF
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       "scale_factor",zsca), cpname, __LINE__ )
-      ENDIF
-      zfill = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "_FillValue") &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       "_FillValue",zfill), cpname, __LINE__ )
-      ENDIF
-      WHERE(z_seaice(:,:) /=  zfill)
-         z_seaice(:,:) = (zsca * z_seaice(:,:)) + zoff
-      ELSEWHERE
-         z_seaice(:,:) = fbrmdi
-      END WHERE
-      
-      ! Get QC flag
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'confidence_flag', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_qc),   &
-            &       cpname, __LINE__ )
-      
-      ! Get seaice obs type
-      
-      i_type(:,:)=1
-      
-      ! Close the file
-      
-      CALL chkerr( nf90_close( i_file_id ), cpname, __LINE__ )
-
-      ! Fill the obfbdata structure
-
-      ! Allocate obfbdata
-      
-      iobs = i_data * i_time
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 1, iobs, 1, 0, 0, ldgrid )
-      inpfile%cname(1) = 'SEAICE'
-
-      ! Fill the obfbdata structure from input data
-
-      inpfile%cdjuldref = "19500101000000"
-      iobs = 0
-      DO jtim = 1, i_time
-         DO jobs = 1, i_data
-            iobs = iobs + 1
-            ! Characters
-            WRITE(inpfile%cdwmo(iobs),'(A6,A2)') 'seaice','  '
-            WRITE(inpfile%cdtyp(iobs),'(I4)') i_type(jobs,jtim)
-            ! Real values
-            inpfile%plam(iobs)         = z_lam(jobs)
-            inpfile%pphi(iobs)         = z_phi(jobs)
-            inpfile%pob(1,iobs,1)      = z_seaice(jobs,jtim)
-            inpfile%ptim(iobs)         = &
-               & REAL(i_reftime(jtim))/(60.*60.*24.) + &
-               & z_offset + REAL(i_dtime(jobs,jtim))/(60.*60.*24.)
-            inpfile%pdep(1,iobs)       = 0.0
-            ! Integers
-            inpfile%kindex(iobs)       = iobs
-            IF ( z_seaice(jobs,jtim) == fbrmdi ) THEN
-               inpfile%ioqc(iobs)      = 4
-               inpfile%ivqc(iobs,1)    = 4 
-               inpfile%ivlqc(1,iobs,1) = 4
-            ELSE 
-               inpfile%ioqc(iobs)      = i_qc(jobs,jtim)
-               inpfile%ivqc(iobs,1)    = i_qc(jobs,jtim)
-               inpfile%ivlqc(1,iobs,1) = 1
-            ENDIF
-            inpfile%ipqc(iobs)         = 0 
-            inpfile%ipqcf(:,iobs)      = 0
-            inpfile%itqc(iobs)         = 0
-            inpfile%itqcf(:,iobs)      = 0
-            inpfile%ivqcf(:,iobs,1)    = 0
-            inpfile%ioqcf(:,iobs)      = 0
-            inpfile%idqc(1,iobs)       = 0
-            inpfile%idqcf(1,1,iobs)    = 0
-            inpfile%ivlqcf(:,1,iobs,1) = 0
-         END DO
-      END DO
-
-   END SUBROUTINE read_seaice
-
-
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obssla_io.h90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obssla_io.h90	(revision 6139)
+++ 	(revision )
@@ -1,378 +1,0 @@
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE read_avisofile( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_avisofile **
-      !!
-      !! ** Purpose : Read from file the AVISO SLA observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! References : http://www.aviso.oceanobs.com
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      CHARACTER(LEN=14),PARAMETER :: cpname = 'read_avisofile'
-      INTEGER :: i_file_id     ! netcdf IDS
-      INTEGER :: i_tracks_id
-      INTEGER :: i_cycles_id
-      INTEGER :: i_data_id
-      INTEGER :: i_var_id
-      INTEGER, PARAMETER :: imaxdim = 2    ! Assumed maximum for no. dims. in file
-      INTEGER, DIMENSION(2) :: idims       ! Dimensions in file
-      INTEGER :: iilen         ! Length of netCDF attributes
-      INTEGER :: itype         ! Typeof netCDF attributes
-      REAL(fbdp) :: zsca       ! Scale factor
-      REAL(fbdp) :: zfill      ! Fill value
-      CHARACTER(len=3) ::  cmission      ! Mission global attribute
-      INTEGER :: itracks       ! Maximum number of passes in file
-      INTEGER :: icycles       ! Maximum number of cycles for each pass
-      INTEGER :: idata         ! Number of data per parameter in current file
-      REAL(fbdp) :: zdeltat    ! Time gap getween two measurements in seconds
-      INTEGER, DIMENSION(:), POINTER :: & 
-         & iptracks,     &  ! List of passes contained in current file
-         & ipnbpoints,   &  ! Number of points per pass
-         & ipdataindexes    ! Index of data in theoretical profile
-      INTEGER, DIMENSION(:,:), POINTER :: & 
-         & ipcycles         ! List of cycles per pass
-      REAL(fbdp), DIMENSION(:), POINTER :: &
-         & zphi,   &        ! Latitudes
-         & zlam             ! Longitudes
-      REAL(fbdp), DIMENSION(:,:), POINTER :: &
-         & zbegindates      ! Date of point with index 0
-      REAL(fbdp) :: zbeginmiss    ! Missing data for dates
-      REAL(fbsp), DIMENSION(:,:), POINTER :: &
-         & zsla             ! SLA data
-      REAL(fbdp), DIMENSION(:), POINTER :: &
-         & zjuld            ! Julian date
-      LOGICAL, DIMENSION(:), POINTER :: &
-         & llskip           ! Skip observation
-      CHARACTER(len=14) :: cdjuldref    ! Julian data reference
-      INTEGER :: imission   ! Mission number converted from Mission global 
-                            ! netCDF atttribute.
-      CHARACTER(len=255) :: ctmp
-      INTEGER :: iobs
-      INTEGER :: jl
-      INTEGER :: jm
-      INTEGER :: jj
-      INTEGER :: ji
-      INTEGER :: jk
-      INTEGER :: jobs
-      INTEGER :: jcycle
-
-      ! Open the file
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, i_file_id ), &
-         &         cpname, __LINE__ )
-
-      ! Get the netCDF dimensions
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'Tracks', i_tracks_id ),  &
-         &         cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_tracks_id, &
-         &                                 len = itracks ),  &
-         &         cpname, __LINE__ )
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'Cycles', i_cycles_id ),  &
-         &         cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_cycles_id, &
-         &                                 len = icycles ),  &
-         &      cpname, __LINE__ )
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'Data', i_data_id ),  &
-         &         cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_data_id, &
-         &                                 len = idata ),  &
-         &         cpname, __LINE__ )
-
-      ! Allocate memory for input data
-
-      ALLOCATE( &
-         & iptracks     ( itracks          ), &  
-         & ipnbpoints   ( itracks          ), &  
-         & ipcycles     ( icycles, itracks ), &
-         & zphi         ( idata            ), &   
-         & zlam         ( idata            ), &  
-         & zbegindates  ( icycles, itracks ), &
-         & ipdataindexes( idata            ), & 
-         & zsla         ( icycles, idata   ), &
-         & zjuld        ( idata*icycles    ), &
-         & llskip       ( idata*icycles    )  &
-         & )
-
-      ! Get time gap getween two measurements in seconds
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'DeltaT', i_var_id ), & 
-         &         cpname, __LINE__ )
-      CALL chkdim( i_file_id, i_var_id, 0, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zdeltat), &
-         &         cpname, __LINE__ )
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     'scale_factor',zsca), cpname,  __LINE__)
-      ENDIF
-      zdeltat = zsca * zdeltat
-         
-      ! Get List of passes contained in current file      
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'Tracks', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = itracks
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, iptracks), &
-         &         cpname, __LINE__ )
-      
-      ! Get Number of points per pass
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'NbPoints', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = itracks
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, ipnbpoints),&
-         &         cpname, __LINE__ )
-      
-      ! Get list of cycles per pass
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'Cycles', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = icycles
-      idims(2) = itracks
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, ipcycles),   &
-         &         cpname, __LINE__ )
-
-      ! Get longitudes
-
-      CALL chkerr( nf90_inq_varid( i_file_id, 'Longitudes', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = idata
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zlam),   &
-         &         cpname, __LINE__ )
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
-         &                         == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     'scale_factor',zsca), cpname,  __LINE__)
-      ENDIF
-      zlam(:) = zsca * zlam(:)
-      
-      ! Get latitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'Latitudes', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = idata
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zphi),   &
-         &         cpname, __LINE__ )
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     'scale_factor',zsca), cpname,  __LINE__)
-      ENDIF
-      zphi(:) = zsca * zphi(:)
-      
-      ! Get date of point with index 0
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'BeginDates', i_var_id ), & 
-         &        cpname, __LINE__ )
-      idims(1) = icycles
-      idims(2) = itracks
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zbegindates), &
-         &         cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_attribute( i_file_id, i_var_id, &
-         &                                 'units', len = iilen,  &
-         &                                  xtype = itype), cpname, __LINE__ )
-      IF (( itype /= NF90_CHAR ) .OR. ( iilen > 255 )) THEN
-         CALL fatal_error('Error decoding BeginDates unit', __LINE__ )
-      ENDIF
-      CALL chkerr( nf90_get_att( i_file_id, i_var_id, 'units', &
-         &                       ctmp ), cpname, __LINE__ )
-      jl=1
-      DO jm = 1, LEN(TRIM(ctmp))
-         IF ((ctmp(jm:jm)>='0').AND.(ctmp(jm:jm)<='9')) THEN
-            cdjuldref(jl:jl) = ctmp(jm:jm)
-            jl=jl+1
-         ENDIF
-         IF (jl>14) EXIT
-      END DO
-      CALL chkerr( nf90_inquire_attribute( i_file_id, i_var_id, '_FillValue', &
-         &                                  xtype = itype), cpname, __LINE__ )
-      IF ( itype /= NF90_DOUBLE ) THEN
-         CALL fatal_error('Error decoding BeginDates missing data', __LINE__ )
-      ENDIF
-      CALL chkerr( nf90_get_att( i_file_id, i_var_id, '_FillValue', &
-         &                       zbeginmiss ), cpname, __LINE__ )
-
-      ! Get indices of data in theoretical profile
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'DataIndexes', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = idata
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, ipdataindexes),   &
-         &       cpname, __LINE__ )
-      
-      ! Get SLA data
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'SLA', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = icycles
-      idims(2) = idata
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zsla),   &
-         &         cpname, __LINE__ )
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
-         &                        == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       'scale_factor',zsca), cpname, __LINE__ )
-      ENDIF
-      zfill = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, '_FillValue') &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     '_FillValue',zfill), cpname,  __LINE__ )
-      ENDIF
-      WHERE(zsla(:,:) /=  zfill)
-         zsla(:,:) = zsca * zsla(:,:)
-      ELSEWHERE
-         zsla(:,:) = fbrmdi
-      END WHERE
-      
-      ! Get the global Mission netCDF attribute
-      
-      cmission='   '
-      CALL chkerr( nf90_inquire_attribute( i_file_id, nf90_global, &
-         &                                 'Mission', len = iilen,  &
-         &                                 xtype = itype), cpname, __LINE__ )
-      IF (( itype /= NF90_CHAR ) .OR. ( iilen > 3 )) THEN
-         CALL fatal_error('Error decoding Mission global attribute', __LINE__ )
-      ENDIF
-      CALL chkerr( nf90_get_att( i_file_id, nf90_global, 'Mission', &
-         &                       cmission ), cpname, __LINE__ )
-      
-      ! Convert it to an integer
-      imission = 0
-      DO jm = 1, imaxmissions
-         IF (cmission==cmissions(jm)) THEN
-            imission = jm
-            EXIT
-         ENDIF
-      END DO
-      
-      ! Close the file
-      
-      CALL chkerr( nf90_close( i_file_id ), cpname, __LINE__ )
-
-      ! Compute Julian dates for all observations
-      
-      jm = 0
-      jl = 0
-      DO jj = 1, itracks
-         DO ji = 1, ipnbpoints(jj)
-            jl = jl + 1
-            DO jk = 1, icycles
-               jm = jm + 1
-               IF (zbegindates(jk,jj)==zbeginmiss) THEN
-                  llskip(jm) = .TRUE.
-                  zjuld(jm)  = fbrmdi
-               ELSE
-                  llskip(jm) = .FALSE.
-                  zjuld(jm)  = zbegindates(jk,jj) + &
-                     &         (ipdataindexes(jl) * zdeltat / 86400._wp )
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      ! Get rid of missing data
-
-      jm = 0
-      DO jobs = 1, idata
-         DO jcycle = 1, icycles
-            jm = jm + 1
-            IF (zsla(jcycle,jobs) == fbrmdi) llskip(jm) = .TRUE.
-         END DO
-      END DO
-      
-      ! Allocate obfbdata
-
-      iobs = COUNT( .NOT.llskip(:) )
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 1, iobs, 1, 0, 0, ldgrid )
-      inpfile%cname(1) = 'SLA'
-
-      ! Fill the obfbdata structure from input data
-
-      inpfile%cdjuldref = cdjuldref
-      iobs = 0
-      jm = 0
-      DO jobs = 1, idata
-         DO jcycle = 1, icycles
-            jm = jm + 1
-            IF (llskip(jm)) CYCLE
-            iobs = iobs + 1
-            ! Characters
-            WRITE(inpfile%cdwmo(iobs),'(A3,A5)') cmissions(imission), '     '
-            WRITE(inpfile%cdtyp(iobs),'(I4)') imission
-            ! Real values
-            inpfile%plam(iobs)         = zlam(jobs)
-            inpfile%pphi(iobs)         = zphi(jobs)
-            inpfile%pob(1,iobs,1)      = zsla(jcycle,jobs)
-            inpfile%ptim(iobs)         = zjuld(jm)
-            inpfile%pdep(1,iobs)       = 0.0
-            ! Integers
-            inpfile%kindex(iobs)       = iobs
-            inpfile%ioqc(iobs)      = 1
-            inpfile%ivqc(iobs,1)    = 1
-            inpfile%ivlqc(1,iobs,1) = 1
-            inpfile%ipqc(iobs)         = 0 
-            inpfile%ipqcf(:,iobs)      = 0
-            inpfile%itqc(iobs)         = 0
-            inpfile%itqcf(:,iobs)      = 0
-            inpfile%ivqcf(:,iobs,1)    = 0
-            inpfile%ioqcf(:,iobs)      = 0
-            inpfile%idqc(1,iobs)       = 0
-            inpfile%idqcf(1,1,iobs)    = 0
-            inpfile%ivlqcf(:,1,iobs,1) = 0
-         END DO
-      END DO
-
-
-      ! Deallocate memory for input data
-
-      DEALLOCATE( &
-         & iptracks,      &
-         & ipnbpoints,    &
-         & ipcycles,      &
-         & zphi,          &
-         & zlam,          &  
-         & zbegindates,   &
-         & ipdataindexes, &
-         & zsla,          &
-         & zjuld,         &
-         & llskip         &
-         & )
-
-   END SUBROUTINE read_avisofile
-
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obssla_types.h90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obssla_types.h90	(revision 6139)
+++ 	(revision )
@@ -1,9 +1,0 @@
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   INTEGER, PARAMETER :: imaxmissions=8
-   CHARACTER(len=3) :: cmissions(0:imaxmissions) = &
-      & (/ 'XXX', 'E1 ', 'E2 ', 'TP ', 'TPM', 'G2 ', 'J1 ', 'EN ', 'J2 ' /)
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obssst_io.h90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obssst_io.h90	(revision 6139)
+++ 	(revision )
@@ -1,286 +1,0 @@
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE read_ghrsst( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_ghrsst **
-      !!
-      !! ** Purpose : Read from file the GHRSST observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! References : 
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      CHARACTER(LEN=12),PARAMETER :: cpname = 'read_ghrsst'
-      INTEGER :: i_file_id        ! netcdf IDS
-      INTEGER :: i_time_id
-      INTEGER :: i_ni_id
-      INTEGER :: i_data_id
-      INTEGER :: i_var_id
-      INTEGER :: i_data           ! Number of data per parameter in current file
-      INTEGER :: i_time           ! Number of reference times in file
-      INTEGER, DIMENSION(:), POINTER :: &
-         & i_reftime        ! Reference time in file in seconds since 1/1/1981.
-      INTEGER, DIMENSION(:,:), POINTER :: &
-         & i_dtime, &       ! Offset in seconds since reference time
-         & i_qc,    &       ! Quality control flag.
-         & i_type           ! Type of SST measurement.            
-      REAL(wp), DIMENSION(:), POINTER :: &
-         & z_phi,   &       ! Latitudes
-         & z_lam            ! Longitudes
-      REAL(wp), DIMENSION(:,:), POINTER :: &
-         & z_sst            ! SST data     
-      INTEGER, PARAMETER :: imaxdim = 2      ! Assumed maximum for no. dims. in file
-      INTEGER, DIMENSION(2) :: idims         ! Dimensions in file
-      INTEGER :: iilen            ! Length of netCDF attributes
-      INTEGER :: itype            ! Typeof netCDF attributes
-      REAL(KIND=wp) :: zsca           ! Scale factor
-      REAL(KIND=wp) :: zoff           ! Offset for data in netcdf file
-      REAL(KIND=wp) :: z_offset       ! Offset for time conversion
-      REAL(KIND=wp) :: zfill          ! Fill value in netcdf file
-      CHARACTER (len=33) :: creftime  ! Reference time of file
-      INTEGER :: i_refyear            ! Integer version of reference time
-      INTEGER :: i_refmonth
-      INTEGER :: i_refday
-      INTEGER :: i_refhour
-      INTEGER :: i_refmin
-      INTEGER :: i_refsec
-      INTEGER :: ichunk
-      INTEGER :: jtim
-      INTEGER :: jobs
-      INTEGER :: iobs
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-         &                i_file_id, chunksize=ichunk), cpname, __LINE__ )
-      
-      ! Get the netCDF dimensions
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'time', i_time_id ),  &
-         &       cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_time_id, &
-         &                              len = i_time ),  &
-         &      cpname, __LINE__ )
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'ni', i_ni_id ),  &
-         &       cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_ni_id, &
-         &                              len = i_data ),  &
-         &      cpname, __LINE__ )
-      
-      
-      ! Allocate NetCDF variables
-      
-      ALLOCATE( &
-         & i_reftime    ( i_time                 ), &
-         & i_dtime      ( i_data,i_time  ), &      
-         & i_qc         ( i_data,i_time  ), & 
-         & i_type       ( i_data,i_time  ), &     
-         & z_phi        ( i_data                 ), &   
-         & z_lam        ( i_data                 ), &  
-         & z_sst        ( i_data,i_time  )  &
-         & )
-      
-      ! Get reference time of file which is in seconds since 1981/1/1 00:00. 
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'time', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_time
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_reftime),&
-         &       cpname, __LINE__ )
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "units") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "units",creftime), cpname,  __LINE__ )
-      ELSE
-         creftime = "seconds since 1981-01-01 00:00:00"
-      ENDIF
-      READ(creftime(15:18),*)i_refyear
-      READ(creftime(20:21),*)i_refmonth
-      READ(creftime(23:24),*)i_refday
-      READ(creftime(26:27),*)i_refhour
-      READ(creftime(29:30),*)i_refmin
-      READ(creftime(32:33),*)i_refsec
-      !Work out offset in days between reference time and 1/1/1950.
-      CALL greg2jul( i_refsec, i_refmin, i_refhour, i_refday, &
-         &           i_refmonth, i_refyear, z_offset)
-      
-      ! Get list of times for each ob in seconds relative to reference time
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'sst_dtime', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_dtime),&
-         &       cpname, __LINE__ )
-      zsca = 1.0      
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "scale_factor",zsca), cpname,  __LINE__ )
-      ENDIF
-      zoff = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "add_offset") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "add_offset",zoff), cpname,  __LINE__ )
-      ENDIF
-      i_dtime(:,:) = NINT((zsca * FLOAT(i_dtime(:,:))) &
-         &                 + zoff)
-      
-      ! Get longitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'lon', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_lam),   &
-         &         cpname, __LINE__ )
-      
-      ! Get latitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'lat', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_phi),   &
-         &         cpname, __LINE__ )
-      
-      ! Get SST data
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'sea_surface_temperature', &
-         &                         i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_sst), &
-         &       cpname, __LINE__ )
-      zoff = 0.
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "scale_factor",zsca), cpname, __LINE__ )
-      ENDIF
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       "scale_factor",zsca), cpname, __LINE__ )
-      ENDIF
-      zfill = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "_FillValue") &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       "_FillValue",zfill), cpname, __LINE__ )
-      ENDIF
-      WHERE(z_sst(:,:) /=  zfill)
-         z_sst(:,:) = (zsca * z_sst(:,:)) + zoff
-      ELSEWHERE
-         z_sst(:,:) = fbrmdi
-      END WHERE
-      
-      ! Get QC flag
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'confidence_flag', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_qc),   &
-            &       cpname, __LINE__ )
-      
-      ! Get SST obs type
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'data_source', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_type),   &
-         &       cpname, __LINE__ )
-      
-      ! Close the file
-      
-      CALL chkerr( nf90_close( i_file_id ), cpname, __LINE__ )
-
-      ! Fill the obfbdata structure
-
-      ! Allocate obfbdata
-      
-      iobs = i_data * i_time
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 1, iobs, 1, 0, 0, ldgrid )
-      inpfile%cname(1) = 'SST'
-
-      ! Fill the obfbdata structure from input data
-
-      inpfile%cdjuldref = "19500101000000"
-      iobs = 0
-      DO jtim = 1, i_time
-         DO jobs = 1, i_data
-            iobs = iobs + 1
-            ! Characters
-            WRITE(inpfile%cdwmo(iobs),'(A6,A2)') 'ghrsst','  '
-            WRITE(inpfile%cdtyp(iobs),'(I4)') i_type(jobs,jtim)
-            ! Real values
-            inpfile%plam(iobs)         = z_lam(jobs)
-            inpfile%pphi(iobs)         = z_phi(jobs)
-            inpfile%pob(1,iobs,1)      = z_sst(jobs,jtim)
-            inpfile%ptim(iobs)         = &
-               & REAL(i_reftime(jtim))/(60.*60.*24.) + &
-               & z_offset + REAL(i_dtime(jobs,jtim))/(60.*60.*24.)
-            inpfile%pdep(1,iobs)       = 0.0
-            ! Integers
-            inpfile%kindex(iobs)       = iobs
-            IF ( z_sst(jobs,jtim) == fbrmdi ) THEN
-               inpfile%ioqc(iobs)      = 4
-               inpfile%ivqc(iobs,1)    = 4 
-               inpfile%ivlqc(1,iobs,1) = 4
-            ELSE 
-               inpfile%ioqc(iobs)      = i_qc(jobs,jtim)
-               inpfile%ivqc(iobs,1)    = i_qc(jobs,jtim)
-               inpfile%ivlqc(1,iobs,1) = 1
-            ENDIF
-            inpfile%ipqc(iobs)         = 0 
-            inpfile%ipqcf(:,iobs)      = 0
-            inpfile%itqc(iobs)         = 0
-            inpfile%itqcf(:,iobs)      = 0
-            inpfile%ivqcf(:,iobs,1)    = 0
-            inpfile%ioqcf(:,iobs)      = 0
-            inpfile%idqc(1,iobs)       = 0
-            inpfile%idqcf(1,1,iobs)    = 0
-            inpfile%ivlqcf(:,1,iobs,1) = 0
-         END DO
-      END DO
-
-      DEALLOCATE( &
-         & i_reftime, &
-         & i_dtime,   &
-         & i_qc,      &
-         & i_type,    &
-         & z_phi,     &
-         & z_lam,     &
-         & z_sst      &
-         & )
-
-   END SUBROUTINE read_ghrsst
-
-
Index: unk/NEMOGCM/NEMO/OPA_SRC/OBS/obsvel_io.h90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/OBS/obsvel_io.h90	(revision 6139)
+++ 	(revision )
@@ -1,360 +1,0 @@
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE read_taondbc( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_enactfile **
-      !!
-      !! ** Purpose : Read from file the TAO data fro NDBC.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! ** Reference : http://tao.noaa.gov/tao/data_deliv/deliv_ndbc.shtml
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original version.
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      INTEGER :: iobs                ! Number of observations
-      INTEGER :: ilev                ! Number of levels
-      INTEGER :: ilat                ! Number of latitudes
-      INTEGER :: ilon                ! Number of longtudes
-      INTEGER :: itim                ! Number of obs. times
-      INTEGER :: i_file_id
-      INTEGER :: i_dimid_id
-      INTEGER :: i_phi_id
-      INTEGER :: i_lam_id
-      INTEGER :: i_depth_id
-      INTEGER :: i_var_id
-      INTEGER :: i_time_id
-      INTEGER :: i_time2_id
-      INTEGER :: i_qc_var_id
-      CHARACTER(LEN=40) :: cl_fld_lam
-      CHARACTER(LEN=40) :: cl_fld_phi
-      CHARACTER(LEN=40) :: cl_fld_depth
-      CHARACTER(LEN=40) :: cl_fld_var_u
-      CHARACTER(LEN=40) :: cl_fld_var_v
-      CHARACTER(LEN=40) :: cl_fld_var_qc_uv1
-      CHARACTER(LEN=40) :: cl_fld_var_qc_uv2
-      CHARACTER(LEN=40) :: cl_fld_time
-      CHARACTER(LEN=40) :: cl_fld_time2
-      INTEGER :: ja
-      INTEGER :: jo
-      INTEGER :: jk
-      INTEGER :: jt
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) :: &
-         & zv,     &
-         & zu,     &
-         & zuv1qc, &
-         & zuv2qc
-      REAL(wp), ALLOCATABLE, DIMENSION(:) :: &
-         & zdep, &
-         & zlat, &
-         & zlon, &
-         & zjuld
-      REAL(wp) :: zl
-      INTEGER, ALLOCATABLE, DIMENSION(:) :: &
-         & itime, &
-         & itime2
-      CHARACTER(LEN=50) :: cdjulref
-      CHARACTER(LEN=12), PARAMETER :: cl_name = 'read_taondbc'
-      CHARACTER(len=1) :: cns, cew
-
-      !-----------------------------------------------------------------------
-      ! Initialization
-      !-----------------------------------------------------------------------
-      cl_fld_lam                 = 'lon'
-      cl_fld_phi                 = 'lat'
-      cl_fld_depth               = 'depth'
-      cl_fld_time                = 'time'
-      cl_fld_time2               = 'time2'
-
-      !-----------------------------------------------------------------------
-      ! Open file
-      !-----------------------------------------------------------------------
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-            &      i_file_id ),           cl_name, __LINE__ )
-
-      !-----------------------------------------------------------------------
-      ! Read the heading of the file
-      !-----------------------------------------------------------------------
-      IF(ldwp) WRITE(kunit,*)
-      IF(ldwp) WRITE(kunit,*) ' read_taondbc :' 
-      IF(ldwp) WRITE(kunit,*) ' ~~~~~~~~~~~~'
-      
-      !---------------------------------------------------------------------
-      ! Read the number of observations and of levels to allocate array
-      !---------------------------------------------------------------------
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'time', i_dimid_id ),        &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = itim ),    &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'depth', i_dimid_id ),       &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = ilev ),    &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'lat', i_dimid_id ),           &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = ilat ),    &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'lon', i_dimid_id ),         &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = ilon ),    &
-         &         cl_name, __LINE__ ) 
-
-      iobs = itim * ilat * ilon
-      IF(ldwp)WRITE(kunit,*) '         No. of data records = ', iobs
-      IF(ldwp)WRITE(kunit,*) '         No. of levels       = ', ilev
-      IF(ldwp)WRITE(kunit,*) 
-
-      !---------------------------------------------------------------------
-      ! Allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 0, ldgrid )
-      inpfile%cname(1) = 'UVEL'
-      inpfile%cname(2) = 'VVEL'
-      inpfile%coblong(1) = 'Zonal current'
-      inpfile%coblong(2) = 'Meridional current'
-      inpfile%cobunit(1) = 'Meters per second'
-      inpfile%cobunit(2) = 'Meters per second'
-
-      ALLOCATE( &
-         & zu(ilon,ilat,ilev,itim),     &
-         & zv(ilon,ilat,ilev,itim),     &
-         & zdep(ilev),                  &
-         & zuv1qc(ilon,ilat,ilev,itim), &
-         & zuv2qc(ilon,ilat,ilev,itim), &
-         & itime(itim),                 &
-         & itime2(itim),                &
-         & zlat(ilat),                  &
-         & zlon(ilon),                  &
-         & zjuld(itim)                  &
-         & )
-
-      !---------------------------------------------------------------------
-      ! Read the time/position variables 
-      !---------------------------------------------------------------------
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_time, i_time_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_time_id, itime ),                                     &
-         &         cl_name, __LINE__ )
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_time2, i_time2_id ),                             &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_time2_id, itime2 ),                                   &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ),                             &
-            &         cl_name, __LINE__ )         
-      CALL chkerr( nf90_get_var  ( i_file_id, i_depth_id, zdep ),                                     &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_phi_id, zlat ),                                       &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_lam_id, zlon ),                                       &
-         &         cl_name, __LINE__ )
-      
-      !---------------------------------------------------------------------
-      ! Read the variables
-      !---------------------------------------------------------------------
-
-      ! ADCP format assumed
-      cl_fld_var_u = 'u_1205'
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_u, i_var_id ) /= nf90_noerr ) THEN
-         ! Try again with current meter format
-         cl_fld_var_u = 'U_320'
-         IF ( nf90_inq_varid( i_file_id, cl_fld_var_u, i_var_id ) /= nf90_noerr ) THEN
-            CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
-         ENDIF
-      ENDIF
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zu ),                                         &
-         &         cl_name, __LINE__ )
-      
-      ! ADCP format assumed
-      cl_fld_var_v = 'v_1206'
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_v, i_var_id ) /= nf90_noerr ) THEN
-         ! Try again with current meter format
-         cl_fld_var_v = 'V_321'
-         IF ( nf90_inq_varid( i_file_id, cl_fld_var_v, i_var_id ) /= nf90_noerr ) THEN
-            CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
-         ENDIF
-      ENDIF
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zv ),                                         &
-         &         cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Read the QC attributes
-      !---------------------------------------------------------------------
-      
-      ! ADCP format assumed
-      cl_fld_var_qc_uv1 = 'QU_5205'
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv1, i_qc_var_id ) /= nf90_noerr ) THEN
-         ! Try again with current meter format
-         cl_fld_var_qc_uv1 = 'QCS_5300'
-         IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv1, i_qc_var_id ) /= nf90_noerr ) THEN
-            ! Try again with high freq. current meter format
-            cl_fld_var_qc_uv1 = 'QCU_5320'
-            IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv1, i_qc_var_id ) /= nf90_noerr ) THEN
-               CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
-            ENDIF
-         ENDIF
-      ENDIF
-      CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, zuv1qc),                                   &
-         &         cl_name, __LINE__ )
-
-      ! ADCP format assumed
-      cl_fld_var_qc_uv2 = 'QV_5206'
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv2, i_qc_var_id ) /= nf90_noerr ) THEN
-         ! Try again with current meter format
-         cl_fld_var_qc_uv2 = 'QCD_5310'
-         IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv2, i_qc_var_id ) /= nf90_noerr ) THEN
-            ! Try again with high freq. current meter format
-            cl_fld_var_qc_uv2 = 'QCV_5321'
-            IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv2, i_qc_var_id ) /= nf90_noerr ) THEN
-               CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
-            ENDIF
-         ENDIF
-      ENDIF
-      CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, zuv2qc),                                   &
-         &         cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Close file
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_close( i_file_id ),           cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Convert to to 19500101 based Julian date
-      !---------------------------------------------------------------------
-      DO jt = 1, itim
-         zjuld(jt) = REAL(itime(jt),wp) + REAL(itime2(jt),wp)/86400000.0_wp &
-            &           - 2433283.0_wp
-      END DO
-      inpfile%cdjuldref = '19500101000000'
-
-      !---------------------------------------------------------------------
-      ! Copy info to obfbdata structure
-      !---------------------------------------------------------------------
-
-      iobs = 0
-      DO jt = 1, itim
-         DO ja = 1, ilat
-            DO jo = 1, ilon
-               iobs = iobs + 1
-               zl = zlon(jo)
-               IF ( zl > 180.0_wp ) zl = zl - 360.0_wp
-               IF ( zl < 0 ) THEN
-                  cew = 'w'
-               ELSE
-                  cew = 'e'
-               ENDIF
-               IF ( zlat(jo) < 0 ) THEN
-                  cns = 's'
-               ELSE
-                  cns = 'n'
-               ENDIF
-               WRITE(inpfile%cdwmo(iobs),'(A1,I2.2,A1,I3.3)') &
-                  & cns, ABS(NINT(zlat(ja))), cew, ABS(NINT(zl))
-               DO jk = 1, ilev
-                  inpfile%pob(jk,iobs,1)     = zu(jo,ja,jk,jt)
-                  inpfile%pob(jk,iobs,2)     = zv(jo,ja,jk,jt)
-                  inpfile%pdep(jk,iobs)      = zdep(jk)
-                  inpfile%ivlqc(jk,iobs,1:2) = INT( MAX( zuv1qc(jo,ja,jk,jt), zuv2qc(jo,ja,jk,jt) ) )
-               END DO
-               inpfile%plam(iobs) = zlon(jo)
-               inpfile%pphi(iobs) = zlat(ja)
-               inpfile%ptim(iobs) = zjuld(jt)
-            END DO
-         END DO
-      END DO
-
-      ! No position, time, depth and variable QC in input files
-      DO jo = 1, iobs
-         inpfile%ipqc(jo) = 1
-         inpfile%itqc(jo) = 1
-         inpfile%ivqc(jo,1:2) = 1
-         DO jk = 1, ilev
-            inpfile%idqc(jk,jo) = 1
-         END DO
-      END DO
-
-      !---------------------------------------------------------------------
-      ! Set the platform information
-      !---------------------------------------------------------------------
-      inpfile%cdtyp(:)=' 820'
-
-      !---------------------------------------------------------------------
-      ! Set QC flags for missing data and rescale to m/s
-      !---------------------------------------------------------------------
-
-      DO jo = 1, iobs
-         DO jk = 1, ilev
-            IF ( ( ABS(inpfile%pob(jk,jo,1)) > 10000.0_wp ) .OR. &
-               & ( ABS(inpfile%pob(jk,jo,2)) > 10000.0_wp ) ) THEN
-               inpfile%ivlqc(jk,jo,:) = 4
-               inpfile%pob(jk,jo,1) = fbrmdi
-               inpfile%pob(jk,jo,2) = fbrmdi
-            ELSE
-               inpfile%pob(jk,jo,1) = 0.01 * inpfile%pob(jk,jo,1)
-               inpfile%pob(jk,jo,2) = 0.01 * inpfile%pob(jk,jo,2)
-            ENDIF
-         END DO
-      END DO
-
-      !---------------------------------------------------------------------
-      ! Set file indexes
-      !---------------------------------------------------------------------
-
-      DO jo = 1, inpfile%nobs
-         inpfile%kindex(jo) = jo
-      END DO
-
-      !---------------------------------------------------------------------
-      ! Initialize flags since they are not in the TAO input files
-      !---------------------------------------------------------------------
-
-      inpfile%ioqcf(:,:)      = 0
-      inpfile%ipqcf(:,:)      = 0
-      inpfile%itqcf(:,:)      = 0
-      inpfile%idqcf(:,:,:)    = 0
-      inpfile%ivqcf(:,:,:)    = 0
-      inpfile%ivlqcf(:,:,:,:) = 0
-
-      !---------------------------------------------------------------------
-      ! Deallocate data
-      !---------------------------------------------------------------------
-      DEALLOCATE( &
-         & zu,     &
-         & zv,     &
-         & zdep,   &
-         & zuv1qc, &
-         & zuv2qc, &
-         & itime,  &
-         & itime2, &
-         & zlat,   &
-         & zlon,   &
-         & zjuld   &
-         & )
-
-   END SUBROUTINE read_taondbc
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 6140)
@@ -4,9 +4,7 @@
    !! Ocean forcing:  read input field for surface boundary condition
    !!=====================================================================
-   !! History :  2.0  !  06-2006  (S. Masson, G. Madec) Original code
-   !!                 !  05-2008  (S. Alderson) Modified for Interpolation in memory
-   !!                 !                         from input grid to model grid
-   !!                 !  10-2013  (D. Delrosso, P. Oddo) implement suppression of 
-   !!                 !                         land point prior to interpolation
+   !! History :  2.0  !  06-2006  (S. Masson, G. Madec)  Original code
+   !!                 !  05-2008  (S. Alderson)  Modified for Interpolation in memory from input grid to model grid
+   !!                 !  10-2013  (D. Delrosso, P. Oddo)  suppression of land point prior to interpolation
    !!----------------------------------------------------------------------
 
@@ -15,15 +13,16 @@
    !!                   surface boundary condition
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! ???
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O manager library
-   USE geo2ocean       ! for vector rotation on to model grid
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! work arrays
-   USE lbclnk          ! ocean lateral boundary conditions (C1D case)
-   USE ioipsl, ONLY :   ymds2ju, ju2ymds   ! for calendar
-   USE sbc_oce
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constant
+   USE sbc_oce        ! surface boundary conditions : fields
+   USE geo2ocean      ! for vector rotation on to model grid
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE ioipsl  , ONLY : ymds2ju, ju2ymds   ! for calendar
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! work arrays
+   USE lbclnk         ! ocean lateral boundary conditions (C1D case)
    
    IMPLICIT NONE
@@ -60,6 +59,6 @@
       INTEGER , DIMENSION(2)          ::   nrec_b       ! before record (1: index, 2: second since Jan. 1st 00h of nit000 year)
       INTEGER , DIMENSION(2)          ::   nrec_a       ! after  record (1: index, 2: second since Jan. 1st 00h of nit000 year)
-      REAL(wp) , ALLOCATABLE, DIMENSION(:,:,:  ) ::   fnow       ! input fields interpolated to now time step
-      REAL(wp) , ALLOCATABLE, DIMENSION(:,:,:,:) ::   fdta       ! 2 consecutive record of input fields
+      REAL(wp) , ALLOCATABLE, DIMENSION(:,:,:  ) ::   fnow   ! input fields interpolated to now time step
+      REAL(wp) , ALLOCATABLE, DIMENSION(:,:,:,:) ::   fdta   ! 2 consecutive record of input fields
       CHARACTER(len = 256)            ::   wgtname      ! current name of the NetCDF weight file acting as a key
       !                                                 ! into the WGTLIST structure
@@ -133,22 +132,21 @@
       INTEGER  , INTENT(in   ), OPTIONAL     ::   kit       ! subcycle timestep for timesplitting option
       INTEGER  , INTENT(in   ), OPTIONAL     ::   kt_offset ! provide fields at time other than "now"
-                                                            !   kt_offset = -1 => fields at "before" time level
-                                                            !   kt_offset = +1 => fields at "after"  time level
-                                                            !   etc.
-      !!
-      INTEGER  ::   itmp       ! temporary variable
-      INTEGER  ::   imf        ! size of the structure sd
-      INTEGER  ::   jf         ! dummy indices
-      INTEGER  ::   isecend    ! number of second since Jan. 1st 00h of nit000 year at nitend
-      INTEGER  ::   isecsbc    ! number of seconds between Jan. 1st 00h of nit000 year and the middle of sbc time step
-      INTEGER  ::   it_offset  ! local time offset variable
-      LOGICAL  ::   llnxtyr    ! open next year  file?
-      LOGICAL  ::   llnxtmth   ! open next month file?
-      LOGICAL  ::   llstop     ! stop is the file does not exist
+      !                                                     !   kt_offset = -1 => fields at "before" time level
+      !                                                     !   kt_offset = +1 => fields at "after"  time level
+      !                                                     !   etc.
+      INTEGER  ::   itmp         ! local variable
+      INTEGER  ::   imf          ! size of the structure sd
+      INTEGER  ::   jf           ! dummy indices
+      INTEGER  ::   isecend      ! number of second since Jan. 1st 00h of nit000 year at nitend
+      INTEGER  ::   isecsbc      ! number of seconds between Jan. 1st 00h of nit000 year and the middle of sbc time step
+      INTEGER  ::   it_offset    ! local time offset variable
+      LOGICAL  ::   llnxtyr      ! open next year  file?
+      LOGICAL  ::   llnxtmth     ! open next month file?
+      LOGICAL  ::   llstop       ! stop is the file does not exist
       LOGICAL  ::   ll_firstcall ! true if this is the first call to fld_read for this set of fields
-      REAL(wp) ::   ztinta     ! ratio applied to after  records when doing time interpolation
-      REAL(wp) ::   ztintb     ! ratio applied to before records when doing time interpolation
-      CHARACTER(LEN=1000) ::   clfmt   ! write format
-      TYPE(MAP_POINTER) ::   imap   ! global-to-local mapping indices
+      REAL(wp) ::   ztinta       ! ratio applied to after  records when doing time interpolation
+      REAL(wp) ::   ztintb       ! ratio applied to before records when doing time interpolation
+      CHARACTER(LEN=1000) ::   clfmt  ! write format
+      TYPE(MAP_POINTER)   ::   imap   ! global-to-local mapping indices
       !!---------------------------------------------------------------------
       ll_firstcall = kt == nit000
@@ -166,5 +164,5 @@
          isecsbc = nsec_year + nsec1jan000 + (kit+it_offset)*NINT( rdt/REAL(nn_baro,wp) )
       ELSE                      ! middle of sbc time step
-         isecsbc = nsec_year + nsec1jan000 + NINT(0.5 * REAL(kn_fsbc - 1,wp) * rdttra(1)) + it_offset * NINT(rdttra(1))
+         isecsbc = nsec_year + nsec1jan000 + NINT(0.5 * REAL(kn_fsbc - 1,wp) * rdt) + it_offset * NINT(rdt)
       ENDIF
       imf = SIZE( sd )
@@ -193,5 +191,5 @@
                CALL fld_rec( kn_fsbc, sd(jf), kt_offset = it_offset, kit = kit )    ! update after record informations
 
-               ! if kn_fsbc*rdttra is larger than nfreqh (which is kind of odd),
+               ! if kn_fsbc*rdt is larger than nfreqh (which is kind of odd),
                ! it is possible that the before value is no more the good one... we have to re-read it
                ! if before is not the last record of the file currently opened and after is the first record to be read
@@ -214,5 +212,5 @@
                IF( sd(jf)%ln_tint ) THEN
                   
-                  ! if kn_fsbc*rdttra is larger than nfreqh (which is kind of odd),
+                  ! if kn_fsbc*rdt is larger than nfreqh (which is kind of odd),
                   ! it is possible that the before value is no more the good one... we have to re-read it
                   ! if before record is not just just before the after record...
@@ -245,5 +243,5 @@
                         ! year/month/week/day file to be not present. If the run continue further than the current
                         ! year/month/week/day, next year/month/week/day file must exist
-                        isecend = nsec_year + nsec1jan000 + (nitend - kt) * NINT(rdttra(1))   ! second at the end of the run 
+                        isecend = nsec_year + nsec1jan000 + (nitend - kt) * NINT(rdt)   ! second at the end of the run
                         llstop = isecend > sd(jf)%nrec_a(2)                                   ! read more than 1 record of next year
                         ! we suppose that the date of next file is next day (should be ok even for weekly files...)
@@ -299,7 +297,5 @@
          END DO                                    ! --- end loop over field --- !
          !
-         !                                         ! ====================================== !
-      ENDIF                                        ! update field at each kn_fsbc time-step !
-      !                                            ! ====================================== !
+      ENDIF
       !
    END SUBROUTINE fld_read
@@ -333,12 +329,12 @@
       llprevday  = .FALSE.
       isec_week  = 0
-            
+      !
       ! define record informations
       CALL fld_rec( kn_fsbc, sdjf, ldbefore = .TRUE. )  ! return before values in sdjf%nrec_a (as we will swap it later)
-
+      !
       ! Note that shifting time to be centrered in the middle of sbc time step impacts only nsec_* variables of the calendar 
-
+      !
       IF( sdjf%ln_tint ) THEN ! we need to read the previous record and we will put it in the current record structure
-
+         !
          IF( sdjf%nrec_a(1) == 0  ) THEN   ! we redefine record sdjf%nrec_a(1) with the last record of previous year file
             IF    ( sdjf%nfreqh == -12 ) THEN   ! yearly mean
@@ -391,5 +387,5 @@
          !
          CALL fld_clopn( sdjf, iyear, imonth, iday, .NOT. llprev )
-
+         !
          ! if previous year/month/day file does not exist, we switch to the current year/month/day
          IF( llprev .AND. sdjf%num <= 0 ) THEN
@@ -401,5 +397,5 @@
             CALL fld_clopn( sdjf )
          ENDIF
-         
+         !
          IF( llprev ) THEN   ! check if the record sdjf%nrec_a(1) exists in the file
             idvar = iom_varid( sdjf%num, sdjf%clvar )                                        ! id of the variable sdjf%clvar
@@ -408,11 +404,10 @@
             sdjf%nrec_a(1) = MIN( sdjf%nrec_a(1), inrec )   ! make sure we select an existing record
          ENDIF
-
-         ! read before data in after arrays(as we will swap it later)
-         CALL fld_get( sdjf, map )
-
+         !
+         CALL fld_get( sdjf, map )         ! read before data in after arrays(as we will swap it later)
+         !
          clfmt = "('fld_init : time-interpolation for ', a, ' read previous record = ', i6, ' at time = ', f7.2, ' days')"
          IF(lwp) WRITE(numout, clfmt) TRIM(sdjf%clvar), sdjf%nrec_a(1), REAL(sdjf%nrec_a(2),wp)/rday
-
+         !
       ENDIF
       !
@@ -435,8 +430,8 @@
       LOGICAL  , INTENT(in   ), OPTIONAL ::   ldbefore  ! sent back before record values (default = .FALSE.)
       INTEGER  , INTENT(in   ), OPTIONAL ::   kit       ! index of barotropic subcycle
-                                                        ! used only if sdjf%ln_tint = .TRUE.
+      !                                                 ! used only if sdjf%ln_tint = .TRUE.
       INTEGER  , INTENT(in   ), OPTIONAL ::   kt_offset ! Offset of required time level compared to "now"
-                                                        !   time level in units of time steps.
-      !!
+      !                                                 !   time level in units of time steps.
+      !
       LOGICAL  ::   llbefore    ! local definition of ldbefore
       INTEGER  ::   iendrec     ! end of this record (in seconds)
@@ -459,5 +454,5 @@
       IF( PRESENT(kt_offset) )   it_offset = kt_offset
       IF( PRESENT(kit) ) THEN   ;   it_offset = ( kit + it_offset ) * NINT( rdt/REAL(nn_baro,wp) )
-      ELSE                      ;   it_offset =         it_offset   * NINT(       rdttra(1)      )
+      ELSE                      ;   it_offset =         it_offset   * NINT(       rdt            )
       ENDIF
       !
@@ -536,6 +531,6 @@
          ELSE                                           ;   ztmp = REAL(nsec_year ,wp)  ! since 00h on Jan 1 of the current year
          ENDIF
-         ztmp = ztmp + 0.5 * REAL(kn_fsbc - 1, wp) * rdttra(1) + REAL( it_offset, wp )  ! centrered in the middle of sbc time step
-         ztmp = ztmp + 0.01 * rdttra(1)                                                 ! avoid truncation error 
+         ztmp = ztmp + 0.5 * REAL(kn_fsbc - 1, wp) * rdt + REAL( it_offset, wp )        ! centrered in the middle of sbc time step
+         ztmp = ztmp + 0.01 * rdt                                                       ! avoid truncation error 
          IF( sdjf%ln_tint ) THEN                ! time interpolation, shift by 1/2 record
             !
@@ -592,13 +587,13 @@
       !! ** Purpose :   read the data
       !!----------------------------------------------------------------------
-      TYPE(FLD), INTENT(inout) ::   sdjf   ! input field related variables
-      TYPE(MAP_POINTER),INTENT(in) ::   map   ! global-to-local mapping indices
-      !!
-      INTEGER                  ::   ipk    ! number of vertical levels of sdjf%fdta ( 2D: ipk=1 ; 3D: ipk=jpk )
-      INTEGER                  ::   iw     ! index into wgts array
-      INTEGER                  ::   ipdom  ! index of the domain
-      INTEGER                  ::   idvar  ! variable ID
-      INTEGER                  ::   idmspc ! number of spatial dimensions
-      LOGICAL                  ::   lmoor  ! C1D case: point data
+      TYPE(FLD)        , INTENT(inout) ::   sdjf   ! input field related variables
+      TYPE(MAP_POINTER), INTENT(in   ) ::   map    ! global-to-local mapping indices
+      !
+      INTEGER ::   ipk      ! number of vertical levels of sdjf%fdta ( 2D: ipk=1 ; 3D: ipk=jpk )
+      INTEGER ::   iw       ! index into wgts array
+      INTEGER ::   ipdom    ! index of the domain
+      INTEGER ::   idvar    ! variable ID
+      INTEGER ::   idmspc   ! number of spatial dimensions
+      LOGICAL ::   lmoor    ! C1D case: point data
       !!---------------------------------------------------------------------
       !
@@ -611,19 +606,19 @@
       ELSE IF( LEN(TRIM(sdjf%wgtname)) > 0 ) THEN
          CALL wgt_list( sdjf, iw )
-         IF( sdjf%ln_tint ) THEN   ;   CALL fld_interp( sdjf%num, sdjf%clvar, iw , ipk  , sdjf%fdta(:,:,:,2), & 
-              & sdjf%nrec_a(1), sdjf%lsmname )
-         ELSE                      ;   CALL fld_interp( sdjf%num, sdjf%clvar, iw , ipk  , sdjf%fnow(:,:,:  ), &
-              & sdjf%nrec_a(1), sdjf%lsmname )
+         IF( sdjf%ln_tint ) THEN   ;   CALL fld_interp( sdjf%num, sdjf%clvar, iw, ipk, sdjf%fdta(:,:,:,2),          & 
+            &                                                                          sdjf%nrec_a(1), sdjf%lsmname )
+         ELSE                      ;   CALL fld_interp( sdjf%num, sdjf%clvar, iw, ipk, sdjf%fnow(:,:,:  ),          &
+            &                                                                          sdjf%nrec_a(1), sdjf%lsmname )
          ENDIF
       ELSE
-         IF( SIZE(sdjf%fnow, 1) == jpi ) THEN  ;  ipdom = jpdom_data
-         ELSE                                  ;  ipdom = jpdom_unknown
+         IF( SIZE(sdjf%fnow, 1) == jpi ) THEN   ;   ipdom = jpdom_data
+         ELSE                                   ;   ipdom = jpdom_unknown
          ENDIF
          ! C1D case: If product of spatial dimensions == ipk, then x,y are of
          ! size 1 (point/mooring data): this must be read onto the central grid point
          idvar  = iom_varid( sdjf%num, sdjf%clvar )
-         idmspc = iom_file( sdjf%num )%ndims( idvar )
+         idmspc = iom_file ( sdjf%num )%ndims( idvar )
          IF( iom_file( sdjf%num )%luld( idvar ) )   idmspc = idmspc - 1
-         lmoor  = (idmspc == 0 .OR. PRODUCT( iom_file( sdjf%num )%dimsz( 1:MAX(idmspc,1) ,idvar ) ) == ipk)
+         lmoor  = (  idmspc == 0 .OR. PRODUCT( iom_file( sdjf%num )%dimsz( 1:MAX(idmspc,1) ,idvar ) ) == ipk  )
          !
          SELECT CASE( ipk )
@@ -660,6 +655,7 @@
       !
       sdjf%rotn(2) = .false.   ! vector not yet rotated
-
+      !
    END SUBROUTINE fld_get
+
 
    SUBROUTINE fld_map( num, clvar, dta, nrec, map )
@@ -688,9 +684,9 @@
       REAL(wp), POINTER, DIMENSION(:,:,:)     ::   dta_read  ! work space for global data
       !!---------------------------------------------------------------------
-            
+      !
       ipi = SIZE( dta, 1 )
       ipj = 1
       ipk = SIZE( dta, 3 )
-
+      !
       idvar   = iom_varid( num, clvar )
       ilendta = iom_file(num)%dimsz(1,idvar)
@@ -698,14 +694,14 @@
 #if defined key_bdy
       ipj = iom_file(num)%dimsz(2,idvar)
-      IF ( map%ll_unstruc) THEN ! unstructured open boundary data file
+      IF( map%ll_unstruc) THEN   ! unstructured open boundary data file
          dta_read => dta_global
-      ELSE                      ! structured open boundary data file
+      ELSE                       ! structured open boundary data file
          dta_read => dta_global2
       ENDIF
 #endif
 
-      IF(lwp) WRITE(numout,*) 'Dim size for ',TRIM(clvar),' is ', ilendta
+      IF(lwp) WRITE(numout,*) 'Dim size for ',        TRIM(clvar),' is ', ilendta
       IF(lwp) WRITE(numout,*) 'Number of levels for ',TRIM(clvar),' is ', ipk
-
+      !
       SELECT CASE( ipk )
       CASE(1)        ;   CALL iom_get ( num, jpdom_unknown, clvar, dta_read(1:ilendta,1:ipj,1    ), nrec )
@@ -713,5 +709,5 @@
       END SELECT
       !
-      IF ( map%ll_unstruc ) THEN ! unstructured open boundary data file
+      IF( map%ll_unstruc ) THEN  ! unstructured open boundary data file
          DO ib = 1, ipi
             DO ik = 1, ipk
@@ -728,5 +724,5 @@
          END DO
       ENDIF
-
+      !
    END SUBROUTINE fld_map
 
@@ -738,17 +734,17 @@
       !! ** Purpose :   Vector fields may need to be rotated onto the local grid direction
       !!----------------------------------------------------------------------
-      INTEGER  , INTENT(in   )               ::   kt        ! ocean time step
-      TYPE(FLD), INTENT(inout), DIMENSION(:) ::   sd        ! input field related variables
-      !!
-      INTEGER                           ::   ju,jv,jk,jn  ! loop indices
-      INTEGER                           ::   imf          ! size of the structure sd
-      INTEGER                           ::   ill          ! character length
-      INTEGER                           ::   iv           ! indice of V component
+      INTEGER                , INTENT(in   ) ::   kt   ! ocean time step
+      TYPE(FLD), DIMENSION(:), INTENT(inout) ::   sd   ! input field related variables
+      !
+      INTEGER ::   ju, jv, jk, jn  ! loop indices
+      INTEGER ::   imf             ! size of the structure sd
+      INTEGER ::   ill             ! character length
+      INTEGER ::   iv              ! indice of V component
+      CHARACTER (LEN=100)               ::   clcomp       ! dummy weight name
       REAL(wp), POINTER, DIMENSION(:,:) ::   utmp, vtmp   ! temporary arrays for vector rotation
-      CHARACTER (LEN=100)               ::   clcomp       ! dummy weight name
-      !!---------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj, utmp, vtmp )
-
+      !!---------------------------------------------------------------------
+      !
+      CALL wrk_alloc( jpi,jpj,   utmp, vtmp )
+      !
       !! (sga: following code should be modified so that pairs arent searched for each time
       !
@@ -786,5 +782,5 @@
        END DO
       !
-      CALL wrk_dealloc( jpi,jpj, utmp, vtmp )
+      CALL wrk_dealloc( jpi,jpj,   utmp, vtmp )
       !
    END SUBROUTINE fld_rot
@@ -802,5 +798,5 @@
       INTEGER, OPTIONAL, INTENT(in   ) ::   kday     ! day value
       LOGICAL, OPTIONAL, INTENT(in   ) ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
-      !!
+      !
       LOGICAL :: llprevyr              ! are we reading previous year  file?
       LOGICAL :: llprevmth             ! are we reading previous month file?
@@ -853,9 +849,9 @@
       !
       IF( TRIM(clname) /= TRIM(sdjf%clname) .OR. sdjf%num == 0 ) THEN   ! new file to be open 
-
+         !
          sdjf%clname = TRIM(clname)
          IF( sdjf%num /= 0 )   CALL iom_close( sdjf%num )   ! close file if already open
          CALL iom_open( sdjf%clname, sdjf%num, ldstop = ldstop, ldiof =  LEN(TRIM(sdjf%wgtname)) > 0 )
-
+         !
          ! find the last record to be read -> update sdjf%nreclast
          indexyr = iyear - nyear + 1
@@ -866,5 +862,5 @@
          CASE ( 2 )   ;   imonth_len = 31   ! next     year -> imonth = 1
          END SELECT
-         
+         !
          ! last record to be read in the current file
          IF    ( sdjf%nfreqh == -12 ) THEN                 ;   sdjf%nreclast = 1    !  yearly mean
@@ -880,5 +876,5 @@
             ENDIF
          ENDIF
-         
+         !
       ENDIF
       !
@@ -901,5 +897,5 @@
       INTEGER  ::   jf       ! dummy indices
       !!---------------------------------------------------------------------
-
+      !
       DO jf = 1, SIZE(sdf)
          sdf(jf)%clrootname = TRIM( cdir )//TRIM( sdf_n(jf)%clname )
@@ -923,5 +919,5 @@
          sdf(jf)%nreclast = -1 ! Set to non zero default value to avoid errors, is updated to meaningful value during fld_clopn
       END DO
-
+      !
       IF(lwp) THEN      ! control print
          WRITE(numout,*)
@@ -943,5 +939,5 @@
          END DO
       ENDIF
-      
+      !
    END SUBROUTINE fld_fill
 
@@ -958,5 +954,5 @@
       TYPE( FLD ), INTENT(in   ) ::   sd        ! field with name of weights file
       INTEGER    , INTENT(inout) ::   kwgt      ! index of weights
-      !!
+      !
       INTEGER ::   kw, nestid   ! local integer
       LOGICAL ::   found        ! local logical
@@ -966,5 +962,5 @@
       !! weights filename is either present or we hit the end of the list
       found = .FALSE.
-
+      !
       !! because agrif nest part of filenames are now added in iom_open
       !! to distinguish between weights files on the different grids, need to track
@@ -1028,18 +1024,18 @@
       TYPE( FLD ), INTENT(in) ::   sd   ! field with name of weights file
       !!
-      INTEGER                           ::   jn            ! dummy loop indices
-      INTEGER                           ::   inum          ! temporary logical unit
-      INTEGER                           ::   id            ! temporary variable id
-      INTEGER                           ::   ipk           ! temporary vertical dimension
-      CHARACTER (len=5)                 ::   aname
+      INTEGER ::   jn         ! dummy loop indices
+      INTEGER ::   inum       ! local logical unit
+      INTEGER ::   id         ! local variable id
+      INTEGER ::   ipk        ! local vertical dimension
+      INTEGER ::   zwrap      ! local integer
+      LOGICAL ::   cyclical   ! 
+      CHARACTER (len=5) ::   aname   !
       INTEGER , DIMENSION(:), ALLOCATABLE ::   ddims
       INTEGER , POINTER, DIMENSION(:,:) ::   data_src
       REAL(wp), POINTER, DIMENSION(:,:) ::   data_tmp
-      LOGICAL                           ::   cyclical
-      INTEGER                           ::   zwrap      ! local integer
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi,jpj, data_src )   ! integer
-      CALL wrk_alloc( jpi,jpj, data_tmp )
+      !!----------------------------------------------------------------------
+      !
+      CALL wrk_alloc( jpi,jpj,   data_src )   ! integer
+      CALL wrk_alloc( jpi,jpj,   data_tmp )
       !
       IF( nxt_wgt > tot_wgts ) THEN
@@ -1151,7 +1147,7 @@
          ALLOCATE( ref_wgts(nxt_wgt)%fly_dta(ref_wgts(nxt_wgt)%jpiwgt+3, ref_wgts(nxt_wgt)%jpjwgt+3 ,ipk) )
          IF( ref_wgts(nxt_wgt)%cyclic ) ALLOCATE( ref_wgts(nxt_wgt)%col(1,ref_wgts(nxt_wgt)%jpjwgt+3,ipk) )
-
+         !
          nxt_wgt = nxt_wgt + 1
-
+         !
       ELSE 
          CALL ctl_stop( '    fld_weight : unable to read the file ' )
@@ -1166,6 +1162,6 @@
 
 
-   SUBROUTINE apply_seaoverland(clmaskfile,zfieldo,jpi1_lsm,jpi2_lsm,jpj1_lsm, &
-                          &      jpj2_lsm,itmpi,itmpj,itmpz,rec1_lsm,recn_lsm)
+   SUBROUTINE apply_seaoverland( clmaskfile, zfieldo, jpi1_lsm, jpi2_lsm, jpj1_lsm,   &
+                          &      jpj2_lsm, itmpi, itmpj, itmpz, rec1_lsm, recn_lsm )
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE apply_seaoverland  ***
@@ -1176,67 +1172,61 @@
       !!      D. Delrosso INGV          
       !!---------------------------------------------------------------------- 
-      INTEGER                                   :: inum,jni,jnj,jnz,jc                  ! temporary indices
-      INTEGER,                   INTENT(in)     :: itmpi,itmpj,itmpz                    ! lengths
-      INTEGER,                   INTENT(in)     :: jpi1_lsm,jpi2_lsm,jpj1_lsm,jpj2_lsm  ! temporary indices
-      INTEGER, DIMENSION(3),     INTENT(in)     :: rec1_lsm,recn_lsm                    ! temporary arrays for start and length
-      REAL(wp),DIMENSION (:,:,:),INTENT(inout)  :: zfieldo                              ! input/output array for seaoverland application
-      REAL(wp),DIMENSION (:,:,:),ALLOCATABLE    :: zslmec1                              ! temporary array for land point detection
-      REAL(wp),DIMENSION (:,:),  ALLOCATABLE    :: zfieldn                              ! array of forcing field with undeff for land points
-      REAL(wp),DIMENSION (:,:),  ALLOCATABLE    :: zfield                               ! array of forcing field
-      CHARACTER (len=100),       INTENT(in)     :: clmaskfile                           ! land/sea mask file name
-      !!---------------------------------------------------------------------
-      ALLOCATE ( zslmec1(itmpi,itmpj,itmpz) )
-      ALLOCATE ( zfieldn(itmpi,itmpj) )
-      ALLOCATE ( zfield(itmpi,itmpj) )
-
+      INTEGER,                   INTENT(in   ) :: itmpi,itmpj,itmpz                    ! lengths
+      INTEGER,                   INTENT(in   ) :: jpi1_lsm,jpi2_lsm,jpj1_lsm,jpj2_lsm  ! temporary indices
+      INTEGER, DIMENSION(3),     INTENT(in   ) :: rec1_lsm,recn_lsm                    ! temporary arrays for start and length
+      REAL(wp),DIMENSION (:,:,:),INTENT(inout) :: zfieldo                              ! input/output array for seaoverland application
+      CHARACTER (len=100),       INTENT(in   ) :: clmaskfile                           ! land/sea mask file name
+      !
+      INTEGER :: inum,jni,jnj,jnz,jc   ! local indices
+      REAL(wp),DIMENSION (:,:,:),ALLOCATABLE :: zslmec1             ! local array for land point detection
+      REAL(wp),DIMENSION (:,:),  ALLOCATABLE :: zfieldn   ! array of forcing field with undeff for land points
+      REAL(wp),DIMENSION (:,:),  ALLOCATABLE :: zfield    ! array of forcing field
+      !!---------------------------------------------------------------------
+      !
+      ALLOCATE ( zslmec1(itmpi,itmpj,itmpz), zfieldn(itmpi,itmpj), zfield(itmpi,itmpj) )
+      !
       ! Retrieve the land sea mask data
       CALL iom_open( clmaskfile, inum )
       SELECT CASE( SIZE(zfieldo(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:),3) )
       CASE(1)
-           CALL iom_get( inum, jpdom_unknown, 'LSM', zslmec1(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,1), 1, rec1_lsm, recn_lsm)
+         CALL iom_get( inum, jpdom_unknown, 'LSM', zslmec1(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,1), 1, rec1_lsm, recn_lsm)
       CASE DEFAULT
-           CALL iom_get( inum, jpdom_unknown, 'LSM', zslmec1(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:), 1, rec1_lsm, recn_lsm)
+         CALL iom_get( inum, jpdom_unknown, 'LSM', zslmec1(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:), 1, rec1_lsm, recn_lsm)
       END SELECT
       CALL iom_close( inum )
-
-      DO jnz=1,rec1_lsm(3)                            !! Loop over k dimension
-
-         DO jni=1,itmpi                               !! copy the original field into a tmp array
-            DO jnj=1,itmpj                            !! substituting undeff over land points
-            zfieldn(jni,jnj) = zfieldo(jni,jnj,jnz)
-               IF ( zslmec1(jni,jnj,jnz) == 1. ) THEN
-                  zfieldn(jni,jnj) = undeff_lsm
-               ENDIF
+      !
+      DO jnz=1,rec1_lsm(3)             !! Loop over k dimension
+         !
+         DO jni = 1, itmpi                               !! copy the original field into a tmp array
+            DO jnj = 1, itmpj                            !! substituting undeff over land points
+               zfieldn(jni,jnj) = zfieldo(jni,jnj,jnz)
+               IF( zslmec1(jni,jnj,jnz) == 1. )   zfieldn(jni,jnj) = undeff_lsm
             END DO
          END DO
-  
-      CALL seaoverland(zfieldn,itmpi,itmpj,zfield)
-      DO jc=1,nn_lsm
-         CALL seaoverland(zfield,itmpi,itmpj,zfield)
-      END DO
-
-      !   Check for Undeff and substitute original values
-      IF(ANY(zfield==undeff_lsm)) THEN
-         DO jni=1,itmpi
-            DO jnj=1,itmpj
-               IF (zfield(jni,jnj)==undeff_lsm) THEN
-                  zfield(jni,jnj) = zfieldo(jni,jnj,jnz)
-               ENDIF
-            ENDDO
-         ENDDO
-      ENDIF
-
-      zfieldo(:,:,jnz)=zfield(:,:)
-
-      END DO                          !! End Loop over k dimension
-
-      DEALLOCATE ( zslmec1 )
-      DEALLOCATE ( zfieldn )
-      DEALLOCATE ( zfield )
-
+         !
+         CALL seaoverland( zfieldn, itmpi, itmpj, zfield )
+         DO jc = 1, nn_lsm
+            CALL seaoverland( zfield, itmpi, itmpj, zfield )
+         END DO
+         !
+         !   Check for Undeff and substitute original values
+         IF( ANY(zfield==undeff_lsm) ) THEN
+            DO jni = 1, itmpi
+               DO jnj = 1, itmpj
+                  IF( zfield(jni,jnj)==undeff_lsm )   zfield(jni,jnj) = zfieldo(jni,jnj,jnz)
+               END DO
+            END DO
+         ENDIF
+         !
+         zfieldo(:,:,jnz) = zfield(:,:)
+         !
+      END DO                           !! End Loop over k dimension
+      !
+      DEALLOCATE ( zslmec1, zfieldn, zfield )
+      !
    END SUBROUTINE apply_seaoverland 
 
 
-   SUBROUTINE seaoverland(zfieldn,ileni,ilenj,zfield)
+   SUBROUTINE seaoverland( zfieldn, ileni, ilenj, zfield )
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE seaoverland  ***
@@ -1245,29 +1235,31 @@
       !!      D. Delrosso INGV
       !!---------------------------------------------------------------------- 
-      INTEGER,INTENT(in)                       :: ileni,ilenj              ! lengths 
-      REAL,DIMENSION (ileni,ilenj),INTENT(in)  :: zfieldn                  ! array of forcing field with undeff for land points
-      REAL,DIMENSION (ileni,ilenj),INTENT(out) :: zfield                   ! array of forcing field
-      REAL,DIMENSION (ileni,ilenj)             :: zmat1,zmat2,zmat3,zmat4  ! temporary arrays for seaoverland application
-      REAL,DIMENSION (ileni,ilenj)             :: zmat5,zmat6,zmat7,zmat8  ! temporary arrays for seaoverland application
-      REAL,DIMENSION (ileni,ilenj)             :: zlsm2d                   ! temporary arrays for seaoverland application
-      REAL,DIMENSION (ileni,ilenj,8)           :: zlsm3d                   ! temporary arrays for seaoverland application
-      LOGICAL,DIMENSION (ileni,ilenj,8)        :: ll_msknan3d              ! logical mask for undeff detection
-      LOGICAL,DIMENSION (ileni,ilenj)          :: ll_msknan2d              ! logical mask for undeff detection
+      INTEGER                      , INTENT(in   ) :: ileni,ilenj   ! lengths 
+      REAL, DIMENSION (ileni,ilenj), INTENT(in   ) :: zfieldn       ! array of forcing field with undeff for land points
+      REAL, DIMENSION (ileni,ilenj), INTENT(  out) :: zfield        ! array of forcing field
+      !
+      REAL   , DIMENSION (ileni,ilenj)   :: zmat1, zmat2, zmat3, zmat4  ! local arrays 
+      REAL   , DIMENSION (ileni,ilenj)   :: zmat5, zmat6, zmat7, zmat8  !   -     - 
+      REAL   , DIMENSION (ileni,ilenj)   :: zlsm2d                      !   -     - 
+      REAL   , DIMENSION (ileni,ilenj,8) :: zlsm3d                      !   -     -
+      LOGICAL, DIMENSION (ileni,ilenj,8) :: ll_msknan3d                 ! logical mask for undeff detection
+      LOGICAL, DIMENSION (ileni,ilenj)   :: ll_msknan2d                 ! logical mask for undeff detection
       !!---------------------------------------------------------------------- 
-      zmat8 = eoshift(zfieldn   ,  SHIFT=-1, BOUNDARY = (/zfieldn(:,1)/)    ,DIM=2)
-      zmat1 = eoshift(zmat8     ,  SHIFT=-1, BOUNDARY = (/zmat8(1,:)/)      ,DIM=1)
-      zmat2 = eoshift(zfieldn   ,  SHIFT=-1, BOUNDARY = (/zfieldn(1,:)/)    ,DIM=1)
-      zmat4 = eoshift(zfieldn   ,  SHIFT= 1, BOUNDARY = (/zfieldn(:,ilenj)/),DIM=2)
-      zmat3 = eoshift(zmat4     ,  SHIFT=-1, BOUNDARY = (/zmat4(1,:)/)      ,DIM=1)
-      zmat5 = eoshift(zmat4     ,  SHIFT= 1, BOUNDARY = (/zmat4(ileni,:)/)  ,DIM=1)
-      zmat6 = eoshift(zfieldn   ,  SHIFT= 1, BOUNDARY = (/zfieldn(ileni,:)/),DIM=1)
-      zmat7 = eoshift(zmat8     ,  SHIFT= 1, BOUNDARY = (/zmat8(ileni,:)/)  ,DIM=1)
-
+      zmat8 = eoshift( zfieldn , SHIFT=-1 , BOUNDARY = (/zfieldn(:,1)/)     , DIM=2 )
+      zmat1 = eoshift( zmat8   , SHIFT=-1 , BOUNDARY = (/zmat8(1,:)/)       , DIM=1 )
+      zmat2 = eoshift( zfieldn , SHIFT=-1 , BOUNDARY = (/zfieldn(1,:)/)     , DIM=1 )
+      zmat4 = eoshift( zfieldn , SHIFT= 1 , BOUNDARY = (/zfieldn(:,ilenj)/) , DIM=2 )
+      zmat3 = eoshift( zmat4   , SHIFT=-1 , BOUNDARY = (/zmat4(1,:)/)       , DIM=1 )
+      zmat5 = eoshift( zmat4   , SHIFT= 1 , BOUNDARY = (/zmat4(ileni,:)/)   , DIM=1 )
+      zmat6 = eoshift( zfieldn , SHIFT= 1 , BOUNDARY = (/zfieldn(ileni,:)/) , DIM=1 )
+      zmat7 = eoshift( zmat8   , SHIFT= 1 , BOUNDARY = (/zmat8(ileni,:)/)   , DIM=1 )
+      !
       zlsm3d  = RESHAPE( (/ zmat1, zmat2, zmat3, zmat4, zmat5, zmat6, zmat7, zmat8 /), (/ ileni, ilenj, 8 /))
-      ll_msknan3d = .not.(zlsm3d==undeff_lsm)
-      ll_msknan2d = .not.(zfieldn==undeff_lsm)  ! FALSE where is Undeff (land)
-      zlsm2d = (SUM ( zlsm3d, 3 , ll_msknan3d ) )/(MAX(1,(COUNT( ll_msknan3d , 3 ))   ))
-      WHERE ((COUNT( ll_msknan3d , 3 )) == 0.0_wp)  zlsm2d = undeff_lsm
-      zfield = MERGE (zfieldn,zlsm2d,ll_msknan2d)
+      ll_msknan3d = .NOT.( zlsm3d  == undeff_lsm )
+      ll_msknan2d = .NOT.( zfieldn == undeff_lsm )  ! FALSE where is Undeff (land)
+      zlsm2d = SUM( zlsm3d, 3 , ll_msknan3d ) / MAX( 1 , COUNT( ll_msknan3d , 3 ) )
+      WHERE( COUNT( ll_msknan3d , 3 ) == 0._wp )   zlsm2d = undeff_lsm
+      zfield = MERGE( zfieldn, zlsm2d, ll_msknan2d )
+      !
    END SUBROUTINE seaoverland
 
@@ -1288,19 +1280,18 @@
       INTEGER                   , INTENT(in   ) ::   nrec    ! record number to read (ie time slice)
       CHARACTER(LEN=*)          , INTENT(in   ) ::   lsmfile ! land sea mask file name
-      !! 
-      REAL(wp),DIMENSION(:,:,:),ALLOCATABLE     ::   ztmp_fly_dta,zfieldo                  ! temporary array of values on input grid
-      INTEGER, DIMENSION(3)                     ::   rec1,recn                             ! temporary arrays for start and length
-      INTEGER, DIMENSION(3)                     ::   rec1_lsm,recn_lsm                     ! temporary arrays for start and length in case of seaoverland
-      INTEGER                                   ::   ii_lsm1,ii_lsm2,ij_lsm1,ij_lsm2       ! temporary indices
-      INTEGER                                   ::   jk, jn, jm, jir, jjr                  ! loop counters
-      INTEGER                                   ::   ni, nj                                ! lengths
-      INTEGER                                   ::   jpimin,jpiwid                         ! temporary indices
-      INTEGER                                   ::   jpimin_lsm,jpiwid_lsm                 ! temporary indices
-      INTEGER                                   ::   jpjmin,jpjwid                         ! temporary indices
-      INTEGER                                   ::   jpjmin_lsm,jpjwid_lsm                 ! temporary indices
-      INTEGER                                   ::   jpi1,jpi2,jpj1,jpj2                   ! temporary indices
-      INTEGER                                   ::   jpi1_lsm,jpi2_lsm,jpj1_lsm,jpj2_lsm   ! temporary indices
-      INTEGER                                   ::   itmpi,itmpj,itmpz                     ! lengths
-      
+      !
+      INTEGER, DIMENSION(3) ::   rec1, recn           ! temporary arrays for start and length
+      INTEGER, DIMENSION(3) ::   rec1_lsm, recn_lsm   ! temporary arrays for start and length in case of seaoverland
+      INTEGER ::   ii_lsm1,ii_lsm2,ij_lsm1,ij_lsm2    ! temporary indices
+      INTEGER ::   jk, jn, jm, jir, jjr               ! loop counters
+      INTEGER ::   ni, nj                             ! lengths
+      INTEGER ::   jpimin,jpiwid                      ! temporary indices
+      INTEGER ::   jpimin_lsm,jpiwid_lsm              ! temporary indices
+      INTEGER ::   jpjmin,jpjwid                      ! temporary indices
+      INTEGER ::   jpjmin_lsm,jpjwid_lsm              ! temporary indices
+      INTEGER ::   jpi1,jpi2,jpj1,jpj2                ! temporary indices
+      INTEGER ::   jpi1_lsm,jpi2_lsm,jpj1_lsm,jpj2_lsm   ! temporary indices
+      INTEGER ::   itmpi,itmpj,itmpz                     ! lengths
+      REAL(wp),DIMENSION(:,:,:), ALLOCATABLE ::   ztmp_fly_dta                 ! local array of values on input grid     
       !!----------------------------------------------------------------------
       !
@@ -1355,6 +1346,6 @@
 
 
-         itmpi=SIZE(ztmp_fly_dta(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:),1)
-         itmpj=SIZE(ztmp_fly_dta(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:),2)
+         itmpi=jpi2_lsm-jpi1_lsm+1
+         itmpj=jpj2_lsm-jpj1_lsm+1
          itmpz=kk
          ALLOCATE(ztmp_fly_dta(itmpi,itmpj,itmpz))
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/geo2ocean.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/geo2ocean.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/geo2ocean.F90	(revision 6140)
@@ -5,39 +5,41 @@
    !!======================================================================
    !! History :  OPA  !  07-1996  (O. Marti)  Original code
-   !!   NEMO     1.0  !  02-2008  (G. Madec)  F90: Free form
-   !!            3.0  !  
+   !!   NEMO     1.0  !  06-2006  (G. Madec )  Free form, F90 + opt.
+   !!                 !  04-2007  (S. Masson)  angle: Add T, F points and bugfix in cos lateral boundary
+   !!            3.0  !  07-2008  (G. Madec)  geo2oce suppress lon/lat agruments
+   !!            3.7  !  11-2015  (G. Madec)  remove the unused repere and repcmo routines
    !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
-   !!   repcmo      : 
-   !!   angle       :
-   !!   geo2oce     :
-   !!   repere      :   old routine suppress it ???
+   !!   rot_rep       : Rotate the Repere: geographic grid <==> stretched coordinates grid
+   !!   angle         :
+   !!   geo2oce       :
+   !!   oce2geo       :
    !!----------------------------------------------------------------------
-   USE dom_oce         ! mesh and scale factors
-   USE phycst          ! physical constants
-   USE in_out_manager  ! I/O manager
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp         ! MPP library
+   USE dom_oce        ! mesh and scale factors
+   USE phycst         ! physical constants
+   !
+   USE in_out_manager ! I/O manager
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp        ! MPP library
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   rot_rep, repcmo, repere, geo2oce, oce2geo   ! only rot_rep should be used
-                                             ! repcmo and repere are keep only for compatibility.
-                                             ! they are only a useless overlay of rot_rep
-
-   PUBLIC   obs_rot
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   &
-      gsint, gcost,   &  ! cos/sin between model grid lines and NP direction at T point
-      gsinu, gcosu,   &  ! cos/sin between model grid lines and NP direction at U point
-      gsinv, gcosv,   &  ! cos/sin between model grid lines and NP direction at V point
-      gsinf, gcosf       ! cos/sin between model grid lines and NP direction at F point
+   PUBLIC   rot_rep   ! called in sbccpl, fldread, and cyclone
+   PUBLIC   geo2oce   ! called in sbccpl
+   PUBLIC   oce2geo   ! called in sbccpl
+   PUBLIC   obs_rot   ! called in obs_rot_vel and obs_write
+
+   !                                         ! cos/sin between model grid lines and NP direction
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   gsint, gcost   ! at T point
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   gsinu, gcosu   ! at U point
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   gsinv, gcosv   ! at V point
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   gsinf, gcosf   ! at F point
 
    LOGICAL ,              SAVE, DIMENSION(4)     ::   linit = .FALSE.
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gsinlon, gcoslon, gsinlat, gcoslat
 
-   LOGICAL ::   lmust_init = .TRUE.        !: used to initialize the cos/sin variables (se above)
+   LOGICAL ::   lmust_init = .TRUE.        !: used to initialize the cos/sin variables (see above)
 
    !! * Substitutions
@@ -50,31 +52,4 @@
 CONTAINS
 
-   SUBROUTINE repcmo ( pxu1, pyu1, pxv1, pyv1,   &
-                       px2 , py2 )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE repcmo  ***
-      !!
-      !! ** Purpose :   Change vector componantes from a geographic grid to a
-      !!      stretched coordinates grid.
-      !!
-      !! ** Method  :   Initialization of arrays at the first call.
-      !!
-      !! ** Action  : - px2 : first  componante (defined at u point)
-      !!              - py2 : second componante (defined at v point)
-      !!----------------------------------------------------------------------
-      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   pxu1, pyu1   ! geographic vector componantes at u-point
-      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   pxv1, pyv1   ! geographic vector componantes at v-point
-      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   px2          ! i-componante (defined at u-point)
-      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   py2          ! j-componante (defined at v-point)
-      !!----------------------------------------------------------------------
-      
-      ! Change from geographic to stretched coordinate
-      ! ----------------------------------------------
-      CALL rot_rep( pxu1, pyu1, 'U', 'en->i',px2 )
-      CALL rot_rep( pxv1, pyv1, 'V', 'en->j',py2 )
-      
-   END SUBROUTINE repcmo
-
-
    SUBROUTINE rot_rep ( pxin, pyin, cd_type, cdtodo, prot )
       !!----------------------------------------------------------------------
@@ -83,33 +58,27 @@
       !! ** Purpose :   Rotate the Repere: Change vector componantes between
       !!                geographic grid <--> stretched coordinates grid.
-      !!
-      !! History :
-      !!   9.2  !  07-04  (S. Masson)  
-      !!                  (O. Marti ) Original code (repere and repcmo)
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT( IN ) ::   pxin, pyin   ! vector componantes
-      CHARACTER(len=1),             INTENT( IN ) ::   cd_type      ! define the nature of pt2d array grid-points
-      CHARACTER(len=5),             INTENT( IN ) ::   cdtodo       ! specify the work to do:
-      !!                                                           ! 'en->i' east-north componantes to model i componante
-      !!                                                           ! 'en->j' east-north componantes to model j componante
-      !!                                                           ! 'ij->e' model i-j componantes to east componante
-      !!                                                           ! 'ij->n' model i-j componantes to east componante
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(out) ::   prot      
-      !!----------------------------------------------------------------------
-
-      ! Initialization of gsin* and gcos* at first call
-      ! -----------------------------------------------
-
-      IF( lmust_init ) THEN
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pxin, pyin   ! vector componantes
+      CHARACTER(len=1),             INTENT(in   ) ::   cd_type      ! define the nature of pt2d array grid-points
+      CHARACTER(len=5),             INTENT(in   ) ::   cdtodo       ! type of transpormation:
+      !                                                             ! 'en->i' = east-north to i-component
+      !                                                             ! 'en->j' = east-north to j-component
+      !                                                             ! 'ij->e' = (i,j) components to east
+      !                                                             ! 'ij->n' = (i,j) components to north
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   prot      
+      !!----------------------------------------------------------------------
+      !
+      IF( lmust_init ) THEN      ! at 1st call only: set  gsin. & gcos.
          IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) ' rot_rep : geographic <--> stretched'
-         IF(lwp) WRITE(numout,*) ' ~~~~~    coordinate transformation'
+         IF(lwp) WRITE(numout,*) ' rot_rep: coordinate transformation : geographic <==> model (i,j)-components'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~~    '
          !
          CALL angle       ! initialization of the transformation
          lmust_init = .FALSE.
       ENDIF
-      
-      SELECT CASE (cdtodo)
-      CASE ('en->i')      ! 'en->i' est-north componantes to model i componante
+      !
+      SELECT CASE( cdtodo )      ! type of rotation
+      !
+      CASE( 'en->i' )                  ! east-north to i-component
          SELECT CASE (cd_type)
          CASE ('T')   ;   prot(:,:) = pxin(:,:) * gcost(:,:) + pyin(:,:) * gsint(:,:)
@@ -119,5 +88,5 @@
          CASE DEFAULT   ;   CALL ctl_stop( 'Only T, U, V and F grid points are coded' )
          END SELECT
-      CASE ('en->j')      ! 'en->j' est-north componantes to model j componante
+      CASE ('en->j')                   ! east-north to j-component
          SELECT CASE (cd_type)
          CASE ('T')   ;   prot(:,:) = pyin(:,:) * gcost(:,:) - pxin(:,:) * gsint(:,:)
@@ -127,5 +96,5 @@
          CASE DEFAULT   ;   CALL ctl_stop( 'Only T, U, V and F grid points are coded' )
          END SELECT
-      CASE ('ij->e')      ! 'ij->e' model i-j componantes to est componante
+      CASE ('ij->e')                   ! (i,j)-components to east
          SELECT CASE (cd_type)
          CASE ('T')   ;   prot(:,:) = pxin(:,:) * gcost(:,:) - pyin(:,:) * gsint(:,:)
@@ -135,5 +104,5 @@
          CASE DEFAULT   ;   CALL ctl_stop( 'Only T, U, V and F grid points are coded' )
          END SELECT
-      CASE ('ij->n')      ! 'ij->n' model i-j componantes to est componante
+      CASE ('ij->n')                   ! (i,j)-components to north 
          SELECT CASE (cd_type)
          CASE ('T')   ;   prot(:,:) = pyin(:,:) * gcost(:,:) + pxin(:,:) * gsint(:,:)
@@ -144,6 +113,7 @@
          END SELECT
       CASE DEFAULT   ;   CALL ctl_stop( 'rot_rep: Syntax Error in the definition of cdtodo' )
+      !
       END SELECT
-      
+      !
    END SUBROUTINE rot_rep
 
@@ -155,31 +125,24 @@
       !! ** Purpose :   Compute angles between model grid lines and the North direction
       !!
-      !! ** Method  :
-      !!
-      !! ** Action  :   Compute (gsint, gcost, gsinu, gcosu, gsinv, gcosv, gsinf, gcosf) arrays:
-      !!      sinus and cosinus of the angle between the north-south axe and the 
-      !!      j-direction at t, u, v and f-points
-      !!
-      !! History :
-      !!   7.0  !  96-07  (O. Marti )  Original code
-      !!   8.0  !  98-06  (G. Madec )
-      !!   8.5  !  98-06  (G. Madec )  Free form, F90 + opt.
-      !!   9.2  !  07-04  (S. Masson)  Add T, F points and bugfix in cos lateral boundary
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj   ! dummy loop indices
-      INTEGER ::   ierr     ! local integer
-      REAL(wp) ::   &
-         zlam, zphi,            &  ! temporary scalars
-         zlan, zphh,            &  !    "         "
-         zxnpt, zynpt, znnpt,   &  ! x,y components and norm of the vector: T point to North Pole
-         zxnpu, zynpu, znnpu,   &  ! x,y components and norm of the vector: U point to North Pole
-         zxnpv, zynpv, znnpv,   &  ! x,y components and norm of the vector: V point to North Pole
-         zxnpf, zynpf, znnpf,   &  ! x,y components and norm of the vector: F point to North Pole
-         zxvvt, zyvvt, znvvt,   &  ! x,y components and norm of the vector: between V points below and above a T point
-         zxffu, zyffu, znffu,   &  ! x,y components and norm of the vector: between F points below and above a U point
-         zxffv, zyffv, znffv,   &  ! x,y components and norm of the vector: between F points left  and right a V point
-         zxuuf, zyuuf, znuuf       ! x,y components and norm of the vector: between U points below and above a F point
-      !!----------------------------------------------------------------------
-
+      !! ** Method  :   sinus and cosinus of the angle between the north-south axe 
+      !!              and the j-direction at t, u, v and f-points
+      !!                dot and cross products are used to obtain cos and sin, resp.
+      !!
+      !! ** Action  : - gsint, gcost, gsinu, gcosu, gsinv, gcosv, gsinf, gcosf
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj   ! dummy loop indices
+      INTEGER  ::   ierr     ! local integer
+      REAL(wp) ::   zlam, zphi            ! local scalars
+      REAL(wp) ::   zlan, zphh            !   -      -
+      REAL(wp) ::   zxnpt, zynpt, znnpt   ! x,y components and norm of the vector: T point to North Pole
+      REAL(wp) ::   zxnpu, zynpu, znnpu   ! x,y components and norm of the vector: U point to North Pole
+      REAL(wp) ::   zxnpv, zynpv, znnpv   ! x,y components and norm of the vector: V point to North Pole
+      REAL(wp) ::   zxnpf, zynpf, znnpf   ! x,y components and norm of the vector: F point to North Pole
+      REAL(wp) ::   zxvvt, zyvvt, znvvt   ! x,y components and norm of the vector: between V points below and above a T point
+      REAL(wp) ::   zxffu, zyffu, znffu   ! x,y components and norm of the vector: between F points below and above a U point
+      REAL(wp) ::   zxffv, zyffv, znffv   ! x,y components and norm of the vector: between F points left  and right a V point
+      REAL(wp) ::   zxuuf, zyuuf, znuuf   ! x,y components and norm of the vector: between U points below and above a F point
+      !!----------------------------------------------------------------------
+      !
       ALLOCATE( gsint(jpi,jpj), gcost(jpi,jpj),   & 
          &      gsinu(jpi,jpj), gcosu(jpi,jpj),   & 
@@ -187,44 +150,39 @@
          &      gsinf(jpi,jpj), gcosf(jpi,jpj), STAT=ierr )
       IF(lk_mpp)   CALL mpp_sum( ierr )
-      IF( ierr /= 0 )   CALL ctl_stop('angle: unable to allocate arrays' )
-
+      IF( ierr /= 0 )   CALL ctl_stop( 'angle: unable to allocate arrays' )
+      !
       ! ============================= !
       ! Compute the cosinus and sinus !
       ! ============================= !
       ! (computation done on the north stereographic polar plane)
-
+      !
       DO jj = 2, jpjm1
          DO ji = fs_2, jpi   ! vector opt.
-
-            ! north pole direction & modulous (at t-point)
-            zlam = glamt(ji,jj)
+            !                  
+            zlam = glamt(ji,jj)     ! north pole direction & modulous (at t-point)
             zphi = gphit(ji,jj)
             zxnpt = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
             zynpt = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
             znnpt = zxnpt*zxnpt + zynpt*zynpt
-
-            ! north pole direction & modulous (at u-point)
-            zlam = glamu(ji,jj)
+            !
+            zlam = glamu(ji,jj)     ! north pole direction & modulous (at u-point)
             zphi = gphiu(ji,jj)
             zxnpu = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
             zynpu = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
             znnpu = zxnpu*zxnpu + zynpu*zynpu
-
-            ! north pole direction & modulous (at v-point)
-            zlam = glamv(ji,jj)
+            !
+            zlam = glamv(ji,jj)     ! north pole direction & modulous (at v-point)
             zphi = gphiv(ji,jj)
             zxnpv = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
             zynpv = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
             znnpv = zxnpv*zxnpv + zynpv*zynpv
-
-            ! north pole direction & modulous (at f-point)
-            zlam = glamf(ji,jj)
+            !
+            zlam = glamf(ji,jj)     ! north pole direction & modulous (at f-point)
             zphi = gphif(ji,jj)
             zxnpf = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
             zynpf = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
             znnpf = zxnpf*zxnpf + zynpf*zynpf
-
-            ! j-direction: v-point segment direction (around t-point)
-            zlam = glamv(ji,jj  )
+            !
+            zlam = glamv(ji,jj  )   ! j-direction: v-point segment direction (around t-point)
             zphi = gphiv(ji,jj  )
             zlan = glamv(ji,jj-1)
@@ -236,7 +194,6 @@
             znvvt = SQRT( znnpt * ( zxvvt*zxvvt + zyvvt*zyvvt )  )
             znvvt = MAX( znvvt, 1.e-14 )
-
-            ! j-direction: f-point segment direction (around u-point)
-            zlam = glamf(ji,jj  )
+            !
+            zlam = glamf(ji,jj  )   ! j-direction: f-point segment direction (around u-point)
             zphi = gphif(ji,jj  )
             zlan = glamf(ji,jj-1)
@@ -248,7 +205,6 @@
             znffu = SQRT( znnpu * ( zxffu*zxffu + zyffu*zyffu )  )
             znffu = MAX( znffu, 1.e-14 )
-
-            ! i-direction: f-point segment direction (around v-point)
-            zlam = glamf(ji  ,jj)
+            !
+            zlam = glamf(ji  ,jj)   ! i-direction: f-point segment direction (around v-point)
             zphi = gphif(ji  ,jj)
             zlan = glamf(ji-1,jj)
@@ -260,7 +216,6 @@
             znffv = SQRT( znnpv * ( zxffv*zxffv + zyffv*zyffv )  )
             znffv = MAX( znffv, 1.e-14 )
-
-            ! j-direction: u-point segment direction (around f-point)
-            zlam = glamu(ji,jj+1)
+            !
+            zlam = glamu(ji,jj+1)   ! j-direction: u-point segment direction (around f-point)
             zphi = gphiu(ji,jj+1)
             zlan = glamu(ji,jj  )
@@ -272,19 +227,18 @@
             znuuf = SQRT( znnpf * ( zxuuf*zxuuf + zyuuf*zyuuf )  )
             znuuf = MAX( znuuf, 1.e-14 )
-
-            ! cosinus and sinus using scalar and vectorial products
+            !
+            !                       ! cosinus and sinus using dot and cross products
             gsint(ji,jj) = ( zxnpt*zyvvt - zynpt*zxvvt ) / znvvt
             gcost(ji,jj) = ( zxnpt*zxvvt + zynpt*zyvvt ) / znvvt
-
+            !
             gsinu(ji,jj) = ( zxnpu*zyffu - zynpu*zxffu ) / znffu
             gcosu(ji,jj) = ( zxnpu*zxffu + zynpu*zyffu ) / znffu
-
+            !
             gsinf(ji,jj) = ( zxnpf*zyuuf - zynpf*zxuuf ) / znuuf
             gcosf(ji,jj) = ( zxnpf*zxuuf + zynpf*zyuuf ) / znuuf
-
-            ! (caution, rotation of 90 degres)
+            !
             gsinv(ji,jj) = ( zxnpv*zxffv + zynpv*zyffv ) / znffv
-            gcosv(ji,jj) =-( zxnpv*zyffv - zynpv*zxffv ) / znffv
-
+            gcosv(ji,jj) =-( zxnpv*zyffv - zynpv*zxffv ) / znffv     ! (caution, rotation of 90 degres)
+            !
          END DO
       END DO
@@ -318,16 +272,14 @@
       ! Lateral boundary conditions !
       ! =========================== !
-
-      ! lateral boundary cond.: T-, U-, V-, F-pts, sgn
+      !           ! lateral boundary cond.: T-, U-, V-, F-pts, sgn
       CALL lbc_lnk( gcost, 'T', -1. )   ;   CALL lbc_lnk( gsint, 'T', -1. )
       CALL lbc_lnk( gcosu, 'U', -1. )   ;   CALL lbc_lnk( gsinu, 'U', -1. )
       CALL lbc_lnk( gcosv, 'V', -1. )   ;   CALL lbc_lnk( gsinv, 'V', -1. )
       CALL lbc_lnk( gcosf, 'F', -1. )   ;   CALL lbc_lnk( gsinf, 'F', -1. )
-
+      !
    END SUBROUTINE angle
 
 
-   SUBROUTINE geo2oce ( pxx, pyy, pzz, cgrid,     &
-                        pte, ptn )
+   SUBROUTINE geo2oce ( pxx, pyy, pzz, cgrid, pte, ptn )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE geo2oce  ***
@@ -335,19 +287,11 @@
       !! ** Purpose :
       !!
-      !! ** Method  :   Change wind stress from geocentric to east/north
-      !!
-      !! History :
-      !!        !         (O. Marti)  Original code
-      !!        !  91-03  (G. Madec)
-      !!        !  92-07  (M. Imbard)
-      !!        !  99-11  (M. Imbard) NetCDF format with IOIPSL
-      !!        !  00-08  (D. Ludicone) Reduced section at Bab el Mandeb
-      !!   8.5  !  02-06  (G. Madec)  F90: Free form
-      !!   3.0  !  07-08  (G. Madec)  geo2oce suppress lon/lat agruments
+      !! ** Method  :   Change a vector from geocentric to east/north 
+      !!
       !!----------------------------------------------------------------------
       REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::  pxx, pyy, pzz
       CHARACTER(len=1)            , INTENT(in   ) ::  cgrid
       REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::  pte, ptn
-      !!
+      !
       REAL(wp), PARAMETER :: rpi = 3.141592653e0
       REAL(wp), PARAMETER :: rad = rpi / 180.e0
@@ -355,5 +299,5 @@
       INTEGER ::   ierr   ! local integer
       !!----------------------------------------------------------------------
-
+      !
       IF( .NOT. ALLOCATED( gsinlon ) ) THEN
          ALLOCATE( gsinlon(jpi,jpj,4) , gcoslon(jpi,jpj,4) ,   &
@@ -361,4 +305,81 @@
          IF( lk_mpp    )   CALL mpp_sum( ierr )
          IF( ierr /= 0 )   CALL ctl_stop('geo2oce: unable to allocate arrays' )
+      ENDIF
+      !
+      SELECT CASE( cgrid)
+      CASE ( 'T' )   
+         ig = 1
+         IF( .NOT. linit(ig) ) THEN 
+            gsinlon(:,:,ig) = SIN( rad * glamt(:,:) )
+            gcoslon(:,:,ig) = COS( rad * glamt(:,:) )
+            gsinlat(:,:,ig) = SIN( rad * gphit(:,:) )
+            gcoslat(:,:,ig) = COS( rad * gphit(:,:) )
+            linit(ig) = .TRUE.
+         ENDIF
+      CASE ( 'U' )   
+         ig = 2
+         IF( .NOT. linit(ig) ) THEN 
+            gsinlon(:,:,ig) = SIN( rad * glamu(:,:) )
+            gcoslon(:,:,ig) = COS( rad * glamu(:,:) )
+            gsinlat(:,:,ig) = SIN( rad * gphiu(:,:) )
+            gcoslat(:,:,ig) = COS( rad * gphiu(:,:) )
+            linit(ig) = .TRUE.
+         ENDIF
+      CASE ( 'V' )   
+         ig = 3
+         IF( .NOT. linit(ig) ) THEN 
+            gsinlon(:,:,ig) = SIN( rad * glamv(:,:) )
+            gcoslon(:,:,ig) = COS( rad * glamv(:,:) )
+            gsinlat(:,:,ig) = SIN( rad * gphiv(:,:) )
+            gcoslat(:,:,ig) = COS( rad * gphiv(:,:) )
+            linit(ig) = .TRUE.
+         ENDIF
+      CASE ( 'F' )   
+         ig = 4
+         IF( .NOT. linit(ig) ) THEN 
+            gsinlon(:,:,ig) = SIN( rad * glamf(:,:) )
+            gcoslon(:,:,ig) = COS( rad * glamf(:,:) )
+            gsinlat(:,:,ig) = SIN( rad * gphif(:,:) )
+            gcoslat(:,:,ig) = COS( rad * gphif(:,:) )
+            linit(ig) = .TRUE.
+         ENDIF
+      CASE default   
+         WRITE(ctmp1,*) 'geo2oce : bad grid argument : ', cgrid
+         CALL ctl_stop( ctmp1 )
+      END SELECT
+      !
+      pte = - gsinlon(:,:,ig) * pxx + gcoslon(:,:,ig) * pyy
+      ptn = - gcoslon(:,:,ig) * gsinlat(:,:,ig) * pxx    &
+         &  - gsinlon(:,:,ig) * gsinlat(:,:,ig) * pyy    &
+         &  + gcoslat(:,:,ig) * pzz
+      !
+   END SUBROUTINE geo2oce
+
+
+   SUBROUTINE oce2geo ( pte, ptn, cgrid, pxx , pyy , pzz )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE oce2geo  ***
+      !!      
+      !! ** Purpose :
+      !!
+      !! ** Method  :   Change vector from east/north to geocentric
+      !!
+      !! History :     ! (A. Caubel)  oce2geo - Original code
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( IN    ) ::  pte, ptn
+      CHARACTER(len=1)            , INTENT( IN    ) ::  cgrid
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(   OUT ) ::  pxx , pyy , pzz
+      !!
+      REAL(wp), PARAMETER :: rpi = 3.141592653E0
+      REAL(wp), PARAMETER :: rad = rpi / 180.e0
+      INTEGER ::   ig     !
+      INTEGER ::   ierr   ! local integer
+      !!----------------------------------------------------------------------
+
+      IF( .NOT. ALLOCATED( gsinlon ) ) THEN
+         ALLOCATE( gsinlon(jpi,jpj,4) , gcoslon(jpi,jpj,4) ,   &
+            &      gsinlat(jpi,jpj,4) , gcoslat(jpi,jpj,4) , STAT=ierr )
+         IF( lk_mpp    )   CALL mpp_sum( ierr )
+         IF( ierr /= 0 )   CALL ctl_stop('oce2geo: unable to allocate arrays' )
       ENDIF
 
@@ -404,139 +425,13 @@
             CALL ctl_stop( ctmp1 )
       END SELECT
-      
-      pte = - gsinlon(:,:,ig) * pxx + gcoslon(:,:,ig) * pyy
-      ptn = - gcoslon(:,:,ig) * gsinlat(:,:,ig) * pxx    &
-            - gsinlon(:,:,ig) * gsinlat(:,:,ig) * pyy    &
-            + gcoslat(:,:,ig) * pzz
-!!$   ptv =   gcoslon(:,:,ig) * gcoslat(:,:,ig) * pxx    &
-!!$         + gsinlon(:,:,ig) * gcoslat(:,:,ig) * pyy    &
-!!$         + gsinlat(:,:,ig) * pzz
-      !
-   END SUBROUTINE geo2oce
-
-   SUBROUTINE oce2geo ( pte, ptn, cgrid,     &
-                        pxx , pyy , pzz )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE oce2geo  ***
-      !!      
-      !! ** Purpose :
-      !!
-      !! ** Method  :   Change vector from east/north to geocentric
-      !!
-      !! History :
-      !!        !         (A. Caubel)  oce2geo - Original code
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT( IN    ) ::  pte, ptn
-      CHARACTER(len=1)            , INTENT( IN    ) ::  cgrid
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(   OUT ) ::  pxx , pyy , pzz
-      !!
-      REAL(wp), PARAMETER :: rpi = 3.141592653E0
-      REAL(wp), PARAMETER :: rad = rpi / 180.e0
-      INTEGER ::   ig     !
-      INTEGER ::   ierr   ! local integer
-      !!----------------------------------------------------------------------
-
-      IF( .NOT. ALLOCATED( gsinlon ) ) THEN
-         ALLOCATE( gsinlon(jpi,jpj,4) , gcoslon(jpi,jpj,4) ,   &
-            &      gsinlat(jpi,jpj,4) , gcoslat(jpi,jpj,4) , STAT=ierr )
-         IF( lk_mpp    )   CALL mpp_sum( ierr )
-         IF( ierr /= 0 )   CALL ctl_stop('oce2geo: unable to allocate arrays' )
-      ENDIF
-
-      SELECT CASE( cgrid)
-         CASE ( 'T' )   
-            ig = 1
-            IF( .NOT. linit(ig) ) THEN 
-               gsinlon(:,:,ig) = SIN( rad * glamt(:,:) )
-               gcoslon(:,:,ig) = COS( rad * glamt(:,:) )
-               gsinlat(:,:,ig) = SIN( rad * gphit(:,:) )
-               gcoslat(:,:,ig) = COS( rad * gphit(:,:) )
-               linit(ig) = .TRUE.
-            ENDIF
-         CASE ( 'U' )   
-            ig = 2
-            IF( .NOT. linit(ig) ) THEN 
-               gsinlon(:,:,ig) = SIN( rad * glamu(:,:) )
-               gcoslon(:,:,ig) = COS( rad * glamu(:,:) )
-               gsinlat(:,:,ig) = SIN( rad * gphiu(:,:) )
-               gcoslat(:,:,ig) = COS( rad * gphiu(:,:) )
-               linit(ig) = .TRUE.
-            ENDIF
-         CASE ( 'V' )   
-            ig = 3
-            IF( .NOT. linit(ig) ) THEN 
-               gsinlon(:,:,ig) = SIN( rad * glamv(:,:) )
-               gcoslon(:,:,ig) = COS( rad * glamv(:,:) )
-               gsinlat(:,:,ig) = SIN( rad * gphiv(:,:) )
-               gcoslat(:,:,ig) = COS( rad * gphiv(:,:) )
-               linit(ig) = .TRUE.
-            ENDIF
-         CASE ( 'F' )   
-            ig = 4
-            IF( .NOT. linit(ig) ) THEN 
-               gsinlon(:,:,ig) = SIN( rad * glamf(:,:) )
-               gcoslon(:,:,ig) = COS( rad * glamf(:,:) )
-               gsinlat(:,:,ig) = SIN( rad * gphif(:,:) )
-               gcoslat(:,:,ig) = COS( rad * gphif(:,:) )
-               linit(ig) = .TRUE.
-            ENDIF
-         CASE default   
-            WRITE(ctmp1,*) 'geo2oce : bad grid argument : ', cgrid
-            CALL ctl_stop( ctmp1 )
-      END SELECT
-
-       pxx = - gsinlon(:,:,ig) * pte - gcoslon(:,:,ig) * gsinlat(:,:,ig) * ptn 
-       pyy =   gcoslon(:,:,ig) * pte - gsinlon(:,:,ig) * gsinlat(:,:,ig) * ptn
-       pzz =   gcoslat(:,:,ig) * ptn
-
-      
+      !
+      pxx = - gsinlon(:,:,ig) * pte - gcoslon(:,:,ig) * gsinlat(:,:,ig) * ptn 
+      pyy =   gcoslon(:,:,ig) * pte - gsinlon(:,:,ig) * gsinlat(:,:,ig) * ptn
+      pzz =   gcoslat(:,:,ig) * ptn
+      !
    END SUBROUTINE oce2geo
 
 
-   SUBROUTINE repere ( px1, py1, px2, py2, kchoix, cd_type )
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE repere  ***
-      !!        
-      !! ** Purpose :   Change vector componantes between a geopgraphic grid 
-      !!      and a stretched coordinates grid.
-      !!
-      !! ** Method  :   
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!        !  89-03  (O. Marti)  original code
-      !!        !  92-02  (M. Imbard)
-      !!        !  93-03  (M. Guyon)  symetrical conditions
-      !!        !  98-05  (B. Blanke)
-      !!   8.5  !  02-08  (G. Madec)  F90: Free form
-      !!----------------------------------------------------------------------
-      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   px1, py1   ! two horizontal components to be rotated
-      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   px2, py2   ! the two horizontal components in the model repere
-      INTEGER , INTENT(in   )                     ::   kchoix     ! type of transformation
-      !                                                           ! = 1 change from geographic to model grid.
-      !                                                           ! =-1 change from model to geographic grid
-      CHARACTER(len=1), INTENT(in   ), OPTIONAL   ::   cd_type    ! define the nature of pt2d array grid-points
-      !
-      CHARACTER(len=1) ::   cl_type      ! define the nature of pt2d array grid-points (T point by default)
-      !!----------------------------------------------------------------------
-
-      cl_type = 'T'
-      IF( PRESENT(cd_type) )   cl_type = cd_type
-         !
-      SELECT CASE (kchoix)
-      CASE ( 1)      ! change from geographic to model grid.
-         CALL rot_rep( px1, py1, cl_type, 'en->i', px2 )
-         CALL rot_rep( px1, py1, cl_type, 'en->j', py2 )
-      CASE (-1)      ! change from model to geographic grid
-         CALL rot_rep( px1, py1, cl_type, 'ij->e', px2 )
-         CALL rot_rep( px1, py1, cl_type, 'ij->n', py2 )
-      CASE DEFAULT   ;   CALL ctl_stop( 'repere: Syntax Error in the definition of kchoix (1 OR -1' )
-      END SELECT
-      
-   END SUBROUTINE repere
-
-
-   SUBROUTINE obs_rot ( psinu, pcosu, psinv, pcosv )
+   SUBROUTINE obs_rot( psinu, pcosu, psinv, pcosv )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE obs_rot  ***
@@ -546,28 +441,24 @@
       !!                current at observation points
       !!
-      !! History :
-      !!   9.2  !  09-02  (K. Mogensen)
+      !! History :  9.2  !  09-02  (K. Mogensen)
       !!----------------------------------------------------------------------
       REAL(wp), DIMENSION(jpi,jpj), INTENT( OUT )::   psinu, pcosu, psinv, pcosv   ! copy of data
       !!----------------------------------------------------------------------
-
+      !
       ! Initialization of gsin* and gcos* at first call
       ! -----------------------------------------------
-
       IF( lmust_init ) THEN
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*) ' obs_rot : geographic <--> stretched'
          IF(lwp) WRITE(numout,*) ' ~~~~~~~   coordinate transformation'
-
          CALL angle       ! initialization of the transformation
          lmust_init = .FALSE.
-
       ENDIF
-
+      !
       psinu(:,:) = gsinu(:,:)
       pcosu(:,:) = gcosu(:,:)
       psinv(:,:) = gsinv(:,:)
       pcosv(:,:) = gcosv(:,:)
-
+      !
    END SUBROUTINE obs_rot
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90	(revision 6140)
@@ -44,8 +44,8 @@
    LOGICAL , PUBLIC ::   ln_dm2dc       !: Daily mean to Diurnal Cycle short wave (qsr)
    LOGICAL , PUBLIC ::   ln_rnf         !: runoffs / runoff mouths
+   LOGICAL , PUBLIC ::   ln_isf         !: ice shelf melting
    LOGICAL , PUBLIC ::   ln_ssr         !: Sea Surface restoring on SST and/or SSS      
    LOGICAL , PUBLIC ::   ln_apr_dyn     !: Atmospheric pressure forcing used on dynamics (ocean & ice)
    INTEGER , PUBLIC ::   nn_ice         !: flag for ice in the surface boundary condition (=0/1/2/3)
-   INTEGER , PUBLIC ::   nn_isf         !: flag for isf in the surface boundary condition (=0/1/2/3/4) 
    INTEGER , PUBLIC ::   nn_ice_embd    !: flag for levitating/embedding sea-ice in the ocean
    !                                             !: =0 levitating ice (no mass exchange, concentration/dilution effect)
@@ -172,7 +172,5 @@
          &      ssv_m  (jpi,jpj) , sss_m(jpi,jpj) , ssh_m(jpi,jpj) , STAT=ierr(4) )
          !
-#if defined key_vvl
       ALLOCATE( e3t_m(jpi,jpj) , STAT=ierr(5) )
-#endif
          !
       sbc_oce_alloc = MAXVAL( ierr )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcana.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcana.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcana.F90	(revision 6140)
@@ -37,5 +37,4 @@
    
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcapr.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcapr.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcapr.F90	(revision 6140)
@@ -13,4 +13,5 @@
    USE sbc_oce         ! surface boundary condition
    USE phycst          ! physical constants
+   !
    USE fldread         ! read input fields
    USE in_out_manager  ! I/O manager
@@ -38,6 +39,4 @@
    TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_apr   ! structure of input fields (file informations, fields read)
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 4.0 , NEMO Consortium (2011) 
@@ -112,5 +111,5 @@
          ENDIF
 !jc: stop below should rather be a warning 
-         IF( ( ln_apr_obc ) .AND. .NOT. ln_apr_dyn   )   &
+         IF( ln_apr_obc .AND. .NOT.ln_apr_dyn   )   &
             CALL ctl_stop( 'sbc_apr: use inverse barometer ssh at open boundary ONLY requires ln_apr_dyn=T' )
       ENDIF
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 6140)
@@ -19,36 +19,37 @@
 
    !!----------------------------------------------------------------------
-   !!   sbc_blk_core    : bulk formulation as ocean surface boundary condition (forced mode, CORE bulk formulea)
-   !!   blk_oce_core    : computes momentum, heat and freshwater fluxes over ocean
-   !!   blk_ice_core    : computes momentum, heat and freshwater fluxes over ice
-   !!   turb_core_2z    : Computes turbulent transfert coefficients
-   !!   cd_neutral_10m  : Estimate of the neutral drag coefficient at 10m
-   !!   psi_m           : universal profile stability function for momentum
-   !!   psi_h           : universal profile stability function for temperature and humidity
+   !!   sbc_blk_core  : bulk formulation as ocean surface boundary condition (forced mode, CORE bulk formulea)
+   !!   blk_oce_core  : computes momentum, heat and freshwater fluxes over ocean
+   !!   blk_ice_core  : computes momentum, heat and freshwater fluxes over ice
+   !!   turb_core_2z  : Computes turbulent transfert coefficients
+   !!   cd_neutral_10m: Estimate of the neutral drag coefficient at 10m
+   !!   psi_m         : universal profile stability function for momentum
+   !!   psi_h         : universal profile stability function for temperature and humidity
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE fldread         ! read input fields
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE cyclone         ! Cyclone 10m wind form trac of cyclone centres
-   USE sbcdcy          ! surface boundary condition: diurnal cycle
-   USE iom             ! I/O manager library
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! distribued memory computing library
-   USE wrk_nemo        ! work arrays
-   USE timing          ! Timing
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE prtctl          ! Print control
-   USE sbcwave, ONLY   :  cdn_wave ! wave module
-   USE sbc_ice         ! Surface boundary condition: ice fields
-   USE lib_fortran     ! to use key_nosignedzero
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE fldread        ! read input fields
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE cyclone        ! Cyclone 10m wind form trac of cyclone centres
+   USE sbcdcy         ! surface boundary condition: diurnal cycle
+   USE sbcwave , ONLY :   cdn_wave ! wave module
+   USE sbc_ice        ! Surface boundary condition: ice fields
+   USE lib_fortran    ! to use key_nosignedzero
 #if defined key_lim3
-   USE ice, ONLY       : u_ice, v_ice, jpl, pfrld, a_i_b
-   USE limthd_dh       ! for CALL lim_thd_snwblow
+   USE ice     , ONLY :   u_ice, v_ice, jpl, pfrld, a_i_b
+   USE limthd_dh      ! for CALL lim_thd_snwblow
 #elif defined key_lim2
-   USE ice_2, ONLY     : u_ice, v_ice
-   USE par_ice_2
+   USE ice_2   , ONLY :   u_ice, v_ice
+   USE par_ice_2      ! LIM-2 parameters
 #endif
+   !
+   USE iom            ! I/O manager library
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! distribued memory computing library
+   USE wrk_nemo       ! work arrays
+   USE timing         ! Timing
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl         ! Print control
 
    IMPLICIT NONE
@@ -84,5 +85,5 @@
    REAL(wp), PARAMETER ::   albo =    0.066       ! ocean albedo assumed to be constant
 
-   !                                  !!* Namelist namsbc_core : CORE bulk parameters
+   !                        !!* Namelist namsbc_core : CORE bulk parameters
    LOGICAL  ::   ln_taudif   ! logical flag to use the "mean of stress module - module of mean stress" data
    REAL(wp) ::   rn_pfac     ! multiplication factor for precipitation
@@ -93,5 +94,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -149,7 +149,7 @@
       TYPE(FLD_N) ::   sn_tdif                                 !   "                                 "
       NAMELIST/namsbc_core/ cn_dir , ln_taudif, rn_pfac, rn_efac, rn_vfac,  &
-         &                  sn_wndi, sn_wndj, sn_humi  , sn_qsr ,           &
-         &                  sn_qlw , sn_tair, sn_prec  , sn_snow,           &
-         &                  sn_tdif, rn_zqt,  rn_zu
+         &                  sn_wndi, sn_wndj  , sn_humi, sn_qsr ,           &
+         &                  sn_qlw , sn_tair  , sn_prec, sn_snow,           &
+         &                  sn_tdif, rn_zqt   ,  rn_zu
       !!---------------------------------------------------------------------
       !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_mfs.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_mfs.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_mfs.F90	(revision 6140)
@@ -8,21 +8,22 @@
 
    !!----------------------------------------------------------------------
-   !!   sbc_blk_mfs  : bulk formulation as ocean surface boundary condition
+   !!   sbc_blk_mfs   : bulk formulation as ocean surface boundary condition
    !!                   (forced mode, mfs bulk formulae)
-   !!   blk_oce_mfs  : ocean: computes momentum, heat and freshwater fluxes
+   !!   blk_oce_mfs   : ocean: computes momentum, heat and freshwater fluxes
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE fldread         ! read input fields
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE iom             ! I/O manager library
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! distribued memory computing library
-   USE wrk_nemo        ! work arrays
-   USE timing          ! Timing
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE prtctl          ! Print control
-   USE sbcwave,ONLY : cdn_wave !wave module
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE fldread        ! read input fields
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE sbcwave  ,ONLY :   cdn_wave !wave module
+   !
+   USE iom            ! I/O manager library
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! distribued memory computing library
+   USE wrk_nemo       ! work arrays
+   USE timing         ! Timing
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl         ! Print control
 
    IMPLICIT NONE
@@ -42,5 +43,4 @@
          
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -49,7 +49,5 @@
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
-
 
    SUBROUTINE sbc_blk_mfs( kt )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 6140)
@@ -18,29 +18,23 @@
    !!   sbc_cpl_snd     : send     fields to the atmosphere
    !!----------------------------------------------------------------------
-   USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice fields
-   USE sbcapr
-   USE sbcdcy          ! surface boundary condition: diurnal cycle
-   USE phycst          ! physical constants
+   USE dom_oce        ! ocean space and time domain
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE sbc_ice        ! Surface boundary condition: ice fields
+   USE sbcapr         ! Stochastic param. : ???
+   USE sbcdcy         ! surface boundary condition: diurnal cycle
+   USE phycst         ! physical constants
 #if defined key_lim3
-   USE ice             ! ice variables
+   USE ice            ! ice variables
 #endif
 #if defined key_lim2
-   USE par_ice_2       ! ice parameters
-   USE ice_2           ! ice variables
+   USE par_ice_2      ! ice parameters
+   USE ice_2          ! ice variables
 #endif
-   USE cpl_oasis3      ! OASIS3 coupling
-   USE geo2ocean       ! 
+   USE cpl_oasis3     ! OASIS3 coupling
+   USE geo2ocean      ! 
    USE oce   , ONLY : tsn, un, vn, sshn, ub, vb, sshb, fraqsr_1lev
-   USE albedo          !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! NetCDF library
-   USE lib_mpp         ! distribued memory computing library
-   USE wrk_nemo        ! work arrays
-   USE timing          ! Timing
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE eosbn2
-   USE sbcrnf   , ONLY : l_rnfcpl
+   USE albedo         ! 
+   USE eosbn2         ! 
+   USE sbcrnf  , ONLY : l_rnfcpl
 #if defined key_cpl_carbon_cycle
    USE p4zflx, ONLY : oce_co2
@@ -50,127 +44,132 @@
 #endif
 #if defined key_lim3
-   USE limthd_dh       ! for CALL lim_thd_snwblow
+   USE limthd_dh      ! for CALL lim_thd_snwblow
 #endif
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! NetCDF library
+   USE lib_mpp        ! distribued memory computing library
+   USE wrk_nemo       ! work arrays
+   USE timing         ! Timing
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   sbc_cpl_init       ! routine called by sbcmod.F90
-   PUBLIC   sbc_cpl_rcv        ! routine called by sbc_ice_lim(_2).F90
-   PUBLIC   sbc_cpl_snd        ! routine called by step.F90
-   PUBLIC   sbc_cpl_ice_tau    ! routine called by sbc_ice_lim(_2).F90
-   PUBLIC   sbc_cpl_ice_flx    ! routine called by sbc_ice_lim(_2).F90
-   PUBLIC   sbc_cpl_alloc      ! routine called in sbcice_cice.F90
-
-   INTEGER, PARAMETER ::   jpr_otx1   =  1            ! 3 atmosphere-ocean stress components on grid 1
-   INTEGER, PARAMETER ::   jpr_oty1   =  2            ! 
-   INTEGER, PARAMETER ::   jpr_otz1   =  3            ! 
-   INTEGER, PARAMETER ::   jpr_otx2   =  4            ! 3 atmosphere-ocean stress components on grid 2
-   INTEGER, PARAMETER ::   jpr_oty2   =  5            ! 
-   INTEGER, PARAMETER ::   jpr_otz2   =  6            ! 
-   INTEGER, PARAMETER ::   jpr_itx1   =  7            ! 3 atmosphere-ice   stress components on grid 1
-   INTEGER, PARAMETER ::   jpr_ity1   =  8            ! 
-   INTEGER, PARAMETER ::   jpr_itz1   =  9            ! 
-   INTEGER, PARAMETER ::   jpr_itx2   = 10            ! 3 atmosphere-ice   stress components on grid 2
-   INTEGER, PARAMETER ::   jpr_ity2   = 11            ! 
-   INTEGER, PARAMETER ::   jpr_itz2   = 12            ! 
-   INTEGER, PARAMETER ::   jpr_qsroce = 13            ! Qsr above the ocean
-   INTEGER, PARAMETER ::   jpr_qsrice = 14            ! Qsr above the ice
+   PUBLIC   sbc_cpl_init      ! routine called by sbcmod.F90
+   PUBLIC   sbc_cpl_rcv       ! routine called by sbc_ice_lim(_2).F90
+   PUBLIC   sbc_cpl_snd       ! routine called by step.F90
+   PUBLIC   sbc_cpl_ice_tau   ! routine called by sbc_ice_lim(_2).F90
+   PUBLIC   sbc_cpl_ice_flx   ! routine called by sbc_ice_lim(_2).F90
+   PUBLIC   sbc_cpl_alloc     ! routine called in sbcice_cice.F90
+
+   INTEGER, PARAMETER ::   jpr_otx1   =  1   ! 3 atmosphere-ocean stress components on grid 1
+   INTEGER, PARAMETER ::   jpr_oty1   =  2   ! 
+   INTEGER, PARAMETER ::   jpr_otz1   =  3   ! 
+   INTEGER, PARAMETER ::   jpr_otx2   =  4   ! 3 atmosphere-ocean stress components on grid 2
+   INTEGER, PARAMETER ::   jpr_oty2   =  5   ! 
+   INTEGER, PARAMETER ::   jpr_otz2   =  6   ! 
+   INTEGER, PARAMETER ::   jpr_itx1   =  7   ! 3 atmosphere-ice   stress components on grid 1
+   INTEGER, PARAMETER ::   jpr_ity1   =  8   ! 
+   INTEGER, PARAMETER ::   jpr_itz1   =  9   ! 
+   INTEGER, PARAMETER ::   jpr_itx2   = 10   ! 3 atmosphere-ice   stress components on grid 2
+   INTEGER, PARAMETER ::   jpr_ity2   = 11   ! 
+   INTEGER, PARAMETER ::   jpr_itz2   = 12   ! 
+   INTEGER, PARAMETER ::   jpr_qsroce = 13   ! Qsr above the ocean
+   INTEGER, PARAMETER ::   jpr_qsrice = 14   ! Qsr above the ice
    INTEGER, PARAMETER ::   jpr_qsrmix = 15 
-   INTEGER, PARAMETER ::   jpr_qnsoce = 16            ! Qns above the ocean
-   INTEGER, PARAMETER ::   jpr_qnsice = 17            ! Qns above the ice
+   INTEGER, PARAMETER ::   jpr_qnsoce = 16   ! Qns above the ocean
+   INTEGER, PARAMETER ::   jpr_qnsice = 17   ! Qns above the ice
    INTEGER, PARAMETER ::   jpr_qnsmix = 18
-   INTEGER, PARAMETER ::   jpr_rain   = 19            ! total liquid precipitation (rain)
-   INTEGER, PARAMETER ::   jpr_snow   = 20            ! solid precipitation over the ocean (snow)
-   INTEGER, PARAMETER ::   jpr_tevp   = 21            ! total evaporation
-   INTEGER, PARAMETER ::   jpr_ievp   = 22            ! solid evaporation (sublimation)
-   INTEGER, PARAMETER ::   jpr_sbpr   = 23            ! sublimation - liquid precipitation - solid precipitation
-   INTEGER, PARAMETER ::   jpr_semp   = 24            ! solid freshwater budget (sublimation - snow)
-   INTEGER, PARAMETER ::   jpr_oemp   = 25            ! ocean freshwater budget (evap - precip)
-   INTEGER, PARAMETER ::   jpr_w10m   = 26            ! 10m wind
-   INTEGER, PARAMETER ::   jpr_dqnsdt = 27            ! d(Q non solar)/d(temperature)
-   INTEGER, PARAMETER ::   jpr_rnf    = 28            ! runoffs
-   INTEGER, PARAMETER ::   jpr_cal    = 29            ! calving
-   INTEGER, PARAMETER ::   jpr_taum   = 30            ! wind stress module
+   INTEGER, PARAMETER ::   jpr_rain   = 19   ! total liquid precipitation (rain)
+   INTEGER, PARAMETER ::   jpr_snow   = 20   ! solid precipitation over the ocean (snow)
+   INTEGER, PARAMETER ::   jpr_tevp   = 21   ! total evaporation
+   INTEGER, PARAMETER ::   jpr_ievp   = 22   ! solid evaporation (sublimation)
+   INTEGER, PARAMETER ::   jpr_sbpr   = 23   ! sublimation - liquid precipitation - solid precipitation
+   INTEGER, PARAMETER ::   jpr_semp   = 24   ! solid freshwater budget (sublimation - snow)
+   INTEGER, PARAMETER ::   jpr_oemp   = 25   ! ocean freshwater budget (evap - precip)
+   INTEGER, PARAMETER ::   jpr_w10m   = 26   ! 10m wind
+   INTEGER, PARAMETER ::   jpr_dqnsdt = 27   ! d(Q non solar)/d(temperature)
+   INTEGER, PARAMETER ::   jpr_rnf    = 28   ! runoffs
+   INTEGER, PARAMETER ::   jpr_cal    = 29   ! calving
+   INTEGER, PARAMETER ::   jpr_taum   = 30   ! wind stress module
    INTEGER, PARAMETER ::   jpr_co2    = 31
-   INTEGER, PARAMETER ::   jpr_topm   = 32            ! topmeltn
-   INTEGER, PARAMETER ::   jpr_botm   = 33            ! botmeltn
-   INTEGER, PARAMETER ::   jpr_sflx   = 34            ! salt flux
-   INTEGER, PARAMETER ::   jpr_toce   = 35            ! ocean temperature
-   INTEGER, PARAMETER ::   jpr_soce   = 36            ! ocean salinity
-   INTEGER, PARAMETER ::   jpr_ocx1   = 37            ! ocean current on grid 1
-   INTEGER, PARAMETER ::   jpr_ocy1   = 38            !
-   INTEGER, PARAMETER ::   jpr_ssh    = 39            ! sea surface height
-   INTEGER, PARAMETER ::   jpr_fice   = 40            ! ice fraction          
-   INTEGER, PARAMETER ::   jpr_e3t1st = 41            ! first T level thickness 
-   INTEGER, PARAMETER ::   jpr_fraqsr = 42            ! fraction of solar net radiation absorbed in the first ocean level
-   INTEGER, PARAMETER ::   jprcv      = 42            ! total number of fields received
-
-   INTEGER, PARAMETER ::   jps_fice   =  1            ! ice fraction sent to the atmosphere
-   INTEGER, PARAMETER ::   jps_toce   =  2            ! ocean temperature
-   INTEGER, PARAMETER ::   jps_tice   =  3            ! ice   temperature
-   INTEGER, PARAMETER ::   jps_tmix   =  4            ! mixed temperature (ocean+ice)
-   INTEGER, PARAMETER ::   jps_albice =  5            ! ice   albedo
-   INTEGER, PARAMETER ::   jps_albmix =  6            ! mixed albedo
-   INTEGER, PARAMETER ::   jps_hice   =  7            ! ice  thickness
-   INTEGER, PARAMETER ::   jps_hsnw   =  8            ! snow thickness
-   INTEGER, PARAMETER ::   jps_ocx1   =  9            ! ocean current on grid 1
-   INTEGER, PARAMETER ::   jps_ocy1   = 10            !
-   INTEGER, PARAMETER ::   jps_ocz1   = 11            !
-   INTEGER, PARAMETER ::   jps_ivx1   = 12            ! ice   current on grid 1
-   INTEGER, PARAMETER ::   jps_ivy1   = 13            !
-   INTEGER, PARAMETER ::   jps_ivz1   = 14            !
+   INTEGER, PARAMETER ::   jpr_topm   = 32   ! topmeltn
+   INTEGER, PARAMETER ::   jpr_botm   = 33   ! botmeltn
+   INTEGER, PARAMETER ::   jpr_sflx   = 34   ! salt flux
+   INTEGER, PARAMETER ::   jpr_toce   = 35   ! ocean temperature
+   INTEGER, PARAMETER ::   jpr_soce   = 36   ! ocean salinity
+   INTEGER, PARAMETER ::   jpr_ocx1   = 37   ! ocean current on grid 1
+   INTEGER, PARAMETER ::   jpr_ocy1   = 38   !
+   INTEGER, PARAMETER ::   jpr_ssh    = 39   ! sea surface height
+   INTEGER, PARAMETER ::   jpr_fice   = 40   ! ice fraction          
+   INTEGER, PARAMETER ::   jpr_e3t1st = 41   ! first T level thickness 
+   INTEGER, PARAMETER ::   jpr_fraqsr = 42   ! fraction of solar net radiation absorbed in the first ocean level
+   INTEGER, PARAMETER ::   jprcv      = 42   ! total number of fields received
+
+   INTEGER, PARAMETER ::   jps_fice   =  1   ! ice fraction sent to the atmosphere
+   INTEGER, PARAMETER ::   jps_toce   =  2   ! ocean temperature
+   INTEGER, PARAMETER ::   jps_tice   =  3   ! ice   temperature
+   INTEGER, PARAMETER ::   jps_tmix   =  4   ! mixed temperature (ocean+ice)
+   INTEGER, PARAMETER ::   jps_albice =  5   ! ice   albedo
+   INTEGER, PARAMETER ::   jps_albmix =  6   ! mixed albedo
+   INTEGER, PARAMETER ::   jps_hice   =  7   ! ice  thickness
+   INTEGER, PARAMETER ::   jps_hsnw   =  8   ! snow thickness
+   INTEGER, PARAMETER ::   jps_ocx1   =  9   ! ocean current on grid 1
+   INTEGER, PARAMETER ::   jps_ocy1   = 10   !
+   INTEGER, PARAMETER ::   jps_ocz1   = 11   !
+   INTEGER, PARAMETER ::   jps_ivx1   = 12   ! ice   current on grid 1
+   INTEGER, PARAMETER ::   jps_ivy1   = 13   !
+   INTEGER, PARAMETER ::   jps_ivz1   = 14   !
    INTEGER, PARAMETER ::   jps_co2    = 15
-   INTEGER, PARAMETER ::   jps_soce   = 16            ! ocean salinity
-   INTEGER, PARAMETER ::   jps_ssh    = 17            ! sea surface height
-   INTEGER, PARAMETER ::   jps_qsroce = 18            ! Qsr above the ocean
-   INTEGER, PARAMETER ::   jps_qnsoce = 19            ! Qns above the ocean
-   INTEGER, PARAMETER ::   jps_oemp   = 20            ! ocean freshwater budget (evap - precip)
-   INTEGER, PARAMETER ::   jps_sflx   = 21            ! salt flux
-   INTEGER, PARAMETER ::   jps_otx1   = 22            ! 2 atmosphere-ocean stress components on grid 1
-   INTEGER, PARAMETER ::   jps_oty1   = 23            ! 
-   INTEGER, PARAMETER ::   jps_rnf    = 24            ! runoffs
-   INTEGER, PARAMETER ::   jps_taum   = 25            ! wind stress module
-   INTEGER, PARAMETER ::   jps_fice2  = 26            ! ice fraction sent to OPA (by SAS when doing SAS-OPA coupling)
-   INTEGER, PARAMETER ::   jps_e3t1st = 27            ! first level depth (vvl)
-   INTEGER, PARAMETER ::   jps_fraqsr = 28            ! fraction of solar net radiation absorbed in the first ocean level
-   INTEGER, PARAMETER ::   jpsnd      = 28            ! total number of fields sended
-
-   !                                                         !!** namelist namsbc_cpl **
-   TYPE ::   FLD_C
-      CHARACTER(len = 32) ::   cldes                  ! desciption of the coupling strategy
-      CHARACTER(len = 32) ::   clcat                  ! multiple ice categories strategy
-      CHARACTER(len = 32) ::   clvref                 ! reference of vector ('spherical' or 'cartesian')
-      CHARACTER(len = 32) ::   clvor                  ! orientation of vector fields ('eastward-northward' or 'local grid')
-      CHARACTER(len = 32) ::   clvgrd                 ! grids on which is located the vector fields
+   INTEGER, PARAMETER ::   jps_soce   = 16   ! ocean salinity
+   INTEGER, PARAMETER ::   jps_ssh    = 17   ! sea surface height
+   INTEGER, PARAMETER ::   jps_qsroce = 18   ! Qsr above the ocean
+   INTEGER, PARAMETER ::   jps_qnsoce = 19   ! Qns above the ocean
+   INTEGER, PARAMETER ::   jps_oemp   = 20   ! ocean freshwater budget (evap - precip)
+   INTEGER, PARAMETER ::   jps_sflx   = 21   ! salt flux
+   INTEGER, PARAMETER ::   jps_otx1   = 22   ! 2 atmosphere-ocean stress components on grid 1
+   INTEGER, PARAMETER ::   jps_oty1   = 23   ! 
+   INTEGER, PARAMETER ::   jps_rnf    = 24   ! runoffs
+   INTEGER, PARAMETER ::   jps_taum   = 25   ! wind stress module
+   INTEGER, PARAMETER ::   jps_fice2  = 26   ! ice fraction sent to OPA (by SAS when doing SAS-OPA coupling)
+   INTEGER, PARAMETER ::   jps_e3t1st = 27   ! first level depth (vvl)
+   INTEGER, PARAMETER ::   jps_fraqsr = 28   ! fraction of solar net radiation absorbed in the first ocean level
+   INTEGER, PARAMETER ::   jpsnd      = 28   ! total number of fields sended
+
+   !                                  !!** namelist namsbc_cpl **
+   TYPE ::   FLD_C                     !   
+      CHARACTER(len = 32) ::   cldes      ! desciption of the coupling strategy
+      CHARACTER(len = 32) ::   clcat      ! multiple ice categories strategy
+      CHARACTER(len = 32) ::   clvref     ! reference of vector ('spherical' or 'cartesian')
+      CHARACTER(len = 32) ::   clvor      ! orientation of vector fields ('eastward-northward' or 'local grid')
+      CHARACTER(len = 32) ::   clvgrd     ! grids on which is located the vector fields
    END TYPE FLD_C
-   ! Send to the atmosphere                           !
+   !                                   ! Send to the atmosphere  
    TYPE(FLD_C) ::   sn_snd_temp, sn_snd_alb, sn_snd_thick, sn_snd_crt, sn_snd_co2                        
-   ! Received from the atmosphere                     !
+   !                                   ! Received from the atmosphere
    TYPE(FLD_C) ::   sn_rcv_w10m, sn_rcv_taumod, sn_rcv_tau, sn_rcv_dqnsdt, sn_rcv_qsr, sn_rcv_qns, sn_rcv_emp, sn_rcv_rnf
    TYPE(FLD_C) ::   sn_rcv_cal, sn_rcv_iceflx, sn_rcv_co2                        
-   ! Other namelist parameters                        !
-   INTEGER     ::   nn_cplmodel            ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
-   LOGICAL     ::   ln_usecplmask          !  use a coupling mask file to merge data received from several models
-                                           !   -> file cplmask.nc with the float variable called cplmask (jpi,jpj,nn_cplmodel)
+   !                                   ! Other namelist parameters
+   INTEGER     ::   nn_cplmodel           ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
+   LOGICAL     ::   ln_usecplmask         !  use a coupling mask file to merge data received from several models
+                                         !   -> file cplmask.nc with the float variable called cplmask (jpi,jpj,nn_cplmodel)
    TYPE ::   DYNARR     
       REAL(wp), POINTER, DIMENSION(:,:,:)    ::   z3   
    END TYPE DYNARR
 
-   TYPE( DYNARR ), SAVE, DIMENSION(jprcv) ::   frcv                      ! all fields recieved from the atmosphere
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   albedo_oce_mix     ! ocean albedo sent to atmosphere (mix clear/overcast sky)
-
-   INTEGER , ALLOCATABLE, SAVE, DIMENSION(    :) ::   nrcvinfo           ! OASIS info argument
+   TYPE( DYNARR ), SAVE, DIMENSION(jprcv) ::   frcv                     ! all fields recieved from the atmosphere
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   albedo_oce_mix    ! ocean albedo sent to atmosphere (mix clear/overcast sky)
+
+   INTEGER , ALLOCATABLE, SAVE, DIMENSION(    :) ::   nrcvinfo          ! OASIS info argument
 
    !! Substitution
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
   
@@ -209,9 +208,8 @@
       !!              * initialise the OASIS coupler
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   k_ice       ! ice management in the sbc (=0/1/2/3)
-      !!
-      INTEGER ::   jn   ! dummy loop index
-      INTEGER ::   ios  ! Local integer output status for namelist read
-      INTEGER ::   inum 
+      INTEGER, INTENT(in) ::   k_ice   ! ice management in the sbc (=0/1/2/3)
+      !
+      INTEGER ::   jn          ! dummy loop index
+      INTEGER ::   ios, inum   ! Local integer
       REAL(wp), POINTER, DIMENSION(:,:) ::   zacs, zaos
       !!
@@ -222,21 +220,21 @@
       !!---------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('sbc_cpl_init')
-      !
-      CALL wrk_alloc( jpi,jpj, zacs, zaos )
+      IF( nn_timing == 1 )   CALL timing_start('sbc_cpl_init')
+      !
+      CALL wrk_alloc( jpi,jpj,   zacs, zaos )
 
       ! ================================ !
       !      Namelist informations       !
       ! ================================ !
-
+      !
       REWIND( numnam_ref )              ! Namelist namsbc_cpl in reference namelist : Variables for OASIS coupling
       READ  ( numnam_ref, namsbc_cpl, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_cpl in reference namelist', lwp )
-
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_cpl in reference namelist', lwp )
+      !
       REWIND( numnam_cfg )              ! Namelist namsbc_cpl in configuration namelist : Variables for OASIS coupling
       READ  ( numnam_cfg, namsbc_cpl, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_cpl in configuration namelist', lwp )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_cpl in configuration namelist', lwp )
       IF(lwm) WRITE ( numond, namsbc_cpl )
-
+      !
       IF(lwp) THEN                        ! control print
          WRITE(numout,*)
@@ -374,5 +372,5 @@
          srcv(jpr_ity1)%clgrid = 'V'                  ! i.e. it is always at U- & V-points for i- & j-comp. resp.
       ENDIF
-       
+      !
       !                                                      ! ------------------------- !
       !                                                      !    freshwater budget      !   E-P
@@ -396,5 +394,5 @@
       CASE default              ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_rcv_emp%cldes' )
       END SELECT
-
+      !
       !                                                      ! ------------------------- !
       !                                                      !     Runoffs & Calving     !   
@@ -410,5 +408,5 @@
       !
       srcv(jpr_cal   )%clname = 'OCalving'   ;   IF( TRIM( sn_rcv_cal%cldes ) == 'coupled' )   srcv(jpr_cal)%laction = .TRUE.
-
+      !
       !                                                      ! ------------------------- !
       !                                                      !    non solar radiation    !   Qns
@@ -535,5 +533,5 @@
          IF( .NOT. ln_cpl ) srcv(:)%nsgn    = 1.        ! force default definition in case of opa <-> sas coupling
          srcv( (/jpr_toce, jpr_soce, jpr_ssh, jpr_fraqsr, jpr_ocx1, jpr_ocy1/) )%laction = .TRUE.
-         srcv( jpr_e3t1st )%laction = lk_vvl
+         srcv( jpr_e3t1st )%laction = .NOT.ln_linssh
          srcv(jpr_ocx1)%clgrid = 'U'        ! oce components given at U-point
          srcv(jpr_ocy1)%clgrid = 'V'        !           and           V-point
@@ -701,5 +699,5 @@
          ssnd(:)%laction = .FALSE.   ! force default definition in case of opa <-> sas coupling
          ssnd( (/jps_toce, jps_soce, jps_ssh, jps_fraqsr, jps_ocx1, jps_ocy1/) )%laction = .TRUE.
-         ssnd( jps_e3t1st )%laction = lk_vvl
+         ssnd( jps_e3t1st )%laction = .NOT.ln_linssh
          ! vector definition: not used but cleaner...
          ssnd(jps_ocx1)%clgrid  = 'U'        ! oce components given at U-point
@@ -785,7 +783,7 @@
       ncpl_qsr_freq = 86400 / ncpl_qsr_freq
 
-      CALL wrk_dealloc( jpi,jpj, zacs, zaos )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('sbc_cpl_init')
+      CALL wrk_dealloc( jpi,jpj,   zacs, zaos )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('sbc_cpl_init')
       !
    END SUBROUTINE sbc_cpl_init
@@ -837,12 +835,12 @@
       !!                        emp          upward mass flux [evap. - precip. (- runoffs) (- calving)] (ocean only case)
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in)           ::   kt          ! ocean model time step index
-      INTEGER, INTENT(in)           ::   k_fsbc      ! frequency of sbc (-> ice model) computation 
-      INTEGER, INTENT(in)           ::   k_ice       ! ice management in the sbc (=0/1/2/3)
+      INTEGER, INTENT(in) ::   kt       ! ocean model time step index
+      INTEGER, INTENT(in) ::   k_fsbc   ! frequency of sbc (-> ice model) computation 
+      INTEGER, INTENT(in) ::   k_ice    ! ice management in the sbc (=0/1/2/3)
 
       !!
       LOGICAL  ::   llnewtx, llnewtau      ! update wind stress components and module??
       INTEGER  ::   ji, jj, jn             ! dummy loop indices
-      INTEGER  ::   isec                   ! number of seconds since nit000 (assuming rdttra did not change since nit000)
+      INTEGER  ::   isec                   ! number of seconds since nit000 (assuming rdt did not change since nit000)
       REAL(wp) ::   zcumulneg, zcumulpos   ! temporary scalars     
       REAL(wp) ::   zcoef                  ! temporary scalar
@@ -853,7 +851,7 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('sbc_cpl_rcv')
-      !
-      CALL wrk_alloc( jpi,jpj, ztx, zty, zmsk, zemp, zqns, zqsr )
+      IF( nn_timing == 1 )   CALL timing_start('sbc_cpl_rcv')
+      !
+      CALL wrk_alloc( jpi,jpj,   ztx, zty, zmsk, zemp, zqns, zqsr )
       !
       IF( ln_mixcpl )   zmsk(:,:) = 1. - xcplmask(:,:,0)
@@ -862,5 +860,5 @@
       !                                                      ! Receive all the atmos. fields (including ice information)
       !                                                      ! ======================================================= !
-      isec = ( kt - nit000 ) * NINT( rdttra(1) )                ! date of exchanges
+      isec = ( kt - nit000 ) * NINT( rdt )                      ! date of exchanges
       DO jn = 1, jprcv                                          ! received fields sent by the atmosphere
          IF( srcv(jn)%laction )   CALL cpl_rcv( jn, isec, frcv(jn)%z3, xcplmask(:,:,1:nn_cplmodel), nrcvinfo(jn) )
@@ -1104,10 +1102,9 @@
          IF( srcv(jpr_fice )%laction )   fr_i(:,:) = frcv(jpr_fice )%z3(:,:,1)
          !
-
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi,jpj, ztx, zty, zmsk, zemp, zqns, zqsr )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('sbc_cpl_rcv')
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi,jpj,   ztx, zty, zmsk, zemp, zqns, zqsr )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('sbc_cpl_rcv')
       !
    END SUBROUTINE sbc_cpl_rcv
@@ -1150,12 +1147,12 @@
       REAL(wp), INTENT(out), DIMENSION(:,:) ::   p_tauj   ! at I-point (B-grid) or U & V-point (C-grid)
       !!
-      INTEGER ::   ji, jj                          ! dummy loop indices
-      INTEGER ::   itx                             ! index of taux over ice
+      INTEGER ::   ji, jj   ! dummy loop indices
+      INTEGER ::   itx      ! index of taux over ice
       REAL(wp), POINTER, DIMENSION(:,:) ::   ztx, zty 
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('sbc_cpl_ice_tau')
-      !
-      CALL wrk_alloc( jpi,jpj, ztx, zty )
+      IF( nn_timing == 1 )   CALL timing_start('sbc_cpl_ice_tau')
+      !
+      CALL wrk_alloc( jpi,jpj,   ztx, zty )
 
       IF( srcv(jpr_itx1)%laction ) THEN   ;   itx =  jpr_itx1   
@@ -1165,5 +1162,4 @@
       ! do something only if we just received the stress from atmosphere
       IF(  nrcvinfo(itx) == OASIS_Rcv ) THEN
-
          !                                                      ! ======================= !
          IF( srcv(jpr_itx1)%laction ) THEN                      !   ice stress received   !
@@ -1318,7 +1314,7 @@
       ENDIF
       !   
-      CALL wrk_dealloc( jpi,jpj, ztx, zty )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('sbc_cpl_ice_tau')
+      CALL wrk_dealloc( jpi,jpj,   ztx, zty )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('sbc_cpl_ice_tau')
       !
    END SUBROUTINE sbc_cpl_ice_tau
@@ -1365,11 +1361,11 @@
       !!                   sprecip             solid precipitation over the ocean  
       !!----------------------------------------------------------------------
-      REAL(wp), INTENT(in   ), DIMENSION(:,:)   ::   p_frld     ! lead fraction                [0 to 1]
+      REAL(wp), INTENT(in   ), DIMENSION(:,:)             ::   p_frld  ! lead fraction            [0 to 1]
       ! optional arguments, used only in 'mixed oce-ice' case
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:), OPTIONAL ::   palbi      ! all skies ice albedo 
-      REAL(wp), INTENT(in   ), DIMENSION(:,:  ), OPTIONAL ::   psst       ! sea surface temperature     [Celsius]
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:), OPTIONAL ::   pist       ! ice surface temperature     [Kelvin]
-      !
-      INTEGER ::   jl         ! dummy loop index
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:), OPTIONAL ::   palbi   ! all skies ice albedo 
+      REAL(wp), INTENT(in   ), DIMENSION(:,:  ), OPTIONAL ::   psst    ! sea surface temperature  [Celsius]
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:), OPTIONAL ::   pist    ! ice surface temperature  [Kelvin]
+      !
+      INTEGER ::   jl   ! dummy loop index
       REAL(wp), POINTER, DIMENSION(:,:  ) ::   zcptn, ztmp, zicefr, zmsk
       REAL(wp), POINTER, DIMENSION(:,:  ) ::   zemp_tot, zemp_ice, zsprecip, ztprecip, zqns_tot, zqsr_tot
@@ -1378,8 +1374,8 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('sbc_cpl_ice_flx')
-      !
-      CALL wrk_alloc( jpi,jpj,     zcptn, ztmp, zicefr, zmsk, zemp_tot, zemp_ice, zsprecip, ztprecip, zqns_tot, zqsr_tot )
-      CALL wrk_alloc( jpi,jpj,jpl, zqns_ice, zqsr_ice, zdqns_ice )
+      IF( nn_timing == 1 )   CALL timing_start('sbc_cpl_ice_flx')
+      !
+      CALL wrk_alloc( jpi,jpj,       zcptn, ztmp, zicefr, zmsk, zemp_tot, zemp_ice, zsprecip, ztprecip, zqns_tot, zqsr_tot )
+      CALL wrk_alloc( jpi,jpj,jpl,   zqns_ice, zqsr_ice, zdqns_ice )
 
       IF( ln_mixcpl )   zmsk(:,:) = 1. - xcplmask(:,:,0)
@@ -1554,6 +1550,6 @@
       CALL wrk_dealloc( jpi,jpj, zevap, zsnw, zqns_oce, zqprec_ice, zqemp_oce ) 
 #else
-
-      ! clem: this formulation is certainly wrong... but better than it was...
+      !
+      ! clem: this formulation is certainly wrong... but better than it was before...
       zqns_tot(:,:) = zqns_tot(:,:)                       &            ! zqns_tot update over free ocean with:
          &          - ztmp(:,:)                           &            ! remove the latent heat flux of solid precip. melting
@@ -1571,7 +1567,6 @@
          qns_ice(:,:,:) = zqns_ice(:,:,:)
       ENDIF
-
+      !
 #endif
-
       !                                                      ! ========================= !
       SELECT CASE( TRIM( sn_rcv_qsr%cldes ) )                !      solar heat fluxes    !   (qsr)
@@ -1682,8 +1677,8 @@
       fr2_i0(:,:) = ( 0.82 * ( 1.0 - cldf_ice ) + 0.65 * cldf_ice )
 
-      CALL wrk_dealloc( jpi,jpj,     zcptn, ztmp, zicefr, zmsk, zemp_tot, zemp_ice, zsprecip, ztprecip, zqns_tot, zqsr_tot )
-      CALL wrk_dealloc( jpi,jpj,jpl, zqns_ice, zqsr_ice, zdqns_ice )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('sbc_cpl_ice_flx')
+      CALL wrk_dealloc( jpi,jpj,       zcptn, ztmp, zicefr, zmsk, zemp_tot, zemp_ice, zsprecip, ztprecip, zqns_tot, zqsr_tot )
+      CALL wrk_dealloc( jpi,jpj,jpl,   zqns_ice, zqsr_ice, zdqns_ice )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('sbc_cpl_ice_flx')
       !
    END SUBROUTINE sbc_cpl_ice_flx
@@ -1708,10 +1703,10 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('sbc_cpl_snd')
-      !
-      CALL wrk_alloc( jpi,jpj, zfr_l, ztmp1, ztmp2, zotx1, zoty1, zotz1, zitx1, zity1, zitz1 )
-      CALL wrk_alloc( jpi,jpj,jpl, ztmp3, ztmp4 )
-
-      isec = ( kt - nit000 ) * NINT(rdttra(1))        ! date of exchanges
+      IF( nn_timing == 1 )   CALL timing_start('sbc_cpl_snd')
+      !
+      CALL wrk_alloc( jpi,jpj,       zfr_l, ztmp1, ztmp2, zotx1, zoty1, zotz1, zitx1, zity1, zitz1 )
+      CALL wrk_alloc( jpi,jpj,jpl,   ztmp3, ztmp4 )
+
+      isec = ( kt - nit000 ) * NINT( rdt )        ! date of exchanges
 
       zfr_l(:,:) = 1.- fr_i(:,:)
@@ -2031,5 +2026,5 @@
       !                                                        ! first T level thickness 
       IF( ssnd(jps_e3t1st )%laction )  THEN
-         CALL cpl_snd( jps_e3t1st, isec, RESHAPE ( fse3t_n(:,:,1)   , (/jpi,jpj,1/) ), info )
+         CALL cpl_snd( jps_e3t1st, isec, RESHAPE ( e3t_n(:,:,1)   , (/jpi,jpj,1/) ), info )
       ENDIF
       !                                                        ! Qsr fraction
@@ -2049,8 +2044,8 @@
       IF( ssnd(jps_taum  )%laction )  CALL cpl_snd( jps_taum  , isec, RESHAPE ( taum, (/jpi,jpj,1/) ), info )
 
-      CALL wrk_dealloc( jpi,jpj, zfr_l, ztmp1, ztmp2, zotx1, zoty1, zotz1, zitx1, zity1, zitz1 )
-      CALL wrk_dealloc( jpi,jpj,jpl, ztmp3, ztmp4 )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('sbc_cpl_snd')
+      CALL wrk_dealloc( jpi,jpj,       zfr_l, ztmp1, ztmp2, zotx1, zoty1, zotz1, zitx1, zity1, zitz1 )
+      CALL wrk_dealloc( jpi,jpj,jpl,   ztmp3, ztmp4 )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('sbc_cpl_snd')
       !
    END SUBROUTINE sbc_cpl_snd
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcdcy.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcdcy.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcdcy.F90	(revision 6140)
@@ -90,6 +90,6 @@
 
       ! When are we during the day (from 0 to 1)
-      zlo = ( REAL(nsec_day, wp) - 0.5_wp * rdttra(1) ) / rday
-      zup = zlo + ( REAL(nn_fsbc, wp)     * rdttra(1) ) / rday
+      zlo = ( REAL(nsec_day, wp) - 0.5_wp * rdt ) / rday
+      zup = zlo + ( REAL(nn_fsbc, wp)     * rdt ) / rday
       !                                          
       IF( nday_qsr == -1 ) THEN       ! first time step only  
@@ -189,5 +189,5 @@
          END DO  
          !
-         ztmp = rday / ( rdttra(1) * REAL(nn_fsbc, wp) )
+         ztmp = rday / ( rdt * REAL(nn_fsbc, wp) )
          rscal(:,:) = rscal(:,:) * ztmp
          !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcflx.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcflx.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcflx.F90	(revision 6140)
@@ -17,4 +17,5 @@
    USE sbcdcy          ! surface boundary condition: diurnal cycle on qsr
    USE phycst          ! physical constants
+   !
    USE fldread         ! read input fields
    USE iom             ! IOM library
@@ -37,5 +38,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -165,7 +165,5 @@
                WRITE(numout,*) 
                WRITE(numout,*) ' day: ', ndastp , TRIM(sf(jf)%clvar), ' * ', zfact
-               CALL prihre( sf(jf)%fnow, jpi, jpj, 1, jpi, 20, 1, jpj, 10, zfact, numout )
             END DO
-            CALL FLUSH(numout)
          ENDIF
          !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90	(revision 6140)
@@ -12,20 +12,20 @@
 
    !!----------------------------------------------------------------------
-   !!   sbc_fwb      : freshwater budget for global ocean configurations
-   !!                  in free surface and forced mode
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! surface ocean boundary condition
-   USE phycst          ! physical constants
-   USE sbcrnf          ! ocean runoffs
-   USE sbcisf          ! ice shelf melting contribution
-   USE sbcssr          ! SS damping terms
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! distribued memory computing library
-   USE wrk_nemo        ! work arrays
-   USE timing          ! Timing
-   USE lbclnk          ! ocean lateral boundary conditions
-   USE lib_fortran
+   !!   sbc_fwb       : freshwater budget for global ocean configurations (free surface & forced mode)
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE sbc_oce        ! surface ocean boundary condition
+   USE phycst         ! physical constants
+   USE sbcrnf         ! ocean runoffs
+   USE sbcisf         ! ice shelf melting contribution
+   USE sbcssr         ! Sea-Surface damping terms
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! distribued memory computing library
+   USE wrk_nemo       ! work arrays
+   USE timing         ! Timing
+   USE lbclnk         ! ocean lateral boundary conditions
+   USE lib_fortran    ! 
 
    IMPLICIT NONE
@@ -40,5 +40,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -129,5 +128,5 @@
          ENDIF   
          !                                         ! Update fwfold if new year start
-         ikty = 365 * 86400 / rdttra(1)    !!bug  use of 365 days leap year or 360d year !!!!!!!
+         ikty = 365 * 86400 / rdt                  !!bug  use of 365 days leap year or 360d year !!!!!!!
          IF( MOD( kt, ikty ) == 0 ) THEN
             a_fwb_b = a_fwb                           ! mean sea level taking into account the ice+snow
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90	(revision 6140)
@@ -9,6 +9,4 @@
    !!----------------------------------------------------------------------
    !!   sbc_ice_cice  : sea-ice model time-stepping and update ocean sbc over ice-covered area
-   !!   
-   !!   
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers
@@ -92,6 +90,4 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:), PRIVATE ::   png     ! local array used in sbc_cice_ice
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.7 , NEMO-consortium (2015) 
@@ -244,46 +240,48 @@
          snwice_mass_b(:,:) = 0.0_wp         ! no mass exchanges
       ENDIF
-      IF( .NOT. ln_rstart ) THEN
+      IF( .NOT.ln_rstart ) THEN
          IF( nn_ice_embd == 2 ) THEN            ! full embedment (case 2) deplete the initial ssh below sea-ice area
             sshn(:,:) = sshn(:,:) - snwice_mass(:,:) * r1_rau0
             sshb(:,:) = sshb(:,:) - snwice_mass(:,:) * r1_rau0
-#if defined key_vvl            
-           ! key_vvl necessary? clem: yes for compilation purpose
-            DO jk = 1,jpkm1                     ! adjust initial vertical scale factors
-               fse3t_n(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshn(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
-               fse3t_b(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshb(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
-            ENDDO
-            fse3t_a(:,:,:) = fse3t_b(:,:,:)
-            ! Reconstruction of all vertical scale factors at now and before time
-            ! steps
-            ! =============================================================================
-            ! Horizontal scale factor interpolations
-            ! --------------------------------------
-            CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3u_b(:,:,:), 'U' )
-            CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3v_b(:,:,:), 'V' )
-            CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3u_n(:,:,:), 'U' )
-            CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3v_n(:,:,:), 'V' )
-            CALL dom_vvl_interpol( fse3u_n(:,:,:), fse3f_n(:,:,:), 'F' )
-            ! Vertical scale factor interpolations
-            ! ------------------------------------
-            CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3w_n (:,:,:), 'W'  )
-            CALL dom_vvl_interpol( fse3u_n(:,:,:), fse3uw_n(:,:,:), 'UW' )
-            CALL dom_vvl_interpol( fse3v_n(:,:,:), fse3vw_n(:,:,:), 'VW' )
-            CALL dom_vvl_interpol( fse3u_b(:,:,:), fse3uw_b(:,:,:), 'UW' )
-            CALL dom_vvl_interpol( fse3v_b(:,:,:), fse3vw_b(:,:,:), 'VW' )
-            ! t- and w- points depth
-            ! ----------------------
-            fsdept_n(:,:,1) = 0.5_wp * fse3w_n(:,:,1)
-            fsdepw_n(:,:,1) = 0.0_wp
-            fsde3w_n(:,:,1) = fsdept_n(:,:,1) - sshn(:,:)
-            DO jk = 2, jpk
-               fsdept_n(:,:,jk) = fsdept_n(:,:,jk-1) + fse3w_n(:,:,jk)
-               fsdepw_n(:,:,jk) = fsdepw_n(:,:,jk-1) + fse3t_n(:,:,jk-1)
-               fsde3w_n(:,:,jk) = fsdept_n(:,:,jk  ) - sshn   (:,:)
-            END DO
-#endif
+
+!!gm This should be put elsewhere....   (same remark for limsbc)
+!!gm especially here it is assumed zstar coordinate, but it can be ztilde....
+            IF( .NOT.ln_linssh ) THEN
+               !
+               DO jk = 1,jpkm1                     ! adjust initial vertical scale factors
+                  e3t_n(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshn(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
+                  e3t_b(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshb(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
+               ENDDO
+               e3t_a(:,:,:) = e3t_b(:,:,:)
+               ! Reconstruction of all vertical scale factors at now and before time-steps
+               ! =============================================================================
+               ! Horizontal scale factor interpolations
+               ! --------------------------------------
+               CALL dom_vvl_interpol( e3t_b(:,:,:), e3u_b(:,:,:), 'U' )
+               CALL dom_vvl_interpol( e3t_b(:,:,:), e3v_b(:,:,:), 'V' )
+               CALL dom_vvl_interpol( e3t_n(:,:,:), e3u_n(:,:,:), 'U' )
+               CALL dom_vvl_interpol( e3t_n(:,:,:), e3v_n(:,:,:), 'V' )
+               CALL dom_vvl_interpol( e3u_n(:,:,:), e3f_n(:,:,:), 'F' )
+               ! Vertical scale factor interpolations
+               ! ------------------------------------
+               CALL dom_vvl_interpol( e3t_n(:,:,:), e3w_n (:,:,:), 'W'  )
+               CALL dom_vvl_interpol( e3u_n(:,:,:), e3uw_n(:,:,:), 'UW' )
+               CALL dom_vvl_interpol( e3v_n(:,:,:), e3vw_n(:,:,:), 'VW' )
+               CALL dom_vvl_interpol( e3u_b(:,:,:), e3uw_b(:,:,:), 'UW' )
+               CALL dom_vvl_interpol( e3v_b(:,:,:), e3vw_b(:,:,:), 'VW' )
+               ! t- and w- points depth
+               ! ----------------------
+               gdept_n(:,:,1) = 0.5_wp * e3w_n(:,:,1)
+               gdepw_n(:,:,1) = 0.0_wp
+               gde3w_n(:,:,1) = gdept_n(:,:,1) - sshn(:,:)
+               DO jk = 2, jpk
+                  gdept_n(:,:,jk) = gdept_n(:,:,jk-1) + e3w_n(:,:,jk)
+                  gdepw_n(:,:,jk) = gdepw_n(:,:,jk-1) + e3t_n(:,:,jk-1)
+                  gde3w_n(:,:,jk) = gdept_n(:,:,jk  ) - sshn   (:,:)
+               END DO
+            ENDIF
          ENDIF
       ENDIF
- 
+      !
       CALL wrk_dealloc( jpi,jpj, ztmp1, ztmp2 )
       !
@@ -448,5 +446,5 @@
 ! Freezing/melting potential
 ! Calculated over NEMO leapfrog timestep (hence 2*dt)
-      nfrzmlt(:,:)=rau0*rcp*fse3t_m(:,:)*(Tocnfrz-sst_m(:,:))/(2.0*dt)
+      nfrzmlt(:,:) = rau0 * rcp * e3t_m(:,:) * ( Tocnfrz-sst_m(:,:) ) / ( 2.0*dt )
 
       ztmp(:,:) = nfrzmlt(:,:)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_if.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_if.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_if.F90	(revision 6140)
@@ -34,6 +34,4 @@
    TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_ice   ! structure of input ice-cover (file informations, fields read)
    
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 6140)
@@ -25,5 +25,5 @@
    USE thd_ice         ! LIM-3: thermodynamical variables
    USE dom_ice         ! LIM-3: ice domain
-
+   !
    USE sbc_oce         ! Surface boundary condition: ocean fields
    USE sbc_ice         ! Surface boundary condition: ice   fields
@@ -32,5 +32,5 @@
    USE sbccpl          ! Surface boundary condition: coupled interface
    USE albedo          ! ocean & ice albedo
-
+   !
    USE phycst          ! Define parameters for the routines
    USE eosbn2          ! equation of state
@@ -47,19 +47,18 @@
    USE limupdate2      ! update of global variables
    USE limvar          ! Ice variables switch
-
+   USE limctl          ! 
    USE limmsh          ! LIM mesh
    USE limistate       ! LIM initial state
    USE limthd_sal      ! LIM ice thermodynamics: salinity
-
+   !
    USE c1d             ! 1D vertical configuration
+   USE in_out_manager  ! I/O manager
+   USE iom             ! I/O manager library
+   USE prtctl          ! Print control
+   USE lib_fortran     ! 
    USE lbclnk          ! lateral boundary condition - MPP link
    USE lib_mpp         ! MPP library
    USE wrk_nemo        ! work arrays
    USE timing          ! Timing
-   USE iom             ! I/O manager library
-   USE in_out_manager  ! I/O manager
-   USE prtctl          ! Print control
-   USE lib_fortran     ! 
-   USE limctl
 
 #if defined key_bdy 
@@ -74,5 +73,4 @@
    
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -82,6 +80,4 @@
    !!----------------------------------------------------------------------
 CONTAINS
-
-   !!======================================================================
 
    SUBROUTINE sbc_ice_lim( kt, kblk )
@@ -270,9 +266,9 @@
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   via Louvain la Neuve Ice Model (LIM-3) time stepping'
       !
-                                       ! Open the reference and configuration namelist files and namelist output file 
+      !                                ! Open the reference and configuration namelist files and namelist output file 
       CALL ctl_opn( numnam_ice_ref, 'namelist_ice_ref',    'OLD',     'FORMATTED', 'SEQUENTIAL', -1, numout, lwp ) 
       CALL ctl_opn( numnam_ice_cfg, 'namelist_ice_cfg',    'OLD',     'FORMATTED', 'SEQUENTIAL', -1, numout, lwp )
       IF(lwm) CALL ctl_opn( numoni, 'output.namelist.ice', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, 1 )
-
+      !
       CALL ice_run                     ! set some ice run parameters
       !
@@ -348,11 +344,10 @@
       REWIND( numnam_ice_ref )              ! Namelist namicerun in reference namelist : Parameters for ice
       READ  ( numnam_ice_ref, namicerun, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicerun in reference namelist', lwp )
-
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namicerun in reference namelist', lwp )
+      !
       REWIND( numnam_ice_cfg )              ! Namelist namicerun in configuration namelist : Parameters for ice
       READ  ( numnam_ice_cfg, namicerun, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicerun in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namicerun )
-      !
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namicerun in configuration namelist', lwp )
+      IF(lwm) WRITE( numoni, namicerun )
       !
       IF(lwp) THEN                        ! control print
@@ -373,5 +368,5 @@
       !
       ! sea-ice timestep and inverse
-      rdt_ice   = nn_fsbc * rdttra(1)  
+      rdt_ice   = nn_fsbc * rdt  
       r1_rdtice = 1._wp / rdt_ice 
 
@@ -405,11 +400,10 @@
       REWIND( numnam_ice_ref )              ! Namelist namiceitd in reference namelist : Parameters for ice
       READ  ( numnam_ice_ref, namiceitd, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceitd in reference namelist', lwp )
-
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namiceitd in reference namelist', lwp )
+      !
       REWIND( numnam_ice_cfg )              ! Namelist namiceitd in configuration namelist : Parameters for ice
       READ  ( numnam_ice_cfg, namiceitd, IOSTAT = ios, ERR = 904 )
-904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceitd in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namiceitd )
-      !
+904   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namiceitd in configuration namelist', lwp )
+      IF(lwm) WRITE( numoni, namiceitd )
       !
       IF(lwp) THEN                        ! control print
@@ -417,8 +411,8 @@
          WRITE(numout,*) 'ice_itd : ice cat distribution'
          WRITE(numout,*) ' ~~~~~~'
-         WRITE(numout,*) '   shape of ice categories distribution                          nn_catbnd = ', nn_catbnd
-         WRITE(numout,*) '   mean ice thickness in the domain (only active if nn_catbnd=2) rn_himean = ', rn_himean
+         WRITE(numout,*) '   shape of ice categories distribution                     nn_catbnd = ', nn_catbnd
+         WRITE(numout,*) '   mean ice thickness in the domain (used if nn_catbnd=2)   rn_himean = ', rn_himean
       ENDIF
-
+      !
       !----------------------------------
       !- Thickness categories boundaries 
@@ -427,42 +421,35 @@
       IF(lwp) WRITE(numout,*) 'lim_itd_init : Initialization of ice cat distribution '
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
-
+      !
       hi_max(:) = 0._wp
-
-      SELECT CASE ( nn_catbnd  )       
-                                   !----------------------
-         CASE (1)                  ! tanh function (CICE)
-                                   !----------------------
+      !
+      SELECT CASE ( nn_catbnd  )    ! type of ice categories distribution
+      !
+      CASE (1)                            !==  tanh function (CICE)  ==!
          zc1 =  3._wp / REAL( jpl, wp )
          zc2 = 10._wp * zc1
          zc3 =  3._wp
-
          DO jl = 1, jpl
             zx1 = REAL( jl-1, wp ) / REAL( jpl, wp )
             hi_max(jl) = hi_max(jl-1) + zc1 + zc2 * (1._wp + TANH( zc3 * (zx1 - 1._wp ) ) )
          END DO
-
-                                   !----------------------
-         CASE (2)                  ! h^(-alpha) function
-                                   !----------------------
-         zalpha = 0.05             ! exponent of the transform function
-
-         zhmax  = 3.*rn_himean
-
+         !
+      CASE (2)                            !==  h^(-alpha) function  ==!
+         zalpha = 0.05_wp
+         zhmax  = 3._wp * rn_himean
          DO jl = 1, jpl 
             znum = jpl * ( zhmax+1 )**zalpha
-            zden = ( jpl - jl ) * ( zhmax+1 )**zalpha + jl
+            zden = REAL( jpl-jl , wp ) * ( zhmax + 1._wp )**zalpha + REAL( jl , wp )
             hi_max(jl) = ( znum / zden )**(1./zalpha) - 1
          END DO
-
+         !
       END SELECT
-
-      DO jl = 1, jpl
+      !
+      DO jl = 1, jpl                ! mean thickness by category
          hi_mean(jl) = ( hi_max(jl) + hi_max(jl-1) ) * 0.5_wp
       END DO
-
-      ! Set hi_max(jpl) to a big value to ensure that all ice is thinner than hi_max(jpl)
-      hi_max(jpl) = 99._wp
-
+      !
+      hi_max(jpl) = 99._wp          ! set to a big value to ensure that all ice is thinner than hi_max(jpl)
+      !
       IF(lwp) WRITE(numout,*) ' Thickness category boundaries '
       IF(lwp) WRITE(numout,*) ' hi_max ', hi_max(0:jpl)
@@ -471,5 +458,6 @@
 
    
-   SUBROUTINE ice_lim_flx( ptn_ice, palb_ice, pqns_ice, pqsr_ice, pdqn_ice, pevap_ice, pdevap_ice, k_limflx )
+   SUBROUTINE ice_lim_flx( ptn_ice , palb_ice, pqns_ice ,    &
+      &                    pqsr_ice, pdqn_ice, pevap_ice, pdevap_ice, k_limflx )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE ice_lim_flx  ***
@@ -483,5 +471,5 @@
       !!---------------------------------------------------------------------
       INTEGER                   , INTENT(in   ) ::   k_limflx   ! =-1 do nothing; =0 average ; 
-                                                                ! =1 average and redistribute ; =2 redistribute
+      !                                                         ! =1 average and redistribute ; =2 redistribute
       REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   ptn_ice    ! ice surface temperature 
       REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   palb_ice   ! ice albedo
@@ -503,7 +491,6 @@
       REAL(wp), POINTER, DIMENSION(:,:) :: z_devap_m ! Mean d(evap)/dT over all categories
       !!----------------------------------------------------------------------
-
+      !
       IF( nn_timing == 1 )  CALL timing_start('ice_lim_flx')
-      !
       !
       SELECT CASE( k_limflx )                              !==  averaged on all ice categories  ==!
@@ -529,5 +516,5 @@
          CALL wrk_dealloc( jpi,jpj, z_qsr_m, z_qns_m, z_evap_m, z_dqn_m, z_devap_m)
       END SELECT
-
+      !
       SELECT CASE( k_limflx )                              !==  redistribution on all ice categories  ==!
       CASE( 1 , 2 )
@@ -548,4 +535,5 @@
       !
    END SUBROUTINE ice_lim_flx
+
 
    SUBROUTINE sbc_lim_bef
@@ -564,6 +552,7 @@
       u_ice_b(:,:)     = u_ice(:,:)
       v_ice_b(:,:)     = v_ice(:,:)
-      
+      !      
    END SUBROUTINE sbc_lim_bef
+
 
    SUBROUTINE sbc_lim_diag0
@@ -580,5 +569,5 @@
       sfx_bom(:,:) = 0._wp   ;   sfx_sum(:,:) = 0._wp
       sfx_res(:,:) = 0._wp
-      
+      !
       wfx_snw(:,:) = 0._wp   ;   wfx_ice(:,:) = 0._wp
       wfx_sni(:,:) = 0._wp   ;   wfx_opw(:,:) = 0._wp
@@ -587,5 +576,5 @@
       wfx_res(:,:) = 0._wp   ;   wfx_sub(:,:) = 0._wp
       wfx_spr(:,:) = 0._wp   ;   
-      
+      !
       hfx_thd(:,:) = 0._wp   ;   
       hfx_snw(:,:) = 0._wp   ;   hfx_opw(:,:) = 0._wp
@@ -596,11 +585,11 @@
       hfx_err(:,:) = 0._wp   ;   hfx_err_rem(:,:) = 0._wp
       hfx_err_dif(:,:) = 0._wp   ;
-
+      !
       afx_tot(:,:) = 0._wp   ;
       afx_dyn(:,:) = 0._wp   ;   afx_thd(:,:) = 0._wp
-
+      !
       diag_heat(:,:) = 0._wp ;   diag_smvi(:,:) = 0._wp ;
       diag_vice(:,:) = 0._wp ;   diag_vsnw(:,:) = 0._wp ;
-      
+      !
    END SUBROUTINE sbc_lim_diag0
 
@@ -634,5 +623,4 @@
    END FUNCTION fice_ice_ave
 
-
 #else
    !!----------------------------------------------------------------------
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90	(revision 6140)
@@ -64,5 +64,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90	(revision 6140)
@@ -35,39 +35,37 @@
    ! public in order to be able to output then 
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   risf_tsc_b, risf_tsc   
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   qisf              !: net heat flux from ice shelf
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   risf_tsc_b, risf_tsc  !: before and now T & S isf contents [K.m/s & PSU.m/s]  
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   qisf                  !: net heat flux from ice shelf      [W/m2]
    REAL(wp), PUBLIC ::   rn_hisf_tbl                 !: thickness of top boundary layer [m]
-   LOGICAL , PUBLIC ::   ln_divisf                   !: flag to correct divergence 
-   INTEGER , PUBLIC ::   nn_isfblk                   !: 
-   INTEGER , PUBLIC ::   nn_gammablk                 !:
-   LOGICAL , PUBLIC ::   ln_conserve                 !:
-   REAL(wp), PUBLIC ::   rn_gammat0                  !: temperature exchange coeficient
-   REAL(wp), PUBLIC ::   rn_gammas0                  !: salinity    exchange coeficient 
-   REAL(wp), PUBLIC ::   rdivisf                     !: flag to test if fwf apply on divergence
+   INTEGER , PUBLIC ::   nn_isf                      !: flag to choose between explicit/param/specified  
+   INTEGER , PUBLIC ::   nn_isfblk                   !: flag to choose the bulk formulation to compute the ice shelf melting
+   INTEGER , PUBLIC ::   nn_gammablk                 !: flag to choose how the exchange coefficient is computed
+   REAL(wp), PUBLIC ::   rn_gammat0                  !: temperature exchange coeficient []
+   REAL(wp), PUBLIC ::   rn_gammas0                  !: salinity    exchange coeficient []
 
    REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  rzisf_tbl              !:depth of calving front (shallowest point) nn_isf ==2/3
-   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  rhisf_tbl, rhisf_tbl_0 !:thickness of tbl
+   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  rhisf_tbl, rhisf_tbl_0 !:thickness of tbl  [m]
    REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  r1_hisf_tbl            !:1/thickness of tbl
    REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  ralpha                 !:proportion of bottom cell influenced by tbl 
    REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  risfLeff               !:effective length (Leff) BG03 nn_isf==2
    REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  ttbl, stbl, utbl, vtbl !:top boundary layer variable at T point
-   INTEGER,    PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  misfkt, misfkb         !:Level of ice shelf base
-
-   REAL(wp), PUBLIC, SAVE ::   rcpi   = 2000.0_wp     ! phycst ?
-   REAL(wp), PUBLIC, SAVE ::   kappa  = 1.54e-6_wp    ! phycst ?
-   REAL(wp), PUBLIC, SAVE ::   rhoisf = 920.0_wp      ! phycst ?
-   REAL(wp), PUBLIC, SAVE ::   tsurf  = -20.0_wp      ! phycst ?
-   REAL(wp), PUBLIC, SAVE ::   lfusisf= 0.334e6_wp    ! phycst ?
+   INTEGER,    PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)      ::  misfkt, misfkb         !:Level of ice shelf base
+
+   REAL(wp), PUBLIC, SAVE ::   rcpi     = 2000.0_wp     ! specific heat of ice shelf             [J/kg/K]
+   REAL(wp), PUBLIC, SAVE ::   rkappa   = 1.54e-6_wp    ! heat diffusivity through the ice-shelf [m2/s]
+   REAL(wp), PUBLIC, SAVE ::   rhoisf   = 920.0_wp      ! volumic mass of ice shelf              [kg/m3]
+   REAL(wp), PUBLIC, SAVE ::   tsurf    = -20.0_wp      ! air temperature on top of ice shelf    [C]
+   REAL(wp), PUBLIC, SAVE ::   rlfusisf = 0.334e6_wp    ! latent heat of fusion of ice shelf     [J/kg]
 
 !: Variable used in fldread to read the forcing file (nn_isf == 4 .OR. nn_isf == 3)
-   CHARACTER(len=100), PUBLIC ::   cn_dirisf  = './'    !: Root directory for location of ssr files
-   TYPE(FLD_N)       , PUBLIC ::   sn_qisf, sn_fwfisf     !: information about the runoff file to be read
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_qisf, sf_fwfisf
-   TYPE(FLD_N)       , PUBLIC ::   sn_rnfisf              !: information about the runoff file to be read
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_rnfisf           
-   TYPE(FLD_N)       , PUBLIC ::   sn_depmax_isf, sn_depmin_isf, sn_Leff_isf     !: information about the runoff file to be read
+   CHARACTER(len=100), PUBLIC           :: cn_dirisf  = './' !: Root directory for location of ssr files
+   TYPE(FLD_N)       , PUBLIC           :: sn_fwfisf         !: information about the isf melting file to be read
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:) :: sf_fwfisf
+   TYPE(FLD_N)       , PUBLIC           :: sn_rnfisf         !: information about the isf melting param.   file to be read
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:) :: sf_rnfisf           
+   TYPE(FLD_N)       , PUBLIC           :: sn_depmax_isf     !: information about the grounding line depth file to be read
+   TYPE(FLD_N)       , PUBLIC           :: sn_depmin_isf     !: information about the calving   line depth file to be read
+   TYPE(FLD_N)       , PUBLIC           :: sn_Leff_isf       !: information about the effective length     file to be read
    
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.7 , LOCEAN-IPSL (2015)
@@ -77,22 +75,21 @@
 CONTAINS
  
-   SUBROUTINE sbc_isf(kt)
+  SUBROUTINE sbc_isf(kt)
       !!---------------------------------------------------------------------
-      !!                     ***  ROUTINE sbc_isf  ***
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in)          ::   kt         ! ocean time step
-      !
-      INTEGER                      ::   ji, jj, jk, ijkmin, inum, ierror
-      INTEGER                      ::   ikt, ikb   ! top and bottom level of the isf boundary layer
-      REAL(wp)                     ::   rmin
-      REAL(wp)                     ::   zhk
-      REAL(wp)                     ::   zt_frz, zpress
-      CHARACTER(len=256)           ::   cfisf , cvarzisf, cvarhisf   ! name for isf file
-      CHARACTER(LEN=256)           :: cnameis                     ! name of iceshelf file
-      CHARACTER (LEN=32)           :: cvarLeff                    ! variable name for efficient Length scale
-      INTEGER           ::   ios           ! Local integer output status for namelist read
-      !!
-      NAMELIST/namsbc_isf/ nn_isfblk, rn_hisf_tbl, ln_divisf, ln_conserve, rn_gammat0, rn_gammas0, nn_gammablk, &
-         &                 sn_fwfisf, sn_qisf, sn_rnfisf, sn_depmax_isf, sn_depmin_isf, sn_Leff_isf
+      !!                  ***  ROUTINE sbc_isf  ***
+      !!
+      !! ** Purpose : Compute Salt and Heat fluxes related to ice_shelf 
+      !!              melting and freezing 
+      !!
+      !! ** Method  :  4 parameterizations are available according to nn_isf 
+      !!               nn_isf = 1 : Realistic ice_shelf formulation
+      !!                        2 : Beckmann & Goose parameterization
+      !!                        3 : Specified runoff in deptht (Mathiot & al. )
+      !!                        4 : specified fwf and heat flux forcing beneath the ice shelf
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) :: kt                   ! ocean time step
+      !
+      INTEGER               :: ji, jj               ! loop index
+      REAL(wp), DIMENSION (:,:), POINTER :: zt_frz, zdep ! freezing temperature (zt_frz) at depth (zdep) 
       !!---------------------------------------------------------------------
       !
@@ -100,189 +97,72 @@
       IF( kt == nit000 ) THEN                   !  First call kt=nit000  !
          !                                      ! ====================== !
-         REWIND( numnam_ref )              ! Namelist namsbc_rnf in reference namelist : Runoffs 
-         READ  ( numnam_ref, namsbc_isf, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_isf in reference namelist', lwp )
-
-         REWIND( numnam_cfg )              ! Namelist namsbc_rnf in configuration namelist : Runoffs
-         READ  ( numnam_cfg, namsbc_isf, IOSTAT = ios, ERR = 902 )
-902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_isf in configuration namelist', lwp )
-         IF(lwm) WRITE ( numond, namsbc_isf )
-
-         IF ( lwp ) WRITE(numout,*)
-         IF ( lwp ) WRITE(numout,*) 'sbc_isf: heat flux of the ice shelf'
-         IF ( lwp ) WRITE(numout,*) '~~~~~~~~~'
-         IF ( lwp ) WRITE(numout,*) 'sbcisf :' 
-         IF ( lwp ) WRITE(numout,*) '~~~~~~~~'
-         IF ( lwp ) WRITE(numout,*) '        nn_isf      = ', nn_isf
-         IF ( lwp ) WRITE(numout,*) '        nn_isfblk   = ', nn_isfblk
-         IF ( lwp ) WRITE(numout,*) '        rn_hisf_tbl = ', rn_hisf_tbl
-         IF ( lwp ) WRITE(numout,*) '        ln_divisf   = ', ln_divisf 
-         IF ( lwp ) WRITE(numout,*) '        nn_gammablk = ', nn_gammablk 
-         IF ( lwp ) WRITE(numout,*) '        rn_tfri2    = ', rn_tfri2 
-         IF (ln_divisf) THEN       ! keep it in the namelist ??? used true anyway as for runoff ? (PM)
-            rdivisf = 1._wp
-         ELSE
-            rdivisf = 0._wp
-         END IF
-         !
-         ! Allocate public variable
-         IF ( sbc_isf_alloc()  /= 0 )         CALL ctl_stop( 'STOP', 'sbc_isf : unable to allocate arrays' )
-         !
-         ! initialisation
-         qisf(:,:)        = 0._wp  ; fwfisf(:,:) = 0._wp
-         risf_tsc(:,:,:)  = 0._wp
-         !
-         ! define isf tbl tickness, top and bottom indice
-         IF      (nn_isf == 1) THEN
-            rhisf_tbl(:,:) = rn_hisf_tbl
-            misfkt(:,:)    = mikt(:,:)         ! same indice for bg03 et cav => used in isfdiv
-         ELSE IF ((nn_isf == 3) .OR. (nn_isf == 2)) THEN
-            ALLOCATE( sf_rnfisf(1), STAT=ierror )
-            ALLOCATE( sf_rnfisf(1)%fnow(jpi,jpj,1), sf_rnfisf(1)%fdta(jpi,jpj,1,2) )
-            CALL fld_fill( sf_rnfisf, (/ sn_rnfisf /), cn_dirisf, 'sbc_isf_init', 'read fresh water flux isf data', 'namsbc_isf' )
-
-            !: read effective lenght (BG03)
-            IF (nn_isf == 2) THEN
-               ! Read Data and save some integral values
-               CALL iom_open( sn_Leff_isf%clname, inum )
-               cvarLeff  = 'soLeff'               !: variable name for Efficient Length scale
-               CALL iom_get( inum, jpdom_data, cvarLeff, risfLeff , 1)
-               CALL iom_close(inum)
-               !
-               risfLeff = risfLeff*1000           !: convertion in m
-            END IF
-
-           ! read depth of the top and bottom of the isf top boundary layer (in this case, isf front depth and grounding line depth)
-            CALL iom_open( sn_depmax_isf%clname, inum )
-            cvarhisf = TRIM(sn_depmax_isf%clvar)
-            CALL iom_get( inum, jpdom_data, cvarhisf, rhisf_tbl, 1) !: depth of deepest point of the ice shelf base
-            CALL iom_close(inum)
-            !
-            CALL iom_open( sn_depmin_isf%clname, inum )
-            cvarzisf = TRIM(sn_depmin_isf%clvar)
-            CALL iom_get( inum, jpdom_data, cvarzisf, rzisf_tbl, 1) !: depth of shallowest point of the ice shelves base
-            CALL iom_close(inum)
-            !
-            rhisf_tbl(:,:) = rhisf_tbl(:,:) - rzisf_tbl(:,:)        !: tickness isf boundary layer
-
-           !! compute first level of the top boundary layer
-           DO ji = 1, jpi
-              DO jj = 1, jpj
-                  jk = 2
-                  DO WHILE ( jk .LE. mbkt(ji,jj) .AND. fsdepw(ji,jj,jk) < rzisf_tbl(ji,jj) ) ;  jk = jk + 1 ;  END DO
-                  misfkt(ji,jj) = jk-1
-               END DO
-            END DO
-
-         ELSE IF ( nn_isf == 4 ) THEN
-            ! as in nn_isf == 1
-            rhisf_tbl(:,:) = rn_hisf_tbl
-            misfkt(:,:)    = mikt(:,:)         ! same indice for bg03 et cav => used in isfdiv
-            
-            ! load variable used in fldread (use for temporal interpolation of isf fwf forcing)
-            ALLOCATE( sf_fwfisf(1), sf_qisf(1), STAT=ierror )
-            ALLOCATE( sf_fwfisf(1)%fnow(jpi,jpj,1), sf_fwfisf(1)%fdta(jpi,jpj,1,2) )
-            ALLOCATE( sf_qisf(1)%fnow(jpi,jpj,1), sf_qisf(1)%fdta(jpi,jpj,1,2) )
-            CALL fld_fill( sf_fwfisf, (/ sn_fwfisf /), cn_dirisf, 'sbc_isf_init', 'read fresh water flux isf data', 'namsbc_isf' )
-            !CALL fld_fill( sf_qisf  , (/ sn_qisf   /), cn_dirisf, 'sbc_isf_init', 'read heat flux isf data'       , 'namsbc_isf' )
-         END IF
-         
-         ! compute bottom level of isf tbl and thickness of tbl below the ice shelf
-         rhisf_tbl_0(:,:) = rhisf_tbl(:,:)
-         DO jj = 1,jpj
-            DO ji = 1,jpi
-               ikt = misfkt(ji,jj)
-               ikb = misfkt(ji,jj)
-               ! thickness of boundary layer at least the top level thickness
-               rhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), fse3t_n(ji,jj,ikt))
-
-               ! determine the deepest level influenced by the boundary layer
-               ! test on tmask useless ?????
-               DO jk = ikt, mbkt(ji,jj)
-                  IF ( (SUM(fse3t_n(ji,jj,ikt:jk-1)) .LT. rhisf_tbl(ji,jj)) .AND. (tmask(ji,jj,jk) == 1) ) ikb = jk
-               END DO
-               rhisf_tbl(ji,jj) = MIN(rhisf_tbl(ji,jj), SUM(fse3t_n(ji,jj,ikt:ikb)))  ! limit the tbl to water thickness.
-               misfkb(ji,jj) = ikb                                                  ! last wet level of the tbl
-               r1_hisf_tbl(ji,jj) = 1._wp / rhisf_tbl(ji,jj)
-
-               zhk           = SUM( fse3t(ji, jj, ikt:ikb - 1)) * r1_hisf_tbl(ji,jj)  ! proportion of tbl cover by cell from ikt to ikb - 1
-               ralpha(ji,jj) = rhisf_tbl(ji,jj) * (1._wp - zhk ) / fse3t(ji,jj,ikb)  ! proportion of bottom cell influenced by boundary layer
-            END DO
-         END DO
+         CALL sbc_isf_init
+      !                                         ! ---------------------------------------- !
+      ELSE                                      !          Swap of forcing fields          !
+         !                                      ! ---------------------------------------- !
+         fwfisf_b  (:,:  ) = fwfisf  (:,:  )    ! Swap the ocean forcing fields except at nit000
+         risf_tsc_b(:,:,:) = risf_tsc(:,:,:)    ! where before fields are set at the end of the routine
          !
       END IF
 
-      !                                            ! ---------------------------------------- !
-      IF( kt /= nit000 ) THEN                      !          Swap of forcing fields          !
-         !                                         ! ---------------------------------------- !
-         fwfisf_b  (:,:  ) = fwfisf  (:,:  )               ! Swap the ocean forcing fields except at nit000
-         risf_tsc_b(:,:,:) = risf_tsc(:,:,:)               ! where before fields are set at the end of the routine
-         !
-      ENDIF
-
       IF( MOD( kt-1, nn_fsbc) == 0 ) THEN
-
-
-         ! compute salf and heat flux
-         IF (nn_isf == 1) THEN
-            ! realistic ice shelf formulation
+         ! allocation
+         CALL wrk_alloc( jpi,jpj, zt_frz, zdep  )
+
+         ! compute salt and heat flux
+         SELECT CASE ( nn_isf )
+         CASE ( 1 )    ! realistic ice shelf formulation
             ! compute T/S/U/V for the top boundary layer
             CALL sbc_isf_tbl(tsn(:,:,:,jp_tem),ttbl(:,:),'T')
             CALL sbc_isf_tbl(tsn(:,:,:,jp_sal),stbl(:,:),'T')
-            CALL sbc_isf_tbl(un(:,:,:),utbl(:,:),'U')
-            CALL sbc_isf_tbl(vn(:,:,:),vtbl(:,:),'V')
+            CALL sbc_isf_tbl(un(:,:,:)        ,utbl(:,:),'U')
+            CALL sbc_isf_tbl(vn(:,:,:)        ,vtbl(:,:),'V')
             ! iom print
             CALL iom_put('ttbl',ttbl(:,:))
             CALL iom_put('stbl',stbl(:,:))
-            CALL iom_put('utbl',utbl(:,:))
-            CALL iom_put('vtbl',vtbl(:,:))
+            CALL iom_put('utbl',utbl(:,:) * (1._wp - tmask(:,:,1)) * ssmask(:,:))
+            CALL iom_put('vtbl',vtbl(:,:) * (1._wp - tmask(:,:,1)) * ssmask(:,:))
             ! compute fwf and heat flux
             CALL sbc_isf_cav (kt)
 
-         ELSE IF (nn_isf == 2) THEN
-            ! Beckmann and Goosse parametrisation 
+         CASE ( 2 )    ! Beckmann and Goosse parametrisation 
             stbl(:,:)   = soce
             CALL sbc_isf_bg03(kt)
 
-         ELSE IF (nn_isf == 3) THEN
-            ! specified runoff in depth (Mathiot et al., XXXX in preparation)
+         CASE ( 3 )    ! specified runoff in depth (Mathiot et al., XXXX in preparation)
             CALL fld_read ( kt, nn_fsbc, sf_rnfisf   )
-            fwfisf(:,:) = - sf_rnfisf(1)%fnow(:,:,1)         ! fresh water flux from the isf (fwfisf <0 mean melting) 
-            qisf(:,:)   = fwfisf(:,:) * lfusisf              ! heat        flux
+            fwfisf(:,:) = - sf_rnfisf(1)%fnow(:,:,1)         ! fwf  flux from the isf (fwfisf <0 mean melting) 
+            qisf(:,:)   = fwfisf(:,:) * rlfusisf             ! heat flux
             stbl(:,:)   = soce
 
-         ELSE IF (nn_isf == 4) THEN
-            ! specified fwf and heat flux forcing beneath the ice shelf
+         CASE ( 4 )    ! specified fwf and heat flux forcing beneath the ice shelf
             CALL fld_read ( kt, nn_fsbc, sf_fwfisf   )
-            !CALL fld_read ( kt, nn_fsbc, sf_qisf   )
-            fwfisf(:,:) = sf_fwfisf(1)%fnow(:,:,1)            ! fwf
-            qisf(:,:)   = fwfisf(:,:) * lfusisf              ! heat        flux
-            !qisf(:,:)   = sf_qisf(1)%fnow(:,:,1)              ! heat flux
+            fwfisf(:,:) = - sf_fwfisf(1)%fnow(:,:,1)           ! fwf  flux from the isf (fwfisf <0 mean melting)
+            qisf(:,:)   = fwfisf(:,:) * rlfusisf               ! heat flux
             stbl(:,:)   = soce
 
-         END IF
+         END SELECT
+
          ! compute tsc due to isf
-         ! WARNING water add at temp = 0C, correction term is added, maybe better here but need a 3D variable).
-!         zpress = grav*rau0*fsdept(ji,jj,jk)*1.e-04
-         zt_frz = -1.9 !eos_fzp( tsn(ji,jj,jk,jp_sal), zpress )
-         risf_tsc(:,:,jp_tem) = qisf(:,:) * r1_rau0_rcp - rdivisf * fwfisf(:,:) * zt_frz * r1_rau0 !
+         ! isf melting implemented as a volume flux and we assume that melt water is at 0 PSU.
+         ! WARNING water add at temp = 0C, need to add a correction term (fwfisf * tfreez / rau0).
+         ! compute freezing point beneath ice shelf (or top cell if nn_isf = 3)
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+               zdep(ji,jj)=gdepw_n(ji,jj,misfkt(ji,jj))
+            END DO
+         END DO
+         CALL eos_fzp( stbl(:,:), zt_frz(:,:), zdep(:,:) )
          
-         ! salt effect already take into account in vertical advection
-         risf_tsc(:,:,jp_sal) = (1.0_wp-rdivisf) * fwfisf(:,:) * stbl(:,:) * r1_rau0
-
-         ! output
-         IF( iom_use('qisf'  ) )   CALL iom_put('qisf'  , qisf)
-         IF( iom_use('fwfisf') )   CALL iom_put('fwfisf', fwfisf * stbl(:,:) / soce )
-
-         ! if apply only on the trend and not as a volume flux (rdivisf = 0), fwfisf have to be set to 0 now
-         fwfisf(:,:) = rdivisf * fwfisf(:,:)         
- 
+         risf_tsc(:,:,jp_tem) = qisf(:,:) * r1_rau0_rcp - fwfisf(:,:) * zt_frz(:,:) * r1_rau0 !
+         risf_tsc(:,:,jp_sal) = 0.0_wp
+
          ! lbclnk
          CALL lbc_lnk(risf_tsc(:,:,jp_tem),'T',1.)
          CALL lbc_lnk(risf_tsc(:,:,jp_sal),'T',1.)
-         CALL lbc_lnk(fwfisf(:,:)   ,'T',1.)
-         CALL lbc_lnk(qisf(:,:)     ,'T',1.)
-
-         IF( kt == nit000 ) THEN                          !   set the forcing field at nit000 - 1    !
+         CALL lbc_lnk(fwfisf(:,:)         ,'T',1.)
+         CALL lbc_lnk(qisf(:,:)           ,'T',1.)
+
+         IF( kt == nit000 ) THEN                         !   set the forcing field at nit000 - 1    !
             IF( ln_rstart .AND.    &                     ! Restart: read in restart file
                  & iom_varid( numror, 'fwf_isf_b', ldstop = .FALSE. ) > 0 ) THEN
@@ -295,6 +175,12 @@
                risf_tsc_b(:,:,:)= risf_tsc(:,:,:)
             END IF
-         ENDIF
+         END IF
          ! 
+         ! output
+         CALL iom_put('qisf'  , qisf)
+         CALL iom_put('fwfisf', fwfisf)
+
+         ! deallocation
+         CALL wrk_dealloc( jpi,jpj, zt_frz, zdep  )
       END IF
       !  
@@ -315,84 +201,205 @@
                &    STAT= sbc_isf_alloc )
          !
-         IF( lk_mpp                  )   CALL mpp_sum ( sbc_isf_alloc )
+         IF( lk_mpp             )   CALL mpp_sum ( sbc_isf_alloc )
          IF( sbc_isf_alloc /= 0 )   CALL ctl_warn('sbc_isf_alloc: failed to allocate arrays.')
          !
-      ENDIF
+      END IF
   END FUNCTION
 
-
-   SUBROUTINE sbc_isf_bg03(kt)
-      !!==========================================================================
-      !!                 *** SUBROUTINE sbcisf_bg03  ***
-      !! add net heat and fresh water flux from ice shelf melting
-      !! into the adjacent ocean using the parameterisation by
-      !! Beckmann and Goosse (2003), "A parameterization of ice shelf-ocean
-      !!     interaction for climate models", Ocean Modelling 5(2003) 157-170.
-      !!  (hereafter BG)
-      !!==========================================================================
-      !!----------------------------------------------------------------------
-      !!   sbc_isf_bg03      : routine called from sbcmod
-      !!----------------------------------------------------------------------
-      !!
-      !! ** Purpose   :   Add heat and fresh water fluxes due to ice shelf melting
-      !! ** Reference :   Beckmann et Goosse, 2003, Ocean Modelling
-      !!
+  SUBROUTINE sbc_isf_init
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_isf_init  ***
+      !!
+      !! ** Purpose : Initialisation of variables for iceshelf fluxes formulation
+      !!
+      !! ** Method  :  4 parameterizations are available according to nn_isf 
+      !!               nn_isf = 1 : Realistic ice_shelf formulation
+      !!                        2 : Beckmann & Goose parameterization
+      !!                        3 : Specified runoff in deptht (Mathiot & al. )
+      !!                        4 : specified fwf and heat flux forcing beneath the ice shelf
+      !!----------------------------------------------------------------------
+      INTEGER               :: ji, jj, jk           ! loop index
+      INTEGER               :: ik                   ! current level index
+      INTEGER               :: ikt, ikb             ! top and bottom level of the isf boundary layer
+      INTEGER               :: inum, ierror
+      INTEGER               :: ios                  ! Local integer output status for namelist read
+      REAL(wp)              :: zhk
+      CHARACTER(len=256)    :: cvarzisf, cvarhisf   ! name for isf file
+      CHARACTER(LEN=32 )    :: cvarLeff             ! variable name for efficient Length scale
+      !!----------------------------------------------------------------------
+      NAMELIST/namsbc_isf/ nn_isfblk, rn_hisf_tbl, rn_gammat0, rn_gammas0, nn_gammablk, nn_isf, &
+                         & sn_fwfisf, sn_rnfisf, sn_depmax_isf, sn_depmin_isf, sn_Leff_isf
+      !!----------------------------------------------------------------------
+
+      REWIND( numnam_ref )              ! Namelist namsbc_rnf in reference namelist : Runoffs 
+      READ  ( numnam_ref, namsbc_isf, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_isf in reference namelist', lwp )
+
+      REWIND( numnam_cfg )              ! Namelist namsbc_rnf in configuration namelist : Runoffs
+      READ  ( numnam_cfg, namsbc_isf, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_isf in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namsbc_isf )
+
+      IF ( lwp ) WRITE(numout,*)
+      IF ( lwp ) WRITE(numout,*) 'sbc_isf: heat flux of the ice shelf'
+      IF ( lwp ) WRITE(numout,*) '~~~~~~~~~'
+      IF ( lwp ) WRITE(numout,*) 'sbcisf :' 
+      IF ( lwp ) WRITE(numout,*) '~~~~~~~~'
+      IF ( lwp ) WRITE(numout,*) '        nn_isf      = ', nn_isf
+      IF ( lwp ) WRITE(numout,*) '        nn_isfblk   = ', nn_isfblk
+      IF ( lwp ) WRITE(numout,*) '        rn_hisf_tbl = ', rn_hisf_tbl
+      IF ( lwp ) WRITE(numout,*) '        nn_gammablk = ', nn_gammablk 
+      IF ( lwp ) WRITE(numout,*) '        rn_gammat0  = ', rn_gammat0  
+      IF ( lwp ) WRITE(numout,*) '        rn_gammas0  = ', rn_gammas0  
+      IF ( lwp ) WRITE(numout,*) '        rn_tfri2    = ', rn_tfri2 
+      !
+      ! Allocate public variable
+      IF ( sbc_isf_alloc()  /= 0 )         CALL ctl_stop( 'STOP', 'sbc_isf : unable to allocate arrays' )
+      !
+      ! initialisation
+      qisf(:,:)        = 0._wp  ; fwfisf  (:,:) = 0._wp
+      risf_tsc(:,:,:)  = 0._wp  ; fwfisf_b(:,:) = 0._wp
+      !
+      ! define isf tbl tickness, top and bottom indice
+      SELECT CASE ( nn_isf )
+      CASE ( 1 ) 
+         rhisf_tbl(:,:) = rn_hisf_tbl
+         misfkt(:,:)    = mikt(:,:)         ! same indice for bg03 et cav => used in isfdiv
+
+      CASE ( 2 , 3 )
+         ALLOCATE( sf_rnfisf(1), STAT=ierror )
+         ALLOCATE( sf_rnfisf(1)%fnow(jpi,jpj,1), sf_rnfisf(1)%fdta(jpi,jpj,1,2) )
+         CALL fld_fill( sf_rnfisf, (/ sn_rnfisf /), cn_dirisf, 'sbc_isf_init', 'read fresh water flux isf data', 'namsbc_isf' )
+
+         !  read effective lenght (BG03)
+         IF (nn_isf == 2) THEN
+            CALL iom_open( sn_Leff_isf%clname, inum )
+            cvarLeff = TRIM(sn_Leff_isf%clvar)
+            CALL iom_get( inum, jpdom_data, cvarLeff, risfLeff , 1)
+            CALL iom_close(inum)
+            !
+            risfLeff = risfLeff*1000.0_wp           !: convertion in m
+         END IF
+
+         ! read depth of the top and bottom of the isf top boundary layer (in this case, isf front depth and grounding line depth)
+         CALL iom_open( sn_depmax_isf%clname, inum )
+         cvarhisf = TRIM(sn_depmax_isf%clvar)
+         CALL iom_get( inum, jpdom_data, cvarhisf, rhisf_tbl, 1) !: depth of deepest point of the ice shelf base
+         CALL iom_close(inum)
+         !
+         CALL iom_open( sn_depmin_isf%clname, inum )
+         cvarzisf = TRIM(sn_depmin_isf%clvar)
+         CALL iom_get( inum, jpdom_data, cvarzisf, rzisf_tbl, 1) !: depth of shallowest point of the ice shelves base
+         CALL iom_close(inum)
+         !
+         rhisf_tbl(:,:) = rhisf_tbl(:,:) - rzisf_tbl(:,:)        !: tickness isf boundary layer
+
+         !! compute first level of the top boundary layer
+         DO ji = 1, jpi
+            DO jj = 1, jpj
+                ik = 2
+                DO WHILE ( ik <= mbkt(ji,jj) .AND. gdepw_n(ji,jj,ik) < rzisf_tbl(ji,jj) ) ;  ik = ik + 1 ;  END DO
+                misfkt(ji,jj) = ik-1
+            END DO
+         END DO
+
+      CASE ( 4 ) 
+         ! as in nn_isf == 1
+         rhisf_tbl(:,:) = rn_hisf_tbl
+         misfkt(:,:)    = mikt(:,:)         ! same indice for bg03 et cav => used in isfdiv
+         
+         ! load variable used in fldread (use for temporal interpolation of isf fwf forcing)
+         ALLOCATE( sf_fwfisf(1), STAT=ierror )
+         ALLOCATE( sf_fwfisf(1)%fnow(jpi,jpj,1), sf_fwfisf(1)%fdta(jpi,jpj,1,2) )
+         CALL fld_fill( sf_fwfisf, (/ sn_fwfisf /), cn_dirisf, 'sbc_isf_init', 'read fresh water flux isf data', 'namsbc_isf' )
+
+      END SELECT
+         
+      rhisf_tbl_0(:,:) = rhisf_tbl(:,:)
+
+      ! compute bottom level of isf tbl and thickness of tbl below the ice shelf
+      DO jj = 1,jpj
+         DO ji = 1,jpi
+            ikt = misfkt(ji,jj)
+            ikb = misfkt(ji,jj)
+            ! thickness of boundary layer at least the top level thickness
+            rhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), e3t_n(ji,jj,ikt))
+
+            ! determine the deepest level influenced by the boundary layer
+            DO jk = ikt+1, mbkt(ji,jj)
+               IF ( (SUM(e3t_n(ji,jj,ikt:jk-1)) < rhisf_tbl(ji,jj)) .AND. (tmask(ji,jj,jk) == 1) ) ikb = jk
+            END DO
+            rhisf_tbl(ji,jj) = MIN(rhisf_tbl(ji,jj), SUM(e3t_n(ji,jj,ikt:ikb))) ! limit the tbl to water thickness.
+            misfkb(ji,jj) = ikb                                                   ! last wet level of the tbl
+            r1_hisf_tbl(ji,jj) = 1._wp / rhisf_tbl(ji,jj)
+
+            zhk           = SUM( e3t_n(ji, jj, ikt:ikb - 1)) * r1_hisf_tbl(ji,jj) ! proportion of tbl cover by cell from ikt to ikb - 1
+            ralpha(ji,jj) = rhisf_tbl(ji,jj) * (1._wp - zhk ) / e3t_n(ji,jj,ikb)  ! proportion of bottom cell influenced by boundary layer
+         END DO
+      END DO
+
+  END SUBROUTINE sbc_isf_init
+
+  SUBROUTINE sbc_isf_bg03(kt)
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_isf_bg03  ***
+      !!
+      !! ** Purpose : add net heat and fresh water flux from ice shelf melting
+      !!          into the adjacent ocean
+      !!
+      !! ** Method  :   See reference
+      !!
+      !! ** Reference : Beckmann and Goosse (2003), "A parameterization of ice shelf-ocean
+      !!         interaction for climate models", Ocean Modelling 5(2003) 157-170.
+      !!         (hereafter BG)
       !! History :
-      !!      !  06-02  (C. Wang) Original code
+      !!         06-02  (C. Wang) Original code
       !!----------------------------------------------------------------------
       INTEGER, INTENT ( in ) :: kt
       !
-    INTEGER :: ji, jj, jk, jish  !temporary integer
-    INTEGER :: ijkmin
-    INTEGER :: ii, ij, ik 
-    INTEGER :: inum
-
-    REAL(wp) :: zt_sum      ! sum of the temperature between 200m and 600m
-    REAL(wp) :: zt_ave      ! averaged temperature between 200m and 600m
-    REAL(wp) :: zt_frz      ! freezing point temperature at depth z
-    REAL(wp) :: zpress      ! pressure to compute the freezing point in depth
-    
-    !!----------------------------------------------------------------------
-    IF ( nn_timing == 1 ) CALL timing_start('sbc_isf_bg03')
-     !
-
-    ! This test is false only in the very first time step of a run (JMM ???- Initialy build to skip 1rst year of run )
-    DO ji = 1, jpi
-       DO jj = 1, jpj
-          ik = misfkt(ji,jj)
-          !! Initialize arrays to 0 (each step)
-          zt_sum = 0.e0_wp
-          IF ( ik .GT. 1 ) THEN
-    ! 3. -----------the average temperature between 200m and 600m ---------------------
-             DO jk = misfkt(ji,jj),misfkb(ji,jj)
-             ! freezing point temperature  at ice shelf base BG eq. 2 (JMM sign pb ??? +7.64e-4 !!!)
-             ! after verif with UNESCO, wrong sign in BG eq. 2
-             ! Calculate freezing temperature
-                zpress = grav*rau0*fsdept(ji,jj,ik)*1.e-04 
-                CALL eos_fzp(tsb(ji,jj,ik,jp_sal), zt_frz, zpress) 
-                zt_sum = zt_sum + (tsn(ji,jj,ik,jp_tem)-zt_frz) * fse3t(ji,jj,ik) * tmask(ji,jj,ik)  ! sum temp
-             ENDDO
-             zt_ave = zt_sum/rhisf_tbl(ji,jj) ! calcul mean value
-    
-    ! 4. ------------Net heat flux and fresh water flux due to the ice shelf
-          ! For those corresponding to zonal boundary    
-             qisf(ji,jj) = - rau0 * rcp * rn_gammat0 * risfLeff(ji,jj) * e1t(ji,jj) * zt_ave  &
-                         & / (e1t(ji,jj) * e2t(ji,jj)) * tmask(ji,jj,ik) 
+      INTEGER  :: ji, jj, jk ! dummy loop index
+      INTEGER  :: ik         ! current level
+      REAL(wp) :: zt_sum     ! sum of the temperature between 200m and 600m
+      REAL(wp) :: zt_ave     ! averaged temperature between 200m and 600m
+      REAL(wp) :: zt_frz     ! freezing point temperature at depth z
+      REAL(wp) :: zpress     ! pressure to compute the freezing point in depth
+      !!----------------------------------------------------------------------
+
+      IF ( nn_timing == 1 ) CALL timing_start('sbc_isf_bg03')
+      !
+      DO ji = 1, jpi
+         DO jj = 1, jpj
+            ik = misfkt(ji,jj)
+            !! Initialize arrays to 0 (each step)
+            zt_sum = 0.e0_wp
+            IF ( ik > 1 ) THEN
+               ! 1. -----------the average temperature between 200m and 600m ---------------------
+               DO jk = misfkt(ji,jj),misfkb(ji,jj)
+                  ! freezing point temperature  at ice shelf base BG eq. 2 (JMM sign pb ??? +7.64e-4 !!!)
+                  ! after verif with UNESCO, wrong sign in BG eq. 2
+                  ! Calculate freezing temperature
+                  CALL eos_fzp(stbl(ji,jj), zt_frz, zpress) 
+                  zt_sum = zt_sum + (tsn(ji,jj,jk,jp_tem)-zt_frz) * e3t_n(ji,jj,jk) * tmask(ji,jj,jk)  ! sum temp
+               END DO
+               zt_ave = zt_sum/rhisf_tbl(ji,jj) ! calcul mean value
+               ! 2. ------------Net heat flux and fresh water flux due to the ice shelf
+               ! For those corresponding to zonal boundary    
+               qisf(ji,jj) = - rau0 * rcp * rn_gammat0 * risfLeff(ji,jj) * e1t(ji,jj) * zt_ave  &
+                           & * r1_e1e2t(ji,jj) * tmask(ji,jj,jk)
              
-             fwfisf(ji,jj) = qisf(ji,jj) / lfusisf          !fresh water flux kg/(m2s)                  
-             fwfisf(ji,jj) = fwfisf(ji,jj) * ( soce / stbl(ji,jj) )
-             !add to salinity trend
-          ELSE
-             qisf(ji,jj) = 0._wp ; fwfisf(ji,jj) = 0._wp
-          END IF
-       END DO
-    END DO
-    !
-    IF( nn_timing == 1 )  CALL timing_stop('sbc_isf_bg03')
+               fwfisf(ji,jj) = qisf(ji,jj) / rlfusisf          !fresh water flux kg/(m2s)                  
+               fwfisf(ji,jj) = fwfisf(ji,jj) * ( soce / stbl(ji,jj) )
+               !add to salinity trend
+            ELSE
+               qisf(ji,jj) = 0._wp ; fwfisf(ji,jj) = 0._wp
+            END IF
+         END DO
+      END DO
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('sbc_isf_bg03')
       !
   END SUBROUTINE sbc_isf_bg03
 
-
-   SUBROUTINE sbc_isf_cav( kt )
+  SUBROUTINE sbc_isf_cav( kt )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE sbc_isf_cav  ***
@@ -409,155 +416,119 @@
       INTEGER, INTENT(in)          ::   kt         ! ocean time step
       !
-      LOGICAL :: ln_isomip = .true.
-      REAL(wp), DIMENSION(:,:), POINTER       ::   zfrz,zpress,zti
-      REAL(wp), DIMENSION(:,:), POINTER       ::   zgammat2d, zgammas2d 
-      !REAL(wp), DIMENSION(:,:), POINTER ::   zqisf, zfwfisf
+      INTEGER  ::   ji, jj     ! dummy loop indices
+      INTEGER  ::   nit
       REAL(wp) ::   zlamb1, zlamb2, zlamb3
       REAL(wp) ::   zeps1,zeps2,zeps3,zeps4,zeps6,zeps7
       REAL(wp) ::   zaqe,zbqe,zcqe,zaqer,zdis,zsfrz,zcfac
-      REAL(wp) ::   zfwflx, zhtflx, zhtflx_b
-      REAL(wp) ::   zgammat, zgammas
-      REAL(wp) ::   zeps   =  -1.e-20_wp        !==   Local constant initialization   ==!
-      INTEGER  ::   ji, jj     ! dummy loop indices
-      INTEGER  ::   ii0, ii1, ij0, ij1   ! temporary integers
-      INTEGER  ::   ierror     ! return error code
-      LOGICAL  ::   lit=.TRUE.
-      INTEGER  ::   nit
+      REAL(wp) ::   zeps = 1.e-20_wp        
+      REAL(wp) ::   zerr
+      REAL(wp), DIMENSION(:,:), POINTER ::   zfrz
+      REAL(wp), DIMENSION(:,:), POINTER ::   zgammat, zgammas 
+      REAL(wp), DIMENSION(:,:), POINTER ::   zfwflx, zhtflx, zhtflx_b
+      LOGICAL  ::   lit
       !!---------------------------------------------------------------------
-      !
-      ! coeficient for linearisation of tfreez
-      zlamb1=-0.0575
-      zlamb2=0.0901
-      zlamb3=-7.61e-04
+      ! coeficient for linearisation of potential tfreez
+      ! Crude approximation for pressure (but commonly used)
+      zlamb1 =-0.0573_wp
+      zlamb2 = 0.0832_wp
+      zlamb3 =-7.53e-08_wp * grav * rau0
       IF( nn_timing == 1 )  CALL timing_start('sbc_isf_cav')
       !
-      CALL wrk_alloc( jpi,jpj, zfrz,zpress,zti, zgammat2d, zgammas2d )
-
-      zcfac=0.0_wp 
-      IF (ln_conserve)  zcfac=1.0_wp
-      zpress(:,:)=0.0_wp
-      zgammat2d(:,:)=0.0_wp
-      zgammas2d(:,:)=0.0_wp
-      !
-      !
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            ! Crude approximation for pressure (but commonly used)
-            ! 1e-04 to convert from Pa to dBar
-            zpress(ji,jj)=grav*rau0*fsdepw(ji,jj,mikt(ji,jj))*1.e-04
-            !
-         END DO
+      CALL wrk_alloc( jpi,jpj, zfrz  , zgammat, zgammas  )
+      CALL wrk_alloc( jpi,jpj, zfwflx, zhtflx , zhtflx_b )
+
+      ! initialisation
+      zgammat(:,:) = rn_gammat0 ; zgammas (:,:) = rn_gammas0
+      zhtflx (:,:) = 0.0_wp     ; zhtflx_b(:,:) = 0.0_wp    
+      zfwflx (:,:) = 0.0_wp
+
+      ! compute ice shelf melting
+      nit = 1 ; lit = .TRUE.
+      DO WHILE ( lit )    ! maybe just a constant number of iteration as in blk_core is fine
+         SELECT CASE ( nn_isfblk )
+         CASE ( 1 )   !  ISOMIP formulation (2 equations) for volume flux (Hunter et al., 2006)
+            ! Calculate freezing temperature
+            CALL eos_fzp( stbl(:,:), zfrz(:,:), risfdep(:,:) )
+
+            ! compute gammat every where (2d)
+            CALL sbc_isf_gammats(zgammat, zgammas, zhtflx, zfwflx)
+            
+            ! compute upward heat flux zhtflx and upward water flux zwflx
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zhtflx(ji,jj) =   zgammat(ji,jj)*rcp*rau0*(ttbl(ji,jj)-zfrz(ji,jj))
+                  zfwflx(ji,jj) = - zhtflx(ji,jj)/rlfusisf
+               END DO
+            END DO
+
+            ! Compute heat flux and upward fresh water flux
+            qisf  (:,:) = - zhtflx(:,:) * (1._wp - tmask(:,:,1)) * ssmask(:,:)
+            fwfisf(:,:) =   zfwflx(:,:) * (1._wp - tmask(:,:,1)) * ssmask(:,:)
+
+         CASE ( 2 )  ! ISOMIP+ formulation (3 equations) for volume flux (Asay-Davis et al., 2015)
+            ! compute gammat every where (2d)
+            CALL sbc_isf_gammats(zgammat, zgammas, zhtflx, zfwflx)
+
+            ! compute upward heat flux zhtflx and upward water flux zwflx
+            ! Resolution of a 2d equation from equation 21, 22 and 23 to find Sb (Asay-Davis et al., 2015)
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ! compute coeficient to solve the 2nd order equation
+                  zeps1 = rcp*rau0*zgammat(ji,jj)
+                  zeps2 = rlfusisf*rau0*zgammas(ji,jj)
+                  zeps3 = rhoisf*rcpi*rkappa/MAX(risfdep(ji,jj),zeps)
+                  zeps4 = zlamb2+zlamb3*risfdep(ji,jj)
+                  zeps6 = zeps4-ttbl(ji,jj)
+                  zeps7 = zeps4-tsurf
+                  zaqe  = zlamb1 * (zeps1 + zeps3)
+                  zaqer = 0.5_wp/MIN(zaqe,-zeps)
+                  zbqe  = zeps1*zeps6+zeps3*zeps7-zeps2
+                  zcqe  = zeps2*stbl(ji,jj)
+                  zdis  = zbqe*zbqe-4.0_wp*zaqe*zcqe               
+
+                  ! Presumably zdis can never be negative because gammas is very small compared to gammat
+                  ! compute s freeze
+                  zsfrz=(-zbqe-SQRT(zdis))*zaqer
+                  IF ( zsfrz < 0.0_wp ) zsfrz=(-zbqe+SQRT(zdis))*zaqer
+
+                  ! compute t freeze (eq. 22)
+                  zfrz(ji,jj)=zeps4+zlamb1*zsfrz
+  
+                  ! zfwflx is upward water flux
+                  ! zhtflx is upward heat flux (out of ocean)
+                  ! compute the upward water and heat flux (eq. 28 and eq. 29)
+                  zfwflx(ji,jj) = rau0 * zgammas(ji,jj) * (zsfrz-stbl(ji,jj)) / MAX(zsfrz,zeps)
+                  zhtflx(ji,jj) = zgammat(ji,jj) * rau0 * rcp * (ttbl(ji,jj) - zfrz(ji,jj) ) 
+               END DO
+            END DO
+
+            ! compute heat and water flux
+            qisf  (:,:) = - zhtflx(:,:) * (1._wp - tmask(:,:,1)) * ssmask(:,:)
+            fwfisf(:,:) =   zfwflx(:,:) * (1._wp - tmask(:,:,1)) * ssmask(:,:)
+
+         END SELECT
+
+         ! define if we need to iterate (nn_gammablk 0/1 do not need iteration)
+         IF ( nn_gammablk <  2 ) THEN ; lit = .FALSE.
+         ELSE                           
+            ! check total number of iteration
+            IF (nit >= 100) THEN ; CALL ctl_stop( 'STOP', 'sbc_isf_hol99 : too many iteration ...' )
+            ELSE                 ; nit = nit + 1
+            END IF
+
+            ! compute error between 2 iterations
+            ! if needed save gammat and compute zhtflx_b for next iteration
+            zerr = MAXVAL(ABS(zhtflx-zhtflx_b))
+            IF ( zerr <= 0.01_wp ) THEN ; lit = .FALSE.
+            ELSE                        ; zhtflx_b(:,:) = zhtflx(:,:)
+            END IF
+         END IF
       END DO
-
-! Calculate in-situ temperature (ref to surface)
-      zti(:,:)=tinsitu( ttbl, stbl, zpress )
-! Calculate freezing temperature
-      CALL eos_fzp( sss_m(:,:), zfrz(:,:), zpress )
-
-      
-      zhtflx=0._wp ; zfwflx=0._wp
-      IF (nn_isfblk == 1) THEN
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF (mikt(ji,jj) > 1 ) THEN
-                  nit = 1; lit = .TRUE.; zgammat=rn_gammat0; zgammas=rn_gammas0; zhtflx_b=0._wp
-                  DO WHILE ( lit )
-! compute gamma
-                     CALL sbc_isf_gammats(zgammat, zgammas, zhtflx, zfwflx, ji, jj, lit)
-! zhtflx is upward heat flux (out of ocean)
-                     zhtflx = zgammat*rcp*rau0*(zti(ji,jj)-zfrz(ji,jj))
-! zwflx is upward water flux
-                     zfwflx = - zhtflx/lfusisf
-! test convergence and compute gammat
-                     IF ( (zhtflx - zhtflx_b) .LE. 0.01 ) lit = .FALSE.
-
-                     nit = nit + 1
-                     IF (nit .GE. 100) CALL ctl_stop( 'STOP', 'sbc_isf_hol99 : too many iteration ...' )
-
-! save gammat and compute zhtflx_b
-                     zgammat2d(ji,jj)=zgammat
-                     zhtflx_b = zhtflx
-                  END DO
-
-                  qisf(ji,jj) = - zhtflx
-! For genuine ISOMIP protocol this should probably be something like
-                  fwfisf(ji,jj) = zfwflx  * ( soce / MAX(stbl(ji,jj),zeps))
-               ELSE
-                  fwfisf(ji,jj) = 0._wp
-                  qisf(ji,jj)   = 0._wp
-               END IF
-            !
-            END DO
-         END DO
-
-      ELSE IF (nn_isfblk == 2 ) THEN
-
-! More complicated 3 equation thermodynamics as in MITgcm
-         DO jj = 2, jpj
-            DO ji = 2, jpi
-               IF (mikt(ji,jj) > 1 ) THEN
-                  nit=1; lit=.TRUE.; zgammat=rn_gammat0; zgammas=rn_gammas0; zhtflx_b=0._wp; zhtflx=0._wp
-                  DO WHILE ( lit )
-                     CALL sbc_isf_gammats(zgammat, zgammas, zhtflx, zfwflx, ji, jj, lit)
-
-                     zeps1=rcp*rau0*zgammat
-                     zeps2=lfusisf*rau0*zgammas
-                     zeps3=rhoisf*rcpi*kappa/risfdep(ji,jj)
-                     zeps4=zlamb2+zlamb3*risfdep(ji,jj)
-                     zeps6=zeps4-zti(ji,jj)
-                     zeps7=zeps4-tsurf
-                     zaqe=zlamb1 * (zeps1 + zeps3)
-                     zaqer=0.5/zaqe
-                     zbqe=zeps1*zeps6+zeps3*zeps7-zeps2
-                     zcqe=zeps2*stbl(ji,jj)
-                     zdis=zbqe*zbqe-4.0*zaqe*zcqe               
-! Presumably zdis can never be negative because gammas is very small compared to gammat
-                     zsfrz=(-zbqe-SQRT(zdis))*zaqer
-                     IF (zsfrz .lt. 0.0) zsfrz=(-zbqe+SQRT(zdis))*zaqer
-                     zfrz(ji,jj)=zeps4+zlamb1*zsfrz
-  
-! zfwflx is upward water flux
-                     zfwflx= rau0 * zgammas * ( (zsfrz-stbl(ji,jj)) / zsfrz )
-! zhtflx is upward heat flux (out of ocean)
-! If non conservative we have zcfac=0.0 so zhtflx is as ISOMIP but with different zfrz value
-                     zhtflx = ( zgammat*rau0 - zcfac*zfwflx ) * rcp * (zti(ji,jj) - zfrz(ji,jj) ) 
-! zwflx is upward water flux
-! If non conservative we have zcfac=0.0 so what follows is then zfwflx*sss_m/zsfrz
-                     zfwflx = ( zgammas*rau0 - zcfac*zfwflx ) * (zsfrz - stbl(ji,jj)) / stbl(ji,jj)
-! test convergence and compute gammat
-                     IF (( zhtflx - zhtflx_b) .LE. 0.01 ) lit = .FALSE.
-
-                     nit = nit + 1
-                     IF (nit .GE. 51) THEN
-                        WRITE(numout,*) "sbcisf : too many iteration ... ", &
-                            &  zhtflx, zhtflx_b, zgammat, zgammas, nn_gammablk, ji, jj, mikt(ji,jj), narea
-                        CALL ctl_stop( 'STOP', 'sbc_isf_hol99 : too many iteration ...' )
-                     END IF
-! save gammat and compute zhtflx_b
-                     zgammat2d(ji,jj)=zgammat
-                     zgammas2d(ji,jj)=zgammas
-                     zhtflx_b = zhtflx
-
-                  END DO
-! If non conservative we have zcfac=0.0 so zhtflx is as ISOMIP but with different zfrz value
-                  qisf(ji,jj) = - zhtflx 
-! If non conservative we have zcfac=0.0 so what follows is then zfwflx*sss_m/zsfrz
-                  fwfisf(ji,jj) = zfwflx 
-               ELSE
-                  fwfisf(ji,jj) = 0._wp
-                  qisf(ji,jj)   = 0._wp
-               ENDIF
-               !
-            END DO
-         END DO
-      ENDIF
-      ! lbclnk
-      CALL lbc_lnk(zgammas2d(:,:),'T',1.)
-      CALL lbc_lnk(zgammat2d(:,:),'T',1.)
-      ! output
-      CALL iom_put('isfgammat', zgammat2d)
-      CALL iom_put('isfgammas', zgammas2d)
-      !
-      CALL wrk_dealloc( jpi,jpj, zfrz,zpress,zti, zgammat2d, zgammas2d )
+      !
+      CALL iom_put('isfgammat', zgammat)
+      CALL iom_put('isfgammas', zgammas)
+      ! 
+      CALL wrk_dealloc( jpi,jpj, zfrz  , zgammat, zgammas  )
+      CALL wrk_dealloc( jpi,jpj, zfwflx, zhtflx , zhtflx_b )
       !
       IF( nn_timing == 1 )  CALL timing_stop('sbc_isf_cav')
@@ -565,6 +536,5 @@
    END SUBROUTINE sbc_isf_cav
 
-
-   SUBROUTINE sbc_isf_gammats(gt, gs, zqhisf, zqwisf, ji, jj, lit )
+   SUBROUTINE sbc_isf_gammats(pgt, pgs, pqhisf, pqwisf )
       !!----------------------------------------------------------------------
       !! ** Purpose    : compute the coefficient echange for heat flux
@@ -575,10 +545,10 @@
       !!                Jenkins et al., 2010, JPO, p2298-2312
       !!---------------------------------------------------------------------
-      REAL(wp), INTENT(inout) :: gt, gs, zqhisf, zqwisf
-      INTEGER , INTENT(in)    :: ji,jj
-      LOGICAL , INTENT(inout) :: lit
-
-      INTEGER  :: ikt                 ! loop index
-      REAL(wp) :: zut, zvt, zustar           ! U, V at T point and friction velocity
+      REAL(wp), DIMENSION(:,:), INTENT(out) :: pgt, pgs
+      REAL(wp), DIMENSION(:,:), INTENT(in ) :: pqhisf, pqwisf
+      !
+      INTEGER  :: ikt                        
+      INTEGER  :: ji, jj                     ! loop index
+      REAL(wp), DIMENSION(:,:), POINTER :: zustar           ! U, V at T point and friction velocity
       REAL(wp) :: zdku, zdkv                 ! U, V shear 
       REAL(wp) :: zPr, zSc, zRc              ! Prandtl, Scmidth and Richardson number 
@@ -590,169 +560,211 @@
       REAL(wp) :: zcoef                      ! temporary coef
       REAL(wp) :: zdep
-      REAL(wp), PARAMETER :: zxsiN = 0.052   ! dimensionless constant
-      REAL(wp), PARAMETER :: epsln = 1.0e-20 ! a small positive number
-      REAL(wp), PARAMETER :: znu   = 1.95e-6 ! kinamatic viscosity of sea water (m2.s-1)
-      REAL(wp) ::   rcs      = 1.0e-3_wp        ! conversion: mm/s ==> m/s
+      REAL(wp) :: zeps = 1.0e-20_wp    
+      REAL(wp), PARAMETER :: zxsiN = 0.052_wp   ! dimensionless constant
+      REAL(wp), PARAMETER :: znu   = 1.95e-6_wp ! kinamatic viscosity of sea water (m2.s-1)
       REAL(wp), DIMENSION(2) :: zts, zab
       !!---------------------------------------------------------------------
-      !
-      IF( nn_gammablk == 0 ) THEN
-      !! gamma is constant (specified in namelist)
-         gt = rn_gammat0
-         gs = rn_gammas0
-         lit = .FALSE.
-      ELSE IF ( nn_gammablk == 1 ) THEN
-      !! gamma is assume to be proportional to u* 
-      !! WARNING in case of Losh 2008 tbl parametrization, 
-      !! you have to used the mean value of u in the boundary layer) 
-      !! not yet coded
-      !! Jenkins et al., 2010, JPO, p2298-2312
-         ikt = mikt(ji,jj)
-      !! Compute U and V at T points
-   !      zut = 0.5 * ( utbl(ji-1,jj  ) + utbl(ji,jj) )
-   !      zvt = 0.5 * ( vtbl(ji  ,jj-1) + vtbl(ji,jj) )
-          zut = utbl(ji,jj)
-          zvt = vtbl(ji,jj)
-
-      !! compute ustar
-         zustar = SQRT( rn_tfri2 * (zut * zut + zvt * zvt) )
-      !! Compute mean value over the TBL
-
-      !! Compute gammats
-         gt = zustar * rn_gammat0
-         gs = zustar * rn_gammas0
-         lit = .FALSE.
-      ELSE IF ( nn_gammablk == 2 ) THEN
-      !! gamma depends of stability of boundary layer
-      !! WARNING in case of Losh 2008 tbl parametrization, 
-      !! you have to used the mean value of u in the boundary layer) 
-      !! not yet coded
-      !! Holland and Jenkins, 1999, JPO, p1787-1800, eq 14
-      !! as MOL depends of flux and flux depends of MOL, best will be iteration (TO DO)
+      CALL wrk_alloc( jpi,jpj, zustar )
+      !
+      SELECT CASE ( nn_gammablk )
+      CASE ( 0 ) ! gamma is constant (specified in namelist)
+         !! ISOMIP formulation (Hunter et al, 2006)
+         pgt(:,:) = rn_gammat0
+         pgs(:,:) = rn_gammas0
+
+      CASE ( 1 ) ! gamma is assume to be proportional to u*
+         !! Jenkins et al., 2010, JPO, p2298-2312
+         !! Adopted by Asay-Davis et al. (2015)
+
+         !! compute ustar (eq. 24)
+         zustar(:,:) = SQRT( rn_tfri2 * (utbl(:,:) * utbl(:,:) + vtbl(:,:) * vtbl(:,:) + rn_tfeb2) )
+
+         !! Compute gammats
+         pgt(:,:) = zustar(:,:) * rn_gammat0
+         pgs(:,:) = zustar(:,:) * rn_gammas0
+      
+      CASE ( 2 ) ! gamma depends of stability of boundary layer
+         !! Holland and Jenkins, 1999, JPO, p1787-1800, eq 14
+         !! as MOL depends of flux and flux depends of MOL, best will be iteration (TO DO)
+         !! compute ustar
+         zustar(:,:) = SQRT( rn_tfri2 * (utbl(:,:) * utbl(:,:) + vtbl(:,:) * vtbl(:,:) + rn_tfeb2) )
+
+         !! compute Pr and Sc number (can be improved)
+         zPr =   13.8_wp
+         zSc = 2432.0_wp
+
+         !! compute gamma mole
+         zgmolet = 12.5_wp * zPr ** (2.0/3.0) - 6.0_wp
+         zgmoles = 12.5_wp * zSc ** (2.0/3.0) - 6.0_wp
+
+         !! compute gamma
+         DO ji=2,jpi
+            DO jj=2,jpj
                ikt = mikt(ji,jj)
 
-      !! Compute U and V at T points
-               zut = 0.5 * ( utbl(ji-1,jj  ) + utbl(ji,jj) )
-               zvt = 0.5 * ( vtbl(ji  ,jj-1) + vtbl(ji,jj) )
-
-      !! compute ustar
-               zustar = SQRT( rn_tfri2 * (zut * zut + zvt * zvt) )
-               IF (zustar == 0._wp) THEN           ! only for kt = 1 I think
-                 gt = rn_gammat0
-                 gs = rn_gammas0
+               IF (zustar(ji,jj) == 0._wp) THEN           ! only for kt = 1 I think
+                  pgt = rn_gammat0
+                  pgs = rn_gammas0
                ELSE
-      !! compute Rc number (as done in zdfric.F90)
-               zcoef = 0.5 / fse3w(ji,jj,ikt)
-               !                                            ! shear of horizontal velocity
-               zdku = zcoef * (  un(ji-1,jj  ,ikt  ) + un(ji,jj,ikt  )   &
-                  &             -un(ji-1,jj  ,ikt+1) - un(ji,jj,ikt+1)  )
-               zdkv = zcoef * (  vn(ji  ,jj-1,ikt  ) + vn(ji,jj,ikt  )   &
-                  &             -vn(ji  ,jj-1,ikt+1) - vn(ji,jj,ikt+1)  )
-               !                                            ! richardson number (minimum value set to zero)
-               zRc = rn2(ji,jj,ikt+1) / ( zdku*zdku + zdkv*zdkv + 1.e-20 )
-
-      !! compute Pr and Sc number (can be improved)
-               zPr =   13.8
-               zSc = 2432.0
-
-      !! compute gamma mole
-               zgmolet = 12.5 * zPr ** (2.0/3.0) - 6.0
-               zgmoles = 12.5 * zSc ** (2.0/3.0) -6.0
-
-      !! compute bouyancy 
-               zts(jp_tem) = ttbl(ji,jj)
-               zts(jp_sal) = stbl(ji,jj)
-               zdep        = fsdepw(ji,jj,ikt)
-               !
-               CALL eos_rab( zts, zdep, zab )
+                  !! compute Rc number (as done in zdfric.F90)
+                  zcoef = 0.5_wp / e3w_n(ji,jj,ikt)
+                  !                                            ! shear of horizontal velocity
+                  zdku = zcoef * (  un(ji-1,jj  ,ikt  ) + un(ji,jj,ikt  )  &
+                     &             -un(ji-1,jj  ,ikt+1) - un(ji,jj,ikt+1)  )
+                  zdkv = zcoef * (  vn(ji  ,jj-1,ikt  ) + vn(ji,jj,ikt  )  &
+                     &             -vn(ji  ,jj-1,ikt+1) - vn(ji,jj,ikt+1)  )
+                  !                                            ! richardson number (minimum value set to zero)
+                  zRc = rn2(ji,jj,ikt+1) / MAX( zdku*zdku + zdkv*zdkv, zeps )
+
+                  !! compute bouyancy 
+                  zts(jp_tem) = ttbl(ji,jj)
+                  zts(jp_sal) = stbl(ji,jj)
+                  zdep        = gdepw_n(ji,jj,ikt)
                   !
-      !! compute length scale 
-               zbuofdep = grav * ( zab(jp_tem) * zqhisf - zab(jp_sal) * zqwisf )  !!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-      !! compute Monin Obukov Length
-               ! Maximum boundary layer depth
-               zhmax = fsdept(ji,jj,mbkt(ji,jj)) - fsdepw(ji,jj,mikt(ji,jj)) -0.001
-               ! Compute Monin obukhov length scale at the surface and Ekman depth:
-               zmob   = zustar ** 3 / (vkarmn * (zbuofdep + epsln))
-               zmols  = SIGN(1._wp, zmob) * MIN(ABS(zmob), zhmax) * tmask(ji,jj,ikt)
-
-      !! compute eta* (stability parameter)
-               zetastar = 1 / ( SQRT(1 + MAX(zxsiN * zustar / ( ABS(ff(ji,jj)) * zmols * zRc ), 0.0)))
-
-      !! compute the sublayer thickness
-               zhnu = 5 * znu / zustar
-      !! compute gamma turb
-               zgturb = 1/vkarmn * LOG(zustar * zxsiN * zetastar * zetastar / ( ABS(ff(ji,jj)) * zhnu )) &
-               &      + 1 / ( 2 * zxsiN * zetastar ) - 1/vkarmn
-
-      !! compute gammats
-               gt = zustar / (zgturb + zgmolet)
-               gs = zustar / (zgturb + zgmoles)
+                  CALL eos_rab( zts, zdep, zab )
+                  !
+                  !! compute length scale 
+                  zbuofdep = grav * ( zab(jp_tem) * pqhisf(ji,jj) - zab(jp_sal) * pqwisf(ji,jj) )  !!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+                  !! compute Monin Obukov Length
+                  ! Maximum boundary layer depth
+                  zhmax = gdept_n(ji,jj,mbkt(ji,jj)) - gdepw_n(ji,jj,mikt(ji,jj)) -0.001_wp
+                  ! Compute Monin obukhov length scale at the surface and Ekman depth:
+                  zmob   = zustar(ji,jj) ** 3 / (vkarmn * (zbuofdep + zeps))
+                  zmols  = SIGN(1._wp, zmob) * MIN(ABS(zmob), zhmax) * tmask(ji,jj,ikt)
+
+                  !! compute eta* (stability parameter)
+                  zetastar = 1._wp / ( SQRT(1._wp + MAX(zxsiN * zustar(ji,jj) / ( ABS(ff(ji,jj)) * zmols * zRc ), 0.0_wp)))
+
+                  !! compute the sublayer thickness
+                  zhnu = 5 * znu / zustar(ji,jj)
+
+                  !! compute gamma turb
+                  zgturb = 1._wp / vkarmn * LOG(zustar(ji,jj) * zxsiN * zetastar * zetastar / ( ABS(ff(ji,jj)) * zhnu )) &
+                  &      + 1._wp / ( 2 * zxsiN * zetastar ) - 1._wp / vkarmn
+
+                  !! compute gammats
+                  pgt(ji,jj) = zustar(ji,jj) / (zgturb + zgmolet)
+                  pgs(ji,jj) = zustar(ji,jj) / (zgturb + zgmoles)
                END IF
-      END IF
-      !
-   END SUBROUTINE
-
-
-   SUBROUTINE sbc_isf_tbl( varin, varout, cptin )
+            END DO
+         END DO
+         CALL lbc_lnk(pgt(:,:),'T',1.)
+         CALL lbc_lnk(pgs(:,:),'T',1.)
+      END SELECT
+      CALL wrk_dealloc( jpi,jpj, zustar )
+      !
+   END SUBROUTINE sbc_isf_gammats
+
+   SUBROUTINE sbc_isf_tbl( pvarin, pvarout, cd_ptin )
       !!----------------------------------------------------------------------
       !!                  ***  SUBROUTINE sbc_isf_tbl  ***
       !!
-      !! ** Purpose : compute mean T/S/U/V in the boundary layer 
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:,:), INTENT(in) :: varin
-      REAL(wp), DIMENSION(:,:)  , INTENT(out):: varout
+      !! ** Purpose : compute mean T/S/U/V in the boundary layer at T- point
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT( in  ) :: pvarin
+      REAL(wp), DIMENSION(:,:)  , INTENT( out ) :: pvarout
+      CHARACTER(len=1),           INTENT( in  ) :: cd_ptin ! point of variable in/out
+      !
+      REAL(wp) :: ze3, zhk
+      REAL(wp), DIMENSION(:,:), POINTER :: zhisf_tbl ! thickness of the tbl
+
+      INTEGER :: ji, jj, jk                  ! loop index
+      INTEGER :: ikt, ikb                    ! top and bottom index of the tbl
+      !!----------------------------------------------------------------------
+      ! allocation
+      CALL wrk_alloc( jpi,jpj, zhisf_tbl)
       
-      CHARACTER(len=1), INTENT(in) :: cptin ! point of variable in/out
-
-      REAL(wp) :: ze3, zhk
-      REAL(wp), DIMENSION(:,:), POINTER :: zikt
-
-      INTEGER :: ji,jj,jk
-      INTEGER :: ikt,ikb
-      INTEGER, DIMENSION(:,:), POINTER :: mkt, mkb
-
-      CALL wrk_alloc( jpi,jpj, mkt, mkb  )
-      CALL wrk_alloc( jpi,jpj, zikt )
-
-      ! get first and last level of tbl
-      mkt(:,:) = misfkt(:,:)
-      mkb(:,:) = misfkb(:,:)
-
-      varout(:,:)=0._wp
-      DO jj = 2,jpj
-         DO ji = 2,jpi
-            IF (ssmask(ji,jj) == 1) THEN
-               ikt = mkt(ji,jj)
-               ikb = mkb(ji,jj)
+      ! initialisation
+      pvarout(:,:)=0._wp
+   
+      SELECT CASE ( cd_ptin )
+      CASE ( 'U' ) ! compute U in the top boundary layer at T- point 
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+               ikt = miku(ji,jj) ; ikb = miku(ji,jj)
+               ! thickness of boundary layer at least the top level thickness
+               zhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), e3u_n(ji,jj,ikt))
+
+               ! determine the deepest level influenced by the boundary layer
+               DO jk = ikt+1, mbku(ji,jj)
+                  IF ( (SUM(e3u_n(ji,jj,ikt:jk-1)) < zhisf_tbl(ji,jj)) .AND. (umask(ji,jj,jk) == 1) ) ikb = jk
+               END DO
+               zhisf_tbl(ji,jj) = MIN(zhisf_tbl(ji,jj), SUM(e3u_n(ji,jj,ikt:ikb)))  ! limit the tbl to water thickness.
 
                ! level fully include in the ice shelf boundary layer
                DO jk = ikt, ikb - 1
-                  ze3 = fse3t_n(ji,jj,jk)
-                  IF (cptin == 'T' ) varout(ji,jj) = varout(ji,jj) + varin(ji,jj,jk) * r1_hisf_tbl(ji,jj) * ze3
-                  IF (cptin == 'U' ) varout(ji,jj) = varout(ji,jj) + 0.5_wp * (varin(ji,jj,jk) + varin(ji-1,jj,jk)) &
-                     &                                                       * r1_hisf_tbl(ji,jj) * ze3
-                  IF (cptin == 'V' ) varout(ji,jj) = varout(ji,jj) + 0.5_wp * (varin(ji,jj,jk) + varin(ji,jj-1,jk)) &
-                     &                                                       * r1_hisf_tbl(ji,jj) * ze3
+                  ze3 = e3u_n(ji,jj,jk)
+                  pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,jk) / zhisf_tbl(ji,jj) * ze3
                END DO
 
                ! level partially include in ice shelf boundary layer 
-               zhk = SUM( fse3t_n(ji, jj, ikt:ikb - 1)) * r1_hisf_tbl(ji,jj)
-               IF (cptin == 'T') &
-                   &  varout(ji,jj) = varout(ji,jj) + varin(ji,jj,ikb) * (1._wp - zhk)
-               IF (cptin == 'U') &
-                   &  varout(ji,jj) = varout(ji,jj) + 0.5_wp * (varin(ji,jj,ikb) + varin(ji-1,jj,ikb)) * (1._wp - zhk)
-               IF (cptin == 'V') &
-                   &  varout(ji,jj) = varout(ji,jj) + 0.5_wp * (varin(ji,jj,ikb) + varin(ji,jj-1,ikb)) * (1._wp - zhk)
-            END IF
-         END DO
-      END DO
-
-      CALL wrk_dealloc( jpi,jpj, mkt, mkb )      
-      CALL wrk_dealloc( jpi,jpj, zikt ) 
-
-      IF (cptin == 'T') CALL lbc_lnk(varout,'T',1.)
-      IF (cptin == 'U' .OR. cptin == 'V') CALL lbc_lnk(varout,'T',-1.)
+               zhk = SUM( e3u_n(ji, jj, ikt:ikb - 1)) / zhisf_tbl(ji,jj)
+               pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,ikb) * (1._wp - zhk)
+            END DO
+         END DO
+         DO jj = 2,jpj
+            DO ji = 2,jpi
+               pvarout(ji,jj) = 0.5_wp * (pvarout(ji,jj) + pvarout(ji-1,jj))
+            END DO
+         END DO
+         CALL lbc_lnk(pvarout,'T',-1.)
+      
+      CASE ( 'V' ) ! compute V in the top boundary layer at T- point 
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+               ikt = mikv(ji,jj) ; ikb = mikv(ji,jj)
+               ! thickness of boundary layer at least the top level thickness
+               zhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), e3v_n(ji,jj,ikt))
+
+               ! determine the deepest level influenced by the boundary layer
+               DO jk = ikt+1, mbkv(ji,jj)
+                  IF ( (SUM(e3v_n(ji,jj,ikt:jk-1)) < zhisf_tbl(ji,jj)) .AND. (vmask(ji,jj,jk) == 1) ) ikb = jk
+               END DO
+               zhisf_tbl(ji,jj) = MIN(zhisf_tbl(ji,jj), SUM(e3v_n(ji,jj,ikt:ikb)))  ! limit the tbl to water thickness.
+
+               ! level fully include in the ice shelf boundary layer
+               DO jk = ikt, ikb - 1
+                  ze3 = e3v_n(ji,jj,jk)
+                  pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,jk) / zhisf_tbl(ji,jj) * ze3
+               END DO
+
+               ! level partially include in ice shelf boundary layer 
+               zhk = SUM( e3v_n(ji, jj, ikt:ikb - 1)) / zhisf_tbl(ji,jj)
+               pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,ikb) * (1._wp - zhk)
+            END DO
+         END DO
+         DO jj = 2,jpj
+            DO ji = 2,jpi
+               pvarout(ji,jj) = 0.5_wp * (pvarout(ji,jj) + pvarout(ji,jj-1))
+            END DO
+         END DO
+         CALL lbc_lnk(pvarout,'T',-1.)
+
+      CASE ( 'T' ) ! compute T in the top boundary layer at T- point 
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+               ikt = misfkt(ji,jj)
+               ikb = misfkb(ji,jj)
+
+               ! level fully include in the ice shelf boundary layer
+               DO jk = ikt, ikb - 1
+                  ze3 = e3t_n(ji,jj,jk)
+                  pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,jk) * r1_hisf_tbl(ji,jj) * ze3
+               END DO
+
+               ! level partially include in ice shelf boundary layer 
+               zhk = SUM( e3t_n(ji, jj, ikt:ikb - 1)) * r1_hisf_tbl(ji,jj)
+               pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,ikb) * (1._wp - zhk)
+            END DO
+         END DO
+      END SELECT
+
+      ! mask mean tbl value
+      pvarout(:,:) = pvarout(:,:) * ssmask(:,:)
+
+      ! deallocation
+      CALL wrk_dealloc( jpi,jpj, zhisf_tbl )      
       !
    END SUBROUTINE sbc_isf_tbl
@@ -771,16 +783,15 @@
       !! ** Action  :   phdivn   decreased by the runoff inflow
       !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   phdivn   ! horizontal divergence
-      !!
+      REAL(wp), DIMENSION(:,:,:), INTENT( inout ) ::   phdivn   ! horizontal divergence
+      ! 
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
       INTEGER  ::   ikt, ikb 
-      INTEGER  ::   nk_isf
-      REAL(wp)     ::   zhk, z1_hisf_tbl, zhisf_tbl
-      REAL(wp)     ::   zfact     ! local scalar
+      REAL(wp) ::   zhk
+      REAL(wp) ::   zfact     ! local scalar
       !!----------------------------------------------------------------------
       !
       zfact   = 0.5_wp
       !
-      IF (lk_vvl) THEN     ! need to re compute level distribution of isf fresh water
+      IF(.NOT.ln_linssh ) THEN     ! need to re compute level distribution of isf fresh water
          DO jj = 1,jpj
             DO ji = 1,jpi
@@ -788,21 +799,21 @@
                ikb = misfkt(ji,jj)
                ! thickness of boundary layer at least the top level thickness
-               rhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), fse3t(ji,jj,ikt))
+               rhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), e3t_n(ji,jj,ikt))
 
                ! determine the deepest level influenced by the boundary layer
-               ! test on tmask useless ?????
                DO jk = ikt, mbkt(ji,jj)
-                  IF ( (SUM(fse3t(ji,jj,ikt:jk-1)) .LT. rhisf_tbl(ji,jj)) .AND. (tmask(ji,jj,jk) == 1) ) ikb = jk
-               END DO
-               rhisf_tbl(ji,jj) = MIN(rhisf_tbl(ji,jj), SUM(fse3t(ji,jj,ikt:ikb)))  ! limit the tbl to water thickness.
+                  IF ( (SUM(e3t_n(ji,jj,ikt:jk-1)) .LT. rhisf_tbl(ji,jj)) .AND. (tmask(ji,jj,jk) == 1) ) ikb = jk
+               END DO
+               rhisf_tbl(ji,jj) = MIN(rhisf_tbl(ji,jj), SUM(e3t_n(ji,jj,ikt:ikb)))  ! limit the tbl to water thickness.
                misfkb(ji,jj) = ikb                                                  ! last wet level of the tbl
                r1_hisf_tbl(ji,jj) = 1._wp / rhisf_tbl(ji,jj)
 
-               zhk           = SUM( fse3t(ji, jj, ikt:ikb - 1)) * r1_hisf_tbl(ji,jj)  ! proportion of tbl cover by cell from ikt to ikb - 1
-               ralpha(ji,jj) = rhisf_tbl(ji,jj) * (1._wp - zhk ) / fse3t(ji,jj,ikb)  ! proportion of bottom cell influenced by boundary layer
-            END DO
-         END DO
-      END IF ! vvl case
-      !
+               zhk           = SUM( e3t_n(ji, jj, ikt:ikb - 1)) * r1_hisf_tbl(ji,jj)  ! proportion of tbl cover by cell from ikt to ikb - 1
+               ralpha(ji,jj) = rhisf_tbl(ji,jj) * (1._wp - zhk ) / e3t_n(ji,jj,ikb)  ! proportion of bottom cell influenced by boundary layer
+            END DO
+         END DO
+      END IF 
+      !
+      !==   ice shelf melting distributed over several levels   ==!
       DO jj = 1,jpj
          DO ji = 1,jpi
@@ -812,91 +823,13 @@
                DO jk = ikt, ikb - 1
                   phdivn(ji,jj,jk) = phdivn(ji,jj,jk) + ( fwfisf(ji,jj) + fwfisf_b(ji,jj) ) &
-                    &               * r1_hisf_tbl(ji,jj) * r1_rau0 * zfact
+                    &              * r1_hisf_tbl(ji,jj) * r1_rau0 * zfact
                END DO
                ! level partially include in ice shelf boundary layer 
                phdivn(ji,jj,ikb) = phdivn(ji,jj,ikb) + ( fwfisf(ji,jj) &
-                  &             + fwfisf_b(ji,jj) ) * r1_hisf_tbl(ji,jj) * r1_rau0 * zfact * ralpha(ji,jj) 
-            !==   ice shelf melting mass distributed over several levels   ==!
+                    &            + fwfisf_b(ji,jj) ) * r1_hisf_tbl(ji,jj) * r1_rau0 * zfact * ralpha(ji,jj) 
          END DO
       END DO
       !
    END SUBROUTINE sbc_isf_div
-
-
-   FUNCTION tinsitu( ptem, psal, ppress ) RESULT( pti )
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE eos_init  ***
-      !!
-      !! ** Purpose :   Compute the in-situ temperature [Celcius]
-      !!
-      !! ** Method  :   
-      !!
-      !! Reference  :   Bryden,h.,1973,deep-sea res.,20,401-408
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   ptem   ! potential temperature [Celcius]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   psal   ! salinity             [psu]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   ppress ! pressure             [dBar]
-      REAL(wp), DIMENSION(:,:), POINTER           ::   pti    ! in-situ temperature [Celcius]
-!      REAL(wp) :: fsatg
-!      REAL(wp) :: pfps, pfpt, pfphp 
-      REAL(wp) :: zt, zs, zp, zh, zq, zxk
-      INTEGER  :: ji, jj            ! dummy loop indices
-      !
-      CALL wrk_alloc( jpi,jpj, pti  )
-      ! 
-      DO jj=1,jpj
-         DO ji=1,jpi
-            zh = ppress(ji,jj)
-! Theta1
-            zt = ptem(ji,jj)
-            zs = psal(ji,jj)
-            zp = 0.0
-            zxk= zh * fsatg( zs, zt, zp )
-            zt = zt + 0.5 * zxk
-            zq = zxk
-! Theta2
-            zp = zp + 0.5 * zh
-            zxk= zh*fsatg( zs, zt, zp )
-            zt = zt + 0.29289322 * ( zxk - zq )
-            zq = 0.58578644 * zxk + 0.121320344 * zq
-! Theta3
-            zxk= zh * fsatg( zs, zt, zp )
-            zt = zt + 1.707106781 * ( zxk - zq )
-            zq = 3.414213562 * zxk - 4.121320344 * zq
-! Theta4
-            zp = zp + 0.5 * zh
-            zxk= zh * fsatg( zs, zt, zp )
-            pti(ji,jj) = zt + ( zxk - 2.0 * zq ) / 6.0
-         END DO
-      END DO
-      !
-      CALL wrk_dealloc( jpi,jpj, pti  )
-      !
-   END FUNCTION tinsitu
-
-
-   FUNCTION fsatg( pfps, pfpt, pfphp )
-      !!----------------------------------------------------------------------
-      !!                 ***  FUNCTION fsatg  ***
-      !!
-      !! ** Purpose    :   Compute the Adiabatic laspse rate [Celcius].[decibar]^-1
-      !!
-      !! ** Reference  :   Bryden,h.,1973,deep-sea res.,20,401-408
-      !! 
-      !! ** units      :   pressure        pfphp    decibars
-      !!                   temperature     pfpt     deg celsius (ipts-68)
-      !!                   salinity        pfps     (ipss-78)
-      !!                   adiabatic       fsatg    deg. c/decibar
-      !!----------------------------------------------------------------------
-      REAL(wp) :: pfps, pfpt, pfphp 
-      REAL(wp) :: fsatg
-      !
-      fsatg = (((-2.1687e-16*pfpt+1.8676e-14)*pfpt-4.6206e-13)*pfphp         &
-        &    +((2.7759e-12*pfpt-1.1351e-10)*(pfps-35.)+((-5.4481e-14*pfpt    &
-        &    +8.733e-12)*pfpt-6.7795e-10)*pfpt+1.8741e-8))*pfphp             &
-        &    +(-4.2393e-8*pfpt+1.8932e-6)*(pfps-35.)                         &
-        &    +((6.6228e-10*pfpt-6.836e-8)*pfpt+8.5258e-6)*pfpt+3.5803e-5
-      !
-    END FUNCTION fsatg
-    !!======================================================================
+   !!======================================================================
 END MODULE sbcisf
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 6140)
@@ -17,40 +17,44 @@
 
    !!----------------------------------------------------------------------
-   !!   sbc_init       : read namsbc namelist
-   !!   sbc            : surface ocean momentum, heat and freshwater boundary conditions
+   !!   sbc_init      : read namsbc namelist
+   !!   sbc           : surface ocean momentum, heat and freshwater boundary conditions
    !!----------------------------------------------------------------------
-   USE oce              ! ocean dynamics and tracers
-   USE dom_oce          ! ocean space and time domain
-   USE phycst           ! physical constants
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE trc_oce          ! shared ocean-passive tracers variables
-   USE sbc_ice          ! Surface boundary condition: ice fields
-   USE sbcdcy           ! surface boundary condition: diurnal cycle
-   USE sbcssm           ! surface boundary condition: sea-surface mean variables
-   USE sbcana           ! surface boundary condition: analytical formulation
-   USE sbcflx           ! surface boundary condition: flux formulation
-   USE sbcblk_clio      ! surface boundary condition: bulk formulation : CLIO
-   USE sbcblk_core      ! surface boundary condition: bulk formulation : CORE
-   USE sbcblk_mfs       ! surface boundary condition: bulk formulation : MFS
-   USE sbcice_if        ! surface boundary condition: ice-if sea-ice model
-   USE sbcice_lim       ! surface boundary condition: LIM 3.0 sea-ice model
-   USE sbcice_lim_2     ! surface boundary condition: LIM 2.0 sea-ice model
-   USE sbcice_cice      ! surface boundary condition: CICE    sea-ice model
-   USE sbccpl           ! surface boundary condition: coupled florulation
-   USE cpl_oasis3       ! OASIS routines for coupling
-   USE sbcssr           ! surface boundary condition: sea surface restoring
-   USE sbcrnf           ! surface boundary condition: runoffs
-   USE sbcisf           ! surface boundary condition: ice shelf
-   USE sbcfwb           ! surface boundary condition: freshwater budget
-   USE closea           ! closed sea
-   USE icbstp           ! Icebergs!
-
-   USE prtctl           ! Print control                    (prt_ctl routine)
-   USE iom              ! IOM library
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE timing           ! Timing
-   USE sbcwave          ! Wave module
-   USE bdy_par          ! Require lk_bdy
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE trc_oce        ! shared ocean-passive tracers variables
+   USE sbc_ice        ! Surface boundary condition: ice fields
+   USE sbcdcy         ! surface boundary condition: diurnal cycle
+   USE sbcssm         ! surface boundary condition: sea-surface mean variables
+   USE sbcana         ! surface boundary condition: analytical formulation
+   USE sbcflx         ! surface boundary condition: flux formulation
+   USE sbcblk_clio    ! surface boundary condition: bulk formulation : CLIO
+   USE sbcblk_core    ! surface boundary condition: bulk formulation : CORE
+   USE sbcblk_mfs     ! surface boundary condition: bulk formulation : MFS
+   USE sbcice_if      ! surface boundary condition: ice-if sea-ice model
+   USE sbcice_lim     ! surface boundary condition: LIM 3.0 sea-ice model
+   USE sbcice_lim_2   ! surface boundary condition: LIM 2.0 sea-ice model
+   USE sbcice_cice    ! surface boundary condition: CICE    sea-ice model
+   USE sbccpl         ! surface boundary condition: coupled florulation
+   USE cpl_oasis3     ! OASIS routines for coupling
+   USE sbcssr         ! surface boundary condition: sea surface restoring
+   USE sbcrnf         ! surface boundary condition: runoffs
+   USE sbcisf         ! surface boundary condition: ice shelf
+   USE sbcfwb         ! surface boundary condition: freshwater budget
+   USE closea         ! closed sea
+   USE icbstp         ! Icebergs
+   USE traqsr         ! active tracers: light penetration
+   USE sbcwave        ! Wave module
+   USE bdy_par        ! Require lk_bdy
+   !
+   USE prtctl         ! Print control                    (prt_ctl routine)
+   USE iom            ! IOM library
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE timing         ! Timing
+
+   USE diurnal_bulk, ONLY: &
+      & ln_diurnal_only 
 
    IMPLICIT NONE
@@ -62,6 +66,4 @@
    INTEGER ::   nsbc   ! type of surface boundary condition (deduced from namsbc informations)
       
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 4.0 , NEMO-consortium (2011) 
@@ -85,13 +87,16 @@
       INTEGER ::   icpt   ! local integer
       !!
-      NAMELIST/namsbc/ nn_fsbc   , ln_ana    , ln_flx, ln_blk_clio, ln_blk_core, ln_mixcpl,   &
-         &             ln_blk_mfs, ln_apr_dyn, nn_ice, nn_ice_embd, ln_dm2dc   , ln_rnf   ,   &
-         &             ln_ssr    , nn_isf    , nn_fwb, ln_cdgw    , ln_wave    , ln_sdw   ,   &
-         &             nn_lsm    , nn_limflx , nn_components, ln_cpl
+      NAMELIST/namsbc/ nn_fsbc  , ln_ana   , ln_flx, ln_blk_clio, ln_blk_core, ln_blk_mfs,   &
+         &             ln_cpl   , ln_mixcpl, nn_components      , nn_limflx  ,               &
+         &             ln_traqsr, ln_dm2dc ,                                                 &  
+         &             nn_ice   , nn_ice_embd,                                               &
+         &             ln_rnf   , ln_ssr   , ln_isf   , nn_fwb    , ln_apr_dyn,              &
+         &             ln_wave  ,                                                            &
+         &             nn_lsm   
       INTEGER  ::   ios
       INTEGER  ::   ierr, ierr0, ierr1, ierr2, ierr3, jpm
       LOGICAL  ::   ll_purecpl
       !!----------------------------------------------------------------------
-
+      !
       IF(lwp) THEN
          WRITE(numout,*)
@@ -99,14 +104,14 @@
          WRITE(numout,*) '~~~~~~~~ '
       ENDIF
-
+      !
       REWIND( numnam_ref )              ! Namelist namsbc in reference namelist : Surface boundary
       READ  ( numnam_ref, namsbc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc in reference namelist', lwp )
-
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc in reference namelist', lwp )
+      !
       REWIND( numnam_cfg )              ! Namelist namsbc in configuration namelist : Parameters of the run
       READ  ( numnam_cfg, namsbc, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc in configuration namelist', lwp )
-      IF(lwm) WRITE ( numond, namsbc )
-
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc in configuration namelist', lwp )
+      IF(lwm) WRITE( numond, namsbc )
+      !
       !                          ! overwrite namelist parameter using CPP key information
       IF( Agrif_Root() ) THEN                ! AGRIF zoom
@@ -119,52 +124,54 @@
           nn_ice      =   0
       ENDIF
-
+      !
       IF(lwp) THEN               ! Control print
          WRITE(numout,*) '        Namelist namsbc (partly overwritten with CPP key setting)'
          WRITE(numout,*) '           frequency update of sbc (and ice)             nn_fsbc     = ', nn_fsbc
-         WRITE(numout,*) '           Type of sbc : '
-         WRITE(numout,*) '              analytical formulation                     ln_ana      = ', ln_ana
-         WRITE(numout,*) '              flux       formulation                     ln_flx      = ', ln_flx
-         WRITE(numout,*) '              CLIO bulk  formulation                     ln_blk_clio = ', ln_blk_clio
-         WRITE(numout,*) '              CORE bulk  formulation                     ln_blk_core = ', ln_blk_core
-         WRITE(numout,*) '              MFS  bulk  formulation                     ln_blk_mfs  = ', ln_blk_mfs
-         WRITE(numout,*) '              ocean-atmosphere coupled formulation       ln_cpl      = ', ln_cpl
-         WRITE(numout,*) '              forced-coupled mixed formulation           ln_mixcpl   = ', ln_mixcpl
-         WRITE(numout,*) '              OASIS coupling (with atm or sas)           lk_oasis    = ', lk_oasis
-         WRITE(numout,*) '              components of your executable            nn_components = ', nn_components
-         WRITE(numout,*) '              Multicategory heat flux formulation (LIM3) nn_limflx   = ', nn_limflx
+         WRITE(numout,*) '           Type of air-sea fluxes : '
+         WRITE(numout,*) '              analytical formulation                     ln_ana        = ', ln_ana
+         WRITE(numout,*) '              flux       formulation                     ln_flx        = ', ln_flx
+         WRITE(numout,*) '              CLIO bulk  formulation                     ln_blk_clio   = ', ln_blk_clio
+         WRITE(numout,*) '              CORE bulk  formulation                     ln_blk_core   = ', ln_blk_core
+         WRITE(numout,*) '              MFS  bulk  formulation                     ln_blk_mfs    = ', ln_blk_mfs
+         WRITE(numout,*) '           Type of coupling (Ocean/Ice/Atmosphere) : '
+         WRITE(numout,*) '              ocean-atmosphere coupled formulation       ln_cpl        = ', ln_cpl
+         WRITE(numout,*) '              forced-coupled mixed formulation           ln_mixcpl     = ', ln_mixcpl
+         WRITE(numout,*) '              OASIS coupling (with atm or sas)           lk_oasis      = ', lk_oasis
+         WRITE(numout,*) '              components of your executable              nn_components = ', nn_components
+         WRITE(numout,*) '              Multicategory heat flux formulation (LIM3) nn_limflx     = ', nn_limflx
+         WRITE(numout,*) '           Sea-ice : '
+         WRITE(numout,*) '              ice management in the sbc (=0/1/2/3)       nn_ice        = ', nn_ice 
+         WRITE(numout,*) '              ice-ocean embedded/levitating (=0/1/2)     nn_ice_embd   = ', nn_ice_embd
          WRITE(numout,*) '           Misc. options of sbc : '
-         WRITE(numout,*) '              Patm gradient added in ocean & ice Eqs.    ln_apr_dyn  = ', ln_apr_dyn
-         WRITE(numout,*) '              ice management in the sbc (=0/1/2/3)       nn_ice      = ', nn_ice 
-         WRITE(numout,*) '              ice-ocean embedded/levitating (=0/1/2)     nn_ice_embd = ', nn_ice_embd
-         WRITE(numout,*) '              daily mean to diurnal cycle qsr            ln_dm2dc    = ', ln_dm2dc 
-         WRITE(numout,*) '              runoff / runoff mouths                     ln_rnf      = ', ln_rnf
-         WRITE(numout,*) '              iceshelf formulation                       nn_isf      = ', nn_isf
-         WRITE(numout,*) '              Sea Surface Restoring on SST and/or SSS    ln_ssr      = ', ln_ssr
-         WRITE(numout,*) '              FreshWater Budget control  (=0/1/2)        nn_fwb      = ', nn_fwb
-         WRITE(numout,*) '              closed sea (=0/1) (set in namdom)          nn_closea   = ', nn_closea
-         WRITE(numout,*) '              n. of iterations if land-sea-mask applied  nn_lsm      = ', nn_lsm
-      ENDIF
-
-      ! LIM3 Multi-category heat flux formulation
-      SELECT CASE ( nn_limflx)
-      CASE ( -1 )
-         IF(lwp) WRITE(numout,*) '              Use of per-category fluxes (nn_limflx = -1) '
-      CASE ( 0  )
-         IF(lwp) WRITE(numout,*) '              Average per-category fluxes (nn_limflx = 0) ' 
-      CASE ( 1  )
-         IF(lwp) WRITE(numout,*) '              Average then redistribute per-category fluxes (nn_limflx = 1) '
-      CASE ( 2  )
-         IF(lwp) WRITE(numout,*) '              Redistribute a single flux over categories (nn_limflx = 2) '
-      END SELECT
-      !
-      IF ( nn_components /= jp_iam_nemo .AND. .NOT. lk_oasis )   &
-         &      CALL ctl_stop( 'STOP', 'sbc_init : OPA-SAS coupled via OASIS, but key_oasis3 disabled' )
-      IF ( nn_components == jp_iam_opa .AND. ln_cpl )   &
-         &      CALL ctl_stop( 'STOP', 'sbc_init : OPA-SAS coupled via OASIS, but ln_cpl = T in OPA' )
-      IF ( nn_components == jp_iam_opa .AND. ln_mixcpl )   &
-         &      CALL ctl_stop( 'STOP', 'sbc_init : OPA-SAS coupled via OASIS, but ln_mixcpl = T in OPA' )
-      IF ( ln_cpl .AND. .NOT. lk_oasis )    &
-         &      CALL ctl_stop( 'STOP', 'sbc_init : OASIS-coupled atmosphere model, but key_oasis3 disabled' )
+         WRITE(numout,*) '              Light penetration in temperature Eq.       ln_traqsr     = ', ln_traqsr
+         WRITE(numout,*) '                 daily mean to diurnal cycle qsr            ln_dm2dc   = ', ln_dm2dc 
+         WRITE(numout,*) '              Sea Surface Restoring on SST and/or SSS    ln_ssr        = ', ln_ssr
+         WRITE(numout,*) '              FreshWater Budget control  (=0/1/2)        nn_fwb        = ', nn_fwb
+         WRITE(numout,*) '              Patm gradient added in ocean & ice Eqs.    ln_apr_dyn    = ', ln_apr_dyn
+         WRITE(numout,*) '              runoff / runoff mouths                     ln_rnf        = ', ln_rnf
+         WRITE(numout,*) '              iceshelf formulation                       ln_isf        = ', ln_isf
+         WRITE(numout,*) '              closed sea (=0/1) (set in namdom)          nn_closea     = ', nn_closea
+         WRITE(numout,*) '              nb of iterations if land-sea-mask applied  nn_lsm        = ', nn_lsm
+         WRITE(numout,*) '              surface wave                               ln_wave       = ', ln_wave  
+      ENDIF
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         SELECT CASE ( nn_limflx )        ! LIM3 Multi-category heat flux formulation
+         CASE ( -1 )   ;   WRITE(numout,*) '   LIM3: use per-category fluxes (nn_limflx = -1) '
+         CASE ( 0  )   ;   WRITE(numout,*) '   LIM3: use average per-category fluxes (nn_limflx = 0) ' 
+         CASE ( 1  )   ;   WRITE(numout,*) '   LIM3: use average then redistribute per-category fluxes (nn_limflx = 1) '
+         CASE ( 2  )   ;   WRITE(numout,*) '   LIM3: Redistribute a single flux over categories (nn_limflx = 2) '
+         END SELECT
+      ENDIF
+      !
+      IF( nn_components /= jp_iam_nemo .AND. .NOT. lk_oasis )   &
+         &      CALL ctl_stop( 'sbc_init : OPA-SAS coupled via OASIS, but key_oasis3 disabled' )
+      IF( nn_components == jp_iam_opa .AND. ln_cpl )   &
+         &      CALL ctl_stop( 'sbc_init : OPA-SAS coupled via OASIS, but ln_cpl = T in OPA' )
+      IF( nn_components == jp_iam_opa .AND. ln_mixcpl )   &
+         &      CALL ctl_stop( 'sbc_init : OPA-SAS coupled via OASIS, but ln_mixcpl = T in OPA' )
+      IF( ln_cpl .AND. .NOT. lk_oasis )    &
+         &      CALL ctl_stop( 'sbc_init : OASIS-coupled atmosphere model, but key_oasis3 disabled' )
       IF( ln_mixcpl .AND. .NOT. lk_oasis )    &
          &      CALL ctl_stop( 'the forced-coupled mixed mode (ln_mixcpl) requires the cpp key key_oasis3' )
@@ -178,18 +185,17 @@
 
       !                          ! Checks:
-      IF( nn_isf .EQ. 0 ) THEN                      ! variable initialisation if no ice shelf 
-         IF( sbc_isf_alloc() /= 0 )   CALL ctl_stop( 'sbc_init : unable to allocate sbc_isf arrays' )
+      IF( .NOT. ln_isf ) THEN                      ! variable initialisation if no ice shelf 
+         IF( sbc_isf_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sbc_init : unable to allocate sbc_isf arrays' )
          fwfisf  (:,:)   = 0.0_wp ; fwfisf_b  (:,:)   = 0.0_wp
          risf_tsc(:,:,:) = 0.0_wp ; risf_tsc_b(:,:,:) = 0.0_wp
-         rdivisf       = 0.0_wp
       END IF
-      IF( nn_ice == 0 .AND. nn_components /= jp_iam_opa )   fr_i(:,:) = 0.e0 ! no ice in the domain, ice fraction is always zero
-
-      sfx(:,:) = 0.0_wp                            ! the salt flux due to freezing/melting will be computed (i.e. will be non-zero) 
+      IF( nn_ice == 0 .AND. nn_components /= jp_iam_opa )   fr_i(:,:) = 0._wp    ! no ice in the domain, ice fraction is always zero
+
+      sfx(:,:) = 0._wp                             ! the salt flux due to freezing/melting will be computed (i.e. will be non-zero) 
                                                    ! only if sea-ice is present
  
-      fmmflx(:,:) = 0.0_wp                        ! freezing-melting array initialisation
+      fmmflx(:,:) = 0._wp                          ! freezing-melting array initialisation
       
-      taum(:,:) = 0.0_wp                           ! Initialise taum for use in gls in case of reduced restart
+      taum(:,:) = 0._wp                            ! Initialise taum for use in gls in case of reduced restart
 
       !                                            ! restartability   
@@ -214,17 +220,4 @@
          &   CALL ctl_stop( 'diurnal cycle into qsr field from daily values requires a flux or core-bulk formulation' )
       
-      IF ( ln_wave ) THEN
-      !Activated wave module but neither drag nor stokes drift activated
-         IF ( .NOT.(ln_cdgw .OR. ln_sdw) )   THEN
-            CALL ctl_warn( 'Ask for wave coupling but nor drag coefficient (ln_cdgw=F) neither stokes drift activated (ln_sdw=F)' )
-      !drag coefficient read from wave model definable only with mfs bulk formulae and core 
-         ELSEIF (ln_cdgw .AND. .NOT.(ln_blk_mfs .OR. ln_blk_core) )       THEN       
-             CALL ctl_stop( 'drag coefficient read from wave model definable only with mfs bulk formulae and core')
-         ENDIF
-      ELSE
-      IF ( ln_cdgw .OR. ln_sdw  )                                                           & 
-         &   CALL ctl_stop( 'Not Activated Wave Module (ln_wave=F) but asked coupling ',    &
-         &                  'with drag coefficient (ln_cdgw =T) or Stokes drift (ln_sdw=T) ')
-      ENDIF 
       !                          ! Choice of the Surface Boudary Condition (set nsbc)
       ll_purecpl = ln_cpl .AND. .NOT. ln_mixcpl
@@ -245,25 +238,26 @@
       IF(lwp) THEN
          WRITE(numout,*)
-         IF( nsbc == jp_gyre    )   WRITE(numout,*) '              GYRE analytical formulation'
-         IF( nsbc == jp_ana     )   WRITE(numout,*) '              analytical formulation'
-         IF( nsbc == jp_flx     )   WRITE(numout,*) '              flux formulation'
-         IF( nsbc == jp_clio    )   WRITE(numout,*) '              CLIO bulk formulation'
-         IF( nsbc == jp_core    )   WRITE(numout,*) '              CORE bulk formulation'
-         IF( nsbc == jp_purecpl )   WRITE(numout,*) '              pure coupled formulation'
-         IF( nsbc == jp_mfs     )   WRITE(numout,*) '              MFS Bulk formulation'
-         IF( nsbc == jp_none    )   WRITE(numout,*) '              OPA coupled to SAS via oasis'
-         IF( ln_mixcpl          )   WRITE(numout,*) '              + forced-coupled mixed formulation'
+         SELECT CASE( nsbc )
+         CASE( jp_gyre    )   ;   WRITE(numout,*) '   GYRE analytical formulation'
+         CASE( jp_ana     )   ;   WRITE(numout,*) '   analytical formulation'
+         CASE( jp_flx     )   ;   WRITE(numout,*) '   flux formulation'
+         CASE( jp_clio    )   ;   WRITE(numout,*) '   CLIO bulk formulation'
+         CASE( jp_core    )   ;   WRITE(numout,*) '   CORE bulk formulation'
+         CASE( jp_purecpl )   ;   WRITE(numout,*) '   pure coupled formulation'
+         CASE( jp_mfs     )   ;   WRITE(numout,*) '   MFS Bulk formulation'
+         CASE( jp_none    )   ;   WRITE(numout,*) '   OPA coupled to SAS via oasis'
+            IF( ln_mixcpl )       WRITE(numout,*) '       + forced-coupled mixed formulation'
+         END SELECT
          IF( nn_components/= jp_iam_nemo )  &
-            &                       WRITE(numout,*) '              + OASIS coupled SAS'
+            &                     WRITE(numout,*) '       + OASIS coupled SAS'
       ENDIF
       !
       IF( lk_oasis )   CALL sbc_cpl_init (nn_ice)   ! OASIS initialisation. must be done before: (1) first time step
       !                                             !                                            (2) the use of nn_fsbc
-
-!     nn_fsbc initialization if OPA-SAS coupling via OASIS
-!     sas model time step has to be declared in OASIS (mandatory) -> nn_fsbc has to be modified accordingly
-      IF ( nn_components /= jp_iam_nemo ) THEN
-         IF ( nn_components == jp_iam_opa ) nn_fsbc = cpl_freq('O_SFLX') / NINT(rdt)
-         IF ( nn_components == jp_iam_sas ) nn_fsbc = cpl_freq('I_SFLX') / NINT(rdt)
+      !     nn_fsbc initialization if OPA-SAS coupling via OASIS
+      !     sas model time step has to be declared in OASIS (mandatory) -> nn_fsbc has to be modified accordingly
+      IF( nn_components /= jp_iam_nemo ) THEN
+         IF( nn_components == jp_iam_opa )   nn_fsbc = cpl_freq('O_SFLX') / NINT(rdt)
+         IF( nn_components == jp_iam_sas )   nn_fsbc = cpl_freq('I_SFLX') / NINT(rdt)
          !
          IF(lwp)THEN
@@ -273,5 +267,5 @@
          ENDIF
       ENDIF
-
+      !
       IF( MOD( nitend - nit000 + 1, nn_fsbc) /= 0 .OR.   &
           MOD( nstock             , nn_fsbc) /= 0 ) THEN 
@@ -286,15 +280,15 @@
       IF( ln_dm2dc .AND. ( ( NINT(rday) / ( nn_fsbc * NINT(rdt) ) )  < 8 ) )   &
          &   CALL ctl_warn( 'diurnal cycle for qsr: the sampling of the diurnal cycle is too small...' )
-
-                               CALL sbc_ssm_init               ! Sea-surface mean fields initialisation
-      !
-      IF( ln_ssr           )   CALL sbc_ssr_init               ! Sea-Surface Restoring initialisation
-      !
-                               CALL sbc_rnf_init               ! Runof initialisation
-      !
-      IF( nn_ice == 3      )   CALL sbc_lim_init               ! LIM3 initialisation
-
-      IF( nn_ice == 4      )   CALL cice_sbc_init( nsbc )      ! CICE initialisation
-      
+      !
+                          CALL sbc_ssm_init               ! Sea-surface mean fields initialisation
+      !
+      IF( ln_ssr      )   CALL sbc_ssr_init               ! Sea-Surface Restoring initialisation
+      !
+                          CALL sbc_rnf_init               ! Runof initialisation
+      !
+      IF( nn_ice == 3 )   CALL sbc_lim_init               ! LIM3 initialisation
+      !
+      IF( nn_ice == 4 )   CALL cice_sbc_init( nsbc )      ! CICE initialisation
+      !
    END SUBROUTINE sbc_init
 
@@ -327,8 +321,6 @@
          vtau_b(:,:) = vtau(:,:)                         ! (except at nit000 where before fields
          qns_b (:,:) = qns (:,:)                         !  are set at the end of the routine)
-         ! The 3D heat content due to qsr forcing is treated in traqsr
-         ! qsr_b (:,:) = qsr (:,:)
-         emp_b(:,:) = emp(:,:)
-         sfx_b(:,:) = sfx(:,:)
+         emp_b (:,:) = emp (:,:)
+         sfx_b (:,:) = sfx (:,:)
       ENDIF
       !                                            ! ---------------------------------------- !
@@ -336,8 +328,9 @@
       !                                            ! ---------------------------------------- !
       !
-      IF( nn_components /= jp_iam_sas )   CALL sbc_ssm( kt )   ! ocean sea surface variables (sst_m, sss_m, ssu_m, ssv_m)
+      IF( nn_components /= jp_iam_sas )   CALL sbc_ssm ( kt )  ! ocean sea surface variables (sst_m, sss_m, ssu_m, ssv_m)
       !                                                        ! averaged over nf_sbc time-step
-
-      IF (ln_wave) CALL sbc_wave( kt )
+      IF( ln_wave                     )   CALL sbc_wave( kt )  ! surface waves
+      
+      
                                                    !==  sbc formulation  ==!
                                                             
@@ -357,13 +350,13 @@
       CASE( jp_mfs   )   ;   CALL sbc_blk_mfs ( kt )                    ! bulk formulation : MFS for the ocean
       CASE( jp_none  ) 
-         IF( nn_components == jp_iam_opa ) &
-                             CALL sbc_cpl_rcv ( kt, nn_fsbc, nn_ice )   ! OPA-SAS coupling: OPA receiving fields from SAS
+         IF( nn_components == jp_iam_opa )   &
+            &                CALL sbc_cpl_rcv ( kt, nn_fsbc, nn_ice )   ! OPA-SAS coupling: OPA receiving fields from SAS
       END SELECT
 
       IF( ln_mixcpl )        CALL sbc_cpl_rcv ( kt, nn_fsbc, nn_ice )   ! forced-coupled mixed formulation after forcing
 
-
+      !
       !                                            !==  Misc. Options  ==!
-      
+      !
       SELECT CASE( nn_ice )                                       ! Update heat and freshwater fluxes over sea-ice areas
       CASE(  1 )   ;         CALL sbc_ice_if   ( kt )                ! Ice-cover climatology ("Ice-if" model)
@@ -375,5 +368,5 @@
       IF( ln_icebergs    )   CALL icb_stp( kt )                   ! compute icebergs
 
-      IF( nn_isf   /= 0  )   CALL sbc_isf( kt )                    ! compute iceshelves
+      IF( ln_isf         )   CALL sbc_isf( kt )                   ! compute iceshelves
 
       IF( ln_rnf         )   CALL sbc_rnf( kt )                   ! add runoffs to fresh water fluxes
@@ -383,6 +376,9 @@
       IF( nn_fwb    /= 0 )   CALL sbc_fwb( kt, nn_fwb, nn_fsbc )  ! control the freshwater budget
 
-      IF( nn_closea == 1 )   CALL sbc_clo( kt )                   ! treatment of closed sea in the model domain 
-      !                                                           ! (update freshwater fluxes)
+      ! treatment of closed sea in the model domain 
+      ! (update freshwater fluxes)
+      ! Should not be ran if ln_diurnal_only
+      IF( .NOT.(ln_diurnal_only) .AND. (nn_closea == 1) )   CALL sbc_clo( kt )   
+
 !RBbug do not understand why see ticket 667
 !clem: it looks like it is necessary for the north fold (in certain circumstances). Don't know why.
@@ -430,5 +426,4 @@
          CALL iom_rstput( kt, nitrst, numrow, 'sfx_b'  , sfx  )
       ENDIF
-
       !                                                ! ---------------------------------------- !
       !                                                !        Outputs and control print         !
@@ -452,7 +447,7 @@
       !
       IF(ln_ctl) THEN         ! print mean trends (used for debugging)
-         CALL prt_ctl(tab2d_1=fr_i              , clinfo1=' fr_i     - : ', mask1=tmask, ovlap=1 )
-         CALL prt_ctl(tab2d_1=(emp-rnf + fwfisf), clinfo1=' emp-rnf  - : ', mask1=tmask, ovlap=1 )
-         CALL prt_ctl(tab2d_1=(sfx-rnf + fwfisf), clinfo1=' sfx-rnf  - : ', mask1=tmask, ovlap=1 )
+         CALL prt_ctl(tab2d_1=fr_i              , clinfo1=' fr_i    - : ', mask1=tmask, ovlap=1 )
+         CALL prt_ctl(tab2d_1=(emp-rnf + fwfisf), clinfo1=' emp-rnf - : ', mask1=tmask, ovlap=1 )
+         CALL prt_ctl(tab2d_1=(sfx-rnf + fwfisf), clinfo1=' sfx-rnf - : ', mask1=tmask, ovlap=1 )
          CALL prt_ctl(tab2d_1=qns              , clinfo1=' qns      - : ', mask1=tmask, ovlap=1 )
          CALL prt_ctl(tab2d_1=qsr              , clinfo1=' qsr      - : ', mask1=tmask, ovlap=1 )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90	(revision 6140)
@@ -12,50 +12,51 @@
 
    !!----------------------------------------------------------------------
-   !!   sbc_rnf      : monthly runoffs read in a NetCDF file
-   !!   sbc_rnf_init : runoffs initialisation
-   !!   rnf_mouth    : set river mouth mask
+   !!   sbc_rnf       : monthly runoffs read in a NetCDF file
+   !!   sbc_rnf_init  : runoffs initialisation
+   !!   rnf_mouth     : set river mouth mask
    !!----------------------------------------------------------------------
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE sbc_oce         ! surface boundary condition variables
-   USE sbcisf          ! PM we could remove it I think
-   USE closea          ! closed seas
-   USE fldread         ! read input field at current time step
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O module
-   USE lib_mpp         ! MPP library
-   USE eosbn2
-   USE wrk_nemo        ! Memory allocation
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE sbc_oce        ! surface boundary condition variables
+   USE sbcisf         ! PM we could remove it I think
+   USE closea         ! closed seas
+   USE eosbn2         ! Equation Of State
+   !
+   USE in_out_manager ! I/O manager
+   USE fldread        ! read input field at current time step
+   USE iom            ! I/O module
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory allocation
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   sbc_rnf       ! routine called in sbcmod module
-   PUBLIC   sbc_rnf_div   ! routine called in divhor module
-   PUBLIC   sbc_rnf_alloc ! routine called in sbcmod module
-   PUBLIC   sbc_rnf_init  ! routine called in sbcmod module
+   PUBLIC   sbc_rnf       ! called in sbcmod module
+   PUBLIC   sbc_rnf_div   ! called in divhor module
+   PUBLIC   sbc_rnf_alloc ! called in sbcmod module
+   PUBLIC   sbc_rnf_init  ! called in sbcmod module
    
-   !                                                     !!* namsbc_rnf namelist *
-   CHARACTER(len=100)         ::   cn_dir          !: Root directory for location of rnf files
+   !                                                !!* namsbc_rnf namelist *
+   CHARACTER(len=100)         ::   cn_dir            !: Root directory for location of rnf files
    LOGICAL                    ::   ln_rnf_depth      !: depth       river runoffs attribute specified in a file
-   LOGICAL                    ::   ln_rnf_depth_ini  !: depth       river runoffs  computed at the initialisation
-   REAL(wp)                   ::   rn_rnf_max        !: maximum value of the runoff climatologie ( ln_rnf_depth_ini = .true )
-   REAL(wp)                   ::   rn_dep_max        !: depth over which runoffs is spread ( ln_rnf_depth_ini = .true )
-   INTEGER                    ::   nn_rnf_depth_file !: create (=1) a runoff depth file or not (=0)
-   LOGICAL                    ::   ln_rnf_tem      !: temperature river runoffs attribute specified in a file
-   LOGICAL           , PUBLIC ::   ln_rnf_sal      !: salinity    river runoffs attribute specified in a file
-   TYPE(FLD_N)       , PUBLIC ::   sn_rnf          !: information about the runoff file to be read
-   TYPE(FLD_N)                ::   sn_cnf          !: information about the runoff mouth file to be read
-   TYPE(FLD_N)                ::   sn_s_rnf        !: information about the salinities of runoff file to be read
-   TYPE(FLD_N)                ::   sn_t_rnf        !: information about the temperatures of runoff file to be read
-   TYPE(FLD_N)                ::   sn_dep_rnf      !: information about the depth which river inflow affects
-   LOGICAL           , PUBLIC ::   ln_rnf_mouth    !: specific treatment in mouths vicinity
-   REAL(wp)                   ::   rn_hrnf         !: runoffs, depth over which enhanced vertical mixing is used
-   REAL(wp)          , PUBLIC ::   rn_avt_rnf      !: runoffs, value of the additional vertical mixing coef. [m2/s]
-   REAL(wp)                   ::   rn_rfact        !: multiplicative factor for runoff
-
-   LOGICAL           , PUBLIC ::   l_rnfcpl = .false.       ! runoffs recieved from oasis
-
-   INTEGER , PUBLIC  ::   nkrnf = 0         !: nb of levels over which Kz is increased at river mouths
+   LOGICAL                    ::      ln_rnf_depth_ini  !: depth       river runoffs  computed at the initialisation
+   REAL(wp)                   ::      rn_rnf_max        !: maximum value of the runoff climatologie (ln_rnf_depth_ini =T)
+   REAL(wp)                   ::      rn_dep_max        !: depth over which runoffs is spread       (ln_rnf_depth_ini =T)
+   INTEGER                    ::      nn_rnf_depth_file !: create (=1) a runoff depth file or not (=0)
+   LOGICAL                    ::   ln_rnf_tem        !: temperature river runoffs attribute specified in a file
+   LOGICAL           , PUBLIC ::   ln_rnf_sal        !: salinity    river runoffs attribute specified in a file
+   TYPE(FLD_N)       , PUBLIC ::   sn_rnf            !: information about the runoff file to be read
+   TYPE(FLD_N)                ::   sn_cnf            !: information about the runoff mouth file to be read
+   TYPE(FLD_N)                ::   sn_s_rnf          !: information about the salinities of runoff file to be read
+   TYPE(FLD_N)                ::   sn_t_rnf          !: information about the temperatures of runoff file to be read
+   TYPE(FLD_N)                ::   sn_dep_rnf        !: information about the depth which river inflow affects
+   LOGICAL           , PUBLIC ::   ln_rnf_mouth      !: specific treatment in mouths vicinity
+   REAL(wp)                   ::   rn_hrnf           !: runoffs, depth over which enhanced vertical mixing is used
+   REAL(wp)          , PUBLIC ::   rn_avt_rnf        !: runoffs, value of the additional vertical mixing coef. [m2/s]
+   REAL(wp)          , PUBLIC ::   rn_rfact          !: multiplicative factor for runoff
+
+   LOGICAL , PUBLIC ::   l_rnfcpl = .false.   !: runoffs recieved from oasis
+   INTEGER , PUBLIC ::   nkrnf = 0            !: nb of levels over which Kz is increased at river mouths
+   
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   rnfmsk              !: river mouth mask (hori.)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)     ::   rnfmsk_z            !: river mouth mask (vert.)
@@ -68,6 +69,4 @@
    TYPE(FLD),        ALLOCATABLE, DIMENSION(:) ::   sf_t_rnf     ! structure: river runoff temperature (file information, fields read)  
  
-   !! * Substitutions  
-#  include "domzgr_substitute.h90"  
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -127,12 +126,4 @@
       IF(   ln_rnf_sal   )   CALL fld_read ( kt, nn_fsbc, sf_s_rnf )    ! idem for runoffs salinity    if required
       !
-      ! Runoff reduction only associated to the ORCA2_LIM configuration
-      ! when reading the NetCDF file runoff_1m_nomask.nc
-      IF( cp_cfg == 'orca' .AND. jp_cfg == 2 .AND. .NOT. l_rnfcpl )   THEN
-         WHERE( 40._wp < gphit(:,:) .AND. gphit(:,:) < 65._wp )
-            sf_rnf(1)%fnow(:,:,1) = 0.85 * sf_rnf(1)%fnow(:,:,1)
-         END WHERE
-      ENDIF
-      !
       IF( MOD( kt - 1, nn_fsbc ) == 0 ) THEN
          !
@@ -142,10 +133,10 @@
          IF( ln_rnf_tem ) THEN                                       ! use runoffs temperature data
             rnf_tsc(:,:,jp_tem) = ( sf_t_rnf(1)%fnow(:,:,1) ) * rnf(:,:) * r1_rau0
+            CALL eos_fzp( sss_m(:,:), ztfrz(:,:) )
             WHERE( sf_t_rnf(1)%fnow(:,:,1) == -999._wp )             ! if missing data value use SST as runoffs temperature
                rnf_tsc(:,:,jp_tem) = sst_m(:,:) * rnf(:,:) * r1_rau0
             END WHERE
             WHERE( sf_t_rnf(1)%fnow(:,:,1) == -222._wp )             ! where fwf comes from melting of ice shelves or iceberg
-               ztfrz(:,:) = -1.9 !tfreez( sss_m(:,:) ) !PM to be discuss (trouble if sensitivity study)
-               rnf_tsc(:,:,jp_tem) = ztfrz(:,:) * rnf(:,:) * r1_rau0 - rnf(:,:) * lfusisf * r1_rau0_rcp
+               rnf_tsc(:,:,jp_tem) = ztfrz(:,:) * rnf(:,:) * r1_rau0 - rnf(:,:) * rlfusisf * r1_rau0_rcp
             END WHERE
          ELSE                                                        ! use SST as runoffs temperature
@@ -211,10 +202,18 @@
       !
       IF( ln_rnf_depth .OR. ln_rnf_depth_ini ) THEN      !==   runoff distributed over several levels   ==!
-         IF( lk_vvl ) THEN             ! variable volume case
+         IF( ln_linssh ) THEN    !* constant volume case : just apply the runoff input flow
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  DO jk = 1, nk_rnf(ji,jj)
+                     phdivn(ji,jj,jk) = phdivn(ji,jj,jk) - ( rnf(ji,jj) + rnf_b(ji,jj) ) * zfact * r1_rau0 / h_rnf(ji,jj)
+                  END DO
+               END DO
+            END DO
+         ELSE                    !* variable volume case
             DO jj = 1, jpj                   ! update the depth over which runoffs are distributed
                DO ji = 1, jpi
                   h_rnf(ji,jj) = 0._wp
                   DO jk = 1, nk_rnf(ji,jj)                           ! recalculates h_rnf to be the depth in metres
-                     h_rnf(ji,jj) = h_rnf(ji,jj) + fse3t(ji,jj,jk)   ! to the bottom of the relevant grid box
+                     h_rnf(ji,jj) = h_rnf(ji,jj) + e3t_n(ji,jj,jk)   ! to the bottom of the relevant grid box
                   END DO
                   !                          ! apply the runoff input flow
@@ -224,18 +223,8 @@
                END DO
             END DO
-         ELSE                          ! constant volume case : just apply the runoff input flow
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  DO jk = 1, nk_rnf(ji,jj)
-                     phdivn(ji,jj,jk) = phdivn(ji,jj,jk) - ( rnf(ji,jj) + rnf_b(ji,jj) ) * zfact * r1_rau0 / h_rnf(ji,jj)
-                  END DO
-               END DO
-            END DO
          ENDIF
       ELSE                       !==   runoff put only at the surface   ==!
-         IF( lk_vvl ) THEN              ! variable volume case
-            h_rnf(:,:) = fse3t(:,:,1)   ! recalculate h_rnf to be depth of top box
-         ENDIF
-         phdivn(:,:,1) = phdivn(:,:,1) - ( rnf(:,:) + rnf_b(:,:) ) * zfact * r1_rau0 / fse3t(:,:,1)
+         h_rnf (:,:)   = e3t_n (:,:,1)        ! update h_rnf to be depth of top box
+         phdivn(:,:,1) = phdivn(:,:,1) - ( rnf(:,:) + rnf_b(:,:) ) * zfact * r1_rau0 / e3t_n(:,:,1)
       ENDIF
       !
@@ -377,5 +366,5 @@
                h_rnf(ji,jj) = 0._wp
                DO jk = 1, nk_rnf(ji,jj)
-                  h_rnf(ji,jj) = h_rnf(ji,jj) + fse3t(ji,jj,jk)
+                  h_rnf(ji,jj) = h_rnf(ji,jj) + e3t_n(ji,jj,jk)
                END DO
             END DO
@@ -435,5 +424,5 @@
                h_rnf(ji,jj) = 0._wp
                DO jk = 1, nk_rnf(ji,jj)
-                  h_rnf(ji,jj) = h_rnf(ji,jj) + fse3t(ji,jj,jk)
+                  h_rnf(ji,jj) = h_rnf(ji,jj) + e3t_n(ji,jj,jk)
                END DO
             END DO
@@ -448,5 +437,5 @@
       ELSE                                       ! runoffs applied at the surface
          nk_rnf(:,:) = 1
-         h_rnf (:,:) = fse3t(:,:,1)
+         h_rnf (:,:) = e3t_n(:,:,1)
       ENDIF
       !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90	(revision 6140)
@@ -6,31 +6,29 @@
    !! History :  9.0  ! 2006-07  (G. Madec)  Original code
    !!            3.3  ! 2010-10  (C. Bricaud, G. Madec)  add the Patm forcing for sea-ice
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   sbc_ssm        : calculate sea surface mean currents, temperature,  
-   !!                    and salinity over nn_fsbc time-step
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! surface boundary condition: ocean fields
-   USE sbcapr          ! surface boundary condition: atmospheric pressure
-   USE eosbn2          ! equation of state and related derivatives
+   !!            3.7  ! 2015-11  (G. Madec)  non linear free surface by default: e3t_m always computed
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   sbc_ssm       : calculate sea surface mean currents, temperature,  
+   !!                   and salinity over nn_fsbc time-step
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE sbc_oce        ! surface boundary condition: ocean fields
+   USE sbcapr         ! surface boundary condition: atmospheric pressure
+   USE eosbn2         ! equation of state and related derivatives
    !
-   USE in_out_manager  ! I/O manager
-   USE prtctl          ! Print control
-   USE iom             ! IOM library
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
+   USE iom            ! IOM library
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   sbc_ssm         ! routine called by step.F90
-   PUBLIC   sbc_ssm_init    ! routine called by sbcmod.F90
-
-   LOGICAL, SAVE  ::   l_ssm_mean = .FALSE.       ! keep track of whether means have been read
-                                                  ! from restart file
+   PUBLIC   sbc_ssm        ! routine called by step.F90
+   PUBLIC   sbc_ssm_init   ! routine called by sbcmod.F90
+
+   LOGICAL, SAVE ::   l_ssm_mean = .FALSE.   ! keep track of whether means have been read from restart file
    
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -59,5 +57,5 @@
       REAL(wp), DIMENSION(jpi,jpj,jpts) :: zts
       !!---------------------------------------------------------------------
-
+      !
       !                                        !* surface T-, U-, V- ocean level variables (T, S, depth, velocity)
       DO jj = 1, jpj
@@ -81,5 +79,5 @@
          ENDIF
          !
-         IF( lk_vvl )   e3t_m(:,:) = fse3t_n(:,:,1)
+         e3t_m(:,:) = e3t_n(:,:,1)
          !
          frq_m(:,:) = fraqsr_1lev(:,:)
@@ -103,5 +101,5 @@
             ENDIF
             !
-            IF( lk_vvl )   e3t_m(:,:) = zcoef * fse3t_n(:,:,1)
+            e3t_m(:,:) = zcoef * e3t_n(:,:,1)
             !
             frq_m(:,:) = zcoef * fraqsr_1lev(:,:)
@@ -109,11 +107,11 @@
          ELSEIF( MOD( kt - 2 , nn_fsbc ) == 0 ) THEN      !   Initialisation: New mean computation   !
             !                                             ! ---------------------------------------- !
-            ssu_m(:,:) = 0.e0      ! reset to zero ocean mean sbc fields
-            ssv_m(:,:) = 0.e0
-            sst_m(:,:) = 0.e0
-            sss_m(:,:) = 0.e0
-            ssh_m(:,:) = 0.e0
-            IF( lk_vvl )   e3t_m(:,:) = 0.e0
-            frq_m(:,:) = 0.e0
+            ssu_m(:,:) = 0._wp     ! reset to zero ocean mean sbc fields
+            ssv_m(:,:) = 0._wp
+            sst_m(:,:) = 0._wp
+            sss_m(:,:) = 0._wp
+            ssh_m(:,:) = 0._wp
+            e3t_m(:,:) = 0._wp
+            frq_m(:,:) = 0._wp
          ENDIF
          !                                                ! ---------------------------------------- !
@@ -131,7 +129,7 @@
          ENDIF
          !
-         IF( lk_vvl )   e3t_m(:,:) = fse3t_m(:,:) + fse3t_n(:,:,1)
-         !
-         frq_m(:,:) =   frq_m(:,:) + fraqsr_1lev(:,:)
+         e3t_m(:,:) = e3t_m(:,:) + e3t_n(:,:,1)
+         !
+         frq_m(:,:) = frq_m(:,:) + fraqsr_1lev(:,:)
 
          !                                                ! ---------------------------------------- !
@@ -139,11 +137,11 @@
             !                                             ! ---------------------------------------- !
             zcoef = 1. / REAL( nn_fsbc, wp )
-            sst_m(:,:) = sst_m(:,:) * zcoef           ! mean SST             [Celcius]
-            sss_m(:,:) = sss_m(:,:) * zcoef           ! mean SSS             [psu]
-            ssu_m(:,:) = ssu_m(:,:) * zcoef           ! mean suface current  [m/s]
-            ssv_m(:,:) = ssv_m(:,:) * zcoef           !
-            ssh_m(:,:) = ssh_m(:,:) * zcoef           ! mean SSH             [m]
-            IF( lk_vvl )   e3t_m(:,:) = fse3t_m(:,:) * zcoef   ! mean vertical scale factor [m]
-            frq_m(:,:) = frq_m(:,:) * zcoef   ! mean fraction of solar net radiation absorbed in the 1st T level [-]
+            sst_m(:,:) = sst_m(:,:) * zcoef     ! mean SST             [Celcius]
+            sss_m(:,:) = sss_m(:,:) * zcoef     ! mean SSS             [psu]
+            ssu_m(:,:) = ssu_m(:,:) * zcoef     ! mean suface current  [m/s]
+            ssv_m(:,:) = ssv_m(:,:) * zcoef     !
+            ssh_m(:,:) = ssh_m(:,:) * zcoef     ! mean SSH             [m]
+            e3t_m(:,:) = e3t_m(:,:) * zcoef     ! mean vertical scale factor [m]
+            frq_m(:,:) = frq_m(:,:) * zcoef     ! mean fraction of solar net radiation absorbed in the 1st T level [-]
             !
          ENDIF
@@ -162,5 +160,5 @@
             CALL iom_rstput( kt, nitrst, numrow, 'sss_m'  , sss_m  )
             CALL iom_rstput( kt, nitrst, numrow, 'ssh_m'  , ssh_m  )
-            IF( lk_vvl )   CALL iom_rstput( kt, nitrst, numrow, 'e3t_m'  , e3t_m  )
+            CALL iom_rstput( kt, nitrst, numrow, 'e3t_m'  , e3t_m  )
             CALL iom_rstput( kt, nitrst, numrow, 'frq_m'  , frq_m  )
             !
@@ -175,9 +173,10 @@
          CALL iom_put( 'sss_m', sss_m )
          CALL iom_put( 'ssh_m', ssh_m )
-         IF( lk_vvl )   CALL iom_put( 'e3t_m', e3t_m )
+         CALL iom_put( 'e3t_m', e3t_m )
          CALL iom_put( 'frq_m', frq_m )
       ENDIF
       !
    END SUBROUTINE sbc_ssm
+
 
    SUBROUTINE sbc_ssm_init
@@ -189,7 +188,7 @@
       !! ** Action  : - read parameters
       !!----------------------------------------------------------------------
-      REAL(wp) ::   zcoef, zf_sbc       ! local scalar
+      REAL(wp) ::   zcoef, zf_sbc   ! local scalar
       !!----------------------------------------------------------------------
-
+      !
       IF( nn_fsbc == 1 ) THEN
          !
@@ -206,11 +205,11 @@
          IF( ln_rstart .AND. iom_varid( numror, 'nn_fsbc', ldstop = .FALSE. ) > 0 ) THEN
             l_ssm_mean = .TRUE.
-            CALL iom_get( numror               , 'nn_fsbc', zf_sbc )   ! sbc frequency of previous run
-            CALL iom_get( numror, jpdom_autoglo, 'ssu_m'  , ssu_m  )   ! sea surface mean velocity    (T-point)
-            CALL iom_get( numror, jpdom_autoglo, 'ssv_m'  , ssv_m  )   !   "         "    velocity    (V-point)
-            CALL iom_get( numror, jpdom_autoglo, 'sst_m'  , sst_m  )   !   "         "    temperature (T-point)
-            CALL iom_get( numror, jpdom_autoglo, 'sss_m'  , sss_m  )   !   "         "    salinity    (T-point)
-            CALL iom_get( numror, jpdom_autoglo, 'ssh_m'  , ssh_m  )   !   "         "    height      (T-point)
-            IF( lk_vvl ) CALL iom_get( numror, jpdom_autoglo, 'e3t_m', e3t_m )
+            CALL iom_get( numror               , 'nn_fsbc', zf_sbc )    ! sbc frequency of previous run
+            CALL iom_get( numror, jpdom_autoglo, 'ssu_m'  , ssu_m  )    ! sea surface mean velocity    (U-point)
+            CALL iom_get( numror, jpdom_autoglo, 'ssv_m'  , ssv_m  )    !   "         "    velocity    (V-point)
+            CALL iom_get( numror, jpdom_autoglo, 'sst_m'  , sst_m  )    !   "         "    temperature (T-point)
+            CALL iom_get( numror, jpdom_autoglo, 'sss_m'  , sss_m  )    !   "         "    salinity    (T-point)
+            CALL iom_get( numror, jpdom_autoglo, 'ssh_m'  , ssh_m  )    !   "         "    height      (T-point)
+            CALL iom_get( numror, jpdom_autoglo, 'e3t_m'  , e3t_m  )    ! 1st level thickness          (T-point)
             ! fraction of solar net radiation absorbed in 1st T level
             IF( iom_varid( numror, 'frq_m', ldstop = .FALSE. ) > 0 ) THEN
@@ -229,5 +228,5 @@
                sss_m(:,:) = zcoef * sss_m(:,:)
                ssh_m(:,:) = zcoef * ssh_m(:,:)
-               IF( lk_vvl )   e3t_m(:,:) = zcoef * fse3t_m(:,:)
+               e3t_m(:,:) = zcoef * e3t_m(:,:)
                frq_m(:,:) = zcoef * frq_m(:,:)
             ELSE
@@ -245,7 +244,7 @@
          ELSE                    ;   sst_m(:,:) = tsn(:,:,1,jp_tem)
          ENDIF
-         sss_m(:,:) = tsn(:,:,1,jp_sal)
-         ssh_m(:,:) = sshn(:,:)
-         IF( lk_vvl )   e3t_m(:,:) = fse3t_n(:,:,1)
+         sss_m(:,:) = tsn  (:,:,1,jp_sal)
+         ssh_m(:,:) = sshn (:,:)
+         e3t_m(:,:) = e3t_n(:,:,1)
          frq_m(:,:) = 1._wp
          !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssr.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssr.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssr.F90	(revision 6140)
@@ -19,6 +19,6 @@
    !
    USE fldread        ! read input fields
+   USE in_out_manager ! I/O manager
    USE iom            ! I/O manager
-   USE in_out_manager ! I/O manager
    USE lib_mpp        ! distribued memory computing library
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
@@ -47,6 +47,4 @@
    TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_sss   ! structure of input SSS (file informations, fields read)
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 4.0 , NEMO Consortium (2011)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90	(revision 6140)
@@ -6,14 +6,14 @@
    !! History :  9.0  !  2007  (O. Le Galloudec)  Original code
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain
-   USE phycst
-   USE daymod
-   USE tideini
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constant
+   USE daymod         ! calandar
+   USE tideini        ! 
    !
-   USE iom
-   USE in_out_manager  ! I/O units
-   USE ioipsl          ! NetCDF IPSL library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager ! I/O units
+   USE iom            ! xIOs server
+   USE ioipsl         ! NetCDF IPSL library
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
 
    IMPLICIT NONE
@@ -46,7 +46,8 @@
       INTEGER, INTENT( in ) ::   kt     ! ocean time-step
       INTEGER               ::   jk     ! dummy loop index
+      INTEGER               ::   nsec_day_orig     ! Temporary variable
       !!----------------------------------------------------------------------
-
-      IF( nsec_day == NINT(0.5_wp * rdttra(1)) ) THEN      ! start a new day
+      
+      IF( nsec_day == NINT(0.5_wp * rdt) .OR. kt == nit000 ) THEN      ! start a new day
          !
          IF( kt == nit000 ) THEN
@@ -59,7 +60,16 @@
          pot_astro(:,:) = 0._wp
          !
+         ! If the run does not start from midnight then need to initialise tides
+         ! at the start of the current day (only occurs when kt==nit000)
+         ! Temporarily set nsec_day to beginning of day.
+         nsec_day_orig = nsec_day
+         IF ( nsec_day /= NINT(0.5_wp * rdt) ) THEN 
+            kt_tide = kt - (nsec_day - 0.5_wp * rdt)/rdt
+            nsec_day = NINT(0.5_wp * rdt)
+         ELSE
+            kt_tide = kt 
+         ENDIF
          CALL tide_harmo( omega_tide, v0tide, utide, ftide, ntide, nb_harmo )
          !
-         kt_tide = kt
          !
          IF(lwp) THEN
@@ -74,4 +84,6 @@
          IF( ln_tide_pot )   CALL tide_init_potential
          !
+         ! Reset nsec_day
+         nsec_day = nsec_day_orig 
       ENDIF
       !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90	(revision 6140)
@@ -40,5 +40,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -72,5 +71,5 @@
       REAL(wp), DIMENSION(:,:,:), POINTER ::   zusd_t, zvsd_t, ze3hdiv   ! 3D workspace
       !!
-      NAMELIST/namsbc_wave/  sn_cdg, cn_dir, sn_usd, sn_vsd, sn_wn
+      NAMELIST/namsbc_wave/  sn_cdg, cn_dir, sn_usd, sn_vsd, sn_wn, ln_cdgw , ln_sdw
       !!---------------------------------------------------------------------
       !
@@ -81,5 +80,5 @@
          READ  ( numnam_ref, namsbc_wave, IOSTAT = ios, ERR = 901)
 901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_wave in reference namelist', lwp )
-
+         !
          REWIND( numnam_cfg )              ! Namelist namsbc_wave in configuration namelist : File for drag coeff. from wave model
          READ  ( numnam_cfg, namsbc_wave, IOSTAT = ios, ERR = 902 )
@@ -87,5 +86,16 @@
          IF(lwm) WRITE ( numond, namsbc_wave )
          !
-         IF ( ln_cdgw ) THEN
+         IF(lwp) THEN               ! Control print
+            WRITE(numout,*) '        Namelist namsbc_wave : surface wave setting' 
+            WRITE(numout,*) '           wave drag coefficient                      ln_cdgw  = ', ln_cdgw  
+            WRITE(numout,*) '           wave stokes drift                          ln_sdw   = ', ln_sdw
+         ENDIF
+         !
+         IF( .NOT.( ln_cdgw .OR. ln_sdw ) )    &
+            &  CALL ctl_warn( 'ln_sbcwave=T but nor drag coefficient (ln_cdgw=F) neither stokes drift activated (ln_sdw=F)' )
+         IF( ln_cdgw .AND. .NOT.(ln_blk_mfs .OR. ln_blk_core) )   &       
+            &  CALL ctl_stop( 'drag coefficient read from wave model definable only with mfs bulk formulae and core')
+         !
+         IF( ln_cdgw ) THEN
             ALLOCATE( sf_cd(1), STAT=ierror )           !* allocate and fill sf_wave with sn_cdg
             IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_wave: unable to allocate sf_wave structure' )
@@ -97,5 +107,5 @@
             cdn_wave(:,:) = 0.0
          ENDIF
-         IF ( ln_sdw ) THEN
+         IF( ln_sdw ) THEN
             slf_i(jp_usd) = sn_usd ; slf_i(jp_vsd) = sn_vsd; slf_i(jp_wn) = sn_wn
             ALLOCATE( sf_sd(3), STAT=ierror )           !* allocate and fill sf_wave with sn_cdg
@@ -115,22 +125,20 @@
       ENDIF
       !
-      IF ( ln_cdgw ) THEN              !==  Neutral drag coefficient  ==!
+      IF( ln_cdgw ) THEN               !==  Neutral drag coefficient  ==!
          CALL fld_read( kt, nn_fsbc, sf_cd )      ! read from external forcing
          cdn_wave(:,:) = sf_cd(1)%fnow(:,:,1)
       ENDIF
       !
-      IF ( ln_sdw )  THEN              !==  Computation of the 3d Stokes Drift  ==!
+      IF( ln_sdw )  THEN               !==  Computation of the 3d Stokes Drift  ==!
+         !
+         CALL wrk_alloc( jpi,jpj,jpk,   zusd_t, zvsd_t, ze3hdiv )
          !
          CALL fld_read( kt, nn_fsbc, sf_sd )    !* read drag coefficient from external forcing
          !
-         !
-         CALL wrk_alloc( jpi,jpj,jpk,   zusd_t, zvsd_t, ze3hdiv )
-         !                                      !* distribute it on the vertical
-         DO jk = 1, jpkm1
-            zusd_t(:,:,jk) = sf_sd(jp_usd)%fnow(:,:,1) * EXP( -2._wp * sf_sd(jp_wn)%fnow(:,:,1) * fsdept_n(:,:,jk) )
-            zvsd_t(:,:,jk) = sf_sd(jp_vsd)%fnow(:,:,1) * EXP( -2._wp * sf_sd(jp_wn)%fnow(:,:,1) * fsdept_n(:,:,jk) )
+         DO jk = 1, jpkm1                       !* distribute it on the vertical
+            zusd_t(:,:,jk) = sf_sd(jp_usd)%fnow(:,:,1) * EXP( -2._wp * sf_sd(jp_wn)%fnow(:,:,1) * gdept_n(:,:,jk) )
+            zvsd_t(:,:,jk) = sf_sd(jp_vsd)%fnow(:,:,1) * EXP( -2._wp * sf_sd(jp_wn)%fnow(:,:,1) * gdept_n(:,:,jk) )
          END DO
-         !                                      !* interpolate the stokes drift from t-point to u- and v-points
-         DO jk = 1, jpkm1
+         DO jk = 1, jpkm1                       !* interpolate the stokes drift from t-point to u- and v-points
             DO jj = 1, jpjm1
                DO ji = 1, jpim1
@@ -146,8 +154,8 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  ze3hdiv(ji,jj,jk) = (  e2u(ji  ,jj) * fse3u_n(ji  ,jj,jk) * usd3d(ji  ,jj,jk)     &
-                     &                 - e2u(ji-1,jj) * fse3u_n(ji-1,jj,jk) * usd3d(ji-1,jj,jk)     &
-                     &                 + e1v(ji,jj  ) * fse3v_n(ji,jj  ,jk) * vsd3d(ji,jj  ,jk)     &
-                     &                 - e1v(ji,jj-1) * fse3v_n(ji,jj-1,jk) * vsd3d(ji,jj-1,jk)   ) * r1_e1e2t(ji,jj)
+                  ze3hdiv(ji,jj,jk) = (  e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) * usd3d(ji  ,jj,jk)     &
+                     &                 - e2u(ji-1,jj) * e3u_n(ji-1,jj,jk) * usd3d(ji-1,jj,jk)     &
+                     &                 + e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * vsd3d(ji,jj  ,jk)     &
+                     &                 - e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * vsd3d(ji,jj-1,jk)   ) * r1_e1e2t(ji,jj)
                END DO  
             END DO  
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/tideini.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/tideini.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/SBC/tideini.F90	(revision 6140)
@@ -6,14 +6,14 @@
    !! History :  1.0  !  2007  (O. Le Galloudec)  Original code
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain
-   USE phycst
-   USE daymod
-   USE tide_mod
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constant
+   USE daymod         ! calandar
+   USE tide_mod       ! 
    !
-   USE iom
-   USE in_out_manager  ! I/O units
-   USE ioipsl          ! NetCDF IPSL library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager ! I/O units
+   USE iom            ! xIOs server
+   USE ioipsl         ! NetCDF IPSL library
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
 
    IMPLICIT NONE
@@ -27,7 +27,7 @@
    LOGICAL , PUBLIC ::   ln_tide_pot     !:
    LOGICAL , PUBLIC ::   ln_tide_ramp    !:
-   INTEGER , PUBLIC ::   nb_harmo                 !:
-   INTEGER , PUBLIC ::   kt_tide                  !:
-   REAL(wp), PUBLIC ::   rdttideramp              !:
+   INTEGER , PUBLIC ::   nb_harmo        !:
+   INTEGER , PUBLIC ::   kt_tide         !:
+   REAL(wp), PUBLIC ::   rdttideramp     !:
    
    INTEGER , PUBLIC, ALLOCATABLE, DIMENSION(:) ::   ntide   !:
@@ -40,75 +40,68 @@
 CONTAINS
    
-  SUBROUTINE tide_init ( kt )
-    !!----------------------------------------------------------------------
-    !!                 ***  ROUTINE tide_init  ***
-    !!----------------------------------------------------------------------      
-    !! * Local declarations
-    INTEGER  :: ji, jk
-    INTEGER, INTENT( in ) ::   kt     ! ocean time-step
-    CHARACTER(LEN=4), DIMENSION(jpmax_harmo) :: clname
-    INTEGER  ::   ios                 ! Local integer output status for namelist read
-    !
-    NAMELIST/nam_tide/ln_tide_pot, ln_tide_ramp, rdttideramp, clname
-    !!----------------------------------------------------------------------
-
-    IF ( kt == nit000 ) THEN
-       !
-       IF(lwp) THEN
-          WRITE(numout,*)
-          WRITE(numout,*) 'tide_init : Initialization of the tidal components'
-          WRITE(numout,*) '~~~~~~~~~ '
-       ENDIF
-       !
-       CALL tide_init_Wave
-       !
-       ! Read Namelist nam_tide
-       REWIND( numnam_ref )              ! Namelist nam_tide in reference namelist : Tides
-       READ  ( numnam_ref, nam_tide, IOSTAT = ios, ERR = 901)
-901    IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_tide in reference namelist', lwp )
-
-       REWIND( numnam_cfg )              ! Namelist nam_tide in configuration namelist : Tides
-       READ  ( numnam_cfg, nam_tide, IOSTAT = ios, ERR = 902 )
-902    IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_tide in configuration namelist', lwp )
-       IF(lwm) WRITE ( numond, nam_tide )
-       !
-       nb_harmo=0
-       DO jk = 1, jpmax_harmo
-          DO ji = 1,jpmax_harmo
-             IF( TRIM(clname(jk)) == Wave(ji)%cname_tide )   nb_harmo = nb_harmo + 1
-          END DO
-       END DO
-       !       
-       ! Ensure that tidal components have been set in namelist_cfg
-       IF( nb_harmo .EQ. 0 ) CALL ctl_stop( 'tide_init : No tidal components set in nam_tide' )
-       !
-       IF(lwp) THEN
-          WRITE(numout,*) '   Namelist nam_tide'
-          WRITE(numout,*) '      Apply astronomical potential : ln_tide_pot  =', ln_tide_pot
-          WRITE(numout,*) '                                     nb_harmo     = ', nb_harmo
-          WRITE(numout,*) '                                     ln_tide_ramp = ', ln_tide_ramp 
-          WRITE(numout,*) '                                     rdttideramp  = ', rdttideramp
-       ENDIF
-       IF( ln_tide_ramp.AND.((nitend-nit000+1)*rdt/rday < rdttideramp) )   &
-          &   CALL ctl_stop('rdttideramp must be lower than run duration')
-       IF( ln_tide_ramp.AND.(rdttideramp<0.) ) &
-          &   CALL ctl_stop('rdttideramp must be positive')
-       !
-       !
-       ALLOCATE( ntide(nb_harmo) )
-       DO jk = 1, nb_harmo
-          DO ji = 1, jpmax_harmo
-             IF( TRIM(clname(jk)) .eq. Wave(ji)%cname_tide ) THEN
-                ntide(jk) = ji
-                EXIT
-             END IF
-          END DO
-       END DO
-       !
-       ALLOCATE( omega_tide(nb_harmo), v0tide    (nb_harmo),   &
-          &      utide     (nb_harmo), ftide     (nb_harmo)  )
-       kt_tide = kt
-       !
+   SUBROUTINE tide_init
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE tide_init  ***
+      !!----------------------------------------------------------------------      
+      INTEGER  :: ji, jk
+      CHARACTER(LEN=4), DIMENSION(jpmax_harmo) :: clname
+      INTEGER  ::   ios                 ! Local integer output status for namelist read
+      !
+      NAMELIST/nam_tide/ln_tide_pot, ln_tide_ramp, rdttideramp, clname
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tide_init : Initialization of the tidal components'
+         WRITE(numout,*) '~~~~~~~~~ '
       ENDIF
+      !
+      CALL tide_init_Wave
+      !
+      ! Read Namelist nam_tide
+      REWIND( numnam_ref )              ! Namelist nam_tide in reference namelist : Tides
+      READ  ( numnam_ref, nam_tide, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_tide in reference namelist', lwp )
+      !
+      REWIND( numnam_cfg )              ! Namelist nam_tide in configuration namelist : Tides
+      READ  ( numnam_cfg, nam_tide, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_tide in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, nam_tide )
+      !
+      nb_harmo=0
+      DO jk = 1, jpmax_harmo
+         DO ji = 1,jpmax_harmo
+            IF( TRIM(clname(jk)) == Wave(ji)%cname_tide )   nb_harmo = nb_harmo + 1
+         END DO
+      END DO
+      !       
+      ! Ensure that tidal components have been set in namelist_cfg
+      IF( nb_harmo == 0 )   CALL ctl_stop( 'tide_init : No tidal components set in nam_tide' )
+      !
+      IF(lwp) THEN
+         WRITE(numout,*) '   Namelist nam_tide'
+         WRITE(numout,*) '      Apply astronomical potential : ln_tide_pot  =', ln_tide_pot
+         WRITE(numout,*) '                                     nb_harmo     = ', nb_harmo
+         WRITE(numout,*) '                                     ln_tide_ramp = ', ln_tide_ramp 
+         WRITE(numout,*) '                                     rdttideramp  = ', rdttideramp
+      ENDIF
+      IF( ln_tide_ramp.AND.((nitend-nit000+1)*rdt/rday < rdttideramp) )   &
+         &   CALL ctl_stop('rdttideramp must be lower than run duration')
+      IF( ln_tide_ramp.AND.(rdttideramp<0.) ) &
+         &   CALL ctl_stop('rdttideramp must be positive')
+      !
+      ALLOCATE( ntide(nb_harmo) )
+      DO jk = 1, nb_harmo
+         DO ji = 1, jpmax_harmo
+            IF( TRIM(clname(jk)) == Wave(ji)%cname_tide ) THEN
+               ntide(jk) = ji
+               EXIT
+            ENDIF
+         END DO
+      END DO
+      !
+      ALLOCATE( omega_tide(nb_harmo), v0tide    (nb_harmo),   &
+         &      utide     (nb_harmo), ftide     (nb_harmo)  )
+      kt_tide = nit000
       !
    END SUBROUTINE tide_init
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/eosbn2.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/eosbn2.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/eosbn2.F90	(revision 6140)
@@ -2,6 +2,5 @@
    !!==============================================================================
    !!                       ***  MODULE  eosbn2  ***
-   !! Ocean diagnostic variable : equation of state - in situ and potential density
-   !!                                               - Brunt-Vaisala frequency
+   !! Equation Of Seawater : in situ density - Brunt-Vaisala frequency
    !!==============================================================================
    !! History :  OPA  ! 1989-03  (O. Marti)  Original code
@@ -26,33 +25,33 @@
 
    !!----------------------------------------------------------------------
-   !!   eos            : generic interface of the equation of state
-   !!   eos_insitu     : Compute the in situ density
-   !!   eos_insitu_pot : Compute the insitu and surface referenced potential volumic mass
-   !!   eos_insitu_2d  : Compute the in situ density for 2d fields
-   !!   bn2            : Compute the Brunt-Vaisala frequency
-   !!   eos_rab        : generic interface of in situ thermal/haline expansion ratio 
-   !!   eos_rab_3d     : compute in situ thermal/haline expansion ratio
-   !!   eos_rab_2d     : compute in situ thermal/haline expansion ratio for 2d fields
-   !!   eos_fzp_2d     : freezing temperature for 2d fields
-   !!   eos_fzp_0d     : freezing temperature for scalar
-   !!   eos_init       : set eos parameters (namelist)
+   !!   eos           : generic interface of the equation of state
+   !!   eos_insitu    : Compute the in situ density
+   !!   eos_insitu_pot: Compute the insitu and surface referenced potential volumic mass
+   !!   eos_insitu_2d : Compute the in situ density for 2d fields
+   !!   bn2           : Compute the Brunt-Vaisala frequency
+   !!   eos_rab       : generic interface of in situ thermal/haline expansion ratio 
+   !!   eos_rab_3d    : compute in situ thermal/haline expansion ratio
+   !!   eos_rab_2d    : compute in situ thermal/haline expansion ratio for 2d fields
+   !!   eos_fzp_2d    : freezing temperature for 2d fields
+   !!   eos_fzp_0d    : freezing temperature for scalar
+   !!   eos_init      : set eos parameters (namelist)
    !!----------------------------------------------------------------------
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE stopar         ! Stochastic T/S fluctuations
+   USE stopts         ! Stochastic T/S fluctuations
    !
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! MPP library
-   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE prtctl          ! Print control
-   USE wrk_nemo        ! Memory Allocation
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE prtctl         ! Print control
+   USE wrk_nemo       ! Memory Allocation
    USE lbclnk         ! ocean lateral boundary conditions
-   USE timing          ! Timing
-   USE stopar          ! Stochastic T/S fluctuations
-   USE stopts          ! Stochastic T/S fluctuations
+   USE timing         ! Timing
 
    IMPLICIT NONE
    PRIVATE
 
-   !                   !! * Interface
+   !                  !! * Interface
    INTERFACE eos
       MODULE PROCEDURE eos_insitu, eos_insitu_pot, eos_insitu_2d
@@ -75,10 +74,9 @@
    PUBLIC   eos_init       ! called by istate module
 
-   !                                !!* Namelist (nameos) *
+   !                               !!** Namelist nameos **
    INTEGER , PUBLIC ::   nn_eos     ! = 0/1/2 type of eq. of state and Brunt-Vaisala frequ.
    LOGICAL , PUBLIC ::   ln_useCT   ! determine if eos_pt_from_ct is used to compute sst_m
 
-   !                                   !!!  simplified eos coefficients
-   ! default value: Vallis 2006
+   !                               !!!  simplified eos coefficients (default value: Vallis 2006)
    REAL(wp) ::   rn_a0      = 1.6550e-1_wp     ! thermal expansion coeff. 
    REAL(wp) ::   rn_b0      = 7.6554e-1_wp     ! saline  expansion coeff. 
@@ -172,5 +170,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -587,5 +584,5 @@
                DO ji = 1, jpi
                   !
-                  zh  = fsdept(ji,jj,jk) * r1_Z0                                ! depth
+                  zh  = gdept_n(ji,jj,jk) * r1_Z0                                ! depth
                   zt  = pts (ji,jj,jk,jp_tem) * r1_T0                           ! temperature
                   zs  = SQRT( ABS( pts(ji,jj,jk,jp_sal) + rdeltaS ) * r1_S0 )   ! square root salinity
@@ -645,5 +642,5 @@
                   zt  = pts (ji,jj,jk,jp_tem) - 10._wp   ! pot. temperature anomaly (t-T0)
                   zs  = pts (ji,jj,jk,jp_sal) - 35._wp   ! abs. salinity anomaly (s-S0)
-                  zh  = fsdept(ji,jj,jk)                 ! depth in meters at t-point
+                  zh  = gdept_n(ji,jj,jk)                ! depth in meters at t-point
                   ztm = tmask(ji,jj,jk)                  ! land/sea bottom mask = surf. mask
                   !
@@ -913,6 +910,6 @@
          DO jj = 1, jpj          ! surface and bottom value set to zero one for all in istate.F90
             DO ji = 1, jpi
-               zrw =   ( fsdepw(ji,jj,jk  ) - fsdept(ji,jj,jk) )   &
-                  &  / ( fsdept(ji,jj,jk-1) - fsdept(ji,jj,jk) ) 
+               zrw =   ( gdepw_n(ji,jj,jk  ) - gdept_n(ji,jj,jk) )   &
+                  &  / ( gdept_n(ji,jj,jk-1) - gdept_n(ji,jj,jk) ) 
                   !
                zaw = pab(ji,jj,jk,jp_tem) * (1. - zrw) + pab(ji,jj,jk-1,jp_tem) * zrw 
@@ -921,5 +918,5 @@
                pn2(ji,jj,jk) = grav * (  zaw * ( pts(ji,jj,jk-1,jp_tem) - pts(ji,jj,jk,jp_tem) )     &
                   &                    - zbw * ( pts(ji,jj,jk-1,jp_sal) - pts(ji,jj,jk,jp_sal) )  )  &
-                  &            / fse3w(ji,jj,jk) * tmask(ji,jj,jk)
+                  &            / e3w_n(ji,jj,jk) * tmask(ji,jj,jk)
             END DO
          END DO
@@ -1129,5 +1126,5 @@
                DO ji = 1, jpi
                   !
-                  zh  = fsdept(ji,jj,jk) * r1_Z0                                ! depth
+                  zh  = gdept_n(ji,jj,jk) * r1_Z0                                ! depth
                   zt  = pts (ji,jj,jk,jp_tem) * r1_T0                           ! temperature
                   zs  = SQRT( ABS( pts(ji,jj,jk,jp_sal) + rdeltaS ) * r1_S0 )   ! square root salinity
@@ -1193,5 +1190,5 @@
                   zt  = pts(ji,jj,jk,jp_tem) - 10._wp  ! temperature anomaly (t-T0)
                   zs = pts (ji,jj,jk,jp_sal) - 35._wp  ! abs. salinity anomaly (s-S0)
-                  zh  = fsdept(ji,jj,jk)               ! depth in meters  at t-point
+                  zh  = gdept_n(ji,jj,jk)              ! depth in meters  at t-point
                   ztm = tmask(ji,jj,jk)                ! tmask
                   zn  = 0.5_wp * zh * r1_rau0 * ztm
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv.F90	(revision 6140)
@@ -26,5 +26,4 @@
    USE ldftra         ! lateral diffusion: eddy diffusivity & EIV coeff.
    USE ldfslp         ! Lateral diffusion: slopes of neutral surfaces
-   USE c1d            ! 1D vertical configuration
    !
    USE in_out_manager ! I/O manager
@@ -67,5 +66,4 @@
    
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -96,13 +94,13 @@
       !                                          ! set time step
       IF( neuler == 0 .AND. kt == nit000 ) THEN     ! at nit000
-         r2dtra(:) =  rdttra(:)                          ! = rdtra (restarting with Euler time stepping)
+         r2dt = rdt                                 ! = rdt (restarting with Euler time stepping)
       ELSEIF( kt <= nit000 + 1) THEN                ! at nit000 or nit000+1
-         r2dtra(:) = 2._wp * rdttra(:)                   ! = 2 rdttra (leapfrog)
+         r2dt = 2._wp * rdt                         ! = 2 rdt (leapfrog)
       ENDIF
       !
       !                                         !==  effective transport  ==!
       DO jk = 1, jpkm1
-         zun(:,:,jk) = e2u  (:,:) * fse3u(:,:,jk) * un(:,:,jk)                  ! eulerian transport only
-         zvn(:,:,jk) = e1v  (:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+         zun(:,:,jk) = e2u  (:,:) * e3u_n(:,:,jk) * un(:,:,jk)                  ! eulerian transport only
+         zvn(:,:,jk) = e1v  (:,:) * e3v_n(:,:,jk) * vn(:,:,jk)
          zwn(:,:,jk) = e1e2t(:,:)                 * wn(:,:,jk)
       END DO
@@ -135,17 +133,17 @@
          CALL tra_adv_cen    ( kt, nit000, 'TRA',         zun, zvn, zwn     , tsn, tsa, jpts, nn_cen_h, nn_cen_v )
       CASE ( np_FCT )                                    ! FCT scheme      : 2nd / 4th order
-         CALL tra_adv_fct    ( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb, tsn, tsa, jpts, nn_fct_h, nn_fct_v )
+         CALL tra_adv_fct    ( kt, nit000, 'TRA', r2dt, zun, zvn, zwn, tsb, tsn, tsa, jpts, nn_fct_h, nn_fct_v )
       CASE ( np_FCT_zts )                                ! 2nd order FCT with vertical time-splitting
-         CALL tra_adv_fct_zts( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb, tsn, tsa, jpts        , nn_fct_zts )
+         CALL tra_adv_fct_zts( kt, nit000, 'TRA', r2dt, zun, zvn, zwn, tsb, tsn, tsa, jpts        , nn_fct_zts )
       CASE ( np_MUS )                                    ! MUSCL
-         CALL tra_adv_mus    ( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb,      tsa, jpts        , ln_mus_ups ) 
+         CALL tra_adv_mus    ( kt, nit000, 'TRA', r2dt, zun, zvn, zwn, tsb,      tsa, jpts        , ln_mus_ups ) 
       CASE ( np_UBS )                                    ! UBS
-         CALL tra_adv_ubs    ( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb, tsn, tsa, jpts        , nn_ubs_v   )
+         CALL tra_adv_ubs    ( kt, nit000, 'TRA', r2dt, zun, zvn, zwn, tsb, tsn, tsa, jpts        , nn_ubs_v   )
       CASE ( np_QCK )                                    ! QUICKEST
-         CALL tra_adv_qck    ( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb, tsn, tsa, jpts                     )
+         CALL tra_adv_qck    ( kt, nit000, 'TRA', r2dt, zun, zvn, zwn, tsb, tsn, tsa, jpts                     )
       !
       END SELECT
       !
-      !                                              ! print mean trends (used for debugging)
+      !                                         ! print mean trends (used for debugging)
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' adv  - Ta: ', mask1=tmask,               &
          &                       tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
@@ -175,14 +173,13 @@
       !
       !                                !==  Namelist  ==!
-      !
       REWIND( numnam_ref )                   ! Namelist namtra_adv in reference namelist : Tracer advection scheme
       READ  ( numnam_ref, namtra_adv, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtra_adv in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_adv in reference namelist', lwp )
       !
       REWIND( numnam_cfg )                   ! Namelist namtra_adv in configuration namelist : Tracer advection scheme
       READ  ( numnam_cfg, namtra_adv, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtra_adv in configuration namelist', lwp )
-      IF(lwm) WRITE ( numond, namtra_adv )
-
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_adv in configuration namelist', lwp )
+      IF(lwm) WRITE( numond, namtra_adv )
+      !
       IF(lwp) THEN                           ! Namelist print
          WRITE(numout,*)
@@ -203,5 +200,5 @@
          WRITE(numout,*) '      QUICKEST scheme                           ln_traadv_qck = ', ln_traadv_qck
       ENDIF
-
+      !
       ioptio = 0                       !==  Parameter control  ==!
       IF( ln_traadv_cen )   ioptio = ioptio + 1
@@ -215,6 +212,5 @@
          CALL ctl_warn( 'tra_adv_init: You are running without tracer advection.' )
       ENDIF
-      IF( (ioptio /= 1).AND. (.NOT. lk_c1d ) ) & 
-        CALL ctl_stop( 'tra_adv_init: Choose ONE advection scheme in namelist namtra_adv' )
+      IF( ioptio /= 1 )   CALL ctl_stop( 'tra_adv_init: Choose ONE advection scheme in namelist namtra_adv' )
       !
       IF( ln_traadv_cen .AND. ( nn_cen_h /= 2 .AND. nn_cen_h /= 4 )   &          ! Centered
@@ -231,5 +227,5 @@
             CALL ctl_stop( 'tra_adv_init: force 2nd order FCT scheme, 4th order does not exist with sub-timestepping' )
          ENDIF
-         IF( lk_vvl ) THEN
+         IF( .NOT.ln_linssh ) THEN
             CALL ctl_stop( 'tra_adv_init: vertical sub-timestepping not allow in non-linear free surface' )
          ENDIF
@@ -243,6 +239,6 @@
       ENDIF
       IF( ln_isfcav ) THEN                                                       ! ice-shelf cavities
-         IF(  ln_traadv_cen .AND. nn_cen_v /= 4    .OR.   &                            ! NO 4th order with ISF
-            & ln_traadv_fct .AND. nn_fct_v /= 4   )   CALL ctl_stop( 'tra_adv_init: 4th order COMPACT scheme not allowed with ISF' )
+         IF(  ln_traadv_cen .AND. nn_cen_v == 4    .OR.   &                            ! NO 4th order with ISF
+            & ln_traadv_fct .AND. nn_fct_v == 4   )   CALL ctl_stop( 'tra_adv_init: 4th order COMPACT scheme not allowed with ISF' )
       ENDIF
       !
@@ -255,16 +251,18 @@
       IF( ln_traadv_ubs                      )   nadv = np_UBS
       IF( ln_traadv_qck                      )   nadv = np_QCK
-
+      !
       IF(lwp) THEN                           ! Print the choice
          WRITE(numout,*)
-         IF( nadv == np_NO_adv  )   WRITE(numout,*) '         NO T-S advection'
-         IF( nadv == np_CEN     )   WRITE(numout,*) '         CEN      scheme is used. Horizontal order: ', nn_cen_h,   &
-            &                                                                        ' Vertical   order: ', nn_cen_v
-         IF( nadv == np_FCT     )   WRITE(numout,*) '         FCT      scheme is used. Horizontal order: ', nn_fct_h,   &
-            &                                                                        ' Vertical   order: ', nn_fct_v
-         IF( nadv == np_FCT_zts )   WRITE(numout,*) '         use 2nd order FCT with ', nn_fct_zts,'vertical sub-timestepping'
-         IF( nadv == np_MUS     )   WRITE(numout,*) '         MUSCL    scheme is used'
-         IF( nadv == np_UBS     )   WRITE(numout,*) '         UBS      scheme is used'
-         IF( nadv == np_QCK     )   WRITE(numout,*) '         QUICKEST scheme is used'
+         SELECT CASE ( nadv )
+         CASE( np_NO_adv  )   ;   WRITE(numout,*) '         NO T-S advection'
+         CASE( np_CEN     )   ;   WRITE(numout,*) '         CEN      scheme is used. Horizontal order: ', nn_cen_h,   &
+            &                                                                     ' Vertical   order: ', nn_cen_v
+         CASE( np_FCT     )   ;   WRITE(numout,*) '         FCT      scheme is used. Horizontal order: ', nn_fct_h,   &
+            &                                                                      ' Vertical   order: ', nn_fct_v
+         CASE( np_FCT_zts )   ;   WRITE(numout,*) '         use 2nd order FCT with ', nn_fct_zts,'vertical sub-timestepping'
+         CASE( np_MUS     )   ;   WRITE(numout,*) '         MUSCL    scheme is used'
+         CASE( np_UBS     )   ;   WRITE(numout,*) '         UBS      scheme is used'
+         CASE( np_QCK     )   ;   WRITE(numout,*) '         QUICKEST scheme is used'
+         END SELECT
       ENDIF
       !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_cen.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_cen.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_cen.F90	(revision 6140)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                     ***  MODULE  traadv_cen  ***
-   !! Ocean  tracers:  horizontal & vertical advective trend (2nd/4th order centered)
+   !! Ocean  tracers:   advective trend (2nd/4th order centered)
    !!======================================================================
    !! History :  3.7  ! 2014-05  (G. Madec)  original code
@@ -8,21 +8,21 @@
 
    !!----------------------------------------------------------------------
-   !!   tra_adv_cen : update the tracer trend with the advection trends using a centered or scheme (2nd or 4th order)
-   !!                 NB: on the vertical it is actually a 4th order COMPACT scheme which is used
-   !!----------------------------------------------------------------------
-   USE oce, ONLY: tsn  ! now ocean temperature and salinity
-   USE dom_oce         ! ocean space and time domain
-   USE eosbn2          ! equation of state
-   USE traadv_fct      ! acces to routine interp_4th_cpt 
-   USE trd_oce         ! trends: ocean variables
-   USE trdtra          ! trends manager: tracers 
-   USE diaptr          ! poleward transport diagnostics
+   !!   tra_adv_cen   : update the tracer trend with the advection trends using a centered or scheme (2nd or 4th order)
+   !!                   NB: on the vertical it is actually a 4th order COMPACT scheme which is used
+   !!----------------------------------------------------------------------
+   USE oce      , ONLY: tsn ! now ocean temperature and salinity
+   USE dom_oce        ! ocean space and time domain
+   USE eosbn2         ! equation of state
+   USE traadv_fct     ! acces to routine interp_4th_cpt 
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! trends manager: tracers 
+   USE diaptr         ! poleward transport diagnostics
    !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! IOM library
-   USE trc_oce         ! share passive tracers/Ocean variables
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE in_out_manager ! I/O manager
+   USE iom            ! IOM library
+   USE trc_oce        ! share passive tracers/Ocean variables
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -34,5 +34,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -53,13 +52,12 @@
       !! ** Method  :   The advection is evaluated by a 2nd or 4th order scheme
       !!               using now fields (leap-frog scheme). 
-      !!
       !!       kn_cen_h = 2  ==>> 2nd order centered scheme on the horizontal
       !!                = 4  ==>> 4th order    -        -       -      -
-      !!
       !!       kn_cen_v = 2  ==>> 2nd order centered scheme on the vertical
       !!                = 4  ==>> 4th order COMPACT  scheme     -      -
       !!
-      !! ** Action :  - update pta  with the now advective tracer trends
-      !!              - send trends to trdtra module for further diagnostcs
+      !! ** Action : - update pta  with the now advective tracer trends
+      !!             - send trends to trdtra module for further diagnostcs (l_trdtra=T)
+      !!             - htr_adv, str_adv : poleward advective heat and salt transport (ln_diaptr=T)
       !!----------------------------------------------------------------------
       INTEGER                              , INTENT(in   ) ::   kt              ! ocean time-step index
@@ -90,13 +88,13 @@
       ENDIF
       !
-      !                          ! surface & bottom values 
-      IF( lk_vvl )   zwz(:,:, 1 ) = 0._wp             ! set to zero one for all
-                     zwz(:,:,jpk) = 0._wp             ! except at the surface in linear free surface
+      !                    
+      zwz(:,:, 1 ) = 0._wp       ! surface & bottom vertical flux set to zero for all tracers
+      zwz(:,:,jpk) = 0._wp
       !
       DO jn = 1, kjpt            !==  loop over the tracers  ==!
          !
-         SELECT CASE( kn_cen_h )          !--  Horizontal fluxes  --!
-         !
-         CASE(  2  )                               ! 2nd order centered
+         SELECT CASE( kn_cen_h )       !--  Horizontal fluxes  --!
+         !
+         CASE(  2  )                         !* 2nd order centered
             DO jk = 1, jpkm1
                DO jj = 1, jpjm1
@@ -108,9 +106,9 @@
             END DO
             !
-         CASE(  4  )                               ! 4th order centered
-            ztu(:,:,jpk) = 0._wp                            ! Bottom value : flux set to zero
+         CASE(  4  )                         !* 4th order centered
+            ztu(:,:,jpk) = 0._wp                   ! Bottom value : flux set to zero
             ztv(:,:,jpk) = 0._wp
-            DO jk = 1, jpkm1                                 ! gradient
-               DO jj = 2, jpjm1                                   ! masked derivative
+            DO jk = 1, jpkm1                       ! masked gradient
+               DO jj = 2, jpjm1
                   DO ji = fs_2, fs_jpim1   ! vector opt.
                      ztu(ji,jj,jk) = ( ptn(ji+1,jj  ,jk,jn) - ptn(ji,jj,jk,jn) ) * umask(ji,jj,jk)
@@ -121,5 +119,5 @@
             CALL lbc_lnk( ztu, 'U', -1. )   ;    CALL lbc_lnk( ztv, 'V', -1. )   ! Lateral boundary cond. (unchanged sgn)
             !
-            DO jk = 1, jpkm1                                 ! Horizontal advective fluxes
+            DO jk = 1, jpkm1                       ! Horizontal advective fluxes
                DO jj = 2, jpjm1
                   DO ji = 1, fs_jpim1   ! vector opt.
@@ -140,9 +138,7 @@
          END SELECT
          !
-         !                             !==  Vertical fluxes  ==!
-         !
-         SELECT CASE( kn_cen_v )             !* interior fluxes
-         !
-         CASE(  2  )                               ! 2nd order centered
+         SELECT CASE( kn_cen_v )       !--  Vertical fluxes  --!   (interior)
+         !
+         CASE(  2  )                         !* 2nd order centered
             DO jk = 2, jpk
                DO jj = 2, jpjm1
@@ -153,6 +149,6 @@
             END DO
             !
-         CASE(  4  )                               ! 4th order centered
-            CALL interp_4th_cpt( ptn(:,:,:,jn) , ztw )         ! 4th order compact interpolation of T at w-point
+         CASE(  4  )                         !* 4th order compact
+            CALL interp_4th_cpt( ptn(:,:,:,jn) , ztw )      ! ztw = interpolated value of T at w-point
             DO jk = 2, jpkm1
                DO jj = 2, jpjm1
@@ -165,9 +161,9 @@
          END SELECT
          !
-         IF(.NOT.lk_vvl ) THEN               !* top value   (only in linear free surf. as zwz is multiplied by wmask)
+         IF( ln_linssh ) THEN                !* top value   (linear free surf. only as zwz is multiplied by wmask)
             IF( ln_isfcav ) THEN                  ! ice-shelf cavities (top of the ocean)
                DO jj = 1, jpj
                   DO ji = 1, jpi
-                     zwz(ji,jj, mikt(ji,jj) ) = pwn(ji,jj,mikt(ji,jj)) * ptn(ji,jj,mikt(ji,jj),jn)   ! linear free surface 
+                     zwz(ji,jj, mikt(ji,jj) ) = pwn(ji,jj,mikt(ji,jj)) * ptn(ji,jj,mikt(ji,jj),jn) 
                   END DO
                END DO   
@@ -183,9 +179,9 @@
                      &             - (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )    &
                      &                + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )    &
-                     &                + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1)  ) / ( e1e2t(ji,jj) *  fse3t_n(ji,jj,jk) )
+                     &                + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1)  ) * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                END DO
             END DO
          END DO
-         !                                 ! trend diagnostics
+         !                             ! trend diagnostics
          IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) ) THEN
             CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptn(:,:,:,jn) )
@@ -193,8 +189,8 @@
             CALL trd_tra( kt, cdtype, jn, jptra_zad, zwz, pwn, ptn(:,:,:,jn) )
          END IF
-         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
+         !                             ! "Poleward" heat and salt transports (contribution of upstream fluxes)
          IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
-           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) )
-           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) )
+           IF( jn == jp_tem )   htr_adv(:) = ptr_sj( zwy(:,:,:) )
+           IF( jn == jp_sal )   str_adv(:) = ptr_sj( zwy(:,:,:) )
          ENDIF
          !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_fct.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_fct.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_fct.F90	(revision 6140)
@@ -39,5 +39,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -53,14 +52,15 @@
       !!                  ***  ROUTINE tra_adv_fct  ***
       !! 
-      !! **  Purpose :   Compute the now trend due to total advection of 
-      !!       tracers and add it to the general trend of tracer equations
+      !! **  Purpose :   Compute the now trend due to total advection of tracers
+      !!               and add it to the general trend of tracer equations
       !!
       !! **  Method  : - 2nd or 4th FCT scheme on the horizontal direction
       !!               (choice through the value of kn_fct)
-      !!               - 4th order compact scheme on the vertical 
+      !!               - on the vertical the 4th order is a compact scheme 
       !!               - corrected flux (monotonic correction) 
       !!
-      !! ** Action : - update (pta) with the now advective tracer trends
-      !!             - send the trends for further diagnostics
+      !! ** Action : - update pta  with the now advective tracer trends
+      !!             - send trends to trdtra module for further diagnostcs (l_trdtra=T)
+      !!             - htr_adv, str_adv : poleward advective heat and salt transport (ln_diaptr=T)
       !!----------------------------------------------------------------------
       INTEGER                              , INTENT(in   ) ::   kt              ! ocean time-step index
@@ -70,5 +70,5 @@
       INTEGER                              , INTENT(in   ) ::   kn_fct_h        ! order of the FCT scheme (=2 or 4)
       INTEGER                              , INTENT(in   ) ::   kn_fct_v        ! order of the FCT scheme (=2 or 4)
-      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
+      REAL(wp)                             , INTENT(in   ) ::   p2dt            ! tracer time-step
       REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pun, pvn, pwn   ! 3 ocean velocity components
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb, ptn        ! before and now tracer fields
@@ -76,5 +76,5 @@
       !
       INTEGER  ::   ji, jj, jk, jn                           ! dummy loop indices  
-      REAL(wp) ::   z2dtt, ztra                              ! local scalar
+      REAL(wp) ::   ztra                                     ! local scalar
       REAL(wp) ::   zfp_ui, zfp_vj, zfp_wk, zC2t_u, zC4t_u   !   -      -
       REAL(wp) ::   zfm_ui, zfm_vj, zfm_wk, zC2t_v, zC4t_v   !   -      -
@@ -101,12 +101,11 @@
       ENDIF
       !
-      !                                         ! surface & bottom value : flux set to zero one for all
-      IF( lk_vvl )   zwz(:,:, 1 ) = 0._wp                ! except at the surface in linear free surface case
+      !                          ! surface & bottom value : flux set to zero one for all
+      zwz(:,:, 1 ) = 0._wp            
       zwx(:,:,jpk) = 0._wp   ;   zwy(:,:,jpk) = 0._wp    ;    zwz(:,:,jpk) = 0._wp
       !
       zwi(:,:,:) = 0._wp        
-      !                                                          ! ===========
-      DO jn = 1, kjpt                                            ! tracer loop
-         !                                                       ! ===========
+      !
+      DO jn = 1, kjpt            !==  loop over the tracers  ==!
          !
          !        !==  upstream advection with initial mass fluxes & intermediate update  ==!
@@ -126,5 +125,5 @@
          END DO
          !                    !* upstream tracer flux in the k direction *!
-         DO jk = 2, jpkm1         ! Interior value ( multiplied by wmask)
+         DO jk = 2, jpkm1        ! Interior value ( multiplied by wmask)
             DO jj = 1, jpj
                DO ji = 1, jpi
@@ -135,6 +134,5 @@
             END DO
          END DO
-         !                    
-         IF(.NOT.lk_vvl ) THEN   ! top ocean value (only in linear free surface as zwz has been w-masked)
+         IF( ln_linssh ) THEN    ! top ocean value (only in linear free surface as zwz has been w-masked)
             IF( ln_isfcav ) THEN             ! top of the ice-shelf cavities and at the ocean surface
                DO jj = 1, jpj
@@ -149,5 +147,4 @@
          !               
          DO jk = 1, jpkm1     !* trend and after field with monotonic scheme
-            z2dtt = p2dt(jk)
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -155,9 +152,9 @@
                   ztra = - (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
                      &      + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
-                     &      + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) ) / ( e1e2t(ji,jj) * fse3t_n(ji,jj,jk) )
+                     &      + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) ) * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                   ! update and guess with monotonic sheme
 !!gm why tmask added in the two following lines ???    the mask is done in tranxt !
                   pta(ji,jj,jk,jn) =   pta(ji,jj,jk,jn)         + ztra   * tmask(ji,jj,jk)
-                  zwi(ji,jj,jk)    = ( ptb(ji,jj,jk,jn) + z2dtt * ztra ) * tmask(ji,jj,jk)
+                  zwi(ji,jj,jk)    = ( ptb(ji,jj,jk,jn) + p2dt * ztra ) * tmask(ji,jj,jk)
                END DO
             END DO
@@ -174,10 +171,9 @@
          ENDIF
          !
-         !
          !        !==  anti-diffusive flux : high order minus low order  ==!
          !
-         SELECT CASE( kn_fct_h )         !* horizontal anti-diffusive fluxes
-         !
-         CASE(  2  )                         ! 2nd order centered
+         SELECT CASE( kn_fct_h )    !* horizontal anti-diffusive fluxes
+         !
+         CASE(  2  )                   !- 2nd order centered
             DO jk = 1, jpkm1
                DO jj = 1, jpjm1
@@ -189,9 +185,9 @@
             END DO
             !
-         CASE(  4  )                         ! 4th order centered
-            zltu(:,:,jpk) = 0._wp                            ! Bottom value : flux set to zero
+         CASE(  4  )                   !- 4th order centered
+            zltu(:,:,jpk) = 0._wp            ! Bottom value : flux set to zero
             zltv(:,:,jpk) = 0._wp
-            DO jk = 1, jpkm1                                 ! Laplacian
-               DO jj = 1, jpjm1                                   ! First derivative (gradient)
+            DO jk = 1, jpkm1                 ! Laplacian
+               DO jj = 1, jpjm1                    ! 1st derivative (gradient)
                   DO ji = 1, fs_jpim1   ! vector opt.
                      ztu(ji,jj,jk) = ( ptn(ji+1,jj  ,jk,jn) - ptn(ji,jj,jk,jn) ) * umask(ji,jj,jk)
@@ -199,5 +195,5 @@
                   END DO
                END DO
-               DO jj = 2, jpjm1                                   ! 
+               DO jj = 2, jpjm1                    ! 2nd derivative * 1/ 6
                   DO ji = fs_2, fs_jpim1   ! vector opt.
                      zltu(ji,jj,jk) = (  ztu(ji,jj,jk) + ztu(ji-1,jj,jk)  ) * r1_6
@@ -206,8 +202,7 @@
                END DO
             END DO
-            !
             CALL lbc_lnk( zltu, 'T', 1. )   ;    CALL lbc_lnk( zltv, 'T', 1. )   ! Lateral boundary cond. (unchanged sgn)
             !
-            DO jk = 1, jpkm1                                 ! Horizontal advective fluxes
+            DO jk = 1, jpkm1                 ! Horizontal advective fluxes
                DO jj = 1, jpjm1
                   DO ji = 1, fs_jpim1   ! vector opt.
@@ -221,9 +216,9 @@
             END DO         
             !
-         CASE(  41 )                         ! 4th order centered       ==>>   !!gm coding attempt   need to be tested
-            ztu(:,:,jpk) = 0._wp                             ! Bottom value : flux set to zero
+         CASE(  41 )                   !- 4th order centered       ==>>   !!gm coding attempt   need to be tested
+            ztu(:,:,jpk) = 0._wp             ! Bottom value : flux set to zero
             ztv(:,:,jpk) = 0._wp
-            DO jk = 1, jpkm1                                 ! gradient
-               DO jj = 1, jpjm1                                   ! First derivative (gradient)
+            DO jk = 1, jpkm1                 ! 1st derivative (gradient)
+               DO jj = 1, jpjm1
                   DO ji = 1, fs_jpim1   ! vector opt.
                      ztu(ji,jj,jk) = ( ptn(ji+1,jj  ,jk,jn) - ptn(ji,jj,jk,jn) ) * umask(ji,jj,jk)
@@ -234,5 +229,5 @@
             CALL lbc_lnk( ztu, 'U', -1. )   ;    CALL lbc_lnk( ztv, 'V', -1. )   ! Lateral boundary cond. (unchanged sgn)
             !
-            DO jk = 1, jpkm1                                 ! Horizontal advective fluxes
+            DO jk = 1, jpkm1                 ! Horizontal advective fluxes
                DO jj = 2, jpjm1
                   DO ji = 2, fs_jpim1   ! vector opt.
@@ -250,21 +245,19 @@
             !
          END SELECT
-         !                                !* vertical anti-diffusive fluxes
-         SELECT CASE( kn_fct_v )                ! Interior values (w-masked)
-         !
-         CASE(  2  )                                  ! 2nd order centered
+         !                      
+         SELECT CASE( kn_fct_v )    !* vertical anti-diffusive fluxes (w-masked interior values)
+         !
+         CASE(  2  )                   !- 2nd order centered
             DO jk = 2, jpkm1    
                DO jj = 2, jpjm1
                   DO ji = fs_2, fs_jpim1
-                     zwz(ji,jj,jk) =  ( 0.5_wp * pwn(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji,jj,jk-1,jn) )   &
-                                       - zwz(ji,jj,jk) ) * wmask(ji,jj,jk)
-                  END DO
-               END DO
-            END DO
-            !
-         CASE(  4  )                                  ! 4th order COMPACT
-            !    
-            CALL interp_4th_cpt( ptn(:,:,:,jn) , ztw )         ! COMPACT interpolation of T at w-point
-            !
+                     zwz(ji,jj,jk) =  (  pwn(ji,jj,jk) * 0.5_wp * ( ptn(ji,jj,jk,jn) + ptn(ji,jj,jk-1,jn) )   &
+                        &              - zwz(ji,jj,jk)  ) * wmask(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+            !
+         CASE(  4  )                   !- 4th order COMPACT
+            CALL interp_4th_cpt( ptn(:,:,:,jn) , ztw )   ! zwt = COMPACT interpolation of T at w-point
             DO jk = 2, jpkm1
                DO jj = 2, jpjm1
@@ -276,15 +269,15 @@
             !
          END SELECT
-         !                                      ! top ocean value: high order = upstream  ==>>  zwz=0
-         zwz(:,:, 1 ) = 0._wp                   ! only ocean surface as interior zwz values have been w-masked
+         IF( ln_linssh ) THEN    ! top ocean value: high order = upstream  ==>>  zwz=0
+            zwz(:,:,1) = 0._wp   ! only ocean surface as interior zwz values have been w-masked
+         ENDIF
          !
          CALL lbc_lnk( zwx, 'U', -1. )   ;   CALL lbc_lnk( zwy, 'V', -1. )         ! Lateral bondary conditions
          CALL lbc_lnk( zwz, 'W',  1. )
-
+         !
          !        !==  monotonicity algorithm  ==!
          !
          CALL nonosc( ptb(:,:,:,jn), zwx, zwy, zwz, zwi, p2dt )
-
-
+         !
          !        !==  final trend with corrected fluxes  ==!
          !
@@ -295,10 +288,10 @@
                      &                                   + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
                      &                                   + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) ) &
-                     &                                / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
-               END DO
-            END DO
-         END DO
-         !
-         IF( l_trd ) THEN                 ! trend diagnostics (contribution of upstream fluxes)
+                     &                                * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !
+         IF( l_trd ) THEN     ! trend diagnostics (contribution of upstream fluxes)
             ztrdx(:,:,:) = ztrdx(:,:,:) + zwx(:,:,:)  ! <<< Add to previously computed
             ztrdy(:,:,:) = ztrdy(:,:,:) + zwy(:,:,:)  ! <<< Add to previously computed
@@ -311,11 +304,11 @@
             CALL wrk_dealloc( jpi,jpj,jpk,   ztrdx, ztrdy, ztrdz )
          END IF
-         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
+         !                    ! "Poleward" heat and salt transports (contribution of upstream fluxes)
          IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
-           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) ) + htr_adv(:)
-           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) ) + str_adv(:)
+           IF( jn == jp_tem )   htr_adv(:) = htr_adv(:) + ptr_sj( zwy(:,:,:) )
+           IF( jn == jp_sal )   str_adv(:) = str_adv(:) + ptr_sj( zwy(:,:,:) )
          ENDIF
          !
-      END DO
+      END DO                     ! end of tracer loop
       !
       CALL wrk_dealloc( jpi,jpj,jpk,    zwi, zwx, zwy, zwz, ztu, ztv, zltu, zltv, ztw )
@@ -348,5 +341,5 @@
       INTEGER                              , INTENT(in   ) ::   kjpt            ! number of tracers
       INTEGER                              , INTENT(in   ) ::   kn_fct_zts      ! number of number of vertical sub-timesteps
-      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
+      REAL(wp)                             , INTENT(in   ) ::   p2dt            ! tracer time-step
       REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pun, pvn, pwn   ! 3 ocean velocity components
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb, ptn        ! before and now tracer fields
@@ -354,10 +347,10 @@
       !
       REAL(wp), DIMENSION( jpk )                           ::   zts             ! length of sub-timestep for vertical advection
-      REAL(wp), DIMENSION( jpk )                           ::   zr_p2dt         ! reciprocal of tracer timestep
+      REAL(wp)                                             ::   zr_p2dt         ! reciprocal of tracer timestep
       INTEGER  ::   ji, jj, jk, jl, jn       ! dummy loop indices  
       INTEGER  ::   jtb, jtn, jta   ! sub timestep pointers for leap-frog/euler forward steps
       INTEGER  ::   jtaken          ! toggle for collecting appropriate fluxes from sub timesteps
       REAL(wp) ::   z_rzts          ! Fractional length of Euler forward sub-timestep for vertical advection
-      REAL(wp) ::   z2dtt, ztra              ! local scalar
+      REAL(wp) ::   ztra            ! local scalar
       REAL(wp) ::   zfp_ui, zfp_vj, zfp_wk   !   -      -
       REAL(wp) ::   zfm_ui, zfm_vj, zfm_wk   !   -      -
@@ -390,18 +383,17 @@
       zwi(:,:,:) = 0._wp
       z_rzts = 1._wp / REAL( kn_fct_zts, wp )
-      zr_p2dt(:) = 1._wp / p2dt(:)
+      zr_p2dt = 1._wp / p2dt
+      !
+      ! surface & Bottom value : flux set to zero for all tracers
+      zwz(:,:, 1 ) = 0._wp
+      zwx(:,:,jpk) = 0._wp   ;    zwz(:,:,jpk) = 0._wp
+      zwy(:,:,jpk) = 0._wp   ;    zwi(:,:,jpk) = 0._wp
       !
       !                                                          ! ===========
       DO jn = 1, kjpt                                            ! tracer loop
          !                                                       ! ===========
-         ! 1. Bottom value : flux set to zero
-         ! ----------------------------------
-         zwx(:,:,jpk) = 0._wp   ;    zwz(:,:,jpk) = 0._wp
-         zwy(:,:,jpk) = 0._wp   ;    zwi(:,:,jpk) = 0._wp
-
-         ! 2. upstream advection with initial mass fluxes & intermediate update
-         ! --------------------------------------------------------------------
-         ! upstream tracer flux in the i and j direction
-         DO jk = 1, jpkm1
+         !
+         ! Upstream advection with initial mass fluxes & intermediate update
+         DO jk = 1, jpkm1        ! upstream tracer flux in the i and j direction
             DO jj = 1, jpjm1
                DO ji = 1, fs_jpim1   ! vector opt.
@@ -416,7 +408,6 @@
             END DO
          END DO
-
-         ! upstream tracer flux in the k direction
-         DO jk = 2, jpkm1         ! Interior value
+         !                       ! upstream tracer flux in the k direction
+         DO jk = 2, jpkm1              ! Interior value
             DO jj = 1, jpj
                DO ji = 1, jpi
@@ -427,9 +418,6 @@
             END DO
          END DO
-         !                       ! top value
-         IF( lk_vvl ) THEN             ! variable volume: only k=1 as zwz is multiplied by wmask
-            zwz(:,:, 1 ) = 0._wp
-         ELSE                          ! linear free surface
-            IF( ln_isfcav ) THEN             ! ice-shelf cavities
+         IF( ln_linssh ) THEN          ! top value : linear free surface case only (as zwz is multiplied by wmask)
+            IF( ln_isfcav ) THEN             ! ice-shelf cavities: top value
                DO jj = 1, jpj
                   DO ji = 1, jpi
@@ -437,5 +425,5 @@
                   END DO
                END DO   
-            ELSE                             ! standard case
+            ELSE                             ! no cavities, surface value
                zwz(:,:,1) = pwn(:,:,1) * ptb(:,:,1,jn)
             ENDIF
@@ -443,14 +431,13 @@
          !
          DO jk = 1, jpkm1         ! total advective trend
-            z2dtt = p2dt(jk)
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  ! total intermediate advective trends
+                  !                             ! total intermediate advective trends
                   ztra = - (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
                      &      + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
-                     &      + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) ) / ( e1e2t(ji,jj) * fse3t_n(ji,jj,jk) )
-                  ! update and guess with monotonic sheme
+                     &      + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1)   ) * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
+                  !                             ! update and guess with monotonic sheme
                   pta(ji,jj,jk,jn) =   pta(ji,jj,jk,jn)         + ztra
-                  zwi(ji,jj,jk)    = ( ptb(ji,jj,jk,jn) + z2dtt * ztra ) * tmask(ji,jj,jk)
+                  zwi(ji,jj,jk)    = ( ptb(ji,jj,jk,jn) + p2dt * ztra ) * tmask(ji,jj,jk)
                END DO
             END DO
@@ -497,10 +484,9 @@
             END DO
          END DO
-      
+         !
          !                                !* vertical anti-diffusive flux
          zwz_sav(:,:,:)   = zwz(:,:,:)
          ztrs   (:,:,:,1) = ptb(:,:,:,jn)
          zwzts  (:,:,:)   = 0._wp
-         IF( lk_vvl )   zwz(:,:, 1 ) = 0._wp    ! surface value set to zero in vvl case
          !
          DO jl = 1, kn_fct_zts                  ! Start of sub timestepping loop
@@ -508,5 +494,5 @@
             IF( jl == 1 ) THEN                        ! Euler forward to kick things off
                jtb = 1   ;   jtn = 1   ;   jta = 2
-               zts(:) = p2dt(:) * z_rzts
+               zts(:) = p2dt * z_rzts
                jtaken = MOD( kn_fct_zts + 1 , 2)            ! Toggle to collect every second flux
                !                                            ! starting at jl =1 if kn_fct_zts is odd; 
@@ -514,5 +500,5 @@
             ELSEIF( jl == 2 ) THEN                    ! First leapfrog step
                jtb = 1   ;   jtn = 2   ;   jta = 3
-               zts(:) = 2._wp * p2dt(:) * z_rzts
+               zts(:) = 2._wp * p2dt * z_rzts
             ELSE                                      ! Shuffle pointers for subsequent leapfrog steps
                jtb = MOD(jtb,3) + 1
@@ -528,5 +514,5 @@
                END DO
             END DO
-            IF(.NOT.lk_vvl ) THEN                    ! top value (only in linear free surface case)
+            IF( ln_linssh ) THEN                    ! top value (only in linear free surface case)
                IF( ln_isfcav ) THEN                      ! ice-shelf cavities
                   DO jj = 1, jpj
@@ -535,5 +521,5 @@
                      END DO
                   END DO   
-               ELSE                                      ! standard case
+               ELSE                                      ! no ocean cavities
                   zwz(:,:,1) = pwn(:,:,1) * ptb(:,:,1,jn)
                ENDIF
@@ -547,5 +533,5 @@
                      ztrs(ji,jj,jk,jta) = ztrs(ji,jj,jk,jtb)                                                 &
                         &               - zts(jk) * (  zhdiv(ji,jj,jk) + zwz(ji,jj,jk) - zwz(ji,jj,jk+1) )   &
-                        &                         / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
+                        &                         * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                   END DO
                END DO
@@ -557,5 +543,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1
-                  zwz(ji,jj,jk) = ( zwzts(ji,jj,jk) * zr_p2dt(jk) - zwz_sav(ji,jj,jk) ) * wmask(ji,jj,jk)
+                  zwz(ji,jj,jk) = ( zwzts(ji,jj,jk) * zr_p2dt - zwz_sav(ji,jj,jk) ) * wmask(ji,jj,jk)
                END DO
             END DO
@@ -576,5 +562,5 @@
                   pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + (   zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )       &
                      &                                    + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1)   )   &
-                     &                                / ( e1e2t(ji,jj) * fse3t_n(ji,jj,jk) )
+                     &                                * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                END DO
             END DO
@@ -623,5 +609,5 @@
       !!       in-space based differencing for fluid
       !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpk)         , INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
+      REAL(wp)                         , INTENT(in   ) ::   p2dt            ! tracer time-step
       REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pbef, paft      ! before & after field
       REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(inout) ::   paa, pbb, pcc   ! monotonic fluxes in the 3 directions
@@ -629,5 +615,5 @@
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
       INTEGER  ::   ikm1         ! local integer
-      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn, z2dtt   ! local scalars
+      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn    ! local scalars
       REAL(wp) ::   zau, zbu, zcu, zav, zbv, zcv, zup, zdo            !   -      -
       REAL(wp), POINTER, DIMENSION(:,:,:) :: zbetup, zbetdo, zbup, zbdo
@@ -652,5 +638,4 @@
       DO jk = 1, jpkm1
          ikm1 = MAX(jk-1,1)
-         z2dtt = p2dt(jk)
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -679,5 +664,5 @@
 
                ! up & down beta terms
-               zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) / z2dtt
+               zbt = e1e2t(ji,jj) * e3t_n(ji,jj,jk) / p2dt
                zbetup(ji,jj,jk) = ( zup            - paft(ji,jj,jk) ) / ( zpos + zrtrn ) * zbt
                zbetdo(ji,jj,jk) = ( paft(ji,jj,jk) - zdo            ) / ( zneg + zrtrn ) * zbt
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mle.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mle.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mle.F90	(revision 6140)
@@ -49,5 +49,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -125,5 +124,5 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               zc = fse3t(ji,jj,jk) * REAL( MIN( MAX( 0, inml_mle(ji,jj)-jk ) , 1  )  )    ! zc being 0 outside the ML t-points
+               zc = e3t_n(ji,jj,jk) * REAL( MIN( MAX( 0, inml_mle(ji,jj)-jk ) , 1  )  )    ! zc being 0 outside the ML t-points
                zmld(ji,jj) = zmld(ji,jj) + zc
                zbm (ji,jj) = zbm (ji,jj) + zc * (rau0 - rhop(ji,jj,jk) ) * r1_rau0
@@ -157,5 +156,5 @@
       END SELECT
       !                                                ! convert density into buoyancy
-      zbm(:,:) = + grav * zbm(:,:) / MAX( fse3t(:,:,1), zmld(:,:) )
+      zbm(:,:) = + grav * zbm(:,:) / MAX( e3t_n(:,:,1), zmld(:,:) )
       !
       !
@@ -215,6 +214,6 @@
          DO jj = 1, jpjm1
             DO ji = 1, fs_jpim1   ! vector opt.
-               zcuw = 1._wp - ( fsdepw(ji+1,jj,jk) + fsdepw(ji,jj,jk) ) * zhu(ji,jj)
-               zcvw = 1._wp - ( fsdepw(ji,jj+1,jk) + fsdepw(ji,jj,jk) ) * zhv(ji,jj)
+               zcuw = 1._wp - ( gdepw_n(ji+1,jj,jk) + gdepw_n(ji,jj,jk) ) * zhu(ji,jj)
+               zcvw = 1._wp - ( gdepw_n(ji,jj+1,jk) + gdepw_n(ji,jj,jk) ) * zhv(ji,jj)
                zcuw = zcuw * zcuw
                zcvw = zcvw * zcvw
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mus.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mus.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mus.F90	(revision 6140)
@@ -41,5 +41,4 @@
    
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -62,6 +61,7 @@
       !!              ld_msc_ups=T : 
       !!
-      !! ** Action  : - update (ta,sa) with the now advective tracer trends
-      !!              - send trends to trdtra module for further diagnostcs
+      !! ** Action : - update pta  with the now advective tracer trends
+      !!             - send trends to trdtra module for further diagnostcs (l_trdtra=T)
+      !!             - htr_adv, str_adv : poleward advective heat and salt transport (ln_diaptr=T)
       !!
       !! References : Estubier, A., and M. Levy, Notes Techn. Pole de Modelisation
@@ -73,5 +73,5 @@
       INTEGER                              , INTENT(in   ) ::   kjpt            ! number of tracers
       LOGICAL                              , INTENT(in   ) ::   ld_msc_ups      ! use upstream scheme within muscl
-      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
+      REAL(wp)                             , INTENT(in   ) ::   p2dt            ! tracer time-step
       REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pun, pvn, pwn   ! 3 ocean velocity components
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb             ! before tracer field
@@ -82,5 +82,5 @@
       REAL(wp) ::   zu, z0u, zzwx, zw    ! local scalars
       REAL(wp) ::   zv, z0v, zzwy, z0w   !   -      -
-      REAL(wp) ::   zdt, zalpha          !   -      -
+      REAL(wp) ::   zalpha               !   -      -
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   zslpx, zslpy   ! 3D workspace
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   zwx  , zwy     ! -      - 
@@ -116,13 +116,12 @@
       ENDIF 
       !      
-      !                                                     ! ===========
-      DO jn = 1, kjpt                                       ! tracer loop
-         !                                                  ! ===========
-         ! I. Horizontal advective fluxes
-         ! ------------------------------
-         ! first guess of the slopes
-         zwx(:,:,jpk) = 0.e0   ;   zwy(:,:,jpk) = 0.e0        ! bottom values
-         ! interior values
-         DO jk = 1, jpkm1
+      DO jn = 1, kjpt            !==  loop over the tracers  ==!
+         !
+         !                          !* Horizontal advective fluxes
+         !
+         !                                !-- first guess of the slopes
+         zwx(:,:,jpk) = 0._wp                   ! bottom values
+         zwy(:,:,jpk) = 0._wp  
+         DO jk = 1, jpkm1                       ! interior values
             DO jj = 1, jpjm1      
                DO ji = 1, fs_jpim1   ! vector opt.
@@ -132,10 +131,10 @@
            END DO
          END DO
-         !
-         CALL lbc_lnk( zwx, 'U', -1. )                        ! lateral boundary conditions on zwx, zwy   (changed sign)
+         CALL lbc_lnk( zwx, 'U', -1. )          ! lateral boundary conditions   (changed sign)
          CALL lbc_lnk( zwy, 'V', -1. )
-         !                                             !-- Slopes of tracer
-         zslpx(:,:,jpk) = 0.e0   ;   zslpy(:,:,jpk) = 0.e0    ! bottom values
-         DO jk = 1, jpkm1                                     ! interior values
+         !                                !-- Slopes of tracer
+         zslpx(:,:,jpk) = 0._wp                 ! bottom values
+         zslpy(:,:,jpk) = 0._wp
+         DO jk = 1, jpkm1                       ! interior values
             DO jj = 2, jpj
                DO ji = fs_2, jpi   ! vector opt.
@@ -148,5 +147,5 @@
          END DO
          !
-         DO jk = 1, jpkm1                                     ! Slopes limitation
+         DO jk = 1, jpkm1                 !-- Slopes limitation
             DO jj = 2, jpj
                DO ji = fs_2, jpi   ! vector opt.
@@ -161,7 +160,5 @@
          END DO
          !
-         !                                             !-- MUSCL horizontal advective fluxes
-         DO jk = 1, jpkm1                                     ! interior values
-            zdt  = p2dt(jk)
+         DO jk = 1, jpkm1                 !-- MUSCL horizontal advective fluxes
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -169,5 +166,5 @@
                   z0u = SIGN( 0.5, pun(ji,jj,jk) )
                   zalpha = 0.5 - z0u
-                  zu  = z0u - 0.5 * pun(ji,jj,jk) * zdt / ( e1e2u(ji,jj) * fse3u(ji,jj,jk) )
+                  zu  = z0u - 0.5 * pun(ji,jj,jk) * p2dt * r1_e1e2u(ji,jj) / e3u_n(ji,jj,jk)
                   zzwx = ptb(ji+1,jj,jk,jn) + xind(ji,jj,jk) * zu * zslpx(ji+1,jj,jk)
                   zzwy = ptb(ji  ,jj,jk,jn) + xind(ji,jj,jk) * zu * zslpx(ji  ,jj,jk)
@@ -176,5 +173,5 @@
                   z0v = SIGN( 0.5, pvn(ji,jj,jk) )
                   zalpha = 0.5 - z0v
-                  zv  = z0v - 0.5 * pvn(ji,jj,jk) * zdt / ( e1e2v(ji,jj) * fse3v(ji,jj,jk) )
+                  zv  = z0v - 0.5 * pvn(ji,jj,jk) * p2dt * r1_e1e2v(ji,jj) / e3v_n(ji,jj,jk)
                   zzwx = ptb(ji,jj+1,jk,jn) + xind(ji,jj,jk) * zv * zslpy(ji,jj+1,jk)
                   zzwy = ptb(ji,jj  ,jk,jn) + xind(ji,jj,jk) * zv * zslpy(ji,jj  ,jk)
@@ -185,14 +182,14 @@
          CALL lbc_lnk( zwx, 'U', -1. )   ;   CALL lbc_lnk( zwy, 'V', -1. )   ! lateral boundary conditions   (changed sign)
          !
-         DO jk = 1, jpkm1         ! Tracer flux divergence at t-point added to the general trend
+         DO jk = 1, jpkm1                 !-- Tracer advective trend
             DO jj = 2, jpjm1      
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) - ( zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )       &
                   &                                     + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  ) )     &
-                  &                                   / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  &                                   * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                END DO
            END DO
          END DO        
-         !                                 ! trend diagnostics (contribution of upstream fluxes)
+         !                                ! trend diagnostics
          IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR.   &
             &( cdtype == 'TRC' .AND. l_trdtrc )      )  THEN
@@ -200,19 +197,18 @@
             CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptb(:,:,:,jn) )
          END IF
-         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
+         !                                ! "Poleward" heat and salt transports
          IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
             IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) )
             IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) )
          ENDIF
-
-         ! II. Vertical advective fluxes
-         ! -----------------------------
+         !
+         !                          !* Vertical advective fluxes
+         !
          !                                !-- first guess of the slopes
          zwx(:,:, 1 ) = 0._wp                   ! surface & bottom boundary conditions
-         zwx(:,:,jpk) = 0._wp                   ! surface & bottom boundary conditions
-         DO jk = 2, jpkm1                                     ! interior values
+         zwx(:,:,jpk) = 0._wp
+         DO jk = 2, jpkm1                       ! interior values
             zwx(:,:,jk) = tmask(:,:,jk) * ( ptb(:,:,jk-1,jn) - ptb(:,:,jk,jn) )
          END DO
-
          !                                !-- Slopes of tracer
          zslpx(:,:,1) = 0._wp                   ! surface values
@@ -220,12 +216,11 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zslpx(ji,jj,jk) =                    ( zwx(ji,jj,jk) + zwx(ji,jj,jk+1) )   &
-                     &            * ( 0.25 + SIGN( 0.25, zwx(ji,jj,jk) * zwx(ji,jj,jk+1) ) )
-               END DO
-            END DO
-         END DO
-         !                                !-- Slopes limitation
-         DO jk = 2, jpkm1                       ! interior values
-            DO jj = 1, jpj
+                  zslpx(ji,jj,jk) =                     ( zwx(ji,jj,jk) + zwx(ji,jj,jk+1) )  &
+                     &            * (  0.25 + SIGN( 0.25, zwx(ji,jj,jk) * zwx(ji,jj,jk+1) )  )
+               END DO
+            END DO
+         END DO
+         DO jk = 2, jpkm1                 !-- Slopes limitation
+            DO jj = 1, jpj                      ! interior values
                DO ji = 1, jpi
                   zslpx(ji,jj,jk) = SIGN( 1., zslpx(ji,jj,jk) ) * MIN(    ABS( zslpx(ji,jj,jk  ) ),   &
@@ -235,12 +230,10 @@
             END DO
          END DO
-         !                                !-- vertical advective flux
-         DO jk = 1, jpkm1                       ! interior values
-            zdt  = p2dt(jk)
+         DO jk = 1, jpk-2                 !-- vertical advective flux
             DO jj = 2, jpjm1      
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   z0w = SIGN( 0.5, pwn(ji,jj,jk+1) )
                   zalpha = 0.5 + z0w
-                  zw  = z0w - 0.5 * pwn(ji,jj,jk+1) * zdt  / ( e1e2t(ji,jj) * fse3w(ji,jj,jk+1) )
+                  zw  = z0w - 0.5 * pwn(ji,jj,jk+1) * p2dt * r1_e1e2t(ji,jj) / e3w_n(ji,jj,jk+1)
                   zzwx = ptb(ji,jj,jk+1,jn) + xind(ji,jj,jk) * zw * zslpx(ji,jj,jk+1)
                   zzwy = ptb(ji,jj,jk  ,jn) + xind(ji,jj,jk) * zw * zslpx(ji,jj,jk  )
@@ -249,9 +242,6 @@
             END DO
          END DO
-         !                                      ! top values  (bottom already set to zero)
-         IF( lk_vvl ) THEN                            !  variable volume
-            zwx(:,:, 1 ) = 0._wp                            ! k=1 only as zwx has been multiplied by wmask
-         ELSE                                         ! linear free surface 
-            IF( ln_isfcav ) THEN                            ! ice-shelf cavities (top of the ocean)
+         IF( ln_linssh ) THEN                   ! top values, linear free surface only
+            IF( ln_isfcav ) THEN                      ! ice-shelf cavities (top of the ocean)
                DO jj = 1, jpj
                   DO ji = 1, jpi
@@ -259,22 +249,22 @@
                   END DO
                END DO   
-            ELSE                                             ! no cavities: only at the ocean surface
+            ELSE                                      ! no cavities: only at the ocean surface
                zwx(:,:,1) = pwn(:,:,1) * ptb(:,:,1,jn)
             ENDIF
          ENDIF
          !
-         DO jk = 1, jpkm1                    ! Compute & add the vertical advective trend
+         DO jk = 1, jpkm1                 !-- vertical advective trend
             DO jj = 2, jpjm1      
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  pta(ji,jj,jk,jn) =  pta(ji,jj,jk,jn) - ( zwx(ji,jj,jk) - zwx(ji,jj,jk+1) ) / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
-               END DO
-            END DO
-         END DO
-         !                                 ! Save the vertical advective trends for diagnostic
+                  pta(ji,jj,jk,jn) =  pta(ji,jj,jk,jn) - ( zwx(ji,jj,jk) - zwx(ji,jj,jk+1) ) * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !                                ! send trends for diagnostic
          IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR.     &
             &( cdtype == 'TRC' .AND. l_trdtrc )      )   &
             CALL trd_tra( kt, cdtype, jn, jptra_zad, zwx, pwn, ptb(:,:,:,jn) )
          !
-      END DO
+      END DO                     ! end of tracer loop
       !
       CALL wrk_dealloc( jpi,jpj,jpk,   zslpx, zslpy, zwx, zwy )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_qck.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_qck.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_qck.F90	(revision 6140)
@@ -38,5 +38,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -78,6 +77,7 @@
       !!            prevent the appearance of spurious numerical oscillations
       !!
-      !! ** Action : - update (pta) with the now advective tracer trends
-      !!             - save the trends 
+      !! ** Action : - update pta  with the now advective tracer trends
+      !!             - send trends to trdtra module for further diagnostcs (l_trdtra=T)
+      !!             - htr_adv, str_adv : poleward advective heat and salt transport (ln_diaptr=T)
       !!
       !! ** Reference : Leonard (1979, 1991)
@@ -87,5 +87,5 @@
       CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype          ! =TRA or TRC (tracer indicator)
       INTEGER                              , INTENT(in   ) ::   kjpt            ! number of tracers
-      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
+      REAL(wp)                             , INTENT(in   ) ::   p2dt            ! tracer time-step
       REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pun, pvn, pwn   ! 3 ocean velocity components
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb, ptn        ! before and now tracer fields
@@ -105,9 +105,9 @@
       IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) )   l_trd = .TRUE.
       !
-      ! I. The horizontal fluxes are computed with the QUICKEST + ULTIMATE scheme
+      !        ! horizontal fluxes are computed with the QUICKEST + ULTIMATE scheme
       CALL tra_adv_qck_i( kt, cdtype, p2dt, pun, ptb, ptn, pta, kjpt ) 
       CALL tra_adv_qck_j( kt, cdtype, p2dt, pvn, ptb, ptn, pta, kjpt ) 
 
-      ! II. The vertical fluxes are computed with the 2nd order centered scheme
+      !        ! vertical fluxes are computed with the 2nd order centered scheme
       CALL tra_adv_cen2_k( kt, cdtype, pwn,         ptn, pta, kjpt )
       !
@@ -125,5 +125,5 @@
       CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype     ! =TRA or TRC (tracer indicator)
       INTEGER                              , INTENT(in   ) ::   kjpt       ! number of tracers
-      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt       ! vertical profile of tracer time-step
+      REAL(wp)                             , INTENT(in   ) ::   p2dt       ! tracer time-step
       REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pun        ! i-velocity components
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb, ptn   ! before and now tracer fields
@@ -131,5 +131,5 @@
       !!
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
-      REAL(wp) ::   ztra, zbtr, zdir, zdx, zdt, zmsk   ! local scalars
+      REAL(wp) ::   ztra, zbtr, zdir, zdx, zmsk   ! local scalars
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   zwx, zfu, zfc, zfd
       !----------------------------------------------------------------------
@@ -166,10 +166,9 @@
          !
          DO jk = 1, jpkm1  
-            zdt =  p2dt(jk)
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.   
                   zdir = 0.5 + SIGN( 0.5, pun(ji,jj,jk) )   ! if pun > 0 : zdir = 1 otherwise zdir = 0 
-                  zdx = ( zdir * e1t(ji,jj) + ( 1. - zdir ) * e1t(ji+1,jj) ) * e2u(ji,jj) * fse3u(ji,jj,jk)
-                  zwx(ji,jj,jk)  = ABS( pun(ji,jj,jk) ) * zdt / zdx    ! (0<zc_cfl<1 : Courant number on x-direction)
+                  zdx = ( zdir * e1t(ji,jj) + ( 1. - zdir ) * e1t(ji+1,jj) ) * e2u(ji,jj) * e3u_n(ji,jj,jk)
+                  zwx(ji,jj,jk)  = ABS( pun(ji,jj,jk) ) * p2dt / zdx    ! (0<zc_cfl<1 : Courant number on x-direction)
                   zfc(ji,jj,jk)  = zdir * ptb(ji  ,jj,jk,jn) + ( 1. - zdir ) * ptb(ji+1,jj,jk,jn)  ! FC in the x-direction for T
                   zfd(ji,jj,jk)  = zdir * ptb(ji+1,jj,jk,jn) + ( 1. - zdir ) * ptb(ji  ,jj,jk,jn)  ! FD in the x-direction for T
@@ -216,5 +215,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.  
-                  zbtr = 1. / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  zbtr = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                   ! horizontal advective trends
                   ztra = - zbtr * ( zwx(ji,jj,jk) - zwx(ji-1,jj,jk) )
@@ -224,5 +223,5 @@
             END DO
          END DO
-         !                                 ! trend diagnostics (contribution of upstream fluxes)
+         !                                 ! trend diagnostics
          IF( l_trd )   CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptn(:,:,:,jn) )
          !
@@ -242,5 +241,5 @@
       CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype     ! =TRA or TRC (tracer indicator)
       INTEGER                              , INTENT(in   ) ::   kjpt       ! number of tracers
-      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt       ! vertical profile of tracer time-step
+      REAL(wp)                             , INTENT(in   ) ::   p2dt       ! tracer time-step
       REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pvn        ! j-velocity components
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb, ptn   ! before and now tracer fields
@@ -248,5 +247,5 @@
       !!
       INTEGER  :: ji, jj, jk, jn   ! dummy loop indices
-      REAL(wp) :: ztra, zbtr, zdir, zdx, zdt, zmsk   ! local scalars
+      REAL(wp) :: ztra, zbtr, zdir, zdx, zmsk   ! local scalars
       REAL(wp), POINTER, DIMENSION(:,:,:) :: zwy, zfu, zfc, zfd
       !----------------------------------------------------------------------
@@ -289,10 +288,9 @@
          !
          DO jk = 1, jpkm1  
-            zdt =  p2dt(jk)
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.   
                   zdir = 0.5 + SIGN( 0.5, pvn(ji,jj,jk) )   ! if pun > 0 : zdir = 1 otherwise zdir = 0 
-                  zdx = ( zdir * e2t(ji,jj) + ( 1. - zdir ) * e2t(ji,jj+1) ) * e1v(ji,jj) * fse3v(ji,jj,jk)
-                  zwy(ji,jj,jk)  = ABS( pvn(ji,jj,jk) ) * zdt / zdx    ! (0<zc_cfl<1 : Courant number on x-direction)
+                  zdx = ( zdir * e2t(ji,jj) + ( 1. - zdir ) * e2t(ji,jj+1) ) * e1v(ji,jj) * e3v_n(ji,jj,jk)
+                  zwy(ji,jj,jk)  = ABS( pvn(ji,jj,jk) ) * p2dt / zdx    ! (0<zc_cfl<1 : Courant number on x-direction)
                   zfc(ji,jj,jk)  = zdir * ptb(ji,jj  ,jk,jn) + ( 1. - zdir ) * ptb(ji,jj+1,jk,jn)  ! FC in the x-direction for T
                   zfd(ji,jj,jk)  = zdir * ptb(ji,jj+1,jk,jn) + ( 1. - zdir ) * ptb(ji,jj  ,jk,jn)  ! FD in the x-direction for T
@@ -340,5 +338,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.  
-                  zbtr = 1. / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  zbtr = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                   ! horizontal advective trends
                   ztra = - zbtr * ( zwy(ji,jj,jk) - zwy(ji,jj-1,jk) )
@@ -348,5 +346,5 @@
             END DO
          END DO
-         !                                 ! trend diagnostics (contribution of upstream fluxes)
+         !                                 ! trend diagnostics
          IF( l_trd )   CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptn(:,:,:,jn) )
          !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
@@ -381,7 +379,6 @@
       CALL wrk_alloc( jpi,jpj,jpk,   zwz )
       !
-      !                          ! surface & bottom values 
-      IF( lk_vvl )   zwz(:,:, 1 ) = 0._wp             ! set to zero one for all
-                     zwz(:,:,jpk) = 0._wp             ! except at the surface in linear free surface
+      zwz(:,:, 1 ) = 0._wp       ! surface & bottom values set to zero for all tracers
+      zwz(:,:,jpk) = 0._wp
       !
       !                                                          ! ===========
@@ -396,5 +393,5 @@
             END DO
          END DO
-         IF(.NOT.lk_vvl ) THEN               !* top value   (only in linear free surf. as zwz is multiplied by wmask)
+         IF( ln_linssh ) THEN                !* top value   (only in linear free surf. as zwz is multiplied by wmask)
             IF( ln_isfcav ) THEN                  ! ice-shelf cavities (top of the ocean)
                DO jj = 1, jpj
@@ -403,5 +400,5 @@
                   END DO
                END DO   
-            ELSE                                   ! no ice-shelf cavities (only ocean surface)
+            ELSE                                   ! no ocean cavities (only ocean surface)
                zwz(:,:,1) = pwn(:,:,1) * ptn(:,:,1,jn)
             ENDIF
@@ -412,14 +409,14 @@
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) - ( zwz(ji,jj,jk) - zwz(ji,jj,jk+1) )   &
-                     &                                / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
-               END DO
-            END DO
-         END DO
-         !                                 ! Save the vertical advective trends for diagnostic
+                     &                                * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !                                 ! Send trends for diagnostic
          IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_zad, zwz, pwn, ptn(:,:,:,jn) )
          !
       END DO
       !
-      CALL wrk_dealloc( jpi, jpj, jpk, zwz )
+      CALL wrk_dealloc( jpi,jpj,jpk,   zwz )
       !
    END SUBROUTINE tra_adv_cen2_k
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_ubs.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_ubs.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_ubs.F90	(revision 6140)
@@ -35,5 +35,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -71,9 +70,11 @@
       !!                On the vertical, the advection is evaluated using a FCT scheme,
       !!      as the UBS have been found to be too diffusive. 
-!!gm  !!                kn_ubs_v argument (not coded for the moment)
-      !!      controles whether the FCT is based on a 2nd order centrered scheme (kn_ubs_v=2) 
-      !!      or on a 4th order compact scheme (kn_ubs_v=4).
+      !!                kn_ubs_v argument controles whether the FCT is based on 
+      !!      a 2nd order centrered scheme (kn_ubs_v=2) or on a 4th order compact 
+      !!      scheme (kn_ubs_v=4).
       !!
-      !! ** Action : - update (pta) with the now advective tracer trends
+      !! ** Action : - update pta  with the now advective tracer trends
+      !!             - send trends to trdtra module for further diagnostcs (l_trdtra=T)
+      !!             - htr_adv, str_adv : poleward advective heat and salt transport (ln_diaptr=T)
       !!
       !! Reference : Shchepetkin, A. F., J. C. McWilliams, 2005, Ocean Modelling, 9, 347-404. 
@@ -85,5 +86,5 @@
       INTEGER                              , INTENT(in   ) ::   kjpt            ! number of tracers
       INTEGER                              , INTENT(in   ) ::   kn_ubs_v        ! number of tracers
-      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
+      REAL(wp)                             , INTENT(in   ) ::   p2dt            ! tracer time-step
       REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pun, pvn, pwn   ! 3 ocean transport components
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb, ptn        ! before and now tracer fields
@@ -91,5 +92,5 @@
       !
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
-      REAL(wp) ::   ztra, zbtr, zcoef, z2dtt                       ! local scalars
+      REAL(wp) ::   ztra, zbtr, zcoef                       ! local scalars
       REAL(wp) ::   zfp_ui, zfm_ui, zcenut, ztak, zfp_wk, zfm_wk   !   -      -
       REAL(wp) ::   zfp_vj, zfm_vj, zcenvt, zeeu, zeev, z_hdivn    !   -      -
@@ -110,7 +111,7 @@
       IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) ) l_trd = .TRUE.
       !
-      zltu(:,:,jpk) = 0._wp   ;   zltv(:,:,jpk) = 0._wp     ! Bottom value : set to zero one for all
+      ztw (:,:, 1 ) = 0._wp      ! surface & bottom value : set to zero for all tracers
+      zltu(:,:,jpk) = 0._wp   ;   zltv(:,:,jpk) = 0._wp
       ztw (:,:,jpk) = 0._wp   ;   zti (:,:,jpk) = 0._wp
-      IF( lk_vvl )   ztw(:,:, 1 ) = 0._wp                   ! surface value: set to zero only in vvl case
       !
       !                                                          ! ===========
@@ -121,6 +122,6 @@
             DO jj = 1, jpjm1              ! First derivative (masked gradient)
                DO ji = 1, fs_jpim1   ! vector opt.
-                  zeeu = e2_e1u(ji,jj) * fse3u(ji,jj,jk) * umask(ji,jj,jk)
-                  zeev = e1_e2v(ji,jj) * fse3v(ji,jj,jk) * vmask(ji,jj,jk)
+                  zeeu = e2_e1u(ji,jj) * e3u_n(ji,jj,jk) * umask(ji,jj,jk)
+                  zeev = e1_e2v(ji,jj) * e3v_n(ji,jj,jk) * vmask(ji,jj,jk)
                   ztu(ji,jj,jk) = zeeu * ( ptb(ji+1,jj  ,jk,jn) - ptb(ji,jj,jk,jn) )
                   ztv(ji,jj,jk) = zeev * ( ptb(ji  ,jj+1,jk,jn) - ptb(ji,jj,jk,jn) )
@@ -129,5 +130,5 @@
             DO jj = 2, jpjm1              ! Second derivative (divergence)
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zcoef = 1._wp / ( 6._wp * fse3t(ji,jj,jk) )
+                  zcoef = 1._wp / ( 6._wp * e3t_n(ji,jj,jk) )
                   zltu(ji,jj,jk) = (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk)  ) * zcoef
                   zltv(ji,jj,jk) = (  ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  ) * zcoef
@@ -162,5 +163,5 @@
                   pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn)                        &
                      &             - (  ztu(ji,jj,jk) - ztu(ji-1,jj  ,jk)    &
-                     &                + ztv(ji,jj,jk) - ztv(ji  ,jj-1,jk)  ) / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
+                     &                + ztv(ji,jj,jk) - ztv(ji  ,jj-1,jk)  ) * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                END DO
             END DO
@@ -199,5 +200,5 @@
                END DO
             END DO 
-            IF(.NOT.lk_vvl ) THEN            ! top ocean value (only in linear free surface as ztw has been w-masked)
+            IF( ln_linssh ) THEN             ! top ocean value (only in linear free surface as ztw has been w-masked)
                IF( ln_isfcav ) THEN                ! top of the ice-shelf cavities and at the ocean surface
                   DO jj = 1, jpj
@@ -212,10 +213,9 @@
             !
             DO jk = 1, jpkm1           !* trend and after field with monotonic scheme
-               z2dtt = p2dt(jk)
                DO jj = 2, jpjm1
                   DO ji = fs_2, fs_jpim1   ! vector opt.
-                     ztak = - ( ztw(ji,jj,jk) - ztw(ji,jj,jk+1) ) / ( e1e2t(ji,jj) * fse3t_n(ji,jj,jk) )
+                     ztak = - ( ztw(ji,jj,jk) - ztw(ji,jj,jk+1) ) * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                      pta(ji,jj,jk,jn) =   pta(ji,jj,jk,jn) +  ztak 
-                     zti(ji,jj,jk)    = ( ptb(ji,jj,jk,jn) + z2dtt * ( ztak + zltu(ji,jj,jk) ) ) * tmask(ji,jj,jk)
+                     zti(ji,jj,jk)    = ( ptb(ji,jj,jk,jn) + p2dt * ( ztak + zltu(ji,jj,jk) ) ) * tmask(ji,jj,jk)
                   END DO
                END DO
@@ -233,5 +233,5 @@
             END DO
             !                                            ! top ocean value: high order == upstream  ==>>  zwz=0
-            IF(.NOT.lk_vvl )   ztw(:,:, 1 ) = 0._wp      ! only ocean surface as interior zwz values have been w-masked
+            IF( ln_linssh )   ztw(:,:, 1 ) = 0._wp       ! only ocean surface as interior zwz values have been w-masked
             !
             CALL nonosc_z( ptb(:,:,:,jn), ztw, zti, p2dt )      !  monotonicity algorithm
@@ -246,5 +246,5 @@
                END DO
             END DO
-            IF(.NOT.lk_vvl )   ztw(:,:, 1 ) = pwn(:,:,1) * ptn(:,:,1,jn)     !!gm ISF & 4th COMPACT doesn't work
+            IF( ln_linssh )   ztw(:,:, 1 ) = pwn(:,:,1) * ptn(:,:,1,jn)     !!gm ISF & 4th COMPACT doesn't work
             !
          END SELECT
@@ -253,5 +253,5 @@
             DO jj = 2, jpjm1 
                DO ji = fs_2, fs_jpim1   ! vector opt.   
-                  pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) - ( ztw(ji,jj,jk) - ztw(ji,jj,jk+1) ) / ( e1e2t(ji,jj) * fse3t_n(ji,jj,jk) )
+                  pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) - ( ztw(ji,jj,jk) - ztw(ji,jj,jk+1) ) * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                END DO
             END DO
@@ -264,5 +264,5 @@
                      zltv(ji,jj,jk) = pta(ji,jj,jk,jn) - zltv(ji,jj,jk)                          &
                         &           + ptn(ji,jj,jk,jn) * (  pwn(ji,jj,jk) - pwn(ji,jj,jk+1)  )   &
-                        &                              / ( e1e2t(ji,jj) * fse3t_n(ji,jj,jk) )
+                        &                              * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                   END DO
                END DO
@@ -293,5 +293,5 @@
       !!       in-space based differencing for fluid
       !!----------------------------------------------------------------------
-      REAL(wp), INTENT(in   ), DIMENSION(jpk)          ::   p2dt   ! vertical profile of tracer time-step
+      REAL(wp), INTENT(in   )                          ::   p2dt   ! tracer time-step
       REAL(wp),                DIMENSION (jpi,jpj,jpk) ::   pbef   ! before field
       REAL(wp), INTENT(inout), DIMENSION (jpi,jpj,jpk) ::   paft   ! after field
@@ -300,5 +300,5 @@
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
       INTEGER  ::   ikm1         ! local integer
-      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn, z2dtt   ! local scalars
+      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn   ! local scalars
       REAL(wp), POINTER, DIMENSION(:,:,:) :: zbetup, zbetdo
       !!----------------------------------------------------------------------
@@ -349,5 +349,4 @@
       ! ---------------------------------------------------
       DO jk = 1, jpkm1
-         z2dtt = p2dt(jk)
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -356,5 +355,5 @@
                zneg = MAX( 0., pcc(ji  ,jj  ,jk  ) ) - MIN( 0., pcc(ji  ,jj  ,jk+1) )
                ! up & down beta terms
-               zbt = e1e2t(ji,jj) * fse3t(ji,jj,jk) / z2dtt
+               zbt = e1e2t(ji,jj) * e3t_n(ji,jj,jk) / p2dt
                zbetup(ji,jj,jk) = ( zbetup(ji,jj,jk) - paft(ji,jj,jk) ) / (zpos+zrtrn) * zbt
                zbetdo(ji,jj,jk) = ( paft(ji,jj,jk) - zbetdo(ji,jj,jk) ) / (zneg+zrtrn) * zbt
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 6140)
@@ -12,20 +12,21 @@
 
    !!----------------------------------------------------------------------
-   !!   tra_bbc      : update the tracer trend at ocean bottom 
-   !!   tra_bbc_init : initialization of geothermal heat flux trend
+   !!   tra_bbc       : update the tracer trend at ocean bottom 
+   !!   tra_bbc_init  : initialization of geothermal heat flux trend
    !!----------------------------------------------------------------------
-   USE oce             ! ocean variables
-   USE dom_oce         ! domain: ocean
-   USE phycst          ! physical constants
-   USE trd_oce         ! trends: ocean variables
-   USE trdtra          ! trends manager: tracers 
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O manager
-   USE fldread         ! read input fields
-   USE lbclnk            ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp           ! distributed memory computing library
-   USE prtctl          ! Print control
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE oce            ! ocean variables
+   USE dom_oce        ! domain: ocean
+   USE phycst         ! physical constants
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! trends manager: tracers 
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! xIOS 
+   USE fldread        ! read input fields
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp        ! distributed memory computing library
+   USE prtctl         ! Print control
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -40,9 +41,8 @@
    REAL(wp)        ::   rn_geoflx_cst !  Constant value of geothermal heat flux
 
-   REAL(wp), PUBLIC, DIMENSION(:,:), ALLOCATABLE ::   qgh_trd0   ! geothermal heating trend
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_qgh              ! structure of input qgh (file informations, fields read)
+   REAL(wp), PUBLIC , ALLOCATABLE, DIMENSION(:,:) ::   qgh_trd0   ! geothermal heating trend
+
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_qgh   ! structure of input qgh (file informations, fields read)
  
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -68,6 +68,6 @@
       !!       Where Qsf is the geothermal heat flux.
       !!
-      !! ** Action  : - update the temperature trends (ta) with the trend of
-      !!                the ocean bottom boundary condition
+      !! ** Action  : - update the temperature trends with geothermal heating trend
+      !!              - send the trend for further diagnostics (ln_trdtra=T)
       !!
       !! References : Stein, C. A., and S. Stein, 1992, Nature, 359, 123-129.
@@ -75,7 +75,6 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      !!
-      INTEGER  ::   ji, jj, ik    ! dummy loop indices
-      REAL(wp) ::   zqgh_trd      ! geothermal heat flux trend
+      !
+      INTEGER  ::   ji, jj    ! dummy loop indices
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrdt
       !!----------------------------------------------------------------------
@@ -83,15 +82,12 @@
       IF( nn_timing == 1 )  CALL timing_start('tra_bbc')
       !
-      IF( l_trdtra )   THEN         ! Save ta and sa trends
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdt )
+      IF( l_trdtra )   THEN         ! Save the input temperature trend
+         CALL wrk_alloc( jpi,jpj,jpk,   ztrdt )
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
       ENDIF
-      !
-      !                             !  Add the geothermal heat flux trend on temperature
+      !                             !  Add the geothermal trend on temperature
       DO jj = 2, jpjm1
          DO ji = 2, jpim1
-            ik = mbkt(ji,jj)
-            zqgh_trd = qgh_trd0(ji,jj) / fse3t(ji,jj,ik)
-            tsa(ji,jj,ik,jp_tem) = tsa(ji,jj,ik,jp_tem) + zqgh_trd
+            tsa(ji,jj,mbkt(ji,jj),jp_tem) = tsa(ji,jj,mbkt(ji,jj),jp_tem) + qgh_trd0(ji,jj) / e3t_n(ji,jj,mbkt(ji,jj))
          END DO
       END DO
@@ -99,8 +95,8 @@
       CALL lbc_lnk( tsa(:,:,:,jp_tem) , 'T', 1. )
       !
-      IF( l_trdtra ) THEN        ! Save the geothermal heat flux trend for diagnostics
+      IF( l_trdtra ) THEN        ! Send the trend for diagnostics
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_bbc, ztrdt )
-         CALL wrk_dealloc( jpi, jpj, jpk, ztrdt )
+         CALL wrk_dealloc( jpi,jpj,jpk,   ztrdt )
       ENDIF
       !
@@ -127,6 +123,4 @@
       !! ** Action  : - read/fix the geothermal heat qgh_trd0
       !!----------------------------------------------------------------------
-      USE iom
-      !!
       INTEGER  ::   ji, jj              ! dummy loop indices
       INTEGER  ::   inum                ! temporary logical unit
@@ -139,14 +133,14 @@
       NAMELIST/nambbc/ln_trabbc, nn_geoflx, rn_geoflx_cst, sn_qgh, cn_dir 
       !!----------------------------------------------------------------------
-
+      !
       REWIND( numnam_ref )              ! Namelist nambbc in reference namelist : Bottom momentum boundary condition
       READ  ( numnam_ref, nambbc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambbc in reference namelist', lwp )
-
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambbc in reference namelist', lwp )
+      !
       REWIND( numnam_cfg )              ! Namelist nambbc in configuration namelist : Bottom momentum boundary condition
       READ  ( numnam_cfg, nambbc, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambbc in configuration namelist', lwp )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambbc in configuration namelist', lwp )
       IF(lwm) WRITE ( numond, nambbc )
-
+      !
       IF(lwp) THEN                     ! Control print
          WRITE(numout,*)
@@ -159,5 +153,5 @@
          WRITE(numout,*)
       ENDIF
-
+      !
       IF( ln_trabbc ) THEN             !==  geothermal heating  ==!
          !
@@ -190,5 +184,4 @@
             WRITE(ctmp1,*) '     bad flag value for nn_geoflx = ', nn_geoflx
             CALL ctl_stop( ctmp1 )
-            !
          END SELECT
          !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 6140)
@@ -70,5 +70,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -112,5 +111,5 @@
       IF( nn_timing == 1 )  CALL timing_start( 'tra_bbl')
       !
-      IF( l_trdtra )   THEN                         !* Save ta and sa trends
+      IF( l_trdtra )   THEN                         !* Save the input trends
          CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds )
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
@@ -132,5 +131,5 @@
          !
       END IF
-
+      !
       IF( nn_bbl_adv /= 0 ) THEN                    !* Advective bbl
          !
@@ -146,5 +145,5 @@
       END IF
 
-      IF( l_trdtra )   THEN                      ! save the horizontal diffusive trends for further diagnostics
+      IF( l_trdtra )   THEN                      ! send the trends for further diagnostics
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
@@ -211,5 +210,5 @@
                   &                + ahv_bbl(ji  ,jj  ) * ( zptb(ji  ,jj+1) - zptb(ji  ,jj  ) )     &
                   &                - ahv_bbl(ji  ,jj-1) * ( zptb(ji  ,jj  ) - zptb(ji  ,jj-1) )  )  &
-                  &             / ( e1e2t(ji,jj) * fse3t(ji,jj,ik) )
+                  &             * r1_e1e2t(ji,jj) / e3t_n(ji,jj,ik)
             END DO
          END DO
@@ -263,15 +262,15 @@
                   !
                   !                                               ! up  -slope T-point (shelf bottom point)
-                  zbtr = r1_e1e2t(iis,jj) / fse3t(iis,jj,ikus)
+                  zbtr = r1_e1e2t(iis,jj) / e3t_n(iis,jj,ikus)
                   ztra = zu_bbl * ( ptb(iid,jj,ikus,jn) - ptb(iis,jj,ikus,jn) ) * zbtr
                   pta(iis,jj,ikus,jn) = pta(iis,jj,ikus,jn) + ztra
                   !
                   DO jk = ikus, ikud-1                            ! down-slope upper to down T-point (deep column)
-                     zbtr = r1_e1e2t(iid,jj) / fse3t(iid,jj,jk)
+                     zbtr = r1_e1e2t(iid,jj) / e3t_n(iid,jj,jk)
                      ztra = zu_bbl * ( ptb(iid,jj,jk+1,jn) - ptb(iid,jj,jk,jn) ) * zbtr
                      pta(iid,jj,jk,jn) = pta(iid,jj,jk,jn) + ztra
                   END DO
                   !
-                  zbtr = r1_e1e2t(iid,jj) / fse3t(iid,jj,ikud)
+                  zbtr = r1_e1e2t(iid,jj) / e3t_n(iid,jj,ikud)
                   ztra = zu_bbl * ( ptb(iis,jj,ikus,jn) - ptb(iid,jj,ikud,jn) ) * zbtr
                   pta(iid,jj,ikud,jn) = pta(iid,jj,ikud,jn) + ztra
@@ -285,15 +284,15 @@
                   !
                   ! up  -slope T-point (shelf bottom point)
-                  zbtr = r1_e1e2t(ji,ijs) / fse3t(ji,ijs,ikvs)
+                  zbtr = r1_e1e2t(ji,ijs) / e3t_n(ji,ijs,ikvs)
                   ztra = zv_bbl * ( ptb(ji,ijd,ikvs,jn) - ptb(ji,ijs,ikvs,jn) ) * zbtr
                   pta(ji,ijs,ikvs,jn) = pta(ji,ijs,ikvs,jn) + ztra
                   !
                   DO jk = ikvs, ikvd-1                            ! down-slope upper to down T-point (deep column)
-                     zbtr = r1_e1e2t(ji,ijd) / fse3t(ji,ijd,jk)
+                     zbtr = r1_e1e2t(ji,ijd) / e3t_n(ji,ijd,jk)
                      ztra = zv_bbl * ( ptb(ji,ijd,jk+1,jn) - ptb(ji,ijd,jk,jn) ) * zbtr
                      pta(ji,ijd,jk,jn) = pta(ji,ijd,jk,jn)  + ztra
                   END DO
                   !                                               ! down-slope T-point (deep bottom point)
-                  zbtr = r1_e1e2t(ji,ijd) / fse3t(ji,ijd,ikvd)
+                  zbtr = r1_e1e2t(ji,ijd) / e3t_n(ji,ijd,ikvd)
                   ztra = zv_bbl * ( ptb(ji,ijs,ikvs,jn) - ptb(ji,ijd,ikvd,jn) ) * zbtr
                   pta(ji,ijd,ikvd,jn) = pta(ji,ijd,ikvd,jn) + ztra
@@ -302,8 +301,7 @@
             !
          END DO
-         !                                                  ! ===========
-      END DO                                                ! end tracer
-      !                                                     ! ===========
-      !
+         !                                                       ! ===========
+      END DO                                                     ! end tracer
+      !                                                          ! ===========
       IF( nn_timing == 1 )  CALL timing_stop( 'tra_bbl_adv')
       !
@@ -340,5 +338,5 @@
       INTEGER         , INTENT(in   ) ::   kit000   ! first time step index
       CHARACTER(len=3), INTENT(in   ) ::   cdtype   ! =TRA or TRC (tracer indicator)
-      !!
+      !
       INTEGER  ::   ji, jj                    ! dummy loop indices
       INTEGER  ::   ik                        ! local integers
@@ -365,5 +363,5 @@
             zts (ji,jj,jp_sal) = tsb(ji,jj,ik,jp_sal)
             !
-            zdep(ji,jj) = fsdept(ji,jj,ik)               ! bottom T-level reference depth
+            zdep(ji,jj) = gdept_n(ji,jj,ik)              ! bottom T-level reference depth
             zub (ji,jj) = un(ji,jj,mbku(ji,jj))          ! bottom velocity
             zvb (ji,jj) = vn(ji,jj,mbkv(ji,jj))
@@ -401,5 +399,5 @@
          !
       ENDIF
-
+      !
       !                                   !-------------------!
       IF( nn_bbl_adv /= 0 ) THEN          !   advective bbl   !
@@ -500,5 +498,5 @@
       INTEGER ::   ios                  !   -      -
       REAL(wp), POINTER, DIMENSION(:,:) :: zmbk
-      !!
+      !
       NAMELIST/nambbl/ nn_bbl_ldf, nn_bbl_adv, rn_ahtbbl, rn_gambbl
       !!----------------------------------------------------------------------
@@ -506,14 +504,11 @@
       IF( nn_timing == 1 )  CALL timing_start( 'tra_bbl_init')
       !
-      CALL wrk_alloc( jpi, jpj, zmbk )
-      !
-
       REWIND( numnam_ref )              ! Namelist nambbl in reference namelist : Bottom boundary layer scheme
       READ  ( numnam_ref, nambbl, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambbl in reference namelist', lwp )
-
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambbl in reference namelist', lwp )
+      !
       REWIND( numnam_cfg )              ! Namelist nambbl in configuration namelist : Bottom boundary layer scheme
       READ  ( numnam_cfg, nambbl, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambbl in configuration namelist', lwp )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambbl in configuration namelist', lwp )
       IF(lwm) WRITE ( numond, nambbl )
       !
@@ -545,6 +540,8 @@
       END DO
       ! converte into REAL to use lbc_lnk ; impose a min value of 1 as a zero can be set in lbclnk
+      CALL wrk_alloc( jpi, jpj, zmbk )
       zmbk(:,:) = REAL( mbku_d(:,:), wp )   ;   CALL lbc_lnk(zmbk,'U',1.)   ;   mbku_d(:,:) = MAX( INT( zmbk(:,:) ), 1 )
       zmbk(:,:) = REAL( mbkv_d(:,:), wp )   ;   CALL lbc_lnk(zmbk,'V',1.)   ;   mbkv_d(:,:) = MAX( INT( zmbk(:,:) ), 1 )
+      CALL wrk_dealloc( jpi, jpj, zmbk )
 
                                         !* sign of grad(H) at u- and v-points
@@ -593,6 +590,4 @@
       ENDIF
       !
-      CALL wrk_dealloc( jpi, jpj, zmbk )
-      !
       IF( nn_timing == 1 )  CALL timing_stop( 'tra_bbl_init')
       !
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 6140)
@@ -31,4 +31,5 @@
    USE dtatsd         ! data: temperature & salinity
    USE zdfmxl         ! vertical physics: mixed layer depth
+   !
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
@@ -41,6 +42,6 @@
    PRIVATE
 
-   PUBLIC   tra_dmp      ! routine called by step.F90
-   PUBLIC   tra_dmp_init ! routine called by nemogcm.F90
+   PUBLIC   tra_dmp        ! called by step.F90
+   PUBLIC   tra_dmp_init   ! called by nemogcm.F90
 
    !                                           !!* Namelist namtra_dmp : T & S newtonian damping *
@@ -52,5 +53,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -89,5 +89,5 @@
       !!      below the well mixed layer (nlmdmp=2)
       !!
-      !! ** Action  : - (ta,sa)   tracer trends updated with the damping trend
+      !! ** Action  : - tsa: tracer trends updated with the damping trend
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
@@ -100,5 +100,4 @@
       !
       CALL wrk_alloc( jpi,jpj,jpk,jpts,   zts_dta )
-      !
       IF( l_trdtra )   THEN                    !* Save ta and sa trends
          CALL wrk_alloc( jpi,jpj,jpk,jpts,   ztrdts ) 
@@ -139,5 +138,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  IF( fsdept(ji,jj,jk) >= hmlp (ji,jj) ) THEN
+                  IF( gdept_n(ji,jj,jk) >= hmlp (ji,jj) ) THEN
                      tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem)   &
                         &                 + resto(ji,jj,jk) * ( zts_dta(ji,jj,jk,jp_tem) - tsb(ji,jj,jk,jp_tem) )
@@ -177,5 +176,5 @@
       !!----------------------------------------------------------------------
       INTEGER ::   ios, imask   ! local integers 
-      !!
+      !
       NAMELIST/namtra_dmp/ ln_tradmp, nn_zdmp, cn_resto
       !!----------------------------------------------------------------------
@@ -229,3 +228,4 @@
    END SUBROUTINE tra_dmp_init
 
+   !!======================================================================
 END MODULE tradmp
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf.F90	(revision 6140)
@@ -12,18 +12,17 @@
 
    !!----------------------------------------------------------------------
-   !!   tra_ldf      : update the tracer trend with the lateral diffusion
-   !!   tra_ldf_init : initialization, namelist read, and parameters control
-   !!----------------------------------------------------------------------
-   USE oce           ! ocean dynamics and tracers
-   USE dom_oce       ! ocean space and time domain
-   USE phycst        ! physical constants
-   USE ldftra        ! lateral diffusion: eddy diffusivity & EIV coeff.
-   USE ldfslp        ! lateral diffusion: iso-neutral slope
-   USE traldf_lap    ! lateral diffusion: laplacian iso-level            operator  (tra_ldf_lap   routine)
-   USE traldf_iso    ! lateral diffusion: laplacian iso-neutral standard operator  (tra_ldf_iso   routine)
-   USE traldf_triad  ! lateral diffusion: laplacian iso-neutral triad    operator  (tra_ldf_triad routine)
-   USE traldf_blp    ! lateral diffusion (iso-level lap/blp)                       (tra_ldf_lap   routine)
-   USE trd_oce       ! trends: ocean variables
-   USE trdtra        ! ocean active tracers trends
+   !!   tra_ldf       : update the tracer trend with the lateral diffusion trend
+   !!   tra_ldf_init  : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE ldftra         ! lateral diffusion: eddy diffusivity & EIV coeff.
+   USE ldfslp         ! lateral diffusion: iso-neutral slope
+   USE traldf_lap_blp ! lateral diffusion: laplacian iso-level            operator  (tra_ldf_lap/_blp   routines)
+   USE traldf_iso     ! lateral diffusion: laplacian iso-neutral standard operator  (tra_ldf_iso        routine )
+   USE traldf_triad   ! lateral diffusion: laplacian iso-neutral triad    operator  (tra_ldf_triad      routine )
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! ocean active tracers trends
    !
    USE prtctl         ! Print control
@@ -43,5 +42,4 @@
    
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -72,5 +70,4 @@
       !
       SELECT CASE ( nldf )                     !* compute lateral mixing trend and add it to the general trend
-      !
       CASE ( np_lap   )                                  ! laplacian: iso-level operator
          CALL tra_ldf_lap  ( kt, nit000,'TRA', ahtu, ahtv, gtsu, gtsv, gtui, gtvi, tsb,      tsa, jpts,  1   )
@@ -82,5 +79,5 @@
          CALL tra_ldf_blp  ( kt, nit000,'TRA', ahtu, ahtv, gtsu, gtsv, gtui, gtvi, tsb      , tsa, jpts, nldf )
       END SELECT
-
+      !
       IF( l_trdtra )   THEN                    !* save the horizontal diffusive trends for further diagnostics
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
@@ -114,6 +111,6 @@
          WRITE(numout,*) 'tra_ldf_init : lateral tracer diffusive operator'
          WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist namtra_ldf already read in ldftra module'
-         WRITE(numout,*) '   see ldf_tra_init report for lateral mixing parameters'
+         WRITE(numout,*) '   Namelist namtra_ldf: already read in ldftra module'
+         WRITE(numout,*) '      see ldf_tra_init report for lateral mixing parameters'
          WRITE(numout,*)
       ENDIF
@@ -178,8 +175,8 @@
       ENDIF
       !
-      IF( ierr == 1 )   CALL ctl_stop( ' iso-level in z-coordinate - partial step, not allowed' )
+      IF( ierr == 1 )   CALL ctl_stop( 'iso-level in z-partial step, not allowed' )
       IF( ln_ldfeiv .AND. .NOT.( ln_traldf_iso .OR. ln_traldf_triad ) )                                    &
-           &            CALL ctl_stop( '          eddy induced velocity on tracers requires isopycnal',    &
-           &                                                                    ' laplacian diffusion' )
+           &            CALL ctl_stop( 'eddy induced velocity on tracers requires iso-neutral laplacian diffusion' )
+           !
       IF(  nldf == np_lap_i .OR. nldf == np_lap_it .OR. &
          & nldf == np_blp_i .OR. nldf == np_blp_it  )   l_ldfslp = .TRUE.    ! slope of neutral surfaces required 
@@ -187,11 +184,13 @@
       IF(lwp) THEN
          WRITE(numout,*)
-         IF( nldf == np_no_ldf )   WRITE(numout,*) '          NO lateral diffusion'
-         IF( nldf == np_lap    )   WRITE(numout,*) '          laplacian iso-level operator'
-         IF( nldf == np_lap_i  )   WRITE(numout,*) '          Rotated laplacian operator (standard)'
-         IF( nldf == np_lap_it )   WRITE(numout,*) '          Rotated laplacian operator (triad)'
-         IF( nldf == np_blp    )   WRITE(numout,*) '          bilaplacian iso-level operator'
-         IF( nldf == np_blp_i  )   WRITE(numout,*) '          Rotated bilaplacian operator (standard)'
-         IF( nldf == np_blp_it )   WRITE(numout,*) '          Rotated bilaplacian operator (triad)'
+         SELECT CASE( nldf )
+         CASE( np_no_ldf )   ;   WRITE(numout,*) '   NO lateral diffusion'
+         CASE( np_lap    )   ;   WRITE(numout,*) '   laplacian iso-level operator'
+         CASE( np_lap_i  )   ;   WRITE(numout,*) '   Rotated laplacian operator (standard)'
+         CASE( np_lap_it )   ;   WRITE(numout,*) '   Rotated laplacian operator (triad)'
+         CASE( np_blp    )   ;   WRITE(numout,*) '   bilaplacian iso-level operator'
+         CASE( np_blp_i  )   ;   WRITE(numout,*) '   Rotated bilaplacian operator (standard)'
+         CASE( np_blp_it )   ;   WRITE(numout,*) '   Rotated bilaplacian operator (triad)'
+         END SELECT
       ENDIF
       !
Index: unk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_blp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_blp.F90	(revision 6139)
+++ 	(revision )
@@ -1,148 +1,0 @@
-MODULE traldf_blp
-   !!======================================================================
-   !!                   ***  MODULE  traldf_blp  ***
-   !! Ocean  tracers:  bilaplacian lateral mixing trend on tracers
-   !!======================================================================
-   !! History :  3.7  ! 2015-09  (G. Madec)  original code
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   traldf_blp    : update the tracer trend with the bilaplacian lateral mixing trend
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and active tracers
-   USE dom_oce        ! ocean space and time domain
-   USE phycst         ! physical constants
-   USE trc_oce        ! share passive tracers/Ocean variables
-   USE zdf_oce        ! ocean vertical physics
-   USE ldftra         ! lateral physics: eddy diffusivity
-   USE ldfslp         ! lateral physics: iso-neutral slopes
-   USE traldf_lap     ! lateral diffusion (Standard operator)         (tra_ldf_lap   routine)
-   USE traldf_iso     ! lateral diffusion (Standard operator)         (tra_ldf_iso   routine)
-   USE traldf_triad   ! lateral diffusion (Standard operator)         (tra_ldf_triad routine)
-   USE diaptr         ! poleward transport diagnostics
-   USE zpshde         ! partial step: hor. derivative     (zps_hde routine)
-   !
-   USE in_out_manager ! I/O manager
-   USE iom            ! I/O library
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
-   USE timing         ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   tra_ldf_blp   ! routine called by traldf.F90
-
-   !                      ! Flag to control the type of lateral diffusive operator
-   INTEGER, PARAMETER, PUBLIC ::   np_ERROR  =-10   ! error in specification of lateral diffusion
-   INTEGER, PARAMETER, PUBLIC ::   np_no_ldf = 00   ! without operator (i.e. no lateral diffusive trend)
-   !                          !!      laplacian     !    bilaplacian    !
-   INTEGER, PARAMETER, PUBLIC ::   np_lap    = 10   ,   np_blp    = 20  ! iso-level operator
-   INTEGER, PARAMETER, PUBLIC ::   np_lap_i  = 11   ,   np_blp_i  = 21  ! standard iso-neutral or geopotential operator
-   INTEGER, PARAMETER, PUBLIC ::   np_lap_it = 12   ,   np_blp_it = 22  ! triad    iso-neutral or geopotential operator
-
-   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE, SAVE ::   zdkt3d   !: vertical tracer gradient at 2 levels
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
-   !! $Id: traldf_iso_grif.F90 5147 2015-03-13 10:01:32Z cetlod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE tra_ldf_blp( kt, kit000, cdtype, pahu, pahv, pgu , pgv ,   &
-      &                                                    pgui, pgvi,   &
-      &                                                    ptb , pta , kjpt, kldf )
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE tra_ldf_blp  ***
-      !!                    
-      !! ** Purpose :   Compute the before lateral tracer diffusive 
-      !!      trend and add it to the general trend of tracer equation.
-      !!
-      !! ** Method  :   The lateral diffusive trends is provided by a bilaplacian
-      !!      operator applied to before field (forward in time).
-      !!      It is computed by two successive calls to laplacian routine
-      !!
-      !! ** Action :   pta   updated with the before rotated bilaplacian diffusion
-      !!----------------------------------------------------------------------
-      INTEGER                              , INTENT(in   ) ::   kt         ! ocean time-step index
-      INTEGER                              , INTENT(in   ) ::   kit000     ! first time step index
-      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype     ! =TRA or TRC (tracer indicator)
-      INTEGER                              , INTENT(in   ) ::   kjpt       ! number of tracers
-      INTEGER                              , INTENT(in   ) ::   kldf       ! type of operator used
-      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   pahu, pahv ! eddy diffusivity at u- and v-points  [m2/s]
-      REAL(wp), DIMENSION(jpi,jpj    ,kjpt), INTENT(in   ) ::   pgu, pgv   ! tracer gradient at pstep levels
-      REAL(wp), DIMENSION(jpi,jpj,    kjpt), INTENT(in   ) ::   pgui, pgvi ! tracer gradient at top levels
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb        ! before and now tracer fields
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta        ! tracer trend
-      !
-      INTEGER ::   ji, jj, jk, jn   ! dummy loop indices
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) :: zlap         ! laplacian at t-point
-      REAL(wp), POINTER, DIMENSION(:,:,:)   :: zglu, zglv   ! bottom GRADh of the laplacian (u- and v-points)
-      REAL(wp), POINTER, DIMENSION(:,:,:)   :: zgui, zgvi   ! top    GRADh of the laplacian (u- and v-points)
-      !!---------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_ldf_blp')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,kjpt,   zlap ) 
-      CALL wrk_alloc( jpi,jpj,    kjpt,   zglu, zglv, zgui, zgvi ) 
-      !
-      IF( kt == kit000 .AND. lwp )  THEN
-         WRITE(numout,*)
-         SELECT CASE ( kldf )
-         CASE ( np_blp    )   ;   WRITE(numout,*) 'tra_ldf_blp : iso-level   bilaplacian operator on ', cdtype
-         CASE ( np_blp_i  )   ;   WRITE(numout,*) 'tra_ldf_blp : iso-neutral bilaplacian operator on ', cdtype, ' (Standard)'
-         CASE ( np_blp_it )   ;   WRITE(numout,*) 'tra_ldf_blp : iso-neutral bilaplacian operator on ', cdtype, ' (triad)'
-         END SELECT
-         WRITE(numout,*) '~~~~~~~~~~~'
-      ENDIF
-
-      zlap(:,:,:,:) = 0._wp
-      !
-      SELECT CASE ( kldf )       !==  1st laplacian applied to ptb (output in zlap)  ==!
-      !
-      CASE ( np_blp    )               ! iso-level bilaplacian
-         CALL tra_ldf_lap  ( kt, kit000, cdtype, pahu, pahv, pgu, pgv, pgui, pgvi, ptb,      zlap, kjpt, 1 )
-         !
-      CASE ( np_blp_i  )               ! rotated   bilaplacian : standard operator (Madec)
-         CALL tra_ldf_iso  ( kt, kit000, cdtype, pahu, pahv, pgu, pgv, pgui, pgvi, ptb, ptb, zlap, kjpt, 1 )
-         !
-      CASE ( np_blp_it )               ! rotated  bilaplacian : triad operator (griffies)
-         CALL tra_ldf_triad( kt, kit000, cdtype, pahu, pahv, pgu, pgv, pgui, pgvi, ptb, ptb, zlap, kjpt, 1 )
-         !
-      END SELECT
-      !
-      DO jn = 1, kjpt
-         CALL lbc_lnk( zlap(:,:,:,jn) , 'T', 1. )     ! Lateral boundary conditions (unchanged sign)
-      END DO
-      !                                               ! Partial top/bottom cell: GRADh( zlap )  
-      IF( ln_isfcav .AND. ln_zps ) THEN   ;   CALL zps_hde_isf( kt, kjpt, zlap, zglu, zglv, zgui, zgvi )  ! both top & bottom
-      ELSEIF(             ln_zps ) THEN   ;   CALL zps_hde    ( kt, kjpt, zlap, zglu, zglv )              ! only bottom 
-      ENDIF
-      !
-      SELECT CASE ( kldf )       !==  2nd laplacian applied to zlap (output in pta)  ==!
-      !
-      CASE ( np_blp    )               ! iso-level bilaplacian
-         CALL tra_ldf_lap  ( kt, kit000, cdtype, pahu, pahv, zglu, zglv, zgui, zgvi, zlap, pta,      kjpt, 2 )
-         !
-      CASE ( np_blp_i  )               ! rotated   bilaplacian : standard operator (Madec)
-         CALL tra_ldf_iso  ( kt, kit000, cdtype, pahu, pahv, zglu, zglv, zgui, zgvi, zlap, ptb, pta, kjpt, 2 )
-         !
-      CASE ( np_blp_it )               ! rotated  bilaplacian : triad operator (griffies)
-         CALL tra_ldf_triad( kt, kit000, cdtype, pahu, pahv, zglu, zglv, zgui, zgvi, zlap, ptb, pta, kjpt, 2 )
-         !
-      END SELECT
-      !
-      CALL wrk_dealloc( jpi,jpj,jpk,kjpt,   zlap ) 
-      CALL wrk_dealloc( jpi,jpj    ,kjpt,   zglu, zglv, zgui, zgvi ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_ldf_blp')
-      !
-   END SUBROUTINE tra_ldf_blp
-
-   !!==============================================================================
-END MODULE traldf_blp
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso.F90	(revision 6140)
@@ -14,21 +14,21 @@
 
    !!----------------------------------------------------------------------
-   !!   tra_ldf_iso  : update the tracer trend with the horizontal component of a iso-neutral laplacian operator
-   !!                  and with the vertical part of the isopycnal or geopotential s-coord. operator 
+   !!   tra_ldf_iso   : update the tracer trend with the horizontal component of a iso-neutral laplacian operator
+   !!                   and with the vertical part of the isopycnal or geopotential s-coord. operator 
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and active tracers
-   USE dom_oce         ! ocean space and time domain
-   USE trc_oce         ! share passive tracers/Ocean variables
-   USE zdf_oce         ! ocean vertical physics
-   USE ldftra          ! lateral diffusion: tracer eddy coefficients
-   USE ldfslp          ! iso-neutral slopes
-   USE diaptr          ! poleward transport diagnostics
+   USE oce            ! ocean dynamics and active tracers
+   USE dom_oce        ! ocean space and time domain
+   USE trc_oce        ! share passive tracers/Ocean variables
+   USE zdf_oce        ! ocean vertical physics
+   USE ldftra         ! lateral diffusion: tracer eddy coefficients
+   USE ldfslp         ! iso-neutral slopes
+   USE diaptr         ! poleward transport diagnostics
    !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O library
-   USE phycst          ! physical constants
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O library
+   USE phycst         ! physical constants
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -38,5 +38,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -103,4 +102,5 @@
       !
       INTEGER  ::  ji, jj, jk, jn   ! dummy loop indices
+      INTEGER  ::  ikt
       INTEGER  ::  ierr             ! local integer
       REAL(wp) ::  zmsku, zahu_w, zabe1, zcof1, zcoef3   ! local scalars
@@ -127,8 +127,7 @@
          ah_wslp2(:,:,:) = 0._wp
       ENDIF
-      !
       !                                               ! set time step size (Euler/Leapfrog)
-      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;   z2dt =     rdttra(1)      ! at nit000   (Euler)
-      ELSE                                        ;   z2dt = 2.* rdttra(1)      !             (Leapfrog)
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;   z2dt =     rdt      ! at nit000   (Euler)
+      ELSE                                        ;   z2dt = 2.* rdt      !             (Leapfrog)
       ENDIF
       z1_2dt = 1._wp / z2dt
@@ -138,5 +137,4 @@
       ENDIF
          
-         
       !!----------------------------------------------------------------------
       !!   0 - calculate  ah_wslp2 and akz
@@ -149,7 +147,7 @@
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   !
-                  zmsku = tmask(ji,jj,jk) / MAX(   umask(ji  ,jj,jk-1) + umask(ji-1,jj,jk)          &
+                  zmsku = wmask(ji,jj,jk) / MAX(   umask(ji  ,jj,jk-1) + umask(ji-1,jj,jk)          &
                      &                           + umask(ji-1,jj,jk-1) + umask(ji  ,jj,jk) , 1._wp  )
-                  zmskv = tmask(ji,jj,jk) / MAX(   vmask(ji,jj  ,jk-1) + vmask(ji,jj-1,jk)          &
+                  zmskv = wmask(ji,jj,jk) / MAX(   vmask(ji,jj  ,jk-1) + vmask(ji,jj-1,jk)          &
                      &                           + vmask(ji,jj-1,jk-1) + vmask(ji,jj  ,jk) , 1._wp  )
                      !
@@ -183,5 +181,5 @@
                      DO ji = 1, fs_jpim1
                         akz(ji,jj,jk) = 16._wp * ah_wslp2(ji,jj,jk)   &
-                           &          * (  akz(ji,jj,jk) + ah_wslp2(ji,jj,jk) / ( fse3w(ji,jj,jk) * fse3w(ji,jj,jk) )  )
+                           &          * (  akz(ji,jj,jk) + ah_wslp2(ji,jj,jk) / ( e3w_n(ji,jj,jk) * e3w_n(ji,jj,jk) )  )
                      END DO
                   END DO
@@ -191,5 +189,5 @@
                   DO jj = 1, jpjm1
                      DO ji = 1, fs_jpim1
-                        ze3w_2 = fse3w(ji,jj,jk) * fse3w(ji,jj,jk)
+                        ze3w_2 = e3w_n(ji,jj,jk) * e3w_n(ji,jj,jk)
                         zcoef0 = z2dt * (  akz(ji,jj,jk) + ah_wslp2(ji,jj,jk) / ze3w_2  )
                         akz(ji,jj,jk) = MAX( zcoef0 - 0.5_wp , 0._wp ) * ze3w_2 * z1_2dt
@@ -228,5 +226,4 @@
             DO jj = 1, jpjm1              ! bottom correction (partial bottom cell)
                DO ji = 1, fs_jpim1   ! vector opt.
-!!gm  the following anonymous remark is to considered: ! IF useless if zpshde defines pgu everywhere
                   zdit(ji,jj,mbku(ji,jj)) = pgu(ji,jj,jn)          
                   zdjt(ji,jj,mbkv(ji,jj)) = pgv(ji,jj,jn)
@@ -242,5 +239,5 @@
             ENDIF
          ENDIF
-
+         !
          !!----------------------------------------------------------------------
          !!   II - horizontal trend  (full)
@@ -255,26 +252,14 @@
             ELSE                 ;   zdkt(:,:) = ( ptb(:,:,jk-1,jn) - ptb(:,:,jk,jn) ) * wmask(:,:,jk)
             ENDIF
-!!gm I don't understand why we should need this.... since wmask is used instead of tmask
-!         IF ( ln_isfcav ) THEN
-!            DO jj = 1, jpj
-!               DO ji = 1, jpi   ! vector opt.
-!                  ikt = mikt(ji,jj) ! surface level
-!                  zdk1t(ji,jj,ikt) = ( ptb(ji,jj,ikt,jn  ) - ptb(ji,jj,ikt+1,jn) ) * wmask(ji,jj,ikt+1)
-!                  zdkt (ji,jj,ikt) = zdk1t(ji,jj,ikt)
-!               END DO
-!            END DO
-!         END IF
-!!gm 
-
             DO jj = 1 , jpjm1            !==  Horizontal fluxes
                DO ji = 1, fs_jpim1   ! vector opt.
-                  zabe1 = pahu(ji,jj,jk) * e2_e1u(ji,jj) * fse3u_n(ji,jj,jk)
-                  zabe2 = pahv(ji,jj,jk) * e1_e2v(ji,jj) * fse3v_n(ji,jj,jk)
-                  !
-                  zmsku = 1. / MAX(  tmask(ji+1,jj,jk  ) + tmask(ji,jj,jk+1)   &
-                     &             + tmask(ji+1,jj,jk+1) + tmask(ji,jj,jk  ), 1. )
-                  !
-                  zmskv = 1. / MAX(  tmask(ji,jj+1,jk  ) + tmask(ji,jj,jk+1)   &
-                     &             + tmask(ji,jj+1,jk+1) + tmask(ji,jj,jk  ), 1. )
+                  zabe1 = pahu(ji,jj,jk) * e2_e1u(ji,jj) * e3u_n(ji,jj,jk)
+                  zabe2 = pahv(ji,jj,jk) * e1_e2v(ji,jj) * e3v_n(ji,jj,jk)
+                  !
+                  zmsku = 1. / MAX(  wmask(ji+1,jj,jk  ) + wmask(ji,jj,jk+1)   &
+                     &             + wmask(ji+1,jj,jk+1) + wmask(ji,jj,jk  ), 1. )
+                  !
+                  zmskv = 1. / MAX(  wmask(ji,jj+1,jk  ) + wmask(ji,jj,jk+1)   &
+                     &             + wmask(ji,jj+1,jk+1) + wmask(ji,jj,jk  ), 1. )
                   !
                   zcof1 = - pahu(ji,jj,jk) * e2u(ji,jj) * uslp(ji,jj,jk) * zmsku
@@ -294,30 +279,27 @@
                   pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + zsign * (  zftu(ji,jj,jk) - zftu(ji-1,jj,jk)      &
                      &                                           + zftv(ji,jj,jk) - zftv(ji,jj-1,jk)  )   &
-                     &                                        / (  e1e2t(ji,jj) * fse3t(ji,jj,jk)  )
+                     &                                        * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                END DO
             END DO
          END DO                                        !   End of slab  
 
-
          !!----------------------------------------------------------------------
          !!   III - vertical trend (full)
          !!----------------------------------------------------------------------
-         
+         !
          ztfw(1,:,:) = 0._wp     ;     ztfw(jpi,:,:) = 0._wp
-         
+         !
          ! Vertical fluxes
          ! ---------------
-         
-         ! Surface and bottom vertical fluxes set to zero
+         !                          ! Surface and bottom vertical fluxes set to zero
          ztfw(:,:, 1 ) = 0._wp      ;      ztfw(:,:,jpk) = 0._wp
          
-         ! interior (2=<jk=<jpk-1)
-         DO jk = 2, jpkm1
+         DO jk = 2, jpkm1           ! interior (2=<jk=<jpk-1)
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   !
-                  zmsku = tmask(ji,jj,jk) / MAX(   umask(ji  ,jj,jk-1) + umask(ji-1,jj,jk)          &
+                  zmsku = wmask(ji,jj,jk) / MAX(   umask(ji  ,jj,jk-1) + umask(ji-1,jj,jk)          &
                      &                           + umask(ji-1,jj,jk-1) + umask(ji  ,jj,jk) , 1._wp  )
-                  zmskv = tmask(ji,jj,jk) / MAX(   vmask(ji,jj  ,jk-1) + vmask(ji,jj-1,jk)          &
+                  zmskv = wmask(ji,jj,jk) / MAX(   vmask(ji,jj  ,jk-1) + vmask(ji,jj-1,jk)          &
                      &                           + vmask(ji,jj-1,jk-1) + vmask(ji,jj  ,jk) , 1._wp  )
                      !
@@ -337,5 +319,4 @@
             END DO
          END DO
-         !
          !                                !==  add the vertical 33 flux  ==!
          IF( ln_traldf_lap ) THEN               ! laplacian case: eddy coef = ah_wslp2 - akz
@@ -343,5 +324,5 @@
                DO jj = 1, jpjm1
                   DO ji = fs_2, fs_jpim1
-                     ztfw(ji,jj,jk) = ztfw(ji,jj,jk) + e1e2t(ji,jj) / fse3w(ji,jj,jk) * tmask(ji,jj,jk)   &
+                     ztfw(ji,jj,jk) = ztfw(ji,jj,jk) + e1e2t(ji,jj) / e3w_n(ji,jj,jk) * wmask(ji,jj,jk)   &
                         &                            * ( ah_wslp2(ji,jj,jk) - akz(ji,jj,jk) )             &
                         &                            * ( ptb(ji,jj,jk-1,jn) - ptb(ji,jj,jk,jn) )
@@ -358,5 +339,5 @@
                         ztfw(ji,jj,jk) = ztfw(ji,jj,jk)    &
                            &           + ah_wslp2(ji,jj,jk) * e1e2t(ji,jj)   &
-                           &           * ( ptb(ji,jj,jk-1,jn) - ptb(ji,jj,jk,jn) ) * tmask(ji,jj,jk) / fse3w(ji,jj,jk)
+                           &           * ( ptb(ji,jj,jk-1,jn) - ptb(ji,jj,jk,jn) ) / e3w_n(ji,jj,jk) * wmask(ji,jj,jk)
                      END DO
                   END DO
@@ -366,5 +347,5 @@
                   DO jj = 1, jpjm1
                      DO ji = fs_2, fs_jpim1
-                        ztfw(ji,jj,jk) = ztfw(ji,jj,jk) + e1e2t(ji,jj) / fse3w(ji,jj,jk) * tmask(ji,jj,jk)                      &
+                        ztfw(ji,jj,jk) = ztfw(ji,jj,jk) + e1e2t(ji,jj) / e3w_n(ji,jj,jk) * wmask(ji,jj,jk)                      &
                            &                            * (  ah_wslp2(ji,jj,jk) * ( ptb (ji,jj,jk-1,jn) - ptb (ji,jj,jk,jn) )   &
                            &                               + akz     (ji,jj,jk) * ( ptbb(ji,jj,jk-1,jn) - ptbb(ji,jj,jk,jn) )   )
@@ -379,5 +360,5 @@
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + zsign * (  ztfw (ji,jj,jk) - ztfw(ji,jj,jk+1)  )   &
-                     &                                        / (  e1e2t(ji,jj) * fse3t_n(ji,jj,jk)  )
+                     &                                        * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                END DO
             END DO
Index: unk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_lap.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_lap.F90	(revision 6139)
+++ 	(revision )
@@ -1,166 +1,0 @@
-MODULE traldf_lap
-   !!==============================================================================
-   !!                       ***  MODULE  traldf_lap  ***
-   !! Ocean tracers:  lateral diffusivity trend  (laplacian and bilaplacian)
-   !!==============================================================================
-   !! History :  OPA  ! 1987-06  (P. Andrich, D. L Hostis)  Original code
-   !!                 ! 1991-11  (G. Madec)
-   !!                 ! 1995-11  (G. Madec)  suppress volumetric scale factors
-   !!                 ! 1996-01  (G. Madec)  statement function for e3
-   !!            NEMO ! 2002-06  (G. Madec)  F90: Free form and module
-   !!            1.0  ! 2004-08  (C. Talandier) New trends organization
-   !!                 ! 2005-11  (G. Madec)  add zps case
-   !!            3.0  ! 2010-06  (C. Ethe, G. Madec) Merge TRA-TRC
-   !!            3.7  ! 2014-01  (G. Madec, S. Masson) re-entrant laplacian 
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   tra_ldf_lap : update the tracer trend with the lateral diffusion : iso-level laplacian operator
-   !!   tra_ldf_blp : update the tracer trend with the lateral diffusion : iso-level bilaplacian operator
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and active tracers
-   USE dom_oce         ! ocean space and time domain
-   USE ldftra          ! lateral physics: eddy diffusivity
-   USE diaptr          ! poleward transport diagnostics
-   USE trc_oce         ! share passive tracers/Ocean variables
-   USE zpshde          ! partial step: hor. derivative     (zps_hde routine)
-   !
-   USE in_out_manager  ! I/O manager
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp         ! distribued memory computing library
-   USE timing          ! Timing
-   USE wrk_nemo        ! Memory allocation
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   tra_ldf_lap   ! routine called by traldf.F90
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE tra_ldf_lap( kt, kit000, cdtype, pahu, pahv, pgu , pgv ,   &
-      &                                                    pgui, pgvi,   &
-      &                                        ptb , pta , kjpt, kpass ) 
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE tra_ldf_lap  ***
-      !!                   
-      !! ** Purpose :   Compute the before horizontal tracer (t & s) diffusive 
-      !!      trend and add it to the general trend of tracer equation.
-      !!
-      !! ** Method  :   Second order diffusive operator evaluated using before
-      !!      fields (forward time scheme). The horizontal diffusive trends of 
-      !!      the tracer is given by:
-      !!          difft = 1/(e1e2t*e3t) {  di-1[ pahu e2u*e3u/e1u di(tb) ]
-      !!                                 + dj-1[ pahv e1v*e3v/e2v dj(tb) ] }
-      !!      Add this trend to the general tracer trend pta :
-      !!          pta = pta + difft
-      !!
-      !! ** Action  : - Update pta arrays with the before iso-level 
-      !!                harmonic mixing trend.
-      !!----------------------------------------------------------------------
-      INTEGER                              , INTENT(in   ) ::   kt         ! ocean time-step index
-      INTEGER                              , INTENT(in   ) ::   kit000     ! first time step index
-      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype     ! =TRA or TRC (tracer indicator)
-      INTEGER                              , INTENT(in   ) ::   kjpt       ! number of tracers
-      INTEGER                              , INTENT(in   ) ::   kpass      ! =1/2 first or second passage
-      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   pahu, pahv ! eddy diffusivity at u- and v-points  [m2/s]
-      REAL(wp), DIMENSION(jpi,jpj    ,kjpt), INTENT(in   ) ::   pgu, pgv   ! tracer gradient at pstep levels
-      REAL(wp), DIMENSION(jpi,jpj,    kjpt), INTENT(in   ) ::   pgui, pgvi ! tracer gradient at top   levels
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb        ! before and now tracer fields
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta        ! tracer trend 
-      !
-      INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
-      REAL(wp) ::   zsign            ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztu, ztv, zaheeu, zaheev
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('tra_ldf_lap')
-      !
-      IF( kt == nit000 .AND. lwp )  THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'tra_ldf_lap : iso-level laplacian diffusion on ', cdtype, ', pass=', kpass
-         WRITE(numout,*) '~~~~~~~~~~~ '
-      ENDIF
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   ztu, ztv, zaheeu, zaheev ) 
-      !
-      !                                !==  Initialization of metric arrays used for all tracers  ==!
-      IF( kpass == 1 ) THEN   ;   zsign =  1._wp      ! bilaplacian operator require a minus sign (eddy diffusivity >0)
-      ELSE                    ;   zsign = -1._wp
-      ENDIF
-      DO jk = 1, jpkm1
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1   ! vector opt.
-               zaheeu(ji,jj,jk) = zsign * pahu(ji,jj,jk) * e2_e1u(ji,jj) * fse3u_n(ji,jj,jk)   !!gm   * umask(ji,jj,jk) pah masked!
-               zaheev(ji,jj,jk) = zsign * pahv(ji,jj,jk) * e1_e2v(ji,jj) * fse3v_n(ji,jj,jk)   !!gm   * vmask(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-      !
-      !                             ! =========== !
-      DO jn = 1, kjpt               ! tracer loop !
-         !                          ! =========== !    
-         !                               
-         DO jk = 1, jpkm1              !== First derivative (gradient)  ==!
-            DO jj = 1, jpjm1
-               DO ji = 1, fs_jpim1
-                  ztu(ji,jj,jk) = zaheeu(ji,jj,jk) * ( ptb(ji+1,jj  ,jk,jn) - ptb(ji,jj,jk,jn) )
-                  ztv(ji,jj,jk) = zaheev(ji,jj,jk) * ( ptb(ji  ,jj+1,jk,jn) - ptb(ji,jj,jk,jn) )
-               END DO
-            END DO
-         END DO  
-         IF( ln_zps ) THEN                ! set gradient at bottom/top ocean level
-            DO jj = 1, jpjm1                    ! bottom
-               DO ji = 1, fs_jpim1
-                  ztu(ji,jj,mbku(ji,jj)) = zaheeu(ji,jj,mbku(ji,jj)) * pgu(ji,jj,jn)
-                  ztv(ji,jj,mbkv(ji,jj)) = zaheev(ji,jj,mbkv(ji,jj)) * pgv(ji,jj,jn)
-               END DO
-            END DO  
-            IF( ln_isfcav ) THEN                ! top in ocean cavities only
-               DO jj = 1, jpjm1
-                  DO ji = 1, fs_jpim1   ! vector opt.
-                     IF( miku(ji,jj) > 1 )   ztu(ji,jj,miku(ji,jj)) = zaheeu(ji,jj,miku(ji,jj)) * pgui(ji,jj,jn) 
-                     IF( mikv(ji,jj) > 1 )   ztv(ji,jj,mikv(ji,jj)) = zaheev(ji,jj,mikv(ji,jj)) * pgvi(ji,jj,jn) 
-                  END DO
-               END DO
-            ENDIF
-         ENDIF
-         !
-         DO jk = 1, jpkm1              !== Second derivative (divergence) added to the general tracer trends  ==!
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1
-                  pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk)     &
-                     &                                   + ztv(ji,jj,jk) - ztv(ji,jj-1,jk) )   &
-                     &                                / ( e1e2t(ji,jj) * fse3t_n(ji,jj,jk) )
-               END DO
-            END DO
-         END DO  
-         !
-         !                             !== "Poleward" diffusive heat or salt transports  ==!
-         IF( ( kpass == 1 .AND. .NOT.ln_traldf_blp ) .OR.  &     !==  first pass only (  laplacian)  ==!
-             ( kpass == 2 .AND.      ln_traldf_blp ) ) THEN      !==  2nd   pass only (bilaplacian)  ==!
-            IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN
-               IF( jn  == jp_tem)   htr_ldf(:) = ptr_sj( -ztv(:,:,:) )
-               IF( jn  == jp_sal)   str_ldf(:) = ptr_sj( -ztv(:,:,:) )
-            ENDIF
-         ENDIF
-         !                          ! ==================
-      END DO                        ! end of tracer loop
-      !                             ! ==================
-      !
-      CALL wrk_dealloc( jpi,jpj,jpk,   ztu, ztv, zaheeu, zaheev ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_ldf_lap')
-      !
-   END SUBROUTINE tra_ldf_lap
-   
-   !!==============================================================================
-END MODULE traldf_lap
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_lap_blp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_lap_blp.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_lap_blp.F90	(revision 6140)
@@ -0,0 +1,253 @@
+MODULE traldf_lap_blp
+   !!==============================================================================
+   !!                       ***  MODULE  traldf_lap_blp  ***
+   !! Ocean tracers:  lateral diffusivity trend  (laplacian and bilaplacian)
+   !!==============================================================================
+   !! History :  3.7  ! 2014-01  (G. Madec, S. Masson)  Original code, re-entrant laplacian 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_ldf_lap   : tracer trend update with iso-level laplacian diffusive operator
+   !!   tra_ldf_blp   : tracer trend update with iso-level or iso-neutral bilaplacian operator
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and active tracers
+   USE dom_oce        ! ocean space and time domain
+   USE ldftra         ! lateral physics: eddy diffusivity
+   USE traldf_iso     ! iso-neutral lateral diffusion (standard operator)     (tra_ldf_iso   routine)
+   USE traldf_triad   ! iso-neutral lateral diffusion (triad    operator)     (tra_ldf_triad routine)
+   USE diaptr         ! poleward transport diagnostics
+   USE trc_oce        ! share passive tracers/Ocean variables
+   USE zpshde         ! partial step: hor. derivative     (zps_hde routine)
+   !
+   USE in_out_manager ! I/O manager
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp        ! distribued memory computing library
+   USE timing         ! Timing
+   USE wrk_nemo       ! Memory allocation
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_ldf_lap   ! called by traldf.F90
+   PUBLIC   tra_ldf_blp   ! called by traldf.F90
+
+   !                      ! Flag to control the type of lateral diffusive operator
+   INTEGER, PARAMETER, PUBLIC ::   np_ERROR  =-10   ! error in specification of lateral diffusion
+   INTEGER, PARAMETER, PUBLIC ::   np_no_ldf = 00   ! without operator (i.e. no lateral diffusive trend)
+   !                          !!      laplacian     !    bilaplacian    !
+   INTEGER, PARAMETER, PUBLIC ::   np_lap    = 10   ,   np_blp    = 20  ! iso-level operator
+   INTEGER, PARAMETER, PUBLIC ::   np_lap_i  = 11   ,   np_blp_i  = 21  ! standard iso-neutral or geopotential operator
+   INTEGER, PARAMETER, PUBLIC ::   np_lap_it = 12   ,   np_blp_it = 22  ! triad    iso-neutral or geopotential operator
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
+   !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE tra_ldf_lap( kt, kit000, cdtype, pahu, pahv, pgu , pgv ,   &
+      &                                                    pgui, pgvi,   &
+      &                                        ptb , pta , kjpt, kpass ) 
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_ldf_lap  ***
+      !!                   
+      !! ** Purpose :   Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   Second order diffusive operator evaluated using before
+      !!      fields (forward time scheme). The horizontal diffusive trends of 
+      !!      the tracer is given by:
+      !!          difft = 1/(e1e2t*e3t) {  di-1[ pahu e2u*e3u/e1u di(tb) ]
+      !!                                 + dj-1[ pahv e1v*e3v/e2v dj(tb) ] }
+      !!      Add this trend to the general tracer trend pta :
+      !!          pta = pta + difft
+      !!
+      !! ** Action  : - Update pta arrays with the before iso-level 
+      !!                harmonic mixing trend.
+      !!----------------------------------------------------------------------
+      INTEGER                              , INTENT(in   ) ::   kt         ! ocean time-step index
+      INTEGER                              , INTENT(in   ) ::   kit000     ! first time step index
+      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype     ! =TRA or TRC (tracer indicator)
+      INTEGER                              , INTENT(in   ) ::   kjpt       ! number of tracers
+      INTEGER                              , INTENT(in   ) ::   kpass      ! =1/2 first or second passage
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   pahu, pahv ! eddy diffusivity at u- and v-points  [m2/s]
+      REAL(wp), DIMENSION(jpi,jpj    ,kjpt), INTENT(in   ) ::   pgu, pgv   ! tracer gradient at pstep levels
+      REAL(wp), DIMENSION(jpi,jpj,    kjpt), INTENT(in   ) ::   pgui, pgvi ! tracer gradient at top   levels
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb        ! before and now tracer fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta        ! tracer trend 
+      !
+      INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
+      REAL(wp) ::   zsign            ! local scalars
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztu, ztv, zaheeu, zaheev
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('tra_ldf_lap')
+      !
+      IF( kt == nit000 .AND. lwp )  THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_ldf_lap : iso-level laplacian diffusion on ', cdtype, ', pass=', kpass
+         WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+      !
+      CALL wrk_alloc( jpi,jpj,jpk,   ztu, ztv, zaheeu, zaheev ) 
+      !
+      !                                !==  Initialization of metric arrays used for all tracers  ==!
+      IF( kpass == 1 ) THEN   ;   zsign =  1._wp      ! bilaplacian operator require a minus sign (eddy diffusivity >0)
+      ELSE                    ;   zsign = -1._wp
+      ENDIF
+      DO jk = 1, jpkm1
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zaheeu(ji,jj,jk) = zsign * pahu(ji,jj,jk) * e2_e1u(ji,jj) * e3u_n(ji,jj,jk)   !!gm   * umask(ji,jj,jk) pah masked!
+               zaheev(ji,jj,jk) = zsign * pahv(ji,jj,jk) * e1_e2v(ji,jj) * e3v_n(ji,jj,jk)   !!gm   * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+      !                             ! =========== !
+      DO jn = 1, kjpt               ! tracer loop !
+         !                          ! =========== !    
+         !                               
+         DO jk = 1, jpkm1              !== First derivative (gradient)  ==!
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1
+                  ztu(ji,jj,jk) = zaheeu(ji,jj,jk) * ( ptb(ji+1,jj  ,jk,jn) - ptb(ji,jj,jk,jn) )
+                  ztv(ji,jj,jk) = zaheev(ji,jj,jk) * ( ptb(ji  ,jj+1,jk,jn) - ptb(ji,jj,jk,jn) )
+               END DO
+            END DO
+         END DO  
+         IF( ln_zps ) THEN                ! set gradient at bottom/top ocean level
+            DO jj = 1, jpjm1                    ! bottom
+               DO ji = 1, fs_jpim1
+                  ztu(ji,jj,mbku(ji,jj)) = zaheeu(ji,jj,mbku(ji,jj)) * pgu(ji,jj,jn)
+                  ztv(ji,jj,mbkv(ji,jj)) = zaheev(ji,jj,mbkv(ji,jj)) * pgv(ji,jj,jn)
+               END DO
+            END DO  
+            IF( ln_isfcav ) THEN                ! top in ocean cavities only
+               DO jj = 1, jpjm1
+                  DO ji = 1, fs_jpim1   ! vector opt.
+                     IF( miku(ji,jj) > 1 )   ztu(ji,jj,miku(ji,jj)) = zaheeu(ji,jj,miku(ji,jj)) * pgui(ji,jj,jn) 
+                     IF( mikv(ji,jj) > 1 )   ztv(ji,jj,mikv(ji,jj)) = zaheev(ji,jj,mikv(ji,jj)) * pgvi(ji,jj,jn) 
+                  END DO
+               END DO
+            ENDIF
+         ENDIF
+         !
+         DO jk = 1, jpkm1              !== Second derivative (divergence) added to the general tracer trends  ==!
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk)     &
+                     &                                   + ztv(ji,jj,jk) - ztv(ji,jj-1,jk) )   &
+                     &                                / ( e1e2t(ji,jj) * e3t_n(ji,jj,jk) )
+               END DO
+            END DO
+         END DO  
+         !
+         !                             !== "Poleward" diffusive heat or salt transports  ==!
+         IF( ( kpass == 1 .AND. .NOT.ln_traldf_blp ) .OR.  &     !==  first pass only (  laplacian)  ==!
+             ( kpass == 2 .AND.      ln_traldf_blp ) ) THEN      !==  2nd   pass only (bilaplacian)  ==!
+            IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN
+               IF( jn  == jp_tem)   htr_ldf(:) = ptr_sj( -ztv(:,:,:) )
+               IF( jn  == jp_sal)   str_ldf(:) = ptr_sj( -ztv(:,:,:) )
+            ENDIF
+         ENDIF
+         !                          ! ==================
+      END DO                        ! end of tracer loop
+      !                             ! ==================
+      !
+      CALL wrk_dealloc( jpi,jpj,jpk,   ztu, ztv, zaheeu, zaheev ) 
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('tra_ldf_lap')
+      !
+   END SUBROUTINE tra_ldf_lap
+   
+
+   SUBROUTINE tra_ldf_blp( kt, kit000, cdtype, pahu, pahv, pgu , pgv ,   &
+      &                                                    pgui, pgvi,   &
+      &                                                    ptb , pta , kjpt, kldf )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE tra_ldf_blp  ***
+      !!                    
+      !! ** Purpose :   Compute the before lateral tracer diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   The lateral diffusive trends is provided by a bilaplacian
+      !!      operator applied to before field (forward in time).
+      !!      It is computed by two successive calls to laplacian routine
+      !!
+      !! ** Action :   pta   updated with the before rotated bilaplacian diffusion
+      !!----------------------------------------------------------------------
+      INTEGER                              , INTENT(in   ) ::   kt         ! ocean time-step index
+      INTEGER                              , INTENT(in   ) ::   kit000     ! first time step index
+      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype     ! =TRA or TRC (tracer indicator)
+      INTEGER                              , INTENT(in   ) ::   kjpt       ! number of tracers
+      INTEGER                              , INTENT(in   ) ::   kldf       ! type of operator used
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   pahu, pahv ! eddy diffusivity at u- and v-points  [m2/s]
+      REAL(wp), DIMENSION(jpi,jpj    ,kjpt), INTENT(in   ) ::   pgu, pgv   ! tracer gradient at pstep levels
+      REAL(wp), DIMENSION(jpi,jpj,    kjpt), INTENT(in   ) ::   pgui, pgvi ! tracer gradient at top levels
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb        ! before and now tracer fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta        ! tracer trend
+      !
+      INTEGER ::   ji, jj, jk, jn   ! dummy loop indices
+      REAL(wp), POINTER, DIMENSION(:,:,:,:) :: zlap         ! laplacian at t-point
+      REAL(wp), POINTER, DIMENSION(:,:,:)   :: zglu, zglv   ! bottom GRADh of the laplacian (u- and v-points)
+      REAL(wp), POINTER, DIMENSION(:,:,:)   :: zgui, zgvi   ! top    GRADh of the laplacian (u- and v-points)
+      !!---------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('tra_ldf_blp')
+      !
+      CALL wrk_alloc( jpi,jpj,jpk,kjpt,   zlap ) 
+      CALL wrk_alloc( jpi,jpj,    kjpt,   zglu, zglv, zgui, zgvi ) 
+      !
+      IF( kt == kit000 .AND. lwp )  THEN
+         WRITE(numout,*)
+         SELECT CASE ( kldf )
+         CASE ( np_blp    )   ;   WRITE(numout,*) 'tra_ldf_blp : iso-level   bilaplacian operator on ', cdtype
+         CASE ( np_blp_i  )   ;   WRITE(numout,*) 'tra_ldf_blp : iso-neutral bilaplacian operator on ', cdtype, ' (Standard)'
+         CASE ( np_blp_it )   ;   WRITE(numout,*) 'tra_ldf_blp : iso-neutral bilaplacian operator on ', cdtype, ' (triad)'
+         END SELECT
+         WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+      zlap(:,:,:,:) = 0._wp
+      !
+      SELECT CASE ( kldf )       !==  1st laplacian applied to ptb (output in zlap)  ==!
+      !
+      CASE ( np_blp    )               ! iso-level bilaplacian
+         CALL tra_ldf_lap  ( kt, kit000, cdtype, pahu, pahv, pgu, pgv, pgui, pgvi, ptb,      zlap, kjpt, 1 )
+      CASE ( np_blp_i  )               ! rotated   bilaplacian : standard operator (Madec)
+         CALL tra_ldf_iso  ( kt, kit000, cdtype, pahu, pahv, pgu, pgv, pgui, pgvi, ptb, ptb, zlap, kjpt, 1 )
+      CASE ( np_blp_it )               ! rotated  bilaplacian : triad operator (griffies)
+         CALL tra_ldf_triad( kt, kit000, cdtype, pahu, pahv, pgu, pgv, pgui, pgvi, ptb, ptb, zlap, kjpt, 1 )
+      END SELECT
+      !
+      DO jn = 1, kjpt
+         CALL lbc_lnk( zlap(:,:,:,jn) , 'T', 1. )     ! Lateral boundary conditions (unchanged sign)
+      END DO
+      !                                               ! Partial top/bottom cell: GRADh( zlap )  
+      IF( ln_isfcav .AND. ln_zps ) THEN   ;   CALL zps_hde_isf( kt, kjpt, zlap, zglu, zglv, zgui, zgvi )  ! both top & bottom
+      ELSEIF(             ln_zps ) THEN   ;   CALL zps_hde    ( kt, kjpt, zlap, zglu, zglv )              ! only bottom 
+      ENDIF
+      !
+      SELECT CASE ( kldf )       !==  2nd laplacian applied to zlap (output in pta)  ==!
+      !
+      CASE ( np_blp    )               ! iso-level bilaplacian
+         CALL tra_ldf_lap  ( kt, kit000, cdtype, pahu, pahv, zglu, zglv, zgui, zgvi, zlap, pta,      kjpt, 2 )
+      CASE ( np_blp_i  )               ! rotated   bilaplacian : standard operator (Madec)
+         CALL tra_ldf_iso  ( kt, kit000, cdtype, pahu, pahv, zglu, zglv, zgui, zgvi, zlap, ptb, pta, kjpt, 2 )
+      CASE ( np_blp_it )               ! rotated  bilaplacian : triad operator (griffies)
+         CALL tra_ldf_triad( kt, kit000, cdtype, pahu, pahv, zglu, zglv, zgui, zgvi, zlap, ptb, pta, kjpt, 2 )
+      END SELECT
+      !
+      CALL wrk_dealloc( jpi,jpj,jpk,kjpt,   zlap ) 
+      CALL wrk_dealloc( jpi,jpj    ,kjpt,   zglu, zglv, zgui, zgvi ) 
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('tra_ldf_blp')
+      !
+   END SUBROUTINE tra_ldf_blp
+
+   !!==============================================================================
+END MODULE traldf_lap_blp
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_triad.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_triad.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_triad.F90	(revision 6140)
@@ -11,21 +11,21 @@
    !!   tra_ldf_triad : update the tracer trend with the iso-neutral laplacian triad-operator
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and active tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE trc_oce         ! share passive tracers/Ocean variables
-   USE zdf_oce         ! ocean vertical physics
-   USE ldftra          ! lateral physics: eddy diffusivity
-   USE ldfslp          ! lateral physics: iso-neutral slopes
-   USE traldf_iso      ! lateral diffusion (Madec operator)         (tra_ldf_iso routine)
-   USE diaptr          ! poleward transport diagnostics
-   USE zpshde          ! partial step: hor. derivative     (zps_hde routine)
+   USE oce            ! ocean dynamics and active tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE trc_oce        ! share passive tracers/Ocean variables
+   USE zdf_oce        ! ocean vertical physics
+   USE ldftra         ! lateral physics: eddy diffusivity
+   USE ldfslp         ! lateral physics: iso-neutral slopes
+   USE traldf_iso     ! lateral diffusion (Madec operator)         (tra_ldf_iso routine)
+   USE diaptr         ! poleward transport diagnostics
+   USE zpshde         ! partial step: hor. derivative     (zps_hde routine)
    !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O library
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -37,5 +37,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -113,8 +112,7 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~'
       ENDIF
-      !
       !                                               ! set time step size (Euler/Leapfrog)
-      IF( neuler == 0 .AND. kt == kit000 ) THEN   ;   z2dt =     rdttra(1)      ! at nit000   (Euler)
-      ELSE                                        ;   z2dt = 2.* rdttra(1)      !             (Leapfrog)
+      IF( neuler == 0 .AND. kt == kit000 ) THEN   ;   z2dt =     rdt      ! at nit000   (Euler)
+      ELSE                                        ;   z2dt = 2.* rdt      !             (Leapfrog)
       ENDIF
       z1_2dt = 1._wp / z2dt
@@ -123,5 +121,5 @@
       ELSE                    ;   zsign = -1._wp
       ENDIF
-                  
+      !    
       !!----------------------------------------------------------------------
       !!   0 - calculate  ah_wslp2, akz, and optionally zpsi_uw, zpsi_vw
@@ -142,15 +140,15 @@
                   DO jj = 1, jpjm1
                      DO ji = 1, fs_jpim1
-                        ze3wr = 1._wp / fse3w(ji+ip,jj,jk+kp)
-                        zbu   = e1e2u(ji,jj) * fse3u(ji,jj,jk)
+                        ze3wr = 1._wp / e3w_n(ji+ip,jj,jk+kp)
+                        zbu   = e1e2u(ji,jj) * e3u_n(ji,jj,jk)
                         zah   = 0.25_wp * pahu(ji,jj,jk)
                         zslope_skew = triadi_g(ji+ip,jj,jk,1-ip,kp)
                         ! Subtract s-coordinate slope at t-points to give slope rel to s-surfaces (do this by *adding* gradient of depth)
-                        zslope2 = zslope_skew + ( fsdept(ji+1,jj,jk) - fsdept(ji,jj,jk) ) * r1_e1u(ji,jj) * umask(ji,jj,jk+kp)
+                        zslope2 = zslope_skew + ( gdept_n(ji+1,jj,jk) - gdept_n(ji,jj,jk) ) * r1_e1u(ji,jj) * umask(ji,jj,jk+kp)
                         zslope2 = zslope2 *zslope2
                         ah_wslp2(ji+ip,jj,jk+kp) = ah_wslp2(ji+ip,jj,jk+kp) + zah * zbu * ze3wr * r1_e1e2t(ji+ip,jj) * zslope2
                         akz     (ji+ip,jj,jk+kp) = akz     (ji+ip,jj,jk+kp) + zah * r1_e1u(ji,jj)       &
                            &                                                      * r1_e1u(ji,jj) * umask(ji,jj,jk+kp)
-                        !
+                           !
                        IF( ln_ldfeiv_dia )   zpsi_uw(ji,jj,jk+kp) = zpsi_uw(ji,jj,jk+kp)   &
                            &                                       + 0.25_wp * aeiu(ji,jj,jk) * e2u(ji,jj) * zslope_skew
@@ -166,11 +164,11 @@
                   DO jj = 1, jpjm1
                      DO ji = 1, fs_jpim1
-                        ze3wr = 1.0_wp / fse3w(ji,jj+jp,jk+kp)
-                        zbv   = e1e2v(ji,jj) * fse3v(ji,jj,jk)
+                        ze3wr = 1.0_wp / e3w_n(ji,jj+jp,jk+kp)
+                        zbv   = e1e2v(ji,jj) * e3v_n(ji,jj,jk)
                         zah   = 0.25_wp * pahv(ji,jj,jk)
                         zslope_skew = triadj_g(ji,jj+jp,jk,1-jp,kp)
                         ! Subtract s-coordinate slope at t-points to give slope rel to s surfaces
                         !    (do this by *adding* gradient of depth)
-                        zslope2 = zslope_skew + ( fsdept(ji,jj+1,jk) - fsdept(ji,jj,jk) ) * r1_e2v(ji,jj) * vmask(ji,jj,jk+kp)
+                        zslope2 = zslope_skew + ( gdept_n(ji,jj+1,jk) - gdept_n(ji,jj,jk) ) * r1_e2v(ji,jj) * vmask(ji,jj,jk+kp)
                         zslope2 = zslope2 * zslope2
                         ah_wslp2(ji,jj+jp,jk+kp) = ah_wslp2(ji,jj+jp,jk+kp) + zah * zbv * ze3wr * r1_e1e2t(ji,jj+jp) * zslope2
@@ -193,5 +191,5 @@
                      DO ji = 1, fs_jpim1
                         akz(ji,jj,jk) = 16._wp * ah_wslp2(ji,jj,jk)   &
-                           &          * (  akz(ji,jj,jk) + ah_wslp2(ji,jj,jk) / ( fse3w(ji,jj,jk) * fse3w(ji,jj,jk) )  )
+                           &          * (  akz(ji,jj,jk) + ah_wslp2(ji,jj,jk) / ( e3w_n(ji,jj,jk) * e3w_n(ji,jj,jk) )  )
                      END DO
                   END DO
@@ -201,5 +199,5 @@
                   DO jj = 1, jpjm1
                      DO ji = 1, fs_jpim1
-                        ze3w_2 = fse3w(ji,jj,jk) * fse3w(ji,jj,jk)
+                        ze3w_2 = e3w_n(ji,jj,jk) * e3w_n(ji,jj,jk)
                         zcoef0 = z2dt * (  akz(ji,jj,jk) + ah_wslp2(ji,jj,jk) / ze3w_2  )
                         akz(ji,jj,jk) = MAX( zcoef0 - 0.5_wp , 0._wp ) * ze3w_2 * z1_2dt
@@ -250,5 +248,5 @@
             ENDIF
          ENDIF
-
+         !
          !!----------------------------------------------------------------------
          !!   II - horizontal trend  (full)
@@ -256,5 +254,4 @@
          !
          DO jk = 1, jpkm1
-            !
             !                    !==  Vertical tracer gradient at level jk and jk+1
             zdkt3d(:,:,1) = ( ptb(:,:,jk,jn) - ptb(:,:,jk+1,jn) ) * tmask(:,:,jk+1)
@@ -274,10 +271,10 @@
                            ze1ur = r1_e1u(ji,jj)
                            zdxt  = zdit(ji,jj,jk) * ze1ur
-                           ze3wr = 1._wp / fse3w(ji+ip,jj,jk+kp)
+                           ze3wr = 1._wp / e3w_n(ji+ip,jj,jk+kp)
                            zdzt  = zdkt3d(ji+ip,jj,kp) * ze3wr
                            zslope_skew = triadi_g(ji+ip,jj,jk,1-ip,kp)
                            zslope_iso  = triadi  (ji+ip,jj,jk,1-ip,kp)
-
-                           zbu = 0.25_wp * e1e2u(ji,jj) * fse3u(ji,jj,jk)
+                           !
+                           zbu = 0.25_wp * e1e2u(ji,jj) * e3u_n(ji,jj,jk)
                            ! ln_botmix_triad is .T. don't mask zah for bottom half cells    !!gm ?????   ahu is masked....
                            zah = pahu(ji,jj,jk)
@@ -290,5 +287,5 @@
                   END DO
                END DO
-
+               !
                DO jp = 0, 1
                   DO kp = 0, 1
@@ -297,9 +294,9 @@
                            ze2vr = r1_e2v(ji,jj)
                            zdyt  = zdjt(ji,jj,jk) * ze2vr
-                           ze3wr = 1._wp / fse3w(ji,jj+jp,jk+kp)
+                           ze3wr = 1._wp / e3w_n(ji,jj+jp,jk+kp)
                            zdzt  = zdkt3d(ji,jj+jp,kp) * ze3wr
                            zslope_skew = triadj_g(ji,jj+jp,jk,1-jp,kp)
                            zslope_iso  = triadj(ji,jj+jp,jk,1-jp,kp)
-                           zbv = 0.25_wp * e1e2v(ji,jj) * fse3v(ji,jj,jk)
+                           zbv = 0.25_wp * e1e2v(ji,jj) * e3v_n(ji,jj,jk)
                            ! ln_botmix_triad is .T. don't mask zah for bottom half cells    !!gm ?????  ahv is masked...
                            zah = pahv(ji,jj,jk)
@@ -312,7 +309,7 @@
                   END DO
                END DO
-
+               !
             ELSE
-
+               !
                DO ip = 0, 1               !==  Horizontal & vertical fluxes
                   DO kp = 0, 1
@@ -321,14 +318,14 @@
                            ze1ur = r1_e1u(ji,jj)
                            zdxt  = zdit(ji,jj,jk) * ze1ur
-                           ze3wr = 1._wp / fse3w(ji+ip,jj,jk+kp)
+                           ze3wr = 1._wp / e3w_n(ji+ip,jj,jk+kp)
                            zdzt  = zdkt3d(ji+ip,jj,kp) * ze3wr
                            zslope_skew = triadi_g(ji+ip,jj,jk,1-ip,kp)
                            zslope_iso  = triadi(ji+ip,jj,jk,1-ip,kp)
-
-                           zbu = 0.25_wp * e1e2u(ji,jj) * fse3u(ji,jj,jk)
+                           !
+                           zbu = 0.25_wp * e1e2u(ji,jj) * e3u_n(ji,jj,jk)
                            ! ln_botmix_triad is .F. mask zah for bottom half cells
                            zah = pahu(ji,jj,jk) * umask(ji,jj,jk+kp)         ! pahu(ji+ip,jj,jk)   ===>>  ????
                            zah_slp  = zah * zslope_iso
-                           IF( ln_ldfeiv )   zaei_slp = aeiu(ji,jj,jk) * zslope_skew        ! fsaeit(ji+ip,jj,jk)*zslope_skew
+                           IF( ln_ldfeiv )   zaei_slp = aeiu(ji,jj,jk) * zslope_skew        ! aeit(ji+ip,jj,jk)*zslope_skew
                            zftu(ji   ,jj,jk   ) = zftu(ji   ,jj,jk   ) - ( zah * zdxt + (zah_slp - zaei_slp) * zdzt ) * zbu * ze1ur
                            ztfw(ji+ip,jj,jk+kp) = ztfw(ji+ip,jj,jk+kp) - (zah_slp + zaei_slp) * zdxt * zbu * ze3wr
@@ -337,5 +334,5 @@
                   END DO
                END DO
-
+               !
                DO jp = 0, 1
                   DO kp = 0, 1
@@ -344,13 +341,13 @@
                            ze2vr = r1_e2v(ji,jj)
                            zdyt  = zdjt(ji,jj,jk) * ze2vr
-                           ze3wr = 1._wp / fse3w(ji,jj+jp,jk+kp)
+                           ze3wr = 1._wp / e3w_n(ji,jj+jp,jk+kp)
                            zdzt  = zdkt3d(ji,jj+jp,kp) * ze3wr
                            zslope_skew = triadj_g(ji,jj+jp,jk,1-jp,kp)
                            zslope_iso  = triadj(ji,jj+jp,jk,1-jp,kp)
-                           zbv = 0.25_wp * e1e2v(ji,jj) * fse3v(ji,jj,jk)
+                           zbv = 0.25_wp * e1e2v(ji,jj) * e3v_n(ji,jj,jk)
                            ! ln_botmix_triad is .F. mask zah for bottom half cells
                            zah = pahv(ji,jj,jk) * vmask(ji,jj,jk+kp)         ! pahv(ji,jj+jp,jk)  ????
                            zah_slp = zah * zslope_iso
-                           IF( ln_ldfeiv )   zaei_slp = aeiv(ji,jj,jk) * zslope_skew        ! fsaeit(ji,jj+jp,jk)*zslope_skew
+                           IF( ln_ldfeiv )   zaei_slp = aeiv(ji,jj,jk) * zslope_skew        ! aeit(ji,jj+jp,jk)*zslope_skew
                            zftv(ji,jj,jk) = zftv(ji,jj,jk) - ( zah * zdyt + (zah_slp - zaei_slp) * zdzt ) * zbv * ze2vr
                            ztfw(ji,jj+jp,jk+kp) = ztfw(ji,jj+jp,jk+kp) - (zah_slp + zaei_slp) * zdyt * zbv * ze3wr
@@ -365,5 +362,5 @@
                   pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + zsign * (  zftu(ji-1,jj,jk) - zftu(ji,jj,jk)       &
                      &                                           + zftv(ji,jj-1,jk) - zftv(ji,jj,jk)   )   &
-                     &                                        / (  e1e2t(ji,jj) * fse3t(ji,jj,jk)  )
+                     &                                        / (  e1e2t(ji,jj) * e3t_n(ji,jj,jk)  )
                END DO
             END DO
@@ -376,5 +373,5 @@
                DO jj = 1, jpjm1
                   DO ji = fs_2, fs_jpim1
-                     ztfw(ji,jj,jk) = ztfw(ji,jj,jk) - e1e2t(ji,jj) / fse3w(ji,jj,jk) * tmask(ji,jj,jk)   &
+                     ztfw(ji,jj,jk) = ztfw(ji,jj,jk) - e1e2t(ji,jj) / e3w_n(ji,jj,jk) * tmask(ji,jj,jk)   &
                         &                            * ( ah_wslp2(ji,jj,jk) - akz(ji,jj,jk) )             &
                         &                            * ( ptb(ji,jj,jk-1,jn) - ptb(ji,jj,jk,jn) )
@@ -388,5 +385,5 @@
                   DO jj = 1, jpjm1
                      DO ji = fs_2, fs_jpim1
-                        ztfw(ji,jj,jk) = ztfw(ji,jj,jk) - e1e2t(ji,jj) / fse3w(ji,jj,jk) * tmask(ji,jj,jk)             &
+                        ztfw(ji,jj,jk) = ztfw(ji,jj,jk) - e1e2t(ji,jj) / e3w_n(ji,jj,jk) * tmask(ji,jj,jk)             &
                            &                            * ah_wslp2(ji,jj,jk) * ( ptb(ji,jj,jk-1,jn) - ptb(ji,jj,jk,jn) )
                      END DO
@@ -397,5 +394,5 @@
                   DO jj = 1, jpjm1
                      DO ji = fs_2, fs_jpim1
-                        ztfw(ji,jj,jk) = ztfw(ji,jj,jk) - e1e2t(ji,jj) / fse3w(ji,jj,jk) * tmask(ji,jj,jk)                      &
+                        ztfw(ji,jj,jk) = ztfw(ji,jj,jk) - e1e2t(ji,jj) / e3w_n(ji,jj,jk) * tmask(ji,jj,jk)                      &
                            &                            * (  ah_wslp2(ji,jj,jk) * ( ptb (ji,jj,jk-1,jn) - ptb (ji,jj,jk,jn) )   &
                            &                               + akz     (ji,jj,jk) * ( ptbb(ji,jj,jk-1,jn) - ptbb(ji,jj,jk,jn) )   )
@@ -410,5 +407,5 @@
                DO ji = fs_2, fs_jpim1  ! vector opt.
                   pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + zsign * (  ztfw(ji,jj,jk+1) - ztfw(ji,jj,jk)  )   &
-                     &                                        / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
+                     &                                        / ( e1e2t(ji,jj) * e3t_n(ji,jj,jk) )
                END DO
             END DO
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/tranpc.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/tranpc.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/tranpc.F90	(revision 6140)
@@ -13,19 +13,19 @@
 
    !!----------------------------------------------------------------------
-   !!   tra_npc : apply the non penetrative convection scheme
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and active tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE zdf_oce         ! ocean vertical physics
-   USE trd_oce         ! ocean active tracer trends
-   USE trdtra          ! ocean active tracer trends
-   USE eosbn2          ! equation of state (eos routine)
+   !!   tra_npc       : apply the non penetrative convection scheme
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and active tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE zdf_oce        ! ocean vertical physics
+   USE trd_oce        ! ocean active tracer trends
+   USE trdtra         ! ocean active tracer trends
+   USE eosbn2         ! equation of state (eos routine)
    !
-   USE lbclnk          ! lateral boundary conditions (or mpp link)
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE lbclnk         ! lateral boundary conditions (or mpp link)
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -35,5 +35,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -55,5 +54,5 @@
       !!              (i.e. static stability computed locally)
       !!
-      !! ** Action  : - (ta,sa) after the application od the npc scheme
+      !! ** Action  : - tsa: after tracers with the application of the npc scheme
       !!              - send the associated trends for on-line diagnostics (l_trdtra=T)
       !!
@@ -115,9 +114,9 @@
                   zvts(:,jp_tem) = tsa(ji,jj,:,jp_tem)      ! temperature
                   zvts(:,jp_sal) = tsa(ji,jj,:,jp_sal)      ! salinity
-
+                  !
                   zvab(:,jp_tem)  = zab(ji,jj,:,jp_tem)     ! Alpha 
                   zvab(:,jp_sal)  = zab(ji,jj,:,jp_sal)     ! Beta  
                   zvn2(:)         = zn2(ji,jj,:)            ! N^2 
-                 
+                  !
                   IF( l_LB_debug ) THEN                  !LB debug:
                      lp_monitor_point = .FALSE.
@@ -126,5 +125,5 @@
                      lp_monitor_point = (narea == nncpu).AND.lp_monitor_point                      
                   ENDIF                                  !LB debug  end
-
+                  !
                   ikbot = mbkt(ji,jj)   ! ikbot: ocean bottom T-level
                   ikp = 1                  ! because N2 is irrelevant at the surface level (will start at ikp=2)
@@ -132,23 +131,23 @@
                   jiter  = 0
                   l_column_treated = .FALSE.
-                 
+                  !
                   DO WHILE ( .NOT. l_column_treated )
                      !
                      jiter = jiter + 1
-                    
+                     ! 
                      IF( jiter >= 400 ) EXIT
-                    
+                     !
                      l_bottom_reached = .FALSE.
-
+                     !
                      DO WHILE ( .NOT. l_bottom_reached )
-
+                        !
                         ikp = ikp + 1
-                       
+                        !
                         !! Testing level ikp for instability
                         !! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                         IF( zvn2(ikp) <  -zn2_zero ) THEN ! Instability found!
-
+                           !
                            ilayer = ilayer + 1    ! yet another instable portion of the water column found....
-
+                           !
                            IF( lp_monitor_point ) THEN 
                               WRITE(numout,*)
@@ -165,13 +164,12 @@
                               WRITE(numout,*)
                            ENDIF
-                           
-
+                           !
                            IF( jiter == 1 )   inpcc = inpcc + 1 
-
+                           !
                            IF( lp_monitor_point )   WRITE(numout, *) 'Negative N2 at ikp =',ikp,' for layer #', ilayer
-
+                           !
                            !! ikup is the uppermost point where mixing will start:
                            ikup = ikp - 1 ! ikup is always "at most at ikp-1", less if neutral levels overlying
-                           
+                           !
                            !! If the points above ikp-1 have N2 == 0 they must also be mixed:
                            IF( ikp > 2 ) THEN
@@ -184,7 +182,7 @@
                               END DO
                            ENDIF
-                           
+                           !
                            IF( ikup < 1 )   CALL ctl_stop( 'tra_npc :  PROBLEM #1')
-
+                           !
                            zsum_temp = 0._wp
                            zsum_sali = 0._wp
@@ -195,5 +193,5 @@
                            DO jk = ikup, ikbot      ! Inside the instable (and overlying neutral) portion of the column
                               !
-                              zdz       = fse3t(ji,jj,jk)
+                              zdz       = e3t_n(ji,jj,jk)
                               zsum_temp = zsum_temp + zvts(jk,jp_tem)*zdz
                               zsum_sali = zsum_sali + zvts(jk,jp_sal)*zdz
@@ -244,6 +242,6 @@
 
                               !! Interpolating alfa and beta at W point:
-                              zrw =  (fsdepw(ji,jj,jk  ) - fsdept(ji,jj,jk)) &
-                                 & / (fsdept(ji,jj,jk-1) - fsdept(ji,jj,jk))
+                              zrw =  (gdepw_n(ji,jj,jk  ) - gdept_n(ji,jj,jk)) &
+                                 & / (gdept_n(ji,jj,jk-1) - gdept_n(ji,jj,jk))
                               zaw = zvab(jk,jp_tem) * (1._wp - zrw) + zvab(jk-1,jp_tem) * zrw
                               zbw = zvab(jk,jp_sal) * (1._wp - zrw) + zvab(jk-1,jp_sal) * zrw
@@ -252,5 +250,5 @@
                               zvn2(jk) = grav*( zaw * ( zvts(jk-1,jp_tem) - zvts(jk,jp_tem) )     &
                                  &            - zbw * ( zvts(jk-1,jp_sal) - zvts(jk,jp_sal) )  )  &
-                                 &       / fse3w(ji,jj,jk) * tmask(ji,jj,jk)
+                                 &       / e3w_n(ji,jj,jk) * tmask(ji,jj,jk)
 
                               !! OR, faster  => just considering the vertical gradient of density
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 6140)
@@ -28,5 +28,5 @@
    USE sbc_oce         ! surface boundary condition: ocean
    USE sbcrnf          ! river runoffs
-   USE sbcisf          ! ice shelf melting/freezing
+   USE sbcisf          ! ice shelf melting
    USE zdf_oce         ! ocean vertical mixing
    USE domvvl          ! variable volume
@@ -56,7 +56,6 @@
    PUBLIC   tra_nxt_vvl   ! to be used in trcnxt
 
-
    !! * Substitutions
-#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO-Consortium (2010) 
@@ -86,11 +85,10 @@
       !!             domains (lk_agrif=T)
       !!
-      !! ** Action  : - (tb,sb) and (tn,sn) ready for the next time step
-      !!
+      !! ** Action  : - tsb & tsn ready for the next time step
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt    ! ocean time-step index
       !!
-      INTEGER  ::   jk, jn    ! dummy loop indices
-      REAL(wp) ::   zfact     ! local scalars
+      INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
+      REAL(wp) ::   zfact            ! local scalars
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdt, ztrds
       !!----------------------------------------------------------------------
@@ -106,5 +104,4 @@
       ! Update after tracer on domain lateral boundaries
       ! 
-      !
 #if defined key_agrif
       CALL Agrif_tra                     ! AGRIF zoom boundaries
@@ -119,6 +116,6 @@
  
       ! set time step size (Euler/Leapfrog)
-      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;   r2dtra(:) =     rdttra(:)      ! at nit000             (Euler)
-      ELSEIF( kt <= nit000 + 1 )           THEN   ;   r2dtra(:) = 2._wp* rdttra(:)      ! at nit000 or nit000+1 (Leapfrog)
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;   r2dt =     rdt      ! at nit000             (Euler)
+      ELSEIF( kt <= nit000 + 1 )           THEN   ;   r2dt = 2._wp* rdt   ! at nit000 or nit000+1 (Leapfrog)
       ENDIF
 
@@ -140,16 +137,22 @@
             END DO
          END DO
+         !
       ELSE                                            ! Leap-Frog + Asselin filter time stepping
          !
-         IF( lk_vvl )  THEN   ;   CALL tra_nxt_vvl( kt, nit000, rdttra, 'TRA', tsb, tsn, tsa,   &
-           &                                                              sbc_tsc, sbc_tsc_b, jpts )  ! variable volume level (vvl) 
-         ELSE                 ;   CALL tra_nxt_fix( kt, nit000,         'TRA', tsb, tsn, tsa, jpts )  ! fixed    volume level 
+         IF( ln_linssh ) THEN   ;   CALL tra_nxt_fix( kt, nit000,      'TRA', tsb, tsn, tsa, jpts )  ! linear free surface 
+         ELSE                   ;   CALL tra_nxt_vvl( kt, nit000, rdt, 'TRA', tsb, tsn, tsa,   &
+           &                                                                sbc_tsc, sbc_tsc_b, jpts )  ! non-linear free surface
          ENDIF
+         !
+         DO jn = 1, jpts
+            CALL lbc_lnk( tsb(:,:,:,jn), 'T', 1._wp ) 
+            CALL lbc_lnk( tsn(:,:,:,jn), 'T', 1._wp )
+            CALL lbc_lnk( tsa(:,:,:,jn), 'T', 1._wp )
+         END DO
       ENDIF     
       !
-      ! trends computation
       IF( l_trdtra ) THEN      ! trend of the Asselin filter (tb filtered - tb)/dt     
          DO jk = 1, jpkm1
-            zfact = 1._wp / r2dtra(jk)             
+            zfact = 1._wp / r2dt             
             ztrdt(:,:,jk) = ( tsb(:,:,jk,jp_tem) - ztrdt(:,:,jk) ) * zfact
             ztrds(:,:,jk) = ( tsb(:,:,jk,jp_sal) - ztrds(:,:,jk) ) * zfact
@@ -179,19 +182,18 @@
       !!              - swap tracer fields to prepare the next time_step.
       !!
-      !! ** Action  : - (tb,sb) and (tn,sn) ready for the next time step
-      !!              
-      !!----------------------------------------------------------------------
-      INTEGER         , INTENT(in   )                               ::   kt       ! ocean time-step index
-      INTEGER         , INTENT(in   )                               ::   kit000   ! first time step index
-      CHARACTER(len=3), INTENT(in   )                               ::   cdtype   ! =TRA or TRC (tracer indicator)
-      INTEGER         , INTENT(in   )                               ::   kjpt     ! number of tracers
-      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk,kjpt)  ::   ptb      ! before tracer fields
-      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk,kjpt)  ::   ptn      ! now tracer fields
-      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk,kjpt)  ::   pta      ! tracer trend
+      !! ** Action  : - tsb & tsn ready for the next time step
+      !!----------------------------------------------------------------------
+      INTEGER                              , INTENT(in   ) ::  kt        ! ocean time-step index
+      INTEGER                              , INTENT(in   ) ::  kit000    ! first time step index
+      CHARACTER(len=3)                     , INTENT(in   ) ::  cdtype    ! =TRA or TRC (tracer indicator)
+      INTEGER                              , INTENT(in   ) ::  kjpt      ! number of tracers
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::  ptb       ! before tracer fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::  ptn       ! now tracer fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::  pta       ! tracer trend
       !
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
       REAL(wp) ::   ztn, ztd         ! local scalars
       !!----------------------------------------------------------------------
-
+      !
       IF( kt == kit000 )  THEN
          IF(lwp) WRITE(numout,*)
@@ -200,16 +202,14 @@
       ENDIF
       !
-      !
       DO jn = 1, kjpt
          !
          DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
                   ztn = ptn(ji,jj,jk,jn)                                    
-                  ztd = pta(ji,jj,jk,jn) - 2. * ztn + ptb(ji,jj,jk,jn)      !  time laplacian on tracers
-                  !
-                  ptb(ji,jj,jk,jn) = ztn + atfp * ztd                       ! ptb <-- filtered ptn 
-                  ptn(ji,jj,jk,jn) = pta(ji,jj,jk,jn)                       ! ptn <-- pta
-                  !
+                  ztd = pta(ji,jj,jk,jn) - 2._wp * ztn + ptb(ji,jj,jk,jn)  ! time laplacian on tracers
+                  !
+                  ptb(ji,jj,jk,jn) = ztn + atfp * ztd                      ! ptb <-- filtered ptn 
+                  ptn(ji,jj,jk,jn) = pta(ji,jj,jk,jn)                      ! ptn <-- pta
                END DO
            END DO
@@ -230,21 +230,21 @@
       !! ** Method  : - Apply a thickness weighted Asselin time filter on now fields.
       !!              - swap tracer fields to prepare the next time_step.
-      !!                This can be summurized for tempearture as:
-      !!
-      !! ** Action  : - (tb,sb) and (tn,sn) ready for the next time step
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER         , INTENT(in   )                               ::  kt       ! ocean time-step index
-      INTEGER         , INTENT(in   )                               ::  kit000   ! first time step index
-      REAL(wp)        , INTENT(in   ), DIMENSION(jpk)               ::  p2dt     ! time-step
-      CHARACTER(len=3), INTENT(in   )                               ::  cdtype   ! =TRA or TRC (tracer indicator)
-      INTEGER         , INTENT(in   )                               ::  kjpt     ! number of tracers
-      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk,kjpt)  ::  ptb      ! before tracer fields
-      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk,kjpt)  ::  ptn      ! now tracer fields
-      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk,kjpt)  ::  pta      ! tracer trend
-      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,kjpt)      ::  psbc_tc   ! surface tracer content
-      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,kjpt)      ::  psbc_tc_b ! before surface tracer content
-
-      !!     
+      !!             tb  = ( e3t_n*tn + atfp*[ e3t_b*tb - 2 e3t_n*tn + e3t_a*ta ] )
+      !!                  /( e3t_n    + atfp*[ e3t_b    - 2 e3t_n    + e3t_a    ] )
+      !!             tn  = ta 
+      !!
+      !! ** Action  : - tsb & tsn ready for the next time step
+      !!----------------------------------------------------------------------
+      INTEGER                              , INTENT(in   ) ::  kt        ! ocean time-step index
+      INTEGER                              , INTENT(in   ) ::  kit000    ! first time step index
+      REAL(wp)                             , INTENT(in   ) ::  p2dt      ! time-step
+      CHARACTER(len=3)                     , INTENT(in   ) ::  cdtype    ! =TRA or TRC (tracer indicator)
+      INTEGER                              , INTENT(in   ) ::  kjpt      ! number of tracers
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::  ptb       ! before tracer fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::  ptn       ! now tracer fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::  pta       ! tracer trend
+      REAL(wp), DIMENSION(jpi,jpj    ,kjpt), INTENT(in   ) ::  psbc_tc   ! surface tracer content
+      REAL(wp), DIMENSION(jpi,jpj    ,kjpt), INTENT(in   ) ::  psbc_tc_b ! before surface tracer content
+      !
       LOGICAL  ::   ll_traqsr, ll_rnf, ll_isf   ! local logical
       INTEGER  ::   ji, jj, jk, jn              ! dummy loop indices
@@ -262,24 +262,20 @@
          ll_traqsr  = ln_traqsr        ! active  tracers case  and  solar penetration
          ll_rnf     = ln_rnf           ! active  tracers case  and  river runoffs
-         IF (nn_isf .GE. 1) THEN 
-            ll_isf = .TRUE.            ! active  tracers case  and  ice shelf melting/freezing
-         ELSE
-            ll_isf = .FALSE.
-         END IF
-      ELSE                          
-         ll_traqsr  = .FALSE.          ! active  tracers case and NO solar penetration
-         ll_rnf     = .FALSE.          ! passive tracers or NO river runoffs
-         ll_isf     = .FALSE.          ! passive tracers or NO ice shelf melting/freezing
+         ll_isf     = ln_isf           ! active  tracers case  and  ice shelf melting
+      ELSE                          ! passive tracers case
+         ll_traqsr  = .FALSE.          ! NO solar penetration
+         ll_rnf     = .FALSE.          ! NO river runoffs ????          !!gm BUG ?  
+         ll_isf     = .FALSE.          ! NO ice shelf melting/freezing  !!gm BUG ?? 
       ENDIF
       !
       DO jn = 1, kjpt      
          DO jk = 1, jpkm1
-            zfact1 = atfp * p2dt(jk)
-            zfact2 = zfact1 / rau0
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ze3t_b = fse3t_b(ji,jj,jk)
-                  ze3t_n = fse3t_n(ji,jj,jk)
-                  ze3t_a = fse3t_a(ji,jj,jk)
+            zfact1 = atfp * p2dt
+            zfact2 = zfact1 * r1_rau0
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  ze3t_b = e3t_b(ji,jj,jk)
+                  ze3t_n = e3t_n(ji,jj,jk)
+                  ze3t_a = e3t_a(ji,jj,jk)
                   !                                         ! tracer content at Before, now and after
                   ztc_b  = ptb(ji,jj,jk,jn) * ze3t_b
@@ -299,14 +295,14 @@
                      ztc_f  = ztc_f  - zfact1 * ( psbc_tc(ji,jj,jn) - psbc_tc_b(ji,jj,jn) )
                   ENDIF
-
+                  !
                   ! solar penetration (temperature only)
                   IF( ll_traqsr .AND. jn == jp_tem .AND. jk <= nksr )                            & 
                      &     ztc_f  = ztc_f  - zfact1 * ( qsr_hc(ji,jj,jk) - qsr_hc_b(ji,jj,jk) ) 
-
+                     !
                   ! river runoff
                   IF( ll_rnf .AND. jk <= nk_rnf(ji,jj) )                                          &
                      &     ztc_f  = ztc_f  - zfact1 * ( rnf_tsc(ji,jj,jn) - rnf_tsc_b(ji,jj,jn) ) & 
-                     &                              * fse3t_n(ji,jj,jk) / h_rnf(ji,jj)
-
+                     &                              * e3t_n(ji,jj,jk) / h_rnf(ji,jj)
+                     !
                   ! ice shelf
                   IF( ll_isf ) THEN
@@ -314,11 +310,11 @@
                      IF ( jk >= misfkt(ji,jj) .AND. jk < misfkb(ji,jj) )                          &
                         ztc_f  = ztc_f  - zfact1 * ( risf_tsc(ji,jj,jn) - risf_tsc_b(ji,jj,jn) )  &
-                               &                 * fse3t_n(ji,jj,jk) * r1_hisf_tbl (ji,jj)
+                               &                 * e3t_n(ji,jj,jk) * r1_hisf_tbl (ji,jj)
                      ! level partially include in Losch_2008 ice shelf boundary layer 
                      IF ( jk == misfkb(ji,jj) )                                                   &
                         ztc_f  = ztc_f  - zfact1 * ( risf_tsc(ji,jj,jn) - risf_tsc_b(ji,jj,jn) )  &
-                               &                 * fse3t_n(ji,jj,jk) * r1_hisf_tbl (ji,jj) * ralpha(ji,jj)
+                               &                 * e3t_n(ji,jj,jk) * r1_hisf_tbl (ji,jj) * ralpha(ji,jj)
                   END IF
-
+                  !
                   ze3t_f = 1.e0 / ze3t_f
                   ptb(ji,jj,jk,jn) = ztc_f * ze3t_f       ! ptb <-- ptn filtered
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 6140)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE  traqsr  ***
-   !! Ocean physics: solar radiation penetration in the top ocean levels
+   !! Ocean physics:   solar radiation penetration in the top ocean levels
    !!======================================================================
    !! History :  OPA  !  1990-10  (B. Blanke)  Original code
@@ -10,24 +10,27 @@
    !!             -   !  2005-11  (G. Madec) zco, zps, sco coordinate
    !!            3.2  !  2009-04  (G. Madec & NEMO team) 
-   !!            4.0  !  2012-05  (C. Rousset) store attenuation coef for use in ice model 
+   !!            3.6  !  2012-05  (C. Rousset) store attenuation coef for use in ice model 
+   !!            3.7  !  2015-11  (G. Madec, A. Coward)  remove optimisation for fix volume 
    !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
-   !!   tra_qsr      : trend due to the solar radiation penetration
-   !!   tra_qsr_init : solar radiation penetration initialization
+   !!   tra_qsr       : temperature trend due to the penetration of solar radiation 
+   !!   tra_qsr_init  : initialization of the qsr penetration 
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and active tracers
-   USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! surface boundary condition: ocean
-   USE trc_oce         ! share SMS/Ocean variables
+   USE oce            ! ocean dynamics and active tracers
+   USE phycst         ! physical constants
+   USE dom_oce        ! ocean space and time domain
+   USE sbc_oce        ! surface boundary condition: ocean
+   USE trc_oce        ! share SMS/Ocean variables
    USE trd_oce        ! trends: ocean variables
    USE trdtra         ! trends manager: tracers
-   USE in_out_manager  ! I/O manager
-   USE phycst          ! physical constants
-   USE prtctl          ! Print control
-   USE iom             ! I/O manager
-   USE fldread         ! read input fields
-   USE restart         ! ocean restart
-   USE lib_mpp         ! MPP library
+   !
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
+   USE iom            ! I/O manager
+   USE fldread        ! read input fields
+   USE restart        ! ocean restart
+   USE lib_mpp        ! MPP library
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
    USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
@@ -49,14 +52,20 @@
    REAL(wp), PUBLIC ::   rn_si0       !: very near surface depth of extinction      (RGB & 2 bands)
    REAL(wp), PUBLIC ::   rn_si1       !: deepest depth of extinction (water type I)       (2 bands)
+   !
+   INTEGER , PUBLIC ::   nksr         !: levels below which the light cannot penetrate (depth larger than 391 m)
  
-   ! Module variables
-   REAL(wp) ::   xsi0r                           !: inverse of rn_si0
-   REAL(wp) ::   xsi1r                           !: inverse of rn_si1
+   INTEGER, PARAMETER ::   np_RGB  = 1   ! R-G-B     light penetration with constant Chlorophyll
+   INTEGER, PARAMETER ::   np_RGBc = 2   ! R-G-B     light penetration with Chlorophyll data
+   INTEGER, PARAMETER ::   np_2BD  = 3   ! 2 bands   light penetration
+   INTEGER, PARAMETER ::   np_BIO  = 4   ! bio-model light penetration
+   !
+   INTEGER  ::   nqsr    ! user choice of the type of light penetration
+   REAL(wp) ::   xsi0r   ! inverse of rn_si0
+   REAL(wp) ::   xsi1r   ! inverse of rn_si1
+   !
+   REAL(wp) , DIMENSION(3,61)           ::   rkrgb    ! tabulated attenuation coefficients for RGB absorption
    TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_chl   ! structure of input Chl (file informations, fields read)
-   INTEGER, PUBLIC ::   nksr              ! levels below which the light cannot penetrate ( depth larger than 391 m)
-   REAL(wp), DIMENSION(3,61) ::   rkrgb   !: tabulated attenuation coefficients for RGB absorption
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -72,5 +81,5 @@
       !!
       !! ** Purpose :   Compute the temperature trend due to the solar radiation
-      !!      penetration and add it to the general temperature trend.
+      !!              penetration and add it to the general temperature trend.
       !!
       !! ** Method  : The profile of the solar radiation within the ocean is defined
@@ -83,32 +92,27 @@
       !!      all heat which has not been absorbed in the above levels is put
       !!      in the last ocean level.
-      !!         In z-coordinate case, the computation is only done down to the
-      !!      level where I(k) < 1.e-15 W/m2. In addition, the coefficients 
-      !!      used for the computation are calculated one for once as they
-      !!      depends on k only.
+      !!         The computation is only done down to the level where 
+      !!      I(k) < 1.e-15 W/m2 (i.e. over the top nksr levels) . 
       !!
       !! ** Action  : - update ta with the penetrative solar radiation trend
-      !!              - save the trend in ttrd ('key_trdtra')
+      !!              - send  trend for further diagnostics (l_trdtra=T)
       !!
       !! Reference  : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
       !!              Lengaigne et al. 2007, Clim. Dyn., V28, 5, 503-516.
       !!----------------------------------------------------------------------
-      !
       INTEGER, INTENT(in) ::   kt     ! ocean time-step
       !
-      INTEGER  ::   ji, jj, jk           ! dummy loop indices
-      INTEGER  ::   irgb                 ! local integers
-      REAL(wp) ::   zchl, zcoef, zfact   ! local scalars
-      REAL(wp) ::   zc0, zc1, zc2, zc3   !    -         -
+      INTEGER  ::   ji, jj, jk               ! dummy loop indices
+      INTEGER  ::   irgb                     ! local integers
+      REAL(wp) ::   zchl, zcoef, z1_2        ! local scalars
+      REAL(wp) ::   zc0 , zc1 , zc2 , zc3    !    -         -
       REAL(wp) ::   zzc0, zzc1, zzc2, zzc3   !    -         -
-      REAL(wp) ::   zz0, zz1, z1_e3t     !    -         -
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: zekb, zekg, zekr
+      REAL(wp) ::   zz0 , zz1                !    -         -
+      REAL(wp), POINTER, DIMENSION(:,:)   :: zekb, zekg, zekr
       REAL(wp), POINTER, DIMENSION(:,:,:) :: ze0, ze1, ze2, ze3, zea, ztrdt
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zetot
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('tra_qsr')
-      !
-      CALL wrk_alloc( jpi, jpj,      zekb, zekg, zekr        ) 
-      CALL wrk_alloc( jpi, jpj, jpk, ze0, ze1, ze2, ze3, zea ) 
       !
       IF( kt == nit000 ) THEN
@@ -116,223 +120,168 @@
          IF(lwp) WRITE(numout,*) 'tra_qsr : penetration of the surface solar radiation'
          IF(lwp) WRITE(numout,*) '~~~~~~~'
-         IF( .NOT.ln_traqsr )   RETURN
-      ENDIF
-
-      IF( l_trdtra ) THEN      ! Save ta and sa trends
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdt ) 
+      ENDIF
+      !
+      IF( l_trdtra ) THEN      ! trends diagnostic: save the input temperature trend
+         CALL wrk_alloc( jpi,jpj,jpk,   ztrdt ) 
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
       ENDIF
-
-      !                                        Set before qsr tracer content field
-      !                                        ***********************************
-      IF( kt == nit000 ) THEN                     ! Set the forcing field at nit000 - 1
-         !                                        ! -----------------------------------
-         qsr_hc(:,:,:) = 0.e0
-         !
-         IF( ln_rstart .AND.    &                    ! Restart: read in restart file
-              & iom_varid( numror, 'qsr_hc_b', ldstop = .FALSE. ) > 0 ) THEN
-            IF(lwp) WRITE(numout,*) '          nit000-1 qsr tracer content forcing field red in the restart file'
-            zfact = 0.5e0
+      !
+      !                         !-----------------------------------!
+      !                         !  before qsr induced heat content  !
+      !                         !-----------------------------------!
+      IF( kt == nit000 ) THEN          !==  1st time step  ==!
+!!gm case neuler  not taken into account....
+         IF( ln_rstart .AND. iom_varid( numror, 'qsr_hc_b', ldstop = .FALSE. ) > 0 ) THEN    ! read in restart
+            IF(lwp) WRITE(numout,*) '          nit000-1 qsr tracer content forcing field read in the restart file'
+            z1_2 = 0.5_wp
             CALL iom_get( numror, jpdom_autoglo, 'qsr_hc_b', qsr_hc_b )   ! before heat content trend due to Qsr flux
          ELSE                                           ! No restart or restart not found: Euler forward time stepping
-            zfact = 1.e0
-            qsr_hc_b(:,:,:) = 0.e0
+            z1_2 = 1._wp
+            qsr_hc_b(:,:,:) = 0._wp
          ENDIF
-      ELSE                                        ! Swap of forcing field
-         !                                        ! ---------------------
-         zfact = 0.5e0
+      ELSE                             !==  Swap of qsr heat content  ==!
+         z1_2 = 0.5_wp
          qsr_hc_b(:,:,:) = qsr_hc(:,:,:)
       ENDIF
-      !                                        Compute now qsr tracer content field
-      !                                        ************************************
-      
-      !                                           ! ============================================== !
-      IF( lk_qsr_bio .AND. ln_qsr_bio ) THEN      !  bio-model fluxes  : all vertical coordinates  !
-         !                                        ! ============================================== !
-         DO jk = 1, jpkm1
+      !
+      !                         !--------------------------------!
+      SELECT CASE( nqsr )       !  now qsr induced heat content  !
+      !                         !--------------------------------!
+      !
+      CASE( np_BIO )                   !==  bio-model fluxes  ==!
+         !
+         DO jk = 1, nksr
             qsr_hc(:,:,jk) = r1_rau0_rcp * ( etot3(:,:,jk) - etot3(:,:,jk+1) )
          END DO
-         !                                        Add to the general trend
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1 
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z1_e3t = zfact / fse3t(ji,jj,jk)
-                  tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem) + ( qsr_hc_b(ji,jj,jk) + qsr_hc(ji,jj,jk) ) * z1_e3t
+         !
+      CASE( np_RGB , np_RGBc )         !==  R-G-B fluxes  ==!
+         !
+         CALL wrk_alloc( jpi,jpj,       zekb, zekg, zekr        ) 
+         CALL wrk_alloc( jpi,jpj,jpk,   ze0, ze1, ze2, ze3, zea ) 
+         !
+         IF( nqsr == np_RGBc ) THEN          !*  Variable Chlorophyll
+            CALL fld_read( kt, 1, sf_chl )         ! Read Chl data and provides it at the current time step
+            DO jj = 2, jpjm1                       ! Separation in R-G-B depending of the surface Chl
+               DO ji = fs_2, fs_jpim1
+                  zchl = MIN( 10. , MAX( 0.03, sf_chl(1)%fnow(ji,jj,1) ) )
+                  irgb = NINT( 41 + 20.*LOG10(zchl) + 1.e-15 )
+                  zekb(ji,jj) = rkrgb(1,irgb)
+                  zekg(ji,jj) = rkrgb(2,irgb)
+                  zekr(ji,jj) = rkrgb(3,irgb)
                END DO
             END DO
-         END DO
-         CALL iom_put( 'qsr3d', etot3 )   ! Shortwave Radiation 3D distribution
-         ! clem: store attenuation coefficient of the first ocean level
-         IF ( ln_qsr_ice ) THEN
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  IF ( qsr(ji,jj) /= 0._wp ) THEN
-                     fraqsr_1lev(ji,jj) = ( qsr_hc(ji,jj,1) / ( r1_rau0_rcp * qsr(ji,jj) ) )
-                  ELSE
-                     fraqsr_1lev(ji,jj) = 1.
-                  ENDIF
+         ELSE                                !* constant chrlorophyll
+            zchl = 0.05                            ! constant chlorophyll
+            !                                      ! Separation in R-G-B depending of the chlorophyll
+            irgb = NINT( 41 + 20.*LOG10( zchl ) + 1.e-15 )
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  zekb(ji,jj) = rkrgb(1,irgb)                      
+                  zekg(ji,jj) = rkrgb(2,irgb)
+                  zekr(ji,jj) = rkrgb(3,irgb)
                END DO
             END DO
          ENDIF
-         !                                        ! ============================================== !
-      ELSE                                        !  Ocean alone : 
-         !                                        ! ============================================== !
-         !
-         !                                                ! ------------------------- !
-         IF( ln_qsr_rgb) THEN                             !  R-G-B  light penetration !
-            !                                             ! ------------------------- !
-            ! Set chlorophyl concentration
-            IF( nn_chldta == 1 .OR. lk_vvl ) THEN            !*  Variable Chlorophyll or ocean volume
-               !
-               IF( nn_chldta == 1 ) THEN                             !*  Variable Chlorophyll
-                  !
-                  CALL fld_read( kt, 1, sf_chl )                         ! Read Chl data and provides it at the current time step
-                  !         
-                  DO jj = 1, jpj                                         ! Separation in R-G-B depending of the surface Chl
-                     DO ji = 1, jpi
-                        zchl = MIN( 10. , MAX( 0.03, sf_chl(1)%fnow(ji,jj,1) ) )
-                        irgb = NINT( 41 + 20.*LOG10(zchl) + 1.e-15 )
-                        zekb(ji,jj) = rkrgb(1,irgb)
-                        zekg(ji,jj) = rkrgb(2,irgb)
-                        zekr(ji,jj) = rkrgb(3,irgb)
-                     END DO
-                  END DO
-               ELSE                                            ! Variable ocean volume but constant chrlorophyll
-                  zchl = 0.05                                     ! constant chlorophyll
-                  irgb = NINT( 41 + 20.*LOG10( zchl ) + 1.e-15 )
-                  zekb(:,:) = rkrgb(1,irgb)                       ! Separation in R-G-B depending of the chlorophyll 
-                  zekg(:,:) = rkrgb(2,irgb)
-                  zekr(:,:) = rkrgb(3,irgb)
+         !
+         zcoef  = ( 1. - rn_abs ) / 3._wp    !* surface equi-partition in R-G-B
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               ze0(ji,jj,1) = rn_abs * qsr(ji,jj)
+               ze1(ji,jj,1) = zcoef  * qsr(ji,jj)
+               ze2(ji,jj,1) = zcoef  * qsr(ji,jj)
+               ze3(ji,jj,1) = zcoef  * qsr(ji,jj)
+               zea(ji,jj,1) =          qsr(ji,jj)
+            END DO
+         END DO
+         !
+         DO jk = 2, nksr+1                   !* interior equi-partition in R-G-B
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  zc0 = ze0(ji,jj,jk-1) * EXP( - e3t_n(ji,jj,jk-1) * xsi0r       )
+                  zc1 = ze1(ji,jj,jk-1) * EXP( - e3t_n(ji,jj,jk-1) * zekb(ji,jj) )
+                  zc2 = ze2(ji,jj,jk-1) * EXP( - e3t_n(ji,jj,jk-1) * zekg(ji,jj) )
+                  zc3 = ze3(ji,jj,jk-1) * EXP( - e3t_n(ji,jj,jk-1) * zekr(ji,jj) )
+                  ze0(ji,jj,jk) = zc0
+                  ze1(ji,jj,jk) = zc1
+                  ze2(ji,jj,jk) = zc2
+                  ze3(ji,jj,jk) = zc3
+                  zea(ji,jj,jk) = ( zc0 + zc1 + zc2 + zc3 ) * wmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !
+         DO jk = 1, nksr                     !* now qsr induced heat content
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  qsr_hc(ji,jj,jk) = r1_rau0_rcp * ( zea(ji,jj,jk) - zea(ji,jj,jk+1) )
+               END DO
+            END DO
+         END DO
+         !
+         CALL wrk_dealloc( jpi,jpj,        zekb, zekg, zekr        ) 
+         CALL wrk_dealloc( jpi,jpj,jpk,   ze0, ze1, ze2, ze3, zea ) 
+         !
+      CASE( np_2BD  )            !==  2-bands fluxes  ==!
+         !
+         zz0 =        rn_abs   * r1_rau0_rcp      ! surface equi-partition in 2-bands
+         zz1 = ( 1. - rn_abs ) * r1_rau0_rcp
+         DO jk = 1, nksr                          ! solar heat absorbed at T-point in the top 400m 
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  zc0 = zz0 * EXP( -gdepw_n(ji,jj,jk  )*xsi0r ) + zz1 * EXP( -gdepw_n(ji,jj,jk  )*xsi1r )
+                  zc1 = zz0 * EXP( -gdepw_n(ji,jj,jk+1)*xsi0r ) + zz1 * EXP( -gdepw_n(ji,jj,jk+1)*xsi1r )
+                  qsr_hc(ji,jj,jk) = qsr(ji,jj) * ( zc0 * wmask(ji,jj,jk) - zc1 * wmask(ji,jj,jk+1) ) 
+               END DO
+            END DO
+         END DO
+         !
+      END SELECT
+      !
+      !                          !-----------------------------!
+      DO jk = 1, nksr            !  update to the temp. trend  !
+         DO jj = 2, jpjm1        !-----------------------------!
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem)   &
+                  &                 + z1_2 * ( qsr_hc_b(ji,jj,jk) + qsr_hc(ji,jj,jk) ) / e3t_n(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+      IF( ln_qsr_ice ) THEN      ! sea-ice: store the 1st ocean level attenuation coefficient
+         DO jj = 2, jpjm1 
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               IF( qsr(ji,jj) /= 0._wp ) THEN   ;   fraqsr_1lev(ji,jj) = qsr_hc(ji,jj,1) / ( r1_rau0_rcp * qsr(ji,jj) )
+               ELSE                             ;   fraqsr_1lev(ji,jj) = 1._wp
                ENDIF
-               !
-               zcoef  = ( 1. - rn_abs ) / 3.e0                        ! equi-partition in R-G-B
-               ze0(:,:,1) = rn_abs  * qsr(:,:)
-               ze1(:,:,1) = zcoef * qsr(:,:)
-               ze2(:,:,1) = zcoef * qsr(:,:)
-               ze3(:,:,1) = zcoef * qsr(:,:)
-               zea(:,:,1) =         qsr(:,:)
-               !
-               DO jk = 2, nksr+1
-                  DO jj = 1, jpj
-                     DO ji = 1, jpi
-                        zc0 = ze0(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * xsi0r     )
-                        zc1 = ze1(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekb(ji,jj) )
-                        zc2 = ze2(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekg(ji,jj) )
-                        zc3 = ze3(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekr(ji,jj) )
-                        ze0(ji,jj,jk) = zc0
-                        ze1(ji,jj,jk) = zc1
-                        ze2(ji,jj,jk) = zc2
-                        ze3(ji,jj,jk) = zc3
-                        zea(ji,jj,jk) = ( zc0 + zc1 + zc2 + zc3 ) * tmask(ji,jj,jk)
-                     END DO
-                  END DO
-               END DO
-               ! clem: store attenuation coefficient of the first ocean level
-               IF ( ln_qsr_ice ) THEN
-                  DO jj = 1, jpj
-                     DO ji = 1, jpi
-                        zzc0 = rn_abs * EXP( - fse3t(ji,jj,1) * xsi0r     )
-                        zzc1 = zcoef  * EXP( - fse3t(ji,jj,1) * zekb(ji,jj) )
-                        zzc2 = zcoef  * EXP( - fse3t(ji,jj,1) * zekg(ji,jj) )
-                        zzc3 = zcoef  * EXP( - fse3t(ji,jj,1) * zekr(ji,jj) )
-                        fraqsr_1lev(ji,jj) = 1.0 - ( zzc0 + zzc1 + zzc2  + zzc3  ) * tmask(ji,jj,2) 
-                     END DO
-                  END DO
-               ENDIF
-               !
-               DO jk = 1, nksr                                        ! compute and add qsr trend to ta
-                  qsr_hc(:,:,jk) = r1_rau0_rcp * ( zea(:,:,jk) - zea(:,:,jk+1) )
-               END DO
-               zea(:,:,nksr+1:jpk) = 0.e0     ! below 400m set to zero
-               CALL iom_put( 'qsr3d', zea )   ! Shortwave Radiation 3D distribution
-               !
-            ELSE                                                 !*  Constant Chlorophyll
-               DO jk = 1, nksr
-                  qsr_hc(:,:,jk) =  etot3(:,:,jk) * qsr(:,:)
-               END DO
-               ! clem: store attenuation coefficient of the first ocean level
-               IF ( ln_qsr_ice ) THEN
-                  fraqsr_1lev(:,:) = etot3(:,:,1) / r1_rau0_rcp
-               ENDIF
-           ENDIF
-
-         ENDIF
-         !                                                ! ------------------------- !
-         IF( ln_qsr_2bd ) THEN                            !  2 band light penetration !
-            !                                             ! ------------------------- !
-            !
-            IF( lk_vvl ) THEN                                  !* variable volume
-               zz0   =        rn_abs   * r1_rau0_rcp
-               zz1   = ( 1. - rn_abs ) * r1_rau0_rcp
-               DO jk = 1, nksr                    ! solar heat absorbed at T-point in the top 400m 
-                  DO jj = 1, jpj
-                     DO ji = 1, jpi
-                        zc0 = zz0 * EXP( -fsdepw(ji,jj,jk  )*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,jk  )*xsi1r )
-                        zc1 = zz0 * EXP( -fsdepw(ji,jj,jk+1)*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,jk+1)*xsi1r )
-                        qsr_hc(ji,jj,jk) = qsr(ji,jj) * ( zc0*tmask(ji,jj,jk) - zc1*tmask(ji,jj,jk+1) ) 
-                     END DO
-                  END DO
-               END DO
-               ! clem: store attenuation coefficient of the first ocean level
-               IF ( ln_qsr_ice ) THEN
-                  DO jj = 1, jpj
-                     DO ji = 1, jpi
-                        zc0 = zz0 * EXP( -fsdepw(ji,jj,1)*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,1)*xsi1r )
-                        zc1 = zz0 * EXP( -fsdepw(ji,jj,2)*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,2)*xsi1r )
-                        fraqsr_1lev(ji,jj) = ( zc0*tmask(ji,jj,1) - zc1*tmask(ji,jj,2) ) / r1_rau0_rcp
-                     END DO
-                  END DO
-               ENDIF
-            ELSE                                               !* constant volume: coef. computed one for all
-               DO jk = 1, nksr
-                  DO jj = 2, jpjm1
-                     DO ji = fs_2, fs_jpim1   ! vector opt.
-                        ! (ISF) no light penetration below the ice shelves         
-                        qsr_hc(ji,jj,jk) =  etot3(ji,jj,jk) * qsr(ji,jj) * tmask(ji,jj,1)
-                     END DO
-                  END DO
-               END DO
-               ! clem: store attenuation coefficient of the first ocean level
-               IF ( ln_qsr_ice ) THEN
-                  fraqsr_1lev(:,:) = etot3(:,:,1) / r1_rau0_rcp
-               ENDIF
-               !
-            ENDIF
-            !
-         ENDIF
-         !
-         !                                        Add to the general trend
-         DO jk = 1, nksr
-            DO jj = 2, jpjm1 
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z1_e3t = zfact / fse3t(ji,jj,jk)
-                  tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem) + ( qsr_hc_b(ji,jj,jk) + qsr_hc(ji,jj,jk) ) * z1_e3t
-               END DO
-            END DO
-         END DO
-         !
-      ENDIF
-      !
-      IF( lrst_oce ) THEN   !                  Write in the ocean restart file
-         !                                     *******************************
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'qsr tracer content forcing field written in ocean restart file ',   &
-            &                    'at it= ', kt,' date= ', ndastp
-         IF(lwp) WRITE(numout,*) '~~~~'
+            END DO
+         END DO
+         ! Update haloes since lim_thd needs fraqsr_1lev to be defined everywhere
+         CALL lbc_lnk( fraqsr_1lev(:,:), 'T', 1._wp )
+      ENDIF
+      !
+      IF( iom_use('qsr3d') ) THEN      ! output the shortwave Radiation distribution
+         CALL wrk_alloc( jpi,jpj,jpk,   zetot )
+         !
+         zetot(:,:,nksr+1:jpk) = 0._wp     ! below ~400m set to zero
+         DO jk = nksr, 1, -1
+            zetot(:,:,jk) = zetot(:,:,jk+1) + qsr_hc(:,:,jk) / r1_rau0_rcp
+         END DO         
+         CALL iom_put( 'qsr3d', zetot )   ! 3D distribution of shortwave Radiation
+         !
+         CALL wrk_dealloc( jpi,jpj,jpk,   zetot ) 
+      ENDIF
+      !
+      IF( lrst_oce ) THEN     ! write in the ocean restart file
          CALL iom_rstput( kt, nitrst, numrow, 'qsr_hc_b'   , qsr_hc      )
-         CALL iom_rstput( kt, nitrst, numrow, 'fraqsr_1lev', fraqsr_1lev )   ! default definition in sbcssm 
-         !
-      ENDIF
-
+         CALL iom_rstput( kt, nitrst, numrow, 'fraqsr_1lev', fraqsr_1lev ) 
+      ENDIF
+      !
       IF( l_trdtra ) THEN     ! qsr tracers trends saved for diagnostics
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_qsr, ztrdt )
-         CALL wrk_dealloc( jpi, jpj, jpk, ztrdt ) 
+         CALL wrk_dealloc( jpi,jpj,jpk,   ztrdt ) 
       ENDIF
       !                       ! print mean trends (used for debugging)
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' qsr  - Ta: ', mask1=tmask, clinfo3='tra-ta' )
-      !
-      CALL wrk_dealloc( jpi, jpj,      zekb, zekg, zekr        ) 
-      CALL wrk_dealloc( jpi, jpj, jpk, ze0, ze1, ze2, ze3, zea ) 
       !
       IF( nn_timing == 1 )  CALL timing_stop('tra_qsr')
@@ -358,34 +307,25 @@
       !! Reference : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
       !!----------------------------------------------------------------------
-      !
-      INTEGER  ::   ji, jj, jk                   ! dummy loop indices
-      INTEGER  ::   irgb, ierror, ioptio, nqsr   ! local integer
-      INTEGER  ::   ios                          ! Local integer output status for namelist read
-      REAL(wp) ::   zz0, zc0  , zc1, zcoef       ! local scalars
-      REAL(wp) ::   zz1, zc2  , zc3, zchl        !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: zekb, zekg, zekr
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: ze0, ze1, ze2, ze3, zea
+      INTEGER  ::   ji, jj, jk                  ! dummy loop indices
+      INTEGER  ::   ios, irgb, ierror, ioptio   ! local integer
+      REAL(wp) ::   zz0, zc0 , zc1, zcoef      ! local scalars
+      REAL(wp) ::   zz1, zc2 , zc3, zchl       !   -      -
       !
       CHARACTER(len=100) ::   cn_dir   ! Root directory for location of ssr files
       TYPE(FLD_N)        ::   sn_chl   ! informations about the chlorofyl field to be read
       !!
-      NAMELIST/namtra_qsr/  sn_chl, cn_dir, ln_traqsr, ln_qsr_rgb, ln_qsr_2bd, ln_qsr_bio, ln_qsr_ice,  &
+      NAMELIST/namtra_qsr/  sn_chl, cn_dir, ln_qsr_rgb, ln_qsr_2bd, ln_qsr_bio, ln_qsr_ice,  &
          &                  nn_chldta, rn_abs, rn_si0, rn_si1
       !!----------------------------------------------------------------------
-
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_qsr_init')
-      !
-      CALL wrk_alloc( jpi, jpj,      zekb, zekg, zekr        ) 
-      CALL wrk_alloc( jpi, jpj, jpk, ze0, ze1, ze2, ze3, zea ) 
-      !
-
-      REWIND( numnam_ref )              ! Namelist namtra_qsr in reference namelist : Ratio and length of penetration
+      !
+      IF( nn_timing == 1 )   CALL timing_start('tra_qsr_init')
+      !
+      REWIND( numnam_ref )              ! Namelist namtra_qsr in reference     namelist
       READ  ( numnam_ref, namtra_qsr, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtra_qsr in reference namelist', lwp )
-
-      REWIND( numnam_cfg )              !  Namelist namtra_qsr in configuration namelist : Ratio and length of penetration
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_qsr in reference namelist', lwp )
+      !
+      REWIND( numnam_cfg )              ! Namelist namtra_qsr in configuration namelist
       READ  ( numnam_cfg, namtra_qsr, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtra_qsr in configuration namelist', lwp )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_qsr in configuration namelist', lwp )
       IF(lwm) WRITE ( numond, namtra_qsr )
       !
@@ -395,173 +335,84 @@
          WRITE(numout,*) '~~~~~~~~~~~~'
          WRITE(numout,*) '   Namelist namtra_qsr : set the parameter of penetration'
-         WRITE(numout,*) '      Light penetration (T) or not (F)         ln_traqsr  = ', ln_traqsr
-         WRITE(numout,*) '      RGB (Red-Green-Blue) light penetration   ln_qsr_rgb = ', ln_qsr_rgb
-         WRITE(numout,*) '      2 band               light penetration   ln_qsr_2bd = ', ln_qsr_2bd
-         WRITE(numout,*) '      bio-model            light penetration   ln_qsr_bio = ', ln_qsr_bio
-         WRITE(numout,*) '      light penetration for ice-model LIM3     ln_qsr_ice = ', ln_qsr_ice
-         WRITE(numout,*) '      RGB : Chl data (=1) or cst value (=0)    nn_chldta  = ', nn_chldta
-         WRITE(numout,*) '      RGB & 2 bands: fraction of light (rn_si1)    rn_abs = ', rn_abs
-         WRITE(numout,*) '      RGB & 2 bands: shortess depth of extinction  rn_si0 = ', rn_si0
-         WRITE(numout,*) '      2 bands: longest depth of extinction         rn_si1 = ', rn_si1
-      ENDIF
-
-      IF( ln_traqsr ) THEN     ! control consistency
-         !                      
-         IF( .NOT.lk_qsr_bio .AND. ln_qsr_bio )   THEN
-            CALL ctl_warn( 'No bio model : force ln_qsr_bio = FALSE ' )
-            ln_qsr_bio = .FALSE.
+         WRITE(numout,*) '      RGB (Red-Green-Blue) light penetration       ln_qsr_rgb = ', ln_qsr_rgb
+         WRITE(numout,*) '      2 band               light penetration       ln_qsr_2bd = ', ln_qsr_2bd
+         WRITE(numout,*) '      bio-model            light penetration       ln_qsr_bio = ', ln_qsr_bio
+         WRITE(numout,*) '      light penetration for ice-model (LIM3)       ln_qsr_ice = ', ln_qsr_ice
+         WRITE(numout,*) '      RGB : Chl data (=1) or cst value (=0)        nn_chldta  = ', nn_chldta
+         WRITE(numout,*) '      RGB & 2 bands: fraction of light (rn_si1)    rn_abs     = ', rn_abs
+         WRITE(numout,*) '      RGB & 2 bands: shortess depth of extinction  rn_si0     = ', rn_si0
+         WRITE(numout,*) '      2 bands: longest depth of extinction         rn_si1     = ', rn_si1
+         WRITE(numout,*)
+      ENDIF
+      !
+      ioptio = 0                    ! Parameter control
+      IF( ln_qsr_rgb  )   ioptio = ioptio + 1
+      IF( ln_qsr_2bd  )   ioptio = ioptio + 1
+      IF( ln_qsr_bio  )   ioptio = ioptio + 1
+      !
+      IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE type of light penetration in namelist namtra_qsr',  &
+         &                               ' 2 bands, 3 RGB bands or bio-model light penetration' )
+      !
+      IF( ln_qsr_rgb .AND. nn_chldta == 0 )   nqsr = np_RGB 
+      IF( ln_qsr_rgb .AND. nn_chldta == 1 )   nqsr = np_RGBc
+      IF( ln_qsr_2bd                      )   nqsr = np_2BD
+      IF( ln_qsr_bio                      )   nqsr = np_BIO
+      !
+      !                             ! Initialisation
+      xsi0r = 1._wp / rn_si0
+      xsi1r = 1._wp / rn_si1
+      !
+      SELECT CASE( nqsr )
+      !                               
+      CASE( np_RGB , np_RGBc )         !==  Red-Green-Blue light penetration  ==!
+         !                             
+         IF(lwp)   WRITE(numout,*) '   R-G-B   light penetration '
+         !
+         CALL trc_oce_rgb( rkrgb )                 ! tabulated attenuation coef.
+         !                                   
+         nksr = trc_oce_ext_lev( r_si2, 33._wp )   ! level of light extinction
+         !
+         IF(lwp) WRITE(numout,*) '        level of light extinction = ', nksr, ' ref depth = ', gdepw_1d(nksr+1), ' m'
+         !
+         IF( nqsr == np_RGBc ) THEN                ! Chl data : set sf_chl structure
+            IF(lwp) WRITE(numout,*) '        Chlorophyll read in a file'
+            ALLOCATE( sf_chl(1), STAT=ierror )
+            IF( ierror > 0 ) THEN
+               CALL ctl_stop( 'tra_qsr_init: unable to allocate sf_chl structure' )   ;   RETURN
+            ENDIF
+            ALLOCATE( sf_chl(1)%fnow(jpi,jpj,1)   )
+            IF( sn_chl%ln_tint )   ALLOCATE( sf_chl(1)%fdta(jpi,jpj,1,2) )
+            !                                        ! fill sf_chl with sn_chl and control print
+            CALL fld_fill( sf_chl, (/ sn_chl /), cn_dir, 'tra_qsr_init',   &
+               &           'Solar penetration function of read chlorophyll', 'namtra_qsr' )
          ENDIF
-         !
-         ioptio = 0                      ! Parameter control
-         IF( ln_qsr_rgb  )   ioptio = ioptio + 1
-         IF( ln_qsr_2bd  )   ioptio = ioptio + 1
-         IF( ln_qsr_bio  )   ioptio = ioptio + 1
-         !
-         IF( ioptio /= 1 ) &
-            CALL ctl_stop( '          Choose ONE type of light penetration in namelist namtra_qsr',  &
-            &              ' 2 bands, 3 RGB bands or bio-model light penetration' )
-         !
-         IF( ln_qsr_rgb .AND. nn_chldta == 0 )   nqsr =  1 
-         IF( ln_qsr_rgb .AND. nn_chldta == 1 )   nqsr =  2
-         IF( ln_qsr_2bd                      )   nqsr =  3
-         IF( ln_qsr_bio                      )   nqsr =  4
-         !
-         IF(lwp) THEN                   ! Print the choice
-            WRITE(numout,*)
-            IF( nqsr ==  1 )   WRITE(numout,*) '         R-G-B   light penetration - Constant Chlorophyll'
-            IF( nqsr ==  2 )   WRITE(numout,*) '         R-G-B   light penetration - Chl data '
-            IF( nqsr ==  3 )   WRITE(numout,*) '         2 bands light penetration'
-            IF( nqsr ==  4 )   WRITE(numout,*) '         bio-model light penetration'
+         IF( nqsr == np_RGB ) THEN                 ! constant Chl
+            IF(lwp) WRITE(numout,*) '        Constant Chlorophyll concentration = 0.05'
          ENDIF
          !
-      ENDIF
-      !                          ! ===================================== !
-      IF( ln_traqsr  ) THEN      !  Initialisation of Light Penetration  !  
-         !                       ! ===================================== !
-         !
-         xsi0r = 1.e0 / rn_si0
-         xsi1r = 1.e0 / rn_si1
-         !                                ! ---------------------------------- !
-         IF( ln_qsr_rgb ) THEN            !  Red-Green-Blue light penetration  !
-            !                             ! ---------------------------------- !
-            !
-            CALL trc_oce_rgb( rkrgb )           !* tabulated attenuation coef.
-            !
-            !                                   !* level of light extinction
-            IF(  ln_sco ) THEN   ;   nksr = jpkm1
-            ELSE                 ;   nksr = trc_oce_ext_lev( r_si2, 0.33e2 )
-            ENDIF
-
-            IF(lwp) WRITE(numout,*) '        level of light extinction = ', nksr, ' ref depth = ', gdepw_1d(nksr+1), ' m'
-            !
-            IF( nn_chldta == 1 ) THEN           !* Chl data : set sf_chl structure
-               IF(lwp) WRITE(numout,*)
-               IF(lwp) WRITE(numout,*) '        Chlorophyll read in a file'
-               ALLOCATE( sf_chl(1), STAT=ierror )
-               IF( ierror > 0 ) THEN
-                  CALL ctl_stop( 'tra_qsr_init: unable to allocate sf_chl structure' )   ;   RETURN
-               ENDIF
-               ALLOCATE( sf_chl(1)%fnow(jpi,jpj,1)   )
-               IF( sn_chl%ln_tint )ALLOCATE( sf_chl(1)%fdta(jpi,jpj,1,2) )
-               !                                        ! fill sf_chl with sn_chl and control print
-               CALL fld_fill( sf_chl, (/ sn_chl /), cn_dir, 'tra_qsr_init',   &
-                  &                                         'Solar penetration function of read chlorophyll', 'namtra_qsr' )
-               !
-            ELSE                                !* constant Chl : compute once for all the distribution of light (etot3)
-               IF(lwp) WRITE(numout,*)
-               IF(lwp) WRITE(numout,*) '        Constant Chlorophyll concentration = 0.05'
-               IF( lk_vvl ) THEN                   ! variable volume
-                  IF(lwp) WRITE(numout,*) '        key_vvl: light distribution will be computed at each time step'
-               ELSE                                ! constant volume: computes one for all
-                  IF(lwp) WRITE(numout,*) '        fixed volume: light distribution computed one for all'
-                  !
-                  zchl = 0.05                                 ! constant chlorophyll
-                  irgb = NINT( 41 + 20.*LOG10(zchl) + 1.e-15 )
-                  zekb(:,:) = rkrgb(1,irgb)                   ! Separation in R-G-B depending of the chlorophyll 
-                  zekg(:,:) = rkrgb(2,irgb)
-                  zekr(:,:) = rkrgb(3,irgb)
-                  !
-                  zcoef = ( 1. - rn_abs ) / 3.e0              ! equi-partition in R-G-B
-                  ze0(:,:,1) = rn_abs
-                  ze1(:,:,1) = zcoef
-                  ze2(:,:,1) = zcoef 
-                  ze3(:,:,1) = zcoef
-                  zea(:,:,1) = tmask(:,:,1)                   ! = ( ze0+ze1+z2+ze3 ) * tmask
-               
-                  DO jk = 2, nksr+1
-                     DO jj = 1, jpj
-                        DO ji = 1, jpi
-                           zc0 = ze0(ji,jj,jk-1) * EXP( - e3t_0(ji,jj,jk-1) * xsi0r     )
-                           zc1 = ze1(ji,jj,jk-1) * EXP( - e3t_0(ji,jj,jk-1) * zekb(ji,jj) )
-                           zc2 = ze2(ji,jj,jk-1) * EXP( - e3t_0(ji,jj,jk-1) * zekg(ji,jj) )
-                           zc3 = ze3(ji,jj,jk-1) * EXP( - e3t_0(ji,jj,jk-1) * zekr(ji,jj) )
-                           ze0(ji,jj,jk) = zc0
-                           ze1(ji,jj,jk) = zc1
-                           ze2(ji,jj,jk) = zc2
-                           ze3(ji,jj,jk) = zc3
-                           zea(ji,jj,jk) = ( zc0 + zc1 + zc2 + zc3 ) * tmask(ji,jj,jk)
-                        END DO
-                     END DO
-                  END DO 
-                  !
-                  DO jk = 1, nksr
-                     ! (ISF) no light penetration below the ice shelves
-                     etot3(:,:,jk) = r1_rau0_rcp * ( zea(:,:,jk) - zea(:,:,jk+1) ) * tmask(:,:,1)
-                  END DO
-                  etot3(:,:,nksr+1:jpk) = 0.e0                ! below 400m set to zero
-               ENDIF
-            ENDIF
-            !
-         ENDIF
-            !                             ! ---------------------------------- !
-         IF( ln_qsr_2bd ) THEN            !    2 bands    light penetration    !
-            !                             ! ---------------------------------- !
-            !
-            !                                ! level of light extinction
-            nksr = trc_oce_ext_lev( rn_si1, 1.e2 )
-            IF(lwp) THEN
-               WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) '        level of light extinction = ', nksr, ' ref depth = ', gdepw_1d(nksr+1), ' m'
-            ENDIF
-            !
-            IF( lk_vvl ) THEN                   ! variable volume
-               IF(lwp) WRITE(numout,*) '        key_vvl: light distribution will be computed at each time step'
-            ELSE                                ! constant volume: computes one for all
-               zz0 =        rn_abs   * r1_rau0_rcp
-               zz1 = ( 1. - rn_abs ) * r1_rau0_rcp
-               DO jk = 1, nksr                    !*  solar heat absorbed at T-point computed once for all
-                  DO jj = 1, jpj                              ! top 400 meters
-                     DO ji = 1, jpi
-                        zc0 = zz0 * EXP( -fsdepw(ji,jj,jk  )*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,jk  )*xsi1r )
-                        zc1 = zz0 * EXP( -fsdepw(ji,jj,jk+1)*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,jk+1)*xsi1r )
-                        etot3(ji,jj,jk) = (  zc0 * tmask(ji,jj,jk) - zc1 * tmask(ji,jj,jk+1)  ) * tmask(ji,jj,1) 
-                     END DO
-                  END DO
-               END DO
-               etot3(:,:,nksr+1:jpk) = 0.e0                   ! below 400m set to zero
-               !
-            ENDIF
-         ENDIF
-         !                       ! ===================================== !
-      ELSE                       !        No light penetration           !                   
-         !                       ! ===================================== !
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) 'tra_qsr_init : NO solar flux penetration'
-            WRITE(numout,*) '~~~~~~~~~~~~'
-         ENDIF
-      ENDIF
-      !
-      ! initialisation of fraqsr_1lev used in sbcssm
+      CASE( np_2BD )                   !==  2 bands light penetration  ==!
+         !
+         IF(lwp)  WRITE(numout,*) '   2 bands light penetration'
+         !
+         nksr = trc_oce_ext_lev( rn_si1, 100._wp )    ! level of light extinction
+         IF(lwp) WRITE(numout,*) '        level of light extinction = ', nksr, ' ref depth = ', gdepw_1d(nksr+1), ' m'
+         !
+      CASE( np_BIO )                   !==  BIO light penetration  ==!
+         !
+         IF(lwp) WRITE(numout,*) '   bio-model light penetration'
+         IF( .NOT.lk_qsr_bio )   CALL ctl_stop( 'No bio model : ln_qsr_bio = true impossible ' )
+         !
+      END SELECT
+      !
+      qsr_hc(:,:,:) = 0._wp     ! now qsr heat content set to zero where it will not be computed
+      !
+      ! 1st ocean level attenuation coefficient (used in sbcssm)
       IF( iom_varid( numror, 'fraqsr_1lev', ldstop = .FALSE. ) > 0 ) THEN
          CALL iom_get( numror, jpdom_autoglo, 'fraqsr_1lev'  , fraqsr_1lev  )
       ELSE
-         fraqsr_1lev(:,:) = 1._wp   ! default definition
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj,      zekb, zekg, zekr        ) 
-      CALL wrk_dealloc( jpi, jpj, jpk, ze0, ze1, ze2, ze3, zea ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_qsr_init')
+         fraqsr_1lev(:,:) = 1._wp   ! default : no penetration
+      ENDIF
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('tra_qsr_init')
       !
    END SUBROUTINE tra_qsr_init
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 6140)
@@ -13,32 +13,32 @@
 
    !!----------------------------------------------------------------------
-   !!   tra_sbc      : update the tracer trend at ocean surface
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and active tracers
-   USE sbc_oce         ! surface boundary condition: ocean
-   USE dom_oce         ! ocean space domain variables
-   USE phycst          ! physical constant
-   USE sbcmod          ! ln_rnf  
-   USE sbcrnf          ! River runoff  
-   USE sbcisf          ! Ice shelf   
-   USE traqsr          ! solar radiation penetration
-   USE trd_oce         ! trends: ocean variables
-   USE trdtra          ! trends manager: tracers 
+   !!   tra_sbc       : update the tracer trend at ocean surface
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and active tracers
+   USE sbc_oce        ! surface boundary condition: ocean
+   USE dom_oce        ! ocean space domain variables
+   USE phycst         ! physical constant
+   USE eosbn2         ! Equation Of State
+   USE sbcmod         ! ln_rnf  
+   USE sbcrnf         ! River runoff  
+   USE sbcisf         ! Ice shelf   
+   USE iscplini       ! Ice sheet coupling
+   USE traqsr         ! solar radiation penetration
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! trends manager: tracers 
    !
-   USE in_out_manager  ! I/O manager
-   USE prtctl          ! Print control
-   USE iom
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
-   USE eosbn2
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
+   USE iom            ! xIOS server
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   tra_sbc    ! routine called by step.F90
+   PUBLIC   tra_sbc   ! routine called by step.F90
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -57,67 +57,22 @@
       !!      and add it to the general trend of tracer equations.
       !!
-      !! ** Method :
-      !!      Following Roullet and Madec (2000), the air-sea flux can be divided 
-      !!      into three effects: (1) Fext, external forcing; 
-      !!      (2) Fwi, concentration/dilution effect due to water exchanged 
-      !!         at the surface by evaporation, precipitations and runoff (E-P-R); 
-      !!      (3) Fwe, tracer carried with the water that is exchanged. 
-      !!            - salinity    : salt flux only due to freezing/melting
-      !!            sa = sa +  sfx / rau0 / e3t  for k=1
+      !! ** Method :   The (air+ice)-sea flux has two components: 
+      !!      (1) Fext, external forcing (i.e. flux through the (air+ice)-sea interface); 
+      !!      (2) Fwe , tracer carried with the water that is exchanged with air+ice. 
+      !!               The input forcing fields (emp, rnf, sfx, isf) contain Fext+Fwe,
+      !!             they are simply added to the tracer trend (tsa).
+      !!               In linear free surface case (ln_linssh=T), the volume of the
+      !!             ocean does not change with the water exchanges at the (air+ice)-sea
+      !!             interface. Therefore another term has to be added, to mimic the
+      !!             concentration/dilution effect associated with water exchanges.
       !!
-      !!      Fext, flux through the air-sea interface for temperature and salt: 
-      !!            - temperature : heat flux q (w/m2). If penetrative solar
-      !!         radiation q is only the non solar part of the heat flux, the
-      !!         solar part is added in traqsr.F routine.
-      !!            ta = ta + q /(rau0 rcp e3t)  for k=1
-      !!            - salinity    : no salt flux
-      !!
-      !!      The formulation for Fwb and Fwi vary according to the free 
-      !!      surface formulation (linear or variable volume). 
-      !!      * Linear free surface
-      !!            The surface freshwater flux modifies the ocean volume
-      !!         and thus the concentration of a tracer and the temperature.
-      !!         First order of the effect of surface freshwater exchange 
-      !!         for salinity, it can be neglected on temperature (especially
-      !!         as the temperature of precipitations and runoffs is usually
-      !!         unknown).
-      !!            - temperature : we assume that the temperature of both
-      !!         precipitations and runoffs is equal to the SST, thus there
-      !!         is no additional flux since in this case, the concentration
-      !!         dilution effect is balanced by the net heat flux associated
-      !!         to the freshwater exchange (Fwe+Fwi=0):
-      !!            (Tp P - Te E) + SST (P-E) = 0 when Tp=Te=SST
-      !!            - salinity    : evaporation, precipitation and runoff
-      !!         water has a zero salinity  but there is a salt flux due to 
-      !!         freezing/melting, thus:
-      !!            sa = sa + emp * sn / rau0 / e3t   for k=1
-      !!                    + sfx    / rau0 / e3t
-      !!         where emp, the surface freshwater budget (evaporation minus
-      !!         precipitation minus runoff) given in kg/m2/s is divided
-      !!         by rau0 (density of sea water) to obtain m/s.    
-      !!         Note: even though Fwe does not appear explicitly for 
-      !!         temperature in this routine, the heat carried by the water
-      !!         exchanged through the surface is part of the total heat flux
-      !!         forcing and must be taken into account in the global heat
-      !!         balance).
-      !!      * nonlinear free surface (variable volume, lk_vvl)
-      !!         contrary to the linear free surface case, Fwi is properly 
-      !!         taken into account by using the true layer thicknesses to       
-      !!         calculate tracer content and advection. There is no need to 
-      !!         deal with it in this routine.
-      !!           - temperature: Fwe=SST (P-E+R) is added to Fext.
-      !!           - salinity:  Fwe = 0, there is no surface flux of salt.
-      !!
-      !! ** Action  : - Update the 1st level of (ta,sa) with the trend associated
-      !!                with the tracer surface boundary condition 
-      !!              - send trends to trdtra module (l_trdtra=T)
+      !! ** Action  : - Update tsa with the surface boundary condition trend 
+      !!              - send trends to trdtra module for further diagnostics(l_trdtra=T)
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      !!
-      INTEGER  ::   ji, jj, jk, jn           ! dummy loop indices  
-      INTEGER  ::   ikt, ikb 
-      INTEGER  ::   nk_isf
-      REAL(wp) ::   zfact, z1_e3t, zdep
-      REAL(wp) ::   zalpha, zhk
+      !
+      INTEGER  ::   ji, jj, jk, jn        ! dummy loop indices  
+      INTEGER  ::   ikt, ikb              ! local integers
+      REAL(wp) ::   zfact, z1_e3t, zdep   ! local scalar
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdt, ztrds
       !!----------------------------------------------------------------------
@@ -130,5 +85,5 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~ '
       ENDIF
-
+      !
       IF( l_trdtra ) THEN                    !* Save ta and sa trends
          CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds ) 
@@ -136,9 +91,9 @@
          ztrds(:,:,:) = tsa(:,:,:,jp_sal)
       ENDIF
-
-!!gm      IF( .NOT.ln_traqsr )   qsr(:,:) = 0.e0   ! no solar radiation penetration
+      !
+!!gm  This should be moved into sbcmod.F90 module ? (especially now that ln_traqsr is read in namsbc namelist)
       IF( .NOT.ln_traqsr ) THEN     ! no solar radiation penetration
          qns(:,:) = qns(:,:) + qsr(:,:)      ! total heat flux in qns
-         qsr(:,:) = 0.e0                     ! qsr set to zero
+         qsr(:,:) = 0._wp                     ! qsr set to zero
       ENDIF
 
@@ -146,71 +101,51 @@
       !        EMP, SFX and QNS effects
       !----------------------------------------
-      !                                          Set before sbc tracer content fields
-      !                                          ************************************
-      IF( kt == nit000 ) THEN                      ! Set the forcing field at nit000 - 1
-         !                                         ! -----------------------------------
-         IF( ln_rstart .AND.    &                     ! Restart: read in restart file
+      !                             !==  Set before sbc tracer content fields  ==!
+      IF( kt == nit000 ) THEN             !* 1st time-step
+         IF( ln_rstart .AND.    &               ! Restart: read in restart file
               & iom_varid( numror, 'sbc_hc_b', ldstop = .FALSE. ) > 0 ) THEN
-            IF(lwp) WRITE(numout,*) '          nit000-1 surface tracer content forcing fields red in the restart file'
+            IF(lwp) WRITE(numout,*) '          nit000-1 sbc tracer content field read in the restart file'
             zfact = 0.5_wp
             CALL iom_get( numror, jpdom_autoglo, 'sbc_hc_b', sbc_tsc_b(:,:,jp_tem) )   ! before heat content sbc trend
             CALL iom_get( numror, jpdom_autoglo, 'sbc_sc_b', sbc_tsc_b(:,:,jp_sal) )   ! before salt content sbc trend
-         ELSE                                         ! No restart or restart not found: Euler forward time stepping
+         ELSE                                   ! No restart or restart not found: Euler forward time stepping
             zfact = 1._wp
             sbc_tsc_b(:,:,:) = 0._wp
          ENDIF
-      ELSE                                         ! Swap of forcing fields
-         !                                         ! ----------------------
+      ELSE                                !* other time-steps: swap of forcing fields
          zfact = 0.5_wp
          sbc_tsc_b(:,:,:) = sbc_tsc(:,:,:)
       ENDIF
-      !                                          Compute now sbc tracer content fields
-      !                                          *************************************
-
-                                                   ! Concentration dilution effect on (t,s) due to  
-                                                   ! evaporation, precipitation and qns, but not river runoff 
-                                               
-      IF( lk_vvl ) THEN                            ! Variable Volume case  ==>> heat content of mass flux is in qns
-         DO jj = 1, jpj
-            DO ji = 1, jpi 
-               sbc_tsc(ji,jj,jp_tem) = r1_rau0_rcp * qns(ji,jj)                              ! non solar heat flux
-               sbc_tsc(ji,jj,jp_sal) = r1_rau0     * sfx(ji,jj)                              ! salt flux due to freezing/melting
+      !                             !==  Now sbc tracer content fields  ==!
+      DO jj = 2, jpj
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            sbc_tsc(ji,jj,jp_tem) = r1_rau0_rcp * qns(ji,jj)   ! non solar heat flux
+            sbc_tsc(ji,jj,jp_sal) = r1_rau0     * sfx(ji,jj)   ! salt flux due to freezing/melting
+         END DO
+      END DO
+      IF( ln_linssh ) THEN                !* linear free surface  
+         DO jj = 2, jpj                         !==>> add concentration/dilution effect due to constant volume cell
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               sbc_tsc(ji,jj,jp_tem) = sbc_tsc(ji,jj,jp_tem) + r1_rau0 * emp(ji,jj) * tsn(ji,jj,1,jp_tem)
+               sbc_tsc(ji,jj,jp_sal) = sbc_tsc(ji,jj,jp_sal) + r1_rau0 * emp(ji,jj) * tsn(ji,jj,1,jp_sal)
             END DO
-         END DO
-      ELSE                                         ! Constant Volume case ==>> Concentration dilution effect
+         END DO                                 !==>> output c./d. term
+         IF( iom_use('emp_x_sst') )   CALL iom_put( "emp_x_sst", emp (:,:) * tsn(:,:,1,jp_tem) )
+         IF( iom_use('emp_x_sss') )   CALL iom_put( "emp_x_sss", emp (:,:) * tsn(:,:,1,jp_sal) )
+      ENDIF
+      !
+      DO jn = 1, jpts               !==  update tracer trend  ==!
          DO jj = 2, jpj
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ! temperature : heat flux
-               sbc_tsc(ji,jj,jp_tem) = r1_rau0_rcp * qns(ji,jj)                          &   ! non solar heat flux
-                  &                  + r1_rau0     * emp(ji,jj)  * tsn(ji,jj,1,jp_tem)       ! concent./dilut. effect
-               ! salinity    : salt flux + concent./dilut. effect (both in sfx)
-               sbc_tsc(ji,jj,jp_sal) = r1_rau0  * (  sfx(ji,jj)                          &   ! salt flux (freezing/melting)
-                  &                                + emp(ji,jj) * tsn(ji,jj,1,jp_sal) )      ! concent./dilut. effect
+            DO ji = fs_2, fs_jpim1   ! vector opt.  
+               tsa(ji,jj,1,jn) = tsa(ji,jj,1,jn) + zfact * ( sbc_tsc_b(ji,jj,jn) + sbc_tsc(ji,jj,jn) ) / e3t_n(ji,jj,1)
             END DO
          END DO
-         IF( iom_use('emp_x_sst') )   CALL iom_put( "emp_x_sst", emp (:,:) * tsn(:,:,1,jp_tem) )   ! c/d term on sst
-         IF( iom_use('emp_x_sss') )   CALL iom_put( "emp_x_sss", emp (:,:) * tsn(:,:,1,jp_sal) )   ! c/d term on sss
-      ENDIF
-      ! Concentration dilution effect on (t,s) due to evapouration, precipitation and qns, but not river runoff  
-      DO jn = 1, jpts
-         DO jj = 2, jpj
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               z1_e3t = zfact / fse3t(ji,jj,1)
-               tsa(ji,jj,1,jn) = tsa(ji,jj,1,jn) + ( sbc_tsc_b(ji,jj,jn) + sbc_tsc(ji,jj,jn) ) * z1_e3t
-            END DO
-         END DO
       END DO
-      !                                          Write in the ocean restart file
-      !                                          *******************************
-      IF( lrst_oce ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'sbc : ocean surface tracer content forcing fields written in ocean restart file ',   &
-            &                    'at it= ', kt,' date= ', ndastp
-         IF(lwp) WRITE(numout,*) '~~~~'
+      !                  
+      IF( lrst_oce ) THEN           !==  write sbc_tsc in the ocean restart file  ==!
          CALL iom_rstput( kt, nitrst, numrow, 'sbc_hc_b', sbc_tsc(:,:,jp_tem) )
          CALL iom_rstput( kt, nitrst, numrow, 'sbc_sc_b', sbc_tsc(:,:,jp_sal) )
       ENDIF
       !
-      !
       !----------------------------------------
       !       Ice Shelf effects (ISF)
@@ -218,39 +153,33 @@
       !----------------------------------------
       !
-      IF( nn_isf > 0 ) THEN
-         zfact = 0.5e0
+!!gm BUG ?   Why no differences between non-linear and linear free surface ?
+!!gm         probably taken into account in r1_hisf_tbl : to be verified
+      IF( ln_isf ) THEN
+         zfact = 0.5_wp
          DO jj = 2, jpj
             DO ji = fs_2, fs_jpim1
-         
+               !
                ikt = misfkt(ji,jj)
                ikb = misfkb(ji,jj)
-   
+               !
                ! level fully include in the ice shelf boundary layer
-               ! if isfdiv, we have to remove heat flux due to inflow at 0oC (as in rnf when you add rnf at sst)
                ! sign - because fwf sign of evapo (rnf sign of precip)
                DO jk = ikt, ikb - 1
-               ! compute tfreez for the temperature correction (we add water at freezing temperature)
                ! compute trend
-                  tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem)                                          &
-                     &           + zfact * (risf_tsc_b(ji,jj,jp_tem) + risf_tsc(ji,jj,jp_tem)) * r1_hisf_tbl(ji,jj)
-                  tsa(ji,jj,jk,jp_sal) = tsa(ji,jj,jk,jp_sal)                                          &
-                     &           + zfact * (risf_tsc_b(ji,jj,jp_sal) + risf_tsc(ji,jj,jp_sal)) * r1_hisf_tbl(ji,jj)
+                  tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem)                                                &
+                     &           + zfact * ( risf_tsc_b(ji,jj,jp_tem) + risf_tsc(ji,jj,jp_tem) )             &
+                     &           * r1_hisf_tbl(ji,jj)
                END DO
    
                ! level partially include in ice shelf boundary layer 
-               ! compute tfreez for the temperature correction (we add water at freezing temperature)
                ! compute trend
-               tsa(ji,jj,ikb,jp_tem) = tsa(ji,jj,ikb,jp_tem)                                           &
-                  &              + zfact * (risf_tsc_b(ji,jj,jp_tem) + risf_tsc(ji,jj,jp_tem)) * r1_hisf_tbl(ji,jj) * ralpha(ji,jj)
-               tsa(ji,jj,ikb,jp_sal) = tsa(ji,jj,ikb,jp_sal)                                           &
-                  &              + zfact * (risf_tsc_b(ji,jj,jp_sal) + risf_tsc(ji,jj,jp_sal)) * r1_hisf_tbl(ji,jj) * ralpha(ji,jj) 
+               tsa(ji,jj,ikb,jp_tem) = tsa(ji,jj,ikb,jp_tem)                                                 &
+                  &              + zfact * ( risf_tsc_b(ji,jj,jp_tem) + risf_tsc(ji,jj,jp_tem) )             &
+                  &              * r1_hisf_tbl(ji,jj) * ralpha(ji,jj)
+
             END DO
          END DO
          IF( lrst_oce ) THEN
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'sbc : isf surface tracer content forcing fields written in ocean restart file ',   &
-               &                    'at it= ', kt,' date= ', ndastp
-            IF(lwp) WRITE(numout,*) '~~~~'
-            CALL iom_rstput( kt, nitrst, numrow, 'fwf_isf_b', fwfisf(:,:)          )
+            CALL iom_rstput( kt, nitrst, numrow, 'fwf_isf_b', fwfisf  (:,:)        )
             CALL iom_rstput( kt, nitrst, numrow, 'isf_hc_b' , risf_tsc(:,:,jp_tem) )
             CALL iom_rstput( kt, nitrst, numrow, 'isf_sc_b' , risf_tsc(:,:,jp_sal) )
@@ -269,8 +198,8 @@
                   zdep = zfact / h_rnf(ji,jj)
                   DO jk = 1, nk_rnf(ji,jj)
-                                        tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem)   &
-                                          &               +  ( rnf_tsc_b(ji,jj,jp_tem) + rnf_tsc(ji,jj,jp_tem) ) * zdep
-                     IF( ln_rnf_sal )   tsa(ji,jj,jk,jp_sal) = tsa(ji,jj,jk,jp_sal)   &
-                                          &               +  ( rnf_tsc_b(ji,jj,jp_sal) + rnf_tsc(ji,jj,jp_sal) ) * zdep 
+                                        tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem)                                 &
+                                           &                 +  ( rnf_tsc_b(ji,jj,jp_tem) + rnf_tsc(ji,jj,jp_tem) ) * zdep
+                     IF( ln_rnf_sal )   tsa(ji,jj,jk,jp_sal) = tsa(ji,jj,jk,jp_sal)                                 &
+                                           &                 +  ( rnf_tsc_b(ji,jj,jp_sal) + rnf_tsc(ji,jj,jp_sal) ) * zdep 
                   END DO
                ENDIF
@@ -278,6 +207,24 @@
          END DO  
       ENDIF
- 
-      IF( l_trdtra )   THEN                      ! send trends for further diagnostics
+      !
+      !----------------------------------------
+      !        Ice Sheet coupling imbalance correction to have conservation
+      !----------------------------------------
+      !
+      IF( ln_iscpl .AND. ln_hsb) THEN         ! input of heat and salt due to river runoff 
+         DO jk = 1,jpk
+            DO jj = 2, jpj 
+               DO ji = fs_2, fs_jpim1
+                  zdep = 1._wp / e3t_n(ji,jj,jk) 
+                  tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem) - htsc_iscpl(ji,jj,jk,jp_tem)                       &
+                      &                                         * zdep
+                  tsa(ji,jj,jk,jp_sal) = tsa(ji,jj,jk,jp_sal) - htsc_iscpl(ji,jj,jk,jp_sal)                       &
+                      &                                         * zdep  
+               END DO  
+            END DO  
+         END DO
+      ENDIF
+
+      IF( l_trdtra )   THEN                      ! save the horizontal diffusive trends for further diagnostics
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 6140)
@@ -9,28 +9,26 @@
 
    !!----------------------------------------------------------------------
-   !!   tra_zdf      : Update the tracer trend with the vertical diffusion
-   !!   tra_zdf_init : initialisation of the computation
+   !!   tra_zdf       : Update the tracer trend with the vertical diffusion
+   !!   tra_zdf_init  : initialisation of the computation
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables 
-   USE domvvl          ! variable volume
-   USE phycst          ! physical constant
-   USE zdf_oce         ! ocean vertical physics variables
-   USE sbc_oce         ! surface boundary condition: ocean
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables 
+   USE domvvl         ! variable volume
+   USE phycst         ! physical constant
+   USE zdf_oce        ! ocean vertical physics variables
+   USE sbc_oce        ! surface boundary condition: ocean
+   USE ldftra         ! lateral diffusion: eddy diffusivity
+   USE ldfslp         ! lateral diffusion: iso-neutral slope 
+   USE trazdf_exp     ! vertical diffusion: explicit (tra_zdf_exp routine)
+   USE trazdf_imp     ! vertical diffusion: implicit (tra_zdf_imp routine)
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! trends: tracer trend manager
    !
-   USE ldftra          ! lateral diffusion: eddy diffusivity
-   USE ldfslp          ! lateral diffusion: iso-neutral slope 
-   USE trazdf_exp      ! vertical diffusion: explicit (tra_zdf_exp     routine)
-   USE trazdf_imp      ! vertical diffusion: implicit (tra_zdf_imp     routine)
-   !
-   USE trd_oce         ! trends: ocean variables
-   USE trdtra          ! trends manager: tracers 
-   !
-   USE in_out_manager  ! I/O manager
-   USE prtctl          ! Print control
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory allocation
-   USE timing          ! Timing
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -43,5 +41,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
@@ -60,5 +57,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-      !!
+      !
       INTEGER  ::   jk                   ! Dummy loop indices
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrdt, ztrds   ! 3D workspace
@@ -68,9 +65,9 @@
       !
       IF( neuler == 0 .AND. kt == nit000 ) THEN     ! at nit000
-         r2dtra(:) =  rdttra(:)                          ! = rdtra (restarting with Euler time stepping)
+         r2dt =  rdt                          ! = rdt (restarting with Euler time stepping)
       ELSEIF( kt <= nit000 + 1) THEN                ! at nit000 or nit000+1
-         r2dtra(:) = 2. * rdttra(:)                      ! = 2 rdttra (leapfrog)
+         r2dt = 2. * rdt                      ! = 2 rdt (leapfrog)
       ENDIF
-
+      !
       IF( l_trdtra )   THEN                    !* Save ta and sa trends
          CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds )
@@ -78,8 +75,8 @@
          ztrds(:,:,:) = tsa(:,:,:,jp_sal)
       ENDIF
-
+      !
       SELECT CASE ( nzdf )                       ! compute lateral mixing trend and add it to the general trend
-      CASE ( 0 )    ;    CALL tra_zdf_exp( kt, nit000, 'TRA', r2dtra, nn_zdfexp, tsb, tsa, jpts )  !   explicit scheme 
-      CASE ( 1 )    ;    CALL tra_zdf_imp( kt, nit000, 'TRA', r2dtra,            tsb, tsa, jpts )  !   implicit scheme 
+      CASE ( 0 )    ;    CALL tra_zdf_exp( kt, nit000, 'TRA', r2dt, nn_zdfexp, tsb, tsa, jpts )  !   explicit scheme 
+      CASE ( 1 )    ;    CALL tra_zdf_imp( kt, nit000, 'TRA', r2dt,            tsb, tsa, jpts )  !   implicit scheme 
       END SELECT
 !!gm WHY here !   and I don't like that !
@@ -87,11 +84,11 @@
       ! JMM avoid negative salinities near river outlet ! Ugly fix
       ! JMM : restore negative salinities to small salinities:
-      WHERE ( tsa(:,:,:,jp_sal) < 0._wp )   tsa(:,:,:,jp_sal) = 0.1_wp
+      WHERE( tsa(:,:,:,jp_sal) < 0._wp )   tsa(:,:,:,jp_sal) = 0.1_wp
 !!gm
 
       IF( l_trdtra )   THEN                      ! save the vertical diffusive trends for further diagnostics
          DO jk = 1, jpkm1
-            ztrdt(:,:,jk) = ( ( tsa(:,:,jk,jp_tem) - tsb(:,:,jk,jp_tem) ) / r2dtra(jk) ) - ztrdt(:,:,jk)
-            ztrds(:,:,jk) = ( ( tsa(:,:,jk,jp_sal) - tsb(:,:,jk,jp_sal) ) / r2dtra(jk) ) - ztrds(:,:,jk)
+            ztrdt(:,:,jk) = ( ( tsa(:,:,jk,jp_tem) - tsb(:,:,jk,jp_tem) ) / r2dt ) - ztrdt(:,:,jk)
+            ztrds(:,:,jk) = ( ( tsa(:,:,jk,jp_sal) - tsb(:,:,jk,jp_sal) ) / r2dt ) - ztrds(:,:,jk)
          END DO
 !!gm this should be moved in trdtra.F90 and done on all trends
@@ -103,5 +100,4 @@
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
       ENDIF
-
       !                                          ! print mean trends (used for debugging)
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' zdf  - Ta: ', mask1=tmask,               &
@@ -128,10 +124,10 @@
       USE zdfgls
       !!----------------------------------------------------------------------
-
+      !
       ! Choice from ln_zdfexp already read in namelist in zdfini module
       IF( ln_zdfexp ) THEN   ;   nzdf = 0           ! use explicit scheme
       ELSE                   ;   nzdf = 1           ! use implicit scheme
       ENDIF
-
+      !
       ! Force implicit schemes
       IF( lk_zdftke .OR. lk_zdfgls   )   nzdf = 1   ! TKE, or GLS physics
@@ -140,5 +136,5 @@
       IF( ln_zdfexp .AND. nzdf == 1 )   CALL ctl_stop( 'tra_zdf : If using the rotation of lateral mixing operator',   &
             &                         ' GLS or TKE scheme, the implicit scheme is required, set ln_zdfexp = .false.' )
-
+            !
       IF(lwp) THEN
          WRITE(numout,*)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf_exp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf_exp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf_exp.F90	(revision 6140)
@@ -20,17 +20,18 @@
 
    !!----------------------------------------------------------------------
-   !!   tra_zdf_exp  : compute the tracer the vertical diffusion trend using a
-   !!                  split-explicit time stepping and provide the after tracer
+   !!   tra_zdf_exp   : compute the tracer the vertical diffusion trend using a
+   !!                   split-explicit time stepping and provide the after tracer
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and active tracers 
-   USE dom_oce         ! ocean space and time domain 
-   USE domvvl          ! variable volume levels
-   USE zdf_oce         ! ocean vertical physics
-   USE zdfddm          ! ocean vertical physics: double diffusion
-   USE trc_oce         ! share passive tracers/Ocean variables
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE oce            ! ocean dynamics and active tracers 
+   USE dom_oce        ! ocean space and time domain 
+   USE domvvl         ! variable volume levels
+   USE zdf_oce        ! ocean vertical physics
+   USE zdfddm         ! ocean vertical physics: double diffusion
+   USE trc_oce        ! share passive tracers/Ocean variables
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -40,5 +41,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
@@ -50,6 +50,6 @@
 CONTAINS
 
-   SUBROUTINE tra_zdf_exp( kt, kit000, cdtype, p2dt, kn_zdfexp,   &
-      &                                ptb , pta      , kjpt )
+   SUBROUTINE tra_zdf_exp( kt, kit000, cdtype, p2dt, ksts,   &
+      &                                        ptb , pta , kjpt )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE tra_zdf_exp  ***
@@ -60,5 +60,5 @@
       !! ** Method  : - The after tracer fields due to the vertical diffusion
       !!      of tracers alone is given by:
-      !!                zwx = ptb + p2dt difft
+      !!                ztb = ptb + p2dt difft
       !!      where difft = dz( avt dz(ptb) ) = 1/e3t dk+1( avt/e3w dk(ptb) )
       !!           (if lk_zdfddm=T use avs on salinity and passive tracers instead of avt)
@@ -67,33 +67,28 @@
       !!      (N.B. bottom condition is applied through the masked field avt).
       !!              - the after tracer fields due to the whole trend is 
-      !!      obtained in leap-frog environment by :
-      !!          pta = zwx + p2dt pta
-      !!              - in case of variable level thickness (lk_vvl=T) the 
-      !!     the leap-frog is applied on thickness weighted tracer. That is:
-      !!          pta = [ ptb*e3tb + e3tn*( zwx - ptb + p2dt pta ) ] / e3tn
+      !!      obtained in leap-frog environment applied on thickness weighted tracer by :
+      !!          pta = [ ptb*e3tb + e3tn*( ztb - ptb + p2dt pta ) ] / e3tn
       !!
       !! ** Action : - after tracer fields pta
       !!---------------------------------------------------------------------
+      INTEGER                              , INTENT(in   ) ::   kt       ! ocean time-step index
+      INTEGER                              , INTENT(in   ) ::   kit000   ! first time step index
+      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype   ! =TRA or TRC (tracer indicator)
+      INTEGER                              , INTENT(in   ) ::   kjpt     ! number of tracers
+      INTEGER                              , INTENT(in   ) ::   ksts     ! number of sub-time step
+      REAL(wp)                             , INTENT(in   ) ::   p2dt     ! vertical profile of tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb      ! before and now tracer fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta      ! in: tracer trend ; out: after tracer field 
       !
-      INTEGER                              , INTENT(in   ) ::   kt          ! ocean time-step index
-      INTEGER                              , INTENT(in   ) ::   kit000      ! first time step index
-      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype      ! =TRA or TRC (tracer indicator)
-      INTEGER                              , INTENT(in   ) ::   kjpt        ! number of tracers
-      INTEGER                              , INTENT(in   ) ::   kn_zdfexp   ! number of sub-time step
-      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt        ! vertical profile of tracer time-step
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb         ! before and now tracer fields
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta         ! tracer trend 
-      !
-      INTEGER  ::  ji, jj, jk, jn, jl        ! dummy loop indices
-      REAL(wp) ::  zlavmr, zave3r, ze3tr     ! local scalars
-      REAL(wp) ::  ztra, ze3tb               !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zwx, zwy
+      INTEGER  ::  ji, jj, jk, jn, jl   ! dummy loop indices
+      REAL(wp) ::  z1_ksts, ze3tr       ! local scalars
+      REAL(wp) ::  ztra, ze3tb    !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztb, zwf
       !!---------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('tra_zdf_exp')
       !
-      CALL wrk_alloc( jpi, jpj, jpk, zwx, zwy ) 
+      CALL wrk_alloc( jpi,jpj,jpk,   ztb, zwf ) 
       !
-
       IF( kt == kit000 )  THEN
          IF(lwp) WRITE(numout,*)
@@ -104,27 +99,22 @@
       ! Initializations
       ! ---------------
-      zlavmr = 1. / float( kn_zdfexp )         ! Local constant
+      z1_ksts = 1._wp / REAL( ksts, wp )
+      zwf(:,:, 1 ) = 0._wp    ! no flux at the surface and at bottom level
+      zwf(:,:,jpk) = 0._wp
       !
       !
-      DO jn = 1, kjpt                          ! loop over tracers
+      DO jn = 1, kjpt         !==  loop over tracers  ==!
          !
-         zwy(:,:, 1 ) = 0.e0     ! surface boundary conditions: no flux
-         zwy(:,:,jpk) = 0.e0     ! bottom  boundary conditions: no flux
-         !
-         zwx(:,:,:)   = ptb(:,:,:,jn)  ! zwx array set to before tracer values
-
-         ! Split-explicit loop  (after tracer due to the vertical diffusion alone)
-         ! -------------------
-         !
-         DO jl = 1, kn_zdfexp
-            !                     ! first vertical derivative
-            DO jk = 2, jpk
+         ztb(:,:,:) = ptb(:,:,:,jn)    ! initial before value for tracer
+         ! 
+         DO jl = 1, ksts         !==  Split-explicit loop  ==!
+            !              
+            DO jk = 2, jpk             ! 1st vertical derivative (w-flux)
                DO jj = 2, jpjm1 
                   DO ji = fs_2, fs_jpim1   ! vector opt.
-                     zave3r = 1.e0 / fse3w_n(ji,jj,jk) 
                      IF( cdtype == 'TRA' .AND. jn == jp_tem ) THEN  ! temperature : use of avt
-                        zwy(ji,jj,jk) =   avt(ji,jj,jk) * ( zwx(ji,jj,jk-1) - zwx(ji,jj,jk) ) * zave3r
+                        zwf(ji,jj,jk) =   avt(ji,jj,jk) * ( ztb(ji,jj,jk-1) - ztb(ji,jj,jk) ) / e3w_b(ji,jj,jk)
                      ELSE                                           ! salinity or pass. tracer : use of avs
-                        zwy(ji,jj,jk) = fsavs(ji,jj,jk) * ( zwx(ji,jj,jk-1) - zwx(ji,jj,jk) ) * zave3r
+                        zwf(ji,jj,jk) = fsavs(ji,jj,jk) * ( ztb(ji,jj,jk-1) - ztb(ji,jj,jk) ) / e3w_b(ji,jj,jk)
                      END IF
                   END DO
@@ -132,40 +122,27 @@
             END DO
             !
-            DO jk = 1, jpkm1      ! second vertical derivative   ==> tracer at kt+l*2*rdt/nn_zdfexp
+            DO jk = 1, jpkm1           ! 2nd vertical derivative   ==> tracer at kt+l*2*rdt/nn_zdfexp
                DO jj = 2, jpjm1 
                   DO ji = fs_2, fs_jpim1   ! vector opt.
-                     ze3tr = zlavmr / fse3t_n(ji,jj,jk)
-                     zwx(ji,jj,jk) = zwx(ji,jj,jk) + p2dt(jk) * ( zwy(ji,jj,jk) - zwy(ji,jj,jk+1) ) * ze3tr
+                     ztb(ji,jj,jk) = ztb(ji,jj,jk) + p2dt * ( zwf(ji,jj,jk) - zwf(ji,jj,jk+1) ) / e3t_n(ji,jj,jk)
                   END DO
                END DO
             END DO
             !
-         END DO
+         END DO                  ! end sub-time stepping
 
-         ! After tracer due to all trends
-         ! ------------------------------
-         IF( lk_vvl ) THEN          ! variable level thickness : leap-frog on tracer*e3t
-            DO jk = 1, jpkm1
-               DO jj = 2, jpjm1 
-                  DO ji = fs_2, fs_jpim1   ! vector opt.
-                     ze3tb = fse3t_b(ji,jj,jk) / fse3t(ji,jj,jk)                          ! before e3t
-                     ztra  = zwx(ji,jj,jk) - ptb(ji,jj,jk,jn) + p2dt(jk) * pta(ji,jj,jk,jn)       ! total trends * 2*rdt 
-                     pta(ji,jj,jk,jn) = ( ze3tb * ptb(ji,jj,jk,jn) + ztra ) * tmask(ji,jj,jk)
-                  END DO
+         DO jk = 1, jpkm1        !==  After tracer due to all trends
+            DO jj = 2, jpjm1 
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ze3tb = e3t_b(ji,jj,jk) / e3t_n(ji,jj,jk)
+                  ztra  = ( ztb(ji,jj,jk) - ptb(ji,jj,jk,jn) ) + p2dt * pta(ji,jj,jk,jn)  ! total trend * 2dt 
+                  pta(ji,jj,jk,jn) = ( ze3tb * ptb(ji,jj,jk,jn) + ztra ) * tmask(ji,jj,jk)    ! after tracer
                END DO
             END DO
-         ELSE                       ! fixed level thickness : leap-frog on tracers
-            DO jk = 1, jpkm1
-               DO jj = 2, jpjm1 
-                  DO ji = fs_2, fs_jpim1   ! vector opt.
-                     pta(ji,jj,jk,jn) = ( zwx(ji,jj,jk) + p2dt(jk) * pta(ji,jj,jk,jn) ) * tmask(ji,jj,jk)
-                  END DO
-               END DO
-            END DO
-         ENDIF
+         END DO
          !
-      END DO
+      END DO                     ! end of tracer loop
       !
-      CALL wrk_dealloc( jpi, jpj, jpk, zwx, zwy ) 
+      CALL wrk_dealloc( jpi,jpj,jpk,   ztb, zwf ) 
       !
       IF( nn_timing == 1 )  CALL timing_stop('tra_zdf_exp')
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf_imp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf_imp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf_imp.F90	(revision 6140)
@@ -16,8 +16,9 @@
    !!            3.3  !  2010-06  (C. Ethe, G. Madec) Merge TRA-TRC
    !!             -   !  2011-02  (A. Coward, C. Ethe, G. Madec) improvment of surface boundary condition
+   !!            3.7  !  2015-11  (G. Madec, A. Coward)  non linear free surface by default 
    !!----------------------------------------------------------------------
   
    !!----------------------------------------------------------------------
-   !!   tra_zdf_imp   : Update the tracer trend with the diagonal vertical part of the mixing tensor.
+   !!   tra_zdf_imp   : Update the tracer trend with vertical mixing, nad compute the after tracer field
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers variables
@@ -42,8 +43,5 @@
    PUBLIC   tra_zdf_imp   !  routine called by step.F90
 
-   REAL(wp) ::  r_vvl     ! variable volume indicator, =1 if lk_vvl=T, =0 otherwise 
-
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
@@ -64,7 +62,8 @@
       !!     it is already computed and add to the general trend in traldf) 
       !!
-      !! ** Method  :  The vertical diffusion of the tracer t  is given by:
-      !!                  difft = dz( avt dz(t) ) = 1/e3t dk+1( avt/e3w dk(t) )
-      !!      It is computed using a backward time scheme (t=ta).
+      !! ** Method  :  The vertical diffusion of a tracer ,t , is given by:
+      !!          difft = dz( avt dz(t) ) = 1/e3t dk+1( avt/e3w dk(t) )
+      !!      It is computed using a backward time scheme (t=after field)
+      !!      which provide directly the after tracer field.
       !!      If lk_zdfddm=T, use avs for salinity or for passive tracers
       !!      Surface and bottom boundary conditions: no diffusive flux on
@@ -75,13 +74,13 @@
       !!---------------------------------------------------------------------
       INTEGER                              , INTENT(in   ) ::   kt       ! ocean time-step index
-      INTEGER                              , INTENT(in   ) ::   kit000          ! first time step index
+      INTEGER                              , INTENT(in   ) ::   kit000   ! first time step index
       CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype   ! =TRA or TRC (tracer indicator)
       INTEGER                              , INTENT(in   ) ::   kjpt     ! number of tracers
-      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt     ! vertical profile of tracer time-step
+      REAL(wp)                             , INTENT(in   ) ::   p2dt     ! tracer time-step
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb      ! before and now tracer fields
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta      ! tracer trend 
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta      ! in: tracer trend ; out: after tracer field
       !
       INTEGER  ::  ji, jj, jk, jn   ! dummy loop indices
-      REAL(wp) ::  zrhs, ze3tb, ze3tn, ze3ta   ! local scalars
+      REAL(wp) ::  zrhs             ! local scalars
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  zwi, zwt, zwd, zws
       !!---------------------------------------------------------------------
@@ -95,14 +94,8 @@
          IF(lwp)WRITE(numout,*) 'tra_zdf_imp : implicit vertical mixing on ', cdtype
          IF(lwp)WRITE(numout,*) '~~~~~~~~~~~ '
-         !
-         IF( lk_vvl ) THEN   ;    r_vvl = 1._wp       ! Variable volume indicator
-         ELSE                ;    r_vvl = 0._wp       
-         ENDIF
       ENDIF
-      !
       !                                               ! ============= !
       DO jn = 1, kjpt                                 !  tracer loop  !
          !                                            ! ============= !
-         !
          !  Matrix construction
          ! --------------------
@@ -142,9 +135,8 @@
                DO jj = 2, jpjm1
                   DO ji = fs_2, fs_jpim1   ! vector opt.
-                     ze3ta =  ( 1. - r_vvl ) +        r_vvl   * fse3t_a(ji,jj,jk)   ! after scale factor at T-point
-                     ze3tn =         r_vvl   + ( 1. - r_vvl ) * fse3t_n(ji,jj,jk)   ! now   scale factor at T-point
-                     zwi(ji,jj,jk) = - p2dt(jk) * zwt(ji,jj,jk  ) / ( ze3tn * fse3w(ji,jj,jk  ) )
-                     zws(ji,jj,jk) = - p2dt(jk) * zwt(ji,jj,jk+1) / ( ze3tn * fse3w(ji,jj,jk+1) )
-                     zwd(ji,jj,jk) = ze3ta - zwi(ji,jj,jk) - zws(ji,jj,jk)
+!!gm BUG  I think, use e3w_a instead of e3w_n
+                     zwi(ji,jj,jk) = - p2dt * zwt(ji,jj,jk  ) / e3w_n(ji,jj,jk  )
+                     zws(ji,jj,jk) = - p2dt * zwt(ji,jj,jk+1) / e3w_n(ji,jj,jk+1)
+                     zwd(ji,jj,jk) = e3t_a(ji,jj,jk) - zwi(ji,jj,jk) - zws(ji,jj,jk)
                  END DO
                END DO
@@ -170,8 +162,6 @@
             !   used as a work space array: its value is modified.
             !
-            ! first recurrence:   Tk = Dk - Ik Sk-1 / Tk-1   (increasing k)
-            ! done once for all passive tracers (so included in the IF instruction)
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1
+            DO jj = 2, jpjm1        !* 1st recurrence:   Tk = Dk - Ik Sk-1 / Tk-1   (increasing k)
+               DO ji = fs_2, fs_jpim1            ! done one for all passive tracers (so included in the IF instruction)
                   zwt(ji,jj,1) = zwd(ji,jj,1)
                END DO
@@ -185,12 +175,9 @@
             END DO
             !
-         END IF 
+         ENDIF 
          !         
-         ! second recurrence:    Zk = Yk - Ik / Tk-1  Zk-1
-         DO jj = 2, jpjm1
+         DO jj = 2, jpjm1           !* 2nd recurrence:    Zk = Yk - Ik / Tk-1  Zk-1
             DO ji = fs_2, fs_jpim1
-               ze3tb = ( 1. - r_vvl ) + r_vvl * fse3t_b(ji,jj,1)
-               ze3tn = ( 1. - r_vvl ) + r_vvl * fse3t(ji,jj,1)
-               pta(ji,jj,1,jn) = ze3tb * ptb(ji,jj,1,jn) + p2dt(1) * ze3tn * pta(ji,jj,1,jn)
+               pta(ji,jj,1,jn) = e3t_b(ji,jj,1) * ptb(ji,jj,1,jn) + p2dt * e3t_n(ji,jj,1) * pta(ji,jj,1,jn)
             END DO
          END DO
@@ -198,14 +185,11 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1
-                  ze3tb = ( 1. - r_vvl ) + r_vvl * fse3t_b(ji,jj,jk)
-                  ze3tn = ( 1. - r_vvl ) + r_vvl * fse3t  (ji,jj,jk)
-                  zrhs = ze3tb * ptb(ji,jj,jk,jn) + p2dt(jk) * ze3tn * pta(ji,jj,jk,jn)   ! zrhs=right hand side 
+                  zrhs = e3t_b(ji,jj,jk) * ptb(ji,jj,jk,jn) + p2dt * e3t_n(ji,jj,jk) * pta(ji,jj,jk,jn)   ! zrhs=right hand side
                   pta(ji,jj,jk,jn) = zrhs - zwi(ji,jj,jk) / zwt(ji,jj,jk-1) * pta(ji,jj,jk-1,jn)
                END DO
             END DO
          END DO
-
-         ! third recurrence:    Xk = (Zk - Sk Xk+1 ) / Tk   (result is the after tracer)
-         DO jj = 2, jpjm1
+         !
+         DO jj = 2, jpjm1           !* 3d recurrence:    Xk = (Zk - Sk Xk+1 ) / Tk   (result is the after tracer)
             DO ji = fs_2, fs_jpim1
                pta(ji,jj,jpkm1,jn) = pta(ji,jj,jpkm1,jn) / zwt(ji,jj,jpkm1) * tmask(ji,jj,jpkm1)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/zpshde.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/zpshde.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRA/zpshde.F90	(revision 6140)
@@ -32,5 +32,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -111,10 +110,11 @@
                iku = mbku(ji,jj)   ;   ikum1 = MAX( iku - 1 , 1 )    ! last and before last ocean level at u- & v-points
                ikv = mbkv(ji,jj)   ;   ikvm1 = MAX( ikv - 1 , 1 )    ! if level first is a p-step, ik.m1=1
-               ze3wu = fse3w(ji+1,jj  ,iku) - fse3w(ji,jj,iku)
-               ze3wv = fse3w(ji  ,jj+1,ikv) - fse3w(ji,jj,ikv)
+!!gm BUG ? when applied to before fields, e3w_b should be used....
+               ze3wu = e3w_n(ji+1,jj  ,iku) - e3w_n(ji,jj,iku)
+               ze3wv = e3w_n(ji  ,jj+1,ikv) - e3w_n(ji,jj,ikv)
                !
                ! i- direction
                IF( ze3wu >= 0._wp ) THEN      ! case 1
-                  zmaxu =  ze3wu / fse3w(ji+1,jj,iku)
+                  zmaxu =  ze3wu / e3w_n(ji+1,jj,iku)
                   ! interpolated values of tracers
                   zti (ji,jj,jn) = pta(ji+1,jj,iku,jn) + zmaxu * ( pta(ji+1,jj,ikum1,jn) - pta(ji+1,jj,iku,jn) )
@@ -122,5 +122,5 @@
                   pgtu(ji,jj,jn) = umask(ji,jj,1) * ( zti(ji,jj,jn) - pta(ji,jj,iku,jn) )
                ELSE                           ! case 2
-                  zmaxu = -ze3wu / fse3w(ji,jj,iku)
+                  zmaxu = -ze3wu / e3w_n(ji,jj,iku)
                   ! interpolated values of tracers
                   zti (ji,jj,jn) = pta(ji,jj,iku,jn) + zmaxu * ( pta(ji,jj,ikum1,jn) - pta(ji,jj,iku,jn) )
@@ -131,5 +131,5 @@
                ! j- direction
                IF( ze3wv >= 0._wp ) THEN      ! case 1
-                  zmaxv =  ze3wv / fse3w(ji,jj+1,ikv)
+                  zmaxv =  ze3wv / e3w_n(ji,jj+1,ikv)
                   ! interpolated values of tracers
                   ztj (ji,jj,jn) = pta(ji,jj+1,ikv,jn) + zmaxv * ( pta(ji,jj+1,ikvm1,jn) - pta(ji,jj+1,ikv,jn) )
@@ -137,5 +137,5 @@
                   pgtv(ji,jj,jn) = vmask(ji,jj,1) * ( ztj(ji,jj,jn) - pta(ji,jj,ikv,jn) )
                ELSE                           ! case 2
-                  zmaxv =  -ze3wv / fse3w(ji,jj,ikv)
+                  zmaxv =  -ze3wv / e3w_n(ji,jj,ikv)
                   ! interpolated values of tracers
                   ztj (ji,jj,jn) = pta(ji,jj,ikv,jn) + zmaxv * ( pta(ji,jj,ikvm1,jn) - pta(ji,jj,ikv,jn) )
@@ -156,11 +156,11 @@
                iku = mbku(ji,jj)
                ikv = mbkv(ji,jj)
-               ze3wu  = fse3w(ji+1,jj  ,iku) - fse3w(ji,jj,iku)
-               ze3wv  = fse3w(ji  ,jj+1,ikv) - fse3w(ji,jj,ikv)
-               IF( ze3wu >= 0._wp ) THEN   ;   zhi(ji,jj) = fsdept(ji  ,jj,iku)     ! i-direction: case 1
-               ELSE                        ;   zhi(ji,jj) = fsdept(ji+1,jj,iku)     ! -     -      case 2
-               ENDIF
-               IF( ze3wv >= 0._wp ) THEN   ;   zhj(ji,jj) = fsdept(ji,jj  ,ikv)     ! j-direction: case 1
-               ELSE                        ;   zhj(ji,jj) = fsdept(ji,jj+1,ikv)     ! -     -      case 2
+               ze3wu  = e3w_n(ji+1,jj  ,iku) - e3w_n(ji,jj,iku)
+               ze3wv  = e3w_n(ji  ,jj+1,ikv) - e3w_n(ji,jj,ikv)
+               IF( ze3wu >= 0._wp ) THEN   ;   zhi(ji,jj) = gdept_n(ji  ,jj,iku)     ! i-direction: case 1
+               ELSE                        ;   zhi(ji,jj) = gdept_n(ji+1,jj,iku)     ! -     -      case 2
+               ENDIF
+               IF( ze3wv >= 0._wp ) THEN   ;   zhj(ji,jj) = gdept_n(ji,jj  ,ikv)     ! j-direction: case 1
+               ELSE                        ;   zhj(ji,jj) = gdept_n(ji,jj+1,ikv)     ! -     -      case 2
                ENDIF
             END DO
@@ -174,6 +174,6 @@
                iku = mbku(ji,jj)
                ikv = mbkv(ji,jj)
-               ze3wu  = fse3w(ji+1,jj  ,iku) - fse3w(ji,jj,iku)
-               ze3wv  = fse3w(ji  ,jj+1,ikv) - fse3w(ji,jj,ikv)
+               ze3wu  = e3w_n(ji+1,jj  ,iku) - e3w_n(ji,jj,iku)
+               ze3wv  = e3w_n(ji  ,jj+1,ikv) - e3w_n(ji,jj,ikv)
                IF( ze3wu >= 0._wp ) THEN   ;   pgru(ji,jj) = umask(ji,jj,1) * ( zri(ji  ,jj    ) - prd(ji,jj,iku) )   ! i: 1
                ELSE                        ;   pgru(ji,jj) = umask(ji,jj,1) * ( prd(ji+1,jj,iku) - zri(ji,jj    ) )   ! i: 2
@@ -191,20 +191,19 @@
       !
    END SUBROUTINE zps_hde
-
-
-   SUBROUTINE zps_hde_isf( kt, kjpt, pta, pgtu , pgtv , pgtui, pgtvi,                                   &
-      &                              prd, pgru , pgrv , pmru , pmrv , pgzu , pgzv , pge3ru , pge3rv ,   &
-      &                                   pgrui, pgrvi, pmrui, pmrvi, pgzui, pgzvi, pge3rui, pge3rvi )
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE zps_hde  ***
+   !
+   SUBROUTINE zps_hde_isf( kt, kjpt, pta, pgtu, pgtv, pgtui, pgtvi,  &
+      &                          prd, pgru, pgrv, pgrui, pgrvi )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE zps_hde_isf  ***
       !!                    
       !! ** Purpose :   Compute the horizontal derivative of T, S and rho
       !!      at u- and v-points with a linear interpolation for z-coordinate
-      !!      with partial steps.
+      !!      with partial steps for top (ice shelf) and bottom.
       !!
       !! ** Method  :   In z-coord with partial steps, scale factors on last 
       !!      levels are different for each grid point, so that T, S and rd 
       !!      points are not at the same depth as in z-coord. To have horizontal
-      !!      gradients again, we interpolate T and S at the good depth : 
+      !!      gradients again, we interpolate T and S at the good depth :
+      !!      For the bottom case:
       !!      Linear interpolation of T, S   
       !!         Computation of di(tb) and dj(tb) by vertical interpolation:
@@ -235,31 +234,22 @@
       !!          di(rho) = rd~ - rd(i,j,k)   or   rd(i+1,j,k) - rd~
       !!
+      !!      For the top case (ice shelf): As for the bottom case but upside down
+      !!
       !! ** Action  : compute for top and bottom interfaces
       !!              - pgtu, pgtv, pgtui, pgtvi: horizontal gradient of tracer at u- & v-points
       !!              - pgru, pgrv, pgrui, pgtvi: horizontal gradient of rho (if present) at u- & v-points
-      !!              - pmru, pmrv, pmrui, pmrvi: horizontal sum of rho at u- & v- point (used in dynhpg with vvl)
-      !!              - pgzu, pgzv, pgzui, pgzvi: horizontal gradient of z at u- and v- point (used in dynhpg with vvl)
-      !!              - pge3ru, pge3rv, pge3rui, pge3rvi: horizontal gradient of rho weighted by local e3w at u- & v-points 
-      !!----------------------------------------------------------------------
-      INTEGER                              , INTENT(in   )           ::  kt                ! ocean time-step index
-      INTEGER                              , INTENT(in   )           ::  kjpt              ! number of tracers
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   )           ::  pta               ! 4D tracers fields
-      !                                                              !!  u-point ! v-point !
-      REAL(wp), DIMENSION(jpi,jpj,    kjpt), INTENT(  out)           ::  pgtu    , pgtv    ! bottom GRADh( ptra )  
-      REAL(wp), DIMENSION(jpi,jpj,    kjpt), INTENT(  out)           ::  pgtui   , pgtvi   ! top    GRADh( ptra )
-      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ), OPTIONAL ::  prd               ! 3D density anomaly fields
-      !                                                              !!  u-point ! v-point !
-      REAL(wp), DIMENSION(jpi,jpj         ), INTENT(  out), OPTIONAL ::  pgru    , pgrv    ! bottom GRADh( prd  )
-      REAL(wp), DIMENSION(jpi,jpj         ), INTENT(  out), OPTIONAL ::  pmru    , pmrv    ! bottom SUM  ( prd  )
-      REAL(wp), DIMENSION(jpi,jpj         ), INTENT(  out), OPTIONAL ::  pgzu    , pgzv    ! bottom GRADh( z    ) 
-      REAL(wp), DIMENSION(jpi,jpj         ), INTENT(  out), OPTIONAL ::  pge3ru  , pge3rv  ! bottom GRADh( prd  ) weighted by e3w
-      REAL(wp), DIMENSION(jpi,jpj         ), INTENT(  out), OPTIONAL ::  pgrui   , pgrvi   ! top    GRADh( prd  ) 
-      REAL(wp), DIMENSION(jpi,jpj         ), INTENT(  out), OPTIONAL ::  pmrui   , pmrvi   ! top    SUM  ( prd  ) 
-      REAL(wp), DIMENSION(jpi,jpj         ), INTENT(  out), OPTIONAL ::  pgzui   , pgzvi   ! top    GRADh( z    ) 
-      REAL(wp), DIMENSION(jpi,jpj         ), INTENT(  out), OPTIONAL ::  pge3rui , pge3rvi ! top    GRADh( prd  ) weighted by e3w
+      !!----------------------------------------------------------------------
+      INTEGER                              , INTENT(in   )           ::  kt           ! ocean time-step index
+      INTEGER                              , INTENT(in   )           ::  kjpt         ! number of tracers
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   )           ::  pta          ! 4D tracers fields
+      REAL(wp), DIMENSION(jpi,jpj,    kjpt), INTENT(  out)           ::  pgtu, pgtv   ! hor. grad. of ptra at u- & v-pts 
+      REAL(wp), DIMENSION(jpi,jpj,    kjpt), INTENT(  out)           ::  pgtui, pgtvi ! hor. grad. of stra at u- & v-pts (ISF)
+      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ), OPTIONAL ::  prd          ! 3D density anomaly fields
+      REAL(wp), DIMENSION(jpi,jpj         ), INTENT(  out), OPTIONAL ::  pgru, pgrv   ! hor. grad of prd at u- & v-pts (bottom)
+      REAL(wp), DIMENSION(jpi,jpj         ), INTENT(  out), OPTIONAL ::  pgrui, pgrvi ! hor. grad of prd at u- & v-pts (top)
       !
       INTEGER  ::   ji, jj, jn      ! Dummy loop indices
       INTEGER  ::   iku, ikv, ikum1, ikvm1,ikup1, ikvp1   ! partial step level (ocean bottom level) at u- and v-points
-      REAL(wp) ::  ze3wu, ze3wv, zmaxu, zmaxv, zdzwu, zdzwv, zdzwuip1, zdzwvjp1  ! temporary scalars
+      REAL(wp) ::  ze3wu, ze3wv, zmaxu, zmaxv             ! temporary scalars
       REAL(wp), DIMENSION(jpi,jpj)      ::  zri, zrj, zhi, zhj   ! NB: 3rd dim=1 to use eos
       REAL(wp), DIMENSION(jpi,jpj,kjpt) ::  zti, ztj             ! 
@@ -277,45 +267,142 @@
          DO jj = 1, jpjm1
             DO ji = 1, jpim1
-               iku = mbku(ji,jj)   ;   ikum1 = MAX( iku - 1 , 1 )    ! last and before last ocean level at u- & v-points
-               ikv = mbkv(ji,jj)   ;   ikvm1 = MAX( ikv - 1 , 1 )    ! if level first is a p-step, ik.m1=1
+
+               iku = mbku(ji,jj); ikum1 = MAX( iku - 1 , 1 )    ! last and before last ocean level at u- & v-points
+               ikv = mbkv(ji,jj); ikvm1 = MAX( ikv - 1 , 1 )    ! if level first is a p-step, ik.m1=1
+               ze3wu = gdept_n(ji+1,jj,iku) - gdept_n(ji,jj,iku)
+               ze3wv = gdept_n(ji,jj+1,ikv) - gdept_n(ji,jj,ikv)
+               !
+               ! i- direction
+               IF( ze3wu >= 0._wp ) THEN      ! case 1
+                  zmaxu =  ze3wu / e3w_n(ji+1,jj,iku)
+                  ! interpolated values of tracers
+                  zti (ji,jj,jn) = pta(ji+1,jj,iku,jn) + zmaxu * ( pta(ji+1,jj,ikum1,jn) - pta(ji+1,jj,iku,jn) )
+                  ! gradient of  tracers
+                  pgtu(ji,jj,jn) = ssumask(ji,jj) * ( zti(ji,jj,jn) - pta(ji,jj,iku,jn) )
+               ELSE                           ! case 2
+                  zmaxu = -ze3wu / e3w_n(ji,jj,iku)
+                  ! interpolated values of tracers
+                  zti (ji,jj,jn) = pta(ji,jj,iku,jn) + zmaxu * ( pta(ji,jj,ikum1,jn) - pta(ji,jj,iku,jn) )
+                  ! gradient of tracers
+                  pgtu(ji,jj,jn) = ssumask(ji,jj) * ( pta(ji+1,jj,iku,jn) - zti(ji,jj,jn) )
+               ENDIF
+               !
+               ! j- direction
+               IF( ze3wv >= 0._wp ) THEN      ! case 1
+                  zmaxv =  ze3wv / e3w_n(ji,jj+1,ikv)
+                  ! interpolated values of tracers
+                  ztj (ji,jj,jn) = pta(ji,jj+1,ikv,jn) + zmaxv * ( pta(ji,jj+1,ikvm1,jn) - pta(ji,jj+1,ikv,jn) )
+                  ! gradient of tracers
+                  pgtv(ji,jj,jn) = ssvmask(ji,jj) * ( ztj(ji,jj,jn) - pta(ji,jj,ikv,jn) )
+               ELSE                           ! case 2
+                  zmaxv =  -ze3wv / e3w_n(ji,jj,ikv)
+                  ! interpolated values of tracers
+                  ztj (ji,jj,jn) = pta(ji,jj,ikv,jn) + zmaxv * ( pta(ji,jj,ikvm1,jn) - pta(ji,jj,ikv,jn) )
+                  ! gradient of tracers
+                  pgtv(ji,jj,jn) = ssvmask(ji,jj) * ( pta(ji,jj+1,ikv,jn) - ztj(ji,jj,jn) )
+               ENDIF
+
+            END DO
+         END DO
+         CALL lbc_lnk( pgtu(:,:,jn), 'U', -1. )   ;   CALL lbc_lnk( pgtv(:,:,jn), 'V', -1. )   ! Lateral boundary cond.
+         !
+      END DO
+
+      ! horizontal derivative of density anomalies (rd)
+      IF( PRESENT( prd ) ) THEN         ! depth of the partial step level
+         pgru(:,:)=0.0_wp   ; pgrv(:,:)=0.0_wp ; 
+         !
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+
+               iku = mbku(ji,jj)
+               ikv = mbkv(ji,jj)
+               ze3wu = gdept_n(ji+1,jj,iku) - gdept_n(ji,jj,iku)
+               ze3wv = gdept_n(ji,jj+1,ikv) - gdept_n(ji,jj,ikv)
+               !
+               IF( ze3wu >= 0._wp ) THEN   ;   zhi(ji,jj) = gdept_n(ji  ,jj,iku)    ! i-direction: case 1
+               ELSE                        ;   zhi(ji,jj) = gdept_n(ji+1,jj,iku)    ! -     -      case 2
+               ENDIF
+               IF( ze3wv >= 0._wp ) THEN   ;   zhj(ji,jj) = gdept_n(ji,jj  ,ikv)    ! j-direction: case 1
+               ELSE                        ;   zhj(ji,jj) = gdept_n(ji,jj+1,ikv)    ! -     -      case 2
+               ENDIF
+
+            END DO
+         END DO
+
+         ! Compute interpolated rd from zti, ztj for the 2 cases at the depth of the partial
+         ! step and store it in  zri, zrj for each  case
+         CALL eos( zti, zhi, zri )
+         CALL eos( ztj, zhj, zrj )
+
+         DO jj = 1, jpjm1                 ! Gradient of density at the last level 
+            DO ji = 1, jpim1
+               iku = mbku(ji,jj)
+               ikv = mbkv(ji,jj)
+               ze3wu = gdept_n(ji+1,jj,iku) - gdept_n(ji,jj,iku)
+               ze3wv = gdept_n(ji,jj+1,ikv) - gdept_n(ji,jj,ikv)
+
+               IF( ze3wu >= 0._wp ) THEN   ;   pgru(ji,jj) = ssumask(ji,jj) * ( zri(ji  ,jj    ) - prd(ji,jj,iku) )   ! i: 1
+               ELSE                        ;   pgru(ji,jj) = ssumask(ji,jj) * ( prd(ji+1,jj,iku) - zri(ji,jj    ) )   ! i: 2
+               ENDIF
+               IF( ze3wv >= 0._wp ) THEN   ;   pgrv(ji,jj) = ssvmask(ji,jj) * ( zrj(ji,jj      ) - prd(ji,jj,ikv) )   ! j: 1
+               ELSE                        ;   pgrv(ji,jj) = ssvmask(ji,jj) * ( prd(ji,jj+1,ikv) - zrj(ji,jj    ) )   ! j: 2
+               ENDIF
+
+            END DO
+         END DO
+
+         CALL lbc_lnk( pgru , 'U', -1. )   ;   CALL lbc_lnk( pgrv , 'V', -1. )   ! Lateral boundary conditions
+         !
+      END IF
+      !
+      !     !==  (ISH)  compute grui and gruvi  ==!
+      !
+      DO jn = 1, kjpt      !==   Interpolation of tracers at the last ocean level   ==!            !
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               iku = miku(ji,jj); ikup1 = miku(ji,jj) + 1
+               ikv = mikv(ji,jj); ikvp1 = mikv(ji,jj) + 1
+               !
                ! (ISF) case partial step top and bottom in adjacent cell in vertical
                ! cannot used e3w because if 2 cell water column, we have ps at top and bottom
                ! in this case e3w(i,j) - e3w(i,j+1) is not the distance between Tj~ and Tj
                ! the only common depth between cells (i,j) and (i,j+1) is gdepw_0
-               ze3wu  = (gdept_0(ji+1,jj,iku) - gdepw_0(ji+1,jj,iku)) - (gdept_0(ji,jj,iku) - gdepw_0(ji,jj,iku))
-               ze3wv  = (gdept_0(ji,jj+1,ikv) - gdepw_0(ji,jj+1,ikv)) - (gdept_0(ji,jj,ikv) - gdepw_0(ji,jj,ikv))
-               !
+               ze3wu  =  gdept_n(ji,jj,iku) - gdept_n(ji+1,jj,iku)
+               ze3wv  =  gdept_n(ji,jj,ikv) - gdept_n(ji,jj+1,ikv) 
+
                ! i- direction
                IF( ze3wu >= 0._wp ) THEN      ! case 1
-                  zmaxu =  ze3wu / fse3w(ji+1,jj,iku)
-                  ! interpolated values of tracers
-                  zti (ji,jj,jn) = pta(ji+1,jj,iku,jn) + zmaxu * ( pta(ji+1,jj,ikum1,jn) - pta(ji+1,jj,iku,jn) )
+                  zmaxu = ze3wu / e3w_n(ji+1,jj,ikup1)
+                  ! interpolated values of tracers
+                  zti(ji,jj,jn) = pta(ji+1,jj,iku,jn) + zmaxu * ( pta(ji+1,jj,ikup1,jn) - pta(ji+1,jj,iku,jn) )
+                  ! gradient of tracers
+                  pgtui(ji,jj,jn) = ssumask(ji,jj) * ( zti(ji,jj,jn) - pta(ji,jj,iku,jn) )
+               ELSE                           ! case 2
+                  zmaxu = - ze3wu / e3w_n(ji,jj,ikup1)
+                  ! interpolated values of tracers
+                  zti(ji,jj,jn) = pta(ji,jj,iku,jn) + zmaxu * ( pta(ji,jj,ikup1,jn) - pta(ji,jj,iku,jn) )
                   ! gradient of  tracers
-                  pgtu(ji,jj,jn) = umask(ji,jj,iku) * ( zti(ji,jj,jn) - pta(ji,jj,iku,jn) )
-               ELSE                           ! case 2
-                  zmaxu = -ze3wu / fse3w(ji,jj,iku)
-                  ! interpolated values of tracers
-                  zti (ji,jj,jn) = pta(ji,jj,iku,jn) + zmaxu * ( pta(ji,jj,ikum1,jn) - pta(ji,jj,iku,jn) )
-                  ! gradient of tracers
-                  pgtu(ji,jj,jn) = umask(ji,jj,iku) * ( pta(ji+1,jj,iku,jn) - zti(ji,jj,jn) )
+                  pgtui(ji,jj,jn) = ssumask(ji,jj) * ( pta(ji+1,jj,iku,jn) - zti(ji,jj,jn) )
                ENDIF
                !
                ! j- direction
                IF( ze3wv >= 0._wp ) THEN      ! case 1
-                  zmaxv =  ze3wv / fse3w(ji,jj+1,ikv)
-                  ! interpolated values of tracers
-                  ztj (ji,jj,jn) = pta(ji,jj+1,ikv,jn) + zmaxv * ( pta(ji,jj+1,ikvm1,jn) - pta(ji,jj+1,ikv,jn) )
-                  ! gradient of tracers
-                  pgtv(ji,jj,jn) = vmask(ji,jj,ikv) * ( ztj(ji,jj,jn) - pta(ji,jj,ikv,jn) )
-               ELSE                           ! case 2
-                  zmaxv =  -ze3wv / fse3w(ji,jj,ikv)
-                  ! interpolated values of tracers
-                  ztj (ji,jj,jn) = pta(ji,jj,ikv,jn) + zmaxv * ( pta(ji,jj,ikvm1,jn) - pta(ji,jj,ikv,jn) )
-                  ! gradient of tracers
-                  pgtv(ji,jj,jn) = vmask(ji,jj,ikv) * ( pta(ji,jj+1,ikv,jn) - ztj(ji,jj,jn) )
-               ENDIF
-            END DO
-         END DO
-         CALL lbc_lnk( pgtu(:,:,jn), 'U', -1. )   ;   CALL lbc_lnk( pgtv(:,:,jn), 'V', -1. )   ! Lateral boundary cond.
+                  zmaxv =  ze3wv / e3w_n(ji,jj+1,ikvp1)
+                  ! interpolated values of tracers
+                  ztj(ji,jj,jn) = pta(ji,jj+1,ikv,jn) + zmaxv * ( pta(ji,jj+1,ikvp1,jn) - pta(ji,jj+1,ikv,jn) )
+                  ! gradient of tracers
+                  pgtvi(ji,jj,jn) = ssvmask(ji,jj) * ( ztj(ji,jj,jn) - pta(ji,jj,ikv,jn) )
+               ELSE                           ! case 2
+                  zmaxv =  - ze3wv / e3w_n(ji,jj,ikvp1)
+                  ! interpolated values of tracers
+                  ztj(ji,jj,jn) = pta(ji,jj,ikv,jn) + zmaxv * ( pta(ji,jj,ikvp1,jn) - pta(ji,jj,ikv,jn) )
+                  ! gradient of tracers
+                  pgtvi(ji,jj,jn) = ssvmask(ji,jj) * ( pta(ji,jj+1,ikv,jn) - ztj(ji,jj,jn) )
+               ENDIF
+
+            END DO
+         END DO
+         CALL lbc_lnk( pgtui(:,:,jn), 'U', -1. ); CALL lbc_lnk( pgtvi(:,:,jn), 'V', -1. )   ! Lateral boundary cond.
          !
       END DO
@@ -323,22 +410,21 @@
       IF( PRESENT( prd ) ) THEN    !==  horizontal derivative of density anomalies (rd)  ==!    (optional part)
          !
-         pgru  (:,:)=0._wp   ;   pgrv  (:,:) = 0._wp
-         pgzu  (:,:)=0._wp   ;   pgzv  (:,:) = 0._wp 
-         pmru  (:,:)=0._wp   ;   pmru  (:,:) = 0._wp 
-         pge3ru(:,:)=0._wp   ;   pge3rv(:,:) = 0._wp 
-         !
-         DO jj = 1, jpjm1                 ! depth of the partial step level
-            DO ji = 1, jpim1
-               iku = mbku(ji,jj)
-               ikv = mbkv(ji,jj)
-               ze3wu  = (gdept_0(ji+1,jj,iku) - gdepw_0(ji+1,jj,iku)) - (gdept_0(ji,jj,iku) - gdepw_0(ji,jj,iku))
-               ze3wv  = (gdept_0(ji,jj+1,ikv) - gdepw_0(ji,jj+1,ikv)) - (gdept_0(ji,jj,ikv) - gdepw_0(ji,jj,ikv))
-               !
-               IF( ze3wu >= 0._wp ) THEN   ;   zhi(ji,jj) = fsdept(ji+1,jj,iku) - ze3wu     ! i-direction: case 1
-               ELSE                        ;   zhi(ji,jj) = fsdept(ji  ,jj,iku) + ze3wu    ! -     -      case 2
-               ENDIF
-               IF( ze3wv >= 0._wp ) THEN   ;   zhj(ji,jj) = fsdept(ji,jj+1,ikv) - ze3wv    ! j-direction: case 1
-               ELSE                        ;   zhj(ji,jj) = fsdept(ji,jj  ,ikv) + ze3wv    ! -     -      case 2
-               ENDIF
+         pgrui(:,:)  =0.0_wp; pgrvi(:,:)  =0.0_wp;
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+
+               iku = miku(ji,jj)
+               ikv = mikv(ji,jj)
+               ze3wu  =  gdept_n(ji,jj,iku) - gdept_n(ji+1,jj,iku)
+               ze3wv  =  gdept_n(ji,jj,ikv) - gdept_n(ji,jj+1,ikv) 
+               !
+               IF( ze3wu >= 0._wp ) THEN   ;   zhi(ji,jj) = gdept_n(ji  ,jj,iku)    ! i-direction: case 1
+               ELSE                        ;   zhi(ji,jj) = gdept_n(ji+1,jj,iku)    ! -     -      case 2
+               ENDIF
+
+               IF( ze3wv >= 0._wp ) THEN   ;   zhj(ji,jj) = gdept_n(ji,jj  ,ikv)    ! j-direction: case 1
+               ELSE                        ;   zhj(ji,jj) = gdept_n(ji,jj+1,ikv)    ! -     -      case 2
+               ENDIF
+
             END DO
          END DO
@@ -346,168 +432,22 @@
          CALL eos( zti, zhi, zri )        ! interpolated density from zti, ztj 
          CALL eos( ztj, zhj, zrj )        ! at the partial step depth output in  zri, zrj 
-
+         !
          DO jj = 1, jpjm1                 ! Gradient of density at the last level 
             DO ji = 1, jpim1
-               iku = mbku(ji,jj) ; ikum1 = MAX( iku - 1 , 1 )    ! last and before last ocean level at u- & v-points
-               ikv = mbkv(ji,jj) ; ikvm1 = MAX( ikv - 1 , 1 )    ! last and before last ocean level at u- & v-points
-               ze3wu  = (gdept_0(ji+1,jj,iku) - gdepw_0(ji+1,jj,iku)) - (gdept_0(ji,jj,iku) - gdepw_0(ji,jj,iku))
-               ze3wv  = (gdept_0(ji,jj+1,ikv) - gdepw_0(ji,jj+1,ikv)) - (gdept_0(ji,jj,ikv) - gdepw_0(ji,jj,ikv))
-               IF( ze3wu >= 0._wp ) THEN 
-                  pgzu(ji,jj) = (fsde3w(ji+1,jj,iku) - ze3wu) - fsde3w(ji,jj,iku)
-                  pgru(ji,jj) = umask(ji,jj,iku) * ( zri(ji  ,jj) - prd(ji,jj,iku) )   ! i: 1
-                  pmru(ji,jj) = umask(ji,jj,iku) * ( zri(ji  ,jj) + prd(ji,jj,iku) )   ! i: 1 
-                  pge3ru(ji,jj) = umask(ji,jj,iku)                                                                  &
-                                * ( (fse3w(ji+1,jj,iku) - ze3wu )* ( zri(ji  ,jj    ) + prd(ji+1,jj,ikum1) + 2._wp) &
-                                   - fse3w(ji  ,jj,iku)          * ( prd(ji  ,jj,iku) + prd(ji  ,jj,ikum1) + 2._wp) )  ! j: 2
-               ELSE  
-                  pgzu(ji,jj) = fsde3w(ji+1,jj,iku) - (fsde3w(ji,jj,iku) + ze3wu)
-                  pgru(ji,jj) = umask(ji,jj,iku) * ( prd(ji+1,jj,iku) - zri(ji,jj) )   ! i: 2
-                  pmru(ji,jj) = umask(ji,jj,iku) * ( prd(ji+1,jj,iku) + zri(ji,jj) )   ! i: 2
-                  pge3ru(ji,jj) = umask(ji,jj,iku)                                                                  &
-                                * (  fse3w(ji+1,jj,iku)          * ( prd(ji+1,jj,iku) + prd(ji+1,jj,ikum1) + 2._wp) &
-                                   -(fse3w(ji  ,jj,iku) + ze3wu) * ( zri(ji  ,jj    ) + prd(ji  ,jj,ikum1) + 2._wp) )  ! j: 2
-               ENDIF
-               IF( ze3wv >= 0._wp ) THEN
-                  pgzv(ji,jj) = (fsde3w(ji,jj+1,ikv) - ze3wv) - fsde3w(ji,jj,ikv) 
-                  pgrv(ji,jj) = vmask(ji,jj,ikv) * ( zrj(ji,jj  ) - prd(ji,jj,ikv) )   ! j: 1
-                  pmrv(ji,jj) = vmask(ji,jj,ikv) * ( zrj(ji,jj  ) + prd(ji,jj,ikv) )   ! j: 1
-                  pge3rv(ji,jj) = vmask(ji,jj,ikv)                                                                  &
-                                * ( (fse3w(ji,jj+1,ikv) - ze3wv )* ( zrj(ji,jj      ) + prd(ji,jj+1,ikvm1) + 2._wp) &
-                                   - fse3w(ji,jj  ,ikv)          * ( prd(ji,jj  ,ikv) + prd(ji,jj  ,ikvm1) + 2._wp) )  ! j: 2
-               ELSE 
-                  pgzv(ji,jj) = fsde3w(ji,jj+1,ikv) - (fsde3w(ji,jj,ikv) + ze3wv)
-                  pgrv(ji,jj) = vmask(ji,jj,ikv) * ( prd(ji,jj+1,ikv) - zrj(ji,jj) )   ! j: 2
-                  pmrv(ji,jj) = vmask(ji,jj,ikv) * ( prd(ji,jj+1,ikv) + zrj(ji,jj) )   ! j: 2
-                  pge3rv(ji,jj) = vmask(ji,jj,ikv)                                                                  &
-                                * (  fse3w(ji,jj+1,ikv)          * ( prd(ji,jj+1,ikv) + prd(ji,jj+1,ikvm1) + 2._wp) &
-                                   -(fse3w(ji,jj  ,ikv) + ze3wv) * ( zrj(ji,jj      ) + prd(ji,jj  ,ikvm1) + 2._wp) )  ! j: 2
-               ENDIF
-            END DO
-         END DO
-         CALL lbc_lnk( pgru   , 'U', -1. )   ;   CALL lbc_lnk( pgrv   , 'V', -1. )   ! Lateral boundary conditions
-         CALL lbc_lnk( pmru   , 'U',  1. )   ;   CALL lbc_lnk( pmrv   , 'V',  1. )   ! Lateral boundary conditions
-         CALL lbc_lnk( pgzu   , 'U', -1. )   ;   CALL lbc_lnk( pgzv   , 'V', -1. )   ! Lateral boundary conditions
-         CALL lbc_lnk( pge3ru , 'U', -1. )   ;   CALL lbc_lnk( pge3rv , 'V', -1. )   ! Lateral boundary conditions
-         !
-      END IF
-      !
-      !     !==  (ISH)  compute grui and gruvi  ==!
-      !
-      DO jn = 1, kjpt      !==   Interpolation of tracers at the last ocean level   ==!            !
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               iku = miku(ji,jj)   ;  ikup1 = miku(ji,jj) + 1
-               ikv = mikv(ji,jj)   ;  ikvp1 = mikv(ji,jj) + 1
-               !
-               ! (ISF) case partial step top and bottom in adjacent cell in vertical
-               ! cannot used e3w because if 2 cell water column, we have ps at top and bottom
-               ! in this case e3w(i,j) - e3w(i,j+1) is not the distance between Tj~ and Tj
-               ! the only common depth between cells (i,j) and (i,j+1) is gdepw_0
-               ze3wu  = (gdepw_0(ji+1,jj,iku+1) - gdept_0(ji+1,jj,iku)) - (gdepw_0(ji,jj,iku+1) - gdept_0(ji,jj,iku)) 
-               ze3wv  = (gdepw_0(ji,jj+1,ikv+1) - gdept_0(ji,jj+1,ikv)) - (gdepw_0(ji,jj,ikv+1) - gdept_0(ji,jj,ikv))
-               ! i- direction
-               IF( ze3wu >= 0._wp ) THEN      ! case 1
-                  zmaxu = ze3wu / fse3w(ji+1,jj,iku+1)
-                  ! interpolated values of tracers
-                  zti(ji,jj,jn) = pta(ji+1,jj,iku,jn) + zmaxu * ( pta(ji+1,jj,iku+1,jn) - pta(ji+1,jj,iku,jn) )
-                  ! gradient of tracers
-                  pgtui(ji,jj,jn) = umask(ji,jj,iku) * ( zti(ji,jj,jn) - pta(ji,jj,iku,jn) )
-               ELSE                           ! case 2
-                  zmaxu = - ze3wu / fse3w(ji,jj,iku+1)
-                  ! interpolated values of tracers
-                  zti(ji,jj,jn) = pta(ji,jj,iku,jn) + zmaxu * ( pta(ji,jj,iku+1,jn) - pta(ji,jj,iku,jn) )
-                  ! gradient of  tracers
-                  pgtui(ji,jj,jn) = umask(ji,jj,iku) * ( pta(ji+1,jj,iku,jn) - zti(ji,jj,jn) )
-               ENDIF
-               !
-               ! j- direction
-               IF( ze3wv >= 0._wp ) THEN      ! case 1
-                  zmaxv =  ze3wv / fse3w(ji,jj+1,ikv+1)
-                  ! interpolated values of tracers
-                  ztj(ji,jj,jn) = pta(ji,jj+1,ikv,jn) + zmaxv * ( pta(ji,jj+1,ikv+1,jn) - pta(ji,jj+1,ikv,jn) )
-                  ! gradient of tracers
-                  pgtvi(ji,jj,jn) = vmask(ji,jj,ikv) * ( ztj(ji,jj,jn) - pta(ji,jj,ikv,jn) )
-               ELSE                           ! case 2
-                  zmaxv =  - ze3wv / fse3w(ji,jj,ikv+1)
-                  ! interpolated values of tracers
-                  ztj(ji,jj,jn) = pta(ji,jj,ikv,jn) + zmaxv * ( pta(ji,jj,ikv+1,jn) - pta(ji,jj,ikv,jn) )
-                  ! gradient of tracers
-                  pgtvi(ji,jj,jn) = vmask(ji,jj,ikv) * ( pta(ji,jj+1,ikv,jn) - ztj(ji,jj,jn) )
-               ENDIF
-            END DO!!
-         END DO!!
-         CALL lbc_lnk( pgtui(:,:,jn), 'U', -1. )   ;   CALL lbc_lnk( pgtvi(:,:,jn), 'V', -1. )   ! Lateral boundary cond.
-         !
-      END DO
-
-      IF( PRESENT( prd ) ) THEN    !==  horizontal derivative of density anomalies (rd)  ==!    (optional part)
-         !
-         pgrui(:,:)  =0.0_wp ; pgrvi(:,:)  =0.0_wp ;
-         pgzui(:,:)  =0.0_wp ; pgzvi(:,:)  =0.0_wp ;
-         pmrui(:,:)  =0.0_wp ; pmrui(:,:)  =0.0_wp ;
-         pge3rui(:,:)=0.0_wp ; pge3rvi(:,:)=0.0_wp ;
-         !
-         DO jj = 1, jpjm1        ! depth of the partial step level
-            DO ji = 1, jpim1
-               iku = miku(ji,jj)
-               ikv = mikv(ji,jj)
-               ze3wu  = (gdepw_0(ji+1,jj,iku+1) - gdept_0(ji+1,jj,iku)) - (gdepw_0(ji,jj,iku+1) - gdept_0(ji,jj,iku))
-               ze3wv  = (gdepw_0(ji,jj+1,ikv+1) - gdept_0(ji,jj+1,ikv)) - (gdepw_0(ji,jj,ikv+1) - gdept_0(ji,jj,ikv))
-               !
-               IF( ze3wu >= 0._wp ) THEN   ;   zhi(ji,jj) = fsdept(ji+1,jj,iku) + ze3wu    ! i-direction: case 1
-               ELSE                        ;   zhi(ji,jj) = fsdept(ji  ,jj,iku) - ze3wu    ! -     -      case 2
-               ENDIF
-               IF( ze3wv >= 0._wp ) THEN   ;   zhj(ji,jj) = fsdept(ji,jj+1,ikv) + ze3wv    ! j-direction: case 1
-               ELSE                        ;   zhj(ji,jj) = fsdept(ji,jj  ,ikv) - ze3wv    ! -     -      case 2
-               ENDIF
-            END DO
-         END DO
-         !
-         CALL eos( zti, zhi, zri )        ! interpolated density from zti, ztj 
-         CALL eos( ztj, zhj, zrj )        ! at the partial step depth output in  zri, zrj 
-         !
-         DO jj = 1, jpjm1                 ! Gradient of density at the last level 
-            DO ji = 1, jpim1
-               iku = miku(ji,jj) ; ikup1 = miku(ji,jj) + 1
-               ikv = mikv(ji,jj) ; ikvp1 = mikv(ji,jj) + 1
-               ze3wu  = (gdepw_0(ji+1,jj,iku+1) - gdept_0(ji+1,jj,iku)) - (gdepw_0(ji,jj,iku+1) - gdept_0(ji,jj,iku))
-               ze3wv  = (gdepw_0(ji,jj+1,ikv+1) - gdept_0(ji,jj+1,ikv)) - (gdepw_0(ji,jj,ikv+1) - gdept_0(ji,jj,ikv))
-               IF( ze3wu >= 0._wp ) THEN
-                 pgzui  (ji,jj) = (fsde3w(ji+1,jj,iku) + ze3wu) - fsde3w(ji,jj,iku)
-                 pgrui  (ji,jj) = umask(ji,jj,iku)   * ( zri(ji,jj) - prd(ji,jj,iku) )          ! i: 1
-                 pmrui  (ji,jj) = umask(ji,jj,iku)   * ( zri(ji,jj) + prd(ji,jj,iku) )          ! i: 1 
-                 pge3rui(ji,jj) = umask(ji,jj,iku+1)                                                                  &
-                    &           * ( (fse3w(ji+1,jj,iku+1) - ze3wu) * (zri(ji,jj    ) + prd(ji+1,jj,iku+1) + 2._wp)   &
-                    &              - fse3w(ji  ,jj,iku+1)          * (prd(ji,jj,iku) + prd(ji  ,jj,iku+1) + 2._wp)   ) ! i: 1
-               ELSE
-                 pgzui  (ji,jj) = fsde3w(ji+1,jj,iku) - (fsde3w(ji,jj,iku) - ze3wu)
-                 pgrui  (ji,jj) = umask(ji,jj,iku)   * ( prd(ji+1,jj,iku) - zri(ji,jj) )      ! i: 2
-                 pmrui  (ji,jj) = umask(ji,jj,iku)   * ( prd(ji+1,jj,iku) + zri(ji,jj) )      ! i: 2
-                 pge3rui(ji,jj) = umask(ji,jj,iku+1)                                                                   &
-                    &           * (  fse3w(ji+1,jj,iku+1)          * (prd(ji+1,jj,iku) + prd(ji+1,jj,iku+1) + 2._wp)  &
-                    &              -(fse3w(ji  ,jj,iku+1) + ze3wu) * (zri(ji,jj      ) + prd(ji  ,jj,iku+1) + 2._wp)  )     ! i: 2
-               ENDIF
-               IF( ze3wv >= 0._wp ) THEN
-                 pgzvi  (ji,jj) = (fsde3w(ji,jj+1,ikv) + ze3wv) - fsde3w(ji,jj,ikv) 
-                 pgrvi  (ji,jj) = vmask(ji,jj,ikv)   * ( zrj(ji,jj  ) - prd(ji,jj,ikv) )        ! j: 1
-                 pmrvi  (ji,jj) = vmask(ji,jj,ikv)   * ( zrj(ji,jj  ) + prd(ji,jj,ikv) )        ! j: 1
-                 pge3rvi(ji,jj) = vmask(ji,jj,ikv+1)                                                                  & 
-                     &           * ( (fse3w(ji,jj+1,ikv+1) - ze3wv) * ( zrj(ji,jj    ) + prd(ji,jj+1,ikv+1) + 2._wp)  &
-                     &                - fse3w(ji,jj  ,ikv+1)          * ( prd(ji,jj,ikv) + prd(ji,jj  ,ikv+1) + 2._wp)  ) ! j: 1
-                                  ! + 2 due to the formulation in density and not in anomalie in hpg sco
-               ELSE
-                 pgzvi  (ji,jj) = fsde3w(ji,jj+1,ikv) - (fsde3w(ji,jj,ikv) - ze3wv)
-                 pgrvi  (ji,jj) = vmask(ji,jj,ikv)   * ( prd(ji,jj+1,ikv) - zrj(ji,jj) )     ! j: 2
-                 pmrvi  (ji,jj) = vmask(ji,jj,ikv)   * ( prd(ji,jj+1,ikv) + zrj(ji,jj) )     ! j: 2
-                 pge3rvi(ji,jj) = vmask(ji,jj,ikv+1)                                                                   &
-                    &           * (  fse3w(ji,jj+1,ikv+1)          * ( prd(ji,jj+1,ikv) + prd(ji,jj+1,ikv+1) + 2._wp) &
-                    &              -(fse3w(ji,jj  ,ikv+1) + ze3wv) * ( zrj(ji,jj      ) + prd(ji,jj  ,ikv+1) + 2._wp) )  ! j: 2
-               ENDIF
-            END DO
-         END DO
-         CALL lbc_lnk( pgrui   , 'U', -1. )   ;   CALL lbc_lnk( pgrvi   , 'V', -1. )   ! Lateral boundary conditions
-         CALL lbc_lnk( pmrui   , 'U',  1. )   ;   CALL lbc_lnk( pmrvi   , 'V',  1. )   ! Lateral boundary conditions
-         CALL lbc_lnk( pgzui   , 'U', -1. )   ;   CALL lbc_lnk( pgzvi   , 'V', -1. )   ! Lateral boundary conditions
-         CALL lbc_lnk( pge3rui , 'U', -1. )   ;   CALL lbc_lnk( pge3rvi , 'V', -1. )   ! Lateral boundary conditions
+               iku = miku(ji,jj) 
+               ikv = mikv(ji,jj) 
+               ze3wu  =  gdept_n(ji,jj,iku) - gdept_n(ji+1,jj,iku)
+               ze3wv  =  gdept_n(ji,jj,ikv) - gdept_n(ji,jj+1,ikv) 
+
+               IF( ze3wu >= 0._wp ) THEN ; pgrui(ji,jj) = ssumask(ji,jj) * ( zri(ji  ,jj      ) - prd(ji,jj,iku) ) ! i: 1
+               ELSE                      ; pgrui(ji,jj) = ssumask(ji,jj) * ( prd(ji+1,jj  ,iku) - zri(ji,jj    ) ) ! i: 2
+               ENDIF
+               IF( ze3wv >= 0._wp ) THEN ; pgrvi(ji,jj) = ssvmask(ji,jj) * ( zrj(ji  ,jj      ) - prd(ji,jj,ikv) ) ! j: 1
+               ELSE                      ; pgrvi(ji,jj) = ssvmask(ji,jj) * ( prd(ji  ,jj+1,ikv) - zrj(ji,jj    ) ) ! j: 2
+               ENDIF
+
+            END DO
+         END DO
+         CALL lbc_lnk( pgrui   , 'U', -1. ); CALL lbc_lnk( pgrvi   , 'V', -1. )   ! Lateral boundary conditions
          !
       END IF  
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trd_oce.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trd_oce.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trd_oce.F90	(revision 6140)
@@ -73,5 +73,5 @@
    !
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trddyn.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trddyn.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trddyn.F90	(revision 6140)
@@ -36,5 +36,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -143,6 +142,6 @@
                               !                                    ! wind stress trends
                               CALL wrk_alloc( jpi, jpj, z2dx, z2dy )
-                              z2dx(:,:) = ( utau_b(:,:) + utau(:,:) ) / ( fse3u(:,:,1) * rau0 )
-                              z2dy(:,:) = ( vtau_b(:,:) + vtau(:,:) ) / ( fse3v(:,:,1) * rau0 )
+                              z2dx(:,:) = ( utau_b(:,:) + utau(:,:) ) / ( e3u_n(:,:,1) * rau0 )
+                              z2dy(:,:) = ( vtau_b(:,:) + vtau(:,:) ) / ( e3v_n(:,:,1) * rau0 )
                               CALL iom_put( "utrd_tau", z2dx )
                               CALL iom_put( "vtrd_tau", z2dy )
@@ -161,6 +160,6 @@
                               	         ikbu = mbku(ji,jj)          ! deepest ocean u- & v-levels
                                           ikbv = mbkv(ji,jj)
-                                          z3dx(ji,jj,jk) = bfrua(ji,jj) * un(ji,jj,ikbu) / fse3u(ji,jj,ikbu)
-                                          z3dy(ji,jj,jk) = bfrva(ji,jj) * vn(ji,jj,ikbv) / fse3v(ji,jj,ikbv)
+                                          z3dx(ji,jj,jk) = bfrua(ji,jj) * un(ji,jj,ikbu) / e3u_n(ji,jj,ikbu)
+                                          z3dy(ji,jj,jk) = bfrva(ji,jj) * vn(ji,jj,ikbv) / e3v_n(ji,jj,ikbv)
                               	      END DO
                               	   END DO
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdglo.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdglo.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdglo.F90	(revision 6140)
@@ -52,5 +52,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
 #  include "zdfddm_substitute.h90"
@@ -92,5 +91,5 @@
       	      DO jj = 1, jpj
       	         DO ji = 1, jpi        
-      	            zvm = e1e2t(ji,jj) * fse3t(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+      	            zvm = e1e2t(ji,jj) * e3t_n(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
       	            zvt = ptrdx(ji,jj,jk) * zvm
       	            zvs = ptrdy(ji,jj,jk) * zvm
@@ -103,9 +102,9 @@
             END DO
             !                       ! linear free surface: diagnose advective flux trough the fixed k=1 w-surface
-            IF( .NOT.lk_vvl .AND. ktrd == jptra_zad ) THEN  
-               tmo(jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_tem) * e1e2t(:,:) )
-               smo(jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_sal) * e1e2t(:,:)  )
-               t2 (jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_tem) * tsn(:,:,1,jp_tem) * e1e2t(:,:)  )
-               s2 (jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_sal) * tsn(:,:,1,jp_sal) * e1e2t(:,:)  )
+            IF( ln_linssh .AND. ktrd == jptra_zad ) THEN  
+               tmo(jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_tem) * e1e2t(:,:) * tmask_i(:,:) )
+               smo(jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_sal) * e1e2t(:,:) * tmask_i(:,:)  )
+               t2 (jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_tem) * tsn(:,:,1,jp_tem) * e1e2t(:,:) * tmask_i(:,:)  )
+               s2 (jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_sal) * tsn(:,:,1,jp_sal) * e1e2t(:,:) * tmask_i(:,:)  )
             ENDIF
             !
@@ -126,7 +125,7 @@
                   DO ji = 1, jpim1
                      zvt = ptrdx(ji,jj,jk) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)   &
-                        &                  * e1u    (ji  ,jj  ) * e2u    (ji,jj) * fse3u(ji,jj,jk)
+                        &                  * e1u    (ji  ,jj  ) * e2u    (ji,jj) * e3u_n(ji,jj,jk)
                      zvs = ptrdy(ji,jj,jk) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)   &
-                        &                  * e1v    (ji  ,jj  ) * e2v    (ji,jj) * fse3u(ji,jj,jk)
+                        &                  * e1v    (ji  ,jj  ) * e2v    (ji,jj) * e3u_n(ji,jj,jk)
                      umo(ktrd) = umo(ktrd) + zvt
                      vmo(ktrd) = vmo(ktrd) + zvs
@@ -143,5 +142,5 @@
                         &                       * z1_2rau0 * e1u    (ji  ,jj  ) * e2u    (ji,jj)
                      zvs = ( vtau_b(ji,jj) + vtau(ji,jj) ) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)   &
-                        &                       * z1_2rau0 * e1v    (ji  ,jj  ) * e2v    (ji,jj) * fse3u(ji,jj,jk)
+                        &                       * z1_2rau0 * e1v    (ji  ,jj  ) * e2v    (ji,jj) * e3u_n(ji,jj,jk)
                      umo(jpdyn_tau) = umo(jpdyn_tau) + zvt
                      vmo(jpdyn_tau) = vmo(jpdyn_tau) + zvs
@@ -225,6 +224,6 @@
             DO jj = 1, jpjm1
                DO ji = 1, jpim1
-                  zkx(ji,jj,jk) = zcof * e2u(ji,jj) * fse3u(ji,jj,jk) * un(ji,jj,jk) * ( rhop(ji,jj,jk) + rhop(ji+1,jj,jk) )
-                  zky(ji,jj,jk) = zcof * e1v(ji,jj) * fse3v(ji,jj,jk) * vn(ji,jj,jk) * ( rhop(ji,jj,jk) + rhop(ji,jj+1,jk) )
+                  zkx(ji,jj,jk) = zcof * e2u(ji,jj) * e3u_n(ji,jj,jk) * un(ji,jj,jk) * ( rhop(ji,jj,jk) + rhop(ji+1,jj,jk) )
+                  zky(ji,jj,jk) = zcof * e1v(ji,jj) * e3v_n(ji,jj,jk) * vn(ji,jj,jk) * ( rhop(ji,jj,jk) + rhop(ji,jj+1,jk) )
                END DO
             END DO
@@ -237,5 +236,5 @@
                      &                 + zkx(ji,jj,jk) - zkx(ji-1,jj  ,jk  )               &
                      &                 + zky(ji,jj,jk) - zky(ji  ,jj-1,jk  )   )           &
-                     &              / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) ) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+                     &              / ( e1e2t(ji,jj) * e3t_n(ji,jj,jk) ) * tmask(ji,jj,jk) * tmask_i(ji,jj)
                END DO
             END DO
@@ -246,5 +245,5 @@
          peke = 0._wp
          DO jk = 1, jpkm1
-            peke = peke + SUM( zkepe(:,:,jk) * fsdept(:,:,jk) * e1e2t(:,:) * fse3t(:,:,jk) )
+            peke = peke + SUM( zkepe(:,:,jk) * gdept_n(:,:,jk) * e1e2t(:,:) * e3t_n(:,:,jk) )
          END DO
          peke = grav * peke
@@ -530,5 +529,5 @@
       tvolt = 0._wp
       DO jk = 1, jpkm1
-         tvolt = tvolt + SUM( e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:) )
+         tvolt = tvolt + SUM( e1e2t(:,:) * e3t_n(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:) )
       END DO
       IF( lk_mpp )   CALL mpp_sum( tvolt )   ! sum over the global domain
@@ -547,6 +546,6 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               tvolu = tvolu + e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)
-               tvolv = tvolv + e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)
+               tvolu = tvolu + e1u(ji,jj) * e2u(ji,jj) * e3u_n(ji,jj,jk) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)
+               tvolv = tvolv + e1v(ji,jj) * e2v(ji,jj) * e3v_n(ji,jj,jk) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)
             END DO
          END DO
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdini.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdini.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdini.F90	(revision 6140)
@@ -26,5 +26,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -91,5 +90,5 @@
 !!gm end
       !
-      IF( lk_vvl .AND. ( l_trdtra .OR. l_trddyn ) )  CALL ctl_stop( 'trend diagnostics with variable volume not validated' )
+      IF( .NOT.ln_linssh .AND. ( l_trdtra .OR. l_trddyn ) )  CALL ctl_stop( 'trend diagnostics with variable volume not validated' )
       
 !!gm  : Potential BUG : 3D output only for vector invariant form!  add a ctl_stop or code the flux form case
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdken.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdken.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdken.F90	(revision 6140)
@@ -41,5 +41,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -94,12 +93,10 @@
       CALL lbc_lnk( putrd, 'U', -1. )   ;   CALL lbc_lnk( pvtrd, 'V', -1. )      ! lateral boundary conditions
       !
-      IF ( lk_vvl .AND. kt /= nkstp ) THEN   ! Variable volume: set box volume at the 1st call of kt time step
-         nkstp = kt
-         DO jk = 1, jpkm1
-            bu   (:,:,jk) =           e1e2u(:,:) * fse3u_n(:,:,jk)
-            bv   (:,:,jk) =           e1e2v(:,:) * fse3v_n(:,:,jk)
-            r1_bt(:,:,jk) = 1._wp / ( e1e2t(:,:) * fse3t_n(:,:,jk) ) * tmask(:,:,jk)
-         END DO
-      ENDIF
+      nkstp = kt
+      DO jk = 1, jpkm1
+         bu   (:,:,jk) =    e1e2u(:,:) * e3u_n(:,:,jk)
+         bv   (:,:,jk) =    e1e2v(:,:) * e3v_n(:,:,jk)
+         r1_bt(:,:,jk) = r1_e1e2t(:,:) / e3t_n(:,:,jk) * tmask(:,:,jk)
+      END DO
       !
       zke(:,:,jpk) = 0._wp
@@ -118,26 +115,26 @@
       !
       SELECT CASE( ktrd )
-         CASE( jpdyn_hpg )   ;   CALL iom_put( "ketrd_hpg", zke )    ! hydrostatic pressure gradient
-         CASE( jpdyn_spg )   ;   CALL iom_put( "ketrd_spg", zke )    ! surface pressure gradient
-         CASE( jpdyn_pvo )   ;   CALL iom_put( "ketrd_pvo", zke )    ! planetary vorticity
-         CASE( jpdyn_rvo )   ;   CALL iom_put( "ketrd_rvo", zke )    ! relative  vorticity     (or metric term)
-         CASE( jpdyn_keg )   ;   CALL iom_put( "ketrd_keg", zke )    ! Kinetic Energy gradient (or had)
-         CASE( jpdyn_zad )   ;   CALL iom_put( "ketrd_zad", zke )    ! vertical   advection
-         CASE( jpdyn_ldf )   ;   CALL iom_put( "ketrd_ldf", zke )    ! lateral diffusion
-         CASE( jpdyn_zdf )   ;   CALL iom_put( "ketrd_zdf", zke )    ! vertical diffusion 
-                                 !                                   ! wind stress trends
+         CASE( jpdyn_hpg )   ;   CALL iom_put( "ketrd_hpg"   , zke )    ! hydrostatic pressure gradient
+         CASE( jpdyn_spg )   ;   CALL iom_put( "ketrd_spg"   , zke )    ! surface pressure gradient
+         CASE( jpdyn_pvo )   ;   CALL iom_put( "ketrd_pvo"   , zke )    ! planetary vorticity
+         CASE( jpdyn_rvo )   ;   CALL iom_put( "ketrd_rvo"   , zke )    ! relative  vorticity     (or metric term)
+         CASE( jpdyn_keg )   ;   CALL iom_put( "ketrd_keg"   , zke )    ! Kinetic Energy gradient (or had)
+         CASE( jpdyn_zad )   ;   CALL iom_put( "ketrd_zad"   , zke )    ! vertical   advection
+         CASE( jpdyn_ldf )   ;   CALL iom_put( "ketrd_ldf"   , zke )    ! lateral diffusion
+         CASE( jpdyn_zdf )   ;   CALL iom_put( "ketrd_zdf"   , zke )    ! vertical diffusion 
+         !                   !                                          ! wind stress trends
                                  CALL wrk_alloc( jpi, jpj, z2dx, z2dy, zke2d )
-                           z2dx(:,:) = un(:,:,1) * ( utau_b(:,:) + utau(:,:) ) * e1u(:,:) * e2u(:,:) * umask(:,:,1)
-                           z2dy(:,:) = vn(:,:,1) * ( vtau_b(:,:) + vtau(:,:) ) * e1v(:,:) * e2v(:,:) * vmask(:,:,1)
+                           z2dx(:,:) = un(:,:,1) * ( utau_b(:,:) + utau(:,:) ) * e1e2u(:,:) * umask(:,:,1)
+                           z2dy(:,:) = vn(:,:,1) * ( vtau_b(:,:) + vtau(:,:) ) * e1e2v(:,:) * vmask(:,:,1)
                            zke2d(1,:) = 0._wp   ;   zke2d(:,1) = 0._wp
                            DO jj = 2, jpj
                               DO ji = 2, jpi
-                                 zke2d(ji,jj) = 0.5_wp * (   z2dx(ji,jj) + z2dx(ji-1,jj)   &
-                                 &                         + z2dy(ji,jj) + z2dy(ji,jj-1)   ) * r1_bt(ji,jj,1)
+                                 zke2d(ji,jj) = r1_rau0 * 0.5_wp * (   z2dx(ji,jj) + z2dx(ji-1,jj)   &
+                                 &                                   + z2dy(ji,jj) + z2dy(ji,jj-1)   ) * r1_bt(ji,jj,1)
                               END DO
                            END DO
-                                 CALL iom_put( "ketrd_tau", zke2d )
+                                 CALL iom_put( "ketrd_tau"   , zke2d )  ! 
                                  CALL wrk_dealloc( jpi, jpj     , z2dx, z2dy, zke2d )
-         CASE( jpdyn_bfr )   ;   CALL iom_put( "ketrd_bfr", zke )    ! bottom friction (explicit case) 
+         CASE( jpdyn_bfr )   ;   CALL iom_put( "ketrd_bfr"   , zke )    ! bottom friction (explicit case) 
 !!gm TO BE DONE properly
 !!gm only valid if ln_bfrimp=F otherwise the bottom stress as to be recomputed at the end of the computation....
@@ -158,8 +155,8 @@
 !               END DO
 !            END DO
-!                              CALL iom_put( "ketrd_bfr", zke2d )    ! bottom friction (explicit case)
+!                                    CALL iom_put( "ketrd_bfr"  , zke2d )   ! bottom friction (explicit case)
 !         ENDIF
 !!gm end
-         CASE( jpdyn_atf )   ;   CALL iom_put( "ketrd_atf", zke )    ! asselin filter trends 
+         CASE( jpdyn_atf )   ;   CALL iom_put( "ketrd_atf"   , zke )    ! asselin filter trends 
 !! a faire !!!!  idee changer dynnxt pour avoir un appel a jpdyn_bfr avant le swap !!!
 !! reflechir a une possible sauvegarde du "vrai" un,vn pour le calcul de atf....
@@ -170,6 +167,6 @@
 !                  ikbu = mbku(ji,jj)          ! deepest ocean u- & v-levels
 !                  ikbv = mbkv(ji,jj)
-!                  z2dx(ji,jj) = un(ji,jj,ikbu) * bfrua(ji,jj) * un(ji,jj,ikbu) / fse3u(ji,jj,ikbu)
-!                  z2dy(ji,jj) = un(ji,jj,ikbu) * bfrva(ji,jj) * vn(ji,jj,ikbv) / fse3v(ji,jj,ikbv)
+!                  z2dx(ji,jj) = un(ji,jj,ikbu) * bfrua(ji,jj) * un(ji,jj,ikbu) / e3u_n(ji,jj,ikbu)
+!                  z2dy(ji,jj) = un(ji,jj,ikbu) * bfrva(ji,jj) * vn(ji,jj,ikbv) / e3v_n(ji,jj,ikbv)
 !               END DO
 !            END DO
@@ -183,12 +180,11 @@
 !                              CALL iom_put( "ketrd_bfri", zke2d )
 !         ENDIF
-         CASE( jpdyn_ken )   ;   ! kinetic energy
-                           ! called in dynnxt.F90 before asselin time filter
-                           ! with putrd=ua and pvtrd=va
-                           zke(:,:,:) = 0.5_wp * zke(:,:,:)
-                           CALL iom_put( "KE", zke )
-                           !
-                           CALL ken_p2k( kt , zke )
-                           CALL iom_put( "ketrd_convP2K", zke )     ! conversion -rau*g*w
+         CASE( jpdyn_ken )   ;                                          ! kinetic energy
+                                 ! called in dynnxt.F90 before asselin time filter with putrd=ua and pvtrd=va
+                                 zke(:,:,:) = 0.5_wp * zke(:,:,:)
+                                 CALL iom_put( "KE", zke )
+                                 !
+                                 CALL ken_p2k( kt , zke )
+                                 CALL iom_put( "ketrd_convP2K", zke )     ! conversion -rau*g*w
          !
       END SELECT
@@ -225,9 +221,9 @@
       
       !  Surface value (also valid in partial step case)
-      zconv(:,:,1) = zcoef * ( 2._wp * rhd(:,:,1) ) * wn(:,:,1) * fse3w(:,:,1)
+      zconv(:,:,1) = zcoef * ( 2._wp * rhd(:,:,1) ) * wn(:,:,1) * e3w_n(:,:,1)
 
       ! interior value (2=<jk=<jpkm1)
       DO jk = 2, jpk
-         zconv(:,:,jk) = zcoef * ( rhd(:,:,jk) + rhd(:,:,jk-1) ) * wn(:,:,jk) * fse3w(:,:,jk)
+         zconv(:,:,jk) = zcoef * ( rhd(:,:,jk) + rhd(:,:,jk-1) ) * wn(:,:,jk) * e3w_n(:,:,jk)
       END DO
 
@@ -236,5 +232,5 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               zcoef = 0.5_wp / fse3t(ji,jj,jk)
+               zcoef = 0.5_wp / e3t_n(ji,jj,jk)
                pconv(ji,jj,jk) = zcoef * ( zconv(ji,jj,jk) + zconv(ji,jj,jk+1) ) * tmask(ji,jj,jk)
             END DO
@@ -264,15 +260,4 @@
       IF( trd_ken_alloc() /= 0 )   CALL ctl_stop('trd_ken_alloc: failed to allocate arrays')
       !
-!!gm      IF( .NOT. (ln_hpg_zco.OR.ln_hpg_zps) )   &
-!!gm         &   CALL ctl_stop('trd_ken_init : only full and partial cells are coded for conversion rate')
-      !
-      IF( .NOT.lk_vvl ) THEN      ! constant volume: bu, bv, 1/bt computed one for all
-         DO jk = 1, jpkm1
-            bu   (:,:,jk) =           e1e2u(:,:) * fse3u_n(:,:,jk)
-            bv   (:,:,jk) =           e1e2v(:,:) * fse3v_n(:,:,jk)
-            r1_bt(:,:,jk) = 1._wp / ( e1e2t(:,:) * fse3t_n(:,:,jk) )
-         END DO
-      ENDIF
-      !
    END SUBROUTINE trd_ken_init
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl.F90	(revision 6140)
@@ -30,5 +30,4 @@
    USE zdfddm          ! ocean vertical physics: double diffusion
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE diadimg         ! dimg direct access file format output
    USE trdmxl_rst      ! restart for diagnosing the ML trends
    !
@@ -49,6 +48,4 @@
 
    INTEGER ::   nkstp       ! current time step 
-
-
 
 !!gm  to be moved from trdmxl_oce
@@ -73,5 +70,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "zdfddm_substitute.h90"
    !!----------------------------------------------------------------------
@@ -126,5 +122,5 @@
             DO jj = 1,jpj
                DO ji = 1,jpi
-                  IF( jk - kmxln(ji,jj) < 0 )   wkx(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
+                  IF( jk - kmxln(ji,jj) < 0 )   wkx(ji,jj,jk) = e3t_n(ji,jj,jk) * tmask(ji,jj,jk)
                END DO
             END DO
@@ -298,5 +294,5 @@
       !! 
       !! ** Purpose :  Compute and cumulate the mixed layer trends over an analysis
-      !!               period, and write NetCDF (or dimg) outputs.
+      !!               period, and write NetCDF outputs.
       !!
       !! ** Method/usage :
@@ -349,8 +345,4 @@
       REAL(wp), POINTER, DIMENSION(:,:  ) ::  ztmltot2, zsmltot2, ztmlres2, zsmlres2, ztmlatf2, zsmlatf2, ztmltrdm2, zsmltrdm2  
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztmltrd2, zsmltrd2   ! only needed for mean diagnostics
-#if defined key_dimgout
-      INTEGER ::  iyear,imon,iday
-      CHARACTER(LEN=80) :: cltext, clmode
-#endif
       !!----------------------------------------------------------------------
   
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl_rst.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl_rst.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl_rst.F90	(revision 6140)
@@ -62,5 +62,4 @@
             WRITE(numout,*)
             SELECT CASE ( jprstlib )
-            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ocean restart_mxl binary file: '//clname
             CASE DEFAULT         ;   WRITE(numout,*) '             open ocean restart_mxl NetCDF file: '//clname
             END SELECT
@@ -147,14 +146,4 @@
       clpath = TRIM(cn_ocerst_indir)
       IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
-
-      IF ( jprstlib == jprstdimg ) THEN
-         ! eventually read netcdf file (monobloc)  for restarting on different number of processors
-         ! if {cn_trdrst_in}.nc exists, then set jlibalt to jpnf90
-         INQUIRE( FILE = TRIM(clpath)//TRIM(cn_trdrst_in)//'.nc', EXIST = llok )
-         IF ( llok ) THEN   ;   jlibalt = jpnf90   
-         ELSE               ;   jlibalt = jprstlib   
-         ENDIF
-      ENDIF
-
       CALL iom_open( TRIM(clpath)//TRIM(cn_trdrst_in), inum, kiolib = jlibalt ) 
 
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdpen.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdpen.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdpen.F90	(revision 6140)
@@ -37,5 +37,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
@@ -79,5 +78,5 @@
       zpe(:,:,:) = 0._wp
       !
-      IF ( kt /= nkstp ) THEN   ! full eos: set partial derivatives at the 1st call of kt time step
+      IF( kt /= nkstp ) THEN     ! full eos: set partial derivatives at the 1st call of kt time step
          nkstp = kt
          CALL eos_pen( tsn, rab_PE, zpe )
@@ -97,10 +96,10 @@
       CASE ( jptra_yad  )   ;   CALL iom_put( "petrd_yad", zpe )   ! merid.   advection
       CASE ( jptra_zad  )   ;   CALL iom_put( "petrd_zad", zpe )   ! vertical advection
-                                IF( .NOT.lk_vvl ) THEN                   ! cst volume : adv flux through z=0 surface
+                                IF( ln_linssh ) THEN                   ! cst volume : adv flux through z=0 surface
                                    CALL wrk_alloc( jpi, jpj, z2d )
                                    z2d(:,:) = wn(:,:,1) * ( &
                                      &   - ( rab_n(:,:,1,jp_tem) + rab_pe(:,:,1,jp_tem) ) * tsn(:,:,1,jp_tem)    &
                                      &   + ( rab_n(:,:,1,jp_sal) + rab_pe(:,:,1,jp_sal) ) * tsn(:,:,1,jp_sal)    &
-                                     & ) / fse3t(:,:,1)
+                                     & ) / e3t_n(:,:,1)
                                    CALL iom_put( "petrd_sad" , z2d )
                                    CALL wrk_dealloc( jpi, jpj, z2d )
@@ -116,9 +115,9 @@
       CASE ( jptra_bbc  )   ;   CALL iom_put( "petrd_bbc" , zpe )   ! bottom bound cond (geoth flux)
       CASE ( jptra_atf  )   ;   CALL iom_put( "petrd_atf" , zpe )   ! asselin time filter (last trend)
-                                !IF( .NOT.lk_vvl ) THEN                   ! cst volume : ssh term (otherwise include in e3t variation)
+                                !IF( ln_linssh ) THEN                   ! cst volume : ssh term (otherwise include in e3t variation)
                                 !   CALL wrk_alloc( jpi, jpj, z2d )
                                 !   z2d(:,:) = ( ssha(:,:) - sshb(:,:) )                 &
                                 !      &     * (   dPE_dt(:,:,1) * tsn(:,:,1,jp_tem)    &
-                                !      &         + dPE_ds(:,:,1) * tsn(:,:,1,jp_sal)  ) / ( fse3t(:,:,1) * pdt )
+                                !      &         + dPE_ds(:,:,1) * tsn(:,:,1,jp_sal)  ) / ( e3t_n(:,:,1) * pdt )
                                 !   CALL iom_put( "petrd_sad" , z2d )
                                 !   CALL wrk_dealloc( jpi, jpj, z2d )
@@ -151,5 +150,5 @@
       rab_pe(:,:,:,:) = 0._wp
       !
-      IF ( lk_vvl               )   CALL ctl_stop('trd_pen_init : PE trends not coded for variable volume')
+      IF( .NOT.ln_linssh )   CALL ctl_stop('trd_pen_init : PE trends not coded for variable volume')
       !
       nkstp     = nit000 - 1
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 6140)
@@ -38,10 +38,7 @@
    PUBLIC   trd_tra   ! called by all tra_... modules
 
-   REAL(wp) ::   r2dt   ! time-step, = 2 rdttra except at nit000 (=rdttra) if neuler=0
-
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   trdtx, trdty, trdt   ! use to store the temperature trends
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
@@ -130,12 +127,12 @@
             zwt(:,:,jpk) = 0._wp   ;   zws(:,:,jpk) = 0._wp
             DO jk = 2, jpk
-               zwt(:,:,jk) =   avt(:,:,jk) * ( tsa(:,:,jk-1,jp_tem) - tsa(:,:,jk,jp_tem) ) / fse3w(:,:,jk) * tmask(:,:,jk)
-               zws(:,:,jk) = fsavs(:,:,jk) * ( tsa(:,:,jk-1,jp_sal) - tsa(:,:,jk,jp_sal) ) / fse3w(:,:,jk) * tmask(:,:,jk)
+               zwt(:,:,jk) =   avt(:,:,jk) * ( tsa(:,:,jk-1,jp_tem) - tsa(:,:,jk,jp_tem) ) / e3w_n(:,:,jk) * tmask(:,:,jk)
+               zws(:,:,jk) = fsavs(:,:,jk) * ( tsa(:,:,jk-1,jp_sal) - tsa(:,:,jk,jp_sal) ) / e3w_n(:,:,jk) * tmask(:,:,jk)
             END DO
             !
             ztrdt(:,:,jpk) = 0._wp   ;   ztrds(:,:,jpk) = 0._wp
             DO jk = 1, jpkm1
-               ztrdt(:,:,jk) = ( zwt(:,:,jk) - zwt(:,:,jk+1) ) / fse3t(:,:,jk)
-               ztrds(:,:,jk) = ( zws(:,:,jk) - zws(:,:,jk+1) ) / fse3t(:,:,jk) 
+               ztrdt(:,:,jk) = ( zwt(:,:,jk) - zwt(:,:,jk+1) ) / e3t_n(:,:,jk)
+               ztrds(:,:,jk) = ( zws(:,:,jk) - zws(:,:,jk+1) ) / e3t_n(:,:,jk) 
             END DO
             CALL trd_tra_mng( ztrdt, ztrds, jptra_zdfp, kt )  
@@ -207,5 +204,5 @@
                ptrd(ji,jj,jk) = - (     pf (ji,jj,jk) - pf (ji-ii,jj-ij,jk-ik)                        &
                  &                  - ( pun(ji,jj,jk) - pun(ji-ii,jj-ij,jk-ik) ) * ptn(ji,jj,jk)  )   &
-                 &              / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )  * tmask(ji,jj,jk)
+                 &              * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk) * tmask(ji,jj,jk)
             END DO
          END DO
@@ -229,6 +226,6 @@
       !!----------------------------------------------------------------------
 
-      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (restart with Euler time stepping)
-      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdttra (leapfrog)
+      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdt (restart with Euler time stepping)
+      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdt (leapfrog)
       ENDIF
 
@@ -306,8 +303,8 @@
       CASE( jptra_zad  )   ;   CALL iom_put( "ttrd_zad" , ptrdx )        ! z- vertical   advection
                                CALL iom_put( "strd_zad" , ptrdy )
-                               IF( .NOT. lk_vvl ) THEN                   ! cst volume : adv flux through z=0 surface
+                               IF( ln_linssh ) THEN                   ! cst volume : adv flux through z=0 surface
                                	 CALL wrk_alloc( jpi, jpj, z2dx, z2dy )
-                                  z2dx(:,:) = wn(:,:,1) * tsn(:,:,1,jp_tem) / fse3t(:,:,1)
-                                  z2dy(:,:) = wn(:,:,1) * tsn(:,:,1,jp_sal) / fse3t(:,:,1)
+                                  z2dx(:,:) = wn(:,:,1) * tsn(:,:,1,jp_tem) / e3t_n(:,:,1)
+                                  z2dy(:,:) = wn(:,:,1) * tsn(:,:,1,jp_sal) / e3t_n(:,:,1)
                                   CALL iom_put( "ttrd_sad", z2dx )
                                   CALL iom_put( "strd_sad", z2dy )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 6140)
@@ -57,5 +57,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -85,5 +84,5 @@
       !! 
       !! ** Purpose :  computation of cumulated trends over analysis period
-      !!               and make outputs (NetCDF or DIMG format)
+      !!               and make outputs (NetCDF format)
       !!----------------------------------------------------------------------
       REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   putrd, pvtrd   ! U and V trends 
@@ -109,6 +108,6 @@
          DO jj = 2, jpjm1                                                             ! wind stress trends
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               ztswu(ji,jj) = 0.5 * ( utau_b(ji,jj) + utau(ji,jj) ) / ( fse3u(ji,jj,1) * rau0 )
-               ztswv(ji,jj) = 0.5 * ( vtau_b(ji,jj) + vtau(ji,jj) ) / ( fse3v(ji,jj,1) * rau0 )
+               ztswu(ji,jj) = 0.5 * ( utau_b(ji,jj) + utau(ji,jj) ) / ( e3u_n(ji,jj,1) * rau0 )
+               ztswv(ji,jj) = 0.5 * ( vtau_b(ji,jj) + vtau(ji,jj) ) / ( e3v_n(ji,jj,1) * rau0 )
             END DO
          END DO
@@ -183,18 +182,18 @@
                ikbu = mbkv(ji,jj)
                ikbv = mbkv(ji,jj)            
-               zudpvor(ji,jj) = putrdvor(ji,jj) * fse3u(ji,jj,ikbu) * e1u(ji,jj) * umask(ji,jj,ikbu)
-               zvdpvor(ji,jj) = pvtrdvor(ji,jj) * fse3v(ji,jj,ikbv) * e2v(ji,jj) * vmask(ji,jj,ikbv)
+               zudpvor(ji,jj) = putrdvor(ji,jj) * e3u_n(ji,jj,ikbu) * e1u(ji,jj) * umask(ji,jj,ikbu)
+               zvdpvor(ji,jj) = pvtrdvor(ji,jj) * e3v_n(ji,jj,ikbv) * e2v(ji,jj) * vmask(ji,jj,ikbv)
             END DO
          END DO
          !
       CASE( jpvor_swf )        ! wind stress
-         zudpvor(:,:) = putrdvor(:,:) * fse3u(:,:,1) * e1u(:,:) * umask(:,:,1)
-         zvdpvor(:,:) = pvtrdvor(:,:) * fse3v(:,:,1) * e2v(:,:) * vmask(:,:,1)
+         zudpvor(:,:) = putrdvor(:,:) * e3u_n(:,:,1) * e1u(:,:) * umask(:,:,1)
+         zvdpvor(:,:) = pvtrdvor(:,:) * e3v_n(:,:,1) * e2v(:,:) * vmask(:,:,1)
          !
       END SELECT
 
       ! Average except for Beta.V
-      zudpvor(:,:) = zudpvor(:,:) * hur(:,:)
-      zvdpvor(:,:) = zvdpvor(:,:) * hvr(:,:)
+      zudpvor(:,:) = zudpvor(:,:) * r1_hu_n(:,:)
+      zvdpvor(:,:) = zvdpvor(:,:) * r1_hv_n(:,:)
    
       ! Curl
@@ -270,6 +269,6 @@
       ! putrdvor and pvtrdvor terms
       DO jk = 1,jpk
-        zudpvor(:,:) = zudpvor(:,:) + putrdvor(:,:,jk) * fse3u(:,:,jk) * e1u(:,:) * umask(:,:,jk)
-        zvdpvor(:,:) = zvdpvor(:,:) + pvtrdvor(:,:,jk) * fse3v(:,:,jk) * e2v(:,:) * vmask(:,:,jk)
+        zudpvor(:,:) = zudpvor(:,:) + putrdvor(:,:,jk) * e3u_n(:,:,jk) * e1u(:,:) * umask(:,:,jk)
+        zvdpvor(:,:) = zvdpvor(:,:) + pvtrdvor(:,:,jk) * e3v_n(:,:,jk) * e2v(:,:) * vmask(:,:,jk)
       END DO
 
@@ -286,10 +285,10 @@
          END DO
          ! Average of the Curl and Surface mask
-         vortrd(:,:,jpvor_bev) = vortrd(:,:,jpvor_bev) * hur(:,:) * fmask(:,:,1)
+         vortrd(:,:,jpvor_bev) = vortrd(:,:,jpvor_bev) * r1_hu_n(:,:) * fmask(:,:,1)
       ENDIF
       !
       ! Average 
-      zudpvor(:,:) = zudpvor(:,:) * hur(:,:)
-      zvdpvor(:,:) = zvdpvor(:,:) * hvr(:,:)
+      zudpvor(:,:) = zudpvor(:,:) * r1_hu_n(:,:)
+      zvdpvor(:,:) = zvdpvor(:,:) * r1_hv_n(:,:)
       !
       ! Curl
@@ -318,5 +317,5 @@
       !! 
       !! ** Purpose :  computation of cumulated trends over analysis period
-      !!               and make outputs (NetCDF or DIMG format)
+      !!               and make outputs (NetCDF format)
       !!----------------------------------------------------------------------
       INTEGER                   , INTENT(in   ) ::   kt             ! time step
@@ -351,10 +350,10 @@
       ! Vertically averaged velocity
       DO jk = 1, jpk - 1
-         zun(:,:) = zun(:,:) + e1u(:,:) * un(:,:,jk) * fse3u(:,:,jk)
-         zvn(:,:) = zvn(:,:) + e2v(:,:) * vn(:,:,jk) * fse3v(:,:,jk)
+         zun(:,:) = zun(:,:) + e1u(:,:) * un(:,:,jk) * e3u_n(:,:,jk)
+         zvn(:,:) = zvn(:,:) + e2v(:,:) * vn(:,:,jk) * e3v_n(:,:,jk)
       END DO
  
-      zun(:,:) = zun(:,:) * hur(:,:)
-      zvn(:,:) = zvn(:,:) * hvr(:,:)
+      zun(:,:) = zun(:,:) * r1_hu_n(:,:)
+      zvn(:,:) = zvn(:,:) * r1_hv_n(:,:)
 
       ! Curl
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfbfr.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfbfr.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfbfr.F90	(revision 6140)
@@ -56,5 +56,4 @@
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 4.0 , NEMO Consortium (2011)
@@ -111,5 +110,5 @@
          CALL wrk_alloc( jpi, jpj, zbfrt, ztfrt )
 
-         IF ( ln_loglayer.AND.lk_vvl ) THEN ! "log layer" bottom friction coefficient
+         IF ( ln_loglayer.AND. .NOT.ln_linssh ) THEN ! "log layer" bottom friction coefficient
 
             DO jj = 1, jpj
@@ -117,5 +116,5 @@
                   ikbt = mbkt(ji,jj)
 !! JC: possible WAD implementation should modify line below if layers vanish
-                  ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * fse3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
+                  ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * e3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
                   zbfrt(ji,jj) = MAX(bfrcoef2d(ji,jj), ztmp)
                   zbfrt(ji,jj) = MIN(zbfrt(ji,jj), rn_bfri2_max)
@@ -128,5 +127,5 @@
                      ikbt = mikt(ji,jj)
 ! JC: possible WAD implementation should modify line below if layers vanish
-                     ztmp = (1-tmask(ji,jj,1)) * ( vkarmn / LOG( 0.5_wp * fse3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
+                     ztmp = (1.-tmask(ji,jj,1)) * ( vkarmn / LOG( 0.5_wp * e3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
                      ztfrt(ji,jj) = MAX(tfrcoef2d(ji,jj), ztmp)
                      ztfrt(ji,jj) = MIN(ztfrt(ji,jj), rn_tfri2_max)
@@ -134,5 +133,5 @@
                END DO
             END IF
-         !   
+            !   
          ELSE
             zbfrt(:,:) = bfrcoef2d(:,:)
@@ -158,20 +157,20 @@
                ! in case of 2 cell water column, we assume each cell feels the top and bottom friction
                IF ( ln_isfcav ) THEN
-                  IF ( miku(ji,jj) + 1 .GE. mbku(ji,jj) ) THEN
+                  IF ( miku(ji,jj) + 1  >=  mbku(ji,jj) ) THEN
                      bfrua(ji,jj) = - 0.5_wp * ( ( zbfrt(ji,jj) + zbfrt(ji+1,jj  ) )   &
                                   &            + ( ztfrt(ji,jj) + ztfrt(ji+1,jj  ) ) ) &
                                   &          * zecu * (1._wp - umask(ji,jj,1))
-                  END IF
-                  IF ( mikv(ji,jj) + 1 .GE. mbkv(ji,jj) ) THEN
+                  ENDIF
+                  IF( mikv(ji,jj) + 1  >=  mbkv(ji,jj) ) THEN
                      bfrva(ji,jj) = - 0.5_wp * ( ( zbfrt(ji,jj) + zbfrt(ji  ,jj+1) )   &
                                   &            + ( ztfrt(ji,jj) + ztfrt(ji  ,jj+1) ) ) &
                                   &          * zecv * (1._wp - vmask(ji,jj,1))
-                  END IF
-               END IF
+                  ENDIF
+               ENDIF
             END DO
          END DO
          CALL lbc_lnk( bfrua, 'U', 1. )   ;   CALL lbc_lnk( bfrva, 'V', 1. )      ! Lateral boundary condition
 
-         IF ( ln_isfcav ) THEN
+         IF( ln_isfcav ) THEN
             DO jj = 2, jpjm1
                DO ji = 2, jpim1
@@ -371,9 +370,9 @@
          END IF
          !
-         IF ( ln_loglayer.AND.(.NOT.lk_vvl) ) THEN ! set "log layer" bottom friction once for all
+         IF( ln_loglayer.AND. ln_linssh ) THEN ! set "log layer" bottom friction once for all
             DO jj = 1, jpj
                DO ji = 1, jpi
                   ikbt = mbkt(ji,jj)
-                  ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * fse3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
+                  ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * e3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
                   bfrcoef2d(ji,jj) = MAX(bfrcoef2d(ji,jj), ztmp)
                   bfrcoef2d(ji,jj) = MIN(bfrcoef2d(ji,jj), rn_bfri2_max)
@@ -384,5 +383,5 @@
                   DO ji = 1, jpi
                      ikbt = mikt(ji,jj)
-                     ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * fse3t_n(ji,jj,ikbt) / rn_tfrz0 ))**2._wp
+                     ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * e3t_n(ji,jj,ikbt) / rn_tfrz0 ))**2._wp
                      tfrcoef2d(ji,jj) = MAX(tfrcoef2d(ji,jj), ztmp)
                      tfrcoef2d(ji,jj) = MIN(tfrcoef2d(ji,jj), rn_tfri2_max)
@@ -424,6 +423,6 @@
              ikbu = mbku(ji,jj)       ! deepest ocean level at u- and v-points
              ikbv = mbkv(ji,jj)
-             zfru = 0.5 * fse3u(ji,jj,ikbu) / rdt
-             zfrv = 0.5 * fse3v(ji,jj,ikbv) / rdt
+             zfru = 0.5 * e3u_n(ji,jj,ikbu) / rdt
+             zfrv = 0.5 * e3v_n(ji,jj,ikbv) / rdt
              IF( ABS( bfrcoef2d(ji,jj) ) > zfru ) THEN
                 IF( ln_ctl ) THEN
@@ -446,6 +445,6 @@
                 ikbu = miku(ji,jj)       ! 1st wet ocean level at u- and v-points
                 ikbv = mikv(ji,jj)
-                zfru = 0.5 * fse3u(ji,jj,ikbu) / rdt
-                zfrv = 0.5 * fse3v(ji,jj,ikbv) / rdt
+                zfru = 0.5 * e3u_n(ji,jj,ikbu) / rdt
+                zfrv = 0.5 * e3v_n(ji,jj,ikbv) / rdt
                 IF( ABS( tfrcoef2d(ji,jj) ) > zfru ) THEN
                    IF( ln_ctl ) THEN
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm.F90	(revision 6140)
@@ -44,5 +44,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -115,6 +114,6 @@
          DO jj = 1, jpj                                ! R=zrau = (alpha / beta) (dk[t] / dk[s])
             DO ji = 1, jpi
-               zrw =   ( fsdepw(ji,jj,jk  ) - fsdept(ji,jj,jk) )   &
-                  &  / ( fsdept(ji,jj,jk-1) - fsdept(ji,jj,jk) ) 
+               zrw =   ( gdepw_n(ji,jj,jk  ) - gdept_n(ji,jj,jk) )   &
+                  &  / ( gdept_n(ji,jj,jk-1) - gdept_n(ji,jj,jk) ) 
                !
                zaw = (  rab_n(ji,jj,jk,jp_tem) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_tem) * zrw  )  &
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfevd.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfevd.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfevd.F90	(revision 6140)
@@ -29,6 +29,4 @@
    PUBLIC   zdf_evd    ! called by step.F90
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 4.0 , NEMO Consortium (2011)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 6140)
@@ -102,5 +102,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -204,10 +203,8 @@
                avmu(ji,jj,jk) = avmu(ji,jj,jk) * ( un(ji,jj,jk-1) - un(ji,jj,jk) )   &
                   &                            * ( ub(ji,jj,jk-1) - ub(ji,jj,jk) )   &
-                  &                            / (  fse3uw_n(ji,jj,jk)               &
-                  &                            *    fse3uw_b(ji,jj,jk) )
+                  &                            / (  e3uw_n(ji,jj,jk) * e3uw_b(ji,jj,jk) )
                avmv(ji,jj,jk) = avmv(ji,jj,jk) * ( vn(ji,jj,jk-1) - vn(ji,jj,jk) )   &
                   &                            * ( vb(ji,jj,jk-1) - vb(ji,jj,jk) )   &
-                  &                            / (  fse3vw_n(ji,jj,jk)               &
-                  &                            *    fse3vw_b(ji,jj,jk) )
+                  &                            / (  e3vw_n(ji,jj,jk) * e3vw_b(ji,jj,jk) )
                eps(ji,jj,jk)  = rc03 * en(ji,jj,jk) * SQRT(en(ji,jj,jk)) / mxln(ji,jj,jk)
             END DO
@@ -226,6 +223,6 @@
             DO jj = 2, jpjm1 
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zup   = mxln(ji,jj,jk) * fsdepw(ji,jj,mbkt(ji,jj)+1)
-                  zdown = vkarmn * fsdepw(ji,jj,jk) * ( -fsdepw(ji,jj,jk) + fsdepw(ji,jj,mbkt(ji,jj)+1) )
+                  zup   = mxln(ji,jj,jk) * gdepw_n(ji,jj,mbkt(ji,jj)+1)
+                  zdown = vkarmn * gdepw_n(ji,jj,jk) * ( -gdepw_n(ji,jj,jk) + gdepw_n(ji,jj,mbkt(ji,jj)+1) )
                   zcoef = ( zup / MAX( zdown, rsmall ) )
                   zwall (ji,jj,jk) = ( 1._wp + re2 * zcoef*zcoef ) * tmask(ji,jj,jk)
@@ -284,9 +281,9 @@
                ! lower diagonal
                z_elem_a(ji,jj,jk) = zcof * ( avm  (ji,jj,jk  ) + avm  (ji,jj,jk-1) )   &
-                  &                      / ( fse3t(ji,jj,jk-1) * fse3w(ji,jj,jk  ) )
+                  &                      / ( e3t_n(ji,jj,jk-1) * e3w_n(ji,jj,jk  ) )
                !
                ! upper diagonal
                z_elem_c(ji,jj,jk) = zcof * ( avm  (ji,jj,jk+1) + avm  (ji,jj,jk  ) )   &
-                  &                      / ( fse3t(ji,jj,jk  ) * fse3w(ji,jj,jk) )
+                  &                      / ( e3t_n(ji,jj,jk  ) * e3w_n(ji,jj,jk) )
                !
                ! diagonal
@@ -320,5 +317,5 @@
       ! 
       ! One level below
-      en(:,:,2) = rc02r * ustars2(:,:) * (1._wp + rsbc_tke1 * ((zhsro(:,:)+fsdepw(:,:,2)) &
+      en(:,:,2) = rc02r * ustars2(:,:) * (1._wp + rsbc_tke1 * ((zhsro(:,:)+gdepw_n(:,:,2)) &
          &               / zhsro(:,:) )**(1.5_wp*ra_sf))**(2._wp/3._wp)
       en(:,:,2) = MAX(en(:,:,2), rn_emin )
@@ -341,9 +338,9 @@
       z_elem_b(:,:,2) = z_elem_b(:,:,2) +  z_elem_a(:,:,2) ! Remove z_elem_a from z_elem_b
       z_elem_a(:,:,2) = 0._wp
-      zkar(:,:)       = (rl_sf + (vkarmn-rl_sf)*(1.-exp(-rtrans*fsdept(:,:,1)/zhsro(:,:)) ))
+      zkar(:,:)       = (rl_sf + (vkarmn-rl_sf)*(1.-exp(-rtrans*gdept_n(:,:,1)/zhsro(:,:)) ))
       zflxs(:,:)      = rsbc_tke2 * ustars2(:,:)**1.5_wp * zkar(:,:) &
-          &                       * ((zhsro(:,:)+fsdept(:,:,1)) / zhsro(:,:) )**(1.5_wp*ra_sf)
-
-      en(:,:,2) = en(:,:,2) + zflxs(:,:)/fse3w(:,:,2)
+          &                       * ((zhsro(:,:)+gdept_n(:,:,1)) / zhsro(:,:) )**(1.5_wp*ra_sf)
+
+      en(:,:,2) = en(:,:,2) + zflxs(:,:)/e3w_n(:,:,2)
       !
       !
@@ -508,8 +505,8 @@
                ! lower diagonal
                z_elem_a(ji,jj,jk) = zcof * ( avm  (ji,jj,jk  ) + avm  (ji,jj,jk-1) )   &
-                  &                      / ( fse3t(ji,jj,jk-1) * fse3w(ji,jj,jk  ) )
+                  &                      / ( e3t_n(ji,jj,jk-1) * e3w_n(ji,jj,jk  ) )
                ! upper diagonal
                z_elem_c(ji,jj,jk) = zcof * ( avm  (ji,jj,jk+1) + avm  (ji,jj,jk  ) )   &
-                  &                      / ( fse3t(ji,jj,jk  ) * fse3w(ji,jj,jk) )
+                  &                      / ( e3t_n(ji,jj,jk  ) * e3w_n(ji,jj,jk) )
                ! diagonal
                z_elem_b(ji,jj,jk) = 1._wp - z_elem_a(ji,jj,jk) - z_elem_c(ji,jj,jk)  &
@@ -539,6 +536,6 @@
       !
       ! One level below
-      zkar(:,:)       = (rl_sf + (vkarmn-rl_sf)*(1._wp-exp(-rtrans*fsdepw(:,:,2)/zhsro(:,:) )))
-      zdep(:,:)       = (zhsro(:,:) + fsdepw(:,:,2)) * zkar(:,:)
+      zkar(:,:)       = (rl_sf + (vkarmn-rl_sf)*(1._wp-exp(-rtrans*gdepw_n(:,:,2)/zhsro(:,:) )))
+      zdep(:,:)       = (zhsro(:,:) + gdepw_n(:,:,2)) * zkar(:,:)
       psi (:,:,2)     = rc0**rpp * en(:,:,2)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
       z_elem_a(:,:,2) = 0._wp
@@ -561,11 +558,11 @@
       !
       ! Set psi vertical flux at the surface:
-      zkar(:,:) = rl_sf + (vkarmn-rl_sf)*(1._wp-exp(-rtrans*fsdept(:,:,1)/zhsro(:,:) )) ! Lengh scale slope
-      zdep(:,:) = ((zhsro(:,:) + fsdept(:,:,1)) / zhsro(:,:))**(rmm*ra_sf)
+      zkar(:,:) = rl_sf + (vkarmn-rl_sf)*(1._wp-exp(-rtrans*gdept_n(:,:,1)/zhsro(:,:) )) ! Lengh scale slope
+      zdep(:,:) = ((zhsro(:,:) + gdept_n(:,:,1)) / zhsro(:,:))**(rmm*ra_sf)
       zflxs(:,:) = (rnn + rsbc_tke1 * (rnn + rmm*ra_sf) * zdep(:,:))*(1._wp + rsbc_tke1*zdep(:,:))**(2._wp*rmm/3._wp-1_wp)
       zdep(:,:) =  rsbc_psi1 * (zwall_psi(:,:,1)*avm(:,:,1)+zwall_psi(:,:,2)*avm(:,:,2)) * &
-             & ustars2(:,:)**rmm * zkar(:,:)**rnn * (zhsro(:,:) + fsdept(:,:,1))**(rnn-1.)
+             & ustars2(:,:)**rmm * zkar(:,:)**rnn * (zhsro(:,:) + gdept_n(:,:,1))**(rnn-1.)
       zflxs(:,:) = zdep(:,:) * zflxs(:,:)
-      psi(:,:,2) = psi(:,:,2) + zflxs(:,:) / fse3w(:,:,2)
+      psi(:,:,2) = psi(:,:,2) + zflxs(:,:) / e3w_n(:,:,2)
 
       !   
@@ -593,5 +590,5 @@
                !
                ! Just above last level, Dirichlet condition again (GOTM like)
-               zdep(ji,jj) = vkarmn * ( rn_bfrz0 + fse3t(ji,jj,ibotm1) )
+               zdep(ji,jj) = vkarmn * ( rn_bfrz0 + e3t_n(ji,jj,ibotm1) )
                psi (ji,jj,ibotm1) = rc0**rpp * en(ji,jj,ibot  )**rmm * zdep(ji,jj)**rnn
                z_elem_a(ji,jj,ibotm1) = 0._wp
@@ -621,8 +618,8 @@
                !
                ! Set psi vertical flux at the bottom:
-               zdep(ji,jj) = rn_bfrz0 + 0.5_wp*fse3t(ji,jj,ibotm1)
+               zdep(ji,jj) = rn_bfrz0 + 0.5_wp*e3t_n(ji,jj,ibotm1)
                zflxb = rsbc_psi2 * ( avm(ji,jj,ibot) + avm(ji,jj,ibotm1) )   &
                   &  * (0.5_wp*(en(ji,jj,ibot)+en(ji,jj,ibotm1)))**rmm * zdep(ji,jj)**(rnn-1._wp)
-               psi(ji,jj,ibotm1) = psi(ji,jj,ibotm1) + zflxb / fse3w(ji,jj,ibotm1)
+               psi(ji,jj,ibotm1) = psi(ji,jj,ibotm1) + zflxb / e3w_n(ji,jj,ibotm1)
             END DO
          END DO
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfmxl.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfmxl.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfmxl.F90	(revision 6140)
@@ -31,11 +31,9 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmld    !: mixing layer depth (turbocline)      [m]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmlp    !: mixed layer depth  (rho=rho0+zdcrit) [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmlpt   !: mixed layer depth at t-points        [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmlpt   !: depth of the last T-point inside the mixed layer
 
    REAL(wp), PUBLIC ::   rho_c = 0.01_wp    !: density criterion for mixed layer depth
    REAL(wp)         ::   avt_c = 5.e-4_wp   ! Kz criterion for the turbocline depth
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 4.0 , NEMO Consortium (2011)
@@ -105,5 +103,5 @@
             DO ji = 1, jpi
                ikt = mbkt(ji,jj)
-               hmlp(ji,jj) = hmlp(ji,jj) + MAX( rn2b(ji,jj,jk) , 0._wp ) * fse3w(ji,jj,jk)
+               hmlp(ji,jj) = hmlp(ji,jj) + MAX( rn2b(ji,jj,jk) , 0._wp ) * e3w_n(ji,jj,jk)
                IF( hmlp(ji,jj) < zN2_c )   nmln(ji,jj) = MIN( jk , ikt ) + 1   ! Mixed layer level
             END DO
@@ -111,11 +109,10 @@
       END DO
       !
-      ! w-level of the turbocline
+      ! w-level of the turbocline and mixing layer (iom_use)
       imld(:,:) = mbkt(:,:) + 1        ! Initialization to the number of w ocean point
       DO jk = jpkm1, nlb10, -1         ! from the bottom to nlb10 
          DO jj = 1, jpj
             DO ji = 1, jpi
-               imkt = mikt(ji,jj)
-               IF( avt (ji,jj,jk) < avt_c )   imld(ji,jj) = MAX( imkt, jk )      ! Turbocline 
+               IF( avt (ji,jj,jk) < avt_c * wmask(ji,jj,jk) )   imld(ji,jj) = jk      ! Turbocline 
             END DO
          END DO
@@ -127,12 +124,18 @@
             iikn = nmln(ji,jj)
             imkt = mikt(ji,jj)
-            hmld (ji,jj) = ( fsdepw(ji,jj,iiki  ) - fsdepw(ji,jj,imkt )            )   * ssmask(ji,jj)    ! Turbocline depth 
-            hmlp (ji,jj) = ( fsdepw(ji,jj,iikn  ) - fsdepw(ji,jj,MAX( imkt,nla10 ) ) ) * ssmask(ji,jj)    ! Mixed layer depth
-            hmlpt(ji,jj) = ( fsdept(ji,jj,iikn-1) - fsdepw(ji,jj,imkt )            )   * ssmask(ji,jj)    ! depth of the last T-point inside the mixed layer
+            hmld (ji,jj) = gdepw_n(ji,jj,iiki  ) * ssmask(ji,jj)    ! Turbocline depth 
+            hmlp (ji,jj) = gdepw_n(ji,jj,iikn  ) * ssmask(ji,jj)    ! Mixed layer depth
+            hmlpt(ji,jj) = gdept_n(ji,jj,iikn-1) * ssmask(ji,jj)    ! depth of the last T-point inside the mixed layer
          END DO
       END DO
       IF( .NOT.lk_offline ) THEN            ! no need to output in offline mode
-         CALL iom_put( "mldr10_1", hmlp )   ! mixed layer depth
-         CALL iom_put( "mldkz5"  , hmld )   ! turbocline depth
+         IF ( iom_use("mldr10_1") ) THEN
+            IF( .NOT. ln_isfcav ) CALL iom_put( "mldr10_1", hmlp )            ! mixed layer depth
+            IF(       ln_isfcav ) CALL iom_put( "mldr10_1", hmlp - risfdep)   ! mixed layer thickness
+         END IF
+         IF ( iom_use("mldkz5") ) THEN
+            IF( .NOT. ln_isfcav ) CALL iom_put( "mldkz5"  , hmld )             ! turbocline depth
+            IF(       ln_isfcav ) CALL iom_put( "mldkz5"  , hmld - risfdep )   ! turbocline thickness
+         END IF
       ENDIF
       
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 6140)
@@ -55,5 +55,5 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 4.0 , NEMO Consortium (2011)
@@ -133,6 +133,6 @@
          ! -----------------
          DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-               zcoef = 0.5 / fse3w(ji,jj,jk)
+            DO ji = fs_2, fs_jpim1
+               zcoef = 0.5 / e3w_n(ji,jj,jk)
                !                                            ! shear of horizontal velocity
                zdku = zcoef * (  ub(ji-1,jj,jk-1) + ub(ji,jj,jk-1)   &
@@ -151,5 +151,5 @@
          z05alp = 0.5_wp * rn_alp
          DO jj = 1, jpjm1                                   ! Eddy viscosity coefficients (avm)
-            DO ji = 1, jpim1
+            DO ji = 1, fs_jpim1
                avmu(ji,jj,jk) = umask(ji,jj,jk) * rn_avmri / ( 1. + z05alp*( zwx(ji+1,jj)+zwx(ji,jj) ) )**nn_ric
                avmv(ji,jj,jk) = vmask(ji,jj,jk) * rn_avmri / ( 1. + z05alp*( zwx(ji,jj+1)+zwx(ji,jj) ) )**nn_ric
@@ -157,5 +157,5 @@
          END DO
          DO jj = 2, jpjm1                                   ! Eddy diffusivity coefficients (avt)
-            DO ji = 2, jpim1
+            DO ji = fs_2, fs_jpim1
                avt(ji,jj,jk) = tmric(ji,jj,jk) / ( 1._wp + rn_alp * zwx(ji,jj) )           &
                   &                            * (  avmu(ji,jj,jk) + avmu(ji-1,jj,jk)      &
@@ -176,6 +176,6 @@
       ! -------------------------------------------------------
       zflageos = ( 0.5 + SIGN( 0.5, nn_eos - 1. ) ) * rau0
-      DO jj = 1, jpj
-         DO ji = 1, jpi
+      DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
             zrhos          = rhop(ji,jj,1) + zflageos * ( 1. - tmask(ji,jj,1) )
             zustar         = SQRT( taum(ji,jj) / ( zrhos +  rsmall ) )
@@ -189,6 +189,6 @@
       ! are always equal to the namelist values rn_wtmix/rn_wvmix
       ! -------------------------------------------------------
-      DO jj = 1, jpj
-         DO ji = 1, jpi
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
             avmv(ji,jj,1) = MAX( avmv(ji,jj,1), rn_wvmix )
             avmu(ji,jj,1) = MAX( avmu(ji,jj,1), rn_wvmix )
@@ -200,6 +200,6 @@
       ! -------------------------------------------------------
       DO jk = 2, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
                IF( fsdept(ji,jj,jk) < ekm_dep(ji,jj) ) THEN
                   avmv(ji,jj,jk) = MAX( avmv(ji,jj,jk), rn_wvmix )
@@ -212,6 +212,6 @@
 
       DO jk = 1, jpkm1                
-         DO jj = 1, jpj
-            DO ji = 1, jpi
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
                avmv(ji,jj,jk) = avmv(ji,jj,jk) * vmask(ji,jj,jk)
                avmu(ji,jj,jk) = avmu(ji,jj,jk) * umask(ji,jj,jk)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 6140)
@@ -99,5 +99,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -294,7 +293,7 @@
          !
          !                        !* total energy produce by LC : cumulative sum over jk
-         zpelc(:,:,1) =  MAX( rn2b(:,:,1), 0._wp ) * fsdepw(:,:,1) * fse3w(:,:,1)
+         zpelc(:,:,1) =  MAX( rn2b(:,:,1), 0._wp ) * gdepw_n(:,:,1) * e3w_n(:,:,1)
          DO jk = 2, jpk
-            zpelc(:,:,jk)  = zpelc(:,:,jk-1) + MAX( rn2b(:,:,jk), 0._wp ) * fsdepw(:,:,jk) * fse3w(:,:,jk)
+            zpelc(:,:,jk)  = zpelc(:,:,jk-1) + MAX( rn2b(:,:,jk), 0._wp ) * gdepw_n(:,:,jk) * e3w_n(:,:,jk)
          END DO
          !                        !* finite Langmuir Circulation depth
@@ -312,5 +311,5 @@
          DO jj = 1, jpj 
             DO ji = 1, jpi
-               zhlc(ji,jj) = fsdepw(ji,jj,imlc(ji,jj))
+               zhlc(ji,jj) = gdepw_n(ji,jj,imlc(ji,jj))
             END DO
          END DO
@@ -321,8 +320,8 @@
                   zus  = zcof * SQRT( taum(ji,jj) )           ! Stokes drift
                   !                                           ! vertical velocity due to LC
-                  zind = 0.5 - SIGN( 0.5, fsdepw(ji,jj,jk) - zhlc(ji,jj) )
-                  zwlc = zind * rn_lc * zus * SIN( rpi * fsdepw(ji,jj,jk) / zhlc(ji,jj) )
+                  zind = 0.5 - SIGN( 0.5, gdepw_n(ji,jj,jk) - zhlc(ji,jj) )
+                  zwlc = zind * rn_lc * zus * SIN( rpi * gdepw_n(ji,jj,jk) / zhlc(ji,jj) )
                   !                                           ! TKE Langmuir circulation source term
-                  en(ji,jj,jk) = en(ji,jj,jk) + rdt * ( zwlc * zwlc * zwlc ) / zhlc(ji,jj) * wmask(ji,jj,jk) * tmask(ji,jj,1)
+                  en(ji,jj,jk) = en(ji,jj,jk) + rdt * (1._wp - fr_i(ji,jj) ) * ( zwlc * zwlc * zwlc ) / zhlc(ji,jj) * wmask(ji,jj,jk) * tmask(ji,jj,1)
                END DO
             END DO
@@ -344,9 +343,9 @@
                   &                 * (  un(ji,jj,jk-1) -  un(ji  ,jj,jk) )   &
                   &                 * (  ub(ji,jj,jk-1) -  ub(ji  ,jj,jk) ) * wumask(ji,jj,jk) &
-                  &                 / (  fse3uw_n(ji,jj,jk) * fse3uw_b(ji,jj,jk) )
+                  &                 / (  e3uw_n(ji,jj,jk) * e3uw_b(ji,jj,jk) )
                z3dv(ji,jj,jk) = 0.5 * ( avm(ji,jj,jk  ) + avm(ji,jj+1,jk) )   &
                   &                 * (  vn(ji,jj,jk-1) -  vn(ji,jj  ,jk) )   &
                   &                 * (  vb(ji,jj,jk-1) -  vb(ji,jj  ,jk) ) * wvmask(ji,jj,jk) &
-                  &                 / (  fse3vw_n(ji,jj,jk) * fse3vw_b(ji,jj,jk) )
+                  &                 / (  e3vw_n(ji,jj,jk) * e3vw_b(ji,jj,jk) )
             END DO
          END DO
@@ -377,7 +376,7 @@
                zcof   = zfact1 * tmask(ji,jj,jk)
                zzd_up = zcof * ( avm  (ji,jj,jk+1) + avm  (ji,jj,jk  ) )   &  ! upper diagonal
-                  &          / ( fse3t(ji,jj,jk  ) * fse3w(ji,jj,jk  ) )
+                  &          / ( e3t_n(ji,jj,jk  ) * e3w_n(ji,jj,jk  ) )
                zzd_lw = zcof * ( avm  (ji,jj,jk  ) + avm  (ji,jj,jk-1) )   &  ! lower diagonal
-                  &          / ( fse3t(ji,jj,jk-1) * fse3w(ji,jj,jk  ) )
+                  &          / ( e3t_n(ji,jj,jk-1) * e3w_n(ji,jj,jk  ) )
                !                                   ! shear prod. at w-point weightened by mask
                zesh2  =  ( z3du(ji-1,jj,jk) + z3du(ji,jj,jk) ) / MAX( 1._wp , umask(ji-1,jj,jk) + umask(ji,jj,jk) )   &
@@ -438,9 +437,12 @@
       !                            !  TKE due to surface and internal wave breaking
       !                            !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+!!gm BUG : in the exp  remove the depth of ssh !!!
+      
+      
       IF( nn_etau == 1 ) THEN           !* penetration below the mixed layer (rn_efr fraction)
          DO jk = 2, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -fsdepw(ji,jj,jk) / htau(ji,jj) )   &
+                  en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -gdepw_n(ji,jj,jk) / htau(ji,jj) )   &
                      &                                 * ( 1._wp - fr_i(ji,jj) )  * wmask(ji,jj,jk) * tmask(ji,jj,1)
                END DO
@@ -451,5 +453,5 @@
             DO ji = fs_2, fs_jpim1   ! vector opt.
                jk = nmln(ji,jj)
-               en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -fsdepw(ji,jj,jk) / htau(ji,jj) )   &
+               en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -gdepw_n(ji,jj,jk) / htau(ji,jj) )   &
                   &                                 * ( 1._wp - fr_i(ji,jj) )  * wmask(ji,jj,jk) * tmask(ji,jj,1)
             END DO
@@ -464,5 +466,5 @@
                   zdif = taum(ji,jj) - ztau                            ! mean of modulus - modulus of the mean 
                   zdif = rhftau_scl * MAX( 0._wp, zdif + rhftau_add )  ! apply some modifications...
-                  en(ji,jj,jk) = en(ji,jj,jk) + zbbrau * zdif * EXP( -fsdepw(ji,jj,jk) / htau(ji,jj) )   &
+                  en(ji,jj,jk) = en(ji,jj,jk) + zbbrau * zdif * EXP( -gdepw_n(ji,jj,jk) / htau(ji,jj) )   &
                      &                        * ( 1._wp - fr_i(ji,jj) ) * wmask(ji,jj,jk) * tmask(ji,jj,1)
                END DO
@@ -565,14 +567,14 @@
       !
  !!gm Not sure of that coding for ISF....
-      ! where wmask = 0 set zmxlm == fse3w
+      ! where wmask = 0 set zmxlm == e3w_n
       CASE ( 0 )           ! bounded by the distance to surface and bottom
          DO jk = 2, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zemxl = MIN( fsdepw(ji,jj,jk) - fsdepw(ji,jj,mikt(ji,jj)), zmxlm(ji,jj,jk),   &
-                  &            fsdepw(ji,jj,mbkt(ji,jj)+1) - fsdepw(ji,jj,jk) )
+                  zemxl = MIN( gdepw_n(ji,jj,jk) - gdepw_n(ji,jj,mikt(ji,jj)), zmxlm(ji,jj,jk),   &
+                  &            gdepw_n(ji,jj,mbkt(ji,jj)+1) - gdepw_n(ji,jj,jk) )
                   ! wmask prevent zmxlm = 0 if jk = mikt(ji,jj)
-                  zmxlm(ji,jj,jk) = zemxl * wmask(ji,jj,jk) + MIN(zmxlm(ji,jj,jk),fse3w(ji,jj,jk)) * (1 - wmask(ji,jj,jk))
-                  zmxld(ji,jj,jk) = zemxl * wmask(ji,jj,jk) + MIN(zmxlm(ji,jj,jk),fse3w(ji,jj,jk)) * (1 - wmask(ji,jj,jk))
+                  zmxlm(ji,jj,jk) = zemxl * wmask(ji,jj,jk) + MIN(zmxlm(ji,jj,jk),e3w_n(ji,jj,jk)) * (1 - wmask(ji,jj,jk))
+                  zmxld(ji,jj,jk) = zemxl * wmask(ji,jj,jk) + MIN(zmxlm(ji,jj,jk),e3w_n(ji,jj,jk)) * (1 - wmask(ji,jj,jk))
                END DO
             END DO
@@ -583,5 +585,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zemxl = MIN( fse3w(ji,jj,jk), zmxlm(ji,jj,jk) )
+                  zemxl = MIN( e3w_n(ji,jj,jk), zmxlm(ji,jj,jk) )
                   zmxlm(ji,jj,jk) = zemxl
                   zmxld(ji,jj,jk) = zemxl
@@ -594,5 +596,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk-1) + fse3t(ji,jj,jk-1), zmxlm(ji,jj,jk) )
+                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk-1) + e3t_n(ji,jj,jk-1), zmxlm(ji,jj,jk) )
                END DO
             END DO
@@ -601,5 +603,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zemxl = MIN( zmxlm(ji,jj,jk+1) + fse3t(ji,jj,jk+1), zmxlm(ji,jj,jk) )
+                  zemxl = MIN( zmxlm(ji,jj,jk+1) + e3t_n(ji,jj,jk+1), zmxlm(ji,jj,jk) )
                   zmxlm(ji,jj,jk) = zemxl
                   zmxld(ji,jj,jk) = zemxl
@@ -612,5 +614,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zmxld(ji,jj,jk) = MIN( zmxld(ji,jj,jk-1) + fse3t(ji,jj,jk-1), zmxlm(ji,jj,jk) )
+                  zmxld(ji,jj,jk) = MIN( zmxld(ji,jj,jk-1) + e3t_n(ji,jj,jk-1), zmxlm(ji,jj,jk) )
                END DO
             END DO
@@ -619,5 +621,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk+1) + fse3t(ji,jj,jk+1), zmxlm(ji,jj,jk) )
+                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk+1) + e3t_n(ji,jj,jk+1), zmxlm(ji,jj,jk) )
                END DO
             END DO
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftmx.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftmx.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftmx.F90	(revision 6140)
@@ -51,5 +51,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -126,5 +125,5 @@
       zkz(:,:) = 0.e0               !* Associated potential energy consummed over the whole water column
       DO jk = 2, jpkm1
-         zkz(:,:) = zkz(:,:) + fse3w(:,:,jk) * MAX( 0.e0, rn2(:,:,jk) ) * rau0 * zav_tide(:,:,jk) * wmask(:,:,jk)
+         zkz(:,:) = zkz(:,:) + e3w_n(:,:,jk) * MAX( 0.e0, rn2(:,:,jk) ) * rau0 * zav_tide(:,:,jk) * wmask(:,:,jk)
       END DO
 
@@ -144,5 +143,5 @@
             DO jj= 1, jpj
                DO ji= 1, jpi
-                  ztpc = ztpc + fse3w(ji,jj,jk) * e1e2t(ji,jj)                  &
+                  ztpc = ztpc + e3w_n(ji,jj,jk) * e1e2t(ji,jj)                  &
                      &        * MAX( 0.e0, rn2(ji,jj,jk) ) * zav_tide(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
                END DO
@@ -238,6 +237,6 @@
       zsum2(:,:) = 0.e0
       DO jk= 2, jpk
-         zsum1(:,:) = zsum1(:,:) + zempba_3d_1(:,:,jk) * fse3w(:,:,jk) * wmask(:,:,jk)
-         zsum2(:,:) = zsum2(:,:) + zempba_3d_2(:,:,jk) * fse3w(:,:,jk) * wmask(:,:,jk)               
+         zsum1(:,:) = zsum1(:,:) + zempba_3d_1(:,:,jk) * e3w_n(:,:,jk) * wmask(:,:,jk)
+         zsum2(:,:) = zsum2(:,:) + zempba_3d_2(:,:,jk) * e3w_n(:,:,jk) * wmask(:,:,jk)               
       END DO
       DO jj = 1, jpj
@@ -256,5 +255,5 @@
                !
                zempba_3d(ji,jj,jk) =               ztpc 
-               zsum     (ji,jj)    = zsum(ji,jj) + ztpc * fse3w(ji,jj,jk)
+               zsum     (ji,jj)    = zsum(ji,jj) + ztpc * e3w_n(ji,jj,jk)
             END DO
          END DO
@@ -275,5 +274,5 @@
       zkz(:,:) = 0.e0               ! Associated potential energy consummed over the whole water column
       DO jk = 2, jpkm1
-         zkz(:,:) = zkz(:,:) + fse3w(:,:,jk) * MAX( 0.e0, rn2(:,:,jk) ) * rau0 * zavt_itf(:,:,jk) * wmask(:,:,jk)
+         zkz(:,:) = zkz(:,:) + e3w_n(:,:,jk) * MAX( 0.e0, rn2(:,:,jk) ) * rau0 * zavt_itf(:,:,jk) * wmask(:,:,jk)
       END DO
 
@@ -293,5 +292,5 @@
             DO jj= 1, jpj
                DO ji= 1, jpi
-                  ztpc = ztpc + e1e2t(ji,jj) * fse3w(ji,jj,jk) * MAX( 0.e0, rn2(ji,jj,jk) )   &
+                  ztpc = ztpc + e1e2t(ji,jj) * e3w_n(ji,jj,jk) * MAX( 0.e0, rn2(ji,jj,jk) )   &
                      &                       * zavt_itf(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
                END DO
@@ -447,5 +446,5 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  ztpc = ztpc + fse3w(ji,jj,jk) * e1e2t(ji,jj) * zpc(ji,jj,jk) * wmask(ji,jj,jk) * tmask_i(ji,jj)
+                  ztpc = ztpc + e3w_n(ji,jj,jk) * e1e2t(ji,jj) * zpc(ji,jj,jk) * wmask(ji,jj,jk) * tmask_i(ji,jj)
                END DO
             END DO
@@ -461,5 +460,5 @@
          zkz(:,:) = 0._wp
          DO jk = 2, jpkm1
-               zkz(:,:) = zkz(:,:) + fse3w(:,:,jk) * MAX(0.e0, rn2(:,:,jk)) * rau0 * zav_tide(:,:,jk) * wmask(:,:,jk)
+               zkz(:,:) = zkz(:,:) + e3w_n(:,:,jk) * MAX(0.e0, rn2(:,:,jk)) * rau0 * zav_tide(:,:,jk) * wmask(:,:,jk)
          END DO
          ! Here zkz should be equal to en_tmx ==> multiply by en_tmx/zkz
@@ -489,5 +488,5 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  ztpc = ztpc + fse3w(ji,jj,jk) * e1e2t(ji,jj) * zpc(ji,jj,jk) * wmask(ji,jj,jk) * tmask_i(ji,jj)
+                  ztpc = ztpc + e3w_n(ji,jj,jk) * e1e2t(ji,jj) * zpc(ji,jj,jk) * wmask(ji,jj,jk) * tmask_i(ji,jj)
                END DO
             END DO
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/lib_fortran.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/lib_fortran.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/lib_fortran.F90	(revision 6140)
@@ -24,6 +24,7 @@
    PRIVATE
 
-   PUBLIC   glob_sum   ! used in many places
-   PUBLIC   DDPDD      ! also used in closea module
+   PUBLIC   glob_sum      ! used in many places (masked with tmask_i)
+   PUBLIC   glob_sum_full ! used in many places (masked with tmask_h, ie omly over the halos)
+   PUBLIC   DDPDD         ! also used in closea module
    PUBLIC   glob_min, glob_max
 #if defined key_nosignedzero
@@ -34,4 +35,7 @@
       MODULE PROCEDURE glob_sum_1d, glob_sum_2d, glob_sum_3d, &
          &             glob_sum_2d_a, glob_sum_3d_a
+   END INTERFACE
+   INTERFACE glob_sum_full
+      MODULE PROCEDURE glob_sum_full_2d, glob_sum_full_3d
    END INTERFACE
    INTERFACE glob_min
@@ -156,4 +160,44 @@
       !
    END FUNCTION glob_sum_3d_a
+
+   FUNCTION glob_sum_full_2d( ptab )
+      !!----------------------------------------------------------------------
+      !!                  ***  FUNCTION  glob_sum_full_2d ***
+      !!
+      !! ** Purpose : perform a sum in calling DDPDD routine (nomask)
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in), DIMENSION(:,:) ::   ptab
+      REAL(wp)                             ::   glob_sum_full_2d   ! global sum
+      !!
+      !!-----------------------------------------------------------------------
+      !
+      glob_sum_full_2d = SUM( ptab(:,:) * tmask_h(:,:) )
+      IF( lk_mpp )   CALL mpp_sum( glob_sum_full_2d )
+      !
+   END FUNCTION glob_sum_full_2d
+
+   FUNCTION glob_sum_full_3d( ptab )
+      !!----------------------------------------------------------------------
+      !!                  ***  FUNCTION  glob_sum_full_3d ***
+      !!
+      !! ** Purpose : perform a sum on a 3D array in calling DDPDD routine (nomask)
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in), DIMENSION(:,:,:) ::   ptab
+      REAL(wp)                               ::   glob_sum_full_3d   ! global sum
+      !!
+      INTEGER    ::   ji, jj, jk   ! dummy loop indices
+      INTEGER    ::   ijpk ! local variables: size of ptab
+      !!-----------------------------------------------------------------------
+      !
+      ijpk = SIZE(ptab,3)
+      !
+      glob_sum_full_3d = 0.e0
+      DO jk = 1, ijpk
+         glob_sum_full_3d = glob_sum_full_3d + SUM( ptab(:,:,jk) * tmask_h(:,:) )
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( glob_sum_full_3d )
+      !
+   END FUNCTION glob_sum_full_3d
+
 
 #else  
@@ -314,4 +358,65 @@
    END FUNCTION glob_sum_3d_a   
 
+   FUNCTION glob_sum_full_2d( ptab )
+      !!----------------------------------------------------------------------
+      !!                  ***  FUNCTION  glob_sum_full_2d ***
+      !!
+      !! ** Purpose : perform a sum in calling DDPDD routine
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in), DIMENSION(:,:) ::   ptab
+      REAL(wp)                             ::   glob_sum_full_2d   ! global sum (nomask)
+      !!
+      COMPLEX(wp)::   ctmp
+      REAL(wp)   ::   ztmp
+      INTEGER    ::   ji, jj   ! dummy loop indices
+      !!-----------------------------------------------------------------------
+      !
+      ztmp = 0.e0
+      ctmp = CMPLX( 0.e0, 0.e0, wp )
+      DO jj = 1, jpj
+         DO ji =1, jpi
+         ztmp =  ptab(ji,jj) * tmask_h(ji,jj) 
+         CALL DDPDD( CMPLX( ztmp, 0.e0, wp ), ctmp )
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( ctmp )   ! sum over the global domain
+      glob_sum_full_2d = REAL(ctmp,wp)
+      !
+   END FUNCTION glob_sum_full_2d
+
+   FUNCTION glob_sum_full_3d( ptab )
+      !!----------------------------------------------------------------------
+      !!                  ***  FUNCTION  glob_sum_full_3d ***
+      !!
+      !! ** Purpose : perform a sum on a 3D array in calling DDPDD routine
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in), DIMENSION(:,:,:) ::   ptab
+      REAL(wp)                               ::   glob_sum_full_3d   ! global sum (nomask)
+      !!
+      COMPLEX(wp)::   ctmp
+      REAL(wp)   ::   ztmp
+      INTEGER    ::   ji, jj, jk   ! dummy loop indices
+      INTEGER    ::   ijpk ! local variables: size of ptab
+      !!-----------------------------------------------------------------------
+      !
+      ijpk = SIZE(ptab,3)
+      !
+      ztmp = 0.e0
+      ctmp = CMPLX( 0.e0, 0.e0, wp )
+      DO jk = 1, ijpk
+         DO jj = 1, jpj
+            DO ji =1, jpi
+            ztmp =  ptab(ji,jj,jk) * tmask_h(ji,jj)
+            CALL DDPDD( CMPLX( ztmp, 0.e0, wp ), ctmp )
+            END DO
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( ctmp )   ! sum over the global domain
+      glob_sum_full_3d = REAL(ctmp,wp)
+      !
+   END FUNCTION glob_sum_full_3d
+
+
+
 #endif
 
Index: unk/NEMOGCM/NEMO/OPA_SRC/lib_print.f90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/lib_print.f90	(revision 6139)
+++ 	(revision )
@@ -1,262 +1,0 @@
-MODULE lib_print
-   !!======================================================================
-   !!                    ***  MODULE  lib_print  ***
-   !! print librairy :  formated real and integer array print
-   !!=====================================================================
-      
-   !!----------------------------------------------------------------------
-   !!   prihin       : print an integer 2D horizontal field
-   !!   prihre       : print an real 2D horizontal field
-   !!   prizre       : print an real 2D vertical field
-   !!----------------------------------------------------------------------
-   USE par_kind      ! kind parameters
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   prihin, prihre, prizre
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE prihin( ktab, ki   , kj   , kideb, kifin ,   &
-                      kind, kjdeb, kjfin, kjnd , kscale, kumout )
-      !!----------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  prihre  ***
-      !!  
-      !! ** purpose :   Print an integer field
-      !!
-      !! ** method :   format of print is selected with the dummy argument kscale
-      !!
-      !! History :
-      !!        !  90-04 (0. Marti)  Original code
-      !!        !  92-02 (M. Imbard)
-      !!        !  03-07 (G. Madec)  F90, free form
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   &
-         ki, kj,                 &  ! array dimensions
-         kideb, kifin, kind,     &  ! first and last index, increment for i 
-         kjdeb, kjfin, kjnd,     &  ! first and last index, increment for j
-         kscale,                 &  ! kscale=0 or > 5  print ktab with format i8
-      !                             !         kscale=1 print ktab with format i1
-      !                             !         kscale=2 print ktab with format i2
-      !                             !         kscale=3 print ktab with format i3
-      !                             !         kscale=4 print ktab with format i4
-      !                             !         kscale=5 print ktab with format i5
-         kumout                     ! unit in which print
-      INTEGER, DIMENSION(ki,kj), INTENT( in ) ::   &
-         ktab                       ! integer 2D array to be print
-
-      !! * local declarations
-      INTEGER ::   ji, jj, jn       ! dummy loop indices
-      INTEGER ::   isca, il1, il2   ! temporary integers
-      INTEGER ::   iind, ijnd       ! temporary integers
-
-      isca = 10
-      IF( kscale == 0 )   isca = 10
-      IF( kscale == 1 )   isca = 100
-      IF( kscale == 2 )   isca = 60
-      IF( kscale == 3 )   isca = 40
-      IF( kscale == 4 )   isca = 30
-      IF( kscale == 5 )   isca = 20
-
-      iind = MAX( 1, kind )
-      ijnd = MAX( 1, kjnd )
-
-      il1 = kideb
-
-      DO jn = 1, (kifin-kideb+1)/(iind*isca) + 1
-
-        IF( il1 > kifin ) RETURN
-        WRITE(kumout,'(/)')
-        il2 = il1+iind*(isca-1)
-        IF( il2 > kifin )   il2 = kifin
-
-        IF( kscale == 1 ) THEN
-            WRITE(kumout,'(4x,i14," to ",1i4," each ",1i4,/)') il1, il2, iind
-            DO jj = kjfin, kjdeb, -ijnd
-              WRITE (kumout,'(1x,i3,100i1)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
-            END DO  
-        ELSEIF( kscale == 2 ) THEN
-            WRITE(kumout,'(4x,i14," to ",1i4," each ",1i4,/)')il1, il2, iind
-            DO jj = kjfin, kjdeb, -ijnd
-              WRITE (kumout,'(1x,i3,60i2)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
-            END DO  
-        ELSEIF( kscale == 3 ) THEN
-            WRITE(kumout,'(4x,i14," to ",1i4," each ",1i4,/)')il1, il2, iind
-            DO jj = kjfin, kjdeb, -ijnd
-              WRITE (kumout,'(1x,i3,40i3)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
-            END DO  
-        ELSEIF( kscale == 4 ) THEN
-            WRITE(kumout,'(4x,30i4,/)') ( ji, ji = il1, il2, iind )
-            DO jj = kjfin, kjdeb, -ijnd
-              WRITE (kumout,'(1x,i3,30i4)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
-            END DO  
-        ELSEIF( kscale == 5 ) THEN
-            WRITE(kumout,'(4x,20i5,/)') ( ji, ji = il1, il2, iind )
-            DO jj = kjfin, kjdeb, -ijnd
-              WRITE (kumout,'(1x,i3,20i5)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
-            END DO  
-        ELSE
-            WRITE(kumout,'(4x,10i8,/)') ( ji, ji = il1, il2, iind )
-            DO jj = kjfin, kjdeb, -ijnd
-              WRITE (kumout,'(1x,i3,10i8)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
-            END DO  
-        ENDIF
-
-        il1 = il1 + iind * isca
-      END DO  
-
-   END SUBROUTINE prihin
-
-
-   SUBROUTINE prihre( ptab, ki   , kj   , kideb, kifin ,   &
-                      kind, kjdeb, kjfin, kjnd , pscale, kumout )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE prihre  ***
-      !!      
-      !! ** purpose :   Print a real field with the format 10e12.4 or 20f6.2
-      !!
-      !! ** method  :   the print format is selected with the pscale argument
-      !!
-      !! History :
-      !!   1.0  !  86-01  (P. Andrich)  Original code
-      !!        !  89-11  (C. Levy)
-      !!        !  92-02  (M. Imbard)
-      !!        !  92-06  (M. Imbard)
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   &
-         ki, kj,                 &  ! array dimensions
-         kideb, kifin, kind,     &  ! first and last index, increment for i
-         kjdeb, kjfin, kjnd,     &  ! first and last index, increment for j
-         kumout                     ! unit in which print
-      REAL(wp), INTENT( in ) ::   &
-         pscale                     ! = 0  print        ptab with e13.5 format
-         !                          ! else print pscale*ptab with f6.2 format
-      REAL(wp), DIMENSION(ki,kj), INTENT( in ) ::   &
-         ptab                       ! integer 2D array to be print
-
-      !! * Local variables
-      INTEGER ::   ji, jj, jn       ! dummy loop indices
-      INTEGER ::   isca, il1, il2   ! temporary integers
-
-      isca = 10
-      IF( pscale /= 0. )   isca=20
-
-      il1 = kideb
-
-      DO jn = 1, (kifin-kideb+1)/(kind*isca) + 1
-
-        IF( il1 > kifin )   RETURN
-
-        WRITE(kumout,9100)
-
-        il2 = il1+kind*(isca-1)
-        IF(il2 > kifin) il2 = kifin
-        IF( pscale == 0.) THEN
-            WRITE(kumout,9101) ( ji, ji = il1, il2, kind )
-            DO jj = kjfin, kjdeb, -kjnd
-              WRITE(kumout,9102) jj, ( ptab(ji,jj), ji = il1, il2, kind )
-            END DO  
-        ELSE
-            WRITE(kumout,9103) ( ji, ji = il1, il2, kind )
-            DO jj = kjfin, kjdeb, -kjnd
-              WRITE(kumout,9104) jj, ( pscale*ptab(ji,jj), ji = il1, il2, kind )
-            END DO  
-        ENDIF
-        il1 = il1+kind*isca
-
-      END DO  
-
-      ! formats
- 9100 FORMAT(/)
- 9101 FORMAT(10i12, /)
- 9102 FORMAT(1x, i3, 10(1pe12.4))
- 9103 FORMAT(3x, 20i6, /)
- 9104 FORMAT(1x, i3, 1x, 20f6.2)
-
-   END SUBROUTINE prihre
-
-
-   SUBROUTINE prizre( ptab , ki   , kj   , kk   , kjcut ,   &
-                      kideb, kifin, kid  , kkdeb, kkfin ,   &
-                      kkd  , pscale, kumout )
-      !!----------------------------------------------------------------------
-      !!                      ***  ROUTINE prizre  ***
-      !!
-      !! ** purpose :   Print a vertical slab from a tridimentional real field
-      !!
-      !!   METHOD :
-      !! ** method  :   the print format is selected with the argument pscale
-      !!
-      !! History :
-      !!      original : 86-01 (o. Marti)
-      !!      addition : 92-02 (M. Imbard)
-      !!      addition : 92-06 (M. Imbard)
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   &
-         ki, kj, kk,             &  ! array dimensions
-         kjcut,                  &  ! index j for the vertical slab
-         kideb, kifin, kid,      &  ! first and last index, increment for i
-         kkdeb, kkfin, kkd,      &  ! first and last index, increment for k
-         kumout                     ! unit in which print
-      REAL(wp), INTENT( in ) ::   &
-         pscale                     ! = 0  print        ptab with e12.4 format
-         !                          ! else print pscale*ptab with f6.2 format
-      REAL(wp), DIMENSION(ki,kj,kk), INTENT( in ) ::   &
-         ptab                       ! integer 3D array to be print
-
-      !! * Local variables
-      INTEGER ::   ji, jn, jk       ! dummy loop indices
-      INTEGER ::   isca, il1, il2   ! temporary integers
-      INTEGER ::   iind, iknd       !    "          "
-
-
-      iind = kid
-      iknd = kkd
-      isca = 10
-      IF( pscale /= 0.) isca = 20
-
-      IF (iind == 0) iind = 1
-      IF (iknd == 0) iknd = 1
-
-      il1 = kideb
-
-      DO jn = 1, (kifin-kideb+1)/(iind*isca) + 1
-
-        IF(il1 > kifin) RETURN
-        WRITE(kumout,9100)
-        il2 = il1+iind*(isca-1)
-        IF(il2 > kifin) il2 = kifin
-
-        IF( pscale == 0.) THEN
-            WRITE(kumout,9101) ( ji, ji = il1, il2, iind )
-            DO jk = kkdeb, kkfin, iknd
-              WRITE (kumout,9102) jk, ( ptab(ji,kjcut,jk), ji = il1, il2, iind )
-            END DO  
-        ELSE
-            WRITE (kumout,9103) ( ji, ji = il1, il2, iind )
-            DO jk = kkdeb, kkfin, iknd
-              WRITE(kumout,9104)jk, ( pscale*ptab(ji,kjcut,jk), ji = il1, il2, iind )
-            END DO  
-        ENDIF
-
-        il1 = il1+iind*isca
-      END DO      
-
- 9100 FORMAT(/)
- 9101 FORMAT(10i12, /)
- 9102 FORMAT(1x, i3, 10(1pe12.4))
- 9103 FORMAT(3x, 20i6, /)
- 9104 FORMAT(1x, i3, 1x, 20f6.1)
-
-      END SUBROUTINE prizre
-
-   !!======================================================================
-END MODULE lib_print
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 6140)
@@ -36,55 +36,60 @@
 
    !!----------------------------------------------------------------------
-   !!   nemo_gcm       : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
-   !!   nemo_init      : initialization of the NEMO system
-   !!   nemo_ctl       : initialisation of the contol print
-   !!   nemo_closefile : close remaining open files
-   !!   nemo_alloc     : dynamical allocation
-   !!   nemo_partition : calculate MPP domain decomposition
-   !!   factorise      : calculate the factors of the no. of MPI processes
+   !!   nemo_gcm      : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
+   !!   nemo_init     : initialization of the NEMO system
+   !!   nemo_ctl      : initialisation of the contol print
+   !!   nemo_closefile: close remaining open files
+   !!   nemo_alloc    : dynamical allocation
+   !!   nemo_partition: calculate MPP domain decomposition
+   !!   factorise     : calculate the factors of the no. of MPI processes
    !!----------------------------------------------------------------------
-   USE step_oce        ! module used in the ocean time stepping module (step.F90)
-   USE domcfg          ! domain configuration               (dom_cfg routine)
-   USE mppini          ! shared/distributed memory setting (mpp_init routine)
-   USE domain          ! domain initialization             (dom_init routine)
+   USE step_oce       ! module used in the ocean time stepping module (step.F90)
+   USE domcfg         ! domain configuration               (dom_cfg routine)
+   USE mppini         ! shared/distributed memory setting (mpp_init routine)
+   USE domain         ! domain initialization             (dom_init routine)
 #if defined key_nemocice_decomp
    USE ice_domain_size, only: nx_global, ny_global
 #endif
-   USE tideini         ! tidal components initialization   (tide_ini routine)
-   USE bdyini          ! open boundary cond. setting       (bdy_init routine)
-   USE bdydta          ! open boundary cond. setting   (bdy_dta_init routine)
-   USE bdytides        ! open boundary cond. setting   (bdytide_init routine)
-   USE istate          ! initial state setting          (istate_init routine)
-   USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
-   USE ldftra          ! lateral diffusivity setting    (ldftra_init routine)
-   USE zdfini          ! vertical physics setting          (zdf_init routine)
-   USE phycst          ! physical constant                  (par_cst routine)
-   USE trdini          ! dyn/tra trends initialization     (trd_init routine)
-   USE asminc          ! assimilation increments     
-   USE asmbkg          ! writing out state trajectory
-   USE diaptr          ! poleward transports           (dia_ptr_init routine)
-   USE diadct          ! sections transports           (dia_dct_init routine)
-   USE diaobs          ! Observation diagnostics       (dia_obs_init routine)
-   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
-   USE step            ! NEMO time-stepping                 (stp     routine)
-   USE icbini          ! handle bergs, initialisation
-   USE icbstp          ! handle bergs, calving, themodynamics and transport
-   USE cpl_oasis3      ! OASIS3 coupling
-   USE c1d             ! 1D configuration
-   USE step_c1d        ! Time stepping loop for the 1D configuration
-   USE dyndmp          ! Momentum damping
+   USE tideini        ! tidal components initialization   (tide_ini routine)
+   USE bdyini         ! open boundary cond. setting       (bdy_init routine)
+   USE bdydta         ! open boundary cond. setting   (bdy_dta_init routine)
+   USE bdytides       ! open boundary cond. setting   (bdytide_init routine)
+   USE sbctide, ONLY  : lk_tide
+   USE istate         ! initial state setting          (istate_init routine)
+   USE ldfdyn         ! lateral viscosity setting      (ldfdyn_init routine)
+   USE ldftra         ! lateral diffusivity setting    (ldftra_init routine)
+   USE zdfini         ! vertical physics setting          (zdf_init routine)
+   USE phycst         ! physical constant                  (par_cst routine)
+   USE trdini         ! dyn/tra trends initialization     (trd_init routine)
+   USE asminc         ! assimilation increments     
+   USE asmbkg         ! writing out state trajectory
+   USE diaptr         ! poleward transports           (dia_ptr_init routine)
+   USE diadct         ! sections transports           (dia_dct_init routine)
+   USE diaobs         ! Observation diagnostics       (dia_obs_init routine)
+   USE diacfl         ! CFL diagnostics               (dia_cfl_init routine)
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
+   USE step           ! NEMO time-stepping                 (stp     routine)
+   USE icbini         ! handle bergs, initialisation
+   USE icbstp         ! handle bergs, calving, themodynamics and transport
+   USE cpl_oasis3     ! OASIS3 coupling
+   USE c1d            ! 1D configuration
+   USE step_c1d       ! Time stepping loop for the 1D configuration
+   USE dyndmp         ! Momentum damping
+   USE stopar         ! Stochastic param.: ???
+   USE stopts         ! Stochastic param.: ???
 #if defined key_top
-   USE trcini          ! passive tracer initialisation
-#endif
-   USE lib_mpp         ! distributed memory computing
+   USE trcini         ! passive tracer initialisation
+#endif
+   USE lib_mpp        ! distributed memory computing
+   USE diurnal_bulk    ! diurnal bulk SST 
+   USE step_diu        ! diurnal bulk SST timestepping (called from here if run offline)
 #if defined key_iomput
-   USE xios            ! xIOserver
-#endif
-   USE sbctide, ONLY   : lk_tide
-   USE crsini          ! initialise grid coarsening utility
-   USE lbcnfd , ONLY   : isendto, nsndto, nfsloop, nfeloop   ! Setup of north fold exchanges 
-   USE sbc_oce, ONLY   : lk_oasis
-   USE stopar
-   USE stopts
+   USE xios           ! xIOserver
+#endif
+   USE crsini         ! initialise grid coarsening utility
+   USE lbcnfd , ONLY  : isendto, nsndto, nfsloop, nfeloop   ! Setup of north fold exchanges 
+   USE sbc_oce, ONLY  : lk_oasis
+   USE diatmb          ! Top,middle,bottom output
+   USE dia25h          ! 25h mean output
 
    IMPLICIT NONE
@@ -171,5 +176,9 @@
             CALL stp                         ! AGRIF: time stepping
 #else
-            CALL stp( istp )                 ! standard time stepping
+            IF ( .NOT. ln_diurnal_only ) THEN 
+               CALL stp( istp )                 ! standard time stepping 
+            ELSE 
+               CALL stp_diurnal( istp )        ! time step only the diurnal SST 
+            ENDIF 
 #endif
             istp = istp + 1
@@ -178,5 +187,5 @@
 #endif
 
-      IF( lk_diaobs   )   CALL dia_obs_wri
+      IF( ln_diaobs   )   CALL dia_obs_wri
       !
       IF( ln_icebergs )   CALL icb_end( nitend )
@@ -193,7 +202,7 @@
       !
 #if defined key_agrif
-      IF(.NOT.Agrif_Root() ) THEN
-                                CALL Agrif_ParentGrid_To_ChildGrid()
-         IF( lk_diaobs )        CALL dia_obs_wri
+      IF( .NOT. Agrif_Root() ) THEN
+                         CALL Agrif_ParentGrid_To_ChildGrid()
+         IF( ln_diaobs ) CALL dia_obs_wri
          IF( nn_timing == 1 )   CALL timing_finalize
                                 CALL Agrif_ChildGrid_To_ParentGrid()
@@ -231,5 +240,5 @@
       NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
          &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
-         &             nn_bench, nn_timing
+         &             nn_bench, nn_timing, nn_diacfl
       NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
          &             jpizoom, jpjzoom, jperio, ln_use_jattr
@@ -398,9 +407,29 @@
       IF( ln_nnogather )    CALL nemo_northcomms! northfold neighbour lists (must be done after the masks are defined)
       IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
+      
+      CALL diurnal_sst_bulk_init            ! diurnal sst
+      IF ( ln_diurnal ) CALL diurnal_sst_coolskin_init   ! cool skin   
+      
+      ! IF ln_diurnal_only, then we only want a subset of the initialisation routines
+      IF ( ln_diurnal_only ) THEN
+         CALL  istate_init   ! ocean initial state (Dynamics and tracers)
+         CALL     sbc_init   ! Forcings : surface module
+         CALL tra_qsr_init   ! penetrative solar radiation qsr
+         IF( ln_diaobs     ) THEN                  ! Observation & model comparison
+            CALL dia_obs_init            ! Initialize observational data
+            CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
+         ENDIF     
+         !                                     ! Assimilation increments
+         IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
+                 
+         IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
+         RETURN
+      ENDIF
+      
                             CALL  istate_init   ! ocean initial state (Dynamics and tracers)
 
       !                                      ! external forcing 
 !!gm to be added : creation and call of sbc_apr_init
-      IF( lk_tide       )   CALL    tide_init( nit000 )    ! tidal harmonics
+      IF( lk_tide       )   CALL    tide_init   ! tidal harmonics
                             CALL     sbc_init   ! surface boundary conditions (including sea-ice)
 !!gm ==>> bdy_init should call bdy_dta_init and bdytide_init  NOT in nemogcm !!!
@@ -458,4 +487,5 @@
       !                                      ! Diagnostics
       IF( lk_floats     )   CALL     flo_init   ! drifting Floats
+                            CALL dia_cfl_init   ! Initialise CFL diagnostics
       IF( lk_diaar5     )   CALL dia_ar5_init   ! ar5 diag
                             CALL dia_ptr_init   ! Poleward TRansports initialization
@@ -463,11 +493,13 @@
                             CALL dia_hsb_init   ! heat content, salt content and volume budgets
                             CALL     trd_init   ! Mixed-layer/Vorticity/Integral constraints trends
-      IF( lk_diaobs     ) THEN                  ! Observation & model comparison
                             CALL dia_obs_init            ! Initialize observational data
-                            CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
-      ENDIF
-      !                                      ! Assimilation increments
+      IF( ln_diaobs     )   CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
+
+      !                                         ! Assimilation increments
       IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
       IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
+                            CALL dia_tmb_init  ! TMB outputs
+                            CALL dia_25h_init  ! 25h mean  outputs
+
       !
    END SUBROUTINE nemo_init
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/oce.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/oce.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/oce.F90	(revision 6140)
@@ -35,24 +35,19 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   vb_b   ,  vn_b  ,  va_b  !: Barotropic velocities at v-point [m/s]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sshb   ,  sshn  ,  ssha  !: sea surface height at t-point [m]
+
+   !! Arrays at barotropic time step:                   ! befbefore! before !  now   ! after  !
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ubb_e  ,  ub_e  ,  un_e  , ua_e   !: u-external velocity
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   vbb_e  ,  vb_e  ,  vn_e  , va_e   !: v-external velocity
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sshbb_e,  sshb_e,  sshn_e, ssha_e !: external ssh
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::                              hu_e   !: external u-depth
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::                              hv_e   !: external v-depth
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::                              hur_e  !: inverse of u-depth
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::                              hvr_e  !: inverse of v-depth
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ub2_b  , vb2_b           !: Half step fluxes (ln_bt_fw=T)
+#if defined key_agrif
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ub2_i_b, vb2_i_b         !: Half step time integrated fluxes 
+#endif
    !
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   spgu, spgv               !: horizontal surface pressure gradient
-
-   !! Specific to split explicit free surface (allocated in dynspg_ts module):
-   !
-   !! Time filtered arrays at baroclinic time step:
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   un_adv, vn_adv    ! Advection vel. at "now" barocl. step
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ub2_b , vb2_b     ! Half step fluxes (ln_bt_fw=T)
-#if defined key_agrif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ub2_i_b,  vb2_i_b ! Half step time integrated fluxes 
-#endif
-
-   !! Arrays at barotropic time step:                   ! bef before !   before   !    now     !   after    !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ubb_e    ,    ub_e    ,    un_e    ,    ua_e 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   vbb_e    ,    vb_e    ,    vn_e    ,    va_e 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sshbb_e  ,    sshb_e  ,    sshn_e  ,    ssha_e 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::                              hu_e
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::                              hv_e                                                
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::                              hur_e
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::                              hvr_e 
 
    !! interpolated gradient (only used in zps case)
@@ -60,7 +55,4 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gtsu, gtsv   !: horizontal gradient of T, S bottom u-point 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   gru , grv    !: horizontal gradient of rd at bottom u-point
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   aru , arv    
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   gzu , gzv    
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ge3ru, ge3rv   !: horizontal gradient of T, S and rd at top v-point  
 
    !! (ISF) interpolated gradient (only used for ice shelf case) 
@@ -68,7 +60,4 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gtui, gtvi   !: horizontal gradient of T, S and rd at top u-point 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   grui, grvi   !: horizontal gradient of T, S and rd at top v-point  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   arui, arvi   !: horizontal average  of rd          at top v-point  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   gzui, gzvi   !: horizontal gradient of z           at top v-point  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ge3rui, ge3rvi   !: horizontal gradient of T, S and rd at top v-point  
    !! (ISF) ice load
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   riceload
@@ -98,7 +87,8 @@
       !!                   ***  FUNCTION oce_alloc  ***
       !!----------------------------------------------------------------------
-      INTEGER :: ierr(4)
+      INTEGER :: ierr(7)
       !!----------------------------------------------------------------------
       !
+      ierr(:) = 0 
       ALLOCATE( ub   (jpi,jpj,jpk)      , un   (jpi,jpj,jpk)      , ua(jpi,jpj,jpk)       ,     &
          &      vb   (jpi,jpj,jpk)      , vn   (jpi,jpj,jpk)      , va(jpi,jpj,jpk)       ,     &          
@@ -115,12 +105,6 @@
          &     spgu  (jpi,jpj)   , spgv(jpi,jpj)   ,                       &
          &     gtsu(jpi,jpj,jpts), gtsv(jpi,jpj,jpts),                     &
-         &     aru(jpi,jpj)      , arv(jpi,jpj)      ,                     &
-         &     gzu(jpi,jpj)      , gzv(jpi,jpj)      ,                     &
          &     gru(jpi,jpj)      , grv(jpi,jpj)      ,                     &
-         &     ge3ru(jpi,jpj)    , ge3rv(jpi,jpj)    ,                     &
          &     gtui(jpi,jpj,jpts), gtvi(jpi,jpj,jpts),                     &
-         &     arui(jpi,jpj)     , arvi(jpi,jpj)     ,                     &
-         &     gzui(jpi,jpj)     , gzvi(jpi,jpj)     ,                     &
-         &     ge3rui(jpi,jpj)   , ge3rvi(jpi,jpj)   ,                     &
          &     grui(jpi,jpj)     , grvi(jpi,jpj)     ,                     &
          &     riceload(jpi,jpj),                             STAT=ierr(2) )
@@ -129,4 +113,14 @@
          !
       ALLOCATE( fraqsr_1lev(jpi,jpj) , STAT=ierr(4) )
+         !
+      ALLOCATE( ssha_e(jpi,jpj),  sshn_e(jpi,jpj), sshb_e(jpi,jpj), sshbb_e(jpi,jpj), &
+         &        ua_e(jpi,jpj),    un_e(jpi,jpj),   ub_e(jpi,jpj),   ubb_e(jpi,jpj), &
+         &        va_e(jpi,jpj),    vn_e(jpi,jpj),   vb_e(jpi,jpj),   vbb_e(jpi,jpj), &
+         &        hu_e(jpi,jpj),   hur_e(jpi,jpj),   hv_e(jpi,jpj),   hvr_e(jpi,jpj), STAT=ierr(5) )
+         !
+      ALLOCATE( ub2_b(jpi,jpj), vb2_b(jpi,jpj)                                      , STAT=ierr(6) )
+#if defined key_agrif
+      ALLOCATE( ub2_i_b(jpi,jpj), vb2_i_b(jpi,jpj)                                  , STAT=ierr(7) )
+#endif
          !
       oce_alloc = MAXVAL( ierr )
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 6140)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE step  ***
-   !! Time-stepping    : manager of the ocean, tracer and ice time stepping
+   !! Time-stepping   : manager of the ocean, tracer and ice time stepping
    !!======================================================================
    !! History :  OPA  !  1991-03  (G. Madec)  Original code
@@ -35,5 +35,6 @@
    !!----------------------------------------------------------------------
    USE step_oce         ! time stepping definition modules
-   USE iom
+   !
+   USE iom              ! xIOs server
 
    IMPLICIT NONE
@@ -42,7 +43,4 @@
    PUBLIC   stp   ! called by nemogcm.F90
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-!!gm   #  include "zdfddm_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.7 , NEMO Consortium (2015)
@@ -166,8 +164,6 @@
 
          IF( ln_zps .AND.       ln_isfcav)                               &
-            &            CALL zps_hde_isf( kstp, jpts, tsb, gtsu, gtsv, gtui, gtvi,   &    ! Partial steps for top cell (ISF)
-            &                                          rhd, gru , grv , aru , arv , gzu , gzv , ge3ru , ge3rv ,   &
-            &                                   grui, grvi, arui, arvi, gzui, gzvi, ge3rui, ge3rvi    ) ! of t, s, rd at the first ocean level
-
+            &            CALL zps_hde_isf( kstp, jpts, tsb, gtsu, gtsv, gtui, gtvi,  &  ! Partial steps for top cell (ISF)
+            &                                          rhd, gru , grv , grui, grvi   )  ! of t, s, rd at the first ocean level
          IF( ln_traldf_triad ) THEN 
                          CALL ldf_slp_triad( kstp )                       ! before slope for triad operator
@@ -183,24 +179,22 @@
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
-                         CALL ssh_nxt       ( kstp )  ! after ssh (includes call to div_hor)
-      IF( lk_vvl     )   CALL dom_vvl_sf_nxt( kstp )  ! after vertical scale factors 
-                         CALL wzv           ( kstp )  ! now cross-level velocity 
-
+                            CALL ssh_nxt       ( kstp )  ! after ssh (includes call to div_hor)
+      IF(.NOT.ln_linssh )   CALL dom_vvl_sf_nxt( kstp )  ! after vertical scale factors 
+                            CALL wzv           ( kstp )  ! now cross-level velocity 
 !!gm : why also here ????
-      IF(ln_sto_eos  )   CALL sto_pts( tsn )                             ! Random T/S fluctuations
+      IF( ln_sto_eos    )   CALL sto_pts( tsn )                             ! Random T/S fluctuations
 !!gm
-                         CALL eos    ( tsn, rhd, rhop, fsdept_n(:,:,:) ) ! now in situ density for hpg computation
-
+                            CALL eos    ( tsn, rhd, rhop, gdept_n(:,:,:) )  ! now in situ density for hpg computation
+                            
 !!jc: fs simplification
-!!jc: lines below are useless if lk_vvl=T. Keep them here (which maintains a bug if lk_vvl=F and ln_zps=T, cf ticket #1636) 
+!!jc: lines below are useless if ln_linssh=F. Keep them here (which maintains a bug if ln_linssh=T and ln_zps=T, cf ticket #1636) 
 !!                                         but ensures reproductible results
 !!                                         with previous versions using split-explicit free surface          
-            IF( ln_zps .AND. .NOT. ln_isfcav)   &                           ! Partial steps: bottom before horizontal gradient
-               &            CALL zps_hde    ( kstp, jpts, tsn, gtsu, gtsv,  &  ! of t, s, rd at the last ocean level
-               &                                          rhd, gru , grv    )
-            IF( ln_zps .AND.       ln_isfcav)   &                           ! Partial steps: top & bottom before horizontal gradient
-               &            CALL zps_hde_isf( kstp, jpts, tsn, gtsu, gtsv, gtui, gtvi,   & 
-               &                                          rhd, gru , grv , aru , arv , gzu , gzv , ge3ru , ge3rv ,   &
-               &                                               grui, grvi, arui, arvi, gzui, gzvi, ge3rui, ge3rvi    )
+            IF( ln_zps .AND. .NOT. ln_isfcav )                               &
+               &            CALL zps_hde    ( kstp, jpts, tsn, gtsu, gtsv,   &  ! Partial steps: before horizontal gradient
+               &                                          rhd, gru , grv     )  ! of t, s, rd at the last ocean level
+            IF( ln_zps .AND.       ln_isfcav )                                          &
+               &            CALL zps_hde_isf( kstp, jpts, tsn, gtsu, gtsv, gtui, gtvi,  &  ! Partial steps for top cell (ISF)
+               &                                          rhd, gru , grv , grui, grvi   )  ! of t, s, rd at the first ocean level
 !!jc: fs simplification
                             
@@ -224,5 +218,5 @@
       IF( ln_dynspg_ts ) THEN                         ! vertical scale factors and vertical velocity need to be updated
                             CALL div_hor    ( kstp )              ! Horizontal divergence  (2nd call in time-split case)
-         IF( lk_vvl )       CALL dom_vvl_sf_nxt( kstp, kcall=2 )  ! after vertical scale factors (update depth average component)
+         IF(.NOT.ln_linssh) CALL dom_vvl_sf_nxt( kstp, kcall=2 )  ! after vertical scale factors (update depth average component)
                             CALL wzv        ( kstp )              ! now cross-level velocity 
       ENDIF
@@ -232,16 +226,22 @@
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! diagnostics and outputs             
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( lk_floats  )   CALL flo_stp       ( kstp )  ! drifting Floats
-      IF( lk_diahth  )   CALL dia_hth       ( kstp )  ! Thermocline depth (20 degres isotherm depth)
-      IF(.NOT.ln_cpl )   CALL dia_fwb       ( kstp )  ! Fresh water budget diagnostics
-      IF( lk_diadct  )   CALL dia_dct       ( kstp )  ! Transports
-      IF( lk_diaar5  )   CALL dia_ar5       ( kstp )  ! ar5 diag
-      IF( lk_diaharm )   CALL dia_harm      ( kstp )  ! Tidal harmonic analysis
-                         CALL dia_wri       ( kstp )  ! ocean model: outputs
+      ! cool skin
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<      
+      IF ( ln_diurnal )  CALL stp_diurnal( kstp )
+      
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! diagnostics and outputs             (ua, va, tsa used as workspace)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF( lk_floats  )   CALL flo_stp( kstp )         ! drifting Floats
+      IF( nn_diacfl == 1 )   CALL dia_cfl( kstp )         ! Courant number diagnostics
+      IF( lk_diahth  )   CALL dia_hth( kstp )         ! Thermocline depth (20 degres isotherm depth)
+      IF(.NOT.ln_cpl )   CALL dia_fwb( kstp )         ! Fresh water budget diagnostics
+      IF( lk_diadct  )   CALL dia_dct( kstp )         ! Transports
+      IF( lk_diaar5  )   CALL dia_ar5( kstp )         ! ar5 diag
+      IF( lk_diaharm )   CALL dia_harm( kstp )        ! Tidal harmonic analysis
+                         CALL dia_wri( kstp )         ! ocean model: outputs
       !
       IF( ln_crs     )   CALL crs_fld       ( kstp )  ! ocean model: online field coarsening & output
-
+      
 #if defined key_top
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -293,9 +293,9 @@
 !!    place.
 !! 
-!!jc2: dynnxt must be the latest call. fse3t_b are indeed updated in that routine
+!!jc2: dynnxt must be the latest call. e3t_b are indeed updated in that routine
                          CALL tra_nxt       ( kstp )  ! finalize (bcs) tracer fields at next time step and swap
                          CALL dyn_nxt       ( kstp )  ! finalize (bcs) velocities at next time step and swap
                          CALL ssh_swp       ( kstp )  ! swap of sea surface height
-      IF( lk_vvl     )   CALL dom_vvl_sf_swp( kstp )  ! swap of vertical scale factors
+      IF(.NOT.ln_linssh) CALL dom_vvl_sf_swp( kstp )  ! swap of vertical scale factors
       !
 
@@ -313,12 +313,12 @@
                          CALL Agrif_Integrate_ChildGrids( stp )  
 
-      IF ( Agrif_NbStepint().EQ.0 ) THEN              ! AGRIF Update 
-!!jc in fact update i useless at last time step, but do it for global diagnostics
+      IF( Agrif_NbStepint() == 0 ) THEN               ! AGRIF Update 
+!!jc in fact update is useless at last time step, but do it for global diagnostics
                          CALL Agrif_Update_Tra()      ! Update active tracers
                          CALL Agrif_Update_Dyn()      ! Update momentum
       ENDIF
 #endif
-      IF( ln_diahsb  )   CALL dia_hsb       ( kstp )  ! - ML - global conservation diagnostics
-      IF( lk_diaobs  )   CALL dia_obs       ( kstp )  ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
+      IF( ln_diahsb  )   CALL dia_hsb( kstp )         ! - ML - global conservation diagnostics
+      IF( ln_diaobs  )   CALL dia_obs( kstp )         ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -326,9 +326,9 @@
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                          CALL stp_ctl       ( kstp, indic )
-      IF( indic < 0  )   THEN
+      IF( indic < 0  ) THEN
                          CALL ctl_stop( 'step: indic < 0' )
                          CALL dia_wri_state( 'output.abort', kstp )
       ENDIF
-      IF( kstp == nit000 )   THEN
+      IF( kstp == nit000 ) THEN
                  CALL iom_close( numror )     ! close input  ocean restart file
          IF(lwm) CALL FLUSH    ( numond )     ! flush output namelist oce
@@ -353,5 +353,4 @@
       !
    END SUBROUTINE stp
-
-   !!======================================================================
+   
 END MODULE step
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/step_oce.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 6140)
@@ -72,4 +72,9 @@
    USE zdfmxl           ! Mixed-layer depth                (zdf_mxl routine)
 
+   USE step_diu        ! Time stepping for diurnal sst
+   USE diurnal_bulk    ! diurnal SST bulk routines  (diurnal_sst_takaya routine) 
+   USE cool_skin       ! diurnal cool skin correction (diurnal_sst_coolskin routine)   
+   USE sbc_oce         ! surface fluxes  
+   
    USE zpshde           ! partial step: hor. derivative     (zps_hde routine)
 
@@ -82,4 +87,5 @@
    USE diahsb           ! heat, salt and volume budgets    (dia_hsb routine)
    USE diaharm
+   USE diacfl
    USE flo_oce          ! floats variables
    USE floats           ! floats computation               (flo_stp routine)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/stpctl.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/stpctl.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/stpctl.F90	(revision 6140)
@@ -16,8 +16,9 @@
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables 
+   USE c1d             ! 1D vertical configuration
+   !
    USE in_out_manager  ! I/O manager
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp         ! distributed memory computing
-   USE c1d             ! 1D vertical configuration
 
    IMPLICIT NONE
@@ -30,5 +31,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -46,14 +46,14 @@
       !!                
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
-      INTEGER, INTENT( inout ) ::   kindic  ! error indicator
+      INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
+      INTEGER, INTENT(inout) ::   kindic   ! error indicator
       !!
-      INTEGER  ::   ji, jj, jk              ! dummy loop indices
-      INTEGER  ::   ii, ij, ik              ! temporary integers
-      REAL(wp) ::   zumax, zsmin, zssh2     ! temporary scalars
-      INTEGER, DIMENSION(3) ::   ilocu      ! 
-      INTEGER, DIMENSION(2) ::   ilocs      ! 
+      INTEGER  ::   ji, jj, jk             ! dummy loop indices
+      INTEGER  ::   ii, ij, ik             ! local integers
+      REAL(wp) ::   zumax, zsmin, zssh2    ! local scalars
+      INTEGER, DIMENSION(3) ::   ilocu     ! 
+      INTEGER, DIMENSION(2) ::   ilocs     ! 
       !!----------------------------------------------------------------------
-
+      !
       IF( kt == nit000 .AND. lwp ) THEN
          WRITE(numout,*)
@@ -63,8 +63,8 @@
          CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
       ENDIF
-
+      !
       IF(lwp) WRITE ( numstp, '(1x, i8)' )   kt      !* save the current time step in numstp
       IF(lwp) REWIND( numstp )                       !  --------------------------
-
+      !
       !                                              !* Test maximum of velocity (zonal only)
       !                                              !  ------------------------
@@ -102,9 +102,9 @@
       ENDIF
 9400  FORMAT (' kt=',i6,' max abs(U): ',1pg11.4,', i j k: ',3i5)
-
+      !
       !                                              !* Test minimum of salinity
       !                                              !  ------------------------
       !! zsmin = MINVAL( tsn(:,:,1,jp_sal), mask = tmask(:,:,1) == 1.e0 )  slower than the following loop on NEC SX5
-      zsmin = 100.e0
+      zsmin = 100._wp
       DO jj = 2, jpjm1
          DO ji = 1, jpi
@@ -136,6 +136,6 @@
       ENDIF
 9500  FORMAT (' kt=',i6,' min SSS: ',1pg11.4,', i j: ',2i5)
-
-      
+      !
+      !
       IF( lk_c1d )  RETURN          ! No log file in case of 1D vertical configuration
 
@@ -151,5 +151,4 @@
       IF(lwp) WRITE(numsol,9300) kt, zssh2, zumax, zsmin      ! ssh statistics
       !
-
 9200  FORMAT('it:', i8, ' iter:', i4, ' r: ',e16.10, ' b: ',e16.10 )
 9300  FORMAT(' it :', i8, ' ssh2: ', e16.10, ' Umax: ',e16.10,' Smin: ',e16.10)
Index: /trunk/NEMOGCM/NEMO/OPA_SRC/trc_oce.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OPA_SRC/trc_oce.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/OPA_SRC/trc_oce.F90	(revision 6140)
@@ -8,10 +8,11 @@
 
    !!----------------------------------------------------------------------
-   !!   trc_oce_rgb : tabulated attenuation coefficients for RGB light penetration         
-   !!----------------------------------------------------------------------
-   USE par_oce
-   USE in_out_manager  ! I/O manager
-   USE dom_oce         ! ocean space and time domain
-   USE lib_mpp         ! MPP library
+   !!   trc_oce_rgb   : tabulated attenuation coefficients for RGB light penetration         
+   !!----------------------------------------------------------------------
+   USE par_oce        ! ocean parameters
+   USE dom_oce        ! ocean space and time domain
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
 
    IMPLICIT NONE
@@ -41,5 +42,4 @@
    LOGICAL, PUBLIC, PARAMETER ::   lk_qsr_bio = .FALSE.   !: bio-model light absorption flag
 #endif
-
 #if defined key_offline
    !!----------------------------------------------------------------------
@@ -64,7 +64,4 @@
    LOGICAL, PUBLIC, PARAMETER ::   lk_degrad = .FALSE.   !: degradation flag
 #endif
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -104,5 +101,5 @@
       !!----------------------------------------------------------------------
       REAL(wp), DIMENSION(3,61), INTENT(out) ::   prgb   ! tabulated attenuation coefficient
-      !!
+      !
       INTEGER  ::   jc     ! dummy loop indice
       INTEGER  ::   irgb   ! temporary integer
@@ -188,5 +185,5 @@
          zchl = zrgb(1,jc)
          irgb = NINT( 41 + 20.* LOG10( zchl ) + 1.e-15 )
-         IF(lwp) WRITE(numout,*) '    jc =', jc, '  Chl = ', zchl, '  irgb = ', irgb
+         IF(lwp .AND. nn_print >= 1 ) WRITE(numout,*) '    jc =', jc, '  Chl = ', zchl, '  irgb = ', irgb
          IF( irgb /= jc ) THEN
             IF(lwp) WRITE(numout,*) '    jc =', jc, '  Chl = ', zchl, '  Chl class = ', irgb
@@ -210,5 +207,5 @@
       !!----------------------------------------------------------------------
       REAL(wp), DIMENSION(3,61), INTENT(out) ::   prgb   ! tabulated attenuation coefficient
-      !!
+      !
       INTEGER  ::   jc, jb ! dummy loop indice
       INTEGER  ::   irgb   ! temporary integer
@@ -262,5 +259,5 @@
       REAL(wp), INTENT(in) ::   prldex    ! longest depth of extinction
       REAL(wp), INTENT(in) ::   pqsr_frc  ! frac. solar radiation which penetrates 
-      !!
+      !
       INTEGER  ::   jk, pjl            ! levels
       REAL(wp) ::   zhext              ! deepest level till which light penetrates
@@ -276,5 +273,5 @@
       DO jk = jpkm1, 1, -1
          IF(SUM(tmask(:,:,jk)) > 0 ) THEN
-            zem = MAXVAL( fsdepw(:,:,jk+1) * tmask(:,:,jk) )
+            zem = MAXVAL( gdepw_0(:,:,jk+1) * tmask(:,:,jk) )
             IF( zem >= zhext )   pjl = jk                       ! last T-level reached by Qsr
          ELSE
Index: /trunk/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90	(revision 6140)
@@ -0,0 +1,647 @@
+MODULE nemogcm
+   !!======================================================================
+   !!                       ***  MODULE nemogcm   ***
+   !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
+   !!======================================================================
+   !! History :  OPA  ! 1990-10  (C. Levy, G. Madec)  Original code
+   !!            7.0  ! 1991-11  (M. Imbard, C. Levy, G. Madec)
+   !!            7.1  ! 1993-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
+   !!                             P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
+   !!             -   ! 1992-06  (L.Terray)  coupling implementation
+   !!             -   ! 1993-11  (M.A. Filiberti) IGLOO sea-ice
+   !!            8.0  ! 1996-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
+   !!                             P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
+   !!            8.1  ! 1997-06  (M. Imbard, G. Madec)
+   !!            8.2  ! 1999-11  (M. Imbard, H. Goosse)  LIM sea-ice model
+   !!                 ! 1999-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP
+   !!                 ! 2000-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
+   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and modules
+   !!             -   ! 2004-06  (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
+   !!             -   ! 2004-08  (C. Talandier) New trends organization
+   !!             -   ! 2005-06  (C. Ethe) Add the 1D configuration possibility
+   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
+   !!             -   ! 2006-03  (L. Debreu, C. Mazauric)  Agrif implementation
+   !!             -   ! 2006-04  (G. Madec, R. Benshila)  Step reorganization
+   !!             -   ! 2007-07  (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
+   !!            3.2  ! 2009-08  (S. Masson)  open/write in the listing file in mpp
+   !!            3.3  ! 2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
+   !!             -   ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
+   !!            3.3.1! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
+   !!            3.4  ! 2011-11  (C. Harris) decomposition changes for running with CICE
+   !!                 ! 2012-05  (C. Calone, J. Simeon, G. Madec, C. Ethe) Add grid coarsening 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   nemo_gcm       : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
+   !!   nemo_init      : initialization of the NEMO system
+   !!   nemo_ctl       : initialisation of the contol print
+   !!   nemo_closefile : close remaining open files
+   !!   nemo_alloc     : dynamical allocation
+   !!   nemo_partition : calculate MPP domain decomposition
+   !!   factorise      : calculate the factors of the no. of MPI processes
+   !!----------------------------------------------------------------------
+   USE step_oce        ! module used in the ocean time stepping module
+   USE domcfg          ! domain configuration               (dom_cfg routine)
+   USE mppini          ! shared/distributed memory setting (mpp_init routine)
+   USE domain          ! domain initialization             (dom_init routine)
+#if defined key_nemocice_decomp
+   USE ice_domain_size, only: nx_global, ny_global
+#endif
+   USE istate          ! initial state setting          (istate_init routine)
+   USE phycst          ! physical constant                  (par_cst routine)
+   USE diaobs          ! Observation diagnostics       (dia_obs_init routine)
+   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
+   USE step            ! NEMO time-stepping                 (stp     routine)
+   USE cpl_oasis3      ! OASIS3 coupling
+   USE lib_mpp         ! distributed memory computing
+#if defined key_iomput
+   USE xios
+#endif
+   USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges 
+
+   ! Stand Alone Observation operator modules
+   USE sao_data
+   USE sao_intp
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   nemo_gcm    ! called by model.F90
+   PUBLIC   nemo_init   ! needed by AGRIF
+   PUBLIC   nemo_alloc  ! needed by TAM
+
+   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE nemo_gcm
+         !!----------------------------------------------------------------------
+         !!                    ***  SUBROUTINE offline_obs_oper ***
+         !!
+         !! ** Purpose : To use NEMO components to interpolate model fields
+         !!              to observation space.
+         !!
+         !! ** Method : 1. Initialise NEMO
+         !!             2. Initialise offline obs_oper
+         !!             3. Cycle through match ups
+         !!             4. Write results to file
+         !!
+         !!----------------------------------------------------------------------
+         !! Initialise NEMO
+         CALL nemo_init
+         !! Initialise Stand Alone Observation operator data
+         CALL sao_data_init
+         !! Initialise obs_oper
+         CALL dia_obs_init
+         !! Interpolate to observation space
+         CALL sao_interp
+         !! Pipe to output files
+         CALL dia_obs_wri
+         !! Reset the obs_oper between
+         CALL dia_obs_dealloc
+         !! Safely stop MPI
+         IF(lk_mpp) CALL mppstop  ! end mpp communications
+   END SUBROUTINE nemo_gcm
+
+
+   SUBROUTINE nemo_init
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE nemo_init  ***
+      !!
+      !! ** Purpose :   initialization of the NEMO GCM
+      !!----------------------------------------------------------------------
+      INTEGER ::   ji            ! dummy loop indices
+      INTEGER ::   ilocal_comm   ! local integer
+      INTEGER ::   ios
+      CHARACTER(len=80), DIMENSION(16) ::   cltxt
+      !
+      NAMELIST/namctl/ ln_ctl, nn_print, nn_ictls, nn_ictle,   &
+         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
+         &             nn_bench, nn_timing
+      NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
+         &             jpizoom, jpjzoom, jperio, ln_use_jattr
+      !!----------------------------------------------------------------------
+      !
+      cltxt = ''
+      cxios_context = 'nemo'
+      !
+      !                             ! Open reference namelist and configuration namelist files
+      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
+      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
+      !
+      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints & Benchmark
+      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
+
+      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
+      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
+
+      !
+      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints & Benchmark
+      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
+
+      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
+      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
+904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
+
+! Force values for AGRIF zoom (cf. agrif_user.F90)
+#if defined key_agrif
+   IF( .NOT. Agrif_Root() ) THEN
+      jpiglo  = nbcellsx + 2 + 2*nbghostcells
+      jpjglo  = nbcellsy + 2 + 2*nbghostcells
+      jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
+      jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
+      jpidta  = jpiglo
+      jpjdta  = jpjglo
+      jpizoom = 1
+      jpjzoom = 1
+      nperio  = 0
+      jperio  = 0
+      ln_use_jattr = .false.
+   ENDIF
+#endif
+      !
+      !                             !--------------------------------------------!
+      !                             !  set communicator & select the local node  !
+      !                             !  NB: mynode also opens output.namelist.dyn !
+      !                             !      on unit number numond on first proc   !
+      !                             !--------------------------------------------!
+#if defined key_iomput
+      IF( Agrif_Root() ) THEN
+         IF( lk_oasis ) THEN
+            CALL cpl_init( "oceanx", ilocal_comm )                     ! nemo local communicator given by oasis
+            CALL xios_initialize( "not used",local_comm=ilocal_comm )    ! send nemo communicator to xios
+         ELSE
+            CALL  xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
+         ENDIF
+      ENDIF
+      ! Nodes selection (control print return in cltxt)
+      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
+#else
+      IF( lk_oasis ) THEN
+         IF( Agrif_Root() ) THEN
+            CALL cpl_init( "oceanx", ilocal_comm )                      ! nemo local communicator given by oasis
+         ENDIF
+         ! Nodes selection (control print return in cltxt)
+         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
+      ELSE
+         ilocal_comm = 0
+         ! Nodes selection (control print return in cltxt)
+         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )
+      ENDIF
+#endif
+      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
+
+      lwm = (narea == 1)                                    ! control of output namelists
+      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
+
+      IF(lwm) THEN
+         ! write merged namelists from earlier to output namelist now that the
+         ! file has been opened in call to mynode. nammpp has already been
+         ! written in mynode (if lk_mpp_mpi)
+         WRITE( numond, namctl )
+         WRITE( numond, namcfg )
+      ENDIF
+
+      ! If dimensions of processor grid weren't specified in the namelist file
+      ! then we calculate them here now that we have our communicator size
+      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
+#if   defined key_mpp_mpi
+         IF( Agrif_Root() ) CALL nemo_partition(mppsize)
+#else
+         jpni  = 1
+         jpnj  = 1
+         jpnij = jpni*jpnj
+#endif
+      END IF
+
+      ! Calculate domain dimensions given calculated jpni and jpnj
+      ! This used to be done in par_oce.F90 when they were parameters rather
+      ! than variables
+      IF( Agrif_Root() ) THEN
+#if defined key_nemocice_decomp
+         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first  dim.
+         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim. 
+#else
+         jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
+         jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
+#endif
+      ENDIF
+         jpk = jpkdta                                             ! third dim
+         jpim1 = jpi-1                                            ! inner domain indices
+         jpjm1 = jpj-1                                            !   "           "
+         jpkm1 = jpk-1                                            !   "           "
+         jpij  = jpi*jpj                                          !  jpi x j
+
+      IF(lwp) THEN                            ! open listing units
+         !
+         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
+         !
+         WRITE(numout,*)
+         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
+         WRITE(numout,*) '                       NEMO team'
+         WRITE(numout,*) '            Stand Alone Observation operator'
+         WRITE(numout,*) '                  version 1.0  (2015) '
+         WRITE(numout,*)
+         WRITE(numout,*)
+         DO ji = 1, SIZE(cltxt)
+            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
+         END DO
+         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
+         !
+      ENDIF
+
+      ! Now we know the dimensions of the grid and numout has been set we can
+      ! allocate arrays
+      CALL nemo_alloc()
+
+      !                             !-------------------------------!
+      !                             !  NEMO general initialization  !
+      !                             !-------------------------------!
+
+      CALL nemo_ctl                          ! Control prints & Benchmark
+
+      !                                      ! Domain decomposition
+      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
+      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
+      ENDIF
+      !
+      IF( nn_timing == 1 )  CALL timing_init
+      !
+      !                                      ! General initialization
+                            CALL     phy_cst    ! Physical constants
+                            CALL     eos_init   ! Equation of state
+                            CALL     dom_cfg    ! Domain configuration
+                            CALL     dom_init   ! Domain
+
+      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
+
+      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
+
+                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
+   END SUBROUTINE nemo_init
+
+
+   SUBROUTINE nemo_ctl
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE nemo_ctl  ***
+      !!
+      !! ** Purpose :   control print setting
+      !!
+      !! ** Method  : - print namctl information and check some consistencies
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) THEN                  ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
+         WRITE(numout,*) '~~~~~~~ '
+         WRITE(numout,*) '   Namelist namctl'
+         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
+         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
+         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
+         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
+         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
+         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
+         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
+         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
+         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
+         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
+      ENDIF
+      !
+      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
+      nictls    = nn_ictls
+      nictle    = nn_ictle
+      njctls    = nn_jctls
+      njctle    = nn_jctle
+      isplt     = nn_isplt
+      jsplt     = nn_jsplt
+      nbench    = nn_bench
+
+      IF(lwp) THEN                  ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
+         WRITE(numout,*) '~~~~~~~ '
+         WRITE(numout,*) '   Namelist namcfg'
+         WRITE(numout,*) '      configuration name              cp_cfg      = ', TRIM(cp_cfg)
+         WRITE(numout,*) '      configuration zoom name         cp_cfz      = ', TRIM(cp_cfz)
+         WRITE(numout,*) '      configuration resolution        jp_cfg      = ', jp_cfg
+         WRITE(numout,*) '      1st lateral dimension ( >= jpi ) jpidta     = ', jpidta
+         WRITE(numout,*) '      2nd    "         "    ( >= jpj ) jpjdta     = ', jpjdta
+         WRITE(numout,*) '      3nd    "         "               jpkdta     = ', jpkdta
+         WRITE(numout,*) '      1st dimension of global domain in i jpiglo  = ', jpiglo
+         WRITE(numout,*) '      2nd    -                  -    in j jpjglo  = ', jpjglo
+         WRITE(numout,*) '      left bottom i index of the zoom (in data domain) jpizoom = ', jpizoom
+         WRITE(numout,*) '      left bottom j index of the zoom (in data domain) jpizoom = ', jpjzoom
+         WRITE(numout,*) '      lateral cond. type (between 0 and 6) jperio = ', jperio   
+         WRITE(numout,*) '      use file attribute if exists as i/p j-start ln_use_jattr = ', ln_use_jattr
+      ENDIF
+      !                             ! Parameter control
+      !
+      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
+         IF( lk_mpp .AND. jpnij > 1 ) THEN
+            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
+         ELSE
+            IF( isplt == 1 .AND. jsplt == 1  ) THEN
+               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
+                  &           ' - the print control will be done over the whole domain' )
+            ENDIF
+            ijsplt = isplt * jsplt            ! total number of processors ijsplt
+         ENDIF
+         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
+         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
+         !
+         !                              ! indices used for the SUM control
+         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
+            lsp_area = .FALSE.
+         ELSE                                             ! print control done over a specific  area
+            lsp_area = .TRUE.
+            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
+               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
+               nictls = 1
+            ENDIF
+            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
+               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
+               nictle = jpiglo
+            ENDIF
+            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
+               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
+               njctls = 1
+            ENDIF
+            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
+               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
+               njctle = jpjglo
+            ENDIF
+         ENDIF
+      ENDIF
+      !
+      IF( nbench == 1 ) THEN              ! Benchmark
+         SELECT CASE ( cp_cfg )
+         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
+         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
+            &                                 ' cp_cfg = "gyre" in namelist &namcfg or set nbench = 0' )
+         END SELECT
+      ENDIF
+      !
+      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
+         &                                               'f2003 standard. '                              ,  &
+         &                                               'Compile with key_nosignedzero enabled' )
+      !
+   END SUBROUTINE nemo_ctl
+
+
+   SUBROUTINE nemo_closefile
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE nemo_closefile  ***
+      !!
+      !! ** Purpose :   Close the files
+      !!----------------------------------------------------------------------
+      !
+      IF( lk_mpp )   CALL mppsync
+      !
+      CALL iom_close                                 ! close all input/output files managed by iom_*
+      !
+      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
+      IF( numsol          /= -1 )   CLOSE( numsol          )   ! solver file
+      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
+      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
+      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
+      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
+      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
+      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
+      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
+      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
+      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
+      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
+      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
+
+      !
+      numout = 6                                     ! redefine numout in case it is used after this point...
+      !
+   END SUBROUTINE nemo_closefile
+
+
+   SUBROUTINE nemo_alloc
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE nemo_alloc  ***
+      !!
+      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
+      !!
+      !! ** Method  :
+      !!----------------------------------------------------------------------
+      USE diawri    , ONLY: dia_wri_alloc
+      USE dom_oce   , ONLY: dom_oce_alloc
+      !
+      INTEGER :: ierr
+      !!----------------------------------------------------------------------
+      !
+      ierr =        oce_alloc       ()          ! ocean
+      ierr = ierr + dia_wri_alloc   ()
+      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
+      !
+      IF( lk_mpp    )   CALL mpp_sum( ierr )
+      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
+      !
+   END SUBROUTINE nemo_alloc
+
+
+   SUBROUTINE nemo_partition( num_pes )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE nemo_partition  ***
+      !!
+      !! ** Purpose :
+      !!
+      !! ** Method  :
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
+      !
+      INTEGER, PARAMETER :: nfactmax = 20
+      INTEGER :: nfact ! The no. of factors returned
+      INTEGER :: ierr  ! Error flag
+      INTEGER :: ji
+      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
+      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
+      !!----------------------------------------------------------------------
+      !
+      ierr = 0
+      !
+      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
+      !
+      IF( nfact <= 1 ) THEN
+         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
+         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
+         jpnj = 1
+         jpni = num_pes
+      ELSE
+         ! Search through factors for the pair that are closest in value
+         mindiff = 1000000
+         imin    = 1
+         DO ji = 1, nfact-1, 2
+            idiff = ABS( ifact(ji) - ifact(ji+1) )
+            IF( idiff < mindiff ) THEN
+               mindiff = idiff
+               imin = ji
+            ENDIF
+         END DO
+         jpnj = ifact(imin)
+         jpni = ifact(imin + 1)
+      ENDIF
+      !
+      jpnij = jpni*jpnj
+      !
+   END SUBROUTINE nemo_partition
+
+
+   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE factorise  ***
+      !!
+      !! ** Purpose :   return the prime factors of n.
+      !!                knfax factors are returned in array kfax which is of
+      !!                maximum dimension kmaxfax.
+      !! ** Method  :
+      !!----------------------------------------------------------------------
+      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
+      INTEGER                    , INTENT(  out) ::   kerr, knfax
+      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
+      !
+      INTEGER :: ifac, jl, inu
+      INTEGER, PARAMETER :: ntest = 14
+      INTEGER :: ilfax(ntest)
+      !
+      ! lfax contains the set of allowed factors.
+      data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
+         &                            128,   64,   32,   16,    8,   4,   2  /
+      !!----------------------------------------------------------------------
+
+      ! Clear the error flag and initialise output vars
+      kerr = 0
+      kfax = 1
+      knfax = 0
+
+      ! Find the factors of n.
+      IF( kn == 1 )   GOTO 20
+
+      ! nu holds the unfactorised part of the number.
+      ! knfax holds the number of factors found.
+      ! l points to the allowed factor list.
+      ! ifac holds the current factor.
+
+      inu   = kn
+      knfax = 0
+
+      DO jl = ntest, 1, -1
+         !
+         ifac = ilfax(jl)
+         IF( ifac > inu )   CYCLE
+
+         ! Test whether the factor will divide.
+
+         IF( MOD(inu,ifac) == 0 ) THEN
+            !
+            knfax = knfax + 1            ! Add the factor to the list
+            IF( knfax > kmaxfax ) THEN
+               kerr = 6
+               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
+               return
+            ENDIF
+            kfax(knfax) = ifac
+            ! Store the other factor that goes with this one
+            knfax = knfax + 1
+            kfax(knfax) = inu / ifac
+            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
+         ENDIF
+         !
+      END DO
+
+   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
+      !
+   END SUBROUTINE factorise
+
+#if defined key_mpp_mpi
+
+   SUBROUTINE nemo_northcomms
+      !!======================================================================
+      !!                     ***  ROUTINE  nemo_northcomms  ***
+      !! nemo_northcomms    :  Setup for north fold exchanges with explicit 
+      !!                       point-to-point messaging
+      !!=====================================================================
+      !!----------------------------------------------------------------------
+      !!
+      !! ** Purpose :   Initialization of the northern neighbours lists.
+      !!----------------------------------------------------------------------
+      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
+      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC) 
+      !!----------------------------------------------------------------------
+
+      INTEGER  ::   sxM, dxM, sxT, dxT, jn
+      INTEGER  ::   njmppmax
+
+      njmppmax = MAXVAL( njmppt )
+    
+      !initializes the north-fold communication variables
+      isendto(:) = 0
+      nsndto = 0
+
+      !if I am a process in the north
+      IF ( njmpp == njmppmax ) THEN
+          !sxM is the first point (in the global domain) needed to compute the
+          !north-fold for the current process
+          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
+          !dxM is the last point (in the global domain) needed to compute the
+          !north-fold for the current process
+          dxM = jpiglo - nimppt(narea) + 2
+
+          !loop over the other north-fold processes to find the processes
+          !managing the points belonging to the sxT-dxT range
+  
+          DO jn = 1, jpni
+                !sxT is the first point (in the global domain) of the jn
+                !process
+                sxT = nfiimpp(jn, jpnj)
+                !dxT is the last point (in the global domain) of the jn
+                !process
+                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
+                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
+                   nsndto = nsndto + 1
+                     isendto(nsndto) = jn
+                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
+                   nsndto = nsndto + 1
+                     isendto(nsndto) = jn
+                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
+                   nsndto = nsndto + 1
+                     isendto(nsndto) = jn
+                END IF
+          END DO
+          nfsloop = 1
+          nfeloop = nlci
+          DO jn = 2,jpni-1
+           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
+              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
+                 nfsloop = nldi
+              ENDIF
+              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
+                 nfeloop = nlei
+              ENDIF
+           ENDIF
+        END DO
+
+      ENDIF
+      l_north_nogather = .TRUE.
+   END SUBROUTINE nemo_northcomms
+#else
+   SUBROUTINE nemo_northcomms      ! Dummy routine
+      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
+   END SUBROUTINE nemo_northcomms
+#endif
+
+   !!======================================================================
+END MODULE nemogcm
+
+
Index: /trunk/NEMOGCM/NEMO/SAO_SRC/obs_fbm.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/SAO_SRC/obs_fbm.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/SAO_SRC/obs_fbm.F90	(revision 6140)
@@ -0,0 +1,1 @@
+link ../OPA_SRC/OBS/obs_fbm.F90
Index: /trunk/NEMOGCM/NEMO/SAO_SRC/sao.nml
===================================================================
--- /trunk/NEMOGCM/NEMO/SAO_SRC/sao.nml	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/SAO_SRC/sao.nml	(revision 6140)
@@ -0,0 +1,10 @@
+!----------------------------------------------------------------------
+!       namsao Stand Alone Observation operator namelist
+!----------------------------------------------------------------------
+!   sao_files     specifies the files containing the model counterpart
+!   nn_sao_idx    specifies the index within the model file
+!   nn_sao_freq   specifies the number of timesteps between file reads
+&namsao
+   sao_files = 'fcst.0.nc'
+   nn_sao_idx = 1
+/
Index: /trunk/NEMOGCM/NEMO/SAO_SRC/sao_data.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/SAO_SRC/sao_data.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/SAO_SRC/sao_data.F90	(revision 6140)
@@ -0,0 +1,82 @@
+MODULE sao_data
+   !! =================================================================
+   !!                    *** MODULE sao_data ***
+   !! =================================================================
+   USE par_kind, ONLY: lc
+   USE lib_mpp         ! distributed memory computing
+
+   IMPLICIT NONE
+
+   !! Public data
+
+   INTEGER, PARAMETER :: MaxNumFiles = 1000
+
+   !! Stand Alone Observation operator settings
+   CHARACTER(len=lc) :: &
+      & sao_files(MaxNumFiles)         !: model files
+   INTEGER            :: &
+      & n_files, &                     !: number of files
+      & nn_sao_idx(MaxNumFiles), &     !: time_counter indices
+      & nn_sao_freq                    !: read frequency in time steps
+CONTAINS
+   SUBROUTINE sao_data_init()
+      !!----------------------------------------------------------------------
+      !!                    ***  SUBROUTINE sao_data_init ***
+      !!
+      !! ** Purpose : To read namelists and initialise offline_oper run.
+      !!
+      !!----------------------------------------------------------------------
+      USE in_out_manager
+      INTEGER            :: &
+         & jf                           !: file dummy loop index
+      LOGICAL :: lmask(MaxNumFiles)     !: Logical mask used for counting
+      INTEGER :: ios
+
+      ! Standard offline obs_oper information
+      NAMELIST/namsao/sao_files, nn_sao_idx, nn_sao_freq
+
+      ! Standard offline obs_oper initialisation
+      n_files = 0                   !: number of files to cycle through
+      sao_files(:) = ''             !: list of files to read in
+      nn_sao_idx(:) = 0             !: list of indices inside each file
+      nn_sao_freq = -1              !: input frequency in time steps
+
+      ! Standard offline obs_oper settings
+      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints & Benchmark
+      READ  ( numnam_ref, namsao, IOSTAT = ios, ERR = 901 )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsao in reference namelist', .TRUE. )
+
+      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
+      READ  ( numnam_cfg, namsao, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsao in configuration namelist', .TRUE. )
+
+
+      ! count input files
+      lmask(:) = .FALSE.
+      WHERE (sao_files(:) /= '') lmask(:) = .TRUE.
+      n_files = COUNT(lmask)
+
+      !! Initialise sub obs window frequency
+      IF (nn_sao_freq == -1) THEN
+         !! Run length
+         nn_sao_freq = nitend - nit000 + 1
+      ENDIF
+
+      !! Print summary of settings
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'offline obs_oper : Initialization'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namsao : set stand alone obs_oper parameters'
+         DO jf = 1, n_files
+            WRITE(numout,'(1X,2A)') '   Input forecast file name          forecastfile = ', &
+               TRIM(sao_files(jf))
+            WRITE(numout,*) '   Input forecast file index        forecastindex = ', &
+               nn_sao_idx(jf)
+         END DO
+      END IF
+
+   END SUBROUTINE sao_data_init
+
+END MODULE sao_data
+
Index: /trunk/NEMOGCM/NEMO/SAO_SRC/sao_intp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/SAO_SRC/sao_intp.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/SAO_SRC/sao_intp.F90	(revision 6140)
@@ -0,0 +1,48 @@
+MODULE sao_intp
+   !!======================================================================
+   !!                    ***  MODULE sao_intp ***
+   !! ** Purpose : Run NEMO observation operator in offline mode
+   !!======================================================================
+   !! NEMO modules
+   USE in_out_manager
+   USE diaobs
+   !! Stand Alone Observation operator modules
+   USE sao_read
+   USE sao_data
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC sao_interp
+
+   CONTAINS
+
+      SUBROUTINE sao_interp
+         !!----------------------------------------------------------------------
+         !!                    ***  SUBROUTINE sao_interp ***
+         !!
+         !! ** Purpose : To interpolate the model as if it were running online.
+         !!
+         !! ** Method : 1. Populate model counterparts
+         !!             2. Call dia_obs at appropriate time steps
+         !!----------------------------------------------------------------------
+         INTEGER :: &
+            & istp, & ! time step index
+            & ifile   ! file index
+         istp = nit000 - 1
+         nstop = 0
+         ifile = 1
+         CALL sao_rea_dri(ifile)
+         DO WHILE ( istp <= nitend .AND. nstop == 0 )
+            IF (ifile <= n_files + 1) THEN
+               IF ( MOD(istp, nn_sao_freq) == nit000 ) THEN
+                  CALL sao_rea_dri(ifile)
+                  ifile = ifile + 1
+               ENDIF
+               CALL dia_obs(istp)
+            ENDIF
+            istp = istp + 1
+         END DO
+      END SUBROUTINE sao_interp
+
+END MODULE sao_intp
Index: /trunk/NEMOGCM/NEMO/SAO_SRC/sao_read.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/SAO_SRC/sao_read.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/SAO_SRC/sao_read.F90	(revision 6140)
@@ -0,0 +1,172 @@
+MODULE sao_read
+   !!==================================================================
+   !!                    *** MODULE sao_read ***
+   !! Read routines : I/O for Stand Alone Observation operator
+   !!==================================================================
+   USE mppini
+   USE lib_mpp
+   USE in_out_manager
+   USE par_kind, ONLY: lc
+   USE netcdf
+   USE oce,     ONLY: tsn, sshn
+   USE dom_oce, ONLY: nlci, nlcj, nimpp, njmpp, tmask
+   USE par_oce, ONLY: jpi, jpj, jpk
+   USE obs_fbm, ONLY: fbimdi, fbrmdi, fbsp, fbdp
+   USE sao_data
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC sao_rea_dri
+
+CONTAINS
+   SUBROUTINE sao_rea_dri(kfile)
+      !!------------------------------------------------------------------------
+      !!             *** sao_rea_dri ***
+      !!
+      !! Purpose : To choose appropriate read method
+      !! Method  :
+      !!
+      !! Author  : A. Ryan Oct 2013
+      !!
+      !!------------------------------------------------------------------------
+      INTEGER, INTENT(IN) :: &
+              & kfile         !: File number
+      CHARACTER(len=lc) :: &
+              & cdfilename    !: File name
+      INTEGER :: &
+              & kindex        !: File index to read
+
+      cdfilename = TRIM(sao_files(kfile))
+      kindex = nn_sao_idx(kfile)
+      CALL sao_read_file(TRIM(cdfilename), kindex)
+
+   END SUBROUTINE sao_rea_dri
+
+   SUBROUTINE sao_read_file(filename, ifcst)
+      !!------------------------------------------------------------------------
+      !!             *** sao_read_file ***
+      !!
+      !! Purpose : To fill tn and sn with dailymean field from netcdf files
+      !! Method  : Use subdomain indices to create start and count matrices
+      !!           for netcdf read.
+      !!
+      !! Author  : A. Ryan Oct 2010
+      !!------------------------------------------------------------------------
+
+      INTEGER,          INTENT(IN) :: ifcst
+      CHARACTER(len=*), INTENT(IN) :: filename
+      INTEGER                      :: ncid, &
+                                    & varid,&
+                                    & istat,&
+                                    & ntimes,&
+                                    & tdim, &
+                                    & xdim, &
+                                    & ydim, &
+                                    & zdim
+      INTEGER                      :: ii, ij, ik
+      INTEGER, DIMENSION(4)        :: start_n, &
+                                    & count_n
+      INTEGER, DIMENSION(3)        :: start_s, &
+                                    & count_s
+      REAL(fbdp), DIMENSION(:,:,:),ALLOCATABLE :: temp_tn, &
+                                              & temp_sn
+      REAL(fbdp), DIMENSION(:,:),  ALLOCATABLE :: temp_sshn
+      REAL(fbdp)                     :: fill_val
+
+      ! DEBUG
+      INTEGER :: istage
+
+      IF (TRIM(filename) == 'nofile') THEN
+         tsn(:,:,:,:) = fbrmdi
+         sshn(:,:) = fbrmdi
+      ELSE
+         WRITE(numout,*) "Opening :", TRIM(filename)
+         ! Open Netcdf file to find dimension id
+         istat = nf90_open(path=TRIM(filename), mode=nf90_nowrite, ncid=ncid)
+         IF ( istat /= nf90_noerr ) THEN
+             WRITE(numout,*) "WARNING: Could not open ", trim(filename)
+             WRITE(numout,*) "ERROR: ", nf90_strerror(istat)
+         ENDIF
+         istat = nf90_inq_dimid(ncid,'x',xdim)
+         istat = nf90_inq_dimid(ncid,'y',ydim)
+         istat = nf90_inq_dimid(ncid,'deptht',zdim)
+         istat = nf90_inq_dimid(ncid,'time_counter',tdim)
+         istat = nf90_inquire_dimension(ncid, tdim, len=ntimes)
+         IF (ifcst .LE. ntimes) THEN
+            ! Allocate temporary temperature array
+            ALLOCATE(temp_tn(nlci,nlcj,jpk))
+            ALLOCATE(temp_sn(nlci,nlcj,jpk))
+            ALLOCATE(temp_sshn(nlci,nlcj))
+
+            ! Set temp_tn, temp_sn to 0.
+            temp_tn(:,:,:) = fbrmdi
+            temp_sn(:,:,:) = fbrmdi
+            temp_sshn(:,:) = fbrmdi
+
+            ! Create start and count arrays
+            start_n = (/ nimpp, njmpp, 1,   ifcst /)
+            count_n = (/ nlci,  nlcj,  jpk, 1     /)
+            start_s = (/ nimpp, njmpp, ifcst /)
+            count_s = (/ nlci,  nlcj,  1     /)
+
+            ! Read information into temporary arrays
+            ! retrieve varid and read in temperature
+            istat = nf90_inq_varid(ncid,'votemper',varid)
+            istat = nf90_get_att(ncid, varid, '_FillValue', fill_val)
+            istat = nf90_get_var(ncid, varid, temp_tn, start_n, count_n)
+            WHERE(temp_tn(:,:,:) == fill_val) temp_tn(:,:,:) = fbrmdi
+
+            ! retrieve varid and read in salinity
+            istat = nf90_inq_varid(ncid,'vosaline',varid)
+            istat = nf90_get_att(ncid, varid, '_FillValue', fill_val)
+            istat = nf90_get_var(ncid, varid, temp_sn, start_n, count_n)
+            WHERE(temp_sn(:,:,:) == fill_val) temp_sn(:,:,:) = fbrmdi
+
+            ! retrieve varid and read in SSH
+            istat = nf90_inq_varid(ncid,'sossheig',varid)
+            IF (istat /= nf90_noerr) THEN
+               ! Altimeter bias
+               istat = nf90_inq_varid(ncid,'altbias',varid)
+            END IF
+
+            istat = nf90_get_att(ncid, varid, '_FillValue', fill_val)
+            istat = nf90_get_var(ncid, varid, temp_sshn, start_s, count_s)
+            WHERE(temp_sshn(:,:) == fill_val) temp_sshn(:,:) = fbrmdi
+
+            ! Initialise tsn, sshn to fbrmdi
+            tsn(:,:,:,:) = fbrmdi
+            sshn(:,:) = fbrmdi
+
+            ! Mask out missing data index
+            tsn(1:nlci,1:nlcj,1:jpk,1) = temp_tn(:,:,:) * tmask(1:nlci,1:nlcj,1:jpk)
+            tsn(1:nlci,1:nlcj,1:jpk,2) = temp_sn(:,:,:) * tmask(1:nlci,1:nlcj,1:jpk)
+            sshn(1:nlci,1:nlcj)        = temp_sshn(:,:) * tmask(1:nlci,1:nlcj,1)
+
+            ! Remove halo from tmask, tsn, sshn to prevent double obs counting
+            IF (jpi > nlci) THEN
+                tmask(nlci+1:,:,:) = 0
+                tsn(nlci+1:,:,:,1) = 0
+                tsn(nlci+1:,:,:,2) = 0
+                sshn(nlci+1:,:) = 0
+            END IF
+            IF (jpj > nlcj) THEN
+                tmask(:,nlcj+1:,:) = 0
+                tsn(:,nlcj+1:,:,1) = 0
+                tsn(:,nlcj+1:,:,2) = 0
+                sshn(:,nlcj+1:) = 0
+            END IF
+
+            ! Deallocate arrays
+            DEALLOCATE(temp_tn, temp_sn, temp_sshn)
+         ELSE
+            ! Mark all as missing data
+            tsn(:,:,:,:) = fbrmdi
+            sshn(:,:) = fbrmdi
+         ENDIF
+         ! Close netcdf file
+         WRITE(numout,*) "Closing :", TRIM(filename)
+         istat = nf90_close(ncid)
+      END IF
+   END SUBROUTINE sao_read_file
+END MODULE sao_read
Index: /trunk/NEMOGCM/NEMO/SAS_SRC/daymod.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/SAS_SRC/daymod.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/SAS_SRC/daymod.F90	(revision 6140)
@@ -20,5 +20,5 @@
    !!
    !!   we suppose that the time step is deviding the number of second of in a day
-   !!             ---> MOD( rday, rdttra(1) ) == 0
+   !!             ---> MOD( rday, rdt ) == 0
    !!
    !!           ----------- WARNING -----------
@@ -76,12 +76,12 @@
             &           'You must do a restart at higher frequency (or remove this stop and recompile the code in I8)' )
       ENDIF
-      ! all calendar staff is based on the fact that MOD( rday, rdttra(1) ) == 0
-      IF( MOD( rday     , rdttra(1) ) /= 0. )   CALL ctl_stop( 'the time step must devide the number of second of in a day' )
-      IF( MOD( rday     , 2.        ) /= 0. )   CALL ctl_stop( 'the number of second of in a day must be an even number'    )
-      IF( MOD( rdttra(1), 2.        ) /= 0. )   CALL ctl_stop( 'the time step (in second) must be an even number'           )
-      nsecd   = NINT(rday           )
-      nsecd05 = NINT(0.5 * rday     )
-      ndt     = NINT(      rdttra(1))
-      ndt05   = NINT(0.5 * rdttra(1))
+      ! all calendar staff is based on the fact that MOD( rday, rdt ) == 0
+      IF( MOD( rday , rdt ) /= 0. )   CALL ctl_stop( 'the time step must devide the number of second of in a day' )
+      IF( MOD( rday , 2.  ) /= 0. )   CALL ctl_stop( 'the number of second of in a day must be an even number'    )
+      IF( MOD( rdt  , 2.  ) /= 0. )   CALL ctl_stop( 'the time step (in second) must be an even number'           )
+      nsecd   = NINT(rday         )
+      nsecd05 = NINT(0.5 * rday   )
+      ndt     = NINT(      rdt    )
+      ndt05   = NINT(0.5 * rdt    )
 
       ! ==> clem: here we read the ocean restart for the date (only if it exists)
@@ -224,6 +224,6 @@
       nsec_week  = nsec_week  + ndt
       nsec_day   = nsec_day   + ndt                
-      adatrj  = adatrj  + rdttra(1) / rday
-      fjulday = fjulday + rdttra(1) / rday
+      adatrj  = adatrj  + rdt / rday
+      fjulday = fjulday + rdt / rday
       IF( ABS(fjulday - REAL(NINT(fjulday),wp)) < zprec )   fjulday = REAL(NINT(fjulday),wp)   ! avoid truncation error
       IF( ABS(adatrj  - REAL(NINT(adatrj ),wp)) < zprec )   adatrj  = REAL(NINT(adatrj ),wp)   ! avoid truncation error
@@ -340,5 +340,5 @@
                ! parameters correspondting to nit000 - 1 (as we start the step loop with a call to day)
                ndastp = ndate0 - 1     ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00
-               adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday
+               adatrj = ( REAL( nit000-1, wp ) * rdt ) / rday
                ! note this is wrong if time step has changed during run
             ENDIF
@@ -346,5 +346,5 @@
             ! parameters correspondting to nit000 - 1 (as we start the step loop with a call to day)
             ndastp = ndate0 - 1        ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00
-            adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday
+            adatrj = ( REAL( nit000-1, wp ) * rdt ) / rday
          ENDIF
          IF( ABS(adatrj  - REAL(NINT(adatrj),wp)) < 0.1 / rday )   adatrj = REAL(NINT(adatrj),wp)   ! avoid truncation error
Index: /trunk/NEMOGCM/NEMO/SAS_SRC/diawri.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/SAS_SRC/diawri.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/SAS_SRC/diawri.F90	(revision 6140)
@@ -36,5 +36,4 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE in_out_manager  ! I/O manager
-   USE diadimg         ! dimg direct access file format output
    USE diaar5, ONLY :   lk_diaar5
    USE iom
@@ -61,6 +60,4 @@
 
    !! * Substitutions
-#  include "zdfddm_substitute.h90"
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -81,15 +78,8 @@
   END FUNCTION dia_wri_alloc
 
-#if defined key_dimgout
-   !!----------------------------------------------------------------------
-   !!   'key_dimgout'                                      DIMG output file
-   !!----------------------------------------------------------------------
-#   include "diawri_dimg.h90"
-
-#else
    !!----------------------------------------------------------------------
    !!   Default option                                   NetCDF output file
    !!----------------------------------------------------------------------
-# if defined key_iomput
+#if defined key_iomput
    !!----------------------------------------------------------------------
    !!   'key_iomput'                                        use IOM library
@@ -106,6 +96,5 @@
       !! ** Method  :  use iom_put
       !!----------------------------------------------------------------------
-      !!
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !!----------------------------------------------------------------------
       ! 
@@ -140,5 +129,5 @@
       INTEGER  ::   ierr                                     ! error code return from allocation
       INTEGER  ::   iimi, iima, ipk, it, itmod, ijmi, ijma   ! local integers
-      REAL(wp) ::   zsto, zout, zmax, zjulian, zdt           ! local scalars
+      REAL(wp) ::   zsto, zout, zmax, zjulian                ! local scalars
       !!----------------------------------------------------------------------
       ! 
@@ -159,18 +148,16 @@
 
       ! Define frequency of output and means
-      zdt = rdt
-      IF( nacc == 1 ) zdt = rdtmin
       IF( ln_mskland )   THEN   ;   clop = "only(x)"   ! put 1.e+20 on land (very expensive!!)
       ELSE                      ;   clop = "x"         ! no use of the mask value (require less cpu time)
       ENDIF
 #if defined key_diainstant
-      zsto = nwrite * zdt
+      zsto = nwrite * rdt
       clop = "inst("//TRIM(clop)//")"
 #else
-      zsto=zdt
+      zsto=rdt
       clop = "ave("//TRIM(clop)//")"
 #endif
-      zout = nwrite * zdt
-      zmax = ( nitend - nit000 + 1 ) * zdt
+      zout = nwrite * rdt
+      zmax = ( nitend - nit000 + 1 ) * rdt
 
       ! Define indices of the horizontal output zoom and vertical limit storage
@@ -214,5 +201,5 @@
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_T, nid_T, domain_id=nidom, snc4chunks=snc4set )
+            &          nit000-1, zjulian, rdt, nh_T, nid_T, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_T, "deptht", "Vertical T levels",      &  ! Vertical grid: gdept
             &           "m", ipk, gdept_1d, nz_T, "down" )
@@ -226,5 +213,5 @@
          CALL histbeg( clhstnam, jpi, glamu, jpj, gphiu,           &  ! Horizontal grid: glamu and gphiu
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_U, nid_U, domain_id=nidom, snc4chunks=snc4set )
+            &          nit000-1, zjulian, rdt, nh_U, nid_U, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_U, "depthu", "Vertical U levels",      &  ! Vertical grid: gdept
             &           "m", ipk, gdept_1d, nz_U, "down" )
@@ -238,5 +225,5 @@
          CALL histbeg( clhstnam, jpi, glamv, jpj, gphiv,           &  ! Horizontal grid: glamv and gphiv
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_V, nid_V, domain_id=nidom, snc4chunks=snc4set )
+            &          nit000-1, zjulian, rdt, nh_V, nid_V, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_V, "depthv", "Vertical V levels",      &  ! Vertical grid : gdept
             &          "m", ipk, gdept_1d, nz_V, "down" )
@@ -334,6 +321,4 @@
       !
    END SUBROUTINE dia_wri
-# endif
-
 #endif
 
@@ -358,5 +343,5 @@
       INTEGER  ::   id_i , nz_i, nh_i       
       INTEGER, DIMENSION(1) ::   idex             ! local workspace
-      REAL(wp) ::   zsto, zout, zmax, zjulian, zdt
+      REAL(wp) ::   zsto, zout, zmax, zjulian
       !!----------------------------------------------------------------------
       ! 
@@ -369,9 +354,8 @@
       clname = cdfile_name
       IF( .NOT. Agrif_Root() ) clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
-      zdt  = rdt
       zsto = rdt
       clop = "inst(x)"           ! no use of the mask value (require less cpu time)
       zout = rdt
-      zmax = ( nitend - nit000 + 1 ) * zdt
+      zmax = ( nitend - nit000 + 1 ) * rdt
 
       IF(lwp) WRITE(numout,*)
@@ -388,5 +372,5 @@
       zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
       CALL histbeg( clname, jpi, glamt, jpj, gphit,   &
-          1, jpi, 1, jpj, nit000-1, zjulian, zdt, nh_i, id_i, domain_id=nidom, snc4chunks=snc4set ) ! Horizontal grid : glamt and gphit
+          1, jpi, 1, jpj, nit000-1, zjulian, rdt, nh_i, id_i, domain_id=nidom, snc4chunks=snc4set ) ! Horizontal grid : glamt and gphit
       CALL histvert( id_i, "deptht", "Vertical T levels",   &    ! Vertical grid : gdept
           "m", jpk, gdept_1d, nz_i, "down")
@@ -431,5 +415,5 @@
       ! -----------------
       CALL histclo( id_i )
-#if ! defined key_iomput && ! defined key_dimgout
+#if ! defined key_iomput
       IF( ninist /= 1  ) THEN
          CALL histclo( nid_T )
Index: /trunk/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 6140)
@@ -184,5 +184,5 @@
       NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
          &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
-         &             nn_bench, nn_timing
+         &             nn_bench, nn_timing, nn_diacfl
       NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
          &             jpizoom, jpjzoom, jperio, ln_use_jattr
Index: /trunk/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90	(revision 6140)
@@ -88,9 +88,9 @@
          ssu_m(:,:) = sf_ssm_3d(jf_usp)%fnow(:,:,1) * umask(:,:,1)    ! u-velocity
          ssv_m(:,:) = sf_ssm_3d(jf_vsp)%fnow(:,:,1) * vmask(:,:,1)    ! v-velocity 
-         IF( lk_vvl )   e3t_m(:,:) = sf_ssm_3d(jf_e3t)%fnow(:,:,1) * tmask(:,:,1)    ! v-velocity 
+         IF( .NOT.ln_linssh )   e3t_m(:,:) = sf_ssm_3d(jf_e3t)%fnow(:,:,1) * tmask(:,:,1)    ! v-velocity 
       ELSE
          ssu_m(:,:) = sf_ssm_2d(jf_usp)%fnow(:,:,1) * umask(:,:,1)    ! u-velocity
          ssv_m(:,:) = sf_ssm_2d(jf_vsp)%fnow(:,:,1) * vmask(:,:,1)    ! v-velocity 
-         IF( lk_vvl )   e3t_m(:,:) = sf_ssm_2d(jf_e3t)%fnow(:,:,1) * tmask(:,:,1)    ! v-velocity 
+         IF( .NOT.ln_linssh )   e3t_m(:,:) = sf_ssm_2d(jf_e3t)%fnow(:,:,1) * tmask(:,:,1)    ! v-velocity 
       ENDIF
       !
@@ -115,6 +115,6 @@
          CALL prt_ctl(tab2d_1=ssv_m, clinfo1=' ssv_m   - : ', mask1=vmask, ovlap=1   )
          CALL prt_ctl(tab2d_1=ssh_m, clinfo1=' ssh_m   - : ', mask1=tmask, ovlap=1   )
-         IF( lk_vvl      )   CALL prt_ctl(tab2d_1=ssh_m, clinfo1=' e3t_m   - : ', mask1=tmask, ovlap=1   )
-         IF( ln_read_frq )   CALL prt_ctl(tab2d_1=frq_m, clinfo1=' frq_m   - : ', mask1=tmask, ovlap=1   )
+         IF( .NOT.ln_linssh )   CALL prt_ctl(tab2d_1=ssh_m, clinfo1=' e3t_m   - : ', mask1=tmask, ovlap=1   )
+         IF( ln_read_frq    )   CALL prt_ctl(tab2d_1=frq_m, clinfo1=' frq_m   - : ', mask1=tmask, ovlap=1   )
       ENDIF
       !
@@ -125,6 +125,6 @@
          CALL iom_put( 'sss_m', sss_m )
          CALL iom_put( 'ssh_m', ssh_m )
-         IF( lk_vvl      )   CALL iom_put( 'e3t_m', e3t_m )
-         IF( ln_read_frq )   CALL iom_put( 'frq_m', frq_m )
+         IF( .NOT.ln_linssh )   CALL iom_put( 'e3t_m', e3t_m )
+         IF( ln_read_frq    )   CALL iom_put( 'frq_m', frq_m )
       ENDIF
       !
@@ -216,10 +216,10 @@
       IF( ln_3d_uve ) THEN
          jf_usp = 1 ; jf_vsp = 2 ; jf_e3t = 3      ! define 3D fields index
-         nfld_3d  = 2 + COUNT( (/lk_vvl/) )        ! number of 3D fields to read
+         nfld_3d  = 2 + COUNT( (/.NOT.ln_linssh/) )        ! number of 3D fields to read
          nfld_2d  = 3 + COUNT( (/ln_read_frq/) )   ! number of 2D fields to read
       ELSE
-         jf_usp = 4 ; jf_vsp = 5 ; jf_e3t = 6 ; jf_frq = 6 + COUNT( (/lk_vvl/) )   ! update 2D fields index
+         jf_usp = 4 ; jf_vsp = 5 ; jf_e3t = 6 ; jf_frq = 6 + COUNT( (/.NOT.ln_linssh/) )   ! update 2D fields index
          nfld_3d  = 0                                                              ! no 3D fields to read
-         nfld_2d  = 5 + COUNT( (/lk_vvl/) ) + COUNT( (/ln_read_frq/) )             ! number of 2D fields to read
+         nfld_2d  = 5 + COUNT( (/.NOT.ln_linssh/) ) + COUNT( (/ln_read_frq/) )             ! number of 2D fields to read
       ENDIF
 
@@ -231,5 +231,5 @@
          slf_3d(jf_usp) = sn_usp
          slf_3d(jf_vsp) = sn_vsp
-         IF( lk_vvl )   slf_3d(jf_e3t) = sn_e3t
+         IF( .NOT.ln_linssh )   slf_3d(jf_e3t) = sn_e3t
       ENDIF
 
@@ -243,5 +243,5 @@
          IF( .NOT. ln_3d_uve ) THEN
             slf_2d(jf_usp) = sn_usp ; slf_2d(jf_vsp) = sn_vsp
-            IF( lk_vvl )   slf_2d(jf_e3t) = sn_e3t
+            IF( .NOT.ln_linssh )   slf_2d(jf_e3t) = sn_e3t
          ENDIF
       ENDIF
Index: /trunk/NEMOGCM/NEMO/SAS_SRC/step.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/SAS_SRC/step.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/SAS_SRC/step.F90	(revision 6140)
@@ -16,29 +16,24 @@
    USE oce              ! ocean dynamics and tracers variables
    USE dom_oce          ! ocean space and time domain variables 
-   USE in_out_manager   ! I/O manager
-   USE sbc_oce
-   USE sbccpl
-   USE iom              !
-   USE lbclnk
-#if defined key_iomput
-   USE xios
-#endif
-
    USE daymod           ! calendar                         (day     routine)
-
+   USE sbc_oce          ! surface boundary condition: fields
    USE sbcmod           ! surface boundary condition       (sbc     routine)
    USE sbcrnf           ! surface boundary condition: runoff variables
-
+   USE sbccpl           ! surface boundary condition: coupled interface
    USE eosbn2           ! equation of state                (eos_bn2 routine)
-
    USE diawri           ! Standard run outputs             (dia_wri routine)
-   USE stpctl           ! time stepping control            (stp_ctl routine)
-   USE prtctl           ! Print control                    (prt_ctl routine)
-
-   USE timing           ! Timing            
-
    USE bdy_par          ! clem: mandatory for LIM3
 #if defined key_bdy
    USE bdydta           ! clem: mandatory for LIM3
+#endif
+   USE stpctl           ! time stepping control            (stp_ctl routine)
+   !
+   USE in_out_manager   ! I/O manager
+   USE prtctl           ! Print control                    (prt_ctl routine)
+   USE iom              !
+   USE lbclnk           !
+   USE timing           ! Timing            
+#if defined key_iomput
+   USE xios
 #endif
 
@@ -46,9 +41,6 @@
    PRIVATE
 
-   PUBLIC   stp   ! called by opa.F90
+   PUBLIC   stp   ! called by nemogcm.F90
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "zdfddm_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/C14b/trcsms_c14b.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/C14b/trcsms_c14b.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/C14b/trcsms_c14b.F90	(revision 6140)
@@ -49,6 +49,4 @@
    REAL(wp) ::   xconv3 = 1.e+3_wp             ! conversion from mol/l/atm to mol/m3/atm
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -257,5 +255,5 @@
                   &                      * tmask(ji,jj,1) * ( 1. - fr_i(ji,jj) ) / 2.
             ! Add the surface flux to the trend
-            tra(ji,jj,1,jpc14) = tra(ji,jj,1,jpc14) + qtr_c14(ji,jj) / fse3t(ji,jj,1) 
+            tra(ji,jj,1,jpc14) = tra(ji,jj,1,jpc14) + qtr_c14(ji,jj) / e3t_n(ji,jj,1) 
             
             ! cumulation of surface flux at each time step
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 6140)
@@ -50,6 +50,4 @@
    REAL(wp) ::   xconv4 = 1.0e-12      ! conversion from mol/m3/atm to mol/m3/pptv 
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -75,5 +73,4 @@
       !!                CFC concentration in pico-mol/m3
       !!----------------------------------------------------------------------
-      !
       INTEGER, INTENT(in) ::   kt    ! ocean time-step index
       !
@@ -167,5 +164,5 @@
                   &                         * tmask(ji,jj,1) * ( 1. - fr_i(ji,jj) )
                ! Add the surface flux to the trend
-               tra(ji,jj,1,jn) = tra(ji,jj,1,jn) + qtr_cfc(ji,jj,jl) / fse3t(ji,jj,1) 
+               tra(ji,jj,1,jn) = tra(ji,jj,1,jn) + qtr_cfc(ji,jj,jl) / e3t_n(ji,jj,1) 
 
                ! cumulation of surface flux at each time step
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcsms_my_trc.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcsms_my_trc.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcsms_my_trc.F90	(revision 6140)
@@ -18,4 +18,5 @@
    USE trd_oce
    USE trdtrc
+   USE trcbc, only : trc_bc_read
 
    IMPLICIT NONE
@@ -56,5 +57,10 @@
       IF( l_trdtrc )  CALL wrk_alloc( jpi, jpj, jpk, ztrmyt )
 
-      IF( l_trdtrc ) THEN      ! Save the trends in the ixed layer
+      CALL trc_bc_read  ( kt )       ! tracers: surface and lateral Boundary Conditions
+
+      ! add here the call to BGC model
+
+      ! Save the trends in the mixed layer
+      IF( l_trdtrc ) THEN
           DO jn = jp_myt0, jp_myt1
             ztrmyt(:,:,:) = tra(:,:,:,jn)
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcwri_my_trc.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcwri_my_trc.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcwri_my_trc.F90	(revision 6140)
@@ -36,5 +36,5 @@
       DO jn = jp_myt0, jp_myt1
          cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
-         CALL iom_put( cltra, trn(:,:,:,jn) )
+         IF( ln_trc_wri(jn) ) CALL iom_put( cltra, trn(:,:,:,jn) )
       END DO
       !
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zbio.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zbio.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zbio.F90	(revision 6140)
@@ -60,5 +60,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -67,5 +66,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -187,5 +185,5 @@
                !    closure : flux grazing is redistributed below level jpkbio
                zzoobod = tmminz * zzoo * zzoo
-               xksi(ji,jj) = xksi(ji,jj) + (1-fdbod) * zzoobod * fse3t(ji,jj,jk)
+               xksi(ji,jj) = xksi(ji,jj) + (1-fdbod) * zzoobod * e3t_n(ji,jj,jk)
                zboddet = fdbod * zzoobod
 
@@ -242,5 +240,5 @@
                 IF( ln_diatrc .OR. lk_iomput ) THEN
                   ! convert fluxes in per day
-                  ze3t = fse3t(ji,jj,jk) * 86400.
+                  ze3t = e3t_n(ji,jj,jk) * 86400._wp
                   zw2d(ji,jj,1)  = zw2d(ji,jj,1)  + zno3phy * ze3t
                   zw2d(ji,jj,2)  = zw2d(ji,jj,2)  + znh4phy * ze3t
@@ -363,5 +361,5 @@
                 IF( ln_diatrc .OR. lk_iomput ) THEN
                   ! convert fluxes in per day
-                  ze3t = fse3t(ji,jj,jk) * 86400.
+                  ze3t = e3t_n(ji,jj,jk) * 86400._wp
                   zw2d(ji,jj,1)  = zw2d(ji,jj,1)  + zno3phy * ze3t
                   zw2d(ji,jj,2)  = zw2d(ji,jj,2)  + znh4phy * ze3t
@@ -382,7 +380,7 @@
                   zw2d(ji,jj,17) = zw2d(ji,jj,17) + zdetdom * ze3t
                   !   
-                  zw3d(ji,jj,jk,1) = zno3phy * 86400
-                  zw3d(ji,jj,jk,2) = znh4phy * 86400
-                  zw3d(ji,jj,jk,3) = znh4no3 * 86400
+                  zw3d(ji,jj,jk,1) = zno3phy * 86400._wp
+                  zw3d(ji,jj,jk,2) = znh4phy * 86400._wp
+                  zw3d(ji,jj,jk,3) = znh4no3 * 86400._wp
                    !
                 ENDIF
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zexp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zexp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zexp.F90	(revision 6140)
@@ -42,5 +42,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -49,5 +48,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -95,5 +93,5 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1
-               ze3t = 1. / fse3t(ji,jj,jk)
+               ze3t = 1. / e3t_n(ji,jj,jk)
                tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) + ze3t * dmin3(ji,jj,jk) * xksi(ji,jj)
             END DO
@@ -110,5 +108,5 @@
          DO ji = fs_2, fs_jpim1
             ikt = mbkt(ji,jj) 
-            tra(ji,jj,ikt,jpno3) = tra(ji,jj,ikt,jpno3) + sedlam * sedpocn(ji,jj) / fse3t(ji,jj,ikt) 
+            tra(ji,jj,ikt,jpno3) = tra(ji,jj,ikt,jpno3) + sedlam * sedpocn(ji,jj) / e3t_n(ji,jj,ikt) 
             ! Deposition of organic matter in the sediment
             zwork = vsed * trn(ji,jj,ikt,jpdet)
@@ -121,5 +119,5 @@
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1
-            tra(ji,jj,1,jpno3) = tra(ji,jj,1,jpno3) + zgeolpoc * cmask(ji,jj) / areacot / fse3t(ji,jj,1)
+            tra(ji,jj,1,jpno3) = tra(ji,jj,1,jpno3) + zgeolpoc * cmask(ji,jj) / areacot / e3t_n(ji,jj,1)
          END DO
       END DO
@@ -212,6 +210,6 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               zfluo = ( fsdepw(ji,jj,jk  ) / fsdepw(ji,jj,jpkb) )**xhr
-               zfluu = ( fsdepw(ji,jj,jk+1) / fsdepw(ji,jj,jpkb) )**xhr
+               zfluo = ( gdepw_n(ji,jj,jk  ) / gdepw_n(ji,jj,jpkb) )**xhr
+               zfluu = ( gdepw_n(ji,jj,jk+1) / gdepw_n(ji,jj,jpkb) )**xhr
                IF( zfluo.GT.1. )   zfluo = 1._wp
                zdm0(ji,jj,jk) = zfluo - zfluu
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zopt.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zopt.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zopt.F90	(revision 6140)
@@ -40,6 +40,4 @@
    REAL(wp), PUBLIC ::  reddom    ! redfield ratio (C:N) for DOM
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -47,5 +45,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -105,6 +102,6 @@
                zkr  = xkr0 + xkrp * EXP( xlr * zpig )
                zkg  = xkg0 + xkgp * EXP( xlg * zpig )
-               zparr(ji,jj,jk) = zparr(ji,jj,jk-1) * EXP( -zkr * fse3t(ji,jj,jk-1) )
-               zparg(ji,jj,jk) = zparg(ji,jj,jk-1) * EXP( -zkg * fse3t(ji,jj,jk-1) )
+               zparr(ji,jj,jk) = zparr(ji,jj,jk-1) * EXP( -zkr * e3t_n(ji,jj,jk-1) )
+               zparg(ji,jj,jk) = zparg(ji,jj,jk-1) * EXP( -zkg * e3t_n(ji,jj,jk-1) )
             END DO
         END DO
@@ -116,6 +113,6 @@
                zkr  = xkr0 + xkrp * EXP( xlr * zpig )
                zkg  = xkg0 + xkgp * EXP( xlg * zpig )
-               zparr(ji,jj,jk) = zparr(ji,jj,jk) / ( zkr * fse3t(ji,jj,jk) ) * ( 1 - EXP( -zkr * fse3t(ji,jj,jk) ) )
-               zparg(ji,jj,jk) = zparg(ji,jj,jk) / ( zkg * fse3t(ji,jj,jk) ) * ( 1 - EXP( -zkg * fse3t(ji,jj,jk) ) )
+               zparr(ji,jj,jk) = zparr(ji,jj,jk) / ( zkr * e3t_n(ji,jj,jk) ) * ( 1 - EXP( -zkr * e3t_n(ji,jj,jk) ) )
+               zparg(ji,jj,jk) = zparg(ji,jj,jk) / ( zkg * e3t_n(ji,jj,jk) ) * ( 1 - EXP( -zkg * e3t_n(ji,jj,jk) ) )
                etot (ji,jj,jk) = MAX( zparr(ji,jj,jk) + zparg(ji,jj,jk), 1.e-15 )
             END DO
@@ -138,5 +135,5 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            heup(ji,jj) = fsdepw(ji,jj,neln(ji,jj))
+            heup(ji,jj) = gdepw_n(ji,jj,neln(ji,jj))
          END DO
       END DO 
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zsed.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zsed.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zsed.F90	(revision 6140)
@@ -34,6 +34,4 @@
    REAL(wp), PUBLIC ::   xhr         ! coeff for martin''s remineralisation profile
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -102,5 +100,5 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               ztra(ji,jj,jk)  = - ( zwork(ji,jj,jk) - zwork(ji,jj,jk+1) ) / fse3t(ji,jj,jk)
+               ztra(ji,jj,jk)  = - ( zwork(ji,jj,jk) - zwork(ji,jj,jk+1) ) / e3t_n(ji,jj,jk)
                tra(ji,jj,jk,jpdet) = tra(ji,jj,jk,jpdet) + ztra(ji,jj,jk) 
             END DO
@@ -111,7 +109,7 @@
          IF( iom_use( "TDETSED" ) ) THEN
             CALL wrk_alloc( jpi, jpj, zw2d )
-            zw2d(:,:) =  ztra(:,:,1) * fse3t(:,:,1) * 86400.
+            zw2d(:,:) =  ztra(:,:,1) * e3t_n(:,:,1) * 86400._wp
             DO jk = 2, jpkm1
-               zw2d(:,:) = zw2d(:,:) + ztra(:,:,jk) * fse3t(:,:,jk) * 86400.
+               zw2d(:,:) = zw2d(:,:) + ztra(:,:,jk) * e3t_n(:,:,jk) * 86400._wp
             END DO
             CALL iom_put( "TDETSED", zw2d )
@@ -121,7 +119,7 @@
          IF( ln_diatrc ) THEN 
             CALL wrk_alloc( jpi, jpj, zw2d )
-            zw2d(:,:) =  ztra(:,:,1) * fse3t(:,:,1) * 86400.
+            zw2d(:,:) =  ztra(:,:,1) * e3t_n(:,:,1) * 86400._wp
             DO jk = 2, jpkm1
-               zw2d(:,:) = zw2d(:,:) + ztra(:,:,jk) * fse3t(:,:,jk) * 86400.
+               zw2d(:,:) = zw2d(:,:) + ztra(:,:,jk) * e3t_n(:,:,jk) * 86400._wp
             END DO
             trc2d(:,:,jp_pcs0_2d + 7) = zw2d(:,:)
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zbio.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zbio.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zbio.F90	(revision 6140)
@@ -34,6 +34,4 @@
    PUBLIC  p4z_bio    
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -41,5 +39,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -70,10 +67,10 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               IF( fsdepw(ji,jj,jk+1) > hmld(ji,jj) )   xdiss(ji,jj,jk) = 0.01
+!!gm  :  use nmln  and test on jk ...  less memory acces
+               IF( gdepw_n(ji,jj,jk+1) > hmld(ji,jj) )   xdiss(ji,jj,jk) = 0.01
             END DO 
          END DO
       END DO
 
-          
       CALL p4z_opt  ( kt, knt )     ! Optic: PAR in the water column
       CALL p4z_sink ( kt, knt )     ! vertical flux of particulate organic matter
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zche.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zche.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zche.F90	(revision 6140)
@@ -164,6 +164,4 @@
    REAL(wp) :: devk55  = 0.3692E-3      
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -244,5 +242,4 @@
 
 
-
       ! CHEMICAL CONSTANTS - DEEP OCEAN
       ! -------------------------------
@@ -252,5 +249,5 @@
 
                ! SET PRESSION
-               zpres   = 1.025e-1 * fsdept(ji,jj,jk)
+               zpres   = 1.025e-1 * gdept_n(ji,jj,jk)
 
                ! SET ABSOLUTE TEMPERATURE
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zfechem.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zfechem.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zfechem.F90	(revision 6140)
@@ -30,15 +30,13 @@
    PUBLIC   p4z_fechem_init ! called in trcsms_pisces.F90
 
-   !! * Shared module variables
-   LOGICAL          ::  ln_fechem    !: boolean for complex iron chemistry following Tagliabue and voelker
-   LOGICAL          ::  ln_ligvar    !: boolean for variable ligand concentration following Tagliabue and voelker
-   REAL(wp), PUBLIC ::  xlam1        !: scavenging rate of Iron 
-   REAL(wp), PUBLIC ::  xlamdust     !: scavenging rate of Iron by dust 
-   REAL(wp), PUBLIC ::  ligand       !: ligand concentration in the ocean 
-
+   LOGICAL          ::   ln_fechem    !: boolean for complex iron chemistry following Tagliabue and voelker
+   LOGICAL          ::   ln_ligvar    !: boolean for variable ligand concentration following Tagliabue and voelker
+   REAL(wp), PUBLIC ::   xlam1        !: scavenging rate of Iron 
+   REAL(wp), PUBLIC ::   xlamdust     !: scavenging rate of Iron by dust 
+   REAL(wp), PUBLIC ::   ligand       !: ligand concentration in the ocean 
+
+!!gm Not DOCTOR norm !!!
    REAL(wp) :: kl1, kl2, kb1, kb2, ks, kpr, spd, con, kth
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -61,8 +59,8 @@
       !!                    and one particulate form (ln_fechem)
       !!---------------------------------------------------------------------
-      !
-      INTEGER, INTENT(in) ::   kt, knt ! ocean time step
+      INTEGER, INTENT(in) ::   kt, knt   ! ocean time step
       !
       INTEGER  ::   ji, jj, jk, jic
+      CHARACTER (len=25) :: charout
       REAL(wp) ::   zdep, zlam1a, zlam1b, zlamfac
       REAL(wp) ::   zkeq, zfeequi, zfesatur, zfecoll
@@ -79,16 +77,14 @@
       REAL(wp) :: ztfe, zoxy
       REAL(wp) :: zstep
-      CHARACTER (len=25) :: charout
       !!---------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('p4z_fechem')
       !
-      ! Allocate temporary workspace
-      CALL wrk_alloc( jpi, jpj, jpk, zFe3, zFeL1, zTL1, ztotlig )
+      CALL wrk_alloc( jpi,jpj,jpk,   zFe3, zFeL1, zTL1, ztotlig )
       zFe3 (:,:,:) = 0.
       zFeL1(:,:,:) = 0.
       zTL1 (:,:,:) = 0.
       IF( ln_fechem ) THEN
-         CALL wrk_alloc( jpi, jpj, jpk, zFe2, zFeL2, zTL2, zFeP )
+         CALL wrk_alloc( jpi,jpj,jpk,   zFe2, zFeL2, zTL2, zFeP )
          zFe2 (:,:,:) = 0.
          zFeL2(:,:,:) = 0.
@@ -253,5 +249,6 @@
                zlamfac = MAX( 0.e0, ( gphit(ji,jj) + 55.) / 30. )
                zlamfac = MIN( 1.  , zlamfac )
-               zdep    = MIN( 1., 1000. / fsdept(ji,jj,jk) )
+!!gm very small BUG :  it is unlikely but possible that gdept_n = 0  .....
+               zdep    = MIN( 1., 1000. / gdept_n(ji,jj,jk) )
                zlam1b  = xlam1 * MAX( 0.e0, ( trb(ji,jj,jk,jpfer) * 1.e9 - ztotlig(ji,jj,jk) ) )
                zcoag   = zfeequi * zlam1b * zstep + 1E-4 * ( 1. - zlamfac ) * zdep * zstep * trb(ji,jj,jk,jpfer)
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zflx.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zflx.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zflx.F90	(revision 6140)
@@ -59,6 +59,4 @@
    REAL(wp) ::  xconv  = 0.01_wp / 3600._wp !: coefficients for conversion 
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -182,5 +180,5 @@
             oce_co2(ji,jj) = ( zfld - zflu ) * rfact2 * e1e2t(ji,jj) * tmask(ji,jj,1) * 1000.
             ! compute the trend
-            tra(ji,jj,1,jpdic) = tra(ji,jj,1,jpdic) + ( zfld - zflu ) * rfact2 / fse3t(ji,jj,1)
+            tra(ji,jj,1,jpdic) = tra(ji,jj,1,jpdic) + ( zfld - zflu ) * rfact2 / e3t_n(ji,jj,1)
 
             ! Compute O2 flux 
@@ -188,5 +186,5 @@
             zflu16 = trb(ji,jj,1,jpoxy) * tmask(ji,jj,1) * zkgo2(ji,jj)
             zoflx(ji,jj) = zfld16 - zflu16
-            tra(ji,jj,1,jpoxy) = tra(ji,jj,1,jpoxy) + zoflx(ji,jj) * rfact2 / fse3t(ji,jj,1)
+            tra(ji,jj,1,jpoxy) = tra(ji,jj,1,jpoxy) + zoflx(ji,jj) * rfact2 / e3t_n(ji,jj,1)
          END DO
       END DO
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zopt.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zopt.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zopt.F90	(revision 6140)
@@ -51,6 +51,4 @@
    REAL(wp), DIMENSION(3,61), PUBLIC ::   xkrgb   !: tabulated attenuation coefficients for RGB absorption
    
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -101,7 +99,7 @@
                irgb = NINT( 41 + 20.* LOG10( zchl ) + rtrn )
                !                                                         
-               ekb(ji,jj,jk) = xkrgb(1,irgb) * fse3t(ji,jj,jk)
-               ekg(ji,jj,jk) = xkrgb(2,irgb) * fse3t(ji,jj,jk)
-               ekr(ji,jj,jk) = xkrgb(3,irgb) * fse3t(ji,jj,jk)
+               ekb(ji,jj,jk) = xkrgb(1,irgb) * e3t_n(ji,jj,jk)
+               ekg(ji,jj,jk) = xkrgb(2,irgb) * e3t_n(ji,jj,jk)
+               ekr(ji,jj,jk) = xkrgb(3,irgb) * e3t_n(ji,jj,jk)
             END DO
          END DO
@@ -162,5 +160,5 @@
                  neln(ji,jj) = jk+1                    ! Euphotic level : 1rst T-level strictly below Euphotic layer
                  !                                     ! nb: ensure the compatibility with nmld_trc definition in trd_mld_trc_zint
-                 heup(ji,jj) = fsdepw(ji,jj,jk+1)      ! Euphotic layer depth
+                 heup(ji,jj) = gdepw_n(ji,jj,jk+1)     ! Euphotic layer depth
               ENDIF
            END DO
@@ -179,10 +177,10 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               IF( fsdepw(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
-                  zetmp1 (ji,jj) = zetmp1 (ji,jj) + etot     (ji,jj,jk) * fse3t(ji,jj,jk) ! remineralisation
-                  zetmp2 (ji,jj) = zetmp2 (ji,jj) + etot_ndcy(ji,jj,jk) * fse3t(ji,jj,jk) ! production
-                  zetmp3 (ji,jj) = zetmp3 (ji,jj) + enano    (ji,jj,jk) * fse3t(ji,jj,jk) ! production
-                  zetmp4 (ji,jj) = zetmp4 (ji,jj) + ediat    (ji,jj,jk) * fse3t(ji,jj,jk) ! production
-                  zdepmoy(ji,jj) = zdepmoy(ji,jj) + fse3t(ji,jj,jk)
+               IF( gdepw_n(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
+                  zetmp1 (ji,jj) = zetmp1 (ji,jj) + etot     (ji,jj,jk) * e3t_n(ji,jj,jk) ! remineralisation
+                  zetmp2 (ji,jj) = zetmp2 (ji,jj) + etot_ndcy(ji,jj,jk) * e3t_n(ji,jj,jk) ! production
+                  zetmp3 (ji,jj) = zetmp3 (ji,jj) + enano    (ji,jj,jk) * e3t_n(ji,jj,jk) ! production
+                  zetmp4 (ji,jj) = zetmp4 (ji,jj) + ediat    (ji,jj,jk) * e3t_n(ji,jj,jk) ! production
+                  zdepmoy(ji,jj) = zdepmoy(ji,jj) +                       e3t_n(ji,jj,jk)
                ENDIF
             END DO
@@ -196,5 +194,5 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               IF( fsdepw(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
+               IF( gdepw_n(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
                   z1_dep = 1. / ( zdepmoy(ji,jj) + rtrn )
                   emoy (ji,jj,jk) = zetmp1(ji,jj) * z1_dep
@@ -260,5 +258,5 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  pe0(ji,jj,jk) = pe0(ji,jj,jk-1) * EXP( -fse3t(ji,jj,jk-1) * xsi0r )
+                  pe0(ji,jj,jk) = pe0(ji,jj,jk-1) * EXP( -e3t_n(ji,jj,jk-1) * xsi0r )
                   pe1(ji,jj,jk) = pe1(ji,jj,jk-1) * EXP( -ekb(ji,jj,jk-1 ) )
                   pe2(ji,jj,jk) = pe2(ji,jj,jk-1) * EXP( -ekg(ji,jj,jk-1 ) )
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zprod.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zprod.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zprod.F90	(revision 6140)
@@ -54,6 +54,4 @@
    REAL(wp) :: texcret2               !: 1 - excret2        
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -277,5 +275,5 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               IF( fsdepw(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
+               IF( gdepw_n(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
                   zprbio(ji,jj,jk) = zprbio(ji,jj,jk) * zmixnano(ji,jj)
                   zprdia(ji,jj,jk) = zprdia(ji,jj,jk) * zmixdiat(ji,jj)
@@ -321,5 +319,5 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  IF( fsdepw(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
+                  IF( gdepw_n(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
                      zprnch(ji,jj,jk) = zprnch(ji,jj,jk) * zmixnano(ji,jj)
                      zprdch(ji,jj,jk) = zprdch(ji,jj,jk) * zmixdiat(ji,jj)
@@ -462,5 +460,5 @@
              zw2d(:,:) = 0.
              DO jk = 1, jpkm1
-               zw2d(:,:) = zw2d(:,:) + zprorca (:,:,jk) * fse3t(:,:,jk) * zfact * tmask(:,:,jk)  ! vert. integrated  primary produc. by nano
+               zw2d(:,:) = zw2d(:,:) + zprorca (:,:,jk) * e3t_n(:,:,jk) * zfact * tmask(:,:,jk)  ! vert. integrated  primary produc. by nano
              ENDDO
              CALL iom_put( "INTPPPHY" , zw2d )
@@ -468,5 +466,5 @@
              zw2d(:,:) = 0.
              DO jk = 1, jpkm1
-                zw2d(:,:) = zw2d(:,:) + zprorcad(:,:,jk) * fse3t(:,:,jk) * zfact * tmask(:,:,jk) ! vert. integrated  primary produc. by diatom
+                zw2d(:,:) = zw2d(:,:) + zprorcad(:,:,jk) * e3t_n(:,:,jk) * zfact * tmask(:,:,jk) ! vert. integrated  primary produc. by diatom
              ENDDO
              CALL iom_put( "INTPPPHY2" , zw2d )
@@ -475,5 +473,5 @@
              zw2d(:,:) = 0.
              DO jk = 1, jpkm1
-                zw2d(:,:) = zw2d(:,:) + ( zprorca(:,:,jk) + zprorcad(:,:,jk) ) * fse3t(:,:,jk) * zfact * tmask(:,:,jk) ! vert. integrated pp
+                zw2d(:,:) = zw2d(:,:) + ( zprorca(:,:,jk) + zprorcad(:,:,jk) ) * e3t_n(:,:,jk) * zfact * tmask(:,:,jk) ! vert. integrated pp
              ENDDO
              CALL iom_put( "INTPP" , zw2d )
@@ -482,5 +480,5 @@
              zw2d(:,:) = 0.
              DO jk = 1, jpkm1
-                zw2d(:,:) = zw2d(:,:) + ( zpronew(:,:,jk) + zpronewd(:,:,jk) ) * fse3t(:,:,jk) * zfact * tmask(:,:,jk)  ! vert. integrated new prod
+                zw2d(:,:) = zw2d(:,:) + ( zpronew(:,:,jk) + zpronewd(:,:,jk) ) * e3t_n(:,:,jk) * zfact * tmask(:,:,jk)  ! vert. integrated new prod
              ENDDO
              CALL iom_put( "INTPNEW" , zw2d )
@@ -489,5 +487,5 @@
              zw2d(:,:) = 0.
              DO jk = 1, jpkm1
-                zw2d(:,:) = zw2d(:,:) + ( zprofen(:,:,jk) + zprofed(:,:,jk) ) * fse3t(:,:,jk) * zfact * tmask(:,:,jk) ! vert integr. bfe prod
+                zw2d(:,:) = zw2d(:,:) + ( zprofen(:,:,jk) + zprofed(:,:,jk) ) * e3t_n(:,:,jk) * zfact * tmask(:,:,jk) ! vert integr. bfe prod
              ENDDO
             CALL iom_put( "INTPBFE" , zw2d )
@@ -496,5 +494,5 @@
              zw2d(:,:) = 0.
              DO jk = 1, jpkm1
-                zw2d(:,:) = zw2d(:,:) + zprorcad(:,:,jk) * zysopt(:,:,jk) * fse3t(:,:,jk) * zfact * tmask(:,:,jk)  ! vert integr. bsi prod
+                zw2d(:,:) = zw2d(:,:) + zprorcad(:,:,jk) * zysopt(:,:,jk) * e3t_n(:,:,jk) * zfact * tmask(:,:,jk)  ! vert integr. bsi prod
              ENDDO
              CALL iom_put( "INTPBSI" , zw2d )
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zrem.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zrem.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zrem.F90	(revision 6140)
@@ -50,6 +50,4 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   denitnh4   !: -    -    -    -   -
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -103,9 +101,9 @@
             DO ji = 1, jpi
                zdep = MAX( hmld(ji,jj), heup(ji,jj) )
-               IF( fsdept(ji,jj,jk) < zdep ) THEN
+               IF( gdept_n(ji,jj,jk) < zdep ) THEN
                   zdepbac(ji,jj,jk) = MIN( 0.7 * ( trb(ji,jj,jk,jpzoo) + 2.* trb(ji,jj,jk,jpmes) ), 4.e-6 )
                   ztempbac(ji,jj)   = zdepbac(ji,jj,jk)
                ELSE
-                  zdepmin = MIN( 1., zdep / fsdept(ji,jj,jk) )
+                  zdepmin = MIN( 1., zdep / gdept_n(ji,jj,jk) )
                   zdepbac (ji,jj,jk) = zdepmin**0.683 * ztempbac(ji,jj)
                   zdepprod(ji,jj,jk) = zdepmin**0.273
@@ -283,5 +281,5 @@
                ! ----------------------------------------------------------
                zdep     = MAX( hmld(ji,jj), heup(ji,jj) ) 
-               zdep     = MAX( 0., fsdept(ji,jj,jk) - zdep )
+               zdep     = MAX( 0., gdept_n(ji,jj,jk) - zdep )
                ztem     = MAX( tsn(ji,jj,1,jp_tem), 0. )
                zfactdep = xsilab * EXP(-( xsiremlab - xsirem ) * znusil2 * zdep / wsbio2 ) * ztem / ( ztem + 10. )
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsbc.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsbc.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsbc.F90	(revision 6140)
@@ -25,5 +25,4 @@
    PUBLIC   p4z_sbc_init   
 
-   !! * Shared module variables
    LOGICAL , PUBLIC  :: ln_dust     !: boolean for dust input from the atmosphere
    LOGICAL , PUBLIC  :: ln_solub    !: boolean for variable solubility of atmospheric iron
@@ -45,5 +44,4 @@
    LOGICAL , PUBLIC  :: ll_sbc
 
-   !! * Module variables
    LOGICAL  ::  ll_solub
 
@@ -80,7 +78,5 @@
    REAL(wp), PUBLIC :: rivdininput, rivdipinput, rivdsiinput
 
-
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -89,5 +85,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -163,5 +158,5 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  nitdep(ji,jj) = sf_ndepo(1)%fnow(ji,jj,1) / rno3 / ( 14E6 * ryyss * fse3t(ji,jj,1) + rtrn )
+                  nitdep(ji,jj) = sf_ndepo(1)%fnow(ji,jj,1) / rno3 / ( 14E6 * ryyss * e3t_n(ji,jj,1) + rtrn )
                END DO
             END DO
@@ -267,5 +262,5 @@
       IF( lk_offline ) THEN
         nk_rnf(:,:) = 1
-        h_rnf (:,:) = fsdept(:,:,1)
+        h_rnf (:,:) = gdept_n(:,:,1)
       ENDIF
 
@@ -456,5 +451,5 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zexpide   = MIN( 8.,( fsdept(ji,jj,jk) / 500. )**(-1.5) )
+                  zexpide   = MIN( 8.,( gdept_n(ji,jj,jk) / 500. )**(-1.5) )
                   zdenitide = -0.9543 + 0.7662 * LOG( zexpide ) - 0.235 * LOG( zexpide )**2
                   zcmask(ji,jj,jk) = zcmask(ji,jj,jk) * MIN( 1., EXP( zdenitide ) / 0.5 )
@@ -466,5 +461,5 @@
          ironsed(:,:,jpk) = 0._wp
          DO jk = 1, jpkm1
-            ironsed(:,:,jk) = sedfeinput * zcmask(:,:,jk) / ( fse3t(:,:,jk) * rday )
+            ironsed(:,:,jk) = sedfeinput * zcmask(:,:,jk) / ( e3t_n(:,:,jk) * rday )
          END DO
          DEALLOCATE( zcmask)
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsed.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsed.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsed.F90	(revision 6140)
@@ -32,12 +32,8 @@
    PUBLIC   p4z_sed_alloc
  
-
-   !! * Module variables
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: nitrpot    !: Nitrogen fixation 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:  ) :: sdenit     !: Nitrate reduction in the sediments
    REAL(wp) :: r1_rday                  !: inverse of rday
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -100,5 +96,5 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               zdep    = rfact2 / fse3t(ji,jj,1)
+               zdep    = rfact2 / e3t_n(ji,jj,1)
                zwflux  = fmmflx(ji,jj) / 1000._wp
                zfminus = MIN( 0._wp, -zwflux ) * trb(ji,jj,1,jpfer) * zdep
@@ -111,5 +107,5 @@
          ! 
          IF( lk_iomput .AND. knt == nrdttrc .AND. iom_use( "Ironice" ) )   &
-            &   CALL iom_put( "Ironice", zironice(:,:) * 1.e+3 * rfact2r * fse3t(:,:,1) * tmask(:,:,1) ) ! iron flux from ice
+            &   CALL iom_put( "Ironice", zironice(:,:) * 1.e+3 * rfact2r * e3t_n(:,:,1) * tmask(:,:,1) ) ! iron flux from ice
          !
          CALL wrk_dealloc( jpi, jpj, zironice )
@@ -125,15 +121,15 @@
          !                                              ! Iron and Si deposition at the surface
          IF( ln_solub ) THEN
-            zirondep(:,:,1) = solub(:,:) * dust(:,:) * mfrac * rfact2 / fse3t(:,:,1) / 55.85 + 3.e-10 * r1_ryyss 
+            zirondep(:,:,1) = solub(:,:) * dust(:,:) * mfrac * rfact2 / e3t_n(:,:,1) / 55.85 + 3.e-10 * r1_ryyss 
          ELSE
-            zirondep(:,:,1) = dustsolub  * dust(:,:) * mfrac * rfact2 / fse3t(:,:,1) / 55.85 + 3.e-10 * r1_ryyss 
+            zirondep(:,:,1) = dustsolub  * dust(:,:) * mfrac * rfact2 / e3t_n(:,:,1) / 55.85 + 3.e-10 * r1_ryyss 
          ENDIF
-         zsidep(:,:) = 8.8 * 0.075 * dust(:,:) * mfrac * rfact2 / fse3t(:,:,1) / 28.1 
-         zpdep (:,:) = 0.1 * 0.021 * dust(:,:) * mfrac * rfact2 / fse3t(:,:,1) / 31. / po4r 
+         zsidep(:,:) = 8.8 * 0.075 * dust(:,:) * mfrac * rfact2 / e3t_n(:,:,1) / 28.1 
+         zpdep (:,:) = 0.1 * 0.021 * dust(:,:) * mfrac * rfact2 / e3t_n(:,:,1) / 31. / po4r 
          !                                              ! Iron solubilization of particles in the water column
          !                                              ! dust in kg/m2/s ---> 1/55.85 to put in mol/Fe ;  wdust in m/j
          zwdust = 0.03 * rday / ( wdust * 55.85 ) / ( 270. * rday )
          DO jk = 2, jpkm1
-            zirondep(:,:,jk) = dust(:,:) * mfrac * zwdust * rfact2 * EXP( -fsdept(:,:,jk) / 540. )
+            zirondep(:,:,jk) = dust(:,:) * mfrac * zwdust * rfact2 * EXP( -gdept_n(:,:,jk) / 540. )
          END DO
          !                                              ! Iron solubilization of particles in the water column
@@ -145,5 +141,5 @@
             IF( knt == nrdttrc ) THEN
                 IF( iom_use( "Irondep" ) )   &
-                &  CALL iom_put( "Irondep", zirondep(:,:,1) * 1.e+3 * rfact2r * fse3t(:,:,1) * tmask(:,:,1) ) ! surface downward dust depo of iron
+                &  CALL iom_put( "Irondep", zirondep(:,:,1) * 1.e+3 * rfact2r * e3t_n(:,:,1) * tmask(:,:,1) ) ! surface downward dust depo of iron
                 IF( iom_use( "pdust" ) )   &
                 &  CALL iom_put( "pdust"  , dust(:,:) / ( wdust * rday )  * tmask(:,:,1) ) ! dust concentration at surface
@@ -151,5 +147,5 @@
          ELSE                                    
             IF( ln_diatrc )  &
-              &  trc2d(:,:,jp_pcs0_2d + 11) = zirondep(:,:,1) * 1.e+3 * rfact2r * fse3t(:,:,1) * tmask(:,:,1)
+              &  trc2d(:,:,jp_pcs0_2d + 11) = zirondep(:,:,1) * 1.e+3 * rfact2r * e3t_n(:,:,1) * tmask(:,:,1)
          ENDIF
          CALL wrk_dealloc( jpi, jpj,      zpdep, zsidep )
@@ -206,5 +202,5 @@
          DO ji = 1, jpi
             ikt  = mbkt(ji,jj)
-            zdep = fse3t(ji,jj,ikt) / xstep
+            zdep = e3t_n(ji,jj,ikt) / xstep
             zwsbio4(ji,jj) = MIN( 0.99 * zdep, wsbio4(ji,jj,ikt) )
             zwscal (ji,jj) = MIN( 0.99 * zdep, wscal (ji,jj,ikt) )
@@ -230,5 +226,5 @@
               zo2   = LOG10( MAX( 10. , trb(ji,jj,ikt,jpoxy) * 1E6 ) )
               zno3  = LOG10( MAX( 1.  , trb(ji,jj,ikt,jpno3) * 1E6 * rno3 ) )
-              zdep  = LOG10( fsdepw(ji,jj,ikt+1) )
+              zdep  = LOG10( gdepw_n(ji,jj,ikt+1) )
               zdenit2d(ji,jj) = -2.2567 - 1.185 * zflx - 0.221 * zflx**2 - 0.3995 * zno3 * zo2 + 1.25 * zno3    &
               &                + 0.4721 * zo2 - 0.0996 * zdep + 0.4256 * zflx * zo2
@@ -279,5 +275,5 @@
          DO ji = 1, jpi
             ikt  = mbkt(ji,jj)
-            zdep = xstep / fse3t(ji,jj,ikt) 
+            zdep = xstep / e3t_n(ji,jj,ikt) 
             zws4 = zwsbio4(ji,jj) * zdep
             zwsc = zwscal (ji,jj) * zdep
@@ -305,5 +301,5 @@
          DO ji = 1, jpi
             ikt  = mbkt(ji,jj)
-            zdep = xstep / fse3t(ji,jj,ikt) 
+            zdep = xstep / e3t_n(ji,jj,ikt) 
             zws4 = zwsbio4(ji,jj) * zdep
             zws3 = zwsbio3(ji,jj) * zdep
@@ -336,5 +332,5 @@
             tra(ji,jj,ikt,jptal) = tra(ji,jj,ikt,jptal) + rno3 * (zolimit + (1.+rdenit) * (zpdenit + zdenitt) )
             tra(ji,jj,ikt,jpdic) = tra(ji,jj,ikt,jpdic) + zpdenit + zolimit + zdenitt
-            sdenit(ji,jj) = rdenit * zpdenit * fse3t(ji,jj,ikt)
+            sdenit(ji,jj) = rdenit * zpdenit * e3t_n(ji,jj,ikt)
 #endif
          END DO
@@ -388,5 +384,5 @@
                zwork1(:,:) = 0.
                DO jk = 1, jpkm1
-                 zwork1(:,:) = zwork1(:,:) + nitrpot(:,:,jk) * nitrfix * zfact * fse3t(:,:,jk) * tmask(:,:,jk)
+                 zwork1(:,:) = zwork1(:,:) + nitrpot(:,:,jk) * nitrfix * zfact * e3t_n(:,:,jk) * tmask(:,:,jk)
                ENDDO
                CALL iom_put( "INTNFIX" , zwork1 ) 
@@ -395,5 +391,5 @@
       ELSE
          IF( ln_diatrc )  &
-            &  trc2d(:,:,jp_pcs0_2d + 12) = nitrpot(:,:,1) * nitrfix * rno3 * 1.e+3 * rfact2r * fse3t(:,:,1) * tmask(:,:,1)
+            &  trc2d(:,:,jp_pcs0_2d + 12) = nitrpot(:,:,1) * nitrfix * rno3 * 1.e+3 * rfact2r * e3t_n(:,:,1) * tmask(:,:,1)
       ENDIF
       !
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsink.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsink.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsink.F90	(revision 6140)
@@ -65,6 +65,4 @@
 #endif
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -108,5 +106,5 @@
             DO ji = 1,jpi
                zmax  = MAX( heup(ji,jj), hmld(ji,jj) )
-               zfact = MAX( 0., fsdepw(ji,jj,jk+1) - zmax ) / 5000._wp
+               zfact = MAX( 0., gdepw_n(ji,jj,jk+1) - zmax ) / 5000._wp
                wsbio4(ji,jj,jk) = wsbio2 + ( 200.- wsbio2 ) * zfact
             END DO
@@ -137,5 +135,5 @@
              DO ji = 1, jpi
                 IF( tmask(ji,jj,jk) == 1) THEN
-                   zwsmax =  0.5 * fse3t(ji,jj,jk) / xstep
+                   zwsmax =  0.5 * e3t_n(ji,jj,jk) / xstep
                    iiter1 =  MAX( iiter1, INT( wsbio3(ji,jj,jk) / zwsmax ) )
                    iiter2 =  MAX( iiter2, INT( wsbio4(ji,jj,jk) / zwsmax ) )
@@ -156,5 +154,5 @@
             DO ji = 1, jpi
                IF( tmask(ji,jj,jk) == 1 ) THEN
-                 zwsmax = 0.5 * fse3t(ji,jj,jk) / xstep
+                 zwsmax = 0.5 * e3t_n(ji,jj,jk) / xstep
                  wsbio3(ji,jj,jk) = MIN( wsbio3(ji,jj,jk), zwsmax * FLOAT( iiter1 ) )
                  wsbio4(ji,jj,jk) = MIN( wsbio4(ji,jj,jk), zwsmax * FLOAT( iiter2 ) )
@@ -700,5 +698,5 @@
          zl = zmin
          zr = zmax
-         wmax = 0.5 * fse3t(1,1,jk) * rday * float(niter1max) / rfact2
+         wmax = 0.5 * e3t_n(1,1,jk) * rday * float(niter1max) / rfact2
          zdiv = xkr_zeta + xkr_eta - xkr_eta * zl
          znum = zl - 1.
@@ -844,5 +842,5 @@
             DO jj = 1, jpj      
                DO ji = 1, jpi    
-                  zigma = zwsink2(ji,jj,jk+1) * zstep / fse3w(ji,jj,jk+1)
+                  zigma = zwsink2(ji,jj,jk+1) * zstep / e3w_n(ji,jj,jk+1)
                   zew   = zwsink2(ji,jj,jk+1)
                   psinkflx(ji,jj,jk+1) = -zew * ( trb(ji,jj,jk,jp_tra) - 0.5 * ( 1 + zigma ) * zakz(ji,jj,jk) ) * zstep
@@ -858,5 +856,5 @@
             DO jj = 1,jpj
                DO ji = 1, jpi
-                  zflx = ( psinkflx(ji,jj,jk) - psinkflx(ji,jj,jk+1) ) / fse3t(ji,jj,jk)
+                  zflx = ( psinkflx(ji,jj,jk) - psinkflx(ji,jj,jk+1) ) / e3t_n(ji,jj,jk)
                   trb(ji,jj,jk,jp_tra) = trb(ji,jj,jk,jp_tra) + zflx
                END DO
@@ -869,5 +867,5 @@
          DO jj = 1,jpj
             DO ji = 1, jpi
-               zflx = ( psinkflx(ji,jj,jk) - psinkflx(ji,jj,jk+1) ) / fse3t(ji,jj,jk)
+               zflx = ( psinkflx(ji,jj,jk) - psinkflx(ji,jj,jk+1) ) / e3t_n(ji,jj,jk)
                ztrb(ji,jj,jk) = ztrb(ji,jj,jk) + 2. * zflx
             END DO
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsms.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsms.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsms.F90	(revision 6140)
@@ -92,6 +92,6 @@
       !
       !                                                                    !   set time step size (Euler/Leapfrog)
-      IF( ( neuler == 0 .AND. kt == nittrc000 ) .OR. ln_top_euler ) THEN   ;    rfact = rdttrc(1)     !  at nittrc000
-      ELSEIF( kt <= nittrc000 + nn_dttrc )                          THEN   ;    rfact = 2. * rdttrc(1)   ! at nittrc000 or nittrc000+nn_dttrc (Leapfrog)
+      IF( ( neuler == 0 .AND. kt == nittrc000 ) .OR. ln_top_euler ) THEN   ;    rfact = rdttrc     !  at nittrc000
+      ELSEIF( kt <= nittrc000 + nn_dttrc )                          THEN   ;    rfact = 2. * rdttrc   ! at nittrc000 or nittrc000+nn_dttrc (Leapfrog)
       ENDIF
       !
@@ -102,5 +102,5 @@
          xstep = rfact2 / rday         ! Time step duration for biology
          IF(lwp) WRITE(numout,*) 
-         IF(lwp) WRITE(numout,*) '    Passive Tracer  time step    rfact  = ', rfact, ' rdt = ', rdttra(1)
+         IF(lwp) WRITE(numout,*) '    Passive Tracer  time step    rfact  = ', rfact, ' rdt = ', rdt
          IF(lwp) write(numout,*) '    PISCES  Biology time step    rfact2 = ', rfact2
          IF(lwp) WRITE(numout,*)
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/SED/sedrst.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/SED/sedrst.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/SED/sedrst.F90	(revision 6140)
@@ -60,11 +60,4 @@
 
       ALLOCATE( zdta(jpi,jpj,jpksed,jptrased), zdta1(jpi,jpj,jpksed,2), zhipor(jpoce,jpksed) ) 
-
-      IF ( jprstlib == jprstdimg ) THEN
-        ! eventually read netcdf file (monobloc)  for restarting on different number of processors
-        ! if restart_sed.nc exists, then set jlibalt to jpnf90
-        INQUIRE( FILE = 'restart_sed.nc', EXIST = llok )
-        IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
-      ENDIF
 
       CALL iom_open( 'restart_sed', numrsr, kiolib = jlibalt )     
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/trcwri_pisces.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/trcwri_pisces.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/PISCES/trcwri_pisces.F90	(revision 6140)
@@ -21,7 +21,9 @@
    PUBLIC trc_wri_pisces 
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id: trcnam.F90 5836 2015-10-26 14:49:40Z cetlod $
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
 
@@ -57,5 +59,5 @@
          zdic(:,:) = 0.
          DO jk = 1, jpkm1
-            zdic(:,:) = zdic(:,:) + trn(:,:,jk,jpdic) * fse3t(:,:,jk) * tmask(:,:,jk) * 12.
+            zdic(:,:) = zdic(:,:) + trn(:,:,jk,jpdic) * e3t_n(:,:,jk) * tmask(:,:,jk) * 12.
          ENDDO
          CALL iom_put( 'INTDIC', zdic )     
@@ -64,5 +66,5 @@
       IF( iom_use( "O2MIN" ) .OR. iom_use ( "ZO2MIN" ) ) THEN  ! Oxygen minimum concentration and depth 
          zo2min   (:,:) = trn(:,:,1,jpoxy) * tmask(:,:,1)
-         zdepo2min(:,:) = fsdepw(:,:,1)    * tmask(:,:,1)
+         zdepo2min(:,:) = gdepw_n(:,:,1)   * tmask(:,:,1)
          DO jk = 2, jpkm1
             DO jj = 1, jpj
@@ -71,5 +73,5 @@
                      IF( trn(ji,jj,jk,jpoxy) < zo2min(ji,jj) ) then
                         zo2min   (ji,jj) = trn(ji,jj,jk,jpoxy)
-                        zdepo2min(ji,jj) = fsdepw(ji,jj,jk)
+                        zdepo2min(ji,jj) = gdepw_n(ji,jj,jk)
                      ENDIF
                   ENDIF
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90	(revision 6140)
@@ -32,5 +32,4 @@
 
    PUBLIC   trc_adv       
-   PUBLIC   trc_adv_alloc 
    PUBLIC   trc_adv_ini  
 
@@ -58,9 +57,8 @@
    INTEGER ::              nadv             ! chosen advection scheme
    !
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::   r2dt  ! vertical profile time-step, = 2 rdttra
-   !                                                    ! except at nitrrc000 (=rdttra) if neuler=0
+   REAL(wp) ::   r2dttrc  ! vertical profile time-step, = 2 rdt
+   !                                                    ! except at nitrrc000 (=rdt) if neuler=0
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -70,16 +68,4 @@
    !!----------------------------------------------------------------------
 CONTAINS
-
-   INTEGER FUNCTION trc_adv_alloc()
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trc_adv_alloc  ***
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( r2dt(jpk), STAT=trc_adv_alloc )
-      !
-      IF( trc_adv_alloc /= 0 ) CALL ctl_warn('trc_adv_alloc : failed to allocate array.')
-      !
-   END FUNCTION trc_adv_alloc
-
 
    SUBROUTINE trc_adv( kt )
@@ -103,12 +89,12 @@
       !
       IF( ( neuler == 0 .AND. kt == nittrc000 ) .OR. ln_top_euler ) THEN     ! at nittrc000
-         r2dt(:) =  rdttrc(:)           ! = rdttrc (use or restarting with Euler time stepping)
+         r2dttrc =  rdttrc           ! = rdttrc (use or restarting with Euler time stepping)
       ELSEIF( kt <= nittrc000 + nn_dttrc ) THEN          ! at nittrc000 or nittrc000+1
-         r2dt(:) = 2. * rdttrc(:)       ! = 2 rdttrc (leapfrog)
+         r2dttrc = 2. * rdttrc       ! = 2 rdttrc (leapfrog)
       ENDIF
       !                                               !==  effective transport  ==!
       DO jk = 1, jpkm1
-         zun(:,:,jk) = e2u  (:,:) * fse3u(:,:,jk) * un(:,:,jk)                   ! eulerian transport
-         zvn(:,:,jk) = e1v  (:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+         zun(:,:,jk) = e2u  (:,:) * e3u_n(:,:,jk) * un(:,:,jk)                   ! eulerian transport
+         zvn(:,:,jk) = e1v  (:,:) * e3v_n(:,:,jk) * vn(:,:,jk)
          zwn(:,:,jk) = e1e2t(:,:)                 * wn(:,:,jk)
       END DO
@@ -134,13 +120,13 @@
          CALL tra_adv_cen    ( kt, nittrc000,'TRC',       zun, zvn, zwn     , trn, tra, jptra, nn_cen_h, nn_cen_v )
       CASE ( np_FCT )                                    ! FCT      : 2nd / 4th order
-         CALL tra_adv_fct    ( kt, nittrc000,'TRC', r2dt, zun, zvn, zwn, trb, trn, tra, jptra, nn_fct_h, nn_fct_v )
+         CALL tra_adv_fct    ( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra, nn_fct_h, nn_fct_v )
       CASE ( np_FCT_zts )                                ! 2nd order FCT with vertical time-splitting
-         CALL tra_adv_fct_zts( kt, nittrc000,'TRC', r2dt, zun, zvn, zwn, trb, trn, tra, jptra        , nn_fct_zts )
+         CALL tra_adv_fct_zts( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra        , nn_fct_zts )
       CASE ( np_MUS )                                    ! MUSCL
-         CALL tra_adv_mus    ( kt, nittrc000,'TRC', r2dt, zun, zvn, zwn, trb,      tra, jptra        , ln_mus_ups ) 
+         CALL tra_adv_mus    ( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb,      tra, jptra        , ln_mus_ups ) 
       CASE ( np_UBS )                                    ! UBS
-         CALL tra_adv_ubs    ( kt, nittrc000,'TRC', r2dt, zun, zvn, zwn, trb, trn, tra, jptra        , nn_ubs_v   )
+         CALL tra_adv_ubs    ( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra        , nn_ubs_v   )
       CASE ( np_QCK )                                    ! QUICKEST
-         CALL tra_adv_qck    ( kt, nittrc000,'TRC', r2dt, zun, zvn, zwn, trb, trn, tra, jptra                     )
+         CALL tra_adv_qck    ( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra                     )
       !
       END SELECT
@@ -231,5 +217,5 @@
             CALL ctl_stop( 'trc_adv_init: force 2nd order FCT scheme, 4th order does not exist with sub-timestepping' )
          ENDIF
-         IF( lk_vvl ) THEN
+         IF( .NOT.ln_linssh ) THEN
             CALL ctl_stop( 'trc_adv_init: vertical sub-timestepping not allow in non-linear free surface' )
          ENDIF
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcdmp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcdmp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcdmp.F90	(revision 6140)
@@ -43,5 +43,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -82,12 +81,10 @@
       !!              - save the trends ('key_trdmxl_trc')
       !!----------------------------------------------------------------------
-      !!
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-      !!
-      INTEGER  ::   ji, jj, jk, jn, jl       ! dummy loop indices
-      REAL(wp) ::   ztra                 ! temporary scalars
-      CHARACTER (len=22) :: charout
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER ::   ji, jj, jk, jn, jl   ! dummy loop indices
+      CHARACTER (len=22) ::   charout
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrtrd
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrcdta   ! 3D  workspace
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrcdta   ! 3D  workspace
       !!----------------------------------------------------------------------
       !
@@ -105,9 +102,9 @@
             !
             IF( ln_trc_ini(jn) ) THEN      ! update passive tracers arrays with input data read from file
-               
+               !
                jl = n_trc_index(jn) 
                CALL trc_dta( kt, sf_trcdta(jl),rf_trfac(jl) )   ! read tracer data at nit000
                ztrcdta(:,:,:) = sf_trcdta(jl)%fnow(:,:,:)
-
+               !
                SELECT CASE ( nn_zdmp_tr )
                !
@@ -116,10 +113,9 @@
                      DO jj = 2, jpjm1
                         DO ji = fs_2, fs_jpim1   ! vector opt.
-                           ztra = restotr(ji,jj,jk) * ( ztrcdta(ji,jj,jk) - trb(ji,jj,jk,jn) )
-                           tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra
+                           tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + restotr(ji,jj,jk) * ( ztrcdta(ji,jj,jk) - trb(ji,jj,jk,jn) )
                         END DO
                      END DO
                   END DO
-               !
+                  !
                CASE ( 1 )                !==  no damping in the turbocline (avt > 5 cm2/s)  ==!
                   DO jk = 1, jpkm1
@@ -127,23 +123,21 @@
                         DO ji = fs_2, fs_jpim1   ! vector opt.
                            IF( avt(ji,jj,jk) <= 5.e-4_wp )  THEN 
-                              ztra = restotr(ji,jj,jk) * ( ztrcdta(ji,jj,jk) - trb(ji,jj,jk,jn) )
-                              tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra
+                              tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + restotr(ji,jj,jk) * ( ztrcdta(ji,jj,jk) - trb(ji,jj,jk,jn) )
                            ENDIF
                         END DO
                      END DO
                   END DO
-               !
+                  !
                CASE ( 2 )               !==  no damping in the mixed layer   ==! 
                   DO jk = 1, jpkm1
                      DO jj = 2, jpjm1
                         DO ji = fs_2, fs_jpim1   ! vector opt.
-                           IF( fsdept(ji,jj,jk) >= hmlp (ji,jj) ) THEN
-                              ztra = restotr(ji,jj,jk) * ( ztrcdta(ji,jj,jk) - trb(ji,jj,jk,jn) )
-                              tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra
+                           IF( gdept_n(ji,jj,jk) >= hmlp (ji,jj) ) THEN
+                              tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + restotr(ji,jj,jk) * ( ztrcdta(ji,jj,jk) - trb(ji,jj,jk,jn) )
                            END IF
                         END DO
                      END DO
                   END DO
-               !  
+                  !  
                END SELECT
                ! 
@@ -162,7 +156,8 @@
       IF( l_trdtrc )  CALL wrk_dealloc( jpi, jpj, jpk, ztrtrd )
       !                                          ! print mean trends (used for debugging)
-      IF( ln_ctl )   THEN
-         WRITE(charout, FMT="('dmp ')") ;  CALL prt_ctl_trc_info(charout)
-                                           CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
+      IF( ln_ctl ) THEN
+         WRITE(charout, FMT="('dmp ')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
       ENDIF
       !
@@ -170,4 +165,5 @@
       !
    END SUBROUTINE trc_dmp
+
 
    SUBROUTINE trc_dmp_ini
@@ -180,14 +176,11 @@
       !!              called by trc_dmp at the first timestep (nittrc000)
       !!----------------------------------------------------------------------
-      !
-      INTEGER ::  ios                 ! Local integer output status for namelist read
-      INTEGER :: imask  !local file handle
-      !
+      INTEGER ::   ios, imask  ! local integers
+      !!
       NAMELIST/namtrc_dmp/ nn_zdmp_tr , cn_resto_tr
       !!----------------------------------------------------------------------
-
+      !
       IF( nn_timing == 1 )  CALL timing_start('trc_dmp_init')
       !
-
       REWIND( numnat_ref )              ! Namelist namtrc_dmp in reference namelist : Passive tracers newtonian damping
       READ  ( numnat_ref, namtrc_dmp, IOSTAT = ios, ERR = 909)
@@ -233,4 +226,5 @@
    END SUBROUTINE trc_dmp_ini
 
+
    SUBROUTINE trc_dmp_clo( kt )
       !!---------------------------------------------------------------------
@@ -245,12 +239,11 @@
       !!                nctsi2(), nctsj2() : north-east Closed sea limits (i,j)
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-      !
-      INTEGER :: ji , jj, jk, jn, jl, jc                     ! dummy loop indicesa
-      INTEGER :: isrow                                      ! local index
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrcdta       ! 3D  workspace
-
-      !!----------------------------------------------------------------------
-
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !
+      INTEGER ::   ji , jj, jk, jn, jl, jc   ! dummy loop indicesa
+      INTEGER ::   isrow                     ! local index
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrcdta   ! 3D  workspace
+      !!----------------------------------------------------------------------
+      !
       IF( kt == nit000 ) THEN
          ! initial values
@@ -364,5 +357,4 @@
    END SUBROUTINE trc_dmp_clo
 
-
 #else
    !!----------------------------------------------------------------------
@@ -376,5 +368,4 @@
 #endif
 
-
    !!======================================================================
 END MODULE trcdmp
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcldf.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcldf.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcldf.F90	(revision 6140)
@@ -12,18 +12,17 @@
    !!   'key_top'                                                TOP models
    !!----------------------------------------------------------------------
-   !!   trc_ldf      : update the tracer trend with the lateral diffusion
-   !!   trc_ldf_ini  : initialization, namelist read, and parameters control
-   !!----------------------------------------------------------------------
-   USE trc           ! ocean passive tracers variables
-   USE oce_trc       ! ocean dynamics and active tracers
-   USE ldfslp        ! lateral diffusion: iso-neutral slope
-   USE traldf_lap    ! lateral diffusion: laplacian iso-level            operator  (tra_ldf_lap   routine)
-   USE traldf_iso    ! lateral diffusion: laplacian iso-neutral standard operator  (tra_ldf_iso   routine)
-   USE traldf_triad  ! lateral diffusion: laplacian iso-neutral triad    operator  (tra_ldf_triad routine)
-   USE traldf_blp    ! lateral diffusion (iso-level lap/blp)                       (tra_ldf_lap   routine)
-   USE trd_oce       ! trends: ocean variables
-   USE trdtra        ! trends manager: tracers 
+   !!   trc_ldf       : update the tracer trend with the lateral diffusion
+   !!   trc_ldf_ini   : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   USE trc            ! ocean passive tracers variables
+   USE oce_trc        ! ocean dynamics and active tracers
+   USE ldfslp         ! lateral diffusion: iso-neutral slope
+   USE traldf_lap_blp ! lateral diffusion: lap/bilaplacian iso-level      operator  (tra_ldf_lap/_blp   routine)
+   USE traldf_iso     ! lateral diffusion: laplacian iso-neutral standard operator  (tra_ldf_iso        routine)
+   USE traldf_triad   ! lateral diffusion: laplacian iso-neutral triad    operator  (tra_ldf_     triad routine)
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! trends manager: tracers
    !
-   USE prtctl_trc      ! Print control
+   USE prtctl_trc     ! Print control
 
    IMPLICIT NONE
@@ -42,10 +41,10 @@
    REAL(wp), PUBLIC ::   rn_bhtrc_0          !: bilaplacian      -          --     -       -   [m4/s]
    !
-                                                 !!: ** lateral mixing namelist (nam_trcldf) **
-   REAL(wp) ::  rldf    ! ratio between active and passive tracers diffusive coefficient
+   !                      !!: ** lateral mixing namelist (nam_trcldf) **
+   REAL(wp) ::  rldf       ! ratio between active and passive tracers diffusive coefficient
+   
    INTEGER  ::  nldf = 0   ! type of lateral diffusion used defined from ln_trcldf_... namlist logicals)
    
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -64,5 +63,5 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-      !!
+      !
       INTEGER            :: jn
       CHARACTER (len=22) :: charout
@@ -99,5 +98,5 @@
       END SELECT
       !
-      IF( l_trdtrc )   THEN                    ! save the horizontal diffusive trends for further diagnostics
+      IF( l_trdtrc )   THEN                    ! send the trends for further diagnostics
         DO jn = 1, jptra
            ztrtrd(:,:,:,jn) = tra(:,:,:,jn) - ztrtrd(:,:,:,jn)
@@ -106,8 +105,9 @@
         CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztrtrd )
       ENDIF
-      !                                        ! print mean trends (used for debugging)
-      IF( ln_ctl ) THEN
-         WRITE(charout, FMT="('ldf ')")   ;   CALL prt_ctl_trc_info(charout)
-                                              CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
+      !                
+      IF( ln_ctl ) THEN                        ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('ldf ')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
       ENDIF
       !
@@ -133,19 +133,20 @@
       INTEGER ::   ioptio, ierr   ! temporary integers
       INTEGER ::   ios            ! Local integer output status for namelist read
-      !
+      !!
       NAMELIST/namtrc_ldf/ ln_trcldf_lap, ln_trcldf_blp,                                  &
          &                 ln_trcldf_lev, ln_trcldf_hor, ln_trcldf_iso, ln_trcldf_triad,  &
          &                 rn_ahtrc_0   , rn_bhtrc_0
       !!----------------------------------------------------------------------
-      REWIND( numnat_ref )              !  namtrc_ldf in reference namelist 
+      !
+      REWIND( numnat_ref )             !  namtrc_ldf in reference namelist 
       READ  ( numnat_ref, namtrc_ldf, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_ldf in reference namelist', lwp )
-
-      REWIND( numnat_cfg )              !  namtrc_ldf in configuration namelist 
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_ldf in reference namelist', lwp )
+      !
+      REWIND( numnat_cfg )             !  namtrc_ldf in configuration namelist 
       READ  ( numnat_cfg, namtrc_ldf, IOSTAT = ios, ERR = 904 )
-904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_ldf in configuration namelist', lwp )
+904   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_ldf in configuration namelist', lwp )
       IF(lwm) WRITE ( numont, namtrc_ldf )
-
-      IF(lwp) THEN                    ! Namelist print
+      !
+      IF(lwp) THEN                     ! Namelist print
          WRITE(numout,*)
          WRITE(numout,*) 'trc_ldf_ini : lateral tracer diffusive operator'
@@ -174,5 +175,5 @@
       IF( ln_trcldf_lap .AND. ln_trcldf_blp )   CALL ctl_stop( 'trc_ldf_ctl: bilaplacian should be used on both TRC and TRA' )
       IF( ln_trcldf_blp .AND. ln_trcldf_lap )   CALL ctl_stop( 'trc_ldf_ctl:   laplacian should be used on both TRC and TRA' )
-      
+      !
       ioptio = 0
       IF( ln_trcldf_lev )   ioptio = ioptio + 1
@@ -180,5 +181,5 @@
       IF( ln_trcldf_iso )   ioptio = ioptio + 1
       IF( ioptio /= 1   )   CALL ctl_stop( 'trc_ldf_ctl: use only ONE direction (level/hor/iso)' )
-
+      !
       ! defined the type of lateral diffusion from ln_trcldf_... logicals
       ! CAUTION : nldf = 1 is used in trazdf_imp, change it carefully
@@ -204,9 +205,9 @@
          ENDIF
          !                                ! diffusivity ratio: passive / active tracers 
-         IF( ABS(rn_aht_0) < 2._wp*TINY(1.e0) ) THEN
-            IF( ABS(rn_ahtrc_0) < 2._wp*TINY(1.e0) ) THEN
+         IF( ABS(rn_aht_0) < 2._wp*TINY(1._wp) ) THEN
+            IF( ABS(rn_ahtrc_0) < 2._wp*TINY(1._wp) ) THEN
                rldf = 1.0_wp
             ELSE
-               CALL ctl_stop( 'STOP', 'trc_ldf_ctl : cannot define rldf, rn_aht_0==0, rn_ahtrc_0 /=0' )
+               CALL ctl_stop( 'trc_ldf_ctl : cannot define rldf, rn_aht_0==0, rn_ahtrc_0 /=0' )
             ENDIF
          ELSE
@@ -235,9 +236,9 @@
          ENDIF
          !                                ! diffusivity ratio: passive / active tracers 
-         IF( ABS(rn_bht_0) < 2._wp*TINY(1.e0) ) THEN
-            IF( ABS(rn_bhtrc_0) < 2._wp*TINY(1.e0) ) THEN
+         IF( ABS(rn_bht_0) < 2._wp*TINY(1._wp) ) THEN
+            IF( ABS(rn_bhtrc_0) < 2._wp*TINY(1._wp) ) THEN
                rldf = 1.0_wp
             ELSE
-               CALL ctl_stop( 'STOP', 'trc_ldf_ctl : cannot define rldf, rn_aht_0==0, rn_ahtrc_0 /=0' )
+               CALL ctl_stop( 'trc_ldf_ctl : cannot define rldf, rn_aht_0==0, rn_ahtrc_0 /=0' )
             ENDIF
          ELSE
@@ -246,21 +247,19 @@
       ENDIF
       !
-      IF( ierr == 1 )   CALL ctl_stop( ' iso-level in z-coordinate - partial step, not allowed' )
-      IF( ln_ldfeiv .AND. .NOT.ln_trcldf_iso )   &
-           CALL ctl_stop( '          eddy induced velocity on tracers',   &
-           &              ' the eddy induced velocity on tracers requires isopycnal laplacian diffusion' )
-      IF( nldf == 1 .OR. nldf == 3 ) THEN      ! rotation
-         IF( .NOT.l_ldfslp )   CALL ctl_stop( '          the rotation of the diffusive tensor require l_ldfslp' )
-      ENDIF
+      IF( ierr == 1 )   CALL ctl_stop( 'trc_ldf_ctl: iso-level in z-partial step, not allowed' )
+      IF( ln_ldfeiv .AND. .NOT.ln_trcldf_iso )   CALL ctl_stop( 'trc_ldf_ctl: eiv requires isopycnal laplacian diffusion' )
+      IF( nldf == 1 .OR. nldf == 3 )   l_ldfslp = .TRUE.    ! slope of neutral surfaces required 
       !
       IF(lwp) THEN
          WRITE(numout,*)
-         IF( nldf == np_no_ldf )   WRITE(numout,*) '          NO lateral diffusion'
-         IF( nldf == np_lap    )   WRITE(numout,*) '          laplacian iso-level operator'
-         IF( nldf == np_lap_i  )   WRITE(numout,*) '          Rotated laplacian operator (standard)'
-         IF( nldf == np_lap_it )   WRITE(numout,*) '          Rotated laplacian operator (triad)'
-         IF( nldf == np_blp    )   WRITE(numout,*) '          bilaplacian iso-level operator'
-         IF( nldf == np_blp_i  )   WRITE(numout,*) '          Rotated bilaplacian operator (standard)'
-         IF( nldf == np_blp_it )   WRITE(numout,*) '          Rotated bilaplacian operator (triad)'
+         SELECT CASE( nldf )
+         CASE( np_no_ldf )   ;   WRITE(numout,*) '          NO lateral diffusion'
+         CASE( np_lap    )   ;   WRITE(numout,*) '          laplacian iso-level operator'
+         CASE( np_lap_i  )   ;   WRITE(numout,*) '          Rotated laplacian operator (standard)'
+         CASE( np_lap_it )   ;   WRITE(numout,*) '          Rotated laplacian operator (triad)'
+         CASE( np_blp    )   ;   WRITE(numout,*) '          bilaplacian iso-level operator'
+         CASE( np_blp_i  )   ;   WRITE(numout,*) '          Rotated bilaplacian operator (standard)'
+         CASE( np_blp_it )   ;   WRITE(numout,*) '          Rotated bilaplacian operator (triad)'
+         END SELECT
       ENDIF
       !
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 6140)
@@ -33,4 +33,6 @@
    USE trdtra
    USE tranxt
+   USE trcbdy          ! BDY open boundaries
+   USE bdy_par, only: lk_bdy
 # if defined key_agrif
    USE agrif_top_interp
@@ -41,7 +43,6 @@
 
    PUBLIC   trc_nxt          ! routine called by step.F90
-   PUBLIC   trc_nxt_alloc    ! routine called by nemogcm.F90
 
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::   r2dt
+   REAL(wp) ::   r2dttrc
 
    !!----------------------------------------------------------------------
@@ -51,15 +52,4 @@
    !!----------------------------------------------------------------------
 CONTAINS
-
-   INTEGER FUNCTION trc_nxt_alloc()
-      !!----------------------------------------------------------------------
-      !!                   ***  ROUTINE trc_nxt_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE( r2dt(jpk), STAT=trc_nxt_alloc )
-      !
-      IF( trc_nxt_alloc /= 0 )   CALL ctl_warn('trc_nxt_alloc : failed to allocate array')
-      !
-   END FUNCTION trc_nxt_alloc
-
 
    SUBROUTINE trc_nxt( kt )
@@ -101,32 +91,25 @@
          WRITE(numout,*) 'trc_nxt : time stepping on passive tracers'
       ENDIF
-
+      !
 #if defined key_agrif
       CALL Agrif_trc                   ! AGRIF zoom boundaries
 #endif
-      ! Update after tracer on domain lateral boundaries
-      DO jn = 1, jptra
+      DO jn = 1, jptra                 ! Update after tracer on domain lateral boundaries
          CALL lbc_lnk( tra(:,:,:,jn), 'T', 1. )   
       END DO
 
+      IF( lk_bdy )  CALL trc_bdy( kt )
 
-#if defined key_bdy
-!!      CALL bdy_trc( kt )               ! BDY open boundaries
-#endif
-
-
-      ! set time step size (Euler/Leapfrog)
-      IF( neuler == 0 .AND. kt ==  nittrc000 ) THEN  ;  r2dt(:) =     rdttrc(:)   ! at nittrc000             (Euler)
-      ELSEIF( kt <= nittrc000 + nn_dttrc )     THEN  ;  r2dt(:) = 2.* rdttrc(:)   ! at nit000 or nit000+1 (Leapfrog)
+      !                                ! set time step size (Euler/Leapfrog)
+      IF( neuler == 0 .AND. kt ==  nittrc000 ) THEN  ;  r2dttrc =     rdttrc   ! at nittrc000             (Euler)
+      ELSEIF( kt <= nittrc000 + nn_dttrc )     THEN  ;  r2dttrc = 2.* rdttrc   ! at nit000 or nit000+1 (Leapfrog)
       ENDIF
 
-      ! trends computation initialisation
-      IF( l_trdtrc )  THEN
-         CALL wrk_alloc( jpi, jpj, jpk, jptra, ztrdt )  !* store now fields before applying the Asselin filter
+      IF( l_trdtrc )  THEN             ! trends: store now fields before the Asselin filter application
+         CALL wrk_alloc( jpi, jpj, jpk, jptra, ztrdt )
          ztrdt(:,:,:,:)  = trn(:,:,:,:)
       ENDIF
-      ! Leap-Frog + Asselin filter time stepping
-      IF( neuler == 0 .AND. kt == nittrc000 ) THEN        ! Euler time-stepping at first time-step
-         !                                                ! (only swap)
+      !                                ! Leap-Frog + Asselin filter time stepping
+      IF( neuler == 0 .AND. kt == nittrc000 ) THEN    ! Euler time-stepping at first time-step (only swap)
          DO jn = 1, jptra
             DO jk = 1, jpkm1
@@ -134,18 +117,21 @@
             END DO
          END DO
-         !                                              
-      ELSE
-         ! Leap-Frog + Asselin filter time stepping
-         IF( lk_vvl ) THEN   ;   CALL tra_nxt_vvl( kt, nittrc000, rdttrc, 'TRC', trb, trn, tra,      &
-           &                                                                sbc_trc, sbc_trc_b, jptra )      ! variable volume level (vvl) 
-         ELSE                ;   CALL tra_nxt_fix( kt, nittrc000,         'TRC', trb, trn, tra, jptra )      ! fixed    volume level 
+      ELSE                                            ! Asselin filter + swap
+         IF( ln_linssh ) THEN   ;   CALL tra_nxt_fix( kt, nittrc000,         'TRC', trb, trn, tra, jptra )  !     linear ssh
+         ELSE                   ;   CALL tra_nxt_vvl( kt, nittrc000, rdttrc, 'TRC', trb, trn, tra,      &
+           &                                                                   sbc_trc, sbc_trc_b, jptra )  ! non-linear ssh
          ENDIF
+         !
+         DO jn = 1, jptra
+            CALL lbc_lnk( trb(:,:,:,jn), 'T', 1._wp ) 
+            CALL lbc_lnk( trn(:,:,:,jn), 'T', 1._wp )
+            CALL lbc_lnk( tra(:,:,:,jn), 'T', 1._wp )
+         END DO
       ENDIF
-
-      ! trends computation
-      IF( l_trdtrc ) THEN                                      ! trends
+      !
+      IF( l_trdtrc ) THEN              ! trends: send Asselin filter trends to trdtra manager for further diagnostics
          DO jn = 1, jptra
             DO jk = 1, jpkm1
-               zfact = 1.e0 / r2dt(jk)  
+               zfact = 1._wp / r2dttrc  
                ztrdt(:,:,jk,jn) = ( trb(:,:,jk,jn) - ztrdt(:,:,jk,jn) ) * zfact 
                CALL trd_tra( kt, 'TRC', jn, jptra_atf, ztrdt )
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 6140)
@@ -28,8 +28,5 @@
    PUBLIC   trc_sbc   ! routine called by step.F90
 
-   REAL(wp) ::   r2dt  !  time-step at surface
-
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -76,6 +73,6 @@
       !
       ! Allocate temporary workspace
-                      CALL wrk_alloc( jpi, jpj,      zsfx   )
-      IF( l_trdtrc )  CALL wrk_alloc( jpi, jpj, jpk, ztrtrd )
+                      CALL wrk_alloc( jpi,jpj,       zsfx   )
+      IF( l_trdtrc )  CALL wrk_alloc( jpi,jpj,jpk,   ztrtrd )
       !
       zrtrn = 1.e-15_wp
@@ -88,10 +85,10 @@
 
       IF( ln_top_euler) THEN
-         r2dt =  rdttrc(1)              ! = rdttrc (use Euler time stepping)
+         r2dt =  rdttrc              ! = rdttrc (use Euler time stepping)
       ELSE
          IF( neuler == 0 .AND. kt == nittrc000 ) THEN     ! at nittrc000
-            r2dt = rdttrc(1)           ! = rdttrc (restarting with Euler time stepping)
+            r2dt = rdttrc            ! = rdttrc (restarting with Euler time stepping)
          ELSEIF( kt <= nittrc000 + nn_dttrc ) THEN          ! at nittrc000 or nittrc000+1
-            r2dt = 2. * rdttrc(1)       ! = 2 rdttrc (leapfrog)
+            r2dt = 2. * rdttrc       ! = 2 rdttrc (leapfrog)
          ENDIF
       ENDIF
@@ -129,5 +126,5 @@
       ! Coupling offline : runoff are in emp which contains E-P-R
       !
-      IF( .NOT. lk_offline .AND. lk_vvl ) THEN  ! online coupling with vvl
+      IF( .NOT. lk_offline .AND. .NOT.ln_linssh ) THEN  ! online coupling with vvl
          zsfx(:,:) = 0._wp
       ELSE                                      ! online coupling free surface or offline with free surface
@@ -138,6 +135,5 @@
       DO jn = 1, jptra
          !
-         IF( l_trdtrc ) ztrtrd(:,:,:) = tra(:,:,:,jn)  ! save trends
-         !                                             ! add the trend to the general tracer trend
+         IF( l_trdtrc )   ztrtrd(:,:,:) = tra(:,:,:,jn)  ! save trends
 
          IF ( nn_ice_tr == -1 ) THEN  ! No tracers in sea ice (null concentration in sea ice)
@@ -153,5 +149,5 @@
             DO jj = 2, jpj
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zse3t = 1. / fse3t(ji,jj,1)
+                  zse3t = 1. / e3t_n(ji,jj,1)
                   ! tracer flux at the ice/ocean interface (tracer/m2/s)
                   zftra = - trc_i(ji,jj,jn) * fmmflx(ji,jj) ! uptake of tracer in the sea ice
@@ -174,5 +170,5 @@
          DO jj = 2, jpj
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zse3t = zfact / fse3t(ji,jj,1)
+               zse3t = zfact / e3t_n(ji,jj,1)
                tra(ji,jj,1,jn) = tra(ji,jj,1,jn) + ( sbc_trc_b(ji,jj,jn) + sbc_trc(ji,jj,jn) ) * zse3t
             END DO
@@ -203,6 +199,6 @@
                                            CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
       ENDIF
-                      CALL wrk_dealloc( jpi, jpj,      zsfx   )
-      IF( l_trdtrc )  CALL wrk_dealloc( jpi, jpj, jpk, ztrtrd )
+                      CALL wrk_dealloc( jpi,jpj,       zsfx   )
+      IF( l_trdtrc )  CALL wrk_dealloc( jpi,jpj,jpk,   ztrtrd )
       !
       IF( nn_timing == 1 )  CALL timing_stop('trc_sbc')
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 6140)
@@ -25,4 +25,6 @@
    USE trcsbc          ! surface boundary condition          (trc_sbc routine)
    USE zpshde          ! partial step: hor. derivative       (zps_hde routine)
+   USE trcbdy          ! BDY open boundaries
+   USE bdy_par, only: lk_bdy
 
 #if defined key_agrif
@@ -64,4 +66,5 @@
          IF( ln_trcdmp )        CALL trc_dmp    ( kt )      ! internal damping trends
          IF( ln_trcdmp_clo )    CALL trc_dmp_clo( kt )      ! internal damping trends on closed seas only
+         IF( lk_bdy )           CALL trc_bdy_dmp( kt )      ! BDY damping trends
                                 CALL trc_adv    ( kt )      ! horizontal & vertical advection 
          !                                                         ! Partial top/bottom cell: GRADh( trb )  
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90	(revision 6140)
@@ -28,5 +28,4 @@
    PUBLIC   trc_zdf         ! called by step.F90 
    PUBLIC   trc_zdf_ini     ! called by nemogcm.F90 
-   PUBLIC   trc_zdf_alloc   ! called by nemogcm.F90 
    
    !                                        !!** Vertical diffusion (nam_trczdf) **
@@ -36,9 +35,8 @@
    INTEGER ::   nzdf = 0               ! type vertical diffusion algorithm used
       !                                ! defined from ln_zdf...  namlist logicals)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::  r2dt   ! vertical profile time-step, = 2 rdttra
-      !                                                 ! except at nittrc000 (=rdttra) if neuler=0
+   REAL(wp) ::  r2dttrc   ! vertical profile time-step, = 2 rdt
+      !                   ! except at nittrc000 (=rdt) if neuler=0
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
@@ -49,15 +47,4 @@
    !!----------------------------------------------------------------------
 CONTAINS
-   
-   INTEGER FUNCTION trc_zdf_alloc()
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trc_zdf_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE( r2dt(jpk) , STAT=trc_zdf_alloc )
-      !
-      IF( trc_zdf_alloc /= 0 )   CALL ctl_warn('trc_zdf_alloc : failed to allocate array.')
-      !
-   END FUNCTION trc_zdf_alloc
-
 
    SUBROUTINE trc_zdf( kt )
@@ -77,7 +64,7 @@
       !
       IF( ( neuler == 0 .AND. kt == nittrc000 ) .OR. ln_top_euler ) THEN     ! at nittrc000
-         r2dt(:) =  rdttrc(:)           ! = rdttrc (use or restarting with Euler time stepping)
+         r2dttrc =  rdttrc           ! = rdttrc (use or restarting with Euler time stepping)
       ELSEIF( kt <= nittrc000 + nn_dttrc ) THEN          ! at nittrc000 or nittrc000+1
-         r2dt(:) = 2. * rdttrc(:)       ! = 2 rdttrc (leapfrog)
+         r2dttrc = 2. * rdttrc       ! = 2 rdttrc (leapfrog)
       ENDIF
 
@@ -88,6 +75,6 @@
 
       SELECT CASE ( nzdf )                       ! compute lateral mixing trend and add it to the general trend
-      CASE ( 0 ) ;  CALL tra_zdf_exp( kt, nittrc000, 'TRC', r2dt, nn_trczdf_exp, trb, tra, jptra )    !   explicit scheme 
-      CASE ( 1 ) ;  CALL tra_zdf_imp( kt, nittrc000, 'TRC', r2dt,                trb, tra, jptra )    !   implicit scheme          
+      CASE ( 0 ) ;  CALL tra_zdf_exp( kt, nittrc000, 'TRC', r2dttrc, nn_trczdf_exp, trb, tra, jptra )    !   explicit scheme 
+      CASE ( 1 ) ;  CALL tra_zdf_imp( kt, nittrc000, 'TRC', r2dttrc,                trb, tra, jptra )    !   implicit scheme          
       END SELECT
 
@@ -95,5 +82,5 @@
          DO jn = 1, jptra
             DO jk = 1, jpkm1
-               ztrtrd(:,:,jk,jn) = ( ( tra(:,:,jk,jn) - trb(:,:,jk,jn) ) / r2dt(jk) ) - ztrtrd(:,:,jk,jn)
+               ztrtrd(:,:,jk,jn) = ( ( tra(:,:,jk,jn) - trb(:,:,jk,jn) ) / r2dttrc ) - ztrtrd(:,:,jk,jn)
             END DO
             CALL trd_tra( kt, 'TRC', jn, jptra_zdf, ztrtrd(:,:,:,jn) )
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc.F90	(revision 6140)
@@ -66,5 +66,4 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "zdfddm_substitute.h90"
    !!----------------------------------------------------------------------
@@ -175,5 +174,5 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  IF( jk - nmld_trc(ji,jj) < 0 )   wkx_trc(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
+                  IF( jk - nmld_trc(ji,jj) < 0 )   wkx_trc(ji,jj,jk) = e3t_n(ji,jj,jk) * tmask(ji,jj,jk)
                END DO
             END DO
@@ -293,5 +292,5 @@
             DO jj = 1,jpj
               DO ji = 1,jpi
-                  IF( jk - nmld_trc(ji,jj) < 0. )   wkx_trc(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
+                  IF( jk - nmld_trc(ji,jj) < 0. )   wkx_trc(ji,jj,jk) = e3t_n(ji,jj,jk) * tmask(ji,jj,jk)
                END DO
             END DO
@@ -330,5 +329,5 @@
       !! 
       !! ** Purpose :  Compute and cumulate the mixed layer trends over an analysis
-      !!               period, and write NetCDF (or dimg) outputs.
+      !!               period, and write NetCDF outputs.
       !!
       !! ** Method/usage :
@@ -390,8 +389,4 @@
       !
       CHARACTER (LEN=10) ::   clvar
-#if defined key_dimgout
-      INTEGER ::   iyear,imon,iday
-      CHARACTER(LEN=80) ::   cltext, clmode
-#endif
       !!----------------------------------------------------------------------
 
@@ -417,5 +412,5 @@
                DO jn = 1, jptra
                   IF( ln_trdtrc(jn) )    &
-                  tmltrd_trc(ji,jj,jpmxl_trc_zdf,jn) = - zavt / fse3w(ji,jj,ik) * tmask(ji,jj,ik)  &
+                  tmltrd_trc(ji,jj,jpmxl_trc_zdf,jn) = - zavt / e3w_n(ji,jj,ik) * tmask(ji,jj,ik)  &
                        &                    * ( trn(ji,jj,ik-1,jn) - trn(ji,jj,ik,jn) )            &
                        &                    / MAX( 1., rmld_trc(ji,jj) ) * tmask(ji,jj,1)
@@ -774,12 +769,5 @@
       ! ======================================================================
 
-      ! IV.1 Code for dimg mpp output
-      ! -----------------------------
-
-# if defined key_dimgout
-      STOP 'Not implemented'
-# else
-      
-      ! IV.2 Code for IOIPSL/NetCDF output
+      ! IV.1 Code for IOIPSL/NetCDF output
       ! ----------------------------------
 
@@ -865,6 +853,4 @@
       icount = 1
 
-# endif /* key_dimgout */
-
       IF( MOD( itmod, nn_trd_trc ) == 0 ) THEN
          !
@@ -896,5 +882,5 @@
       !!
       !! ** Purpose :  Compute and cumulate the mixed layer biological trends over an analysis
-      !!               period, and write NetCDF (or dimg) outputs.
+      !!               period, and write NetCDF outputs.
       !!
       !! ** Method/usage :
@@ -943,8 +929,4 @@
       LOGICAL  :: llwarn  = .TRUE., lldebug = .TRUE.
       REAL(wp) :: zfn, zfn2
-#if defined key_dimgout
-      INTEGER ::  iyear,imon,iday
-      CHARACTER(LEN=80) :: cltext, clmode
-#endif
       !!----------------------------------------------------------------------
       ! ... Warnings
@@ -1055,12 +1037,5 @@
       ! ======================================================================
 
-      ! IV.1 Code for dimg mpp output
-      ! -----------------------------
-
-# if defined key_dimgout
-      STOP 'Not implemented'
-# else
-
-      ! IV.2 Code for IOIPSL/NetCDF output
+      ! IV.1 Code for IOIPSL/NetCDF output
       ! ----------------------------------
 
@@ -1107,5 +1082,4 @@
 
 
-# endif /* key_dimgout */
 
       IF( MOD( itmod, nn_trd_trc ) == 0 ) THEN
@@ -1258,7 +1232,4 @@
       ! ======================================================================
 
-#if defined key_dimgout 
-      ???
-#else
       ! clmxl = legend root for netCDF output
       IF( nn_ctls_trc == 0 ) THEN                                   ! control surface = mixed-layer with density criterion
@@ -1403,5 +1374,4 @@
 #endif
 
-#endif        /* key_dimgout */
    END SUBROUTINE trd_mxl_trc_init
 
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc_rst.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc_rst.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc_rst.F90	(revision 6140)
@@ -21,4 +21,5 @@
   
    INTEGER ::   nummldw_trc               ! logical unit for mld restart
+   
    !!---------------------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -26,7 +27,5 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!---------------------------------------------------------------------------------
-  
 CONTAINS
-  
 
     SUBROUTINE trd_mxl_trc_rst_write( kt )
@@ -147,12 +146,4 @@
       clpath = TRIM(cn_trcrst_indir)
       IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
-
-      IF ( jprstlib == jprstdimg ) THEN
-        ! eventually read netcdf file (monobloc)  for restarting on different number of processors
-        ! if {cn_trdrst_trc_in}.nc exists, then set jlibalt to jpnf90
-        INQUIRE( FILE = TRIM(clpath)//TRIM(cn_trdrst_trc_in)//'.nc', EXIST = llok )
-        IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
-      ENDIF
-
       CALL iom_open( TRIM(clpath)//TRIM(cn_trdrst_trc_in), inum, kiolib = jlibalt ) 
       
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/trc.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 6140)
@@ -14,4 +14,7 @@
    USE par_oce
    USE par_trc
+#if defined key_bdy
+   USE bdy_oce, only: nb_bdy, OBC_DATA
+#endif
    
    IMPLICIT NONE
@@ -64,5 +67,5 @@
    CHARACTER(len = 80) , PUBLIC                                    ::  cn_trcrst_out  !: suffix of pass. tracer restart name (output)
    CHARACTER(len = 256), PUBLIC                                    ::  cn_trcrst_outdir  !: restart output directory
-   REAL(wp)            , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::  rdttrc         !: vertical profile of passive tracer time step
+   REAL(wp)            , PUBLIC                                    ::  rdttrc         !: passive tracer time step
    LOGICAL             , PUBLIC                                    ::  ln_top_euler  !: boolean term for euler integration 
    LOGICAL             , PUBLIC                                    ::  ln_trcdta      !: Read inputs data from files
@@ -91,4 +94,9 @@
        CHARACTER(len = 20)  :: clunit   !: unit
        LOGICAL              :: llinit   !: read in a file or not
+#if defined  key_my_trc
+       LOGICAL              :: llsbc   !: read in a file or not
+       LOGICAL              :: llcbc   !: read in a file or not
+       LOGICAL              :: llobc   !: read in a file or not
+#endif
        LOGICAL              :: llsave   !: save the tracer or not
    END TYPE PTRACER
@@ -181,4 +189,12 @@
 # endif
    !
+#if defined key_bdy
+   CHARACTER(len=20), PUBLIC, ALLOCATABLE,  SAVE,  DIMENSION(:)   ::  cn_trc_dflt          ! Default OBC condition for all tracers
+   CHARACTER(len=20), PUBLIC, ALLOCATABLE,  SAVE,  DIMENSION(:)   ::  cn_trc               ! Choice of boundary condition for tracers
+   INTEGER,           PUBLIC, ALLOCATABLE,  SAVE,  DIMENSION(:)   ::  nn_trcdmp_bdy        !: =T Tracer damping
+   ! External data structure of BDY for TOP. Available elements: cn_obc, ll_trc, trcnow, dmp
+   TYPE(OBC_DATA),    PUBLIC, ALLOCATABLE, DIMENSION(:,:), TARGET ::  trcdta_bdy           !: bdy external data (local process)
+#endif
+   !
 
    !!----------------------------------------------------------------------
@@ -201,7 +217,15 @@
          &      gtrui(jpi,jpj,jptra)  , gtrvi(jpi,jpj,jptra)                          ,       &
          &      sbc_trc_b(jpi,jpj,jptra), sbc_trc(jpi,jpj,jptra)                      ,       &  
-         &      cvol(jpi,jpj,jpk)     , rdttrc(jpk)           , trai(jptra)           ,       &
+         &      cvol(jpi,jpj,jpk)     , trai(jptra)                                   ,       &
          &      ctrcnm(jptra)         , ctrcln(jptra)         , ctrcun(jptra)         ,       & 
-         &      ln_trc_ini(jptra)     , ln_trc_wri(jptra)     , qsr_mean(jpi,jpj)     ,  STAT = trc_alloc  )  
+         &      ln_trc_ini(jptra)     , ln_trc_wri(jptra)     , qsr_mean(jpi,jpj)     ,       &
+#if defined key_my_trc
+         &      ln_trc_sbc(jptra)     , ln_trc_cbc(jptra)     , ln_trc_obc(jptra)     ,       &
+#endif
+#if defined key_bdy
+         &      cn_trc_dflt(nb_bdy)   , cn_trc(nb_bdy)        , nn_trcdmp_bdy(nb_bdy) ,       &
+         &      trcdta_bdy(jptra,nb_bdy)                                              ,       &
+#endif
+         &      STAT = trc_alloc  )
 
       IF( trc_alloc /= 0 )   CALL ctl_warn('trc_alloc: failed to allocate arrays')
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/trcbc.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/trcbc.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/trcbc.F90	(revision 6140)
@@ -1,13 +1,15 @@
 MODULE trcbc
    !!======================================================================
-   !!                     ***  MODULE  trcdta  ***
+   !!                     ***  MODULE  trcbc  ***
    !! TOP :  module for passive tracer boundary conditions
    !!=====================================================================
-   !!----------------------------------------------------------------------
-#if  defined key_top 
+   !! History :  3.5 !  2014-04  (M. Vichi, T. Lovato)  Original
+   !!            3.6 !  2015-03  (T . Lovato) Revision and BDY support
+   !!----------------------------------------------------------------------
+#if defined key_top
    !!----------------------------------------------------------------------
    !!   'key_top'                                                TOP model 
    !!----------------------------------------------------------------------
-   !!   trc_dta    : read and time interpolated passive tracer data
+   !!   trc_bc       : read and time interpolated tracer Boundary Conditions
    !!----------------------------------------------------------------------
    USE par_trc       !  passive tracers parameters
@@ -17,4 +19,7 @@
    USE lib_mpp       !  MPP library
    USE fldread       !  read input fields
+#if defined key_bdy
+   USE bdy_oce, only: nb_bdy , idx_bdy, ln_coords_file, rn_time_dmp, rn_time_dmp_out
+#endif
 
    IMPLICIT NONE
@@ -24,30 +29,26 @@
    PUBLIC   trc_bc_read    ! called in trcstp.F90 or within
 
-   INTEGER  , SAVE, PUBLIC                             :: nb_trcobc   ! number of tracers with open BC
-   INTEGER  , SAVE, PUBLIC                             :: nb_trcsbc   ! number of tracers with surface BC
-   INTEGER  , SAVE, PUBLIC                             :: nb_trccbc   ! number of tracers with coastal BC
+   INTEGER  , SAVE, PUBLIC                             :: nb_trcobc    ! number of tracers with open BC
+   INTEGER  , SAVE, PUBLIC                             :: nb_trcsbc    ! number of tracers with surface BC
+   INTEGER  , SAVE, PUBLIC                             :: nb_trccbc    ! number of tracers with coastal BC
    INTEGER  , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: n_trc_indobc ! index of tracer with OBC data
    INTEGER  , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: n_trc_indsbc ! index of tracer with SBC data
    INTEGER  , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: n_trc_indcbc ! index of tracer with CBC data
-   INTEGER  , SAVE, PUBLIC                             :: ntra_obc     ! MAX( 1, nb_trcxxx ) to avoid compilation error with bounds checking
-   INTEGER  , SAVE, PUBLIC                             :: ntra_sbc     ! MAX( 1, nb_trcxxx ) to avoid compilation error with bounds checking
-   INTEGER  , SAVE, PUBLIC                             :: ntra_cbc     ! MAX( 1, nb_trcxxx ) to avoid compilation error with bounds checking
-   REAL(wp) , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: rf_trofac   ! multiplicative factor for OBCtracer values
-   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: sf_trcobc   ! structure of data input OBC (file informations, fields read)
-   REAL(wp) , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: rf_trsfac   ! multiplicative factor for SBC tracer values
-   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: sf_trcsbc   ! structure of data input SBC (file informations, fields read)
-   REAL(wp) , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: rf_trcfac   ! multiplicative factor for CBC tracer values
-   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: sf_trccbc   ! structure of data input CBC (file informations, fields read)
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
+   REAL(wp) , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: rf_trsfac    ! multiplicative factor for SBC tracer values
+   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: sf_trcsbc    ! structure of data input SBC (file informations, fields read)
+   REAL(wp) , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: rf_trcfac    ! multiplicative factor for CBC tracer values
+   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: sf_trccbc    ! structure of data input CBC (file informations, fields read)
+   REAL(wp) , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: rf_trofac    ! multiplicative factor for OBCtracer values
+   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:), TARGET  :: sf_trcobc    ! structure of data input OBC (file informations, fields read)
+   TYPE(MAP_POINTER), ALLOCATABLE, DIMENSION(:) :: nbmap_ptr   ! array of pointers to nbmap
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.6 , NEMO Consortium (2015)
+   !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 CONTAINS
 
-   SUBROUTINE trc_bc_init(ntrc)
+   SUBROUTINE trc_bc_init( ntrc )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE trc_bc_init  ***
@@ -60,10 +61,12 @@
       !
       INTEGER,INTENT(IN) :: ntrc                           ! number of tracers
-      INTEGER            :: jl, jn                         ! dummy loop indices
+      INTEGER            :: jl, jn , ib, ibd, ii, ij, ik   ! dummy loop indices
       INTEGER            :: ierr0, ierr1, ierr2, ierr3     ! temporary integers
-      INTEGER            ::  ios                           ! Local integer output status for namelist read
+      INTEGER            :: ios                            ! Local integer output status for namelist read
+      INTEGER            :: nblen, igrd                    ! support arrays for BDY
       CHARACTER(len=100) :: clndta, clntrc
       !
-      CHARACTER(len=100) :: cn_dir
+      CHARACTER(len=100) :: cn_dir_sbc, cn_dir_cbc, cn_dir_obc
+
       TYPE(FLD_N), ALLOCATABLE, DIMENSION(:) :: slf_i  ! local array of namelist informations on the fields to read
       TYPE(FLD_N), DIMENSION(jpmaxtrc) :: sn_trcobc    ! open
@@ -74,8 +77,16 @@
       REAL(wp)   , DIMENSION(jpmaxtrc) :: rn_trcfac    ! multiplicative factor for tracer values
       !!
-      NAMELIST/namtrc_bc/ cn_dir, sn_trcobc, rn_trofac, sn_trcsbc, rn_trsfac, sn_trccbc, rn_trcfac 
+      NAMELIST/namtrc_bc/ cn_dir_sbc, cn_dir_cbc, cn_dir_obc, sn_trcobc, rn_trofac, sn_trcsbc, rn_trsfac, sn_trccbc, rn_trcfac
+#if defined key_bdy
+      NAMELIST/namtrc_bdy/ cn_trc_dflt, cn_trc, nn_trcdmp_bdy
+#endif
       !!----------------------------------------------------------------------
       IF( nn_timing == 1 )  CALL timing_start('trc_bc_init')
       !
+      IF( lwp ) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) 'trc_bc_init : Tracers Boundary Conditions (BC)'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
       !  Initialisation and local array allocation
       ierr0 = 0  ;  ierr1 = 0  ;  ierr2 = 0  ;  ierr3 = 0  
@@ -107,31 +118,5 @@
       n_trc_indcbc(:) = 0
       !
-      DO jn = 1, ntrc
-         IF( ln_trc_obc(jn) ) THEN
-             nb_trcobc       = nb_trcobc + 1 
-             n_trc_indobc(jn) = nb_trcobc 
-         ENDIF
-         IF( ln_trc_sbc(jn) ) THEN
-             nb_trcsbc       = nb_trcsbc + 1
-             n_trc_indsbc(jn) = nb_trcsbc
-         ENDIF
-         IF( ln_trc_cbc(jn) ) THEN
-             nb_trccbc       = nb_trccbc + 1
-             n_trc_indcbc(jn) = nb_trccbc
-         ENDIF
-      ENDDO
-      ntra_obc = MAX( 1, nb_trcobc )   ! To avoid compilation error with bounds checking
-      IF( lwp ) WRITE(numout,*) ' '
-      IF( lwp ) WRITE(numout,*) ' Number of passive tracers to be initialized with open boundary data :', nb_trcobc
-      IF( lwp ) WRITE(numout,*) ' '
-      ntra_sbc = MAX( 1, nb_trcsbc )   ! To avoid compilation error with bounds checking
-      IF( lwp ) WRITE(numout,*) ' '
-      IF( lwp ) WRITE(numout,*) ' Number of passive tracers to be initialized with surface boundary data :', nb_trcsbc
-      IF( lwp ) WRITE(numout,*) ' '
-      ntra_cbc = MAX( 1, nb_trccbc )   ! To avoid compilation error with bounds checking
-      IF( lwp ) WRITE(numout,*) ' '
-      IF( lwp ) WRITE(numout,*) ' Number of passive tracers to be initialized with coastal boundary data :', nb_trccbc
-      IF( lwp ) WRITE(numout,*) ' '
-
+      ! Read Boundary Conditions Namelists
       REWIND( numnat_ref )              ! Namelist namtrc_bc in reference namelist : Passive tracer data structure
       READ  ( numnat_ref, namtrc_bc, IOSTAT = ios, ERR = 901)
@@ -143,54 +128,149 @@
       IF(lwm) WRITE ( numont, namtrc_bc )
 
-      ! print some information for each 
+#if defined key_bdy
+      REWIND( numnat_ref )              ! Namelist namtrc_bc in reference namelist : Passive tracer data structure
+      READ  ( numnat_ref, namtrc_bdy, IOSTAT = ios, ERR = 903)
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_bdy in reference namelist', lwp )
+
+      REWIND( numnat_cfg )              ! Namelist namtrc_bc in configuration namelist : Passive tracer data structure
+      READ  ( numnat_cfg, namtrc_bdy, IOSTAT = ios, ERR = 904 )
+904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_bdy in configuration namelist', lwp )
+      IF(lwm) WRITE ( numont, namtrc_bdy )
+      ! setup up preliminary informations for BDY structure
+      DO jn = 1, ntrc
+         DO ib = 1, nb_bdy
+            ! Set type of obc in BDY data structure (around here we may plug user override of obc type from nml)
+            IF ( ln_trc_obc(jn) ) THEN
+               trcdta_bdy(jn,ib)%cn_obc = TRIM( cn_trc(ib) )
+            ELSE
+               trcdta_bdy(jn,ib)%cn_obc = TRIM( cn_trc_dflt(ib) )
+            ENDIF
+            ! set damping use in BDY data structure
+            trcdta_bdy(jn,ib)%dmp = .false.
+            IF(nn_trcdmp_bdy(ib) .EQ. 1 .AND. ln_trc_obc(jn) ) trcdta_bdy(jn,ib)%dmp = .true.
+            IF(nn_trcdmp_bdy(ib) .EQ. 2 ) trcdta_bdy(jn,ib)%dmp = .true.
+            IF(trcdta_bdy(jn,ib)%cn_obc == 'frs' .AND. nn_trcdmp_bdy(ib) .NE. 0 )  &
+                & CALL ctl_stop( 'Use FRS OR relaxation' )
+            IF (nn_trcdmp_bdy(ib) .LT. 0 .OR. nn_trcdmp_bdy(ib) .GT. 2)            &
+                & CALL ctl_stop( 'Not a valid option for nn_trcdmp_bdy. Allowed: 0,1,2.' )
+         ENDDO
+      ENDDO
+
+#else
+      ! Force all tracers OBC to false if bdy not used
+      ln_trc_obc = .false.
+#endif
+      ! compose BC data indexes
+      DO jn = 1, ntrc
+         IF( ln_trc_obc(jn) ) THEN
+             nb_trcobc       = nb_trcobc + 1  ; n_trc_indobc(jn) = nb_trcobc
+         ENDIF
+         IF( ln_trc_sbc(jn) ) THEN
+             nb_trcsbc       = nb_trcsbc + 1  ; n_trc_indsbc(jn) = nb_trcsbc
+         ENDIF
+         IF( ln_trc_cbc(jn) ) THEN
+             nb_trccbc       = nb_trccbc + 1  ; n_trc_indcbc(jn) = nb_trccbc
+         ENDIF
+      ENDDO
+
+      ! Print summmary of Boundary Conditions
       IF( lwp ) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,'(a,i3)') '   Total tracers to be initialized with SURFACE BCs data:', nb_trcsbc
+         IF ( nb_trcsbc > 0 ) THEN
+            WRITE(numout,*) '   #trc        NAME        Boundary     Mult.Fact. '
+            DO jn = 1, ntrc
+               IF ( ln_trc_sbc(jn) ) WRITE(numout,9001) jn, TRIM( sn_trcsbc(jn)%clvar ), 'SBC', rn_trsfac(jn)
+            ENDDO
+         ENDIF
+         WRITE(numout,'(2a)') '   SURFACE BC data repository : ', TRIM(cn_dir_sbc)
+
+         WRITE(numout,*) ' '
+         WRITE(numout,'(a,i3)') '   Total tracers to be initialized with COASTAL BCs data:', nb_trccbc
+         IF ( nb_trccbc > 0 ) THEN
+            WRITE(numout,*) '   #trc        NAME        Boundary     Mult.Fact. '
+            DO jn = 1, ntrc
+               IF ( ln_trc_cbc(jn) ) WRITE(numout, 9001) jn, TRIM( sn_trccbc(jn)%clvar ), 'CBC', rn_trcfac(jn)
+            ENDDO
+         ENDIF
+         WRITE(numout,'(2a)') '   COASTAL BC data repository : ', TRIM(cn_dir_cbc)
+
+         WRITE(numout,*) ' '
+         WRITE(numout,'(a,i3)') '   Total tracers to be initialized with OPEN BCs data:', nb_trcobc
+#if defined key_bdy
+         IF ( nb_trcobc > 0 ) THEN
+            WRITE(numout,*) '   #trc        NAME        Boundary     Mult.Fact.   OBC Settings'
+            DO jn = 1, ntrc
+               IF ( ln_trc_obc(jn) )  WRITE(numout, 9001) jn, TRIM( sn_trcobc(jn)%clvar ), 'OBC', rn_trofac(jn), (trcdta_bdy(jn,ib)%cn_obc,ib=1,nb_bdy)
+               IF ( .NOT. ln_trc_obc(jn) )  WRITE(numout, 9002) jn, 'Set data to IC and use default condition', (trcdta_bdy(jn,ib)%cn_obc,ib=1,nb_bdy)
+            ENDDO
+            WRITE(numout,*) ' '
+            DO ib = 1, nb_bdy
+                IF (nn_trcdmp_bdy(ib) .EQ. 0) WRITE(numout,9003) '   Boundary ',ib,' -> NO damping of tracers'
+                IF (nn_trcdmp_bdy(ib) .EQ. 1) WRITE(numout,9003) '   Boundary ',ib,' -> damping ONLY for tracers with external data provided'
+                IF (nn_trcdmp_bdy(ib) .EQ. 2) WRITE(numout,9003) '   Boundary ',ib,' -> damping of ALL tracers'
+                IF (nn_trcdmp_bdy(ib) .GT. 0) THEN
+                   WRITE(numout,9003) '     USE damping parameters from nambdy for boundary ', ib,' : '
+                   WRITE(numout,'(a,f10.2,a)') '     - Inflow damping time scale  : ',rn_time_dmp(ib),' days'
+                   WRITE(numout,'(a,f10.2,a)') '     - Outflow damping time scale : ',rn_time_dmp_out(ib),' days'
+                ENDIF
+            ENDDO
+         ENDIF
+#endif
+         WRITE(numout,'(2a)') '   OPEN BC data repository : ', TRIM(cn_dir_obc)
+      ENDIF
+9001  FORMAT(2x,i5, 3x, a15, 3x, a5, 6x, e11.3, 4x, 10a13)
+9002  FORMAT(2x,i5, 3x, a41, 3x, 10a13)
+9003  FORMAT(a, i5, a)
+
+      !
+#if defined key_bdy
+      ! OPEN Lateral boundary conditions
+      IF( nb_trcobc > 0 ) THEN 
+         ALLOCATE ( sf_trcobc(nb_trcobc), rf_trofac(nb_trcobc), nbmap_ptr(nb_trcobc), STAT=ierr1 )
+         IF( ierr1 > 0 ) THEN
+            CALL ctl_stop( 'trc_bc_init: unable to allocate sf_trcobc structure' )   ;   RETURN
+         ENDIF
+
+         igrd = 1                       ! Everything is at T-points here
+
          DO jn = 1, ntrc
-            IF( ln_trc_obc(jn) )  THEN    
-               clndta = TRIM( sn_trcobc(jn)%clvar ) 
-               IF(lwp) WRITE(numout,*) 'Preparing to read OBC data file for passive tracer number :', jn, ' name : ', clndta, & 
-               &               ' multiplicative factor : ', rn_trofac(jn)
-            ENDIF
-            IF( ln_trc_sbc(jn) )  THEN    
-               clndta = TRIM( sn_trcsbc(jn)%clvar ) 
-               IF(lwp) WRITE(numout,*) 'Preparing to read SBC data file for passive tracer number :', jn, ' name : ', clndta, & 
-               &               ' multiplicative factor : ', rn_trsfac(jn)
-            ENDIF
-            IF( ln_trc_cbc(jn) )  THEN    
-               clndta = TRIM( sn_trccbc(jn)%clvar ) 
-               IF(lwp) WRITE(numout,*) 'Preparing to read CBC data file for passive tracer number :', jn, ' name : ', clndta, & 
-               &               ' multiplicative factor : ', rn_trcfac(jn)
-            ENDIF
-         END DO
-      ENDIF
-      !
-      ! The following code is written this way to reduce memory usage and repeated for each boundary data
-      ! MAV: note that this is just a placeholder and the dimensions must be changed according to 
-      !      what will be done with BDY. A new structure will probably need to be included
-      !
-      ! OPEN Lateral boundary conditions
-      IF( nb_trcobc > 0 ) THEN       !  allocate only if the number of tracer to initialise is greater than zero
-         ALLOCATE( sf_trcobc(nb_trcobc), rf_trofac(nb_trcobc), STAT=ierr1 )
-         IF( ierr1 > 0 ) THEN
-            CALL ctl_stop( 'trc_bc_init: unable to allocate  sf_trcobc structure' )   ;   RETURN
-         ENDIF
-         !
-         DO jn = 1, ntrc
-            IF( ln_trc_obc(jn) ) THEN      ! update passive tracers arrays with input data read from file
-               jl = n_trc_indobc(jn)
-               slf_i(jl)    = sn_trcobc(jn)
-               rf_trofac(jl) = rn_trofac(jn)
-                                            ALLOCATE( sf_trcobc(jl)%fnow(jpi,jpj,jpk)   , STAT=ierr2 )
-               IF( sn_trcobc(jn)%ln_tint )  ALLOCATE( sf_trcobc(jl)%fdta(jpi,jpj,jpk,2) , STAT=ierr3 )
-               IF( ierr2 + ierr3 > 0 ) THEN
-                 CALL ctl_stop( 'trc_bc_init : unable to allocate passive tracer OBC data arrays' )   ;   RETURN
+            DO ib = 1, nb_bdy
+
+               nblen = idx_bdy(ib)%nblen(igrd)
+
+               IF ( ln_trc_obc(jn) ) THEN
+               ! Initialise from external data
+                  jl = n_trc_indobc(jn)
+                  slf_i(jl)    = sn_trcobc(jn)
+                  rf_trofac(jl) = rn_trofac(jn)
+                                               ALLOCATE( sf_trcobc(jl)%fnow(nblen,1,jpk)   , STAT=ierr2 )
+                  IF( sn_trcobc(jn)%ln_tint )  ALLOCATE( sf_trcobc(jl)%fdta(nblen,1,jpk,2) , STAT=ierr3 )
+                  IF( ierr2 + ierr3 > 0 ) THEN
+                    CALL ctl_stop( 'trc_bc_init : unable to allocate passive tracer OBC data arrays' )   ;   RETURN
+                  ENDIF
+                  trcdta_bdy(jn,ib)%trc => sf_trcobc(jl)%fnow(:,1,:)
+                  trcdta_bdy(jn,ib)%rn_fac = rf_trofac(jl)
+                  ! create OBC mapping array
+                  nbmap_ptr(jl)%ptr => idx_bdy(ib)%nbmap(:,igrd)
+                  nbmap_ptr(jl)%ll_unstruc = ln_coords_file(igrd)
+               ELSE
+               ! Initialise obc arrays from initial conditions
+                  ALLOCATE ( trcdta_bdy(jn,ib)%trc(nblen,jpk) )
+                  DO ibd = 1, nblen
+                     DO ik = 1, jpkm1
+                        ii = idx_bdy(ib)%nbi(ibd,igrd)
+                        ij = idx_bdy(ib)%nbj(ibd,igrd)
+                        trcdta_bdy(jn,ib)%trc(ibd,ik) = trn(ii,ij,ik,jn) * tmask(ii,ij,ik)
+                     END DO
+                  END DO
+                  trcdta_bdy(jn,ib)%rn_fac = 1._wp
                ENDIF
-            ENDIF
-            !   
+            ENDDO
          ENDDO
-         !                         ! fill sf_trcdta with slf_i and control print
-         CALL fld_fill( sf_trcobc, slf_i, cn_dir, 'trc_bc_init', 'Passive tracer OBC data', 'namtrc_bc' )
-         !
-      ENDIF
-      !
+
+         CALL fld_fill( sf_trcobc, slf_i, cn_dir_obc, 'trc_bc_init', 'Passive tracer OBC data', 'namtrc_bc' )
+      ENDIF
+#endif
       ! SURFACE Boundary conditions
       IF( nb_trcsbc > 0 ) THEN       !  allocate only if the number of tracer to initialise is greater than zero
@@ -214,5 +294,5 @@
          ENDDO
          !                         ! fill sf_trcsbc with slf_i and control print
-         CALL fld_fill( sf_trcsbc, slf_i, cn_dir, 'trc_bc_init', 'Passive tracer SBC data', 'namtrc_bc' )
+         CALL fld_fill( sf_trcsbc, slf_i, cn_dir_sbc, 'trc_bc_init', 'Passive tracer SBC data', 'namtrc_bc' )
          !
       ENDIF
@@ -239,15 +319,15 @@
          ENDDO
          !                         ! fill sf_trccbc with slf_i and control print
-         CALL fld_fill( sf_trccbc, slf_i, cn_dir, 'trc_bc_init', 'Passive tracer CBC data', 'namtrc_bc' )
+         CALL fld_fill( sf_trccbc, slf_i, cn_dir_cbc, 'trc_bc_init', 'Passive tracer CBC data', 'namtrc_bc' )
          !
       ENDIF
- 
+      !
       DEALLOCATE( slf_i )          ! deallocate local field structure
       IF( nn_timing == 1 )  CALL timing_stop('trc_bc_init')
-
+      !
    END SUBROUTINE trc_bc_init
 
 
-   SUBROUTINE trc_bc_read(kt)
+   SUBROUTINE trc_bc_read(kt, jit)
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE trc_bc_init  ***
@@ -258,44 +338,66 @@
       !!              
       !!----------------------------------------------------------------------
-   
-      ! NEMO
       USE fldread
       
       !! * Arguments
       INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-
+      INTEGER, INTENT( in ), OPTIONAL ::   jit   ! subcycle time-step index (for timesplitting option)
       !!---------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('trc_bc_read')
 
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'trc_bc_read : Surface boundary conditions for passive tracers.'
-         IF(lwp) WRITE(numout,*) '~~~~~~~ '
-      ENDIF
-
-      ! OPEN boundary conditions: DOES NOT WORK. Waiting for stable BDY
-      IF( nb_trcobc > 0 ) THEN
-        if (lwp) write(numout,'(a,i5,a,i5)') '   reading OBC data for ', nb_trcobc ,' variables at step ', kt
-        CALL fld_read(kt,1,sf_trcobc)
-        ! vertical interpolation on s-grid and partial step to be added
-      ENDIF
-
-      ! SURFACE boundary conditions       
-      IF( nb_trcsbc > 0 ) THEN
-        if (lwp) write(numout,'(a,i5,a,i5)') '   reading SBC data for ', nb_trcsbc ,' variables at step ', kt
-        CALL fld_read(kt,1,sf_trcsbc)
-      ENDIF
-
-      ! COASTAL boundary conditions       
-      IF( nb_trccbc > 0 ) THEN
-        if (lwp) write(numout,'(a,i5,a,i5)') '   reading CBC data for ', nb_trccbc ,' variables at step ', kt
-        CALL fld_read(kt,1,sf_trccbc)
-      ENDIF   
+      IF( kt == nit000 .AND. lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trc_bc_read : Surface boundary conditions for passive tracers.'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+
+      IF ( PRESENT(jit) ) THEN 
+
+         ! OPEN boundary conditions (use time_offset=+1 as they are applied at the end of the step)
+         IF( nb_trcobc > 0 ) THEN
+           if (lwp) write(numout,'(a,i5,a,i10)') '   reading OBC data for ', nb_trcobc ,' variable(s) at step ', kt
+           CALL fld_read(kt=kt, kn_fsbc=1, sd=sf_trcobc, map=nbmap_ptr, kit=jit, kt_offset=+1)
+         ENDIF
+
+         ! SURFACE boundary conditions
+         IF( nb_trcsbc > 0 ) THEN
+           if (lwp) write(numout,'(a,i5,a,i10)') '   reading SBC data for ', nb_trcsbc ,' variable(s) at step ', kt
+           CALL fld_read(kt=kt, kn_fsbc=1, sd=sf_trcsbc, kit=jit)
+         ENDIF
+
+         ! COASTAL boundary conditions
+         IF( nb_trccbc > 0 ) THEN
+           if (lwp) write(numout,'(a,i5,a,i10)') '   reading CBC data for ', nb_trccbc ,' variable(s) at step ', kt
+           CALL fld_read(kt=kt, kn_fsbc=1, sd=sf_trccbc, kit=jit)
+         ENDIF
+
+      ELSE
+
+         ! OPEN boundary conditions (use time_offset=+1 as they are applied at the end of the step)
+         IF( nb_trcobc > 0 ) THEN
+           if (lwp) write(numout,'(a,i5,a,i10)') '   reading OBC data for ', nb_trcobc ,' variable(s) at step ', kt
+           CALL fld_read(kt=kt, kn_fsbc=1, sd=sf_trcobc, map=nbmap_ptr, kt_offset=+1)
+         ENDIF
+
+         ! SURFACE boundary conditions
+         IF( nb_trcsbc > 0 ) THEN
+           if (lwp) write(numout,'(a,i5,a,i10)') '   reading SBC data for ', nb_trcsbc ,' variable(s) at step ', kt
+           CALL fld_read(kt=kt, kn_fsbc=1, sd=sf_trcsbc)
+         ENDIF
+
+         ! COASTAL boundary conditions
+         IF( nb_trccbc > 0 ) THEN
+           if (lwp) write(numout,'(a,i5,a,i10)') '   reading CBC data for ', nb_trccbc ,' variable(s) at step ', kt
+           CALL fld_read(kt=kt, kn_fsbc=1, sd=sf_trccbc)
+         ENDIF
+
+      ENDIF
+
       !
       IF( nn_timing == 1 )  CALL timing_stop('trc_bc_read')
-      !       
-
+      !
    END SUBROUTINE trc_bc_read
+
 #else
    !!----------------------------------------------------------------------
@@ -303,4 +405,10 @@
    !!----------------------------------------------------------------------
 CONTAINS
+
+   SUBROUTINE trc_bc_init( ntrc )        ! Empty routine
+      INTEGER,INTENT(IN) :: ntrc                           ! number of tracers
+      WRITE(*,*) 'trc_bc_init: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_bc_init
+
    SUBROUTINE trc_bc_read( kt )        ! Empty routine
       WRITE(*,*) 'trc_bc_read: You should not have seen this print! error?', kt
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/trcbdy.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/trcbdy.F90	(revision 6140)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/trcbdy.F90	(revision 6140)
@@ -0,0 +1,293 @@
+MODULE trcbdy
+   !!======================================================================
+   !!                       ***  MODULE  bdytrc  ***
+   !! Ocean tracers:   Apply boundary conditions for tracers in TOP component
+   !!======================================================================
+   !! History :  1.0  !  2005-01  (J. Chanut, A. Sellar)  Original code
+   !!            3.0  !  2008-04  (NEMO team)  add in the reference version
+   !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
+   !!            3.5  !  2012     (S. Mocavero, I. Epicoco) Optimization of BDY communications
+   !!            3.6  !  2015     (T. Lovato) Adapt BDY for tracers in TOP component
+   !!----------------------------------------------------------------------
+#if defined key_bdy && key_top
+   !!----------------------------------------------------------------------
+   !!   'key_bdy'                     Unstructured Open Boundary Conditions
+   !!----------------------------------------------------------------------
+   !!   trc_bdy            : Apply open boundary conditions to T and S
+   !!   trc_bdy_frs        : Apply Flow Relaxation Scheme
+   !!----------------------------------------------------------------------
+   USE timing                       ! Timing
+   USE oce_trc                      ! ocean dynamics and tracers variables
+   USE par_trc
+   USE trc                          ! ocean space and time domain variables 
+   USE bdylib                       ! for orlanski library routines
+   USE lbclnk                       ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager               ! I/O manager
+   USE bdy_oce, only: idx_bdy, OBC_INDEX, BDYTMASK, lk_bdy       ! ocean open boundary conditions
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_bdy      ! routine called in trcnxt.F90 
+   PUBLIC trc_bdy_dmp  ! routine called in trcstp.F90 
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.6 , NEMO Consortium (2015)
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trc_bdy( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  SUBROUTINE trc_bdy  ***
+      !!
+      !! ** Purpose : - Apply open boundary conditions for tracers in TOP component
+      !!                and scale the tracer data
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) :: kt     ! Main time step counter
+      !!
+      INTEGER               :: ib_bdy, jn ! Loop indeces
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('trc_bdy')
+      !
+      DO jn = 1, jptra
+         DO ib_bdy=1, nb_bdy
+
+            SELECT CASE( trcdta_bdy(jn,ib_bdy)%cn_obc )
+            CASE('none')
+               CYCLE
+            CASE('frs')
+               CALL bdy_trc_frs( jn, idx_bdy(ib_bdy), trcdta_bdy(jn,ib_bdy), kt )
+            CASE('specified')
+               CALL bdy_trc_spe( jn, idx_bdy(ib_bdy), trcdta_bdy(jn,ib_bdy), kt )
+            CASE('neumann')
+               CALL bdy_trc_nmn( jn, idx_bdy(ib_bdy), trcdta_bdy(jn,ib_bdy), kt )
+            CASE('orlanski')
+               CALL bdy_trc_orlanski( jn, idx_bdy(ib_bdy), trcdta_bdy(jn,ib_bdy), ll_npo=.false. )
+            CASE('orlanski_npo')
+               CALL bdy_trc_orlanski( jn, idx_bdy(ib_bdy), trcdta_bdy(jn,ib_bdy), ll_npo=.true. )
+            CASE DEFAULT
+               CALL ctl_stop( 'trc_bdy : unrecognised option for open boundaries for passive tracers' )
+            END SELECT
+
+            ! Boundary points should be updated
+            CALL lbc_bdy_lnk( tra(:,:,:,jn), 'T', 1., ib_bdy )
+
+         ENDDO
+      ENDDO
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('trc_bdy')
+
+   END SUBROUTINE trc_bdy
+
+   SUBROUTINE bdy_trc_frs( jn, idx, dta, kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_trc_frs  ***
+      !!                    
+      !! ** Purpose : Apply the Flow Relaxation Scheme for tracers at open boundaries.
+      !! 
+      !! Reference : Engedahl H., 1995, Tellus, 365-382.
+      !!----------------------------------------------------------------------
+      INTEGER,         INTENT(in) ::   kt
+      INTEGER,         INTENT(in) ::   jn   ! Tracer index
+      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
+      !! 
+      REAL(wp) ::   zwgt           ! boundary weight
+      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
+      INTEGER  ::   ii, ij         ! 2D addresses
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('bdy_trc_frs')
+      ! 
+      igrd = 1                       ! Everything is at T-points here
+      DO ib = 1, idx%nblen(igrd)
+         DO ik = 1, jpkm1
+            ii = idx%nbi(ib,igrd)
+            ij = idx%nbj(ib,igrd)
+            zwgt = idx%nbw(ib,igrd)
+            tra(ii,ij,ik,jn) = ( tra(ii,ij,ik,jn) + zwgt * ( ( dta%trc(ib,ik) * dta%rn_fac)  & 
+                        &  - tra(ii,ij,ik,jn) ) ) * tmask(ii,ij,ik)
+         END DO
+      END DO 
+      !
+      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_trc_frs')
+      !
+   END SUBROUTINE bdy_trc_frs
+  
+   SUBROUTINE bdy_trc_spe( jn, idx, dta, kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_trc_frs  ***
+      !!                    
+      !! ** Purpose : Apply a specified value for tracers at open boundaries.
+      !! 
+      !!----------------------------------------------------------------------
+      INTEGER,         INTENT(in) ::   kt
+      INTEGER,         INTENT(in) ::   jn   ! Tracer index
+      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
+      !! 
+      REAL(wp) ::   zwgt           ! boundary weight
+      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
+      INTEGER  ::   ii, ij         ! 2D addresses
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('bdy_trc_spe')
+      !
+      igrd = 1                       ! Everything is at T-points here
+      DO ib = 1, idx%nblenrim(igrd)
+         ii = idx%nbi(ib,igrd)
+         ij = idx%nbj(ib,igrd)
+         DO ik = 1, jpkm1
+            tra(ii,ij,ik,jn) = dta%trc(ib,ik) * dta%rn_fac * tmask(ii,ij,ik)
+         END DO
+      END DO
+      !
+      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_trc_spe')
+      !
+   END SUBROUTINE bdy_trc_spe
+
+   SUBROUTINE bdy_trc_nmn( jn, idx, dta, kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_trc_nmn  ***
+      !!                    
+      !! ** Purpose : Duplicate the value for tracers at open boundaries.
+      !! 
+      !!----------------------------------------------------------------------
+      INTEGER,         INTENT(in) ::   kt
+      INTEGER,         INTENT(in) ::   jn   ! Tracer index
+      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
+      !! 
+      REAL(wp) ::   zwgt           ! boundary weight
+      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
+      INTEGER  ::   ii, ij, zcoef, zcoef1, zcoef2, ip, jp   ! 2D addresses
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('bdy_trc_nmn')
+      !
+      igrd = 1                       ! Everything is at T-points here
+      DO ib = 1, idx%nblenrim(igrd)
+         ii = idx%nbi(ib,igrd)
+         ij = idx%nbj(ib,igrd)
+         DO ik = 1, jpkm1
+            ! search the sense of the gradient
+            zcoef1 = bdytmask(ii-1,ij  ) +  bdytmask(ii+1,ij  )
+            zcoef2 = bdytmask(ii  ,ij-1) +  bdytmask(ii  ,ij+1)
+            IF ( zcoef1+zcoef2 == 0) THEN
+               ! corner
+               zcoef = tmask(ii-1,ij,ik) + tmask(ii+1,ij,ik) +  tmask(ii,ij-1,ik) +  tmask(ii,ij+1,ik)
+               tra(ii,ij,ik,jn) = tra(ii-1,ij  ,ik,jn) * tmask(ii-1,ij  ,ik) + &
+                 &                tra(ii+1,ij  ,ik,jn) * tmask(ii+1,ij  ,ik) + &
+                 &                tra(ii  ,ij-1,ik,jn) * tmask(ii  ,ij-1,ik) + &
+                 &                tra(ii  ,ij+1,ik,jn) * tmask(ii  ,ij+1,ik)
+               tra(ii,ij,ik,jn) = ( tra(ii,ij,ik,jn) / MAX( 1, zcoef) ) * tmask(ii,ij,ik)
+            ELSE
+               ip = bdytmask(ii+1,ij  ) - bdytmask(ii-1,ij  )
+               jp = bdytmask(ii  ,ij+1) - bdytmask(ii  ,ij-1)
+               tra(ii,ij,ik,jn) = tra(ii+ip,ij+jp,ik,jn) * tmask(ii+ip,ij+jp,ik)
+            ENDIF
+         END DO
+      END DO
+      !
+      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_trc_nmn')
+      !
+   END SUBROUTINE bdy_trc_nmn
+ 
+
+   SUBROUTINE bdy_trc_orlanski( jn, idx, dta, ll_npo )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_trc_orlanski  ***
+      !!             
+      !!              - Apply Orlanski radiation to tracers of TOP component. 
+      !!              - Wrapper routine for bdy_orlanski_3d
+      !! 
+      !!
+      !! References:  Marchesiello, McWilliams and Shchepetkin, Ocean Modelling vol. 3 (2001)    
+      !!----------------------------------------------------------------------
+      INTEGER,                      INTENT(in) ::   jn      ! Tracer index
+      TYPE(OBC_INDEX),              INTENT(in) ::   idx     ! OBC indices
+      TYPE(OBC_DATA),               INTENT(in) ::   dta     ! OBC external data
+      LOGICAL,                      INTENT(in) ::   ll_npo  ! switch for NPO version
+
+      INTEGER  ::   igrd                                    ! grid index
+      !!----------------------------------------------------------------------
+
+      IF( nn_timing == 1 ) CALL timing_start('bdy_trc_orlanski')
+      !
+      igrd = 1      ! Orlanski bc on tracers; 
+      !            
+      CALL bdy_orlanski_3d( idx, igrd, trb(:,:,:,jn), tra(:,:,:,jn), (dta%trc * dta%rn_fac), ll_npo )
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_trc_orlanski')
+      !
+
+   END SUBROUTINE bdy_trc_orlanski
+
+   SUBROUTINE trc_bdy_dmp( kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE trc_bdy_dmp  ***
+      !!                    
+      !! ** Purpose : Apply damping for tracers at open boundaries.
+      !!             It currently applies the damping to all tracers!!!
+      !! 
+      !!----------------------------------------------------------------------
+      INTEGER,         INTENT(in) ::   kt
+      !! 
+      INTEGER  ::   jn             ! Tracer index
+      REAL(wp) ::   zwgt           ! boundary weight
+      REAL(wp) ::   zta, zsa, ztime
+      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
+      INTEGER  ::   ii, ij         ! 2D addresses
+      INTEGER  ::   ib_bdy         ! Loop index
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('trc_bdy_dmp')
+      !
+      DO jn = 1, jptra
+         DO ib_bdy=1, nb_bdy
+            IF ( trcdta_bdy(jn, ib_bdy)%dmp ) THEN
+               igrd = 1                       ! Everything is at T-points here
+               DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
+                  ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                  ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                  zwgt = idx_bdy(ib_bdy)%nbd(ib,igrd)
+                  DO ik = 1, jpkm1
+                     zta = zwgt * ( trcdta_bdy(jn, ib_bdy)%trc(ib,ik) - trb(ii,ij,ik,jn) ) * tmask(ii,ij,ik)
+                     tra(ii,ij,ik,jn) = tra(ii,ij,ik,jn) + zta
+                  END DO
+               END DO
+            ENDIF
+         ENDDO
+      ENDDO
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('trc_bdy_dmp')
+      !
+   END SUBROUTINE trc_bdy_dmp
+ 
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                   NO Unstruct Open Boundary Conditions
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_bdy(kt)      ! Empty routine
+      WRITE(*,*) 'trc_bdy: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_bdy
+
+   SUBROUTINE trc_bdy_dmp(kt)      ! Empty routine
+      WRITE(*,*) 'trc_bdy_dmp: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_bdy_dmp
+
+#endif
+
+   !!======================================================================
+END MODULE trcbdy
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/trcdia.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/trcdia.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/trcdia.F90	(revision 6140)
@@ -106,5 +106,5 @@
       CHARACTER (len=20) :: cltra, cltrau
       CHARACTER (len=80) :: cltral
-      REAL(wp) :: zsto, zout, zdt
+      REAL(wp) :: zsto, zout
       INTEGER  :: iimi, iima, ijmi, ijma, ipk, it, itmod, iiter
       !!----------------------------------------------------------------------
@@ -118,5 +118,4 @@
 
       ! Define frequency of output and means
-      zdt = rdt
       IF( ln_mskland )   THEN   ;   clop = "only(x)"   ! put 1.e+20 on land (very expensive!!)
       ELSE                      ;   clop = "x"         ! no use of the mask value (require less cpu time)
@@ -126,8 +125,8 @@
       clop = "inst("//TRIM(clop)//")"
 # else
-      zsto = zdt
+      zsto = rdt
       clop = "ave("//TRIM(clop)//")"
 # endif
-      zout = nn_writetrc * zdt
+      zout = nn_writetrc * rdt
 
       ! Define indices of the horizontal output zoom and vertical limit storage
@@ -182,5 +181,5 @@
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,     &
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,         & 
-            &          iiter, zjulian, zdt, nhorit5, nit5 , domain_id=nidom, snc4chunks=snc4set)
+            &          iiter, zjulian, rdt, nhorit5, nit5 , domain_id=nidom, snc4chunks=snc4set)
 
          ! Vertical grid for tracer : gdept
@@ -250,5 +249,5 @@
       INTEGER  ::   jl
       INTEGER  ::   iimi, iima, ijmi, ijma, ipk, it, itmod, iiter
-      REAL(wp) ::   zsto, zout, zdt
+      REAL(wp) ::   zsto, zout
       !!----------------------------------------------------------------------
 
@@ -261,16 +260,15 @@
       !
       ! Define frequency of output and means
-      zdt = rdt
       IF( ln_mskland )   THEN   ;   clop = "only(x)"   ! put 1.e+20 on land (very expensive!!)
       ELSE                      ;   clop = "x"         ! no use of the mask value (require less cpu time)
       ENDIF
 #  if defined key_diainstant
-      zsto = nn_writedia * zdt
+      zsto = nn_writedia * rdt
       clop = "inst("//TRIM(clop)//")"
 #  else
-      zsto = zdt
+      zsto = rdt
       clop = "ave("//TRIM(clop)//")"
 #  endif
-      zout = nn_writedia * zdt
+      zout = nn_writedia * rdt
 
       ! Define indices of the horizontal output zoom and vertical limit storage
@@ -302,5 +300,5 @@
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,             &
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,         &
-            &          iiter, zjulian, zdt, nhoritd, nitd , domain_id=nidom, snc4chunks=snc4set )
+            &          iiter, zjulian, rdt, nhoritd, nitd , domain_id=nidom, snc4chunks=snc4set )
 
          ! Vertical grid for 2d and 3d arrays
@@ -387,5 +385,5 @@
       INTEGER  ::   ji, jj, jk, jl
       INTEGER  ::   iimi, iima, ijmi, ijma, ipk, it, itmod, iiter
-      REAL(wp) ::   zsto, zout, zdt
+      REAL(wp) ::   zsto, zout
       !!----------------------------------------------------------------------
 
@@ -398,16 +396,15 @@
 
       ! Define frequency of output and means
-      zdt = rdt
       IF( ln_mskland )   THEN   ;   clop = "only(x)"   ! put 1.e+20 on land (very expensive!!)
       ELSE                      ;   clop = "x"         ! no use of the mask value (require less cpu time)
       ENDIF
 #        if defined key_diainstant
-      zsto = nn_writebio * zdt
+      zsto = nn_writebio * rdt
       clop = "inst("//TRIM(clop)//")"
 #        else
-      zsto = zdt
+      zsto = rdt
       clop = "ave("//TRIM(clop)//")"
 #        endif
-      zout = nn_writebio * zdt
+      zout = nn_writebio * rdt
 
       ! Define indices of the horizontal output zoom and vertical limit storage
@@ -435,5 +432,5 @@
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,      &
             &    iimi, iima-iimi+1, ijmi, ijma-ijmi+1,          &
-            &    iiter, zjulian, zdt, nhoritb, nitb , domain_id=nidom, snc4chunks=snc4set )
+            &    iiter, zjulian, rdt, nhoritb, nitb , domain_id=nidom, snc4chunks=snc4set )
          ! Vertical grid for biological trends
          CALL histvert(nitb, 'deptht', 'Vertical T levels', 'm', ipk, gdept_1d, ndepitb)
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/trcdta.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/trcdta.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/trcdta.F90	(revision 6140)
@@ -9,6 +9,7 @@
    !!            3.4   !  2010-11  (C. Ethe, G. Madec)  use of fldread + dynamical allocation 
    !!            3.5   !  2013-08  (M. Vichi)  generalization for other BGC models
-   !!----------------------------------------------------------------------
-#if  defined key_top 
+   !!            3.6   !  2015-03  (T. Lovato) revision of code log info
+   !!----------------------------------------------------------------------
+#if defined key_top 
    !!----------------------------------------------------------------------
    !!   'key_top'                                                TOP model 
@@ -36,6 +37,5 @@
    TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: sf_trcdta   ! structure of input SST (file informations, fields read)
 !$AGRIF_END_DO_NOT_TREAT
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
+
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -72,4 +72,10 @@
       IF( nn_timing == 1 )  CALL timing_start('trc_dta_init')
       !
+      IF( lwp ) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) '  trc_dta_init : Tracers Initial Conditions (IC)'
+         WRITE(numout,*) '  ~~~~~~~~~~~ '
+      ENDIF
+      !
       !  Initialisation
       ierr0 = 0  ;  ierr1 = 0  ;  ierr2 = 0  ;  ierr3 = 0  
@@ -77,5 +83,5 @@
       ALLOCATE( n_trc_index(ntrc), slf_i(ntrc), STAT=ierr0 )
       IF( ierr0 > 0 ) THEN
-         CALL ctl_stop( 'trc_nam: unable to allocate n_trc_index' )   ;   RETURN
+         CALL ctl_stop( 'trc_dta_init: unable to allocate n_trc_index' )   ;   RETURN
       ENDIF
       nb_trcdta      = 0
@@ -97,9 +103,9 @@
       REWIND( numnat_ref )              ! Namelist namtrc_dta in reference namelist : Passive tracer input data
       READ  ( numnat_ref, namtrc_dta, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_dta in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_dta_init in reference namelist', lwp )
 
       REWIND( numnat_cfg )              ! Namelist namtrc_dta in configuration namelist : Passive tracer input data
       READ  ( numnat_cfg, namtrc_dta, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_dta in configuration namelist', lwp )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_dta_init in configuration namelist', lwp )
       IF(lwm) WRITE ( numont, namtrc_dta )
 
@@ -109,12 +115,14 @@
                clndta = TRIM( sn_trcdta(jn)%clvar ) 
                clntrc = TRIM( ctrcnm   (jn)       ) 
+               if (jn > jptra) clntrc='Dummy' ! By pass weird formats in ocean.output if ntrc > jptra
                zfact  = rn_trfac(jn)
                IF( clndta /=  clntrc ) THEN 
-                  CALL ctl_warn( 'trc_dta_init: passive tracer data initialisation :  ',   &
-                  &              'the variable name in the data file : '//clndta//   & 
-                  &              '  must be the same than the name of the passive tracer : '//clntrc//' ')
+                  CALL ctl_warn( 'trc_dta_init: passive tracer data initialisation    ',   &
+                  &              'Input name of data file : '//TRIM(clndta)//   &
+                  &              ' differs from that of tracer : '//TRIM(clntrc)//' ')
                ENDIF
-               WRITE(numout,*) ' read an initial file for passive tracer number :', jn, ' name : ', clndta, & 
-               &               ' multiplicative factor : ', zfact
+               WRITE(numout,*) ' '
+               WRITE(numout,'(a, i3,3a,e11.3)') ' Read IC file for tracer number :', &
+               &            jn, ', name : ', TRIM(clndta), ', Multiplicative Scaling factor : ', zfact
             ENDIF
          END DO
@@ -124,5 +132,5 @@
          ALLOCATE( sf_trcdta(nb_trcdta), rf_trfac(nb_trcdta), STAT=ierr1 )
          IF( ierr1 > 0 ) THEN
-            CALL ctl_stop( 'trc_dta_ini: unable to allocate  sf_trcdta structure' )   ;   RETURN
+            CALL ctl_stop( 'trc_dta_init: unable to allocate  sf_trcdta structure' )   ;   RETURN
          ENDIF
          !
@@ -135,5 +143,5 @@
                IF( sn_trcdta(jn)%ln_tint )  ALLOCATE( sf_trcdta(jl)%fdta(jpi,jpj,jpk,2) , STAT=ierr3 )
                IF( ierr2 + ierr3 > 0 ) THEN
-                 CALL ctl_stop( 'trc_dta : unable to allocate passive tracer data arrays' )   ;   RETURN
+                 CALL ctl_stop( 'trc_dta_init : unable to allocate passive tracer data arrays' )   ;   RETURN
                ENDIF
             ENDIF
@@ -141,5 +149,5 @@
          ENDDO
          !                         ! fill sf_trcdta with slf_i and control print
-         CALL fld_fill( sf_trcdta, slf_i, cn_dir, 'trc_dta', 'Passive tracer data', 'namtrc' )
+         CALL fld_fill( sf_trcdta, slf_i, cn_dir, 'trc_dta_init', 'Passive tracer data', 'namtrc' )
          !
       ENDIF
@@ -189,5 +197,5 @@
                   DO ji = 1, jpi
                      DO jk = 1, jpk                        ! determines the intepolated T-S profiles at each (i,j) points
-                        zl = fsdept_n(ji,jj,jk)
+                        zl = gdept_n(ji,jj,jk)
                         IF(     zl < gdept_1d(1  ) ) THEN         ! above the first level of data
                            ztp(jk) =  sf_dta(1)%fnow(ji,jj,1)
@@ -220,11 +228,6 @@
                         ik = mbkt(ji,jj) 
                         IF( ik > 1 ) THEN
-                           zl = ( gdept_1d(ik) - fsdept_n(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
+                           zl = ( gdept_1d(ik) - gdept_n(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
                            sf_dta(1)%fnow(ji,jj,ik) = (1.-zl) * sf_dta(1)%fnow(ji,jj,ik) + zl * sf_dta(1)%fnow(ji,jj,ik-1)
-                        ENDIF
-                        ik = mikt(ji,jj)
-                        IF( ik > 1 ) THEN
-                           zl = ( gdept_0(ji,jj,ik) - gdept_1d(ik) ) / ( gdept_1d(ik+1) - gdept_1d(ik) )
-                           sf_dta(1)%fnow(ji,jj,ik) = (1.-zl) * sf_dta(1)%fnow(ji,jj,ik) + zl * sf_dta(1)%fnow(ji,jj,ik+1)
                         ENDIF
                      END DO
@@ -236,16 +239,4 @@
          sf_dta(1)%fnow(:,:,:) = sf_dta(1)%fnow(:,:,:) * zrf_trfac   !  multiplicative factor
          !
-         IF( lwp .AND. kt == nit000 ) THEN
-               clndta = TRIM( sf_dta(1)%clvar ) 
-               WRITE(numout,*) ''//clndta//' data '
-               WRITE(numout,*)
-               WRITE(numout,*)'  level = 1'
-               CALL prihre( sf_dta(1)%fnow(:,:,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-               WRITE(numout,*)'  level = ', jpk/2
-               CALL prihre( sf_dta(1)%fnow(:,:,jpk/2), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-               WRITE(numout,*)'  level = ', jpkm1
-               CALL prihre( sf_dta(1)%fnow(:,:,jpkm1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
-               WRITE(numout,*)
-         ENDIF
       ENDIF
       !
@@ -253,4 +244,5 @@
       !
    END SUBROUTINE trc_dta
+   
 #else
    !!----------------------------------------------------------------------
@@ -262,4 +254,5 @@
    END SUBROUTINE trc_dta
 #endif
+
    !!======================================================================
 END MODULE trcdta
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/trcini.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 6140)
@@ -26,4 +26,5 @@
    USE sbc_oce
    USE trcice          ! tracers in sea ice
+   USE trcbc,   only : trc_bc_init ! generalized Boundary Conditions
  
    IMPLICIT NONE
@@ -32,6 +33,4 @@
    PUBLIC   trc_init   ! called by opa
 
-    !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2011)
@@ -119,7 +118,7 @@
       !                                                              ! masked grid volume
       DO jk = 1, jpk
-         cvol(:,:,jk) = e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk)
+         cvol(:,:,jk) = e1e2t(:,:) * e3t_n(:,:,jk) * tmask(:,:,jk)
       END DO
-      IF( lk_degrad ) cvol(:,:,:) = cvol(:,:,:) * facvol(:,:,:)      ! degrad option: reduction by facvol
+      IF( lk_degrad )   cvol(:,:,:) = cvol(:,:,:) * facvol(:,:,:)    ! degrad option: reduction by facvol
       !                                                              ! total volume of the ocean 
       areatot = glob_sum( cvol(:,:,:) )
@@ -208,5 +207,9 @@
       !!----------------------------------------------------------------------
       !
+      ! Initialisation of tracers Initial Conditions
       IF( ln_trcdta )      CALL trc_dta_init(jptra)
+
+      ! Initialisation of tracers Boundary Conditions
+      IF( lk_my_trc )     CALL trc_bc_init(jptra)
 
       IF( ln_rsttr ) THEN
@@ -246,5 +249,4 @@
    END SUBROUTINE trc_ini_state
 
-
    SUBROUTINE top_alloc
       !!----------------------------------------------------------------------
@@ -253,8 +255,5 @@
       !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
       !!----------------------------------------------------------------------
-      USE trcadv        , ONLY:   trc_adv_alloc          ! TOP-related alloc routines...
       USE trc           , ONLY:   trc_alloc
-      USE trcnxt        , ONLY:   trc_nxt_alloc
-      USE trczdf        , ONLY:   trc_zdf_alloc
       USE trdtrc_oce    , ONLY:   trd_trc_oce_alloc
 #if defined key_trdmxl_trc 
@@ -265,8 +264,5 @@
       !!----------------------------------------------------------------------
       !
-      ierr =        trc_adv_alloc()          ! Start of TOP-related alloc routines...
-      ierr = ierr + trc_alloc    ()
-      ierr = ierr + trc_nxt_alloc()
-      ierr = ierr + trc_zdf_alloc()
+      ierr =        trc_alloc()
       ierr = ierr + trd_trc_oce_alloc()
 #if defined key_trdmxl_trc 
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/trcnam.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 6140)
@@ -98,9 +98,9 @@
 
       
-      rdttrc(:) = rdttra(:) * FLOAT( nn_dttrc )   ! vertical profile of passive tracer time-step
+      rdttrc = rdt * FLOAT( nn_dttrc )   ! passive tracer time-step
   
       IF(lwp) THEN                   ! control print
         WRITE(numout,*) 
-        WRITE(numout,*) '    Passive Tracer  time step    rdttrc  = ', rdttrc(1)
+        WRITE(numout,*) '    Passive Tracer  time step    rdttrc  = ', rdttrc
         WRITE(numout,*) 
       ENDIF
@@ -173,5 +173,5 @@
       !!---------------------------------------------------------------------
       !
-      IF(lwp) WRITE(numout,*) 'trc_nam : read the passive tracer namelists'
+      IF(lwp) WRITE(numout,*) 'trc_nam_run : read the passive tracer namelists'
       IF(lwp) WRITE(numout,*) '~~~~~~~'
 
@@ -271,8 +271,8 @@
       TYPE(PTRACER), DIMENSION(jptra) :: sn_tracer  ! type of tracer for saving if not key_iomput
       !!
-      NAMELIST/namtrc/ sn_tracer, ln_trcdta,ln_trcdmp, ln_trcdmp_clo
+      NAMELIST/namtrc/ sn_tracer, ln_trcdta, ln_trcdmp, ln_trcdmp_clo
       !!---------------------------------------------------------------------
       IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'trc_nam : read the passive tracer namelists'
+      IF(lwp) WRITE(numout,*) 'trc_nam_trc : read the passive tracer namelists'
       IF(lwp) WRITE(numout,*) '~~~~~~~'
 
@@ -291,4 +291,9 @@
          ctrcun    (jn) = TRIM( sn_tracer(jn)%clunit  )
          ln_trc_ini(jn) =       sn_tracer(jn)%llinit
+#if defined key_my_trc
+         ln_trc_sbc(jn) =       sn_tracer(jn)%llsbc
+         ln_trc_cbc(jn) =       sn_tracer(jn)%llcbc
+         ln_trc_obc(jn) =       sn_tracer(jn)%llobc
+#endif
          ln_trc_wri(jn) =       sn_tracer(jn)%llsave
       END DO
@@ -317,8 +322,4 @@
       NAMELIST/namtrc_dia/ ln_diatrc, ln_diabio, nn_writedia, nn_writebio
       !!---------------------------------------------------------------------
-
-      IF(lwp) WRITE(numout,*) 
-      IF(lwp) WRITE(numout,*) 'trc_nam_dia : read the passive tracer diagnostics options'
-      IF(lwp) WRITE(numout,*) '~~~~~~~'
 
       IF(lwp) WRITE(numout,*)
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/trcrst.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 6140)
@@ -14,9 +14,5 @@
    !!----------------------------------------------------------------------
    !!----------------------------------------------------------------------
-   !!   trc_rst :   Restart for passive tracer
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!   'key_top'                                                TOP models
-   !!----------------------------------------------------------------------
+   !!   trc_rst        : Restart for passive tracer
    !!   trc_rst_opn    : open  restart file
    !!   trc_rst_read   : read  restart file
@@ -27,4 +23,5 @@
    USE iom
    USE daymod
+   
    IMPLICIT NONE
    PRIVATE
@@ -35,7 +32,9 @@
    PUBLIC   trc_rst_cal
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-   
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.7 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
    
@@ -131,5 +130,5 @@
       !!----------------------------------------------------------------------
       !
-      CALL iom_rstput( kt, nitrst, numrtw, 'rdttrc1', rdttrc(1) )   ! surface passive tracer time step
+      CALL iom_rstput( kt, nitrst, numrtw, 'rdttrc1', rdttrc )   ! passive tracer time step
       ! prognostic variables 
       ! -------------------- 
@@ -199,11 +198,4 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
 
-         IF ( jprstlib == jprstdimg ) THEN
-           ! eventually read netcdf file (monobloc)  for restarting on different number of processors
-           ! if {cn_trcrst_in}.nc exists, then set jlibalt to jpnf90 
-           INQUIRE( FILE = TRIM(cn_trcrst_indir)//'/'//TRIM(cn_trcrst_in)//'.nc', EXIST = llok )
-           IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
-         ENDIF
-
          IF( ln_rsttr ) THEN
             CALL iom_open( TRIM(cn_trcrst_indir)//'/'//cn_trcrst_in, numrtr, kiolib = jlibalt )
@@ -235,5 +227,5 @@
              ELSE
                ndastp = ndate0 - 1     ! ndate0 read in the namelist in dom_nam
-               adatrj = ( REAL( nittrc000-1, wp ) * rdttra(1) ) / rday
+               adatrj = ( REAL( nittrc000-1, wp ) * rdt ) / rday
                ! note this is wrong if time step has changed during run
             ENDIF
@@ -288,5 +280,5 @@
       !
       DO jk = 1, jpk
-         zvol(:,:,jk) = e1e2t(:,:) * fse3t_a(:,:,jk) * tmask(:,:,jk)
+         zvol(:,:,jk) = e1e2t(:,:) * e3t_a(:,:,jk) * tmask(:,:,jk)
       END DO
       !
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/trcstp.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 6140)
@@ -36,6 +36,4 @@
    LOGICAL  :: llnew
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -66,7 +64,7 @@
       IF( kt == nittrc000 .AND. lk_trdmxl_trc )  CALL trd_mxl_trc_init    ! trends: Mixed-layer
       !
-      IF( lk_vvl ) THEN                                                   ! update ocean volume due to ssh temporal evolution
+      IF( .NOT.ln_linssh ) THEN                                           ! update ocean volume due to ssh temporal evolution
          DO jk = 1, jpk
-            cvol(:,:,jk) = e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk)
+            cvol(:,:,jk) = e1e2t(:,:) * e3t_n(:,:,jk) * tmask(:,:,jk)
          END DO
          IF( lk_degrad )  cvol(:,:,:) = cvol(:,:,:) * facvol(:,:,:)       ! degrad option: reduction by facvol
@@ -116,4 +114,5 @@
    END SUBROUTINE trc_stp
 
+
    SUBROUTINE trc_mean_qsr( kt )
       !!----------------------------------------------------------------------
@@ -130,5 +129,6 @@
       INTEGER, INTENT(in) ::   kt
       INTEGER  :: jn
-
+      !!----------------------------------------------------------------------
+      !
       IF( kt == nittrc000 ) THEN
          IF( ln_cpl )  THEN  
@@ -165,5 +165,5 @@
           DO jn = 1, nb_rec_per_days - 1
              qsr_arr(:,:,jn) = qsr_arr(:,:,jn+1)
-          ENDDO
+          END DO
           qsr_arr (:,:,nb_rec_per_days) = qsr(:,:)
           qsr_mean(:,:                ) = SUM( qsr_arr(:,:,:), 3 ) / nb_rec_per_days
Index: /trunk/NEMOGCM/NEMO/TOP_SRC/trcsub.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/TOP_SRC/trcsub.F90	(revision 6139)
+++ /trunk/NEMOGCM/NEMO/TOP_SRC/trcsub.F90	(revision 6140)
@@ -40,5 +40,4 @@
    PUBLIC   trc_sub_ssh      ! called by trc_stp to reset physics variables
 
-   !!* Module variables
    REAL(wp)  :: r1_ndttrc     !    1 /  nn_dttrc 
    REAL(wp)  :: r1_ndttrcp1   !    1 / (nn_dttrc+1) 
@@ -48,6 +47,4 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  uslp_tm  , vslp_tm  , wslpi_tm  , wslpj_tm     !: time mean 
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -88,12 +85,12 @@
        IF( MOD( kt , nn_dttrc ) /= 0 ) THEN
           !
-          un_tm   (:,:,:)        = un_tm   (:,:,:)        + un   (:,:,:)        * fse3u(:,:,:) 
-          vn_tm   (:,:,:)        = vn_tm   (:,:,:)        + vn   (:,:,:)        * fse3v(:,:,:) 
-          tsn_tm  (:,:,:,jp_tem) = tsn_tm  (:,:,:,jp_tem) + tsn  (:,:,:,jp_tem) * fse3t(:,:,:)  
-          tsn_tm  (:,:,:,jp_sal) = tsn_tm  (:,:,:,jp_sal) + tsn  (:,:,:,jp_sal) * fse3t(:,:,:)  
-          rhop_tm (:,:,:)        = rhop_tm (:,:,:)        + rhop (:,:,:)        * fse3t(:,:,:)  
-          avt_tm  (:,:,:)        = avt_tm  (:,:,:)        + avt  (:,:,:)        * fse3w(:,:,:)  
-# if defined key_zdfddm
-          avs_tm  (:,:,:)        = avs_tm  (:,:,:)        + avs  (:,:,:)        * fse3w(:,:,:)  
+          un_tm   (:,:,:)        = un_tm   (:,:,:)        + un   (:,:,:)        * e3u_n(:,:,:) 
+          vn_tm   (:,:,:)        = vn_tm   (:,:,:)        + vn   (:,:,:)        * e3v_n(:,:,:) 
+          tsn_tm  (:,:,:,jp_tem) = tsn_tm  (:,:,:,jp_tem) + tsn  (:,:,:,jp_tem) * e3t_n(:,:,:)  
+          tsn_tm  (:,:,:,jp_sal) = tsn_tm  (:,:,:,jp_sal) + tsn  (:,:,:,jp_sal) * e3t_n(:,:,:)  
+          rhop_tm (:,:,:)        = rhop_tm (:,:,:)        + rhop (:,:,:)        * e3t_n(:,:,:)  
+          avt_tm  (:,:,:)        = avt_tm  (:,:,:)        + avt  (:,:,:)        * e3w_n(:,:,:)  
+# if defined key_zdfddm
+          avs_tm  (:,:,:)        = avs_tm  (:,:,:)        + avs  (:,:,:)        * e3w_n(:,:,:)  
 # endif
          IF( l_ldfslp ) THEN
@@ -165,12 +162,12 @@
          !
          ! 2. Create averages and reassign variables
-         un_tm    (:,:,:)        = un_tm   (:,:,:)        + un   (:,:,:)        * fse3u(:,:,:) 
-         vn_tm    (:,:,:)        = vn_tm   (:,:,:)        + vn   (:,:,:)        * fse3v(:,:,:) 
-         tsn_tm   (:,:,:,jp_tem) = tsn_tm  (:,:,:,jp_tem) + tsn  (:,:,:,jp_tem) * fse3t(:,:,:)  
-         tsn_tm   (:,:,:,jp_sal) = tsn_tm  (:,:,:,jp_sal) + tsn  (:,:,:,jp_sal) * fse3t(:,:,:)  
-         rhop_tm (:,:,:)         = rhop_tm (:,:,:)        + rhop (:,:,:)        * fse3t(:,:,:)  
-         avt_tm   (:,:,:)        = avt_tm  (:,:,:)        + avt  (:,:,:)        * fse3w(:,:,:)  
-# if defined key_zdfddm
-         avs_tm   (:,:,:)        = avs_tm  (:,:,:)        + avs  (:,:,:)        * fse3w(:,:,:)  
+         un_tm    (:,:,:)        = un_tm   (:,:,:)        + un   (:,:,:)        * e3u_n(:,:,:) 
+         vn_tm    (:,:,:)        = vn_tm   (:,:,:)        + vn   (:,:,:)        * e3v_n(:,:,:) 
+         tsn_tm   (:,:,:,jp_tem) = tsn_tm  (:,:,:,jp_tem) + tsn  (:,:,:,jp_tem) * e3t_n(:,:,:)  
+         tsn_tm   (:,:,:,jp_sal) = tsn_tm  (:,:,:,jp_sal) + tsn  (:,:,:,jp_sal) * e3t_n(:,:,:)  
+         rhop_tm (:,:,:)         = rhop_tm (:,:,:)        + rhop (:,:,:)        * e3t_n(:,:,:)  
+         avt_tm   (:,:,:)        = avt_tm  (:,:,:)        + avt  (:,:,:)        * e3w_n(:,:,:)  
+# if defined key_zdfddm
+         avs_tm   (:,:,:)        = avs_tm  (:,:,:)        + avs  (:,:,:)        * e3w_n(:,:,:)  
 # endif
          IF( l_ldfslp ) THEN
@@ -244,8 +241,8 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  z1_ne3t = r1_ndttrcp1  / fse3t(ji,jj,jk)
-                  z1_ne3u = r1_ndttrcp1  / fse3u(ji,jj,jk)
-                  z1_ne3v = r1_ndttrcp1  / fse3v(ji,jj,jk)
-                  z1_ne3w = r1_ndttrcp1  / fse3w(ji,jj,jk)
+                  z1_ne3t = r1_ndttrcp1  / e3t_n(ji,jj,jk)
+                  z1_ne3u = r1_ndttrcp1  / e3u_n(ji,jj,jk)
+                  z1_ne3v = r1_ndttrcp1  / e3v_n(ji,jj,jk)
+                  z1_ne3w = r1_ndttrcp1  / e3w_n(ji,jj,jk)
                   !
                   un   (ji,jj,jk)        = un_tm   (ji,jj,jk)        * z1_ne3u
@@ -300,13 +297,13 @@
       IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'top_sub_alloc : unable to allocate standard ocean arrays' )
 
-      un_tm   (:,:,:)        = un   (:,:,:)        * fse3u(:,:,:) 
-      vn_tm   (:,:,:)        = vn   (:,:,:)        * fse3v(:,:,:) 
-      tsn_tm  (:,:,:,jp_tem) = tsn  (:,:,:,jp_tem) * fse3t(:,:,:)  
-      tsn_tm  (:,:,:,jp_sal) = tsn  (:,:,:,jp_sal) * fse3t(:,:,:)  
-      rhop_tm (:,:,:)        = rhop (:,:,:)        * fse3t(:,:,:)  
+      un_tm   (:,:,:)        = un   (:,:,:)        * e3u_n(:,:,:) 
+      vn_tm   (:,:,:)        = vn   (:,:,:)        * e3v_n(:,:,:) 
+      tsn_tm  (:,:,:,jp_tem) = tsn  (:,:,:,jp_tem) * e3t_n(:,:,:)  
+      tsn_tm  (:,:,:,jp_sal) = tsn  (:,:,:,jp_sal) * e3t_n(:,:,:)  
+      rhop_tm (:,:,:)        = rhop (:,:,:)        * e3t_n(:,:,:)  
 !!gm : BUG? ==>> for avt & avs I don't understand the division by e3w
-      avt_tm  (:,:,:)        = avt  (:,:,:)        * fse3w(:,:,:)  
-# if defined key_zdfddm
-      avs_tm  (:,:,:)        = avs  (:,:,:)        * fse3w(:,:,:)  
+      avt_tm  (:,:,:)        = avt  (:,:,:)        * e3w_n(:,:,:)  
+# if defined key_zdfddm
+      avs_tm  (:,:,:)        = avs  (:,:,:)        * e3w_n(:,:,:)  
 # endif
       IF( l_ldfslp ) THEN
@@ -400,12 +397,12 @@
       !                                      
       ! Start new averages
-         un_tm   (:,:,:)        = un   (:,:,:)        * fse3u(:,:,:) 
-         vn_tm   (:,:,:)        = vn   (:,:,:)        * fse3v(:,:,:) 
-         tsn_tm  (:,:,:,jp_tem) = tsn  (:,:,:,jp_tem) * fse3t(:,:,:)  
-         tsn_tm  (:,:,:,jp_sal) = tsn  (:,:,:,jp_sal) * fse3t(:,:,:)  
-         rhop_tm (:,:,:)        = rhop (:,:,:)        * fse3t(:,:,:)  
-         avt_tm  (:,:,:)        = avt  (:,:,:)        * fse3w(:,:,:)  
-# if defined key_zdfddm
-         avs_tm  (:,:,:)        = avs  (:,:,:)        * fse3w(:,:,:)  
+         un_tm   (:,:,:)        = un   (:,:,:)        * e3u_n(:,:,:) 
+         vn_tm   (:,:,:)        = vn   (:,:,:)        * e3v_n(:,:,:) 
+         tsn_tm  (:,:,:,jp_tem) = tsn  (:,:,:,jp_tem) * e3t_n(:,:,:)  
+         tsn_tm  (:,:,:,jp_sal) = tsn  (:,:,:,jp_sal) * e3t_n(:,:,:)  
+         rhop_tm (:,:,:)        = rhop (:,:,:)        * e3t_n(:,:,:)  
+         avt_tm  (:,:,:)        = avt  (:,:,:)        * e3w_n(:,:,:)  
+# if defined key_zdfddm
+         avs_tm  (:,:,:)        = avs  (:,:,:)        * e3w_n(:,:,:)  
 # endif
       IF( l_ldfslp ) THEN
@@ -449,5 +446,5 @@
       !!                   
       !! ** Purpose :   compute the after ssh (ssha), the now vertical velocity
-      !!              and update the now vertical coordinate (lk_vvl=T).
+      !!              and update the now vertical coordinate (ln_linssh=F).
       !!
       !! ** Method  : - Using the incompressibility hypothesis, the vertical 
@@ -458,9 +455,8 @@
       !! ** action  :   ssha    : after sea surface height
       !!                wn      : now vertical velocity
-      !!                sshu_a, sshv_a, sshf_a  : after sea surface height (lk_vvl=T)
+      !!                sshu_a, sshv_a, sshf_a  : after sea surface height (ln_linssh=F)
       !!
       !! Reference  : Leclair, M., and G. Madec, 2009, Ocean Modelling.
       !!----------------------------------------------------------------------
-      !
       INTEGER, INTENT(in) ::   kt   ! time step
       !
@@ -473,5 +469,5 @@
       !
       ! Allocate temporary workspace
-      CALL wrk_alloc( jpi, jpj, zhdiv )
+      CALL wrk_alloc( jpi,jpj,   zhdiv )
 
       IF( kt == nittrc000 ) THEN
@@ -485,4 +481,5 @@
       ENDIF
       !
+!!gm BUG here !   hdivn will include the runoff divergence at the wrong timestep !!!!
       CALL div_hor( kt )                              ! Horizontal divergence & Relative vorticity
       !
@@ -495,5 +492,5 @@
       zhdiv(:,:) = 0._wp
       DO jk = 1, jpkm1                                 ! Horizontal divergence of barotropic transports
-        zhdiv(:,:) = zhdiv(:,:) + fse3t(:,:,jk) * hdivn(:,:,jk)
+        zhdiv(:,:) = zhdiv(:,:) + e3t_n(:,:,jk) * hdivn(:,:,jk)
       END DO
       !                                                ! Sea surface elevation time stepping
@@ -502,5 +499,5 @@
       z1_rau0 = 0.5 / rau0
       ssha(:,:) = (  sshb(:,:) - z2dt * ( z1_rau0 * ( emp_b(:,:) + emp(:,:) ) + zhdiv(:,:) )  ) * tmask(:,:,1)
-
+#if ! defined key_dynspg_ts
       ! These lines are not necessary with time splitting since
       ! boundary condition on sea level is set during ts loop
@@ -512,5 +509,6 @@
       CALL lbc_lnk( ssha, 'T', 1. ) 
 #endif
-
+#endif
+      !
       !                                           !------------------------------!
       !                                           !     Now Vertical Velocity    !
@@ -518,7 +516,7 @@
       z1_2dt = 1.e0 / z2dt
       DO jk = jpkm1, 1, -1                             ! integrate from the bottom the hor. divergence
-         ! - ML - need 3 lines here because replacement of fse3t by its expression yields too long lines otherwise
-         wn(:,:,jk) = wn(:,:,jk+1) -   fse3t_n(:,:,jk) * hdivn(:,:,jk)        &
-            &                      - ( fse3t_a(:,:,jk) - fse3t_b(:,:,jk) )    &
+         ! - ML - need 3 lines here because replacement of e3t by its expression yields too long lines otherwise
+         wn(:,:,jk) = wn(:,:,jk+1) -   e3t_n(:,:,jk) * hdivn(:,:,jk)        &
+            &                      - ( e3t_a(:,:,jk) - e3t_b(:,:,jk) )    &
             &                         * tmask(:,:,jk) * z1_2dt
 #if defined key_bdy
@@ -526,11 +524,11 @@
 #endif
       END DO
-
-      !
-      CALL wrk_dealloc( jpi, jpj, zhdiv )
+      !
+      CALL wrk_dealloc( jpi,jpj,   zhdiv )
       !
       IF( nn_timing == 1 )  CALL timing_stop('trc_sub_ssh')
       !
    END SUBROUTINE trc_sub_ssh
+
 
    INTEGER FUNCTION trc_sub_alloc()
@@ -598,5 +596,4 @@
       WRITE(*,*) 'trc_sub_ini: You should not have seen this print! error?', kt
    END SUBROUTINE trc_sub_ini
-
 #endif
 
Index: /trunk/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-XC40_METO
===================================================================
--- /trunk/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-XC40_METO	(revision 6139)
+++ /trunk/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-XC40_METO	(revision 6140)
@@ -2,7 +2,7 @@
 #!
 #PBS -N nemo_sette
-#PBS -l walltime=00:30:00
+#PBS -l walltime=00:08:00
 #PBS -j oe
-#PBS -q QUEUE
+#PBS -q normal
 #PBS -l SELECT
 
@@ -77,12 +77,6 @@
 # Run SPMD case
 #
-    if [ $OCORES -gt 32 ] ; then
-        #Still more than one node so run in parallel queue
-        echo time aprun -b  -n $OCORES -N $O_PER_NODE ./opa
-             time aprun -b  -n $OCORES -N $O_PER_NODE ./opa
-    else
-       echo time mpiexec -n $OCORES ./opa
-            time mpiexec -n $OCORES ./opa
-    fi
+    echo time aprun -b  -n $OCORES -N $O_PER_NODE ./opa
+         time aprun -b  -n $OCORES -N $O_PER_NODE ./opa
   fi
 #
Index: /trunk/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena
===================================================================
--- /trunk/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena	(revision 6140)
+++ /trunk/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena	(revision 6140)
@@ -0,0 +1,80 @@
+#!/bin/bash 
+#!
+#BSUB -q poe_short
+#BSUB -n NPROCS
+#BSUB -a poe
+#BSUB -J MPI_config
+#BSUB -o poe.stdout.%J
+#BSUB -e poe.stderr.%J
+
+ 
+
+###############################################################
+# Test specific settings. Do not hand edit these lines; the fcm_job.sh script will set these
+# (via sed operating on this template job file). 
+#
+  OCEANCORES=NPROCS
+  export SETTE_DIR=DEF_SETTE_DIR
+
+###############################################################
+#
+# set up mpp computing environment
+#
+# Local settings for machine IBM Power6 (VARGAS at IDRIS France)
+#
+
+# export MPIRUN="mpirun -n $OCEANCORES"
+
+export MPIRUN="mpirun.lsf"
+
+#
+# load sette functions (only post_test_tidyup needed)
+#
+  . ${SETTE_DIR}/all_functions.sh
+
+
+# Don't remove neither change the following line 
+# BODY
+
+#
+# These variables are needed by post_test_tidyup function in all_functions.sh
+#
+  export EXE_DIR=DEF_EXE_DIR
+  export INPUT_DIR=DEF_INPUT_DIR
+  export CONFIG_DIR=DEF_CONFIG_DIR
+  export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
+  export NEW_CONF=DEF_NEW_CONF
+  export CMP_NAM=DEF_CMP_NAM
+  export TEST_NAME=DEF_TEST_NAME
+#
+# end of set up
+
+
+###############################################################
+#
+# change to the working directory 
+#
+cd ${EXE_DIR}
+
+#
+  echo Running on host `hostname`
+  echo Time is `date`
+  echo Directory is `pwd`
+# 
+#  Run the parallel MPI executable 
+#
+#  echo "Running time ${MPIRUN} " $OCEANCORES " ./opa"
+#
+
+  if [ MPI_FLAG == "yes" ]; then
+     time ${MPIRUN} ./opa
+  else
+     time ./opa
+  fi
+#
+  post_test_tidyup
+
+# END_BODY
+# Don't remove neither change the previous line 
+
+  exit
Index: /trunk/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena_xios
===================================================================
--- /trunk/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena_xios	(revision 6140)
+++ /trunk/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena_xios	(revision 6140)
@@ -0,0 +1,106 @@
+#!/bin/bash 
+#!
+#BSUB -q poe_short
+#BSUB -n TOTAL_NPROCS
+#BSUB -a poe
+#BSUB -J MPI_config
+#BSUB -o poe.stdout.%J
+#BSUB -e poe.stderr.%J
+
+ 
+
+###############################################################
+# Test specific settings. Do not hand edit these lines; the fcm_job.sh script will set these
+# (via sed operating on this template job file). 
+#
+  OCEANCORES=NPROCS
+  XIOS_NUMPROCS=NXIOPROCS
+  export SETTE_DIR=DEF_SETTE_DIR
+
+###############################################################
+#
+# set up mpp computing environment
+#
+# Local settings for machine IBM Power6 (VARGAS at IDRIS France)
+#
+
+# export MPIRUN="mpirun -n $OCEANCORES"
+
+module load  INTEL/intel_xe_2013 NETCDF/netcdf-4.3_parallel_shared NETCDF/parallel-netcdf-1.3.1 HDF5/hdf5-1.8.11_parallel_shared
+export MPIRUN="mpirun.lsf"
+
+export LD_LIBRARY_PATH=${XIOS}/lib:${LD_LIBRARY_PATH}
+
+XIOS_SERVER_PATHNAME="${XIOS}/bin/xios_server.exe"
+
+#
+# load sette functions (only post_test_tidyup needed)
+#
+  . ${SETTE_DIR}/all_functions.sh
+
+
+# Don't remove neither change the following line 
+# BODY
+
+#
+# These variables are needed by post_test_tidyup function in all_functions.sh
+#
+  export EXE_DIR=DEF_EXE_DIR
+  export INPUT_DIR=DEF_INPUT_DIR
+  export CONFIG_DIR=DEF_CONFIG_DIR
+  export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
+  export NEW_CONF=DEF_NEW_CONF
+  export CMP_NAM=DEF_CMP_NAM
+  export TEST_NAME=DEF_TEST_NAME
+#
+# end of set up
+
+
+###############################################################
+#
+# change to the working directory 
+#
+cd ${EXE_DIR}
+
+#
+  echo Running on host `hostname`
+  echo Time is `date`
+  echo Directory is `pwd`
+# 
+#  Run the parallel MPI executable 
+#
+#  echo "Running time ${MPIRUN} " $OCEANCORES " ./opa"
+#
+
+  if [ MPI_FLAG == "yes" ]; then
+     if [ $XIOS_NUMPROCS -eq 0 ]; then
+       time ${MPIRUN} ./opa
+     else
+
+       export MP_PGMMODEL=mpmd
+       export MP_CMDFILE=xioscmdfile
+       rm xioscmdfile &> /dev/null
+       touch xioscmdfile
+       k=0
+       while (( k < $OCEANCORES )) ; do
+          echo ./opa >> xioscmdfile
+          k=`expr $k + 1`
+       done
+       k=0
+       while (( k < $XIOS_NUMPROCS )) ; do
+          echo $XIOS_SERVER_PATHNAME >> xioscmdfile
+          k=`expr $k + 1`
+       done
+
+       time ${MPIRUN}
+     fi
+  else
+     time ./opa
+  fi
+#
+  post_test_tidyup
+
+# END_BODY
+# Don't remove neither change the previous line 
+
+  exit
Index: /trunk/NEMOGCM/SETTE/input_ORCA2_LIM.cfg
===================================================================
--- /trunk/NEMOGCM/SETTE/input_ORCA2_LIM.cfg	(revision 6139)
+++ /trunk/NEMOGCM/SETTE/input_ORCA2_LIM.cfg	(revision 6140)
@@ -1,1 +1,1 @@
-ORCA2_LIM_nemo_v3.6.tar ORCA2_LIM_nemo_v3.6
+ORCA2_LIM_nemo_v3.6st.tar ORCA2_LIM_nemo_v3.6
Index: /trunk/NEMOGCM/SETTE/prepare_job.sh
===================================================================
--- /trunk/NEMOGCM/SETTE/prepare_job.sh	(revision 6139)
+++ /trunk/NEMOGCM/SETTE/prepare_job.sh	(revision 6140)
@@ -266,17 +266,7 @@
                                 echo NB_XNODES=${NB_XNODES} 
                                 echo Total NB_NODES=${NB_NODES}
-                                if [ ${NB_NODES} -eq 1 ] ; then
-                                   QUEUE=shared
-                                   #Not using XIOS in detatched mode and using less than one node so should be ok on shared node
-                                   #Load snplauncher module to allow use of mpiexec
-                                   SELECT="select=1:ncpus=$((NXIO_PROC + NB_PROC))":mem=15GB
-                                   module load cray-snplauncher
-                                   echo 'Shared Queue'
-                                else
-                                   QUEUE=normal
-                                   SELECT="select=$NB_NODES"
-                                   module unload cray-snplauncher #Make sure snplauncher module is not loaded
-                                   echo 'Normal Queue'
-                                fi
+                                QUEUE=normal
+                                SELECT="select=$NB_NODES"
+                                module unload cray-snplauncher #Make sure snplauncher module is not loaded
                                 ;;
                         openmpi_NAVITI_MERCATOR)
@@ -330,6 +320,5 @@
                     ;;
               XC40_METO*)
-                    cat run_sette_test.job | sed -e"s/QUEUE/${QUEUE}/" \
-                                                 -e"s/SELECT/${SELECT}/" > run_sette_test1.job
+                    cat run_sette_test.job | sed -e"s/SELECT/${SELECT}/" > run_sette_test1.job
                     mv run_sette_test1.job run_sette_test.job
                     ;;
Index: /trunk/NEMOGCM/SETTE/sette.sh
===================================================================
--- /trunk/NEMOGCM/SETTE/sette.sh	(revision 6139)
+++ /trunk/NEMOGCM/SETTE/sette.sh	(revision 6140)
@@ -144,5 +144,5 @@
 #                  18 & 19 
 
-for config in  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
+for config in  1 2 3 4 5 6 7 8 9 10 11 12 15 16
 
 do
@@ -168,4 +168,5 @@
     set_namelist namelist_cfg ln_clobber .true.
     set_namelist namelist_cfg nn_fwb 0
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist namelist_cfg jpni 2
     set_namelist namelist_cfg jpnj 2
@@ -191,4 +192,5 @@
     set_namelist namelist_cfg ln_clobber .true.
     set_namelist namelist_cfg nn_fwb 0
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist namelist_cfg jpni 2
     set_namelist namelist_cfg jpnj 2
@@ -236,4 +238,5 @@
     set_namelist namelist_cfg ln_ctl .false.
     set_namelist namelist_cfg ln_clobber .true.
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist namelist_cfg jpni 1
     set_namelist namelist_cfg jpnj 4
@@ -262,4 +265,5 @@
     set_namelist namelist_cfg ln_ctl .false.
     set_namelist namelist_cfg ln_clobber .true.
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist namelist_cfg jpni 2
     set_namelist namelist_cfg jpnj 2
@@ -300,4 +304,5 @@
     set_namelist namelist_cfg jpnj 4
     set_namelist namelist_cfg jpnij 8
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist namelist_top_cfg ln_trcdta .false.
     set_namelist namelist_top_cfg ln_diatrc .false.
@@ -335,4 +340,5 @@
     set_namelist namelist_cfg jpnj 4
     set_namelist namelist_cfg jpnij 8
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist namelist_top_cfg ln_diatrc .false.
     set_namelist namelist_top_cfg ln_rsttr .true.
@@ -392,4 +398,5 @@
     set_namelist namelist_cfg jpnj 4
     set_namelist namelist_cfg jpnij 16
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist namelist_top_cfg ln_trcdta .false.
     set_namelist namelist_top_cfg ln_diatrc .false.
@@ -430,4 +437,5 @@
     set_namelist namelist_cfg jpnj 8
     set_namelist namelist_cfg jpnij 16
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist namelist_top_cfg ln_trcdta .false.
     set_namelist namelist_top_cfg ln_diatrc .false.
@@ -650,4 +658,5 @@
     set_namelist namelist_cfg jpnj 2
     set_namelist namelist_cfg jpnij 4
+#   set_namelist namelist_cfg nn_solv 2
     if [ ${USING_MPMD} == "yes" ] ; then
        set_xio_using_server iodef.xml true
@@ -673,4 +682,5 @@
     set_namelist namelist_cfg jpnj 2
     set_namelist namelist_cfg jpnij 4
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist namelist_cfg cn_ocerst_in \"O2L3_LONG_00000075_restart\"
     set_namelist namelist_ice_cfg cn_icerst_in \"O2L3_LONG_00000075_restart_ice\"
@@ -713,4 +723,5 @@
     set_namelist namelist_cfg jpnj 4
     set_namelist namelist_cfg jpnij 16
+#   set_namelist namelist_cfg nn_solv 2
     if [ ${USING_MPMD} == "yes" ] ; then
        set_xio_using_server iodef.xml true
@@ -737,4 +748,5 @@
     set_namelist namelist_cfg jpnj 8
     set_namelist namelist_cfg jpnij 16
+#   set_namelist namelist_cfg nn_solv 2
     if [ ${USING_MPMD} == "yes" ] ; then
        set_xio_using_server iodef.xml true
@@ -1007,4 +1019,5 @@
     set_namelist namelist_cfg ln_clobber .true.
     set_namelist namelist_cfg nn_fwb 0
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist namelist_cfg jpni 2
     set_namelist namelist_cfg jpnj 2
@@ -1030,4 +1043,5 @@
     set_namelist namelist_cfg ln_clobber .true.
     set_namelist namelist_cfg nn_fwb 0
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist namelist_cfg jpni 2
     set_namelist namelist_cfg jpnj 2
@@ -1074,4 +1088,5 @@
     set_namelist namelist_cfg ln_ctl .false.
     set_namelist namelist_cfg ln_clobber .true.
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist namelist_cfg jpni 1
     set_namelist namelist_cfg jpnj 4
@@ -1100,4 +1115,5 @@
     set_namelist namelist_cfg ln_ctl .false.
     set_namelist namelist_cfg ln_clobber .true.
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist namelist_cfg jpni 2
     set_namelist namelist_cfg jpnj 2
@@ -1121,5 +1137,5 @@
     export TEST_NAME="REPRO_4_4"
     cd ${CONFIG_DIR}
-    . ./makenemo -m ${CMP_NAM} -n ORCA2_LIM_OBS -r ORCA2_LIM -j 8 add_key "key_mpp_rep key_diaobs key_asminc" del_key ${DEL_KEYS}
+    . ./makenemo -m ${CMP_NAM} -n ORCA2_LIM_OBS -r ORCA2_LIM -j 8 add_key "key_mpp_rep key_asminc" del_key ${DEL_KEYS}
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -1138,12 +1154,11 @@
     set_namelist namelist_cfg jpnj 4
     set_namelist namelist_cfg jpnij 16
+    set_namelist namelist_cfg ln_diaobs .true.
     set_namelist namelist_cfg ln_t3d .true.
     set_namelist namelist_cfg ln_s3d .true.
-    set_namelist namelist_cfg ln_profb .true.
     set_namelist namelist_cfg ln_sst .true.
-    set_namelist namelist_cfg ln_sstfb .true.
     set_namelist namelist_cfg ln_sla .true.
-    set_namelist namelist_cfg ln_slafb .true.
-    set_namelist namelist_cfg ln_seaice .false.
+    set_namelist namelist_cfg ln_sic .true.
+    set_namelist namelist_cfg ln_vel3d .true.
     set_namelist namelist_cfg ln_bkgwri .true.
     set_namelist namelist_cfg ln_trainc .true.
@@ -1176,12 +1191,11 @@
     set_namelist namelist_cfg jpnj 8
     set_namelist namelist_cfg jpnij 16
+    set_namelist namelist_cfg ln_diaobs .true.
     set_namelist namelist_cfg ln_t3d .true.
     set_namelist namelist_cfg ln_s3d .true.
-    set_namelist namelist_cfg ln_profb .true.
     set_namelist namelist_cfg ln_sst .true.
-    set_namelist namelist_cfg ln_sstfb .true.
     set_namelist namelist_cfg ln_sla .true.
-    set_namelist namelist_cfg ln_slafb .true.
-    set_namelist namelist_cfg ln_seaice .false.
+    set_namelist namelist_cfg ln_sic .true.
+    set_namelist namelist_cfg ln_vel3d .true.
     set_namelist namelist_cfg ln_bkgwri .true.
     set_namelist namelist_cfg ln_trainc .true.
@@ -1329,4 +1343,5 @@
     set_namelist namelist_cfg jpnj 2
     set_namelist namelist_cfg jpnij 4
+#   set_namelist namelist_cfg nn_solv 2
 #
     set_namelist 1_namelist_cfg cn_exp \"O2LP_LONG\"
@@ -1361,4 +1376,5 @@
 
     set_namelist namelist_cfg jpnij 4
+#   set_namelist namelist_cfg nn_solv 2
     set_namelist 1_namelist_cfg cn_exp \"O2LP_SHORT\"
     set_namelist 1_namelist_cfg nn_it000 151
@@ -1412,4 +1428,5 @@
     set_namelist namelist_cfg jpnj 4
     set_namelist namelist_cfg jpnij 16
+#   set_namelist namelist_cfg nn_solv 2
 #
     set_namelist 1_namelist_cfg nn_it000 1
@@ -1443,4 +1460,5 @@
     set_namelist namelist_cfg jpnj 8
     set_namelist namelist_cfg jpnij 16
+#   set_namelist namelist_cfg nn_solv 2
 #
     set_namelist 1_namelist_cfg nn_it000 1
Index: /trunk/NEMOGCM/SETTE/sette_rpt
===================================================================
--- /trunk/NEMOGCM/SETTE/sette_rpt	(revision 6139)
+++ /trunk/NEMOGCM/SETTE/sette_rpt	(revision 6140)
@@ -90,24 +90,48 @@
     set f1o = ./WORCA2LIMPIS_LONG/{$mach}/{$dorv}/LONG/ocean.output
     set f1s = ./WORCA2LIMPIS_LONG/{$mach}/{$dorv}/LONG/solver.stat
+    set f1t = ./WORCA2LIMPIS_LONG/{$mach}/{$dorv}/LONG/tracer.stat
     set f2o = ./WORCA2LIMPIS_LONG/{$mach}/{$dorv}/SHORT/ocean.output
     set f2s = ./WORCA2LIMPIS_LONG/{$mach}/{$dorv}/SHORT/solver.stat
-  
-    set nl = `wc -l $f2s`
-    tail -$nl[1] $f1s > f1.tmp$$
-    cmp -s f1.tmp$$ $f2s
-    if ( $status == 0 ) then
-      echo "ORCA2LIMPIS restartability  passed"
-    else
-      echo "ORCA2LIMPIS restartability  FAILED"
-      if ( $pass == 1 ) then
-        echo "<return> to view solver.stat differences"
-        set y = $<
-        sdiff f1.tmp$$ $f2s
-        echo "<return> to view ocean.output differences"
-        set y = $<
-        sdiff $f1o $f2o | grep "|"
-        echo "<return> to continue"
-        set y = $<
-      endif
+    set f2t = ./WORCA2LIMPIS_LONG/{$mach}/{$dorv}/SHORT/tracer.stat
+
+    set stato = 0
+    set nl = `wc -l $f2s`
+    tail -$nl[1] $f1s > f1.tmp$$
+    cmp -s f1.tmp$$ $f2s
+    if ( $status == 0 ) then
+      echo "ORCA2LIMPIS solver.stat restartability  passed"
+    else
+      set stato = 1
+      echo "ORCA2LIMPIS solver.stat restartability  FAILED"
+      if ( $pass == 1 ) then
+        echo "<return> to view solver.stat differences"
+        set y = $<
+        sdiff f1.tmp$$ $f2s
+      endif
+    endif
+
+    set nl = `wc -l $f2t`
+    tail -$nl[1] $f1t > f1.tmp$$
+    cmp -s f1.tmp$$ $f2t
+    if ( $status == 0 ) then
+      echo "ORCA2LIMPIS tracer.stat restartability  passed"
+    else
+      set stato = 1
+      echo "ORCA2LIMPIS tracer.stat restartability  FAILED"
+      if ( $pass == 1 ) then
+        echo "<return> to view tracer.stat differences"
+        set y = $<
+        sdiff f1.tmp$$ $f2t
+      endif
+    endif
+    if ( $stato == 1 ) then
+      if ( $pass == 1 ) then
+        echo "<return> to view ocean.output differences"
+        set y = $<
+        sdiff $f1o $f2o | grep "|"
+        echo "<return> to continue"
+        set y = $<
+      endif
+      set stato = 0
     endif
     rm f1.tmp$$
@@ -293,22 +317,44 @@
     set f1o = ./WORCA2LIMPIS_16/{$mach}/{$dorv}/REPRO_2_8/ocean.output
     set f1s = ./WORCA2LIMPIS_16/{$mach}/{$dorv}/REPRO_2_8/solver.stat
+    set f1t = ./WORCA2LIMPIS_16/{$mach}/{$dorv}/REPRO_2_8/tracer.stat
     set f2o = ./WORCA2LIMPIS_16/{$mach}/{$dorv}/REPRO_4_4/ocean.output
     set f2s = ./WORCA2LIMPIS_16/{$mach}/{$dorv}/REPRO_4_4/solver.stat
-  
-    cmp -s $f1s $f2s
-    if ( $status == 0 ) then
-      echo "ORCA2LIMPIS reproducibility passed"
-    else
-      echo "ORCA2LIMPIS reproducibility FAILED"
-      if ( $pass == 1 ) then
-        echo "<return> to view solver.stat differences"
-        set y = $<
-        sdiff $f1s $f2s
-        echo "<return> to view ocean.output differences"
-        set y = $<
-        sdiff $f1o $f2o | grep "|"
-        echo "<return> to continue"
-        set y = $<
-      endif
+    set f2t = ./WORCA2LIMPIS_16/{$mach}/{$dorv}/REPRO_4_4/tracer.stat
+
+    set stato = 0
+    cmp -s $f1s $f2s
+    if ( $status == 0 ) then
+      echo "ORCA2LIMPIS solver.stat reproducibility  passed"
+    else
+      set stato = 1
+      echo "ORCA2LIMPIS solver.stat reproducibility  FAILED"
+      if ( $pass == 1 ) then
+        echo "<return> to view solver.stat differences"
+        set y = $<
+        sdiff $f1s $f2s
+      endif
+    endif
+
+    cmp -s $f1t $f2t
+    if ( $status == 0 ) then
+      echo "ORCA2LIMPIS tracer.stat reproducibility  passed"
+    else
+      set stato = 1
+      echo "ORCA2LIMPIS tracer.stat reproducibility  FAILED"
+      if ( $pass == 1 ) then
+        echo "<return> to view tracer.stat differences"
+        set y = $<
+        sdiff $f1t $f2t
+      endif
+    endif
+    if ( $stato == 1 ) then
+      if ( $pass == 1 ) then
+        echo "<return> to view ocean.output differences"
+        set y = $<
+        sdiff $f1o $f2o | grep "|"
+        echo "<return> to continue"
+        set y = $<
+      endif
+      set stato = 0
     endif
   endif
Index: /trunk/NEMOGCM/SETTE/sette_rpt.sh
===================================================================
--- /trunk/NEMOGCM/SETTE/sette_rpt.sh	(revision 6140)
+++ /trunk/NEMOGCM/SETTE/sette_rpt.sh	(revision 6140)
@@ -0,0 +1,228 @@
+#!/bin/bash -f
+#
+# simple SETTE report generator.
+#
+# This version should be run in the SETTE directory. 
+# The machine name will be picked up from the sette.sh script but the location of the
+# validation directory needs to be set here (currently assumed to reside in the ../CONFIG directory)
+#
+#########################################################################################
+######################### Start of function definitions #################################
+##
+function resttest() { 
+#
+# Restartability checks. Expects LONG and SHORT run directories
+# Compares end of LONG stat files with equivalent entries from the SHORT stat files.
+#
+  vdir=$1
+  nam=$2
+  pass=$3
+#
+  if [ -d $vdir/$nam ]; then
+    dorv=`ls -1rt $vdir/$nam/$mach/ | tail -1l `
+    dorv=`echo $dorv | sed -e 's:.*/::'`
+    f1o=$vdir/$nam/$mach/$dorv/LONG/ocean.output
+    f1s=$vdir/$nam/$mach/$dorv/LONG/solver.stat
+    f1t=$vdir/$nam/$mach/$dorv/LONG/tracer.stat
+    f2o=$vdir/$nam/$mach/$dorv/SHORT/ocean.output
+    f2s=$vdir/$nam/$mach/$dorv/SHORT/solver.stat
+    f2t=$vdir/$nam/$mach/$dorv/SHORT/tracer.stat
+
+    if  [ ! -f $f1s ]; then 
+      printf "%-20s %s\n" $nam " incomplete test";
+      return; 
+    fi
+    if  [ ! -f $f2s ]; then 
+      printf "%-20s %s\n" $nam " incomplete test";
+      return; 
+    fi
+#
+# Check for tracer.stat files
+#
+    ttest=-1
+    if  [  -f $f1t ]; then (( ttest++ )); fi
+    if  [  -f $f2t ]; then (( ttest++ )); fi
+    done_oce=0
+
+    nl=(`wc -l $f2s`)
+    tail -${nl[0]} $f1s > f1.tmp$$
+    cmp -s f1.tmp$$ $f2s
+    if [ $? == 0 ]; then
+      if [ $pass == 0 ]; then printf "%-20s %s\n" $nam  " solver.stat restartability  passed";fi
+    else
+      printf "%-20s %s\n" $nam  " solver.stat restartability  FAILED"
+#
+# Offer view of differences on the second pass
+#
+      if [ $pass == 1 ]; then
+        echo "<return> to view solver.stat differences"
+        read y
+        sdiff f1.tmp$$ $f2s
+        echo "<return> to view ocean.output differences"
+        read y
+        sdiff $f1o $f2o | grep "|"
+        done_oce=1
+        echo "<return> to continue"
+        read y
+      fi
+    fi
+#
+# Check tracer.stat files (if they exist)
+#
+    if [ $ttest == 1 ]; then
+      nl=(`wc -l $f2t`)
+      tail -${nl[0]} $f1t > f1.tmp$$
+      cmp -s f1.tmp$$ $f2t
+      if [ $? == 0 ]; then
+        if [ $pass == 0 ]; then printf "%-20s %s\n" $nam  " tracer.stat restartability  passed";fi
+      else
+        printf "%-20s %s\n" $nam  " solver.stat restartability  FAILED"
+#
+# Offer view of differences on the second pass
+#
+        if [ $pass == 1 ]; then
+          echo "<return> to view tracer.stat differences"
+          read y
+          sdiff f1.tmp$$ $f2t
+#
+# Only offer ocean.output view if it has not been viewed previously
+#
+          if [ $done_oce == 0 ]; then
+            echo "<return> to view ocean.output differences"
+            read y
+            sdiff $f1o $f2o | grep "|"
+          fi
+          echo "<return> to continue"
+          read y
+        fi
+      fi
+    fi
+    rm f1.tmp$$
+  fi
+}
+
+function reprotest(){
+#
+# Reproducibility checks. Expects REPRO_N_M and REPRO_I_J run directories
+# Compares end of stat files from each
+#
+  vdir=$1
+  nam=$2
+  pass=$3
+#
+  if [ -d $vdir/$nam ]; then
+    dorv=`ls -1rt $vdir/$nam/$mach/ | tail -1l `
+    dorv=`echo $dorv | sed -e 's:.*/::'`
+    rep1=`ls -1rt $vdir/$nam/$mach/$dorv/ | tail -2l | head -1 `
+    rep2=`ls -1rt $vdir/$nam/$mach/$dorv/ | tail -1l`
+    f1o=$vdir/$nam/$mach/$dorv/$rep1/ocean.output
+    f1s=$vdir/$nam/$mach/$dorv/$rep1/solver.stat
+    f1t=$vdir/$nam/$mach/$dorv/$rep1/tracer.stat
+    f2o=$vdir/$nam/$mach/$dorv/$rep2/ocean.output
+    f2s=$vdir/$nam/$mach/$dorv/$rep2/solver.stat
+    f2t=$vdir/$nam/$mach/$dorv/$rep2/tracer.stat
+
+    if  [ ! -f $f1s ]; then 
+      printf "%-20s %s\n" $nam " incomplete test";
+      return; 
+    fi
+    if  [ ! -f $f2s ]; then 
+      printf "%-20s %s\n" $nam " incomplete test";
+      return; 
+    fi
+#
+# Check for tracer.stat files
+#
+    ttest=-1
+    if  [  -f $f1t ]; then (( ttest++ )); fi
+    if  [  -f $f2t ]; then (( ttest++ )); fi
+    done_oce=0
+
+    cmp -s $f1s $f2s
+    if [ $? == 0 ]; then
+      if [ $pass == 0 ]; then printf "%-20s %s\n" $nam  " solver.stat reproducibility passed";fi
+    else
+      printf "%-20s %s\n" $nam  " solver.stat reproducibility FAILED"
+#
+# Offer view of differences on the second pass
+#
+      if [ $pass == 1 ]; then
+        echo "<return> to view solver.stat differences"
+        read y
+        sdiff f1.tmp$$ $f2s
+        echo "<return> to view ocean.output differences"
+        read y
+        sdiff $f1o $f2o | grep "|"
+        done_oce=1
+        echo "<return> to continue"
+        read y
+      fi
+    fi
+#
+# Check tracer.stat files (if they exist)
+#
+    if [ $ttest == 1 ]; then
+      cmp -s $f1t $f2t
+      if [ $? == 0 ]; then
+        if [ $pass == 0 ]; then printf "%-20s %s\n" $nam  " tracer.stat reproducibility passed";fi
+      else
+        printf "%-20s %s\n" $nam  " solver.stat reproducibility FAILED"
+#
+# Offer view of differences on the second pass
+#
+        if [ $pass == 1 ]; then
+          echo "<return> to view tracer.stat differences"
+          read y
+          sdiff $f1t $f2t
+#
+# Only offer ocean.output view if it has not been viewed previously
+#
+          if [ $done_oce == 0 ]; then
+            echo "<return> to view ocean.output differences"
+            read y
+            sdiff $f1o $f2o | grep "|"
+          fi
+          echo "<return> to continue"
+          read y
+        fi
+      fi
+    fi
+  fi
+}
+########################### END of function definitions #################################
+##                                                                                     ##
+##    Main script                                                                      ##
+##                                                                                     ##
+#########################################################################################
+#
+  mach=`grep "COMPILER=" ./sette.sh | sed -e 's/COMPILER=//'`
+  NEMO_VALID=`grep "NEMO_VALIDATION_DIR=" ./param.cfg | sed -e 's/NEMO_VALIDATION_DIR=//'`
+#
+  if [ ! -d $NEMO_VALID ]; then
+    echo "$NEMO_VALID validation directory not found"
+    exit
+  fi
+#
+# The script also needs the date or revision tag. Currently this is taken from the latest sub-directory found in each directory
+#  
+for pass in  0 1 
+do
+#
+ if [ $pass == 1 ]; then echo "---------------2nd pass------------------";fi
+#
+# Restartability test
+#
+ for restart_test in WGYRE_LONG WISOMIP_LONG WORCA2LIMPIS_LONG WORCA2OFFPIS_LONG WAMM12_LONG WORCA2LIM3_LONG WSAS_LONG WORCA2AGUL_LONG
+ do
+   resttest $NEMO_VALID $restart_test $pass
+ done
+#
+# Reproducibility tests
+#
+ for repro_test in WGYRE_4 WISOMIP_4 WORCA2LIMPIS_16 WORCA2OFFPIS_16 WAMM12_32 WORCA2LIM3_16 WORCA2_LIM_OBS WSAS_32 WORCA2AGUL_1_2 WORCA2AGUL_16 WORCA2AGUL_2_2_NAG
+ do
+   reprotest $NEMO_VALID $repro_test $pass
+ done
+#
+done
+exit
Index: /trunk/NEMOGCM/TOOLS/NESTING/src/agrif_create_restart.f90
===================================================================
--- /trunk/NEMOGCM/TOOLS/NESTING/src/agrif_create_restart.f90	(revision 6139)
+++ /trunk/NEMOGCM/TOOLS/NESTING/src/agrif_create_restart.f90	(revision 6140)
@@ -411,5 +411,5 @@
         ENDIF
         !
-     CASE('nfice','nfbulk','kt','ndastp','adatrj','rdt','rdttra1') 
+     CASE('nfice','nfbulk','kt','ndastp','adatrj','rdt') 
         IF(.NOT. dimg ) THEN
            WRITE(*,*) 'copy ',TRIM(Ncdf_varname(i))
@@ -417,5 +417,5 @@
               CALL Read_Ncdf_var(TRIM(Ncdf_varname(i)),TRIM(restart_file),tabtemp0dreal)  
               SELECT CASE (TRIM(Ncdf_varname(i)))
-              CASE('rdt','rdttra1')
+              CASE('rdt')
                  tabtemp0dreal = tabtemp0dreal/rhot
               CASE('kt')
Index: /trunk/NEMOGCM/TOOLS/REBUILD_NEMO/icb_combrest.py
===================================================================
--- /trunk/NEMOGCM/TOOLS/REBUILD_NEMO/icb_combrest.py	(revision 6140)
+++ /trunk/NEMOGCM/TOOLS/REBUILD_NEMO/icb_combrest.py	(revision 6140)
@@ -0,0 +1,255 @@
+from netCDF4 import Dataset
+from argparse import ArgumentParser
+import numpy as np
+import sys
+
+#
+# Basic iceberg trajectory restart post-processing python script.
+# This script collects iceberg information from the distributed restarts written
+# out by each processing region and writes the information into a global restart file.
+# The global restart file must already exist and contain the collated 2D spatial fields
+# as prepared by utilities such as rebuild_nemo. This python script simply adds the
+# iceberg position and state data that is held using the unlimited dimension 'n' which
+# has been ignored by rebuild_nemo. Each processing region that contains icebergs will
+# (probably) have a different number of icebergs (indicated by differing values for the
+# current size of the unlimited dimension). This script collects all icebergs into a 
+# single unordered list.
+#
+
+parser = ArgumentParser(description='produce a global trajectory restart file from distributed output\
+                                     files, e.g. \n python ./icb_pp.py \
+                                     -f  icebergs_00692992_restart_ -n 480 -o icebergs_restart.nc [-O]')
+
+parser.add_argument('-f',dest='froot',help='fileroot_of_distrbuted_data; root name of \
+                     distributed trajectory restart file (usually completed with XXXX.nc, where \
+                     XXXX is the 4 digit processor number)', 
+                     default='icebergs_00692992_restart_')
+
+parser.add_argument('-n',dest='fnum',help='number of distributed files to process', 
+                     type=int, default=None)
+
+parser.add_argument('-o',dest='fout',help='global_iceberg_restart; file name to append the \
+                     global iceberg restart data to.', default='icebergs_restart.nc')
+
+parser.add_argument('-O',dest='fcre',help='Create the output file from scratch rather than \
+                     append to an existing file.', \
+                     action='store_true', default=False)
+
+args = parser.parse_args()
+
+default_used = 0
+if args.froot is None:
+    pathstart = 'icebergs_00692992_restart_'
+    default_used = 1
+else:
+    pathstart = args.froot
+
+if args.fnum is None:
+    procnum = 0
+    default_used = 1
+else:
+    procnum = args.fnum
+
+if args.fout is None:
+    pathout = 'icebergs_restart.nc'
+    default_used = 1
+else:
+    pathout = args.fout
+
+if default_used == 1:
+   print('At least one default value will be used; command executing is:')
+   print('icb_combrest.py -f ',pathstart,' -n ',procnum,' -o ',pathout)
+
+if procnum < 1:
+   print('Need some files to collate! procnum = ',procnum)
+   sys.exit()
+
+icu = []
+times = []
+ntraj = 0
+nk = 0
+#
+# Loop through all distributed datasets to obtain the total number 
+# of icebergs to transfer
+#
+for n in range(procnum):
+ nn = '%4.4d' % n
+ try:
+   fw = Dataset(pathstart+nn+'.nc')
+ except:
+   print 'Error: unable to open input file: ' + pathstart+nn+'.nc'
+   sys.exit()
+ for d in fw.dimensions :
+  if d == 'n' :
+   if len(fw.dimensions['n']) > 0:
+#    print 'icebergs found in: ' + pathstart+nn+'.nc' 
+     if len(fw.dimensions['k']) > nk :
+       nk = len(fw.dimensions['k'])
+     ntraj = ntraj + len(fw.dimensions['n'])
+ fw.close()
+#
+print(ntraj, ' icebergs found across all datasets')
+#
+# Declare 2-D arrays to receive the data from all files
+#
+lons = np.zeros(ntraj)
+lats = np.zeros(ntraj)
+xis  = np.zeros(ntraj)
+yjs  = np.zeros(ntraj)
+uvs  = np.zeros(ntraj)
+vvs  = np.zeros(ntraj)
+mas  = np.zeros(ntraj)
+ths  = np.zeros(ntraj)
+wis  = np.zeros(ntraj)
+les  = np.zeros(ntraj)
+dys  = np.zeros(ntraj)
+mss  = np.zeros(ntraj)
+msb  = np.zeros(ntraj)
+hds  = np.zeros(ntraj)
+yrs  = np.zeros(ntraj      , dtype=int)
+num  = np.zeros((ntraj, nk), dtype=int)
+#
+# loop through distributed datasets again, this time
+# collecting all trajectory data
+#
+nt = 0
+for n in range(procnum):
+ nn = '%4.4d' % n
+ fw = Dataset(pathstart+nn+'.nc')
+ for d in fw.dimensions :
+  if d == 'n' :
+# Note many distributed datafiles will contain no iceberg data
+# so skip quickly over these
+    m  = len(fw.dimensions['n'])
+    if m > 0:
+#     print pathstart+nn+'.nc'
+      lons[nt:nt+m]  = fw.variables['lon'][:]
+      lats[nt:nt+m]  = fw.variables['lat'][:]
+      xis[nt:nt+m]   = fw.variables['xi'][:]
+      yjs[nt:nt+m]   = fw.variables['yj'][:]
+      uvs[nt:nt+m]   = fw.variables['uvel'][:]
+      vvs[nt:nt+m]   = fw.variables['vvel'][:]
+      mas[nt:nt+m]   = fw.variables['mass'][:]
+      ths[nt:nt+m]   = fw.variables['thickness'][:]
+      wis[nt:nt+m]   = fw.variables['width'][:]
+      les[nt:nt+m]   = fw.variables['length'][:]
+      dys[nt:nt+m]   = fw.variables['day'][:]
+      mss[nt:nt+m]   = fw.variables['mass_scaling'][:]
+      msb[nt:nt+m]   = fw.variables['mass_of_bits'][:]
+      hds[nt:nt+m]   = fw.variables['heat_density'][:]
+      yrs[nt:nt+m]   = fw.variables['year'][:]
+      num[nt:nt+m,:] = fw.variables['number'][:,:]
+      nt = nt + m
+ fw.close()
+
+# Finally create the output file and write out the collated sets
+#
+if args.fcre :
+  try:
+    fo = Dataset(pathout, 'w', format='NETCDF4')
+  except:
+    print 'Error accessing output file: ' + pathout
+    print 'Check it is a writable location.'
+    sys.exit()
+else :
+  try:
+    fo = Dataset(pathout, 'r+', format='NETCDF4')
+  except:
+    print 'Error accessing output file: ' + pathout
+    print 'Check it exists and is writable.'
+    print 'Or run adding the -O option to create an output file which will'
+    print 'contain the iceberg state data only.'
+    sys.exit()
+#
+add_k = 1
+for d in fo.dimensions :
+  if d == 'n' :
+    print 'Error: dimension n already exists in output file'
+    sys.exit()
+  if d == 'k' :
+    add_k = 0
+onn  = fo.createDimension('n', None)
+if add_k > 0 :
+ onk = fo.createDimension('k', nk)
+olon = fo.createVariable('lon', 'f8',('n'))
+olat = fo.createVariable('lat', 'f8',('n'))
+oxis = fo.createVariable('xi', 'f8',('n'))
+oyjs = fo.createVariable('yj', 'f8',('n'))
+ouvs = fo.createVariable('uvel', 'f8',('n'))
+ovvs = fo.createVariable('vvel', 'f8',('n'))
+omas = fo.createVariable('mass', 'f8',('n'))
+oths = fo.createVariable('thickness', 'f8',('n'))
+owis = fo.createVariable('width', 'f8',('n'))
+oles = fo.createVariable('length', 'f8',('n'))
+odys = fo.createVariable('day', 'f8',('n'))
+omss = fo.createVariable('mass_scaling', 'f8',('n'))
+omsb = fo.createVariable('mass_of_bits', 'f8',('n'))
+ohds = fo.createVariable('heat_density', 'f8',('n'))
+oyrs = fo.createVariable('year', 'i4',('n'))
+onum = fo.createVariable('number', 'i4',('n','k'))
+#
+olon[:] = lons
+olon.long_name = "longitude"
+olon.units = "degrees_E" 
+#
+olat[:] = lats
+olat.long_name = "latitude"
+olat.units = "degrees_N"
+#
+oxis[:] = xis
+oxis.long_name = "x grid box position"
+oxis.units = "fractional"
+#
+oyjs[:] = yjs
+oyjs.long_name = "y grid box position"
+oyjs.units = "fractional"
+#
+ouvs[:] = uvs
+ouvs.long_name = "zonal velocity"
+ouvs.units = "m/s"
+#
+ovvs[:] = vvs
+ovvs.long_name = "meridional velocity"
+ovvs.units = "m/s"
+#
+omas[:] = mas
+omas.long_name = "mass"
+omas.units = "kg"
+#
+oths[:] = ths
+oths.long_name = "thickness"
+oths.units = "m"
+#
+owis[:] = wis
+owis.long_name = "width"
+owis.units = "m"
+#
+oles[:] = les
+oles.long_name = "length"
+oles.units = "m"
+#
+odys[:] = dys
+odys.long_name = "year day of calving event"
+odys.units = "days"
+#
+omss[:] = mss
+omss.long_name = "scaling factor for mass of calving berg"
+omss.units = "none"
+#
+omsb[:] = msb
+omsb.long_name = "mass of bergy bits"
+omsb.units = "kg"
+#
+ohds[:] = hds
+ohds.long_name = "heat density"
+ohds.units = "J/kg"
+#
+oyrs[:] = yrs
+oyrs.long_name = "calendar year of calving event"
+oyrs.units = "years"
+#
+onum[:,:] = num
+onum.long_name = "iceberg number on this processor"
+onum.units = "count"
+#
+fo.close()
Index: /trunk/NEMOGCM/TOOLS/SCOORD_GEN/namelist
===================================================================
--- /trunk/NEMOGCM/TOOLS/SCOORD_GEN/namelist	(revision 6140)
+++ /trunk/NEMOGCM/TOOLS/SCOORD_GEN/namelist	(revision 6140)
@@ -0,0 +1,28 @@
+!-----------------------------------------------------------------------
+&namzgr_sco    !   s-coordinate or hybrid z-s-coordinate
+!-----------------------------------------------------------------------
+   ln_s_sh94   = .false.    !  Song & Haidvogel 1994 hybrid S-sigma   (T)|
+   ln_s_sf12   = .true.   !  Siddorn & Furner 2012 hybrid S-z-sigma (T)| if both are false the NEMO tanh stretching is applied
+   ln_sigcrit  = .true.    !  use sigma coordinates below critical depth (T) or Z coordinates (F) for Siddorn & Furner stretch
+                           !  stretching coefficients for all functions
+   rn_jpk      =  51       ! Number of S levels
+   ln_eq_taper = .false.   !  Tapering of S coords near equator
+   cn_coord_hgr = 'coordinates.nc'  ! File containing gphit (latitude) coordinate for use if ln_eq_taper=.true.
+   rn_sbot_min =   10.0    !  minimum depth of s-bottom surface (>0) (m)
+   rn_sbot_max = 7000.0    !  maximum depth of s-bottom surface (= ocean depth) (>0) (m)
+   rn_hc       =   50.0    !  critical depth for transition to stretched coordinates
+                        !!!!!!!  Envelop bathymetry
+   rn_rmax     =    0.3    !  maximum cut-off r-value allowed (0<r_max<1)
+                        !!!!!!!  SH94 stretching coefficients  (ln_s_sh94 = .true.)
+   rn_theta    =    6.0    !  surface control parameter (0<=theta<=20)
+   rn_bb       =    0.8    !  stretching with SH94 s-sigma   
+                        !!!!!!!  SF12 stretching coefficient  (ln_s_sf12 = .true.)
+   rn_alpha    =    4.4    !  stretching with SF12 s-sigma
+   rn_efold    =    0.0    !  efold length scale for transition to stretched coord
+   rn_zs       =    1.0    !  depth of surface grid box
+                           !  bottom cell depth (Zb) is a linear function of water depth Zb = H*a + b
+   rn_zb_a     =    0.024  !  bathymetry scaling factor for calculating Zb
+   rn_zb_b     =   -0.2    !  offset for calculating Zb
+                        !!!!!!!! Other stretching (not SH94 or SF12) [also uses rn_theta above]
+   rn_thetb    =    1.0    !  bottom control parameter  (0<=thetb<= 1) 
+/
Index: /trunk/NEMOGCM/TOOLS/SCOORD_GEN/src/scoord_gen.F90
===================================================================
--- /trunk/NEMOGCM/TOOLS/SCOORD_GEN/src/scoord_gen.F90	(revision 6140)
+++ /trunk/NEMOGCM/TOOLS/SCOORD_GEN/src/scoord_gen.F90	(revision 6140)
@@ -0,0 +1,664 @@
+PROGRAM SCOORD_GEN
+      !!----------------------------------------------------------------------
+      !!                  ***  PROGRAM scoord_gen  ***
+      !!                     
+      !! ** Purpose :   define the s-coordinate system
+      !!
+      !! ** Method  :   s-coordinate
+      !!         The depth of model levels is defined as the product of an
+      !!      analytical function by the local bathymetry, while the vertical
+      !!      scale factors are defined as the product of the first derivative
+      !!      of the analytical function by the bathymetry.
+      !!      (this solution save memory as depth and scale factors are not
+      !!      3d fields)
+      !!          - Read bathymetry (in meters) at t-point and compute the
+      !!         bathymetry at u-, v-, and f-points.
+      !!            hbatu = mi( hbatt )
+      !!            hbatv = mj( hbatt )
+      !!            hbatf = mi( mj( hbatt ) )
+      !!          - Compute z_gsigt, z_gsigw, z_esigt, z_esigw from an analytical
+      !!         function and its derivative given as function.
+      !!            z_gsigt(k) = fssig (k    )
+      !!            z_gsigw(k) = fssig (k-0.5)
+      !!            z_esigt(k) = fsdsig(k    )
+      !!            z_esigw(k) = fsdsig(k-0.5)
+      !!      Three options for stretching are give, and they can be modified
+      !!      following the users requirements. 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.
+      !!
+      !!      The three methods for stretching available are:
+      !! 
+      !!           s_sh94 (Song and Haidvogel 1994)
+      !!                a sinh/tanh function that allows sigma and stretched sigma
+      !!
+      !!           s_sf12 (Siddorn and Furner 2012?)
+      !!                allows the maintenance of fixed surface and or
+      !!                bottom cell resolutions (cf. geopotential coordinates) 
+      !!                within an analytically derived stretched S-coordinate framework.
+      !! 
+      !!          s_tanh  (Madec et al 1996)
+      !!                a cosh/tanh function that gives stretched coordinates        
+      !!
+      !! ** History: 2015: Tim Graham - Code created based on online zdf_sco routine
+      !!
+      !!
+      !!----------------------------------------------------------------------
+      !
+      USE utils
+      IMPLICIT NONE
+
+
+     !!----------------------------------------------------------------------
+      !
+      !
+      OPEN( UNIT=numnam, FILE='namelist', FORM='FORMATTED', STATUS='OLD' )
+      READ( numnam, namzgr_sco )
+      CLOSE( numnam )
+      jpk = INT(rn_jpk)
+
+      WRITE(*,*)
+      WRITE(*,*) 'scoord_gen : s-coordinate or hybrid z-s-coordinate'
+      WRITE(*,*) '~~~~~~~~~~~'
+      WRITE(*,*) '   Namelist namzgr_sco'
+      WRITE(*,*) '     stretching coeffs '
+      WRITE(*,*) '        Number of levels                             rn_jpk        = ',rn_jpk
+      WRITE(*,*) '        maximum depth of s-bottom surface (>0)       rn_sbot_max   = ',rn_sbot_max
+      WRITE(*,*) '        minimum depth of s-bottom surface (>0)       rn_sbot_min   = ',rn_sbot_min
+      WRITE(*,*) '        Critical depth                               rn_hc         = ',rn_hc
+      WRITE(*,*) '        maximum cut-off r-value allowed              rn_rmax       = ',rn_rmax
+      WRITE(*,*) '        Tapering in vicinity of equator              ln_eq_taper   = ',ln_eq_taper
+      WRITE(*,*) '        Horizontal Coordinate File                   cn_coord_hgr  = ',cn_coord_hgr
+      WRITE(*,*) '     Song and Haidvogel 1994 stretching              ln_s_sh94     = ',ln_s_sh94
+      WRITE(*,*) '        Song and Haidvogel 1994 stretching coefficients'
+      WRITE(*,*) '        surface control parameter (0<=rn_theta<=20)  rn_theta      = ',rn_theta
+      WRITE(*,*) '        bottom  control parameter (0<=rn_thetb<= 1)  rn_thetb      = ',rn_thetb
+      WRITE(*,*) '        stretching parameter (song and haidvogel)    rn_bb         = ',rn_bb
+      WRITE(*,*) '     Siddorn and Furner 2012 stretching              ln_s_sf12     = ',ln_s_sf12
+      WRITE(*,*) '        switching to sigma (T) or Z (F) at H<Hc      ln_sigcrit    = ',ln_sigcrit
+      WRITE(*,*) '        Siddorn and Furner 2012 stretching coefficients'
+      WRITE(*,*) '        stretchin parameter ( >1 surface; <1 bottom) rn_alpha      = ',rn_alpha
+      WRITE(*,*) '        e-fold length scale for transition region    rn_efold      = ',rn_efold
+      WRITE(*,*) '        Surface cell depth (Zs) (m)                  rn_zs         = ',rn_zs
+      WRITE(*,*) '        Bathymetry multiplier for Zb                 rn_zb_a       = ',rn_zb_a
+      WRITE(*,*) '        Offset for Zb                                rn_zb_b       = ',rn_zb_b
+      WRITE(*,*) '        Bottom cell (Zb) (m) = H*rn_zb_a + rn_zb_b'
+
+      
+      ! Read in bathy, jpi and jpj from bathy.nc
+      CALL read_bathy()
+
+      !Allocate all other allocatable variables
+      ios = dom_oce_alloc()
+      IF( ios .NE. 0) THEN
+         WRITE(0,*) 'Unable to allocate all arrays'
+         STOP 1
+      ENDIF
+
+      hift(:,:) = rn_sbot_min                     ! set the minimum depth for the s-coordinate
+      hifu(:,:) = rn_sbot_min
+      hifv(:,:) = rn_sbot_min
+      hiff(:,:) = rn_sbot_min
+
+      !                                        ! set maximum ocean depth
+      bathy(:,:) = MIN( rn_sbot_max, bathy(:,:) )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+           IF( bathy(ji,jj) > 0. )   bathy(ji,jj) = MAX( rn_sbot_min, bathy(ji,jj) )
+         END DO
+      END DO
+      !                                        ! =============================
+      !                                        ! Define the envelop bathymetry   (hbatt)
+      !                                        ! =============================
+      ! use r-value to create hybrid coordinates
+      zenv(:,:) = bathy(:,:)
+      !
+      ! set first land point adjacent to a wet cell to sbot_min as this needs to be included in smoothing
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+           IF( bathy(ji,jj) == 0. ) THEN
+             iip1 = MIN( ji+1, jpi )
+             ijp1 = MIN( jj+1, jpj )
+             iim1 = MAX( ji-1, 1 )
+             ijm1 = MAX( jj-1, 1 )
+             IF( (bathy(iip1,jj) + bathy(iim1,jj) + bathy(ji,ijp1) + bathy(ji,ijm1) +              &
+        &         bathy(iip1,ijp1) + bathy(iim1,ijm1) + bathy(iip1,ijp1) + bathy(iim1,ijm1)) > 0. ) THEN
+               zenv(ji,jj) = rn_sbot_min
+             ENDIF
+           ENDIF
+         END DO
+      END DO
+      ! 
+      ! smooth the bathymetry (if required)
+      scosrf(:,:) = 0.             ! ocean surface depth (here zero: no under ice-shelf sea)
+      scobot(:,:) = bathy(:,:)        ! ocean bottom  depth
+      !
+      jl = 0
+      zrmax = 1.
+      !   
+      !     
+      ! set scaling factor used in reducing vertical gradients
+      zrfact = ( 1. - rn_rmax ) / ( 1. + rn_rmax )
+      !
+      ! initialise temporary evelope depth arrays
+      ztmpi1(:,:) = zenv(:,:)
+      ztmpi2(:,:) = zenv(:,:)
+      ztmpj1(:,:) = zenv(:,:)
+      ztmpj2(:,:) = zenv(:,:)
+      !
+      ! initialise temporary r-value arrays
+      zri(:,:) = 1.
+      zrj(:,:) = 1.
+
+      !                                                            ! ================ !
+      DO WHILE( jl <= 10000 .AND. ( zrmax - rn_rmax ) > 1.e-8 ) !  Iterative loop  !
+         !                                                         ! ================ !
+         jl = jl + 1
+         zrmax = 0.
+         ! we set zrmax from previous r-values (zri and zrj) first
+         ! if set after current r-value calculation (as previously)
+         ! we could exit DO WHILE prematurely before checking r-value
+         ! of current zenv
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+               zrmax = MAX( zrmax, ABS(zri(ji,jj)), ABS(zrj(ji,jj)) )
+            END DO
+         END DO
+         zri(:,:) = 0.
+         zrj(:,:) = 0.
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iip1 = MIN(ji+1,jpi) 
+               ijp1 = MIN(jj+1,jpj)     
+               IF( (zenv(ji,jj) > 0.) .AND. (zenv(iip1,jj) > 0.)) THEN
+                  zri(ji,jj) = ( zenv(iip1,jj  ) - zenv(ji,jj) ) / ( zenv(iip1,jj  ) + zenv(ji,jj) )
+               END IF
+               IF( (zenv(ji,jj) > 0.) .AND. (zenv(ji,ijp1) > 0.)) THEN
+                  zrj(ji,jj) = ( zenv(ji  ,ijp1) - zenv(ji,jj) ) / ( zenv(ji  ,ijp1) + zenv(ji,jj) )
+               END IF
+               IF( zri(ji,jj) >  rn_rmax )   ztmpi1(ji  ,jj  ) = zenv(iip1,jj  ) * zrfact
+               IF( zri(ji,jj) < -rn_rmax )   ztmpi2(iip1,jj  ) = zenv(ji  ,jj  ) * zrfact
+               IF( zrj(ji,jj) >  rn_rmax )   ztmpj1(ji  ,jj  ) = zenv(ji  ,ijp1) * zrfact
+               IF( zrj(ji,jj) < -rn_rmax )   ztmpj2(ji  ,ijp1) = zenv(ji  ,jj  ) * zrfact
+            END DO
+         END DO
+         !
+         WRITE(*,*) 'zgr_sco :   iter= ',jl, ' rmax= ', zrmax
+         !
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zenv(ji,jj) = MAX(zenv(ji,jj), ztmpi1(ji,jj), ztmpi2(ji,jj), ztmpj1(ji,jj), ztmpj2(ji,jj) )
+            END DO
+         END DO
+         !                                                  ! ================ !
+      END DO                                                !     End loop     !
+      !                                                     ! ================ !
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zenv(ji,jj) = MAX( zenv(ji,jj), rn_sbot_min ) ! set all points to avoid undefined scale value warnings
+         END DO
+      END DO
+      !
+      ! Envelope bathymetry saved in hbatt
+      hbatt(:,:) = zenv(:,:) 
+      IF( ln_eq_taper) THEN
+        CALL READ_GPHIT()
+        IF( MINVAL( gphit(:,:) ) * MAXVAL( gphit(:,:) ) <= 0. ) THEN
+          WRITE(*,*) 's-coordinates are tapered in vicinity of the Equator' 
+          DO jj = 1, jpj
+             DO ji = 1, jpi
+                ztaper = EXP( -(gphit(ji,jj)/8.)**2. )
+                hbatt(ji,jj) = rn_sbot_max * ztaper + hbatt(ji,jj) * ( 1. - ztaper )
+             END DO
+          END DO
+        ENDIF
+      ENDIF
+      !
+      !                                        ! ==============================
+      !                                        !   hbatu, hbatv, hbatf fields
+      !                                        ! ==============================
+      WRITE(*,*)
+      WRITE(*,*) ' zgr_sco: minimum depth of the envelop topography set to : ', rn_sbot_min
+      hbatu(:,:) = rn_sbot_min
+      hbatv(:,:) = rn_sbot_min
+      hbatf(:,:) = rn_sbot_min
+      DO jj = 1, jpj-1
+        DO ji = 1, jpi-1   ! NO vector opt.
+           hbatu(ji,jj) = 0.50 * ( hbatt(ji  ,jj) + hbatt(ji+1,jj  ) )
+           hbatv(ji,jj) = 0.50 * ( hbatt(ji  ,jj) + hbatt(ji  ,jj+1) )
+           hbatf(ji,jj) = 0.25 * ( hbatt(ji  ,jj) + hbatt(ji  ,jj+1)   &
+              &                     + hbatt(ji+1,jj) + hbatt(ji+1,jj+1) )
+        END DO
+      END DO
+      ! 
+      zhbat(:,:) = hbatu(:,:)   
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( hbatu(ji,jj) == 0. ) THEN
+               IF( zhbat(ji,jj) == 0. )   hbatu(ji,jj) = rn_sbot_min
+               IF( zhbat(ji,jj) /= 0. )   hbatu(ji,jj) = zhbat(ji,jj)
+            ENDIF
+         END DO
+      END DO
+      zhbat(:,:) = hbatv(:,:)  
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( hbatv(ji,jj) == 0. ) THEN
+               IF( zhbat(ji,jj) == 0. )   hbatv(ji,jj) = rn_sbot_min
+               IF( zhbat(ji,jj) /= 0. )   hbatv(ji,jj) = zhbat(ji,jj)
+            ENDIF
+         END DO
+      END DO
+      zhbat(:,:) = hbatf(:,:)   
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( hbatf(ji,jj) == 0. ) THEN
+               IF( zhbat(ji,jj) == 0. )   hbatf(ji,jj) = rn_sbot_min
+               IF( zhbat(ji,jj) /= 0. )   hbatf(ji,jj) = zhbat(ji,jj)
+            ENDIF
+         END DO
+      END DO
+
+!!bug:  key_helsinki a verifer
+      hift(:,:) = MIN( hift(:,:), hbatt(:,:) )
+      hifu(:,:) = MIN( hifu(:,:), hbatu(:,:) )
+      hifv(:,:) = MIN( hifv(:,:), hbatv(:,:) )
+      hiff(:,:) = MIN( hiff(:,:), hbatf(:,:) )
+
+         WRITE(*,*) ' MAX val hif   t ', MAXVAL( hift (:,:) ), ' f ', MAXVAL( hiff (:,:) ),  &
+            &                        ' u ',   MAXVAL( hifu (:,:) ), ' v ', MAXVAL( hifv (:,:) )
+         WRITE(*,*) ' MIN val hif   t ', MINVAL( hift (:,:) ), ' f ', MINVAL( hiff (:,:) ),  &
+            &                        ' u ',   MINVAL( hifu (:,:) ), ' v ', MINVAL( hifv (:,:) )
+         WRITE(*,*) ' MAX val hbat  t ', MAXVAL( hbatt(:,:) ), ' f ', MAXVAL( hbatf(:,:) ),  &
+            &                        ' u ',   MAXVAL( hbatu(:,:) ), ' v ', MAXVAL( hbatv(:,:) )
+         WRITE(*,*) ' MIN val hbat  t ', MINVAL( hbatt(:,:) ), ' f ', MINVAL( hbatf(:,:) ),  &
+            &                        ' u ',   MINVAL( hbatu(:,:) ), ' v ', MINVAL( hbatv(:,:) )
+      
+      ! Create the output file
+      CALL make_coord_file()
+
+      !                                            ! =======================
+      !                                            !   s-coordinate fields     (gdep., e3.)
+      !                                            ! =======================
+      !
+      ! non-dimensional "sigma" for model level depth at w- and t-levels
+
+
+!========================================================================
+! Song and Haidvogel  1994 (ln_s_sh94=T)
+! Siddorn and Furner 2012 (ln_sf12=T)
+! or  tanh function       (both false)                    
+! To reduce memory loop over jpk and write each level to file
+!========================================================================
+      IF      ( ln_s_sh94 ) THEN 
+                           CALL s_sh94()
+      ELSE IF ( ln_s_sf12 ) THEN
+                           CALL s_sf12()
+      ELSE                 
+                           CALL s_tanh()
+      ENDIF
+
+!Write all 2D variables to output file
+      CALL write_netcdf_2d_vars()
+      CALL check_nf90( nf90_close(ncout) )
+
+ 
+      !
+END PROGRAM SCOORD_GEN
+
+!!======================================================================
+   SUBROUTINE s_sh94()
+
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE s_sh94  ***
+      !!                     
+      !! ** Purpose :   stretch the s-coordinate system
+      !!
+      !! ** Method  :   s-coordinate stretch using the Song and Haidvogel 1994
+      !!                mixed S/sigma coordinate
+      !!
+      !! Reference : Song and Haidvogel 1994. 
+      !!----------------------------------------------------------------------
+      !
+      USE utils
+      REAL(wp) ::   zcoeft, zcoefw   ! temporary scalars
+      !
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_gsigw3, z_gsigt3, z_gsi3w3
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_gsigw3p1, z_gsigt3m1, z_gsi3w3m1
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_esigt3, z_esigw3, z_esigtu3 
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3           
+
+      ALLOCATE( z_gsigw3(jpi,jpj), z_gsigt3(jpi,jpj), z_gsi3w3(jpi,jpj) )
+      ALLOCATE( z_esigt3(jpi,jpj), z_esigw3(jpi,jpj), z_esigtu3(jpi,jpj)) 
+      ALLOCATE( z_esigtv3(jpi,jpj), z_esigtf3(jpi,jpj), z_esigwu3(jpi,jpj)) 
+      ALLOCATE( z_esigwv3(jpi,jpj), z_gsigw3p1(jpi,jpj), z_gsigt3m1(jpi,jpj) )
+      ALLOCATE( z_gsi3w3m1(jpi,jpj) )
+ 
+      z_gsigw3  = 0.   ;   z_gsigt3  = 0.   ;   z_gsi3w3  = 0.
+      z_esigt3  = 0.   ;   z_esigw3  = 0. 
+      z_esigtu3 = 0.   ;   z_esigtv3 = 0.   ;   z_esigtf3 = 0.
+      z_esigwu3 = 0.   ;   z_esigwv3 = 0.
+
+      DO jk = 1,jpk
+         DO ji = 1, jpi
+            DO jj = 1, jpj
+
+               IF( hbatt(ji,jj) > rn_hc ) THEN    !deep water, stretched sigma
+                     z_gsigw3(ji,jj) = -fssig1( REAL(jk,wp)-0.5, rn_bb )
+                     z_gsigw3p1(ji,jj) = -fssig1( REAL(jk+1,wp)-0.5, rn_bb )
+                     z_gsigt3(ji,jj) = -fssig1( REAL(jk,wp)    , rn_bb )
+               ELSE ! shallow water, uniform sigma
+                     z_gsigw3(ji,jj) =   REAL(jk-1,wp)            / REAL(jpk-1,wp)
+                     z_gsigw3p1(ji,jj) =   REAL(jk,wp)            / REAL(jpk-1,wp)
+                     z_gsigt3(ji,jj) = ( REAL(jk-1,wp) + 0.5 ) / REAL(jpk-1,wp)
+               ENDIF
+               !
+             !gsi3w3m1 & gsigt3m1 only used if jk /= 1 and is set at the end of the loop over jk
+               IF( jk .EQ. 1) THEN
+                  z_esigw3(ji,jj ) = 2. * ( z_gsigt3(ji,jj ) - z_gsigw3(ji,jj ) )
+                  z_gsi3w3(ji,jj) = 0.5 * z_esigw3(ji,jj)
+               ELSE
+                  z_esigw3(ji,jj) = z_gsigt3(ji,jj) - z_gsigt3m1(ji,jj)
+                  z_gsi3w3(ji,jj) = z_gsi3w3m1(ji,jj) + z_esigw3(ji,jj)
+               ENDIF
+               IF( jk .EQ. jpk) THEN
+                  z_esigt3(ji,jj) = 2. * ( z_gsigt3(ji,jj) - z_gsigw3(ji,jj) )
+               ELSE
+                  z_esigt3(ji,jj ) = z_gsigw3p1(ji,jj) - z_gsigw3(ji,jj)
+               ENDIF
+               !
+
+               zcoeft = ( REAL(jk,wp) - 0.5 ) / REAL(jpk-1,wp)
+               zcoefw = ( REAL(jk,wp) - 1.0 ) / REAL(jpk-1,wp)
+               gdept_0(ji,jj) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsigt3(ji,jj)+rn_hc*zcoeft )
+               gdepw_0(ji,jj) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsigw3(ji,jj)+rn_hc*zcoefw )
+               gdep3w_0(ji,jj) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsi3w3(ji,jj)+rn_hc*zcoeft )
+              !
+            END DO   ! for all jj's
+         END DO    ! for all ji's
+
+         DO ji = 1, jpi-1
+            DO jj = 1, jpj-1
+               z_esigtu3(ji,jj) = ( hbatt(ji,jj)*z_esigt3(ji,jj)+hbatt(ji+1,jj)*z_esigt3(ji+1,jj) )   &
+                  &              / ( hbatt(ji,jj)+hbatt(ji+1,jj) )
+               z_esigtv3(ji,jj) = ( hbatt(ji,jj)*z_esigt3(ji,jj)+hbatt(ji,jj+1)*z_esigt3(ji,jj+1) )   &
+                  &              / ( hbatt(ji,jj)+hbatt(ji,jj+1) )
+               z_esigtf3(ji,jj) = ( hbatt(ji,jj)*z_esigt3(ji,jj)+hbatt(ji+1,jj)*z_esigt3(ji+1,jj)     &
+                  &                + hbatt(ji,jj+1)*z_esigt3(ji,jj+1)+hbatt(ji+1,jj+1)*z_esigt3(ji+1,jj+1) )   &
+                  &              / ( hbatt(ji,jj)+hbatt(ji+1,jj)+hbatt(ji,jj+1)+hbatt(ji+1,jj+1) )
+               z_esigwu3(ji,jj) = ( hbatt(ji,jj)*z_esigw3(ji,jj)+hbatt(ji+1,jj)*z_esigw3(ji+1,jj) )   &
+                  &              / ( hbatt(ji,jj)+hbatt(ji+1,jj) )
+               z_esigwv3(ji,jj) = ( hbatt(ji,jj)*z_esigw3(ji,jj)+hbatt(ji,jj+1)*z_esigw3(ji,jj+1) )   &
+                  &              / ( hbatt(ji,jj)+hbatt(ji,jj+1) )
+               !
+               e3t_0(ji,jj) = ( (hbatt(ji,jj)-rn_hc)*z_esigt3 (ji,jj) + rn_hc/REAL(jpk-1,wp) )
+               e3u_0(ji,jj) = ( (hbatu(ji,jj)-rn_hc)*z_esigtu3(ji,jj) + rn_hc/REAL(jpk-1,wp) )
+               e3v_0(ji,jj) = ( (hbatv(ji,jj)-rn_hc)*z_esigtv3(ji,jj) + rn_hc/REAL(jpk-1,wp) )
+               e3f_0(ji,jj) = ( (hbatf(ji,jj)-rn_hc)*z_esigtf3(ji,jj) + rn_hc/REAL(jpk-1,wp) )
+               !
+               e3w_0 (ji,jj) = ( (hbatt(ji,jj)-rn_hc)*z_esigw3 (ji,jj) + rn_hc/REAL(jpk-1,wp) )
+               e3uw_0(ji,jj) = ( (hbatu(ji,jj)-rn_hc)*z_esigwu3(ji,jj) + rn_hc/REAL(jpk-1,wp) )
+               e3vw_0(ji,jj) = ( (hbatv(ji,jj)-rn_hc)*z_esigwv3(ji,jj) + rn_hc/REAL(jpk-1,wp) )
+            END DO
+         END DO
+
+         z_gsigt3m1 = z_gsigt3
+         z_gsi3w3m1 = z_gsi3w3
+ 
+         where (e3t_0   (:,:).eq.0.0)  e3t_0(:,:) = 1.0
+         where (e3u_0   (:,:).eq.0.0)  e3u_0(:,:) = 1.0
+         where (e3v_0   (:,:).eq.0.0)  e3v_0(:,:) = 1.0
+         where (e3f_0   (:,:).eq.0.0)  e3f_0(:,:) = 1.0
+         where (e3w_0   (:,:).eq.0.0)  e3w_0(:,:) = 1.0
+         where (e3uw_0  (:,:).eq.0.0)  e3uw_0(:,:) = 1.0
+         where (e3vw_0  (:,:).eq.0.0)  e3vw_0(:,:) = 1.0
+        
+         CALL write_netcdf_3d_vars(jk)
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+                  IF( scobot(ji,jj) >= gdept_0(ji,jj) )   mbathy(ji,jj) = MAX( 2, jk )
+                  IF( scobot(ji,jj) == 0.             )   mbathy(ji,jj) = 0
+            END DO
+         END DO
+      END DO !End of loop over jk
+
+      DEALLOCATE( z_gsigw3, z_gsigt3, z_gsi3w3, z_gsigw3p1, z_gsigt3m1, z_gsi3w3m1)
+      DEALLOCATE( z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3 )
+
+   END SUBROUTINE s_sh94
+
+   SUBROUTINE s_sf12
+
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE s_sf12 *** 
+      !!                     
+      !! ** Purpose :   stretch the s-coordinate system
+      !!
+      !! ** Method  :   s-coordinate stretch using the Siddorn and Furner 2012?
+      !!                mixed S/sigma/Z coordinate
+      !!
+      !!                This method allows the maintenance of fixed surface and or
+      !!                bottom cell resolutions (cf. geopotential coordinates) 
+      !!                within an analytically derived stretched S-coordinate framework.
+      !!
+      !!
+      !! Reference : Siddorn and Furner 2012 (submitted Ocean modelling).
+      !!----------------------------------------------------------------------
+      !
+      USE utils
+      REAL(wp) ::   zsmth               ! smoothing around critical depth
+      REAL(wp) ::   zzs, zzb           ! Surface and bottom cell thickness in sigma space
+      !
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_gsigw3, z_gsigt3, z_gsi3w3
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_gsigw3p1, z_gsigt3m1, z_gsi3w3m1
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_esigt3, z_esigw3, z_esigtu3 
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3           
+
+      ALLOCATE( z_gsigw3(jpi,jpj), z_gsigt3(jpi,jpj), z_gsi3w3(jpi,jpj) )
+      ALLOCATE( z_esigt3(jpi,jpj), z_esigw3(jpi,jpj), z_esigtu3(jpi,jpj)) 
+      ALLOCATE( z_esigtv3(jpi,jpj), z_esigtf3(jpi,jpj), z_esigwu3(jpi,jpj)) 
+      ALLOCATE( z_esigwv3(jpi,jpj), z_gsigw3p1(jpi,jpj), z_gsigt3m1(jpi,jpj) )
+      ALLOCATE( z_gsi3w3m1(jpi,jpj) )
+
+      z_gsigw3  = 0.   ;   z_gsigt3  = 0.   ;   z_gsi3w3  = 0.
+      z_esigt3  = 0.   ;   z_esigw3  = 0. 
+      z_esigtu3 = 0.   ;   z_esigtv3 = 0.   ;   z_esigtf3 = 0.
+      z_esigwu3 = 0.   ;   z_esigwv3 = 0.
+      
+
+      DO jk = 1,jpk
+         DO ji = 1, jpi
+            DO jj = 1, jpj
+             IF (hbatt(ji,jj)>rn_hc) THEN !deep water, stretched sigma
+              
+                zzb = hbatt(ji,jj)*rn_zb_a + rn_zb_b   ! this forces a linear bottom cell depth relationship with H,.
+                                                     ! could be changed by users but care must be taken to do so carefully
+                zzb = 1.0-(zzb/hbatt(ji,jj))
+            
+                zzs = rn_zs / hbatt(ji,jj) 
+              
+                IF (rn_efold /= 0.0) THEN
+                   zsmth   = tanh( (hbatt(ji,jj)- rn_hc ) / rn_efold )
+                ELSE
+                   zsmth = 1.0 
+                ENDIF
+                  
+                z_gsigw3(ji,jj) =  REAL(jk-1,wp)        /REAL(jpk-1,wp)
+                z_gsigw3p1(ji,jj) =  REAL(jk,wp)        /REAL(jpk-1,wp)
+                z_gsigt3(ji,jj) = (REAL(jk-1,wp)+0.5)/REAL(jpk-1,wp)
+                z_gsigw3(ji,jj) = fgamma( z_gsigw3(ji,jj), zzb, zzs, zsmth  )
+                z_gsigw3p1(ji,jj) = fgamma( z_gsigw3p1(ji,jj), zzb, zzs, zsmth  )
+                z_gsigt3(ji,jj) = fgamma( z_gsigt3(ji,jj), zzb, zzs, zsmth  )
+ 
+             ELSE IF(ln_sigcrit) THEN ! shallow water, uniform sigma
+
+                z_gsigw3(ji,jj) =  REAL(jk-1,wp)     /REAL(jpk-1,wp)
+                z_gsigw3p1(ji,jj) =  REAL(jk,wp)     /REAL(jpk-1,wp)
+                z_gsigt3(ji,jj) = (REAL(jk-1,wp)+0.5)/REAL(jpk-1,wp)
+
+             ELSE  ! shallow water, z coordinates
+
+               z_gsigw3(ji,jj) =  REAL(jk-1,wp)        /REAL(jpk-1,wp)*(rn_hc/hbatt(ji,jj))
+               z_gsigw3p1(ji,jj) =  REAL(jk,wp)        /REAL(jpk-1,wp)*(rn_hc/hbatt(ji,jj))
+               z_gsigt3(ji,jj) = (REAL(jk-1,wp)+0.5)/REAL(jpk-1,wp)*(rn_hc/hbatt(ji,jj))
+
+             ENDIF
+
+             !gsi3w3m1 & z_gsigt3m1 only used if jk /= 1 and is set at the end of the loop over jk
+             IF( jk .EQ. 1) THEN
+                z_esigw3(ji,jj  ) = 2.0 * (z_gsigt3(ji,jj ) - z_gsigw3(ji,jj ))
+                z_gsi3w3(ji,jj) = 0.5 * z_esigw3(ji,jj) 
+             ELSE
+                z_esigw3(ji,jj) = z_gsigt3(ji,jj) - z_gsigt3m1(ji,jj)
+                z_gsi3w3(ji,jj) = z_gsi3w3m1(ji,jj) + z_esigw3(ji,jj)
+             ENDIF
+             IF( jk .EQ. jpk) THEN
+                z_esigt3(ji,jj) = 2.0 * (z_gsigt3(ji,jj) - z_gsigw3(ji,jj))
+             ELSE
+                z_esigt3(ji,jj) = z_gsigw3p1(ji,jj) - z_gsigw3(ji,jj)
+             ENDIF
+
+             gdept_0(ji,jj) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsigt3(ji,jj)
+             gdepw_0(ji,jj) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsigw3(ji,jj)
+             gdep3w_0(ji,jj) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsi3w3(ji,jj)
+
+            ENDDO   ! for all jj's
+         ENDDO    ! for all ji's
+
+         DO ji=1,jpi-1
+            DO jj=1,jpj-1
+
+               z_esigtu3(ji,jj) = ( hbatt(ji,jj)*z_esigt3(ji,jj)+hbatt(ji+1,jj)*z_esigt3(ji+1,jj) ) / &
+                                     ( hbatt(ji,jj)+hbatt(ji+1,jj) )
+               z_esigtv3(ji,jj) = ( hbatt(ji,jj)*z_esigt3(ji,jj)+hbatt(ji,jj+1)*z_esigt3(ji,jj+1) ) / &
+                                     ( hbatt(ji,jj)+hbatt(ji,jj+1) )
+               z_esigtf3(ji,jj) = ( hbatt(ji,jj)*z_esigt3(ji,jj)+hbatt(ji+1,jj)*z_esigt3(ji+1,jj) +  &
+                                       hbatt(ji,jj+1)*z_esigt3(ji,jj+1)+hbatt(ji+1,jj+1)*z_esigt3(ji+1,jj+1) ) / &
+                                     ( hbatt(ji,jj)+hbatt(ji+1,jj)+hbatt(ji,jj+1)+hbatt(ji+1,jj+1) )
+               z_esigwu3(ji,jj) = ( hbatt(ji,jj)*z_esigw3(ji,jj)+hbatt(ji+1,jj)*z_esigw3(ji+1,jj) ) / &
+                                     ( hbatt(ji,jj)+hbatt(ji+1,jj) )
+               z_esigwv3(ji,jj) = ( hbatt(ji,jj)*z_esigw3(ji,jj)+hbatt(ji,jj+1)*z_esigw3(ji,jj+1) ) / &
+                                     ( hbatt(ji,jj)+hbatt(ji,jj+1) )
+
+               e3t_0(ji,jj)=(scosrf(ji,jj)+hbatt(ji,jj))*z_esigt3(ji,jj)
+               e3u_0(ji,jj)=(scosrf(ji,jj)+hbatu(ji,jj))*z_esigtu3(ji,jj)
+               e3v_0(ji,jj)=(scosrf(ji,jj)+hbatv(ji,jj))*z_esigtv3(ji,jj)
+               e3f_0(ji,jj)=(scosrf(ji,jj)+hbatf(ji,jj))*z_esigtf3(ji,jj)
+               !
+               e3w_0(ji,jj)=hbatt(ji,jj)*z_esigw3(ji,jj)
+               e3uw_0(ji,jj)=hbatu(ji,jj)*z_esigwu3(ji,jj)
+               e3vw_0(ji,jj)=hbatv(ji,jj)*z_esigwv3(ji,jj)
+            ENDDO
+         ENDDO
+         ! Keep some arrays for next level
+         z_gsigt3m1 = z_gsigt3
+         z_gsi3w3m1 = z_gsi3w3
+ 
+         where (e3t_0   (:,:).eq.0.0)  e3t_0(:,:) = 1.0
+         where (e3u_0   (:,:).eq.0.0)  e3u_0(:,:) = 1.0
+         where (e3v_0   (:,:).eq.0.0)  e3v_0(:,:) = 1.0
+         where (e3f_0   (:,:).eq.0.0)  e3f_0(:,:) = 1.0
+         where (e3w_0   (:,:).eq.0.0)  e3w_0(:,:) = 1.0
+         where (e3uw_0  (:,:).eq.0.0)  e3uw_0(:,:) = 1.0
+         where (e3vw_0  (:,:).eq.0.0)  e3vw_0(:,:) = 1.0
+         
+         CALL write_netcdf_3d_vars(jk)
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+                  IF( scobot(ji,jj) >= gdept_0(ji,jj) )   mbathy(ji,jj) = MAX( 2, jk )
+                  IF( scobot(ji,jj) == 0.             )   mbathy(ji,jj) = 0
+            END DO
+         END DO
+
+      ENDDO ! End of loop over jk
+
+      DEALLOCATE( z_gsigw3, z_gsigt3, z_gsi3w3, z_gsigw3p1, z_gsigt3m1, z_gsi3w3m1)
+      DEALLOCATE( z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3 )
+
+   END SUBROUTINE s_sf12
+
+   SUBROUTINE s_tanh()
+
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE s_tanh*** 
+      !!                     
+      !! ** Purpose :   stretch the s-coordinate system
+      !!
+      !! ** Method  :   s-coordinate stretch 
+      !!
+      !! Reference : Madec, Lott, Delecluse and Crepon, 1996. JPO, 26, 1393-1408.
+      !!----------------------------------------------------------------------
+
+      USE utils
+      REAL(wp) ::   zcoeft, zcoefw   ! temporary scalars
+
+      REAL(wp), ALLOCATABLE, DIMENSION(:) :: z_gsigw, z_gsigt, z_gsi3w
+      REAL(wp), ALLOCATABLE, DIMENSION(:) :: z_esigt, z_esigw
+
+      ALLOCATE( z_gsigw(jpk), z_gsigt(jpk), z_gsi3w(jpk) )
+      ALLOCATE( z_esigt(jpk), z_esigw(jpk) )
+
+      z_gsigw  = 0.   ;   z_gsigt  = 0.   ;   z_gsi3w  = 0.
+      z_esigt  = 0.   ;   z_esigw  = 0. 
+
+      DO jk = 1, jpk
+        z_gsigw(jk) = -fssig( REAL(jk,wp)-0.5 )
+        z_gsigt(jk) = -fssig( REAL(jk,wp)        )
+      END DO
+      WRITE(*,*) 'z_gsigw 1 jpk    ', z_gsigw(1), z_gsigw(jpk)
+      !
+      ! Coefficients for vertical scale factors at w-, t- levels
+!!gm bug :  define it from analytical function, not like juste bellow....
+!!gm        or betteroffer the 2 possibilities....
+      DO jk = 1, jpk-1
+         z_esigt(jk  ) = z_gsigw(jk+1) - z_gsigw(jk)
+         z_esigw(jk+1) = z_gsigt(jk+1) - z_gsigt(jk)
+      END DO
+      z_esigw( 1 ) = 2. * ( z_gsigt(1  ) - z_gsigw(1  ) ) 
+      z_esigt(jpk) = 2. * ( z_gsigt(jpk) - z_gsigw(jpk) )
+      !
+      ! Coefficients for vertical depth as the sum of e3w scale factors
+      z_gsi3w(1) = 0.5 * z_esigw(1)
+      DO jk = 2, jpk
+         z_gsi3w(jk) = z_gsi3w(jk-1) + z_esigw(jk)
+      END DO
+!!gm: e3uw, e3vw can be suppressed  (modif in dynzdf, dynzdf_iso, zdfbfr) (save 2 3D arrays)
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+              zcoeft = ( REAL(jk,wp) - 0.5 ) / REAL(jpk-1,wp)
+              zcoefw = ( REAL(jk,wp) - 1.0 ) / REAL(jpk-1,wp)
+              gdept_0(ji,jj) = ( scosrf(ji,jj) + (hbatt(ji,jj)-hift(ji,jj))*z_gsigt(jk) + hift(ji,jj)*zcoeft )
+              gdepw_0(:,:) = ( scosrf(ji,jj) + (hbatt(ji,jj)-hift(ji,jj))*z_gsigw(jk) + hift(ji,jj)*zcoefw )
+              gdep3w_0(:,:) = ( scosrf(ji,jj) + (hbatt(ji,jj)-hift(ji,jj))*z_gsi3w(jk) + hift(ji,jj)*zcoeft )
+              e3t_0(ji,jj) = ( (hbatt(ji,jj)-hift(ji,jj))*z_esigt(jk) + hift(ji,jj)/REAL(jpk-1,wp) )
+              e3u_0(ji,jj) = ( (hbatu(ji,jj)-hifu(ji,jj))*z_esigt(jk) + hifu(ji,jj)/REAL(jpk-1,wp) )
+              e3v_0(ji,jj) = ( (hbatv(ji,jj)-hifv(ji,jj))*z_esigt(jk) + hifv(ji,jj)/REAL(jpk-1,wp) )
+              e3f_0(ji,jj) = ( (hbatf(ji,jj)-hiff(ji,jj))*z_esigt(jk) + hiff(ji,jj)/REAL(jpk-1,wp) )
+              !
+              e3w_0(ji,jj) = ( (hbatt(ji,jj)-hift(ji,jj))*z_esigw(jk) + hift(ji,jj)/REAL(jpk-1,wp) )
+              e3uw_0(ji,jj) = ( (hbatu(ji,jj)-hifu(ji,jj))*z_esigw(jk) + hifu(ji,jj)/REAL(jpk-1,wp) )
+              e3vw_0(ji,jj) = ( (hbatv(ji,jj)-hifv(ji,jj))*z_esigw(jk) + hifv(ji,jj)/REAL(jpk-1,wp) )
+              IF( scobot(ji,jj) >= gdept_0(ji,jj) )   mbathy(ji,jj) = MAX( 2, jk )
+              IF( scobot(ji,jj) == 0.             )   mbathy(ji,jj) = 0
+            END DO
+         END DO
+         where (e3t_0   (:,:).eq.0.0)  e3t_0(:,:) = 1.0
+         where (e3u_0   (:,:).eq.0.0)  e3u_0(:,:) = 1.0
+         where (e3v_0   (:,:).eq.0.0)  e3v_0(:,:) = 1.0
+         where (e3f_0   (:,:).eq.0.0)  e3f_0(:,:) = 1.0
+         where (e3w_0   (:,:).eq.0.0)  e3w_0(:,:) = 1.0
+         where (e3uw_0  (:,:).eq.0.0)  e3uw_0(:,:) = 1.0
+         where (e3vw_0  (:,:).eq.0.0)  e3vw_0(:,:) = 1.0
+ 
+         CALL write_netcdf_3d_vars(jk)
+      ENDDO ! End of loop over jk
+
+
+      DEALLOCATE( z_gsigw, z_gsigt, z_gsi3w )
+      DEALLOCATE( z_esigt, z_esigw )
+
+   END SUBROUTINE s_tanh
Index: /trunk/NEMOGCM/TOOLS/SCOORD_GEN/src/utils.F90
===================================================================
--- /trunk/NEMOGCM/TOOLS/SCOORD_GEN/src/utils.F90	(revision 6140)
+++ /trunk/NEMOGCM/TOOLS/SCOORD_GEN/src/utils.F90	(revision 6140)
@@ -0,0 +1,330 @@
+MODULE utils
+
+   USE netcdf
+
+   IMPLICIT NONE
+   PUBLIC             ! allows the acces to par_oce when dom_oce is used
+   !                  ! exception to coding rules... to be suppressed ???
+
+!   PUBLIC dom_oce_alloc
+
+   INTEGER, PARAMETER   :: dp=8 , sp=4, wp=dp
+
+   !! All coordinates
+   !! ---------------
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   gdep3w_0           !: depth of t-points (sum of e3w) (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   gdept_0, gdepw_0   !: analytical (time invariant) depth at t-w  points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   gphit              !: latitude at t points
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   e3v_0  , e3f_0     !: analytical (time invariant) vertical scale factors at  v-f
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   e3t_0  , e3u_0     !:                                      t-u  points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   e3vw_0             !: analytical (time invariant) vertical scale factors at  vw
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   e3w_0  , e3uw_0    !:                                      w-uw points (m)
+
+   !! s-coordinate and hybrid z-s-coordinate
+   !! =----------------======---------------
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hbatv , hbatf      !: ocean depth at the vertical of  v--f
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hbatt , hbatu      !:                                 t--u points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   scosrf, scobot     !: ocean surface and bottom topographies 
+   !                                                                           !  (if deviating from coordinate surfaces in HYBRID)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hifv  , hiff       !: interface depth between stretching at v--f
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hift  , hifu       !: and quasi-uniform spacing             t--u points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rx1                !: Maximum grid stiffness ratio
+
+   !!----------------------------------------------------------------------
+   !! masks, bathymetry
+   !! ---------------------------------------------------------------------
+   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbathy             !: number of ocean level (=0, 1, ... , jpk-1)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bathy              !: ocean depth (meters - read from file)
+
+   !! Other variables needed by scoord_gen
+   INTEGER  ::   jpi, jpj, jpk            ! Size of the domain - read from bathy or namelist?
+   INTEGER  ::   ji, jj, jk, jl           ! dummy loop argument
+   INTEGER  ::   iip1, ijp1, iim1, ijm1   ! temporary integers
+   INTEGER  ::   ios                      ! Local integer output status for namelist read and allocation
+   INTEGER,PARAMETER  ::   numnam=8       ! File handle for namelist 
+   REAL(wp) ::   zrmax, ztaper   ! temporary scalars
+   REAL(wp) ::   zrfact
+   !
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: ztmpi1, ztmpi2, ztmpj1, ztmpj2
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zenv, ztmp, zmsk, zri, zrj, zhbat
+
+   !Namelist variables
+   REAL(wp) :: rn_jpk, rn_sbot_min, rn_sbot_max, rn_hc, rn_rmax, rn_theta
+   REAL(wp) :: rn_thetb, rn_bb, rn_alpha, rn_efold, rn_zs, rn_zb_a, rn_zb_b
+   LOGICAL :: ln_s_sh94, ln_s_sf12, ln_sigcrit, ln_eq_taper
+   CHARACTER(len=50) :: cn_coord_hgr
+
+   NAMELIST/namzgr_sco/rn_jpk, ln_s_sh94, ln_s_sf12, ln_sigcrit, ln_eq_taper, & 
+                  &      cn_coord_hgr, rn_sbot_min, rn_sbot_max, rn_hc, rn_rmax,rn_theta, &
+                  &      rn_thetb, rn_bb, rn_alpha, rn_efold, rn_zs, rn_zb_a, rn_zb_b
+
+  ! IDs for output netcdf file
+  INTEGER :: id_x, id_y, id_z
+  INTEGER :: ncout
+  INTEGER, DIMENSION(20) :: var_ids  !Array to contain all variable IDs
+
+   CONTAINS
+
+   INTEGER FUNCTION dom_oce_alloc()
+      !!----------------------------------------------------------------------
+      INTEGER, DIMENSION(4) :: ierr
+      !!----------------------------------------------------------------------
+      ierr(:) = 0
+      !
+      ALLOCATE( zenv(jpi,jpj), ztmp(jpi,jpj), zmsk(jpi,jpj), zri(jpi,jpj), zrj(jpi,jpj), &
+         &      zhbat(jpi,jpj) , ztmpi1(jpi,jpj), ztmpi2(jpi,jpj), ztmpj1(jpi,jpj), ztmpj2(jpi,jpj), STAT=ierr(1) )
+         !
+      ALLOCATE( gdep3w_0(jpi,jpj) , e3v_0(jpi,jpj) , e3f_0(jpi,jpj) ,                         &
+         &      gdept_0(jpi,jpj) , e3t_0(jpi,jpj) , e3u_0 (jpi,jpj) ,                         &
+         &      gdepw_0(jpi,jpj) , e3w_0(jpi,jpj) , e3vw_0(jpi,jpj) ,                         &
+         &      gphit(jpi,jpj)   , e3uw_0(jpi,jpj) , STAT=ierr(2) )
+         !
+         !
+      ALLOCATE( hbatv (jpi,jpj) , hbatf (jpi,jpj) ,     &
+         &      hbatt (jpi,jpj) , hbatu (jpi,jpj) ,     &
+         &      scosrf(jpi,jpj) , scobot(jpi,jpj) ,     &
+         &      hifv  (jpi,jpj) , hiff  (jpi,jpj) ,     &
+         &      hift  (jpi,jpj) , hifu  (jpi,jpj) , rx1 (jpi,jpj) , STAT=ierr(3) )
+
+      ALLOCATE( mbathy(jpi,jpj) , STAT=ierr(4) )
+     !
+      dom_oce_alloc = MAXVAL(ierr)
+      !
+   END FUNCTION dom_oce_alloc
+ 
+
+   SUBROUTINE read_bathy()
+     !! Read bathymetry from input netcdf file
+     INTEGER :: var_id, ncin
+
+     CALL check_nf90( nf90_open('bathy_meter.nc', NF90_NOWRITE, ncin), 'Error opening bathy_meter.nc file' )
+
+     ! Find the size of the input bathymetry
+     CALL dimlen(ncin, 'lon', jpi)    
+     CALL dimlen(ncin, 'lat', jpj)    
+     
+     ALLOCATE( bathy(jpi, jpj) )
+     
+     ! Read the bathymetry variable from file
+     CALL check_nf90( nf90_inq_varid( ncin, 'Bathymetry', var_id ), 'Cannot get variable ID for bathymetry')
+     CALL check_nf90( nf90_get_var( ncin, var_id, bathy, (/ 1,1 /), (/ jpi, jpj /) ) )
+
+     CALL check_nf90( nf90_close(ncin), 'Error closing bathy.nc file' )
+
+   END SUBROUTINE read_bathy
+
+   SUBROUTINE read_gphit()
+   !! Read gphit from horizontal coordinate file if required
+     INTEGER :: var_id, ncin
+
+     CALL check_nf90( nf90_open(cn_coord_hgr, NF90_NOWRITE, ncin), 'Error opening horizontal coordinate file' )
+
+     ! Read gphit variable from file
+     CALL check_nf90( nf90_inq_varid( ncin, 'gphit', var_id ), 'Cannot get variable ID for bathymetry')
+     CALL check_nf90( nf90_get_var( ncin, var_id, gphit, (/ 1,1 /), (/ jpi, jpj /) ) )
+
+     CALL check_nf90( nf90_close(ncin), 'Error closing horizontal coordinate file' )
+
+   END SUBROUTINE read_gphit
+
+   SUBROUTINE dimlen( ncid, dimname, len )
+     ! Determine the length of dimension dimname
+     INTEGER, INTENT(in)          :: ncid
+     CHARACTER(LEN=*), INTENT(in) :: dimname
+     INTEGER, INTENT(out)         :: len
+     ! Local variables
+     INTEGER :: id_var
+
+     id_var = 1
+     CALL check_nf90( nf90_inq_dimid(ncid, dimname, id_var), 'Dimension not found in file')
+     CALL check_nf90( nf90_inquire_dimension(ncid,id_var,len=len))
+
+   END SUBROUTINE dimlen
+  
+ 
+   SUBROUTINE make_coord_file()
+     ! Create new coordinates file and define dimensions and variables ready for
+     ! writing
+     
+
+     !Create the file
+     CALL check_nf90( nf90_create('coord_zgr.nc', NF90_NETCDF4, ncout), 'Could not create output file')
+     !
+     !Define dimensions
+     CALL check_nf90( nf90_def_dim(ncout, 'x', jpi, id_x) )
+     CALL check_nf90( nf90_def_dim(ncout, 'y', jpj, id_y) )
+     CALL check_nf90( nf90_def_dim(ncout, 'z', jpk, id_z) )
+     !
+     !Define variables - include all varibles that would be put into the mesh
+     !mask file
+     CALL check_nf90( nf90_def_var(ncout, 'gdept_0', nf90_double, (/id_x, id_y,id_z/), var_ids(1)) )
+     CALL check_nf90( nf90_def_var(ncout, 'gdepw_0', nf90_double, (/id_x, id_y,id_z/), var_ids(2)) )
+     CALL check_nf90( nf90_def_var(ncout, 'gdep3w_0', nf90_double, (/id_x, id_y,id_z/), var_ids(3)) )
+     CALL check_nf90( nf90_def_var(ncout, 'e3f_0', nf90_double, (/id_x, id_y,id_z/), var_ids(4)) )
+     CALL check_nf90( nf90_def_var(ncout, 'e3t_0', nf90_double, (/id_x, id_y,id_z/), var_ids(5)) )
+     CALL check_nf90( nf90_def_var(ncout, 'e3u_0', nf90_double, (/id_x, id_y,id_z/), var_ids(6)) )
+     CALL check_nf90( nf90_def_var(ncout, 'e3v_0', nf90_double, (/id_x, id_y,id_z/), var_ids(7)) )
+     CALL check_nf90( nf90_def_var(ncout, 'e3w_0', nf90_double, (/id_x, id_y,id_z/), var_ids(8)) )
+     CALL check_nf90( nf90_def_var(ncout, 'e3uw_0', nf90_double, (/id_x, id_y,id_z/), var_ids(9)) )
+     CALL check_nf90( nf90_def_var(ncout, 'e3vw_0', nf90_double, (/id_x, id_y,id_z/), var_ids(10)) )
+     ! 2D fields
+     CALL check_nf90( nf90_def_var(ncout, 'mbathy', nf90_double, (/id_x, id_y/), var_ids(11)) )
+     CALL check_nf90( nf90_def_var(ncout, 'hbatt', nf90_double, (/id_x, id_y/), var_ids(12)) )
+     CALL check_nf90( nf90_def_var(ncout, 'hbatu', nf90_double, (/id_x, id_y/), var_ids(13)) )
+     CALL check_nf90( nf90_def_var(ncout, 'hbatv', nf90_double, (/id_x, id_y/), var_ids(14)) )
+     CALL check_nf90( nf90_def_var(ncout, 'hbatf', nf90_double, (/id_x, id_y/), var_ids(15)) )
+     CALL check_nf90( nf90_def_var(ncout, 'rx1', nf90_double, (/id_x, id_y/), var_ids(16)) )
+
+     
+     ! End define mode
+     CALL check_nf90( nf90_enddef(ncout) )
+     
+     WRITE(*,*) 'Opened coord_zgr.nc file and defined variables'
+
+   END SUBROUTINE make_coord_file
+
+   SUBROUTINE write_netcdf_2d_vars()
+
+     CALL check_nf90( nf90_put_var(ncout, var_ids(11), mbathy, (/ 1,1 /), (/ jpi, jpj /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(12), hbatt, (/ 1,1 /), (/ jpi, jpj /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(13), hbatu, (/ 1,1 /), (/ jpi, jpj /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(14), hbatv, (/ 1,1 /), (/ jpi, jpj /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(15), hbatf, (/ 1,1 /), (/ jpi, jpj /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(16), rx1, (/ 1,1 /), (/ jpi, jpj /) ) )
+
+   END SUBROUTINE write_netcdf_2d_vars
+
+   SUBROUTINE write_netcdf_3d_vars(kk)
+   ! Write  variables to the netcdf file at level kk
+     INTEGER, INTENT(in) :: kk
+
+     CALL check_nf90( nf90_put_var(ncout, var_ids(1), gdept_0, (/ 1,1,kk /), (/ jpi, jpj,1 /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(2), gdepw_0, (/ 1,1,kk /), (/ jpi, jpj,1 /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(3), gdep3w_0, (/ 1,1,kk /), (/ jpi, jpj,1 /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(4), e3f_0, (/ 1,1,kk /), (/ jpi, jpj,1 /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(5), e3t_0, (/ 1,1,kk /), (/ jpi, jpj,1 /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(6), e3u_0, (/ 1,1,kk /), (/ jpi, jpj,1 /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(7), e3v_0, (/ 1,1,kk /), (/ jpi, jpj,1 /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(8), e3w_0, (/ 1,1,kk /), (/ jpi, jpj,1 /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(9), e3uw_0, (/ 1,1,kk /), (/ jpi, jpj,1 /) ) )
+     CALL check_nf90( nf90_put_var(ncout, var_ids(10), e3vw_0, (/ 1,1,kk /), (/ jpi, jpj,1 /) ) )
+
+   END SUBROUTINE write_netcdf_3d_vars
+
+   SUBROUTINE check_nf90( istat, message )
+      !Check for netcdf errors
+      INTEGER, INTENT(in) :: istat
+      CHARACTER(LEN=*), INTENT(in), OPTIONAL :: message
+
+      IF (istat /= nf90_noerr) THEN
+         WRITE(*,*) 'ERROR! : '//TRIM(nf90_strerror(istat))
+         IF ( PRESENT(message) ) THEN ; WRITE(*,*) message ; ENDIF
+         STOP
+      ENDIF
+
+   END SUBROUTINE check_nf90
+   FUNCTION fssig( pk ) RESULT( pf )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE fssig ***
+      !!       
+      !! ** Purpose :   provide the analytical function in s-coordinate
+      !!          
+      !! ** Method  :   the function provide the non-dimensional position of
+      !!                T and W (i.e. between 0 and 1)
+      !!                T-points at integer values (between 1 and jpk)
+      !!                W-points at integer values - 1/2 (between 0.5 and jpk-0.5)
+      !!----------------------------------------------------------------------
+!     USE utils, ONLY : wp,rn_theta,rn_thetb,jpk
+      IMPLICIT NONE
+      REAL(wp), INTENT(in) ::   pk   ! continuous "k" coordinate
+      REAL(wp)             ::   pf   ! sigma value
+      !!----------------------------------------------------------------------
+      !
+      pf =   (   TANH( rn_theta * ( -(pk-0.5) / REAL(jpk-1) + rn_thetb )  )   &
+         &     - TANH( rn_thetb * rn_theta                                )  )   &
+         & * (   COSH( rn_theta                           )                      &
+         &     + COSH( rn_theta * ( 2. * rn_thetb - 1. ) )  )              &
+         & / ( 2. * SINH( rn_theta ) )
+      !
+   END FUNCTION fssig
+
+   FUNCTION fssig1( pk1, pbb ) RESULT( pf1 )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE fssig1 ***
+      !!
+      !! ** Purpose :   provide the Song and Haidvogel version of the analytical function in s-coordinate
+      !!
+      !! ** Method  :   the function provides the non-dimensional position of
+      !!                T and W (i.e. between 0 and 1)
+      !!                T-points at integer values (between 1 and jpk)
+      !!                W-points at integer values - 1/2 (between 0.5 and jpk-0.5)
+      !!----------------------------------------------------------------------
+!     USE utils, ONLY : wp, jpk, rn_theta
+      IMPLICIT NONE
+      REAL(wp), INTENT(in) ::   pk1   ! continuous "k" coordinate
+      REAL(wp), INTENT(in) ::   pbb   ! Stretching coefficient
+      REAL(wp)             ::   pf1   ! sigma value
+      !!----------------------------------------------------------------------
+      !
+      IF ( rn_theta == 0 ) then      ! uniform sigma
+         pf1 = - ( pk1 - 0.5 ) / REAL( jpk-1 )
+      ELSE                        ! stretched sigma
+         pf1 =   ( 1. - pbb ) * ( SINH( rn_theta*(-(pk1-0.5)/REAL(jpk-1)) ) ) / SINH( rn_theta )              &
+            &  + pbb * (  (TANH( rn_theta*( (-(pk1-0.5)/REAL(jpk-1)) + 0.5) ) - TANH( 0.5 * rn_theta )  )  &
+            &        / ( 2. * TANH( 0.5 * rn_theta ) )  )
+      ENDIF
+      !
+   END FUNCTION fssig1
+
+   FUNCTION fgamma( pk1, pzb, pzs, psmth) RESULT( p_gamma )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE fgamma  ***
+      !!
+      !! ** Purpose :   provide analytical function for the s-coordinate
+      !!
+      !! ** Method  :   the function provides the non-dimensional position of
+      !!                T and W (i.e. between 0 and 1)
+      !!                T-points at integer values (between 1 and jpk)
+      !!                W-points at integer values - 1/2 (between 0.5 and jpk-0.5)
+      !!
+      !!                This method allows the maintenance of fixed surface and or
+      !!                bottom cell resolutions (cf. geopotential coordinates) 
+      !!                within an analytically derived stretched S-coordinate framework.
+      !!
+      !! Reference  :   Siddorn and Furner, in prep
+      !!----------------------------------------------------------------------
+!     USE utils, ONLY : jpk,wp,rn_alpha
+      IMPLICIT NONE
+      REAL(wp), INTENT(in   ) ::   pk1           ! continuous "k" coordinate
+      REAL(wp)                ::   p_gamma       ! stretched coordinate
+      REAL(wp), INTENT(in   ) ::   pzb           ! Bottom box depth
+      REAL(wp), INTENT(in   ) ::   pzs           ! surface box depth
+      REAL(wp), INTENT(in   ) ::   psmth         ! Smoothing parameter
+      REAL(wp)                ::   za1,za2,za3   ! local variables
+      REAL(wp)                ::   zn1,zn2       ! local variables
+      REAL(wp)                ::   za,zb,zx      ! local variables
+      !!----------------------------------------------------------------------
+      !
+
+      zn1  =  1./(jpk-1.)
+      zn2  =  1. -  zn1
+
+      za1 = (rn_alpha+2.0)*zn1**(rn_alpha+1.0)-(rn_alpha+1.0)*zn1**(rn_alpha+2.0) 
+      za2 = (rn_alpha+2.0)*zn2**(rn_alpha+1.0)-(rn_alpha+1.0)*zn2**(rn_alpha+2.0)
+      za3 = (zn2**3.0 - za2)/( zn1**3.0 - za1)
+     
+      za = pzb - za3*(pzs-za1)-za2
+      za = za/( zn2-0.5*(za2+zn2**2.0) - za3*(zn1-0.5*(za1+zn1**2.0) ) )
+      zb = (pzs - za1 - za*( zn1-0.5*(za1+zn1**2.0 ) ) ) / (zn1**3.0 - za1)
+      zx = 1.0-za/2.0-zb
+
+      p_gamma = za*(pk1*(1.0-pk1/2.0))+zb*pk1**3.0 +  &
+                  & zx*( (rn_alpha+2.0)*pk1**(rn_alpha+1.0)- &
+                  &      (rn_alpha+1.0)*pk1**(rn_alpha+2.0) )
+      p_gamma = p_gamma*psmth+pk1*(1.0-psmth)
+
+      !
+   END FUNCTION fgamma
+
+
+END MODULE utils
Index: /trunk/NEMOGCM/TOOLS/SIREN/cfg/variable.cfg
===================================================================
--- /trunk/NEMOGCM/TOOLS/SIREN/cfg/variable.cfg	(revision 6139)
+++ /trunk/NEMOGCM/TOOLS/SIREN/cfg/variable.cfg	(revision 6140)
@@ -43,5 +43,4 @@
 kt           |                |      |   |                 |                                       |                                  
 rdt          |                |      |   |                 |                                       |                                  
-rdttra1      |                |      |   |                 |                                       |                                  
 utau_b       |                | XY   | U |                 |                                       |surface_downward_eastward_stress  
 vtau_b       |                | XY   | V |                 |                                       |surface_downward_northward_stress 
Index: /trunk/NEMOGCM/fcm-make/inc/keys-amm12.cfg
===================================================================
--- /trunk/NEMOGCM/fcm-make/inc/keys-amm12.cfg	(revision 6139)
+++ /trunk/NEMOGCM/fcm-make/inc/keys-amm12.cfg	(revision 6140)
@@ -1,2 +1,2 @@
 preprocess.prop{fpp.defs} = \
-  key_bdy key_tide key_ldfslp key_zdfgls key_vvl key_diainstant key_mpp_mpi key_iomput
+  key_bdy key_tide key_dynspg_ts key_ldfslp key_zdfgls key_vvl key_diainstant key_mpp_mpi key_iomput
Index: /trunk/NEMOGCM/fcm-make/inc/keys-gyre.cfg
===================================================================
--- /trunk/NEMOGCM/fcm-make/inc/keys-gyre.cfg	(revision 6139)
+++ /trunk/NEMOGCM/fcm-make/inc/keys-gyre.cfg	(revision 6140)
@@ -1,2 +1,2 @@
 preprocess.prop{fpp.defs} = \
-  key_ldfslp key_zdftke key_iomput key_mpp_mpi key_nosignedzero
+  key_dynspg_flt key_ldfslp key_zdftke key_iomput key_mpp_mpi key_nosignedzero
Index: /trunk/NEMOGCM/fcm-make/inc/keys-gyre_pisces.cfg
===================================================================
--- /trunk/NEMOGCM/fcm-make/inc/keys-gyre_pisces.cfg	(revision 6139)
+++ /trunk/NEMOGCM/fcm-make/inc/keys-gyre_pisces.cfg	(revision 6140)
@@ -1,2 +1,2 @@
 preprocess.prop{fpp.defs} = \
-  key_ldfslp key_zdftke key_top key_pisces_reduced key_iomput key_mpp_mpi
+  key_dynspg_flt key_ldfslp key_zdftke key_top key_pisces_reduced key_iomput key_mpp_mpi
Index: /trunk/NEMOGCM/fcm-make/inc/keys-orca2_lim.cfg
===================================================================
--- /trunk/NEMOGCM/fcm-make/inc/keys-orca2_lim.cfg	(revision 6139)
+++ /trunk/NEMOGCM/fcm-make/inc/keys-orca2_lim.cfg	(revision 6140)
@@ -1,2 +1,2 @@
 preprocess.prop{fpp.defs} = \
-  key_trabbl key_lim2 key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_zdftke key_zdfddm key_zdftmx key_iomput key_mpp_mpi key_diaobs key_asminc
+  key_trabbl key_lim2 key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_zdftke key_zdfddm key_zdftmx key_iomput key_mpp_mpi key_asminc
Index: /trunk/NEMOGCM/fcm-make/inc/keys-orca2_lim3.cfg
===================================================================
--- /trunk/NEMOGCM/fcm-make/inc/keys-orca2_lim3.cfg	(revision 6139)
+++ /trunk/NEMOGCM/fcm-make/inc/keys-orca2_lim3.cfg	(revision 6140)
@@ -1,2 +1,2 @@
 preprocess.prop{fpp.defs} = \
-  key_trabbl key_lim3 key_vvl key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_zdftke key_zdfddm key_zdftmx key_iomput key_mpp_mpi key_diaobs key_asminc
+  key_trabbl key_lim3 key_vvl key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_zdftke key_zdfddm key_zdftmx key_iomput key_mpp_mpi key_asminc
Index: /trunk/NEMOGCM/fcm-make/inc/keys-orca2_lim_cfc.cfg
===================================================================
--- /trunk/NEMOGCM/fcm-make/inc/keys-orca2_lim_cfc.cfg	(revision 6139)
+++ /trunk/NEMOGCM/fcm-make/inc/keys-orca2_lim_cfc.cfg	(revision 6140)
@@ -1,2 +1,2 @@
 preprocess.prop{fpp.defs} = \
-  key_trabbl key_lim2 key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_zdftke key_zdfddm key_zdftmx key_top key_cfc key_c14b key_iomput key_mpp_mpi
+  key_trabbl key_lim2 key_dynspg_flt key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_zdftke key_zdfddm key_zdftmx key_top key_cfc key_c14b key_iomput key_mpp_mpi
Index: /trunk/NEMOGCM/fcm-make/inc/keys-orca2_lim_pisces.cfg
===================================================================
--- /trunk/NEMOGCM/fcm-make/inc/keys-orca2_lim_pisces.cfg	(revision 6139)
+++ /trunk/NEMOGCM/fcm-make/inc/keys-orca2_lim_pisces.cfg	(revision 6140)
@@ -1,2 +1,2 @@
 preprocess.prop{fpp.defs} = \
-  key_trabbl key_lim2 key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_zdftke key_zdfddm key_zdftmx key_top key_pisces key_iomput key_mpp_mpi
+  key_trabbl key_lim2 key_dynspg_flt key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_zdftke key_zdfddm key_zdftmx key_top key_pisces key_iomput key_mpp_mpi
Index: /trunk/NEMOGCM/fcm-make/inc/keys-orca2_sas_lim.cfg
===================================================================
--- /trunk/NEMOGCM/fcm-make/inc/keys-orca2_sas_lim.cfg	(revision 6139)
+++ /trunk/NEMOGCM/fcm-make/inc/keys-orca2_sas_lim.cfg	(revision 6140)
@@ -1,2 +1,2 @@
 preprocess.prop{fpp.defs} = \
-  key_trabbl key_lim2 key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_zdftke key_zdfddm key_zdftmx key_iomput key_mpp_mpi
+  key_trabbl key_lim2 key_dynspg_flt key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_zdftke key_zdfddm key_zdftmx key_iomput key_mpp_mpi
