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