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