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