Index: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/TOOLS/SIREN/src/create_boundary.f90
===================================================================
--- branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/TOOLS/SIREN/src/create_boundary.f90	(revision 4810)
+++ branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/TOOLS/SIREN/src/create_boundary.f90	(revision 5600)
@@ -7,21 +7,170 @@
 !
 ! DESCRIPTION:
+!> @file
 !> @brief 
 !> This program create boundary files.
 !>
 !> @details
-!> Variables are read from standard output.
-!> Then theses variables are interpolated on fine grid boundaries.
-!>
-!> @author
-!> J.Paul
+!> @section sec1 method
+!> Variables are read from coarse grid standard output 
+!> and interpolated on fine grid or manually written.<br/>
+!> @note 
+!>    method could be different for each variable.
+!>
+!> @section sec2 how to 
+!>    to create boundaries files:<br/>
+!> @code{.sh}
+!>    ./SIREN/bin/create_boundary create_boundary.nam
+!> @endcode
+!>    
+!>    create_boundary.nam comprise 9 namelists:<br/>
+!>       - logger namelist (namlog)
+!>       - config namelist (namcfg)
+!>       - coarse grid namelist (namcrs)
+!>       - fine grid namelist (namfin)
+!>       - variable namelist (namvar)
+!>       - nesting namelist (namnst)
+!>       - boundary namelist (nambdy)
+!>       - vertical grid namelist (namzgr)
+!>       - output namelist (namout)
+!>    
+!>    @note 
+!>       All namelists have to be in file create_boundary.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
+!>       - cn_bathy1 : bathymetry file
+!>       - in_perio1 : periodicity index
+!>
+!>    * _vertical grid namelist (namzgr)_:<br/>
+!>       - dn_pp_to_be_computed  :
+!>       - dn_ppsur              :
+!>       - dn_ppa0               :
+!>       - dn_ppa1               :
+!>       - dn_ppa2               : 
+!>       - dn_ppkth              :
+!>       - dn_ppkth2             :
+!>       - dn_ppacr              :
+!>       - dn_ppacr2             :
+!>       - dn_ppdzmin            :
+!>       - dn_pphmax             :
+!>       - in_nlevel             : number of vertical level
+!>
+!>    * _partial step namelist (namzps)_:<br/>
+!>       - dn_e3zps_mi           :
+!>       - dn_e3zps_rat          : 
+!>
+!>    * _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
+!>
+!>                requests must be separated by ';'.<br/>
+!>                order of requests does not matter.
+!>
+!>          informations about available method could be find in @ref interp,
+!>          @ref extrap and @ref filter.<br/>
+!>
+!>          Example: 'votemper:linear;hann;dist_weight', 'vosaline:cubic'
+!>          @note 
+!>             If you do not specify a method which is required, 
+!>             default one is apply.
+!>       - cn_varfile : list of variable, and corresponding file<br/> 
+!>          *cn_varfile* is the path and filename of the file where find
+!>          variable.<br/> 
+!>          @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$
+!>          @warning 
+!>             the same matrix is used for all boundaries.
+!>
+!>       Examples: 
+!>          - 'votemper:gridT.nc', 'vozocrtx:gridU.nc'
+!>          - 'votemper:10\25', 'vozocrtx:gridU.nc'
+!>
+!>    * _nesting namelist (namnst)_:<br/>
+!>       - in_rhoi  : refinement factor in i-direction
+!>       - in_rhoj  : refinement factor in j-direction
+!>
+!>    * _boundary namelist (nambdy)_:<br/>
+!>       - ln_north  : use north boundary
+!>       - ln_south  : use south boundary
+!>       - ln_east   : use east  boundary
+!>       - ln_west   : use west  boundary
+!>       - cn_north  : north boundary indices on fine grid
+!>          *cn_north* is a string character defining boundary
+!>          segmentation.<br/>
+!>          segments are separated by '|'.<br/>
+!>          each segments of the boundary is composed of:
+!>             - orthogonal indice (.ie. for north boundary,
+!>             J-indice where boundary are). 
+!>             - first indice of boundary (I-indice for north boundary) 
+!>             - last  indice of boundary (I-indice for north boundary)<br/>
+!>                indices must be separated by ',' .<br/>
+!>             - optionally, boundary size could be added between '(' and ')' 
+!>             in the first segment defined.
+!>                @note 
+!>                   boundary width is the same for all segments of one boundary.
+!>
+!>          Examples:
+!>             - cn_north='index1,first1,last1(width)'
+!>             - cn_north='index1(width),first1,last1|index2,first2,last2'
+!>
+!>          \image html  boundary_50.png 
+!>          \image latex boundary_50.png
+!>
+!>       - cn_south  : south boundary indices on fine grid
+!>       - cn_east   : east  boundary indices on fine grid
+!>       - cn_west   : west  boundary indices on fine grid
+!>       - ln_oneseg : use only one segment for each boundary or not
+!>       - in_extrap : number of mask point to be extrapolated
+!>
+!>   * _output namelist (namout)_:<br/>
+!>       - cn_fileout : fine grid boundary basename
+!>         (cardinal and segment number will be automatically added)
+!>
+!> @author J.Paul
 ! REVISION HISTORY:
-!> @date Nov, 2013 - Initial Version
-!
+!> @date November, 2013 - Initial Version
+!> @date September, 2014
+!> - add header for user
+!> - take into account grid point to compue boundaries
+!> - reorder output dimension for north and south boundaries 
+!>
 !> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-!>
-!> @todo
 !----------------------------------------------------------------------
-!> @code
 PROGRAM create_boundary
 
@@ -57,9 +206,11 @@
    CHARACTER(LEN=lc)                                  :: cl_bdyout
    CHARACTER(LEN=lc)                                  :: cl_data
+   CHARACTER(LEN=lc)                                  :: cl_dimorder
+   CHARACTER(LEN=lc)                                  :: cl_point
+   CHARACTER(LEN=lc)                                  :: cl_fmt
 
    INTEGER(i4)                                        :: il_narg
    INTEGER(i4)                                        :: il_status
    INTEGER(i4)                                        :: il_fileid
-   INTEGER(i4)                                        :: il_attid
    INTEGER(i4)                                        :: il_dim
    INTEGER(i4)                                        :: il_imin0
@@ -67,35 +218,23 @@
    INTEGER(i4)                                        :: il_jmin0
    INTEGER(i4)                                        :: il_jmax0
+   INTEGER(i4)                                        :: il_shift
    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
 
    LOGICAL                                            :: ll_exist
-
-   TYPE(TFILE)                                        :: tl_coord0
-   TYPE(TFILE)                                        :: tl_bathy0
-   TYPE(TFILE)                                        :: tl_coord1
-   TYPE(TFILE)                                        :: tl_bathy1
-   TYPE(TFILE)                                        :: tl_file
-   TYPE(TFILE)                                        :: tl_fileout
-   
-   TYPE(TMPP)                                         :: tl_mpp
-
-   TYPE(TMULTI)                                       :: tl_multi
 
    TYPE(TATT)                                         :: tl_att
    
+   TYPE(TVAR)                                         :: tl_depth   
+   TYPE(TVAR)                                         :: tl_time
+   TYPE(TVAR)                                         :: tl_var1
+   TYPE(TVAR)                                         :: tl_var0
+   TYPE(TVAR)                                         :: tl_lon1
+   TYPE(TVAR)                                         :: tl_lat1
+   TYPE(TVAR)                                         :: tl_lvl1  
    TYPE(TVAR)       , DIMENSION(:)      , ALLOCATABLE :: tl_level
    TYPE(TVAR)       , DIMENSION(:,:,:)  , ALLOCATABLE :: tl_seglvl1
-   TYPE(TVAR)                                         :: tl_var1
    TYPE(TVAR)       , DIMENSION(:,:,:)  , ALLOCATABLE :: tl_segvar1
-   TYPE(TVAR)       , DIMENSION(:,:)    , ALLOCATABLE :: tl_seglon1
-   TYPE(TVAR)       , DIMENSION(:,:)    , ALLOCATABLE :: tl_seglat1
-   TYPE(TVAR)       , DIMENSION(:,:)    , ALLOCATABLE :: tl_var
-   TYPE(TVAR)       , DIMENSION(:)      , ALLOCATABLE :: tl_lon1
-   TYPE(TVAR)       , DIMENSION(:)      , ALLOCATABLE :: tl_lat1
-   TYPE(TVAR)                                         :: tl_depth   
-   TYPE(TVAR)                                         :: tl_time
-   TYPE(TVAR)                                         :: tl_tmp   
 
    TYPE(TDIM)       , DIMENSION(ip_maxdim)            :: tl_dim
@@ -104,8 +243,19 @@
    
    TYPE(TDOM)                                         :: tl_dom0
-   TYPE(TDOM)       , DIMENSION(:,:)    , ALLOCATABLE :: tl_segdom1
+   TYPE(TDOM)                                         :: tl_dom1
+   TYPE(TDOM)       , DIMENSION(:,:,:)  , ALLOCATABLE :: tl_segdom1
+
+   TYPE(TFILE)                                        :: tl_fileout
+   
+   TYPE(TMPP)                                         :: tl_coord0
+   TYPE(TMPP)                                         :: tl_coord1
+   TYPE(TMPP)                                         :: tl_bathy1
+   TYPE(TMPP)                                         :: tl_mpp
+
+   TYPE(TMULTI)                                       :: tl_multi
 
    ! loop indices
    INTEGER(i4) :: jvar
+   INTEGER(i4) :: jpoint
    INTEGER(i4) :: ji
    INTEGER(i4) :: jj
@@ -117,4 +267,8 @@
    CHARACTER(LEN=lc)                       :: cn_logfile = 'create_boundary.log' 
    CHARACTER(LEN=lc)                       :: cn_verbosity = 'warning' 
+   INTEGER(i4)                             :: in_maxerror = 5
+
+   ! namcfg
+   CHARACTER(LEN=lc)                       :: cn_varcfg = 'variable.cfg' 
 
    ! namcrs
@@ -127,18 +281,14 @@
    INTEGER(i4)                             :: in_perio1 = -1
 
-   ! namcfg
-   CHARACTER(LEN=lc)                       :: cn_varcfg = 'variable.cfg' 
+   !namzgr
+   INTEGER(i4)                             :: in_nlevel = 75
 
    ! namvar
-   CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varinfo = ''
-   CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varfile = ''
+   CHARACTER(LEN=lc), DIMENSION(ip_maxvar) :: cn_varinfo = ''
+   CHARACTER(LEN=lc), DIMENSION(ip_maxvar) :: cn_varfile = ''
 
    ! namnst
-   INTEGER(i4)                             :: in_imin0 = 0
-   INTEGER(i4)                             :: in_imax0 = 0
-   INTEGER(i4)                             :: in_jmin0 = 0
-   INTEGER(i4)                             :: in_jmax0 = 0
-   INTEGER(i4)                             :: in_rhoi  = 1
-   INTEGER(i4)                             :: in_rhoj  = 1
+   INTEGER(i4)                             :: in_rhoi  = 0
+   INTEGER(i4)                             :: in_rhoj  = 0
 
    ! nambdy
@@ -160,5 +310,6 @@
    NAMELIST /namlog/ &  !< logger namelist
    &  cn_logfile,    &  !< log file
-   &  cn_verbosity      !< log verbosity
+   &  cn_verbosity,  &  !< log verbosity
+   &  in_maxerror
 
    NAMELIST /namcfg/ &  !< config namelist
@@ -174,4 +325,7 @@
    &  in_perio1         !< periodicity index
  
+   NAMELIST /namzgr/ &
+   &  in_nlevel
+
    NAMELIST /namvar/ &  !< variable namelist
    &  cn_varinfo,    &  !< list of variable and method to apply on. (ex: 'votemper:linear','vosaline:cubic' )
@@ -179,8 +333,4 @@
    
    NAMELIST /namnst/ &  !< nesting namelist
-   &  in_imin0,      &  !< i-direction lower left  point indice on coarse grid 
-   &  in_imax0,      &  !< i-direction upper right point indice on coarse grid
-   &  in_jmin0,      &  !< j-direction lower left  point indice on coarse grid
-   &  in_jmax0,      &  !< j-direction upper right point indice on coarse grid
    &  in_rhoi,       &  !< refinement factor in i-direction
    &  in_rhoj           !< refinement factor in j-direction
@@ -196,5 +346,5 @@
    &  cn_west ,      &  !< west  boundary indices on fine grid
    &  ln_oneseg,     &  !< use only one segment for each boundary or not
-   &  in_extrap         !< number of mask point to extrapolate
+   &  in_extrap         !< number of mask point to be extrapolated
 
    NAMELIST /namout/ &  !< output namelist
@@ -202,6 +352,6 @@
    !-------------------------------------------------------------------
 
-   !1- namelist
-   !1-1 get namelist
+   ! namelist
+   ! get namelist
    il_narg=COMMAND_ARGUMENT_COUNT() !f03 intrinsec
    IF( il_narg/=1 )THEN
@@ -212,5 +362,5 @@
    ENDIF
    
-   !1-2 read namelist
+   ! read namelist
    INQUIRE(FILE=TRIM(cl_namelist), EXIST=ll_exist)
    IF( ll_exist )THEN
@@ -231,23 +381,23 @@
 
       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))
 
       READ( il_fileid, NML = namcrs )
       READ( il_fileid, NML = namfin )
+      READ( il_fileid, NML = namzgr )
       READ( il_fileid, NML = namvar )
-      !1-2-3 add user change in extra information
+      ! add user change in extra information
       CALL var_chg_extra(cn_varinfo)
-      !1-2-4 match variable with file
+      ! match variable with file
       tl_multi=multi_init(cn_varfile)
 
       READ( il_fileid, NML = namnst )
       READ( il_fileid, NML = nambdy )
-
       READ( il_fileid, NML = namout )
 
@@ -261,11 +411,18 @@
 
       PRINT *,"CREATE BOUNDARY: ERROR. can not find "//TRIM(cl_namelist)
+      STOP
 
    ENDIF
 
-   !2- open files
+   CALL multi_print(tl_multi)
+   IF( tl_multi%i_nvar <= 0 )THEN
+      CALL logger_fatal("CREATE BOUNDARY: no variable to be used."//&
+      &  " check namelist.")
+   ENDIF
+
+   ! open files
    IF( TRIM(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 BOUNDARY: can not find coarse grid "//&
@@ -274,6 +431,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 BOUNDARY: can not find fine grid coordinate "//&
@@ -282,6 +439,6 @@
 
    IF( TRIM(cn_bathy1) /= '' )THEN
-      tl_bathy1=file_init(TRIM(cn_bathy1),id_perio=in_perio1)
-      CALL iom_open(tl_bathy1)
+      tl_bathy1=mpp_init( file_init(TRIM(cn_bathy1)), id_perio=in_perio1)
+      CALL grid_get_info(tl_bathy1)
    ELSE
       CALL logger_fatal("CREATE BOUNDARY: can not find fine grid bathymetry "//&
@@ -289,9 +446,9 @@
    ENDIF
 
-   !3- check
-   !3-1 check output file do not already exist
+   ! check
+   ! check output file do not already exist
    DO jk=1,ip_ncard
       cl_bdyout=boundary_set_filename( TRIM(cn_fileout), &
-      &                                TRIM(ip_card(jk)) )
+      &                                TRIM(cp_card(jk)), 1 )
       INQUIRE(FILE=TRIM(cl_bdyout), EXIST=ll_exist)
       IF( ll_exist )THEN
@@ -301,6 +458,6 @@
    ENDDO
 
-   !3-1 check namelist
-   !3-1-1 check refinement factor
+   ! check namelist
+   ! check refinement factor
    il_rho(:)=1
    IF( in_rhoi < 1 .OR. in_rhoj < 1 )THEN
@@ -312,20 +469,16 @@
    ENDIF
 
-   !3-1-2
-   IF( in_imin0 < 1 .OR. in_imax0 < 1 .OR. in_jmin0 < 1 .OR. in_jmax0 < 1)THEN
-      ! compute coarse grid indices around fine grid
-      il_ind(:,:,:)=grid_get_coarse_index(tl_bathy0, tl_bathy1 )
-
-      il_imin0=il_ind(1,1,1) ; il_imax0=il_ind(1,2,1)
-      il_jmin0=il_ind(2,1,1) ; il_jmax0=il_ind(2,2,1)
-   ELSE
-      il_imin0=in_imin0 ; il_imax0=in_imax0
-      il_jmin0=in_jmin0 ; il_jmax0=in_jmax0
-   ENDIF
-
-   !3-2 check domain validity
+   !
+   ! 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(1,1) ; il_imax0=il_ind(1,2)
+   il_jmin0=il_ind(2,1) ; il_jmax0=il_ind(2,2)
+
+   ! check domain validity
    CALL grid_check_dom(tl_coord0, il_imin0, il_imax0, il_jmin0, il_jmax0)
 
-   !3-3 check coordinate file
+   ! check coordinate file
    CALL grid_check_coincidence( tl_coord0, tl_coord1, &
    &                            il_imin0, il_imax0, &
@@ -333,6 +486,12 @@
    &                            il_rho(:) )      
 
-   !4- read or compute boundary
-   tl_var1=iom_read_var(tl_bathy1,'Bathymetry')
+   ! read or compute boundary
+   CALL mpp_get_contour(tl_bathy1)
+
+   CALL iom_mpp_open(tl_bathy1)
+   
+   tl_var1=iom_mpp_read_var(tl_bathy1,'Bathymetry')
+   
+   CALL iom_mpp_close(tl_bathy1)
 
    tl_bdy(:)=boundary_init(tl_var1, ln_north, ln_south, ln_east, ln_west, &
@@ -342,25 +501,30 @@
    CALL var_clean(tl_var1)
 
-   !5- compute level
-   ALLOCATE(tl_level(ig_npoint))
+   ! compute level
+   ALLOCATE(tl_level(ip_npoint))
    tl_level(:)=vgrid_get_level(tl_bathy1, cl_namelist )
 
-   !6- get coordinate on each segment of each boundary
-   ALLOCATE( tl_seglon1(ip_ncard,ig_maxseg) )
-   ALLOCATE( tl_seglat1(ip_ncard,ig_maxseg) )
-   ALLOCATE( tl_segdom1(ip_ncard,ig_maxseg) )
-   ALLOCATE( tl_segvar1(tl_multi%i_nvar,ip_ncard,ig_maxseg) )
-   ALLOCATE( tl_seglvl1(ip_ncard,ig_maxseg,ig_npoint) )
-   DO jk=1,ip_ncard
-      IF( tl_bdy(jk)%l_use )THEN
-         DO jl=1,tl_bdy(jk)%i_nseg
-            !6-1 get fine grid segment domain
-            tl_segdom1(jk,jl)=create_boundary_get_dom( tl_bathy1, tl_bdy(jk), jl )
-
-            !6-2 get fine grid segment coordinate
-            CALL create_boundary_get_coord( tl_bathy1, tl_segdom1(jk,jl), &
-            &                               tl_seglon1(jk,jl), tl_seglat1(jk,jl) )
-            !6-2 get fine grid segment coordinate
-            tl_seglvl1(jk,jl,:)=create_bdy_get_level(tl_level(:), tl_segdom1(jk,jl))
+   ! get coordinate on each segment of each boundary
+   ALLOCATE( tl_segdom1(ip_npoint,ip_maxseg,ip_ncard) )
+   ALLOCATE( tl_seglvl1(ip_npoint,ip_maxseg,ip_ncard) )
+   
+   DO jl=1,ip_ncard
+      IF( tl_bdy(jl)%l_use )THEN
+         DO jk=1,tl_bdy(jl)%i_nseg
+
+            ! get fine grid segment domain
+            tl_segdom1(:,jk,jl)=create_boundary_get_dom( tl_bathy1, &
+            &                                            tl_bdy(jl), jk )
+
+            ! add extra band to fine grid domain (if possible)
+            ! to avoid dimension of one and so be able to compute offset
+            DO jj=1,ip_npoint
+               CALL dom_add_extra(tl_segdom1(jj,jk,jl), &
+               &                  il_rho(jp_I), il_rho(jp_J))
+            ENDDO
+
+            ! get fine grid level
+            tl_seglvl1(:,jk,jl)=create_boundary_get_level( tl_level(:), &
+                                                           tl_segdom1(:,jk,jl))
 
          ENDDO
@@ -368,253 +532,370 @@
    ENDDO
 
+   ! clean
+   CALL var_clean(tl_level(:))
    DEALLOCATE(tl_level)
 
-   !7- compute boundary for variable to be used (see namelist)
-   IF( .NOT. ASSOCIATED(tl_multi%t_file) )THEN
+   ! clean bathy
+   CALL mpp_clean(tl_bathy1)
+
+   ALLOCATE( tl_segvar1(tl_multi%i_nvar,ip_maxseg,ip_ncard) )
+   ! compute boundary for variable to be used (see namelist)
+   IF( .NOT. ASSOCIATED(tl_multi%t_mpp) )THEN
       CALL logger_error("CREATE BOUNDARY: no file to work on. "//&
       &                 "check cn_varfile in namelist.")
    ELSE
+
       jvar=0
       ! for each file
-      DO ji=1,tl_multi%i_nfile
-         WRITE(cl_data,'(a,i2.2)') 'data_',jvar+1
-
-         IF( .NOT. ASSOCIATED(tl_multi%t_file(ji)%t_var) )THEN
+      DO ji=1,tl_multi%i_nmpp
+
+         WRITE(cl_data,'(a,i2.2)') 'data-',jvar+1
+
+         IF( .NOT. ASSOCIATED(tl_multi%t_mpp(ji)%t_proc(1)%t_var) )THEN
+
             CALL logger_error("CREATE BOUNDARY: no variable to work on for "//&
-            &                 "file "//TRIM(tl_multi%t_file(ji)%c_name)//&
+            &                 "mpp "//TRIM(tl_multi%t_mpp(ji)%c_name)//&
             &                 ". check cn_varfile in namelist.")
+
+         ELSEIF( TRIM(tl_multi%t_mpp(ji)%c_name) == TRIM(cl_data) )THEN
+         !- use input matrix to fill variable
+
+            WRITE(*,'(a)') "work on data"
+            ! for each variable initialise from matrix
+            DO jj=1,tl_multi%t_mpp(ji)%t_proc(1)%i_nvar
+
+               jvar=jvar+1
+               WRITE(*,'(2x,a,a)') "work on variable "//&
+               &  TRIM(tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj)%c_name)
+
+               tl_var1=var_copy(tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj))
+
+               SELECT CASE(TRIM(tl_var1%c_point))
+               CASE DEFAULT !'T'
+                  jpoint=jp_T
+               CASE('U')
+                  jpoint=jp_U
+               CASE('V')
+                  jpoint=jp_V
+               CASE('F')
+                  jpoint=jp_F
+               END SELECT
+
+               WRITE(*,'(4x,a,a)') 'work on '//TRIM(tl_var1%c_name)
+               DO jl=1,ip_ncard
+                  IF( tl_bdy(jl)%l_use )THEN
+
+                     DO jk=1,tl_bdy(jl)%i_nseg
+
+                        ! fill value with matrix data
+                        tl_segvar1(jvar,jk,jl)=create_boundary_matrix( &
+                        &                          tl_var1, &
+                        &                          tl_segdom1(jpoint,jk,jl), &
+                        &                          in_nlevel )
+
+                        ! use mask
+                        CALL create_boundary_use_mask( tl_segvar1(jvar,jk,jl), &
+                        &                         tl_seglvl1(jpoint,jk,jl))
+
+                        !del extra
+                        CALL dom_del_extra( tl_segvar1(jvar,jk,jl), &
+                        &                   tl_segdom1(jpoint,jk,jl) )
+
+                     ENDDO
+
+                  ENDIF
+               ENDDO
+               
+               ! clean
+               CALL var_clean(tl_var1)
+
+            ENDDO
+
+         !- end of use input matrix to fill variable
          ELSE
-            IF( .NOT. ASSOCIATED(tl_multi%t_file(ji)%t_var) )THEN
-
-               CALL logger_error("CREATE BOUNDARY: no variable to work on for "//&
-               &                 "file "//TRIM(tl_multi%t_file(ji)%c_name)//&
-               &                 ". check cn_varfile in namelist.")
-
-            ELSEIF( TRIM(tl_multi%t_file(ji)%c_name) == TRIM(cl_data) )THEN
-            !- use input matrix to fill variable
-
-               ! for each variable initialise from matrix
-               DO jj=1,tl_multi%t_file(ji)%i_nvar
-                  jvar=jvar+1
-                  tl_tmp=tl_multi%t_file(ji)%t_var(jj)
-                  DO jk=1,ip_ncard
-                     IF( tl_bdy(jk)%l_use )THEN
-                        DO jl=1,tl_bdy(jk)%i_nseg
-                           !7-1 fill value with matrix data
-                           ! pb voir comment gerer nb de dimension
-                           tl_segvar1(jvar,jk,jl)=create_bdy_matrix(tl_tmp, tl_segdom1(jk,jl), tl_coord1)
-
-                           !7-2 use mask
-                           CALL create_bdy_use_mask(tl_segvar1(jvar,jk,jl), tl_seglvl1(jk,jl,:))
-                        ENDDO
-                     ENDIF
-                  ENDDO
-               ENDDO
-
+         !- use file to fill variable
+
+            WRITE(*,'(a)') "work on file "//TRIM(tl_multi%t_mpp(ji)%c_name)
+            ! 
+            tl_mpp=mpp_init(file_init(TRIM(tl_multi%t_mpp(ji)%t_proc(1)%c_name)))
+            CALL grid_get_info(tl_mpp)
+
+            ! check vertical dimension
+            IF( tl_mpp%t_dim(jp_K)%l_use .AND. &
+            &   tl_mpp%t_dim(jp_K)%i_len /= in_nlevel  )THEN
+               CALL logger_error("CREATE BOUNDARY: dimension in file "//&
+               &  TRIM(tl_mpp%c_name)//" not agree with namelist in_nlevel ")
+            ENDIF
+
+            ! open mpp file
+            CALL iom_mpp_open(tl_mpp)
+
+            ! get or check depth value
+            CALL create_boundary_check_depth( tl_mpp, tl_depth )
+
+            ! get or check time value
+            CALL create_boundary_check_time( tl_mpp, tl_time )
+
+            ! 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 value from fine grid
+
+               IF( ANY( tl_mpp%t_dim(1:2)%i_len <= &
+               &        tl_coord1%t_dim(1:2)%i_len) )THEN
+                  CALL logger_fatal("CREATE BOUNDARY: dimension in file "//&
+                  &  TRIM(tl_mpp%c_name)//" smaller than those in fine"//&
+                  &  " grid coordinates.")
+               ENDIF
+
+               DO jl=1,ip_ncard
+                  IF( tl_bdy(jl)%l_use )THEN
+                     
+                     WRITE(*,'(2x,a,a)') 'work on '//TRIM(tl_bdy(jl)%c_card)//' boundary'
+                     DO jk=1,tl_bdy(jl)%i_nseg
+                        ! compute domain on fine grid
+                        
+                        ! for each variable of this file
+                        DO jj=1,tl_multi%t_mpp(ji)%t_proc(1)%i_nvar
+                           
+                           cl_name=tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj)%c_name
+                           WRITE(*,'(4x,a,a)') "work on variable "//TRIM(cl_name)
+
+                           cl_point=tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj)%c_point
+                           ! open mpp file on domain
+                           SELECT CASE(TRIM(cl_point))
+                              CASE DEFAULT !'T'
+                                 jpoint=jp_T
+                              CASE('U')
+                                 jpoint=jp_U
+                              CASE('V')
+                                 jpoint=jp_V
+                              CASE('F')
+                                 jpoint=jp_F
+                           END SELECT
+
+                           tl_dom1=dom_copy(tl_segdom1(jpoint,jk,jl))
+                           tl_lvl1=var_copy(tl_seglvl1(jpoint,jk,jl))
+
+                           ! open mpp files
+                           CALL iom_dom_open(tl_mpp, tl_dom1)
+
+                           !7-5 read variable over domain
+                           tl_segvar1(jvar+jj,jk,jl)=iom_dom_read_var( &
+                           &                     tl_mpp, TRIM(cl_name), tl_dom1)
+
+                           ! use mask
+                           CALL create_boundary_use_mask( &
+                           &                 tl_segvar1(jvar+jj,jk,jl), tl_lvl1)
+
+                           ! del extra point
+                           CALL dom_del_extra( tl_segvar1(jvar+jj,jk,jl), &
+                           &                   tl_dom1 )
+
+                           ! clean extra point information on fine grid domain
+                           CALL dom_clean_extra( tl_dom1 )
+
+                           ! add attribute to variable
+                           tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name)))
+                           CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
+
+                           tl_att=att_init('src_i_indices',(/tl_dom1%i_imin, tl_dom1%i_imax/))
+                           CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
+
+                           tl_att=att_init('src_j_indices',(/tl_dom1%i_jmin, tl_dom1%i_jmax/))
+                           CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
+
+                           ! clean structure
+                           CALL att_clean(tl_att)
+                           CALL dom_clean(tl_dom1)
+
+                           ! close mpp files
+                           CALL iom_dom_close(tl_mpp)
+
+                           ! clean
+                           CALL var_clean(tl_lvl1)
+
+                        ENDDO ! jj
+                     ENDDO ! jk
+
+                  ENDIF
+               ENDDO ! jl
+
+               ! clean
+               CALL mpp_clean(tl_mpp)
+
+               jvar=jvar+tl_multi%t_mpp(ji)%t_proc(1)%i_nvar
+
+            !- end of extract value from fine grid
             ELSE
-            !- use file to fill variable
-
-               ! open file
-               tl_file=file_init(TRIM(tl_multi%t_file(ji)%c_name))
-               CALL iom_open(tl_file)
-
-               ! get or check depth value
-               IF( tl_file%i_depthid /= 0 )THEN
-                  IF( ASSOCIATED(tl_depth%d_value) )THEN
-                     IF( ANY( tl_depth%d_value(:,:,:,:) /= &
-                     &        tl_tmp%d_value(:,:,:,:) ) )THEN
-                        CALL logger_fatal("CREATE BOUNDARY: depth value from "//&
-                        &  TRIM(tl_multi%t_file(ji)%c_name)//" not conform "//&
-                        &  " to those from former file(s).")
-                     ENDIF
-                  ELSE
-                     tl_depth=iom_read_var(tl_file,tl_file%i_depthid)
-                  ENDIF
-               ENDIF
-
-               ! get or check time value
-               IF( tl_file%i_timeid /= 0 )THEN
-                  IF( ASSOCIATED(tl_time%d_value) )THEN
-                     IF( ANY( tl_time%d_value(:,:,:,:) /= &
-                     &        tl_tmp%d_value(:,:,:,:) ) )THEN
-                        CALL logger_fatal("CREATE BOUNDARY: time value from "//&
-                        &  TRIM(tl_multi%t_file(ji)%c_name)//" not conform "//&
-                        &  " to those from former file(s).")
-                     ENDIF
-                  ELSE
-                     tl_time=iom_read_var(tl_file,tl_file%i_timeid)
-                  ENDIF
-               ENDIF
-
-               IF( ANY( tl_file%t_dim(1:2)%i_len /= &
-               &      tl_coord0%t_dim(1:2)%i_len) )THEN
-               !- extract value from fine grid
-                  DO jk=1,ip_ncard
-                     IF( tl_bdy(jk)%l_use )THEN
-
-                        DO jl=1,tl_bdy(jk)%i_nseg
-                           !7-1 compute domain on fine grid
+            !- interpolate value from coarse grid
+
+               DO jl=1,ip_ncard
+                  IF( tl_bdy(jl)%l_use )THEN
+
+                     WRITE(*,'(2x,a,a)') 'work on '//TRIM(tl_bdy(jl)%c_card)//' boundary'
+                     DO jk=1,tl_bdy(jl)%i_nseg
+                        
+                        ! for each variable of this file
+                        DO jj=1,tl_multi%t_mpp(ji)%t_proc(1)%i_nvar
                            
+                           WRITE(*,'(4x,a,a)') "work on variable "//&
+                           &  TRIM(tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj)%c_name)
+
+                           tl_var0=var_copy(tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj))
                            ! open mpp file on domain
-                           !7-2 init mpp structure
-                           tl_mpp=mpp_init(tl_file)
-
-                           !7-3 get processor to be used
-                           CALL mpp_get_use( tl_mpp, tl_segdom1(jk,jl) )
-                           !7-4 open mpp files
-                           CALL iom_mpp_open(tl_mpp)
-
-                           ! for each variable of this file
-                           DO jj=1,tl_multi%t_file(ji)%i_nvar
-                              
-                              cl_name=tl_multi%t_file(ji)%t_var(jj)%c_name
-                              !7-5 read variable over domain
-                              tl_segvar1(jvar+jj,jk,jl)=iom_mpp_read_var( tl_mpp, TRIM(cl_name), &
-                              &                                           td_dom=tl_segdom1(jk,jl) )
-
-                              !7-6 add attribute to variable
-                              tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name)))
-                              CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
-
-                              tl_att=att_init('src_i-indices',(/tl_segdom1(jk,jl)%i_imin, tl_segdom1(jk,jl)%i_imax/))
-                              CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
-
-                              tl_att=att_init('src_j-indices',(/tl_segdom1(jk,jl)%i_jmin, tl_segdom1(jk,jl)%i_jmax/))
-                              CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
-                              
-                              ! clean structure
-                              CALL att_clean(tl_att)
-
-                              !7-7 use mask
-                              CALL create_bdy_use_mask(tl_segvar1(jvar+jj,jk,jl), tl_seglvl1(jk,jl,:))
-                           ENDDO
-                           
-                           !7-8 close mpp files
-                           CALL iom_mpp_close(tl_mpp)
-
-                           CALL mpp_clean(tl_mpp)
-
-                        ENDDO
-                     ENDIF
-                  ENDDO
-                  jvar=jvar+tl_multi%t_file(ji)%i_nvar
-               ELSE
-               !- interpolate value from coarse grid
-
-                  DO jk=1,ip_ncard
-                     IF( tl_bdy(jk)%l_use )THEN
-
-                        DO jl=1,tl_bdy(jk)%i_nseg
-                           !7-1 get coarse grid indices of this segment
-                           il_ind(:,:,:)=grid_get_coarse_index(tl_coord0, &
-                           &                                   tl_seglon1(jk,jl), tl_seglat1(jk,jl), &
-                           &                                   id_rho=il_rho(:) )
-
-                           IF( ANY(il_ind(:,:,:)==0) )THEN
-                              CALL logger_error("CREATE BOUNDARY: error computing "//&
-                              &                 " coarse grid indices")
+                           SELECT CASE(TRIM(tl_var0%c_point))
+                              CASE DEFAULT !'T'
+                                 jpoint=jp_T
+                              CASE('U')
+                                 jpoint=jp_U
+                              CASE('V')
+                                 jpoint=jp_V
+                              CASE('F')
+                                 jpoint=jp_F
+                           END SELECT
+
+                           tl_dom1=dom_copy(tl_segdom1(jpoint,jk,jl))
+                           tl_lvl1=var_copy(tl_seglvl1(jpoint,jk,jl))
+
+                           CALL create_boundary_get_coord( tl_coord1, tl_dom1, &
+                           &                               tl_var0%c_point,    &
+                           &                               tl_lon1, tl_lat1 )
+
+                           ! get coarse grid indices of this segment
+                           il_ind(:,:)=grid_get_coarse_index(tl_coord0, &
+                           &                                 tl_lon1, tl_lat1, &
+                           &                                 id_rho=il_rho(:) )
+
+                           IF( ANY(il_ind(:,:)==0) )THEN
+                              CALL logger_error("CREATE BOUNDARY: error "//&
+                              &  "computing coarse grid indices")
                            ELSE
-                              il_imin0=il_ind(1,1,1)
-                              il_imax0=il_ind(1,2,1)
-
-                              il_jmin0=il_ind(2,1,1)
-                              il_jmax0=il_ind(2,2,1)
-
-                              il_offset(:,:)=il_ind(:,:,2)
+                              il_imin0=il_ind(1,1)
+                              il_imax0=il_ind(1,2)
+
+                              il_jmin0=il_ind(2,1)
+                              il_jmax0=il_ind(2,2)
                            ENDIF
 
-                           !7-2 compute coarse grid segment domain
+                           il_offset(:,:)= grid_get_fine_offset( &
+                           &                    tl_coord0, &
+                           &                    il_imin0, il_jmin0,&
+                           &                    il_imax0, il_jmax0,&
+                           &                    tl_lon1%d_value(:,:,1,1),&
+                           &                    tl_lat1%d_value(:,:,1,1),&
+                           &                    il_rho(:),&
+                           &                    TRIM(tl_var0%c_point) )
+
+                           ! compute coarse grid segment domain
                            tl_dom0=dom_init( tl_coord0,         &
                            &                 il_imin0, il_imax0,&
                            &                 il_jmin0, il_jmax0 )
 
-                           !7-3 add extra band (if possible) to compute interpolation
+                           ! add extra band (if possible) to compute interpolation
                            CALL dom_add_extra(tl_dom0)
 
-                           !7-4 read variables on domain (ugly way to do it, have to work on it)
-                           !7-4-1 init mpp structure
-                           tl_mpp=mpp_init(tl_file)
- 
-                           !7-4-2 get processor to be used
-                           CALL mpp_get_use( tl_mpp, tl_dom0 )
-
-                           !7-4-3 open mpp files
-                           CALL iom_mpp_open(tl_mpp)
-
-                           ! check file dimension
-                           IF( ANY(tl_mpp%t_dim(1:2)%i_len /= tl_coord0%t_dim(1:2)%i_len) )THEN
-                              CALL logger_error("CREATE BOUNDARY INTERP: dimension of file "//&
-                              &  TRIM(tl_mpp%c_name)//" not conform to those of "//&
-                              &  TRIM(tl_coord0%c_name))
-                           ELSE
-
-                              ! for each variable of this file
-                              DO jj=1,tl_multi%t_file(ji)%i_nvar
-
-                                 cl_name=tl_multi%t_file(ji)%t_var(jj)%c_name
-                                 !7-4-4 read variable value on domain
-                                 tl_segvar1(jvar+jj,jk,jl)=iom_mpp_read_var( tl_mpp, TRIM(cl_name), &
-                                 &                                           td_dom=tl_dom0 )
-
-                                 !7-4-5 work on variable
-                                 CALL create_boundary_interp(tl_segvar1(jvar+jj,jk,jl), &
-                                 &                           il_rho(:), &
-                                 &                           il_offset(:,:) )
-
-                                 !7-4-6 remove extraband added to domain
-                                 CALL dom_del_extra( tl_segvar1(jvar+jj,jk,jl), tl_dom0, il_rho(:) )
-
-                                 !7-4-7 keep only useful point (width) 
-                                 ! interpolation could create more point than necessary
-                                 CALL boundary_clean_interp(tl_segvar1(jvar+jj,jk,jl), tl_bdy(jk) )
-
-                                 !7-4-8 add attribute to variable
-                                 tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name)))
-                                 CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
-
-                                 tl_att=att_init('src_i-indices',(/tl_dom0%i_imin, tl_dom0%i_imax/))
-                                 CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
-
-                                 tl_att=att_init('src_j-indices',(/tl_dom0%i_jmin, tl_dom0%i_jmax/))
-                                 CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), tl_att)
-
-                                 ! clean structure
-                                 CALL att_clean(tl_att)
-
-                                 !7-4-9 use mask
-                                 CALL create_bdy_use_mask(tl_segvar1(jvar+jj,jk,jl), tl_seglvl1(jk,jl,:))
-                              ENDDO
+                           ! read variables on domain 
+                           ! open mpp files
+                           CALL iom_dom_open(tl_mpp, tl_dom0)
+
+                           cl_name=tl_var0%c_name
+                           ! read variable value on domain
+                           tl_segvar1(jvar+jj,jk,jl)= &
+                           &    iom_dom_read_var(tl_mpp, TRIM(cl_name), tl_dom0)
+
+                           ! work on variable
+                           CALL create_boundary_interp( &
+                           &                 tl_segvar1(jvar+jj,jk,jl),&
+                           &                 il_rho(:), il_offset(:,:) )
+
+                           ! remove extraband added to domain
+                           CALL dom_del_extra( tl_segvar1(jvar+jj,jk,jl), &
+                           &                   tl_dom0, il_rho(:) )
+
+                           ! use mask
+                           CALL create_boundary_use_mask( &
+                           &     tl_segvar1(jvar+jj,jk,jl), tl_lvl1)
+
+                           ! del extra point on fine grid
+                           CALL dom_del_extra( tl_segvar1(jvar+jj,jk,jl), &
+                           &                   tl_dom1 )
+                           ! clean extra point information on coarse grid domain
+                           CALL dom_clean_extra( tl_dom0 )
+
+                           ! add attribute to variable
+                           tl_att=att_init('src_file',&
+                           &  TRIM(fct_basename(tl_mpp%c_name)))
+                           CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), &
+                           &                 tl_att)
+
+                           ! use clean extra avt creer attribut
+                           tl_att=att_init('src_i-indices',&
+                           &  (/tl_dom0%i_imin, tl_dom0%i_imax/))
+                           CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), &
+                           &                 tl_att)
+
+                           tl_att=att_init('src_j-indices', &
+                           &  (/tl_dom0%i_jmin, tl_dom0%i_jmax/))
+                           CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), &
+                           &                 tl_att)
+
+                           IF( ANY(il_rho(:)/=1) )THEN
+                              tl_att=att_init("refinment_factor", &
+                              &               (/il_rho(jp_I),il_rho(jp_J)/))
+                              CALL var_move_att(tl_segvar1(jvar+jj,jk,jl), &
+                              &                 tl_att)
                            ENDIF
 
+                           ! clean structure
+                           CALL att_clean(tl_att)
+
+                           ! clean
                            CALL dom_clean(tl_dom0)
-
-                           !7-5 close mpp files
-                           CALL iom_mpp_close(tl_mpp)
-
-                           !7-6 clean structure
-                           CALL mpp_clean(tl_mpp)
-                        ENDDO
-                     ENDIF
-                  ENDDO
-                  jvar=jvar+tl_multi%t_file(ji)%i_nvar
-
-               ENDIF
-               CALL file_clean(tl_file)
-
+                           CALL dom_clean(tl_dom1)
+
+                           ! close mpp files
+                           CALL iom_dom_close(tl_mpp)
+
+                           ! clean structure
+                           CALL var_clean(tl_lon1)
+                           CALL var_clean(tl_lat1)
+                           CALL var_clean(tl_lvl1)
+
+                        ENDDO ! jj
+
+                        ! clean
+                        CALL var_clean(tl_var0)
+
+                     ENDDO ! jk
+               
+                  ENDIF
+               ENDDO ! jl
+
+               jvar=jvar+tl_multi%t_mpp(ji)%t_proc(1)%i_nvar
+
+            !- end of interpolate value from coarse grid
             ENDIF
+
+            ! clean
+            CALL mpp_clean(tl_mpp)
+
+         !- end of use file to fill variable
          ENDIF
       ENDDO
    ENDIF
+
    IF( jvar /= tl_multi%i_nvar )THEN
       CALL logger_error("CREATE BOUNDARY: it seems some variable can not be read")
    ENDIF
 
-   !8- concatenate file
-   ALLOCATE( tl_lon1(ip_ncard) )
-   ALLOCATE( tl_lat1(ip_ncard) )
-   ALLOCATE( tl_var(tl_multi%i_nvar,ip_ncard) )
-
-   DO jk=1,ip_ncard
-      IF( tl_bdy(jk)%l_use )THEN
+   CALL var_clean(tl_seglvl1(:,:,:))
+   DEALLOCATE( tl_seglvl1 )
+
+   ! write file for each segment of each boundary
+   DO jl=1,ip_ncard
+      IF( tl_bdy(jl)%l_use )THEN
 
          SELECT CASE(TRIM(tl_bdy(jk)%c_card))
@@ -625,153 +906,169 @@
          END SELECT   
 
-         DO jl=1,tl_bdy(jk)%i_nseg
-            !- concatenate variable
-            IF( jl == 1 )THEN
-               tl_lon1(jk)=tl_seglon1(jk,jl)
-               tl_lat1(jk)=tl_seglat1(jk,jl)
-               DO jvar=1,tl_multi%i_nvar
-                  tl_var(jvar,jk)=tl_segvar1(jvar,jk,jl)
-               ENDDO
+         DO jk=1,tl_bdy(jl)%i_nseg
+            !- 
+            CALL create_boundary_get_coord( tl_coord1, tl_segdom1(jp_T,jk,jl),&
+            &                               'T', tl_lon1, tl_lat1 )
+
+            ! del extra point on fine grid
+            CALL dom_del_extra( tl_lon1, tl_segdom1(jp_T,jk,jl) )
+            CALL dom_del_extra( tl_lat1, tl_segdom1(jp_T,jk,jl) )
+
+            ! clean
+            DO jpoint=1,ip_npoint
+               CALL dom_clean(tl_segdom1(jpoint,jk,jl))
+            ENDDO
+
+            ! swap array
+            CALL boundary_swap(tl_lon1, tl_bdy(jl))
+            CALL boundary_swap(tl_lat1, tl_bdy(jl))
+            DO jvar=1,tl_multi%i_nvar
+               CALL boundary_swap(tl_segvar1(jvar,jk,jl), tl_bdy(jl))
+
+               ! use additional request
+               ! forced min and max value
+               CALL var_limit_value(tl_segvar1(jvar,jk,jl))
+
+               ! filter
+               CALL filter_fill_value(tl_segvar1(jvar,jk,jl))
+
+               ! extrapolate
+               CALL extrap_fill_value( tl_segvar1(jvar,jk,jl), &
+               &                       id_iext=in_extrap,      &
+               &                       id_jext=in_extrap,      &
+               &                       id_kext=in_extrap )
+
+            ENDDO
+
+            ! create file
+            ! create file structure
+            ! set file namearray of level variable structure
+            IF( ASSOCIATED(tl_time%d_value) )THEN
+               cl_fmt="('y',i0.4,'m',i0.2,'d',i0.2)"
+               cl_date=date_print( var_to_date(tl_time), cl_fmt ) 
+
+               cl_bdyout=boundary_set_filename( TRIM(cn_fileout), &
+               &                                TRIM(tl_bdy(jl)%c_card), jk, TRIM(cl_date) )
             ELSE
-               tl_lon1(jk)=var_concat(tl_lon1(jk),tl_seglon1(jk,jl),DIM=il_dim)
-               tl_lat1(jk)=var_concat(tl_lat1(jk),tl_seglat1(jk,jl),DIM=il_dim)
-               DO jvar=1,tl_multi%i_nvar
-                  tl_var(jvar,jk)=var_concat(tl_var(jvar,jk),tl_segvar1(jvar,jk,jl),DIM=il_dim)
-               ENDDO
-            ENDIF   
-         ENDDO
-
-         ! swap array
-         CALL boundary_swap(tl_lon1(jk), tl_bdy(jk))
-         CALL boundary_swap(tl_lat1(jk), tl_bdy(jk))
-         DO jvar=1,tl_multi%i_nvar
-            CALL boundary_swap(tl_var(jvar,jk), tl_bdy(jk))
-
-            !9- use additional request
-
-            !9-1 forced min and max value
-            CALL var_limit_value(tl_var(jvar,jk))
-
-            !9-2 filter
-            CALL filter_fill_value(tl_var(jvar,jk))
-
-            !9-3 extrapolate
-            CALL extrap_fill_value(tl_var(jvar,jk), id_iext=in_extrap, &
-            &                                       id_jext=in_extrap, &
-            &                                       id_kext=in_extrap)
-
-         ENDDO
+               cl_bdyout=boundary_set_filename( TRIM(cn_fileout), &
+               &                                TRIM(tl_bdy(jl)%c_card), jk )
+            ENDIF
+            ! 
+            tl_fileout=file_init(TRIM(cl_bdyout),id_perio=in_perio1)
+
+            ! add dimension
+            tl_dim(:)=var_max_dim(tl_segvar1(:,jk,jl))
+
+            CALL dim_unorder(tl_dim(:))
+            SELECT CASE(TRIM(tl_bdy(jl)%c_card))
+               CASE DEFAULT ! 'north','south'
+                  cl_dimorder='xyzt'
+                  CALL dim_reorder(tl_dim(:),TRIM(cl_dimorder))
+               CASE('east','west')
+                  cl_dimorder='yxzt'
+                  CALL dim_reorder(tl_dim(:),TRIM(cl_dimorder))
+                  ! reorder coordinates dimension
+                  CALL var_reorder(tl_lon1,TRIM(cl_dimorder))
+                  CALL var_reorder(tl_lat1,TRIM(cl_dimorder))
+                  ! reorder other variable dimension
+                  DO jvar=1,tl_multi%i_nvar
+                     CALL var_reorder(tl_segvar1(jvar,jk,jl),TRIM(cl_dimorder))
+                  ENDDO
+            END SELECT
+
+            DO ji=1,ip_maxdim
+               IF( tl_dim(ji)%l_use ) CALL file_add_dim(tl_fileout, tl_dim(ji))
+            ENDDO
+
+            ! add variables
+            IF( ALL( tl_dim(1:2)%l_use ) )THEN
+               ! add longitude
+               CALL file_add_var(tl_fileout, tl_lon1)
+               CALL var_clean(tl_lon1)
+
+               ! add latitude
+               CALL file_add_var(tl_fileout, tl_lat1)
+               CALL var_clean(tl_lat1)
+            ENDIF
+            
+            IF( tl_dim(3)%l_use )THEN
+               ! add depth
+               CALL file_add_var(tl_fileout, tl_depth)
+            ENDIF
+
+            IF( tl_dim(4)%l_use )THEN
+               ! add time
+               CALL file_add_var(tl_fileout, tl_time)
+            ENDIF
+
+            ! add other variable
+            DO jvar=1,tl_multi%i_nvar
+               CALL file_add_var(tl_fileout, tl_segvar1(jvar,jk,jl))
+               CALL var_clean(tl_segvar1(jvar,jk,jl))
+            ENDDO
+
+            ! add some attribute
+            tl_att=att_init("Created_by","SIREN create_boundary")
+            CALL file_add_att(tl_fileout, tl_att)
+
+            cl_date=date_print(date_now())
+            tl_att=att_init("Creation_date",cl_date)
+            CALL file_add_att(tl_fileout, tl_att)
+
+            ! add shift on north and east boundary
+            ! boundary compute on T point but express on U or V point
+            SELECT CASE(TRIM(tl_bdy(jl)%c_card))
+            CASE DEFAULT ! 'south','west'
+               il_shift=0
+            CASE('north','east')
+               il_shift=1
+            END SELECT
+
+            ! add indice of velocity row or column
+            tl_att=att_init('bdy_ind',tl_bdy(jl)%t_seg(jk)%i_index-il_shift)
+            CALL file_move_att(tl_fileout, tl_att)
+
+            ! add width of the relaxation zone
+            tl_att=att_init('bdy_width',tl_bdy(jl)%t_seg(jk)%i_width)
+            CALL file_move_att(tl_fileout, tl_att)
+            
+            ! add indice of segment start 
+            tl_att=att_init('bdy_deb',tl_bdy(jl)%t_seg(jk)%i_first)
+            CALL file_move_att(tl_fileout, tl_att)
+            
+            ! add indice of segment end 
+            tl_att=att_init('bdy_end',tl_bdy(jl)%t_seg(jk)%i_last)
+            CALL file_move_att(tl_fileout, tl_att)
+                           
+            ! clean
+            CALL att_clean(tl_att)
+
+            ! create file
+            CALL iom_create(tl_fileout)
+
+            ! write file
+            CALL iom_write_file(tl_fileout)
+
+            ! close file
+            CALL iom_close(tl_fileout)
+            CALL file_clean(tl_fileout)
+
+         ENDDO ! jk
+
       ENDIF
-   ENDDO
-
-   DEALLOCATE( tl_seglon1 )
-   DEALLOCATE( tl_seglat1 )
+      ! clean
+      CALL boundary_clean(tl_bdy(jl))
+   ENDDO !jl
+
+   ! clean
+   IF( ASSOCIATED(tl_depth%d_value) ) CALL var_clean(tl_depth)
+   IF( ASSOCIATED(tl_time%d_value) )   CALL var_clean(tl_time)
    DEALLOCATE( tl_segdom1 )
    DEALLOCATE( tl_segvar1 )
-   DEALLOCATE( tl_seglvl1 )
-   
-   DO jk=1,ip_ncard
-      IF( tl_bdy(jk)%l_use )THEN
-
-         !10   create file
-         !10-1 create file structure
-         !10-1-1 set file name
-         cl_bdyout=boundary_set_filename( TRIM(cn_fileout), &
-         &                                TRIM(tl_bdy(jk)%c_card) )
-         !10-1-2 
-         tl_fileout=file_init(TRIM(cl_bdyout),id_perio=in_perio1)
-
-         !10-2 add dimension
-         tl_dim(:)=var_max_dim(tl_var(:,jk))
-
-         DO ji=1,ip_maxdim
-            IF( tl_dim(ji)%l_use ) CALL file_add_dim(tl_fileout, tl_dim(ji))
-         ENDDO
-
-         !10-3 add variables
-         IF( ALL( tl_dim(1:2)%l_use ) )THEN
-            ! add longitude
-            CALL file_add_var(tl_fileout, tl_lon1(jk))
-            CALL var_clean(tl_lon1(jk))
-
-            ! add latitude
-            CALL file_add_var(tl_fileout, tl_lat1(jk))
-            CALL var_clean(tl_lat1(jk))
-         ENDIF
-         
-         IF( tl_dim(3)%l_use )THEN
-            ! add depth
-            CALL file_add_var(tl_fileout, tl_depth)
-         ENDIF
-
-         IF( tl_dim(4)%l_use )THEN
-            ! add time
-            CALL file_add_var(tl_fileout, tl_time)
-         ENDIF
-
-         ! add other variable
-         DO jvar=1,tl_multi%i_nvar
-            !IF( TRIM(tl_var(jvar,jk)%c_name) /= 'X' .AND. &
-            !&   TRIM(tl_var(jvar,jk)%c_name) /= 'Y' )THEN
-               CALL file_add_var(tl_fileout, tl_var(jvar,jk))
-            !ENDIF
-            CALL var_clean(tl_var(jvar,jk))
-         ENDDO
-
-         !10-4 add some attribute
-         tl_att=att_init("Created_by","SIREN create_boundary")
-         CALL file_add_att(tl_fileout, tl_att)
-
-         cl_date=date_print(date_now())
-         tl_att=att_init("Creation_date",cl_date)
-         CALL file_add_att(tl_fileout, tl_att)
-
-         ! add attribute periodicity
-         il_attid=0
-         IF( ASSOCIATED(tl_fileout%t_att) )THEN
-            il_attid=att_get_id(tl_fileout%t_att(:),'periodicity')
-         ENDIF
-         IF( tl_coord1%i_perio >= 0 .AND. il_attid == 0 )THEN
-            tl_att=att_init('periodicity',tl_coord1%i_perio)
-            CALL file_add_att(tl_fileout,tl_att)
-         ENDIF
-      
-         il_attid=0
-         IF( ASSOCIATED(tl_fileout%t_att) )THEN
-            il_attid=att_get_id(tl_fileout%t_att(:),'ew_overlap')
-         ENDIF
-         IF( tl_coord1%i_ew >= 0 .AND. il_attid == 0 )THEN
-            tl_att=att_init('ew_overlap',tl_coord1%i_ew)
-            CALL file_add_att(tl_fileout,tl_att)
-         ENDIF
-
-         !10-5 create file
-         CALL iom_create(tl_fileout)
-
-         !10-6 write file
-         CALL iom_write_file(tl_fileout)
-
-         !10-7 close file
-         CALL iom_close(tl_fileout)
-         CALL file_clean(tl_fileout)
-
-      ENDIF
-   ENDDO
-   DEALLOCATE( tl_lon1 ) 
-   DEALLOCATE( tl_lat1 ) 
-   DEALLOCATE( tl_var ) 
-
-   !11- close file
-   CALL iom_close(tl_bathy1)
-   CALL iom_close(tl_coord1)
-   CALL iom_close(tl_coord0)
-
-   !12- clean
-   CALL var_clean(tl_depth)
-   CALL var_clean(tl_time)
-   CALL file_clean(tl_fileout)
-   CALL file_clean(tl_bathy1)
-   CALL file_clean(tl_coord1)
-   CALL file_clean(tl_coord0)
+
+   CALL mpp_clean(tl_coord1)
+   CALL mpp_clean(tl_coord0)
+
+   CALL multi_clean(tl_multi)
 
    ! close log file
@@ -779,19 +1076,19 @@
    CALL logger_close()
 
-!> @endcode
 CONTAINS
    !-------------------------------------------------------------------
    !> @brief
-   !> This subroutine
+   !> This subroutine compute boundary domain for each grid point (T,U,V,F) 
    !> 
-   !> @details 
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
+   !> @date September, 2014
+   !> - take into account grid point to compute boundary indices
    !>
-   !> @author J.Paul
-   !> - 2013- Initial Version
-   !>
-   !> @param[in] 
-   !> @todo 
-   !-------------------------------------------------------------------
-   !> @code
+   !> @param[in] td_bathy1 file structure 
+   !> @param[in] td_bdy    boundary structure
+   !> @param[in] id_seg    segment indice 
+   !> @return array of domain structure 
+   !-------------------------------------------------------------------
    FUNCTION create_boundary_get_dom( td_bathy1, td_bdy, id_seg )
 
@@ -799,10 +1096,10 @@
 
       ! Argument
-      TYPE(TFILE), INTENT(IN   ) :: td_bathy1
+      TYPE(TMPP) , INTENT(IN   ) :: td_bathy1
       TYPE(TBDY) , INTENT(IN   ) :: td_bdy
       INTEGER(i4), INTENT(IN   ) :: id_seg
 
       ! function
-      TYPE(TDOM) :: create_boundary_get_dom
+      TYPE(TDOM), DIMENSION(ip_npoint) :: create_boundary_get_dom
 
       ! local variable
@@ -812,60 +1109,133 @@
       INTEGER(i4) :: il_jmax1
 
-      TYPE(TFILE) :: tl_bathy1
-      
+      INTEGER(i4) :: il_imin
+      INTEGER(i4) :: il_imax
+      INTEGER(i4) :: il_jmin
+      INTEGER(i4) :: il_jmax
+
+      INTEGER(i4), DIMENSION(ip_npoint) :: il_ishift
+      INTEGER(i4), DIMENSION(ip_npoint) :: il_jshift
+
       ! loop indices
-      INTEGER(i4) :: jl
+      INTEGER(i4) :: ji
+      INTEGER(i4) :: jk
       !----------------------------------------------------------------
-      jl=id_seg
-
-      !1- get boundary definition
+      ! init
+      jk=id_seg
+
+      il_ishift(:)=0
+      il_jshift(:)=0
+
+      ! get boundary definition
       SELECT CASE(TRIM(td_bdy%c_card))
          CASE('north')
 
-            il_imin1=td_bdy%t_seg(jl)%i_first
-            il_imax1=td_bdy%t_seg(jl)%i_last 
-            il_jmin1=td_bdy%t_seg(jl)%i_index-(td_bdy%t_seg(jl)%i_width-1)
-            il_jmax1=td_bdy%t_seg(jl)%i_index
+            il_imin1=td_bdy%t_seg(jk)%i_first
+            il_imax1=td_bdy%t_seg(jk)%i_last 
+            il_jmin1=td_bdy%t_seg(jk)%i_index-(td_bdy%t_seg(jk)%i_width-1)
+            il_jmax1=td_bdy%t_seg(jk)%i_index
+
+            il_jshift(jp_V)=-1
+            il_jshift(jp_F)=-1
 
          CASE('south')
 
-            il_imin1=td_bdy%t_seg(jl)%i_first
-            il_imax1=td_bdy%t_seg(jl)%i_last 
-            il_jmin1=td_bdy%t_seg(jl)%i_index
-            il_jmax1=td_bdy%t_seg(jl)%i_index+(td_bdy%t_seg(jl)%i_width-1)
+            il_imin1=td_bdy%t_seg(jk)%i_first
+            il_imax1=td_bdy%t_seg(jk)%i_last 
+            il_jmin1=td_bdy%t_seg(jk)%i_index
+            il_jmax1=td_bdy%t_seg(jk)%i_index+(td_bdy%t_seg(jk)%i_width-1)
 
          CASE('east')
 
-            il_imin1=td_bdy%t_seg(jl)%i_index-(td_bdy%t_seg(jl)%i_width-1)
-            il_imax1=td_bdy%t_seg(jl)%i_index
-            il_jmin1=td_bdy%t_seg(jl)%i_first
-            il_jmax1=td_bdy%t_seg(jl)%i_last 
+            il_imin1=td_bdy%t_seg(jk)%i_index-(td_bdy%t_seg(jk)%i_width-1)
+            il_imax1=td_bdy%t_seg(jk)%i_index
+            il_jmin1=td_bdy%t_seg(jk)%i_first
+            il_jmax1=td_bdy%t_seg(jk)%i_last 
+
+            il_ishift(jp_U)=-1
+            il_ishift(jp_F)=-1
 
          CASE('west')
 
-            il_imin1=td_bdy%t_seg(jl)%i_index
-            il_imax1=td_bdy%t_seg(jl)%i_index+(td_bdy%t_seg(jl)%i_width-1)
-            il_jmin1=td_bdy%t_seg(jl)%i_first
-            il_jmax1=td_bdy%t_seg(jl)%i_last 
+            il_imin1=td_bdy%t_seg(jk)%i_index
+            il_imax1=td_bdy%t_seg(jk)%i_index+(td_bdy%t_seg(jk)%i_width-1)
+            il_jmin1=td_bdy%t_seg(jk)%i_first
+            il_jmax1=td_bdy%t_seg(jk)%i_last 
 
       END SELECT         
 
-      !2 -read fine grid domain
-      tl_bathy1=td_bathy1
-      CALL iom_open(tl_bathy1)
-
-      !2-1 compute domain
-      create_boundary_get_dom=dom_init( tl_bathy1,         &
-      &                                 il_imin1, il_imax1,&
-      &                                 il_jmin1, il_jmax1 )
-
-      !2-2 close file
-      CALL iom_close(tl_bathy1)
+      !-read fine grid domain
+      DO ji=1,ip_npoint
+
+         ! shift domain
+         il_imin=il_imin1+il_ishift(ji)
+         il_imax=il_imax1+il_ishift(ji)
+
+         il_jmin=il_jmin1+il_jshift(ji)
+         il_jmax=il_jmax1+il_jshift(ji)
+
+         ! compute domain
+         create_boundary_get_dom(ji)=dom_init( td_bathy1,       &
+         &                                     il_imin, il_imax,&
+         &                                     il_jmin, il_jmax,&
+         &                                     TRIM(td_bdy%c_card) )
+
+      ENDDO
 
    END FUNCTION create_boundary_get_dom
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief
-   !> This subroutine
+   !> This subroutine get coordinates over boudnary domain
+   !> 
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
+   !> @date September, 2014 - take into account grid point
+   !>
+   !> @param[in] td_coord1 coordinates file structure
+   !> @param[in] td_dom1   boundary domain structure
+   !> @param[in] cd_point  grid point
+   !> @param[out] td_lon1  longitude variable structure
+   !> @param[out] td_lat1  latitude variable structure
+   !-------------------------------------------------------------------
+   SUBROUTINE create_boundary_get_coord( td_coord1, td_dom1, cd_point, &
+   &                                     td_lon1, td_lat1 )
+
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TMPP)      , INTENT(IN   ) :: td_coord1
+      TYPE(TDOM)      , INTENT(IN   ) :: td_dom1
+      TYPE(TVAR)      , INTENT(  OUT) :: td_lon1
+      TYPE(TVAR)      , INTENT(  OUT) :: td_lat1 
+      CHARACTER(LEN=*), INTENT(IN   ), OPTIONAL :: cd_point
+
+      ! local variable
+      TYPE(TMPP)  :: tl_coord1
+      
+      CHARACTER(LEN=lc) :: cl_name
+      ! loop indices
+      !----------------------------------------------------------------
+      !read variables on domain (ugly way to do it, have to work on it)
+      ! init mpp structure
+      tl_coord1=mpp_copy(td_coord1)
+      
+      ! open mpp files
+      CALL iom_dom_open(tl_coord1, td_dom1)
+
+      ! read variable value on domain
+      WRITE(cl_name,*) 'longitude_'//TRIM(cd_point)
+      td_lon1=iom_dom_read_var( tl_coord1, TRIM(cl_name), td_dom1)
+      WRITE(cl_name,*) 'latitude_'//TRIM(cd_point)
+      td_lat1=iom_dom_read_var( tl_coord1, TRIM(cl_name), td_dom1)
+
+      ! close mpp files
+      CALL iom_dom_close(tl_coord1)
+
+      ! clean structure
+      CALL mpp_clean(tl_coord1)
+
+   END SUBROUTINE create_boundary_get_coord
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine interpolate variable over boundary
    !> 
    !> @details 
@@ -874,247 +1244,10 @@
    !> - Nov, 2013- Initial Version
    !>
-   !> @param[in] 
-   !> @todo 
-   !-------------------------------------------------------------------
-   !> @code
-   SUBROUTINE create_boundary_get_coord( td_bathy1, td_dom1, &
-   &                                     td_lon1, td_lat1 )
-
-      IMPLICIT NONE
-
-      ! Argument
-      TYPE(TFILE), INTENT(IN   ) :: td_bathy1
-      TYPE(TDOM) , INTENT(IN   ) :: td_dom1
-      TYPE(TVAR) , INTENT(  OUT) :: td_lon1
-      TYPE(TVAR) , INTENT(  OUT) :: td_lat1 
-
-      ! local variable
-      TYPE(TFILE) :: tl_bathy1
-      
-      TYPE(TMPP)  :: tl_mppbathy1
-
-      ! loop indices
-      !----------------------------------------------------------------
-      !read variables on domain (ugly way to do it, have to work on it)
-
-      !1 init mpp structure
-      tl_bathy1=td_bathy1
-      tl_mppbathy1=mpp_init(tl_bathy1)
-      
-      CALL file_clean(tl_bathy1)
-
-      !2 get processor to be used
-      CALL mpp_get_use( tl_mppbathy1, td_dom1 )
-
-      !3 open mpp files
-      CALL iom_mpp_open(tl_mppbathy1)
-
-      !4 read variable value on domain
-      td_lon1=iom_mpp_read_var(tl_mppbathy1,'longitude',td_dom=td_dom1)
-      td_lat1=iom_mpp_read_var(tl_mppbathy1,'latitude' ,td_dom=td_dom1)
-
-      !5 close mpp files
-      CALL iom_mpp_close(tl_mppbathy1)
-
-      !6 clean structure
-      CALL mpp_clean(tl_mppbathy1)
-
-   END SUBROUTINE create_boundary_get_coord
-   !> @endcode
-   !-------------------------------------------------------------------
-   !> @brief
-   !> This subroutine
-   !> 
-   !> @details 
-   !>
-   !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !>
-   !> @param[in] 
-   !> @todo 
-   !-------------------------------------------------------------------
-   !> @code
-   SUBROUTINE create_boundary_get_mask( td_level1, td_dom1, &
-   &                                    td_var, td_mask )
-
-      IMPLICIT NONE
-
-      ! Argument
-      TYPE(TFILE), INTENT(IN   ) :: td_level1
-      TYPE(TDOM) , INTENT(IN   ) :: td_dom1
-      TYPE(TVAR) , INTENT(IN   ) :: td_var
-      TYPE(TVAR) , INTENT(  OUT) :: td_mask 
-
-      ! local variable
-      TYPE(TFILE) :: tl_level1
-      
-      TYPE(TMPP)  :: tl_mpplevel1
-
-      ! loop indices
-      !----------------------------------------------------------------
-      !read variables on domain (ugly way to do it, have to work on it)
-
-      !1 init mpp structure
-      tl_level1=td_level1
-      tl_mpplevel1=mpp_init(tl_level1)
-      
-      CALL file_clean(tl_level1)
-
-      !2 get processor to be used
-      CALL mpp_get_use( tl_mpplevel1, td_dom1 )
-
-      !3 open mpp files
-      CALL iom_mpp_open(tl_mpplevel1)
-
-      !4 read variable value on domain
-      SELECT CASE(TRIM(td_var%c_point))
-      CASE('T')
-         td_mask=iom_mpp_read_var(tl_mpplevel1,'tlevel',td_dom=td_dom1)
-      CASE('U')
-         td_mask=iom_mpp_read_var(tl_mpplevel1,'ulevel',td_dom=td_dom1)
-      CASE('V')
-         td_mask=iom_mpp_read_var(tl_mpplevel1,'vlevel',td_dom=td_dom1)
-      CASE('F')
-         td_mask=iom_mpp_read_var(tl_mpplevel1,'flevel',td_dom=td_dom1)
-      END SELECT
-
-      !5 close mpp files
-      CALL iom_mpp_close(tl_mpplevel1)
-
-      !6 clean structure
-      CALL mpp_clean(tl_mpplevel1)
-
-   END SUBROUTINE create_boundary_get_mask
-   !> @endcode
-!   !-------------------------------------------------------------------
-!   !> @brief
-!   !> This subroutine
-!   !> 
-!   !> @details 
-!   !>
-!   !> @author J.Paul
-!   !> - Nov, 2013- Initial Version
-!   !>
-!   !> @param[in] 
-!   !> @todo 
-!   !-------------------------------------------------------------------
-!   !> @code
-!   SUBROUTINE create_boundary_get_var( td_var, td_bdy,      &
-!   &                                   td_coord0, td_dom0,  &
-!   &                                   td_mask,             &
-!   &                                   id_rhoi, id_rhoj )
-!
-!      IMPLICIT NONE
-!
-!      ! Argument
-!      TYPE(TVAR) , INTENT(INOUT) :: td_var
-!      TYPE(TBDY) , INTENT(IN   ) :: td_bdy
-!      TYPE(TFILE), INTENT(IN   ) :: td_coord0
-!      TYPE(TDOM) , INTENT(IN   ) :: td_dom0
-!      TYPE(TVAR) , INTENT(IN   ) :: td_mask
-!      INTEGER(I4), INTENT(IN   ) :: id_rhoi
-!      INTEGER(I4), INTENT(IN   ) :: id_rhoj
-!
-!      ! local variable
-!      TYPE(TVAR)  :: tl_var0
-!
-!      TYPE(TDOM)  :: tl_dom0
-!
-!      TYPE(TFILE) :: tl_file0
-!
-!      TYPE(TMPP)  :: tl_mppfile0
-!
-!      ! loop indices
-!      INTEGER(i4) :: jk
-!      INTEGER(i4) :: jl
-!      !----------------------------------------------------------------
-!
-!      CALL logger_debug("CREATE BOUNDARY INTERP: read coarse grid"// TRIM(td_var%c_file) )
-!      !1- read coarse grid variable on domain
-!      tl_file0=file_init( TRIM(td_var%c_file) )
-!
-!      !2- init
-!      tl_dom0=td_dom0
-!
-!      !3- add extra band (if possible) to compute interpolation
-!      CALL dom_add_extra(tl_dom0)
-!
-!      !4- read variables on domain (ugly way to do it, have to work on it)
-!      !4-1 init mpp structure
-!      tl_mppfile0=mpp_init(tl_file0)
-! 
-!      CALL file_clean(tl_file0)
-!
-!      !4-2 get processor to be used
-!      CALL mpp_get_use( tl_mppfile0, tl_dom0 )
-!
-!      !4-3 open mpp files
-!      CALL iom_mpp_open(tl_mppfile0)
-!
-!      ! check file dimension
-!      IF( ANY(tl_mppfile0%t_dim(1:2)%i_len /= td_coord0%t_dim(1:2)%i_len) )THEN
-!         CALL logger_error("CREATE BOUNDARY INTERP: dimension of file "//&
-!         &  TRIM(tl_mppfile0%c_name)//" not conform to those of "//&
-!         &  TRIM(td_coord0%c_name))
-!      ELSE
-!
-!         !4-4 read variable value on domain
-!         tl_var0=iom_mpp_read_var( tl_mppfile0, TRIM(td_var%c_name), &
-!         &                         td_dom=tl_dom0 )
-!
-!         !5- work on variable
-!         CALL create_boundary_interp(tl_var0, id_rhoi, id_rhoj )
-!         
-!         !6- remove extraband added to domain
-!         CALL dom_del_extra( tl_var0, tl_dom0, id_rhoi, id_rhoj )
-!
-!         !6-1 remove extraband added to domain
-!         CALL dom_clean_extra( tl_dom0 )         
-!
-!         !7- keep only useful point (width) 
-!         ! interpolation could create more point than necessary
-!         CALL boundary_clean_interp(tl_var0, td_bdy )
-!
-!         !8- forced min and max value
-!         CALL var_limit_value(tl_var0)
-!
-!         !9- filter
-!         CALL filter_fill_value(tl_var0)
-!
-!         td_var=tl_var0
-!
-!         CALL var_clean(tl_var0)
-!      ENDIF
-!
-!      !4-5 close mpp files
-!      CALL iom_mpp_close(tl_mppfile0)
-!
-!      !4-6 clean structure
-!      CALL mpp_clean(tl_mppfile0)
-!      
-!      !5- apply mask
-!      DO jl=1,td_var%t_dim(4)%i_len
-!         DO jk=1,td_var%t_dim(3)%i_len
-!            WHERE( td_mask%d_value(:,:,1,1) < jk )
-!               td_var%d_value(:,:,jk,jl)=td_var%d_fill
-!            END WHERE
-!         ENDDO
-!      ENDDO
-!
-!   END SUBROUTINE create_boundary_get_var
-!   !> @endcode
-   !-------------------------------------------------------------------
-   !> @brief
-   !> This subroutine
-   !> 
-   !> @details 
-   !>
-   !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !>
-   !> @param[in] 
-   !> @todo 
-   !-------------------------------------------------------------------
-   !> @code
+   !> @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)
+   !-------------------------------------------------------------------
    SUBROUTINE create_boundary_interp( td_var,           &
    &                                  id_rho,           &
@@ -1134,13 +1267,8 @@
 
       ! local variable
-      TYPE(TVAR)  :: tl_var
-
       INTEGER(i4) :: il_iext
       INTEGER(i4) :: il_jext
       ! loop indices
       !----------------------------------------------------------------
-
-      ! copy variable
-      tl_var=td_var
 
       !WARNING: at least two extrabands are required for cubic interpolation
@@ -1163,26 +1291,19 @@
       ENDIF
 
-      !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_iext=il_iext, id_jext=il_jext )
-
-      !2-2 interpolate Bathymetry
-      CALL interp_fill_value( tl_var, id_rho(:), &
+      ! work on variable
+      ! add extraband
+      CALL extrap_add_extrabands(td_var, il_iext, il_jext)
+
+      ! extrapolate variable
+      CALL extrap_fill_value( td_var, id_iext=il_iext, id_jext=il_jext )
+
+      ! 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))
-
-      !3- save result
-      td_var=tl_var
-
-      ! clean variable structure
-      CALL var_clean(tl_var)
+      ! remove extraband
+      CALL extrap_del_extrabands(td_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J))
 
    END SUBROUTINE create_boundary_interp
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief
@@ -1192,30 +1313,26 @@
    !> A variable is create with the same name that the input variable, 
    !> and with dimension of the coordinate file. 
-   !> Then the variable table of value is split into equal subdomain.
+   !> Then the variable array of value is split into equal subdomain.
    !> Each subdomain is fill with the linked value of the matrix.
    !>
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
+   !> - November, 2013- Initial Version
    !>
-   !> @param[in] td_var : variable structure 
-   !> @param[in] td_dom : domain structure 
-   !> @param[in] td_coord : coordinate 
+   !> @param[in] td_var    variable structure 
+   !> @param[in] td_dom    domain structure 
+   !> @param[in] id_nlevel number of levels 
    !> @return variable structure 
    !-------------------------------------------------------------------
-   !> @code
-   FUNCTION create_bdy_matrix(td_var, td_dom, td_coord)
+   FUNCTION create_boundary_matrix(td_var, td_dom, id_nlevel)
       IMPLICIT NONE
       ! Argument
-      TYPE(TVAR) , INTENT(IN) :: td_var
-      TYPE(TDOM) , INTENT(IN) :: td_dom
-      TYPE(TFILE), INTENT(IN) :: td_coord
+      TYPE(TVAR) ,               INTENT(IN) :: td_var
+      TYPE(TDOM) ,               INTENT(IN) :: td_dom
+      INTEGER(i4),               INTENT(IN) :: id_nlevel
 
       ! function
-      TYPE(TVAR) :: create_bdy_matrix
+      TYPE(TVAR) :: create_boundary_matrix
 
       ! local variable
-      INTEGER(i4)                                        :: il_ighost
-      INTEGER(i4)                                        :: il_jghost
-      INTEGER(i4)      , DIMENSION(2)                    :: il_xghost
       INTEGER(i4)      , DIMENSION(3)                    :: il_dim
       INTEGER(i4)      , DIMENSION(3)                    :: il_size
@@ -1228,7 +1345,4 @@
       REAL(dp)         , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
 
-      TYPE(TVAR)                                         :: tl_lon
-      TYPE(TVAR)                                         :: tl_lat
-      TYPE(TVAR)                                         :: tl_var
       TYPE(TDIM)       , DIMENSION(ip_maxdim)            :: tl_dim
 
@@ -1239,25 +1353,12 @@
       !----------------------------------------------------------------
 
-      !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
+      ! 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 
+
+      tl_dim(jp_I:jp_J)=dim_copy(td_dom%t_dim(jp_I:jp_J))
+      tl_dim(jp_K)%i_len=id_nlevel
+
+      ! 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(:))
@@ -1271,5 +1372,4 @@
       il_ishape(il_dim(1)+1)=il_ishape(il_dim(1)+1)+il_rest(1)
       
-
       ALLOCATE( il_jshape(il_dim(2)+1) )
       il_jshape(:)=0
@@ -1288,5 +1388,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, &
@@ -1309,37 +1409,29 @@
       ENDDO
 
-      !3-4 initialise variable with value
-      tl_var=var_init(TRIM(td_var%c_name),dl_value(:,:,:,:))
+      ! initialise variable with value
+      create_boundary_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_bdy_matrix=tl_var
-
-   END FUNCTION create_bdy_matrix
-   !> @endcode
+   END FUNCTION create_boundary_matrix
    !-------------------------------------------------------------------
    !> @brief
-   !> This subroutine
+   !> This subroutine use mask to filled land point with _FillValue
    !> 
    !> @details 
    !>
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
+   !> - November, 2013- Initial Version
    !>
-   !> @param[in] 
-   !> @todo 
-   !-------------------------------------------------------------------
-   !> @code
-   SUBROUTINE create_bdy_use_mask( td_var, td_mask )
+   !> @param[inout] td_var variable structure 
+   !> @param[in] td_mask   mask variable structure
+   !-------------------------------------------------------------------
+   SUBROUTINE create_boundary_use_mask( td_var, td_mask )
 
       IMPLICIT NONE
 
       ! Argument
-      TYPE(TVAR)              , INTENT(INOUT) :: td_var
-      TYPE(TVAR), DIMENSION(:), INTENT(IN   ) :: td_mask
+      TYPE(TVAR), INTENT(INOUT) :: td_var
+      TYPE(TVAR), INTENT(IN   ) :: td_mask
 
       ! local variable
@@ -1351,17 +1443,20 @@
       !----------------------------------------------------------------
 
+      IF( ANY(td_var%t_dim(1:2)%i_len /= &
+      &       td_mask%t_dim(1:2)%i_len) )THEN
+         CALL logger_debug("     mask dimension ( "//&
+         &              TRIM(fct_str(td_mask%t_dim(1)%i_len))//","//&
+         &              TRIM(fct_str(td_mask%t_dim(2)%i_len))//")" )
+         CALL logger_debug(" variable dimension ( "//&
+         &              TRIM(fct_str(td_var%t_dim(1)%i_len))//","//&
+         &              TRIM(fct_str(td_var%t_dim(2)%i_len))//")" )
+         CALL logger_fatal("CREATE BOUNDARY USE MASK: mask and "//&
+         &                 "variable dimension differ."   )
+      ENDIF
+
       ALLOCATE( il_mask(td_var%t_dim(1)%i_len, &
       &                 td_var%t_dim(2)%i_len) )
 
-      SELECT CASE(TRIM(td_var%c_point))
-      CASE('T')
-         il_mask(:,:)=INT(td_mask(jp_T)%d_value(:,:,1,1))
-      CASE('U')
-         il_mask(:,:)=INT(td_mask(jp_U)%d_value(:,:,1,1))
-      CASE('V')
-         il_mask(:,:)=INT(td_mask(jp_V)%d_value(:,:,1,1))
-      CASE('F')
-         il_mask(:,:)=INT(td_mask(jp_F)%d_value(:,:,1,1))
-      END SELECT
+      il_mask(:,:)=INT(td_mask%d_value(:,:,1,1))
 
       DO jl=1,td_var%t_dim(4)%i_len
@@ -1372,62 +1467,172 @@
 
       DEALLOCATE( il_mask )
-   END SUBROUTINE create_bdy_use_mask
-   !> @endcode
+
+   END SUBROUTINE create_boundary_use_mask
    !-------------------------------------------------------------------
    !> @brief
+   !> This function extract level over domain on each grid point, and return
+   !> array of variable structure
+   !>
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
+   !>
+   !> @param[in] td_level  array of level variable structure
+   !> @param[in] td_dom    array of domain structure
+   !> @return array of variable structure
+   !-------------------------------------------------------------------
+   FUNCTION create_boundary_get_level(td_level, td_dom)
+      IMPLICIT NONE
+      ! Argument
+      TYPE(TVAR), DIMENSION(:), INTENT(IN) :: td_level
+      TYPE(TDOM), DIMENSION(:), INTENT(IN) :: td_dom
+
+      ! function
+      TYPE(TVAR), DIMENSION(ip_npoint) :: create_boundary_get_level
+
+      ! local variable
+      TYPE(TVAR), DIMENSION(ip_npoint) :: tl_var
+
+      ! loop indices
+      INTEGER(i4) :: ji
+      !----------------------------------------------------------------
+
+      IF( SIZE(td_level(:)) /= ip_npoint .OR. &
+      &   SIZE(td_dom(:)) /= ip_npoint )THEN
+         CALL logger_error("CREATE BDY GET LEVEL: invalid dimension. "//&
+         &  "check input array of level and domain.")
+      ELSE
+
+         DO ji=1,ip_npoint
+
+            tl_var(ji)=var_copy(td_level(ji))
+
+            IF( ASSOCIATED(tl_var(ji)%d_value) ) DEALLOCATE(tl_var(ji)%d_value)
+
+            tl_var(ji)%t_dim(1)%i_len=td_dom(ji)%t_dim(1)%i_len
+            tl_var(ji)%t_dim(2)%i_len=td_dom(ji)%t_dim(2)%i_len
+            ALLOCATE(tl_var(ji)%d_value(tl_var(ji)%t_dim(1)%i_len, &
+            &                           tl_var(ji)%t_dim(2)%i_len, &
+            &                           tl_var(ji)%t_dim(3)%i_len, &
+            &                           tl_var(ji)%t_dim(4)%i_len) )
+
+            tl_var(ji)%d_value(:,:,:,:) = &
+            &  td_level(ji)%d_value( td_dom(ji)%i_imin:td_dom(ji)%i_imax, &
+            &                        td_dom(ji)%i_jmin:td_dom(ji)%i_jmax, :, : )
+
+         ENDDO
+         ! save result
+         create_boundary_get_level(:)=var_copy(tl_var(:))
+
+         ! clean
+         CALL var_clean(tl_var(:))
+
+      ENDIF
+   END FUNCTION create_boundary_get_level
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine get depth variable value in an open mpp structure
+   !> and check if agree with already input depth variable.
    !> 
    !> @details 
    !>
    !> @author J.Paul
-   !> - 2013- Initial Version
+   !> - November, 2014- Initial Version
    !>
-   !-------------------------------------------------------------------
-   !> @code
-   FUNCTION create_bdy_get_level(td_level, td_dom)
+   !> @param[in] td_mpp       mpp structure
+   !> @param[inout] td_depth  depth variable structure 
+   !-------------------------------------------------------------------
+   SUBROUTINE create_boundary_check_depth( td_mpp, td_depth )
+
       IMPLICIT NONE
+
       ! Argument
-      TYPE(TVAR), DIMENSION(:), INTENT(IN) :: td_level
-      TYPE(TDOM)              , INTENT(IN) :: td_dom
-
-      ! function
-      TYPE(TVAR), DIMENSION(ig_npoint) :: create_bdy_get_level
+      TYPE(TMPP) , INTENT(IN   ) :: td_mpp
+      TYPE(TVAR) , INTENT(INOUT) :: td_depth
 
       ! local variable
-      TYPE(TVAR), DIMENSION(ig_npoint) :: tl_var
-
+      INTEGER(i4) :: il_varid
+      TYPE(TVAR)  :: tl_depth
       ! loop indices
-      INTEGER(i4) :: ji
       !----------------------------------------------------------------
 
-      IF( SIZE(td_level(:)) /= ig_npoint )THEN
-         CALL logger_error("CREATE BDY GET LEVEL: invalid dimension. "//&
-         &  "check input table of level.")
-      ELSE
-
-         !tl_var(1:ig_npoint)=td_level(1:ig_npoint)
-         create_bdy_get_level(:)=tl_var(:)
-         DO ji=1,ig_npoint
-
-         tl_var(ji)=td_level(ji)
-
-            IF( ASSOCIATED(tl_var(ji)%d_value) ) DEALLOCATE( tl_var(ji)%d_value )
-
-            tl_var(ji)%t_dim(1)%i_len=td_dom%t_dim(1)%i_len
-            tl_var(ji)%t_dim(2)%i_len=td_dom%t_dim(2)%i_len
-            ALLOCATE(tl_var(ji)%d_value(tl_var(ji)%t_dim(1)%i_len, &
-            &                           tl_var(ji)%t_dim(2)%i_len, &
-            &                           tl_var(ji)%t_dim(3)%i_len, &
-            &                           tl_var(ji)%t_dim(4)%i_len) )
-
-            tl_var(ji)%d_value(:,:,:,:) = &
-            &  td_level(ji)%d_value( td_dom%i_imin:td_dom%i_imax, &
-            &                        td_dom%i_jmin:td_dom%i_jmax, :, : )
-
-         ENDDO
-         !4 save result
-         create_bdy_get_level(:)=tl_var(:)
+      ! get or check depth value
+      IF( td_mpp%t_proc(1)%i_depthid /= 0 )THEN
+
+         il_varid=td_mpp%t_proc(1)%i_depthid
+         IF( ASSOCIATED(td_depth%d_value) )THEN
+
+            tl_depth=iom_mpp_read_var(td_mpp, il_varid)
+            IF( ANY( td_depth%d_value(:,:,:,:) /= &
+            &        tl_depth%d_value(:,:,:,:) ) )THEN
+
+               CALL logger_fatal("CREATE BOUNDARY: depth value from "//&
+               &  TRIM(tl_multi%t_mpp(ji)%c_name)//" not conform "//&
+               &  " to those from former file(s).")
+
+            ENDIF
+            CALL var_clean(tl_depth)
+
+         ELSE
+            td_depth=iom_mpp_read_var(td_mpp,il_varid)
+         ENDIF
 
       ENDIF
-   END FUNCTION create_bdy_get_level
-   !> @endcode
+      
+   END SUBROUTINE create_boundary_check_depth
+   !-------------------------------------------------------------------
+   !> @brief
+   !> This subroutine get date and time in an open mpp structure
+   !> and check if agree with date and time already read.
+   !> 
+   !> @details 
+   !>
+   !> @author J.Paul
+   !> - November, 2014- Initial Version
+   !>
+   !> @param[in] td_mpp      mpp structure
+   !> @param[inout] td_time  time variable structure 
+   !-------------------------------------------------------------------
+   SUBROUTINE create_boundary_check_time( td_mpp, td_time )
+
+      IMPLICIT NONE
+
+      ! Argument
+      TYPE(TMPP), INTENT(IN   ) :: td_mpp
+      TYPE(TVAR), INTENT(INOUT) :: td_time
+
+      ! local variable
+      INTEGER(i4) :: il_varid
+      TYPE(TVAR)  :: tl_time
+
+      TYPE(TDATE) :: tl_date1
+      TYPE(TDATE) :: tl_date2
+      ! loop indices
+      !----------------------------------------------------------------
+
+      ! get or check depth value
+      IF( td_mpp%t_proc(1)%i_timeid /= 0 )THEN
+
+         il_varid=td_mpp%t_proc(1)%i_timeid
+         IF( ASSOCIATED(td_time%d_value) )THEN
+
+            tl_time=iom_mpp_read_var(td_mpp, il_varid)
+
+            tl_date1=var_to_date(td_time)
+            tl_date2=var_to_date(tl_time)
+            IF( tl_date1 - tl_date2 /= 0 )THEN
+
+               CALL logger_fatal("CREATE BOUNDARY: date from "//&
+               &  TRIM(tl_multi%t_mpp(ji)%c_name)//" not conform "//&
+               &  " to those from former file(s).")
+
+            ENDIF
+            CALL var_clean(tl_time)
+
+         ELSE
+            td_time=iom_mpp_read_var(td_mpp,il_varid)
+         ENDIF
+
+      ENDIF
+      
+   END SUBROUTINE create_boundary_check_time
 END PROGRAM create_boundary
