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