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