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

Last change on this file since 4180 was 4180, checked in by scharf, 5 years ago

removed comments in 'Former revisions' section that are older than 01.01.2019

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