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