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