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