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