New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 5600 for branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/TOOLS/SIREN/src/mpp.f90 – NEMO

Ignore:
Timestamp:
2015-07-15T17:46:12+02:00 (9 years ago)
Author:
andrewryan
Message:

merged in latest version of trunk alongside changes to SAO_SRC to be compatible with latest OBS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/TOOLS/SIREN/src/mpp.f90

    r4213 r5600  
    55! MODULE: mpp 
    66! 
    7 ! 
    87! DESCRIPTION: 
    9 !> This module manage massively parallel processing 
     8!> @brief 
     9!> This module manage massively parallel processing. 
    1010! 
    1111!> @details 
    1212!> define type TMPP:<br/> 
    13 !> TYPE(TMPP) :: tl_mpp<br/> 
     13!> @code 
     14!> TYPE(TMPP) :: tl_mpp 
     15!> @endcode 
    1416!> 
    1517!>    to initialise a mpp structure:<br/> 
    16 !>    - tl_mpp=mpp_init( cd_file, id_mask, [id_niproc,] [id_njproc,]  
    17 !>         [id_nproc] [id_preci,] [id_precj,] [cd_type]) 
    18 !>    - tl_mpp=mpp_init( cd_file, td_var, [id_niproc,] [id_njproc,]  
    19 !>         [id_nproc] [id_preci,] [id_precj,] [cd_type]) 
    20 !>    - tl_mpp=mpp_init( td_file ) 
     18!> @code 
     19!>    tl_mpp=mpp_init( cd_file, id_mask,  
     20!>                       [id_niproc,] [id_njproc,] [id_nproc,] 
     21!>                       [id_preci,] [id_precj,]  
     22!>                       [cd_type,] [id_ew]) 
     23!> @endcode 
     24!> or 
     25!> @code 
     26!>    tl_mpp=mpp_init( cd_file, td_var,  
     27!>                      [id_niproc,] [id_njproc,] [id_nproc,] 
     28!>                      [id_preci,] [id_precj,] 
     29!>                      [cd_type] ) 
     30!> @endcode 
     31!> or 
     32!> @code 
     33!>    tl_mpp=mpp_init( td_file [,id_ew] ) 
     34!> @endcode 
    2135!>       - cd_file is the filename of the global domain file, in which  
    2236!>         MPP will be done (example: Bathymetry)  
    2337!>       - td_file is the file structure of one processor file composing an MPP 
    24 !>       - id_mask is the 2D mask of global domain  
     38!>       - id_mask is the 2D mask of global domain [optional] 
    2539!>       - td_var is a variable structure (on T-point) from global domain file. 
    26 !>         mask of the domain will be computed using FillValue 
     40!>         mask of the domain will be computed using FillValue [optional] 
    2741!>       - id_niproc is the number of processor following I-direction to be used 
    28 !>         (optional) 
     42!>         [optional] 
    2943!>       - id_njproc is the number of processor following J-direction to be used  
    30 !>         (optional) 
    31 !>       - id_nproc is the total number of processor to be used (optional) 
    32 !>       - id_preci is the size of the overlap region following I-direction 
    33 !>       - id_precj is the size of the overlap region following J-direction 
    34 !>       - cd_type is the type of files composing MPP<br/> 
     44!>         [optional] 
     45!>       - id_nproc is the total number of processor to be used [optional] 
     46!>       - id_preci is the size of the overlap region following I-direction [optional] 
     47!>       - id_precj is the size of the overlap region following J-direction [optional] 
     48!>       - cd_type is the type of files composing MPP [optional] 
     49!>       - id_ew is east-west overlap [optional]<br/>  
    3550!>   
    3651!>    to get mpp name:<br/> 
     
    6277!>    - tl_mpp\%i_ndim 
    6378!> 
    64 !>    to get the table of dimension structure (4 elts) associated to the 
     79!>    to get the array of dimension structure (4 elts) associated to the 
    6580!>    mpp structure:<br/> 
    6681!>    - tl_mpp\%t_dim(:) 
     
    7085!> 
    7186!>    to clean a mpp structure:<br/> 
    72 !>    - CALL mpp_clean(tl_mpp) 
     87!> @code 
     88!>    CALL mpp_clean(tl_mpp) 
     89!> @endcode 
    7390!> 
    7491!>    to print information about mpp:<br/> 
     92!> @code 
    7593!>    CALL mpp_print(tl_mpp) 
     94!> @endcode 
    7695!> 
    7796!>    to add variable to mpp:<br/> 
     97!> @code 
    7898!>    CALL mpp_add_var(td_mpp, td_var) 
     99!> @endcode 
    79100!>       - td_var is a variable structure 
    80101!> 
    81102!>    to add dimension to mpp:<br/> 
     103!> @code 
    82104!>    CALL mpp_add_dim(td_mpp, td_dim) 
     105!> @endcode 
    83106!>       - td_dim is a dimension structure 
    84107!> 
    85 !>    to delete variable to mpp:<br/> 
     108!>    to add attribute to mpp:<br/> 
     109!> @code 
     110!>    CALL mpp_add_att(td_mpp, td_att) 
     111!> @endcode 
     112!>       - td_att is a attribute structure 
     113!> 
     114!>    to delete variable from mpp:<br/> 
     115!> @code 
    86116!>    CALL mpp_del_var(td_mpp, td_var) 
     117!> @endcode 
     118!>    or 
     119!> @code 
     120!>    CALL mpp_del_var(td_mpp, cd_name) 
     121!> @endcode 
    87122!>       - td_var is a variable structure 
     123!>       - cd_name is variable name or standard name 
    88124!> 
    89 !>    to delete dimension to mpp:<br/> 
     125!>    to delete dimension from mpp:<br/> 
     126!> @code 
    90127!>    CALL mpp_del_dim(td_mpp, td_dim) 
     128!> @endcode 
    91129!>       - td_dim is a dimension structure 
    92130!> 
     131!>    to delete attribute from mpp:<br/> 
     132!> @code 
     133!>    CALL mpp_del_att(td_mpp, td_att) 
     134!> @endcode 
     135!>    or 
     136!> @code 
     137!>    CALL mpp_del_att(td_mpp, cd_name) 
     138!> @endcode 
     139!>       - td_att is a attribute structure 
     140!>       - cd_name is attribute name 
     141!> 
    93142!>    to overwrite variable to mpp:<br/> 
     143!> @code 
    94144!>    CALL mpp_move_var(td_mpp, td_var) 
     145!> @endcode 
    95146!>       - td_var is a variable structure 
    96147!> 
    97148!>    to overwrite dimension to mpp:<br/> 
     149!> @code 
    98150!>    CALL mpp_move_dim(td_mpp, td_dim) 
     151!> @endcode 
    99152!>       - td_dim is a dimension structure 
    100153!> 
     154!>    to overwrite attribute to mpp:<br/> 
     155!> @code 
     156!>    CALL mpp_move_att(td_mpp, td_att) 
     157!> @endcode 
     158!>       - td_att is a attribute structure 
     159!> 
    101160!>    to determine domain decomposition type:<br/> 
     161!> @code 
    102162!>    CALL mpp_get_dom(td_mpp) 
     163!> @endcode 
    103164!> 
    104165!>    to get processors to be used:<br/> 
    105 !>    CALL mpp_get_use( td_mpp, td_dom ) 
    106 !>       - td_dom is a domain structure 
     166!> @code 
     167!>    CALL mpp_get_use( td_mpp, id_imin, id_imax, id_idim, &  
     168!>    &                         id_jmin, id_jmax, id_jdim ) 
     169!> @endcode 
     170!>       - id_imin  
     171!>       - id_imax  
     172!>       - id_idim  
     173!>       - id_jmin  
     174!>       - id_jmax  
     175!>       - id_jdim  
    107176!> 
    108177!>    to get sub domains which form global domain contour:<br/> 
     178!> @code 
    109179!>    CALL mpp_get_contour( td_mpp )  
     180!> @endcode 
    110181!> 
    111182!>    to get global domain indices of one processor:<br/> 
     183!> @code 
    112184!>    il_ind(1:4)=mpp_get_proc_index( td_mpp, id_procid ) 
     185!> @endcode 
    113186!>       - il_ind(1:4) are global domain indices (i1,i2,j1,j2) 
    114187!>       - id_procid is the processor id 
    115188!> 
    116189!>    to get the processor domain size:<br/> 
     190!> @code 
    117191!>    il_size(1:2)=mpp_get_proc_size( td_mpp, id_procid ) 
     192!> @endcode 
    118193!>       - il_size(1:2) are the size of domain following I and J 
    119194!>       - id_procid is the processor id 
     
    122197!>  J.Paul 
    123198! REVISION HISTORY: 
    124 !> @date Nov, 2013 - Initial Version 
    125 !> @todo 
    126 !>  - add description generique de l'objet mpp 
    127 !>  - mpp_print 
    128 !>  - voir pour mettre cd_file systematiquement pour mpp_init 
    129 !>  + modifier utilisation la haut 
     199!> @date November, 2013 - Initial Version 
     200!> @date November, 2014 - Fix memory leaks bug 
    130201! 
    131202!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt) 
    132203!---------------------------------------------------------------------- 
    133204MODULE mpp 
     205   USE global                          ! global parameter 
    134206   USE kind                            ! F90 kind parameter 
    135    USE logger                             ! log file manager 
     207   USE logger                          ! log file manager 
    136208   USE fct                             ! basic useful function 
    137209   USE dim                             ! dimension manager 
     
    140212   USE file                            ! file manager 
    141213   USE iom                             ! I/O manager 
    142 !   USE proc                            ! proc manager 
    143    USE dom                             ! domain manager 
    144214   IMPLICIT NONE 
    145    PRIVATE 
    146215   ! NOTE_avoid_public_variables_if_possible 
    147216 
    148217   ! type and variable 
    149    PUBLIC :: TMPP       ! mpp structure 
     218   PUBLIC :: TMPP       !< mpp structure 
    150219 
    151220   ! function and subroutine 
    152    PUBLIC :: ASSIGNMENT(=)      !< copy mpp structure 
     221   PUBLIC :: mpp_copy           !< copy mpp structure 
    153222   PUBLIC :: mpp_init           !< initialise mpp structure 
    154223   PUBLIC :: mpp_clean          !< clean mpp strcuture 
     
    163232   PUBLIC :: mpp_move_dim       !< overwrite one dimension strucutre in mpp structure 
    164233   PUBLIC :: mpp_move_att       !< overwrite one attribute strucutre in mpp structure 
     234   PUBLIC :: mpp_recombine_var  !< recombine variable from mpp structure 
     235   PUBLIC :: mpp_get_index      !< return index of mpp  
    165236 
    166237   PUBLIC :: mpp_get_dom        !< determine domain decomposition type (full, overlap, noverlap) 
     
    170241   PUBLIC :: mpp_get_proc_size  !< get processor domain size 
    171242 
    172    PRIVATE :: mpp__add_proc     !< add one proc strucutre in mpp structure 
    173    PRIVATE :: mpp__del_proc     !< delete one proc strucutre in mpp structure 
    174    PRIVATE :: mpp__move_proc    !< overwrite proc strucutre in mpp structure 
    175    PRIVATE :: mpp__compute      !< compute domain decomposition 
    176    PRIVATE :: mpp__del_land     !< remove land sub domain from domain decomposition 
    177    PRIVATE :: mpp__optimiz      !< compute optimum domain decomposition 
    178    PRIVATE :: mpp__land_proc    !< check if processor is a land processor 
    179    PRIVATE :: mpp__check_dim    !< check mpp structure dimension with proc or variable dimension 
    180    PRIVATE :: mpp__del_var_name !< delete variable in mpp structure, given variable name 
    181    PRIVATE :: mpp__del_var_str  !< delete variable in mpp structure, given variable structure 
    182    PRIVATE :: mpp__del_att_name !< delete variable in mpp structure, given variable name 
    183    PRIVATE :: mpp__del_att_str  !< delete variable in mpp structure, given variable structure 
    184    PRIVATE :: mpp__split_var    !< extract variable part that will be written in processor  
    185    PRIVATE :: mpp__copy         !< copy mpp structure 
    186  
    187    !> @struct TMPP 
    188    TYPE TMPP 
     243   PRIVATE :: mpp__add_proc            ! add one proc strucutre in mpp structure 
     244   PRIVATE :: mpp__del_proc            ! delete one proc strucutre in mpp structure 
     245   PRIVATE :: mpp__del_proc_id         ! delete one proc strucutre in mpp structure, given procesor id 
     246   PRIVATE :: mpp__del_proc_str        ! delete one proc strucutre in mpp structure, given procesor file structure  
     247   PRIVATE :: mpp__move_proc           ! overwrite proc strucutre in mpp structure 
     248   PRIVATE :: mpp__compute             ! compute domain decomposition 
     249   PRIVATE :: mpp__del_land            ! remove land sub domain from domain decomposition 
     250   PRIVATE :: mpp__optimiz             ! compute optimum domain decomposition 
     251   PRIVATE :: mpp__land_proc           ! check if processor is a land processor 
     252   PRIVATE :: mpp__check_dim           ! check mpp structure dimension with proc or variable dimension 
     253   PRIVATE :: mpp__check_proc_dim      ! check if processor and mpp structure use same dimension 
     254   PRIVATE :: mpp__check_var_dim       ! check if variable  and mpp structure use same dimension 
     255   PRIVATE :: mpp__del_var_name        ! delete variable in mpp structure, given variable name 
     256   PRIVATE :: mpp__del_var_mpp         ! delete all variable in mpp structure 
     257   PRIVATE :: mpp__del_var_str         ! delete variable in mpp structure, given variable structure 
     258   PRIVATE :: mpp__del_att_name        ! delete variable in mpp structure, given variable name 
     259   PRIVATE :: mpp__del_att_str         ! delete variable in mpp structure, given variable structure 
     260   PRIVATE :: mpp__split_var           ! extract variable part that will be written in processor  
     261   PRIVATE :: mpp__copy_unit           ! copy mpp structure 
     262   PRIVATE :: mpp__copy_arr            ! copy array of mpp structure 
     263   PRIVATE :: mpp__get_use_unit        ! get sub domains to be used (which cover "zoom domain") 
     264   PRIVATE :: mpp__init_mask           ! initialise mpp structure, given file name 
     265   PRIVATE :: mpp__init_var            ! initialise mpp structure, given variable strcuture 
     266   PRIVATE :: mpp__init_file           ! initialise a mpp structure, given file structure  
     267   PRIVATE :: mpp__init_file_cdf       ! initialise a mpp structure with cdf file 
     268   PRIVATE :: mpp__init_file_rstdimg   ! initialise a mpp structure with rstdimg file 
     269   PRIVATE :: mpp__clean_unit          ! clean mpp strcuture 
     270   PRIVATE :: mpp__clean_arr           ! clean array of mpp strcuture 
     271 
     272   TYPE TMPP !< mpp structure 
    189273 
    190274      ! general  
    191       CHARACTER(LEN=lc)                   :: c_name = ''   !< base name ??? 
    192  
    193       INTEGER(i4)                         :: i_niproc = 0         !< number of processors following i 
    194       INTEGER(i4)                         :: i_njproc = 0         !< number of processors following j 
    195       INTEGER(i4)                         :: i_nproc  = 0         !< total number of proccessors used 
    196       INTEGER(i4)                         :: i_preci = 1          !< i-direction overlap region length 
    197       INTEGER(i4)                         :: i_precj = 1          !< j-direction overlap region length 
    198  
    199       CHARACTER(LEN=lc)                   :: c_type = ''   !< type of the files (cdf, cdf4, dimg) 
    200       CHARACTER(LEN=lc)                   :: c_dom  = ''   !< type of domain (full, overlap, nooverlap) 
    201  
    202       INTEGER(i4)                         :: i_ndim = 0           !< number of dimensions used in mpp 
    203       TYPE(TDIM),  DIMENSION(ip_maxdim)   :: t_dim                !< global domain dimension 
    204  
    205       TYPE(TFILE), DIMENSION(:), POINTER  :: t_proc => NULL()     !< files/processors composing mpp 
     275      CHARACTER(LEN=lc)                  :: c_name = ''   !< base name  
     276      INTEGER(i4)                        :: i_id   = 0    !< mpp id 
     277 
     278      INTEGER(i4)                        :: i_niproc = 0  !< number of processors following i 
     279      INTEGER(i4)                        :: i_njproc = 0  !< number of processors following j 
     280      INTEGER(i4)                        :: i_nproc  = 0  !< total number of proccessors used 
     281      INTEGER(i4)                        :: i_preci = 1   !< i-direction overlap region length 
     282      INTEGER(i4)                        :: i_precj = 1   !< j-direction overlap region length 
     283      INTEGER(i4)                        :: i_ew    = -1  !< east-west overlap 
     284      INTEGER(i4)                        :: i_perio = -1  !< NEMO periodicity index 
     285      INTEGER(i4)                        :: i_pivot = -1  !< NEMO pivot point index F(0),T(1) 
     286 
     287      CHARACTER(LEN=lc)                  :: c_type = ''   !< type of the files (cdf, cdf4, dimg) 
     288      CHARACTER(LEN=lc)                  :: c_dom  = ''   !< type of domain (full, overlap, nooverlap) 
     289 
     290      INTEGER(i4)                        :: i_ndim = 0    !< number of dimensions used in mpp 
     291      TYPE(TDIM),  DIMENSION(ip_maxdim)  :: t_dim         !< global domain dimension 
     292 
     293      TYPE(TFILE), DIMENSION(:), POINTER :: t_proc => NULL()     !< files/processors composing mpp 
    206294 
    207295   END TYPE 
     296 
     297   INTERFACE mpp_get_use 
     298      MODULE PROCEDURE mpp__get_use_unit  
     299   END INTERFACE mpp_get_use 
     300 
     301   INTERFACE mpp_clean 
     302      MODULE PROCEDURE mpp__clean_unit  
     303      MODULE PROCEDURE mpp__clean_arr    
     304   END INTERFACE mpp_clean 
    208305 
    209306   INTERFACE mpp__check_dim 
     
    220317      MODULE PROCEDURE mpp__del_var_name 
    221318      MODULE PROCEDURE mpp__del_var_str 
     319      MODULE PROCEDURE mpp__del_var_mpp 
    222320   END INTERFACE mpp_del_var 
    223321 
     
    230328      MODULE PROCEDURE mpp__init_mask 
    231329      MODULE PROCEDURE mpp__init_var 
    232       MODULE PROCEDURE mpp__init_read 
     330      MODULE PROCEDURE mpp__init_file 
    233331   END INTERFACE mpp_init 
    234332 
    235    INTERFACE ASSIGNMENT(=) 
    236       MODULE PROCEDURE mpp__copy   ! copy mpp structure 
     333   INTERFACE mpp_copy 
     334      MODULE PROCEDURE mpp__copy_unit  ! copy mpp structure 
     335      MODULE PROCEDURE mpp__copy_arr   ! copy array of mpp structure 
    237336   END INTERFACE 
    238337 
     
    240339   !------------------------------------------------------------------- 
    241340   !> @brief 
    242    !> This subroutine copy mpp structure in another mpp 
    243    !> structure 
     341   !> This subroutine copy mpp structure in another one 
    244342   !> @details  
    245    !> mpp file are copied in a temporary table,  
     343   !> mpp file are copied in a temporary array,  
    246344   !> so input and output mpp structure do not point on the same  
    247345   !> "memory cell", and so on are independant.  
    248346   !> 
    249    !> @author J.Paul 
    250    !> - Nov, 2013- Initial Version 
    251    ! 
    252    !> @param[out] td_mpp1  : mpp structure 
    253    !> @param[in] td_mpp2  : mpp structure 
    254    !------------------------------------------------------------------- 
    255    ! @code 
    256    SUBROUTINE mpp__copy( td_mpp1, td_mpp2 ) 
     347   !> @warning do not use on the output of a function who create or read an 
     348   !> structure (ex: tl_file=file_copy(file_init()) is forbidden). 
     349   !> This will create memory leaks. 
     350   !> @warning to avoid infinite loop, do not use any function inside  
     351   !> this subroutine 
     352   !> 
     353   !> @author J.Paul 
     354   !> - November, 2013- Initial Version 
     355   !> @date November, 2014 
     356   !>    - use function instead of overload assignment operator  
     357   !> (to avoid memory leak) 
     358   ! 
     359   !> @param[in] td_mpp   mpp structure 
     360   !> @return copy of input mpp structure 
     361   !------------------------------------------------------------------- 
     362   FUNCTION mpp__copy_unit( td_mpp ) 
    257363      IMPLICIT NONE 
    258364      ! Argument 
    259       TYPE(TMPP), INTENT(OUT) :: td_mpp1 
    260       TYPE(TMPP), INTENT(IN)  :: td_mpp2 
     365      TYPE(TMPP), INTENT(IN)  :: td_mpp 
     366      ! function 
     367      TYPE(TMPP) :: mpp__copy_unit 
     368 
     369      ! local variable 
     370      TYPE(TFILE) :: tl_file 
    261371 
    262372      ! loop indices 
     
    264374      !---------------------------------------------------------------- 
    265375 
    266       CALL logger_trace("COPY: mpp "//TRIM(td_mpp2%c_name)//" in "//& 
    267       &  TRIM(td_mpp1%c_name)) 
     376      CALL logger_trace("MPP COPY: "//TRIM(td_mpp%c_name)//" in "//& 
     377      &  TRIM(mpp__copy_unit%c_name)) 
     378 
    268379      ! copy mpp variable 
    269       td_mpp1%c_name     = TRIM(td_mpp2%c_name) 
    270       td_mpp1%i_niproc   = td_mpp2%i_niproc 
    271       td_mpp1%i_njproc   = td_mpp2%i_njproc 
    272       td_mpp1%i_nproc    = td_mpp2%i_nproc 
    273       td_mpp1%i_preci    = td_mpp2%i_preci 
    274       td_mpp1%i_precj    = td_mpp2%i_precj 
    275       td_mpp1%c_type     = TRIM(td_mpp2%c_type) 
    276       td_mpp1%c_dom      = TRIM(td_mpp2%c_dom) 
    277       td_mpp1%i_ndim     = td_mpp2%i_ndim 
     380      mpp__copy_unit%c_name     = TRIM(td_mpp%c_name) 
     381      mpp__copy_unit%i_niproc   = td_mpp%i_niproc 
     382      mpp__copy_unit%i_njproc   = td_mpp%i_njproc 
     383      mpp__copy_unit%i_nproc    = td_mpp%i_nproc 
     384      mpp__copy_unit%i_preci    = td_mpp%i_preci 
     385      mpp__copy_unit%i_precj    = td_mpp%i_precj 
     386      mpp__copy_unit%c_type     = TRIM(td_mpp%c_type) 
     387      mpp__copy_unit%c_dom      = TRIM(td_mpp%c_dom) 
     388      mpp__copy_unit%i_ndim     = td_mpp%i_ndim 
     389      mpp__copy_unit%i_ew       = td_mpp%i_ew 
     390      mpp__copy_unit%i_perio    = td_mpp%i_perio 
     391      mpp__copy_unit%i_pivot    = td_mpp%i_pivot 
    278392 
    279393      ! copy dimension 
    280       td_mpp1%t_dim(:) = td_mpp2%t_dim(:) 
     394      mpp__copy_unit%t_dim(:) = dim_copy(td_mpp%t_dim(:)) 
    281395       
    282396      ! copy file structure 
    283       IF( ASSOCIATED(td_mpp1%t_proc) ) DEALLOCATE(td_mpp1%t_proc) 
    284       IF( ASSOCIATED(td_mpp2%t_proc) )THEN 
    285          ALLOCATE( td_mpp1%t_proc(td_mpp1%i_nproc) ) 
    286          DO ji=1,td_mpp1%i_nproc 
    287             td_mpp1%t_proc(ji) = td_mpp2%t_proc(ji) 
     397      IF( ASSOCIATED(mpp__copy_unit%t_proc) )THEN 
     398         CALL file_clean(mpp__copy_unit%t_proc(:)) 
     399         DEALLOCATE(mpp__copy_unit%t_proc) 
     400      ENDIF 
     401      IF( ASSOCIATED(td_mpp%t_proc) .AND. mpp__copy_unit%i_nproc > 0 )THEN 
     402         ALLOCATE( mpp__copy_unit%t_proc(mpp__copy_unit%i_nproc) ) 
     403         DO ji=1,mpp__copy_unit%i_nproc 
     404            tl_file = file_copy(td_mpp%t_proc(ji)) 
     405            mpp__copy_unit%t_proc(ji) = file_copy(tl_file) 
    288406         ENDDO 
    289       ENDIF 
    290  
    291    END SUBROUTINE mpp__copy 
    292    ! @endcode 
     407         ! clean 
     408         CALL file_clean(tl_file) 
     409      ENDIF 
     410 
     411   END FUNCTION mpp__copy_unit 
     412   !------------------------------------------------------------------- 
     413   !> @brief 
     414   !> This subroutine copy an array of mpp structure in another one 
     415   !> @details  
     416   !> mpp file are copied in a temporary array,  
     417   !> so input and output mpp structure do not point on the same  
     418   !> "memory cell", and so on are independant.  
     419   !> 
     420   !> @warning do not use on the output of a function who create or read an 
     421   !> structure (ex: tl_file=file_copy(file_init()) is forbidden). 
     422   !> This will create memory leaks. 
     423   !> @warning to avoid infinite loop, do not use any function inside  
     424   !> this subroutine 
     425   !> 
     426   !> @author J.Paul 
     427   !> - November, 2013- Initial Version 
     428   !> @date November, 2014 
     429   !>    - use function instead of overload assignment operator  
     430   !> (to avoid memory leak) 
     431   !> 
     432   !> @param[in] td_mpp   mpp structure 
     433   !> @return copy of input array of mpp structure 
     434   !------------------------------------------------------------------- 
     435   FUNCTION mpp__copy_arr( td_mpp ) 
     436      IMPLICIT NONE 
     437      ! Argument 
     438      TYPE(TMPP), DIMENSION(:), INTENT(IN)  :: td_mpp 
     439      ! function 
     440      TYPE(TMPP), DIMENSION(SIZE(td_mpp(:))) :: mpp__copy_arr 
     441 
     442      ! local variable 
     443      ! loop indices 
     444      INTEGER(i4) :: ji 
     445      !---------------------------------------------------------------- 
     446 
     447      DO ji=1,SIZE(td_mpp(:)) 
     448         mpp__copy_arr(ji)=mpp_copy(td_mpp(ji)) 
     449      ENDDO 
     450 
     451   END FUNCTION mpp__copy_arr 
    293452   !------------------------------------------------------------------- 
    294453   !> @brief This subroutine print some information about mpp strucutre. 
     
    297456   !> - Nov, 2013- Initial Version 
    298457   ! 
    299    !> @param[in] td_mpp : mpp structure 
    300    !------------------------------------------------------------------- 
    301    ! @code 
     458   !> @param[in] td_mpp mpp structure 
     459   !------------------------------------------------------------------- 
    302460   SUBROUTINE mpp_print(td_mpp) 
    303461      IMPLICIT NONE 
     
    307465 
    308466      ! local variable 
    309       INTEGER(i4), PARAMETER :: ip_freq = 4 
     467      INTEGER(i4), PARAMETER :: il_freq = 4 
    310468 
    311469      INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_proc 
     
    321479      !---------------------------------------------------------------- 
    322480 
    323       WRITE(*,'((a,a),2(/3x,a,a),6(/3x,a,i0))')& 
     481      WRITE(*,'((a,a),2(/3x,a,a),9(/3x,a,i0))')& 
    324482      &  "MPP : ",TRIM(td_mpp%c_name), & 
    325483      &  " type   : ",TRIM(td_mpp%c_type), & 
     
    330488      &  " preci  : ",td_mpp%i_preci, & 
    331489      &  " precj  : ",td_mpp%i_precj, & 
    332       &  " ndim   : ",td_mpp%i_ndim 
     490      &  " ndim   : ",td_mpp%i_ndim,  & 
     491      &  " overlap: ",td_mpp%i_ew, & 
     492      &  " perio  : ",td_mpp%i_perio, & 
     493      &  " pivot  : ",td_mpp%i_pivot 
    333494 
    334495      ! print dimension 
     
    363524               &  td_mpp%t_proc(ji)%i_lej 
    364525 
    365                !! attribute 
    366                !DO jj=1, td_mpp%t_proc(ji)%i_natt 
    367                !   CALL att_print(td_mpp%t_proc(ji)%t_att(jj)) 
    368                !ENDDO 
    369  
    370  
    371526            ENDDO 
     527 
     528            IF( td_mpp%t_proc(1)%i_nvar > 0 )THEN 
     529               WRITE(*,'(/a)') " Variable(s) used : " 
     530               DO ji=1,td_mpp%t_proc(1)%i_nvar 
     531                  WRITE(*,'(3x,a)') TRIM(td_mpp%t_proc(1)%t_var(ji)%c_name)  
     532               ENDDO 
     533            ENDIF 
    372534 
    373535         ELSE 
     
    387549               &  td_mpp%t_proc(ji)%i_lej 
    388550 
    389                !! attribute 
    390                !DO jj=1, td_mpp%t_proc(ji)%i_natt 
    391                !   CALL att_print(td_mpp%t_proc(ji)%t_att(jj)) 
    392                !ENDDO 
    393  
    394551            ENDDO 
    395552             
     553            IF( td_mpp%t_proc(1)%i_nvar > 0 )THEN 
     554               WRITE(*,'(/a)') " Variable(s) used : " 
     555               DO ji=1,td_mpp%t_proc(1)%i_nvar 
     556                  WRITE(*,'(3x,a)') TRIM(td_mpp%t_proc(1)%t_var(ji)%c_name)  
     557               ENDDO 
     558            ENDIF 
     559 
    396560            ALLOCATE( il_proc(td_mpp%i_niproc,td_mpp%i_njproc) ) 
    397561            ALLOCATE( il_lci(td_mpp%i_niproc,td_mpp%i_njproc) ) 
     
    407571 
    408572            jl = 1 
    409             DO jk = 1,(td_mpp%i_niproc-1)/ip_freq+1 
    410                jm = MIN(td_mpp%i_niproc, jl+ip_freq-1) 
     573            DO jk = 1,(td_mpp%i_niproc-1)/il_freq+1 
     574               jm = MIN(td_mpp%i_niproc, jl+il_freq-1) 
    411575               WRITE(*,*) 
    412576               WRITE(*,9401) (ji, ji = jl,jm) 
     
    419583                  WRITE(*,9400) ('***', ji = jl,jm-1) 
    420584               ENDDO 
    421                jl = jl+ip_freq 
     585               jl = jl+il_freq 
    422586            ENDDO 
    423587          
     
    439603 
    440604   END SUBROUTINE mpp_print 
    441    ! @endcode 
    442605   !------------------------------------------------------------------- 
    443606   !> @brief 
    444    !> This function initialised mpp structure, given file name, mask and number of 
    445    !> processor following I and J 
     607   !> This function initialise mpp structure, given file name,  
     608   !> and optionaly mask and number of processor following I and J 
    446609   !> @detail 
    447610   !> - If no total number of processor is defined (id_nproc), optimize  
     
    452615   ! 
    453616   !> @author J.Paul 
    454    !> @date Nov, 2013 
    455    ! 
    456    !> @param[in] cd_file : file name of one file composing mpp domain 
    457    !> @param[in] id_mask : domain mask 
    458    !> @param[in] id_niproc : number of processors following i 
    459    !> @param[in] id_njproc : number of processors following j 
    460    !> @param[in] id_nproc  : total number of processors 
    461    !> @param[in] id_preci  : i-direction overlap region 
    462    !> @param[in] id_precj  : j-direction overlap region 
    463    !> @param[in] cd_type   : type of the files (cdf, cdf4, dimg) 
     617   !> @date November, 2013 - Initial version 
     618   ! 
     619   !> @param[in] cd_file   file name of one file composing mpp domain 
     620   !> @param[in] id_mask   domain mask 
     621   !> @param[in] id_niproc number of processors following i 
     622   !> @param[in] id_njproc number of processors following j 
     623   !> @param[in] id_nproc  total number of processors 
     624   !> @param[in] id_preci  i-direction overlap region 
     625   !> @param[in] id_precj  j-direction overlap region 
     626   !> @param[in] cd_type   type of the files (cdf, cdf4, dimg) 
     627   !> @param[in] id_ew     east-west overlap 
     628   !> @param[in] id_perio  NEMO periodicity index 
     629   !> @param[in] id_pivot  NEMO pivot point index F(0),T(1) 
    464630   !> @return mpp structure 
    465631   !------------------------------------------------------------------- 
    466    !> @code 
    467632   TYPE(TMPP) FUNCTION mpp__init_mask(cd_file, id_mask,              & 
    468633   &                                  id_niproc, id_njproc, id_nproc,& 
    469634   &                                  id_preci, id_precj,            & 
    470                                       cd_type) 
     635                                      cd_type, id_ew, id_perio, id_pivot) 
    471636      IMPLICIT NONE 
    472637      ! Argument 
    473638      CHARACTER(LEN=*),            INTENT(IN) :: cd_file 
    474       INTEGER(i4), DIMENSION(:,:), INTENT(IN), OPTIONAL :: id_mask 
     639      INTEGER(i4), DIMENSION(:,:), INTENT(IN) :: id_mask 
    475640      INTEGER(i4),                 INTENT(IN), OPTIONAL :: id_niproc 
    476641      INTEGER(i4),                 INTENT(IN), OPTIONAL :: id_njproc 
     
    479644      INTEGER(i4),                 INTENT(IN), OPTIONAL :: id_precj 
    480645      CHARACTER(LEN=*),            INTENT(IN), OPTIONAL :: cd_type 
     646      INTEGER(i4),                 INTENT(IN), OPTIONAL :: id_ew 
     647      INTEGER(i4),                 INTENT(IN), OPTIONAL :: id_perio 
     648      INTEGER(i4),                 INTENT(IN), OPTIONAL :: id_pivot 
    481649 
    482650      ! local variable 
     
    494662      ! clean mpp 
    495663      CALL mpp_clean(mpp__init_mask) 
    496  
    497       ! get mpp name 
    498       mpp__init_mask%c_name=TRIM(file_rename(cd_file)) 
    499664 
    500665      ! check type 
     
    518683      ENDIF 
    519684 
    520       IF( PRESENT(id_mask) )THEN 
    521          ! get global domain dimension 
    522          il_shape(:)=SHAPE(id_mask) 
    523  
    524          tl_dim=dim_init('X',il_shape(1)) 
    525          CALL mpp_add_dim(mpp__init_mask, tl_dim) 
    526  
    527          tl_dim=dim_init('Y',il_shape(2)) 
    528          CALL mpp_add_dim(mpp__init_mask,tl_dim) 
    529       ENDIF 
     685      ! get mpp name 
     686      mpp__init_mask%c_name=TRIM(file_rename(cd_file)) 
     687 
     688      ! get global domain dimension 
     689      il_shape(:)=SHAPE(id_mask) 
     690 
     691      tl_dim=dim_init('X',il_shape(1)) 
     692      CALL mpp_add_dim(mpp__init_mask, tl_dim) 
     693 
     694      tl_dim=dim_init('Y',il_shape(2)) 
     695      CALL mpp_add_dim(mpp__init_mask, tl_dim) 
     696 
     697      ! clean 
     698      CALL dim_clean(tl_dim) 
    530699 
    531700      IF( (       PRESENT(id_niproc)  .AND. (.NOT. PRESENT(id_niproc))) .OR. & 
     
    546715      IF( PRESENT(id_precj) ) mpp__init_mask%i_precj= id_precj 
    547716 
     717      ! east-west overlap 
     718      IF( PRESENT(id_ew) ) mpp__init_mask%i_ew= id_ew 
     719      ! NEMO periodicity 
     720      IF( PRESENT(id_perio) ) mpp__init_mask%i_perio= id_perio 
     721      IF( PRESENT(id_pivot) ) mpp__init_mask%i_pivot= id_pivot 
     722 
    548723      IF( mpp__init_mask%i_nproc  /= 0 .AND. & 
    549724      &   mpp__init_mask%i_niproc /= 0 .AND. & 
     
    560735      ELSE 
    561736 
    562          IF( mpp__init_mask%i_niproc /= 0 .AND. mpp__init_mask%i_njproc /= 0 )THEN 
     737         IF( mpp__init_mask%i_niproc /= 0 .AND. & 
     738         &   mpp__init_mask%i_njproc /= 0 )THEN 
    563739            ! compute domain decomposition 
    564740            CALL mpp__compute( mpp__init_mask ) 
     
    570746 
    571747         ELSE 
    572             CALL logger_error("MPP INIT: can't define domain decomposition") 
    573             CALL logger_debug ("MPP INIT: maximum number of processor to be used "//& 
    574             &  "or number of processor following I and J direction must "//& 
    575             &  "be specified.") 
     748            CALL logger_warn("MPP INIT: number of processor to be used "//& 
     749            &                "not specify. force to one.") 
     750            mpp__init_mask%i_nproc  = 1 
     751            ! optimiz 
     752            CALL mpp__optimiz( mpp__init_mask, id_mask ) 
    576753         ENDIF 
     754         CALL logger_info("MPP INIT: domain decoposition : "//& 
     755         &  'niproc('//TRIM(fct_str(mpp__init_mask%i_niproc))//') * '//& 
     756         &  'njproc('//TRIM(fct_str(mpp__init_mask%i_njproc))//') = '//& 
     757         &  'nproc('//TRIM(fct_str(mpp__init_mask%i_nproc))//')' ) 
    577758 
    578759         ! get domain type 
     
    593774            mpp__init_mask%t_proc(ji)%c_type=TRIM(mpp__init_mask%c_type) 
    594775 
     776            ! clean 
     777            CALL dim_clean(tl_dim) 
    595778         ENDDO 
    596779 
     
    640823         CALL mpp_add_att(mpp__init_mask, tl_att)          
    641824 
     825         ! clean 
     826         CALL att_clean(tl_att) 
    642827      ENDIF 
    643828 
    644829   END FUNCTION mpp__init_mask 
    645    !> @endcode 
    646830   !------------------------------------------------------------------- 
    647831   !> @brief 
    648    !> This function initialised mpp structure, given variable strcuture  
    649    !> and number of processor following I and J 
     832   !> This function initialise mpp structure, given variable strcuture  
     833   !> and optionaly number of processor following I and J 
    650834   !> @detail 
    651835   !> - If no total number of processor is defined (id_nproc), optimize  
     
    656840   ! 
    657841   !> @author J.Paul 
    658    !> @date Nov, 2013 
    659    ! 
    660    !> @param[in] cd_file : file name of one file composing mpp domain 
    661    !> @param[in] td_var : variable structure 
    662    !> @param[in] id_niproc : number of processors following i 
    663    !> @param[in] id_njproc : number of processors following j 
    664    !> @param[in] id_nproc  : total number of processors 
    665    !> @param[in] id_preci  : i-direction overlap region 
    666    !> @param[in] id_precj  : j-direction overlap region 
    667    !> @param[in] cd_type   : type of the files (cdf, cdf4, dimg) 
     842   !> @date November, 2013 - Initial version 
     843   ! 
     844   !> @param[in] cd_file   file name of one file composing mpp domain 
     845   !> @param[in] td_var    variable structure 
     846   !> @param[in] id_niproc number of processors following i 
     847   !> @param[in] id_njproc number of processors following j 
     848   !> @param[in] id_nproc  total number of processors 
     849   !> @param[in] id_preci  i-direction overlap region 
     850   !> @param[in] id_precj  j-direction overlap region 
     851   !> @param[in] cd_type   type of the files (cdf, cdf4, dimg) 
     852   !> @param[in] id_perio  NEMO periodicity index 
     853   !> @param[in] id_pivot  NEMO pivot point index F(0),T(1) 
    668854   !> @return mpp structure 
    669855   !------------------------------------------------------------------- 
    670    !> @code 
    671856   TYPE(TMPP) FUNCTION mpp__init_var( cd_file, td_var,               & 
    672857   &                                  id_niproc, id_njproc, id_nproc,& 
    673    &                                  id_preci, id_precj, cd_type ) 
     858   &                                  id_preci, id_precj, cd_type,   & 
     859   &                                  id_perio, id_pivot ) 
    674860      IMPLICIT NONE 
    675861      ! Argument 
     
    682868      INTEGER(i4),      INTENT(IN), OPTIONAL :: id_precj 
    683869      CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: cd_type 
     870      INTEGER(i4),      INTENT(IN), OPTIONAL :: id_perio 
     871      INTEGER(i4),      INTENT(IN), OPTIONAL :: id_pivot 
    684872 
    685873      ! local variable 
    686       INTEGER(i4), DIMENSION(:,:), ALLOCATABLE :: il_mask 
     874      INTEGER(i4), DIMENSION(:,:,:), ALLOCATABLE :: il_mask 
    687875      !---------------------------------------------------------------- 
    688876 
    689877      IF( ASSOCIATED(td_var%d_value) )THEN 
    690          ALLOCATE( il_mask(td_var%t_dim(1)%i_len, td_var%t_dim(2)%i_len) ) 
    691          il_mask(:,:)=var_get_mask(td_var) 
     878         ALLOCATE( il_mask(td_var%t_dim(1)%i_len, & 
     879         &                 td_var%t_dim(2)%i_len, & 
     880         &                 td_var%t_dim(3)%i_len) ) 
     881         il_mask(:,:,:)=var_get_mask(td_var) 
    692882          
    693          mpp__init_var=mpp_init( cd_file, il_mask(:,:),         & 
     883         mpp__init_var=mpp_init( cd_file, il_mask(:,:,1),       & 
    694884         &                       id_niproc, id_njproc, id_nproc,& 
    695          &                       id_preci, id_precj, cd_type ) 
     885         &                       id_preci, id_precj, cd_type,   & 
     886         &                       id_ew=td_var%i_ew, & 
     887         &                       id_perio=id_perio, id_pivot=id_pivot) 
    696888 
    697889         DEALLOCATE(il_mask) 
     
    701893 
    702894   END FUNCTION mpp__init_var 
    703    !> @endcode 
    704    !------------------------------------------------------------------- 
    705    !> @brief This function initalise a mpp structure,  
    706    !> reading one restart dimg file, or some netcdf files. 
    707    ! 
     895   !------------------------------------------------------------------- 
     896   !> @brief This function initalise a mpp structure given file structure.  
    708897   !> @details  
    709    !> 
    710    !> @warning td_file should be not opened 
    711    !> 
    712    !> @author J.Paul 
    713    !> - Nov, 2013- Initial Version 
    714    ! 
    715    !> @param[in] td_file : file strcuture 
     898   !> It reads restart dimg files, or some netcdf files. 
     899   !> 
     900   !> @warning  
     901   !>  netcdf file must contains some attributes: 
     902   !>    - DOMAIN_number_total  
     903   !>    - DOMAIN_size_global 
     904   !>    - DOMAIN_number 
     905   !>    - DOMAIN_position_first 
     906   !>    - DOMAIN_position_last 
     907   !>    - DOMAIN_halo_size_start 
     908   !>    - DOMAIN_halo_size_end 
     909   !>  or the file is assume to be no mpp file. 
     910   !>   
     911   !>  
     912   !> 
     913   !> @author J.Paul 
     914   !> - November, 2013- Initial Version 
     915   ! 
     916   !> @param[in] td_file   file strcuture 
     917   !> @param[in] id_ew     east-west overlap 
     918   !> @param[in] id_perio  NEMO periodicity index 
     919   !> @param[in] id_pivot  NEMO pivot point index F(0),T(1) 
    716920   !> @return mpp structure 
    717921   !------------------------------------------------------------------- 
    718    ! @code 
    719    TYPE(TMPP) FUNCTION mpp__init_read( td_file ) 
     922   TYPE(TMPP) FUNCTION mpp__init_file( td_file, id_ew, id_perio, id_pivot ) 
    720923      IMPLICIT NONE 
    721924 
    722925      ! Argument 
    723926      TYPE(TFILE), INTENT(IN) :: td_file 
     927      INTEGER(i4), INTENT(IN), OPTIONAL :: id_ew 
     928      INTEGER(i4), INTENT(IN), OPTIONAL :: id_perio 
     929      INTEGER(i4), INTENT(IN), OPTIONAL :: id_pivot 
    724930 
    725931      ! local variable 
    726932      TYPE(TMPP)  :: tl_mpp 
     933       
    727934      TYPE(TFILE) :: tl_file 
     935       
    728936      TYPE(TDIM)  :: tl_dim 
     937 
    729938      TYPE(TATT)  :: tl_att 
     939 
    730940      INTEGER(i4) :: il_nproc 
    731941      INTEGER(i4) :: il_attid 
     
    737947 
    738948      ! clean mpp 
    739       CALL mpp_clean(mpp__init_read) 
     949      CALL mpp_clean(mpp__init_file) 
    740950 
    741951      ! check file type 
     
    743953         CASE('cdf') 
    744954            ! need to read all file to get domain decomposition 
    745  
    746             tl_file=td_file 
     955            tl_file=file_copy(td_file) 
    747956 
    748957            ! open file 
     
    750959 
    751960            ! read first file domain decomposition 
    752             tl_mpp=mpp__init_read_cdf(tl_file) 
     961            tl_mpp=mpp__init_file_cdf(tl_file) 
    753962 
    754963            ! get number of processor/file to be read 
     
    779988 
    780989                  ! read domain decomposition 
    781                   tl_mpp = mpp__init_read_cdf(tl_file) 
     990                  tl_mpp = mpp__init_file_cdf(tl_file) 
    782991                  IF( ji == 1 )THEN 
    783                      mpp__init_read=tl_mpp 
     992                     mpp__init_file=mpp_copy(tl_mpp) 
    784993                  ELSE 
    785                      IF( ANY( mpp__init_read%t_dim(1:2)%i_len /= & 
     994                     IF( ANY( mpp__init_file%t_dim(1:2)%i_len /= & 
    786995                                      tl_mpp%t_dim(1:2)%i_len) )THEN 
    787996 
    788                         CALL logger_error("INIT READ: dimension from file "//& 
     997                        CALL logger_error("MPP INIT READ: dimension from file "//& 
    789998                        &     TRIM(tl_file%c_name)//" and mpp strcuture "//& 
    790                         &     TRIM(mpp__init_read%c_name)//"differ ") 
     999                        &     TRIM(mpp__init_file%c_name)//"differ ") 
    7911000 
    7921001                     ELSE 
    7931002 
    7941003                        ! add processor to mpp strcuture 
    795                         CALL mpp__add_proc(mpp__init_read, tl_mpp%t_proc(1)) 
     1004                        CALL mpp__add_proc(mpp__init_file, tl_mpp%t_proc(1)) 
    7961005 
    7971006                     ENDIF 
     
    8021011 
    8031012               ENDDO 
    804                IF( mpp__init_read%i_nproc /= il_nproc )THEN 
    805                   CALL logger_error("INIT READ: some processors can't be added & 
     1013               IF( mpp__init_file%i_nproc /= il_nproc )THEN 
     1014                  CALL logger_error("MPP INIT READ: some processors can't be added & 
    8061015                  &               to mpp structure") 
    8071016               ENDIF 
    8081017 
    8091018            ELSE 
    810                mpp__init_read=tl_mpp 
     1019               mpp__init_file=mpp_copy(tl_mpp) 
    8111020            ENDIF 
    8121021 
    8131022            ! mpp type 
    814             mpp__init_read%c_type=TRIM(td_file%c_type) 
     1023            mpp__init_file%c_type=TRIM(td_file%c_type) 
    8151024 
    8161025            ! mpp domain type 
    817             CALL mpp_get_dom(mpp__init_read) 
     1026            CALL mpp_get_dom(mpp__init_file) 
    8181027 
    8191028            ! create some attributes for domain decomposition (use with dimg file) 
    820             tl_att=att_init( "DOMAIN_number_total", mpp__init_read%i_nproc ) 
    821             CALL mpp_add_att(mpp__init_read, tl_att) 
    822  
    823             tl_att=att_init( "DOMAIN_I_position_first", mpp__init_read%t_proc(:)%i_impp ) 
    824             CALL mpp_add_att(mpp__init_read, tl_att) 
    825  
    826             tl_att=att_init( "DOMAIN_J_position_first", mpp__init_read%t_proc(:)%i_jmpp ) 
    827             CALL mpp_add_att(mpp__init_read, tl_att) 
    828  
    829             tl_att=att_init( "DOMAIN_I_position_last", mpp__init_read%t_proc(:)%i_lci ) 
    830             CALL mpp_add_att(mpp__init_read, tl_att) 
    831  
    832             tl_att=att_init( "DOMAIN_J_position_last", mpp__init_read%t_proc(:)%i_lcj ) 
    833             CALL mpp_add_att(mpp__init_read, tl_att) 
    834  
    835             tl_att=att_init( "DOMAIN_I_halo_size_start", mpp__init_read%t_proc(:)%i_ldi ) 
    836             CALL mpp_add_att(mpp__init_read, tl_att) 
    837  
    838             tl_att=att_init( "DOMAIN_J_halo_size_start", mpp__init_read%t_proc(:)%i_ldj ) 
    839             CALL mpp_add_att(mpp__init_read, tl_att) 
    840  
    841             tl_att=att_init( "DOMAIN_I_halo_size_end", mpp__init_read%t_proc(:)%i_lei ) 
    842             CALL mpp_add_att(mpp__init_read, tl_att) 
    843  
    844             tl_att=att_init( "DOMAIN_J_halo_size_end", mpp__init_read%t_proc(:)%i_lej ) 
    845             CALL mpp_add_att(mpp__init_read, tl_att) 
     1029            tl_att=att_init( "DOMAIN_number_total", mpp__init_file%i_nproc ) 
     1030            CALL mpp_add_att(mpp__init_file, tl_att) 
     1031 
     1032            tl_att=att_init( "DOMAIN_I_position_first", mpp__init_file%t_proc(:)%i_impp ) 
     1033            CALL mpp_add_att(mpp__init_file, tl_att) 
     1034 
     1035            tl_att=att_init( "DOMAIN_J_position_first", mpp__init_file%t_proc(:)%i_jmpp ) 
     1036            CALL mpp_add_att(mpp__init_file, tl_att) 
     1037 
     1038            tl_att=att_init( "DOMAIN_I_position_last", mpp__init_file%t_proc(:)%i_lci ) 
     1039            CALL mpp_add_att(mpp__init_file, tl_att) 
     1040 
     1041            tl_att=att_init( "DOMAIN_J_position_last", mpp__init_file%t_proc(:)%i_lcj ) 
     1042            CALL mpp_add_att(mpp__init_file, tl_att) 
     1043 
     1044            tl_att=att_init( "DOMAIN_I_halo_size_start", mpp__init_file%t_proc(:)%i_ldi ) 
     1045            CALL mpp_add_att(mpp__init_file, tl_att) 
     1046 
     1047            tl_att=att_init( "DOMAIN_J_halo_size_start", mpp__init_file%t_proc(:)%i_ldj ) 
     1048            CALL mpp_add_att(mpp__init_file, tl_att) 
     1049 
     1050            tl_att=att_init( "DOMAIN_I_halo_size_end", mpp__init_file%t_proc(:)%i_lei ) 
     1051            CALL mpp_add_att(mpp__init_file, tl_att) 
     1052 
     1053            tl_att=att_init( "DOMAIN_J_halo_size_end", mpp__init_file%t_proc(:)%i_lej ) 
     1054            CALL mpp_add_att(mpp__init_file, tl_att) 
    8461055             
     1056            ! clean 
     1057            CALL mpp_clean(tl_mpp) 
     1058            CALL att_clean(tl_att) 
    8471059 
    8481060         CASE('dimg') 
    8491061            ! domain decomposition could be read in one file 
    8501062 
    851             tl_file=td_file 
     1063            tl_file=file_copy(td_file) 
    8521064            ! open file 
     1065            CALL logger_debug("MPP INIT READ: open file "//TRIM(tl_file%c_name)) 
    8531066            CALL iom_open(tl_file) 
    8541067 
     1068            CALL logger_debug("MPP INIT READ: read mpp structure ") 
    8551069            ! read mpp structure 
    856             mpp__init_read=mpp__init_read_rstdimg(tl_file) 
     1070            mpp__init_file=mpp__init_file_rstdimg(tl_file) 
    8571071 
    8581072            ! mpp type 
    859             mpp__init_read%c_type=TRIM(td_file%c_type) 
     1073            mpp__init_file%c_type=TRIM(td_file%c_type) 
    8601074 
    8611075            ! mpp domain type 
    862             CALL mpp_get_dom(mpp__init_read) 
     1076            CALL logger_debug("MPP INIT READ: mpp_get_dom ") 
     1077            CALL mpp_get_dom(mpp__init_file) 
    8631078 
    8641079            ! get processor size 
    865             DO ji=1,mpp__init_read%i_nproc 
    866  
    867                il_shape(:)=mpp_get_proc_size( mpp__init_read, ji ) 
     1080            CALL logger_debug("MPP INIT READ: get processor size ") 
     1081            DO ji=1,mpp__init_file%i_nproc 
     1082 
     1083               il_shape(:)=mpp_get_proc_size( mpp__init_file, ji ) 
    8681084 
    8691085               tl_dim=dim_init('X',il_shape(1)) 
    870                CALL file_add_dim(mpp__init_read%t_proc(ji), tl_dim) 
     1086               CALL file_add_dim(mpp__init_file%t_proc(ji), tl_dim) 
    8711087 
    8721088               tl_dim=dim_init('Y',il_shape(2)) 
    873                CALL file_add_dim(mpp__init_read%t_proc(ji), tl_dim)             
     1089               CALL file_add_dim(mpp__init_file%t_proc(ji), tl_dim)             
     1090 
     1091               ! clean 
     1092               CALL dim_clean(tl_dim) 
    8741093 
    8751094            ENDDO 
     
    8791098 
    8801099         CASE DEFAULT 
    881             CALL logger_error("INIT READ: invalid type for file "//& 
     1100            CALL logger_error("MPP INIT READ: invalid type for file "//& 
    8821101            &              TRIM(tl_file%c_name)) 
    8831102      END SELECT 
    8841103 
    885    END FUNCTION mpp__init_read 
    886    ! @endcode 
     1104      ! east west overlap 
     1105      IF( PRESENT(id_ew) ) mpp__init_file%i_ew=id_ew 
     1106      ! NEMO periodicity 
     1107      IF( PRESENT(id_perio) )THEN 
     1108         mpp__init_file%i_perio= id_perio 
     1109         SELECT CASE(id_perio) 
     1110         CASE(3,4) 
     1111            mpp__init_file%i_pivot=1 
     1112         CASE(5,6) 
     1113            mpp__init_file%i_pivot=0 
     1114         CASE DEFAULT 
     1115            mpp__init_file%i_pivot=1 
     1116         END SELECT 
     1117      ENDIF 
     1118 
     1119      IF( PRESENT(id_pivot) ) mpp__init_file%i_pivot= id_pivot 
     1120 
     1121      ! clean  
     1122      CALL file_clean(tl_file) 
     1123 
     1124      CALL logger_debug("MPP INIT READ: fin init_read ") 
     1125   END FUNCTION mpp__init_file 
    8871126   !------------------------------------------------------------------- 
    8881127   !> @brief This function initalise a mpp structure,  
     
    8921131   ! 
    8931132   !> @author J.Paul 
    894    !> - Nov, 2013- Initial Version 
    895    ! 
    896    !> @param[in] td_file : file strcuture 
     1133   !> - November, 2013- Initial Version 
     1134   !> 
     1135   !> @param[in] td_file   file strcuture 
    8971136   !> @return mpp structure 
    8981137   !------------------------------------------------------------------- 
    899    ! @code 
    900    TYPE(TMPP) FUNCTION mpp__init_read_cdf( td_file ) 
     1138   TYPE(TMPP) FUNCTION mpp__init_file_cdf( td_file ) 
    9011139      IMPLICIT NONE 
    9021140 
     
    9061144      ! local variable 
    9071145      INTEGER(i4) :: il_attid  ! attribute id 
     1146       
    9081147      LOGICAL     :: ll_exist 
    9091148      LOGICAL     :: ll_open 
    9101149 
    9111150      TYPE(TATT)  :: tl_att 
     1151 
     1152      TYPE(TDIM)  :: tl_dim 
     1153       
    9121154      TYPE(TFILE) :: tl_proc 
    9131155      !---------------------------------------------------------------- 
    9141156 
    915       CALL logger_trace(" INIT READ: netcdf file "//TRIM(td_file%c_name)) 
     1157      CALL logger_trace("MPP INIT READ: netcdf file "//TRIM(td_file%c_name)) 
    9161158 
    9171159      INQUIRE( FILE=TRIM(td_file%c_name), EXIST=ll_exist, OPENED=ll_open ) 
     
    9211163         IF( td_file%i_id == 0 )THEN 
    9221164            CALL logger_info(" id "//TRIM(fct_str(td_file%i_id)))  
    923             CALL logger_error("INIT READ: netcdf file "//TRIM(td_file%c_name)//& 
     1165            CALL logger_error("MPP INIT READ: netcdf file "//TRIM(td_file%c_name)//& 
    9241166            &  " not opened") 
    9251167         ELSE 
    9261168 
    9271169            ! get mpp name 
    928             mpp__init_read_cdf%c_name=TRIM( file_rename(td_file%c_name) ) 
     1170            mpp__init_file_cdf%c_name=TRIM( file_rename(td_file%c_name) ) 
    9291171 
    9301172            ! add type 
    931             mpp__init_read_cdf%c_type="cdf" 
     1173            mpp__init_file_cdf%c_type="cdf" 
    9321174 
    9331175            ! global domain size 
     
    9371179            ENDIF 
    9381180            IF( il_attid /= 0 )THEN 
    939                mpp__init_read_cdf%t_dim(1)= & 
    940                &  dim_init('X',INT(td_file%t_att(il_attid)%d_value(1))) 
    941                mpp__init_read_cdf%t_dim(2)= & 
    942                &  dim_init('Y',INT(td_file%t_att(il_attid)%d_value(2))) 
    943             ELSE 
    944                mpp__init_read_cdf%t_dim(1)= & 
    945                &  dim_init( td_file%t_dim(1)%c_name, td_file%t_dim(1)%i_len) 
    946                mpp__init_read_cdf%t_dim(2)= & 
    947                &  dim_init( td_file%t_dim(2)%c_name, td_file%t_dim(2)%i_len) 
    948  
    949             ENDIF 
    950             mpp__init_read_cdf%t_dim(3)= & 
    951             &  dim_init( td_file%t_dim(3)%c_name, td_file%t_dim(1)%i_len) 
    952             mpp__init_read_cdf%t_dim(4)= & 
    953             &  dim_init( td_file%t_dim(4)%c_name, td_file%t_dim(2)%i_len) 
     1181               tl_dim=dim_init('X',INT(td_file%t_att(il_attid)%d_value(1))) 
     1182               CALL mpp_add_dim(mpp__init_file_cdf,tl_dim) 
     1183 
     1184               tl_dim=dim_init('Y',INT(td_file%t_att(il_attid)%d_value(2))) 
     1185               CALL mpp_add_dim(mpp__init_file_cdf,tl_dim) 
     1186            ELSE ! assume only one file (not mpp) 
     1187               tl_dim=dim_init( td_file%t_dim(1)%c_name, td_file%t_dim(1)%i_len) 
     1188               CALL mpp_add_dim(mpp__init_file_cdf,tl_dim) 
     1189 
     1190               tl_dim=dim_init( td_file%t_dim(2)%c_name, td_file%t_dim(2)%i_len) 
     1191               CALL mpp_add_dim(mpp__init_file_cdf,tl_dim) 
     1192            ENDIF 
     1193            tl_dim=dim_init( td_file%t_dim(3)%c_name, td_file%t_dim(3)%i_len) 
     1194            CALL mpp_add_dim(mpp__init_file_cdf,tl_dim) 
     1195 
     1196            tl_dim=dim_init( td_file%t_dim(4)%c_name, td_file%t_dim(4)%i_len) 
     1197            CALL mpp_add_dim(mpp__init_file_cdf,tl_dim) 
    9541198 
    9551199            ! initialise file/processor 
    956             tl_proc=td_file 
     1200            tl_proc=file_copy(td_file) 
    9571201 
    9581202            ! processor id 
     
    9681212 
    9691213            ! processor dimension 
    970             tl_proc%t_dim(:)=td_file%t_dim(:) 
     1214            tl_proc%t_dim(:)=dim_copy(td_file%t_dim(:)) 
    9711215 
    9721216            ! DOMAIN_position_first 
     
    9921236               tl_proc%i_lcj = INT(td_file%t_att(il_attid)%d_value(2)) + tl_proc%i_jmpp 
    9931237            ELSE 
    994                tl_proc%i_lci = mpp__init_read_cdf%t_dim(1)%i_len 
    995                tl_proc%i_lcj = mpp__init_read_cdf%t_dim(2)%i_len 
     1238               tl_proc%i_lci = mpp__init_file_cdf%t_dim(1)%i_len 
     1239               tl_proc%i_lcj = mpp__init_file_cdf%t_dim(2)%i_len 
    9961240            ENDIF 
    9971241 
     
    10181262               tl_proc%i_lej = INT(td_file%t_att(il_attid)%d_value(2)) 
    10191263            ELSE 
    1020                tl_proc%i_lei = mpp__init_read_cdf%t_dim(1)%i_len 
    1021                tl_proc%i_lej = mpp__init_read_cdf%t_dim(2)%i_len 
     1264               tl_proc%i_lei = mpp__init_file_cdf%t_dim(1)%i_len 
     1265               tl_proc%i_lej = mpp__init_file_cdf%t_dim(2)%i_len 
    10221266            ENDIF 
    10231267 
    10241268            ! add attributes 
    10251269            tl_att=att_init( "DOMAIN_size_global", & 
    1026             &                mpp__init_read_cdf%t_dim(:)%i_len) 
     1270            &                mpp__init_file_cdf%t_dim(:)%i_len) 
    10271271            CALL file_move_att(tl_proc, tl_att) 
    10281272 
     
    10471291 
    10481292            ! add processor to mpp structure 
    1049             CALL mpp__add_proc(mpp__init_read_cdf, tl_proc) 
    1050  
     1293            CALL mpp__add_proc(mpp__init_file_cdf, tl_proc) 
     1294 
     1295            ! clean  
     1296            CALL file_clean(tl_proc) 
     1297            CALL att_clean(tl_att) 
    10511298         ENDIF 
    10521299 
    10531300      ELSE 
    10541301 
    1055          CALL logger_error("INIT READ: netcdf file "//TRIM(td_file%c_name)//& 
     1302         CALL logger_error("MPP INIT READ: netcdf file "//TRIM(td_file%c_name)//& 
    10561303         &  " do not exist") 
    10571304 
    10581305      ENDIF       
    1059    END FUNCTION mpp__init_read_cdf 
    1060    ! @endcode 
     1306   END FUNCTION mpp__init_file_cdf 
    10611307   !------------------------------------------------------------------- 
    10621308   !> @brief This function initalise a mpp structure,  
     
    10661312   ! 
    10671313   !> @author J.Paul 
    1068    !> - Nov, 2013- Initial Version 
    1069    ! 
    1070    !> @param[in] td_file : file strcuture 
     1314   !> - November, 2013- Initial Version 
     1315   ! 
     1316   !> @param[in] td_file   file strcuture 
    10711317   !> @return mpp structure 
    10721318   !------------------------------------------------------------------- 
    1073    ! @code 
    1074    TYPE(TMPP) FUNCTION mpp__init_read_rstdimg( td_file ) 
     1319   TYPE(TMPP) FUNCTION mpp__init_file_rstdimg( td_file ) 
    10751320      IMPLICIT NONE 
    10761321 
     
    10791324 
    10801325      ! local variable 
    1081       INTEGER(i4) :: il_status 
    1082       INTEGER(i4) :: il_recl                          ! record length  
    1083       INTEGER(i4) :: il_nx, il_ny, il_nz              ! x,y,z dimension  
    1084       INTEGER(i4) :: il_n0d, il_n1d, il_n2d, il_n3d   ! number of 0/1/2/3D variables  
    1085       INTEGER(i4) :: il_iglo, il_jglo                 ! domain global size 
    1086       INTEGER(i4) :: il_rhd                           ! record of the header infos 
    1087       INTEGER(i4) :: il_pni, il_pnj, il_pnij          ! domain decomposition 
    1088       INTEGER(i4) :: il_area                          ! domain index 
    1089  
    1090       LOGICAL     ::  ll_exist 
    1091       LOGICAL     ::  ll_open 
     1326      INTEGER(i4)       :: il_status 
     1327      INTEGER(i4)       :: il_recl                          ! record length  
     1328      INTEGER(i4)       :: il_nx, il_ny, il_nz              ! x,y,z dimension  
     1329      INTEGER(i4)       :: il_n0d, il_n1d, il_n2d, il_n3d   ! number of 0/1/2/3D variables  
     1330      INTEGER(i4)       :: il_iglo, il_jglo                 ! domain global size 
     1331      INTEGER(i4)       :: il_rhd                           ! record of the header infos 
     1332      INTEGER(i4)       :: il_pni, il_pnj, il_pnij          ! domain decomposition 
     1333      INTEGER(i4)       :: il_area                          ! domain index 
     1334 
     1335      LOGICAL           ::  ll_exist 
     1336      LOGICAL           ::  ll_open 
    10921337 
    10931338      CHARACTER(LEN=lc) :: cl_file 
    10941339 
    1095       TYPE(TDIM)  :: tl_dim ! dimension structure 
    1096       TYPE(TATT)  :: tl_att 
     1340      TYPE(TDIM)        :: tl_dim ! dimension structure 
     1341      TYPE(TATT)        :: tl_att 
     1342      TYPE(TFILE)       :: tl_proc 
    10971343 
    10981344      ! loop indices 
     
    11041350 
    11051351         IF( .NOT. ll_open )THEN 
    1106             CALL logger_error("INIT READ: dimg file "//TRIM(td_file%c_name)//& 
     1352            CALL logger_error("MPP INIT READ: dimg file "//TRIM(td_file%c_name)//& 
    11071353            &  " not opened") 
    11081354         ELSE 
     
    11181364            CALL fct_err(il_status) 
    11191365            IF( il_status /= 0 )THEN 
    1120                CALL logger_error("INIT READ: read first line header of "//& 
     1366               CALL logger_error("MPP INIT READ: read first line header of "//& 
    11211367               &              TRIM(td_file%c_name)) 
    11221368            ENDIF 
    11231369 
    11241370            ! get mpp name 
    1125             mpp__init_read_rstdimg%c_name=TRIM( file_rename(td_file%c_name) ) 
     1371            mpp__init_file_rstdimg%c_name=TRIM( file_rename(td_file%c_name) ) 
     1372 
     1373            ! add type 
     1374            mpp__init_file_rstdimg%c_type="dimg" 
    11261375 
    11271376            ! number of processors to be read 
    1128             mpp__init_read_rstdimg%i_nproc  = il_pnij 
    1129             mpp__init_read_rstdimg%i_niproc = il_pni 
    1130             mpp__init_read_rstdimg%i_njproc = il_pnj 
    1131  
    1132             IF( ASSOCIATED(mpp__init_read_rstdimg%t_proc) )THEN 
    1133                DEALLOCATE(mpp__init_read_rstdimg%t_proc) 
    1134             ENDIF 
    1135             ALLOCATE( mpp__init_read_rstdimg%t_proc(il_pnij) , stat=il_status ) 
     1377            mpp__init_file_rstdimg%i_nproc  = il_pnij 
     1378            mpp__init_file_rstdimg%i_niproc = il_pni 
     1379            mpp__init_file_rstdimg%i_njproc = il_pnj 
     1380 
     1381            IF( ASSOCIATED(mpp__init_file_rstdimg%t_proc) )THEN 
     1382               CALL file_clean(mpp__init_file_rstdimg%t_proc(:)) 
     1383               DEALLOCATE(mpp__init_file_rstdimg%t_proc) 
     1384            ENDIF 
     1385            ALLOCATE( mpp__init_file_rstdimg%t_proc(il_pnij) , stat=il_status ) 
     1386 
     1387            tl_proc=file_copy(td_file) 
     1388            ! remove dimension from file 
     1389            CALL dim_clean(tl_proc%t_dim(:)) 
     1390            ! initialise file/processors 
     1391            DO ji=1,mpp__init_file_rstdimg%i_nproc 
     1392               mpp__init_file_rstdimg%t_proc(ji)=file_copy(tl_proc) 
     1393            ENDDO 
     1394 
    11361395            IF( il_status /= 0 )THEN 
    1137                CALL logger_error("INIT READ: not enough space to read domain & 
     1396               CALL logger_error("MPP INIT READ: not enough space to read domain & 
    11381397               &              decomposition in file "//TRIM(td_file%c_name)) 
    11391398            ENDIF 
     
    11481407            &     il_area,                         & 
    11491408            &     il_iglo, il_jglo,                & 
    1150             &     mpp__init_read_rstdimg%t_proc(:)%i_lci,    & 
    1151             &     mpp__init_read_rstdimg%t_proc(:)%i_lcj,    & 
    1152             &     mpp__init_read_rstdimg%t_proc(:)%i_ldi,    & 
    1153             &     mpp__init_read_rstdimg%t_proc(:)%i_ldj,    & 
    1154             &     mpp__init_read_rstdimg%t_proc(:)%i_lei,    & 
    1155             &     mpp__init_read_rstdimg%t_proc(:)%i_lej,    & 
    1156             &     mpp__init_read_rstdimg%t_proc(:)%i_impp,   & 
    1157             &     mpp__init_read_rstdimg%t_proc(:)%i_jmpp 
     1409            &     mpp__init_file_rstdimg%t_proc(:)%i_lci,    & 
     1410            &     mpp__init_file_rstdimg%t_proc(:)%i_lcj,    & 
     1411            &     mpp__init_file_rstdimg%t_proc(:)%i_ldi,    & 
     1412            &     mpp__init_file_rstdimg%t_proc(:)%i_ldj,    & 
     1413            &     mpp__init_file_rstdimg%t_proc(:)%i_lei,    & 
     1414            &     mpp__init_file_rstdimg%t_proc(:)%i_lej,    & 
     1415            &     mpp__init_file_rstdimg%t_proc(:)%i_impp,   & 
     1416            &     mpp__init_file_rstdimg%t_proc(:)%i_jmpp 
    11581417            CALL fct_err(il_status) 
    11591418            IF( il_status /= 0 )THEN 
    1160                CALL logger_error("INIT READ: read first line of "//& 
     1419               CALL logger_error("MPP INIT READ: read first line of "//& 
    11611420               &              TRIM(td_file%c_name)) 
    11621421            ENDIF 
    11631422 
    1164             ! mpp dimension 
     1423            ! global domain size 
    11651424            tl_dim=dim_init('X',il_iglo) 
    1166             CALL mpp_add_dim(mpp__init_read_rstdimg,tl_dim) 
     1425            CALL mpp_add_dim(mpp__init_file_rstdimg,tl_dim) 
    11671426            tl_dim=dim_init('Y',il_jglo) 
    1168             CALL mpp_add_dim(mpp__init_read_rstdimg,tl_dim) 
    1169  
    1170             DO ji=1,mpp__init_read_rstdimg%i_nproc 
     1427            CALL mpp_add_dim(mpp__init_file_rstdimg,tl_dim) 
     1428 
     1429            tl_dim=dim_init('Z',il_nz) 
     1430            CALL mpp_add_dim(mpp__init_file_rstdimg,tl_dim) 
     1431 
     1432            DO ji=1,mpp__init_file_rstdimg%i_nproc 
    11711433               ! get file name 
    11721434               cl_file =  file_rename(td_file%c_name,ji) 
    1173                mpp__init_read_rstdimg%t_proc(ji)%c_name = TRIM(cl_file) 
     1435               mpp__init_file_rstdimg%t_proc(ji)%c_name = TRIM(cl_file) 
    11741436               ! update processor id 
    1175                mpp__init_read_rstdimg%t_proc(ji)%i_pid=ji 
     1437               mpp__init_file_rstdimg%t_proc(ji)%i_pid=ji 
    11761438 
    11771439               ! add attributes 
    11781440               tl_att=att_init( "DOMAIN_number", ji ) 
    1179                CALL file_move_att(mpp__init_read_rstdimg%t_proc(ji), tl_att)  
     1441               CALL file_move_att(mpp__init_file_rstdimg%t_proc(ji), tl_att)  
    11801442 
    11811443               tl_att=att_init( "DOMAIN_position_first", & 
    1182                &                (/mpp__init_read_rstdimg%t_proc(ji)%i_impp, & 
    1183                &                  mpp__init_read_rstdimg%t_proc(ji)%i_jmpp /) ) 
    1184                CALL file_move_att(mpp__init_read_rstdimg%t_proc(ji), tl_att) 
     1444               &                (/mpp__init_file_rstdimg%t_proc(ji)%i_impp, & 
     1445               &                  mpp__init_file_rstdimg%t_proc(ji)%i_jmpp /) ) 
     1446               CALL file_move_att(mpp__init_file_rstdimg%t_proc(ji), tl_att) 
    11851447 
    11861448               tl_att=att_init( "DOMAIN_position_last", & 
    1187                &                (/mpp__init_read_rstdimg%t_proc(ji)%i_lci, & 
    1188                &                  mpp__init_read_rstdimg%t_proc(ji)%i_lcj /) ) 
    1189                CALL file_move_att(mpp__init_read_rstdimg%t_proc(ji), tl_att) 
     1449               &                (/mpp__init_file_rstdimg%t_proc(ji)%i_lci, & 
     1450               &                  mpp__init_file_rstdimg%t_proc(ji)%i_lcj /) ) 
     1451               CALL file_move_att(mpp__init_file_rstdimg%t_proc(ji), tl_att) 
    11901452 
    11911453               tl_att=att_init( "DOMAIN_halo_size_start", & 
    1192                &                (/mpp__init_read_rstdimg%t_proc(ji)%i_ldi, & 
    1193                &                  mpp__init_read_rstdimg%t_proc(ji)%i_ldj /) ) 
    1194                CALL file_move_att(mpp__init_read_rstdimg%t_proc(ji), tl_att)                
     1454               &                (/mpp__init_file_rstdimg%t_proc(ji)%i_ldi, & 
     1455               &                  mpp__init_file_rstdimg%t_proc(ji)%i_ldj /) ) 
     1456               CALL file_move_att(mpp__init_file_rstdimg%t_proc(ji), tl_att)                
    11951457 
    11961458               tl_att=att_init( "DOMAIN_halo_size_end", & 
    1197                &                (/mpp__init_read_rstdimg%t_proc(ji)%i_lei, & 
    1198                &                  mpp__init_read_rstdimg%t_proc(ji)%i_lej /) ) 
    1199                CALL file_move_att(mpp__init_read_rstdimg%t_proc(ji), tl_att) 
     1459               &                (/mpp__init_file_rstdimg%t_proc(ji)%i_lei, & 
     1460               &                  mpp__init_file_rstdimg%t_proc(ji)%i_lej /) ) 
     1461               CALL file_move_att(mpp__init_file_rstdimg%t_proc(ji), tl_att) 
    12001462            ENDDO 
    1201        
     1463  
    12021464            ! add type 
    1203             mpp__init_read_rstdimg%t_proc(:)%c_type="dimg" 
     1465            mpp__init_file_rstdimg%t_proc(:)%c_type="dimg" 
    12041466 
    12051467            ! add attributes 
    12061468            tl_att=att_init( "DOMAIN_size_global", & 
    1207             &                mpp__init_read_rstdimg%t_dim(:)%i_len) 
    1208             CALL mpp_move_att(mpp__init_read_rstdimg, tl_att) 
     1469            &                mpp__init_file_rstdimg%t_dim(:)%i_len) 
     1470            CALL mpp_move_att(mpp__init_file_rstdimg, tl_att) 
    12091471 
    12101472            tl_att=att_init( "DOMAIN_number_total", & 
    1211             &                 mpp__init_read_rstdimg%i_nproc ) 
    1212             CALL mpp_add_att(mpp__init_read_rstdimg, tl_att) 
     1473            &                 mpp__init_file_rstdimg%i_nproc ) 
     1474            CALL mpp_move_att(mpp__init_file_rstdimg, tl_att) 
    12131475 
    12141476            tl_att=att_init( "DOMAIN_I_number_total", & 
    1215             &                 mpp__init_read_rstdimg%i_niproc ) 
    1216             CALL mpp_add_att(mpp__init_read_rstdimg, tl_att) 
     1477            &                 mpp__init_file_rstdimg%i_niproc ) 
     1478            CALL mpp_move_att(mpp__init_file_rstdimg, tl_att) 
    12171479 
    12181480            tl_att=att_init( "DOMAIN_J_number_total", & 
    1219             &                 mpp__init_read_rstdimg%i_njproc ) 
    1220             CALL mpp_add_att(mpp__init_read_rstdimg, tl_att) 
     1481            &                 mpp__init_file_rstdimg%i_njproc ) 
     1482            CALL mpp_move_att(mpp__init_file_rstdimg, tl_att) 
    12211483 
    12221484            tl_att=att_init( "DOMAIN_I_position_first", & 
    1223             &                 mpp__init_read_rstdimg%t_proc(:)%i_impp ) 
    1224             CALL mpp_add_att(mpp__init_read_rstdimg, tl_att) 
     1485            &                 mpp__init_file_rstdimg%t_proc(:)%i_impp ) 
     1486            CALL mpp_move_att(mpp__init_file_rstdimg, tl_att) 
    12251487 
    12261488            tl_att=att_init( "DOMAIN_J_position_first", & 
    1227             &                 mpp__init_read_rstdimg%t_proc(:)%i_jmpp ) 
    1228             CALL mpp_add_att(mpp__init_read_rstdimg, tl_att) 
     1489            &                 mpp__init_file_rstdimg%t_proc(:)%i_jmpp ) 
     1490            CALL mpp_move_att(mpp__init_file_rstdimg, tl_att) 
    12291491 
    12301492            tl_att=att_init( "DOMAIN_I_position_last", & 
    1231             &                 mpp__init_read_rstdimg%t_proc(:)%i_lci ) 
    1232             CALL mpp_add_att(mpp__init_read_rstdimg, tl_att) 
     1493            &                 mpp__init_file_rstdimg%t_proc(:)%i_lci ) 
     1494            CALL mpp_move_att(mpp__init_file_rstdimg, tl_att) 
    12331495 
    12341496            tl_att=att_init( "DOMAIN_J_position_last", & 
    1235             &                 mpp__init_read_rstdimg%t_proc(:)%i_lcj ) 
    1236             CALL mpp_add_att(mpp__init_read_rstdimg, tl_att) 
     1497            &                 mpp__init_file_rstdimg%t_proc(:)%i_lcj ) 
     1498            CALL mpp_move_att(mpp__init_file_rstdimg, tl_att) 
    12371499 
    12381500            tl_att=att_init( "DOMAIN_I_halo_size_start", & 
    1239             &                 mpp__init_read_rstdimg%t_proc(:)%i_ldi ) 
    1240             CALL mpp_add_att(mpp__init_read_rstdimg, tl_att) 
     1501            &                 mpp__init_file_rstdimg%t_proc(:)%i_ldi ) 
     1502            CALL mpp_move_att(mpp__init_file_rstdimg, tl_att) 
    12411503 
    12421504            tl_att=att_init( "DOMAIN_J_halo_size_start", & 
    1243             &                 mpp__init_read_rstdimg%t_proc(:)%i_ldj ) 
    1244             CALL mpp_add_att(mpp__init_read_rstdimg, tl_att) 
     1505            &                 mpp__init_file_rstdimg%t_proc(:)%i_ldj ) 
     1506            CALL mpp_move_att(mpp__init_file_rstdimg, tl_att) 
    12451507 
    12461508            tl_att=att_init( "DOMAIN_I_halo_size_end", & 
    1247             &                 mpp__init_read_rstdimg%t_proc(:)%i_lei ) 
    1248             CALL mpp_add_att(mpp__init_read_rstdimg, tl_att) 
     1509            &                 mpp__init_file_rstdimg%t_proc(:)%i_lei ) 
     1510            CALL mpp_move_att(mpp__init_file_rstdimg, tl_att) 
    12491511 
    12501512            tl_att=att_init( "DOMAIN_J_halo_size_end", & 
    1251             &                 mpp__init_read_rstdimg%t_proc(:)%i_lej ) 
    1252             CALL mpp_add_att(mpp__init_read_rstdimg, tl_att) 
     1513            &                 mpp__init_file_rstdimg%t_proc(:)%i_lej ) 
     1514            CALL mpp_move_att(mpp__init_file_rstdimg, tl_att) 
     1515 
     1516            ! clean 
     1517            CALL dim_clean(tl_dim) 
     1518            CALL att_clean(tl_att) 
    12531519         ENDIF 
    12541520 
    12551521      ELSE 
    12561522 
    1257          CALL logger_error("INIT READ: dimg file "//TRIM(td_file%c_name)//& 
     1523         CALL logger_error("MPP INIT READ: dimg file "//TRIM(td_file%c_name)//& 
    12581524         &  " do not exist") 
    12591525 
    12601526      ENDIF 
    12611527 
    1262    END FUNCTION mpp__init_read_rstdimg 
    1263    ! @endcode 
     1528   END FUNCTION mpp__init_file_rstdimg 
    12641529   !------------------------------------------------------------------- 
    12651530   !> @brief This function check if variable and mpp structure use same 
    12661531   !> dimension. 
    12671532   ! 
    1268    !> @details 
    1269    ! 
    12701533   !> @author J.Paul 
    12711534   !> - Nov, 2013- Initial Version 
    12721535   ! 
    1273    !> @param[in] td_mpp : mpp structure 
    1274    !> @param[in] td_proc : processor structure 
     1536   !> @param[in] td_mpp   mpp structure 
     1537   !> @param[in] td_proc   processor structure 
    12751538   !> @return dimension of processor and mpp structure agree (or not) 
    12761539   !------------------------------------------------------------------- 
    1277    ! @code 
    12781540   LOGICAL FUNCTION mpp__check_proc_dim(td_mpp, td_proc) 
    12791541      IMPLICIT NONE 
     
    13011563            mpp__check_proc_dim=.FALSE. 
    13021564 
    1303             CALL logger_error( " CHECK DIM: processor and mpp dimension differ" ) 
     1565            CALL logger_error( "MPP CHECK DIM: processor and mpp dimension differ" ) 
    13041566 
    13051567         ENDIF 
     
    13121574            mpp__check_proc_dim=.FALSE. 
    13131575 
    1314             CALL logger_error( " CHECK DIM: processor and mpp dimension differ" ) 
     1576            CALL logger_error( "MPP CHECK DIM: processor and mpp dimension differ" ) 
    13151577 
    13161578         ENDIF 
     
    13181580 
    13191581   END FUNCTION mpp__check_proc_dim 
    1320    ! @endcode 
    13211582   !------------------------------------------------------------------- 
    13221583   !> @brief 
    1323    !>    This subroutine add variable to mpp structure. 
    1324    !> 
    1325    !> @detail 
    1326    ! 
    1327    !> @author J.Paul 
    1328    !> @date Nov, 2013 
    1329    ! 
    1330    !> @param[inout] td_mpp : mpp strcuture 
    1331    !> @param[in]    td_var : variable strcuture 
    1332    ! 
    1333    !> @todo  
    1334    !------------------------------------------------------------------- 
    1335    !> @code 
     1584   !>    This subroutine add variable in all files of mpp structure. 
     1585   !> 
     1586   !> @author J.Paul 
     1587   !> @date November, 2013 - Initial version 
     1588   ! 
     1589   !> @param[inout] td_mpp mpp strcuture 
     1590   !> @param[in]    td_var variable strcuture 
     1591   !------------------------------------------------------------------- 
    13361592   SUBROUTINE mpp_add_var( td_mpp, td_var ) 
    13371593      IMPLICIT NONE 
     
    13501606      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN 
    13511607 
    1352          CALL logger_error( "MPP ADD VAR: domain decomposition not define "//& 
    1353          &               "for mpp "//TRIM(td_mpp%c_name)) 
    1354  
    1355       ELSEIF( td_mpp%i_ndim == 0 )THEN 
    1356  
    1357          CALL logger_error( " MPP ADD VAR: no dimension define for "//& 
    1358          &               " mpp strcuture "//TRIM(td_mpp%c_name)) 
     1608         CALL logger_error( "MPP ADD VAR: processor decomposition not "//& 
     1609         &  "define for mpp "//TRIM(td_mpp%c_name)) 
    13591610 
    13601611      ELSE 
     
    13671618            il_varid=0 
    13681619            IF( ASSOCIATED(td_mpp%t_proc(1)%t_var) )THEN 
    1369                il_varid=var_get_id( td_mpp%t_proc(1)%t_var(:), & 
    1370                &                    td_var%c_name, td_var%c_stdname ) 
     1620               il_varid=var_get_index( td_mpp%t_proc(1)%t_var(:), & 
     1621               &                       td_var%c_name, td_var%c_stdname ) 
    13711622            ENDIF 
    13721623 
     
    13931644               IF( mpp__check_dim(td_mpp, td_var) )THEN 
    13941645 
     1646                  ! update dimension if need be 
     1647                  DO ji=1,ip_maxdim 
     1648                     IF( td_var%t_dim(ji)%l_use .AND. & 
     1649                     &   .NOT. td_mpp%t_dim(ji)%l_use )THEN 
     1650                        CALL mpp_add_dim(td_mpp,td_var%t_dim(ji)) 
     1651                     ENDIF 
     1652                  ENDDO 
     1653 
    13951654                  ! add variable in each processor 
    13961655                  DO ji=1,td_mpp%i_nproc 
     
    14011660                     CALL file_add_var(td_mpp%t_proc(ji), tl_var) 
    14021661 
     1662                     ! clean 
     1663                     CALL var_clean(tl_var) 
    14031664                  ENDDO 
    14041665 
     
    14091670 
    14101671   END SUBROUTINE mpp_add_var 
    1411    !> @endcode 
    1412    !------------------------------------------------------------------- 
    1413    !> @brief This function extract from variable structure, part that will  
     1672   !------------------------------------------------------------------- 
     1673   !> @brief This function extract, from variable structure, part that will  
    14141674   !> be written in processor id_procid.<br/> 
    14151675   ! 
    1416    !> @details 
    1417    ! 
    1418    !> @author J.Paul 
    1419    !> - Nov, 2013- Initial Version 
    1420    ! 
    1421    !> @param[in] td_mpp : mpp structure 
    1422    !> @param[in] td_var : variable structure 
    1423    !> @param[in] id_procid : processor id 
     1676   !> @author J.Paul 
     1677   !> - November, 2013- Initial Version 
     1678   ! 
     1679   !> @param[in] td_mpp    mpp structure 
     1680   !> @param[in] td_var    variable structure 
     1681   !> @param[in] id_procid processor id 
    14241682   !> @return variable structure 
    14251683   !------------------------------------------------------------------- 
    1426    ! @code    
    14271684   TYPE(TVAR) FUNCTION mpp__split_var(td_mpp, td_var, id_procid) 
    14281685      IMPLICIT NONE 
     
    14441701 
    14451702      ! copy mpp 
    1446       mpp__split_var=td_var 
    1447  
    1448       ! remove value over global domain from pointer 
    1449       CALL var_del_value( mpp__split_var ) 
    1450  
    1451       ! get processor dimension 
    1452       il_size(:)=mpp_get_proc_size( td_mpp, id_procid ) 
    1453  
    1454       ! define new dimension in variable structure  
    1455       IF( td_var%t_dim(1)%l_use )THEN 
    1456          tl_dim=dim_init( TRIM(td_var%t_dim(1)%c_name), il_size(1) ) 
    1457          CALL var_move_dim( mpp__split_var, tl_dim ) 
    1458       ENDIF 
    1459       IF( td_var%t_dim(2)%l_use )THEN 
    1460          tl_dim=dim_init( TRIM(td_var%t_dim(2)%c_name), il_size(2) ) 
    1461          CALL var_move_dim( mpp__split_var, tl_dim )       
    1462       ENDIF 
    1463  
    1464       ! get processor indices 
    1465       il_ind(:)=mpp_get_proc_index( td_mpp, id_procid ) 
    1466       il_i1 = il_ind(1) 
    1467       il_i2 = il_ind(2) 
    1468       il_j1 = il_ind(3) 
    1469       il_j2 = il_ind(4) 
    1470  
    1471       IF( .NOT. td_var%t_dim(1)%l_use )THEN 
    1472          il_i1=1  
    1473          il_i2=1  
    1474       ENDIF 
    1475  
    1476       IF( .NOT. td_var%t_dim(2)%l_use )THEN 
    1477          il_j1=1  
    1478          il_j2=1  
    1479       ENDIF       
    1480  
    1481       ! add variable value on processor 
    1482       CALL var_add_value( mpp__split_var, & 
    1483       &                   td_var%d_value(il_i1:il_i2, il_j1:il_j2, :, :) ) 
     1703      mpp__split_var=var_copy(td_var) 
     1704 
     1705      IF( ASSOCIATED(td_var%d_value) )THEN 
     1706         ! remove value over global domain from pointer 
     1707         CALL var_del_value( mpp__split_var ) 
     1708 
     1709         ! get processor dimension 
     1710         il_size(:)=mpp_get_proc_size( td_mpp, id_procid ) 
     1711 
     1712         ! define new dimension in variable structure  
     1713         IF( td_var%t_dim(1)%l_use )THEN 
     1714            tl_dim=dim_init( TRIM(td_var%t_dim(1)%c_name), il_size(1) ) 
     1715            CALL var_move_dim( mpp__split_var, tl_dim ) 
     1716         ENDIF 
     1717         IF( td_var%t_dim(2)%l_use )THEN 
     1718            tl_dim=dim_init( TRIM(td_var%t_dim(2)%c_name), il_size(2) ) 
     1719            CALL var_move_dim( mpp__split_var, tl_dim )       
     1720         ENDIF 
     1721 
     1722         ! get processor indices 
     1723         il_ind(:)=mpp_get_proc_index( td_mpp, id_procid ) 
     1724         il_i1 = il_ind(1) 
     1725         il_i2 = il_ind(2) 
     1726         il_j1 = il_ind(3) 
     1727         il_j2 = il_ind(4) 
     1728 
     1729         IF( .NOT. td_var%t_dim(1)%l_use )THEN 
     1730            il_i1=1  
     1731            il_i2=1  
     1732         ENDIF 
     1733 
     1734         IF( .NOT. td_var%t_dim(2)%l_use )THEN 
     1735            il_j1=1  
     1736            il_j2=1  
     1737         ENDIF       
     1738 
     1739         ! add variable value on processor 
     1740         CALL var_add_value( mpp__split_var, & 
     1741         &                   td_var%d_value(il_i1:il_i2, il_j1:il_j2, :, :) ) 
     1742      ENDIF 
    14841743 
    14851744   END FUNCTION mpp__split_var 
    1486    !> @endcode 
     1745   !------------------------------------------------------------------- 
     1746   !> @brief  
     1747   !>  This subroutine delete all variable in mpp strcuture. 
     1748   !> 
     1749   !> @author J.Paul 
     1750   !> @date October, 2014 - Initial version 
     1751   !> 
     1752   !> @param[inout] td_mpp mpp strcuture 
     1753   !------------------------------------------------------------------- 
     1754   SUBROUTINE mpp__del_var_mpp( td_mpp ) 
     1755      IMPLICIT NONE 
     1756      ! Argument 
     1757      TYPE(TMPP), INTENT(INOUT) :: td_mpp 
     1758 
     1759      ! local variable 
     1760      ! loop indices 
     1761      INTEGER(i4) :: ji 
     1762      !---------------------------------------------------------------- 
     1763 
     1764      CALL logger_info( & 
     1765      &  "MPP CLEAN VAR: reset all variable "//& 
     1766      &  "in mpp strcuture "//TRIM(td_mpp%c_name) ) 
     1767 
     1768      IF( ASSOCIATED(td_mpp%t_proc) )THEN 
     1769         DO ji=td_mpp%t_proc(1)%i_nvar,1,-1 
     1770            CALL mpp_del_var(td_mpp, td_mpp%t_proc(1)%t_var(ji)) 
     1771         ENDDO 
     1772      ENDIF 
     1773 
     1774   END SUBROUTINE mpp__del_var_mpp 
    14871775   !------------------------------------------------------------------- 
    14881776   !> @brief 
     
    14901778   !> structure. 
    14911779   !> 
    1492    !> @detail 
    1493    ! 
    1494    !> @author J.Paul 
    1495    !> @date Nov, 2013 
    1496    ! 
    1497    !> @param[inout] td_mpp : mpp strcuture 
    1498    !> @param[in]    td_var : variable strcuture 
    1499    ! 
    1500    !> @todo  
    1501    !------------------------------------------------------------------- 
    1502    !> @code 
     1780   !> @author J.Paul 
     1781   !> @date November, 2013 - Initial version 
     1782   ! 
     1783   !> @param[inout] td_mpp mpp strcuture 
     1784   !> @param[in]    td_var variable strcuture 
     1785   !------------------------------------------------------------------- 
    15031786   SUBROUTINE mpp__del_var_str( td_mpp, td_var ) 
    15041787      IMPLICIT NONE 
     
    15171800      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN 
    15181801 
    1519          CALL logger_error( " DEL VAR: domain decomposition not define "//& 
     1802         CALL logger_error( "MPP DEL VAR: domain decomposition not define "//& 
    15201803         &               " in mpp strcuture "//TRIM(td_mpp%c_name)) 
    15211804 
     
    15251808         il_varid = 0 
    15261809         IF( ASSOCIATED(td_mpp%t_proc(1)%t_var) )THEN 
    1527             il_varid=var_get_id( td_mpp%t_proc(1)%t_var(:), & 
    1528             &                    td_var%c_name, td_var%c_stdname ) 
     1810            il_varid=var_get_index( td_mpp%t_proc(1)%t_var(:), & 
     1811            &                       td_var%c_name, td_var%c_stdname ) 
    15291812         ENDIF 
    15301813         IF( il_varid == 0 )THEN 
    15311814            CALL logger_error( & 
    1532             &  " DEL VAR: no variable "//TRIM(td_var%c_name)//& 
     1815            &  "MPP DEL VAR: no variable "//TRIM(td_var%c_name)//& 
    15331816            &  ", in mpp structure "//TRIM(td_mpp%c_name) ) 
    15341817 
    15351818            DO ji=1,td_mpp%t_proc(1)%i_nvar 
    1536                CALL logger_debug( " DEL VAR: in mpp structure : & 
     1819               CALL logger_debug( "MPP DEL VAR: in mpp structure : & 
    15371820               &  variable : "//TRIM(td_mpp%t_proc(1)%t_var(ji)%c_name)//& 
    15381821               &  ", standard name "//& 
     
    15511834      ENDIF 
    15521835   END SUBROUTINE mpp__del_var_str 
    1553    !> @endcode 
    15541836   !------------------------------------------------------------------- 
    15551837   !> @brief 
    15561838   !>    This subroutine delete variable in mpp structure, given variable name. 
    15571839   !> 
    1558    !> @detail 
    1559    ! 
    1560    !> @author J.Paul 
    1561    !> @date Nov, 2013 
    1562    ! 
    1563    !> @param[inout] td_mpp : mpp strcuture 
    1564    !> @param[in]    cd_name: variable name 
    1565    ! 
    1566    !> @todo  
    1567    !------------------------------------------------------------------- 
    1568    !> @code 
     1840   !> @author J.Paul 
     1841   !> @date November, 2013 - Initial version 
     1842   ! 
     1843   !> @param[inout] td_mpp    mpp strcuture 
     1844   !> @param[in]    cd_name   variable name 
     1845   !------------------------------------------------------------------- 
    15691846   SUBROUTINE mpp__del_var_name( td_mpp, cd_name ) 
    15701847      IMPLICIT NONE 
     
    15791856      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN 
    15801857 
    1581          CALL logger_error( " DEL VAR: domain decomposition not define "//& 
     1858         CALL logger_error( "MPP DEL VAR: domain decomposition not define "//& 
    15821859         &               " in mpp strcuture "//TRIM(td_mpp%c_name)) 
    15831860 
     
    15851862 
    15861863         IF( td_mpp%t_proc(1)%i_nvar == 0 )THEN 
    1587             CALL logger_debug( " DEL VAR NAME: no variable associated to mpp & 
     1864            CALL logger_debug( "MPP DEL VAR NAME: no variable associated to mpp & 
    15881865            &                 structure "//TRIM(td_mpp%c_name) ) 
    15891866         ELSE 
     
    15921869            il_varid=0 
    15931870            IF( ASSOCIATED(td_mpp%t_proc(1)%t_var) )THEN 
    1594                il_varid=var_get_id( td_mpp%t_proc(1)%t_var(:), & 
    1595                &                    cd_name ) 
    1596             ENDIF 
     1871               il_varid=var_get_index( td_mpp%t_proc(1)%t_var(:), & 
     1872               &                       cd_name ) 
     1873            ENDIF 
     1874 
    15971875            IF( il_varid == 0 )THEN 
    15981876 
    15991877               CALL logger_warn( & 
    1600                &  "DEL VAR : there is no variable with name "//& 
     1878               &  "MPP DEL VAR : there is no variable with name "//& 
    16011879               &  "or standard name "//TRIM(ADJUSTL(cd_name))//& 
    16021880               &  " in mpp structure "//TRIM(td_mpp%c_name)) 
     
    16111889      ENDIF 
    16121890   END SUBROUTINE mpp__del_var_name 
    1613    !> @endcode 
    16141891   !------------------------------------------------------------------- 
    16151892   !> @brief 
    16161893   !>    This subroutine overwrite variable in mpp structure. 
    16171894   !> 
    1618    !> @detail 
    1619    ! 
    1620    !> @author J.Paul 
    1621    !> @date Nov, 2013 
    1622    ! 
    1623    !> @param[inout] td_mpp : mpp strcuture 
    1624    !> @param[in]    td_var : variable structure 
    1625    !> @todo 
    1626    !> - voir si il ne faut pas redefinir (__copy) variable si elle vient de mpp 
    1627    !> exemple CALL  mpp_move_var( td_mpp, td_mpp%t_proc()%t_var ) 
    1628    !> remarque cas probabelement impossible puisque td_var doit avoir dim de td_mpp 
    1629    !------------------------------------------------------------------- 
    1630    !> @code 
     1895   !> @author J.Paul 
     1896   !> @date November, 2013 - Initial version 
     1897   ! 
     1898   !> @param[inout] td_mpp mpp strcuture 
     1899   !> @param[in]    td_var variable structure 
     1900   !------------------------------------------------------------------- 
    16311901   SUBROUTINE mpp_move_var( td_mpp, td_var ) 
    16321902      IMPLICIT NONE 
     
    16391909      !---------------------------------------------------------------- 
    16401910      ! copy variable 
    1641       tl_var=td_var 
     1911      tl_var=var_copy(td_var) 
    16421912 
    16431913      ! remove processor 
     
    16471917      CALL mpp_add_var(td_mpp, tl_var) 
    16481918 
     1919      ! clean  
     1920      CALL var_clean(tl_var) 
     1921 
    16491922   END SUBROUTINE mpp_move_var 
    16501923   !> @endcode 
     
    16531926   !>    This subroutine add processor to mpp structure. 
    16541927   !> 
    1655    !> @detail 
    1656    ! 
    1657    !> @author J.Paul 
    1658    !> @date Nov, 2013 
    1659    ! 
    1660    !> @param[inout] td_mpp : mpp strcuture 
    1661    !> @param[in]    td_proc : processor strcuture 
     1928   !> @author J.Paul 
     1929   !> @date November, 2013 - Initial version 
     1930   ! 
     1931   !> @param[inout] td_mpp    mpp strcuture 
     1932   !> @param[in]    td_proc   processor strcuture 
    16621933   ! 
    16631934   !> @todo  
    16641935   !> - check proc type 
    16651936   !------------------------------------------------------------------- 
    1666    !> @code 
    16671937   SUBROUTINE mpp__add_proc( td_mpp, td_proc ) 
    16681938      IMPLICIT NONE 
     
    16981968 
    16991969            CALL logger_error( & 
    1700             &  " ADD PROC: processor "//TRIM(fct_str(td_proc%i_pid))//& 
     1970            &  "MPP ADD PROC: processor "//TRIM(fct_str(td_proc%i_pid))//& 
    17011971            &  ", already in mpp structure " ) 
    17021972 
    17031973      ELSE 
    1704           
    1705          CALL logger_trace("ADD PROC: add processor "//& 
     1974  
     1975         CALL logger_trace("MPP ADD PROC: add processor "//& 
    17061976         &               TRIM(fct_str(td_mpp%i_nproc+1))//" in mpp structure") 
    17071977 
     
    17161986            IF(il_status /= 0 )THEN 
    17171987 
    1718                CALL logger_error( " ADD PROC: not enough space to put processor & 
     1988               CALL logger_error( "MPP ADD PROC: not enough space to put processor & 
    17191989               &               in mpp structure") 
    17201990 
    17211991            ELSE 
    17221992               ! save temporary mpp structure 
    1723                tl_proc(:)=td_mpp%t_proc(:) 
    1724  
    1725                DEALLOCATE( td_mpp%t_proc ) 
     1993               tl_proc(:)=file_copy(td_mpp%t_proc(:)) 
     1994 
     1995               CALL file_clean( td_mpp%t_proc(:) ) 
     1996               DEALLOCATE(td_mpp%t_proc) 
    17261997               ALLOCATE( td_mpp%t_proc(td_mpp%i_nproc+1), stat=il_status) 
    17271998               IF(il_status /= 0 )THEN 
    17281999 
    1729                   CALL logger_error( " ADD PROC: not enough space to put "//& 
     2000                  CALL logger_error( "MPP ADD PROC: not enough space to put "//& 
    17302001                  &  "processor in mpp structure ") 
    17312002 
     
    17332004 
    17342005               ! copy processor in mpp before 
    1735                ! processor with lesser id than new processor 
    1736                td_mpp%t_proc( 1:il_procid ) = tl_proc( 1:il_procid ) 
     2006               ! processor with lower id than new processor 
     2007               td_mpp%t_proc( 1:il_procid ) = file_copy(tl_proc( 1:il_procid )) 
    17372008 
    17382009               ! processor with greater id than new processor 
    17392010               td_mpp%t_proc( il_procid+1 : td_mpp%i_nproc+1 ) = & 
    1740                &                 tl_proc( il_procid : td_mpp%i_nproc ) 
    1741  
     2011               &              file_copy(tl_proc( il_procid : td_mpp%i_nproc )) 
     2012 
     2013               ! clean 
     2014               CALL file_clean(tl_proc(:)) 
    17422015               DEALLOCATE(tl_proc) 
    17432016            ENDIF 
     
    17462019            ! no processor in mpp structure 
    17472020            IF( ASSOCIATED(td_mpp%t_proc) )THEN 
     2021               CALL file_clean(td_mpp%t_proc(:)) 
    17482022               DEALLOCATE(td_mpp%t_proc) 
    17492023            ENDIF 
     
    17512025            IF(il_status /= 0 )THEN 
    17522026 
    1753                CALL logger_error( " ADD PROC: not enough space to put "//& 
     2027               CALL logger_error( "MPP ADD PROC: not enough space to put "//& 
    17542028               &  "processor in mpp structure " ) 
    17552029 
     
    17592033         ! check dimension 
    17602034         IF( ANY(td_mpp%t_dim(1:2)%i_len < td_proc%t_dim(1:2)%i_len) )THEN 
    1761             CALL logger_error( "ADD PROC: mpp structure and new processor "//& 
     2035            CALL logger_error( "MPP ADD PROC: mpp structure and new processor "//& 
    17622036            &  " dimension differ. ") 
    1763             CALL logger_debug("ADD PROC: mpp dimension ("//& 
     2037            CALL logger_debug("MPP ADD PROC: mpp dimension ("//& 
    17642038            &  TRIM(fct_str(td_mpp%t_dim(1)%i_len))//","//& 
    17652039            &  TRIM(fct_str(td_mpp%t_dim(2)%i_len))//")" ) 
    1766             CALL logger_debug("ADD PROC: processor dimension ("//& 
     2040            CALL logger_debug("MPP ADD PROC: processor dimension ("//& 
    17672041            &  TRIM(fct_str(td_proc%t_dim(1)%i_len))//","//& 
    17682042            &  TRIM(fct_str(td_proc%t_dim(2)%i_len))//")" ) 
     
    17712045 
    17722046            ! add new processor 
    1773             td_mpp%t_proc(td_mpp%i_nproc)=td_proc 
     2047            td_mpp%t_proc(td_mpp%i_nproc)=file_copy(td_proc) 
    17742048         ENDIF 
    17752049 
    17762050      ENDIF 
    17772051   END SUBROUTINE mpp__add_proc 
    1778    !> @endcode 
    17792052   !------------------------------------------------------------------- 
    17802053   !> @brief 
    17812054   !>    This subroutine delete processor in mpp structure, given processor id. 
    17822055   !> 
    1783    !> @detail 
    1784    ! 
    1785    !> @author J.Paul 
    1786    !> @date Nov, 2013 
    1787    ! 
    1788    !> @param[inout] td_mpp : mpp strcuture 
    1789    !> @param[in]    id_procid : processor id 
    1790    ! 
    1791    !> @todo check proc id exist 
    1792    !------------------------------------------------------------------- 
    1793    !> @code 
     2056   !> @author J.Paul 
     2057   !> @date November, 2013 - Initial version 
     2058   !> 
     2059   !> @param[inout] td_mpp    mpp strcuture 
     2060   !> @param[in]    id_procid processor id 
     2061   !------------------------------------------------------------------- 
    17942062   SUBROUTINE mpp__del_proc_id( td_mpp, id_procid ) 
    17952063      IMPLICIT NONE 
     
    18032071      INTEGER(i4), DIMENSION(1) :: il_ind 
    18042072      TYPE(TFILE), DIMENSION(:), ALLOCATABLE :: tl_proc 
     2073 
     2074      ! loop indices 
    18052075      !---------------------------------------------------------------- 
    18062076 
     
    18082078      il_procid=il_ind(1) 
    18092079      IF( il_procid == 0 )THEN 
    1810          CALL logger_error("DEL PROC: no processor "//TRIM(fct_str(id_procid))//& 
    1811          &              " associated to mpp structure") 
     2080         CALL logger_error("MPP DEL PROC: no processor "//& 
     2081         &                 TRIM(fct_str(id_procid))//& 
     2082         &                 " associated to mpp structure") 
    18122083      ELSE 
    1813          CALL logger_trace("DEL PROC: remove processor "//TRIM(fct_str(id_procid))) 
     2084         CALL logger_trace("DEL PROC: remove processor "//& 
     2085         &                 TRIM(fct_str(id_procid))) 
    18142086 
    18152087         IF( td_mpp%i_nproc > 1 )THEN 
    18162088            ALLOCATE( tl_proc(td_mpp%i_nproc-1), stat=il_status ) 
    18172089            IF(il_status /= 0 )THEN 
    1818                CALL logger_error( " DEL PROC: not enough space to put processor & 
    1819                &                in temporary mpp structure") 
     2090               CALL logger_error( "MPP DEL PROC: not enough space to put & 
     2091               &  processor in temporary mpp structure") 
    18202092 
    18212093            ELSE 
     
    18232095               ! save temporary processor's mpp structure 
    18242096               IF( il_procid > 1 )THEN 
    1825                   tl_proc(1:il_procid-1)=td_mpp%t_proc(1:il_procid-1) 
     2097                  tl_proc(1:il_procid-1)=file_copy(td_mpp%t_proc(1:il_procid-1)) 
    18262098               ENDIF 
    1827                tl_proc(il_procid:)=td_mpp%t_proc(il_procid+1:) 
     2099 
     2100               IF( il_procid < td_mpp%i_nproc )THEN 
     2101                  tl_proc(il_procid:)=file_copy(td_mpp%t_proc(il_procid+1:)) 
     2102               ENDIF 
    18282103 
    18292104               ! new number of processor in mpp 
    18302105               td_mpp%i_nproc=td_mpp%i_nproc-1 
    18312106 
    1832                DEALLOCATE( td_mpp%t_proc ) 
     2107               CALL file_clean( td_mpp%t_proc(:) ) 
     2108               DEALLOCATE(td_mpp%t_proc) 
    18332109               ALLOCATE( td_mpp%t_proc(td_mpp%i_nproc), stat=il_status ) 
    18342110               IF(il_status /= 0 )THEN 
    18352111 
    1836                   CALL logger_error( " DEL PROC: not enough space to put processors & 
    1837                   &              in mpp structure " ) 
     2112                  CALL logger_error( "MPP DEL PROC: not enough space & 
     2113                  &  to put processors in mpp structure " ) 
    18382114 
    18392115               ELSE 
    18402116 
    18412117                  ! copy processor in mpp before 
    1842                   td_mpp%t_proc(:)=tl_proc(:) 
     2118                  td_mpp%t_proc(:)=file_copy(tl_proc(:)) 
    18432119 
    18442120                  ! update processor id 
     
    18482124               ENDIF 
    18492125            ENDIF 
     2126            ! clean 
     2127            CALL file_clean( tl_proc(:) ) 
     2128            DEALLOCATE(tl_proc) 
    18502129         ELSE 
    1851             DEALLOCATE( td_mpp%t_proc ) 
     2130            CALL file_clean( td_mpp%t_proc(:) ) 
     2131            DEALLOCATE(td_mpp%t_proc) 
    18522132 
    18532133            ! new number of processor in mpp 
     
    18562136      ENDIF 
    18572137   END SUBROUTINE mpp__del_proc_id 
    1858    !> @endcode 
    18592138   !------------------------------------------------------------------- 
    18602139   !> @brief 
     
    18622141   !>    structure. 
    18632142   !> 
    1864    !> @detail 
    1865    ! 
    1866    !> @author J.Paul 
    1867    !> @date Nov, 2013 
     2143   !> @author J.Paul 
     2144   !> @date November, 2013 - Initial version 
    18682145   ! 
    18692146   !> @param[inout] td_mpp : mpp strcuture 
    18702147   !> @param[in]    td_proc : file/processor structure 
    1871    ! 
    1872    !> @todo check proc id exist 
    1873    !------------------------------------------------------------------- 
    1874    !> @code 
     2148   !------------------------------------------------------------------- 
    18752149   SUBROUTINE mpp__del_proc_str( td_mpp, td_proc ) 
    18762150      IMPLICIT NONE 
     
    18832157         CALL mpp__del_proc( td_mpp, td_proc%i_pid ) 
    18842158      ELSE 
    1885          CALL logger_error("DEL PROC: processor not defined") 
     2159         CALL logger_error("MPP DEL PROC: processor not defined") 
    18862160      ENDIF 
    18872161 
    18882162   END SUBROUTINE mpp__del_proc_str 
    1889    !> @endcode 
    18902163   !------------------------------------------------------------------- 
    18912164   !> @brief 
     
    18952168   ! 
    18962169   !> @author J.Paul 
    1897    !> @date Nov, 2013 
    1898    ! 
    1899    !> @param[inout] td_mpp : mpp strcuture 
    1900    !> @param[in]    id_procid : processor id 
    1901    !> @todo 
    1902    !> - voir si il ne faut pas redefinir (__copy) proc si il vient de mpp 
    1903    !> exemple CALL  mpp_move_proc( td_mpp, td_mpp%t_proc )    
    1904    !------------------------------------------------------------------- 
    1905    !> @code 
     2170   !> @date Nov, 2013 - Initial version 
     2171   ! 
     2172   !> @param[inout] td_mpp    mpp strcuture 
     2173   !> @param[in]    id_procid processor id 
     2174   !------------------------------------------------------------------- 
    19062175   SUBROUTINE mpp__move_proc( td_mpp, td_proc ) 
    19072176      IMPLICIT NONE 
     
    19182187 
    19192188   END SUBROUTINE mpp__move_proc 
    1920    !> @endcode 
    19212189   !------------------------------------------------------------------- 
    19222190   !> @brief This subroutine add a dimension structure in a mpp  
    19232191   !> structure. 
    19242192   !> Do not overwrite, if dimension already in mpp structure. 
    1925    ! 
    1926    !> @details 
    1927    ! 
    1928    !> @author J.Paul 
    1929    !> - Nov, 2013- Initial Version 
    1930    ! 
    1931    !> @param[inout] td_mpp : mpp structure 
    1932    !> @param[in] td_dim : dimension structure 
    1933    ! 
    1934    !> @todo  
    1935    !------------------------------------------------------------------- 
    1936    ! @code 
     2193   !> 
     2194   !> @author J.Paul 
     2195   !> - November, 2013- Initial Version 
     2196   !> 
     2197   !> @param[inout] td_mpp mpp structure 
     2198   !> @param[in] td_dim    dimension structure 
     2199   !------------------------------------------------------------------- 
    19372200   SUBROUTINE mpp_add_dim(td_mpp, td_dim) 
    19382201      IMPLICIT NONE 
     
    19422205 
    19432206      ! local variable 
    1944       INTEGER(i4) :: il_dimid 
     2207      INTEGER(i4) :: il_ind 
    19452208 
    19462209      ! loop indices 
    1947       !---------------------------------------------------------------- 
    1948       IF( td_mpp%i_ndim <= 4 )THEN 
     2210      INTEGER(i4) :: ji 
     2211      !---------------------------------------------------------------- 
     2212      IF( td_mpp%i_ndim <= ip_maxdim )THEN 
    19492213 
    19502214         ! check if dimension already in mpp structure 
    1951          il_dimid=dim_get_id(td_mpp%t_dim(:), td_dim%c_name, td_dim%c_sname) 
    1952          IF( il_dimid /= 0 )THEN 
    1953  
    1954             CALL logger_error( & 
    1955             &  " ADD DIM: dimension "//TRIM(td_dim%c_name)//& 
    1956             &  ", short name "//TRIM(td_dim%c_sname)//& 
    1957             &  ", already in mpp "//TRIM(td_mpp%c_name) ) 
     2215         il_ind=dim_get_index(td_mpp%t_dim(:), td_dim%c_name, td_dim%c_sname) 
     2216         IF( il_ind /= 0 )THEN 
     2217 
     2218            IF( td_mpp%t_dim(il_ind)%l_use )THEN 
     2219               CALL logger_error( & 
     2220               &  "MPP ADD DIM: dimension "//TRIM(td_dim%c_name)//& 
     2221               &  ", short name "//TRIM(td_dim%c_sname)//& 
     2222               &  ", already used in mpp "//TRIM(td_mpp%c_name) ) 
     2223            ELSE 
     2224               ! replace dimension 
     2225               td_mpp%t_dim(il_ind)=dim_copy(td_dim) 
     2226               td_mpp%t_dim(il_ind)%i_id=il_ind 
     2227               td_mpp%t_dim(il_ind)%l_use=.TRUE. 
     2228            ENDIF 
    19582229 
    19592230         ELSE 
    19602231 
    1961             CALL logger_debug( & 
    1962             &  " ADD DIM: add dimension "//TRIM(td_dim%c_name)//& 
    1963             &  ", short name "//TRIM(td_dim%c_sname)//& 
    1964             &  ", in mpp "//TRIM(td_mpp%c_name) ) 
    1965  
    1966             IF( td_mpp%i_ndim == 4 )THEN 
     2232            IF( td_mpp%i_ndim == ip_maxdim )THEN 
     2233               CALL logger_error( & 
     2234               &  "MPP ADD DIM: can not add dimension "//TRIM(td_dim%c_name)//& 
     2235               &  ", short name "//TRIM(td_dim%c_sname)//& 
     2236               &  ", in mpp "//TRIM(td_mpp%c_name)//". Already "//& 
     2237               &  TRIM(fct_str(ip_maxdim))//" dimensions." ) 
     2238            ELSE 
    19672239               ! search empty dimension 
    1968                il_dimid=dim_get_void_id(td_mpp%t_dim(:),TRIM(td_dim%c_name), & 
    1969                &                                        TRIM(td_dim%c_sname)) 
    1970                ! replace empty dimension 
    1971                td_mpp%t_dim(il_dimid)=td_dim 
    1972                td_mpp%t_dim(il_dimid)%i_id=il_dimid 
    1973                td_mpp%t_dim(il_dimid)%l_use=.TRUE. 
    1974             ELSE 
    1975                il_dimid=dim_get_void_id(td_mpp%t_dim(:),TRIM(td_dim%c_name), & 
    1976                &                                        TRIM(td_dim%c_sname)) 
    1977                ! add new dimension 
    1978                td_mpp%t_dim(il_dimid)=td_dim 
    1979                td_mpp%t_dim(il_dimid)%i_id=td_mpp%i_ndim+1 
    1980                td_mpp%t_dim(il_dimid)%l_use=.TRUE. 
     2240               DO ji=1,ip_maxdim 
     2241                  IF( td_mpp%t_dim(ji)%i_id == 0 )THEN 
     2242                     il_ind=ji  
     2243                     EXIT 
     2244                  ENDIF 
     2245               ENDDO 
     2246  
     2247               ! add new dimension     
     2248               td_mpp%t_dim(il_ind)=dim_copy(td_dim) 
    19812249               ! update number of attribute 
    19822250               td_mpp%i_ndim=COUNT(td_mpp%t_dim(:)%l_use) 
    1983             ENDIF 
    1984  
    1985             ! reorder dimension to ('x','y','z','t') 
    1986             CALL dim_reorder(td_mpp%t_dim) 
     2251 
     2252               td_mpp%t_dim(il_ind)%l_use=.TRUE. 
     2253               td_mpp%t_dim(il_ind)%i_id=td_mpp%i_ndim 
     2254            ENDIF 
    19872255 
    19882256         ENDIF 
     
    19902258      ELSE 
    19912259         CALL logger_error( & 
    1992          &  " ADD DIM: too much dimension in mpp "//& 
     2260         &  "MPP ADD DIM: too much dimension in mpp "//& 
    19932261         &  TRIM(td_mpp%c_name)//" ("//TRIM(fct_str(td_mpp%i_ndim))//")") 
    19942262      ENDIF 
    19952263 
    19962264   END SUBROUTINE mpp_add_dim 
    1997    ! @endcode 
    19982265   !------------------------------------------------------------------- 
    19992266   !> @brief This subroutine delete a dimension structure in a mpp  
    20002267   !> structure.<br/> 
    2001    ! 
    2002    !> @details 
    2003    ! 
    2004    !> @author J.Paul 
    2005    !> - Nov, 2013- Initial Version 
    2006    ! 
    2007    !> @param[inout] td_mpp : mpp structure 
    2008    !> @param[in] td_dim : dimension structure 
    2009    ! 
    2010    !> @todo  
    2011    !------------------------------------------------------------------- 
    2012    ! @code 
     2268   !> 
     2269   !> @author J.Paul 
     2270   !> - November, 2013- Initial Version 
     2271   !> 
     2272   !> @param[inout] td_mpp mpp structure 
     2273   !> @param[in] td_dim    dimension structure 
     2274   !------------------------------------------------------------------- 
    20132275   SUBROUTINE mpp_del_dim(td_mpp, td_dim) 
    20142276      IMPLICIT NONE 
     
    20192281      ! local variable 
    20202282      INTEGER(i4) :: il_status 
    2021       INTEGER(i4) :: il_dimid 
     2283      INTEGER(i4) :: il_ind 
    20222284      TYPE(TDIM), DIMENSION(:), ALLOCATABLE  :: tl_dim 
    20232285 
    20242286      ! loop indices 
    2025       !---------------------------------------------------------------- 
    2026       IF( td_mpp%i_ndim <= 4 )THEN 
    2027  
    2028          ! check if dimension already in mpp structure 
    2029          il_dimid=dim_get_id(td_mpp%t_dim(:), td_dim%c_name, td_dim%c_sname) 
    2030          IF( il_dimid == 0 )THEN 
     2287      INTEGER(i4) :: ji 
     2288      !---------------------------------------------------------------- 
     2289      ! check if dimension already in mpp structure 
     2290      il_ind=dim_get_index(td_mpp%t_dim(:), td_dim%c_name, td_dim%c_sname) 
     2291      IF( il_ind == 0 )THEN 
     2292 
     2293         CALL logger_error( & 
     2294         &  "MPP DEL DIM: no dimension "//TRIM(td_dim%c_name)//& 
     2295         &  ", short name "//TRIM(td_dim%c_sname)//& 
     2296         &  ", in mpp "//TRIM(td_mpp%c_name) ) 
     2297 
     2298      ELSE 
     2299 
     2300         ALLOCATE( tl_dim(td_mpp%i_ndim-1), stat=il_status ) 
     2301         IF(il_status /= 0 )THEN 
    20312302 
    20322303            CALL logger_error( & 
    2033             &  " DEL DIM: no dimension "//TRIM(td_dim%c_name)//& 
    2034             &  ", short name "//TRIM(td_dim%c_sname)//& 
    2035             &  ", in mpp "//TRIM(td_mpp%c_name) ) 
     2304            &  "MPP DEL DIM: not enough space to put dimensions from "//& 
     2305            &  TRIM(td_mpp%c_name)//" in temporary dimension structure") 
    20362306 
    20372307         ELSE 
    20382308 
    2039             CALL logger_debug( & 
    2040             &  " DEL DIM: delete dimension "//TRIM(td_dim%c_name)//& 
    2041             &  ", short name "//TRIM(td_dim%c_sname)//& 
    2042             &  ", in mpp "//TRIM(td_mpp%c_name) ) 
    2043  
    2044             IF( td_mpp%i_ndim == 4 )THEN 
    2045                ALLOCATE( tl_dim(1), stat=il_status ) 
    2046                IF(il_status /= 0 )THEN 
    2047                   CALL logger_error( & 
    2048                   &  " DEL DIM: not enough space to put dimensions from "//& 
    2049                   &  TRIM(td_mpp%c_name)//" in temporary dimension structure") 
    2050                ELSE 
    2051                   ! replace dimension by empty one 
    2052                   td_mpp%t_dim(il_dimid)=tl_dim(1) 
    2053                ENDIF 
    2054                DEALLOCATE(tl_dim) 
    2055             ELSE 
    2056                !  
    2057                ALLOCATE( tl_dim(td_mpp%i_ndim), stat=il_status ) 
    2058                IF(il_status /= 0 )THEN 
    2059  
    2060                   CALL logger_error( & 
    2061                   &  " DEL DIM: not enough space to put dimensions from "//& 
    2062                   &  TRIM(td_mpp%c_name)//" in temporary dimension structure") 
    2063  
    2064                ELSE 
    2065  
    2066                   ! save temporary dimension's mpp structure 
    2067                   tl_dim( 1 : il_dimid-1 ) = td_mpp%t_dim( 1 : il_dimid-1 ) 
    2068                   tl_dim( il_dimid : td_mpp%i_ndim-1 ) = & 
    2069                   &           td_mpp%t_dim( il_dimid+1 : td_mpp%i_ndim ) 
    2070  
    2071                   ! copy dimension in file, except one 
    2072                   td_mpp%t_dim(1:td_mpp%i_ndim)=tl_dim(:) 
    2073  
    2074                   ! update number of dimension 
    2075                   td_mpp%i_ndim=td_mpp%i_ndim-1 
    2076  
    2077                ENDIF 
    2078             ENDIF 
    2079  
    2080             ! reorder dimension to ('x','y','z','t') 
    2081             CALL dim_reorder(td_mpp%t_dim) 
    2082  
    2083             !IF( ASSOCIATED(td_mpp%t_proc) )THEN 
    2084             !   ! del dimension of processor 
    2085             !   DO ji=1,td_mpp%i_nproc 
    2086             !      CALL file_del_dim(td_mpp%t_proc(ji), td_dim) 
    2087             !   ENDDO 
    2088             !ENDIF 
     2309            ! save temporary dimension's mpp structure 
     2310            tl_dim( 1 : il_ind-1 ) = dim_copy(td_mpp%t_dim( 1 : il_ind-1 )) 
     2311            tl_dim( il_ind : td_mpp%i_ndim-1 ) = & 
     2312            &           dim_copy(td_mpp%t_dim( il_ind+1 : td_mpp%i_ndim )) 
     2313 
     2314            ! remove dimension from file 
     2315            CALL dim_clean(td_mpp%t_dim(:)) 
     2316            ! copy dimension in file, except one 
     2317            td_mpp%t_dim(1:td_mpp%i_ndim)=dim_copy(tl_dim(:)) 
     2318 
     2319            ! update number of dimension 
     2320            td_mpp%i_ndim=td_mpp%i_ndim-1 
     2321 
     2322            ! update dimension id 
     2323            DO ji=1,td_mpp%i_ndim 
     2324               td_mpp%t_dim(ji)%i_id=ji 
     2325            ENDDO 
     2326 
     2327            ! clean 
     2328            CALL dim_clean(tl_dim(:)) 
     2329            DEALLOCATE(tl_dim) 
    20892330 
    20902331         ENDIF 
    2091       ELSE 
    2092          CALL logger_error( & 
    2093          &  " DEL DIM: too much dimension in mpp "//& 
    2094          &  TRIM(td_mpp%c_name)//" ("//TRIM(fct_str(td_mpp%i_ndim))//")") 
     2332 
    20952333      ENDIF 
    20962334 
    20972335   END SUBROUTINE mpp_del_dim 
    2098    ! @endcode 
    20992336   !------------------------------------------------------------------- 
    21002337   !> @brief This subroutine move a dimension structure  
    21012338   !> in mpp structure. 
    21022339   !> @warning dimension order may have changed 
    2103    ! 
    2104    !> @details 
    2105    ! 
    2106    !> @author J.Paul 
    2107    !> - Nov, 2013- Initial Version 
    2108    ! 
    2109    !> @param[inout] td_mpp : mpp structure 
    2110    !> @param[in] td_dim : dimension structure 
    2111    !> @todo 
    2112    !------------------------------------------------------------------- 
    2113    ! @code 
     2340   !> 
     2341   !> @author J.Paul 
     2342   !> - November, 2013- Initial Version 
     2343   !> 
     2344   !> @param[inout] td_mpp mpp structure 
     2345   !> @param[in] td_dim    dimension structure 
     2346   !------------------------------------------------------------------- 
    21142347   SUBROUTINE mpp_move_dim(td_mpp, td_dim) 
    21152348      IMPLICIT NONE 
     
    21192352 
    21202353      ! local variable 
     2354      INTEGER(i4) :: il_ind 
    21212355      INTEGER(i4) :: il_dimid 
    2122  
    2123       !---------------------------------------------------------------- 
    2124  
    2125       il_dimid=dim_get_id(td_mpp%t_dim(:), TRIM(td_dim%c_name), & 
    2126       &                                    TRIM(td_dim%c_sname)) 
    2127       IF( il_dimid /= 0 )THEN 
    2128          ! remove dimension with same name 
    2129          CALL mpp_del_dim(td_mpp, td_dim) 
    2130       ENDIF 
    2131  
    2132       ! add new dimension 
    2133       CALL mpp_add_dim(td_mpp, td_dim) 
    2134  
     2356      !---------------------------------------------------------------- 
     2357      IF( td_mpp%i_ndim <= ip_maxdim )THEN 
     2358 
     2359         ! check if dimension already in mpp structure 
     2360         il_ind=dim_get_index(td_mpp%t_dim(:), td_dim%c_name, td_dim%c_sname) 
     2361         IF( il_ind /= 0 )THEN 
     2362 
     2363            il_dimid=td_mpp%t_dim(il_ind)%i_id 
     2364            ! replace dimension 
     2365            td_mpp%t_dim(il_ind)=dim_copy(td_dim) 
     2366            td_mpp%t_dim(il_ind)%i_id=il_dimid 
     2367            td_mpp%t_dim(il_ind)%l_use=.TRUE. 
     2368 
     2369         ELSE 
     2370            CALL mpp_add_dim(td_mpp, td_dim) 
     2371         ENDIF 
     2372 
     2373      ELSE 
     2374         CALL logger_error( & 
     2375         &  "MPP MOVE DIM: too much dimension in mpp "//& 
     2376         &  TRIM(td_mpp%c_name)//" ("//TRIM(fct_str(td_mpp%i_ndim))//")") 
     2377      ENDIF 
    21352378   END SUBROUTINE mpp_move_dim 
    2136    ! @endcode 
    21372379   !------------------------------------------------------------------- 
    21382380   !> @brief 
    21392381   !>    This subroutine add global attribute to mpp structure. 
    21402382   !> 
    2141    !> @detail 
    2142    ! 
    2143    !> @author J.Paul 
    2144    !> @date Nov, 2013 
    2145    ! 
    2146    !> @param[inout] td_mpp : mpp strcuture 
    2147    !> @param[in]    td_att : attribute strcuture 
    2148    ! 
    2149    !> @todo  
    2150    !------------------------------------------------------------------- 
    2151    !> @code 
     2383   !> @author J.Paul 
     2384   !> @date November, 2013 - Initial version 
     2385   !> 
     2386   !> @param[inout] td_mpp mpp strcuture 
     2387   !> @param[in]    td_att attribute strcuture 
     2388   !------------------------------------------------------------------- 
    21522389   SUBROUTINE mpp_add_att( td_mpp, td_att ) 
    21532390      IMPLICIT NONE 
     
    21762413            il_attid=0 
    21772414            IF( ASSOCIATED(td_mpp%t_proc(1)%t_att) )THEN 
    2178                il_attid=att_get_id( td_mpp%t_proc(1)%t_att(:), & 
     2415               il_attid=att_get_index( td_mpp%t_proc(1)%t_att(:), & 
    21792416               &                    td_att%c_name ) 
    21802417            ENDIF 
    21812418            IF( il_attid /= 0 )THEN 
    21822419 
    2183                CALL logger_error( " MPP ADD ATT: attribute "//TRIM(td_att%c_name)//& 
    2184                &  ", already in mpp "//TRIM(td_mpp%c_name) ) 
     2420               CALL logger_error( " MPP ADD ATT: attribute "//& 
     2421               &                 TRIM(td_att%c_name)//& 
     2422               &                 ", already in mpp "//TRIM(td_mpp%c_name) ) 
    21852423 
    21862424               DO ji=1,td_mpp%t_proc(1)%i_natt 
     
    21922430             
    21932431               CALL logger_info( & 
    2194                &  " MPP ADD VAR: add attribute "//TRIM(td_att%c_name)//& 
     2432               &  " MPP ADD ATT: add attribute "//TRIM(td_att%c_name)//& 
    21952433               &  ", in mpp "//TRIM(td_mpp%c_name) ) 
    21962434 
     
    22072445 
    22082446   END SUBROUTINE mpp_add_att 
    2209    !> @endcode 
    22102447   !------------------------------------------------------------------- 
    22112448   !> @brief 
     
    22132450   !> structure. 
    22142451   !> 
    2215    !> @detail 
    2216    ! 
    2217    !> @author J.Paul 
    2218    !> @date Nov, 2013 
    2219    ! 
    2220    !> @param[inout] td_mpp : mpp strcuture 
    2221    !> @param[in]    td_att : attribute strcuture 
    2222    ! 
    2223    !> @todo  
    2224    !> - check proc id exist 
    2225    !> - check proc dimension 
    2226    !> - check proc file name 
    2227    !> - check proc type 
    2228    !------------------------------------------------------------------- 
    2229    !> @code 
     2452   !> @author J.Paul 
     2453   !> @date November, 2013 - Initial version 
     2454   !> 
     2455   !> @param[inout] td_mpp mpp strcuture 
     2456   !> @param[in]    td_att attribute strcuture 
     2457   !------------------------------------------------------------------- 
    22302458   SUBROUTINE mpp__del_att_str( td_mpp, td_att ) 
    22312459      IMPLICIT NONE 
     
    22442472      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN 
    22452473 
    2246          CALL logger_error( " DEL VAR: domain decomposition not define "//& 
     2474         CALL logger_warn( "MPP DEL VAR: domain decomposition not define "//& 
    22472475         &               " in mpp strcuture "//TRIM(td_mpp%c_name)) 
    22482476 
     
    22522480         il_attid=0 
    22532481         IF( ASSOCIATED(td_mpp%t_proc(1)%t_att) )THEN 
    2254             il_attid=att_get_id( td_mpp%t_proc(1)%t_att(:), & 
     2482            il_attid=att_get_index( td_mpp%t_proc(1)%t_att(:), & 
    22552483            &                    td_att%c_name ) 
    22562484         ENDIF 
    22572485         IF( il_attid == 0 )THEN 
    2258             CALL logger_error( & 
    2259             &  " DEL VAR: no attribute "//TRIM(td_att%c_name)//& 
     2486            CALL logger_warn( & 
     2487            &  "MPP DEL VAR: no attribute "//TRIM(td_att%c_name)//& 
    22602488            &  ", in mpp structure "//TRIM(td_mpp%c_name) ) 
    22612489 
    2262             DO ji=1,td_mpp%t_proc(1)%i_natt 
    2263                CALL logger_debug( " DEL ATT: in mpp structure : & 
    2264                &  attribute : "//TRIM(td_mpp%t_proc(1)%t_var(ji)%c_name) ) 
    2265             ENDDO 
     2490            IF( ASSOCIATED(td_mpp%t_proc(1)%t_var) )THEN 
     2491               DO ji=1,td_mpp%t_proc(1)%i_natt 
     2492                  CALL logger_debug( "MPP DEL ATT: in mpp structure : & 
     2493                  &  attribute : "//TRIM(td_mpp%t_proc(1)%t_var(ji)%c_name) ) 
     2494               ENDDO 
     2495            ENDIF 
    22662496 
    22672497         ELSE 
    22682498 
    22692499            cl_name=TRIM(td_att%c_name) 
     2500            CALL logger_debug( "MPP DEL ATT: delete in mpp structure : & 
     2501            &  attribute : "//TRIM(cl_name) ) 
    22702502            DO ji=1,td_mpp%i_nproc 
    22712503               CALL file_del_att(td_mpp%t_proc(ji), TRIM(cl_name))  
     
    22762508      ENDIF 
    22772509   END SUBROUTINE mpp__del_att_str 
    2278    !> @endcode 
    22792510   !------------------------------------------------------------------- 
    22802511   !> @brief 
     
    22842515   ! 
    22852516   !> @author J.Paul 
    2286    !> @date Nov, 2013 
    2287    ! 
    2288    !> @param[inout] td_mpp : mpp strcuture 
    2289    !> @param[in]    cd_name: attribute name 
    2290    ! 
    2291    !> @todo  
    2292    !> - check proc id exist 
    2293    !> - check proc dimension 
    2294    !> - check proc file name 
    2295    !> - check proc type 
    2296    !------------------------------------------------------------------- 
    2297    !> @code 
     2517   !> @date November, 2013 - Initial version 
     2518   ! 
     2519   !> @param[inout] td_mpp    mpp strcuture 
     2520   !> @param[in]    cd_name   attribute name 
     2521   !------------------------------------------------------------------- 
    22982522   SUBROUTINE mpp__del_att_name( td_mpp, cd_name ) 
    22992523      IMPLICIT NONE 
     
    23082532      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN 
    23092533 
    2310          CALL logger_error( " DEL ATT: domain decomposition not define "//& 
     2534         CALL logger_warn( "MPP DEL ATT: domain decomposition not define "//& 
    23112535         &               " in mpp strcuture "//TRIM(td_mpp%c_name)) 
    23122536 
     
    23142538 
    23152539         IF( td_mpp%t_proc(1)%i_natt == 0 )THEN 
    2316             CALL logger_debug( " DEL ATT NAME: no attribute associated to mpp & 
     2540            CALL logger_debug( "MPP DEL ATT NAME: no attribute associated to mpp & 
    23172541            &                 structure "//TRIM(td_mpp%c_name) ) 
    23182542         ELSE 
     
    23282552 
    23292553               CALL logger_warn( & 
    2330                &  " DEL ATT : there is no attribute with "//& 
     2554               &  "MPP DEL ATT : there is no attribute with "//& 
    23312555               &  "name "//TRIM(cd_name)//" in mpp structure "//& 
    23322556               &  TRIM(td_mpp%c_name)) 
     
    23412565      ENDIF 
    23422566   END SUBROUTINE mpp__del_att_name 
    2343    !> @endcode 
    23442567   !------------------------------------------------------------------- 
    23452568   !> @brief 
    23462569   !>    This subroutine overwrite attribute in mpp structure. 
    23472570   !> 
    2348    !> @detail 
    2349    ! 
    2350    !> @author J.Paul 
    2351    !> @date Nov, 2013 
    2352    ! 
    2353    !> @param[inout] td_mpp : mpp strcuture 
    2354    !> @param[in]    td_att : attribute structure 
    2355    !> @todo 
    2356    !------------------------------------------------------------------- 
    2357    !> @code 
     2571   !> @author J.Paul 
     2572   !> @date November, 2013 - Initial version 
     2573   ! 
     2574   !> @param[inout] td_mpp mpp strcuture 
     2575   !> @param[in]    td_att attribute structure 
     2576   !------------------------------------------------------------------- 
    23582577   SUBROUTINE mpp_move_att( td_mpp, td_att ) 
    23592578      IMPLICIT NONE 
     
    23632582 
    23642583      !local variable 
    2365       TYPE(TATT) :: tl_att 
     2584      TYPE(TATT)  :: tl_att 
    23662585      !---------------------------------------------------------------- 
    23672586      ! copy variable 
    2368       tl_att=td_att 
     2587      tl_att=att_copy(td_att) 
    23692588 
    23702589      ! remove processor 
     
    23742593      CALL mpp_add_att(td_mpp, tl_att) 
    23752594 
     2595      ! clean 
     2596      CALL att_clean(tl_att) 
     2597 
    23762598   END SUBROUTINE mpp_move_att 
    2377    !> @endcode 
    23782599   !------------------------------------------------------------------- 
    23792600   !> @brief 
     
    23882609   ! 
    23892610   !> @author J.Paul 
    2390    !> @date Nov, 2013 
    2391    ! 
    2392    !> @param[inout] td_mpp : mpp strcuture 
    2393    !------------------------------------------------------------------- 
    2394    !> @code 
     2611   !> @date November, 2013 - Initial version 
     2612   ! 
     2613   !> @param[inout] td_mpp mpp strcuture 
     2614   !------------------------------------------------------------------- 
    23952615   SUBROUTINE mpp__compute( td_mpp ) 
    23962616      IMPLICIT NONE 
     
    24102630      CHARACTER(LEN=lc)                        :: cl_file 
    24112631      TYPE(TFILE)                              :: tl_proc 
    2412       TYPE(TATT)                               ::tl_att 
     2632      TYPE(TATT)                               :: tl_att 
    24132633 
    24142634      ! loop indices 
     
    24212641      td_mpp%i_nproc=0 
    24222642 
    2423       CALL logger_trace( "COMPUTE: compute domain decomposition with "//& 
     2643      CALL logger_trace( "MPP COMPUTE: compute domain decomposition with "//& 
    24242644      &               TRIM(fct_str(td_mpp%i_niproc))//" x "//& 
    24252645      &               TRIM(fct_str(td_mpp%i_njproc))//" processors") 
     
    24982718            &                (/tl_proc%i_lci, tl_proc%i_lcj/) ) 
    24992719            CALL file_add_att(tl_proc, tl_att) 
    2500  
    25012720 
    25022721            ! compute first and last indoor indices 
     
    25442763            CALL mpp__add_proc(td_mpp, tl_proc) 
    25452764 
     2765            ! clean 
     2766            CALL att_clean(tl_att) 
     2767            CALL file_clean(tl_proc) 
     2768 
    25462769         ENDDO 
    25472770      ENDDO 
     
    25512774 
    25522775   END SUBROUTINE mpp__compute 
    2553    !> @endcode 
    25542776   !------------------------------------------------------------------- 
    25552777   !> @brief  
    25562778   !>  This subroutine remove land processor from domain decomposition. 
    2557    ! 
    2558    !> @author J.Paul 
    2559    !> @date Nov, 2013 
    2560    ! 
    2561    !> @param[inout] td_mpp : mpp strcuture 
    2562    !> @param[in] id_mask : sub domain mask (sea=1, land=0) 
    2563    !------------------------------------------------------------------- 
    2564    !> @code 
     2779   !> 
     2780   !> @author J.Paul 
     2781   !> @date November, 2013 - Initial version 
     2782   !> 
     2783   !> @param[inout] td_mpp mpp strcuture 
     2784   !> @param[in] id_mask   sub domain mask (sea=1, land=0) 
     2785   !------------------------------------------------------------------- 
    25652786   SUBROUTINE mpp__del_land( td_mpp, id_mask ) 
    25662787      IMPLICIT NONE 
     
    25832804         ENDDO 
    25842805      ELSE 
    2585          CALL logger_error("DEL LAND: domain decomposition not define.") 
     2806         CALL logger_error("MPP DEL LAND: domain decomposition not define.") 
    25862807      ENDIF 
    25872808 
    25882809   END SUBROUTINE mpp__del_land 
    2589    !> @endcode 
    25902810   !------------------------------------------------------------------- 
    25912811   !> @brief  
     
    25962816   ! 
    25972817   !> @author J.Paul 
    2598    !> @date Nov, 2013 
    2599    ! 
    2600    !> @param[inout] td_mpp : mpp strcuture 
    2601    !------------------------------------------------------------------- 
    2602    !> @code 
     2818   !> @date November, 2013 - Initial version 
     2819   ! 
     2820   !> @param[inout] td_mpp mpp strcuture 
     2821   !> @param[in] id_mask   sub domain mask (sea=1, land=0)  
     2822   !------------------------------------------------------------------- 
    26032823   SUBROUTINE mpp__optimiz( td_mpp, id_mask ) 
    26042824      IMPLICIT NONE 
     
    26172837      !---------------------------------------------------------------- 
    26182838 
    2619       CALL logger_trace("OPTIMIZ: look for best domain decomposition") 
    2620       tl_mpp=td_mpp 
     2839      CALL logger_trace("MPP OPTIMIZ: look for best domain decomposition") 
     2840      tl_mpp=mpp_copy(td_mpp) 
    26212841 
    26222842      ! save maximum number of processor to be used 
     
    26292849            ! clean mpp processor 
    26302850            IF( ASSOCIATED(tl_mpp%t_proc) )THEN 
     2851               CALL file_clean(tl_mpp%t_proc(:)) 
    26312852               DEALLOCATE(tl_mpp%t_proc) 
    26322853            ENDIF 
     
    26412862            CALL mpp__del_land( tl_mpp, id_mask ) 
    26422863 
    2643             CALL logger_info("OPTIMIZ: number of processor "//& 
     2864            CALL logger_info("MPP OPTIMIZ: number of processor "//& 
    26442865            &  TRIM(fct_str(tl_mpp%i_nproc)) ) 
    26452866            IF( tl_mpp%i_nproc > td_mpp%i_nproc .AND. & 
     
    26502871               CALL mpp_clean(td_mpp) 
    26512872 
    2652                ! save processor table 
     2873               ! save processor array 
    26532874               ALLOCATE( tl_proc(tl_mpp%i_nproc) ) 
    2654                tl_proc(:)=tl_mpp%t_proc(:) 
    2655  
    2656                ! remove pointer on processor table 
     2875               tl_proc(:)=file_copy(tl_mpp%t_proc(:)) 
     2876 
     2877               ! remove pointer on processor array 
     2878               CALL file_clean(tl_mpp%t_proc(:)) 
    26572879               DEALLOCATE(tl_mpp%t_proc) 
    26582880  
    2659                ! save data except processor table 
    2660                td_mpp=tl_mpp 
    2661                ! save processor table 
     2881               ! save data except processor array 
     2882               td_mpp=mpp_copy(tl_mpp) 
     2883 
     2884               ! save processor array 
    26622885               ALLOCATE( td_mpp%t_proc(td_mpp%i_nproc) ) 
    2663                td_mpp%t_proc(:)=tl_proc(:) 
    2664  
    2665                DEALLOCATE( tl_proc ) 
     2886               td_mpp%t_proc(:)=file_copy(tl_proc(:)) 
     2887 
     2888               ! clean 
     2889               CALL file_clean( tl_proc(:) ) 
     2890               DEALLOCATE(tl_proc) 
    26662891 
    26672892            ENDIF 
     
    26702895      ENDDO 
    26712896 
     2897      ! clean 
     2898      CALL mpp_clean(tl_mpp) 
     2899 
    26722900   END SUBROUTINE mpp__optimiz 
    2673    !> @endcode 
    26742901   !------------------------------------------------------------------- 
    26752902   !> @brief 
    26762903   !>    This function check if processor is a land processor. 
    2677    ! 
    2678    !> @author J.Paul 
    2679    !> @date Nov, 2013 
    2680    ! 
    2681    !> @param[in] td_mpp : mpp strcuture 
    2682    !> @param[in] id_proc : processor id 
    2683    !> @param[in] id_mask : sub domain mask (sea=1, land=0) 
    2684    !------------------------------------------------------------------- 
    2685    !> @code 
     2904   !> 
     2905   !> @author J.Paul 
     2906   !> @date November, 2013 - Initial version 
     2907   !> 
     2908   !> @param[in] td_mpp    mpp strcuture 
     2909   !> @param[in] id_proc   processor id 
     2910   !> @param[in] id_mask   sub domain mask (sea=1, land=0) 
     2911   !------------------------------------------------------------------- 
    26862912   LOGICAL FUNCTION mpp__land_proc( td_mpp , id_proc, id_mask ) 
    26872913      IMPLICIT NONE 
     
    26952921      !---------------------------------------------------------------- 
    26962922 
    2697       CALL logger_trace("LAND PROC: check processor "//TRIM(fct_str(id_proc))//& 
     2923      CALL logger_trace("MPP LAND PROC: check processor "//TRIM(fct_str(id_proc))//& 
    26982924      &  " of mpp "//TRIM(td_mpp%c_name) ) 
    26992925      mpp__land_proc=.FALSE. 
     
    27032929         IF( il_shape(1) /= td_mpp%t_dim(1)%i_len .OR. & 
    27042930         &   il_shape(2) /= td_mpp%t_dim(2)%i_len )THEN 
    2705              CALL logger_error("LAND PROC: mask and domain size differ") 
     2931             CALL logger_debug("MPP LAND PROC: mask size ("//& 
     2932             &                  TRIM(fct_str(il_shape(1)))//","//& 
     2933             &                  TRIM(fct_str(il_shape(2)))//")") 
     2934             CALL logger_debug("MPP LAND PROC: domain size ("//& 
     2935             &                  TRIM(fct_str(td_mpp%t_dim(1)%i_len))//","//& 
     2936             &                  TRIM(fct_str(td_mpp%t_dim(2)%i_len))//")") 
     2937             CALL logger_error("MPP LAND PROC: mask and domain size differ") 
    27062938         ELSE 
    27072939            IF( ALL(id_mask( td_mpp%t_proc(id_proc)%i_impp +            & 
     
    27152947            &      /= 1 ) )THEN 
    27162948               ! land domain 
    2717                CALL logger_info(" LAND PROC: processor "//TRIM(fct_str(id_proc))//& 
     2949               CALL logger_info("MPP LAND PROC: processor "//TRIM(fct_str(id_proc))//& 
    27182950               &             " is land processor") 
    27192951               mpp__land_proc=.TRUE. 
     
    27222954 
    27232955      ELSE 
    2724          CALL logger_error("LAND PROC: domain decomposition not define.") 
     2956         CALL logger_error("MPP LAND PROC: domain decomposition not define.") 
    27252957      ENDIF 
    27262958 
    27272959   END FUNCTION mpp__land_proc 
    2728    !> @endcode 
    27292960   !------------------------------------------------------------------- 
    27302961   !> @brief  
    27312962   !>  This subroutine clean mpp strcuture. 
    2732    ! 
    2733    !> @author J.Paul 
    2734    !> @date Nov, 2013 
    2735    ! 
    2736    !> @param[inout] td_mpp : mpp strcuture 
    2737    !------------------------------------------------------------------- 
    2738    !> @code 
    2739    SUBROUTINE mpp_clean( td_mpp ) 
     2963   !> 
     2964   !> @author J.Paul 
     2965   !> @date November, 2013 - Initial version 
     2966   !> 
     2967   !> @param[inout] td_mpp mpp strcuture 
     2968   !------------------------------------------------------------------- 
     2969   SUBROUTINE mpp__clean_unit( td_mpp ) 
    27402970      IMPLICIT NONE 
    27412971      ! Argument 
     
    27462976 
    27472977      ! loop indices 
    2748       INTEGER(i4) :: ji 
    27492978      !---------------------------------------------------------------- 
    27502979 
    27512980      CALL logger_info( & 
    2752       &  " CLEAN: reset mpp "//TRIM(td_mpp%c_name) ) 
     2981      &  "MPP CLEAN: reset mpp "//TRIM(td_mpp%c_name) ) 
    27532982 
    27542983      ! del dimension 
    27552984      IF( td_mpp%i_ndim /= 0 )THEN 
    2756          DO ji=td_mpp%i_ndim,1,-1 
    2757             CALL dim_clean( td_mpp%t_dim(ji) ) 
    2758          ENDDO 
     2985         CALL dim_clean( td_mpp%t_dim(:) ) 
    27592986      ENDIF 
    27602987 
    27612988      IF( ASSOCIATED(td_mpp%t_proc) )THEN 
    2762          ! clean each proc 
    2763          DO ji=1,td_mpp%i_nproc 
    2764             CALL file_clean( td_mpp%t_proc(ji) ) 
    2765          ENDDO 
     2989         ! clean array of file processor 
     2990         CALL file_clean( td_mpp%t_proc(:) ) 
    27662991         DEALLOCATE(td_mpp%t_proc) 
    27672992      ENDIF 
    27682993 
    27692994      ! replace by empty structure 
    2770       td_mpp=tl_mpp 
    2771  
    2772    END SUBROUTINE mpp_clean 
    2773    !> @endcode 
     2995      td_mpp=mpp_copy(tl_mpp) 
     2996 
     2997   END SUBROUTINE mpp__clean_unit 
     2998   !------------------------------------------------------------------- 
     2999   !> @brief  
     3000   !>  This subroutine clean mpp strcuture. 
     3001   !> 
     3002   !> @author J.Paul 
     3003   !> @date November, 2013 - Initial version 
     3004   !> 
     3005   !> @param[inout] td_mpp mpp strcuture 
     3006   !------------------------------------------------------------------- 
     3007   SUBROUTINE mpp__clean_arr( td_mpp ) 
     3008      IMPLICIT NONE 
     3009      ! Argument 
     3010      TYPE(TMPP),  DIMENSION(:), INTENT(INOUT) :: td_mpp 
     3011 
     3012      ! local variable 
     3013      ! loop indices 
     3014      INTEGER(i4) :: ji 
     3015      !---------------------------------------------------------------- 
     3016 
     3017      DO ji=SIZE(td_mpp(:)),1,-1 
     3018         CALL mpp_clean(td_mpp(ji)) 
     3019      ENDDO 
     3020 
     3021   END SUBROUTINE mpp__clean_arr 
    27743022   !------------------------------------------------------------------- 
    27753023   !> @brief  
    27763024   !>  This subroutine get sub domains which cover "zoom domain". 
    2777    ! 
    2778    !> @author J.Paul 
    2779    !> @date Nov, 2013 
    2780    ! 
    2781    !> @param[inout] td_mpp : mpp strcuture 
    2782    !> @param[in] td_dom : domain strcuture 
    2783    !------------------------------------------------------------------- 
    2784    !> @code 
    2785    SUBROUTINE mpp_get_use( td_mpp, td_dom ) 
     3025   !> 
     3026   !> @author J.Paul 
     3027   !> @date November, 2013 - Initial version 
     3028   !> 
     3029   !> @param[inout] td_mpp mpp strcuture 
     3030   !> @param[in] id_imin   i-direction lower indice 
     3031   !> @param[in] id_imax   i-direction upper indice 
     3032   !> @param[in] id_jmin   j-direction lower indice 
     3033   !> @param[in] id_jmax   j-direction upper indice 
     3034   !------------------------------------------------------------------- 
     3035   SUBROUTINE mpp__get_use_unit( td_mpp, id_imin, id_imax, & 
     3036   &                                     id_jmin, id_jmax ) 
    27863037      IMPLICIT NONE 
    27873038      ! Argument 
    2788       TYPE(TMPP),  INTENT(INOUT) :: td_mpp 
    2789       TYPE(TDOM),  INTENT(IN)    :: td_dom 
     3039      TYPE(TMPP) ,  INTENT(INOUT) :: td_mpp 
     3040      INTEGER(i4),  INTENT(IN), OPTIONAL :: id_imin 
     3041      INTEGER(i4),  INTENT(IN), OPTIONAL :: id_imax 
     3042      INTEGER(i4),  INTENT(IN), OPTIONAL :: id_jmin 
     3043      INTEGER(i4),  INTENT(IN), OPTIONAL :: id_jmax 
    27903044 
    27913045      ! local variable 
    2792       INTEGER(i4) :: il_jmin 
    27933046      LOGICAL     :: ll_iuse 
    27943047      LOGICAL     :: ll_juse 
    27953048 
     3049      INTEGER(i4) :: il_imin 
     3050      INTEGER(i4) :: il_imax 
     3051      INTEGER(i4) :: il_jmin 
     3052      INTEGER(i4) :: il_jmax 
     3053 
    27963054      ! loop indices 
    27973055      INTEGER(i4) :: jk 
     
    27993057      IF( ASSOCIATED(td_mpp%t_proc) )THEN 
    28003058    
     3059         il_imin=1 
     3060         il_imax=td_mpp%t_dim(1)%i_len 
     3061         IF( PRESENT(id_imin) ) il_imin=id_imin 
     3062         IF( PRESENT(id_imax) ) il_imax=id_imax 
     3063         il_jmin=1 
     3064         il_jmax=td_mpp%t_dim(2)%i_len 
     3065         IF( PRESENT(id_jmin) ) il_jmin=id_jmin 
     3066         IF( PRESENT(id_jmax) ) il_jmax=id_jmax 
     3067 
    28013068         ! check domain 
    2802          IF( td_mpp%t_dim(1)%i_len == td_dom%t_dim0(1)%i_len .AND. & 
    2803          &   td_mpp%t_dim(2)%i_len == td_dom%t_dim0(2)%i_len )THEN 
    2804  
     3069         IF( il_imin < 1 .OR. il_imin > td_mpp%t_dim(1)%i_len .OR. & 
     3070         &   il_imax < 1 .OR. il_imax > td_mpp%t_dim(1)%i_len .OR. & 
     3071         &   il_jmin < 1 .OR. il_jmin > td_mpp%t_dim(2)%i_len .OR. & 
     3072         &   il_jmax < 1 .OR. il_jmax > td_mpp%t_dim(2)%i_len )THEN 
     3073            CALL logger_debug("MPP GET USE: mpp gloabl size "//& 
     3074            &        TRIM(fct_str(td_mpp%t_dim(1)%i_len))//","//& 
     3075            &        TRIM(fct_str(td_mpp%t_dim(2)%i_len))) 
     3076            CALL logger_debug("MPP GET USE: i-indices "//& 
     3077            &        TRIM(fct_str(il_imin))//","//TRIM(fct_str(il_imax))) 
     3078            CALL logger_debug("MPP GET USE: j-indices "//& 
     3079            &        TRIM(fct_str(il_jmin))//","//TRIM(fct_str(il_jmax))) 
     3080            CALL logger_error("MPP GET USE: invalid indices ") 
     3081         ELSE 
    28053082            td_mpp%t_proc(:)%l_use=.FALSE. 
    28063083            DO jk=1,td_mpp%i_nproc 
     
    28083085               ! check i-direction 
    28093086               ll_iuse=.FALSE. 
    2810                IF( td_dom%i_imin < td_dom%i_imax )THEN 
     3087               IF( il_imin < il_imax )THEN 
    28113088 
    28123089                  ! not overlap east west boundary 
    28133090                  IF( td_mpp%t_proc(jk)%i_impp + td_mpp%t_proc(jk)%i_lci > & 
    2814                   &   td_dom%i_imin .AND.                                  & 
    2815                   &   td_mpp%t_proc(jk)%i_impp < td_dom%i_imax )THEN 
     3091                  &   il_imin .AND.                                  & 
     3092                  &   td_mpp%t_proc(jk)%i_impp < il_imax )THEN 
    28163093                      ll_iuse=.TRUE. 
    28173094                  ENDIF 
    28183095 
    2819                ELSEIF( td_dom%i_imin == td_dom%i_imax )THEN 
     3096               ELSEIF( il_imin == il_imax )THEN 
    28203097 
    28213098                  ! east west cyclic 
    28223099                  ll_iuse=.TRUE. 
    28233100 
    2824                ELSE ! td_dom%i_imin > td_dom%i_imax 
     3101               ELSE ! il_imin > id_imax 
    28253102 
    28263103                  ! overlap east west boundary 
    28273104                  IF( ( td_mpp%t_proc(jk)%i_impp + td_mpp%t_proc(jk)%i_lci >  & 
    2828                   &     td_dom%i_imin .AND.                                   & 
    2829                   &     td_mpp%t_proc(jk)%i_impp < td_dom%t_dim0(1)%i_len )    & 
     3105                  &     il_imin )                                             & 
    28303106                  &   .OR.                                                    & 
    2831                   &   ( td_mpp%t_proc(jk)%i_impp + td_mpp%t_proc(jk)%i_lci >  & 
    2832                   &     1 .AND.                                               & 
    2833                   &     td_mpp%t_proc(jk)%i_impp < td_dom%i_imax) )THEN 
     3107                  &   ( td_mpp%t_proc(jk)%i_impp < il_imax) )THEN 
    28343108                     ll_iuse=.TRUE. 
    28353109                  ENDIF 
     
    28393113               ! check j-direction 
    28403114               ll_juse=.FALSE. 
    2841                IF( td_dom%i_jmin < td_dom%i_jmax )THEN 
     3115               IF( il_jmin < il_jmax )THEN 
    28423116 
    28433117                  ! not overlap north fold 
    28443118                  IF( td_mpp%t_proc(jk)%i_jmpp + td_mpp%t_proc(jk)%i_lcj > & 
    2845                   &   td_dom%i_jmin .AND.                                  & 
    2846                   &   td_mpp%t_proc(jk)%i_jmpp < td_dom%i_jmax )THEN 
     3119                  &   il_jmin .AND.                                  & 
     3120                  &   td_mpp%t_proc(jk)%i_jmpp < il_jmax )THEN 
    28473121                     ll_juse=.TRUE. 
    28483122                  ENDIF 
    28493123 
    2850                ELSE ! td_dom%i_jmin >= td_dom%i_jmax 
    2851  
    2852                   il_jmin=MIN(td_dom%i_jmin,td_dom%i_jmax) 
     3124               ELSE ! id_jmin >= id_jmax 
     3125 
    28533126                  IF( td_mpp%t_proc(jk)%i_jmpp + td_mpp%t_proc(jk)%i_lcj > & 
    28543127                  &  il_jmin )THEN 
     
    28613134 
    28623135            ENDDO 
    2863          ELSE 
    2864             CALL logger_error("GET USE: domain differ") 
    28653136         ENDIF 
    28663137 
    28673138      ELSE 
    2868          CALL logger_error("GET USE: domain decomposition not define.") 
    2869       ENDIF 
    2870  
    2871    END SUBROUTINE mpp_get_use 
    2872    !> @endcode 
     3139         CALL logger_error("MPP GET USE: mpp decomposition not define.") 
     3140      ENDIF 
     3141 
     3142   END SUBROUTINE mpp__get_use_unit 
    28733143   !------------------------------------------------------------------- 
    28743144   !> @brief  
    28753145   !>  This subroutine get sub domains which form global domain border. 
    2876    ! 
    2877    !> @author J.Paul 
    2878    !> @date Nov, 2013 
    2879    ! 
    2880    !> @param[inout] td_mpp : mpp strcuture 
    2881    !------------------------------------------------------------------- 
    2882    !> @code 
     3146   !> 
     3147   !> @author J.Paul 
     3148   !> @date November, 2013 
     3149   !> 
     3150   !> @param[inout] td_mpp mpp strcuture 
     3151   !------------------------------------------------------------------- 
    28833152   SUBROUTINE mpp_get_contour( td_mpp ) 
    28843153      IMPLICIT NONE 
     
    28923161      IF( ASSOCIATED(td_mpp%t_proc) )THEN 
    28933162 
    2894          td_mpp%t_proc(:)%l_ctr = .FALSE. 
     3163         td_mpp%t_proc(:)%l_use = .FALSE. 
    28953164         DO jk=1,td_mpp%i_nproc 
    28963165            IF( td_mpp%t_proc(jk)%i_ldi == 1 .OR. & 
     
    28993168            &   td_mpp%t_proc(jk)%i_lej == td_mpp%t_proc(jk)%i_lcj )THEN 
    29003169 
    2901                td_mpp%t_proc(jk)%l_ctr = .TRUE. 
    2902              
     3170               td_mpp%t_proc(jk)%l_use = .TRUE. 
     3171  
    29033172            ENDIF 
    29043173         ENDDO 
    29053174    
    29063175      ELSE 
    2907          CALL logger_error("GET CONTOUR: domain decomposition not define.") 
     3176         CALL logger_error("MPP GET CONTOUR: domain decomposition not define.") 
    29083177      ENDIF 
    29093178 
    29103179   END SUBROUTINE mpp_get_contour 
    2911    !> @endcode 
    29123180   !------------------------------------------------------------------- 
    29133181   !> @brief 
    29143182   !> This function return processor indices, without overlap boundary, 
    2915    !> given processor id. This depends of domain decompisition type.  
    2916    ! 
    2917    !> @author J.Paul 
    2918    !> @date Nov, 2013 
    2919    ! 
    2920    !> @param[in] td_mpp : mpp strcuture 
    2921    !> @param[in] id_procid : processor id 
    2922    !> @return table of index (/ i1, i2, j1, j2 /) 
    2923    !------------------------------------------------------------------- 
    2924    !> @code 
     3183   !> given processor id.  
     3184   !> 
     3185   !> @author J.Paul 
     3186   !> @date November, 2013 
     3187   !> 
     3188   !> @param[in] td_mpp    mpp strcuture 
     3189   !> @param[in] id_procid processor id 
     3190   !> @return array of index (/ i1, i2, j1, j2 /) 
     3191   !------------------------------------------------------------------- 
    29253192   FUNCTION mpp_get_proc_index( td_mpp, id_procid ) 
    29263193      IMPLICIT NONE 
    29273194 
    29283195      ! Argument 
    2929       TYPE(TMPP), INTENT(IN) :: td_mpp 
     3196      TYPE(TMPP) , INTENT(IN) :: td_mpp 
    29303197      INTEGER(i4), INTENT(IN) :: id_procid 
    29313198 
     
    29363203      INTEGER(i4) :: il_i1, il_i2 
    29373204      INTEGER(i4) :: il_j1, il_j2 
    2938       TYPE(TMPP)  :: tl_mpp 
    29393205      !---------------------------------------------------------------- 
    29403206 
    29413207      IF( ASSOCIATED(td_mpp%t_proc) )THEN 
    29423208 
    2943          tl_mpp=td_mpp 
    2944          !IF( TRIM(td_mpp%c_dom) == "unknown" )THEN 
    29453209         IF( TRIM(td_mpp%c_dom) == '' )THEN 
    2946             CALL logger_warn("GET PROC INDEX: decomposition type unknown. "//& 
    2947             &             "look for it") 
    2948             CALL mpp_get_dom( tl_mpp ) 
     3210            CALL logger_fatal("MPP GET PROC INDEX: decomposition type unknown. "//& 
     3211            &                 "you should ahve run mpp_get_dom before.") 
    29493212         ENDIF 
    29503213 
    2951          SELECT CASE(TRIM(tl_mpp%c_dom)) 
     3214         SELECT CASE(TRIM(td_mpp%c_dom)) 
    29523215            CASE('full') 
    29533216               il_i1 = 1 ; il_i2 = td_mpp%t_dim(1)%i_len 
     
    29573220                il_j1 = td_mpp%t_proc(id_procid)%i_jmpp 
    29583221 
    2959                 il_i2 = il_i1 + td_mpp%t_proc(id_procid)%i_lci - 1 ! attention lei dans ioRestartDimg 
     3222                il_i2 = il_i1 + td_mpp%t_proc(id_procid)%i_lci - 1  
    29603223                il_j2 = il_j1 + td_mpp%t_proc(id_procid)%i_lcj - 1  
    29613224            CASE('nooverlap') 
     
    29703233               &        td_mpp%t_proc(id_procid)%i_lej - 1 
    29713234            CASE DEFAULT 
    2972                CALL logger_error("GET PROC INDEX: invalid decomposition type.") 
     3235               CALL logger_error("MPP GET PROC INDEX: invalid decomposition type.") 
    29733236         END SELECT 
    29743237 
     
    29763239 
    29773240      ELSE 
    2978          CALL logger_error("GET PROC INDEX: domain decomposition not define.") 
     3241         CALL logger_error("MPP GET PROC INDEX: domain decomposition not define.") 
    29793242      ENDIF 
    29803243 
    29813244   END FUNCTION mpp_get_proc_index 
    2982    !> @endcode 
    29833245   !------------------------------------------------------------------- 
    29843246   !> @brief 
     
    29873249   ! 
    29883250   !> @author J.Paul 
    2989    !> @date Nov, 2013 
    2990    ! 
    2991    !> @param[in] td_mpp : mpp strcuture 
    2992    !> @param[in] id_procid : sub domain id 
    2993    !> @return table of index (/ isize, jsize /) 
    2994    !------------------------------------------------------------------- 
    2995    !> @code 
     3251   !> @date November, 2013 
     3252   ! 
     3253   !> @param[in] td_mpp    mpp strcuture 
     3254   !> @param[in] id_procid sub domain id 
     3255   !> @return array of index (/ isize, jsize /) 
     3256   !------------------------------------------------------------------- 
    29963257   FUNCTION mpp_get_proc_size( td_mpp, id_procid ) 
    29973258      IMPLICIT NONE 
     
    30073268      INTEGER(i4) :: il_isize 
    30083269      INTEGER(i4) :: il_jsize 
    3009       TYPE(TMPP)  :: tl_mpp 
    30103270      !---------------------------------------------------------------- 
    30113271 
    30123272      IF( ASSOCIATED(td_mpp%t_proc) )THEN 
    30133273 
    3014          tl_mpp=td_mpp 
    3015          !IF( TRIM(td_mpp%c_dom) == "unknown" )THEN 
    30163274         IF( TRIM(td_mpp%c_dom) == '' )THEN 
    3017             CALL logger_warn("GET PROC SIZE: decomposition type unknown. "//& 
    3018             &              "look for it") 
    3019             CALL mpp_get_dom( tl_mpp ) 
     3275            CALL logger_fatal("MPP GET PROC SIZE: decomposition type unknown. "//& 
     3276            &                 "you should ahve run mpp_get_dom before.") 
    30203277         ENDIF 
    30213278 
    3022          SELECT CASE(TRIM(tl_mpp%c_dom)) 
     3279         SELECT CASE(TRIM(td_mpp%c_dom)) 
    30233280            CASE('full') 
    30243281                
     
    30373294               &          td_mpp%t_proc(id_procid)%i_ldj + 1 
    30383295            CASE DEFAULT 
    3039                CALL logger_error("GET PROC SIZE: invalid decomposition type : "//& 
    3040                &  TRIM(tl_mpp%c_dom) ) 
     3296               CALL logger_error("MPP GET PROC SIZE: invalid decomposition type : "//& 
     3297               &  TRIM(td_mpp%c_dom) ) 
    30413298         END SELECT 
    30423299 
     
    30443301 
    30453302      ELSE 
    3046          CALL logger_error("GET PROC SIZE: domain decomposition not define.") 
     3303         CALL logger_error("MPP GET PROC SIZE: domain decomposition not define.") 
    30473304      ENDIF 
    30483305 
    30493306   END FUNCTION mpp_get_proc_size 
    3050    !> @endcode 
    30513307   !------------------------------------------------------------------- 
    30523308   !> @brief  
    30533309   !>  This subroutine determine domain decomposition type. 
    30543310   !>  (full, overlap, noverlap) 
    3055    ! 
    3056    !> @author J.Paul 
    3057    !> @date Nov, 2013 
    3058    ! 
    3059    !> @param[inout] td_mpp : mpp strcuture 
    3060    !> @todo 
    3061    !> - change name, confusing with domain.f90 
    3062    !------------------------------------------------------------------- 
    3063    !> @code 
     3311   !> 
     3312   !> @author J.Paul 
     3313   !> @date November, 2013 
     3314   !> 
     3315   !> @param[inout] td_mpp mpp strcuture 
     3316   !------------------------------------------------------------------- 
    30643317   SUBROUTINE mpp_get_dom( td_mpp ) 
    30653318      IMPLICIT NONE 
     
    30753328 
    30763329         IF( td_mpp%i_niproc == 0 .AND. td_mpp%i_niproc == 0 )THEN 
    3077             CALL logger_info("GET DOM: use indoor indices to get domain "//& 
     3330            CALL logger_info("MPP GET DOM: use indoor indices to get domain "//& 
    30783331            &             "decomposition type.") 
    30793332            IF((td_mpp%t_proc(1)%t_dim(1)%i_len ==                         & 
     
    31003353            ELSE 
    31013354 
    3102                CALL logger_error("GET DOM: should have been an impossible case") 
     3355               CALL logger_error("MPP GET DOM: should have been an impossible case") 
    31033356 
    31043357               il_isize=td_mpp%t_proc(1)%t_dim(1)%i_len 
    31053358               il_jsize=td_mpp%t_proc(1)%t_dim(2)%i_len 
    3106                CALL logger_debug("GET DOM: proc size "//& 
     3359               CALL logger_debug("MPP GET DOM: proc size "//& 
    31073360               &  TRIM(fct_str(il_isize))//" x "//TRIM(fct_str(il_jsize)) ) 
    31083361 
    31093362               il_isize=td_mpp%t_proc(1)%i_lei - td_mpp%t_proc(1)%i_ldi + 1 
    31103363               il_jsize=td_mpp%t_proc(1)%i_lej - td_mpp%t_proc(1)%i_ldj + 1 
    3111                CALL logger_debug("GET DOM: no overlap size "//& 
     3364               CALL logger_debug("MPP GET DOM: no overlap size "//& 
    31123365               &  TRIM(fct_str(il_isize))//" x "//TRIM(fct_str(il_jsize)) ) 
    31133366 
    31143367               il_isize=td_mpp%t_proc(1)%i_lci 
    31153368               il_jsize=td_mpp%t_proc(1)%i_lcj 
    3116                CALL logger_debug("GET DOM: overlap size "//& 
     3369               CALL logger_debug("MPP GET DOM: overlap size "//& 
    31173370               &  TRIM(fct_str(il_isize))//" x "//TRIM(fct_str(il_jsize)) ) 
    31183371 
    31193372               il_isize=td_mpp%t_dim(1)%i_len 
    31203373               il_jsize=td_mpp%t_dim(2)%i_len 
    3121                CALL logger_debug("GET DOM: full size "//& 
     3374               CALL logger_debug("MPP GET DOM: full size "//& 
    31223375               &  TRIM(fct_str(il_isize))//" x "//TRIM(fct_str(il_jsize)) ) 
    31233376 
     
    31263379         ELSE 
    31273380 
    3128             CALL logger_info("GET DOM: use number of processors following "//& 
     3381            CALL logger_info("MPP GET DOM: use number of processors following "//& 
    31293382            &             "I and J to get domain decomposition type.") 
    31303383            IF( td_mpp%i_niproc*td_mpp%i_njproc==td_mpp%i_nproc )THEN 
     
    31403393 
    31413394      ELSE 
    3142          CALL logger_error("GET DOM: domain decomposition not define.") 
     3395         CALL logger_error("MPP GET DOM: domain decomposition not define.") 
    31433396      ENDIF 
    31443397 
    31453398   END SUBROUTINE mpp_get_dom 
    3146    !> @endcode 
    31473399   !------------------------------------------------------------------- 
    31483400   !> @brief This function check if variable  and mpp structure use same 
    31493401   !> dimension. 
    3150    ! 
     3402   !> 
    31513403   !> @details 
    3152    ! 
    3153    !> @author J.Paul 
    3154    !> - Nov, 2013- Initial Version 
    3155    ! 
    3156    !> @param[in] td_mpp : mpp structure 
    3157    !> @param[in] td_var : variable structure 
     3404   !> 
     3405   !> @author J.Paul 
     3406   !> - November, 2013- Initial Version 
     3407   !> 
     3408   !> @param[in] td_mpp mpp structure 
     3409   !> @param[in] td_var variable structure 
    31583410   !> @return dimension of variable and mpp structure agree (or not) 
    31593411   !------------------------------------------------------------------- 
    3160    ! @code 
    31613412   LOGICAL FUNCTION mpp__check_var_dim(td_mpp, td_var) 
    31623413      IMPLICIT NONE 
     
    31793430 
    31803431         CALL logger_error( & 
    3181          &  " CHECK DIM: variable and mpp dimension differ"//& 
     3432         &  "MPP CHECK DIM: variable and mpp dimension differ"//& 
    31823433         &  " for variable "//TRIM(td_var%c_name)//& 
    31833434         &  " and mpp "//TRIM(td_mpp%c_name)) 
     
    31893440         DO ji = 1, il_ndim 
    31903441            CALL logger_debug( & 
    3191             &  " CHECK DIM: for dimension "//& 
     3442            &  "MPP CHECK DIM: for dimension "//& 
    31923443            &  TRIM(td_mpp%t_dim(ji)%c_name)//& 
    31933444            &  ", mpp length: "//& 
     
    32003451 
    32013452   END FUNCTION mpp__check_var_dim 
    3202    ! @endcode 
     3453   !------------------------------------------------------------------- 
     3454   !> @brief This function return the mpp id, in a array of mpp 
     3455   !> structure,  given mpp base name.  
     3456   ! 
     3457   !> @author J.Paul 
     3458   !> - November, 2013- Initial Version 
     3459   ! 
     3460   !> @param[in] td_file   array of file structure 
     3461   !> @param[in] cd_name   file name 
     3462   !> @return file id in array of file structure (0 if not found) 
     3463   !------------------------------------------------------------------- 
     3464   INTEGER(i4) FUNCTION mpp_get_index(td_mpp, cd_name) 
     3465      IMPLICIT NONE 
     3466      ! Argument       
     3467      TYPE(TMPP)      , DIMENSION(:), INTENT(IN) :: td_mpp 
     3468      CHARACTER(LEN=*),               INTENT(IN) :: cd_name 
     3469 
     3470      ! local variable 
     3471      CHARACTER(LEN=lc) :: cl_name 
     3472      INTEGER(i4)       :: il_size 
     3473 
     3474      ! loop indices 
     3475      INTEGER(i4) :: ji 
     3476      !---------------------------------------------------------------- 
     3477      mpp_get_index=0 
     3478      il_size=SIZE(td_mpp(:)) 
     3479 
     3480      cl_name=TRIM( file_rename(cd_name) ) 
     3481 
     3482      ! check if mpp is in array of mpp structure 
     3483      DO ji=1,il_size 
     3484         ! look for file name 
     3485         IF( TRIM(fct_lower(td_mpp(ji)%c_name)) == TRIM(fct_lower(cd_name)) )THEN 
     3486  
     3487            mpp_get_index=ji 
     3488            EXIT 
     3489 
     3490         ENDIF 
     3491      ENDDO 
     3492 
     3493   END FUNCTION mpp_get_index 
     3494   !------------------------------------------------------------------- 
     3495   !> @brief This function recombine variable splitted mpp structure.  
     3496   ! 
     3497   !> @author J.Paul 
     3498   !> - Ocotber, 2014- Initial Version 
     3499   ! 
     3500   !> @param[in] td_mpp   mpp file structure 
     3501   !> @param[in] cd_name  variable name 
     3502   !> @return variable strucutre 
     3503   !------------------------------------------------------------------- 
     3504   TYPE(TVAR) FUNCTION mpp_recombine_var(td_mpp, cd_name)  
     3505   IMPLICIT NONE 
     3506      ! Argument       
     3507      TYPE(TMPP)      , INTENT(IN) :: td_mpp 
     3508      CHARACTER(LEN=*), INTENT(IN) :: cd_name 
     3509 
     3510      ! local variable 
     3511      INTEGER(i4)                       :: il_varid 
     3512      INTEGER(i4)                       :: il_status 
     3513      INTEGER(i4)                       :: il_i1p 
     3514      INTEGER(i4)                       :: il_i2p 
     3515      INTEGER(i4)                       :: il_j1p 
     3516      INTEGER(i4)                       :: il_j2p 
     3517      INTEGER(i4), DIMENSION(4)         :: il_ind 
     3518 
     3519      INTEGER(i4), DIMENSION(ip_maxdim) :: il_strt 
     3520      INTEGER(i4), DIMENSION(ip_maxdim) :: il_cnt 
     3521 
     3522      TYPE(TVAR)                        :: tl_tmp 
     3523      TYPE(TVAR)                        :: tl_var 
     3524 
     3525      ! loop indices 
     3526      INTEGER(i4) :: ji 
     3527      INTEGER(i4) :: jk 
     3528      !---------------------------------------------------------------- 
     3529 
     3530      il_varid=var_get_index( td_mpp%t_proc(1)%t_var(:), cd_name) 
     3531      IF( il_varid /= 0 )THEN 
     3532       
     3533         tl_var=var_copy(td_mpp%t_proc(1)%t_var(il_varid)) 
     3534         ! Allocate space to hold variable value in structure  
     3535         IF( ASSOCIATED(tl_var%d_value) )THEN 
     3536            DEALLOCATE(tl_var%d_value)    
     3537         ENDIF 
     3538         !  
     3539         DO ji=1,ip_maxdim 
     3540            IF( tl_var%t_dim(ji)%l_use )THEN 
     3541               tl_var%t_dim(ji)%i_len=td_mpp%t_dim(ji)%i_len 
     3542            ENDIF 
     3543         ENDDO 
     3544 
     3545         ALLOCATE(tl_var%d_value( tl_var%t_dim(1)%i_len, & 
     3546         &                        tl_var%t_dim(2)%i_len, & 
     3547         &                        tl_var%t_dim(3)%i_len, & 
     3548         &                        tl_var%t_dim(4)%i_len),& 
     3549         &        stat=il_status) 
     3550         IF(il_status /= 0 )THEN 
     3551 
     3552           CALL logger_error( & 
     3553            &  " MPP RECOMBINE VAR: not enough space to put variable "//& 
     3554            &  TRIM(tl_var%c_name)//" in variable structure") 
     3555 
     3556         ENDIF 
     3557 
     3558         ! FillValue by default 
     3559         tl_var%d_value(:,:,:,:)=tl_var%d_fill 
     3560 
     3561         ! read processor  
     3562         DO jk=1,td_mpp%i_nproc 
     3563            IF( td_mpp%t_proc(jk)%l_use )THEN 
     3564               ! get processor indices 
     3565               il_ind(:)=mpp_get_proc_index( td_mpp, jk ) 
     3566               il_i1p = il_ind(1) 
     3567               il_i2p = il_ind(2) 
     3568               il_j1p = il_ind(3) 
     3569               il_j2p = il_ind(4) 
     3570  
     3571               il_strt(:)=(/ 1,1,1,1 /) 
     3572 
     3573               il_cnt(:)=(/ il_i2p-il_i1p+1,         & 
     3574               &            il_j2p-il_j1p+1,         & 
     3575               &            tl_var%t_dim(3)%i_len, & 
     3576               &            tl_var%t_dim(4)%i_len /) 
     3577 
     3578               tl_tmp=iom_read_var( td_mpp%t_proc(jk), tl_var%c_name,& 
     3579               &                    il_strt(:), il_cnt(:) ) 
     3580                
     3581               ! replace value in output variable structure 
     3582               tl_var%d_value( il_i1p : il_i2p,  & 
     3583               &               il_j1p : il_j2p,  & 
     3584               &               :,:) = tl_tmp%d_value(:,:,:,:) 
     3585 
     3586               ! clean 
     3587               CALL var_clean(tl_tmp) 
     3588 
     3589            ENDIF 
     3590         ENDDO 
     3591 
     3592         mpp_recombine_var=var_copy(tl_var) 
     3593 
     3594         ! clean 
     3595         CALL var_clean(tl_var) 
     3596 
     3597      ELSE 
     3598 
     3599         CALL logger_error( & 
     3600         &  " MPP RECOMBINE VAR: there is no variable with "//& 
     3601         &  "name or standard name"//TRIM(cd_name)//& 
     3602         &  " in mpp file "//TRIM(td_mpp%c_name)) 
     3603      ENDIF 
     3604   END FUNCTION mpp_recombine_var 
    32033605END MODULE mpp 
    32043606 
Note: See TracChangeset for help on using the changeset viewer.