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