1 | !> @file init_masks.f90 |
---|
2 | !--------------------------------------------------------------------------------! |
---|
3 | ! This file is part of PALM. |
---|
4 | ! |
---|
5 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
6 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
7 | ! either version 3 of the License, or (at your option) any later version. |
---|
8 | ! |
---|
9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
10 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
11 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
12 | ! |
---|
13 | ! You should have received a copy of the GNU General Public License along with |
---|
14 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
15 | ! |
---|
16 | ! Copyright 1997-2016 Leibniz Universitaet Hannover |
---|
17 | !--------------------------------------------------------------------------------! |
---|
18 | ! |
---|
19 | ! Current revisions: |
---|
20 | ! ----------------- |
---|
21 | ! |
---|
22 | ! |
---|
23 | ! Former revisions: |
---|
24 | ! ----------------- |
---|
25 | ! $Id: init_masks.f90 1823 2016-04-07 08:57:52Z suehring $ |
---|
26 | ! |
---|
27 | ! 1822 2016-04-07 07:49:42Z hoffmann |
---|
28 | ! icloud_scheme replaced by microphysics_* |
---|
29 | ! |
---|
30 | ! 1804 2016-04-05 16:30:18Z maronga |
---|
31 | ! Removed code for parameter file check (__check) |
---|
32 | ! |
---|
33 | ! 1783 2016-03-06 18:36:17Z raasch |
---|
34 | ! netcdf module name changed + related changes |
---|
35 | ! |
---|
36 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
37 | ! Code annotations made doxygen readable |
---|
38 | ! |
---|
39 | ! 1438 2014-07-22 14:14:06Z heinze |
---|
40 | ! +nr, qc, qr |
---|
41 | ! |
---|
42 | ! 1414 2014-05-31 11:19:48Z gronemeier |
---|
43 | ! Bugfix: first and last grid points as they appear in 3D volume data can now |
---|
44 | ! be included to masked data output |
---|
45 | ! |
---|
46 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
47 | ! REAL constants provided with KIND-attribute |
---|
48 | ! |
---|
49 | ! 1324 2014-03-21 09:13:16Z suehring |
---|
50 | ! Bugfix: ONLY statement for module netcdf_control removed |
---|
51 | ! |
---|
52 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
53 | ! ONLY-attribute added to USE-statements, |
---|
54 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
55 | ! kinds are defined in new module kinds, |
---|
56 | ! revision history before 2012 removed, |
---|
57 | ! comment fields (!:) to be used for variable explanations added to |
---|
58 | ! all variable declaration statements |
---|
59 | ! |
---|
60 | ! 1186 2013-06-18 06:22:52Z raasch |
---|
61 | ! bugfix: 0.0 replaced by zu(nzb) as the lowest default height level for masks, |
---|
62 | ! because a zero value does not work in case of ocean runs |
---|
63 | ! |
---|
64 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
65 | ! code put under GPL (PALM 3.9) |
---|
66 | ! |
---|
67 | ! 1032 2012-10-21 13:03:21Z letzel |
---|
68 | ! mask locations determined based on scalar positions |
---|
69 | ! |
---|
70 | ! 1031 2012-10-19 14:35:30Z raasch |
---|
71 | ! netCDF4 without parallel file support implemented |
---|
72 | ! |
---|
73 | ! 996 2012-09-07 10:41:47Z raasch |
---|
74 | ! little reformatting |
---|
75 | ! |
---|
76 | ! 978 2012-08-09 08:28:32Z fricke |
---|
77 | ! +z0h* |
---|
78 | ! |
---|
79 | ! 809 2012-01-30 13:32:58Z maronga |
---|
80 | ! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives |
---|
81 | ! |
---|
82 | ! 807 2012-01-25 11:53:51Z maronga |
---|
83 | ! New cpp directive "__check" implemented which is used by check_namelist_files |
---|
84 | ! |
---|
85 | ! 410 2009-12-04 17:05:40Z letzel |
---|
86 | ! Initial revision |
---|
87 | ! |
---|
88 | ! |
---|
89 | ! Description: |
---|
90 | ! ------------ |
---|
91 | !> Initialize masked data output |
---|
92 | !------------------------------------------------------------------------------! |
---|
93 | SUBROUTINE init_masks |
---|
94 | |
---|
95 | USE arrays_3d, & |
---|
96 | ONLY: zu, zw |
---|
97 | |
---|
98 | USE control_parameters, & |
---|
99 | ONLY: constant_diffusion, cloud_droplets, cloud_physics, & |
---|
100 | data_output_masks, data_output_masks_user, & |
---|
101 | doav, doav_n, domask, domask_no, dz, dz_stretch_level, humidity,& |
---|
102 | mask, masks, mask_scale, mask_i, & |
---|
103 | mask_i_global, mask_j, mask_j_global, mask_k, mask_k_global, & |
---|
104 | mask_loop, mask_size, mask_size_l, mask_start_l, mask_x, & |
---|
105 | mask_x_loop, mask_xyz_dimension, mask_y, mask_y_loop, mask_z, & |
---|
106 | mask_z_loop, max_masks, message_string, mid, & |
---|
107 | microphysics_seifert, passive_scalar, ocean |
---|
108 | |
---|
109 | USE grid_variables, & |
---|
110 | ONLY: dx, dy |
---|
111 | |
---|
112 | USE indices, & |
---|
113 | ONLY: nx, nxl, nxr, ny, nyn, nys, nz, nzb, nzt |
---|
114 | |
---|
115 | USE kinds |
---|
116 | |
---|
117 | USE netcdf_interface, & |
---|
118 | ONLY: domask_unit, netcdf_data_format |
---|
119 | |
---|
120 | USE particle_attributes, & |
---|
121 | ONLY: particle_advection |
---|
122 | |
---|
123 | USE pegrid |
---|
124 | |
---|
125 | IMPLICIT NONE |
---|
126 | |
---|
127 | CHARACTER (LEN=6) :: var !< |
---|
128 | CHARACTER (LEN=7) :: unit !< |
---|
129 | |
---|
130 | CHARACTER (LEN=10), DIMENSION(max_masks,100) :: do_mask !< |
---|
131 | CHARACTER (LEN=10), DIMENSION(max_masks,100) :: do_mask_user !< |
---|
132 | |
---|
133 | INTEGER(iwp) :: i !< |
---|
134 | INTEGER(iwp) :: ilen !< |
---|
135 | INTEGER(iwp) :: ind(6) !< |
---|
136 | INTEGER(iwp) :: ind_array(1) !< |
---|
137 | INTEGER(iwp) :: j !< |
---|
138 | INTEGER(iwp) :: k !< |
---|
139 | INTEGER(iwp) :: n !< |
---|
140 | INTEGER(iwp) :: sender !< |
---|
141 | |
---|
142 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: tmp_array !< |
---|
143 | |
---|
144 | LOGICAL :: found !< |
---|
145 | ! |
---|
146 | !-- Allocation and initialization |
---|
147 | ALLOCATE( tmp_array( MAX(nx,ny,nz)+2 ) ) |
---|
148 | |
---|
149 | ALLOCATE( mask_i(max_masks,nxr-nxl+2), & |
---|
150 | mask_j(max_masks,nyn-nys+2), & |
---|
151 | mask_k(max_masks,nzt-nzb+2) ) |
---|
152 | ! |
---|
153 | !-- internal mask arrays ("mask,dimension,selection") |
---|
154 | ALLOCATE( mask(max_masks,3,mask_xyz_dimension), & |
---|
155 | mask_loop(max_masks,3,3) ) |
---|
156 | |
---|
157 | ! |
---|
158 | !-- Parallel mask output not yet tested |
---|
159 | IF ( netcdf_data_format > 4 ) THEN |
---|
160 | message_string = 'netCDF file formats '// & |
---|
161 | '3 (netCDF 4) and 4 (netCDF 4 Classic model)'// & |
---|
162 | '&are currently not supported (not yet tested).' |
---|
163 | CALL message( 'init_masks', 'PA0328', 1, 2, 0, 6, 0 ) |
---|
164 | ENDIF |
---|
165 | |
---|
166 | ! |
---|
167 | !-- Store data output parameters for masked data output in few shared arrays |
---|
168 | DO mid = 1, masks |
---|
169 | |
---|
170 | do_mask (mid,:) = data_output_masks(mid,:) |
---|
171 | do_mask_user(mid,:) = data_output_masks_user(mid,:) |
---|
172 | mask (mid,1,:) = mask_x(mid,:) |
---|
173 | mask (mid,2,:) = mask_y(mid,:) |
---|
174 | mask (mid,3,:) = mask_z(mid,:) |
---|
175 | |
---|
176 | IF ( mask_x_loop(mid,1) == -1.0_wp .AND. mask_x_loop(mid,2) == -1.0_wp& |
---|
177 | .AND. mask_x_loop(mid,3) == -1.0_wp ) THEN |
---|
178 | mask_loop(mid,1,1:2) = -1.0_wp |
---|
179 | mask_loop(mid,1,3) = 0.0_wp |
---|
180 | ELSE |
---|
181 | mask_loop(mid,1,:) = mask_x_loop(mid,:) |
---|
182 | ENDIF |
---|
183 | IF ( mask_y_loop(mid,1) == -1.0_wp .AND. mask_y_loop(mid,2) == -1.0_wp& |
---|
184 | .AND. mask_y_loop(mid,3) == -1.0_wp ) THEN |
---|
185 | mask_loop(mid,2,1:2) = -1.0_wp |
---|
186 | mask_loop(mid,2,3) = 0.0_wp |
---|
187 | ELSE |
---|
188 | mask_loop(mid,2,:) = mask_y_loop(mid,:) |
---|
189 | ENDIF |
---|
190 | IF ( mask_z_loop(mid,1) == -1.0_wp .AND. mask_z_loop(mid,2) == -1.0_wp& |
---|
191 | .AND. mask_z_loop(mid,3) == -1.0_wp ) THEN |
---|
192 | mask_loop(mid,3,1:2) = -1.0_wp |
---|
193 | mask_loop(mid,3,3) = 0.0_wp |
---|
194 | ELSE |
---|
195 | mask_loop(mid,3,:) = mask_z_loop(mid,:) |
---|
196 | ENDIF |
---|
197 | |
---|
198 | ENDDO |
---|
199 | |
---|
200 | mask_i = -1; mask_j = -1; mask_k = -1 |
---|
201 | |
---|
202 | ! |
---|
203 | !-- Global arrays are required by define_netcdf_header. |
---|
204 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
205 | ALLOCATE( mask_i_global(max_masks,nx+2), & |
---|
206 | mask_j_global(max_masks,ny+2), & |
---|
207 | mask_k_global(max_masks,nz+2) ) |
---|
208 | mask_i_global = -1; mask_j_global = -1; mask_k_global = -1 |
---|
209 | ENDIF |
---|
210 | |
---|
211 | ! |
---|
212 | !-- Determine variable names for each mask |
---|
213 | DO mid = 1, masks |
---|
214 | ! |
---|
215 | !-- Append user-defined data output variables to the standard data output |
---|
216 | IF ( do_mask_user(mid,1) /= ' ' ) THEN |
---|
217 | i = 1 |
---|
218 | DO WHILE ( do_mask(mid,i) /= ' ' .AND. i <= 100 ) |
---|
219 | i = i + 1 |
---|
220 | ENDDO |
---|
221 | j = 1 |
---|
222 | DO WHILE ( do_mask_user(mid,j) /= ' ' .AND. j <= 100 ) |
---|
223 | IF ( i > 100 ) THEN |
---|
224 | WRITE ( message_string, * ) 'number of output quantitities ', & |
---|
225 | 'given by data_output_mask and data_output_mask_user ', & |
---|
226 | 'exceeds the limit of 100' |
---|
227 | CALL message( 'init_masks', 'PA0329', 1, 2, 0, 6, 0 ) |
---|
228 | ENDIF |
---|
229 | do_mask(mid,i) = do_mask_user(mid,j) |
---|
230 | i = i + 1 |
---|
231 | j = j + 1 |
---|
232 | ENDDO |
---|
233 | ENDIF |
---|
234 | |
---|
235 | ! |
---|
236 | !-- Check and set steering parameters for mask data output and averaging |
---|
237 | i = 1 |
---|
238 | DO WHILE ( do_mask(mid,i) /= ' ' .AND. i <= 100 ) |
---|
239 | ! |
---|
240 | !-- Check for data averaging |
---|
241 | ilen = LEN_TRIM( do_mask(mid,i) ) |
---|
242 | j = 0 ! no data averaging |
---|
243 | IF ( ilen > 3 ) THEN |
---|
244 | IF ( do_mask(mid,i)(ilen-2:ilen) == '_av' ) THEN |
---|
245 | j = 1 ! data averaging |
---|
246 | do_mask(mid,i) = do_mask(mid,i)(1:ilen-3) |
---|
247 | ENDIF |
---|
248 | ENDIF |
---|
249 | var = TRIM( do_mask(mid,i) ) |
---|
250 | ! |
---|
251 | !-- Check for allowed value and set units |
---|
252 | SELECT CASE ( TRIM( var ) ) |
---|
253 | |
---|
254 | CASE ( 'e' ) |
---|
255 | IF ( constant_diffusion ) THEN |
---|
256 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
257 | '" requires constant_diffusion = .FALSE.' |
---|
258 | CALL message( 'init_masks', 'PA0103', 1, 2, 0, 6, 0 ) |
---|
259 | ENDIF |
---|
260 | unit = 'm2/s2' |
---|
261 | |
---|
262 | CASE ( 'lpt' ) |
---|
263 | IF ( .NOT. cloud_physics ) THEN |
---|
264 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
265 | '" requires cloud_physics = .TRUE.' |
---|
266 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
267 | ENDIF |
---|
268 | unit = 'K' |
---|
269 | |
---|
270 | CASE ( 'nr' ) |
---|
271 | IF ( .NOT. cloud_physics ) THEN |
---|
272 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
273 | '" requires cloud_physics = .TRUE.' |
---|
274 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
275 | ELSEIF ( .NOT. microphysics_seifert ) THEN |
---|
276 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
277 | 'res cloud_scheme = seifert_beheng' |
---|
278 | CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 ) |
---|
279 | ENDIF |
---|
280 | unit = '1/m3' |
---|
281 | |
---|
282 | CASE ( 'pc', 'pr' ) |
---|
283 | IF ( .NOT. particle_advection ) THEN |
---|
284 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
285 | '" requires a "particles_par"-NAMELIST in the ', & |
---|
286 | 'parameter file (PARIN)' |
---|
287 | CALL message( 'init_masks', 'PA0104', 1, 2, 0, 6, 0 ) |
---|
288 | ENDIF |
---|
289 | IF ( TRIM( var ) == 'pc' ) unit = 'number' |
---|
290 | IF ( TRIM( var ) == 'pr' ) unit = 'm' |
---|
291 | |
---|
292 | CASE ( 'q', 'vpt' ) |
---|
293 | IF ( .NOT. humidity ) THEN |
---|
294 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
295 | '" requires humidity = .TRUE.' |
---|
296 | CALL message( 'init_masks', 'PA0105', 1, 2, 0, 6, 0 ) |
---|
297 | ENDIF |
---|
298 | IF ( TRIM( var ) == 'q' ) unit = 'kg/kg' |
---|
299 | IF ( TRIM( var ) == 'vpt' ) unit = 'K' |
---|
300 | |
---|
301 | CASE ( 'qc' ) |
---|
302 | IF ( .NOT. cloud_physics ) THEN |
---|
303 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
304 | 'res cloud_physics = .TRUE.' |
---|
305 | CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
306 | ENDIF |
---|
307 | unit = 'kg/kg' |
---|
308 | |
---|
309 | CASE ( 'ql' ) |
---|
310 | IF ( .NOT. ( cloud_physics .OR. cloud_droplets ) ) THEN |
---|
311 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
312 | '" requires cloud_physics = .TRUE. or cloud_droplets', & |
---|
313 | ' = .TRUE.' |
---|
314 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
315 | ENDIF |
---|
316 | unit = 'kg/kg' |
---|
317 | |
---|
318 | CASE ( 'ql_c', 'ql_v', 'ql_vp' ) |
---|
319 | IF ( .NOT. cloud_droplets ) THEN |
---|
320 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
321 | '" requires cloud_droplets = .TRUE.' |
---|
322 | CALL message( 'init_masks', 'PA0107', 1, 2, 0, 6, 0 ) |
---|
323 | ENDIF |
---|
324 | IF ( TRIM( var ) == 'ql_c' ) unit = 'kg/kg' |
---|
325 | IF ( TRIM( var ) == 'ql_v' ) unit = 'm3' |
---|
326 | IF ( TRIM( var ) == 'ql_vp' ) unit = 'none' |
---|
327 | |
---|
328 | CASE ( 'qv' ) |
---|
329 | IF ( .NOT. cloud_physics ) THEN |
---|
330 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
331 | '" requires cloud_physics = .TRUE.' |
---|
332 | CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
333 | ENDIF |
---|
334 | unit = 'kg/kg' |
---|
335 | |
---|
336 | CASE ( 'qr' ) |
---|
337 | IF ( .NOT. cloud_physics ) THEN |
---|
338 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
339 | 'res cloud_physics = .TRUE.' |
---|
340 | CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 ) |
---|
341 | ELSEIF ( .NOT. microphysics_seifert ) THEN |
---|
342 | message_string = 'output of "' // TRIM( var ) // '" requi' // & |
---|
343 | 'res cloud_scheme = seifert_beheng' |
---|
344 | CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 ) |
---|
345 | ENDIF |
---|
346 | unit = 'kg/kg' |
---|
347 | |
---|
348 | CASE ( 'rho' ) |
---|
349 | IF ( .NOT. ocean ) THEN |
---|
350 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
351 | '" requires ocean = .TRUE.' |
---|
352 | CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 ) |
---|
353 | ENDIF |
---|
354 | unit = 'kg/m3' |
---|
355 | |
---|
356 | CASE ( 's' ) |
---|
357 | IF ( .NOT. passive_scalar ) THEN |
---|
358 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
359 | '" requires passive_scalar = .TRUE.' |
---|
360 | CALL message( 'init_masks', 'PA0110', 1, 2, 0, 6, 0 ) |
---|
361 | ENDIF |
---|
362 | unit = 'conc' |
---|
363 | |
---|
364 | CASE ( 'sa' ) |
---|
365 | IF ( .NOT. ocean ) THEN |
---|
366 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
367 | '" requires ocean = .TRUE.' |
---|
368 | CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 ) |
---|
369 | ENDIF |
---|
370 | unit = 'psu' |
---|
371 | |
---|
372 | CASE ( 'u*', 't*', 'lwp*', 'pra*', 'prr*', 'z0*', 'z0h*' ) |
---|
373 | WRITE ( message_string, * ) 'illegal value for data_',& |
---|
374 | 'output: "', TRIM( var ), '" is only allowed', & |
---|
375 | 'for horizontal cross section' |
---|
376 | CALL message( 'init_masks', 'PA0111', 1, 2, 0, 6, 0 ) |
---|
377 | |
---|
378 | CASE ( 'p', 'pt', 'u', 'v', 'w' ) |
---|
379 | IF ( TRIM( var ) == 'p' ) unit = 'Pa' |
---|
380 | IF ( TRIM( var ) == 'pt' ) unit = 'K' |
---|
381 | IF ( TRIM( var ) == 'u' ) unit = 'm/s' |
---|
382 | IF ( TRIM( var ) == 'v' ) unit = 'm/s' |
---|
383 | IF ( TRIM( var ) == 'w' ) unit = 'm/s' |
---|
384 | CONTINUE |
---|
385 | |
---|
386 | CASE DEFAULT |
---|
387 | CALL user_check_data_output( var, unit ) |
---|
388 | |
---|
389 | IF ( unit == 'illegal' ) THEN |
---|
390 | IF ( do_mask_user(mid,1) /= ' ' ) THEN |
---|
391 | WRITE ( message_string, * ) 'illegal value for data_',& |
---|
392 | 'output or data_output_user: "', & |
---|
393 | TRIM( do_mask(mid,i) ), '"' |
---|
394 | CALL message( 'init_masks', 'PA0114', 1, 2, 0, 6, 0 ) |
---|
395 | ELSE |
---|
396 | WRITE ( message_string, * ) 'illegal value for data_',& |
---|
397 | 'output: "', TRIM( do_mask(mid,i) ), '"' |
---|
398 | CALL message( 'init_masks', 'PA0330', 1, 2, 0, 6, 0 ) |
---|
399 | ENDIF |
---|
400 | ENDIF |
---|
401 | |
---|
402 | END SELECT |
---|
403 | ! |
---|
404 | !-- Set the internal steering parameters appropriately |
---|
405 | domask_no(mid,j) = domask_no(mid,j) + 1 |
---|
406 | domask(mid,j,domask_no(mid,j)) = do_mask(mid,i) |
---|
407 | domask_unit(mid,j,domask_no(mid,j)) = unit |
---|
408 | |
---|
409 | IF ( j == 1 ) THEN |
---|
410 | ! |
---|
411 | !-- Check, if variable is already subject to averaging |
---|
412 | found = .FALSE. |
---|
413 | DO k = 1, doav_n |
---|
414 | IF ( TRIM( doav(k) ) == TRIM( var ) ) found = .TRUE. |
---|
415 | ENDDO |
---|
416 | |
---|
417 | IF ( .NOT. found ) THEN |
---|
418 | doav_n = doav_n + 1 |
---|
419 | doav(doav_n) = var |
---|
420 | ENDIF |
---|
421 | ENDIF |
---|
422 | |
---|
423 | i = i + 1 |
---|
424 | |
---|
425 | ENDDO ! do_mask(mid,i) |
---|
426 | ENDDO ! mid |
---|
427 | |
---|
428 | |
---|
429 | ! |
---|
430 | !-- Determine mask locations for each mask |
---|
431 | DO mid = 1, masks |
---|
432 | ! |
---|
433 | !-- Set local masks for each subdomain along all three dimensions |
---|
434 | CALL set_mask_locations( 1, dx, 'dx', nx, 'nx', nxl, nxr ) |
---|
435 | CALL set_mask_locations( 2, dy, 'dy', ny, 'ny', nys, nyn ) |
---|
436 | CALL set_mask_locations( 3, dz, 'dz', nz, 'nz', nzb, nzt ) |
---|
437 | ! |
---|
438 | !-- Set global masks along all three dimensions (required by |
---|
439 | !-- define_netcdf_header). |
---|
440 | #if defined( __parallel ) |
---|
441 | ! |
---|
442 | !-- PE0 receives partial arrays from all processors of the respective mask |
---|
443 | !-- and outputs them. Here a barrier has to be set, because otherwise |
---|
444 | !-- "-MPI- FATAL: Remote protocol queue full" may occur. |
---|
445 | |
---|
446 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
447 | |
---|
448 | IF ( myid == 0 ) THEN |
---|
449 | ! |
---|
450 | !-- Local arrays can be relocated directly. |
---|
451 | mask_i_global(mid,mask_start_l(mid,1): & |
---|
452 | mask_start_l(mid,1)+mask_size_l(mid,1)-1) = & |
---|
453 | mask_i(mid,:mask_size_l(mid,1)) |
---|
454 | mask_j_global(mid,mask_start_l(mid,2): & |
---|
455 | mask_start_l(mid,2)+mask_size_l(mid,2)-1) = & |
---|
456 | mask_j(mid,:mask_size_l(mid,2)) |
---|
457 | mask_k_global(mid,mask_start_l(mid,3): & |
---|
458 | mask_start_l(mid,3)+mask_size_l(mid,3)-1) = & |
---|
459 | mask_k(mid,:mask_size_l(mid,3)) |
---|
460 | ! |
---|
461 | !-- Receive data from all other PEs. |
---|
462 | DO n = 1, numprocs-1 |
---|
463 | ! |
---|
464 | !-- Receive index limits first, then arrays. |
---|
465 | !-- Index limits are received in arbitrary order from the PEs. |
---|
466 | CALL MPI_RECV( ind(1), 6, MPI_INTEGER, MPI_ANY_SOURCE, 0, & |
---|
467 | comm2d, status, ierr ) |
---|
468 | ! |
---|
469 | !-- Not all PEs have data for the mask. |
---|
470 | IF ( ind(1) /= -9999 ) THEN |
---|
471 | sender = status(MPI_SOURCE) |
---|
472 | CALL MPI_RECV( tmp_array(ind(1)), ind(2)-ind(1)+1, & |
---|
473 | MPI_INTEGER, sender, 1, comm2d, status, ierr ) |
---|
474 | mask_i_global(mid,ind(1):ind(2)) = tmp_array(ind(1):ind(2)) |
---|
475 | CALL MPI_RECV( tmp_array(ind(3)), ind(4)-ind(3)+1, & |
---|
476 | MPI_INTEGER, sender, 2, comm2d, status, ierr ) |
---|
477 | mask_j_global(mid,ind(3):ind(4)) = tmp_array(ind(3):ind(4)) |
---|
478 | CALL MPI_RECV( tmp_array(ind(5)), ind(6)-ind(5)+1, & |
---|
479 | MPI_INTEGER, sender, 3, comm2d, status, ierr ) |
---|
480 | mask_k_global(mid,ind(5):ind(6)) = tmp_array(ind(5):ind(6)) |
---|
481 | ENDIF |
---|
482 | ENDDO |
---|
483 | |
---|
484 | ELSE |
---|
485 | ! |
---|
486 | !-- If at least part of the mask resides on the PE, send the index limits |
---|
487 | !-- for the target array, otherwise send -9999 to PE0. |
---|
488 | IF ( mask_size_l(mid,1) > 0 .AND. mask_size_l(mid,2) > 0 .AND. & |
---|
489 | mask_size_l(mid,3) > 0 ) THEN |
---|
490 | ind(1) = mask_start_l(mid,1) |
---|
491 | ind(2) = mask_start_l(mid,1) + mask_size_l(mid,1) - 1 |
---|
492 | ind(3) = mask_start_l(mid,2) |
---|
493 | ind(4) = mask_start_l(mid,2) + mask_size_l(mid,2) - 1 |
---|
494 | ind(5) = mask_start_l(mid,3) |
---|
495 | ind(6) = mask_start_l(mid,3) + mask_size_l(mid,3) - 1 |
---|
496 | ELSE |
---|
497 | ind(1) = -9999; ind(2) = -9999 |
---|
498 | ind(3) = -9999; ind(4) = -9999 |
---|
499 | ind(5) = -9999; ind(6) = -9999 |
---|
500 | ENDIF |
---|
501 | CALL MPI_SEND( ind(1), 6, MPI_INTEGER, 0, 0, comm2d, ierr ) |
---|
502 | ! |
---|
503 | !-- If applicable, send data to PE0. |
---|
504 | IF ( ind(1) /= -9999 ) THEN |
---|
505 | tmp_array(:mask_size_l(mid,1)) = mask_i(mid,:mask_size_l(mid,1)) |
---|
506 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,1), & |
---|
507 | MPI_INTEGER, 0, 1, comm2d, ierr ) |
---|
508 | tmp_array(:mask_size_l(mid,2)) = mask_j(mid,:mask_size_l(mid,2)) |
---|
509 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,2), & |
---|
510 | MPI_INTEGER, 0, 2, comm2d, ierr ) |
---|
511 | tmp_array(:mask_size_l(mid,3)) = mask_k(mid,:mask_size_l(mid,3)) |
---|
512 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,3), & |
---|
513 | MPI_INTEGER, 0, 3, comm2d, ierr ) |
---|
514 | ENDIF |
---|
515 | ENDIF |
---|
516 | ! |
---|
517 | !-- A barrier has to be set, because otherwise some PEs may proceed too fast |
---|
518 | !-- so that PE0 may receive wrong data on tag 0. |
---|
519 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
520 | |
---|
521 | IF ( netcdf_data_format > 4 ) THEN |
---|
522 | |
---|
523 | CALL MPI_BCAST( mask_i_global(mid,:), nx+2, MPI_INTEGER, 0, comm2d, & |
---|
524 | ierr ) |
---|
525 | CALL MPI_BCAST( mask_j_global(mid,:), ny+2, MPI_INTEGER, 0, comm2d, & |
---|
526 | ierr ) |
---|
527 | CALL MPI_BCAST( mask_k_global(mid,:), nz+2, MPI_INTEGER, 0, comm2d, & |
---|
528 | ierr ) |
---|
529 | |
---|
530 | ENDIF |
---|
531 | |
---|
532 | #else |
---|
533 | ! |
---|
534 | !-- Local arrays can be relocated directly. |
---|
535 | mask_i_global(mid,:) = mask_i(mid,:) |
---|
536 | mask_j_global(mid,:) = mask_j(mid,:) |
---|
537 | mask_k_global(mid,:) = mask_k(mid,:) |
---|
538 | #endif |
---|
539 | ENDDO ! mid |
---|
540 | |
---|
541 | DEALLOCATE( tmp_array ) |
---|
542 | ! |
---|
543 | !-- Internal mask arrays cannot be deallocated on PE 0 because they are |
---|
544 | !-- required for header output on PE 0. |
---|
545 | IF ( myid /= 0 ) DEALLOCATE( mask, mask_loop ) |
---|
546 | |
---|
547 | CONTAINS |
---|
548 | |
---|
549 | !------------------------------------------------------------------------------! |
---|
550 | ! Description: |
---|
551 | ! ------------ |
---|
552 | !> Set local mask for each subdomain along 'dim' direction. |
---|
553 | !------------------------------------------------------------------------------! |
---|
554 | SUBROUTINE set_mask_locations( dim, dxyz, dxyz_string, nxyz, nxyz_string, & |
---|
555 | lb, ub ) |
---|
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 |
---|