[1682] | 1 | !> @file init_masks.f90 |
---|
[2000] | 2 | !------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1036] | 4 | ! |
---|
[2000] | 5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
| 6 | ! terms of the GNU General Public License as published by the Free Software |
---|
| 7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
| 8 | ! version. |
---|
[1036] | 9 | ! |
---|
| 10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 13 | ! |
---|
| 14 | ! You should have received a copy of the GNU General Public License along with |
---|
| 15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 16 | ! |
---|
[3655] | 17 | ! Copyright 1997-2019 Leibniz Universitaet Hannover |
---|
[2000] | 18 | !------------------------------------------------------------------------------! |
---|
[1036] | 19 | ! |
---|
[484] | 20 | ! Current revisions: |
---|
[298] | 21 | ! ----------------- |
---|
[1805] | 22 | ! |
---|
[3589] | 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: init_masks.f90 4069 2019-07-01 14:05:51Z motisi $ |
---|
[4069] | 27 | ! Masked output running index mid has been introduced as a local variable to |
---|
| 28 | ! avoid runtime error (Loop variable has been modified) in time_integration |
---|
| 29 | ! |
---|
| 30 | ! 3766 2019-02-26 16:23:41Z raasch |
---|
[3665] | 31 | ! unused variables removed |
---|
| 32 | ! |
---|
[3766] | 33 | ! 3687 2019-01-22 10:42:06Z knoop |
---|
| 34 | ! unused variables removed |
---|
| 35 | ! |
---|
[3665] | 36 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
[3589] | 37 | ! Move the control parameter "salsa" from salsa_mod to control_parameters |
---|
| 38 | ! (M. Kurppa) |
---|
| 39 | ! |
---|
| 40 | ! 3582 2018-11-29 19:16:36Z suehring |
---|
[3554] | 41 | ! add variable description |
---|
| 42 | ! |
---|
| 43 | ! 3512 2018-11-09 18:09:51Z gronemeier |
---|
[3512] | 44 | ! Bugfix: do not output ghost points if mask_x/y_loop is not specified |
---|
| 45 | ! |
---|
| 46 | ! 3467 2018-10-30 19:05:21Z suehring |
---|
[3467] | 47 | ! Implementation of a new aerosol module salsa. |
---|
| 48 | ! |
---|
| 49 | ! 3435 2018-10-26 18:25:44Z gronemeier |
---|
[3435] | 50 | ! Add checks for chemistry and radiation model |
---|
| 51 | ! Set indices for terrain-following masked output |
---|
| 52 | ! |
---|
| 53 | ! 3421 2018-10-24 18:39:32Z gronemeier |
---|
[3421] | 54 | ! Renamed output variables |
---|
| 55 | ! |
---|
| 56 | ! 3419 2018-10-24 17:27:31Z gronemeier |
---|
[3294] | 57 | ! ocean renamed ocean_mode |
---|
| 58 | ! |
---|
| 59 | ! 3274 2018-09-24 15:42:55Z knoop |
---|
[3274] | 60 | ! Modularization of all bulk cloud physics code components |
---|
| 61 | ! |
---|
| 62 | ! 3065 2018-06-12 07:03:02Z Giersch |
---|
[3065] | 63 | ! dz_stretch_level was replaced by dz_stretch_level_start |
---|
| 64 | ! |
---|
| 65 | ! 3049 2018-05-29 13:52:36Z Giersch |
---|
[3045] | 66 | ! Error messages revised |
---|
| 67 | ! |
---|
[3049] | 68 | ! 3045 2018-05-28 07:55:41Z Giersch |
---|
| 69 | ! Error messages revised |
---|
| 70 | ! |
---|
[3045] | 71 | ! 2718 2018-01-02 08:49:38Z maronga |
---|
[2716] | 72 | ! Corrected "Former revisions" section |
---|
| 73 | ! |
---|
| 74 | ! 2696 2017-12-14 17:12:51Z kanani |
---|
| 75 | ! Change in file header (GPL part) |
---|
| 76 | ! |
---|
| 77 | ! 2344 2017-08-09 11:00:34Z raasch |
---|
[2344] | 78 | ! explicit setting of initial values for array domask required due to a bug |
---|
| 79 | ! in the Cray compiler (appears only if option -eD is used) |
---|
| 80 | ! |
---|
| 81 | ! 2301 2017-06-29 16:41:21Z gronemeier |
---|
[2301] | 82 | ! Bugfix: set variable name length to global value |
---|
| 83 | ! |
---|
| 84 | ! |
---|
[2292] | 85 | ! Implementation of new microphysic scheme: cloud_scheme = 'morrison' |
---|
| 86 | ! includes two more prognostic equations for cloud drop concentration (nc) |
---|
| 87 | ! and cloud water content (qc). |
---|
| 88 | ! |
---|
| 89 | ! 2271 2017-06-09 12:34:55Z sward |
---|
[2271] | 90 | ! Changed error message |
---|
| 91 | ! |
---|
| 92 | ! 2101 2017-01-05 16:42:31Z suehring |
---|
[1321] | 93 | ! |
---|
[2032] | 94 | ! 2031 2016-10-21 15:11:58Z knoop |
---|
| 95 | ! renamed variable rho to rho_ocean |
---|
| 96 | ! |
---|
[2001] | 97 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 98 | ! Forced header and separation lines into 80 columns |
---|
| 99 | ! |
---|
[1823] | 100 | ! 1822 2016-04-07 07:49:42Z hoffmann |
---|
| 101 | ! icloud_scheme replaced by microphysics_* |
---|
| 102 | ! |
---|
[1805] | 103 | ! 1804 2016-04-05 16:30:18Z maronga |
---|
| 104 | ! Removed code for parameter file check (__check) |
---|
| 105 | ! |
---|
[1784] | 106 | ! 1783 2016-03-06 18:36:17Z raasch |
---|
| 107 | ! netcdf module name changed + related changes |
---|
| 108 | ! |
---|
[1683] | 109 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 110 | ! Code annotations made doxygen readable |
---|
| 111 | ! |
---|
[1439] | 112 | ! 1438 2014-07-22 14:14:06Z heinze |
---|
| 113 | ! +nr, qc, qr |
---|
| 114 | ! |
---|
[1415] | 115 | ! 1414 2014-05-31 11:19:48Z gronemeier |
---|
| 116 | ! Bugfix: first and last grid points as they appear in 3D volume data can now |
---|
| 117 | ! be included to masked data output |
---|
| 118 | ! |
---|
[1354] | 119 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
| 120 | ! REAL constants provided with KIND-attribute |
---|
| 121 | ! |
---|
[1325] | 122 | ! 1324 2014-03-21 09:13:16Z suehring |
---|
| 123 | ! Bugfix: ONLY statement for module netcdf_control removed |
---|
| 124 | ! |
---|
[1321] | 125 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 126 | ! ONLY-attribute added to USE-statements, |
---|
| 127 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 128 | ! kinds are defined in new module kinds, |
---|
| 129 | ! revision history before 2012 removed, |
---|
| 130 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 131 | ! all variable declaration statements |
---|
[298] | 132 | ! |
---|
[1187] | 133 | ! 1186 2013-06-18 06:22:52Z raasch |
---|
| 134 | ! bugfix: 0.0 replaced by zu(nzb) as the lowest default height level for masks, |
---|
| 135 | ! because a zero value does not work in case of ocean runs |
---|
| 136 | ! |
---|
[1037] | 137 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 138 | ! code put under GPL (PALM 3.9) |
---|
| 139 | ! |
---|
[1033] | 140 | ! 1032 2012-10-21 13:03:21Z letzel |
---|
| 141 | ! mask locations determined based on scalar positions |
---|
| 142 | ! |
---|
[1035] | 143 | ! 1031 2012-10-19 14:35:30Z raasch |
---|
| 144 | ! netCDF4 without parallel file support implemented |
---|
| 145 | ! |
---|
[997] | 146 | ! 996 2012-09-07 10:41:47Z raasch |
---|
| 147 | ! little reformatting |
---|
| 148 | ! |
---|
[979] | 149 | ! 978 2012-08-09 08:28:32Z fricke |
---|
| 150 | ! +z0h* |
---|
| 151 | ! |
---|
[810] | 152 | ! 809 2012-01-30 13:32:58Z maronga |
---|
| 153 | ! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives |
---|
| 154 | ! |
---|
[808] | 155 | ! 807 2012-01-25 11:53:51Z maronga |
---|
| 156 | ! New cpp directive "__check" implemented which is used by check_namelist_files |
---|
| 157 | ! |
---|
[449] | 158 | ! 410 2009-12-04 17:05:40Z letzel |
---|
| 159 | ! Initial revision |
---|
[298] | 160 | ! |
---|
[449] | 161 | ! |
---|
[298] | 162 | ! Description: |
---|
| 163 | ! ------------ |
---|
[1682] | 164 | !> Initialize masked data output |
---|
[298] | 165 | !------------------------------------------------------------------------------! |
---|
[1682] | 166 | SUBROUTINE init_masks |
---|
[298] | 167 | |
---|
[1320] | 168 | USE arrays_3d, & |
---|
| 169 | ONLY: zu, zw |
---|
| 170 | |
---|
[3435] | 171 | USE bulk_cloud_model_mod, & |
---|
| 172 | ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert |
---|
| 173 | |
---|
[1320] | 174 | USE control_parameters, & |
---|
[3766] | 175 | ONLY: constant_diffusion, cloud_droplets, & |
---|
[1320] | 176 | data_output_masks, data_output_masks_user, & |
---|
[3065] | 177 | doav, doav_n, domask, domask_no, dz, dz_stretch_level_start, & |
---|
| 178 | humidity, mask, masks, mask_scale, mask_i, & |
---|
[1320] | 179 | mask_i_global, mask_j, mask_j_global, mask_k, mask_k_global, & |
---|
[3435] | 180 | mask_k_over_surface, & |
---|
| 181 | mask_loop, mask_size, mask_size_l, mask_start_l, & |
---|
| 182 | mask_surface, mask_x, & |
---|
[1320] | 183 | mask_x_loop, mask_xyz_dimension, mask_y, mask_y_loop, mask_z, & |
---|
[4069] | 184 | mask_z_loop, max_masks, message_string, & |
---|
[3766] | 185 | passive_scalar, ocean_mode, varnamelength |
---|
[1320] | 186 | |
---|
| 187 | USE grid_variables, & |
---|
| 188 | ONLY: dx, dy |
---|
| 189 | |
---|
| 190 | USE indices, & |
---|
| 191 | ONLY: nx, nxl, nxr, ny, nyn, nys, nz, nzb, nzt |
---|
| 192 | |
---|
| 193 | USE kinds |
---|
| 194 | |
---|
[3687] | 195 | USE module_interface, & |
---|
| 196 | ONLY: module_interface_init_masks |
---|
| 197 | |
---|
[1783] | 198 | USE netcdf_interface, & |
---|
| 199 | ONLY: domask_unit, netcdf_data_format |
---|
[1320] | 200 | |
---|
| 201 | USE particle_attributes, & |
---|
| 202 | ONLY: particle_advection |
---|
| 203 | |
---|
[3687] | 204 | USE pegrid |
---|
[3435] | 205 | |
---|
[298] | 206 | IMPLICIT NONE |
---|
| 207 | |
---|
[3554] | 208 | CHARACTER (LEN=varnamelength) :: var !< contains variable name |
---|
| 209 | CHARACTER (LEN=7) :: unit !< contains unit of variable |
---|
[1320] | 210 | |
---|
[3554] | 211 | CHARACTER (LEN=varnamelength), DIMENSION(max_masks,100) :: do_mask !< list of output variables |
---|
| 212 | CHARACTER (LEN=varnamelength), DIMENSION(max_masks,100) :: do_mask_user !< list of user-specified output variables |
---|
[298] | 213 | |
---|
[3435] | 214 | INTEGER(iwp) :: count !< counting masking indices along a dimension |
---|
[3554] | 215 | INTEGER(iwp) :: i !< loop index |
---|
| 216 | INTEGER(iwp) :: ilen !< length of string saved in 'do_mask' |
---|
| 217 | INTEGER(iwp) :: ind(6) !< index limits (lower/upper bounds) of output array |
---|
| 218 | INTEGER(iwp) :: ind_array(1) !< array index |
---|
| 219 | INTEGER(iwp) :: j !< loop index |
---|
| 220 | INTEGER(iwp) :: k !< loop index |
---|
[3435] | 221 | INTEGER(iwp) :: m !< mask index |
---|
[4069] | 222 | INTEGER(iwp) :: mid !< masked output running index |
---|
[3554] | 223 | INTEGER(iwp) :: n !< loop index |
---|
| 224 | INTEGER(iwp) :: sender !< PE id of sending PE |
---|
[1320] | 225 | |
---|
[3554] | 226 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: tmp_array !< temporary 1D array |
---|
[298] | 227 | |
---|
[3554] | 228 | LOGICAL :: found !< true if variable is found |
---|
[2344] | 229 | |
---|
[298] | 230 | ! |
---|
[2344] | 231 | !-- Initial values are explicitly set here due to a bug in the Cray compiler |
---|
| 232 | !-- in case of assignments of initial values in declaration statements for |
---|
| 233 | !-- arrays with more than 9999 elements (appears with -eD only) |
---|
| 234 | domask = ' ' |
---|
| 235 | |
---|
| 236 | ! |
---|
[298] | 237 | !-- Allocation and initialization |
---|
[1414] | 238 | ALLOCATE( tmp_array( MAX(nx,ny,nz)+2 ) ) |
---|
[298] | 239 | |
---|
[1414] | 240 | ALLOCATE( mask_i(max_masks,nxr-nxl+2), & |
---|
| 241 | mask_j(max_masks,nyn-nys+2), & |
---|
| 242 | mask_k(max_masks,nzt-nzb+2) ) |
---|
[298] | 243 | ! |
---|
| 244 | !-- internal mask arrays ("mask,dimension,selection") |
---|
| 245 | ALLOCATE( mask(max_masks,3,mask_xyz_dimension), & |
---|
| 246 | mask_loop(max_masks,3,3) ) |
---|
[493] | 247 | |
---|
[298] | 248 | ! |
---|
[3045] | 249 | !-- Parallel mask output not yet supported. In check_parameters data format |
---|
| 250 | !-- is restricted and is switched back to non-parallel output. Therefore the |
---|
| 251 | !-- following error can not occur at the moment. |
---|
[1031] | 252 | IF ( netcdf_data_format > 4 ) THEN |
---|
[3045] | 253 | message_string = 'netCDF file formats '// & |
---|
| 254 | '5 and 6 (with parallel I/O support)'// & |
---|
| 255 | ' are currently not supported.' |
---|
[564] | 256 | CALL message( 'init_masks', 'PA0328', 1, 2, 0, 6, 0 ) |
---|
[298] | 257 | ENDIF |
---|
[553] | 258 | |
---|
[298] | 259 | ! |
---|
| 260 | !-- Store data output parameters for masked data output in few shared arrays |
---|
[996] | 261 | DO mid = 1, masks |
---|
[564] | 262 | |
---|
[553] | 263 | do_mask (mid,:) = data_output_masks(mid,:) |
---|
| 264 | do_mask_user(mid,:) = data_output_masks_user(mid,:) |
---|
| 265 | mask (mid,1,:) = mask_x(mid,:) |
---|
| 266 | mask (mid,2,:) = mask_y(mid,:) |
---|
| 267 | mask (mid,3,:) = mask_z(mid,:) |
---|
[3435] | 268 | ! |
---|
| 269 | !-- Flag a mask as terrain following |
---|
| 270 | IF ( mask_k_over_surface(mid,1) /= -1_iwp ) THEN |
---|
| 271 | mask_surface(mid) = .TRUE. |
---|
| 272 | ENDIF |
---|
| 273 | |
---|
[1353] | 274 | IF ( mask_x_loop(mid,1) == -1.0_wp .AND. mask_x_loop(mid,2) == -1.0_wp& |
---|
| 275 | .AND. mask_x_loop(mid,3) == -1.0_wp ) THEN |
---|
| 276 | mask_loop(mid,1,1:2) = -1.0_wp |
---|
| 277 | mask_loop(mid,1,3) = 0.0_wp |
---|
[564] | 278 | ELSE |
---|
| 279 | mask_loop(mid,1,:) = mask_x_loop(mid,:) |
---|
| 280 | ENDIF |
---|
[1353] | 281 | IF ( mask_y_loop(mid,1) == -1.0_wp .AND. mask_y_loop(mid,2) == -1.0_wp& |
---|
| 282 | .AND. mask_y_loop(mid,3) == -1.0_wp ) THEN |
---|
| 283 | mask_loop(mid,2,1:2) = -1.0_wp |
---|
| 284 | mask_loop(mid,2,3) = 0.0_wp |
---|
[564] | 285 | ELSE |
---|
| 286 | mask_loop(mid,2,:) = mask_y_loop(mid,:) |
---|
| 287 | ENDIF |
---|
[1353] | 288 | IF ( mask_z_loop(mid,1) == -1.0_wp .AND. mask_z_loop(mid,2) == -1.0_wp& |
---|
| 289 | .AND. mask_z_loop(mid,3) == -1.0_wp ) THEN |
---|
| 290 | mask_loop(mid,3,1:2) = -1.0_wp |
---|
| 291 | mask_loop(mid,3,3) = 0.0_wp |
---|
[564] | 292 | ELSE |
---|
| 293 | mask_loop(mid,3,:) = mask_z_loop(mid,:) |
---|
| 294 | ENDIF |
---|
| 295 | |
---|
[553] | 296 | ENDDO |
---|
| 297 | |
---|
[298] | 298 | mask_i = -1; mask_j = -1; mask_k = -1 |
---|
[553] | 299 | |
---|
[298] | 300 | ! |
---|
| 301 | !-- Global arrays are required by define_netcdf_header. |
---|
[1031] | 302 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1414] | 303 | ALLOCATE( mask_i_global(max_masks,nx+2), & |
---|
| 304 | mask_j_global(max_masks,ny+2), & |
---|
| 305 | mask_k_global(max_masks,nz+2) ) |
---|
[298] | 306 | mask_i_global = -1; mask_j_global = -1; mask_k_global = -1 |
---|
| 307 | ENDIF |
---|
| 308 | |
---|
| 309 | ! |
---|
| 310 | !-- Determine variable names for each mask |
---|
| 311 | DO mid = 1, masks |
---|
| 312 | ! |
---|
| 313 | !-- Append user-defined data output variables to the standard data output |
---|
| 314 | IF ( do_mask_user(mid,1) /= ' ' ) THEN |
---|
| 315 | i = 1 |
---|
| 316 | DO WHILE ( do_mask(mid,i) /= ' ' .AND. i <= 100 ) |
---|
| 317 | i = i + 1 |
---|
| 318 | ENDDO |
---|
| 319 | j = 1 |
---|
| 320 | DO WHILE ( do_mask_user(mid,j) /= ' ' .AND. j <= 100 ) |
---|
| 321 | IF ( i > 100 ) THEN |
---|
[3045] | 322 | WRITE ( message_string, * ) 'number of output quantitities ', & |
---|
| 323 | 'given by data_output_mask and data_output_mask_user ', & |
---|
[298] | 324 | 'exceeds the limit of 100' |
---|
[564] | 325 | CALL message( 'init_masks', 'PA0329', 1, 2, 0, 6, 0 ) |
---|
[298] | 326 | ENDIF |
---|
| 327 | do_mask(mid,i) = do_mask_user(mid,j) |
---|
| 328 | i = i + 1 |
---|
| 329 | j = j + 1 |
---|
| 330 | ENDDO |
---|
| 331 | ENDIF |
---|
| 332 | |
---|
| 333 | ! |
---|
| 334 | !-- Check and set steering parameters for mask data output and averaging |
---|
| 335 | i = 1 |
---|
[996] | 336 | DO WHILE ( do_mask(mid,i) /= ' ' .AND. i <= 100 ) |
---|
[298] | 337 | ! |
---|
| 338 | !-- Check for data averaging |
---|
| 339 | ilen = LEN_TRIM( do_mask(mid,i) ) |
---|
| 340 | j = 0 ! no data averaging |
---|
| 341 | IF ( ilen > 3 ) THEN |
---|
| 342 | IF ( do_mask(mid,i)(ilen-2:ilen) == '_av' ) THEN |
---|
| 343 | j = 1 ! data averaging |
---|
| 344 | do_mask(mid,i) = do_mask(mid,i)(1:ilen-3) |
---|
| 345 | ENDIF |
---|
| 346 | ENDIF |
---|
| 347 | var = TRIM( do_mask(mid,i) ) |
---|
| 348 | ! |
---|
| 349 | !-- Check for allowed value and set units |
---|
| 350 | SELECT CASE ( TRIM( var ) ) |
---|
| 351 | |
---|
| 352 | CASE ( 'e' ) |
---|
| 353 | IF ( constant_diffusion ) THEN |
---|
[3045] | 354 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
[298] | 355 | '" requires constant_diffusion = .FALSE.' |
---|
[564] | 356 | CALL message( 'init_masks', 'PA0103', 1, 2, 0, 6, 0 ) |
---|
[298] | 357 | ENDIF |
---|
| 358 | unit = 'm2/s2' |
---|
| 359 | |
---|
[3421] | 360 | CASE ( 'thetal' ) |
---|
[3274] | 361 | IF ( .NOT. bulk_cloud_model ) THEN |
---|
[3045] | 362 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
[3274] | 363 | '" requires bulk_cloud_model = .TRUE.' |
---|
[773] | 364 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
[771] | 365 | ENDIF |
---|
| 366 | unit = 'K' |
---|
| 367 | |
---|
[2292] | 368 | CASE ( 'nc' ) |
---|
[3274] | 369 | IF ( .NOT. bulk_cloud_model ) THEN |
---|
[3045] | 370 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
[3274] | 371 | '" requires bulk_cloud_model = .TRUE.' |
---|
[2292] | 372 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
| 373 | ELSEIF ( .NOT. microphysics_morrison ) THEN |
---|
[3045] | 374 | message_string = 'output of "' // TRIM( var ) // '" ' // & |
---|
| 375 | 'requires = morrison' |
---|
[2292] | 376 | CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 ) |
---|
| 377 | ENDIF |
---|
| 378 | unit = '1/m3' |
---|
| 379 | |
---|
[1438] | 380 | CASE ( 'nr' ) |
---|
[3274] | 381 | IF ( .NOT. bulk_cloud_model ) THEN |
---|
[3045] | 382 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
[3274] | 383 | '" requires bulk_cloud_model = .TRUE.' |
---|
[1438] | 384 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
[1822] | 385 | ELSEIF ( .NOT. microphysics_seifert ) THEN |
---|
[3045] | 386 | message_string = 'output of "' // TRIM( var ) // '"' // & |
---|
| 387 | 'requires cloud_scheme = seifert_beheng' |
---|
[1438] | 388 | CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 ) |
---|
| 389 | ENDIF |
---|
| 390 | unit = '1/m3' |
---|
| 391 | |
---|
[298] | 392 | CASE ( 'pc', 'pr' ) |
---|
| 393 | IF ( .NOT. particle_advection ) THEN |
---|
[3045] | 394 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 395 | '" requires a "particles_par"-NAMELIST in the ', & |
---|
[298] | 396 | 'parameter file (PARIN)' |
---|
[564] | 397 | CALL message( 'init_masks', 'PA0104', 1, 2, 0, 6, 0 ) |
---|
[298] | 398 | ENDIF |
---|
| 399 | IF ( TRIM( var ) == 'pc' ) unit = 'number' |
---|
| 400 | IF ( TRIM( var ) == 'pr' ) unit = 'm' |
---|
| 401 | |
---|
[3421] | 402 | CASE ( 'q', 'thetav' ) |
---|
[298] | 403 | IF ( .NOT. humidity ) THEN |
---|
[3045] | 404 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
[298] | 405 | '" requires humidity = .TRUE.' |
---|
[564] | 406 | CALL message( 'init_masks', 'PA0105', 1, 2, 0, 6, 0 ) |
---|
[298] | 407 | ENDIF |
---|
| 408 | IF ( TRIM( var ) == 'q' ) unit = 'kg/kg' |
---|
[3421] | 409 | IF ( TRIM( var ) == 'thetav' ) unit = 'K' |
---|
[298] | 410 | |
---|
[1438] | 411 | CASE ( 'qc' ) |
---|
[3274] | 412 | IF ( .NOT. bulk_cloud_model ) THEN |
---|
[3045] | 413 | message_string = 'output of "' // TRIM( var ) // '"' // & |
---|
[3274] | 414 | 'requires bulk_cloud_model = .TRUE.' |
---|
[1438] | 415 | CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
| 416 | ENDIF |
---|
| 417 | unit = 'kg/kg' |
---|
| 418 | |
---|
[298] | 419 | CASE ( 'ql' ) |
---|
[3274] | 420 | IF ( .NOT. ( bulk_cloud_model .OR. cloud_droplets ) ) THEN |
---|
[3045] | 421 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
[3274] | 422 | '" requires bulk_cloud_model = .TRUE. or ', & |
---|
| 423 | 'cloud_droplets = .TRUE.' |
---|
[3045] | 424 | CALL message( 'init_masks', 'PA0106', 1, 2, 0, 6, 0 ) |
---|
[298] | 425 | ENDIF |
---|
| 426 | unit = 'kg/kg' |
---|
| 427 | |
---|
| 428 | CASE ( 'ql_c', 'ql_v', 'ql_vp' ) |
---|
| 429 | IF ( .NOT. cloud_droplets ) THEN |
---|
[3045] | 430 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
[298] | 431 | '" requires cloud_droplets = .TRUE.' |
---|
[564] | 432 | CALL message( 'init_masks', 'PA0107', 1, 2, 0, 6, 0 ) |
---|
[298] | 433 | ENDIF |
---|
| 434 | IF ( TRIM( var ) == 'ql_c' ) unit = 'kg/kg' |
---|
| 435 | IF ( TRIM( var ) == 'ql_v' ) unit = 'm3' |
---|
| 436 | IF ( TRIM( var ) == 'ql_vp' ) unit = 'none' |
---|
| 437 | |
---|
| 438 | CASE ( 'qv' ) |
---|
[3274] | 439 | IF ( .NOT. bulk_cloud_model ) THEN |
---|
[3045] | 440 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
[3274] | 441 | '" requires bulk_cloud_model = .TRUE.' |
---|
[564] | 442 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
[298] | 443 | ENDIF |
---|
| 444 | unit = 'kg/kg' |
---|
| 445 | |
---|
[1438] | 446 | CASE ( 'qr' ) |
---|
[3274] | 447 | IF ( .NOT. bulk_cloud_model ) THEN |
---|
[3045] | 448 | message_string = 'output of "' // TRIM( var ) // '" ' // & |
---|
[3274] | 449 | 'requires bulk_cloud_model = .TRUE.' |
---|
[1438] | 450 | CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
[1822] | 451 | ELSEIF ( .NOT. microphysics_seifert ) THEN |
---|
[3045] | 452 | message_string = 'output of "' // TRIM( var ) // '" ' // & |
---|
| 453 | 'requires cloud_scheme = seifert_beheng' |
---|
[1438] | 454 | CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 ) |
---|
| 455 | ENDIF |
---|
| 456 | unit = 'kg/kg' |
---|
| 457 | |
---|
[3421] | 458 | CASE ( 'rho_sea_water' ) |
---|
[3294] | 459 | IF ( .NOT. ocean_mode ) THEN |
---|
[3045] | 460 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
[3294] | 461 | '" requires ocean mode' |
---|
[564] | 462 | CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 ) |
---|
[298] | 463 | ENDIF |
---|
| 464 | unit = 'kg/m3' |
---|
| 465 | |
---|
| 466 | CASE ( 's' ) |
---|
| 467 | IF ( .NOT. passive_scalar ) THEN |
---|
[3045] | 468 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
[298] | 469 | '" requires passive_scalar = .TRUE.' |
---|
[564] | 470 | CALL message( 'init_masks', 'PA0110', 1, 2, 0, 6, 0 ) |
---|
[298] | 471 | ENDIF |
---|
| 472 | unit = 'conc' |
---|
| 473 | |
---|
| 474 | CASE ( 'sa' ) |
---|
[3294] | 475 | IF ( .NOT. ocean_mode ) THEN |
---|
[3045] | 476 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
[3294] | 477 | '" requires ocean mode' |
---|
[564] | 478 | CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 ) |
---|
[298] | 479 | ENDIF |
---|
| 480 | unit = 'psu' |
---|
| 481 | |
---|
[3421] | 482 | CASE ( 'us*', 't*', 'lwp*', 'pra*', 'prr*', 'z0*', 'z0h*' ) |
---|
[3045] | 483 | WRITE ( message_string, * ) 'illegal value for data_', & |
---|
| 484 | 'output: "', TRIM( var ), '" is only allowed', & |
---|
[298] | 485 | 'for horizontal cross section' |
---|
[564] | 486 | CALL message( 'init_masks', 'PA0111', 1, 2, 0, 6, 0 ) |
---|
[298] | 487 | |
---|
[3421] | 488 | CASE ( 'p', 'theta', 'u', 'v', 'w' ) |
---|
[298] | 489 | IF ( TRIM( var ) == 'p' ) unit = 'Pa' |
---|
[3421] | 490 | IF ( TRIM( var ) == 'theta' ) unit = 'K' |
---|
[298] | 491 | IF ( TRIM( var ) == 'u' ) unit = 'm/s' |
---|
| 492 | IF ( TRIM( var ) == 'v' ) unit = 'm/s' |
---|
| 493 | IF ( TRIM( var ) == 'w' ) unit = 'm/s' |
---|
| 494 | CONTINUE |
---|
| 495 | |
---|
| 496 | CASE DEFAULT |
---|
[3687] | 497 | ! |
---|
| 498 | !-- Allocate arrays for other modules |
---|
| 499 | CALL module_interface_init_masks( var, unit ) |
---|
[298] | 500 | |
---|
| 501 | IF ( unit == 'illegal' ) THEN |
---|
| 502 | IF ( do_mask_user(mid,1) /= ' ' ) THEN |
---|
[3045] | 503 | WRITE ( message_string, * ) 'illegal value for data_', & |
---|
| 504 | 'output_masks or data_output_masks_user: "', & |
---|
[298] | 505 | TRIM( do_mask(mid,i) ), '"' |
---|
[3045] | 506 | CALL message( 'init_masks', 'PA0018', 1, 2, 0, 6, 0 ) |
---|
[298] | 507 | ELSE |
---|
[3045] | 508 | WRITE ( message_string, * ) 'illegal value for data_', & |
---|
| 509 | ' output_masks : "', TRIM( do_mask(mid,i) ), '"' |
---|
[564] | 510 | CALL message( 'init_masks', 'PA0330', 1, 2, 0, 6, 0 ) |
---|
[298] | 511 | ENDIF |
---|
| 512 | ENDIF |
---|
| 513 | |
---|
| 514 | END SELECT |
---|
| 515 | ! |
---|
| 516 | !-- Set the internal steering parameters appropriately |
---|
| 517 | domask_no(mid,j) = domask_no(mid,j) + 1 |
---|
| 518 | domask(mid,j,domask_no(mid,j)) = do_mask(mid,i) |
---|
| 519 | domask_unit(mid,j,domask_no(mid,j)) = unit |
---|
| 520 | |
---|
| 521 | IF ( j == 1 ) THEN |
---|
| 522 | ! |
---|
| 523 | !-- Check, if variable is already subject to averaging |
---|
| 524 | found = .FALSE. |
---|
| 525 | DO k = 1, doav_n |
---|
| 526 | IF ( TRIM( doav(k) ) == TRIM( var ) ) found = .TRUE. |
---|
| 527 | ENDDO |
---|
| 528 | |
---|
| 529 | IF ( .NOT. found ) THEN |
---|
| 530 | doav_n = doav_n + 1 |
---|
| 531 | doav(doav_n) = var |
---|
| 532 | ENDIF |
---|
| 533 | ENDIF |
---|
| 534 | |
---|
| 535 | i = i + 1 |
---|
| 536 | |
---|
| 537 | ENDDO ! do_mask(mid,i) |
---|
| 538 | ENDDO ! mid |
---|
| 539 | |
---|
| 540 | |
---|
| 541 | ! |
---|
| 542 | !-- Determine mask locations for each mask |
---|
| 543 | DO mid = 1, masks |
---|
| 544 | ! |
---|
| 545 | !-- Set local masks for each subdomain along all three dimensions |
---|
| 546 | CALL set_mask_locations( 1, dx, 'dx', nx, 'nx', nxl, nxr ) |
---|
| 547 | CALL set_mask_locations( 2, dy, 'dy', ny, 'ny', nys, nyn ) |
---|
[3435] | 548 | IF ( .NOT. mask_surface(mid) ) THEN |
---|
| 549 | CALL set_mask_locations( 3, dz(1), 'dz', nz, 'nz', nzb, nzt ) |
---|
| 550 | ELSE |
---|
[298] | 551 | ! |
---|
[3435] | 552 | !-- Set vertical mask locations and size in case of terrain-following |
---|
| 553 | !-- output |
---|
| 554 | count = 0 |
---|
| 555 | DO WHILE ( mask_k_over_surface(mid, count+1) >= 0 ) |
---|
| 556 | m = mask_k_over_surface(mid, count+1) |
---|
| 557 | IF ( m > nz+1 ) THEN |
---|
| 558 | WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' ) & |
---|
| 559 | m,' in mask ',mid,' along dimension ', 3, & |
---|
| 560 | ' exceeds (nz+1) = ',nz+1 |
---|
| 561 | CALL message( 'init_masks', 'PA0331', 1, 2, 0, 6, 0 ) |
---|
| 562 | ENDIF |
---|
| 563 | count = count + 1 |
---|
| 564 | mask_k(mid,count) = mask_k_over_surface(mid, count) |
---|
| 565 | IF ( count == mask_xyz_dimension ) EXIT |
---|
| 566 | ENDDO |
---|
| 567 | mask_start_l(mid,3) = 1 |
---|
| 568 | mask_size(mid,3) = count |
---|
| 569 | mask_size_l(mid,3) = count |
---|
| 570 | ENDIF |
---|
| 571 | ! |
---|
[298] | 572 | !-- Set global masks along all three dimensions (required by |
---|
| 573 | !-- define_netcdf_header). |
---|
[1804] | 574 | #if defined( __parallel ) |
---|
[298] | 575 | ! |
---|
| 576 | !-- PE0 receives partial arrays from all processors of the respective mask |
---|
| 577 | !-- and outputs them. Here a barrier has to be set, because otherwise |
---|
| 578 | !-- "-MPI- FATAL: Remote protocol queue full" may occur. |
---|
[807] | 579 | |
---|
[298] | 580 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 581 | |
---|
| 582 | IF ( myid == 0 ) THEN |
---|
| 583 | ! |
---|
| 584 | !-- Local arrays can be relocated directly. |
---|
| 585 | mask_i_global(mid,mask_start_l(mid,1): & |
---|
| 586 | mask_start_l(mid,1)+mask_size_l(mid,1)-1) = & |
---|
| 587 | mask_i(mid,:mask_size_l(mid,1)) |
---|
| 588 | mask_j_global(mid,mask_start_l(mid,2): & |
---|
| 589 | mask_start_l(mid,2)+mask_size_l(mid,2)-1) = & |
---|
| 590 | mask_j(mid,:mask_size_l(mid,2)) |
---|
| 591 | mask_k_global(mid,mask_start_l(mid,3): & |
---|
| 592 | mask_start_l(mid,3)+mask_size_l(mid,3)-1) = & |
---|
| 593 | mask_k(mid,:mask_size_l(mid,3)) |
---|
| 594 | ! |
---|
| 595 | !-- Receive data from all other PEs. |
---|
| 596 | DO n = 1, numprocs-1 |
---|
| 597 | ! |
---|
| 598 | !-- Receive index limits first, then arrays. |
---|
| 599 | !-- Index limits are received in arbitrary order from the PEs. |
---|
| 600 | CALL MPI_RECV( ind(1), 6, MPI_INTEGER, MPI_ANY_SOURCE, 0, & |
---|
| 601 | comm2d, status, ierr ) |
---|
| 602 | ! |
---|
| 603 | !-- Not all PEs have data for the mask. |
---|
| 604 | IF ( ind(1) /= -9999 ) THEN |
---|
| 605 | sender = status(MPI_SOURCE) |
---|
| 606 | CALL MPI_RECV( tmp_array(ind(1)), ind(2)-ind(1)+1, & |
---|
[363] | 607 | MPI_INTEGER, sender, 1, comm2d, status, ierr ) |
---|
[298] | 608 | mask_i_global(mid,ind(1):ind(2)) = tmp_array(ind(1):ind(2)) |
---|
| 609 | CALL MPI_RECV( tmp_array(ind(3)), ind(4)-ind(3)+1, & |
---|
[363] | 610 | MPI_INTEGER, sender, 2, comm2d, status, ierr ) |
---|
[298] | 611 | mask_j_global(mid,ind(3):ind(4)) = tmp_array(ind(3):ind(4)) |
---|
| 612 | CALL MPI_RECV( tmp_array(ind(5)), ind(6)-ind(5)+1, & |
---|
[363] | 613 | MPI_INTEGER, sender, 3, comm2d, status, ierr ) |
---|
[298] | 614 | mask_k_global(mid,ind(5):ind(6)) = tmp_array(ind(5):ind(6)) |
---|
| 615 | ENDIF |
---|
| 616 | ENDDO |
---|
| 617 | |
---|
| 618 | ELSE |
---|
| 619 | ! |
---|
| 620 | !-- If at least part of the mask resides on the PE, send the index limits |
---|
| 621 | !-- for the target array, otherwise send -9999 to PE0. |
---|
[996] | 622 | IF ( mask_size_l(mid,1) > 0 .AND. mask_size_l(mid,2) > 0 .AND. & |
---|
| 623 | mask_size_l(mid,3) > 0 ) THEN |
---|
[298] | 624 | ind(1) = mask_start_l(mid,1) |
---|
| 625 | ind(2) = mask_start_l(mid,1) + mask_size_l(mid,1) - 1 |
---|
| 626 | ind(3) = mask_start_l(mid,2) |
---|
| 627 | ind(4) = mask_start_l(mid,2) + mask_size_l(mid,2) - 1 |
---|
| 628 | ind(5) = mask_start_l(mid,3) |
---|
| 629 | ind(6) = mask_start_l(mid,3) + mask_size_l(mid,3) - 1 |
---|
| 630 | ELSE |
---|
| 631 | ind(1) = -9999; ind(2) = -9999 |
---|
| 632 | ind(3) = -9999; ind(4) = -9999 |
---|
| 633 | ind(5) = -9999; ind(6) = -9999 |
---|
| 634 | ENDIF |
---|
| 635 | CALL MPI_SEND( ind(1), 6, MPI_INTEGER, 0, 0, comm2d, ierr ) |
---|
| 636 | ! |
---|
| 637 | !-- If applicable, send data to PE0. |
---|
| 638 | IF ( ind(1) /= -9999 ) THEN |
---|
| 639 | tmp_array(:mask_size_l(mid,1)) = mask_i(mid,:mask_size_l(mid,1)) |
---|
| 640 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,1), & |
---|
[363] | 641 | MPI_INTEGER, 0, 1, comm2d, ierr ) |
---|
[298] | 642 | tmp_array(:mask_size_l(mid,2)) = mask_j(mid,:mask_size_l(mid,2)) |
---|
| 643 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,2), & |
---|
[363] | 644 | MPI_INTEGER, 0, 2, comm2d, ierr ) |
---|
[298] | 645 | tmp_array(:mask_size_l(mid,3)) = mask_k(mid,:mask_size_l(mid,3)) |
---|
| 646 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,3), & |
---|
[363] | 647 | MPI_INTEGER, 0, 3, comm2d, ierr ) |
---|
[298] | 648 | ENDIF |
---|
| 649 | ENDIF |
---|
| 650 | ! |
---|
| 651 | !-- A barrier has to be set, because otherwise some PEs may proceed too fast |
---|
| 652 | !-- so that PE0 may receive wrong data on tag 0. |
---|
| 653 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
[409] | 654 | |
---|
[1031] | 655 | IF ( netcdf_data_format > 4 ) THEN |
---|
[409] | 656 | |
---|
[1414] | 657 | CALL MPI_BCAST( mask_i_global(mid,:), nx+2, MPI_INTEGER, 0, comm2d, & |
---|
[493] | 658 | ierr ) |
---|
[1414] | 659 | CALL MPI_BCAST( mask_j_global(mid,:), ny+2, MPI_INTEGER, 0, comm2d, & |
---|
[493] | 660 | ierr ) |
---|
[1414] | 661 | CALL MPI_BCAST( mask_k_global(mid,:), nz+2, MPI_INTEGER, 0, comm2d, & |
---|
[493] | 662 | ierr ) |
---|
[1682] | 663 | |
---|
[409] | 664 | ENDIF |
---|
[298] | 665 | |
---|
[1804] | 666 | #else |
---|
[298] | 667 | ! |
---|
| 668 | !-- Local arrays can be relocated directly. |
---|
| 669 | mask_i_global(mid,:) = mask_i(mid,:) |
---|
| 670 | mask_j_global(mid,:) = mask_j(mid,:) |
---|
| 671 | mask_k_global(mid,:) = mask_k(mid,:) |
---|
| 672 | #endif |
---|
| 673 | ENDDO ! mid |
---|
| 674 | |
---|
| 675 | DEALLOCATE( tmp_array ) |
---|
| 676 | ! |
---|
| 677 | !-- Internal mask arrays cannot be deallocated on PE 0 because they are |
---|
| 678 | !-- required for header output on PE 0. |
---|
| 679 | IF ( myid /= 0 ) DEALLOCATE( mask, mask_loop ) |
---|
| 680 | |
---|
| 681 | CONTAINS |
---|
[493] | 682 | |
---|
[298] | 683 | !------------------------------------------------------------------------------! |
---|
| 684 | ! Description: |
---|
| 685 | ! ------------ |
---|
[1682] | 686 | !> Set local mask for each subdomain along 'dim' direction. |
---|
[298] | 687 | !------------------------------------------------------------------------------! |
---|
[1682] | 688 | SUBROUTINE set_mask_locations( dim, dxyz, dxyz_string, nxyz, nxyz_string, & |
---|
| 689 | lb, ub ) |
---|
[298] | 690 | |
---|
| 691 | IMPLICIT NONE |
---|
| 692 | |
---|
[1682] | 693 | CHARACTER (LEN=2) :: dxyz_string !< |
---|
| 694 | CHARACTER (LEN=2) :: nxyz_string !< |
---|
[1320] | 695 | |
---|
[1682] | 696 | INTEGER(iwp) :: count !< |
---|
| 697 | INTEGER(iwp) :: count_l !< |
---|
| 698 | INTEGER(iwp) :: dim !< |
---|
| 699 | INTEGER(iwp) :: m !< |
---|
| 700 | INTEGER(iwp) :: loop_begin !< |
---|
| 701 | INTEGER(iwp) :: loop_end !< |
---|
| 702 | INTEGER(iwp) :: loop_stride !< |
---|
| 703 | INTEGER(iwp) :: lb !< |
---|
| 704 | INTEGER(iwp) :: nxyz !< |
---|
| 705 | INTEGER(iwp) :: ub !< |
---|
[1320] | 706 | |
---|
[1682] | 707 | REAL(wp) :: dxyz !< |
---|
| 708 | REAL(wp) :: ddxyz !< |
---|
| 709 | REAL(wp) :: tmp1 !< |
---|
| 710 | REAL(wp) :: tmp2 !< |
---|
[298] | 711 | |
---|
[1353] | 712 | count = 0; count_l = 0 |
---|
| 713 | ddxyz = 1.0_wp / dxyz |
---|
| 714 | tmp1 = 0.0_wp |
---|
| 715 | tmp2 = 0.0_wp |
---|
[298] | 716 | |
---|
[1353] | 717 | IF ( mask(mid,dim,1) >= 0.0_wp ) THEN |
---|
[298] | 718 | ! |
---|
| 719 | !-- use predefined mask_* array |
---|
[1353] | 720 | DO WHILE ( mask(mid,dim,count+1) >= 0.0_wp ) |
---|
[298] | 721 | count = count + 1 |
---|
| 722 | IF ( dim == 1 .OR. dim == 2 ) THEN |
---|
[1353] | 723 | m = NINT( mask(mid,dim,count) * mask_scale(dim) * ddxyz - 0.5_wp ) |
---|
[1414] | 724 | IF ( m < 0 ) m = 0 ! avoid negative values |
---|
[298] | 725 | ELSEIF ( dim == 3 ) THEN |
---|
| 726 | ind_array = & |
---|
[595] | 727 | MINLOC( ABS( mask(mid,dim,count) * mask_scale(dim) - zu ) ) |
---|
[298] | 728 | m = ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1 |
---|
| 729 | ENDIF |
---|
[1414] | 730 | IF ( m > (nxyz+1) ) THEN |
---|
[3045] | 731 | WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' ) & |
---|
| 732 | m,' in mask ',mid,' along dimension ',dim, & |
---|
[1414] | 733 | ' exceeds (',nxyz_string,'+1) = ',nxyz+1 |
---|
[564] | 734 | CALL message( 'init_masks', 'PA0331', 1, 2, 0, 6, 0 ) |
---|
[298] | 735 | ENDIF |
---|
[1414] | 736 | IF ( ( m >= lb .AND. m <= ub ) .OR. & |
---|
| 737 | ( m == (nxyz+1) .AND. ub == nxyz ) ) THEN |
---|
[298] | 738 | IF ( count_l == 0 ) mask_start_l(mid,dim) = count |
---|
| 739 | count_l = count_l + 1 |
---|
| 740 | IF ( dim == 1 ) THEN |
---|
| 741 | mask_i(mid,count_l) = m |
---|
| 742 | ELSEIF ( dim == 2 ) THEN |
---|
| 743 | mask_j(mid,count_l) = m |
---|
| 744 | ELSEIF ( dim == 3 ) THEN |
---|
| 745 | mask_k(mid,count_l) = m |
---|
| 746 | ENDIF |
---|
| 747 | ENDIF |
---|
| 748 | IF ( count == mask_xyz_dimension ) EXIT |
---|
| 749 | ENDDO |
---|
| 750 | mask_size(mid,dim) = count |
---|
| 751 | mask_size_l(mid,dim) = count_l |
---|
| 752 | |
---|
| 753 | ELSE |
---|
| 754 | ! |
---|
| 755 | !-- use predefined mask_loop_* array, or use the default (all grid points |
---|
| 756 | !-- along this direction) |
---|
[1353] | 757 | IF ( mask_loop(mid,dim,1) < 0.0_wp ) THEN |
---|
[298] | 758 | tmp1 = mask_loop(mid,dim,1) |
---|
[1186] | 759 | mask_loop(mid,dim,1) = zw(nzb) ! lowest level (default) |
---|
[298] | 760 | ENDIF |
---|
| 761 | IF ( dim == 1 .OR. dim == 2 ) THEN |
---|
[1353] | 762 | IF ( mask_loop(mid,dim,2) < 0.0_wp ) THEN |
---|
[298] | 763 | tmp2 = mask_loop(mid,dim,2) |
---|
[3512] | 764 | mask_loop(mid,dim,2) = nxyz*dxyz / mask_scale(dim) ! (default) |
---|
[298] | 765 | ENDIF |
---|
| 766 | IF ( MAXVAL( mask_loop(mid,dim,1:2) ) & |
---|
[1414] | 767 | > (nxyz+1) * dxyz / mask_scale(dim) ) THEN |
---|
[303] | 768 | WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),5A,I1,A,F9.3)' ) & |
---|
[3045] | 769 | 'mask_loop(',mid,',',dim,',1)=',mask_loop(mid,dim,1), & |
---|
[303] | 770 | ' and/or mask_loop(',mid,',',dim,',2)=', & |
---|
[3045] | 771 | mask_loop(mid,dim,2),' exceed (', & |
---|
| 772 | nxyz_string,'+1)*',dxyz_string,'/mask_scale(',dim,')=', & |
---|
[1414] | 773 | (nxyz+1)*dxyz/mask_scale(dim) |
---|
[564] | 774 | CALL message( 'init_masks', 'PA0332', 1, 2, 0, 6, 0 ) |
---|
[298] | 775 | ENDIF |
---|
[3045] | 776 | loop_begin = NINT( mask_loop(mid,dim,1) * mask_scale(dim) & |
---|
[1353] | 777 | * ddxyz - 0.5_wp ) |
---|
[3045] | 778 | loop_end = NINT( mask_loop(mid,dim,2) * mask_scale(dim) & |
---|
[1353] | 779 | * ddxyz - 0.5_wp ) |
---|
[3045] | 780 | loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) & |
---|
[1032] | 781 | * ddxyz ) |
---|
[1414] | 782 | IF ( loop_begin == -1 ) loop_begin = 0 ! avoid negative values |
---|
[298] | 783 | ELSEIF ( dim == 3 ) THEN |
---|
[1353] | 784 | IF ( mask_loop(mid,dim,2) < 0.0_wp ) THEN |
---|
[298] | 785 | tmp2 = mask_loop(mid,dim,2) |
---|
[1414] | 786 | mask_loop(mid,dim,2) = zu(nz+1) / mask_scale(dim) ! (default) |
---|
[298] | 787 | ENDIF |
---|
| 788 | IF ( MAXVAL( mask_loop(mid,dim,1:2) ) & |
---|
[1414] | 789 | > zu(nz+1) / mask_scale(dim) ) THEN |
---|
[3045] | 790 | WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),A,I1,A,F9.3)' ) & |
---|
| 791 | 'mask_loop(',mid,',',dim,',1)=',mask_loop(mid,dim,1), & |
---|
[303] | 792 | ' and/or mask_loop(',mid,',',dim,',2)=', & |
---|
[3045] | 793 | mask_loop(mid,dim,2),' exceed zu(nz+1)/mask_scale(',dim, & |
---|
[1414] | 794 | ')=',zu(nz+1)/mask_scale(dim) |
---|
[564] | 795 | CALL message( 'init_masks', 'PA0333', 1, 2, 0, 6, 0 ) |
---|
[298] | 796 | ENDIF |
---|
[303] | 797 | ind_array = & |
---|
[595] | 798 | MINLOC( ABS( mask_loop(mid,dim,1) * mask_scale(dim) - zu ) ) |
---|
[298] | 799 | loop_begin = & |
---|
[303] | 800 | ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1 |
---|
| 801 | ind_array = & |
---|
[595] | 802 | MINLOC( ABS( mask_loop(mid,dim,2) * mask_scale(dim) - zu ) ) |
---|
[298] | 803 | loop_end = ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1 |
---|
| 804 | ! |
---|
[303] | 805 | !-- The following line assumes a constant vertical grid spacing within |
---|
| 806 | !-- the vertical mask range; it fails for vertical grid stretching. |
---|
[3065] | 807 | !-- Maybe revise later. Issue warning but continue execution. ABS(...) |
---|
| 808 | !-- within the IF statement is necessary because the default value of |
---|
| 809 | !-- dz_stretch_level_start is -9999999.9_wp. |
---|
[303] | 810 | loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) * ddxyz ) |
---|
| 811 | |
---|
[3065] | 812 | IF ( mask_loop(mid,dim,2) * mask_scale(dim) > & |
---|
| 813 | ABS( dz_stretch_level_start(1) ) ) THEN |
---|
[3045] | 814 | WRITE ( message_string, '(A,I3,A,I1,A,F9.3,A,F8.2,3A)' ) & |
---|
| 815 | 'mask_loop(',mid,',',dim,',2)=', mask_loop(mid,dim,2), & |
---|
[3065] | 816 | ' exceeds dz_stretch_level=',dz_stretch_level_start(1), & |
---|
[3046] | 817 | '.&Vertical mask locations will not ', & |
---|
[3045] | 818 | 'match the desired heights within the stretching ', & |
---|
[2271] | 819 | 'region.' |
---|
[564] | 820 | CALL message( 'init_masks', 'PA0334', 0, 1, 0, 6, 0 ) |
---|
[303] | 821 | ENDIF |
---|
| 822 | |
---|
[298] | 823 | ENDIF |
---|
| 824 | ! |
---|
| 825 | !-- If necessary, reset mask_loop(mid,dim,1) and mask_loop(mid,dim,2). |
---|
[1353] | 826 | IF ( tmp1 < 0.0_wp ) mask_loop(mid,dim,1) = tmp1 |
---|
| 827 | IF ( tmp2 < 0.0_wp ) mask_loop(mid,dim,2) = tmp2 |
---|
[298] | 828 | ! |
---|
| 829 | !-- The default stride +/-1 (every grid point) applies if |
---|
| 830 | !-- mask_loop(mid,dim,3) is not specified (its default is zero). |
---|
| 831 | IF ( loop_stride == 0 ) THEN |
---|
| 832 | IF ( loop_end >= loop_begin ) THEN |
---|
| 833 | loop_stride = 1 |
---|
| 834 | ELSE |
---|
| 835 | loop_stride = -1 |
---|
| 836 | ENDIF |
---|
| 837 | ENDIF |
---|
| 838 | DO m = loop_begin, loop_end, loop_stride |
---|
| 839 | count = count + 1 |
---|
[1414] | 840 | IF ( ( m >= lb .AND. m <= ub ) .OR. & |
---|
| 841 | ( m == (nxyz+1) .AND. ub == nxyz ) ) THEN |
---|
[298] | 842 | IF ( count_l == 0 ) mask_start_l(mid,dim) = count |
---|
| 843 | count_l = count_l + 1 |
---|
| 844 | IF ( dim == 1 ) THEN |
---|
| 845 | mask_i(mid,count_l) = m |
---|
| 846 | ELSEIF ( dim == 2 ) THEN |
---|
| 847 | mask_j(mid,count_l) = m |
---|
| 848 | ELSEIF ( dim == 3 ) THEN |
---|
| 849 | mask_k(mid,count_l) = m |
---|
| 850 | ENDIF |
---|
| 851 | ENDIF |
---|
| 852 | ENDDO |
---|
| 853 | mask_size(mid,dim) = count |
---|
| 854 | mask_size_l(mid,dim) = count_l |
---|
[1414] | 855 | |
---|
[298] | 856 | ENDIF |
---|
| 857 | |
---|
| 858 | END SUBROUTINE set_mask_locations |
---|
| 859 | |
---|
| 860 | END SUBROUTINE init_masks |
---|