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