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 | ! +nr, qc, qr |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: init_masks.f90 1438 2014-07-22 14:14:06Z heinze $ |
---|
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 | icloud_scheme, 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, precipitation, 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 ( 'nr' ) |
---|
255 | IF ( .NOT. cloud_physics ) THEN |
---|
256 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
257 | '" requires cloud_physics = .TRUE.' |
---|
258 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
259 | ELSEIF ( icloud_scheme /= 0 ) THEN |
---|
260 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
261 | 'res cloud_scheme = seifert_beheng' |
---|
262 | CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 ) |
---|
263 | ELSEIF ( .NOT. precipitation ) THEN |
---|
264 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
265 | 'res precipitation = .TRUE.' |
---|
266 | CALL message( 'check_parameters', 'PA0112', 1, 2, 0, 6, 0 ) |
---|
267 | ENDIF |
---|
268 | unit = '1/m3' |
---|
269 | |
---|
270 | CASE ( 'pc', 'pr' ) |
---|
271 | IF ( .NOT. particle_advection ) THEN |
---|
272 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
273 | '" requires a "particles_par"-NAMELIST in the ', & |
---|
274 | 'parameter file (PARIN)' |
---|
275 | CALL message( 'init_masks', 'PA0104', 1, 2, 0, 6, 0 ) |
---|
276 | ENDIF |
---|
277 | IF ( TRIM( var ) == 'pc' ) unit = 'number' |
---|
278 | IF ( TRIM( var ) == 'pr' ) unit = 'm' |
---|
279 | |
---|
280 | CASE ( 'q', 'vpt' ) |
---|
281 | IF ( .NOT. humidity ) THEN |
---|
282 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
283 | '" requires humidity = .TRUE.' |
---|
284 | CALL message( 'init_masks', 'PA0105', 1, 2, 0, 6, 0 ) |
---|
285 | ENDIF |
---|
286 | IF ( TRIM( var ) == 'q' ) unit = 'kg/kg' |
---|
287 | IF ( TRIM( var ) == 'vpt' ) unit = 'K' |
---|
288 | |
---|
289 | CASE ( 'qc' ) |
---|
290 | IF ( .NOT. cloud_physics ) THEN |
---|
291 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
292 | 'res cloud_physics = .TRUE.' |
---|
293 | CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
294 | ELSEIF ( icloud_scheme /= 0 ) THEN |
---|
295 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
296 | 'res cloud_scheme = seifert_beheng' |
---|
297 | CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 ) |
---|
298 | ENDIF |
---|
299 | unit = 'kg/kg' |
---|
300 | |
---|
301 | CASE ( 'ql' ) |
---|
302 | IF ( .NOT. ( cloud_physics .OR. cloud_droplets ) ) THEN |
---|
303 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
304 | '" requires cloud_physics = .TRUE. or cloud_droplets', & |
---|
305 | ' = .TRUE.' |
---|
306 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
307 | ENDIF |
---|
308 | unit = 'kg/kg' |
---|
309 | |
---|
310 | CASE ( 'ql_c', 'ql_v', 'ql_vp' ) |
---|
311 | IF ( .NOT. cloud_droplets ) THEN |
---|
312 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
313 | '" requires cloud_droplets = .TRUE.' |
---|
314 | CALL message( 'init_masks', 'PA0107', 1, 2, 0, 6, 0 ) |
---|
315 | ENDIF |
---|
316 | IF ( TRIM( var ) == 'ql_c' ) unit = 'kg/kg' |
---|
317 | IF ( TRIM( var ) == 'ql_v' ) unit = 'm3' |
---|
318 | IF ( TRIM( var ) == 'ql_vp' ) unit = 'none' |
---|
319 | |
---|
320 | CASE ( 'qv' ) |
---|
321 | IF ( .NOT. cloud_physics ) THEN |
---|
322 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
323 | '" requires cloud_physics = .TRUE.' |
---|
324 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
325 | ENDIF |
---|
326 | unit = 'kg/kg' |
---|
327 | |
---|
328 | CASE ( 'qr' ) |
---|
329 | IF ( .NOT. cloud_physics ) THEN |
---|
330 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
331 | 'res cloud_physics = .TRUE.' |
---|
332 | CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
333 | ELSEIF ( icloud_scheme /= 0 ) THEN |
---|
334 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
335 | 'res cloud_scheme = seifert_beheng' |
---|
336 | CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 ) |
---|
337 | ELSEIF ( .NOT. precipitation ) THEN |
---|
338 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
339 | 'res precipitation = .TRUE.' |
---|
340 | CALL message( 'check_parameters', 'PA0112', 1, 2, 0, 6, 0 ) |
---|
341 | ENDIF |
---|
342 | unit = 'kg/kg' |
---|
343 | |
---|
344 | CASE ( 'rho' ) |
---|
345 | IF ( .NOT. ocean ) THEN |
---|
346 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
347 | '" requires ocean = .TRUE.' |
---|
348 | CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 ) |
---|
349 | ENDIF |
---|
350 | unit = 'kg/m3' |
---|
351 | |
---|
352 | CASE ( 's' ) |
---|
353 | IF ( .NOT. passive_scalar ) THEN |
---|
354 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
355 | '" requires passive_scalar = .TRUE.' |
---|
356 | CALL message( 'init_masks', 'PA0110', 1, 2, 0, 6, 0 ) |
---|
357 | ENDIF |
---|
358 | unit = 'conc' |
---|
359 | |
---|
360 | CASE ( 'sa' ) |
---|
361 | IF ( .NOT. ocean ) THEN |
---|
362 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
363 | '" requires ocean = .TRUE.' |
---|
364 | CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 ) |
---|
365 | ENDIF |
---|
366 | unit = 'psu' |
---|
367 | |
---|
368 | CASE ( 'u*', 't*', 'lwp*', 'pra*', 'prr*', 'z0*', 'z0h*' ) |
---|
369 | WRITE ( message_string, * ) 'illegal value for data_',& |
---|
370 | 'output: "', TRIM( var ), '" is only allowed', & |
---|
371 | 'for horizontal cross section' |
---|
372 | CALL message( 'init_masks', 'PA0111', 1, 2, 0, 6, 0 ) |
---|
373 | |
---|
374 | CASE ( 'p', 'pt', 'u', 'v', 'w' ) |
---|
375 | IF ( TRIM( var ) == 'p' ) unit = 'Pa' |
---|
376 | IF ( TRIM( var ) == 'pt' ) unit = 'K' |
---|
377 | IF ( TRIM( var ) == 'u' ) unit = 'm/s' |
---|
378 | IF ( TRIM( var ) == 'v' ) unit = 'm/s' |
---|
379 | IF ( TRIM( var ) == 'w' ) unit = 'm/s' |
---|
380 | CONTINUE |
---|
381 | |
---|
382 | CASE DEFAULT |
---|
383 | CALL user_check_data_output( var, unit ) |
---|
384 | |
---|
385 | IF ( unit == 'illegal' ) THEN |
---|
386 | IF ( do_mask_user(mid,1) /= ' ' ) THEN |
---|
387 | WRITE ( message_string, * ) 'illegal value for data_',& |
---|
388 | 'output or data_output_user: "', & |
---|
389 | TRIM( do_mask(mid,i) ), '"' |
---|
390 | CALL message( 'init_masks', 'PA0114', 1, 2, 0, 6, 0 ) |
---|
391 | ELSE |
---|
392 | WRITE ( message_string, * ) 'illegal value for data_',& |
---|
393 | 'output: "', TRIM( do_mask(mid,i) ), '"' |
---|
394 | CALL message( 'init_masks', 'PA0330', 1, 2, 0, 6, 0 ) |
---|
395 | ENDIF |
---|
396 | ENDIF |
---|
397 | |
---|
398 | END SELECT |
---|
399 | ! |
---|
400 | !-- Set the internal steering parameters appropriately |
---|
401 | domask_no(mid,j) = domask_no(mid,j) + 1 |
---|
402 | domask(mid,j,domask_no(mid,j)) = do_mask(mid,i) |
---|
403 | domask_unit(mid,j,domask_no(mid,j)) = unit |
---|
404 | |
---|
405 | IF ( j == 1 ) THEN |
---|
406 | ! |
---|
407 | !-- Check, if variable is already subject to averaging |
---|
408 | found = .FALSE. |
---|
409 | DO k = 1, doav_n |
---|
410 | IF ( TRIM( doav(k) ) == TRIM( var ) ) found = .TRUE. |
---|
411 | ENDDO |
---|
412 | |
---|
413 | IF ( .NOT. found ) THEN |
---|
414 | doav_n = doav_n + 1 |
---|
415 | doav(doav_n) = var |
---|
416 | ENDIF |
---|
417 | ENDIF |
---|
418 | |
---|
419 | i = i + 1 |
---|
420 | |
---|
421 | ENDDO ! do_mask(mid,i) |
---|
422 | ENDDO ! mid |
---|
423 | |
---|
424 | |
---|
425 | ! |
---|
426 | !-- Determine mask locations for each mask |
---|
427 | DO mid = 1, masks |
---|
428 | ! |
---|
429 | !-- Set local masks for each subdomain along all three dimensions |
---|
430 | CALL set_mask_locations( 1, dx, 'dx', nx, 'nx', nxl, nxr ) |
---|
431 | CALL set_mask_locations( 2, dy, 'dy', ny, 'ny', nys, nyn ) |
---|
432 | CALL set_mask_locations( 3, dz, 'dz', nz, 'nz', nzb, nzt ) |
---|
433 | ! |
---|
434 | !-- Set global masks along all three dimensions (required by |
---|
435 | !-- define_netcdf_header). |
---|
436 | #if defined( __parallel ) && ! defined ( __check ) |
---|
437 | ! |
---|
438 | !-- PE0 receives partial arrays from all processors of the respective mask |
---|
439 | !-- and outputs them. Here a barrier has to be set, because otherwise |
---|
440 | !-- "-MPI- FATAL: Remote protocol queue full" may occur. |
---|
441 | |
---|
442 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
443 | |
---|
444 | IF ( myid == 0 ) THEN |
---|
445 | ! |
---|
446 | !-- Local arrays can be relocated directly. |
---|
447 | mask_i_global(mid,mask_start_l(mid,1): & |
---|
448 | mask_start_l(mid,1)+mask_size_l(mid,1)-1) = & |
---|
449 | mask_i(mid,:mask_size_l(mid,1)) |
---|
450 | mask_j_global(mid,mask_start_l(mid,2): & |
---|
451 | mask_start_l(mid,2)+mask_size_l(mid,2)-1) = & |
---|
452 | mask_j(mid,:mask_size_l(mid,2)) |
---|
453 | mask_k_global(mid,mask_start_l(mid,3): & |
---|
454 | mask_start_l(mid,3)+mask_size_l(mid,3)-1) = & |
---|
455 | mask_k(mid,:mask_size_l(mid,3)) |
---|
456 | ! |
---|
457 | !-- Receive data from all other PEs. |
---|
458 | DO n = 1, numprocs-1 |
---|
459 | ! |
---|
460 | !-- Receive index limits first, then arrays. |
---|
461 | !-- Index limits are received in arbitrary order from the PEs. |
---|
462 | CALL MPI_RECV( ind(1), 6, MPI_INTEGER, MPI_ANY_SOURCE, 0, & |
---|
463 | comm2d, status, ierr ) |
---|
464 | ! |
---|
465 | !-- Not all PEs have data for the mask. |
---|
466 | IF ( ind(1) /= -9999 ) THEN |
---|
467 | sender = status(MPI_SOURCE) |
---|
468 | CALL MPI_RECV( tmp_array(ind(1)), ind(2)-ind(1)+1, & |
---|
469 | MPI_INTEGER, sender, 1, comm2d, status, ierr ) |
---|
470 | mask_i_global(mid,ind(1):ind(2)) = tmp_array(ind(1):ind(2)) |
---|
471 | CALL MPI_RECV( tmp_array(ind(3)), ind(4)-ind(3)+1, & |
---|
472 | MPI_INTEGER, sender, 2, comm2d, status, ierr ) |
---|
473 | mask_j_global(mid,ind(3):ind(4)) = tmp_array(ind(3):ind(4)) |
---|
474 | CALL MPI_RECV( tmp_array(ind(5)), ind(6)-ind(5)+1, & |
---|
475 | MPI_INTEGER, sender, 3, comm2d, status, ierr ) |
---|
476 | mask_k_global(mid,ind(5):ind(6)) = tmp_array(ind(5):ind(6)) |
---|
477 | ENDIF |
---|
478 | ENDDO |
---|
479 | |
---|
480 | ELSE |
---|
481 | ! |
---|
482 | !-- If at least part of the mask resides on the PE, send the index limits |
---|
483 | !-- for the target array, otherwise send -9999 to PE0. |
---|
484 | IF ( mask_size_l(mid,1) > 0 .AND. mask_size_l(mid,2) > 0 .AND. & |
---|
485 | mask_size_l(mid,3) > 0 ) THEN |
---|
486 | ind(1) = mask_start_l(mid,1) |
---|
487 | ind(2) = mask_start_l(mid,1) + mask_size_l(mid,1) - 1 |
---|
488 | ind(3) = mask_start_l(mid,2) |
---|
489 | ind(4) = mask_start_l(mid,2) + mask_size_l(mid,2) - 1 |
---|
490 | ind(5) = mask_start_l(mid,3) |
---|
491 | ind(6) = mask_start_l(mid,3) + mask_size_l(mid,3) - 1 |
---|
492 | ELSE |
---|
493 | ind(1) = -9999; ind(2) = -9999 |
---|
494 | ind(3) = -9999; ind(4) = -9999 |
---|
495 | ind(5) = -9999; ind(6) = -9999 |
---|
496 | ENDIF |
---|
497 | CALL MPI_SEND( ind(1), 6, MPI_INTEGER, 0, 0, comm2d, ierr ) |
---|
498 | ! |
---|
499 | !-- If applicable, send data to PE0. |
---|
500 | IF ( ind(1) /= -9999 ) THEN |
---|
501 | tmp_array(:mask_size_l(mid,1)) = mask_i(mid,:mask_size_l(mid,1)) |
---|
502 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,1), & |
---|
503 | MPI_INTEGER, 0, 1, comm2d, ierr ) |
---|
504 | tmp_array(:mask_size_l(mid,2)) = mask_j(mid,:mask_size_l(mid,2)) |
---|
505 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,2), & |
---|
506 | MPI_INTEGER, 0, 2, comm2d, ierr ) |
---|
507 | tmp_array(:mask_size_l(mid,3)) = mask_k(mid,:mask_size_l(mid,3)) |
---|
508 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,3), & |
---|
509 | MPI_INTEGER, 0, 3, comm2d, ierr ) |
---|
510 | ENDIF |
---|
511 | ENDIF |
---|
512 | ! |
---|
513 | !-- A barrier has to be set, because otherwise some PEs may proceed too fast |
---|
514 | !-- so that PE0 may receive wrong data on tag 0. |
---|
515 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
516 | |
---|
517 | IF ( netcdf_data_format > 4 ) THEN |
---|
518 | |
---|
519 | CALL MPI_BCAST( mask_i_global(mid,:), nx+2, MPI_INTEGER, 0, comm2d, & |
---|
520 | ierr ) |
---|
521 | CALL MPI_BCAST( mask_j_global(mid,:), ny+2, MPI_INTEGER, 0, comm2d, & |
---|
522 | ierr ) |
---|
523 | CALL MPI_BCAST( mask_k_global(mid,:), nz+2, MPI_INTEGER, 0, comm2d, & |
---|
524 | ierr ) |
---|
525 | |
---|
526 | ENDIF |
---|
527 | |
---|
528 | #elif ! defined ( __parallel ) |
---|
529 | ! |
---|
530 | !-- Local arrays can be relocated directly. |
---|
531 | mask_i_global(mid,:) = mask_i(mid,:) |
---|
532 | mask_j_global(mid,:) = mask_j(mid,:) |
---|
533 | mask_k_global(mid,:) = mask_k(mid,:) |
---|
534 | #endif |
---|
535 | ENDDO ! mid |
---|
536 | |
---|
537 | DEALLOCATE( tmp_array ) |
---|
538 | ! |
---|
539 | !-- Internal mask arrays cannot be deallocated on PE 0 because they are |
---|
540 | !-- required for header output on PE 0. |
---|
541 | IF ( myid /= 0 ) DEALLOCATE( mask, mask_loop ) |
---|
542 | |
---|
543 | CONTAINS |
---|
544 | |
---|
545 | SUBROUTINE set_mask_locations( dim, dxyz, dxyz_string, nxyz, nxyz_string, & |
---|
546 | lb, ub ) |
---|
547 | !------------------------------------------------------------------------------! |
---|
548 | ! |
---|
549 | ! Description: |
---|
550 | ! ------------ |
---|
551 | ! Set local mask for each subdomain along 'dim' direction. |
---|
552 | !------------------------------------------------------------------------------! |
---|
553 | |
---|
554 | IMPLICIT NONE |
---|
555 | |
---|
556 | CHARACTER (LEN=2) :: dxyz_string !: |
---|
557 | CHARACTER (LEN=2) :: nxyz_string !: |
---|
558 | |
---|
559 | INTEGER(iwp) :: count !: |
---|
560 | INTEGER(iwp) :: count_l !: |
---|
561 | INTEGER(iwp) :: dim !: |
---|
562 | INTEGER(iwp) :: m !: |
---|
563 | INTEGER(iwp) :: loop_begin !: |
---|
564 | INTEGER(iwp) :: loop_end !: |
---|
565 | INTEGER(iwp) :: loop_stride !: |
---|
566 | INTEGER(iwp) :: lb !: |
---|
567 | INTEGER(iwp) :: nxyz !: |
---|
568 | INTEGER(iwp) :: ub !: |
---|
569 | |
---|
570 | REAL(wp) :: dxyz !: |
---|
571 | REAL(wp) :: ddxyz !: |
---|
572 | REAL(wp) :: tmp1 !: |
---|
573 | REAL(wp) :: tmp2 !: |
---|
574 | |
---|
575 | count = 0; count_l = 0 |
---|
576 | ddxyz = 1.0_wp / dxyz |
---|
577 | tmp1 = 0.0_wp |
---|
578 | tmp2 = 0.0_wp |
---|
579 | |
---|
580 | IF ( mask(mid,dim,1) >= 0.0_wp ) THEN |
---|
581 | ! |
---|
582 | !-- use predefined mask_* array |
---|
583 | DO WHILE ( mask(mid,dim,count+1) >= 0.0_wp ) |
---|
584 | count = count + 1 |
---|
585 | IF ( dim == 1 .OR. dim == 2 ) THEN |
---|
586 | m = NINT( mask(mid,dim,count) * mask_scale(dim) * ddxyz - 0.5_wp ) |
---|
587 | IF ( m < 0 ) m = 0 ! avoid negative values |
---|
588 | ELSEIF ( dim == 3 ) THEN |
---|
589 | ind_array = & |
---|
590 | MINLOC( ABS( mask(mid,dim,count) * mask_scale(dim) - zu ) ) |
---|
591 | m = ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1 |
---|
592 | ENDIF |
---|
593 | IF ( m > (nxyz+1) ) THEN |
---|
594 | WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' ) & |
---|
595 | m,' in mask ',mid,' along dimension ',dim, & |
---|
596 | ' exceeds (',nxyz_string,'+1) = ',nxyz+1 |
---|
597 | CALL message( 'init_masks', 'PA0331', 1, 2, 0, 6, 0 ) |
---|
598 | ENDIF |
---|
599 | IF ( ( m >= lb .AND. m <= ub ) .OR. & |
---|
600 | ( m == (nxyz+1) .AND. ub == nxyz ) ) THEN |
---|
601 | IF ( count_l == 0 ) mask_start_l(mid,dim) = count |
---|
602 | count_l = count_l + 1 |
---|
603 | IF ( dim == 1 ) THEN |
---|
604 | mask_i(mid,count_l) = m |
---|
605 | ELSEIF ( dim == 2 ) THEN |
---|
606 | mask_j(mid,count_l) = m |
---|
607 | ELSEIF ( dim == 3 ) THEN |
---|
608 | mask_k(mid,count_l) = m |
---|
609 | ENDIF |
---|
610 | ENDIF |
---|
611 | IF ( count == mask_xyz_dimension ) EXIT |
---|
612 | ENDDO |
---|
613 | mask_size(mid,dim) = count |
---|
614 | mask_size_l(mid,dim) = count_l |
---|
615 | |
---|
616 | ELSE |
---|
617 | ! |
---|
618 | !-- use predefined mask_loop_* array, or use the default (all grid points |
---|
619 | !-- along this direction) |
---|
620 | IF ( mask_loop(mid,dim,1) < 0.0_wp ) THEN |
---|
621 | tmp1 = mask_loop(mid,dim,1) |
---|
622 | mask_loop(mid,dim,1) = zw(nzb) ! lowest level (default) |
---|
623 | ENDIF |
---|
624 | IF ( dim == 1 .OR. dim == 2 ) THEN |
---|
625 | IF ( mask_loop(mid,dim,2) < 0.0_wp ) THEN |
---|
626 | tmp2 = mask_loop(mid,dim,2) |
---|
627 | mask_loop(mid,dim,2) = (nxyz+1)*dxyz / mask_scale(dim) ! (default) |
---|
628 | ENDIF |
---|
629 | IF ( MAXVAL( mask_loop(mid,dim,1:2) ) & |
---|
630 | > (nxyz+1) * dxyz / mask_scale(dim) ) THEN |
---|
631 | WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),5A,I1,A,F9.3)' ) & |
---|
632 | 'mask_loop(',mid,',',dim,',1)=',mask_loop(mid,dim,1), & |
---|
633 | ' and/or mask_loop(',mid,',',dim,',2)=', & |
---|
634 | mask_loop(mid,dim,2),'&exceed (', & |
---|
635 | nxyz_string,'+1)*',dxyz_string,'/mask_scale(',dim,')=', & |
---|
636 | (nxyz+1)*dxyz/mask_scale(dim) |
---|
637 | CALL message( 'init_masks', 'PA0332', 1, 2, 0, 6, 0 ) |
---|
638 | ENDIF |
---|
639 | loop_begin = NINT( mask_loop(mid,dim,1) * mask_scale(dim) & |
---|
640 | * ddxyz - 0.5_wp ) |
---|
641 | loop_end = NINT( mask_loop(mid,dim,2) * mask_scale(dim) & |
---|
642 | * ddxyz - 0.5_wp ) |
---|
643 | loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) & |
---|
644 | * ddxyz ) |
---|
645 | IF ( loop_begin == -1 ) loop_begin = 0 ! avoid negative values |
---|
646 | ELSEIF ( dim == 3 ) THEN |
---|
647 | IF ( mask_loop(mid,dim,2) < 0.0_wp ) THEN |
---|
648 | tmp2 = mask_loop(mid,dim,2) |
---|
649 | mask_loop(mid,dim,2) = zu(nz+1) / mask_scale(dim) ! (default) |
---|
650 | ENDIF |
---|
651 | IF ( MAXVAL( mask_loop(mid,dim,1:2) ) & |
---|
652 | > zu(nz+1) / mask_scale(dim) ) THEN |
---|
653 | WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),A,I1,A,F9.3)' ) & |
---|
654 | 'mask_loop(',mid,',',dim,',1)=',mask_loop(mid,dim,1), & |
---|
655 | ' and/or mask_loop(',mid,',',dim,',2)=', & |
---|
656 | mask_loop(mid,dim,2),'&exceed zu(nz+1)/mask_scale(',dim, & |
---|
657 | ')=',zu(nz+1)/mask_scale(dim) |
---|
658 | CALL message( 'init_masks', 'PA0333', 1, 2, 0, 6, 0 ) |
---|
659 | ENDIF |
---|
660 | ind_array = & |
---|
661 | MINLOC( ABS( mask_loop(mid,dim,1) * mask_scale(dim) - zu ) ) |
---|
662 | loop_begin = & |
---|
663 | ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1 |
---|
664 | ind_array = & |
---|
665 | MINLOC( ABS( mask_loop(mid,dim,2) * mask_scale(dim) - zu ) ) |
---|
666 | loop_end = ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1 |
---|
667 | ! |
---|
668 | !-- The following line assumes a constant vertical grid spacing within |
---|
669 | !-- the vertical mask range; it fails for vertical grid stretching. |
---|
670 | !-- Maybe revise later. Issue warning but continue execution. |
---|
671 | loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) * ddxyz ) |
---|
672 | |
---|
673 | IF ( mask_loop(mid,dim,2) * mask_scale(dim) > dz_stretch_level ) & |
---|
674 | THEN |
---|
675 | WRITE ( message_string, '(A,I3,A,I1,A,F9.3,A,F8.2,3A)' ) & |
---|
676 | 'mask_loop(',mid,',',dim,',2)=', mask_loop(mid,dim,2),& |
---|
677 | ' exceeds dz_stretch_level=',dz_stretch_level, & |
---|
678 | '.&Vertical mask locations will not ', & |
---|
679 | 'match the desired heights&within the stretching ', & |
---|
680 | 'region. Recommendation: use mask instead of mask_loop.' |
---|
681 | CALL message( 'init_masks', 'PA0334', 0, 1, 0, 6, 0 ) |
---|
682 | ENDIF |
---|
683 | |
---|
684 | ENDIF |
---|
685 | ! |
---|
686 | !-- If necessary, reset mask_loop(mid,dim,1) and mask_loop(mid,dim,2). |
---|
687 | IF ( tmp1 < 0.0_wp ) mask_loop(mid,dim,1) = tmp1 |
---|
688 | IF ( tmp2 < 0.0_wp ) mask_loop(mid,dim,2) = tmp2 |
---|
689 | ! |
---|
690 | !-- The default stride +/-1 (every grid point) applies if |
---|
691 | !-- mask_loop(mid,dim,3) is not specified (its default is zero). |
---|
692 | IF ( loop_stride == 0 ) THEN |
---|
693 | IF ( loop_end >= loop_begin ) THEN |
---|
694 | loop_stride = 1 |
---|
695 | ELSE |
---|
696 | loop_stride = -1 |
---|
697 | ENDIF |
---|
698 | ENDIF |
---|
699 | DO m = loop_begin, loop_end, loop_stride |
---|
700 | count = count + 1 |
---|
701 | IF ( ( m >= lb .AND. m <= ub ) .OR. & |
---|
702 | ( m == (nxyz+1) .AND. ub == nxyz ) ) THEN |
---|
703 | IF ( count_l == 0 ) mask_start_l(mid,dim) = count |
---|
704 | count_l = count_l + 1 |
---|
705 | IF ( dim == 1 ) THEN |
---|
706 | mask_i(mid,count_l) = m |
---|
707 | ELSEIF ( dim == 2 ) THEN |
---|
708 | mask_j(mid,count_l) = m |
---|
709 | ELSEIF ( dim == 3 ) THEN |
---|
710 | mask_k(mid,count_l) = m |
---|
711 | ENDIF |
---|
712 | ENDIF |
---|
713 | ENDDO |
---|
714 | mask_size(mid,dim) = count |
---|
715 | mask_size_l(mid,dim) = count_l |
---|
716 | |
---|
717 | ENDIF |
---|
718 | |
---|
719 | END SUBROUTINE set_mask_locations |
---|
720 | |
---|
721 | END SUBROUTINE init_masks |
---|