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