1 | !> @file data_output_mask.f90 |
---|
2 | !--------------------------------------------------------------------------------! |
---|
3 | ! This file is part of PALM. |
---|
4 | ! |
---|
5 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
6 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
7 | ! either version 3 of the License, or (at your option) any later version. |
---|
8 | ! |
---|
9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
10 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
11 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
12 | ! |
---|
13 | ! You should have received a copy of the GNU General Public License along with |
---|
14 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
15 | ! |
---|
16 | ! Copyright 1997-2016 Leibniz Universitaet Hannover |
---|
17 | !--------------------------------------------------------------------------------! |
---|
18 | ! |
---|
19 | ! Current revisions: |
---|
20 | ! ----------------- |
---|
21 | ! |
---|
22 | ! |
---|
23 | ! Former revisions: |
---|
24 | ! ----------------- |
---|
25 | ! $Id: data_output_mask.f90 1981 2016-07-29 15:53:00Z suehring $ |
---|
26 | ! |
---|
27 | ! 1980 2016-07-29 15:51:57Z suehring |
---|
28 | ! Bugfix, in order to steer user-defined output, setting flag found explicitly |
---|
29 | ! to .F. |
---|
30 | ! |
---|
31 | ! 1976 2016-07-27 13:28:04Z maronga |
---|
32 | ! Output of radiation quantities is now done directly in the respective module |
---|
33 | ! |
---|
34 | ! 1960 2016-07-12 16:34:24Z suehring |
---|
35 | ! Separate humidity and passive scalar |
---|
36 | ! |
---|
37 | ! 2016-03-06 18:36:17Z raasch |
---|
38 | ! name change of netcdf routines and module + related changes, |
---|
39 | ! switch back of netcdf data format moved from time integration routine to here |
---|
40 | ! |
---|
41 | ! 1691 2015-10-26 16:17:44Z maronga |
---|
42 | ! Added output of radiative heating rates for RRTMG |
---|
43 | ! |
---|
44 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
45 | ! Code annotations made doxygen readable |
---|
46 | ! |
---|
47 | ! 1585 2015-04-30 07:05:52Z maronga |
---|
48 | ! Added support for RRTMG |
---|
49 | ! |
---|
50 | ! 1438 2014-07-22 14:14:06Z heinze |
---|
51 | ! +nr, qc, qr |
---|
52 | ! |
---|
53 | ! 1359 2014-04-11 17:15:14Z hoffmann |
---|
54 | ! New particle structure integrated. |
---|
55 | ! |
---|
56 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
57 | ! REAL constants provided with KIND-attribute |
---|
58 | ! |
---|
59 | ! 1327 2014-03-21 11:00:16Z raasch |
---|
60 | ! |
---|
61 | ! |
---|
62 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
63 | ! ONLY-attribute added to USE-statements, |
---|
64 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
65 | ! kinds are defined in new module kinds, |
---|
66 | ! revision history before 2012 removed, |
---|
67 | ! comment fields (!:) to be used for variable explanations added to |
---|
68 | ! all variable declaration statements |
---|
69 | ! |
---|
70 | ! 1318 2014-03-17 13:35:16Z raasch |
---|
71 | ! barrier argument removed from cpu_log, |
---|
72 | ! module interfaces removed |
---|
73 | ! |
---|
74 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
75 | ! unused variables removed |
---|
76 | ! |
---|
77 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
78 | ! code put under GPL (PALM 3.9) |
---|
79 | ! |
---|
80 | ! 1031 2012-10-19 14:35:30Z raasch |
---|
81 | ! netCDF4 without parallel file support implemented |
---|
82 | ! |
---|
83 | ! 1007 2012-09-19 14:30:36Z franke |
---|
84 | ! Bugfix: calculation of pr must depend on the particle weighting factor, |
---|
85 | ! missing calculation of ql_vp added |
---|
86 | ! |
---|
87 | ! 410 2009-12-04 17:05:40Z letzel |
---|
88 | ! Initial version |
---|
89 | ! |
---|
90 | ! Description: |
---|
91 | ! ------------ |
---|
92 | !> Masked data output in netCDF format for current mask (current value of mid). |
---|
93 | !------------------------------------------------------------------------------! |
---|
94 | SUBROUTINE data_output_mask( av ) |
---|
95 | |
---|
96 | |
---|
97 | |
---|
98 | #if defined( __netcdf ) |
---|
99 | USE arrays_3d, & |
---|
100 | ONLY: e, nr, p, pt, q, qc, ql, ql_c, ql_v, qr, rho, s, sa, tend, u, & |
---|
101 | v, vpt, w |
---|
102 | |
---|
103 | USE averaging, & |
---|
104 | ONLY: e_av, lpt_av, nr_av, p_av, pc_av, pr_av, pt_av, q_av, qc_av, & |
---|
105 | ql_av, ql_c_av, ql_v_av, ql_vp_av, qv_av, qr_av, rho_av, s_av, & |
---|
106 | sa_av, u_av, v_av, vpt_av, w_av |
---|
107 | |
---|
108 | USE cloud_parameters, & |
---|
109 | ONLY: l_d_cp, pt_d_t |
---|
110 | |
---|
111 | USE control_parameters, & |
---|
112 | ONLY: cloud_physics, domask, domask_no, domask_time_count, mask_i, & |
---|
113 | mask_j, mask_k, mask_size, mask_size_l, mask_start_l, & |
---|
114 | max_masks, message_string, mid, nz_do3d, simulated_time |
---|
115 | USE cpulog, & |
---|
116 | ONLY: cpu_log, log_point |
---|
117 | |
---|
118 | USE indices, & |
---|
119 | ONLY: nbgp, nxl, nxr, nyn, nys, nzb, nzt |
---|
120 | |
---|
121 | USE kinds |
---|
122 | |
---|
123 | USE NETCDF |
---|
124 | |
---|
125 | USE netcdf_interface, & |
---|
126 | ONLY: id_set_mask, id_var_domask, id_var_time_mask, nc_stat, & |
---|
127 | netcdf_data_format, netcdf_handle_error |
---|
128 | |
---|
129 | USE particle_attributes, & |
---|
130 | ONLY: grid_particles, number_of_particles, particles, & |
---|
131 | particle_advection_start, prt_count |
---|
132 | |
---|
133 | USE pegrid |
---|
134 | |
---|
135 | USE radiation_model_mod, & |
---|
136 | ONLY: radiation, radiation_data_output_mask |
---|
137 | |
---|
138 | IMPLICIT NONE |
---|
139 | |
---|
140 | INTEGER(iwp) :: av !< |
---|
141 | INTEGER(iwp) :: ngp !< |
---|
142 | INTEGER(iwp) :: i !< |
---|
143 | INTEGER(iwp) :: if !< |
---|
144 | INTEGER(iwp) :: j !< |
---|
145 | INTEGER(iwp) :: k !< |
---|
146 | INTEGER(iwp) :: n !< |
---|
147 | INTEGER(iwp) :: netcdf_data_format_save !< |
---|
148 | INTEGER(iwp) :: psi !< |
---|
149 | INTEGER(iwp) :: sender !< |
---|
150 | INTEGER(iwp) :: ind(6) !< |
---|
151 | |
---|
152 | LOGICAL :: found !< |
---|
153 | LOGICAL :: resorted !< |
---|
154 | |
---|
155 | REAL(wp) :: mean_r !< |
---|
156 | REAL(wp) :: s_r2 !< |
---|
157 | REAL(wp) :: s_r3 !< |
---|
158 | |
---|
159 | REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: local_pf !< |
---|
160 | #if defined( __parallel ) |
---|
161 | REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: total_pf !< |
---|
162 | #endif |
---|
163 | REAL(wp), DIMENSION(:,:,:), POINTER :: to_be_resorted !< |
---|
164 | |
---|
165 | ! |
---|
166 | !-- Return, if nothing to output |
---|
167 | IF ( domask_no(mid,av) == 0 ) RETURN |
---|
168 | |
---|
169 | CALL cpu_log (log_point(49),'data_output_mask','start') |
---|
170 | |
---|
171 | ! |
---|
172 | !-- Parallel netcdf output is not tested so far for masked data, hence |
---|
173 | !-- netcdf_data_format is switched back to non-paralell output. |
---|
174 | netcdf_data_format_save = netcdf_data_format |
---|
175 | IF ( netcdf_data_format == 5 ) netcdf_data_format = 3 |
---|
176 | IF ( netcdf_data_format == 6 ) netcdf_data_format = 4 |
---|
177 | |
---|
178 | ! |
---|
179 | !-- Open output file. |
---|
180 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
181 | CALL check_open( 200+mid+av*max_masks ) |
---|
182 | ENDIF |
---|
183 | |
---|
184 | ! |
---|
185 | !-- Allocate total and local output arrays. |
---|
186 | #if defined( __parallel ) |
---|
187 | IF ( myid == 0 ) THEN |
---|
188 | ALLOCATE( total_pf(mask_size(mid,1),mask_size(mid,2),mask_size(mid,3)) ) |
---|
189 | ENDIF |
---|
190 | #endif |
---|
191 | ALLOCATE( local_pf(mask_size_l(mid,1),mask_size_l(mid,2), & |
---|
192 | mask_size_l(mid,3)) ) |
---|
193 | |
---|
194 | ! |
---|
195 | !-- Update the netCDF time axis. |
---|
196 | domask_time_count(mid,av) = domask_time_count(mid,av) + 1 |
---|
197 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
198 | nc_stat = NF90_PUT_VAR( id_set_mask(mid,av), id_var_time_mask(mid,av), & |
---|
199 | (/ simulated_time /), & |
---|
200 | start = (/ domask_time_count(mid,av) /), & |
---|
201 | count = (/ 1 /) ) |
---|
202 | CALL netcdf_handle_error( 'data_output_mask', 460 ) |
---|
203 | ENDIF |
---|
204 | |
---|
205 | ! |
---|
206 | !-- Loop over all variables to be written. |
---|
207 | if = 1 |
---|
208 | |
---|
209 | DO WHILE ( domask(mid,av,if)(1:1) /= ' ' ) |
---|
210 | ! |
---|
211 | !-- Reallocate local_pf on PE 0 since its shape changes during MPI exchange |
---|
212 | IF ( netcdf_data_format < 5 .AND. myid == 0 .AND. if > 1 ) THEN |
---|
213 | DEALLOCATE( local_pf ) |
---|
214 | ALLOCATE( local_pf(mask_size_l(mid,1),mask_size_l(mid,2), & |
---|
215 | mask_size_l(mid,3)) ) |
---|
216 | ENDIF |
---|
217 | ! |
---|
218 | !-- Set flag to steer output of radiation, land-surface, or user-defined |
---|
219 | !-- quantities |
---|
220 | found = .FALSE. |
---|
221 | ! |
---|
222 | !-- Store the variable chosen. |
---|
223 | resorted = .FALSE. |
---|
224 | SELECT CASE ( TRIM( domask(mid,av,if) ) ) |
---|
225 | |
---|
226 | CASE ( 'e' ) |
---|
227 | IF ( av == 0 ) THEN |
---|
228 | to_be_resorted => e |
---|
229 | ELSE |
---|
230 | to_be_resorted => e_av |
---|
231 | ENDIF |
---|
232 | |
---|
233 | CASE ( 'lpt' ) |
---|
234 | IF ( av == 0 ) THEN |
---|
235 | to_be_resorted => pt |
---|
236 | ELSE |
---|
237 | to_be_resorted => lpt_av |
---|
238 | ENDIF |
---|
239 | |
---|
240 | CASE ( 'nr' ) |
---|
241 | IF ( av == 0 ) THEN |
---|
242 | to_be_resorted => nr |
---|
243 | ELSE |
---|
244 | to_be_resorted => nr_av |
---|
245 | ENDIF |
---|
246 | |
---|
247 | CASE ( 'p' ) |
---|
248 | IF ( av == 0 ) THEN |
---|
249 | to_be_resorted => p |
---|
250 | ELSE |
---|
251 | to_be_resorted => p_av |
---|
252 | ENDIF |
---|
253 | |
---|
254 | CASE ( 'pc' ) ! particle concentration (requires ghostpoint exchange) |
---|
255 | IF ( av == 0 ) THEN |
---|
256 | tend = prt_count |
---|
257 | CALL exchange_horiz( tend, nbgp ) |
---|
258 | DO i = 1, mask_size_l(mid,1) |
---|
259 | DO j = 1, mask_size_l(mid,2) |
---|
260 | DO k = 1, mask_size_l(mid,3) |
---|
261 | local_pf(i,j,k) = tend(mask_k(mid,k), & |
---|
262 | mask_j(mid,j),mask_i(mid,i)) |
---|
263 | ENDDO |
---|
264 | ENDDO |
---|
265 | ENDDO |
---|
266 | resorted = .TRUE. |
---|
267 | ELSE |
---|
268 | CALL exchange_horiz( pc_av, nbgp ) |
---|
269 | to_be_resorted => pc_av |
---|
270 | ENDIF |
---|
271 | |
---|
272 | CASE ( 'pr' ) ! mean particle radius (effective radius) |
---|
273 | IF ( av == 0 ) THEN |
---|
274 | IF ( simulated_time >= particle_advection_start ) THEN |
---|
275 | DO i = nxl, nxr |
---|
276 | DO j = nys, nyn |
---|
277 | DO k = nzb, nz_do3d |
---|
278 | number_of_particles = prt_count(k,j,i) |
---|
279 | IF (number_of_particles <= 0) CYCLE |
---|
280 | particles => grid_particles(k,j,i)%particles(1:number_of_particles) |
---|
281 | s_r2 = 0.0_wp |
---|
282 | s_r3 = 0.0_wp |
---|
283 | DO n = 1, number_of_particles |
---|
284 | IF ( particles(n)%particle_mask ) THEN |
---|
285 | s_r2 = s_r2 + grid_particles(k,j,i)%particles(n)%radius**2 * & |
---|
286 | grid_particles(k,j,i)%particles(n)%weight_factor |
---|
287 | s_r3 = s_r3 + grid_particles(k,j,i)%particles(n)%radius**3 * & |
---|
288 | grid_particles(k,j,i)%particles(n)%weight_factor |
---|
289 | ENDIF |
---|
290 | ENDDO |
---|
291 | IF ( s_r2 > 0.0_wp ) THEN |
---|
292 | mean_r = s_r3 / s_r2 |
---|
293 | ELSE |
---|
294 | mean_r = 0.0_wp |
---|
295 | ENDIF |
---|
296 | tend(k,j,i) = mean_r |
---|
297 | ENDDO |
---|
298 | ENDDO |
---|
299 | ENDDO |
---|
300 | CALL exchange_horiz( tend, nbgp ) |
---|
301 | ELSE |
---|
302 | tend = 0.0_wp |
---|
303 | ENDIF |
---|
304 | DO i = 1, mask_size_l(mid,1) |
---|
305 | DO j = 1, mask_size_l(mid,2) |
---|
306 | DO k = 1, mask_size_l(mid,3) |
---|
307 | local_pf(i,j,k) = tend(mask_k(mid,k), & |
---|
308 | mask_j(mid,j),mask_i(mid,i)) |
---|
309 | ENDDO |
---|
310 | ENDDO |
---|
311 | ENDDO |
---|
312 | resorted = .TRUE. |
---|
313 | ELSE |
---|
314 | CALL exchange_horiz( pr_av, nbgp ) |
---|
315 | to_be_resorted => pr_av |
---|
316 | ENDIF |
---|
317 | |
---|
318 | CASE ( 'pt' ) |
---|
319 | IF ( av == 0 ) THEN |
---|
320 | IF ( .NOT. cloud_physics ) THEN |
---|
321 | to_be_resorted => pt |
---|
322 | ELSE |
---|
323 | DO i = 1, mask_size_l(mid,1) |
---|
324 | DO j = 1, mask_size_l(mid,2) |
---|
325 | DO k = 1, mask_size_l(mid,3) |
---|
326 | local_pf(i,j,k) = & |
---|
327 | pt(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i)) & |
---|
328 | + l_d_cp * pt_d_t(mask_k(mid,k)) * & |
---|
329 | ql(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i)) |
---|
330 | ENDDO |
---|
331 | ENDDO |
---|
332 | ENDDO |
---|
333 | resorted = .TRUE. |
---|
334 | ENDIF |
---|
335 | ELSE |
---|
336 | to_be_resorted => pt_av |
---|
337 | ENDIF |
---|
338 | |
---|
339 | CASE ( 'q' ) |
---|
340 | IF ( av == 0 ) THEN |
---|
341 | to_be_resorted => q |
---|
342 | ELSE |
---|
343 | to_be_resorted => q_av |
---|
344 | ENDIF |
---|
345 | |
---|
346 | CASE ( 'qc' ) |
---|
347 | IF ( av == 0 ) THEN |
---|
348 | to_be_resorted => qc |
---|
349 | ELSE |
---|
350 | to_be_resorted => qc_av |
---|
351 | ENDIF |
---|
352 | |
---|
353 | CASE ( 'ql' ) |
---|
354 | IF ( av == 0 ) THEN |
---|
355 | to_be_resorted => ql |
---|
356 | ELSE |
---|
357 | to_be_resorted => ql_av |
---|
358 | ENDIF |
---|
359 | |
---|
360 | CASE ( 'ql_c' ) |
---|
361 | IF ( av == 0 ) THEN |
---|
362 | to_be_resorted => ql_c |
---|
363 | ELSE |
---|
364 | to_be_resorted => ql_c_av |
---|
365 | ENDIF |
---|
366 | |
---|
367 | CASE ( 'ql_v' ) |
---|
368 | IF ( av == 0 ) THEN |
---|
369 | to_be_resorted => ql_v |
---|
370 | ELSE |
---|
371 | to_be_resorted => ql_v_av |
---|
372 | ENDIF |
---|
373 | |
---|
374 | CASE ( 'ql_vp' ) |
---|
375 | IF ( av == 0 ) THEN |
---|
376 | IF ( simulated_time >= particle_advection_start ) THEN |
---|
377 | DO i = nxl, nxr |
---|
378 | DO j = nys, nyn |
---|
379 | DO k = nzb, nz_do3d |
---|
380 | number_of_particles = prt_count(k,j,i) |
---|
381 | IF (number_of_particles <= 0) CYCLE |
---|
382 | particles => grid_particles(k,j,i)%particles(1:number_of_particles) |
---|
383 | DO n = 1, number_of_particles |
---|
384 | IF ( particles(n)%particle_mask ) THEN |
---|
385 | tend(k,j,i) = tend(k,j,i) + & |
---|
386 | particles(n)%weight_factor / & |
---|
387 | prt_count(k,j,i) |
---|
388 | ENDIF |
---|
389 | ENDDO |
---|
390 | ENDDO |
---|
391 | ENDDO |
---|
392 | ENDDO |
---|
393 | CALL exchange_horiz( tend, nbgp ) |
---|
394 | ELSE |
---|
395 | tend = 0.0_wp |
---|
396 | ENDIF |
---|
397 | DO i = 1, mask_size_l(mid,1) |
---|
398 | DO j = 1, mask_size_l(mid,2) |
---|
399 | DO k = 1, mask_size_l(mid,3) |
---|
400 | local_pf(i,j,k) = tend(mask_k(mid,k), & |
---|
401 | mask_j(mid,j),mask_i(mid,i)) |
---|
402 | ENDDO |
---|
403 | ENDDO |
---|
404 | ENDDO |
---|
405 | resorted = .TRUE. |
---|
406 | ELSE |
---|
407 | CALL exchange_horiz( ql_vp_av, nbgp ) |
---|
408 | to_be_resorted => ql_vp_av |
---|
409 | ENDIF |
---|
410 | |
---|
411 | CASE ( 'qv' ) |
---|
412 | IF ( av == 0 ) THEN |
---|
413 | DO i = 1, mask_size_l(mid,1) |
---|
414 | DO j = 1, mask_size_l(mid,2) |
---|
415 | DO k = 1, mask_size_l(mid,3) |
---|
416 | local_pf(i,j,k) = & |
---|
417 | q(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i)) - & |
---|
418 | ql(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i)) |
---|
419 | ENDDO |
---|
420 | ENDDO |
---|
421 | ENDDO |
---|
422 | resorted = .TRUE. |
---|
423 | ELSE |
---|
424 | to_be_resorted => qv_av |
---|
425 | ENDIF |
---|
426 | |
---|
427 | CASE ( 'qr' ) |
---|
428 | IF ( av == 0 ) THEN |
---|
429 | to_be_resorted => qr |
---|
430 | ELSE |
---|
431 | to_be_resorted => qr_av |
---|
432 | ENDIF |
---|
433 | |
---|
434 | CASE ( 'rho' ) |
---|
435 | IF ( av == 0 ) THEN |
---|
436 | to_be_resorted => rho |
---|
437 | ELSE |
---|
438 | to_be_resorted => rho_av |
---|
439 | ENDIF |
---|
440 | |
---|
441 | CASE ( 's' ) |
---|
442 | IF ( av == 0 ) THEN |
---|
443 | to_be_resorted => s |
---|
444 | ELSE |
---|
445 | to_be_resorted => s_av |
---|
446 | ENDIF |
---|
447 | |
---|
448 | CASE ( 'sa' ) |
---|
449 | IF ( av == 0 ) THEN |
---|
450 | to_be_resorted => sa |
---|
451 | ELSE |
---|
452 | to_be_resorted => sa_av |
---|
453 | ENDIF |
---|
454 | |
---|
455 | CASE ( 'u' ) |
---|
456 | IF ( av == 0 ) THEN |
---|
457 | to_be_resorted => u |
---|
458 | ELSE |
---|
459 | to_be_resorted => u_av |
---|
460 | ENDIF |
---|
461 | |
---|
462 | CASE ( 'v' ) |
---|
463 | IF ( av == 0 ) THEN |
---|
464 | to_be_resorted => v |
---|
465 | ELSE |
---|
466 | to_be_resorted => v_av |
---|
467 | ENDIF |
---|
468 | |
---|
469 | CASE ( 'vpt' ) |
---|
470 | IF ( av == 0 ) THEN |
---|
471 | to_be_resorted => vpt |
---|
472 | ELSE |
---|
473 | to_be_resorted => vpt_av |
---|
474 | ENDIF |
---|
475 | |
---|
476 | CASE ( 'w' ) |
---|
477 | IF ( av == 0 ) THEN |
---|
478 | to_be_resorted => w |
---|
479 | ELSE |
---|
480 | to_be_resorted => w_av |
---|
481 | ENDIF |
---|
482 | |
---|
483 | CASE DEFAULT |
---|
484 | |
---|
485 | ! |
---|
486 | !-- Radiation quantity |
---|
487 | IF ( radiation ) THEN |
---|
488 | CALL radiation_data_output_mask(av, domask(mid,av,if), found, & |
---|
489 | local_pf ) |
---|
490 | ENDIF |
---|
491 | |
---|
492 | ! |
---|
493 | !-- User defined quantity |
---|
494 | IF ( .NOT. found ) THEN |
---|
495 | CALL user_data_output_mask(av, domask(mid,av,if), found, & |
---|
496 | local_pf ) |
---|
497 | ENDIF |
---|
498 | |
---|
499 | resorted = .TRUE. |
---|
500 | |
---|
501 | IF ( .NOT. found ) THEN |
---|
502 | WRITE ( message_string, * ) 'no output available for: ', & |
---|
503 | TRIM( domask(mid,av,if) ) |
---|
504 | CALL message( 'data_output_mask', 'PA0327', 0, 0, 0, 6, 0 ) |
---|
505 | ENDIF |
---|
506 | |
---|
507 | END SELECT |
---|
508 | |
---|
509 | ! |
---|
510 | !-- Resort the array to be output, if not done above |
---|
511 | IF ( .NOT. resorted ) THEN |
---|
512 | DO i = 1, mask_size_l(mid,1) |
---|
513 | DO j = 1, mask_size_l(mid,2) |
---|
514 | DO k = 1, mask_size_l(mid,3) |
---|
515 | local_pf(i,j,k) = to_be_resorted(mask_k(mid,k), & |
---|
516 | mask_j(mid,j),mask_i(mid,i)) |
---|
517 | ENDDO |
---|
518 | ENDDO |
---|
519 | ENDDO |
---|
520 | ENDIF |
---|
521 | |
---|
522 | ! |
---|
523 | !-- I/O block. I/O methods are implemented |
---|
524 | !-- (1) for parallel execution |
---|
525 | !-- a. with netCDF 4 parallel I/O-enabled library |
---|
526 | !-- b. with netCDF 3 library |
---|
527 | !-- (2) for serial execution. |
---|
528 | !-- The choice of method depends on the correct setting of preprocessor |
---|
529 | !-- directives __parallel and __netcdf4_parallel as well as on the parameter |
---|
530 | !-- netcdf_data_format. |
---|
531 | #if defined( __parallel ) |
---|
532 | #if defined( __netcdf4_parallel ) |
---|
533 | IF ( netcdf_data_format > 4 ) THEN |
---|
534 | ! |
---|
535 | !-- (1) a. Parallel I/O using netCDF 4 (not yet tested) |
---|
536 | nc_stat = NF90_PUT_VAR( id_set_mask(mid,av), & |
---|
537 | id_var_domask(mid,av,if), & |
---|
538 | local_pf, & |
---|
539 | start = (/ mask_start_l(mid,1), mask_start_l(mid,2), & |
---|
540 | mask_start_l(mid,3), domask_time_count(mid,av) /), & |
---|
541 | count = (/ mask_size_l(mid,1), mask_size_l(mid,2), & |
---|
542 | mask_size_l(mid,3), 1 /) ) |
---|
543 | CALL netcdf_handle_error( 'data_output_mask', 461 ) |
---|
544 | ELSE |
---|
545 | #endif |
---|
546 | ! |
---|
547 | !-- (1) b. Conventional I/O only through PE0 |
---|
548 | !-- PE0 receives partial arrays from all processors of the respective mask |
---|
549 | !-- and outputs them. Here a barrier has to be set, because otherwise |
---|
550 | !-- "-MPI- FATAL: Remote protocol queue full" may occur. |
---|
551 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
552 | |
---|
553 | ngp = mask_size_l(mid,1) * mask_size_l(mid,2) * mask_size_l(mid,3) |
---|
554 | IF ( myid == 0 ) THEN |
---|
555 | ! |
---|
556 | !-- Local array can be relocated directly. |
---|
557 | total_pf( & |
---|
558 | mask_start_l(mid,1):mask_start_l(mid,1)+mask_size_l(mid,1)-1, & |
---|
559 | mask_start_l(mid,2):mask_start_l(mid,2)+mask_size_l(mid,2)-1, & |
---|
560 | mask_start_l(mid,3):mask_start_l(mid,3)+mask_size_l(mid,3)-1 ) & |
---|
561 | = local_pf |
---|
562 | ! |
---|
563 | !-- Receive data from all other PEs. |
---|
564 | DO n = 1, numprocs-1 |
---|
565 | ! |
---|
566 | !-- Receive index limits first, then array. |
---|
567 | !-- Index limits are received in arbitrary order from the PEs. |
---|
568 | CALL MPI_RECV( ind(1), 6, MPI_INTEGER, MPI_ANY_SOURCE, 0, & |
---|
569 | comm2d, status, ierr ) |
---|
570 | ! |
---|
571 | !-- Not all PEs have data for the mask |
---|
572 | IF ( ind(1) /= -9999 ) THEN |
---|
573 | ngp = ( ind(2)-ind(1)+1 ) * (ind(4)-ind(3)+1 ) * & |
---|
574 | ( ind(6)-ind(5)+1 ) |
---|
575 | sender = status(MPI_SOURCE) |
---|
576 | DEALLOCATE( local_pf ) |
---|
577 | ALLOCATE(local_pf(ind(1):ind(2),ind(3):ind(4),ind(5):ind(6))) |
---|
578 | CALL MPI_RECV( local_pf(ind(1),ind(3),ind(5)), ngp, & |
---|
579 | MPI_REAL, sender, 1, comm2d, status, ierr ) |
---|
580 | total_pf(ind(1):ind(2),ind(3):ind(4),ind(5):ind(6)) & |
---|
581 | = local_pf |
---|
582 | ENDIF |
---|
583 | ENDDO |
---|
584 | |
---|
585 | nc_stat = NF90_PUT_VAR( id_set_mask(mid,av), & |
---|
586 | id_var_domask(mid,av,if), total_pf, & |
---|
587 | start = (/ 1, 1, 1, domask_time_count(mid,av) /), & |
---|
588 | count = (/ mask_size(mid,1), mask_size(mid,2), & |
---|
589 | mask_size(mid,3), 1 /) ) |
---|
590 | CALL netcdf_handle_error( 'data_output_mask', 462 ) |
---|
591 | |
---|
592 | ELSE |
---|
593 | ! |
---|
594 | !-- If at least part of the mask resides on the PE, send the index |
---|
595 | !-- limits for the target array, otherwise send -9999 to PE0. |
---|
596 | IF ( mask_size_l(mid,1) > 0 .AND. mask_size_l(mid,2) > 0 .AND. & |
---|
597 | mask_size_l(mid,3) > 0 ) & |
---|
598 | THEN |
---|
599 | ind(1) = mask_start_l(mid,1) |
---|
600 | ind(2) = mask_start_l(mid,1) + mask_size_l(mid,1) - 1 |
---|
601 | ind(3) = mask_start_l(mid,2) |
---|
602 | ind(4) = mask_start_l(mid,2) + mask_size_l(mid,2) - 1 |
---|
603 | ind(5) = mask_start_l(mid,3) |
---|
604 | ind(6) = mask_start_l(mid,3) + mask_size_l(mid,3) - 1 |
---|
605 | ELSE |
---|
606 | ind(1) = -9999; ind(2) = -9999 |
---|
607 | ind(3) = -9999; ind(4) = -9999 |
---|
608 | ind(5) = -9999; ind(6) = -9999 |
---|
609 | ENDIF |
---|
610 | CALL MPI_SEND( ind(1), 6, MPI_INTEGER, 0, 0, comm2d, ierr ) |
---|
611 | ! |
---|
612 | !-- If applicable, send data to PE0. |
---|
613 | IF ( ind(1) /= -9999 ) THEN |
---|
614 | CALL MPI_SEND( local_pf(1,1,1), ngp, MPI_REAL, 0, 1, comm2d, & |
---|
615 | ierr ) |
---|
616 | ENDIF |
---|
617 | ENDIF |
---|
618 | ! |
---|
619 | !-- A barrier has to be set, because otherwise some PEs may proceed too |
---|
620 | !-- fast so that PE0 may receive wrong data on tag 0. |
---|
621 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
622 | #if defined( __netcdf4_parallel ) |
---|
623 | ENDIF |
---|
624 | #endif |
---|
625 | #else |
---|
626 | ! |
---|
627 | !-- (2) For serial execution of PALM, the single processor (PE0) holds all |
---|
628 | !-- data and writes them directly to file. |
---|
629 | nc_stat = NF90_PUT_VAR( id_set_mask(mid,av), & |
---|
630 | id_var_domask(mid,av,if), & |
---|
631 | local_pf, & |
---|
632 | start = (/ 1, 1, 1, domask_time_count(mid,av) /), & |
---|
633 | count = (/ mask_size_l(mid,1), mask_size_l(mid,2), & |
---|
634 | mask_size_l(mid,3), 1 /) ) |
---|
635 | CALL netcdf_handle_error( 'data_output_mask', 463 ) |
---|
636 | #endif |
---|
637 | |
---|
638 | if = if + 1 |
---|
639 | |
---|
640 | ENDDO |
---|
641 | |
---|
642 | ! |
---|
643 | !-- Deallocate temporary arrays. |
---|
644 | DEALLOCATE( local_pf ) |
---|
645 | #if defined( __parallel ) |
---|
646 | IF ( myid == 0 ) THEN |
---|
647 | DEALLOCATE( total_pf ) |
---|
648 | ENDIF |
---|
649 | #endif |
---|
650 | |
---|
651 | ! |
---|
652 | !-- Switch back to original format given by user (see beginning of this routine) |
---|
653 | netcdf_data_format = netcdf_data_format_save |
---|
654 | |
---|
655 | CALL cpu_log( log_point(49), 'data_output_mask', 'stop' ) |
---|
656 | #endif |
---|
657 | |
---|
658 | END SUBROUTINE data_output_mask |
---|