Changeset 12080 for utils/tools/SIREN/src/create_bathy.f90
- Timestamp:
- 2019-12-06T10:30:14+01:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
utils/tools/SIREN/src/create_bathy.f90
r9598 r12080 3 3 !---------------------------------------------------------------------- 4 4 ! 5 ! PROGRAM: create_bathy6 !7 5 ! DESCRIPTION: 8 6 !> @file 9 !> @brief10 7 !> This program creates fine grid bathymetry file. 11 8 !> 12 !> @details13 9 !> @section sec1 method 14 !> Bathymetry could be extracted from fine grid Bathymetry file, interpolated 15 !> from coarse grid Bathymetry file, or manually written. 10 !> This bathymetry could be : 11 !> - extracted from a wider fine grid bathymetry file 12 !> - interpolated from a wider coarse grid bathymetry file 13 !> - handwritten 14 !> 15 !> @image html bathy_40.png 16 !> <center>@image latex bathy_30.png 17 !> </center> 16 18 !> 17 19 !> @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 !> <center>\image latex bathy_30.png 25 !> </center> 26 !> 27 !> @note 28 !> you could find a template of the namelist in templates directory. 29 !> 30 !> create_bathy.nam contains 7 namelists:<br/> 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 !> - output namelist (namout) 38 !> 39 !> * _logger namelist (namlog)_:<br/> 40 !> - cn_logfile : log filename 41 !> - cn_verbosity : verbosity ('trace','debug','info', 42 !> 'warning','error','fatal','none') 43 !> - in_maxerror : maximum number of error allowed 44 !> 45 !> * _config namelist (namcfg)_:<br/> 46 !> - cn_varcfg : variable configuration file 47 !> (see ./SIREN/cfg/variable.cfg) 48 !> - cn_dimcfg : dimension configuration file. defines dimension allowed 49 !> (see ./SIREN/cfg/dimension.cfg). 50 !> - cn_dumcfg : useless (dummy) configuration file, for useless 51 !> dimension or variable (see ./SIREN/cfg/dummy.cfg). 52 !> 53 !> * _coarse grid namelist (namcrs)_:<br/> 54 !> - cn_coord0 : coordinate 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)_:<br/> 59 !> - cn_coord1 : coordinate file 60 !> - in_perio1 : periodicity index 61 !> - ln_fillclosed : fill closed sea or not (default is .TRUE.) 62 !> 63 !> * _variable namelist (namvar)_:<br/> 64 !> - cn_varfile : list of variable, and corresponding file.<br/> 65 !> *cn_varfile* is the path and filename of the file where find 66 !> variable. 67 !> @note 68 !> *cn_varfile* could be a matrix of value, if you want to filled 69 !> manually variable value.<br/> 70 !> the variable array of value is split into equal subdomain.<br/> 71 !> Each subdomain is filled with the corresponding value 72 !> of the matrix.<br/> 73 !> separators used to defined matrix are: 74 !> - ',' for line 75 !> - '/' for row 76 !> Example:<br/> 77 !> 3,2,3/1,4,5 => @f$ \left( \begin{array}{ccc} 78 !> 3 & 2 & 3 \\ 79 !> 1 & 4 & 5 \end{array} \right) @f$ 80 !> 81 !> Examples: 82 !> - 'Bathymetry:gridT.nc' 83 !> - 'Bathymetry:5000,5000,5000/5000,3000,5000/5000,5000,5000' 84 !> 85 !> - cn_varinfo : list of variable and extra information about request(s) 86 !> to be used.<br/> 87 !> each elements of *cn_varinfo* is a string character 88 !> (separated by ',').<br/> 89 !> it is composed of the variable name follow by ':', 90 !> then request(s) to be used on this variable.<br/> 91 !> request could be: 92 !> - int = interpolation method 93 !> - ext = extrapolation method 94 !> - flt = filter method 95 !> - min = minimum value 96 !> - max = maximum value 97 !> - unt = new units 98 !> - unf = unit scale factor (linked to new units) 99 !> 100 !> requests must be separated by ';'.<br/> 101 !> order of requests does not matter.<br/> 102 !> 103 !> informations about available method could be find in @ref interp, 104 !> @ref extrap and @ref filter modules.<br/> 105 !> Example: 'Bathymetry: flt=2*hamming(2,3); min=0' 106 !> @note 107 !> If you do not specify a method which is required, 108 !> default one is apply. 109 !> @warning 110 !> variable name must be __Bathymetry__ here. 111 !> 112 !> * _nesting namelist (namnst)_:<br/> 113 !> - in_rhoi : refinement factor in i-direction 114 !> - in_rhoj : refinement factor in j-direction 20 !> USAGE: create_bathy create_bathy.nam [-v] [-h]<br/> 21 !> - positional arguments:<br/> 22 !> - create_bathy.nam<br/> 23 !> namelist of create_bathy 24 !> @note 25 !> a template of the namelist could be created running (in templates directory): 26 !> @code{.sh} 27 !> python create_templates.py create_bathy 28 !> @endcode 29 !> 30 !> - optional arguments:<br/> 31 !> - -h, --help<br/> 32 !> show this help message (and exit)<br/> 33 !> - -v, --version<br/> 34 !> show Siren's version (and exit) 35 !> 36 !> @section sec_bathy create_bathy.nam 37 !> create_bathy.nam contains 7 sub-namelists:<br/> 38 !> - **namlog** to set logger parameters 39 !> - **namcfg** to set configuration file parameters 40 !> - **namsrc** to set source/coarse grid parameters 41 !> - **namtgt** to set target/fine grid parameters 42 !> - **namvar** to set variable parameters 43 !> - **namnst** to set sub domain and nesting paramters 44 !> - **namout** to set output parameters 45 !> 46 !> here after, each sub-namelist parameters is detailed. 47 !> @note 48 !> default values are specified between brackets 49 !> 50 !> @subsection sublog namlog 51 !> the logger sub-namelist parameters are : 52 !> 53 !> - **cn_logfile** [@a create_bathy.log]<br/> 54 !> logger filename 55 !> 56 !> - **cn_verbosity** [@a warning]<br/> 57 !> verbosity level, choose between : 58 !> - trace 59 !> - debug 60 !> - info 61 !> - warning 62 !> - error 63 !> - fatal 64 !> - none 65 !> 66 !> - **in_maxerror** [@a 5]<br/> 67 !> maximum number of error allowed 68 !> 69 !> @subsection subcfg namcfg 70 !> the configuration sub-namelist parameters are : 71 !> 72 !> - **cn_varcfg** [@a ./cfg/variable.cfg]<br/> 73 !> path to the variable configuration file.<br/> 74 !> the variable configuration file defines standard name, 75 !> default interpolation method, axis,... 76 !> to be used for some known variables.<br/> 77 !> 78 !> - **cn_dimcfg** [@a ./cfg/dimension.cfg]<br/> 79 !> path to the dimension configuration file.<br/> 80 !> the dimension configuration file defines dimensions allowed.<br/> 81 !> 82 !> - **cn_dumcfg** [@a ./cfg/dummy.cfg]<br/> 83 !> path to the useless (dummy) configuration file.<br/> 84 !> the dummy configuration file defines useless 85 !> dimension or variable. these dimension(s) or variable(s) will not be 86 !> processed.<br/> 87 !> 88 !> @subsection subsrc namsrc 89 !> the source/coarse grid sub-namelist parameters are : 90 !> 91 !> - **cn_coord0** [@a ]<br/> 92 !> path to the coordinate file 93 !> 94 !> - **in_perio0** [@a ]<br/> 95 !> NEMO periodicity index<br/> 96 !> the NEMO periodicity could be choose between 0 to 6: 97 !> <dl> 98 !> <dt>in_perio=0</dt> 99 !> <dd>standard regional model</dd> 100 !> <dt>in_perio=1</dt> 101 !> <dd>east-west cyclic model</dd> 102 !> <dt>in_perio=2</dt> 103 !> <dd>model with symmetric boundary condition across the equator</dd> 104 !> <dt>in_perio=3</dt> 105 !> <dd>regional model with North fold boundary and T-point pivot</dd> 106 !> <dt>in_perio=4</dt> 107 !> <dd>global model with a T-point pivot.<br/> 108 !> example: ORCA2, ORCA025, ORCA12</dd> 109 !> <dt>in_perio=5</dt> 110 !> <dd>regional model with North fold boundary and F-point pivot</dd> 111 !> <dt>in_perio=6</dt> 112 !> <dd>global model with a F-point pivot<br/> 113 !> example: ORCA05</dd> 114 !> </dd> 115 !> </dl> 116 !> @sa For more information see @ref md_src_docsrc_6_perio 117 !> and Model Boundary Condition paragraph in the 118 !> [NEMO documentation](https://forge.ipsl.jussieu.fr/nemo/chrome/site/doc/NEMO/manual/pdf/NEMO_manual.pdf) 119 !> 120 !> @subsection subtgt namtgt 121 !> the target/fine grid sub-namelist parameters are : 122 !> 123 !> - **cn_coord1** [@a ]<br/> 124 !> path to coordinate file 125 !> 126 !> - **in_perio1** [@a ]<br/> 127 !> NEMO periodicity index (see above) 128 !> @note if the fine/target coordinates file (cn_coord1) was created by SIREN, you do 129 !> not need to fill this parameter. SIREN will read it on the global attributes of 130 !> the coordinates file. 131 !> 132 !> - **ln_fillclosed** [@a .TRUE.]<br/> 133 !> logical to fill closed sea or not 134 !> 135 !> @subsection subvar namvar 136 !> the variable sub-namelist parameters are : 137 !> 138 !> - **cn_varfile** [@a ]<br/> 139 !> list of variable, and associated file 140 !> @warning 141 !> variable name must be __Bathymetry__ here. 142 !> 143 !> *cn_varfile* is the path and filename of the file where find 144 !> variable. 115 145 !> @note 116 !> coarse grid indices will be deduced from fine grid 117 !> coordinate file. 118 !> 119 !> * _output namelist (namout)_:<br/> 120 !> - cn_fileout : output bathymetry file 121 !> 146 !> *cn_varfile* could be a matrix of value, if you want to handwrite 147 !> variable value.<br/> 148 !> the variable array of value is split into equal subdomain.<br/> 149 !> each subdomain is filled with the corresponding value 150 !> of the matrix.<br/> 151 !> separators used to defined matrix are: 152 !> - ',' for line 153 !> - '/' for row 154 !> Example:<br/> 155 !> 3,2,3/1,4,5 => @f$ \left( \begin{array}{ccc} 156 !> 3 & 2 & 3 \\ 157 !> 1 & 4 & 5 \end{array} \right) @f$ 158 !> 159 !> Examples: 160 !> - 'Bathymetry:gridT.nc' 161 !> - 'Bathymetry:5000,5000,5000/5000,3000,5000/5000,5000,5000'<br/> 162 !> 163 !> @note 164 !> Optionnaly, NEMO periodicity could be added following the filename. 165 !> the periodicity must be separated by ';' 166 !> 167 !> Example: 168 !> - 'Bathymetry:gridT.nc ; perio=4'<br/> 169 !> 170 !> - **cn_varinfo** [@a ]<br/> 171 !> list of variable and extra information about request(s) to be used<br/> 172 !> 173 !> each elements of *cn_varinfo* is a string character (separated by ',').<br/> 174 !> it is composed of the variable name follow by ':', 175 !> then request(s) to be used on this variable.<br/> 176 !> request could be: 177 !> - int = interpolation method 178 !> - ext = extrapolation method 179 !> - flt = filter method 180 !> - min = minimum value 181 !> - max = maximum value 182 !> - unt = new units 183 !> - unf = unit scale factor (linked to new units) 184 !> 185 !> requests must be separated by ';'.<br/> 186 !> order of requests does not matter.<br/> 187 !> 188 !> informations about available method could be find in @ref interp, 189 !> @ref extrap and @ref filter modules.<br/> 190 !> Example: 191 !> - 'Bathymetry: flt=2*hamming(2,3); min=0' 192 !> 193 !> @note 194 !> If you do not specify a method which is required, 195 !> default one is apply. 196 !> 197 !> - **ln_rand** [@a .False.]<br/> 198 !> logical to add random value to Bathymetry<br/> 199 !> Only for handmade Bathymetry. 200 !> A random value (+/- 0.1% of the maximum depth) will 201 !> will be added to avoid flat Bathymetry (which may cause issue). 202 !> 203 !> @subsection subnst namnst 204 !> the nesting sub-namelist parameters are : 205 !> 206 !> - **in_rhoi** [@a 1]<br/> 207 !> refinement factor in i-direction 208 !> 209 !> - **in_rhoj** [@a 1]<br/> 210 !> refinement factor in j-direction 211 !> 212 !> @note 213 !> coarse grid indices will be deduced from fine grid 214 !> coordinate file. 215 !> 216 !> @subsection subout namout 217 !> the output sub-namelist parameter is : 218 !> 219 !> - **cn_fileout** [@a bathy_fine.nc]<br/> 220 !> output bathymetry filename 221 !> 222 !> <hr> 122 223 !> @author J.Paul 123 ! REVISION HISTORY:224 !> 124 225 !> @date November, 2013 - Initial Version 125 226 !> @date Sepember, 2014 … … 138 239 !> @date October, 2016 139 240 !> - dimension to be used select from configuration file 140 ! 241 !> @date July, 2017 242 !> - add random value to avoid flat bathymetry 243 !> @date January, 2019 244 !> - add option to add random value to a flat Bathymetry 245 !> - create and clean file structure to avoid memory leaks 246 !> - check dimension of matrix for 'handmade' bathymetry 247 !> - add url path to global attributes of output file(s) 248 !> @date February, 2019 249 !> - rename sub namelist namcrs to namsrc 250 !> - rename sub namelist namfin to namtgt 251 !> @date August, 2019 252 !> - use periodicity read from namelist, and store in multi structure 253 !> @date Ocober, 2019 254 !> - add help and version optional arguments 255 !> 141 256 !> @todo 142 257 !> - check tl_multi is not empty 143 258 !> 144 !> @note Software governed by the CeCILL licence ( ./LICENSE)259 !> @note Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) 145 260 !---------------------------------------------------------------------- 146 261 PROGRAM create_bathy … … 168 283 IMPLICIT NONE 169 284 285 ! parameters 286 CHARACTER(LEN=lc), PARAMETER :: cp_myname = "create_bathy" 287 170 288 ! local variable 289 CHARACTER(LEN=lc) :: cl_arg 171 290 CHARACTER(LEN=lc) :: cl_namelist 172 291 CHARACTER(LEN=lc) :: cl_date 173 292 CHARACTER(LEN=lc) :: cl_data 293 CHARACTER(LEN=lc) :: cl_url 294 CHARACTER(LEN=lc) :: cl_errormsg 174 295 175 296 INTEGER(i4) :: il_narg 176 297 INTEGER(i4) :: il_status 177 298 INTEGER(i4) :: il_fileid 299 INTEGER(i4) :: il_varid 178 300 INTEGER(i4) :: il_attid 179 301 INTEGER(i4) :: il_imin0 … … 206 328 TYPE(TDIM) , DIMENSION(ip_maxdim) :: tl_dim 207 329 330 TYPE(TFILE) :: tl_file 331 208 332 TYPE(TMULTI) :: tl_multi 209 333 … … 217 341 ! namelist variable 218 342 ! namlog 219 CHARACTER(LEN=lc) :: cn_logfile = 'create_bathy.log'220 CHARACTER(LEN=lc) :: cn_verbosity = 'warning'221 INTEGER(i4) :: in_maxerror = 5343 CHARACTER(LEN=lc) :: cn_logfile = 'create_bathy.log' 344 CHARACTER(LEN=lc) :: cn_verbosity = 'warning' 345 INTEGER(i4) :: in_maxerror = 5 222 346 223 347 ! namcfg 224 CHARACTER(LEN=lc) :: cn_varcfg = './cfg/variable.cfg'225 CHARACTER(LEN=lc) :: cn_dimcfg = './cfg/dimension.cfg'226 CHARACTER(LEN=lc) :: cn_dumcfg = './cfg/dummy.cfg'227 228 ! nam crs229 CHARACTER(LEN=lc) :: cn_coord0 = ''230 INTEGER(i4) :: in_perio0 = -1231 232 ! nam fin233 CHARACTER(LEN=lc) :: cn_coord1 = ''234 INTEGER(i4) :: in_perio1 = -1348 CHARACTER(LEN=lc) :: cn_varcfg = './cfg/variable.cfg' 349 CHARACTER(LEN=lc) :: cn_dimcfg = './cfg/dimension.cfg' 350 CHARACTER(LEN=lc) :: cn_dumcfg = './cfg/dummy.cfg' 351 352 ! namsrc 353 CHARACTER(LEN=lc) :: cn_coord0 = '' 354 INTEGER(i4) :: in_perio0 = -1 355 356 ! namtgt 357 CHARACTER(LEN=lc) :: cn_coord1 = '' 358 INTEGER(i4) :: in_perio1 = -1 235 359 LOGICAL :: ln_fillclosed = .TRUE. 236 360 … … 238 362 CHARACTER(LEN=lc), DIMENSION(ip_maxvar) :: cn_varfile = '' 239 363 CHARACTER(LEN=lc), DIMENSION(ip_maxvar) :: cn_varinfo = '' 364 LOGICAL :: ln_rand = .FALSE. 240 365 241 366 ! namnst 242 INTEGER(i4) :: in_rhoi = 1243 INTEGER(i4) :: in_rhoj = 1367 INTEGER(i4) :: in_rhoi = 1 368 INTEGER(i4) :: in_rhoj = 1 244 369 245 370 ! namout … … 247 372 !------------------------------------------------------------------- 248 373 249 NAMELIST /namlog/ & 250 & cn_logfile, & 251 & cn_verbosity, & 252 & in_maxerror 253 254 NAMELIST /namcfg/ & 255 & cn_varcfg, &!< variable configuration file256 & cn_dimcfg, &!< dimension configuration file257 & cn_dumcfg 258 259 NAMELIST /nam crs/ & !<coarse grid namelist260 & cn_coord0, &!< coordinate file261 & in_perio0 262 263 NAMELIST /nam fin/ & !<fine grid namelist264 & cn_coord1, &!< coordinate file265 & in_perio1, &!< periodicity index266 & ln_fillclosed 374 NAMELIST /namlog/ & !< logger namelist 375 & cn_logfile, & !< log file 376 & cn_verbosity, & !< log verbosity 377 & in_maxerror !< logger maximum error 378 379 NAMELIST /namcfg/ & !< configuration namelist 380 & cn_varcfg, & !< variable configuration file 381 & cn_dimcfg, & !< dimension configuration file 382 & cn_dumcfg !< dummy configuration file 383 384 NAMELIST /namsrc/ & !< source/coarse grid namelist 385 & cn_coord0, & !< coordinate file 386 & in_perio0 !< periodicity index 387 388 NAMELIST /namtgt/ & !< target/fine grid namelist 389 & cn_coord1, & !< coordinate file 390 & in_perio1, & !< periodicity index 391 & ln_fillclosed !< fill closed sea 267 392 268 NAMELIST /namvar/ & !< variable namelist 269 & cn_varfile, & !< list of variable file 270 & cn_varinfo !< list of variable and interpolation method to be used. (ex: 'votemper:linear','vosaline:cubic' ) 271 272 NAMELIST /namnst/ & !< nesting namelist 273 & in_rhoi, & !< refinement factor in i-direction 274 & in_rhoj !< refinement factor in j-direction 275 276 NAMELIST /namout/ & !< output namlist 277 & cn_fileout !< fine grid bathymetry file 393 NAMELIST /namvar/ & !< variable namelist 394 & cn_varfile, & !< list of variable file 395 & cn_varinfo, & !< list of variable and interpolation method to be used. (ex: 'votemper:linear','vosaline:cubic' ) 396 & ln_rand !< add random value to avoid flat bathymetry 397 398 NAMELIST /namnst/ & !< nesting namelist 399 & in_rhoi, & !< refinement factor in i-direction 400 & in_rhoj !< refinement factor in j-direction 401 402 NAMELIST /namout/ & !< output namelist 403 & cn_fileout !< fine grid bathymetry file 278 404 !------------------------------------------------------------------- 279 405 280 ! namelist 281 ! get namelist 406 ! 407 ! Initialisation 408 ! -------------- 409 ! 282 410 il_narg=COMMAND_ARGUMENT_COUNT() !f03 intrinsec 283 IF( il_narg/=1 )THEN 284 PRINT *,"ERROR in create_bathy: need a namelist" 285 STOP 411 412 ! Traitement des arguments fournis 413 ! -------------------------------- 414 IF( il_narg /= 1 )THEN 415 WRITE(cl_errormsg,*) ' ERROR : one argument is needed ' 416 CALL fct_help(cp_myname,cl_errormsg) 417 CALL EXIT(1) 286 418 ELSE 287 CALL GET_COMMAND_ARGUMENT(1,cl_namelist) !f03 intrinsec 419 420 CALL GET_COMMAND_ARGUMENT(1,cl_arg) !f03 intrinsec 421 SELECT CASE (cl_arg) 422 CASE ('-v', '--version') 423 424 CALL fct_version(cp_myname) 425 CALL EXIT(0) 426 427 CASE ('-h', '--help') 428 429 CALL fct_help(cp_myname) 430 CALL EXIT(0) 431 432 CASE DEFAULT 433 434 cl_namelist=cl_arg 435 436 ! read namelist 437 INQUIRE(FILE=TRIM(cl_namelist), EXIST=ll_exist) 438 IF( ll_exist )THEN 439 440 il_fileid=fct_getunit() 441 442 OPEN( il_fileid, FILE=TRIM(cl_namelist), & 443 & FORM='FORMATTED', & 444 & ACCESS='SEQUENTIAL', & 445 & STATUS='OLD', & 446 & ACTION='READ', & 447 & IOSTAT=il_status) 448 CALL fct_err(il_status) 449 IF( il_status /= 0 )THEN 450 WRITE(cl_errormsg,*) " ERROR : error opening "//TRIM(cl_namelist) 451 CALL fct_help(cp_myname,cl_errormsg) 452 CALL EXIT(1) 453 ENDIF 454 455 READ( il_fileid, NML = namlog ) 456 457 ! define logger file 458 CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity),in_maxerror) 459 CALL logger_header() 460 461 READ( il_fileid, NML = namcfg ) 462 ! get variable extra information on configuration file 463 CALL var_def_extra(TRIM(cn_varcfg)) 464 465 ! get dimension allowed 466 CALL dim_def_extra(TRIM(cn_dimcfg)) 467 468 ! get dummy variable 469 CALL var_get_dummy(TRIM(cn_dumcfg)) 470 ! get dummy dimension 471 CALL dim_get_dummy(TRIM(cn_dumcfg)) 472 ! get dummy attribute 473 CALL att_get_dummy(TRIM(cn_dumcfg)) 474 475 READ( il_fileid, NML = namsrc ) 476 READ( il_fileid, NML = namtgt ) 477 READ( il_fileid, NML = namvar ) 478 ! add user change in extra information 479 CALL var_chg_extra( cn_varinfo ) 480 ! match variable with file 481 tl_multi=multi_init(cn_varfile) 482 483 READ( il_fileid, NML = namnst ) 484 READ( il_fileid, NML = namout ) 485 486 CLOSE( il_fileid, IOSTAT=il_status ) 487 CALL fct_err(il_status) 488 IF( il_status /= 0 )THEN 489 CALL logger_error("CREATE BATHY: closing "//TRIM(cl_namelist)) 490 ENDIF 491 492 ELSE 493 494 WRITE(cl_errormsg,*) " ERROR : can't find "//TRIM(cl_namelist) 495 CALL fct_help(cp_myname,cl_errormsg) 496 CALL EXIT(1) 497 498 ENDIF 499 500 END SELECT 288 501 ENDIF 289 290 ! read namelist291 INQUIRE(FILE=TRIM(cl_namelist), EXIST=ll_exist)292 IF( ll_exist )THEN293 294 il_fileid=fct_getunit()295 296 OPEN( il_fileid, FILE=TRIM(cl_namelist), &297 & FORM='FORMATTED', &298 & ACCESS='SEQUENTIAL', &299 & STATUS='OLD', &300 & ACTION='READ', &301 & IOSTAT=il_status)302 CALL fct_err(il_status)303 IF( il_status /= 0 )THEN304 PRINT *,"ERROR in create_bathy: error opening "//TRIM(cl_namelist)305 STOP306 ENDIF307 308 READ( il_fileid, NML = namlog )309 ! define log file310 CALL logger_open(TRIM(cn_logfile),TRIM(cn_verbosity),in_maxerror)311 CALL logger_header()312 313 READ( il_fileid, NML = namcfg )314 ! get variable extra information315 CALL var_def_extra(TRIM(cn_varcfg))316 317 ! get dimension allowed318 CALL dim_def_extra(TRIM(cn_dimcfg))319 320 ! get dummy variable321 CALL var_get_dummy(TRIM(cn_dumcfg))322 ! get dummy dimension323 CALL dim_get_dummy(TRIM(cn_dumcfg))324 ! get dummy attribute325 CALL att_get_dummy(TRIM(cn_dumcfg))326 327 READ( il_fileid, NML = namcrs )328 READ( il_fileid, NML = namfin )329 READ( il_fileid, NML = namvar )330 ! add user change in extra information331 CALL var_chg_extra( cn_varinfo )332 ! match variable with file333 tl_multi=multi_init(cn_varfile)334 335 READ( il_fileid, NML = namnst )336 READ( il_fileid, NML = namout )337 338 CLOSE( il_fileid, IOSTAT=il_status )339 CALL fct_err(il_status)340 IF( il_status /= 0 )THEN341 CALL logger_error("CREATE BATHY: closing "//TRIM(cl_namelist))342 ENDIF343 344 ELSE345 346 PRINT *,"ERROR in create_bathy: can't find "//TRIM(cl_namelist)347 STOP348 349 ENDIF350 502 351 503 CALL multi_print(tl_multi) 352 504 353 505 ! open files 354 IF( cn_coord0 /= '' )THEN 355 tl_coord0=mpp_init( file_init(TRIM(cn_coord0)), id_perio=in_perio0) 506 IF( TRIM(cn_coord0) /= '' )THEN 507 tl_file=file_init(TRIM(cn_coord0)) 508 tl_coord0=mpp_init( tl_file, id_perio=in_perio0) 509 ! clean 510 CALL file_clean(tl_file) 356 511 CALL grid_get_info(tl_coord0) 357 512 ELSE … … 361 516 362 517 IF( TRIM(cn_coord1) /= '' )THEN 363 tl_coord1=mpp_init( file_init(TRIM(cn_coord1)),id_perio=in_perio1) 518 tl_file=file_init(TRIM(cn_coord1)) 519 tl_coord1=mpp_init( tl_file, id_perio=in_perio1) 520 ! clean 521 CALL file_clean(tl_file) 364 522 CALL grid_get_info(tl_coord1) 365 523 ELSE … … 430 588 jk=jk+1 431 589 tl_tmp=var_copy(tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj)) 432 433 tl_var(jk)=create_bathy_matrix(tl_tmp, tl_coord1) 590 591 IF( COUNT(tl_tmp%t_dim(:)%l_use) > 2 )THEN 592 CALL logger_fatal("CREATE BATHY: input matrix use more "//& 593 & "than 2D. Check namelist.") 594 ENDIF 595 tl_var(jk)=create_bathy_matrix(tl_tmp, tl_coord1, ln_rand) 434 596 ENDDO 435 597 ! clean … … 438 600 ELSE 439 601 440 tl_mpp=mpp_init( file_init(TRIM(tl_multi%t_mpp(ji)%c_name)) ) 602 tl_file=file_init(TRIM(tl_multi%t_mpp(ji)%c_name), & 603 & id_perio=tl_multi%t_mpp(ji)%i_perio) 604 tl_mpp=mpp_init( tl_file ) 605 606 ! clean 607 CALL file_clean(tl_file) 441 608 CALL grid_get_info(tl_mpp) 442 609 … … 459 626 jk=jk+1 460 627 tl_tmp=var_copy(tl_multi%t_mpp(ji)%t_proc(1)%t_var(jj)) 461 628 462 629 tl_var(jk)=create_bathy_extract( tl_tmp, tl_mpp, & 463 630 & tl_coord1 ) … … 548 715 549 716 ! add longitude 550 tl_lon=iom_mpp_read_var(tl_coord1,'longitude') 717 il_varid=var_get_id(tl_coord1%t_proc(1)%t_var(:),'longitude') 718 IF( il_varid == 0 )THEN 719 il_varid=var_get_id(tl_coord1%t_proc(1)%t_var(:),'longitude_T') 720 ENDIF 721 tl_lon=iom_mpp_read_var(tl_coord1, il_varid) 551 722 CALL file_add_var(tl_fileout, tl_lon) 552 723 CALL var_clean(tl_lon) 553 724 554 725 ! add latitude 555 tl_lat=iom_mpp_read_var(tl_coord1,'latitude') 726 il_varid=var_get_id(tl_coord1%t_proc(1)%t_var(:),'latitude') 727 IF( il_varid == 0 )THEN 728 il_varid=var_get_id(tl_coord1%t_proc(1)%t_var(:),'latitude_T') 729 ENDIF 730 tl_lat=iom_mpp_read_var(tl_coord1, il_varid) 556 731 CALL file_add_var(tl_fileout, tl_lat) 557 732 CALL var_clean(tl_lat) … … 581 756 DEALLOCATE(tl_var) 582 757 758 ! clean 759 CALL multi_clean(tl_multi) 760 583 761 ! add some attribute 584 762 tl_att=att_init("Created_by","SIREN create_bathy") 585 763 CALL file_add_att(tl_fileout, tl_att) 586 764 765 !add source url 766 cl_url=fct_split(fct_split(cp_url,2,'$'),2,'URL:') 767 tl_att=att_init("SIREN_url",cl_url) 768 CALL file_add_att(tl_fileout, tl_att) 769 770 ! add date of creation 587 771 cl_date=date_print(date_now()) 588 772 tl_att=att_init("Creation_date",cl_date) … … 631 815 632 816 CONTAINS 817 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 818 FUNCTION create_bathy_matrix(td_var, td_coord, ld_rand) & 819 & RESULT (tf_var) 633 820 !------------------------------------------------------------------- 634 821 !> @brief … … 641 828 !> Each subdomain is filled with the corresponding value of the matrix. 642 829 !> 830 !> Optionaly, you could add a random value of 0.1% of maximum depth to each 831 !> points of the bathymetry 832 !> 643 833 !> @author J.Paul 644 834 !> @date November, 2013 - Initial Version … … 646 836 !> @param[in] td_var variable structure 647 837 !> @param[in] td_coord coordinate file structure 838 !> @param[in] ld_rand add random value to bathymetry 648 839 !> @return variable structure 649 840 !------------------------------------------------------------------- 650 FUNCTION create_bathy_matrix(td_var, td_coord) 841 651 842 IMPLICIT NONE 843 652 844 ! Argument 653 845 TYPE(TVAR), INTENT(IN) :: td_var 654 846 TYPE(TMPP), INTENT(IN) :: td_coord 847 LOGICAL , INTENT(IN) :: ld_rand 655 848 656 849 ! function 657 TYPE(TVAR) :: create_bathy_matrix850 TYPE(TVAR) :: tf_var 658 851 659 852 ! local variable 660 853 INTEGER(i4) , DIMENSION(2,2) :: il_xghost 661 INTEGER(i4) , DIMENSION( 3) :: il_dim662 INTEGER(i4) , DIMENSION( 3) :: il_size663 INTEGER(i4) , DIMENSION( 3) :: il_rest854 INTEGER(i4) , DIMENSION(2) :: il_dim 855 INTEGER(i4) , DIMENSION(2) :: il_size 856 INTEGER(i4) , DIMENSION(2) :: il_rest 664 857 665 858 INTEGER(i4) , DIMENSION(:) , ALLOCATABLE :: il_ishape 666 859 INTEGER(i4) , DIMENSION(:) , ALLOCATABLE :: il_jshape 667 INTEGER(i4) , DIMENSION(:) , ALLOCATABLE :: il_kshape 668 860 861 REAL(dp) , DIMENSION(:,:) , ALLOCATABLE :: dl_ran 669 862 REAL(dp) , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value 670 863 … … 677 870 INTEGER(i4) :: ji 678 871 INTEGER(i4) :: jj 679 INTEGER(i4) :: jk680 872 !---------------------------------------------------------------- 681 873 … … 705 897 ! write value on grid 706 898 ! get matrix dimension 707 il_dim(:)=td_var%t_dim(1: 3)%i_len899 il_dim(:)=td_var%t_dim(1:2)%i_len 708 900 ! output dimension 709 901 tl_dim(:)=dim_copy(tl_lon%t_dim(:)) … … 712 904 713 905 ! split output domain in N subdomain depending of matrix dimension 714 il_size(:) = tl_dim(1: 3)%i_len / il_dim(:)715 il_rest(:) = MOD(tl_dim(1: 3)%i_len, il_dim(:))906 il_size(:) = tl_dim(1:2)%i_len / il_dim(:) 907 il_rest(:) = MOD(tl_dim(1:2)%i_len, il_dim(:)) 716 908 717 909 ALLOCATE( il_ishape(il_dim(1)+1) ) … … 731 923 il_jshape(il_dim(2)+1)=il_jshape(il_dim(2)+1)+il_rest(2) 732 924 733 ALLOCATE( il_kshape(il_dim(3)+1) )734 il_kshape(:)=0735 DO jk=2,il_dim(3)+1736 il_kshape(jk)=il_kshape(jk-1)+il_size(3)737 ENDDO738 ! add rest to last cell739 il_kshape(il_dim(3)+1)=il_kshape(il_dim(3)+1)+il_rest(3)740 741 925 ! write ouput array of value 742 926 ALLOCATE(dl_value( tl_dim(1)%i_len, & … … 746 930 747 931 dl_value(:,:,:,:)=0 748 749 DO jk=2,il_dim(3)+1 750 DO jj=2,il_dim(2)+1 751 DO ji=2,il_dim(1)+1 752 753 dl_value( 1+il_ishape(ji-1):il_ishape(ji), & 754 & 1+il_jshape(jj-1):il_jshape(jj), & 755 & 1+il_kshape(jk-1):il_kshape(jk), & 756 & 1 ) = td_var%d_value(ji-1,jj-1,jk-1,1) 757 758 ENDDO 932 DO jj=2,il_dim(2)+1 933 DO ji=2,il_dim(1)+1 934 935 dl_value( 1+il_ishape(ji-1):il_ishape(ji), & 936 & 1+il_jshape(jj-1):il_jshape(jj), & 937 & 1,1 ) = td_var%d_value(ji-1,jj-1,1,1) 938 759 939 ENDDO 760 940 ENDDO 761 941 942 943 IF( ld_rand )THEN 944 ALLOCATE(dl_ran(tl_dim(1)%i_len, & 945 & tl_dim(2)%i_len) ) 946 947 ! set random value between 0 and 1 948 CALL RANDOM_NUMBER(dl_ran(:,:)) 949 ! set random value between -0.5 and 0.5 950 dl_ran(:,:)=dl_ran(:,:)-0.5 951 ! set random value of 0.1% of maximum depth 952 dl_ran(:,:)=dl_ran(:,:)*1.e-4*MAXVAL(td_var%d_value(:,:,1,1)) 953 954 dl_value(:,:,1,1)=dl_value(:,:,1,1)+dl_ran(:,:) 955 956 DEALLOCATE(dl_ran) 957 ENDIF 958 762 959 ! initialise variable with value 763 create_bathy_matrix=var_init(TRIM(td_var%c_name),dl_value(:,:,:,:))960 tf_var=var_init(TRIM(td_var%c_name),dl_value(:,:,:,:)) 764 961 765 962 DEALLOCATE(dl_value) 766 963 767 964 ! add ghost cell 768 CALL grid_add_ghost( create_bathy_matrix, il_xghost(:,:))965 CALL grid_add_ghost(tf_var, il_xghost(:,:)) 769 966 770 967 ! clean … … 772 969 773 970 END FUNCTION create_bathy_matrix 971 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 972 FUNCTION create_bathy_extract(td_var, td_mpp, td_coord) & 973 & RESULT (tf_var) 774 974 !------------------------------------------------------------------- 775 975 !> @brief … … 785 985 !> @return variable structure 786 986 !------------------------------------------------------------------- 787 FUNCTION create_bathy_extract(td_var, td_mpp, & 788 & td_coord) 987 789 988 IMPLICIT NONE 989 790 990 ! Argument 791 991 TYPE(TVAR), INTENT(IN) :: td_var … … 794 994 795 995 ! function 796 TYPE(TVAR) :: create_bathy_extract996 TYPE(TVAR) :: tf_var 797 997 798 998 ! local variable … … 808 1008 TYPE(TATT) :: tl_att 809 1009 810 TYPE(TVAR) :: tl_var811 812 1010 TYPE(TDOM) :: tl_dom 813 1011 ! loop indices … … 843 1041 844 1042 ! read variable on domain 845 t l_var=iom_dom_read_var(tl_mpp,TRIM(td_var%c_name),tl_dom)1043 tf_var=iom_dom_read_var(tl_mpp,TRIM(td_var%c_name),tl_dom) 846 1044 847 1045 ! close mpp file … … 849 1047 850 1048 ! add ghost cell 851 CALL grid_add_ghost(t l_var,tl_dom%i_ghost(:,:))1049 CALL grid_add_ghost(tf_var,tl_dom%i_ghost(:,:)) 852 1050 853 1051 ! check result 854 IF( ANY( t l_var%t_dim(:)%l_use .AND. &855 & t l_var%t_dim(:)%i_len /= td_coord%t_dim(:)%i_len) )THEN1052 IF( ANY( tf_var%t_dim(:)%l_use .AND. & 1053 & tf_var%t_dim(:)%i_len /= td_coord%t_dim(:)%i_len) )THEN 856 1054 CALL logger_debug("CREATE BATHY EXTRACT: "//& 857 1055 & "dimensoin of variable "//TRIM(td_var%c_name)//" "//& 858 & TRIM(fct_str(t l_var%t_dim(1)%i_len))//","//&859 & TRIM(fct_str(t l_var%t_dim(2)%i_len))//","//&860 & TRIM(fct_str(t l_var%t_dim(3)%i_len))//","//&861 & TRIM(fct_str(t l_var%t_dim(4)%i_len)) )1056 & TRIM(fct_str(tf_var%t_dim(1)%i_len))//","//& 1057 & TRIM(fct_str(tf_var%t_dim(2)%i_len))//","//& 1058 & TRIM(fct_str(tf_var%t_dim(3)%i_len))//","//& 1059 & TRIM(fct_str(tf_var%t_dim(4)%i_len)) ) 862 1060 CALL logger_debug("CREATE BATHY EXTRACT: "//& 863 1061 & "dimensoin of coordinate file "//& … … 873 1071 ! add attribute to variable 874 1072 tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name))) 875 CALL var_move_att(t l_var, tl_att)1073 CALL var_move_att(tf_var, tl_att) 876 1074 877 1075 tl_att=att_init('src_i_indices',(/tl_dom%i_imin, tl_dom%i_imax/)) 878 CALL var_move_att(t l_var, tl_att)1076 CALL var_move_att(tf_var, tl_att) 879 1077 880 1078 tl_att=att_init('src_j_indices',(/tl_dom%i_jmin, tl_dom%i_jmax/)) 881 CALL var_move_att(tl_var, tl_att) 882 883 ! save result 884 create_bathy_extract=var_copy(tl_var) 1079 CALL var_move_att(tf_var, tl_att) 885 1080 886 1081 ! clean structure 887 1082 CALL att_clean(tl_att) 888 CALL var_clean(tl_var)889 1083 CALL mpp_clean(tl_mpp) 890 1084 ENDIF 891 1085 892 1086 END FUNCTION create_bathy_extract 1087 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1088 FUNCTION create_bathy_get_var(td_var, td_mpp, & 1089 & id_imin, id_jmin, & 1090 & id_imax, id_jmax, & 1091 & id_offset, & 1092 & id_rho) & 1093 & RESULT (tf_var) 893 1094 !------------------------------------------------------------------- 894 1095 !> @brief … … 909 1110 !> @return variable structure 910 1111 !------------------------------------------------------------------- 911 FUNCTION create_bathy_get_var(td_var, td_mpp, & 912 & id_imin, id_jmin, & 913 & id_imax, id_jmax, & 914 & id_offset, & 915 & id_rho ) 1112 916 1113 IMPLICIT NONE 1114 917 1115 ! Argument 918 1116 TYPE(TVAR) , INTENT(IN) :: td_var … … 926 1124 927 1125 ! function 928 TYPE(TVAR) :: create_bathy_get_var1126 TYPE(TVAR) :: tf_var 929 1127 930 1128 ! local variable 931 1129 TYPE(TMPP) :: tl_mpp 932 1130 TYPE(TATT) :: tl_att 933 TYPE(TVAR) :: tl_var934 1131 TYPE(TDOM) :: tl_dom 935 1132 … … 959 1156 960 1157 !- read variable value on domain 961 t l_var=iom_dom_read_var(tl_mpp,TRIM(td_var%c_name),tl_dom)1158 tf_var=iom_dom_read_var(tl_mpp,TRIM(td_var%c_name),tl_dom) 962 1159 963 1160 !- close mpp files … … 969 1166 970 1167 !- interpolate variable 971 CALL create_bathy_interp(t l_var, il_rho(:), id_offset(:,:))1168 CALL create_bathy_interp(tf_var, il_rho(:), id_offset(:,:)) 972 1169 973 1170 !- remove extraband added to domain 974 CALL dom_del_extra( t l_var, tl_dom, il_rho(:) )1171 CALL dom_del_extra( tf_var, tl_dom, il_rho(:) ) 975 1172 976 1173 CALL dom_clean_extra( tl_dom ) 977 1174 978 1175 !- add ghost cell 979 CALL grid_add_ghost(t l_var,tl_dom%i_ghost(:,:))1176 CALL grid_add_ghost(tf_var,tl_dom%i_ghost(:,:)) 980 1177 981 1178 !- add attribute to variable 982 1179 tl_att=att_init('src_file',TRIM(fct_basename(tl_mpp%c_name))) 983 CALL var_move_att(t l_var, tl_att)1180 CALL var_move_att(tf_var, tl_att) 984 1181 985 1182 tl_att=att_init('src_i_indices',(/tl_dom%i_imin, tl_dom%i_imax/)) 986 CALL var_move_att(t l_var, tl_att)1183 CALL var_move_att(tf_var, tl_att) 987 1184 988 1185 tl_att=att_init('src_j_indices',(/tl_dom%i_jmin, tl_dom%i_jmax/)) 989 CALL var_move_att(t l_var, tl_att)1186 CALL var_move_att(tf_var, tl_att) 990 1187 991 1188 IF( .NOT. ALL(id_rho(:)==1) )THEN 992 1189 tl_att=att_init("refinment_factor",(/id_rho(jp_I),id_rho(jp_J)/)) 993 CALL var_move_att(t l_var, tl_att)1190 CALL var_move_att(tf_var, tl_att) 994 1191 ENDIF 995 1192 996 1193 DEALLOCATE( il_rho ) 997 998 !- save result999 create_bathy_get_var=var_copy(tl_var)1000 1194 1001 1195 !- clean structure 1002 1196 CALL att_clean(tl_att) 1003 CALL var_clean(tl_var)1004 1197 CALL mpp_clean(tl_mpp) 1005 1198 1006 1199 END FUNCTION create_bathy_get_var 1200 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1201 SUBROUTINE create_bathy_interp(td_var, id_rho, id_offset, & 1202 & id_iext, id_jext) 1007 1203 !------------------------------------------------------------------- 1008 1204 !> @brief … … 1018 1214 !> @param[in] id_jext j-direction size of extra bands (default=im_minext) 1019 1215 !------------------------------------------------------------------- 1020 SUBROUTINE create_bathy_interp( td_var, &1021 & id_rho, &1022 & id_offset, &1023 & id_iext, id_jext)1024 1216 1025 1217 IMPLICIT NONE … … 1112 1304 1113 1305 END SUBROUTINE create_bathy_interp 1306 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1307 SUBROUTINE create_bathy_check_depth(td_mpp, td_depth) 1114 1308 !------------------------------------------------------------------- 1115 1309 !> @brief … … 1125 1319 !> @param[inout] td_depth depth variable structure 1126 1320 !------------------------------------------------------------------- 1127 SUBROUTINE create_bathy_check_depth( td_mpp, td_depth )1128 1321 1129 1322 IMPLICIT NONE … … 1164 1357 1165 1358 END SUBROUTINE create_bathy_check_depth 1359 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1360 SUBROUTINE create_bathy_check_time(td_mpp, td_time) 1166 1361 !------------------------------------------------------------------- 1167 1362 !> @brief … … 1177 1372 !> @param[inout] td_time time variable structure 1178 1373 !------------------------------------------------------------------- 1179 SUBROUTINE create_bathy_check_time( td_mpp, td_time )1180 1374 1181 1375 IMPLICIT NONE … … 1220 1414 1221 1415 END SUBROUTINE create_bathy_check_time 1416 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1222 1417 END PROGRAM create_bathy
Note: See TracChangeset
for help on using the changeset viewer.