Index: branches/2014/dev_r4650_UKMO10_Tidally_Meaned_Diagnostics/NEMOGCM/TOOLS/SIREN/src/create_bathy.f90
===================================================================
--- branches/2014/dev_r4650_UKMO10_Tidally_Meaned_Diagnostics/NEMOGCM/TOOLS/SIREN/src/create_bathy.f90	(revision 4744)
+++ branches/2014/dev_r4650_UKMO10_Tidally_Meaned_Diagnostics/NEMOGCM/TOOLS/SIREN/src/create_bathy.f90	(revision 5260)
@@ -3,29 +3,125 @@
 !----------------------------------------------------------------------
 !
-!
 ! PROGRAM: create_bathy
 !
 ! DESCRIPTION:
+!> @file
 !> @brief 
-!> This program create bathymetry file.
+!> This program create fine grid bathymetry file.
 !>
 !> @details
-!> Bathymetry could be extracted from fine grid Bathymetry file, or interpolated
-!> from coarse grid Bathymetry file.
-!>
-!> @author
-!> J.Paul
+!> @section sec1 method
+!> Bathymetry could be extracted from fine grid Bathymetry file, interpolated
+!> from coarse grid Bathymetry file, or manually written.
+!>
+!> @section sec2 how to
+!>    to create fine grid bathymetry file:<br/>
+!> @code{.sh}
+!>    ./SIREN/bin/create_bathy create_bathy.nam
+!> @endcode
+!>    
+!>    create_bathy.nam comprise 7 namelists:<br/>
+!>       - logger namelist (namlog)
+!>       - config namelist (namcfg)
+!>       - coarse grid namelist (namcrs)
+!>       - fine grid namelist (namfin)
+!>       - variable namelist (namvar)
+!>       - nesting namelist (namnst)
+!>       - output namelist (namout)
+!>    
+!>    @note 
+!>       All namelists have to be in file create_bathy.nam, however variables of
+!>       those namelists are all optional.
+!>
+!>    * _logger namelist (namlog)_:<br/>
+!>       - cn_logfile   : log filename
+!>       - cn_verbosity : verbosity ('trace','debug','info',
+!> 'warning','error','fatal')
+!>       - in_maxerror  : maximum number of error allowed
+!>
+!>    * _config namelist (namcfg)_:<br/>
+!>       - cn_varcfg : variable configuration file 
+!> (see ./SIREN/cfg/variable.cfg)
+!>
+!>    * _coarse grid namelist (namcrs)_:<br/>
+!>       - cn_coord0 : coordinate file
+!>       - in_perio0 : NEMO periodicity index (see Model Boundary Condition in
+!> [NEMO documentation](http://www.nemo-ocean.eu/About-NEMO/Reference-manuals))
+!>
+!>    * _fine grid namelist (namfin)_:<br/>
+!>       - cn_coord1 : coordinate file
+!>       - in_perio1 : periodicity index
+!>       - ln_fillclosed : fill closed sea or not
+!>
+!>    * _variable namelist (namvar)_:<br/>
+!>       - cn_varinfo : list of variable and extra information about request(s) 
+!>       to be used.<br/>
+!>          each elements of *cn_varinfo* is a string character.<br/>
+!>          it is composed of the variable name follow by ':', 
+!>          then request(s) to be used on this variable.<br/> 
+!>          request could be:
+!>             - interpolation method
+!>             - extrapolation method
+!>             - filter method
+!>             - > minimum value
+!>             - < maximum value
+!>
+!>                requests must be separated by ';'.<br/>
+!>                order of requests does not matter.<br/>
+!>
+!>          informations about available method could be find in @ref interp,
+!>          @ref extrap and @ref filter modules.<br/>
+!>          Example: 'Bathymetry: 2*hamming(2,3); > 0'
+!>          @note 
+!>             If you do not specify a method which is required, 
+!>             default one is apply.
+!>          @warning 
+!>             variable name must be __Bathymetry__ here.
+!>       - cn_varfile : list of variable, and corresponding file.<br/> 
+!>          *cn_varfile* is the path and filename of the file where find
+!>          variable.
+!>          @note 
+!>             *cn_varfile* could be a matrix of value, if you want to filled
+!>             manually variable value.<br/>
+!>             the variable array of value is split into equal subdomain.<br/>
+!>             Each subdomain is filled with the corresponding value 
+!>             of the matrix.<br/>          
+!>             separators used to defined matrix are:
+!>                - ',' for line
+!>                - '/' for row
+!>                - '\' for level<br/>
+!>                Example:<br/>
+!>                   3,2,3/1,4,5  =>  @f$ \left( \begin{array}{ccc}
+!>                                         3 & 2 & 3 \\
+!>                                         1 & 4 & 5 \end{array} \right) @f$
+!>
+!>          Examples: 
+!>             - 'Bathymetry:gridT.nc'
+!>             - 'Bathymetry:5000,5000,5000/5000,3000,5000/5000,5000,5000'
+!>
+!>          \image html  bathy_40.png 
+!>          \image latex bathy_30.png
+!>
+!>    * _nesting namelist (namnst)_:<br/>
+!>       - in_rhoi  : refinement factor in i-direction
+!>       - in_rhoj  : refinement factor in j-direction
+!>       @note 
+!>          coarse grid indices will be deduced from fine grid
+!>          coordinate file.
+!>
+!>    * _output namelist (namout)_:<br/>
+!>       - cn_fileout : output bathymetry file
+!>
+!> @author J.Paul
 ! REVISION HISTORY:
-!> @date Nov, 2013 - Initial Version
+!> @date November, 2013 - Initial Version
+!> @date Sepember, 2014 
+!> - add header for user
+!> - Bug fix, compute offset depending of grid point
 !
 !> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-!>
-!> @todo
-!> - add attributes indices and refinement in output file
 !----------------------------------------------------------------------
-!> @code
 PROGRAM create_bathy
 
-!   USE netcdf                          ! nf90 library
    USE global                          ! global variable
    USE kind                            ! F90 kind parameter
@@ -39,5 +135,4 @@
    USE multi                           ! multi file manager
    USE iom                             ! I/O manager
-   USE dom                             ! domain manager
    USE grid                            ! grid manager
    USE extrap                          ! extrapolation manager
@@ -45,5 +140,7 @@
    USE filter                          ! filter manager
    USE mpp                             ! MPP manager
+   USE dom                             ! domain manager
    USE iom_mpp                         ! MPP I/O manager
+   USE iom_dom                         ! DOM I/O manager
 
    IMPLICIT NONE
@@ -57,19 +154,20 @@
    INTEGER(i4)                                        :: il_status
    INTEGER(i4)                                        :: il_fileid
+   INTEGER(i4)                                        :: il_varid
    INTEGER(i4)                                        :: il_attid
-   INTEGER(i4)                                        :: il_imin
-   INTEGER(i4)                                        :: il_imax
-   INTEGER(i4)                                        :: il_jmin
-   INTEGER(i4)                                        :: il_jmax
+   INTEGER(i4)                                        :: il_imin0
+   INTEGER(i4)                                        :: il_imax0
+   INTEGER(i4)                                        :: il_jmin0
+   INTEGER(i4)                                        :: il_jmax0
    INTEGER(i4)      , DIMENSION(ip_maxdim)            :: il_rho
    INTEGER(i4)      , DIMENSION(2,2)                  :: il_offset
-   INTEGER(i4)      , DIMENSION(2,2,2)                :: il_ind
+   INTEGER(i4)      , DIMENSION(2,2)                  :: il_ind
    INTEGER(i4)      , DIMENSION(:,:)    , ALLOCATABLE :: il_mask
 
    LOGICAL                                            :: ll_exist
 
-   TYPE(TFILE)                                        :: tl_coord0
-   TYPE(TFILE)                                        :: tl_coord1
-   TYPE(TFILE)                                        :: tl_file
+   TYPE(TMPP)                                         :: tl_coord0
+   TYPE(TMPP)                                         :: tl_coord1
+   TYPE(TMPP)                                         :: tl_mpp
    TYPE(TFILE)                                        :: tl_fileout
 
@@ -88,4 +186,6 @@
    TYPE(TMULTI)                                       :: tl_multi
 
+   REAL(dp)                                           :: dl_minbat
+
    ! loop indices
    INTEGER(i4) :: ji
@@ -94,35 +194,40 @@
 
    ! namelist variable
+   ! namlog
    CHARACTER(LEN=lc) :: cn_logfile = 'create_bathy.log' 
    CHARACTER(LEN=lc) :: cn_verbosity = 'warning' 
-
+   INTEGER(i4)       :: in_maxerror = 5
+
+   ! namcfg
    CHARACTER(LEN=lc) :: cn_varcfg = 'variable.cfg' 
 
+   ! namcrs
    CHARACTER(LEN=lc) :: cn_coord0 = '' 
    INTEGER(i4)       :: in_perio0 = -1
 
+   ! namfin
    CHARACTER(LEN=lc) :: cn_coord1 = ''
    INTEGER(i4)       :: in_perio1 = -1
    LOGICAL           :: ln_fillclosed = .TRUE.
 
-   CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varinfo = ''
-   CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varfile = ''
-
-   INTEGER(i4)       :: in_imin0 = 0
-   INTEGER(i4)       :: in_imax0 = 0
-   INTEGER(i4)       :: in_jmin0 = 0
-   INTEGER(i4)       :: in_jmax0 = 0
+   ! namvar
+   CHARACTER(LEN=lc), DIMENSION(ip_maxvar) :: cn_varinfo = ''
+   CHARACTER(LEN=lc), DIMENSION(ip_maxvar) :: cn_varfile = ''
+
+   ! namnst
    INTEGER(i4)       :: in_rhoi  = 1
    INTEGER(i4)       :: in_rhoj  = 1
 
+   ! namout
    CHARACTER(LEN=lc) :: cn_fileout = 'bathy_fine.nc' 
    !-------------------------------------------------------------------
 
-   NAMELIST /namlog/ &  !< logger namelist
-   &  cn_logfile,    &  !< log file
-   &  cn_verbosity      !< log verbosity
-
-   NAMELIST /namcfg/ &  !< configuration namelist
-   &  cn_varcfg         !< variable configuration file
+   NAMELIST /namlog/ &   !< logger namelist
+   &  cn_logfile,    &   !< log file
+   &  cn_verbosity,  &   !< log verbosity
+   &  in_maxerror        !< logger maximum error
+
+   NAMELIST /namcfg/ &   !< configuration namelist
+   &  cn_varcfg          !< variable configuration file
 
    NAMELIST /namcrs/ &   !< coarse grid namelist
@@ -135,22 +240,18 @@
    &  ln_fillclosed      !< fill closed sea
  
-   NAMELIST /namvar/ &  !< variable namelist
-   &  cn_varinfo, &     !< list of variable and interpolation method to be used. (ex: 'votemper:linear','vosaline:cubic' )
-   &  cn_varfile        !< list of variable file
+   NAMELIST /namvar/ &   !< variable namelist
+   &  cn_varinfo, &      !< list of variable and interpolation method to be used. (ex: 'votemper:linear','vosaline:cubic' )
+   &  cn_varfile         !< list of variable file
    
-   NAMELIST /namnst/ &  !< nesting namelist
-   &  in_imin0,   &     !< i-direction lower left  point indice 
-   &  in_imax0,   &     !< i-direction upper right point indice
-   &  in_jmin0,   &     !< j-direction lower left  point indice
-   &  in_jmax0,   &     !< j-direction upper right point indice
-   &  in_rhoi,    &     !< refinement factor in i-direction
-   &  in_rhoj           !< refinement factor in j-direction
-
-   NAMELIST /namout/ &  !< output namlist
-   &  cn_fileout       !< fine grid bathymetry file
+   NAMELIST /namnst/ &   !< nesting namelist
+   &  in_rhoi,    &      !< refinement factor in i-direction
+   &  in_rhoj            !< refinement factor in j-direction
+
+   NAMELIST /namout/ &   !< output namlist
+   &  cn_fileout         !< fine grid bathymetry file
    !-------------------------------------------------------------------
 
-   !1- namelist
-   !1-1 get namelist
+   ! namelist
+   ! get namelist
    il_narg=COMMAND_ARGUMENT_COUNT() !f03 intrinsec
    IF( il_narg/=1 )THEN
@@ -160,9 +261,9 @@
       CALL GET_COMMAND_ARGUMENT(1,cl_namelist) !f03 intrinsec
    ENDIF
-   
-   !1-2 read namelist
+ 
+   ! read namelist
    INQUIRE(FILE=TRIM(cl_namelist), EXIST=ll_exist)
    IF( ll_exist )THEN
-      
+ 
       il_fileid=fct_getunit()
 
@@ -180,10 +281,10 @@
 
       READ( il_fileid, NML = namlog )
-      !1-2-1 define log file
-      CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity))
+      ! define log file
+      CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity),in_maxerror)
       CALL logger_header()
 
       READ( il_fileid, NML = namcfg )
-      !1-2-2 get variable extra information
+      ! get variable extra information
       CALL var_def_extra(TRIM(cn_varcfg))
 
@@ -191,7 +292,7 @@
       READ( il_fileid, NML = namfin )
       READ( il_fileid, NML = namvar )
-      !1-2-3 add user change in extra information
-      CALL var_chg_extra(cn_varinfo)
-      !1-2-4 match variable with file
+      ! add user change in extra information
+      CALL var_chg_extra( cn_varinfo )
+      ! match variable with file
       tl_multi=multi_init(cn_varfile)
       
@@ -211,8 +312,10 @@
    ENDIF
 
-   !2- open files
+   CALL multi_print(tl_multi)
+
+   ! open files
    IF( cn_coord0 /= '' )THEN
-      tl_coord0=file_init(TRIM(cn_coord0),id_perio=in_perio0)
-      CALL iom_open(tl_coord0)
+      tl_coord0=mpp_init( file_init(TRIM(cn_coord0)), id_perio=in_perio0)
+      CALL grid_get_info(tl_coord0)
    ELSE
       CALL logger_fatal("CREATE BATHY: no coarse grid coordinate found. "//&
@@ -221,6 +324,6 @@
 
    IF( TRIM(cn_coord1) /= '' )THEN
-      tl_coord1=file_init(TRIM(cn_coord1),id_perio=in_perio1)
-      CALL iom_open(tl_coord1)
+      tl_coord1=mpp_init( file_init(TRIM(cn_coord1)),id_perio=in_perio1)
+      CALL grid_get_info(tl_coord1)
    ELSE
       CALL logger_fatal("CREATE BATHY: no fine grid coordinate found. "//&
@@ -228,6 +331,6 @@
    ENDIF
 
-   !3- check
-   !3-1 check output file do not already exist
+   ! check
+   ! check output file do not already exist
    INQUIRE(FILE=TRIM(cn_fileout), EXIST=ll_exist)
    IF( ll_exist )THEN
@@ -236,6 +339,6 @@
    ENDIF
 
-   !3-2 check namelist
-   !3-2-1 check refinement factor
+   ! check namelist
+   ! check refinement factor
    il_rho(:)=1
    IF( in_rhoi < 1 .OR. in_rhoj < 1 )THEN
@@ -247,116 +350,132 @@
    ENDIF
 
-   !3-2-2 check domain indices
-   IF( in_imin0 < 1 .OR. in_imax0 < 1 .OR. &
-   &   in_jmin0 < 1 .OR. in_jmax0 < 1)THEN
-      ! compute coarse grid indices around fine grid
-      IF( cn_coord0 /= '' )THEN
-         il_ind(:,:,:)=grid_get_coarse_index( tl_coord0, tl_coord1, &
-         &                                    id_rho=il_rho(:) )
-      ENDIF
-
-      il_imin=il_ind(1,1,1) ; il_imax=il_ind(1,2,1)
-      il_jmin=il_ind(2,1,1) ; il_jmax=il_ind(2,2,1)
-
-      il_offset(:,:)=il_ind(:,:,2)
-   ELSE
-      il_imin=in_imin0 ; il_imax=in_imax0
-      il_jmin=in_jmin0 ; il_jmax=in_jmax0
-
-      il_offset(jp_I,:)=FLOOR(REAL(il_rho(jp_I)-1,dp)*0.5)
-      il_offset(jp_J,:)=FLOOR(REAL(il_rho(jp_J)-1,dp)*0.5)
-   ENDIF
-
-   !3-2-3 check domain validity
-   IF( cn_coord0 /= '' )THEN
-      CALL grid_check_dom(tl_coord0, il_imin, il_imax, il_jmin, il_jmax)
-   ENDIF
-
-   !3-2-4 check coincidence between coarse and fine grid
-   IF( cn_coord0 /= '' )THEN
-      CALL grid_check_coincidence( tl_coord0, tl_coord1, &
-      &                            il_imin, il_imax, &
-      &                            il_jmin, il_jmax, &
-      &                            il_rho(:) )
-   ENDIF
-
-   IF( .NOT. ASSOCIATED(tl_multi%t_file) )THEN
-      CALL logger_error("CREATE BATHY: no file to work on. "//&
+   ! check domain indices
+   ! compute coarse grid indices around fine grid
+   il_ind(:,:)=grid_get_coarse_index( tl_coord0, tl_coord1, &
+   &                                  id_rho=il_rho(:) )
+
+   il_imin0=il_ind(jp_I,1) ; il_imax0=il_ind(jp_I,2)
+   il_jmin0=il_ind(jp_J,1) ; il_jmax0=il_ind(jp_J,2)
+
+   ! check domain validity
+   CALL grid_check_dom(tl_coord0, il_imin0, il_imax0, il_jmin0, il_jmax0)
+
+   ! check coincidence between coarse and fine grid
+   CALL grid_check_coincidence( tl_coord0, tl_coord1, &
+   &                            il_imin0, il_imax0, &
+   &                            il_jmin0, il_jmax0, &
+   &                            il_rho(:) )
+
+   IF( .NOT. ASSOCIATED(tl_multi%t_mpp) )THEN
+      CALL logger_error("CREATE BATHY: no mpp file to work on. "//&
       &                 "check cn_varfile in namelist.")
    ELSE
+
       ALLOCATE( tl_var( tl_multi%i_nvar ) )
       jk=0
-      DO ji=1,tl_multi%i_nfile
-         WRITE(cl_data,'(a,i2.2)') 'data_',jk+1
-         IF( .NOT. ASSOCIATED(tl_multi%t_file(ji)%t_var) )THEN
-            CALL logger_error("CREATE BATHY: no variable to work on for "//&
-            &                 "file"//TRIM(tl_multi%t_file(ji)%c_name)//&
+      DO ji=1,tl_multi%i_nmpp
+      
+         WRITE(cl_data,'(a,i2.2)') 'data-',jk+1
+         IF( .NOT. ASSOCIATED(tl_multi%t_mpp(ji)%t_proc(1)%t_var) )THEN
+
+            CALL logger_fatal("CREATE BATHY: no variable to work on for "//&
+            &                 "mpp file"//TRIM(tl_multi%t_mpp(ji)%c_name)//&
             &                 ". check cn_varfile in namelist.")
-         ELSEIF( TRIM(tl_multi%t_file(ji)%c_name) == TRIM(cl_data) )THEN
-            DO jj=1,tl_multi%t_file(ji)%i_nvar
+
+         ELSEIF( TRIM(tl_multi%t_mpp(ji)%c_name) == TRIM(cl_data) )THEN
+
+            !- use input matrix to initialise variable
+            DO jj=1,tl_multi%t_mpp(ji)%t_proc(1)%i_nvar
                jk=jk+1
-               tl_tmp=tl_multi%t_file(ji)%t_var(jj)
-               !- use input matrix to initialise variable
+               tl_tmp=var_copy(tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj))
+            
                tl_var(jk)=create_bathy_matrix(tl_tmp, tl_coord1)
             ENDDO
+            ! clean
+            CALL var_clean(tl_tmp)
+
          ELSE
-            ! open file
-            tl_file=file_init(TRIM(tl_multi%t_file(ji)%c_name))
-            CALL iom_open(tl_file)
+
+            tl_mpp=mpp_init( file_init(TRIM(tl_multi%t_mpp(ji)%c_name)) )
+            CALL grid_get_info(tl_mpp)
+
+            ! open mpp file
+            CALL iom_mpp_open(tl_mpp)
 
             ! get or check depth value
-            IF( tl_file%i_depthid /= 0 )THEN
+            IF( tl_multi%t_mpp(ji)%t_proc(1)%i_depthid /= 0 )THEN
+               il_varid=tl_multi%t_mpp(ji)%t_proc(1)%i_depthid
                IF( ASSOCIATED(tl_depth%d_value) )THEN
+                  tl_tmp=iom_mpp_read_var(tl_mpp,il_varid)
                   IF( ANY( tl_depth%d_value(:,:,:,:) /= &
                   &        tl_tmp%d_value(:,:,:,:) ) )THEN
                      CALL logger_fatal("CREATE BATHY: depth value from "//&
-                     &  TRIM(tl_multi%t_file(ji)%c_name)//" not conform "//&
+                     &  TRIM(tl_multi%t_mpp(ji)%c_name)//" not conform "//&
                      &  " to those from former file(s).")
                   ENDIF
+                  CALL var_clean(tl_tmp)
                ELSE
-                  tl_depth=iom_read_var(tl_file,tl_file%i_depthid)
+                  tl_depth=iom_mpp_read_var(tl_mpp,il_varid)
                ENDIF
             ENDIF
 
             ! get or check time value
-            IF( tl_file%i_timeid /= 0 )THEN
+            IF( tl_multi%t_mpp(ji)%t_proc(1)%i_timeid /= 0 )THEN
+               il_varid=tl_multi%t_mpp(ji)%t_proc(1)%i_timeid
                IF( ASSOCIATED(tl_time%d_value) )THEN
+                  tl_tmp=iom_mpp_read_var(tl_mpp,il_varid)
                   IF( ANY( tl_time%d_value(:,:,:,:) /= &
                   &        tl_tmp%d_value(:,:,:,:) ) )THEN
                      CALL logger_fatal("CREATE BATHY: time value from "//&
-                     &  TRIM(tl_multi%t_file(ji)%c_name)//" not conform "//&
+                     &  TRIM(tl_multi%t_mpp(ji)%c_name)//" not conform "//&
                      &  " to those from former file(s).")
                   ENDIF
+                  CALL var_clean(tl_tmp)
                ELSE
-                  tl_time=iom_read_var(tl_file,tl_file%i_timeid)
+                  tl_time=iom_mpp_read_var(tl_mpp,il_varid)
                ENDIF
             ENDIF
 
-            IF( ANY( tl_file%t_dim(1:2)%i_len /= &
-            &      tl_coord0%t_dim(1:2)%i_len) )THEN
-               DO jj=1,tl_multi%t_file(ji)%i_nvar
+            ! close mpp file
+            CALL iom_mpp_close(tl_mpp)
+
+            IF( ANY( tl_mpp%t_dim(1:2)%i_len /= &
+            &        tl_coord0%t_dim(1:2)%i_len) )THEN
+               !- extract bathymetry from fine grid bathymetry 
+               DO jj=1,tl_multi%t_mpp(ji)%t_proc(1)%i_nvar
                   jk=jk+1
-                  tl_tmp=tl_multi%t_file(ji)%t_var(jj)
-                  !- extract bathymetry from fine grid bathymetry 
-                  tl_var(jk)=create_bathy_extract( tl_tmp, tl_file, &
+                  tl_tmp=var_copy(tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj))
+               
+                  tl_var(jk)=create_bathy_extract( tl_tmp, tl_mpp, &
                   &                                tl_coord1 )
                ENDDO
+               ! clean
+               CALL var_clean(tl_tmp)
             ELSE
-               DO jj=1,tl_multi%t_file(ji)%i_nvar
+               !- get bathymetry from coarse grid bathymetry 
+               DO jj=1,tl_multi%t_mpp(ji)%t_proc(1)%i_nvar
                   jk=jk+1
-                  tl_tmp=tl_multi%t_file(ji)%t_var(jj)
-                  !- get bathymetry from coarse grid bathymetry 
-                  tl_var(jk)=create_bathy_get_var( tl_tmp, tl_file,  &
-                  &                                il_imin, il_jmin, &
-                  &                                il_imax, il_jmax, &
-                  &                                il_offset(:,:),   &
+                  tl_tmp=var_copy(tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj))
+
+                  il_offset(:,:)= grid_get_fine_offset(tl_coord0,    &
+                  &                                    il_imin0, il_jmin0, &
+                  &                                    il_imax0, il_jmax0, &
+                  &                                    tl_coord1,          &
+                  &                                    il_rho(:),          &
+                  &                                    TRIM(tl_tmp%c_point) )
+
+                  tl_var(jk)=create_bathy_get_var( tl_tmp, tl_mpp,     &
+                  &                                il_imin0, il_jmin0, &
+                  &                                il_imax0, il_jmax0, &
+                  &                                il_offset(:,:),  &
                   &                                il_rho(:) )
                ENDDO
+               ! clean
+               CALL var_clean(tl_tmp)
             ENDIF
 
-            ! close file
-            CALL iom_close(tl_file)
             ! clean structure
-            CALL file_clean(tl_file)
+            CALL mpp_clean(tl_mpp)
+
          ENDIF
       ENDDO
@@ -364,17 +483,16 @@
 
    DO jk=1,tl_multi%i_nvar
-         !6- forced min and max value
+         ! forced min and max value
          CALL var_limit_value(tl_var(jk))
 
-         !7- fill closed sea
-         IF( TRIM(tl_var(jk)%c_stdname) == 'bathymetry' .AND. &
-             ln_fillclosed )THEN
+         ! fill closed sea
+         IF( ln_fillclosed )THEN
             ALLOCATE( il_mask(tl_var(jk)%t_dim(1)%i_len, &
             &                 tl_var(jk)%t_dim(2)%i_len) )
 
-            !7-1 split domain in N sea subdomain
+            ! split domain in N sea subdomain
             il_mask(:,:)=grid_split_domain(tl_var(jk))
 
-            !7-2  fill smallest domain
+            !  fill smallest domain
             CALL grid_fill_small_dom( tl_var(jk), il_mask(:,:) )
 
@@ -382,19 +500,21 @@
          ENDIF
 
-         !8- filter
+         ! filter
          CALL filter_fill_value(tl_var(jk))
 
-         !9- check bathymetry
+         ! check bathymetry
+         dl_minbat=MINVAL(tl_var(jk)%d_value(:,:,:,:))
          IF( TRIM(tl_var(jk)%c_stdname) == 'bathymetry' .AND. &
-         &   MINVAL(tl_var(jk)%d_value(:,:,:,:)) <= 0._dp  )THEN
+         &   dl_minbat <= 0._dp  )THEN
+            CALL logger_debug("CREATE BATHY: min value "//TRIM(fct_str(dl_minbat)))
             CALL logger_error("CREATE BATHY: Bathymetry has value <= 0")
          ENDIF
+
    ENDDO
 
-
-   !10- create file
-   tl_fileout=file_init(TRIM(cn_fileout),id_perio=in_perio1)
-
-   !10-1 add dimension
+   ! create file
+   tl_fileout=file_init(TRIM(cn_fileout))
+
+   ! add dimension
    tl_dim(:)=var_max_dim(tl_var(:))
 
@@ -403,16 +523,22 @@
    ENDDO
 
-   !10-2 add variables
+   ! add variables
    IF( ALL( tl_dim(1:2)%l_use ) )THEN
 
+      ! open mpp files
+      CALL iom_mpp_open(tl_coord1)
+
       ! add longitude
-      tl_lon=iom_read_var(tl_coord1,'longitude')
+      tl_lon=iom_mpp_read_var(tl_coord1,'longitude')
       CALL file_add_var(tl_fileout, tl_lon)
       CALL var_clean(tl_lon)
 
       ! add latitude
-      tl_lat=iom_read_var(tl_coord1,'latitude')
+      tl_lat=iom_mpp_read_var(tl_coord1,'latitude')
       CALL file_add_var(tl_fileout, tl_lat)
       CALL var_clean(tl_lat)
+
+      ! close mpp files
+      CALL iom_mpp_close(tl_coord1)
 
    ENDIF
@@ -435,6 +561,7 @@
       CALL var_clean(tl_var(jk))
    ENDDO
-
-   !10-3 add some attribute
+   DEALLOCATE(tl_var)
+
+   ! add some attribute
    tl_att=att_init("Created_by","SIREN create_bathy")
    CALL file_add_att(tl_fileout, tl_att)
@@ -447,5 +574,5 @@
    il_attid=0
    IF( ASSOCIATED(tl_fileout%t_att) )THEN
-      il_attid=att_get_id(tl_fileout%t_att(:),'periodicity')
+      il_attid=att_get_index(tl_fileout%t_att(:),'periodicity')
    ENDIF
    IF( tl_coord1%i_perio >= 0 .AND. il_attid == 0 )THEN
@@ -454,7 +581,8 @@
    ENDIF
 
+   ! add attribute east west overlap
    il_attid=0
    IF( ASSOCIATED(tl_fileout%t_att) )THEN
-      il_attid=att_get_id(tl_fileout%t_att(:),'ew_overlap')
+      il_attid=att_get_index(tl_fileout%t_att(:),'ew_overlap')
    ENDIF
    IF( tl_coord1%i_ew >= 0 .AND. il_attid == 0 )THEN
@@ -462,21 +590,20 @@
       CALL file_add_att(tl_fileout,tl_att)
    ENDIF
-
-   !10-4 create file
+   
+   ! create file
    CALL iom_create(tl_fileout)
 
-   !10-5 write file
+   ! write file
    CALL iom_write_file(tl_fileout)
 
-   !10-6 close file
+   ! close file
    CALL iom_close(tl_fileout)
-   IF( cn_coord0 /= '' ) CALL iom_close(tl_coord0)
-
-   !11- clean
-   DEALLOCATE(tl_var)
+
+   ! clean
+   CALL att_clean(tl_att)
 
    CALL file_clean(tl_fileout)
-   CALL file_clean(tl_coord1)
-   CALL file_clean(tl_coord0)
+   CALL mpp_clean(tl_coord1)
+   CALL mpp_clean(tl_coord0)
 
    ! close log file
@@ -484,23 +611,27 @@
    CALL logger_close()
 
-!> @endcode
 CONTAINS
    !-------------------------------------------------------------------
    !> @brief
-   !> This subroutine
+   !> This function create variable, filled with matrix value
    !> 
    !> @details 
+   !> A variable is create with the same name that the input variable, 
+   !> and with dimension of the coordinate file.<br/> 
+   !> Then the variable array of value is split into equal subdomain.
+   !> Each subdomain is filled with the corresponding value of the matrix.
    !>
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
+   !> - November, 2013- Initial Version
    !>
-   !> @param[in] 
+   !> @param[in] td_var    variable structure 
+   !> @param[in] td_coord  coordinate file structure
+   !> @return variable structure
    !-------------------------------------------------------------------
-   !> @code
    FUNCTION create_bathy_matrix(td_var, td_coord)
       IMPLICIT NONE
       ! Argument
-      TYPE(TVAR) , INTENT(IN) :: td_var
-      TYPE(TFILE), INTENT(IN) :: td_coord
+      TYPE(TVAR), INTENT(IN) :: td_var
+      TYPE(TMPP), INTENT(IN) :: td_coord
 
       ! function
@@ -508,7 +639,5 @@
 
       ! local variable
-      INTEGER(i4)                                        :: il_ighost
-      INTEGER(i4)                                        :: il_jghost
-      INTEGER(i4)      , DIMENSION(2)                    :: il_xghost
+      INTEGER(i4)      , DIMENSION(2,2)                  :: il_xghost
       INTEGER(i4)      , DIMENSION(3)                    :: il_dim
       INTEGER(i4)      , DIMENSION(3)                    :: il_size
@@ -522,7 +651,7 @@
 
       TYPE(TVAR)                                         :: tl_lon
-      TYPE(TVAR)                                         :: tl_lat
-      TYPE(TVAR)                                         :: tl_var
       TYPE(TDIM)       , DIMENSION(ip_maxdim)            :: tl_dim
+
+      TYPE(TMPP)                                         :: tl_coord
 
       ! loop indices
@@ -532,25 +661,36 @@
       !----------------------------------------------------------------
 
-      !1- read output grid
-      tl_lon=iom_read_var(td_coord,'longitude')
-      tl_lat=iom_read_var(td_coord,'latitude')
-
-      !2- look for ghost cell
-      il_xghost(:)=grid_get_ghost( tl_lon, tl_lat )
-
-      il_ighost=il_xghost(1)*ig_ghost
-      il_jghost=il_xghost(2)*ig_ghost
-      
-      !3- write value on grid
-      !3-1 get matrix dimension
+      ! copy structure
+      tl_coord=mpp_copy(td_coord)
+
+      ! use only edge processor
+      CALL mpp_get_contour(tl_coord)
+
+      ! open useful processor
+      CALL iom_mpp_open(tl_coord)
+
+      ! read output grid
+      tl_lon=iom_mpp_read_var(tl_coord,'longitude')
+
+      ! look for ghost cell
+      il_xghost(:,:)=grid_get_ghost( tl_coord )
+
+      ! close processor
+      CALL iom_mpp_close(tl_coord)
+      ! clean
+      CALL mpp_clean(tl_coord)
+
+      ! remove ghost cell
+      CALL grid_del_ghost(tl_lon, il_xghost(:,:))
+
+      ! write value on grid
+      ! get matrix dimension
       il_dim(:)=td_var%t_dim(1:3)%i_len
-      !3-2 output dimension
-      tl_dim(:)=tl_lon%t_dim(:)
-
-      ! remove ghost cell
-      tl_dim(1)%i_len=tl_dim(1)%i_len - 2*il_xghost(1)*ig_ghost
-      tl_dim(2)%i_len=tl_dim(2)%i_len - 2*il_xghost(2)*ig_ghost
-
-      !3-3 split output domain in N subdomain depending of matrix dimension 
+      ! output dimension
+      tl_dim(:)=dim_copy(tl_lon%t_dim(:))
+      ! clean
+      CALL var_clean(tl_lon)
+
+      ! split output domain in N subdomain depending of matrix dimension 
       il_size(:) = tl_dim(1:3)%i_len / il_dim(:)
       il_rest(:) = MOD(tl_dim(1:3)%i_len, il_dim(:))
@@ -563,5 +703,4 @@
       ! add rest to last cell
       il_ishape(il_dim(1)+1)=il_ishape(il_dim(1)+1)+il_rest(1)
-      
 
       ALLOCATE( il_jshape(il_dim(2)+1) )
@@ -581,5 +720,5 @@
       il_kshape(il_dim(3)+1)=il_kshape(il_dim(3)+1)+il_rest(3)
 
-      !3-3 write ouput table of value 
+      ! write ouput array of value 
       ALLOCATE(dl_value( tl_dim(1)%i_len, &
       &                  tl_dim(2)%i_len, &
@@ -602,36 +741,36 @@
       ENDDO
 
-      !3-4 initialise variable with value
-      tl_var=var_init(TRIM(td_var%c_name),dl_value(:,:,:,:))
+      ! initialise variable with value
+      create_bathy_matrix=var_init(TRIM(td_var%c_name),dl_value(:,:,:,:))
 
       DEALLOCATE(dl_value)
 
-      !4- add ghost cell
-      CALL grid_add_ghost(tl_var,il_ighost,il_jghost)
-
-      !5- save result
-      create_bathy_matrix=tl_var
+      ! add ghost cell
+      CALL grid_add_ghost(create_bathy_matrix, il_xghost(:,:))
+
+      ! clean
+      CALL dim_clean(tl_dim(:))
 
    END FUNCTION create_bathy_matrix
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief
-   !> This subroutine
+   !> This function extract variable from file over coordinate domain and
+   !> return variable structure
    !> 
-   !> @details 
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
    !>
-   !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !>
-   !> @param[in] 
+   !> @param[in] td_var    variable structure 
+   !> @param[in] td_mpp    mpp file structure
+   !> @param[in] td_coord  coordinate file structure
+   !> @return variable structure
    !-------------------------------------------------------------------
-   !> @code
-   FUNCTION create_bathy_extract(td_var, td_file, &
+   FUNCTION create_bathy_extract(td_var, td_mpp, &
    &                             td_coord)
       IMPLICIT NONE
       ! Argument
-      TYPE(TVAR) , INTENT(IN) :: td_var  
-      TYPE(TFILE), INTENT(IN) :: td_file
-      TYPE(TFILE), INTENT(IN) :: td_coord
+      TYPE(TVAR), INTENT(IN) :: td_var  
+      TYPE(TMPP), INTENT(IN) :: td_mpp
+      TYPE(TMPP), INTENT(IN) :: td_coord
 
       ! function
@@ -639,8 +778,5 @@
 
       ! local variable
-      INTEGER(i4), DIMENSION(2,2,2) :: il_ind
-
-      INTEGER(i4) :: il_pivot
-      INTEGER(i4) :: il_perio
+      INTEGER(i4), DIMENSION(2,2) :: il_ind
 
       INTEGER(i4) :: il_imin
@@ -648,6 +784,4 @@
       INTEGER(i4) :: il_imax
       INTEGER(i4) :: il_jmax
-
-      TYPE(TFILE) :: tl_file
 
       TYPE(TMPP)  :: tl_mpp
@@ -661,67 +795,42 @@
       !----------------------------------------------------------------
 
-      IF( td_file%i_id == 0 )THEN
-         CALL logger_error("CREATE BATHY EXTRACT: file "//&
-         &  TRIM(td_file%c_name)//" not opened ")
+      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN
+         CALL logger_error("CREATE BATHY EXTRACT: no processor associated "//&
+         &  "to mpp "//TRIM(td_mpp%c_name))
       ELSE
 
          !init
-         tl_file=td_file
-
-         !1- open file
-         CALL iom_open(tl_file)
-
-         ! get periodicity
-         il_pivot=grid_get_pivot(tl_file)
-         il_perio=grid_get_perio(tl_file,il_pivot)
-
-         tl_file%i_perio=il_perio
-
-         !2- compute file grid indices around coord grid
-         il_ind(:,:,:)=grid_get_coarse_index(tl_file, td_coord )
-
-         il_imin=il_ind(1,1,1) ; il_imax=il_ind(1,2,1)
-         il_jmin=il_ind(2,1,1) ; il_jmax=il_ind(2,2,1)
-
-         IF( ANY( il_ind(:,:,2) /= 0 ) )THEN
-            CALL logger_error("CREATE BATHY EXTRACT: something wrong "//&
-            &  " find offset when extracting data")
-         ENDIF
-         !3- check grid coincidence
-         CALL grid_check_coincidence( tl_file, td_coord, &
+         tl_mpp=mpp_copy(td_mpp)
+
+         ! compute file grid indices around coord grid
+         il_ind(:,:)=grid_get_coarse_index(tl_mpp, td_coord )
+
+         il_imin=il_ind(1,1) ; il_imax=il_ind(1,2)
+         il_jmin=il_ind(2,1) ; il_jmax=il_ind(2,2)
+
+         ! check grid coincidence
+         CALL grid_check_coincidence( tl_mpp, td_coord, &
          &                            il_imin, il_imax, &
          &                            il_jmin, il_jmax, &
          &                            (/1, 1, 1/) )
 
-         !4- compute domain
-         tl_dom=dom_init(tl_file,         &
+         ! compute domain
+         tl_dom=dom_init(tl_mpp,           &
          &               il_imin, il_imax, &
          &               il_jmin, il_jmax)
 
-         ! close file
-         CALL iom_close(tl_file)
-
-         !5- read bathymetry on domain (ugly way to do it, have to work on it)
-         !5-1 init mpp structure
-         tl_mpp=mpp_init(tl_file)
-
-         CALL file_clean(tl_file)
-
-         !5-2 get processor to be used
-         CALL mpp_get_use( tl_mpp, tl_dom )
-
-         !5-3 open mpp files
-         CALL iom_mpp_open(tl_mpp)
-
-         !5-4 read variable on domain
-         tl_var=iom_mpp_read_var(tl_mpp,TRIM(td_var%c_name),td_dom=tl_dom)
-
-         !5-5 close mpp file
-         CALL iom_mpp_close(tl_mpp)
-
-         !6- add ghost cell
-         CALL grid_add_ghost(tl_var,tl_dom%i_ighost,tl_dom%i_jghost)
-
-         !7- check result
+         ! open mpp files over domain
+         CALL iom_dom_open(tl_mpp, tl_dom)
+
+         ! read variable on domain
+         tl_var=iom_dom_read_var(tl_mpp,TRIM(td_var%c_name),tl_dom)
+
+         ! close mpp file
+         CALL iom_dom_close(tl_mpp)
+
+         ! add ghost cell
+         CALL grid_add_ghost(tl_var,tl_dom%i_ghost(:,:))
+
+         ! check result
          IF( ANY( tl_var%t_dim(:)%l_use .AND. &
          &        tl_var%t_dim(:)%i_len /= td_coord%t_dim(:)%i_len) )THEN
@@ -743,18 +852,19 @@
          ENDIF
 
-         !8- add attribute to variable
+         ! add attribute to variable
          tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name)))
          CALL var_move_att(tl_var, tl_att)         
 
-         tl_att=att_init('src_i-indices',(/tl_dom%i_imin, tl_dom%i_imax/))
+         tl_att=att_init('src_i_indices',(/tl_dom%i_imin, tl_dom%i_imax/))
          CALL var_move_att(tl_var, tl_att)
 
-         tl_att=att_init('src_j-indices',(/tl_dom%i_jmin, tl_dom%i_jmax/))
+         tl_att=att_init('src_j_indices',(/tl_dom%i_jmin, tl_dom%i_jmax/))
          CALL var_move_att(tl_var, tl_att)
 
-         !9- save result
-         create_bathy_extract=tl_var
+         ! save result
+         create_bathy_extract=var_copy(tl_var)
 
          ! clean structure
+         CALL att_clean(tl_att)
          CALL var_clean(tl_var)
          CALL mpp_clean(tl_mpp)
@@ -762,24 +872,23 @@
 
    END FUNCTION create_bathy_extract
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief
-   !> This subroutine
+   !> This function get coarse grid variable, interpolate variable, and return
+   !> variable structure over fine grid
    !> 
-   !> @details 
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
    !>
-   !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !>
-   !> @param[in] td_var : variable structure
-   !> @param[in] td_file : file structure
-   !> @param[in] id_imin : i-direction lower left  corner indice 
-   !> @param[in] id_imax : i-direction upper right corner indice 
-   !> @param[in] id_jmin : j-direction lower left  corner indice
-   !> @param[in] id_jmax : j-direction upper right corner indice 
-   !> @param[in] id_rho  : table of refinement factor
+   !> @param[in] td_var    variable structure
+   !> @param[in] td_mpp    mpp file structure
+   !> @param[in] id_imin   i-direction lower left  corner indice 
+   !> @param[in] id_imax   i-direction upper right corner indice 
+   !> @param[in] id_jmin   j-direction lower left  corner indice
+   !> @param[in] id_jmax   j-direction upper right corner indice 
+   !> @param[in] id_offset offset between fine grid and coarse grid
+   !> @param[in] id_rho    array of refinement factor
+   !> @return variable structure
    !-------------------------------------------------------------------
-   !> @code
-   FUNCTION create_bathy_get_var(td_var, td_file,  &
+   FUNCTION create_bathy_get_var(td_var, td_mpp,   &
             &                    id_imin, id_jmin, &
             &                    id_imax, id_jmax, &
@@ -789,5 +898,5 @@
       ! Argument
       TYPE(TVAR) , INTENT(IN) :: td_var  
-      TYPE(TFILE), INTENT(IN) :: td_file  
+      TYPE(TMPP) , INTENT(IN) :: td_mpp 
       INTEGER(i4), INTENT(IN) :: id_imin
       INTEGER(i4), INTENT(IN) :: id_imax
@@ -801,107 +910,91 @@
 
       ! local variable
-      INTEGER(i4) :: il_pivot
-      INTEGER(i4) :: il_perio
-
-      TYPE(TFILE) :: tl_file
-
       TYPE(TMPP)  :: tl_mpp
-
       TYPE(TATT)  :: tl_att
-
       TYPE(TVAR)  :: tl_var
-      
       TYPE(TDOM)  :: tl_dom
+
+      INTEGER(i4) :: il_size
+      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_rho
 
       ! loop indices
       !----------------------------------------------------------------
       IF( ANY(SHAPE(id_offset(:,:)) /= 2) )THEN
-         CALL logger_error("CREATE BATHY GET VAR: invalid dimensio of "//&
-         &                 "offset table")
+         CALL logger_error("CREATE BATHY GET VAR: invalid dimension of "//&
+         &                 "offset array")
       ENDIF
 
-      !init
-      tl_file=td_file
-
-      !1- open file
-      CALL iom_open(tl_file)
-
-      ! get periodicity
-      il_pivot=grid_get_pivot(tl_file)
-      il_perio=grid_get_perio(tl_file,il_pivot)
-
-      tl_file%i_perio=il_perio
-
-      !2- compute domain
-      tl_dom=dom_init(tl_file,          &
+      ! copy structure
+      tl_mpp=mpp_copy(td_mpp)
+
+      !- compute domain
+      tl_dom=dom_init(tl_mpp,           &
       &               id_imin, id_imax, &
       &               id_jmin, id_jmax)
 
-      CALL dom_print(tl_dom)
-      print *,'id_offset ',id_offset(:,:)
-      !3- close file
-      CALL iom_close(tl_file)      
-
-      !4- add extra band (if possible) to compute interpolation
+      !- add extra band (if possible) to compute interpolation
       CALL dom_add_extra(tl_dom)
 
-      !5- read bathymetry on domain (ugly way to do it, have to work on it)
-      !5-1 init mpp sturcutre
-      tl_mpp=mpp_init(tl_file)
-
-      CALL file_clean(tl_file)
-
-      !5-2 get processor to be used
-      CALL mpp_get_use( tl_mpp, tl_dom )
-
-      !5-3 open mpp files
-      CALL iom_mpp_open(tl_mpp)
-
-      !5-4 read variable value on domain
-      tl_var=iom_mpp_read_var(tl_mpp,TRIM(td_var%c_name),td_dom=tl_dom)
-
-      !5-5 close mpp files
-      CALL iom_mpp_close(tl_mpp)      
-
-      !6- interpolate variable
-      CALL create_bathy_interp(tl_var, id_rho(:), id_offset(:,:))
-
-      !7- remove extraband added to domain
-      CALL dom_del_extra( tl_var, tl_dom, id_rho(:) )
-
-      !8- add ghost cell
-      CALL grid_add_ghost(tl_var,tl_dom%i_ighost,tl_dom%i_jghost)
+      !- open mpp files over domain
+      CALL iom_dom_open(tl_mpp, tl_dom)
+
+      !- read variable value on domain
+      tl_var=iom_dom_read_var(tl_mpp,TRIM(td_var%c_name),tl_dom)
+
+      !- close mpp files
+      CALL iom_dom_close(tl_mpp)
+
+      il_size=SIZE(id_rho(:))
+      ALLOCATE( il_rho(il_size) )
+      il_rho(:)=id_rho(:)
+      
+      !- interpolate variable
+      CALL create_bathy_interp(tl_var, il_rho(:), id_offset(:,:))
+
+      !- remove extraband added to domain
+      CALL dom_del_extra( tl_var, tl_dom, il_rho(:) )
+
+      !- add ghost cell
+      CALL grid_add_ghost(tl_var,tl_dom%i_ghost(:,:))
  
-      !9- add attribute to variable
+      !- add attribute to variable
       tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name)))
       CALL var_move_att(tl_var, tl_att)
 
-      tl_att=att_init('src_i-indices',(/tl_dom%i_imin, tl_dom%i_imax/))
+      tl_att=att_init('src_i_indices',(/tl_dom%i_imin, tl_dom%i_imax/))
       CALL var_move_att(tl_var, tl_att)
 
-      tl_att=att_init('src_j-indices',(/tl_dom%i_jmin, tl_dom%i_jmax/))
+      tl_att=att_init('src_j_indices',(/tl_dom%i_jmin, tl_dom%i_jmax/))
       CALL var_move_att(tl_var, tl_att)
 
-      !10- save result
-      create_bathy_get_var=tl_var
-
-      !11- clean structure
+      IF( .NOT. ALL(id_rho(:)==1) )THEN
+         tl_att=att_init("refinment_factor",(/id_rho(jp_I),id_rho(jp_J)/))
+         CALL var_move_att(tl_var, tl_att)
+      ENDIF
+
+      DEALLOCATE( il_rho )
+
+      !- save result
+      create_bathy_get_var=var_copy(tl_var)
+
+      !- clean structure
+      CALL att_clean(tl_att)
+      CALL var_clean(tl_var)
       CALL mpp_clean(tl_mpp)
  
    END FUNCTION create_bathy_get_var
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief
-   !> This subroutine
+   !> This subroutine interpolate variable
    !> 
-   !> @details 
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
    !>
-   !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !>
-   !> @param[in] 
-   !> @todo 
+   !> @param[inout] td_var variable structure 
+   !> @param[in] id_rho    array of refinment factor
+   !> @param[in] id_offset array of offset between fine and coarse grid
+   !> @param[in] id_iext   i-direction size of extra bands (default=im_minext)
+   !> @param[in] id_jext   j-direction size of extra bands (default=im_minext)
    !-------------------------------------------------------------------
-   !> @code
    SUBROUTINE create_bathy_interp( td_var,         &
    &                               id_rho,          &
@@ -919,5 +1012,4 @@
 
       ! local variable
-      TYPE(TVAR)  :: tl_var
       TYPE(TVAR)  :: tl_mask
 
@@ -929,7 +1021,4 @@
       ! loop indices
       !----------------------------------------------------------------
-
-      ! copy variable
-      tl_var=td_var
 
       !WARNING: two extrabands are required for cubic interpolation
@@ -952,60 +1041,55 @@
       ENDIF
 
-      !1- work on mask
-      !1-1 create mask
-      ALLOCATE(bl_mask(tl_var%t_dim(1)%i_len, &
-      &                tl_var%t_dim(2)%i_len, &
-      &                tl_var%t_dim(3)%i_len, &
-      &                tl_var%t_dim(4)%i_len) )
+      ! work on mask
+      ! create mask
+      ALLOCATE(bl_mask(td_var%t_dim(1)%i_len, &
+      &                td_var%t_dim(2)%i_len, &
+      &                td_var%t_dim(3)%i_len, &
+      &                td_var%t_dim(4)%i_len) )
 
       bl_mask(:,:,:,:)=1
-      WHERE(tl_var%d_value(:,:,:,:)==tl_var%d_fill) bl_mask(:,:,:,:)=0      
-
-      SELECT CASE(TRIM(tl_var%c_point))
+      WHERE(td_var%d_value(:,:,:,:)==td_var%d_fill) bl_mask(:,:,:,:)=0      
+
+      SELECT CASE(TRIM(td_var%c_point))
       CASE DEFAULT ! 'T'
-         tl_mask=var_init('tmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
-      CASE('U')
-         tl_mask=var_init('umask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
-      CASE('V')
-         tl_mask=var_init('vmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
-      CASE('F')
-         tl_mask=var_init('fmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:))
+         tl_mask=var_init('tmask', bl_mask(:,:,:,:), td_dim=td_var%t_dim(:), &
+         &                id_ew=td_var%i_ew )
+      CASE('U','V','F')
+         CALL logger_fatal("CREATE BATHY INTERP: can not computed "//&
+         &                 "interpolation on "//TRIM(td_var%c_point)//&
+         &                 " grid point (variable "//TRIM(td_var%c_name)//&
+         &                 "). check namelist.")
       END SELECT
 
       DEALLOCATE(bl_mask)
 
-      !1-2 interpolate mask
+      ! interpolate mask
       CALL interp_fill_value( tl_mask, id_rho(:), &
       &                       id_offset=id_offset(:,:) )
 
-      !2- work on variable
-      !2-0 add extraband
-      CALL extrap_add_extrabands(tl_var, il_iext, il_jext)
-
-      !2-1 extrapolate variable
-      CALL extrap_fill_value( tl_var, id_offset=id_offset(:,:), &
+      ! work on variable
+      ! add extraband
+      CALL extrap_add_extrabands(td_var, il_iext, il_jext)
+
+      ! extrapolate variable
+      CALL extrap_fill_value( td_var, id_offset=id_offset(:,:), &
       &                               id_rho=id_rho(:),         &
       &                               id_iext=il_iext, id_jext=il_jext )
 
-      !2-2 interpolate Bathymetry
-      CALL interp_fill_value( tl_var, id_rho(:), &
+      ! interpolate Bathymetry
+      CALL interp_fill_value( td_var, id_rho(:), &
       &                       id_offset=id_offset(:,:) )
 
-      !2-3 remove extraband
-      CALL extrap_del_extrabands(tl_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J))
-
-      !2-2-5 keep original mask 
+      ! remove extraband
+      CALL extrap_del_extrabands(td_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J))
+
+      ! keep original mask 
       WHERE( tl_mask%d_value(:,:,:,:) == 0 )
-         tl_var%d_value(:,:,:,:)=tl_var%d_fill
+         td_var%d_value(:,:,:,:)=td_var%d_fill
       END WHERE
-
-      !3- save result
-      td_var=tl_var
 
       ! clean variable structure
       CALL var_clean(tl_mask)
-      CALL var_clean(tl_var)
 
    END SUBROUTINE create_bathy_interp
-   !> @endcode
 END PROGRAM create_bathy
