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