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