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