Index: /utils/tools/DOMAINcfg/README.rst
===================================================================
--- /utils/tools/DOMAINcfg/README.rst	(revision 13389)
+++ /utils/tools/DOMAINcfg/README.rst	(revision 13390)
@@ -56,4 +56,5 @@
 * id trg is a integer used to defined group of closed sea and their river outflow (for example all the great lake and the St Laurent outflow).
 
+
 2) copy in DOMAINcfg directory same input files (of related configuration) required in v3.6_stable.
 
@@ -85,2 +86,35 @@
             field_def.xml
             iodef.xml
+
+
+==============================================================
+= How to keep track of the parameter used to generate the file
+==============================================================
+To do so, you need to fill the namelist_cfg with the input file name used in
+cn_fcoord, cn_topo, cn_fisfd and the associated variable name (see namelist ref for the extensive list).
+Once you generate the domain_cfg.nc file you can run the dom_doc.exe tools available.
+
+.. code-block:: console
+
+  $ ./dom_doc.exe -h
+    usage : dom_doc -n NAMELIST-file 
+                    -d DOMAIN_CFG-file
+       
+      PURPOSE :
+         Add information in the domain_cfg.nc file after its creation for
+         NEMO4. The additional information consists in a new netcdf variable
+         called namelist_cfg, holding the content of the used namelist_cfg.
+       
+      ARGUMENTS :
+         -n NAMELIST-file : name of the namelist_cfg. file required
+         -d DOMAIN_CFG-file : name of the domain_cfg file to document. file required
+       
+      OUTPUT : 
+          input DOMAIN_CFG-file is modified on output.
+
+This will add a variable namelist_cfg into the netcdf.
+
+To extract the namelist again, simply run the available script xtrac_namelist.bash
+::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+./xtrac_namelist.bash input_domain_cfg_file.nc output_namelist_cfg 
+::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Index: /utils/tools/DOMAINcfg/cpp_DOMAINcfg.fcm
===================================================================
--- /utils/tools/DOMAINcfg/cpp_DOMAINcfg.fcm	(revision 13389)
+++ /utils/tools/DOMAINcfg/cpp_DOMAINcfg.fcm	(revision 13390)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys
+ bld::tool::fppkeys key_mpp_mpi
Index: /utils/tools/DOMAINcfg/namelist_ref
===================================================================
--- /utils/tools/DOMAINcfg/namelist_ref	(revision 13389)
+++ /utils/tools/DOMAINcfg/namelist_ref	(revision 13390)
@@ -29,6 +29,11 @@
    nn_interp   =    1                          ! type of interpolation (nn_bathy =2)
    cn_domcfg   = ' '       ! Name of the domain_cfg input file
-   cn_topo     =  'bathymetry_ORCA12_V3.3.nc'  ! external topo file (nn_bathy =2)
-   cn_bath     =  'Bathymetry'                 ! topo name in file  (nn_bathy =2)
+   cn_fcoord   =  'coordinates.nc'             ! external coordinates file (jphgr_msh = 0)
+   cn_topo     =  'bathy_meter.nc           '  ! external topo file (nn_bathy =1/2)
+   cn_topolvl  =  'bathy_level.nc           '  ! external topo file (nn_bathy =1)
+   cn_fisfd    =  'isf_draft_meter.nc'         ! external isf draft (nn_bathy =1 and ln_isfcav = .true.)
+   cn_bath     =  'Bathymetry'                 ! topo name in file  (nn_bathy =1/2)
+   cn_bathlvl  =  'Bathy_level'                ! lvl name in file   (nn_bathy =1)
+   cn_visfd    =  'isf_draft'                  ! isf draft variable (nn_bathy =1 and ln_isfcav = .true.)
    cn_lon      =  'nav_lon'                    ! lon  name in file  (nn_bathy =2)
    cn_lat      =  'nav_lat'                    ! lat  name in file  (nn_bathy =2)
Index: /utils/tools/DOMAINcfg/src/dom_doc.f90
===================================================================
--- /utils/tools/DOMAINcfg/src/dom_doc.f90	(revision 13390)
+++ /utils/tools/DOMAINcfg/src/dom_doc.f90	(revision 13390)
@@ -0,0 +1,123 @@
+PROGRAM dom_doc
+   !!======================================================================
+   !!                     ***  PROGRAM  dom_doc  ***
+   !!=====================================================================
+   !!  ** Purpose : Add documentation to domain_cfg.nc files created for
+   !!               NEMO4.
+   !!
+   !!  ** Method  : Define a namelist_cfg variable and add source_bathy, 
+   !!               source_coord as global attributes.
+   !!
+   !! History :  1.0  : 05/2019  : J.M. Molines (MEOM/IGE/DRAKKAR)   : original DRAKKAR file
+   !!                   07/2020  : P.   Mathiot (CryoDyn/IGE/DRAKKAR): added in NEMO repo
+   !!----------------------------------------------------------------------
+   USE netcdf
+   IMPLICIT NONE
+ 
+   INTEGER :: narg, ijarg, iargc
+   INTEGER :: inum=10, n, ji
+   INTEGER :: ncid, id , ierr, idl, idlen, ilen
+   INTEGER :: iformat
+ 
+   CHARACTER(LEN=300), DIMENSION(:), ALLOCATABLE :: cv_namlist
+   CHARACTER(LEN=300)                            :: cldum
+   CHARACTER(LEN=80)                             :: cf_namlist
+   CHARACTER(LEN=255)                            :: cf_domcfg
+   !!----------------------------------------------------------------------
+   !! DCM4, MEOM 2019
+   !! Copyright (c) 2019, J.-M. Molines
+   !! Software governed by the CeCILL licence 
+   !!----------------------------------------------------------------------
+   narg = iargc()
+   
+   ! default initialisation
+   cf_namlist='namelist_cfg'
+   cf_domcfg ='domain_cfg.nc'
+
+   ijarg = 1 
+   DO WHILE ( ijarg <= narg )
+      CALL getarg(ijarg, cldum ) ; ijarg=ijarg+1
+      SELECT CASE ( cldum )
+      CASE ( '-n'   ) ; CALL getarg(ijarg, cf_namlist ) ; ijarg=ijarg+1
+      CASE ( '-d'   ) ; CALL getarg(ijarg, cf_domcfg  ) ; ijarg=ijarg+1
+      CASE ( '-h'   ) ; CALL usage
+      CASE DEFAULT    ; PRINT *, ' ERROR : ', TRIM(cldum),' : unknown option.'; STOP 1
+      END SELECT
+   ENDDO
+   
+   ! Open namelist and count the number of lines before redifining namelist variable in domcfg file.
+   OPEN(inum, file=cf_namlist)
+ 
+   ! count the number of lines
+   n=0 ; ilen=0
+   DO
+      READ(inum,'(a)',END=999) cldum   ! loop till the end of file
+      ilen=MAX(ilen,LEN(TRIM(cldum)))
+      n=n+1
+   ENDDO
+ 
+ 999 PRINT *,' Number of lines in ',TRIM(cf_namlist),' is : ', n
+ 
+   ! allocate variable array
+   ALLOCATE (cv_namlist(n) )
+ 
+   REWIND (inum)
+   DO ji = 1, n
+      READ(inum,'(a)',END=999) cv_namlist(ji)
+   ENDDO
+   CLOSE(inum)
+   
+   ! Open domain_cfg file 
+   ierr = NF90_OPEN(cf_domcfg,NF90_WRITE,ncid)
+   ierr = NF90_REDEF(ncid)
+ 
+   ierr=NF90_DEF_DIM(ncid,'nlines',n, idl)
+   ierr=NF90_DEF_DIM(ncid,'nlen',ilen, idlen)
+ 
+   ! note that namelist is a character 2D variables in the sense of netcdf 
+   ! the program variable is thus an array of character with ilen char per line and n lines.
+   ! If domain_cfg is netcdf4, then deflate the namelist
+   ierr = NF90_INQUIRE(ncid,formatNum=iformat)
+   IF ( iformat == NF90_FORMAT_NETCDF4 .OR. iformat == NF90_FORMAT_NETCDF4_CLASSIC ) THEN
+      ierr=NF90_DEF_VAR(ncid,'namelist_cfg',NF90_CHAR,(/idlen,idl/), id, chunksizes=(/ilen,n/), deflate_level=9 )
+   ELSE
+      ierr=NF90_DEF_VAR(ncid,'namelist_cfg',NF90_CHAR,(/idlen,idl/), id)
+   ENDIF
+   IF (ierr /= 0 ) THEN 
+      PRINT *,NF90_STRERROR(ierr); STOP 1; 
+   END IF
+ 
+   ierr=NF90_ENDDEF(ncid)
+   DO ji=1,n
+      ierr=NF90_PUT_VAR(ncid,id,cv_namlist(ji)(1:ilen) ,start=(/1,ji/), count=(/ilen,1/) )
+      IF (ierr /= 0 ) THEN 
+         PRINT *,NF90_STRERROR(ierr); STOP 1;
+      END IF
+   ENDDO
+   ierr=NF90_CLOSE(ncid)
+
+CONTAINS
+
+   SUBROUTINE usage
+
+      PRINT *,' usage : dom_doc -n NAMELIST-file '
+      PRINT *,'                       -d DOMAIN_CFG-file'
+      PRINT *,'      '
+      PRINT *,'     PURPOSE :'
+      PRINT *,'        Add information in the domain_cfg.nc file after its creation for'
+      PRINT *,'        NEMO4. The additional information consists in a new netcdf variable'
+      PRINT *,'        called namelist_cfg, holding the content of the used namelist_cfg.'
+      PRINT *,'      '
+      PRINT *,'     ARGUMENTS :'
+      PRINT *,'        -n NAMELIST-file : name of the namelist_cfg. file required'
+      PRINT *,'        -d DOMAIN_CFG-file : name of the domain_cfg file to document. file required'
+      PRINT *,'      '
+      PRINT *,'     OUTPUT : '
+      PRINT *,'         input DOMAIN_CFG-file is modified on output.'
+      PRINT *,'      '
+      STOP
+
+   END SUBROUTINE usage
+ 
+END PROGRAM dom_doc
+ 
Index: /utils/tools/DOMAINcfg/src/dom_oce.F90
===================================================================
--- /utils/tools/DOMAINcfg/src/dom_oce.F90	(revision 13389)
+++ /utils/tools/DOMAINcfg/src/dom_oce.F90	(revision 13390)
@@ -45,5 +45,10 @@
    INTEGER, PUBLIC :: nn_interp
    CHARACTER(LEN=200), PUBLIC :: cn_topo
+   CHARACTER(LEN=200), PUBLIC :: cn_topolvl
+   CHARACTER(LEN=200), PUBLIC :: cn_fisfd
    CHARACTER(LEN=132), PUBLIC :: cn_bath
+   CHARACTER(LEN=132), PUBLIC :: cn_bathlvl
+   CHARACTER(LEN=132), PUBLIC :: cn_visfd
+   CHARACTER(LEN=132), PUBLIC :: cn_fcoord
    CHARACTER(LEN=132), PUBLIC :: cn_lon
    CHARACTER(LEN=132), PUBLIC :: cn_lat
Index: /utils/tools/DOMAINcfg/src/domain.F90
===================================================================
--- /utils/tools/DOMAINcfg/src/domain.F90	(revision 13389)
+++ /utils/tools/DOMAINcfg/src/domain.F90	(revision 13390)
@@ -109,5 +109,6 @@
 
       NAMELIST/namdom/ ln_read_cfg, nn_bathy, cn_domcfg, cn_topo, cn_bath, cn_lon, cn_lat, rn_scale, nn_interp, &
-         &              rn_bathy , rn_e3zps_min, rn_e3zps_rat, nn_msh, rn_hmin,            &
+         &             cn_topolvl, cn_fisfd, cn_visfd, cn_bathlvl, cn_fcoord,                       & 
+         &             rn_bathy , rn_e3zps_min, rn_e3zps_rat, nn_msh, rn_hmin,                       &
          &             rn_atfp , rn_rdt   ,  ln_crs      , jphgr_msh ,                               &
          &             ppglam0, ppgphi0, ppe1_deg, ppe2_deg, ppe1_m, ppe2_m,                         &
@@ -169,5 +170,10 @@
          WRITE(numout,*) '   Namelist namdom : space & time domain'
          WRITE(numout,*) '      flag read/compute bathymetry      nn_bathy     = ', nn_bathy
-         IF( nn_bathy == 2 ) THEN
+         IF( nn_bathy == 1 ) THEN
+            WRITE(numout,*) '   read bathymetry from file      cn_topo      = ' ,TRIM(cn_topo)
+            WRITE(numout,*) '   bathymetry name in file        cn_bath      = ' ,TRIM(cn_bath)
+            WRITE(numout,*) '   read isf draft from file       cn_fisfd     = ' ,TRIM(cn_fisfd)
+            WRITE(numout,*) '   isf draft name in file         cn_visfd     = ' ,TRIM(cn_visfd)
+         ELSE IF( nn_bathy == 2 ) THEN
             WRITE(numout,*) '   compute bathymetry from file      cn_topo      = ' , cn_topo
             WRITE(numout,*) '   bathymetry name in file           cn_bath      = ' , cn_bath
@@ -435,6 +441,4 @@
    END SUBROUTINE cfg_write
 
-
-
    !!======================================================================
 END MODULE domain
Index: /utils/tools/DOMAINcfg/src/domhgr.F90
===================================================================
--- /utils/tools/DOMAINcfg/src/domhgr.F90	(revision 13389)
+++ /utils/tools/DOMAINcfg/src/domhgr.F90	(revision 13390)
@@ -465,5 +465,5 @@
          coordinate_filename=TRIM(cn_domcfg)
       ELSE
-         coordinate_filename='coordinates'
+         coordinate_filename=cn_fcoord
       ENDIF
       CALL iom_open( coordinate_filename, inum )
Index: /utils/tools/DOMAINcfg/src/domzgr.F90
===================================================================
--- /utils/tools/DOMAINcfg/src/domzgr.F90	(revision 13389)
+++ /utils/tools/DOMAINcfg/src/domzgr.F90	(revision 13390)
@@ -676,6 +676,6 @@
          !
          IF( ln_zco )   THEN                          ! zco : read level bathymetry 
-            CALL iom_open ( 'bathy_level.nc', inum )  
-            CALL iom_get  ( inum, jpdom_data, 'Bathy_level', bathy )
+            CALL iom_open ( cn_topolvl, inum )  
+            CALL iom_get  ( inum, jpdom_data, cn_bathlvl, bathy )
             CALL iom_close( inum )
             mbathy(:,:) = INT( bathy(:,:) )
@@ -714,10 +714,6 @@
 #endif
             IF( ntopo == 1) THEN
-               CALL iom_open ( 'bathy_meter.nc', inum ) 
-               IF ( ln_isfcav ) THEN
-                  CALL iom_get  ( inum, jpdom_data, 'Bathymetry_isf', bathy, lrowattr=.false. )
-               ELSE
-                  CALL iom_get  ( inum, jpdom_data, 'Bathymetry'    , bathy, lrowattr=ln_use_jattr  )
-               END IF
+               CALL iom_open ( cn_topo, inum ) 
+               CALL iom_get  ( inum, jpdom_data, cn_bath, bathy, lrowattr=ln_use_jattr  )
                CALL iom_close( inum )
             ELSE
@@ -738,6 +734,6 @@
             !
             IF ( ln_isfcav ) THEN
-               CALL iom_open ( 'isf_draft_meter.nc', inum ) 
-               CALL iom_get  ( inum, jpdom_data, 'isf_draft', risfdep )
+               CALL iom_open ( cn_fisfd, inum ) 
+               CALL iom_get  ( inum, jpdom_data, cn_visfd, risfdep )
                CALL iom_close( inum )
             END IF
Index: /utils/tools/DOMAINcfg/xtrac_namelist.bash
===================================================================
--- /utils/tools/DOMAINcfg/xtrac_namelist.bash	(revision 13390)
+++ /utils/tools/DOMAINcfg/xtrac_namelist.bash	(revision 13390)
@@ -0,0 +1,38 @@
+#!/bin/bash
+#####################################################################
+#
+# history: JM Molines (MEOM/IGE/DRAKKAR)    XX/2019: DRAKKAR version
+#          P  Mathiot (CryoDyn/IGE/DRAKKAR) 07/2020: added in NEMO
+#
+# purpose: re-generate the namelist used to build a domain_cfg.nc file
+#          assuming namelist_cfg variable has been added into via
+#          the dom_doc.exe tools
+#
+#####################################################################
+#
+# function to extract namelist
+xtrac_namelist()   {
+   domain_cfg=$1
+   namelist_cfg=$2
+   #ncdump -v namelist_cfg $domain_cfg | tr -d '"'  \
+   #                                   | tr -d '\\' \
+   #                                   | sed -e 's/ *,$//'  \
+   #                                         -e 's/;$//' \
+   #                                         -e '1,/namelist_cfg =/d' \
+   #                                         -e '$d' -e 's/^..//'
+   ncdump -v namelist_cfg $domain_cfg \
+                                      | tr -d '\\' \
+                                      | sed -e 's/^  "//'   \
+                                            -e 's/ *",$//'  \
+                                            -e 's/;$//' \
+                                            -e '1,/namelist_cfg =/d' \
+                                            -e '$d'
+   }
+#
+# main script
+#
+if [ $# != 2 ]; then echo 'usage xtract_namelist.bash [domain_cfg.nc file name] [namelist_output name]'; exit 42; fi
+
+xtrac_namelist $1 > $2
+
+exit $?
