[4213] | 1 | !---------------------------------------------------------------------- |
---|
| 2 | ! NEMO system team, System and Interface for oceanic RElocable Nesting |
---|
| 3 | !---------------------------------------------------------------------- |
---|
| 4 | ! |
---|
| 5 | ! |
---|
| 6 | ! PROGRAM: merge_bathy |
---|
| 7 | ! |
---|
| 8 | ! DESCRIPTION: |
---|
[5214] | 9 | !> @file |
---|
[4213] | 10 | !> @brief |
---|
| 11 | !> This program merge bathymetry file at boundaries. |
---|
| 12 | !> |
---|
| 13 | !> @details |
---|
[5214] | 14 | !> @section sec1 method |
---|
[4213] | 15 | !> Coarse grid Bathymetry is interpolated on fine grid. |
---|
[5214] | 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 |
---|
[4213] | 23 | !> |
---|
[5214] | 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. |
---|
[4213] | 43 | !> |
---|
[5214] | 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 |
---|
[4213] | 49 | !> |
---|
[5214] | 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 |
---|
[4213] | 119 | ! REVISION HISTORY: |
---|
[5214] | 120 | !> @date November, 2013 - Initial Version |
---|
| 121 | !> @date Sepember, 2014 |
---|
| 122 | !> - add header for user |
---|
| 123 | !> |
---|
[4213] | 124 | !> @note Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
| 125 | !---------------------------------------------------------------------- |
---|
| 126 | PROGRAM merge_bathy |
---|
| 127 | |
---|
| 128 | USE netcdf ! nf90 library |
---|
| 129 | USE global ! global variable |
---|
| 130 | USE phycst ! physical constant |
---|
| 131 | USE kind ! F90 kind parameter |
---|
| 132 | USE logger ! log file manager |
---|
| 133 | USE fct ! basic useful function |
---|
| 134 | USE date ! date manager |
---|
| 135 | USE att ! attribute manager |
---|
| 136 | USE dim ! dimension manager |
---|
| 137 | USE var ! variable manager |
---|
| 138 | USE file ! file manager |
---|
| 139 | USE boundary ! boundary manager |
---|
| 140 | USE iom ! I/O manager |
---|
| 141 | USE grid ! grid manager |
---|
| 142 | USE extrap ! extrapolation manager |
---|
| 143 | USE interp ! interpolation manager |
---|
| 144 | USE filter ! filter manager |
---|
| 145 | USE mpp ! MPP manager |
---|
[5214] | 146 | USE dom ! domain manager |
---|
[4213] | 147 | USE iom_mpp ! MPP I/O manager |
---|
[5214] | 148 | USE iom_dom ! DOM I/O manager |
---|
[4213] | 149 | |
---|
| 150 | IMPLICIT NONE |
---|
| 151 | |
---|
| 152 | ! local variable |
---|
| 153 | CHARACTER(LEN=lc) :: cl_namelist |
---|
| 154 | CHARACTER(LEN=lc) :: cl_date |
---|
| 155 | |
---|
| 156 | INTEGER(i4) :: il_narg |
---|
| 157 | INTEGER(i4) :: il_status |
---|
| 158 | INTEGER(i4) :: il_fileid |
---|
[5214] | 159 | INTEGER(i4) :: il_attind |
---|
[4213] | 160 | INTEGER(i4) :: il_imin0 |
---|
| 161 | INTEGER(i4) :: il_imax0 |
---|
| 162 | INTEGER(i4) :: il_jmin0 |
---|
| 163 | INTEGER(i4) :: il_jmax0 |
---|
| 164 | INTEGER(i4) , DIMENSION(ip_maxdim) :: il_rho |
---|
[5214] | 165 | INTEGER(i4) , DIMENSION(2,2) :: il_ind |
---|
[4213] | 166 | |
---|
| 167 | LOGICAL :: ll_exist |
---|
| 168 | |
---|
| 169 | REAL(dp) :: dl_fill |
---|
| 170 | REAL(dp) , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_refined |
---|
| 171 | REAL(dp) , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_weight |
---|
| 172 | |
---|
[5214] | 173 | TYPE(TMPP) :: tl_bathy0 |
---|
| 174 | TYPE(TMPP) :: tl_bathy1 |
---|
[4213] | 175 | TYPE(TFILE) :: tl_fileout |
---|
| 176 | |
---|
| 177 | TYPE(TATT) :: tl_att |
---|
| 178 | |
---|
| 179 | TYPE(TVAR) :: tl_var |
---|
| 180 | TYPE(TVAR) :: tl_lon |
---|
| 181 | TYPE(TVAR) :: tl_lat |
---|
| 182 | |
---|
| 183 | TYPE(TDIM) , DIMENSION(ip_maxdim) :: tl_dim |
---|
| 184 | |
---|
| 185 | TYPE(TBDY) , DIMENSION(ip_ncard) :: tl_bdy |
---|
| 186 | |
---|
| 187 | ! loop indices |
---|
| 188 | INTEGER(i4) :: ji |
---|
| 189 | INTEGER(i4) :: jk |
---|
| 190 | INTEGER(i4) :: jl |
---|
| 191 | |
---|
| 192 | ! namelist variable |
---|
[5214] | 193 | ! namlog |
---|
[4213] | 194 | CHARACTER(LEN=lc) :: cn_logfile = 'merge_bathy.log' |
---|
| 195 | CHARACTER(LEN=lc) :: cn_verbosity = 'warning' |
---|
[5214] | 196 | INTEGER(i4) :: in_maxerror = 5 |
---|
[4213] | 197 | |
---|
[5214] | 198 | ! namcfg |
---|
| 199 | CHARACTER(LEN=lc) :: cn_varcfg = 'variable.cfg' |
---|
| 200 | |
---|
| 201 | ! namcrs |
---|
[4213] | 202 | CHARACTER(LEN=lc) :: cn_bathy0 = '' |
---|
| 203 | INTEGER(i4) :: in_perio0 = -1 |
---|
| 204 | |
---|
[5214] | 205 | ! namfin |
---|
[4213] | 206 | CHARACTER(LEN=lc) :: cn_bathy1 = '' |
---|
| 207 | INTEGER(i4) :: in_perio1 = -1 |
---|
| 208 | |
---|
[5214] | 209 | ! namvar |
---|
| 210 | CHARACTER(LEN=lc), DIMENSION(ip_maxvar) :: cn_varinfo = '' |
---|
[4213] | 211 | |
---|
[5214] | 212 | ! namnst |
---|
[4213] | 213 | INTEGER(i4) :: in_rhoi = 0 |
---|
| 214 | INTEGER(i4) :: in_rhoj = 0 |
---|
| 215 | |
---|
[5214] | 216 | ! nambdy |
---|
[4213] | 217 | LOGICAL :: ln_north = .TRUE. |
---|
| 218 | LOGICAL :: ln_south = .TRUE. |
---|
| 219 | LOGICAL :: ln_east = .TRUE. |
---|
| 220 | LOGICAL :: ln_west = .TRUE. |
---|
| 221 | LOGICAL :: ln_oneseg= .TRUE. |
---|
| 222 | CHARACTER(LEN=lc) :: cn_north = '' |
---|
| 223 | CHARACTER(LEN=lc) :: cn_south = '' |
---|
| 224 | CHARACTER(LEN=lc) :: cn_east = '' |
---|
| 225 | CHARACTER(LEN=lc) :: cn_west = '' |
---|
| 226 | |
---|
[5214] | 227 | ! namout |
---|
[4213] | 228 | CHARACTER(LEN=lc) :: cn_fileout = 'bathy_merged.nc' |
---|
| 229 | !------------------------------------------------------------------- |
---|
| 230 | |
---|
| 231 | NAMELIST /namlog/ & !< logger namelist |
---|
| 232 | & cn_logfile, & !< log file |
---|
| 233 | & cn_verbosity !< log verbosity |
---|
| 234 | |
---|
| 235 | NAMELIST /namcfg/ & !< config namelist |
---|
| 236 | & cn_varcfg !< variable configuration file |
---|
| 237 | |
---|
| 238 | NAMELIST /namcrs/ & !< coarse grid namelist |
---|
| 239 | & cn_bathy0, & !< bathymetry file |
---|
| 240 | & in_perio0 !< periodicity index |
---|
| 241 | |
---|
| 242 | NAMELIST /namfin/ & !< fine grid namelist |
---|
| 243 | & cn_bathy1, & !< bathymetry file |
---|
| 244 | & in_perio1 !< periodicity index |
---|
| 245 | |
---|
| 246 | NAMELIST /namvar/ & !< variable namelist |
---|
| 247 | & cn_varinfo !< list of variable and interpolation |
---|
| 248 | !< method to be used. |
---|
| 249 | !< (ex: 'votemper|linear','vosaline|cubic' ) |
---|
| 250 | |
---|
| 251 | NAMELIST /namnst/ & !< nesting namelist |
---|
| 252 | & in_rhoi, & !< refinement factor in i-direction |
---|
| 253 | & in_rhoj !< refinement factor in j-direction |
---|
| 254 | |
---|
| 255 | NAMELIST /nambdy/ & !< boundary namelist |
---|
| 256 | & ln_north, & !< use north boundary |
---|
| 257 | & ln_south, & !< use south boundary |
---|
| 258 | & ln_east , & !< use east boundary |
---|
| 259 | & ln_west , & !< use west boundary |
---|
| 260 | & cn_north, & !< north boundary indices on fine grid |
---|
| 261 | & cn_south, & !< south boundary indices on fine grid |
---|
| 262 | & cn_east , & !< east boundary indices on fine grid |
---|
| 263 | & cn_west , & !< west boundary indices on fine grid |
---|
| 264 | & ln_oneseg !< use only one segment for each boundary or not |
---|
| 265 | |
---|
| 266 | NAMELIST /namout/ & !< output namelist |
---|
[5214] | 267 | & cn_fileout !< fine grid merged bathymetry file |
---|
[4213] | 268 | !------------------------------------------------------------------- |
---|
| 269 | |
---|
[5214] | 270 | ! namelist |
---|
| 271 | ! get namelist |
---|
[4213] | 272 | il_narg=COMMAND_ARGUMENT_COUNT() !f03 intrinsec |
---|
| 273 | IF( il_narg/=1 )THEN |
---|
| 274 | PRINT *,"MERGE BATHY: ERROR. need a namelist" |
---|
| 275 | STOP |
---|
| 276 | ELSE |
---|
| 277 | CALL GET_COMMAND_ARGUMENT(1,cl_namelist) !f03 intrinsec |
---|
| 278 | ENDIF |
---|
| 279 | |
---|
[5214] | 280 | ! read namelist |
---|
[4213] | 281 | INQUIRE(FILE=TRIM(cl_namelist), EXIST=ll_exist) |
---|
| 282 | IF( ll_exist )THEN |
---|
| 283 | |
---|
| 284 | il_fileid=fct_getunit() |
---|
| 285 | |
---|
| 286 | OPEN( il_fileid, FILE=TRIM(cl_namelist), & |
---|
| 287 | & FORM='FORMATTED', & |
---|
| 288 | & ACCESS='SEQUENTIAL', & |
---|
| 289 | & STATUS='OLD', & |
---|
| 290 | & ACTION='READ', & |
---|
| 291 | & IOSTAT=il_status) |
---|
| 292 | CALL fct_err(il_status) |
---|
| 293 | IF( il_status /= 0 )THEN |
---|
| 294 | PRINT *,"MERGE BATHY: ERROR opening "//TRIM(cl_namelist) |
---|
| 295 | STOP |
---|
| 296 | ENDIF |
---|
| 297 | |
---|
| 298 | READ( il_fileid, NML = namlog ) |
---|
[5214] | 299 | ! define log file |
---|
| 300 | CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity), in_maxerror) |
---|
[4213] | 301 | CALL logger_header() |
---|
| 302 | |
---|
| 303 | READ( il_fileid, NML = namcfg ) |
---|
[5214] | 304 | ! get variable extra information |
---|
[4213] | 305 | CALL var_def_extra(TRIM(cn_varcfg)) |
---|
| 306 | |
---|
| 307 | READ( il_fileid, NML = namcrs ) |
---|
| 308 | READ( il_fileid, NML = namfin ) |
---|
| 309 | READ( il_fileid, NML = namvar ) |
---|
[5214] | 310 | ! add user change in extra information |
---|
[4213] | 311 | CALL var_chg_extra(cn_varinfo) |
---|
| 312 | |
---|
| 313 | READ( il_fileid, NML = namnst ) |
---|
| 314 | READ( il_fileid, NML = nambdy ) |
---|
| 315 | |
---|
| 316 | READ( il_fileid, NML = namout ) |
---|
| 317 | |
---|
| 318 | CLOSE( il_fileid, IOSTAT=il_status ) |
---|
| 319 | CALL fct_err(il_status) |
---|
| 320 | IF( il_status /= 0 )THEN |
---|
| 321 | CALL logger_error("MERGE BATHY: ERROR closing "//TRIM(cl_namelist)) |
---|
| 322 | ENDIF |
---|
| 323 | |
---|
| 324 | ELSE |
---|
| 325 | |
---|
| 326 | PRINT *,"MERGE BATHY: ERROR. can not find "//TRIM(cl_namelist) |
---|
| 327 | |
---|
| 328 | ENDIF |
---|
| 329 | |
---|
[5214] | 330 | ! open files |
---|
[4213] | 331 | IF( TRIM(cn_bathy0) /= '' )THEN |
---|
[5214] | 332 | tl_bathy0=mpp_init( file_init(TRIM(cn_bathy0)), id_perio=in_perio0) |
---|
| 333 | CALL grid_get_info(tl_bathy0) |
---|
[4213] | 334 | ELSE |
---|
| 335 | CALL logger_fatal("MERGE BATHY: can not find coarse grid bathymetry "//& |
---|
| 336 | & "file. check namelist") |
---|
| 337 | ENDIF |
---|
| 338 | |
---|
| 339 | IF( TRIM(cn_bathy1) /= '' )THEN |
---|
[5214] | 340 | tl_bathy1=mpp_init( file_init(TRIM(cn_bathy1)), id_perio=in_perio1) |
---|
| 341 | CALL grid_get_info(tl_bathy1) |
---|
[4213] | 342 | ELSE |
---|
| 343 | CALL logger_fatal("MERGE BATHY: can not find fine grid bathymetry "//& |
---|
| 344 | & "file. check namelist") |
---|
| 345 | ENDIF |
---|
| 346 | |
---|
[5214] | 347 | ! check |
---|
| 348 | ! check output file do not already exist |
---|
[4213] | 349 | INQUIRE(FILE=TRIM(cn_fileout), EXIST=ll_exist) |
---|
| 350 | IF( ll_exist )THEN |
---|
| 351 | CALL logger_fatal("CREATE BATHY: output file "//TRIM(cn_fileout)//& |
---|
| 352 | & " already exist.") |
---|
| 353 | ENDIF |
---|
| 354 | |
---|
[5214] | 355 | ! check namelist |
---|
| 356 | ! check refinament factor |
---|
[4213] | 357 | il_rho(:)=1 |
---|
| 358 | IF( in_rhoi < 1 .OR. in_rhoj < 1 )THEN |
---|
| 359 | CALL logger_error("MERGE BATHY: invalid refinement factor."//& |
---|
| 360 | & " check namelist "//TRIM(cl_namelist)) |
---|
| 361 | ELSE |
---|
| 362 | il_rho(jp_I)=in_rhoi |
---|
| 363 | il_rho(jp_J)=in_rhoj |
---|
| 364 | ENDIF |
---|
| 365 | |
---|
[5214] | 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(:) ) |
---|
[4213] | 370 | |
---|
[5214] | 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) |
---|
[4213] | 373 | |
---|
[5214] | 374 | ! check domain validity |
---|
[4213] | 375 | CALL grid_check_dom(tl_bathy0, il_imin0, il_imax0, il_jmin0, il_jmax0) |
---|
| 376 | |
---|
[5214] | 377 | ! check coincidence between coarse and fine grid |
---|
[4213] | 378 | CALL grid_check_coincidence( tl_bathy0, tl_bathy1, & |
---|
| 379 | & il_imin0, il_imax0, & |
---|
| 380 | & il_jmin0, il_jmax0, & |
---|
| 381 | & il_rho(:) ) |
---|
| 382 | |
---|
[5214] | 383 | ! open mpp files |
---|
| 384 | CALL iom_mpp_open(tl_bathy1) |
---|
[4213] | 385 | |
---|
[5214] | 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) |
---|
| 391 | |
---|
[4213] | 392 | tl_bdy(:)=boundary_init(tl_var, ln_north, ln_south, ln_east, ln_west, & |
---|
| 393 | & cn_north, cn_south, cn_east, cn_west, & |
---|
| 394 | & ln_oneseg ) |
---|
| 395 | |
---|
[5214] | 396 | ! get boundary on coarse grid |
---|
| 397 | ! define refined bathymetry array (for coarse grid) |
---|
[4213] | 398 | dl_fill=tl_var%d_fill |
---|
| 399 | ALLOCATE( dl_refined(tl_var%t_dim(1)%i_len, & |
---|
| 400 | & tl_var%t_dim(2)%i_len, & |
---|
| 401 | & tl_var%t_dim(3)%i_len, & |
---|
| 402 | & tl_var%t_dim(4)%i_len) ) |
---|
| 403 | |
---|
| 404 | dl_refined(:,:,:,:)=dl_fill |
---|
| 405 | |
---|
[5214] | 406 | ! define weight array |
---|
[4213] | 407 | ALLOCATE( dl_weight(tl_var%t_dim(1)%i_len, & |
---|
| 408 | & tl_var%t_dim(2)%i_len, & |
---|
| 409 | & 1,1) ) |
---|
| 410 | |
---|
| 411 | dl_weight(:,:,:,:)=dl_fill |
---|
| 412 | |
---|
[5214] | 413 | ! compute coarse grid refined bathymetry on boundary. |
---|
[4213] | 414 | DO jk=1,ip_ncard |
---|
| 415 | CALL merge_bathy_get_boundary(tl_bathy0, tl_bathy1, tl_bdy(jk), & |
---|
| 416 | & il_rho(:), & |
---|
| 417 | & dl_refined(:,:,:,:), dl_weight(:,:,:,:), & |
---|
| 418 | & dl_fill) |
---|
| 419 | |
---|
| 420 | ENDDO |
---|
| 421 | |
---|
[5214] | 422 | ! merge bathy on boundary |
---|
[4213] | 423 | DO jl=1,tl_var%t_dim(4)%i_len |
---|
| 424 | DO jk=1,tl_var%t_dim(3)%i_len |
---|
| 425 | WHERE( dl_refined(:,:,jk,jl) /= dl_fill .AND. & |
---|
| 426 | & tl_var%d_value(:,:,jk,jl)/= tl_var%d_fill ) |
---|
| 427 | tl_var%d_value(:,:,jk,jl)= & |
---|
| 428 | & dl_weight(:,:,1,1) * dl_refined(:,:,jk,jl) + & |
---|
| 429 | & (1-dl_weight(:,:,1,1))*tl_var%d_value(:,:,jk,jl) |
---|
| 430 | ELSE WHERE( dl_refined(:,:,jk,jl)== dl_fill .AND. & |
---|
| 431 | & dl_weight(:,:,1,1) /= dl_fill ) |
---|
| 432 | ! to keep coarse grid mask on boundary |
---|
| 433 | tl_var%d_value(:,:,jk,jl)=dl_fill |
---|
| 434 | END WHERE |
---|
| 435 | ENDDO |
---|
| 436 | ENDDO |
---|
| 437 | |
---|
| 438 | DEALLOCATE(dl_refined) |
---|
| 439 | |
---|
[5214] | 440 | ! create file |
---|
[4213] | 441 | tl_fileout=file_init(TRIM(cn_fileout),id_perio=in_perio1) |
---|
| 442 | |
---|
[5214] | 443 | ! add dimension |
---|
| 444 | tl_dim(:)=dim_copy(tl_var%t_dim(:)) |
---|
[4213] | 445 | |
---|
| 446 | DO ji=1,ip_maxdim |
---|
| 447 | IF( tl_dim(ji)%l_use ) CALL file_add_dim(tl_fileout, tl_dim(ji)) |
---|
| 448 | ENDDO |
---|
| 449 | |
---|
[5214] | 450 | ! add variables |
---|
[4213] | 451 | IF( ALL( tl_dim(1:2)%l_use ) )THEN |
---|
[5214] | 452 | ! open mpp files |
---|
| 453 | CALL iom_mpp_open(tl_bathy1) |
---|
[4213] | 454 | |
---|
[5214] | 455 | ! add longitude |
---|
| 456 | tl_lon=iom_mpp_read_var(tl_bathy1,'longitude') |
---|
[4213] | 457 | CALL file_add_var(tl_fileout, tl_lon) |
---|
| 458 | CALL var_clean(tl_lon) |
---|
| 459 | |
---|
[5214] | 460 | ! add latitude |
---|
| 461 | tl_lat=iom_mpp_read_var(tl_bathy1,'latitude') |
---|
[4213] | 462 | CALL file_add_var(tl_fileout, tl_lat) |
---|
| 463 | CALL var_clean(tl_lat) |
---|
| 464 | |
---|
[5214] | 465 | ! close mpp files |
---|
| 466 | CALL iom_mpp_close(tl_bathy1) |
---|
[4213] | 467 | ENDIF |
---|
| 468 | |
---|
| 469 | CALL file_add_var(tl_fileout, tl_var) |
---|
| 470 | CALL var_clean(tl_var) |
---|
| 471 | |
---|
| 472 | ! only 2 first dimension to be used |
---|
[5214] | 473 | tl_dim(:)=dim_copy(tl_fileout%t_dim(:)) |
---|
[4213] | 474 | tl_dim(3:4)%l_use=.FALSE. |
---|
| 475 | tl_var=var_init('weight',dl_weight(:,:,:,:),td_dim=tl_dim(:),dd_fill=dl_fill) |
---|
| 476 | CALL file_add_var(tl_fileout, tl_var) |
---|
| 477 | CALL var_clean(tl_var) |
---|
| 478 | |
---|
[5214] | 479 | ! add some attribute |
---|
[4213] | 480 | tl_att=att_init("Created_by","SIREN merge_bathy") |
---|
| 481 | CALL file_add_att(tl_fileout, tl_att) |
---|
| 482 | |
---|
| 483 | cl_date=date_print(date_now()) |
---|
| 484 | tl_att=att_init("Creation_date",cl_date) |
---|
| 485 | CALL file_add_att(tl_fileout, tl_att) |
---|
| 486 | |
---|
| 487 | tl_att=att_init("coarse_grid_source_file",TRIM(fct_basename(tl_bathy0%c_name))) |
---|
| 488 | CALL file_add_att(tl_fileout, tl_att) |
---|
| 489 | |
---|
| 490 | tl_att=att_init("fine_grid_source_file",TRIM(fct_basename(tl_bathy1%c_name))) |
---|
| 491 | CALL file_add_att(tl_fileout, tl_att) |
---|
| 492 | |
---|
| 493 | ! add attribute periodicity |
---|
[5214] | 494 | il_attind=0 |
---|
[4213] | 495 | IF( ASSOCIATED(tl_fileout%t_att) )THEN |
---|
[5214] | 496 | il_attind=att_get_index(tl_fileout%t_att(:),'periodicity') |
---|
[4213] | 497 | ENDIF |
---|
[5214] | 498 | IF( tl_bathy1%i_perio >= 0 .AND. il_attind == 0 )THEN |
---|
[4213] | 499 | tl_att=att_init('periodicity',tl_bathy1%i_perio) |
---|
| 500 | CALL file_add_att(tl_fileout,tl_att) |
---|
| 501 | ENDIF |
---|
| 502 | |
---|
[5214] | 503 | il_attind=0 |
---|
[4213] | 504 | IF( ASSOCIATED(tl_fileout%t_att) )THEN |
---|
[5214] | 505 | il_attind=att_get_index(tl_fileout%t_att(:),'ew_overlap') |
---|
[4213] | 506 | ENDIF |
---|
[5214] | 507 | IF( tl_bathy1%i_ew >= 0 .AND. il_attind == 0 )THEN |
---|
[4213] | 508 | tl_att=att_init('ew_overlap',tl_bathy1%i_ew) |
---|
| 509 | CALL file_add_att(tl_fileout,tl_att) |
---|
| 510 | ENDIF |
---|
| 511 | |
---|
[5214] | 512 | ! create file |
---|
[4213] | 513 | CALL iom_create(tl_fileout) |
---|
| 514 | |
---|
[5214] | 515 | ! write file |
---|
[4213] | 516 | CALL iom_write_file(tl_fileout) |
---|
| 517 | |
---|
[5214] | 518 | ! close file |
---|
[4213] | 519 | CALL iom_close(tl_fileout) |
---|
| 520 | |
---|
[5214] | 521 | ! clean |
---|
| 522 | CALL att_clean(tl_att) |
---|
[4213] | 523 | CALL file_clean(tl_fileout) |
---|
[5214] | 524 | CALL mpp_clean(tl_bathy1) |
---|
| 525 | CALL mpp_clean(tl_bathy0) |
---|
[4213] | 526 | DEALLOCATE(dl_weight) |
---|
| 527 | |
---|
| 528 | ! close log file |
---|
| 529 | CALL logger_footer() |
---|
| 530 | CALL logger_close() |
---|
| 531 | |
---|
| 532 | CONTAINS |
---|
| 533 | !------------------------------------------------------------------- |
---|
| 534 | !> @brief |
---|
[5214] | 535 | !> This subroutine compute refined bathymetry on boundary from coarse grid. |
---|
[4213] | 536 | !> |
---|
| 537 | !> @author J.Paul |
---|
[5214] | 538 | !> @date November, 2013 - Initial Version |
---|
[4213] | 539 | !> |
---|
[5214] | 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 |
---|
[4213] | 547 | !------------------------------------------------------------------- |
---|
| 548 | SUBROUTINE merge_bathy_get_boundary( td_bathy0, td_bathy1, td_bdy, & |
---|
| 549 | & id_rho, & |
---|
| 550 | & dd_refined, dd_weight, dd_fill ) |
---|
| 551 | |
---|
| 552 | IMPLICIT NONE |
---|
| 553 | |
---|
| 554 | ! Argument |
---|
[5214] | 555 | TYPE(TMPP) , INTENT(IN ) :: td_bathy0 |
---|
| 556 | TYPE(TMPP) , INTENT(IN ) :: td_bathy1 |
---|
[4213] | 557 | TYPE(TBDY) , INTENT(IN ) :: td_bdy |
---|
| 558 | INTEGER(i4), DIMENSION(:) , INTENT(IN ) :: id_rho |
---|
| 559 | REAL(dp) , DIMENSION(:,:,:,:), INTENT(INOUT) :: dd_refined |
---|
| 560 | REAL(dp) , DIMENSION(:,:,:,:), INTENT(INOUT) :: dd_weight |
---|
| 561 | REAL(dp) , INTENT(IN ) :: dd_fill |
---|
| 562 | |
---|
| 563 | ! local variable |
---|
| 564 | INTEGER(i4) :: il_imin1 |
---|
| 565 | INTEGER(i4) :: il_imax1 |
---|
| 566 | INTEGER(i4) :: il_jmin1 |
---|
| 567 | INTEGER(i4) :: il_jmax1 |
---|
| 568 | |
---|
| 569 | INTEGER(i4) :: il_imin0 |
---|
| 570 | INTEGER(i4) :: il_imax0 |
---|
| 571 | INTEGER(i4) :: il_jmin0 |
---|
| 572 | INTEGER(i4) :: il_jmax0 |
---|
| 573 | |
---|
| 574 | INTEGER(i4), DIMENSION(2,2) :: il_offset |
---|
[5214] | 575 | INTEGER(i4), DIMENSION(2,2) :: il_ind |
---|
[4213] | 576 | |
---|
| 577 | REAL(dp) , DIMENSION(:) , ALLOCATABLE :: dl_tmp1d |
---|
| 578 | REAL(dp) , DIMENSION(:,:) , ALLOCATABLE :: dl_tmp2d |
---|
| 579 | REAL(dp) , DIMENSION(:,:) , ALLOCATABLE :: dl_wseg |
---|
| 580 | |
---|
| 581 | TYPE(TVAR) :: tl_var0 |
---|
| 582 | TYPE(TVAR) :: tl_lon1 |
---|
| 583 | TYPE(TVAR) :: tl_lat1 |
---|
| 584 | |
---|
[5214] | 585 | TYPE(TMPP) :: tl_bathy1 |
---|
| 586 | TYPE(TMPP) :: tl_bathy0 |
---|
[4213] | 587 | |
---|
| 588 | TYPE(TDOM) :: tl_dom1 |
---|
| 589 | TYPE(TDOM) :: tl_dom0 |
---|
| 590 | |
---|
| 591 | ! loop indices |
---|
| 592 | INTEGER(i4) :: ji |
---|
| 593 | INTEGER(i4) :: jl |
---|
| 594 | !---------------------------------------------------------------- |
---|
| 595 | |
---|
| 596 | IF( td_bdy%l_use )THEN |
---|
| 597 | DO jl=1,td_bdy%i_nseg |
---|
[5214] | 598 | ! get boundary definition |
---|
[4213] | 599 | SELECT CASE(TRIM(td_bdy%c_card)) |
---|
| 600 | CASE('north') |
---|
| 601 | |
---|
| 602 | il_imin1=td_bdy%t_seg(jl)%i_first |
---|
| 603 | il_imax1=td_bdy%t_seg(jl)%i_last |
---|
| 604 | il_jmin1=td_bdy%t_seg(jl)%i_index-(td_bdy%t_seg(jl)%i_width-1) |
---|
| 605 | il_jmax1=td_bdy%t_seg(jl)%i_index |
---|
| 606 | |
---|
| 607 | CASE('south') |
---|
| 608 | |
---|
| 609 | il_imin1=td_bdy%t_seg(jl)%i_first |
---|
| 610 | il_imax1=td_bdy%t_seg(jl)%i_last |
---|
| 611 | il_jmin1=td_bdy%t_seg(jl)%i_index |
---|
| 612 | il_jmax1=td_bdy%t_seg(jl)%i_index+(td_bdy%t_seg(jl)%i_width-1) |
---|
| 613 | |
---|
| 614 | CASE('east') |
---|
| 615 | |
---|
| 616 | il_imin1=td_bdy%t_seg(jl)%i_index-(td_bdy%t_seg(jl)%i_width-1) |
---|
| 617 | il_imax1=td_bdy%t_seg(jl)%i_index |
---|
| 618 | il_jmin1=td_bdy%t_seg(jl)%i_first |
---|
| 619 | il_jmax1=td_bdy%t_seg(jl)%i_last |
---|
| 620 | |
---|
| 621 | CASE('west') |
---|
| 622 | |
---|
| 623 | il_imin1=td_bdy%t_seg(jl)%i_index |
---|
| 624 | il_imax1=td_bdy%t_seg(jl)%i_index+(td_bdy%t_seg(jl)%i_width-1) |
---|
| 625 | il_jmin1=td_bdy%t_seg(jl)%i_first |
---|
| 626 | il_jmax1=td_bdy%t_seg(jl)%i_last |
---|
| 627 | |
---|
| 628 | END SELECT |
---|
| 629 | |
---|
[5214] | 630 | ! -read fine grid domain |
---|
| 631 | tl_bathy1=mpp_copy(td_bathy1) |
---|
[4213] | 632 | |
---|
[5214] | 633 | ! compute domain |
---|
[4213] | 634 | tl_dom1=dom_init( tl_bathy1, & |
---|
| 635 | & il_imin1, il_imax1,& |
---|
[5214] | 636 | & il_jmin1, il_jmax1,& |
---|
| 637 | & TRIM(td_bdy%c_card)) |
---|
[4213] | 638 | |
---|
[5214] | 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)) |
---|
[4213] | 642 | |
---|
[5214] | 643 | ! open mpp files over domain |
---|
| 644 | CALL iom_dom_open(tl_bathy1, tl_dom1) |
---|
[4213] | 645 | |
---|
[5214] | 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) |
---|
[4213] | 649 | |
---|
[5214] | 650 | ! close mpp files |
---|
| 651 | CALL iom_dom_close(tl_bathy1) |
---|
[4213] | 652 | |
---|
[5214] | 653 | ! clean structure |
---|
| 654 | CALL mpp_clean(tl_bathy1) |
---|
[4213] | 655 | |
---|
[5214] | 656 | ! get coarse grid indices |
---|
| 657 | il_ind(:,:)=grid_get_coarse_index(td_bathy0, tl_lon1, tl_lat1, & |
---|
| 658 | & id_rho=id_rho(:)) |
---|
[4213] | 659 | |
---|
[5214] | 660 | il_imin0=il_ind(1,1) |
---|
| 661 | il_imax0=il_ind(1,2) |
---|
[4213] | 662 | |
---|
[5214] | 663 | il_jmin0=il_ind(2,1) |
---|
| 664 | il_jmax0=il_ind(2,2) |
---|
[4213] | 665 | |
---|
[5214] | 666 | ! read coarse grid bathymetry on domain |
---|
| 667 | tl_bathy0=mpp_copy(td_bathy0) |
---|
[4213] | 668 | |
---|
[5214] | 669 | ! compute domain |
---|
[4213] | 670 | tl_dom0=dom_init( tl_bathy0, & |
---|
| 671 | & il_imin0, il_imax0,& |
---|
| 672 | & il_jmin0, il_jmax0 ) |
---|
| 673 | |
---|
[5214] | 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(:)) |
---|
[4213] | 680 | |
---|
[5214] | 681 | ! clean |
---|
| 682 | CALL var_clean(tl_lon1) |
---|
| 683 | CALL var_clean(tl_lat1) |
---|
| 684 | |
---|
| 685 | ! add extra band (if possible) to compute interpolation |
---|
[4213] | 686 | CALL dom_add_extra(tl_dom0) |
---|
| 687 | |
---|
[5214] | 688 | ! open mpp files over domain |
---|
| 689 | CALL iom_dom_open(tl_bathy0, tl_dom0) |
---|
[4213] | 690 | |
---|
[5214] | 691 | ! read variable value on domain |
---|
| 692 | tl_var0=iom_dom_read_var(tl_bathy0,'Bathymetry',tl_dom0) |
---|
[4213] | 693 | |
---|
[5214] | 694 | ! close mpp files |
---|
| 695 | CALL iom_dom_close(tl_bathy0) |
---|
[4213] | 696 | |
---|
[5214] | 697 | ! clean structure |
---|
| 698 | CALL mpp_clean(tl_bathy0) |
---|
[4213] | 699 | |
---|
[5214] | 700 | ! interpolate variable |
---|
[4213] | 701 | CALL merge_bathy_interp( tl_var0, & |
---|
| 702 | & id_rho(:), & |
---|
| 703 | & il_offset(:,:) ) |
---|
| 704 | |
---|
[5214] | 705 | ! remove extraband added to domain |
---|
[4213] | 706 | CALL dom_del_extra( tl_var0, tl_dom0, id_rho(:) ) |
---|
| 707 | |
---|
[5214] | 708 | ! remove extraband added to domain |
---|
[4213] | 709 | CALL dom_clean_extra( tl_dom0 ) |
---|
| 710 | |
---|
[5214] | 711 | ! remove extraband added to fine grid domain |
---|
| 712 | CALL dom_del_extra( tl_var0, tl_dom1 ) |
---|
[4213] | 713 | |
---|
[5214] | 714 | ! remove extraband added to fine grid domain |
---|
| 715 | CALL dom_clean_extra( tl_dom1 ) |
---|
[4213] | 716 | |
---|
[5214] | 717 | ! fill refined array |
---|
[4213] | 718 | dd_refined( il_imin1:il_imax1, & |
---|
| 719 | & il_jmin1:il_jmax1, & |
---|
| 720 | & :,: )= tl_var0%d_value(:,:,:,:) |
---|
| 721 | |
---|
[5214] | 722 | ! clean |
---|
| 723 | CALL var_clean(tl_var0) |
---|
| 724 | |
---|
| 725 | ! compute weight function |
---|
[4213] | 726 | ALLOCATE( dl_tmp1d(td_bdy%t_seg(jl)%i_width) ) |
---|
| 727 | |
---|
| 728 | SELECT CASE(TRIM(td_bdy%c_card)) |
---|
| 729 | CASE('north') |
---|
| 730 | |
---|
| 731 | ! compute "distance" |
---|
| 732 | dl_tmp1d(:)=(/(ji-1,ji=td_bdy%t_seg(jl)%i_width,1,-1)/) |
---|
| 733 | |
---|
| 734 | ! compute weight on segment |
---|
[5214] | 735 | dl_tmp1d(:)= 0.5 + 0.5*COS( (dp_pi*dl_tmp1d(:)) / & |
---|
[4213] | 736 | & (td_bdy%t_seg(jl)%i_width) ) |
---|
| 737 | |
---|
| 738 | ALLOCATE( dl_wseg(tl_dom1%t_dim(1)%i_len, & |
---|
| 739 | & tl_dom1%t_dim(2)%i_len) ) |
---|
| 740 | dl_wseg(:,:)=dd_fill |
---|
| 741 | dl_wseg(:,:)=SPREAD( dl_tmp1d(:), & |
---|
| 742 | & DIM=1, & |
---|
| 743 | & NCOPIES=tl_dom1%t_dim(1)%i_len ) |
---|
| 744 | |
---|
| 745 | CASE('south') |
---|
| 746 | |
---|
| 747 | ! compute "distance" |
---|
| 748 | dl_tmp1d(:)=(/(ji-1,ji=1,td_bdy%t_seg(jl)%i_width)/) |
---|
| 749 | |
---|
| 750 | ! compute weight on segment |
---|
[5214] | 751 | dl_tmp1d(:)= 0.5 + 0.5*COS( (dp_pi*dl_tmp1d(:)) / & |
---|
[4213] | 752 | & (td_bdy%t_seg(jl)%i_width) ) |
---|
| 753 | |
---|
| 754 | ALLOCATE( dl_wseg(tl_dom1%t_dim(1)%i_len, & |
---|
| 755 | & tl_dom1%t_dim(2)%i_len) ) |
---|
| 756 | dl_wseg(:,:)=dd_fill |
---|
| 757 | dl_wseg(:,:)=SPREAD( dl_tmp1d(:), & |
---|
| 758 | & DIM=1, & |
---|
| 759 | & NCOPIES=tl_dom1%t_dim(1)%i_len ) |
---|
| 760 | |
---|
| 761 | CASE('east') |
---|
| 762 | |
---|
| 763 | ! compute "distance" |
---|
| 764 | dl_tmp1d(:)=(/(ji-1,ji=td_bdy%t_seg(jl)%i_width,1,-1)/) |
---|
| 765 | |
---|
| 766 | ! compute weight on segment |
---|
[5214] | 767 | dl_tmp1d(:)= 0.5 + 0.5*COS( (dp_pi*dl_tmp1d(:)) / & |
---|
[4213] | 768 | & (td_bdy%t_seg(jl)%i_width) ) |
---|
| 769 | |
---|
| 770 | ALLOCATE( dl_wseg(tl_dom1%t_dim(1)%i_len, & |
---|
| 771 | & tl_dom1%t_dim(2)%i_len) ) |
---|
| 772 | dl_wseg(:,:)=dd_fill |
---|
| 773 | dl_wseg(:,:)=SPREAD( dl_tmp1d(:), & |
---|
| 774 | & DIM=2, & |
---|
| 775 | & NCOPIES=tl_dom1%t_dim(2)%i_len ) |
---|
| 776 | |
---|
| 777 | CASE('west') |
---|
| 778 | |
---|
| 779 | ! compute "distance" |
---|
| 780 | dl_tmp1d(:)=(/(ji-1,ji=1,td_bdy%t_seg(jl)%i_width)/) |
---|
| 781 | |
---|
| 782 | ! compute weight on segment |
---|
[5214] | 783 | dl_tmp1d(:)= 0.5 + 0.5*COS( (dp_pi*dl_tmp1d(:)) / & |
---|
[4213] | 784 | & (td_bdy%t_seg(jl)%i_width) ) |
---|
| 785 | |
---|
| 786 | ALLOCATE( dl_wseg(tl_dom1%t_dim(1)%i_len, & |
---|
| 787 | & tl_dom1%t_dim(2)%i_len) ) |
---|
| 788 | dl_wseg(:,:)=dd_fill |
---|
| 789 | dl_wseg(:,:)=SPREAD( dl_tmp1d(:), & |
---|
| 790 | & DIM=2, & |
---|
| 791 | & NCOPIES=tl_dom1%t_dim(2)%i_len ) |
---|
| 792 | |
---|
| 793 | END SELECT |
---|
| 794 | |
---|
| 795 | DEALLOCATE( dl_tmp1d ) |
---|
| 796 | |
---|
[5214] | 797 | ! fill weight array |
---|
[4213] | 798 | ALLOCATE( dl_tmp2d( tl_dom1%t_dim(1)%i_len, & |
---|
| 799 | & tl_dom1%t_dim(2)%i_len) ) |
---|
| 800 | |
---|
| 801 | dl_tmp2d(:,:)=dd_weight( il_imin1:il_imax1, & |
---|
| 802 | & il_jmin1:il_jmax1, & |
---|
| 803 | & 1,1 ) |
---|
| 804 | |
---|
| 805 | WHERE( dl_tmp2d(:,:) == dd_fill ) |
---|
| 806 | dl_tmp2d(:,:)= dl_wseg(:,:) |
---|
| 807 | ELSE WHERE |
---|
| 808 | dl_tmp2d(:,:)= MAX( dl_tmp2d(:,:), dl_wseg(:,:) ) |
---|
| 809 | END WHERE |
---|
| 810 | |
---|
| 811 | dd_weight( il_imin1:il_imax1, & |
---|
| 812 | & il_jmin1:il_jmax1, & |
---|
| 813 | & 1,1 ) = dl_tmp2d(:,:) |
---|
| 814 | |
---|
| 815 | DEALLOCATE( dl_wseg ) |
---|
| 816 | DEALLOCATE( dl_tmp2d ) |
---|
| 817 | |
---|
| 818 | ENDDO |
---|
| 819 | ENDIF |
---|
| 820 | END SUBROUTINE merge_bathy_get_boundary |
---|
| 821 | !------------------------------------------------------------------- |
---|
| 822 | !> @brief |
---|
[5214] | 823 | !> This subroutine interpolate variable. |
---|
[4213] | 824 | !> |
---|
| 825 | !> @author J.Paul |
---|
[5214] | 826 | !> @date November, 2013 - Initial Version |
---|
[4213] | 827 | !> |
---|
[5214] | 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) |
---|
[4213] | 833 | !------------------------------------------------------------------- |
---|
| 834 | SUBROUTINE merge_bathy_interp( td_var, & |
---|
| 835 | & id_rho, & |
---|
| 836 | & id_offset, & |
---|
| 837 | & id_iext, id_jext) |
---|
| 838 | |
---|
| 839 | IMPLICIT NONE |
---|
| 840 | |
---|
| 841 | ! Argument |
---|
| 842 | TYPE(TVAR) , INTENT(INOUT) :: td_var |
---|
| 843 | INTEGER(i4), DIMENSION(:) , INTENT(IN ) :: id_rho |
---|
| 844 | INTEGER(i4), DIMENSION(:,:), INTENT(IN ) :: id_offset |
---|
| 845 | INTEGER(i4), INTENT(IN ), OPTIONAL :: id_iext |
---|
| 846 | INTEGER(i4), INTENT(IN ), OPTIONAL :: id_jext |
---|
| 847 | |
---|
| 848 | ! local variable |
---|
| 849 | TYPE(TVAR) :: tl_mask |
---|
| 850 | |
---|
| 851 | INTEGER(i1), DIMENSION(:,:,:,:), ALLOCATABLE :: bl_mask |
---|
| 852 | |
---|
| 853 | INTEGER(i4) :: il_iext |
---|
| 854 | INTEGER(i4) :: il_jext |
---|
| 855 | |
---|
| 856 | ! loop indices |
---|
| 857 | !---------------------------------------------------------------- |
---|
| 858 | |
---|
| 859 | !WARNING: two extrabands are required for cubic interpolation |
---|
| 860 | il_iext=3 |
---|
| 861 | IF( PRESENT(id_iext) ) il_iext=id_iext |
---|
| 862 | |
---|
| 863 | il_jext=3 |
---|
| 864 | IF( PRESENT(id_jext) ) il_jext=id_jext |
---|
| 865 | |
---|
| 866 | IF( il_iext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN |
---|
[5214] | 867 | CALL logger_warn("MERGE BATHY INTERP: at least extrapolation "//& |
---|
[4213] | 868 | & "on two points are required with cubic interpolation ") |
---|
| 869 | il_iext=2 |
---|
| 870 | ENDIF |
---|
| 871 | |
---|
| 872 | IF( il_jext < 2 .AND. td_var%c_interp(1) == 'cubic' )THEN |
---|
[5214] | 873 | CALL logger_warn("MERGE BATHY INTERP: at least extrapolation "//& |
---|
[4213] | 874 | & "on two points are required with cubic interpolation ") |
---|
| 875 | il_jext=2 |
---|
| 876 | ENDIF |
---|
| 877 | |
---|
[5214] | 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) ) |
---|
[4213] | 884 | |
---|
| 885 | bl_mask(:,:,:,:)=1 |
---|
[5214] | 886 | WHERE(td_var%d_value(:,:,:,:)==td_var%d_fill) bl_mask(:,:,:,:)=0 |
---|
[4213] | 887 | |
---|
[5214] | 888 | SELECT CASE(TRIM(td_var%c_point)) |
---|
[4213] | 889 | CASE DEFAULT ! 'T' |
---|
[5214] | 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.") |
---|
[4213] | 897 | END SELECT |
---|
| 898 | |
---|
| 899 | DEALLOCATE(bl_mask) |
---|
| 900 | |
---|
[5214] | 901 | ! interpolate mask |
---|
[4213] | 902 | CALL interp_fill_value( tl_mask, id_rho(:), & |
---|
| 903 | & id_offset=id_offset(:,:) ) |
---|
| 904 | |
---|
[5214] | 905 | ! work on variable |
---|
| 906 | ! add extraband |
---|
| 907 | CALL extrap_add_extrabands(td_var, il_iext, il_iext) |
---|
[4213] | 908 | |
---|
[5214] | 909 | ! extrapolate variable |
---|
| 910 | CALL extrap_fill_value( td_var, id_offset=id_offset(:,:), & |
---|
[4213] | 911 | & id_rho=id_rho(:), & |
---|
| 912 | & id_iext=il_iext, id_jext=il_jext ) |
---|
| 913 | |
---|
[5214] | 914 | ! interpolate Bathymetry |
---|
| 915 | CALL interp_fill_value( td_var, id_rho(:), & |
---|
[4213] | 916 | & id_offset=id_offset(:,:) ) |
---|
| 917 | |
---|
[5214] | 918 | ! remove extraband |
---|
| 919 | CALL extrap_del_extrabands(td_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J)) |
---|
[4213] | 920 | |
---|
[5214] | 921 | ! keep original mask |
---|
[4213] | 922 | WHERE( tl_mask%d_value(:,:,:,:) == 0 ) |
---|
[5214] | 923 | td_var%d_value(:,:,:,:)=td_var%d_fill |
---|
[4213] | 924 | END WHERE |
---|
| 925 | |
---|
| 926 | END SUBROUTINE merge_bathy_interp |
---|
| 927 | END PROGRAM merge_bathy |
---|