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

Last change on this file since 4484 was 4457, checked in by raasch, 4 years ago

ghost point exchange modularized, bugfix for wrong 2d-exchange

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