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

Last change on this file since 1977 was 1977, checked in by maronga, 8 years ago

last commit documented

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