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