Index: /palm/trunk/SOURCE/flow_statistics.f90
===================================================================
--- /palm/trunk/SOURCE/flow_statistics.f90	(revision 4702)
+++ /palm/trunk/SOURCE/flow_statistics.f90	(revision 4703)
@@ -24,4 +24,7 @@
 ! -----------------
 ! $Id$
+! Revise averaging of land-surface quantities
+!
+! 4672 2020-09-09 21:27:32Z pavelkrc
 ! OpenACC bugfix
 !
@@ -1414,12 +1417,10 @@
              j = surf_lsm_h(0)%j(m)
 
-             IF ( i >= nxl  .AND.  i <= nxr  .AND.  j >= nys  .AND.  j <= nyn )  THEN
-                sums_l(nzb,93,tn)  = sums_l(nzb,93,tn) + surf_lsm_h(0)%ghf(m)       * rmask(j,i,sr)
-                sums_l(nzb,94,tn)  = sums_l(nzb,94,tn) + surf_lsm_h(0)%qsws_liq(m)  * rmask(j,i,sr)
-                sums_l(nzb,95,tn)  = sums_l(nzb,95,tn) + surf_lsm_h(0)%qsws_soil(m) * rmask(j,i,sr)
-                sums_l(nzb,96,tn)  = sums_l(nzb,96,tn) + surf_lsm_h(0)%qsws_veg(m)  * rmask(j,i,sr)
-                sums_l(nzb,97,tn)  = sums_l(nzb,97,tn) + surf_lsm_h(0)%r_a(m)       * rmask(j,i,sr)
-                sums_l(nzb,98,tn)  = sums_l(nzb,98,tn) + surf_lsm_h(0)%r_s(m)       * rmask(j,i,sr)
-             ENDIF
+             sums_l(nzb,93,tn)  = sums_l(nzb,93,tn) + surf_lsm_h(0)%ghf(m)       * rmask(j,i,sr)
+             sums_l(nzb,94,tn)  = sums_l(nzb,94,tn) + surf_lsm_h(0)%qsws_liq(m)  * rmask(j,i,sr)
+             sums_l(nzb,95,tn)  = sums_l(nzb,95,tn) + surf_lsm_h(0)%qsws_soil(m) * rmask(j,i,sr)
+             sums_l(nzb,96,tn)  = sums_l(nzb,96,tn) + surf_lsm_h(0)%qsws_veg(m)  * rmask(j,i,sr)
+             sums_l(nzb,97,tn)  = sums_l(nzb,97,tn) + surf_lsm_h(0)%r_a(m)       * rmask(j,i,sr)
+             sums_l(nzb,98,tn)  = sums_l(nzb,98,tn) + surf_lsm_h(0)%r_s(m)       * rmask(j,i,sr)
           ENDDO
           !$OMP END PARALLEL
@@ -1433,12 +1434,8 @@
              i = surf_lsm_h(0)%i(m)
              j = surf_lsm_h(0)%j(m)
-
-             IF ( i >= nxl  .AND.  i <= nxr  .AND.  j >= nys  .AND.  j <= nyn )  THEN
-
-                DO  k = nzb_soil, nzt_soil
-                   sums_l(k,89,tn)  = sums_l(k,89,tn)  + t_soil_h(0)%var_2d(k,m) * rmask(j,i,sr)
-                   sums_l(k,91,tn)  = sums_l(k,91,tn)  + m_soil_h(0)%var_2d(k,m) * rmask(j,i,sr)
-                ENDDO
-             ENDIF
+             DO  k = nzb_soil, nzt_soil
+                sums_l(k,89,tn)  = sums_l(k,89,tn)  + t_soil_h(0)%var_2d(k,m) * rmask(j,i,sr)
+                sums_l(k,91,tn)  = sums_l(k,91,tn)  + m_soil_h(0)%var_2d(k,m) * rmask(j,i,sr)
+             ENDDO
           ENDDO
           !$OMP END PARALLEL
@@ -1806,5 +1803,10 @@
           sums(k,55:63)         = sums(k,55:63)         / ngp_2dh(sr)
           sums(k,81:88)         = sums(k,81:88)         / ngp_2dh(sr)
-          sums(k,89:112)        = sums(k,89:112)        / ngp_2dh(sr)
+
+          IF ( land_surface  .AND.  surf_lsm_h(0)%ns_tot > 0 )  THEN
+             sums(k,89:98) = sums(k,89:98)              / surf_lsm_h(0)%ns_tot
+          ENDIF
+
+          sums(k,99:112)        = sums(k,99:112)        / ngp_2dh(sr)
           sums(k,114)           = sums(k,114)           / ngp_2dh(sr)
           sums(k,117)           = sums(k,117)           / ngp_2dh(sr)
Index: /palm/trunk/SOURCE/surface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/surface_mod.f90	(revision 4702)
+++ /palm/trunk/SOURCE/surface_mod.f90	(revision 4703)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Calculate and store total number of surfaces within the model domain.
+!
+! 4694 2020-09-23 15:09:19Z pavelkrc
 ! Fix reading of surface data from MPI restart file
 !
@@ -227,8 +230,9 @@
     TYPE surf_type
 
-       INTEGER(iwp) ::  ioff  !< offset value in x-direction, used to determine index of surface element
-       INTEGER(iwp) ::  joff  !< offset value in y-direction, used to determine index of surface element
-       INTEGER(iwp) ::  koff  !< offset value in z-direction, used to determine index of surface element
-       INTEGER(iwp) ::  ns    !< number of surface elements on the PE
+       INTEGER(iwp) ::  ioff        !< offset value in x-direction, used to determine index of surface element
+       INTEGER(iwp) ::  joff        !< offset value in y-direction, used to determine index of surface element
+       INTEGER(iwp) ::  koff        !< offset value in z-direction, used to determine index of surface element
+       INTEGER(iwp) ::  ns          !< number of surface elements on the PE
+       INTEGER(iwp) ::  ns_tot = 0  !< number of surface elements within the entire model domain
 
        INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  i  !< x-index linking to the PALM 3D-grid
@@ -1173,5 +1177,6 @@
     ENDDO
 !
-!-- Set the flag for the existence of vertical urban/land surfaces
+!-- Set the flag for the existence of vertical urban/land surfaces. Therefore, sum-up the number of
+!-- all natural and urban-type vertical surfaces and check.
     num_surf_v_l = 0
     DO  l = 0, 3
@@ -1186,4 +1191,31 @@
     IF ( num_surf_v > 0 )  vertical_surfaces_exist = .TRUE.
 
+!
+!-- Calculate the total number of surfaces in the entire model domain of a type.
+!-- Horizontal walls.
+    DO  l = 0, 1
+#if defined( __parallel )
+       CALL MPI_ALLREDUCE( surf_def_h(l)%ns, surf_def_h(l)%ns_tot, 1, MPI_INTEGER, MPI_SUM, comm2d, ierr)
+       CALL MPI_ALLREDUCE( surf_lsm_h(l)%ns, surf_lsm_h(l)%ns_tot, 1, MPI_INTEGER, MPI_SUM, comm2d, ierr)
+       CALL MPI_ALLREDUCE( surf_usm_h(l)%ns, surf_usm_h(l)%ns_tot, 1, MPI_INTEGER, MPI_SUM, comm2d, ierr)
+#else
+       surf_def_h(l)%ns_tot = surf_def_h(l)%ns
+       surf_lsm_h(l)%ns_tot = surf_lsm_h(l)%ns
+       surf_usm_h(l)%ns_tot = surf_usm_h(l)%ns
+#endif
+    ENDDO
+!
+!-- Vertical walls.
+    DO  l = 0, 3
+#if defined( __parallel )
+       CALL MPI_ALLREDUCE( surf_def_v(l)%ns, surf_def_v(l)%ns_tot, 1, MPI_INTEGER, MPI_SUM, comm2d, ierr)
+       CALL MPI_ALLREDUCE( surf_lsm_v(l)%ns, surf_lsm_v(l)%ns_tot, 1, MPI_INTEGER, MPI_SUM, comm2d, ierr)
+       CALL MPI_ALLREDUCE( surf_usm_v(l)%ns, surf_usm_v(l)%ns_tot, 1, MPI_INTEGER, MPI_SUM, comm2d, ierr)
+#else
+       surf_def_v(l)%ns_tot = surf_def_v(l)%ns
+       surf_lsm_v(l)%ns_tot = surf_lsm_v(l)%ns
+       surf_usm_v(l)%ns_tot = surf_usm_v(l)%ns
+#endif
+    ENDDO
 
  END SUBROUTINE init_surface_arrays
