Changeset 6225 for branches/2014/dev_r4704_NOC5_MPP_BDY_UPDATE/NEMOGCM/TOOLS/SIREN/src/create_bathy.f90
- Timestamp:
- 2016-01-08T10:35:19+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2014/dev_r4704_NOC5_MPP_BDY_UPDATE/NEMOGCM/TOOLS/SIREN/src/create_bathy.f90
r4213 r6225 3 3 !---------------------------------------------------------------------- 4 4 ! 5 !6 5 ! PROGRAM: create_bathy 7 6 ! 8 7 ! DESCRIPTION: 8 !> @file 9 9 !> @brief 10 !> This program create bathymetry file.10 !> This program create fine grid bathymetry file. 11 11 !> 12 12 !> @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 18 121 ! 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. 20 129 ! 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 !> 21 135 !> @note Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) 22 !>23 !> @todo24 !> - add attributes indices and refinement in output file25 136 !---------------------------------------------------------------------- 26 !> @code27 137 PROGRAM create_bathy 28 138 29 ! USE netcdf ! nf90 library30 139 USE global ! global variable 31 140 USE kind ! F90 kind parameter … … 39 148 USE multi ! multi file manager 40 149 USE iom ! I/O manager 41 USE dom ! domain manager42 150 USE grid ! grid manager 43 151 USE extrap ! extrapolation manager … … 45 153 USE filter ! filter manager 46 154 USE mpp ! MPP manager 155 USE dom ! domain manager 47 156 USE iom_mpp ! MPP I/O manager 157 USE iom_dom ! DOM I/O manager 48 158 49 159 IMPLICIT NONE … … 57 167 INTEGER(i4) :: il_status 58 168 INTEGER(i4) :: il_fileid 169 INTEGER(i4) :: il_varid 59 170 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 64 175 INTEGER(i4) , DIMENSION(ip_maxdim) :: il_rho 65 176 INTEGER(i4) , DIMENSION(2,2) :: il_offset 66 INTEGER(i4) , DIMENSION(2,2 ,2):: il_ind177 INTEGER(i4) , DIMENSION(2,2) :: il_ind 67 178 INTEGER(i4) , DIMENSION(:,:) , ALLOCATABLE :: il_mask 68 179 69 180 LOGICAL :: ll_exist 70 181 71 TYPE(T FILE):: tl_coord072 TYPE(T FILE):: tl_coord173 TYPE(T FILE) :: tl_file182 TYPE(TMPP) :: tl_coord0 183 TYPE(TMPP) :: tl_coord1 184 TYPE(TMPP) :: tl_mpp 74 185 TYPE(TFILE) :: tl_fileout 75 186 … … 88 199 TYPE(TMULTI) :: tl_multi 89 200 201 REAL(dp) :: dl_minbat 202 90 203 ! loop indices 91 204 INTEGER(i4) :: ji … … 94 207 95 208 ! namelist variable 209 ! namlog 96 210 CHARACTER(LEN=lc) :: cn_logfile = 'create_bathy.log' 97 211 CHARACTER(LEN=lc) :: cn_verbosity = 'warning' 98 212 INTEGER(i4) :: in_maxerror = 5 213 214 ! namcfg 99 215 CHARACTER(LEN=lc) :: cn_varcfg = 'variable.cfg' 100 216 217 ! namcrs 101 218 CHARACTER(LEN=lc) :: cn_coord0 = '' 102 219 INTEGER(i4) :: in_perio0 = -1 103 220 221 ! namfin 104 222 CHARACTER(LEN=lc) :: cn_coord1 = '' 105 223 INTEGER(i4) :: in_perio1 = -1 106 224 LOGICAL :: ln_fillclosed = .TRUE. 107 225 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 115 231 INTEGER(i4) :: in_rhoi = 1 116 232 INTEGER(i4) :: in_rhoj = 1 117 233 234 ! namout 118 235 CHARACTER(LEN=lc) :: cn_fileout = 'bathy_fine.nc' 119 236 !------------------------------------------------------------------- 120 237 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 127 245 128 246 NAMELIST /namcrs/ & !< coarse grid namelist … … 135 253 & ln_fillclosed !< fill closed sea 136 254 137 NAMELIST /namvar/ & !< variable namelist138 & cn_varinfo, & !< list of variable and interpolation method to be used. (ex: 'votemper:linear','vosaline:cubic' )139 & cn_varfile !< list of variable file255 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 140 258 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 151 265 !------------------------------------------------------------------- 152 266 153 ! 1-namelist154 ! 1-1get namelist267 ! namelist 268 ! get namelist 155 269 il_narg=COMMAND_ARGUMENT_COUNT() !f03 intrinsec 156 270 IF( il_narg/=1 )THEN … … 160 274 CALL GET_COMMAND_ARGUMENT(1,cl_namelist) !f03 intrinsec 161 275 ENDIF 162 163 ! 1-2read namelist276 277 ! read namelist 164 278 INQUIRE(FILE=TRIM(cl_namelist), EXIST=ll_exist) 165 279 IF( ll_exist )THEN 166 280 167 281 il_fileid=fct_getunit() 168 282 … … 180 294 181 295 READ( il_fileid, NML = namlog ) 182 ! 1-2-1define log file183 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) 184 298 CALL logger_header() 185 299 186 300 READ( il_fileid, NML = namcfg ) 187 ! 1-2-2get variable extra information301 ! get variable extra information 188 302 CALL var_def_extra(TRIM(cn_varcfg)) 189 303 … … 191 305 READ( il_fileid, NML = namfin ) 192 306 READ( il_fileid, NML = namvar ) 193 ! 1-2-3add user change in extra information194 CALL var_chg_extra( cn_varinfo)195 ! 1-2-4match variable with file307 ! add user change in extra information 308 CALL var_chg_extra( cn_varinfo ) 309 ! match variable with file 196 310 tl_multi=multi_init(cn_varfile) 197 311 … … 211 325 ENDIF 212 326 213 !2- open files 327 CALL multi_print(tl_multi) 328 329 ! open files 214 330 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) 217 333 ELSE 218 334 CALL logger_fatal("CREATE BATHY: no coarse grid coordinate found. "//& … … 221 337 222 338 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) 225 341 ELSE 226 342 CALL logger_fatal("CREATE BATHY: no fine grid coordinate found. "//& … … 228 344 ENDIF 229 345 230 ! 3-check231 ! 3-1check output file do not already exist346 ! check 347 ! check output file do not already exist 232 348 INQUIRE(FILE=TRIM(cn_fileout), EXIST=ll_exist) 233 349 IF( ll_exist )THEN … … 236 352 ENDIF 237 353 238 ! 3-2check namelist239 ! 3-2-1check refinement factor354 ! check namelist 355 ! check refinement factor 240 356 il_rho(:)=1 241 357 IF( in_rhoi < 1 .OR. in_rhoj < 1 )THEN … … 247 363 ENDIF 248 364 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. "//& 285 384 & "check cn_varfile in namelist.") 286 385 ELSE 386 287 387 ALLOCATE( tl_var( tl_multi%i_nvar ) ) 288 388 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)//& 294 396 & ". 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 297 402 jk=jk+1 298 tl_tmp= tl_multi%t_file(ji)%t_var(jj)299 !- use input matrix to initialise variable403 tl_tmp=var_copy(tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj)) 404 300 405 tl_var(jk)=create_bathy_matrix(tl_tmp, tl_coord1) 301 406 ENDDO 407 ! clean 408 CALL var_clean(tl_tmp) 409 302 410 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) 306 417 307 418 ! 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 309 421 IF( ASSOCIATED(tl_depth%d_value) )THEN 422 tl_tmp=iom_mpp_read_var(tl_mpp,il_varid) 310 423 IF( ANY( tl_depth%d_value(:,:,:,:) /= & 311 424 & tl_tmp%d_value(:,:,:,:) ) )THEN 312 425 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 "//& 314 427 & " to those from former file(s).") 315 428 ENDIF 429 CALL var_clean(tl_tmp) 316 430 ELSE 317 tl_depth=iom_ read_var(tl_file,tl_file%i_depthid)431 tl_depth=iom_mpp_read_var(tl_mpp,il_varid) 318 432 ENDIF 319 433 ENDIF 320 434 321 435 ! 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 323 438 IF( ASSOCIATED(tl_time%d_value) )THEN 439 tl_tmp=iom_mpp_read_var(tl_mpp,il_varid) 324 440 IF( ANY( tl_time%d_value(:,:,:,:) /= & 325 441 & tl_tmp%d_value(:,:,:,:) ) )THEN 326 442 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 "//& 328 444 & " to those from former file(s).") 329 445 ENDIF 446 CALL var_clean(tl_tmp) 330 447 ELSE 331 tl_time=iom_ read_var(tl_file,tl_file%i_timeid)448 tl_time=iom_mpp_read_var(tl_mpp,il_varid) 332 449 ENDIF 333 450 ENDIF 334 451 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 338 459 jk=jk+1 339 tl_tmp= tl_multi%t_file(ji)%t_var(jj)340 !- extract bathymetry from fine grid bathymetry341 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, & 342 463 & tl_coord1 ) 343 464 ENDDO 465 ! clean 466 CALL var_clean(tl_tmp) 344 467 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 346 470 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(:,:), & 353 484 & il_rho(:) ) 354 485 ENDDO 486 ! clean 487 CALL var_clean(tl_tmp) 355 488 ENDIF 356 489 357 ! close file358 CALL iom_close(tl_file)359 490 ! clean structure 360 CALL file_clean(tl_file) 491 CALL mpp_clean(tl_mpp) 492 361 493 ENDIF 362 494 ENDDO 363 495 ENDIF 364 496 497 ! use additional request 365 498 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 367 504 CALL var_limit_value(tl_var(jk)) 368 505 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 372 508 ALLOCATE( il_mask(tl_var(jk)%t_dim(1)%i_len, & 373 509 & tl_var(jk)%t_dim(2)%i_len) ) 374 510 375 ! 7-1split domain in N sea subdomain511 ! split domain in N sea subdomain 376 512 il_mask(:,:)=grid_split_domain(tl_var(jk)) 377 513 378 ! 7-2fill smallest domain514 ! fill smallest domain 379 515 CALL grid_fill_small_dom( tl_var(jk), il_mask(:,:) ) 380 516 … … 382 518 ENDIF 383 519 384 ! 8-filter520 ! filter 385 521 CALL filter_fill_value(tl_var(jk)) 386 522 387 !9- check bathymetry 523 ! check bathymetry 524 dl_minbat=MINVAL(tl_var(jk)%d_value(:,:,:,:)) 388 525 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))) 390 528 CALL logger_error("CREATE BATHY: Bathymetry has value <= 0") 391 529 ENDIF 530 392 531 ENDDO 393 532 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 399 537 tl_dim(:)=var_max_dim(tl_var(:)) 400 538 … … 403 541 ENDDO 404 542 405 ! 10-2add variables543 ! add variables 406 544 IF( ALL( tl_dim(1:2)%l_use ) )THEN 407 545 546 ! open mpp files 547 CALL iom_mpp_open(tl_coord1) 548 408 549 ! add longitude 409 tl_lon=iom_ read_var(tl_coord1,'longitude')550 tl_lon=iom_mpp_read_var(tl_coord1,'longitude') 410 551 CALL file_add_var(tl_fileout, tl_lon) 411 552 CALL var_clean(tl_lon) 412 553 413 554 ! add latitude 414 tl_lat=iom_ read_var(tl_coord1,'latitude')555 tl_lat=iom_mpp_read_var(tl_coord1,'latitude') 415 556 CALL file_add_var(tl_fileout, tl_lat) 416 557 CALL var_clean(tl_lat) 558 559 ! close mpp files 560 CALL iom_mpp_close(tl_coord1) 417 561 418 562 ENDIF … … 431 575 432 576 ! add other variables 433 DO jk= 1,tl_multi%i_nvar577 DO jk=tl_multi%i_nvar,1,-1 434 578 CALL file_add_var(tl_fileout, tl_var(jk)) 435 579 CALL var_clean(tl_var(jk)) 436 580 ENDDO 437 438 !10-3 add some attribute 581 DEALLOCATE(tl_var) 582 583 ! add some attribute 439 584 tl_att=att_init("Created_by","SIREN create_bathy") 440 585 CALL file_add_att(tl_fileout, tl_att) … … 447 592 il_attid=0 448 593 IF( ASSOCIATED(tl_fileout%t_att) )THEN 449 il_attid=att_get_i d(tl_fileout%t_att(:),'periodicity')594 il_attid=att_get_index(tl_fileout%t_att(:),'periodicity') 450 595 ENDIF 451 596 IF( tl_coord1%i_perio >= 0 .AND. il_attid == 0 )THEN … … 454 599 ENDIF 455 600 601 ! add attribute east west overlap 456 602 il_attid=0 457 603 IF( ASSOCIATED(tl_fileout%t_att) )THEN 458 il_attid=att_get_i d(tl_fileout%t_att(:),'ew_overlap')604 il_attid=att_get_index(tl_fileout%t_att(:),'ew_overlap') 459 605 ENDIF 460 606 IF( tl_coord1%i_ew >= 0 .AND. il_attid == 0 )THEN … … 462 608 CALL file_add_att(tl_fileout,tl_att) 463 609 ENDIF 464 465 ! 10-4create file610 611 ! create file 466 612 CALL iom_create(tl_fileout) 467 613 468 ! 10-5write file614 ! write file 469 615 CALL iom_write_file(tl_fileout) 470 616 471 ! 10-6close file617 ! close file 472 618 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) 477 622 478 623 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) 481 626 482 627 ! close log file … … 484 629 CALL logger_close() 485 630 486 !> @endcode487 631 CONTAINS 488 632 !------------------------------------------------------------------- 489 633 !> @brief 490 !> This subroutine634 !> This function create variable, filled with matrix value 491 635 !> 492 636 !> @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. 493 641 !> 494 642 !> @author J.Paul 495 !> - Nov, 2013- Initial Version643 !> @date November, 2013 - Initial Version 496 644 !> 497 !> @param[in] 645 !> @param[in] td_var variable structure 646 !> @param[in] td_coord coordinate file structure 647 !> @return variable structure 498 648 !------------------------------------------------------------------- 499 !> @code500 649 FUNCTION create_bathy_matrix(td_var, td_coord) 501 650 IMPLICIT NONE 502 651 ! Argument 503 TYPE(TVAR) 504 TYPE(T FILE), INTENT(IN) :: td_coord652 TYPE(TVAR), INTENT(IN) :: td_var 653 TYPE(TMPP), INTENT(IN) :: td_coord 505 654 506 655 ! function … … 508 657 509 658 ! 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 513 660 INTEGER(i4) , DIMENSION(3) :: il_dim 514 661 INTEGER(i4) , DIMENSION(3) :: il_size … … 522 669 523 670 TYPE(TVAR) :: tl_lon 524 TYPE(TVAR) :: tl_lat525 TYPE(TVAR) :: tl_var526 671 TYPE(TDIM) , DIMENSION(ip_maxdim) :: tl_dim 672 673 TYPE(TMPP) :: tl_coord 527 674 528 675 ! loop indices … … 532 679 !---------------------------------------------------------------- 533 680 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 546 706 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 555 713 il_size(:) = tl_dim(1:3)%i_len / il_dim(:) 556 714 il_rest(:) = MOD(tl_dim(1:3)%i_len, il_dim(:)) … … 563 721 ! add rest to last cell 564 722 il_ishape(il_dim(1)+1)=il_ishape(il_dim(1)+1)+il_rest(1) 565 566 723 567 724 ALLOCATE( il_jshape(il_dim(2)+1) ) … … 581 738 il_kshape(il_dim(3)+1)=il_kshape(il_dim(3)+1)+il_rest(3) 582 739 583 ! 3-3 write ouput tableof value740 ! write ouput array of value 584 741 ALLOCATE(dl_value( tl_dim(1)%i_len, & 585 742 & tl_dim(2)%i_len, & … … 602 759 ENDDO 603 760 604 ! 3-4initialise variable with value605 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(:,:,:,:)) 606 763 607 764 DEALLOCATE(dl_value) 608 765 609 ! 4-add ghost cell610 CALL grid_add_ghost( tl_var,il_ighost,il_jghost)611 612 ! 5- save result613 create_bathy_matrix=tl_var766 ! add ghost cell 767 CALL grid_add_ghost(create_bathy_matrix, il_xghost(:,:)) 768 769 ! clean 770 CALL dim_clean(tl_dim(:)) 614 771 615 772 END FUNCTION create_bathy_matrix 616 !> @endcode617 773 !------------------------------------------------------------------- 618 774 !> @brief 619 !> This subroutine 775 !> This function extract variable from file over coordinate domain and 776 !> return variable structure 620 777 !> 621 !> @details 778 !> @author J.Paul 779 !> @date November, 2013 - Initial Version 622 780 !> 623 !> @ author J.Paul624 !> - Nov, 2013- Initial Version625 !> 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 627 785 !------------------------------------------------------------------- 628 !> @code 629 FUNCTION create_bathy_extract(td_var, td_file, & 786 FUNCTION create_bathy_extract(td_var, td_mpp, & 630 787 & td_coord) 631 788 IMPLICIT NONE 632 789 ! Argument 633 TYPE(TVAR) 634 TYPE(T FILE), INTENT(IN) :: td_file635 TYPE(T FILE), INTENT(IN) :: td_coord790 TYPE(TVAR), INTENT(IN) :: td_var 791 TYPE(TMPP), INTENT(IN) :: td_mpp 792 TYPE(TMPP), INTENT(IN) :: td_coord 636 793 637 794 ! function … … 639 796 640 797 ! 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 645 799 646 800 INTEGER(i4) :: il_imin … … 648 802 INTEGER(i4) :: il_imax 649 803 INTEGER(i4) :: il_jmax 650 651 TYPE(TFILE) :: tl_file652 804 653 805 TYPE(TMPP) :: tl_mpp … … 661 813 !---------------------------------------------------------------- 662 814 663 IF( td_file%i_id == 0)THEN664 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)) 666 818 ELSE 667 819 668 820 !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, & 692 831 & il_imin, il_imax, & 693 832 & il_jmin, il_jmax, & 694 833 & (/1, 1, 1/) ) 695 834 696 ! 4-compute domain697 tl_dom=dom_init(tl_ file,&835 ! compute domain 836 tl_dom=dom_init(tl_mpp, & 698 837 & il_imin, il_imax, & 699 838 & il_jmin, il_jmax) 700 839 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 726 853 IF( ANY( tl_var%t_dim(:)%l_use .AND. & 727 854 & tl_var%t_dim(:)%i_len /= td_coord%t_dim(:)%i_len) )THEN … … 743 870 ENDIF 744 871 745 ! 8-add attribute to variable872 ! add attribute to variable 746 873 tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name))) 747 874 CALL var_move_att(tl_var, tl_att) 748 875 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/)) 750 877 CALL var_move_att(tl_var, tl_att) 751 878 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/)) 753 880 CALL var_move_att(tl_var, tl_att) 754 881 755 ! 9-save result756 create_bathy_extract= tl_var882 ! save result 883 create_bathy_extract=var_copy(tl_var) 757 884 758 885 ! clean structure 886 CALL att_clean(tl_att) 759 887 CALL var_clean(tl_var) 760 888 CALL mpp_clean(tl_mpp) … … 762 890 763 891 END FUNCTION create_bathy_extract 764 !> @endcode765 892 !------------------------------------------------------------------- 766 893 !> @brief 767 !> This subroutine 894 !> This function get coarse grid variable, interpolate variable, and return 895 !> variable structure over fine grid 768 896 !> 769 !> @details 897 !> @author J.Paul 898 !> @date November, 2013 - Initial Version 770 899 !> 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 781 909 !------------------------------------------------------------------- 782 !> @code 783 FUNCTION create_bathy_get_var(td_var, td_file, & 910 FUNCTION create_bathy_get_var(td_var, td_mpp, & 784 911 & id_imin, id_jmin, & 785 912 & id_imax, id_jmax, & … … 788 915 IMPLICIT NONE 789 916 ! Argument 790 TYPE(TVAR) , INTENT(IN) :: td_var791 TYPE(T FILE), INTENT(IN) :: td_file792 INTEGER(i4) , INTENT(IN) :: id_imin793 INTEGER(i4) , INTENT(IN) :: id_imax794 INTEGER(i4) , INTENT(IN) :: id_jmin795 INTEGER(i4) , INTENT(IN) :: id_jmax917 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 796 923 INTEGER(i4), DIMENSION(:,:), INTENT(IN) :: id_offset 797 924 INTEGER(i4), DIMENSION(:) , INTENT(IN) :: id_rho … … 801 928 802 929 ! local variable 803 INTEGER(i4) :: il_pivot804 INTEGER(i4) :: il_perio805 806 TYPE(TFILE) :: tl_file807 808 930 TYPE(TMPP) :: tl_mpp 809 810 931 TYPE(TATT) :: tl_att 811 812 932 TYPE(TVAR) :: tl_var 813 814 933 TYPE(TDOM) :: tl_dom 934 935 INTEGER(i4) :: il_size 936 INTEGER(i4), DIMENSION(:), ALLOCATABLE :: il_rho 815 937 816 938 ! loop indices 817 939 !---------------------------------------------------------------- 818 940 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") 821 943 ENDIF 822 944 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, & 837 950 & id_imin, id_imax, & 838 951 & id_jmin, id_jmax) 839 952 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 846 954 CALL dom_add_extra(tl_dom) 847 955 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(:,:)) 874 977 875 ! 9- add attribute to variable978 !- add attribute to variable 876 979 tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name))) 877 980 CALL var_move_att(tl_var, tl_att) 878 981 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/)) 880 983 CALL var_move_att(tl_var, tl_att) 881 984 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/)) 883 986 CALL var_move_att(tl_var, tl_att) 884 987 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) 889 1001 CALL mpp_clean(tl_mpp) 890 1002 891 1003 END FUNCTION create_bathy_get_var 892 !> @endcode893 1004 !------------------------------------------------------------------- 894 1005 !> @brief 895 !> This subroutine 1006 !> This subroutine interpolate variable 896 1007 !> 897 !> @details 1008 !> @author J.Paul 1009 !> @date November, 2013 - Initial Version 898 1010 !> 899 !> @ author J.Paul900 !> - Nov, 2013- Initial Version901 !> 902 !> @param[in] 903 !> @ todo1011 !> @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) 904 1016 !------------------------------------------------------------------- 905 !> @code906 1017 SUBROUTINE create_bathy_interp( td_var, & 907 1018 & id_rho, & … … 919 1030 920 1031 ! local variable 921 TYPE(TVAR) :: tl_var922 1032 TYPE(TVAR) :: tl_mask 923 1033 … … 929 1039 ! loop indices 930 1040 !---------------------------------------------------------------- 931 932 ! copy variable933 tl_var=td_var934 1041 935 1042 !WARNING: two extrabands are required for cubic interpolation … … 952 1059 ENDIF 953 1060 954 ! 1-work on mask955 ! 1-1create mask956 ALLOCATE(bl_mask(t l_var%t_dim(1)%i_len, &957 & t l_var%t_dim(2)%i_len, &958 & t l_var%t_dim(3)%i_len, &959 & t l_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) ) 960 1067 961 1068 bl_mask(:,:,:,:)=1 962 WHERE(t l_var%d_value(:,:,:,:)==tl_var%d_fill) bl_mask(:,:,:,:)=0963 964 SELECT CASE(TRIM(t l_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)) 965 1072 CASE DEFAULT ! 'T' 966 tl_mask=var_init('tmask', bl_mask(:,:,:,:), td_dim=t l_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.") 973 1080 END SELECT 974 1081 975 1082 DEALLOCATE(bl_mask) 976 1083 977 ! 1-2interpolate mask1084 ! interpolate mask 978 1085 CALL interp_fill_value( tl_mask, id_rho(:), & 979 1086 & id_offset=id_offset(:,:) ) 980 1087 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(:), & 992 1097 & id_offset=id_offset(:,:) ) 993 1098 994 ! 2-3remove extraband995 CALL extrap_del_extrabands(t l_var, il_iext*id_rho(jp_I), il_jext*id_rho(jp_J))996 997 ! 2-2-5keep original mask1099 ! 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 998 1103 WHERE( tl_mask%d_value(:,:,:,:) == 0 ) 999 t l_var%d_value(:,:,:,:)=tl_var%d_fill1104 td_var%d_value(:,:,:,:)=td_var%d_fill 1000 1105 END WHERE 1001 1002 !3- save result1003 td_var=tl_var1004 1106 1005 1107 ! clean variable structure 1006 1108 CALL var_clean(tl_mask) 1007 CALL var_clean(tl_var)1008 1109 1009 1110 END SUBROUTINE create_bathy_interp 1010 !> @endcode1011 1111 END PROGRAM create_bathy
Note: See TracChangeset
for help on using the changeset viewer.