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