[298] | 1 | SUBROUTINE init_masks |
---|
| 2 | |
---|
[1036] | 3 | !--------------------------------------------------------------------------------! |
---|
| 4 | ! This file is part of PALM. |
---|
| 5 | ! |
---|
| 6 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 7 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
| 8 | ! either version 3 of the License, or (at your option) any later version. |
---|
| 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 | ! |
---|
[1310] | 17 | ! Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
[1036] | 18 | !--------------------------------------------------------------------------------! |
---|
| 19 | ! |
---|
[484] | 20 | ! Current revisions: |
---|
[298] | 21 | ! ----------------- |
---|
[1354] | 22 | ! |
---|
[1439] | 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: init_masks.f90 1439 2014-07-22 14:16:14Z letzel $ |
---|
| 27 | ! |
---|
[1439] | 28 | ! 1438 2014-07-22 14:14:06Z heinze |
---|
| 29 | ! +nr, qc, qr |
---|
| 30 | ! |
---|
[1415] | 31 | ! 1414 2014-05-31 11:19:48Z gronemeier |
---|
| 32 | ! Bugfix: first and last grid points as they appear in 3D volume data can now |
---|
| 33 | ! be included to masked data output |
---|
| 34 | ! |
---|
[1354] | 35 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
| 36 | ! REAL constants provided with KIND-attribute |
---|
| 37 | ! |
---|
[1325] | 38 | ! 1324 2014-03-21 09:13:16Z suehring |
---|
| 39 | ! Bugfix: ONLY statement for module netcdf_control removed |
---|
| 40 | ! |
---|
[1321] | 41 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 42 | ! ONLY-attribute added to USE-statements, |
---|
| 43 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 44 | ! kinds are defined in new module kinds, |
---|
| 45 | ! revision history before 2012 removed, |
---|
| 46 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 47 | ! all variable declaration statements |
---|
[298] | 48 | ! |
---|
[1187] | 49 | ! 1186 2013-06-18 06:22:52Z raasch |
---|
| 50 | ! bugfix: 0.0 replaced by zu(nzb) as the lowest default height level for masks, |
---|
| 51 | ! because a zero value does not work in case of ocean runs |
---|
| 52 | ! |
---|
[1037] | 53 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 54 | ! code put under GPL (PALM 3.9) |
---|
| 55 | ! |
---|
[1033] | 56 | ! 1032 2012-10-21 13:03:21Z letzel |
---|
| 57 | ! mask locations determined based on scalar positions |
---|
| 58 | ! |
---|
[1035] | 59 | ! 1031 2012-10-19 14:35:30Z raasch |
---|
| 60 | ! netCDF4 without parallel file support implemented |
---|
| 61 | ! |
---|
[997] | 62 | ! 996 2012-09-07 10:41:47Z raasch |
---|
| 63 | ! little reformatting |
---|
| 64 | ! |
---|
[979] | 65 | ! 978 2012-08-09 08:28:32Z fricke |
---|
| 66 | ! +z0h* |
---|
| 67 | ! |
---|
[810] | 68 | ! 809 2012-01-30 13:32:58Z maronga |
---|
| 69 | ! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives |
---|
| 70 | ! |
---|
[808] | 71 | ! 807 2012-01-25 11:53:51Z maronga |
---|
| 72 | ! New cpp directive "__check" implemented which is used by check_namelist_files |
---|
| 73 | ! |
---|
[449] | 74 | ! 410 2009-12-04 17:05:40Z letzel |
---|
| 75 | ! Initial revision |
---|
[298] | 76 | ! |
---|
[449] | 77 | ! |
---|
[298] | 78 | ! Description: |
---|
| 79 | ! ------------ |
---|
| 80 | ! Initialize masked data output |
---|
| 81 | !------------------------------------------------------------------------------! |
---|
| 82 | |
---|
[1320] | 83 | USE arrays_3d, & |
---|
| 84 | ONLY: zu, zw |
---|
| 85 | |
---|
| 86 | USE control_parameters, & |
---|
| 87 | ONLY: constant_diffusion, cloud_droplets, cloud_physics, & |
---|
| 88 | data_output_masks, data_output_masks_user, & |
---|
| 89 | doav, doav_n, domask, domask_no, dz, dz_stretch_level, humidity,& |
---|
[1438] | 90 | icloud_scheme, mask, masks, mask_scale, mask_i, & |
---|
[1320] | 91 | mask_i_global, mask_j, mask_j_global, mask_k, mask_k_global, & |
---|
| 92 | mask_loop, mask_size, mask_size_l, mask_start_l, mask_x, & |
---|
| 93 | mask_x_loop, mask_xyz_dimension, mask_y, mask_y_loop, mask_z, & |
---|
| 94 | mask_z_loop, max_masks, message_string, mid, & |
---|
[1438] | 95 | netcdf_data_format, passive_scalar, precipitation, ocean |
---|
[1320] | 96 | |
---|
| 97 | USE grid_variables, & |
---|
| 98 | ONLY: dx, dy |
---|
| 99 | |
---|
| 100 | USE indices, & |
---|
| 101 | ONLY: nx, nxl, nxr, ny, nyn, nys, nz, nzb, nzt |
---|
| 102 | |
---|
| 103 | USE kinds |
---|
| 104 | |
---|
[1324] | 105 | USE netcdf_control |
---|
[1320] | 106 | |
---|
| 107 | USE particle_attributes, & |
---|
| 108 | ONLY: particle_advection |
---|
| 109 | |
---|
[298] | 110 | USE pegrid |
---|
| 111 | |
---|
| 112 | IMPLICIT NONE |
---|
| 113 | |
---|
[1320] | 114 | CHARACTER (LEN=6) :: var !: |
---|
| 115 | CHARACTER (LEN=7) :: unit !: |
---|
| 116 | |
---|
| 117 | CHARACTER (LEN=10), DIMENSION(max_masks,100) :: do_mask !: |
---|
| 118 | CHARACTER (LEN=10), DIMENSION(max_masks,100) :: do_mask_user !: |
---|
[298] | 119 | |
---|
[1320] | 120 | INTEGER(iwp) :: i !: |
---|
| 121 | INTEGER(iwp) :: ilen !: |
---|
| 122 | INTEGER(iwp) :: ind(6) !: |
---|
| 123 | INTEGER(iwp) :: ind_array(1) !: |
---|
| 124 | INTEGER(iwp) :: j !: |
---|
| 125 | INTEGER(iwp) :: k !: |
---|
| 126 | INTEGER(iwp) :: n !: |
---|
| 127 | INTEGER(iwp) :: sender !: |
---|
| 128 | |
---|
| 129 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: tmp_array !: |
---|
[298] | 130 | |
---|
[1320] | 131 | LOGICAL :: found !: |
---|
[298] | 132 | ! |
---|
| 133 | !-- Allocation and initialization |
---|
[1414] | 134 | ALLOCATE( tmp_array( MAX(nx,ny,nz)+2 ) ) |
---|
[298] | 135 | |
---|
[1414] | 136 | ALLOCATE( mask_i(max_masks,nxr-nxl+2), & |
---|
| 137 | mask_j(max_masks,nyn-nys+2), & |
---|
| 138 | mask_k(max_masks,nzt-nzb+2) ) |
---|
[298] | 139 | ! |
---|
| 140 | !-- internal mask arrays ("mask,dimension,selection") |
---|
| 141 | ALLOCATE( mask(max_masks,3,mask_xyz_dimension), & |
---|
| 142 | mask_loop(max_masks,3,3) ) |
---|
[493] | 143 | |
---|
[298] | 144 | ! |
---|
[493] | 145 | !-- Parallel mask output not yet tested |
---|
[1031] | 146 | IF ( netcdf_data_format > 4 ) THEN |
---|
[996] | 147 | message_string = 'netCDF file formats '// & |
---|
| 148 | '3 (netCDF 4) and 4 (netCDF 4 Classic model)'// & |
---|
[493] | 149 | '&are currently not supported (not yet tested).' |
---|
[564] | 150 | CALL message( 'init_masks', 'PA0328', 1, 2, 0, 6, 0 ) |
---|
[298] | 151 | ENDIF |
---|
[553] | 152 | |
---|
[298] | 153 | ! |
---|
| 154 | !-- Store data output parameters for masked data output in few shared arrays |
---|
[996] | 155 | DO mid = 1, masks |
---|
[564] | 156 | |
---|
[553] | 157 | do_mask (mid,:) = data_output_masks(mid,:) |
---|
| 158 | do_mask_user(mid,:) = data_output_masks_user(mid,:) |
---|
| 159 | mask (mid,1,:) = mask_x(mid,:) |
---|
| 160 | mask (mid,2,:) = mask_y(mid,:) |
---|
| 161 | mask (mid,3,:) = mask_z(mid,:) |
---|
[564] | 162 | |
---|
[1353] | 163 | IF ( mask_x_loop(mid,1) == -1.0_wp .AND. mask_x_loop(mid,2) == -1.0_wp& |
---|
| 164 | .AND. mask_x_loop(mid,3) == -1.0_wp ) THEN |
---|
| 165 | mask_loop(mid,1,1:2) = -1.0_wp |
---|
| 166 | mask_loop(mid,1,3) = 0.0_wp |
---|
[564] | 167 | ELSE |
---|
| 168 | mask_loop(mid,1,:) = mask_x_loop(mid,:) |
---|
| 169 | ENDIF |
---|
[1353] | 170 | IF ( mask_y_loop(mid,1) == -1.0_wp .AND. mask_y_loop(mid,2) == -1.0_wp& |
---|
| 171 | .AND. mask_y_loop(mid,3) == -1.0_wp ) THEN |
---|
| 172 | mask_loop(mid,2,1:2) = -1.0_wp |
---|
| 173 | mask_loop(mid,2,3) = 0.0_wp |
---|
[564] | 174 | ELSE |
---|
| 175 | mask_loop(mid,2,:) = mask_y_loop(mid,:) |
---|
| 176 | ENDIF |
---|
[1353] | 177 | IF ( mask_z_loop(mid,1) == -1.0_wp .AND. mask_z_loop(mid,2) == -1.0_wp& |
---|
| 178 | .AND. mask_z_loop(mid,3) == -1.0_wp ) THEN |
---|
| 179 | mask_loop(mid,3,1:2) = -1.0_wp |
---|
| 180 | mask_loop(mid,3,3) = 0.0_wp |
---|
[564] | 181 | ELSE |
---|
| 182 | mask_loop(mid,3,:) = mask_z_loop(mid,:) |
---|
| 183 | ENDIF |
---|
| 184 | |
---|
[553] | 185 | ENDDO |
---|
| 186 | |
---|
[298] | 187 | mask_i = -1; mask_j = -1; mask_k = -1 |
---|
[553] | 188 | |
---|
[298] | 189 | ! |
---|
| 190 | !-- Global arrays are required by define_netcdf_header. |
---|
[1031] | 191 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1414] | 192 | ALLOCATE( mask_i_global(max_masks,nx+2), & |
---|
| 193 | mask_j_global(max_masks,ny+2), & |
---|
| 194 | mask_k_global(max_masks,nz+2) ) |
---|
[298] | 195 | mask_i_global = -1; mask_j_global = -1; mask_k_global = -1 |
---|
| 196 | ENDIF |
---|
| 197 | |
---|
| 198 | ! |
---|
| 199 | !-- Determine variable names for each mask |
---|
| 200 | DO mid = 1, masks |
---|
| 201 | ! |
---|
| 202 | !-- Append user-defined data output variables to the standard data output |
---|
| 203 | IF ( do_mask_user(mid,1) /= ' ' ) THEN |
---|
| 204 | i = 1 |
---|
| 205 | DO WHILE ( do_mask(mid,i) /= ' ' .AND. i <= 100 ) |
---|
| 206 | i = i + 1 |
---|
| 207 | ENDDO |
---|
| 208 | j = 1 |
---|
| 209 | DO WHILE ( do_mask_user(mid,j) /= ' ' .AND. j <= 100 ) |
---|
| 210 | IF ( i > 100 ) THEN |
---|
| 211 | WRITE ( message_string, * ) 'number of output quantitities ', & |
---|
| 212 | 'given by data_output_mask and data_output_mask_user ', & |
---|
| 213 | 'exceeds the limit of 100' |
---|
[564] | 214 | CALL message( 'init_masks', 'PA0329', 1, 2, 0, 6, 0 ) |
---|
[298] | 215 | ENDIF |
---|
| 216 | do_mask(mid,i) = do_mask_user(mid,j) |
---|
| 217 | i = i + 1 |
---|
| 218 | j = j + 1 |
---|
| 219 | ENDDO |
---|
| 220 | ENDIF |
---|
| 221 | |
---|
| 222 | ! |
---|
| 223 | !-- Check and set steering parameters for mask data output and averaging |
---|
| 224 | i = 1 |
---|
[996] | 225 | DO WHILE ( do_mask(mid,i) /= ' ' .AND. i <= 100 ) |
---|
[298] | 226 | ! |
---|
| 227 | !-- Check for data averaging |
---|
| 228 | ilen = LEN_TRIM( do_mask(mid,i) ) |
---|
| 229 | j = 0 ! no data averaging |
---|
| 230 | IF ( ilen > 3 ) THEN |
---|
| 231 | IF ( do_mask(mid,i)(ilen-2:ilen) == '_av' ) THEN |
---|
| 232 | j = 1 ! data averaging |
---|
| 233 | do_mask(mid,i) = do_mask(mid,i)(1:ilen-3) |
---|
| 234 | ENDIF |
---|
| 235 | ENDIF |
---|
| 236 | var = TRIM( do_mask(mid,i) ) |
---|
| 237 | ! |
---|
| 238 | !-- Check for allowed value and set units |
---|
| 239 | SELECT CASE ( TRIM( var ) ) |
---|
| 240 | |
---|
| 241 | CASE ( 'e' ) |
---|
| 242 | IF ( constant_diffusion ) THEN |
---|
| 243 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 244 | '" requires constant_diffusion = .FALSE.' |
---|
[564] | 245 | CALL message( 'init_masks', 'PA0103', 1, 2, 0, 6, 0 ) |
---|
[298] | 246 | ENDIF |
---|
| 247 | unit = 'm2/s2' |
---|
| 248 | |
---|
[771] | 249 | CASE ( 'lpt' ) |
---|
| 250 | IF ( .NOT. cloud_physics ) THEN |
---|
| 251 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 252 | '" requires cloud_physics = .TRUE.' |
---|
[773] | 253 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
[771] | 254 | ENDIF |
---|
| 255 | unit = 'K' |
---|
| 256 | |
---|
[1438] | 257 | CASE ( 'nr' ) |
---|
| 258 | IF ( .NOT. cloud_physics ) THEN |
---|
| 259 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 260 | '" requires cloud_physics = .TRUE.' |
---|
| 261 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
| 262 | ELSEIF ( icloud_scheme /= 0 ) THEN |
---|
| 263 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
| 264 | 'res cloud_scheme = seifert_beheng' |
---|
| 265 | CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 ) |
---|
| 266 | ELSEIF ( .NOT. precipitation ) THEN |
---|
| 267 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
| 268 | 'res precipitation = .TRUE.' |
---|
| 269 | CALL message( 'check_parameters', 'PA0112', 1, 2, 0, 6, 0 ) |
---|
| 270 | ENDIF |
---|
| 271 | unit = '1/m3' |
---|
| 272 | |
---|
[298] | 273 | CASE ( 'pc', 'pr' ) |
---|
| 274 | IF ( .NOT. particle_advection ) THEN |
---|
| 275 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 276 | '" requires a "particles_par"-NAMELIST in the ', & |
---|
| 277 | 'parameter file (PARIN)' |
---|
[564] | 278 | CALL message( 'init_masks', 'PA0104', 1, 2, 0, 6, 0 ) |
---|
[298] | 279 | ENDIF |
---|
| 280 | IF ( TRIM( var ) == 'pc' ) unit = 'number' |
---|
| 281 | IF ( TRIM( var ) == 'pr' ) unit = 'm' |
---|
| 282 | |
---|
| 283 | CASE ( 'q', 'vpt' ) |
---|
| 284 | IF ( .NOT. humidity ) THEN |
---|
| 285 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 286 | '" requires humidity = .TRUE.' |
---|
[564] | 287 | CALL message( 'init_masks', 'PA0105', 1, 2, 0, 6, 0 ) |
---|
[298] | 288 | ENDIF |
---|
| 289 | IF ( TRIM( var ) == 'q' ) unit = 'kg/kg' |
---|
| 290 | IF ( TRIM( var ) == 'vpt' ) unit = 'K' |
---|
| 291 | |
---|
[1438] | 292 | CASE ( 'qc' ) |
---|
| 293 | IF ( .NOT. cloud_physics ) THEN |
---|
| 294 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
| 295 | 'res cloud_physics = .TRUE.' |
---|
| 296 | CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
| 297 | ELSEIF ( icloud_scheme /= 0 ) THEN |
---|
| 298 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
| 299 | 'res cloud_scheme = seifert_beheng' |
---|
| 300 | CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 ) |
---|
| 301 | ENDIF |
---|
| 302 | unit = 'kg/kg' |
---|
| 303 | |
---|
[298] | 304 | CASE ( 'ql' ) |
---|
| 305 | IF ( .NOT. ( cloud_physics .OR. cloud_droplets ) ) THEN |
---|
| 306 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 307 | '" requires cloud_physics = .TRUE. or cloud_droplets', & |
---|
| 308 | ' = .TRUE.' |
---|
[564] | 309 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
[298] | 310 | ENDIF |
---|
| 311 | unit = 'kg/kg' |
---|
| 312 | |
---|
| 313 | CASE ( 'ql_c', 'ql_v', 'ql_vp' ) |
---|
| 314 | IF ( .NOT. cloud_droplets ) THEN |
---|
| 315 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 316 | '" requires cloud_droplets = .TRUE.' |
---|
[564] | 317 | CALL message( 'init_masks', 'PA0107', 1, 2, 0, 6, 0 ) |
---|
[298] | 318 | ENDIF |
---|
| 319 | IF ( TRIM( var ) == 'ql_c' ) unit = 'kg/kg' |
---|
| 320 | IF ( TRIM( var ) == 'ql_v' ) unit = 'm3' |
---|
| 321 | IF ( TRIM( var ) == 'ql_vp' ) unit = 'none' |
---|
| 322 | |
---|
| 323 | CASE ( 'qv' ) |
---|
| 324 | IF ( .NOT. cloud_physics ) THEN |
---|
| 325 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 326 | '" requires cloud_physics = .TRUE.' |
---|
[564] | 327 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
[298] | 328 | ENDIF |
---|
| 329 | unit = 'kg/kg' |
---|
| 330 | |
---|
[1438] | 331 | CASE ( 'qr' ) |
---|
| 332 | IF ( .NOT. cloud_physics ) THEN |
---|
| 333 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
| 334 | 'res cloud_physics = .TRUE.' |
---|
| 335 | CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
| 336 | ELSEIF ( icloud_scheme /= 0 ) THEN |
---|
| 337 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
| 338 | 'res cloud_scheme = seifert_beheng' |
---|
| 339 | CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 ) |
---|
| 340 | ELSEIF ( .NOT. precipitation ) THEN |
---|
| 341 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
| 342 | 'res precipitation = .TRUE.' |
---|
| 343 | CALL message( 'check_parameters', 'PA0112', 1, 2, 0, 6, 0 ) |
---|
| 344 | ENDIF |
---|
| 345 | unit = 'kg/kg' |
---|
| 346 | |
---|
[298] | 347 | CASE ( 'rho' ) |
---|
| 348 | IF ( .NOT. ocean ) THEN |
---|
| 349 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 350 | '" requires ocean = .TRUE.' |
---|
[564] | 351 | CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 ) |
---|
[298] | 352 | ENDIF |
---|
| 353 | unit = 'kg/m3' |
---|
| 354 | |
---|
| 355 | CASE ( 's' ) |
---|
| 356 | IF ( .NOT. passive_scalar ) THEN |
---|
| 357 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 358 | '" requires passive_scalar = .TRUE.' |
---|
[564] | 359 | CALL message( 'init_masks', 'PA0110', 1, 2, 0, 6, 0 ) |
---|
[298] | 360 | ENDIF |
---|
| 361 | unit = 'conc' |
---|
| 362 | |
---|
| 363 | CASE ( 'sa' ) |
---|
| 364 | IF ( .NOT. ocean ) THEN |
---|
| 365 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 366 | '" requires ocean = .TRUE.' |
---|
[564] | 367 | CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 ) |
---|
[298] | 368 | ENDIF |
---|
| 369 | unit = 'psu' |
---|
| 370 | |
---|
[978] | 371 | CASE ( 'u*', 't*', 'lwp*', 'pra*', 'prr*', 'z0*', 'z0h*' ) |
---|
[298] | 372 | WRITE ( message_string, * ) 'illegal value for data_',& |
---|
| 373 | 'output: "', TRIM( var ), '" is only allowed', & |
---|
| 374 | 'for horizontal cross section' |
---|
[564] | 375 | CALL message( 'init_masks', 'PA0111', 1, 2, 0, 6, 0 ) |
---|
[298] | 376 | |
---|
| 377 | CASE ( 'p', 'pt', 'u', 'v', 'w' ) |
---|
| 378 | IF ( TRIM( var ) == 'p' ) unit = 'Pa' |
---|
| 379 | IF ( TRIM( var ) == 'pt' ) unit = 'K' |
---|
| 380 | IF ( TRIM( var ) == 'u' ) unit = 'm/s' |
---|
| 381 | IF ( TRIM( var ) == 'v' ) unit = 'm/s' |
---|
| 382 | IF ( TRIM( var ) == 'w' ) unit = 'm/s' |
---|
| 383 | CONTINUE |
---|
| 384 | |
---|
| 385 | CASE DEFAULT |
---|
| 386 | CALL user_check_data_output( var, unit ) |
---|
| 387 | |
---|
| 388 | IF ( unit == 'illegal' ) THEN |
---|
| 389 | IF ( do_mask_user(mid,1) /= ' ' ) THEN |
---|
| 390 | WRITE ( message_string, * ) 'illegal value for data_',& |
---|
| 391 | 'output or data_output_user: "', & |
---|
| 392 | TRIM( do_mask(mid,i) ), '"' |
---|
[564] | 393 | CALL message( 'init_masks', 'PA0114', 1, 2, 0, 6, 0 ) |
---|
[298] | 394 | ELSE |
---|
| 395 | WRITE ( message_string, * ) 'illegal value for data_',& |
---|
| 396 | 'output: "', TRIM( do_mask(mid,i) ), '"' |
---|
[564] | 397 | CALL message( 'init_masks', 'PA0330', 1, 2, 0, 6, 0 ) |
---|
[298] | 398 | ENDIF |
---|
| 399 | ENDIF |
---|
| 400 | |
---|
| 401 | END SELECT |
---|
| 402 | ! |
---|
| 403 | !-- Set the internal steering parameters appropriately |
---|
| 404 | domask_no(mid,j) = domask_no(mid,j) + 1 |
---|
| 405 | domask(mid,j,domask_no(mid,j)) = do_mask(mid,i) |
---|
| 406 | domask_unit(mid,j,domask_no(mid,j)) = unit |
---|
| 407 | |
---|
| 408 | IF ( j == 1 ) THEN |
---|
| 409 | ! |
---|
| 410 | !-- Check, if variable is already subject to averaging |
---|
| 411 | found = .FALSE. |
---|
| 412 | DO k = 1, doav_n |
---|
| 413 | IF ( TRIM( doav(k) ) == TRIM( var ) ) found = .TRUE. |
---|
| 414 | ENDDO |
---|
| 415 | |
---|
| 416 | IF ( .NOT. found ) THEN |
---|
| 417 | doav_n = doav_n + 1 |
---|
| 418 | doav(doav_n) = var |
---|
| 419 | ENDIF |
---|
| 420 | ENDIF |
---|
| 421 | |
---|
| 422 | i = i + 1 |
---|
| 423 | |
---|
| 424 | ENDDO ! do_mask(mid,i) |
---|
| 425 | ENDDO ! mid |
---|
| 426 | |
---|
| 427 | |
---|
| 428 | ! |
---|
| 429 | !-- Determine mask locations for each mask |
---|
| 430 | DO mid = 1, masks |
---|
| 431 | ! |
---|
| 432 | !-- Set local masks for each subdomain along all three dimensions |
---|
| 433 | CALL set_mask_locations( 1, dx, 'dx', nx, 'nx', nxl, nxr ) |
---|
| 434 | CALL set_mask_locations( 2, dy, 'dy', ny, 'ny', nys, nyn ) |
---|
| 435 | CALL set_mask_locations( 3, dz, 'dz', nz, 'nz', nzb, nzt ) |
---|
| 436 | ! |
---|
| 437 | !-- Set global masks along all three dimensions (required by |
---|
| 438 | !-- define_netcdf_header). |
---|
[809] | 439 | #if defined( __parallel ) && ! defined ( __check ) |
---|
[298] | 440 | ! |
---|
| 441 | !-- PE0 receives partial arrays from all processors of the respective mask |
---|
| 442 | !-- and outputs them. Here a barrier has to be set, because otherwise |
---|
| 443 | !-- "-MPI- FATAL: Remote protocol queue full" may occur. |
---|
[807] | 444 | |
---|
[298] | 445 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 446 | |
---|
| 447 | IF ( myid == 0 ) THEN |
---|
| 448 | ! |
---|
| 449 | !-- Local arrays can be relocated directly. |
---|
| 450 | mask_i_global(mid,mask_start_l(mid,1): & |
---|
| 451 | mask_start_l(mid,1)+mask_size_l(mid,1)-1) = & |
---|
| 452 | mask_i(mid,:mask_size_l(mid,1)) |
---|
| 453 | mask_j_global(mid,mask_start_l(mid,2): & |
---|
| 454 | mask_start_l(mid,2)+mask_size_l(mid,2)-1) = & |
---|
| 455 | mask_j(mid,:mask_size_l(mid,2)) |
---|
| 456 | mask_k_global(mid,mask_start_l(mid,3): & |
---|
| 457 | mask_start_l(mid,3)+mask_size_l(mid,3)-1) = & |
---|
| 458 | mask_k(mid,:mask_size_l(mid,3)) |
---|
| 459 | ! |
---|
| 460 | !-- Receive data from all other PEs. |
---|
| 461 | DO n = 1, numprocs-1 |
---|
| 462 | ! |
---|
| 463 | !-- Receive index limits first, then arrays. |
---|
| 464 | !-- Index limits are received in arbitrary order from the PEs. |
---|
| 465 | CALL MPI_RECV( ind(1), 6, MPI_INTEGER, MPI_ANY_SOURCE, 0, & |
---|
| 466 | comm2d, status, ierr ) |
---|
| 467 | ! |
---|
| 468 | !-- Not all PEs have data for the mask. |
---|
| 469 | IF ( ind(1) /= -9999 ) THEN |
---|
| 470 | sender = status(MPI_SOURCE) |
---|
| 471 | CALL MPI_RECV( tmp_array(ind(1)), ind(2)-ind(1)+1, & |
---|
[363] | 472 | MPI_INTEGER, sender, 1, comm2d, status, ierr ) |
---|
[298] | 473 | mask_i_global(mid,ind(1):ind(2)) = tmp_array(ind(1):ind(2)) |
---|
| 474 | CALL MPI_RECV( tmp_array(ind(3)), ind(4)-ind(3)+1, & |
---|
[363] | 475 | MPI_INTEGER, sender, 2, comm2d, status, ierr ) |
---|
[298] | 476 | mask_j_global(mid,ind(3):ind(4)) = tmp_array(ind(3):ind(4)) |
---|
| 477 | CALL MPI_RECV( tmp_array(ind(5)), ind(6)-ind(5)+1, & |
---|
[363] | 478 | MPI_INTEGER, sender, 3, comm2d, status, ierr ) |
---|
[298] | 479 | mask_k_global(mid,ind(5):ind(6)) = tmp_array(ind(5):ind(6)) |
---|
| 480 | ENDIF |
---|
| 481 | ENDDO |
---|
| 482 | |
---|
| 483 | ELSE |
---|
| 484 | ! |
---|
| 485 | !-- If at least part of the mask resides on the PE, send the index limits |
---|
| 486 | !-- for the target array, otherwise send -9999 to PE0. |
---|
[996] | 487 | IF ( mask_size_l(mid,1) > 0 .AND. mask_size_l(mid,2) > 0 .AND. & |
---|
| 488 | mask_size_l(mid,3) > 0 ) THEN |
---|
[298] | 489 | ind(1) = mask_start_l(mid,1) |
---|
| 490 | ind(2) = mask_start_l(mid,1) + mask_size_l(mid,1) - 1 |
---|
| 491 | ind(3) = mask_start_l(mid,2) |
---|
| 492 | ind(4) = mask_start_l(mid,2) + mask_size_l(mid,2) - 1 |
---|
| 493 | ind(5) = mask_start_l(mid,3) |
---|
| 494 | ind(6) = mask_start_l(mid,3) + mask_size_l(mid,3) - 1 |
---|
| 495 | ELSE |
---|
| 496 | ind(1) = -9999; ind(2) = -9999 |
---|
| 497 | ind(3) = -9999; ind(4) = -9999 |
---|
| 498 | ind(5) = -9999; ind(6) = -9999 |
---|
| 499 | ENDIF |
---|
| 500 | CALL MPI_SEND( ind(1), 6, MPI_INTEGER, 0, 0, comm2d, ierr ) |
---|
| 501 | ! |
---|
| 502 | !-- If applicable, send data to PE0. |
---|
| 503 | IF ( ind(1) /= -9999 ) THEN |
---|
| 504 | tmp_array(:mask_size_l(mid,1)) = mask_i(mid,:mask_size_l(mid,1)) |
---|
| 505 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,1), & |
---|
[363] | 506 | MPI_INTEGER, 0, 1, comm2d, ierr ) |
---|
[298] | 507 | tmp_array(:mask_size_l(mid,2)) = mask_j(mid,:mask_size_l(mid,2)) |
---|
| 508 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,2), & |
---|
[363] | 509 | MPI_INTEGER, 0, 2, comm2d, ierr ) |
---|
[298] | 510 | tmp_array(:mask_size_l(mid,3)) = mask_k(mid,:mask_size_l(mid,3)) |
---|
| 511 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,3), & |
---|
[363] | 512 | MPI_INTEGER, 0, 3, comm2d, ierr ) |
---|
[298] | 513 | ENDIF |
---|
| 514 | ENDIF |
---|
| 515 | ! |
---|
| 516 | !-- A barrier has to be set, because otherwise some PEs may proceed too fast |
---|
| 517 | !-- so that PE0 may receive wrong data on tag 0. |
---|
| 518 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
[409] | 519 | |
---|
[1031] | 520 | IF ( netcdf_data_format > 4 ) THEN |
---|
[409] | 521 | |
---|
[1414] | 522 | CALL MPI_BCAST( mask_i_global(mid,:), nx+2, MPI_INTEGER, 0, comm2d, & |
---|
[493] | 523 | ierr ) |
---|
[1414] | 524 | CALL MPI_BCAST( mask_j_global(mid,:), ny+2, MPI_INTEGER, 0, comm2d, & |
---|
[493] | 525 | ierr ) |
---|
[1414] | 526 | CALL MPI_BCAST( mask_k_global(mid,:), nz+2, MPI_INTEGER, 0, comm2d, & |
---|
[493] | 527 | ierr ) |
---|
[409] | 528 | |
---|
| 529 | ENDIF |
---|
[298] | 530 | |
---|
[809] | 531 | #elif ! defined ( __parallel ) |
---|
[298] | 532 | ! |
---|
| 533 | !-- Local arrays can be relocated directly. |
---|
| 534 | mask_i_global(mid,:) = mask_i(mid,:) |
---|
| 535 | mask_j_global(mid,:) = mask_j(mid,:) |
---|
| 536 | mask_k_global(mid,:) = mask_k(mid,:) |
---|
| 537 | #endif |
---|
| 538 | ENDDO ! mid |
---|
| 539 | |
---|
| 540 | DEALLOCATE( tmp_array ) |
---|
| 541 | ! |
---|
| 542 | !-- Internal mask arrays cannot be deallocated on PE 0 because they are |
---|
| 543 | !-- required for header output on PE 0. |
---|
| 544 | IF ( myid /= 0 ) DEALLOCATE( mask, mask_loop ) |
---|
| 545 | |
---|
| 546 | CONTAINS |
---|
[493] | 547 | |
---|
[298] | 548 | SUBROUTINE set_mask_locations( dim, dxyz, dxyz_string, nxyz, nxyz_string, & |
---|
| 549 | lb, ub ) |
---|
| 550 | !------------------------------------------------------------------------------! |
---|
| 551 | ! |
---|
| 552 | ! Description: |
---|
| 553 | ! ------------ |
---|
| 554 | ! Set local mask for each subdomain along 'dim' direction. |
---|
| 555 | !------------------------------------------------------------------------------! |
---|
| 556 | |
---|
| 557 | IMPLICIT NONE |
---|
| 558 | |
---|
[1320] | 559 | CHARACTER (LEN=2) :: dxyz_string !: |
---|
| 560 | CHARACTER (LEN=2) :: nxyz_string !: |
---|
| 561 | |
---|
| 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 !: |
---|
| 572 | |
---|
| 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 |
---|