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 6225 for branches/2014/dev_r4704_NOC5_MPP_BDY_UPDATE/NEMOGCM/TOOLS/SIREN/src/create_bathy.f90 – NEMO

Ignore:
Timestamp:
2016-01-08T10:35:19+01:00 (8 years ago)
Author:
jamesharle
Message:

Update MPP_BDY_UPDATE branch to be consistent with head of trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2014/dev_r4704_NOC5_MPP_BDY_UPDATE/NEMOGCM/TOOLS/SIREN/src/create_bathy.f90

    r4213 r6225  
    33!---------------------------------------------------------------------- 
    44! 
    5 ! 
    65! PROGRAM: create_bathy 
    76! 
    87! DESCRIPTION: 
     8!> @file 
    99!> @brief  
    10 !> This program create bathymetry file. 
     10!> This program create fine grid bathymetry file. 
    1111!> 
    1212!> @details 
    13 !> Bathymetry could be extracted from fine grid Bathymetry file, or interpolated 
    14 !> from coarse grid Bathymetry file. 
    15 !> 
    16 !> @author 
    17 !> J.Paul 
     13!> @section sec1 method 
     14!> Bathymetry could be extracted from fine grid Bathymetry file, interpolated 
     15!> from coarse grid Bathymetry file, or manually written. 
     16!> 
     17!> @section sec2 how to 
     18!>    to create fine grid bathymetry file:<br/> 
     19!> @code{.sh} 
     20!>    ./SIREN/bin/create_bathy create_bathy.nam 
     21!> @endcode 
     22!> <br/>     
     23!> \image html  bathy_40.png  
     24!> \image latex bathy_30.png 
     25!> 
     26!> @note  
     27!>    you could find a template of the namelist in templates directory. 
     28!> 
     29!>    create_bathy.nam comprise 7 namelists:<br/> 
     30!>       - logger namelist (namlog) 
     31!>       - config namelist (namcfg) 
     32!>       - coarse grid namelist (namcrs) 
     33!>       - fine grid namelist (namfin) 
     34!>       - variable namelist (namvar) 
     35!>       - nesting namelist (namnst) 
     36!>       - output namelist (namout) 
     37!>     
     38!>    @note  
     39!>       All namelists have to be in file create_bathy.nam, however variables of 
     40!>       those namelists are all optional. 
     41!> 
     42!>    * _logger namelist (namlog)_:<br/> 
     43!>       - cn_logfile   : log filename 
     44!>       - cn_verbosity : verbosity ('trace','debug','info', 
     45!> 'warning','error','fatal','none') 
     46!>       - in_maxerror  : maximum number of error allowed 
     47!> 
     48!>    * _config namelist (namcfg)_:<br/> 
     49!>       - cn_varcfg : variable configuration file  
     50!> (see ./SIREN/cfg/variable.cfg) 
     51!> 
     52!>    * _coarse grid namelist (namcrs)_:<br/> 
     53!>       - cn_coord0 : coordinate file 
     54!>       - in_perio0 : NEMO periodicity index (see Model Boundary Condition in 
     55!> [NEMO documentation](http://www.nemo-ocean.eu/About-NEMO/Reference-manuals)) 
     56!> 
     57!>    * _fine grid namelist (namfin)_:<br/> 
     58!>       - cn_coord1 : coordinate file 
     59!>       - in_perio1 : periodicity index 
     60!>       - ln_fillclosed : fill closed sea or not (default is .TRUE.) 
     61!> 
     62!>    * _variable namelist (namvar)_:<br/> 
     63!>       - cn_varinfo : list of variable and extra information about request(s)  
     64!>       to be used.<br/> 
     65!>          each elements of *cn_varinfo* is a string character 
     66!>          (separated by ',').<br/> 
     67!>          it is composed of the variable name follow by ':',  
     68!>          then request(s) to be used on this variable.<br/>  
     69!>          request could be: 
     70!>             - int = interpolation method 
     71!>             - ext = extrapolation method 
     72!>             - flt = filter method 
     73!>             - min = minimum value 
     74!>             - max = maximum value 
     75!>             - unt = new units 
     76!>             - unf = unit scale factor (linked to new units) 
     77!> 
     78!>                requests must be separated by ';'.<br/> 
     79!>                order of requests does not matter.<br/> 
     80!> 
     81!>          informations about available method could be find in @ref interp, 
     82!>          @ref extrap and @ref filter modules.<br/> 
     83!>          Example: 'Bathymetry: flt=2*hamming(2,3); min=0' 
     84!>          @note  
     85!>             If you do not specify a method which is required,  
     86!>             default one is apply. 
     87!>          @warning  
     88!>             variable name must be __Bathymetry__ here. 
     89!>       - cn_varfile : list of variable, and corresponding file.<br/>  
     90!>          *cn_varfile* is the path and filename of the file where find 
     91!>          variable. 
     92!>          @note  
     93!>             *cn_varfile* could be a matrix of value, if you want to filled 
     94!>             manually variable value.<br/> 
     95!>             the variable array of value is split into equal subdomain.<br/> 
     96!>             Each subdomain is filled with the corresponding value  
     97!>             of the matrix.<br/>           
     98!>             separators used to defined matrix are: 
     99!>                - ',' for line 
     100!>                - '/' for row 
     101!>                Example:<br/> 
     102!>                   3,2,3/1,4,5  =>  @f$ \left( \begin{array}{ccc} 
     103!>                                         3 & 2 & 3 \\ 
     104!>                                         1 & 4 & 5 \end{array} \right) @f$ 
     105!> 
     106!>          Examples:  
     107!>             - 'Bathymetry:gridT.nc' 
     108!>             - 'Bathymetry:5000,5000,5000/5000,3000,5000/5000,5000,5000' 
     109!> 
     110!>    * _nesting namelist (namnst)_:<br/> 
     111!>       - in_rhoi  : refinement factor in i-direction 
     112!>       - in_rhoj  : refinement factor in j-direction 
     113!>       @note  
     114!>          coarse grid indices will be deduced from fine grid 
     115!>          coordinate file. 
     116!> 
     117!>    * _output namelist (namout)_:<br/> 
     118!>       - cn_fileout : output bathymetry file 
     119!> 
     120!> @author J.Paul 
    18121! REVISION HISTORY: 
    19 !> @date Nov, 2013 - Initial Version 
     122!> @date November, 2013 - Initial Version 
     123!> @date Sepember, 2014  
     124!> - add header for user 
     125!> - Bug fix, compute offset depending of grid point 
     126!> @date June, 2015 
     127!> - extrapolate all land points. 
     128!> - allow to change unit. 
    20129! 
     130!> @todo 
     131!> - use create_bathy_check_depth as in create_boundary 
     132!> - use create_bathy_check_time  as in create_boundary 
     133!> - check tl_multi is not empty 
     134!> 
    21135!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt) 
    22 !> 
    23 !> @todo 
    24 !> - add attributes indices and refinement in output file 
    25136!---------------------------------------------------------------------- 
    26 !> @code 
    27137PROGRAM create_bathy 
    28138 
    29 !   USE netcdf                          ! nf90 library 
    30139   USE global                          ! global variable 
    31140   USE kind                            ! F90 kind parameter 
     
    39148   USE multi                           ! multi file manager 
    40149   USE iom                             ! I/O manager 
    41    USE dom                             ! domain manager 
    42150   USE grid                            ! grid manager 
    43151   USE extrap                          ! extrapolation manager 
     
    45153   USE filter                          ! filter manager 
    46154   USE mpp                             ! MPP manager 
     155   USE dom                             ! domain manager 
    47156   USE iom_mpp                         ! MPP I/O manager 
     157   USE iom_dom                         ! DOM I/O manager 
    48158 
    49159   IMPLICIT NONE 
     
    57167   INTEGER(i4)                                        :: il_status 
    58168   INTEGER(i4)                                        :: il_fileid 
     169   INTEGER(i4)                                        :: il_varid 
    59170   INTEGER(i4)                                        :: il_attid 
    60    INTEGER(i4)                                        :: il_imin 
    61    INTEGER(i4)                                        :: il_imax 
    62    INTEGER(i4)                                        :: il_jmin 
    63    INTEGER(i4)                                        :: il_jmax 
     171   INTEGER(i4)                                        :: il_imin0 
     172   INTEGER(i4)                                        :: il_imax0 
     173   INTEGER(i4)                                        :: il_jmin0 
     174   INTEGER(i4)                                        :: il_jmax0 
    64175   INTEGER(i4)      , DIMENSION(ip_maxdim)            :: il_rho 
    65176   INTEGER(i4)      , DIMENSION(2,2)                  :: il_offset 
    66    INTEGER(i4)      , DIMENSION(2,2,2)                :: il_ind 
     177   INTEGER(i4)      , DIMENSION(2,2                :: il_ind 
    67178   INTEGER(i4)      , DIMENSION(:,:)    , ALLOCATABLE :: il_mask 
    68179 
    69180   LOGICAL                                            :: ll_exist 
    70181 
    71    TYPE(TFILE)                                        :: tl_coord0 
    72    TYPE(TFILE)                                        :: tl_coord1 
    73    TYPE(TFILE)                                        :: tl_file 
     182   TYPE(TMPP)                                         :: tl_coord0 
     183   TYPE(TMPP)                                         :: tl_coord1 
     184   TYPE(TMPP)                                         :: tl_mpp 
    74185   TYPE(TFILE)                                        :: tl_fileout 
    75186 
     
    88199   TYPE(TMULTI)                                       :: tl_multi 
    89200 
     201   REAL(dp)                                           :: dl_minbat 
     202 
    90203   ! loop indices 
    91204   INTEGER(i4) :: ji 
     
    94207 
    95208   ! namelist variable 
     209   ! namlog 
    96210   CHARACTER(LEN=lc) :: cn_logfile = 'create_bathy.log'  
    97211   CHARACTER(LEN=lc) :: cn_verbosity = 'warning'  
    98  
     212   INTEGER(i4)       :: in_maxerror = 5 
     213 
     214   ! namcfg 
    99215   CHARACTER(LEN=lc) :: cn_varcfg = 'variable.cfg'  
    100216 
     217   ! namcrs 
    101218   CHARACTER(LEN=lc) :: cn_coord0 = ''  
    102219   INTEGER(i4)       :: in_perio0 = -1 
    103220 
     221   ! namfin 
    104222   CHARACTER(LEN=lc) :: cn_coord1 = '' 
    105223   INTEGER(i4)       :: in_perio1 = -1 
    106224   LOGICAL           :: ln_fillclosed = .TRUE. 
    107225 
    108    CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varinfo = '' 
    109    CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varfile = '' 
    110  
    111    INTEGER(i4)       :: in_imin0 = 0 
    112    INTEGER(i4)       :: in_imax0 = 0 
    113    INTEGER(i4)       :: in_jmin0 = 0 
    114    INTEGER(i4)       :: in_jmax0 = 0 
     226   ! namvar 
     227   CHARACTER(LEN=lc), DIMENSION(ip_maxvar) :: cn_varinfo = '' 
     228   CHARACTER(LEN=lc), DIMENSION(ip_maxvar) :: cn_varfile = '' 
     229 
     230   ! namnst 
    115231   INTEGER(i4)       :: in_rhoi  = 1 
    116232   INTEGER(i4)       :: in_rhoj  = 1 
    117233 
     234   ! namout 
    118235   CHARACTER(LEN=lc) :: cn_fileout = 'bathy_fine.nc'  
    119236   !------------------------------------------------------------------- 
    120237 
    121    NAMELIST /namlog/ &  !< logger namelist 
    122    &  cn_logfile,    &  !< log file 
    123    &  cn_verbosity      !< log verbosity 
    124  
    125    NAMELIST /namcfg/ &  !< configuration namelist 
    126    &  cn_varcfg         !< variable configuration file 
     238   NAMELIST /namlog/ &   !< logger namelist 
     239   &  cn_logfile,    &   !< log file 
     240   &  cn_verbosity,  &   !< log verbosity 
     241   &  in_maxerror        !< logger maximum error 
     242 
     243   NAMELIST /namcfg/ &   !< configuration namelist 
     244   &  cn_varcfg          !< variable configuration file 
    127245 
    128246   NAMELIST /namcrs/ &   !< coarse grid namelist 
     
    135253   &  ln_fillclosed      !< fill closed sea 
    136254  
    137    NAMELIST /namvar/ &  !< variable namelist 
    138    &  cn_varinfo, &     !< list of variable and interpolation method to be used. (ex: 'votemper:linear','vosaline:cubic' ) 
    139    &  cn_varfile        !< list of variable file 
     255   NAMELIST /namvar/ &   !< variable namelist 
     256   &  cn_varinfo, &      !< list of variable and interpolation method to be used. (ex: 'votemper:linear','vosaline:cubic' ) 
     257   &  cn_varfile         !< list of variable file 
    140258    
    141    NAMELIST /namnst/ &  !< nesting namelist 
    142    &  in_imin0,   &     !< i-direction lower left  point indice  
    143    &  in_imax0,   &     !< i-direction upper right point indice 
    144    &  in_jmin0,   &     !< j-direction lower left  point indice 
    145    &  in_jmax0,   &     !< j-direction upper right point indice 
    146    &  in_rhoi,    &     !< refinement factor in i-direction 
    147    &  in_rhoj           !< refinement factor in j-direction 
    148  
    149    NAMELIST /namout/ &  !< output namlist 
    150    &  cn_fileout       !< fine grid bathymetry file 
     259   NAMELIST /namnst/ &   !< nesting namelist 
     260   &  in_rhoi,    &      !< refinement factor in i-direction 
     261   &  in_rhoj            !< refinement factor in j-direction 
     262 
     263   NAMELIST /namout/ &   !< output namlist 
     264   &  cn_fileout         !< fine grid bathymetry file 
    151265   !------------------------------------------------------------------- 
    152266 
    153    !1- namelist 
    154    !1-1 get namelist 
     267   ! namelist 
     268   ! get namelist 
    155269   il_narg=COMMAND_ARGUMENT_COUNT() !f03 intrinsec 
    156270   IF( il_narg/=1 )THEN 
     
    160274      CALL GET_COMMAND_ARGUMENT(1,cl_namelist) !f03 intrinsec 
    161275   ENDIF 
    162     
    163    !1-2 read namelist 
     276  
     277   ! read namelist 
    164278   INQUIRE(FILE=TRIM(cl_namelist), EXIST=ll_exist) 
    165279   IF( ll_exist )THEN 
    166        
     280  
    167281      il_fileid=fct_getunit() 
    168282 
     
    180294 
    181295      READ( il_fileid, NML = namlog ) 
    182       !1-2-1 define log file 
    183       CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity)) 
     296      ! define log file 
     297      CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity),in_maxerror) 
    184298      CALL logger_header() 
    185299 
    186300      READ( il_fileid, NML = namcfg ) 
    187       !1-2-2 get variable extra information 
     301      ! get variable extra information 
    188302      CALL var_def_extra(TRIM(cn_varcfg)) 
    189303 
     
    191305      READ( il_fileid, NML = namfin ) 
    192306      READ( il_fileid, NML = namvar ) 
    193       !1-2-3 add user change in extra information 
    194       CALL var_chg_extra(cn_varinfo) 
    195       !1-2-4 match variable with file 
     307      ! add user change in extra information 
     308      CALL var_chg_extra( cn_varinfo ) 
     309      ! match variable with file 
    196310      tl_multi=multi_init(cn_varfile) 
    197311       
     
    211325   ENDIF 
    212326 
    213    !2- open files 
     327   CALL multi_print(tl_multi) 
     328 
     329   ! open files 
    214330   IF( cn_coord0 /= '' )THEN 
    215       tl_coord0=file_init(TRIM(cn_coord0),id_perio=in_perio0) 
    216       CALL iom_open(tl_coord0) 
     331      tl_coord0=mpp_init( file_init(TRIM(cn_coord0)), id_perio=in_perio0) 
     332      CALL grid_get_info(tl_coord0) 
    217333   ELSE 
    218334      CALL logger_fatal("CREATE BATHY: no coarse grid coordinate found. "//& 
     
    221337 
    222338   IF( TRIM(cn_coord1) /= '' )THEN 
    223       tl_coord1=file_init(TRIM(cn_coord1),id_perio=in_perio1) 
    224       CALL iom_open(tl_coord1) 
     339      tl_coord1=mpp_init( file_init(TRIM(cn_coord1)),id_perio=in_perio1) 
     340      CALL grid_get_info(tl_coord1) 
    225341   ELSE 
    226342      CALL logger_fatal("CREATE BATHY: no fine grid coordinate found. "//& 
     
    228344   ENDIF 
    229345 
    230    !3- check 
    231    !3-1 check output file do not already exist 
     346   ! check 
     347   ! check output file do not already exist 
    232348   INQUIRE(FILE=TRIM(cn_fileout), EXIST=ll_exist) 
    233349   IF( ll_exist )THEN 
     
    236352   ENDIF 
    237353 
    238    !3-2 check namelist 
    239    !3-2-1 check refinement factor 
     354   ! check namelist 
     355   ! check refinement factor 
    240356   il_rho(:)=1 
    241357   IF( in_rhoi < 1 .OR. in_rhoj < 1 )THEN 
     
    247363   ENDIF 
    248364 
    249    !3-2-2 check domain indices 
    250    IF( in_imin0 < 1 .OR. in_imax0 < 1 .OR. & 
    251    &   in_jmin0 < 1 .OR. in_jmax0 < 1)THEN 
    252       ! compute coarse grid indices around fine grid 
    253       IF( cn_coord0 /= '' )THEN 
    254          il_ind(:,:,:)=grid_get_coarse_index( tl_coord0, tl_coord1, & 
    255          &                                    id_rho=il_rho(:) ) 
    256       ENDIF 
    257  
    258       il_imin=il_ind(1,1,1) ; il_imax=il_ind(1,2,1) 
    259       il_jmin=il_ind(2,1,1) ; il_jmax=il_ind(2,2,1) 
    260  
    261       il_offset(:,:)=il_ind(:,:,2) 
    262    ELSE 
    263       il_imin=in_imin0 ; il_imax=in_imax0 
    264       il_jmin=in_jmin0 ; il_jmax=in_jmax0 
    265  
    266       il_offset(jp_I,:)=FLOOR(REAL(il_rho(jp_I)-1,dp)*0.5) 
    267       il_offset(jp_J,:)=FLOOR(REAL(il_rho(jp_J)-1,dp)*0.5) 
    268    ENDIF 
    269  
    270    !3-2-3 check domain validity 
    271    IF( cn_coord0 /= '' )THEN 
    272       CALL grid_check_dom(tl_coord0, il_imin, il_imax, il_jmin, il_jmax) 
    273    ENDIF 
    274  
    275    !3-2-4 check coincidence between coarse and fine grid 
    276    IF( cn_coord0 /= '' )THEN 
    277       CALL grid_check_coincidence( tl_coord0, tl_coord1, & 
    278       &                            il_imin, il_imax, & 
    279       &                            il_jmin, il_jmax, & 
    280       &                            il_rho(:) ) 
    281    ENDIF 
    282  
    283    IF( .NOT. ASSOCIATED(tl_multi%t_file) )THEN 
    284       CALL logger_error("CREATE BATHY: no file to work on. "//& 
     365   ! check domain indices 
     366   ! compute coarse grid indices around fine grid 
     367   il_ind(:,:)=grid_get_coarse_index( tl_coord0, tl_coord1, & 
     368   &                                  id_rho=il_rho(:) ) 
     369 
     370   il_imin0=il_ind(jp_I,1) ; il_imax0=il_ind(jp_I,2) 
     371   il_jmin0=il_ind(jp_J,1) ; il_jmax0=il_ind(jp_J,2) 
     372 
     373   ! check domain validity 
     374   CALL grid_check_dom(tl_coord0, il_imin0, il_imax0, il_jmin0, il_jmax0) 
     375 
     376   ! check coincidence between coarse and fine grid 
     377   CALL grid_check_coincidence( tl_coord0, tl_coord1, & 
     378   &                            il_imin0, il_imax0, & 
     379   &                            il_jmin0, il_jmax0, & 
     380   &                            il_rho(:) ) 
     381 
     382   IF( .NOT. ASSOCIATED(tl_multi%t_mpp) )THEN 
     383      CALL logger_error("CREATE BATHY: no mpp file to work on. "//& 
    285384      &                 "check cn_varfile in namelist.") 
    286385   ELSE 
     386 
    287387      ALLOCATE( tl_var( tl_multi%i_nvar ) ) 
    288388      jk=0 
    289       DO ji=1,tl_multi%i_nfile 
    290          WRITE(cl_data,'(a,i2.2)') 'data_',jk+1 
    291          IF( .NOT. ASSOCIATED(tl_multi%t_file(ji)%t_var) )THEN 
    292             CALL logger_error("CREATE BATHY: no variable to work on for "//& 
    293             &                 "file"//TRIM(tl_multi%t_file(ji)%c_name)//& 
     389      DO ji=1,tl_multi%i_nmpp 
     390       
     391         WRITE(cl_data,'(a,i2.2)') 'data-',jk+1 
     392         IF( .NOT. ASSOCIATED(tl_multi%t_mpp(ji)%t_proc(1)%t_var) )THEN 
     393 
     394            CALL logger_fatal("CREATE BATHY: no variable to work on for "//& 
     395            &                 "mpp file"//TRIM(tl_multi%t_mpp(ji)%c_name)//& 
    294396            &                 ". check cn_varfile in namelist.") 
    295          ELSEIF( TRIM(tl_multi%t_file(ji)%c_name) == TRIM(cl_data) )THEN 
    296             DO jj=1,tl_multi%t_file(ji)%i_nvar 
     397 
     398         ELSEIF( TRIM(tl_multi%t_mpp(ji)%c_name) == TRIM(cl_data) )THEN 
     399 
     400            !- use input matrix to initialise variable 
     401            DO jj=1,tl_multi%t_mpp(ji)%t_proc(1)%i_nvar 
    297402               jk=jk+1 
    298                tl_tmp=tl_multi%t_file(ji)%t_var(jj) 
    299                !- use input matrix to initialise variable 
     403               tl_tmp=var_copy(tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj)) 
     404             
    300405               tl_var(jk)=create_bathy_matrix(tl_tmp, tl_coord1) 
    301406            ENDDO 
     407            ! clean 
     408            CALL var_clean(tl_tmp) 
     409 
    302410         ELSE 
    303             ! open file 
    304             tl_file=file_init(TRIM(tl_multi%t_file(ji)%c_name)) 
    305             CALL iom_open(tl_file) 
     411 
     412            tl_mpp=mpp_init( file_init(TRIM(tl_multi%t_mpp(ji)%c_name)) ) 
     413            CALL grid_get_info(tl_mpp) 
     414 
     415            ! open mpp file 
     416            CALL iom_mpp_open(tl_mpp) 
    306417 
    307418            ! get or check depth value 
    308             IF( tl_file%i_depthid /= 0 )THEN 
     419            IF( tl_multi%t_mpp(ji)%t_proc(1)%i_depthid /= 0 )THEN 
     420               il_varid=tl_multi%t_mpp(ji)%t_proc(1)%i_depthid 
    309421               IF( ASSOCIATED(tl_depth%d_value) )THEN 
     422                  tl_tmp=iom_mpp_read_var(tl_mpp,il_varid) 
    310423                  IF( ANY( tl_depth%d_value(:,:,:,:) /= & 
    311424                  &        tl_tmp%d_value(:,:,:,:) ) )THEN 
    312425                     CALL logger_fatal("CREATE BATHY: depth value from "//& 
    313                      &  TRIM(tl_multi%t_file(ji)%c_name)//" not conform "//& 
     426                     &  TRIM(tl_multi%t_mpp(ji)%c_name)//" not conform "//& 
    314427                     &  " to those from former file(s).") 
    315428                  ENDIF 
     429                  CALL var_clean(tl_tmp) 
    316430               ELSE 
    317                   tl_depth=iom_read_var(tl_file,tl_file%i_depthid) 
     431                  tl_depth=iom_mpp_read_var(tl_mpp,il_varid) 
    318432               ENDIF 
    319433            ENDIF 
    320434 
    321435            ! get or check time value 
    322             IF( tl_file%i_timeid /= 0 )THEN 
     436            IF( tl_multi%t_mpp(ji)%t_proc(1)%i_timeid /= 0 )THEN 
     437               il_varid=tl_multi%t_mpp(ji)%t_proc(1)%i_timeid 
    323438               IF( ASSOCIATED(tl_time%d_value) )THEN 
     439                  tl_tmp=iom_mpp_read_var(tl_mpp,il_varid) 
    324440                  IF( ANY( tl_time%d_value(:,:,:,:) /= & 
    325441                  &        tl_tmp%d_value(:,:,:,:) ) )THEN 
    326442                     CALL logger_fatal("CREATE BATHY: time value from "//& 
    327                      &  TRIM(tl_multi%t_file(ji)%c_name)//" not conform "//& 
     443                     &  TRIM(tl_multi%t_mpp(ji)%c_name)//" not conform "//& 
    328444                     &  " to those from former file(s).") 
    329445                  ENDIF 
     446                  CALL var_clean(tl_tmp) 
    330447               ELSE 
    331                   tl_time=iom_read_var(tl_file,tl_file%i_timeid) 
     448                  tl_time=iom_mpp_read_var(tl_mpp,il_varid) 
    332449               ENDIF 
    333450            ENDIF 
    334451 
    335             IF( ANY( tl_file%t_dim(1:2)%i_len /= & 
    336             &      tl_coord0%t_dim(1:2)%i_len) )THEN 
    337                DO jj=1,tl_multi%t_file(ji)%i_nvar 
     452            ! close mpp file 
     453            CALL iom_mpp_close(tl_mpp) 
     454 
     455            IF( ANY( tl_mpp%t_dim(1:2)%i_len /= & 
     456            &        tl_coord0%t_dim(1:2)%i_len) )THEN 
     457               !- extract bathymetry from fine grid bathymetry  
     458               DO jj=1,tl_multi%t_mpp(ji)%t_proc(1)%i_nvar 
    338459                  jk=jk+1 
    339                   tl_tmp=tl_multi%t_file(ji)%t_var(jj) 
    340                   !- extract bathymetry from fine grid bathymetry  
    341                   tl_var(jk)=create_bathy_extract( tl_tmp, tl_file, & 
     460                  tl_tmp=var_copy(tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj)) 
     461                
     462                  tl_var(jk)=create_bathy_extract( tl_tmp, tl_mpp, & 
    342463                  &                                tl_coord1 ) 
    343464               ENDDO 
     465               ! clean 
     466               CALL var_clean(tl_tmp) 
    344467            ELSE 
    345                DO jj=1,tl_multi%t_file(ji)%i_nvar 
     468               !- get bathymetry from coarse grid bathymetry  
     469               DO jj=1,tl_multi%t_mpp(ji)%t_proc(1)%i_nvar 
    346470                  jk=jk+1 
    347                   tl_tmp=tl_multi%t_file(ji)%t_var(jj) 
    348                   !- get bathymetry from coarse grid bathymetry  
    349                   tl_var(jk)=create_bathy_get_var( tl_tmp, tl_file,  & 
    350                   &                                il_imin, il_jmin, & 
    351                   &                                il_imax, il_jmax, & 
    352                   &                                il_offset(:,:),   & 
     471                  tl_tmp=var_copy(tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj)) 
     472 
     473                  il_offset(:,:)= grid_get_fine_offset(tl_coord0,    & 
     474                  &                                    il_imin0, il_jmin0, & 
     475                  &                                    il_imax0, il_jmax0, & 
     476                  &                                    tl_coord1,          & 
     477                  &                                    il_rho(:),          & 
     478                  &                                    TRIM(tl_tmp%c_point) ) 
     479 
     480                  tl_var(jk)=create_bathy_get_var( tl_tmp, tl_mpp,     & 
     481                  &                                il_imin0, il_jmin0, & 
     482                  &                                il_imax0, il_jmax0, & 
     483                  &                                il_offset(:,:),  & 
    353484                  &                                il_rho(:) ) 
    354485               ENDDO 
     486               ! clean 
     487               CALL var_clean(tl_tmp) 
    355488            ENDIF 
    356489 
    357             ! close file 
    358             CALL iom_close(tl_file) 
    359490            ! clean structure 
    360             CALL file_clean(tl_file) 
     491            CALL mpp_clean(tl_mpp) 
     492 
    361493         ENDIF 
    362494      ENDDO 
    363495   ENDIF 
    364496 
     497   ! use additional request 
    365498   DO jk=1,tl_multi%i_nvar 
    366          !6- forced min and max value 
     499 
     500         ! change unit and apply factor 
     501         CALL var_chg_unit(tl_var(jk)) 
     502 
     503         ! forced min and max value 
    367504         CALL var_limit_value(tl_var(jk)) 
    368505 
    369          !7- fill closed sea 
    370          IF( TRIM(tl_var(jk)%c_stdname) == 'bathymetry' .AND. & 
    371              ln_fillclosed )THEN 
     506         ! fill closed sea 
     507         IF( ln_fillclosed )THEN 
    372508            ALLOCATE( il_mask(tl_var(jk)%t_dim(1)%i_len, & 
    373509            &                 tl_var(jk)%t_dim(2)%i_len) ) 
    374510 
    375             !7-1 split domain in N sea subdomain 
     511            ! split domain in N sea subdomain 
    376512            il_mask(:,:)=grid_split_domain(tl_var(jk)) 
    377513 
    378             !7-2  fill smallest domain 
     514            !  fill smallest domain 
    379515            CALL grid_fill_small_dom( tl_var(jk), il_mask(:,:) ) 
    380516 
     
    382518         ENDIF 
    383519 
    384          !8- filter 
     520         ! filter 
    385521         CALL filter_fill_value(tl_var(jk)) 
    386522 
    387          !9- check bathymetry 
     523         ! check bathymetry 
     524         dl_minbat=MINVAL(tl_var(jk)%d_value(:,:,:,:)) 
    388525         IF( TRIM(tl_var(jk)%c_stdname) == 'bathymetry' .AND. & 
    389          &   MINVAL(tl_var(jk)%d_value(:,:,:,:)) <= 0._dp  )THEN 
     526         &   dl_minbat <= 0._dp  )THEN 
     527            CALL logger_debug("CREATE BATHY: min value "//TRIM(fct_str(dl_minbat))) 
    390528            CALL logger_error("CREATE BATHY: Bathymetry has value <= 0") 
    391529         ENDIF 
     530 
    392531   ENDDO 
    393532 
    394  
    395    !10- create file 
    396    tl_fileout=file_init(TRIM(cn_fileout),id_perio=in_perio1) 
    397  
    398    !10-1 add dimension 
     533   ! create file 
     534   tl_fileout=file_init(TRIM(cn_fileout)) 
     535 
     536   ! add dimension 
    399537   tl_dim(:)=var_max_dim(tl_var(:)) 
    400538 
     
    403541   ENDDO 
    404542 
    405    !10-2 add variables 
     543   ! add variables 
    406544   IF( ALL( tl_dim(1:2)%l_use ) )THEN 
    407545 
     546      ! open mpp files 
     547      CALL iom_mpp_open(tl_coord1) 
     548 
    408549      ! add longitude 
    409       tl_lon=iom_read_var(tl_coord1,'longitude') 
     550      tl_lon=iom_mpp_read_var(tl_coord1,'longitude') 
    410551      CALL file_add_var(tl_fileout, tl_lon) 
    411552      CALL var_clean(tl_lon) 
    412553 
    413554      ! add latitude 
    414       tl_lat=iom_read_var(tl_coord1,'latitude') 
     555      tl_lat=iom_mpp_read_var(tl_coord1,'latitude') 
    415556      CALL file_add_var(tl_fileout, tl_lat) 
    416557      CALL var_clean(tl_lat) 
     558 
     559      ! close mpp files 
     560      CALL iom_mpp_close(tl_coord1) 
    417561 
    418562   ENDIF 
     
    431575 
    432576   ! add other variables 
    433    DO jk=1,tl_multi%i_nvar 
     577   DO jk=tl_multi%i_nvar,1,-1 
    434578      CALL file_add_var(tl_fileout, tl_var(jk)) 
    435579      CALL var_clean(tl_var(jk)) 
    436580   ENDDO 
    437  
    438    !10-3 add some attribute 
     581   DEALLOCATE(tl_var) 
     582 
     583   ! add some attribute 
    439584   tl_att=att_init("Created_by","SIREN create_bathy") 
    440585   CALL file_add_att(tl_fileout, tl_att) 
     
    447592   il_attid=0 
    448593   IF( ASSOCIATED(tl_fileout%t_att) )THEN 
    449       il_attid=att_get_id(tl_fileout%t_att(:),'periodicity') 
     594      il_attid=att_get_index(tl_fileout%t_att(:),'periodicity') 
    450595   ENDIF 
    451596   IF( tl_coord1%i_perio >= 0 .AND. il_attid == 0 )THEN 
     
    454599   ENDIF 
    455600 
     601   ! add attribute east west overlap 
    456602   il_attid=0 
    457603   IF( ASSOCIATED(tl_fileout%t_att) )THEN 
    458       il_attid=att_get_id(tl_fileout%t_att(:),'ew_overlap') 
     604      il_attid=att_get_index(tl_fileout%t_att(:),'ew_overlap') 
    459605   ENDIF 
    460606   IF( tl_coord1%i_ew >= 0 .AND. il_attid == 0 )THEN 
     
    462608      CALL file_add_att(tl_fileout,tl_att) 
    463609   ENDIF 
    464  
    465    !10-4 create file 
     610    
     611   ! create file 
    466612   CALL iom_create(tl_fileout) 
    467613 
    468    !10-5 write file 
     614   ! write file 
    469615   CALL iom_write_file(tl_fileout) 
    470616 
    471    !10-6 close file 
     617   ! close file 
    472618   CALL iom_close(tl_fileout) 
    473    IF( cn_coord0 /= '' ) CALL iom_close(tl_coord0) 
    474  
    475    !11- clean 
    476    DEALLOCATE(tl_var) 
     619 
     620   ! clean 
     621   CALL att_clean(tl_att) 
    477622 
    478623   CALL file_clean(tl_fileout) 
    479    CALL file_clean(tl_coord1) 
    480    CALL file_clean(tl_coord0) 
     624   CALL mpp_clean(tl_coord1) 
     625   CALL mpp_clean(tl_coord0) 
    481626 
    482627   ! close log file 
     
    484629   CALL logger_close() 
    485630 
    486 !> @endcode 
    487631CONTAINS 
    488632   !------------------------------------------------------------------- 
    489633   !> @brief 
    490    !> This subroutine 
     634   !> This function create variable, filled with matrix value 
    491635   !>  
    492636   !> @details  
     637   !> A variable is create with the same name that the input variable,  
     638   !> and with dimension of the coordinate file.<br/>  
     639   !> Then the variable array of value is split into equal subdomain. 
     640   !> Each subdomain is filled with the corresponding value of the matrix. 
    493641   !> 
    494642   !> @author J.Paul 
    495    !> - Nov, 2013- Initial Version 
     643   !> @date November, 2013 - Initial Version 
    496644   !> 
    497    !> @param[in]  
     645   !> @param[in] td_var    variable structure  
     646   !> @param[in] td_coord  coordinate file structure 
     647   !> @return variable structure 
    498648   !------------------------------------------------------------------- 
    499    !> @code 
    500649   FUNCTION create_bathy_matrix(td_var, td_coord) 
    501650      IMPLICIT NONE 
    502651      ! Argument 
    503       TYPE(TVAR) , INTENT(IN) :: td_var 
    504       TYPE(TFILE), INTENT(IN) :: td_coord 
     652      TYPE(TVAR), INTENT(IN) :: td_var 
     653      TYPE(TMPP), INTENT(IN) :: td_coord 
    505654 
    506655      ! function 
     
    508657 
    509658      ! local variable 
    510       INTEGER(i4)                                        :: il_ighost 
    511       INTEGER(i4)                                        :: il_jghost 
    512       INTEGER(i4)      , DIMENSION(2)                    :: il_xghost 
     659      INTEGER(i4)      , DIMENSION(2,2)                  :: il_xghost 
    513660      INTEGER(i4)      , DIMENSION(3)                    :: il_dim 
    514661      INTEGER(i4)      , DIMENSION(3)                    :: il_size 
     
    522669 
    523670      TYPE(TVAR)                                         :: tl_lon 
    524       TYPE(TVAR)                                         :: tl_lat 
    525       TYPE(TVAR)                                         :: tl_var 
    526671      TYPE(TDIM)       , DIMENSION(ip_maxdim)            :: tl_dim 
     672 
     673      TYPE(TMPP)                                         :: tl_coord 
    527674 
    528675      ! loop indices 
     
    532679      !---------------------------------------------------------------- 
    533680 
    534       !1- read output grid 
    535       tl_lon=iom_read_var(td_coord,'longitude') 
    536       tl_lat=iom_read_var(td_coord,'latitude') 
    537  
    538       !2- look for ghost cell 
    539       il_xghost(:)=grid_get_ghost( tl_lon, tl_lat ) 
    540  
    541       il_ighost=il_xghost(1)*ig_ghost 
    542       il_jghost=il_xghost(2)*ig_ghost 
    543        
    544       !3- write value on grid 
    545       !3-1 get matrix dimension 
     681      ! copy structure 
     682      tl_coord=mpp_copy(td_coord) 
     683 
     684      ! use only edge processor 
     685      CALL mpp_get_contour(tl_coord) 
     686 
     687      ! open useful processor 
     688      CALL iom_mpp_open(tl_coord) 
     689 
     690      ! read output grid 
     691      tl_lon=iom_mpp_read_var(tl_coord,'longitude') 
     692 
     693      ! look for ghost cell 
     694      il_xghost(:,:)=grid_get_ghost( tl_coord ) 
     695 
     696      ! close processor 
     697      CALL iom_mpp_close(tl_coord) 
     698      ! clean 
     699      CALL mpp_clean(tl_coord) 
     700 
     701      ! remove ghost cell 
     702      CALL grid_del_ghost(tl_lon, il_xghost(:,:)) 
     703 
     704      ! write value on grid 
     705      ! get matrix dimension 
    546706      il_dim(:)=td_var%t_dim(1:3)%i_len 
    547       !3-2 output dimension 
    548       tl_dim(:)=tl_lon%t_dim(:) 
    549  
    550       ! remove ghost cell 
    551       tl_dim(1)%i_len=tl_dim(1)%i_len - 2*il_xghost(1)*ig_ghost 
    552       tl_dim(2)%i_len=tl_dim(2)%i_len - 2*il_xghost(2)*ig_ghost 
    553  
    554       !3-3 split output domain in N subdomain depending of matrix dimension  
     707      ! output dimension 
     708      tl_dim(:)=dim_copy(tl_lon%t_dim(:)) 
     709      ! clean 
     710      CALL var_clean(tl_lon) 
     711 
     712      ! split output domain in N subdomain depending of matrix dimension  
    555713      il_size(:) = tl_dim(1:3)%i_len / il_dim(:) 
    556714      il_rest(:) = MOD(tl_dim(1:3)%i_len, il_dim(:)) 
     
    563721      ! add rest to last cell 
    564722      il_ishape(il_dim(1)+1)=il_ishape(il_dim(1)+1)+il_rest(1) 
    565        
    566723 
    567724      ALLOCATE( il_jshape(il_dim(2)+1) ) 
     
    581738      il_kshape(il_dim(3)+1)=il_kshape(il_dim(3)+1)+il_rest(3) 
    582739 
    583       !3-3 write ouput table of value  
     740      ! write ouput array of value  
    584741      ALLOCATE(dl_value( tl_dim(1)%i_len, & 
    585742      &                  tl_dim(2)%i_len, & 
     
    602759      ENDDO 
    603760 
    604       !3-4 initialise variable with value 
    605       tl_var=var_init(TRIM(td_var%c_name),dl_value(:,:,:,:)) 
     761      ! initialise variable with value 
     762      create_bathy_matrix=var_init(TRIM(td_var%c_name),dl_value(:,:,:,:)) 
    606763 
    607764      DEALLOCATE(dl_value) 
    608765 
    609       !4- add ghost cell 
    610       CALL grid_add_ghost(tl_var,il_ighost,il_jghost) 
    611  
    612       !5- save result 
    613       create_bathy_matrix=tl_var 
     766      ! add ghost cell 
     767      CALL grid_add_ghost(create_bathy_matrix, il_xghost(:,:)) 
     768 
     769      ! clean 
     770      CALL dim_clean(tl_dim(:)) 
    614771 
    615772   END FUNCTION create_bathy_matrix 
    616    !> @endcode 
    617773   !------------------------------------------------------------------- 
    618774   !> @brief 
    619    !> This subroutine 
     775   !> This function extract variable from file over coordinate domain and 
     776   !> return variable structure 
    620777   !>  
    621    !> @details  
     778   !> @author J.Paul 
     779   !> @date November, 2013 - Initial Version 
    622780   !> 
    623    !> @author J.Paul 
    624    !> - Nov, 2013- Initial Version 
    625    !> 
    626    !> @param[in]  
     781   !> @param[in] td_var    variable structure  
     782   !> @param[in] td_mpp    mpp file structure 
     783   !> @param[in] td_coord  coordinate file structure 
     784   !> @return variable structure 
    627785   !------------------------------------------------------------------- 
    628    !> @code 
    629    FUNCTION create_bathy_extract(td_var, td_file, & 
     786   FUNCTION create_bathy_extract(td_var, td_mpp, & 
    630787   &                             td_coord) 
    631788      IMPLICIT NONE 
    632789      ! Argument 
    633       TYPE(TVAR) , INTENT(IN) :: td_var   
    634       TYPE(TFILE), INTENT(IN) :: td_file 
    635       TYPE(TFILE), INTENT(IN) :: td_coord 
     790      TYPE(TVAR), INTENT(IN) :: td_var   
     791      TYPE(TMPP), INTENT(IN) :: td_mpp 
     792      TYPE(TMPP), INTENT(IN) :: td_coord 
    636793 
    637794      ! function 
     
    639796 
    640797      ! local variable 
    641       INTEGER(i4), DIMENSION(2,2,2) :: il_ind 
    642  
    643       INTEGER(i4) :: il_pivot 
    644       INTEGER(i4) :: il_perio 
     798      INTEGER(i4), DIMENSION(2,2) :: il_ind 
    645799 
    646800      INTEGER(i4) :: il_imin 
     
    648802      INTEGER(i4) :: il_imax 
    649803      INTEGER(i4) :: il_jmax 
    650  
    651       TYPE(TFILE) :: tl_file 
    652804 
    653805      TYPE(TMPP)  :: tl_mpp 
     
    661813      !---------------------------------------------------------------- 
    662814 
    663       IF( td_file%i_id == 0 )THEN 
    664          CALL logger_error("CREATE BATHY EXTRACT: file "//& 
    665          &  TRIM(td_file%c_name)//" not opened ") 
     815      IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN 
     816         CALL logger_error("CREATE BATHY EXTRACT: no processor associated "//& 
     817         &  "to mpp "//TRIM(td_mpp%c_name)) 
    666818      ELSE 
    667819 
    668820         !init 
    669          tl_file=td_file 
    670  
    671          !1- open file 
    672          CALL iom_open(tl_file) 
    673  
    674          ! get periodicity 
    675          il_pivot=grid_get_pivot(tl_file) 
    676          il_perio=grid_get_perio(tl_file,il_pivot) 
    677  
    678          tl_file%i_perio=il_perio 
    679  
    680          !2- compute file grid indices around coord grid 
    681          il_ind(:,:,:)=grid_get_coarse_index(tl_file, td_coord ) 
    682  
    683          il_imin=il_ind(1,1,1) ; il_imax=il_ind(1,2,1) 
    684          il_jmin=il_ind(2,1,1) ; il_jmax=il_ind(2,2,1) 
    685  
    686          IF( ANY( il_ind(:,:,2) /= 0 ) )THEN 
    687             CALL logger_error("CREATE BATHY EXTRACT: something wrong "//& 
    688             &  " find offset when extracting data") 
    689          ENDIF 
    690          !3- check grid coincidence 
    691          CALL grid_check_coincidence( tl_file, td_coord, & 
     821         tl_mpp=mpp_copy(td_mpp) 
     822 
     823         ! compute file grid indices around coord grid 
     824         il_ind(:,:)=grid_get_coarse_index(tl_mpp, td_coord ) 
     825 
     826         il_imin=il_ind(1,1) ; il_imax=il_ind(1,2) 
     827         il_jmin=il_ind(2,1) ; il_jmax=il_ind(2,2) 
     828 
     829         ! check grid coincidence 
     830         CALL grid_check_coincidence( tl_mpp, td_coord, & 
    692831         &                            il_imin, il_imax, & 
    693832         &                            il_jmin, il_jmax, & 
    694833         &                            (/1, 1, 1/) ) 
    695834 
    696          !4- compute domain 
    697          tl_dom=dom_init(tl_file,         & 
     835         ! compute domain 
     836         tl_dom=dom_init(tl_mpp,           & 
    698837         &               il_imin, il_imax, & 
    699838         &               il_jmin, il_jmax) 
    700839 
    701          ! close file 
    702          CALL iom_close(tl_file) 
    703  
    704          !5- read bathymetry on domain (ugly way to do it, have to work on it) 
    705          !5-1 init mpp structure 
    706          tl_mpp=mpp_init(tl_file) 
    707  
    708          CALL file_clean(tl_file) 
    709  
    710          !5-2 get processor to be used 
    711          CALL mpp_get_use( tl_mpp, tl_dom ) 
    712  
    713          !5-3 open mpp files 
    714          CALL iom_mpp_open(tl_mpp) 
    715  
    716          !5-4 read variable on domain 
    717          tl_var=iom_mpp_read_var(tl_mpp,TRIM(td_var%c_name),td_dom=tl_dom) 
    718  
    719          !5-5 close mpp file 
    720          CALL iom_mpp_close(tl_mpp) 
    721  
    722          !6- add ghost cell 
    723          CALL grid_add_ghost(tl_var,tl_dom%i_ighost,tl_dom%i_jghost) 
    724  
    725          !7- check result 
     840         ! open mpp files over domain 
     841         CALL iom_dom_open(tl_mpp, tl_dom) 
     842 
     843         ! read variable on domain 
     844         tl_var=iom_dom_read_var(tl_mpp,TRIM(td_var%c_name),tl_dom) 
     845 
     846         ! close mpp file 
     847         CALL iom_dom_close(tl_mpp) 
     848 
     849         ! add ghost cell 
     850         CALL grid_add_ghost(tl_var,tl_dom%i_ghost(:,:)) 
     851 
     852         ! check result 
    726853         IF( ANY( tl_var%t_dim(:)%l_use .AND. & 
    727854         &        tl_var%t_dim(:)%i_len /= td_coord%t_dim(:)%i_len) )THEN 
     
    743870         ENDIF 
    744871 
    745          !8- add attribute to variable 
     872         ! add attribute to variable 
    746873         tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name))) 
    747874         CALL var_move_att(tl_var, tl_att)          
    748875 
    749          tl_att=att_init('src_i-indices',(/tl_dom%i_imin, tl_dom%i_imax/)) 
     876         tl_att=att_init('src_i_indices',(/tl_dom%i_imin, tl_dom%i_imax/)) 
    750877         CALL var_move_att(tl_var, tl_att) 
    751878 
    752          tl_att=att_init('src_j-indices',(/tl_dom%i_jmin, tl_dom%i_jmax/)) 
     879         tl_att=att_init('src_j_indices',(/tl_dom%i_jmin, tl_dom%i_jmax/)) 
    753880         CALL var_move_att(tl_var, tl_att) 
    754881 
    755          !9- save result 
    756          create_bathy_extract=tl_var 
     882         ! save result 
     883         create_bathy_extract=var_copy(tl_var) 
    757884 
    758885         ! clean structure 
     886         CALL att_clean(tl_att) 
    759887         CALL var_clean(tl_var) 
    760888         CALL mpp_clean(tl_mpp) 
     
    762890 
    763891   END FUNCTION create_bathy_extract 
    764    !> @endcode 
    765892   !------------------------------------------------------------------- 
    766893   !> @brief 
    767    !> This subroutine 
     894   !> This function get coarse grid variable, interpolate variable, and return 
     895   !> variable structure over fine grid 
    768896   !>  
    769    !> @details  
     897   !> @author J.Paul 
     898   !> @date November, 2013 - Initial Version 
    770899   !> 
    771    !> @author J.Paul 
    772    !> - Nov, 2013- Initial Version 
    773    !> 
    774    !> @param[in] td_var : variable structure 
    775    !> @param[in] td_file : file structure 
    776    !> @param[in] id_imin : i-direction lower left  corner indice  
    777    !> @param[in] id_imax : i-direction upper right corner indice  
    778    !> @param[in] id_jmin : j-direction lower left  corner indice 
    779    !> @param[in] id_jmax : j-direction upper right corner indice  
    780    !> @param[in] id_rho  : table of refinement factor 
     900   !> @param[in] td_var    variable structure 
     901   !> @param[in] td_mpp    mpp file structure 
     902   !> @param[in] id_imin   i-direction lower left  corner indice  
     903   !> @param[in] id_imax   i-direction upper right corner indice  
     904   !> @param[in] id_jmin   j-direction lower left  corner indice 
     905   !> @param[in] id_jmax   j-direction upper right corner indice  
     906   !> @param[in] id_offset offset between fine grid and coarse grid 
     907   !> @param[in] id_rho    array of refinement factor 
     908   !> @return variable structure 
    781909   !------------------------------------------------------------------- 
    782    !> @code 
    783    FUNCTION create_bathy_get_var(td_var, td_file,  & 
     910   FUNCTION create_bathy_get_var(td_var, td_mpp,   & 
    784911            &                    id_imin, id_jmin, & 
    785912            &                    id_imax, id_jmax, & 
     
    788915      IMPLICIT NONE 
    789916      ! Argument 
    790       TYPE(TVAR) , INTENT(IN) :: td_var   
    791       TYPE(TFILE), INTENT(IN) :: td_file  
    792       INTEGER(i4), INTENT(IN) :: id_imin 
    793       INTEGER(i4), INTENT(IN) :: id_imax 
    794       INTEGER(i4), INTENT(IN) :: id_jmin 
    795       INTEGER(i4), INTENT(IN) :: id_jmax 
     917      TYPE(TVAR)                 , INTENT(IN) :: td_var   
     918      TYPE(TMPP)                 , INTENT(IN) :: td_mpp  
     919      INTEGER(i4)                , INTENT(IN) :: id_imin 
     920      INTEGER(i4)                , INTENT(IN) :: id_imax 
     921      INTEGER(i4)                , INTENT(IN) :: id_jmin 
     922      INTEGER(i4)                , INTENT(IN) :: id_jmax 
    796923      INTEGER(i4), DIMENSION(:,:), INTENT(IN) :: id_offset 
    797924      INTEGER(i4), DIMENSION(:)  , INTENT(IN) :: id_rho 
     
    801928 
    802929      ! local variable 
    803       INTEGER(i4) :: il_pivot 
    804       INTEGER(i4) :: il_perio 
    805  
    806       TYPE(TFILE) :: tl_file 
    807  
    808930      TYPE(TMPP)  :: tl_mpp 
    809  
    810931      TYPE(TATT)  :: tl_att 
    811  
    812932      TYPE(TVAR)  :: tl_var 
    813        
    814933      TYPE(TDOM)  :: tl_dom 
     934 
     935      INTEGER(i4) :: il_size 
     936      INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_rho 
    815937 
    816938      ! loop indices 
    817939      !---------------------------------------------------------------- 
    818940      IF( ANY(SHAPE(id_offset(:,:)) /= 2) )THEN 
    819          CALL logger_error("CREATE BATHY GET VAR: invalid dimensio of "//& 
    820          &                 "offset table") 
     941         CALL logger_error("CREATE BATHY GET VAR: invalid dimension of "//& 
     942         &                 "offset array") 
    821943      ENDIF 
    822944 
    823       !init 
    824       tl_file=td_file 
    825  
    826       !1- open file 
    827       CALL iom_open(tl_file) 
    828  
    829       ! get periodicity 
    830       il_pivot=grid_get_pivot(tl_file) 
    831       il_perio=grid_get_perio(tl_file,il_pivot) 
    832  
    833       tl_file%i_perio=il_perio 
    834  
    835       !2- compute domain 
    836       tl_dom=dom_init(tl_file,          & 
     945      ! copy structure 
     946      tl_mpp=mpp_copy(td_mpp) 
     947 
     948      !- compute domain 
     949      tl_dom=dom_init(tl_mpp,           & 
    837950      &               id_imin, id_imax, & 
    838951      &               id_jmin, id_jmax) 
    839952 
    840       CALL dom_print(tl_dom) 
    841       print *,'id_offset ',id_offset(:,:) 
    842       !3- close file 
    843       CALL iom_close(tl_file)       
    844  
    845       !4- add extra band (if possible) to compute interpolation 
     953      !- add extra band (if possible) to compute interpolation 
    846954      CALL dom_add_extra(tl_dom) 
    847955 
    848       !5- read bathymetry on domain (ugly way to do it, have to work on it) 
    849       !5-1 init mpp sturcutre 
    850       tl_mpp=mpp_init(tl_file) 
    851  
    852       CALL file_clean(tl_file) 
    853  
    854       !5-2 get processor to be used 
    855       CALL mpp_get_use( tl_mpp, tl_dom ) 
    856  
    857       !5-3 open mpp files 
    858       CALL iom_mpp_open(tl_mpp) 
    859  
    860       !5-4 read variable value on domain 
    861       tl_var=iom_mpp_read_var(tl_mpp,TRIM(td_var%c_name),td_dom=tl_dom) 
    862  
    863       !5-5 close mpp files 
    864       CALL iom_mpp_close(tl_mpp)       
    865  
    866       !6- interpolate variable 
    867       CALL create_bathy_interp(tl_var, id_rho(:), id_offset(:,:)) 
    868  
    869       !7- remove extraband added to domain 
    870       CALL dom_del_extra( tl_var, tl_dom, id_rho(:) ) 
    871  
    872       !8- add ghost cell 
    873       CALL grid_add_ghost(tl_var,tl_dom%i_ighost,tl_dom%i_jghost) 
     956      !- open mpp files over domain 
     957      CALL iom_dom_open(tl_mpp, tl_dom) 
     958 
     959      !- read variable value on domain 
     960      tl_var=iom_dom_read_var(tl_mpp,TRIM(td_var%c_name),tl_dom) 
     961 
     962      !- close mpp files 
     963      CALL iom_dom_close(tl_mpp) 
     964 
     965      il_size=SIZE(id_rho(:)) 
     966      ALLOCATE( il_rho(il_size) ) 
     967      il_rho(:)=id_rho(:) 
     968       
     969      !- interpolate variable 
     970      CALL create_bathy_interp(tl_var, il_rho(:), id_offset(:,:)) 
     971 
     972      !- remove extraband added to domain 
     973      CALL dom_del_extra( tl_var, tl_dom, il_rho(:) ) 
     974 
     975      !- add ghost cell 
     976      CALL grid_add_ghost(tl_var,tl_dom%i_ghost(:,:)) 
    874977  
    875       !9- add attribute to variable 
     978      !- add attribute to variable 
    876979      tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name))) 
    877980      CALL var_move_att(tl_var, tl_att) 
    878981 
    879       tl_att=att_init('src_i-indices',(/tl_dom%i_imin, tl_dom%i_imax/)) 
     982      tl_att=att_init('src_i_indices',(/tl_dom%i_imin, tl_dom%i_imax/)) 
    880983      CALL var_move_att(tl_var, tl_att) 
    881984 
    882       tl_att=att_init('src_j-indices',(/tl_dom%i_jmin, tl_dom%i_jmax/)) 
     985      tl_att=att_init('src_j_indices',(/tl_dom%i_jmin, tl_dom%i_jmax/)) 
    883986      CALL var_move_att(tl_var, tl_att) 
    884987 
    885       !10- save result 
    886       create_bathy_get_var=tl_var 
    887  
    888       !11- clean structure 
     988      IF( .NOT. ALL(id_rho(:)==1) )THEN 
     989         tl_att=att_init("refinment_factor",(/id_rho(jp_I),id_rho(jp_J)/)) 
     990         CALL var_move_att(tl_var, tl_att) 
     991      ENDIF 
     992 
     993      DEALLOCATE( il_rho ) 
     994 
     995      !- save result 
     996      create_bathy_get_var=var_copy(tl_var) 
     997 
     998      !- clean structure 
     999      CALL att_clean(tl_att) 
     1000      CALL var_clean(tl_var) 
    8891001      CALL mpp_clean(tl_mpp) 
    8901002  
    8911003   END FUNCTION create_bathy_get_var 
    892    !> @endcode 
    8931004   !------------------------------------------------------------------- 
    8941005   !> @brief 
    895    !> This subroutine 
     1006   !> This subroutine interpolate variable 
    8961007   !>  
    897    !> @details  
     1008   !> @author J.Paul 
     1009   !> @date November, 2013 - Initial Version 
    8981010   !> 
    899    !> @author J.Paul 
    900    !> - Nov, 2013- Initial Version 
    901    !> 
    902    !> @param[in]  
    903    !> @todo  
     1011   !> @param[inout] td_var variable structure  
     1012   !> @param[in] id_rho    array of refinment factor 
     1013   !> @param[in] id_offset array of offset between fine and coarse grid 
     1014   !> @param[in] id_iext   i-direction size of extra bands (default=im_minext) 
     1015   !> @param[in] id_jext   j-direction size of extra bands (default=im_minext) 
    9041016   !------------------------------------------------------------------- 
    905    !> @code 
    9061017   SUBROUTINE create_bathy_interp( td_var,         & 
    9071018   &                               id_rho,          & 
     
    9191030 
    9201031      ! local variable 
    921       TYPE(TVAR)  :: tl_var 
    9221032      TYPE(TVAR)  :: tl_mask 
    9231033 
     
    9291039      ! loop indices 
    9301040      !---------------------------------------------------------------- 
    931  
    932       ! copy variable 
    933       tl_var=td_var 
    9341041 
    9351042      !WARNING: two extrabands are required for cubic interpolation 
     
    9521059      ENDIF 
    9531060 
    954       !1- work on mask 
    955       !1-1 create mask 
    956       ALLOCATE(bl_mask(tl_var%t_dim(1)%i_len, & 
    957       &                tl_var%t_dim(2)%i_len, & 
    958       &                tl_var%t_dim(3)%i_len, & 
    959       &                tl_var%t_dim(4)%i_len) ) 
     1061      ! work on mask 
     1062      ! create mask 
     1063      ALLOCATE(bl_mask(td_var%t_dim(1)%i_len, & 
     1064      &                td_var%t_dim(2)%i_len, & 
     1065      &                td_var%t_dim(3)%i_len, & 
     1066      &                td_var%t_dim(4)%i_len) ) 
    9601067 
    9611068      bl_mask(:,:,:,:)=1 
    962       WHERE(tl_var%d_value(:,:,:,:)==tl_var%d_fill) bl_mask(:,:,:,:)=0       
    963  
    964       SELECT CASE(TRIM(tl_var%c_point)) 
     1069      WHERE(td_var%d_value(:,:,:,:)==td_var%d_fill) bl_mask(:,:,:,:)=0       
     1070 
     1071      SELECT CASE(TRIM(td_var%c_point)) 
    9651072      CASE DEFAULT ! 'T' 
    966          tl_mask=var_init('tmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:)) 
    967       CASE('U') 
    968          tl_mask=var_init('umask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:)) 
    969       CASE('V') 
    970          tl_mask=var_init('vmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:)) 
    971       CASE('F') 
    972          tl_mask=var_init('fmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:)) 
     1073         tl_mask=var_init('tmask', bl_mask(:,:,:,:), td_dim=td_var%t_dim(:), & 
     1074         &                id_ew=td_var%i_ew ) 
     1075      CASE('U','V','F') 
     1076         CALL logger_fatal("CREATE BATHY INTERP: can not computed "//& 
     1077         &                 "interpolation on "//TRIM(td_var%c_point)//& 
     1078         &                 " grid point (variable "//TRIM(td_var%c_name)//& 
     1079         &                 "). check namelist.") 
    9731080      END SELECT 
    9741081 
    9751082      DEALLOCATE(bl_mask) 
    9761083 
    977       !1-2 interpolate mask 
     1084      ! interpolate mask 
    9781085      CALL interp_fill_value( tl_mask, id_rho(:), & 
    9791086      &                       id_offset=id_offset(:,:) ) 
    9801087 
    981       !2- work on variable 
    982       !2-0 add extraband 
    983       CALL extrap_add_extrabands(tl_var, il_iext, il_jext) 
    984  
    985       !2-1 extrapolate variable 
    986       CALL extrap_fill_value( tl_var, id_offset=id_offset(:,:), & 
    987       &                               id_rho=id_rho(:),         & 
    988       &                               id_iext=il_iext, id_jext=il_jext ) 
    989  
    990       !2-2 interpolate Bathymetry 
    991       CALL interp_fill_value( tl_var, id_rho(:), & 
     1088      ! work on variable 
     1089      ! add extraband 
     1090      CALL extrap_add_extrabands(td_var, il_iext, il_jext) 
     1091 
     1092      ! extrapolate variable 
     1093      CALL extrap_fill_value( td_var ) 
     1094 
     1095      ! interpolate Bathymetry 
     1096      CALL interp_fill_value( td_var, id_rho(:), & 
    9921097      &                       id_offset=id_offset(:,:) ) 
    9931098 
    994       !2-3 remove extraband 
    995       CALL extrap_del_extrabands(tl_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J)) 
    996  
    997       !2-2-5 keep original mask  
     1099      ! remove extraband 
     1100      CALL extrap_del_extrabands(td_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J)) 
     1101 
     1102      ! keep original mask  
    9981103      WHERE( tl_mask%d_value(:,:,:,:) == 0 ) 
    999          tl_var%d_value(:,:,:,:)=tl_var%d_fill 
     1104         td_var%d_value(:,:,:,:)=td_var%d_fill 
    10001105      END WHERE 
    1001  
    1002       !3- save result 
    1003       td_var=tl_var 
    10041106 
    10051107      ! clean variable structure 
    10061108      CALL var_clean(tl_mask) 
    1007       CALL var_clean(tl_var) 
    10081109 
    10091110   END SUBROUTINE create_bathy_interp 
    1010    !> @endcode 
    10111111END PROGRAM create_bathy 
Note: See TracChangeset for help on using the changeset viewer.