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