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/merge_bathy.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/merge_bathy.f90

    r4213 r5600  
    77! 
    88! DESCRIPTION: 
     9!> @file 
    910!> @brief  
    1011!> This program merge bathymetry file at boundaries. 
    1112!> 
    1213!> @details 
     14!> @section sec1 method 
    1315!> Coarse grid Bathymetry is interpolated on fine grid.  
    14 !> Then fine Bathymetry and refined coarse bathymetry are merged at boundaries. 
    15 !> 
    16 !> BathyFine= weight * BathyCoarse + (1-weight)*BathyFine 
    17 !> 
    18 !> The weight function used is : 0.5 + 0.5*COS( (pi*dist) / width )  
    19 !> 
    20 !> @author 
    21 !> J.Paul 
     16!> Then fine Bathymetry and refined coarse bathymetry are merged at boundaries.<br/> 
     17!>    @f[BathyFine= Weight * BathyCoarse + (1-Weight)*BathyFine@f] 
     18!> The weight function used is :<br/> 
     19!>       @f[Weight = 0.5 + 0.5*COS( \frac{\pi*dist}{width} )@f]<br/> 
     20!> with 
     21!> - dist : number of point to border  
     22!> - width : boundary size 
     23!> 
     24!> @section sec2 how to 
     25!>    to merge bathymetry file:<br/> 
     26!> @code{.sh} 
     27!>    ./SIREN/bin/merge_bathy merge_bathy.nam 
     28!> @endcode 
     29!>     
     30!>    merge_bathy.nam comprise 8 namelists: 
     31!>       - logger namelist (namlog) 
     32!>       - config namelist (namcfg) 
     33!>       - coarse grid namelist (namcrs) 
     34!>       - fine grid namelist (namfin) 
     35!>       - variable namelist (namvar) 
     36!>       - nesting namelist (namnst) 
     37!>       - boundary namelist (nambdy) 
     38!>       - output namelist (namout) 
     39!>  
     40!>    @note  
     41!>       All namelists have to be in file merge_bathy.nam,  
     42!>       however variables of those namelists are all optional. 
     43!> 
     44!>    * _logger namelist (namlog)_: 
     45!>       - cn_logfile   : logger filename 
     46!>       - cn_verbosity : verbosity ('trace','debug','info', 
     47!>  'warning','error','fatal') 
     48!>       - in_maxerror  : maximum number of error allowed 
     49!> 
     50!>    * _config namelist (namcfg)_: 
     51!>       - cn_varcfg : variable configuration file (see ./SIREN/cfg/variable.cfg) 
     52!> 
     53!>    * _coarse grid namelist (namcrs)_: 
     54!>       - cn_bathy0 : bathymetry file 
     55!>       - in_perio0 : NEMO periodicity index (see Model Boundary Condition in 
     56!> [NEMO documentation](http://www.nemo-ocean.eu/About-NEMO/Reference-manuals)) 
     57!> 
     58!>    * _fine grid namelist (namfin)_: 
     59!>       - cn_bathy1 : bathymetry file 
     60!>       - in_perio1 : NEMO periodicity index 
     61!> 
     62!>    * _variable namelist (namvar)_: 
     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.<br/> 
     66!>          it is composed of the variable name follow by ':',  
     67!>          then request(s) to be used on this variable.<br/>  
     68!>          request could be: 
     69!>             - interpolation method 
     70!>  
     71!>                requests must be separated by ';'.<br/> 
     72!>                order of requests does not matter.<br/> 
     73!> 
     74!>          informations about available method could be find in  
     75!>          @ref interp modules.<br/> 
     76!>          Example: 'bathymetry: cubic' 
     77!>          @note  
     78!>             If you do not specify a method which is required,  
     79!>             default one is apply. 
     80!>          @warning  
     81!>             variable name must be __Bathymetry__ here. 
     82!> 
     83!>    * _nesting namelist (namnst)_: 
     84!>       - in_rhoi  : refinement factor in i-direction 
     85!>       - in_rhoj  : refinement factor in j-direction 
     86!> 
     87!>    * _boundary namelist (nambdy)_: 
     88!>       - ln_north : use north boundary or not 
     89!>       - ln_south : use south boundary or not 
     90!>       - ln_east  : use east  boundary or not 
     91!>       - ln_west  : use west  boundary or not 
     92!>       - cn_north : north boundary indices on fine grid<br/> 
     93!>          *cn_north* is a string character defining boundary 
     94!>          segmentation.<br/> 
     95!>          segments are separated by '|'.<br/> 
     96!>          each segments of the boundary is composed of: 
     97!>             - orthogonal indice (.ie. for north boundary, 
     98!>             J-indice where boundary are).  
     99!>             - first indice of boundary (I-indice for north boundary)  
     100!>             - last  indice of boundary (I-indice for north boundary)<br/> 
     101!>                indices must be separated by ',' .<br/> 
     102!>             - optionally, boundary size could be added between '(' and ')'  
     103!>             in the first segment defined. 
     104!>                @note  
     105!>                   boundary size is the same for all segments of one boundary. 
     106!> 
     107!>          Examples: 
     108!>             - cn_north='index1,first1,last1(width)' 
     109!>             - cn_north='index1(width),first1,last1|index2,first2,last2' 
     110!>       - cn_south : south boundary indices on fine grid<br/> 
     111!>       - cn_east  : east  boundary indices on fine grid<br/> 
     112!>       - cn_west  : west  boundary indices on fine grid<br/> 
     113!>       - ln_oneseg: use only one segment for each boundary or not 
     114!> 
     115!>    * _output namelist (namout)_: 
     116!>       - cn_fileout : merged bathymetry file 
     117!> 
     118!> @author J.Paul 
    22119! REVISION HISTORY: 
    23 !> @date Nov, 2013 - Initial Version 
    24 ! 
     120!> @date November, 2013 - Initial Version 
     121!> @date Sepember, 2014  
     122!> - add header for user 
     123!> 
    25124!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt) 
    26 !> 
    27 !> @todo 
    28125!---------------------------------------------------------------------- 
    29 !> @code 
    30126PROGRAM merge_bathy 
    31127 
     
    43139   USE boundary                        ! boundary manager 
    44140   USE iom                             ! I/O manager 
    45    USE dom                             ! domain manager 
    46141   USE grid                            ! grid manager 
    47142   USE extrap                          ! extrapolation manager 
     
    49144   USE filter                          ! filter manager 
    50145   USE mpp                             ! MPP manager 
     146   USE dom                             ! domain manager 
    51147   USE iom_mpp                         ! MPP I/O manager 
     148   USE iom_dom                         ! DOM I/O manager 
    52149 
    53150   IMPLICIT NONE 
     
    60157   INTEGER(i4)                                        :: il_status 
    61158   INTEGER(i4)                                        :: il_fileid 
    62    INTEGER(i4)                                        :: il_attid 
     159   INTEGER(i4)                                        :: il_attind 
    63160   INTEGER(i4)                                        :: il_imin0 
    64161   INTEGER(i4)                                        :: il_imax0 
     
    66163   INTEGER(i4)                                        :: il_jmax0 
    67164   INTEGER(i4)      , DIMENSION(ip_maxdim)            :: il_rho 
    68    INTEGER(i4)      , DIMENSION(2,2)                  :: il_offset 
    69    INTEGER(i4)      , DIMENSION(2,2,2)                :: il_ind 
    70 !   INTEGER(i4)      , DIMENSION(:,:,:,:), ALLOCATABLE :: il_value 
     165   INTEGER(i4)      , DIMENSION(2,2)                  :: il_ind 
    71166 
    72167   LOGICAL                                            :: ll_exist 
     
    76171   REAL(dp)         , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_weight 
    77172 
    78    TYPE(TFILE)                                        :: tl_bathy0 
    79    TYPE(TFILE)                                        :: tl_bathy1 
     173   TYPE(TMPP)                                         :: tl_bathy0 
     174   TYPE(TMPP)                                         :: tl_bathy1 
    80175   TYPE(TFILE)                                        :: tl_fileout 
    81176    
     
    85180   TYPE(TVAR)                                         :: tl_lon 
    86181   TYPE(TVAR)                                         :: tl_lat 
    87 !   TYPE(TVAR)                                         :: tl_depth 
    88 !   TYPE(TVAR)                                         :: tl_time 
    89182    
    90183   TYPE(TDIM)       , DIMENSION(ip_maxdim)            :: tl_dim 
     
    98191 
    99192   ! namelist variable 
     193   ! namlog 
    100194   CHARACTER(LEN=lc)                       :: cn_logfile = 'merge_bathy.log'  
    101195   CHARACTER(LEN=lc)                       :: cn_verbosity = 'warning'  
    102  
     196   INTEGER(i4)                             :: in_maxerror = 5 
     197 
     198   ! namcfg 
     199   CHARACTER(LEN=lc)                       :: cn_varcfg = 'variable.cfg'  
     200 
     201   ! namcrs 
    103202   CHARACTER(LEN=lc)                       :: cn_bathy0 = ''  
    104203   INTEGER(i4)                             :: in_perio0 = -1 
    105204 
     205   ! namfin 
    106206   CHARACTER(LEN=lc)                       :: cn_bathy1 = ''  
    107207   INTEGER(i4)                             :: in_perio1 = -1 
    108208 
    109    CHARACTER(LEN=lc)                       :: cn_varcfg = 'variable.cfg'  
    110  
    111    CHARACTER(LEN=lc), DIMENSION(ig_maxvar) :: cn_varinfo = '' 
    112  
    113    INTEGER(i4)                             :: in_imin0 = 0 
    114    INTEGER(i4)                             :: in_imax0 = 0 
    115    INTEGER(i4)                             :: in_jmin0 = 0 
    116    INTEGER(i4)                             :: in_jmax0 = 0 
     209   ! namvar 
     210   CHARACTER(LEN=lc), DIMENSION(ip_maxvar) :: cn_varinfo = '' 
     211 
     212   ! namnst 
    117213   INTEGER(i4)                             :: in_rhoi  = 0 
    118214   INTEGER(i4)                             :: in_rhoj  = 0 
    119215 
     216   ! nambdy 
    120217   LOGICAL                                 :: ln_north = .TRUE. 
    121218   LOGICAL                                 :: ln_south = .TRUE. 
     
    128225   CHARACTER(LEN=lc)                       :: cn_west  = '' 
    129226 
     227   ! namout 
    130228   CHARACTER(LEN=lc)                       :: cn_fileout = 'bathy_merged.nc'  
    131229   !------------------------------------------------------------------- 
     
    152250    
    153251   NAMELIST /namnst/ &  !< nesting namelist 
    154    &  in_imin0,   &     !< i-direction lower left  point indice on coarse grid  
    155    &  in_imax0,   &     !< i-direction upper right point indice on coarse grid 
    156    &  in_jmin0,   &     !< j-direction lower left  point indice on coarse grid 
    157    &  in_jmax0,   &     !< j-direction upper right point indice on coarse grid 
    158252   &  in_rhoi,    &     !< refinement factor in i-direction 
    159253   &  in_rhoj           !< refinement factor in j-direction 
     
    171265 
    172266   NAMELIST /namout/ &  !< output namelist 
    173    &  cn_fileout       !< fine grid merged bathymetry file    
     267   &  cn_fileout        !< fine grid merged bathymetry file    
    174268   !------------------------------------------------------------------- 
    175269 
    176    !1- namelist 
    177    !1-1 get namelist 
     270   ! namelist 
     271   ! get namelist 
    178272   il_narg=COMMAND_ARGUMENT_COUNT() !f03 intrinsec 
    179273   IF( il_narg/=1 )THEN 
     
    184278   ENDIF 
    185279    
    186    !1-2 read namelist 
     280   ! read namelist 
    187281   INQUIRE(FILE=TRIM(cl_namelist), EXIST=ll_exist) 
    188282   IF( ll_exist )THEN 
     
    203297 
    204298      READ( il_fileid, NML = namlog ) 
    205       !1-2-1 define log file 
    206       CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity)) 
     299      ! define log file 
     300      CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity), in_maxerror) 
    207301      CALL logger_header() 
    208302 
    209303      READ( il_fileid, NML = namcfg ) 
    210       !1-2-2 get variable extra information 
     304      ! get variable extra information 
    211305      CALL var_def_extra(TRIM(cn_varcfg)) 
    212306 
     
    214308      READ( il_fileid, NML = namfin ) 
    215309      READ( il_fileid, NML = namvar ) 
    216       !1-2-3 add user change in extra information 
     310      ! add user change in extra information 
    217311      CALL var_chg_extra(cn_varinfo) 
    218312 
     
    234328   ENDIF 
    235329 
    236    !2- open files 
     330   ! open files 
    237331   IF( TRIM(cn_bathy0) /= '' )THEN 
    238       tl_bathy0=file_init(TRIM(cn_bathy0),id_perio=in_perio0) 
    239       CALL iom_open(tl_bathy0) 
     332      tl_bathy0=mpp_init( file_init(TRIM(cn_bathy0)), id_perio=in_perio0) 
     333      CALL grid_get_info(tl_bathy0) 
    240334   ELSE 
    241335      CALL logger_fatal("MERGE BATHY: can not find coarse grid bathymetry "//& 
     
    244338 
    245339   IF( TRIM(cn_bathy1) /= '' )THEN 
    246       tl_bathy1=file_init(TRIM(cn_bathy1),id_perio=in_perio1) 
    247       CALL iom_open(tl_bathy1) 
     340      tl_bathy1=mpp_init( file_init(TRIM(cn_bathy1)), id_perio=in_perio1) 
     341      CALL grid_get_info(tl_bathy1) 
    248342   ELSE 
    249343      CALL logger_fatal("MERGE BATHY: can not find fine grid bathymetry "//& 
     
    251345   ENDIF 
    252346 
    253    !3- check 
    254    !3-1 check output file do not already exist 
     347   ! check 
     348   ! check output file do not already exist 
    255349   INQUIRE(FILE=TRIM(cn_fileout), EXIST=ll_exist) 
    256350   IF( ll_exist )THEN 
     
    259353   ENDIF 
    260354 
    261    !3-2 check namelist 
    262    !3-2-1 check refinament factor 
     355   ! check namelist 
     356   ! check refinament factor 
    263357   il_rho(:)=1 
    264358   IF( in_rhoi < 1 .OR. in_rhoj < 1 )THEN 
     
    270364   ENDIF 
    271365 
    272    !3-2-2 check domain indices 
    273    IF( in_imin0 < 1 .OR. in_imax0 < 1 .OR. in_jmin0 < 1 .OR. in_jmax0 < 1)THEN 
    274       ! compute coarse grid indices around fine grid 
    275       il_ind(:,:,:)=grid_get_coarse_index(tl_bathy0, tl_bathy1 ) 
    276  
    277       il_imin0=il_ind(1,1,1) ; il_imax0=il_ind(1,2,1) 
    278       il_jmin0=il_ind(2,1,1) ; il_jmax0=il_ind(2,2,1) 
    279  
    280       il_offset(:,:)=il_ind(:,:,2) 
    281    ELSE 
    282       il_imin0=in_imin0 ; il_imax0=in_imax0 
    283       il_jmin0=in_jmin0 ; il_jmax0=in_jmax0 
    284  
    285       il_offset(1,:)=FLOOR(REAL(il_rho(jp_I)-1,dp)*0.5) 
    286       il_offset(2,:)=FLOOR(REAL(il_rho(jp_J)-1,dp)*0.5) 
    287    ENDIF 
    288  
    289    !3-3 check domain validity 
     366   ! check domain indices 
     367   ! compute coarse grid indices around fine grid 
     368   il_ind(:,:)=grid_get_coarse_index(tl_bathy0, tl_bathy1, & 
     369   &                                 id_rho=il_rho(:) ) 
     370 
     371   il_imin0=il_ind(1,1) ; il_imax0=il_ind(1,2) 
     372   il_jmin0=il_ind(2,1) ; il_jmax0=il_ind(2,2) 
     373 
     374   ! check domain validity 
    290375   CALL grid_check_dom(tl_bathy0, il_imin0, il_imax0, il_jmin0, il_jmax0) 
    291376 
    292    !3-4 check coincidence between coarse and fine grid 
     377   ! check coincidence between coarse and fine grid 
    293378   CALL grid_check_coincidence( tl_bathy0, tl_bathy1, & 
    294379   &                            il_imin0, il_imax0, & 
     
    296381   &                            il_rho(:) ) 
    297382 
    298    !4- read or compute boundary 
    299    tl_var=iom_read_var(tl_bathy1,'Bathymetry') 
     383   ! open mpp files 
     384   CALL iom_mpp_open(tl_bathy1) 
     385 
     386   ! read or compute boundary 
     387   tl_var=iom_mpp_read_var(tl_bathy1,'Bathymetry') 
     388 
     389   ! close mpp files 
     390   CALL iom_mpp_close(tl_bathy1) 
    300391 
    301392   tl_bdy(:)=boundary_init(tl_var, ln_north, ln_south, ln_east, ln_west, & 
     
    303394   &                               ln_oneseg )  
    304395 
    305    !5- get boundary on coarse grid 
    306    !5-1 define refined bathymetry table (for coarse grid) 
     396   ! get boundary on coarse grid 
     397   ! define refined bathymetry array (for coarse grid) 
    307398   dl_fill=tl_var%d_fill 
    308399   ALLOCATE( dl_refined(tl_var%t_dim(1)%i_len, & 
     
    313404   dl_refined(:,:,:,:)=dl_fill 
    314405 
    315    !5-2 define weight table 
     406   ! define weight array 
    316407   ALLOCATE( dl_weight(tl_var%t_dim(1)%i_len, & 
    317408   &                   tl_var%t_dim(2)%i_len, & 
     
    320411   dl_weight(:,:,:,:)=dl_fill  
    321412 
    322    !5-3 compute coarse grid refined bathymetry on boundary. 
     413   ! compute coarse grid refined bathymetry on boundary. 
    323414   DO jk=1,ip_ncard 
    324  
    325415      CALL merge_bathy_get_boundary(tl_bathy0, tl_bathy1, tl_bdy(jk), & 
    326416      &                             il_rho(:),                        & 
     
    330420   ENDDO 
    331421 
    332    !6- merge bathy on boundary 
     422   ! merge bathy on boundary 
    333423   DO jl=1,tl_var%t_dim(4)%i_len 
    334424      DO jk=1,tl_var%t_dim(3)%i_len 
     
    348438   DEALLOCATE(dl_refined) 
    349439 
    350    !7- create file 
     440   ! create file 
    351441   tl_fileout=file_init(TRIM(cn_fileout),id_perio=in_perio1) 
    352442 
    353    !7-1 add dimension 
    354    tl_dim(:)=tl_var%t_dim(:) 
     443   ! add dimension 
     444   tl_dim(:)=dim_copy(tl_var%t_dim(:)) 
    355445 
    356446   DO ji=1,ip_maxdim 
     
    358448   ENDDO 
    359449 
    360    !7-2 add variables 
     450   ! add variables 
    361451   IF( ALL( tl_dim(1:2)%l_use ) )THEN 
    362  
    363       tl_lon=iom_read_var(tl_bathy1,'longitude') 
     452      ! open mpp files 
     453      CALL iom_mpp_open(tl_bathy1) 
     454 
     455      ! add longitude 
     456      tl_lon=iom_mpp_read_var(tl_bathy1,'longitude') 
    364457      CALL file_add_var(tl_fileout, tl_lon) 
    365458      CALL var_clean(tl_lon) 
    366459 
    367       tl_lat=iom_read_var(tl_bathy1,'latitude') 
     460      ! add latitude 
     461      tl_lat=iom_mpp_read_var(tl_bathy1,'latitude') 
    368462      CALL file_add_var(tl_fileout, tl_lat) 
    369463      CALL var_clean(tl_lat) 
    370464 
     465      ! close mpp files 
     466      CALL iom_mpp_close(tl_bathy1)       
    371467   ENDIF 
    372468 
     
    375471 
    376472   ! only 2 first dimension to be used 
    377    tl_dim(:)=tl_fileout%t_dim(:) 
     473   tl_dim(:)=dim_copy(tl_fileout%t_dim(:)) 
    378474   tl_dim(3:4)%l_use=.FALSE. 
    379475   tl_var=var_init('weight',dl_weight(:,:,:,:),td_dim=tl_dim(:),dd_fill=dl_fill) 
     
    381477   CALL var_clean(tl_var) 
    382478 
    383    !7-3 add some attribute 
     479   ! add some attribute 
    384480   tl_att=att_init("Created_by","SIREN merge_bathy") 
    385481   CALL file_add_att(tl_fileout, tl_att) 
     
    395491   CALL file_add_att(tl_fileout, tl_att) 
    396492 
    397    ! a voir 
    398493   ! add attribute periodicity 
    399    il_attid=0 
     494   il_attind=0 
    400495   IF( ASSOCIATED(tl_fileout%t_att) )THEN 
    401       il_attid=att_get_id(tl_fileout%t_att(:),'periodicity') 
    402    ENDIF 
    403    IF( tl_bathy1%i_perio >= 0 .AND. il_attid == 0 )THEN 
     496      il_attind=att_get_index(tl_fileout%t_att(:),'periodicity') 
     497   ENDIF 
     498   IF( tl_bathy1%i_perio >= 0 .AND. il_attind == 0 )THEN 
    404499      tl_att=att_init('periodicity',tl_bathy1%i_perio) 
    405500      CALL file_add_att(tl_fileout,tl_att) 
    406501   ENDIF 
    407502 
    408    il_attid=0 
     503   il_attind=0 
    409504   IF( ASSOCIATED(tl_fileout%t_att) )THEN 
    410       il_attid=att_get_id(tl_fileout%t_att(:),'ew_overlap') 
    411    ENDIF 
    412    IF( tl_bathy1%i_ew >= 0 .AND. il_attid == 0 )THEN 
     505      il_attind=att_get_index(tl_fileout%t_att(:),'ew_overlap') 
     506   ENDIF 
     507   IF( tl_bathy1%i_ew >= 0 .AND. il_attind == 0 )THEN 
    413508      tl_att=att_init('ew_overlap',tl_bathy1%i_ew) 
    414509      CALL file_add_att(tl_fileout,tl_att) 
    415510   ENDIF 
    416511 
    417    !7-4 create file 
     512   ! create file 
    418513   CALL iom_create(tl_fileout) 
    419514 
    420    !7-5 write file 
     515   ! write file 
    421516   CALL iom_write_file(tl_fileout) 
    422517 
    423    !7-6 close file 
     518   ! close file 
    424519   CALL iom_close(tl_fileout) 
    425520 
    426    CALL iom_close(tl_bathy1) 
    427    CALL iom_close(tl_bathy0) 
    428  
    429    !8- clean 
     521   ! clean 
     522   CALL att_clean(tl_att) 
    430523   CALL file_clean(tl_fileout) 
    431    CALL file_clean(tl_bathy1) 
    432    CALL file_clean(tl_bathy0) 
     524   CALL mpp_clean(tl_bathy1) 
     525   CALL mpp_clean(tl_bathy0) 
    433526   DEALLOCATE(dl_weight) 
    434527 
     
    437530   CALL logger_close() 
    438531 
    439 !> @endcode 
    440532CONTAINS 
    441533   !------------------------------------------------------------------- 
    442534   !> @brief 
    443    !> This subroutine 
     535   !> This subroutine compute refined bathymetry on boundary from coarse grid. 
    444536   !>  
    445    !> @details  
     537   !> @author J.Paul 
     538   !> @date November, 2013 - Initial Version 
    446539   !> 
    447    !> @author J.Paul 
    448    !> - Nov, 2013- Initial Version 
    449    !> 
    450    !> @param[in]  
    451    !> @todo  
     540   !> @param[in] td_bathy0       coarse grid bathymetry file structure  
     541   !> @param[in] td_bathy1       fine grid bathymetry file structure 
     542   !> @param[in] td_bdy          boundary structure 
     543   !> @param[in] id_rho          array of refinement factor 
     544   !> @param[inout] dd_refined   array of refined bathymetry  
     545   !> @param[inout] dd_weight    array of weight 
     546   !> @param[in] dd_fill         fillValue 
    452547   !------------------------------------------------------------------- 
    453    !> @code 
    454548   SUBROUTINE merge_bathy_get_boundary( td_bathy0, td_bathy1, td_bdy, & 
    455549   &                                    id_rho,                       & 
     
    459553 
    460554      ! Argument 
    461       TYPE(TFILE)                    , INTENT(IN   ) :: td_bathy0 
    462       TYPE(TFILE)                    , INTENT(IN   ) :: td_bathy1 
     555      TYPE(TMPP)                     , INTENT(IN   ) :: td_bathy0 
     556      TYPE(TMPP)                     , INTENT(IN   ) :: td_bathy1 
    463557      TYPE(TBDY)                     , INTENT(IN   ) :: td_bdy 
    464558      INTEGER(i4), DIMENSION(:)      , INTENT(IN   ) :: id_rho 
     
    478572      INTEGER(i4) :: il_jmax0 
    479573 
    480       INTEGER(i4) :: il_imin 
    481       INTEGER(i4) :: il_imax 
    482       INTEGER(i4) :: il_jmin 
    483       INTEGER(i4) :: il_jmax 
    484  
    485574      INTEGER(i4), DIMENSION(2,2)         :: il_offset 
    486       INTEGER(i4), DIMENSION(2,2,2)       :: il_ind 
     575      INTEGER(i4), DIMENSION(2,2       :: il_ind 
    487576 
    488577      REAL(dp)   , DIMENSION(:)      , ALLOCATABLE :: dl_tmp1d 
     
    494583      TYPE(TVAR) :: tl_lat1 
    495584 
    496       TYPE(TFILE) :: tl_bathy1 
    497       TYPE(TFILE) :: tl_bathy0 
    498  
    499       TYPE(TMPP)  :: tl_mppbathy1 
    500       TYPE(TMPP)  :: tl_mppbathy0 
     585      TYPE(TMPP)  :: tl_bathy1 
     586      TYPE(TMPP)  :: tl_bathy0 
    501587 
    502588      TYPE(TDOM)  :: tl_dom1 
     
    510596      IF( td_bdy%l_use )THEN 
    511597         DO jl=1,td_bdy%i_nseg 
    512              
    513             !1- get boundary definition 
     598            ! get boundary definition 
    514599            SELECT CASE(TRIM(td_bdy%c_card)) 
    515600            CASE('north') 
     
    520605               il_jmax1=td_bdy%t_seg(jl)%i_index 
    521606 
    522                il_imin=1 
    523                il_imax=il_imax1-il_imin1+1 
    524                il_jmin=td_bdy%t_seg(jl)%i_width 
    525                il_jmax=1 
    526  
    527607            CASE('south') 
    528608 
     
    532612               il_jmax1=td_bdy%t_seg(jl)%i_index+(td_bdy%t_seg(jl)%i_width-1) 
    533613 
    534                il_imin=1 
    535                il_imax=il_imax1-il_imin1+1 
    536                il_jmin=1 
    537                il_jmax=td_bdy%t_seg(jl)%i_width 
    538                 
    539614            CASE('east') 
    540615 
     
    544619               il_jmax1=td_bdy%t_seg(jl)%i_last  
    545620 
    546                il_imin=td_bdy%t_seg(jl)%i_width 
    547                il_imax=1 
    548                il_jmin=1 
    549                il_jmax=il_jmax1-il_jmin1+1 
    550  
    551621            CASE('west') 
    552622 
     
    556626               il_jmax1=td_bdy%t_seg(jl)%i_last  
    557627 
    558                il_imin=1 
    559                il_imax=td_bdy%t_seg(jl)%i_width 
    560                il_jmin=1 
    561                il_jmax=il_jmax1-il_jmin1+1 
    562  
    563628            END SELECT 
    564629 
    565             !2 -read fine grid domain 
    566             tl_bathy1=td_bathy1 
    567             CALL iom_open(tl_bathy1) 
    568  
    569             !2-1 compute domain 
     630            ! -read fine grid domain 
     631            tl_bathy1=mpp_copy(td_bathy1) 
     632 
     633            ! compute domain 
    570634            tl_dom1=dom_init( tl_bathy1,         & 
    571635            &                 il_imin1, il_imax1,& 
    572             &                 il_jmin1, il_jmax1 ) 
    573  
    574             !2-2 close file 
    575             CALL iom_close(tl_bathy1) 
    576  
    577             !2-3 read variables on domain (ugly way to do it, have to work on it) 
    578             !2-3-1 init mpp structure 
    579             tl_mppbathy1=mpp_init(tl_bathy1) 
    580   
    581             CALL file_clean(tl_bathy1) 
    582  
    583             !2-3-2 get processor to be used 
    584             CALL mpp_get_use( tl_mppbathy1, tl_dom1 ) 
    585  
    586             !2-3-3 open mpp files 
    587             CALL iom_mpp_open(tl_mppbathy1) 
    588  
    589             !2-3-4 read variable value on domain 
    590             tl_lon1=iom_mpp_read_var(tl_mppbathy1,'longitude',td_dom=tl_dom1) 
    591             tl_lat1=iom_mpp_read_var(tl_mppbathy1,'latitude' ,td_dom=tl_dom1) 
    592  
    593             !2-3-5 close mpp files 
    594             CALL iom_mpp_close(tl_mppbathy1) 
    595  
    596             !2-3-6 clean structure 
    597             CALL mpp_clean(tl_mppbathy1) 
    598  
    599             !3- get coarse grid indices 
    600             il_ind(:,:,:)=grid_get_coarse_index(td_bathy0, tl_lon1, tl_lat1, & 
    601             &                                   id_rho=id_rho(:)) 
    602  
    603             il_imin0=il_ind(1,1,1) 
    604             il_imax0=il_ind(1,2,1) 
    605  
    606             il_jmin0=il_ind(2,1,1) 
    607             il_jmax0=il_ind(2,2,1) 
    608  
    609             il_offset(:,:)=il_ind(:,:,2) 
    610  
    611             !4- read coarse grid bathymetry on domain 
    612             tl_bathy0=td_bathy0 
    613             CALL iom_open(tl_bathy0) 
    614  
    615             !4-1 compute domain 
     636            &                 il_jmin1, il_jmax1,& 
     637            &                 TRIM(td_bdy%c_card)) 
     638 
     639            ! add extra band to fine grid domain (if possible) 
     640            ! to avoid dimension of one and so be able to compute offset 
     641            CALL dom_add_extra(tl_dom1, id_rho(jp_I), id_rho(jp_J)) 
     642 
     643            ! open mpp files over domain 
     644            CALL iom_dom_open(tl_bathy1, tl_dom1) 
     645 
     646            ! read variable value on domain 
     647            tl_lon1=iom_dom_read_var(tl_bathy1,'longitude',tl_dom1) 
     648            tl_lat1=iom_dom_read_var(tl_bathy1,'latitude' ,tl_dom1) 
     649 
     650            ! close mpp files 
     651            CALL iom_dom_close(tl_bathy1) 
     652 
     653            ! clean structure 
     654            CALL mpp_clean(tl_bathy1) 
     655 
     656            ! get coarse grid indices 
     657            il_ind(:,:)=grid_get_coarse_index(td_bathy0, tl_lon1, tl_lat1, & 
     658            &                                 id_rho=id_rho(:)) 
     659 
     660            il_imin0=il_ind(1,1) 
     661            il_imax0=il_ind(1,2) 
     662 
     663            il_jmin0=il_ind(2,1) 
     664            il_jmax0=il_ind(2,2) 
     665 
     666            ! read coarse grid bathymetry on domain 
     667            tl_bathy0=mpp_copy(td_bathy0) 
     668 
     669            ! compute domain 
    616670            tl_dom0=dom_init( tl_bathy0,         & 
    617671            &                 il_imin0, il_imax0,& 
    618672            &                 il_jmin0, il_jmax0 ) 
    619673 
    620             !4-2 close file 
    621             CALL iom_close(tl_bathy0) 
    622  
    623             !4-3 add extra band (if possible) to compute interpolation 
     674            il_offset(:,:)= grid_get_fine_offset(tl_bathy0,         & 
     675            &                                    il_imin0, il_jmin0,& 
     676            &                                    il_imax0, il_jmax0,& 
     677            &                                    tl_lon1%d_value(:,:,1,1), & 
     678            &                                    tl_lat1%d_value(:,:,1,1), & 
     679            &                                    id_rho=id_rho(:)) 
     680 
     681            ! clean 
     682            CALL var_clean(tl_lon1) 
     683            CALL var_clean(tl_lat1) 
     684 
     685            ! add extra band (if possible) to compute interpolation 
    624686            CALL dom_add_extra(tl_dom0) 
    625687 
    626             !4-4 read variables on domain (ugly way to do it, have to work on it) 
    627             !4-4-1 init mpp structure 
    628             tl_mppbathy0=mpp_init(tl_bathy0) 
    629              
    630             CALL file_clean(tl_bathy0) 
    631  
    632             !4-4-2 get processor to be used 
    633             CALL mpp_get_use( tl_mppbathy0, tl_dom0 ) 
    634  
    635             !4-4-3 open mpp files 
    636             CALL iom_mpp_open(tl_mppbathy0) 
    637  
    638             !4-4-4 read variable value on domain 
    639             tl_var0=iom_mpp_read_var(tl_mppbathy0,'Bathymetry',td_dom=tl_dom0) 
    640  
    641             !4-4-5 close mpp files 
    642             CALL iom_mpp_close(tl_mppbathy0) 
    643  
    644             !4-4-6 clean structure 
    645             CALL mpp_clean(tl_mppbathy0) 
    646  
    647             !5- interpolate variable 
     688            ! open mpp files over domain 
     689            CALL iom_dom_open(tl_bathy0, tl_dom0) 
     690 
     691            ! read variable value on domain 
     692            tl_var0=iom_dom_read_var(tl_bathy0,'Bathymetry',tl_dom0) 
     693 
     694            ! close mpp files 
     695            CALL iom_dom_close(tl_bathy0) 
     696 
     697            ! clean structure 
     698            CALL mpp_clean(tl_bathy0) 
     699 
     700            ! interpolate variable 
    648701            CALL merge_bathy_interp( tl_var0,         & 
    649702            &                        id_rho(:),       & 
    650703            &                        il_offset(:,:) ) 
    651704 
    652             !6- remove extraband added to domain 
     705            ! remove extraband added to domain 
    653706            CALL dom_del_extra( tl_var0, tl_dom0, id_rho(:) ) 
    654707 
    655             !6-1 remove extraband added to domain 
     708            ! remove extraband added to domain 
    656709            CALL dom_clean_extra( tl_dom0 ) 
    657710 
    658             !7- fill refined table   
    659             !7-1 keep only useful point 
    660             ! interpolation could create more point than necessary 
    661             CALL boundary_clean_interp(tl_var0, td_bdy ) 
    662  
    663             ! use add request ???? 
    664  
    665             !7-2 fill refined table 
     711            ! remove extraband added to fine grid domain 
     712            CALL dom_del_extra( tl_var0, tl_dom1 ) 
     713 
     714            ! remove extraband added to fine grid domain 
     715            CALL dom_clean_extra( tl_dom1 ) 
     716 
     717            ! fill refined array 
    666718            dd_refined( il_imin1:il_imax1, & 
    667719            &           il_jmin1:il_jmax1, & 
    668720            &           :,: )= tl_var0%d_value(:,:,:,:) 
    669721 
    670             !8- compute weight function 
     722            ! clean 
     723            CALL var_clean(tl_var0) 
     724 
     725            ! compute weight function 
    671726            ALLOCATE( dl_tmp1d(td_bdy%t_seg(jl)%i_width) ) 
    672727 
     
    678733 
    679734               ! compute weight on segment 
    680                dl_tmp1d(:)= 0.5 + 0.5*COS( (dg_pi*dl_tmp1d(:)) / & 
     735               dl_tmp1d(:)= 0.5 + 0.5*COS( (dp_pi*dl_tmp1d(:)) / & 
    681736               &                           (td_bdy%t_seg(jl)%i_width) ) 
    682737 
     
    694749 
    695750               ! compute weight on segment 
    696                dl_tmp1d(:)= 0.5 + 0.5*COS( (dg_pi*dl_tmp1d(:)) / & 
     751               dl_tmp1d(:)= 0.5 + 0.5*COS( (dp_pi*dl_tmp1d(:)) / & 
    697752               &                           (td_bdy%t_seg(jl)%i_width) ) 
    698753 
     
    710765 
    711766               ! compute weight on segment 
    712                dl_tmp1d(:)= 0.5 + 0.5*COS( (dg_pi*dl_tmp1d(:)) / & 
     767               dl_tmp1d(:)= 0.5 + 0.5*COS( (dp_pi*dl_tmp1d(:)) / & 
    713768               &                           (td_bdy%t_seg(jl)%i_width) ) 
    714769 
     
    726781 
    727782               ! compute weight on segment 
    728                dl_tmp1d(:)= 0.5 + 0.5*COS( (dg_pi*dl_tmp1d(:)) / & 
     783               dl_tmp1d(:)= 0.5 + 0.5*COS( (dp_pi*dl_tmp1d(:)) / & 
    729784               &                           (td_bdy%t_seg(jl)%i_width) ) 
    730785 
     
    740795            DEALLOCATE( dl_tmp1d ) 
    741796 
    742             !8-1 fill weight table 
     797            ! fill weight array 
    743798            ALLOCATE( dl_tmp2d( tl_dom1%t_dim(1)%i_len, & 
    744799            &                   tl_dom1%t_dim(2)%i_len) ) 
     
    764819      ENDIF 
    765820   END SUBROUTINE merge_bathy_get_boundary 
    766    !> @endcode 
    767821   !------------------------------------------------------------------- 
    768822   !> @brief 
    769    !> This subroutine 
     823   !> This subroutine interpolate variable. 
    770824   !>  
    771    !> @details  
     825   !> @author J.Paul 
     826   !> @date November, 2013 - Initial Version 
    772827   !> 
    773    !> @author J.Paul 
    774    !> - Nov, 2013- Initial Version 
    775    !> 
    776    !> @param[in]  
    777    !> @todo  
     828   !> @param[inout] td_var variable structure 
     829   !> @param[in] id_rho    array of refinment factor 
     830   !> @param[in] id_offset array of offset between fine and coarse grid 
     831   !> @param[in] id_iext   i-direction size of extra bands (default=im_minext)  
     832   !> @param[in] id_jext   j-direction size of extra bands (default=im_minext) 
    778833   !------------------------------------------------------------------- 
    779    !> @code 
    780834   SUBROUTINE merge_bathy_interp( td_var,          & 
    781835   &                              id_rho,          & 
     
    793847 
    794848      ! local variable 
    795       TYPE(TVAR)  :: tl_var 
    796849      TYPE(TVAR)  :: tl_mask 
    797850 
     
    803856      ! loop indices 
    804857      !---------------------------------------------------------------- 
    805  
    806       ! copy variable 
    807       tl_var=td_var 
    808858 
    809859      !WARNING: two extrabands are required for cubic interpolation 
     
    815865 
    816866      IF( il_iext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN 
    817          CALL logger_warn("CREATE BATHY INTERP: at least extrapolation "//& 
     867         CALL logger_warn("MERGE BATHY INTERP: at least extrapolation "//& 
    818868         &  "on two points are required with cubic interpolation ") 
    819869         il_iext=2 
     
    821871 
    822872      IF( il_jext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN 
    823          CALL logger_warn("CREATE BATHY INTERP: at least extrapolation "//& 
     873         CALL logger_warn("MERGE BATHY INTERP: at least extrapolation "//& 
    824874         &  "on two points are required with cubic interpolation ") 
    825875         il_jext=2 
    826876      ENDIF 
    827877 
    828       !1- work on mask 
    829       !1-1 create mask 
    830       ALLOCATE(bl_mask(tl_var%t_dim(1)%i_len, & 
    831       &                tl_var%t_dim(2)%i_len, & 
    832       &                tl_var%t_dim(3)%i_len, & 
    833       &                tl_var%t_dim(4)%i_len) ) 
     878      ! work on mask 
     879      ! create mask 
     880      ALLOCATE(bl_mask(td_var%t_dim(1)%i_len, & 
     881      &                td_var%t_dim(2)%i_len, & 
     882      &                td_var%t_dim(3)%i_len, & 
     883      &                td_var%t_dim(4)%i_len) ) 
    834884 
    835885      bl_mask(:,:,:,:)=1 
    836       WHERE(tl_var%d_value(:,:,:,:)==tl_var%d_fill) bl_mask(:,:,:,:)=0       
    837  
    838       SELECT CASE(TRIM(tl_var%c_point)) 
     886      WHERE(td_var%d_value(:,:,:,:)==td_var%d_fill) bl_mask(:,:,:,:)=0       
     887 
     888      SELECT CASE(TRIM(td_var%c_point)) 
    839889      CASE DEFAULT ! 'T' 
    840          tl_mask=var_init('tmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:)) 
    841       CASE('U') 
    842          tl_mask=var_init('umask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:)) 
    843       CASE('V') 
    844          tl_mask=var_init('vmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:)) 
    845       CASE('F') 
    846          tl_mask=var_init('fmask', bl_mask(:,:,:,:), td_dim=tl_var%t_dim(:)) 
     890         tl_mask=var_init('tmask',bl_mask(:,:,:,:),td_dim=td_var%t_dim(:),& 
     891         &                id_ew=td_var%i_ew ) 
     892      CASE('U','V','F') 
     893         CALL logger_fatal("MERGE BATHY INTERP: can not computed "//& 
     894         &                 "interpolation on "//TRIM(td_var%c_point)//& 
     895         &                 " grid point (variable "//TRIM(td_var%c_name)//& 
     896         &                 "). check namelist.") 
    847897      END SELECT 
    848898 
    849899      DEALLOCATE(bl_mask) 
    850900 
    851       !1-2 interpolate mask 
     901      ! interpolate mask 
    852902      CALL interp_fill_value( tl_mask, id_rho(:),  & 
    853903      &                       id_offset=id_offset(:,:) ) 
    854904 
    855       !2- work on variable 
    856       !2-0 add extraband 
    857       CALL extrap_add_extrabands(tl_var, il_iext, il_iext) 
    858  
    859       !2-1 extrapolate variable 
    860       CALL extrap_fill_value( tl_var, id_offset=id_offset(:,:), & 
     905      ! work on variable 
     906      ! add extraband 
     907      CALL extrap_add_extrabands(td_var, il_iext, il_iext) 
     908 
     909      ! extrapolate variable 
     910      CALL extrap_fill_value( td_var, id_offset=id_offset(:,:), & 
    861911      &                               id_rho=id_rho(:),         & 
    862912      &                               id_iext=il_iext, id_jext=il_jext ) 
    863913 
    864       !2-2 interpolate Bathymetry 
    865       CALL interp_fill_value( tl_var, id_rho(:), & 
     914      ! interpolate Bathymetry 
     915      CALL interp_fill_value( td_var, id_rho(:), & 
    866916      &                       id_offset=id_offset(:,:) ) 
    867917 
    868       !2-3 remove extraband 
    869       CALL extrap_del_extrabands(tl_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J)) 
    870  
    871       !2-4 keep original mask  
     918      ! remove extraband 
     919      CALL extrap_del_extrabands(td_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J)) 
     920 
     921      ! keep original mask  
    872922      WHERE( tl_mask%d_value(:,:,:,:) == 0 ) 
    873          tl_var%d_value(:,:,:,:)=tl_var%d_fill 
     923         td_var%d_value(:,:,:,:)=td_var%d_fill 
    874924      END WHERE 
    875925 
    876       !3- save result 
    877       td_var=tl_var 
    878  
    879       ! clean variable structure 
    880       CALL var_clean(tl_var) 
    881  
    882926   END SUBROUTINE merge_bathy_interp 
    883    !> @endcode 
    884927END PROGRAM merge_bathy 
Note: See TracChangeset for help on using the changeset viewer.