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