source: palm/trunk/SOURCE/data_output_2d.f90 @ 1053

Last change on this file since 1053 was 1053, checked in by hoffmann, 11 years ago

two-moment cloud physics implemented

  • Property svn:keywords set to Id
File size: 71.6 KB
Line 
1 SUBROUTINE data_output_2d( mode, av )
2
3!--------------------------------------------------------------------------------!
4! This file is part of PALM.
5!
6! PALM is free software: you can redistribute it and/or modify it under the terms
7! of the GNU General Public License as published by the Free Software Foundation,
8! either version 3 of the License, or (at your option) any later version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 1997-2012  Leibniz University Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22! +qr, nr, qc and cross sections
23!
24! Former revisions:
25! -----------------
26! $Id: data_output_2d.f90 1053 2012-11-13 17:11:03Z hoffmann $
27!
28! 1036 2012-10-22 13:43:42Z raasch
29! code put under GPL (PALM 3.9)
30!
31! 1031 2012-10-19 14:35:30Z raasch
32! netCDF4 without parallel file support implemented
33!
34! 1007 2012-09-19 14:30:36Z franke
35! Bugfix: missing calculation of ql_vp added
36!
37! 978 2012-08-09 08:28:32Z fricke
38! +z0h
39!
40! 790 2011-11-29 03:11:20Z raasch
41! bugfix: calculation of 'pr' must depend on the particle weighting factor
42!
43! 771 2011-10-27 10:56:21Z heinze
44! +lpt
45!
46! 759 2011-09-15 13:58:31Z raasch
47! Splitting of parallel I/O
48!
49! 729 2011-05-26 10:33:34Z heinze
50! Exchange ghost layers for p regardless of used pressure solver (except SOR).
51!
52! 691 2011-03-04 08:45:30Z maronga
53! Replaced simulated_time by time_since_reference_point
54!
55! 673 2011-01-18 16:19:48Z suehring
56! When using Multigrid or SOR solver an additional CALL exchange_horiz is
57! is needed for pressure output.
58!
59! 667 2010-12-23 12:06:00Z suehring/gryschka
60! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng in loops and
61! allocation of arrays local_2d and total_2d.
62! Calls of exchange_horiz are modiefied.
63!
64! 622 2010-12-10 08:08:13Z raasch
65! optional barriers included in order to speed up collective operations
66!
67! 493 2010-03-01 08:30:24Z raasch
68! netCDF4 support (parallel output)
69!
70! 367 2009-08-25 08:35:52Z maronga
71! simulated_time in netCDF output replaced by time_since_reference_point.
72! Output of netCDF messages with aid of message handling routine.
73! Bugfix: averaging along z is not allowed for 2d quantities (e.g. u* and z0)
74! Output of messages replaced by message handling routine.
75! Output of user defined 2D (XY) arrays at z=nzb+1 is now possible
76! Bugfix: to_be_resorted => s_av for time-averaged scalars
77! Calculation of shf* and qsws* added.
78!
79! 215 2008-11-18 09:54:31Z raasch
80! Bugfix: no output of particle concentration and radius unless particles
81! have been started
82!
83! 96 2007-06-04 08:07:41Z raasch
84! Output of density and salinity
85!
86! 75 2007-03-22 09:54:05Z raasch
87! Output of precipitation amount/rate and roughness length,
88! 2nd+3rd argument removed from exchange horiz
89!
90! RCS Log replace by Id keyword, revision history cleaned up
91!
92! Revision 1.5  2006/08/22 13:50:29  raasch
93! xz and yz cross sections now up to nzt+1
94!
95! Revision 1.2  2006/02/23 10:19:22  raasch
96! Output of time-averaged data, output of averages along x, y, or z,
97! output of user-defined quantities,
98! section data are copied from local_pf to local_2d before they are output,
99! output of particle concentration and mean radius,
100! Former subroutine plot_2d renamed data_output_2d, pl2d.. renamed do2d..,
101! anz renamed ngp, ebene renamed section, pl2d_.._anz renamed do2d_.._n
102!
103! Revision 1.1  1997/08/11 06:24:09  raasch
104! Initial revision
105!
106!
107! Description:
108! ------------
109! Data output of horizontal cross-sections in netCDF format or binary format
110! compatible to old graphic software iso2d.
111! Attention: The position of the sectional planes is still not always computed
112! ---------  correctly. (zu is used always)!
113!------------------------------------------------------------------------------!
114
115    USE arrays_3d
116    USE averaging
117    USE cloud_parameters
118    USE control_parameters
119    USE cpulog
120    USE grid_variables
121    USE indices
122    USE interfaces
123    USE netcdf_control
124    USE particle_attributes
125    USE pegrid
126
127    IMPLICIT NONE
128
129    CHARACTER (LEN=2)  ::  do2d_mode, mode
130    CHARACTER (LEN=4)  ::  grid
131    CHARACTER (LEN=25) ::  section_chr
132    CHARACTER (LEN=50) ::  rtext
133    INTEGER ::  av, ngp, file_id, i, if, is, iis, j, k, l, layer_xy, n, psi, &
134                s, sender, &
135                ind(4)
136    LOGICAL ::  found, resorted, two_d
137    REAL    ::  mean_r, s_r3, s_r4
138    REAL, DIMENSION(:), ALLOCATABLE ::      level_z
139    REAL, DIMENSION(:,:), ALLOCATABLE ::    local_2d, local_2d_l
140    REAL, DIMENSION(:,:,:), ALLOCATABLE ::  local_pf
141#if defined( __parallel )
142    REAL, DIMENSION(:,:),   ALLOCATABLE ::  total_2d
143#endif
144    REAL, DIMENSION(:,:,:), POINTER ::  to_be_resorted
145
146    NAMELIST /LOCAL/  rtext
147
148    CALL cpu_log (log_point(3),'data_output_2d','start')
149
150!
151!-- Immediate return, if no output is requested (no respective sections
152!-- found in parameter data_output)
153    IF ( mode == 'xy'  .AND.  .NOT. data_output_xy(av) )  RETURN
154    IF ( mode == 'xz'  .AND.  .NOT. data_output_xz(av) )  RETURN
155    IF ( mode == 'yz'  .AND.  .NOT. data_output_yz(av) )  RETURN
156
157    two_d = .FALSE.    ! local variable to distinguish between output of pure 2D
158                       ! arrays and cross-sections of 3D arrays.
159
160!
161!-- Depending on the orientation of the cross-section, the respective output
162!-- files have to be opened.
163    SELECT CASE ( mode )
164
165       CASE ( 'xy' )
166          s = 1
167          ALLOCATE( level_z(nzb:nzt+1), local_2d(nxlg:nxrg,nysg:nyng) )
168
169!
170!--       Parallel netCDF4/HDF5 output is done on all PEs, all other on PE0 only
171          IF ( netcdf_output .AND. ( myid == 0 .OR. netcdf_data_format > 4 ) ) &
172          THEN
173             CALL check_open( 101+av*10 )
174          ENDIF
175
176          IF ( data_output_2d_on_each_pe )  THEN
177             CALL check_open( 21 )
178          ELSE
179             IF ( myid == 0 )  THEN
180                IF ( iso2d_output )  CALL check_open( 21 )
181#if defined( __parallel )
182                ALLOCATE( total_2d(-nbgp:nx+nbgp,-nbgp:ny+nbgp) )
183#endif
184             ENDIF
185          ENDIF
186
187       CASE ( 'xz' )
188          s = 2
189          ALLOCATE( local_2d(nxlg:nxrg,nzb:nzt+1) )
190
191!
192!--       Parallel netCDF4/HDF5 output is done on all PEs, all other on PE0 only
193          IF ( netcdf_output .AND. ( myid == 0 .OR. netcdf_data_format > 4 ) ) &
194          THEN
195             CALL check_open( 102+av*10 )
196          ENDIF
197
198          IF ( data_output_2d_on_each_pe )  THEN
199             CALL check_open( 22 )
200          ELSE
201             IF ( myid == 0 )  THEN
202                IF ( iso2d_output )  CALL check_open( 22 )
203#if defined( __parallel )
204                ALLOCATE( total_2d(-nbgp:nx+nbgp,nzb:nzt+1) )
205#endif
206             ENDIF
207          ENDIF
208
209       CASE ( 'yz' )
210
211          s = 3
212          ALLOCATE( local_2d(nysg:nyng,nzb:nzt+1) )
213
214!
215!--       Parallel netCDF4/HDF5 output is done on all PEs, all other on PE0 only
216          IF ( netcdf_output .AND. ( myid == 0 .OR. netcdf_data_format > 4 ) ) &
217          THEN
218             CALL check_open( 103+av*10 )
219          ENDIF
220
221          IF ( data_output_2d_on_each_pe )  THEN
222             CALL check_open( 23 )
223          ELSE
224             IF ( myid == 0 )  THEN
225                IF ( iso2d_output )  CALL check_open( 23 )
226#if defined( __parallel )
227                ALLOCATE( total_2d(-nbgp:ny+nbgp,nzb:nzt+1) )
228#endif
229             ENDIF
230          ENDIF
231
232       CASE DEFAULT
233
234          message_string = 'unknown cross-section: ' // TRIM( mode )
235          CALL message( 'data_output_2d', 'PA0180', 1, 2, 0, 6, 0 )
236
237    END SELECT
238
239!
240!-- Allocate a temporary array for resorting (kji -> ijk).
241    ALLOCATE( local_pf(nxlg:nxrg,nysg:nyng,nzb:nzt+1) )
242
243!
244!-- Loop of all variables to be written.
245!-- Output dimensions chosen
246    if = 1
247    l = MAX( 2, LEN_TRIM( do2d(av,if) ) )
248    do2d_mode = do2d(av,if)(l-1:l)
249
250    DO  WHILE ( do2d(av,if)(1:1) /= ' ' )
251
252       IF ( do2d_mode == mode )  THEN
253!
254!--       Store the array chosen on the temporary array.
255          resorted = .FALSE.
256          SELECT CASE ( TRIM( do2d(av,if) ) )
257
258             CASE ( 'e_xy', 'e_xz', 'e_yz' )
259                IF ( av == 0 )  THEN
260                   to_be_resorted => e
261                ELSE
262                   to_be_resorted => e_av
263                ENDIF
264                IF ( mode == 'xy' )  level_z = zu
265
266             CASE ( 'lpt_xy', 'lpt_xz', 'lpt_yz' )
267                IF ( av == 0 )  THEN
268                   to_be_resorted => pt
269                ELSE
270                   to_be_resorted => lpt_av
271                ENDIF
272                IF ( mode == 'xy' )  level_z = zu
273
274             CASE ( 'lwp*_xy' )        ! 2d-array
275                IF ( av == 0 )  THEN
276                   DO  i = nxlg, nxrg
277                      DO  j = nysg, nyng
278                         local_pf(i,j,nzb+1) = SUM( ql(nzb:nzt,j,i) * &
279                                                    dzw(1:nzt+1) )
280                      ENDDO
281                   ENDDO
282                ELSE
283                   DO  i = nxlg, nxrg
284                      DO  j = nysg, nyng
285                         local_pf(i,j,nzb+1) = lwp_av(j,i)
286                      ENDDO
287                   ENDDO
288                ENDIF
289                resorted = .TRUE.
290                two_d = .TRUE.
291                level_z(nzb+1) = zu(nzb+1)
292
293             CASE ( 'nr_xy', 'nr_xz', 'nr_yz' )
294                IF ( av == 0 )  THEN
295                   to_be_resorted => nr
296                ELSE
297                   to_be_resorted => nr_av
298                ENDIF
299                IF ( mode == 'xy' )  level_z = zu
300
301             CASE ( 'p_xy', 'p_xz', 'p_yz' )
302                IF ( av == 0 )  THEN
303                   IF ( psolver /= 'sor' )  CALL exchange_horiz( p, nbgp )
304                   to_be_resorted => p
305                ELSE
306                   IF ( psolver /= 'sor' )  CALL exchange_horiz( p_av, nbgp )
307                   to_be_resorted => p_av
308                ENDIF
309                IF ( mode == 'xy' )  level_z = zu
310
311             CASE ( 'pc_xy', 'pc_xz', 'pc_yz' )  ! particle concentration
312                IF ( av == 0 )  THEN
313                   IF ( simulated_time >= particle_advection_start )  THEN
314                      tend = prt_count
315                      CALL exchange_horiz( tend, nbgp )
316                   ELSE
317                      tend = 0.0
318                   ENDIF
319                   DO  i = nxlg, nxrg
320                      DO  j = nysg, nyng
321                         DO  k = nzb, nzt+1
322                            local_pf(i,j,k) = tend(k,j,i)
323                         ENDDO
324                      ENDDO
325                   ENDDO
326                   resorted = .TRUE.
327                ELSE
328                   CALL exchange_horiz( pc_av, nbgp )
329                   to_be_resorted => pc_av
330                ENDIF
331
332             CASE ( 'pr_xy', 'pr_xz', 'pr_yz' )  ! mean particle radius
333                IF ( av == 0 )  THEN
334                   IF ( simulated_time >= particle_advection_start )  THEN
335                      DO  i = nxl, nxr
336                         DO  j = nys, nyn
337                            DO  k = nzb, nzt+1
338                               psi = prt_start_index(k,j,i)
339                               s_r3 = 0.0
340                               s_r4 = 0.0
341                               DO  n = psi, psi+prt_count(k,j,i)-1
342                                  s_r3 = s_r3 + particles(n)%radius**3 * &
343                                                particles(n)%weight_factor
344                                  s_r4 = s_r4 + particles(n)%radius**4 * &
345                                                particles(n)%weight_factor
346                               ENDDO
347                               IF ( s_r3 /= 0.0 )  THEN
348                                  mean_r = s_r4 / s_r3
349                               ELSE
350                                  mean_r = 0.0
351                               ENDIF
352                               tend(k,j,i) = mean_r
353                            ENDDO
354                         ENDDO
355                      ENDDO
356                      CALL exchange_horiz( tend, nbgp )
357                   ELSE
358                      tend = 0.0
359                   END IF
360                   DO  i = nxlg, nxrg
361                      DO  j = nysg, nyng
362                         DO  k = nzb, nzt+1
363                            local_pf(i,j,k) = tend(k,j,i)
364                         ENDDO
365                      ENDDO
366                   ENDDO
367                   resorted = .TRUE.
368                ELSE
369                   CALL exchange_horiz( pr_av, nbgp )
370                   to_be_resorted => pr_av
371                ENDIF
372
373             CASE ( 'pra*_xy' )        ! 2d-array / integral quantity => no av
374                CALL exchange_horiz_2d( precipitation_amount )
375                   DO  i = nxlg, nxrg
376                      DO  j = nysg, nyng
377                      local_pf(i,j,nzb+1) =  precipitation_amount(j,i)
378                   ENDDO
379                ENDDO
380                precipitation_amount = 0.0   ! reset for next integ. interval
381                resorted = .TRUE.
382                two_d = .TRUE.
383                level_z(nzb+1) = zu(nzb+1)
384
385             CASE ( 'prr*_xy' )        ! 2d-array
386                IF ( icloud_scheme == 1 )  THEN
387                   IF ( av == 0 )  THEN
388                      CALL exchange_horiz_2d( precipitation_rate )
389                      DO  i = nxlg, nxrg
390                         DO  j = nysg, nyng
391                            local_pf(i,j,nzb+1) =  precipitation_rate(j,i)
392                         ENDDO
393                      ENDDO
394                   ELSE
395                      CALL exchange_horiz_2d( precipitation_rate_av )
396                      DO  i = nxlg, nxrg
397                         DO  j = nysg, nyng
398                            local_pf(i,j,nzb+1) =  precipitation_rate_av(j,i)
399                         ENDDO
400                      ENDDO
401                   ENDIF
402                ELSE
403                   IF ( av == 0 )  THEN
404                      CALL exchange_horiz_2d( prr(nzb+1,:,:) )
405                      DO  i = nxlg, nxrg
406                         DO  j = nysg, nyng
407                            local_pf(i,j,nzb+1) = prr(nzb+1,j,i) * hyrho(nzb+1)
408                         ENDDO
409                      ENDDO
410                   ELSE
411                      CALL exchange_horiz_2d( prr_av(nzb+1,:,:) )
412                      DO  i = nxlg, nxrg
413                         DO  j = nysg, nyng
414                            local_pf(i,j,nzb+1) = prr_av(nzb+1,j,i) * hyrho(nzb+1)
415                         ENDDO
416                      ENDDO
417                   ENDIF
418                ENDIF
419                resorted = .TRUE.
420                two_d = .TRUE.
421                level_z(nzb+1) = zu(nzb+1)
422
423             CASE ( 'prr_xy', 'prr_xz', 'prr_yz' )
424                IF ( av == 0 )  THEN
425                   CALL exchange_horiz( prr, nbgp )
426                   DO  i = nxlg, nxrg
427                      DO  j = nysg, nyng
428                         DO  k = nzb, nzt+1
429                            local_pf(i,j,k) = prr(k,j,i)
430                         ENDDO
431                      ENDDO
432                   ENDDO
433                ELSE
434                   CALL exchange_horiz( prr_av, nbgp )
435                   DO  i = nxlg, nxrg
436                      DO  j = nysg, nyng
437                         DO  k = nzb, nzt+1
438                            local_pf(i,j,k) = prr_av(k,j,i)
439                         ENDDO
440                      ENDDO
441                   ENDDO
442                ENDIF
443                resorted = .TRUE.
444                IF ( mode == 'xy' )  level_z = zu
445
446             CASE ( 'pt_xy', 'pt_xz', 'pt_yz' )
447                IF ( av == 0 )  THEN
448                   IF ( .NOT. cloud_physics ) THEN
449                      to_be_resorted => pt
450                   ELSE
451                   DO  i = nxlg, nxrg
452                      DO  j = nysg, nyng
453                            DO  k = nzb, nzt+1
454                               local_pf(i,j,k) = pt(k,j,i) + l_d_cp *    &
455                                                             pt_d_t(k) * &
456                                                             ql(k,j,i)
457                            ENDDO
458                         ENDDO
459                      ENDDO
460                      resorted = .TRUE.
461                   ENDIF
462                ELSE
463                   to_be_resorted => pt_av
464                ENDIF
465                IF ( mode == 'xy' )  level_z = zu
466
467             CASE ( 'q_xy', 'q_xz', 'q_yz' )
468                IF ( av == 0 )  THEN
469                   to_be_resorted => q
470                ELSE
471                   to_be_resorted => q_av
472                ENDIF
473                IF ( mode == 'xy' )  level_z = zu
474
475             CASE ( 'qc_xy', 'qc_xz', 'qc_yz' )
476                IF ( av == 0 )  THEN
477                   to_be_resorted => ql
478                ELSE
479                   to_be_resorted => ql_av
480                ENDIF
481                IF ( mode == 'xy' )  level_z = zu
482
483             CASE ( 'ql_xy', 'ql_xz', 'ql_yz' )
484                IF ( av == 0 )  THEN
485                   IF ( icloud_scheme == 0 )  THEN
486                      DO  i = nxlg, nxrg
487                         DO  j = nysg, nyng
488                            DO  k = nzb, nz_do3d
489                               local_pf(i,j,k) = ql(k,j,i) + qr(k,j,i)
490                            ENDDO
491                         ENDDO
492                      ENDDO
493                      resorted = .TRUE.
494                   ELSE
495                      to_be_resorted => ql
496                   ENDIF
497                ELSE
498                   IF ( icloud_scheme == 0 )  THEN
499                      DO  i = nxlg, nxrg
500                         DO  j = nysg, nyng
501                            DO  k = nzb, nz_do3d
502                               local_pf(i,j,k) = ql_av(k,j,i) + qr_av(k,j,i)
503                            ENDDO
504                         ENDDO
505                      ENDDO
506                      resorted = .TRUE.
507                   ELSE
508                      to_be_resorted => ql_av
509                   ENDIF
510                ENDIF
511                IF ( mode == 'xy' )  level_z = zu
512
513             CASE ( 'ql_c_xy', 'ql_c_xz', 'ql_c_yz' )
514                IF ( av == 0 )  THEN
515                   to_be_resorted => ql_c
516                ELSE
517                   to_be_resorted => ql_c_av
518                ENDIF
519                IF ( mode == 'xy' )  level_z = zu
520
521             CASE ( 'ql_v_xy', 'ql_v_xz', 'ql_v_yz' )
522                IF ( av == 0 )  THEN
523                   to_be_resorted => ql_v
524                ELSE
525                   to_be_resorted => ql_v_av
526                ENDIF
527                IF ( mode == 'xy' )  level_z = zu
528
529             CASE ( 'ql_vp_xy', 'ql_vp_xz', 'ql_vp_yz' )
530                IF ( av == 0 )  THEN
531                   IF ( simulated_time >= particle_advection_start )  THEN
532                      DO  i = nxl, nxr
533                         DO  j = nys, nyn
534                            DO  k = nzb, nzt+1
535                               psi = prt_start_index(k,j,i)
536                               DO  n = psi, psi+prt_count(k,j,i)-1
537                                  tend(k,j,i) =  tend(k,j,i) + &
538                                                 particles(n)%weight_factor / &
539                                                 prt_count(k,j,i)
540                               ENDDO
541                            ENDDO
542                         ENDDO
543                      ENDDO
544                      CALL exchange_horiz( tend, nbgp )
545                   ELSE
546                      tend = 0.0
547                   END IF
548                   DO  i = nxlg, nxrg
549                      DO  j = nysg, nyng
550                         DO  k = nzb, nzt+1
551                            local_pf(i,j,k) = tend(k,j,i)
552                         ENDDO
553                      ENDDO
554                   ENDDO
555                   resorted = .TRUE.
556                ELSE
557                   CALL exchange_horiz( ql_vp_av, nbgp )
558                   to_be_resorted => ql_vp
559                ENDIF
560                IF ( mode == 'xy' )  level_z = zu
561
562             CASE ( 'qr_xy', 'qr_xz', 'qr_yz' )
563                IF ( av == 0 )  THEN
564                   to_be_resorted => qr
565                ELSE
566                   to_be_resorted => qr_av
567                ENDIF
568                IF ( mode == 'xy' )  level_z = zu
569
570             CASE ( 'qsws*_xy' )        ! 2d-array
571                IF ( av == 0 ) THEN
572                   DO  i = nxlg, nxrg
573                      DO  j = nysg, nyng
574                         local_pf(i,j,nzb+1) =  qsws(j,i)
575                      ENDDO
576                   ENDDO
577                ELSE
578                   DO  i = nxlg, nxrg
579                      DO  j = nysg, nyng 
580                         local_pf(i,j,nzb+1) =  qsws_av(j,i)
581                      ENDDO
582                   ENDDO
583                ENDIF
584                resorted = .TRUE.
585                two_d = .TRUE.
586                level_z(nzb+1) = zu(nzb+1)
587
588             CASE ( 'qv_xy', 'qv_xz', 'qv_yz' )
589                IF ( av == 0 )  THEN
590                   DO  i = nxlg, nxrg
591                      DO  j = nysg, nyng
592                         DO  k = nzb, nzt+1
593                            local_pf(i,j,k) = q(k,j,i) - ql(k,j,i)
594                         ENDDO
595                      ENDDO
596                   ENDDO
597                   resorted = .TRUE.
598                ELSE
599                   to_be_resorted => qv_av
600                ENDIF
601                IF ( mode == 'xy' )  level_z = zu
602
603             CASE ( 'rho_xy', 'rho_xz', 'rho_yz' )
604                IF ( av == 0 )  THEN
605                   to_be_resorted => rho
606                ELSE
607                   to_be_resorted => rho_av
608                ENDIF
609
610             CASE ( 's_xy', 's_xz', 's_yz' )
611                IF ( av == 0 )  THEN
612                   to_be_resorted => q
613                ELSE
614                   to_be_resorted => s_av
615                ENDIF
616
617             CASE ( 'sa_xy', 'sa_xz', 'sa_yz' )
618                IF ( av == 0 )  THEN
619                   to_be_resorted => sa
620                ELSE
621                   to_be_resorted => sa_av
622                ENDIF
623
624             CASE ( 'shf*_xy' )        ! 2d-array
625                IF ( av == 0 ) THEN
626                   DO  i = nxlg, nxrg
627                      DO  j = nysg, nyng
628                         local_pf(i,j,nzb+1) =  shf(j,i)
629                      ENDDO
630                   ENDDO
631                ELSE
632                   DO  i = nxlg, nxrg
633                      DO  j = nysg, nyng
634                         local_pf(i,j,nzb+1) =  shf_av(j,i)
635                      ENDDO
636                   ENDDO
637                ENDIF
638                resorted = .TRUE.
639                two_d = .TRUE.
640                level_z(nzb+1) = zu(nzb+1)
641
642             CASE ( 't*_xy' )        ! 2d-array
643                IF ( av == 0 )  THEN
644                   DO  i = nxlg, nxrg
645                      DO  j = nysg, nyng
646                         local_pf(i,j,nzb+1) = ts(j,i)
647                      ENDDO
648                   ENDDO
649                ELSE
650                   DO  i = nxlg, nxrg
651                      DO  j = nysg, nyng
652                         local_pf(i,j,nzb+1) = ts_av(j,i)
653                      ENDDO
654                   ENDDO
655                ENDIF
656                resorted = .TRUE.
657                two_d = .TRUE.
658                level_z(nzb+1) = zu(nzb+1)
659
660             CASE ( 'u_xy', 'u_xz', 'u_yz' )
661                IF ( av == 0 )  THEN
662                   to_be_resorted => u
663                ELSE
664                   to_be_resorted => u_av
665                ENDIF
666                IF ( mode == 'xy' )  level_z = zu
667!
668!--             Substitute the values generated by "mirror" boundary condition
669!--             at the bottom boundary by the real surface values.
670                IF ( do2d(av,if) == 'u_xz'  .OR.  do2d(av,if) == 'u_yz' )  THEN
671                   IF ( ibc_uv_b == 0 )  local_pf(:,:,nzb) = 0.0
672                ENDIF
673
674             CASE ( 'u*_xy' )        ! 2d-array
675                IF ( av == 0 )  THEN
676                   DO  i = nxlg, nxrg
677                      DO  j = nysg, nyng
678                         local_pf(i,j,nzb+1) = us(j,i)
679                      ENDDO
680                   ENDDO
681                ELSE
682                   DO  i = nxlg, nxrg
683                      DO  j = nysg, nyng
684                         local_pf(i,j,nzb+1) = us_av(j,i)
685                      ENDDO
686                   ENDDO
687                ENDIF
688                resorted = .TRUE.
689                two_d = .TRUE.
690                level_z(nzb+1) = zu(nzb+1)
691
692             CASE ( 'v_xy', 'v_xz', 'v_yz' )
693                IF ( av == 0 )  THEN
694                   to_be_resorted => v
695                ELSE
696                   to_be_resorted => v_av
697                ENDIF
698                IF ( mode == 'xy' )  level_z = zu
699!
700!--             Substitute the values generated by "mirror" boundary condition
701!--             at the bottom boundary by the real surface values.
702                IF ( do2d(av,if) == 'v_xz'  .OR.  do2d(av,if) == 'v_yz' )  THEN
703                   IF ( ibc_uv_b == 0 )  local_pf(:,:,nzb) = 0.0
704                ENDIF
705
706             CASE ( 'vpt_xy', 'vpt_xz', 'vpt_yz' )
707                IF ( av == 0 )  THEN
708                   to_be_resorted => vpt
709                ELSE
710                   to_be_resorted => vpt_av
711                ENDIF
712                IF ( mode == 'xy' )  level_z = zu
713
714             CASE ( 'w_xy', 'w_xz', 'w_yz' )
715                IF ( av == 0 )  THEN
716                   to_be_resorted => w
717                ELSE
718                   to_be_resorted => w_av
719                ENDIF
720                IF ( mode == 'xy' )  level_z = zw
721
722             CASE ( 'z0*_xy' )        ! 2d-array
723                IF ( av == 0 ) THEN
724                   DO  i = nxlg, nxrg
725                      DO  j = nysg, nyng
726                         local_pf(i,j,nzb+1) =  z0(j,i)
727                      ENDDO
728                   ENDDO
729                ELSE
730                   DO  i = nxlg, nxrg
731                      DO  j = nysg, nyng
732                         local_pf(i,j,nzb+1) =  z0_av(j,i)
733                      ENDDO
734                   ENDDO
735                ENDIF
736                resorted = .TRUE.
737                two_d = .TRUE.
738                level_z(nzb+1) = zu(nzb+1)
739
740             CASE ( 'z0h*_xy' )        ! 2d-array
741                IF ( av == 0 ) THEN
742                   DO  i = nxlg, nxrg
743                      DO  j = nysg, nyng
744                         local_pf(i,j,nzb+1) =  z0h(j,i)
745                      ENDDO
746                   ENDDO
747                ELSE
748                   DO  i = nxlg, nxrg
749                      DO  j = nysg, nyng
750                         local_pf(i,j,nzb+1) =  z0h_av(j,i)
751                      ENDDO
752                   ENDDO
753                ENDIF
754                resorted = .TRUE.
755                two_d = .TRUE.
756                level_z(nzb+1) = zu(nzb+1)
757
758             CASE DEFAULT
759!
760!--             User defined quantity
761                CALL user_data_output_2d( av, do2d(av,if), found, grid, &
762                                          local_pf, two_d )
763                resorted = .TRUE.
764
765                IF ( grid == 'zu' )  THEN
766                   IF ( mode == 'xy' )  level_z = zu
767                ELSEIF ( grid == 'zw' )  THEN
768                   IF ( mode == 'xy' )  level_z = zw
769                ELSEIF ( grid == 'zu1' ) THEN
770                   IF ( mode == 'xy' )  level_z(nzb+1) = zu(nzb+1)
771                ENDIF
772
773                IF ( .NOT. found )  THEN
774                   message_string = 'no output provided for: ' //    &
775                                    TRIM( do2d(av,if) )
776                   CALL message( 'data_output_2d', 'PA0181', 0, 0, 0, 6, 0 )
777                ENDIF
778
779          END SELECT
780
781!
782!--       Resort the array to be output, if not done above
783          IF ( .NOT. resorted )  THEN
784             DO  i = nxlg, nxrg
785                DO  j = nysg, nyng
786                   DO  k = nzb, nzt+1
787                      local_pf(i,j,k) = to_be_resorted(k,j,i)
788                   ENDDO
789                ENDDO
790             ENDDO
791          ENDIF
792
793!
794!--       Output of the individual cross-sections, depending on the cross-
795!--       section mode chosen.
796          is = 1
797   loop1: DO  WHILE ( section(is,s) /= -9999  .OR.  two_d )
798
799             SELECT CASE ( mode )
800
801                CASE ( 'xy' )
802!
803!--                Determine the cross section index
804                   IF ( two_d )  THEN
805                      layer_xy = nzb+1
806                   ELSE
807                      layer_xy = section(is,s)
808                   ENDIF
809
810!
811!--                Update the netCDF xy cross section time axis
812                   IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
813                      IF ( simulated_time /= do2d_xy_last_time(av) )  THEN
814                         do2d_xy_time_count(av) = do2d_xy_time_count(av) + 1
815                         do2d_xy_last_time(av)  = simulated_time
816                         IF ( ( .NOT. data_output_2d_on_each_pe  .AND. &
817                              netcdf_output )  .OR.  netcdf_data_format > 4 ) &
818                         THEN
819#if defined( __netcdf )
820                            nc_stat = NF90_PUT_VAR( id_set_xy(av),             &
821                                                    id_var_time_xy(av),        &
822                                             (/ time_since_reference_point /), &
823                                         start = (/ do2d_xy_time_count(av) /), &
824                                                    count = (/ 1 /) )
825                            CALL handle_netcdf_error( 'data_output_2d', 53 )
826#endif
827                         ENDIF
828                      ENDIF
829                   ENDIF
830!
831!--                If required, carry out averaging along z
832                   IF ( section(is,s) == -1  .AND.  .NOT. two_d )  THEN
833
834                      local_2d = 0.0
835!
836!--                   Carry out the averaging (all data are on the PE)
837                      DO  k = nzb, nzt+1
838                         DO  j = nysg, nyng
839                            DO  i = nxlg, nxrg
840                               local_2d(i,j) = local_2d(i,j) + local_pf(i,j,k)
841                            ENDDO
842                         ENDDO
843                      ENDDO
844
845                      local_2d = local_2d / ( nzt -nzb + 2.0)
846
847                   ELSE
848!
849!--                   Just store the respective section on the local array
850                      local_2d = local_pf(:,:,layer_xy)
851
852                   ENDIF
853
854#if defined( __parallel )
855                   IF ( netcdf_output  .AND.  netcdf_data_format > 4 )  THEN
856!
857!--                   Parallel output in netCDF4/HDF5 format.
858!--                   Do not output redundant ghost point data except for the
859!--                   boundaries of the total domain.
860                      IF ( two_d ) THEN
861                         iis = 1
862                      ELSE
863                         iis = is
864                      ENDIF
865
866#if defined( __netcdf )
867                      IF ( nxr == nx  .AND.  nyn /= ny )  THEN
868                         nc_stat = NF90_PUT_VAR( id_set_xy(av),                &
869                                                 id_var_do2d(av,if),           &
870                                                 local_2d(nxl:nxr+1,nys:nyn),  &
871                                                 start = (/ nxl+1, nys+1, iis, &
872                                                    do2d_xy_time_count(av) /), &
873                                                 count = (/ nxr-nxl+2,         &
874                                                            nyn-nys+1, 1, 1 /) )
875                      ELSEIF ( nxr /= nx  .AND.  nyn == ny )  THEN
876                         nc_stat = NF90_PUT_VAR( id_set_xy(av),                &
877                                                 id_var_do2d(av,if),           &
878                                                 local_2d(nxl:nxr,nys:nyn+1),  &
879                                                 start = (/ nxl+1, nys+1, iis, &
880                                                    do2d_xy_time_count(av) /), &
881                                                 count = (/ nxr-nxl+1,         &
882                                                            nyn-nys+2, 1, 1 /) )
883                      ELSEIF ( nxr == nx  .AND.  nyn == ny )  THEN
884                         nc_stat = NF90_PUT_VAR( id_set_xy(av),                &
885                                                 id_var_do2d(av,if),           &
886                                                 local_2d(nxl:nxr+1,nys:nyn+1),&
887                                                 start = (/ nxl+1, nys+1, iis, &
888                                                    do2d_xy_time_count(av) /), &
889                                                 count = (/ nxr-nxl+2,          &
890                                                            nyn-nys+2, 1, 1 /) )
891                      ELSE
892                         nc_stat = NF90_PUT_VAR( id_set_xy(av),                &
893                                                 id_var_do2d(av,if),           &
894                                                 local_2d(nxl:nxr,nys:nyn),    &
895                                                 start = (/ nxl+1, nys+1, iis, &
896                                                    do2d_xy_time_count(av) /), &
897                                                 count = (/ nxr-nxl+1,         &
898                                                            nyn-nys+1, 1, 1 /) )
899                      ENDIF
900
901                      CALL handle_netcdf_error( 'data_output_2d', 55 )
902#endif
903                   ELSE
904
905                      IF ( data_output_2d_on_each_pe )  THEN
906!
907!--                      Output of partial arrays on each PE
908#if defined( __netcdf )
909                         IF ( netcdf_output  .AND.  myid == 0 )  THEN
910                            WRITE ( 21 )  time_since_reference_point, &
911                                          do2d_xy_time_count(av), av
912                         ENDIF
913#endif
914                         DO  i = 0, io_blocks-1
915                            IF ( i == io_group )  THEN
916                               WRITE ( 21 )  nxlg, nxrg, nysg, nyng
917                               WRITE ( 21 )  local_2d
918                            ENDIF
919#if defined( __parallel )
920                            CALL MPI_BARRIER( comm2d, ierr )
921#endif
922                         ENDDO
923
924                      ELSE
925!
926!--                      PE0 receives partial arrays from all processors and
927!--                      then outputs them. Here a barrier has to be set,
928!--                      because otherwise "-MPI- FATAL: Remote protocol queue
929!--                      full" may occur.
930                         CALL MPI_BARRIER( comm2d, ierr )
931
932                         ngp = ( nxrg-nxlg+1 ) * ( nyng-nysg+1 )
933                         IF ( myid == 0 )  THEN
934!
935!--                         Local array can be relocated directly.
936                            total_2d(nxlg:nxrg,nysg:nyng) = local_2d
937!
938!--                         Receive data from all other PEs.
939                            DO  n = 1, numprocs-1
940!
941!--                            Receive index limits first, then array.
942!--                            Index limits are received in arbitrary order from
943!--                            the PEs.
944                               CALL MPI_RECV( ind(1), 4, MPI_INTEGER,    &
945                                              MPI_ANY_SOURCE, 0, comm2d, &
946                                              status, ierr )
947                               sender = status(MPI_SOURCE)
948                               DEALLOCATE( local_2d )
949                               ALLOCATE( local_2d(ind(1):ind(2),ind(3):ind(4)) )
950                               CALL MPI_RECV( local_2d(ind(1),ind(3)), ngp,  &
951                                              MPI_REAL, sender, 1, comm2d,   &
952                                              status, ierr )
953                               total_2d(ind(1):ind(2),ind(3):ind(4)) = local_2d
954                            ENDDO
955!
956!--                         Output of the total cross-section.
957                            IF ( iso2d_output )  THEN
958                               WRITE (21)  total_2d(-nbgp:nx+nbgp,-nbgp:ny+nbgp)
959                            ENDIF
960!
961!--                         Relocate the local array for the next loop increment
962                            DEALLOCATE( local_2d )
963                            ALLOCATE( local_2d(nxlg:nxrg,nysg:nyng) )
964
965#if defined( __netcdf )
966                            IF ( netcdf_output )  THEN
967                               IF ( two_d ) THEN
968                                  nc_stat = NF90_PUT_VAR( id_set_xy(av),       &
969                                                          id_var_do2d(av,if),  &
970                                                      total_2d(0:nx+1,0:ny+1), &
971                                start = (/ 1, 1, 1, do2d_xy_time_count(av) /), &
972                                                count = (/ nx+2, ny+2, 1, 1 /) )
973                               ELSE
974                                  nc_stat = NF90_PUT_VAR( id_set_xy(av),       &
975                                                          id_var_do2d(av,if),  &
976                                                      total_2d(0:nx+1,0:ny+1), &
977                               start = (/ 1, 1, is, do2d_xy_time_count(av) /), &
978                                                count = (/ nx+2, ny+2, 1, 1 /) )
979                               ENDIF
980                               CALL handle_netcdf_error( 'data_output_2d', 54 )
981                            ENDIF
982#endif
983
984                         ELSE
985!
986!--                         First send the local index limits to PE0
987                            ind(1) = nxlg; ind(2) = nxrg
988                            ind(3) = nysg; ind(4) = nyng
989                            CALL MPI_SEND( ind(1), 4, MPI_INTEGER, 0, 0, &
990                                           comm2d, ierr )
991!
992!--                         Send data to PE0
993                            CALL MPI_SEND( local_2d(nxlg,nysg), ngp, &
994                                           MPI_REAL, 0, 1, comm2d, ierr )
995                         ENDIF
996!
997!--                      A barrier has to be set, because otherwise some PEs may
998!--                      proceed too fast so that PE0 may receive wrong data on
999!--                      tag 0
1000                         CALL MPI_BARRIER( comm2d, ierr )
1001                      ENDIF
1002
1003                   ENDIF
1004#else
1005                   IF ( iso2d_output )  THEN
1006                      WRITE (21)  local_2d(nxl:nxr+1,nys:nyn+1)
1007                   ENDIF
1008#if defined( __netcdf )
1009                   IF ( netcdf_output )  THEN
1010                      IF ( two_d ) THEN
1011                         nc_stat = NF90_PUT_VAR( id_set_xy(av),                &
1012                                                 id_var_do2d(av,if),           &
1013                                                local_2d(nxl:nxr+1,nys:nyn+1), &
1014                                start = (/ 1, 1, 1, do2d_xy_time_count(av) /), &
1015                                              count = (/ nx+2, ny+2, 1, 1 /) )
1016                      ELSE
1017                         nc_stat = NF90_PUT_VAR( id_set_xy(av),                &
1018                                                 id_var_do2d(av,if),           &
1019                                                local_2d(nxl:nxr+1,nys:nyn+1), &
1020                               start = (/ 1, 1, is, do2d_xy_time_count(av) /), &
1021                                              count = (/ nx+2, ny+2, 1, 1 /) )
1022                      ENDIF
1023                      CALL handle_netcdf_error( 'data_output_2d', 447 )
1024                   ENDIF
1025#endif
1026#endif
1027                   do2d_xy_n = do2d_xy_n + 1
1028!
1029!--                Write LOCAL parameter set for ISO2D.
1030                   IF ( myid == 0  .AND.  iso2d_output )  THEN
1031                      IF ( section(is,s) /= -1 )  THEN
1032                         WRITE ( section_chr, '(''z = '',F7.2,'' m  (GP '',I3, &
1033                                               &'')'')'                        &
1034                               )  level_z(layer_xy), layer_xy
1035                      ELSE
1036                         section_chr = 'averaged along z'
1037                      ENDIF
1038                      IF ( av == 0 )  THEN
1039                         rtext = TRIM( do2d(av,if) ) // '  t = ' //    &
1040                                 TRIM( simulated_time_chr ) // '  ' // &
1041                                 TRIM( section_chr )
1042                      ELSE
1043                         rtext = TRIM( do2d(av,if) ) // '  averaged t = ' // &
1044                                 TRIM( simulated_time_chr ) // '  ' //       &
1045                                 TRIM( section_chr )
1046                      ENDIF
1047                      WRITE (27,LOCAL)
1048                   ENDIF
1049!
1050!--                For 2D-arrays (e.g. u*) only one cross-section is available.
1051!--                Hence exit loop of output levels.
1052                   IF ( two_d )  THEN
1053                      two_d = .FALSE.
1054                      EXIT loop1
1055                   ENDIF
1056
1057                CASE ( 'xz' )
1058!
1059!--                Update the netCDF xz cross section time axis
1060                   IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
1061
1062                      IF ( simulated_time /= do2d_xz_last_time(av) )  THEN
1063                         do2d_xz_time_count(av) = do2d_xz_time_count(av) + 1
1064                         do2d_xz_last_time(av)  = simulated_time
1065                         IF ( ( .NOT. data_output_2d_on_each_pe  .AND.        &
1066                              netcdf_output )  .OR.  netcdf_data_format > 4 ) &
1067                         THEN
1068#if defined( __netcdf )
1069                            nc_stat = NF90_PUT_VAR( id_set_xz(av),             &
1070                                                    id_var_time_xz(av),        &
1071                                             (/ time_since_reference_point /), &
1072                                         start = (/ do2d_xz_time_count(av) /), &
1073                                                    count = (/ 1 /) )
1074                            CALL handle_netcdf_error( 'data_output_2d', 56 )
1075#endif
1076                         ENDIF
1077                      ENDIF
1078
1079                   ENDIF
1080
1081!
1082!--                If required, carry out averaging along y
1083                   IF ( section(is,s) == -1 )  THEN
1084
1085                      ALLOCATE( local_2d_l(nxlg:nxrg,nzb:nzt+1) )
1086                      local_2d_l = 0.0
1087                      ngp = ( nxrg-nxlg+1 ) * ( nzt-nzb+2 )
1088!
1089!--                   First local averaging on the PE
1090                      DO  k = nzb, nzt+1
1091                         DO  j = nys, nyn
1092                            DO  i = nxlg, nxrg
1093                               local_2d_l(i,k) = local_2d_l(i,k) + &
1094                                                 local_pf(i,j,k)
1095                            ENDDO
1096                         ENDDO
1097                      ENDDO
1098#if defined( __parallel )
1099!
1100!--                   Now do the averaging over all PEs along y
1101                      IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
1102                      CALL MPI_ALLREDUCE( local_2d_l(nxlg,nzb),              &
1103                                          local_2d(nxlg,nzb), ngp, MPI_REAL, &
1104                                          MPI_SUM, comm1dy, ierr )
1105#else
1106                      local_2d = local_2d_l
1107#endif
1108                      local_2d = local_2d / ( ny + 1.0 )
1109
1110                      DEALLOCATE( local_2d_l )
1111
1112                   ELSE
1113!
1114!--                   Just store the respective section on the local array
1115!--                   (but only if it is available on this PE!)
1116                      IF ( section(is,s) >= nys  .AND.  section(is,s) <= nyn ) &
1117                      THEN
1118                         local_2d = local_pf(:,section(is,s),nzb:nzt+1)
1119                      ENDIF
1120
1121                   ENDIF
1122
1123#if defined( __parallel )
1124                   IF ( netcdf_output  .AND.  netcdf_data_format > 4 )  THEN
1125!
1126!--                   ATTENTION: The following lines are a workaround, because
1127!--                              independet output does not work with the
1128!--                              current netCDF4 installation. Therefore, data
1129!--                              are transferred from PEs having the cross
1130!--                              sections to other PEs along y having no cross
1131!--                              section data. Some of these data are the
1132!--                              output.
1133!--                   BEGIN WORKAROUND---------------------------------------
1134                      IF ( npey /= 1  .AND.  section(is,s) /= -1)  THEN
1135                         ALLOCATE( local_2d_l(nxlg:nxrg,nzb:nzt+1) )
1136                         local_2d_l = 0.0
1137                         IF ( section(is,s) >= nys .AND. section(is,s) <= nyn )&
1138                         THEN
1139                            local_2d_l = local_2d
1140                         ENDIF
1141#if defined( __parallel )
1142!
1143!--                      Distribute data over all PEs along y
1144                         ngp = ( nxrg-nxlg+1 ) * ( nzt-nzb+2 )
1145                         IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr )
1146                         CALL MPI_ALLREDUCE( local_2d_l(nxlg,nzb),            &
1147                                             local_2d(nxlg,nzb), ngp,         &
1148                                             MPI_REAL, MPI_SUM, comm1dy, ierr )
1149#else
1150                         local_2d = local_2d_l
1151#endif
1152                         DEALLOCATE( local_2d_l )
1153                      ENDIF
1154!--                   END WORKAROUND-----------------------------------------
1155
1156!
1157!--                   Output in netCDF4/HDF5 format.
1158!--                   Output only on those PEs where the respective cross
1159!--                   sections reside. Cross sections averaged along y are
1160!--                   output on the respective first PE along y (myidy=0).
1161                      IF ( ( section(is,s) >= nys  .AND.  &
1162                             section(is,s) <= nyn )  .OR.  &
1163                           ( section(is,s) == -1  .AND.  myidy == 0 ) )  THEN
1164!
1165!--                      Do not output redundant ghost point data except for the
1166!--                      boundaries of the total domain.
1167#if defined( __netcdf )
1168                         IF ( nxr == nx )  THEN
1169                            nc_stat = NF90_PUT_VAR( id_set_xz(av),             &
1170                                                id_var_do2d(av,if),            &
1171                                                local_2d(nxl:nxr+1,nzb:nzt+1), &
1172                                                start = (/ nxl+1, is, 1,       &
1173                                                    do2d_xz_time_count(av) /), &
1174                                                count = (/ nxr-nxl+2, 1,       &
1175                                                           nzt+2, 1 /) )
1176                         ELSE
1177                            nc_stat = NF90_PUT_VAR( id_set_xz(av),             &
1178                                                id_var_do2d(av,if),            &
1179                                                local_2d(nxl:nxr,nzb:nzt+1),   &
1180                                                start = (/ nxl+1, is, 1,       &
1181                                                    do2d_xz_time_count(av) /), &
1182                                                count = (/ nxr-nxl+1, 1,       &
1183                                                           nzt+2, 1 /) )
1184                         ENDIF
1185
1186                         CALL handle_netcdf_error( 'data_output_2d', 57 )
1187
1188                      ELSE
1189!
1190!--                      Output on other PEs. Only one point is output!!
1191!--                      ATTENTION: This is a workaround (see above)!!
1192                         IF ( npey /= 1 )  THEN
1193                            nc_stat = NF90_PUT_VAR( id_set_xz(av),             &
1194                                                    id_var_do2d(av,if),        &
1195                                                    local_2d(nxl:nxl,nzb:nzb), &
1196                                                    start = (/ nxl+1, is, 1,   &
1197                                                    do2d_xz_time_count(av) /), &
1198                                                    count = (/ 1, 1, 1, 1 /) )
1199                            CALL handle_netcdf_error( 'data_output_2d', 451 )
1200                         ENDIF
1201#endif
1202                      ENDIF
1203
1204                   ELSE
1205
1206                      IF ( data_output_2d_on_each_pe )  THEN
1207!
1208!--                      Output of partial arrays on each PE. If the cross
1209!--                      section does not reside on the PE, output special
1210!--                      index values.
1211#if defined( __netcdf )
1212                         IF ( netcdf_output  .AND.  myid == 0 )  THEN
1213                            WRITE ( 22 )  time_since_reference_point, &
1214                                          do2d_xz_time_count(av), av
1215                         ENDIF
1216#endif
1217                         DO  i = 0, io_blocks-1
1218                            IF ( i == io_group )  THEN
1219                               IF ( ( section(is,s) >= nys  .AND.   &
1220                                      section(is,s) <= nyn )  .OR.  &
1221                                    ( section(is,s) == -1  .AND.    &
1222                                      nys-1 == -1 ) )               &
1223                               THEN
1224                                  WRITE (22)  nxlg, nxrg, nzb, nzt+1
1225                                  WRITE (22)  local_2d
1226                               ELSE
1227                                  WRITE (22)  -1, -1, -1, -1
1228                               ENDIF
1229                            ENDIF
1230#if defined( __parallel )
1231                            CALL MPI_BARRIER( comm2d, ierr )
1232#endif
1233                         ENDDO
1234
1235                      ELSE
1236!
1237!--                      PE0 receives partial arrays from all processors of the
1238!--                      respective cross section and outputs them. Here a
1239!--                      barrier has to be set, because otherwise
1240!--                      "-MPI- FATAL: Remote protocol queue full" may occur.
1241                         CALL MPI_BARRIER( comm2d, ierr )
1242
1243                         ngp = ( nxrg-nxlg+1 ) * ( nzt-nzb+2 )
1244                         IF ( myid == 0 )  THEN
1245!
1246!--                         Local array can be relocated directly.
1247                            IF ( ( section(is,s) >= nys  .AND.                 &
1248                                   section(is,s) <= nyn )  .OR.                &
1249                                 ( section(is,s) == -1  .AND.  nys-1 == -1 ) ) &
1250                            THEN
1251                               total_2d(nxlg:nxrg,nzb:nzt+1) = local_2d
1252                            ENDIF
1253!
1254!--                         Receive data from all other PEs.
1255                            DO  n = 1, numprocs-1
1256!
1257!--                            Receive index limits first, then array.
1258!--                            Index limits are received in arbitrary order from
1259!--                            the PEs.
1260                               CALL MPI_RECV( ind(1), 4, MPI_INTEGER,     &
1261                                              MPI_ANY_SOURCE, 0, comm2d,  &
1262                                              status, ierr )
1263!
1264!--                            Not all PEs have data for XZ-cross-section.
1265                               IF ( ind(1) /= -9999 )  THEN
1266                                  sender = status(MPI_SOURCE)
1267                                  DEALLOCATE( local_2d )
1268                                  ALLOCATE( local_2d(ind(1):ind(2), &
1269                                                     ind(3):ind(4)) )
1270                                  CALL MPI_RECV( local_2d(ind(1),ind(3)), ngp, &
1271                                                 MPI_REAL, sender, 1, comm2d,  &
1272                                                 status, ierr )
1273                                  total_2d(ind(1):ind(2),ind(3):ind(4)) = &
1274                                                                        local_2d
1275                               ENDIF
1276                            ENDDO
1277!
1278!--                         Output of the total cross-section.
1279                            IF ( iso2d_output )  THEN
1280                               WRITE (22)  total_2d(-nbgp:nx+nbgp,nzb:nzt+1)
1281                            ENDIF
1282!
1283!--                         Relocate the local array for the next loop increment
1284                            DEALLOCATE( local_2d )
1285                            ALLOCATE( local_2d(nxlg:nxrg,nzb:nzt+1) )
1286
1287#if defined( __netcdf )
1288                            IF ( netcdf_output )  THEN
1289                               nc_stat = NF90_PUT_VAR( id_set_xz(av),          &
1290                                                    id_var_do2d(av,if),        &
1291                                                    total_2d(0:nx+1,nzb:nzt+1),&
1292                               start = (/ 1, is, 1, do2d_xz_time_count(av) /), &
1293                                                count = (/ nx+2, 1, nz+2, 1 /) )
1294                               CALL handle_netcdf_error( 'data_output_2d', 58 )
1295                            ENDIF
1296#endif
1297
1298                         ELSE
1299!
1300!--                         If the cross section resides on the PE, send the
1301!--                         local index limits, otherwise send -9999 to PE0.
1302                            IF ( ( section(is,s) >= nys  .AND.                 &
1303                                   section(is,s) <= nyn )  .OR.                &
1304                                 ( section(is,s) == -1  .AND.  nys-1 == -1 ) ) &
1305                            THEN
1306                               ind(1) = nxlg; ind(2) = nxrg
1307                               ind(3) = nzb;   ind(4) = nzt+1
1308                            ELSE
1309                               ind(1) = -9999; ind(2) = -9999
1310                               ind(3) = -9999; ind(4) = -9999
1311                            ENDIF
1312                            CALL MPI_SEND( ind(1), 4, MPI_INTEGER, 0, 0, &
1313                                           comm2d, ierr )
1314!
1315!--                         If applicable, send data to PE0.
1316                            IF ( ind(1) /= -9999 )  THEN
1317                               CALL MPI_SEND( local_2d(nxlg,nzb), ngp, &
1318                                              MPI_REAL, 0, 1, comm2d, ierr )
1319                            ENDIF
1320                         ENDIF
1321!
1322!--                      A barrier has to be set, because otherwise some PEs may
1323!--                      proceed too fast so that PE0 may receive wrong data on
1324!--                      tag 0
1325                         CALL MPI_BARRIER( comm2d, ierr )
1326                      ENDIF
1327
1328                   ENDIF
1329#else
1330                   IF ( iso2d_output )  THEN
1331                      WRITE (22)  local_2d(nxl:nxr+1,nzb:nzt+1)
1332                   ENDIF
1333#if defined( __netcdf )
1334                   IF ( netcdf_output )  THEN
1335                      nc_stat = NF90_PUT_VAR( id_set_xz(av),                   &
1336                                              id_var_do2d(av,if),              &
1337                                              local_2d(nxl:nxr+1,nzb:nzt+1),   &
1338                               start = (/ 1, is, 1, do2d_xz_time_count(av) /), &
1339                                              count = (/ nx+2, 1, nz+2, 1 /) )
1340                      CALL handle_netcdf_error( 'data_output_2d', 451 )
1341                   ENDIF
1342#endif
1343#endif
1344                   do2d_xz_n = do2d_xz_n + 1
1345!
1346!--                Write LOCAL-parameter set for ISO2D.
1347                   IF ( myid == 0  .AND.  iso2d_output )  THEN
1348                      IF ( section(is,s) /= -1 )  THEN
1349                         WRITE ( section_chr, '(''y = '',F8.2,'' m  (GP '',I3, &
1350                                               &'')'')'                        &
1351                               )  section(is,s)*dy, section(is,s)
1352                      ELSE
1353                         section_chr = 'averaged along y'
1354                      ENDIF
1355                      IF ( av == 0 )  THEN
1356                         rtext = TRIM( do2d(av,if) ) // '  t = ' //    &
1357                                 TRIM( simulated_time_chr ) // '  ' // &
1358                                 TRIM( section_chr )
1359                      ELSE
1360                         rtext = TRIM( do2d(av,if) ) // '  averaged t = ' // &
1361                                 TRIM( simulated_time_chr ) // '  ' //       &
1362                                 TRIM( section_chr )
1363                      ENDIF
1364                      WRITE (28,LOCAL)
1365                   ENDIF
1366
1367                CASE ( 'yz' )
1368!
1369!--                Update the netCDF yz cross section time axis
1370                   IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
1371
1372                      IF ( simulated_time /= do2d_yz_last_time(av) )  THEN
1373                         do2d_yz_time_count(av) = do2d_yz_time_count(av) + 1
1374                         do2d_yz_last_time(av)  = simulated_time
1375                         IF ( ( .NOT. data_output_2d_on_each_pe  .AND.        &
1376                              netcdf_output )  .OR.  netcdf_data_format > 4 ) &
1377                         THEN
1378#if defined( __netcdf )
1379                            nc_stat = NF90_PUT_VAR( id_set_yz(av),             &
1380                                                    id_var_time_yz(av),        &
1381                                             (/ time_since_reference_point /), &
1382                                         start = (/ do2d_yz_time_count(av) /), &
1383                                                    count = (/ 1 /) )
1384                            CALL handle_netcdf_error( 'data_output_2d', 59 )
1385#endif
1386                         ENDIF
1387                      ENDIF
1388
1389                   ENDIF
1390!
1391!--                If required, carry out averaging along x
1392                   IF ( section(is,s) == -1 )  THEN
1393
1394                      ALLOCATE( local_2d_l(nysg:nyng,nzb:nzt+1) )
1395                      local_2d_l = 0.0
1396                      ngp = ( nyng-nysg+1 ) * ( nzt-nzb+2 )
1397!
1398!--                   First local averaging on the PE
1399                      DO  k = nzb, nzt+1
1400                         DO  j = nysg, nyng
1401                            DO  i = nxl, nxr
1402                               local_2d_l(j,k) = local_2d_l(j,k) + &
1403                                                 local_pf(i,j,k)
1404                            ENDDO
1405                         ENDDO
1406                      ENDDO
1407#if defined( __parallel )
1408!
1409!--                   Now do the averaging over all PEs along x
1410                      IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
1411                      CALL MPI_ALLREDUCE( local_2d_l(nysg,nzb),              &
1412                                          local_2d(nysg,nzb), ngp, MPI_REAL, &
1413                                          MPI_SUM, comm1dx, ierr )
1414#else
1415                      local_2d = local_2d_l
1416#endif
1417                      local_2d = local_2d / ( nx + 1.0 )
1418
1419                      DEALLOCATE( local_2d_l )
1420
1421                   ELSE
1422!
1423!--                   Just store the respective section on the local array
1424!--                   (but only if it is available on this PE!)
1425                      IF ( section(is,s) >= nxl  .AND.  section(is,s) <= nxr ) &
1426                      THEN
1427                         local_2d = local_pf(section(is,s),:,nzb:nzt+1)
1428                      ENDIF
1429
1430                   ENDIF
1431
1432#if defined( __parallel )
1433                   IF ( netcdf_output  .AND.  netcdf_data_format > 4 )  THEN
1434!
1435!--                   ATTENTION: The following lines are a workaround, because
1436!--                              independet output does not work with the
1437!--                              current netCDF4 installation. Therefore, data
1438!--                              are transferred from PEs having the cross
1439!--                              sections to other PEs along y having no cross
1440!--                              section data. Some of these data are the
1441!--                              output.
1442!--                   BEGIN WORKAROUND---------------------------------------
1443                      IF ( npex /= 1  .AND.  section(is,s) /= -1)  THEN
1444                         ALLOCATE( local_2d_l(nysg:nyng,nzb:nzt+1) )
1445                         local_2d_l = 0.0
1446                         IF ( section(is,s) >= nxl .AND. section(is,s) <= nxr )&
1447                         THEN
1448                            local_2d_l = local_2d
1449                         ENDIF
1450#if defined( __parallel )
1451!
1452!--                      Distribute data over all PEs along x
1453                         ngp = ( nyng-nysg+1 ) * ( nzt-nzb + 2 )
1454                         IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr )
1455                         CALL MPI_ALLREDUCE( local_2d_l(nysg,nzb),            &
1456                                             local_2d(nysg,nzb), ngp,         &
1457                                             MPI_REAL, MPI_SUM, comm1dx, ierr )
1458#else
1459                         local_2d = local_2d_l
1460#endif
1461                         DEALLOCATE( local_2d_l )
1462                      ENDIF
1463!--                   END WORKAROUND-----------------------------------------
1464
1465!
1466!--                   Output in netCDF4/HDF5 format.
1467!--                   Output only on those PEs where the respective cross
1468!--                   sections reside. Cross sections averaged along x are
1469!--                   output on the respective first PE along x (myidx=0).
1470                      IF ( ( section(is,s) >= nxl  .AND.  &
1471                             section(is,s) <= nxr )  .OR.  &
1472                           ( section(is,s) == -1  .AND.  myidx == 0 ) )  THEN
1473!
1474!--                      Do not output redundant ghost point data except for the
1475!--                      boundaries of the total domain.
1476#if defined( __netcdf )
1477                         IF ( nyn == ny )  THEN
1478                            nc_stat = NF90_PUT_VAR( id_set_yz(av),             &
1479                                                id_var_do2d(av,if),            &
1480                                                local_2d(nys:nyn+1,nzb:nzt+1), &
1481                                                start = (/ is, nys+1, 1,       &
1482                                                    do2d_yz_time_count(av) /), &
1483                                                count = (/ 1, nyn-nys+2,       &
1484                                                           nzt+2, 1 /) )
1485                         ELSE
1486                            nc_stat = NF90_PUT_VAR( id_set_yz(av),             &
1487                                                id_var_do2d(av,if),            &
1488                                                local_2d(nys:nyn,nzb:nzt+1),   &
1489                                                start = (/ is, nys+1, 1,       &
1490                                                    do2d_yz_time_count(av) /), &
1491                                                count = (/ 1, nyn-nys+1,       &
1492                                                           nzt+2, 1 /) )
1493                         ENDIF
1494
1495                         CALL handle_netcdf_error( 'data_output_2d', 60 )
1496
1497                      ELSE
1498!
1499!--                      Output on other PEs. Only one point is output!!
1500!--                      ATTENTION: This is a workaround (see above)!!
1501                         IF ( npex /= 1 )  THEN
1502                            nc_stat = NF90_PUT_VAR( id_set_yz(av),             &
1503                                                    id_var_do2d(av,if),        &
1504                                                    local_2d(nys:nys,nzb:nzb), &
1505                                                    start = (/ is, nys+1, 1,   &
1506                                                    do2d_yz_time_count(av) /), &
1507                                                    count = (/ 1, 1, 1, 1 /) )
1508                            CALL handle_netcdf_error( 'data_output_2d', 452 )
1509                         ENDIF
1510#endif
1511                      ENDIF
1512
1513                   ELSE
1514
1515                      IF ( data_output_2d_on_each_pe )  THEN
1516!
1517!--                      Output of partial arrays on each PE. If the cross
1518!--                      section does not reside on the PE, output special
1519!--                      index values.
1520#if defined( __netcdf )
1521                         IF ( netcdf_output  .AND.  myid == 0 )  THEN
1522                            WRITE ( 23 )  time_since_reference_point, &
1523                                          do2d_yz_time_count(av), av
1524                         ENDIF
1525#endif
1526                         DO  i = 0, io_blocks-1
1527                            IF ( i == io_group )  THEN
1528                               IF ( ( section(is,s) >= nxl  .AND.   &
1529                                      section(is,s) <= nxr )  .OR.  &
1530                                    ( section(is,s) == -1  .AND.    &
1531                                      nxl-1 == -1 ) )               &
1532                               THEN
1533                                  WRITE (23)  nysg, nyng, nzb, nzt+1
1534                                  WRITE (23)  local_2d
1535                               ELSE
1536                                  WRITE (23)  -1, -1, -1, -1
1537                               ENDIF
1538                            ENDIF
1539#if defined( __parallel )
1540                            CALL MPI_BARRIER( comm2d, ierr )
1541#endif
1542                         ENDDO
1543
1544                      ELSE
1545!
1546!--                      PE0 receives partial arrays from all processors of the
1547!--                      respective cross section and outputs them. Here a
1548!--                      barrier has to be set, because otherwise
1549!--                      "-MPI- FATAL: Remote protocol queue full" may occur.
1550                         CALL MPI_BARRIER( comm2d, ierr )
1551
1552                         ngp = ( nyng-nysg+1 ) * ( nzt-nzb+2 )
1553                         IF ( myid == 0 )  THEN
1554!
1555!--                         Local array can be relocated directly.
1556                            IF ( ( section(is,s) >= nxl  .AND.                 &
1557                                   section(is,s) <= nxr )   .OR.               &
1558                                 ( section(is,s) == -1  .AND.  nxl-1 == -1 ) ) &
1559                            THEN
1560                               total_2d(nysg:nyng,nzb:nzt+1) = local_2d
1561                            ENDIF
1562!
1563!--                         Receive data from all other PEs.
1564                            DO  n = 1, numprocs-1
1565!
1566!--                            Receive index limits first, then array.
1567!--                            Index limits are received in arbitrary order from
1568!--                            the PEs.
1569                               CALL MPI_RECV( ind(1), 4, MPI_INTEGER,     &
1570                                              MPI_ANY_SOURCE, 0, comm2d,  &
1571                                              status, ierr )
1572!
1573!--                            Not all PEs have data for YZ-cross-section.
1574                               IF ( ind(1) /= -9999 )  THEN
1575                                  sender = status(MPI_SOURCE)
1576                                  DEALLOCATE( local_2d )
1577                                  ALLOCATE( local_2d(ind(1):ind(2), &
1578                                                     ind(3):ind(4)) )
1579                                  CALL MPI_RECV( local_2d(ind(1),ind(3)), ngp, &
1580                                                 MPI_REAL, sender, 1, comm2d,  &
1581                                                 status, ierr )
1582                                  total_2d(ind(1):ind(2),ind(3):ind(4)) = &
1583                                                                        local_2d
1584                               ENDIF
1585                            ENDDO
1586!
1587!--                         Output of the total cross-section.
1588                            IF ( iso2d_output )  THEN
1589                               WRITE (23)  total_2d(0:ny+1,nzb:nzt+1)
1590                            ENDIF
1591!
1592!--                         Relocate the local array for the next loop increment
1593                            DEALLOCATE( local_2d )
1594                            ALLOCATE( local_2d(nysg:nyng,nzb:nzt+1) )
1595
1596#if defined( __netcdf )
1597                            IF ( netcdf_output )  THEN
1598                               nc_stat = NF90_PUT_VAR( id_set_yz(av),          &
1599                                                    id_var_do2d(av,if),        &
1600                                                    total_2d(0:ny+1,nzb:nzt+1),&
1601                               start = (/ is, 1, 1, do2d_yz_time_count(av) /), &
1602                                                count = (/ 1, ny+2, nz+2, 1 /) )
1603                               CALL handle_netcdf_error( 'data_output_2d', 61 )
1604                            ENDIF
1605#endif
1606
1607                         ELSE
1608!
1609!--                         If the cross section resides on the PE, send the
1610!--                         local index limits, otherwise send -9999 to PE0.
1611                            IF ( ( section(is,s) >= nxl  .AND.                 &
1612                                   section(is,s) <= nxr )  .OR.                &
1613                                 ( section(is,s) == -1  .AND.  nxl-1 == -1 ) ) &
1614                            THEN
1615                               ind(1) = nysg; ind(2) = nyng
1616                               ind(3) = nzb;   ind(4) = nzt+1
1617                            ELSE
1618                               ind(1) = -9999; ind(2) = -9999
1619                               ind(3) = -9999; ind(4) = -9999
1620                            ENDIF
1621                            CALL MPI_SEND( ind(1), 4, MPI_INTEGER, 0, 0, &
1622                                           comm2d, ierr )
1623!
1624!--                         If applicable, send data to PE0.
1625                            IF ( ind(1) /= -9999 )  THEN
1626                               CALL MPI_SEND( local_2d(nysg,nzb), ngp, &
1627                                              MPI_REAL, 0, 1, comm2d, ierr )
1628                            ENDIF
1629                         ENDIF
1630!
1631!--                      A barrier has to be set, because otherwise some PEs may
1632!--                      proceed too fast so that PE0 may receive wrong data on
1633!--                      tag 0
1634                         CALL MPI_BARRIER( comm2d, ierr )
1635                      ENDIF
1636
1637                   ENDIF
1638#else
1639                   IF ( iso2d_output )  THEN
1640                      WRITE (23)  local_2d(nys:nyn+1,nzb:nzt+1)
1641                   ENDIF
1642#if defined( __netcdf )
1643                   IF ( netcdf_output )  THEN
1644                      nc_stat = NF90_PUT_VAR( id_set_yz(av),                   &
1645                                              id_var_do2d(av,if),              &
1646                                              local_2d(nys:nyn+1,nzb:nzt+1),   &
1647                               start = (/ is, 1, 1, do2d_xz_time_count(av) /), &
1648                                              count = (/ 1, ny+2, nz+2, 1 /) )
1649                      CALL handle_netcdf_error( 'data_output_2d', 452 )
1650                   ENDIF
1651#endif
1652#endif
1653                   do2d_yz_n = do2d_yz_n + 1
1654!
1655!--                Write LOCAL-parameter set for ISO2D.
1656                   IF ( myid == 0  .AND.  iso2d_output )  THEN
1657                      IF ( section(is,s) /= -1 )  THEN
1658                         WRITE ( section_chr, '(''x = '',F8.2,'' m  (GP '',I3, &
1659                                               &'')'')'                        &
1660                               )  section(is,s)*dx, section(is,s)
1661                      ELSE
1662                         section_chr = 'averaged along x'
1663                      ENDIF
1664                      IF ( av == 0 )  THEN
1665                         rtext = TRIM( do2d(av,if) ) // '  t = ' //    &
1666                                 TRIM( simulated_time_chr ) // '  ' // &
1667                                 TRIM( section_chr )
1668                      ELSE
1669                         rtext = TRIM( do2d(av,if) ) // '  averaged t = ' // &
1670                                 TRIM( simulated_time_chr ) // '  ' //       &
1671                                 TRIM( section_chr )
1672                      ENDIF
1673                      WRITE (29,LOCAL)
1674                   ENDIF
1675
1676             END SELECT
1677
1678             is = is + 1
1679          ENDDO loop1
1680
1681       ENDIF
1682
1683       if = if + 1
1684       l = MAX( 2, LEN_TRIM( do2d(av,if) ) )
1685       do2d_mode = do2d(av,if)(l-1:l)
1686
1687    ENDDO
1688
1689!
1690!-- Deallocate temporary arrays.
1691    IF ( ALLOCATED( level_z ) )  DEALLOCATE( level_z )
1692    DEALLOCATE( local_pf, local_2d )
1693#if defined( __parallel )
1694    IF ( .NOT.  data_output_2d_on_each_pe  .AND.  myid == 0 )  THEN
1695       DEALLOCATE( total_2d )
1696    ENDIF
1697#endif
1698
1699!
1700!-- Close plot output file.
1701    file_id = 20 + s
1702
1703    IF ( data_output_2d_on_each_pe )  THEN
1704       DO  i = 0, io_blocks-1
1705          IF ( i == io_group )  THEN
1706             CALL close_file( file_id )
1707          ENDIF
1708#if defined( __parallel )
1709          CALL MPI_BARRIER( comm2d, ierr )
1710#endif
1711       ENDDO
1712    ELSE
1713       IF ( myid == 0 )  CALL close_file( file_id )
1714    ENDIF
1715
1716
1717    CALL cpu_log (log_point(3),'data_output_2d','stop','nobarrier')
1718
1719 END SUBROUTINE data_output_2d
Note: See TracBrowser for help on using the repository browser.