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