Index: utils/tools/NESTING/src/agrif_create_bathy.f90
===================================================================
--- utils/tools/NESTING/src/agrif_create_bathy.f90	(revision 10093)
+++ utils/tools/NESTING/src/agrif_create_bathy.f90	(revision 10381)
@@ -41,5 +41,5 @@
   !      
   CHARACTER(len=80) ::   namelistname
-  CHARACTER*100     ::   Childmeter_file,Childlevel_file,Child_coordinates,child_ps, Child_domcfg    
+  CHARACTER*100     ::   child_coordinates, child_level, child_meter, child_domcfg    
   LOGICAL ::   identical_grids     
   INTEGER ::   nbadd,status,narg,iargc     
@@ -69,10 +69,19 @@
   ! read input file (namelist.input)
   CALL read_namelist(namelistname)
-  !      
+
+  ! if level or meter name is missing
+  IF( TRIM(parent_level_name) == '' )   parent_level_name='mbathy'
+  IF( TRIM(parent_meter_name) == '' )   parent_meter_name='Bathymetry'
+
   ! define names of child grid files
-  CALL set_child_name(parent_coordinate_file,Child_coordinates) 
-  IF( TRIM(parent_bathy_file) .NE. '/NULL' )    CALL set_child_name(parent_bathy_file,Childlevel_file)            
-  IF( TRIM(parent_bathy_file) .NE. '/NULL' )    CALL set_child_name(parent_domcfg_output,Child_domcfg) 
+  CALL set_child_name(parent_coordinate_file,child_coordinates) 
+  IF( TRIM(parent_bathy_level) /= '' )   CALL set_child_name(parent_bathy_level,child_level)            
+  IF( TRIM(parent_bathy_meter) /= '' )   CALL set_child_name(parent_bathy_meter,child_meter)
+  IF( TRIM(parent_domcfg_out)  /= '' )   CALL set_child_name(parent_domcfg_out,child_domcfg) 
   !
+  IF( TRIM(parent_bathy_level) == '' .AND. TRIM(parent_bathy_meter) == '') THEN
+     WRITE(*,*) 'ERROR ***** one needs at least to define parent_bathy_level or parent_bathy_meter ...'
+     STOP
+  ENDIF
   !                                                   ! ------------------------------------------------------------------
   IF( .NOT.new_topo .AND. .NOT.partial_steps ) THEN   ! **** First option : no new topo file & no partial steps
@@ -81,10 +90,18 @@
      WRITE(*,*) '*** First option: no new topo file & no partial steps'
      !      
-     ! read coarse grid bathymetry and coordinates
+     ! read coarse grid coordinates
      status = Read_Coordinates(TRIM(parent_coordinate_file),G0)    
-     status = Read_bathy_level(TRIM(parent_bathy_file),G0)
+
+     ! read coarse grid bathymetry
+     IF( TRIM(parent_bathy_level) /= '' ) THEN
+        status = Read_bathy_level(TRIM(parent_bathy_level),G0)
+        CALL levels_to_meter(G0)
+     ELSEIF( TRIM(parent_bathy_level) == '' .AND. TRIM(parent_bathy_meter) /= '') THEN
+        status = read_bathy_meter(TRIM(parent_bathy_meter),G0)
+        CALL meter_to_levels(G0)
+     ENDIF
      !           
      ! read fine grid coordinates
-     status = Read_Coordinates(TRIM(Child_coordinates),G1,pacifique)
+     status = Read_Coordinates(TRIM(child_coordinates),G1,pacifique)
      !
      ! stop if error in size
@@ -113,9 +130,7 @@
         WHERE(G0%nav_lon < 0.001)   G0%nav_lon = G0%nav_lon + 360.
      ENDIF
-
-     ! From levels to meters
+     !             
      ALLOCATE(G1%bathy_meter(nxfin,nyfin))
-     CALL levels_to_meter(G0)
-     !             
+     !
      ! compute remapping matrix thanks to SCRIP package
      CALL get_remap_matrix(G0%nav_lat,G1%nav_lat,G0%nav_lon,G1%nav_lon,masksrc,matrix,src_add,dst_add)
@@ -189,11 +204,13 @@
         WHERE (bathy_test.EQ.0.)   G1%bathy_level = 0.
 
-        DEALLOCATE(bathy_test)           
-     ENDIF
+        DEALLOCATE(bathy_test)
+     ENDIF
+     !
+     CALL levels_to_meter(G1) ! needed for domcfg
      !
      ! store interpolation result in output file
-     CALL levels_to_meter(G1)   ! From levels to meters
-     status = Write_Bathy_level(TRIM(Childlevel_file),G1)
-     status = write_domcfg(TRIM(Child_domcfg),G1)
+     status = Write_Bathy_level(TRIM(child_level),G1)
+     status = write_domcfg(TRIM(child_domcfg),G1)
+     !!status = write_domcfg(TRIM(parent_domcfg_out),G0) ! do not activate it
 
      WRITE(*,*) '****** Bathymetry successfully created if no new topo ******'
@@ -203,9 +220,9 @@
   ELSE                                                ! **** Second option : new topo file or partial steps     
      !                                                ! ----------------------------------------------------- 
-     WRITE(*,*) '***Second option : new topo or partial steps'
+     WRITE(*,*) '*** Second option : new topo or partial steps'
 
      ! read fine and coarse grids coordinates file
      status = Read_Coordinates(TRIM(parent_coordinate_file),G0)
-     status = Read_Coordinates(TRIM(Child_coordinates),G1,Pacifique)
+     status = Read_Coordinates(TRIM(child_coordinates),G1,Pacifique)
      !
      ! check error in size
@@ -221,12 +238,17 @@
      ENDIF
      !
-     ! === From here on: G0 is the grid associated with the new topography (like gebco or etopo) ===
+     ! === From here on: G0 is the grid associated with the new topography (as gebco or etopo) ===
      !
      ! read bathymetry data set => G0%bathy_meter
      IF( new_topo ) THEN                                       ! read G0%bathy_meter (on a reduced grid) and G1 coordinates
         DEALLOCATE( G0%nav_lon, G0%nav_lat )
-        status = Read_bathy_meter(TRIM(elevation_database),G0,G1,Pacifique)
+        status = read_bathy_coord(TRIM(elevation_database),G0,G1,Pacifique)
      ELSE                                                      ! read G0%bathy_meter (on the global grid)
-        status = Read_Bathymeter(TRIM(parent_bathy_meter),G0)   
+        IF( TRIM(parent_bathy_level) /= '' ) THEN
+           status = Read_bathy_level(TRIM(parent_bathy_level),G0)
+           CALL levels_to_meter(G0)
+        ELSEIF( TRIM(parent_bathy_level) == '' .AND. TRIM(parent_bathy_meter) /= '') THEN
+           status = read_bathy_meter(TRIM(parent_bathy_meter),G0)
+        ENDIF
         IF(Pacifique) THEN
            WHERE(G0%nav_lon < 0.0001)   G0%nav_lon = G0%nav_lon + 360.
@@ -408,8 +430,9 @@
      !
      ! Coarse grid bathymetry : G0%bathy_meter (on the global grid)
-     IF( partial_steps ) THEN                     
-        status = Read_Bathymeter(TRIM(parent_bathy_meter),G0)
+     IF( TRIM(parent_bathy_meter) /= '') THEN
+        status = read_bathy_meter(TRIM(parent_bathy_meter),G0)
      ELSE
-        status = Read_Bathymeter(TRIM(parent_bathy_file),G0)
+        status = Read_bathy_level(TRIM(parent_bathy_level),G0)
+        CALL levels_to_meter(G0)
      ENDIF
      
@@ -586,52 +609,23 @@
      ENDIF
      !
-     !                              ! ----------------
-     IF( partial_steps ) THEN       ! If partial steps
-        !                           ! ----------------
-        !
-        CALL get_partial_steps(G1)  ! recompute gdepw_ps for G1
-
-        IF(bathy_update)   CALL Update_Parent_Bathy( G0,G1 ) 
-        CALL set_child_name(parent_bathy_meter,child_ps)
-        
-                           status = Write_Bathy_meter(TRIM(child_ps),G1)
-        IF(bathy_update)   status = Write_Bathy_meter(TRIM(updated_parent_file),G0)
-        IF(bathy_update)   status = write_domcfg(TRIM(updated_parent_domcfg),G0)
-
-        CALL get_partial_steps(G1)
-        !
-        G1%bathy_level=NINT(G1%bathy_level)
-        !
-        ! store interpolation result in output file
-        CALL levels_to_meter(G1)   ! From levels to meters
-        IF( TRIM(parent_bathy_file) .NE. '/NULL' )    status = Write_Bathy_level(TRIM(Childlevel_file),G1)
-        IF( TRIM(parent_bathy_file) .NE. '/NULL' )    status = write_domcfg(TRIM(Child_domcfg),G1)
-        !
-        WRITE(*,*) '****** Bathymetry successfully created for partial cells ******'
-        STOP
-        !
-        !                           ! ----------------
-     ELSE                           ! No partial steps
-        !                           ! ----------------
-        !
-        ! convert bathymetry from meters to levels
-        CALL meter_to_levels(G1) 
-
-        IF(bathy_update)   CALL Update_Parent_Bathy( G0,G1 ) 
-        CALL set_child_name(parent_bathy_meter,child_ps)
-        
-                           status = Write_Bathy_meter(TRIM(child_ps),G1)        
-        IF(bathy_update)   status = Write_Bathy_meter(TRIM(updated_parent_file),G0)
-        IF(bathy_update)   status = write_domcfg(TRIM(updated_parent_domcfg),G0)
-        !
-        ! store interpolation result in output file
-        CALL levels_to_meter(G1)   ! From levels to meters
-        status = Write_Bathy_level(TRIM(Childlevel_file),G1)
-        status = write_domcfg(TRIM(Child_domcfg),G1)
-        !
-        WRITE(*,*) '****** Bathymetry successfully created for full cells ******'
-        STOP
-        ! 
-     ENDIF
+     IF( partial_steps ) THEN
+        CALL get_partial_steps(G1)  ! recompute bathy_level and gdepw_ps for G1 (and correct bathy_meter)
+     ELSE
+        CALL meter_to_levels(G1)    ! convert bathymetry from meters to levels
+     ENDIF
+     !
+     ! update parent grid
+     IF(bathy_update)   CALL Update_Parent_Bathy( G0,G1 ) 
+     
+     IF(bathy_update)   status = Write_Bathy_meter(TRIM(parent_bathy_meter_updated),G0)
+     IF(bathy_update)   status = write_domcfg(TRIM(parent_domcfg_updated),G0)
+     
+     ! store interpolation result in output file
+     IF( TRIM(parent_bathy_level) /= '' )   status = Write_Bathy_level(TRIM(child_level),G1)
+     IF( TRIM(parent_bathy_meter) /= '' )   status = Write_Bathy_meter(TRIM(child_meter),G1)
+     IF( TRIM(parent_domcfg_out)  /= '' )   status = write_domcfg(TRIM(child_domcfg),G1)
+     !
+     WRITE(*,*) '****** Bathymetry successfully created ******'
+     STOP
   ENDIF
   !
