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