Index: branches/2013/dev_MERCATOR_UKMO_2013/DOC/TexFiles/Chapters/Chap_OBS.tex
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/DOC/TexFiles/Chapters/Chap_OBS.tex	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/DOC/TexFiles/Chapters/Chap_OBS.tex	(revision 4229)
@@ -5,5 +5,5 @@
 \label{OBS}
 
-Authors: D. Lea, M. Martin, K. Mogensen, A. Vidard, A. Weaver...   % do we keep that ?
+Authors: D. Lea, M. Martin, K. Mogensen, A. Vidard, A. Weaver, A. Ryan, ...   % do we keep that ?
 
 \minitoc
@@ -42,8 +42,9 @@
 where to obtain data and how to setup the namelist. Section~\ref{OBS_details} introduces some
 more technical details of the different observation types used and also shows a more complete
-namelist. Section~\ref{OBS_theory} introduces some of the theoretical aspects of the
-observation operator including interpolation methods and running on multiple processors.
-Section~\ref{OBS_obsutils} introduces some utilities to help working with the files produced
-by the OBS code.
+namelist. Section~\ref{OBS_theory} introduces some of the theoretical aspects of the observation
+operator including interpolation methods and running on multiple processors.
+Section~\ref{OBS_ooo} describes the offline observation operator code.
+Section~\ref{OBS_obsutils} introduces some utilities to help working with the files
+produced by the OBS code.
 
 % ================================================================
@@ -786,4 +787,367 @@
 \newpage
 
+% ================================================================
+% Offline observation operator documentation
+% ================================================================
+
+%\usepackage{framed}
+
+\section{Offline observation operator}
+\label{OBS_ooo}
+
+\subsection{Concept}
+
+The obs oper maps model variables to observation space. It is possible to apply this mapping
+without running the model. The software which performs this functionality is known as the
+\textbf{offline obs oper}. The obs oper is divided into three stages. An initialisation phase,
+an interpolation phase and an output phase. The implementation of which is outlined in the
+previous sections. During the interpolation phase the offline obs oper populates the model
+arrays by reading saved model fields from disk.
+
+There are two ways of exploiting this offline capacity. The first is to mimic the behaviour of
+the online system by supplying model fields at regular intervals between the start and the end
+of the run. This approach results in a single model counterpart per observation. This kind of
+usage produces feedback files the same file format as the online obs oper. 
+The second is to take advantage of the offline setting in which multiple model counterparts can
+be calculated per observation. In this case it is possible to consider all forecasts verifying
+at the same time. By forecast, I mean any method which produces an estimate of physical reality
+which is not an observed value. In the case of class 4 files this means forecasts, analyses, persisted
+analyses and climatological values verifying at the same time. Although the class 4 file format
+doesn't account for multiple ensemble members or multiple experiments per observation, it is possible
+to include these components in the same or multiple files.
+
+%--------------------------------------------------------------------------------------------------------
+% offline_oper.exe 
+%--------------------------------------------------------------------------------------------------------
+
+\subsection{Using the offline observation operator}
+
+\subsubsection{Building}
+
+In addition to \emph{OPA\_SRC} the offline obs oper requires the inclusion
+of the \emph{OOO\_SRC} directory. \emph{OOO\_SRC} contains a replacement \textbf{nemo.f90} and
+\textbf{nemogcm.F90} which overwrites the resultant \textbf{nemo.exe}. This is the approach taken
+by \emph{SAS\_SRC} and \emph{OFF\_SRC}.
+
+%--------------------------------------------------------------------------------------------------------
+% Running 
+%--------------------------------------------------------------------------------------------------------
+\subsubsection{Running}
+
+The simplest way to use the executable is to edit and append the \textbf{ooo.nml} namelist to
+a full NEMO namelist and then to run the executable as if it were nemo.exe. 
+
+\subsubsection{Quick script}
+
+A useful Python utility to control the namelist options can be found in \textbf{OBSTOOLS/OOO}. The
+functions which locate model fields and observation files can be manually specified. The package
+can be installed by appropriate use of the included setup.py script.
+
+Documentation can be auto-generated by Sphinx by running \emph{make html} in the \textbf{doc} directory.
+
+%--------------------------------------------------------------------------------------------------------
+% Configuration section
+%--------------------------------------------------------------------------------------------------------
+\subsection{Configuring the offline observation operator}
+The observation files and settings understood by \textbf{namobs} have been outlined in the online
+obs oper section. In addition there are two further namelists wich control the operation of the offline
+obs oper. \textbf{namooo} which controls the input model fields and \textbf{namcl4} which controls the
+production of class 4 files. 
+
+\subsubsection{Single field}
+
+In offline mode model arrays are populated at appropriate time steps via input files.
+At present, \textbf{tsn} and \textbf{sshn} are populated by the default read routines. 
+These routines will be expanded upon in future versions to allow the specification of any
+model variable. As such, input files must be global versions of the model domain with
+\textbf{votemper}, \textbf{vosaline} and optionally \textbf{sshn} present.
+
+For each field read there must be an entry in the \textbf{namooo} namelist specifying the
+name of the file to read and the index along the \emph{time\_counter}. For example, to
+read the second time counter from a single file the namelist would be.
+
+\begin{alltt}
+\tiny
+\begin{verbatim} 
+!----------------------------------------------------------------------
+!       namooo Offline obs_oper namelist
+!----------------------------------------------------------------------
+!   ooo_files    specifies the files containing the model counterpart
+!   nn_ooo_idx   specifies the time_counter index within the model file
+&namooo
+   ooo_files = "foo.nc"
+   nn_ooo_idx = 2
+/
+\end{verbatim} 
+\end{alltt}
+
+\subsubsection{Multiple fields per run}
+
+Model field iteration is controlled via \textbf{nn\_ooo\_freq} which specifies
+the number of model steps at which the next field gets read. For example, if
+12 hourly fields are to be interpolated in a setup where 288 steps equals 24 hours.
+
+\begin{alltt}
+\tiny
+\begin{verbatim} 
+!----------------------------------------------------------------------
+!       namooo Offline obs_oper namelist
+!----------------------------------------------------------------------
+!   ooo_files    specifies the files containing the model counterpart
+!   nn_ooo_idx   specifies the time_counter index within the model file
+!   nn_ooo_freq  specifies number of time steps between read operations
+&namooo
+   ooo_files = "foo.nc" "foo.nc"
+   nn_ooo_idx = 1 2
+   nn_ooo_freq = 144
+/
+\end{verbatim} 
+\end{alltt}
+
+The above namelist will result in feedback files whose first 12 hours contain
+the first field of foo.nc and the second 12 hours contain the second field.
+
+%\begin{framed}
+\textbf{Note} Missing files can be denoted as "nofile".
+%\end{framed}
+
+It is easy to see how a collection of fields taken fron a number of files 
+at different indices can be combined at a particular frequency in time to 
+generate a pseudo model evolution. As long as all that is needed is a single
+model counterpart at a regular interval then namooo is all that needs to
+be edited. However, a far more interesting approach can be taken in which
+multiple forecasts, analyses, persisted analyses and climatologies are
+considered against the same set of observations. For this a slightly more
+complicated approach is needed. It is referred to as \emph{Class 4} since
+it is the fourth metric defined by the GODAE intercomparison project.
+
+%--------------------------------------------------------------------------------------------------------
+% Class 4 file section
+%--------------------------------------------------------------------------------------------------------
+\subsubsection{Multiple model counterparts per observation a.k.a Class 4}
+
+A generalisation of feedback files to allow multiple model components per observation. For a single
+observation, as well as previous forecasts verifying at the same time there are also analyses, persisted
+analyses and climatologies. 
+
+
+The above namelist performs two basic functions. It organises the fields
+given in \textbf{namooo} into groups so that observations can be matched
+up multiple times. It also controls the metadata and the output variable
+of the class 4 file when a write routine is called.
+
+%\begin{framed}
+\textbf{Note: ln\_cl4} must be set to \emph{.TRUE.} in \textbf{namobs} 
+to use class 4 outputs.
+%\end{framed}
+
+\subsubsection{Class 4 naming convention}
+
+The standard class 4 file naming convention is as follows.
+
+\noindent
+\linebreak
+\textbf{\$\{prefix\}\_\$\{yyyymmdd\}\_\$\{sys\}\_\$\{cfg\}\_\$\{vn\}\_\$\{kind\}\_\$\{nproc\}.nc}
+
+\noindent
+\linebreak
+Much of the namelist is devoted to specifying this convention. The
+following namelist settings control the elements of the output
+file names. Each should be specified as a single string of character data.
+
+\begin{description}
+\item[cl4\_prefix]
+Prefix for class 4 files e.g. class4
+\item[cl4\_date]
+YYYYMMDD validity date
+\item[cl4\_sys]
+The name of the class 4 model system e.g. FOAM
+\item[cl4\_cfg]
+The name of the class 4 model configuration e.g. orca025
+\item[cl4\_vn]
+The name of the class 4 model version e.g. 12.0
+\end{description}
+
+\noindent
+The kind is specified by the observation type internally to the obs oper. The processor
+number is specified internally in NEMO. 
+
+\subsubsection{Class 4 file global attributes}
+
+Global attributes necessary to fulfill the class 4 file definition. These
+are also useful pieces of information when collaborating with external
+partners.
+
+\begin{description}
+\item[cl4\_contact]
+Contact email for class 4 files.
+\item[cl4\_inst]
+The name of the producers institution.
+\item[cl4\_cfg]
+The name of the class 4 model configuration e.g. orca025
+\item[cl4\_vn]
+The name of the class 4 model version e.g. 12.0
+\end{description}
+
+\noindent
+The obs\_type,
+creation date and validity time are specified internally to the obs oper.
+
+\subsubsection{Class 4 model counterpart configuration}
+
+As seen previously it is possible to perform a single sweep of the
+obs oper and specify a collection of model fields equally spaced 
+along that sweep. In the class 4 case the single sweep is replaced
+with multiple sweeps and a certain ammount of book keeping is
+needed to ensure each model counterpart makes its way to the 
+correct piece of memory in the output files.
+
+\noindent
+\linebreak
+In terms of book keeping, the offline obs oper needs to know how many
+full sweeps need to be performed. This is specified via the 
+\textbf{cl4\_match\_len} variable and is the total number of model
+counterparts per observation. For example, a 3 forecasts plus 3 persistence
+fields plus an analysis field would be 7 counterparts per observation.
+
+\begin{alltt}
+\tiny
+\begin{verbatim}
+   cl4_match_len = 7
+\end{verbatim}
+\end{alltt}
+
+Then to correctly allocate a class 4 file the forecast axis must be defined. This
+is controlled via \textbf{cl4\_fcst\_len}, which in out above example would be 3.
+
+\begin{alltt}
+\tiny
+\begin{verbatim}
+   cl4_fcst_len = 3
+\end{verbatim}
+\end{alltt}
+
+Then for each model field it is necessary to designate what class 4 variable and
+index along the forecast dimension the model counterpart should be stored in the
+output file. As well as a value for that lead time in hours, this will be useful
+when interpreting the data afterwards. 
+
+\begin{alltt}
+\tiny
+\begin{verbatim}
+   cl4_vars = "forecast" "forecast" "forecast" "persistence" "persistence"
+              "persistence" "best_estimate"
+   cl4_fcst_idx = 1 2 3 1 2 3 1
+   cl4_leadtime = 12 36 60 
+\end{verbatim}
+\end{alltt}
+
+In terms of files and indices of fields inside each file the class 4 approach
+makes use of the \textbf{namooo} namelist. If our fields are in separate files
+with a single field per file our example inputs will be specified.
+
+\begin{alltt}
+\tiny
+\begin{verbatim}
+   ooo_files = "F.1.nc" "F.2.nc" "F.3.nc" "P.1.nc" "P.2.nc" "P.3.nc" "A.1.nc"
+   nn_ooo_idx = 1 1 1 1 1 1 1
+\end{verbatim}
+\end{alltt}
+
+When we combine all of the naming conventions, global attributes and i/o instructions
+the class 4 namelist becomes.
+
+\begin{alltt}
+\tiny
+\begin{verbatim}
+!----------------------------------------------------------------------
+!       namooo Offline obs_oper namelist
+!----------------------------------------------------------------------
+!   ooo_files    specifies the files containing the model counterpart
+!   nn_ooo_idx   specifies the time_counter index within the model file
+!   nn_ooo_freq  specifies number of time steps between read operations
+&namooo
+   ooo_files = "F.1.nc" "F.2.nc" "F.3.nc" "P.1.nc" "P.2.nc" "P.3.nc" "A.1.nc"
+   nn_ooo_idx = 1 1 1 1 1 1 1
+/
+!----------------------------------------------------------------------
+!       namcl4 Offline obs_oper class 4 namelist
+!----------------------------------------------------------------------
+!
+!  Naming convention
+!  -----------------
+!  cl4_prefix    specifies the output file prefix
+!  cl4_date      specifies the output file validity date
+!  cl4_sys       specifies the model counterpart system
+!  cl4_cfg       specifies the model counterpart configuration
+!  cl4_vn        specifies the model counterpart version
+!  cl4_inst      specifies the model counterpart institute
+!  cl4_contact   specifies the file producers contact details
+!
+!  I/O specification
+!  -----------------
+!  cl4_vars      specifies the names of the output file netcdf variable
+!  cl4_fcst_idx  specifies output file forecast index
+!  cl4_fcst_len  specifies forecast axis length
+!  cl4_match_len specifies number of unique matches per observation
+!  cl4_leadtime  specifies the forecast axis lead time 
+!
+&namcl4
+   cl4_match_len = 7
+   cl4_fcst_len = 3
+   cl4_fcst_idx = 1 2 3 1 2 3 1
+   cl4_vars = "forecast" "forecast" "forecast" "persistence" "persistence"
+              "persistence" "best_estimate"
+   cl4_leadtime = 12 36 60
+   cl4_prefix = "class4"
+   cl4_date = "20130101"
+   cl4_vn = "12.0"
+   cl4_sys = "FOAM"
+   cl4_cfg = "AMM7"
+   cl4_contact = "example@example.com"
+   cl4_inst = "UK Met Office"
+/
+\end{verbatim}
+\end{alltt}
+
+\subsubsection{Climatology interpolation}
+
+The climatological counterpart is generated at the start of the run by restarting 
+the model from climatology through appropriate use of \textbf{namtsd}. To override
+the offline observation operator read routine and to take advantage of the restart
+settings, specify the first entry in \textbf{cl4\_vars} as "climatology". This will then
+pipe the restart from climatology into the output class 4 file. As in every other
+class 4 matchup the input file, input index and output index must be specified.
+These can be replaced with dummy data since they are not used but they must be
+present to cycle through the matchups correctly. 
+
+\subsection{Advanced usage}
+
+In certain cases it may be desirable to include both multiple model fields per
+observation window with multiple match ups per observation. This can be achieved
+by specifying \textbf{nn\_ooo\_freq} as well as the class 4 settings. Care must
+be taken in generating the ooo\_files list such that the files are arranged into
+consecutive blocks of single match ups. For example, 2 forecast fields 
+of 12 hourly data would result in 4 separate read operations but only 2 write
+operations, 1 per forecast.
+
+\begin{alltt}
+\tiny
+\begin{verbatim}
+   ooo_files = "F1.nc" "F1.nc" "F2.nc" "F2.nc"
+...
+   cl4_fcst_idx = 1 2
+\end{verbatim}
+\end{alltt}
+
+The above notation reveals the internal split between match up iterators and file
+iterators. This technique has not been used before so experimentation is needed
+before results can be trusted.
+
+
+
+
+\newpage
+
 \section{Observation Utilities}
 \label{OBS_obsutils}
@@ -801,4 +1165,16 @@
 handling observation files and the feedback file output from the NEMO observation operator.
 The utilities are as follows
+
+\subsubsection{c4comb}
+
+The program c4comb combines multiple class 4 files produced by individual processors in an
+MPI run of NEMO offline obs\_oper into a single class 4 file. The program is called in the following way:
+
+\begin{alltt}
+\footnotesize
+\begin{verbatim}
+c4comb.exe outputfile inputfile1 inputfile2 ...
+\end{verbatim}
+\end{alltt}
 
 \subsubsection{corio2fb}
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/AMM12/EXP00/namelist
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/AMM12/EXP00/namelist	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/AMM12/EXP00/namelist	(revision 4229)
@@ -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    (namsol, nammpp, nammpp_dyndist, namctl)
+!!             10 - miscellaneous    (namsol, nammpp, nammpp_dyndist, namctl, namc1d, namc1d_uvd, namc1d_dyndmp)
 !!             11 - Obs & Assim      (namobs, nam_asminc)
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -28,5 +28,5 @@
    nn_it000    =       1   !  first time step
    nn_itend    =    2880   !  last  time step (std 1 day = 288)
-   nn_date0    =  20070101 !  date at nit_0000 (format yyyymmdd) used if ln_rstart=F or (ln_rstart=T and nn_rstctl=0 or 1)
+   nn_date0    =  20120101 !  date at nit_0000 (format yyyymmdd) used if ln_rstart=F or (ln_rstart=T and nn_rstctl=0 or 1)
    nn_leapy    =       1   !  Leap year calendar (1) or not (0)
    ln_rstart   =  .true.  !  start from rest (F) or from a restart file (T)
@@ -140,5 +140,5 @@
    nn_fsbc     = 1         !  frequency of surface boundary condition computation
                            !     (also = the frequency of sea-ice model call)
-   ln_ana      = .false    !  analytical formulation (T => fill namsbc_ana )
+   ln_ana      = .false.   !  analytical formulation (T => fill namsbc_ana )
    ln_flx      = .true.    !  flux formulation       (T => fill namsbc_flx )
    ln_blk_clio = .false.   !  CLIO bulk formulation                     (T => fill namsbc_clio)
@@ -218,4 +218,7 @@
    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_bulk2z   = .false.   !  Air temperature/humidity and wind vectors are referenced at heights rn_zqt and rn_zu
+   rn_zqt      = 3.        !  Air temperature and humidity reference height (m) (ln_bulk2z)
+   rn_zu       = 4.        !  Wind vector reference height (m)                  (ln_bulk2z)
    ln_taudif   = .false.   !  HF tau contribution: use "mean of stress module - module of the mean stress" data
    rn_pfac     = 1.        !  multiplicative factor for precipitation (total & snow)
@@ -466,9 +469,9 @@
 !              !   file name    ! frequency (hours) !  variable  ! time interpol. !  clim   ! 'yearly'/ ! weights  ! rotation !
 !              !                !  (if <0  months)  !    name    !    (logical)   !  (T/F)  ! 'monthly' ! filename ! pairing  !
-   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_ssh =     'amm12_bdyT_dyn2d' ,         24        , 'sossheig' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
+   bn_u2d =     'amm12_bdyU_dyn2d' ,         24        , 'vobtcrtx' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
+   bn_v2d =     'amm12_bdyV_dyn2d' ,         24        , 'vobtcrty' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
+   bn_u3d  =    'amm12_bdyU_dyn3d' ,         24        , 'vozocrtx' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
+   bn_v3d  =    'amm12_bdyV_dyn3d' ,         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'  ,    ''    ,   ''
@@ -771,4 +774,7 @@
 !!   namctl            Control prints & Benchmark
 !!   namsol            elliptic solver / island / free surface
+!!   namc1d            1D column configuration options                  ("key_c1d")
+!!   namc1d_uvd        data: U & V currents                             ("key_c1d")
+!!   namc1d_dyndmp     U & V newtonian damping                          ("key_c1d")
 !!======================================================================
 !
@@ -811,4 +817,27 @@
                            !     (no physical validity of the results)
    nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
+/
+!-----------------------------------------------------------------------
+&namc1d        !   1D configuration options                             ("key_c1d")
+!-----------------------------------------------------------------------
+   rn_lat      =    50     !  Column latitude
+   rn_lon      =    -145   !  Column longitude
+/
+!-----------------------------------------------------------------------
+&namc1d_uvd    !   data: U & V currents                                 ("key_c1d")
+!-----------------------------------------------------------------------
+!              ! file name ! frequency (hours)    ! variable ! time interp. ! clim  !'yearly' or ! weights  ! rotation !
+!              !           !  (if <0  months)     !   name   !  (logical)   ! (T/F) ! 'monthly'  ! filename ! pairing  !
+   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)
 /
 
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/GYRE/EXP00/namelist
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/GYRE/EXP00/namelist	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/GYRE/EXP00/namelist	(revision 4229)
@@ -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    (namsol, nammpp, nammpp_dyndist, namctl)
+!!             10 - miscellaneous    (namsol, nammpp, nammpp_dyndist, namctl, namc1d, namc1d_uvd, namc1d_dyndmp)
 !!             11 - Obs & Assim      (namobs, nam_asminc)
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -219,4 +219,7 @@
    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_bulk2z   = .false.   !  Air temperature/humidity and wind vectors are referenced at heights rn_zqt and rn_zu
+   rn_zqt      = 3.        !  Air temperature and humidity reference height (m) (ln_bulk2z)
+   rn_zu       = 4.        !  Wind vector reference height (m)                  (ln_bulk2z)
    ln_taudif   = .false.   !  HF tau contribution: use "mean of stress module - module of the mean stress" data
    rn_pfac     = 1.        !  multiplicative factor for precipitation (total & snow)
@@ -807,4 +810,7 @@
 !!   namctl            Control prints & Benchmark
 !!   namsol            elliptic solver / island / free surface
+!!   namc1d            1D column configuration options                  ("key_c1d")
+!!   namc1d_uvd        data: U & V currents                             ("key_c1d")
+!!   namc1d_dyndmp     U & V newtonian damping                          ("key_c1d")
 !!======================================================================
 !
@@ -847,4 +853,27 @@
                            !     (no physical validity of the results)
    nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
+/
+!-----------------------------------------------------------------------
+&namc1d        !   1D configuration options                             ("key_c1d")
+!-----------------------------------------------------------------------
+   rn_lat      =    50     !  Column latitude
+   rn_lon      =    -145   !  Column longitude
+/
+!-----------------------------------------------------------------------
+&namc1d_uvd    !   data: U & V currents                                 ("key_c1d")
+!-----------------------------------------------------------------------
+!              ! file name ! frequency (hours)    ! variable ! time interp. ! clim  !'yearly' or ! weights  ! rotation !
+!              !           !  (if <0  months)     !   name   !  (logical)   ! (T/F) ! 'monthly'  ! filename ! pairing  !
+   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)
 /
 
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist	(revision 4229)
@@ -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    (namsol, nammpp, nammpp_dyndist, namctl)
+!!             10 - miscellaneous    (namsol, nammpp, nammpp_dyndist, namctl, namc1d, namc1d_uvd, namc1d_dyndmp)
 !!             11 - Obs & Assim      (namobs, nam_asminc)
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -219,4 +219,7 @@
    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_bulk2z   = .false.   !  Air temperature/humidity and wind vectors are referenced at heights rn_zqt and rn_zu
+   rn_zqt      = 3.        !  Air temperature and humidity reference height (m) (ln_bulk2z)
+   rn_zu       = 4.        !  Wind vector reference height (m)                  (ln_bulk2z)
    ln_taudif   = .false.   !  HF tau contribution: use "mean of stress module - module of the mean stress" data
    rn_pfac     = 1.        !  multiplicative factor for precipitation (total & snow)
@@ -807,4 +810,7 @@
 !!   namctl            Control prints & Benchmark
 !!   namsol            elliptic solver / island / free surface
+!!   namc1d            1D column configuration options                  ("key_c1d")
+!!   namc1d_uvd        data: U & V currents                             ("key_c1d")
+!!   namc1d_dyndmp     U & V newtonian damping                          ("key_c1d")
 !!======================================================================
 !
@@ -847,4 +853,27 @@
                            !     (no physical validity of the results)
    nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
+/
+!-----------------------------------------------------------------------
+&namc1d        !   1D configuration options                             ("key_c1d")
+!-----------------------------------------------------------------------
+   rn_lat      =    50     !  Column latitude
+   rn_lon      =    -145   !  Column longitude
+/
+!-----------------------------------------------------------------------
+&namc1d_uvd    !   data: U & V currents                                 ("key_c1d")
+!-----------------------------------------------------------------------
+!              ! file name ! frequency (hours)    ! variable ! time interp. ! clim  !'yearly' or ! weights  ! rotation !
+!              !           !  (if <0  months)     !   name   !  (logical)   ! (T/F) ! 'monthly'  ! filename ! pairing  !
+   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)
 /
 
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/namelist
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/namelist	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/namelist	(revision 4229)
@@ -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    (namsol, nammpp, nammpp_dyndist, namctl)
+!!             10 - miscellaneous    (namsol, nammpp, nammpp_dyndist, namctl, namc1d, namc1d_uvd, namc1d_dyndmp)
 !!             11 - Obs & Assim      (namobs, nam_asminc)
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -219,4 +219,7 @@
    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_bulk2z   = .false.   !  Air temperature/humidity and wind vectors are referenced at heights rn_zqt and rn_zu
+   rn_zqt      = 3.        !  Air temperature and humidity reference height (m) (ln_bulk2z)
+   rn_zu       = 4.        !  Wind vector reference height (m)                  (ln_bulk2z)
    ln_taudif   = .false.   !  HF tau contribution: use "mean of stress module - module of the mean stress" data
    rn_pfac     = 1.        !  multiplicative factor for precipitation (total & snow)
@@ -802,4 +805,7 @@
 !!   namctl            Control prints & Benchmark
 !!   namsol            elliptic solver / island / free surface
+!!   namc1d            1D column configuration options                  ("key_c1d")
+!!   namc1d_uvd        data: U & V currents                             ("key_c1d")
+!!   namc1d_dyndmp     U & V newtonian damping                          ("key_c1d")
 !!======================================================================
 !
@@ -842,4 +848,27 @@
                            !     (no physical validity of the results)
    nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
+/
+!-----------------------------------------------------------------------
+&namc1d        !   1D configuration options                             ("key_c1d")
+!-----------------------------------------------------------------------
+   rn_lat      =    50     !  Column latitude
+   rn_lon      =    -145   !  Column longitude
+/
+!-----------------------------------------------------------------------
+&namc1d_uvd    !   data: U & V currents                                 ("key_c1d")
+!-----------------------------------------------------------------------
+!              ! file name ! frequency (hours)    ! variable ! time interp. ! clim  !'yearly' or ! weights  ! rotation !
+!              !           !  (if <0  months)     !   name   !  (logical)   ! (T/F) ! 'monthly'  ! filename ! pairing  !
+   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)
 /
 
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/namelist
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/namelist	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/namelist	(revision 4229)
@@ -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    (namsol, nammpp, nammpp_dyndist, namctl)
+!!             10 - miscellaneous    (namsol, nammpp, nammpp_dyndist, namctl, namc1d, namc1d_uvd, namc1d_dyndmp)
 !!             11 - Obs & Assim      (namobs, nam_asminc)
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -201,4 +201,7 @@
    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_bulk2z   = .false.   !  Air temperature/humidity and wind vectors are referenced at heights rn_zqt and rn_zu
+   rn_zqt      = 3.        !  Air temperature and humidity reference height (m) (ln_bulk2z)
+   rn_zu       = 4.        !  Wind vector reference height (m)                  (ln_bulk2z)
    ln_taudif   = .false.   !  HF tau contribution: use "mean of stress module - module of the mean stress" data
    rn_pfac     = 1.        !  multiplicative factor for precipitation (total & snow)
@@ -782,4 +785,7 @@
 !!   namctl            Control prints & Benchmark
 !!   namsol            elliptic solver / island / free surface 
+!!   namc1d            1D column configuration options                  ("key_c1d")
+!!   namc1d_uvd        data: U & V currents                             ("key_c1d")
+!!   namc1d_dyndmp     U & V newtonian damping                          ("key_c1d")
 !!======================================================================
 !
@@ -822,4 +828,27 @@
                            !     (no physical validity of the results)
    nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
+/
+!-----------------------------------------------------------------------
+&namc1d        !   1D configuration options                             ("key_c1d")
+!-----------------------------------------------------------------------
+   rn_lat      =    50     !  Column latitude
+   rn_lon      =    -145   !  Column longitude
+/
+!-----------------------------------------------------------------------
+&namc1d_uvd    !   data: U & V currents                                 ("key_c1d")
+!-----------------------------------------------------------------------
+!              ! file name ! frequency (hours)    ! variable ! time interp. ! clim  !'yearly' or ! weights  ! rotation !
+!              !           !  (if <0  months)     !   name   !  (logical)   ! (T/F) ! 'monthly'  ! filename ! pairing  !
+   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)
 /
 
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist	(revision 4229)
@@ -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    (namsol, nammpp, nammpp_dyndist, namctl)
+!!             10 - miscellaneous    (namsol, nammpp, nammpp_dyndist, namctl, namc1d, namc1d_uvd, namc1d_dyndmp)
 !!             11 - Obs & Assim      (namobs, nam_asminc)
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -218,4 +218,7 @@
    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_bulk2z   = .false.   !  Air temperature/humidity and wind vectors are referenced at heights rn_zqt and rn_zu
+   rn_zqt      = 3.        !  Air temperature and humidity reference height (m) (ln_bulk2z)
+   rn_zu       = 4.        !  Wind vector reference height (m)                  (ln_bulk2z)
    ln_taudif   = .false.   !  HF tau contribution: use "mean of stress module - module of the mean stress" data
    rn_pfac     = 1.        !  multiplicative factor for precipitation (total & snow)
@@ -803,4 +806,7 @@
 !!   namctl            Control prints & Benchmark
 !!   namsol            elliptic solver / island / free surface 
+!!   namc1d            1D column configuration options                  ("key_c1d")
+!!   namc1d_uvd        data: U & V currents                             ("key_c1d")
+!!   namc1d_dyndmp     U & V newtonian damping                          ("key_c1d")
 !!======================================================================
 !
@@ -843,4 +849,27 @@
                            !     (no physical validity of the results)
    nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
+/
+!-----------------------------------------------------------------------
+&namc1d        !   1D configuration options                             ("key_c1d")
+!-----------------------------------------------------------------------
+   rn_lat      =    50     !  Column latitude
+   rn_lon      =    -145   !  Column longitude
+/
+!-----------------------------------------------------------------------
+&namc1d_uvd    !   data: U & V currents                                 ("key_c1d")
+!-----------------------------------------------------------------------
+!              ! file name ! frequency (hours)    ! variable ! time interp. ! clim  !'yearly' or ! weights  ! rotation !
+!              !           !  (if <0  months)     !   name   !  (logical)   ! (T/F) ! 'monthly'  ! filename ! pairing  !
+   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)
 /
 
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/ORCA2_SAS_LIM/EXP00/namelist
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/ORCA2_SAS_LIM/EXP00/namelist	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/CONFIG/ORCA2_SAS_LIM/EXP00/namelist	(revision 4229)
@@ -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    (namsol, nammpp, nammpp_dyndist, namctl)
+!!             10 - miscellaneous    (namsol, nammpp, nammpp_dyndist, namctl, namc1d, namc1d_uvd, namc1d_dyndmp)
 !!             11 - Obs & Assim      (namobs, nam_asminc)
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -216,4 +216,7 @@
    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_bulk2z   = .false.   !  Air temperature/humidity and wind vectors are referenced at heights rn_zqt and rn_zu
+   rn_zqt      = 3.        !  Air temperature and humidity reference height (m) (ln_bulk2z)
+   rn_zu       = 4.        !  Wind vector reference height (m)                  (ln_bulk2z)
    ln_taudif   = .false.   !  HF tau contribution: use "mean of stress module - module of the mean stress" data
    rn_pfac     = 1.        !  multiplicative factor for precipitation (total & snow)
@@ -798,4 +801,7 @@
 !!   namctl            Control prints & Benchmark
 !!   namsol            elliptic solver / island / free surface 
+!!   namc1d            1D column configuration options                  ("key_c1d")
+!!   namc1d_uvd        data: U & V currents                             ("key_c1d")
+!!   namc1d_dyndmp     U & V newtonian damping                          ("key_c1d")
 !!======================================================================
 !
@@ -838,4 +844,27 @@
                            !     (no physical validity of the results)
    nn_timing   =    1      !  timing by routine activated (=1) creates timing.output file, or not (=0)
+/
+!-----------------------------------------------------------------------
+&namc1d        !   1D configuration options                             ("key_c1d")
+!-----------------------------------------------------------------------
+   rn_lat      =    50     !  Column latitude
+   rn_lon      =    -145   !  Column longitude
+/
+!-----------------------------------------------------------------------
+&namc1d_uvd    !   data: U & V currents                                 ("key_c1d")
+!-----------------------------------------------------------------------
+!              ! file name ! frequency (hours)    ! variable ! time interp. ! clim  !'yearly' or ! weights  ! rotation !
+!              !           !  (if <0  months)     !   name   !  (logical)   ! (T/F) ! 'monthly'  ! filename ! pairing  !
+   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)
 /
 
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/dtadyn.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/dtadyn.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/dtadyn.F90	(revision 4229)
@@ -0,0 +1,1 @@
+link ../OFF_SRC/dtadyn.F90
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/nemogcm.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/nemogcm.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/nemogcm.F90	(revision 4229)
@@ -0,0 +1,657 @@
+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
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   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 icbini          ! handle bergs, initialisation
+   USE icbstp          ! handle bergs, calving, themodynamics and transport
+#if defined key_oasis3
+   USE cpl_oasis3      ! OASIS3 coupling
+#elif defined key_oasis4
+   USE cpl_oasis4      ! OASIS4 coupling (not working)
+#endif
+   USE lib_mpp         ! distributed memory computing
+#if defined key_iomput
+   USE xios
+#endif
+   USE ooo_data        ! Offline obs_oper data
+   USE ooo_read        ! Offline obs_oper read routines
+   USE ooo_intp        ! Offline obs_oper interpolation
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   nemo_gcm    ! called by nemo.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
+         !!
+         !!----------------------------------------------------------------------
+         !! Class 4 output stream switch
+         USE obs_fbm, ONLY: ln_cl4
+         !! Initialise NEMO
+         CALL nemo_init
+         !! Initialise Offline obs_oper data
+         CALL ooo_data_init( ln_cl4 )
+         !! Loop over various model counterparts
+         DO jimatch = 1, cl4_match_len
+            IF (jimatch .GT. 1) THEN
+               !! Initialise obs_oper
+               CALL dia_obs_init
+            END IF
+            !! Interpolate to observation space
+            CALL ooo_interp
+            !! Pipe to output files
+            CALL dia_obs_wri
+            !! Reset the obs_oper between
+            CALL dia_obs_dealloc
+         END DO
+         !! 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
+      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
+      !!----------------------------------------------------------------------
+      !
+      cltxt = ''
+      !
+      !                             ! open Namelist file
+      CALL ctl_opn( numnam, 'namelist', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
+      !
+      READ( numnam, namctl )        ! Namelist namctl : Control prints & Benchmark
+      !
+      !                             !--------------------------------------------!
+      !                             !  set communicator & select the local node  !
+      !                             !--------------------------------------------!
+#if defined key_iomput
+      IF( Agrif_Root() ) THEN
+# if defined key_oasis3 || defined key_oasis4
+         CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
+         CALL xios_initialize( "oceanx",local_comm=ilocal_comm )
+# else
+         CALL  xios_initialize( "nemo",return_comm=ilocal_comm )
+# endif
+      ENDIF
+      narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection
+#else
+# if defined key_oasis3 || defined key_oasis4
+      IF( Agrif_Root() ) THEN
+         CALL cpl_prism_init( ilocal_comm )                 ! nemo local communicator given by oasis
+      ENDIF
+      narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
+# else
+      ilocal_comm = 0
+      narea = mynode( cltxt, numnam, nstop )                 ! Nodes selection (control print return in cltxt)
+# endif
+#endif
+      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
+
+      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
+
+      ! 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
+         jpk = jpkdta                                             ! third dim
+         jpim1 = jpi-1                                            ! inner domain indices
+         jpjm1 = jpj-1                                            !   "           "
+         jpkm1 = jpk-1                                            !   "           "
+         jpij  = jpi*jpj                                          !  jpi x j
+      ENDIF
+
+      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,*) '            Ocean General Circulation Model'
+         WRITE(numout,*) '                  version 3.4  (2011) '
+         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)
+
+      IF( lk_diaobs     ) THEN                  ! Observation & model comparison
+                            CALL dia_obs_init            ! Initialize observational data
+                            CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
+      ENDIF
+   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
+      !                             ! 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:',   &
+            &                                 ' key_gyre must be used or set nbench = 0' )
+         END SELECT
+      ENDIF
+      !
+      IF( lk_c1d .AND. .NOT.lk_iomput )   CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ',   &
+         &                                               'with the IOM Input/Output manager. '         ,   &
+         &                                               'Compile with key_iomput enabled' )
+      !
+      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      /= -1 )   CLOSE( numnam      )   ! oce namelist
+      IF( numnam_ice  /= -1 )   CLOSE( numnam_ice  )   ! ice 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
+      !
+      ierr = ierr + lib_mpp_alloc   (numout)    ! mpp exchanges
+      !
+      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 peer to peer messaging
+      !!=====================================================================
+      !!----------------------------------------------------------------------
+      !!
+      !! ** Purpose :   Initialization of the northern neighbours lists.
+      !!----------------------------------------------------------------------
+      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
+      !!----------------------------------------------------------------------
+
+      INTEGER ::   ji, jj, jk, ij, jtyp    ! dummy loop indices
+      INTEGER ::   ijpj                    ! number of rows involved in north-fold exchange
+      INTEGER ::   northcomms_alloc        ! allocate return status
+      REAL(wp), ALLOCATABLE, DIMENSION ( :,: ) ::   znnbrs     ! workspace
+      LOGICAL,  ALLOCATABLE, DIMENSION ( : )   ::   lrankset   ! workspace
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'nemo_northcomms : Initialization of the northern neighbours lists'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+
+      !!----------------------------------------------------------------------
+      ALLOCATE( znnbrs(jpi,jpj), stat = northcomms_alloc )
+      ALLOCATE( lrankset(jpnij), stat = northcomms_alloc )
+      IF( northcomms_alloc /= 0 ) THEN
+         WRITE(numout,cform_war)
+         WRITE(numout,*) 'northcomms_alloc : failed to allocate arrays'
+         CALL ctl_stop( 'STOP', 'nemo_northcomms : unable to allocate temporary arrays' )
+      ENDIF
+      nsndto = 0
+      isendto = -1
+      ijpj   = 4
+      !
+      ! This routine has been called because ln_nnogather has been set true ( nammpp )
+      ! However, these first few exchanges have to use the mpi_allgather method to
+      ! establish the neighbour lists to use in subsequent peer to peer exchanges.
+      ! Consequently, set l_north_nogather to be false here and set it true only after
+      ! the lists have been established.
+      !
+      l_north_nogather = .FALSE.
+      !
+      ! Exchange and store ranks on northern rows
+
+      DO jtyp = 1,4
+
+         lrankset = .FALSE.
+         znnbrs = narea
+         SELECT CASE (jtyp)
+            CASE(1)
+               CALL lbc_lnk( znnbrs, 'T', 1. )      ! Type 1: T,W-points
+            CASE(2)
+               CALL lbc_lnk( znnbrs, 'U', 1. )      ! Type 2: U-point
+            CASE(3)
+               CALL lbc_lnk( znnbrs, 'V', 1. )      ! Type 3: V-point
+            CASE(4)
+               CALL lbc_lnk( znnbrs, 'F', 1. )      ! Type 4: F-point
+         END SELECT
+
+         IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
+            DO jj = nlcj-ijpj+1, nlcj
+               ij = jj - nlcj + ijpj
+               DO ji = 1,jpi
+                  IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
+               &     lrankset(INT(znnbrs(ji,jj))) = .true.
+               END DO
+            END DO
+
+            DO jj = 1,jpnij
+               IF ( lrankset(jj) ) THEN
+                  nsndto(jtyp) = nsndto(jtyp) + 1
+                  IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
+                     CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
+                  &                 ' jpmaxngh will need to be increased ')
+                  ENDIF
+                  isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
+               ENDIF
+            END DO
+         ENDIF
+
+      END DO
+
+      !
+      ! Type 5: I-point
+      !
+      ! ICE point exchanges may involve some averaging. The neighbours list is
+      ! built up using two exchanges to ensure that the whole stencil is covered.
+      ! lrankset should not be reset between these 'J' and 'K' point exchanges
+
+      jtyp = 5
+      lrankset = .FALSE.
+      znnbrs = narea
+      CALL lbc_lnk( znnbrs, 'J', 1. ) ! first ice U-V point
+
+      IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
+         DO jj = nlcj-ijpj+1, nlcj
+            ij = jj - nlcj + ijpj
+            DO ji = 1,jpi
+               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
+            &     lrankset(INT(znnbrs(ji,jj))) = .true.
+         END DO
+        END DO
+      ENDIF
+
+      znnbrs = narea
+      CALL lbc_lnk( znnbrs, 'K', 1. ) ! second ice U-V point
+
+      IF ( njmppt(narea) .EQ. MAXVAL( njmppt )) THEN
+         DO jj = nlcj-ijpj+1, nlcj
+            ij = jj - nlcj + ijpj
+            DO ji = 1,jpi
+               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND.  INT(znnbrs(ji,jj)) .NE. narea ) &
+            &       lrankset( INT(znnbrs(ji,jj))) = .true.
+            END DO
+         END DO
+
+         DO jj = 1,jpnij
+            IF ( lrankset(jj) ) THEN
+               nsndto(jtyp) = nsndto(jtyp) + 1
+               IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
+                  CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
+               &                 ' jpmaxngh will need to be increased ')
+               ENDIF
+               isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
+            ENDIF
+         END DO
+         !
+         ! For northern row areas, set l_north_nogather so that all subsequent exchanges
+         ! can use peer to peer communications at the north fold
+         !
+         l_north_nogather = .TRUE.
+         !
+      ENDIF
+      DEALLOCATE( znnbrs )
+      DEALLOCATE( lrankset )
+
+   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: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/obs_fbm.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/obs_fbm.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/obs_fbm.F90	(revision 4229)
@@ -0,0 +1,1 @@
+link ../OPA_SRC/OBS/obs_fbm.F90
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo.nml
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo.nml	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo.nml	(revision 4229)
@@ -0,0 +1,44 @@
+
+!----------------------------------------------------------------------
+!       namooo Offline obs_oper namelist
+!----------------------------------------------------------------------
+!   ooo_files     specifies the files containing the model counterpart
+!   nn_ooo_idx    specifies the index within the model file
+!   nn_ooo_freq   specifies the number of timesteps between file reads
+&namooo
+   ooo_files = 'fcst.0.nc'
+   nn_ooo_idx = 1
+/
+!----------------------------------------------------------------------
+!       namcl4 Class 4 obs_oper namelist
+!----------------------------------------------------------------------
+!   cl4_date      the verfication date of the class 4 file
+!   cl4_vars      the name of the variable in the class 4 file
+!   cl4_sys       the forecast system being used e.g. FOAM
+!   cl4_cfg       the model configuration being used e.g. amm7
+!   cl4_vn        the version number e.g. 12.0
+!   cl4_prefix    prefix which denotes the output file
+!   cl4_contact   email address of file creator
+!   cl4_inst      institution related to the data within the file
+!   cl4_leadtime  lead time axis of class 4 file
+!   cl4_fcst_idx  output file forecast index
+!   cl4_fcst_len  output file forecast dimension length
+!   cl4_match_len number of match types
+!
+&namcl4
+   cl4_leadtime = 12
+   cl4_fcst_idx = 1
+   cl4_fcst_len = 1
+   cl4_match_len = 1
+   cl4_date = '20130101'
+   cl4_vars = 'forecast'
+   cl4_sys = 'FOAM'
+   cl4_cfg = 'amm7'
+   cl4_vn = '12.0'
+   cl4_prefix = 'class4'
+   cl4_contact = ''
+   cl4_inst = 'UK Met Office'
+/
+
+
+
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_data.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_data.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_data.F90	(revision 4229)
@@ -0,0 +1,142 @@
+MODULE ooo_data
+   !! =================================================================
+   !!                    *** MODULE ooo_data ***
+   !! =================================================================
+   USE par_kind, ONLY: lc
+
+   IMPLICIT NONE
+
+   !! Public data
+
+   INTEGER, PARAMETER :: MaxNumFiles = 1000
+
+   !! Class 4 file settings
+   INTEGER :: &
+           & cl4_fcst_idx(MaxNumFiles), & !: forecast indices
+           & cl4_match_len, &             !: number of match types
+           & cl4_fcst_len                 !: number of forecast days
+   CHARACTER(len=lc) :: &
+           & cl4_vars(MaxNumFiles), &  !: class 4 variables
+           & cl4_sys, &                !: class 4 system
+           & cl4_cfg, &                !: class 4 configuration
+           & cl4_date, &               !: class 4 date
+           & cl4_vn,  &                !: class 4 version
+           & cl4_prefix, &             !: class 4 prefix
+           & cl4_contact, &            !: class 4 contact
+           & cl4_inst                  !: class 4 institute
+   REAL ::   cl4_modjuld               !: model Julian day
+   REAL :: &
+      & cl4_leadtime(MaxNumFiles)      !: Lead time data
+
+   !! Offline obs_oper settings
+   CHARACTER(len=lc) :: &
+      & ooo_files(MaxNumFiles)         !: model files
+   INTEGER            :: &
+      & jifile, &                      !: current file list index
+      & n_files, &                     !: number of files
+      & jimatch, &                     !: current match
+      & nn_ooo_idx(MaxNumFiles), &     !: time_counter indices
+      & nn_ooo_freq                    !: read frequency in time steps
+   CHARACTER(len=128) :: &
+      & alt_file                       !: altimeter file
+CONTAINS
+   SUBROUTINE ooo_data_init( ld_cl4 )
+      !!----------------------------------------------------------------------
+      !!                    ***  SUBROUTINE ooo_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
+      LOGICAL, INTENT(IN) :: ld_cl4     !: Logical class 4 on/off
+
+      ! Standard offline obs_oper information
+      NAMELIST/namooo/ooo_files, nn_ooo_idx, nn_ooo_freq
+
+      ! Class 4 file specifiers
+      NAMELIST/namcl4/cl4_vars, cl4_sys, cl4_cfg, cl4_date, cl4_vn, &
+         &            cl4_prefix, cl4_contact, cl4_inst, cl4_leadtime, &
+         &            cl4_fcst_idx, cl4_fcst_len, cl4_match_len
+
+      ! Standard offline obs_oper initialisation
+      jimatch = 0                   !: match-up iteration variable 
+      jifile = 1                    !: input file iteration variable 
+      n_files = 0                   !: number of files to cycle through
+      ooo_files(:) = ''             !: list of files to read in
+      nn_ooo_idx(:) = 0             !: list of indices inside each file
+      nn_ooo_freq = -1              !: input frequency in time steps
+
+      ! Class 4 initialisation
+      cl4_leadtime(:) = 0           !: Lead time axis value for each file
+      cl4_fcst_len = 0              !: Length of the forecast dimension
+      cl4_match_len = 1             !: Number of match types
+      cl4_fcst_idx(:) = 0           !: output file forecast index
+      cl4_vars(:) = ''              !: output file variable names
+      cl4_sys = ''                  !: output file system
+      cl4_cfg = ''                  !: output file configuration
+      cl4_date = ''                 !: output file date string
+      cl4_vn = ''                   !: output file version
+      cl4_prefix = 'class4'         !: output file prefix
+      cl4_contact = ''              !: output file contact details
+      cl4_inst = ''                 !: output file institution
+
+      ! Standard offline obs_oper settings
+      READ(numnam, namooo)
+
+      ! Read class 4 output settings
+      IF (ld_cl4) THEN
+         READ(numnam, namcl4)
+      ENDIF
+
+      ! count input files
+      lmask(:) = .FALSE.
+      WHERE (ooo_files(:) /= '') lmask(:) = .TRUE.
+      n_files = COUNT(lmask)
+
+      !! Initialise sub obs window frequency
+      IF (nn_ooo_freq == -1) THEN
+         !! Run length
+         nn_ooo_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 namooo : set offline obs_oper parameters' 
+         DO jf = 1, n_files
+            WRITE(numout,'(1X,2A)') '   Input forecast file name          forecastfile = ', &
+               TRIM(ooo_files(jf))
+            WRITE(numout,*) '   Input forecast file index        forecastindex = ', &
+               nn_ooo_idx(jf)
+            WRITE(numout,*) '   Output forecast leadtime index   leadtimeindex = ', &
+               cl4_fcst_idx(jf)
+            WRITE(numout,*) '   Output forecast leadtime value   leadtimevalue = ', &
+               cl4_leadtime(jf)
+            WRITE(numout,'(1X,2A)') '   Input class 4 variable       class 4 parameter = ', &
+               TRIM(cl4_vars(jf))
+         END DO
+         WRITE(numout, '(1X,2A)') '   Input class 4 system            class 4 system = ', &
+            TRIM(cl4_sys)
+         WRITE(numout, '(1X,2A)') '   Input class 4 config            class 4 config = ', &
+            TRIM(cl4_cfg)
+         WRITE(numout, '(1X,2A)') '   Input class 4 date                class 4 date = ', &
+            TRIM(cl4_date)
+         WRITE(numout, '(1X,2A)') '   Input class 4 version          class 4 version = ', &
+            TRIM(cl4_vn)
+         WRITE(numout, '(1X,2A)') '   Input class 4 prefix            class 4 prefix = ', &
+            TRIM(cl4_prefix)
+         WRITE(numout, '(1X,2A)') '   Input class 4 contact          class 4 contact = ', &
+            TRIM(cl4_contact)
+         WRITE(numout, '(1X,2A)') '   Input class 4 institute      class 4 institute = ', &
+            TRIM(cl4_inst)
+      END IF
+
+   END SUBROUTINE ooo_data_init
+
+END MODULE ooo_data
+
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_intp.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_intp.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_intp.F90	(revision 4229)
@@ -0,0 +1,48 @@
+MODULE ooo_intp
+   !!======================================================================
+   !!                    ***  MODULE ooo_intp ***
+   !! ** Purpose : Run NEMO observation operator in offline mode
+   !!======================================================================
+   !! NEMO modules
+   USE in_out_manager
+   USE diaobs
+   !! Offline obs_oper modules
+   USE ooo_read
+   USE ooo_data
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC ooo_interp
+
+   CONTAINS
+
+      SUBROUTINE ooo_interp
+         !!----------------------------------------------------------------------
+         !!                    ***  SUBROUTINE ooo_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
+         !! Loop over entire run
+         istp = nit000
+         nstop = 0
+         DO WHILE ( istp <= nitend .AND. nstop == 0 )
+            IF (jifile <= n_files + 1) THEN
+               IF ( MOD(istp, nn_ooo_freq) == nit000 ) THEN
+                  !! Read next model counterpart
+                  CALL ooo_rea_dri(jifile)
+                  jifile = jifile + 1
+               ENDIF
+               !! Interpolate single time step
+               CALL dia_obs(istp)
+            ENDIF
+            !! Increment model step
+            istp = istp + 1
+         END DO
+      END SUBROUTINE ooo_interp
+
+END MODULE ooo_intp
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_read.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_read.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_read.F90	(revision 4229)
@@ -0,0 +1,347 @@
+
+MODULE ooo_read
+   !!==================================================================
+   !!                    *** MODULE ooo_read ***
+   !! Read routines : I/O for offline obs_oper
+   !!==================================================================
+
+   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 ooo_data
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC ooo_rea_dri
+
+CONTAINS
+   SUBROUTINE ooo_rea_dri(kfile)
+      !!------------------------------------------------------------------------
+      !!             *** ooo_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
+              & cmatchname    !: Match name
+      INTEGER :: &
+              & kindex       !: File index to read
+ 
+      !! Filename, index and match-up kind
+      cdfilename = TRIM(ooo_files(kfile))
+      cmatchname = TRIM(cl4_vars(kfile))
+      kindex = nn_ooo_idx(kfile)
+
+      !! Update model fields
+      !! Class 4 variables: forecast, persistence,
+      !!                    nrt_analysis, best_estimate
+      !! Feedback variables: empty string
+      IF ( (TRIM(cmatchname) == 'forecast') .OR. &
+         & (TRIM(cmatchname) == 'persistence') .OR. &
+         & (TRIM(cmatchname) == 'nrt_analysis') .OR. &
+         & (TRIM(cmatchname) == 'best_estimate').OR. &
+         & (TRIM(cmatchname) == '') ) THEN
+         CALL ooo_read_file(TRIM(cdfilename), kindex)
+         CALL ooo_read_juld(TRIM(cdfilename), kindex, cl4_modjuld)
+      ELSE IF (TRIM(cmatchname) == 'climatology') THEN
+         WRITE(numout,*) 'Interpolating climatologies'
+      ELSE IF (TRIM(cmatchname) == 'altimeter') THEN
+         CALL ooo_read_altbias(TRIM(cdfilename))
+         CALL ooo_read_juld(TRIM(cdfilename), kindex, cl4_modjuld)
+      END IF
+
+   END SUBROUTINE ooo_rea_dri
+
+   SUBROUTINE ooo_read_altbias(filename)
+      !!------------------------------------------------------------------------
+      !!                      *** ooo_read_altbias ***
+      !!
+      !! Purpose : To read altimeter bias and set tn,sn to missing values
+      !! Method  : Use subdomain indices to create start and count matrices
+      !!           for netcdf read.
+      !!
+      !! Author  : A. Ryan Sept 2012
+      !!------------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(IN) :: filename
+      INTEGER                      :: ncid, &
+                                    & varid,&
+                                    & istat,&
+                                    & ntimes,&
+                                    & tdim, &
+                                    & xdim, &
+                                    & ydim, &
+                                    & zdim
+      INTEGER                      :: ii, ij, ik
+      INTEGER, DIMENSION(3)        :: start_s, &
+                                    & count_s
+      REAL(fbdp), DIMENSION(:,:),  ALLOCATABLE :: temp_sshn
+      REAL(fbdp)                     :: fill_val
+
+      IF (TRIM(filename) == 'nofile') THEN
+         tsn(:,:,:,:) = fbrmdi
+         sshn(:,:) = fbrmdi 
+      ELSE
+         ! Open Netcdf file to find dimension id
+         istat = nf90_open(trim(filename),nf90_nowrite,ncid)
+         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',tdim)
+         istat = nf90_inquire_dimension(ncid, tdim, len=ntimes)
+         ! Allocate temporary temperature array
+         ALLOCATE(temp_sshn(nlci,nlcj))
+         ! Create start and count arrays
+         start_s = (/ nimpp, njmpp, 1 /)
+         count_s = (/ nlci,  nlcj,  1 /)
+          
+         ! Altimeter bias
+         istat = nf90_inq_varid(ncid,'altbias',varid)
+         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 
+
+         ! Fill sshn with altimeter bias 
+         sshn(1:nlci,1:nlcj) = temp_sshn(:,:) * tmask(1:nlci,1:nlcj,1)
+
+         ! Remove halo from tmask, sshn to prevent double obs counting
+         IF (jpi > nlci) THEN
+             tmask(nlci+1:,:,:) = 0
+             sshn(nlci+1:,:) = 0
+         END IF
+         IF (jpj > nlcj) THEN
+             tmask(:,nlcj+1:,:) = 0
+             sshn(:,nlcj+1:) = 0
+         END IF
+
+         ! Deallocate arrays
+         DEALLOCATE(temp_sshn)
+
+         ! Close netcdf file
+         istat = nf90_close(ncid)
+      END IF
+   
+   END SUBROUTINE ooo_read_altbias
+
+   SUBROUTINE ooo_read_file(filename, ifcst)
+      !!------------------------------------------------------------------------
+      !!             *** ooo_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 ooo_read_file
+
+   SUBROUTINE ooo_read_juld(filename, ifcst, julian)
+      USE calendar
+      !!--------------------------------------------------------------------
+      !!                 *** ooo_read_juld ***
+      !!
+      !!   Purpose : To read model julian day information from file
+      !!   Author  : A. Ryan Nov 2010
+      !!--------------------------------------------------------------------
+
+      !! Routine arguments
+      CHARACTER(len=*), INTENT(IN)  :: filename
+      INTEGER,          INTENT(IN)  :: ifcst
+      REAL,             INTENT(OUT) :: julian    !: Julian day
+
+      !! Local variables
+      INTEGER :: year,  &   !: Date information
+               & month, &
+               & day,   &
+               & hour,  &
+               & minute,&
+               & second
+      INTEGER :: istat, &   !: Netcdf variables
+               & ncid,  &
+               & dimid, &
+               & varid, &
+               & ntime      
+      REAL,DIMENSION(:),ALLOCATABLE :: r_sec     !: Remainder seconds
+      CHARACTER(len=120) :: time_str  !: time string
+
+      time_str=''
+      !! Read in time_counter and remainder seconds
+      istat = nf90_open(trim(filename),nf90_nowrite,ncid)
+      istat = nf90_inq_dimid(ncid,'time_counter',dimid)
+      IF (istat /= nf90_noerr) THEN
+          istat = nf90_inq_dimid(ncid,'time',dimid)
+      ENDIF
+      istat = nf90_inquire_dimension(ncid,dimid,len=ntime)
+      istat = nf90_inq_varid(ncid,'time_counter',varid)
+      IF (istat /= nf90_noerr) THEN
+          istat = nf90_inq_dimid(ncid,'time',dimid)
+      ENDIF
+      istat = nf90_get_att(ncid,varid,'units',time_str)
+      ALLOCATE(r_sec(ntime))
+      istat = nf90_get_var(ncid,varid, r_sec)
+      istat = nf90_close(ncid)
+
+      !! Fill yyyy-mm-dd hh:mm:ss
+      !! format(('seconds since ', I4.4,'-',I2.2,'-',I2.2,' ',I2.2,':',I2.2,':',I2.2))
+      100 format((14x, I4.4,1x,I2.2,1x,I2.2,1x,I2.2,1x,I2.2,1x,I2.2))
+      READ( time_str, 100 ) year, month, day, hour, minute, second
+
+      CALL ymds2ju(year, month, day, r_sec(ifcst), julian)
+
+      !! To take a comment from the ymds2ju subroutine
+
+   !- In the case of the Gregorian calendar we have chosen to use
+   !- the Lilian day numbers. This is the day counter which starts
+   !- on the 15th October 1582.
+   !- This is the day at which Pope Gregory XIII introduced the
+   !- Gregorian calendar.
+   !- Compared to the true Julian calendar, which starts some
+   !- 7980 years ago, the Lilian days are smaler and are dealt with
+   !- easily on 32 bit machines. With the true Julian days you can only
+   !- the fraction of the day in the real part to a precision of
+   !- a 1/4 of a day with 32 bits.
+      
+      !! The obs operator routines prefer to calculate Julian days since 
+      !! 01/01/1950 00:00:00
+      !! In order to convert to the 1950 version we must adjust by the number
+      !! of days between 15th October 1582 and 1st Jan 1950
+
+      julian = julian - 134123.
+      
+      DEALLOCATE(r_sec)
+      
+   END SUBROUTINE ooo_read_juld
+
+END MODULE ooo_read 
+
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_utils.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_utils.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_utils.F90	(revision 4229)
@@ -0,0 +1,102 @@
+MODULE ooo_utils
+   !! =================================================================
+   !!                    *** MODULE ooo_utils ***
+   !! =================================================================
+   USE par_oce
+
+   IMPLICIT NONE
+
+   ! Define double precision obfillflt
+   REAL(kind=dp), PARAMETER :: obfilldbl=99999.
+
+   CONTAINS
+
+   SUBROUTINE yyyymmdd_to_ref_date(indate, intime, outstring)
+      !----------------------------------------
+      ! Routine to create reference date string
+      !----------------------------------------
+      ! Routine arguments
+      CHARACTER(len=8),  INTENT(IN)  :: indate    ! yyyymmdd
+      CHARACTER(len=6),  INTENT(IN)  :: intime    ! hhmmss
+      CHARACTER(len=23), INTENT(OUT) :: outstring ! yyyy-mm-dd hh:mm:ss utc
+      ! Local variables
+      CHARACTER(len=4)  :: year      ! yyyy
+      CHARACTER(len=2)  :: month     ! mm
+      CHARACTER(len=2)  :: day       ! dd
+      CHARACTER(len=2)  :: hour      ! hh
+      CHARACTER(len=2)  :: minute    ! mm
+      CHARACTER(len=2)  :: second    ! ss
+
+      year   = indate(1:4)
+      month  = indate(5:6)
+      day    = indate(7:8)
+      hour   = intime(1:2)
+      minute = intime(3:4)
+      second = intime(5:6)
+
+      outstring = year//"-"//month//"-"//day//" "//hour//":"//minute//":"//second//" utc"
+      
+   END SUBROUTINE yyyymmdd_to_ref_date
+
+   SUBROUTINE date_format(date_str)
+      !---------------------------------------
+      ! Routine to create creation date string
+      !---------------------------------------
+
+      ! Routine arguments
+      CHARACTER(len=*), INTENT(OUT) :: date_str
+      ! Local variables
+      CHARACTER(8)  :: date
+      CHARACTER(10) :: time
+
+      CHARACTER(10)  :: date_part
+      CHARACTER(8)  :: time_part
+
+      CALL date_and_time(DATE=date)
+      CALL date_and_time(TIME=time)
+      date_part  = date(1:4)//'/'//date(5:6)//'/'//date(7:8)
+      time_part  = time(1:2)//':'//time(3:4)//':'//time(5:6)
+
+      date_str   = date_part//' '//time_part
+
+   END SUBROUTINE date_format
+
+   SUBROUTINE inst_converter(wmo_inst_list, nprofs, obs_names)
+      !---------------------------------------
+      ! Routine to convert WMO_INST_TYPE to
+      ! 'ARGO', 'TESAC', 'XBT', 'BUOYS'
+      !---------------------------------------
+
+      !! Routine arguments
+      INTEGER,                             INTENT(IN) :: nprofs
+      CHARACTER(len=*),DIMENSION(nprofs),  INTENT(IN) :: wmo_inst_list      
+      CHARACTER(len=128),DIMENSION(nprofs),INTENT(OUT):: obs_names
+
+      !! Local variables
+      INTEGER :: inam !: loop over name
+
+      !! Initialise obs_names
+      obs_names(:) = ''
+
+      !! Convert number to text
+      DO inam = 1,nprofs
+         IF (trim(adjustl(wmo_inst_list(inam))) .EQ. '820') THEN
+            obs_names(inam) = 'BUOYS'
+         ELSEIF (trim(adjustl(wmo_inst_list(inam))) .EQ. '401') THEN
+            obs_names(inam) = 'XBT'
+         ELSEIF (trim(adjustl(wmo_inst_list(inam))) .EQ. '741') THEN
+            obs_names(inam) = 'TESAC'
+         ELSEIF (trim(adjustl(wmo_inst_list(inam))) .EQ. '831') THEN
+            obs_names(inam) = 'ARGO'
+         ELSEIF (trim(adjustl(wmo_inst_list(inam))) .EQ. '22') THEN ! Special case for AATSR
+            obs_names(inam) = '22'
+         ELSEIF (trim(adjustl(wmo_inst_list(inam))) .EQ. '') THEN
+            obs_names(inam) = 'UNKNOWN'
+         ELSE 
+            obs_names(inam) = adjustl(wmo_inst_list(inam)) ! For all other cases
+         ENDIF
+      ENDDO
+
+   END SUBROUTINE inst_converter
+
+END MODULE ooo_utils
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_write.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_write.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OOO_SRC/ooo_write.F90	(revision 4229)
@@ -0,0 +1,591 @@
+MODULE ooo_write
+   !!======================================================================
+   !!                       ***  MODULE ooo_write  ***
+   !!======================================================================
+
+   USE in_out_manager
+   USE netcdf
+   USE obs_utils, ONLY: chkerr
+   USE ooo_utils, ONLY: date_format, inst_converter, yyyymmdd_to_ref_date
+   USE ooo_data
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC ooo_wri_init
+   PUBLIC ooo_wri_default
+   PUBLIC ooo_wri_extra
+
+   ! Type kinds for class 4 data.
+   INTEGER, PARAMETER :: clsp = SELECTED_REAL_KIND( 6, 37) !: single precision
+   INTEGER, PARAMETER :: cldp = SELECTED_REAL_KIND(12,307) !: double precision
+
+   ! Missinge data indicators 
+   INTEGER, PARAMETER    :: climdi = -99999   !: Integers
+   REAL(clsp), PARAMETER :: clrmdi =  99999   !: Reals
+
+   INTERFACE ooo_wri_extra
+      MODULE PROCEDURE ooo_wri_extra_3d_index, ooo_wri_extra_4d, ooo_wri_extra_4d_index
+   END INTERFACE
+
+   CONTAINS
+
+      SUBROUTINE ooo_wri_extra_3d_index(cdfilename, cdvarname, ndeps, nvars, &
+                               &  nobs, kstart, kcount, pdata)
+         !!----------------------------------------------------------------------
+         !!                    ***  ROUTINE ooo_wri_extra_3d  ***
+         !!
+         !! ** Purpose : Write 3d variables to class 4 file.
+         !!
+         !!----------------------------------------------------------------------
+         INTEGER, INTENT(IN) :: &
+                 & nobs, &       !: number of observations/profiles
+                 & nvars, &      !: number of physical parameters
+                 & ndeps         !: number of depths
+         CHARACTER(len=*), INTENT(IN) :: &
+                 & cdfilename, & !: netcdf file name
+                 & cdvarname     !: netcdf variable name
+         INTEGER, DIMENSION(3), INTENT(IN) :: &
+                 & kstart, &     !: start indices
+                 & kcount        !: count indices
+         REAL(KIND=cldp), DIMENSION(ndeps, nvars, nobs), INTENT(IN) :: &
+                 & pdata         !: 3d data
+         INTEGER :: &
+                 & ncid, &       !:
+                 & dimid, &      !:
+                 & varid         !:
+         CHARACTER(len=16), PARAMETER :: cpname = 'ooo_wri_extra_3d'
+         ! Open netcdf file
+         CALL chkerr(nf90_open(trim(cdfilename), nf90_write, ncid), cpname, __LINE__ )
+         ! Write data
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cdvarname), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, pdata, kstart, kcount),cpname, __LINE__ )
+         ! Close netcdf file
+         CALL chkerr(nf90_close(ncid), cpname, __LINE__ )
+      END SUBROUTINE ooo_wri_extra_3d_index
+
+      SUBROUTINE ooo_wri_extra_4d_index(cdfilename, cdvarname, ndeps, nfcst, &
+                               &  nvars, nobs, kstart, kcount, pdata)
+         !!----------------------------------------------------------------------
+         !!                    ***  ROUTINE ooo_wri_extra_4d  ***
+         !!
+         !! ** Purpose : Write 4d variables to class 4 file.
+         !!
+         !!----------------------------------------------------------------------
+         INTEGER, INTENT(IN) :: &
+                 & nobs, &       !: number of observations/profiles
+                 & nvars, &      !: number of physical parameters
+                 & ndeps, &      !: number of depths
+                 & nfcst         !: number of forecasts
+         CHARACTER(len=*), INTENT(IN) :: &
+                 & cdfilename, & !: netcdf file name
+                 & cdvarname     !: netcdf variable name
+         INTEGER, DIMENSION(4), INTENT(IN) :: &
+                 & kstart, &     !: start indices
+                 & kcount        !: count indices
+         REAL(KIND=cldp), DIMENSION(ndeps, nvars, nobs), INTENT(IN) :: &
+                 & pdata         !: slice of 4d data
+         INTEGER :: &
+                 & ncid, &       !:
+                 & dimid, &      !:
+                 & varid         !:
+         CHARACTER(len=22), PARAMETER :: cpname = 'ooo_wri_extra_4d_index'
+         ! Open netcdf file
+         CALL chkerr(nf90_open(trim(cdfilename), nf90_write, ncid), cpname, __LINE__ )
+         ! Write data
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cdvarname), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, pdata, kstart, kcount),cpname, __LINE__ )
+         ! Close netcdf file
+         CALL chkerr(nf90_close(ncid), cpname, __LINE__ )
+      END SUBROUTINE ooo_wri_extra_4d_index
+
+      SUBROUTINE ooo_wri_extra_4d(cdfilename, cdvarname, ndeps, nfcst, &
+                               &  nvars, nobs, pdata)
+         !!----------------------------------------------------------------------
+         !!                    ***  ROUTINE ooo_wri_extra_4d  ***
+         !!
+         !! ** Purpose : Write 4d variables to class 4 file.
+         !!
+         !!----------------------------------------------------------------------
+         INTEGER, INTENT(IN) :: &
+                 & nobs, &       !: number of observations/profiles
+                 & nvars, &      !: number of physical parameters
+                 & ndeps, &      !: number of depths
+                 & nfcst         !: number of forecasts
+         CHARACTER(len=*), INTENT(IN) :: &
+                 & cdfilename, & !: netcdf file name
+                 & cdvarname     !: netcdf variable name
+         REAL(KIND=cldp), DIMENSION(ndeps, nfcst, nvars, nobs), INTENT(IN) :: &
+                 & pdata         !: 4d data
+         INTEGER :: &
+                 & ncid, &       !:
+                 & dimid, &      !:
+                 & varid         !:
+         CHARACTER(len=16), PARAMETER :: cpname = 'ooo_wri_extra_4d'
+         ! Open netcdf file
+         CALL chkerr(nf90_open(trim(cdfilename), nf90_write, ncid), cpname, __LINE__ )
+         ! Write data
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cdvarname), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, pdata),cpname, __LINE__ )
+         ! Close netcdf file
+         CALL chkerr(nf90_close(ncid), cpname, __LINE__ )
+      END SUBROUTINE ooo_wri_extra_4d
+
+      SUBROUTINE ooo_wri_default(cdfilename, nobs, nvars, nfcst, ndeps, & 
+                             &   cdtyp, cdwmo, cunit, cvnam, &
+                             &   plam, pphi, pdep, ptim, pob, plead, &
+                             &   kqc, pmjuld)
+         !!----------------------------------------------------------------------
+         !!                    ***  ROUTINE ooo_wri_default  ***
+         !!
+         !! ** Purpose : Write standard variables to class 4 file.
+         !! ** Method  : Write the following variables;
+         !!                 observation type
+         !!                 observation wmo id
+         !!                 variable units
+         !!                 variable names
+         !!                 observation latitudes
+         !!                 observation longitudes
+         !!                 observation depths
+         !!                 observation times
+         !!                 observation values
+         !!                 observation qc flags
+         !!                 model julian days
+         !!                 
+         !! ** Returns : 
+         !!----------------------------------------------------------------------
+         INTEGER, INTENT(IN) :: &
+                 & nfcst, &      !: number of forecasts
+                 & nobs, &       !: number of observations/profiles
+                 & nvars, &      !: number of physical parameters
+                 & ndeps         !: number of depths
+         CHARACTER(len=*), INTENT(IN) :: &
+                 & cdfilename    !: file name
+         CHARACTER(LEN=128), DIMENSION(nobs), INTENT(IN) :: &
+                 & cdtyp         !: Instrument type
+         CHARACTER(LEN=8), DIMENSION(nobs), INTENT(IN) :: &
+                 & cdwmo         ! WMO number
+         CHARACTER(LEN=128), DIMENSION(nobs) :: &
+                 & cdpad         !: Instrument type (padded)
+         CHARACTER(LEN=8), DIMENSION(nvars), INTENT(IN) :: &
+                 & cunit, &      !: variable units (e.g. psu)
+                 & cvnam         !: variable names (e.g. vosaline)
+         REAL(KIND=cldp), DIMENSION(nfcst), INTENT(IN) :: &
+                 & plead         !: Leadtime
+         REAL(KIND=cldp), DIMENSION(nobs), INTENT(IN) :: &
+                 & pphi, &       !: Latitude
+                 & plam          !: Longitude
+         REAL(KIND=cldp), DIMENSION(ndeps, nobs), INTENT(IN) :: &
+                 & pdep          !: Depth               
+         REAL(KIND=cldp), DIMENSION(ndeps, nvars, nobs), INTENT(IN) :: &
+                 & pob           !: T observation
+         REAL(KIND=cldp), DIMENSION(nobs), INTENT(IN) :: &
+                 & ptim          !: Time
+         INTEGER(KIND=2), DIMENSION(ndeps, nvars, nobs), INTENT(IN) :: &
+                 & kqc           !: Observation QC
+         REAL, INTENT(IN) :: &
+                 & pmjuld        !: Model Julian Day
+         CHARACTER(len=128) :: &
+                 & cvar          !: variable name placeholder
+         INTEGER :: &
+                 & ncid, &  !:
+                 & dimid, & !:
+                 & varid    !:
+         CHARACTER(len=15), PARAMETER :: cpname = 'ooo_wri_default'
+         ! Open netcdf file
+         CALL chkerr(nf90_open(trim(cdfilename), nf90_write, ncid), cpname, __LINE__ )
+         ! longitude
+         cvar = 'longitude'
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, plam),cpname, __LINE__ )
+         ! latitude
+         cvar = 'latitude'
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, pphi),cpname, __LINE__ )
+         ! depth
+         cvar = 'depth'
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, pdep),cpname, __LINE__ )
+         ! varname
+         cvar = 'varname'
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, cvnam),cpname, __LINE__ )
+         ! unitname
+         cvar = 'unitname'
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, cunit),cpname, __LINE__ )
+         ! leadtime
+         cvar = 'leadtime'
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, plead),cpname, __LINE__ )
+         ! observation
+         cvar = 'observation'
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, pob),cpname, __LINE__ )
+         ! qc
+         cvar = 'qc'
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, kqc),cpname, __LINE__ )
+         ! juld
+         cvar = 'juld'
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, ptim),cpname, __LINE__ )
+         ! type
+         cvar = 'type'
+         CALL inst_converter(cdtyp,nobs,cdpad)
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, cdpad),cpname, __LINE__ )
+         ! id
+         cvar = 'id'
+         CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ )
+         CALL chkerr(nf90_put_var(ncid, varid, cdwmo),cpname, __LINE__ )
+         ! Close netcdf file
+         CALL chkerr(nf90_close(ncid), cpname, __LINE__ )
+      END SUBROUTINE ooo_wri_default
+
+      SUBROUTINE ooo_wri_init(cconf, csys, ckind, cversion, ccont, &
+                            & cinst, cdate, nproc, nobs, nvars, &
+                            & ndeps, nfcst, cdfilename)
+         !!----------------------------------------------------------------------
+         !!                    ***  ROUTINE ooo_wri_init  ***
+         !!
+         !! ** Purpose : Initialise a class 4 file.
+         !!
+         !! ** Method  :
+         !! ** Returns : cdfilename
+         !!----------------------------------------------------------------------
+         CHARACTER(len=*), INTENT(IN) :: &
+                 & cconf, &      !: model configuration e.g. orca025
+                 & csys, &       !: model system e.g. FOAM
+                 & ckind, &      !: observation kind e.g. profile
+                 & cversion, &   !: model version e.g. 12.0
+                 & ccont, &      !: contact email
+                 & cinst, &      !: institution description
+                 & cdate         !: e.g. yyyymmdd
+         INTEGER, INTENT(IN) :: &
+                 & nproc, &      !: processor number
+                 & nobs, &       !: number of observations/profiles
+                 & nvars, &      !: number of physical parameters
+                 & ndeps, &      !: number of depths
+                 & nfcst         !: number of forecast days
+         CHARACTER(len=128), INTENT(OUT) :: &
+                 & cdfilename    !: e.g. orca025
+         CHARACTER(len=4) :: &
+                 & cproc         !: character representation of nproc
+         CHARACTER(len=128) :: &
+                 & cattnam, &    !: attribute placeholder
+                 & cattval, &    !: attribute placeholder
+                 & cvar, &       !: variable name placeholder
+                 & cqcdes, &     !: quality control description
+                 & cqcval        !: quality control values
+         INTEGER :: &
+                 & istat, &      !: status of netcdf operation
+                 & ncid, &       !: netcdf file id placeholder
+                 & dimid_d, &    !: netcdf dimension id placeholder
+                 & dimid_f, &    !: netcdf dimension id placeholder
+                 & dimid_o, &    !: netcdf dimension id placeholder
+                 & dimid_v, &    !: netcdf dimension id placeholder
+                 & dimid_s, &    !: netcdf dimension id placeholder
+                 & dimid_l, &    !: netcdf dimension id placeholder
+                 & varid         !: netcdf variable id placeholder
+         INTEGER, DIMENSION(2) :: &
+                 & qc_flags      !: quality control flags
+         CHARACTER(len=23) :: &
+                 & ref_date      !: reference date holder
+         INTEGER, DIMENSION(2) :: &
+                 & dim2a, &      !: 2 dimensional settings
+                 & dim2b, &      !:
+                 & dim2c, &      !:
+                 & dim2d         !:
+         INTEGER, DIMENSION(3) :: &
+                 & dim3a         !: 3 dimensional settings
+         INTEGER, DIMENSION(4) :: &
+                 & dim4a         !: 4 dimensional settings
+         CHARACTER(len=12), PARAMETER :: cpname = 'ooo_wri_init'
+         ! Global att variables
+         CHARACTER(len=40) :: date_str
+         CHARACTER(len=6)  :: noon
+
+         WRITE(cproc, FMT="(I4.4)") nproc
+         cdfilename = 'class4'
+         cdfilename = TRIM(cdfilename)//'_'//TRIM(cdate)
+         cdfilename = TRIM(cdfilename)//'_'//TRIM(csys)
+         cdfilename = TRIM(cdfilename)//'_'//TRIM(cconf)
+         cdfilename = TRIM(cdfilename)//'_'//TRIM(cversion)
+         cdfilename = TRIM(cdfilename)//'_'//TRIM(ckind)
+         cdfilename = TRIM(cdfilename)//'_'//TRIM(cproc)
+         cdfilename = TRIM(cdfilename)//'.nc'
+         ! QC attribute string settings
+         IF (ckind .EQ. 'profile') THEN
+            cqcval = '0 - good data. 9 - bad data.'
+            cqcdes = ''
+            qc_flags = (/0, 9/)
+         ELSE IF (ckind .EQ. 'SST') THEN
+            cqcval = '0 - good data. 1 - bad data.'
+            cqcdes = 'In situ qc flag set to 0 if prob. of gross error < 0.5, &
+                     &1 otherwise. AATSR qc flag set to 0 for best_quality, 1 otherwise.'
+            qc_flags = (/0, 1/)
+         ELSE IF (ckind .EQ. 'SLA') THEN
+            cqcval = '0 - good data. 9 - bad data.'
+            cqcdes = ''
+            qc_flags = (/0, 9/)
+         ELSE
+            cqcval = ''
+            cqcdes = ''
+            qc_flags = (/0, 9/)
+         END IF
+         ! Check cdfilename exists
+         istat = nf90_open(TRIM(cdfilename), nf90_nowrite, ncid)
+         IF (istat /= nf90_noerr) THEN
+            IF (lwp) WRITE(numout, *) TRIM(cdfilename), ' opened successfully.'
+            CALL chkerr( nf90_create(TRIM(cdfilename), nf90_clobber, ncid), cpname, __LINE__ )
+            !! Global Dimension section
+            !  Partially hardwired for now
+            CALL date_format(date_str)
+            noon = '120000' ! hhmmss
+            ref_date = ''
+            CALL yyyymmdd_to_ref_date(TRIM(cdate), noon, ref_date)
+
+            CALL chkerr( nf90_put_att(ncid, nf90_global, 'title', &
+               & 'Forecast class 4 file'), cpname, __LINE__ )
+            CALL chkerr( nf90_put_att(ncid, nf90_global, 'version', &
+               & TRIM(cversion)), cpname, __LINE__ )
+            CALL chkerr( nf90_put_att(ncid, nf90_global, 'creation_date', &
+               & TRIM(date_str) ), cpname, __LINE__ )
+            CALL chkerr( nf90_put_att(ncid, nf90_global, 'validity_time', &
+               & TRIM(ref_date) ), cpname, __LINE__ )
+            CALL chkerr( nf90_put_att(ncid, nf90_global, 'contact', &
+               & TRIM(ccont) ), cpname, __LINE__ )
+            CALL chkerr( nf90_put_att(ncid, nf90_global, 'obs_type', &
+               & TRIM(ckind) ), cpname, __LINE__ )
+            CALL chkerr( nf90_put_att(ncid, nf90_global, 'system', &
+               & TRIM(csys)), cpname, __LINE__ )
+            CALL chkerr( nf90_put_att(ncid, nf90_global, 'configuration', &
+               & TRIM(cconf) ), cpname, __LINE__ ) 
+            CALL chkerr( nf90_put_att(ncid, nf90_global, 'institution', &
+               & TRIM(cinst) ), cpname, __LINE__ ) 
+
+            !! Define Dimensions
+            CALL chkerr(nf90_def_dim(ncid, 'numdeps', ndeps, dimid_d), cpname, __LINE__ )
+            CALL chkerr(nf90_def_dim(ncid, 'numfcsts', nfcst, dimid_f), cpname, __LINE__ )
+            CALL chkerr(nf90_def_dim(ncid, 'numvars', nvars, dimid_v), cpname, __LINE__ )
+            CALL chkerr(nf90_def_dim(ncid, 'numobs', nobs, dimid_o), cpname, __LINE__ )
+            CALL chkerr(nf90_def_dim(ncid, 'string_length8', 8, dimid_s), cpname, __LINE__ )
+            CALL chkerr(nf90_def_dim(ncid, 'string_length128', 128, dimid_l), cpname, __LINE__ )
+            !! Define possible dimension permutations
+            ! 2d
+            dim2a(:) = (/ dimid_d, dimid_o /) !: (/ ndeps, nobs  /) 
+            dim2b(:) = (/ dimid_s, dimid_o /) !: (/ 8, nobs  /)
+            dim2c(:) = (/ dimid_s, dimid_v /) !: (/ 8, nvars /)
+            dim2d(:) = (/ dimid_l, dimid_o /) !: (/ 128, nobs  /)
+            ! 3d
+            dim3a(:) = (/ dimid_d, dimid_v, dimid_o/) !: (/ ndeps, nvars, nobs /)
+            ! 4d
+            dim4a(:) = (/ dimid_d, dimid_f, dimid_v, dimid_o /) !: (/ ndeps, nfcst, nvars, nobs /)
+
+            !! Create the variables
+            !  Forecast day
+            cvar = 'leadtime'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dimid_f, varid), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Model forecast day offset'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'units'
+            cattval = 'Hours'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'comment'
+            cattval = 'Hours between forecast production and validity time'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            !  longitude
+            cvar = 'longitude'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dimid_o, varid), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Longitudes'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'units'
+            cattval = 'Degrees'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            !  latitude
+            cvar = 'latitude'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dimid_o, varid), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Latitudes'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'units'
+            cattval = 'Degrees'
+
+            !  depth
+            cvar = 'depth'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim2a, varid), cpname, __LINE__ )
+            CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Depths'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'units'
+            cattval = 'metre'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            !  varname
+            cvar = 'varname'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_char, dim2c, varid), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Variable name'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            !  unitname
+            cvar = 'unitname'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_char, dim2c, varid), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Unit name'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            !  observation
+            cvar = 'observation'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim3a, varid), cpname, __LINE__ )
+            CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Observation value'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            !  forecast
+            cvar = 'forecast'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim4a, varid), cpname, __LINE__ )
+            CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Model forecast counterpart of obs. value'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'comment'
+            cattval = 'Model daily mean valid at noon used for calculation'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            !  persistence
+            cvar = 'persistence'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim4a, varid), cpname, __LINE__ )
+            CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Model persistence counterpart of obs. value'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'comment'
+            cattval = 'Model daily mean valid at noon used for calculation'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            !  climatology
+            cvar = 'climatology'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim3a, varid), cpname, __LINE__ )
+            CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Climatological value'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'comment'
+            cattval = 'Levitus monthly fields interpolated to the correct day'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            !  daym2
+            cvar = 'best_estimate'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim3a, varid), cpname, __LINE__ )
+            CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Best estimate'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'comment'
+            cattval = 'FOAM daym2 field'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            !  daym1
+            cvar = 'nrt_analysis'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim3a, varid), cpname, __LINE__ )
+            CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Near real time analysis'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'comment'
+            cattval = 'FOAM daym1 field'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+         
+            !  optional fields
+            IF (TRIM(ckind) .EQ. 'SLA') THEN
+               !  mdt
+               cvar = 'mdt_reference'
+               CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim3a, varid), cpname, __LINE__ )
+               CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ )
+               cattnam = 'long_name'
+               cattval = 'Mean dynamic topography'
+               CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+               cattnam = 'comment'
+               cattval = 'MDT reference field'
+               CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+               !  altbias
+               cvar = 'altimeter_bias'
+               CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim3a, varid), cpname, __LINE__ )
+               CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ )
+               cattnam = 'long_name'
+               cattval = 'Altimeter bias'
+               CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            ENDIF
+         
+            !  qc
+            cvar = 'qc'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_short, dim3a, varid), cpname, __LINE__ )
+            CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', NF90_FILL_SHORT), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Quality flags'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'flag_value'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), qc_flags), cpname, __LINE__ )
+            cattnam = 'flag_meaning'
+            cattval = cqcval
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'comment'
+            cattval = cqcdes
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+!            !  juld
+            cvar = 'juld'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_double, dimid_o, varid), cpname, __LINE__ )
+!            CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Observation time in Julian days'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'units'
+            CALL yyyymmdd_to_ref_date('19500101', '000000', ref_date)
+            cattval = 'Days since '//ref_date
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            !  modeljuld 
+            cvar = 'modeljuld'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dimid_f, varid), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Model field date in Julian days'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+            cattnam = 'units'
+            cattval = 'Days since '//ref_date
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            !  type
+            cvar = 'type'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_char, dim2d, varid), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Observation type'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            !  id
+            cvar = 'id'
+            CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_char, dim2b, varid), cpname, __LINE__ )
+            cattnam = 'long_name'
+            cattval = 'Observation id'
+            CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ )
+
+            ! Close netcdf file
+            CALL chkerr(nf90_close(ncid), cpname, __LINE__ )
+         ELSE
+            IF (lwp) WRITE(numout, *) TRIM(cdfilename), 'already exists.'
+            ! Close netcdf file
+            CALL chkerr(nf90_close(ncid), cpname, __LINE__ )
+         END IF
+      END SUBROUTINE ooo_wri_init
+
+
+END MODULE ooo_write
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 4229)
@@ -1016,5 +1016,5 @@
 #endif
 
-#if defined key_cice
+#if defined key_cice && defined key_asminc
             ! Sea-ice : CICE case. Pass ice increment tendency into CICE
             ndaice_da(:,:) = seaice_bkginc(:,:) * zincwgt / rdt
@@ -1027,5 +1027,5 @@
          ELSE
 
-#if defined key_cice
+#if defined key_cice && defined key_asminc
             ! Sea-ice : CICE case. Zero ice increment tendency into CICE
             ndaice_da(:,:) = 0.0_wp
@@ -1071,6 +1071,6 @@
 #endif
  
-#if defined key_cice
-            ! Sea-ice : CICE case. Pass ice increment tendency into CICE - is this correct?
+#if defined key_cice && defined key_asminc
+            ! Sea-ice : CICE case. Pass ice increment tendency into CICE
            ndaice_da(:,:) = seaice_bkginc(:,:) / rdt
 #endif
@@ -1081,5 +1081,5 @@
          ELSE
 
-#if defined key_cice
+#if defined key_cice && defined key_asminc
             ! Sea-ice : CICE case. Zero ice increment tendency into CICE 
             ndaice_da(:,:) = 0.0_wp
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/c1d.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/c1d.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/c1d.F90	(revision 4229)
@@ -4,16 +4,26 @@
    !! Ocean domain  :  1D configuration
    !!=====================================================================
-   !! History :   2.0  !  2004-09  (C. Ethe)  Original code
-   !!             3.0  !  2008-04 (G. Madec)  adaptation to SBC
+   !! 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
+   !!----------------------------------------------------------------------
+   !!   'key_c1d'                                   1D column configuration
+   !!----------------------------------------------------------------------
+   !!   c1d_init       : read in the C1D namelist
+   !!----------------------------------------------------------------------
+   USE in_out_manager   ! I/O manager
+   USE par_kind         ! kind parameters
 
    IMPLICIT NONE
    PRIVATE
 
-#if defined key_c1d
-   LOGICAL, PUBLIC, PARAMETER ::   lk_c1d = .TRUE.    !: 1D config. flag activated
-#else
-   LOGICAL, PUBLIC, PARAMETER ::   lk_c1d = .FALSE.   !: 1D config. flag de-activated
-#endif
+   PUBLIC   c1d_init                                 ! called by nemogcm.F90
+
+   LOGICAL , PUBLIC, PARAMETER ::  lk_c1d = .TRUE.   ! 1D config. flag
+
+   REAL(wp), PUBLIC            ::  rn_lat = 50       ! Column latitude
+   REAL(wp), PUBLIC            ::  rn_lon = -145     ! Column longitude
 
    !!----------------------------------------------------------------------
@@ -22,3 +32,45 @@
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!======================================================================
+CONTAINS
+
+   SUBROUTINE c1d_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE c1d_init  ***
+      !! 
+      !! ** Purpose :   Initialization of C1D options
+      !!
+      !! ** Method  :   Read namelist namc1d 
+      !!----------------------------------------------------------------------
+      NAMELIST/namc1d/ rn_lat, rn_lon
+      !!----------------------------------------------------------------------
+      !
+      REWIND ( numnam )               ! Read C1D options from namelist
+      READ   ( numnam, namc1d )
+      !
+      IF(lwp) THEN                    ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'c1d_init : Initialize 1D model configuration options'
+         WRITE(numout,*) '~~~~~~~~'
+         WRITE(numout,*) '   Namelist namc1d : set options for the C1D model'
+         WRITE(numout,*) '      column latitude                 rn_lat = ', rn_lat
+         WRITE(numout,*) '      column longitude                rn_lon = ', rn_lon
+      ENDIF
+      !
+      !
+   END SUBROUTINE c1d_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                           No use of 1D configuration
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_c1d = .FALSE.   !: 1D config. flag de-activated
+   REAL                       ::   rn_lat, rn_lon
+CONTAINS
+
+   SUBROUTINE c1d_init               ! Dummy routine
+   END SUBROUTINE c1d_init
+
+#endif
+
+   !!======================================================================
 END MODULE c1d
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/domc1d.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/domc1d.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/domc1d.F90	(revision 4229)
@@ -0,0 +1,208 @@
+MODULE domc1d
+   !!======================================================================
+   !!                     ***  MODULE  domc1d  ***
+   !! Ocean Domain : 1D column position from lat/lon namelist specification
+   !!======================================================================
+   !! History :  3.5  !  2013-04  (D. Calvert)  Original code
+   !!----------------------------------------------------------------------
+#if defined key_c1d
+   !!----------------------------------------------------------------------
+   !!   'key_c1d'   :                                      1D Configuration
+   !!----------------------------------------------------------------------
+   !!   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 wrk_nemo                      ! Memory allocation
+   USE timing                        ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dom_c1d                  ! Routine called in domcfg.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: domc1d.F90 3851 2013-04-30 10:30:51Z hadcv $ 
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+   
+   SUBROUTINE dom_c1d( plat, plon )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE dom_c1d  ***
+      !! 
+      !! ** Purpose : Recalculate jpizoom/jpjzoom indices from lat/lon point
+      !!
+      !! ** Method  : Calculate global gphit and glamt as for dom_hgr.
+      !!              After, find closest grid point to lat/lon point as for 
+      !!              dom_ngb on T grid. From this infer jpizoom and jpjzoom.
+      !!
+      !! ** Action  : Recalculate jpizoom, jpjzoom (indices of C1D zoom)
+      !!----------------------------------------------------------------------
+      INTEGER  ::  ji, jj                          ! Dummy loop indices
+      INTEGER  ::  inum                            ! Coordinate file handle (case 0)
+      INTEGER  ::  ijeq                            ! Index of equator T point (case 4)
+
+      INTEGER , DIMENSION(2) ::   iloc             ! Minloc returned indices
+
+      REAL(wp), INTENT(in) ::  plat                ! Column latitude
+      REAL(wp), INTENT(in) ::  plon                ! Column longitude
+
+      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) , POINTER, DIMENSION(:,:) ::  gphidta, glamdta, zdist ! Global lat/lon
+      !!----------------------------------------------------------------------
+
+      IF( nn_timing == 1 )   CALL timing_start('dom_c1d')
+
+      CALL wrk_alloc( jpidta, jpjdta, gphidta, glamdta, zdist )
+
+
+      ! ============================= !
+      !  Code from dom_hgr:           !
+      !  Calculate global horizontal  !
+      !  mesh, only glamt and gphit   !
+      ! ============================= !
+
+      SELECT CASE( jphgr_msh )   ! type of horizontal mesh
+
+      CASE ( 0 )                 !  curvilinear coordinate on the sphere read in coordinate.nc file
+
+         CALL iom_open( 'coordinates', inum )
+         CALL iom_get( inum, jpdom_unknown, 'glamt', glamdta ) ! mig, mjg undefined at this point
+         CALL iom_get( inum, jpdom_unknown, 'gphit', gphidta ) ! so use jpdom_unknown not jpdom_data
+         CALL iom_close ( inum )
+
+         PRINT *,'Check dom_c1d coordinates file data read in:' !!!
+         PRINT *,'Bottom-left most glamdta is ', glamdta(1,1)    !!! Need to check
+         PRINT *,'Bottom-left most gphidta is ', gphidta(1,1)    !!! field read
+         PRINT *,'We are using nimpp,njmpp = ' , nimpp,njmpp     !!!
+
+      CASE ( 1 )                 ! geographical mesh on the sphere with regular grid-spacing
+
+         DO jj = 1, jpjdta
+            DO ji = 1, jpidta
+               zti = FLOAT( ji - 1 + nimpp - 1 )
+               ztj = FLOAT( jj - 1 + njmpp - 1 )
+
+               glamdta(ji,jj) = ppglam0 + ppe1_deg * zti
+               gphidta(ji,jj) = ppgphi0 + ppe2_deg * ztj
+            END DO
+         END DO
+
+      CASE ( 2:3 )               ! f- or beta-plane with regular grid-spacing
+         
+         glam0 = 0.e0
+         gphi0 = - ppe2_m * 1.e-3
+
+         DO jj = 1, jpjdta
+            DO ji = 1, jpidta
+               glamdta(ji,jj) = glam0 + ppe1_m * 1.e-3 * FLOAT( ji - 1 + nimpp - 1 )
+               gphidta(ji,jj) = gphi0 + ppe2_m * 1.e-3 * FLOAT( jj - 1 + njmpp - 1 )
+            END DO
+         END DO
+
+      CASE ( 4 )                 ! geographical mesh on the sphere, isotropic MERCATOR type
+
+         IF( ppgphi0 == -90 )   CALL ctl_stop( ' Mercator grid cannot start at south pole !!!! ' )
+
+         zarg = rpi / 4. - rpi / 180. * ppgphi0 / 2.
+         ijeq = ABS( 180. / rpi * LOG( COS( zarg ) / SIN( zarg ) ) / ppe1_deg )
+         IF( ppgphi0 > 0 )   ijeq = -ijeq
+
+         DO jj = 1, jpjdta
+            DO ji = 1, jpidta
+               zti = FLOAT( ji - 1    + nimpp - 1 )
+               ztj = FLOAT( jj - ijeq + njmpp - 1 )
+
+               glamdta(ji,jj) = ppglam0 + ppe1_deg * zti
+               gphidta(ji,jj) = 1. / rad * ASIN ( TANH( ppe1_deg * rad * ztj ) )
+            END DO
+         END DO
+
+      CASE ( 5 )                 ! beta-plane with regular grid-spacing and rotated domain (GYRE configuration)
+   
+         zlam1 = -85
+         zphi1 = 29
+         ze1 = 106000. / FLOAT(jp_cfg)
+ 
+         zsin_alpha = - SQRT( 2. ) / 2.
+         zcos_alpha =   SQRT( 2. ) / 2.
+         ze1deg = ze1 / (ra * rad)
+
+         glam0 = zlam1 + zcos_alpha * ze1deg * FLOAT( jpjdta-2 ) ! Force global
+         gphi0 = zphi1 + zsin_alpha * ze1deg * FLOAT( jpjdta-2 )
+
+         DO jj = 1, jpjdta
+            DO ji = 1, jpidta
+               zim05 = FLOAT( ji + nimpp - 1 ) - 1.5
+               zjm05 = FLOAT( jj + njmpp - 1 ) - 1.5
+
+               glamdta(ji,jj) = glam0 + zim05 * ze1deg * zcos_alpha + zjm05 * ze1deg * zsin_alpha
+               gphidta(ji,jj) = gphi0 - zim05 * ze1deg * zsin_alpha + zjm05 * ze1deg * zcos_alpha
+            END DO
+         END DO
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for jphgr_msh = ', jphgr_msh
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+
+      ! ============================== !
+      !  Code from dom_ngb:            !
+      !  Calculate the nearest grid    !
+      !  point to the given lat/lon &  !
+      !  update jpizoom and jpjzoom    !
+      ! ============================== !
+
+      zlon         = MOD( plon         + 720., 360. )                                      ! plon    between    0 and 360
+      glamdta(:,:) = MOD( glamdta(:,:) + 720., 360. )                                      ! glamdta between    0 and 360
+      IF( zlon > 270. )   zlon = zlon - 360.                                               ! zlon    between  -90 and 270
+      IF( zlon <  90. )   WHERE( glamdta(:,:) > 180. ) glamdta(:,:) = glamdta(:,:) - 360.  ! glamdta between -180 and 180
+
+      glamdta(:,:) = glamdta(:,:) - zlon
+      gphidta(:,:) = gphidta(:,:) - plat
+      zdist(:,:)   = glamdta(:,:) * glamdta(:,:) + gphidta(:,:) * gphidta(:,:)
+      
+      iloc(:) = MINLOC( zdist(:,:) ) ! No mask; zoom indices freely defined
+      jpizoom = iloc(1) + nimpp - 2  ! Minloc index - 1; want the bottom-left
+      jpjzoom = iloc(2) + njmpp - 2  ! corner index of the zoom domain.
+
+      CALL wrk_dealloc( jpidta, jpjdta, gphidta, glamdta, zdist )
+
+      IF (lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_c1d : compute jpizoom & jpjzoom from global mesh and given coordinates'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) '      column i zoom index             jpizoom = ', jpizoom
+         WRITE(numout,*) '      column j zoom index             jpjzoom = ', jpjzoom
+         WRITE(numout,*)
+      ENDIF
+
+      IF( nn_timing == 1 )   CALL timing_stop('dom_c1d')
+
+   END SUBROUTINE dom_c1d
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                  NO 1D Configuration
+   !!----------------------------------------------------------------------
+CONTAINS  
+   SUBROUTINE dom_c1d( plat, plon )     ! Empty routine
+      REAL :: plat, plon
+      WRITE(*,*) 'dom_c1d: You should not have seen this print! error?',plat,plon
+   END SUBROUTINE dom_c1d
+#endif
+
+   !!======================================================================
+END MODULE domc1d
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/dtauvd.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/dtauvd.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/dtauvd.F90	(revision 4229)
@@ -0,0 +1,263 @@
+MODULE dtauvd
+   !!======================================================================
+   !!                     ***  MODULE  dtauvd  ***
+   !! 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
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dta_uvd_init   ! called by nemogcm.F90
+   PUBLIC   dta_uvd        ! called by istate.F90 and dyndmp.90
+
+   LOGICAL , PUBLIC ::   ln_uvd_init   = .FALSE.      ! Flag to initialise with U & V current data
+   LOGICAL , PUBLIC ::   ln_uvd_dyndmp = .FALSE.      ! 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)
+   !! $Id: dtauvd.F90 2392 2010-11-15 21:20:05Z gm $ 
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE dta_uvd_init( ld_dyndmp )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE dta_uvd_init  ***
+      !!                    
+      !! ** Purpose :   initialization of U & V current input data 
+      !! 
+      !! ** Method  : - read namc1d_uvd namelist
+      !!              - allocate U & V current data structure
+      !!              - 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
+      !!
+      NAMELIST/namc1d_uvd/ ln_uvd_init, ln_uvd_dyndmp, cn_dir, sn_ucur, sn_vcur
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('dta_uvd_init')
+      !
+      ierr0 = 0  ;  ierr1 = 0  ;  ierr2 = 0  ;  ierr3 = 0
+      !
+      cn_dir = './'                 ! default: directory in which the model is executed
+      !
+      !                             !==   read namelist namc1d_uvd: flags and field info   ==!
+
+      !                             ! default values (NB: frequency positive => hours, negative => months)
+      !              !   file   ! frequency ! variable  ! time intep !  clim   ! 'yearly' or ! weights  ! rotation !
+      !              !   name   !  (hours)  !  name     !   (T/F)    !  (T/F)  !  'monthly'  ! filename ! pairs    !
+      sn_ucur = FLD_N( 'ucurrent',   -1     , 'u_current',  .false.  , .true.  ,  'monthly'  , ''       , 'Ume'    )
+      sn_vcur = FLD_N( 'vcurrent',   -1     , 'v_current',  .false.  , .true.  ,  'monthly'  , ''       , 'Vme'    )
+
+      REWIND( numnam )              ! Read in namelist namc1d_uvd
+      READ  ( numnam, namc1d_uvd )
+
+      !                             ! force the initialization when dyndmp is used
+      IF( PRESENT( ld_dyndmp ) )   ln_uvd_dyndmp = .TRUE.
+      
+      IF(lwp) THEN                  ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'dta_uvd_init : U & V current data '
+         WRITE(numout,*) '~~~~~~~~~~~~ '
+         WRITE(numout,*) '   Namelist namc1d_uvd : Set flags'
+         WRITE(numout,*) '      Initialization of ocean U & V current with input data   ln_uvd_init   = ', ln_uvd_init
+         WRITE(numout,*) '      Damping of ocean U & V current toward input data        ln_uvd_dyndmp = ', ln_uvd_dyndmp
+         WRITE(numout,*)
+         IF( .NOT. ln_uvd_init .AND. .NOT. ln_uvd_dyndmp ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) '   U & V current data not used'
+         ENDIF
+      ENDIF
+      !                             ! no initialization when restarting
+      IF( ln_rstart .AND. ln_uvd_init ) THEN
+         CALL ctl_warn( 'dta_uvd_init: ocean restart and U & V current data initialization, ',   &
+            &           'we keep the restart U & V current values and set ln_uvd_init to FALSE' )
+         ln_uvd_init = .FALSE.
+      ENDIF
+
+      !
+      IF(  ln_uvd_init .OR. ln_uvd_dyndmp  ) THEN
+         !                          !==   allocate the data arrays   ==!
+         ALLOCATE( sf_uvd(2), STAT=ierr0 )
+         IF( ierr0 > 0 ) THEN
+            CALL ctl_stop( 'dta_uvd_init: unable to allocate sf_uvd structure' )             ;   RETURN
+         ENDIF
+         !
+                                 ALLOCATE( sf_uvd(1)%fnow(jpi,jpj,jpk)   , STAT=ierr0 )
+         IF( sn_ucur%ln_tint )   ALLOCATE( sf_uvd(1)%fdta(jpi,jpj,jpk,2) , STAT=ierr1 )
+                                 ALLOCATE( sf_uvd(2)%fnow(jpi,jpj,jpk)   , STAT=ierr2 )
+         IF( sn_vcur%ln_tint )   ALLOCATE( sf_uvd(2)%fdta(jpi,jpj,jpk,2) , STAT=ierr3 )
+         !
+         IF( ierr0 + ierr1 + ierr2 + ierr3 > 0 ) THEN
+            CALL ctl_stop( 'dta_uvd_init : unable to allocate U & V current data arrays' )   ;   RETURN
+         ENDIF
+         !                          !==   fill sf_uvd with sn_ucur, sn_vcur and control print   ==!
+         suv_i(1) = sn_ucur   ;   suv_i(2) = sn_vcur
+         CALL fld_fill( sf_uvd, suv_i, cn_dir, 'dta_uvd', 'U & V current data', 'namc1d_uvd' )
+         !
+      ENDIF
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('dta_uvd_init')
+      !
+   END SUBROUTINE dta_uvd_init
+
+
+   SUBROUTINE dta_uvd( kt, puvd )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE dta_uvd  ***
+      !!                    
+      !! ** Purpose :   provides U & V current data at time step kt
+      !! 
+      !! ** Method  : - call fldread routine
+      !!              - ORCA_R2: make some hand made alterations to the data (EMPTY)
+      !!              - s- or mixed s-zps coordinate: vertical interpolation onto model mesh
+      !!              - zps coordinate: vertical interpolation onto last partial level
+      !!              - ln_uvd_dyndmp=False: deallocate the U & V current data structure,
+      !!                                     as the data is no longer used
+      !!
+      !! ** Action  :   puvd,  U & V current data interpolated onto model mesh at time-step kt
+      !!----------------------------------------------------------------------
+      INTEGER                           , INTENT(in   ) ::   kt     ! ocean time-step
+      REAL(wp), DIMENSION(jpi,jpj,jpk,2), INTENT(  out) ::   puvd   ! U & V current data
+      !
+      INTEGER ::   ji, jj, jk, jl, jkk               ! dummy loop indicies
+      INTEGER ::   ik, il0, il1, ii0, ii1, ij0, ij1  ! local integers
+      REAL(wp)::   zl, zi                            ! local floats
+      REAL(wp), POINTER, DIMENSION(:) ::  zup, zvp   ! 1D workspace
+      !!----------------------------------------------------------------------
+      !
+      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
+      puvd(:,:,:,2) = sf_uvd(2)%fnow(:,:,:) 
+      !
+      IF( ln_sco ) THEN                   !==   s- or mixed s-zps-coordinate   ==!
+         !
+         CALL wrk_alloc( jpk, zup, zvp )
+         !
+         IF( kt == nit000 .AND. lwp )THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'dta_uvd: interpolate U & V current data onto the s- or mixed s-z-coordinate mesh'
+         ENDIF
+         !
+         DO jj = 1, jpj                   ! vertical interpolation of U & V current:
+            DO ji = 1, jpi                ! determines the interpolated U & V current profiles at each (i,j) point
+               DO jk = 1, jpk
+                  zl = fsdept_0(ji,jj,jk)
+                  IF    ( zl < gdept_0(1  ) ) THEN          ! extrapolate above the first level of data
+                     zup(jk) =  puvd(ji,jj,1    ,1)
+                     zvp(jk) =  puvd(ji,jj,1    ,2)
+                  ELSEIF( zl > gdept_0(jpk) ) THEN          ! extrapolate below the last level of data
+                     zup(jk) =  puvd(ji,jj,jpkm1,1)
+                     zvp(jk) =  puvd(ji,jj,jpkm1,2)
+                  ELSE                                      ! inbetween : vertical interpolation between jkk & jkk+1
+                     DO jkk = 1, jpkm1                      ! when  gdept(jkk) < zl < gdept(jkk+1)
+                        IF( (zl-gdept_0(jkk)) * (zl-gdept_0(jkk+1)) <= 0._wp ) THEN
+                           zi = ( zl - gdept_0(jkk) ) / (gdept_0(jkk+1)-gdept_0(jkk))
+                           zup(jk) = puvd(ji,jj,jkk,1) + ( puvd(ji,jj,jkk+1,1 ) - puvd(ji,jj,jkk,1) ) * zi 
+                           zvp(jk) = puvd(ji,jj,jkk,2) + ( puvd(ji,jj,jkk+1,2 ) - puvd(ji,jj,jkk,2) ) * zi
+                        ENDIF
+                     END DO
+                  ENDIF
+               END DO
+               DO jk = 1, jpkm1           ! apply mask
+                  puvd(ji,jj,jk,1) = zup(jk) * umask(ji,jj,jk)
+                  puvd(ji,jj,jk,2) = zvp(jk) * vmask(ji,jj,jk)
+               END DO
+               puvd(ji,jj,jpk,1) = 0._wp
+               puvd(ji,jj,jpk,2) = 0._wp
+            END DO
+         END DO
+         ! 
+         CALL wrk_dealloc( jpk, zup, zvp )
+         ! 
+      ELSE                                !==   z- or zps- coordinate   ==!
+         !                             
+         puvd(:,:,:,1) = puvd(:,:,:,1) * umask(:,:,:)       ! apply mask
+         puvd(:,:,:,2) = puvd(:,:,:,2) * vmask(:,:,:)
+         !
+         IF( ln_zps ) THEN                ! zps-coordinate (partial steps) interpolation at the last ocean level
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ik = mbkt(ji,jj) 
+                  IF( ik > 1 ) THEN
+                     zl = ( gdept_0(ik) - fsdept_0(ji,jj,ik) ) / ( gdept_0(ik) - gdept_0(ik-1) )
+                     puvd(ji,jj,ik,1) = (1.-zl) * puvd(ji,jj,ik,1) + zl * puvd(ji,jj,ik-1,1)
+                     puvd(ji,jj,ik,2) = (1.-zl) * puvd(ji,jj,ik,2) + zl * puvd(ji,jj,ik-1,2)
+                  ENDIF
+               END DO
+            END DO
+         ENDIF
+         !
+      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)  ==!
+         IF(lwp) WRITE(numout,*) 'dta_uvd: deallocate U & V current arrays as they are only used to initialize the run'
+                                   DEALLOCATE( sf_uvd(1)%fnow )     ! U current arrays in the structure
+         IF( sf_uvd(1)%ln_tint )   DEALLOCATE( sf_uvd(1)%fdta )
+                                   DEALLOCATE( sf_uvd(2)%fnow )     ! V current arrays in the structure
+         IF( sf_uvd(2)%ln_tint )   DEALLOCATE( sf_uvd(2)%fdta )
+                                   DEALLOCATE( sf_uvd         )     ! the structure itself
+      ENDIF
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('dta_uvd')
+      !
+   END SUBROUTINE dta_uvd
+
+   !!======================================================================
+END MODULE dtauvd
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/dyndmp.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/dyndmp.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/dyndmp.F90	(revision 4229)
@@ -0,0 +1,244 @@
+MODULE dyndmp
+   !!======================================================================
+   !!                       ***  MODULE  dyndmp  ***
+   !! Ocean dynamics: internal restoring trend on momentum (U and V current)
+   !!======================================================================
+   !! History :  3.5  ! 2013-08  (D. Calvert)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_dmp_alloc : allocate dyndmp arrays
+   !!   dyn_dmp_init  : namelist read, parameter control and resto coeff.
+   !!   dyn_dmp       : update the momentum trend with the internal damping
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean: variables
+   USE dom_oce        ! ocean: domain variables
+   USE c1d            ! 1D vertical configuration
+   USE trdmod         ! ocean: trends
+   USE tradmp         ! ocean: internal damping
+   USE zdf_oce        ! ocean: vertical physics
+   USE phycst         ! physical constants
+   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
+   USE prtctl         ! Print control
+   USE wrk_nemo       ! Memory allocation
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_dmp_init ! routine called by nemogcm.F90
+   PUBLIC   dyn_dmp      ! routine called by step_c1d.F90
+
+   LOGICAL, PUBLIC ::   ln_dyndmp = .TRUE.                             ! 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)
+   !! $Id: dyndmp.F90 3294 2012-01-28 16:44:18Z rblod $ 
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION dyn_dmp_alloc()
+      !!----------------------------------------------------------------------
+      !!                ***  FUNCTION dyn_dmp_alloc  ***
+      !!----------------------------------------------------------------------
+      ALLOCATE( utrdmp(jpi,jpj,jpk), vtrdmp(jpi,jpj,jpk), resto_uv(jpi,jpj,jpk), STAT= dyn_dmp_alloc )
+      !
+      IF( lk_mpp            )   CALL mpp_sum ( dyn_dmp_alloc )
+      IF( dyn_dmp_alloc > 0 )   CALL ctl_warn('dyn_dmp_alloc: allocation of arrays failed')
+      !
+   END FUNCTION dyn_dmp_alloc
+
+
+   SUBROUTINE dyn_dmp_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_dmp_init  ***
+      !! 
+      !! ** Purpose :   Initialization for the Newtonian damping 
+      !!
+      !! ** Method  : - read the ln_dyndmp parameter from the namc1d_dyndmp namelist
+      !!              - allocate damping arrays
+      !!              - check the parameters of the namtra_dmp namelist
+      !!              - calculate damping coefficient
+      !!----------------------------------------------------------------------
+      NAMELIST/namc1d_dyndmp/ ln_dyndmp
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )                      !==   read namelist namc1d_dyndmp : momentum damping flag     ==!
+      READ   ( numnam, namc1d_dyndmp )       !==   (namelist of namtra_dmp is used for other parameters)   ==!
+
+      IF(lwp) THEN                           ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'dyn_dmp_init : U and V current Newtonian damping'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namc1d_dyndmp : Set damping flag'
+         WRITE(numout,*) '      add a damping term or not       ln_dyndmp = ', ln_dyndmp
+         WRITE(numout,*) '   Namelist namtra_dmp    : Set damping parameters'
+         WRITE(numout,*) '      horizontal damping option       nn_hdmp   = ', nn_hdmp
+         WRITE(numout,*) '      mixed layer damping option      nn_zdmp   = ', nn_zdmp, '(non-C1D zoom: forced to 0)'
+         WRITE(numout,*) '      surface time scale (days)       rn_surf   = ', rn_surf
+         WRITE(numout,*) '      bottom time scale (days)        rn_bot    = ', rn_bot
+         WRITE(numout,*) '      depth of transition (meters)    rn_dep    = ', rn_dep
+         WRITE(numout,*) '      create a damping.coeff file     nn_file   = ', nn_file
+         WRITE(numout,*)
+      ENDIF
+
+      IF( ln_dyndmp ) THEN
+         !                                   !==   allocate the data arrays   ==!
+         IF( dyn_dmp_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dyn_dmp_init: unable to allocate arrays' )
+         !
+#if ! defined key_c1d
+         SELECT CASE ( nn_hdmp )             !==   control print of horizontal option   ==!
+         CASE (  -1  )   ;   IF(lwp) WRITE(numout,*) '   momentum damping in the Med & Red seas only'
+         CASE ( 1:90 )   ;   IF(lwp) WRITE(numout,*) '   momentum damping poleward of', nn_hdmp, ' degrees'
+         CASE DEFAULT
+            WRITE(ctmp1,*) '          bad flag value for nn_hdmp = ', nn_hdmp
+            CALL ctl_stop(ctmp1)
+         END SELECT
+         !
+#endif
+         SELECT CASE ( nn_zdmp )             !==   control print of vertical option   ==!
+         CASE ( 0    )   ;   IF(lwp) WRITE(numout,*) '   momentum damping throughout the water column'
+         CASE ( 1    )   ;   IF(lwp) WRITE(numout,*) '   no momentum damping in the turbocline (avt > 5 cm2/s)'
+         CASE ( 2    )   ;   IF(lwp) WRITE(numout,*) '   no momentum damping in the mixed layer'
+         CASE DEFAULT
+            WRITE(ctmp1,*) '          bad flag value for nn_zdmp = ', nn_zdmp
+            CALL ctl_stop(ctmp1)
+         END SELECT
+         !
+         IF( .NOT. ln_uvd_dyndmp ) THEN      ! force the initialization of U & V current data for damping
+            CALL ctl_warn( 'dyn_dmp_init: U & V current read data not initialized, we force ln_uvd_dyndmp=T' )
+            CALL dta_uvd_init( ld_dyndmp=ln_dyndmp )
+         ENDIF
+         !
+         utrdmp(:,:,:) = 0._wp               ! internal damping trends
+         vtrdmp(:,:,:) = 0._wp
+         !                                   !==   Damping coefficients calculation:                           ==!
+         !                                   !==   use tradmp.F90 subroutines dtacof, dtacof_zoom and cofdis   ==!
+         !                                   !!!   NOTE: these need to be altered for use in this module if 
+         !                                   !!!       they are to be used outside the C1D context 
+         !                                   !!!       (use of U,V grid variables)
+         IF( lzoom .AND. .NOT. lk_c1d ) THEN   ;   CALL dtacof_zoom( resto_uv )
+         ELSE               ;   CALL dtacof( nn_hdmp, rn_surf, rn_bot, rn_dep, nn_file, 'DYN', resto_uv )
+         ENDIF
+         !
+      ENDIF
+      !
+   END SUBROUTINE dyn_dmp_init
+
+
+   SUBROUTINE dyn_dmp( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE dyn_dmp  ***
+      !!                  
+      !! ** Purpose :   Compute the momentum trends due to a newtonian damping
+      !!      of the ocean velocities towards the given data and add it to the 
+      !!      general momentum trends.
+      !!
+      !! ** Method  :   Compute Newtonian damping towards u_dta and v_dta 
+      !!      and add to the general momentum trends:
+      !!                     ua = ua + resto_uv * (u_dta - ub)
+      !!                     va = va + resto_uv * (v_dta - vb)
+      !!      The trend is computed either throughout the water column
+      !!      (nn_zdmp=0), where the vertical mixing is weak (nn_zdmp=1) or
+      !!      below the well mixed layer (nn_zdmp=2)
+      !!
+      !! ** 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 
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start( 'dyn_dmp' )
+      !
+      CALL wrk_alloc( jpi, jpj, jpk, 2,  zuv_dta )
+      !
+      !                           !==   read and interpolate U & V current data at kt   ==!
+      CALL dta_uvd( kt, zuv_dta ) !!! NOTE: This subroutine must be altered for use outside
+                                  !!!       the C1D context (use of U,V grid variables)
+      !
+      SELECT CASE ( nn_zdmp )     !==   Calculate/add Newtonian damping to the momentum trend   ==!
+      !
+      CASE( 0 )                   ! Newtonian damping throughout the water column
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  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) )
+                  ua(ji,jj,jk) = ua(ji,jj,jk) + zua
+                  va(ji,jj,jk) = va(ji,jj,jk) + zva
+                  utrdmp(ji,jj,jk) = zua           ! save the trends
+                  vtrdmp(ji,jj,jk) = zva      
+               END DO
+            END DO
+         END DO
+         !
+      CASE ( 1 )                  ! no damping above the turbocline (avt > 5 cm2/s)
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  IF( avt(ji,jj,jk) <= 5.e-4_wp ) 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) )
+                  ELSE
+                     zua = 0._wp
+                     zva = 0._wp  
+                  ENDIF
+                  ua(ji,jj,jk) = ua(ji,jj,jk) + zua
+                  va(ji,jj,jk) = va(ji,jj,jk) + zva
+                  utrdmp(ji,jj,jk) = zua           ! save the trends
+                  vtrdmp(ji,jj,jk) = zva
+               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
+                     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) )
+                  ELSE
+                     zua = 0._wp
+                     zva = 0._wp  
+                  ENDIF
+                  ua(ji,jj,jk) = ua(ji,jj,jk) + zua
+                  va(ji,jj,jk) = va(ji,jj,jk) + zva
+                  utrdmp(ji,jj,jk) = zua           ! save the trends
+                  vtrdmp(ji,jj,jk) = zva
+               END DO
+            END DO
+         END DO
+         !
+      END SELECT
+      !
+      !                           ! Trend diagnostic
+      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 )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop( 'dyn_dmp')
+      !
+   END SUBROUTINE dyn_dmp
+
+   !!======================================================================
+END MODULE dyndmp
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90	(revision 4229)
@@ -13,10 +13,11 @@
    !!   stp_c1d        : NEMO system time-stepping in c1d case
    !!----------------------------------------------------------------------
-   USE step_oce         ! time stepping definition modules 
+   USE step_oce        ! time stepping definition modules 
 #if defined key_top
-   USE trcstp           ! passive tracer time-stepping      (trc_stp routine)
+   USE trcstp          ! passive tracer time-stepping      (trc_stp routine)
 #endif
    USE dyncor_c1d      ! Coriolis term (c1d case)         (dyn_cor_1d     )
    USE dynnxt_c1d      ! time-stepping                    (dyn_nxt routine)
+   USE dyndmp          ! U & V momentum damping           (dyn_dmp routine)
    USE restart         ! restart 
 
@@ -124,4 +125,5 @@
                              CALL tra_sbc    ( kstp )        ! surface boundary condition
       IF( ln_traqsr      )   CALL tra_qsr    ( kstp )        ! penetrative solar radiation qsr
+      IF( ln_tradmp      )   CALL tra_dmp    ( kstp )        ! internal damping trends- tracers
       IF( lk_zdfkpp      )   CALL tra_kpp    ( kstp )        ! KPP non-local tracer fluxes
                              CALL tra_zdf    ( kstp )        ! vertical mixing
@@ -136,4 +138,5 @@
                                va(:,:,:) = 0.e0
 
+      IF( ln_dyndmp      )     CALL dyn_dmp    ( kstp )       ! internal damping trends- momentum
                                CALL dyn_cor_c1d( kstp )       ! vorticity term including Coriolis
                                CALL dyn_zdf    ( kstp )       ! vertical diffusion
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domcfg.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domcfg.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domcfg.F90	(revision 4229)
@@ -16,4 +16,6 @@
    USE lib_mpp         ! distributed memory computing library
    USE timing          ! Timing
+   USE c1d             ! 1D configuration
+   USE domc1d          ! 1D configuration: column location
 
    IMPLICIT NONE
@@ -80,4 +82,7 @@
       !!----------------------------------------------------------------------
 
+      !                              ! recalculate jpizoom/jpjzoom given lat/lon
+      IF( lk_c1d )  CALL dom_c1d( rn_lat, rn_lon )
+      !
       !                        ! ============== !
       !                        !  Local domain  ! 
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4229)
@@ -1173,11 +1173,25 @@
       !                                        ! =============================
       ! 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
-            zenv(ji,jj) = MAX( bathy(ji,jj), rn_sbot_min )
-         END DO
-      END DO
+           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
+           ENDIF
+         END DO
+      END DO
+      ! apply lateral boundary condition   CAUTION: keep the value when the lbc field is zero
+      CALL lbc_lnk( zenv, 'T', 1._wp, 'no0' )
       ! 
-      ! Smooth the bathymetry (if required)
+      ! smooth the bathymetry (if required)
       scosrf(:,:) = 0._wp             ! ocean surface depth (here zero: no under ice-shelf sea)
       scobot(:,:) = bathy(:,:)        ! ocean bottom  depth
@@ -1185,78 +1199,68 @@
       jl = 0
       zrmax = 1._wp
-      !                                                     ! ================ !
-      DO WHILE( jl <= 10000 .AND. zrmax > rn_rmax )         !  Iterative loop  !
-         !                                                  ! ================ !
+      !   
+      !     
+      ! set scaling factor used in reducing vertical gradients
+      zrfact = ( 1._wp - rn_rmax ) / ( 1._wp + rn_rmax )
+      !
+      ! initialise temporary evelope depth arrays
+      ztmpi1(:,:) = zenv(:,:)
+      ztmpi2(:,:) = zenv(:,:)
+      ztmpj1(:,:) = zenv(:,:)
+      ztmpj2(:,:) = zenv(:,:)
+      !
+      ! initialise temporary r-value arrays
+      zri(:,:) = 1._wp
+      zrj(:,:) = 1._wp
+      !                                                            ! ================ !
+      DO WHILE( jl <= 10000 .AND. ( zrmax - rn_rmax ) > 1.e-8_wp ) !  Iterative loop  !
+         !                                                         ! ================ !
          jl = jl + 1
          zrmax = 0._wp
-         zmsk(:,:) = 0._wp
+         ! 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, nlcj
+            DO ji = 1, nlci
+               zrmax = MAX( zrmax, ABS(zri(ji,jj)), ABS(zrj(ji,jj)) )
+            END DO
+         END DO
+         zri(:,:) = 0._wp
+         zrj(:,:) = 0._wp
          DO jj = 1, nlcj
             DO ji = 1, nlci
                iip1 = MIN( ji+1, nlci )      ! force zri = 0 on last line (ji=ncli+1 to jpi)
                ijp1 = MIN( jj+1, nlcj )      ! force zrj = 0 on last raw  (jj=nclj+1 to jpj)
-               zri(ji,jj) = ABS( zenv(iip1,jj  ) - zenv(ji,jj) ) / ( zenv(iip1,jj  ) + zenv(ji,jj) )
-               zrj(ji,jj) = ABS( zenv(ji  ,ijp1) - zenv(ji,jj) ) / ( zenv(ji  ,ijp1) + zenv(ji,jj) )
-               zrmax = MAX( zrmax, zri(ji,jj), zrj(ji,jj) )
-               IF( zri(ji,jj) > rn_rmax )   zmsk(ji  ,jj  ) = 1._wp
-               IF( zri(ji,jj) > rn_rmax )   zmsk(iip1,jj  ) = 1._wp
-               IF( zrj(ji,jj) > rn_rmax )   zmsk(ji  ,jj  ) = 1._wp
-               IF( zrj(ji,jj) > rn_rmax )   zmsk(ji  ,ijp1) = 1._wp
+               IF( (zenv(ji,jj) > 0._wp) .AND. (zenv(iip1,jj) > 0._wp)) THEN
+                  zri(ji,jj) = ( zenv(iip1,jj  ) - zenv(ji,jj) ) / ( zenv(iip1,jj  ) + zenv(ji,jj) )
+               END IF
+               IF( (zenv(ji,jj) > 0._wp) .AND. (zenv(ji,ijp1) > 0._wp)) 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
          IF( lk_mpp )   CALL mpp_max( zrmax )   ! max over the global domain
-         ! lateral boundary condition on zmsk: keep 1 along closed boundary (use of MAX)
-         ztmp(:,:) = zmsk(:,:)   ;   CALL lbc_lnk( zmsk, 'T', 1._wp )
-         DO jj = 1, nlcj
-            DO ji = 1, nlci
-                zmsk(ji,jj) = MAX( zmsk(ji,jj), ztmp(ji,jj) )
-            END DO
-         END DO
          !
-         IF(lwp)WRITE(numout,*) 'zgr_sco :   iter= ',jl, ' rmax= ', zrmax, ' nb of pt= ', INT( SUM(zmsk(:,:) ) )
+         IF(lwp)WRITE(numout,*) 'zgr_sco :   iter= ',jl, ' rmax= ', zrmax
          !
          DO jj = 1, nlcj
             DO ji = 1, nlci
-               iip1 = MIN( ji+1, nlci )     ! last  line (ji=nlci)
-               ijp1 = MIN( jj+1, nlcj )     ! last  raw  (jj=nlcj)
-               iim1 = MAX( ji-1,  1  )      ! first line (ji=nlci)
-               ijm1 = MAX( jj-1,  1  )      ! first raw  (jj=nlcj)
-               IF( zmsk(ji,jj) == 1._wp ) THEN
-                  ztmp(ji,jj) =   (                                                                                   &
-             &      zenv(iim1,ijp1)*zmsk(iim1,ijp1) + zenv(ji,ijp1)*zmsk(ji,ijp1) + zenv(iip1,ijp1)*zmsk(iip1,ijp1)   &
-             &    + zenv(iim1,jj  )*zmsk(iim1,jj  ) + zenv(ji,jj  )*    2._wp     + zenv(iip1,jj  )*zmsk(iip1,jj  )   &
-             &    + zenv(iim1,ijm1)*zmsk(iim1,ijm1) + zenv(ji,ijm1)*zmsk(ji,ijm1) + zenv(iip1,ijm1)*zmsk(iip1,ijm1)   &
-             &                    ) / (                                                                               &
-             &                      zmsk(iim1,ijp1) +               zmsk(ji,ijp1) +                 zmsk(iip1,ijp1)   &
-             &    +                 zmsk(iim1,jj  ) +                   2._wp     +                 zmsk(iip1,jj  )   &
-             &    +                 zmsk(iim1,ijm1) +               zmsk(ji,ijm1) +                 zmsk(iip1,ijm1)   &
-             &                        )
-               ENDIF
-            END DO
-         END DO
-         !
-         DO jj = 1, nlcj
-            DO ji = 1, nlci
-               IF( zmsk(ji,jj) == 1._wp )   zenv(ji,jj) = MAX( ztmp(ji,jj), bathy(ji,jj) )
-            END DO
-         END DO
-         !
-         ! Apply lateral boundary condition   CAUTION: keep the value when the lbc field is zero
-         ztmp(:,:) = zenv(:,:)   ;   CALL lbc_lnk( zenv, 'T', 1._wp )
-         DO jj = 1, nlcj
-            DO ji = 1, nlci
-               IF( zenv(ji,jj) == 0._wp )   zenv(ji,jj) = ztmp(ji,jj)
-            END DO
-         END DO
+               zenv(ji,jj) = MAX(zenv(ji,jj), ztmpi1(ji,jj), ztmpi2(ji,jj), ztmpj1(ji,jj), ztmpj2(ji,jj) )
+            END DO
+         END DO
+         ! apply lateral boundary condition   CAUTION: keep the value when the lbc field is zero
+         CALL lbc_lnk( zenv, 'T', 1._wp, 'no0' )
          !                                                  ! ================ !
       END DO                                                !     End loop     !
       !                                                     ! ================ !
-      !
-      ! Fill ghost rows with appropriate values to avoid undefined e3 values with some mpp decompositions
-      DO ji = nlci+1, jpi 
-         zenv(ji,1:nlcj) = zenv(nlci,1:nlcj)
-      END DO
-      !
-      DO jj = nlcj+1, jpj
-         zenv(:,jj) = zenv(:,nlcj)
+      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
       !
@@ -1536,5 +1540,5 @@
       END DO
       !
-      CALL wrk_dealloc( jpi, jpj,      zenv, ztmp, zmsk, zri, zrj, zhbat                           )
+      CALL wrk_dealloc( jpi, jpj,      zenv, ztmpi1, ztmpi2, ztmpj1, ztmpj2, zri, zrj, zhbat                           )      !
       !
       IF( nn_timing == 1 )  CALL timing_stop('zgr_sco')
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90	(revision 4229)
@@ -26,4 +26,5 @@
    USE oce             ! ocean dynamics and active tracers 
    USE dom_oce         ! ocean space and time domain 
+   USE c1d             ! 1D vertical configuration
    USE daymod          ! calendar
    USE eosbn2          ! eq. of state, Brunt Vaisala frequency (eos     routine)
@@ -32,4 +33,5 @@
    USE phycst          ! physical constants
    USE dtatsd          ! data temperature and salinity   (dta_tsd routine)
+   USE dtauvd          ! data: U & V current             (dta_uvd routine)
    USE in_out_manager  ! I/O manager
    USE iom             ! I/O library
@@ -70,4 +72,5 @@
       ! - ML - needed for initialization of e3t_b
       INTEGER  ::  jk     ! dummy loop indice
+      REAL(wp), POINTER, DIMENSION(:,:,:,:)  ::  zuvd    ! U & V data workspace
       !!----------------------------------------------------------------------
       !
@@ -80,4 +83,5 @@
 
       CALL dta_tsd_init                       ! Initialisation of T & S input data
+      IF( lk_c1d ) CALL dta_uvd_init          ! Initialization of U & V input data
 
       rhd  (:,:,:  ) = 0.e0
@@ -111,10 +115,19 @@
          ELSEIF( cp_cfg == 'gyre' ) THEN         
             CALL istate_gyre                     ! GYRE  configuration : start from pre-defined T-S fields
-         ELSEIF( ln_tsd_init      ) THEN         ! Initial T-S fields read in files
-            CALL dta_tsd( nit000, tsb )                  ! read 3D T and S data at nit000
-            tsn(:,:,:,:) = tsb(:,:,:,:)
-            !
-         ELSE                                    ! Initial T-S fields defined analytically
-            CALL istate_t_s
+         ELSE                                    ! Initial T-S, U-V fields read in files
+            IF ( ln_tsd_init ) THEN              ! read 3D T and S data at nit000
+               CALL dta_tsd( nit000, tsb )  
+               tsn(:,:,:,:) = tsb(:,:,:,:)
+               !
+            ELSE                                 ! Initial T-S fields defined analytically
+               CALL istate_t_s
+            ENDIF
+            IF ( ln_uvd_init .AND. lk_c1d ) THEN ! read 3D U and V data at nit000
+               CALL wrk_alloc( jpi, jpj, jpk, 2, zuvd )
+               CALL dta_uvd( nit000, zuvd )
+               ub(:,:,:) = zuvd(:,:,:,1) ;  un(:,:,:) = ub(:,:,:)
+               vb(:,:,:) = zuvd(:,:,:,2) ;  vn(:,:,:) = vb(:,:,:)
+               CALL wrk_dealloc( jpi, jpj, jpk, 2, zuvd )
+            ENDIF
          ENDIF
          !
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 4229)
@@ -14,4 +14,5 @@
    USE oce            ! ocean dynamics and tracers variables
    USE dom_oce        ! ocean space and time domain variables
+   USE c1d            ! 1D vertical configuration
    USE phycst         ! physical constants
    USE sbc_oce        ! surface boundary condition: ocean
@@ -220,5 +221,5 @@
       IF(lk_dynspg_flt)   ioptio = ioptio + 1
       !
-      IF( ( ioptio > 1 .AND. .NOT. lk_esopa ) .OR. ioptio == 0 )   &
+      IF( ( ioptio > 1 .AND. .NOT. lk_esopa ) .OR. ( ioptio == 0 .AND. .NOT. lk_c1d ) )   &
            &   CALL ctl_stop( ' Choose only one surface pressure gradient scheme with a key cpp' )
       !
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 4229)
@@ -463,17 +463,35 @@
    !!                   INTERFACE iom_get
    !!----------------------------------------------------------------------
-   SUBROUTINE iom_g0d( kiomid, cdvar, pvar )
+   SUBROUTINE iom_g0d( kiomid, cdvar, pvar, ktime )
       INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
       CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
       REAL(wp)        , INTENT(  out)                 ::   pvar      ! read field
-      !
-      INTEGER               :: idvar   ! variable id
+      INTEGER         , INTENT(in   ),     OPTIONAL   ::   ktime     ! record number
+      !
+      INTEGER                                         ::   idvar     ! variable id
+      INTEGER                                         ::   idmspc    ! number of spatial dimensions
+      INTEGER         , DIMENSION(1)                  ::   itime     ! record number
+      CHARACTER(LEN=100)                              ::   clinfo    ! info character
+      CHARACTER(LEN=100)                              ::   clname    ! file name
+      CHARACTER(LEN=1)                                ::   cldmspc   !
+      !
+      itime = 1
+      IF( PRESENT(ktime) ) itime = ktime
+      !
+      clname = iom_file(kiomid)%name
+      clinfo = '          iom_g0d, file: '//trim(clname)//', var: '//trim(cdvar)
       !
       IF( kiomid > 0 ) THEN
          idvar = iom_varid( kiomid, cdvar )
          IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
+            idmspc = iom_file ( kiomid )%ndims( idvar )
+            IF( iom_file(kiomid)%luld(idvar) )  idmspc = idmspc - 1
+            WRITE(cldmspc , fmt='(i1)') idmspc
+            IF( idmspc > 0 )  CALL ctl_stop( TRIM(clinfo), 'When reading to a 0D array, we do not accept data', &
+                                 &                         'with 1 or more spatial dimensions: '//cldmspc//' were found.' , &
+                                 &                         'Use ncwa -a to suppress the unnecessary dimensions' )
             SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, pvar )
-            CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar )
+            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    
@@ -640,5 +658,5 @@
                ELSE
                   CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,'         ,   &
-                     &                         'we do not accept data with more than '//cldmspc//' spatial dimension',   &
+                     &                         'we do not accept data with '//cldmspc//' spatial dimensions',   &
                      &                         'Use ncwa -a to suppress the unnecessary dimensions' )
                ENDIF
@@ -752,5 +770,5 @@
 
          IF( istop == nstop ) THEN   ! no additional errors until this point...
-            IF(lwp) WRITE(numout,"(10x,' read ',a,' (rec: ',i4,') in ',a,' ok')") TRIM(cdvar), itime, TRIM(iom_file(kiomid)%name)
+            IF(lwp) WRITE(numout,"(10x,' read ',a,' (rec: ',i6,') in ',a,' ok')") TRIM(cdvar), itime, TRIM(iom_file(kiomid)%name)
           
             !--- overlap areas and extra hallows (mpp)
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom_ioipsl.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom_ioipsl.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom_ioipsl.F90	(revision 4229)
@@ -170,4 +170,5 @@
             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
@@ -210,5 +211,5 @@
 
 
-   SUBROUTINE iom_ioipsl_g0d( kiomid, kvid, pvar )
+   SUBROUTINE iom_ioipsl_g0d( kiomid, kvid, pvar, kstart )
       !!-----------------------------------------------------------------------
       !!                  ***  ROUTINE  iom_ioipsl_g0d  ***
@@ -216,9 +217,10 @@
       !! ** 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
-      !
-      CALL fliogetv( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), pvar )
+      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
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 4229)
@@ -216,4 +216,5 @@
          CALL iom_nf90_check(NF90_Inquire_Variable(if90id, ivarid, dimids = idimid(1:i_nvd)), clinfo)   ! dimensions ids
          iom_file(kiomid)%luld(kiv) = .FALSE.   ! default value
+         iom_file(kiomid)%dimsz(:,kiv) = 0   ! reset dimsz in case previously used
          DO ji = 1, i_nvd                       ! dimensions size
             CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, idimid(ji), len = iom_file(kiomid)%dimsz(ji,kiv)), clinfo)   
@@ -249,5 +250,5 @@
 
 
-   SUBROUTINE iom_nf90_g0d( kiomid, kvid, pvar )
+   SUBROUTINE iom_nf90_g0d( kiomid, kvid, pvar, kstart )
       !!-----------------------------------------------------------------------
       !!                  ***  ROUTINE  iom_nf90_g0d  ***
@@ -255,12 +256,13 @@
       !! ** Purpose : read a scalar with NF90
       !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in   ) ::   kiomid   ! Identifier of the file
-      INTEGER , INTENT(in   ) ::   kvid     ! variable id
-      REAL(wp), INTENT(  out) ::   pvar     ! read field
+      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
       !
       CHARACTER(LEN=100)      ::   clinfo   ! info character
       !---------------------------------------------------------------------
       clinfo = 'iom_nf90_g0d , file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid))
-      CALL iom_nf90_check(NF90_GET_VAR(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), pvar), clinfo )
+      CALL iom_nf90_check(NF90_GET_VAR(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), pvar, start = kstart), clinfo )
       ! 
    END SUBROUTINE iom_nf90_g0d
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 4229)
@@ -21,4 +21,5 @@
    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  
@@ -48,5 +49,6 @@
    PUBLIC dia_obs_init, &  ! Initialize and read observations
       &   dia_obs,      &  ! Compute model equivalent to observations
-      &   dia_obs_wri      ! Write model equivalent to observations
+      &   dia_obs_wri,  &  ! Write model equivalent to observations
+      &   dia_obs_dealloc  ! Deallocate dia_obs data
 
    !! * Shared Module variables
@@ -80,4 +82,5 @@
    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  
@@ -167,4 +170,5 @@
          &            nmsshc, mdtcorr, mdtcutoff,                     &
          &            ln_reysst, ln_ghrsst, reysstname, reysstfmt,    &
+         &            ln_sstnight,                                    &
          &            ln_grid_search_lookup,                          &
          &            grid_search_file, grid_search_res,              &
@@ -176,5 +180,5 @@
          &            ln_velhradcp, velhradcpfiles,                   &
          &            ln_velfb, velfbfiles, ln_velfb_av,              &
-         &            ln_profb_enatim, ln_ignmis
+         &            ln_profb_enatim, ln_ignmis, ln_cl4
 
       INTEGER :: jprofset
@@ -226,8 +230,10 @@
       ln_velhradcp = .FALSE.
       ln_velfb = .FALSE.
+      ln_sstnight = .FALSE.
       ln_nea = .FALSE.
       ln_grid_search_lookup = .FALSE.
       ln_grid_global = .FALSE.
       ln_s_at_t = .TRUE.
+      ln_cl4 = .FALSE.
       grid_search_file = 'xypos'
       bias_file='bias.nc'
@@ -357,4 +363,5 @@
          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
@@ -750,5 +757,5 @@
             nsstsets = nsstsets + 1
 
-            ld_sstnight(nsstsets) = .TRUE.
+            ld_sstnight(nsstsets) = ln_sstnight
 
             CALL obs_rea_sst_rey( reysstname, reysstfmt, sstdata(nsstsets), &
@@ -764,5 +771,5 @@
             nsstsets = nsstsets + 1
 
-            ld_sstnight(nsstsets) = .TRUE.
+            ld_sstnight(nsstsets) = ln_sstnight
           
             CALL obs_rea_sst( 1, sstdata(nsstsets), jnumsst, &
@@ -783,5 +790,5 @@
                nsstsets = nsstsets + 1
 
-               ld_sstnight(nsstsets) = .TRUE.
+               ld_sstnight(nsstsets) = ln_sstnight
             
                CALL obs_rea_sst( 0, sstdata(nsstsets), 1, &
@@ -1414,4 +1421,45 @@
    END SUBROUTINE dia_obs_wri
 
+   SUBROUTINE dia_obs_dealloc
+      IMPLICIT NONE
+      !!----------------------------------------------------------------------
+      !!                    *** ROUTINE dia_obs_dealloc ***
+      !!
+      !!  ** Purpose : To deallocate data to enable the obs_oper online loop.
+      !!               Specifically: dia_obs_init --> dia_obs --> dia_obs_wri
+      !!
+      !!  ** Method : Clean up various arrays left behind by the obs_oper.
+      !!
+      !!  ** Action :
+      !!
+      !!----------------------------------------------------------------------
+      !! 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
+   END SUBROUTINE dia_obs_dealloc
+
    SUBROUTINE ini_date( ddobsini )
       !!----------------------------------------------------------------------
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/OBS/mpp_map.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/OBS/mpp_map.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/OBS/mpp_map.F90	(revision 4229)
@@ -52,8 +52,9 @@
       !!----------------------------------------------------------------------
 
-      ALLOCATE( &
-         & mppmap(jpiglo,jpjglo) &
-         & )
-
+      IF (.NOT. ALLOCATED(mppmap)) THEN
+         ALLOCATE( &
+            & mppmap(jpiglo,jpjglo) &
+            & )
+      ENDIF
       ! Initialize local imppmap
 
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_fbm.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_fbm.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_fbm.F90	(revision 4229)
@@ -45,5 +45,9 @@
    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.
 
@@ -1026,4 +1030,31 @@
 
    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  ***
@@ -1524,5 +1555,237 @@
 
       
-   END SUBROUTINE write_obfbdata
+   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
 
    SUBROUTINE putvaratt_obfbdata( idfile, idvar, cdlongname, cdunits, &
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_oper.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_oper.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_oper.F90	(revision 4229)
@@ -861,5 +861,4 @@
 
          ENDIF
-         
          sstdatqc%rmod(jobs,1) = zext(1)
          
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 4229)
@@ -21,4 +21,5 @@
    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
 
@@ -31,5 +32,5 @@
    TYPE, PUBLIC ::   FLD_N      !: Namelist field informations
       CHARACTER(len = 256) ::   clname      ! generic name of the NetCDF flux file
-      INTEGER              ::   nfreqh      ! frequency of each flux file
+      REAL(wp)             ::   nfreqh      ! frequency of each flux file
       CHARACTER(len = 34)  ::   clvar       ! generic name of the variable in the NetCDF flux file
       LOGICAL              ::   ln_tint     ! time interpolation or not (T/F)
@@ -45,5 +46,5 @@
       CHARACTER(len = 256)            ::   clrootname   ! generic name of the NetCDF file
       CHARACTER(len = 256)            ::   clname       ! current name of the NetCDF file
-      INTEGER                         ::   nfreqh       ! frequency of each flux file
+      REAL(wp)                        ::   nfreqh       ! frequency of each flux file
       CHARACTER(len = 34)             ::   clvar        ! generic name of the variable in the NetCDF flux file
       LOGICAL                         ::   ln_tint      ! time interpolation or not (T/F)
@@ -193,5 +194,5 @@
                   sd(jf)%fdta(:,:,:,1) = sd(jf)%fdta(:,:,:,2)   ! re-swap before record field
                   sd(jf)%nrec_b(1) = sd(jf)%nrec_a(1)           ! update before record informations
-                  sd(jf)%nrec_b(2) = sd(jf)%nrec_a(2) - sd(jf)%nfreqh * 3600  ! assume freq to be in hours in this case
+                  sd(jf)%nrec_b(2) = sd(jf)%nrec_a(2) - NINT( sd(jf)%nfreqh * 3600 )  ! assume freq to be in hours in this case
                   sd(jf)%rotn(1)   = sd(jf)%rotn(2)             ! update before rotate informations
                   sd(jf)%nrec_a(1) = itmp                       ! move back to after record 
@@ -211,5 +212,5 @@
                      sd(jf)%fdta(:,:,:,1) = sd(jf)%fdta(:,:,:,2)   ! re-swap before record field
                      sd(jf)%nrec_b(1) = sd(jf)%nrec_a(1)           ! update before record informations
-                     sd(jf)%nrec_b(2) = sd(jf)%nrec_a(2) - sd(jf)%nfreqh * 3600  ! assume freq to be in hours in this case
+                     sd(jf)%nrec_b(2) = sd(jf)%nrec_a(2) - NINT( sd(jf)%nfreqh * 3600 )  ! assume freq to be in hours in this case
                      sd(jf)%rotn(1)   = sd(jf)%rotn(2)             ! update before rotate informations
                      sd(jf)%nrec_a(1) = sd(jf)%nrec_a(1) + 1       ! move back to after record
@@ -264,6 +265,6 @@
             IF( sd(jf)%ln_tint ) THEN              ! temporal interpolation
                IF(lwp .AND. kt - nit000 <= 100 ) THEN 
-                  clfmt = "('fld_read: var ', a, ' kt = ', i8, ' (', f7.2,' days), Y/M/D = ', i4.4,'/', i2.2,'/', i2.2," //   &
-                     &    "', records b/a: ', i4.4, '/', i4.4, ' (days ', f7.2,'/', f7.2, ')')"
+                  clfmt = "('fld_read: var ', a, ' kt = ', i8, ' (', f9.4,' days), Y/M/D = ', i4.4,'/', i2.2,'/', i2.2," //   &
+                     &    "', records b/a: ', i6.4, '/', i6.4, ' (days ', f9.4,'/', f9.4, ')')"
                   WRITE(numout, clfmt)  TRIM( sd(jf)%clvar ), kt, REAL(isecsbc,wp)/rday, nyear, nmonth, nday,   &            
                      & sd(jf)%nrec_b(1), sd(jf)%nrec_a(1), REAL(sd(jf)%nrec_b(2),wp)/rday, REAL(sd(jf)%nrec_a(2),wp)/rday
@@ -277,6 +278,6 @@
             ELSE   ! nothing to do...
                IF(lwp .AND. kt - nit000 <= 100 ) THEN
-                  clfmt = "('fld_read: var ', a, ' kt = ', i8,' (', f7.2,' days), Y/M/D = ', i4.4,'/', i2.2,'/', i2.2," //   &
-                     &    "', record: ', i4.4, ' (days ', f7.2, ' <-> ', f7.2, ')')"
+                  clfmt = "('fld_read: var ', a, ' kt = ', i8,' (', f9.4,' days), Y/M/D = ', i4.4,'/', i2.2,'/', i2.2," //   &
+                     &    "', record: ', i6.4, ' (days ', f9.4, ' <-> ', f9.4, ')')"
                   WRITE(numout, clfmt) TRIM(sd(jf)%clvar), kt, REAL(isecsbc,wp)/rday, nyear, nmonth, nday,    &
                      &                 sd(jf)%nrec_a(1), REAL(sd(jf)%nrec_b(2),wp)/rday, REAL(sd(jf)%nrec_a(2),wp)/rday
@@ -349,18 +350,18 @@
             ELSE                                ! higher frequency mean (in hours) 
                IF    ( sdjf%cltype      == 'monthly' ) THEN   ! monthly file
-                  sdjf%nrec_a(1) = 24 * nmonth_len(nmonth-1) / sdjf%nfreqh                 ! last record of previous month
+                  sdjf%nrec_a(1) = NINT( 24 * nmonth_len(nmonth-1) / sdjf%nfreqh )         ! last record of previous month
                   llprevmth = .TRUE.                                                       ! use previous month file?
                   llprevyr  = llprevmth .AND. nmonth == 1                                  ! use previous year  file?
                ELSEIF( sdjf%cltype(1:4) == 'week'    ) THEN   ! weekly file
                   llprevweek = .TRUE.                                                      ! use previous week  file?
-                  sdjf%nrec_a(1) = 24 * 7 / sdjf%nfreqh                                    ! last record of previous week
+                  sdjf%nrec_a(1) = NINT( 24 * 7 / sdjf%nfreqh )                            ! last record of previous week
                   isec_week = NINT(rday) * 7                                               ! add a shift toward previous week
                ELSEIF( sdjf%cltype      == 'daily'   ) THEN   ! daily file
-                  sdjf%nrec_a(1) = 24 / sdjf%nfreqh                                        ! last record of previous day
+                  sdjf%nrec_a(1) = NINT( 24 / sdjf%nfreqh )                                ! last record of previous day
                   llprevday = .TRUE.                                                       ! use previous day   file?
                   llprevmth = llprevday .AND. nday   == 1                                  ! use previous month file?
                   llprevyr  = llprevmth .AND. nmonth == 1                                  ! use previous year  file?
                ELSE                                           ! yearly file
-                  sdjf%nrec_a(1) = 24 * nyear_len(0) / sdjf%nfreqh                         ! last record of previous year 
+                  sdjf%nrec_a(1) = NINT( 24 * nyear_len(0) / sdjf%nfreqh )                 ! last record of previous year 
                   llprevyr = .NOT. sdjf%ln_clim                                            ! use previous year  file?
                ENDIF
@@ -401,5 +402,5 @@
          CALL fld_get( sdjf, map )
 
-         clfmt = "('fld_init : time-interpolation for ', a, ' read previous record = ', i4, ' at time = ', f7.2, ' days')"
+         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
 
@@ -511,5 +512,5 @@
          !                                   ! ================================ !
          !
-         ifreq_sec = sdjf%nfreqh * 3600                                                 ! frequency mean (in seconds)
+         ifreq_sec = NINT( sdjf%nfreqh * 3600 )                                         ! frequency mean (in seconds)
          IF( sdjf%cltype(1:4) == 'week' )   isec_week = ksec_week( sdjf%cltype(6:8) )   ! since the first day of the current week
          ! number of second since the beginning of the file
@@ -581,4 +582,7 @@
       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
       !!---------------------------------------------------------------------
       !
@@ -598,12 +602,39 @@
          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 )
+         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)
+         !
          SELECT CASE( ipk )
          CASE(1)
-            IF( sdjf%ln_tint ) THEN   ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fdta(:,:,1,2), sdjf%nrec_a(1) )
-            ELSE                      ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fnow(:,:,1  ), sdjf%nrec_a(1) )
+            IF( lk_c1d .AND. lmoor ) THEN
+               IF( sdjf%ln_tint ) THEN
+                  CALL iom_get( sdjf%num, sdjf%clvar, sdjf%fdta(2,2,1,2), sdjf%nrec_a(1) )
+                  CALL lbc_lnk( sdjf%fdta(:,:,1,2),'Z',1. )
+               ELSE
+                  CALL iom_get( sdjf%num, sdjf%clvar, sdjf%fnow(2,2,1  ), sdjf%nrec_a(1) )
+                  CALL lbc_lnk( sdjf%fnow(:,:,1  ),'Z',1. )
+               ENDIF
+            ELSE
+               IF( sdjf%ln_tint ) THEN   ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fdta(:,:,1,2), sdjf%nrec_a(1) )
+               ELSE                      ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fnow(:,:,1  ), sdjf%nrec_a(1) )
+               ENDIF
             ENDIF
          CASE DEFAULT
-            IF( sdjf%ln_tint ) THEN   ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fdta(:,:,:,2), sdjf%nrec_a(1) )
-            ELSE                      ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fnow(:,:,:  ), sdjf%nrec_a(1) )
+            IF (lk_c1d .AND. lmoor ) THEN
+               IF( sdjf%ln_tint ) THEN
+                  CALL iom_get( sdjf%num, jpdom_unknown, sdjf%clvar, sdjf%fdta(2,2,:,2), sdjf%nrec_a(1) )
+                  CALL lbc_lnk( sdjf%fdta(:,:,:,2),'Z',1. )
+               ELSE
+                  CALL iom_get( sdjf%num, jpdom_unknown, sdjf%clvar, sdjf%fnow(2,2,:  ), sdjf%nrec_a(1) )
+                  CALL lbc_lnk( sdjf%fnow(:,:,:  ),'Z',1. )
+               ENDIF
+            ELSE
+               IF( sdjf%ln_tint ) THEN   ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fdta(:,:,:,2), sdjf%nrec_a(1) )
+               ELSE                      ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fnow(:,:,:  ), sdjf%nrec_a(1) )
+               ENDIF
             ENDIF
          END SELECT
@@ -817,8 +848,8 @@
             ENDIF
          ELSE                                                                       ! higher frequency mean (in hours)
-            IF(     sdjf%cltype      == 'monthly' ) THEN   ;   sdjf%nreclast = 24 * imonth_len / sdjf%nfreqh 
-            ELSEIF( sdjf%cltype(1:4) == 'week'    ) THEN   ;   sdjf%nreclast = 24 * 7          / sdjf%nfreqh
-            ELSEIF( sdjf%cltype      == 'daily'   ) THEN   ;   sdjf%nreclast = 24              / sdjf%nfreqh
-            ELSE                                           ;   sdjf%nreclast = 24 * iyear_len  / sdjf%nfreqh 
+            IF(     sdjf%cltype      == 'monthly' ) THEN   ;   sdjf%nreclast = NINT( 24 * imonth_len / sdjf%nfreqh )
+            ELSEIF( sdjf%cltype(1:4) == 'week'    ) THEN   ;   sdjf%nreclast = NINT( 24 * 7          / sdjf%nfreqh )
+            ELSEIF( sdjf%cltype      == 'daily'   ) THEN   ;   sdjf%nreclast = NINT( 24              / sdjf%nfreqh )
+            ELSE                                           ;   sdjf%nreclast = NINT( 24 * iyear_len  / sdjf%nfreqh )
             ENDIF
          ENDIF
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 4229)
@@ -73,5 +73,8 @@
 
    !                                  !!* Namelist namsbc_core : CORE bulk parameters
-   LOGICAL  ::   ln_2m     = .FALSE.   ! logical flag for height of air temp. and hum
+   LOGICAL  ::   ln_2m     = .FALSE.   ! logical flag for case where z(q,t) = 2m and z(u) = 10m
+   LOGICAL  ::   ln_bulk2z = .FALSE.   ! logical flag for case where z(q,t) and z(u) are specified in the namelist
+   REAL(wp) ::   rn_zqt    = 10.       ! z(q,t) : height of humidity and temperature measurements
+   REAL(wp) ::   rn_zu     = 10.       ! z(u)   : height of wind measurements
    LOGICAL  ::   ln_taudif = .FALSE.   ! logical flag to use the "mean of stress module - module of mean stress" data
    REAL(wp) ::   rn_pfac   = 1.        ! multiplication factor for precipitation
@@ -129,5 +132,6 @@
       NAMELIST/namsbc_core/ cn_dir , ln_2m  , ln_taudif, rn_pfac,           &
          &                  sn_wndi, sn_wndj, sn_humi  , sn_qsr ,           &
-         &                  sn_qlw , sn_tair, sn_prec  , sn_snow, sn_tdif
+         &                  sn_qlw , sn_tair, sn_prec  , sn_snow,           &
+         &                  sn_tdif, rn_zqt , ln_bulk2z, rn_zu
       !!---------------------------------------------------------------------
 
@@ -319,4 +323,18 @@
             &                      Cd    , Ch              , Ce  ,   &
             &                      zt_zu , zq_zu                   )
+      ELSE IF( ln_bulk2z ) THEN
+         !! If the height of the air temp./spec. hum. and wind are to be specified by hand :
+         IF( rn_zqt == rn_zu ) THEN
+            !! If air temp. and spec. hum. are at the same height as wind :
+            CALL TURB_CORE_1Z( rn_zu, zst   , sf(jp_tair)%fnow(:,:,1),       &
+               &                      zqsatw, sf(jp_humi)%fnow(:,:,1), wndm, &
+               &                      Cd    , Ch                     , Ce  )
+         ELSE
+            !! If air temp. and spec. hum. are at a different height to wind :
+            CALL TURB_CORE_2Z(rn_zqt, rn_zu , zst   , sf(jp_tair)%fnow,         &
+               &                              zqsatw, sf(jp_humi)%fnow, wndm,   &
+               &                              Cd    , Ch              , Ce  ,   &
+               &                              zt_zu , zq_zu                 )
+         ENDIF
       ELSE
          !! If air temp. and spec. hum. are given at same height than wind (10m) :
@@ -363,6 +381,6 @@
       !  Turbulent fluxes over ocean
       ! -----------------------------
-      IF( ln_2m ) THEN
-         ! Values of temp. and hum. adjusted to 10m must be used instead of 2m values
+      IF( ln_2m .OR. ( ln_bulk2z .AND. rn_zqt /= rn_zu ) ) THEN
+         ! Values of temp. and hum. adjusted to height of wind must be used
          zevap(:,:) = MAX( 0.e0, rhoa    *Ce(:,:)*( zqsatw(:,:) - zq_zu(:,:) ) * wndm(:,:) )   ! Evaporation
          zqsb (:,:) =            rhoa*cpa*Ch(:,:)*( zst   (:,:) - zt_zu(:,:) ) * wndm(:,:)     ! Sensible Heat
@@ -786,6 +804,6 @@
       !!      Momentum, Latent and sensible heat exchange coefficients
       !!      Caution: this procedure should only be used in cases when air
-      !!      temperature (T_air) and air specific humidity (q_air) are at 2m
-      !!      whereas wind (dU) is at 10m.
+      !!      temperature (T_air) and air specific humidity (q_air) are at a
+      !!      different height to wind (dU).
       !!
       !! References :   Large & Yeager, 2004 : ???
@@ -805,5 +823,5 @@
 
       INTEGER :: j_itt
-      INTEGER , PARAMETER :: nb_itt = 3              ! number of itterations
+      INTEGER , PARAMETER :: nb_itt = 5              ! number of itterations
       REAL(wp), PARAMETER ::   grav   = 9.8          ! gravity                       
       REAL(wp), PARAMETER ::   kappa  = 0.4          ! von Karman's constant
@@ -902,5 +920,5 @@
            !!
            !! Shifting the neutral 10m transfer coefficients to (zu,zeta_u) :
-           xct = 1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m)
+           xct = 1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m)   ! L & Y eq. (10a)
            Cd = Cd_n10/(xct*xct) ; sqrt_Cd = sqrt(Cd)
          ENDIF
@@ -908,8 +926,8 @@
          xlogt = log(zu/10.) - zpsi_hu
          !!
-         xct = 1. + Ch_n10*xlogt/kappa/sqrt_Cd_n10
+         xct = 1. + Ch_n10*xlogt/kappa/sqrt_Cd_n10               ! L & Y eq. (10b)
          Ch  = Ch_n10*sqrt_Cd/sqrt_Cd_n10/xct
          !!
-         xct = 1. + Ce_n10*xlogt/kappa/sqrt_Cd_n10
+         xct = 1. + Ce_n10*xlogt/kappa/sqrt_Cd_n10               ! L & Y eq. (10c)
          Ce  = Ce_n10*sqrt_Cd/sqrt_Cd_n10/xct
          !!
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 4229)
@@ -27,4 +27,5 @@
    USE oce            ! ocean: variables
    USE dom_oce        ! ocean: domain variables
+   USE c1d            ! 1D vertical configuration
    USE trdmod_oce     ! ocean: trend variables
    USE trdtra         ! active tracers: trends
@@ -44,15 +45,15 @@
    PUBLIC   tra_dmp      ! routine called by step.F90
    PUBLIC   tra_dmp_init ! routine called by opa.F90
-   PUBLIC   dtacof       ! routine called by in both tradmp.F90 and trcdmp.F90
-   PUBLIC   dtacof_zoom  ! routine called by in both tradmp.F90 and trcdmp.F90
+   PUBLIC   dtacof       ! routine called by tradmp.F90, trcdmp.F90 and dyndmp.F90
+   PUBLIC   dtacof_zoom  ! routine called by tradmp.F90, trcdmp.F90 and dyndmp.F90
 
    !                                !!* Namelist namtra_dmp : T & S newtonian damping *
-   LOGICAL, PUBLIC ::   ln_tradmp = .TRUE.    !: internal damping flag
-   INTEGER         ::   nn_hdmp   =   -1      ! = 0/-1/'latitude' for damping over T and S
-   INTEGER         ::   nn_zdmp   =    0      ! = 0/1/2 flag for damping in the mixed layer
-   REAL(wp)        ::   rn_surf   =   50._wp  ! surface time scale for internal damping        [days]
-   REAL(wp)        ::   rn_bot    =  360._wp  ! bottom time scale for internal damping         [days]
-   REAL(wp)        ::   rn_dep    =  800._wp  ! depth of transition between rn_surf and rn_bot [meters]
-   INTEGER         ::   nn_file   =    2      ! = 1 create a damping.coeff NetCDF file 
+   LOGICAL , PUBLIC ::   ln_tradmp = .TRUE.    !: internal damping flag
+   INTEGER , PUBLIC ::   nn_hdmp   =   -1      ! = 0/-1/'latitude' for damping over T and S
+   INTEGER , PUBLIC ::   nn_zdmp   =    0      ! = 0/1/2 flag for damping in the mixed layer
+   REAL(wp), PUBLIC ::   rn_surf   =   50._wp  ! surface time scale for internal damping        [days]
+   REAL(wp), PUBLIC ::   rn_bot    =  360._wp  ! bottom time scale for internal damping         [days]
+   REAL(wp), PUBLIC ::   rn_dep    =  800._wp  ! depth of transition between rn_surf and rn_bot [meters]
+   INTEGER , PUBLIC ::   nn_file   =    2      ! = 1 create a damping.coeff NetCDF file 
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   strdmp   !: damping salinity trend (psu/s)
@@ -191,5 +192,5 @@
       !! ** Purpose :   Initialization for the newtonian damping 
       !!
-      !! ** Method  :   read the nammbf namelist and check the parameters
+      !! ** Method  :   read the namtra_dmp namelist and check the parameters
       !!----------------------------------------------------------------------
       NAMELIST/namtra_dmp/ ln_tradmp, nn_hdmp, nn_zdmp, rn_surf, rn_bot, rn_dep, nn_file
@@ -199,5 +200,5 @@
       READ   ( numnam, namtra_dmp )
       
-      IF( lzoom )   nn_zdmp = 0          ! restoring to climatology at closed north or south boundaries
+      IF( lzoom .AND. .NOT. lk_c1d )   nn_zdmp = 0          ! restoring to climatology at closed north or south boundaries
 
       IF(lwp) THEN                       ! Namelist print
@@ -206,7 +207,7 @@
          WRITE(numout,*) '~~~~~~~'
          WRITE(numout,*) '   Namelist namtra_dmp : set damping parameter'
-         WRITE(numout,*) '      add a damping termn or not      ln_tradmp = ', ln_tradmp
+         WRITE(numout,*) '      add a damping term or not       ln_tradmp = ', ln_tradmp
          WRITE(numout,*) '      T and S damping option          nn_hdmp   = ', nn_hdmp
-         WRITE(numout,*) '      mixed layer damping option      nn_zdmp   = ', nn_zdmp, '(zoom: forced to 0)'
+         WRITE(numout,*) '      mixed layer damping option      nn_zdmp   = ', nn_zdmp, '(non-C1D zoom: forced to 0)'
          WRITE(numout,*) '      surface time scale (days)       rn_surf   = ', rn_surf
          WRITE(numout,*) '      bottom time scale (days)        rn_bot    = ', rn_bot
@@ -220,4 +221,5 @@
          IF( tra_dmp_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'tra_dmp_init: unable to allocate arrays' )
          !
+#if ! defined key_c1d
          SELECT CASE ( nn_hdmp )
          CASE (  -1  )   ;   IF(lwp) WRITE(numout,*) '   tracer damping in the Med & Red seas only'
@@ -228,4 +230,5 @@
          END SELECT
          !
+#endif
          SELECT CASE ( nn_zdmp )
          CASE ( 0 )   ;   IF(lwp) WRITE(numout,*) '   tracer damping throughout the water column'
@@ -245,5 +248,5 @@
          ttrdmp(:,:,:) = 0._wp
          !                          ! Damping coefficients initialization
-         IF( lzoom ) THEN   ;   CALL dtacof_zoom( resto )
+         IF( lzoom .AND. .NOT. lk_c1d ) THEN   ;   CALL dtacof_zoom( resto )
          ELSE               ;   CALL dtacof( nn_hdmp, rn_surf, rn_bot, rn_dep, nn_file, 'TRA', resto )
          ENDIF
@@ -353,5 +356,5 @@
       REAL(wp)                        , INTENT(in   )  ::  pn_dep     ! depth of transition (meters)
       INTEGER                         , INTENT(in   )  ::  kn_file    ! save the damping coef on a file or not
-      CHARACTER(len=3)                , INTENT(in   )  ::  cdtype     ! =TRA or TRC (tracer indicator)
+      CHARACTER(len=3)                , INTENT(in   )  ::  cdtype     ! =TRA, TRC or DYN (tracer/dynamics indicator)
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout)  ::  presto     ! restoring coeff. (s-1)
       !
@@ -373,4 +376,28 @@
       CALL wrk_alloc( jpi, jpj, zmrs      )
       CALL wrk_alloc( jpi, jpj, jpk, zdct )
+#if defined key_c1d
+      !                                   ! ====================
+      !                                   !  C1D configuration : local domain
+      !                                   ! ====================
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '              dtacof : C1D 3x3 local domain'
+      IF(lwp) WRITE(numout,*) '              -----------------------------'
+      !
+      presto(:,:,:) = 0._wp
+      !
+      zsdmp = 1._wp / ( pn_surf * rday )
+      zbdmp = 1._wp / ( pn_bot  * rday )
+      DO jk = 2, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               !   ONLY vertical variation from zsdmp (sea surface) to zbdmp (bottom)
+               presto(ji,jj,jk) = zbdmp + (zsdmp-zbdmp) * EXP(-fsdept(ji,jj,jk)/pn_dep)
+            END DO
+         END DO
+      END DO
+      !
+      presto(:,:, : ) = presto(:,:,:) * tmask(:,:,:)
+#else
       !                                   ! ====================
       !                                   !  ORCA configuration : global domain
@@ -552,4 +579,5 @@
          CALL ctl_stop( 'Choose a correct value of nn_hdmp or put ln_tradmp to FALSE' )
       ENDIF
+#endif
 
       !                            !--------------------------------!
@@ -559,4 +587,5 @@
          IF( cdtype == 'TRA' ) cfile = 'damping.coeff'
          IF( cdtype == 'TRC' ) cfile = 'damping.coeff.trc'
+         IF( cdtype == 'DYN' ) cfile = 'damping.coeff.dyn'
          cfile = TRIM( cfile )
          CALL iom_open  ( cfile, inum0, ldwrt = .TRUE., kiolib = jprstlib )
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 4229)
@@ -76,4 +76,5 @@
    USE c1d             ! 1D configuration
    USE step_c1d        ! Time stepping loop for the 1D configuration
+   USE dyndmp          ! Momentum damping
 #if defined key_top
    USE trcini          ! passive tracer initialisation
@@ -328,4 +329,5 @@
                             CALL     phy_cst    ! Physical constants
                             CALL     eos_init   ! Equation of state
+      IF( lk_c1d        )   CALL     c1d_init   ! 1D column configuration
                             CALL     dom_cfg    ! Domain configuration
                             CALL     dom_init   ! Domain
@@ -368,5 +370,5 @@
                             CALL tra_bbc_init   ! bottom heat flux
       IF( lk_trabbl     )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
-      IF( ln_tradmp     )   CALL tra_dmp_init   ! internal damping trends
+                            CALL tra_dmp_init   ! internal damping trends- tracers
                             CALL tra_adv_init   ! horizontal & vertical advection
                             CALL tra_ldf_init   ! lateral mixing
@@ -374,4 +376,5 @@
 
       !                                     ! Dynamics
+      IF( lk_c1d        )   CALL dyn_dmp_init   ! internal damping trends- momentum
                             CALL dyn_adv_init   ! advection (vector or flux form)
                             CALL dyn_vor_init   ! vorticity term including Coriolis
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_AMM_12km.h90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_AMM_12km.h90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_AMM_12km.h90	(revision 4229)
@@ -4,84 +4,101 @@
    !!                  (AMM_12km configuration VN3.3)
    !!---------------------------------------------------------------------
-   CHARACTER (len=16)        &
+   CHARACTER (len=16)         &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::    &  
-      cp_cfg = "amm"         !: name of the configuration
-   INTEGER                   &
+      ::                      &  
+      cp_cfg  =  "amm"           !: Name of the configuration
+   INTEGER                    &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::    &  
-      jp_cfg = 011  ,        &  !: resolution of the configuration (degrees)
-      ! Original data size
-      jpidta  = 198,        &  !: first horizontal dimension > or = to jpi
-      jpjdta  = 224,        &  !: second                     > or = to jpj
-      jpkdta  = 51,         &  !: number of levels           > or = to jpk
-      ! total domain matrix size
-      jpiglo  = jpidta,      &  !: first  dimension of global domain --> i
-      jpjglo  = jpjdta,      &  !: second dimension of global domain --> j
-      ! starting position of the zoom
-      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   1   ,      &  !: in data indices
+      ::                      &
+      jp_cfg  =  011   ,      &  !: Resolution of the configuration (degrees)
+
+      ! Data domain size         !!! *  Size of all input files  *
+      jpidta  =  198   ,      &  !: 1st lateral dimension ( >= jpiglo )
+      jpjdta  =  224   ,      &  !: 2nd lateral dimension ( >= jpjglo )
+      jpkdta  =  51    ,      &  !: Number of levels      ( >= jpk    )
+
+#if defined key_c1d
+      ! Zoom domain size         !!! *  C1D zoom  *
+      jpiglo  =  3     ,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  3     ,      &  !: 2nd dimension of global domain --> j
       ! Domain characteristics
-      jperio  =    0            !: lateral cond. type (between 0 and 6)
+      jperio  =  0               !: Lateral cond. type (between 0 and 6)
+
+   INTEGER                    &
+      ::                      &
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1               !: in data domain indices
+#else
+      ! Global domain size       !!! *  Global domain  *
+      jpiglo  =  jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  jpjdta,      &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1     ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =  0               !: Lateral cond. type (between 0 and 6)
+#endif
+
 
    !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
    !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
-   REAL,PARAMETER      ::  pp_not_used = 999999_wp , &
-      &                    pp_to_be_computed = 0._wp
-   !!
-   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
-   !!
-   INTEGER, PARAMETER ::     & !
-      jphgr_msh = 0            !: type of horizontal mesh
-      !                        !  = 0 curvilinear coordinate on the sphere
-      !                        !      read in coordinate.nc file
-      !                        !  = 1 geographical mesh on the sphere
-      !                        !      with regular grid-spacing
-      !                        !  = 2 f-plane with regular grid-spacing
-      !                        !  = 3 beta-plane with regular grid-spacing
-      !                        !  = 4 Mercator grid with T/U point at the equator  with
-      !                        !      isotropic resolution (e1_deg)
+
+   REAL(wp), PARAMETER ::              &
+      pp_not_used       = 999999._wp , &  !:
+      pp_to_be_computed = 0._wp           !:
+
+
+   !! Coefficients associated with the horizontal coordinate system
+
+   INTEGER, PARAMETER  ::     &
+      jphgr_msh = 0              !: type of horizontal mesh
+      !                          !: = 0 curvilinear coordinate on the sphere
+      !                          !:     read in coordinate.nc file
+      !                          !: = 1 geographical mesh on the sphere
+      !                          !:     with regular grid-spacing
+      !                          !: = 2 f-plane with regular grid-spacing
+      !                          !: = 3 beta-plane with regular grid-spacing
+      !                          !: = 4 Mercator grid with T/U point at the equator  with
+      !                          !:     isotropic resolution (e1_deg)
 
       !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
       !   The mercator grid starts only approximately at gphi0 because
       !   of the constraint that the equator be a T point.
-   REAL(wp), PARAMETER ::       &  !
-      ppglam0  = pp_not_used,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
-      ppgphi0  = pp_not_used,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
-      !                            !  latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
-      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
-      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+
+   REAL(wp), PARAMETER ::     &
+      ppglam0  = pp_not_used, &  !: longitude of first raw and column T-point   (jphgr_msh = 1)
+      ppgphi0  = pp_not_used, &  !: latitude  of first raw and column T-point   (jphgr_msh = 1)
+      !                          !: latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used, &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used, &  !: meridional grid-spacing (degrees)
       !
-      ppe1_m   = pp_not_used,   &  !: zonal      grid-spacing (meters )
-      ppe2_m   = pp_not_used       !: meridional grid-spacing (meters )
+      ppe1_m   = pp_not_used, &  !: zonal      grid-spacing (meters )
+      ppe2_m   = pp_not_used     !: meridional grid-spacing (meters )
 
-   !!
-   !! Vertical grid parameter for domzgr
-   !! ==================================
-   !!
-   REAL(wp), PARAMETER  ::       &
-      &     ppsur = pp_to_be_computed ,  &  !: Computed in domzgr, set ppdzmin and pphmax below
-      &     ppa0  = pp_to_be_computed ,  &  !:    "           "
-      &     ppa1  = pp_to_be_computed ,  &  !:    "           "
-      !
-      &     ppkth =  23.563_wp        ,  &  !: (non dimensional): gives the approximate
-      !                                     !: layer number above which  stretching will
-      !                                     !: be maximum. Usually of order jpk/2.
-      &     ppacr =    9.00000000000_wp     !: (non dimensional): stretching factor
-      !                                     !: for the grid. The highest zacr, the smallest
-      !                                     !: the stretching.
 
-   !!
-   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
-   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
-   !!
-   REAL(wp), PARAMETER ::        &
-      &     ppdzmin = 6._wp           ,  &  !: (meters) vertical thickness of the top layer
-      &     pphmax  = 5720._wp              !: (meters) Maximum depth of the ocean gdepw(jpk)
-   !!
+   !!  Coefficients associated with the vertical coordinate system
+
+   REAL(wp), PARAMETER  ::                     &
+      &     ppsur =   pp_to_be_computed     ,  &  !: Computed in domzgr, set ppdzmin and pphmax below
+      &     ppa0  =   pp_to_be_computed     ,  &  !:    "           "
+      &     ppa1  =   pp_to_be_computed     ,  &  !:    "           "
+      &     ppkth =   23.563_wp             ,  &  !: (non dimensional): gives the approximate
+      !                                           !: layer number above which  stretching will
+      !                                           !: be maximum. Usually of order jpk/2.
+      &     ppacr =   9.00000000000_wp            !: (non dimensional): stretching factor
+      !                                           !: for the grid. The higher zacr, the smaller
+      !                                           !: the stretching.
+
+      !  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
+      !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+
+   REAL(wp), PARAMETER ::                      &
+      &     ppdzmin = 6._wp                 ,  &  !: (meters) vertical thickness of the top layer
+      &     pphmax  = 5720._wp                    !: (meters) Maximum depth of the ocean gdepw(jpk)
    LOGICAL,  PARAMETER ::                      &
       &     ldbletanh = .FALSE.                   !: Use/do not use double tanf function for vertical coordinates
@@ -90,4 +107,3 @@
       &     ppkth2  = pp_not_used           ,  &  !:
       &     ppacr2  = pp_not_used                 !:
-
    !!---------------------------------------------------------------------
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_EEL_R2.h90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_EEL_R2.h90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_EEL_R2.h90	(revision 4229)
@@ -8,92 +8,108 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-   CHARACTER (len=16)      &
+   CHARACTER (len=16)         &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::    &  
-      cp_cfg = "eel"            !: name of the configuration
-   INTEGER     &
+      ::                      &  
+      cp_cfg  =  "eel"           !: Name of the configuration
+   INTEGER                    &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      :: &
-      jp_cfg = 2   ,         &  !: resolution of the configuration (km)
+      ::                      &
+      jp_cfg  =  2     ,      &  !: Resolution of the configuration (km)
 
-      ! data size              !!! * size of all the input files *
-      jpidta  = 83,          &  !: 1st horizontal dimension ( >= jpi )
-      jpjdta  = 242,         &  !: 2nd    "            "    ( >= jpj )
-      jpkdta  = 30,          &  !: number of levels         ( >= jpk )
+      ! Data domain size         !!! *  Size of all input files  *
+      jpidta  =  83    ,      &  !: 1st lateral dimension ( >= jpiglo )
+      jpjdta  =  242   ,      &  !: 2nd lateral dimension ( >= jpjglo )
+      jpkdta  =  30    ,      &  !: Number of levels      ( >= jpk    )
 
-      ! global domain size     !!! * full domain *
-      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
-      jpjglo  = jpjdta,      &  !: 2nd    "                  "    --> j
-      ! zoom starting position
-      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   1   ,      &  !: in data indices
+#if defined key_c1d
+      ! Zoom domain size         !!! *  C1D zoom  *
+      jpiglo  =  3     ,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  3     ,      &  !: 2nd dimension of global domain --> j
+      ! Domain characteristics
+      jperio  =  0               !: Lateral cond. type (between 0 and 6)
 
+   INTEGER                    &
+      ::                      &
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1               !: in data domain indices
+#else
+      ! Global domain size       !!! *  Global domain  *
+      jpiglo  =  jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  jpjdta,      &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1     ,      &  !: in data domain indices
       ! Domain characteristics
-      jperio  =     1           !: lateral cond. type (between 0 and 6)
+      jperio  =  1               !: Lateral cond. type (between 0 and 6)
+#endif
+
 
    !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
    !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
-   REAL(wp), PARAMETER ::   &  !:
-      pp_not_used       = 999999._wp  , & !: ???
-      pp_to_be_computed =      0._wp      !: ???
-   !!
-   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
-   !!
-   INTEGER,PARAMETER   ::    & !:
-      jphgr_msh = 3            !: type of horizontal mesh
-      !                        ! = 0 curvilinear coordinate on the sphere
-      !                        !     read in coordinate.nc file
-      !                        ! = 1 geographical mesh on the sphere
-      !                        !     with regular grid-spacing
-      !                        ! = 2 f-plane with regular grid-spacing
-      !                        ! = 3 beta-plane with regular grid-spacing
-      !                        ! = 4 Mercator grid with T/U point at the equator  with
-      !                        !     isotropic resolution (e1_deg)
+
+   REAL(wp), PARAMETER ::              &
+      pp_not_used       = 999999._wp , &  !:
+      pp_to_be_computed = 0._wp           !:
+
+
+   !! Coefficients associated with the horizontal coordinate system
+
+   INTEGER, PARAMETER  ::     &
+      jphgr_msh = 3              !: type of horizontal mesh
+      !                          !: = 0 curvilinear coordinate on the sphere
+      !                          !:     read in coordinate.nc file
+      !                          !: = 1 geographical mesh on the sphere
+      !                          !:     with regular grid-spacing
+      !                          !: = 2 f-plane with regular grid-spacing
+      !                          !: = 3 beta-plane with regular grid-spacing
+      !                          !: = 4 Mercator grid with T/U point at the equator  with
+      !                          !:     isotropic resolution (e1_deg)
 
       !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
       !   The mercator grid starts only approximately at gphi0 because
       !   of the constraint that the equator be a T point.
-   REAL(wp) ,PARAMETER ::     &  !:
-      ppglam0  =    0.0_wp,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
-      ppgphi0  =   35.0_wp,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
-      !                          ! latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
-      ppe1_deg = pp_not_used ,   &  !: zonal      grid-spacing (degrees)
-      ppe2_deg = pp_not_used ,   &  !: meridional grid-spacing (degrees)
+
+   REAL(wp), PARAMETER ::     &
+      ppglam0  = 0.0_wp     , &  !: longitude of first raw and column T-point   (jphgr_msh = 1)
+      ppgphi0  = 35.0_wp    , &  !: latitude  of first raw and column T-point   (jphgr_msh = 1)
+      !                          !: latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used, &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used, &  !: meridional grid-spacing (degrees)
       !
-      ppe1_m   = 2000.0_wp,   &  !: zonal      grid-spacing (meters )
+      ppe1_m   = 2000.0_wp  , &  !: zonal      grid-spacing (meters )
       ppe2_m   = 2000.0_wp       !: meridional grid-spacing (meters )
-   !!
+
+
    !!  Coefficients associated with the vertical coordinate system
-   !!
-   REAL(wp) &
+
+   REAL(wp)                                    &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER                              &
 #endif
-      ::     &  !:
-      &     ppsur = -2033.194295283385_wp   ,  &  !: Computed in domzgr
-      &     ppa0  =  155.8325369664153_wp   ,  &  !:
-      &     ppa1  =  146.3615918601890_wp   ,  &  !:
-      !
-      &     ppkth =  17.28520372419791_wp   ,  &  !: (non dimensional): gives the approximate
+      ::                                       &	
+      &     ppsur =   -2033.194295283385_wp ,  &  !: Computed in domzgr, set ppdzmin, pphmax below
+      &     ppa0  =   155.8325369664153_wp  ,  &  !:
+      &     ppa1  =   146.3615918601890_wp  ,  &  !:
+      &     ppkth =   17.28520372419791_wp  ,  &  !: (non dimensional): gives the approximate
       !                                           !: layer number above which  stretching will
       !                                           !: be maximum. Usually of order jpk/2.
-      &     ppacr =  5.000000000000000_wp         !: (non dimensional): stretching factor
-      !                                           !: for the grid. The highest zacr, the smallest
+      &     ppacr =   5.000000000000000_wp        !: (non dimensional): stretching factor
+      !                                           !: for the grid. The higher zacr, the smaller
       !                                           !: the stretching.
 
-   !!
-   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
-   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
-   !!
-   REAL(wp), PARAMETER ::        &
+      !  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
+      !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+
+   REAL(wp), PARAMETER ::                      &
       &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
       &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
-   LOGICAL,  PARAMETER ::        &
+   LOGICAL,  PARAMETER ::                      &
       &     ldbletanh = .FALSE.                   !: Use/do not use double tanf function for vertical coordinates
-   REAL(wp), PARAMETER ::        &
+   REAL(wp), PARAMETER ::                      &
       &     ppa2    = pp_not_used           ,  &  !: Double tanh function parameters
       &     ppkth2  = pp_not_used           ,  &  !:
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_EEL_R5.h90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_EEL_R5.h90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_EEL_R5.h90	(revision 4229)
@@ -8,92 +8,108 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-   CHARACTER (len=16)      &
+   CHARACTER (len=16)         &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::    &  
-      cp_cfg = "eel"            !: name of the configuration
-   INTEGER     &
+      ::                      &  
+      cp_cfg  =  "eel"           !: Name of the configuration
+   INTEGER                    &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      :: &
-      jp_cfg = 5      ,      &  !: resolution of the configuration (km)
+      ::                      &
+      jp_cfg  =  5     ,      &  !: Resolution of the configuration (km)
 
-      ! data size              !!! * size of all the input files
-      jpidta  =  66   ,      &  !: first horizontal dimension > or = to jpi
-      jpjdta  =  66   ,      &  !: second                     > or = to jpj
-      jpkdta  =  31   ,      &  !: number of levels           > or = to jpk
+      ! Data domain size         !!! *  Size of all input files  *
+      jpidta  =  66    ,      &  !: 1st lateral dimension ( >= jpiglo )
+      jpjdta  =  66    ,      &  !: 2nd lateral dimension ( >= jpjglo )
+      jpkdta  =  31    ,      &  !: Number of levels      ( >= jpk    )
 
-      ! total domain size      !!! * full domain *
-      jpiglo  = jpidta,      &  !: first  dimension of global domain --> i
-      jpjglo  = jpjdta,      &  !: second dimension of global domain --> j
-      ! zoom starting position
-      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   1   ,      &  !: in data indices
+#if defined key_c1d
+      ! Zoom domain size         !!! *  C1D zoom  *
+      jpiglo  =  3     ,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  3     ,      &  !: 2nd dimension of global domain --> j
+      ! Domain characteristics
+      jperio  =  0               !: Lateral cond. type (between 0 and 6)
 
+   INTEGER                    &
+      ::                      &
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1               !: in data domain indices
+#else
+      ! Global domain size       !!! *  Global domain  *
+      jpiglo  =  jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  jpjdta,      &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1     ,      &  !: in data domain indices
       ! Domain characteristics
-      jperio  =   1             !: lateral cond. type (between 0 and 6)
+      jperio  =  1               !: Lateral cond. type (between 0 and 6)
+#endif
+
 
    !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
    !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
-   REAL(wp), PARAMETER ::   &  !:
-      pp_not_used       = 999999._wp ,  &  !:
-      pp_to_be_computed =      0._wp       !:
 
-   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   REAL(wp), PARAMETER ::              &
+      pp_not_used       = 999999._wp , &  !:
+      pp_to_be_computed = 0._wp           !:
 
-   INTEGER,PARAMETER   ::    & !:
-      jphgr_msh = 2            !: type of horizontal mesh
-      !                        ! = 0 curvilinear coordinate on the sphere
-      !                        !     read in coordinate.nc file
-      !                        ! = 1 geographical mesh on the sphere
-      !                        !     with regular grid-spacing
-      !                        ! = 2 f-plane with regular grid-spacing
-      !                        ! = 3 beta-plane with regular grid-spacing
-      !                        ! = 4 Mercator grid with T/U point at the equator  with
-      !                        !     isotropic resolution (e1_deg)
+
+   !! Coefficients associated with the horizontal coordinate system
+
+   INTEGER, PARAMETER  ::     &
+      jphgr_msh = 2              !: type of horizontal mesh
+      !                          !: = 0 curvilinear coordinate on the sphere
+      !                          !:     read in coordinate.nc file
+      !                          !: = 1 geographical mesh on the sphere
+      !                          !:     with regular grid-spacing
+      !                          !: = 2 f-plane with regular grid-spacing
+      !                          !: = 3 beta-plane with regular grid-spacing
+      !                          !: = 4 Mercator grid with T/U point at the equator  with
+      !                          !:     isotropic resolution (e1_deg)
 
       !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
       !   The mercator grid starts only approximately at gphi0 because
       !   of the constraint that the equator be a T point.
-   REAL(wp) &
+
+   REAL(wp)                       &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER                 &
 #endif
-      ::     &  !:
-      ppglam0  =    0.0_wp,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
-      ppgphi0  = 43.436430714_wp,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
-      !                          ! latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
-      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
-      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+      ::                          &
+      ppglam0  = 0.0_wp         , &  !: longitude of first raw and column T-point   (jphgr_msh = 1)
+      ppgphi0  = 43.436430714_wp, &  !: latitude  of first raw and column T-point   (jphgr_msh = 1)
+      !                              !: latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used    , &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used    , &  !: meridional grid-spacing (degrees)
       !
-      ppe1_m   = 8000.0_wp,   &  !: zonal      grid-spacing (meters)
-      ppe2_m   = 8000.0_wp       !: meridional grid-spacing (meters)
-   !!
+      ppe1_m   = 8000.0_wp      , &  !: zonal      grid-spacing (meters )
+      ppe2_m   = 8000.0_wp           !: meridional grid-spacing (meters )
+
+
    !!  Coefficients associated with the vertical coordinate system
-   !!
-   REAL(wp), PARAMETER  ::       &   !:
-      &     ppsur = -4762.96143546300_wp    ,  &  !: Computed in domzgr, set ppdzmin, pphmax below
+
+   REAL(wp), PARAMETER  ::                     &
+      &     ppsur =   -4762.96143546300_wp  ,  &  !: Computed in domzgr, set ppdzmin, pphmax below
       &     ppa0  =   255.58049070440_wp    ,  &  !:
       &     ppa1  =   245.58132232490_wp    ,  &  !:
-      !
-      &     ppkth =    21.43336197938_wp    ,  &  !: (non dimensional): gives the approximate
+      &     ppkth =   21.43336197938_wp     ,  &  !: (non dimensional): gives the approximate
       !                                           !: layer number above which  stretching will
       !                                           !: be maximum. Usually of order jpk/2.
-      &     ppacr =     3.00000000000_wp          !: (non dimensional): stretching factor
-      !                                           !: for the grid. The highest zacr, the smallest
+      &     ppacr =   3.00000000000_wp            !: (non dimensional): stretching factor
+      !                                           !: for the grid. The higher zacr, the smaller
       !                                           !: the stretching.
 
-   !!
-   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
-   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
-   !!
-   REAL(wp), PARAMETER ::        &  !:
+      !  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
+      !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+
+   REAL(wp), PARAMETER ::                      &
       &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
       &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
-   LOGICAL,  PARAMETER ::        &
+   LOGICAL,  PARAMETER ::                      &
       &     ldbletanh = .FALSE.                   !: Use/do not use double tanf function for vertical coordinates
-   REAL(wp), PARAMETER ::        &
+   REAL(wp), PARAMETER ::                      &
       &     ppa2    = pp_not_used           ,  &  !: Double tanh function parameters
       &     ppkth2  = pp_not_used           ,  &  !:
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_EEL_R6.h90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_EEL_R6.h90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_EEL_R6.h90	(revision 4229)
@@ -8,92 +8,108 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-   CHARACTER (len=16)      &
+   CHARACTER (len=16)         &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::    &  
-      cp_cfg = "eel"            !: name of the configuration
-   INTEGER     &
+      ::                      &  
+      cp_cfg  =  "eel"           !: Name of the configuration
+   INTEGER                    &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::     &
-      jp_cfg = 6      ,      &  !: resolution of the configuration (km)
+      ::                      &
+      jp_cfg  =  6     ,      &  !: Resolution of the configuration (km)
 
-      ! data size              !!! * size of all the input files *
-      jpidta  = 29,          &  !: 1st lateral dimension ( >= jpi )
-      jpjdta  = 83,          &  !: 2nd    "         "    ( >= jpj )
-      jpkdta  = 30,          &  !: number of levels      ( >= jpk )
+      ! Data domain size         !!! *  Size of all input files  *
+      jpidta  =  29    ,      &  !: 1st lateral dimension ( >= jpiglo )
+      jpjdta  =  83    ,      &  !: 2nd lateral dimension ( >= jpjglo )
+      jpkdta  =  30    ,      &  !: Number of levels      ( >= jpk    )
 
-      ! global domain size     !!! * full domain *
-      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
-      jpjglo  = jpjdta,      &  !: 2nd    "                  "    --> j
-      ! starting position of the zoom
-      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   1   ,      &  !: in data domain indices
+#if defined key_c1d
+      ! Zoom domain size         !!! *  C1D zoom  *
+      jpiglo  =  3     ,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  3     ,      &  !: 2nd dimension of global domain --> j
+      ! Domain characteristics
+      jperio  =  0               !: Lateral cond. type (between 0 and 6)
 
+   INTEGER                    &
+      ::                      &
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1               !: in data domain indices
+#else
+      ! Global domain size       !!! *  Global domain  *
+      jpiglo  =  jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  jpjdta,      &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1     ,      &  !: in data domain indices
       ! Domain characteristics
-      jperio  =      1          !: lateral cond. type (between 0 and 6)
+      jperio  =  1               !: Lateral cond. type (between 0 and 6)
+#endif
+
 
    !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
    !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
-   REAL(wp), PARAMETER ::   &  !:
-      pp_not_used       = 999999._wp ,  &  !: ???
-      pp_to_be_computed =      0._wp       !: ???
 
-   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   REAL(wp), PARAMETER ::              &
+      pp_not_used       = 999999._wp , &  !:
+      pp_to_be_computed = 0._wp           !:
 
-   INTEGER,PARAMETER   ::    & !:
-      jphgr_msh = 3            !: type of horizontal mesh
-      !                        ! = 0 curvilinear coordinate on the sphere
-      !                        !     read in coordinate.nc file
-      !                        ! = 1 geographical mesh on the sphere
-      !                        !     with regular grid-spacing
-      !                        ! = 2 f-plane with regular grid-spacing
-      !                        ! = 3 beta-plane with regular grid-spacing
-      !                        ! = 4 Mercator grid with T/U point at the equator  with
-      !                        !     isotropic resolution (e1_deg)
+
+   !! Coefficients associated with the horizontal coordinate system
+
+   INTEGER, PARAMETER  ::     &
+      jphgr_msh = 3              !: type of horizontal mesh
+      !                          !: = 0 curvilinear coordinate on the sphere
+      !                          !:     read in coordinate.nc file
+      !                          !: = 1 geographical mesh on the sphere
+      !                          !:     with regular grid-spacing
+      !                          !: = 2 f-plane with regular grid-spacing
+      !                          !: = 3 beta-plane with regular grid-spacing
+      !                          !: = 4 Mercator grid with T/U point at the equator  with
+      !                          !:     isotropic resolution (e1_deg)
 
       !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
       !   The mercator grid starts only approximately at gphi0 because
       !   of the constraint that the equator be a T point.
-   REAL(wp) &
+
+   REAL(wp)                   &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::     &  !:
-      ppglam0  =    0.0_wp,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
-      ppgphi0  =   35.0_wp,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
-      !                          !  latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
-      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
-      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+      ::                      &
+      ppglam0  = 0.0_wp     , &  !: longitude of first raw and column T-point   (jphgr_msh = 1)
+      ppgphi0  = 35.0_wp    , &  !: latitude  of first raw and column T-point   (jphgr_msh = 1)
+      !                          !: latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used, &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used, &  !: meridional grid-spacing (degrees)
       !
-      ppe1_m   = 6000.0_wp,   &  !: zonal      grid-spacing (meters )
+      ppe1_m   = 6000.0_wp  , &  !: zonal      grid-spacing (meters )
       ppe2_m   = 6000.0_wp       !: meridional grid-spacing (meters )
+
 
    !!  Coefficients associated with the vertical coordinate system
 
-   REAL(wp), PARAMETER  ::       &  !:
-      &     ppsur = -2033.194295283385_wp   ,  &  !: Computed in domzgr
-      &     ppa0  =  155.8325369664153_wp   ,  &  !:
-      &     ppa1  =  146.3615918601890_wp   ,  &  !:
-      !
-      &     ppkth =  17.28520372419791_wp   ,  &  !: (non dimensional): gives the approximate
+   REAL(wp), PARAMETER  ::                     &
+      &     ppsur =   -2033.194295283385_wp ,  &  !: Computed in domzgr, set ppdzmin, pphmax below
+      &     ppa0  =   155.8325369664153_wp  ,  &  !:
+      &     ppa1  =   146.3615918601890_wp  ,  &  !:
+      &     ppkth =   17.28520372419791_wp  ,  &  !: (non dimensional): gives the approximate
       !                                           !: layer number above which  stretching will
       !                                           !: be maximum. Usually of order jpk/2.
-      &     ppacr =  5.000000000000000_wp         !: (non dimensional): stretching factor
-      !                                           !: for the grid. The highest zacr, the smallest
+      &     ppacr =   5.000000000000000_wp        !: (non dimensional): stretching factor
+      !                                           !: for the grid. The higher zacr, the smaller
       !                                           !: the stretching.
 
+      !  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
+      !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
 
-   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
-   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
-   !!
-   REAL(wp), PARAMETER ::        &  !:
+   REAL(wp), PARAMETER ::                      &
       &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
       &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
-   LOGICAL,  PARAMETER ::        &
+   LOGICAL,  PARAMETER ::                      &
       &     ldbletanh = .FALSE.                   !: Use/do not use double tanf function for vertical coordinates
-   REAL(wp), PARAMETER ::        &
+   REAL(wp), PARAMETER ::                      &
       &     ppa2    = pp_not_used           ,  &  !: Double tanh function parameters
       &     ppkth2  = pp_not_used           ,  &  !:
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_GYRE.h90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_GYRE.h90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_GYRE.h90	(revision 4229)
@@ -8,99 +8,111 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-   CHARACTER (len=16)      &
+   CHARACTER (len=16)         &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::    &  
-      cp_cfg = "gyre"           !: name of the configuration
-   INTEGER     &
+      ::                      &  
+      cp_cfg  =  "gyre"          !: Name of the configuration
+   INTEGER                    &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      :: &
-      jp_cfg =  1   ,        &  !: 
+      ::                      &
+      jp_cfg  =  1     ,      &  !: Resolution of the configuration (degrees)
 
-      ! data size              !!! * size of all the input files *
-      jpidta  = 30*jp_cfg+2, &  !: 1st horizontal dimension ( >= jpi )
-      jpjdta  = 20*jp_cfg+2, &  !: 2nd    "            "    ( >= jpj )
-      jpkdta  = 31,          &  !: number of levels         ( >= jpk )
+      ! Data domain size         !!! *  Size of all input files  *
+      jpidta  =  30*jp_cfg+2, &  !: 1st lateral dimension ( >= jpiglo )
+      jpjdta  =  20*jp_cfg+2, &  !: 2nd lateral dimension ( >= jpjglo )
+      jpkdta  =  31         , &  !: Number of levels      ( >= jpk    )
 
-      ! global domain size     !!! * full domain *
-      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
-      jpjglo  = jpjdta,      &  !: 2nd    "                  "    --> j
-      ! zoom starting position
-      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   1   ,      &  !: in data indices
+#if defined key_c1d
+      ! Zoom domain size         !!! *  C1D zoom  *
+      jpiglo  =  3     ,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  3     ,      &  !: 2nd dimension of global domain --> j
+      ! Domain characteristics
+      jperio  =  0               !: Lateral cond. type (between 0 and 6)
 
+   INTEGER                    &
+      ::                      &
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1               !: in data domain indices
+#else
+      ! Global domain size       !!! *  Global domain  *
+      jpiglo  =  jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  jpjdta,      &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1     ,      &  !: in data domain indices
       ! Domain characteristics
-      jperio  =     0           !: lateral cond. type (between 0 and 6)
+      jperio  =  0               !: Lateral cond. type (between 0 and 6)
+#endif
+
 
    !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
    !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
-   REAL(wp), PARAMETER ::   &  !:
-      pp_not_used       = 999999._wp  , & !: ???
-      pp_to_be_computed =      0._wp      !: ???
-   !!
-   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
-   !!
-   INTEGER,PARAMETER   ::    & !:
-      jphgr_msh = 5            !: type of horizontal mesh
-      !                        ! = 0 curvilinear coordinate on the sphere
-      !                        !     read in coordinate.nc file
-      !                        ! = 1 geographical mesh on the sphere
-      !                        !     with regular grid-spacing
-      !                        ! = 2 f-plane with regular grid-spacing
-      !                        ! = 3 beta-plane with regular grid-spacing
-      !                        ! = 4 Mercator grid with T/U point at the equator  with
-      !                        !     isotropic resolution (e1_deg)
-      !                        ! =5  beta-plane with regular grid-spacing and rotated domain (GYRE configuration)
+
+   REAL(wp), PARAMETER ::              &
+      pp_not_used       = 999999._wp , &  !:
+      pp_to_be_computed = 0._wp           !:
+
+
+   !! Coefficients associated with the horizontal coordinate system
+
+   INTEGER, PARAMETER  ::     &
+      jphgr_msh = 5              !: type of horizontal mesh
+      !                          !: = 0 curvilinear coordinate on the sphere
+      !                          !:     read in coordinate.nc file
+      !                          !: = 1 geographical mesh on the sphere
+      !                          !:     with regular grid-spacing
+      !                          !: = 2 f-plane with regular grid-spacing
+      !                          !: = 3 beta-plane with regular grid-spacing
+      !                          !: = 4 Mercator grid with T/U point at the equator  with
+      !                          !:     isotropic resolution (e1_deg)
+      !                          !: = 5 beta-plane with regular grid-spacing and rotated domain (GYRE configuration)
 
       !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
       !   The mercator grid starts only approximately at gphi0 because
       !   of the constraint that the equator be a T point.
-   REAL(wp) &
+
+   REAL(wp)                   &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::     &  !:
-      ppglam0  =    0.0_wp,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
-      ppgphi0  =   29.0_wp,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
-      !                          ! latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
-      ppe1_deg = pp_not_used ,   &  !: zonal      grid-spacing (degrees)
-      ppe2_deg = pp_not_used ,   &  !: meridional grid-spacing (degrees)
+      ::                      &
+      ppglam0  = 0.0_wp     , &  !: longitude of first raw and column T-point   (jphgr_msh = 1)
+      ppgphi0  = 29.0_wp    , &  !: latitude  of first raw and column T-point   (jphgr_msh = 1)
+      !                          !: latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used, &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used, &  !: meridional grid-spacing (degrees)
       !
-      ppe1_m   = pp_not_used,    &  !: zonal      grid-spacing (meters )
-      ppe2_m   = pp_not_used        !: meridional grid-spacing (meters )
-   !!
+      ppe1_m   = pp_not_used, &  !: zonal      grid-spacing (meters )
+      ppe2_m   = pp_not_used     !: meridional grid-spacing (meters )
+
+
    !!  Coefficients associated with the vertical coordinate system
-   !!
 
-   REAL(wp), PARAMETER  ::       &  !:
-      &     ppsur = -2033.194295283385_wp   ,  &  !: 
-      &     ppa0  =  155.8325369664153_wp   ,  &  !:
-      &     ppa1  =  146.3615918601890_wp   ,  &  !:
-      !
-      &     ppkth =  17.28520372419791_wp   ,  &  !: (non dimensional): gives the approximate
-      !                                           !    layer number above which  stretching will
-      !                                           !    be maximum. Usually of order jpk/2.
-      &     ppacr =  5.000000000000000_wp         !: (non dimensional): stretching factor
-      !                                           !    for the grid. The highest zacr, the smallest
-      !                                           !    the stretching.
+   REAL(wp), PARAMETER  ::                     &
+      &     ppsur =   -2033.194295283385_wp ,  &  !:
+      &     ppa0  =   155.8325369664153_wp  ,  &  !:
+      &     ppa1  =   146.3615918601890_wp  ,  &  !:
+      &     ppkth =   17.28520372419791_wp  ,  &  !: (non dimensional): gives the approximate
+      !                                           !: layer number above which  stretching will
+      !                                           !: be maximum. Usually of order jpk/2.
+      &     ppacr =   5.000000000000000_wp        !: (non dimensional): stretching factor
+      !                                           !: for the grid. The higher zacr, the smaller
+      !                                           !: the stretching.
 
-   !!
-   !!  If all ppa0 ppa1 and ppsur are specified to 0, then
-   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
-   !!
-   REAL(wp), PARAMETER ::        &  !:
-      &     ppdzmin = pp_not_used   ,  &  !: (meters): depth of the top (first) model layer
-      !                             !            depth of second "w" level
-      &     pphmax  = pp_not_used         !: (meters): maximum depth of the ocean
-      !                             !            depth of the last "w" level
-   LOGICAL,  PARAMETER ::        &
+      !  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
+      !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+
+   REAL(wp), PARAMETER ::                      &
+      &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
+      &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
+   LOGICAL,  PARAMETER ::                      &
       &     ldbletanh = .FALSE.                   !: Use/do not use double tanf function for vertical coordinates
-   REAL(wp), PARAMETER ::        &
+   REAL(wp), PARAMETER ::                      &
       &     ppa2    = pp_not_used           ,  &  !: Double tanh function parameters
       &     ppkth2  = pp_not_used           ,  &  !:
       &     ppacr2  = pp_not_used                 !:
-
    !!---------------------------------------------------------------------
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R025.h90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R025.h90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R025.h90	(revision 4229)
@@ -9,69 +9,91 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-   CHARACTER (len=16)      &
+   CHARACTER (len=16)         &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::    &  
-      cp_cfg = "orca"           !: name of the configuration
-   INTEGER     &
+      ::                      &  
+      cp_cfg  =  "orca"          !: Name of the configuration
+   INTEGER                    &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      :: &
-      jp_cfg = 025  ,        &  !: resolution of the configuration (degrees)
-      ! Original data size
-      jpidta  = 1442,        &  !: first horizontal dimension > or = to jpi
-      jpjdta  = 1021,        &  !: second                     > or = to jpj
+      ::                      &
+      jp_cfg  =  025   ,      &  !: Resolution of the configuration (degrees)
+
+      ! Data domain size         !!! *  Size of all input files  *
+      jpidta  =  1442  ,      &  !: 1st lateral dimension ( >= jpiglo )
+      jpjdta  =  1021  ,      &  !: 2nd lateral dimension ( >= jpjglo )
 #if key_orca_r025==75
-      jpkdta  = 75 ,         &  !: number of levels           > or = to jpk
+      jpkdta  =  75    ,      &  !: Number of levels      ( >= jpk    )
 #else
-      jpkdta  = 46 ,         &  !: number of levels           > or = to jpk
+      jpkdta  =  46    ,      &  !: Number of levels      ( >= jpk    )
 #endif
-      ! total domain matrix size
-      jpiglo  = jpidta,      &  !: first  dimension of global domain --> i
-      jpjglo  = jpjdta,      &  !: second dimension of global domain --> j
-      ! starting position of the zoom
-      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   1   ,      &  !: in data indices
+
+#if defined key_c1d
+      ! Zoom domain size         !!! *  C1D zoom  *
+      jpiglo  =  3     ,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  3     ,      &  !: 2nd dimension of global domain --> j
       ! Domain characteristics
-      jperio  =    4            !: lateral cond. type (between 0 and 6)
+      jperio  =  0               !: Lateral cond. type (between 0 and 6)
+
+   INTEGER                    &
+      ::                      &
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1               !: in data domain indices
+#else
+      ! Global domain size       !!! *  Global domain  *
+      jpiglo  =  jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  jpjdta,      &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1     ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =  4               !: Lateral cond. type (between 0 and 6)
+#endif
+
 
    !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
    !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
-   REAL,PARAMETER      ::  pp_not_used = 999999_wp , &
-      &                    pp_to_be_computed = 0._wp
-   !!
-   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
-   !!
-   INTEGER, PARAMETER ::     & !
-      jphgr_msh = 0            !: type of horizontal mesh
-      !                        !  = 0 curvilinear coordinate on the sphere
-      !                        !      read in coordinate.nc file
-      !                        !  = 1 geographical mesh on the sphere
-      !                        !      with regular grid-spacing
-      !                        !  = 2 f-plane with regular grid-spacing
-      !                        !  = 3 beta-plane with regular grid-spacing
-      !                        !  = 4 Mercator grid with T/U point at the equator  with
-      !                        !      isotropic resolution (e1_deg)
+
+   REAL(wp), PARAMETER ::              &
+      pp_not_used       = 999999._wp , &  !:
+      pp_to_be_computed = 0._wp           !:
+
+
+   !! Coefficients associated with the horizontal coordinate system
+
+   INTEGER, PARAMETER  ::     &
+      jphgr_msh = 0              !: type of horizontal mesh
+      !                          !: = 0 curvilinear coordinate on the sphere
+      !                          !:     read in coordinate.nc file
+      !                          !: = 1 geographical mesh on the sphere
+      !                          !:     with regular grid-spacing
+      !                          !: = 2 f-plane with regular grid-spacing
+      !                          !: = 3 beta-plane with regular grid-spacing
+      !                          !: = 4 Mercator grid with T/U point at the equator  with
+      !                          !:     isotropic resolution (e1_deg)
 
       !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
       !   The mercator grid starts only approximately at gphi0 because
       !   of the constraint that the equator be a T point.
-   REAL(wp), PARAMETER ::       &  !
-      ppglam0  = pp_not_used,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
-      ppgphi0  = pp_not_used,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
-      !                            !  latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
-      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
-      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+
+   REAL(wp), PARAMETER ::     &
+      ppglam0  = pp_not_used, &  !: longitude of first raw and column T-point   (jphgr_msh = 1)
+      ppgphi0  = pp_not_used, &  !: latitude  of first raw and column T-point   (jphgr_msh = 1)
+      !                          !: latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used, &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used, &  !: meridional grid-spacing (degrees)
       !
-      ppe1_m   = pp_not_used,   &  !: zonal      grid-spacing (meters )
-      ppe2_m   = pp_not_used       !: meridional grid-spacing (meters )
+      ppe1_m   = pp_not_used, &  !: zonal      grid-spacing (meters )
+      ppe2_m   = pp_not_used     !: meridional grid-spacing (meters )
+
 
    !!  Coefficients associated with the vertical coordinate system
 
 #if key_orca_r025==75
-   REAL(wp), PARAMETER  ::       &
-      &     ppsur =  -3958.951371276829_wp  ,  &  !: ORCA r025 coefficients
+   REAL(wp), PARAMETER  ::                     &
+      &     ppsur =   -3958.951371276829_wp ,  &  !: ORCA r025 coefficients
       &     ppa0  =   103.9530096000000_wp  ,  &  !: (75 levels case)
       &     ppa1  =   2.415951269000000_wp  ,  &  !:
@@ -79,42 +101,38 @@
       !                                           !: layer number above which  stretching will
       !                                           !: be maximum. Usually of order jpk/2.
-      &     ppacr =       7.00000000000_wp        !: (non dimensional): stretching factor
+      &     ppacr =   7.00000000000_wp            !: (non dimensional): stretching factor
       !                                           !: for the grid. The higher zacr, the smaller
       !                                           !: the stretching.
-   !!
-   !!  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
-   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
-   !!
+
+      !  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
+      !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+
    REAL(wp), PARAMETER ::                      &
       &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
       &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
-   !!
    LOGICAL,  PARAMETER ::                      &
       &     ldbletanh = .TRUE.                    !: Use/do not use double tanf function for vertical coordinates
    REAL(wp), PARAMETER ::                      &
-      &     ppa2  =   100.7609285000000_wp  ,  &  !: Double tanh function parameters
-      &     ppkth2=   48.02989372000000_wp  ,  &  !:
-      &     ppacr2=    13.00000000000_wp          !:
-      !
+      &     ppa2    = 100.7609285000000_wp  ,  &  !: Double tanh function parameters
+      &     ppkth2  = 48.02989372000000_wp  ,  &  !:
+      &     ppacr2  = 13.00000000000_wp           !:
 #else
-   REAL(wp), PARAMETER  ::       &
-      &     ppsur = pp_to_be_computed ,        &  !: Computed in domzgr, set ppdzmin and pphmax below
-      &     ppa0  = pp_to_be_computed ,        &  !:    "           "
-      &     ppa1  = pp_to_be_computed ,        &  !:    "           "
-      !
-      &     ppkth =  23.563_wp        ,        &  !: (non dimensional): gives the approximate
+   REAL(wp), PARAMETER  ::                     &
+      &     ppsur =   pp_to_be_computed     ,  &  !: Computed in domzgr, set ppdzmin and pphmax below
+      &     ppa0  =   pp_to_be_computed     ,  &  !:    "           "
+      &     ppa1  =   pp_to_be_computed     ,  &  !:    "           "
+      &     ppkth =   23.563_wp             ,  &  !: (non dimensional): gives the approximate
       !                                           !: layer number above which  stretching will
       !                                           !: be maximum. Usually of order jpk/2.
       &     ppacr =   9.00000000000_wp            !: (non dimensional): stretching factor
-      !                                           !: for the grid. The highest zacr, the smallest
+      !                                           !: for the grid. The higher zacr, the smaller
       !                                           !: the stretching.
-   !!
-   !!  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
-   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
-   !!
+
+      !  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
+      !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+
    REAL(wp), PARAMETER ::                      &
-      &     ppdzmin = 6._wp           ,        &  !: (meters) vertical thickness of the top layer
+      &     ppdzmin = 6._wp                 ,  &  !: (meters) vertical thickness of the top layer
       &     pphmax  = 5750._wp                    !: (meters) Maximum depth of the ocean gdepw(jpk)
-   !!
    LOGICAL,  PARAMETER ::                      &
       &     ldbletanh = .FALSE.                   !: Use/do not use double tanf function for vertical coordinates
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R05.h90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R05.h90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R05.h90	(revision 4229)
@@ -9,126 +9,122 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-   CHARACTER (len=16)      &
+   CHARACTER (len=16)         &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::    &  
-      cp_cfg = "orca"           !: name of the configuration
-   INTEGER     &
+      ::                      &  
+      cp_cfg  =  "orca"          !: Name of the configuration
+   INTEGER                    &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      :: &
-      jp_cfg = 05  ,         &  !: resolution of the configuration (degrees)
+      ::                      &
+      jp_cfg  =  05    ,      &  !: Resolution of the configuration (degrees)
 
-      ! data size              !!! * size of all the input files *
-      jpidta  = 722,         &  !: 1st lateral dimension > or = to jpiglo
-      jpjdta  = 511,         &  !: 2nd   "         "     > or = to jpjglo
-      jpkdta  =  31             !: number of levels      > or = to jpkglo
+      ! Data domain size         !!! *  Size of all input files  *
+      jpidta  =  722   ,      &  !: 1st lateral dimension ( >= jpiglo )
+      jpjdta  =  511   ,      &  !: 2nd lateral dimension ( >= jpjglo )
+      jpkdta  =  31    ,      &  !: Number of levels      ( >= jpk    )
 
-#if defined key_antarctic
-      ! zoom domain size       !!! *  antarctic zoom  * 
-   INTEGER     &
-#if !defined key_agrif
-      , PARAMETER  &
+#if defined key_c1d
+      ! Zoom domain size         !!! *  C1D zoom  *
+      jpiglo  =  3     ,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  3     ,      &  !: 2nd dimension of global domain --> j
+      ! Domain characteristics
+      jperio  =  0               !: Lateral cond. type (between 0 and 6)
+
+   INTEGER                    &
+      ::                      &
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1               !: in data domain indices
+#elif defined key_antarctic
+      ! Zoom domain size         !!! *  Antarctic zoom  * 
+      jpiglo  =  jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  187   ,      &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1     ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =  1               !: Lateral cond. type (between 0 and 6)
+#elif defined key_arctic
+      ! Zoom domain size         !!! *  Arctic zoom  *
+      jpiglo  =  562   ,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  jpjdta-301+1,&  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  81    ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  301   ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =  5               !: Lateral cond. type (between 0 and 6)
+#else
+      ! Global domain size       !!! *  Global domain  *
+      jpiglo  =  jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  jpjdta,      &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1     ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =  6               !: Lateral cond. type (between 0 and 6)
 #endif
-      :: &
-      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
-      jpjglo  = 187   ,      &  !: 2nd     "                 "    --> j 
-      ! starting position of the zoom
-      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   1   ,      &  !: in data domain indices
-      ! Domain characteristics
-      jperio  =   1             !: lateral cond. type (between 0 and 6)
 
-#elif defined key_arctic
-      ! zoom domain size       !!! *  arctic zoom  *
-   INTEGER    &
-#if !defined key_agrif
-      , PARAMETER  &
-#endif
-      :: &
-      ! zoom domain size       !!! *  arctic zoom  *
-      jpiglo  = 562,         &  !: 1st dimension of global domain --> i
-      jpjglo  = jpjdta-301+1,&  !: 2nd     "                 "    --> j
-      ! zoom starting position
-      jpizoom =  81   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom = 301   ,      &  !: in data domain indices
-      ! Domain characteristics
-      jperio  =   5             !: lateral cond. type (between 0 and 6)
-
-#else
-      ! global domain size     !!! *  global domain  *
-   INTEGER    &
-#if !defined key_agrif
-      , PARAMETER  &
-#endif
-      :: &
-      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
-      jpjglo  = jpjdta,      &  !: 2nd     "                 "    --> j
-      ! zoom starting position    
-      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   1   ,      &  !: in data domain indices
-      ! Domain characteristics
-      jperio  =    6            !: lateral cond. type (between 0 and 6)
-#endif
 
    !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
    !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
-   REAL(wp), PARAMETER ::   &
+
+   REAL(wp), PARAMETER ::              &
       pp_not_used       = 999999._wp , &  !:
-      pp_to_be_computed = 0._wp          !:
+      pp_to_be_computed = 0._wp           !:
 
-   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
 
-   INTEGER, PARAMETER   ::   & !
-      jphgr_msh = 0            !: type of horizontal mesh
-      !                        !  = 0 curvilinear coordinate on the sphere
-      !                        !      read in coordinate.nc file
-      !                        !  = 1 geographical mesh on the sphere
-      !                        !      with regular grid-spacing
-      !                        !  = 2 f-plane with regular grid-spacing
-      !                        !  = 3 beta-plane with regular grid-spacing
-      !                        !  = 4 Mercator grid with T/U point at the equator  with
-      !                        !      isotropic resolution (e1_deg)
+   !! Coefficients associated with the horizontal coordinate system
+
+   INTEGER, PARAMETER  ::     &
+      jphgr_msh = 0              !: type of horizontal mesh
+      !                          !: = 0 curvilinear coordinate on the sphere
+      !                          !:     read in coordinate.nc file
+      !                          !: = 1 geographical mesh on the sphere
+      !                          !:     with regular grid-spacing
+      !                          !: = 2 f-plane with regular grid-spacing
+      !                          !: = 3 beta-plane with regular grid-spacing
+      !                          !: = 4 Mercator grid with T/U point at the equator  with
+      !                          !:     isotropic resolution (e1_deg)
 
       !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
       !   The mercator grid starts only approximately at gphi0 because
       !   of the constraint that the equator be a T point.
-   REAL(wp) , PARAMETER ::      &  !
-      ppglam0  = pp_not_used,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
-      ppgphi0  = pp_not_used,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
-      !                            ! latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
-      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
-      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+
+   REAL(wp), PARAMETER ::     &
+      ppglam0  = pp_not_used, &  !: longitude of first raw and column T-point   (jphgr_msh = 1)
+      ppgphi0  = pp_not_used, &  !: latitude  of first raw and column T-point   (jphgr_msh = 1)
+      !                          !: latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used, &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used, &  !: meridional grid-spacing (degrees)
       !
-      ppe1_m   = pp_not_used,   &  !: zonal      grid-spacing (meters )
-      ppe2_m   = pp_not_used       !: meridional grid-spacing (meters )
+      ppe1_m   = pp_not_used, &  !: zonal      grid-spacing (meters )
+      ppe2_m   = pp_not_used     !: meridional grid-spacing (meters )
 
-   !!
-   !! Vertical grid parameter for domzgr
-   !! =====================================
-   !!
-   REAL(wp), PARAMETER  ::       &
-      &     ppsur = -4762.96143546300_wp    ,  &  !: ORCA r4, r2 and r05 coefficients
+
+   !!  Coefficients associated with the vertical coordinate system
+
+   REAL(wp), PARAMETER  ::                     &
+      &     ppsur =   -4762.96143546300_wp  ,  &  !: ORCA r4, r2 and r05 coefficients
       &     ppa0  =   255.58049070440_wp    ,  &  !: (default coefficients)
       &     ppa1  =   245.58132232490_wp    ,  &  !:
-      &     ppkth =    21.43336197938_wp    ,  &  !: (non dimensional): gives the approximate
+      &     ppkth =   21.43336197938_wp     ,  &  !: (non dimensional): gives the approximate
       !                                           !: layer number above which  stretching will
       !                                           !: be maximum. Usually of order jpk/2.
-      &     ppacr =     3.00000000000_wp          !: (non dimensional): stretching factor
-      !                                           !: for the grid. The highest zacr, the smallest
+      &     ppacr =   3.00000000000_wp            !: (non dimensional): stretching factor
+      !                                           !: for the grid. The higher zacr, the smaller
       !                                           !: the stretching.
 
-   !!
-   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
-   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
-   !!
-   REAL(wp), PARAMETER ::        &
+      !  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
+      !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+
+   REAL(wp), PARAMETER ::                      &
       &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
       &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
-   LOGICAL,  PARAMETER ::        &
+   LOGICAL,  PARAMETER ::                      &
       &     ldbletanh = .FALSE.                   !: Use/do not use double tanf function for vertical coordinates
-   REAL(wp), PARAMETER ::        &
+   REAL(wp), PARAMETER ::                      &
       &     ppa2    = pp_not_used           ,  &  !: Double tanh function parameters
       &     ppkth2  = pp_not_used           ,  &  !:
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R1.h90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R1.h90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R1.h90	(revision 4229)
@@ -12,69 +12,91 @@
    !! Use: key_orca_r1=75 to set 75 levels
    !!----------------------------------------------------------------------
-   CHARACTER (len=16)      &
+   CHARACTER (len=16)         &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::    &  
-      cp_cfg = "orca"           !: name of the configuration
-   INTEGER     &
+      ::                      &  
+      cp_cfg  =  "orca"          !: Name of the configuration
+   INTEGER                    &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      :: &
-      jp_cfg = 1    ,        &  !: resolution of the configuration (degrees)
-      ! Original data size
-      jpidta  =  362,        &  !: first horizontal dimension > or = to jpi
-      jpjdta  =  292,        &  !: second                     > or = to jpj
+      ::                      &
+      jp_cfg  =  1     ,      &  !: Resolution of the configuration (degrees)
+
+      ! Data domain size         !!! *  Size of all input files  *
+      jpidta  =  362   ,      &  !: 1st lateral dimension ( >= jpiglo )
+      jpjdta  =  292   ,      &  !: 2nd lateral dimension ( >= jpjglo )
 #if key_orca_r1==75
-      jpkdta  = 75 ,         &  !: number of levels           > or = to jpk
+      jpkdta  =  75    ,      &  !: Number of levels      ( >= jpk    )
 #else
-      jpkdta  = 46 ,         &  !: number of levels           > or = to jpk
+      jpkdta  =  46    ,      &  !: Number of levels      ( >= jpk    )
 #endif
-      ! total domain matrix size
-      jpiglo  = jpidta,      &  !: first  dimension of global domain --> i
-      jpjglo  = jpjdta,      &  !: second dimension of global domain --> j
-      ! starting position of the zoom
-      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   1   ,      &  !: in data indices
+
+#if defined key_c1d
+      ! Zoom domain size         !!! *  C1D zoom  *
+      jpiglo  =  3     ,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  3     ,      &  !: 2nd dimension of global domain --> j
       ! Domain characteristics
-      jperio  =   6             !: lateral cond. type (between 0 and 6)
+      jperio  =  0               !: Lateral cond. type (between 0 and 6)
+
+   INTEGER                    &
+      ::                      &
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1               !: in data domain indices
+#else
+      ! Global domain size       !!! *  Global domain  *
+      jpiglo  =  jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  jpjdta,      &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1     ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =  6               !: Lateral cond. type (between 0 and 6)
+#endif
+
 
    !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
    !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
-   REAL,PARAMETER      ::  pp_not_used = 999999_wp , &
-      &                    pp_to_be_computed = 0._wp
-   !!
-   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
-   !!
-   INTEGER, PARAMETER ::     & !
-      jphgr_msh = 0            !: type of horizontal mesh
-      !                        !  = 0 curvilinear coordinate on the sphere
-      !                        !      read in coordinate.nc file
-      !                        !  = 1 geographical mesh on the sphere
-      !                        !      with regular grid-spacing
-      !                        !  = 2 f-plane with regular grid-spacing
-      !                        !  = 3 beta-plane with regular grid-spacing
-      !                        !  = 4 Mercator grid with T/U point at the equator  with
-      !                        !      isotropic resolution (e1_deg)
+
+   REAL(wp), PARAMETER ::              &
+      pp_not_used       = 999999._wp , &  !:
+      pp_to_be_computed = 0._wp           !:
+
+
+   !! Coefficients associated with the horizontal coordinate system
+
+   INTEGER, PARAMETER  ::     &
+      jphgr_msh = 0              !: type of horizontal mesh
+      !                          !: = 0 curvilinear coordinate on the sphere
+      !                          !:     read in coordinate.nc file
+      !                          !: = 1 geographical mesh on the sphere
+      !                          !:     with regular grid-spacing
+      !                          !: = 2 f-plane with regular grid-spacing
+      !                          !: = 3 beta-plane with regular grid-spacing
+      !                          !: = 4 Mercator grid with T/U point at the equator  with
+      !                          !:     isotropic resolution (e1_deg)
 
       !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
       !   The mercator grid starts only approximately at gphi0 because
       !   of the constraint that the equator be a T point.
-   REAL(wp), PARAMETER ::       &  !
-      ppglam0  = pp_not_used,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
-      ppgphi0  = pp_not_used,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
-      !                            !  latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
-      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
-      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+
+   REAL(wp), PARAMETER ::     &
+      ppglam0  = pp_not_used, &  !: longitude of first raw and column T-point   (jphgr_msh = 1)
+      ppgphi0  = pp_not_used, &  !: latitude  of first raw and column T-point   (jphgr_msh = 1)
+      !                          !: latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used, &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used, &  !: meridional grid-spacing (degrees)
       !
-      ppe1_m   = pp_not_used,   &  !: zonal      grid-spacing (meters )
-      ppe2_m   = pp_not_used       !: meridional grid-spacing (meters )
+      ppe1_m   = pp_not_used, &  !: zonal      grid-spacing (meters )
+      ppe2_m   = pp_not_used     !: meridional grid-spacing (meters )
+
 
    !!  Coefficients associated with the vertical coordinate system
 
 #if key_orca_r1==75
-   REAL(wp), PARAMETER  ::       &
-      &     ppsur =  -3958.951371276829_wp  ,  &  !: ORCA r1 coefficients
+   REAL(wp), PARAMETER  ::                     &
+      &     ppsur =   -3958.951371276829_wp ,  &  !: ORCA r1 coefficients
       &     ppa0  =   103.9530096000000_wp  ,  &  !: (75 levels case)
       &     ppa1  =   2.415951269000000_wp  ,  &  !:
@@ -82,42 +104,38 @@
       !                                           !: layer number above which  stretching will
       !                                           !: be maximum. Usually of order jpk/2.
-      &     ppacr =       7.00000000000_wp        !: (non dimensional): stretching factor
+      &     ppacr =   7.00000000000_wp            !: (non dimensional): stretching factor
       !                                           !: for the grid. The higher zacr, the smaller
       !                                           !: the stretching.
-   !!
-   !!  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
-   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
-   !!
+
+      !  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
+      !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+
    REAL(wp), PARAMETER ::                      &
       &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
       &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
-   !!
    LOGICAL,  PARAMETER ::                      &
       &     ldbletanh = .TRUE.                    !: Use/do not use double tanf function for vertical coordinates
    REAL(wp), PARAMETER ::                      &
-      &     ppa2  =   100.7609285000000_wp  ,  &  !: Double tanh function parameters
-      &     ppkth2=   48.02989372000000_wp  ,  &  !:
-      &     ppacr2=    13.00000000000_wp          !:
-      !
+      &     ppa2    = 100.7609285000000_wp  ,  &  !: Double tanh function parameters
+      &     ppkth2  = 48.02989372000000_wp  ,  &  !:
+      &     ppacr2  = 13.00000000000_wp           !:
 #else
-   REAL(wp), PARAMETER  ::       &
-      &     ppsur = pp_to_be_computed ,        &  !: Computed in domzgr, set ppdzmin and pphmax below
-      &     ppa0  = pp_to_be_computed ,        &  !:    "           "
-      &     ppa1  = pp_to_be_computed ,        &  !:    "           "
-      !
-      &     ppkth =  23.563_wp        ,        &  !: (non dimensional): gives the approximate
+   REAL(wp), PARAMETER  ::                     &
+      &     ppsur =   pp_to_be_computed     ,  &  !: Computed in domzgr, set ppdzmin and pphmax below
+      &     ppa0  =   pp_to_be_computed     ,  &  !:    "           "
+      &     ppa1  =   pp_to_be_computed     ,  &  !:    "           "
+      &     ppkth =   23.563_wp             ,  &  !: (non dimensional): gives the approximate
       !                                           !: layer number above which  stretching will
       !                                           !: be maximum. Usually of order jpk/2.
       &     ppacr =   9.00000000000_wp            !: (non dimensional): stretching factor
-      !                                           !: for the grid. The highest zacr, the smallest
+      !                                           !: for the grid. The higher zacr, the smaller
       !                                           !: the stretching.
-   !!
-   !!  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
-   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
-   !!
+
+      !  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
+      !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+
    REAL(wp), PARAMETER ::                      &
-      &     ppdzmin = 6._wp           ,        &  !: (meters) vertical thickness of the top layer
+      &     ppdzmin = 6._wp                 ,  &  !: (meters) vertical thickness of the top layer
       &     pphmax  = 5750._wp                    !: (meters) Maximum depth of the ocean gdepw(jpk)
-   !!
    LOGICAL,  PARAMETER ::                      &
       &     ldbletanh = .FALSE.                   !: Use/do not use double tanf function for vertical coordinates
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R2.h90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R2.h90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R2.h90	(revision 4229)
@@ -9,154 +9,122 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-   CHARACTER (len=16)      &
+   CHARACTER (len=16)         &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::    &  
-      cp_cfg = "orca"           !: name of the configuration 
-   INTEGER     &
+      ::                      &  
+      cp_cfg  =  "orca"          !: Name of the configuration
+   INTEGER                    &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      :: &
-      jp_cfg = 2,            &  !: resolution of the configuration (degrees)
+      ::                      &
+      jp_cfg  =  2     ,      &  !: Resolution of the configuration (degrees)
 
-      ! data size              !!! * size of all input files *
-      jpidta  = 182,         &  !: 1st lateral dimension ( >= jpiglo )
-      jpjdta  = 149,         &  !: 2nd    "       "      ( >= jpjglo )
-      jpkdta  = 31              !: number of levels      ( >= jpk    ) 
+      ! Data domain size         !!! *  Size of all input files  *
+      jpidta  =  182   ,      &  !: 1st lateral dimension ( >= jpiglo )
+      jpjdta  =  149   ,      &  !: 2nd lateral dimension ( >= jpjglo )
+      jpkdta  =  31    ,      &  !: Number of levels      ( >= jpk    )
 
-#if defined key_antarctic
-      ! zoom domain size       !!! *  antarctic zoom  * 
-   INTEGER     &
-#if !defined key_agrif
-      , PARAMETER  &
+#if defined key_c1d
+      ! Zoom domain size         !!! *  C1D zoom  *
+      jpiglo  =  3     ,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  3     ,      &  !: 2nd dimension of global domain --> j
+      ! Domain characteristics
+      jperio  =  0               !: Lateral cond. type (between 0 and 6)
+
+   INTEGER                    &
+      ::                      &
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1               !: in data domain indices
+#elif defined key_antarctic
+      ! Zoom domain size         !!! *  Antarctic zoom  * 
+      jpiglo  =  jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  50    ,      &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1     ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =  1               !: Lateral cond. type (between 0 and 6)
+#elif defined key_arctic
+      ! Zoom domain size         !!! *  Arctic zoom  *
+      jpiglo  =  142   ,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  jpjdta-97+1, &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  21    ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  97    ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =  3               !: Lateral cond. type (between 0 and 6)
+#else
+      ! Global domain size       !!! *  Global domain  *
+      jpiglo  =  jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  jpjdta,      &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1     ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =  4               !: Lateral cond. type (between 0 and 6)
 #endif
-      :: &
-      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
-      jpjglo  = 50,          &  !: 2nd    "                  "    --> j
-      ! zoom starting position
-      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   1   ,      &  !: in data domain indices
-      ! Domain characteristics
-      jperio  =   1             !: lateral cond. type (between 0 and 6)
 
-#elif defined key_arctic
-      ! zoom domain size       !!! *  arctic zoom  *
-   INTEGER    &
-#if !defined key_agrif
-      , PARAMETER  &
-#endif
-      :: &
-      jpiglo  = 142   ,      &  !: 1st dimension of global domain --> i
-      jpjglo  = jpjdta-97+1, &  !: 2nd    "                  "    --> j
-      ! zoom starting position 
-      jpizoom =  21   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =  97   ,      &  !: in data domain indices
-      ! Domain characteristics
-      jperio  =   3             !: lateral cond. type (between 0 and 6)
-
-#elif defined key_c1d
-      ! global domain size     !!! *  global domain  *
-   INTEGER    &
-#if !defined key_agrif
-      , PARAMETER  &
-#endif
-      :: &
-      jpiglo  = 3     ,      &  !: 1st dimension of global domain --> i
-      jpjglo  = 3     ,      &  !: 2nd    "                  "    --> j
-      ! starting position of the zoom 
-      ! jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
-      ! jpjzoom =   133  ,    &  !: in data domain indices (160W,75N)
-      ! jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
-      ! jpjzoom =   110  ,    &  !: in data domain indices (160W,50N)
-      ! jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
-      ! jpjzoom =   97   ,    &  !: in data domain indices (160W,30N)
-      ! jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
-      ! jpjzoom =   86   ,    &  !: in data domain indices (160W,10N)
-      ! jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
-      ! jpjzoom =   49   ,    &  !: in data domain indices (160W,30S)
-      ! jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
-      ! jpjzoom =   27   ,    &  !: in data domain indices (160W,60S)
-      ! jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
-      ! jpjzoom =    7   ,    &  !: in data domain indices (160W,75S)
-      jpizoom =   110   ,    &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   97   ,    &  !: in data domain indices (64W,31.5N) BATS site
-      ! Domain characteristics
-      jperio  =   0            !: lateral cond. type (between 0 and 6)
-#else
-      ! global domain size     !!! *  global domain  *
-   INTEGER    &
-#if !defined key_agrif
-      , PARAMETER  &
-#endif
-      :: &
-      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
-      jpjglo  = jpjdta,      &  !: 2nd    "                  "    --> j
-      ! starting position of the zoom 
-      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   1   ,      &  !: in data domain indices
-      ! Domain characteristics
-      jperio  =   4             !: lateral cond. type (between 0 and 6)
-
-#endif
 
    !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
    !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
-   REAL(wp), PARAMETER ::   &
-      pp_not_used       = 999999_wp , &  !:
-      pp_to_be_computed = 0._wp          !:
 
-   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   REAL(wp), PARAMETER ::              &
+      pp_not_used       = 999999._wp , &  !:
+      pp_to_be_computed = 0._wp           !:
 
-   INTEGER,PARAMETER   ::    & !
-      jphgr_msh = 0            !: type of horizontal mesh
-      !                        !  = 0 curvilinear coordinate on the sphere
-      !                        !      read in coordinate.nc file
-      !                        !  = 1 geographical mesh on the sphere
-      !                        !      with regular grid-spacing
-      !                        !  = 2 f-plane with regular grid-spacing
-      !                        !  = 3 beta-plane with regular grid-spacing
-      !                        !  = 4 Mercator grid with T/U point at the equator  with
-      !                        !      isotropic resolution (e1_deg)
+
+   !! Coefficients associated with the horizontal coordinate system
+
+   INTEGER, PARAMETER  ::     &
+      jphgr_msh = 0              !: type of horizontal mesh
+      !                          !: = 0 curvilinear coordinate on the sphere
+      !                          !:     read in coordinate.nc file
+      !                          !: = 1 geographical mesh on the sphere
+      !                          !:     with regular grid-spacing
+      !                          !: = 2 f-plane with regular grid-spacing
+      !                          !: = 3 beta-plane with regular grid-spacing
+      !                          !: = 4 Mercator grid with T/U point at the equator  with
+      !                          !:     isotropic resolution (e1_deg)
 
       !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
       !   The mercator grid starts only approximately at gphi0 because
       !   of the constraint that the equator be a T point.
-   REAL(wp) ,PARAMETER ::       &  !
-      ppglam0  = pp_not_used,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
-      ppgphi0  = pp_not_used,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
-      !                            !  latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
-      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
-      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+
+   REAL(wp), PARAMETER ::     &
+      ppglam0  = pp_not_used, &  !: longitude of first raw and column T-point   (jphgr_msh = 1)
+      ppgphi0  = pp_not_used, &  !: latitude  of first raw and column T-point   (jphgr_msh = 1)
+      !                          !: latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used, &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used, &  !: meridional grid-spacing (degrees)
       !
-      ppe1_m   = pp_not_used,   &  !: zonal      grid-spacing (meters )
-      ppe2_m   = pp_not_used       !: meridional grid-spacing (meters )
+      ppe1_m   = pp_not_used, &  !: zonal      grid-spacing (meters )
+      ppe2_m   = pp_not_used     !: meridional grid-spacing (meters )
 
-   !!
-   !! Vertical grid parameter for domzgr
-   !! ==================================
-   !!
-   REAL(wp), PARAMETER  ::       &
-      &     ppsur = -4762.96143546300_wp    ,  &  !: ORCA r4, r2 and r05 coefficients
+
+   !!  Coefficients associated with the vertical coordinate system
+
+   REAL(wp), PARAMETER  ::                     &
+      &     ppsur =   -4762.96143546300_wp  ,  &  !: ORCA r4, r2 and r05 coefficients
       &     ppa0  =   255.58049070440_wp    ,  &  !: (default coefficients)
       &     ppa1  =   245.58132232490_wp    ,  &  !:
-      &     ppkth =    21.43336197938_wp    ,  &  !: (non dimensional): gives the approximate
+      &     ppkth =   21.43336197938_wp     ,  &  !: (non dimensional): gives the approximate
       !                                           !: layer number above which  stretching will
       !                                           !: be maximum. Usually of order jpk/2.
-      &     ppacr =     3.00000000000_wp          !: (non dimensional): stretching factor
-      !                                           !: for the grid. The highest zacr, the smallest
+      &     ppacr =   3.00000000000_wp            !: (non dimensional): stretching factor
+      !                                           !: for the grid. The higher zacr, the smaller
       !                                           !: the stretching.
 
-   !!
-   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
-   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
-   !!
-   REAL(wp), PARAMETER ::        &
+      !  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
+      !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+
+   REAL(wp), PARAMETER ::                      &
       &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
       &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
-   LOGICAL,  PARAMETER ::        &
+   LOGICAL,  PARAMETER ::                      &
       &     ldbletanh = .FALSE.                   !: Use/do not use double tanf function for vertical coordinates
-   REAL(wp), PARAMETER ::        &
+   REAL(wp), PARAMETER ::                      &
       &     ppa2    = pp_not_used           ,  &  !: Double tanh function parameters
       &     ppkth2  = pp_not_used           ,  &  !:
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R4.h90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R4.h90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_ORCA_R4.h90	(revision 4229)
@@ -1,4 +1,4 @@
    !!---------------------------------------------------------------------
-   !!                     ***  par_ORCA_R4.h90  ***   
+   !!                     ***  par_ORCA_R4.h90  ***  
    !!   Ocean Domain : 4 degrees resolution global ocean
    !!                  (0RCA_R4 configuration)
@@ -9,84 +9,104 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-   CHARACTER (len=16)      &
+   CHARACTER (len=16)         &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-       ::    &  
-     cp_cfg = "orca"           !: name of the configuration
-   INTEGER     &
+      ::                      &  
+      cp_cfg  =  "orca"          !: Name of the configuration
+   INTEGER                    &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      :: &
-      jp_cfg = 4      ,      &  !: resolution of the configuration (degrees)
-      ! Original data size
-      jpidta  =  92   ,      &  !: first horizontal dimension > or = to jpi
-      jpjdta  =  76   ,      &  !: second                     > or = to jpj
-      jpkdta  =  31   ,      &  !: number of levels           > or = to jpk
-      ! global domain matrix size
-      jpiglo  = jpidta,      &  !: first  dimension of global domain --> i
-      jpjglo  = jpjdta,      &  !: second dimension of global domain --> j
-      ! starting position of the zoom
-      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   1   ,      &  !: in data indices
+      ::                      &
+      jp_cfg  =  4     ,      &  !: Resolution of the configuration (degrees)
+
+      ! Data domain size         !!! *  Size of all input files  *
+      jpidta  =  92    ,      &  !: 1st lateral dimension ( >= jpiglo )
+      jpjdta  =  76    ,      &  !: 2nd lateral dimension ( >= jpjglo )
+      jpkdta  =  31    ,      &  !: Number of levels      ( >= jpk    )
+
+#if defined key_c1d
+      ! Zoom domain size         !!! *  C1D zoom  *
+      jpiglo  =  3     ,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  3     ,      &  !: 2nd dimension of global domain --> j
       ! Domain characteristics
-      jperio  =   4             !: lateral cond. type (between 0 and 6)
+      jperio  =  0               !: Lateral cond. type (between 0 and 6)
+
+   INTEGER                    &
+      ::                      &
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1               !: in data domain indices
+#else
+      ! Global domain size       !!! *  Global domain  *
+      jpiglo  =  jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  jpjdta,      &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1     ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =  4               !: Lateral cond. type (between 0 and 6)
+#endif
+
 
    !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
    !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
-   REAL(wp), PARAMETER ::   &
-      pp_not_used       = 999999_wp , &  !:
-      pp_to_be_computed = 0._wp          !:
 
-   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
-   INTEGER, PARAMETER ::     & !
-      jphgr_msh = 0            !: type of horizontal mesh
-      !                        ! = 0 curvilinear coordinate on the sphere
-      !                        !     read in coordinate.nc file
-      !                        ! = 1 geographical mesh on the sphere
-      !                        !     with regular grid-spacing
-      !                        ! = 2 f-plane with regular grid-spacing
-      !                        ! = 3 beta-plane with regular grid-spacing
-      !                        ! = 4 Mercator grid with T/U point at the equator  with
-      !                        !     isotropic resolution (e1_deg)
+   REAL(wp), PARAMETER ::              &
+      pp_not_used       = 999999._wp , &  !:
+      pp_to_be_computed = 0._wp           !:
+
+
+   !! Coefficients associated with the horizontal coordinate system
+
+   INTEGER, PARAMETER  ::     &
+      jphgr_msh = 0              !: type of horizontal mesh
+      !                          !: = 0 curvilinear coordinate on the sphere
+      !                          !:     read in coordinate.nc file
+      !                          !: = 1 geographical mesh on the sphere
+      !                          !:     with regular grid-spacing
+      !                          !: = 2 f-plane with regular grid-spacing
+      !                          !: = 3 beta-plane with regular grid-spacing
+      !                          !: = 4 Mercator grid with T/U point at the equator  with
+      !                          !:     isotropic resolution (e1_deg)
 
       !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
       !   The mercator grid starts only approximately at gphi0 because
       !   of the constraint that the equator be a T point.
-   REAL(wp) , PARAMETER ::      &  !
-      ppglam0  = pp_not_used,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
-      ppgphi0  = pp_not_used,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
-      !                            ! latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
-      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
-      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+
+   REAL(wp), PARAMETER ::     &
+      ppglam0  = pp_not_used, &  !: longitude of first raw and column T-point   (jphgr_msh = 1)
+      ppgphi0  = pp_not_used, &  !: latitude  of first raw and column T-point   (jphgr_msh = 1)
+      !                          !: latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used, &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used, &  !: meridional grid-spacing (degrees)
       !
-      ppe1_m   = pp_not_used,   &  !: zonal      grid-spacing (meters )
-      ppe2_m   = pp_not_used       !: meridional grid-spacing (meters )
+      ppe1_m   = pp_not_used, &  !: zonal      grid-spacing (meters )
+      ppe2_m   = pp_not_used     !: meridional grid-spacing (meters )
 
 
-   !! Vertical grid parameter for domzgr
-   !! ==================================
+   !!  Coefficients associated with the vertical coordinate system
 
-   REAL(wp), PARAMETER  ::       &
-      &     ppsur = -4762.96143546300_wp    ,  &  !: ORCA r4, r2 and r05 coefficients
+   REAL(wp), PARAMETER  ::                     &
+      &     ppsur =   -4762.96143546300_wp  ,  &  !: ORCA r4, r2 and r05 coefficients
       &     ppa0  =   255.58049070440_wp    ,  &  !: (default coefficients)
       &     ppa1  =   245.58132232490_wp    ,  &  !:
-      &     ppkth =    21.43336197938_wp    ,  &  !: (non dimensional): gives the approximate
+      &     ppkth =   21.43336197938_wp     ,  &  !: (non dimensional): gives the approximate
       !                                           !: layer number above which  stretching will
       !                                           !: be maximum. Usually of order jpk/2.
-      &     ppacr =     3.00000000000_wp          !: (non dimensional): stretching factor
-      !                                           !: for the grid. The highest zacr, the smallest
+      &     ppacr =   3.00000000000_wp            !: (non dimensional): stretching factor
+      !                                           !: for the grid. The higher zacr, the smaller
       !                                           !: the stretching.
 
-   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
-   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+      !  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
+      !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
 
-   REAL(wp), PARAMETER ::        &
+   REAL(wp), PARAMETER ::                      &
       &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
       &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
-   LOGICAL,  PARAMETER ::        &
+   LOGICAL,  PARAMETER ::                      &
       &     ldbletanh = .FALSE.                   !: Use/do not use double tanf function for vertical coordinates
-   REAL(wp), PARAMETER ::        &
+   REAL(wp), PARAMETER ::                      &
       &     ppa2    = pp_not_used           ,  &  !: Double tanh function parameters
       &     ppkth2  = pp_not_used           ,  &  !:
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_POMME_R025.h90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_POMME_R025.h90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_POMME_R025.h90	(revision 4229)
@@ -9,94 +9,101 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-   CHARACTER (len=16)      &
+   CHARACTER (len=16)         &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      ::    &  
-      cp_cfg = "pomme"          !: POMME025 name of the configuration
-   INTEGER     &
+      ::                      &  
+      cp_cfg  =  "pomme"         !: Name of the configuration
+   INTEGER                    &
 #if !defined key_agrif
-      , PARAMETER  &
+      , PARAMETER             &
 #endif
-      :: &
-      jp_cfg = 025  ,        &  !: resolution of the configuration (degrees)
-      ! Original data size
+      ::                      &
+      jp_cfg  =  025   ,      &  !: Resolution of the configuration (degrees)
+
       ! ORCA025 global grid size
-      jpiglo_ORCA025 = 1442, &
-      jpjglo_ORCA025 = 1021, &  ! not used currently
+      jpiglo_ORCA025 = 1442,  &
+      jpjglo_ORCA025 = 1021,  &  ! not used currently
       ! POMME "global" domain localisation in the ORCA025 global grid
-      jpi_iw    = 1059,      & 
-      jpi_ie    = 1088,      &  
-      jpj_js    = 661,       &
-      jpj_jn    = 700,       &
-      jpidta  = ( jpi_ie - jpi_iw + 1 ), &   !: =30 first horizontal dimension > or = to jpi
-      jpjdta  = ( jpj_jn - jpj_js + 1 ), &   !: =40 second                     > or = to jpj
-      jpkdta  = 46 ,         &  !: number of levels           > or = to jpk
-      ! total domain matrix size
-      jpiglo  = jpidta,      &  !: first  dimension of global domain --> i
-      jpjglo  = jpjdta,      &  !: second dimension of global domain --> j
-      ! starting position of the zoom
-      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
-      jpjzoom =   1   ,      &  !: in data indices
+      jpi_iw  =  1059  ,      & 
+      jpi_ie  =  1088  ,      &  
+      jpj_js  =  661   ,      &
+      jpj_jn  =  700   ,      &
+
+      ! Data domain size                      !!! *  Size of all input files  *
+      jpidta  =  ( jpi_ie - jpi_iw + 1 ), &   !: =30 1st lateral dimension ( >= jpiglo )
+      jpjdta  =  ( jpj_jn - jpj_js + 1 ), &   !: =40 2nd lateral dimension ( >= jpjglo )
+      jpkdta  =  46    ,      &               !: Number of levels          ( >= jpk    )
+
+      ! Global domain size       !!! *  Global domain  *
+      jpiglo  =  jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  =  jpjdta,      &  !: 2nd dimension of global domain --> j
+      ! Starting position of the zoom
+      jpizoom =  1     ,      &  !: Left bottom (i,j) indices of the zoom
+      jpjzoom =  1     ,      &  !: in data domain indices
       ! Domain characteristics
-      jperio  =    0            !: lateral cond. type (between 0 and 6)
+      jperio  =  0               !: Lateral cond. type (between 0 and 6)
+
 
    !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
    !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
-   REAL,PARAMETER      ::  pp_not_used = 999999_wp , &
-      &                    pp_to_be_computed = 0._wp
-   !!
-   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
-   !!
-   INTEGER, PARAMETER ::     & !
-      jphgr_msh = 0            !: type of horizontal mesh
-      !                        !  = 0 curvilinear coordinate on the sphere
-      !                        !      read in coordinate.nc file
-      !                        !  = 1 geographical mesh on the sphere
-      !                        !      with regular grid-spacing
-      !                        !  = 2 f-plane with regular grid-spacing
-      !                        !  = 3 beta-plane with regular grid-spacing
-      !                        !  = 4 Mercator grid with T/U point at the equator  with
-      !                        !      isotropic resolution (e1_deg)
+
+   REAL(wp), PARAMETER ::              &
+      pp_not_used       = 999999._wp , &  !:
+      pp_to_be_computed = 0._wp           !:
+
+
+   !! Coefficients associated with the horizontal coordinate system
+
+   INTEGER, PARAMETER  ::     &
+      jphgr_msh = 0              !: type of horizontal mesh
+      !                          !: = 0 curvilinear coordinate on the sphere
+      !                          !:     read in coordinate.nc file
+      !                          !: = 1 geographical mesh on the sphere
+      !                          !:     with regular grid-spacing
+      !                          !: = 2 f-plane with regular grid-spacing
+      !                          !: = 3 beta-plane with regular grid-spacing
+      !                          !: = 4 Mercator grid with T/U point at the equator  with
+      !                          !:     isotropic resolution (e1_deg)
 
       !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
       !   The mercator grid starts only approximately at gphi0 because
       !   of the constraint that the equator be a T point.
-   REAL(wp), PARAMETER ::       &  !
-      ppglam0  = pp_not_used,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
-      ppgphi0  = pp_not_used,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
-      !                            !  latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
-      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
-      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+
+   REAL(wp), PARAMETER ::     &
+      ppglam0  = pp_not_used, &  !: longitude of first raw and column T-point   (jphgr_msh = 1)
+      ppgphi0  = pp_not_used, &  !: latitude  of first raw and column T-point   (jphgr_msh = 1)
+      !                          !: latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used, &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used, &  !: meridional grid-spacing (degrees)
       !
-      ppe1_m   = pp_not_used,   &  !: zonal      grid-spacing (meters )
-      ppe2_m   = pp_not_used       !: meridional grid-spacing (meters )
+      ppe1_m   = pp_not_used, &  !: zonal      grid-spacing (meters )
+      ppe2_m   = pp_not_used     !: meridional grid-spacing (meters )
+
 
    !!  Coefficients associated with the vertical coordinate system
 
-   REAL(wp), PARAMETER  ::       &
-      &     ppsur = pp_to_be_computed ,  &  !: Computed in domzgr, set ppdzmin and pphmax below
-      &     ppa0  = pp_to_be_computed ,  &  !:    "           "
-      &     ppa1  = pp_to_be_computed ,  &  !:    "           "
-      !
-      &     ppkth =  23.563_wp        ,  &  !: (non dimensional): gives the approximate
-      !                                     !: layer number above which  stretching will
-      !                                     !: be maximum. Usually of order jpk/2.
-      &     ppacr =    9.00000000000_wp     !: (non dimensional): stretching factor
-      !                                     !: for the grid. The highest zacr, the smallest
-      !                                     !: the stretching.
+   REAL(wp), PARAMETER ::                      &
+      &     ppsur =   pp_to_be_computed     ,  &  !: Computed in domzgr, set ppdzmin and pphmax below
+      &     ppa0  =   pp_to_be_computed     ,  &  !:    "           "
+      &     ppa1  =   pp_to_be_computed     ,  &  !:    "           "
+      &     ppkth =   23.563_wp             ,  &  !: (non dimensional): gives the approximate
+      !                                           !: layer number above which  stretching will
+      !                                           !: be maximum. Usually of order jpk/2.
+      &     ppacr =   9.00000000000_wp            !: (non dimensional): stretching factor
+      !                                           !: for the grid. The higher zacr, the smaller
+      !                                           !: the stretching.
 
-   !!
-   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
-   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
-   !!
-   REAL(wp), PARAMETER ::        &
-      &     ppdzmin = 6._wp           ,  &  !: (meters) vertical thickness of the top layer
-      &     pphmax  = 5750._wp              !: (meters) Maximum depth of the ocean gdepw(jpk)
-   LOGICAL,  PARAMETER ::        &
-      &     ldbletanh = .FALSE.             !: Use/do not use double tanf function for vertical coordinates
-   REAL(wp), PARAMETER ::        &
-      &     ppa2    = pp_not_used     ,  &  !: Double tanh function parameters
-      &     ppkth2  = pp_not_used     ,  &  !:
-      &     ppacr2  = pp_not_used           !:
+      !  If both ppa0 ppa1 and ppsur are specified to pp_to_be_computed, then
+      !  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+
+   REAL(wp), PARAMETER ::                      &
+      &     ppdzmin = 6._wp                 ,  &  !: (meters) vertical thickness of the top layer
+      &     pphmax  = 5750._wp                    !: (meters) Maximum depth of the ocean gdepw(jpk)
+   LOGICAL,  PARAMETER ::                      &
+      &     ldbletanh = .FALSE.                   !: Use/do not use double tanf function for vertical coordinates
+   REAL(wp), PARAMETER ::                      &
+      &     ppa2    = pp_not_used           ,  &  !: Double tanh function parameters
+      &     ppkth2  = pp_not_used           ,  &  !:
+      &     ppacr2  = pp_not_used                 !:
    !!---------------------------------------------------------------------
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_oce.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_oce.F90	(revision 4228)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/NEMO/OPA_SRC/par_oce.F90	(revision 4229)
@@ -104,4 +104,12 @@
 
    ! global or zoom domain size                      !!! * computational domain *
+#if defined key_c1d
+   INTEGER, PUBLIC, PARAMETER ::   jpiglo  = 3        !: 1st dimension of global domain --> i
+   INTEGER, PUBLIC, PARAMETER ::   jpjglo  = 3        !: 2nd    -                  -    --> j
+
+   ! zoom starting position 
+   INTEGER, PUBLIC            ::   jpizoom =   1      !: left bottom (i,j) indices of the zoom
+   INTEGER, PUBLIC            ::   jpjzoom =   1      !: in data domain indices
+#else
    INTEGER, PUBLIC, PARAMETER ::   jpiglo  = jpidta   !: 1st dimension of global domain --> i
    INTEGER, PUBLIC, PARAMETER ::   jpjglo  = jpjdta   !: 2nd    -                  -    --> j
@@ -110,4 +118,5 @@
    INTEGER, PUBLIC, PARAMETER ::   jpizoom =   1      !: left bottom (i,j) indices of the zoom
    INTEGER, PUBLIC, PARAMETER ::   jpjzoom =   1      !: in data domain indices
+#endif
 
    ! Domain characteristics
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/bin/ooo
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/bin/ooo	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/bin/ooo	(revision 4229)
@@ -0,0 +1,4 @@
+#!/usr/bin/env python2.7
+import ooo
+if __name__ == '__main__':
+    ooo.main()
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/Makefile
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/Makefile	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/Makefile	(revision 4229)
@@ -0,0 +1,153 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS    =
+SPHINXBUILD   = sphinx-build
+PAPER         =
+BUILDDIR      = build
+
+# Internal variables.
+PAPEROPT_a4     = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
+
+help:
+	@echo "Please use \`make <target>' where <target> is one of"
+	@echo "  html       to make standalone HTML files"
+	@echo "  dirhtml    to make HTML files named index.html in directories"
+	@echo "  singlehtml to make a single large HTML file"
+	@echo "  pickle     to make pickle files"
+	@echo "  json       to make JSON files"
+	@echo "  htmlhelp   to make HTML files and a HTML help project"
+	@echo "  qthelp     to make HTML files and a qthelp project"
+	@echo "  devhelp    to make HTML files and a Devhelp project"
+	@echo "  epub       to make an epub"
+	@echo "  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+	@echo "  latexpdf   to make LaTeX files and run them through pdflatex"
+	@echo "  text       to make text files"
+	@echo "  man        to make manual pages"
+	@echo "  texinfo    to make Texinfo files"
+	@echo "  info       to make Texinfo files and run them through makeinfo"
+	@echo "  gettext    to make PO message catalogs"
+	@echo "  changes    to make an overview of all changed/added/deprecated items"
+	@echo "  linkcheck  to check all external links for integrity"
+	@echo "  doctest    to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+	-rm -rf $(BUILDDIR)/*
+
+html:
+	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+	$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+	$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+	@echo
+	@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+	$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+	@echo
+	@echo "Build finished; now you can process the pickle files."
+
+json:
+	$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+	@echo
+	@echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+	$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+	@echo
+	@echo "Build finished; now you can run HTML Help Workshop with the" \
+	      ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+	$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+	@echo
+	@echo "Build finished; now you can run "qcollectiongenerator" with the" \
+	      ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+	@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Offlineobservationoperator.qhcp"
+	@echo "To view the help file:"
+	@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Offlineobservationoperator.qhc"
+
+devhelp:
+	$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+	@echo
+	@echo "Build finished."
+	@echo "To view the help file:"
+	@echo "# mkdir -p $$HOME/.local/share/devhelp/Offlineobservationoperator"
+	@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Offlineobservationoperator"
+	@echo "# devhelp"
+
+epub:
+	$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+	@echo
+	@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo
+	@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+	@echo "Run \`make' in that directory to run these through (pdf)latex" \
+	      "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo "Running LaTeX files through pdflatex..."
+	$(MAKE) -C $(BUILDDIR)/latex all-pdf
+	@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+	$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+	@echo
+	@echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+	$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+	@echo
+	@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+texinfo:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo
+	@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+	@echo "Run \`make' in that directory to run these through makeinfo" \
+	      "(use \`make info' here to do that automatically)."
+
+info:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo "Running Texinfo files through makeinfo..."
+	make -C $(BUILDDIR)/texinfo info
+	@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+gettext:
+	$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+	@echo
+	@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+changes:
+	$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+	@echo
+	@echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+	$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+	@echo
+	@echo "Link check complete; look for any errors in the above output " \
+	      "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+	$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+	@echo "Testing of doctests in the sources finished, look at the " \
+	      "results in $(BUILDDIR)/doctest/output.txt."
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/make.bat
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/make.bat	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/make.bat	(revision 4229)
@@ -0,0 +1,190 @@
+@ECHO OFF
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+	set SPHINXBUILD=sphinx-build
+)
+set BUILDDIR=build
+set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source
+set I18NSPHINXOPTS=%SPHINXOPTS% source
+if NOT "%PAPER%" == "" (
+	set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
+	set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
+)
+
+if "%1" == "" goto help
+
+if "%1" == "help" (
+	:help
+	echo.Please use `make ^<target^>` where ^<target^> is one of
+	echo.  html       to make standalone HTML files
+	echo.  dirhtml    to make HTML files named index.html in directories
+	echo.  singlehtml to make a single large HTML file
+	echo.  pickle     to make pickle files
+	echo.  json       to make JSON files
+	echo.  htmlhelp   to make HTML files and a HTML help project
+	echo.  qthelp     to make HTML files and a qthelp project
+	echo.  devhelp    to make HTML files and a Devhelp project
+	echo.  epub       to make an epub
+	echo.  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter
+	echo.  text       to make text files
+	echo.  man        to make manual pages
+	echo.  texinfo    to make Texinfo files
+	echo.  gettext    to make PO message catalogs
+	echo.  changes    to make an overview over all changed/added/deprecated items
+	echo.  linkcheck  to check all external links for integrity
+	echo.  doctest    to run all doctests embedded in the documentation if enabled
+	goto end
+)
+
+if "%1" == "clean" (
+	for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
+	del /q /s %BUILDDIR%\*
+	goto end
+)
+
+if "%1" == "html" (
+	%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/html.
+	goto end
+)
+
+if "%1" == "dirhtml" (
+	%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
+	goto end
+)
+
+if "%1" == "singlehtml" (
+	%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
+	goto end
+)
+
+if "%1" == "pickle" (
+	%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can process the pickle files.
+	goto end
+)
+
+if "%1" == "json" (
+	%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can process the JSON files.
+	goto end
+)
+
+if "%1" == "htmlhelp" (
+	%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can run HTML Help Workshop with the ^
+.hhp project file in %BUILDDIR%/htmlhelp.
+	goto end
+)
+
+if "%1" == "qthelp" (
+	%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can run "qcollectiongenerator" with the ^
+.qhcp project file in %BUILDDIR%/qthelp, like this:
+	echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Offlineobservationoperator.qhcp
+	echo.To view the help file:
+	echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Offlineobservationoperator.ghc
+	goto end
+)
+
+if "%1" == "devhelp" (
+	%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished.
+	goto end
+)
+
+if "%1" == "epub" (
+	%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The epub file is in %BUILDDIR%/epub.
+	goto end
+)
+
+if "%1" == "latex" (
+	%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
+	goto end
+)
+
+if "%1" == "text" (
+	%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The text files are in %BUILDDIR%/text.
+	goto end
+)
+
+if "%1" == "man" (
+	%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The manual pages are in %BUILDDIR%/man.
+	goto end
+)
+
+if "%1" == "texinfo" (
+	%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
+	goto end
+)
+
+if "%1" == "gettext" (
+	%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
+	goto end
+)
+
+if "%1" == "changes" (
+	%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.The overview file is in %BUILDDIR%/changes.
+	goto end
+)
+
+if "%1" == "linkcheck" (
+	%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Link check complete; look for any errors in the above output ^
+or in %BUILDDIR%/linkcheck/output.txt.
+	goto end
+)
+
+if "%1" == "doctest" (
+	%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Testing of doctests in the sources finished, look at the ^
+results in %BUILDDIR%/doctest/output.txt.
+	goto end
+)
+
+:end
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/conf.py
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/conf.py	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/conf.py	(revision 4229)
@@ -0,0 +1,246 @@
+# -*- coding: utf-8 -*-
+#
+# Offline observation operator documentation build configuration file, created by
+# sphinx-quickstart on Mon Oct  7 17:21:35 2013.
+#
+# This file is execfile()d with the current directory set to its containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys, os
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+sys.path.insert(0, os.path.abspath('../..'))
+
+# -- General configuration -----------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be extensions
+# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx']
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'Offline observation operator'
+copyright = u'2013, Andrew Ryan'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '0.1'
+# The full version, including alpha/beta/rc tags.
+release = '0.1.0'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = []
+
+# The reST default role (used for this markup: `text`) to use for all documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+
+# -- Options for HTML output ---------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  See the documentation for
+# a list of builtin themes.
+html_theme = 'default'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further.  For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+#html_theme_path = []
+
+# The name for this set of Sphinx documents.  If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# A shorter title for the navigation bar.  Default is the same as html_title.
+#html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_domain_indices = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it.  The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'Offlineobservationoperatordoc'
+
+
+# -- Options for LaTeX output --------------------------------------------------
+
+latex_elements = {
+# The paper size ('letterpaper' or 'a4paper').
+#'papersize': 'letterpaper',
+
+# The font size ('10pt', '11pt' or '12pt').
+#'pointsize': '10pt',
+
+# Additional stuff for the LaTeX preamble.
+#'preamble': '',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass [howto/manual]).
+latex_documents = [
+  ('index', 'Offlineobservationoperator.tex', u'Offline observation operator Documentation',
+   u'Andrew Ryan', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_domain_indices = True
+
+
+# -- Options for manual page output --------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+    ('index', 'offlineobservationoperator', u'Offline observation operator Documentation',
+     [u'Andrew Ryan'], 1)
+]
+
+# If true, show URL addresses after external links.
+#man_show_urls = False
+
+
+# -- Options for Texinfo output ------------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+#  dir menu entry, description, category)
+texinfo_documents = [
+  ('index', 'Offlineobservationoperator', u'Offline observation operator Documentation',
+   u'Andrew Ryan', 'Offlineobservationoperator', 'One line description of project.',
+   'Miscellaneous'),
+]
+
+# Documents to append as an appendix to all manuals.
+#texinfo_appendices = []
+
+# If false, no module index is generated.
+#texinfo_domain_indices = True
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#texinfo_show_urls = 'footnote'
+
+
+# Example configuration for intersphinx: refer to the Python standard library.
+intersphinx_mapping = {'http://docs.python.org/': None}
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/index.rst
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/index.rst	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/index.rst	(revision 4229)
@@ -0,0 +1,23 @@
+.. Offline observation operator documentation master file, created by
+   sphinx-quickstart on Mon Oct  7 17:21:35 2013.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
+Welcome to Offline observation operator's documentation!
+========================================================
+
+Contents:
+
+.. toctree::
+   :maxdepth: 2
+
+   intro
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
+
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/intro.rst
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/intro.rst	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/doc/source/intro.rst	(revision 4229)
@@ -0,0 +1,57 @@
+
+Introduction
+------------
+
+The offline observation operator quick start script involves simple
+computation and manipulation of NEMO namelists.
+
+Quick start script
+------------------
+
+.. code-block:: none
+
+   ooo -h
+   usage: ooo [-h] [-w WORK_DIR] [-f FORECAST_TYPES] [-l LEAD_TIMES]
+              [-o OBS_TYPES] [--class4]
+              DATE NAMELIST
+   
+   positional arguments:
+     DATE                  Run date.
+     NAMELIST              NEMO namelist to edit.
+   
+   optional arguments:
+     -h, --help            show this help message and exit
+     -w WORK_DIR, --work-dir WORK_DIR
+     -f FORECAST_TYPES, --forecast-types FORECAST_TYPES
+                           Choice of forecast,persistence,climatology
+     -l LEAD_TIMES, --lead-times LEAD_TIMES
+                           Forecast lead times
+     -o OBS_TYPES, --obs-types OBS_TYPES
+                           Choice of namobs types.
+     --class4              Flag to choose class 4 file outputs
+     --dry-run             Flag to test namelist building without submitting.
+     --cmd COMMAND         Submit task to run.
+     -v, --verbose         Prints difference between before and after namelists.
+
+
+The above command line utility ``ooo`` can be used to edit **NEMO** namelists. 
+
+Run
+---
+
+.. automodule:: ooo.run
+   :members:
+
+
+Locators
+--------
+
+.. automodule:: ooo.locator
+   :members:
+
+Fortran
+-------
+
+.. automodule:: ooo.nml
+   :members:
+
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/__init__.py
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/__init__.py	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/__init__.py	(revision 4229)
@@ -0,0 +1,3 @@
+import nml
+import locator
+from ooo import main
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/locator.py
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/locator.py	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/locator.py	(revision 4229)
@@ -0,0 +1,151 @@
+"""Locates input files and calculates namelist attributes
+
+    Typically a user will have files distributed throughout the hard drive
+    and it makes little or no sense to try to capture all use cases.
+
+    >>> date = "20130101"
+    >>> namobs = observations(date, types=["profbfiles"])
+
+    >>> namooo, namcl4 = forecasts(date, types=["forecast", "persistence"], lead_times=[12, 36, 60])
+"""
+
+def observations(date, types=None):
+    """Responsible for locating observation files
+
+    Valid **namobs** observation types.
+
+    * profbfiles
+    * sstfbfiles
+    * slafbfiles
+
+    :param date: The verification date in string format ``'%Y%m%d'``
+    :param types: A list of namobs observation types
+
+    :returns: namobs namelist dictionary
+    """
+    namobs = {"ln_t3d": False,
+              "ln_s3d": False,
+              "ln_ena": False,
+              "ln_profb": False,
+              "ln_sst": False,
+              "ln_sstfb": False,
+              "ln_reysst": False,
+              "ln_ghrsst": False,
+              "ln_sla": False,
+              "ln_slafb": False,
+              "ln_sladt": False}
+    if types is None: types = []
+    for obtype in types: 
+        if obtype == "profbfiles":
+            namobs[obtype] = profbfiles(date)
+            namobs["ln_t3d"] = True
+            namobs["ln_s3d"] = True
+            namobs["ln_profb"] = True
+        elif obtype == "sstfbfiles":
+            namobs[obtype] = sstfbfiles(date)
+            namobs["ln_sst"] = True
+            namobs["ln_sstfb"] = True
+        elif obtype == "slafbfiles":
+            namobs[obtype] = slafbfiles(date)
+            namobs["ln_sla"] = True
+            namobs["ln_slafb"] = True
+    return namobs
+
+def profbfiles(date):
+    """Observation file locator stub
+
+    .. note:: User-specified stub
+
+    :param date: The verification date in string format ``'%Y%m%d'``
+    :returns: List of files
+    """
+    files = ['profb.nc']
+    return files
+
+def sstfbfiles(date):
+    """Observation file locator stub
+
+    .. note:: User-specified stub
+
+    :param date: The verification date in string format ``'%Y%m%d'``
+    :returns: List of files
+    """
+    files = ['sstfb.nc']
+    return files
+
+def slafbfiles(date):
+    """Observation file locator stub
+
+    .. note:: User-specified stub
+
+    :param date: The verification date in string format ``'%Y%m%d'``
+    :returns: List of files
+    """
+    files = ['slafb.nc']
+    return files
+
+def forecasts(date, types=None, lead_times=None):
+    """Responsible for locating forecast fields
+
+    :param date: The verification date in string format ``'%Y%m%d'``
+    :param types: A list of forecast system types
+    :param lead_times: A list of lead_times to search for
+
+    :returns: tuple of namelist data, (namooo, namcl4)
+    """
+    namooo = {}
+    namcl4 = {}
+    if types is None: types = []
+    if lead_times is None: lead_times = []
+
+    # Initialise data
+    ooo_files = []
+    nn_ooo_idx = []
+    cl4_vars = []
+    cl4_fcst_idx = []
+
+    # Search for files
+    for type in types:
+        files = []
+        in_indices = []
+        out_indices = []
+        for ilt, lead_time in enumerate(lead_times):
+            file, index = field(date, type=type, lead_time=lead_time)
+            files.append(file)
+            in_indices.append(index)
+            out_indices.append(ilt + 1)
+        # Expand return lists
+        ooo_files += files
+        nn_ooo_idx += in_indices
+        cl4_fcst_idx += out_indices
+        cl4_vars += len(files) * [type]
+
+    # Namoo
+    namooo["ooo_files"] = ooo_files
+    namooo["nn_ooo_idx"] = nn_ooo_idx
+
+    # Namcl4
+    namcl4["cl4_vars"] = cl4_vars
+    namcl4["cl4_fcst_idx"] = cl4_fcst_idx
+
+    return namooo, namcl4
+
+def field(date, type=None, lead_time=None):
+    """Forecast field locator
+
+    Maps verification date and lead time off set to file name and
+    index along file *time_counter*
+
+    .. note:: User-specified stub
+
+    :param date: The verification date in string format ``'%Y%m%d'``
+    :param type: Forecast type
+    :param lead_time: Forecast off set
+
+    :returns: (**path**, **index**)
+    """
+    # Worker function
+    file = 'nofile'
+    index = -1
+    return file, index
+
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/nml.py
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/nml.py	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/nml.py	(revision 4229)
@@ -0,0 +1,479 @@
+"""Collection of Fortran 90 namelist helper functions.
+
+    A common way to interface with a Fortran executable is via
+    an input file called a namelist. This module defines
+    functions which simplify the process of updating and
+    extending namelist data.
+
+    .. note:: This module is especially lightweight and follows the
+              batteries included philosophy. As such, only standard
+              library modules are required to use this code.
+
+    Walkthrough
+    ===========
+
+    New namelist
+    ------------
+
+    A typical usage is to create and update a Fortran namelist on the fly.
+
+    >>> import nml
+    >>> namid = "namfoo"
+    >>> text = nml.new(namid)
+    >>> data = {"x": nml.tostring([1, 2, 3])}
+    >>> text = nml.update(namid, text, data)
+    >>> print text
+    &namfoo
+       x = 1 2 3
+    /
+    <BLANKLINE>
+
+    In the above snippet :func:`tostring` has been used to sanitize the input
+    Python list. This function cleverly maps string data and numeric data to
+    the correct Fortran syntax.
+
+    However, the :func:`new` function takes care of many of the above steps automatically.
+    Where appropriate :func:`sanitize` has been embedded to reduce the need
+    to worry about data format problems. Take for example,
+
+    >>> print nml.new("namfoo", data={"x": range(3)})
+    &namfoo
+       x = 0 1 2
+    /
+    <BLANKLINE>
+
+    Parse existing namelist
+    -----------------------
+
+    In order to update a namelist it is necessary to convert the namelist text into
+    a dictionary of *key, value* pairs which can be manipulated in the usual Pythonic
+    fashion before being piped back out to disk.
+
+    In everyday usage text will be read from files, here however for illustration
+    purposes I have hand written a namelist.
+
+    >>> text = '''
+    ... &namfoo
+    ...     x = y  ! A description of the variables
+    ... /
+    ... &nambar
+    ...     ln_on = .TRUE. ! A description of the variables
+    ... /
+    ... '''
+
+    This can be parsed by invoking the :func:`variables` command.
+
+    >>> nml.variables(text)
+    {'x': 'y', 'ln_on': '.TRUE.'}
+
+    Or by using the :func:`namelists` function to split the file into sub-lists.
+
+    >>> nml.namelists(text)
+    {'namfoo': '&namfoo\\n    x = y  ! A description of the variables\\n/', 'nambar': '&nambar\\n    ln_on = .TRUE. ! A description of the variables\\n/'}
+    >>> sublists = nml.namelists(text)
+    >>> print sublists["nambar"]
+    &nambar
+        ln_on = .TRUE. ! A description of the variables
+    /
+
+    Which can be parsed into a dictionary as before.
+
+    >>> print nml.variables(sublists["nambar"])
+    {'ln_on': '.TRUE.'}
+
+
+    Update/replace data
+    -------------------
+
+    There are two ways of modifying values inside a Fortran namelist. 
+
+    Replace
+        The first is to simply replace a set of variables with new values. This behaviour is accomplished
+        via the :func:`replace` function. This approach simply overwrites existing variables. No knowledge
+        of sub-namelist structure is required to modify a string of text. 
+
+    .. note:: Additional variables will not be added to a namelist via this approach
+
+    Update
+        The second is to extend the set of variables contained within a namelist. This functionality is
+        controlled by the :func:`update` function. Here, variables which are not already specified are
+        added using a templated namelist line.
+
+    .. note:: It is essential to specify which sub-namelist is to be updated before modification takes place
+
+    Pipe to/from file
+    -----------------
+
+    As typical NEMO namelists are no larger than a few tens of kilobytes
+    it makes sense to process namelists as single strings instead of
+    line by line.
+
+    >>> path = "foo.nml"
+    >>> text = nml.new("namfoo")
+
+    To write to a file simply invoke the writer.
+
+    >>> # Write to file
+    >>> nml.writer(path, text)
+
+    To read from a file specify the path to be read.
+
+    >>> # Read from file
+    >>> text = nml.reader(path)
+
+    Join multiple namelists
+    -----------------------
+
+    Since the namelists are regular Python strings there is no need for a 
+    specific *join* function. Namelists can be combined in whatever manner
+    is most pleasing to the eye.
+
+    >>> namoff = nml.new("namoff")
+    >>> namcl4 = nml.new("namcl4")
+    >>> # new line join
+    >>> print "\\n".join([namoff, namcl4])
+    &namoff
+    /
+    <BLANKLINE>
+    &namcl4
+    /
+    <BLANKLINE>
+
+    >>> # Or addition
+    >>> print namoff + namcl4
+    &namoff
+    /
+    &namcl4
+    /
+    <BLANKLINE>
+
+    Module functions
+    ================
+
+"""
+__version__ = "0.1.0"
+import re
+from numbers import Number
+
+def reader(path):
+    """Reads a file into a string
+
+    Reads whole file into single string. Typically, 
+    namelists are small enough to be stored in memory
+    while updates and edits are being performed.
+
+    :param path: Path to input file
+    :returns: entire file as a single string
+
+    """
+    with open(path, "r") as handle:
+        text = handle.read()
+    return text
+
+def writer(path, text):
+    """Writes to a file from a string
+
+    Handy way of piping a processed namelist into
+    a file.
+
+    :param path: Path to output file
+    :param text: Input text to process
+
+    """
+    with open(path, "w") as handle:
+        handle.write(text)
+
+def update(namid, text, data, convert=True):
+    """Extends namelist definition.
+
+    Similar to replace this function alters the values
+    of variables defined within a namelist. In addition to
+    replacing values it also creates definitions if the
+    variable is not found in the namelist. As such, the
+    namelist id must be specified.
+
+    :param namid: Namelist id
+    :param text: Input text to process
+    :param data: Dictionary of variables
+    :keyword convert: Sanitizes input data before replacement takes place
+
+    :returns: Text
+
+    .. seealso:: :func:`replace` :func:`sanitize`
+    """
+    sublists = namelists(text)
+    assert namid in sublists, "Warning: invalid namid specified!"
+
+    # Sanitize inputs
+    if convert:
+        data = sanitize(data)
+
+    # Parse subsection
+    namtext = sublists[namid]
+    subdata = variables(namtext)
+    subvars = subdata.keys()
+
+    # Replace existing variables in namtext
+    tmptext = replace(namtext, data)
+    text = text.replace(namtext, tmptext)
+    namtext = tmptext
+
+    # Identify new variables
+    vars = data.keys()
+    newvars = list(set(vars) - set(subvars))
+    newvars.sort()
+
+    # Append new vars to namid
+    lines = namtext.split("\n")
+    for v in newvars:
+        newline = "   %s = %s" % (v, data[v])
+        lines.insert(-1, newline)
+    newtext = "\n".join(lines)
+
+    # Replace old namtext with new namtext
+    text = text.replace(namtext, newtext)
+    return text
+
+def replace(text, data, convert=True):
+    """Edits existing variables.
+
+    Pattern matches and substitutes variables inside
+    a string of text. This is independent of namid and
+    as such is useful for modifying existing variables.
+    To append new variables the :func:`update` function 
+    is required.
+
+    >>> text = '''
+    ... &namobs
+    ...    ln_sst = .TRUE. ! Logical switch for SST observations
+    ... /
+    ... '''
+    >>> data = {"ln_sst": ".FALSE."}
+    >>> print replace(text, data)
+    <BLANKLINE>
+    &namobs
+       ln_sst = .FALSE. ! Logical switch for SST observations
+    /
+    <BLANKLINE>
+
+    .. note :: This does not append new variables to a namelist
+
+    :param text: string to process
+    :param data: dictionary with which to modify **text**
+    :keyword convert: Sanitizes input data before replacement takes place
+
+    :returns: string with new data values
+
+    .. seealso:: :func:`update`, :func:`sanitize`
+    """
+    if convert:
+        data = sanitize(data)
+    for k, v in data.iteritems():
+        pat = r"(%s\s*=\s*).+?(\s*[!\n])" % (k,)
+        repl = r"\g<1>%s\g<2>" % (v,)
+        text = re.sub(pat, repl, text)
+    return text
+
+def variables(text):
+    """Retrieves dictionary of variables in text.
+
+    >>> text = '''
+    ... &namobs
+    ...    ln_sst = .TRUE. ! Logical switch for SST observations
+    ... /
+    ... '''
+    >>> variables(text)
+    {'ln_sst': '.TRUE.'}
+
+    :param text: Input text to process
+
+    :returns: A dictionary of variable, value pairs.
+
+    """
+    data = {}
+    pairs = re.findall(r"\n\s*(\w+)\s*=\s*(.+?)\s*(?=[!\n])", text)
+    for key, value in pairs:
+        data[key] = value
+    return data
+
+def namelists(text):
+    """Retrieves dictionary of namelists in text.
+
+    Useful for isolating sub-namelists.
+
+    >>> text = '''
+    ... &namobs
+    ...    ln_sst = .TRUE. ! Logical switch for SST observations
+    ... /
+    ... '''
+    >>> namelists(text)
+    {'namobs': '&namobs\\n   ln_sst = .TRUE. ! Logical switch for SST observations\\n/'}
+
+    :param text: Input text to process
+
+    :returns: A dictionary of id, text block key, value pairs
+
+    """
+    # Boundary case
+    if text.startswith("&"):
+        text = "\n" + text
+    # Regular expression
+    results = re.findall(r"\n(&(\w+).*?\n/)", text, re.DOTALL)
+    data = {}
+    for content, namid in results:
+        data[namid] = content
+    return data
+
+def tostring(data):
+    """Maps standard Python data to Fortran namelist format.
+
+    >>> tostring([1, 2, 3])
+    '1 2 3'
+    >>> tostring(["foo.nc", "bar.nc"])
+    "'foo.nc', 'bar.nc'"
+    >>> tostring(True)
+    '.TRUE.'
+
+    :param data: Input Python data
+
+    :returns: Namelist formatted string
+
+    .. seealso:: :func:`sanitize`
+    """
+    if isinstance(data, list):
+        if all_numeric(data):
+            delim = " "
+        else:
+            delim = ", "
+        text = delim.join([convert(item) for item in data])
+    else:
+        text = convert(data)
+    return text
+
+def all_numeric(inputs):
+    # Checks all list entries are numbers
+    flag = True
+    for input in inputs:
+        if not isinstance(input, Number):
+            flag = False
+            break
+    return flag
+
+def numeric(word):
+    # Tests input string is numeric data
+    parts = word.split(" ")
+    try:
+        map(float, parts)
+        flag = True
+    except ValueError:
+        flag = False
+    return flag
+
+def logical(word):
+    # Tests input string is numeric data
+    if word.upper() in [".FALSE.", ".TRUE."]:
+        flag = True
+    else:
+        flag = False
+    return flag
+
+def listed(word):
+    # Tests input string is not a list
+    if ("," in word) or (" " in word):
+        flag = True
+    else:
+        flag = False
+    return flag
+
+def quote(word):
+    word = str(word)
+    if not quoted(word):
+        word = "'%s'" % (word,)
+    return word
+
+def convert(word):
+    # Conversion function
+    if isinstance(word, str):
+        if (quoted(word) or numeric(word) 
+            or logical(word) or listed(word)):
+            result = "%s" % (word,)
+        else:
+            result = quote(word)
+    elif isinstance(word, bool):
+        if word:
+            result = ".TRUE."
+        else:
+            result = ".FALSE."
+    else:
+        result = str(word)
+    return result
+
+def quoted(word):
+    # Checks if string begins/ends with quotation marks
+    if (word.startswith("'") and word.endswith("'")):
+        flag = True
+    elif (word.startswith('"') and word.endswith('"')):
+        flag = True
+    else: 
+        flag = False
+    return flag
+
+def same_type(data):
+    # True if all entries are the same type
+    types = map(type, data)
+    if len(set(types)) == 1:
+        flag = True
+    else:
+        flag = False
+    return flag
+
+def sanitize(data):
+    """Converts dictionary values into Fortran namelist format.
+
+    This is a more typical way to prepare data for inclusion in
+    a Fortran namelist. Instead of manually applying :func:`tostring`
+    to every element of the input data, **sanitize** fixes the entire
+    data set.
+
+    >>> sanitize({"x": True})
+    {'x': '.TRUE.'}
+    >>> 
+
+    :param data: Dictionary to convert
+
+    :returns: Dictionary whose values are in Fortran namelist format
+
+    .. seealso:: :func:`tostring`
+    """
+    replacements = [(k, tostring(v)) for k, v in data.items()]
+    data.update(replacements)
+    return data
+
+def new(namid, data=None, convert=True):
+    """Creates a new Fortran namelist
+
+    >>> new("namobs")
+    '&namobs\\n/\\n'
+    >>> print new("namobs")
+    &namobs
+    /
+    <BLANKLINE>
+
+    :param namid: Name for the new namelist
+
+    :keyword data: Specifies an initial dictionary with which to
+                   populate the namelist
+    :type data: dict
+    :keyword convert: Sanitizes input data before replacement takes place
+
+    :returns: string representation of a Fortran namelist
+    """
+    text = "&{namid}\n/\n".format(namid=namid)
+    if data is not None:
+        text = update(namid, text, data, convert=convert)
+    return text
+
+if __name__ == '__main__':
+    import doctest
+    doctest.testmod()
+
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/ooo.py
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/ooo.py	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/ooo.py	(revision 4229)
@@ -0,0 +1,124 @@
+#!/usr/bin/env python2.7
+
+import os
+import shutil
+
+# Local imports
+import locator
+import nml
+import run
+
+def parse_args():
+    import argparse
+    parser = argparse.ArgumentParser()
+    parser.add_argument("date", metavar="DATE", 
+                        help="Run date.")
+    parser.add_argument("-w", "--work-dir", default=os.getcwd())
+    parser.add_argument("-f", "--forecast-types", default="forecast",
+                        help="Choice of forecast,persistence,climatology")
+    parser.add_argument("-l", "--lead-times", default="12",
+                        help="Forecast lead times")
+    parser.add_argument("-o", "--obs-types", default="profbfiles",
+                        help="Choice of namobs types.")
+    parser.add_argument("--class4", dest="ln_cl4", action="store_true",
+                        help="Flag to choose class 4 file outputs")
+    parser.add_argument("--dry-run", action="store_true",
+                        help="Flag to test namelist building without submitting.")
+    parser.add_argument("--cmd", dest="command", default="./opa",
+                        help="Submit task to run.")
+    parser.add_argument("-v", "--verbose", action="store_true",
+                        help="Prints difference between before and after namelists.")
+    parser.add_argument("namelist", metavar="NAMELIST", 
+                        help="NEMO namelist to edit.")
+    args = parser.parse_args()
+    args.forecast_types = args.forecast_types.split(',')
+    args.obs_types = args.obs_types.split(',')
+    args.lead_times = map(int, args.lead_times.split(','))
+    return args
+
+def printdiff(text1, text2):
+    # Provides nice text difference summary of namelists
+    import difflib
+    lines1 = text1.splitlines()
+    lines2 = text2.splitlines()
+    d = difflib.Differ()
+    result = list(d.compare(lines1, lines2))
+    text = '\n'.join(result)
+    print text
+
+def main():
+    args = parse_args()
+    date = args.date
+    print "Processing", args.namelist, " for", args.date
+    
+    # Move to working directory
+    if not os.path.exists(args.work_dir):
+        os.makedirs(args.work_dir)
+    os.chdir(args.work_dir)
+
+    # Collect forecast files
+    types = args.forecast_types
+    lead_times = args.lead_times
+    namooo, namcl4 = locator.forecasts(date=date,
+                                       types=types,
+                                       lead_times=lead_times)
+
+    # Process NEMO namelist
+    text = nml.reader(args.namelist)
+    sublists = nml.namelists(text)
+
+    # Verbose save original text
+    if args.verbose:
+        original_text = text
+
+    # namooo
+    if "namooo" not in sublists:
+        # Attach boilerplate
+        text += nml.new("namooo")
+    text = nml.update("namooo", text, data=namooo)
+
+    # namcl4
+    if "namcl4" not in sublists:
+        # Attach boilerplate
+        text += nml.new("namcl4")
+    namcl4["cl4_leadtime"] = lead_times
+    namcl4["cl4_date"] = nml.quote(date)
+    namcl4["cl4_match_len"] = len(namcl4["cl4_vars"])
+    namcl4["cl4_fcst_len"] = len(namcl4["cl4_leadtime"])
+    # Add naming convention
+    namcl4["cl4_sys"] = "FOAM"
+    namcl4["cl4_cfg"] = "orca025"
+    namcl4["cl4_vn"] = "'1.0'"
+    namcl4["cl4_prefix"] = "class4"
+    namcl4["cl4_contact"] = "example@example.com"
+    namcl4["cl4_inst"] = "institute"
+    text = nml.update("namcl4", text, data=namcl4)
+
+    # namrun
+    namrun = {"nn_date0": nml.quote(date)}
+    text = nml.update("namrun", text, data=namrun)
+
+    # namobs
+    namobs = locator.observations(date=date,
+                                  types=args.obs_types)
+    namobs["ln_cl4"] = args.ln_cl4
+    text = nml.update("namobs", text, data=namobs)
+
+    # Verbose print namelist differences
+    if args.verbose:
+        printdiff(original_text, text)
+
+    # pipe text to file
+    tmp = args.namelist+".tmp"
+    nml.writer(tmp, text)
+    shutil.move(tmp, args.namelist)
+
+    # Run job
+    if not args.dry_run:
+        run.submit(command=args.command)
+    
+
+
+if __name__ == '__main__':
+    main()
+
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/run.py
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/run.py	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/run.py	(revision 4229)
@@ -0,0 +1,27 @@
+"""
+
+The NEMO offline observation operator is built and runs similarly to the
+online NEMO model.
+ 
+"""
+import subprocess
+import shlex
+import os
+
+class SubmitError(Exception):
+    pass
+
+def submit(command="./opa"):
+    """Simple function that runs the code.
+
+    This can be customised based on the particular environment
+    used to submit MPI or serial tasks. For simplicity, this
+    function calls opa.
+
+    By default, this program runs ``./opa``.
+
+    :returns: retcode
+    """
+    retcode = subprocess.call(shlex.split(command))
+    return retcode
+
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/test_nml.py
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/test_nml.py	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/test_nml.py	(revision 4229)
@@ -0,0 +1,248 @@
+#!/usr/bin/env python2.7
+import unittest
+import nml
+
+def version(vn):
+    # Converts module version string to int tuple as PEP-440
+    return tuple(map(int, vn.split(".")))
+
+HEADER = """
+!! =====================================
+!! An example FORTRAN 90 namelist
+!! =====================================
+&namex
+"""
+NOHEADER = "&namex\n"
+LOGIC = " ln_test = .TRUE. ! Comment\n"
+NUMERIC = " nn_off_idx = 1 2 3\n"
+NOSPACE = " nn_off_idx=1 2 3\n"
+NEGATIVE = " nn_off_idx = -1 -2 -3\n"
+LIST = " off_files = 'a.nc' 'b.nc' 'c.nc' ! Comment\n"
+STRING = ' contact = "example@nowhere.com" ! Comment\n'
+COMMENT = ' ! x = y '
+FOOTER = "/\n"
+NOFOOTER = "/"
+
+class TestNamelist(unittest.TestCase):
+    def setUp(self):
+        self.logic_text = "\n".join([HEADER, LOGIC, FOOTER])
+        self.numeric_text = "\n".join([HEADER, NUMERIC, FOOTER])
+        self.nospace_text = "\n".join([HEADER, NOSPACE, FOOTER])
+        self.neg_numeric_text = "\n".join([HEADER, NEGATIVE, FOOTER])
+        self.list_text = "\n".join([HEADER, LIST, FOOTER])
+        self.mix_text = "\n".join([HEADER, LIST, NUMERIC, FOOTER])
+        self.string_text = "\n".join([HEADER, STRING, FOOTER])
+        self.comment_text = "\n".join([HEADER, COMMENT, FOOTER])
+        self.no_trail_text = "\n".join([HEADER, NUMERIC, LIST, NOFOOTER])
+
+    def test_should_handle_footer(self):
+        data = nml.variables(self.no_trail_text)
+        truth = {"nn_off_idx": "1 2 3",
+                 "off_files": "'a.nc' 'b.nc' 'c.nc'"}
+        self.assertDictEqual(data, truth)
+
+    def test_mix_data(self):
+        data = nml.variables(self.mix_text)
+        truth = {"nn_off_idx": "1 2 3",
+                 "off_files": "'a.nc' 'b.nc' 'c.nc'"}
+        self.assertDictEqual(data, truth)
+
+    def test_comment_data(self):
+        data = nml.variables(self.comment_text)
+        truth = {}
+        self.assertDictEqual(data, truth)
+
+    def test_logical_data(self):
+        data = nml.variables(self.logic_text)
+        truth = {"ln_test": ".TRUE."}
+        self.assertDictEqual(data, truth)
+
+    def test_numeric_data(self):
+        data = nml.variables(self.numeric_text)
+        truth = {"nn_off_idx": "1 2 3"}
+        self.assertDictEqual(data, truth)
+
+    def test_nospace_data(self):
+        data = nml.variables(self.nospace_text)
+        truth = {"nn_off_idx": "1 2 3"}
+        self.assertDictEqual(data, truth)
+
+    def test_negative_numeric_data(self):
+        data = nml.variables(self.neg_numeric_text)
+        truth = {"nn_off_idx": "-1 -2 -3"}
+        self.assertDictEqual(data, truth)
+
+    def test_string_data(self):
+        data = nml.variables(self.string_text)
+        truth = {"contact": '"example@nowhere.com"'}
+        self.assertDictEqual(data, truth)
+
+    def test_list_data(self):
+        data = nml.variables(self.list_text)
+        truth = {"off_files": "'a.nc' 'b.nc' 'c.nc'"}
+        self.assertDictEqual(data, truth)
+
+    def test_replace_variable_comment(self):
+        FIXTURE = " x = 'y' ! comment \n"
+        RESULT = " x = 'z' ! comment \n"
+        text = nml.replace(FIXTURE, {"x": "z"})
+        self.assertEqual(text, RESULT)
+
+    def test_replace_variable_no_comment(self):
+        FIXTURE = " x = 'y' \n"
+        RESULT = " x = 'z' \n"
+        text = nml.replace(FIXTURE, {"x": "z"})
+        self.assertEqual(text, RESULT)
+
+    def test_replace_variable_no_space(self):
+        FIXTURE = " x='y' \n"
+        RESULT = " x='z' \n"
+        text = nml.replace(FIXTURE, {"x": "z"})
+        self.assertEqual(text, RESULT)
+
+    def test_replace_variable_no_space_comment(self):
+        FIXTURE = " x='y' ! comment \n"
+        RESULT = " x='z' ! comment \n"
+        text = nml.replace(FIXTURE, {"x": "z"})
+        self.assertEqual(text, RESULT)
+
+    @unittest.skipIf(version(nml.__version__) < (1, 0),
+                     "Not implemented in this version")
+    def test_multiline_variable_replace(self):
+        # As a result of a code review
+        FIXTURE = " x = 1, \n     2"
+        RESULT =  " x = 3, \n     4"
+        text = nml.replace(FIXTURE, {"x": [3,4]})
+        self.assertEqual(text, RESULT)
+
+class TestCombinedNamelists(unittest.TestCase):
+    def setUp(self):
+        self.minimal = """&namone
+/"""
+        self.blanks = """
+&namone
+/
+&namtwo
+/
+"""
+        self.contents = """
+&namone
+Content 1
+/
+&namtwo
+Content 2
+/
+"""
+        self.contents_slash = """
+&namone
+Content 1 ! Y/N
+/
+&namtwo
+Content 2
+/
+"""
+    def test_should_select_name_from_minimal_namelist(self):
+        data = nml.namelists(self.minimal)
+        result = {"namone": "&namone\n/"}
+        self.assertDictEqual(data, result)
+
+    def test_should_select_names(self):
+        data = nml.namelists(self.blanks)
+        result = {"namone": "&namone\n/",
+                  "namtwo": "&namtwo\n/"}
+        self.assertDictEqual(data, result)
+
+    def test_should_select_contents(self):
+        data = nml.namelists(self.contents)
+        result = {"namone": "&namone\nContent 1\n/",
+                  "namtwo": "&namtwo\nContent 2\n/"}
+        self.assertDictEqual(data, result)
+
+    def test_should_select_contents_with_forward_slash(self):
+        data = nml.namelists(self.contents_slash)
+        result = {"namone": "&namone\nContent 1 ! Y/N\n/",
+                  "namtwo": "&namtwo\nContent 2\n/"}
+        self.assertDictEqual(data, result)
+
+
+class TestToString(unittest.TestCase):
+    def setUp(self):
+        self.char_list = ["a.nc", "b.nc", "c.nc"]
+        self.num_list = [1, 3, 7]
+        self.char = "foo@bar.com"
+        self.num = 10
+        self.mixed_list = ["foo.nc", -1, True]
+        self.mixed_str_list = map(nml.quote, ["foo.nc", "-1", ".TRUE."])
+
+    def test_should_format_mixed_list(self):
+        data = nml.tostring(self.mixed_list)
+        result = "'foo.nc', -1, .TRUE."
+        self.assertEqual(data, result)
+
+    def test_should_format_numeric_list(self):
+        data = nml.tostring(self.num_list)
+        result = "1 3 7"
+        self.assertEqual(data, result)
+
+    def test_should_format_character_list(self):
+        data = nml.tostring(self.char_list)
+        result = "'a.nc', 'b.nc', 'c.nc'"
+        self.assertEqual(data, result)
+
+    def test_should_format_strings(self):
+        data = nml.tostring(self.char)
+        result = "'%s'" % (self.char,)
+        self.assertEqual(data, result)
+
+    def test_should_format_numbers(self):
+        data = nml.tostring(self.num)
+        result = str(self.num)
+        self.assertEqual(data, result)
+
+    def test_should_not_format_numeric_string(self):
+        input = "3.14159"
+        self.assertEqual(nml.tostring(input), input)
+
+    def test_should_format_logicals(self):
+        data = nml.tostring(True)
+        result = ".TRUE."
+        self.assertEqual(data.upper(), result)
+
+    def test_should_not_format_string_of_list_data(self):
+        for input in ["1 2 3", "1, 2, 3", ".TRUE. .FALSE."]:
+            case = nml.tostring(input)
+            self.assertEqual(case, input)
+
+    def test_should_treat_mixed_numeric_character_data_as_character(self):
+        case = nml.tostring(self.mixed_str_list)
+        result = "'foo.nc', '-1', '.TRUE.'"
+        self.assertEqual(case, result)
+
+class TestUpdateNamelist(unittest.TestCase):
+    def setUp(self):
+        self.empty = """
+&namone
+/
+"""
+        self.single = """
+&namone
+   x = 'y'
+/
+"""
+        self.single_update = """
+&namone
+   x = 'z'
+/
+"""
+
+    def test_should_append_new_variable_to_namelist(self):
+        trial = nml.update("namone", self.empty, {"x": "'y'"})
+        self.assertEqual(trial, self.single)
+
+    def test_should_update_existing_variables(self):
+        trial = nml.update("namone", self.single, {"x": "'z'"})
+        self.assertEqual(trial, self.single_update)
+
+if __name__ == '__main__':
+    unittest.main()
+
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/setup.py
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/setup.py	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/OOO/setup.py	(revision 4229)
@@ -0,0 +1,9 @@
+from distutils.core import setup
+setup(name='Offline observation operator',
+      version='0.1',
+      description='NEMO Offline observation operator',
+      author='Andrew Ryan',
+      author_email='andrew.ryan@metoffice.gov.uk',
+      packages=['ooo',],
+      scripts=['bin/ooo'],
+      )
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/c4comb.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/c4comb.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/c4comb.F90	(revision 4229)
@@ -0,0 +1,702 @@
+PROGRAM c4comb
+   !!---------------------------------------------------------------------
+   !!
+   !!                     ** PROGRAM c4comb **
+   !!
+   !!  ** Purpose : Combine MPI decomposed class4 files into one file
+   !!
+   !!  ** Method  : Use of utilities from obs_utils, ooo_utils.
+   !!
+   !!  ** Action  : 
+   !!
+   !!   Usage:
+   !!     c4comb.exe outputfile inputfile1 inputfile2 ...
+   !!
+   !!   History :
+   !!----------------------------------------------------------------------
+   USE netcdf
+   USE obs_const
+   USE obs_utils
+   USE ooo_utils, ONLY: date_format, obfilldbl
+   USE toolspar_kind
+   IMPLICIT NONE
+   !! Command line setup
+#ifndef NOIARGCPROTO
+   INTEGER,EXTERNAL :: iargc
+#endif
+   INTEGER :: nargs,    & !: number of command line arguments
+            & ia,       & !: argument loop index
+            & ninfiles    !: number of input files
+   !! Routine arguments
+   CHARACTER(len=256) :: cdoutfile
+   CHARACTER(len=256),ALLOCATABLE :: cdinfile(:)
+   !! Routine variables
+   CHARACTER(len=80) :: cpname
+   INTEGER,PARAMETER :: nstr=8, n128=128
+   INTEGER           ::    ncid,   & !: netcdf file id
+                        &  dimid,  & !: netcdf dimension id
+                        &  dpdim,  & !: netcdf dimension ids
+                        &  fcdim,  &
+                        &  vrdim,  &
+                        &  obdim,  &
+                        &  stdim,  &
+                        &  sxdim,  &
+                        &  fdvid,  & !: netcdf variable ids
+                        &  lonid,  &
+                        &  latid,  &
+                        &  depid,  &
+                        &  varid,  &
+                        &  unitid, &
+                        &  obvid,  &
+                        &  fcvid,  &
+                        &  prvid,  &
+                        &  clvid,  &
+                        &  dm2id,  &
+                        &  dm1id,  &
+                        &  mdtid,  &
+                        &  altid,  &
+                        &  qcvid,  &
+                        &  jdvid,  &
+                        &  mjdid,  &
+                        &  typid,  &
+                        &  idvid,  &
+                        &  ndeps,  & !: number depths
+                        &  nfcst,  & !: number forecast
+                        &  nvars,  & !: number variables
+                        &  nobs,   & !: number obs
+                        &  sdeps,  &
+                        &  sobs,   &
+                        &  l_dex,  &
+                        &  u_dex
+
+   INTEGER                   :: iob, idep, istat
+   INTEGER, DIMENSION(2)     :: dim2a, dim2b, dim2c, dim2d
+   INTEGER, DIMENSION(3)     :: dim3a
+   INTEGER, DIMENSION(4)     :: dim4a
+   INTEGER,  ALLOCATABLE, DIMENSION(:)           :: fcday
+   REAL(wp), ALLOCATABLE, DIMENSION(:)           :: modjd
+   !: Global Attributes
+   CHARACTER(len=40)                             :: nam_str, &
+                                                 & version,  &
+                                                 & contact,  &
+                                                 & sys_str,  &
+                                                 & cfg_str,  &
+                                                 & ins_str,  &
+                                                 & val_str,  &
+                                                 & dat_str,  &
+                                                 & obs_str
+   !: Variable Attributes
+   CHARACTER(len=100)                            :: lon_units, &
+                                                 &  lat_units, &
+                                                 &  dep_units, &
+                                                 &  jul_units, &
+                                                 &  mjd_units, &
+                                                 &  fcd_units, &
+                                                 &  lead_comment, &
+                                                 &  fcst_comment, &
+                                                 &  per_comment,  &
+                                                 &  cli_comment,  &
+                                                 &  dm2_comment,  &
+                                                 &  dm1_comment
+   CHARACTER(len=128)                            :: qc_comment,   &
+                                                 &  qc_flag_meaning
+   INTEGER, DIMENSION(2)                         :: qc_flag_value
+
+   !: Global Arrays
+   REAL(wp), ALLOCATABLE, DIMENSION(:)           :: g_lam, &
+                                                 &  g_phi, & 
+                                                 &  gjuld 
+   CHARACTER(len=n128),ALLOCATABLE,DIMENSION(:)  :: gtype
+   CHARACTER(len=nstr),ALLOCATABLE,DIMENSION(:)  ::        &
+                                                 &  g_id,  & 
+                                                 &  gvnam, & 
+                                                 &  gunit
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:)         :: g_dep
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)       :: g3dob, &
+                                                 &  g3dcl, &
+                                                 &  g3mdt, &
+                                                 &  g3alt, &
+                                                 &  g3dm2, &
+                                                 &  g3dm1
+   INTEGER(ik),  ALLOCATABLE, DIMENSION(:,:,:)   :: g3dqc
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:)     :: g3dmc, &
+                                                 &  g3dpr
+   !: Small Arrays  
+   REAL(wp), ALLOCATABLE, DIMENSION(:)       ::     s_lam, &
+                                                 &  s_phi, & 
+                                                 &  sjuld
+
+   CHARACTER(len=n128),ALLOCATABLE,DIMENSION(:) ::  stype
+   CHARACTER(len=nstr),ALLOCATABLE,DIMENSION(:) ::        &
+                                                 &  s_id 
+
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:)        :: s_dep
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)      :: s3dob, &
+                                                &  s3dcl, &
+                                                &  s3mdt, &
+                                                &  s3alt, &
+                                                &  s3dm2, &
+                                                &  s3dm1
+   INTEGER(ik),  ALLOCATABLE, DIMENSION(:,:,:)  :: s3dqc
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:)    :: s3dmc, &
+                                                &  s3dpr
+
+   !: File creation logical
+   LOGICAL                                     :: ln_cre
+
+   !: Optional variable logicals
+   LOGICAL                                     :: ln_init, &
+                                                & ln_mdt,  &
+                                                & ln_altbias, &
+                                                & ln_best
+   !! Command name
+   cpname='c4comb.exe'
+
+   !! Process command line
+   nargs = IARGC()
+   IF (nargs /= 2) THEN
+      WRITE(*, *) "Usage: c4comb.exe outputfile inputfile1 inputfile2 ..."
+      CALL abort()
+   END IF
+   CALL GETARG(1, cdoutfile)
+
+   !! Process input files
+   !! Set output file creation to off
+   ln_cre = .false.
+
+   !! Turn optional variables off
+   ln_init = .false.
+   ln_best = .false.
+   ln_altbias = .false.
+   ln_mdt = .false.
+
+   !! Compute size of output file
+   nobs = 0
+   ndeps= 0
+   ALLOCATE( cdinfile( nargs - 1 ) )
+   ninfiles = nargs - 1
+   DO ia = 1, ninfiles
+      CALL GETARG(ia+1, cdinfile(ia))
+      WRITE(*,*) "Opening : ", TRIM(cdinfile(ia))
+      !! Open Netcdf file
+      istat = nf90_open(TRIM(cdinfile(ia)),nf90_nowrite,ncid)
+      IF (istat == nf90_noerr) THEN
+         !! Turn output file creation on
+         ln_cre = .true.
+         !! Get Dimensions
+         CALL chkerr( nf90_inq_dimid(ncid, 'numobs',  dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=sobs  ),  cpname, __LINE__ )
+         CALL chkerr( nf90_inq_dimid(ncid, 'numdeps', dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=sdeps ),  cpname, __LINE__ )
+         CALL chkerr( nf90_inq_dimid(ncid, 'numfcsts',dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=nfcst ),  cpname, __LINE__ )
+         CALL chkerr( nf90_inq_dimid(ncid, 'numvars', dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=nvars ),  cpname, __LINE__ )
+         !! Close Netcdf file
+         CALL chkerr( nf90_close(ncid), cpname, __LINE__ )
+         !! Report on file contents
+         WRITE(*,'(2A)')'File = ', TRIM(cdinfile(ia))
+         WRITE(*,'(A,I9,A)')'has', sobs, ' observations'
+         !! Increment size
+         nobs  = nobs + sobs       !: Accumulate number of profiles
+         ndeps = MAX(ndeps, sdeps) !: Define maximum number of levels needed
+      END IF ! istat
+   END DO
+
+   !! Allocate global arrays
+   ALLOCATE( g_phi(nobs),                      &
+          &  g_lam(nobs),                      &
+          &  g_dep(ndeps, nobs),               &
+          &  g3dob(ndeps,        nvars, nobs), &
+          &  g3dmc(ndeps, nfcst, nvars, nobs), &
+          &  g3dpr(ndeps, nfcst, nvars, nobs), &
+          &  g3dcl(ndeps,        nvars, nobs), &
+          &  g3dm2(ndeps,        nvars, nobs), &
+          &  g3dm1(ndeps,        nvars, nobs), &
+          &  g3mdt(ndeps,        nvars, nobs), &
+          &  g3alt(ndeps,        nvars, nobs), &
+          &  g3dqc(ndeps,        nvars, nobs), &
+          &  gjuld(nobs),                      &
+          &  gtype(nobs),                      &
+          &  g_id(nobs),                       &
+          &  gvnam(nvars),                     &
+          &  gunit(nvars) )
+   ALLOCATE(fcday(nfcst), modjd(nfcst))
+
+   !! Fill with missing data value
+   g_dep(:,:)     = 99999.
+   g3dmc(:,:,:,:) = 99999.
+   g3dpr(:,:,:,:) = 99999.
+   g3dob(:,:,:)   = 99999.
+   g3dcl(:,:,:)   = 99999.
+   g3dm2(:,:,:)   = 99999.
+   g3dm1(:,:,:)   = 99999.
+   g3mdt(:,:,:)   = 99999.
+   g3alt(:,:,:)   = 99999.
+   g3dqc(:,:,:)   = NF90_FILL_SHORT
+
+   !! Read in each file
+   !  initialise global matrix indices
+   l_dex = 0
+   u_dex = 0
+
+   !! initialise Global attribute strings
+   nam_str = ''
+   version = ''
+   contact = ''
+   sys_str = ''
+   cfg_str = ''
+   ins_str = ''
+   val_str = ''
+   dat_str = ''
+   obs_str = ''
+
+   !! initialise Variable attribute strings
+   fcd_units = ''
+   lon_units = ''
+   lat_units = ''
+   dep_units = ''
+   jul_units = ''
+   mjd_units = ''
+   lead_comment = ''
+   fcst_comment = ''
+   per_comment  = ''
+   cli_comment  = ''
+   dm2_comment  = ''
+   dm1_comment  = ''
+   qc_comment  = ''
+   qc_flag_meaning  = ''
+
+   DO ia = 1, ninfiles
+      WRITE(*,*) "Opening : ", TRIM(cdinfile(ia))
+      !! Open Netcdf file
+      istat = nf90_open(TRIM(cdinfile(ia)),nf90_nowrite,ncid)
+      IF (istat == nf90_noerr) THEN
+         !! Get Global Attributes
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'title',         nam_str),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'version',       version),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'contact',       contact),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'obs_type',      obs_str),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'system',        sys_str),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'configuration', cfg_str),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'institution',   ins_str),cpname, __LINE__)
+         CALL chkerr( nf90_get_att(ncid, nf90_global,'validity_time', val_str),cpname, __LINE__)
+         !! Get Dimensions of single file
+         CALL chkerr( nf90_inq_dimid(ncid, 'numdeps', dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=sdeps ),  cpname, __LINE__ )
+         CALL chkerr( nf90_inq_dimid(ncid, 'numfcsts',dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=nfcst ),  cpname, __LINE__ )
+         CALL chkerr( nf90_inq_dimid(ncid, 'numvars', dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=nvars ),  cpname, __LINE__ )
+         CALL chkerr( nf90_inq_dimid(ncid, 'numobs',  dimid),              cpname, __LINE__ )
+         CALL chkerr( nf90_inquire_dimension(ncid,    dimid, len=sobs  ),  cpname, __LINE__ )
+         !! Check for Optional variables in first file
+         IF (ia == 1) THEN
+            !! Best estimate
+            istat = nf90_inq_varid(ncid,'best_estimate',dm2id)
+            IF (istat == nf90_noerr) THEN
+               ln_best = .TRUE.
+            ENDIF 
+            !! nrt_analysis
+            istat = nf90_inq_varid(ncid,'nrt_analysis',dm1id)
+            IF (istat == nf90_noerr) THEN
+               ln_init = .TRUE.
+            ENDIF 
+            !! Mean Dynamic Topography
+            istat = nf90_inq_varid(ncid,'mdt_reference',mdtid)
+            IF (istat == nf90_noerr) THEN
+               ln_mdt = .TRUE.
+            ENDIF 
+            !! Altimeter bias
+            istat = nf90_inq_varid(ncid,'altimeter_bias',altid)
+            IF (istat == nf90_noerr) THEN
+               ln_altbias = .TRUE.
+            ENDIF 
+         END IF
+         WRITE(*,*) TRIM(cdinfile(ia)), " contains ", sobs, " observations"
+         WRITE(*,*) TRIM(cdinfile(ia)), " contains ", sdeps, " depths"
+         WRITE(*,*) TRIM(cdinfile(ia)), " contains ", nfcst, " forecasts"
+         WRITE(*,*) TRIM(cdinfile(ia)), " contains ", nvars, " vars"
+         !! Read Variables
+         IF (sobs /= 0) THEN
+            !! Get Variable ids
+            CALL chkerr(nf90_inq_varid(ncid,'leadtime', fdvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'longitude',   lonid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'latitude',    latid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'depth',       depid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'varname',     varid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'unitname',   unitid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'observation', obvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'forecast',    fcvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'persistence', prvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'climatology', clvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'qc',          qcvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'juld',        jdvid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'modeljuld',   mjdid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'type',        typid) ,cpname, __LINE__ )
+            CALL chkerr(nf90_inq_varid(ncid,'id',          idvid) ,cpname, __LINE__ )
+            !! Get variable attributes
+            CALL chkerr(nf90_get_att(ncid, fdvid, 'units', fcd_units) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, lonid, 'units', lon_units) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, latid, 'units', lat_units) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, depid, 'units', dep_units) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, jdvid, 'units', jul_units) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, mjdid, 'units', mjd_units) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, fcvid, 'comment', fcst_comment) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, prvid, 'comment', per_comment)  ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, clvid, 'comment', cli_comment)  ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, fdvid, 'comment', lead_comment) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, qcvid, 'comment', qc_comment) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, qcvid, 'flag_value', qc_flag_value) ,cpname, __LINE__ )
+            CALL chkerr(nf90_get_att(ncid, qcvid, 'flag_meaning', qc_flag_meaning) ,cpname, __LINE__ )
+            !! Optional variables
+            IF (ln_best) THEN
+               CALL chkerr(nf90_inq_varid(ncid,'best_estimate',dm2id) ,cpname, __LINE__ )
+               CALL chkerr(nf90_get_att(ncid, dm2id, 'comment', dm2_comment)  ,cpname, __LINE__ )
+            ENDIF
+            IF (ln_init) THEN
+               CALL chkerr(nf90_inq_varid(ncid,'nrt_analysis', dm1id) ,cpname, __LINE__ )
+               CALL chkerr(nf90_get_att(ncid, dm1id, 'comment', dm1_comment)  ,cpname, __LINE__ )
+            ENDIF
+            IF (ln_mdt) THEN
+               CALL chkerr(nf90_inq_varid(ncid,'mdt_reference', mdtid) ,cpname, __LINE__ )
+            ENDIF
+            IF (ln_altbias) THEN
+               CALL chkerr(nf90_inq_varid(ncid,'altimeter_bias', altid) ,cpname, __LINE__ )
+            ENDIF
+
+            !! Allocate small arrays
+            ALLOCATE( s_lam(sobs), s_phi(sobs),  s_dep(sdeps, sobs),               &
+                   &  s3dob(sdeps,        nvars, sobs), & !: observations 
+                   &  s3dmc(sdeps, nfcst, nvars, sobs), & !: model data
+                   &  s3dpr(sdeps, nfcst, nvars, sobs), & !: persistence
+                   &  s3dcl(sdeps,        nvars, sobs), & !: climatology
+                   &  s3dm2(sdeps,        nvars, sobs), & !: best estimate
+                   &  s3dm1(sdeps,        nvars, sobs), & !: nrt_analysis
+                   &  s3mdt(sdeps,        nvars, sobs), & !: mdt
+                   &  s3alt(sdeps,        nvars, sobs), & !: altbias
+                   &  s3dqc(sdeps,        nvars, sobs), & !: QC
+                   &  sjuld(sobs), stype( sobs),  &
+                   &  s_id(sobs) )
+            !! Fill with missing data value
+            s3dmc(:,:,:,:) = 99999.
+            s3dpr(:,:,:,:) = 99999.
+            s3dob(:,:,:)   = 99999.
+            s3dcl(:,:,:)   = 99999.
+            s3dm2(:,:,:)   = 99999.
+            s3dm1(:,:,:)   = 99999.
+            s3mdt(:,:,:)   = 99999.
+            s3alt(:,:,:)   = 99999.
+            s3dqc(:,:,:)   = NF90_FILL_SHORT
+
+            !! Read variables into small arrays
+            CALL chkerr( nf90_get_var(ncid, fdvid, fcday), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, lonid, s_lam), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, latid, s_phi), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, depid, s_dep), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, obvid, s3dob), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, fcvid, s3dmc), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, prvid, s3dpr), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, clvid, s3dcl), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, qcvid, s3dqc), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, jdvid, sjuld), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, mjdid, modjd), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, typid, stype), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, idvid, s_id),  cpname, __LINE__ )       
+            !! Read unitname and varname into global arrays
+            CALL chkerr( nf90_get_var(ncid, varid, gvnam), cpname, __LINE__ )       
+            CALL chkerr( nf90_get_var(ncid, unitid,gunit), cpname, __LINE__ )       
+            !! Optional variables read
+            IF (ln_best) THEN
+               CALL chkerr( nf90_get_var(ncid, dm2id, s3dm2), cpname, __LINE__ )       
+            ENDIF
+            IF (ln_init) THEN
+               CALL chkerr( nf90_get_var(ncid, dm1id, s3dm1), cpname, __LINE__ )       
+            ENDIF
+            IF (ln_mdt) THEN
+               CALL chkerr( nf90_get_var(ncid, mdtid, s3mdt), cpname, __LINE__ )       
+            ENDIF
+            IF (ln_altbias) THEN
+               CALL chkerr( nf90_get_var(ncid, altid, s3alt), cpname, __LINE__ )       
+            ENDIF
+
+            !! Fill Global arrays
+            !  increment numobs indices
+            l_dex = u_dex + 1
+            u_dex = l_dex + sobs -1
+
+            g_lam(l_dex:u_dex)                          = s_lam(:)
+            g_phi(l_dex:u_dex)                          = s_phi(:)
+            g_dep(1:sdeps,  l_dex:u_dex)                = s_dep(1:sdeps,:)
+            g3dob(1:sdeps,1:nvars,l_dex:u_dex)          = s3dob(1:sdeps,1:nvars,:)
+            g3dmc(1:sdeps,1:nfcst,1:nvars,l_dex:u_dex)  = s3dmc(1:sdeps,1:nfcst,1:nvars,:)
+            g3dpr(1:sdeps,1:nfcst,1:nvars,l_dex:u_dex)  = s3dpr(1:sdeps,1:nfcst,1:nvars,:)
+            g3dcl(1:sdeps,1:nvars,l_dex:u_dex)          = s3dcl(1:sdeps,1:nvars,:)
+            g3dm2(1:sdeps,1:nvars,l_dex:u_dex)          = s3dm2(1:sdeps,1:nvars,:)
+            g3dm1(1:sdeps,1:nvars,l_dex:u_dex)          = s3dm1(1:sdeps,1:nvars,:)
+            g3mdt(1:sdeps,1:nvars,l_dex:u_dex)          = s3mdt(1:sdeps,1:nvars,:)
+            g3alt(1:sdeps,1:nvars,l_dex:u_dex)          = s3alt(1:sdeps,1:nvars,:)
+            g3dqc(1:sdeps,1:nvars,l_dex:u_dex)          = s3dqc(1:sdeps,1:nvars,:)
+            gjuld(l_dex:u_dex)                          = sjuld(:)
+            gtype(l_dex:u_dex)                          = stype(:)
+            g_id(l_dex:u_dex)                           = s_id(:)
+
+            !! Deallocate small array
+            DEALLOCATE( s_lam, s_phi, s_dep, s3dob, s3dmc, s3dpr, s3dcl, s3dqc, s3dm2, s3dm1, s3mdt, s3alt, sjuld, stype, s_id)
+         ENDIF ! sobs    
+         !! Close Netcdf file
+         CALL chkerr( nf90_close(ncid), cpname, __LINE__ )
+      END IF ! istat
+   END DO
+
+   !! Create Output file
+   IF (ln_cre) THEN
+      WRITE(*,*) 'Create the output file, ',trim(cdoutfile)
+      CALL chkerr( nf90_create(trim(cdoutfile),nf90_clobber,ncid),      cpname, __LINE__ )
+      !! Put Global Attributes
+      CALL date_format(dat_str) 
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'title',          trim(nam_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'version',        trim(version)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'creation_date',  trim(dat_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'contact',        trim(contact)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'obs_type',       trim(obs_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'system',         trim(sys_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'configuration',  trim(cfg_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'institution',    trim(ins_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'validity_time',  trim(val_str)),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'best_estimate_description', &
+                              &       'analysis produced 2 days behind real time'),cpname, __LINE__)
+      CALL chkerr( nf90_put_att(ncid, nf90_global,'time_interp', 'daily average fields'),cpname, __LINE__)
+      WRITE(*,*) 'Succesfully put global attributes '
+
+      !! Define Dimensions
+      CALL chkerr( nf90_def_dim(ncid, 'numdeps',          ndeps, dpdim) ,cpname, __LINE__ )
+      CALL chkerr( nf90_def_dim(ncid, 'numfcsts',         nfcst, fcdim) ,cpname, __LINE__ )
+      CALL chkerr( nf90_def_dim(ncid, 'numvars',          nvars, vrdim) ,cpname, __LINE__ )
+      CALL chkerr( nf90_def_dim(ncid, 'numobs',           nobs,  obdim) ,cpname, __LINE__ )
+      CALL chkerr( nf90_def_dim(ncid, 'string_length8',   nstr,  stdim) ,cpname, __LINE__ )
+      CALL chkerr( nf90_def_dim(ncid, 'string_length128', n128,  sxdim) ,cpname, __LINE__ )
+      WRITE(*,*) 'Succesfully defined dimensions'
+
+      !! Define possible dimension permutations
+      ! 2d
+      dim2a(:) = (/ dpdim, obdim /) !: (/ ndeps, nobs  /) 
+      dim2b(:) = (/ stdim, obdim /) !: (/ nstr,  nobs  /)
+      dim2c(:) = (/ stdim, vrdim /) !: (/ nstr,  nvars /)
+      dim2d(:) = (/ sxdim, obdim /) !: (/ nstr,  nobs  /)
+      ! 3d
+      dim3a(:) = (/ dpdim, vrdim, obdim/) !: (/ ndeps, nvars, nobs /)
+      ! 4d
+      dim4a(:) = (/ dpdim, fcdim, vrdim, obdim /) !: (/ ndeps, nfcst, nvars, nobs /)
+
+
+      !! Create the variables
+      !  Forecast day
+      CALL chkerr( nf90_def_var(ncid, 'leadtime',  nf90_double, fcdim, fdvid)          ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, fdvid, 'long_name', 'Model forecast day offset') ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, fdvid, 'units',     trim(fcd_units))             ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, fdvid, 'comment',   trim(lead_comment))          ,cpname, __LINE__ )
+      WRITE(*,*) 'leadtime created'
+      !  longitude
+      CALL chkerr( nf90_def_var(ncid, 'longitude',    nf90_float, obdim, lonid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, lonid, 'long_name', 'Longitudes')                ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, lonid, 'units',     trim(lon_units))             ,cpname, __LINE__ )
+      WRITE(*,*) 'lon created'
+      !  latitude
+      CALL chkerr( nf90_def_var(ncid, 'latitude',     nf90_float, obdim, latid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, latid, 'long_name', 'Latitudes')                 ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, latid, 'units',     trim(lat_units))             ,cpname, __LINE__ )
+      WRITE(*,*) 'lat created'
+      !  depth
+      CALL chkerr( nf90_def_var(ncid, 'depth',        nf90_float, dim2a, depid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, depid, 'long_name', 'Depths')                    ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, depid, 'units',     trim(dep_units))             ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, depid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+      WRITE(*,*) 'dep created'
+      !  varname
+      CALL chkerr( nf90_def_var(ncid, 'varname',      nf90_char,  dim2c, varid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, varid, 'long_name', 'Variable name')             ,cpname, __LINE__ )
+      WRITE(*,*) 'varname created'
+      !  unitname
+      CALL chkerr( nf90_def_var(ncid, 'unitname',     nf90_char,  dim2c, unitid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid,  unitid, 'long_name', 'Unit name')              ,cpname, __LINE__ )
+      WRITE(*,*) 'unitname created'
+      !  obs
+      CALL chkerr( nf90_def_var(ncid, 'observation', nf90_float,  dim3a,  obvid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, obvid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid,  obvid, 'long_name', 'Observation value')         ,cpname, __LINE__ )
+      WRITE(*,*) 'obs created'
+      !  forecast
+      CALL chkerr( nf90_def_var(ncid, 'forecast',    nf90_float,  dim4a,  fcvid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, fcvid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, fcvid, 'long_name', 'Model forecast counterpart of obs. value')   ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, fcvid, 'comment',   trim(fcst_comment))           ,cpname, __LINE__ )
+      WRITE(*,*) 'forecast created'
+      !  persistence
+      CALL chkerr( nf90_def_var(ncid, 'persistence', nf90_float,  dim4a,  prvid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, prvid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, prvid, 'long_name', 'Model persistence counterpart of obs. value'),cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, prvid, 'comment',   trim(per_comment))            ,cpname, __LINE__ )
+      WRITE(*,*) 'persistence created'
+      !  clim
+      CALL chkerr( nf90_def_var(ncid, 'climatology', nf90_float,  dim3a, clvid)        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, clvid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, clvid, 'long_name', 'Climatological value')       ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, clvid, 'comment',   trim(cli_comment))            ,cpname, __LINE__ )
+      WRITE(*,*) 'clim created'
+      IF (ln_best) THEN
+         !  daym2
+         CALL chkerr( nf90_def_var(ncid, 'best_estimate', nf90_float,  dim3a, dm2id)    ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, dm2id, '_FillValue',obfillflt)                 ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, dm2id, 'long_name', 'Best estimate')           ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, dm2id, 'comment',   trim(dm2_comment))         ,cpname, __LINE__ )
+         WRITE(*,*) 'daym2 created'
+      ENDIF
+      IF (ln_init) THEN
+         !  daym1
+         CALL chkerr( nf90_def_var(ncid, 'nrt_analysis', nf90_float,  dim3a, dm1id)        ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, dm1id, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, dm1id, 'long_name', 'Near real time analysis')    ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, dm1id, 'comment',   trim(dm1_comment))            ,cpname, __LINE__ )
+         WRITE(*,*) 'daym1 created'
+      ENDIF
+      IF (ln_mdt) THEN
+         !  mdt
+         CALL chkerr( nf90_def_var(ncid, 'mdt_reference', nf90_float,  dim3a, mdtid)      ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, mdtid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, mdtid, 'long_name', 'Mean dynamic topography')    ,cpname, __LINE__ )
+         WRITE(*,*) 'mdt created'
+      ENDIF
+      IF (ln_altbias) THEN
+         !  altbias
+         CALL chkerr( nf90_def_var(ncid, 'altimeter_bias', nf90_float,  dim3a, altid)     ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, altid, '_FillValue',obfillflt)                    ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_att(ncid, altid, 'long_name', 'Altimeter bias')             ,cpname, __LINE__ )
+         WRITE(*,*) 'altbias created'
+      ENDIF
+      !  qc
+      CALL chkerr( nf90_def_var(ncid, 'qc',          nf90_short,  dim3a, qcvid)         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, qcvid, '_FillValue', NF90_FILL_SHORT)             ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, qcvid, 'long_name', 'Quality flags')              ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, qcvid, 'flag_value', qc_flag_value)               ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, qcvid, 'flag_meaning', qc_flag_meaning)           ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, qcvid, 'comment', qc_comment)                     ,cpname, __LINE__ )
+      WRITE(*,*) 'qc created'
+      !  juld
+      CALL chkerr( nf90_def_var(ncid, 'juld',       nf90_double,  obdim, jdvid)         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, jdvid, '_FillValue',99999.)                       ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, jdvid, 'long_name', 'Observation time in Julian days'),cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, jdvid, 'units',     trim(jul_units))              ,cpname, __LINE__ )
+      WRITE(*,*) 'juld created'
+      !  modeljuld 
+      CALL chkerr( nf90_def_var(ncid, 'modeljuld',  nf90_double,  fcdim, mjdid)         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, mjdid, 'long_name', 'Model field date in Julian days'),cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, mjdid, 'units',     trim(mjd_units))              ,cpname, __LINE__ )
+      WRITE(*,*) 'modeljuld created'
+      !  type
+      CALL chkerr( nf90_def_var(ncid, 'type',     nf90_char,      dim2d, typid)         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, typid, 'long_name', 'Observation type')           ,cpname, __LINE__ )
+      WRITE(*,*) 'type created'
+      !  id
+      CALL chkerr( nf90_def_var(ncid, 'id',       nf90_char,      dim2b, idvid)         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_att(ncid, idvid, 'long_name', 'Observation id')             ,cpname, __LINE__ )
+      WRITE(*,*) 'id created'
+      ! Close Netcdf file 
+      CALL chkerr( nf90_close(ncid) ,cpname, __LINE__ )  
+      !! Fill in the variables
+      CALL chkerr( nf90_open(trim(cdoutfile),nf90_write,ncid),                   cpname, __LINE__ )
+      WRITE(*,*) 'Create the variables ',trim(cdoutfile)
+      !  Forecast day
+      CALL chkerr( nf90_inq_varid(ncid, 'leadtime', fdvid)                ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, fdvid, fcday) ,cpname, __LINE__ )
+      WRITE(*,*) 'forecast day put'
+      !  longitude
+      CALL chkerr( nf90_inq_varid(ncid, 'longitude', lonid)                  ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, lonid, g_lam) ,cpname, __LINE__ )
+      WRITE(*,*) 'lon put'
+      !  latitude
+      CALL chkerr( nf90_inq_varid(ncid, 'latitude', latid)                   ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, latid, g_phi) ,cpname, __LINE__ )
+      WRITE(*,*) 'lat put'
+      !  depth
+      CALL chkerr( nf90_inq_varid(ncid, 'depth',depid)                       ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, depid, g_dep) ,cpname, __LINE__ )
+      WRITE(*,*) 'dep put'
+      ! varname
+      CALL chkerr( nf90_inq_varid(ncid, 'varname', varid)                    ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, varid, gvnam,(/1,1/), (/nstr,nvars/) ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'var put'
+      ! unitname
+      CALL chkerr( nf90_inq_varid(ncid, 'unitname',unitid)                   ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, unitid, gunit,(/1,1/),(/nstr,nvars/) ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'unitnam put'
+      ! obs
+      CALL chkerr( nf90_inq_varid(ncid, 'observation', obvid)                ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, obvid,g3dob ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'obs put'
+      ! clim
+      CALL chkerr( nf90_inq_varid(ncid, 'climatology', clvid)                ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, clvid,g3dcl ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'cli put'
+      IF (ln_best) THEN
+         ! daym2
+         CALL chkerr( nf90_inq_varid(ncid, 'best_estimate',dm2id)            ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_var(ncid, dm2id,g3dm2 ) ,cpname, __LINE__ )   
+         WRITE(*,*) 'daym2 put'
+      ENDIF
+      IF (ln_init) THEN 
+         ! daym1
+         CALL chkerr( nf90_inq_varid(ncid, 'nrt_analysis',dm1id)              ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_var(ncid, dm1id,g3dm1 ) ,cpname, __LINE__ )   
+         WRITE(*,*) 'daym1 put'
+      ENDIF
+      IF (ln_mdt) THEN 
+         ! mdt
+         CALL chkerr( nf90_inq_varid(ncid, 'mdt_reference', mdtid)              ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_var(ncid, mdtid, g3mdt ) ,cpname, __LINE__ )   
+         WRITE(*,*) 'mdt put'
+      ENDIF
+      IF (ln_altbias) THEN 
+         ! altbias
+         CALL chkerr( nf90_inq_varid(ncid, 'altimeter_bias', altid)             ,cpname, __LINE__ )
+         CALL chkerr( nf90_put_var(ncid, altid, g3alt ) ,cpname, __LINE__ )   
+         WRITE(*,*) 'altbias put'
+      ENDIF
+      ! persistence
+      CALL chkerr( nf90_inq_varid(ncid, 'persistence',prvid)                                 ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, prvid, g3dpr, (/1,1,1,1/) ,(/ ndeps,nfcst,nvars,nobs/) ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'per put'
+      ! forecast
+      CALL chkerr( nf90_inq_varid(ncid, 'forecast',fcvid)                                      ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, fcvid, g3dmc, (/1,1,1,1/), (/ ndeps,nfcst,nvars,nobs/) ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'fcst put'
+      ! qc
+      CALL chkerr( nf90_inq_varid(ncid, 'qc', qcvid)                         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, qcvid,g3dqc ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'qc put'
+      ! juld
+      CALL chkerr( nf90_inq_varid(ncid, 'juld',jdvid)                        ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, jdvid, gjuld) ,cpname, __LINE__ )   
+      WRITE(*,*) 'juld put'
+      ! modeljuld
+      CALL chkerr( nf90_inq_varid(ncid, 'modeljuld', mjdid)                  ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, mjdid, modjd,(/1/),(/nfcst/))          ,cpname, __LINE__ )   
+      WRITE(*,*) 'modjuld put'
+      ! type
+      CALL chkerr( nf90_inq_varid(ncid, 'type', typid)                       ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, typid, gtype,(/1,1/) , (/n128,nobs/) ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'type put'
+      ! id
+      CALL chkerr( nf90_inq_varid(ncid, 'id', idvid)                         ,cpname, __LINE__ )
+      CALL chkerr( nf90_put_var(ncid, idvid, g_id,(/1,1/)  , (/nstr,nobs/) ) ,cpname, __LINE__ )   
+      WRITE(*,*) 'id put'
+      ! Close netcdf file
+      CALL chkerr( nf90_close(ncid),                                          cpname, __LINE__ )
+   END IF ! ln_cre
+   !! Deallocate Global arrays
+   DEALLOCATE( g_lam, g_phi, g_dep, g3dob, g3dmc, g3dpr, g3dcl, g3dm2, g3dm1, g3mdt, g3alt, g3dqc, gjuld, gtype, g_id, gvnam, gunit)
+   DEALLOCATE( fcday, modjd )
+
+   !! Deallocate input argument list
+   DEALLOCATE(cdinfile)
+END PROGRAM c4comb
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/obs_const.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/obs_const.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/obs_const.F90	(revision 4229)
@@ -0,0 +1,1 @@
+link ../../../NEMO/OPA_SRC/OBS/obs_const.F90
Index: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/ooo_utils.F90
===================================================================
--- branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/ooo_utils.F90	(revision 4229)
+++ branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/TOOLS/OBSTOOLS/src/ooo_utils.F90	(revision 4229)
@@ -0,0 +1,1 @@
+link ../../../NEMO/OOO_SRC/ooo_utils.F90
